ai 3.2.27 → 3.2.28
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/dist/index.d.mts +23 -9
- package/dist/index.d.ts +23 -9
- package/dist/index.js +104 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
@@ -748,6 +748,44 @@ function createAsyncIterableStream(source, transformer) {
|
|
748
748
|
return transformedStream;
|
749
749
|
}
|
750
750
|
|
751
|
+
// core/util/delayed-promise.ts
|
752
|
+
var DelayedPromise = class {
|
753
|
+
constructor() {
|
754
|
+
this.status = { type: "pending" };
|
755
|
+
this._resolve = void 0;
|
756
|
+
this._reject = void 0;
|
757
|
+
}
|
758
|
+
get value() {
|
759
|
+
if (this.promise) {
|
760
|
+
return this.promise;
|
761
|
+
}
|
762
|
+
this.promise = new Promise((resolve, reject) => {
|
763
|
+
if (this.status.type === "resolved") {
|
764
|
+
resolve(this.status.value);
|
765
|
+
} else if (this.status.type === "rejected") {
|
766
|
+
reject(this.status.error);
|
767
|
+
}
|
768
|
+
this._resolve = resolve;
|
769
|
+
this._reject = reject;
|
770
|
+
});
|
771
|
+
return this.promise;
|
772
|
+
}
|
773
|
+
resolve(value) {
|
774
|
+
var _a;
|
775
|
+
this.status = { type: "resolved", value };
|
776
|
+
if (this.promise) {
|
777
|
+
(_a = this._resolve) == null ? void 0 : _a.call(this, value);
|
778
|
+
}
|
779
|
+
}
|
780
|
+
reject(error) {
|
781
|
+
var _a;
|
782
|
+
this.status = { type: "rejected", error };
|
783
|
+
if (this.promise) {
|
784
|
+
(_a = this._reject) == null ? void 0 : _a.call(this, error);
|
785
|
+
}
|
786
|
+
}
|
787
|
+
};
|
788
|
+
|
751
789
|
// core/generate-object/stream-object.ts
|
752
790
|
async function streamObject({
|
753
791
|
model,
|
@@ -892,12 +930,7 @@ var StreamObjectResult = class {
|
|
892
930
|
}) {
|
893
931
|
this.warnings = warnings;
|
894
932
|
this.rawResponse = rawResponse;
|
895
|
-
|
896
|
-
let rejectObject;
|
897
|
-
this.object = new Promise((resolve, reject) => {
|
898
|
-
resolveObject = resolve;
|
899
|
-
rejectObject = reject;
|
900
|
-
});
|
933
|
+
this.objectPromise = new DelayedPromise();
|
901
934
|
let resolveUsage;
|
902
935
|
this.usage = new Promise((resolve) => {
|
903
936
|
resolveUsage = resolve;
|
@@ -908,6 +941,7 @@ var StreamObjectResult = class {
|
|
908
941
|
let accumulatedText = "";
|
909
942
|
let delta = "";
|
910
943
|
let latestObject = void 0;
|
944
|
+
const self = this;
|
911
945
|
this.originalStream = stream.pipeThrough(
|
912
946
|
new TransformStream({
|
913
947
|
async transform(chunk, controller) {
|
@@ -948,10 +982,10 @@ var StreamObjectResult = class {
|
|
948
982
|
});
|
949
983
|
if (validationResult.success) {
|
950
984
|
object = validationResult.value;
|
951
|
-
|
985
|
+
self.objectPromise.resolve(object);
|
952
986
|
} else {
|
953
987
|
error = validationResult.error;
|
954
|
-
|
988
|
+
self.objectPromise.reject(error);
|
955
989
|
}
|
956
990
|
break;
|
957
991
|
}
|
@@ -983,6 +1017,12 @@ var StreamObjectResult = class {
|
|
983
1017
|
);
|
984
1018
|
}
|
985
1019
|
/**
|
1020
|
+
The generated object (typed according to the schema). Resolved when the response is finished.
|
1021
|
+
*/
|
1022
|
+
get object() {
|
1023
|
+
return this.objectPromise.value;
|
1024
|
+
}
|
1025
|
+
/**
|
986
1026
|
Stream of partial objects. It gets more complete as the stream progresses.
|
987
1027
|
|
988
1028
|
Note that the partial object is not validated.
|
@@ -1553,6 +1593,7 @@ import { generateId } from "@ai-sdk/ui-utils";
|
|
1553
1593
|
function runToolsTransformation({
|
1554
1594
|
tools,
|
1555
1595
|
generatorStream,
|
1596
|
+
toolCallStreaming,
|
1556
1597
|
tracer
|
1557
1598
|
}) {
|
1558
1599
|
let canClose = false;
|
@@ -1563,6 +1604,7 @@ function runToolsTransformation({
|
|
1563
1604
|
toolResultsStreamController = controller;
|
1564
1605
|
}
|
1565
1606
|
});
|
1607
|
+
const activeToolCalls = {};
|
1566
1608
|
const forwardStream = new TransformStream({
|
1567
1609
|
transform(chunk, controller) {
|
1568
1610
|
const chunkType = chunk.type;
|
@@ -1572,6 +1614,25 @@ function runToolsTransformation({
|
|
1572
1614
|
controller.enqueue(chunk);
|
1573
1615
|
break;
|
1574
1616
|
}
|
1617
|
+
case "tool-call-delta": {
|
1618
|
+
if (toolCallStreaming) {
|
1619
|
+
if (!activeToolCalls[chunk.toolCallId]) {
|
1620
|
+
controller.enqueue({
|
1621
|
+
type: "tool-call-streaming-start",
|
1622
|
+
toolCallId: chunk.toolCallId,
|
1623
|
+
toolName: chunk.toolName
|
1624
|
+
});
|
1625
|
+
activeToolCalls[chunk.toolCallId] = true;
|
1626
|
+
}
|
1627
|
+
controller.enqueue({
|
1628
|
+
type: "tool-call-delta",
|
1629
|
+
toolCallId: chunk.toolCallId,
|
1630
|
+
toolName: chunk.toolName,
|
1631
|
+
argsTextDelta: chunk.argsTextDelta
|
1632
|
+
});
|
1633
|
+
}
|
1634
|
+
break;
|
1635
|
+
}
|
1575
1636
|
case "tool-call": {
|
1576
1637
|
const toolName = chunk.toolName;
|
1577
1638
|
if (tools == null) {
|
@@ -1657,9 +1718,6 @@ function runToolsTransformation({
|
|
1657
1718
|
});
|
1658
1719
|
break;
|
1659
1720
|
}
|
1660
|
-
case "tool-call-delta": {
|
1661
|
-
break;
|
1662
|
-
}
|
1663
1721
|
default: {
|
1664
1722
|
const _exhaustiveCheck = chunkType;
|
1665
1723
|
throw new Error(`Unhandled chunk type: ${_exhaustiveCheck}`);
|
@@ -1712,6 +1770,7 @@ async function streamText({
|
|
1712
1770
|
abortSignal,
|
1713
1771
|
headers,
|
1714
1772
|
experimental_telemetry: telemetry,
|
1773
|
+
experimental_toolCallStreaming: toolCallStreaming = false,
|
1715
1774
|
onFinish,
|
1716
1775
|
...settings
|
1717
1776
|
}) {
|
@@ -1772,6 +1831,7 @@ async function streamText({
|
|
1772
1831
|
stream: runToolsTransformation({
|
1773
1832
|
tools,
|
1774
1833
|
generatorStream: stream,
|
1834
|
+
toolCallStreaming,
|
1775
1835
|
tracer
|
1776
1836
|
}),
|
1777
1837
|
warnings,
|
@@ -1849,6 +1909,8 @@ var StreamTextResult = class {
|
|
1849
1909
|
resolveText(text);
|
1850
1910
|
resolveToolCalls(toolCalls);
|
1851
1911
|
break;
|
1912
|
+
case "tool-call-streaming-start":
|
1913
|
+
case "tool-call-delta":
|
1852
1914
|
case "error":
|
1853
1915
|
break;
|
1854
1916
|
default: {
|
@@ -1992,10 +2054,27 @@ var StreamTextResult = class {
|
|
1992
2054
|
});
|
1993
2055
|
const streamDataTransformer = new TransformStream({
|
1994
2056
|
transform: async (chunk, controller) => {
|
1995
|
-
|
2057
|
+
const chunkType = chunk.type;
|
2058
|
+
switch (chunkType) {
|
1996
2059
|
case "text-delta":
|
1997
2060
|
controller.enqueue(formatStreamPart("text", chunk.textDelta));
|
1998
2061
|
break;
|
2062
|
+
case "tool-call-streaming-start":
|
2063
|
+
controller.enqueue(
|
2064
|
+
formatStreamPart("tool_call_streaming_start", {
|
2065
|
+
toolCallId: chunk.toolCallId,
|
2066
|
+
toolName: chunk.toolName
|
2067
|
+
})
|
2068
|
+
);
|
2069
|
+
break;
|
2070
|
+
case "tool-call-delta":
|
2071
|
+
controller.enqueue(
|
2072
|
+
formatStreamPart("tool_call_delta", {
|
2073
|
+
toolCallId: chunk.toolCallId,
|
2074
|
+
argsTextDelta: chunk.argsTextDelta
|
2075
|
+
})
|
2076
|
+
);
|
2077
|
+
break;
|
1999
2078
|
case "tool-call":
|
2000
2079
|
controller.enqueue(
|
2001
2080
|
formatStreamPart("tool_call", {
|
@@ -2020,6 +2099,12 @@ var StreamTextResult = class {
|
|
2020
2099
|
formatStreamPart("error", JSON.stringify(chunk.error))
|
2021
2100
|
);
|
2022
2101
|
break;
|
2102
|
+
case "finish":
|
2103
|
+
break;
|
2104
|
+
default: {
|
2105
|
+
const exhaustiveCheck = chunkType;
|
2106
|
+
throw new Error(`Unknown chunk type: ${exhaustiveCheck}`);
|
2107
|
+
}
|
2023
2108
|
}
|
2024
2109
|
}
|
2025
2110
|
});
|
@@ -2182,6 +2267,13 @@ function convertToCoreMessages(messages) {
|
|
2182
2267
|
experimental_attachments
|
2183
2268
|
} of messages) {
|
2184
2269
|
switch (role) {
|
2270
|
+
case "system": {
|
2271
|
+
coreMessages.push({
|
2272
|
+
role: "system",
|
2273
|
+
content
|
2274
|
+
});
|
2275
|
+
break;
|
2276
|
+
}
|
2185
2277
|
case "user": {
|
2186
2278
|
coreMessages.push({
|
2187
2279
|
role: "user",
|