[AIT-676] Move /api/chat default from core to Vercel layer#35
Open
lawrence-forooghian wants to merge 1 commit intomainfrom
Open
[AIT-676] Move /api/chat default from core to Vercel layer#35lawrence-forooghian wants to merge 1 commit intomainfrom
/api/chat default from core to Vercel layer#35lawrence-forooghian wants to merge 1 commit intomainfrom
Conversation
/api/chat default from core to Vercel layer
/api/chat default from core to Vercel layer/api/chat default from core to Vercel layer
dfe3364 to
e3729c8
Compare
e3729c8 to
4b71a8f
Compare
The default HTTP endpoint "/api/chat" is the Vercel AI SDK's default (set by DefaultChatTransport), but we were setting it in our generic core transport. This violates the two-layer architecture principle that the generic layer should know nothing about Vercel. Make `api` required on core `ClientTransportOptions` and apply the "/api/chat" default in the Vercel layer's `createClientTransport` factory. To avoid forcing useChat users to call `useClientTransport` (where `api` would now be required), `useChatTransport` now returns a `ChatTransportHandle` containing both the `ChatTransport` and the underlying `ClientTransport`. Previously it only returned the `ChatTransport`, so callers had no way to access the transport it created internally — they needed a separate `useClientTransport` call. The handle lets useChat users get the Vercel default without extra configuration, while still having access to the transport for `useMessageSync`, `useActiveTurns`, `useView`, etc. [AIT-676] Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
0646512 to
75c08db
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: This is a Claude-generated thing but it reflects the result of my thinking and I've read through it all.
Summary
The default HTTP endpoint "/api/chat" is the Vercel AI SDK's default (set by
DefaultChatTransport), but we were setting it in our generic core transport. This violates the two-layer architecture principle that the generic layer should know nothing about Vercel.Make
apirequired on coreClientTransportOptionsand apply the "/api/chat" default in the Vercel layer'screateClientTransportfactory.To avoid forcing useChat users to call
useClientTransport(whereapiwould now be required),useChatTransportnow returns aChatTransportHandlecontaining both theChatTransportand the underlyingClientTransport. Previously it only returned theChatTransport, so callers had no way to access the transport it created internally — they needed a separateuseClientTransportcall. The handle lets useChat users get the Vercel default without extra configuration, while still having access to the transport foruseMessageSync,useActiveTurns,useView, etc.Options considered
This PR implements Option B below. Feedback welcome on whether Option A would be preferable.
Both diffs are against the Client - React with
useChatsection of the README.Option A: Make
apirequired everywhereSimplest change. Remove the default from core, make
apirequired onClientTransportOptions. All callers must specify it explicitly. No new types or return type changes.import { useChat } from '@ai-sdk/react'; import { useChannel } from 'ably/react'; import { useClientTransport, useActiveTurns, useView } from '@ably/ai-transport/react'; import { useChatTransport, useMessageSync } from '@ably/ai-transport/vercel/react'; import { UIMessageCodec } from '@ably/ai-transport/vercel'; function Chat({ chatId, clientId }: { chatId: string; clientId?: string }) { const { channel } = useChannel({ channelName: chatId }); - const transport = useClientTransport({ channel, codec: UIMessageCodec, clientId }); + const transport = useClientTransport({ channel, codec: UIMessageCodec, clientId, api: '/api/chat' }); const chatTransport = useChatTransport(transport);Pros: Simple implementation, explicit, no new abstractions.
Cons:
useChatusers must specifyapieven though Vercel's own default transport doesn't require it.Option B: Preserve the default in the Vercel layer (this PR)
Make
apirequired in core but optional in the Vercel layer.useChatTransportreturns both theChatTransportand the underlyingClientTransport.import { useChat } from '@ai-sdk/react'; import { useChannel } from 'ably/react'; -import { useClientTransport, useActiveTurns, useView } from '@ably/ai-transport/react'; +import { useActiveTurns, useView } from '@ably/ai-transport/react'; import { useChatTransport, useMessageSync } from '@ably/ai-transport/vercel/react'; -import { UIMessageCodec } from '@ably/ai-transport/vercel'; function Chat({ chatId, clientId }: { chatId: string; clientId?: string }) { const { channel } = useChannel({ channelName: chatId }); - const transport = useClientTransport({ channel, codec: UIMessageCodec, clientId }); - const chatTransport = useChatTransport(transport); + const { chatTransport, transport } = useChatTransport({ channel, clientId });Pros: Matches Vercel's own ergonomics (no endpoint needed), fewer imports, fewer lines.
Cons: Was there perhaps some motivation that I've missed — perhaps didactic, perhaps something else? — for requiring users to create the
ClientTransportexplicitly?🤖 Generated with Claude Code