agents 0.13.2 → 0.13.3

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.
@@ -1912,6 +1912,22 @@ type FiberRecoveryContext = {
1912
1912
  createdAt: number;
1913
1913
  [key: string]: unknown;
1914
1914
  };
1915
+ type InternalFiberOptions = {
1916
+ signal?: AbortSignal;
1917
+ managed?: boolean;
1918
+ initialSnapshot?: unknown;
1919
+ wrapStash?: (data: unknown) => unknown;
1920
+ beforeRunCleanup?: (
1921
+ outcome:
1922
+ | {
1923
+ ok: true;
1924
+ }
1925
+ | {
1926
+ ok: false;
1927
+ error: unknown;
1928
+ }
1929
+ ) => void;
1930
+ };
1915
1931
  /**
1916
1932
  * MCP Server state update message from server -> Client
1917
1933
  */
@@ -2071,6 +2087,13 @@ declare class Agent<
2071
2087
  private _protocolBroadcastExcludeIds;
2072
2088
  private _cf_currentSubAgentBridge?;
2073
2089
  private _cf_virtualSubAgentConnections;
2090
+ /**
2091
+ * User-facing facet name. For legacy facets this is the same as
2092
+ * `ctx.id.name`; path-scoped facets use an internal routing id and
2093
+ * keep the logical name here instead.
2094
+ * @internal
2095
+ */
2096
+ private _facetName?;
2074
2097
  /**
2075
2098
  * Ancestor chain, root-first. Empty for top-level DOs; populated at
2076
2099
  * facet init time from the parent's own `selfPath`. Exposed publicly
@@ -2483,6 +2506,7 @@ declare class Agent<
2483
2506
  private _facetRunRowsForPrefix;
2484
2507
  private _deleteFacetRunRowsForPrefix;
2485
2508
  private _rootAlarmOwner;
2509
+ private _cf_rootResolvesToSelf;
2486
2510
  private _validateScheduleCallback;
2487
2511
  /**
2488
2512
  * Insert (or, for idempotent calls, return the existing row for) a
@@ -2828,6 +2852,20 @@ declare class Agent<
2828
2852
  * @returns The return value of fn
2829
2853
  */
2830
2854
  runFiber<T>(name: string, fn: (ctx: FiberContext) => Promise<T>): Promise<T>;
2855
+ /**
2856
+ * Internal framework entry point for fibers that need to compose their own
2857
+ * recovery metadata with user checkpoint data while preserving the public
2858
+ * `this.stash()` behavior.
2859
+ *
2860
+ * This deliberately stays protected/internal rather than becoming a public
2861
+ * `runFiber()` option until the durable execution API needs this generality.
2862
+ * @internal
2863
+ */
2864
+ protected _runFiberWithStashWrapper<T>(
2865
+ name: string,
2866
+ fn: (ctx: FiberContext) => Promise<T>,
2867
+ options: Pick<InternalFiberOptions, "initialSnapshot" | "wrapStash">
2868
+ ): Promise<T>;
2831
2869
  startFiber(
2832
2870
  name: string,
2833
2871
  fn: (ctx: FiberContext) => Promise<void>,
@@ -3128,13 +3166,9 @@ declare class Agent<
3128
3166
  * broadcast to their own WebSocket clients reached via sub-agent
3129
3167
  * routing.
3130
3168
  *
3131
- * The facet's name (and `this.name` getter) is handled entirely by
3132
- * partyserver via `ctx.id.name`, which is populated because the
3133
- * parent passed an explicit named Durable Object id to
3134
- * `ctx.facets.get()` — see {@link _cf_resolveSubAgent}. No
3135
- * `setName()` call or `__ps_name` storage write is needed; the
3136
- * facet's name survives cold wake automatically because the factory
3137
- * re-runs and `idFromName` is deterministic.
3169
+ * The facet's logical name is persisted separately from its routing id.
3170
+ * Legacy facets used the logical name directly as `ctx.id.name`; newer
3171
+ * facets can use path-scoped routing ids while preserving `this.name`.
3138
3172
  *
3139
3173
  * @internal Called by {@link subAgent}.
3140
3174
  */
@@ -3143,8 +3177,10 @@ declare class Agent<
3143
3177
  parentPath?: ReadonlyArray<{
3144
3178
  className: string;
3145
3179
  name: string;
3146
- }>
3180
+ }>,
3181
+ identityName?: string
3147
3182
  ): Promise<void>;
3183
+ get name(): string;
3148
3184
  /**
3149
3185
  * Ancestor chain for this agent, root-first. Empty for top-level
3150
3186
  * DOs. Populated at facet init time; survives hibernation.
@@ -3332,11 +3368,15 @@ declare class Agent<
3332
3368
  deleteSubAgent(cls: SubAgentClass, name: string): Promise<void>;
3333
3369
  /** @internal */
3334
3370
  private _subAgentRegistryReady;
3371
+ private _addColumnIfNotExists;
3335
3372
  /** @internal */
3336
3373
  private _ensureSubAgentRegistry;
3337
3374
  /** @internal */
3338
3375
  private _recordSubAgent;
3339
3376
  /** @internal */
