pi-loop-graph-sdk 0.2.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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README-zh.md +416 -0
  3. package/README.md +414 -0
  4. package/ROADMAP.md +60 -0
  5. package/dist/adapter/complete-tool.d.ts +3 -0
  6. package/dist/adapter/complete-tool.js +53 -0
  7. package/dist/adapter/debug-log.d.ts +38 -0
  8. package/dist/adapter/debug-log.js +151 -0
  9. package/dist/adapter/extension.d.ts +2 -0
  10. package/dist/adapter/extension.js +11 -0
  11. package/dist/adapter/graph-execution-host.d.ts +73 -0
  12. package/dist/adapter/graph-execution-host.js +181 -0
  13. package/dist/adapter/isolated-graph-session.d.ts +75 -0
  14. package/dist/adapter/isolated-graph-session.js +313 -0
  15. package/dist/adapter/loop-graph-extension.d.ts +96 -0
  16. package/dist/adapter/loop-graph-extension.js +487 -0
  17. package/dist/adapter/mechanism-runtime.d.ts +97 -0
  18. package/dist/adapter/mechanism-runtime.js +670 -0
  19. package/dist/adapter/model-messages.d.ts +17 -0
  20. package/dist/adapter/model-messages.js +11 -0
  21. package/dist/adapter/observability.d.ts +88 -0
  22. package/dist/adapter/observability.js +31 -0
  23. package/dist/adapter/output-contract.d.ts +12 -0
  24. package/dist/adapter/output-contract.js +87 -0
  25. package/dist/adapter/pi-node-context.d.ts +132 -0
  26. package/dist/adapter/pi-node-context.js +619 -0
  27. package/dist/adapter/projection.d.ts +121 -0
  28. package/dist/adapter/projection.js +169 -0
  29. package/dist/adapter/skill-content.d.ts +16 -0
  30. package/dist/adapter/skill-content.js +16 -0
  31. package/dist/advanced.d.ts +32 -0
  32. package/dist/advanced.js +17 -0
  33. package/dist/builders/graph.d.ts +27 -0
  34. package/dist/builders/graph.js +39 -0
  35. package/dist/builders/node.d.ts +8 -0
  36. package/dist/builders/node.js +9 -0
  37. package/dist/builders/refs.d.ts +5 -0
  38. package/dist/builders/refs.js +10 -0
  39. package/dist/builders/route.d.ts +11 -0
  40. package/dist/builders/route.js +18 -0
  41. package/dist/core/context.d.ts +73 -0
  42. package/dist/core/context.js +229 -0
  43. package/dist/core/graph.d.ts +172 -0
  44. package/dist/core/graph.js +57 -0
  45. package/dist/core/json.d.ts +8 -0
  46. package/dist/core/json.js +46 -0
  47. package/dist/core/limits.d.ts +7 -0
  48. package/dist/core/limits.js +14 -0
  49. package/dist/core/mechanism.d.ts +88 -0
  50. package/dist/core/mechanism.js +5 -0
  51. package/dist/core/result.d.ts +41 -0
  52. package/dist/core/result.js +1 -0
  53. package/dist/core/schema.d.ts +8 -0
  54. package/dist/core/schema.js +23 -0
  55. package/dist/core/skill.d.ts +12 -0
  56. package/dist/core/skill.js +1 -0
  57. package/dist/host/baseline.d.ts +11 -0
  58. package/dist/host/baseline.js +4 -0
  59. package/dist/host/graph-catalog.d.ts +8 -0
  60. package/dist/host/graph-catalog.js +24 -0
  61. package/dist/host/graph-host.d.ts +53 -0
  62. package/dist/host/graph-host.js +181 -0
  63. package/dist/host/preflight.d.ts +17 -0
  64. package/dist/host/preflight.js +81 -0
  65. package/dist/host/skill-catalog.d.ts +24 -0
  66. package/dist/host/skill-catalog.js +92 -0
  67. package/dist/host/tool-catalog.d.ts +27 -0
  68. package/dist/host/tool-catalog.js +33 -0
  69. package/dist/index.d.ts +21 -0
  70. package/dist/index.js +10 -0
  71. package/dist/replay/checkpoint.d.ts +40 -0
  72. package/dist/replay/checkpoint.js +57 -0
  73. package/dist/replay/events.d.ts +40 -0
  74. package/dist/replay/events.js +1 -0
  75. package/dist/replay/finalizer.d.ts +26 -0
  76. package/dist/replay/finalizer.js +117 -0
  77. package/dist/replay/html.d.ts +3 -0
  78. package/dist/replay/html.js +270 -0
  79. package/dist/replay/index.d.ts +13 -0
  80. package/dist/replay/index.js +7 -0
  81. package/dist/replay/model.d.ts +81 -0
  82. package/dist/replay/model.js +1 -0
  83. package/dist/replay/parser.d.ts +3 -0
  84. package/dist/replay/parser.js +332 -0
  85. package/dist/replay/recorder.d.ts +30 -0
  86. package/dist/replay/recorder.js +195 -0
  87. package/dist/replay/store.d.ts +41 -0
  88. package/dist/replay/store.js +94 -0
  89. package/dist/router.d.ts +4 -0
  90. package/dist/router.js +61 -0
  91. package/dist/runtime/event-bus.d.ts +101 -0
  92. package/dist/runtime/event-bus.js +18 -0
  93. package/dist/runtime/graph-runtime.d.ts +173 -0
  94. package/dist/runtime/graph-runtime.js +1293 -0
  95. package/dist/runtime/invocation-budget.d.ts +22 -0
  96. package/dist/runtime/invocation-budget.js +52 -0
  97. package/dist/runtime/mechanism-runtime.d.ts +92 -0
  98. package/dist/runtime/mechanism-runtime.js +387 -0
  99. package/dist/runtime.d.ts +91 -0
  100. package/dist/runtime.js +258 -0
  101. package/dist/tools-resolve.d.ts +20 -0
  102. package/dist/tools-resolve.js +52 -0
  103. package/dist/type.d.ts +593 -0
  104. package/dist/type.js +30 -0
  105. package/dist/validate.d.ts +25 -0
  106. package/dist/validate.js +203 -0
  107. package/package.json +69 -0
