ai 3.4.25 → 3.4.27
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 +14 -11
- package/dist/index.d.ts +14 -11
- package/dist/index.js +332 -265
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +313 -246
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/rsc/dist/index.d.ts +9 -1
- package/rsc/dist/rsc-server.d.mts +9 -1
- package/rsc/dist/rsc-server.mjs +313 -69
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -81,7 +81,7 @@ function getMutableAIState(...args) {
|
|
81
81
|
store.mutationDeltaResolve = resolve;
|
82
82
|
}
|
83
83
|
function doUpdate(newState, done) {
|
84
|
-
var
|
84
|
+
var _a9, _b;
|
85
85
|
if (args.length > 0) {
|
86
86
|
if (typeof store.currentState !== "object") {
|
87
87
|
const key = args[0];
|
@@ -105,7 +105,7 @@ function getMutableAIState(...args) {
|
|
105
105
|
store.currentState = newState;
|
106
106
|
}
|
107
107
|
}
|
108
|
-
(_b = (
|
108
|
+
(_b = (_a9 = store.options).onSetAIState) == null ? void 0 : _b.call(_a9, {
|
109
109
|
key: args.length > 0 ? args[0] : void 0,
|
110
110
|
state: store.currentState,
|
111
111
|
done
|
@@ -172,20 +172,20 @@ function createAI({
|
|
172
172
|
onGetUIState
|
173
173
|
}) {
|
174
174
|
const wrappedActions = {};
|
175
|
-
for (const
|
176
|
-
wrappedActions[
|
175
|
+
for (const name9 in actions) {
|
176
|
+
wrappedActions[name9] = wrapAction(actions[name9], {
|
177
177
|
onSetAIState
|
178
178
|
});
|
179
179
|
}
|
180
180
|
const wrappedSyncUIState = onGetUIState ? wrapAction(onGetUIState, {}) : void 0;
|
181
181
|
const AI = async (props) => {
|
182
|
-
var
|
182
|
+
var _a9, _b;
|
183
183
|
if ("useState" in React) {
|
184
184
|
throw new Error(
|
185
185
|
"This component can only be used inside Server Components."
|
186
186
|
);
|
187
187
|
}
|
188
|
-
let uiState = (
|
188
|
+
let uiState = (_a9 = props.initialUIState) != null ? _a9 : initialUIState;
|
189
189
|
let aiState = (_b = props.initialAIState) != null ? _b : initialAIState;
|
190
190
|
let aiStateDelta = void 0;
|
191
191
|
if (wrappedSyncUIState) {
|
@@ -263,7 +263,7 @@ async function download({
|
|
263
263
|
url,
|
264
264
|
fetchImplementation = fetch
|
265
265
|
}) {
|
266
|
-
var
|
266
|
+
var _a9;
|
267
267
|
const urlText = url.toString();
|
268
268
|
try {
|
269
269
|
const response = await fetchImplementation(urlText);
|
@@ -276,7 +276,7 @@ async function download({
|
|
276
276
|
}
|
277
277
|
return {
|
278
278
|
data: new Uint8Array(await response.arrayBuffer()),
|
279
|
-
mimeType: (
|
279
|
+
mimeType: (_a9 = response.headers.get("content-type")) != null ? _a9 : void 0
|
280
280
|
};
|
281
281
|
} catch (error) {
|
282
282
|
if (DownloadError.isInstance(error)) {
|
@@ -357,8 +357,8 @@ var dataContentSchema = z.union([
|
|
357
357
|
z.custom(
|
358
358
|
// Buffer might not be available in some environments such as CloudFlare:
|
359
359
|
(value) => {
|
360
|
-
var
|
361
|
-
return (_b = (
|
360
|
+
var _a9, _b;
|
361
|
+
return (_b = (_a9 = globalThis.Buffer) == null ? void 0 : _a9.isBuffer(value)) != null ? _b : false;
|
362
362
|
},
|
363
363
|
{ message: "Must be a Buffer" }
|
364
364
|
)
|
@@ -392,6 +392,13 @@ function convertDataContentToUint8Array(content) {
|
|
392
392
|
}
|
393
393
|
throw new InvalidDataContentError({ content });
|
394
394
|
}
|
395
|
+
function convertUint8ArrayToText(uint8Array) {
|
396
|
+
try {
|
397
|
+
return new TextDecoder().decode(uint8Array);
|
398
|
+
} catch (error) {
|
399
|
+
throw new Error("Error decoding Uint8Array to text");
|
400
|
+
}
|
401
|
+
}
|
395
402
|
|
396
403
|
// core/prompt/invalid-message-role-error.ts
|
397
404
|
import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
|
@@ -805,24 +812,24 @@ function prepareToolsAndToolChoice({
|
|
805
812
|
};
|
806
813
|
}
|
807
814
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
808
|
-
([
|
815
|
+
([name9]) => activeTools.includes(name9)
|
809
816
|
) : Object.entries(tools);
|
810
817
|
return {
|
811
|
-
tools: filteredTools.map(([
|
818
|
+
tools: filteredTools.map(([name9, tool]) => {
|
812
819
|
const toolType = tool.type;
|
813
820
|
switch (toolType) {
|
814
821
|
case void 0:
|
815
822
|
case "function":
|
816
823
|
return {
|
817
824
|
type: "function",
|
818
|
-
name:
|
825
|
+
name: name9,
|
819
826
|
description: tool.description,
|
820
827
|
parameters: asSchema(tool.parameters).jsonSchema
|
821
828
|
};
|
822
829
|
case "provider-defined":
|
823
830
|
return {
|
824
831
|
type: "provider-defined",
|
825
|
-
name:
|
832
|
+
name: name9,
|
826
833
|
id: tool.id,
|
827
834
|
args: tool.args
|
828
835
|
};
|
@@ -950,8 +957,232 @@ var coreMessageSchema = z6.union([
|
|
950
957
|
coreToolMessageSchema
|
951
958
|
]);
|
952
959
|
|
960
|
+
// core/prompt/detect-prompt-type.ts
|
961
|
+
function detectPromptType(prompt) {
|
962
|
+
if (!Array.isArray(prompt)) {
|
963
|
+
return "other";
|
964
|
+
}
|
965
|
+
if (prompt.length === 0) {
|
966
|
+
return "messages";
|
967
|
+
}
|
968
|
+
const characteristics = prompt.map(detectSingleMessageCharacteristics);
|
969
|
+
if (characteristics.some((c) => c === "has-ui-specific-parts")) {
|
970
|
+
return "ui-messages";
|
971
|
+
} else if (characteristics.every(
|
972
|
+
(c) => c === "has-core-specific-parts" || c === "message"
|
973
|
+
)) {
|
974
|
+
return "messages";
|
975
|
+
} else {
|
976
|
+
return "other";
|
977
|
+
}
|
978
|
+
}
|
979
|
+
function detectSingleMessageCharacteristics(message) {
|
980
|
+
if (typeof message === "object" && message !== null && (message.role === "function" || // UI-only role
|
981
|
+
message.role === "data" || // UI-only role
|
982
|
+
"toolInvocations" in message || // UI-specific field
|
983
|
+
"experimental_attachments" in message)) {
|
984
|
+
return "has-ui-specific-parts";
|
985
|
+
} else if (typeof message === "object" && message !== null && "content" in message && (Array.isArray(message.content) || // Core messages can have array content
|
986
|
+
"experimental_providerMetadata" in message)) {
|
987
|
+
return "has-core-specific-parts";
|
988
|
+
} else if (typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.content === "string" && ["system", "user", "assistant", "tool"].includes(message.role)) {
|
989
|
+
return "message";
|
990
|
+
} else {
|
991
|
+
return "other";
|
992
|
+
}
|
993
|
+
}
|
994
|
+
|
995
|
+
// core/prompt/attachments-to-parts.ts
|
996
|
+
function attachmentsToParts(attachments) {
|
997
|
+
var _a9, _b, _c;
|
998
|
+
const parts = [];
|
999
|
+
for (const attachment of attachments) {
|
1000
|
+
let url;
|
1001
|
+
try {
|
1002
|
+
url = new URL(attachment.url);
|
1003
|
+
} catch (error) {
|
1004
|
+
throw new Error(`Invalid URL: ${attachment.url}`);
|
1005
|
+
}
|
1006
|
+
switch (url.protocol) {
|
1007
|
+
case "http:":
|
1008
|
+
case "https:": {
|
1009
|
+
if ((_a9 = attachment.contentType) == null ? void 0 : _a9.startsWith("image/")) {
|
1010
|
+
parts.push({ type: "image", image: url });
|
1011
|
+
} else {
|
1012
|
+
if (!attachment.contentType) {
|
1013
|
+
throw new Error(
|
1014
|
+
"If the attachment is not an image, it must specify a content type"
|
1015
|
+
);
|
1016
|
+
}
|
1017
|
+
parts.push({
|
1018
|
+
type: "file",
|
1019
|
+
data: url,
|
1020
|
+
mimeType: attachment.contentType
|
1021
|
+
});
|
1022
|
+
}
|
1023
|
+
break;
|
1024
|
+
}
|
1025
|
+
case "data:": {
|
1026
|
+
let header;
|
1027
|
+
let base64Content;
|
1028
|
+
let mimeType;
|
1029
|
+
try {
|
1030
|
+
[header, base64Content] = attachment.url.split(",");
|
1031
|
+
mimeType = header.split(";")[0].split(":")[1];
|
1032
|
+
} catch (error) {
|
1033
|
+
throw new Error(`Error processing data URL: ${attachment.url}`);
|
1034
|
+
}
|
1035
|
+
if (mimeType == null || base64Content == null) {
|
1036
|
+
throw new Error(`Invalid data URL format: ${attachment.url}`);
|
1037
|
+
}
|
1038
|
+
if ((_b = attachment.contentType) == null ? void 0 : _b.startsWith("image/")) {
|
1039
|
+
parts.push({
|
1040
|
+
type: "image",
|
1041
|
+
image: convertDataContentToUint8Array(base64Content)
|
1042
|
+
});
|
1043
|
+
} else if ((_c = attachment.contentType) == null ? void 0 : _c.startsWith("text/")) {
|
1044
|
+
parts.push({
|
1045
|
+
type: "text",
|
1046
|
+
text: convertUint8ArrayToText(
|
1047
|
+
convertDataContentToUint8Array(base64Content)
|
1048
|
+
)
|
1049
|
+
});
|
1050
|
+
} else {
|
1051
|
+
if (!attachment.contentType) {
|
1052
|
+
throw new Error(
|
1053
|
+
"If the attachment is not an image or text, it must specify a content type"
|
1054
|
+
);
|
1055
|
+
}
|
1056
|
+
parts.push({
|
1057
|
+
type: "file",
|
1058
|
+
data: base64Content,
|
1059
|
+
mimeType: attachment.contentType
|
1060
|
+
});
|
1061
|
+
}
|
1062
|
+
break;
|
1063
|
+
}
|
1064
|
+
default: {
|
1065
|
+
throw new Error(`Unsupported URL protocol: ${url.protocol}`);
|
1066
|
+
}
|
1067
|
+
}
|
1068
|
+
}
|
1069
|
+
return parts;
|
1070
|
+
}
|
1071
|
+
|
1072
|
+
// core/prompt/message-conversion-error.ts
|
1073
|
+
import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
|
1074
|
+
var name5 = "AI_MessageConversionError";
|
1075
|
+
var marker5 = `vercel.ai.error.${name5}`;
|
1076
|
+
var symbol5 = Symbol.for(marker5);
|
1077
|
+
var _a5;
|
1078
|
+
var MessageConversionError = class extends AISDKError5 {
|
1079
|
+
constructor({
|
1080
|
+
originalMessage,
|
1081
|
+
message
|
1082
|
+
}) {
|
1083
|
+
super({ name: name5, message });
|
1084
|
+
this[_a5] = true;
|
1085
|
+
this.originalMessage = originalMessage;
|
1086
|
+
}
|
1087
|
+
static isInstance(error) {
|
1088
|
+
return AISDKError5.hasMarker(error, marker5);
|
1089
|
+
}
|
1090
|
+
};
|
1091
|
+
_a5 = symbol5;
|
1092
|
+
|
1093
|
+
// core/prompt/convert-to-core-messages.ts
|
1094
|
+
function convertToCoreMessages(messages, options) {
|
1095
|
+
var _a9;
|
1096
|
+
const tools = (_a9 = options == null ? void 0 : options.tools) != null ? _a9 : {};
|
1097
|
+
const coreMessages = [];
|
1098
|
+
for (const message of messages) {
|
1099
|
+
const { role, content, toolInvocations, experimental_attachments } = message;
|
1100
|
+
switch (role) {
|
1101
|
+
case "system": {
|
1102
|
+
coreMessages.push({
|
1103
|
+
role: "system",
|
1104
|
+
content
|
1105
|
+
});
|
1106
|
+
break;
|
1107
|
+
}
|
1108
|
+
case "user": {
|
1109
|
+
coreMessages.push({
|
1110
|
+
role: "user",
|
1111
|
+
content: experimental_attachments ? [
|
1112
|
+
{ type: "text", text: content },
|
1113
|
+
...attachmentsToParts(experimental_attachments)
|
1114
|
+
] : content
|
1115
|
+
});
|
1116
|
+
break;
|
1117
|
+
}
|
1118
|
+
case "assistant": {
|
1119
|
+
if (toolInvocations == null) {
|
1120
|
+
coreMessages.push({ role: "assistant", content });
|
1121
|
+
break;
|
1122
|
+
}
|
1123
|
+
coreMessages.push({
|
1124
|
+
role: "assistant",
|
1125
|
+
content: [
|
1126
|
+
{ type: "text", text: content },
|
1127
|
+
...toolInvocations.map(
|
1128
|
+
({ toolCallId, toolName, args }) => ({
|
1129
|
+
type: "tool-call",
|
1130
|
+
toolCallId,
|
1131
|
+
toolName,
|
1132
|
+
args
|
1133
|
+
})
|
1134
|
+
)
|
1135
|
+
]
|
1136
|
+
});
|
1137
|
+
coreMessages.push({
|
1138
|
+
role: "tool",
|
1139
|
+
content: toolInvocations.map((toolInvocation) => {
|
1140
|
+
if (!("result" in toolInvocation)) {
|
1141
|
+
throw new MessageConversionError({
|
1142
|
+
originalMessage: message,
|
1143
|
+
message: "ToolInvocation must have a result: " + JSON.stringify(toolInvocation)
|
1144
|
+
});
|
1145
|
+
}
|
1146
|
+
const { toolCallId, toolName, result } = toolInvocation;
|
1147
|
+
const tool = tools[toolName];
|
1148
|
+
return (tool == null ? void 0 : tool.experimental_toToolResultContent) != null ? {
|
1149
|
+
type: "tool-result",
|
1150
|
+
toolCallId,
|
1151
|
+
toolName,
|
1152
|
+
result: tool.experimental_toToolResultContent(result),
|
1153
|
+
experimental_content: tool.experimental_toToolResultContent(result)
|
1154
|
+
} : {
|
1155
|
+
type: "tool-result",
|
1156
|
+
toolCallId,
|
1157
|
+
toolName,
|
1158
|
+
result
|
1159
|
+
};
|
1160
|
+
})
|
1161
|
+
});
|
1162
|
+
break;
|
1163
|
+
}
|
1164
|
+
case "function":
|
1165
|
+
case "data":
|
1166
|
+
case "tool": {
|
1167
|
+
break;
|
1168
|
+
}
|
1169
|
+
default: {
|
1170
|
+
const _exhaustiveCheck = role;
|
1171
|
+
throw new MessageConversionError({
|
1172
|
+
originalMessage: message,
|
1173
|
+
message: `Unsupported role: ${_exhaustiveCheck}`
|
1174
|
+
});
|
1175
|
+
}
|
1176
|
+
}
|
1177
|
+
}
|
1178
|
+
return coreMessages;
|
1179
|
+
}
|
1180
|
+
|
953
1181
|
// core/prompt/standardize-prompt.ts
|
954
|
-
function standardizePrompt(
|
1182
|
+
function standardizePrompt({
|
1183
|
+
prompt,
|
1184
|
+
tools
|
1185
|
+
}) {
|
955
1186
|
if (prompt.prompt == null && prompt.messages == null) {
|
956
1187
|
throw new InvalidPromptError({
|
957
1188
|
prompt,
|
@@ -989,21 +1220,30 @@ function standardizePrompt(prompt) {
|
|
989
1220
|
};
|
990
1221
|
}
|
991
1222
|
if (prompt.messages != null) {
|
1223
|
+
const promptType = detectPromptType(prompt.messages);
|
1224
|
+
if (promptType === "other") {
|
1225
|
+
throw new InvalidPromptError({
|
1226
|
+
prompt,
|
1227
|
+
message: "messages must be an array of CoreMessage or UIMessage"
|
1228
|
+
});
|
1229
|
+
}
|
1230
|
+
const messages = promptType === "ui-messages" ? convertToCoreMessages(prompt.messages, {
|
1231
|
+
tools
|
1232
|
+
}) : prompt.messages;
|
992
1233
|
const validationResult = safeValidateTypes({
|
993
|
-
value:
|
1234
|
+
value: messages,
|
994
1235
|
schema: z7.array(coreMessageSchema)
|
995
1236
|
});
|
996
1237
|
if (!validationResult.success) {
|
997
1238
|
throw new InvalidPromptError({
|
998
1239
|
prompt,
|
999
|
-
message: "messages must be an array of CoreMessage",
|
1240
|
+
message: "messages must be an array of CoreMessage or UIMessage",
|
1000
1241
|
cause: validationResult.error
|
1001
1242
|
});
|
1002
1243
|
}
|
1003
1244
|
return {
|
1004
1245
|
type: "messages",
|
1005
|
-
messages
|
1006
|
-
// only possible case bc of checks above
|
1246
|
+
messages,
|
1007
1247
|
system: prompt.system
|
1008
1248
|
};
|
1009
1249
|
}
|
@@ -1020,12 +1260,12 @@ function calculateLanguageModelUsage(usage) {
|
|
1020
1260
|
}
|
1021
1261
|
|
1022
1262
|
// errors/invalid-tool-arguments-error.ts
|
1023
|
-
import { AISDKError as
|
1024
|
-
var
|
1025
|
-
var
|
1026
|
-
var
|
1027
|
-
var
|
1028
|
-
var InvalidToolArgumentsError = class extends
|
1263
|
+
import { AISDKError as AISDKError6, getErrorMessage } from "@ai-sdk/provider";
|
1264
|
+
var name6 = "AI_InvalidToolArgumentsError";
|
1265
|
+
var marker6 = `vercel.ai.error.${name6}`;
|
1266
|
+
var symbol6 = Symbol.for(marker6);
|
1267
|
+
var _a6;
|
1268
|
+
var InvalidToolArgumentsError = class extends AISDKError6 {
|
1029
1269
|
constructor({
|
1030
1270
|
toolArgs,
|
1031
1271
|
toolName,
|
@@ -1034,19 +1274,19 @@ var InvalidToolArgumentsError = class extends AISDKError5 {
|
|
1034
1274
|
cause
|
1035
1275
|
)}`
|
1036
1276
|
}) {
|
1037
|
-
super({ name:
|
1038
|
-
this[
|
1277
|
+
super({ name: name6, message, cause });
|
1278
|
+
this[_a6] = true;
|
1039
1279
|
this.toolArgs = toolArgs;
|
1040
1280
|
this.toolName = toolName;
|
1041
1281
|
}
|
1042
1282
|
static isInstance(error) {
|
1043
|
-
return
|
1283
|
+
return AISDKError6.hasMarker(error, marker6);
|
1044
1284
|
}
|
1045
1285
|
/**
|
1046
1286
|
* @deprecated use `isInstance` instead
|
1047
1287
|
*/
|
1048
1288
|
static isInvalidToolArgumentsError(error) {
|
1049
|
-
return error instanceof Error && error.name ===
|
1289
|
+
return error instanceof Error && error.name === name6 && typeof error.toolName === "string" && typeof error.toolArgs === "string";
|
1050
1290
|
}
|
1051
1291
|
/**
|
1052
1292
|
* @deprecated Do not use this method. It will be removed in the next major version.
|
@@ -1062,33 +1302,33 @@ var InvalidToolArgumentsError = class extends AISDKError5 {
|
|
1062
1302
|
};
|
1063
1303
|
}
|
1064
1304
|
};
|
1065
|
-
|
1305
|
+
_a6 = symbol6;
|
1066
1306
|
|
1067
1307
|
// errors/no-such-tool-error.ts
|
1068
|
-
import { AISDKError as
|
1069
|
-
var
|
1070
|
-
var
|
1071
|
-
var
|
1072
|
-
var
|
1073
|
-
var NoSuchToolError = class extends
|
1308
|
+
import { AISDKError as AISDKError7 } from "@ai-sdk/provider";
|
1309
|
+
var name7 = "AI_NoSuchToolError";
|
1310
|
+
var marker7 = `vercel.ai.error.${name7}`;
|
1311
|
+
var symbol7 = Symbol.for(marker7);
|
1312
|
+
var _a7;
|
1313
|
+
var NoSuchToolError = class extends AISDKError7 {
|
1074
1314
|
constructor({
|
1075
1315
|
toolName,
|
1076
1316
|
availableTools = void 0,
|
1077
1317
|
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
1078
1318
|
}) {
|
1079
|
-
super({ name:
|
1080
|
-
this[
|
1319
|
+
super({ name: name7, message });
|
1320
|
+
this[_a7] = true;
|
1081
1321
|
this.toolName = toolName;
|
1082
1322
|
this.availableTools = availableTools;
|
1083
1323
|
}
|
1084
1324
|
static isInstance(error) {
|
1085
|
-
return
|
1325
|
+
return AISDKError7.hasMarker(error, marker7);
|
1086
1326
|
}
|
1087
1327
|
/**
|
1088
1328
|
* @deprecated use `isInstance` instead
|
1089
1329
|
*/
|
1090
1330
|
static isNoSuchToolError(error) {
|
1091
|
-
return error instanceof Error && error.name ===
|
1331
|
+
return error instanceof Error && error.name === name7 && "toolName" in error && error.toolName != void 0 && typeof error.name === "string";
|
1092
1332
|
}
|
1093
1333
|
/**
|
1094
1334
|
* @deprecated Do not use this method. It will be removed in the next major version.
|
@@ -1103,7 +1343,7 @@ var NoSuchToolError = class extends AISDKError6 {
|
|
1103
1343
|
};
|
1104
1344
|
}
|
1105
1345
|
};
|
1106
|
-
|
1346
|
+
_a7 = symbol7;
|
1107
1347
|
|
1108
1348
|
// util/is-async-generator.ts
|
1109
1349
|
function isAsyncGenerator(value) {
|
@@ -1125,31 +1365,31 @@ async function delay(delayInMs) {
|
|
1125
1365
|
}
|
1126
1366
|
|
1127
1367
|
// util/retry-error.ts
|
1128
|
-
import { AISDKError as
|
1129
|
-
var
|
1130
|
-
var
|
1131
|
-
var
|
1132
|
-
var
|
1133
|
-
var RetryError = class extends
|
1368
|
+
import { AISDKError as AISDKError8 } from "@ai-sdk/provider";
|
1369
|
+
var name8 = "AI_RetryError";
|
1370
|
+
var marker8 = `vercel.ai.error.${name8}`;
|
1371
|
+
var symbol8 = Symbol.for(marker8);
|
1372
|
+
var _a8;
|
1373
|
+
var RetryError = class extends AISDKError8 {
|
1134
1374
|
constructor({
|
1135
1375
|
message,
|
1136
1376
|
reason,
|
1137
1377
|
errors
|
1138
1378
|
}) {
|
1139
|
-
super({ name:
|
1140
|
-
this[
|
1379
|
+
super({ name: name8, message });
|
1380
|
+
this[_a8] = true;
|
1141
1381
|
this.reason = reason;
|
1142
1382
|
this.errors = errors;
|
1143
1383
|
this.lastError = errors[errors.length - 1];
|
1144
1384
|
}
|
1145
1385
|
static isInstance(error) {
|
1146
|
-
return
|
1386
|
+
return AISDKError8.hasMarker(error, marker8);
|
1147
1387
|
}
|
1148
1388
|
/**
|
1149
1389
|
* @deprecated use `isInstance` instead
|
1150
1390
|
*/
|
1151
1391
|
static isRetryError(error) {
|
1152
|
-
return error instanceof Error && error.name ===
|
1392
|
+
return error instanceof Error && error.name === name8 && typeof error.reason === "string" && Array.isArray(error.errors);
|
1153
1393
|
}
|
1154
1394
|
/**
|
1155
1395
|
* @deprecated Do not use this method. It will be removed in the next major version.
|
@@ -1164,7 +1404,7 @@ var RetryError = class extends AISDKError7 {
|
|
1164
1404
|
};
|
1165
1405
|
}
|
1166
1406
|
};
|
1167
|
-
|
1407
|
+
_a8 = symbol8;
|
1168
1408
|
|
1169
1409
|
// util/retry-with-exponential-backoff.ts
|
1170
1410
|
var retryWithExponentialBackoff = ({
|
@@ -1362,10 +1602,10 @@ async function streamUI({
|
|
1362
1602
|
);
|
1363
1603
|
}
|
1364
1604
|
if (tools) {
|
1365
|
-
for (const [
|
1605
|
+
for (const [name9, tool] of Object.entries(tools)) {
|
1366
1606
|
if ("render" in tool) {
|
1367
1607
|
throw new Error(
|
1368
|
-
"Tool definition in `streamUI` should not have `render` property. Use `generate` instead. Found in tool: " +
|
1608
|
+
"Tool definition in `streamUI` should not have `render` property. Use `generate` instead. Found in tool: " + name9
|
1369
1609
|
);
|
1370
1610
|
}
|
1371
1611
|
}
|
@@ -1408,7 +1648,11 @@ async function streamUI({
|
|
1408
1648
|
renderFinished.resolve(void 0);
|
1409
1649
|
}
|
1410
1650
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1411
|
-
const validatedPrompt = standardizePrompt({
|
1651
|
+
const validatedPrompt = standardizePrompt({
|
1652
|
+
prompt: { system, prompt, messages },
|
1653
|
+
tools: void 0
|
1654
|
+
// streamUI tools don't support multi-modal tool result conversion
|
1655
|
+
});
|
1412
1656
|
const result = await retry(
|
1413
1657
|
async () => model.doStream({
|
1414
1658
|
mode: {
|
@@ -1654,8 +1898,8 @@ function readableFromAsyncIterable(iterable) {
|
|
1654
1898
|
controller.enqueue(value);
|
1655
1899
|
},
|
1656
1900
|
async cancel(reason) {
|
1657
|
-
var
|
1658
|
-
await ((
|
1901
|
+
var _a9;
|
1902
|
+
await ((_a9 = it.return) == null ? void 0 : _a9.call(it, reason));
|
1659
1903
|
}
|
1660
1904
|
});
|
1661
1905
|
}
|
@@ -1694,10 +1938,10 @@ async function* streamable(stream) {
|
|
1694
1938
|
model: chunk.model,
|
1695
1939
|
// not exposed by Azure API
|
1696
1940
|
choices: chunk.choices.map((choice) => {
|
1697
|
-
var
|
1941
|
+
var _a9, _b, _c, _d, _e, _f, _g;
|
1698
1942
|
return {
|
1699
1943
|
delta: {
|
1700
|
-
content: (
|
1944
|
+
content: (_a9 = choice.delta) == null ? void 0 : _a9.content,
|
1701
1945
|
function_call: (_b = choice.delta) == null ? void 0 : _b.functionCall,
|
1702
1946
|
role: (_c = choice.delta) == null ? void 0 : _c.role,
|
1703
1947
|
tool_calls: ((_e = (_d = choice.delta) == null ? void 0 : _d.toolCalls) == null ? void 0 : _e.length) ? (_g = (_f = choice.delta) == null ? void 0 : _f.toolCalls) == null ? void 0 : _g.map((toolCall, index) => ({
|
@@ -1722,9 +1966,9 @@ function chunkToText() {
|
|
1722
1966
|
const trimStartOfStream = trimStartOfStreamHelper();
|
1723
1967
|
let isFunctionStreamingIn;
|
1724
1968
|
return (json) => {
|
1725
|
-
var
|
1969
|
+
var _a9, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
1726
1970
|
if (isChatCompletionChunk(json)) {
|
1727
|
-
const delta = (
|
1971
|
+
const delta = (_a9 = json.choices[0]) == null ? void 0 : _a9.delta;
|
1728
1972
|
if ((_b = delta.function_call) == null ? void 0 : _b.name) {
|
1729
1973
|
isFunctionStreamingIn = true;
|
1730
1974
|
return {
|
@@ -2010,20 +2254,20 @@ function render(options) {
|
|
2010
2254
|
const ui = createStreamableUI(options.initial);
|
2011
2255
|
const text = options.text ? options.text : ({ content }) => content;
|
2012
2256
|
const functions = options.functions ? Object.entries(options.functions).map(
|
2013
|
-
([
|
2257
|
+
([name9, { description, parameters }]) => {
|
2014
2258
|
return {
|
2015
|
-
name:
|
2259
|
+
name: name9,
|
2016
2260
|
description,
|
2017
2261
|
parameters: zodToJsonSchema(parameters)
|
2018
2262
|
};
|
2019
2263
|
}
|
2020
2264
|
) : void 0;
|
2021
2265
|
const tools = options.tools ? Object.entries(options.tools).map(
|
2022
|
-
([
|
2266
|
+
([name9, { description, parameters }]) => {
|
2023
2267
|
return {
|
2024
2268
|
type: "function",
|
2025
2269
|
function: {
|
2026
|
-
name:
|
2270
|
+
name: name9,
|
2027
2271
|
description,
|
2028
2272
|
parameters: zodToJsonSchema(parameters)
|
2029
2273
|
}
|
@@ -2093,23 +2337,23 @@ function render(options) {
|
|
2093
2337
|
{
|
2094
2338
|
...functions ? {
|
2095
2339
|
async experimental_onFunctionCall(functionCallPayload) {
|
2096
|
-
var
|
2340
|
+
var _a9, _b;
|
2097
2341
|
hasFunction = true;
|
2098
2342
|
handleRender(
|
2099
2343
|
functionCallPayload.arguments,
|
2100
|
-
(_b = (
|
2344
|
+
(_b = (_a9 = options.functions) == null ? void 0 : _a9[functionCallPayload.name]) == null ? void 0 : _b.render,
|
2101
2345
|
ui
|
2102
2346
|
);
|
2103
2347
|
}
|
2104
2348
|
} : {},
|
2105
2349
|
...tools ? {
|
2106
2350
|
async experimental_onToolCall(toolCallPayload) {
|
2107
|
-
var
|
2351
|
+
var _a9, _b;
|
2108
2352
|
hasFunction = true;
|
2109
2353
|
for (const tool of toolCallPayload.tools) {
|
2110
2354
|
handleRender(
|
2111
2355
|
tool.func.arguments,
|
2112
|
-
(_b = (
|
2356
|
+
(_b = (_a9 = options.tools) == null ? void 0 : _a9[tool.func.name]) == null ? void 0 : _b.render,
|
2113
2357
|
ui
|
2114
2358
|
);
|
2115
2359
|
}
|