agents 0.13.2 → 0.14.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 (74) hide show
  1. package/README.md +6 -4
  2. package/dist/{agent-tool-types-Dn9n-3SI.d.ts → agent-tool-types-LInzZfLo.d.ts} +511 -124
  3. package/dist/agent-tool-types.d.ts +13 -11
  4. package/dist/{agent-tools-B1ttU-pq.d.ts → agent-tools-BE9xosUG.d.ts} +2 -2
  5. package/dist/agent-tools.d.ts +14 -20
  6. package/dist/agent-tools.js +10 -6
  7. package/dist/agent-tools.js.map +1 -1
  8. package/dist/browser/ai.d.ts +1 -1
  9. package/dist/browser/ai.js +1 -1
  10. package/dist/browser/index.d.ts +1 -1
  11. package/dist/browser/index.js +1 -1
  12. package/dist/browser/tanstack-ai.d.ts +1 -1
  13. package/dist/browser/tanstack-ai.js +1 -1
  14. package/dist/chat/index.d.ts +194 -22
  15. package/dist/chat/index.js +144 -11
  16. package/dist/chat/index.js.map +1 -1
  17. package/dist/chat-sdk/index.d.ts +4 -4
  18. package/dist/classPrivateMethodInitSpec-bG0tD96O.js +7 -0
  19. package/dist/{client-D1kFXo80.js → client-NradHZZz.js} +206 -75
  20. package/dist/client-NradHZZz.js.map +1 -0
  21. package/dist/client.d.ts +1 -1
  22. package/dist/{compaction-helpers-DvcZnvQ1.js → compaction-helpers-BjT2NKRZ.js} +37 -9
  23. package/dist/compaction-helpers-BjT2NKRZ.js.map +1 -0
  24. package/dist/{compaction-helpers-DAe-xiVY.d.ts → compaction-helpers-DpP_XP9J.d.ts} +86 -29
  25. package/dist/{do-oauth-client-provider-4OKQU9rT.d.ts → do-oauth-client-provider-CPm9rK5I.d.ts} +1 -1
  26. package/dist/{email-J0GGS3sa.d.ts → email-1fTSJwPm.d.ts} +1 -1
  27. package/dist/email.d.ts +2 -2
  28. package/dist/experimental/memory/session/index.d.ts +58 -23
  29. package/dist/experimental/memory/session/index.js +98 -9
  30. package/dist/experimental/memory/session/index.js.map +1 -1
  31. package/dist/experimental/memory/utils/index.d.ts +13 -11
  32. package/dist/experimental/memory/utils/index.js +2 -2
  33. package/dist/{index-DKey3P4s.d.ts → index-Brdu5nMI.d.ts} +270 -1
  34. package/dist/index.d.ts +74 -67
  35. package/dist/index.js +607 -97
  36. package/dist/index.js.map +1 -1
  37. package/dist/{internal_context-BZrMS0B5.d.ts → internal_context-CcZy2Em7.d.ts} +1 -1
  38. package/dist/internal_context.d.ts +1 -1
  39. package/dist/mcp/client.d.ts +17 -13
  40. package/dist/mcp/client.js +2 -2
  41. package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
  42. package/dist/mcp/index.d.ts +35 -27
  43. package/dist/mcp/index.js +402 -69
  44. package/dist/mcp/index.js.map +1 -1
  45. package/dist/observability/index.d.ts +1 -1
  46. package/dist/observability/index.js +15 -1
  47. package/dist/observability/index.js.map +1 -1
  48. package/dist/react.d.ts +3 -3
  49. package/dist/{retries-BVdRl5ZE.d.ts → retries-ClWwxADl.d.ts} +1 -1
  50. package/dist/retries.d.ts +1 -1
  51. package/dist/serializable.d.ts +1 -1
  52. package/dist/{shared-Cvj92byG.d.ts → shared-CpY1FLvm.d.ts} +1 -1
  53. package/dist/{shared-CiKaIK4h.js → shared-DdOn6sp4.js} +3 -7
  54. package/dist/{shared-CiKaIK4h.js.map → shared-DdOn6sp4.js.map} +1 -1
  55. package/dist/skills/index.d.ts +236 -0
  56. package/dist/skills/index.js +1326 -0
  57. package/dist/skills/index.js.map +1 -0
  58. package/dist/sub-routing.d.ts +6 -6
  59. package/dist/{tool-output-truncation-CH-khbZ3.js → tool-output-truncation-BF4AZQlw.js} +1 -1
  60. package/dist/{tool-output-truncation-CH-khbZ3.js.map → tool-output-truncation-BF4AZQlw.js.map} +1 -1
  61. package/dist/{types-_JjKmv-l.d.ts → types-B0GymtN_.d.ts} +1 -1
  62. package/dist/types.d.ts +1 -1
  63. package/dist/vite.d.ts +1 -1
  64. package/dist/vite.js +248 -2
  65. package/dist/vite.js.map +1 -1
  66. package/dist/{workflow-types-Dkzg4hAx.d.ts → workflow-types-DPkuBi--.d.ts} +1 -1
  67. package/dist/workflow-types.d.ts +1 -1
  68. package/dist/workflows.d.ts +13 -3
  69. package/dist/workflows.js +10 -1
  70. package/dist/workflows.js.map +1 -1
  71. package/package.json +21 -3
  72. package/skills-module.d.ts +22 -0
  73. package/dist/client-D1kFXo80.js.map +0 -1
  74. package/dist/compaction-helpers-DvcZnvQ1.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { i as isReplayChunk, n as createAgentToolEventState, r as applyChunkToParts, t as applyAgentToolEvent } from "../agent-tools-BAdX1vdI.js";