@@ -0,0 +1,94 @@
1
+ import { createHash } from "node:crypto";
2
+ import { mkdir, readFile, rename, rm, writeFile, appendFile, readdir } from "node:fs/promises";
3
+ import { resolve, join } from "node:path";
4
+ export class FileRunStore {
5
+ rootDir;
6
+ constructor(options = {}) {
7
+ this.rootDir = resolve(typeof options === "string" ? options : (options.rootDir ?? ".loop-graph/runs"));
8
+ }
9
+ location(runId) {
10
+ return this.runDir(runId);
11
+ }
12
+ async appendJournal(runId, line) {
13
+ const dir = this.runDir(runId);
14
+ await mkdir(dir, { recursive: true });
15
+ await appendFile(join(dir, "journal.jsonl"), line.endsWith("\n") ? line : `${line}\n`, "utf8");
16
+ }
17
+ readJournal(runId) {
18
+ return readFile(join(this.runDir(runId), "journal.jsonl"), "utf8");
19
+ }
20
+ async writeArtifact(runId, artifactId, content, mediaType = "application/json") {
21
+ const safeId = safeSegment(artifactId, "artifactId");
22
+ const dir = join(this.runDir(runId), "artifacts");
23
+ await mkdir(dir, { recursive: true });
24
+ await atomicWrite(join(dir, safeId), content);
25
+ return Object.freeze({
26
+ artifactId: safeId,
27
+ mediaType,
28
+ byteSize: Buffer.byteLength(content, "utf8"),
29
+ sha256: createHash("sha256").update(content).digest("hex"),
30
+ });
31
+ }
32
+ readArtifact(runId, artifactId) {
33
+ return readFile(join(this.runDir(runId), "artifacts", safeSegment(artifactId, "artifactId")), "utf8");
34
+ }
35
+ async writeCheckpoint(runId, checkpointId, content) {
36
+ const dir = join(this.runDir(runId), "checkpoints");
37
+ await mkdir(dir, { recursive: true });
38
+ await atomicWrite(join(dir, safeSegment(checkpointId, "checkpointId")), content);
39
+ }
40
+ readCheckpoint(runId, checkpointId) {
41
+ return readFile(join(this.runDir(runId), "checkpoints", safeSegment(checkpointId, "checkpointId")), "utf8");
42
+ }
43
+ async listCheckpoints(runId) {
44
+ try {
45
+ return Object.freeze((await readdir(join(this.runDir(runId), "checkpoints"), { withFileTypes: true }))
46
+ .filter((entry) => entry.isFile())
47
+ .map((entry) => entry.name)
48
+ .sort());
49
+ }
50
+ catch (error) {
51
+ if (error.code === "ENOENT")
52
+ return Object.freeze([]);
53
+ throw error;
54
+ }
55
+ }
56
+ async pruneCheckpoints(runId, keep) {
57
+ const retained = new Set(keep.map((id) => safeSegment(id, "checkpointId")));
58
+ for (const id of await this.listCheckpoints(runId)) {
59
+ if (!retained.has(id))
60
+ await this.deleteCheckpoint(runId, id);
61
+ }
62
+ }
63
+ async deleteCheckpoint(runId, checkpointId) {
64
+ await rm(join(this.runDir(runId), "checkpoints", safeSegment(checkpointId, "checkpointId")), { force: true });
65
+ }
66
+ async writeReplay(runId, content) {
67
+ const dir = this.runDir(runId);
68
+ await mkdir(dir, { recursive: true });
69
+ await atomicWrite(join(dir, "replay.json"), content);
70
+ }
71
+ readReplay(runId) {
72
+ return readFile(join(this.runDir(runId), "replay.json"), "utf8");
73
+ }
74
+ runDir(runId) {
75
+ return join(this.rootDir, safeSegment(runId, "runId"));
76
+ }
77
+ }
78
+ async function atomicWrite(target, content) {
79
+ const temporary = `${target}.${process.pid}.${crypto.randomUUID()}.tmp`;
80
+ await writeFile(temporary, content, "utf8");
81
+ try {
82
+ await rename(temporary, target);
83
+ }
84
+ catch (error) {
85
+ await rm(temporary, { force: true });
86
+ throw error;
87
+ }
88
+ }
89
+ function safeSegment(value, name) {
90
+ if (!/^[A-Za-z0-9._-]+$/.test(value) || value === "." || value === "..") {
91
+ throw new TypeError(`${name} contains unsafe path characters`);
92
+ }
93
+ return value;
94
+ }
@@ -0,0 +1,4 @@
1
+ import type { Edge, NodeRouting, NodeCompletion, AgentInstance } from "./type.js";
2
+ import type { Connection, NodeCompletion as CoreNodeCompletion, Route } from "./core/graph.js";
3
+ export declare function selectConnection(route: Route, completion: CoreNodeCompletion): Promise<Connection | null>;
4
+ export declare function selectEdge(routing: NodeRouting, completion: NodeCompletion, instance: AgentInstance): Promise<Edge | null>;
package/dist/router.js ADDED
@@ -0,0 +1,61 @@
1
+ // ============================================================
2
+ // 路由器 — 单边裁决
3
+ // ============================================================
4
+ export async function selectConnection(route, completion) {
5
+ const matched = [];
6
+ for (const connection of route.connections) {
7
+ try {
8
+ if (!connection.transition.guard || await connection.transition.guard(completion.result)) {
9
+ matched.push(connection);
10
+ }
11
+ }
12
+ catch {
13
+ // A throwing guard does not match.
14
+ }
15
+ }
16
+ return matched[0] ?? null;
17
+ }
18
+ export async function selectEdge(routing, completion, instance) {
19
+ const matched = routing.edges.filter((e) => {
20
+ try {
21
+ return e.guard(completion);
22
+ }
23
+ catch {
24
+ return false;
25
+ }
26
+ });
27
+ if (matched.length === 0)
28
+ return null;
29
+ switch (routing.router.kind) {
30
+ case "first-match":
31
+ return matched[0] ?? null;
32
+ case "priority-first":
33
+ return priorityFirst(matched);
34
+ case "custom":
35
+ return (await routing.router.fn(matched, completion, instance)) ?? null;
36
+ case "agent-choice": {
37
+ // 单边匹配 → 无需 agent 选择,直接返回
38
+ if (matched.length === 1)
39
+ return matched[0];
40
+ // 从 completion.result 读取 agent 声明的边 ID
41
+ const field = routing.agentChoiceField ?? "chosen_edge_id";
42
+ const chosenId = completion.result?.[field];
43
+ if (typeof chosenId === "string") {
44
+ const edge = matched.find((e) => e.id === chosenId);
45
+ if (edge)
46
+ return edge;
47
+ }
48
+ // 防御性降级:正常情况下 upstream validateCompletion 已拦截并让 agent 重试,
49
+ // 此处 priority-first 作为兜底不应该被执行到。
50
+ return priorityFirst(matched);
51
+ }
52
+ default:
53
+ return matched[0] ?? null;
54
+ }
55
+ }
56
+ function priorityFirst(matched) {
57
+ return matched
58
+ .map((edge, index) => ({ edge, index }))
59
+ .sort((a, b) => b.edge.priority - a.edge.priority || a.index - b.index)[0]
60
+ ?.edge ?? null;
61
+ }
@@ -0,0 +1,101 @@
1
+ import type { GraphFailure } from "../core/result.js";
2
+ import type { InvocationBudgetUsage } from "./invocation-budget.js";
3
+ export type RuntimeEvent = {
4
+ readonly type: "root_started";
5
+ readonly rootRunId: string;
6
+ readonly graphId: string;
7
+ readonly graphVersion: string;
8
+ } | {
9
+ readonly type: "host_baseline_selected";
10
+ readonly rootRunId: string;
11
+ readonly baseline: "isolated" | "inherit" | "custom";
12
+ readonly id?: string;
13
+ readonly fingerprint?: string;
14
+ } | {
15
+ readonly type: "root_finished";
16
+ readonly rootRunId: string;
17
+ readonly status: "completed" | "failed" | "cancelled";
18
+ readonly usage: InvocationBudgetUsage;
19
+ } | {
20
+ readonly type: "graph_entered";
21
+ readonly rootRunId: string;
22
+ readonly graphInvocationId: string;
23
+ readonly parentGraphInvocationId?: string;
24
+ readonly graphId: string;
25
+ readonly graphVersion: string;
26
+ readonly boundary: "root" | "call" | "compose" | "delegate";
27
+ readonly depth: number;
28
+ } | {
29
+ readonly type: "graph_exited";
30
+ readonly rootRunId: string;
31
+ readonly graphInvocationId: string;
32
+ readonly status: "completed" | "failed" | "cancelled";
33
+ readonly failure?: GraphFailure;
34
+ } | {
35
+ readonly type: "node_entered";
36
+ readonly rootRunId: string;
37
+ readonly graphInvocationId: string;
38
+ readonly nodeVisitId: string;
39
+ readonly stageId: string;
40
+ readonly visit: number;
41
+ } | {
42
+ readonly type: "node_exited";
43
+ readonly rootRunId: string;
44
+ readonly graphInvocationId: string;
45
+ readonly nodeVisitId: string;
46
+ readonly stageId: string;
47
+ } | {
48
+ readonly type: "agent_started";
49
+ readonly rootRunId: string;
50
+ readonly graphInvocationId: string;
51
+ readonly nodeVisitId: string;
52
+ readonly agentRunId: string;
53
+ readonly index: number;
54
+ } | {
55
+ readonly type: "agent_finished";
56
+ readonly rootRunId: string;
57
+ readonly graphInvocationId: string;
58
+ readonly nodeVisitId: string;
59
+ readonly agentRunId: string;
60
+ } | {
61
+ readonly type: "context_snapshot_materialized";
62
+ readonly rootRunId: string;
63
+ readonly graphInvocationId: string;
64
+ readonly nodeVisitId: string;
65
+ readonly memoryRevision: number;
66
+ readonly layerCount: number;
67
+ } | {
68
+ readonly type: "mechanism_scope_opened" | "mechanism_scope_closed";
69
+ readonly rootRunId: string;
70
+ readonly graphInvocationId?: string;
71
+ readonly nodeVisitId?: string;
72
+ readonly installation: "host" | "graph" | "node";
73
+ readonly count: number;
74
+ } | {
75
+ readonly type: "transition_selected";
76
+ readonly rootRunId: string;
77
+ readonly graphInvocationId: string;
78
+ readonly nodeVisitId: string;
79
+ readonly stageId: string;
80
+ readonly connectionId: string;
81
+ readonly target: string;
82
+ } | {
83
+ readonly type: "checkpoint_saved";
84
+ readonly rootRunId: string;
85
+ readonly graphInvocationId: string;
86
+ readonly checkpointId: string;
87
+ readonly nextStageId: string;
88
+ } | {
89
+ readonly type: "runtime_warning";
90
+ readonly rootRunId: string;
91
+ readonly graphInvocationId?: string;
92
+ readonly stageId?: string;
93
+ readonly code: "unsafe-tool-policy-bypass" | "unsafe-host-baseline" | "unmanaged-mechanism-access";
94
+ readonly message: string;
95
+ };
96
+ export type RuntimeEventListener = (event: RuntimeEvent) => void;
97
+ export declare class RuntimeEventBus {
98
+ private readonly listeners;
99
+ subscribe(listener: RuntimeEventListener): () => void;
100
+ emit(event: RuntimeEvent): void;
101
+ }
@@ -0,0 +1,18 @@
1
+ export class RuntimeEventBus {
2
+ listeners = new Set();
3
+ subscribe(listener) {
4
+ this.listeners.add(listener);
5
+ return () => this.listeners.delete(listener);
6
+ }
7
+ emit(event) {
8
+ const frozen = Object.freeze({ ...event });
9
+ for (const listener of this.listeners) {
10
+ try {
11
+ listener(frozen);
12
+ }
13
+ catch {
14
+ // Runtime fact observers cannot change control flow.
15
+ }
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,173 @@
1
+ import type { TSchema } from "typebox";
2
+ import type { AgentNodeDefinition, AgentRunRequest, CodeNodeDefinition, Graph, GraphRef, SchemaValue } from "../core/graph.js";
3
+ import type { InvocationLimits } from "../core/limits.js";
4
+ import type { GraphFailure, GraphRunResult } from "../core/result.js";
5
+ import type { JsonValue } from "../core/json.js";
6
+ import type { Mechanism, MechanismCompletionDecision } from "../core/mechanism.js";
7
+ import { type ContextSnapshot } from "../core/context.js";
8
+ import type { ResolvedSkillView } from "../core/skill.js";
9
+ import type { GraphCatalog } from "../host/graph-catalog.js";
10
+ import type { HostBaseline } from "../host/baseline.js";
11
+ import type { SkillCatalog } from "../host/skill-catalog.js";
12
+ import { type ToolCatalog, type ToolImplementation, type UnsafeToolResolver } from "../host/tool-catalog.js";
13
+ import { RuntimeEventBus } from "./event-bus.js";
14
+ import { InvocationBudget } from "./invocation-budget.js";
15
+ import { type MechanismChain, type MechanismRuntimeOptions } from "./mechanism-runtime.js";
16
+ import type { CheckpointStore } from "../replay/store.js";
17
+ export type InvocationBoundary = "root" | "call" | "compose" | "delegate";
18
+ export interface RootRunState {
19
+ readonly rootRunId: string;
20
+ readonly startedAt: number;
21
+ readonly budget: InvocationBudget;
22
+ readonly signal?: AbortSignal;
23
+ readonly baseline: HostBaseline;
24
+ }
25
+ export interface GraphInvocationState {
26
+ readonly graphInvocationId: string;
27
+ readonly rootRunId: string;
28
+ readonly parentGraphInvocationId?: string;
29
+ readonly graph: GraphRef;
30
+ readonly boundary: InvocationBoundary;
31
+ readonly depth: number;
32
+ readonly frames: JsonValue[];
33
+ readonly frameRevision: {
34
+ value: number;
35
+ };
36
+ }
37
+ export interface NodeVisitState {
38
+ readonly nodeVisitId: string;
39
+ readonly rootRunId: string;
40
+ readonly graphInvocationId: string;
41
+ readonly stageId: string;
42
+ readonly visit: number;
43
+ }
44
+ export interface AgentRunState {
45
+ readonly agentRunId: string;
46
+ readonly rootRunId: string;
47
+ readonly graphInvocationId: string;
48
+ readonly nodeVisitId: string;
49
+ readonly index: number;
50
+ }
51
+ export interface AgentExecutionContext {
52
+ readonly root: RootRunState;
53
+ readonly invocation: GraphInvocationState;
54
+ readonly nodeVisit: NodeVisitState;
55
+ readonly agentRun: AgentRunState;
56
+ readonly tools: readonly ToolImplementation[];
57
+ readonly skills: readonly ResolvedSkillView[];
58
+ readonly baseline: HostBaseline;
59
+ readonly snapshot: ContextSnapshot;
60
+ readonly mechanisms?: MechanismChain;
61
+ validateNodeCompletion(result: JsonValue): Promise<{
62
+ readonly valid: boolean;
63
+ readonly reason?: string;
64
+ }>;
65
+ validateRouteStructure(result: JsonValue): Promise<{
66
+ readonly valid: boolean;
67
+ readonly reason?: string;
68
+ }>;
69
+ validateMechanismCompletion(result: JsonValue): Promise<MechanismCompletionDecision>;
70
+ validateAgentChoice(result: JsonValue): Promise<{
71
+ readonly valid: boolean;
72
+ readonly reason?: string;
73
+ }>;
74
+ invokeGraph(ref: GraphRef, input: JsonValue, boundary?: Exclude<InvocationBoundary, "root">): Promise<InvocationOutcome>;
75
+ }
76
+ export interface DelegateGraphRequest {
77
+ readonly graph: Graph;
78
+ readonly input: JsonValue;
79
+ readonly root: RootRunState;
80
+ readonly parentInvocation: GraphInvocationState;
81
+ readonly execute: () => Promise<InvocationOutcome>;
82
+ }
83
+ export interface InvocationAgentHost {
84
+ runAgent?: GraphRuntimeHost["runAgent"];
85
+ runAgentFromCode?: GraphRuntimeHost["runAgentFromCode"];
86
+ dispose(): void | Promise<void>;
87
+ }
88
+ export interface InvocationAgentHostRequest {
89
+ readonly root: RootRunState;
90
+ readonly invocation: GraphInvocationState;
91
+ }
92
+ export interface GraphRuntimeHost {
93
+ /** Hard upper bound; per-run limits may only reduce these values. */
94
+ readonly limits?: InvocationLimits;
95
+ readonly catalog?: GraphCatalog;
96
+ readonly eventBus?: RuntimeEventBus;
97
+ readonly toolCatalog?: ToolCatalog;
98
+ readonly skillCatalog?: SkillCatalog;
99
+ readonly unsafeToolResolver?: UnsafeToolResolver;
100
+ readonly protocolTools?: readonly ToolImplementation[];
101
+ readonly baseline?: HostBaseline;
102
+ /** Maximum UTF-8 bytes of canonical sticky context allowed before an Agent Run. */
103
+ readonly maxStickyContextBytes?: number;
104
+ readonly mechanisms?: readonly Mechanism[];
105
+ readonly mechanismRuntime?: MechanismRuntimeOptions;
106
+ /** Store for persisting node-boundary checkpoints. */
107
+ readonly checkpointStore?: CheckpointStore;
108
+ runAgent?(node: AgentNodeDefinition, input: JsonValue, context: AgentExecutionContext): Promise<JsonValue>;
109
+ runAgentFromCode?(request: AgentRunRequest, node: CodeNodeDefinition, context: AgentExecutionContext): Promise<JsonValue>;
110
+ resolveGraph?(ref: GraphRef): Graph | undefined;
111
+ delegateGraph?(request: DelegateGraphRequest): Promise<InvocationOutcome>;
112
+ /** Creates an Agent execution lane for one call/compose Graph Invocation. */
113
+ createInvocationAgentHost?(request: InvocationAgentHostRequest): Promise<InvocationAgentHost>;
114
+ }
115
+ /** Lets an Agent host terminate execution with a stable Runtime failure. */
116
+ export declare class AgentExecutionFailure extends Error {
117
+ readonly failure: GraphFailure;
118
+ constructor(failure: GraphFailure);
119
+ }
120
+ export interface GraphExecutionOptions {
121
+ readonly limits?: Partial<InvocationLimits>;
122
+ readonly signal?: AbortSignal;
123
+ readonly maxSteps?: number;
124
+ }
125
+ export interface InvocationOutcome {
126
+ readonly status: "completed" | "failed" | "cancelled";
127
+ readonly output?: JsonValue;
128
+ readonly failure?: GraphFailure;
129
+ }
130
+ export declare class GraphRuntime {
131
+ private readonly host;
132
+ readonly eventBus: RuntimeEventBus;
133
+ private readonly mechanismRuns;
134
+ private readonly invocationAgentHosts;
135
+ private readonly activeInvocations;
136
+ private readonly activeGraphMechanisms;
137
+ constructor(host?: GraphRuntimeHost);
138
+ execute<TInputSchema extends TSchema, TOutputSchema extends TSchema>(graph: Graph<TInputSchema, TOutputSchema>, input: SchemaValue<TInputSchema>, options?: number | GraphExecutionOptions): Promise<GraphRunResult<SchemaValue<TOutputSchema>>>;
139
+ private runInvocation;
140
+ private exitInvocation;
141
+ private executeNode;
142
+ private runAgent;
143
+ private runCodeAgent;
144
+ private beginAgent;
145
+ private finishAgent;
146
+ private createAgentContext;
147
+ private assertStickyContextBudget;
148
+ private executeGraphNode;
149
+ private invokeGraph;
150
+ private validateGraphTools;
151
+ private resolveNodeCapabilities;
152
+ private resolveSkills;
153
+ private resolveGraph;
154
+ private buildInvocationStack;
155
+ private writeNodeCheckpoint;
156
+ /** Resume a root graph run from the latest checkpoint. */
157
+ resume<TInputSchema extends TSchema, TOutputSchema extends TSchema>(graph: Graph<TInputSchema, TOutputSchema>, options: {
158
+ readonly runId: string;
159
+ readonly signal?: AbortSignal;
160
+ readonly checkpointMigrator?: (saved: {
161
+ readonly id: string;
162
+ readonly version: string;
163
+ }) => {
164
+ readonly id: string;
165
+ readonly version: string;
166
+ };
167
+ readonly maxSteps?: number;
168
+ }): Promise<GraphRunResult<SchemaValue<TOutputSchema>>>;
169
+ private resumeFromCheckpoint;
170
+ private executeNodeWithResume;
171
+ private assertNotCancelled;
172
+ private validateSchemaBoundary;
173
+ }