@dudko.dev/agent-web 0.0.41 → 0.0.43

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.
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  getOrCreateVaultKey,
12
12
  mcpAppOrigin,
13
13
  renderMcpInstructions
14
- } from "./chunk-4FBTBE74.js";
14
+ } from "./chunk-2MLHZ6LQ.js";
15
15
  import {
16
16
  AttachmentsNotSupportedError,
17
17
  ContextWindowExceededError,
@@ -95,7 +95,7 @@ import {
95
95
  toolRunContextOf,
96
96
  withDeadline,
97
97
  wrapToolsForRun
98
- } from "./chunk-L7Y3QRAM.js";
98
+ } from "./chunk-DAREMCXF.js";
99
99
  import {
100
100
  FILES_STORE,
101
101
  KEYS_STORE,
@@ -106,9 +106,13 @@ import {
106
106
  MCP_SKILL_CONSENTS,
107
107
  MCP_SKILL_CONSENT_DEFAULT,
108
108
  MCP_SKILL_DESCRIPTION_MAX_CHARS,
109
+ MCP_SKILL_DIRECTORY_ENTRIES_MAX,
109
110
  MCP_SKILL_FILE_MAX_CHARS,
110
111
  MCP_SKILL_MAX_RESOURCES,
111
112
  MCP_SKILL_MAX_TOTAL_BYTES,
113
+ MCP_SKILL_SNAPSHOTS_MAX_BYTES,
114
+ MCP_SKILL_SNAPSHOT_MAX_DEPTH,
115
+ MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES,
112
116
  MCP_SKILL_URI_MAX_CHARS,
113
117
  RUNS_STORE,
114
118
  SECRETS_STORE,
@@ -117,6 +121,7 @@ import {
117
121
  assignMcpSkillNames,
118
122
  collectMcpSkillSources,
119
123
  createMcpSkillRunConsent,
124
+ createMcpSkillSnapshotMemory,
120
125
  decideMcpSkillConsent,
121
126
  isMcpSkillName,
122
127
  mcpSkillBodyText,
@@ -135,10 +140,12 @@ import {
135
140
  openAgentWebDB,
136
141
  recordMcpSkillConsent,
137
142
  resolveMcpSkillConsent,
138
- resolveMcpSkillFile,
143
+ resolveMcpSkillPath,
139
144
  resolveMcpSkillServer,
140
- selectMcpSkills
141
- } from "./chunk-YUA2BHRM.js";
145
+ selectMcpSkills,
146
+ skillDirectoryListing,
147
+ skillDirectoryOf
148
+ } from "./chunk-ZSZSSJS4.js";
142
149
 
143
150
  // src/caching.ts
144
151
  var resolveCaching = (s) => {
@@ -618,17 +625,24 @@ var McpSkillDeniedError = class extends Error {
618
625
  return this.message;
619
626
  }
620
627
  };
621
- var mcpSkillOf = (source, record2, name, byUri) => {
628
+ var mcpSkillOf = (source, record2, name, byUri, memory) => {
622
629
  const skill = {
623
630
  name,
624
- description: mcpSkillDescription(record2.description, source.server),
631
+ description: mcpSkillDescription(record2.description, source.server, record2.dynamic === true),
625
632
  content: "",
626
633
  mcp: { server: source.server, uri: record2.uri }
627
634
  };
628
- mcpSkillStates.set(skill, { source, record: record2, ...byUri ? { byUri: true } : {} });
635
+ mcpSkillStates.set(skill, { source, record: record2, memory, ...byUri ? { byUri: true } : {} });
629
636
  return skill;
630
637
  };
631
- var createMcpSkills = (sources, names, warn) => {
638
+ var memoryOf = (skills) => {
639
+ for (const skill of skills) {
640
+ const memory = mcpSkillStates.get(skill)?.memory;
641
+ if (memory) return memory;
642
+ }
643
+ return void 0;
644
+ };
645
+ var createMcpSkills = (sources, names, warn, memory = createMcpSkillSnapshotMemory()) => {
632
646
  const own = new Set(names);
633
647
  const taken = new Set(own);
634
648
  const { kept, notices } = selectMcpSkills(
@@ -659,12 +673,12 @@ var createMcpSkills = (sources, names, warn) => {
659
673
  `[mcp] ${source.server}: its skill "${record2.name}" has the name of one of this agent's own skills; the agent's keeps the name, the server's is "${name}"`
660
674
  );
661
675
  }
662
- out.push(mcpSkillOf(source, record2, name, added.has(record2)));
676
+ out.push(mcpSkillOf(source, record2, name, added.has(record2), memory));
663
677
  }
664
678
  }
665
679
  return out;
666
680
  };
667
- var addMcpSkillByUri = async (skills, sources, requested, signal) => {
681
+ var addMcpSkillByUri = async (skills, sources, requested, signal, memory) => {
668
682
  const refused = mcpSkillUriRefusal(requested.uri);
669
683
  if (refused) throw new Error(`load_skill: ${refused}`);
670
684
  const able = sources.filter((s) => typeof s.get === "function");
@@ -689,13 +703,22 @@ var addMcpSkillByUri = async (skills, sources, requested, signal) => {
689
703
  const meanwhile = held();
690
704
  if (meanwhile) return meanwhile;
691
705
  const name = assignAddedMcpSkillName(source.server, record2, new Set(skills.map((s) => s.name)));
692
- const skill = mcpSkillOf(source, record2, name, true);
706
+ const skill = mcpSkillOf(
707
+ source,
708
+ record2,
709
+ name,
710
+ true,
711
+ memoryOf(skills) ?? memory ?? createMcpSkillSnapshotMemory()
712
+ );
693
713
  skills.push(skill);
694
714
  return skill;
695
715
  };
696
716
  var fetchMcpSkill = async (state, signal) => {
697
717
  if (state.fetched) return state.fetched;
698
- state.fetching ??= state.source.load(state.record.uri, signal ? { signal } : void 0);
718
+ state.fetching ??= state.source.load(state.record.uri, {
719
+ ...signal ? { signal } : {},
720
+ memory: state.memory
721
+ });
699
722
  try {
700
723
  state.fetched = await state.fetching;
701
724
  return state.fetched;
@@ -756,7 +779,8 @@ var acquireMcpSkill = async (skill, skills, scope, opts = {}) => {
756
779
  body: fetched.body,
757
780
  consent,
758
781
  ...state.byUri ? { byUri: true } : {},
759
- ...enclosing ? { nestedIn: enclosing } : {}
782
+ ...enclosing ? { nestedIn: enclosing } : {},
783
+ ...fetched.snapshot ? { snapshot: fetched.snapshot } : {}
760
784
  });
761
785
  const answer = await scope.ask(opts.input ?? { name: skill.name }, view, opts.signal);
762
786
  if (answer.by === "person") {
@@ -801,8 +825,16 @@ var readMcpSkillFile = async (skill, skills, requested, scope, signal) => {
801
825
  }
802
826
  const state = mcpSkillStates.get(skill);
803
827
  const loaded = state.loaded;
804
- const target = resolveMcpSkillFile(loaded.files, requested);
828
+ const target = resolveMcpSkillPath(loaded.files, requested);
805
829
  if ("refused" in target) throw new Error(`skill "${skill.name}": ${target.refused}`);
830
+ if ("dir" in target) {
831
+ const drift = await state.source.readDirectory?.(
832
+ loaded,
833
+ target.dir,
834
+ signal ? { signal } : void 0
835
+ );
836
+ return skillDirectoryListing(skill.name, target.dir, target, drift);
837
+ }
806
838
  const text = await state.source.readFile(loaded, target.path, signal ? { signal } : void 0);
807
839
  return mcpSkillFileText(state.source.server, state.record.uri, target.path, text);
808
840
  };
@@ -869,7 +901,8 @@ var createSkillTools = (skills, onLoad, mcp) => {
869
901
  skills,
870
902
  servers,
871
903
  { server, uri },
872
- signalOf(options)
904
+ signalOf(options),
905
+ mcp?.memory
873
906
  );
874
907
  return load(skill2, { server, uri }, signalOf(options));
875
908
  }
@@ -895,12 +928,15 @@ var createSkillTools = (skills, onLoad, mcp) => {
895
928
  }
896
929
  });
897
930
  const readFile = tool({
898
- description: "Read one of a skill's bundled files (paths are listed by load_skill).",
931
+ description: `Read one of a skill's bundled files (paths are listed by load_skill); a directory path ("templates/", "." for the root) returns its listing.`,
899
932
  inputSchema: jsonSchema({
900
933
  type: "object",
901
934
  properties: {
902
935
  name: { type: "string", description: "The skill name" },
903
- path: { type: "string", description: "The file path, relative to the skill" }
936
+ path: {
937
+ type: "string",
938
+ description: "The file path, relative to the skill, or a directory to list"
939
+ }
904
940
  },
905
941
  required: ["name", "path"],
906
942
  additionalProperties: false
@@ -913,8 +949,12 @@ var createSkillTools = (skills, onLoad, mcp) => {
913
949
  }
914
950
  const file = skill.files?.find((f) => f.path === path);
915
951
  if (!file) {
916
- const listed = (skill.files ?? []).map((f) => f.path).join(", ") || "none";
917
- throw new Error(`skill "${name}" has no file "${path}"; files: ${listed}`);
952
+ const paths = (skill.files ?? []).map((f) => f.path);
953
+ const directory = skillDirectoryOf(paths, path);
954
+ if (directory) return skillDirectoryListing(skill.name, directory.dir, directory);
955
+ throw new Error(
956
+ `skill "${name}" has no file "${path}"; files: ${paths.join(", ") || "none"}`
957
+ );
918
958
  }
919
959
  return file.content;
920
960
  }
@@ -4122,6 +4162,7 @@ var SPAWN_INPUT_SCHEMA = {
4122
4162
  description: "Optional: the names of YOUR tools the helper may use. Only tools you have can be named. Omit it for the default set; pass [] for a helper that only reasons."
4123
4163
  }
4124
4164
  },
4165
+ // A mutable array: JSON Schema 7's `required` is `string[]`, and `as const` would make it readonly.
4125
4166
  required: ["task"],
4126
4167
  additionalProperties: false
4127
4168
  };
@@ -4541,8 +4582,49 @@ var resolveResume = async (persistence, resumeFromRunId) => {
4541
4582
  `Run "${resumeFromRunId}" has no steps left to run (status="${snapshot.status}"); nothing to resume`
4542
4583
  );
4543
4584
  }
4585
+ if (snapshot.attempt !== void 0 && !(Number.isSafeInteger(snapshot.attempt) && snapshot.attempt >= 1)) {
4586
+ throw new Error(
4587
+ `Run "${resumeFromRunId}" has an invalid attempt (${JSON.stringify(snapshot.attempt)}); it must be a positive integer`
4588
+ );
4589
+ }
4544
4590
  return snapshot;
4545
4591
  };
4592
+ var resolveRunId = async (persistence, runId, resumeFromRunId) => {
4593
+ if (runId === void 0) return void 0;
4594
+ if (resumeFromRunId !== void 0) {
4595
+ throw new Error(
4596
+ "runId names a fresh run and cannot be combined with resumeFromRunId: a resume keeps the id of the run it resumes"
4597
+ );
4598
+ }
4599
+ assertSafeRunId(runId, "runId");
4600
+ const snapshot = await persistence?.loadRun?.(runId);
4601
+ if (snapshot) {
4602
+ throw new Error(
4603
+ `Run "${runId}" already exists (status "${snapshot.status}"); resume it with resumeFromRunId instead of starting it again`
4604
+ );
4605
+ }
4606
+ return runId;
4607
+ };
4608
+ var resumeAttemptOf = (snapshot) => (snapshot.attempt ?? 1) + 1;
4609
+ var recordResume = async (persistence, resumed, attempt, warn) => {
4610
+ const hook = persistence?.onRunResume ? "onRunResume" : persistence?.onStepComplete ? "onStepComplete" : void 0;
4611
+ if (!persistence || !hook) {
4612
+ warn(
4613
+ `persistence has neither onRunResume nor onStepComplete: attempt ${attempt} of run ${resumed.runId} is not on record until the run ends`
4614
+ );
4615
+ return;
4616
+ }
4617
+ const { error: _error, completedAt: _completedAt, text: _text, ...rest } = resumed;
4618
+ void [_error, _completedAt, _text];
4619
+ try {
4620
+ await persistence[hook]?.call(persistence, { ...rest, status: "executing", attempt });
4621
+ } catch (err) {
4622
+ throw new Error(
4623
+ `persistence.${hook} threw while recording attempt ${attempt} of run ${resumed.runId}; the resume was refused: ${err instanceof Error ? err.message : String(err)}`,
4624
+ { cause: err }
4625
+ );
4626
+ }
4627
+ };
4546
4628
 
4547
4629
  // src/agent/schemas.ts
4548
4630
  import { z as z5 } from "zod";
@@ -5513,7 +5595,7 @@ var createAgent = async (config) => {
5513
5595
  config.availableTools,
5514
5596
  config.excludedTools
5515
5597
  );
5516
- const sandbox = config.sandbox ? (await import("./sandbox-ZDQIIZS7.js")).createSandbox(
5598
+ const sandbox = config.sandbox ? (await import("./sandbox-3VRX47UY.js")).createSandbox(
5517
5599
  config.sandbox === true ? {} : config.sandbox,
5518
5600
  hostTools,
5519
5601
  (m) => log.warn(m)
@@ -5526,12 +5608,14 @@ var createAgent = async (config) => {
5526
5608
  const spawnBuiltIn = Boolean(dynamicSubagents) && config.tools?.[SPAWN_SUBAGENT_TOOL] === void 0 && baseTools[SPAWN_SUBAGENT_TOOL] !== void 0;
5527
5609
  const mcpInstructions = config.mcpInstructions === false ? "" : renderMcpInstructions(collectMcpInstructions(baseTools));
5528
5610
  const mcpSkillSources = collectMcpSkillSources(baseTools);
5611
+ const mcpSkillMemory = createMcpSkillSnapshotMemory();
5529
5612
  if (!seed) {
5530
5613
  skills.push(
5531
5614
  ...createMcpSkills(
5532
5615
  mcpSkillSources,
5533
5616
  skills.map((s) => s.name),
5534
- (m) => log.warn(m)
5617
+ (m) => log.warn(m),
5618
+ mcpSkillMemory
5535
5619
  )
5536
5620
  );
5537
5621
  }
@@ -5608,16 +5692,20 @@ ${renderActiveSkills(active)}`
5608
5692
  spentBySession.set(sessionId, addUsage(spentBySession.get(sessionId) ?? emptyUsage(), u));
5609
5693
  };
5610
5694
  const runCore = async (goal, opts, track, port) => {
5695
+ const ownRunId = await resolveRunId(config.persistence, opts.runId, opts.resumeFromRunId);
5611
5696
  const resumed = await resolveResume(config.persistence, opts.resumeFromRunId);
5697
+ const attempt = resumed ? resumeAttemptOf(resumed) : 1;
5698
+ let seq3 = 0;
5612
5699
  const emit = (event) => {
5613
5700
  try {
5614
- opts.onEvent?.(event);
5701
+ opts.onEvent?.({ ...event, seq: ++seq3, attempt });
5615
5702
  } catch {
5616
5703
  }
5617
5704
  };
5705
+ if (resumed) await recordResume(config.persistence, resumed, attempt, (m) => log.warn(m));
5618
5706
  let text = (resumed?.goal ?? goal).trim();
5619
5707
  const sessionId = resumed?.sessionId ?? opts.sessionId ?? cfg.sessionId;
5620
- const runId = resumed?.runId ?? newRunId();
5708
+ const runId = resumed?.runId ?? ownRunId ?? newRunId();
5621
5709
  const startedAt = resumed?.startedAt ?? Date.now();
5622
5710
  let usage = resumed ? { ...resumed.usage } : emptyUsage();
5623
5711
  const result = {
@@ -5735,7 +5823,7 @@ ${renderActiveSkills(active)}`
5735
5823
  createSkillTools(
5736
5824
  skills,
5737
5825
  (s) => activateSkill(s.name, "tool"),
5738
- mcpSkillSources.length ? { sources: mcpSkillSources, scope: skillScope } : void 0
5826
+ mcpSkillSources.length ? { sources: mcpSkillSources, scope: skillScope, memory: mcpSkillMemory } : void 0
5739
5827
  )
5740
5828
  );
5741
5829
  }
@@ -6002,6 +6090,7 @@ ${renderActiveSkills(active)}`
6002
6090
  ...userUpdates.length ? { userUpdates: userUpdates.map((u) => ({ ...u })) } : {},
6003
6091
  ...escalationCount ? { escalations: escalationCount } : {},
6004
6092
  ...spawnRun && !seed && spawnRun.root.spawned ? { subagentsSpawned: spawnRun.root.spawned } : {},
6093
+ attempt,
6005
6094
  ...extra
6006
6095
  });
6007
6096
  const persist = async (hook, snapshot) => {
@@ -7334,7 +7423,100 @@ var preparePipeline = (definition) => {
7334
7423
  reaches: (from, to) => descendants(from).has(to)
7335
7424
  };
7336
7425
  };
7337
- var abortError2 = () => new DOMException("Aborted", "AbortError");
7426
+ var passReach = (plan) => {
7427
+ const entry = plan.definition.entry;
7428
+ const order = [entry];
7429
+ const preds = /* @__PURE__ */ new Map([[entry, []]]);
7430
+ for (let i = 0; i < order.length; i++) {
7431
+ for (const { edge } of plan.outgoing.get(order[i]) ?? []) {
7432
+ if (!preds.has(edge.to)) {
7433
+ preds.set(edge.to, []);
7434
+ order.push(edge.to);
7435
+ }
7436
+ ;
7437
+ preds.get(edge.to).push(order[i]);
7438
+ }
7439
+ }
7440
+ const dom = /* @__PURE__ */ new Map();
7441
+ for (const nodeId of order) dom.set(nodeId, new Set(nodeId === entry ? [entry] : order));
7442
+ for (let changed = true; changed; ) {
7443
+ changed = false;
7444
+ for (const nodeId of order) {
7445
+ if (nodeId === entry) continue;
7446
+ const [first, ...rest] = preds.get(nodeId).map((p) => dom.get(p));
7447
+ const next = /* @__PURE__ */ new Set([nodeId]);
7448
+ for (const d of first) if (rest.every((set) => set.has(d))) next.add(d);
7449
+ if (next.size < dom.get(nodeId).size) {
7450
+ dom.set(nodeId, next);
7451
+ changed = true;
7452
+ }
7453
+ }
7454
+ }
7455
+ const closure = /* @__PURE__ */ new Map();
7456
+ return (from, to) => {
7457
+ let seen = closure.get(from);
7458
+ if (!seen) {
7459
+ const found = /* @__PURE__ */ new Set();
7460
+ const queue = [from];
7461
+ while (queue.length) {
7462
+ const at = queue.pop();
7463
+ for (const { edge } of plan.outgoing.get(at) ?? []) {
7464
+ if (dom.get(at)?.has(edge.to) || found.has(edge.to)) continue;
7465
+ found.add(edge.to);
7466
+ queue.push(edge.to);
7467
+ }
7468
+ }
7469
+ closure.set(from, seen = found);
7470
+ }
7471
+ return seen.has(to);
7472
+ };
7473
+ };
7474
+ var abortError2 = () => {
7475
+ if (typeof DOMException === "function") return new DOMException("Aborted", "AbortError");
7476
+ const error = new Error("Aborted");
7477
+ error.name = "AbortError";
7478
+ return error;
7479
+ };
7480
+ var createStopper = () => {
7481
+ if (typeof AbortController === "function") {
7482
+ const controller = new AbortController();
7483
+ return { signal: controller.signal, abort: () => controller.abort() };
7484
+ }
7485
+ const listeners = [];
7486
+ const signal = {
7487
+ aborted: false,
7488
+ reason: void 0,
7489
+ onabort: null,
7490
+ addEventListener(type, listener) {
7491
+ if (type === "abort" && listener && !listeners.includes(listener)) listeners.push(listener);
7492
+ },
7493
+ removeEventListener(type, listener) {
7494
+ const index = listener ? listeners.indexOf(listener) : -1;
7495
+ if (type === "abort" && index >= 0) listeners.splice(index, 1);
7496
+ },
7497
+ throwIfAborted() {
7498
+ if (signal.aborted) throw signal.reason;
7499
+ }
7500
+ };
7501
+ const abort = () => {
7502
+ if (signal.aborted) return;
7503
+ signal.aborted = true;
7504
+ signal.reason = abortError2();
7505
+ const event = { type: "abort", target: signal };
7506
+ const call = (fn, thisArg) => {
7507
+ try {
7508
+ fn.call(thisArg, event);
7509
+ } catch {
7510
+ }
7511
+ };
7512
+ for (const listener of listeners.splice(0)) {
7513
+ if (typeof listener === "function") call(listener, signal);
7514
+ else call(listener.handleEvent, listener);
7515
+ }
7516
+ if (typeof signal.onabort === "function") call(signal.onabort, signal);
7517
+ };
7518
+ return { signal, abort };
7519
+ };
7338
7520
  var addUsage2 = (into, usage) => {
7339
7521
  if (!usage) return;
7340
7522
  const sum = into;
@@ -7342,9 +7524,10 @@ var addUsage2 = (into, usage) => {
7342
7524
  if (typeof value === "number" && Number.isFinite(value)) sum[key] = (sum[key] ?? 0) + value;
7343
7525
  }
7344
7526
  };
7345
- var runPipelineGraph = async (plan, runNode, options, onAbort) => {
7527
+ var runPipelineGraph = async (plan, runNode, options) => {
7346
7528
  const { definition } = plan;
7347
- const controller = new AbortController();
7529
+ const onAbort = options.onAbort ?? "reject";
7530
+ const stopper = createStopper();
7348
7531
  let halted;
7349
7532
  let halt = () => {
7350
7533
  };
@@ -7379,7 +7562,7 @@ ${t.text}`).join("\n\n");
7379
7562
  const onOuterAbort = () => {
7380
7563
  if (halted) return;
7381
7564
  halted = "aborted";
7382
- controller.abort();
7565
+ stopper.abort();
7383
7566
  halt(abortError2());
7384
7567
  };
7385
7568
  const visit = async (nodeId, activations) => {
@@ -7395,7 +7578,7 @@ ${t.text}`).join("\n\n");
7395
7578
  node,
7396
7579
  { request: options.input, from: activations.map((a) => ({ ...a.source })), visit: number },
7397
7580
  {
7398
- signal: controller.signal,
7581
+ signal: stopper.signal,
7399
7582
  pipeline: definition,
7400
7583
  emit: (event) => {
7401
7584
  if (!halted) emit({ ...event, nodeId, visit: number });
@@ -7412,7 +7595,7 @@ ${t.text}`).join("\n\n");
7412
7595
  visit: number,
7413
7596
  error: err instanceof Error ? err.message : String(err)
7414
7597
  });
