kernl 0.12.0 → 0.12.2

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 (51) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +21 -0
  3. package/dist/api/resources/agents/agents.d.ts +2 -2
  4. package/dist/api/resources/agents/agents.d.ts.map +1 -1
  5. package/dist/api/resources/agents/agents.js +1 -1
  6. package/dist/index.d.ts +3 -2
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1 -0
  9. package/dist/kernl/index.d.ts +2 -1
  10. package/dist/kernl/index.d.ts.map +1 -1
  11. package/dist/kernl/index.js +1 -0
  12. package/dist/kernl/kernl.d.ts +4 -4
  13. package/dist/kernl/kernl.d.ts.map +1 -1
  14. package/dist/kernl/kernl.js +17 -13
  15. package/dist/kernl/registry.d.ts +46 -0
  16. package/dist/kernl/registry.d.ts.map +1 -0
  17. package/dist/kernl/registry.js +57 -0
  18. package/dist/kernl/types.d.ts +2 -2
  19. package/dist/kernl/types.d.ts.map +1 -1
  20. package/dist/storage/base.d.ts +3 -3
  21. package/dist/storage/base.d.ts.map +1 -1
  22. package/dist/storage/in-memory.d.ts +5 -5
  23. package/dist/storage/in-memory.d.ts.map +1 -1
  24. package/dist/thread/__tests__/mock.d.ts +2 -3
  25. package/dist/thread/__tests__/mock.d.ts.map +1 -1
  26. package/dist/thread/thread.d.ts +4 -0
  27. package/dist/thread/thread.d.ts.map +1 -1
  28. package/dist/thread/thread.js +43 -75
  29. package/dist/thread/types.d.ts +18 -3
  30. package/dist/thread/types.d.ts.map +1 -1
  31. package/dist/thread/utils.d.ts +7 -7
  32. package/dist/thread/utils.d.ts.map +1 -1
  33. package/dist/thread/utils.js +1 -1
  34. package/package.json +4 -6
  35. package/src/api/__tests__/threads.test.ts +3 -3
  36. package/src/api/resources/agents/agents.ts +3 -3
  37. package/src/index.ts +4 -2
  38. package/src/kernl/index.ts +3 -2
  39. package/src/kernl/kernl.ts +18 -15
  40. package/src/kernl/registry.ts +69 -0
  41. package/src/kernl/types.ts +2 -2
  42. package/src/storage/base.ts +2 -2
  43. package/src/storage/in-memory.ts +4 -4
  44. package/src/thread/__tests__/mock.ts +2 -2
  45. package/src/thread/thread.ts +47 -78
  46. package/src/thread/types.ts +49 -3
  47. package/src/thread/utils.ts +14 -7
  48. package/dist/thread/__tests__/integration.test.d.ts +0 -2
  49. package/dist/thread/__tests__/integration.test.d.ts.map +0 -1
  50. package/dist/thread/__tests__/integration.test.js +0 -320
  51. package/src/thread/__tests__/integration.test.ts +0 -434
