ai 6.0.287 → 6.0.289
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/CHANGELOG.md +21 -0
- package/dist/index.js +52 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -32
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +17 -4
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +17 -4
- package/dist/internal/index.mjs.map +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +1 -0
- package/docs/03-ai-sdk-core/40-middleware.mdx +92 -7
- package/package.json +4 -4
- package/src/generate-text/run-tools-transformation.ts +37 -3
- package/src/generate-text/stream-text.ts +0 -27
- package/src/prompt/convert-to-language-model-prompt.ts +7 -2
- package/src/prompt/data-content.ts +11 -2
- package/src/ui/http-chat-transport.ts +1 -1
- package/src/ui/last-assistant-message-is-complete-with-approval-responses.ts +1 -1
- package/src/ui/last-assistant-message-is-complete-with-tool-calls.ts +2 -1
package/dist/index.mjs
CHANGED
|
@@ -1224,7 +1224,7 @@ import {
|
|
|
1224
1224
|
} from "@ai-sdk/provider-utils";
|
|
1225
1225
|
|
|
1226
1226
|
// src/version.ts
|
|
1227
|
-
var VERSION = true ? "6.0.
|
|
1227
|
+
var VERSION = true ? "6.0.289" : "0.0.0-test";
|
|
1228
1228
|
|
|
1229
1229
|
// src/util/download/download.ts
|
|
1230
1230
|
var download = async ({
|
|
@@ -1352,6 +1352,7 @@ var dataContentSchema = z.union([
|
|
|
1352
1352
|
)
|
|
1353
1353
|
]);
|
|
1354
1354
|
function convertToLanguageModelV3DataContent(content) {
|
|
1355
|
+
let originalUrl;
|
|
1355
1356
|
if (content instanceof Uint8Array) {
|
|
1356
1357
|
return { data: content, mediaType: void 0 };
|
|
1357
1358
|
}
|
|
@@ -1360,7 +1361,9 @@ function convertToLanguageModelV3DataContent(content) {
|
|
|
1360
1361
|
}
|
|
1361
1362
|
if (typeof content === "string") {
|
|
1362
1363
|
try {
|
|
1363
|
-
|
|
1364
|
+
const url = new URL(content);
|
|
1365
|
+
originalUrl = url.toString() !== content ? content : void 0;
|
|
1366
|
+
content = url;
|
|
1364
1367
|
} catch (error) {
|
|
1365
1368
|
}
|
|
1366
1369
|
}
|
|
@@ -1376,7 +1379,11 @@ function convertToLanguageModelV3DataContent(content) {
|
|
|
1376
1379
|
}
|
|
1377
1380
|
return { data: base64Content, mediaType: dataUrlMediaType };
|
|
1378
1381
|
}
|
|
1379
|
-
return {
|
|
1382
|
+
return {
|
|
1383
|
+
data: content,
|
|
1384
|
+
mediaType: void 0,
|
|
1385
|
+
...originalUrl != null ? { originalUrl } : {}
|
|
1386
|
+
};
|
|
1380
1387
|
}
|
|
1381
1388
|
function convertDataContentToBase64String(content) {
|
|
1382
1389
|
if (typeof content === "string") {
|
|
@@ -1741,7 +1748,11 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
1741
1748
|
default:
|
|
1742
1749
|
throw new Error(`Unsupported part type: ${type}`);
|
|
1743
1750
|
}
|
|
1744
|
-
const {
|
|
1751
|
+
const {
|
|
1752
|
+
data: convertedData,
|
|
1753
|
+
mediaType: convertedMediaType,
|
|
1754
|
+
originalUrl
|
|
1755
|
+
} = convertToLanguageModelV3DataContent(originalData);
|
|
1745
1756
|
let mediaType = convertedMediaType != null ? convertedMediaType : part.mediaType;
|
|
1746
1757
|
let data = convertedData;
|
|
1747
1758
|
if (data instanceof URL) {
|
|
@@ -1762,6 +1773,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
1762
1773
|
// any image
|
|
1763
1774
|
filename: void 0,
|
|
1764
1775
|
data,
|
|
1776
|
+
...data instanceof URL && originalUrl != null ? { originalUrl } : {},
|
|
1765
1777
|
providerOptions: part.providerOptions
|
|
1766
1778
|
};
|
|
1767
1779
|
}
|
|
@@ -1774,6 +1786,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
1774
1786
|
mediaType,
|
|
1775
1787
|
filename: part.filename,
|
|
1776
1788
|
data,
|
|
1789
|
+
...data instanceof URL && originalUrl != null ? { originalUrl } : {},
|
|
1777
1790
|
providerOptions: part.providerOptions
|
|
1778
1791
|
};
|
|
1779
1792
|
}
|
|
@@ -6892,8 +6905,10 @@ function runToolsTransformation({
|
|
|
6892
6905
|
attemptClose();
|
|
6893
6906
|
});
|
|
6894
6907
|
}
|
|
6908
|
+
const activeToolCallToolNames = /* @__PURE__ */ new Map();
|
|
6895
6909
|
const forwardStream = new TransformStream({
|
|
6896
6910
|
async transform(chunk, controller) {
|
|
6911
|
+
var _a23, _b, _c, _d;
|
|
6897
6912
|
const chunkType = chunk.type;
|
|
6898
6913
|
switch (chunkType) {
|
|
6899
6914
|
case "stream-start":
|
|
@@ -6903,9 +6918,6 @@ function runToolsTransformation({
|
|
|
6903
6918
|
case "reasoning-start":
|
|
6904
6919
|
case "reasoning-delta":
|
|
6905
6920
|
case "reasoning-end":
|
|
6906
|
-
case "tool-input-start":
|
|
6907
|
-
case "tool-input-delta":
|
|
6908
|
-
case "tool-input-end":
|
|
6909
6921
|
case "source":
|
|
6910
6922
|
case "response-metadata":
|
|
6911
6923
|
case "error":
|
|
@@ -6913,6 +6925,36 @@ function runToolsTransformation({
|
|
|
6913
6925
|
controller.enqueue(chunk);
|
|
6914
6926
|
break;
|
|
6915
6927
|
}
|
|
6928
|
+
case "tool-input-start": {
|
|
6929
|
+
activeToolCallToolNames.set(chunk.id, chunk.toolName);
|
|
6930
|
+
await ((_b = (_a23 = tools == null ? void 0 : tools[chunk.toolName]) == null ? void 0 : _a23.onInputStart) == null ? void 0 : _b.call(_a23, {
|
|
6931
|
+
toolCallId: chunk.id,
|
|
6932
|
+
messages,
|
|
6933
|
+
abortSignal,
|
|
6934
|
+
experimental_context
|
|
6935
|
+
}));
|
|
6936
|
+
controller.enqueue(chunk);
|
|
6937
|
+
break;
|
|
6938
|
+
}
|
|
6939
|
+
case "tool-input-delta": {
|
|
6940
|
+
const toolName = activeToolCallToolNames.get(chunk.id);
|
|
6941
|
+
if (toolName != null) {
|
|
6942
|
+
await ((_d = (_c = tools == null ? void 0 : tools[toolName]) == null ? void 0 : _c.onInputDelta) == null ? void 0 : _d.call(_c, {
|
|
6943
|
+
inputTextDelta: chunk.delta,
|
|
6944
|
+
toolCallId: chunk.id,
|
|
6945
|
+
messages,
|
|
6946
|
+
abortSignal,
|
|
6947
|
+
experimental_context
|
|
6948
|
+
}));
|
|
6949
|
+
}
|
|
6950
|
+
controller.enqueue(chunk);
|
|
6951
|
+
break;
|
|
6952
|
+
}
|
|
6953
|
+
case "tool-input-end": {
|
|
6954
|
+
activeToolCallToolNames.delete(chunk.id);
|
|
6955
|
+
controller.enqueue(chunk);
|
|
6956
|
+
break;
|
|
6957
|
+
}
|
|
6916
6958
|
case "file": {
|
|
6917
6959
|
controller.enqueue({
|
|
6918
6960
|
type: "file",
|
|
@@ -8134,7 +8176,6 @@ var DefaultStreamTextResult = class {
|
|
|
8134
8176
|
const stepToolCalls = [];
|
|
8135
8177
|
const stepToolOutputs = [];
|
|
8136
8178
|
let warnings;
|
|
8137
|
-
const activeToolCallToolNames = {};
|
|
8138
8179
|
let stepFinishReason = "other";
|
|
8139
8180
|
let stepRawFinishReason = void 0;
|
|
8140
8181
|
let hasReceivedTerminalChunk = false;
|
|
@@ -8281,16 +8322,7 @@ var DefaultStreamTextResult = class {
|
|
|
8281
8322
|
break;
|
|
8282
8323
|
}
|
|
8283
8324
|
case "tool-input-start": {
|
|
8284
|
-
activeToolCallToolNames[chunk.id] = chunk.toolName;
|
|
8285
8325
|
const tool2 = stepToolSet == null ? void 0 : stepToolSet[chunk.toolName];
|
|
8286
|
-
if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
|
|
8287
|
-
await tool2.onInputStart({
|
|
8288
|
-
toolCallId: chunk.id,
|
|
8289
|
-
messages: stepInputMessages,
|
|
8290
|
-
abortSignal,
|
|
8291
|
-
experimental_context
|
|
8292
|
-
});
|
|
8293
|
-
}
|
|
8294
8326
|
controller.enqueue({
|
|
8295
8327
|
...chunk,
|
|
8296
8328
|
dynamic: (_i2 = chunk.dynamic) != null ? _i2 : (tool2 == null ? void 0 : tool2.type) === "dynamic",
|
|
@@ -8299,22 +8331,10 @@ var DefaultStreamTextResult = class {
|
|
|
8299
8331
|
break;
|
|
8300
8332
|
}
|
|
8301
8333
|
case "tool-input-end": {
|
|
8302
|
-
delete activeToolCallToolNames[chunk.id];
|
|
8303
8334
|
controller.enqueue(chunk);
|
|
8304
8335
|
break;
|
|
8305
8336
|
}
|
|
8306
8337
|
case "tool-input-delta": {
|
|
8307
|
-
const toolName = activeToolCallToolNames[chunk.id];
|
|
8308
|
-
const tool2 = stepToolSet == null ? void 0 : stepToolSet[toolName];
|
|
8309
|
-
if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
|
|
8310
|
-
await tool2.onInputDelta({
|
|
8311
|
-
inputTextDelta: chunk.delta,
|
|
8312
|
-
toolCallId: chunk.id,
|
|
8313
|
-
messages: stepInputMessages,
|
|
8314
|
-
abortSignal,
|
|
8315
|
-
experimental_context
|
|
8316
|
-
});
|
|
8317
|
-
}
|
|
8318
8338
|
controller.enqueue(chunk);
|
|
8319
8339
|
break;
|
|
8320
8340
|
}
|
|
@@ -14267,7 +14287,7 @@ var HttpChatTransport = class {
|
|
|
14267
14287
|
const response = await fetch2(api, {
|
|
14268
14288
|
method: "POST",
|
|
14269
14289
|
headers: {
|
|
14270
|
-
"
|
|
14290
|
+
"content-type": "application/json",
|
|
14271
14291
|
...headers
|
|
14272
14292
|
},
|
|
14273
14293
|
body: JSON.stringify(body),
|
|
@@ -14855,7 +14875,7 @@ function lastAssistantMessageIsCompleteWithApprovalResponses({
|
|
|
14855
14875
|
// has at least one tool approval response
|
|
14856
14876
|
lastStepToolInvocations.filter((part) => part.state === "approval-responded").length > 0 && // all tool approvals must have a response
|
|
14857
14877
|
lastStepToolInvocations.every(
|
|
14858
|
-
(part) => part.state === "output-available" || part.state === "output-error" || part.state === "output-denied" || part.state === "approval-responded"
|
|
14878
|
+
(part) => part.state === "output-available" && part.preliminary !== true || part.state === "output-error" || part.state === "output-denied" || part.state === "approval-responded"
|
|
14859
14879
|
)
|
|
14860
14880
|
);
|
|
14861
14881
|
}
|
|
@@ -14876,7 +14896,7 @@ function lastAssistantMessageIsCompleteWithToolCalls({
|
|
|
14876
14896
|
}, -1);
|
|
14877
14897
|
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart).filter((part) => !part.providerExecuted);
|
|
14878
14898
|
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every(
|
|
14879
|
-
(part) => part.state === "output-available" || part.state === "output-error"
|
|
14899
|
+
(part) => part.state === "output-available" && part.preliminary !== true || part.state === "output-error"
|
|
14880
14900
|
);
|
|
14881
14901
|
}
|
|
14882
14902
|
|