zidane 5.10.0 → 5.10.2

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 (79) hide show
  1. package/dist/{agent-AnumGPWj.d.ts → agent-Bt123Fdy.d.ts} +103 -3
  2. package/dist/agent-Bt123Fdy.d.ts.map +1 -0
  3. package/dist/chat/pure.d.ts +3 -3
  4. package/dist/chat/pure.js +1 -1
  5. package/dist/chat.d.ts +6 -6
  6. package/dist/chat.js +3 -3
  7. package/dist/contexts/docker.d.ts +1 -1
  8. package/dist/{contexts-CbI8dRfI.js → contexts-GKAWYq07.js} +113 -7
  9. package/dist/contexts-GKAWYq07.js.map +1 -0
  10. package/dist/contexts.d.ts +3 -3
  11. package/dist/contexts.js +2 -2
  12. package/dist/eval.d.ts +1 -1
  13. package/dist/eval.js +3 -3
  14. package/dist/{headless-D0qfvzG9.js → headless-Cn6XXmr3.js} +4 -4
  15. package/dist/{headless-D0qfvzG9.js.map → headless-Cn6XXmr3.js.map} +1 -1
  16. package/dist/headless.d.ts +1 -1
  17. package/dist/headless.js +1 -1
  18. package/dist/{index-B65HjjKZ.d.ts → index-4pQUnr2W.d.ts} +2 -2
  19. package/dist/{index-B65HjjKZ.d.ts.map → index-4pQUnr2W.d.ts.map} +1 -1
  20. package/dist/{index-DsvHiyYU.d.ts → index-BodGKXBV.d.ts} +3 -3
  21. package/dist/{index-DsvHiyYU.d.ts.map → index-BodGKXBV.d.ts.map} +1 -1
  22. package/dist/{index-LX8KCBXU.d.ts → index-C7BvI1Hi.d.ts} +14 -4
  23. package/dist/index-C7BvI1Hi.d.ts.map +1 -0
  24. package/dist/index.d.ts +6 -6
  25. package/dist/index.js +7 -7
  26. package/dist/{login-DocBwMVo.js → login-DoGslmKC.js} +2 -2
  27. package/dist/{login-DocBwMVo.js.map → login-DoGslmKC.js.map} +1 -1
  28. package/dist/{mcp-DzuTfq-I.js → mcp-BdN9UjTO.js} +32 -7
  29. package/dist/mcp-BdN9UjTO.js.map +1 -0
  30. package/dist/mcp.d.ts +1 -1
  31. package/dist/mcp.js +1 -1
  32. package/dist/output/stream-json.d.ts +2 -2
  33. package/dist/output/stream-json.js +1 -1
  34. package/dist/output/terminal.d.ts +2 -2
  35. package/dist/{presets-CTNbWXWz.js → presets-DCrQmY3b.js} +3 -2
  36. package/dist/presets-DCrQmY3b.js.map +1 -0
  37. package/dist/presets.d.ts +2 -2
  38. package/dist/presets.js +1 -1
  39. package/dist/providers.d.ts +1 -1
  40. package/dist/restate.d.ts +192 -16
  41. package/dist/restate.d.ts.map +1 -1
  42. package/dist/restate.js +133 -5
  43. package/dist/restate.js.map +1 -1
  44. package/dist/session/sqlite.d.ts +1 -1
  45. package/dist/session.d.ts +1 -1
  46. package/dist/skills.d.ts +2 -2
  47. package/dist/{tool-formatters-5nr1eXPn.d.ts → tool-formatters-BuB31L-c.d.ts} +2 -2
  48. package/dist/{tool-formatters-5nr1eXPn.d.ts.map → tool-formatters-BuB31L-c.d.ts.map} +1 -1
  49. package/dist/tools/fetch-url.d.ts +1 -1
  50. package/dist/tools/web-search.d.ts +1 -1
  51. package/dist/{tools-ycHDeHBZ.js → tools-Bk9TqmCV.js} +225 -18
  52. package/dist/tools-Bk9TqmCV.js.map +1 -0
  53. package/dist/tools.d.ts +3 -3
  54. package/dist/tools.js +2 -2
  55. package/dist/{transcript-anchors-D6Sw-Gzk.js → transcript-anchors-Bkuspqgn.js} +5 -5
  56. package/dist/{transcript-anchors-D6Sw-Gzk.js.map → transcript-anchors-Bkuspqgn.js.map} +1 -1
  57. package/dist/{transcript-anchors-DezrH1sp.d.ts → transcript-anchors-DhVgKmEl.d.ts} +4 -4
  58. package/dist/{transcript-anchors-DezrH1sp.d.ts.map → transcript-anchors-DhVgKmEl.d.ts.map} +1 -1
  59. package/dist/tui.d.ts +3 -3
  60. package/dist/tui.js +7 -7
  61. package/dist/{turn-operations-C70p-7Nn.js → turn-operations-DLWN2J7f.js} +13 -1
  62. package/dist/{turn-operations-C70p-7Nn.js.map → turn-operations-DLWN2J7f.js.map} +1 -1
  63. package/dist/{turn-operations-CICEEhrU.d.ts → turn-operations-DYKtoVd9.d.ts} +3 -3
  64. package/dist/{turn-operations-CICEEhrU.d.ts.map → turn-operations-DYKtoVd9.d.ts.map} +1 -1
  65. package/dist/{types-CRf_uTpK.d.ts → types-BMwiYRIJ.d.ts} +100 -6
  66. package/dist/types-BMwiYRIJ.d.ts.map +1 -0
  67. package/dist/types-BiobHM1D.js.map +1 -1
  68. package/dist/types.d.ts +5 -5
  69. package/docs/RESTATE.md +79 -5
  70. package/docs/RUN_IN_BACKGROUND.md +10 -1
  71. package/docs/SKILL.md +11 -4
  72. package/package.json +1 -1
  73. package/dist/agent-AnumGPWj.d.ts.map +0 -1
  74. package/dist/contexts-CbI8dRfI.js.map +0 -1
  75. package/dist/index-LX8KCBXU.d.ts.map +0 -1
  76. package/dist/mcp-DzuTfq-I.js.map +0 -1
  77. package/dist/presets-CTNbWXWz.js.map +0 -1
  78. package/dist/tools-ycHDeHBZ.js.map +0 -1
  79. package/dist/types-CRf_uTpK.d.ts.map +0 -1
