ai 5.0.69 → 5.0.71
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 +13 -0
- package/dist/index.d.mts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +75 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -1
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -695,7 +695,7 @@ import {
|
|
|
695
695
|
} from "@ai-sdk/provider-utils";
|
|
696
696
|
|
|
697
697
|
// src/version.ts
|
|
698
|
-
var VERSION = true ? "5.0.
|
|
698
|
+
var VERSION = true ? "5.0.71" : "0.0.0-test";
|
|
699
699
|
|
|
700
700
|
// src/util/download/download.ts
|
|
701
701
|
var download = async ({ url }) => {
|
|
@@ -8015,6 +8015,78 @@ var object = ({
|
|
|
8015
8015
|
};
|
|
8016
8016
|
};
|
|
8017
8017
|
|
|
8018
|
+
// src/generate-text/prune-messages.ts
|
|
8019
|
+
function pruneMessages({
|
|
8020
|
+
messages,
|
|
8021
|
+
reasoning = "none",
|
|
8022
|
+
toolCalls = [],
|
|
8023
|
+
emptyMessages = "remove"
|
|
8024
|
+
}) {
|
|
8025
|
+
if (reasoning === "all" || reasoning === "before-last-message") {
|
|
8026
|
+
messages = messages.map((message, messageIndex) => {
|
|
8027
|
+
if (message.role !== "assistant" || typeof message.content === "string" || reasoning === "before-last-message" && messageIndex === messages.length - 1) {
|
|
8028
|
+
return message;
|
|
8029
|
+
}
|
|
8030
|
+
return {
|
|
8031
|
+
...message,
|
|
8032
|
+
content: message.content.filter((part) => part.type !== "reasoning")
|
|
8033
|
+
};
|
|
8034
|
+
});
|
|
8035
|
+
}
|
|
8036
|
+
if (toolCalls === "none") {
|
|
8037
|
+
toolCalls = [];
|
|
8038
|
+
} else if (toolCalls === "all") {
|
|
8039
|
+
toolCalls = [{ type: "all" }];
|
|
8040
|
+
} else if (toolCalls === "before-last-message") {
|
|
8041
|
+
toolCalls = [{ type: "before-last-message" }];
|
|
8042
|
+
} else if (typeof toolCalls === "string") {
|
|
8043
|
+
toolCalls = [{ type: toolCalls }];
|
|
8044
|
+
}
|
|
8045
|
+
for (const toolCall of toolCalls) {
|
|
8046
|
+
const keepLastMessagesCount = toolCall.type === "all" ? void 0 : toolCall.type === "before-last-message" ? 1 : Number(
|
|
8047
|
+
toolCall.type.slice("before-last-".length).slice(0, -"-messages".length)
|
|
8048
|
+
);
|
|
8049
|
+
const keptToolCallIds = /* @__PURE__ */ new Set();
|
|
8050
|
+
const keptApprovalIds = /* @__PURE__ */ new Set();
|
|
8051
|
+
if (keepLastMessagesCount != null) {
|
|
8052
|
+
for (const message of messages.slice(0, -keepLastMessagesCount)) {
|
|
8053
|
+
if ((message.role === "assistant" || message.role === "tool") && typeof message.content !== "string") {
|
|
8054
|
+
for (const part of message.content) {
|
|
8055
|
+
if (part.type === "tool-call" || part.type === "tool-result") {
|
|
8056
|
+
keptToolCallIds.add(part.toolCallId);
|
|
8057
|
+
}
|
|
8058
|
+
}
|
|
8059
|
+
}
|
|
8060
|
+
}
|
|
8061
|
+
}
|
|
8062
|
+
messages = messages.map((message, messageIndex) => {
|
|
8063
|
+
if (message.role !== "assistant" && message.role !== "tool" || typeof message.content === "string" || keepLastMessagesCount && messageIndex >= messages.length - keepLastMessagesCount) {
|
|
8064
|
+
return message;
|
|
8065
|
+
}
|
|
8066
|
+
const toolCallIdToToolName = {};
|
|
8067
|
+
return {
|
|
8068
|
+
...message,
|
|
8069
|
+
content: message.content.filter((part) => {
|
|
8070
|
+
if (part.type !== "tool-call" && part.type !== "tool-result") {
|
|
8071
|
+
return true;
|
|
8072
|
+
}
|
|
8073
|
+
if (part.type === "tool-call") {
|
|
8074
|
+
toolCallIdToToolName[part.toolCallId] = part.toolName;
|
|
8075
|
+
}
|
|
8076
|
+
if ((part.type === "tool-call" || part.type === "tool-result") && keptToolCallIds.has(part.toolCallId)) {
|
|
8077
|
+
return true;
|
|
8078
|
+
}
|
|
8079
|
+
return toolCall.tools != null && !toolCall.tools.includes(part.toolName);
|
|
8080
|
+
})
|
|
8081
|
+
};
|
|
8082
|
+
});
|
|
8083
|
+
}
|
|
8084
|
+
if (emptyMessages === "remove") {
|
|
8085
|
+
messages = messages.filter((message) => message.content.length > 0);
|
|
8086
|
+
}
|
|
8087
|
+
return messages;
|
|
8088
|
+
}
|
|
8089
|
+
|
|
8018
8090
|
// src/generate-text/smooth-stream.ts
|
|
8019
8091
|
import { delay as originalDelay } from "@ai-sdk/provider-utils";
|
|
8020
8092
|
import { InvalidArgumentError as InvalidArgumentError2 } from "@ai-sdk/provider";
|
|
@@ -10540,6 +10612,7 @@ export {
|
|
|
10540
10612
|
parsePartialJson,
|
|
10541
10613
|
pipeTextStreamToResponse,
|
|
10542
10614
|
pipeUIMessageStreamToResponse,
|
|
10615
|
+
pruneMessages,
|
|
10543
10616
|
readUIMessageStream,
|
|
10544
10617
|
safeValidateUIMessages,
|
|
10545
10618
|
simulateReadableStream,
|