@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
package/src/types.ts ADDED
@@ -0,0 +1,280 @@
1
+ // ABOUTME: Core types for kernel orchestration
2
+ // ABOUTME: Defines Kernel, KernelSession, and session event types
3
+
4
+ import type { CoordinationMode } from '@inf-minds/coordination-modes';
5
+ import type {
6
+ MindConfig,
7
+ MindEvent,
8
+ } from '@inf-minds/mindkit';
9
+ import type {
10
+ JobManager,
11
+ EventAppender,
12
+ ArtifactManager,
13
+ GraphState,
14
+ ArtifactRef,
15
+ } from '@inf-minds/jobs';
16
+ import type { ArtifactRouter } from '@inf-minds/jobs';
17
+
18
+ // Re-export for convenience
19
+ export type { GraphState } from '@inf-minds/jobs';
20
+
21
+ /**
22
+ * Session status values.
23
+ */
24
+ export const SESSION_STATUS = {
25
+ PENDING: 'pending',
26
+ RUNNING: 'running',
27
+ PAUSED: 'paused',
28
+ COMPLETED: 'completed',
29
+ FAILED: 'failed',
30
+ CANCELLED: 'cancelled',
31
+ } as const;
32
+
33
+ export type SessionStatus = (typeof SESSION_STATUS)[keyof typeof SESSION_STATUS];
34
+
35
+ /**
36
+ * Unsubscribe function returned by subscribe methods.
37
+ */
38
+ export type Unsubscribe = () => void;
39
+
40
+ /**
41
+ * Filter options for listing sessions.
42
+ */
43
+ export interface SessionFilter {
44
+ /** Filter by account ID */
45
+ accountId?: string;
46
+ /** Filter by mode name */
47
+ mode?: string;
48
+ /** Filter by status */
49
+ status?: SessionStatus;
50
+ /** Maximum number of sessions to return */
51
+ limit?: number;
52
+ /** Number of sessions to skip */
53
+ offset?: number;
54
+ }
55
+
56
+ /**
57
+ * Options for creating a new kernel session.
58
+ */
59
+ export interface CreateSessionOptions {
60
+ /** Coordination mode (name of registered mode or inline definition) */
61
+ mode: string | CoordinationMode;
62
+ /** Initial input data for the session */
63
+ input: unknown;
64
+ /** Account ID this session belongs to */
65
+ accountId: string;
66
+ /** Custom artifact router (uses default if not provided) */
67
+ artifactRouter?: ArtifactRouter;
68
+ /** Additional metadata */
69
+ metadata?: Record<string, unknown>;
70
+ }
71
+
72
+ /**
73
+ * Events emitted during kernel session execution.
74
+ */
75
+ export type SessionEvent =
76
+ | { type: 'session_started'; sessionId: string; mode: string; timestamp: Date }
77
+ | { type: 'node_started'; nodeId: string; mindType: string; jobId: string; timestamp: Date }
78
+ | { type: 'node_progress'; nodeId: string; event: MindEvent; timestamp: Date }
79
+ | { type: 'node_completed'; nodeId: string; output: unknown; timestamp: Date }
80
+ | { type: 'node_failed'; nodeId: string; error: string; timestamp: Date }
81
+ | { type: 'node_skipped'; nodeId: string; reason: string; timestamp: Date }
82
+ | { type: 'artifact_routed'; from: string; to: string; artifact: ArtifactRef; timestamp: Date }
83
+ | { type: 'graph_advanced'; fromNode: string; toNode: string; timestamp: Date }
84
+ | { type: 'session_paused'; timestamp: Date }
85
+ | { type: 'session_resumed'; timestamp: Date }
86
+ | { type: 'session_completed'; output: unknown; timestamp: Date }
87
+ | { type: 'session_failed'; error: string; timestamp: Date }
88
+ | { type: 'session_cancelled'; timestamp: Date };
89
+
90
+ /**
91
+ * Kernel session representing an execution of a coordination mode.
92
+ */
93
+ export interface KernelSession {
94
+ /** Unique session ID (same as parent job ID) */
95
+ readonly id: string;
96
+ /** Name of the coordination mode being executed */
97
+ readonly mode: string;
98
+ /** Current session status */
99
+ readonly status: SessionStatus;
100
+ /** Current graph execution state */
101
+ readonly graphState: GraphState;
102
+ /** Base path for session artifacts */
103
+ readonly artifactBasePath: string;
104
+ /** Account ID this session belongs to */
105
+ readonly accountId: string;
106
+
107
+ /**
108
+ * Pause session execution.
109
+ * Active nodes will complete but no new nodes will start.
110
+ */
111
+ pause(): Promise<void>;
112
+
113
+ /**
114
+ * Resume a paused session.
115
+ */
116
+ resume(): Promise<void>;
117
+
118
+ /**
119
+ * Cancel session execution.
120
+ * Active nodes will be cancelled if possible.
121
+ */
122
+ cancel(): Promise<void>;
123
+
124
+ /**
125
+ * Subscribe to session events.
126
+ * @param handler - Event handler function
127
+ * @returns Unsubscribe function
128
+ */
129
+ subscribe(handler: (event: SessionEvent) => void): Unsubscribe;
130
+
131
+ /**
132
+ * Get artifacts for this session.
133
+ * @param path - Optional path prefix to filter by
134
+ * @returns List of artifact references
135
+ */
136
+ getArtifacts(path?: string): Promise<ArtifactRef[]>;
137
+
138
+ /**
139
+ * Get the output of a completed node.
140
+ * @param nodeId - Node ID to get output for
141
+ * @returns Node output or null if not completed
142
+ */
143
+ getNodeOutput(nodeId: string): unknown | null;
144
+
145
+ /**
146
+ * Wait for session to complete.
147
+ * @returns Final session output
148
+ * @throws If session fails or is cancelled
149
+ */
150
+ waitForCompletion(): Promise<unknown>;
151
+ }
152
+
153
+ /**
154
+ * Kernel interface for creating and managing sessions.
155
+ */
156
+ export interface Kernel {
157
+ /**
158
+ * Create a new session with the given coordination mode.
159
+ * @param options - Session creation options
160
+ * @returns The created session (not yet started)
161
+ */
162
+ createSession(options: CreateSessionOptions): Promise<KernelSession>;
163
+
164
+ /**
165
+ * Get an existing session by ID.
166
+ * @param sessionId - Session ID to retrieve
167
+ * @returns Session or null if not found
168
+ */
169
+ getSession(sessionId: string): Promise<KernelSession | null>;
170
+
171
+ /**
172
+ * List sessions with optional filtering.
173
+ * @param filter - Optional filter options
174
+ * @returns List of sessions
175
+ */
176
+ listSessions(filter?: SessionFilter): Promise<KernelSession[]>;
177
+
178
+ /**
179
+ * Register a named mind configuration.
180
+ * @param name - Mind type name (e.g., 'researcher', 'coordinator')
181
+ * @param config - Mind configuration
182
+ */
183
+ registerMind(name: string, config: MindConfig): void;
184
+
185
+ /**
186
+ * Get a registered mind configuration.
187
+ * @param name - Mind type name
188
+ * @returns Mind configuration or undefined
189
+ */
190
+ getMind(name: string): MindConfig | undefined;
191
+
192
+ /**
193
+ * Register a named coordination mode.
194
+ * @param mode - Coordination mode definition
195
+ */
196
+ registerMode(mode: CoordinationMode): void;
197
+
198
+ /**
199
+ * Get a registered coordination mode.
200
+ * @param name - Mode name
201
+ * @returns Coordination mode or undefined
202
+ */
203
+ getMode(name: string): CoordinationMode | undefined;
204
+
205
+ /**
206
+ * List all registered mind type names.
207
+ */
208
+ listMindTypes(): string[];
209
+
210
+ /**
211
+ * List all registered mode names.
212
+ */
213
+ listModeNames(): string[];
214
+ }
215
+
216
+ /**
217
+ * Options for creating a kernel instance.
218
+ */
219
+ export interface KernelOptions {
220
+ /** JobManager instance for job lifecycle */
221
+ jobManager: JobManager;
222
+ /** EventAppender instance for event streaming */
223
+ eventAppender: EventAppender;
224
+ /** ArtifactManager instance for artifact operations */
225
+ artifactManager: ArtifactManager;
226
+ /** Default artifact router (optional, uses DefaultArtifactRouter if not provided) */
227
+ defaultArtifactRouter?: ArtifactRouter;
228
+ }
229
+
230
+ /**
231
+ * Mind registry for registered mind configurations.
232
+ */
233
+ export interface MindRegistry {
234
+ /** Register a mind configuration */
235
+ register(name: string, config: MindConfig): void;
236
+ /** Get a registered mind configuration */
237
+ get(name: string): MindConfig | undefined;
238
+ /** Check if a mind is registered */
239
+ has(name: string): boolean;
240
+ /** List all registered mind names */
241
+ list(): string[];
242
+ }
243
+
244
+ /**
245
+ * Mode registry for registered coordination modes.
246
+ */
247
+ export interface ModeRegistry {
248
+ /** Register a coordination mode */
249
+ register(mode: CoordinationMode): void;
250
+ /** Get a registered mode by name */
251
+ get(name: string): CoordinationMode | undefined;
252
+ /** Check if a mode is registered */
253
+ has(name: string): boolean;
254
+ /** List all registered mode names */
255
+ list(): string[];
256
+ }
257
+
258
+ /**
259
+ * Options for starting a node execution.
260
+ */
261
+ export interface StartNodeOptions {
262
+ /** Node ID to start */
263
+ nodeId: string;
264
+ /** Input data for the node */
265
+ input: unknown;
266
+ /** Iteration number (for loops) */
267
+ iteration?: number;
268
+ }
269
+
270
+ /**
271
+ * Options for handling node completion.
272
+ */
273
+ export interface NodeCompletionOptions {
274
+ /** Node ID that completed */
275
+ nodeId: string;
276
+ /** Output from the node */
277
+ output: unknown;
278
+ /** Artifacts created by the node */
279
+ artifacts?: Array<{ ref: ArtifactRef; hints: unknown }>;
280
+ }