package/dist/restate.d.ts CHANGED
@@ -1,14 +1,6 @@
1
- import { Gt as AgentBehavior, Kt as AgentClock, L as SessionStore, b as ToolDef, bn as ToolBatchExecutor, pt as StreamOptions, ut as Provider } from "./agent-AnumGPWj.js";
1
+ import { Cn as ToolResultContent, Gt as AgentBehavior, Kt as AgentClock, L as SessionStore, b as ToolDef, bn as ToolBatchExecutor, pt as StreamOptions, ut as Provider, y as ToolContext } from "./agent-Bt123Fdy.js";
2
+ import { a as DetachedTasksCapability } from "./types-BMwiYRIJ.js";
2
3
 
3
- //#region src/restate/behavior.d.ts
4
- /**
5
- * Conservative behavior defaults for agents running inside Restate.
6
- *
7
- * The helper is opt-in and returns a plain AgentBehavior object, so callers can
8
- * spread or override it without changing non-Restate harness defaults.
9
- */
10
- declare function restateBehavior(overrides?: AgentBehavior): AgentBehavior;
11
- //#endregion
12
4
  //#region src/restate/types.d.ts
13
5
  /**
14
6
  * Minimal structural types mirroring the subset of `@restatedev/restate-sdk`
@@ -82,6 +74,19 @@ interface RestateContextLike {
82
74
  uuidv4: () => string;
83
75
  };
84
76
  awakeable: <T>() => RestateAwakeable<T>;
77
+ /**
78
+ * Durable timer — suspends the invocation for `millis` and survives
79
+ * process death (replay resumes the same timer). Mirrors the SDK's
80
+ * `Context.sleep(duration)`; we narrow the parameter to plain millis
81
+ * (the SDK also accepts a `Duration`, which a wider implementation
82
+ * signature satisfies structurally).
83
+ *
84
+ * What it's for in this adapter: durable timeouts. Racing
85
+ * `awakeable.promise` against `sleep(timeoutMs)` is the canonical
86
+ * "wait with a deadline" shape — see {@link awakeableWithTimeout},
87
+ * which packages exactly that race for `waitBackground`-style parks.
88
+ */
89
+ sleep: (millis: number) => Promise<void>;
85
90
  }
