@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.
Files changed (46) hide show
  1. package/dist/condition-evaluator.d.ts +69 -0
  2. package/dist/condition-evaluator.d.ts.map +1 -0
  3. package/dist/condition-evaluator.js +120 -0
  4. package/dist/condition-evaluator.js.map +1 -0
  5. package/dist/graph-executor.d.ts +63 -0
  6. package/dist/graph-executor.d.ts.map +1 -0
  7. package/dist/graph-executor.js +245 -0
  8. package/dist/graph-executor.js.map +1 -0
  9. package/dist/index.d.ts +7 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +13 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/kernel.d.ts +45 -0
  14. package/dist/kernel.d.ts.map +1 -0
  15. package/dist/kernel.js +202 -0
  16. package/dist/kernel.js.map +1 -0
  17. package/dist/registries/index.d.ts +3 -0
  18. package/dist/registries/index.d.ts.map +1 -0
  19. package/dist/registries/index.js +5 -0
  20. package/dist/registries/index.js.map +1 -0
  21. package/dist/registries/mind-registry.d.ts +11 -0
  22. package/dist/registries/mind-registry.d.ts.map +1 -0
  23. package/dist/registries/mind-registry.js +31 -0
  24. package/dist/registries/mind-registry.js.map +1 -0
  25. package/dist/registries/mode-registry.d.ts +11 -0
  26. package/dist/registries/mode-registry.d.ts.map +1 -0
  27. package/dist/registries/mode-registry.js +31 -0
  28. package/dist/registries/mode-registry.js.map +1 -0
  29. package/dist/session.d.ts +123 -0
  30. package/dist/session.d.ts.map +1 -0
  31. package/dist/session.js +403 -0
  32. package/dist/session.js.map +1 -0
  33. package/dist/types.d.ts +288 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/types.js +14 -0
  36. package/dist/types.js.map +1 -0
  37. package/package.json +37 -0
  38. package/src/condition-evaluator.ts +168 -0
  39. package/src/graph-executor.ts +315 -0
  40. package/src/index.ts +50 -0
  41. package/src/kernel.ts +242 -0
  42. package/src/registries/index.ts +5 -0
  43. package/src/registries/mind-registry.ts +38 -0
  44. package/src/registries/mode-registry.ts +38 -0
  45. package/src/session.ts +541 -0
  46. package/src/types.ts +280 -0