7415
- controller.abort();
7598
+ stopper.abort();
7416
7599
  halt(failure);
7417
7600
  return;
7418
7601
  }
@@ -7468,7 +7651,8 @@ ${t.text}`).join("\n\n");
7468
7651
  if (record2.live === 0) terminals.push(record2);
7469
7652
  }
7470
7653
  };
7471
- const deferred = (nodeId, all) => (plan.nodes.get(nodeId)?.join ?? "all") === "all" && all.some((other) => other !== nodeId && plan.reaches(other, nodeId));
7654
+ const deferred = (nodeId, all, reaches = plan.reaches) => (plan.nodes.get(nodeId)?.join ?? "all") === "all" && all.some((other) => other !== nodeId && reaches(other, nodeId));
7655
+ let inPass;
7472
7656
  emit({ type: "pipeline.started", ...definition.name ? { pipeline: definition.name } : {} });
7473
7657
  options.signal?.addEventListener("abort", onOuterAbort, { once: true });
7474
7658
  try {
@@ -7476,6 +7660,10 @@ ${t.text}`).join("\n\n");
7476
7660
  while (pending.size > 0 && !halted) {
7477
7661
  const waiting = [...pending.keys()];
7478
7662
  let ready = waiting.filter((nodeId) => !deferred(nodeId, waiting));
7663
+ if (ready.length === 0) {
7664
+ const reaches = inPass ??= passReach(plan);
7665
+ ready = waiting.filter((nodeId) => !deferred(nodeId, waiting, reaches));
7666
+ }
7479
7667
  if (ready.length === 0) ready = waiting;
7480
7668
  const starting = [];
7481
7669
  for (const nodeId of ready) {
@@ -7563,6 +7751,21 @@ var pickRouteWithDecisionModel = async ({ agent, config }, node, text, signal, e
7563
7751
  ...outcome.accepted && outcome.choice !== void 0 ? { route: outcome.choice } : {}
7564
7752
  };
7565
7753
  };
7754
+ var pickPipelineRoute = async (node, text, options) => {
7755
+ if (!node.routes?.length) return { usage: normalizeUsage() };
7756
+ const entry = { agent: options.agent, config: options.config };
7757
+ const signal = options.signal ?? new AbortController().signal;
7758
+ const emit = (event) => {
7759
+ try {
7760
+ options.onEvent?.(event);
7761
+ } catch {
7762
+ }
7763
+ };
7764
+ const quick = await pickRouteWithDecisionModel(entry, node, text, signal, emit);
7765
+ if (quick?.route) return quick;
7766
+ const slow = await pickRoute(entry, node, text, signal);
7767
+ return quick ? { ...slow, usage: addUsage(quick.usage, slow.usage) } : slow;
7768
+ };
7566
7769
  var createPipeline = (definition, options) => {
7567
7770
  const plan = preparePipeline(definition);
7568
7771
  const { resolveNode } = options;
@@ -7597,11 +7800,11 @@ var createPipeline = (definition, options) => {
7597
7800
  if (result.stopped || ctx.signal.aborted) throw aborted();
7598
7801
  if (failure !== void 0) throw new Error(failure);
7599
7802
  if (!node.routes?.length) return { text: result.final, usage: result.usage };
7600
- const quick = await pickRouteWithDecisionModel(entry, node, result.final, ctx.signal, ctx.emit);
7601
- const picked = quick?.route ? quick : await pickRoute(entry, node, result.final, ctx.signal).then((slow) => ({
7602
- ...slow,
7603
- usage: quick ? addUsage(quick.usage, slow.usage) : slow.usage
7604
- }));
7803
+ const picked = await pickPipelineRoute(node, result.final, {
7804
+ ...entry,
7805
+ signal: ctx.signal,
7806
+ onEvent: ctx.emit
7807
+ });
7605
7808
  return {
7606
7809
  text: result.final,
7607
7810
  usage: addUsage(result.usage, picked.usage),
@@ -7610,12 +7813,12 @@ var createPipeline = (definition, options) => {
7610
7813
  };
7611
7814
  return {
7612
7815
  definition: plan.definition,
7613
- run: (run) => runPipelineGraph(
7614
- plan,
7615
- options.runNode ?? runWithAgent,
7616
- { input: run.input, signal: run.signal, onEvent: run.onEvent },
7617
- "resolve"
7618
- ),
7816
+ run: (run) => runPipelineGraph(plan, options.runNode ?? runWithAgent, {
7817
+ input: run.input,
7818
+ signal: run.signal,
7819
+ onEvent: run.onEvent,
7820
+ onAbort: "resolve"
7821
+ }),
7619
7822
  close: async () => {
7620
7823
  agents.clear();
7621
7824
  }
@@ -8240,6 +8443,10 @@ var MemoryRunStore = class {
8240
8443
  onStepComplete(snapshot) {
8241
8444
  this.runs.set(snapshot.runId, snapshot);
8242
8445
  }
8446
+ /** A resume started: its attempt is on record before any of its events. */
8447
+ onRunResume(snapshot) {
8448
+ this.runs.set(snapshot.runId, snapshot);
8449
+ }
8243
8450
  onRunComplete(snapshot) {
8244
8451
  if (snapshot.status === "complete" && !this.keepCompleted) this.runs.delete(snapshot.runId);
8245
8452
  else this.runs.set(snapshot.runId, snapshot);
@@ -8290,6 +8497,10 @@ var IndexedDBRunStore = class {
8290
8497
  onStepComplete(snapshot) {
8291
8498
  return this.put(snapshot);
8292
8499
  }
8500
+ /** A resume started: its attempt is on record before any of its events. */
8501
+ onRunResume(snapshot) {
8502
+ return this.put(snapshot);
8503
+ }
8293
8504
  async onRunComplete(snapshot) {
8294
8505
  if (snapshot.status === "complete" && !this.keepCompleted) {
8295
8506
  await this.delete(snapshot.runId);
@@ -8359,9 +8570,13 @@ export {
8359
8570
  MCP_SKILL_CONSENTS,
8360
8571
  MCP_SKILL_CONSENT_DEFAULT,
8361
8572
  MCP_SKILL_DESCRIPTION_MAX_CHARS,
8573
+ MCP_SKILL_DIRECTORY_ENTRIES_MAX,
8362
8574
  MCP_SKILL_FILE_MAX_CHARS,
8363
8575
  MCP_SKILL_MAX_RESOURCES,
8364
8576
  MCP_SKILL_MAX_TOTAL_BYTES,
8577
+ MCP_SKILL_SNAPSHOTS_MAX_BYTES,
8578
+ MCP_SKILL_SNAPSHOT_MAX_DEPTH,
8579
+ MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES,
8365
8580
  MCP_SKILL_URI_MAX_CHARS,
8366
8581
  MEDIA_AUDIO_TYPES,
8367
8582
  MEDIA_DEFAULT_MAX_CALLS,
@@ -8383,6 +8598,7 @@ export {
8383
8598
  MemorySkillStore,
8384
8599
  MemoryStore,
8385
8600
  PIPELINE_LIMITS,
8601
+ PIPELINE_ROUTER_SYSTEM,
8386
8602
  PipelineNodeError,
8387
8603
  PipelineValidationError,
8388
8604
  PlanSchema,
@@ -8501,6 +8717,7 @@ export {
8501
8717
  looksLikeJson,
8502
8718
  markCodeExecution,
8503
8719
  markReadOnly,
8720
+ matchPipelineRoute,
8504
8721
  matchRule,
8505
8722
  mcpAppOrigin,
8506
8723
  mcpSkillEntryRefusal,
@@ -8525,12 +8742,15 @@ export {
8525
8742
  parseReplannerResponse,
8526
8743
  parseSearchResponse,
8527
8744
  parseSkillMarkdown,
8745
+ pickPipelineRoute,
8528
8746
  pickTier,
8529
8747
  preloadWebLLMModel,
8748
+ preparePipeline,
8530
8749
  promptHintOf,
8531
8750
  renderActiveSkills,
8532
8751
  renderCatalog,
8533
8752
  renderPipelineNodeInput,
8753
+ renderPipelineRoutePrompt,
8534
8754
  renderSearchCatalog,
8535
8755
  renderSkillIndex,
8536
8756
  replanWanted,
@@ -8547,6 +8767,7 @@ export {
8547
8767
  resolveResume,
8548
8768
  resolveStage,
8549
8769
  resolveThinking,
8770
+ runPipelineGraph,
8550
8771
  runToolLoop,
8551
8772
  sanitizeSearchResults,
8552
8773
  schemaHintOf,