kernl 0.11.2 → 0.12.0
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +62 -0
- package/dist/agent/__tests__/run.test.js +2 -2
- package/dist/context.d.ts +2 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -0
- package/dist/kernl/kernl.d.ts +1 -1
- package/dist/kernl/kernl.d.ts.map +1 -1
- package/dist/lifecycle/__tests__/hooks.test.js +6 -6
- package/dist/storage/__tests__/in-memory.test.js +1 -1
- package/dist/thread/__tests__/fixtures/mock-model.js +3 -3
- package/dist/thread/__tests__/integration.test.js +14 -14
- package/dist/thread/__tests__/thread-persistence.test.js +6 -6
- package/dist/thread/__tests__/thread.test.js +22 -22
- package/dist/thread/thread.js +5 -5
- package/dist/thread/utils.js +5 -5
- package/dist/tool/__tests__/tool.test.js +4 -4
- package/dist/tool/tool.d.ts +1 -2
- package/dist/tool/tool.d.ts.map +1 -1
- package/dist/tool/tool.js +2 -2
- package/dist/tool/toolkit.d.ts +5 -3
- package/dist/tool/toolkit.d.ts.map +1 -1
- package/dist/tool/toolkit.js +3 -1
- package/dist/tool/types.d.ts +1 -2
- package/dist/tool/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/agent/__tests__/run.test.ts +2 -2
- package/src/context.ts +2 -1
- package/src/kernl/kernl.ts +1 -1
- package/src/lifecycle/__tests__/hooks.test.ts +6 -6
- package/src/storage/__tests__/in-memory.test.ts +1 -1
- package/src/thread/__tests__/fixtures/mock-model.ts +3 -3
- package/src/thread/__tests__/integration.test.ts +18 -18
- package/src/thread/__tests__/thread-persistence.test.ts +6 -6
- package/src/thread/__tests__/thread.test.ts +22 -22
- package/src/thread/thread.ts +5 -5
- package/src/thread/utils.ts +5 -5
- package/src/tool/__tests__/tool.test.ts +4 -8
- package/src/tool/tool.ts +3 -3
- package/src/tool/toolkit.ts +5 -3
- package/src/tool/types.ts +0 -2
package/dist/tool/tool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/tool/tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/tool/tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAMpD,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EACV,UAAU,EACV,oBAAoB,EACpB,mBAAmB,EAEnB,iBAAiB,EAGjB,mBAAmB,EACnB,UAAU,EACX,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,wBAAgB,IAAI,CAClB,QAAQ,GAAG,cAAc,EACzB,WAAW,SAAS,mBAAmB,GAAG,SAAS,EACnD,OAAO,GAAG,MAAM,EAEhB,MAAM,EAAE,UAAU,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,GACjD,YAAY,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,CAE9C;AAED;;GAEG;AACH,8BAAsB,QAAQ,CAAC,QAAQ,GAAG,cAAc;IACtD,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,aAAa,CAAC;IACnD,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEhC;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAE3C;;OAEG;IACH,QAAQ,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAC;IAErD;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,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AAC;IACvB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE5C;;OAEG;IACH,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAA4B;IAE7D;;OAEG;IACH,gBAAgB,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAqB;gBAEpD,MAAM,EAAE;QAClB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACpC;IAOD;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAInC;;OAEG;IACH,SAAS,IAAI,iBAAiB;CAQ/B"}
|
package/dist/tool/tool.js
CHANGED
|
@@ -54,9 +54,9 @@ export class FunctionTool extends BaseTool {
|
|
|
54
54
|
// setup enabled function
|
|
55
55
|
this.isEnabled =
|
|
56
56
|
typeof config.isEnabled === "function"
|
|
57
|
-
? async (context
|
|
57
|
+
? async (context) => {
|
|
58
58
|
const predicate = config.isEnabled;
|
|
59
|
-
const result = await predicate({ context
|
|
59
|
+
const result = await predicate({ context });
|
|
60
60
|
return Boolean(result);
|
|
61
61
|
}
|
|
62
62
|
: async () => typeof config.isEnabled === "boolean" ? config.isEnabled : true;
|
package/dist/tool/toolkit.d.ts
CHANGED
|
@@ -18,14 +18,16 @@ export declare abstract class BaseToolkit<TContext = UnknownContext> {
|
|
|
18
18
|
*/
|
|
19
19
|
abstract readonly description: string;
|
|
20
20
|
/**
|
|
21
|
-
* The agent this toolkit is bound to (if any)
|
|
21
|
+
* The agent this toolkit is bound to (if any).
|
|
22
|
+
* Uses `any` to allow toolkits with different context types
|
|
23
|
+
* to be composed in the same agent.
|
|
22
24
|
*/
|
|
23
|
-
protected agent?: BaseAgent<
|
|
25
|
+
protected agent?: BaseAgent<any>;
|
|
24
26
|
/**
|
|
25
27
|
* Bind this toolkit to an agent.
|
|
26
28
|
* Called by agent constructor.
|
|
27
29
|
*/
|
|
28
|
-
bind(agent: BaseAgent<
|
|
30
|
+
bind(agent: BaseAgent<any>): void;
|
|
29
31
|
/**
|
|
30
32
|
* Get a specific tool by its ID.
|
|
31
33
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolkit.d.ts","sourceRoot":"","sources":["../../src/tool/toolkit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAMzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;AAC9B,OAAO,KAAK,EACV,qBAAqB,EACrB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,8BAAsB,WAAW,CAAC,QAAQ,GAAG,cAAc;IACzD;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAEtC
|
|
1
|
+
{"version":3,"file":"toolkit.d.ts","sourceRoot":"","sources":["../../src/tool/toolkit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAMzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;AAC9B,OAAO,KAAK,EACV,qBAAqB,EACrB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,8BAAsB,WAAW,CAAC,QAAQ,GAAG,cAAc;IACzD;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,WAAW,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C,WAAW,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,KAAK,CAA8B;IAC3C,OAAO,CAAC,MAAM,CAA0B;IAExC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;OAIG;gBACS,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC;IAS9C;;;;;;;;OAQG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,SAAS;IAI3C;;;;;;;;;OASG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;IAgClE;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ/B"}
|
package/dist/tool/toolkit.js
CHANGED
|
@@ -8,7 +8,9 @@ import { filter } from "@kernl-sdk/shared/lib";
|
|
|
8
8
|
*/
|
|
9
9
|
export class BaseToolkit {
|
|
10
10
|
/**
|
|
11
|
-
* The agent this toolkit is bound to (if any)
|
|
11
|
+
* The agent this toolkit is bound to (if any).
|
|
12
|
+
* Uses `any` to allow toolkits with different context types
|
|
13
|
+
* to be composed in the same agent.
|
|
12
14
|
*/
|
|
13
15
|
agent;
|
|
14
16
|
/**
|
package/dist/tool/types.d.ts
CHANGED
|
@@ -176,10 +176,9 @@ export type ToolExecuteFunction<TContext = UnknownContext, TParameters extends T
|
|
|
176
176
|
* @returns True if the tool call should be approved, false otherwise
|
|
177
177
|
*/
|
|
178
178
|
export type ToolApprovalFunction<TParameters extends ToolInputParameters> = (context: Context, input: ToolExecuteArgument<TParameters>, callId?: string) => Promise<boolean>;
|
|
179
|
-
export type ToolEnabledFunction<TContext = UnknownContext> = (context: Context<TContext
|
|
179
|
+
export type ToolEnabledFunction<TContext = UnknownContext> = (context: Context<TContext>) => Promise<boolean>;
|
|
180
180
|
export type ToolEnabledPredicate<TContext = UnknownContext> = (args: {
|
|
181
181
|
context: Context<TContext>;
|
|
182
|
-
agent: BaseAgent<TContext>;
|
|
183
182
|
}) => boolean | Promise<boolean>;
|
|
184
183
|
type ToolEnabledOption<Context = UnknownContext> = boolean | ToolEnabledPredicate<Context>;
|
|
185
184
|
/**
|
package/dist/tool/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tool/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,IAAI,CAAC,QAAQ,GAAG,cAAc,IACtC,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC,GAChC,UAAU,CAAC;AAEf;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CACpB,QAAQ,GAAG,cAAc,EACzB,WAAW,SAAS,mBAAmB,GAAG,SAAS,EACnD,OAAO,GAAG,OAAO,IACf;IACF;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,UAAU,EAAE,WAAW,CAAC;IAExB;;;OAGG;IACH,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;IAE5B;;OAEG;IACH,OAAO,EAAE,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0.
|
|
3
|
+
"version": "0.12.0",
|
|
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/
|
|
38
|
-
"@kernl-sdk/
|
|
39
|
-
"@kernl-sdk/
|
|
37
|
+
"@kernl-sdk/protocol": "0.5.0",
|
|
38
|
+
"@kernl-sdk/retrieval": "0.1.9",
|
|
39
|
+
"@kernl-sdk/shared": "^0.4.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"zod": "^4.1.8"
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"typescript": "5.9.2",
|
|
49
49
|
"vitest": "^4.0.8",
|
|
50
50
|
"zod": "^4.1.8",
|
|
51
|
-
"@kernl-sdk/ai": "0.
|
|
51
|
+
"@kernl-sdk/ai": "0.4.0"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"clean": "rm -rf dist",
|
|
@@ -268,7 +268,7 @@ describe("Agent.stream() lifecycle", () => {
|
|
|
268
268
|
events.push(event);
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
expect(events[0]).toEqual({ kind: "stream
|
|
271
|
+
expect(events[0]).toEqual({ kind: "stream.start" });
|
|
272
272
|
});
|
|
273
273
|
|
|
274
274
|
it("should have same persistence behavior as run()", async () => {
|
|
@@ -305,7 +305,7 @@ describe("Agent.stream() lifecycle", () => {
|
|
|
305
305
|
// Should have streamed events
|
|
306
306
|
expect(events).toEqual(
|
|
307
307
|
expect.arrayContaining([
|
|
308
|
-
{ kind: "stream
|
|
308
|
+
{ kind: "stream.start" },
|
|
309
309
|
expect.objectContaining({ kind: "message" }),
|
|
310
310
|
]),
|
|
311
311
|
);
|
package/src/context.ts
CHANGED
|
@@ -25,8 +25,9 @@ export class Context<TContext = UnknownContext> {
|
|
|
25
25
|
* Set by the thread during execution.
|
|
26
26
|
*
|
|
27
27
|
* NOTE: Primarily used by system tools (e.g., memory) that need agent access.
|
|
28
|
+
* Uses `any` to avoid invariance issues when composing toolkits.
|
|
28
29
|
*/
|
|
29
|
-
agent?: Agent<
|
|
30
|
+
agent?: Agent<any, any>;
|
|
30
31
|
|
|
31
32
|
// ----------------------
|
|
32
33
|
// TEMPORARY: Tool approval tracking until actions system is refined
|
package/src/kernl/kernl.ts
CHANGED
|
@@ -308,7 +308,7 @@ describe("Lifecycle Hooks", () => {
|
|
|
308
308
|
content: [
|
|
309
309
|
message({ role: "assistant", text: "" }),
|
|
310
310
|
{
|
|
311
|
-
kind: "tool
|
|
311
|
+
kind: "tool.call" as const,
|
|
312
312
|
toolId: "echo",
|
|
313
313
|
state: IN_PROGRESS,
|
|
314
314
|
callId: "call_1",
|
|
@@ -381,7 +381,7 @@ describe("Lifecycle Hooks", () => {
|
|
|
381
381
|
content: [
|
|
382
382
|
message({ role: "assistant", text: "" }),
|
|
383
383
|
{
|
|
384
|
-
kind: "tool
|
|
384
|
+
kind: "tool.call" as const,
|
|
385
385
|
toolId: "add",
|
|
386
386
|
state: IN_PROGRESS,
|
|
387
387
|
callId: "call_1",
|
|
@@ -446,7 +446,7 @@ describe("Lifecycle Hooks", () => {
|
|
|
446
446
|
content: [
|
|
447
447
|
message({ role: "assistant", text: "" }),
|
|
448
448
|
{
|
|
449
|
-
kind: "tool
|
|
449
|
+
kind: "tool.call" as const,
|
|
450
450
|
toolId: "add",
|
|
451
451
|
state: IN_PROGRESS,
|
|
452
452
|
callId: "call_1",
|
|
@@ -510,7 +510,7 @@ describe("Lifecycle Hooks", () => {
|
|
|
510
510
|
content: [
|
|
511
511
|
message({ role: "assistant", text: "" }),
|
|
512
512
|
{
|
|
513
|
-
kind: "tool
|
|
513
|
+
kind: "tool.call" as const,
|
|
514
514
|
toolId: "failing",
|
|
515
515
|
state: IN_PROGRESS,
|
|
516
516
|
callId: "call_1",
|
|
@@ -576,14 +576,14 @@ describe("Lifecycle Hooks", () => {
|
|
|
576
576
|
content: [
|
|
577
577
|
message({ role: "assistant", text: "" }),
|
|
578
578
|
{
|
|
579
|
-
kind: "tool
|
|
579
|
+
kind: "tool.call" as const,
|
|
580
580
|
toolId: "tool1",
|
|
581
581
|
state: IN_PROGRESS,
|
|
582
582
|
callId: "call_1",
|
|
583
583
|
arguments: JSON.stringify({ value: "a" }),
|
|
584
584
|
},
|
|
585
585
|
{
|
|
586
|
-
kind: "tool
|
|
586
|
+
kind: "tool.call" as const,
|
|
587
587
|
toolId: "tool2",
|
|
588
588
|
state: IN_PROGRESS,
|
|
589
589
|
callId: "call_2",
|
|
@@ -20,18 +20,18 @@ async function* streamFromResponse(
|
|
|
20
20
|
if (contentItem.kind === "text") {
|
|
21
21
|
// Yield text-start
|
|
22
22
|
yield {
|
|
23
|
-
kind: "text
|
|
23
|
+
kind: "text.start" as const,
|
|
24
24
|
id: item.id,
|
|
25
25
|
};
|
|
26
26
|
// Yield text-delta
|
|
27
27
|
yield {
|
|
28
|
-
kind: "text
|
|
28
|
+
kind: "text.delta" as const,
|
|
29
29
|
id: item.id,
|
|
30
30
|
text: contentItem.text,
|
|
31
31
|
};
|
|
32
32
|
// Yield text-end
|
|
33
33
|
yield {
|
|
34
|
-
kind: "text
|
|
34
|
+
kind: "text.end" as const,
|
|
35
35
|
id: item.id,
|
|
36
36
|
};
|
|
37
37
|
}
|
|
@@ -63,15 +63,15 @@ describe.skipIf(SKIP_INTEGRATION_TESTS)("Thread streaming integration", () => {
|
|
|
63
63
|
expect(events.length).toBeGreaterThan(0);
|
|
64
64
|
|
|
65
65
|
// Should have text-delta events (for streaming UX)
|
|
66
|
-
const textDeltas = events.filter((e) => e.kind === "text
|
|
66
|
+
const textDeltas = events.filter((e) => e.kind === "text.delta");
|
|
67
67
|
expect(textDeltas.length).toBeGreaterThan(0);
|
|
68
68
|
|
|
69
69
|
// Should have text-start event
|
|
70
|
-
const textStarts = events.filter((e) => e.kind === "text
|
|
70
|
+
const textStarts = events.filter((e) => e.kind === "text.start");
|
|
71
71
|
expect(textStarts.length).toBeGreaterThan(0);
|
|
72
72
|
|
|
73
73
|
// Should have text-end event
|
|
74
|
-
const textEnds = events.filter((e) => e.kind === "text
|
|
74
|
+
const textEnds = events.filter((e) => e.kind === "text.end");
|
|
75
75
|
expect(textEnds.length).toBeGreaterThan(0);
|
|
76
76
|
|
|
77
77
|
// Should have complete Message item (for history)
|
|
@@ -140,9 +140,9 @@ describe.skipIf(SKIP_INTEGRATION_TESTS)("Thread streaming integration", () => {
|
|
|
140
140
|
// Stream events should include deltas (but history should not)
|
|
141
141
|
const streamDeltas = streamEvents.filter(
|
|
142
142
|
(e: any) =>
|
|
143
|
-
e.kind === "text
|
|
144
|
-
e.kind === "text
|
|
145
|
-
e.kind === "text
|
|
143
|
+
e.kind === "text.delta" ||
|
|
144
|
+
e.kind === "text.start" ||
|
|
145
|
+
e.kind === "text.end",
|
|
146
146
|
);
|
|
147
147
|
expect(streamDeltas.length).toBeGreaterThan(0);
|
|
148
148
|
|
|
@@ -216,8 +216,8 @@ describe.skipIf(SKIP_INTEGRATION_TESTS)("Thread streaming integration", () => {
|
|
|
216
216
|
|
|
217
217
|
// Should have tool calls
|
|
218
218
|
const toolCalls = events.filter(
|
|
219
|
-
(e): e is Extract<ThreadStreamEvent, { kind: "tool
|
|
220
|
-
e.kind === "tool
|
|
219
|
+
(e): e is Extract<ThreadStreamEvent, { kind: "tool.call" }> =>
|
|
220
|
+
e.kind === "tool.call",
|
|
221
221
|
);
|
|
222
222
|
expect(toolCalls.length).toBeGreaterThan(0);
|
|
223
223
|
|
|
@@ -228,8 +228,8 @@ describe.skipIf(SKIP_INTEGRATION_TESTS)("Thread streaming integration", () => {
|
|
|
228
228
|
|
|
229
229
|
// Should have tool results
|
|
230
230
|
const toolResults = events.filter(
|
|
231
|
-
(e): e is Extract<ThreadStreamEvent, { kind: "tool
|
|
232
|
-
e.kind === "tool
|
|
231
|
+
(e): e is Extract<ThreadStreamEvent, { kind: "tool.result" }> =>
|
|
232
|
+
e.kind === "tool.result",
|
|
233
233
|
);
|
|
234
234
|
expect(toolResults.length).toBeGreaterThan(0);
|
|
235
235
|
|
|
@@ -242,9 +242,9 @@ describe.skipIf(SKIP_INTEGRATION_TESTS)("Thread streaming integration", () => {
|
|
|
242
242
|
|
|
243
243
|
// History should contain tool calls and results
|
|
244
244
|
const history = (thread as any).history as ThreadEvent[];
|
|
245
|
-
const historyToolCalls = history.filter((e) => e.kind === "tool
|
|
245
|
+
const historyToolCalls = history.filter((e) => e.kind === "tool.call");
|
|
246
246
|
const historyToolResults = history.filter(
|
|
247
|
-
(e) => e.kind === "tool
|
|
247
|
+
(e) => e.kind === "tool.result",
|
|
248
248
|
);
|
|
249
249
|
|
|
250
250
|
expect(historyToolCalls.length).toBe(toolCalls.length);
|
|
@@ -309,12 +309,12 @@ describe.skipIf(SKIP_INTEGRATION_TESTS)("Thread streaming integration", () => {
|
|
|
309
309
|
|
|
310
310
|
// Find the tool call and result
|
|
311
311
|
const toolCalls = events.filter(
|
|
312
|
-
(e): e is Extract<ThreadStreamEvent, { kind: "tool
|
|
313
|
-
e.kind === "tool
|
|
312
|
+
(e): e is Extract<ThreadStreamEvent, { kind: "tool.call" }> =>
|
|
313
|
+
e.kind === "tool.call",
|
|
314
314
|
);
|
|
315
315
|
const toolResults = events.filter(
|
|
316
|
-
(e): e is Extract<ThreadStreamEvent, { kind: "tool
|
|
317
|
-
e.kind === "tool
|
|
316
|
+
(e): e is Extract<ThreadStreamEvent, { kind: "tool.result" }> =>
|
|
317
|
+
e.kind === "tool.result",
|
|
318
318
|
);
|
|
319
319
|
|
|
320
320
|
expect(toolCalls.length).toBeGreaterThan(0);
|
|
@@ -336,10 +336,10 @@ describe.skipIf(SKIP_INTEGRATION_TESTS)("Thread streaming integration", () => {
|
|
|
336
336
|
// Verify history contains both with matching callIds
|
|
337
337
|
const history = (thread as any).history as ThreadEvent[];
|
|
338
338
|
const historyToolCall = history.find(
|
|
339
|
-
(e) => e.kind === "tool
|
|
339
|
+
(e) => e.kind === "tool.call" && e.toolId === "multiply",
|
|
340
340
|
);
|
|
341
341
|
const historyToolResult = history.find(
|
|
342
|
-
(e) => e.kind === "tool
|
|
342
|
+
(e) => e.kind === "tool.result" && e.toolId === "multiply",
|
|
343
343
|
);
|
|
344
344
|
|
|
345
345
|
expect(historyToolCall).toBeDefined();
|
|
@@ -77,7 +77,7 @@ describe("Thread Persistence", () => {
|
|
|
77
77
|
// return {
|
|
78
78
|
// content: [
|
|
79
79
|
// message({ role: "assistant", text: "" }),
|
|
80
|
-
// { kind: "tool
|
|
80
|
+
// { kind: "tool.call", toolId: "test", callId: "call_1", state: IN_PROGRESS, arguments: "{}" },
|
|
81
81
|
// ],
|
|
82
82
|
// finishReason: "stop",
|
|
83
83
|
// usage: { inputTokens: 2, outputTokens: 2, totalTokens: 4 },
|
|
@@ -138,7 +138,7 @@ describe("Thread Persistence", () => {
|
|
|
138
138
|
// return {
|
|
139
139
|
// content: [
|
|
140
140
|
// message({ role: "assistant", text: "" }),
|
|
141
|
-
// { kind: "tool
|
|
141
|
+
// { kind: "tool.call", toolId: "echo", callId: "call_1", state: IN_PROGRESS, arguments: '{"text":"test"}' },
|
|
142
142
|
// ],
|
|
143
143
|
// finishReason: "stop",
|
|
144
144
|
// usage: { inputTokens: 2, outputTokens: 2, totalTokens: 4 },
|
|
@@ -178,7 +178,7 @@ describe("Thread Persistence", () => {
|
|
|
178
178
|
//
|
|
179
179
|
// // Find the append call for tick 1 (should include model message, tool-call, and tool-result)
|
|
180
180
|
// const tick1Events = storage.calls.append.find(batch =>
|
|
181
|
-
// batch.some(e => e.kind === "tool
|
|
181
|
+
// batch.some(e => e.kind === "tool.result")
|
|
182
182
|
// );
|
|
183
183
|
//
|
|
184
184
|
// expect(tick1Events).toBeDefined();
|
|
@@ -188,8 +188,8 @@ describe("Thread Persistence", () => {
|
|
|
188
188
|
// expect(tick1Events).toEqual(
|
|
189
189
|
// expect.arrayContaining([
|
|
190
190
|
// expect.objectContaining({ kind: "message", role: "assistant" }),
|
|
191
|
-
// expect.objectContaining({ kind: "tool
|
|
192
|
-
// expect.objectContaining({ kind: "tool
|
|
191
|
+
// expect.objectContaining({ kind: "tool.call", toolId: "echo" }),
|
|
192
|
+
// expect.objectContaining({ kind: "tool.result", toolId: "echo", result: "Echo: test" }),
|
|
193
193
|
// ])
|
|
194
194
|
// );
|
|
195
195
|
});
|
|
@@ -232,7 +232,7 @@ describe("Thread Persistence", () => {
|
|
|
232
232
|
// expect(lastUpdate.patch.state).toBe(STOPPED);
|
|
233
233
|
//
|
|
234
234
|
// // Verify stream-start event
|
|
235
|
-
// expect(events[0]).toEqual({ kind: "stream
|
|
235
|
+
// expect(events[0]).toEqual({ kind: "stream.start" });
|
|
236
236
|
});
|
|
237
237
|
|
|
238
238
|
it.skip("should persist STOPPED state even on model error", async () => {
|
|
@@ -194,7 +194,7 @@ describe("Thread", () => {
|
|
|
194
194
|
content: [],
|
|
195
195
|
},
|
|
196
196
|
{
|
|
197
|
-
kind: "tool
|
|
197
|
+
kind: "tool.call" as const,
|
|
198
198
|
toolId: "echo",
|
|
199
199
|
state: IN_PROGRESS,
|
|
200
200
|
callId: "call_1",
|
|
@@ -270,7 +270,7 @@ describe("Thread", () => {
|
|
|
270
270
|
}),
|
|
271
271
|
// Tool call (tick 1)
|
|
272
272
|
expect.objectContaining({
|
|
273
|
-
kind: "tool
|
|
273
|
+
kind: "tool.call",
|
|
274
274
|
toolId: "echo",
|
|
275
275
|
callId: "call_1",
|
|
276
276
|
state: IN_PROGRESS,
|
|
@@ -278,7 +278,7 @@ describe("Thread", () => {
|
|
|
278
278
|
}),
|
|
279
279
|
// Tool result (executed after tick 1)
|
|
280
280
|
expect.objectContaining({
|
|
281
|
-
kind: "tool
|
|
281
|
+
kind: "tool.result",
|
|
282
282
|
callId: "call_1",
|
|
283
283
|
toolId: "echo",
|
|
284
284
|
state: COMPLETED,
|
|
@@ -312,7 +312,7 @@ describe("Thread", () => {
|
|
|
312
312
|
content: [],
|
|
313
313
|
},
|
|
314
314
|
{
|
|
315
|
-
kind: "tool
|
|
315
|
+
kind: "tool.call" as const,
|
|
316
316
|
toolId: "simple",
|
|
317
317
|
state: IN_PROGRESS,
|
|
318
318
|
callId: "call_1",
|
|
@@ -339,7 +339,7 @@ describe("Thread", () => {
|
|
|
339
339
|
content: [],
|
|
340
340
|
},
|
|
341
341
|
{
|
|
342
|
-
kind: "tool
|
|
342
|
+
kind: "tool.call" as const,
|
|
343
343
|
toolId: "simple",
|
|
344
344
|
state: IN_PROGRESS,
|
|
345
345
|
callId: "call_2",
|
|
@@ -423,7 +423,7 @@ describe("Thread", () => {
|
|
|
423
423
|
content: [],
|
|
424
424
|
},
|
|
425
425
|
{
|
|
426
|
-
kind: "tool
|
|
426
|
+
kind: "tool.call" as const,
|
|
427
427
|
toolId: "nonexistent",
|
|
428
428
|
state: IN_PROGRESS,
|
|
429
429
|
callId: "call_1",
|
|
@@ -476,9 +476,9 @@ describe("Thread", () => {
|
|
|
476
476
|
const history = (thread as any).history as ThreadEvent[];
|
|
477
477
|
|
|
478
478
|
// Check that the tool result is an error
|
|
479
|
-
const toolResult = history.find((e) => e.kind === "tool
|
|
479
|
+
const toolResult = history.find((e) => e.kind === "tool.result");
|
|
480
480
|
expect(toolResult).toEqual(expect.objectContaining({
|
|
481
|
-
kind: "tool
|
|
481
|
+
kind: "tool.result",
|
|
482
482
|
callId: "call_1",
|
|
483
483
|
toolId: "nonexistent",
|
|
484
484
|
state: FAILED,
|
|
@@ -504,7 +504,7 @@ describe("Thread", () => {
|
|
|
504
504
|
content: [],
|
|
505
505
|
},
|
|
506
506
|
{
|
|
507
|
-
kind: "tool
|
|
507
|
+
kind: "tool.call" as const,
|
|
508
508
|
toolId: "failing",
|
|
509
509
|
state: IN_PROGRESS,
|
|
510
510
|
callId: "call_1",
|
|
@@ -567,9 +567,9 @@ describe("Thread", () => {
|
|
|
567
567
|
|
|
568
568
|
const history = (thread as any).history as ThreadEvent[];
|
|
569
569
|
|
|
570
|
-
const toolResult = history.find((e) => e.kind === "tool
|
|
570
|
+
const toolResult = history.find((e) => e.kind === "tool.result");
|
|
571
571
|
expect(toolResult).toMatchObject({
|
|
572
|
-
kind: "tool
|
|
572
|
+
kind: "tool.result",
|
|
573
573
|
callId: "call_1",
|
|
574
574
|
toolId: "failing",
|
|
575
575
|
state: FAILED,
|
|
@@ -595,7 +595,7 @@ describe("Thread", () => {
|
|
|
595
595
|
content: [],
|
|
596
596
|
},
|
|
597
597
|
{
|
|
598
|
-
kind: "tool
|
|
598
|
+
kind: "tool.call" as const,
|
|
599
599
|
toolId: "add",
|
|
600
600
|
state: IN_PROGRESS,
|
|
601
601
|
callId: "call_1",
|
|
@@ -655,9 +655,9 @@ describe("Thread", () => {
|
|
|
655
655
|
// @ts-expect-error
|
|
656
656
|
const history = thread.history as ThreadEvent[];
|
|
657
657
|
|
|
658
|
-
const toolResult = history.find((e) => e.kind === "tool
|
|
658
|
+
const toolResult = history.find((e) => e.kind === "tool.result");
|
|
659
659
|
expect(toolResult).toEqual(expect.objectContaining({
|
|
660
|
-
kind: "tool
|
|
660
|
+
kind: "tool.result",
|
|
661
661
|
callId: "call_1",
|
|
662
662
|
toolId: "add",
|
|
663
663
|
state: COMPLETED,
|
|
@@ -685,14 +685,14 @@ describe("Thread", () => {
|
|
|
685
685
|
content: [],
|
|
686
686
|
},
|
|
687
687
|
{
|
|
688
|
-
kind: "tool
|
|
688
|
+
kind: "tool.call" as const,
|
|
689
689
|
toolId: "tool1",
|
|
690
690
|
state: IN_PROGRESS,
|
|
691
691
|
callId: "call_1",
|
|
692
692
|
arguments: JSON.stringify({ value: "a" }),
|
|
693
693
|
},
|
|
694
694
|
{
|
|
695
|
-
kind: "tool
|
|
695
|
+
kind: "tool.call" as const,
|
|
696
696
|
toolId: "tool2",
|
|
697
697
|
state: IN_PROGRESS,
|
|
698
698
|
callId: "call_2",
|
|
@@ -761,12 +761,12 @@ describe("Thread", () => {
|
|
|
761
761
|
const history = (thread as any).history as ThreadEvent[];
|
|
762
762
|
|
|
763
763
|
// Should have both tool results in history
|
|
764
|
-
const toolResults = history.filter((e) => e.kind === "tool
|
|
764
|
+
const toolResults = history.filter((e) => e.kind === "tool.result");
|
|
765
765
|
expect(toolResults).toHaveLength(2);
|
|
766
766
|
expect(toolResults).toEqual(
|
|
767
767
|
expect.arrayContaining([
|
|
768
768
|
expect.objectContaining({
|
|
769
|
-
kind: "tool
|
|
769
|
+
kind: "tool.result",
|
|
770
770
|
callId: "call_1",
|
|
771
771
|
toolId: "tool1",
|
|
772
772
|
state: COMPLETED,
|
|
@@ -774,7 +774,7 @@ describe("Thread", () => {
|
|
|
774
774
|
error: null,
|
|
775
775
|
}),
|
|
776
776
|
expect.objectContaining({
|
|
777
|
-
kind: "tool
|
|
777
|
+
kind: "tool.result",
|
|
778
778
|
callId: "call_2",
|
|
779
779
|
toolId: "tool2",
|
|
780
780
|
state: COMPLETED,
|
|
@@ -803,7 +803,7 @@ describe("Thread", () => {
|
|
|
803
803
|
content: [],
|
|
804
804
|
},
|
|
805
805
|
{
|
|
806
|
-
kind: "tool
|
|
806
|
+
kind: "tool.call" as const,
|
|
807
807
|
toolId: "simple",
|
|
808
808
|
state: IN_PROGRESS,
|
|
809
809
|
callId: `call_${callCount}`,
|
|
@@ -880,7 +880,7 @@ describe("Thread", () => {
|
|
|
880
880
|
content: [],
|
|
881
881
|
},
|
|
882
882
|
{
|
|
883
|
-
kind: "tool
|
|
883
|
+
kind: "tool.call" as const,
|
|
884
884
|
toolId: "simple",
|
|
885
885
|
state: IN_PROGRESS,
|
|
886
886
|
callId: "call_1",
|
|
@@ -997,7 +997,7 @@ describe("Thread", () => {
|
|
|
997
997
|
content: [{ kind: "text" as const, text: "Let me use a tool" }],
|
|
998
998
|
},
|
|
999
999
|
{
|
|
1000
|
-
kind: "tool
|
|
1000
|
+
kind: "tool.call" as const,
|
|
1001
1001
|
toolId: "simple",
|
|
1002
1002
|
state: IN_PROGRESS,
|
|
1003
1003
|
callId: "call_1",
|
package/src/thread/thread.ts
CHANGED
|
@@ -184,7 +184,7 @@ export class Thread<
|
|
|
184
184
|
context: this.context,
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
-
yield { kind: "stream
|
|
187
|
+
yield { kind: "stream.start" }; // always yield start immediately
|
|
188
188
|
|
|
189
189
|
try {
|
|
190
190
|
yield* this._execute();
|
|
@@ -470,7 +470,7 @@ export class Thread<
|
|
|
470
470
|
// (TODO): clean this - approval tracking should be handled differently
|
|
471
471
|
for (const e of toolEvents) {
|
|
472
472
|
if (
|
|
473
|
-
e.kind === "tool
|
|
473
|
+
e.kind === "tool.result" &&
|
|
474
474
|
(e.state as any) === "requires_approval" // (TODO): fix this
|
|
475
475
|
) {
|
|
476
476
|
// find the original tool call for this pending approval
|
|
@@ -542,7 +542,7 @@ export class Thread<
|
|
|
542
542
|
});
|
|
543
543
|
|
|
544
544
|
return {
|
|
545
|
-
kind: "tool
|
|
545
|
+
kind: "tool.result" as const,
|
|
546
546
|
callId: call.callId,
|
|
547
547
|
toolId: call.toolId,
|
|
548
548
|
state: res.state,
|
|
@@ -562,7 +562,7 @@ export class Thread<
|
|
|
562
562
|
});
|
|
563
563
|
|
|
564
564
|
return {
|
|
565
|
-
kind: "tool
|
|
565
|
+
kind: "tool.result" as const,
|
|
566
566
|
callId: call.callId,
|
|
567
567
|
toolId: call.toolId,
|
|
568
568
|
state: FAILED,
|
|
@@ -610,7 +610,7 @@ export class Thread<
|
|
|
610
610
|
const all = await this.agent.tools(this.context);
|
|
611
611
|
const enabled = await filter(
|
|
612
612
|
all,
|
|
613
|
-
async (tool) => await tool.isEnabled(this.context
|
|
613
|
+
async (tool) => await tool.isEnabled(this.context),
|
|
614
614
|
);
|
|
615
615
|
const tools = enabled.map((tool) => tool.serialize());
|
|
616
616
|
|
package/src/thread/utils.ts
CHANGED
|
@@ -58,7 +58,7 @@ export function tevent(event: {
|
|
|
58
58
|
* Check if an event is a tool call
|
|
59
59
|
*/
|
|
60
60
|
export function isActionIntention(event: LanguageModelItem): event is ToolCall {
|
|
61
|
-
return event.kind === "tool
|
|
61
|
+
return event.kind === "tool.call";
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
@@ -78,8 +78,8 @@ export function notDelta(event: ThreadStreamEvent): event is LanguageModelItem {
|
|
|
78
78
|
switch (event.kind) {
|
|
79
79
|
case "message":
|
|
80
80
|
case "reasoning":
|
|
81
|
-
case "tool
|
|
82
|
-
case "tool
|
|
81
|
+
case "tool.call":
|
|
82
|
+
case "tool.result":
|
|
83
83
|
return true;
|
|
84
84
|
|
|
85
85
|
// all other events are streaming deltas/control events
|
|
@@ -96,8 +96,8 @@ export function isPublicEvent(event: ThreadEvent): event is PublicThreadEvent {
|
|
|
96
96
|
switch (event.kind) {
|
|
97
97
|
case "message":
|
|
98
98
|
case "reasoning":
|
|
99
|
-
case "tool
|
|
100
|
-
case "tool
|
|
99
|
+
case "tool.call":
|
|
100
|
+
case "tool.result":
|
|
101
101
|
return true;
|
|
102
102
|
|
|
103
103
|
case "system":
|