agents 0.20.0 → 0.21.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 (87) hide show
  1. package/README.md +50 -12
  2. package/dist/{agent-tool-types-Btk9ETS-.d.ts → agent-tool-types-CzGGB-20.d.ts} +403 -115
  3. package/dist/agent-tool-types.d.ts +1 -1
  4. package/dist/{agent-tools-UuScsJg3.d.ts → agent-tools-zR2d5uij.d.ts} +2 -2
  5. package/dist/agent-tools.d.ts +24 -8
  6. package/dist/agent-tools.js +14 -6
  7. package/dist/agent-tools.js.map +1 -1
  8. package/dist/browser/ai.d.ts +5 -3
  9. package/dist/browser/ai.js +86 -7
  10. package/dist/browser/ai.js.map +1 -1
  11. package/dist/browser/index.d.ts +1 -1
  12. package/dist/browser/index.js +1 -1
  13. package/dist/browser/tanstack-ai.js +13 -1
  14. package/dist/browser/tanstack-ai.js.map +1 -1
  15. package/dist/chat/index.d.ts +31 -2
  16. package/dist/chat/index.js +57 -2
  17. package/dist/chat/index.js.map +1 -1
  18. package/dist/chat/react.d.ts +5 -179
  19. package/dist/chat/react.js +18 -555
  20. package/dist/chat/react.js.map +1 -1
  21. package/dist/chat/transport.d.ts +10 -0
  22. package/dist/chat/transport.js +2 -0
  23. package/dist/chat-sdk/index.d.ts +1 -1
  24. package/dist/client.d.ts +1 -1
  25. package/dist/cloudflare-BduZwmYK.js +204 -0
  26. package/dist/cloudflare-BduZwmYK.js.map +1 -0
  27. package/dist/{connector-v2M1zlZp.d.ts → connector-CkQD4MK3.d.ts} +20 -3
  28. package/dist/{connector-KEJnl6e5.js → connector-CptFKzRh.js} +158 -40
  29. package/dist/connector-CptFKzRh.js.map +1 -0
  30. package/dist/{handler-stateless-8hQN_kC3.js → handler-stateless-CIkKPETH.js} +20 -69
  31. package/dist/handler-stateless-CIkKPETH.js.map +1 -0
  32. package/dist/index.d.ts +21 -11
  33. package/dist/index.js +31 -21
  34. package/dist/index.js.map +1 -1
  35. package/dist/mcp/client.d.ts +20 -20
  36. package/dist/mcp/index.d.ts +35 -35
  37. package/dist/mcp/index.js +32 -98
  38. package/dist/mcp/index.js.map +1 -1
  39. package/dist/mcp/server.js +1 -1
  40. package/dist/observability/ai/index.d.ts +10 -131
  41. package/dist/observability/ai/index.js +209 -444
  42. package/dist/observability/ai/index.js.map +1 -1
  43. package/dist/{wire-types-CU9rLoeS.js → protocol-Dqc2MQxo.js} +2 -46
  44. package/dist/protocol-Dqc2MQxo.js.map +1 -0
  45. package/dist/react.d.ts +1 -1
  46. package/dist/react.js +5 -8
  47. package/dist/react.js.map +1 -1
  48. package/dist/serializable.d.ts +1 -1
  49. package/dist/sub-routing.d.ts +18 -6
  50. package/dist/sub-routing.js +92 -2
  51. package/dist/sub-routing.js.map +1 -1
  52. package/dist/wire-types-CnMt6_HR.js +47 -0
  53. package/dist/wire-types-CnMt6_HR.js.map +1 -0
  54. package/dist/workflow-types.d.ts +25 -25
  55. package/dist/workflow-types.js.map +1 -1
  56. package/dist/workflows.d.ts +22 -22
  57. package/dist/ws-chat-transport-CIoOBbO7.js +561 -0
  58. package/dist/ws-chat-transport-CIoOBbO7.js.map +1 -0
  59. package/dist/ws-chat-transport-UNRIS2xl.d.ts +184 -0
  60. package/docs/adding-to-existing-project.md +4 -2
  61. package/docs/agent-class.md +1 -1
  62. package/docs/agent-tools.md +29 -0
  63. package/docs/browse-the-web.md +16 -1
  64. package/docs/chat-agents.md +3 -1
  65. package/docs/client-sdk.md +12 -8
  66. package/docs/configuration.md +7 -1
  67. package/docs/cross-domain-authentication.md +7 -35
  68. package/docs/email.md +2 -13
  69. package/docs/human-in-the-loop.md +15 -12
  70. package/docs/long-running-agents.md +11 -11
  71. package/docs/mcp-client.md +1 -1
  72. package/docs/mcp-servers.md +7 -1
  73. package/docs/mcp-transports.md +18 -12
  74. package/docs/migration-to-ai-sdk-v5.md +2 -2
  75. package/docs/migration-to-ai-sdk-v6.md +5 -1
  76. package/docs/observability.md +24 -67
  77. package/docs/routing.md +27 -0
  78. package/docs/sub-agents.md +47 -2
  79. package/docs/webhooks.md +109 -136
  80. package/docs/workflows.md +9 -1
  81. package/package.json +19 -10
  82. package/dist/cloudflare-BldFV0Pa.js +0 -117
  83. package/dist/cloudflare-BldFV0Pa.js.map +0 -1
  84. package/dist/connector-KEJnl6e5.js.map +0 -1
  85. package/dist/handler-stateless-8hQN_kC3.js.map +0 -1
  86. package/dist/wire-types-CU9rLoeS.js.map +0 -1
  87. package/dist/workflow-types-Baz_PO5v.d.ts +0 -280
