@framers/agentos 0.1.68 → 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,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file MissionCompiler.ts
|
|
3
|
+
* @description Bridges PlanningEngine output (or the stub planner) to a
|
|
4
|
+
* `CompiledExecutionGraph` IR, enabling goal-oriented mission authoring via
|
|
5
|
+
* the `mission()` builder API.
|
|
6
|
+
*
|
|
7
|
+
* Compilation pipeline:
|
|
8
|
+
* 1. Run stub planner → `SimplePlan` (real PlanningEngine wired later)
|
|
9
|
+
* 2. Map plan steps to `GraphNode` objects via `stepToNode()`
|
|
10
|
+
* 3. Splice declared anchors into the phase-ordered node sequence
|
|
11
|
+
* 4. Build a linear edge chain (START → … → END)
|
|
12
|
+
* 5. Apply mission-level guardrail policies to all nodes
|
|
13
|
+
* 6. Lower to `CompiledExecutionGraph` via `GraphCompiler` + `GraphValidator`
|
|
14
|
+
*/
|
|
15
|
+
import type { GraphNode, CompiledExecutionGraph, MemoryConsistencyMode } from '../ir/types.js';
|
|
16
|
+
/**
|
|
17
|
+
* Top-level configuration object consumed by `MissionCompiler.compile()`.
|
|
18
|
+
* Produced internally by `MissionBuilder.compile()`.
|
|
19
|
+
*/
|
|
20
|
+
export interface MissionConfig {
|
|
21
|
+
/** Human-readable mission name; becomes the compiled graph's display name. */
|
|
22
|
+
name: string;
|
|
23
|
+
/** Zod schema (or plain JSON-Schema object) describing the mission's input payload. */
|
|
24
|
+
inputSchema: any;
|
|
25
|
+
/**
|
|
26
|
+
* Goal prompt template. Supports `{{variable}}` interpolation (e.g. `{{topic}}`).
|
|
27
|
+
* Injected as the system instruction for the stub planner and `gmi` reasoning nodes.
|
|
28
|
+
*/
|
|
29
|
+
goalTemplate: string;
|
|
30
|
+
/** Zod schema (or plain JSON-Schema object) describing the mission's output artifacts. */
|
|
31
|
+
returnsSchema: any;
|
|
32
|
+
/** Planner configuration controlling step generation and execution budgets. */
|
|
33
|
+
plannerConfig: {
|
|
34
|
+
/** Routing/planning strategy identifier (e.g. `'linear'`, `'react'`, `'tree-of-thought'`). */
|
|
35
|
+
strategy: string;
|
|
36
|
+
/** Hard cap on the total number of plan steps the planner may emit. */
|
|
37
|
+
maxSteps: number;
|
|
38
|
+
/**
|
|
39
|
+
* Maximum LLM iterations a single `gmi` node may consume per invocation.
|
|
40
|
+
* Forwarded to `gmiNode` as `maxInternalIterations`.
|
|
41
|
+
*/
|
|
42
|
+
maxIterationsPerNode?: number;
|
|
43
|
+
/**
|
|
44
|
+
* When `true`, `gmi` nodes are configured to issue multiple tool calls per turn.
|
|
45
|
+
* Forwarded to `gmiNode` as `parallelTools`.
|
|
46
|
+
*/
|
|
47
|
+
parallelTools?: boolean;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Optional mission-level policy overrides.
|
|
51
|
+
* When set, they are applied to all compiled nodes unless a node already declares
|
|
52
|
+
* its own policy.
|
|
53
|
+
*/
|
|
54
|
+
policyConfig?: {
|
|
55
|
+
memory?: {
|
|
56
|
+
consistency?: MemoryConsistencyMode;
|
|
57
|
+
read?: any;
|
|
58
|
+
write?: any;
|
|
59
|
+
};
|
|
60
|
+
discovery?: {
|
|
61
|
+
kind?: string;
|
|
62
|
+
fallback?: string;
|
|
63
|
+
};
|
|
64
|
+
personality?: {
|
|
65
|
+
traitRouting?: boolean;
|
|
66
|
+
adaptStyle?: boolean;
|
|
67
|
+
mood?: string;
|
|
68
|
+
};
|
|
69
|
+
/** Guardrail identifiers applied as output guardrails on every node. */
|
|
70
|
+
guardrails?: string[];
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Declarative anchor nodes that must be spliced into the execution order at specific phases.
|
|
74
|
+
* Anchors allow callers to inject pre-built `GraphNode` objects (e.g. specialised tools or
|
|
75
|
+
* human-in-the-loop checkpoints) without modifying the planner output.
|
|
76
|
+
*/
|
|
77
|
+
anchors: Array<{
|
|
78
|
+
/** Node id assigned to the anchor inside the compiled graph. */
|
|
79
|
+
id: string;
|
|
80
|
+
/** Pre-built `GraphNode` to splice in. The compiler overwrites `node.id` with `anchor.id`. */
|
|
81
|
+
node: GraphNode;
|
|
82
|
+
/** Placement constraints that control where in the phase sequence the anchor is inserted. */
|
|
83
|
+
constraints: {
|
|
84
|
+
/** When `true` the compiler will throw if the anchor cannot be placed. */
|
|
85
|
+
required: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Execution phase the anchor belongs to. Phases are ordered:
|
|
88
|
+
* `gather` → `process` → `validate` → `deliver`.
|
|
89
|
+
*/
|
|
90
|
+
phase?: 'gather' | 'process' | 'validate' | 'deliver';
|
|
91
|
+
/**
|
|
92
|
+
* Insert the anchor *after* this node id (sibling anchor id or plan step id).
|
|
93
|
+
* When the referenced id is not found the anchor is appended to the phase tail.
|
|
94
|
+
*/
|
|
95
|
+
after?: any;
|
|
96
|
+
/**
|
|
97
|
+
* Insert the anchor *before* this node id.
|
|
98
|
+
* Currently reserved for future use; has no effect in this compiler version.
|
|
99
|
+
*/
|
|
100
|
+
before?: any;
|
|
101
|
+
};
|
|
102
|
+
}>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Minimal plan structure produced by the stub planner (and, eventually, by the
|
|
106
|
+
* real `PlanningEngine`). Each step maps 1-to-1 to a `GraphNode` in the compiled IR.
|
|
107
|
+
*/
|
|
108
|
+
export interface SimplePlan {
|
|
109
|
+
steps: Array<{
|
|
110
|
+
/** Unique step id; becomes the compiled `GraphNode.id`. */
|
|
111
|
+
id: string;
|
|
112
|
+
/**
|
|
113
|
+
* Step action type, used to select the correct node builder:
|
|
114
|
+
* - `'reasoning'` → `gmiNode`
|
|
115
|
+
* - `'tool_call'` → `toolNode`
|
|
116
|
+
* - `'human_input'` → `humanNode`
|
|
117
|
+
* - `'validation'` → `guardrailNode`
|
|
118
|
+
*/
|
|
119
|
+
action: string;
|
|
120
|
+
/** Human-readable description injected as the node's instructions or prompt. */
|
|
121
|
+
description: string;
|
|
122
|
+
/** Execution phase this step belongs to (governs ordering alongside anchors). */
|
|
123
|
+
phase: 'gather' | 'process' | 'validate' | 'deliver';
|
|
124
|
+
/** Required when `action` is `'tool_call'`; the registered tool name. */
|
|
125
|
+
toolName?: string;
|
|
126
|
+
}>;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Static compiler that transforms a `MissionConfig` into a `CompiledExecutionGraph`.
|
|
130
|
+
*
|
|
131
|
+
* The compiler is intentionally stateless — call `MissionCompiler.compile()` as many
|
|
132
|
+
* times as needed; each invocation is fully isolated.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* const ir = MissionCompiler.compile({
|
|
137
|
+
* name: 'research-mission',
|
|
138
|
+
* inputSchema: z.object({ topic: z.string() }),
|
|
139
|
+
* goalTemplate: 'Research {{topic}} and produce a summary',
|
|
140
|
+
* returnsSchema: z.object({ summary: z.string() }),
|
|
141
|
+
* plannerConfig: { strategy: 'linear', maxSteps: 5 },
|
|
142
|
+
* anchors: [],
|
|
143
|
+
* });
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export declare class MissionCompiler {
|
|
147
|
+
/**
|
|
148
|
+
* Compile a mission config into a `CompiledExecutionGraph`.
|
|
149
|
+
*
|
|
150
|
+
* Uses a stub planner that generates a simple linear plan based on the goal template.
|
|
151
|
+
* Real `PlanningEngine` integration will be wired in a future task once the planner
|
|
152
|
+
* interface is stable.
|
|
153
|
+
*
|
|
154
|
+
* @param config - Fully-populated `MissionConfig` object produced by `MissionBuilder`.
|
|
155
|
+
* @returns A validated `CompiledExecutionGraph` ready for `GraphRuntime`.
|
|
156
|
+
* @throws {Error} When `GraphValidator.validate()` reports structural errors.
|
|
157
|
+
*/
|
|
158
|
+
static compile(config: MissionConfig): CompiledExecutionGraph;
|
|
159
|
+
/**
|
|
160
|
+
* Stub planner: emits a fixed 3-step linear plan derived from the goal template.
|
|
161
|
+
*
|
|
162
|
+
* This is intentionally minimal — its only job is to prove the compilation pipeline
|
|
163
|
+
* works end-to-end. The real `PlanningEngine` (Task 16+) will replace this method.
|
|
164
|
+
*
|
|
165
|
+
* @param config - Mission configuration providing the goal template and planner settings.
|
|
166
|
+
* @returns A `SimplePlan` with steps distributed across `gather`, `process`, and `deliver` phases.
|
|
167
|
+
*/
|
|
168
|
+
private static generateStubPlan;
|
|
169
|
+
/**
|
|
170
|
+
* Convert a single `SimplePlan` step to its corresponding `GraphNode`.
|
|
171
|
+
*
|
|
172
|
+
* The returned node's `id` is immediately overwritten by the caller with `step.id`,
|
|
173
|
+
* so the auto-generated id from the node builders is discarded.
|
|
174
|
+
*
|
|
175
|
+
* @param step - Plan step descriptor.
|
|
176
|
+
* @param config - Parent mission configuration (provides planner and policy settings).
|
|
177
|
+
* @returns A fully-initialised `GraphNode` whose `id` will be overwritten by the caller.
|
|
178
|
+
*/
|
|
179
|
+
private static stepToNode;
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=MissionCompiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MissionCompiler.d.ts","sourceRoot":"","sources":["../../../src/orchestration/compiler/MissionCompiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,SAAS,EAET,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAUxB;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,uFAAuF;IACvF,WAAW,EAAE,GAAG,CAAC;IACjB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB,0FAA0F;IAC1F,aAAa,EAAE,GAAG,CAAC;IACnB,+EAA+E;IAC/E,aAAa,EAAE;QACb,8FAA8F;QAC9F,QAAQ,EAAE,MAAM,CAAC;QACjB,uEAAuE;QACvE,QAAQ,EAAE,MAAM,CAAC;QACjB;;;WAGG;QACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B;;;WAGG;QACH,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;IACF;;;;OAIG;IACH,YAAY,CAAC,EAAE;QACb,MAAM,CAAC,EAAE;YAAE,WAAW,CAAC,EAAE,qBAAqB,CAAC;YAAC,IAAI,CAAC,EAAE,GAAG,CAAC;YAAC,KAAK,CAAC,EAAE,GAAG,CAAA;SAAE,CAAC;QAC1E,SAAS,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QACjD,WAAW,CAAC,EAAE;YAAE,YAAY,CAAC,EAAE,OAAO,CAAC;YAAC,UAAU,CAAC,EAAE,OAAO,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC9E,wEAAwE;QACxE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC;IACF;;;;OAIG;IACH,OAAO,EAAE,KAAK,CAAC;QACb,gEAAgE;QAChE,EAAE,EAAE,MAAM,CAAC;QACX,8FAA8F;QAC9F,IAAI,EAAE,SAAS,CAAC;QAChB,6FAA6F;QAC7F,WAAW,EAAE;YACX,0EAA0E;YAC1E,QAAQ,EAAE,OAAO,CAAC;YAClB;;;eAGG;YACH,KAAK,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;YACtD;;;eAGG;YACH,KAAK,CAAC,EAAE,GAAG,CAAC;YACZ;;;eAGG;YACH,MAAM,CAAC,EAAE,GAAG,CAAC;SACd,CAAC;KACH,CAAC,CAAC;CACJ;AAMD;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,KAAK,CAAC;QACX,2DAA2D;QAC3D,EAAE,EAAE,MAAM,CAAC;QACX;;;;;;WAMG;QACH,MAAM,EAAE,MAAM,CAAC;QACf,gFAAgF;QAChF,WAAW,EAAE,MAAM,CAAC;QACpB,iFAAiF;QACjF,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;QACrD,yEAAyE;QACzE,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;CACJ;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,eAAe;IAK1B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,sBAAsB;IAgH7D;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAyB/B;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;CAiC1B"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file MissionCompiler.ts
|
|
3
|
+
* @description Bridges PlanningEngine output (or the stub planner) to a
|
|
4
|
+
* `CompiledExecutionGraph` IR, enabling goal-oriented mission authoring via
|
|
5
|
+
* the `mission()` builder API.
|
|
6
|
+
*
|
|
7
|
+
* Compilation pipeline:
|
|
8
|
+
* 1. Run stub planner → `SimplePlan` (real PlanningEngine wired later)
|
|
9
|
+
* 2. Map plan steps to `GraphNode` objects via `stepToNode()`
|
|
10
|
+
* 3. Splice declared anchors into the phase-ordered node sequence
|
|
11
|
+
* 4. Build a linear edge chain (START → … → END)
|
|
12
|
+
* 5. Apply mission-level guardrail policies to all nodes
|
|
13
|
+
* 6. Lower to `CompiledExecutionGraph` via `GraphCompiler` + `GraphValidator`
|
|
14
|
+
*/
|
|
15
|
+
import { START, END } from '../ir/types.js';
|
|
16
|
+
import { gmiNode, toolNode, humanNode, guardrailNode } from '../builders/nodes.js';
|
|
17
|
+
import { GraphCompiler } from './GraphCompiler.js';
|
|
18
|
+
import { GraphValidator } from './Validator.js';
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// MissionCompiler
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
/**
|
|
23
|
+
* Static compiler that transforms a `MissionConfig` into a `CompiledExecutionGraph`.
|
|
24
|
+
*
|
|
25
|
+
* The compiler is intentionally stateless — call `MissionCompiler.compile()` as many
|
|
26
|
+
* times as needed; each invocation is fully isolated.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const ir = MissionCompiler.compile({
|
|
31
|
+
* name: 'research-mission',
|
|
32
|
+
* inputSchema: z.object({ topic: z.string() }),
|
|
33
|
+
* goalTemplate: 'Research {{topic}} and produce a summary',
|
|
34
|
+
* returnsSchema: z.object({ summary: z.string() }),
|
|
35
|
+
* plannerConfig: { strategy: 'linear', maxSteps: 5 },
|
|
36
|
+
* anchors: [],
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export class MissionCompiler {
|
|
41
|
+
// -------------------------------------------------------------------------
|
|
42
|
+
// Public API
|
|
43
|
+
// -------------------------------------------------------------------------
|
|
44
|
+
/**
|
|
45
|
+
* Compile a mission config into a `CompiledExecutionGraph`.
|
|
46
|
+
*
|
|
47
|
+
* Uses a stub planner that generates a simple linear plan based on the goal template.
|
|
48
|
+
* Real `PlanningEngine` integration will be wired in a future task once the planner
|
|
49
|
+
* interface is stable.
|
|
50
|
+
*
|
|
51
|
+
* @param config - Fully-populated `MissionConfig` object produced by `MissionBuilder`.
|
|
52
|
+
* @returns A validated `CompiledExecutionGraph` ready for `GraphRuntime`.
|
|
53
|
+
* @throws {Error} When `GraphValidator.validate()` reports structural errors.
|
|
54
|
+
*/
|
|
55
|
+
static compile(config) {
|
|
56
|
+
// 1. Generate a linear plan (stub — real planner integration planned for Task 16+)
|
|
57
|
+
const plan = this.generateStubPlan(config);
|
|
58
|
+
// 2. Map plan steps to GraphNode objects
|
|
59
|
+
const nodes = new Map();
|
|
60
|
+
const edges = [];
|
|
61
|
+
let edgeCounter = 0;
|
|
62
|
+
const nextEdgeId = () => `me-${++edgeCounter}`;
|
|
63
|
+
for (const step of plan.steps) {
|
|
64
|
+
const node = this.stepToNode(step, config);
|
|
65
|
+
nodes.set(step.id, node);
|
|
66
|
+
}
|
|
67
|
+
// 3. Splice anchors — overwrite their id so the compiled graph uses the declared id
|
|
68
|
+
for (const anchor of config.anchors) {
|
|
69
|
+
// Mutate a shallow copy to avoid modifying the caller's object
|
|
70
|
+
const anchoredNode = { ...anchor.node, id: anchor.id };
|
|
71
|
+
nodes.set(anchor.id, anchoredNode);
|
|
72
|
+
}
|
|
73
|
+
// 4. Build a phase-ordered sequence of node ids
|
|
74
|
+
const phaseOrder = [
|
|
75
|
+
'gather',
|
|
76
|
+
'process',
|
|
77
|
+
'validate',
|
|
78
|
+
'deliver',
|
|
79
|
+
];
|
|
80
|
+
const orderedNodeIds = [];
|
|
81
|
+
for (const phase of phaseOrder) {
|
|
82
|
+
// Plan steps belonging to this phase
|
|
83
|
+
const phaseSteps = plan.steps.filter(s => s.phase === phase);
|
|
84
|
+
for (const step of phaseSteps) {
|
|
85
|
+
orderedNodeIds.push(step.id);
|
|
86
|
+
}
|
|
87
|
+
// Anchors belonging to this phase, respecting `after` constraints
|
|
88
|
+
const phaseAnchors = config.anchors.filter(a => a.constraints.phase === phase);
|
|
89
|
+
for (const anchor of phaseAnchors) {
|
|
90
|
+
if (typeof anchor.constraints.after === 'string') {
|
|
91
|
+
const afterIdx = orderedNodeIds.indexOf(anchor.constraints.after);
|
|
92
|
+
if (afterIdx >= 0) {
|
|
93
|
+
orderedNodeIds.splice(afterIdx + 1, 0, anchor.id);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
orderedNodeIds.push(anchor.id);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Anchors without a phase constraint are appended at the tail
|
|
101
|
+
for (const anchor of config.anchors) {
|
|
102
|
+
if (!anchor.constraints.phase && !orderedNodeIds.includes(anchor.id)) {
|
|
103
|
+
orderedNodeIds.push(anchor.id);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// 5. Build linear edge chain: START → n₀ → n₁ → … → END
|
|
107
|
+
let prev = START;
|
|
108
|
+
for (const nodeId of orderedNodeIds) {
|
|
109
|
+
edges.push({ id: nextEdgeId(), source: prev, target: nodeId, type: 'static' });
|
|
110
|
+
prev = nodeId;
|
|
111
|
+
}
|
|
112
|
+
edges.push({ id: nextEdgeId(), source: prev, target: END, type: 'static' });
|
|
113
|
+
// 6. Apply mission-level guardrail policy to every node that has none yet
|
|
114
|
+
if (config.policyConfig?.guardrails && config.policyConfig.guardrails.length > 0) {
|
|
115
|
+
for (const [key, node] of nodes) {
|
|
116
|
+
if (!node.guardrailPolicy) {
|
|
117
|
+
nodes.set(key, {
|
|
118
|
+
...node,
|
|
119
|
+
guardrailPolicy: {
|
|
120
|
+
output: config.policyConfig.guardrails,
|
|
121
|
+
onViolation: 'warn',
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// 7. Lower to CompiledExecutionGraph via GraphCompiler
|
|
128
|
+
const ir = GraphCompiler.compile({
|
|
129
|
+
name: config.name,
|
|
130
|
+
nodes,
|
|
131
|
+
edges,
|
|
132
|
+
stateSchema: {
|
|
133
|
+
input: config.inputSchema,
|
|
134
|
+
scratch: config.inputSchema,
|
|
135
|
+
artifacts: config.returnsSchema,
|
|
136
|
+
},
|
|
137
|
+
reducers: {},
|
|
138
|
+
memoryConsistency: config.policyConfig?.memory?.consistency ?? 'snapshot',
|
|
139
|
+
checkpointPolicy: 'every_node',
|
|
140
|
+
});
|
|
141
|
+
// 8. Validate structural correctness (acyclicity required for linear missions)
|
|
142
|
+
const validation = GraphValidator.validate(ir, { requireAcyclic: true });
|
|
143
|
+
if (!validation.valid) {
|
|
144
|
+
throw new Error(`Mission compilation failed for "${config.name}": ${validation.errors.join('; ')}`);
|
|
145
|
+
}
|
|
146
|
+
return ir;
|
|
147
|
+
}
|
|
148
|
+
// -------------------------------------------------------------------------
|
|
149
|
+
// Private helpers
|
|
150
|
+
// -------------------------------------------------------------------------
|
|
151
|
+
/**
|
|
152
|
+
* Stub planner: emits a fixed 3-step linear plan derived from the goal template.
|
|
153
|
+
*
|
|
154
|
+
* This is intentionally minimal — its only job is to prove the compilation pipeline
|
|
155
|
+
* works end-to-end. The real `PlanningEngine` (Task 16+) will replace this method.
|
|
156
|
+
*
|
|
157
|
+
* @param config - Mission configuration providing the goal template and planner settings.
|
|
158
|
+
* @returns A `SimplePlan` with steps distributed across `gather`, `process`, and `deliver` phases.
|
|
159
|
+
*/
|
|
160
|
+
static generateStubPlan(config) {
|
|
161
|
+
return {
|
|
162
|
+
steps: [
|
|
163
|
+
{
|
|
164
|
+
id: 'gather-info',
|
|
165
|
+
action: 'reasoning',
|
|
166
|
+
description: `Gather information for: ${config.goalTemplate}`,
|
|
167
|
+
phase: 'gather',
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
id: 'process-info',
|
|
171
|
+
action: 'reasoning',
|
|
172
|
+
description: 'Process and analyse gathered information',
|
|
173
|
+
phase: 'process',
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
id: 'deliver-result',
|
|
177
|
+
action: 'reasoning',
|
|
178
|
+
description: 'Deliver final result',
|
|
179
|
+
phase: 'deliver',
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Convert a single `SimplePlan` step to its corresponding `GraphNode`.
|
|
186
|
+
*
|
|
187
|
+
* The returned node's `id` is immediately overwritten by the caller with `step.id`,
|
|
188
|
+
* so the auto-generated id from the node builders is discarded.
|
|
189
|
+
*
|
|
190
|
+
* @param step - Plan step descriptor.
|
|
191
|
+
* @param config - Parent mission configuration (provides planner and policy settings).
|
|
192
|
+
* @returns A fully-initialised `GraphNode` whose `id` will be overwritten by the caller.
|
|
193
|
+
*/
|
|
194
|
+
static stepToNode(step, config) {
|
|
195
|
+
switch (step.action) {
|
|
196
|
+
case 'tool_call':
|
|
197
|
+
return { ...toolNode(step.toolName ?? 'unknown'), id: step.id };
|
|
198
|
+
case 'human_input':
|
|
199
|
+
return { ...humanNode({ prompt: step.description }), id: step.id };
|
|
200
|
+
case 'validation':
|
|
201
|
+
return {
|
|
202
|
+
...guardrailNode(config.policyConfig?.guardrails ?? [], { onViolation: 'warn' }),
|
|
203
|
+
id: step.id,
|
|
204
|
+
};
|
|
205
|
+
case 'reasoning':
|
|
206
|
+
default:
|
|
207
|
+
return {
|
|
208
|
+
...gmiNode({
|
|
209
|
+
instructions: step.description,
|
|
210
|
+
executionMode: 'planner_controlled',
|
|
211
|
+
maxInternalIterations: config.plannerConfig.maxIterationsPerNode,
|
|
212
|
+
parallelTools: config.plannerConfig.parallelTools,
|
|
213
|
+
}),
|
|
214
|
+
id: step.id,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=MissionCompiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|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;;;;;;;OASG;IACK,MAAM,CAAC,UAAU,CACvB,IAA4B,EAC5B,MAAqB;QAErB,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;YACpB,KAAK,WAAW;gBACd,OAAO,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,IAAI,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;YAElE,KAAK,aAAa;gBAChB,OAAO,EAAE,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;YAErE,KAAK,YAAY;gBACf,OAAO;oBACL,GAAG,aAAa,CACd,MAAM,CAAC,YAAY,EAAE,UAAU,IAAI,EAAE,EACrC,EAAE,WAAW,EAAE,MAAM,EAAE,CACxB;oBACD,EAAE,EAAE,IAAI,CAAC,EAAE;iBACZ,CAAC;YAEJ,KAAK,WAAW,CAAC;YACjB;gBACE,OAAO;oBACL,GAAG,OAAO,CAAC;wBACT,YAAY,EAAE,IAAI,CAAC,WAAW;wBAC9B,aAAa,EAAE,oBAAoB;wBACnC,qBAAqB,EAAE,MAAM,CAAC,aAAa,CAAC,oBAAoB;wBAChE,aAAa,EAAE,MAAM,CAAC,aAAa,CAAC,aAAa;qBAClD,CAAC;oBACF,EAAE,EAAE,IAAI,CAAC,EAAE;iBACZ,CAAC;QACN,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file SchemaLowering.ts
|
|
3
|
+
* @description Minimal Zod-to-JSON-Schema converter for the AgentOS orchestration layer.
|
|
4
|
+
*
|
|
5
|
+
* Intentionally hand-rolled to avoid adding `zod-to-json-schema` as a dependency.
|
|
6
|
+
* Handles the subset of Zod types used in node input/output schemas across the codebase:
|
|
7
|
+
* z.string, z.number, z.boolean, z.null, z.object, z.array, z.enum, z.optional, z.default.
|
|
8
|
+
*
|
|
9
|
+
* Targets Zod v4 `_def` internals:
|
|
10
|
+
* - Discriminant field: `_def.type` (string literal, e.g. `"string"`, `"object"`)
|
|
11
|
+
* - Array inner schema: `_def.element`
|
|
12
|
+
* - Object shape: `_def.shape` (plain Record, NOT a function as in Zod v3)
|
|
13
|
+
* - Enum values: `_def.entries` (Record<string, string> — keys and values are the same)
|
|
14
|
+
* - Optional/Default inner schema: `_def.innerType`
|
|
15
|
+
*
|
|
16
|
+
* Unsupported types fall through to an empty object `{}` — callers should treat that as
|
|
17
|
+
* an "unknown / untyped" schema rather than an error.
|
|
18
|
+
*/
|
|
19
|
+
import type { ZodType } from 'zod';
|
|
20
|
+
/**
|
|
21
|
+
* Converts a Zod schema instance to a plain JSON Schema object.
|
|
22
|
+
*
|
|
23
|
+
* Recursively descends into ZodObject shapes, ZodArray item types, ZodOptional and
|
|
24
|
+
* ZodDefault wrappers, transparently unwrapping them so the produced JSON Schema
|
|
25
|
+
* is clean and does not contain Zod-specific metadata.
|
|
26
|
+
*
|
|
27
|
+
* @param schema - Any Zod schema instance.
|
|
28
|
+
* @returns A JSON Schema-compatible plain object.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const jsonSchema = lowerZodToJsonSchema(z.object({ name: z.string(), age: z.number().optional() }));
|
|
33
|
+
* // → { type: 'object', properties: { name: { type: 'string' }, age: { type: 'number' } }, required: ['name'] }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function lowerZodToJsonSchema(schema: ZodType): Record<string, unknown>;
|
|
37
|
+
//# sourceMappingURL=SchemaLowering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaLowering.d.ts","sourceRoot":"","sources":["../../../src/orchestration/compiler/SchemaLowering.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyE7E"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file SchemaLowering.ts
|
|
3
|
+
* @description Minimal Zod-to-JSON-Schema converter for the AgentOS orchestration layer.
|
|
4
|
+
*
|
|
5
|
+
* Intentionally hand-rolled to avoid adding `zod-to-json-schema` as a dependency.
|
|
6
|
+
* Handles the subset of Zod types used in node input/output schemas across the codebase:
|
|
7
|
+
* z.string, z.number, z.boolean, z.null, z.object, z.array, z.enum, z.optional, z.default.
|
|
8
|
+
*
|
|
9
|
+
* Targets Zod v4 `_def` internals:
|
|
10
|
+
* - Discriminant field: `_def.type` (string literal, e.g. `"string"`, `"object"`)
|
|
11
|
+
* - Array inner schema: `_def.element`
|
|
12
|
+
* - Object shape: `_def.shape` (plain Record, NOT a function as in Zod v3)
|
|
13
|
+
* - Enum values: `_def.entries` (Record<string, string> — keys and values are the same)
|
|
14
|
+
* - Optional/Default inner schema: `_def.innerType`
|
|
15
|
+
*
|
|
16
|
+
* Unsupported types fall through to an empty object `{}` — callers should treat that as
|
|
17
|
+
* an "unknown / untyped" schema rather than an error.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Converts a Zod schema instance to a plain JSON Schema object.
|
|
21
|
+
*
|
|
22
|
+
* Recursively descends into ZodObject shapes, ZodArray item types, ZodOptional and
|
|
23
|
+
* ZodDefault wrappers, transparently unwrapping them so the produced JSON Schema
|
|
24
|
+
* is clean and does not contain Zod-specific metadata.
|
|
25
|
+
*
|
|
26
|
+
* @param schema - Any Zod schema instance.
|
|
27
|
+
* @returns A JSON Schema-compatible plain object.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const jsonSchema = lowerZodToJsonSchema(z.object({ name: z.string(), age: z.number().optional() }));
|
|
32
|
+
* // → { type: 'object', properties: { name: { type: 'string' }, age: { type: 'number' } }, required: ['name'] }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function lowerZodToJsonSchema(schema) {
|
|
36
|
+
// Access Zod v4 internals via `_def`; the top-level `_def.type` is the discriminant.
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
const def = schema._def;
|
|
39
|
+
if (!def)
|
|
40
|
+
return {};
|
|
41
|
+
// In Zod v4 the discriminant is `_def.type` (a plain string literal).
|
|
42
|
+
const typeName = def.type;
|
|
43
|
+
switch (typeName) {
|
|
44
|
+
case 'string':
|
|
45
|
+
return { type: 'string' };
|
|
46
|
+
case 'number':
|
|
47
|
+
return { type: 'number' };
|
|
48
|
+
case 'boolean':
|
|
49
|
+
return { type: 'boolean' };
|
|
50
|
+
case 'null':
|
|
51
|
+
return { type: 'null' };
|
|
52
|
+
case 'enum': {
|
|
53
|
+
// Zod v4: def.entries is Record<string, string> — extract the values array.
|
|
54
|
+
const entries = def.entries;
|
|
55
|
+
return { enum: Object.values(entries) };
|
|
56
|
+
}
|
|
57
|
+
case 'array': {
|
|
58
|
+
// Zod v4: def.element holds the inner schema instance.
|
|
59
|
+
return {
|
|
60
|
+
type: 'array',
|
|
61
|
+
items: lowerZodToJsonSchema(def.element),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
case 'object': {
|
|
65
|
+
const properties = {};
|
|
66
|
+
const required = [];
|
|
67
|
+
// Zod v4: def.shape is a plain Record<string, ZodType> (not a function as in Zod v3).
|
|
68
|
+
const shape = def.shape;
|
|
69
|
+
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
70
|
+
properties[key] = lowerZodToJsonSchema(fieldSchema);
|
|
71
|
+
// A field is required unless its outermost wrapper is optional or has a default.
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
+
const fieldType = fieldSchema._def?.type;
|
|
74
|
+
if (fieldType !== 'optional' && fieldType !== 'default') {
|
|
75
|
+
required.push(key);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
type: 'object',
|
|
80
|
+
properties,
|
|
81
|
+
...(required.length > 0 ? { required } : {}),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
case 'optional':
|
|
85
|
+
// Unwrap; optionality is expressed via absence from `required`, not in the field schema.
|
|
86
|
+
return lowerZodToJsonSchema(def.innerType);
|
|
87
|
+
case 'default':
|
|
88
|
+
// Unwrap; defaults are runtime concerns, not JSON Schema concerns for our use case.
|
|
89
|
+
return lowerZodToJsonSchema(def.innerType);
|
|
90
|
+
default:
|
|
91
|
+
// Unknown / unsupported Zod type — return empty schema (treat as untyped).
|
|
92
|
+
return {};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=SchemaLowering.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaLowering.js","sourceRoot":"","sources":["../../../src/orchestration/compiler/SchemaLowering.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAe;IAClD,qFAAqF;IACrF,8DAA8D;IAC9D,MAAM,GAAG,GAAI,MAAc,CAAC,IAA2C,CAAC;IACxE,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IAEpB,sEAAsE;IACtE,MAAM,QAAQ,GAAG,GAAG,CAAC,IAA0B,CAAC;IAEhD,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,QAAQ;YACX,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QAE5B,KAAK,QAAQ;YACX,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QAE5B,KAAK,SAAS;YACZ,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAE7B,KAAK,MAAM;YACT,OAAO,E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AAG,CAAC,SAAoB,CAAC,CAAC;QAExD,KAAK,SAAS;YACZ,oFAAoF;YACpF,OAAO,oBAAoB,CAAC,GAAG,CAAC,SAAoB,CAAC,CAAC;QAExD;YACE,2EAA2E;YAC3E,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Validator.ts
|
|
3
|
+
* @description Static graph validator for `CompiledExecutionGraph` IR objects.
|
|
4
|
+
*
|
|
5
|
+
* Validation is split into two severity levels:
|
|
6
|
+
* - **errors** — structural problems that will cause runtime failures (missing entry/exit
|
|
7
|
+
* points, dangling edge references, cycles when acyclicity is required).
|
|
8
|
+
* - **warnings** — non-fatal issues worth investigating (unreachable nodes).
|
|
9
|
+
*
|
|
10
|
+
* The validator delegates cycle detection and reachability analysis to `NodeScheduler`,
|
|
11
|
+
* which already implements Kahn's algorithm and DFS reachability traversal.
|
|
12
|
+
*/
|
|
13
|
+
import type { CompiledExecutionGraph } from '../ir/types.js';
|
|
14
|
+
/**
|
|
15
|
+
* The result returned by `GraphValidator.validate()`.
|
|
16
|
+
*
|
|
17
|
+
* `valid` is `true` iff `errors` is empty — warnings do not affect validity.
|
|
18
|
+
*/
|
|
19
|
+
export interface ValidationResult {
|
|
20
|
+
/** `true` when no structural errors were found. */
|
|
21
|
+
valid: boolean;
|
|
22
|
+
/** Fatal structural problems that would prevent correct execution. */
|
|
23
|
+
errors: string[];
|
|
24
|
+
/** Non-fatal issues that should be reviewed but do not block execution. */
|
|
25
|
+
warnings: string[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Static validator for compiled execution graphs.
|
|
29
|
+
*
|
|
30
|
+
* Runs a suite of structural checks against a `CompiledExecutionGraph`:
|
|
31
|
+
*
|
|
32
|
+
* 1. **Cycle detection** — rejects cyclic graphs when `requireAcyclic` is not `false`.
|
|
33
|
+
* 2. **Unreachable nodes** — warns when one or more nodes cannot be reached from `__START__`.
|
|
34
|
+
* 3. **Edge reference integrity** — errors when an edge's source/target names a non-existent node
|
|
35
|
+
* (ignoring the sentinel values `__START__` and `__END__`).
|
|
36
|
+
* 4. **Entry point** — errors when no edge originates from `__START__`.
|
|
37
|
+
* 5. **Exit point** — errors when no edge terminates at `__END__`.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const result = GraphValidator.validate(graph, { requireAcyclic: true });
|
|
42
|
+
* if (!result.valid) {
|
|
43
|
+
* throw new Error(result.errors.join('\n'));
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare class GraphValidator {
|
|
48
|
+
/**
|
|
49
|
+
* Validates a compiled execution graph.
|
|
50
|
+
*
|
|
51
|
+
* @param graph - The `CompiledExecutionGraph` produced by a compiler pass.
|
|
52
|
+
* @param options - Optional validation flags.
|
|
53
|
+
* @param options.requireAcyclic - When `true` (the default) any cycle is treated as an error.
|
|
54
|
+
* Pass `false` to allow cyclic graphs (e.g. iterative agent loops).
|
|
55
|
+
* @returns A `ValidationResult` describing errors and warnings found.
|
|
56
|
+
*/
|
|
57
|
+
static validate(graph: CompiledExecutionGraph, options?: {
|
|
58
|
+
requireAcyclic?: boolean;
|
|
59
|
+
}): ValidationResult;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=Validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../../src/orchestration/compiler/Validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAO7D;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,KAAK,EAAE,OAAO,CAAC;IACf,sEAAsE;IACtE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,cAAc;IACzB;;;;;;;;OAQG;IACH,MAAM,CAAC,QAAQ,CACb,KAAK,EAAE,sBAAsB,EAC7B,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,OAAO,CAAA;KAAE,GACrC,gBAAgB;CA8DpB"}
|