agents 0.24.0 → 0.25.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 (170) hide show
  1. package/dist/{agent-routing-B2XLNMxq.d.ts → agent-routing-0DR0Tk2v.d.ts} +205 -132
  2. package/dist/agent-routing.d.ts +1 -1
  3. package/dist/agent-routing.js.map +1 -1
  4. package/dist/agent-tool-types.d.ts +28 -22
  5. package/dist/agent-tool-types.js +23 -1
  6. package/dist/agent-tool-types.js.map +1 -1
  7. package/dist/{agent-tools-y7zLfw4Q.js → agent-tools-CdJC-8Dc.js} +72 -9
  8. package/dist/agent-tools-CdJC-8Dc.js.map +1 -0
  9. package/dist/{agent-tools-Dj5Mzlw7.d.ts → agent-tools-YrATZJu2.d.ts} +34 -20
  10. package/dist/agent-tools.d.ts +20 -18
  11. package/dist/agent-tools.js.map +1 -1
  12. package/dist/ai-fm7xx1BK.js +312 -0
  13. package/dist/ai-fm7xx1BK.js.map +1 -0
  14. package/dist/base64-redaction-C1Uu29t5.js +59 -0
  15. package/dist/base64-redaction-C1Uu29t5.js.map +1 -0
  16. package/dist/browser/ai-sdk.d.ts +90 -0
  17. package/dist/browser/ai-sdk.js +51 -0
  18. package/dist/browser/ai-sdk.js.map +1 -0
  19. package/dist/browser/ai.d.ts +4 -4
  20. package/dist/browser/ai.js +1 -347
  21. package/dist/browser/index.d.ts +81 -79
  22. package/dist/browser/index.js +361 -2
  23. package/dist/browser/index.js.map +1 -0
  24. package/dist/browser/tanstack-ai.d.ts +96 -1
  25. package/dist/browser/tanstack-ai.js +62 -2
  26. package/dist/browser/tanstack-ai.js.map +1 -1
  27. package/dist/browser-DE3d-RLk.d.ts +275 -0
  28. package/dist/browser-tool-CQ10e6Kj.js +480 -0
  29. package/dist/browser-tool-CQ10e6Kj.js.map +1 -0
  30. package/dist/browser-tool-DuNdlwZ9.d.ts +73 -0
  31. package/dist/capability-B4WbF81e.js.map +1 -1
  32. package/dist/{capability-runner-BUBa6Ake.d.ts → capability-runner-DBAnGr6L.d.ts} +7 -2
  33. package/dist/chat/index.d.ts +340 -234
  34. package/dist/chat/index.js +592 -66
  35. package/dist/chat/index.js.map +1 -1
  36. package/dist/chat/react.d.ts +42 -2
  37. package/dist/chat/react.js +191 -35
  38. package/dist/chat/react.js.map +1 -1
  39. package/dist/chat/transport.d.ts +1 -1
  40. package/dist/chat/transport.js +1 -1
  41. package/dist/chat-sdk/index.d.ts +17 -3
  42. package/dist/chat-sdk/index.js +28 -2
  43. package/dist/chat-sdk/index.js.map +1 -1
  44. package/dist/{client-C9DAjZIY.js → client-4OlMIJx-.js} +102 -29
  45. package/dist/client-4OlMIJx-.js.map +1 -0
  46. package/dist/{client-BxdkCuVy.d.ts → client-je3koD9Z.d.ts} +45 -10
  47. package/dist/client.d.ts +7 -5
  48. package/dist/client.js +2 -2
  49. package/dist/{connector-CptFKzRh.js → connector-58XDGvc3.js} +251 -120
  50. package/dist/connector-58XDGvc3.js.map +1 -0
  51. package/dist/{connector-CkQD4MK3.d.ts → connector-Cl-VqPmA.d.ts} +244 -146
  52. package/dist/context/index.d.ts +29 -0
  53. package/dist/context/index.js +64 -17
  54. package/dist/context/index.js.map +1 -1
  55. package/dist/current-agent-DhoDkSnH.js.map +1 -1
  56. package/dist/{current-agent-C4w86kcN.d.ts → current-agent-vAk_5JMt.d.ts} +4 -4
  57. package/dist/{durable-object-lifecycle-ei7M7lqB.d.ts → durable-object-lifecycle-HhgOMWq9.d.ts} +15 -7
  58. package/dist/harnesses/pi/index.d.ts +348 -0
  59. package/dist/harnesses/pi/index.js +754 -0
  60. package/dist/harnesses/pi/index.js.map +1 -0
  61. package/dist/images-iiTDSyRu.js +1631 -0
  62. package/dist/images-iiTDSyRu.js.map +1 -0
  63. package/dist/{index-Dlgtd3Mj.d.ts → index-BreL0YrQ.d.ts} +2 -2
  64. package/dist/index-kbSUIer3.d.ts +343 -0
  65. package/dist/index.d.ts +46 -44
  66. package/dist/index.js +1 -1
  67. package/dist/internal_context.d.ts +1 -1
  68. package/dist/lifecycle/index.d.ts +3 -3
  69. package/dist/lifecycle/index.js +1 -1
  70. package/dist/{lifecycle-Mm_jQh7r.js → lifecycle-CFu6OV03.js} +39 -10
  71. package/dist/{lifecycle-Mm_jQh7r.js.map → lifecycle-CFu6OV03.js.map} +1 -1
  72. package/dist/mcp/client/index.d.ts +20 -20
  73. package/dist/mcp/client/x402.js +21 -19
  74. package/dist/mcp/client/x402.js.map +1 -1
  75. package/dist/mcp/index.d.ts +35 -35
  76. package/dist/mcp/index.js +1 -1
  77. package/dist/{message-builder-BymO4N_D.js → message-builder-DAl9AhHH.js} +89 -4
  78. package/dist/message-builder-DAl9AhHH.js.map +1 -0
  79. package/dist/models/ai-sdk/index.d.ts +353 -0
  80. package/dist/models/ai-sdk/index.js +2443 -0
  81. package/dist/models/ai-sdk/index.js.map +1 -0
  82. package/dist/models/pi-ai/index.d.ts +313 -0
  83. package/dist/models/pi-ai/index.js +1795 -0
  84. package/dist/models/pi-ai/index.js.map +1 -0
  85. package/dist/observability/ai/index.js +20 -4
  86. package/dist/observability/ai/index.js.map +1 -1
  87. package/dist/{protocol-B0nh6KNf.js → protocol-kHsr-f0X.js} +26 -12
  88. package/dist/{protocol-B0nh6KNf.js.map → protocol-kHsr-f0X.js.map} +1 -1
  89. package/dist/queue/index.d.ts +3 -3
  90. package/dist/queue/index.js +1 -1
  91. package/dist/{queue-BC9F5cUo.js → queue-BB-zfIYF.js} +2 -2
  92. package/dist/{queue-BC9F5cUo.js.map → queue-BB-zfIYF.js.map} +1 -1
  93. package/dist/react.d.ts +6 -6
  94. package/dist/react.js +160 -64
  95. package/dist/react.js.map +1 -1
  96. package/dist/{retries-D9B2UCq3.d.ts → retries-CV6AkXmQ.d.ts} +18 -9
  97. package/dist/retries.d.ts +11 -9
  98. package/dist/retries.js +11 -1
  99. package/dist/retries.js.map +1 -1
  100. package/dist/routing/index.d.ts +2 -2
  101. package/dist/routing/index.js +1 -1
  102. package/dist/{scheduler-D_KHqxBa.js → scheduler-DZ3xQfeK.js} +2 -2
  103. package/dist/{scheduler-D_KHqxBa.js.map → scheduler-DZ3xQfeK.js.map} +1 -1
  104. package/dist/{scheduler-BGq6M5Kd.d.ts → scheduler-RdACNXDP.d.ts} +3 -3
  105. package/dist/schedules/index.d.ts +1 -1
  106. package/dist/schedules/index.js +1 -1
  107. package/dist/serializable.d.ts +1 -1
  108. package/dist/sessions/index.d.ts +70 -3
  109. package/dist/sessions/index.js +276 -67
  110. package/dist/sessions/index.js.map +1 -1
  111. package/dist/skills/index.d.ts +29 -314
  112. package/dist/socket-address.d.ts +16 -0
  113. package/dist/socket-address.js +19 -0
  114. package/dist/socket-address.js.map +1 -0
  115. package/dist/{src-BNU3ZiJM.js → src-BZeu-SCD.js} +423 -115
  116. package/dist/src-BZeu-SCD.js.map +1 -0
  117. package/dist/state/index.d.ts +1 -1
  118. package/dist/state/index.js +1 -1
  119. package/dist/streams/index.d.ts +1 -1
  120. package/dist/streams/index.js +1 -1
  121. package/dist/{streams-BcE8JP2X.d.ts → streams-Cmkj9QfW.d.ts} +4 -2
  122. package/dist/{streams-CCPRV6dt.js → streams-DW-UCOUc.js} +9 -2
  123. package/dist/streams-DW-UCOUc.js.map +1 -0
  124. package/dist/sub-routing.d.ts +12 -12
  125. package/dist/tasks/index.d.ts +1 -1
  126. package/dist/tasks/index.js +1 -1
  127. package/dist/{tasks-D4nLqVSI.js → tasks-68DESxf0.js} +2 -2
  128. package/dist/{tasks-D4nLqVSI.js.map → tasks-68DESxf0.js.map} +1 -1
  129. package/dist/{tasks-V2lCT8ZV.d.ts → tasks-9YxYtByh.d.ts} +2 -2
  130. package/dist/transport-PfFnt-Ld.d.ts +525 -0
  131. package/dist/{types-DCD6BNZH.d.ts → types-BA4anrjI.d.ts} +2 -2
  132. package/dist/voice/index.d.ts +2 -2
  133. package/dist/websockets/index.d.ts +23 -6
  134. package/dist/websockets/index.js +1 -1
  135. package/dist/{websockets-D7IzWbZb.js → websockets-Ci-LZFHH.js} +45 -20
  136. package/dist/{websockets-D7IzWbZb.js.map → websockets-Ci-LZFHH.js.map} +1 -1
  137. package/dist/wire-types-CnMt6_HR.js.map +1 -1
  138. package/dist/wire-types-CrjKvDyi.d.ts +300 -0
  139. package/dist/workflow-types.d.ts +25 -25
  140. package/dist/workflows.d.ts +21 -21
  141. package/dist/workflows.js +1 -1
  142. package/dist/{ws-chat-transport-UNRIS2xl.d.ts → ws-chat-transport-BbT1A5Lc.d.ts} +51 -2
  143. package/dist/{ws-chat-transport-rWwta645.js → ws-chat-transport-cqMKq3IY.js} +143 -16
  144. package/dist/ws-chat-transport-cqMKq3IY.js.map +1 -0
  145. package/docs/agent-tools.md +29 -4
  146. package/docs/browse-the-web.md +87 -5
  147. package/docs/chat-agents.md +124 -16
  148. package/docs/context.md +27 -0
  149. package/docs/durable-execution.md +2 -0
  150. package/docs/harnesses/pi.md +91 -0
  151. package/docs/human-in-the-loop.md +4 -0
  152. package/docs/index.md +3 -0
  153. package/docs/lifecycle.md +20 -4
  154. package/docs/models-pi-ai.md +325 -0
  155. package/docs/models.md +504 -0
  156. package/docs/resumable-streaming.md +2 -0
  157. package/docs/routing.md +13 -13
  158. package/docs/sessions.md +36 -1
  159. package/docs/state.md +1 -0
  160. package/docs/sub-agents.md +9 -0
  161. package/package.json +40 -2
  162. package/dist/agent-tools-y7zLfw4Q.js.map +0 -1
  163. package/dist/browser/ai.js.map +0 -1
  164. package/dist/client-C9DAjZIY.js.map +0 -1
  165. package/dist/client-tools-aIBO0Fk7.d.ts +0 -53
  166. package/dist/connector-CptFKzRh.js.map +0 -1
  167. package/dist/message-builder-BymO4N_D.js.map +0 -1
  168. package/dist/src-BNU3ZiJM.js.map +0 -1
  169. package/dist/streams-CCPRV6dt.js.map +0 -1
  170. package/dist/ws-chat-transport-rWwta645.js.map +0 -1