2
- import { t as truncateToolOutput } from "../tool-output-truncation-CH-khbZ3.js";
2
+ import { t as truncateToolOutput } from "../tool-output-truncation-BF4AZQlw.js";
3
3
  import { jsonSchema, tool } from "ai";
4
4
  import { nanoid } from "nanoid";
5
5
  //#region src/chat/sanitize.ts
@@ -520,7 +520,8 @@ const CHAT_MESSAGE_TYPES = {
520
520
  STREAM_RESUME_NONE: "cf_agent_stream_resume_none",
521
521
  TOOL_RESULT: "cf_agent_tool_result",
522
522
  TOOL_APPROVAL: "cf_agent_tool_approval",
523
- MESSAGE_UPDATED: "cf_agent_message_updated"
523
+ MESSAGE_UPDATED: "cf_agent_message_updated",
524
+ CHAT_RECOVERING: "cf_agent_chat_recovering"
524
525
  };
525
526
  //#endregion
526
527
  //#region src/chat/resumable-stream.ts
@@ -969,6 +970,22 @@ var ContinuationState = class {
969
970
  this.activeConnectionId = null;
970
971
  }
971
972
  /**
973
+ * Mark a connection as no longer available without canceling the
974
+ * continuation it initiated.
975
+ */
976
+ releaseConnection(connectionId) {
977
+ this.awaitingConnections.delete(connectionId);
978
+ if (this.pending?.connectionId === connectionId) this.pending = {
979
+ ...this.pending,
980
+ connectionId: null
981
+ };
982
+ if (this.deferred?.connectionId === connectionId) this.deferred = {
983
+ ...this.deferred,
984
+ connectionId: null
985
+ };
986
+ if (this.activeConnectionId === connectionId) this.activeConnectionId = null;
987
+ }
988
+ /**
972
989
  * Send STREAM_RESUME_NONE to all connections waiting for a
973
990
  * continuation stream to start, then clear the map.
974
991
  */
@@ -1019,7 +1036,7 @@ var ContinuationState = class {
1019
1036
  prerequisite: d.prerequisite,
1020
1037
  pastCoalesce: false
1021
1038
  };
1022
- this.awaitingConnections.set(d.connectionId, d.connection);
1039
+ if (d.connectionId !== null) this.awaitingConnections.set(d.connectionId, d.connection);
1023
1040
  return this.pending;
1024
1041
  }
1025
1042
  };
@@ -1172,6 +1189,60 @@ function toolResultUpdate(toolCallId, output, overrideState, errorText) {
1172
1189
  };
1173
1190
  }