86
91
  /**
87
92
  * Structural subset of `restate.ObjectContext` — adds keyed K/V state
@@ -97,6 +102,114 @@ interface RestateObjectContextLike extends RestateContextLike {
97
102
  clear: (name: string) => void;
98
103
  }
99
104
  //#endregion
105
+ //#region src/restate/awakeable.d.ts
106
+ /**
107
+ * Structural subset of the SDK's `RestatePromise` static surface used by
108
+ * {@link awakeableWithTimeout} — mirrors `RestatePromiseAllLike` from
109
+ * `./parallel`. Pass `RestatePromise` from `@restatedev/restate-sdk` so
110
+ * the race goes through the journaled combinator; native `Promise.race`
111
+ * over two durable promises leaves the winner to the runtime's replay
112
+ * ordering instead of an explicit journal entry.
113
+ */
114
+ interface RestatePromiseRaceLike<TPromise extends Promise<unknown> = Promise<unknown>> {
115
+ race: (values: readonly TPromise[]) => Promise<unknown>;
116
+ }
117
+ interface AwakeableWithTimeoutOptions<TPromise extends Promise<unknown> = Promise<unknown>> {
118
+ /**
119
+ * Durable deadline in milliseconds. Unset / non-positive = no timeout
120
+ * (the returned awakeable is the plain `ctx.awakeable()` passthrough).
121
+ */
122
+ timeoutMs?: number;
123
+ /**
124
+ * Durable race combinator — pass `RestatePromise` from the SDK. When
125
+ * omitted, native `Promise.race` is used: correct at runtime and
126
+ * replay-safe for THIS pattern (both branches are journaled
127
+ * primitives), but the SDK combinator is the recommended belt-and-
128
+ * braces choice for deterministic replay.
129
+ */
130
+ promises?: RestatePromiseRaceLike<TPromise>;
131
+ }
132
+ /**
133
+ * Mint an awakeable that resolves with the resumer's payload, or `null`
134
+ * when `timeoutMs` elapses first. The id is journal-stable (send it
135
+ * out-of-band as usual); the timeout is a durable `ctx.sleep`, so a
136
+ * parked invocation suspends instead of holding a worker.
137
+ *
138
+ * Timeout surfaces as `null` — a resumer that resolves `undefined` is
139
+ * indistinguishable from a timeout, so resolve a concrete payload.
140
+ *
141
+ * ```ts
142
+ * // waitBackground for a durable host, in three lines:
143
+ * const { id, promise } = awakeableWithTimeout<TaskExitInfo>(ctx, { timeoutMs, promises: RestatePromise })
144
+ * await registerExitResumer(taskId, id) // runner → ctx.resolveAwakeable(id, info)
145
+ * return await promise // TaskExitInfo, or null on timeout
146
+ * ```
147
+ */
148
+ declare function awakeableWithTimeout<T, TPromise extends Promise<unknown> = Promise<unknown>>(ctx: RestateContextLike, options?: AwakeableWithTimeoutOptions<TPromise>): RestateAwakeable<T | null>;
149
+ //#endregion
150
+ //#region src/restate/awakeable-tool.d.ts
151
+ interface RestateAwakeableToolOptions<T = unknown> {
152
+ /** Canonical tool name (what the model calls). */
153
+ name: string;
154
+ /** Model-facing tool description. */
155
+ description: string;
156
+ /** JSON schema for the tool input. */
157
+ inputSchema: Record<string, unknown>;
158
+ /** The Restate context the awakeable + journal entries bind to. */
159
+ ctx: RestateContextLike;
160
+ /**
161
+ * Send the awakeable id (plus the call's input) out-of-band so a
162
+ * resumer can later call `ctx.resolveAwakeable(awakeableId, value)`.
163
+ * Runs inside `ctx.run` — fires exactly once across replays.
164
+ */
165
+ notify: (info: {
166
+ awakeableId: string;
167
+ input: Record<string, unknown>;
168
+ toolCtx: ToolContext;
169
+ }) => void | Promise<void>;
170
+ /**
171
+ * Map the resolved awakeable payload to the tool result. Default:
172
+ * strings pass through, everything else is JSON-stringified.
173
+ */
174
+ toResult?: (value: T, input: Record<string, unknown>) => string | ToolResultContent[];
175
+ /**
176
+ * `ctx.run` options for the notify entry. Defaults to
177
+ * `{ maxRetryAttempts: 1 }`, matching `restateTool`'s rationale.
178
+ */
179
+ runOptions?: RestateRunOptions;
180
+ /**
181
+ * Concurrency-safety flag passed through to the `ToolDef`. Defaults to
182
+ * `false` — a parked wait holding a scheduler slot should barrier.
183
+ */
184
+ isConcurrencySafe?: boolean;
185
+ }
186
+ /**
187
+ * Build a `ToolDef` that parks on a Restate awakeable until an external
188
+ * resumer resolves it. See the module doc for the replay contract.
189
+ *
190
+ * Do NOT additionally wrap the returned tool in `restateTool` — the
191
+ * journal discipline is already internal, and an outer `ctx.run` would
192
+ * illegally nest the suspension point inside a journaled closure.
193
+ */
194
+ declare function restateAwakeableTool<T = unknown>(options: RestateAwakeableToolOptions<T>): ToolDef;
195
+ //#endregion
196
+ //#region src/restate/behavior.d.ts
197
+ /**
198
+ * Conservative behavior defaults for agents running inside Restate.
199
+ *
200
+ * The helper is opt-in and returns a plain AgentBehavior object, so callers can
201
+ * spread or override it without changing non-Restate harness defaults.
202
+ *
203
+ * `disableBackgroundTasks: 'non-durable'` is capability-aware: background
204
+ * tasks stay enabled for execution contexts whose
205
+ * `capabilities.detachedTasks` is `'durable'` (tasks live on a remote
206
+ * runner and survive worker crashes) and are disabled for everything
207
+ * else (host-local processes don't survive process death). Hosts on
208
+ * plain `ProcessContext` see the same effective behavior as the old
209
+ * blanket `true`.
210
+ */
211
+ declare function restateBehavior(overrides?: AgentBehavior): AgentBehavior;
212
+ //#endregion
100
213
  //#region src/restate/clock.d.ts