@@ -0,0 +1,300 @@
1
+ import { JSONSchema7, Tool, ToolSet, UIMessage } from "ai";
2
+
3
+ //#region src/chat/client-tools.d.ts
4
+ /**
5
+ * Wire-format tool schema sent from the client.
6
+ * Uses `parameters` (JSONSchema7) rather than AI SDK's `inputSchema`
7
+ * because Zod schemas cannot be serialized over the wire.
8
+ */
9
+ type ClientToolSchema = {
10
+ /** Unique name for the tool */ name: string /** Human-readable description of what the tool does */;
11
+ description?: Tool["description"] /** JSON Schema defining the tool's input parameters */;
12
+ parameters?: JSONSchema7;
13
+ };
14
+ /**
15
+ * Executes a client-defined tool and returns its output.
16
+ *
17
+ * Used for the RPC path (e.g. a parent agent delegating to a Think sub-agent)
18
+ * where the caller can run the client tools itself, rather than the
19
+ * browser/WebSocket path where results are sent back asynchronously.
20
+ */
21
+ type ClientToolExecutor = (call: {
22
+ /** The name of the client tool the model called. */ toolName: string /** The model-generated input for the tool call. */;
23
+ input: unknown /** The AI SDK tool-call id for the invocation. */;
24
+ toolCallId: string;
25
+ }) => unknown | Promise<unknown>;
26
+ /**
27
+ * Converts client tool schemas to AI SDK tool format.
28
+ *
29
+ * By default these tools have no `execute` function — when the AI model calls
30
+ * them, the tool call is sent back to the client for execution.
31
+ *
32
+ * When `options.execute` is provided, each tool is built WITH an `execute` that
33
+ * delegates to it. This is used by the RPC path (e.g. a parent agent driving a
34
+ * Think sub-agent) so the model's client-tool call is resolved inline within
35
+ * the same turn.
36
+ *
37
+ * @param clientTools - Array of tool schemas from the client
38
+ * @param options - Optional `execute` delegate to run the tools inline
39
+ * @returns Record of AI SDK tools that can be spread into your tools object
40
+ */
41
+ declare function createToolsFromClientSchemas(
42
+ clientTools?: ClientToolSchema[],
43
+ options?: {
44
+ execute?: ClientToolExecutor;
45
+ }
46
+ ): ToolSet;
47
+ //#endregion
48
+ //#region src/chat/protocol.d.ts
49
+ /**
50
+ * Wire protocol message type constants for the cf_agent_chat_* protocol.
51
+ *
52
+ * These are the string values used on the wire between agent servers and
53
+ * clients. Both @cloudflare/ai-chat (via its MessageType enum) and
54
+ * @cloudflare/think use these values.
55
+ */
56
+ declare const STREAM_RESUME_NONE_REASONS: {
57
+ /** No active, pending, or terminal stream exists for this agent. */ readonly IDLE: "idle" /** An active tool continuation is owned by another live connection. */;
58
+ readonly CONTINUATION_OWNED: "continuation-owned";
59
+ };
60
+ type StreamResumeNoneReason =
61
+ (typeof STREAM_RESUME_NONE_REASONS)[keyof typeof STREAM_RESUME_NONE_REASONS];
62
+ declare const CHAT_MESSAGE_TYPES: {
63
+ readonly CHAT_MESSAGES: "cf_agent_chat_messages";
64
+ readonly USE_CHAT_REQUEST: "cf_agent_use_chat_request";
65
+ readonly USE_CHAT_RESPONSE: "cf_agent_use_chat_response";
66
+ readonly CHAT_CLEAR: "cf_agent_chat_clear";
67
+ readonly CHAT_REQUEST_CANCEL: "cf_agent_chat_request_cancel";
68
+ readonly STREAM_RESUMING: "cf_agent_stream_resuming";
69
+ readonly STREAM_RESUME_ACK: "cf_agent_stream_resume_ack";
70
+ readonly STREAM_RESUME_REQUEST: "cf_agent_stream_resume_request";
71
+ readonly STREAM_RESUME_NONE: "cf_agent_stream_resume_none";
72
+ readonly STREAM_PENDING: "cf_agent_stream_pending";
73
+ readonly TOOL_RESULT: "cf_agent_tool_result";
74
+ readonly TOOL_APPROVAL: "cf_agent_tool_approval";
75
+ readonly MESSAGE_UPDATED: "cf_agent_message_updated";
76
+ readonly CHAT_RECOVERING: "cf_agent_chat_recovering";
77
+ };
78
+ //#endregion
79
+ //#region src/chat/wire-types.d.ts
80
+ /**
81
+ * How a chat request ended.
82
+ *
83
+ * - `completed`: the turn finished normally.
84
+ * - `error`: the turn failed.
85
+ * - `aborted`: the turn was cancelled while it ran.
86
+ * - `skipped`: the turn never ran, because a newer send superseded it or the
87
+ * concurrency policy dropped it.
88
+ * - `recovering`: this request stopped, but recovery continues the same turn
89
+ * under a new request that carries the same `messageIds`.
90
+ */
91
+ type ChatTurnOutcome =
92
+ | "completed"
93
+ | "error"
94
+ | "aborted"
95
+ | "skipped"
96
+ | "recovering";
97
+ /**
98
+ * Enum for message types to improve type safety and maintainability
99
+ */
100
+ declare enum MessageType {
101
+ CF_AGENT_CHAT_MESSAGES = "cf_agent_chat_messages",
102
+ CF_AGENT_USE_CHAT_REQUEST = "cf_agent_use_chat_request",
103
+ CF_AGENT_USE_CHAT_RESPONSE = "cf_agent_use_chat_response",
104
+ CF_AGENT_CHAT_CLEAR = "cf_agent_chat_clear",
105
+ CF_AGENT_CHAT_REQUEST_CANCEL = "cf_agent_chat_request_cancel",
106
+ /** Sent by server when client connects and there's an active stream to resume */
107
+ CF_AGENT_STREAM_RESUMING = "cf_agent_stream_resuming",
108
+ /** Sent by client to acknowledge stream resuming notification and request chunks */
109
+ CF_AGENT_STREAM_RESUME_ACK = "cf_agent_stream_resume_ack",
110
+ /** Sent by client after message handler is ready, requesting stream resume check */
111
+ CF_AGENT_STREAM_RESUME_REQUEST = "cf_agent_stream_resume_request",
112
+ /** Sent by server when client requests resume but no active stream exists */
113
+ CF_AGENT_STREAM_RESUME_NONE = "cf_agent_stream_resume_none",
114
+ /**
115
+ * Sent by server when a turn is accepted but its resumable stream has not
116
+ * started yet (queued / debouncing / waiting on MCP / async setup). Tells a
117
+ * reconnecting client to keep waiting rather than resolve its resume probe to
118
+ * "no stream". Resolved by a later `CF_AGENT_STREAM_RESUMING` (stream started)
119
+ * or `CF_AGENT_STREAM_RESUME_NONE` (settled without streaming). See #1784.
120
+ */
121
+ CF_AGENT_STREAM_PENDING = "cf_agent_stream_pending",
122
+ /** Client sends tool result to server (for client-side tools) */
123
+ CF_AGENT_TOOL_RESULT = "cf_agent_tool_result",
124
+ /** Server notifies client that a message was updated (e.g., tool result applied) */
125
+ CF_AGENT_MESSAGE_UPDATED = "cf_agent_message_updated",
126
+ /** Client sends tool approval response to server (for tools with needsApproval) */
127
+ CF_AGENT_TOOL_APPROVAL = "cf_agent_tool_approval",
128
+ /**
129
+ * Server→client progress hint: a durable chat turn is being recovered
130
+ * (interrupted by a deploy/eviction or a stream-stall watchdog abort and now
131
+ * resuming). Sent when a recovery continuation is scheduled and cleared on
132
+ * every terminal outcome. (`@cloudflare/think` also replays it on connect;
133
+ * `@cloudflare/ai-chat` broadcasts the live signal only — see #1645.)
134
+ * Backward-compatible — clients that don't understand it ignore it. See #1620.
135
+ */
136
+ CF_AGENT_CHAT_RECOVERING = "cf_agent_chat_recovering"
137
+ }
138
+ /**
139
+ * Types of messages sent from the Agent to clients
140
+ */
141
+ type OutgoingMessage<ChatMessage extends UIMessage = UIMessage> =
142
+ | {
143
+ /** Indicates this message is a command to clear chat history */ type: MessageType.CF_AGENT_CHAT_CLEAR;
144
+ }
145
+ | {
146
+ /** Indicates this message contains updated chat messages */ type: MessageType.CF_AGENT_CHAT_MESSAGES /** Array of chat messages */;
147
+ messages: readonly ChatMessage[];
148
+ /**
149
+ * Set on the transcript a server sends to a newly connected client. It
150
+ * predates any request the client buffered while disconnected, so the
151
+ * client keeps those optimistic sends; any other snapshot is
152
+ * authoritative (#1983).
153
+ */
154
+ connect?: boolean;
155
+ }
156
+ | {
157
+ /** Indicates this message is a response to a chat request */ type: MessageType.CF_AGENT_USE_CHAT_RESPONSE /** Unique ID of the request this response corresponds to */;
158
+ id: string /** Content body of the response */;
159
+ body: string /** Whether this is the final chunk of the response */;
160
+ done: boolean /** Whether this response contains an error */;
161
+ error?: boolean /** Whether this is a continuation (append to last assistant message) */;
162
+ continuation?: boolean /** Whether this chunk is being replayed from storage (stream resumption) */;
163
+ replay?: boolean /** Signals that replay of stored chunks is complete (stream is still active) */;
164
+ replayComplete?: boolean;
165
+ /**
166
+ * Index of this chunk within its stream. A live chunk carries the index
167
+ * its replay will carry, so a client can skip replayed chunks it has
168
+ * already applied.
169
+ */
170
+ seq?: number;
171
+ /**
172
+ * IDs of the user messages the originating request carried (the
173
+ * trailing user messages of its `messages`). Set on terminal frames
174
+ * (`done` or `error`), live and replayed, when the server knows them,
175
+ * so a client can settle exactly the sends a completion, error, or
176
+ * cancellation belongs to.
177
+ */
178
+ messageIds?: string[];
179
+ /**
180
+ * How the request ended, on its terminal `done` frame. Absent means
181
+ * `"error"` when the frame (or an earlier frame for the request) carried
182
+ * `error`, and `"completed"` otherwise.
183
+ */
184
+ outcome?: ChatTurnOutcome;
185
+ }
186
+ | {
187
+ /** Indicates the server is resuming an active stream */ type: MessageType.CF_AGENT_STREAM_RESUMING /** The request ID of the stream being resumed */;
188
+ id: string /** Present when this offer directly answers a client resume probe. */;
189
+ probeId?: string;
190
+ }
191
+ | {
192
+ /** Server notifies client that a message was updated (e.g., tool result applied) */ type: MessageType.CF_AGENT_MESSAGE_UPDATED /** The updated message */;
193
+ message: ChatMessage;
194
+ }
195
+ | {
196
+ /** Server responds to a resume request with no stream for this client. */ type: MessageType.CF_AGENT_STREAM_RESUME_NONE;
197
+ /**
198
+ * Why no stream was offered. Only `idle` proves global inactivity;
199
+ * omitted by older servers and by non-authoritative delayed releases.
200
+ */
201
+ reason?: StreamResumeNoneReason /** Correlates an authoritative response to its client resume probe. */;
202
+ probeId?: string;
203
+ }
204
+ | {
205
+ /**
206
+ * Server signals an accepted turn whose resumable stream has not started
207
+ * yet — the client should keep waiting for `STREAM_RESUMING` (or a later
208
+ * `STREAM_RESUME_NONE`) rather than give up. See #1784.
209
+ */
210
+ type: MessageType.CF_AGENT_STREAM_PENDING /** The accepted request id, when known. */;
211
+ id?: string /** Correlates a direct keep-waiting response to its client probe. */;
212
+ probeId?: string;
213
+ }
214
+ | {
215
+ /**
216
+ * Progress hint: a durable chat turn is being recovered (`recovering:
217
+ * true`) or recovery has resolved (`recovering: false`). Purely advisory;
218
+ * a client renders a "recovering…" indicator while true.
219
+ */
220
+ type: MessageType.CF_AGENT_CHAT_RECOVERING /** Whether recovery is in progress (true) or has resolved (false). */;
221
+ recovering: boolean /** The recovery-root request id of the turn being recovered, if known. */;
222
+ id?: string;
223
+ };
224
+ /**
225
+ * Types of messages sent from clients to the Agent
226
+ */
227
+ type IncomingMessage<ChatMessage extends UIMessage = UIMessage> =
228
+ | {
229
+ /** Indicates this message is a command to clear chat history */ type: MessageType.CF_AGENT_CHAT_CLEAR;
230
+ }
231
+ | {
232
+ /** Indicates this message is a request to the chat API */ type: MessageType.CF_AGENT_USE_CHAT_REQUEST /** Unique ID for this request */;
233
+ id: string /** Request initialization options */;
234
+ init: Pick<
235
+ RequestInit,
236
+ | "method"
237
+ | "keepalive"
238
+ | "headers"
239
+ | "body"
240
+ | "redirect"
241
+ | "integrity"
242
+ | "credentials"
243
+ | "mode"
244
+ | "referrer"
245
+ | "referrerPolicy"
246
+ | "window"
247
+ >;
248
+ }
249
+ | {
250
+ /** Indicates this message contains updated chat messages */ type: MessageType.CF_AGENT_CHAT_MESSAGES /** Array of chat messages */;
251
+ messages: ChatMessage[];
252
+ }
253
+ | {
254
+ /** Indicates the user wants to stop generation of this message */ type: MessageType.CF_AGENT_CHAT_REQUEST_CANCEL;
255
+ id: string;
256
+ }
257
+ | {
258
+ /** Client acknowledges stream resuming notification and is ready to receive chunks */ type: MessageType.CF_AGENT_STREAM_RESUME_ACK /** The request ID of the stream being resumed */;
259
+ id: string;
260
+ }
261
+ | {
262
+ /** Client requests stream resume check after message handler is registered */ type: MessageType.CF_AGENT_STREAM_RESUME_REQUEST /** Opaque correlation id echoed by direct server responses. */;
263
+ probeId?: string;
264
+ }
265
+ | {
266
+ /** Client sends tool result to server (for client-side tools) */ type: MessageType.CF_AGENT_TOOL_RESULT /** The tool call ID this result is for */;
267
+ toolCallId: string /** The name of the tool */;
268
+ toolName: string /** The output from the tool execution */;
269
+ output: unknown /** Override the tool part state (e.g. "output-error" for custom denial) */;
270
+ state?:
271
+ | "output-available"
272
+ | "output-error" /** Error message when state is "output-error" */;
273
+ errorText?: string /** Whether server should auto-continue the conversation after applying result */;
274
+ autoContinue?: boolean /** Client tool schemas for continuation (client is source of truth) */;
275
+ clientTools?: Array<{
276
+ name: string;
277
+ description?: string;
278
+ parameters?: JSONSchema7;
279
+ }>;
280
+ }
281
+ | {
282
+ /** Client sends tool approval response to server (for tools with needsApproval) */ type: MessageType.CF_AGENT_TOOL_APPROVAL /** The tool call ID this approval is for */;
283
+ toolCallId: string /** Whether the tool execution was approved */;
284
+ approved: boolean /** Whether server should auto-continue the conversation after applying approval */;
285
+ autoContinue?: boolean;
286
+ };
287
+ //#endregion
288
+ export {
289
+ CHAT_MESSAGE_TYPES as a,
290
+ ClientToolExecutor as c,
291
+ OutgoingMessage as i,
292
+ ClientToolSchema as l,
293
+ IncomingMessage as n,
294
+ STREAM_RESUME_NONE_REASONS as o,
295
+ MessageType as r,
296
+ StreamResumeNoneReason as s,
297
+ ChatTurnOutcome as t,
298
+ createToolsFromClientSchemas as u
299
+ };
300
+ //# sourceMappingURL=wire-types-CrjKvDyi.d.ts.map
@@ -1,29 +1,29 @@
1
1
  import {
2
- Ct as WorkflowQueryCriteria,
3
- Et as WorkflowTrackingRow,
4
- St as WorkflowProgressCallback,
5
- Tt as WorkflowStatus,
6
- _t as WorkflowErrorCallback,
7
- at as AgentWorkflowOrigin,
8
- bt as WorkflowInfo,
9
- ct as AgentWorkflowStep,
10
- dt as RunWorkflowOptions,
11
- ft as WaitForApprovalOptions,
12
- gt as WorkflowCompleteCallback,
13
- ht as WorkflowCallbackType,
14
- it as AgentWorkflowInternalParams,
15
- lt as ApprovalEventPayload,
16
- mt as WorkflowCallbackBase,
17
- ot as AgentWorkflowParams,
18
- pt as WorkflowCallback,
19
- rt as AgentWorkflowEvent,
20
- st as AgentWorkflowPathStep,
21
- ut as DefaultProgress,
22
- vt as WorkflowEventCallback,
23
- wt as WorkflowRejectedError,
24
- xt as WorkflowPage,
25
- yt as WorkflowEventPayload
26
- } from "./agent-routing-B2XLNMxq.js";
2
+ Ct as WorkflowInfo,
3
+ Dt as WorkflowRejectedError,
4
+ Et as WorkflowQueryCriteria,
5
+ Ot as WorkflowStatus,
6
+ St as WorkflowEventPayload,
7
+ Tt as WorkflowProgressCallback,
8
+ _t as WorkflowCallbackBase,
9
+ bt as WorkflowErrorCallback,
10
+ ct as AgentWorkflowOrigin,
11
+ dt as AgentWorkflowStep,
12
+ ft as ApprovalEventPayload,
13
+ gt as WorkflowCallback,
14
+ ht as WaitForApprovalOptions,
15
+ kt as WorkflowTrackingRow,
16
+ lt as AgentWorkflowParams,
17
+ mt as RunWorkflowOptions,
18
+ ot as AgentWorkflowEvent,
19
+ pt as DefaultProgress,
20
+ st as AgentWorkflowInternalParams,
21
+ ut as AgentWorkflowPathStep,
22
+ vt as WorkflowCallbackType,
23
+ wt as WorkflowPage,
24
+ xt as WorkflowEventCallback,
25
+ yt as WorkflowCompleteCallback
26
+ } from "./agent-routing-0DR0Tk2v.js";
27
27
  export {
28
28
  AgentWorkflowEvent,
29
29
  AgentWorkflowInternalParams,
@@ -1,26 +1,26 @@
1
1
  import {
2
- Ct as WorkflowQueryCriteria,
3
- Et as WorkflowTrackingRow,
4
- St as WorkflowProgressCallback,
5
- Tt as WorkflowStatus,
6
- _t as WorkflowErrorCallback,
7
- bt as WorkflowInfo,
2
+ Ct as WorkflowInfo,
3
+ Dt as WorkflowRejectedError,
4
+ Et as WorkflowQueryCriteria,
5
+ Ot as WorkflowStatus,
6
+ St as WorkflowEventPayload,
7
+ Tt as WorkflowProgressCallback,
8
+ bt as WorkflowErrorCallback,
8
9
  c as Agent,
9
- ct as AgentWorkflowStep,
10
- dt as RunWorkflowOptions,
11
- ft as WaitForApprovalOptions,
12
- gt as WorkflowCompleteCallback,
13
- ht as WorkflowCallbackType,
14
- lt as ApprovalEventPayload,
15
- ot as AgentWorkflowParams,
16
- pt as WorkflowCallback,
17
- rt as AgentWorkflowEvent,
18
- ut as DefaultProgress,
19
- vt as WorkflowEventCallback,
20
- wt as WorkflowRejectedError,
21
- xt as WorkflowPage,
22
- yt as WorkflowEventPayload
23
- } from "./agent-routing-B2XLNMxq.js";
10
+ dt as AgentWorkflowStep,
11
+ ft as ApprovalEventPayload,
12
+ gt as WorkflowCallback,
13
+ ht as WaitForApprovalOptions,
14
+ kt as WorkflowTrackingRow,
15
+ lt as AgentWorkflowParams,
16
+ mt as RunWorkflowOptions,
17
+ ot as AgentWorkflowEvent,
18
+ pt as DefaultProgress,
19
+ vt as WorkflowCallbackType,
20
+ wt as WorkflowPage,
21
+ xt as WorkflowEventCallback,
22
+ yt as WorkflowCompleteCallback
23
+ } from "./agent-routing-0DR0Tk2v.js";
24
24
  import { WorkflowEntrypoint, WorkflowEvent } from "cloudflare:workers";