3377
+ private _subAgentRegistryRow;
3378
+ private _cf_subAgentIdentity;
3379
+ /** @internal */
3340
3380
  private _forgetSubAgent;
3341
3381
  /**
3342
3382
  * Whether this agent has previously spawned (and not deleted) a
@@ -4237,4 +4277,4 @@ export {
4237
4277
  MCPServersState as z,
4238
4278
  SUB_PREFIX as zt
4239
4279
  };
4240
- //# sourceMappingURL=agent-tool-types-Dn9n-3SI.d.ts.map
4280
+ //# sourceMappingURL=agent-tool-types-l98LCbBl.d.ts.map
@@ -14,7 +14,7 @@ import {
14
14
  s as AgentToolRunInfo,
15
15
  t as AgentToolChildAdapter,
16
16
  u as AgentToolRunStatus
17
- } from "./agent-tool-types-Dn9n-3SI.js";
17
+ } from "./agent-tool-types-l98LCbBl.js";
18
18
  export {
19
19
  AgentToolChildAdapter,
20
20
  AgentToolDisplayMetadata,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  a as AgentToolEventState,
3
3
  i as AgentToolEventMessage
4
- } from "./agent-tool-types-Dn9n-3SI.js";
4
+ } from "./agent-tool-types-l98LCbBl.js";
5
5
 
6
6
  //#region src/chat/agent-tools.d.ts
7
7
  declare function createAgentToolEventState(): AgentToolEventState;
@@ -11,4 +11,4 @@ declare function applyAgentToolEvent(
11
11
  ): AgentToolEventState;
12
12
  //#endregion
13
13
  export { createAgentToolEventState as n, applyAgentToolEvent as t };
14
- //# sourceMappingURL=agent-tools-B1ttU-pq.d.ts.map
14
+ //# sourceMappingURL=agent-tools-Bg5ilERh.d.ts.map
@@ -14,7 +14,7 @@ import {
14
14
  s as AgentToolRunInfo,
15
15
  t as AgentToolChildAdapter,
16
16
  u as AgentToolRunStatus
17
- } from "./agent-tool-types-Dn9n-3SI.js";
17
+ } from "./agent-tool-types-l98LCbBl.js";
18
18
  import { Tool } from "ai";
19
19
 
20
20
  //#region src/agent-tools.d.ts
@@ -3,11 +3,11 @@ import {
3
3
  i as AgentToolEventMessage,
4
4
  l as AgentToolRunState,
5
5
  r as AgentToolEvent
6
- } from "../agent-tool-types-Dn9n-3SI.js";
6
+ } from "../agent-tool-types-l98LCbBl.js";
7
7
  import {
8
8
  n as createAgentToolEventState,
9
9
  t as applyAgentToolEvent
10
- } from "../agent-tools-B1ttU-pq.js";
10
+ } from "../agent-tools-Bg5ilERh.js";
11
11
  import { JSONSchema7, Tool, ToolSet, UIMessage } from "ai";
12
12
  import { Connection } from "agents";
13
13
 
@@ -317,10 +317,17 @@ type SaveMessagesOptions = {
317
317
  * completion, either by `MSG_CHAT_CANCEL` over the chat WebSocket or
318
318
  * by an external `AbortSignal` passed via {@link SaveMessagesOptions}.
319
319
  * Partial chunks streamed before the abort are still persisted.
320
+ * - `"error"` — the turn ran but ended with a stream error. Partial chunks
321
+ * streamed before the error are still persisted.
320
322
  */
321
323
  type SaveMessagesResult = {
322
- /** Server-generated request ID for the chat turn. */ requestId: string /** Whether the turn ran, was skipped, or was aborted. */;
323
- status: "completed" | "skipped" | "aborted";
324
+ /** Server-generated request ID for the chat turn. */ requestId: string /** Whether the turn completed, errored, was skipped, or was aborted. */;
325
+ status:
326
+ | "completed"
327
+ | "error"
328
+ | "skipped"
329
+ | "aborted" /** Error message when `status` is `"error"`. */;
330
+ error?: string;
324
331
  };
