@darkhorseprojects/circuitry 0.2.25 → 0.2.27

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/graph.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export declare const CIRCUITRY_SPEC_VERSION: "0.2";
2
- export declare const CIRCUITRY_SPEC_VERSION_LEGACY: "0.1";
3
- export type CircuitrySpecVersion = typeof CIRCUITRY_SPEC_VERSION | typeof CIRCUITRY_SPEC_VERSION_LEGACY;
2
+ export type CircuitrySpecVersion = typeof CIRCUITRY_SPEC_VERSION;
4
3
  export type CircuitryNodeKind = "agent" | "input" | "tool" | "output" | string;
5
4
  export type CircuitryEdgeKind = "context" | "dependency" | "message" | "control" | string;
6
5
  export type CircuitryInputKind = "text" | "file" | "url" | "image" | "uri" | "canvas" | "mcp" | string;
@@ -178,12 +177,14 @@ export type CircuitryGraph = {
178
177
  title?: string;
179
178
  description?: string;
180
179
  resources?: Record<string, CircuitryResourceEntry>;
181
- agents?: Record<string, Omit<CircuitryNode, "id" | "kind"> & {
182
- kind?: "agent";
183
- }>;
184
- inputs?: Record<string, Omit<CircuitryInput, "id">>;
180
+ /** Internal normalized execution nodes. Authored graph files must not set this. */
185
181
  nodes?: CircuitryNode[];
182
+ /** Internal normalized execution edges. Authored graph files must not set this. */
186
183
  edges?: CircuitryEdge[];
184
+ /** Rejected legacy field. */
185
+ agents?: never;
186
+ /** Rejected legacy field. */
187
+ inputs?: never;
187
188
  runtime?: CircuitryRuntime;
188
189
  validation?: CircuitryGraphValidation;
189
190
  metadata?: Record<string, unknown>;
@@ -222,6 +223,7 @@ export declare const DEFAULT_CIRCUITRY_VALIDATION_STANDARD: {
222
223
  export declare const createCircuitryValidationStandard: (standard?: CircuitryValidationStandard, graph?: CircuitryGraph) => Required<CircuitryValidationStandard>;
223
224
  export declare const normalizeCircuitryGraph: (graph: CircuitryGraph) => CircuitryGraph;
224
225
  export declare const validateCircuitryGraphWithStandard: (graph: unknown, standard?: CircuitryValidationStandard) => CircuitryValidationResult;
226
+ export declare const validateCircuitryExecutionGraphWithStandard: (graph: unknown, standard?: CircuitryValidationStandard) => CircuitryValidationResult;
225
227
  export declare const validateCircuitryGraph: (graph: unknown, standard?: CircuitryValidationStandard) => string[];
226
228
  export declare const parseCircuitryJson: (text: string, standard?: CircuitryValidationStandard, options?: {
227
229
  validate?: boolean;
package/dist/index.js CHANGED
@@ -28,7 +28,6 @@ var isNodeElement = (element) => {
28
28
 
29
29
  // src/graph.ts
30
30
  var CIRCUITRY_SPEC_VERSION = "0.2";
31
- var CIRCUITRY_SPEC_VERSION_LEGACY = "0.1";
32
31
  var runtimeInputToText = (value) => {
33
32
  if (typeof value === "string") return value;
34
33
  if (value === void 0) return "";
@@ -39,12 +38,7 @@ var applyCircuitryRuntimeInputs = (graph, inputs = {}) => {
39
38
  if (entries.length === 0) return graph;
40
39
  const next = {
41
40
  ...graph,
42
- resources: graph.resources ? { ...graph.resources } : graph.resources,
43
- inputs: graph.inputs ? { ...graph.inputs } : graph.inputs,
44
- nodes: graph.nodes ? graph.nodes.map((node) => ({
45
- ...node,
46
- input: node.input ? { ...node.input } : node.input
47
- })) : graph.nodes
41
+ resources: graph.resources ? { ...graph.resources } : graph.resources
48
42
  };
49
43
  for (const [id, value] of entries) {
50
44
  const text = runtimeInputToText(value);
@@ -55,17 +49,7 @@ var applyCircuitryRuntimeInputs = (graph, inputs = {}) => {
55
49
  next.resources[id] = { ...resource, value: text };
56
50
  continue;
57
51
  }
58
- const legacyInput = next.inputs?.[id];
59
- if (legacyInput) {
60
- next.inputs[id] = { ...legacyInput, value: text };
61
- continue;
62
- }
63
- const node = next.nodes?.find((candidate) => candidate.id === id);
64
- if (node?.kind === "input" && node.input) {
65
- node.input.value = text;
66
- continue;
67
- }
68
- throw new Error(`Runtime input does not match a graph text input: ${id}`);
52
+ throw new Error(`Runtime input does not match a graph text resource: ${id}`);
69
53
  }
70
54
  return next;
71
55
  };
@@ -148,69 +132,12 @@ var expandResources = (resources) => {
148
132
  return { nodes, edges };
149
133
  };
150
134
  var normalizeCircuitryGraph = (graph) => {
151
- if (graph.resources && Object.keys(graph.resources).length > 0) {
152
- const { nodes: nodes2, edges } = expandResources(graph.resources);
153
- return { ...graph, nodes: nodes2, edges };
154
- }
155
- if (graph.nodes && graph.nodes.length > 0) {
156
- const nodeIds = new Set(graph.nodes.map((n) => n.id));
157
- const agents = graph.agents || {};
158
- const inputs = graph.inputs || {};
159
- const nodes2 = [...graph.nodes];
160
- for (const [id, agent] of Object.entries(agents)) {
161
- if (!nodeIds.has(id)) {
162
- nodes2.push({
163
- ...agent,
164
- id,
165
- kind: "agent",
166
- label: agent.label || agent.agent?.identity || id,
167
- agent: {
168
- identity: agent.agent?.identity || agent.label || id,
169
- ...agent.agent
170
- }
171
- });
172
- }
173
- }
174
- for (const [id, input] of Object.entries(inputs)) {
175
- if (!nodeIds.has(id)) {
176
- nodes2.push({
177
- id,
178
- kind: "input",
179
- label: input.label || id,
180
- input
181
- });
182
- }
183
- }
184
- return { ...graph, nodes: nodes2 };
185
- }
186
- const nodes = [];
187
- for (const [id, agent] of Object.entries(graph.agents || {})) {
188
- nodes.push({
189
- ...agent,
190
- id,
191
- kind: "agent",
192
- label: agent.label || agent.agent?.identity || id,
193
- agent: {
194
- identity: agent.agent?.identity || agent.label || id,
195
- ...agent.agent
196
- }
197
- });
198
- }
199
- for (const [id, input] of Object.entries(graph.inputs || {})) {
200
- nodes.push({
201
- id,
202
- kind: "input",
203
- label: input.label || id,
204
- input
205
- });
206
- }
207
- return {
208
- ...graph,
209
- nodes
210
- };
135
+ if (!graph.resources || Object.keys(graph.resources).length === 0) return { ...graph };
136
+ const { nodes, edges } = expandResources(graph.resources);
137
+ return { ...graph, nodes, edges };
211
138
  };
212
139
  var VALID_SPEC_VERSIONS = /* @__PURE__ */ new Set([CIRCUITRY_SPEC_VERSION]);
213
- var validateCircuitryGraphWithStandard = (graph, standard = {}) => {
140
+ var validateCircuitryGraphInternal = (graph, standard = {}, options) => {
214
141
  const resolvedStandard = createCircuitryValidationStandard(
215
142
  standard,
216
143
  graph && typeof graph === "object" && !Array.isArray(graph) ? graph : void 0
@@ -231,15 +158,21 @@ var validateCircuitryGraphWithStandard = (graph, standard = {}) => {
231
158
  ["circuitry"]
232
159
  );
233
160
  }
234
- if (graphObject.circuitry === CIRCUITRY_SPEC_VERSION && graphObject.resources && Object.keys(graphObject.resources).length > 0) {
161
+ if (options.sourceFormat) {
162
+ if (!graphObject.resources || Object.keys(graphObject.resources).length === 0) {
163
+ addError("missing_resources", "Circuitry v0.2 graphs must use a resources: section", ["resources"]);
164
+ }
235
165
  if (graphObject.agents && Object.keys(graphObject.agents).length > 0) {
236
- addError("v02_mixed_format", "v0.2 graphs with resources: must not use legacy agents: section", ["agents"]);
166
+ addError("legacy_agents", "Circuitry v0.2 graphs must not use legacy agents: section", ["agents"]);
237
167
  }
238
168
  if (graphObject.inputs && Object.keys(graphObject.inputs).length > 0) {
239
- addError("v02_mixed_format", "v0.2 graphs with resources: must not use legacy inputs: section", ["inputs"]);
169
+ addError("legacy_inputs", "Circuitry v0.2 graphs must not use legacy inputs: section", ["inputs"]);
240
170
  }
241
- if (graphObject.edges && graphObject.edges.length > 0 && !(graphObject.nodes && graphObject.nodes.length > 0)) {
242
- addError("v02_mixed_format", "v0.2 graphs with resources: must not use legacy edges: section", ["edges"]);
171
+ if (graphObject.nodes && graphObject.nodes.length > 0) {
172
+ addError("legacy_nodes", "Circuitry v0.2 graph files must not use nodes:; use resources:", ["nodes"]);
173
+ }
174
+ if (graphObject.edges && graphObject.edges.length > 0) {
175
+ addError("legacy_edges", "Circuitry v0.2 graph files must not use edges:; use resource inputs:", ["edges"]);
243
176
  }
244
177
  }
245
178
  const normalized = normalizeCircuitryGraph(graphObject);
@@ -384,6 +317,8 @@ var validateCircuitryGraphWithStandard = (graph, standard = {}) => {
384
317
  }
385
318
  return { ok: errors.length === 0, errors, standard: resolvedStandard };
386
319
  };
320
+ var validateCircuitryGraphWithStandard = (graph, standard = {}) => validateCircuitryGraphInternal(graph, standard, { sourceFormat: true });
321
+ var validateCircuitryExecutionGraphWithStandard = (graph, standard = {}) => validateCircuitryGraphInternal(graph, standard, { sourceFormat: false });
387
322
  var validateCircuitryGraph = (graph, standard = {}) => validateCircuitryGraphWithStandard(graph, standard).errors.map(
388
323
  (error) => error.message
389
324
  );
@@ -396,12 +331,11 @@ var parseCircuitryJson = (text, standard = {}, options = {}) => {
396
331
  throw new Error(`Could not parse Circuitry JSON. Check commas, quotes, and braces.
397
332
  ${message}`);
398
333
  }
399
- if (options.validate !== false) {
400
- const errors = validateCircuitryGraph(graph, standard);
401
- if (errors.length) {
402
- throw new Error(`Invalid Circuitry graph:
334
+ if (options.validate === false) return graph;
335
+ const errors = validateCircuitryGraph(graph, standard);
336
+ if (errors.length) {
337
+ throw new Error(`Invalid Circuitry graph:
403
338
  ${errors.join("\n")}`);
404
- }
405
339
  }
406
340
  return normalizeCircuitryGraph(graph);
407
341
  };
@@ -427,12 +361,11 @@ ${message}`);
427
361
  if (!graph || typeof graph !== "object" || Array.isArray(graph)) {
428
362
  throw new Error("Could not parse Circuitry YAML. Expected a graph object.");
429
363
  }
430
- if (options.validate !== false) {
431
- const errors = validateCircuitryGraph(graph, standard);
432
- if (errors.length) {
433
- throw new Error(`Invalid Circuitry graph:
364
+ if (options.validate === false) return graph;
365
+ const errors = validateCircuitryGraph(graph, standard);
366
+ if (errors.length) {
367
+ throw new Error(`Invalid Circuitry graph:
434
368
  ${errors.join("\n")}`);
435
- }
436
369
  }
437
370
  return normalizeCircuitryGraph(graph);
438
371
  };
@@ -694,15 +627,15 @@ var runCircuitryGraphExecution = async ({
694
627
  const ready = [];
695
628
  for (const nodeId of nodeIds) {
696
629
  const node = executionGraph.nodes.get(nodeId);
697
- if (node.completed) {
698
- completed.add(nodeId);
699
- if (node.output) {
700
- outputs.set(nodeId, node.output);
701
- }
702
- continue;
703
- }
630
+ if (!node.completed) continue;
631
+ completed.add(nodeId);
632
+ outputs.set(nodeId, node.output || "");
633
+ }
634
+ for (const nodeId of nodeIds) {
635
+ if (completed.has(nodeId)) continue;
636
+ const node = executionGraph.nodes.get(nodeId);
704
637
  const count = node.inputNodeIds.filter(
705
- (sourceId) => executionGraph.nodes.has(sourceId)
638
+ (sourceId) => executionGraph.nodes.has(sourceId) && !completed.has(sourceId)
706
639
  ).length;
707
640
  remainingDependencies.set(nodeId, count);
708
641
  if (count === 0) {
@@ -1135,7 +1068,6 @@ export {
1135
1068
  CIRCUITRY_NODE_CUSTOM_TYPE,
1136
1069
  CIRCUITRY_NODE_KIND,
1137
1070
  CIRCUITRY_SPEC_VERSION,
1138
- CIRCUITRY_SPEC_VERSION_LEGACY,
1139
1071
  DEFAULT_CIRCUITRY_VALIDATION_RULES,
1140
1072
  DEFAULT_CIRCUITRY_VALIDATION_STANDARD,
1141
1073
  DEFAULT_MAX_PARALLEL_RUNS,
@@ -1169,6 +1101,7 @@ export {
1169
1101
  stringifyCircuitryJson,
1170
1102
  stringifyCircuitryText,
1171
1103
  stringifyCircuitryYaml,
1104
+ validateCircuitryExecutionGraphWithStandard,
1172
1105
  validateCircuitryGraph,
1173
1106
  validateCircuitryGraphWithStandard
1174
1107
  };
package/dist/node.js CHANGED
@@ -19,12 +19,7 @@ var applyCircuitryRuntimeInputs = (graph, inputs = {}) => {
19
19
  if (entries.length === 0) return graph;
20
20
  const next = {
21
21
  ...graph,
22
- resources: graph.resources ? { ...graph.resources } : graph.resources,
23
- inputs: graph.inputs ? { ...graph.inputs } : graph.inputs,
24
- nodes: graph.nodes ? graph.nodes.map((node) => ({
25
- ...node,
26
- input: node.input ? { ...node.input } : node.input
27
- })) : graph.nodes
22
+ resources: graph.resources ? { ...graph.resources } : graph.resources
28
23
  };
29
24
  for (const [id, value] of entries) {
30
25
  const text = runtimeInputToText(value);
@@ -35,17 +30,7 @@ var applyCircuitryRuntimeInputs = (graph, inputs = {}) => {
35
30
  next.resources[id] = { ...resource, value: text };
36
31
  continue;
37
32
  }
38
- const legacyInput = next.inputs?.[id];
39
- if (legacyInput) {
40
- next.inputs[id] = { ...legacyInput, value: text };
41
- continue;
42
- }
43
- const node = next.nodes?.find((candidate) => candidate.id === id);
44
- if (node?.kind === "input" && node.input) {
45
- node.input.value = text;
46
- continue;
47
- }
48
- throw new Error(`Runtime input does not match a graph text input: ${id}`);
33
+ throw new Error(`Runtime input does not match a graph text resource: ${id}`);
49
34
  }
50
35
  return next;
51
36
  };
@@ -128,69 +113,12 @@ var expandResources = (resources) => {
128
113
  return { nodes, edges };
129
114
  };
130
115
  var normalizeCircuitryGraph = (graph) => {
131
- if (graph.resources && Object.keys(graph.resources).length > 0) {
132
- const { nodes: nodes2, edges } = expandResources(graph.resources);
133
- return { ...graph, nodes: nodes2, edges };
134
- }
135
- if (graph.nodes && graph.nodes.length > 0) {
136
- const nodeIds = new Set(graph.nodes.map((n) => n.id));
137
- const agents = graph.agents || {};
138
- const inputs = graph.inputs || {};
139
- const nodes2 = [...graph.nodes];
140
- for (const [id, agent] of Object.entries(agents)) {
141
- if (!nodeIds.has(id)) {
142
- nodes2.push({
143
- ...agent,
144
- id,
145
- kind: "agent",
146
- label: agent.label || agent.agent?.identity || id,
147
- agent: {
148
- identity: agent.agent?.identity || agent.label || id,
149
- ...agent.agent
150
- }
151
- });
152
- }
153
- }
154
- for (const [id, input] of Object.entries(inputs)) {
155
- if (!nodeIds.has(id)) {
156
- nodes2.push({
157
- id,
158
- kind: "input",
159
- label: input.label || id,
160
- input
161
- });
162
- }
163
- }
164
- return { ...graph, nodes: nodes2 };
165
- }
166
- const nodes = [];
167
- for (const [id, agent] of Object.entries(graph.agents || {})) {
168
- nodes.push({
169
- ...agent,
170
- id,
171
- kind: "agent",
172
- label: agent.label || agent.agent?.identity || id,
173
- agent: {
174
- identity: agent.agent?.identity || agent.label || id,
175
- ...agent.agent
176
- }
177
- });
178
- }
179
- for (const [id, input] of Object.entries(graph.inputs || {})) {
180
- nodes.push({
181
- id,
182
- kind: "input",
183
- label: input.label || id,
184
- input
185
- });
186
- }
187
- return {
188
- ...graph,
189
- nodes
190
- };
116
+ if (!graph.resources || Object.keys(graph.resources).length === 0) return { ...graph };
117
+ const { nodes, edges } = expandResources(graph.resources);
118
+ return { ...graph, nodes, edges };
191
119
  };
192
120
  var VALID_SPEC_VERSIONS = /* @__PURE__ */ new Set([CIRCUITRY_SPEC_VERSION]);
193
- var validateCircuitryGraphWithStandard = (graph, standard = {}) => {
121
+ var validateCircuitryGraphInternal = (graph, standard = {}, options) => {
194
122
  const resolvedStandard = createCircuitryValidationStandard(
195
123
  standard,
196
124
  graph && typeof graph === "object" && !Array.isArray(graph) ? graph : void 0
@@ -211,15 +139,21 @@ var validateCircuitryGraphWithStandard = (graph, standard = {}) => {
211
139
  ["circuitry"]
212
140
  );
213
141
  }
214
- if (graphObject.circuitry === CIRCUITRY_SPEC_VERSION && graphObject.resources && Object.keys(graphObject.resources).length > 0) {
142
+ if (options.sourceFormat) {
143
+ if (!graphObject.resources || Object.keys(graphObject.resources).length === 0) {
144
+ addError("missing_resources", "Circuitry v0.2 graphs must use a resources: section", ["resources"]);
145
+ }
215
146
  if (graphObject.agents && Object.keys(graphObject.agents).length > 0) {
216
- addError("v02_mixed_format", "v0.2 graphs with resources: must not use legacy agents: section", ["agents"]);
147
+ addError("legacy_agents", "Circuitry v0.2 graphs must not use legacy agents: section", ["agents"]);
217
148
  }
218
149
  if (graphObject.inputs && Object.keys(graphObject.inputs).length > 0) {
219
- addError("v02_mixed_format", "v0.2 graphs with resources: must not use legacy inputs: section", ["inputs"]);
150
+ addError("legacy_inputs", "Circuitry v0.2 graphs must not use legacy inputs: section", ["inputs"]);
220
151
  }
221
- if (graphObject.edges && graphObject.edges.length > 0 && !(graphObject.nodes && graphObject.nodes.length > 0)) {
222
- addError("v02_mixed_format", "v0.2 graphs with resources: must not use legacy edges: section", ["edges"]);
152
+ if (graphObject.nodes && graphObject.nodes.length > 0) {
153
+ addError("legacy_nodes", "Circuitry v0.2 graph files must not use nodes:; use resources:", ["nodes"]);
154
+ }
155
+ if (graphObject.edges && graphObject.edges.length > 0) {
156
+ addError("legacy_edges", "Circuitry v0.2 graph files must not use edges:; use resource inputs:", ["edges"]);
223
157
  }
224
158
  }
225
159
  const normalized = normalizeCircuitryGraph(graphObject);
@@ -364,6 +298,8 @@ var validateCircuitryGraphWithStandard = (graph, standard = {}) => {
364
298
  }
365
299
  return { ok: errors.length === 0, errors, standard: resolvedStandard };
366
300
  };
301
+ var validateCircuitryGraphWithStandard = (graph, standard = {}) => validateCircuitryGraphInternal(graph, standard, { sourceFormat: true });
302
+ var validateCircuitryExecutionGraphWithStandard = (graph, standard = {}) => validateCircuitryGraphInternal(graph, standard, { sourceFormat: false });
367
303
  var validateCircuitryGraph = (graph, standard = {}) => validateCircuitryGraphWithStandard(graph, standard).errors.map(
368
304
  (error) => error.message
369
305
  );
@@ -376,12 +312,11 @@ var parseCircuitryJson = (text, standard = {}, options = {}) => {
376
312
  throw new Error(`Could not parse Circuitry JSON. Check commas, quotes, and braces.
377
313
  ${message}`);
378
314
  }
379
- if (options.validate !== false) {
380
- const errors = validateCircuitryGraph(graph, standard);
381
- if (errors.length) {
382
- throw new Error(`Invalid Circuitry graph:
315
+ if (options.validate === false) return graph;
316
+ const errors = validateCircuitryGraph(graph, standard);
317
+ if (errors.length) {
318
+ throw new Error(`Invalid Circuitry graph:
383
319
  ${errors.join("\n")}`);
384
- }
385
320
  }
386
321
  return normalizeCircuitryGraph(graph);
387
322
  };
@@ -403,12 +338,11 @@ ${message}`);
403
338
  if (!graph || typeof graph !== "object" || Array.isArray(graph)) {
404
339
  throw new Error("Could not parse Circuitry YAML. Expected a graph object.");
405
340
  }
406
- if (options.validate !== false) {
407
- const errors = validateCircuitryGraph(graph, standard);
408
- if (errors.length) {
409
- throw new Error(`Invalid Circuitry graph:
341
+ if (options.validate === false) return graph;
342
+ const errors = validateCircuitryGraph(graph, standard);
343
+ if (errors.length) {
344
+ throw new Error(`Invalid Circuitry graph:
410
345
  ${errors.join("\n")}`);
411
- }
412
346
  }
413
347
  return normalizeCircuitryGraph(graph);
414
348
  };
@@ -615,15 +549,15 @@ var runCircuitryGraphExecution = async ({
615
549
  const ready = [];
616
550
  for (const nodeId of nodeIds) {
617
551
  const node = executionGraph.nodes.get(nodeId);
618
- if (node.completed) {
619
- completed.add(nodeId);
620
- if (node.output) {
621
- outputs.set(nodeId, node.output);
622
- }
623
- continue;
624
- }
552
+ if (!node.completed) continue;
553
+ completed.add(nodeId);
554
+ outputs.set(nodeId, node.output || "");
555
+ }
556
+ for (const nodeId of nodeIds) {
557
+ if (completed.has(nodeId)) continue;
558
+ const node = executionGraph.nodes.get(nodeId);
625
559
  const count = node.inputNodeIds.filter(
626
- (sourceId) => executionGraph.nodes.has(sourceId)
560
+ (sourceId) => executionGraph.nodes.has(sourceId) && !completed.has(sourceId)
627
561
  ).length;
628
562
  remainingDependencies.set(nodeId, count);
629
563
  if (count === 0) {
@@ -869,10 +803,10 @@ ${validation.errors.map((e) => e.message).join("\n")}`
869
803
  throw new Error(`Invalid Circuitry graph:
870
804
  ${parsed.error?.message}`);
871
805
  const runnableGraph = applyCircuitryRuntimeInputs(parsed.graph, input.inputs);
872
- const validation = await this.validateGraph({
873
- graph: runnableGraph,
874
- standard: input.standard
875
- });
806
+ const validation = validateCircuitryExecutionGraphWithStandard(
807
+ runnableGraph,
808
+ input.standard
809
+ );
876
810
  if (validation.errors.length)
877
811
  throw new Error(
878
812
  `Invalid Circuitry graph:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkhorseprojects/circuitry",
3
- "version": "0.2.25",
3
+ "version": "0.2.27",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",