@ably/ai-transport 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +93 -111
  2. package/dist/ably-ai-transport.js +2401 -1387
  3. package/dist/ably-ai-transport.js.map +1 -1
  4. package/dist/ably-ai-transport.umd.cjs +1 -1
  5. package/dist/ably-ai-transport.umd.cjs.map +1 -1
  6. package/dist/constants.d.ts +116 -42
  7. package/dist/core/agent.d.ts +44 -0
  8. package/dist/core/channel-options.d.ts +57 -0
  9. package/dist/core/codec/codec-event.d.ts +9 -0
  10. package/dist/core/codec/decoder.d.ts +24 -24
  11. package/dist/core/codec/define-codec.d.ts +100 -0
  12. package/dist/core/codec/encoder.d.ts +10 -12
  13. package/dist/core/codec/field-bag.d.ts +85 -0
  14. package/dist/core/codec/fields.d.ts +141 -0
  15. package/dist/core/codec/index.d.ts +8 -2
  16. package/dist/core/codec/input-descriptor-decoder.d.ts +19 -0
  17. package/dist/core/codec/input-descriptor-encoder.d.ts +22 -0
  18. package/dist/core/codec/input-descriptors.d.ts +281 -0
  19. package/dist/core/codec/lifecycle-tracker.d.ts +10 -9
  20. package/dist/core/codec/output-descriptor-decoder.d.ts +29 -0
  21. package/dist/core/codec/output-descriptor-encoder.d.ts +31 -0
  22. package/dist/core/codec/output-descriptors.d.ts +237 -0
  23. package/dist/core/codec/types.d.ts +470 -119
  24. package/dist/core/codec/well-known-inputs.d.ts +52 -0
  25. package/dist/core/transport/agent-session.d.ts +10 -0
  26. package/dist/core/transport/agent-view.d.ts +296 -0
  27. package/dist/core/transport/client-session.d.ts +13 -0
  28. package/dist/core/transport/decode-fold.d.ts +55 -0
  29. package/dist/core/transport/headers.d.ts +121 -14
  30. package/dist/core/transport/index.d.ts +5 -6
  31. package/dist/core/transport/internal/bounded-map.d.ts +20 -0
  32. package/dist/core/transport/invocation.d.ts +74 -0
  33. package/dist/core/transport/load-history-pages.d.ts +71 -0
  34. package/dist/core/transport/load-history.d.ts +44 -0
  35. package/dist/core/transport/pipe-stream.d.ts +9 -9
  36. package/dist/core/transport/run-manager.d.ts +76 -0
  37. package/dist/core/transport/session-support.d.ts +55 -0
  38. package/dist/core/transport/tree.d.ts +523 -109
  39. package/dist/core/transport/types/agent.d.ts +375 -0
  40. package/dist/core/transport/types/client.d.ts +201 -0
  41. package/dist/core/transport/types/shared.d.ts +24 -0
  42. package/dist/core/transport/types/tree.d.ts +357 -0
  43. package/dist/core/transport/types/view.d.ts +249 -0
  44. package/dist/core/transport/types.d.ts +13 -553
  45. package/dist/core/transport/view.d.ts +390 -84
  46. package/dist/core/transport/wire-log.d.ts +102 -0
  47. package/dist/errors.d.ts +27 -10
  48. package/dist/index.d.ts +8 -9
  49. package/dist/logger.d.ts +12 -0
  50. package/dist/react/ably-ai-transport-react.js +1365 -1010
  51. package/dist/react/ably-ai-transport-react.js.map +1 -1
  52. package/dist/react/ably-ai-transport-react.umd.cjs +1 -1
  53. package/dist/react/ably-ai-transport-react.umd.cjs.map +1 -1
  54. package/dist/react/contexts/client-session-context.d.ts +37 -0
  55. package/dist/react/contexts/client-session-provider.d.ts +56 -0
  56. package/dist/react/create-session-hooks.d.ts +116 -0
  57. package/dist/react/index.d.ts +13 -12
  58. package/dist/react/internal/skipped-session.d.ts +8 -0
  59. package/dist/react/internal/use-resolved-session.d.ts +36 -0
  60. package/dist/react/use-ably-messages.d.ts +17 -14
  61. package/dist/react/use-client-session.d.ts +81 -0
  62. package/dist/react/use-create-view.d.ts +14 -13
  63. package/dist/react/use-tree.d.ts +30 -15
  64. package/dist/react/use-view.d.ts +81 -50
  65. package/dist/utils.d.ts +48 -71
  66. package/dist/vercel/ably-ai-transport-vercel.js +3257 -2499
  67. package/dist/vercel/ably-ai-transport-vercel.js.map +1 -1
  68. package/dist/vercel/ably-ai-transport-vercel.umd.cjs +1 -1
  69. package/dist/vercel/ably-ai-transport-vercel.umd.cjs.map +1 -1
  70. package/dist/vercel/codec/decode-lifecycle.d.ts +9 -0
  71. package/dist/vercel/codec/events.d.ts +50 -0
  72. package/dist/vercel/codec/fields.d.ts +44 -0
  73. package/dist/vercel/codec/fold-content.d.ts +16 -0
  74. package/dist/vercel/codec/fold-data.d.ts +16 -0
  75. package/dist/vercel/codec/fold-input.d.ts +67 -0
  76. package/dist/vercel/codec/fold-lifecycle.d.ts +16 -0
  77. package/dist/vercel/codec/fold-text.d.ts +16 -0
  78. package/dist/vercel/codec/fold-tool-input.d.ts +17 -0
  79. package/dist/vercel/codec/fold-tool-output.d.ts +16 -0
  80. package/dist/vercel/codec/index.d.ts +7 -20
  81. package/dist/vercel/codec/inputs.d.ts +11 -0
  82. package/dist/vercel/codec/outputs.d.ts +11 -0
  83. package/dist/vercel/codec/reducer-state.d.ts +121 -0
  84. package/dist/vercel/codec/reducer.d.ts +62 -0
  85. package/dist/vercel/codec/tool-transitions.d.ts +2 -8
  86. package/dist/vercel/codec/wire-data.d.ts +34 -0
  87. package/dist/vercel/index.d.ts +5 -5
  88. package/dist/vercel/react/ably-ai-transport-vercel-react.js +2859 -9705
  89. package/dist/vercel/react/ably-ai-transport-vercel-react.js.map +1 -1
  90. package/dist/vercel/react/ably-ai-transport-vercel-react.umd.cjs +1 -45
  91. package/dist/vercel/react/ably-ai-transport-vercel-react.umd.cjs.map +1 -1
  92. package/dist/vercel/react/contexts/chat-transport-context.d.ts +9 -7
  93. package/dist/vercel/react/contexts/chat-transport-provider.d.ts +53 -41
  94. package/dist/vercel/react/index.d.ts +1 -2
  95. package/dist/vercel/react/use-chat-transport.d.ts +30 -26
  96. package/dist/vercel/react/use-message-sync.d.ts +17 -30
  97. package/dist/vercel/run-end-reason.d.ts +84 -0
  98. package/dist/vercel/tool-part.d.ts +21 -0
  99. package/dist/vercel/transport/chat-transport.d.ts +41 -24
  100. package/dist/vercel/transport/index.d.ts +24 -20
  101. package/dist/vercel/transport/run-output-stream.d.ts +54 -0
  102. package/dist/version.d.ts +2 -0
  103. package/package.json +31 -24
  104. package/src/constants.ts +124 -51
  105. package/src/core/agent.ts +92 -0
  106. package/src/core/channel-options.ts +89 -0
  107. package/src/core/codec/codec-event.ts +27 -0
  108. package/src/core/codec/decoder.ts +202 -105
  109. package/src/core/codec/define-codec.ts +432 -0
  110. package/src/core/codec/encoder.ts +114 -107
  111. package/src/core/codec/field-bag.ts +142 -0
  112. package/src/core/codec/fields.ts +193 -0
  113. package/src/core/codec/index.ts +56 -6
  114. package/src/core/codec/input-descriptor-decoder.ts +97 -0
  115. package/src/core/codec/input-descriptor-encoder.ts +150 -0
  116. package/src/core/codec/input-descriptors.ts +373 -0
  117. package/src/core/codec/lifecycle-tracker.ts +10 -9
  118. package/src/core/codec/output-descriptor-decoder.ts +139 -0
  119. package/src/core/codec/output-descriptor-encoder.ts +101 -0
  120. package/src/core/codec/output-descriptors.ts +307 -0
  121. package/src/core/codec/types.ts +505 -126
  122. package/src/core/codec/well-known-inputs.ts +96 -0
  123. package/src/core/transport/agent-session.ts +1085 -0
  124. package/src/core/transport/agent-view.ts +738 -0
  125. package/src/core/transport/client-session.ts +780 -0
  126. package/src/core/transport/decode-fold.ts +101 -0
  127. package/src/core/transport/headers.ts +234 -22
  128. package/src/core/transport/index.ts +27 -27
  129. package/src/core/transport/internal/bounded-map.ts +27 -0
  130. package/src/core/transport/invocation.ts +98 -0
  131. package/src/core/transport/load-history-pages.ts +220 -0
  132. package/src/core/transport/load-history.ts +271 -0
  133. package/src/core/transport/pipe-stream.ts +63 -39
  134. package/src/core/transport/run-manager.ts +243 -0
  135. package/src/core/transport/session-support.ts +96 -0
  136. package/src/core/transport/tree.ts +1293 -308
  137. package/src/core/transport/types/agent.ts +434 -0
  138. package/src/core/transport/types/client.ts +247 -0
  139. package/src/core/transport/types/shared.ts +27 -0
  140. package/src/core/transport/types/tree.ts +393 -0
  141. package/src/core/transport/types/view.ts +288 -0
  142. package/src/core/transport/types.ts +13 -706
  143. package/src/core/transport/view.ts +1229 -450
  144. package/src/core/transport/wire-log.ts +189 -0
  145. package/src/errors.ts +29 -9
  146. package/src/event-emitter.ts +3 -2
  147. package/src/index.ts +86 -42
  148. package/src/logger.ts +14 -1
  149. package/src/react/contexts/client-session-context.ts +41 -0
  150. package/src/react/contexts/client-session-provider.tsx +222 -0
  151. package/src/react/create-session-hooks.ts +141 -0
  152. package/src/react/index.ts +24 -13
  153. package/src/react/internal/skipped-session.ts +62 -0
  154. package/src/react/internal/use-resolved-session.ts +63 -0
  155. package/src/react/use-ably-messages.ts +32 -22
  156. package/src/react/use-client-session.ts +178 -0
  157. package/src/react/use-create-view.ts +33 -29
  158. package/src/react/use-tree.ts +61 -30
  159. package/src/react/use-view.ts +138 -96
  160. package/src/utils.ts +83 -131
  161. package/src/vercel/codec/decode-lifecycle.ts +70 -0
  162. package/src/vercel/codec/events.ts +85 -0
  163. package/src/vercel/codec/fields.ts +58 -0
  164. package/src/vercel/codec/fold-content.ts +54 -0
  165. package/src/vercel/codec/fold-data.ts +46 -0
  166. package/src/vercel/codec/fold-input.ts +255 -0
  167. package/src/vercel/codec/fold-lifecycle.ts +85 -0
  168. package/src/vercel/codec/fold-text.ts +55 -0
  169. package/src/vercel/codec/fold-tool-input.ts +86 -0
  170. package/src/vercel/codec/fold-tool-output.ts +79 -0
  171. package/src/vercel/codec/index.ts +28 -21
  172. package/src/vercel/codec/inputs.ts +116 -0
  173. package/src/vercel/codec/outputs.ts +207 -0
  174. package/src/vercel/codec/reducer-state.ts +169 -0
  175. package/src/vercel/codec/reducer.ts +191 -0
  176. package/src/vercel/codec/tool-transitions.ts +3 -14
  177. package/src/vercel/codec/wire-data.ts +64 -0
  178. package/src/vercel/index.ts +7 -19
  179. package/src/vercel/react/contexts/chat-transport-context.ts +8 -7
  180. package/src/vercel/react/contexts/chat-transport-provider.tsx +87 -59
  181. package/src/vercel/react/index.ts +3 -5
  182. package/src/vercel/react/use-chat-transport.ts +44 -66
  183. package/src/vercel/react/use-message-sync.ts +75 -39
  184. package/src/vercel/run-end-reason.ts +157 -0
  185. package/src/vercel/tool-part.ts +25 -0
  186. package/src/vercel/transport/chat-transport.ts +380 -98
  187. package/src/vercel/transport/index.ts +38 -37
  188. package/src/vercel/transport/run-output-stream.ts +169 -0
  189. package/src/version.ts +2 -0
  190. package/dist/core/transport/client-transport.d.ts +0 -10
  191. package/dist/core/transport/decode-history.d.ts +0 -43
  192. package/dist/core/transport/server-transport.d.ts +0 -7
  193. package/dist/core/transport/stream-router.d.ts +0 -29
  194. package/dist/core/transport/turn-manager.d.ts +0 -37
  195. package/dist/react/contexts/transport-context.d.ts +0 -31
  196. package/dist/react/contexts/transport-provider.d.ts +0 -49
  197. package/dist/react/create-transport-hooks.d.ts +0 -124
  198. package/dist/react/use-active-turns.d.ts +0 -12
  199. package/dist/react/use-client-transport.d.ts +0 -80
  200. package/dist/vercel/codec/accumulator.d.ts +0 -21
  201. package/dist/vercel/codec/decoder.d.ts +0 -22
  202. package/dist/vercel/codec/encoder.d.ts +0 -41
  203. package/dist/vercel/react/use-staged-add-tool-approval-response.d.ts +0 -30
  204. package/dist/vercel/tool-approvals.d.ts +0 -124
  205. package/dist/vercel/tool-events.d.ts +0 -26
  206. package/src/core/transport/client-transport.ts +0 -977
  207. package/src/core/transport/decode-history.ts +0 -485
  208. package/src/core/transport/server-transport.ts +0 -612
  209. package/src/core/transport/stream-router.ts +0 -136
  210. package/src/core/transport/turn-manager.ts +0 -165
  211. package/src/react/contexts/transport-context.ts +0 -37
  212. package/src/react/contexts/transport-provider.tsx +0 -164
  213. package/src/react/create-transport-hooks.ts +0 -144
  214. package/src/react/use-active-turns.ts +0 -72
  215. package/src/react/use-client-transport.ts +0 -197
  216. package/src/vercel/codec/accumulator.ts +0 -588
  217. package/src/vercel/codec/decoder.ts +0 -618
  218. package/src/vercel/codec/encoder.ts +0 -410
  219. package/src/vercel/react/use-staged-add-tool-approval-response.ts +0 -87
  220. package/src/vercel/tool-approvals.ts +0 -380
  221. package/src/vercel/tool-events.ts +0 -53
