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.
- package/README.md +50 -12
- package/dist/{agent-tool-types-Btk9ETS-.d.ts → agent-tool-types-CzGGB-20.d.ts} +403 -115
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-UuScsJg3.d.ts → agent-tools-zR2d5uij.d.ts} +2 -2
- package/dist/agent-tools.d.ts +24 -8
- package/dist/agent-tools.js +14 -6
- package/dist/agent-tools.js.map +1 -1
- package/dist/browser/ai.d.ts +5 -3
- package/dist/browser/ai.js +86 -7
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/tanstack-ai.js +13 -1
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/chat/index.d.ts +31 -2
- package/dist/chat/index.js +57 -2
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react.d.ts +5 -179
- package/dist/chat/react.js +18 -555
- package/dist/chat/react.js.map +1 -1
- package/dist/chat/transport.d.ts +10 -0
- package/dist/chat/transport.js +2 -0
- package/dist/chat-sdk/index.d.ts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/cloudflare-BduZwmYK.js +204 -0
- package/dist/cloudflare-BduZwmYK.js.map +1 -0
- package/dist/{connector-v2M1zlZp.d.ts → connector-CkQD4MK3.d.ts} +20 -3
- package/dist/{connector-KEJnl6e5.js → connector-CptFKzRh.js} +158 -40
- package/dist/connector-CptFKzRh.js.map +1 -0
- package/dist/{handler-stateless-8hQN_kC3.js → handler-stateless-CIkKPETH.js} +20 -69
- package/dist/handler-stateless-CIkKPETH.js.map +1 -0
- package/dist/index.d.ts +21 -11
- package/dist/index.js +31 -21
- package/dist/index.js.map +1 -1
- package/dist/mcp/client.d.ts +20 -20
- package/dist/mcp/index.d.ts +35 -35
- package/dist/mcp/index.js +32 -98
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/server.js +1 -1
- package/dist/observability/ai/index.d.ts +10 -131
- package/dist/observability/ai/index.js +209 -444
- package/dist/observability/ai/index.js.map +1 -1
- package/dist/{wire-types-CU9rLoeS.js → protocol-Dqc2MQxo.js} +2 -46
- package/dist/protocol-Dqc2MQxo.js.map +1 -0
- package/dist/react.d.ts +1 -1
- package/dist/react.js +5 -8
- package/dist/react.js.map +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/sub-routing.d.ts +18 -6
- package/dist/sub-routing.js +92 -2
- package/dist/sub-routing.js.map +1 -1
- package/dist/wire-types-CnMt6_HR.js +47 -0
- package/dist/wire-types-CnMt6_HR.js.map +1 -0
- package/dist/workflow-types.d.ts +25 -25
- package/dist/workflow-types.js.map +1 -1
- package/dist/workflows.d.ts +22 -22
- package/dist/ws-chat-transport-CIoOBbO7.js +561 -0
- package/dist/ws-chat-transport-CIoOBbO7.js.map +1 -0
- package/dist/ws-chat-transport-UNRIS2xl.d.ts +184 -0
- package/docs/adding-to-existing-project.md +4 -2
- package/docs/agent-class.md +1 -1
- package/docs/agent-tools.md +29 -0
- package/docs/browse-the-web.md +16 -1
- package/docs/chat-agents.md +3 -1
- package/docs/client-sdk.md +12 -8
- package/docs/configuration.md +7 -1
- package/docs/cross-domain-authentication.md +7 -35
- package/docs/email.md +2 -13
- package/docs/human-in-the-loop.md +15 -12
- package/docs/long-running-agents.md +11 -11
- package/docs/mcp-client.md +1 -1
- package/docs/mcp-servers.md +7 -1
- package/docs/mcp-transports.md +18 -12
- package/docs/migration-to-ai-sdk-v5.md +2 -2
- package/docs/migration-to-ai-sdk-v6.md +5 -1
- package/docs/observability.md +24 -67
- package/docs/routing.md +27 -0
- package/docs/sub-agents.md +47 -2
- package/docs/webhooks.md +109 -136
- package/docs/workflows.md +9 -1
- package/package.json +19 -10
- package/dist/cloudflare-BldFV0Pa.js +0 -117
- package/dist/cloudflare-BldFV0Pa.js.map +0 -1
- package/dist/connector-KEJnl6e5.js.map +0 -1
- package/dist/handler-stateless-8hQN_kC3.js.map +0 -1
- package/dist/wire-types-CU9rLoeS.js.map +0 -1
- package/dist/workflow-types-Baz_PO5v.d.ts +0 -280
package/dist/chat/react.d.ts
CHANGED
|
@@ -1,186 +1,12 @@
|
|
|
1
1
|
import { n as ClientToolSchema } from "../client-tools-aIBO0Fk7.js";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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;
|