101
214
  /**
102
215
  * Wrap a Restate context's `date.now()` + `rand.uuidv4()` into the
@@ -202,7 +315,50 @@ declare function restateProvider(inner: Provider, ctx: RestateContextLike, optio
202
315
  declare function restateSessionStore(ctx: RestateObjectContextLike): SessionStore;
203
316
  //#endregion
204
317
  //#region src/restate/tool.d.ts
205
- interface RestateToolOptions {
318
+ /**
319
+ * Opt-in two-phase journaling for long-running, re-attachable tools.
320
+ *
321
+ * The default `restateTool` wrapping journals only the COMPLETED result —
322
+ * a crash mid-execute re-runs the tool on replay, which is unacceptable
323
+ * for builds / migrations / deploys. `durableStart` splits the execution:
324
+ *
325
+ * 1. `start` runs inside its own `ctx.run` entry, journaled BEFORE the
326
+ * body — it kicks off the side effect and returns a re-attach token
327
+ * (a background task id, a job handle, an idempotency key).
328
+ * 2. `attach` runs inside the result entry with the journaled token —
329
+ * on replay it receives the SAME token and re-attaches to the
330
+ * already-running work instead of starting it again.
331
+ *
332
+ * The wrapped tool's own `execute` is bypassed; the start/attach pair IS
333
+ * the execution.
334
+ */
335
+ interface RestateDurableStart<Token = unknown> {
336
+ /** Kick off the side effect; journaled before `attach`. Must be cheap + idempotent-safe up to journal persistence. */
337
+ start: (input: Record<string, unknown>, toolCtx: ToolContext) => Promise<Token> | Token;
338
+ /** Await / re-attach to the work identified by `token` and produce the tool result. */
339
+ attach: (token: Token, input: Record<string, unknown>, toolCtx: ToolContext) => Promise<string | ToolResultContent[]>;
340
+ /**
341
+ * Best-effort cleanup when the per-call abort signal fires before
342
+ * `attach` settles (run abort, `agent.cancelTool`, sibling-cascade
343
+ * cancel, `agent.destroy()` mid-run). Without it, the journaled token
344
+ * identifies a remote job that keeps running with nobody attached —
345
+ * a leak for hosts whose jobs outlive the session.
346
+ *
347
+ * Contract:
348
+ * - Fires at most once per call, outside the journal (an aborting
349
+ * invocation can't open new `ctx.run` entries reliably) — journal
350
+ * your own cleanup on the host side if it must be durable.
351
+ * - May run concurrently with a still-unwinding `attach`; make it
352
+ * idempotent against "job already gone".
353
+ * - NOT called on process death — that's not termination: the
354
+ * journaled token re-attaches on replay instead. This seam is for
355
+ * deliberate aborts, where no replay is coming.
356
+ * - Errors are swallowed (surfaced under `ZIDANE_DEBUG`) — cleanup
357
+ * failure must not mask the abort itself.
358
+ */
359
+ onAbort?: (token: Token, input: Record<string, unknown>, toolCtx: ToolContext) => Promise<void> | void;
360
+ }
361
+ interface RestateToolOptions<Token = unknown> {
206
362
  /**
207
363
  * `ctx.run` options forwarded on every wrapped tool call. Defaults to
208
364
  * `{ maxRetryAttempts: 1 }` — tool errors are typically deterministic
@@ -221,16 +377,36 @@ interface RestateToolOptions {
221
377
  */
222
378
  entryName?: (seq: number, name: string, input: Record<string, unknown>) => string;
223
379
  /**
224
- * Hide and reject the built-in shell tool's background mode. Defaults to
225
- * `true` because Restate cannot recover host-local background processes.
380
+ * Hide and reject the built-in shell tool's background mode.
381
+ *
382
+ * Default: derived from {@link RestateToolOptions.detachedTasks} —
383
+ * disabled unless the execution context declares `'durable'` detached
384
+ * tasks. An explicit boolean always wins.
226
385
  */
227
386
  disableShellBackground?: boolean;
387
+ /**
388
+ * `detachedTasks` capability of the execution context the agent will
389
+ * run with (see `ContextCapabilities.detachedTasks` /
390
+ * `resolveDetachedTasksCapability`). Drives the
391
+ * `disableShellBackground` default: a `'durable'` context keeps its
392
+ * background tasks across worker crashes, so the wrapper leaves the
393
+ * shell tool's background mode intact.
394
+ *
395
+ * Default: `undefined`, treated as non-durable (background disabled).
396
+ */
397
+ detachedTasks?: DetachedTasksCapability;
398
+ /**
399
+ * Two-phase start/attach journaling for crash-safe long tools — see
400
+ * {@link RestateDurableStart}. Per-tool by nature; not accepted by
401
+ * `wrapAgentTools` (a single start/attach pair can't fit a whole map).
402
+ */
403
+ durableStart?: RestateDurableStart<Token>;
228
404
  }
