kernl 0.12.2 → 0.12.3

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > kernl@0.12.2 build /home/runner/work/kernl/kernl/packages/kernl
2
+ > kernl@0.12.3 build /home/runner/work/kernl/kernl/packages/kernl
3
3
  > tsc && tsc-alias --resolve-full-paths
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @kernl/core
2
2
 
3
+ ## 0.12.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 884e513: Align with @ai-sdk/provider v3 stable release
8
+ - Update LanguageModelUsage to nested structure (inputTokens.total, outputTokens.total, etc.)
9
+ - Update LanguageModelFinishReason to object with unified and raw properties
10
+ - Rename LanguageModelWarning to SharedWarning with updated structure
11
+ - Update tool type from "provider-defined" to "provider"
12
+ - Bump @ai-sdk peer dependencies from beta to stable (^3.0.3)
13
+
14
+ - 0576a77: Fix model not being updated when resuming thread from storage
15
+ - Updated dependencies [884e513]
16
+ - @kernl-sdk/protocol@0.5.1
17
+ - @kernl-sdk/retrieval@0.1.10
18
+
3
19
  ## 0.12.2
4
20
 
5
21
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,iBAAiB,EACjB,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EACL,cAAc,EACd,eAAe,EACf,KAAK,qBAAqB,EAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC,OAAO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;gBAEtB,MAAM,EAAE,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC;IAYlD;;;;;OAKG;IACG,GAAG,CACP,KAAK,EAAE,MAAM,GAAG,iBAAiB,EAAE,EACnC,OAAO,CAAC,EAAE,oBAAoB,CAAC,QAAQ,CAAC,GACvC,OAAO,CAAC,mBAAmB,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;IA4D/D;;;;;;;OAOG;IACI,MAAM,CACX,KAAK,EAAE,MAAM,GAAG,iBAAiB,EAAE,EACnC,OAAO,CAAC,EAAE,oBAAoB,CAAC,QAAQ,CAAC,GACvC,aAAa,CAAC,iBAAiB,CAAC;IA6DnC;;;;OAIG;IACH,IAAI,OAAO;mBAWI,MAAM,YAAY,iBAAiB;wBAE/B,IAAI,CAAC,kBAAkB,EAAE,SAAS,CAAC;sBAEpC,MAAM;uBACL,MAAM,WAAW,oBAAoB;yBAEnC,IAAI,CAAC,mBAAmB,EAAE,SAAS,GAAG,OAAO,CAAC;sBASjD,MAAM,SAAS,mBAAmB;MAGnD;CACF"}
package/dist/agent.js CHANGED
@@ -27,14 +27,11 @@ export class Agent extends BaseAgent {
27
27
  * @throws {MisconfiguredError} If the agent is not bound to a kernl instance
28
28
  */
29
29
  async run(input, options) {
30
+ let thread = null;
30
31
  if (!this.kernl) {
31
32
  throw new MisconfiguredError(`Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`);
32
33
  }
33
- const items = typeof input === "string"
34
- ? [message({ role: "user", text: input })]
35
- : input;
36
34
  const tid = options?.threadId;
37
- let thread = null;
38
35
  if (tid) {
39
36
  // no concurrent execution of same thread - correctness contract
40
37
  // TODO: race condition - need to check again after async storage.get()
@@ -48,6 +45,9 @@ export class Agent extends BaseAgent {
48
45
  }));
49
46
  }
50
47
  }
48
+ const items = typeof input === "string"
49
+ ? [message({ role: "user", text: input })]
50
+ : input;
51
51
  // create new thread if not found in storage or no tid provided
