agents 0.23.0 → 0.24.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 (98) hide show
  1. package/dist/{agent-routing-DE5zmCQ8.d.ts → agent-routing-B2XLNMxq.d.ts} +196 -189
  2. package/dist/agent-routing.d.ts +1 -1
  3. package/dist/agent-tool-types.d.ts +26 -26
  4. package/dist/{agent-tools-DtXMTDGM.d.ts → agent-tools-Dj5Mzlw7.d.ts} +7 -7
  5. package/dist/agent-tools.d.ts +21 -21
  6. package/dist/{capability-BjSKYpzg.js → capability-B4WbF81e.js} +2 -1
  7. package/dist/capability-B4WbF81e.js.map +1 -0
  8. package/dist/{capability-runner-Be_-PLR1.d.ts → capability-runner-BUBa6Ake.d.ts} +40 -15
  9. package/dist/chat/index.d.ts +14 -11
  10. package/dist/chat/index.js +11 -7
  11. package/dist/chat/index.js.map +1 -1
  12. package/dist/chat-sdk/index.d.ts +3 -3
  13. package/dist/chat-sdk/index.js +1 -1
  14. package/dist/client-BxdkCuVy.d.ts +411 -0
  15. package/dist/client-C9DAjZIY.js +518 -0
  16. package/dist/client-C9DAjZIY.js.map +1 -0
  17. package/dist/{client-jagG8a9_.js → client-fyQrLGkD.js} +2 -2
  18. package/dist/{client-jagG8a9_.js.map → client-fyQrLGkD.js.map} +1 -1
  19. package/dist/client.d.ts +27 -283
  20. package/dist/client.js +2 -274
  21. package/dist/current-agent-C4w86kcN.d.ts +93 -0
  22. package/dist/{current-agent-Da_C9a3b.d.ts → durable-object-lifecycle-ei7M7lqB.d.ts} +13 -122
  23. package/dist/index-Dlgtd3Mj.d.ts +78 -0
  24. package/dist/index.d.ts +59 -59
  25. package/dist/index.js +2 -2
  26. package/dist/internal_context.d.ts +1 -1
  27. package/dist/lifecycle/index.d.ts +19 -17
  28. package/dist/lifecycle/index.js +2 -2
  29. package/dist/{lifecycle-CMRGjZdw.js → lifecycle-Mm_jQh7r.js} +36 -21
  30. package/dist/lifecycle-Mm_jQh7r.js.map +1 -0
  31. package/dist/mcp/client/index.d.ts +20 -20
  32. package/dist/mcp/client/index.js +1 -1
  33. package/dist/mcp/index.d.ts +35 -35
  34. package/dist/mcp/index.js +2 -2
  35. package/dist/queue/index.d.ts +123 -0
  36. package/dist/queue/index.js +2 -0
  37. package/dist/queue-BC9F5cUo.js +406 -0
  38. package/dist/queue-BC9F5cUo.js.map +1 -0
  39. package/dist/react.d.ts +33 -15
  40. package/dist/react.js +31 -8
  41. package/dist/react.js.map +1 -1
  42. package/dist/{retries-D9Ds-1lz.d.ts → retries-D9B2UCq3.d.ts} +9 -3
  43. package/dist/retries.d.ts +5 -3
  44. package/dist/retries.js +9 -1
  45. package/dist/retries.js.map +1 -1
  46. package/dist/routing/index.d.ts +2 -2
  47. package/dist/routing/index.js +1 -1
  48. package/dist/{scheduler-Dwh85ZGl.d.ts → scheduler-BGq6M5Kd.d.ts} +6 -6
  49. package/dist/{scheduler-DD9NdYbF.js → scheduler-D_KHqxBa.js} +4 -11
  50. package/dist/scheduler-D_KHqxBa.js.map +1 -0
  51. package/dist/schedules/index.d.ts +1 -1
  52. package/dist/schedules/index.js +1 -1
  53. package/dist/serializable.d.ts +1 -1
  54. package/dist/sessions/index.d.ts +1 -1
  55. package/dist/sessions/index.js +1 -1
  56. package/dist/{src-DlSHshb2.js → src-BNU3ZiJM.js} +126 -393
  57. package/dist/src-BNU3ZiJM.js.map +1 -0
  58. package/dist/state/index.d.ts +6 -0
  59. package/dist/state/index.js +137 -0
  60. package/dist/state/index.js.map +1 -0
  61. package/dist/streams/index.d.ts +1 -1
  62. package/dist/streams/index.js +1 -1
  63. package/dist/{streams-D6tJ0NN9.d.ts → streams-BcE8JP2X.d.ts} +2 -2
  64. package/dist/{streams-DZKgAj9b.js → streams-CCPRV6dt.js} +2 -2
  65. package/dist/{streams-DZKgAj9b.js.map → streams-CCPRV6dt.js.map} +1 -1
  66. package/dist/sub-routing.d.ts +12 -12
  67. package/dist/tasks/index.d.ts +1 -1
  68. package/dist/tasks/index.js +1 -1
  69. package/dist/{tasks-ylZgBjhj.js → tasks-D4nLqVSI.js} +3 -3
  70. package/dist/{tasks-ylZgBjhj.js.map → tasks-D4nLqVSI.js.map} +1 -1
  71. package/dist/{tasks-BRJ5zgya.d.ts → tasks-V2lCT8ZV.d.ts} +5 -5
  72. package/dist/transport-protocol-BxyngQ_R.js +25 -0
  73. package/dist/transport-protocol-BxyngQ_R.js.map +1 -0
  74. package/dist/transport-protocol-ZTew5Wso.d.ts +27 -0
  75. package/dist/types-DCD6BNZH.d.ts +70 -0
  76. package/dist/voice/index.d.ts +2 -2
  77. package/dist/websockets/index.d.ts +178 -69
  78. package/dist/websockets/index.js +3 -2
  79. package/dist/websockets-D7IzWbZb.js +1005 -0
  80. package/dist/websockets-D7IzWbZb.js.map +1 -0
  81. package/dist/workflow-types.d.ts +25 -25
  82. package/dist/workflows.d.ts +21 -21
  83. package/dist/workflows.js +1 -1
  84. package/docs/agent-class.md +2 -2
  85. package/docs/client-sdk.md +30 -0
  86. package/docs/index.md +1 -1
  87. package/docs/lifecycle.md +97 -22
  88. package/docs/queue.md +135 -241
  89. package/docs/retries.md +1 -1
  90. package/docs/sub-agents.md +3 -3
  91. package/package.json +12 -2
  92. package/dist/capability-BjSKYpzg.js.map +0 -1
  93. package/dist/client.js.map +0 -1
  94. package/dist/lifecycle-CMRGjZdw.js.map +0 -1
  95. package/dist/scheduler-DD9NdYbF.js.map +0 -1
  96. package/dist/src-DlSHshb2.js.map +0 -1
  97. package/dist/websockets-DUfRHPRq.js +0 -502
  98. package/dist/websockets-DUfRHPRq.js.map +0 -1
