zidane 6.4.3 → 6.5.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 (104) hide show
  1. package/README.md +1 -0
  2. package/dist/{acp-Kr7LyExq.js → acp-B-AOovHz.js} +3 -3
  3. package/dist/{acp-Kr7LyExq.js.map → acp-B-AOovHz.js.map} +1 -1
  4. package/dist/acp-cli.js +3 -2
  5. package/dist/acp-cli.js.map +1 -1
  6. package/dist/acp.d.ts +1 -1
  7. package/dist/acp.js +1 -1
  8. package/dist/{agent-CEvzc1Ao.js → agent-SQ6rxfpT.js} +298 -110
  9. package/dist/agent-SQ6rxfpT.js.map +1 -0
  10. package/dist/agent.d.ts +1 -1
  11. package/dist/agent.js +2 -2
  12. package/dist/chat/pure.d.ts +3 -3
  13. package/dist/chat.d.ts +13 -44
  14. package/dist/chat.d.ts.map +1 -1
  15. package/dist/chat.js +5 -4
  16. package/dist/chat.js.map +1 -1
  17. package/dist/{context-transport-DbzJctSl.js → context-transport-CDBatvQc.js} +3 -3
  18. package/dist/{context-transport-DbzJctSl.js.map → context-transport-CDBatvQc.js.map} +1 -1
  19. package/dist/contexts/daytona.d.ts +1 -1
  20. package/dist/contexts/e2b.d.ts +1 -1
  21. package/dist/eval.d.ts +1 -1
  22. package/dist/extensions.d.ts +2 -2
  23. package/dist/extensions.js +2 -2
  24. package/dist/headless.d.ts +1 -1
  25. package/dist/headless.js +1 -1
  26. package/dist/{index-W_8010Lt.d.ts → index-CWBSrqI6.d.ts} +931 -3
  27. package/dist/index-CWBSrqI6.d.ts.map +1 -0
  28. package/dist/index.d.ts +2 -2
  29. package/dist/index.js +8 -7
  30. package/dist/index.js.map +1 -1
  31. package/dist/{login-Blkiy-58.js → login-XZDS4K2o.js} +3 -3
  32. package/dist/{login-Blkiy-58.js.map → login-XZDS4K2o.js.map} +1 -1
  33. package/dist/{mcp-CDN-m5lp.js → mcp-D27rP47I.js} +87 -6
  34. package/dist/mcp-D27rP47I.js.map +1 -0
  35. package/dist/mcp.d.ts +2 -2
  36. package/dist/mcp.js +3 -2
  37. package/dist/origin-pinned-fetch-CqG8VZIq.js +159 -0
  38. package/dist/origin-pinned-fetch-CqG8VZIq.js.map +1 -0
  39. package/dist/output/stream-json.d.ts +1 -1
  40. package/dist/output/terminal.d.ts +1 -1
  41. package/dist/plugins-2PMTVcp-.js +1174 -0
  42. package/dist/plugins-2PMTVcp-.js.map +1 -0
  43. package/dist/plugins.d.ts +2 -0
  44. package/dist/plugins.js +2 -0
  45. package/dist/presets.d.ts +1 -1
  46. package/dist/presets.js +1 -1
  47. package/dist/providers/anthropic.d.ts +1 -1
  48. package/dist/providers/arcee.d.ts +1 -1
  49. package/dist/providers/baseten.d.ts +1 -1
  50. package/dist/providers/cerebras.d.ts +1 -1
  51. package/dist/providers/local.d.ts +1 -1
  52. package/dist/providers/openai-compat.d.ts +1 -1
  53. package/dist/providers/openai.d.ts +1 -1
  54. package/dist/providers/openrouter.d.ts +1 -1
  55. package/dist/providers/xai.d.ts +1 -1
  56. package/dist/providers.d.ts +1 -1
  57. package/dist/restate.d.ts +52 -2
  58. package/dist/restate.d.ts.map +1 -1
  59. package/dist/restate.js +156 -36
  60. package/dist/restate.js.map +1 -1
  61. package/dist/session/sqlite.d.ts +1 -1
  62. package/dist/session.d.ts +1 -1
  63. package/dist/{resolve-CZJxds85.js → skills-Cp9vnBwd.js} +1430 -1006
  64. package/dist/skills-Cp9vnBwd.js.map +1 -0
  65. package/dist/skills.d.ts +1 -1
  66. package/dist/skills.js +1 -2
  67. package/dist/{stdio-DWQKYKad.js → stdio-O-m9WVkE.js} +2 -2
  68. package/dist/{stdio-DWQKYKad.js.map → stdio-O-m9WVkE.js.map} +1 -1
  69. package/dist/{stdio-loader-3uz37d_3.js → stdio-loader-BSGQmG4L.js} +2 -2
  70. package/dist/{stdio-loader-3uz37d_3.js.map → stdio-loader-BSGQmG4L.js.map} +1 -1
  71. package/dist/{tool-formatters-bhC2Xp8z.d.ts → tool-formatters-gFqQbzPY.d.ts} +2 -2
  72. package/dist/{tool-formatters-bhC2Xp8z.d.ts.map → tool-formatters-gFqQbzPY.d.ts.map} +1 -1
  73. package/dist/{read-state-Dt7UbVsd.js → tool-state-DTs-3ZHH.js} +218 -2
  74. package/dist/tool-state-DTs-3ZHH.js.map +1 -0
  75. package/dist/tools/fetch-url.d.ts +1 -1
  76. package/dist/tools/web-search.d.ts +1 -1
  77. package/dist/tools.d.ts +1 -1
  78. package/dist/tools.js +2 -2
  79. package/dist/{transcript-anchors-D7wVCZ2S.js → transcript-anchors-D4IxJifV.js} +42 -5
  80. package/dist/transcript-anchors-D4IxJifV.js.map +1 -0
  81. package/dist/{transcript-anchors-mcMLuXM1.d.ts → transcript-anchors-qCs3wZpu.d.ts} +98 -92
  82. package/dist/transcript-anchors-qCs3wZpu.d.ts.map +1 -0
  83. package/dist/tui.d.ts +38 -4
  84. package/dist/tui.d.ts.map +1 -1
  85. package/dist/tui.js +893 -148
  86. package/dist/tui.js.map +1 -1
  87. package/dist/{turn-operations-B5vVcG0Z.d.ts → turn-operations-M9-jUyDd.d.ts} +3 -3
  88. package/dist/{turn-operations-B5vVcG0Z.d.ts.map → turn-operations-M9-jUyDd.d.ts.map} +1 -1
  89. package/dist/types-BIarq1qE.js.map +1 -1
  90. package/dist/types.d.ts +2 -2
  91. package/docs/ARCHITECTURE.md +2 -0
  92. package/docs/PLUGINS.md +340 -0
  93. package/docs/RESTATE.md +133 -3
  94. package/docs/SKILL.md +24 -8
  95. package/package.json +6 -1
  96. package/dist/agent-CEvzc1Ao.js.map +0 -1
  97. package/dist/index-W_8010Lt.d.ts.map +0 -1
  98. package/dist/mcp-CDN-m5lp.js.map +0 -1
  99. package/dist/read-state-Dt7UbVsd.js.map +0 -1
  100. package/dist/resolve-CZJxds85.js.map +0 -1
  101. package/dist/skills-Dd6XCi4s.js +0 -420
  102. package/dist/skills-Dd6XCi4s.js.map +0 -1
  103. package/dist/transcript-anchors-D7wVCZ2S.js.map +0 -1
  104. package/dist/transcript-anchors-mcMLuXM1.d.ts.map +0 -1