25
25
 
26
26
  //#region src/workflows.d.ts
package/dist/workflows.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { isInternalJsStubProp } from "./utils.js";
2
2
  import { getAgentByName } from "./agent-routing.js";
3
- import "./src-BNU3ZiJM.js";
3
+ import "./src-BZeu-SCD.js";
4
4
  import { WorkflowRejectedError } from "./workflow-types.js";
5
5
  import { WorkflowEntrypoint } from "cloudflare:workers";
6
6
  //#region src/workflows.ts
@@ -1,5 +1,35 @@
1
1
  import { ChatTransport, UIMessage, UIMessageChunk } from "ai";
2
2
 
3
+ //#region src/chat/replay-dedupe.d.ts
4
+ /**
5
+ * Replay de-duplication for continuation streams (#1951).
6
+ *
7
+ * A continuation appends to an assistant message this client may already have
8
+ * rendered live. After a reconnect the server replays the continuation's
9
+ * whole buffer, and applying it on top of the live-rendered bytes would
10
+ * duplicate them. Every live and replayed chunk frame carries its index in
11
+ * the stream (`seq`), so a client that records how far it applied each
12
+ * stream can drop the replayed chunks it already has.
13
+ *
14
+ * Non-continuation replays are left alone: the client resets the message and
15
+ * rebuilds it from chunk 0 for those.
16
+ */
17
+ type ChunkFrame = {
18
+ body?: string;
19
+ continuation?: boolean;
20
+ replay?: boolean;
21
+ seq?: number;
22
+ };
23
+ /** Highest chunk `seq` this client applied, per request id. */
24
+ declare class AppliedChunkLedger {
25
+ private readonly applied;
26
+ record(requestId: string, seq: number | undefined): void;
27
+ /** Whether `frame` replays a continuation chunk this client already applied. */
28
+ isAppliedReplay(requestId: string, frame: ChunkFrame): boolean;
29
+ forget(requestId: string): void;
30
+ clear(): void;
31
+ }
32
+ //#endregion
3
33
  //#region src/chat/ws-chat-transport.d.ts