325
332
  /**
326
333
  * Context passed to the `onChatRecovery` hook when an interrupted chat
@@ -933,6 +940,48 @@ declare function assistantContentKey(
933
940
  sanitize?: (message: UIMessage) => UIMessage
934
941
  ): string | undefined;
935
942
  //#endregion
943
+ //#region src/chat/recovery.d.ts
944
+ type ChatFiberSnapshot<Kind extends string = string> = {
945
+ kind: Kind;
946
+ version: 1;
947
+ requestId: string;
948
+ continuation: boolean;
949
+ latestMessageId?: string;
950
+ latestMessageRole?: string;
951
+ latestUserMessageId?: string;
952
+ startedAt: number;
953
+ lastBody?: Record<string, unknown>;
954
+ lastClientTools?: ClientToolSchema[];
955
+ };
956
+ declare function createChatFiberSnapshot<Kind extends string>({
957
+ kind,
958
+ requestId,
959
+ continuation,
960
+ messages,
961
+ lastBody,
962
+ lastClientTools
963
+ }: {
964
+ kind: Kind;
965
+ requestId: string;
966
+ continuation: boolean;
967
+ messages: UIMessage[];
968
+ lastBody?: Record<string, unknown>;
969
+ lastClientTools?: ClientToolSchema[];
970
+ }): ChatFiberSnapshot<Kind>;
971
+ declare function wrapChatFiberSnapshot<Kind extends string>(
972
+ key: string,
973
+ snapshot: ChatFiberSnapshot<Kind>,
974
+ user: unknown | null
975
+ ): Record<string, unknown>;
976
+ declare function unwrapChatFiberSnapshot<Kind extends string>(
977
+ key: string,
978
+ value: unknown,
979
+ expectedKind?: Kind
980
+ ): {
981
+ snapshot: ChatFiberSnapshot<Kind> | null;
982
+ user: unknown | null;
983
+ };
984
+ //#endregion
936
985
  export {
937
986
  AbortRegistry,
938
987
  type AgentToolEvent,
@@ -943,6 +992,7 @@ export {
943
992
  type BroadcastStreamState,
944
993
  type TransitionResult as BroadcastTransitionResult,
945
994
  CHAT_MESSAGE_TYPES,
995
+ type ChatFiberSnapshot,
946
996
  type ChatProtocolEvent,
947
997
  type ChatRecoveryContext,
948
998
  type ChatRecoveryOptions,
@@ -979,6 +1029,7 @@ export {
979
1029
  transition as broadcastTransition,
980
1030
  byteLength,
981
1031
  createAgentToolEventState,
1032
+ createChatFiberSnapshot,
982
1033
  createToolsFromClientSchemas,
983
1034
  enforceRowSizeLimit,
984
1035
  isReplayChunk,
@@ -987,6 +1038,8 @@ export {
987
1038
  resolveToolMergeId,
988
1039
  sanitizeMessage,
989
1040
  toolApprovalUpdate,
990
- toolResultUpdate
1041
+ toolResultUpdate,
1042
+ unwrapChatFiberSnapshot,
1043
+ wrapChatFiberSnapshot
991
1044
  };
992
1045
  //# sourceMappingURL=index.d.ts.map
@@ -1378,6 +1378,55 @@ function findMessageByToolCallId(messages, toolCallId) {
1378
1378
  }
1379
1379
  }
1380
1380
  //#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 };
1381
+ //#region src/chat/recovery.ts
1382
+ function createChatFiberSnapshot({ kind, requestId, continuation, messages, lastBody, lastClientTools }) {
1383
+ const latestMessage = messages.length > 0 ? messages[messages.length - 1] : void 0;
1384
+ let latestUser;
1385
+ for (let index = messages.length - 1; index >= 0; index--) if (messages[index].role === "user") {
1386
+ latestUser = messages[index];
1387
+ break;
1388
+ }
1389
+ return {
1390
+ kind,
1391
+ version: 1,
1392
+ requestId,
1393
+ continuation,
1394
+ latestMessageId: latestMessage?.id,
1395
+ latestMessageRole: latestMessage?.role,
1396
+ latestUserMessageId: latestUser?.id,
1397
+ startedAt: Date.now(),
1398
+ lastBody,
1399
+ lastClientTools
1400
+ };
1401
+ }
1402
+ function wrapChatFiberSnapshot(key, snapshot, user) {
1403
+ return {
1404
+ [key]: snapshot,
1405
+ user
1406
+ };
1407
+ }
1408
+ function unwrapChatFiberSnapshot(key, value, expectedKind) {
1409
+ if (typeof value !== "object" || value === null || !(key in value)) return {
1410
+ snapshot: null,
1411
+ user: value
1412
+ };
1413
+ const envelope = value;
1414
+ const snapshot = envelope[key];
1415
+ if (typeof snapshot !== "object" || snapshot === null) return {
1416
+ snapshot: null,
1417
+ user: value
1418
+ };
1419
+ const candidate = snapshot;
1420
+ if (candidate.version !== 1 || expectedKind !== void 0 && candidate.kind !== expectedKind || typeof candidate.requestId !== "string" || typeof candidate.continuation !== "boolean") return {
1421
+ snapshot: null,
1422
+ user: value
1423
+ };
1424
+ return {
1425
+ snapshot,
1426
+ user: envelope.user ?? null
1427
+ };
1428
+ }
1429
+ //#endregion
1430
+ export { AbortRegistry, CHAT_MESSAGE_TYPES, ContinuationState, ROW_MAX_BYTES, ResumableStream, StreamAccumulator, SubmitConcurrencyController, TurnQueue, applyAgentToolEvent, applyChunkToParts, applyToolUpdate, assistantContentKey, transition as broadcastTransition, byteLength, createAgentToolEventState, createChatFiberSnapshot, createToolsFromClientSchemas, enforceRowSizeLimit, isReplayChunk, parseProtocolMessage, reconcileMessages, resolveToolMergeId, sanitizeMessage, toolApprovalUpdate, toolResultUpdate, unwrapChatFiberSnapshot, wrapChatFiberSnapshot };
1382
1431
 
1383
1432
  //# sourceMappingURL=index.js.map