agents 0.22.0 → 0.23.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 (186) hide show
  1. package/README.md +20 -1
  2. package/dist/{agent-routing-CnkaHb-v.d.ts → agent-routing-DE5zmCQ8.d.ts} +1038 -394
  3. package/dist/agent-routing.d.ts +1 -1
  4. package/dist/agent-tool-types.d.ts +26 -26
  5. package/dist/{agent-tools-C0XJqWzB.d.ts → agent-tools-DtXMTDGM.d.ts} +7 -7
  6. package/dist/agent-tools.d.ts +21 -21
  7. package/dist/browser/ai.js +4 -1
  8. package/dist/browser/ai.js.map +1 -1
  9. package/dist/browser/tanstack-ai.js.map +1 -1
  10. package/dist/callable-decorator-DP__HhBA.d.ts +72 -0
  11. package/dist/callable-decorator.d.ts +18 -0
  12. package/dist/callable-decorator.js +71 -0
  13. package/dist/callable-decorator.js.map +1 -0
  14. package/dist/capability-BjSKYpzg.js.map +1 -1
  15. package/dist/capability-runner-Be_-PLR1.d.ts +459 -0
  16. package/dist/channel-Bnm4S7T2.d.ts +491 -0
  17. package/dist/channels/ai-sdk.d.ts +46 -0
  18. package/dist/channels/ai-sdk.js +120 -0
  19. package/dist/channels/ai-sdk.js.map +1 -0
  20. package/dist/channels/email.d.ts +95 -0
  21. package/dist/channels/email.js +323 -0
  22. package/dist/channels/email.js.map +1 -0
  23. package/dist/channels/index.d.ts +233 -0
  24. package/dist/channels/index.js +608 -0
  25. package/dist/channels/index.js.map +1 -0
  26. package/dist/channels/slack.d.ts +140 -0
  27. package/dist/channels/slack.js +614 -0
  28. package/dist/channels/slack.js.map +1 -0
  29. package/dist/channels/tanstack-ai.d.ts +39 -0
  30. package/dist/channels/tanstack-ai.js +17 -0
  31. package/dist/channels/tanstack-ai.js.map +1 -0
  32. package/dist/channels/telegram.d.ts +106 -0
  33. package/dist/channels/telegram.js +427 -0
  34. package/dist/channels/telegram.js.map +1 -0
  35. package/dist/channels/voice.d.ts +45 -0
  36. package/dist/channels/voice.js +122 -0
  37. package/dist/channels/voice.js.map +1 -0
  38. package/dist/chat/index.d.ts +2325 -2019
  39. package/dist/chat/index.js +888 -518
  40. package/dist/chat/index.js.map +1 -1
  41. package/dist/chat-sdk/index.d.ts +7 -7
  42. package/dist/chat-sdk/index.js +1 -1
  43. package/dist/client.d.ts +1 -1
  44. package/dist/context/index.d.ts +216 -0
  45. package/dist/context/index.js +454 -0
  46. package/dist/context/index.js.map +1 -0
  47. package/dist/{current-agent-CuMErtly.d.ts → current-agent-Da_C9a3b.d.ts} +90 -107
  48. package/dist/current-agent-DhoDkSnH.js.map +1 -1
  49. package/dist/{diagnostics-CaBjfz4J.js → diagnostics-BzvaX2UT.js} +5 -1
  50. package/dist/diagnostics-BzvaX2UT.js.map +1 -0
  51. package/dist/diagnostics-C4jcz3VK.js +360 -0
  52. package/dist/diagnostics-C4jcz3VK.js.map +1 -0
  53. package/dist/index-BB0kqhIz.d.ts +101 -0
  54. package/dist/index-BVVgDSdq.d.ts +1 -0
  55. package/dist/index-XDkuQ7zm.d.ts +89 -0
  56. package/dist/{index-DcSAZKsB.d.ts → index-YSKgfgg9.d.ts} +3 -1
  57. package/dist/index.d.ts +91 -82
  58. package/dist/index.js +3 -2
  59. package/dist/ingress-BfetZbMO.js +83 -0
  60. package/dist/ingress-BfetZbMO.js.map +1 -0
  61. package/dist/internal-CYlgHl1l.js +59 -0
  62. package/dist/internal-CYlgHl1l.js.map +1 -0
  63. package/dist/internal_context.d.ts +1 -1
  64. package/dist/lifecycle/index.d.ts +35 -17
  65. package/dist/lifecycle/index.js +1 -1
  66. package/dist/lifecycle-CMRGjZdw.js +1299 -0
  67. package/dist/lifecycle-CMRGjZdw.js.map +1 -0
  68. package/dist/mcp/client/index.d.ts +20 -20
  69. package/dist/mcp/index.d.ts +35 -35
  70. package/dist/mcp/index.js +1 -1
  71. package/dist/observability/index.d.ts +1 -1
  72. package/dist/observability/index.js +1 -1
  73. package/dist/react.d.ts +4 -4
  74. package/dist/{retries-CAvxtG9d.d.ts → retries-D9Ds-1lz.d.ts} +17 -6
  75. package/dist/retries.d.ts +8 -6
  76. package/dist/retries.js +13 -1
  77. package/dist/retries.js.map +1 -1
  78. package/dist/routing/index.d.ts +137 -0
  79. package/dist/routing/index.js +244 -0
  80. package/dist/routing/index.js.map +1 -0
  81. package/dist/sanitize-D9TujEK8.js +79 -0
  82. package/dist/sanitize-D9TujEK8.js.map +1 -0
  83. package/dist/scheduler-DD9NdYbF.js +665 -0
  84. package/dist/scheduler-DD9NdYbF.js.map +1 -0
  85. package/dist/{scheduler-DQoTGoAW.d.ts → scheduler-Dwh85ZGl.d.ts} +21 -22
  86. package/dist/schedules/index.d.ts +1 -1
  87. package/dist/schedules/index.js +1 -1
  88. package/dist/sentence-chunker-BAidJ4DA.d.ts +68 -0
  89. package/dist/serializable.d.ts +1 -1
  90. package/dist/sessions/index.d.ts +441 -0
  91. package/dist/sessions/index.js +2063 -0
  92. package/dist/sessions/index.js.map +1 -0
  93. package/dist/skills/index.d.ts +99 -0
  94. package/dist/skills/index.js +254 -5
  95. package/dist/skills/index.js.map +1 -1
  96. package/dist/{src-5W6JNKVb.js → src-DlSHshb2.js} +1460 -1110
  97. package/dist/src-DlSHshb2.js.map +1 -0
  98. package/dist/streams/index.d.ts +120 -0
  99. package/dist/streams/index.js +107 -0
  100. package/dist/streams/index.js.map +1 -0
  101. package/dist/streams-D6tJ0NN9.d.ts +370 -0
  102. package/dist/streams-DZKgAj9b.js +709 -0
  103. package/dist/streams-DZKgAj9b.js.map +1 -0
  104. package/dist/sub-routing.d.ts +12 -12
  105. package/dist/surface-bZZJqBka.js +17 -0
  106. package/dist/surface-bZZJqBka.js.map +1 -0
  107. package/dist/tasks/index.d.ts +64 -0
  108. package/dist/tasks/index.js +2 -0
  109. package/dist/tasks-BRJ5zgya.d.ts +517 -0
  110. package/dist/tasks-ylZgBjhj.js +1656 -0
  111. package/dist/tasks-ylZgBjhj.js.map +1 -0
  112. package/dist/text-segment-joiner-BtAFQSA_.js +57 -0
  113. package/dist/text-segment-joiner-BtAFQSA_.js.map +1 -0
  114. package/dist/text-stream-CpdiKrJB.js +272 -0
  115. package/dist/text-stream-CpdiKrJB.js.map +1 -0
  116. package/dist/tokens-nHAKcN6M.js +52 -0
  117. package/dist/tokens-nHAKcN6M.js.map +1 -0
  118. package/dist/tool-schema-CBjGPrsQ.js +31 -0
  119. package/dist/tool-schema-CBjGPrsQ.js.map +1 -0
  120. package/dist/types-B7LojTe4.d.ts +202 -0
  121. package/dist/types-_Faxb570.d.ts +439 -0
  122. package/dist/voice/client.d.ts +226 -0
  123. package/dist/voice/client.js +932 -0
  124. package/dist/voice/client.js.map +1 -0
  125. package/dist/voice/errors.d.ts +43 -0
  126. package/dist/voice/errors.js +41 -0
  127. package/dist/voice/errors.js.map +1 -0
  128. package/dist/voice/index.d.ts +271 -0
  129. package/dist/voice/index.js +1812 -0
  130. package/dist/voice/index.js.map +1 -0
  131. package/dist/voice/react.d.ts +167 -0
  132. package/dist/voice/react.js +234 -0
  133. package/dist/voice/react.js.map +1 -0
  134. package/dist/voice/sfu.d.ts +71 -0
  135. package/dist/voice/sfu.js +157 -0
  136. package/dist/voice/sfu.js.map +1 -0
  137. package/dist/voice/text.d.ts +6 -0
  138. package/dist/voice/text.js +2 -0
  139. package/dist/voice/types.d.ts +58 -0
  140. package/dist/voice/types.js +18 -0
  141. package/dist/voice/types.js.map +1 -0
  142. package/dist/voice/workers-ai.d.ts +136 -0
  143. package/dist/voice/workers-ai.js +568 -0
  144. package/dist/voice/workers-ai.js.map +1 -0
  145. package/dist/websockets/index.d.ts +192 -0
  146. package/dist/websockets/index.js +2 -0
  147. package/dist/websockets-DUfRHPRq.js +502 -0
  148. package/dist/websockets-DUfRHPRq.js.map +1 -0
  149. package/dist/workflow-types.d.ts +25 -25
  150. package/dist/workflows.d.ts +21 -21
  151. package/dist/workflows.js +1 -1
  152. package/docs/agent-class.md +2 -2
  153. package/docs/agent-tools.md +2 -1
  154. package/docs/channels.md +323 -0
  155. package/docs/chat-agents.md +6 -13
  156. package/docs/context.md +131 -0
  157. package/docs/index.md +15 -12
  158. package/docs/lifecycle.md +102 -55
  159. package/docs/long-running-agents.md +2 -2
  160. package/docs/mcp-servers.md +5 -1
  161. package/docs/resumable-streaming.md +1 -1
  162. package/docs/routing.md +105 -0
  163. package/docs/sessions.md +237 -871
  164. package/docs/streams.md +213 -0
  165. package/docs/sub-agents.md +184 -124
  166. package/docs/tasks.md +246 -0
  167. package/docs/voice.md +745 -0
  168. package/package.json +115 -13
  169. package/dist/capability-runner-CvHGZqUu.d.ts +0 -150
  170. package/dist/compaction-helpers-iiKMr2TQ.js +0 -340
  171. package/dist/compaction-helpers-iiKMr2TQ.js.map +0 -1
  172. package/dist/compaction-helpers-wUz6M3us.d.ts +0 -621
  173. package/dist/diagnostics-CaBjfz4J.js.map +0 -1
  174. package/dist/durable-object-lifecycle-D6nNQJJd.js +0 -862
  175. package/dist/durable-object-lifecycle-D6nNQJJd.js.map +0 -1
  176. package/dist/experimental/memory/session/index.d.ts +0 -671
  177. package/dist/experimental/memory/session/index.js +0 -2379
  178. package/dist/experimental/memory/session/index.js.map +0 -1
  179. package/dist/experimental/memory/utils/index.d.ts +0 -96
  180. package/dist/experimental/memory/utils/index.js +0 -79
  181. package/dist/experimental/memory/utils/index.js.map +0 -1
  182. package/dist/scheduler-CR9RHGos.js +0 -857
  183. package/dist/scheduler-CR9RHGos.js.map +0 -1
  184. package/dist/src-5W6JNKVb.js.map +0 -1
  185. package/dist/tool-output-truncation-CNnnGZQ3.js +0 -98
  186. package/dist/tool-output-truncation-CNnnGZQ3.js.map +0 -1