1174
1191
  /**
1192
+ * Build an update descriptor for a terminal tool result that belongs to a
1193
+ * tool part in a *different* (earlier) assistant message than the one
1194
+ * currently being streamed.
1195
+ *
1196
+ * This is the "cross-message" case: an approved server tool executes during a
1197
+ * continuation stream, but its tool part lives in the assistant message that
1198
+ * originally requested it. `StreamAccumulator` surfaces this as a
1199
+ * `cross-message-tool-update` action because the accumulator only owns the
1200
+ * current turn's new content and cannot mutate a part from a prior message.
1201
+ *
1202
+ * Compared to {@link toolResultUpdate} this builder is deliberately more
1203
+ * defensive, mirroring the equivalent fallback in `@cloudflare/ai-chat`:
1204
+ *
1205
+ * - It matches the broad set of pre-terminal **and** terminal states, so a
1206
+ * provider that replays the entire prior tool round-trip during a
1207
+ * continuation (notably the OpenAI Responses API — issue #1404) still
1208
+ * resolves to the same part instead of silently missing it.
1209
+ * - It is **first-write-wins**: a chunk arriving for a tool that already holds
1210
+ * a terminal result is treated as a replay and the existing output is never
1211
+ * overwritten. In that case `apply` returns the *same part reference*, which
1212
+ * callers use as an idempotent-no-op signal to skip the durable write and a
1213
+ * redundant `MESSAGE_UPDATED` broadcast.
1214
+ * - It preserves a streamed `preliminary` flag when one is present, otherwise
1215
+ * marks the result final (`preliminary: false`).
1216
+ */
1217
+ function crossMessageToolResultUpdate(toolCallId, updateType, output, errorText, preliminary) {
1218
+ return {
1219
+ toolCallId,
1220
+ matchStates: [
1221
+ "input-streaming",
1222
+ "input-available",
1223
+ "approval-requested",
1224
+ "approval-responded",
1225
+ "output-available",
1226
+ "output-error",
1227
+ "output-denied"
1228
+ ],
1229
+ apply: (part) => {
1230
+ if (part.state === "output-available" || part.state === "output-error" || part.state === "output-denied") return part;
1231
+ if (updateType === "output-error") return {
1232
+ ...part,
1233
+ state: "output-error",
1234
+ errorText: errorText ?? "Tool execution failed"
1235
+ };
1236
+ return {
1237
+ ...part,
1238
+ state: "output-available",
1239
+ output,
1240
+ preliminary: preliminary ?? false
1241
+ };
1242
+ }
1243
+ };
1244
+ }
1245
+ /**
1175
1246
  * Build an update descriptor for applying a tool approval.
1176
1247
  *
1177
1248
  * Matches parts in `input-available` or `approval-requested` state.
@@ -1311,23 +1382,35 @@ function assistantContentKey(message, sanitize) {
1311
1382
  return JSON.stringify(sanitized.parts);
1312
1383
  }
1313
1384
  function mergeServerToolOutputs(incoming, serverMessages) {
1314
- const serverToolOutputs = /* @__PURE__ */ new Map();
1385
+ const serverResolvedParts = /* @__PURE__ */ new Map();
1315
1386
  for (const msg of serverMessages) {
1316
1387
  if (msg.role !== "assistant") continue;
1317
- for (const part of msg.parts) if ("toolCallId" in part && "state" in part && part.state === "output-available" && "output" in part) serverToolOutputs.set(part.toolCallId, part.output);
1388
+ for (const part of msg.parts) {
1389
+ const record = part;
1390
+ if ("toolCallId" in record && "state" in record && (record.state === "output-available" || record.state === "output-error" || record.state === "output-denied")) serverResolvedParts.set(record.toolCallId, record);
1391
+ }
1318
1392
  }