4
34
  /**
5
35
  * Agent-like interface for sending/receiving WebSocket messages.
@@ -7,7 +37,7 @@ import { ChatTransport, UIMessage, UIMessageChunk } from "ai";
7
37
  * `useAgent` from `agents/react`.
8
38
  */
9
39
  interface AgentConnection {
10
- send: (data: string) => void;
40
+ send: (data: string) => boolean | void;
11
41
  addEventListener: (
12
42
  type: string,
13
43
  listener: (event: MessageEvent) => void,
@@ -44,6 +74,13 @@ type WebSocketChatTransportOptions<ChatMessage extends UIMessage = UIMessage> =
44
74
  * @default false
45
75
  */
46
76
  cancelOnClientAbort?: boolean;
77
+ /**
78
+ * Called when a `submit-message` request frame was buffered rather than sent
79
+ * immediately (the socket was not OPEN, so PartySocket queued it for the next
80
+ * reconnect). The hook uses this to preserve the optimistic message across the
81
+ * reconnect transcript replay. `messageId` is the submitted user message's id.
82
+ */
83
+ onRequestBuffered?: (messageId: string | undefined) => void;
47
84
  };
48
85
  /**
49
86
  * ChatTransport that sends messages over WebSocket and returns a
@@ -61,7 +98,13 @@ declare class WebSocketChatTransport<
61
98
  private prepareBody?;
62
99
  private activeRequestIds?;
63
100
  private cancelOnClientAbort;
101
+ private onRequestBuffered?;
64
102
  private _resumeResolver;
103
+ /**
104
+ * Continuation chunks this client applied, shared with the hook's fallback
105
+ * observer so a replay after reconnect skips them on either path (#1951).
106
+ */
107
+ readonly appliedChunks: AppliedChunkLedger;
65
108
  private _resumeNoneResolver;
66
109
  private _onStreamPending;
67
110
  private _retryResumeProbe;
@@ -84,6 +127,12 @@ declare class WebSocketChatTransport<
84
127
  * clients can detach locally without stopping server work.
85
128
  */
86
129
  cancelActiveServerTurn(): boolean;
130
+ /**
131
+ * The server turn this transport last attached to that has not reported a
132
+ * terminal frame. A socket close ends the local stream but keeps this set,
133
+ * since the server keeps running the turn.
134
+ */
135
+ get activeServerTurnId(): string | null;
87
136
  private sendCancelFrame;
88
137
  private setActiveServerTurn;
89
138
  private clearActiveServerTurn;
@@ -181,4 +230,4 @@ export {
181
230
  WebSocketChatTransportOptions as r,
182
231
  AgentConnection as t
183
232
  };
184
- //# sourceMappingURL=ws-chat-transport-UNRIS2xl.d.ts.map
233
+ //# sourceMappingURL=ws-chat-transport-BbT1A5Lc.d.ts.map