ai 6.0.288 → 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 +14 -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/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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.289
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 86f0089: fix(ai): prevent preliminary tool outputs from completing chats
|
|
8
|
+
- da2e17b: fix(provider): preserve opaque file URI strings for provider serialization
|
|
9
|
+
- f211ce5: fix(ai): prevent duplicate content types in chat transport requests
|
|
10
|
+
- 2f1488e: Fix streamed tool input callbacks firing out of order on newer Node.js versions by awaiting start and delta callbacks before invoking `onInputAvailable`.
|
|
11
|
+
- Updated dependencies [da2e17b]
|
|
12
|
+
- Updated dependencies [0b9d00b]
|
|
13
|
+
- @ai-sdk/provider@3.0.17
|
|
14
|
+
- @ai-sdk/gateway@3.0.199
|
|
15
|
+
- @ai-sdk/provider-utils@4.0.53
|
|
16
|
+
|
|
3
17
|
## 6.0.288
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1334,7 +1334,7 @@ function detectMediaType({
|
|
|
1334
1334
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
1335
1335
|
|
|
1336
1336
|
// src/version.ts
|
|
1337
|
-
var VERSION = true ? "6.0.
|
|
1337
|
+
var VERSION = true ? "6.0.289" : "0.0.0-test";
|
|
1338
1338
|
|
|
1339
1339
|
// src/util/download/download.ts
|
|
1340
1340
|
var download = async ({
|
|
@@ -1459,6 +1459,7 @@ var dataContentSchema = import_v4.z.union([
|
|
|
1459
1459
|
)
|
|
1460
1460
|
]);
|
|
1461
1461
|
function convertToLanguageModelV3DataContent(content) {
|
|
1462
|
+
let originalUrl;
|
|
1462
1463
|
if (content instanceof Uint8Array) {
|
|
1463
1464
|
return { data: content, mediaType: void 0 };
|
|
1464
1465
|
}
|
|
@@ -1467,7 +1468,9 @@ function convertToLanguageModelV3DataContent(content) {
|
|
|
1467
1468
|
}
|
|
1468
1469
|
if (typeof content === "string") {
|
|
1469
1470
|
try {
|
|
1470
|
-
|
|
1471
|
+
const url = new URL(content);
|
|
1472
|
+
originalUrl = url.toString() !== content ? content : void 0;
|
|
1473
|
+
content = url;
|
|
1471
1474
|
} catch (error) {
|
|
1472
1475
|
}
|
|
1473
1476
|
}
|
|
@@ -1483,7 +1486,11 @@ function convertToLanguageModelV3DataContent(content) {
|
|
|
1483
1486
|
}
|
|
1484
1487
|
return { data: base64Content, mediaType: dataUrlMediaType };
|
|
1485
1488
|
}
|
|
1486
|
-
return {
|
|
1489
|
+
return {
|
|
1490
|
+
data: content,
|
|
1491
|
+
mediaType: void 0,
|
|
1492
|
+
...originalUrl != null ? { originalUrl } : {}
|
|
1493
|
+
};
|
|
1487
1494
|
}
|
|
1488
1495
|
function convertDataContentToBase64String(content) {
|
|
1489
1496
|
if (typeof content === "string") {
|
|
@@ -1848,7 +1855,11 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
1848
1855
|
default:
|
|
1849
1856
|
throw new Error(`Unsupported part type: ${type}`);
|
|
1850
1857
|
}
|
|
1851
|
-
const {
|
|
1858
|
+
const {
|
|
1859
|
+
data: convertedData,
|
|
1860
|
+
mediaType: convertedMediaType,
|
|
1861
|
+
originalUrl
|
|
1862
|
+
} = convertToLanguageModelV3DataContent(originalData);
|
|
1852
1863
|
let mediaType = convertedMediaType != null ? convertedMediaType : part.mediaType;
|
|
1853
1864
|
let data = convertedData;
|
|
1854
1865
|
if (data instanceof URL) {
|
|
@@ -1869,6 +1880,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
1869
1880
|
// any image
|
|
1870
1881
|
filename: void 0,
|
|
1871
1882
|
data,
|
|
1883
|
+
...data instanceof URL && originalUrl != null ? { originalUrl } : {},
|
|
1872
1884
|
providerOptions: part.providerOptions
|
|
1873
1885
|
};
|
|
1874
1886
|
}
|
|
@@ -1881,6 +1893,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
1881
1893
|
mediaType,
|
|
1882
1894
|
filename: part.filename,
|
|
1883
1895
|
data,
|
|
1896
|
+
...data instanceof URL && originalUrl != null ? { originalUrl } : {},
|
|
1884
1897
|
providerOptions: part.providerOptions
|
|
1885
1898
|
};
|
|
1886
1899
|
}
|
|
@@ -6963,8 +6976,10 @@ function runToolsTransformation({
|
|
|
6963
6976
|
attemptClose();
|
|
6964
6977
|
});
|
|
6965
6978
|
}
|
|
6979
|
+
const activeToolCallToolNames = /* @__PURE__ */ new Map();
|
|
6966
6980
|
const forwardStream = new TransformStream({
|
|
6967
6981
|
async transform(chunk, controller) {
|
|
6982
|
+
var _a23, _b, _c, _d;
|
|
6968
6983
|
const chunkType = chunk.type;
|
|
6969
6984
|
switch (chunkType) {
|
|
6970
6985
|
case "stream-start":
|
|
@@ -6974,9 +6989,6 @@ function runToolsTransformation({
|
|
|
6974
6989
|
case "reasoning-start":
|
|
6975
6990
|
case "reasoning-delta":
|
|
6976
6991
|
case "reasoning-end":
|
|
6977
|
-
case "tool-input-start":
|
|
6978
|
-
case "tool-input-delta":
|
|
6979
|
-
case "tool-input-end":
|
|
6980
6992
|
case "source":
|
|
6981
6993
|
case "response-metadata":
|
|
6982
6994
|
case "error":
|
|
@@ -6984,6 +6996,36 @@ function runToolsTransformation({
|
|
|
6984
6996
|
controller.enqueue(chunk);
|
|
6985
6997
|
break;
|
|
6986
6998
|
}
|
|
6999
|
+
case "tool-input-start": {
|
|
7000
|
+
activeToolCallToolNames.set(chunk.id, chunk.toolName);
|
|
7001
|
+
await ((_b = (_a23 = tools == null ? void 0 : tools[chunk.toolName]) == null ? void 0 : _a23.onInputStart) == null ? void 0 : _b.call(_a23, {
|
|
7002
|
+
toolCallId: chunk.id,
|
|
7003
|
+
messages,
|
|
7004
|
+
abortSignal,
|
|
7005
|
+
experimental_context
|
|
7006
|
+
}));
|
|
7007
|
+
controller.enqueue(chunk);
|
|
7008
|
+
break;
|
|
7009
|
+
}
|
|
7010
|
+
case "tool-input-delta": {
|
|
7011
|
+
const toolName = activeToolCallToolNames.get(chunk.id);
|
|
7012
|
+
if (toolName != null) {
|
|
7013
|
+
await ((_d = (_c = tools == null ? void 0 : tools[toolName]) == null ? void 0 : _c.onInputDelta) == null ? void 0 : _d.call(_c, {
|
|
7014
|
+
inputTextDelta: chunk.delta,
|
|
7015
|
+
toolCallId: chunk.id,
|
|
7016
|
+
messages,
|
|
7017
|
+
abortSignal,
|
|
7018
|
+
experimental_context
|
|
7019
|
+
}));
|
|
7020
|
+
}
|
|
7021
|
+
controller.enqueue(chunk);
|
|
7022
|
+
break;
|
|
7023
|
+
}
|
|
7024
|
+
case "tool-input-end": {
|
|
7025
|
+
activeToolCallToolNames.delete(chunk.id);
|
|
7026
|
+
controller.enqueue(chunk);
|
|
7027
|
+
break;
|
|
7028
|
+
}
|
|
6987
7029
|
case "file": {
|
|
6988
7030
|
controller.enqueue({
|
|
6989
7031
|
type: "file",
|
|
@@ -8205,7 +8247,6 @@ var DefaultStreamTextResult = class {
|
|
|
8205
8247
|
const stepToolCalls = [];
|
|
8206
8248
|
const stepToolOutputs = [];
|
|
8207
8249
|
let warnings;
|
|
8208
|
-
const activeToolCallToolNames = {};
|
|
8209
8250
|
let stepFinishReason = "other";
|
|
8210
8251
|
let stepRawFinishReason = void 0;
|
|
8211
8252
|
let hasReceivedTerminalChunk = false;
|
|
@@ -8352,16 +8393,7 @@ var DefaultStreamTextResult = class {
|
|
|
8352
8393
|
break;
|
|
8353
8394
|
}
|
|
8354
8395
|
case "tool-input-start": {
|
|
8355
|
-
activeToolCallToolNames[chunk.id] = chunk.toolName;
|
|
8356
8396
|
const tool2 = stepToolSet == null ? void 0 : stepToolSet[chunk.toolName];
|
|
8357
|
-
if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
|
|
8358
|
-
await tool2.onInputStart({
|
|
8359
|
-
toolCallId: chunk.id,
|
|
8360
|
-
messages: stepInputMessages,
|
|
8361
|
-
abortSignal,
|
|
8362
|
-
experimental_context
|
|
8363
|
-
});
|
|
8364
|
-
}
|
|
8365
8397
|
controller.enqueue({
|
|
8366
8398
|
...chunk,
|
|
8367
8399
|
dynamic: (_i2 = chunk.dynamic) != null ? _i2 : (tool2 == null ? void 0 : tool2.type) === "dynamic",
|
|
@@ -8370,22 +8402,10 @@ var DefaultStreamTextResult = class {
|
|
|
8370
8402
|
break;
|
|
8371
8403
|
}
|
|
8372
8404
|
case "tool-input-end": {
|
|
8373
|
-
delete activeToolCallToolNames[chunk.id];
|
|
8374
8405
|
controller.enqueue(chunk);
|
|
8375
8406
|
break;
|
|
8376
8407
|
}
|
|
8377
8408
|
case "tool-input-delta": {
|
|
8378
|
-
const toolName = activeToolCallToolNames[chunk.id];
|
|
8379
|
-
const tool2 = stepToolSet == null ? void 0 : stepToolSet[toolName];
|
|
8380
|
-
if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
|
|
8381
|
-
await tool2.onInputDelta({
|
|
8382
|
-
inputTextDelta: chunk.delta,
|
|
8383
|
-
toolCallId: chunk.id,
|
|
8384
|
-
messages: stepInputMessages,
|
|
8385
|
-
abortSignal,
|
|
8386
|
-
experimental_context
|
|
8387
|
-
});
|
|
8388
|
-
}
|
|
8389
8409
|
controller.enqueue(chunk);
|
|
8390
8410
|
break;
|
|
8391
8411
|
}
|
|
@@ -14282,7 +14302,7 @@ var HttpChatTransport = class {
|
|
|
14282
14302
|
const response = await fetch2(api, {
|
|
14283
14303
|
method: "POST",
|
|
14284
14304
|
headers: {
|
|
14285
|
-
"
|
|
14305
|
+
"content-type": "application/json",
|
|
14286
14306
|
...headers
|
|
14287
14307
|
},
|
|
14288
14308
|
body: JSON.stringify(body),
|
|
@@ -14870,7 +14890,7 @@ function lastAssistantMessageIsCompleteWithApprovalResponses({
|
|
|
14870
14890
|
// has at least one tool approval response
|
|
14871
14891
|
lastStepToolInvocations.filter((part) => part.state === "approval-responded").length > 0 && // all tool approvals must have a response
|
|
14872
14892
|
lastStepToolInvocations.every(
|
|
14873
|
-
(part) => part.state === "output-available" || part.state === "output-error" || part.state === "output-denied" || part.state === "approval-responded"
|
|
14893
|
+
(part) => part.state === "output-available" && part.preliminary !== true || part.state === "output-error" || part.state === "output-denied" || part.state === "approval-responded"
|
|
14874
14894
|
)
|
|
14875
14895
|
);
|
|
14876
14896
|
}
|
|
@@ -14891,7 +14911,7 @@ function lastAssistantMessageIsCompleteWithToolCalls({
|
|
|
14891
14911
|
}, -1);
|
|
14892
14912
|
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart).filter((part) => !part.providerExecuted);
|
|
14893
14913
|
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every(
|
|
14894
|
-
(part) => part.state === "output-available" || part.state === "output-error"
|
|
14914
|
+
(part) => part.state === "output-available" && part.preliminary !== true || part.state === "output-error"
|
|
14895
14915
|
);
|
|
14896
14916
|
}
|
|
14897
14917
|
|