agents 0.17.3 → 0.18.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/dist/{agent-tool-types-CNyE1iz_.d.ts → agent-tool-types-BNUGGBzQ.d.ts} +191 -61
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-BeOheFBK.d.ts → agent-tools-BFbzVLFc.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/chat/index.d.ts +29 -9
- package/dist/chat/index.js +31 -41
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react.d.ts +25 -1
- package/dist/chat/react.js +249 -93
- package/dist/chat/react.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +1 -1
- package/dist/{client-BZ-B3NhC.js → client-CcjiFpTf.js} +352 -81
- package/dist/client-CcjiFpTf.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/cloudflare-BldFV0Pa.js +117 -0
- package/dist/cloudflare-BldFV0Pa.js.map +1 -0
- package/dist/index.d.ts +13 -11
- package/dist/index.js +153 -48
- package/dist/index.js.map +1 -1
- package/dist/mcp/client.d.ts +18 -14
- package/dist/mcp/client.js +1 -1
- package/dist/mcp/index.d.ts +38 -30
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/observability/ai/index.d.ts +155 -0
- package/dist/observability/ai/index.js +1845 -0
- package/dist/observability/ai/index.js.map +1 -0
- package/dist/react.d.ts +1 -1
- package/dist/{retries-CvHJwSuh.d.ts → retries-CAvxtG9d.d.ts} +16 -7
- package/dist/retries.d.ts +8 -6
- package/dist/retries.js +20 -2
- package/dist/retries.js.map +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/sub-routing.d.ts +6 -6
- package/dist/vite.d.ts +4 -4
- package/dist/vite.js +4 -2
- package/dist/vite.js.map +1 -1
- package/dist/{wire-types-nflOzNuU.js → wire-types-CU9rLoeS.js} +33 -2
- package/dist/wire-types-CU9rLoeS.js.map +1 -0
- package/dist/workflows.d.ts +1 -1
- package/docs/agent-class.md +9 -1
- package/docs/configuration.md +20 -0
- package/docs/mcp-client.md +52 -4
- package/docs/observability.md +282 -0
- package/package.json +7 -2
- package/dist/client-BZ-B3NhC.js.map +0 -1
- package/dist/wire-types-nflOzNuU.js.map +0 -1
package/dist/chat/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as normalizeToolInput, n as getPartialStreamText, r as isReplayChunk, t as applyChunkToParts } from "../message-builder-BymO4N_D.js";
|
|
2
2
|
import { i as interceptAgentToolBroadcast, n as applyAgentToolEvent, r as createAgentToolEventState, t as AgentToolProgressEmitter } from "../agent-tools-y7zLfw4Q.js";
|
|
3
3
|
import { t as truncateToolOutput } from "../tool-output-truncation-CNnnGZQ3.js";
|
|
4
|
-
import {
|
|
4
|
+
import { a as StreamAccumulator, i as transition, n as CHAT_MESSAGE_TYPES, r as STREAM_RESUME_NONE_REASONS, t as MessageType } from "../wire-types-CU9rLoeS.js";
|
|
5
5
|
import { jsonSchema, tool } from "ai";
|
|
6
6
|
import { nanoid } from "nanoid";
|
|
7
7
|
//#region src/chat/sanitize.ts
|
|
@@ -335,31 +335,6 @@ var SubmitConcurrencyController = class {
|
|
|
335
335
|
}
|
|
336
336
|
};
|
|
337
337
|
//#endregion
|
|
338
|
-
//#region src/chat/protocol.ts
|
|
339
|
-
/**
|
|
340
|
-
* Wire protocol message type constants for the cf_agent_chat_* protocol.
|
|
341
|
-
*
|
|
342
|
-
* These are the string values used on the wire between agent servers and
|
|
343
|
-
* clients. Both @cloudflare/ai-chat (via its MessageType enum) and
|
|
344
|
-
* @cloudflare/think use these values.
|
|
345
|
-
*/
|
|
346
|
-
const CHAT_MESSAGE_TYPES = {
|
|
347
|
-
CHAT_MESSAGES: "cf_agent_chat_messages",
|
|
348
|
-
USE_CHAT_REQUEST: "cf_agent_use_chat_request",
|
|
349
|
-
USE_CHAT_RESPONSE: "cf_agent_use_chat_response",
|
|
350
|
-
CHAT_CLEAR: "cf_agent_chat_clear",
|
|
351
|
-
CHAT_REQUEST_CANCEL: "cf_agent_chat_request_cancel",
|
|
352
|
-
STREAM_RESUMING: "cf_agent_stream_resuming",
|
|
353
|
-
STREAM_RESUME_ACK: "cf_agent_stream_resume_ack",
|
|
354
|
-
STREAM_RESUME_REQUEST: "cf_agent_stream_resume_request",
|
|
355
|
-
STREAM_RESUME_NONE: "cf_agent_stream_resume_none",
|
|
356
|
-
STREAM_PENDING: "cf_agent_stream_pending",
|
|
357
|
-
TOOL_RESULT: "cf_agent_tool_result",
|
|
358
|
-
TOOL_APPROVAL: "cf_agent_tool_approval",
|
|
359
|
-
MESSAGE_UPDATED: "cf_agent_message_updated",
|
|
360
|
-
CHAT_RECOVERING: "cf_agent_chat_recovering"
|
|
361
|
-
};
|
|
362
|
-
//#endregion
|
|
363
338
|
//#region src/chat/connection.ts
|
|
364
339
|
/**
|
|
365
340
|
* Send a message on a connection, swallowing the specific
|
|
@@ -1245,12 +1220,13 @@ var PreStreamTurns = class {
|
|
|
1245
1220
|
* `pendingResumeConnections` — they must keep receiving any live broadcast —
|
|
1246
1221
|
* until the host flushes them through `notifyStreamResuming` on stream start.
|
|
1247
1222
|
*/
|
|
1248
|
-
park(connection) {
|
|
1223
|
+
park(connection, probeId) {
|
|
1249
1224
|
if (!this.hasInFlight()) return false;
|
|
1250
1225
|
this.awaitingConnections.set(connection.id, connection);
|
|
1251
1226
|
sendIfOpen(connection, JSON.stringify({
|
|
1252
1227
|
type: MSG_STREAM_PENDING,
|
|
1253
|
-
...this._latestRequestId ? { id: this._latestRequestId } : {}
|
|
1228
|
+
...this._latestRequestId ? { id: this._latestRequestId } : {},
|
|
1229
|
+
...probeId ? { probeId } : {}
|
|
1254
1230
|
}));
|
|
1255
1231
|
return true;
|
|
1256
1232
|
}
|
|
@@ -1870,7 +1846,10 @@ function parseProtocolMessage(raw) {
|
|
|
1870
1846
|
approved: data.approved,
|
|
1871
1847
|
autoContinue: data.autoContinue
|
|
1872
1848
|
};
|
|
1873
|
-
case CHAT_MESSAGE_TYPES.STREAM_RESUME_REQUEST: return {
|
|
1849
|
+
case CHAT_MESSAGE_TYPES.STREAM_RESUME_REQUEST: return {
|
|
1850
|
+
type: "stream-resume-request",
|
|
1851
|
+
...typeof data.probeId === "string" ? { probeId: data.probeId } : {}
|
|
1852
|
+
};
|
|
1874
1853
|
case CHAT_MESSAGE_TYPES.STREAM_RESUME_ACK: return {
|
|
1875
1854
|
type: "stream-resume-ack",
|
|
1876
1855
|
id: data.id
|
|
@@ -2327,13 +2306,15 @@ var ResumeHandshake = class {
|
|
|
2327
2306
|
* `reconnectToStream` hangs to its timeout with no replay), and the proactive
|
|
2328
2307
|
* notify is required for clients that never send a request. The notify is one
|
|
2329
2308
|
* tiny frame; the client dedupes its ACK so the buffer is not replayed twice.
|
|
2309
|
+
* Direct responses echo the opaque probe id; proactive notifications omit it.
|
|
2330
2310
|
*/
|
|
2331
|
-
notifyStreamResuming(connection) {
|
|
2311
|
+
notifyStreamResuming(connection, probeId) {
|
|
2332
2312
|
const { resumableStream, pendingResumeConnections } = this.host;
|
|
2333
2313
|
if (!resumableStream.hasActiveStream()) return;
|
|
2334
2314
|
if (sendIfOpen(connection, JSON.stringify({
|
|
2335
2315
|
type: CHAT_MESSAGE_TYPES.STREAM_RESUMING,
|
|
2336
|
-
id: resumableStream.activeRequestId
|
|
2316
|
+
id: resumableStream.activeRequestId,
|
|
2317
|
+
...probeId ? { probeId } : {}
|
|
2337
2318
|
}))) pendingResumeConnections.add(connection.id);
|
|
2338
2319
|
}
|
|
2339
2320
|
/**
|
|
@@ -2341,20 +2322,28 @@ var ResumeHandshake = class {
|
|
|
2341
2322
|
* message handler is registered, avoiding the race where a proactive
|
|
2342
2323
|
* `STREAM_RESUMING` from onConnect arrives before the handler is ready.
|
|
2343
2324
|
*/
|
|
2344
|
-
async handleResumeRequest(connection) {
|
|
2325
|
+
async handleResumeRequest(connection, probeId) {
|
|
2345
2326
|
const { resumableStream, continuation, preStream } = this.host;
|
|
2346
|
-
if (resumableStream.hasActiveStream()) if (continuation.activeRequestId === resumableStream.activeRequestId && continuation.activeConnectionId !== null && continuation.activeConnectionId !== connection.id && this._ownerStillPresent(continuation.activeConnectionId))
|
|
2347
|
-
else this.notifyStreamResuming(connection);
|
|
2327
|
+
if (resumableStream.hasActiveStream()) if (continuation.activeRequestId === resumableStream.activeRequestId && continuation.activeConnectionId !== null && continuation.activeConnectionId !== connection.id && this._ownerStillPresent(continuation.activeConnectionId)) this._sendResumeNone(connection, STREAM_RESUME_NONE_REASONS.CONTINUATION_OWNED, probeId);
|
|
2328
|
+
else this.notifyStreamResuming(connection, probeId);
|
|
2348
2329
|
else if (continuation.pending !== null && (continuation.pending.connectionId === null || continuation.pending.connectionId === connection.id)) {
|
|
2349
2330
|
continuation.awaitingConnections.set(connection.id, connection);
|
|
2350
|
-
this._sendStreamPending(connection, continuation.pending.requestId);
|
|
2351
|
-
} else if (await this._replayTerminalOnResume(connection)) {} else if (preStream?.park(connection)) {} else
|
|
2331
|
+
this._sendStreamPending(connection, continuation.pending.requestId, probeId);
|
|
2332
|
+
} else if (await this._replayTerminalOnResume(connection, probeId)) {} else if (preStream?.park(connection, probeId)) {} else this._sendResumeNone(connection, STREAM_RESUME_NONE_REASONS.IDLE, probeId);
|
|
2333
|
+
}
|
|
2334
|
+
_sendResumeNone(connection, reason, probeId) {
|
|
2335
|
+
sendIfOpen(connection, JSON.stringify({
|
|
2336
|
+
type: CHAT_MESSAGE_TYPES.STREAM_RESUME_NONE,
|
|
2337
|
+
reason,
|
|
2338
|
+
...probeId ? { probeId } : {}
|
|
2339
|
+
}));
|
|
2352
2340
|
}
|
|
2353
2341
|
/** Send a keep-waiting `STREAM_PENDING` frame (#1784). */
|
|
2354
|
-
_sendStreamPending(connection, requestId) {
|
|
2342
|
+
_sendStreamPending(connection, requestId, probeId) {
|
|
2355
2343
|
sendIfOpen(connection, JSON.stringify({
|
|
2356
2344
|
type: CHAT_MESSAGE_TYPES.STREAM_PENDING,
|
|
2357
|
-
...requestId ? { id: requestId } : {}
|
|
2345
|
+
...requestId ? { id: requestId } : {},
|
|
2346
|
+
...probeId ? { probeId } : {}
|
|
2358
2347
|
}));
|
|
2359
2348
|
}
|
|
2360
2349
|
/** Whether the active continuation's owner connection is still present. */
|
|
@@ -2385,12 +2374,13 @@ var ResumeHandshake = class {
|
|
|
2385
2374
|
* error frame once the client ACKs (see {@link _replayTerminalOnAck}). Returns
|
|
2386
2375
|
* `true` if a terminal was pending (and `STREAM_RESUMING` was sent).
|
|
2387
2376
|
*/
|
|
2388
|
-
async _replayTerminalOnResume(connection) {
|
|
2377
|
+
async _replayTerminalOnResume(connection, probeId) {
|
|
2389
2378
|
const pending = await this.host.pendingChatTerminal();
|
|
2390
2379
|
if (!pending) return false;
|
|
2391
2380
|
sendIfOpen(connection, JSON.stringify({
|
|
2392
2381
|
type: CHAT_MESSAGE_TYPES.STREAM_RESUMING,
|
|
2393
|
-
id: pending.requestId
|
|
2382
|
+
id: pending.requestId,
|
|
2383
|
+
...probeId ? { probeId } : {}
|
|
2394
2384
|
}));
|
|
2395
2385
|
return true;
|
|
2396
2386
|
}
|
|
@@ -3403,6 +3393,6 @@ async function* iterateWithStallWatchdog(source, timeoutMs, onStall) {
|
|
|
3403
3393
|
}
|
|
3404
3394
|
}
|
|
3405
3395
|
//#endregion
|
|
3406
|
-
export { AGENT_TOOL_STREAM_PROGRESS_BUMP_THROTTLE_MS, AbortRegistry, AgentToolProgressEmitter, AgentToolStreamProgressThrottle, AutoContinuationController, CHAT_LAST_TERMINAL_KEY, CHAT_MESSAGE_TYPES, CHAT_RECOVERING_FLAG_TTL_MS, CHAT_RECOVERING_KEY, CHAT_RECOVERY_ALARM_DEBOUNCE_MS, CHAT_RECOVERY_INCIDENT_KEY_PREFIX, CHAT_RECOVERY_INCIDENT_TTL_MS, CHAT_RECOVERY_PROGRESS_KEY, CHAT_RECOVERY_STABLE_RETRY_DELAY_SECONDS, CHAT_STREAM_PROGRESS_CREDIT_THROTTLE_MS, ChatRecoveryEngine, ChatStreamStalledError, ContinuationState, DEFAULT_CHAT_RECOVERY_MAX_ATTEMPTS, DEFAULT_CHAT_RECOVERY_MAX_OOM_RETRIES, DEFAULT_CHAT_RECOVERY_MAX_WORK, DEFAULT_CHAT_RECOVERY_NO_PROGRESS_TIMEOUT_MS, DEFAULT_CHAT_RECOVERY_STABLE_TIMEOUT_MS, DEFAULT_CHAT_RECOVERY_TERMINAL_MESSAGE, KV_DELETE_MAX_KEYS, MAX_BOUND_PARAMS, MessageType, PreStreamTurns, ROW_MAX_BYTES, ResumableStream, ResumeHandshake, STREAM_CLEANUP_DELAY_SECONDS, StreamAccumulator, StreamProgressCreditThrottle, SubmitConcurrencyController, TIMED_OUT, TurnQueue, aiSdkRecoveryCodec, applyAgentToolEvent, applyChunkToParts, applyToolUpdate, awaitWithDeadline, transition as broadcastTransition, buildChatRecoveringFrame, buildInClauseStrings, bumpChatRecoveryProgress, byteLength, chatRecoverySchedulePolicy, classifyAgentToolChildRecovery, cleanupStreamBuffers, clearChatTerminal, clientResolvableToolNames, createAgentToolEventState, createChatFiberSnapshot, createToolsFromClientSchemas, crossMessageToolResultUpdate, drainInteractionApplies, enforceRowSizeLimit, hasIncompleteToolBatch, interceptAgentToolBroadcast, isReplayChunk, iterateWithStallWatchdog, listActiveChatRecoveryIncidents, normalizeToolInput, parseProtocolMessage, partAwaitsClientInteraction, pausedExecutionUpdate, pendingChatTerminal, persistReconstructedOrphan, readChatRecoveryProgress, reconcileMessages, reconcileOrphanPartial, recordChatTerminal, repairInterruptedToolParts, resolveChatRecoveryConfig, resolveToolMergeId, runChatRecoveryExhaustion, sanitizeMessage, sendIfOpen, setChatRecovering, shouldCreditStreamProgress, sweepStaleChatRecoveryIncidents, toolApprovalUpdate, toolPartHasSettledResult, toolResultUpdate, unwrapChatFiberSnapshot, wrapChatFiberSnapshot };
|
|
3396
|
+
export { AGENT_TOOL_STREAM_PROGRESS_BUMP_THROTTLE_MS, AbortRegistry, AgentToolProgressEmitter, AgentToolStreamProgressThrottle, AutoContinuationController, CHAT_LAST_TERMINAL_KEY, CHAT_MESSAGE_TYPES, CHAT_RECOVERING_FLAG_TTL_MS, CHAT_RECOVERING_KEY, CHAT_RECOVERY_ALARM_DEBOUNCE_MS, CHAT_RECOVERY_INCIDENT_KEY_PREFIX, CHAT_RECOVERY_INCIDENT_TTL_MS, CHAT_RECOVERY_PROGRESS_KEY, CHAT_RECOVERY_STABLE_RETRY_DELAY_SECONDS, CHAT_STREAM_PROGRESS_CREDIT_THROTTLE_MS, ChatRecoveryEngine, ChatStreamStalledError, ContinuationState, DEFAULT_CHAT_RECOVERY_MAX_ATTEMPTS, DEFAULT_CHAT_RECOVERY_MAX_OOM_RETRIES, DEFAULT_CHAT_RECOVERY_MAX_WORK, DEFAULT_CHAT_RECOVERY_NO_PROGRESS_TIMEOUT_MS, DEFAULT_CHAT_RECOVERY_STABLE_TIMEOUT_MS, DEFAULT_CHAT_RECOVERY_TERMINAL_MESSAGE, KV_DELETE_MAX_KEYS, MAX_BOUND_PARAMS, MessageType, PreStreamTurns, ROW_MAX_BYTES, ResumableStream, ResumeHandshake, STREAM_CLEANUP_DELAY_SECONDS, STREAM_RESUME_NONE_REASONS, StreamAccumulator, StreamProgressCreditThrottle, SubmitConcurrencyController, TIMED_OUT, TurnQueue, aiSdkRecoveryCodec, applyAgentToolEvent, applyChunkToParts, applyToolUpdate, awaitWithDeadline, transition as broadcastTransition, buildChatRecoveringFrame, buildInClauseStrings, bumpChatRecoveryProgress, byteLength, chatRecoverySchedulePolicy, classifyAgentToolChildRecovery, cleanupStreamBuffers, clearChatTerminal, clientResolvableToolNames, createAgentToolEventState, createChatFiberSnapshot, createToolsFromClientSchemas, crossMessageToolResultUpdate, drainInteractionApplies, enforceRowSizeLimit, hasIncompleteToolBatch, interceptAgentToolBroadcast, isReplayChunk, iterateWithStallWatchdog, listActiveChatRecoveryIncidents, normalizeToolInput, parseProtocolMessage, partAwaitsClientInteraction, pausedExecutionUpdate, pendingChatTerminal, persistReconstructedOrphan, readChatRecoveryProgress, reconcileMessages, reconcileOrphanPartial, recordChatTerminal, repairInterruptedToolParts, resolveChatRecoveryConfig, resolveToolMergeId, runChatRecoveryExhaustion, sanitizeMessage, sendIfOpen, setChatRecovering, shouldCreditStreamProgress, sweepStaleChatRecoveryIncidents, toolApprovalUpdate, toolPartHasSettledResult, toolResultUpdate, unwrapChatFiberSnapshot, wrapChatFiberSnapshot };
|
|
3407
3397
|
|
|
3408
3398
|
//# sourceMappingURL=index.js.map
|