@@ -0,0 +1,288 @@
1
+ import type { CoordinationMode } from '@inf-minds/coordination-modes';
2
+ import type { MindConfig, MindEvent } from '@inf-minds/mindkit';
3
+ import type { JobManager, EventAppender, ArtifactManager, GraphState, ArtifactRef } from '@inf-minds/jobs';
4
+ import type { ArtifactRouter } from '@inf-minds/jobs';
5
+ export type { GraphState } from '@inf-minds/jobs';
6
+ /**
7
+ * Session status values.
8
+ */
9
+ export declare const SESSION_STATUS: {
10
+ readonly PENDING: "pending";
11
+ readonly RUNNING: "running";
12
+ readonly PAUSED: "paused";
13
+ readonly COMPLETED: "completed";
14
+ readonly FAILED: "failed";
15
+ readonly CANCELLED: "cancelled";
16
+ };
17
+ export type SessionStatus = (typeof SESSION_STATUS)[keyof typeof SESSION_STATUS];
18
+ /**
19
+ * Unsubscribe function returned by subscribe methods.
20
+ */
21
+ export type Unsubscribe = () => void;
22
+ /**
23
+ * Filter options for listing sessions.
24
+ */
25
+ export interface SessionFilter {
26
+ /** Filter by account ID */
27
+ accountId?: string;
28
+ /** Filter by mode name */
29
+ mode?: string;
30
+ /** Filter by status */
31
+ status?: SessionStatus;
32
+ /** Maximum number of sessions to return */
33
+ limit?: number;
34
+ /** Number of sessions to skip */
35
+ offset?: number;
36
+ }
37
+ /**
38
+ * Options for creating a new kernel session.
39
+ */
40
+ export interface CreateSessionOptions {
41
+ /** Coordination mode (name of registered mode or inline definition) */
42
+ mode: string | CoordinationMode;
43
+ /** Initial input data for the session */
44
+ input: unknown;
45
+ /** Account ID this session belongs to */
46
+ accountId: string;
47
+ /** Custom artifact router (uses default if not provided) */
48
+ artifactRouter?: ArtifactRouter;
49
+ /** Additional metadata */
50
+ metadata?: Record<string, unknown>;
51
+ }
52
+ /**
53
+ * Events emitted during kernel session execution.
54
+ */
55
+ export type SessionEvent = {
56
+ type: 'session_started';
57
+ sessionId: string;
58
+ mode: string;
59
+ timestamp: Date;
60
+ } | {
61
+ type: 'node_started';
62
+ nodeId: string;
63
+ mindType: string;
64
+ jobId: string;
65
+ timestamp: Date;
66
+ } | {
67
+ type: 'node_progress';
68
+ nodeId: string;
69
+ event: MindEvent;
70
+ timestamp: Date;
71
+ } | {
72
+ type: 'node_completed';
73
+ nodeId: string;
74
+ output: unknown;
75
+ timestamp: Date;
76
+ } | {
77
+ type: 'node_failed';
78
+ nodeId: string;
79
+ error: string;
80
+ timestamp: Date;
81
+ } | {
82
+ type: 'node_skipped';
83
+ nodeId: string;
84
+ reason: string;
85
+ timestamp: Date;
86
+ } | {
87
+ type: 'artifact_routed';
88
+ from: string;
89
+ to: string;
90
+ artifact: ArtifactRef;
91
+ timestamp: Date;
92
+ } | {
93
+ type: 'graph_advanced';
94
+ fromNode: string;
95
+ toNode: string;
96
+ timestamp: Date;
97
+ } | {
98
+ type: 'session_paused';
99
+ timestamp: Date;
100
+ } | {
101
+ type: 'session_resumed';
102
+ timestamp: Date;
103
+ } | {
104
+ type: 'session_completed';
105
+ output: unknown;
106
+ timestamp: Date;
107
+ } | {
108
+ type: 'session_failed';
109
+ error: string;
110
+ timestamp: Date;
111
+ } | {
112
+ type: 'session_cancelled';
113
+ timestamp: Date;
114
+ };
115
+ /**
116
+ * Kernel session representing an execution of a coordination mode.
117
+ */
118
+ export interface KernelSession {
119
+ /** Unique session ID (same as parent job ID) */
120
+ readonly id: string;
121
+ /** Name of the coordination mode being executed */
122
+ readonly mode: string;
123
+ /** Current session status */
124
+ readonly status: SessionStatus;
125
+ /** Current graph execution state */
126
+ readonly graphState: GraphState;
127
+ /** Base path for session artifacts */
128
+ readonly artifactBasePath: string;
129
+ /** Account ID this session belongs to */
130
+ readonly accountId: string;
131
+ /**
132
+ * Pause session execution.
133
+ * Active nodes will complete but no new nodes will start.
134
+ */
135
+ pause(): Promise<void>;
136
+ /**
137
+ * Resume a paused session.
138
+ */
139
+ resume(): Promise<void>;
140
+ /**
141
+ * Cancel session execution.
142
+ * Active nodes will be cancelled if possible.
143
+ */
144
+ cancel(): Promise<void>;
145
+ /**
146
+ * Subscribe to session events.
147
+ * @param handler - Event handler function
148
+ * @returns Unsubscribe function
149
+ */
150
+ subscribe(handler: (event: SessionEvent) => void): Unsubscribe;
151
+ /**
152
+ * Get artifacts for this session.
153
+ * @param path - Optional path prefix to filter by
154
+ * @returns List of artifact references
155
+ */
156
+ getArtifacts(path?: string): Promise<ArtifactRef[]>;
157
+ /**
158
+ * Get the output of a completed node.
159
+ * @param nodeId - Node ID to get output for
160
+ * @returns Node output or null if not completed
161
+ */
162
+ getNodeOutput(nodeId: string): unknown | null;
163
+ /**
164
+ * Wait for session to complete.
165
+ * @returns Final session output
166
+ * @throws If session fails or is cancelled
167
+ */
168
+ waitForCompletion(): Promise<unknown>;
169
+ }
170
+ /**
171
+ * Kernel interface for creating and managing sessions.
172
+ */
173
+ export interface Kernel {
174
+ /**
175
+ * Create a new session with the given coordination mode.
176
+ * @param options - Session creation options
177
+ * @returns The created session (not yet started)
178
+ */
179
+ createSession(options: CreateSessionOptions): Promise<KernelSession>;
180
+ /**
181
+ * Get an existing session by ID.
182
+ * @param sessionId - Session ID to retrieve
183
+ * @returns Session or null if not found
184
+ */
185
+ getSession(sessionId: string): Promise<KernelSession | null>;
186
+ /**
187
+ * List sessions with optional filtering.
188
+ * @param filter - Optional filter options
189
+ * @returns List of sessions
190
+ */
191
+ listSessions(filter?: SessionFilter): Promise<KernelSession[]>;
192
+ /**
193
+ * Register a named mind configuration.
194
+ * @param name - Mind type name (e.g., 'researcher', 'coordinator')
195
+ * @param config - Mind configuration
196
+ */
197
+ registerMind(name: string, config: MindConfig): void;
198
+ /**
199
+ * Get a registered mind configuration.
200
+ * @param name - Mind type name
201
+ * @returns Mind configuration or undefined
202
+ */
203
+ getMind(name: string): MindConfig | undefined;
204
+ /**
205
+ * Register a named coordination mode.
206
+ * @param mode - Coordination mode definition
207
+ */
208
+ registerMode(mode: CoordinationMode): void;
209
+ /**
210
+ * Get a registered coordination mode.
211
+ * @param name - Mode name
212
+ * @returns Coordination mode or undefined
213
+ */
214
+ getMode(name: string): CoordinationMode | undefined;
215
+ /**
216
+ * List all registered mind type names.
217
+ */
218
+ listMindTypes(): string[];
219
+ /**
220
+ * List all registered mode names.
221
+ */
222
+ listModeNames(): string[];
223
+ }
224
+ /**
225
+ * Options for creating a kernel instance.
226
+ */
227
+ export interface KernelOptions {
228
+ /** JobManager instance for job lifecycle */
229
+ jobManager: JobManager;
230
+ /** EventAppender instance for event streaming */
231
+ eventAppender: EventAppender;
232
+ /** ArtifactManager instance for artifact operations */
233
+ artifactManager: ArtifactManager;
234
+ /** Default artifact router (optional, uses DefaultArtifactRouter if not provided) */
235
+ defaultArtifactRouter?: ArtifactRouter;
236
+ }
237
+ /**
238
+ * Mind registry for registered mind configurations.
239
+ */
240
+ export interface MindRegistry {
241
+ /** Register a mind configuration */
242
+ register(name: string, config: MindConfig): void;
243
+ /** Get a registered mind configuration */
244
+ get(name: string): MindConfig | undefined;
245
+ /** Check if a mind is registered */
246
+ has(name: string): boolean;
247
+ /** List all registered mind names */
248
+ list(): string[];
249
+ }
250
+ /**
251
+ * Mode registry for registered coordination modes.
252
+ */
253
+ export interface ModeRegistry {
254
+ /** Register a coordination mode */
255
+ register(mode: CoordinationMode): void;
256
+ /** Get a registered mode by name */
257
+ get(name: string): CoordinationMode | undefined;
258
+ /** Check if a mode is registered */
259
+ has(name: string): boolean;
260
+ /** List all registered mode names */
261
+ list(): string[];
262
+ }
263
+ /**
264
+ * Options for starting a node execution.
265
+ */
266
+ export interface StartNodeOptions {
267
+ /** Node ID to start */
268
+ nodeId: string;
269
+ /** Input data for the node */
270
+ input: unknown;
271
+ /** Iteration number (for loops) */
272
+ iteration?: number;
273
+ }
274
+ /**
275
+ * Options for handling node completion.
276
+ */
277
+ export interface NodeCompletionOptions {
278
+ /** Node ID that completed */
279
+ nodeId: string;
280
+ /** Output from the node */
281
+ output: unknown;
282
+ /** Artifacts created by the node */
283
+ artifacts?: Array<{
284
+ ref: ArtifactRef;
285
+ hints: unknown;
286
+ }>;
287
+ }
288
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,eAAe,EACf,UAAU,EACV,WAAW,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGtD,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;CAOjB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;AAEjF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uBAAuB;IACvB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,uEAAuE;IACvE,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAChC,yCAAyC;IACzC,KAAK,EAAE,OAAO,CAAC;IACf,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;I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,WAAW,YAAY;IAC3B,oCAAoC;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IACjD,0CAA0C;IAC1C,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;IAC1C,oCAAoC;IACpC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,qCAAqC;IACrC,IAAI,IAAI,MAAM,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACvC,oCAAoC;IACpC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;IAChD,oCAAoC;IACpC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,qCAAqC;IACrC,IAAI,IAAI,MAAM,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,KAAK,EAAE,OAAO,CAAC;IACf,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,2BAA2B;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,oCAAoC;IACpC,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,WAAW,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CACzD"}
package/dist/types.js ADDED
@@ -0,0 +1,14 @@
1
+ // ABOUTME: Core types for kernel orchestration
2
+ // ABOUTME: Defines Kernel, KernelSession, and session event types
3
+ /**
4
+ * Session status values.
5
+ */
6
+ export const SESSION_STATUS = {
7
+ PENDING: 'pending',
8
+ RUNNING: 'running',
9
+ PAUSED: 'paused',
10
+ COMPLETED: 'completed',
11
+ FAILED: 'failed',
12
+ CANCELLED: 'cancelled',
13
+ };
14
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,kEAAkE;AAmBlE;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,WAAW;CACd,CAAC"}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@inf-minds/kernel",
3
+ "version": "0.0.1",
4
+ "description": "Kernel orchestration for multi-mind coordination",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "src"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest",
24
+ "typecheck": "tsc --noEmit",
25
+ "lint": "echo 'No linter configured yet'"
26
+ },
27
+ "dependencies": {
28
+ "@inf-minds/coordination-modes": "workspace:*",
29
+ "@inf-minds/mindkit": "workspace:*",
30
+ "@inf-minds/jobs": "workspace:*"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^20.0.0",
34
+ "typescript": "^5.3.0",
35
+ "vitest": "^2.0.0"
36
+ }
37
+ }
@@ -0,0 +1,168 @@
1
+ // ABOUTME: Safe condition evaluation for graph edges and node exit conditions
2
+ // ABOUTME: Uses sandboxed function execution for expression evaluation
3
+
4
+ /**
5
+ * Context object passed to condition expressions.
6
+ */
7
+ export interface ConditionContext {
8
+ /** Output from the source node */
9
+ output: unknown;
10
+ /** Current graph state */
11
+ graphState?: {
12
+ completedNodes: string[];
13
+ activeNodes: string[];
14
+ nodeOutputs?: Record<string, unknown>;
15
+ };
16
+ /** Current iteration count (for loops) */
17
+ iteration?: number;
18
+ }
19
+
20
+ /**
21
+ * Result of condition evaluation.
22
+ */
23
+ export interface EvaluationResult {
24
+ /** Whether the condition evaluated to true */
25
+ result: boolean;
26
+ /** Error message if evaluation failed */
27
+ error?: string;
28
+ }
29
+
30
+ /**
31
+ * Evaluate a condition expression against a context.
32
+ *
33
+ * The condition is a JavaScript expression that has access to:
34
+ * - `output` - The output from the source node
35
+ * - `graphState` - Current graph execution state
36
+ * - `iteration` - Current iteration count (for loops)
37
+ *
38
+ * Examples:
39
+ * - `output.done === true`
40
+ * - `output.tasks.length > 0`
41
+ * - `iteration < 5`
42
+ * - `output.allTasksComplete`
43
+ * - `graphState.completedNodes.includes('research')`
44
+ *
45
+ * @param expression - JavaScript expression to evaluate
46
+ * @param context - Context object with output, graphState, iteration
47
+ * @returns Evaluation result with boolean result or error
48
+ */
49
+ export function evaluateCondition(
50
+ expression: string,
51
+ context: ConditionContext
52
+ ): EvaluationResult {
53
+ try {
54
+ // Validate expression for safety
55
+ const validationError = validateExpression(expression);
56
+ if (validationError) {
57
+ return { result: false, error: validationError };
58
+ }
59
+
60
+ // Create sandboxed function
61
+ const fn = new Function(
62
+ 'output',
63
+ 'graphState',
64
+ 'iteration',
65
+ `"use strict"; return (${expression});`
66
+ );
67
+
68
+ // Execute with context
69
+ const result = fn(
70
+ context.output,
71
+ context.graphState ?? { completedNodes: [], activeNodes: [] },
72
+ context.iteration ?? 0
73
+ );
74
+
75
+ // Coerce to boolean
76
+ return { result: Boolean(result) };
77
+ } catch (error) {
78
+ return {
79
+ result: false,
80
+ error: error instanceof Error ? error.message : String(error),
81
+ };
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Validate a condition expression for safety.
87
+ * Returns an error message if the expression is unsafe, undefined otherwise.
88
+ */
89
+ function validateExpression(expression: string): string | undefined {
90
+ // Block potentially dangerous constructs
91
+ const blockedPatterns = [
92
+ /\beval\b/,
93
+ /\bFunction\b/,
94
+ /\bsetTimeout\b/,
95
+ /\bsetInterval\b/,
96
+ /\bsetImmediate\b/,
97
+ /\brequire\b/,
98
+ /\bimport\b/,
99
+ /\bprocess\b/,
100
+ /\bglobal\b/,
101
+ /\bglobalThis\b/,
102
+ /\bwindow\b/,
103
+ /\bdocument\b/,
104
+ /\bfetch\b/,
105
+ /\bXMLHttpRequest\b/,
106
+ /\bWebSocket\b/,
107
+ /\b__proto__\b/,
108
+ /\bconstructor\b/,
109
+ /\bprototype\b/,
110
+ /\bObject\.assign\b/,
111
+ /\bObject\.defineProperty\b/,
112
+ /\bReflect\b/,
113
+ /\bProxy\b/,
114
+ ];
115
+
116
+ for (const pattern of blockedPatterns) {
117
+ if (pattern.test(expression)) {
118
+ return `Expression contains blocked construct: ${pattern.source}`;
119
+ }
120
+ }
121
+
122
+ // Block assignment operators (but allow == and ===)
123
+ if (/[^=!<>]=[^=]/.test(expression) && !/=>/.test(expression)) {
124
+ return 'Expression contains assignment operator';
125
+ }
126
+
127
+ // Block function definitions
128
+ if (/\bfunction\b/.test(expression)) {
129
+ return 'Expression contains function definition';
130
+ }
131
+
132
+ return undefined;
133
+ }
134
+
135
+ /**
136
+ * Check if a string looks like a valid condition expression.
137
+ * This is a quick heuristic check, not a full validation.
138
+ */
139
+ export function isValidConditionExpression(expression: string): boolean {
140
+ // Must be non-empty
141
+ if (!expression || expression.trim().length === 0) {
142
+ return false;
143
+ }
144
+
145
+ // Validate
146
+ const error = validateExpression(expression);
147
+ return error === undefined;
148
+ }
149
+
150
+ /**
151
+ * Common condition expressions for reference.
152
+ */
153
+ export const COMMON_CONDITIONS = {
154
+ /** Node output indicates completion */
155
+ OUTPUT_DONE: 'output.done === true',
156
+ /** Node output indicates all tasks complete */
157
+ ALL_TASKS_COMPLETE: 'output.allTasksComplete',
158
+ /** Node has a delegated task */
159
+ HAS_DELEGATED_TASK: 'output.delegatedTask',
160
+ /** Output has items to process */
161
+ HAS_ITEMS: 'output.items && output.items.length > 0',
162
+ /** Iteration count under limit */
163
+ UNDER_MAX_ITERATIONS: 'iteration < 10',
164
+ /** Output indicates success */
165
+ SUCCESS: 'output.success === true',
166
+ /** Output indicates failure */
167
+ FAILURE: 'output.success === false',
168
+ } as const;