package/dist/restate.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { n as buildAliasMaps } from "./aliasing-lVFbm81n.js";
2
2
  import { r as coerceToolResultContent } from "./types-BIarq1qE.js";
3
- import { a as hydrateReadStateFromSessionAsync } from "./read-state-Dt7UbVsd.js";
3
+ import { i as stagedToolState, l as hydrateReadStateFromSessionAsync, r as isToolStateOps } from "./tool-state-DTs-3ZHH.js";
4
4
  import { createHash } from "node:crypto";
5
5
  //#region src/restate/awakeable.ts
6
6
  /**
@@ -182,7 +182,8 @@ function restateClock(ctx, options = {}) {
182
182
  const randomUUID = () => deterministicUuid(`${idSeed}:uuid:${idSeq++}`);
183
183
  if (!coalesce) return {
184
184
  now: () => ctx.date.now(),
185
- randomUUID
185
+ randomUUID,
186
+ journaled: true
186
187
  };
187
188
  const requested = typeof coalesce === "object" ? coalesce.reanchorEvery : void 0;
188
189
  const reanchorEvery = typeof requested === "number" && Number.isFinite(requested) && requested >= 1 ? Math.floor(requested) : DEFAULT_REANCHOR_EVERY;
@@ -201,7 +202,8 @@ function restateClock(ctx, options = {}) {
201
202
  lastReturned = value;
202
203
  return value;
203
204
  },
204
- randomUUID
205
+ randomUUID,
206
+ journaled: true
205
207
  };
206
208
  }
207
209
  //#endregion
@@ -318,26 +320,52 @@ function restateTool(inner, ctx, options = {}) {
318
320
  return ctx.run(nameFor(seq, canonicalName, input, toolCtx.callId), async () => {
319
321
  options.replayTracker?.markLive();
320
322
  await hydrateOnce(toolCtx);
323
+ const staged = stagedToolState(toolCtx.state);
324
+ staged?.clear();
321
325
  if (shellBackgroundDisabled && input.run_in_background === true) return SHELL_BACKGROUND_DISABLED_MESSAGE;
322
326
  if (!softErrors) {
323
327
  const out = await inner.execute(input, toolCtx);
324
- return coerceBlocks ? coerceToolResultContent(out) : out;
328
+ return attachToolState(coerceBlocks ? coerceToolResultContent(out) : out, staged);
325
329
  }
326
330
  try {
327
331
  const out = await inner.execute(input, toolCtx);
328
- return coerceBlocks ? coerceToolResultContent(out) : out;
332
+ return attachToolState(coerceBlocks ? coerceToolResultContent(out) : out, staged);
329
333
  } catch (err) {
330
334
  if (isRestateControlOrAbort(err, toolCtx.signal)) throw err;
331
- return makeSoftToolError(err);
335
+ return attachToolState(makeSoftToolError(err), staged);
332
336
  }
333
337
  }, runOpts);
334
338
  };
335
- const executeDurably = softErrors ? async (input, toolCtx) => rethrowSoftToolError(await runJournaled(input, toolCtx)) : runJournaled;
336
- const durableExecuteImpl = softErrors ? (input, toolCtx) => unwrapDurableSoftError(runJournaled(input, toolCtx)) : runJournaled;
337
- const executeTwoPhase = async (input, toolCtx) => {
339
+ const finishJournaled = async (journaled, staged) => {
340
+ let value;
341
+ try {
342
+ value = await journaled;
343
+ } catch (err) {
344
+ staged?.clear();
345
+ throw err;
346
+ }
347
+ const output = applyToolState(value, staged);
348
+ return softErrors ? rethrowSoftToolError(output) : output;
349
+ };
350
+ const executeDurably = (input, toolCtx) => {
351
+ const staged = stagedToolState(toolCtx.state);
352
+ if (!softErrors && !staged) return runJournaled(input, toolCtx);
353
+ return finishJournaled(runJournaled(input, toolCtx), staged);
354
+ };
355
+ const durableExecuteImpl = (input, toolCtx) => {
356
+ const staged = stagedToolState(toolCtx.state);
357
+ if (!softErrors && !staged) return runJournaled(input, toolCtx);
358
+ return unwrapDurableToolValue(runJournaled(input, toolCtx), staged, softErrors);
359
+ };
360
+ const executeTwoPhaseInner = async (input, toolCtx) => {
338
361
  const start = durableStart;
362
+ const staged = stagedToolState(toolCtx.state);
339
363
  seq += 1;
340
364
  const entry = nameFor(seq, canonicalName, input, toolCtx.callId);
365
+ const runFinal = async (body) => applyToolState(await ctx.run(entry, async () => {
366
+ options.replayTracker?.markLive();
367
+ return attachToolState(await body(), staged);
368
+ }, runOpts), staged);
341
369
  const token = await ctx.run(`${entry}-start`, async () => {
342
370
  options.replayTracker?.markLive();
343
371
  await hydrateOnce(toolCtx);
@@ -356,17 +384,11 @@ function restateTool(inner, ctx, options = {}) {
356
384
  const wait = start.wait;
357
385
  if (wait) {
358
386
  if (wait.inline?.(token, input, toolCtx)) {
359
- if (!onAbort || !signal) return await ctx.run(entry, () => {
360
- options.replayTracker?.markLive();
361
- return wait.result(token, null, input, toolCtx);
362
- }, runOpts);
387
+ if (!onAbort || !signal) return await runFinal(() => wait.result(token, null, input, toolCtx));
363
388
  if (signal.aborted) fireAbortCleanup();
364
389
  else signal.addEventListener("abort", fireAbortCleanup, { once: true });
365
390
  try {
366
- return await ctx.run(entry, () => {
367
- options.replayTracker?.markLive();
368
- return wait.result(token, null, input, toolCtx);
369
- }, runOpts);
391
+ return await runFinal(() => wait.result(token, null, input, toolCtx));
370
392
  } finally {
371
393
  signal.removeEventListener("abort", fireAbortCleanup);
372
394
  }
@@ -392,18 +414,12 @@ function restateTool(inner, ctx, options = {}) {
392
414
  }, runOpts);
393
415
  if (marker.awakeableId !== awakeable.id) throw new Error(`restateTool(${canonicalName}): journal drift — registration marker carries awakeable "${marker.awakeableId}" but this replay minted "${awakeable.id}". Refusing to park on an unreachable awakeable.`);
394
416
  const resumed = await parkWithSignal(awakeable.promise, signal, canonicalName);
395
- return await ctx.run(entry, () => {
396
- options.replayTracker?.markLive();
397
- return wait.result(token, resumed, input, toolCtx);
398
- }, runOpts);
417
+ return await runFinal(() => wait.result(token, resumed, input, toolCtx));
399
418
  } finally {
400
419
  signal?.removeEventListener("abort", fireAbortCleanup);
401
420
  }
402
421
  }
403
- const attach = () => ctx.run(entry, () => {
404
- options.replayTracker?.markLive();
405
- return start.attach(token, input, toolCtx);
406
- }, runOpts);
422
+ const attach = () => runFinal(() => start.attach(token, input, toolCtx));
407
423
  if (!onAbort || !signal) return attach();
408
424
  if (signal.aborted) {
409
425
  fireAbortCleanup();
@@ -416,6 +432,15 @@ function restateTool(inner, ctx, options = {}) {
416
432
  signal.removeEventListener("abort", fireAbortCleanup);
417
433
  }
418
434
  };
435
+ const executeTwoPhase = async (input, toolCtx) => {
436
+ const staged = stagedToolState(toolCtx.state);
437
+ try {
438
+ return await executeTwoPhaseInner(input, toolCtx);
439
+ } catch (err) {
440
+ staged?.clear();
441
+ throw err;
442
+ }
443
+ };
419
444
  if (durableStart) {
420
445
  const { durableExecute: _dropped, ...rest } = inner;
421
446
  return {
@@ -431,20 +456,59 @@ function restateTool(inner, ctx, options = {}) {
431
456
  durableExecute: durableExecuteImpl
432
457
  };
433
458
  }
459
+ function isToolStateEnvelope(value) {
460
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
461
+ const candidate = value;
462
+ return candidate.__zidaneToolState === 1 && Array.isArray(candidate.ops) && "output" in candidate;
463
+ }
464
+ /**
465
+ * Wrap the output with the staged ops so they cross the journal as DATA.
466
+ * Returns the output untouched when nothing was staged — the no-state path
467
+ * must not change the journaled shape.
468
+ */
469
+ function attachToolState(output, staged) {
470
+ const ops = staged?.pending() ?? [];
471
+ return ops.length === 0 ? output : {
472
+ __zidaneToolState: 1,
473
+ ops,
474
+ output
475
+ };
476
+ }
434
477
  /**
435
- * Compose the soft-error unwrap into the runtime's mappable durable promise.
436
- * A journaled sentinel becomes a thrown (rejected) value so the Restate batch
437
- * scheduler classifies it as a tool failure → `tool_result { isError }`; a real
438
- * action failure (control error) is rethrown verbatim. Non-mappable promises
439
- * (a ctx without the SDK's `RestatePromise`) pass through so the loop's durable
440
- * guard surfaces the "not a mappable durable promise" error instead.
478
+ * Inverse of {@link attachToolState}, run OUTSIDE the journal: re-seed the
479
+ * staging view from the journaled ops so the loop's commit writes the same
480
+ * thing on a live attempt and on every replay. A value with no envelope
481
+ * clears the view — whatever it holds was staged by an attempt no journal
482
+ * entry records, and committing that would be a write replay can't reproduce.
441
483
  */
