@tangle-network/agent-runtime 6.0.8 → 8.0.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 (119) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +23 -12
  3. package/dist/{activation-Cwy3_Qn_.js → activation-Ce4zUcu8.js} +4 -4
  4. package/dist/{activation-Cwy3_Qn_.js.map → activation-Ce4zUcu8.js.map} +1 -1
  5. package/dist/{activation-CWx7I1PU.d.ts → activation-xxvLF1-1.d.ts} +2 -2
  6. package/dist/agent.d.ts +1 -1
  7. package/dist/agent.js +3 -3
  8. package/dist/{bundle-Cy5igJdv.js → bundle-CcpL2lfr.js} +2 -2
  9. package/dist/{bundle-Cy5igJdv.js.map → bundle-CcpL2lfr.js.map} +1 -1
  10. package/dist/candidate-execution/index.js +4 -4
  11. package/dist/continuation-CIyKnS1Q.js +451 -0
  12. package/dist/continuation-CIyKnS1Q.js.map +1 -0
  13. package/dist/{coordination-manager-D9z7To7p.js → coordination-manager-sa_PkISw.js} +247 -149
  14. package/dist/coordination-manager-sa_PkISw.js.map +1 -0
  15. package/dist/{coordination-map-routing-CKRNZSaV.js → coordination-map-routing-XZXTlCmn.js} +2 -4
  16. package/dist/coordination-map-routing-XZXTlCmn.js.map +1 -0
  17. package/dist/{delegate-ws-KBA2H.js → delegate-DhTkJIta.js} +3 -3
  18. package/dist/{delegate-ws-KBA2H.js.map → delegate-DhTkJIta.js.map} +1 -1
  19. package/dist/durable.d.ts +71 -4
  20. package/dist/durable.js +162 -13
  21. package/dist/durable.js.map +1 -1
  22. package/dist/{errors-AzSuGI23.js → errors-DG8yufqX.js} +8 -1
  23. package/dist/errors-DG8yufqX.js.map +1 -0
  24. package/dist/{failure-cause-BzjUUsRz.js → failure-cause-CVB-YE88.js} +17 -16
  25. package/dist/failure-cause-CVB-YE88.js.map +1 -0
  26. package/dist/{graph-registry-7X2nrreR.js → graph-registry-czAwYwNj.js} +133 -9
  27. package/dist/graph-registry-czAwYwNj.js.map +1 -0
  28. package/dist/{graph-registry-gYbq4L5Z.js → graph-registry-uTIyyy7A.js} +1 -1
  29. package/dist/graph-tSIT_eWK.js +1793 -0
  30. package/dist/graph-tSIT_eWK.js.map +1 -0
  31. package/dist/{improve-BxfqTsZy.js → improve-H08hiIw9.js} +19 -48
  32. package/dist/improve-H08hiIw9.js.map +1 -0
  33. package/dist/index.d.ts +3 -3
  34. package/dist/index.js +16 -16
  35. package/dist/intelligence.d.ts +2 -2
  36. package/dist/intelligence.js +8 -8
  37. package/dist/intelligence.js.map +1 -1
  38. package/dist/kernel.d.ts +2 -2
  39. package/dist/kernel.js +16 -15
  40. package/dist/{loop-runner-CUMypgRw.d.ts → loop-runner-BGwhcn1p.d.ts} +2 -2
  41. package/dist/{loop-runner-BmGZ4y1W.js → loop-runner-ChqK8kSz.js} +3 -3
  42. package/dist/{loop-runner-BmGZ4y1W.js.map → loop-runner-ChqK8kSz.js.map} +1 -1
  43. package/dist/loop-runner-bin.d.ts +1 -1
  44. package/dist/loop-runner-bin.js +1 -1
  45. package/dist/mcp/bin.js +7 -5
  46. package/dist/mcp/bin.js.map +1 -1
  47. package/dist/mcp/index.d.ts +1 -1
  48. package/dist/mcp/index.js +9 -9
  49. package/dist/mcp/memory-bin.js +2 -2
  50. package/dist/{model-policy-JOcg3NRs.js → model-policy-yxOrDTTj.js} +9 -9
  51. package/dist/model-policy-yxOrDTTj.js.map +1 -0
  52. package/dist/{prepare-Dtfk_Wi_.js → prepare-BnF8nGIg.js} +4 -4
  53. package/dist/{prepare-Dtfk_Wi_.js.map → prepare-BnF8nGIg.js.map} +1 -1
  54. package/dist/{profile-CNSQjOes.js → profile-CD25rTJF.js} +4 -4
  55. package/dist/{profile-CNSQjOes.js.map → profile-CD25rTJF.js.map} +1 -1
  56. package/dist/profiles.d.ts +1 -1
  57. package/dist/profiles.js +2 -2
  58. package/dist/{provision-supervisor-CeQTPHRr.js → provision-supervisor-Dx4TXTMM.js} +8 -8
  59. package/dist/{provision-supervisor-CeQTPHRr.js.map → provision-supervisor-Dx4TXTMM.js.map} +1 -1
  60. package/dist/{run-cancellation-D_4vJ522.js → run-cancellation-DYszFJtQ.js} +4 -4
  61. package/dist/{run-cancellation-D_4vJ522.js.map → run-cancellation-DYszFJtQ.js.map} +1 -1
  62. package/dist/{run-state-CTZVngI_.js → run-state-DHBoJjaF.js} +6 -6
  63. package/dist/{run-state-CTZVngI_.js.map → run-state-DHBoJjaF.js.map} +1 -1
  64. package/dist/{runtime-COm9uBBx.js → runtime-CaM5Gbbv.js} +76 -987
  65. package/dist/runtime-CaM5Gbbv.js.map +1 -0
  66. package/dist/{sandbox-profile-compat-oFGWESLn.js → sandbox-profile-compat-l-SLQnGb.js} +2 -2
  67. package/dist/{sandbox-profile-compat-oFGWESLn.js.map → sandbox-profile-compat-l-SLQnGb.js.map} +1 -1
  68. package/dist/{search-executor-DTEIl58w.js → search-executor-B9L8W_1O.js} +17 -46
  69. package/dist/search-executor-B9L8W_1O.js.map +1 -0
  70. package/dist/{server-zO9Nz9Nk.js → server-BlDV8sj_.js} +32 -8
  71. package/dist/{server-zO9Nz9Nk.js.map → server-BlDV8sj_.js.map} +1 -1
  72. package/dist/{settle-record-U7fkQEZa.js → settle-record-WWQasnDq.js} +12 -4
  73. package/dist/settle-record-WWQasnDq.js.map +1 -0
  74. package/dist/{snapshot-Cgj2Wzi6.js → snapshot-BKI_w3JD.js} +19 -5
  75. package/dist/snapshot-BKI_w3JD.js.map +1 -0
  76. package/dist/{structural-rollout-BwTwTUXF.js → structural-rollout-C1xxoWcN.js} +39 -57
  77. package/dist/structural-rollout-C1xxoWcN.js.map +1 -0
  78. package/dist/{supervise-tmqDU6YT.js → supervise-DWiSgPLB.js} +103 -111
  79. package/dist/supervise-DWiSgPLB.js.map +1 -0
  80. package/dist/{supervision-discovery-CGbXayGv.js → supervision-discovery-C9kfBLKy.js} +4 -4
  81. package/dist/{supervision-discovery-CGbXayGv.js.map → supervision-discovery-C9kfBLKy.js.map} +1 -1
  82. package/dist/{supervisor-1A27fE6k.js → supervisor-Dpeu7rnZ.js} +209 -999
  83. package/dist/supervisor-Dpeu7rnZ.js.map +1 -0
  84. package/dist/{scope-gIYQ5ZiL.js → supervisor-accounting-Bw4MJk-b.js} +755 -458
  85. package/dist/supervisor-accounting-Bw4MJk-b.js.map +1 -0
  86. package/dist/testing.d.ts +1 -1
  87. package/dist/testing.js +13 -13
  88. package/dist/{tool-server-B9q2dtnW.js → tool-server-DYwRbi0I.js} +3 -3
  89. package/dist/{tool-server-B9q2dtnW.js.map → tool-server-DYwRbi0I.js.map} +1 -1
  90. package/dist/{top-web-CS4PD4ck.js → top-web-B3HOAtrZ.js} +9 -7
  91. package/dist/{top-web-CS4PD4ck.js.map → top-web-B3HOAtrZ.js.map} +1 -1
  92. package/dist/tui/bin.js +6 -6
  93. package/dist/tui/bin.js.map +1 -1
  94. package/dist/tui/index.d.ts +1 -1
  95. package/dist/tui/index.js +2 -2
  96. package/dist/{types-w3Oo1uRJ.d.ts → types-C_qbnw9N.d.ts} +1263 -1497
  97. package/dist/{util-C_cdPNC4.js → util-fcckrkKp.js} +39 -113
  98. package/dist/util-fcckrkKp.js.map +1 -0
  99. package/dist/{workspace-streams-B7yNMahl.js → workspace-streams-DA9R3j-p.js} +2 -2
  100. package/dist/{workspace-streams-B7yNMahl.js.map → workspace-streams-DA9R3j-p.js.map} +1 -1
  101. package/package.json +1 -1
  102. package/dist/coordination-manager-D9z7To7p.js.map +0 -1
  103. package/dist/coordination-map-routing-CKRNZSaV.js.map +0 -1
  104. package/dist/errors-AzSuGI23.js.map +0 -1
  105. package/dist/failure-cause-BzjUUsRz.js.map +0 -1
  106. package/dist/graph-2_nX4ib4.js +0 -579
  107. package/dist/graph-2_nX4ib4.js.map +0 -1
  108. package/dist/graph-registry-7X2nrreR.js.map +0 -1
  109. package/dist/improve-BxfqTsZy.js.map +0 -1
  110. package/dist/model-policy-JOcg3NRs.js.map +0 -1
  111. package/dist/runtime-COm9uBBx.js.map +0 -1
  112. package/dist/scope-gIYQ5ZiL.js.map +0 -1
  113. package/dist/search-executor-DTEIl58w.js.map +0 -1
  114. package/dist/settle-record-U7fkQEZa.js.map +0 -1
  115. package/dist/snapshot-Cgj2Wzi6.js.map +0 -1
  116. package/dist/structural-rollout-BwTwTUXF.js.map +0 -1
  117. package/dist/supervise-tmqDU6YT.js.map +0 -1
  118. package/dist/supervisor-1A27fE6k.js.map +0 -1
  119. package/dist/util-C_cdPNC4.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"coordination-map-routing-CKRNZSaV.js","names":[],"sources":["../src/mcp/tools/coordination-json.ts","../src/mcp/tools/coordination-runtime-spawn.ts","../src/mcp/tools/coordination-map-routing.ts"],"sourcesContent":["/** Stringify a findings payload for a routed delivery; never throws (a cyclic payload degrades to\n * its String form rather than killing the settle path). */\nexport function safeJsonText(value: unknown): string {\n if (typeof value === 'string') return value\n try {\n return JSON.stringify(value) ?? String(value)\n } catch {\n return String(value)\n }\n}\n","import { errMessage } from '../../runtime/supervise/error-message'\nimport type { SpawnAdmission } from './coordination-contracts'\n\n/** What a keyed runtime spawn (a flow's entry or route, a map's item or join) became. */\nexport type RuntimeSpawnOutcome =\n /** `committed`: the key already has a durable done result; no new execution ran. */\n | { readonly workerId: string; readonly committed: boolean }\n /** The key and its one replacement both have a prior worker started without a terminal receipt. */\n | { readonly inDoubt: true }\n | { readonly refused: string; readonly code?: string }\n\n/**\n * Admit one keyed runtime spawn. A key whose prior worker is in doubt (started in a dead process\n * with no terminal receipt) is re-admitted once under `<key>#2`, the replacement key the\n * `spawn_worker` contract names; a replacement that is in doubt too is reported, never retried.\n */\nexport async function admitRuntimeSpawn(\n admitSpawn: (input: SpawnAdmission) => Promise<unknown>,\n input: SpawnAdmission & { readonly key: string },\n): Promise<RuntimeSpawnOutcome> {\n for (const key of [input.key, `${input.key}#2`]) {\n let response: unknown\n try {\n response = await admitSpawn({ ...input, key })\n } catch (error) {\n return { refused: errMessage(error) }\n }\n const started = response as Partial<\n Record<'workerId' | 'resumed' | 'error' | 'reason', unknown>\n >\n if (typeof started.workerId === 'string') {\n return { workerId: started.workerId, committed: started.resumed === 'completed' }\n }\n if (started.error !== 'in-doubt') {\n return {\n refused: typeof started.reason === 'string' ? started.reason : 'spawn refused',\n ...(typeof started.error === 'string' ? { code: started.error } : {}),\n }\n }\n }\n return { inDoubt: true }\n}\n","import type { AgentProfile } from '@tangle-network/agent-interface'\nimport type { Scope, Settled } from '../../runtime'\nimport { errMessage } from '../../runtime/supervise/error-message'\nimport type { EventBus } from '../../runtime/supervise/event-bus'\nimport { detachedFrozen } from '../../runtime/supervise/snapshot'\nimport type {\n CoordinationToolsOptions,\n SettledWorker,\n SpawnAdmission,\n} from './coordination-contracts'\nimport type { CoordinationEvent } from './coordination-events'\nimport { safeJsonText } from './coordination-json'\nimport type { MapOnSettleRoute, MapTraversalEvent } from './coordination-map-contracts'\nimport { admitRuntimeSpawn } from './coordination-runtime-spawn'\n\ninterface MapExpansion {\n readonly route: MapOnSettleRoute\n readonly sourceWorker: string\n /** The source node's 1-based done-settle count: its spawns' keys are\n * `map:<edge>#<expansion>:<index>` and `map:<edge>#<expansion>:join`. */\n readonly expansion: number\n readonly items: ReadonlyArray<unknown>\n readonly settlements: Array<WorkerSettlement | undefined>\n /** The next index to start. */\n next: number\n inFlight: number\n /** Set by a failed item under all-or-refuse: no further item starts. */\n stopped: boolean\n finished: boolean\n}\n\ninterface MapMember {\n readonly expansion: MapExpansion\n readonly role: 'item' | 'join'\n readonly index?: number\n readonly bytes: number\n}\n\ntype MapDeps = {\n readonly opts: CoordinationToolsOptions\n readonly bus: EventBus<CoordinationEvent>\n readonly admitSpawn: (input: SpawnAdmission) => Promise<unknown>\n /** The node a worker of this manager runs, by profile name. */\n readonly nodeOf: (workerId: string) => string | undefined\n /** Run a committed spawn's journaled settle through the live settle path. */\n readonly settleCommitted: (workerId: string, node: string) => Promise<void>\n /** End a flow whose map spawn is in doubt twice, at the node and source worker named. */\n readonly endInDoubt: (node: string, source: string) => Promise<void>\n}\n\n/** The map state one manager owns; every function below reads and writes it by reference. */\ntype MapState = MapDeps & {\n readonly mapRoutes: ReadonlyArray<MapOnSettleRoute>\n readonly mapMembers: Map<string, MapMember>\n readonly liveExpansions: Map<string, number>\n}\n\n// ── Map routes: fan-out over a run-time list, then one join ──\n// A map's items and its join are runtime spawns, like analyst runs: each takes the admission a\n// `spawn_worker` call takes, so the pool, the pre-flight and the pinning authority judge it, and\n// no manager turn is spent starting it.\nexport function createMapRouting(deps: MapDeps) {\n const state: MapState = {\n ...deps,\n mapRoutes: deps.opts.mapOnSettle ?? [],\n mapMembers: new Map(),\n liveExpansions: new Map(),\n }\n return {\n isItem: (workerId: string) => state.mapMembers.get(workerId)?.role === 'item',\n settleMapMember: settleMapMember.bind(null, state),\n expandMaps: expandMaps.bind(null, state),\n runMapStep: runMapStep.bind(null, state),\n }\n}\n\nexport const textBytes = (value: unknown): number => Buffer.byteLength(safeJsonText(value), 'utf8')\n\nasync function publishMap(\n { bus }: MapState,\n event: MapTraversalEvent,\n wake = false,\n): Promise<void> {\n const record = detachedFrozen<CoordinationEvent>({ type: 'map', map: event })\n if (wake) await bus.publish(record)\n else await bus.publish(record, { queue: false })\n}\n\n// The run's worker-slot bound, or undefined when only the pool bounds concurrency.\nfunction workerSlotBound({ opts }: MapState): number | undefined {\n const capacity = (opts.scope as Partial<Scope<unknown>>).workerCapacity\n if (capacity === undefined || capacity.freeSlots === null) return undefined\n return capacity.working + capacity.freeSlots\n}\n\n// A started spawn is a map member until it settles. A committed one (its key's done settlement\n// is on disk from a prior process) settles at once through the live settle path, so a restarted\n// manager re-expanding a map runs only the items with no done settlement, then the join once.\n// A spawn in doubt twice is refused, and ends a flow.\nasync function startMapSpawn(\n state: MapState,\n expansion: MapExpansion,\n role: 'item' | 'join',\n profile: AgentProfile,\n task: unknown,\n index: number | undefined,\n): Promise<{ readonly workerId: string } | { readonly refused: string }> {\n const { opts } = state\n const { route } = expansion\n const name = typeof profile.name === 'string' && profile.name.length > 0 ? profile.name : 'worker'\n const spawned = await admitRuntimeSpawn(state.admitSpawn, {\n profile,\n args: {\n label: index === undefined ? name : `${name}#${index}`,\n ...(role === 'item' && route.itemBudget !== undefined ? { budget: route.itemBudget } : {}),\n },\n task,\n key: `map:${route.edge}#${expansion.expansion}:${index ?? 'join'}`,\n continuity: { continuity: 'fresh' },\n successorOf: undefined,\n preflightProfile: () =>\n opts.resolveSpawnProfile ? detachedFrozen(opts.resolveSpawnProfile(profile)) : profile,\n resourcesFromPath: [],\n defaultLabel: name,\n map: Object.freeze({ edge: route.edge, role, ...(index === undefined ? {} : { index }) }),\n })\n if ('inDoubt' in spawned) {\n await state.endInDoubt(name, expansion.sourceWorker)\n return { refused: `in-doubt:${name}` }\n }\n if ('refused' in spawned) return spawned\n state.mapMembers.set(spawned.workerId, {\n expansion,\n role,\n ...(index === undefined ? {} : { index }),\n bytes: textBytes(task),\n })\n if (role === 'item') expansion.inFlight += 1\n if (spawned.committed) await state.settleCommitted(spawned.workerId, name)\n return { workerId: spawned.workerId }\n}\n\n// A graph item starts the way `run_graph` starts a graph: the run prepares the same root profile.\nasync function mapItemProfile(\n { opts }: MapState,\n route: MapOnSettleRoute,\n): Promise<{ readonly profile: AgentProfile } | { readonly refused: string }> {\n if ('profile' in route.item) return { profile: route.item.profile }\n if (!opts.graphs) {\n return { refused: 'a graph item starts through run_graph, which this manager does not serve' }\n }\n const prepared = await opts.graphs.prepare({ graph: route.item.graph })\n return prepared.ok ? { profile: detachedFrozen(prepared.profile) } : { refused: prepared.reason }\n}\n\n/** Record an item that never ran, and tell the manager. */\nasync function recordUnstartedItem(\n state: MapState,\n expansion: MapExpansion,\n index: number,\n reason: string,\n): Promise<void> {\n expansion.settlements[index] = { outcome: 'unpropagated', reason }\n await publishMap(state, {\n edge: expansion.route.edge,\n phase: 'item',\n outcome: 'unpropagated',\n sourceWorker: expansion.sourceWorker,\n index,\n bytes: 0,\n reason,\n })\n}\n\nasync function startMapItem(\n state: MapState,\n expansion: MapExpansion,\n index: number,\n): Promise<void> {\n const { route } = expansion\n const resolved = await mapItemProfile(state, route)\n const started =\n 'refused' in resolved\n ? resolved\n : await startMapSpawn(\n state,\n expansion,\n 'item',\n resolved.profile,\n expansion.items[index],\n index,\n )\n if ('workerId' in started) return\n if (route.onItemFailure === 'all-or-refuse') expansion.stopped = true\n await recordUnstartedItem(state, expansion, index, `item spawn refused: ${started.refused}`)\n}\n\n// Start items until the concurrency cap is reached, the list is exhausted, or all-or-refuse\n// stopped the map; once nothing is in flight, the map finishes.\nasync function pumpMap(state: MapState, expansion: MapExpansion): Promise<void> {\n const { route, items } = expansion\n while (\n !expansion.stopped &&\n expansion.inFlight < route.concurrency &&\n expansion.next < items.length\n ) {\n const index = expansion.next\n expansion.next += 1\n await startMapItem(state, expansion, index)\n }\n if (expansion.inFlight === 0) await finishMap(state, expansion)\n}\n\n// Every item settled or was never started: record the unstarted ones, then start the join with\n// the ordered results, or refuse it. `closed` names why a manager that already stopped does not\n// run the join; nobody would read it.\nasync function finishMap(state: MapState, expansion: MapExpansion, closed?: string): Promise<void> {\n if (expansion.finished) return\n expansion.finished = true\n const { route, items, sourceWorker } = expansion\n for (let index = expansion.next; index < items.length; index += 1) {\n const reason = closed ?? 'not started: all-or-refuse stopped this map after an item failed'\n await recordUnstartedItem(state, expansion, index, reason)\n }\n expansion.next = items.length\n const { results, failures } = collectJoinInputs(expansion)\n const refusal =\n closed ??\n (route.onItemFailure === 'all-or-refuse' && failures.length > 0\n ? `all-or-refuse: ${failures.length} of ${items.length} items did not deliver (${failures\n .map((failure) => `#${failure.index} ${failure.outcome}: ${failure.reason}`)\n .join('; ')}); the join did not run`\n : undefined)\n if (refusal !== undefined) {\n // No settlement follows a refused join, so this event is what wakes the manager.\n await publishMap(\n state,\n {\n edge: route.edge,\n phase: 'join',\n outcome: 'unpropagated',\n sourceWorker,\n bytes: 0,\n reason: refusal,\n },\n closed === undefined,\n )\n return\n }\n const task = { map: route.edge, source: sourceWorker, items: items.length, results, failures }\n const started = await startMapSpawn(state, expansion, 'join', route.join, task, undefined)\n if ('refused' in started) {\n await publishMap(\n state,\n {\n edge: route.edge,\n phase: 'join',\n outcome: 'unpropagated',\n sourceWorker,\n bytes: 0,\n reason: `join spawn refused: ${started.refused}`,\n },\n true,\n )\n }\n // A started join is recorded when it settles; its outcome is not known before.\n}\n\n/** Split an expansion's settlements into the delivered results and the failures, in item order. */\nfunction collectJoinInputs(expansion: MapExpansion) {\n const results: Array<{ index: number; item: unknown; result: unknown }> = []\n const failures: Array<{ index: number; item: unknown; outcome: string; reason: string }> = []\n expansion.items.forEach((item, index) => {\n const settlement = expansion.settlements[index]\n if (settlement?.outcome === 'delivered') {\n results.push({ index, item, result: settlement.result })\n } else {\n failures.push({\n index,\n item,\n outcome: settlement?.outcome ?? 'unpropagated',\n reason: settlement?.reason ?? 'never settled',\n })\n }\n })\n return { results, failures }\n}\n\n// A map item or join settled. `advance` is false once the manager stopped: no further item or\n// join starts, and what never started is recorded as such.\nasync function settleMapMember(\n state: MapState,\n settled: Settled<unknown>,\n worker: SettledWorker,\n advance: boolean,\n): Promise<void> {\n const member = state.mapMembers.get(worker.id)\n if (member === undefined) return\n state.mapMembers.delete(worker.id)\n const { expansion, role, index, bytes } = member\n const settlement = workerSettlement(settled, worker)\n await publishMap(state, {\n edge: expansion.route.edge,\n phase: role,\n outcome: settlement.outcome,\n sourceWorker: expansion.sourceWorker,\n ...(index === undefined ? {} : { index }),\n workerId: worker.id,\n bytes,\n ...(settlement.reason === undefined ? {} : { reason: settlement.reason }),\n })\n if (role === 'join' || index === undefined) return\n expansion.inFlight -= 1\n expansion.settlements[index] = settlement\n if (settlement.outcome !== 'delivered' && expansion.route.onItemFailure === 'all-or-refuse') {\n expansion.stopped = true\n }\n if (advance) await pumpMap(state, expansion)\n else if (expansion.inFlight === 0) {\n await finishMap(state, expansion, 'not started: the manager stopped before this map finished')\n }\n}\n\n// The expansion number of a source's done settle. A settle a prior process committed keeps the\n// number it had there (its rank among the resumed done settles of that node), so a replay\n// re-derives the keys that process journaled. A new settle counts on past every prior settle and\n// every journaled expansion: a root-driven graph replays no prior settle, and its driver may\n// label a worker other than by its node.\nfunction expansionOf(state: MapState, source: string, workerId: string): number {\n const resume = state.opts.scope.resume\n const labels = new Map(resume?.view.nodes.map((node) => [node.id, node.label]) ?? [])\n const prior = (resume?.settled ?? [])\n .filter((s) => s.kind === 'done' && labels.get(s.handle.id) === source)\n .map((s) => s.handle.id)\n const rank = prior.indexOf(workerId)\n if (rank >= 0) return rank + 1\n let journaled = 0\n for (const route of state.mapRoutes) {\n if (route.from !== source) continue\n const prefix = `key:map:${route.edge}#`\n for (const node of resume?.view.nodes ?? []) {\n if (!node.assignmentId?.startsWith(prefix)) continue\n const n = Number.parseInt(node.assignmentId.slice(prefix.length), 10)\n if (Number.isSafeInteger(n)) journaled = Math.max(journaled, n)\n }\n }\n const live = (state.liveExpansions.get(source) ?? 0) + 1\n state.liveExpansions.set(source, live)\n return Math.max(prior.length, journaled) + live\n}\n\n/** The list a map expands over, or the reason no item runs. */\nfunction resolveMapItems(\n state: MapState,\n out: unknown,\n route: MapOnSettleRoute,\n): { readonly items: ReadonlyArray<unknown> } | { readonly refusal: string } {\n const selected = resolveJsonPointer(out, route.pointer)\n if (!selected.found) {\n return {\n refusal: `pointer ${JSON.stringify(route.pointer)} does not resolve in the source result: ${selected.reason}; no item ran`,\n }\n }\n const items = selected.value\n if (!Array.isArray(items)) {\n return {\n refusal: `pointer ${JSON.stringify(route.pointer)} resolves to ${items === null ? 'null' : typeof items}, not an array; no item ran`,\n }\n }\n if (items.length > route.maxItems) {\n return {\n refusal: `max-items-exceeded: the list holds ${items.length} items and this map admits at most ${route.maxItems}; no item ran`,\n }\n }\n const slots = workerSlotBound(state)\n if (slots !== undefined && route.concurrency > slots) {\n return {\n refusal: `concurrency-unsatisfiable: concurrency ${route.concurrency} exceeds this run's ${slots} worker slots, so the cap could never be honored; no item ran`,\n }\n }\n return { items }\n}\n\n// A source settled `done`: expand every map that names it.\nasync function expandMaps(\n state: MapState,\n settled: Settled<unknown>,\n worker: SettledWorker,\n): Promise<void> {\n const { mapRoutes } = state\n if (settled.kind !== 'done' || mapRoutes.length === 0) return\n const name = state.nodeOf(worker.id)\n if (name === undefined || !mapRoutes.some((route) => route.from === name)) return\n const expansion = expansionOf(state, name, worker.id)\n for (const route of mapRoutes) {\n if (route.from !== name) continue\n const resolved = resolveMapItems(state, settled.out, route)\n if ('refusal' in resolved) {\n await publishMap(\n state,\n {\n edge: route.edge,\n phase: 'expand',\n outcome: 'unpropagated',\n sourceWorker: worker.id,\n bytes: 0,\n reason: resolved.refusal,\n },\n true,\n )\n continue\n }\n const { items } = resolved\n await publishMap(state, {\n edge: route.edge,\n phase: 'expand',\n outcome: items.length === 0 ? 'empty' : 'delivered',\n sourceWorker: worker.id,\n bytes: textBytes(items),\n items: items.length,\n ...(items.length === 0 ? { reason: 'the list is empty; the join runs with no results' } : {}),\n })\n await pumpMap(state, {\n route,\n sourceWorker: worker.id,\n expansion,\n items: detachedFrozen(items),\n settlements: [],\n next: 0,\n inFlight: 0,\n stopped: false,\n finished: false,\n })\n }\n}\n\n// Map steps run on the settlement path, which must never be taken down by them.\nasync function runMapStep(\n { opts }: MapState,\n step: () => Promise<void>,\n worker: SettledWorker,\n): Promise<void> {\n try {\n await step()\n } catch (error) {\n console.error('Runtime map step failed', {\n managerId: opts.scope.view.root,\n worker: worker.id,\n error: errMessage(error),\n })\n }\n}\n\n/** What one settle delivered. A settle is usable (`delivered`) when it settled `done`, its\n * deliverable check did not reject it, and its result is defined; maps and routes both read\n * results through this one rule. */\ninterface WorkerSettlement {\n readonly outcome: 'delivered' | 'empty' | 'failed' | 'unpropagated'\n readonly result?: unknown\n readonly reason?: string\n}\n\nexport function workerSettlement(\n settled: Settled<unknown>,\n worker: SettledWorker,\n): WorkerSettlement {\n if (settled.kind !== 'done' || worker.status !== 'done') {\n return { outcome: 'failed', reason: worker.status === 'down' ? worker.reason : 'down' }\n }\n if (worker.valid === false) {\n return { outcome: 'failed', reason: 'its deliverable check rejected the result' }\n }\n if (settled.out === undefined) return { outcome: 'empty', reason: 'it settled with no result' }\n return { outcome: 'delivered', result: settled.out }\n}\n\n/** Resolve an RFC 6901 JSON pointer (`''` is the whole document). */\nexport function resolveJsonPointer(\n document: unknown,\n pointer: string,\n):\n | { readonly found: true; readonly value: unknown }\n | { readonly found: false; readonly reason: string } {\n if (pointer === '') return { found: true, value: document }\n if (!pointer.startsWith('/')) {\n return { found: false, reason: 'a JSON pointer is empty or starts with \"/\"' }\n }\n let value = document\n for (const raw of pointer.slice(1).split('/')) {\n const token = raw.replaceAll('~1', '/').replaceAll('~0', '~')\n if (Array.isArray(value)) {\n if (!/^(0|[1-9]\\d*)$/.test(token) || Number(token) >= value.length) {\n return {\n found: false,\n reason: `no index ${JSON.stringify(token)} in an array of ${value.length}`,\n }\n }\n value = value[Number(token)]\n } else if (typeof value === 'object' && value !== null && Object.hasOwn(value, token)) {\n value = (value as Record<string, unknown>)[token]\n } else {\n return { found: false, reason: `no member ${JSON.stringify(token)}` }\n }\n }\n return { found: true, value }\n}\n"],"mappings":";;;;AAEA,SAAgB,aAAa,OAAwB;CACnD,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI;EACF,OAAO,KAAK,UAAU,KAAK,KAAK,OAAO,KAAK;CAC9C,QAAQ;EACN,OAAO,OAAO,KAAK;CACrB;AACF;;;;;;;ACOA,eAAsB,kBACpB,YACA,OAC8B;CAC9B,KAAK,MAAM,OAAO,CAAC,MAAM,KAAK,GAAG,MAAM,IAAI,GAAG,GAAG;EAC/C,IAAI;EACJ,IAAI;GACF,WAAW,MAAM,WAAW;IAAE,GAAG;IAAO;GAAI,CAAC;EAC/C,SAAS,OAAO;GACd,OAAO,EAAE,SAAS,WAAW,KAAK,EAAE;EACtC;EACA,MAAM,UAAU;EAGhB,IAAI,OAAO,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I;AACrD;;AAGA,SAAgB,mBACd,UACA,SAGqD;CACrD,IAAI,YAAY,IAAI,OAAO;EAAE,OAAO;EAAM,OAAO;CAAS;CAC1D,IAAI,CAAC,QAAQ,WAAW,GAAG,GACzB,OAAO;EAAE,OAAO;EAAO,QAAQ;CAA6C;CAE9E,IAAI,QAAQ;CACZ,KAAK,MAAM,OAAO,QAAQ,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG;EAC7C,MAAM,QAAQ,IAAI,WAAW,MAAM,GAAG,CAAC,CAAC,WAAW,MAAM,GAAG;EAC5D,IAAI,MAAM,QAAQ,KAAK,GAAG;GACxB,IAAI,CAAC,iBAAiB,KAAK,KAAK,KAAK,OAAO,KAAK,KAAK,MAAM,QAC1D,OAAO;IACL,OAAO;IACP,QAAQ,YAAY,KAAK,UAAU,KAAK,EAAE,kBAAkB,MAAM;GACpE;GAEF,QAAQ,MAAM,OAAO,KAAK;EAC5B,OAAO,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAO,OAAO,OAAO,KAAK,GAClF,QAAS,MAAkC;OAE3C,OAAO;GAAE,OAAO;GAAO,QAAQ,aAAa,KAAK,UAAU,KAAK;EAAI;CAExE;CACA,OAAO;EAAE,OAAO;EAAM;CAAM;AAC9B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors-AzSuGI23.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n *\n * Error taxonomy for `@tangle-network/agent-runtime`.\n *\n * Public contract: every error this package throws as part of its consumer-\n * facing API either extends `AgentEvalError` (re-exported here for ergonomic\n * `instanceof` checks at the runtime boundary) or extends one of the\n * runtime-specific subclasses below.\n *\n * Internal invariant guards (`throw new Error('this should never happen')`)\n * remain plain `Error` — they are programmer-mistake assertions, not\n * consumer-catchable contract failures.\n *\n * Subclassing strategy: where a runtime-specific failure maps cleanly to an\n * agent-eval code (validation, config, not_found), we re-use the agent-eval\n * subclass. Runtime-only failure modes (session resume against the wrong\n * backend, backend transport errors) get fresh subclasses that still carry an\n * `AgentEvalErrorCode` so cross-package handlers can pattern-match without\n * importing the runtime.\n *\n * @stable\n */\n\nimport { AgentEvalError } from '@tangle-network/agent-eval'\nimport type {\n AgentInteractiveSessionRef,\n AgentInteractiveSessionStart,\n AgentInteractiveSessionStatus,\n} from '@tangle-network/agent-interface'\nimport type { RuntimeFailureCause } from './runtime/failure-cause'\nimport type {\n RetainedInteractiveAdmission,\n RetainedRunAdmission,\n} from './runtime/retained-run-types'\n\nexport {\n AgentEvalError,\n type AgentEvalErrorCode,\n ConfigError,\n JudgeError,\n NotFoundError,\n ValidationError,\n} from '@tangle-network/agent-eval'\n\n/**\n *\n * Caller asked to resume a session against a backend whose `kind` does not\n * match the session's recorded backend. This is a routing bug — the same\n * session id was reused across two different backend implementations — and\n * is not retryable without picking the right backend.\n *\n * @stable\n */\nexport class SessionMismatchError extends AgentEvalError {\n readonly sessionBackend: string\n readonly requestedBackend: string\n\n constructor(sessionBackend: string, requestedBackend: string, options?: { cause?: unknown }) {\n super(\n 'validation',\n `Cannot resume ${sessionBackend} session with ${requestedBackend} backend`,\n options,\n )\n this.sessionBackend = sessionBackend\n this.requestedBackend = requestedBackend\n }\n}\n\n/**\n *\n * A backend transport call (HTTP, gRPC, sidecar IPC) failed with a non-success\n * status. Distinct from `JudgeError` (which is structural / unrecoverable)\n * because backend failures are sometimes retryable and consumers may want to\n * branch on the upstream status code.\n *\n * @stable\n */\nexport class BackendTransportError extends AgentEvalError {\n readonly backend: string\n readonly status?: number\n /**\n * Router-owned proof that a rejected request never reached a provider.\n *\n * This is intentionally one-sided. An absent value, or any value this\n * package does not understand, remains unknown to Runtime.\n */\n readonly providerDispatch?: 'not_started'\n /**\n * The upstream's own error class when it names one (the bridge's `parse_error`,\n * `not_configured`, a provider's `invalid_request_error`). A class the upstream never\n * retries is a decision about the request, so a retry policy may read it where no\n * status arrived.\n */\n readonly upstreamCode?: string\n /** Validated producer remedy; absent when the upstream supplied no trusted structured remedy. */\n readonly remediation?: RuntimeFailureCause['remediation']\n /**\n * Truncated upstream response body (≤2 KiB) when available. Diagnostic\n * only — surfaces in `backend_error.error.body` and `final.error.body`\n * so operators can see \"free_tier_limit\", \"invalid_api_key\", etc. without\n * cracking the log line open.\n */\n readonly body?: string\n\n constructor(\n backend: string,\n message: string,\n options?: {\n cause?: unknown\n status?: number\n upstreamCode?: string\n remediation?: RuntimeFailureCause['remediation']\n body?: string\n providerDispatch?: 'not_started'\n },\n ) {\n super('config', message, options)\n this.backend = backend\n this.status = options?.status\n this.upstreamCode = options?.upstreamCode\n this.remediation = options?.remediation\n this.body = options?.body\n this.providerDispatch = options?.providerDispatch\n }\n}\n\n/**\n *\n * A runtime-run lifecycle method was called in an order the state machine does\n * not allow: `persist()` before `complete()`, `complete()` twice, etc.\n *\n * @stable\n */\nexport class RuntimeRunStateError extends AgentEvalError {\n constructor(message: string, options?: { cause?: unknown }) {\n super('validation', message, options)\n }\n}\n\n/**\n *\n * The dynamic-loop planner returned an unusable topology move — the LLM emitted\n * no parseable envelope, an unknown `kind`, or a structurally-invalid move\n * (e.g. a fanout with zero tasks). This is a structural failure of the\n * agent-authored topology, not a config mistake: the planner ran but its output\n * cannot drive the kernel. Carries `validation` so cross-package handlers can\n * pattern-match without importing the runtime. Fail loud — never substitute a\n * default move, or the loop silently runs a topology nobody chose.\n *\n * @stable\n */\nexport class PlannerError extends AgentEvalError {\n constructor(message: string, options?: { cause?: unknown }) {\n super('validation', message, options)\n }\n}\n\n/**\n * The analyst loop could not read or run over a round's trace — e.g. an empty round\n * (no iterations to analyze) or a malformed trace projection. Fail loud: a silent empty\n * store would mask a broken capture path and the driver would steer on nothing.\n */\nexport class AnalystError extends AgentEvalError {\n constructor(message: string, options?: { cause?: unknown }) {\n super('validation', message, options)\n }\n}\n\n/**\n *\n * The caller's `onAdmission` durability hook rejected, so a retained run's\n * admission record is not durable. For a pre-create intent, no provider work\n * has started. For a later record, provider state may already be live and the\n * environment remains available for recovery. Carries `capture_integrity`\n * because the required recovery record was not written.\n *\n * @stable\n */\nabstract class RetainedAdmissionError<\n TAdmission extends RetainedRunAdmission | RetainedInteractiveAdmission,\n> extends AgentEvalError {\n readonly phase: TAdmission['phase']\n /** The exact record the hook failed to persist, for direct recovery. */\n readonly admission: TAdmission\n\n constructor(admission: TAdmission, options?: { cause?: unknown }) {\n const recovery =\n admission.phase === 'intent' || admission.phase === 'interactive_intent'\n ? 'no provider work has started'\n : 'the environment is kept for recovery'\n super(\n 'capture_integrity',\n `retained run admission (${admission.phase}) was not persisted; ${recovery}`,\n options,\n )\n this.phase = admission.phase\n this.admission = admission\n }\n}\n\n/** The caller could not persist one detached-run recovery record. @stable */\nexport class RetainedRunAdmissionError extends RetainedAdmissionError<RetainedRunAdmission> {}\n\n/** The caller could not persist one exact interactive-process recovery record. @stable */\nexport class RetainedInteractiveAdmissionError extends RetainedAdmissionError<RetainedInteractiveAdmission> {}\n\n/**\n * A provider returned a valid interactive reference that does not bind to the\n * exact start request, or returned data that could not be parsed as one.\n *\n * The requested start and any valid provider reference are detached snapshots.\n * Malformed provider data is never copied into the error, so the error remains\n * safe to persist while the environment remains available for orphan cleanup.\n *\n * @stable\n */\nexport class RetainedInteractiveBindingError extends AgentEvalError {\n /** The exact native-process start request sent to the provider. */\n readonly requested: AgentInteractiveSessionStart\n /** The valid provider data, when the provider returned a parseable value. */\n readonly returned: {\n readonly ref?: AgentInteractiveSessionRef\n readonly status?: AgentInteractiveSessionStatus\n }\n\n constructor(\n requested: AgentInteractiveSessionStart,\n returned: RetainedInteractiveBindingError['returned'],\n options?: { cause?: unknown },\n ) {\n super(\n 'backend_integrity',\n 'provider returned interactive data that does not bind to the requested start; the environment is kept for diagnosis and cleanup',\n options,\n )\n this.requested = Object.freeze(requested)\n this.returned = Object.freeze(returned)\n }\n}\n\n/**\n *\n * A retained dispatch answered with coordinates that do not bind to the\n * identity the runtime requested, or failed exact verification. The\n * environment-phase admission is already durable at this point, so its\n * coordinates plus the provider reference carried here are the manual\n * recovery path. The environment is intentionally kept. Carries\n * `backend_integrity` because the provider violated its dispatch contract.\n *\n * @stable\n */\nexport class RetainedRunDispatchBindingError extends AgentEvalError {\n /** The coordinates the runtime sent with the dispatch. */\n readonly requested: {\n readonly provider: string\n readonly environmentId: string\n readonly sessionId: string\n readonly executionId: string\n }\n /** The loose reference the provider actually returned, for triage. */\n readonly returned: {\n readonly id?: string\n readonly provider?: string\n readonly controlRef?: unknown\n }\n\n constructor(\n requested: RetainedRunDispatchBindingError['requested'],\n returned: RetainedRunDispatchBindingError['returned'],\n options?: { cause?: unknown },\n ) {\n super(\n 'backend_integrity',\n 'retained dispatch did not bind to the requested identity; the durable environment admission and the returned reference on this error are the recovery path',\n options,\n )\n this.requested = requested\n this.returned = returned\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,IAAa,uBAAb,cAA0C,eAAe;CACvD;CACA;CAEA,YAAY,gBAAwB,kBAA0B,SAA+B;EAC3F,MACE,cACA,iBAAiB,eAAe,gBAAgB,iBAAiB,WACjE,OACF;EACA,KAAK,iBAAiB;EACtB,KAAK,mBAAmB;CAC1B;AACF;;;;;;;;;;AAWA,IAAa,wBAAb,cAA2C,eAAe;CACxD;CACA;;;;;;;CAOA;;;;;;;CAOA;;CAEA;;;;;;;CAOA;CAEA,YACE,SACA,SACA,SAQA;EACA,MAAM,UAAU,SAAS,OAAO;EAChC,KAAK,UAAU;EACf,KAAK,SAAS,SAAS;EACvB,KAAK,eAAe,SAAS;EAC7B,KAAK,cAAc,SAAS;EAC5B,KAAK,OAAO,SAAS;EACrB,KAAK,mBAAmB,SAAS;CACnC;AACF;;;;;;;;AASA,IAAa,uBAAb,cAA0C,eAAe;CACvD,YAAY,SAAiB,SAA+B;EAC1D,MAAM,cAAc,SAAS,OAAO;CACtC;AACF;;;;;;;;;;;;;AAcA,IAAa,eAAb,cAAkC,eAAe;CAC/C,YAAY,SAAiB,SAA+B;EAC1D,MAAM,cAAc,SAAS,O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