kernl 0.2.1 → 0.6.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.
- package/.turbo/turbo-build.log +5 -4
- package/.turbo/turbo-check-types.log +4 -0
- package/CHANGELOG.md +147 -0
- package/LICENSE +1 -1
- package/dist/agent/__tests__/concurrency.test.d.ts +2 -0
- package/dist/agent/__tests__/concurrency.test.d.ts.map +1 -0
- package/dist/agent/__tests__/concurrency.test.js +152 -0
- package/dist/agent/__tests__/run.test.d.ts +2 -0
- package/dist/agent/__tests__/run.test.d.ts.map +1 -0
- package/dist/agent/__tests__/run.test.js +357 -0
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent.d.ts +35 -12
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +102 -15
- package/dist/api/__tests__/cursor-page.test.d.ts +2 -0
- package/dist/api/__tests__/cursor-page.test.d.ts.map +1 -0
- package/dist/api/__tests__/cursor-page.test.js +414 -0
- package/dist/api/__tests__/offset-page.test.d.ts +2 -0
- package/dist/api/__tests__/offset-page.test.d.ts.map +1 -0
- package/dist/api/__tests__/offset-page.test.js +510 -0
- package/dist/api/__tests__/threads.test.d.ts +2 -0
- package/dist/api/__tests__/threads.test.d.ts.map +1 -0
- package/dist/api/__tests__/threads.test.js +338 -0
- package/dist/api/models/index.d.ts +2 -0
- package/dist/api/models/index.d.ts.map +1 -0
- package/dist/api/models/thread.d.ts +120 -0
- package/dist/api/models/thread.d.ts.map +1 -0
- package/dist/api/pagination/base.d.ts +48 -0
- package/dist/api/pagination/base.d.ts.map +1 -0
- package/dist/api/pagination/base.js +45 -0
- package/dist/api/pagination/cursor.d.ts +44 -0
- package/dist/api/pagination/cursor.d.ts.map +1 -0
- package/dist/api/pagination/cursor.js +52 -0
- package/dist/api/pagination/offset.d.ts +42 -0
- package/dist/api/pagination/offset.d.ts.map +1 -0
- package/dist/api/pagination/offset.js +55 -0
- package/dist/api/resources/threads/events.d.ts +21 -0
- package/dist/api/resources/threads/events.d.ts.map +1 -0
- package/dist/api/resources/threads/events.js +24 -0
- package/dist/api/resources/threads/index.d.ts +4 -0
- package/dist/api/resources/threads/index.d.ts.map +1 -0
- package/dist/api/resources/threads/index.js +2 -0
- package/dist/api/resources/threads/threads.d.ts +57 -0
- package/dist/api/resources/threads/threads.d.ts.map +1 -0
- package/dist/api/resources/threads/threads.js +199 -0
- package/dist/api/resources/threads/types.d.ts +123 -0
- package/dist/api/resources/threads/types.d.ts.map +1 -0
- package/dist/api/resources/threads/utils.d.ts +18 -0
- package/dist/api/resources/threads/utils.d.ts.map +1 -0
- package/dist/api/resources/threads/utils.js +78 -0
- package/dist/context.d.ts +5 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +6 -1
- package/dist/guardrail.d.ts +4 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -3
- package/dist/internal.d.ts +4 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +2 -0
- package/dist/kernl/index.d.ts +3 -0
- package/dist/kernl/index.d.ts.map +1 -0
- package/dist/kernl/index.js +2 -0
- package/dist/kernl/kernl.d.ts +64 -0
- package/dist/kernl/kernl.d.ts.map +1 -0
- package/dist/kernl/kernl.js +116 -0
- package/dist/kernl/threads.d.ts +110 -0
- package/dist/kernl/threads.d.ts.map +1 -0
- package/dist/kernl/threads.js +126 -0
- package/dist/kernl.d.ts +27 -11
- package/dist/kernl.d.ts.map +1 -1
- package/dist/kernl.js +74 -11
- package/dist/lib/env.d.ts +3 -3
- package/dist/lib/env.js +1 -1
- package/dist/lib/error.d.ts +3 -3
- package/dist/lib/logger.js +1 -1
- package/dist/lifecycle.d.ts +5 -5
- package/dist/mcp/__tests__/base.test.js +2 -2
- package/dist/mcp/__tests__/fixtures/utils.d.ts +1 -1
- package/dist/mcp/__tests__/fixtures/utils.js +1 -1
- package/dist/mcp/__tests__/integration.test.js +16 -16
- package/dist/mcp/__tests__/stdio.test.js +2 -2
- package/dist/mcp/__tests__/utils.test.js +8 -8
- package/dist/mcp/base.d.ts +2 -2
- package/dist/mcp/http.d.ts +3 -3
- package/dist/mcp/http.d.ts.map +1 -1
- package/dist/mcp/http.js +11 -11
- package/dist/mcp/sse.d.ts +3 -3
- package/dist/mcp/sse.d.ts.map +1 -1
- package/dist/mcp/sse.js +9 -9
- package/dist/mcp/stdio.d.ts +2 -2
- package/dist/mcp/stdio.js +2 -2
- package/dist/mcp/types.d.ts +3 -3
- package/dist/mcp/utils.d.ts +4 -4
- package/dist/mcp/utils.d.ts.map +1 -1
- package/dist/mcp/utils.js +5 -6
- package/dist/storage/__tests__/in-memory.test.d.ts +2 -0
- package/dist/storage/__tests__/in-memory.test.d.ts.map +1 -0
- package/dist/storage/__tests__/in-memory.test.js +455 -0
- package/dist/storage/base.d.ts +64 -0
- package/dist/storage/base.d.ts.map +1 -0
- package/dist/storage/base.js +4 -0
- package/dist/storage/in-memory.d.ts +62 -0
- package/dist/storage/in-memory.d.ts.map +1 -0
- package/dist/storage/in-memory.js +283 -0
- package/dist/storage/index.d.ts +10 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +7 -0
- package/dist/storage/thread.d.ts +123 -0
- package/dist/storage/thread.d.ts.map +1 -0
- package/dist/storage/thread.js +4 -0
- package/dist/task.d.ts +8 -6
- package/dist/task.d.ts.map +1 -1
- package/dist/task.js +10 -8
- package/dist/thread/__tests__/fixtures/mock-model.d.ts +1 -2
- package/dist/thread/__tests__/fixtures/mock-model.d.ts.map +1 -1
- package/dist/thread/__tests__/integration.test.js +10 -10
- package/dist/thread/__tests__/mock.d.ts +1 -1
- package/dist/thread/__tests__/namespace.test.d.ts +2 -0
- package/dist/thread/__tests__/namespace.test.d.ts.map +1 -0
- package/dist/thread/__tests__/namespace.test.js +131 -0
- package/dist/thread/__tests__/thread-persistence.test.d.ts +2 -0
- package/dist/thread/__tests__/thread-persistence.test.d.ts.map +1 -0
- package/dist/thread/__tests__/thread-persistence.test.js +351 -0
- package/dist/thread/__tests__/thread.test.js +55 -57
- package/dist/thread/index.d.ts +1 -1
- package/dist/thread/index.js +1 -1
- package/dist/thread/thread.d.ts +74 -22
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/thread/thread.js +212 -74
- package/dist/thread/utils.d.ts +38 -10
- package/dist/thread/utils.d.ts.map +1 -1
- package/dist/thread/utils.js +53 -9
- package/dist/tool/__tests__/fixtures.d.ts +8 -8
- package/dist/tool/__tests__/fixtures.js +3 -3
- package/dist/tool/__tests__/tool.test.js +2 -2
- package/dist/tool/__tests__/toolkit.test.js +17 -14
- package/dist/tool/index.d.ts +3 -3
- package/dist/tool/index.js +2 -2
- package/dist/tool/tool.d.ts +2 -2
- package/dist/tool/tool.js +5 -5
- package/dist/tool/toolkit.d.ts +4 -4
- package/dist/tool/toolkit.js +1 -1
- package/dist/tool/types.d.ts +4 -4
- package/dist/trace/traces.js +2 -2
- package/dist/types/agent.d.ts +4 -4
- package/dist/types/kernl.d.ts +42 -0
- package/dist/types/kernl.d.ts.map +1 -0
- package/dist/types/thread.d.ts +110 -24
- package/dist/types/thread.d.ts.map +1 -1
- package/dist/types/thread.js +12 -0
- package/package.json +12 -8
- package/src/agent/__tests__/concurrency.test.ts +194 -0
- package/src/agent/__tests__/run.test.ts +441 -0
- package/src/agent/index.ts +0 -0
- package/src/agent.ts +139 -24
- package/src/api/__tests__/cursor-page.test.ts +512 -0
- package/src/api/__tests__/offset-page.test.ts +624 -0
- package/src/api/__tests__/threads.test.ts +415 -0
- package/src/api/models/index.ts +6 -0
- package/src/api/models/thread.ts +138 -0
- package/src/api/pagination/base.ts +79 -0
- package/src/api/pagination/cursor.ts +86 -0
- package/src/api/pagination/offset.ts +89 -0
- package/src/api/resources/threads/events.ts +26 -0
- package/src/api/resources/threads/index.ts +9 -0
- package/src/api/resources/threads/threads.ts +256 -0
- package/src/api/resources/threads/types.ts +143 -0
- package/src/api/resources/threads/utils.ts +104 -0
- package/src/context.ts +10 -1
- package/src/index.ts +49 -1
- package/src/internal.ts +15 -0
- package/src/kernl.ts +86 -17
- package/src/mcp/__tests__/integration.test.ts +8 -9
- package/src/mcp/__tests__/utils.test.ts +6 -6
- package/src/mcp/http.ts +9 -9
- package/src/mcp/sse.ts +7 -7
- package/src/mcp/utils.ts +6 -5
- package/src/storage/__tests__/in-memory.test.ts +534 -0
- package/src/storage/base.ts +77 -0
- package/src/storage/in-memory.ts +372 -0
- package/src/storage/index.ts +21 -0
- package/src/storage/thread.ts +141 -0
- package/src/task.ts +12 -10
- package/src/thread/__tests__/fixtures/mock-model.ts +2 -4
- package/src/thread/__tests__/integration.test.ts +13 -12
- package/src/thread/__tests__/namespace.test.ts +158 -0
- package/src/thread/__tests__/thread-persistence.test.ts +367 -0
- package/src/thread/__tests__/thread.test.ts +52 -54
- package/src/thread/thread.ts +247 -96
- package/src/thread/utils.ts +76 -13
- package/src/tool/__tests__/fixtures.ts +1 -1
- package/src/tool/__tests__/toolkit.test.ts +15 -12
- package/src/tool/tool.ts +3 -3
- package/src/types/kernl.ts +51 -0
- package/src/types/thread.ts +139 -25
- package/vitest.config.ts +1 -0
- package/dist/env.d.ts +0 -45
- package/dist/env.d.ts.map +0 -1
- package/dist/env.js +0 -31
- package/dist/error.d.ts +0 -1
- package/dist/error.d.ts.map +0 -1
- package/dist/kernel.d.ts +0 -7
- package/dist/kernel.d.ts.map +0 -1
- package/dist/kernel.js +0 -7
- package/dist/lib/serde/__tests__/codec.test.d.ts +0 -2
- package/dist/lib/serde/__tests__/codec.test.d.ts.map +0 -1
- package/dist/lib/serde/__tests__/codec.test.js +0 -75
- package/dist/lib/serde/codec.d.ts +0 -12
- package/dist/lib/serde/codec.d.ts.map +0 -1
- package/dist/lib/serde/codec.js +0 -54
- package/dist/lib/serde/thread.d.ts +0 -1
- package/dist/lib/serde/thread.d.ts.map +0 -1
- package/dist/lib/serde/thread.js +0 -172
- package/dist/lib/serde/tool.d.ts +0 -36
- package/dist/lib/serde/tool.d.ts.map +0 -1
- package/dist/lib/utils.d.ts +0 -19
- package/dist/lib/utils.d.ts.map +0 -1
- package/dist/lib/utils.js +0 -41
- package/dist/logger.d.ts +0 -36
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -43
- package/dist/mcp/__tests__/fixtures/echo-server.d.ts +0 -3
- package/dist/mcp/__tests__/fixtures/echo-server.d.ts.map +0 -1
- package/dist/mcp/__tests__/fixtures/echo-server.js +0 -92
- package/dist/mcp/__tests__/fixtures/math-server.d.ts +0 -3
- package/dist/mcp/__tests__/fixtures/math-server.d.ts.map +0 -1
- package/dist/mcp/__tests__/fixtures/math-server.js +0 -98
- package/dist/mcp/__tests__/fixtures/test-server.d.ts +0 -3
- package/dist/mcp/__tests__/fixtures/test-server.d.ts.map +0 -1
- package/dist/mcp/__tests__/fixtures/test-server.js +0 -163
- package/dist/mcp/__tests__/test-utils.d.ts +0 -17
- package/dist/mcp/__tests__/test-utils.d.ts.map +0 -1
- package/dist/mcp/__tests__/test-utils.js +0 -42
- package/dist/mcp/node.d.ts +0 -60
- package/dist/mcp/node.d.ts.map +0 -1
- package/dist/mcp/node.js +0 -297
- package/dist/model.d.ts +0 -175
- package/dist/model.d.ts.map +0 -1
- package/dist/providers/ai.d.ts +0 -1
- package/dist/providers/ai.d.ts.map +0 -1
- package/dist/providers/ai.js +0 -1
- package/dist/providers/default.d.ts +0 -16
- package/dist/providers/default.d.ts.map +0 -1
- package/dist/providers/default.js +0 -17
- package/dist/providers/registry.d.ts +0 -1
- package/dist/providers/registry.d.ts.map +0 -1
- package/dist/providers/registry.js +0 -1
- package/dist/sched/scheduler.d.ts +0 -20
- package/dist/sched/scheduler.d.ts.map +0 -1
- package/dist/sched/task.d.ts +0 -92
- package/dist/sched/task.d.ts.map +0 -1
- package/dist/sched/task.js +0 -102
- package/dist/serde/__tests__/codec.test.d.ts +0 -2
- package/dist/serde/__tests__/codec.test.d.ts.map +0 -1
- package/dist/serde/__tests__/codec.test.js +0 -75
- package/dist/serde/codec.d.ts +0 -12
- package/dist/serde/codec.d.ts.map +0 -1
- package/dist/serde/codec.js +0 -54
- package/dist/serde/json.d.ts +0 -8
- package/dist/serde/json.d.ts.map +0 -1
- package/dist/serde/json.js +0 -13
- package/dist/serde/thread.d.ts +0 -687
- package/dist/serde/thread.d.ts.map +0 -1
- package/dist/serde/thread.js +0 -158
- package/dist/serde/tool.d.ts +0 -36
- package/dist/serde/tool.d.ts.map +0 -1
- package/dist/session.d.ts +0 -1
- package/dist/session.d.ts.map +0 -1
- package/dist/session.js +0 -1
- package/dist/thread/__tests__/stream.test.d.ts +0 -2
- package/dist/thread/__tests__/stream.test.d.ts.map +0 -1
- package/dist/thread/__tests__/stream.test.js +0 -244
- package/dist/tool/mcp.d.ts +0 -75
- package/dist/tool/mcp.d.ts.map +0 -1
- package/dist/tool/mcp.js +0 -111
- package/dist/tools.d.ts +0 -362
- package/dist/tools.d.ts.map +0 -1
- package/dist/tools.js +0 -220
- package/dist/types/proto.d.ts +0 -1551
- package/dist/types/proto.d.ts.map +0 -1
- package/dist/types/proto.js +0 -531
- package/dist/usage.d.ts +0 -43
- package/dist/usage.d.ts.map +0 -1
- package/dist/usage.js +0 -61
- package/src/lib/serde/thread.ts +0 -188
- /package/dist/{error.js → agent/index.js} +0 -0
- /package/dist/{lib/serde/tool.js → api/models/index.js} +0 -0
- /package/dist/{model.js → api/models/thread.js} +0 -0
- /package/dist/{sched/scheduler.js → api/resources/threads/types.js} +0 -0
- /package/dist/{serde/tool.js → types/kernl.js} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
|
-
import type { LanguageModelRequest } from "@kernl-sdk/protocol";
|
|
4
|
+
import type { LanguageModelRequest, LanguageModelItem } from "@kernl-sdk/protocol";
|
|
5
5
|
import { IN_PROGRESS, COMPLETED, FAILED } from "@kernl-sdk/protocol";
|
|
6
6
|
|
|
7
7
|
import { Thread } from "../thread";
|
|
@@ -15,7 +15,7 @@ import type { ThreadEvent } from "@/types/thread";
|
|
|
15
15
|
import { createMockModel } from "./fixtures/mock-model";
|
|
16
16
|
|
|
17
17
|
// Helper to create user message input
|
|
18
|
-
function userMessage(text: string):
|
|
18
|
+
function userMessage(text: string): LanguageModelItem[] {
|
|
19
19
|
return [
|
|
20
20
|
{
|
|
21
21
|
kind: "message" as const,
|
|
@@ -57,7 +57,7 @@ describe("Thread", () => {
|
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
const kernl = new Kernl();
|
|
60
|
-
const thread = new Thread(
|
|
60
|
+
const thread = new Thread({ agent, input: userMessage("Hello world") });
|
|
61
61
|
|
|
62
62
|
const result = await thread.execute();
|
|
63
63
|
|
|
@@ -65,18 +65,16 @@ describe("Thread", () => {
|
|
|
65
65
|
const history = (thread as any).history as ThreadEvent[];
|
|
66
66
|
|
|
67
67
|
expect(history).toEqual([
|
|
68
|
-
{
|
|
68
|
+
expect.objectContaining({
|
|
69
69
|
kind: "message",
|
|
70
|
-
id: expect.any(String),
|
|
71
70
|
role: "user",
|
|
72
71
|
content: [{ kind: "text", text: "Hello world" }],
|
|
73
|
-
},
|
|
74
|
-
{
|
|
72
|
+
}),
|
|
73
|
+
expect.objectContaining({
|
|
75
74
|
kind: "message",
|
|
76
|
-
id: "msg_1",
|
|
77
75
|
role: "assistant",
|
|
78
76
|
content: [{ kind: "text", text: "Hello world" }],
|
|
79
|
-
},
|
|
77
|
+
}),
|
|
80
78
|
]);
|
|
81
79
|
|
|
82
80
|
expect(thread._tick).toBe(1);
|
|
@@ -111,19 +109,18 @@ describe("Thread", () => {
|
|
|
111
109
|
});
|
|
112
110
|
|
|
113
111
|
const kernl = new Kernl();
|
|
114
|
-
const thread = new Thread(
|
|
112
|
+
const thread = new Thread({ agent, input: userMessage("Test input") });
|
|
115
113
|
|
|
116
114
|
await thread.execute();
|
|
117
115
|
|
|
118
116
|
const history = (thread as any).history as ThreadEvent[];
|
|
119
117
|
const firstMessage = history[0];
|
|
120
118
|
|
|
121
|
-
expect(firstMessage).toEqual({
|
|
119
|
+
expect(firstMessage).toEqual(expect.objectContaining({
|
|
122
120
|
kind: "message",
|
|
123
|
-
id: expect.any(String),
|
|
124
121
|
role: "user",
|
|
125
122
|
content: [{ kind: "text", text: "Test input" }],
|
|
126
|
-
});
|
|
123
|
+
}));
|
|
127
124
|
});
|
|
128
125
|
|
|
129
126
|
it("should use array input as-is", async () => {
|
|
@@ -154,7 +151,7 @@ describe("Thread", () => {
|
|
|
154
151
|
model,
|
|
155
152
|
});
|
|
156
153
|
|
|
157
|
-
const events:
|
|
154
|
+
const events: LanguageModelItem[] = [
|
|
158
155
|
{
|
|
159
156
|
kind: "message",
|
|
160
157
|
id: "custom_msg",
|
|
@@ -164,14 +161,18 @@ describe("Thread", () => {
|
|
|
164
161
|
];
|
|
165
162
|
|
|
166
163
|
const kernl = new Kernl();
|
|
167
|
-
const thread = new Thread(
|
|
164
|
+
const thread = new Thread({ agent, input: events });
|
|
168
165
|
|
|
169
166
|
await thread.execute();
|
|
170
167
|
|
|
171
168
|
const history = (thread as any).history as ThreadEvent[];
|
|
172
169
|
const firstMessage = history[0];
|
|
173
170
|
|
|
174
|
-
expect(firstMessage).toEqual(
|
|
171
|
+
expect(firstMessage).toEqual(expect.objectContaining({
|
|
172
|
+
kind: events[0].kind,
|
|
173
|
+
role: (events[0] as any).role,
|
|
174
|
+
content: (events[0] as any).content,
|
|
175
|
+
}));
|
|
175
176
|
});
|
|
176
177
|
});
|
|
177
178
|
|
|
@@ -248,7 +249,7 @@ describe("Thread", () => {
|
|
|
248
249
|
});
|
|
249
250
|
|
|
250
251
|
const kernl = new Kernl();
|
|
251
|
-
const thread = new Thread(
|
|
252
|
+
const thread = new Thread({ agent, input: userMessage("Use the echo tool") });
|
|
252
253
|
|
|
253
254
|
const result = await thread.execute();
|
|
254
255
|
|
|
@@ -256,43 +257,40 @@ describe("Thread", () => {
|
|
|
256
257
|
|
|
257
258
|
expect(history).toEqual([
|
|
258
259
|
// Initial user message
|
|
259
|
-
{
|
|
260
|
+
expect.objectContaining({
|
|
260
261
|
kind: "message",
|
|
261
|
-
id: expect.any(String),
|
|
262
262
|
role: "user",
|
|
263
263
|
content: [{ kind: "text", text: "Use the echo tool" }],
|
|
264
|
-
},
|
|
264
|
+
}),
|
|
265
265
|
// Assistant message (tick 1)
|
|
266
|
-
{
|
|
266
|
+
expect.objectContaining({
|
|
267
267
|
kind: "message",
|
|
268
|
-
id: "msg_1",
|
|
269
268
|
role: "assistant",
|
|
270
269
|
content: [],
|
|
271
|
-
},
|
|
270
|
+
}),
|
|
272
271
|
// Tool call (tick 1)
|
|
273
|
-
{
|
|
272
|
+
expect.objectContaining({
|
|
274
273
|
kind: "tool-call",
|
|
275
274
|
toolId: "echo",
|
|
276
275
|
callId: "call_1",
|
|
277
276
|
state: IN_PROGRESS,
|
|
278
277
|
arguments: JSON.stringify({ text: "test" }),
|
|
279
|
-
},
|
|
278
|
+
}),
|
|
280
279
|
// Tool result (executed after tick 1)
|
|
281
|
-
{
|
|
280
|
+
expect.objectContaining({
|
|
282
281
|
kind: "tool-result",
|
|
283
282
|
callId: "call_1",
|
|
284
283
|
toolId: "echo",
|
|
285
284
|
state: COMPLETED,
|
|
286
285
|
result: "Echo: test",
|
|
287
286
|
error: null,
|
|
288
|
-
},
|
|
287
|
+
}),
|
|
289
288
|
// Final assistant message (tick 2)
|
|
290
|
-
{
|
|
289
|
+
expect.objectContaining({
|
|
291
290
|
kind: "message",
|
|
292
|
-
id: "msg_2",
|
|
293
291
|
role: "assistant",
|
|
294
292
|
content: [{ kind: "text", text: "Done!" }],
|
|
295
|
-
},
|
|
293
|
+
}),
|
|
296
294
|
]);
|
|
297
295
|
|
|
298
296
|
expect(thread._tick).toBe(2);
|
|
@@ -395,7 +393,7 @@ describe("Thread", () => {
|
|
|
395
393
|
});
|
|
396
394
|
|
|
397
395
|
const kernl = new Kernl();
|
|
398
|
-
const thread = new Thread(
|
|
396
|
+
const thread = new Thread({ agent, input: userMessage("Start") });
|
|
399
397
|
|
|
400
398
|
const result = await thread.execute();
|
|
401
399
|
|
|
@@ -471,7 +469,7 @@ describe("Thread", () => {
|
|
|
471
469
|
});
|
|
472
470
|
|
|
473
471
|
const kernl = new Kernl();
|
|
474
|
-
const thread = new Thread(
|
|
472
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
475
473
|
|
|
476
474
|
await thread.execute();
|
|
477
475
|
|
|
@@ -479,14 +477,14 @@ describe("Thread", () => {
|
|
|
479
477
|
|
|
480
478
|
// Check that the tool result is an error
|
|
481
479
|
const toolResult = history.find((e) => e.kind === "tool-result");
|
|
482
|
-
expect(toolResult).toEqual({
|
|
480
|
+
expect(toolResult).toEqual(expect.objectContaining({
|
|
483
481
|
kind: "tool-result",
|
|
484
482
|
callId: "call_1",
|
|
485
483
|
toolId: "nonexistent",
|
|
486
484
|
state: FAILED,
|
|
487
485
|
result: undefined,
|
|
488
486
|
error: "Tool nonexistent not found",
|
|
489
|
-
});
|
|
487
|
+
}));
|
|
490
488
|
});
|
|
491
489
|
|
|
492
490
|
it("should handle tool execution error", async () => {
|
|
@@ -563,7 +561,7 @@ describe("Thread", () => {
|
|
|
563
561
|
});
|
|
564
562
|
|
|
565
563
|
const kernl = new Kernl();
|
|
566
|
-
const thread = new Thread(
|
|
564
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
567
565
|
|
|
568
566
|
await thread.execute();
|
|
569
567
|
|
|
@@ -650,7 +648,7 @@ describe("Thread", () => {
|
|
|
650
648
|
});
|
|
651
649
|
|
|
652
650
|
const kernl = new Kernl();
|
|
653
|
-
const thread = new Thread(
|
|
651
|
+
const thread = new Thread({ agent, input: userMessage("Add 5 and 3") });
|
|
654
652
|
|
|
655
653
|
await thread.execute();
|
|
656
654
|
|
|
@@ -658,14 +656,14 @@ describe("Thread", () => {
|
|
|
658
656
|
const history = thread.history as ThreadEvent[];
|
|
659
657
|
|
|
660
658
|
const toolResult = history.find((e) => e.kind === "tool-result");
|
|
661
|
-
expect(toolResult).toEqual({
|
|
659
|
+
expect(toolResult).toEqual(expect.objectContaining({
|
|
662
660
|
kind: "tool-result",
|
|
663
661
|
callId: "call_1",
|
|
664
662
|
toolId: "add",
|
|
665
663
|
state: COMPLETED,
|
|
666
664
|
result: 8,
|
|
667
665
|
error: null,
|
|
668
|
-
});
|
|
666
|
+
}));
|
|
669
667
|
});
|
|
670
668
|
});
|
|
671
669
|
|
|
@@ -756,7 +754,7 @@ describe("Thread", () => {
|
|
|
756
754
|
});
|
|
757
755
|
|
|
758
756
|
const kernl = new Kernl();
|
|
759
|
-
const thread = new Thread(
|
|
757
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
760
758
|
|
|
761
759
|
await thread.execute();
|
|
762
760
|
|
|
@@ -767,22 +765,22 @@ describe("Thread", () => {
|
|
|
767
765
|
expect(toolResults).toHaveLength(2);
|
|
768
766
|
expect(toolResults).toEqual(
|
|
769
767
|
expect.arrayContaining([
|
|
770
|
-
{
|
|
768
|
+
expect.objectContaining({
|
|
771
769
|
kind: "tool-result",
|
|
772
770
|
callId: "call_1",
|
|
773
771
|
toolId: "tool1",
|
|
774
772
|
state: COMPLETED,
|
|
775
773
|
result: "Tool1: a",
|
|
776
774
|
error: null,
|
|
777
|
-
},
|
|
778
|
-
{
|
|
775
|
+
}),
|
|
776
|
+
expect.objectContaining({
|
|
779
777
|
kind: "tool-result",
|
|
780
778
|
callId: "call_2",
|
|
781
779
|
toolId: "tool2",
|
|
782
780
|
state: COMPLETED,
|
|
783
781
|
result: "Tool2: b",
|
|
784
782
|
error: null,
|
|
785
|
-
},
|
|
783
|
+
}),
|
|
786
784
|
]),
|
|
787
785
|
);
|
|
788
786
|
});
|
|
@@ -859,7 +857,7 @@ describe("Thread", () => {
|
|
|
859
857
|
});
|
|
860
858
|
|
|
861
859
|
const kernl = new Kernl();
|
|
862
|
-
const thread = new Thread(
|
|
860
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
863
861
|
|
|
864
862
|
const result = await thread.execute();
|
|
865
863
|
|
|
@@ -936,7 +934,7 @@ describe("Thread", () => {
|
|
|
936
934
|
});
|
|
937
935
|
|
|
938
936
|
const kernl = new Kernl();
|
|
939
|
-
const thread = new Thread(
|
|
937
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
940
938
|
|
|
941
939
|
const result = await thread.execute();
|
|
942
940
|
|
|
@@ -976,7 +974,7 @@ describe("Thread", () => {
|
|
|
976
974
|
});
|
|
977
975
|
|
|
978
976
|
const kernl = new Kernl();
|
|
979
|
-
const thread = new Thread(
|
|
977
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
980
978
|
|
|
981
979
|
const result = await thread.execute();
|
|
982
980
|
|
|
@@ -1053,7 +1051,7 @@ describe("Thread", () => {
|
|
|
1053
1051
|
});
|
|
1054
1052
|
|
|
1055
1053
|
const kernl = new Kernl();
|
|
1056
|
-
const thread = new Thread(
|
|
1054
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
1057
1055
|
|
|
1058
1056
|
const result = await thread.execute();
|
|
1059
1057
|
|
|
@@ -1093,7 +1091,7 @@ describe("Thread", () => {
|
|
|
1093
1091
|
});
|
|
1094
1092
|
|
|
1095
1093
|
const kernl = new Kernl();
|
|
1096
|
-
const thread = new Thread(
|
|
1094
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
1097
1095
|
|
|
1098
1096
|
const result = await thread.execute();
|
|
1099
1097
|
|
|
@@ -1142,7 +1140,7 @@ describe("Thread", () => {
|
|
|
1142
1140
|
});
|
|
1143
1141
|
|
|
1144
1142
|
const kernl = new Kernl();
|
|
1145
|
-
const thread = new Thread(
|
|
1143
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
1146
1144
|
|
|
1147
1145
|
const result = await thread.execute();
|
|
1148
1146
|
|
|
@@ -1192,7 +1190,7 @@ describe("Thread", () => {
|
|
|
1192
1190
|
});
|
|
1193
1191
|
|
|
1194
1192
|
const kernl = new Kernl();
|
|
1195
|
-
const thread = new Thread(
|
|
1193
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
1196
1194
|
|
|
1197
1195
|
await expect(thread.execute()).rejects.toThrow(ModelBehaviorError);
|
|
1198
1196
|
});
|
|
@@ -1237,7 +1235,7 @@ describe("Thread", () => {
|
|
|
1237
1235
|
});
|
|
1238
1236
|
|
|
1239
1237
|
const kernl = new Kernl();
|
|
1240
|
-
const thread = new Thread(
|
|
1238
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
1241
1239
|
|
|
1242
1240
|
await expect(thread.execute()).rejects.toThrow(ModelBehaviorError);
|
|
1243
1241
|
});
|
|
@@ -1283,7 +1281,7 @@ describe("Thread", () => {
|
|
|
1283
1281
|
});
|
|
1284
1282
|
|
|
1285
1283
|
const kernl = new Kernl();
|
|
1286
|
-
const thread = new Thread(
|
|
1284
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
1287
1285
|
|
|
1288
1286
|
await expect(thread.execute()).rejects.toThrow(ModelBehaviorError);
|
|
1289
1287
|
});
|
|
@@ -1342,7 +1340,7 @@ describe("Thread", () => {
|
|
|
1342
1340
|
});
|
|
1343
1341
|
|
|
1344
1342
|
const kernl = new Kernl();
|
|
1345
|
-
const thread = new Thread(
|
|
1343
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
1346
1344
|
|
|
1347
1345
|
const result = await thread.execute();
|
|
1348
1346
|
|
|
@@ -1411,7 +1409,7 @@ describe("Thread", () => {
|
|
|
1411
1409
|
});
|
|
1412
1410
|
|
|
1413
1411
|
const kernl = new Kernl();
|
|
1414
|
-
const thread = new Thread(
|
|
1412
|
+
const thread = new Thread({ agent, input: userMessage("test") });
|
|
1415
1413
|
|
|
1416
1414
|
const result = await thread.execute();
|
|
1417
1415
|
|