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
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: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, orPromise<Response>— handler returnstoServerSentEventsResponse(stream).Neither shape is currently assignable, so
useChat({ connection: stream(() => chatFn({ data })) })won't compile without anas any.Suggested fix
Widen
stream()(andrpcStream()) to accept all three shapes, awaiting the result and parsing SSE if aResponseis 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