229
405
  /**
230
406
  * Wrap a single `ToolDef` so its `execute` runs inside `ctx.run`. The
231
407
  * tool's `spec` and `isConcurrencySafe` pass through unchanged.
232
408
  */
233
- declare function restateTool(inner: ToolDef, ctx: RestateContextLike, options?: RestateToolOptions): ToolDef;
409
+ declare function restateTool<Token = unknown>(inner: ToolDef, ctx: RestateContextLike, options?: RestateToolOptions<Token>): ToolDef;
234
410
  /**
235
411
  * Wrap an entire tool map at once — convenience for the common case of
236
412
  * "journal every tool the agent has". Pass-through for tools whose
@@ -239,9 +415,9 @@ declare function restateTool(inner: ToolDef, ctx: RestateContextLike, options?:
239
415
  *
240
416
  * The returned map is a fresh object; the input is untouched.
241
417
  */
242
- declare function wrapAgentTools(tools: Record<string, ToolDef>, ctx: RestateContextLike, opts?: RestateToolOptions & {
418
+ declare function wrapAgentTools(tools: Record<string, ToolDef>, ctx: RestateContextLike, opts?: Omit<RestateToolOptions, 'durableStart'> & {
243
419
  exclude?: readonly string[];
244
420
  }): Record<string, ToolDef>;
245
421
  //#endregion
246
- export { type RestateAwakeable, type RestateContextLike, type RestateObjectContextLike, type RestatePromiseAllLike, type RestatePromiseLike, type RestateProviderOptions, type RestateRunOptions, type RestateToolBatchExecutorOptions, type RestateToolOptions, restateBehavior, restateClock, restateProvider, restateSessionStore, restateTool, restateToolBatchExecutor, shouldRethrowRestateControlError, wrapAgentTools };
422
+ export { type AwakeableWithTimeoutOptions, type RestateAwakeable, type RestateAwakeableToolOptions, type RestateContextLike, type RestateDurableStart, type RestateObjectContextLike, type RestatePromiseAllLike, type RestatePromiseLike, type RestatePromiseRaceLike, type RestateProviderOptions, type RestateRunOptions, type RestateToolBatchExecutorOptions, type RestateToolOptions, awakeableWithTimeout, restateAwakeableTool, restateBehavior, restateClock, restateProvider, restateSessionStore, restateTool, restateToolBatchExecutor, shouldRethrowRestateControlError, wrapAgentTools };
247
423
  //# sourceMappingURL=restate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"restate.d.ts","names":[],"sources":["../src/restate/behavior.ts","../src/restate/types.ts","../src/restate/clock.ts","../src/restate/errors.ts","../src/restate/parallel.ts","../src/restate/provider.ts","../src/restate/session.ts","../src/restate/tool.ts"],"mappings":";;;;;AASA;;;;iBAAgB,eAAA,CAAgB,SAAA,GAAW,aAAA,GAAqB,aAAa;;;;;;AAA7E;;;;;;;;AAA6E;;;;ACU7E;;;UAAiB,iBAAA;EAEf;EAAA,gBAAA;EAIA;EAFA,gBA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AAA,IACxC,iBAAA;;;UCHc,sBAAA;EJMf;;AAAK;AAUP;;;;;;;;;;AAEoB;AAuBpB;;;;;;;EInBE,UAAA,GAAa,iBAAA;EJwBR;;;;;;;EIhBL,SAAA,IAAa,GAAA,UAAa,IAAA,EAAM,aAAa;EJa3C;;;;;;;EILF,eAAA;AAAA;;;;;;;iBASc,eAAA,CACd,KAAA,EAAO,QAAA,EACP,GAAA,EAAK,kBAAA,EACL,OAAA,GAAS,sBAAA,GACR,QAAA;;;;;;;;;;;iBChBa,mBAAA,CAAoB,GAAA,EAAK,wBAAA,GAA2B,YAAY;;;UC/B/D,kBAAA;ENEV;AAUP;;;;;;EMJE,UAAA,GAAa,iBAAA;ENMJ;;;AAAS;AAuBpB;;;;EMpBE,SAAA,IAAa,GAAA,UAAa,IAAA,UAAc,KAAA,EAAO,MAAM;ENuB5B;;;;EMlBzB,sBAAA;AAAA;;;;;iBAUc,WAAA,CACd,KAAA,EAAO,OAAA,EACP,GAAA,EAAK,kBAAA,EACL,OAAA,GAAS,kBAAA,GACR,OAAA;;;;;;;;;iBA2Fa,cAAA,CACd,KAAA,EAAO,MAAA,SAAe,OAAA,GACtB,GAAA,EAAK,kBAAA,EACL,IAAA,GAAM,kBAAA;EAAuB,OAAA;AAAA,IAC5B,MAAA,SAAe,OAAA"}
1
+ {"version":3,"file":"restate.d.ts","names":[],"sources":["../src/restate/types.ts","../src/restate/awakeable.ts","../src/restate/awakeable-tool.ts","../src/restate/behavior.ts","../src/restate/clock.ts","../src/restate/errors.ts","../src/restate/parallel.ts","../src/restate/provider.ts","../src/restate/session.ts","../src/restate/tool.ts"],"mappings":";;;;;;;;AAmBA;;;;;;;;;;;AAYO;AAUP;;UAtBiB,iBAAA;EAwBC;EAtBhB,gBAAA;EAqBA;EAnBA,gBAAA;EAoBS;EAlBT,oBAAA;EAkBkB;EAhBlB,gBAAA;EAuCe;EArCf,mBAAA;EAqCiC;EAnCjC,KAAA;AAAA;;;;;;;;UAUe,gBAAA;E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;;;;;;;;;;;iBChBa,mBAAA,CAAoB,GAAA,EAAK,wBAAA,GAA2B,YAAY;;;ARMhF;;;;;;;;;;;;;;;;;AAAA,USlBiB,mBAAA;ETqBH;ESnBZ,KAAA,GAAQ,KAAA,EAAO,MAAA,mBAAyB,OAAA,EAAS,WAAA,KAAgB,OAAA,CAAQ,KAAA,IAAS,KAAA;ETmBzD;ESjBzB,MAAA,GAAS,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,MAAA,mBAAyB,OAAA,EAAS,WAAA,KAAgB,OAAA,UAAiB,iBAAA;ETkBrF;;;;;;;;;;;;;;;;;AAiBsB;AAUpC;ESzBE,OAAA,IAAW,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,MAAA,mBAAyB,OAAA,EAAS,WAAA,KAAgB,OAAA;AAAA;AAAA,UAGnE,kBAAA;ETwBW;;;;;;;EShB1B,UAAA,GAAa,iBAAA;ETgBP;;;;;;;;ESPN,SAAA,IAAa,GAAA,UAAa,IAAA,UAAc,KAAA,EAAO,MAAA;ETS/C;;;AAAoB;;;;ESDpB,sBAAA;ER7EqC;;;;;;;;;;EQwFrC,aAAA,GAAgB,uBAAA;ERvFhB;;;;;EQ6FA,YAAA,GAAe,mBAAA,CAAoB,KAAA;AAAA;;;;;iBAUrB,WAAA,iBAAA,CACd,KAAA,EAAO,OAAA,EACP,GAAA,EAAK,kBAAA,EACL,OAAA,GAAS,kBAAA,CAAmB,KAAA,IAC3B,OAAA;;;;;;;;;iBAsKa,cAAA,CACd,KAAA,EAAO,MAAA,SAAe,OAAA,GACtB,GAAA,EAAK,kBAAA,EACL,IAAA,GAAM,IAAA,CAAK,kBAAA;EAAwC,OAAA;AAAA,IAClD,MAAA,SAAe,OAAA"}
package/dist/restate.js CHANGED
@@ -1,4 +1,77 @@
1
1
  import { i as hydrateReadStateFromSessionAsync } from "./read-state-CDVYj7q-.js";
2
+ //#region src/restate/awakeable.ts
3
+ /**
4
+ * Mint an awakeable that resolves with the resumer's payload, or `null`
5
+ * when `timeoutMs` elapses first. The id is journal-stable (send it
6
+ * out-of-band as usual); the timeout is a durable `ctx.sleep`, so a
7
+ * parked invocation suspends instead of holding a worker.
8
+ *
9
+ * Timeout surfaces as `null` — a resumer that resolves `undefined` is
10
+ * indistinguishable from a timeout, so resolve a concrete payload.
11
+ *
12
+ * ```ts
13
+ * // waitBackground for a durable host, in three lines:
14
+ * const { id, promise } = awakeableWithTimeout<TaskExitInfo>(ctx, { timeoutMs, promises: RestatePromise })
15
+ * await registerExitResumer(taskId, id) // runner → ctx.resolveAwakeable(id, info)
16
+ * return await promise // TaskExitInfo, or null on timeout
17
+ * ```
18
+ */
19
+ function awakeableWithTimeout(ctx, options = {}) {
20
+ const awakeable = ctx.awakeable();
21
+ const timeoutMs = options.timeoutMs;
22
+ if (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs <= 0) return awakeable;
23
+ const timer = ctx.sleep(timeoutMs);
24
+ const raced = options.promises ? options.promises.race([awakeable.promise, timer]) : Promise.race([awakeable.promise, timer]);
25
+ return {
26
+ id: awakeable.id,
27
+ promise: raced.then((value) => value === void 0 ? null : value)
28
+ };
29
+ }
30
+ //#endregion
31
+ //#region src/restate/awakeable-tool.ts
32
+ /**
33
+ * Build a `ToolDef` that parks on a Restate awakeable until an external
34
+ * resumer resolves it. See the module doc for the replay contract.
35
+ *
36
+ * Do NOT additionally wrap the returned tool in `restateTool` — the
37
+ * journal discipline is already internal, and an outer `ctx.run` would
38
+ * illegally nest the suspension point inside a journaled closure.
39
+ */
40
+ function restateAwakeableTool(options) {
41
+ const { name, description, inputSchema, ctx, notify, toResult } = options;
42
+ const runOpts = options.runOptions ?? { maxRetryAttempts: 1 };
43
+ let seq = 0;
44
+ const execute = async (input, toolCtx) => {
45
+ seq += 1;
46
+ const awakeable = ctx.awakeable();
47
+ const marker = await ctx.run(`awakeable-${name}-${seq}-notify`, async () => {
48
+ await notify({
49
+ awakeableId: awakeable.id,
50
+ input,
51
+ toolCtx
52
+ });
53
+ return {
54
+ notified: true,
55
+ awakeableId: awakeable.id
56
+ };
57
+ }, runOpts);
58
+ if (marker.awakeableId !== awakeable.id) throw new Error(`restateAwakeableTool(${name}): journal drift — broadcast marker carries awakeable "${marker.awakeableId}" but this replay minted "${awakeable.id}". The journal and the code path no longer line up; refusing to park on an unreachable awakeable.`);
59
+ const value = await awakeable.promise;
60
+ if (toResult) return toResult(value, input);
61
+ return typeof value === "string" ? value : JSON.stringify(value);
62
+ };
63
+ return {
64
+ spec: {
65
+ name,
66
+ description,
67
+ inputSchema
68
+ },
69
+ ...options.isConcurrencySafe !== void 0 ? { isConcurrencySafe: options.isConcurrencySafe } : {},
70
+ execute,
71
+ durableExecute: execute
72
+ };
73
+ }
74
+ //#endregion
2
75
  //#region src/restate/errors.ts
3
76
  /**
4
77
  * Restate control-flow errors must escape the agent loop. If they are turned
@@ -26,11 +99,19 @@ function shouldRethrowRestateControlError(error) {
26
99
  *
27
100
  * The helper is opt-in and returns a plain AgentBehavior object, so callers can
28
101
  * spread or override it without changing non-Restate harness defaults.
102
+ *
103
+ * `disableBackgroundTasks: 'non-durable'` is capability-aware: background
104
+ * tasks stay enabled for execution contexts whose
105
+ * `capabilities.detachedTasks` is `'durable'` (tasks live on a remote
106
+ * runner and survive worker crashes) and are disabled for everything
107
+ * else (host-local processes don't survive process death). Hosts on
108
+ * plain `ProcessContext` see the same effective behavior as the old
109
+ * blanket `true`.
29
110
  */
30
111
  function restateBehavior(overrides = {}) {
31
112
  return {
32
113
  maxConcurrentTools: 1,
33
- disableBackgroundTasks: true,
114
+ disableBackgroundTasks: "non-durable",
34
115
  cache: true,
35
116
  shouldRethrowToolError: shouldRethrowRestateControlError,
36
117
  ...overrides
@@ -188,7 +269,13 @@ function restateSessionStore(ctx) {
188
269
  },
189
270
  async save(session) {
190
271
  const { turns, runs, ...header } = session;
191
- ctx.set(KEY_DATA, header);
272
+ const prior = await ctx.get(KEY_DATA);
273
+ const now = await ctx.date.now();
274
+ ctx.set(KEY_DATA, {
275
+ ...header,
276
+ createdAt: prior?.createdAt ?? now,
277
+ updatedAt: now
278
+ });
192
279
  ctx.set(KEY_TURNS, sanitizeTurnsForState(turns));
193
280
  ctx.set(KEY_RUNS, sanitizeRunsForState(runs));
194
281
  },
@@ -297,7 +384,8 @@ function restateTool(inner, ctx, options = {}) {
297
384
  const runOpts = options.runOptions ?? { maxRetryAttempts: 1 };
298
385
  const nameFor = options.entryName ?? ((seq, name) => `tool-${name}-${seq}`);
299
386
  const canonicalName = inner.spec.name;
300
- const shellBackgroundDisabled = (options.disableShellBackground ?? true) && canonicalName === "shell";
387
+ const shellBackgroundDisabled = (options.disableShellBackground ?? options.detachedTasks !== "durable") && canonicalName === "shell";
388
+ const durableStart = options.durableStart;
301
389
  let seq = 0;
302
390
  const hydrateOnce = async (toolCtx) => {
303
391
  if (toolCtx.session && !HYDRATED_READ_STATE_SESSIONS.has(toolCtx.session)) {
@@ -322,6 +410,45 @@ function restateTool(inner, ctx, options = {}) {
322
410
  return inner.execute(input, toolCtx);
323
411
  }, runOpts);
324
412
  };
413
+ const executeTwoPhase = async (input, toolCtx) => {
414
+ const start = durableStart;
415
+ seq += 1;
416
+ const entry = nameFor(seq, canonicalName, input);
417
+ const token = await ctx.run(`${entry}-start`, async () => {
418
+ await hydrateOnce(toolCtx);
419
+ return start.start(input, toolCtx);
420
+ }, runOpts);
421
+ const attach = () => ctx.run(entry, () => start.attach(token, input, toolCtx), runOpts);
422
+ const onAbort = start.onAbort;
423
+ const signal = toolCtx.signal;
424
+ if (!onAbort || !signal) return attach();
425
+ let fired = false;
426
+ const fireAbortCleanup = () => {
427
+ if (fired) return;
428
+ fired = true;
429
+ Promise.resolve(onAbort(token, input, toolCtx)).catch((err) => {
430
+ if (process.env.ZIDANE_DEBUG) process.stderr.write(`[zidane/restate] durableStart onAbort threw: ${err instanceof Error ? err.message : String(err)}\n`);
431
+ });
432
+ };
433
+ if (signal.aborted) {
434
+ fireAbortCleanup();
435
+ return attach();
436
+ }
437
+ signal.addEventListener("abort", fireAbortCleanup, { once: true });
438
+ try {
439
+ return await attach();
440
+ } finally {
441
+ signal.removeEventListener("abort", fireAbortCleanup);
442
+ }
443
+ };
444
+ if (durableStart) {
445
+ const { durableExecute: _dropped, ...rest } = inner;
446
+ return {
447
+ ...rest,
448
+ spec: shellBackgroundDisabled ? withoutShellBackgroundInput(inner.spec) : inner.spec,
449
+ execute: executeTwoPhase
450
+ };
451
+ }
325
452
  return {
326
453
  ...inner,
327
454
  spec: shellBackgroundDisabled ? withoutShellBackgroundInput(inner.spec) : inner.spec,
@@ -361,11 +488,12 @@ function isRecord(value) {
361
488
  */
362
489
  function wrapAgentTools(tools, ctx, opts = {}) {
363
490
  const excludeSet = new Set(opts.exclude ?? []);
491
+ const skipWaitTask = opts.detachedTasks === "durable";
364
492
  const wrapped = {};
365
- for (const [name, def] of Object.entries(tools)) wrapped[name] = excludeSet.has(name) ? def : restateTool(def, ctx, opts);
493
+ for (const [name, def] of Object.entries(tools)) wrapped[name] = excludeSet.has(name) || skipWaitTask && def.spec.name === "wait_task" ? def : restateTool(def, ctx, opts);
366
494
  return wrapped;
367
495
  }
368
496
  //#endregion
369
- export { restateBehavior, restateClock, restateProvider, restateSessionStore, restateTool, restateToolBatchExecutor, shouldRethrowRestateControlError, wrapAgentTools };
497
+ export { awakeableWithTimeout, restateAwakeableTool, restateBehavior, restateClock, restateProvider, restateSessionStore, restateTool, restateToolBatchExecutor, shouldRethrowRestateControlError, wrapAgentTools };
370
498
 
371
499
  //# sourceMappingURL=restate.js.map