@@ -120,33 +120,14 @@ export class Thread {
120
120
  this.abort = new AbortController();
121
121
  this.tickres = undefined; // reset for this run
122
122
  await this.checkpoint(); /* c1: persist RUNNING state + initial input */
123
- this.agent.emit("thread.start", {
124
- kind: "thread.start",
125
- threadId: this.tid,
126
- agentId: this.agent.id,
127
- namespace: this.namespace,
128
- context: this.context,
129
- });
123
+ this.emit("thread.start");
130
124
  yield { kind: "stream.start" }; // always yield start immediately
131
125
  try {
132
126
  yield* this._execute();
133
- this.agent.emit("thread.stop", {
134
- kind: "thread.stop",
135
- threadId: this.tid,
136
- agentId: this.agent.id,
137
- namespace: this.namespace,
138
- context: this.context,
139
- state: STOPPED,
140
- result: this.tickres,
141
- });
127
+ this.emit("thread.stop", { state: STOPPED, result: this.tickres });
142
128
  }
143
129
  catch (err) {
144
- this.agent.emit("thread.stop", {
145
- kind: "thread.stop",
146
- threadId: this.tid,
147
- agentId: this.agent.id,
148
- namespace: this.namespace,
149
- context: this.context,
130
+ this.emit("thread.stop", {
150
131
  state: STOPPED,
151
132
  error: err instanceof Error ? err.message : String(err),
152
133
  });
@@ -176,12 +157,15 @@ export class Thread {
176
157
  err = e.error;
177
158
  logger.error(e.error); // (TODO): onError callback in options
178
159
  }
179
- // we don't want deltas in the history
160
+ // complete items get persisted with seq, deltas are ephemeral
180
161
  if (notDelta(e)) {
181
- events.push(e);
182
- this.append(e);
162
+ const [seqd] = this.append(e);
163
+ events.push(seqd);
164
+ yield seqd;
165
+ }
166
+ else {
167
+ yield e;
183
168
  }
184
- yield e;
185
169
  }
186
170
  // if an error event occurred → throw it
187
171
  if (err) {
@@ -201,10 +185,10 @@ export class Thread {
201
185
  }
202
186
  // perform intended actions
203
187
  const { actions, pendingApprovals } = await this.performActions(intentions);
204
- // append + yield action events
188
+ // append + yield action events (sequenced)
205
189
  for (const a of actions) {
206
- this.append(a);
207
- yield a;
190
+ const [seqd] = this.append(a);
191
+ yield seqd;
208
192
  }
209
193
  await this.checkpoint(); /* c3: tick complete */
210
194
  if (pendingApprovals.length > 0) {
@@ -228,16 +212,9 @@ export class Thread {
228
212
  this._tick++;
229
213
  // (TODO): check limits (if this._tick > this.limits.maxTicks)
230
214
  // (TODO): run input guardrails on first tick (if this._tick === 1)
215
+ // (TODO): compaction if necessary
231
216
  const req = await this.prepareModelRequest(this.history);
232
- this.agent.emit("model.call.start", {
233
- kind: "model.call.start",
234
- provider: this.model.provider,
235
- modelId: this.model.modelId,
236
- settings: req.settings ?? {},
237
- threadId: this.tid,
238
- agentId: this.agent.id,
239
- context: this.context,
240
- });
217
+ this.emit("model.call.start", { settings: req.settings ?? {} });
241
218
  let usage;
242
219
  let finishReason = "unknown";
243
220
  try {
@@ -259,27 +236,10 @@ export class Thread {
259
236
  yield event;
260
237
  }
261
238
  }
262
- this.agent.emit("model.call.end", {
263
- kind: "model.call.end",
264
- provider: this.model.provider,
265
- modelId: this.model.modelId,
266
- finishReason,
267
- usage,
268
- threadId: this.tid,
269
- agentId: this.agent.id,
270
- context: this.context,
271
- });
239
+ this.emit("model.call.end", { finishReason, usage });
272
240
  }
273
241
  catch (error) {
274
- this.agent.emit("model.call.end", {
275
- kind: "model.call.end",
276
- provider: this.model.provider,
277
- modelId: this.model.modelId,
278
- finishReason: "error",
279
- threadId: this.tid,
280
- agentId: this.agent.id,
281
- context: this.context,
282
- });
242
+ this.emit("model.call.end", { finishReason: "error" });
283
243
  yield {
284
244
  kind: "error",
285
245
  error: error instanceof Error ? error : new Error(String(error)),
@@ -356,9 +316,29 @@ export class Thread {
356
316
  cancel() {
357
317
  this.abort?.abort();
358
318
  }
359
- // ----------------------------
360
- // utils
361
- // ----------------------------
319
+ /**
320
+ * Emit an agent event with common fields auto-filled.
321
+ */
322
+ emit(kind, payload) {
323
+ const base = {
324
+ kind,
325
+ threadId: this.tid,
326
+ agentId: this.agent.id,
327
+ context: this.context,
328
+ };
329
+ let auto = {};
330
+ switch (kind) {
331
+ case "thread.start":
332
+ case "thread.stop":
333
+ auto = { namespace: this.namespace };
334
+ break;
335
+ case "model.call.start":
336
+ case "model.call.end":
337
+ auto = { provider: this.model.provider, modelId: this.model.modelId };
338
+ break;
339
+ }
340
+ this.agent.emit(kind, { ...base, ...auto, ...payload });
341
+ }
362
342
  /**
363
343
  * Perform the actions returned by the model
364
344
  */
@@ -404,11 +384,7 @@ export class Thread {
404
384
  async executeTools(calls) {
405
385
  return await Promise.all(calls.map(async (call) => {
406
386
  const parsedArgs = JSON.parse(call.arguments || "{}");
407
- this.agent.emit("tool.call.start", {
408
- kind: "tool.call.start",
409
- threadId: this.tid,
410
- agentId: this.agent.id,
411
- context: this.context,
387
+ this.emit("tool.call.start", {
412
388
  toolId: call.toolId,
413
389
  callId: call.callId,
414
390
  args: parsedArgs,
@@ -426,11 +402,7 @@ export class Thread {
426
402
  ctx.agent = this.agent;
427
403
  ctx.approve(call.callId); // mark this call as approved
428
404
  const res = await tool.invoke(ctx, call.arguments, call.callId);
429
- this.agent.emit("tool.call.end", {
430
- kind: "tool.call.end",
431
- threadId: this.tid,
432
- agentId: this.agent.id,
433
- context: this.context,
405
+ this.emit("tool.call.end", {
434
406
  toolId: call.toolId,
435
407
  callId: call.callId,
436
408
  state: res.state,
@@ -449,11 +421,7 @@ export class Thread {
449
421
  };
450
422
  }
451
423
  catch (error) {
452
- this.agent.emit("tool.call.end", {
453
- kind: "tool.call.end",
454
- threadId: this.tid,
455
- agentId: this.agent.id,
456
- context: this.context,
424
+ this.emit("tool.call.end", {
457
425
  toolId: call.toolId,
458
426
  callId: call.callId,
459
427
  state: FAILED,
@@ -1,4 +1,4 @@
1
- import { ToolCall, LanguageModel, LanguageModelItem, LanguageModelStreamEvent, RUNNING, STOPPED, INTERRUPTIBLE, UNINTERRUPTIBLE, ZOMBIE, DEAD } from "@kernl-sdk/protocol";
1
+ import { ToolCall, LanguageModel, LanguageModelItem, RUNNING, STOPPED, INTERRUPTIBLE, UNINTERRUPTIBLE, ZOMBIE, DEAD, TextStartEvent, TextEndEvent, TextDeltaEvent, ReasoningStartEvent, ReasoningEndEvent, ReasoningDeltaEvent, ToolInputStartEvent, ToolInputEndEvent, ToolInputDeltaEvent, StartEvent, FinishEvent, AbortEvent, ErrorEvent, RawEvent } from "@kernl-sdk/protocol";
2
2
  import { Task } from "../task.js";
3
3
  import { Context } from "../context.js";
4
4
  import { Agent } from "../agent.js";
@@ -79,9 +79,24 @@ export interface ThreadSystemEvent extends ThreadEventBase {
79
79
  */
80
80
  export type ThreadEvent = (LanguageModelItem & ThreadEventBase) | ThreadSystemEvent;
81
81
  /**
82
- * Stream events - use protocol definition directly.
82
+ * Incremental content chunks (ephemeral, not persisted).
83
83
  */
84
- export type ThreadStreamEvent = LanguageModelStreamEvent;
84
+ export type StreamDeltaEvent = TextDeltaEvent | ReasoningDeltaEvent | ToolInputDeltaEvent;
85
+ /**
86
+ * Boundary markers + control flow (ephemeral, not persisted).
87
+ */
88
+ export type StreamControlEvent = TextStartEvent | TextEndEvent | ReasoningStartEvent | ReasoningEndEvent | ToolInputStartEvent | ToolInputEndEvent | StartEvent | FinishEvent | AbortEvent | ErrorEvent | RawEvent;
89
+ /**
90
+ * All ephemeral stream types (not persisted to history).
91
+ */
92
+ export type StreamEvent = StreamDeltaEvent | StreamControlEvent;
93
+ /**
94
+ * Thread stream events = sequenced ThreadEvents + ephemeral StreamEvents.
95
+ *
96
+ * Complete items (Message, ToolCall, etc.) are yielded as ThreadEvents with seq.
97
+ * Deltas and control events are yielded as StreamEvents without seq.
98
+ */
99
+ export type ThreadStreamEvent = ThreadEvent | StreamEvent;
85
100
  /**
86
101
  * Result of thread execution
87
102
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/thread/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,OAAO,EACP,OAAO,EACP,aAAa,EACb,eAAe,EACf,MAAM,EACN,IAAI,EACL,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAEpE;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;GAEG;AACH,eAAO,MAAM,aAAa,uFAOhB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,OAAO,OAAO,GACd,OAAO,OAAO,GACd,OAAO,aAAa,GACpB,OAAO,eAAe,GACtB,OAAO,MAAM,GACb,OAAO,IAAI,CAAC;AAEhB;;;GAGG;AACH,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AAErD;;;;GAIG;AACH,MAAM,WAAW,OAAO,CACtB,QAAQ,GAAG,OAAO,EAClB,OAAO,SAAS,eAAe,GAAG,MAAM;IAExC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChC,KAAK,EAAE,aAAa,CAAC;IAErB,OAAO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I,CAAC;IACjB,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC1C;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,QAAQ;IAC5C,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,QAAQ,EAAE,CAAC;CAEvB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B;;OAEG;IACH,gBAAgB,EAAE,QAAQ,EAAE,CAAC;CAC9B"}
@@ -1,12 +1,12 @@
1
1
  import type { ResolvedAgentResponse } from "../guardrail.js";
2
- import { ToolCall, LanguageModelItem } from "@kernl-sdk/protocol";
2
+ import { ToolCall, LanguageModelItem, LanguageModelStreamEvent } from "@kernl-sdk/protocol";
3
3
  import type { AgentOutputType } from "../agent/types.js";
4
- import type { ThreadEvent, ThreadStreamEvent, ActionSet, PublicThreadEvent } from "./types.js";
4
+ import type { ThreadEvent, ThreadEventBase, ActionSet, PublicThreadEvent } from "./types.js";
5
5
  /**
6
6
  * Create a ThreadEvent from a LanguageModelItem with thread metadata.
7
7
  *
8
8
  * @example
9
- * ```typescript
9
+ * ```ts
10
10
  * tevent({
11
11
  * kind: "message",
12
12
  * seq: 0,
@@ -28,17 +28,17 @@ export declare function tevent(event: {
28
28
  /**
29
29
  * Check if an event is a tool call
30
30
  */
31
- export declare function isActionIntention(event: LanguageModelItem): event is ToolCall;
31
+ export declare function isActionIntention(event: ThreadEvent): event is ToolCall & ThreadEventBase;
32
32
  /**
33
33
  * Extract action intentions from a list of events.
34
34
  * Returns ActionSet if there are any tool calls, null otherwise.
35
35
  */
36
- export declare function getIntentions(events: LanguageModelItem[]): ActionSet | null;
36
+ export declare function getIntentions(events: ThreadEvent[]): ActionSet | null;
37
37
  /**
38
38
  * Check if an event is NOT a delta/start/end event (i.e., a complete item).
39
39
  * Returns true for complete items: Message, Reasoning, ToolCall, ToolResult
40
40
  */
41
- export declare function notDelta(event: ThreadStreamEvent): event is LanguageModelItem;
41
+ export declare function notDelta(event: LanguageModelStreamEvent): event is LanguageModelItem;
42
42
  /**
43
43
  * Check if an event is public/client-facing (not internal).
44
44
  * Filters out internal system events that clients don't need.
@@ -48,7 +48,7 @@ export declare function isPublicEvent(event: ThreadEvent): event is PublicThread
48
48
  * Extract the final text response from a list of items.
49
49
  * Returns null if no assistant message with text content is found.
50
50
  */
51
- export declare function getFinalResponse(items: LanguageModelItem[]): string | null;
51
+ export declare function getFinalResponse(items: ThreadEvent[]): string | null;
52
52
  /**
53
53
  * Parse the final response according to the output type schema.
54
54
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/thread/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAIzD,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIlE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EACV,WAAW,EAEX,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE;IAC5B,GAAG,EAAE,MAAM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AS,EACT,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1B,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,GAAG,WAAW,CAad;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,WAAW,GACjB,KAAK,IAAI,QAAQ,GAAG,eAAe,CAErC;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,GAAG,IAAI,CAGrE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,wBAAwB,GAC9B,KAAK,IAAI,iBAAiB,CAY5B;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,KAAK,IAAI,iBAAiB,CAc5E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,GAAG,IAAI,CAapE;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,eAAe,EAChE,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,GACd,qBAAqB,CAAC,OAAO,CAAC,CAsBhC"}
@@ -5,7 +5,7 @@ import { ModelBehaviorError } from "../lib/error.js";
5
5
  * Create a ThreadEvent from a LanguageModelItem with thread metadata.
6
6
  *
7
7
  * @example
8
- * ```typescript
8
+ * ```ts
9
9
  * tevent({
10
10
  * kind: "message",
11
11
  * seq: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kernl",
3
- "version": "0.12.0",
3
+ "version": "0.12.2",
4
4
  "description": "A modern AI agent framework",
5
5
  "keywords": [
6
6
  "kernl",
@@ -35,20 +35,18 @@
35
35
  "@modelcontextprotocol/sdk": "^1.20.2",
36
36
  "yaml": "^2.8.2",
37
37
  "@kernl-sdk/protocol": "0.5.0",
38
- "@kernl-sdk/retrieval": "0.1.9",
39
- "@kernl-sdk/shared": "^0.4.0"
38
+ "@kernl-sdk/shared": "^0.4.0",
39
+ "@kernl-sdk/retrieval": "0.1.9"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "zod": "^4.1.8"
43
43
  },
44
44
  "devDependencies": {
45
- "@ai-sdk/openai": "3.0.0-beta.57",
46
45
  "@types/node": "^24.10.0",
47
46
  "tsc-alias": "^1.8.10",
48
47
  "typescript": "5.9.2",
49
48
  "vitest": "^4.0.8",
50
- "zod": "^4.1.8",
51
- "@kernl-sdk/ai": "0.4.0"
49
+ "zod": "^4.1.8"
52
50
  },
53
51
  "scripts": {
54
52
  "clean": "rm -rf dist",
@@ -4,7 +4,7 @@ import { message, RUNNING } from "@kernl-sdk/protocol";
4
4
 
5
5
  import { Agent } from "@/agent";
6
6
  import { InMemoryThreadStore } from "@/storage/in-memory";
7
- import type { AgentRegistry, ModelRegistry } from "@/kernl/types";
7
+ import type { IAgentRegistry, IModelRegistry } from "@/kernl/types";
8
8
  import type { NewThread } from "@/storage";
9
9
  import { tevent } from "@/thread/utils";
10
10
  import type { ThreadEvent } from "@/thread/types";
@@ -14,8 +14,8 @@ import type { MThread } from "@/api/models";
14
14
  function createTestStore() {
15
15
  const store = new InMemoryThreadStore();
16
16
 
17
- const agents: AgentRegistry & Map<string, Agent> = new Map();
18
- const models: ModelRegistry & Map<string, any> = new Map();
17
+ const agents: IAgentRegistry & Map<string, Agent> = new Map();
18
+ const models: IModelRegistry & Map<string, any> = new Map();
19
19
 
20
20
  const model = {
21
21
  spec: "1.0" as const,
@@ -1,7 +1,7 @@
1
1
  import { Agent } from "@/agent";
2
- import type { BaseAgent } from "@/agent/base";
3
2
  import type { AgentOutputType } from "@/agent/types";
4
3
  import type { UnknownContext } from "@/context";
4
+ import type { AgentRegistry } from "@/kernl/registry";
5
5
  import type { TextOutput } from "@/thread/types";
6
6
 
7
7
  /**
@@ -16,7 +16,7 @@ import type { TextOutput } from "@/thread/types";
16
16
  * to realtime agents is needed, add a separate `kernl.realtimeAgents` resource.
17
17
  */
18
18
  export class RAgents {
19
- constructor(private readonly registry: Map<string, BaseAgent>) {}
19
+ constructor(private readonly registry: AgentRegistry) {}
20
20
 
21
21
  /**
22
22
  * Get a live Agent instance by id.
@@ -57,6 +57,6 @@ export class RAgents {
57
57
  * Unregister an agent at runtime.
58
58
  */
59
59
  unregister(id: string): boolean {
60
- return this.registry.delete(id);
60
+ return this.registry.unregister(id);
61
61
  }
62
62
  }
package/src/index.ts CHANGED
@@ -2,9 +2,10 @@ export { Kernl } from "./kernl";
2
2
  export type {
3
3
  KernlOptions,
4
4
  StorageOptions,
5
- AgentRegistry,
6
- ModelRegistry,
5
+ IAgentRegistry,
6
+ IModelRegistry,
7
7
  } from "./kernl";
8
+ export { AgentRegistry, ModelRegistry } from "./kernl";
8
9
  export { Agent } from "./agent";
9
10
  export { Context } from "./context";
10
11
 
@@ -56,6 +57,7 @@ export {
56
57
  THREAD_STATES,
57
58
  type ThreadState,
58
59
  type PublicThreadEvent,
60
+ type ThreadStreamEvent,
59
61
  } from "./thread/types";
60
62
 
61
63
  // --- storage ---
@@ -1,8 +1,9 @@
1
1
  export { Kernl } from "./kernl";
2
+ export { AgentRegistry, ModelRegistry } from "./registry";
2
3
  export type {
3
4
  KernlOptions,
4
5
  StorageOptions,
5
6
  MemoryOptions,
6
- AgentRegistry,
7
- ModelRegistry,
7
+ IAgentRegistry,
8
+ IModelRegistry,
8
9
  } from "./types";
@@ -6,8 +6,6 @@ import { KernlHooks } from "@/lifecycle";
6
6
  import type { Thread } from "@/thread";
7
7
  import type { ResolvedAgentResponse } from "@/guardrail";
8
8
  import { InMemoryStorage, type KernlStorage } from "@/storage";
9
- import { RThreads } from "@/api/resources/threads";
10
- import { RAgents } from "@/api/resources/agents";
11
9
  import {
12
10
  Memory,
13
11
  MemoryByteEncoder,
@@ -16,10 +14,13 @@ import {
16
14
  } from "@/memory";
17
15
 
18
16
  import { logger } from "@/lib/logger";
19
-
17
+ import { RThreads } from "@/api/resources/threads";
18
+ import { RAgents } from "@/api/resources/agents";
20
19
  import type { ThreadExecuteResult, ThreadStreamEvent } from "@/thread/types";
21
20
  import type { AgentOutputType } from "@/agent/types";
21
+
22
22
  import type { KernlOptions, MemoryOptions, StorageOptions } from "./types";
23
+ import { AgentRegistry, ModelRegistry } from "./registry";
23
24
 
24
25
  /**
25
26
  * The kernl - manages agent processes, scheduling, and task lifecycle.
@@ -28,15 +29,14 @@ import type { KernlOptions, MemoryOptions, StorageOptions } from "./types";
28
29
  * tracing.
29
30
  */
30
31
  export class Kernl extends KernlHooks {
31
- private readonly _agents: Map<string, BaseAgent> = new Map();
32
- private readonly _models: Map<string, LanguageModel> = new Map();
32
+ private readonly _agents: AgentRegistry;
33
+ private readonly _models: ModelRegistry;
34
+ private readonly _memopts: MemoryOptions | undefined;
35
+ private readonly _storopts: StorageOptions | undefined;
33
36
 
34
37
  readonly storage: KernlStorage;
35
38
  athreads: Map<string, Thread<any, any>> = new Map(); /* active threads */
36
39
 
37
- private readonly _memopts: MemoryOptions | undefined;
38
- private readonly _storopts: StorageOptions | undefined;
39
-
40
40
  private warnings = {
41
41
  embedding: false, // "Embeddings are not configured. If you want memories to auto-embed text content..."
42
42
  vector: false, // "No vector storage configured. The memories.search() function will not be..."
@@ -53,18 +53,20 @@ export class Kernl extends KernlHooks {
53
53
  this._memopts = options.memory;
54
54
  this._storopts = options.storage;
55
55
 
56
+ this._agents = new AgentRegistry();
57
+ this._models = new ModelRegistry();
56
58
  this.storage = options.storage?.db ?? new InMemoryStorage();
57
59
  this.storage.bind({ agents: this._agents, models: this._models });
58
60
  this.threads = new RThreads(this.storage.threads);
59
61
  this.agents = new RAgents(this._agents);
60
- this.memories = this.initializeMemory();
62
+ this.memories = this.initmem();
61
63
  }
62
64
 
63
65
  /**
64
66
  * Registers a new agent with the kernl instance.
65
67
  */
66
68
  register(agent: BaseAgent<any>): void {
67
- this._agents.set(agent.id, agent);
69
+ this._agents.register(agent);
68
70
  agent.bind(this);
69
71
 
70
72
  // memory config warnings (log once)
@@ -88,10 +90,7 @@ export class Kernl extends KernlHooks {
88
90
 
89
91
  // auto-populate model registry for storage hydration (llm agents only - for now)
90
92
  if (agent.kind === "llm") {
91
- const key = `${agent.model.provider}/${agent.model.modelId}`;
92
- if (!this._models.has(key)) {
93
- this._models.set(key, agent.model as LanguageModel);
94
- }
93
+ this._models.register(agent.model as LanguageModel);
95
94
  }
96
95
  }
97
96
 
@@ -101,6 +100,7 @@ export class Kernl extends KernlHooks {
101
100
  async spawn<TContext, TOutput extends AgentOutputType>(
102
101
  thread: Thread<TContext, TOutput>,
103
102
  ): Promise<ThreadExecuteResult<ResolvedAgentResponse<TOutput>>> {
103
+ this._models.register(thread.model);
104
104
  this.athreads.set(thread.tid, thread);
105
105
  try {
106
106
  return await thread.execute();
@@ -117,6 +117,7 @@ export class Kernl extends KernlHooks {
117
117
  async schedule<TContext, TOutput extends AgentOutputType>(
118
118
  thread: Thread<TContext, TOutput>,
119
119
  ): Promise<ThreadExecuteResult<ResolvedAgentResponse<TOutput>>> {
120
+ this._models.register(thread.model);
120
121
  this.athreads.set(thread.tid, thread);
121
122
  try {
122
123
  return await thread.execute();
@@ -133,6 +134,7 @@ export class Kernl extends KernlHooks {
133
134
  async *spawnStream<TContext, TOutput extends AgentOutputType>(
134
135
  thread: Thread<TContext, TOutput>,
135
136
  ): AsyncIterable<ThreadStreamEvent> {
137
+ this._models.register(thread.model);
136
138
  this.athreads.set(thread.tid, thread);
137
139
  try {
138
140
  yield* thread.stream();
@@ -149,6 +151,7 @@ export class Kernl extends KernlHooks {
149
151
  async *scheduleStream<TContext, TOutput extends AgentOutputType>(
150
152
  thread: Thread<TContext, TOutput>,
151
153
  ): AsyncIterable<ThreadStreamEvent> {
154
+ this._models.register(thread.model);
152
155
  this.athreads.set(thread.tid, thread);
153
156
  try {
154
157
  yield* thread.stream();
@@ -164,7 +167,7 @@ export class Kernl extends KernlHooks {
164
167
  *
165
168
  * Initialize the memory system based on the storage + memory configuration.
166
169
  */
167
- private initializeMemory(): Memory {
170
+ private initmem(): Memory {
168
171
  const embeddingModel = this._memopts?.embedding;
169
172
  const embedder = embeddingModel
170
173
  ? typeof embeddingModel === "string"
@@ -0,0 +1,69 @@
1
+ import type { LanguageModel } from "@kernl-sdk/protocol";
2
+
3
+ import type { BaseAgent } from "@/agent/base";
4
+ import type { IAgentRegistry, IModelRegistry } from "./types";
5
+
6
+ /**
7
+ * Registry for language models used by threads.
8
+ *
9
+ * Models are keyed by "{provider}/{modelId}" and must be registered before
10
+ * storage can hydrate threads that reference them.
11
+ */
12
+ export class ModelRegistry implements IModelRegistry {
13
+ private readonly models: Map<string, LanguageModel> = new Map();
14
+
15
+ /**
16
+ * Register a model instance. Idempotent - only adds if not already present.
17
+ */
18
+ register(model: LanguageModel): void {
19
+ const key = `${model.provider}/${model.modelId}`;
20
+ if (!this.models.has(key)) {
21
+ this.models.set(key, model);
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Get a model by its composite key ("{provider}/{modelId}").
27
+ */
28
+ get(key: string): LanguageModel | undefined {
29
+ return this.models.get(key);
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Registry for agents.
35
+ *
36
+ * Agents are keyed by their id and must be registered before threads can
37
+ * reference them.
38
+ */
39
+ export class AgentRegistry implements IAgentRegistry {
40
+ private readonly agents: Map<string, BaseAgent<any>> = new Map();
41
+
42
+ /**
43
+ * Register an agent instance. Replaces existing agent with same id.
44
+ */
45
+ register(agent: BaseAgent<any>): void {
46
+ this.agents.set(agent.id, agent);
47
+ }
48
+
49
+ /**
50
+ * Get an agent by its id.
51
+ */
52
+ get(id: string): BaseAgent<any> | undefined {
53
+ return this.agents.get(id);
54
+ }
55
+
56
+ /**
57
+ * Unregister an agent by id.
58
+ */
59
+ unregister(id: string): boolean {
60
+ return this.agents.delete(id);
61
+ }
62
+
63
+ /**
64
+ * List all registered agents.
65
+ */
66
+ values(): IterableIterator<BaseAgent<any>> {
67
+ return this.agents.values();
68
+ }
69
+ }
@@ -89,7 +89,7 @@ export interface KernlOptions {
89
89
  *
90
90
  * Satisfied by Map<string, BaseAgent>.
91
91
  */
92
- export interface AgentRegistry {
92
+ export interface IAgentRegistry {
93
93
  get(id: string): BaseAgent<any> | undefined;
94
94
  }
95
95
 
@@ -102,6 +102,6 @@ export interface AgentRegistry {
102
102
  * TODO: Create an exhaustive model registry in the protocol package
103
103
  * with all supported models and their metadata.
104
104
  */
105
- export interface ModelRegistry {
105
+ export interface IModelRegistry {
106
106
  get(key: string): LanguageModel | undefined;
107
107
  }
@@ -2,7 +2,7 @@
2
2
  * Core storage contracts.
3
3
  */
4
4
 
5
- import type { AgentRegistry, ModelRegistry } from "@/kernl/types";
5
+ import type { IAgentRegistry, IModelRegistry } from "@/kernl/types";
6
6
  import type { ThreadStore } from "./thread";
7
7
  import type { MemoryStore } from "@/memory/store";
8
8
 
@@ -30,7 +30,7 @@ export interface KernlStorage {
30
30
  *
31
31
  * Called by Kernl after construction to wire up agent/model lookups.
32
32
  */
33
- bind(registries: { agents: AgentRegistry; models: ModelRegistry }): void;
33
+ bind(registries: { agents: IAgentRegistry; models: IModelRegistry }): void;
34
34
 
35
35
  /**
36
36
  * Execute a function within a transaction.