ai 4.1.8 → 4.1.10
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 +16 -0
- package/dist/index.d.mts +85 -95
- package/dist/index.d.ts +85 -95
- package/dist/index.js +184 -180
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +182 -179
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/rsc/dist/index.d.ts +2 -2
- package/rsc/dist/rsc-server.d.mts +2 -2
- package/rsc/dist/rsc-server.mjs +144 -144
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/test/dist/index.d.mts +0 -3
- package/test/dist/index.d.ts +0 -3
- package/test/dist/index.js.map +1 -1
- package/test/dist/index.mjs.map +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ai",
|
3
|
-
"version": "4.1.
|
3
|
+
"version": "4.1.10",
|
4
4
|
"description": "AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"sideEffects": false,
|
@@ -41,9 +41,9 @@
|
|
41
41
|
},
|
42
42
|
"dependencies": {
|
43
43
|
"@ai-sdk/provider": "1.0.6",
|
44
|
-
"@ai-sdk/provider-utils": "2.1.
|
45
|
-
"@ai-sdk/react": "1.1.
|
46
|
-
"@ai-sdk/ui-utils": "1.1.
|
44
|
+
"@ai-sdk/provider-utils": "2.1.5",
|
45
|
+
"@ai-sdk/react": "1.1.6",
|
46
|
+
"@ai-sdk/ui-utils": "1.1.6",
|
47
47
|
"@opentelemetry/api": "1.9.0",
|
48
48
|
"jsondiffpatch": "0.6.0"
|
49
49
|
},
|
package/rsc/dist/index.d.ts
CHANGED
@@ -199,7 +199,7 @@ Tool choice for the generation. It supports the following settings:
|
|
199
199
|
- `none`: the model must not call tools
|
200
200
|
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
201
201
|
*/
|
202
|
-
type
|
202
|
+
type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
203
203
|
type: 'tool';
|
204
204
|
toolName: keyof TOOLS;
|
205
205
|
};
|
@@ -514,7 +514,7 @@ declare function streamUI<TOOLS extends {
|
|
514
514
|
/**
|
515
515
|
* The tool choice strategy. Default: 'auto'.
|
516
516
|
*/
|
517
|
-
toolChoice?:
|
517
|
+
toolChoice?: ToolChoice<TOOLS>;
|
518
518
|
text?: RenderText;
|
519
519
|
initial?: ReactNode;
|
520
520
|
/**
|
@@ -197,7 +197,7 @@ Tool choice for the generation. It supports the following settings:
|
|
197
197
|
- `none`: the model must not call tools
|
198
198
|
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
199
199
|
*/
|
200
|
-
type
|
200
|
+
type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
201
201
|
type: 'tool';
|
202
202
|
toolName: keyof TOOLS;
|
203
203
|
};
|
@@ -512,7 +512,7 @@ declare function streamUI<TOOLS extends {
|
|
512
512
|
/**
|
513
513
|
* The tool choice strategy. Default: 'auto'.
|
514
514
|
*/
|
515
|
-
toolChoice?:
|
515
|
+
toolChoice?: ToolChoice<TOOLS>;
|
516
516
|
text?: RenderText;
|
517
517
|
initial?: ReactNode;
|
518
518
|
/**
|
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -872,150 +872,6 @@ import { InvalidPromptError } from "@ai-sdk/provider";
|
|
872
872
|
import { safeValidateTypes } from "@ai-sdk/provider-utils";
|
873
873
|
import { z as z7 } from "zod";
|
874
874
|
|
875
|
-
// core/prompt/message.ts
|
876
|
-
import { z as z6 } from "zod";
|
877
|
-
|
878
|
-
// core/types/provider-metadata.ts
|
879
|
-
import { z as z3 } from "zod";
|
880
|
-
|
881
|
-
// core/types/json-value.ts
|
882
|
-
import { z as z2 } from "zod";
|
883
|
-
var jsonValueSchema = z2.lazy(
|
884
|
-
() => z2.union([
|
885
|
-
z2.null(),
|
886
|
-
z2.string(),
|
887
|
-
z2.number(),
|
888
|
-
z2.boolean(),
|
889
|
-
z2.record(z2.string(), jsonValueSchema),
|
890
|
-
z2.array(jsonValueSchema)
|
891
|
-
])
|
892
|
-
);
|
893
|
-
|
894
|
-
// core/types/provider-metadata.ts
|
895
|
-
var providerMetadataSchema = z3.record(
|
896
|
-
z3.string(),
|
897
|
-
z3.record(z3.string(), jsonValueSchema)
|
898
|
-
);
|
899
|
-
|
900
|
-
// core/prompt/content-part.ts
|
901
|
-
import { z as z5 } from "zod";
|
902
|
-
|
903
|
-
// core/prompt/tool-result-content.ts
|
904
|
-
import { z as z4 } from "zod";
|
905
|
-
var toolResultContentSchema = z4.array(
|
906
|
-
z4.union([
|
907
|
-
z4.object({ type: z4.literal("text"), text: z4.string() }),
|
908
|
-
z4.object({
|
909
|
-
type: z4.literal("image"),
|
910
|
-
data: z4.string(),
|
911
|
-
mimeType: z4.string().optional()
|
912
|
-
})
|
913
|
-
])
|
914
|
-
);
|
915
|
-
|
916
|
-
// core/prompt/content-part.ts
|
917
|
-
var textPartSchema = z5.object({
|
918
|
-
type: z5.literal("text"),
|
919
|
-
text: z5.string(),
|
920
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
921
|
-
});
|
922
|
-
var imagePartSchema = z5.object({
|
923
|
-
type: z5.literal("image"),
|
924
|
-
image: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
925
|
-
mimeType: z5.string().optional(),
|
926
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
927
|
-
});
|
928
|
-
var filePartSchema = z5.object({
|
929
|
-
type: z5.literal("file"),
|
930
|
-
data: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
931
|
-
mimeType: z5.string(),
|
932
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
933
|
-
});
|
934
|
-
var toolCallPartSchema = z5.object({
|
935
|
-
type: z5.literal("tool-call"),
|
936
|
-
toolCallId: z5.string(),
|
937
|
-
toolName: z5.string(),
|
938
|
-
args: z5.unknown()
|
939
|
-
});
|
940
|
-
var toolResultPartSchema = z5.object({
|
941
|
-
type: z5.literal("tool-result"),
|
942
|
-
toolCallId: z5.string(),
|
943
|
-
toolName: z5.string(),
|
944
|
-
result: z5.unknown(),
|
945
|
-
content: toolResultContentSchema.optional(),
|
946
|
-
isError: z5.boolean().optional(),
|
947
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
948
|
-
});
|
949
|
-
|
950
|
-
// core/prompt/message.ts
|
951
|
-
var coreSystemMessageSchema = z6.object({
|
952
|
-
role: z6.literal("system"),
|
953
|
-
content: z6.string(),
|
954
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
955
|
-
});
|
956
|
-
var coreUserMessageSchema = z6.object({
|
957
|
-
role: z6.literal("user"),
|
958
|
-
content: z6.union([
|
959
|
-
z6.string(),
|
960
|
-
z6.array(z6.union([textPartSchema, imagePartSchema, filePartSchema]))
|
961
|
-
]),
|
962
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
963
|
-
});
|
964
|
-
var coreAssistantMessageSchema = z6.object({
|
965
|
-
role: z6.literal("assistant"),
|
966
|
-
content: z6.union([
|
967
|
-
z6.string(),
|
968
|
-
z6.array(z6.union([textPartSchema, toolCallPartSchema]))
|
969
|
-
]),
|
970
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
971
|
-
});
|
972
|
-
var coreToolMessageSchema = z6.object({
|
973
|
-
role: z6.literal("tool"),
|
974
|
-
content: z6.array(toolResultPartSchema),
|
975
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
976
|
-
});
|
977
|
-
var coreMessageSchema = z6.union([
|
978
|
-
coreSystemMessageSchema,
|
979
|
-
coreUserMessageSchema,
|
980
|
-
coreAssistantMessageSchema,
|
981
|
-
coreToolMessageSchema
|
982
|
-
]);
|
983
|
-
|
984
|
-
// core/prompt/detect-prompt-type.ts
|
985
|
-
function detectPromptType(prompt) {
|
986
|
-
if (!Array.isArray(prompt)) {
|
987
|
-
return "other";
|
988
|
-
}
|
989
|
-
if (prompt.length === 0) {
|
990
|
-
return "messages";
|
991
|
-
}
|
992
|
-
const characteristics = prompt.map(detectSingleMessageCharacteristics);
|
993
|
-
if (characteristics.some((c) => c === "has-ui-specific-parts")) {
|
994
|
-
return "ui-messages";
|
995
|
-
} else if (characteristics.every(
|
996
|
-
(c) => c === "has-core-specific-parts" || c === "message"
|
997
|
-
)) {
|
998
|
-
return "messages";
|
999
|
-
} else {
|
1000
|
-
return "other";
|
1001
|
-
}
|
1002
|
-
}
|
1003
|
-
function detectSingleMessageCharacteristics(message) {
|
1004
|
-
if (typeof message === "object" && message !== null && (message.role === "function" || // UI-only role
|
1005
|
-
message.role === "data" || // UI-only role
|
1006
|
-
"toolInvocations" in message || // UI-specific field
|
1007
|
-
"experimental_attachments" in message)) {
|
1008
|
-
return "has-ui-specific-parts";
|
1009
|
-
} else if (typeof message === "object" && message !== null && "content" in message && (Array.isArray(message.content) || // Core messages can have array content
|
1010
|
-
"experimental_providerMetadata" in message)) {
|
1011
|
-
return "has-core-specific-parts";
|
1012
|
-
} else if (typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.content === "string" && ["system", "user", "assistant", "tool"].includes(message.role)) {
|
1013
|
-
return "message";
|
1014
|
-
} else {
|
1015
|
-
return "other";
|
1016
|
-
}
|
1017
|
-
}
|
1018
|
-
|
1019
875
|
// core/prompt/attachments-to-parts.ts
|
1020
876
|
function attachmentsToParts(attachments) {
|
1021
877
|
var _a9, _b, _c;
|
@@ -1200,6 +1056,150 @@ function convertToCoreMessages(messages, options) {
|
|
1200
1056
|
return coreMessages;
|
1201
1057
|
}
|
1202
1058
|
|
1059
|
+
// core/prompt/detect-prompt-type.ts
|
1060
|
+
function detectPromptType(prompt) {
|
1061
|
+
if (!Array.isArray(prompt)) {
|
1062
|
+
return "other";
|
1063
|
+
}
|
1064
|
+
if (prompt.length === 0) {
|
1065
|
+
return "messages";
|
1066
|
+
}
|
1067
|
+
const characteristics = prompt.map(detectSingleMessageCharacteristics);
|
1068
|
+
if (characteristics.some((c) => c === "has-ui-specific-parts")) {
|
1069
|
+
return "ui-messages";
|
1070
|
+
} else if (characteristics.every(
|
1071
|
+
(c) => c === "has-core-specific-parts" || c === "message"
|
1072
|
+
)) {
|
1073
|
+
return "messages";
|
1074
|
+
} else {
|
1075
|
+
return "other";
|
1076
|
+
}
|
1077
|
+
}
|
1078
|
+
function detectSingleMessageCharacteristics(message) {
|
1079
|
+
if (typeof message === "object" && message !== null && (message.role === "function" || // UI-only role
|
1080
|
+
message.role === "data" || // UI-only role
|
1081
|
+
"toolInvocations" in message || // UI-specific field
|
1082
|
+
"experimental_attachments" in message)) {
|
1083
|
+
return "has-ui-specific-parts";
|
1084
|
+
} else if (typeof message === "object" && message !== null && "content" in message && (Array.isArray(message.content) || // Core messages can have array content
|
1085
|
+
"experimental_providerMetadata" in message)) {
|
1086
|
+
return "has-core-specific-parts";
|
1087
|
+
} else if (typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.content === "string" && ["system", "user", "assistant", "tool"].includes(message.role)) {
|
1088
|
+
return "message";
|
1089
|
+
} else {
|
1090
|
+
return "other";
|
1091
|
+
}
|
1092
|
+
}
|
1093
|
+
|
1094
|
+
// core/prompt/message.ts
|
1095
|
+
import { z as z6 } from "zod";
|
1096
|
+
|
1097
|
+
// core/types/provider-metadata.ts
|
1098
|
+
import { z as z3 } from "zod";
|
1099
|
+
|
1100
|
+
// core/types/json-value.ts
|
1101
|
+
import { z as z2 } from "zod";
|
1102
|
+
var jsonValueSchema = z2.lazy(
|
1103
|
+
() => z2.union([
|
1104
|
+
z2.null(),
|
1105
|
+
z2.string(),
|
1106
|
+
z2.number(),
|
1107
|
+
z2.boolean(),
|
1108
|
+
z2.record(z2.string(), jsonValueSchema),
|
1109
|
+
z2.array(jsonValueSchema)
|
1110
|
+
])
|
1111
|
+
);
|
1112
|
+
|
1113
|
+
// core/types/provider-metadata.ts
|
1114
|
+
var providerMetadataSchema = z3.record(
|
1115
|
+
z3.string(),
|
1116
|
+
z3.record(z3.string(), jsonValueSchema)
|
1117
|
+
);
|
1118
|
+
|
1119
|
+
// core/prompt/content-part.ts
|
1120
|
+
import { z as z5 } from "zod";
|
1121
|
+
|
1122
|
+
// core/prompt/tool-result-content.ts
|
1123
|
+
import { z as z4 } from "zod";
|
1124
|
+
var toolResultContentSchema = z4.array(
|
1125
|
+
z4.union([
|
1126
|
+
z4.object({ type: z4.literal("text"), text: z4.string() }),
|
1127
|
+
z4.object({
|
1128
|
+
type: z4.literal("image"),
|
1129
|
+
data: z4.string(),
|
1130
|
+
mimeType: z4.string().optional()
|
1131
|
+
})
|
1132
|
+
])
|
1133
|
+
);
|
1134
|
+
|
1135
|
+
// core/prompt/content-part.ts
|
1136
|
+
var textPartSchema = z5.object({
|
1137
|
+
type: z5.literal("text"),
|
1138
|
+
text: z5.string(),
|
1139
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1140
|
+
});
|
1141
|
+
var imagePartSchema = z5.object({
|
1142
|
+
type: z5.literal("image"),
|
1143
|
+
image: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
1144
|
+
mimeType: z5.string().optional(),
|
1145
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1146
|
+
});
|
1147
|
+
var filePartSchema = z5.object({
|
1148
|
+
type: z5.literal("file"),
|
1149
|
+
data: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
1150
|
+
mimeType: z5.string(),
|
1151
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1152
|
+
});
|
1153
|
+
var toolCallPartSchema = z5.object({
|
1154
|
+
type: z5.literal("tool-call"),
|
1155
|
+
toolCallId: z5.string(),
|
1156
|
+
toolName: z5.string(),
|
1157
|
+
args: z5.unknown()
|
1158
|
+
});
|
1159
|
+
var toolResultPartSchema = z5.object({
|
1160
|
+
type: z5.literal("tool-result"),
|
1161
|
+
toolCallId: z5.string(),
|
1162
|
+
toolName: z5.string(),
|
1163
|
+
result: z5.unknown(),
|
1164
|
+
content: toolResultContentSchema.optional(),
|
1165
|
+
isError: z5.boolean().optional(),
|
1166
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1167
|
+
});
|
1168
|
+
|
1169
|
+
// core/prompt/message.ts
|
1170
|
+
var coreSystemMessageSchema = z6.object({
|
1171
|
+
role: z6.literal("system"),
|
1172
|
+
content: z6.string(),
|
1173
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1174
|
+
});
|
1175
|
+
var coreUserMessageSchema = z6.object({
|
1176
|
+
role: z6.literal("user"),
|
1177
|
+
content: z6.union([
|
1178
|
+
z6.string(),
|
1179
|
+
z6.array(z6.union([textPartSchema, imagePartSchema, filePartSchema]))
|
1180
|
+
]),
|
1181
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1182
|
+
});
|
1183
|
+
var coreAssistantMessageSchema = z6.object({
|
1184
|
+
role: z6.literal("assistant"),
|
1185
|
+
content: z6.union([
|
1186
|
+
z6.string(),
|
1187
|
+
z6.array(z6.union([textPartSchema, toolCallPartSchema]))
|
1188
|
+
]),
|
1189
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1190
|
+
});
|
1191
|
+
var coreToolMessageSchema = z6.object({
|
1192
|
+
role: z6.literal("tool"),
|
1193
|
+
content: z6.array(toolResultPartSchema),
|
1194
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1195
|
+
});
|
1196
|
+
var coreMessageSchema = z6.union([
|
1197
|
+
coreSystemMessageSchema,
|
1198
|
+
coreUserMessageSchema,
|
1199
|
+
coreAssistantMessageSchema,
|
1200
|
+
coreToolMessageSchema
|
1201
|
+
]);
|
1202
|
+
|
1203
1203
|
// core/prompt/standardize-prompt.ts
|
1204
1204
|
function standardizePrompt({
|
1205
1205
|
prompt,
|