@@ -1,10 +1,10 @@
1
1
  import {
2
- J as AgentToolRunPart,
3
- R as AgentToolEventMessage,
4
- W as AgentToolProgress,
5
- Z as AgentToolStoredChunk,
6
- z as AgentToolEventState
7
- } from "./agent-routing-DE5zmCQ8.js";
2
+ L as AgentToolEventMessage,
3
+ R as AgentToolEventState,
4
+ U as AgentToolProgress,
5
+ X as AgentToolStoredChunk,
6
+ q as AgentToolRunPart
7
+ } from "./agent-routing-B2XLNMxq.js";
8
8
 
9
9
  //#region src/chat/agent-tools.d.ts
10
10
  type AgentToolProgressEmitResult = "emitted" | "coalesced" | "inactive";
@@ -130,4 +130,4 @@ export {
130
130
  interceptAgentToolBroadcast as s,
131
131
  AgentToolBroadcastHooks as t
132
132
  };
133
- //# sourceMappingURL=agent-tools-DtXMTDGM.d.ts.map
133
+ //# sourceMappingURL=agent-tools-Dj5Mzlw7.d.ts.map
@@ -1,25 +1,25 @@
1
1
  import {
2
- $ as ChatCapableAgentClass,
3
- B as AgentToolFailure,
4
- F as AgentToolChildAdapter,
5
- H as AgentToolLifecycleResult,
6
- I as AgentToolDisplayMetadata,
7
- J as AgentToolRunPart,
8
- K as AgentToolRunInfo,
9
- L as AgentToolEvent,
10
- Q as AgentToolTerminalStatus,
11
- R as AgentToolEventMessage,
12
- V as AgentToolInterruptedReason,
13
- X as AgentToolRunStatus,
14
- Y as AgentToolRunState,
15
- Z as AgentToolStoredChunk,
16
- et as DetachedAgentToolConfig,
17
- nt as RunAgentToolOptions,
18
- q as AgentToolRunInspection,
19
- rt as RunAgentToolResult,
20
- tt as DetachedRunAgentToolResult,
21
- z as AgentToolEventState
22
- } from "./agent-routing-DE5zmCQ8.js";
2
+ $ as DetachedAgentToolConfig,
3
+ B as AgentToolInterruptedReason,
4
+ F as AgentToolDisplayMetadata,
5
+ G as AgentToolRunInfo,
6
+ I as AgentToolEvent,
7
+ J as AgentToolRunState,
8
+ K as AgentToolRunInspection,
9
+ L as AgentToolEventMessage,
10
+ P as AgentToolChildAdapter,
11
+ Q as ChatCapableAgentClass,
12
+ R as AgentToolEventState,
13
+ V as AgentToolLifecycleResult,
14
+ X as AgentToolStoredChunk,
15
+ Y as AgentToolRunStatus,
16
+ Z as AgentToolTerminalStatus,
17
+ et as DetachedRunAgentToolResult,
18
+ nt as RunAgentToolResult,
19
+ q as AgentToolRunPart,
20
+ tt as RunAgentToolOptions,
21
+ z as AgentToolFailure
22
+ } from "./agent-routing-B2XLNMxq.js";
23
23
  import { FlexibleSchema, InferSchema, Tool } from "ai";
