ai 6.0.0-beta.43 → 6.0.0-beta.45
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 +12 -0
- package/dist/index.d.mts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +88 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -2
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -720,7 +720,7 @@ import {
|
|
|
720
720
|
} from "@ai-sdk/provider-utils";
|
|
721
721
|
|
|
722
722
|
// src/version.ts
|
|
723
|
-
var VERSION = true ? "6.0.0-beta.
|
|
723
|
+
var VERSION = true ? "6.0.0-beta.45" : "0.0.0-test";
|
|
724
724
|
|
|
725
725
|
// src/util/download/download.ts
|
|
726
726
|
var download = async ({ url }) => {
|
|
@@ -3044,7 +3044,12 @@ function writeToServerResponse({
|
|
|
3044
3044
|
const { done, value } = await reader.read();
|
|
3045
3045
|
if (done)
|
|
3046
3046
|
break;
|
|
3047
|
-
response.write(value);
|
|
3047
|
+
const canContinue = response.write(value);
|
|
3048
|
+
if (!canContinue) {
|
|
3049
|
+
await new Promise((resolve3) => {
|
|
3050
|
+
response.once("drain", resolve3);
|
|
3051
|
+
});
|
|
3052
|
+
}
|
|
3048
3053
|
}
|
|
3049
3054
|
} catch (error) {
|
|
3050
3055
|
throw error;
|
|
@@ -8401,6 +8406,85 @@ var object = ({
|
|
|
8401
8406
|
};
|
|
8402
8407
|
};
|
|
8403
8408
|
|
|
8409
|
+
// src/generate-text/prune-messages.ts
|
|
8410
|
+
function pruneMessages({
|
|
8411
|
+
messages,
|
|
8412
|
+
reasoning = "none",
|
|
8413
|
+
toolCalls = [],
|
|
8414
|
+
emptyMessages = "remove"
|
|
8415
|
+
}) {
|
|
8416
|
+
if (reasoning === "all" || reasoning === "before-last-message") {
|
|
8417
|
+
messages = messages.map((message, messageIndex) => {
|
|
8418
|
+
if (message.role !== "assistant" || typeof message.content === "string" || reasoning === "before-last-message" && messageIndex === messages.length - 1) {
|
|
8419
|
+
return message;
|
|
8420
|
+
}
|
|
8421
|
+
return {
|
|
8422
|
+
...message,
|
|
8423
|
+
content: message.content.filter((part) => part.type !== "reasoning")
|
|
8424
|
+
};
|
|
8425
|
+
});
|
|
8426
|
+
}
|
|
8427
|
+
if (toolCalls === "none") {
|
|
8428
|
+
toolCalls = [];
|
|
8429
|
+
} else if (toolCalls === "all") {
|
|
8430
|
+
toolCalls = [{ type: "all" }];
|
|
8431
|
+
} else if (toolCalls === "before-last-message") {
|
|
8432
|
+
toolCalls = [{ type: "before-last-message" }];
|
|
8433
|
+
} else if (typeof toolCalls === "string") {
|
|
8434
|
+
toolCalls = [{ type: toolCalls }];
|
|
8435
|
+
}
|
|
8436
|
+
for (const toolCall of toolCalls) {
|
|
8437
|
+
const keepLastMessagesCount = toolCall.type === "all" ? void 0 : toolCall.type === "before-last-message" ? 1 : Number(
|
|
8438
|
+
toolCall.type.slice("before-last-".length).slice(0, -"-messages".length)
|
|
8439
|
+
);
|
|
8440
|
+
const keptToolCallIds = /* @__PURE__ */ new Set();
|
|
8441
|
+
const keptApprovalIds = /* @__PURE__ */ new Set();
|
|
8442
|
+
if (keepLastMessagesCount != null) {
|
|
8443
|
+
for (const message of messages.slice(0, -keepLastMessagesCount)) {
|
|
8444
|
+
if ((message.role === "assistant" || message.role === "tool") && typeof message.content !== "string") {
|
|
8445
|
+
for (const part of message.content) {
|
|
8446
|
+
if (part.type === "tool-call" || part.type === "tool-result") {
|
|
8447
|
+
keptToolCallIds.add(part.toolCallId);
|
|
8448
|
+
} else if (part.type === "tool-approval-request" || part.type === "tool-approval-response") {
|
|
8449
|
+
keptApprovalIds.add(part.approvalId);
|
|
8450
|
+
}
|
|
8451
|
+
}
|
|
8452
|
+
}
|
|
8453
|
+
}
|
|
8454
|
+
}
|
|
8455
|
+
messages = messages.map((message, messageIndex) => {
|
|
8456
|
+
if (message.role !== "assistant" && message.role !== "tool" || typeof message.content === "string" || keepLastMessagesCount && messageIndex >= messages.length - keepLastMessagesCount) {
|
|
8457
|
+
return message;
|
|
8458
|
+
}
|
|
8459
|
+
const toolCallIdToToolName = {};
|
|
8460
|
+
const approvalIdToToolName = {};
|
|
8461
|
+
return {
|
|
8462
|
+
...message,
|
|
8463
|
+
content: message.content.filter((part) => {
|
|
8464
|
+
if (part.type !== "tool-call" && part.type !== "tool-result" && part.type !== "tool-approval-request" && part.type !== "tool-approval-response") {
|
|
8465
|
+
return true;
|
|
8466
|
+
}
|
|
8467
|
+
if (part.type === "tool-call") {
|
|
8468
|
+
toolCallIdToToolName[part.toolCallId] = part.toolName;
|
|
8469
|
+
} else if (part.type === "tool-approval-request") {
|
|
8470
|
+
approvalIdToToolName[part.approvalId] = toolCallIdToToolName[part.toolCallId];
|
|
8471
|
+
}
|
|
8472
|
+
if ((part.type === "tool-call" || part.type === "tool-result") && keptToolCallIds.has(part.toolCallId) || (part.type === "tool-approval-request" || part.type === "tool-approval-response") && keptApprovalIds.has(part.approvalId)) {
|
|
8473
|
+
return true;
|
|
8474
|
+
}
|
|
8475
|
+
return toolCall.tools != null && !toolCall.tools.includes(
|
|
8476
|
+
part.type === "tool-call" || part.type === "tool-result" ? part.toolName : approvalIdToToolName[part.approvalId]
|
|
8477
|
+
);
|
|
8478
|
+
})
|
|
8479
|
+
};
|
|
8480
|
+
});
|
|
8481
|
+
}
|
|
8482
|
+
if (emptyMessages === "remove") {
|
|
8483
|
+
messages = messages.filter((message) => message.content.length > 0);
|
|
8484
|
+
}
|
|
8485
|
+
return messages;
|
|
8486
|
+
}
|
|
8487
|
+
|
|
8404
8488
|
// src/generate-text/smooth-stream.ts
|
|
8405
8489
|
import { delay as originalDelay } from "@ai-sdk/provider-utils";
|
|
8406
8490
|
import { InvalidArgumentError as InvalidArgumentError2 } from "@ai-sdk/provider";
|
|
@@ -10971,6 +11055,7 @@ export {
|
|
|
10971
11055
|
parsePartialJson,
|
|
10972
11056
|
pipeTextStreamToResponse,
|
|
10973
11057
|
pipeUIMessageStreamToResponse,
|
|
11058
|
+
pruneMessages,
|
|
10974
11059
|
readUIMessageStream,
|
|
10975
11060
|
safeValidateUIMessages,
|
|
10976
11061
|
simulateReadableStream,
|