442
- function unwrapDurableSoftError(promise) {
484
+ function applyToolState(value, staged) {
485
+ if (isToolStateEnvelope(value)) {
486
+ if (isToolStateOps(value.ops)) staged?.restore(value.ops);
487
+ else staged?.clear();
488
+ return value.output;
489
+ }
490
+ staged?.clear();
491
+ return value;
492
+ }
493
+ /**
494
+ * Compose the state unwrap + soft-error unwrap into the runtime's mappable
495
+ * durable promise. A journaled sentinel becomes a thrown (rejected) value so
496
+ * the Restate batch scheduler classifies it as a tool failure →
497
+ * `tool_result { isError }`; a real action failure (control error) is rethrown
498
+ * verbatim. Non-mappable promises (a ctx without the SDK's `RestatePromise`)
499
+ * pass through so the loop's durable guard surfaces the "not a mappable
500
+ * durable promise" error instead.
501
+ */
502
+ function unwrapDurableToolValue(promise, staged, softErrors) {
443
503
  const mappable = promise;
444
504
  if (typeof mappable.map !== "function") return promise;
445
505
  return mappable.map((value, failure) => {
446
- if (failure !== void 0) throw failure instanceof Error ? failure : new Error(String(failure));
447
- return rethrowSoftToolError(value);
506
+ if (failure !== void 0) {
507
+ staged?.clear();
508
+ throw failure instanceof Error ? failure : new Error(String(failure));
509
+ }
510
+ const output = applyToolState(value, staged);
511
+ return softErrors ? rethrowSoftToolError(output) : output;
448
512
  });
449
513
  }
450
514
  /**
@@ -505,7 +569,7 @@ function wrapAgentTools(tools, ctx, opts = {}) {
505
569
  const excludeSet = new Set(opts.exclude ?? []);
506
570
  const skipWaitTask = opts.detachedTasks === "durable";
507
571
  const wrapped = {};
508
- for (const [name, def] of Object.entries(tools)) wrapped[name] = excludeSet.has(name) || skipWaitTask && def.spec.name === "wait_task" ? def : restateTool(def, ctx, opts);
572
+ for (const [name, def] of Object.entries(tools)) wrapped[name] = excludeSet.has(name) || def.runsNestedAgent === true || skipWaitTask && def.spec.name === "wait_task" ? def : restateTool(def, ctx, opts);
509
573
  return wrapped;
510
574
  }
511
575
  //#endregion
@@ -903,6 +967,62 @@ function maxDefined(values) {
903
967
  return max;
904
968
  }
905
969
  //#endregion
970
+ //#region src/restate/tool-state.ts
971
+ /** Default virtual-object state key holding the tool-state map. */
972
+ const DEFAULT_TOOL_STATE_KEY = "zidane_tool_state";
973
+ /**
974
+ * Build a {@link ToolStateStore} over the bound virtual object's state.
975
+ *
976
+ * ```ts
977
+ * const agent = createAgent({
978
+ * provider,
979
+ * tools: wrapAgentTools({ shell }, ctx),
980
+ * session: createSession({ id: ctx.key, store: restateSessionStore(ctx) }),
981
+ * toolState: restateToolStateStore(ctx),
982
+ * })
983
+ * ```
984
+ *
985
+ * Single-writer like the session store: the state belongs to the object key,
986
+ * so bind one key per conversation and one agent per invocation.
987
+ *
988
+ * Build it INSIDE the handler. The returned store closes over this `ctx`, so
989
+ * an agent constructed once at module scope and reused across invocations
990
+ * would commit through a context that is already finished, and would never
991
+ * re-hydrate (the controller memoizes the load for the life of the agent).
992
+ * Same rule as `restateSessionStore` / `restateProvider` / `restateClock` —
993
+ * but easier to get wrong here, because `toolState` looks like
994
+ * agent-lifetime configuration rather than a per-invocation binding.
995
+ *
996
+ * The map is a schema you own: one JSON object, no versioning, no migration.
997
+ * A value written by an earlier deploy is still there after you change its
998
+ * shape, so either read tolerantly or move to a fresh `key`.
999
+ *
1000
+ * Enabling this adds a `ctx.get` at run start, which changes the journal
1001
+ * shape for NEW invocations. Existing in-flight invocations replay against
1002
+ * the old shape — drain them (or accept the failed attempts) before rolling
1003
+ * it out.
1004
+ */
1005
+ function restateToolStateStore(ctx, options = {}) {
1006
+ const key = options.key ?? "zidane_tool_state";
1007
+ const maxValueBytes = options.maxValueBytes;
1008
+ let cache;
1009
+ return {
1010
+ ...maxValueBytes !== void 0 ? { maxValueBytes } : {},
1011
+ load: async () => {
1012
+ cache = await ctx.get(key) ?? {};
1013
+ return { ...cache };
1014
+ },
1015
+ commit: (ops) => {
1016
+ if (ops.length === 0) return;
1017
+ const next = { ...cache ?? {} };
1018
+ for (const op of ops) if (op.delete === true) delete next[op.key];
1019
+ else next[op.key] = op.value;
1020
+ cache = next;
1021
+ ctx.set(key, next);
1022
+ }
1023
+ };
1024
+ }
1025
+ //#endregion
906
1026
  //#region src/restate/wait-background.ts
907
1027
  function entryToExit(entry) {
908
1028
  return {
@@ -981,6 +1101,6 @@ function restateWaitBackground(options) {
981
1101
  };
982
1102
  }
983
1103
  //#endregion
984
- export { awakeableWithTimeout, createReplayTracker, deterministicUuid, replayAwareAbort, restateAwakeableTool, restateBehavior, restateClock, restateMcpToolWrap, restateProvider, restateSessionStore, restateTool, restateToolBatchExecutor, restateWaitBackground, shouldRethrowRestateControlError, wrapAgentTools };
1104
+ export { DEFAULT_TOOL_STATE_KEY, awakeableWithTimeout, createReplayTracker, deterministicUuid, replayAwareAbort, restateAwakeableTool, restateBehavior, restateClock, restateMcpToolWrap, restateProvider, restateSessionStore, restateTool, restateToolBatchExecutor, restateToolStateStore, restateWaitBackground, shouldRethrowRestateControlError, wrapAgentTools };
985
1105
 
986
1106
  //# sourceMappingURL=restate.js.map