@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.
Files changed (68) hide show
  1. package/.turbo/turbo-build.log +5 -4
  2. package/.turbo/turbo-check-types.log +4 -0
  3. package/CHANGELOG.md +81 -0
  4. package/LICENSE +1 -1
  5. package/dist/__tests__/integration.test.js +278 -27
  6. package/dist/__tests__/language-model.test.js +3 -2
  7. package/dist/convert/__tests__/message.test.js +28 -3
  8. package/dist/convert/__tests__/response.test.js +1 -1
  9. package/dist/convert/__tests__/settings.test.js +1 -1
  10. package/dist/convert/__tests__/stream.test.js +32 -8
  11. package/dist/convert/__tests__/tools.test.js +1 -1
  12. package/dist/convert/__tests__/ui-message.test.d.ts +2 -0
  13. package/dist/convert/__tests__/ui-message.test.d.ts.map +1 -0
  14. package/dist/convert/__tests__/ui-message.test.js +1836 -0
  15. package/dist/convert/__tests__/ui-stream.test.d.ts +2 -0
  16. package/dist/convert/__tests__/ui-stream.test.d.ts.map +1 -0
  17. package/dist/convert/__tests__/ui-stream.test.js +452 -0
  18. package/dist/convert/message.d.ts +2 -1
  19. package/dist/convert/message.d.ts.map +1 -1
  20. package/dist/convert/message.js +15 -9
  21. package/dist/convert/response.d.ts +2 -1
  22. package/dist/convert/response.d.ts.map +1 -1
  23. package/dist/convert/response.js +66 -46
  24. package/dist/convert/settings.d.ts +2 -1
  25. package/dist/convert/settings.d.ts.map +1 -1
  26. package/dist/convert/settings.js +1 -1
  27. package/dist/convert/stream.d.ts +2 -1
  28. package/dist/convert/stream.d.ts.map +1 -1
  29. package/dist/convert/stream.js +13 -18
  30. package/dist/convert/tools.d.ts +2 -1
  31. package/dist/convert/tools.d.ts.map +1 -1
  32. package/dist/convert/ui-message.d.ts +40 -0
  33. package/dist/convert/ui-message.d.ts.map +1 -0
  34. package/dist/convert/ui-message.js +324 -0
  35. package/dist/convert/ui-stream.d.ts +29 -0
  36. package/dist/convert/ui-stream.d.ts.map +1 -0
  37. package/dist/convert/ui-stream.js +139 -0
  38. package/dist/index.d.ts +8 -6
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +8 -6
  41. package/dist/language-model.d.ts.map +1 -1
  42. package/dist/language-model.js +77 -88
  43. package/dist/providers/anthropic.d.ts +1 -1
  44. package/dist/providers/anthropic.js +1 -1
  45. package/dist/providers/google.d.ts +1 -1
  46. package/dist/providers/google.js +1 -1
  47. package/dist/providers/openai.d.ts +1 -1
  48. package/dist/providers/openai.js +1 -1
  49. package/package.json +12 -8
  50. package/src/__tests__/integration.test.ts +789 -507
  51. package/src/__tests__/language-model.test.ts +2 -1
  52. package/src/convert/__tests__/message.test.ts +29 -2
  53. package/src/convert/__tests__/stream.test.ts +34 -7
  54. package/src/convert/__tests__/ui-message.test.ts +2008 -0
  55. package/src/convert/__tests__/ui-stream.test.ts +547 -0
  56. package/src/convert/message.ts +17 -12
  57. package/src/convert/response.ts +82 -52
  58. package/src/convert/settings.ts +2 -1
  59. package/src/convert/stream.ts +22 -20
  60. package/src/convert/tools.ts +1 -1
  61. package/src/convert/ui-message.ts +409 -0
  62. package/src/convert/ui-stream.ts +167 -0
  63. package/src/index.ts +2 -0
  64. package/src/language-model.ts +78 -87
  65. package/tsconfig.json +1 -1
  66. package/vitest.config.ts +1 -0
  67. package/src/error.ts +0 -16
  68. package/src/types.ts +0 -0
@@ -1,5 +1,6 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import { STREAM_PART, convertStream } from "../stream";
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
- id: "call-123",
148
- toolName: "get_weather",
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: "Network error",
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 return null for response-metadata", () => {
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).toBeNull();
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: "response-metadata",
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ui-message.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui-message.test.d.ts","sourceRoot":"","sources":["../../../src/convert/__tests__/ui-message.test.ts"],"names":[],"mappings":""}