@@ -1,16 +1,17 @@
1
- import { ClientTransport } from '../../../core/transport/types.js';
1
+ import { ClientSession } from '../../../core/transport/types.js';
2
+ import { VercelInput, VercelOutput, VercelProjection } from '../../codec/index.js';
2
3
  import { ChatTransport } from '../../transport/chat-transport.js';
3
4
  import type * as Ably from 'ably';
4
5
  import type * as AI from 'ai';
5
6
  /**
6
7
  * A single entry in the chat transport registry, holding both the
7
- * underlying {@link ClientTransport} and the {@link ChatTransport} wrapping it.
8
+ * underlying {@link ClientSession} and the {@link ChatTransport} wrapping it.
8
9
  */
9
10
  export interface ChatTransportSlot {
10
- /** The underlying client transport used to create the chat transport. */
11
- readonly transport: ClientTransport<AI.UIMessageChunk, AI.UIMessage>;
12
- /** Construction error from the underlying {@link ClientTransport}, or `undefined` on success. */
13
- readonly transportError: Ably.ErrorInfo | undefined;
11
+ /** The underlying client session used to create the chat transport. */
12
+ readonly session: ClientSession<VercelInput, VercelOutput, VercelProjection, AI.UIMessage>;
13
+ /** Construction error from the underlying {@link ClientSession}, or `undefined` on success. */
14
+ readonly sessionError?: Ably.ErrorInfo | undefined;
14
15
  /** The chat transport adapter for use with Vercel's useChat hook. */
15
16
  readonly chatTransport: ChatTransport;
16
17
  }