52
52
  if (!thread) {
53
53
  const ctx = options?.context
@@ -69,6 +69,9 @@ export class Agent extends BaseAgent {
69
69
  if (options?.context) {
70
70
  thread.context.context = options.context;
71
71
  }
72
+ if (options?.model) {
73
+ thread.model = options.model;
74
+ }
72
75
  thread.append(...items);
73
76
  return this.kernl.schedule(thread);
74
77
  }
@@ -124,6 +127,9 @@ export class Agent extends BaseAgent {
124
127
  if (options?.context) {
125
128
  thread.context.context = options.context;
126
129
  }
130
+ if (options?.model) {
131
+ thread.model = options.model;
132
+ }
127
133
  thread.append(...items);
128
134
  yield* this.kernl.scheduleStream(thread);
129
135
  }
package/dist/lib/env.d.ts CHANGED
@@ -7,11 +7,11 @@ import { z } from "zod";
7
7
  */
8
8
  declare const envSchema: z.ZodObject<{
9
9
  LOG_LEVEL: z.ZodDefault<z.ZodEnum<{
10
- error: "error";
11
10
  trace: "trace";
12
11
  debug: "debug";
13
12
  info: "info";
14
13
  warn: "warn";
14
+ error: "error";
15
15
  fatal: "fatal";
16
16
  }>>;
17
17
  KERNL_LOG_MODEL_DATA: z.ZodPipe<z.ZodOptional<z.ZodEnum<{
@@ -31,7 +31,7 @@ declare const envSchema: z.ZodObject<{
31
31
  * console.log(env.LOG_LEVEL);
32
32
  */
33
33
  export declare const env: {
34
- LOG_LEVEL: "error" | "trace" | "debug" | "info" | "warn" | "fatal";
34
+ LOG_LEVEL: "trace" | "debug" | "info" | "warn" | "error" | "fatal";
35
35
  KERNL_LOG_MODEL_DATA: boolean;
36
36
  KERNL_LOG_TOOL_DATA: boolean;
37
37
  };
@@ -1 +1 @@
1
- {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../src/thread/__tests__/mock.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EAGrB,wBAAwB,EACzB,MAAM,qBAAqB,CAAC;AAE7B;;;;;GAKG;AACH,qBAAa,iBAAkB,YAAW,aAAa;IACrD,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAU;IAC/B,QAAQ,CAAC,QAAQ,UAAU;IAC3B,QAAQ,CAAC,OAAO,gBAAgB;IAE1B,QAAQ,CACZ,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAgC1B,MAAM,CACX,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CAAC,wBAAwB,CAAC;IAK1C;;OAEG;IACH,OAAO,CAAC,eAAe;IAgBvB;;OAEG;IACH,OAAO,CAAC,WAAW;IAKnB;;OAEG;IACH,OAAO,CAAC,UAAU;CAGnB"}
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../src/thread/__tests__/mock.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EAGrB,wBAAwB,EACzB,MAAM,qBAAqB,CAAC;AAE7B;;;;;GAKG;AACH,qBAAa,iBAAkB,YAAW,aAAa;IACrD,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAU;IAC/B,QAAQ,CAAC,QAAQ,UAAU;IAC3B,QAAQ,CAAC,OAAO,gBAAgB;IAE1B,QAAQ,CACZ,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAyC1B,MAAM,CACX,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CAAC,wBAAwB,CAAC;IAK1C;;OAEG;IACH,OAAO,CAAC,eAAe;IAgBvB;;OAEG;IACH,OAAO,CAAC,WAAW;IAKnB;;OAEG;IACH,OAAO,CAAC,UAAU;CAGnB"}
@@ -26,13 +26,22 @@ export class MockLanguageModel {
26
26
  },
27
27
  ];
28
28
  // Return with fake usage stats
29
+ const tokens = this.countTokens(userText);
29
30
  return {
30
31
  content,
31
- finishReason: "stop",
32
+ finishReason: { unified: "stop", raw: "stop" },
32
33
  usage: {
33
- inputTokens: this.countTokens(userText),
34
- outputTokens: this.countTokens(userText),
35
- totalTokens: this.countTokens(userText) * 2,
34
+ inputTokens: {
35
+ total: tokens,
36
+ noCache: tokens,
37
+ cacheRead: undefined,
38
+ cacheWrite: undefined,
39
+ },
40
+ outputTokens: {
41
+ total: tokens,
42
+ text: tokens,
43
+ reasoning: undefined,
44
+ },
36
45
  },
37
46
  warnings: [],
38
47
  };
@@ -155,13 +155,13 @@ export class Thread {
155
155
  for await (const e of this.tick()) {
156
156
  if (e.kind === "error") {
157
157
  err = e.error;
158
- logger.error(e.error); // (TODO): onError callback in options
158
+ logger.error(err.message); // (TODO): onError callback in options
159
159
  }
160
160
  // complete items get persisted with seq, deltas are ephemeral
161
161
  if (notDelta(e)) {
162
- const [seqd] = this.append(e);
163
- events.push(seqd);
164
- yield seqd;
162
+ const [eseq] = this.append(e);
163
+ events.push(eseq);
164
+ yield eseq;
165
165
  }
166
166
  else {
167
167
  yield e;
@@ -187,8 +187,8 @@ export class Thread {
187
187
  const { actions, pendingApprovals } = await this.performActions(intentions);
188
188
  // append + yield action events (sequenced)
189
189
  for (const a of actions) {
190
- const [seqd] = this.append(a);
191
- yield seqd;
190
+ const [eseq] = this.append(a);
191
+ yield eseq;
192
192
  }
193
193
  await this.checkpoint(); /* c3: tick complete */
194
194
  if (pendingApprovals.length > 0) {
@@ -216,7 +216,7 @@ export class Thread {
216
216
  const req = await this.prepareModelRequest(this.history);
217
217
  this.emit("model.call.start", { settings: req.settings ?? {} });
218
218
  let usage;
219
- let finishReason = "unknown";
219
+ let finishReason = { unified: "other", raw: undefined };
220
220
  try {
221
221
  if (this.model.stream) {
222
222
  for await (const event of this.model.stream(req)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kernl",
3
- "version": "0.12.2",
3
+ "version": "0.12.3",
4
4
  "description": "A modern AI agent framework",
5
5
  "keywords": [
6
6
  "kernl",
@@ -34,9 +34,9 @@
34
34
  "dependencies": {
35
35
  "@modelcontextprotocol/sdk": "^1.20.2",
36
36
  "yaml": "^2.8.2",
37
- "@kernl-sdk/protocol": "0.5.0",
38
- "@kernl-sdk/shared": "^0.4.0",
39
- "@kernl-sdk/retrieval": "0.1.9"
37
+ "@kernl-sdk/protocol": "0.5.1",
38
+ "@kernl-sdk/retrieval": "0.1.10",
39
+ "@kernl-sdk/shared": "^0.4.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "zod": "^4.1.8"
package/src/agent.ts CHANGED
@@ -71,20 +71,15 @@ export class Agent<
71
71
  input: string | LanguageModelItem[],
72
72
  options?: ThreadExecuteOptions<TContext>,
73
73
  ): Promise<ThreadExecuteResult<ResolvedAgentResponse<TOutput>>> {
74
+ let thread: Thread<TContext, TOutput> | null = null;
75
+
74
76
  if (!this.kernl) {
75
77
  throw new MisconfiguredError(
76
78
  `Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`,
77
79
  );
78
80
  }
79
81
 
80
- const items =
81
- typeof input === "string"
82
- ? [message({ role: "user", text: input })]
83
- : input;
84
82
  const tid = options?.threadId;
85
-
86
- let thread: Thread<TContext, TOutput> | null = null;
87
-
88
83
  if (tid) {
89
84
  // no concurrent execution of same thread - correctness contract
90
85
  // TODO: race condition - need to check again after async storage.get()
@@ -100,6 +95,11 @@ export class Agent<
100
95
  }
101
96
  }
102
97
 
98
+ const items =
99
+ typeof input === "string"
100
+ ? [message({ role: "user", text: input })]
101
+ : input;
102
+
103
103
  // create new thread if not found in storage or no tid provided
104
104
  if (!thread) {
105
105
  const ctx = options?.context
@@ -123,6 +123,9 @@ export class Agent<
123
123
  if (options?.context) {
124
124
  thread.context.context = options.context;
125
125
  }
126
+ if (options?.model) {
127
+ thread.model = options.model;
128
+ }
126
129
  thread.append(...items);
127
130
  return this.kernl.schedule(thread);
128
131
  }
@@ -192,6 +195,9 @@ export class Agent<
192
195
  if (options?.context) {
193
196
  thread.context.context = options.context;
194
197
  }
198
+ if (options?.model) {
199
+ thread.model = options.model;
200
+ }
195
201
  thread.append(...items);
196
202
  yield* this.kernl.scheduleStream(thread);
197
203
  }
@@ -40,13 +40,22 @@ export class MockLanguageModel implements LanguageModel {
40
40
  ];
41
41
 
42
42
  // Return with fake usage stats
43
+ const tokens = this.countTokens(userText);
43
44
  return {
44
45
  content,
45
- finishReason: "stop",
46
+ finishReason: { unified: "stop", raw: "stop" },
46
47
  usage: {
47
- inputTokens: this.countTokens(userText),
48
- outputTokens: this.countTokens(userText),
49
- totalTokens: this.countTokens(userText) * 2,
48
+ inputTokens: {
49
+ total: tokens,
50
+ noCache: tokens,
51
+ cacheRead: undefined,
52
+ cacheWrite: undefined,
53
+ },
54
+ outputTokens: {
55
+ total: tokens,
56
+ text: tokens,
57
+ reasoning: undefined,
58
+ },
50
59
  },
51
60
  warnings: [],
52
61
  };
@@ -216,13 +216,13 @@ export class Thread<
216
216
  for await (const e of this.tick()) {
217
217
  if (e.kind === "error") {
218
218
  err = e.error;
219
- logger.error(e.error); // (TODO): onError callback in options
219
+ logger.error(err.message); // (TODO): onError callback in options
220
220
  }
221
221
  // complete items get persisted with seq, deltas are ephemeral
222
222
  if (notDelta(e)) {
223
- const [seqd] = this.append(e);
224
- events.push(seqd);
225
- yield seqd;
223
+ const [eseq] = this.append(e);
224
+ events.push(eseq);
225
+ yield eseq;
226
226
  } else {
227
227
  yield e;
228
228
  }
@@ -253,8 +253,8 @@ export class Thread<
253
253
 
254
254
  // append + yield action events (sequenced)
255
255
  for (const a of actions) {
256
- const [seqd] = this.append(a);
257
- yield seqd;
256
+ const [eseq] = this.append(a);
257
+ yield eseq;
258
258
  }
259
259
 
260
260
  await this.checkpoint(); /* c3: tick complete */
@@ -289,7 +289,7 @@ export class Thread<
289
289
  this.emit("model.call.start", { settings: req.settings ?? {} });
290
290
 
291
291
  let usage: LanguageModelUsage | undefined;
292
- let finishReason: LanguageModelFinishReason = "unknown";
292
+ let finishReason: LanguageModelFinishReason = { unified: "other", raw: undefined };
293
293
 
294
294
  try {
295
295
  if (this.model.stream) {