ai 3.4.25 → 3.4.26
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 +6 -0
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +23 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
@@ -1331,7 +1331,9 @@ type ConvertibleMessage = {
|
|
1331
1331
|
Converts an array of messages from useChat into an array of CoreMessages that can be used
|
1332
1332
|
with the AI core functions (e.g. `streamText`).
|
1333
1333
|
*/
|
1334
|
-
declare function convertToCoreMessages(messages: Array<ConvertibleMessage
|
1334
|
+
declare function convertToCoreMessages<TOOLS extends Record<string, CoreTool> = never>(messages: Array<ConvertibleMessage>, options?: {
|
1335
|
+
tools: TOOLS;
|
1336
|
+
}): CoreMessage[];
|
1335
1337
|
|
1336
1338
|
/**
|
1337
1339
|
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
package/dist/index.d.ts
CHANGED
@@ -1331,7 +1331,9 @@ type ConvertibleMessage = {
|
|
1331
1331
|
Converts an array of messages from useChat into an array of CoreMessages that can be used
|
1332
1332
|
with the AI core functions (e.g. `streamText`).
|
1333
1333
|
*/
|
1334
|
-
declare function convertToCoreMessages(messages: Array<ConvertibleMessage
|
1334
|
+
declare function convertToCoreMessages<TOOLS extends Record<string, CoreTool> = never>(messages: Array<ConvertibleMessage>, options?: {
|
1335
|
+
tools: TOOLS;
|
1336
|
+
}): CoreMessage[];
|
1335
1337
|
|
1336
1338
|
/**
|
1337
1339
|
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
package/dist/index.js
CHANGED
@@ -4783,7 +4783,9 @@ function attachmentsToParts(attachments) {
|
|
4783
4783
|
}
|
4784
4784
|
|
4785
4785
|
// core/prompt/convert-to-core-messages.ts
|
4786
|
-
function convertToCoreMessages(messages) {
|
4786
|
+
function convertToCoreMessages(messages, options) {
|
4787
|
+
var _a11;
|
4788
|
+
const tools = (_a11 = options == null ? void 0 : options.tools) != null ? _a11 : {};
|
4787
4789
|
const coreMessages = [];
|
4788
4790
|
for (const message of messages) {
|
4789
4791
|
const { role, content, toolInvocations, experimental_attachments } = message;
|
@@ -4814,29 +4816,37 @@ function convertToCoreMessages(messages) {
|
|
4814
4816
|
role: "assistant",
|
4815
4817
|
content: [
|
4816
4818
|
{ type: "text", text: content },
|
4817
|
-
...toolInvocations.map(
|
4818
|
-
|
4819
|
-
|
4820
|
-
|
4821
|
-
|
4822
|
-
|
4819
|
+
...toolInvocations.map(
|
4820
|
+
({ toolCallId, toolName, args }) => ({
|
4821
|
+
type: "tool-call",
|
4822
|
+
toolCallId,
|
4823
|
+
toolName,
|
4824
|
+
args
|
4825
|
+
})
|
4826
|
+
)
|
4823
4827
|
]
|
4824
4828
|
});
|
4825
4829
|
coreMessages.push({
|
4826
4830
|
role: "tool",
|
4827
|
-
content: toolInvocations.map((
|
4828
|
-
if (!("result" in
|
4831
|
+
content: toolInvocations.map((toolInvocation) => {
|
4832
|
+
if (!("result" in toolInvocation)) {
|
4829
4833
|
throw new MessageConversionError({
|
4830
4834
|
originalMessage: message,
|
4831
|
-
message: "ToolInvocation must have a result: " + JSON.stringify(
|
4835
|
+
message: "ToolInvocation must have a result: " + JSON.stringify(toolInvocation)
|
4832
4836
|
});
|
4833
4837
|
}
|
4834
|
-
const { toolCallId, toolName,
|
4835
|
-
|
4838
|
+
const { toolCallId, toolName, result } = toolInvocation;
|
4839
|
+
const tool2 = tools[toolName];
|
4840
|
+
return (tool2 == null ? void 0 : tool2.experimental_toToolResultContent) != null ? {
|
4841
|
+
type: "tool-result",
|
4842
|
+
toolCallId,
|
4843
|
+
toolName,
|
4844
|
+
result: tool2.experimental_toToolResultContent(result),
|
4845
|
+
experimental_content: tool2.experimental_toToolResultContent(result)
|
4846
|
+
} : {
|
4836
4847
|
type: "tool-result",
|
4837
4848
|
toolCallId,
|
4838
4849
|
toolName,
|
4839
|
-
args,
|
4840
4850
|
result
|
4841
4851
|
};
|
4842
4852
|
})
|