@@ -18,7 +19,7 @@ export interface ChatTransportSlot {
18
19
  * The shape of the single {@link ChatTransportContext} value.
19
20
  * Combines the nearest slot with the full registry in one context object.
20
21
  */
21
- export interface ChatTransportContextValue {
22
+ interface ChatTransportContextValue {
22
23
  /** The slot from the nearest {@link ChatTransportProvider} in the tree. */
23
24
  readonly nearest: ChatTransportSlot | undefined;
24
25
  /** All registered slots, keyed by channelName. */
@@ -30,3 +31,4 @@ export interface ChatTransportContextValue {
30
31
  * read by {@link useChatTransport}.
31
32
  */
32
33
  export declare const ChatTransportContext: import('react').Context<ChatTransportContextValue>;
34
+ export {};
@@ -1,70 +1,79 @@
1
1
  import { PropsWithChildren, ReactNode } from 'react';
2
- import { TransportProviderProps } from '../../../react/index.js';
2
+ import { ClientSessionProviderProps } from '../../../react/index.js';
3
+ import { VercelInput, VercelOutput, VercelProjection } from '../../codec/index.js';
3
4
  import { ChatTransportOptions } from '../../transport/index.js';
4
5
  /**
5
- * ChatTransportProvider: creates a ChatTransport from a ClientTransport and makes it
6
+ * ChatTransportProvider: creates a ChatTransport from a ClientSession and makes it
6
7
  * available to descendants via ChatTransportContext.
7
8
  *
8
- * Wraps children with TransportProvider (using UIMessageCodec) so the Ably channel
9
- * lifecycle is managed in one place. An inner component reads the ClientTransport
10
- * from NearestTransportContext and creates the ChatTransport once on first render
11
- * (via useRef).
9
+ * Wraps children with ClientSessionProvider (using UIMessageCodec). The
10
+ * surrounding `<AblyProvider>` supplies the Realtime client; the session
11
+ * resolves the channel from `channelName` itself. An inner component reads
12
+ * the ClientSession via useClientSession() and creates the ChatTransport
13
+ * via useMemo, keyed on the session and transport options.
12
14
  *
13
- * The ChatTransport is NOT closed on unmount — the underlying ClientTransport
14
- * lifecycle is managed by the wrapping TransportProvider. Auto-closing would break
15
- * React Strict Mode, and ChatTransport.close() delegates to ClientTransport.close()
16
- * which TransportProvider already calls.
15
+ * The ChatTransport is NOT closed on unmount — the underlying ClientSession
16
+ * lifecycle is managed by the wrapping ClientSessionProvider. Auto-closing would break
17
+ * React Strict Mode, and ChatTransport.close() delegates to ClientSession.close()
18
+ * which ClientSessionProvider already calls.
17
19
  *
18
20
  * Multiple ChatTransportProviders can be nested using distinct channelNames.
19
- * Each provider merges its transport into the parent registry, so descendants
20
- * can access all registered transports via useChatTransport({ channelName }).
21
+ * Each provider merges its session into the parent registry, so descendants
22
+ * can access all registered sessions via useChatTransport({ channelName }).
21
23
  */
22
24
  import type * as AI from 'ai';
23
- export declare const TransportProvider: import('react').ComponentType<TransportProviderProps<AI.UIMessageChunk, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>>>, useAblyMessages: (props?: {
24
- transport?: import('../../../index.js').ClientTransport<AI.UIMessageChunk, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>> | undefined;
25
+ export declare const ClientSessionProvider: import('react').ComponentType<ClientSessionProviderProps<VercelInput, VercelOutput, VercelProjection, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>>>, useAblyMessages: (props?: {
26
+ session?: import('../../../react/index.js').ClientSession<VercelInput, VercelOutput, VercelProjection, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>> | undefined;
25
27
  skip?: boolean;
26
- } | undefined) => import('ably').InboundMessage[], useActiveTurns: (props?: {
27
- transport?: import('../../../index.js').ClientTransport<AI.UIMessageChunk, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>> | null | undefined;
28
- } | undefined) => Map<string, Set<string>>, useClientTransport: (props?: {
28
+ } | undefined) => import('ably').InboundMessage[], useClientSession: (props?: {
29
29
  channelName?: string;
30
30
  skip?: boolean;
31
31
  onError?: (error: import('ably').ErrorInfo) => void;
32
- }) => import('../../../react/use-client-transport.js').ClientTransportHandle<AI.UIMessageChunk, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>>, useCreateView: (props?: {
33
- transport?: import('../../../index.js').ClientTransport<AI.UIMessageChunk, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>> | null | undefined;
32
+ }) => import('../../../react/use-client-session.js').ClientSessionHandle<VercelInput, VercelOutput, VercelProjection, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>>, useCreateView: (props?: {
33
+ session?: import('../../../react/index.js').ClientSession<VercelInput, VercelOutput, VercelProjection, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>> | null | undefined;
34
34
  limit?: number;
35
35
  skip?: boolean;
36
- } | undefined) => import('../../../react/use-view.js').ViewHandle<AI.UIMessageChunk, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>>, useTree: (props?: {
37
- transport?: import('../../../index.js').ClientTransport<AI.UIMessageChunk, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>> | undefined;
38
- } | undefined) => import('../../../react/use-tree.js').TreeHandle<AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>>, useView: (props?: {
39
- transport?: import('../../../index.js').ClientTransport<AI.UIMessageChunk, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>> | null | undefined;
40
- view?: import('../../../index.js').View<AI.UIMessageChunk, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>> | null | undefined;
36
+ } | undefined) => import('../../../react/use-view.js').ViewHandle<VercelInput, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>>, useTree: (props?: {
37
+ session?: import('../../../react/index.js').ClientSession<VercelInput, VercelOutput, VercelProjection, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>> | undefined;
38
+ } | undefined) => import('../../../react/use-tree.js').TreeHandle<VercelProjection>, useView: (props?: {
39
+ session?: import('../../../react/index.js').ClientSession<VercelInput, VercelOutput, VercelProjection, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>> | null | undefined;
40
+ view?: import('../../../index.js').View<VercelInput, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>> | null | undefined;
41
41
  limit?: number;
42
42
  skip?: boolean;
43
- } | undefined) => import('../../../react/use-view.js').ViewHandle<AI.UIMessageChunk, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>>;
44
- type CoreTransportProviderProps = Omit<TransportProviderProps<AI.UIMessageChunk, AI.UIMessage>, 'codec' | 'api'> & Partial<Pick<TransportProviderProps<AI.UIMessageChunk, AI.UIMessage>, 'api'>>;
43
+ } | undefined) => import('../../../react/use-view.js').ViewHandle<VercelInput, AI.UIMessage<unknown, AI.UIDataTypes, AI.UITools>>;
44
+ type CoreClientSessionProviderProps = Omit<ClientSessionProviderProps<VercelInput, VercelOutput, VercelProjection, AI.UIMessage>, 'codec'>;
45
45
  /**
46
46
  * Props for {@link ChatTransportProvider}.
47
47
  *
48
- * All {@link TransportProviderProps} for Vercel types except `codec` (baked as UIMessageCodec),
49
- * plus `chatOptions` for customizing chat request construction.
48
+ * All {@link ClientSessionProviderProps} for Vercel types except `codec` (baked as UIMessageCodec),
49
+ * plus the transport-owned invocation POST options (`api` / `credentials` / `fetch`) and
50
+ * `chatOptions` for customizing chat request construction.
50
51
  */
51
- export interface ChatTransportProviderProps extends CoreTransportProviderProps {
52
+ export interface ChatTransportProviderProps extends CoreClientSessionProviderProps {
53
+ /** Endpoint the chat transport POSTs the invocation to, to wake the agent. Default `/api/chat`. */
54
+ api?: string;
55
+ /** Fetch credentials mode for the invocation POST. */
56
+ credentials?: RequestCredentials;
57
+ /** Custom fetch implementation for the invocation POST. Defaults to `globalThis.fetch`. */
58
+ fetch?: typeof globalThis.fetch;
52
59
  /**
53
- * Optional hooks for customizing chat request construction (e.g. prepareSendMessagesRequest).
60
+ * Optional transport options for customizing chat request construction (e.g. the `prepareSendMessagesRequest` hook).
54
61
  * Must be stable across renders — wrap in `useMemo` or define outside the component.
55
62
  * A new object reference triggers ChatTransport recreation.
63
+ * If this object also sets `api`/`credentials`/`fetch`, the dedicated top-level props of the same name take precedence.
56
64
  */
57
65
  chatOptions?: ChatTransportOptions;
58
66
  }
59
67
  /**
60
- * Provide a {@link ChatTransport} and its underlying {@link ClientTransport} to descendant components.
68
+ * Provide a {@link ChatTransport} and its underlying {@link ClientSession} to descendant components.
61
69
  *
62
- * Wraps children with Ably's `ChannelProvider` (via `TransportProvider`) using `channelName`,
63
- * creates a {@link ClientTransport} with UIMessageCodec, wraps it in a {@link ChatTransport},
70
+ * Wraps children with `ClientSessionProvider` using `channelName` (the Realtime
71
+ * client is read from the surrounding `<AblyProvider>`), creates a
72
+ * {@link ClientSession} with UIMessageCodec, wraps it in a {@link ChatTransport},
64
73
  * and registers the full slot in `ChatTransportContext` under `channelName`. Descendants call
65
- * {@link useChatTransport} with the same `channelName` to access both transports.
74
+ * {@link useChatTransport} with the same `channelName` to access both.
66
75
  *
67
- * `useClientTransport` is also available inside this provider's subtree.
76
+ * `useClientSession` is also available inside this provider's subtree.
68
77
  *
69
78
  * ```tsx
70
79
  * <ChatTransportProvider channelName="ai:demo">
@@ -72,13 +81,16 @@ export interface ChatTransportProviderProps extends CoreTransportProviderProps {
72
81
  * </ChatTransportProvider>
73
82
  *
74
83
  * // Inside Chat:
75
- * const { chatTransport, transport } = useChatTransport();
76
- * const { transport } = useClientTransport(); // also available
84
+ * const { chatTransport, session } = useChatTransport();
85
+ * const { session } = useClientSession(); // also available
77
86
  * ```
78
- * @param props - Provider configuration including `channelName`, optional `chatOptions`, and all other transport options.
87
+ * @param props - Provider configuration including `channelName`, the invocation POST options (`api` / `credentials` / `fetch`), optional `chatOptions`, and all other session options.
88
+ * @param props.api - Endpoint the chat transport POSTs the invocation to. Default `/api/chat`.
89
+ * @param props.credentials - Fetch credentials mode for the invocation POST.
90
+ * @param props.fetch - Custom fetch implementation for the invocation POST.
79
91
  * @param props.chatOptions - Optional hooks for customizing chat request construction. Must be stable (memoized) — a new reference recreates the ChatTransport.
80
- * @param props.children - Descendant components that consume the transport via hooks.
81
- * @returns A React element wrapping children with ChannelProvider, TransportContext, and ChatTransportContext.
92
+ * @param props.children - Descendant components that consume the chat transport via hooks.
93
+ * @returns A React element wrapping children with ClientSessionContext and ChatTransportContext.
82
94
  */
83
- export declare const ChatTransportProvider: ({ chatOptions, children, ...transportProps }: ChatTransportProviderProps & PropsWithChildren) => ReactNode;
95
+ export declare const ChatTransportProvider: ({ api, credentials, fetch, chatOptions, children, ...sessionProps }: ChatTransportProviderProps & PropsWithChildren) => ReactNode;
84
96
  export {};
@@ -1,8 +1,7 @@
1
1
  export type { ChatTransport } from '../transport/chat-transport.js';
2
2
  export type { ChatTransportProviderProps } from './contexts/chat-transport-provider.js';
3
- export { ChatTransportProvider, TransportProvider, useAblyMessages, useActiveTurns, useClientTransport, useCreateView, useTree, useView, } from './contexts/chat-transport-provider.js';
3
+ export { ChatTransportProvider, ClientSessionProvider, useAblyMessages, useClientSession, useCreateView, useTree, useView, } from './contexts/chat-transport-provider.js';
4
4
  export type { ChatTransportHandle, UseChatTransportOptions } from './use-chat-transport.js';
5
5
  export { useChatTransport } from './use-chat-transport.js';
6
6
  export type { UseMessageSyncOptions } from './use-message-sync.js';
7
7
  export { useMessageSync } from './use-message-sync.js';
8
- export { useStagedAddToolApprovalResponse } from './use-staged-add-tool-approval-response.js';
@@ -1,16 +1,18 @@
1
- import { ClientTransport } from '../../core/transport/types.js';
1
+ import { ClientSession } from '../../core/transport/types.js';
2
+ import { VercelInput, VercelOutput, VercelProjection } from '../codec/index.js';
2
3
  import { ChatTransport } from '../transport/index.js';
3
4
  /**
4
- * useChatTransport: reads a ChatTransport and its underlying ClientTransport from
5
+ * useChatTransport: reads a ChatTransport and its underlying ClientSession from
5
6
  * the nearest ChatTransportProvider.
6
7
  *
7
- * The transport is created by ChatTransportProvider, which also wraps the subtree
8
- * with TransportProvider and Ably's ChannelProvider. This hook is a thin context
9
- * reader it does not create or manage any transport state.
8
+ * The chat transport is created by ChatTransportProvider, which wraps the subtree
9
+ * with ClientSessionProvider. The Ably Realtime client is read from the
10
+ * surrounding `<AblyProvider>`. This hook is a thin context reader it does
11
+ * not create or manage any session/transport state.
10
12
  *
11
13
  * Pass `channelName` to look up a specific provider by name. Omit to use the nearest
12
14
  * provider in the tree. Pass `skip: true` to defer (e.g. when auth is not yet resolved)
13
- * — returns stub transports whose properties throw with a descriptive error.
15
+ * — returns stubs whose properties throw with a descriptive error.
14
16
  */
15
17
  import * as Ably from 'ably';
16
18
  import type * as AI from 'ai';
@@ -18,53 +20,55 @@ import type * as AI from 'ai';
18
20
  export interface UseChatTransportOptions {
19
21
  /** Channel name to look up; omit to use the nearest {@link ChatTransportProvider}. */
20
22
  channelName?: string;
21
- /** When `true`, return stub transports that throw on any access. */
23
+ /** When `true`, return stubs that throw on any access. */
22
24
  skip?: boolean;
23
25
  }
24
26
  /**
25
27
  * The value returned by {@link useChatTransport}.
26
- * Provides both the underlying {@link ClientTransport} and the {@link ChatTransport}
28
+ * Provides both the underlying {@link ClientSession} and the {@link ChatTransport}
27
29
  * adapter for Vercel's useChat hook.
28
30
  */
29
31
  export interface ChatTransportHandle {
30
32
  /**
31
- * The underlying client transport, also available via {@link useClientTransport}.
32
- * A throwing stub when `skip` is `true`, when no matching {@link TransportProvider}
33
- * was found in the tree, or when transport construction failed. Check `transportError` before use.
33
+ * The underlying client session, also available via {@link useClientSession}.
34
+ * A throwing stub when `skip` is `true`, when no matching {@link ClientSessionProvider}
35
+ * was found in the tree, or when session construction failed. Check `sessionError` before use.
34
36
  */
35
- transport: ClientTransport<AI.UIMessageChunk, AI.UIMessage>;
37
+ session: ClientSession<VercelInput, VercelOutput, VercelProjection, AI.UIMessage>;
36
38
  /**
37
39
  * The chat transport adapter for use with Vercel's `useChat` hook.
38
40
  *
39
- * A throwing stub when `skip` is `true`, when no matching
40
- * {@link ChatTransportProvider} was found in the tree, or when the underlying
41
- * {@link ClientTransport} construction failed. Check both `chatTransportError`
42
- * and `transportError` before use.
41
+ * A throwing stub when `skip` is `true` or when no matching
42
+ * {@link ChatTransportProvider} was found in the tree. When a provider is found
43
+ * but the underlying {@link ClientSession} failed to construct, this is the real
44
+ * transport and `sessionError` is set instead. Check `chatTransportError` and
45
+ * `sessionError` before use.
43
46
  */
44
47
  chatTransport: ChatTransport;
45
48
  /**
46
- * Set when no matching {@link TransportProvider} was found, when transport
49
+ * Set when no matching {@link ClientSessionProvider} was found, when session
47
50
  * construction failed, and `skip` is `false`.
48
- * `undefined` when the transport resolved successfully or when `skip` is `true`.
51
+ * `undefined` when the session resolved successfully or when `skip` is `true`.
49
52
  */
50
- transportError?: Ably.ErrorInfo | undefined;
53
+ sessionError?: Ably.ErrorInfo | undefined;
51
54
  /**
52
- * Set when no matching {@link ChatTransportProvider} was found or when transport
53
- * construction failed, and `skip` is `false`.
54
- * `undefined` when the transport resolved successfully or when `skip` is `true`.
55
+ * Set only when no matching {@link ChatTransportProvider} was found and `skip` is
56
+ * `false`.
57
+ * `undefined` when the chat transport resolved successfully (even if session
58
+ * construction failed — see `sessionError`) or when `skip` is `true`.
55
59
  */
56
60
  chatTransportError?: Ably.ErrorInfo | undefined;
57
61
  }
58
62
  /**
59
- * Access a {@link ChatTransport} and {@link ClientTransport} from the nearest {@link ChatTransportProvider}.
63
+ * Access a {@link ChatTransport} and {@link ClientSession} from the nearest {@link ChatTransportProvider}.
60
64
  *
61
65
  * When `channelName` is omitted, the innermost `ChatTransportProvider` in the tree is used.
62
- * When `skip` is `true`, returns stub transports whose every property and method throws
66
+ * When `skip` is `true`, returns stubs whose every property and method throws
63
67
  * an {@link Ably.ErrorInfo} — safe to hold in state before conditions are ready.
64
68
  * When no provider is found, returns stubs with `chatTransportError` set instead of throwing.
65
- * @param props - Options for selecting the transport.
69
+ * @param props - Options for selecting the chat transport.
66
70
  * @param props.channelName - The channel name passed to the enclosing `ChatTransportProvider`. Omit to use the nearest.
67
71
  * @param props.skip - When `true`, return stubs that throw on any access instead of reading from context.
68
- * @returns The `ChatTransportHandle` containing both the chat transport adapter and the underlying client transport.
72
+ * @returns The `ChatTransportHandle` containing both the chat transport adapter and the underlying client session.
69
73
  */
70
74
  export declare const useChatTransport: ({ channelName, skip }?: UseChatTransportOptions) => ChatTransportHandle;
@@ -1,51 +1,38 @@
1
1
  /**
2
- * useMessageSync: wires transport message lifecycle events into useChat's setMessages.
2
+ * useMessageSync: wire view updates into useChat's setMessages.
3
3
  *
4
- * Subscribes to the transport view's 'update' event and replaces messages state
5
- * with the view's authoritative message list.
4
+ * During active own-run streams, setMessages is gated to avoid an
5
+ * ID-mismatch in useChat's write(). When the stream ends, the gate
6
+ * opens and the view is synced into useChat's overlay.
6
7
  *
7
- * When a ChatTransport is provided (resolved from the nearest ChatTransportProvider),
8
- * setMessages calls are gated during active own-turn streams. This prevents the
9
- * push/replace ID mismatch in useChat's write() function. When the stream finishes,
10
- * the gate opens and an immediate sync fires to pick up any observer messages that
11
- * arrived during the stream.
12
- *
13
- * All dependencies are resolved from the nearest ChatTransportProvider via
14
- * useChatTransport(). Pass channelName to select a specific provider; omit to use
15
- * the nearest. Pass skip: true to pause all subscriptions.
16
- *
17
- * Returns the unsubscribe function in the useEffect cleanup so handlers
18
- * are removed on unmount or when dependencies change.
8
+ * The sync is a per-message merge, not a replace: when the overlay has
9
+ * resolved a client-side tool locally (via addToolResult) but the
10
+ * tree's echo hasn't landed yet, the overlay's resolution wins.
11
+ * Without that, the gate-open sync would race the AI SDK's post-stream
12
+ * sendAutomaticallyWhen check and could clobber the resolution before
13
+ * the continuation publishes.
19
14
  */
20
15
  import type * as AI from 'ai';
21
16
  /** Options for {@link useMessageSync}. */
22
17
  export interface UseMessageSyncOptions {
23
18
  /**
24
- * The `setMessages` updater function from `useChat()`. Required.
25
- * Called with a function that replaces the previous message list with the
26
- * transport's current authoritative message list.
19
+ * The `setMessages` updater function from `useChat()`. Called with an
20
+ * updater that returns the next overlay.
27
21
  */
28
22
  setMessages: (updater: (prev: AI.UIMessage[]) => AI.UIMessage[]) => void;
29
23
  /**
30
24
  * Channel name of the {@link ChatTransportProvider} to observe.
31
- * Omit to use the nearest provider in the tree.
25
+ * Omit to use the nearest provider.
32
26
  */
33
27
  channelName?: string;
34
- /**
35
- * When `true`, skip all subscriptions and do nothing.
36
- * Use when the hook's dependencies are not yet resolved (e.g. auth pending).
37
- */
28
+ /** When `true`, skip all subscriptions. */
38
29
  skip?: boolean;
39
30
  }
40
31
  /**
41
- * Wire transport message updates into `useChat()`'s `setMessages` updater.
42
- *
43
- * Resolves both the transport view and the streaming gate from the nearest
44
- * `ChatTransportProvider`. Pass `channelName` to target a specific provider.
45
- * Pass `skip: true` to pause all subscriptions.
32
+ * Subscribe to view updates and sync them into `useChat()`'s overlay.
46
33
  * @param options - Hook options.
47
- * @param options.setMessages - The `setMessages` function from `useChat()`. Required.
48
- * @param options.channelName - Channel name of the provider to observe; defaults to nearest.
34
+ * @param options.setMessages - The `setMessages` function from `useChat()`.
35
+ * @param options.channelName - Channel name of the provider to observe; defaults to the nearest.
49
36
  * @param options.skip - When `true`, skip all subscriptions.
50
37
  */
51
38
  export declare const useMessageSync: ({ setMessages, channelName, skip }: UseMessageSyncOptions) => void;
@@ -0,0 +1,84 @@
1
+ import { RunEndReason, StreamResult } from '../core/transport/types.js';
2
+ import * as Ably from 'ably';
3
+ import type * as AI from 'ai';
4
+ /**
5
+ * The outcome of a Vercel `streamText` response piped through `Run.pipe`.
6
+ * Discriminated on `reason`: `'suspend'` means the run should pause; the
7
+ * non-`'suspend'` arms describe how it terminated, and an `'error'` outcome
8
+ * always carries `error`.
9
+ *
10
+ * This is a *description of what the Vercel run resulted in*, not a command to
11
+ * the SDK. The common case maps cleanly onto one transport action — `'suspend'`
12
+ * → `Run.suspend()`, everything else → `Run.end()` — and to make that case a
13
+ * one-liner the non-`'suspend'` arms are deliberately assignable to
14
+ * {@link RunEndParams}, so after a `suspend` guard the whole object passes
15
+ * straight to `Run.end(outcome)`. That assignability is a convenience for this
16
+ * adapter, not a constraint on what an outcome can mean: responding to an
17
+ * outcome may also involve work outside this SDK (persisting a result,
18
+ * notifying a human, triggering a downstream workflow), and the developer is
19
+ * free to do that around the terminal call.
20
+ *
21
+ * The type is Vercel-specific by design. Outcomes are the layer where agent
22
+ * SDKs diverge most — both in what they report (the `'suspend'` arm exists only
23
+ * because Vercel surfaces unexecuted tool calls as a non-terminal finish) and
24
+ * in what a developer must do in response. A different SDK's outcome type would
25
+ * have different arms; hence each adapter names its own rather than sharing a
26
+ * single core `RunOutcome`. The vocabulary it bottoms out in
27
+ * ({@link RunEndParams}, `Run.suspend`/`Run.end`) is the shared, codec-agnostic
28
+ * part that does live in core.
29
+ */
30
+ export type VercelRunOutcome = {
31
+ /**
32
+ * The LLM requested tools the SDK did not auto-execute, so the run
33
+ * pauses rather than ending — call `Run.suspend()`.
34
+ */
35
+ reason: 'suspend';
36
+ /** Never present for a suspend outcome. */
37
+ error?: never;
38
+ } | {
39
+ /** A non-error terminal reason; pass the outcome to `Run.end()`. */
40
+ reason: Exclude<RunEndReason, 'error'>;
41
+ /** Never present for a non-error outcome. */
42
+ error?: never;
43
+ } | {
44
+ /** The run ended in error; pass the outcome to `Run.end()`. */
45
+ reason: Extract<RunEndReason, 'error'>;
46
+ /**
47
+ * The terminal error: the underlying stream / `finishReason` failure
48
+ * wrapped as an `Ably.ErrorInfo` (code `StreamError`).
49
+ */
50
+ error: Ably.ErrorInfo;
51
+ };
52
+ /**
53
+ * Derive the {@link VercelRunOutcome} for a Vercel `streamText` response that
54
+ * was piped through `Run.pipe`. Preserves transport-level outcomes
55
+ * (`'cancelled'`, `'error'`) from the pipe result; when the pipe completed
56
+ * naturally, awaits Vercel's `finishReason` and returns `'suspend'` for
57
+ * `'tool-calls'` (the LLM requested tools the SDK did not auto-execute, so the
58
+ * run should suspend rather than end), or `'complete'` otherwise.
59
+ *
60
+ * Surfaces the failure for both error shapes so the caller can forward it to
61
+ * `Run.end(reason, error)`: a stream that threw (`pipeResult.error`) and a
62
+ * `finishReason` that rejected with a non-abort error (e.g.
63
+ * `NoOutputGeneratedError`, network blow-ups). The error is wrapped as an
64
+ * `Ably.ErrorInfo` (code `StreamError`). A stream that already produced a
65
+ * codec-level error chunk is unaffected — stamping run-end is the
66
+ * codec-agnostic baseline that any consumer can read.
67
+ *
68
+ * Tolerates `finishReason` rejection. Vercel AI SDK v6 rejects
69
+ * `streamText().finishReason` with the abort signal's reason when the stream
70
+ * is aborted before any step completes, and rejects with
71
+ * `NoOutputGeneratedError` when the model produced nothing at all. Without
72
+ * this guard the rejection would bubble out of the route handler's `after()`
73
+ * block, skip the developer's `Run.end(...)` call, and leave the run with no
74
+ * `ai-run-end` event on the channel — so observers' UIs stay stuck on
75
+ * `streaming` indefinitely.
76
+ *
77
+ * Saves callers from interpreting Vercel domain semantics inline at the end
78
+ * of every route handler.
79
+ * @param pipeResult - The result returned by `Run.pipe`.
80
+ * @param finishReason - The `finishReason` promise from a `streamText` result.
81
+ * @returns The {@link VercelRunOutcome}: the terminal `reason` (or `'suspend'`)
82
+ * and, when `reason` is `'error'`, the wrapped `error` to pass to `Run.end`.
83
+ */
84
+ export declare const vercelRunOutcome: (pipeResult: StreamResult, finishReason: PromiseLike<AI.FinishReason>) => Promise<VercelRunOutcome>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Shared tool-part type guard for the Vercel layer.
3
+ *
4
+ * The codec normalises every tool part to the `dynamic-tool` shape, but the AI
5
+ * SDK emits `tool-${name}` parts for statically-declared tools. Both shapes
6
+ * carry `toolCallId` and `state`. The guard accepts either representation so
7
+ * the transport's unresolved-tool detection and the React overlay merge can
8
+ * match tool parts uniformly — and so the cross-representation rule lives in
9
+ * one place rather than being re-spelled per call site.
10
+ */
11
+ import type * as AI from 'ai';
12
+ /** A UIMessage tool part in either the `dynamic-tool` or `tool-${name}` representation. */
13
+ export type ToolPart = AI.DynamicToolUIPart | AI.ToolUIPart;
14
+ /**
15
+ * Whether a UIMessage part is a tool part of either representation. The
16
+ * `toolCallId`/`state` shape check is defensive against a future AI SDK release
17
+ * introducing a non-tool variant under the `tool-` prefix (none exists today).
18
+ * @param part - The UIMessage part to inspect.
19
+ * @returns True when the part is a tool part.
20
+ */
21
+ export declare const isToolPart: (part: AI.UIMessage["parts"][number]) => part is ToolPart;
@@ -1,11 +1,12 @@
1
- import { ClientTransport, CloseOptions } from '../../core/transport/types.js';
1
+ import { ClientSession } from '../../core/transport/types.js';
2
+ import { VercelInput, VercelOutput, VercelProjection } from '../codec/index.js';
2
3
  /**
3
- * Vercel chat transport: wraps a core ClientTransport to satisfy the
4
+ * Vercel chat transport: wraps a core ClientSession to satisfy the
4
5
  * ChatTransport interface that useChat expects.
5
6
  *
6
- * This is a thin adapter — the real logic lives in the core transport.
7
+ * This is a thin adapter — the real logic lives in the core client session.
7
8
  * The chat transport maps Vercel's sendMessages/reconnectToStream contract
8
- * to the core transport's send/cancel methods.
9
+ * to the core session's send/cancel methods.
9
10
  *
10
11
  * useChat manages message state before calling sendMessages:
11
12
  * - submit-message (new): appends the new user message, passes the full array
@@ -13,13 +14,20 @@ import { ClientTransport, CloseOptions } from '../../core/transport/types.js';
13
14
  * passes the truncated array with messageId set
14
15
  * - regenerate-message: truncates after the target, passes the truncated array
15
16
  *
16
- * The adapter uses `trigger` to determine the history/messages split:
17
- * - submit-message: last message is new (publish to channel), rest is history
17
+ * The adapter uses `(trigger, last-message role)` to determine the
18
+ * history/messages split:
19
+ * - submit-message + last message is a user message: that last message is new
20
+ * (publish to channel), rest is history. A new submit and an edit both take
21
+ * this path — an edit just carries a messageId.
22
+ * - submit-message + last message is an assistant already in the tree
23
+ * (continuation): no new messages, entire array is history
18
24
  * - regenerate-message: no new messages, entire array is history
19
25
  *
20
- * When messageId is set (edit or regeneration), the adapter computes fork
21
- * metadata (forkOf/parent) from the conversation tree so the server can
22
- * place the response on the correct branch.
26
+ * For an edit (submit-message with messageId) and for forking off an
27
+ * unresolved tool call, the adapter computes fork metadata (forkOf/parent)
28
+ * from the conversation tree so the server can place the response on the
29
+ * correct branch. Regeneration fork metadata is NOT computed here —
30
+ * `View.regenerate` derives forkOf/parent from the tree itself.
23
31
  */
24
32
  import type * as AI from 'ai';
25
33
  /**
@@ -40,23 +48,32 @@ export interface SendMessagesRequestContext {
40
48
  messageId?: string;
41
49
  /** Previous messages in the conversation (context for the LLM). */
42
50
  history: AI.UIMessage[];
43
- /** The new message(s) being sent (to publish to the channel). Empty for regeneration. */
51
+ /** The new message(s) being sent (to publish to the channel). Empty for regeneration and for continuations (an auto-submit where the last message is an already-tracked assistant). */
44
52
  messages: AI.UIMessage[];
45
- /** The msg-id of the message being forked (regenerated or edited). */
53
+ /** The codec-message-id of the message being forked the edited user message, or the preceding assistant when forking off an unresolved tool call. Undefined for regeneration (View.regenerate derives it) and fresh sends. */
46
54
  forkOf?: string;
47
- /** The msg-id of the predecessor in the conversation thread. */
55
+ /** The codec-message-id of the predecessor in the conversation thread. */
48
56
  parent?: string;
49
57
  }
50
58
  /** Options for customizing the ChatTransport behavior. */
51
59
  export interface ChatTransportOptions {
52
60
  /**
53
- * Customize the POST body before sending. Called by sendMessages()
54
- * with the conversation context. Return the body and headers for
55
- * the HTTP POST.
56
- *
57
- * Default: sends all previous messages as `history` in the body.
61
+ * Endpoint the transport POSTs the invocation pointer to, to wake the
62
+ * agent. Mirrors useChat's request-driven contract. Default `/api/chat`.
63
+ */
64
+ api?: string;
65
+ /** Fetch credentials mode for the invocation POST (e.g. `'include'`). */
66
+ credentials?: RequestCredentials;
67
+ /** Custom fetch implementation for the invocation POST. Defaults to `globalThis.fetch`. */
68
+ fetch?: typeof globalThis.fetch;
69
+ /**
70
+ * Customize the invocation POST before sending. Called by sendMessages()
71
+ * with the conversation context; the returned `body` is merged into the
72
+ * POST body (the run's invocation identifiers always take precedence) and
73
+ * `headers` are added to the request. Use it for auth headers or extra
74
+ * agent metadata.
58
75
  * @param context - The conversation context for the current request.
59
- * @returns The body and headers to use for the HTTP POST.
76
+ * @returns The body and headers to merge into the invocation POST.
60
77
  */
61
78
  prepareSendMessagesRequest?: (context: SendMessagesRequestContext) => {
62
79
  body?: Record<string, unknown>;
@@ -109,8 +126,8 @@ export interface ChatTransport {
109
126
  chatId: string;
110
127
  } & ChatRequestOptions) => Promise<ReadableStream<AI.UIMessageChunk> | null>;
111
128
  /** Close the underlying transport, releasing all resources. */
112
- close(options?: CloseOptions): Promise<void>;
113
- /** Whether an own-turn stream is currently being consumed by useChat. */
129
+ close(): Promise<void>;
130
+ /** Whether an own-run stream is currently being consumed by useChat. */
114
131
  readonly streaming: boolean;
115
132
  /**
116
133
  * Subscribe to streaming state changes. The callback fires when the
@@ -122,19 +139,19 @@ export interface ChatTransport {
122
139
  onStreamingChange(callback: (streaming: boolean) => void): () => void;
123
140
  }
124
141
  /**
125
- * Create a Vercel ChatTransport from a core ClientTransport.
142
+ * Create a Vercel ChatTransport from a core ClientSession.
126
143
  *
127
144
  * Exposes a `streaming` flag and `onStreamingChange` callback so that
128
- * `useMessageSync` can gate `setMessages` calls during active own-turn
145
+ * `useMessageSync` can gate `setMessages` calls during active own-run
129
146
  * streams, preventing the push/replace ID mismatch in useChat's `write()`.
130
147
  *
131
148
  * Note: concurrent `sendMessage` calls from the same user are a useChat
132
149
  * limitation that cannot be fixed from the transport layer. The
133
150
  * developer must respect useChat's `status` and only call `sendMessage`
134
151
  * when status is `'ready'`.
135
- * @param transport - The core client transport to wrap.
152
+ * @param session - The core client session to wrap.
136
153
  * @param chatOptions - Optional hooks for customizing request construction.
137
154
  * @returns A {@link ChatTransport} compatible with Vercel's useChat hook.
138
155
  */
139
- export declare const createChatTransport: (transport: ClientTransport<AI.UIMessageChunk, AI.UIMessage>, chatOptions?: ChatTransportOptions) => ChatTransport;
156
+ export declare const createChatTransport: (session: ClientSession<VercelInput, VercelOutput, VercelProjection, AI.UIMessage>, chatOptions?: ChatTransportOptions) => ChatTransport;
140
157
  export {};