Skip to content

feat(ai-client): useChat server functions #509

@tombeckenham

Description

@tombeckenham

Reported by @vfshera in Discord (thread: useChat with server functions, 23 Apr 2026).

Wiring a TanStack Start server function into useChat (Solid in the report; same on React) currently fails to typecheck:

Property '[Symbol.asyncIterator]' is missing in type 'Promise<Response>'
but required in type 'AsyncIterable<AGUIEvent>'. ts(2741)

The stream() connection adapter's factory is typed as () => AsyncIterable<StreamChunk>, but a server function call is async and typically returns either:

  • Promise<AsyncIterable<StreamChunk>> — handler returns the chat stream directly, or
  • Promise<Response> — handler returns toServerSentEventsResponse(stream).

Neither shape is currently assignable, so useChat({ connection: stream(() => chatFn({ data })) }) won't compile without an as any.

Suggested fix

Widen stream() (and rpcStream()) to accept all three shapes, awaiting the result and parsing SSE if a Response is returned. A working implementation + tests + docs is on this fork: tombeckenham/ai-tom@claude/add-usechat-server-functions-pBsj5 — happy to open a PR upstream if useful.

cc @vfshera

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions