@kernl-sdk/ai 0.1.3 → 0.2.6
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 +81 -0
- package/LICENSE +1 -1
- package/dist/__tests__/integration.test.js +278 -27
- package/dist/__tests__/language-model.test.js +3 -2
- package/dist/convert/__tests__/message.test.js +28 -3
- package/dist/convert/__tests__/response.test.js +1 -1
- package/dist/convert/__tests__/settings.test.js +1 -1
- package/dist/convert/__tests__/stream.test.js +32 -8
- package/dist/convert/__tests__/tools.test.js +1 -1
- package/dist/convert/__tests__/ui-message.test.d.ts +2 -0
- package/dist/convert/__tests__/ui-message.test.d.ts.map +1 -0
- package/dist/convert/__tests__/ui-message.test.js +1836 -0
- package/dist/convert/__tests__/ui-stream.test.d.ts +2 -0
- package/dist/convert/__tests__/ui-stream.test.d.ts.map +1 -0
- package/dist/convert/__tests__/ui-stream.test.js +452 -0
- package/dist/convert/message.d.ts +2 -1
- package/dist/convert/message.d.ts.map +1 -1
- package/dist/convert/message.js +15 -9
- package/dist/convert/response.d.ts +2 -1
- package/dist/convert/response.d.ts.map +1 -1
- package/dist/convert/response.js +66 -46
- package/dist/convert/settings.d.ts +2 -1
- package/dist/convert/settings.d.ts.map +1 -1
- package/dist/convert/settings.js +1 -1
- package/dist/convert/stream.d.ts +2 -1
- package/dist/convert/stream.d.ts.map +1 -1
- package/dist/convert/stream.js +13 -18
- package/dist/convert/tools.d.ts +2 -1
- package/dist/convert/tools.d.ts.map +1 -1
- package/dist/convert/ui-message.d.ts +40 -0
- package/dist/convert/ui-message.d.ts.map +1 -0
- package/dist/convert/ui-message.js +324 -0
- package/dist/convert/ui-stream.d.ts +29 -0
- package/dist/convert/ui-stream.d.ts.map +1 -0
- package/dist/convert/ui-stream.js +139 -0
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -6
- package/dist/language-model.d.ts.map +1 -1
- package/dist/language-model.js +77 -88
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/google.d.ts +1 -1
- package/dist/providers/google.js +1 -1
- package/dist/providers/openai.d.ts +1 -1
- package/dist/providers/openai.js +1 -1
- package/package.json +12 -8
- package/src/__tests__/integration.test.ts +789 -507
- package/src/__tests__/language-model.test.ts +2 -1
- package/src/convert/__tests__/message.test.ts +29 -2
- package/src/convert/__tests__/stream.test.ts +34 -7
- package/src/convert/__tests__/ui-message.test.ts +2008 -0
- package/src/convert/__tests__/ui-stream.test.ts +547 -0
- package/src/convert/message.ts +17 -12
- package/src/convert/response.ts +82 -52
- package/src/convert/settings.ts +2 -1
- package/src/convert/stream.ts +22 -20
- package/src/convert/tools.ts +1 -1
- package/src/convert/ui-message.ts +409 -0
- package/src/convert/ui-stream.ts +167 -0
- package/src/index.ts +2 -0
- package/src/language-model.ts +78 -87
- package/tsconfig.json +1 -1
- package/vitest.config.ts +1 -0
- package/src/error.ts +0 -16
- package/src/types.ts +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import { IN_PROGRESS } from "@kernl-sdk/protocol";
|
|
3
|
+
import { STREAM_PART, convertStream } from "../stream.js";
|
|
3
4
|
describe("STREAM_PART codec", () => {
|
|
4
5
|
describe("decode - text events", () => {
|
|
5
6
|
it("should decode text-start event", () => {
|
|
@@ -144,12 +145,31 @@ describe("STREAM_PART codec", () => {
|
|
|
144
145
|
const result = STREAM_PART.decode(part);
|
|
145
146
|
expect(result).toEqual({
|
|
146
147
|
kind: "tool-call",
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
callId: "call-123",
|
|
149
|
+
toolId: "get_weather",
|
|
150
|
+
state: IN_PROGRESS,
|
|
149
151
|
arguments: '{"city":"SF"}',
|
|
150
152
|
providerMetadata: undefined,
|
|
151
153
|
});
|
|
152
154
|
});
|
|
155
|
+
it("should decode tool-call event with empty input string", () => {
|
|
156
|
+
const part = {
|
|
157
|
+
type: "tool-call",
|
|
158
|
+
toolCallId: "call-empty",
|
|
159
|
+
toolName: "list_issues",
|
|
160
|
+
input: "", // AI SDK documents stringified JSON but doesn't actually enforce this
|
|
161
|
+
providerMetadata: undefined,
|
|
162
|
+
};
|
|
163
|
+
const result = STREAM_PART.decode(part);
|
|
164
|
+
expect(result).toEqual({
|
|
165
|
+
kind: "tool-call",
|
|
166
|
+
callId: "call-empty",
|
|
167
|
+
toolId: "list_issues",
|
|
168
|
+
state: IN_PROGRESS,
|
|
169
|
+
arguments: "{}", // Empty string is converted to "{}" to ensure valid JSON
|
|
170
|
+
providerMetadata: undefined,
|
|
171
|
+
});
|
|
172
|
+
});
|
|
153
173
|
it("should decode tool-result event (success)", () => {
|
|
154
174
|
const part = {
|
|
155
175
|
type: "tool-result",
|
|
@@ -185,7 +205,7 @@ describe("STREAM_PART codec", () => {
|
|
|
185
205
|
callId: "call-123",
|
|
186
206
|
toolId: "get_weather",
|
|
187
207
|
state: "failed",
|
|
188
|
-
result:
|
|
208
|
+
result: null,
|
|
189
209
|
error: "Network error",
|
|
190
210
|
providerMetadata: undefined,
|
|
191
211
|
});
|
|
@@ -261,12 +281,16 @@ describe("STREAM_PART codec", () => {
|
|
|
261
281
|
rawValue: { custom: "data" },
|
|
262
282
|
});
|
|
263
283
|
});
|
|
264
|
-
it("should
|
|
284
|
+
it("should decode response-metadata as raw", () => {
|
|
265
285
|
const part = {
|
|
266
286
|
type: "response-metadata",
|
|
287
|
+
timestamp: new Date("2024-01-01T00:00:00Z"),
|
|
267
288
|
};
|
|
268
289
|
const result = STREAM_PART.decode(part);
|
|
269
|
-
expect(result).
|
|
290
|
+
expect(result).toEqual({
|
|
291
|
+
kind: "raw",
|
|
292
|
+
rawValue: part,
|
|
293
|
+
});
|
|
270
294
|
});
|
|
271
295
|
});
|
|
272
296
|
describe("decode - file and source events", () => {
|
|
@@ -349,8 +373,8 @@ describe("convertStream", () => {
|
|
|
349
373
|
providerMetadata: undefined,
|
|
350
374
|
},
|
|
351
375
|
{
|
|
352
|
-
type: "
|
|
353
|
-
}, // This should be filtered out
|
|
376
|
+
type: "unknown-type",
|
|
377
|
+
}, // This should be filtered out (returns null from default case)
|
|
354
378
|
{
|
|
355
379
|
type: "finish",
|
|
356
380
|
finishReason: "stop",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { TOOL, TOOL_CHOICE } from "../tools";
|
|
2
|
+
import { TOOL, TOOL_CHOICE } from "../tools.js";
|
|
3
3
|
describe("TOOL codec", () => {
|
|
4
4
|
describe("encode - function tools", () => {
|
|
5
5
|
it("should encode function tool with basic schema", () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui-message.test.d.ts","sourceRoot":"","sources":["../../../src/convert/__tests__/ui-message.test.ts"],"names":[],"mappings":""}
|