@kernl-sdk/ai 0.3.4 → 0.4.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 +53 -0
- package/dist/__tests__/integration.test.js +16 -16
- package/dist/__tests__/language-model.test.js +10 -10
- package/dist/convert/__tests__/message.test.js +7 -7
- package/dist/convert/__tests__/settings.test.js +1 -1
- package/dist/convert/__tests__/stream.test.js +19 -19
- package/dist/convert/__tests__/tools.test.js +1 -1
- package/dist/convert/__tests__/ui-message.test.js +44 -44
- package/dist/convert/__tests__/ui-stream.test.js +42 -42
- package/dist/convert/message.js +2 -2
- package/dist/convert/response.js +2 -2
- package/dist/convert/stream.js +13 -13
- package/dist/convert/ui-message.js +5 -5
- package/dist/convert/ui-stream.js +13 -13
- package/dist/language-model.js +7 -7
- package/package.json +4 -4
- package/src/__tests__/integration.test.ts +16 -16
- package/src/__tests__/language-model.test.ts +10 -10
- package/src/convert/__tests__/message.test.ts +7 -7
- package/src/convert/__tests__/settings.test.ts +1 -1
- package/src/convert/__tests__/stream.test.ts +19 -19
- package/src/convert/__tests__/tools.test.ts +1 -1
- package/src/convert/__tests__/ui-message.test.ts +44 -44
- package/src/convert/__tests__/ui-stream.test.ts +42 -42
- package/src/convert/message.ts +2 -2
- package/src/convert/response.ts +2 -2
- package/src/convert/stream.ts +13 -13
- package/src/convert/ui-message.ts +7 -7
- package/src/convert/ui-stream.ts +13 -13
- package/src/language-model.ts +7 -7
package/dist/convert/stream.js
CHANGED
|
@@ -31,66 +31,66 @@ export const STREAM_PART = {
|
|
|
31
31
|
switch (part.type) {
|
|
32
32
|
case "text-start":
|
|
33
33
|
return {
|
|
34
|
-
kind: "text
|
|
34
|
+
kind: "text.start",
|
|
35
35
|
id: part.id,
|
|
36
36
|
providerMetadata: part.providerMetadata,
|
|
37
37
|
};
|
|
38
38
|
case "text-delta":
|
|
39
39
|
return {
|
|
40
|
-
kind: "text
|
|
40
|
+
kind: "text.delta",
|
|
41
41
|
id: part.id,
|
|
42
42
|
text: part.delta,
|
|
43
43
|
providerMetadata: part.providerMetadata,
|
|
44
44
|
};
|
|
45
45
|
case "text-end":
|
|
46
46
|
return {
|
|
47
|
-
kind: "text
|
|
47
|
+
kind: "text.end",
|
|
48
48
|
id: part.id,
|
|
49
49
|
providerMetadata: part.providerMetadata,
|
|
50
50
|
};
|
|
51
51
|
case "reasoning-start":
|
|
52
52
|
return {
|
|
53
|
-
kind: "reasoning
|
|
53
|
+
kind: "reasoning.start",
|
|
54
54
|
id: part.id,
|
|
55
55
|
providerMetadata: part.providerMetadata,
|
|
56
56
|
};
|
|
57
57
|
case "reasoning-delta":
|
|
58
58
|
return {
|
|
59
|
-
kind: "reasoning
|
|
59
|
+
kind: "reasoning.delta",
|
|
60
60
|
id: part.id,
|
|
61
61
|
text: part.delta,
|
|
62
62
|
providerMetadata: part.providerMetadata,
|
|
63
63
|
};
|
|
64
64
|
case "reasoning-end":
|
|
65
65
|
return {
|
|
66
|
-
kind: "reasoning
|
|
66
|
+
kind: "reasoning.end",
|
|
67
67
|
id: part.id,
|
|
68
68
|
providerMetadata: part.providerMetadata,
|
|
69
69
|
};
|
|
70
70
|
case "tool-input-start":
|
|
71
71
|
return {
|
|
72
|
-
kind: "tool
|
|
72
|
+
kind: "tool.input.start",
|
|
73
73
|
id: part.id,
|
|
74
|
-
|
|
74
|
+
toolId: part.toolName,
|
|
75
75
|
title: part.title,
|
|
76
76
|
providerMetadata: part.providerMetadata,
|
|
77
77
|
};
|
|
78
78
|
case "tool-input-delta":
|
|
79
79
|
return {
|
|
80
|
-
kind: "tool
|
|
80
|
+
kind: "tool.input.delta",
|
|
81
81
|
id: part.id,
|
|
82
82
|
delta: part.delta,
|
|
83
83
|
providerMetadata: part.providerMetadata,
|
|
84
84
|
};
|
|
85
85
|
case "tool-input-end":
|
|
86
86
|
return {
|
|
87
|
-
kind: "tool
|
|
87
|
+
kind: "tool.input.end",
|
|
88
88
|
id: part.id,
|
|
89
89
|
providerMetadata: part.providerMetadata,
|
|
90
90
|
};
|
|
91
91
|
case "tool-call":
|
|
92
92
|
return {
|
|
93
|
-
kind: "tool
|
|
93
|
+
kind: "tool.call",
|
|
94
94
|
callId: part.toolCallId,
|
|
95
95
|
toolId: part.toolName,
|
|
96
96
|
state: IN_PROGRESS,
|
|
@@ -100,7 +100,7 @@ export const STREAM_PART = {
|
|
|
100
100
|
case "tool-result":
|
|
101
101
|
// provider-defined tools can stream tool results
|
|
102
102
|
return {
|
|
103
|
-
kind: "tool
|
|
103
|
+
kind: "tool.result",
|
|
104
104
|
callId: part.toolCallId,
|
|
105
105
|
toolId: part.toolName,
|
|
106
106
|
state: part.isError ? FAILED : COMPLETED,
|
|
@@ -110,7 +110,7 @@ export const STREAM_PART = {
|
|
|
110
110
|
};
|
|
111
111
|
case "stream-start":
|
|
112
112
|
return {
|
|
113
|
-
kind: "stream
|
|
113
|
+
kind: "stream.start",
|
|
114
114
|
warnings: part.warnings.map(WARNING.decode),
|
|
115
115
|
};
|
|
116
116
|
case "finish":
|
|
@@ -123,7 +123,7 @@ const TOOL_UI_PART = {
|
|
|
123
123
|
switch (part.state) {
|
|
124
124
|
case "input-available": {
|
|
125
125
|
const call = {
|
|
126
|
-
kind: "tool
|
|
126
|
+
kind: "tool.call",
|
|
127
127
|
callId,
|
|
128
128
|
toolId,
|
|
129
129
|
state: IN_PROGRESS,
|
|
@@ -134,7 +134,7 @@ const TOOL_UI_PART = {
|
|
|
134
134
|
}
|
|
135
135
|
case "output-available": {
|
|
136
136
|
const result = {
|
|
137
|
-
kind: "tool
|
|
137
|
+
kind: "tool.result",
|
|
138
138
|
callId,
|
|
139
139
|
toolId,
|
|
140
140
|
state: COMPLETED,
|
|
@@ -146,7 +146,7 @@ const TOOL_UI_PART = {
|
|
|
146
146
|
}
|
|
147
147
|
case "output-error": {
|
|
148
148
|
const result = {
|
|
149
|
-
kind: "tool
|
|
149
|
+
kind: "tool.result",
|
|
150
150
|
callId,
|
|
151
151
|
toolId,
|
|
152
152
|
state: FAILED,
|
|
@@ -220,11 +220,11 @@ export function historyToUIMessages(items) {
|
|
|
220
220
|
const reasoningParts = [];
|
|
221
221
|
while (j < items.length && items[j].kind !== "message") {
|
|
222
222
|
const next = items[j];
|
|
223
|
-
if (next.kind === "tool
|
|
223
|
+
if (next.kind === "tool.call") {
|
|
224
224
|
const existing = toolMap.get(next.callId) || {};
|
|
225
225
|
toolMap.set(next.callId, { ...existing, call: next });
|
|
226
226
|
}
|
|
227
|
-
else if (next.kind === "tool
|
|
227
|
+
else if (next.kind === "tool.result") {
|
|
228
228
|
const existing = toolMap.get(next.callId) || {};
|
|
229
229
|
toolMap.set(next.callId, { ...existing, result: next });
|
|
230
230
|
}
|
|
@@ -38,59 +38,59 @@ export function toUIMessageStream(stream) {
|
|
|
38
38
|
export const STREAM_UI_PART = {
|
|
39
39
|
encode: (event) => {
|
|
40
40
|
switch (event.kind) {
|
|
41
|
-
case "text
|
|
41
|
+
case "text.start":
|
|
42
42
|
return {
|
|
43
43
|
type: "text-start",
|
|
44
44
|
id: event.id,
|
|
45
45
|
};
|
|
46
|
-
case "text
|
|
46
|
+
case "text.delta":
|
|
47
47
|
return {
|
|
48
48
|
type: "text-delta",
|
|
49
49
|
id: event.id,
|
|
50
50
|
delta: event.text,
|
|
51
51
|
};
|
|
52
|
-
case "text
|
|
52
|
+
case "text.end":
|
|
53
53
|
return {
|
|
54
54
|
type: "text-end",
|
|
55
55
|
id: event.id,
|
|
56
56
|
};
|
|
57
|
-
case "reasoning
|
|
57
|
+
case "reasoning.start":
|
|
58
58
|
return {
|
|
59
59
|
type: "reasoning-start",
|
|
60
60
|
id: event.id,
|
|
61
61
|
};
|
|
62
|
-
case "reasoning
|
|
62
|
+
case "reasoning.delta":
|
|
63
63
|
return {
|
|
64
64
|
type: "reasoning-delta",
|
|
65
65
|
id: event.id,
|
|
66
66
|
delta: event.text,
|
|
67
67
|
};
|
|
68
|
-
case "reasoning
|
|
68
|
+
case "reasoning.end":
|
|
69
69
|
return {
|
|
70
70
|
type: "reasoning-end",
|
|
71
71
|
id: event.id,
|
|
72
72
|
};
|
|
73
|
-
case "tool
|
|
73
|
+
case "tool.input.start":
|
|
74
74
|
return {
|
|
75
75
|
type: "tool-input-start",
|
|
76
76
|
toolCallId: event.id,
|
|
77
|
-
toolName: event.
|
|
77
|
+
toolName: event.toolId,
|
|
78
78
|
...(event.title != null ? { title: event.title } : {}),
|
|
79
79
|
};
|
|
80
|
-
case "tool
|
|
80
|
+
case "tool.input.delta":
|
|
81
81
|
return {
|
|
82
82
|
type: "tool-input-delta",
|
|
83
83
|
toolCallId: event.id,
|
|
84
84
|
inputTextDelta: event.delta,
|
|
85
85
|
};
|
|
86
|
-
case "tool
|
|
86
|
+
case "tool.call":
|
|
87
87
|
return {
|
|
88
88
|
type: "tool-input-available",
|
|
89
89
|
toolCallId: event.callId,
|
|
90
90
|
toolName: event.toolId,
|
|
91
91
|
input: JSON.parse(event.arguments),
|
|
92
92
|
};
|
|
93
|
-
case "tool
|
|
93
|
+
case "tool.result":
|
|
94
94
|
// Convert tool result to tool-output-available or tool-output-error
|
|
95
95
|
if (event.state === FAILED) {
|
|
96
96
|
return {
|
|
@@ -104,7 +104,7 @@ export const STREAM_UI_PART = {
|
|
|
104
104
|
toolCallId: event.callId,
|
|
105
105
|
output: event.result,
|
|
106
106
|
};
|
|
107
|
-
case "stream
|
|
107
|
+
case "stream.start":
|
|
108
108
|
return {
|
|
109
109
|
type: "start",
|
|
110
110
|
};
|
|
@@ -125,7 +125,7 @@ export const STREAM_UI_PART = {
|
|
|
125
125
|
case "message":
|
|
126
126
|
case "reasoning":
|
|
127
127
|
// - events without direct UI equivalents -
|
|
128
|
-
case "tool
|
|
128
|
+
case "tool.input.end":
|
|
129
129
|
case "raw":
|
|
130
130
|
return null;
|
|
131
131
|
default:
|
package/dist/language-model.js
CHANGED
|
@@ -54,19 +54,19 @@ export class AISDKLanguageModel {
|
|
|
54
54
|
const rbuf = {};
|
|
55
55
|
for await (const event of convertStream(stream.stream)) {
|
|
56
56
|
switch (event.kind) {
|
|
57
|
-
case "text
|
|
57
|
+
case "text.start": {
|
|
58
58
|
tbuf[event.id] = "";
|
|
59
59
|
yield event;
|
|
60
60
|
break;
|
|
61
61
|
}
|
|
62
|
-
case "text
|
|
62
|
+
case "text.delta": {
|
|
63
63
|
if (tbuf[event.id] !== undefined) {
|
|
64
64
|
tbuf[event.id] += event.text;
|
|
65
65
|
}
|
|
66
66
|
yield event;
|
|
67
67
|
break;
|
|
68
68
|
}
|
|
69
|
-
case "text
|
|
69
|
+
case "text.end": {
|
|
70
70
|
const text = tbuf[event.id];
|
|
71
71
|
if (text !== undefined) {
|
|
72
72
|
yield message({
|
|
@@ -79,19 +79,19 @@ export class AISDKLanguageModel {
|
|
|
79
79
|
yield event;
|
|
80
80
|
break;
|
|
81
81
|
}
|
|
82
|
-
case "reasoning
|
|
82
|
+
case "reasoning.start": {
|
|
83
83
|
rbuf[event.id] = "";
|
|
84
84
|
yield event;
|
|
85
85
|
break;
|
|
86
86
|
}
|
|
87
|
-
case "reasoning
|
|
87
|
+
case "reasoning.delta": {
|
|
88
88
|
if (rbuf[event.id] !== undefined) {
|
|
89
89
|
rbuf[event.id] += event.text;
|
|
90
90
|
}
|
|
91
91
|
yield event;
|
|
92
92
|
break;
|
|
93
93
|
}
|
|
94
|
-
case "reasoning
|
|
94
|
+
case "reasoning.end": {
|
|
95
95
|
const text = rbuf[event.id];
|
|
96
96
|
if (text !== undefined) {
|
|
97
97
|
yield reasoning({
|
|
@@ -104,7 +104,7 @@ export class AISDKLanguageModel {
|
|
|
104
104
|
break;
|
|
105
105
|
}
|
|
106
106
|
default:
|
|
107
|
-
// all other events (tool
|
|
107
|
+
// all other events (tool.call, tool.result, finish, etc.) pass through
|
|
108
108
|
yield event;
|
|
109
109
|
break;
|
|
110
110
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kernl-sdk/ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Vercel AI SDK adapter for kernl",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kernl",
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"vitest": "^4.0.8"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@kernl-sdk/protocol": "0.
|
|
72
|
-
"@kernl-sdk/retrieval": "0.1.
|
|
73
|
-
"@kernl-sdk/shared": "^0.
|
|
71
|
+
"@kernl-sdk/protocol": "0.5.0",
|
|
72
|
+
"@kernl-sdk/retrieval": "0.1.9",
|
|
73
|
+
"@kernl-sdk/shared": "^0.4.0"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
76
|
"build": "tsc && tsc-alias --resolve-full-paths",
|
|
@@ -240,7 +240,7 @@ describe.skipIf(SKIP_OPENAI_TESTS)("AISDKLanguageModel - OpenAI", () => {
|
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
// Should have text-delta events
|
|
243
|
-
const textDeltas = events.filter((e) => e.kind === "text
|
|
243
|
+
const textDeltas = events.filter((e) => e.kind === "text.delta");
|
|
244
244
|
expect(textDeltas.length).toBeGreaterThan(0);
|
|
245
245
|
|
|
246
246
|
// Each text-delta should have text
|
|
@@ -302,15 +302,15 @@ describe.skipIf(SKIP_OPENAI_TESTS)("AISDKLanguageModel - OpenAI", () => {
|
|
|
302
302
|
expect(events.length).toBeGreaterThan(0);
|
|
303
303
|
|
|
304
304
|
// Should have text-delta events (for streaming UX)
|
|
305
|
-
const textDeltas = events.filter((e) => e.kind === "text
|
|
305
|
+
const textDeltas = events.filter((e) => e.kind === "text.delta");
|
|
306
306
|
expect(textDeltas.length).toBeGreaterThan(0);
|
|
307
307
|
|
|
308
308
|
// Should have text-start event
|
|
309
|
-
const textStarts = events.filter((e) => e.kind === "text
|
|
309
|
+
const textStarts = events.filter((e) => e.kind === "text.start");
|
|
310
310
|
expect(textStarts.length).toBeGreaterThan(0);
|
|
311
311
|
|
|
312
312
|
// Should have text-end event
|
|
313
|
-
const textEnds = events.filter((e) => e.kind === "text
|
|
313
|
+
const textEnds = events.filter((e) => e.kind === "text.end");
|
|
314
314
|
expect(textEnds.length).toBeGreaterThan(0);
|
|
315
315
|
|
|
316
316
|
// Should have complete Message item (for history)
|
|
@@ -386,7 +386,7 @@ describe.skipIf(SKIP_OPENAI_TESTS)("AISDKLanguageModel - OpenAI", () => {
|
|
|
386
386
|
expect(events.length).toBeGreaterThan(0);
|
|
387
387
|
|
|
388
388
|
// Should have a tool-call event
|
|
389
|
-
const toolCalls = events.filter((e) => e.kind === "tool
|
|
389
|
+
const toolCalls = events.filter((e) => e.kind === "tool.call");
|
|
390
390
|
expect(toolCalls.length).toBeGreaterThan(0);
|
|
391
391
|
|
|
392
392
|
const toolCall = toolCalls[0] as any;
|
|
@@ -445,7 +445,7 @@ describe.skipIf(SKIP_OPENAI_TESTS)("AISDKLanguageModel - OpenAI", () => {
|
|
|
445
445
|
|
|
446
446
|
// Should have a tool call
|
|
447
447
|
const toolCalls = response.content.filter(
|
|
448
|
-
(item) => item.kind === "tool
|
|
448
|
+
(item) => item.kind === "tool.call",
|
|
449
449
|
);
|
|
450
450
|
expect(toolCalls.length).toBeGreaterThan(0);
|
|
451
451
|
|
|
@@ -499,7 +499,7 @@ describe.skipIf(SKIP_OPENAI_TESTS)("AISDKLanguageModel - OpenAI", () => {
|
|
|
499
499
|
|
|
500
500
|
// Should have a tool call since it's required
|
|
501
501
|
const toolCalls = response.content.filter(
|
|
502
|
-
(item) => item.kind === "tool
|
|
502
|
+
(item) => item.kind === "tool.call",
|
|
503
503
|
);
|
|
504
504
|
expect(toolCalls.length).toBeGreaterThan(0);
|
|
505
505
|
});
|
|
@@ -546,7 +546,7 @@ describe.skipIf(SKIP_OPENAI_TESTS)("AISDKLanguageModel - OpenAI", () => {
|
|
|
546
546
|
|
|
547
547
|
// Should potentially have multiple tool calls
|
|
548
548
|
const toolCalls = response.content.filter(
|
|
549
|
-
(item) => item.kind === "tool
|
|
549
|
+
(item) => item.kind === "tool.call",
|
|
550
550
|
);
|
|
551
551
|
expect(toolCalls.length).toBeGreaterThan(0);
|
|
552
552
|
});
|
|
@@ -589,7 +589,7 @@ describe.skipIf(SKIP_OPENAI_TESTS)("AISDKLanguageModel - OpenAI", () => {
|
|
|
589
589
|
|
|
590
590
|
// Extract tool calls
|
|
591
591
|
const toolCalls = firstResponse.content.filter(
|
|
592
|
-
(item) => item.kind === "tool
|
|
592
|
+
(item) => item.kind === "tool.call",
|
|
593
593
|
);
|
|
594
594
|
expect(toolCalls.length).toBeGreaterThan(0);
|
|
595
595
|
|
|
@@ -608,7 +608,7 @@ describe.skipIf(SKIP_OPENAI_TESTS)("AISDKLanguageModel - OpenAI", () => {
|
|
|
608
608
|
},
|
|
609
609
|
...firstResponse.content,
|
|
610
610
|
{
|
|
611
|
-
kind: "tool
|
|
611
|
+
kind: "tool.result",
|
|
612
612
|
callId: toolCall.callId,
|
|
613
613
|
toolId: toolCall.toolId,
|
|
614
614
|
state: "completed",
|
|
@@ -699,7 +699,7 @@ describe.skipIf(SKIP_OPENAI_TESTS)("AISDKLanguageModel - OpenAI", () => {
|
|
|
699
699
|
|
|
700
700
|
// Should have a tool call
|
|
701
701
|
const toolCalls = response.content.filter(
|
|
702
|
-
(item) => item.kind === "tool
|
|
702
|
+
(item) => item.kind === "tool.call",
|
|
703
703
|
);
|
|
704
704
|
expect(toolCalls.length).toBeGreaterThan(0);
|
|
705
705
|
|
|
@@ -840,7 +840,7 @@ describe.skipIf(SKIP_OPENAI_TESTS)("AISDKLanguageModel - OpenAI", () => {
|
|
|
840
840
|
expect(events.length).toBeGreaterThan(0);
|
|
841
841
|
|
|
842
842
|
// Should have text-delta events for streaming JSON
|
|
843
|
-
const textDeltas = events.filter((e) => e.kind === "text
|
|
843
|
+
const textDeltas = events.filter((e) => e.kind === "text.delta");
|
|
844
844
|
expect(textDeltas.length).toBeGreaterThan(0);
|
|
845
845
|
|
|
846
846
|
// Should have a complete message with the JSON
|
|
@@ -921,7 +921,7 @@ describe.skipIf(SKIP_ANTHROPIC_TESTS)("AISDKLanguageModel - Anthropic", () => {
|
|
|
921
921
|
|
|
922
922
|
// Should have a tool call
|
|
923
923
|
const toolCalls = response.content.filter(
|
|
924
|
-
(item) => item.kind === "tool
|
|
924
|
+
(item) => item.kind === "tool.call",
|
|
925
925
|
);
|
|
926
926
|
expect(toolCalls.length).toBeGreaterThan(0);
|
|
927
927
|
|
|
@@ -987,7 +987,7 @@ describe.skipIf(SKIP_ANTHROPIC_TESTS)("AISDKLanguageModel - Anthropic", () => {
|
|
|
987
987
|
expect(events.length).toBeGreaterThan(0);
|
|
988
988
|
|
|
989
989
|
// Should have a tool-call event
|
|
990
|
-
const toolCalls = events.filter((e) => e.kind === "tool
|
|
990
|
+
const toolCalls = events.filter((e) => e.kind === "tool.call");
|
|
991
991
|
expect(toolCalls.length).toBeGreaterThan(0);
|
|
992
992
|
|
|
993
993
|
const toolCall = toolCalls[0] as any;
|
|
@@ -1089,7 +1089,7 @@ describe.skipIf(SKIP_ANTHROPIC_TESTS)("AISDKLanguageModel - Anthropic", () => {
|
|
|
1089
1089
|
expect(events.length).toBeGreaterThan(0);
|
|
1090
1090
|
|
|
1091
1091
|
// Should have text-delta events for streaming JSON
|
|
1092
|
-
const textDeltas = events.filter((e) => e.kind === "text
|
|
1092
|
+
const textDeltas = events.filter((e) => e.kind === "text.delta");
|
|
1093
1093
|
expect(textDeltas.length).toBeGreaterThan(0);
|
|
1094
1094
|
|
|
1095
1095
|
// Should have a complete message with the JSON
|
|
@@ -1265,7 +1265,7 @@ describe.skipIf(SKIP_GOOGLE_TESTS)("AISDKLanguageModel - Google", () => {
|
|
|
1265
1265
|
expect(events.length).toBeGreaterThan(0);
|
|
1266
1266
|
|
|
1267
1267
|
// Should have text-delta events for streaming JSON
|
|
1268
|
-
const textDeltas = events.filter((e) => e.kind === "text
|
|
1268
|
+
const textDeltas = events.filter((e) => e.kind === "text.delta");
|
|
1269
1269
|
expect(textDeltas.length).toBeGreaterThan(0);
|
|
1270
1270
|
|
|
1271
1271
|
// Should have a complete message with the JSON
|
|
@@ -91,19 +91,19 @@ describe("AISDKLanguageModel", () => {
|
|
|
91
91
|
expect(events).toHaveLength(7);
|
|
92
92
|
|
|
93
93
|
// Check delta events
|
|
94
|
-
expect(events[0]).toMatchObject({ kind: "text
|
|
94
|
+
expect(events[0]).toMatchObject({ kind: "text.start", id: "text-1" });
|
|
95
95
|
expect(events[1]).toMatchObject({
|
|
96
|
-
kind: "text
|
|
96
|
+
kind: "text.delta",
|
|
97
97
|
id: "text-1",
|
|
98
98
|
text: "Hello",
|
|
99
99
|
});
|
|
100
100
|
expect(events[2]).toMatchObject({
|
|
101
|
-
kind: "text
|
|
101
|
+
kind: "text.delta",
|
|
102
102
|
id: "text-1",
|
|
103
103
|
text: " ",
|
|
104
104
|
});
|
|
105
105
|
expect(events[3]).toMatchObject({
|
|
106
|
-
kind: "text
|
|
106
|
+
kind: "text.delta",
|
|
107
107
|
id: "text-1",
|
|
108
108
|
text: "World",
|
|
109
109
|
});
|
|
@@ -125,7 +125,7 @@ describe("AISDKLanguageModel", () => {
|
|
|
125
125
|
expect(messageEvent.id).toBeDefined();
|
|
126
126
|
|
|
127
127
|
// Check end event (yielded after Message)
|
|
128
|
-
expect(events[5]).toMatchObject({ kind: "text
|
|
128
|
+
expect(events[5]).toMatchObject({ kind: "text.end", id: "text-1" });
|
|
129
129
|
|
|
130
130
|
// Check finish event
|
|
131
131
|
expect(events[6]).toMatchObject({ kind: "finish" });
|
|
@@ -204,16 +204,16 @@ describe("AISDKLanguageModel", () => {
|
|
|
204
204
|
|
|
205
205
|
// Check delta events
|
|
206
206
|
expect(events[0]).toMatchObject({
|
|
207
|
-
kind: "reasoning
|
|
207
|
+
kind: "reasoning.start",
|
|
208
208
|
id: "reason-1",
|
|
209
209
|
});
|
|
210
210
|
expect(events[1]).toMatchObject({
|
|
211
|
-
kind: "reasoning
|
|
211
|
+
kind: "reasoning.delta",
|
|
212
212
|
id: "reason-1",
|
|
213
213
|
text: "Let me think",
|
|
214
214
|
});
|
|
215
215
|
expect(events[2]).toMatchObject({
|
|
216
|
-
kind: "reasoning
|
|
216
|
+
kind: "reasoning.delta",
|
|
217
217
|
id: "reason-1",
|
|
218
218
|
text: " about this",
|
|
219
219
|
});
|
|
@@ -230,7 +230,7 @@ describe("AISDKLanguageModel", () => {
|
|
|
230
230
|
|
|
231
231
|
// Check end event (yielded after Reasoning)
|
|
232
232
|
expect(events[4]).toMatchObject({
|
|
233
|
-
kind: "reasoning
|
|
233
|
+
kind: "reasoning.end",
|
|
234
234
|
id: "reason-1",
|
|
235
235
|
});
|
|
236
236
|
|
|
@@ -453,7 +453,7 @@ describe("AISDKLanguageModel", () => {
|
|
|
453
453
|
expect(events).toHaveLength(2);
|
|
454
454
|
|
|
455
455
|
expect(events[0]).toMatchObject({
|
|
456
|
-
kind: "tool
|
|
456
|
+
kind: "tool.call",
|
|
457
457
|
callId: "call-123",
|
|
458
458
|
toolId: "calculator",
|
|
459
459
|
state: IN_PROGRESS,
|
|
@@ -212,7 +212,7 @@ describe("MESSAGE codec", () => {
|
|
|
212
212
|
describe("encode - tool-call items", () => {
|
|
213
213
|
it("should encode tool-call item", () => {
|
|
214
214
|
const result = MESSAGE.encode({
|
|
215
|
-
kind: "tool
|
|
215
|
+
kind: "tool.call",
|
|
216
216
|
callId: "call-123",
|
|
217
217
|
toolId: "get_weather",
|
|
218
218
|
state: "completed",
|
|
@@ -225,7 +225,7 @@ describe("MESSAGE codec", () => {
|
|
|
225
225
|
{
|
|
226
226
|
type: "tool-call",
|
|
227
227
|
toolCallId: "call-123",
|
|
228
|
-
|
|
228
|
+
toolId: "get_weather",
|
|
229
229
|
input: { city: "SF" },
|
|
230
230
|
providerOptions: undefined,
|
|
231
231
|
},
|
|
@@ -235,7 +235,7 @@ describe("MESSAGE codec", () => {
|
|
|
235
235
|
|
|
236
236
|
it("should include providerMetadata for tool-call", () => {
|
|
237
237
|
const result = MESSAGE.encode({
|
|
238
|
-
kind: "tool
|
|
238
|
+
kind: "tool.call",
|
|
239
239
|
callId: "call-123",
|
|
240
240
|
toolId: "get_weather",
|
|
241
241
|
state: "completed",
|
|
@@ -253,7 +253,7 @@ describe("MESSAGE codec", () => {
|
|
|
253
253
|
describe("encode - tool-result items", () => {
|
|
254
254
|
it("should encode tool-result item", () => {
|
|
255
255
|
const result = MESSAGE.encode({
|
|
256
|
-
kind: "tool
|
|
256
|
+
kind: "tool.result",
|
|
257
257
|
callId: "call-123",
|
|
258
258
|
toolId: "get_weather",
|
|
259
259
|
state: "completed",
|
|
@@ -267,7 +267,7 @@ describe("MESSAGE codec", () => {
|
|
|
267
267
|
{
|
|
268
268
|
type: "tool-result",
|
|
269
269
|
toolCallId: "call-123",
|
|
270
|
-
|
|
270
|
+
toolId: "get_weather",
|
|
271
271
|
output: {
|
|
272
272
|
type: "json",
|
|
273
273
|
value: { temp: 72, conditions: "sunny" },
|
|
@@ -280,7 +280,7 @@ describe("MESSAGE codec", () => {
|
|
|
280
280
|
|
|
281
281
|
it("should encode tool-result item with error", () => {
|
|
282
282
|
const result = MESSAGE.encode({
|
|
283
|
-
kind: "tool
|
|
283
|
+
kind: "tool.result",
|
|
284
284
|
callId: "call-123",
|
|
285
285
|
toolId: "get_weather",
|
|
286
286
|
state: "failed",
|
|
@@ -294,7 +294,7 @@ describe("MESSAGE codec", () => {
|
|
|
294
294
|
{
|
|
295
295
|
type: "tool-result",
|
|
296
296
|
toolCallId: "call-123",
|
|
297
|
-
|
|
297
|
+
toolId: "get_weather",
|
|
298
298
|
output: {
|
|
299
299
|
type: "error-text",
|
|
300
300
|
value: "Network timeout",
|
|
@@ -109,7 +109,7 @@ describe("MODEL_SETTINGS codec", () => {
|
|
|
109
109
|
const result = MODEL_SETTINGS.encode(settings);
|
|
110
110
|
|
|
111
111
|
expect(result).toEqual({
|
|
112
|
-
toolChoice: { type: "tool",
|
|
112
|
+
toolChoice: { type: "tool", toolId: "get_weather" },
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
115
|
|