@framers/agentos 0.1.69 → 0.1.70
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/api/agent.d.ts +98 -2
- package/dist/api/agent.d.ts.map +1 -1
- package/dist/api/agent.js +64 -9
- package/dist/api/agent.js.map +1 -1
- package/dist/api/generateImage.d.ts +109 -0
- package/dist/api/generateImage.d.ts.map +1 -0
- package/dist/api/generateImage.js +41 -0
- package/dist/api/generateImage.js.map +1 -0
- package/dist/api/generateText.d.ts +73 -3
- package/dist/api/generateText.d.ts.map +1 -1
- package/dist/api/generateText.js +29 -4
- package/dist/api/generateText.js.map +1 -1
- package/dist/api/model.d.ts +74 -4
- package/dist/api/model.d.ts.map +1 -1
- package/dist/api/model.js +79 -5
- package/dist/api/model.js.map +1 -1
- package/dist/api/streamText.d.ts +37 -1
- package/dist/api/streamText.d.ts.map +1 -1
- package/dist/api/streamText.js +188 -49
- package/dist/api/streamText.js.map +1 -1
- package/dist/api/toolAdapter.d.ts +58 -0
- package/dist/api/toolAdapter.d.ts.map +1 -0
- package/dist/api/{tool-adapter.js → toolAdapter.js} +24 -2
- package/dist/api/toolAdapter.js.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/orchestration/builders/AgentGraph.d.ts +250 -0
- package/dist/orchestration/builders/AgentGraph.d.ts.map +1 -0
- package/dist/orchestration/builders/AgentGraph.js +338 -0
- package/dist/orchestration/builders/AgentGraph.js.map +1 -0
- package/dist/orchestration/builders/MissionBuilder.d.ts +231 -0
- package/dist/orchestration/builders/MissionBuilder.d.ts.map +1 -0
- package/dist/orchestration/builders/MissionBuilder.js +321 -0
- package/dist/orchestration/builders/MissionBuilder.js.map +1 -0
- package/dist/orchestration/builders/WorkflowBuilder.d.ts +265 -0
- package/dist/orchestration/builders/WorkflowBuilder.d.ts.map +1 -0
- package/dist/orchestration/builders/WorkflowBuilder.js +472 -0
- package/dist/orchestration/builders/WorkflowBuilder.js.map +1 -0
- package/dist/orchestration/builders/index.d.ts +7 -0
- package/dist/orchestration/builders/index.d.ts.map +1 -0
- package/dist/orchestration/builders/index.js +5 -0
- package/dist/orchestration/builders/index.js.map +1 -0
- package/dist/orchestration/builders/nodes.d.ts +36 -0
- package/dist/orchestration/builders/nodes.d.ts.map +1 -0
- package/dist/orchestration/builders/nodes.js +98 -0
- package/dist/orchestration/builders/nodes.js.map +1 -0
- package/dist/orchestration/checkpoint/ICheckpointStore.d.ts +152 -0
- package/dist/orchestration/checkpoint/ICheckpointStore.d.ts.map +1 -0
- package/dist/orchestration/checkpoint/ICheckpointStore.js +8 -0
- package/dist/orchestration/checkpoint/ICheckpointStore.js.map +1 -0
- package/dist/orchestration/checkpoint/InMemoryCheckpointStore.d.ts +89 -0
- package/dist/orchestration/checkpoint/InMemoryCheckpointStore.d.ts.map +1 -0
- package/dist/orchestration/checkpoint/InMemoryCheckpointStore.js +156 -0
- package/dist/orchestration/checkpoint/InMemoryCheckpointStore.js.map +1 -0
- package/dist/orchestration/checkpoint/index.d.ts +10 -0
- package/dist/orchestration/checkpoint/index.d.ts.map +1 -0
- package/dist/orchestration/checkpoint/index.js +10 -0
- package/dist/orchestration/checkpoint/index.js.map +1 -0
- package/dist/orchestration/compiler/GraphCompiler.d.ts +85 -0
- package/dist/orchestration/compiler/GraphCompiler.d.ts.map +1 -0
- package/dist/orchestration/compiler/GraphCompiler.js +71 -0
- package/dist/orchestration/compiler/GraphCompiler.js.map +1 -0
- package/dist/orchestration/compiler/MissionCompiler.d.ts +181 -0
- package/dist/orchestration/compiler/MissionCompiler.d.ts.map +1 -0
- package/dist/orchestration/compiler/MissionCompiler.js +219 -0
- package/dist/orchestration/compiler/MissionCompiler.js.map +1 -0
- package/dist/orchestration/compiler/SchemaLowering.d.ts +37 -0
- package/dist/orchestration/compiler/SchemaLowering.d.ts.map +1 -0
- package/dist/orchestration/compiler/SchemaLowering.js +95 -0
- package/dist/orchestration/compiler/SchemaLowering.js.map +1 -0
- package/dist/orchestration/compiler/Validator.d.ts +61 -0
- package/dist/orchestration/compiler/Validator.d.ts.map +1 -0
- package/dist/orchestration/compiler/Validator.js +96 -0
- package/dist/orchestration/compiler/Validator.js.map +1 -0
- package/dist/orchestration/compiler/index.d.ts +16 -0
- package/dist/orchestration/compiler/index.d.ts.map +1 -0
- package/dist/orchestration/compiler/index.js +13 -0
- package/dist/orchestration/compiler/index.js.map +1 -0
- package/dist/orchestration/events/GraphEvent.d.ts +233 -0
- package/dist/orchestration/events/GraphEvent.d.ts.map +1 -0
- package/dist/orchestration/events/GraphEvent.js +203 -0
- package/dist/orchestration/events/GraphEvent.js.map +1 -0
- package/dist/orchestration/events/index.d.ts +2 -0
- package/dist/orchestration/events/index.d.ts.map +1 -0
- package/dist/orchestration/events/index.js +2 -0
- package/dist/orchestration/events/index.js.map +1 -0
- package/dist/orchestration/index.d.ts +20 -0
- package/dist/orchestration/index.d.ts.map +1 -0
- package/dist/orchestration/index.js +26 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/orchestration/ir/index.d.ts +2 -0
- package/dist/orchestration/ir/index.d.ts.map +1 -0
- package/dist/orchestration/ir/index.js +2 -0
- package/dist/orchestration/ir/index.js.map +1 -0
- package/dist/orchestration/ir/types.d.ts +540 -0
- package/dist/orchestration/ir/types.d.ts.map +1 -0
- package/dist/orchestration/ir/types.js +20 -0
- package/dist/orchestration/ir/types.js.map +1 -0
- package/dist/orchestration/runtime/GraphRuntime.d.ts +135 -0
- package/dist/orchestration/runtime/GraphRuntime.d.ts.map +1 -0
- package/dist/orchestration/runtime/GraphRuntime.js +381 -0
- package/dist/orchestration/runtime/GraphRuntime.js.map +1 -0
- package/dist/orchestration/runtime/LoopController.d.ts +173 -0
- package/dist/orchestration/runtime/LoopController.d.ts.map +1 -0
- package/dist/orchestration/runtime/LoopController.js +130 -0
- package/dist/orchestration/runtime/LoopController.js.map +1 -0
- package/dist/orchestration/runtime/NodeExecutor.d.ts +206 -0
- package/dist/orchestration/runtime/NodeExecutor.d.ts.map +1 -0
- package/dist/orchestration/runtime/NodeExecutor.js +227 -0
- package/dist/orchestration/runtime/NodeExecutor.js.map +1 -0
- package/dist/orchestration/runtime/NodeScheduler.d.ts +85 -0
- package/dist/orchestration/runtime/NodeScheduler.d.ts.map +1 -0
- package/dist/orchestration/runtime/NodeScheduler.js +180 -0
- package/dist/orchestration/runtime/NodeScheduler.js.map +1 -0
- package/dist/orchestration/runtime/StateManager.d.ts +122 -0
- package/dist/orchestration/runtime/StateManager.d.ts.map +1 -0
- package/dist/orchestration/runtime/StateManager.js +243 -0
- package/dist/orchestration/runtime/StateManager.js.map +1 -0
- package/dist/orchestration/runtime/index.d.ts +16 -0
- package/dist/orchestration/runtime/index.d.ts.map +1 -0
- package/dist/orchestration/runtime/index.js +13 -0
- package/dist/orchestration/runtime/index.js.map +1 -0
- package/package.json +10 -4
- package/dist/api/tool-adapter.d.ts +0 -12
- package/dist/api/tool-adapter.d.ts.map +0 -1
- package/dist/api/tool-adapter.js.map +0 -1
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file ICheckpointStore.ts
|
|
3
|
+
* @description Checkpoint persistence interface and related types for the AgentOS
|
|
4
|
+
* Unified Orchestration Layer. Checkpoints capture a full snapshot of graph execution
|
|
5
|
+
* state so that interrupted runs can be resumed or forked from any saved point.
|
|
6
|
+
*/
|
|
7
|
+
import type { CheckpointMetadata, DiagnosticsView, EffectClass, GraphState } from '../ir/types.js';
|
|
8
|
+
export type { CheckpointMetadata } from '../ir/types.js';
|
|
9
|
+
/**
|
|
10
|
+
* A complete, serialisable snapshot of a graph run captured at a node boundary.
|
|
11
|
+
*
|
|
12
|
+
* The store persists one `Checkpoint` per `save()` call and makes them queryable
|
|
13
|
+
* by `runId` (latest or by `nodeId`) so the runtime can restore execution state
|
|
14
|
+
* after a crash or perform time-travel debugging.
|
|
15
|
+
*/
|
|
16
|
+
export interface Checkpoint {
|
|
17
|
+
/** Unique checkpoint identifier (UUIDv4 assigned by the runtime). */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Id of the `CompiledExecutionGraph` being executed. */
|
|
20
|
+
graphId: string;
|
|
21
|
+
/** Id of the graph run that produced this checkpoint. */
|
|
22
|
+
runId: string;
|
|
23
|
+
/** Id of the node at whose boundary this checkpoint was captured. */
|
|
24
|
+
nodeId: string;
|
|
25
|
+
/** Unix epoch milliseconds when the checkpoint was persisted. */
|
|
26
|
+
timestamp: number;
|
|
27
|
+
/**
|
|
28
|
+
* Serialised `GraphState` partitions captured at the checkpoint boundary.
|
|
29
|
+
* `memory` is excluded because it is always rehydrated fresh on resume.
|
|
30
|
+
*/
|
|
31
|
+
state: {
|
|
32
|
+
/** The original user-provided input frozen at graph start. */
|
|
33
|
+
input: unknown;
|
|
34
|
+
/** Node-to-node communication bag value at the checkpoint boundary. */
|
|
35
|
+
scratch: unknown;
|
|
36
|
+
/** Accumulated external outputs at the checkpoint boundary. */
|
|
37
|
+
artifacts: unknown;
|
|
38
|
+
/** Accumulated diagnostic telemetry up to this checkpoint. */
|
|
39
|
+
diagnostics: DiagnosticsView;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Optional snapshot of the memory subsystem state at this checkpoint.
|
|
43
|
+
* When present the runtime can restore memory context without re-reading from the store.
|
|
44
|
+
*/
|
|
45
|
+
memorySnapshot?: {
|
|
46
|
+
/** Memory traces that were read before or during the checkpointed node. */
|
|
47
|
+
reads: Array<{
|
|
48
|
+
/** Trace identifier in the memory store. */
|
|
49
|
+
traceId: string;
|
|
50
|
+
/** Textual content of the trace. */
|
|
51
|
+
content: string;
|
|
52
|
+
/** Consolidation strength in range 0–1. */
|
|
53
|
+
strength: number;
|
|
54
|
+
}>;
|
|
55
|
+
/** Writes that were staged but not yet committed when the checkpoint was taken. */
|
|
56
|
+
pendingWrites: Array<{
|
|
57
|
+
/** Memory trace category (matches `MemoryTraceType`). */
|
|
58
|
+
type: string;
|
|
59
|
+
/** Textual content to be written. */
|
|
60
|
+
content: string;
|
|
61
|
+
/** Visibility scope (matches `MemoryScope`). */
|
|
62
|
+
scope: string;
|
|
63
|
+
}>;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Results from every node that completed execution before this checkpoint was taken.
|
|
67
|
+
* Keyed by node id.
|
|
68
|
+
*/
|
|
69
|
+
nodeResults: Record<string, {
|
|
70
|
+
/** The node's declared effect class. */
|
|
71
|
+
effectClass: EffectClass;
|
|
72
|
+
/** The output value produced by the node. */
|
|
73
|
+
output: unknown;
|
|
74
|
+
/** Wall-clock execution time in milliseconds. */
|
|
75
|
+
durationMs: number;
|
|
76
|
+
}>;
|
|
77
|
+
/** Ordered list of node ids that had completed execution when this checkpoint was taken. */
|
|
78
|
+
visitedNodes: string[];
|
|
79
|
+
/** Ids of edges that had been emitted but whose target nodes had not yet started. */
|
|
80
|
+
pendingEdges: string[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Persistence contract for checkpoint snapshots.
|
|
84
|
+
*
|
|
85
|
+
* Implementations may back this with in-memory maps (for testing / ephemeral runs),
|
|
86
|
+
* SQLite / Postgres rows, object storage blobs, or any other durable medium.
|
|
87
|
+
*
|
|
88
|
+
* All methods are async to accommodate I/O-bound backends without interface changes.
|
|
89
|
+
*/
|
|
90
|
+
export interface ICheckpointStore {
|
|
91
|
+
/**
|
|
92
|
+
* Persist a checkpoint snapshot.
|
|
93
|
+
*
|
|
94
|
+
* If a checkpoint with the same `id` already exists it is overwritten.
|
|
95
|
+
*
|
|
96
|
+
* @param checkpoint - The snapshot to persist.
|
|
97
|
+
*/
|
|
98
|
+
save(checkpoint: Checkpoint): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Load a checkpoint for the given `runId`.
|
|
101
|
+
*
|
|
102
|
+
* When `nodeId` is supplied, returns the most recent checkpoint for that specific
|
|
103
|
+
* node within the run. When `nodeId` is omitted, returns the most recent checkpoint
|
|
104
|
+
* for the run regardless of node (equivalent to `latest(runId)`).
|
|
105
|
+
*
|
|
106
|
+
* @param runId - The graph run identifier.
|
|
107
|
+
* @param nodeId - Optional node filter.
|
|
108
|
+
* @returns The matching checkpoint, or `null` when none exists.
|
|
109
|
+
*/
|
|
110
|
+
load(runId: string, nodeId?: string): Promise<Checkpoint | null>;
|
|
111
|
+
/**
|
|
112
|
+
* Return the most recently persisted checkpoint for a run, or `null` when the run
|
|
113
|
+
* has no checkpoints.
|
|
114
|
+
*
|
|
115
|
+
* @param runId - The graph run identifier.
|
|
116
|
+
*/
|
|
117
|
+
latest(runId: string): Promise<Checkpoint | null>;
|
|
118
|
+
/**
|
|
119
|
+
* List lightweight metadata descriptors for all checkpoints belonging to a graph.
|
|
120
|
+
*
|
|
121
|
+
* @param graphId - The compiled graph identifier.
|
|
122
|
+
* @param options.runId - Optional filter to a single run within the graph.
|
|
123
|
+
* @param options.limit - Maximum number of entries to return (most-recent-first).
|
|
124
|
+
* @returns Array of `CheckpointMetadata`, sorted by `timestamp` descending.
|
|
125
|
+
*/
|
|
126
|
+
list(graphId: string, options?: {
|
|
127
|
+
limit?: number;
|
|
128
|
+
runId?: string;
|
|
129
|
+
}): Promise<CheckpointMetadata[]>;
|
|
130
|
+
/**
|
|
131
|
+
* Permanently remove a checkpoint from the store.
|
|
132
|
+
*
|
|
133
|
+
* Silently succeeds when `checkpointId` does not exist.
|
|
134
|
+
*
|
|
135
|
+
* @param checkpointId - The checkpoint to remove.
|
|
136
|
+
*/
|
|
137
|
+
delete(checkpointId: string): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Create a new run branching from an existing checkpoint.
|
|
140
|
+
*
|
|
141
|
+
* The operation deep-clones the source checkpoint, assigns a fresh `runId` and
|
|
142
|
+
* checkpoint `id`, applies any `patchState` overrides, persists the new checkpoint,
|
|
143
|
+
* and returns the new `runId`.
|
|
144
|
+
*
|
|
145
|
+
* @param checkpointId - The checkpoint to fork from.
|
|
146
|
+
* @param patchState - Optional partial `GraphState` overrides applied after cloning.
|
|
147
|
+
* @returns The new `runId` for the forked run.
|
|
148
|
+
* @throws When `checkpointId` does not exist.
|
|
149
|
+
*/
|
|
150
|
+
fork(checkpointId: string, patchState?: Partial<GraphState>): Promise<string>;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=ICheckpointStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ICheckpointStore.d.ts","sourceRoot":"","sources":["../../../src/orchestration/checkpoint/ICheckpointStore.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGnG,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAMzD;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAC;IACX,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,iEAAiE;IACjE,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,KAAK,EAAE;QACL,8DAA8D;QAC9D,KAAK,EAAE,OAAO,CAAC;QACf,uEAAuE;QACvE,OAAO,EAAE,OAAO,CAAC;QACjB,+DAA+D;QAC/D,SAAS,EAAE,OAAO,CAAC;QACnB,8DAA8D;QAC9D,WAAW,EAAE,eAAe,CAAC;KAC9B,CAAC;IAEF;;;OAGG;IACH,cAAc,CAAC,EAAE;QACf,2EAA2E;QAC3E,KAAK,EAAE,KAAK,CAAC;YACX,4CAA4C;YAC5C,OAAO,EAAE,MAAM,CAAC;YAChB,oCAAoC;YACpC,OAAO,EAAE,MAAM,CAAC;YAChB,2CAA2C;YAC3C,QAAQ,EAAE,MAAM,CAAC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ACH,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC/E"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file ICheckpointStore.ts
|
|
3
|
+
* @description Checkpoint persistence interface and related types for the AgentOS
|
|
4
|
+
* Unified Orchestration Layer. Checkpoints capture a full snapshot of graph execution
|
|
5
|
+
* state so that interrupted runs can be resumed or forked from any saved point.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=ICheckpointStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ICheckpointStore.js","sourceRoot":"","sources":["../../../src/orchestration/checkpoint/ICheckpointStore.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file InMemoryCheckpointStore.ts
|
|
3
|
+
* @description In-memory implementation of `ICheckpointStore` backed by a `Map<string, Checkpoint>`.
|
|
4
|
+
*
|
|
5
|
+
* Intended for unit tests, local development, and ephemeral graph runs where durability is
|
|
6
|
+
* not required. All data is lost when the process exits.
|
|
7
|
+
*
|
|
8
|
+
* Thread-safety note: Node.js is single-threaded so no explicit locking is needed, but callers
|
|
9
|
+
* should be aware that concurrent async operations on the same store instance may interleave.
|
|
10
|
+
*/
|
|
11
|
+
import type { GraphState } from '../ir/types.js';
|
|
12
|
+
import type { Checkpoint, CheckpointMetadata, ICheckpointStore } from './ICheckpointStore.js';
|
|
13
|
+
/**
|
|
14
|
+
* In-memory `ICheckpointStore` implementation.
|
|
15
|
+
*
|
|
16
|
+
* All checkpoints are stored in a `Map` keyed by checkpoint `id`. Scans are O(n) over
|
|
17
|
+
* the number of stored checkpoints — acceptable for test workloads; a production store
|
|
18
|
+
* should use indexed secondary keys (runId, graphId).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const store = new InMemoryCheckpointStore();
|
|
23
|
+
* await store.save(checkpoint);
|
|
24
|
+
* const restored = await store.latest(runId);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class InMemoryCheckpointStore implements ICheckpointStore {
|
|
28
|
+
/** Primary storage map — checkpoint.id → Checkpoint. */
|
|
29
|
+
private readonly _checkpoints;
|
|
30
|
+
/**
|
|
31
|
+
* Persist a checkpoint snapshot.
|
|
32
|
+
*
|
|
33
|
+
* Overwrites any existing entry with the same `id`.
|
|
34
|
+
*
|
|
35
|
+
* {@inheritDoc ICheckpointStore.save}
|
|
36
|
+
*/
|
|
37
|
+
save(checkpoint: Checkpoint): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Load a checkpoint for the given `runId`.
|
|
40
|
+
*
|
|
41
|
+
* Scans the full store filtering by `runId` and optionally `nodeId`. When multiple
|
|
42
|
+
* checkpoints match, returns the one with the highest `timestamp`.
|
|
43
|
+
*
|
|
44
|
+
* {@inheritDoc ICheckpointStore.load}
|
|
45
|
+
*/
|
|
46
|
+
load(runId: string, nodeId?: string): Promise<Checkpoint | null>;
|
|
47
|
+
/**
|
|
48
|
+
* Return the most recently persisted checkpoint for a run.
|
|
49
|
+
*
|
|
50
|
+
* Equivalent to `load(runId)` with no `nodeId` filter.
|
|
51
|
+
*
|
|
52
|
+
* {@inheritDoc ICheckpointStore.latest}
|
|
53
|
+
*/
|
|
54
|
+
latest(runId: string): Promise<Checkpoint | null>;
|
|
55
|
+
/**
|
|
56
|
+
* List lightweight metadata for all checkpoints belonging to a graph.
|
|
57
|
+
*
|
|
58
|
+
* Results are sorted by `timestamp` descending (most recent first). When
|
|
59
|
+
* `options.limit` is set, only the first `limit` entries are returned after sorting.
|
|
60
|
+
*
|
|
61
|
+
* {@inheritDoc ICheckpointStore.list}
|
|
62
|
+
*/
|
|
63
|
+
list(graphId: string, options?: {
|
|
64
|
+
limit?: number;
|
|
65
|
+
runId?: string;
|
|
66
|
+
}): Promise<CheckpointMetadata[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Permanently remove a checkpoint from the store.
|
|
69
|
+
*
|
|
70
|
+
* Silently succeeds when `checkpointId` does not exist.
|
|
71
|
+
*
|
|
72
|
+
* {@inheritDoc ICheckpointStore.delete}
|
|
73
|
+
*/
|
|
74
|
+
delete(checkpointId: string): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Create a new run branching from an existing checkpoint.
|
|
77
|
+
*
|
|
78
|
+
* Steps:
|
|
79
|
+
* 1. Loads the source checkpoint (throws if missing).
|
|
80
|
+
* 2. Deep-clones via `structuredClone`.
|
|
81
|
+
* 3. Assigns a fresh `runId` and `id` via `crypto.randomUUID()`.
|
|
82
|
+
* 4. Applies `patchState` overrides via `Object.assign` on each state partition.
|
|
83
|
+
* 5. Saves the forked checkpoint and returns the new `runId`.
|
|
84
|
+
*
|
|
85
|
+
* {@inheritDoc ICheckpointStore.fork}
|
|
86
|
+
*/
|
|
87
|
+
fork(checkpointId: string, patchState?: Partial<GraphState>): Promise<string>;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=InMemoryCheckpointStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryCheckpointStore.d.ts","sourceRoot":"","sources":["../../../src/orchestration/checkpoint/InMemoryCheckpointStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAuB9F;;;;;;;;;;;;;GAaG;AACH,qBAAa,uBAAwB,YAAW,gBAAgB;IAC9D,wDAAwD;IACxD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiC;IAE9D;;;;;;OAMG;IACG,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD;;;;;;;OAOG;IACG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAYtE;;;;;;OAMG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAIvD;;;;;;;OAOG;IACG,IAAI,CACR,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAC3C,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAiBhC;;;;;;OAMG;IACG,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD;;;;;;;;;;;OAWG;IACG,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAmCpF"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file InMemoryCheckpointStore.ts
|
|
3
|
+
* @description In-memory implementation of `ICheckpointStore` backed by a `Map<string, Checkpoint>`.
|
|
4
|
+
*
|
|
5
|
+
* Intended for unit tests, local development, and ephemeral graph runs where durability is
|
|
6
|
+
* not required. All data is lost when the process exits.
|
|
7
|
+
*
|
|
8
|
+
* Thread-safety note: Node.js is single-threaded so no explicit locking is needed, but callers
|
|
9
|
+
* should be aware that concurrent async operations on the same store instance may interleave.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Derives a `CheckpointMetadata` descriptor from a full `Checkpoint` without copying the
|
|
13
|
+
* heavyweight `state` payload.
|
|
14
|
+
*
|
|
15
|
+
* `stateSize` is approximated via `JSON.stringify` length — sufficient for ranking and
|
|
16
|
+
* display purposes; no guarantee of byte-level accuracy.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
function toMetadata(checkpoint) {
|
|
21
|
+
return {
|
|
22
|
+
id: checkpoint.id,
|
|
23
|
+
runId: checkpoint.runId,
|
|
24
|
+
graphId: checkpoint.graphId,
|
|
25
|
+
nodeId: checkpoint.nodeId,
|
|
26
|
+
timestamp: checkpoint.timestamp,
|
|
27
|
+
stateSize: JSON.stringify(checkpoint.state).length,
|
|
28
|
+
hasMemorySnapshot: checkpoint.memorySnapshot !== undefined,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* In-memory `ICheckpointStore` implementation.
|
|
33
|
+
*
|
|
34
|
+
* All checkpoints are stored in a `Map` keyed by checkpoint `id`. Scans are O(n) over
|
|
35
|
+
* the number of stored checkpoints — acceptable for test workloads; a production store
|
|
36
|
+
* should use indexed secondary keys (runId, graphId).
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const store = new InMemoryCheckpointStore();
|
|
41
|
+
* await store.save(checkpoint);
|
|
42
|
+
* const restored = await store.latest(runId);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export class InMemoryCheckpointStore {
|
|
46
|
+
constructor() {
|
|
47
|
+
/** Primary storage map — checkpoint.id → Checkpoint. */
|
|
48
|
+
this._checkpoints = new Map();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Persist a checkpoint snapshot.
|
|
52
|
+
*
|
|
53
|
+
* Overwrites any existing entry with the same `id`.
|
|
54
|
+
*
|
|
55
|
+
* {@inheritDoc ICheckpointStore.save}
|
|
56
|
+
*/
|
|
57
|
+
async save(checkpoint) {
|
|
58
|
+
this._checkpoints.set(checkpoint.id, checkpoint);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Load a checkpoint for the given `runId`.
|
|
62
|
+
*
|
|
63
|
+
* Scans the full store filtering by `runId` and optionally `nodeId`. When multiple
|
|
64
|
+
* checkpoints match, returns the one with the highest `timestamp`.
|
|
65
|
+
*
|
|
66
|
+
* {@inheritDoc ICheckpointStore.load}
|
|
67
|
+
*/
|
|
68
|
+
async load(runId, nodeId) {
|
|
69
|
+
const candidates = Array.from(this._checkpoints.values()).filter((cp) => cp.runId === runId && (nodeId === undefined || cp.nodeId === nodeId));
|
|
70
|
+
if (candidates.length === 0)
|
|
71
|
+
return null;
|
|
72
|
+
// Return the most recently saved checkpoint among the matches.
|
|
73
|
+
candidates.sort((a, b) => b.timestamp - a.timestamp);
|
|
74
|
+
return candidates[0];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Return the most recently persisted checkpoint for a run.
|
|
78
|
+
*
|
|
79
|
+
* Equivalent to `load(runId)` with no `nodeId` filter.
|
|
80
|
+
*
|
|
81
|
+
* {@inheritDoc ICheckpointStore.latest}
|
|
82
|
+
*/
|
|
83
|
+
async latest(runId) {
|
|
84
|
+
return this.load(runId);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* List lightweight metadata for all checkpoints belonging to a graph.
|
|
88
|
+
*
|
|
89
|
+
* Results are sorted by `timestamp` descending (most recent first). When
|
|
90
|
+
* `options.limit` is set, only the first `limit` entries are returned after sorting.
|
|
91
|
+
*
|
|
92
|
+
* {@inheritDoc ICheckpointStore.list}
|
|
93
|
+
*/
|
|
94
|
+
async list(graphId, options) {
|
|
95
|
+
let results = Array.from(this._checkpoints.values()).filter((cp) => cp.graphId === graphId &&
|
|
96
|
+
(options?.runId === undefined || cp.runId === options.runId));
|
|
97
|
+
// Most-recent-first ordering.
|
|
98
|
+
results.sort((a, b) => b.timestamp - a.timestamp);
|
|
99
|
+
if (options?.limit !== undefined && options.limit > 0) {
|
|
100
|
+
results = results.slice(0, options.limit);
|
|
101
|
+
}
|
|
102
|
+
return results.map(toMetadata);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Permanently remove a checkpoint from the store.
|
|
106
|
+
*
|
|
107
|
+
* Silently succeeds when `checkpointId` does not exist.
|
|
108
|
+
*
|
|
109
|
+
* {@inheritDoc ICheckpointStore.delete}
|
|
110
|
+
*/
|
|
111
|
+
async delete(checkpointId) {
|
|
112
|
+
this._checkpoints.delete(checkpointId);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create a new run branching from an existing checkpoint.
|
|
116
|
+
*
|
|
117
|
+
* Steps:
|
|
118
|
+
* 1. Loads the source checkpoint (throws if missing).
|
|
119
|
+
* 2. Deep-clones via `structuredClone`.
|
|
120
|
+
* 3. Assigns a fresh `runId` and `id` via `crypto.randomUUID()`.
|
|
121
|
+
* 4. Applies `patchState` overrides via `Object.assign` on each state partition.
|
|
122
|
+
* 5. Saves the forked checkpoint and returns the new `runId`.
|
|
123
|
+
*
|
|
124
|
+
* {@inheritDoc ICheckpointStore.fork}
|
|
125
|
+
*/
|
|
126
|
+
async fork(checkpointId, patchState) {
|
|
127
|
+
const source = this._checkpoints.get(checkpointId);
|
|
128
|
+
if (!source) {
|
|
129
|
+
throw new Error(`InMemoryCheckpointStore.fork: checkpoint "${checkpointId}" not found`);
|
|
130
|
+
}
|
|
131
|
+
// Deep clone so mutations to the forked checkpoint cannot affect the source.
|
|
132
|
+
const forked = structuredClone(source);
|
|
133
|
+
// Assign fresh identifiers so the fork is a distinct run.
|
|
134
|
+
forked.runId = crypto.randomUUID();
|
|
135
|
+
forked.id = crypto.randomUUID();
|
|
136
|
+
forked.timestamp = Date.now();
|
|
137
|
+
// Apply optional state patches — each partition is merged independently.
|
|
138
|
+
if (patchState !== undefined) {
|
|
139
|
+
if (patchState.input !== undefined) {
|
|
140
|
+
Object.assign(forked.state.input, patchState.input);
|
|
141
|
+
}
|
|
142
|
+
if (patchState.scratch !== undefined) {
|
|
143
|
+
Object.assign(forked.state.scratch, patchState.scratch);
|
|
144
|
+
}
|
|
145
|
+
if (patchState.artifacts !== undefined) {
|
|
146
|
+
Object.assign(forked.state.artifacts, patchState.artifacts);
|
|
147
|
+
}
|
|
148
|
+
if (patchState.diagnostics !== undefined) {
|
|
149
|
+
Object.assign(forked.state.diagnostics, patchState.diagnostics);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
await this.save(forked);
|
|
153
|
+
return forked.runId;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=InMemoryCheckpointStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryCheckpointStore.js","sourceRoot":"","sources":["../../../src/orchestration/checkpoint/InMemoryCheckpointStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH;;;;;;;;GAQG;AACH,SAAS,UAAU,CAAC,UAAsB;IACxC,OAAO;QACL,EAAE,EAAE,UAAU,CAAC,EAAE;QACjB,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,SAAS,EAAE,UAAU,CAAC,SAAS;QAC/B,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM;QAClD,iBAAiB,EAAE,UAAU,CAAC,cAAc,KAAK,SAAS;KAC3D,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,uBAAuB;IAApC;QACE,wDAAwD;QACvC,iBAAY,GAAG,IAAI,GAAG,EAAsB,CAAC;IAkIhE,CAAC;IAhIC;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,CAAC,UAAsB;QAC/B,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,IAAI,CAAC,KAAa,EAAE,MAAe;QACvC,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MA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U,CAAC,SAAS,CAAC,CAAC;YACxE,CAAC;YACD,IAAI,UAAU,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;gBACzC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;QAED,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxB,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Public barrel for the orchestration checkpoint subsystem.
|
|
4
|
+
*
|
|
5
|
+
* Exports the `ICheckpointStore` interface, the `Checkpoint` and `CheckpointMetadata`
|
|
6
|
+
* types, and the built-in `InMemoryCheckpointStore` implementation.
|
|
7
|
+
*/
|
|
8
|
+
export * from './ICheckpointStore.js';
|
|
9
|
+
export { InMemoryCheckpointStore } from './InMemoryCheckpointStore.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/orchestration/checkpoint/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Public barrel for the orchestration checkpoint subsystem.
|
|
4
|
+
*
|
|
5
|
+
* Exports the `ICheckpointStore` interface, the `Checkpoint` and `CheckpointMetadata`
|
|
6
|
+
* types, and the built-in `InMemoryCheckpointStore` implementation.
|
|
7
|
+
*/
|
|
8
|
+
export * from './ICheckpointStore.js';
|
|
9
|
+
export { InMemoryCheckpointStore } from './InMemoryCheckpointStore.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/orchestration/checkpoint/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file GraphCompiler.ts
|
|
3
|
+
* @description Compiles an AgentGraph builder's internal state into a `CompiledExecutionGraph` IR object.
|
|
4
|
+
*
|
|
5
|
+
* The compiler is a pure, stateless transformation — it accepts a snapshot of the builder's
|
|
6
|
+
* node map and edge list, lowers Zod schemas to JSON Schema, and produces the canonical IR
|
|
7
|
+
* that the `GraphRuntime` operates on.
|
|
8
|
+
*
|
|
9
|
+
* This is intentionally thin: validation belongs in `GraphValidator`, optimisation passes
|
|
10
|
+
* (dead-node elimination, edge compaction) can be added as separate compiler passes later.
|
|
11
|
+
*/
|
|
12
|
+
import type { GraphNode, GraphEdge, CompiledExecutionGraph, StateReducers, MemoryConsistencyMode } from '../ir/types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Everything the compiler needs to produce a `CompiledExecutionGraph`.
|
|
15
|
+
*
|
|
16
|
+
* @property name - Human-readable name embedded in the compiled graph.
|
|
17
|
+
* @property nodes - All user-declared nodes keyed by their declared id.
|
|
18
|
+
* @property edges - All directed edges (including START / END connections).
|
|
19
|
+
* @property stateSchema - Zod schema instances for the three GraphState generics.
|
|
20
|
+
* @property reducers - Field-level merge strategies forwarded unchanged to the IR.
|
|
21
|
+
* @property memoryConsistency - Graph-wide memory isolation mode.
|
|
22
|
+
* @property checkpointPolicy - Graph-wide default checkpoint persistence strategy.
|
|
23
|
+
*/
|
|
24
|
+
export interface GraphCompilerInput {
|
|
25
|
+
/** Human-readable graph name; used as the `name` field in the compiled output. */
|
|
26
|
+
name: string;
|
|
27
|
+
/** All `GraphNode` instances keyed by their assigned id. */
|
|
28
|
+
nodes: Map<string, GraphNode>;
|
|
29
|
+
/** All directed edges declared by the builder (start/end sentinels included). */
|
|
30
|
+
edges: GraphEdge[];
|
|
31
|
+
/**
|
|
32
|
+
* Zod schema instances for each of the three `GraphState` generic partitions.
|
|
33
|
+
* Lowered to JSON Schema during compilation via `lowerZodToJsonSchema`.
|
|
34
|
+
*/
|
|
35
|
+
stateSchema: {
|
|
36
|
+
/** Schema for `GraphState.input` — the frozen user-provided input. */
|
|
37
|
+
input: any;
|
|
38
|
+
/** Schema for `GraphState.scratch` — the node-to-node communication bag. */
|
|
39
|
+
scratch: any;
|
|
40
|
+
/** Schema for `GraphState.artifacts` — accumulated external outputs. */
|
|
41
|
+
artifacts: any;
|
|
42
|
+
};
|
|
43
|
+
/** Field-level reducer configuration passed through to the IR without modification. */
|
|
44
|
+
reducers: StateReducers;
|
|
45
|
+
/** Graph-wide memory consistency mode. */
|
|
46
|
+
memoryConsistency: MemoryConsistencyMode;
|
|
47
|
+
/** Graph-wide checkpoint persistence strategy. */
|
|
48
|
+
checkpointPolicy: 'every_node' | 'explicit' | 'none';
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Stateless compiler that transforms AgentGraph builder state into a `CompiledExecutionGraph`.
|
|
52
|
+
*
|
|
53
|
+
* Compilation steps:
|
|
54
|
+
* 1. Flatten the `nodes` Map into a plain array (preserving insertion order).
|
|
55
|
+
* 2. Copy the `edges` array without transformation.
|
|
56
|
+
* 3. Lower each Zod state schema to a JSON Schema object via `lowerZodToJsonSchema`.
|
|
57
|
+
* 4. Assign a unique `id` based on `name` and the current timestamp.
|
|
58
|
+
* 5. Forward `reducers`, `memoryConsistency`, and `checkpointPolicy` unchanged.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const ir = GraphCompiler.compile({
|
|
63
|
+
* name: 'my-agent',
|
|
64
|
+
* nodes,
|
|
65
|
+
* edges,
|
|
66
|
+
* stateSchema: { input: z.object({ topic: z.string() }), scratch: z.object({}), artifacts: z.object({}) },
|
|
67
|
+
* reducers: {},
|
|
68
|
+
* memoryConsistency: 'snapshot',
|
|
69
|
+
* checkpointPolicy: 'none',
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare class GraphCompiler {
|
|
74
|
+
/**
|
|
75
|
+
* Compile builder state into a `CompiledExecutionGraph` IR object.
|
|
76
|
+
*
|
|
77
|
+
* This method is **pure** — it reads from `input` and returns a new object without
|
|
78
|
+
* mutating any of its arguments.
|
|
79
|
+
*
|
|
80
|
+
* @param input - The full set of builder state required for compilation.
|
|
81
|
+
* @returns A `CompiledExecutionGraph` ready for validation and execution.
|
|
82
|
+
*/
|
|
83
|
+
static compile(input: GraphCompilerInput): CompiledExecutionGraph;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=GraphCompiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphCompiler.d.ts","sourceRoot":"","sources":["../../../src/orchestration/compiler/GraphCompiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,sBAAsB,EACtB,aAAa,EACb,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAOxB;;;;;;;;;;GAUG;AACH,MAAM,WAAW,kBAAkB;IACjC,kFAAkF;IAClF,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC9B,iFAAiF;IACjF,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB;;;OAGG;IACH,WAAW,EAAE;QACX,sEAAsE;QACtE,KAAK,EAAE,GAAG,CAAC;QACX,4EAA4E;QAC5E,OAAO,EAAE,GAAG,CAAC;QACb,wEAAwE;QACxE,SAAS,EAAE,GAAG,CAAC;KAChB,CAAC;IACF,uFAAuF;IACvF,QAAQ,EAAE,aAAa,CAAC;IACxB,0CAA0C;IAC1C,iBAAiB,EAAE,qBAAqB,CAAC;IACzC,kDAAkD;IAClD,gBAAgB,EAAE,YAAY,GAAG,UAAU,GAAG,MAAM,CAAC;CACtD;AAMD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,aAAa;IACxB;;;;;;;;OAQG;IACH,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,kBAAkB,GAAG,sBAAsB;CAyBlE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file GraphCompiler.ts
|
|
3
|
+
* @description Compiles an AgentGraph builder's internal state into a `CompiledExecutionGraph` IR object.
|
|
4
|
+
*
|
|
5
|
+
* The compiler is a pure, stateless transformation — it accepts a snapshot of the builder's
|
|
6
|
+
* node map and edge list, lowers Zod schemas to JSON Schema, and produces the canonical IR
|
|
7
|
+
* that the `GraphRuntime` operates on.
|
|
8
|
+
*
|
|
9
|
+
* This is intentionally thin: validation belongs in `GraphValidator`, optimisation passes
|
|
10
|
+
* (dead-node elimination, edge compaction) can be added as separate compiler passes later.
|
|
11
|
+
*/
|
|
12
|
+
import { lowerZodToJsonSchema } from './SchemaLowering.js';
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// GraphCompiler
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
/**
|
|
17
|
+
* Stateless compiler that transforms AgentGraph builder state into a `CompiledExecutionGraph`.
|
|
18
|
+
*
|
|
19
|
+
* Compilation steps:
|
|
20
|
+
* 1. Flatten the `nodes` Map into a plain array (preserving insertion order).
|
|
21
|
+
* 2. Copy the `edges` array without transformation.
|
|
22
|
+
* 3. Lower each Zod state schema to a JSON Schema object via `lowerZodToJsonSchema`.
|
|
23
|
+
* 4. Assign a unique `id` based on `name` and the current timestamp.
|
|
24
|
+
* 5. Forward `reducers`, `memoryConsistency`, and `checkpointPolicy` unchanged.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const ir = GraphCompiler.compile({
|
|
29
|
+
* name: 'my-agent',
|
|
30
|
+
* nodes,
|
|
31
|
+
* edges,
|
|
32
|
+
* stateSchema: { input: z.object({ topic: z.string() }), scratch: z.object({}), artifacts: z.object({}) },
|
|
33
|
+
* reducers: {},
|
|
34
|
+
* memoryConsistency: 'snapshot',
|
|
35
|
+
* checkpointPolicy: 'none',
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export class GraphCompiler {
|
|
40
|
+
/**
|
|
41
|
+
* Compile builder state into a `CompiledExecutionGraph` IR object.
|
|
42
|
+
*
|
|
43
|
+
* This method is **pure** — it reads from `input` and returns a new object without
|
|
44
|
+
* mutating any of its arguments.
|
|
45
|
+
*
|
|
46
|
+
* @param input - The full set of builder state required for compilation.
|
|
47
|
+
* @returns A `CompiledExecutionGraph` ready for validation and execution.
|
|
48
|
+
*/
|
|
49
|
+
static compile(input) {
|
|
50
|
+
return {
|
|
51
|
+
// Unique graph id: name slug + wall-clock timestamp for collision resistance.
|
|
52
|
+
id: `graph-${input.name}-${Date.now()}`,
|
|
53
|
+
name: input.name,
|
|
54
|
+
// Flatten Map → Array preserving the order in which nodes were added to the builder.
|
|
55
|
+
nodes: Array.from(input.nodes.values()),
|
|
56
|
+
// Edges are already an array; copy reference (immutable after compile).
|
|
57
|
+
edges: input.edges,
|
|
58
|
+
// Lower each Zod schema partition to a plain JSON Schema object.
|
|
59
|
+
stateSchema: {
|
|
60
|
+
input: lowerZodToJsonSchema(input.stateSchema.input),
|
|
61
|
+
scratch: lowerZodToJsonSchema(input.stateSchema.scratch),
|
|
62
|
+
artifacts: lowerZodToJsonSchema(input.stateSchema.artifacts),
|
|
63
|
+
},
|
|
64
|
+
// Forward reducer, consistency, and checkpoint config unchanged.
|
|
65
|
+
reducers: input.reducers,
|
|
66
|
+
checkpointPolicy: input.checkpointPolicy,
|
|
67
|
+
memoryConsistency: input.memoryConsistency,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=GraphCompiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphCompiler.js","sourceRoot":"","sources":["../../../src/orchestration/compiler/GraphCompiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AASH,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AA4C3D,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAE9E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,aAAa;IACxB;;;;;;;;OAQG;IACH,MAAM,CAAC,OAAO,CAAC,KAAyB;QACtC,OAAO;YACL,8EAA8E;YAC9E,EAAE,EAAE,SAAS,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE;YACvC,IAAI,EAAE,KAAK,CAAC,IAAI;YAEhB,qFAAqF;YACrF,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YAEvC,wEAAwE;YACxE,KAAK,EAAE,KAAK,CAAC,KAAK;YAElB,iEAAiE;YACjE,WAAW,EAAE;gBACX,KAAK,EAAE,oBAAoB,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC;gBACpD,OAAO,EAAE,oBAAoB,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC;gBACxD,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC;aAC7D;YAED,iEAAiE;YACjE,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;YACxC,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;SAC3C,CAAC;IACJ,CAAC;CACF"}
|