24
24
 
25
25
  //#region src/agent-tools.d.ts
@@ -7,6 +7,7 @@ const installedServices = /* @__PURE__ */ new WeakMap();
7
7
  */
8
8
  var LifecycleCapability = class {
9
9
  constructor(capabilityId) {
10
+ this.claims = "selective";
10
11
  if (capabilityId.trim() === "") throw new Error("Lifecycle capability IDs must be non-empty");
11
12
  this.capabilityId = capabilityId;
12
13
  }
@@ -39,4 +40,4 @@ function lifecycleCapabilityId(capability) {
39
40
  //#endregion
40
41
  export { bindLifecycleCapability as n, lifecycleCapabilityId as r, LifecycleCapability as t };
41
42
 
42
- //# sourceMappingURL=capability-BjSKYpzg.js.map
43
+ //# sourceMappingURL=capability-B4WbF81e.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability-B4WbF81e.js","names":[],"sources":["../src/lifecycle/capability.ts"],"sourcesContent":["import type {\n CapabilityStartContext,\n DurableObjectCapability\n} from \"./capability-runner\";\nimport type { Connection } from \"./types\";\nimport type { LifecycleJobs } from \"./job-queue\";\n\n/** Opaque address understood by a Lifecycle routing transport. */\nexport type LifecycleRouteAddress = {\n /** Stable equality and storage key. */\n readonly key: string;\n /** Transport-owned serialized address. */\n readonly data: string;\n};\n\n/** Context supplied with a routed capability message. */\nexport type LifecycleRouteContext = {\n /** Address of the sending Lifecycle, or undefined for an unrouted root. */\n readonly source: LifecycleRouteAddress | undefined;\n /** Capability-owned message payload. */\n readonly payload: unknown;\n};\n\n/** Startup state of a Lifecycle. */\nexport type LifecycleStatus = \"zero\" | \"starting\" | \"started\";\n\n/** Best-effort telemetry available to every Lifecycle capability. */\nexport type LifecycleEvents = {\n /** Publish an event under this capability's stable identity. */\n readonly emit: (type: string, payload: unknown) => void;\n};\n\n/** Routing available to every Lifecycle capability. */\nexport type LifecycleRoutes = {\n /** This Lifecycle's transport address, or undefined at the route root. */\n readonly source: LifecycleRouteAddress | undefined;\n /** Route a capability-owned message to the root Lifecycle. */\n readonly toRoot: (payload: unknown) => Promise<unknown>;\n /** Route a capability-owned message to another Lifecycle. */\n readonly to: (\n target: LifecycleRouteAddress,\n payload: unknown\n ) => Promise<unknown>;\n};\n\n/**\n * Ambient scope a capability supplies when entering host context on\n * behalf of a live connection or request.\n */\nexport type LifecycleHostContextScope = {\n /** The connection the callback runs on behalf of, when there is one. */\n readonly connection?: Connection;\n /** The request the callback runs on behalf of, when there is one. */\n readonly request?: Request;\n};\n\n/**\n * The platform's hibernatable-socket surface, exposed narrowly so a\n * capability that owns connections (e.g. WebSockets) can accept and\n * enumerate them without holding the whole `DurableObjectState`.\n * These are workerd API names, not Lifecycle modeling sockets.\n */\nexport type LifecycleSockets = {\n /** Accept a socket into hibernation under the given tags. */\n readonly accept: (ws: WebSocket, tags: string[]) => void;\n /** Every hibernated socket on the object, optionally by tag. */\n readonly get: (tag?: string) => WebSocket[];\n};\n\n/**\n * Standard services granted to every installed Lifecycle capability.\n *\n * @experimental The API surface may change before stabilizing.\n */\nexport type LifecycleServices = {\n /** The host's Durable Object name; see `Lifecycle.name`. */\n readonly name: string;\n /** The host class name, as exported from the Worker. */\n readonly className: string;\n readonly storage: DurableObjectStorage;\n readonly sockets: LifecycleSockets;\n readonly ready: () => Promise<void>;\n /**\n * Startup state: `\"zero\"` before startup, `\"starting\"` while capability\n * and host startup hooks run, `\"started\"` once `ready()` resolves without\n * waiting.\n */\n readonly status: () => LifecycleStatus;\n /**\n * This capability's scoped access to the Lifecycle-owned work queue.\n * Pushed items are dispatched to `onJob` when due; every queue mutation\n * re-arms the physical alarm automatically.\n */\n readonly jobs: LifecycleJobs;\n /**\n * Keep work this capability hands off at a bounded `onJob` return inside\n * the current alarm's memory-limit breaker domain (#1825). Returns false,\n * tracking nothing, outside an alarm invocation.\n */\n readonly trackAlarmWork: (work: Promise<unknown>) => boolean;\n /**\n * Run a capability-held user callback inside the host invocation context.\n * Capability hooks run outside host context; this is the one boundary for\n * entering it, and a host composition root may substitute its own wrapper\n * (Agent adds tracing span scope). Pass `scope` to make a live\n * connection or request ambient for the callback.\n */\n readonly runInHostContext: (\n fn: () => unknown,\n scope?: LifecycleHostContextScope\n ) => Promise<unknown>;\n readonly events: LifecycleEvents;\n readonly routes: LifecycleRoutes;\n};\n\nconst installedServices = new WeakMap<object, LifecycleServices>();\n\n/**\n * Base class for capabilities that consume standard Lifecycle services.\n *\n * @experimental The API surface may change before stabilizing.\n */\nexport abstract class LifecycleCapability<Props extends object = object> {\n readonly capabilityId: string;\n\n /** How this capability claims traffic; see {@link DurableObjectCapability.claims}. */\n readonly claims: \"selective\" | \"catch-all\" = \"selective\";\n\n protected constructor(capabilityId: string) {\n if (capabilityId.trim() === \"\") {\n throw new Error(\"Lifecycle capability IDs must be non-empty\");\n }\n this.capabilityId = capabilityId;\n }\n\n /** Default startup hook; capabilities override when they own startup work. */\n onStart(_context: CapabilityStartContext<Props>): void {}\n\n /** Standard services when installed, or undefined in isolated unit tests. */\n protected get lifecycleServices(): LifecycleServices | undefined {\n return installedServices.get(this);\n }\n\n /** Standard services supplied when Lifecycle installs this capability. */\n protected get lifecycle(): LifecycleServices {\n const services = this.lifecycleServices;\n if (!services) {\n throw new Error(\n `${this.constructor.name} must be installed with Lifecycle.use() before use`\n );\n }\n return services;\n }\n}\n\n/**\n * @internal Bind the standard service surface to one capability instance.\n * `Lifecycle.use()` calls this during installation. Test a capability by\n * installing it on a minimal Durable Object with a real Lifecycle rather\n * than binding fake services.\n */\nexport function bindLifecycleCapability(\n capability: LifecycleCapability,\n services: LifecycleServices\n): void {\n installedServices.set(capability, services);\n}\n\n/** @internal Read a capability ID without exposing installation internals. */\nexport function lifecycleCapabilityId(\n capability: DurableObjectCapability\n): string | undefined {\n return capability instanceof LifecycleCapability\n ? capability.capabilityId\n : undefined;\n}\n"],"mappings":";AAmHA,MAAM,oCAAoB,IAAI,QAAmC;;;;;;AAOjE,IAAsB,sBAAtB,MAAyE;CAMvE,YAAsB,cAAsB;EAF5C,KAAS,SAAoC;EAG3C,IAAI,aAAa,KAAK,MAAM,IAC1B,MAAM,IAAI,MAAM,4CAA4C;EAE9D,KAAK,eAAe;CACtB;;CAGA,QAAQ,UAA+C,CAAC;;CAGxD,IAAc,oBAAmD;EAC/D,OAAO,kBAAkB,IAAI,IAAI;CACnC;;CAGA,IAAc,YAA+B;EAC3C,MAAM,WAAW,KAAK;EACtB,IAAI,CAAC,UACH,MAAM,IAAI,MACR,GAAG,KAAK,YAAY,KAAK,mDAC3B;EAEF,OAAO;CACT;AACF;;;;;;;AAQA,SAAgB,wBACd,YACA,UACM;CACN,kBAAkB,IAAI,YAAY,QAAQ;AAC5C;;AAGA,SAAgB,sBACd,YACoB;CACpB,OAAO,sBAAsB,sBACzB,WAAW,eACX,KAAA;AACN"}
@@ -1,4 +1,4 @@
1
- import { t as RetryOptions } from "./retries-D9Ds-1lz.js";
1
+ import { t as RetryOptions } from "./retries-D9B2UCq3.js";
2
2
 
3
3
  //#region src/lifecycle/types.d.ts
4
4
  type ImmutablePrimitive = undefined | null | boolean | string | number;
@@ -174,6 +174,8 @@ type LifecycleRouteContext = {
174
174
  | undefined /** Capability-owned message payload. */;
175
175
  readonly payload: unknown;
176
176
  };
177
+ /** Startup state of a Lifecycle. */
178
+ type LifecycleStatus = "zero" | "starting" | "started";
177
179
  /** Best-effort telemetry available to every Lifecycle capability. */
178
180
  type LifecycleEvents = {
179
181
  /** Publish an event under this capability's stable identity. */ readonly emit: (
@@ -221,10 +223,17 @@ type LifecycleSockets = {
221
223
  * @experimental The API surface may change before stabilizing.
222
224
  */
223
225
  type LifecycleServices = {
226
+ /** The host's Durable Object name; see `Lifecycle.name`. */ readonly name: string /** The host class name, as exported from the Worker. */;
227
+ readonly className: string;
224
228
  readonly storage: DurableObjectStorage;
225
229
  readonly sockets: LifecycleSockets;
226
- readonly ready: () => Promise<void> /** True while capability and host startup hooks are still running. */;
227
- readonly starting: () => boolean;
230
+ readonly ready: () => Promise<void>;
231
+ /**
232
+ * Startup state: `"zero"` before startup, `"starting"` while capability
233
+ * and host startup hooks run, `"started"` once `ready()` resolves without
234
+ * waiting.
235
+ */
236
+ readonly status: () => LifecycleStatus;
228
237
  /**
229
238
  * This capability's scoped access to the Lifecycle-owned work queue.
230
239
  * Pushed items are dispatched to `onJob` when due; every queue mutation
@@ -258,6 +267,8 @@ type LifecycleServices = {
258
267
  */
259
268
  declare abstract class LifecycleCapability<Props extends object = object> {
260
269
  readonly capabilityId: string;
270
+ /** How this capability claims traffic; see {@link DurableObjectCapability.claims}. */
271
+ readonly claims: "selective" | "catch-all";
261
272
  protected constructor(capabilityId: string);
262
273
  /** Default startup hook; capabilities override when they own startup work. */
263
274
  onStart(_context: CapabilityStartContext<Props>): void;
@@ -334,7 +345,7 @@ type MemoryLimitContext = {
334
345
  *
335
346
  * Dispatch contract, hook by hook:
336
347
  * - `onRequest` and `onWebSocketUpgrade` are offered in declaration
337
- * order, fallbacks last; the first capability to return a `Response`
348
+ * order, the catch-all last; the first capability to return a `Response`
338
349
  * claims the request, and a claimed upgrade's socket belongs to that
339
350
  * capability for its whole lifetime.
340
351
  * - `onWebSocketMessage`/`onWebSocketClose`/`onWebSocketError` are
@@ -349,6 +360,19 @@ type MemoryLimitContext = {
349
360
  * @experimental The API surface may change before stabilizing.
350
361
  */
351
362
  interface DurableObjectCapability<Props extends object = object> {
363
+ /**
364
+ * How this capability claims traffic. Default: `"selective"`.
365
+ *
366
+ * A `"selective"` capability answers only requests and upgrades it
367
+ * recognizes and declines the rest. A `"catch-all"` claims everything
368
+ * offered to the hooks it implements, so Lifecycle always places it
369
+ * last, whenever it was installed, and refuses a second catch-all for
370
+ * the same hook. Catch-alls for disjoint hooks coexist: `WebSockets`
371
+ * claims every upgrade and implements no `onRequest`, so an HTTP
372
+ * catch-all installs beside it. Selective HTTP capabilities target
373
+ * their own routes and run before either.
374
+ */
375
+ readonly claims?: "selective" | "catch-all";
352
376
  /** Initialize or recover the capability before the host handles work. */
353
377
  onStart?(context: CapabilityStartContext<Props>): MaybePromise<void>;
354
378
  /**
@@ -431,16 +455,17 @@ interface DurableObjectCapability<Props extends object = object> {
431
455
  }
432
456
  //#endregion
433
457
  export {
434
- ConnectionState as C,
435
- ConnectionSetStateFn as S,
436
- LifecycleJobOutcome as _,
458
+ ConnectionSetStateFn as C,
459
+ ConnectionContext as S,
460
+ WSMessage as T,
461
+ LifecycleJobContext as _,
437
462
  LifecycleEvent as a,
438
- Connection as b,
463
+ LifecycleJobs as b,
439
464
  LifecycleEvents as c,
440
465
  LifecycleRouteContext as d,
441
466
  LifecycleRoutes as f,
442
- LifecycleJobContext as g,
443
- LifecycleJob as h,
467
+ LifecycleJob as g,
468
+ LifecycleStatus as h,
444
469
  DurableObjectCapability as i,
445
470
  LifecycleHostContextScope as l,
446
471
  LifecycleSockets as m,
@@ -451,9 +476,9 @@ export {
451
476
  LifecycleCapability as s,
452
477
  CapabilityRequestContext as t,
453
478
  LifecycleRouteAddress as u,
454
- LifecycleJobPushOptions as v,
455
- WSMessage as w,
456
- ConnectionContext as x,
457
- LifecycleJobs as y
479
+ LifecycleJobOutcome as v,
480
+ ConnectionState as w,
481
+ Connection as x,
482
+ LifecycleJobPushOptions as y
458
483
  };
459
- //# sourceMappingURL=capability-runner-Be_-PLR1.d.ts.map
484
+ //# sourceMappingURL=capability-runner-BUBa6Ake.d.ts.map
@@ -1,18 +1,18 @@
1
- import { o as isPlatformFailure } from "../retries-D9Ds-1lz.js";
1
+ import { o as isPlatformFailure } from "../retries-D9B2UCq3.js";
2
2
  import {
3
- L as AgentToolEvent,
4
- R as AgentToolEventMessage,
5
- Y as AgentToolRunState,
6
- _ as FiberRecoveryContext$1,
7
- z as AgentToolEventState
8
- } from "../agent-routing-DE5zmCQ8.js";
9
- import { _ as TaskStep, m as TaskRunOptions } from "../tasks-BRJ5zgya.js";
3
+ I as AgentToolEvent,
4
+ J as AgentToolRunState,
5
+ L as AgentToolEventMessage,
6
+ R as AgentToolEventState,
7
+ _ as FiberRecoveryContext$1
8
+ } from "../agent-routing-B2XLNMxq.js";
9
+ import { _ as TaskStep, m as TaskRunOptions } from "../tasks-V2lCT8ZV.js";
10
10
  import {
11
11
  n as ClientToolSchema,
12
12
  r as createToolsFromClientSchemas,
13
13
  t as ClientToolExecutor
14
14
  } from "../client-tools-aIBO0Fk7.js";
15
- import { n as Streams } from "../streams-D6tJ0NN9.js";
15
+ import { n as Streams } from "../streams-BcE8JP2X.js";
16
16
  import {
17
17
  a as applyAgentToolEvent,
18
18
  i as AgentToolProgressEmitter,
@@ -21,7 +21,7 @@ import {
21
21
  r as AgentToolProgressEmitResult,
22
22
  s as interceptAgentToolBroadcast,
23
23
  t as AgentToolBroadcastHooks
24
- } from "../agent-tools-DtXMTDGM.js";
24
+ } from "../agent-tools-Dj5Mzlw7.js";
25
25
  import { l as SessionMessage } from "../types-B7LojTe4.js";
26
26
  import { JSONSchema7, UIMessage } from "ai";
27
27
  import { Connection, FiberRecoveryContext } from "agents";
@@ -942,7 +942,8 @@ declare class ResumableStream {
942
942
  * crash leaves either the live stream or the finished message, never
943
943
  * neither; nothing is left to sweep. `discard: false` keeps the settled
944
944
  * rows (an agent-tool child whose parent still tails them); they are
945
- * reclaimed by the next {@link start}.
945
+ * reclaimed by the next {@link start}. The settlement and `persist`
946
+ * writes commit or roll back together.
946
947
  */
947
948
  cutover(
948
949
  streamId: string,
@@ -954,6 +955,8 @@ declare class ResumableStream {
954
955
  /**
955
956
  * Settle a {@link finish}ed stream that had nothing to persist (no parts,
956
957
  * a persist that threw). Idempotent; a no-op when nothing is pending.
958
+ * The pending marker clears only once settlement succeeds, so a caller
959
+ * may retry after a settlement failure — matching {@link cutover}.
957
960
  */
958
961
  finalizePending(): void;
959
962
  private _clearActive;
@@ -4,7 +4,7 @@ import { i as interceptAgentToolBroadcast, n as applyAgentToolEvent, r as create
4
4
  import { t as TextSegmentJoiner } from "../text-segment-joiner-BtAFQSA_.js";
5
5
  import { n as sanitizeMessage, t as byteLength } from "../sanitize-D9TujEK8.js";
6
6
  import { i as StreamAccumulator, n as STREAM_RESUME_NONE_REASONS, r as transition, t as CHAT_MESSAGE_TYPES } from "../protocol-B0nh6KNf.js";
7
- import { n as Streams } from "../streams-DZKgAj9b.js";
7
+ import { n as Streams } from "../streams-CCPRV6dt.js";
8
8
  import { t as MessageType } from "../wire-types-CnMt6_HR.js";
9
9
  import { jsonSchema, tool } from "ai";
10
10
  import { nanoid } from "nanoid";
@@ -492,8 +492,8 @@ const REPLAY_PAGE_SEGMENTS = 10;
492
492
  * the newest chunk's timestamp for rows past it — so a long but still-active
493
493
  * stream is never reclaimed mid-flight. Terminal rows carry no such window:
494
494
  * a stream that finished is redundant with its persisted message, and the
495
- * cutover deletes it in the same transaction; anything a crash left behind
496
- * is reclaimed by the next {@link ResumableStream.start}.
495
+ * cutover deletes it in the same transaction; leftovers are reclaimed by
496
+ * the next {@link ResumableStream.start}.
497
497
  */
498
498
  const ABANDONED_STREAM_RETENTION_MS = 3600 * 1e3;
499
499
  /** Shared encoder for UTF-8 byte length measurement */
@@ -814,29 +814,33 @@ var ResumableStream = class {
814
814
  * crash leaves either the live stream or the finished message, never
815
815
  * neither; nothing is left to sweep. `discard: false` keeps the settled
816
816
  * rows (an agent-tool child whose parent still tails them); they are
817
- * reclaimed by the next {@link start}.
817
+ * reclaimed by the next {@link start}. The settlement and `persist`
818
+ * writes commit or roll back together.
818
819
  */
819
820
  cutover(streamId, persist, options = {}) {
820
821
  this.flushBuffer();
821
822
  const discard = options.discard ?? true;
823
+ const commit = persist;
822
824
  const settled = this.ops.settle(streamId, "completed", null, {
823
- commit: persist,
825
+ commit,
824
826
  discard
825
827
  });
826
828
  if (settled && discard) this._notifyProgress();
827
- if (!settled) persist();
829
+ if (!settled) commit();
828
830
  if (this._pendingCutover === streamId) this._pendingCutover = null;
829
831
  this._clearActive();
830
832
  }
831
833
  /**
832
834
  * Settle a {@link finish}ed stream that had nothing to persist (no parts,
833
835
  * a persist that threw). Idempotent; a no-op when nothing is pending.
836
+ * The pending marker clears only once settlement succeeds, so a caller
837
+ * may retry after a settlement failure — matching {@link cutover}.
834
838
  */
835
839
  finalizePending() {
836
840
  const streamId = this._pendingCutover;
837
841
  if (streamId === null) return;
838
- this._pendingCutover = null;
839
842
  this.ops.settle(streamId, "completed", null);
843
+ this._pendingCutover = null;
840
844
  }
841
845
  _clearActive() {
842
846
  this._activeStreamId = null;