kernl 0.11.4 → 0.12.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 +1 -1
- package/CHANGELOG.md +59 -0
- package/dist/agent/__tests__/run.test.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.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__/mock.d.ts +2 -3
- package/dist/thread/__tests__/mock.d.ts.map +1 -1
- package/dist/thread/__tests__/thread-persistence.test.js +6 -6
- package/dist/thread/__tests__/thread.test.js +22 -22
- package/dist/thread/thread.d.ts +4 -0
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/thread/thread.js +47 -79
- package/dist/thread/types.d.ts +18 -3
- package/dist/thread/types.d.ts.map +1 -1
- package/dist/thread/utils.d.ts +7 -7
- package/dist/thread/utils.d.ts.map +1 -1
- package/dist/thread/utils.js +6 -6
- package/package.json +5 -7
- package/src/agent/__tests__/run.test.ts +2 -2
- package/src/index.ts +1 -0
- 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__/mock.ts +2 -2
- package/src/thread/__tests__/thread-persistence.test.ts +6 -6
- package/src/thread/__tests__/thread.test.ts +22 -22
- package/src/thread/thread.ts +51 -82
- package/src/thread/types.ts +49 -3
- package/src/thread/utils.ts +19 -12
- package/dist/thread/__tests__/integration.test.d.ts +0 -2
- package/dist/thread/__tests__/integration.test.d.ts.map +0 -1
- package/dist/thread/__tests__/integration.test.js +0 -320
- package/src/thread/__tests__/integration.test.ts +0 -434
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,64 @@
|
|
|
1
1
|
# @kernl/core
|
|
2
2
|
|
|
3
|
+
## 0.12.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 58e9db2: Fix provider normalization and ThreadStreamEvent types
|
|
8
|
+
- Normalize AI SDK provider strings (`anthropic.messages` -> `anthropic`, etc.)
|
|
9
|
+
- Export `ThreadStreamEvent` from kernl for consumers
|
|
10
|
+
- Update `toUIMessageStream` to accept `ThreadStreamEvent` from `agent.stream()`
|
|
11
|
+
- Add `kernl` as dependency to `@kernl-sdk/ai` (breaking circular devDep)
|
|
12
|
+
|
|
13
|
+
- 320b76a: Add emit helper and sequence streamed events
|
|
14
|
+
- Thread now yields `ThreadEvent` with `seq` for complete items (messages, tool calls, tool results)
|
|
15
|
+
- Delta and control events remain ephemeral `StreamEvent` without seq
|
|
16
|
+
- Internal `emit()` helper reduces boilerplate in event emission
|
|
17
|
+
|
|
18
|
+
## 0.12.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- 8815744: **BREAKING:** Refactor event kind naming from kebab-case to dot notation
|
|
23
|
+
|
|
24
|
+
This aligns the language model stream/item kinds with the existing realtime events naming convention.
|
|
25
|
+
|
|
26
|
+
### Kind value changes
|
|
27
|
+
|
|
28
|
+
| Old | New |
|
|
29
|
+
| ------------------ | ------------------ |
|
|
30
|
+
| `tool-call` | `tool.call` |
|
|
31
|
+
| `tool-result` | `tool.result` |
|
|
32
|
+
| `text-start` | `text.start` |
|
|
33
|
+
| `text-delta` | `text.delta` |
|
|
34
|
+
| `text-end` | `text.end` |
|
|
35
|
+
| `reasoning-start` | `reasoning.start` |
|
|
36
|
+
| `reasoning-delta` | `reasoning.delta` |
|
|
37
|
+
| `reasoning-end` | `reasoning.end` |
|
|
38
|
+
| `tool-input-start` | `tool.input.start` |
|
|
39
|
+
| `tool-input-delta` | `tool.input.delta` |
|
|
40
|
+
| `tool-input-end` | `tool.input.end` |
|
|
41
|
+
| `stream-start` | `stream.start` |
|
|
42
|
+
|
|
43
|
+
### ToolInputStartEvent: `toolName` → `toolId`
|
|
44
|
+
|
|
45
|
+
The `ToolInputStartEvent` now uses `toolId` to match `ToolCall` and `ToolResult`.
|
|
46
|
+
|
|
47
|
+
### Migration
|
|
48
|
+
|
|
49
|
+
If you have persisted thread events, run:
|
|
50
|
+
|
|
51
|
+
```sql
|
|
52
|
+
UPDATE thread_events SET kind = 'tool.call' WHERE kind = 'tool-call';
|
|
53
|
+
UPDATE thread_events SET kind = 'tool.result' WHERE kind = 'tool-result';
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- Updated dependencies [8815744]
|
|
59
|
+
- @kernl-sdk/protocol@0.5.0
|
|
60
|
+
- @kernl-sdk/retrieval@0.1.9
|
|
61
|
+
|
|
3
62
|
## 0.11.4
|
|
4
63
|
|
|
5
64
|
### Patch Changes
|
|
@@ -218,7 +218,7 @@ describe("Agent.stream() lifecycle", () => {
|
|
|
218
218
|
for await (const event of agent.stream("Hello")) {
|
|
219
219
|
events.push(event);
|
|
220
220
|
}
|
|
221
|
-
expect(events[0]).toEqual({ kind: "stream
|
|
221
|
+
expect(events[0]).toEqual({ kind: "stream.start" });
|
|
222
222
|
});
|
|
223
223
|
it("should have same persistence behavior as run()", async () => {
|
|
224
224
|
const storage = new InMemoryStorage();
|
|
@@ -247,7 +247,7 @@ describe("Agent.stream() lifecycle", () => {
|
|
|
247
247
|
expect(history.length).toBeGreaterThan(0);
|
|
248
248
|
// Should have streamed events
|
|
249
249
|
expect(events).toEqual(expect.arrayContaining([
|
|
250
|
-
{ kind: "stream
|
|
250
|
+
{ kind: "stream.start" },
|
|
251
251
|
expect.objectContaining({ kind: "message" }),
|
|
252
252
|
]));
|
|
253
253
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { MCPServerSSE } from "./mcp/sse.js";
|
|
|
10
10
|
export { MCPServerStreamableHttp } from "./mcp/http.js";
|
|
11
11
|
export type { MThread as Thread, MThreadEvent as ThreadEvent, MThreadEventBase as ThreadEventBase, } from "./api/models/index.js";
|
|
12
12
|
export type { RThreadsListParams as ThreadsListParams, RThreadGetOptions as ThreadGetOptions, RThreadHistoryParams as ThreadHistoryParams, RThreadCreateParams as ThreadCreateParams, RThreadUpdateParams as ThreadUpdateParams, } from "./api/resources/threads/index.js";
|
|
13
|
-
export { THREAD_STATES, type ThreadState, type PublicThreadEvent, } from "./thread/types.js";
|
|
13
|
+
export { THREAD_STATES, type ThreadState, type PublicThreadEvent, type ThreadStreamEvent, } from "./thread/types.js";
|
|
14
14
|
export type { ThreadStore, NewThread, ThreadUpdate, ThreadFilter, ThreadHistoryOptions, ThreadInclude, ThreadListOptions, SortOrder, KernlStorage, Transaction, } from "./storage/index.js";
|
|
15
15
|
export { Memory, MemoryByteEncoder } from "./memory/index.js";
|
|
16
16
|
export type { MemoryStore, MemoryScope, NewMemory, MemoryConfig, MemoryReindexParams, MemoryRecord, MemoryKind, MemoryRecordUpdate, MemoryFilter, MemoryListOptions, MemorySearchQuery, WorkingMemorySnapshot, ShortTermMemorySnapshot, MemoryIndexBase, MemorySearchIndex, MemoryGraphIndex, MemoryArchiveIndex, GraphTraversalQuery, GraphTraversalResult, ArchiveQuery, ArchiveResult, MemoryByte, MemoryByteCodec, } from "./memory/index.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,YAAY,EACV,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,mBAA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,EACb,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,GACvB,MAAM,gBAAgB,CAAC;AAIxB,YAAY,EACV,WAAW,EACX,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,WAAW,GACZ,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AACrD,YAAY,EACV,WAAW,EACX,WAAW,EACX,SAAS,EACT,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,UAAU,EACV,eAAe,GAChB,MAAM,UAAU,CAAC"}
|
|
@@ -238,7 +238,7 @@ describe("Lifecycle Hooks", () => {
|
|
|
238
238
|
content: [
|
|
239
239
|
message({ role: "assistant", text: "" }),
|
|
240
240
|
{
|
|
241
|
-
kind: "tool
|
|
241
|
+
kind: "tool.call",
|
|
242
242
|
toolId: "echo",
|
|
243
243
|
state: IN_PROGRESS,
|
|
244
244
|
callId: "call_1",
|
|
@@ -302,7 +302,7 @@ describe("Lifecycle Hooks", () => {
|
|
|
302
302
|
content: [
|
|
303
303
|
message({ role: "assistant", text: "" }),
|
|
304
304
|
{
|
|
305
|
-
kind: "tool
|
|
305
|
+
kind: "tool.call",
|
|
306
306
|
toolId: "add",
|
|
307
307
|
state: IN_PROGRESS,
|
|
308
308
|
callId: "call_1",
|
|
@@ -359,7 +359,7 @@ describe("Lifecycle Hooks", () => {
|
|
|
359
359
|
content: [
|
|
360
360
|
message({ role: "assistant", text: "" }),
|
|
361
361
|
{
|
|
362
|
-
kind: "tool
|
|
362
|
+
kind: "tool.call",
|
|
363
363
|
toolId: "add",
|
|
364
364
|
state: IN_PROGRESS,
|
|
365
365
|
callId: "call_1",
|
|
@@ -415,7 +415,7 @@ describe("Lifecycle Hooks", () => {
|
|
|
415
415
|
content: [
|
|
416
416
|
message({ role: "assistant", text: "" }),
|
|
417
417
|
{
|
|
418
|
-
kind: "tool
|
|
418
|
+
kind: "tool.call",
|
|
419
419
|
toolId: "failing",
|
|
420
420
|
state: IN_PROGRESS,
|
|
421
421
|
callId: "call_1",
|
|
@@ -473,14 +473,14 @@ describe("Lifecycle Hooks", () => {
|
|
|
473
473
|
content: [
|
|
474
474
|
message({ role: "assistant", text: "" }),
|
|
475
475
|
{
|
|
476
|
-
kind: "tool
|
|
476
|
+
kind: "tool.call",
|
|
477
477
|
toolId: "tool1",
|
|
478
478
|
state: IN_PROGRESS,
|
|
479
479
|
callId: "call_1",
|
|
480
480
|
arguments: JSON.stringify({ value: "a" }),
|
|
481
481
|
},
|
|
482
482
|
{
|
|
483
|
-
kind: "tool
|
|
483
|
+
kind: "tool.call",
|
|
484
484
|
toolId: "tool2",
|
|
485
485
|
state: IN_PROGRESS,
|
|
486
486
|
callId: "call_2",
|
|
@@ -10,18 +10,18 @@ async function* streamFromResponse(response) {
|
|
|
10
10
|
if (contentItem.kind === "text") {
|
|
11
11
|
// Yield text-start
|
|
12
12
|
yield {
|
|
13
|
-
kind: "text
|
|
13
|
+
kind: "text.start",
|
|
14
14
|
id: item.id,
|
|
15
15
|
};
|
|
16
16
|
// Yield text-delta
|
|
17
17
|
yield {
|
|
18
|
-
kind: "text
|
|
18
|
+
kind: "text.delta",
|
|
19
19
|
id: item.id,
|
|
20
20
|
text: contentItem.text,
|
|
21
21
|
};
|
|
22
22
|
// Yield text-end
|
|
23
23
|
yield {
|
|
24
|
-
kind: "text
|
|
24
|
+
kind: "text.end",
|
|
25
25
|
id: item.id,
|
|
26
26
|
};
|
|
27
27
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { LanguageModel, LanguageModelRequest, LanguageModelResponse } from "@kernl-sdk/protocol";
|
|
2
|
-
import type { ThreadStreamEvent } from "../../thread/types.js";
|
|
1
|
+
import { LanguageModel, LanguageModelRequest, LanguageModelResponse, LanguageModelStreamEvent } from "@kernl-sdk/protocol";
|
|
3
2
|
/**
|
|
4
3
|
* A mock language model that echoes the user input back as an assistant message.
|
|
5
4
|
* Useful for testing the execution flow without calling a real LLM.
|
|
@@ -11,7 +10,7 @@ export declare class MockLanguageModel implements LanguageModel {
|
|
|
11
10
|
readonly provider = "mock";
|
|
12
11
|
readonly modelId = "mock-model";
|
|
13
12
|
generate(request: LanguageModelRequest): Promise<LanguageModelResponse>;
|
|
14
|
-
stream(request: LanguageModelRequest): AsyncIterable<
|
|
13
|
+
stream(request: LanguageModelRequest): AsyncIterable<LanguageModelStreamEvent>;
|
|
15
14
|
/**
|
|
16
15
|
* Extract text from the input (LanguageModelItem[])
|
|
17
16
|
*/
|
|
@@ -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,
|
|
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"}
|
|
@@ -67,7 +67,7 @@ describe("Thread Persistence", () => {
|
|
|
67
67
|
// return {
|
|
68
68
|
// content: [
|
|
69
69
|
// message({ role: "assistant", text: "" }),
|
|
70
|
-
// { kind: "tool
|
|
70
|
+
// { kind: "tool.call", toolId: "test", callId: "call_1", state: IN_PROGRESS, arguments: "{}" },
|
|
71
71
|
// ],
|
|
72
72
|
// finishReason: "stop",
|
|
73
73
|
// usage: { inputTokens: 2, outputTokens: 2, totalTokens: 4 },
|
|
@@ -127,7 +127,7 @@ describe("Thread Persistence", () => {
|
|
|
127
127
|
// return {
|
|
128
128
|
// content: [
|
|
129
129
|
// message({ role: "assistant", text: "" }),
|
|
130
|
-
// { kind: "tool
|
|
130
|
+
// { kind: "tool.call", toolId: "echo", callId: "call_1", state: IN_PROGRESS, arguments: '{"text":"test"}' },
|
|
131
131
|
// ],
|
|
132
132
|
// finishReason: "stop",
|
|
133
133
|
// usage: { inputTokens: 2, outputTokens: 2, totalTokens: 4 },
|
|
@@ -167,7 +167,7 @@ describe("Thread Persistence", () => {
|
|
|
167
167
|
//
|
|
168
168
|
// // Find the append call for tick 1 (should include model message, tool-call, and tool-result)
|
|
169
169
|
// const tick1Events = storage.calls.append.find(batch =>
|
|
170
|
-
// batch.some(e => e.kind === "tool
|
|
170
|
+
// batch.some(e => e.kind === "tool.result")
|
|
171
171
|
// );
|
|
172
172
|
//
|
|
173
173
|
// expect(tick1Events).toBeDefined();
|
|
@@ -177,8 +177,8 @@ describe("Thread Persistence", () => {
|
|
|
177
177
|
// expect(tick1Events).toEqual(
|
|
178
178
|
// expect.arrayContaining([
|
|
179
179
|
// expect.objectContaining({ kind: "message", role: "assistant" }),
|
|
180
|
-
// expect.objectContaining({ kind: "tool
|
|
181
|
-
// expect.objectContaining({ kind: "tool
|
|
180
|
+
// expect.objectContaining({ kind: "tool.call", toolId: "echo" }),
|
|
181
|
+
// expect.objectContaining({ kind: "tool.result", toolId: "echo", result: "Echo: test" }),
|
|
182
182
|
// ])
|
|
183
183
|
// );
|
|
184
184
|
});
|
|
@@ -220,7 +220,7 @@ describe("Thread Persistence", () => {
|
|
|
220
220
|
// expect(lastUpdate.patch.state).toBe(STOPPED);
|
|
221
221
|
//
|
|
222
222
|
// // Verify stream-start event
|
|
223
|
-
// expect(events[0]).toEqual({ kind: "stream
|
|
223
|
+
// expect(events[0]).toEqual({ kind: "stream.start" });
|
|
224
224
|
});
|
|
225
225
|
it.skip("should persist STOPPED state even on model error", async () => {
|
|
226
226
|
// TODO: Enable once InMemoryStorage is implemented
|
|
@@ -164,7 +164,7 @@ describe("Thread", () => {
|
|
|
164
164
|
content: [],
|
|
165
165
|
},
|
|
166
166
|
{
|
|
167
|
-
kind: "tool
|
|
167
|
+
kind: "tool.call",
|
|
168
168
|
toolId: "echo",
|
|
169
169
|
state: IN_PROGRESS,
|
|
170
170
|
callId: "call_1",
|
|
@@ -233,7 +233,7 @@ describe("Thread", () => {
|
|
|
233
233
|
}),
|
|
234
234
|
// Tool call (tick 1)
|
|
235
235
|
expect.objectContaining({
|
|
236
|
-
kind: "tool
|
|
236
|
+
kind: "tool.call",
|
|
237
237
|
toolId: "echo",
|
|
238
238
|
callId: "call_1",
|
|
239
239
|
state: IN_PROGRESS,
|
|
@@ -241,7 +241,7 @@ describe("Thread", () => {
|
|
|
241
241
|
}),
|
|
242
242
|
// Tool result (executed after tick 1)
|
|
243
243
|
expect.objectContaining({
|
|
244
|
-
kind: "tool
|
|
244
|
+
kind: "tool.result",
|
|
245
245
|
callId: "call_1",
|
|
246
246
|
toolId: "echo",
|
|
247
247
|
state: COMPLETED,
|
|
@@ -271,7 +271,7 @@ describe("Thread", () => {
|
|
|
271
271
|
content: [],
|
|
272
272
|
},
|
|
273
273
|
{
|
|
274
|
-
kind: "tool
|
|
274
|
+
kind: "tool.call",
|
|
275
275
|
toolId: "simple",
|
|
276
276
|
state: IN_PROGRESS,
|
|
277
277
|
callId: "call_1",
|
|
@@ -297,7 +297,7 @@ describe("Thread", () => {
|
|
|
297
297
|
content: [],
|
|
298
298
|
},
|
|
299
299
|
{
|
|
300
|
-
kind: "tool
|
|
300
|
+
kind: "tool.call",
|
|
301
301
|
toolId: "simple",
|
|
302
302
|
state: IN_PROGRESS,
|
|
303
303
|
callId: "call_2",
|
|
@@ -371,7 +371,7 @@ describe("Thread", () => {
|
|
|
371
371
|
content: [],
|
|
372
372
|
},
|
|
373
373
|
{
|
|
374
|
-
kind: "tool
|
|
374
|
+
kind: "tool.call",
|
|
375
375
|
toolId: "nonexistent",
|
|
376
376
|
state: IN_PROGRESS,
|
|
377
377
|
callId: "call_1",
|
|
@@ -418,9 +418,9 @@ describe("Thread", () => {
|
|
|
418
418
|
await thread.execute();
|
|
419
419
|
const history = thread.history;
|
|
420
420
|
// Check that the tool result is an error
|
|
421
|
-
const toolResult = history.find((e) => e.kind === "tool
|
|
421
|
+
const toolResult = history.find((e) => e.kind === "tool.result");
|
|
422
422
|
expect(toolResult).toEqual(expect.objectContaining({
|
|
423
|
-
kind: "tool
|
|
423
|
+
kind: "tool.result",
|
|
424
424
|
callId: "call_1",
|
|
425
425
|
toolId: "nonexistent",
|
|
426
426
|
state: FAILED,
|
|
@@ -443,7 +443,7 @@ describe("Thread", () => {
|
|
|
443
443
|
content: [],
|
|
444
444
|
},
|
|
445
445
|
{
|
|
446
|
-
kind: "tool
|
|
446
|
+
kind: "tool.call",
|
|
447
447
|
toolId: "failing",
|
|
448
448
|
state: IN_PROGRESS,
|
|
449
449
|
callId: "call_1",
|
|
@@ -499,9 +499,9 @@ describe("Thread", () => {
|
|
|
499
499
|
const thread = new Thread({ agent, input: userMessage("test") });
|
|
500
500
|
await thread.execute();
|
|
501
501
|
const history = thread.history;
|
|
502
|
-
const toolResult = history.find((e) => e.kind === "tool
|
|
502
|
+
const toolResult = history.find((e) => e.kind === "tool.result");
|
|
503
503
|
expect(toolResult).toMatchObject({
|
|
504
|
-
kind: "tool
|
|
504
|
+
kind: "tool.result",
|
|
505
505
|
callId: "call_1",
|
|
506
506
|
toolId: "failing",
|
|
507
507
|
state: FAILED,
|
|
@@ -524,7 +524,7 @@ describe("Thread", () => {
|
|
|
524
524
|
content: [],
|
|
525
525
|
},
|
|
526
526
|
{
|
|
527
|
-
kind: "tool
|
|
527
|
+
kind: "tool.call",
|
|
528
528
|
toolId: "add",
|
|
529
529
|
state: IN_PROGRESS,
|
|
530
530
|
callId: "call_1",
|
|
@@ -577,9 +577,9 @@ describe("Thread", () => {
|
|
|
577
577
|
await thread.execute();
|
|
578
578
|
// @ts-expect-error
|
|
579
579
|
const history = thread.history;
|
|
580
|
-
const toolResult = history.find((e) => e.kind === "tool
|
|
580
|
+
const toolResult = history.find((e) => e.kind === "tool.result");
|
|
581
581
|
expect(toolResult).toEqual(expect.objectContaining({
|
|
582
|
-
kind: "tool
|
|
582
|
+
kind: "tool.result",
|
|
583
583
|
callId: "call_1",
|
|
584
584
|
toolId: "add",
|
|
585
585
|
state: COMPLETED,
|
|
@@ -604,14 +604,14 @@ describe("Thread", () => {
|
|
|
604
604
|
content: [],
|
|
605
605
|
},
|
|
606
606
|
{
|
|
607
|
-
kind: "tool
|
|
607
|
+
kind: "tool.call",
|
|
608
608
|
toolId: "tool1",
|
|
609
609
|
state: IN_PROGRESS,
|
|
610
610
|
callId: "call_1",
|
|
611
611
|
arguments: JSON.stringify({ value: "a" }),
|
|
612
612
|
},
|
|
613
613
|
{
|
|
614
|
-
kind: "tool
|
|
614
|
+
kind: "tool.call",
|
|
615
615
|
toolId: "tool2",
|
|
616
616
|
state: IN_PROGRESS,
|
|
617
617
|
callId: "call_2",
|
|
@@ -672,11 +672,11 @@ describe("Thread", () => {
|
|
|
672
672
|
await thread.execute();
|
|
673
673
|
const history = thread.history;
|
|
674
674
|
// Should have both tool results in history
|
|
675
|
-
const toolResults = history.filter((e) => e.kind === "tool
|
|
675
|
+
const toolResults = history.filter((e) => e.kind === "tool.result");
|
|
676
676
|
expect(toolResults).toHaveLength(2);
|
|
677
677
|
expect(toolResults).toEqual(expect.arrayContaining([
|
|
678
678
|
expect.objectContaining({
|
|
679
|
-
kind: "tool
|
|
679
|
+
kind: "tool.result",
|
|
680
680
|
callId: "call_1",
|
|
681
681
|
toolId: "tool1",
|
|
682
682
|
state: COMPLETED,
|
|
@@ -684,7 +684,7 @@ describe("Thread", () => {
|
|
|
684
684
|
error: null,
|
|
685
685
|
}),
|
|
686
686
|
expect.objectContaining({
|
|
687
|
-
kind: "tool
|
|
687
|
+
kind: "tool.result",
|
|
688
688
|
callId: "call_2",
|
|
689
689
|
toolId: "tool2",
|
|
690
690
|
state: COMPLETED,
|
|
@@ -709,7 +709,7 @@ describe("Thread", () => {
|
|
|
709
709
|
content: [],
|
|
710
710
|
},
|
|
711
711
|
{
|
|
712
|
-
kind: "tool
|
|
712
|
+
kind: "tool.call",
|
|
713
713
|
toolId: "simple",
|
|
714
714
|
state: IN_PROGRESS,
|
|
715
715
|
callId: `call_${callCount}`,
|
|
@@ -777,7 +777,7 @@ describe("Thread", () => {
|
|
|
777
777
|
content: [],
|
|
778
778
|
},
|
|
779
779
|
{
|
|
780
|
-
kind: "tool
|
|
780
|
+
kind: "tool.call",
|
|
781
781
|
toolId: "simple",
|
|
782
782
|
state: IN_PROGRESS,
|
|
783
783
|
callId: "call_1",
|
|
@@ -880,7 +880,7 @@ describe("Thread", () => {
|
|
|
880
880
|
content: [{ kind: "text", text: "Let me use a tool" }],
|
|
881
881
|
},
|
|
882
882
|
{
|
|
883
|
-
kind: "tool
|
|
883
|
+
kind: "tool.call",
|
|
884
884
|
toolId: "simple",
|
|
885
885
|
state: IN_PROGRESS,
|
|
886
886
|
callId: "call_1",
|
package/dist/thread/thread.d.ts
CHANGED
|
@@ -113,6 +113,10 @@ export declare class Thread<TContext = unknown, TOutput extends AgentOutputType
|
|
|
113
113
|
* TODO: Emit thread.stop when cancelled (neither result nor error set)
|
|
114
114
|
*/
|
|
115
115
|
cancel(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Emit an agent event with common fields auto-filled.
|
|
118
|
+
*/
|
|
119
|
+
private emit;
|
|
116
120
|
/**
|
|
117
121
|
* Perform the actions returned by the model
|
|
118
122
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/thread/thread.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAKzD,OAAO,EAML,aAAa,
|
|
1
|
+
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/thread/thread.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAKzD,OAAO,EAML,aAAa,EAMd,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAEV,WAAW,EACX,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EAGpB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAWrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,MAAM,CACjB,QAAQ,GAAG,OAAO,EAClB,OAAO,SAAS,eAAe,GAAG,MAAM;IAExC,QAAQ,C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