@inf-minds/kernel 0.0.1
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/condition-evaluator.d.ts +69 -0
- package/dist/condition-evaluator.d.ts.map +1 -0
- package/dist/condition-evaluator.js +120 -0
- package/dist/condition-evaluator.js.map +1 -0
- package/dist/graph-executor.d.ts +63 -0
- package/dist/graph-executor.d.ts.map +1 -0
- package/dist/graph-executor.js +245 -0
- package/dist/graph-executor.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/kernel.d.ts +45 -0
- package/dist/kernel.d.ts.map +1 -0
- package/dist/kernel.js +202 -0
- package/dist/kernel.js.map +1 -0
- package/dist/registries/index.d.ts +3 -0
- package/dist/registries/index.d.ts.map +1 -0
- package/dist/registries/index.js +5 -0
- package/dist/registries/index.js.map +1 -0
- package/dist/registries/mind-registry.d.ts +11 -0
- package/dist/registries/mind-registry.d.ts.map +1 -0
- package/dist/registries/mind-registry.js +31 -0
- package/dist/registries/mind-registry.js.map +1 -0
- package/dist/registries/mode-registry.d.ts +11 -0
- package/dist/registries/mode-registry.d.ts.map +1 -0
- package/dist/registries/mode-registry.js +31 -0
- package/dist/registries/mode-registry.js.map +1 -0
- package/dist/session.d.ts +123 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +403 -0
- package/dist/session.js.map +1 -0
- package/dist/types.d.ts +288 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/package.json +37 -0
- package/src/condition-evaluator.ts +168 -0
- package/src/graph-executor.ts +315 -0
- package/src/index.ts +50 -0
- package/src/kernel.ts +242 -0
- package/src/registries/index.ts +5 -0
- package/src/registries/mind-registry.ts +38 -0
- package/src/registries/mode-registry.ts +38 -0
- package/src/session.ts +541 -0
- package/src/types.ts +280 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context object passed to condition expressions.
|
|
3
|
+
*/
|
|
4
|
+
export interface ConditionContext {
|
|
5
|
+
/** Output from the source node */
|
|
6
|
+
output: unknown;
|
|
7
|
+
/** Current graph state */
|
|
8
|
+
graphState?: {
|
|
9
|
+
completedNodes: string[];
|
|
10
|
+
activeNodes: string[];
|
|
11
|
+
nodeOutputs?: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
/** Current iteration count (for loops) */
|
|
14
|
+
iteration?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Result of condition evaluation.
|
|
18
|
+
*/
|
|
19
|
+
export interface EvaluationResult {
|
|
20
|
+
/** Whether the condition evaluated to true */
|
|
21
|
+
result: boolean;
|
|
22
|
+
/** Error message if evaluation failed */
|
|
23
|
+
error?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Evaluate a condition expression against a context.
|
|
27
|
+
*
|
|
28
|
+
* The condition is a JavaScript expression that has access to:
|
|
29
|
+
* - `output` - The output from the source node
|
|
30
|
+
* - `graphState` - Current graph execution state
|
|
31
|
+
* - `iteration` - Current iteration count (for loops)
|
|
32
|
+
*
|
|
33
|
+
* Examples:
|
|
34
|
+
* - `output.done === true`
|
|
35
|
+
* - `output.tasks.length > 0`
|
|
36
|
+
* - `iteration < 5`
|
|
37
|
+
* - `output.allTasksComplete`
|
|
38
|
+
* - `graphState.completedNodes.includes('research')`
|
|
39
|
+
*
|
|
40
|
+
* @param expression - JavaScript expression to evaluate
|
|
41
|
+
* @param context - Context object with output, graphState, iteration
|
|
42
|
+
* @returns Evaluation result with boolean result or error
|
|
43
|
+
*/
|
|
44
|
+
export declare function evaluateCondition(expression: string, context: ConditionContext): EvaluationResult;
|
|
45
|
+
/**
|
|
46
|
+
* Check if a string looks like a valid condition expression.
|
|
47
|
+
* This is a quick heuristic check, not a full validation.
|
|
48
|
+
*/
|
|
49
|
+
export declare function isValidConditionExpression(expression: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Common condition expressions for reference.
|
|
52
|
+
*/
|
|
53
|
+
export declare const COMMON_CONDITIONS: {
|
|
54
|
+
/** Node output indicates completion */
|
|
55
|
+
readonly OUTPUT_DONE: "output.done === true";
|
|
56
|
+
/** Node output indicates all tasks complete */
|
|
57
|
+
readonly ALL_TASKS_COMPLETE: "output.allTasksComplete";
|
|
58
|
+
/** Node has a delegated task */
|
|
59
|
+
readonly HAS_DELEGATED_TASK: "output.delegatedTask";
|
|
60
|
+
/** Output has items to process */
|
|
61
|
+
readonly HAS_ITEMS: "output.items && output.items.length > 0";
|
|
62
|
+
/** Iteration count under limit */
|
|
63
|
+
readonly UNDER_MAX_ITERATIONS: "iteration < 10";
|
|
64
|
+
/** Output indicates success */
|
|
65
|
+
readonly SUCCESS: "output.success === true";
|
|
66
|
+
/** Output indicates failure */
|
|
67
|
+
readonly FAILURE: "output.success === false";
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=condition-evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-evaluator.d.ts","sourceRoot":"","sources":["../src/condition-evaluator.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kCAAkC;IAClC,MAAM,EAAE,OAAO,CAAC;IAChB,0BAA0B;IAC1B,UAAU,CAAC,EAAE;QACX,cAAc,EAAE,MAAM,EAAE,CAAC;QACzB,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACvC,CAAC;IACF,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8CAA8C;IAC9C,MAAM,EAAE,OAAO,CAAC;IAChB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,gBAAgB,GACxB,gBAAgB,CA+BlB;AAoDD;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAStE;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB;IAC5B,uCAAuC;;IAEvC,+CAA+C;;IAE/C,gCAAgC;;IAEhC,kCAAkC;;IAElC,kCAAkC;;IAElC,+BAA+B;;IAE/B,+BAA+B;;CAEvB,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// ABOUTME: Safe condition evaluation for graph edges and node exit conditions
|
|
2
|
+
// ABOUTME: Uses sandboxed function execution for expression evaluation
|
|
3
|
+
/**
|
|
4
|
+
* Evaluate a condition expression against a context.
|
|
5
|
+
*
|
|
6
|
+
* The condition is a JavaScript expression that has access to:
|
|
7
|
+
* - `output` - The output from the source node
|
|
8
|
+
* - `graphState` - Current graph execution state
|
|
9
|
+
* - `iteration` - Current iteration count (for loops)
|
|
10
|
+
*
|
|
11
|
+
* Examples:
|
|
12
|
+
* - `output.done === true`
|
|
13
|
+
* - `output.tasks.length > 0`
|
|
14
|
+
* - `iteration < 5`
|
|
15
|
+
* - `output.allTasksComplete`
|
|
16
|
+
* - `graphState.completedNodes.includes('research')`
|
|
17
|
+
*
|
|
18
|
+
* @param expression - JavaScript expression to evaluate
|
|
19
|
+
* @param context - Context object with output, graphState, iteration
|
|
20
|
+
* @returns Evaluation result with boolean result or error
|
|
21
|
+
*/
|
|
22
|
+
export function evaluateCondition(expression, context) {
|
|
23
|
+
try {
|
|
24
|
+
// Validate expression for safety
|
|
25
|
+
const validationError = validateExpression(expression);
|
|
26
|
+
if (validationError) {
|
|
27
|
+
return { result: false, error: validationError };
|
|
28
|
+
}
|
|
29
|
+
// Create sandboxed function
|
|
30
|
+
const fn = new Function('output', 'graphState', 'iteration', `"use strict"; return (${expression});`);
|
|
31
|
+
// Execute with context
|
|
32
|
+
const result = fn(context.output, context.graphState ?? { completedNodes: [], activeNodes: [] }, context.iteration ?? 0);
|
|
33
|
+
// Coerce to boolean
|
|
34
|
+
return { result: Boolean(result) };
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return {
|
|
38
|
+
result: false,
|
|
39
|
+
error: error instanceof Error ? error.message : String(error),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Validate a condition expression for safety.
|
|
45
|
+
* Returns an error message if the expression is unsafe, undefined otherwise.
|
|
46
|
+
*/
|
|
47
|
+
function validateExpression(expression) {
|
|
48
|
+
// Block potentially dangerous constructs
|
|
49
|
+
const blockedPatterns = [
|
|
50
|
+
/\beval\b/,
|
|
51
|
+
/\bFunction\b/,
|
|
52
|
+
/\bsetTimeout\b/,
|
|
53
|
+
/\bsetInterval\b/,
|
|
54
|
+
/\bsetImmediate\b/,
|
|
55
|
+
/\brequire\b/,
|
|
56
|
+
/\bimport\b/,
|
|
57
|
+
/\bprocess\b/,
|
|
58
|
+
/\bglobal\b/,
|
|
59
|
+
/\bglobalThis\b/,
|
|
60
|
+
/\bwindow\b/,
|
|
61
|
+
/\bdocument\b/,
|
|
62
|
+
/\bfetch\b/,
|
|
63
|
+
/\bXMLHttpRequest\b/,
|
|
64
|
+
/\bWebSocket\b/,
|
|
65
|
+
/\b__proto__\b/,
|
|
66
|
+
/\bconstructor\b/,
|
|
67
|
+
/\bprototype\b/,
|
|
68
|
+
/\bObject\.assign\b/,
|
|
69
|
+
/\bObject\.defineProperty\b/,
|
|
70
|
+
/\bReflect\b/,
|
|
71
|
+
/\bProxy\b/,
|
|
72
|
+
];
|
|
73
|
+
for (const pattern of blockedPatterns) {
|
|
74
|
+
if (pattern.test(expression)) {
|
|
75
|
+
return `Expression contains blocked construct: ${pattern.source}`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Block assignment operators (but allow == and ===)
|
|
79
|
+
if (/[^=!<>]=[^=]/.test(expression) && !/=>/.test(expression)) {
|
|
80
|
+
return 'Expression contains assignment operator';
|
|
81
|
+
}
|
|
82
|
+
// Block function definitions
|
|
83
|
+
if (/\bfunction\b/.test(expression)) {
|
|
84
|
+
return 'Expression contains function definition';
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Check if a string looks like a valid condition expression.
|
|
90
|
+
* This is a quick heuristic check, not a full validation.
|
|
91
|
+
*/
|
|
92
|
+
export function isValidConditionExpression(expression) {
|
|
93
|
+
// Must be non-empty
|
|
94
|
+
if (!expression || expression.trim().length === 0) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
// Validate
|
|
98
|
+
const error = validateExpression(expression);
|
|
99
|
+
return error === undefined;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Common condition expressions for reference.
|
|
103
|
+
*/
|
|
104
|
+
export const COMMON_CONDITIONS = {
|
|
105
|
+
/** Node output indicates completion */
|
|
106
|
+
OUTPUT_DONE: 'output.done === true',
|
|
107
|
+
/** Node output indicates all tasks complete */
|
|
108
|
+
ALL_TASKS_COMPLETE: 'output.allTasksComplete',
|
|
109
|
+
/** Node has a delegated task */
|
|
110
|
+
HAS_DELEGATED_TASK: 'output.delegatedTask',
|
|
111
|
+
/** Output has items to process */
|
|
112
|
+
HAS_ITEMS: 'output.items && output.items.length > 0',
|
|
113
|
+
/** Iteration count under limit */
|
|
114
|
+
UNDER_MAX_ITERATIONS: 'iteration < 10',
|
|
115
|
+
/** Output indicates success */
|
|
116
|
+
SUCCESS: 'output.success === true',
|
|
117
|
+
/** Output indicates failure */
|
|
118
|
+
FAILURE: 'output.success === false',
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=condition-evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-evaluator.js","sourceRoot":"","sources":["../src/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C,+BAA+B;IAC/B,OAAO,EAAE,0BAA0B;CAC3B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { CoordinationMode } from '@inf-minds/coordination-modes';
|
|
2
|
+
import type { GraphState } from '@inf-minds/jobs';
|
|
3
|
+
/**
|
|
4
|
+
* Result of determining the next nodes to execute.
|
|
5
|
+
*/
|
|
6
|
+
export interface NextNodesResult {
|
|
7
|
+
/** Node IDs to start executing */
|
|
8
|
+
nodesToStart: string[];
|
|
9
|
+
/** Node IDs that were skipped (condition not met) */
|
|
10
|
+
skippedNodes: string[];
|
|
11
|
+
/** Whether the session should complete */
|
|
12
|
+
shouldComplete: boolean;
|
|
13
|
+
/** Final output if session should complete */
|
|
14
|
+
finalOutput?: unknown;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Options for determining next nodes.
|
|
18
|
+
*/
|
|
19
|
+
export interface DetermineNextNodesOptions {
|
|
20
|
+
/** The coordination mode */
|
|
21
|
+
mode: CoordinationMode;
|
|
22
|
+
/** Current graph state */
|
|
23
|
+
graphState: GraphState;
|
|
24
|
+
/** Node that just completed (or null if starting) */
|
|
25
|
+
completedNodeId: string | null;
|
|
26
|
+
/** Output from the completed node */
|
|
27
|
+
completedOutput: unknown;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Determine which nodes should be executed next after a node completes.
|
|
31
|
+
*
|
|
32
|
+
* This function:
|
|
33
|
+
* 1. Finds outgoing edges from the completed node
|
|
34
|
+
* 2. Evaluates edge conditions
|
|
35
|
+
* 3. Handles loop logic (exit conditions and max iterations)
|
|
36
|
+
* 4. Checks if session should complete
|
|
37
|
+
*/
|
|
38
|
+
export declare function determineNextNodes(options: DetermineNextNodesOptions): NextNodesResult;
|
|
39
|
+
/**
|
|
40
|
+
* Update graph state when a node starts.
|
|
41
|
+
*/
|
|
42
|
+
export declare function updateStateForNodeStart(graphState: GraphState, nodeId: string, jobId: string): GraphState;
|
|
43
|
+
/**
|
|
44
|
+
* Update graph state when a node completes.
|
|
45
|
+
*/
|
|
46
|
+
export declare function updateStateForNodeComplete(graphState: GraphState, nodeId: string, output: unknown): GraphState;
|
|
47
|
+
/**
|
|
48
|
+
* Update graph state when a node fails.
|
|
49
|
+
*/
|
|
50
|
+
export declare function updateStateForNodeFailure(graphState: GraphState, nodeId: string, error: string): GraphState;
|
|
51
|
+
/**
|
|
52
|
+
* Update graph state when a node is skipped.
|
|
53
|
+
*/
|
|
54
|
+
export declare function updateStateForNodeSkipped(graphState: GraphState, nodeId: string, reason: string): GraphState;
|
|
55
|
+
/**
|
|
56
|
+
* Mark graph state as completed.
|
|
57
|
+
*/
|
|
58
|
+
export declare function markGraphComplete(graphState: GraphState): GraphState;
|
|
59
|
+
/**
|
|
60
|
+
* Mark graph state as failed.
|
|
61
|
+
*/
|
|
62
|
+
export declare function markGraphFailed(graphState: GraphState): GraphState;
|
|
63
|
+
//# sourceMappingURL=graph-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-executor.d.ts","sourceRoot":"","sources":["../src/graph-executor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,iBAAiB,CAAC;AAGlE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,kCAAkC;IAClC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,qDAAqD;IACrD,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,0CAA0C;IAC1C,cAAc,EAAE,OAAO,CAAC;IACxB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,4BAA4B;IAC5B,IAAI,EAAE,gBAAgB,CAAC;IACvB,0BAA0B;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,qDAAqD;IACrD,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,qCAAqC;IACrC,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,eAAe,CA+GtF;AAyBD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,UAAU,CAmBZ;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,GACd,UAAU,CAoBZ;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,UAAU,CAoBZ;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,UAAU,CAmBZ;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAMpE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAMlE"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// ABOUTME: Graph executor for coordination mode execution
|
|
2
|
+
// ABOUTME: Handles node scheduling, edge traversal, and state management
|
|
3
|
+
import { evaluateCondition } from './condition-evaluator.js';
|
|
4
|
+
/**
|
|
5
|
+
* Determine which nodes should be executed next after a node completes.
|
|
6
|
+
*
|
|
7
|
+
* This function:
|
|
8
|
+
* 1. Finds outgoing edges from the completed node
|
|
9
|
+
* 2. Evaluates edge conditions
|
|
10
|
+
* 3. Handles loop logic (exit conditions and max iterations)
|
|
11
|
+
* 4. Checks if session should complete
|
|
12
|
+
*/
|
|
13
|
+
export function determineNextNodes(options) {
|
|
14
|
+
const { mode, graphState, completedNodeId, completedOutput } = options;
|
|
15
|
+
const nodesToStart = [];
|
|
16
|
+
const skippedNodes = [];
|
|
17
|
+
// If no completed node, we're starting - go to entry node
|
|
18
|
+
if (!completedNodeId) {
|
|
19
|
+
return {
|
|
20
|
+
nodesToStart: [mode.graph.entryNode],
|
|
21
|
+
skippedNodes: [],
|
|
22
|
+
shouldComplete: false,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
// Get the completed node definition
|
|
26
|
+
const completedNode = mode.graph.nodes[completedNodeId];
|
|
27
|
+
if (!completedNode) {
|
|
28
|
+
return {
|
|
29
|
+
nodesToStart: [],
|
|
30
|
+
skippedNodes: [],
|
|
31
|
+
shouldComplete: true,
|
|
32
|
+
finalOutput: { error: `Node ${completedNodeId} not found in graph` },
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// Check if this is an exit node
|
|
36
|
+
const isExitNode = mode.graph.exitNodes.includes(completedNodeId);
|
|
37
|
+
// Count iterations for loop handling
|
|
38
|
+
const currentIteration = graphState.nodes[completedNodeId]?.jobId
|
|
39
|
+
? countIterations(graphState, completedNodeId)
|
|
40
|
+
: 0;
|
|
41
|
+
// Build condition context (reused for edge and exit conditions)
|
|
42
|
+
const context = {
|
|
43
|
+
output: completedOutput,
|
|
44
|
+
graphState: {
|
|
45
|
+
completedNodes: graphState.completedNodes,
|
|
46
|
+
activeNodes: graphState.activeNodes,
|
|
47
|
+
nodeOutputs: extractNodeOutputs(graphState),
|
|
48
|
+
},
|
|
49
|
+
iteration: currentIteration,
|
|
50
|
+
};
|
|
51
|
+
// Find outgoing edges
|
|
52
|
+
const outgoingEdges = mode.graph.edges.filter((e) => e.from === completedNodeId);
|
|
53
|
+
// Evaluate conditions for each outgoing edge FIRST
|
|
54
|
+
for (const edge of outgoingEdges) {
|
|
55
|
+
if (edge.condition) {
|
|
56
|
+
const evalResult = evaluateCondition(edge.condition, context);
|
|
57
|
+
if (evalResult.result) {
|
|
58
|
+
nodesToStart.push(edge.to);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
skippedNodes.push(edge.to);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// No condition - always traverse
|
|
66
|
+
nodesToStart.push(edge.to);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// If we have nodes to traverse, go to them (regardless of exit condition)
|
|
70
|
+
if (nodesToStart.length > 0) {
|
|
71
|
+
return {
|
|
72
|
+
nodesToStart,
|
|
73
|
+
skippedNodes,
|
|
74
|
+
shouldComplete: false,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// No edges to traverse - check exit condition for potential looping
|
|
78
|
+
if (completedNode.exitCondition) {
|
|
79
|
+
const exitResult = evaluateCondition(completedNode.exitCondition, context);
|
|
80
|
+
// If exit condition is NOT met and under max iterations, loop back
|
|
81
|
+
if (!exitResult.result) {
|
|
82
|
+
const maxIterations = completedNode.maxIterations ?? Infinity;
|
|
83
|
+
if (currentIteration < maxIterations) {
|
|
84
|
+
// Loop: re-execute this node
|
|
85
|
+
return {
|
|
86
|
+
nodesToStart: [completedNodeId],
|
|
87
|
+
skippedNodes,
|
|
88
|
+
shouldComplete: false,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Exit condition met or max iterations reached - session should complete
|
|
93
|
+
}
|
|
94
|
+
// No edges taken and either:
|
|
95
|
+
// - No exit condition (so we just complete)
|
|
96
|
+
// - Exit condition is met
|
|
97
|
+
// - Max iterations reached
|
|
98
|
+
if (isExitNode || outgoingEdges.length === 0) {
|
|
99
|
+
return {
|
|
100
|
+
nodesToStart: [],
|
|
101
|
+
skippedNodes,
|
|
102
|
+
shouldComplete: true,
|
|
103
|
+
finalOutput: completedOutput,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// Dead end but not an exit node - this is a graph issue
|
|
107
|
+
return {
|
|
108
|
+
nodesToStart: [],
|
|
109
|
+
skippedNodes,
|
|
110
|
+
shouldComplete: true,
|
|
111
|
+
finalOutput: { error: `Node ${completedNodeId} has no traversable edges and is not an exit node` },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Count how many times a node has been executed in this session.
|
|
116
|
+
*/
|
|
117
|
+
function countIterations(graphState, nodeId) {
|
|
118
|
+
// In the current model, we track iterations through job count
|
|
119
|
+
// For now, count how many times the node appears in completedNodes
|
|
120
|
+
// A more robust implementation would track this in the node state
|
|
121
|
+
return graphState.completedNodes.filter((id) => id === nodeId).length + 1;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Extract node outputs from graph state.
|
|
125
|
+
*/
|
|
126
|
+
function extractNodeOutputs(graphState) {
|
|
127
|
+
const outputs = {};
|
|
128
|
+
for (const [nodeId, nodeState] of Object.entries(graphState.nodes)) {
|
|
129
|
+
if (nodeState.output !== undefined) {
|
|
130
|
+
outputs[nodeId] = nodeState.output;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return outputs;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Update graph state when a node starts.
|
|
137
|
+
*/
|
|
138
|
+
export function updateStateForNodeStart(graphState, nodeId, jobId) {
|
|
139
|
+
const nodeState = graphState.nodes[nodeId] ?? {
|
|
140
|
+
nodeId,
|
|
141
|
+
status: 'pending',
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
...graphState,
|
|
145
|
+
nodes: {
|
|
146
|
+
...graphState.nodes,
|
|
147
|
+
[nodeId]: {
|
|
148
|
+
...nodeState,
|
|
149
|
+
status: 'active',
|
|
150
|
+
jobId,
|
|
151
|
+
startedAt: new Date().toISOString(),
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
activeNodes: [...graphState.activeNodes.filter((id) => id !== nodeId), nodeId],
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Update graph state when a node completes.
|
|
159
|
+
*/
|
|
160
|
+
export function updateStateForNodeComplete(graphState, nodeId, output) {
|
|
161
|
+
const nodeState = graphState.nodes[nodeId];
|
|
162
|
+
if (!nodeState) {
|
|
163
|
+
return graphState;
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
...graphState,
|
|
167
|
+
nodes: {
|
|
168
|
+
...graphState.nodes,
|
|
169
|
+
[nodeId]: {
|
|
170
|
+
...nodeState,
|
|
171
|
+
status: 'completed',
|
|
172
|
+
output,
|
|
173
|
+
completedAt: new Date().toISOString(),
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
activeNodes: graphState.activeNodes.filter((id) => id !== nodeId),
|
|
177
|
+
completedNodes: [...graphState.completedNodes, nodeId],
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Update graph state when a node fails.
|
|
182
|
+
*/
|
|
183
|
+
export function updateStateForNodeFailure(graphState, nodeId, error) {
|
|
184
|
+
const nodeState = graphState.nodes[nodeId];
|
|
185
|
+
if (!nodeState) {
|
|
186
|
+
return graphState;
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
...graphState,
|
|
190
|
+
nodes: {
|
|
191
|
+
...graphState.nodes,
|
|
192
|
+
[nodeId]: {
|
|
193
|
+
...nodeState,
|
|
194
|
+
status: 'failed',
|
|
195
|
+
error,
|
|
196
|
+
completedAt: new Date().toISOString(),
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
activeNodes: graphState.activeNodes.filter((id) => id !== nodeId),
|
|
200
|
+
failedNodes: [...graphState.failedNodes, nodeId],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Update graph state when a node is skipped.
|
|
205
|
+
*/
|
|
206
|
+
export function updateStateForNodeSkipped(graphState, nodeId, reason) {
|
|
207
|
+
const nodeState = graphState.nodes[nodeId] ?? {
|
|
208
|
+
nodeId,
|
|
209
|
+
status: 'pending',
|
|
210
|
+
};
|
|
211
|
+
return {
|
|
212
|
+
...graphState,
|
|
213
|
+
nodes: {
|
|
214
|
+
...graphState.nodes,
|
|
215
|
+
[nodeId]: {
|
|
216
|
+
...nodeState,
|
|
217
|
+
status: 'skipped',
|
|
218
|
+
error: reason,
|
|
219
|
+
completedAt: new Date().toISOString(),
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
skippedNodes: [...graphState.skippedNodes, nodeId],
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Mark graph state as completed.
|
|
227
|
+
*/
|
|
228
|
+
export function markGraphComplete(graphState) {
|
|
229
|
+
return {
|
|
230
|
+
...graphState,
|
|
231
|
+
status: 'completed',
|
|
232
|
+
completedAt: new Date().toISOString(),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Mark graph state as failed.
|
|
237
|
+
*/
|
|
238
|
+
export function markGraphFailed(graphState) {
|
|
239
|
+
return {
|
|
240
|
+
...graphState,
|
|
241
|
+
status: 'failed',
|
|
242
|
+
completedAt: new Date().toISOString(),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=graph-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-executor.js","sourceRoot":"","sources":["../src/graph-executor.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,yEAAyE;AAIzE,OAAO,EAAE,iBAAiB,EAAyB,MAAM,0BAA0B,CAAC;AA8BpF;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkC;IACnE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IACvE,MAAM,YAAY,GAAa,EAAE,CAAC;IAClC,MAAM,YAAY,GAAa,EAAE,CAAC;IAElC,0DAA0D;IAC1D,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO;YACL,YAAY,EAAE,CAAC,IAAI,CAAC,K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C,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,MAAM,CAAC;QACjE,WAAW,EAAE,CAAC,GAAG,UAAU,CAAC,WAAW,EAAE,MAAM,CAAC;KACjD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CACvC,UAAsB,EACtB,MAAc,EACd,MAAc;IAEd,MAAM,SAAS,GAAmB,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI;QAC5D,MAAM;QACN,MAAM,EAAE,SAAS;KAClB,CAAC;IAEF,OAAO;QACL,GAAG,UAAU;QACb,KAAK,EAAE;YACL,GAAG,UAAU,CAAC,KAAK;YACnB,CAAC,MAAM,CAAC,EAAE;gBACR,GAAG,SAAS;gBACZ,MAAM,EAAE,SAAS;gBACjB,KAAK,EAAE,MAAM;gBACb,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACtC;SACF;QACD,YAAY,EAAE,CAAC,GAAG,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC;KACnD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAsB;IACtD,OAAO;QACL,GAAG,UAAU;QACb,MAAM,EAAE,WAAW;QACnB,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACtC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,UAAsB;IACpD,OAAO;QACL,GAAG,UAAU;QACb,MAAM,EAAE,QAAQ;QAChB,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACtC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { SessionStatus, Unsubscribe, SessionFilter, CreateSessionOptions, SessionEvent, KernelSession, Kernel, KernelOptions, MindRegistry, ModeRegistry, StartNodeOptions, NodeCompletionOptions, GraphState, } from './types.js';
|
|
2
|
+
export { SESSION_STATUS } from './types.js';
|
|
3
|
+
export { createMindRegistry, createModeRegistry } from './registries/index.js';
|
|
4
|
+
export { createKernel } from './kernel.js';
|
|
5
|
+
export { evaluateCondition, isValidConditionExpression, COMMON_CONDITIONS, type ConditionContext, type EvaluationResult, } from './condition-evaluator.js';
|
|
6
|
+
export { determineNextNodes, updateStateForNodeStart, updateStateForNodeComplete, updateStateForNodeFailure, updateStateForNodeSkipped, markGraphComplete, markGraphFailed, type NextNodesResult, type DetermineNextNodesOptions, } from './graph-executor.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,YAAY,EACV,aAAa,EACb,WAAW,EACX,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,MAAM,EACN,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAG/E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACtB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,0BAA0B,EAC1B,yBAAyB,EACzB,yBAAyB,EACzB,iBAAiB,EACjB,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,yBAAyB,GAC/B,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// ABOUTME: Kernel package entry point
|
|
2
|
+
// ABOUTME: Exports kernel session orchestration and graph execution
|
|
3
|
+
// Constant exports
|
|
4
|
+
export { SESSION_STATUS } from './types.js';
|
|
5
|
+
// Registry exports
|
|
6
|
+
export { createMindRegistry, createModeRegistry } from './registries/index.js';
|
|
7
|
+
// Kernel factory
|
|
8
|
+
export { createKernel } from './kernel.js';
|
|
9
|
+
// Condition evaluator
|
|
10
|
+
export { evaluateCondition, isValidConditionExpression, COMMON_CONDITIONS, } from './condition-evaluator.js';
|
|
11
|
+
// Graph executor utilities
|
|
12
|
+
export { determineNextNodes, updateStateForNodeStart, updateStateForNodeComplete, updateStateForNodeFailure, updateStateForNodeSkipped, markGraphComplete, markGraphFailed, } from './graph-executor.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,oEAAoE;AAmBpE,mBAAmB;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,mBAAmB;AACnB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE/E,iBAAiB;AACjB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,sBAAsB;AACtB,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,GAGlB,MAAM,0BAA0B,CAAC;AAElC,2BAA2B;AAC3B,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,0BAA0B,EAC1B,yBAAyB,EACzB,yBAAyB,EACzB,iBAAiB,EACjB,eAAe,GAGhB,MAAM,qBAAqB,CAAC"}
|
package/dist/kernel.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Kernel, KernelOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a new kernel instance.
|
|
4
|
+
*
|
|
5
|
+
* The kernel is the central orchestrator for multi-mind coordination.
|
|
6
|
+
* It manages:
|
|
7
|
+
* - Mind configurations (registered by name)
|
|
8
|
+
* - Coordination modes (execution graphs)
|
|
9
|
+
* - Sessions (executing instances of modes)
|
|
10
|
+
*
|
|
11
|
+
* @param options - Kernel configuration options
|
|
12
|
+
* @returns A new Kernel instance
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const kernel = createKernel({
|
|
17
|
+
* jobManager,
|
|
18
|
+
* eventAppender,
|
|
19
|
+
* artifactManager,
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Register minds
|
|
23
|
+
* kernel.registerMind('researcher', {
|
|
24
|
+
* model: 'claude-sonnet-4-20250514',
|
|
25
|
+
* systemPrompt: 'You are a research assistant...',
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Register modes
|
|
29
|
+
* kernel.registerMode(createPipelineMode({
|
|
30
|
+
* steps: [
|
|
31
|
+
* { id: 'research', mind: { type: 'registered', mindType: 'researcher' } },
|
|
32
|
+
* { id: 'analyze', mind: { type: 'registered', mindType: 'analyzer' } },
|
|
33
|
+
* ],
|
|
34
|
+
* }));
|
|
35
|
+
*
|
|
36
|
+
* // Create and run a session
|
|
37
|
+
* const session = await kernel.createSession({
|
|
38
|
+
* mode: 'pipeline',
|
|
39
|
+
* input: { topic: 'quantum computing' },
|
|
40
|
+
* accountId: 'acc-123',
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function createKernel(options: KernelOptions): Kernel;
|
|
45
|
+
//# sourceMappingURL=kernel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../src/kernel.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EAKd,MAAM,YAAY,CAAC;AAIpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAqL3D"}
|