@@ -0,0 +1,517 @@
1
+ import {
2
+ _ as LifecycleJobOutcome,
3
+ d as LifecycleRouteContext,
4
+ g as LifecycleJobContext,
5
+ o as MemoryLimitContext,
6
+ s as LifecycleCapability
7
+ } from "./capability-runner-Be_-PLR1.js";
8
+
9
+ //#region src/tasks/duration.d.ts
10
+ /**
11
+ * Duration parsing for the Tasks capability. Durations appear in step
12
+ * retry delays, per-attempt timeouts, and durable sleeps.
13
+ */
14
+ /** Units accepted in a {@link TaskDurationString}. */
15
+ type TaskDurationUnit = "second" | "minute" | "hour" | "day" | "week";
16
+ /**
17
+ * A human-readable duration such as `"10 seconds"` or `"1 day"`.
18
+ *
19
+ * @experimental The API surface may change before stabilizing.
20
+ */
21
+ type TaskDurationString = `${number} ${TaskDurationUnit}${"" | "s"}`;
22
+ //#endregion
23
+ //#region src/tasks/types.d.ts
24
+ /**
25
+ * JSON-serializable data accepted as Task input, step results, metadata,
26
+ * and final results.
27
+ *
28
+ * @experimental The API surface may change before stabilizing.
29
+ */
30
+ type TaskJson =
31
+ | string
32
+ | number
33
+ | boolean
34
+ | null
35
+ | TaskJson[]
36
+ | {
37
+ [key: string]: TaskJson;
38
+ };
39
+ /**
40
+ * A value a Task handler or step callback may produce. `undefined` and
41
+ * `void` persist as SQL `NULL` and restore as `undefined`.
42
+ *
43
+ * @experimental The API surface may change before stabilizing.
44
+ */
45
+ type TaskValue = TaskJson | undefined | void;
46
+ /**
47
+ * Constraint for a Tasks definitions map: named handlers invoked from the
48
+ * beginning on every execution attempt, with completed steps returning
49
+ * journaled results instead of running again. An unclean interruption —
50
+ * process loss mid-attempt — replays the handler the same way; durable
51
+ * progress lives in the step journal and in whatever durable state the
52
+ * handler wrote (a stream's cursor, an idempotent external write), so
53
+ * handlers resume from evidence instead of receiving a recovery callback.
54
+ *
55
+ * @experimental The API surface may change before stabilizing.
56
+ */
57
+ type TaskHandlers = Record<
58
+ string,
59
+ (input: never, step: TaskStep) => TaskValue | Promise<TaskValue>
60
+ >;
61
+ /**
62
+ * Default definitions surface for a Tasks constructed without a typed map:
63
+ * any name compiles with an untyped input. At runtime a name must be
64
+ * declared in the constructor map or supplied by a composition-root
65
+ * resolver; a bare Tasks rejects it otherwise.
66
+ *
67
+ * @experimental The API surface may change before stabilizing.
68
+ */
69
+ type TaskCallbacks = Record<
70
+ string,
71
+ (input: unknown, step: TaskStep) => TaskValue | Promise<TaskValue>
72
+ >;
73
+ /**
74
+ * The input type a registered Task definition accepts.
75
+ *
76
+ * @experimental The API surface may change before stabilizing.
77
+ */
78
+ type TaskInput<Handler> = Handler extends (
79
+ input: infer Input,
80
+ ...rest: never[]
81
+ ) => unknown
82
+ ? Input
83
+ : never;
84
+ /**
85
+ * The settled output type a registered Task definition produces.
86
+ *
87
+ * @experimental The API surface may change before stabilizing.
88
+ */
89
+ type TaskOutput<Handler> = Handler extends (...args: never[]) => infer Output
90
+ ? Awaited<Output> extends TaskValue
91
+ ? Awaited<Output>
92
+ : never
93
+ : never;
94
+ /**
95
+ * Per-attempt context passed to a `step.do()` callback.
96
+ *
97
+ * @experimental The API surface may change before stabilizing.
98
+ */
99
+ interface TaskStepAttempt {
100
+ /** One-based attempt number for this named step. */
101
+ readonly attempt: number;
102
+ /**
103
+ * Stable external deduplication key for this step: identical across
104
+ * attempts and replays of the same run.
105
+ */
106
+ readonly idempotencyKey: string;
107
+ /** Aborted on cancellation or when this attempt's timeout elapses. */
108
+ readonly signal: AbortSignal;
109
+ }
110
+ /**
111
+ * Retry and timeout policy for one `step.do()` call.
112
+ *
113
+ * @experimental The API surface may change before stabilizing.
114
+ */
115
+ interface TaskStepConfig {
116
+ retries?: {
117
+ /** Total attempts, including the first. */ limit?: number /** Delay before the first retry. */;
118
+ delay?:
119
+ | number
120
+ | TaskDurationString /** Delay growth across retries. Defaults to exponential. */;
121
+ backoff?: "constant" | "linear" | "exponential";
122
+ };
123
+ /** Timeout of one callback attempt. */
124
+ timeout?: number | TaskDurationString;
125
+ }
126
+ /**
127
+ * The step API a Task handler receives. Named steps are the run's durable
128
+ * journal: `do` memoizes completed results, sleeps persist their first
129
+ * deadline, and both suspend the execution attempt rather than holding the
130
+ * invocation open.
131
+ *
132
+ * @experimental The API surface may change before stabilizing.
133
+ */
134
+ interface TaskStep {
135
+ /**
136
+ * The step an unclean interruption left mid-execution, or `null` on a
137
+ * clean attempt — the durable evidence a replayed handler branches on
138
+ * before re-entering irreversible work. Populated when a lost attempt's
139
+ * claim is taken over; a retry park or first attempt sees `null`.
140
+ */
141
+ readonly interrupted: {
142
+ readonly name: string;
143
+ readonly attempt: number;
144
+ } | null;
145
+ /** Run a named step once, replaying its journaled result thereafter. */
146
+ do<T extends TaskValue>(
147
+ name: string,
148
+ callback: (attempt: TaskStepAttempt) => T | Promise<T>
149
+ ): Promise<T>;
150
+ do<T extends TaskValue>(
151
+ name: string,
152
+ config: TaskStepConfig,
153
+ callback: (attempt: TaskStepAttempt) => T | Promise<T>
154
+ ): Promise<T>;
155
+ /**
156
+ * Sleep durably. The first recorded deadline is authoritative; replays
157
+ * before it suspend again, replays after it continue.
158
+ */
159
+ sleep(name: string, duration: number | TaskDurationString): Promise<void>;
160
+ /** Sleep durably until a wall-clock time. */
161
+ sleepUntil(name: string, when: number | Date): Promise<void>;
162
+ /**
163
+ * Update observable progress. Replays stay silent until execution reaches
164
+ * new ground, so old progress is not re-published as new.
165
+ */
166
+ status(message: string): Promise<void>;
167
+ /** The stable external deduplication key `step.do(name, ...)` would get. */
168
+ idempotencyKey(name: string): string;
169
+ }
170
+ /**
171
+ * States a Task run moves through.
172
+ *
173
+ * @experimental The API surface may change before stabilizing.
174
+ */
175
+ type TaskRunState =
176
+ | "pending"
177
+ | "running"
178
+ | "waiting"
179
+ | "completed"
180
+ | "failed"
181
+ | "cancelled";
182
+ /** Why a waiting run is waiting. */
183
+ type TaskWaitReason = "sleep" | "retry";
184
+ /** Safe projection of an error retained with a failed run. */
185
+ interface TaskError {
186
+ name: string;
187
+ message: string;
188
+ }
189
+ /**
190
+ * Options accepted when starting one Task run.
191
+ *
192
+ * @experimental The API surface may change before stabilizing.
193
+ */
194
+ interface TaskRunOptions {
195
+ /** Stable key deduplicating repeated acceptance attempts onto one run. */
196
+ idempotencyKey?: string;
197
+ /** Caller-selected run ID. Generated when omitted. */
198
+ runId?: string;
199
+ /** JSON metadata retained with the run. */
200
+ metadata?: Record<string, TaskJson>;
201
+ /** Keep terminal state for inspection. Defaults to `true`. */
202
+ retain?: boolean;
203
+ }
204
+ /**
205
+ * Durable acceptance receipt returned by `Task.run()`. `accepted: false`
206
+ * means an existing run matched `runId` or `idempotencyKey`; it is not an
207
+ * error.
208
+ *
209
+ * @experimental The API surface may change before stabilizing.
210
+ */
211
+ interface TaskReceipt {
212
+ runId: string;
213
+ definition: string;
214
+ accepted: boolean;
215
+ state: TaskRunState;
216
+ createdAt: number;
217
+ }
218
+ /**
219
+ * Read-only snapshot of one Task run, discriminated by state.
220
+ *
221
+ * @experimental The API surface may change before stabilizing.
222
+ */
223
+ type TaskRunSnapshot<Output extends TaskValue> =
224
+ | {
225
+ runId: string;
226
+ definition: string;
227
+ state: "pending";
228
+ createdAt: number;
229
+ metadata?: Record<string, TaskJson>;
230
+ }
231
+ | {
232
+ runId: string;
233
+ definition: string;
234
+ state: "running";
235
+ attempt: number;
236
+ startedAt: number;
237
+ createdAt: number;
238
+ statusMessage?: string;
239
+ metadata?: Record<string, TaskJson>;
240
+ }
241
+ | {
242
+ runId: string;
243
+ definition: string;
244
+ state: "waiting";
245
+ reason: TaskWaitReason;
246
+ wakeAt: number;
247
+ createdAt: number;
248
+ statusMessage?: string;
249
+ metadata?: Record<string, TaskJson>;
250
+ }
251
+ | {
252
+ runId: string;
253
+ definition: string;
254
+ state: "completed";
255
+ result: Output;
256
+ createdAt: number;
257
+ settledAt: number;
258
+ metadata?: Record<string, TaskJson>;
259
+ }
260
+ | {
261
+ runId: string;
262
+ definition: string;
263
+ state: "failed";
264
+ error: TaskError;
265
+ createdAt: number;
266
+ settledAt: number;
267
+ metadata?: Record<string, TaskJson>;
268
+ }
269
+ | {
270
+ runId: string;
271
+ definition: string;
272
+ state: "cancelled";
273
+ reason?: string;
274
+ createdAt: number;
275
+ settledAt: number;
276
+ metadata?: Record<string, TaskJson>;
277
+ };
278
+ /**
279
+ * Typed handle for one named Task definition, returned by
280
+ * `tasks.create()`. The handle holds no state of its own; it addresses runs
281
+ * of its definition through the owning capability.
282
+ *
283
+ * @experimental The API surface may change before stabilizing.
284
+ */
285
+ interface Task<Input, Output extends TaskValue> {
286
+ readonly name: string;
287
+ /** Durably accept a run and return without waiting for terminal state. */
288
+ run(input: Input, options?: TaskRunOptions): Promise<TaskReceipt>;
289
+ /** Read one run of this definition. */
290
+ get(runId: string): Promise<TaskRunSnapshot<Output> | null>;
291
+ /** Read one run of this definition by its idempotency key. */
292
+ getByIdempotencyKey(
293
+ idempotencyKey: string
294
+ ): Promise<TaskRunSnapshot<Output> | null>;
295
+ /** Request cooperative cancellation. True when a live run was cancelled. */
296
+ cancel(runId: string, reason?: string): Promise<boolean>;
297
+ }
298
+ //#endregion
299
+ //#region src/tasks/options.d.ts
300
+ /** Events emitted while Tasks accepts, executes, retries, or settles runs. */
301
+ type TaskEventType =
302
+ | "task:accepted"
303
+ | "task:attempt:started"
304
+ | "task:attempt:interrupted"
305
+ | "task:step:started"
306
+ | "task:step:retry"
307
+ | "task:step:completed"
308
+ | "task:waiting"
309
+ | "task:completed"
310
+ | "task:failed"
311
+ | "task:cancelled"
312
+ | "task:deleted";
313
+ /**
314
+ * Definitions and policy for a Tasks capability.
315
+ *
316
+ * @experimental The API surface may change before stabilizing.
317
+ */
318
+ interface TasksOptions<Handlers extends TaskHandlers = TaskCallbacks> {
319
+ /**
320
+ * Named Task definitions this capability can run. Each run row persists a
321
+ * definition name; declaring the map in the constructor re-registers the
322
+ * names on every Durable Object wake, so recovery of in-flight runs is
323
+ * correct by construction. Names outside this map are rejected unless a
324
+ * composition-root resolver supplies them.
325
+ */
326
+ readonly definitions?: Handlers;
327
+ /** Default step retry policy, overridable per `step.do()`. */
328
+ readonly retries?: TaskStepConfig["retries"];
329
+ /** Default timeout of one step callback attempt. Default: 5 minutes. */
330
+ readonly stepTimeout?: number | TaskDurationString;
331
+ /** Observe terminal run failures. Runs inside the host invocation context. */
332
+ readonly onError?: (error: unknown) => void | Promise<void>;
333
+ }
334
+ //#endregion
335
+ //#region src/tasks/tasks.d.ts
336
+ /** Filters accepted by {@link Tasks.list}. */
337
+ type TaskListOptions = {
338
+ definition?: string;
339
+ status?: TaskRunState | TaskRunState[];
340
+ limit?: number;
341
+ };
342
+ /** Filters accepted by {@link Tasks.delete}. */
343
+ type TaskDeleteOptions = {
344
+ status?: Array<"completed" | "failed" | "cancelled">;
345
+ settledBefore?: Date;
346
+ limit?: number;
347
+ };
348
+ /**
349
+ * Durable replayable execution for a Lifecycle Object.
350
+ *
351
+ * Declare named definitions in the constructor and install the instance with
352
+ * `Lifecycle.use()`. The constructor map is the registry: it is rebuilt on
353
+ * every Durable Object wake, so in-flight runs always resolve their
354
+ * persisted definition names. Each definition's handler replays from the
355
+ * beginning on every execution attempt; completed steps return journaled
356
+ * results, sleeps consult persisted deadlines, and interrupted work
357
+ * continues from the first unfinished step after process loss.
358
+ *
359
+ * @experimental The API surface may change before stabilizing.
360
+ */
361
+ declare class Tasks<
362
+ Handlers extends TaskHandlers = TaskCallbacks
363
+ > extends LifecycleCapability {
364
+ #private;
365
+ /**
366
+ * Create a Tasks capability.
367
+ *
368
+ * @param options - Named definitions plus default step retry/timeout
369
+ * policy and alarm batching. Declaring `definitions` types {@link run} and
370
+ * {@link handle} against the map — names and inputs are checked where the
371
+ * handlers are declared and where runs start. Names outside the map are
372
+ * rejected unless a composition-root resolver supplies them.
373
+ */
374
+ constructor(options?: TasksOptions<Handlers>);
375
+ /**
376
+ * @internal Framework aperture: register one reserved (`__cf`-prefixed)
377
+ * Task definition directly on this instance, bypassing the constructor's
378
+ * `definitions` map so a host's own subclass layers can each declare their
379
+ * own `definitions` / `taskDefinitions` field without colliding with — or
380
+ * being silently clobbered by — a framework's internal names. Call once per
381
+ * name from the owning host's own constructor, unconditionally, so the
382
+ * definition is rebuilt identically on every Durable Object wake: an
383
+ * in-flight run resolves the same handler for its persisted definition name
384
+ * every time, or it cannot resume.
385
+ *
386
+ * Throws if `name` does not carry the reserved `__cf` prefix — this is not
387
+ * a general-purpose registration path; declare ordinary definitions in the
388
+ * constructor's `definitions` map instead — or if `name` is already
389
+ * registered, which is always a real conflict: this method runs exactly
390
+ * once per name per Tasks construction.
391
+ */
392
+ register(name: string, definition: TaskCallbacks[string]): void;
393
+ /**
394
+ * Durably accept one run of a declared definition and return a receipt
395
+ * without waiting for terminal state. The same `idempotencyKey` or `runId`
396
+ * joins the existing run (`accepted: false`) instead of creating a second.
397
+ */
398
+ run<Name extends keyof Handlers & string>(
399
+ definition: Name,
400
+ input?: TaskInput<Handlers[Name]>,
401
+ options?: TaskRunOptions
402
+ ): Promise<TaskReceipt>;
403
+ /**
404
+ * A typed handle scoped to one declared definition: its `run`, `get`,
405
+ * `getByIdempotencyKey`, and `cancel` see only that definition's runs. The
406
+ * handle is a pure lens over this capability — it holds no state and may
407
+ * be created at any time.
408
+ */
409
+ handle<Name extends keyof Handlers & string>(
410
+ definition: Name
411
+ ): Task<TaskInput<Handlers[Name]>, TaskOutput<Handlers[Name]>>;
412
+ /** Migrate storage and reconcile run deadlines during Lifecycle startup. */
413
+ onStart(): Promise<void>;
414
+ /** Drive one due run's wake dispatched by the Lifecycle event loop. */
415
+ onJob(context: LifecycleJobContext): Promise<LifecycleJobOutcome | void>;
416
+ /**
417
+ * Alarm memory-limit breaker policy (#1825) for the run whose wake struck.
418
+ *
419
+ * The run row is the durable source of truth: startup reconciliation
420
+ * re-derives due-now wakes from it, so the breaker's queue-row backoff
421
+ * and purge alone cannot contain a run whose attempt deterministically
422
+ * exhausts memory — a fresh isolate would resurrect it immediately. On a
423
+ * strike the run's claim is stripped and its deadline pushed to the
424
+ * backoff wake: the row keeps its state, so a struck `running` row still
425
+ * reads as an interrupted attempt (`step.interrupted`) when it is
426
+ * reclaimed, while reconciliation leaves the claimless row alone instead
427
+ * of flooring its deadline to now. When the breaker seals, the run
428
+ * terminally fails with an observable `task:failed` outcome.
429
+ */
430
+ onMemoryLimit(context: MemoryLimitContext): Promise<void>;
431
+ /**
432
+ * @internal Framework aperture: durably accept one run — reserved
433
+ * (`__cf`-prefixed) definition names included, which the public `run()`
434
+ * refuses so users cannot start framework runs — and drive its first
435
+ * attempt in the caller's invocation, resolving when that attempt reaches
436
+ * its next durable boundary. The receipt's run may already be terminal
437
+ * when this resolves; callers that need the outcome read it from their own
438
+ * channel (the run handler settles it) or from the snapshot.
439
+ */
440
+ __DO_NOT_USE_WILL_BREAK__runAttached(
441
+ definition: string,
442
+ input: unknown,
443
+ options?: TaskRunOptions
444
+ ): Promise<TaskReceipt>;
445
+ /**
446
+ * @internal Framework aperture: durably accept one run — reserved names
447
+ * included — and leave its first attempt to the durable queue wake instead
448
+ * of warm-starting it in the caller's invocation. Chat recovery uses this
449
+ * so a continuation always runs under an alarm, where `trackAlarmWork`
450
+ * keeps its model turn inside the memory-limit breaker domain.
451
+ */
452
+ __DO_NOT_USE_WILL_BREAK__enqueue(
453
+ definition: string,
454
+ input: unknown,
455
+ options?: TaskRunOptions
456
+ ): Promise<TaskReceipt>;
457
+ /** Handle Tasks protocol messages routed by another Lifecycle. */
458
+ onRoute(context: LifecycleRouteContext): Promise<unknown>;
459
+ /**
460
+ * @internal Framework aperture: bulk-cancel this root's routed wake
461
+ * mirrors for every run owned by a deleted facet subtree. The runs and
462
+ * their step journals live on the deleted facets' own storage and are
463
+ * wiped with them; only this root's mirror job needs an explicit cancel,
464
+ * or it stays due forever, retrying a dispatch to a facet that is gone.
465
+ */
466
+ __DO_NOT_USE_WILL_BREAK__cleanupRoutePrefix(prefix: string): Promise<void>;
467
+ /** Read one run by ID across all definitions. */
468
+ get(runId: string): Promise<TaskRunSnapshot<TaskValue> | null>;
469
+ /** Read one run by idempotency key across all definitions. */
470
+ getByIdempotencyKey(
471
+ idempotencyKey: string
472
+ ): Promise<TaskRunSnapshot<TaskValue> | null>;
473
+ /** List runs, newest first. */
474
+ list(options?: TaskListOptions): Promise<TaskRunSnapshot<TaskValue>[]>;
475
+ /**
476
+ * Request cooperative cancellation of one run.
477
+ *
478
+ * A live attempt is aborted and settles as cancelled at its next step
479
+ * boundary; a parked run settles immediately.
480
+ *
481
+ * @returns True when a non-terminal run accepted the request.
482
+ */
483
+ cancel(runId: string, reason?: string): Promise<boolean>;
484
+ /**
485
+ * Delete retained terminal runs and their step journals.
486
+ *
487
+ * @returns The number of runs deleted.
488
+ */
489
+ delete(options?: TaskDeleteOptions): Promise<number>;
490
+ }
491
+ //#endregion
492
+ export {
493
+ TaskDurationUnit as C,
494
+ TaskDurationString as S,
495
+ TaskStep as _,
496
+ TasksOptions as a,
497
+ TaskValue as b,
498
+ TaskError as c,
499
+ TaskJson as d,
500
+ TaskOutput as f,
501
+ TaskRunState as g,
502
+ TaskRunSnapshot as h,
503
+ TaskEventType as i,
504
+ TaskHandlers as l,
505
+ TaskRunOptions as m,
506
+ TaskListOptions as n,
507
+ Task as o,
508
+ TaskReceipt as p,
509
+ Tasks as r,
510
+ TaskCallbacks as s,
511
+ TaskDeleteOptions as t,
512
+ TaskInput as u,
513
+ TaskStepAttempt as v,
514
+ TaskWaitReason as x,
515
+ TaskStepConfig as y
516
+ };
517
+ //# sourceMappingURL=tasks-BRJ5zgya.d.ts.map