@kernl-sdk/ai 0.3.5 → 0.4.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 +58 -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.d.ts +2 -1
- package/dist/convert/ui-stream.d.ts.map +1 -1
- package/dist/convert/ui-stream.js +16 -14
- package/dist/language-model.d.ts.map +1 -1
- package/dist/language-model.js +9 -8
- package/dist/util.d.ts +10 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +12 -0
- package/package.json +5 -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 +18 -18
- package/src/language-model.ts +9 -8
- package/src/util.ts +12 -0
|
@@ -385,7 +385,7 @@ describe("UIMessageCodec", () => {
|
|
|
385
385
|
});
|
|
386
386
|
expect(result).toHaveLength(1);
|
|
387
387
|
expect(result[0]).toMatchObject({
|
|
388
|
-
kind: "tool
|
|
388
|
+
kind: "tool.call",
|
|
389
389
|
callId: "call-1",
|
|
390
390
|
toolId: "calculator",
|
|
391
391
|
state: IN_PROGRESS,
|
|
@@ -408,7 +408,7 @@ describe("UIMessageCodec", () => {
|
|
|
408
408
|
});
|
|
409
409
|
expect(result).toHaveLength(1);
|
|
410
410
|
expect(result[0]).toMatchObject({
|
|
411
|
-
kind: "tool
|
|
411
|
+
kind: "tool.result",
|
|
412
412
|
callId: "call-1",
|
|
413
413
|
toolId: "calculator",
|
|
414
414
|
state: COMPLETED,
|
|
@@ -432,7 +432,7 @@ describe("UIMessageCodec", () => {
|
|
|
432
432
|
});
|
|
433
433
|
expect(result).toHaveLength(1);
|
|
434
434
|
expect(result[0]).toMatchObject({
|
|
435
|
-
kind: "tool
|
|
435
|
+
kind: "tool.result",
|
|
436
436
|
callId: "call-1",
|
|
437
437
|
toolId: "calculator",
|
|
438
438
|
state: FAILED,
|
|
@@ -478,7 +478,7 @@ describe("UIMessageCodec", () => {
|
|
|
478
478
|
});
|
|
479
479
|
expect(result).toHaveLength(1);
|
|
480
480
|
expect(result[0]).toMatchObject({
|
|
481
|
-
kind: "tool
|
|
481
|
+
kind: "tool.call",
|
|
482
482
|
callId: "call-1",
|
|
483
483
|
toolId: "weather",
|
|
484
484
|
providerMetadata: {
|
|
@@ -505,7 +505,7 @@ describe("UIMessageCodec", () => {
|
|
|
505
505
|
});
|
|
506
506
|
expect(result).toHaveLength(1);
|
|
507
507
|
expect(result[0]).toMatchObject({
|
|
508
|
-
kind: "tool
|
|
508
|
+
kind: "tool.result",
|
|
509
509
|
callId: "call-1",
|
|
510
510
|
toolId: "weather",
|
|
511
511
|
providerMetadata: {
|
|
@@ -531,7 +531,7 @@ describe("UIMessageCodec", () => {
|
|
|
531
531
|
});
|
|
532
532
|
expect(result).toHaveLength(1);
|
|
533
533
|
expect(result[0]).toMatchObject({
|
|
534
|
-
kind: "tool
|
|
534
|
+
kind: "tool.call",
|
|
535
535
|
callId: "call-1",
|
|
536
536
|
toolId: "screenshot",
|
|
537
537
|
state: IN_PROGRESS,
|
|
@@ -555,7 +555,7 @@ describe("UIMessageCodec", () => {
|
|
|
555
555
|
});
|
|
556
556
|
expect(result).toHaveLength(1);
|
|
557
557
|
expect(result[0]).toMatchObject({
|
|
558
|
-
kind: "tool
|
|
558
|
+
kind: "tool.result",
|
|
559
559
|
callId: "call-1",
|
|
560
560
|
toolId: "screenshot",
|
|
561
561
|
state: COMPLETED,
|
|
@@ -580,7 +580,7 @@ describe("UIMessageCodec", () => {
|
|
|
580
580
|
});
|
|
581
581
|
expect(result).toHaveLength(1);
|
|
582
582
|
expect(result[0]).toMatchObject({
|
|
583
|
-
kind: "tool
|
|
583
|
+
kind: "tool.result",
|
|
584
584
|
callId: "call-1",
|
|
585
585
|
toolId: "screenshot",
|
|
586
586
|
state: FAILED,
|
|
@@ -616,12 +616,12 @@ describe("UIMessageCodec", () => {
|
|
|
616
616
|
content: [{ kind: "text", text: "Let me help with that" }],
|
|
617
617
|
});
|
|
618
618
|
expect(result[1]).toMatchObject({
|
|
619
|
-
kind: "tool
|
|
619
|
+
kind: "tool.call",
|
|
620
620
|
callId: "call-1",
|
|
621
621
|
toolId: "calculator",
|
|
622
622
|
});
|
|
623
623
|
expect(result[2]).toMatchObject({
|
|
624
|
-
kind: "tool
|
|
624
|
+
kind: "tool.call",
|
|
625
625
|
callId: "call-2",
|
|
626
626
|
toolId: "weather",
|
|
627
627
|
});
|
|
@@ -654,11 +654,11 @@ describe("UIMessageCodec", () => {
|
|
|
654
654
|
content: [{ kind: "text", text: "The result is 3" }],
|
|
655
655
|
});
|
|
656
656
|
expect(result[1]).toMatchObject({
|
|
657
|
-
kind: "tool
|
|
657
|
+
kind: "tool.result",
|
|
658
658
|
callId: "call-1",
|
|
659
659
|
});
|
|
660
660
|
expect(result[2]).toMatchObject({
|
|
661
|
-
kind: "tool
|
|
661
|
+
kind: "tool.call",
|
|
662
662
|
callId: "call-2",
|
|
663
663
|
});
|
|
664
664
|
});
|
|
@@ -684,11 +684,11 @@ describe("UIMessageCodec", () => {
|
|
|
684
684
|
});
|
|
685
685
|
expect(result).toHaveLength(2);
|
|
686
686
|
expect(result[0]).toMatchObject({
|
|
687
|
-
kind: "tool
|
|
687
|
+
kind: "tool.call",
|
|
688
688
|
toolId: "calculator",
|
|
689
689
|
});
|
|
690
690
|
expect(result[1]).toMatchObject({
|
|
691
|
-
kind: "tool
|
|
691
|
+
kind: "tool.call",
|
|
692
692
|
toolId: "screenshot",
|
|
693
693
|
});
|
|
694
694
|
});
|
|
@@ -709,7 +709,7 @@ describe("UIMessageCodec", () => {
|
|
|
709
709
|
],
|
|
710
710
|
});
|
|
711
711
|
expect(result[0]).toMatchObject({
|
|
712
|
-
kind: "tool
|
|
712
|
+
kind: "tool.result",
|
|
713
713
|
result: "result string",
|
|
714
714
|
});
|
|
715
715
|
});
|
|
@@ -728,7 +728,7 @@ describe("UIMessageCodec", () => {
|
|
|
728
728
|
],
|
|
729
729
|
});
|
|
730
730
|
expect(result[0]).toMatchObject({
|
|
731
|
-
kind: "tool
|
|
731
|
+
kind: "tool.result",
|
|
732
732
|
result: 42,
|
|
733
733
|
});
|
|
734
734
|
});
|
|
@@ -751,7 +751,7 @@ describe("UIMessageCodec", () => {
|
|
|
751
751
|
],
|
|
752
752
|
});
|
|
753
753
|
expect(result[0]).toMatchObject({
|
|
754
|
-
kind: "tool
|
|
754
|
+
kind: "tool.result",
|
|
755
755
|
result: {
|
|
756
756
|
temperature: 20,
|
|
757
757
|
condition: "sunny",
|
|
@@ -774,7 +774,7 @@ describe("UIMessageCodec", () => {
|
|
|
774
774
|
],
|
|
775
775
|
});
|
|
776
776
|
expect(result[0]).toMatchObject({
|
|
777
|
-
kind: "tool
|
|
777
|
+
kind: "tool.result",
|
|
778
778
|
result: ["result1", "result2", "result3"],
|
|
779
779
|
});
|
|
780
780
|
});
|
|
@@ -793,7 +793,7 @@ describe("UIMessageCodec", () => {
|
|
|
793
793
|
],
|
|
794
794
|
});
|
|
795
795
|
expect(result[0]).toMatchObject({
|
|
796
|
-
kind: "tool
|
|
796
|
+
kind: "tool.result",
|
|
797
797
|
result: null,
|
|
798
798
|
});
|
|
799
799
|
});
|
|
@@ -811,7 +811,7 @@ describe("UIMessageCodec", () => {
|
|
|
811
811
|
],
|
|
812
812
|
});
|
|
813
813
|
expect(result[0]).toMatchObject({
|
|
814
|
-
kind: "tool
|
|
814
|
+
kind: "tool.call",
|
|
815
815
|
arguments: "{}",
|
|
816
816
|
});
|
|
817
817
|
});
|
|
@@ -1312,14 +1312,14 @@ describe("historyToUIMessages", () => {
|
|
|
1312
1312
|
content: [{ kind: "text", text: "Let me calculate that." }],
|
|
1313
1313
|
},
|
|
1314
1314
|
{
|
|
1315
|
-
kind: "tool
|
|
1315
|
+
kind: "tool.call",
|
|
1316
1316
|
callId: "call-1",
|
|
1317
1317
|
toolId: "calculator",
|
|
1318
1318
|
state: IN_PROGRESS,
|
|
1319
1319
|
arguments: JSON.stringify({ operation: "add", numbers: [1, 2] }),
|
|
1320
1320
|
},
|
|
1321
1321
|
{
|
|
1322
|
-
kind: "tool
|
|
1322
|
+
kind: "tool.result",
|
|
1323
1323
|
callId: "call-1",
|
|
1324
1324
|
toolId: "calculator",
|
|
1325
1325
|
state: COMPLETED,
|
|
@@ -1337,7 +1337,7 @@ describe("historyToUIMessages", () => {
|
|
|
1337
1337
|
{
|
|
1338
1338
|
type: "tool-calculator",
|
|
1339
1339
|
toolCallId: "call-1",
|
|
1340
|
-
|
|
1340
|
+
toolId: "calculator",
|
|
1341
1341
|
input: { operation: "add", numbers: [1, 2] },
|
|
1342
1342
|
state: "output-available",
|
|
1343
1343
|
output: 3,
|
|
@@ -1355,14 +1355,14 @@ describe("historyToUIMessages", () => {
|
|
|
1355
1355
|
content: [{ kind: "text", text: "Let me try that." }],
|
|
1356
1356
|
},
|
|
1357
1357
|
{
|
|
1358
|
-
kind: "tool
|
|
1358
|
+
kind: "tool.call",
|
|
1359
1359
|
callId: "call-1",
|
|
1360
1360
|
toolId: "calculator",
|
|
1361
1361
|
state: IN_PROGRESS,
|
|
1362
1362
|
arguments: JSON.stringify({ operation: "divide", numbers: [1, 0] }),
|
|
1363
1363
|
},
|
|
1364
1364
|
{
|
|
1365
|
-
kind: "tool
|
|
1365
|
+
kind: "tool.result",
|
|
1366
1366
|
callId: "call-1",
|
|
1367
1367
|
toolId: "calculator",
|
|
1368
1368
|
state: FAILED,
|
|
@@ -1380,7 +1380,7 @@ describe("historyToUIMessages", () => {
|
|
|
1380
1380
|
{
|
|
1381
1381
|
type: "tool-calculator",
|
|
1382
1382
|
toolCallId: "call-1",
|
|
1383
|
-
|
|
1383
|
+
toolId: "calculator",
|
|
1384
1384
|
input: { operation: "divide", numbers: [1, 0] },
|
|
1385
1385
|
state: "output-error",
|
|
1386
1386
|
errorText: "Division by zero",
|
|
@@ -1398,7 +1398,7 @@ describe("historyToUIMessages", () => {
|
|
|
1398
1398
|
content: [{ kind: "text", text: "Processing..." }],
|
|
1399
1399
|
},
|
|
1400
1400
|
{
|
|
1401
|
-
kind: "tool
|
|
1401
|
+
kind: "tool.call",
|
|
1402
1402
|
callId: "call-1",
|
|
1403
1403
|
toolId: "search",
|
|
1404
1404
|
state: IN_PROGRESS,
|
|
@@ -1415,7 +1415,7 @@ describe("historyToUIMessages", () => {
|
|
|
1415
1415
|
{
|
|
1416
1416
|
type: "tool-search",
|
|
1417
1417
|
toolCallId: "call-1",
|
|
1418
|
-
|
|
1418
|
+
toolId: "search",
|
|
1419
1419
|
input: { query: "weather" },
|
|
1420
1420
|
state: "input-available",
|
|
1421
1421
|
},
|
|
@@ -1432,14 +1432,14 @@ describe("historyToUIMessages", () => {
|
|
|
1432
1432
|
content: [{ kind: "text", text: "I'll use multiple tools." }],
|
|
1433
1433
|
},
|
|
1434
1434
|
{
|
|
1435
|
-
kind: "tool
|
|
1435
|
+
kind: "tool.call",
|
|
1436
1436
|
callId: "call-1",
|
|
1437
1437
|
toolId: "tool1",
|
|
1438
1438
|
state: IN_PROGRESS,
|
|
1439
1439
|
arguments: JSON.stringify({ value: "value-1" }),
|
|
1440
1440
|
},
|
|
1441
1441
|
{
|
|
1442
|
-
kind: "tool
|
|
1442
|
+
kind: "tool.result",
|
|
1443
1443
|
callId: "call-1",
|
|
1444
1444
|
toolId: "tool1",
|
|
1445
1445
|
state: COMPLETED,
|
|
@@ -1447,14 +1447,14 @@ describe("historyToUIMessages", () => {
|
|
|
1447
1447
|
error: null,
|
|
1448
1448
|
},
|
|
1449
1449
|
{
|
|
1450
|
-
kind: "tool
|
|
1450
|
+
kind: "tool.call",
|
|
1451
1451
|
callId: "call-2",
|
|
1452
1452
|
toolId: "tool2",
|
|
1453
1453
|
state: IN_PROGRESS,
|
|
1454
1454
|
arguments: JSON.stringify({ value: "value-2" }),
|
|
1455
1455
|
},
|
|
1456
1456
|
{
|
|
1457
|
-
kind: "tool
|
|
1457
|
+
kind: "tool.result",
|
|
1458
1458
|
callId: "call-2",
|
|
1459
1459
|
toolId: "tool2",
|
|
1460
1460
|
state: COMPLETED,
|
|
@@ -1462,14 +1462,14 @@ describe("historyToUIMessages", () => {
|
|
|
1462
1462
|
error: null,
|
|
1463
1463
|
},
|
|
1464
1464
|
{
|
|
1465
|
-
kind: "tool
|
|
1465
|
+
kind: "tool.call",
|
|
1466
1466
|
callId: "call-3",
|
|
1467
1467
|
toolId: "tool3",
|
|
1468
1468
|
state: IN_PROGRESS,
|
|
1469
1469
|
arguments: JSON.stringify({ value: "value-3" }),
|
|
1470
1470
|
},
|
|
1471
1471
|
{
|
|
1472
|
-
kind: "tool
|
|
1472
|
+
kind: "tool.result",
|
|
1473
1473
|
callId: "call-3",
|
|
1474
1474
|
toolId: "tool3",
|
|
1475
1475
|
state: COMPLETED,
|
|
@@ -1487,7 +1487,7 @@ describe("historyToUIMessages", () => {
|
|
|
1487
1487
|
{
|
|
1488
1488
|
type: "tool-tool1",
|
|
1489
1489
|
toolCallId: "call-1",
|
|
1490
|
-
|
|
1490
|
+
toolId: "tool1",
|
|
1491
1491
|
input: { value: "value-1" },
|
|
1492
1492
|
state: "output-available",
|
|
1493
1493
|
output: "result-1",
|
|
@@ -1495,7 +1495,7 @@ describe("historyToUIMessages", () => {
|
|
|
1495
1495
|
{
|
|
1496
1496
|
type: "tool-tool2",
|
|
1497
1497
|
toolCallId: "call-2",
|
|
1498
|
-
|
|
1498
|
+
toolId: "tool2",
|
|
1499
1499
|
input: { value: "value-2" },
|
|
1500
1500
|
state: "output-available",
|
|
1501
1501
|
output: "result-2",
|
|
@@ -1503,7 +1503,7 @@ describe("historyToUIMessages", () => {
|
|
|
1503
1503
|
{
|
|
1504
1504
|
type: "tool-tool3",
|
|
1505
1505
|
toolCallId: "call-3",
|
|
1506
|
-
|
|
1506
|
+
toolId: "tool3",
|
|
1507
1507
|
input: { value: "value-3" },
|
|
1508
1508
|
state: "output-available",
|
|
1509
1509
|
output: "result-3",
|
|
@@ -1521,7 +1521,7 @@ describe("historyToUIMessages", () => {
|
|
|
1521
1521
|
content: [{ kind: "text", text: "Response" }],
|
|
1522
1522
|
},
|
|
1523
1523
|
{
|
|
1524
|
-
kind: "tool
|
|
1524
|
+
kind: "tool.result",
|
|
1525
1525
|
callId: "orphan-1",
|
|
1526
1526
|
toolId: "calculator",
|
|
1527
1527
|
state: COMPLETED,
|
|
@@ -1547,14 +1547,14 @@ describe("historyToUIMessages", () => {
|
|
|
1547
1547
|
content: [{ kind: "text", text: "Using tool" }],
|
|
1548
1548
|
},
|
|
1549
1549
|
{
|
|
1550
|
-
kind: "tool
|
|
1550
|
+
kind: "tool.call",
|
|
1551
1551
|
callId: "call-1",
|
|
1552
1552
|
toolId: "search",
|
|
1553
1553
|
state: IN_PROGRESS,
|
|
1554
1554
|
arguments: JSON.stringify({ query: "test" }),
|
|
1555
1555
|
},
|
|
1556
1556
|
{
|
|
1557
|
-
kind: "tool
|
|
1557
|
+
kind: "tool.result",
|
|
1558
1558
|
callId: "call-1",
|
|
1559
1559
|
toolId: "search",
|
|
1560
1560
|
state: COMPLETED,
|
|
@@ -1578,7 +1578,7 @@ describe("historyToUIMessages", () => {
|
|
|
1578
1578
|
{
|
|
1579
1579
|
type: "tool-search",
|
|
1580
1580
|
toolCallId: "call-1",
|
|
1581
|
-
|
|
1581
|
+
toolId: "search",
|
|
1582
1582
|
input: { query: "test" },
|
|
1583
1583
|
state: "output-available",
|
|
1584
1584
|
output: "found it",
|
|
@@ -1764,14 +1764,14 @@ describe("historyToUIMessages", () => {
|
|
|
1764
1764
|
text: "The image shows numerical data",
|
|
1765
1765
|
},
|
|
1766
1766
|
{
|
|
1767
|
-
kind: "tool
|
|
1767
|
+
kind: "tool.call",
|
|
1768
1768
|
callId: "call-1",
|
|
1769
1769
|
toolId: "calculator",
|
|
1770
1770
|
state: IN_PROGRESS,
|
|
1771
1771
|
arguments: JSON.stringify({ operation: "sum", values: [10, 20, 30] }),
|
|
1772
1772
|
},
|
|
1773
1773
|
{
|
|
1774
|
-
kind: "tool
|
|
1774
|
+
kind: "tool.result",
|
|
1775
1775
|
callId: "call-1",
|
|
1776
1776
|
toolId: "calculator",
|
|
1777
1777
|
state: COMPLETED,
|
|
@@ -1815,7 +1815,7 @@ describe("historyToUIMessages", () => {
|
|
|
1815
1815
|
{
|
|
1816
1816
|
type: "tool-calculator",
|
|
1817
1817
|
toolCallId: "call-1",
|
|
1818
|
-
|
|
1818
|
+
toolId: "calculator",
|
|
1819
1819
|
input: { operation: "sum", values: [10, 20, 30] },
|
|
1820
1820
|
state: "output-available",
|
|
1821
1821
|
output: 60,
|
|
@@ -5,7 +5,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
5
5
|
describe("encode - text events", () => {
|
|
6
6
|
it("should encode text-start event", () => {
|
|
7
7
|
const event = {
|
|
8
|
-
kind: "text
|
|
8
|
+
kind: "text.start",
|
|
9
9
|
id: "text-1",
|
|
10
10
|
};
|
|
11
11
|
const result = STREAM_UI_PART.encode(event);
|
|
@@ -16,7 +16,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
16
16
|
});
|
|
17
17
|
it("should encode text-delta event", () => {
|
|
18
18
|
const event = {
|
|
19
|
-
kind: "text
|
|
19
|
+
kind: "text.delta",
|
|
20
20
|
id: "text-1",
|
|
21
21
|
text: "Hello world",
|
|
22
22
|
};
|
|
@@ -29,7 +29,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
29
29
|
});
|
|
30
30
|
it("should encode text-end event", () => {
|
|
31
31
|
const event = {
|
|
32
|
-
kind: "text
|
|
32
|
+
kind: "text.end",
|
|
33
33
|
id: "text-1",
|
|
34
34
|
};
|
|
35
35
|
const result = STREAM_UI_PART.encode(event);
|
|
@@ -42,7 +42,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
42
42
|
describe("encode - reasoning events", () => {
|
|
43
43
|
it("should encode reasoning-start event", () => {
|
|
44
44
|
const event = {
|
|
45
|
-
kind: "reasoning
|
|
45
|
+
kind: "reasoning.start",
|
|
46
46
|
id: "reason-1",
|
|
47
47
|
};
|
|
48
48
|
const result = STREAM_UI_PART.encode(event);
|
|
@@ -53,7 +53,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
53
53
|
});
|
|
54
54
|
it("should encode reasoning-delta event", () => {
|
|
55
55
|
const event = {
|
|
56
|
-
kind: "reasoning
|
|
56
|
+
kind: "reasoning.delta",
|
|
57
57
|
id: "reason-1",
|
|
58
58
|
text: "thinking step by step",
|
|
59
59
|
};
|
|
@@ -66,7 +66,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
66
66
|
});
|
|
67
67
|
it("should encode reasoning-end event", () => {
|
|
68
68
|
const event = {
|
|
69
|
-
kind: "reasoning
|
|
69
|
+
kind: "reasoning.end",
|
|
70
70
|
id: "reason-1",
|
|
71
71
|
};
|
|
72
72
|
const result = STREAM_UI_PART.encode(event);
|
|
@@ -79,35 +79,35 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
79
79
|
describe("encode - tool input events", () => {
|
|
80
80
|
it("should encode tool-input-start event", () => {
|
|
81
81
|
const event = {
|
|
82
|
-
kind: "tool
|
|
82
|
+
kind: "tool.input.start",
|
|
83
83
|
id: "tool-1",
|
|
84
|
-
|
|
84
|
+
toolId: "calculator",
|
|
85
85
|
};
|
|
86
86
|
const result = STREAM_UI_PART.encode(event);
|
|
87
87
|
expect(result).toEqual({
|
|
88
88
|
type: "tool-input-start",
|
|
89
89
|
toolCallId: "tool-1",
|
|
90
|
-
|
|
90
|
+
toolId: "calculator",
|
|
91
91
|
});
|
|
92
92
|
});
|
|
93
93
|
it("should encode tool-input-start event with title", () => {
|
|
94
94
|
const event = {
|
|
95
|
-
kind: "tool
|
|
95
|
+
kind: "tool.input.start",
|
|
96
96
|
id: "tool-1",
|
|
97
|
-
|
|
97
|
+
toolId: "calculator",
|
|
98
98
|
title: "Calculate sum",
|
|
99
99
|
};
|
|
100
100
|
const result = STREAM_UI_PART.encode(event);
|
|
101
101
|
expect(result).toEqual({
|
|
102
102
|
type: "tool-input-start",
|
|
103
103
|
toolCallId: "tool-1",
|
|
104
|
-
|
|
104
|
+
toolId: "calculator",
|
|
105
105
|
title: "Calculate sum",
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
108
|
it("should encode tool-input-delta event", () => {
|
|
109
109
|
const event = {
|
|
110
|
-
kind: "tool
|
|
110
|
+
kind: "tool.input.delta",
|
|
111
111
|
id: "tool-1",
|
|
112
112
|
delta: '{"a": 1',
|
|
113
113
|
};
|
|
@@ -120,7 +120,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
120
120
|
});
|
|
121
121
|
it("should return null for tool-input-end event", () => {
|
|
122
122
|
const event = {
|
|
123
|
-
kind: "tool
|
|
123
|
+
kind: "tool.input.end",
|
|
124
124
|
id: "tool-1",
|
|
125
125
|
};
|
|
126
126
|
const result = STREAM_UI_PART.encode(event);
|
|
@@ -130,7 +130,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
130
130
|
describe("encode - tool call and result events", () => {
|
|
131
131
|
it("should encode tool-call as tool-input-available", () => {
|
|
132
132
|
const event = {
|
|
133
|
-
kind: "tool
|
|
133
|
+
kind: "tool.call",
|
|
134
134
|
callId: "call-123",
|
|
135
135
|
toolId: "calculator",
|
|
136
136
|
state: COMPLETED,
|
|
@@ -140,13 +140,13 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
140
140
|
expect(result).toEqual({
|
|
141
141
|
type: "tool-input-available",
|
|
142
142
|
toolCallId: "call-123",
|
|
143
|
-
|
|
143
|
+
toolId: "calculator",
|
|
144
144
|
input: { a: 5, b: 3 },
|
|
145
145
|
});
|
|
146
146
|
});
|
|
147
147
|
it("should handle tool-call with empty arguments string", () => {
|
|
148
148
|
const event = {
|
|
149
|
-
kind: "tool
|
|
149
|
+
kind: "tool.call",
|
|
150
150
|
callId: "call-empty",
|
|
151
151
|
toolId: "list_issues",
|
|
152
152
|
state: IN_PROGRESS,
|
|
@@ -156,13 +156,13 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
156
156
|
expect(result).toEqual({
|
|
157
157
|
type: "tool-input-available",
|
|
158
158
|
toolCallId: "call-empty",
|
|
159
|
-
|
|
159
|
+
toolId: "list_issues",
|
|
160
160
|
input: {},
|
|
161
161
|
});
|
|
162
162
|
});
|
|
163
163
|
it("should encode successful tool-result as tool-output-available", () => {
|
|
164
164
|
const event = {
|
|
165
|
-
kind: "tool
|
|
165
|
+
kind: "tool.result",
|
|
166
166
|
callId: "call-123",
|
|
167
167
|
toolId: "calculator",
|
|
168
168
|
state: COMPLETED,
|
|
@@ -178,7 +178,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
178
178
|
});
|
|
179
179
|
it("should encode failed tool-result as tool-output-error", () => {
|
|
180
180
|
const event = {
|
|
181
|
-
kind: "tool
|
|
181
|
+
kind: "tool.result",
|
|
182
182
|
callId: "call-123",
|
|
183
183
|
toolId: "calculator",
|
|
184
184
|
state: FAILED,
|
|
@@ -194,7 +194,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
194
194
|
});
|
|
195
195
|
it("should handle failed tool-result with null error", () => {
|
|
196
196
|
const event = {
|
|
197
|
-
kind: "tool
|
|
197
|
+
kind: "tool.result",
|
|
198
198
|
callId: "call-123",
|
|
199
199
|
toolId: "calculator",
|
|
200
200
|
state: FAILED,
|
|
@@ -212,7 +212,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
212
212
|
describe("encode - stream control events", () => {
|
|
213
213
|
it("should encode stream-start as start", () => {
|
|
214
214
|
const event = {
|
|
215
|
-
kind: "stream
|
|
215
|
+
kind: "stream.start",
|
|
216
216
|
};
|
|
217
217
|
const result = STREAM_UI_PART.encode(event);
|
|
218
218
|
expect(result).toEqual({
|
|
@@ -286,7 +286,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
286
286
|
describe("encode - providerMetadata omission", () => {
|
|
287
287
|
it("should omit providerMetadata from text events", () => {
|
|
288
288
|
const event = {
|
|
289
|
-
kind: "text
|
|
289
|
+
kind: "text.delta",
|
|
290
290
|
id: "text-1",
|
|
291
291
|
text: "Hello",
|
|
292
292
|
providerMetadata: {
|
|
@@ -303,7 +303,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
303
303
|
});
|
|
304
304
|
it("should omit providerMetadata from tool calls", () => {
|
|
305
305
|
const event = {
|
|
306
|
-
kind: "tool
|
|
306
|
+
kind: "tool.call",
|
|
307
307
|
callId: "call-123",
|
|
308
308
|
toolId: "calculator",
|
|
309
309
|
state: COMPLETED,
|
|
@@ -316,7 +316,7 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
316
316
|
expect(result).toEqual({
|
|
317
317
|
type: "tool-input-available",
|
|
318
318
|
toolCallId: "call-123",
|
|
319
|
-
|
|
319
|
+
toolId: "calculator",
|
|
320
320
|
input: { x: 1 },
|
|
321
321
|
});
|
|
322
322
|
expect(result).not.toHaveProperty("providerMetadata");
|
|
@@ -336,11 +336,11 @@ describe("STREAM_UI_PART codec", () => {
|
|
|
336
336
|
describe("toUIMessageStream", () => {
|
|
337
337
|
it("should convert async iterable to readable stream", async () => {
|
|
338
338
|
const events = [
|
|
339
|
-
{ kind: "stream
|
|
340
|
-
{ kind: "text
|
|
341
|
-
{ kind: "text
|
|
342
|
-
{ kind: "text
|
|
343
|
-
{ kind: "text
|
|
339
|
+
{ kind: "stream.start" },
|
|
340
|
+
{ kind: "text.start", id: "text-1" },
|
|
341
|
+
{ kind: "text.delta", id: "text-1", text: "Hello" },
|
|
342
|
+
{ kind: "text.delta", id: "text-1", text: " world" },
|
|
343
|
+
{ kind: "text.end", id: "text-1" },
|
|
344
344
|
{ kind: "finish", finishReason: "stop", usage: { inputTokens: 10, outputTokens: 5, totalTokens: 15 } },
|
|
345
345
|
];
|
|
346
346
|
async function* generateEvents() {
|
|
@@ -369,11 +369,11 @@ describe("toUIMessageStream", () => {
|
|
|
369
369
|
});
|
|
370
370
|
it("should filter out null events", async () => {
|
|
371
371
|
const events = [
|
|
372
|
-
{ kind: "text
|
|
373
|
-
{ kind: "text
|
|
374
|
-
{ kind: "tool
|
|
372
|
+
{ kind: "text.start", id: "text-1" },
|
|
373
|
+
{ kind: "text.delta", id: "text-1", text: "Hello" },
|
|
374
|
+
{ kind: "tool.input.end", id: "tool-1" }, // Should be filtered (returns null)
|
|
375
375
|
{ kind: "raw", rawValue: {} }, // Should be filtered (returns null)
|
|
376
|
-
{ kind: "text
|
|
376
|
+
{ kind: "text.end", id: "text-1" },
|
|
377
377
|
];
|
|
378
378
|
async function* generateEvents() {
|
|
379
379
|
for (const event of events) {
|
|
@@ -397,11 +397,11 @@ describe("toUIMessageStream", () => {
|
|
|
397
397
|
});
|
|
398
398
|
it("should handle tool calls and results", async () => {
|
|
399
399
|
const events = [
|
|
400
|
-
{ kind: "tool
|
|
401
|
-
{ kind: "tool
|
|
402
|
-
{ kind: "tool
|
|
403
|
-
{ kind: "tool
|
|
404
|
-
{ kind: "tool
|
|
400
|
+
{ kind: "tool.input.start", id: "tool-1", toolId: "calculator" },
|
|
401
|
+
{ kind: "tool.input.delta", id: "tool-1", delta: '{"x":' },
|
|
402
|
+
{ kind: "tool.input.delta", id: "tool-1", delta: '5}' },
|
|
403
|
+
{ kind: "tool.call", callId: "tool-1", toolId: "calculator", state: COMPLETED, arguments: '{"x":5}' },
|
|
404
|
+
{ kind: "tool.result", callId: "tool-1", toolId: "calculator", state: COMPLETED, result: 25, error: null },
|
|
405
405
|
];
|
|
406
406
|
async function* generateEvents() {
|
|
407
407
|
for (const event of events) {
|
|
@@ -418,16 +418,16 @@ describe("toUIMessageStream", () => {
|
|
|
418
418
|
chunks.push(value);
|
|
419
419
|
}
|
|
420
420
|
expect(chunks).toEqual([
|
|
421
|
-
{ type: "tool-input-start", toolCallId: "tool-1",
|
|
421
|
+
{ type: "tool-input-start", toolCallId: "tool-1", toolId: "calculator" },
|
|
422
422
|
{ type: "tool-input-delta", toolCallId: "tool-1", inputTextDelta: '{"x":' },
|
|
423
423
|
{ type: "tool-input-delta", toolCallId: "tool-1", inputTextDelta: '5}' },
|
|
424
|
-
{ type: "tool-input-available", toolCallId: "tool-1",
|
|
424
|
+
{ type: "tool-input-available", toolCallId: "tool-1", toolId: "calculator", input: { x: 5 } },
|
|
425
425
|
{ type: "tool-output-available", toolCallId: "tool-1", output: 25 },
|
|
426
426
|
]);
|
|
427
427
|
});
|
|
428
428
|
it("should handle errors in stream", async () => {
|
|
429
429
|
const events = [
|
|
430
|
-
{ kind: "text
|
|
430
|
+
{ kind: "text.start", id: "text-1" },
|
|
431
431
|
{ kind: "error", error: new Error("Network timeout") },
|
|
432
432
|
];
|
|
433
433
|
async function* generateEvents() {
|
package/dist/convert/message.js
CHANGED
|
@@ -82,7 +82,7 @@ export const MESSAGE = {
|
|
|
82
82
|
],
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
case "tool
|
|
85
|
+
case "tool.call": {
|
|
86
86
|
return {
|
|
87
87
|
role: "assistant",
|
|
88
88
|
content: [
|
|
@@ -96,7 +96,7 @@ export const MESSAGE = {
|
|
|
96
96
|
],
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
-
case "tool
|
|
99
|
+
case "tool.result": {
|
|
100
100
|
return {
|
|
101
101
|
role: "tool",
|
|
102
102
|
content: [
|
package/dist/convert/response.js
CHANGED
|
@@ -32,7 +32,7 @@ export const MODEL_RESPONSE = {
|
|
|
32
32
|
break;
|
|
33
33
|
case "tool-call":
|
|
34
34
|
content.push({
|
|
35
|
-
kind: "tool
|
|
35
|
+
kind: "tool.call",
|
|
36
36
|
callId: item.toolCallId,
|
|
37
37
|
toolId: item.toolName,
|
|
38
38
|
state: IN_PROGRESS,
|
|
@@ -42,7 +42,7 @@ export const MODEL_RESPONSE = {
|
|
|
42
42
|
break;
|
|
43
43
|
case "tool-result":
|
|
44
44
|
content.push({
|
|
45
|
-
kind: "tool
|
|
45
|
+
kind: "tool.result",
|
|
46
46
|
callId: item.toolCallId,
|
|
47
47
|
toolId: item.toolName,
|
|
48
48
|
state: item.isError ? FAILED : COMPLETED,
|