@@ -1,186 +1,12 @@
1
1
  import { n as ClientToolSchema } from "../client-tools-aIBO0Fk7.js";
2
2
  import {
3
- ChatInit,
4
- ChatTransport,
5
- JSONSchema7,
6
- Tool,
7
- UIMessage,
8
- UIMessageChunk
9
- } from "ai";
3
+ n as WebSocketChatTransport,
4
+ r as WebSocketChatTransportOptions,
5
+ t as AgentConnection
6
+ } from "../ws-chat-transport-UNRIS2xl.js";
7
+ import { ChatInit, JSONSchema7, Tool, UIMessage } from "ai";
10
8
  import { UseChatOptions, useChat } from "@ai-sdk/react";
11
9
 
12
- //#region src/chat/ws-chat-transport.d.ts
13
- /**
14
- * Agent-like interface for sending/receiving WebSocket messages.
15
- * Matches the shape returned by useAgent from agents/react.
16
- */
17
- interface AgentConnection {
18
- send: (data: string) => void;
19
- addEventListener: (
20
- type: string,
21
- listener: (event: MessageEvent) => void,
22
- options?: {
23
- signal?: AbortSignal;
24
- }
25
- ) => void;
26
- removeEventListener: (
27
- type: string,
28
- listener: (event: MessageEvent) => void
29
- ) => void;
30
- }
31
- type WebSocketChatTransportOptions<ChatMessage extends UIMessage = UIMessage> =
32
- {
33
- /** The agent connection from useAgent */ agent: AgentConnection;
34
- /**
35
- * Callback to prepare the request body before sending.
36
- * Can add custom headers, body fields, or credentials.
37
- */
38
- prepareBody?: (options: {
39
- messages: ChatMessage[];
40
- trigger: "submit-message" | "regenerate-message";
41
- messageId?: string;
42
- }) => Promise<Record<string, unknown>> | Record<string, unknown>;
43
- /**
44
- * Optional set to track active request IDs.
45
- * IDs are added when a request starts and removed when it completes.
46
- * Used by the onAgentMessage handler to skip messages already handled by the transport.
47
- */
48
- activeRequestIds?: Set<string>;
49
- /**
50
- * Whether generic client-side abort/cancel lifecycle should cancel the
51
- * server turn. Explicit cancellation via cancelActiveServerTurn() always
52
- * sends CF_AGENT_CHAT_REQUEST_CANCEL.
53
- * @default false
54
- */
55
- cancelOnClientAbort?: boolean;
56
- };
57
- /**
58
- * ChatTransport that sends messages over WebSocket and returns a
59
- * ReadableStream<UIMessageChunk> that the AI SDK's useChat consumes directly.
60
- * No fake fetch, no Response reconstruction, no double SSE parsing.
61
- */
62
- declare class WebSocketChatTransport<
63
- ChatMessage extends UIMessage = UIMessage
64
- > implements ChatTransport<ChatMessage> {
65
- agent: AgentConnection;
66
- private prepareBody?;
67
- private activeRequestIds?;
68
- private cancelOnClientAbort;
69
- private _resumeResolver;
70
- private _resumeNoneResolver;
71
- private _onStreamPending;
72
- private _retryResumeProbe;
73
- private _expectToolContinuation;
74
- private _abortToolContinuation;
75
- private _activeServerTurnId;
76
- private _cancelAttachedStream;
77
- private _detachResumeStream;
78
- constructor(options: WebSocketChatTransportOptions<ChatMessage>);
79
- /**
80
- * Point the singleton transport at a new Agent connection. A pending resolver
81
- * belongs to the old Chat/socket generation and must settle before messages
82
- * from the replacement connection can be consumed (#1914 review).
83
- */
84
- setAgent(agent: AgentConnection): void;
85
- setCancelOnClientAbort(cancelOnClientAbort: boolean): void;
86
- /**
87
- * Explicitly cancel the active server turn, if any.
88
- * This is separate from generic client-side abort/cancel lifecycle so
89
- * clients can detach locally without stopping server work.
90
- */
91
- cancelActiveServerTurn(): boolean;
92
- private sendCancelFrame;
93
- private setActiveServerTurn;
94
- private clearActiveServerTurn;
95
- /**
96
- * Mark that the next reconnectToStream() call should attach to a
97
- * server-initiated tool continuation rather than a page-load resume.
98
- */
99
- expectToolContinuation(): void;
100
- /**
101
- * Abort the active client-side tool continuation stream, if one is attached
102
- * to a server request id.
103
- */
104
- abortActiveToolContinuation(): boolean;
105
- /**
106
- * True when the transport is waiting for a resume handshake.
107
- */
108
- isAwaitingResume(): boolean;
109
- /**
110
- * Settle and detach the current handshake without interpreting it as a
111
- * server-idle response. Used when the owning hook/agent generation changes.
112
- */
113
- cancelPendingResume(): boolean;
114
- /**
115
- * Invalidate all client-side resume state for an obsolete hook/agent
116
- * generation without cancelling its durable server turn.
117
- */
118
- resetResumeState(): void;
119
- /**
120
- * Re-send the active handshake request on the latest socket generation. This
121
- * preserves one AI SDK resume operation while recovering a request/reply lost
122
- * with the previous WebSocket.
123
- */
124
- retryPendingResume(): boolean;
125
- /**
126
- * Called by onAgentMessage when it receives CF_AGENT_STREAM_RESUMING.
127
- * If reconnectToStream is waiting, this handles the resume handshake
128
- * (ACK + stream creation) and returns true. Otherwise returns false
129
- * so the caller can use its own fallback path.
130
- */
131
- handleStreamResuming(data: { id: string }): boolean;
132
- /**
133
- * Called by onAgentMessage when it receives CF_AGENT_STREAM_RESUME_NONE.
134
- * If reconnectToStream is waiting, resolves the promise with null
135
- * immediately (no 5-second timeout). Returns true if handled.
136
- */
137
- handleStreamResumeNone(data?: { probeId?: string }): boolean;
138
- /**
139
- * Called by onAgentMessage when it receives CF_AGENT_STREAM_PENDING (#1784):
140
- * the server accepted a turn but its stream has not started yet. If a resume
141
- * path is awaiting, extend its probe timeout (so it keeps waiting for the
142
- * eventual STREAM_RESUMING / STREAM_RESUME_NONE instead of resolving null
143
- * after the short window). Returns true if a waiting path consumed it.
144
- */
145
- handleStreamPending(): boolean;
146
- /**
147
- * Called by the hook's shared message handler when a server turn finishes
148
- * outside the currently attached transport stream, such as after local-only
149
- * client cleanup.
150
- */
151
- handleServerTurnCompleted(requestId: string): void;
152
- /**
153
- * Register a server turn that is being rendered outside a transport-owned
154
- * stream, such as the hook's fallback cross-tab/resume observer path.
155
- */
156
- observeServerTurn(requestId: string): void;
157
- sendMessages(options: {
158
- chatId: string;
159
- messages: ChatMessage[];
160
- abortSignal: AbortSignal | undefined;
161
- trigger: "submit-message" | "regenerate-message";
162
- messageId?: string;
163
- body?: object;
164
- headers?: Record<string, string> | Headers;
165
- metadata?: unknown;
166
- }): Promise<ReadableStream<UIMessageChunk>>;
167
- reconnectToStream(_options: {
168
- chatId: string;
169
- }): Promise<ReadableStream<UIMessageChunk> | null>;
170
- /**
171
- * Creates a deferred ReadableStream for client-side tool continuations.
172
- * The stream is returned immediately so AI SDK status becomes "submitted"
173
- * right after addToolOutput()/addToolApprovalResponse(), then it waits for
174
- * the server to announce the continuation via STREAM_RESUMING.
175
- */
176
- private _createToolContinuationStream;
177
- /**
178
- * Creates a ReadableStream that receives resumed stream chunks
179
- * and forwards them to useChat as UIMessageChunk objects.
180
- */
181
- private _createResumeStream;
182
- }
183
- //#endregion
184
10
  //#region src/chat/react.d.ts
185
11
  type AgentConnectionErrorLike = Error & {
186
12
  code: number;