1319
- if (serverToolOutputs.size === 0) return incoming;
1393
+ if (serverResolvedParts.size === 0) return incoming;
1320
1394
  return incoming.map((msg) => {
1321
1395
  if (msg.role !== "assistant") return msg;
1322
1396
  let hasChanges = false;
1323
1397
  const updatedParts = msg.parts.map((part) => {
1324
- if ("toolCallId" in part && "state" in part && (part.state === "input-available" || part.state === "approval-requested" || part.state === "approval-responded") && serverToolOutputs.has(part.toolCallId)) {
1398
+ const record = part;
1399
+ if ("toolCallId" in record && "state" in record && (record.state === "input-available" || record.state === "approval-requested" || record.state === "approval-responded") && serverResolvedParts.has(record.toolCallId)) {
1325
1400
  hasChanges = true;
1326
- return {
1401
+ const server = serverResolvedParts.get(record.toolCallId);
1402
+ const merged = {
1327
1403
  ...part,
1328
- state: "output-available",
1329
- output: serverToolOutputs.get(part.toolCallId)
1404
+ state: server.state
1330
1405
  };
1406
+ if (server.state === "output-available") {
1407
+ if ("output" in server) merged.output = server.output;
1408
+ } else if (server.state === "output-error") {
1409
+ if ("errorText" in server) merged.errorText = server.errorText;
1410
+ } else if (server.state === "output-denied") {
1411
+ if ("approval" in server) merged.approval = server.approval;
1412
+ }
1413
+ return merged;
1331
1414
  }
1332
1415
  return part;
1333
1416
  });
@@ -1378,6 +1461,56 @@ function findMessageByToolCallId(messages, toolCallId) {
1378
1461
  }
1379
1462
  }
1380
1463
  //#endregion
1381
- export { AbortRegistry, CHAT_MESSAGE_TYPES, ContinuationState, ROW_MAX_BYTES, ResumableStream, StreamAccumulator, SubmitConcurrencyController, TurnQueue, applyAgentToolEvent, applyChunkToParts, applyToolUpdate, assistantContentKey, transition as broadcastTransition, byteLength, createAgentToolEventState, createToolsFromClientSchemas, enforceRowSizeLimit, isReplayChunk, parseProtocolMessage, reconcileMessages, resolveToolMergeId, sanitizeMessage, toolApprovalUpdate, toolResultUpdate };
1464
+ //#region src/chat/recovery.ts
1465
+ function createChatFiberSnapshot({ kind, requestId, recoveryRootRequestId, continuation, messages, lastBody, lastClientTools }) {
1466
+ const latestMessage = messages.length > 0 ? messages[messages.length - 1] : void 0;
1467
+ let latestUser;
1468
+ for (let index = messages.length - 1; index >= 0; index--) if (messages[index].role === "user") {
1469
+ latestUser = messages[index];
1470
+ break;
1471
+ }
1472
+ return {
1473
+ kind,
1474
+ version: 1,
1475
+ requestId,
1476
+ recoveryRootRequestId,
1477
+ continuation,
1478
+ latestMessageId: latestMessage?.id,
1479
+ latestMessageRole: latestMessage?.role,
1480
+ latestUserMessageId: latestUser?.id,
1481
+ startedAt: Date.now(),
1482
+ lastBody,
1483
+ lastClientTools
1484
+ };
1485
+ }
1486
+ function wrapChatFiberSnapshot(key, snapshot, user) {
1487
+ return {
1488
+ [key]: snapshot,
1489
+ user
1490
+ };
1491
+ }
1492
+ function unwrapChatFiberSnapshot(key, value, expectedKind) {
1493
+ if (typeof value !== "object" || value === null || !(key in value)) return {
1494
+ snapshot: null,
1495
+ user: value
1496
+ };
1497
+ const envelope = value;
1498
+ const snapshot = envelope[key];
1499
+ if (typeof snapshot !== "object" || snapshot === null) return {
1500
+ snapshot: null,
1501
+ user: value
1502
+ };
1503
+ const candidate = snapshot;
1504
+ if (candidate.version !== 1 || expectedKind !== void 0 && candidate.kind !== expectedKind || typeof candidate.requestId !== "string" || typeof candidate.continuation !== "boolean") return {
1505
+ snapshot: null,
1506
+ user: value
1507
+ };
1508
+ return {
1509
+ snapshot,
1510
+ user: envelope.user ?? null
1511
+ };
1512
+ }
1513
+ //#endregion
1514
+ export { AbortRegistry, CHAT_MESSAGE_TYPES, ContinuationState, ROW_MAX_BYTES, ResumableStream, StreamAccumulator, SubmitConcurrencyController, TurnQueue, applyAgentToolEvent, applyChunkToParts, applyToolUpdate, assistantContentKey, transition as broadcastTransition, byteLength, createAgentToolEventState, createChatFiberSnapshot, createToolsFromClientSchemas, crossMessageToolResultUpdate, enforceRowSizeLimit, isReplayChunk, parseProtocolMessage, reconcileMessages, resolveToolMergeId, sanitizeMessage, toolApprovalUpdate, toolResultUpdate, unwrapChatFiberSnapshot, wrapChatFiberSnapshot };
1382
1515
 
1383
1516
  //# sourceMappingURL=index.js.map