ai 5.1.0-beta.0 → 5.1.0-beta.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 +83 -0
- package/dist/index.d.mts +169 -28
- package/dist/index.d.ts +169 -28
- package/dist/index.js +122 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +120 -81
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +7 -7
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +7 -7
- package/dist/internal/index.mjs.map +1 -1
- package/dist/test/index.d.mts +32 -32
- package/dist/test/index.d.ts +32 -32
- package/dist/test/index.js +14 -14
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +11 -11
- package/dist/test/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
dynamicTool as dynamicTool2,
|
|
13
13
|
generateId as generateId2,
|
|
14
14
|
jsonSchema as jsonSchema2,
|
|
15
|
+
parseJsonEventStream as parseJsonEventStream3,
|
|
15
16
|
tool as tool2,
|
|
16
17
|
zodSchema
|
|
17
18
|
} from "@ai-sdk/provider-utils";
|
|
@@ -463,7 +464,7 @@ function resolveLanguageModel(model) {
|
|
|
463
464
|
}
|
|
464
465
|
function resolveEmbeddingModel(model) {
|
|
465
466
|
if (typeof model !== "string") {
|
|
466
|
-
if (model.specificationVersion !== "
|
|
467
|
+
if (model.specificationVersion !== "v3") {
|
|
467
468
|
throw new UnsupportedModelVersionError({
|
|
468
469
|
version: model.specificationVersion,
|
|
469
470
|
provider: model.provider,
|
|
@@ -678,7 +679,7 @@ import {
|
|
|
678
679
|
} from "@ai-sdk/provider-utils";
|
|
679
680
|
|
|
680
681
|
// src/version.ts
|
|
681
|
-
var VERSION = true ? "5.1.0-beta.
|
|
682
|
+
var VERSION = true ? "5.1.0-beta.10" : "0.0.0-test";
|
|
682
683
|
|
|
683
684
|
// src/util/download/download.ts
|
|
684
685
|
var download = async ({ url }) => {
|
|
@@ -971,12 +972,12 @@ async function downloadAssets(messages, download2, supportedUrls) {
|
|
|
971
972
|
}));
|
|
972
973
|
const downloadedFiles = await download2(plannedDownloads);
|
|
973
974
|
return Object.fromEntries(
|
|
974
|
-
downloadedFiles.
|
|
975
|
-
(
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
975
|
+
downloadedFiles.map(
|
|
976
|
+
(file, index) => file == null ? null : [
|
|
977
|
+
plannedDownloads[index].url.toString(),
|
|
978
|
+
{ data: file.data, mediaType: file.mediaType }
|
|
979
|
+
]
|
|
980
|
+
).filter((file) => file != null)
|
|
980
981
|
);
|
|
981
982
|
}
|
|
982
983
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
@@ -2922,11 +2923,6 @@ var uiMessageChunkSchema = z7.union([
|
|
|
2922
2923
|
providerExecuted: z7.boolean().optional(),
|
|
2923
2924
|
dynamic: z7.boolean().optional()
|
|
2924
2925
|
}),
|
|
2925
|
-
z7.strictObject({
|
|
2926
|
-
type: z7.literal("reasoning"),
|
|
2927
|
-
text: z7.string(),
|
|
2928
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
2929
|
-
}),
|
|
2930
2926
|
z7.strictObject({
|
|
2931
2927
|
type: z7.literal("reasoning-start"),
|
|
2932
2928
|
id: z7.string(),
|
|
@@ -2943,9 +2939,6 @@ var uiMessageChunkSchema = z7.union([
|
|
|
2943
2939
|
id: z7.string(),
|
|
2944
2940
|
providerMetadata: providerMetadataSchema.optional()
|
|
2945
2941
|
}),
|
|
2946
|
-
z7.strictObject({
|
|
2947
|
-
type: z7.literal("reasoning-part-finish")
|
|
2948
|
-
}),
|
|
2949
2942
|
z7.strictObject({
|
|
2950
2943
|
type: z7.literal("source-url"),
|
|
2951
2944
|
sourceId: z7.string(),
|
|
@@ -2968,7 +2961,10 @@ var uiMessageChunkSchema = z7.union([
|
|
|
2968
2961
|
providerMetadata: providerMetadataSchema.optional()
|
|
2969
2962
|
}),
|
|
2970
2963
|
z7.strictObject({
|
|
2971
|
-
type: z7.
|
|
2964
|
+
type: z7.custom(
|
|
2965
|
+
(value) => typeof value === "string" && value.startsWith("data-"),
|
|
2966
|
+
{ message: 'Type must start with "data-"' }
|
|
2967
|
+
),
|
|
2972
2968
|
id: z7.string().optional(),
|
|
2973
2969
|
data: z7.unknown(),
|
|
2974
2970
|
transient: z7.boolean().optional()
|
|
@@ -6322,7 +6318,7 @@ async function generateImage({
|
|
|
6322
6318
|
headers
|
|
6323
6319
|
}) {
|
|
6324
6320
|
var _a17, _b;
|
|
6325
|
-
if (model.specificationVersion !== "
|
|
6321
|
+
if (model.specificationVersion !== "v3") {
|
|
6326
6322
|
throw new UnsupportedModelVersionError({
|
|
6327
6323
|
version: model.specificationVersion,
|
|
6328
6324
|
provider: model.provider,
|
|
@@ -9701,9 +9697,11 @@ var AbstractChat = class {
|
|
|
9701
9697
|
}
|
|
9702
9698
|
};
|
|
9703
9699
|
this.addToolResult = async ({
|
|
9700
|
+
state = "output-available",
|
|
9704
9701
|
tool: tool3,
|
|
9705
9702
|
toolCallId,
|
|
9706
|
-
output
|
|
9703
|
+
output,
|
|
9704
|
+
errorText
|
|
9707
9705
|
}) => this.jobExecutor.run(async () => {
|
|
9708
9706
|
var _a17, _b;
|
|
9709
9707
|
const messages = this.state.messages;
|
|
@@ -9711,16 +9709,16 @@ var AbstractChat = class {
|
|
|
9711
9709
|
this.state.replaceMessage(messages.length - 1, {
|
|
9712
9710
|
...lastMessage,
|
|
9713
9711
|
parts: lastMessage.parts.map(
|
|
9714
|
-
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state
|
|
9712
|
+
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state, output, errorText } : part
|
|
9715
9713
|
)
|
|
9716
9714
|
});
|
|
9717
9715
|
if (this.activeResponse) {
|
|
9718
9716
|
this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(
|
|
9719
9717
|
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? {
|
|
9720
9718
|
...part,
|
|
9721
|
-
state
|
|
9719
|
+
state,
|
|
9722
9720
|
output,
|
|
9723
|
-
errorText
|
|
9721
|
+
errorText
|
|
9724
9722
|
} : part
|
|
9725
9723
|
);
|
|
9726
9724
|
}
|
|
@@ -9929,7 +9927,9 @@ function lastAssistantMessageIsCompleteWithToolCalls({
|
|
|
9929
9927
|
return part.type === "step-start" ? index : lastIndex;
|
|
9930
9928
|
}, -1);
|
|
9931
9929
|
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolOrDynamicToolUIPart);
|
|
9932
|
-
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every(
|
|
9930
|
+
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every(
|
|
9931
|
+
(part) => part.state === "output-available" || part.state === "output-error"
|
|
9932
|
+
);
|
|
9933
9933
|
}
|
|
9934
9934
|
|
|
9935
9935
|
// src/ui/transform-text-to-ui-message-stream.ts
|
|
@@ -10117,82 +10117,118 @@ var uiMessageSchema = z10.object({
|
|
|
10117
10117
|
])
|
|
10118
10118
|
)
|
|
10119
10119
|
});
|
|
10120
|
-
async function
|
|
10120
|
+
async function safeValidateUIMessages({
|
|
10121
10121
|
messages,
|
|
10122
10122
|
metadataSchema,
|
|
10123
10123
|
dataSchemas,
|
|
10124
10124
|
tools
|
|
10125
10125
|
}) {
|
|
10126
|
-
|
|
10127
|
-
|
|
10128
|
-
|
|
10126
|
+
try {
|
|
10127
|
+
if (messages == null) {
|
|
10128
|
+
return {
|
|
10129
|
+
success: false,
|
|
10130
|
+
error: new InvalidArgumentError({
|
|
10131
|
+
parameter: "messages",
|
|
10132
|
+
value: messages,
|
|
10133
|
+
message: "messages parameter must be provided"
|
|
10134
|
+
})
|
|
10135
|
+
};
|
|
10136
|
+
}
|
|
10137
|
+
const validatedMessages = await validateTypes2({
|
|
10129
10138
|
value: messages,
|
|
10130
|
-
|
|
10139
|
+
schema: z10.array(uiMessageSchema)
|
|
10131
10140
|
});
|
|
10132
|
-
|
|
10133
|
-
|
|
10134
|
-
value: messages,
|
|
10135
|
-
schema: z10.array(uiMessageSchema)
|
|
10136
|
-
});
|
|
10137
|
-
if (metadataSchema) {
|
|
10138
|
-
for (const message of validatedMessages) {
|
|
10139
|
-
await validateTypes2({
|
|
10140
|
-
value: message.metadata,
|
|
10141
|
-
schema: metadataSchema
|
|
10142
|
-
});
|
|
10143
|
-
}
|
|
10144
|
-
}
|
|
10145
|
-
if (dataSchemas) {
|
|
10146
|
-
for (const message of validatedMessages) {
|
|
10147
|
-
const dataParts = message.parts.filter(
|
|
10148
|
-
(part) => part.type.startsWith("data-")
|
|
10149
|
-
);
|
|
10150
|
-
for (const dataPart of dataParts) {
|
|
10151
|
-
const dataName = dataPart.type.slice(5);
|
|
10152
|
-
const dataSchema = dataSchemas[dataName];
|
|
10153
|
-
if (!dataSchema) {
|
|
10154
|
-
throw new TypeValidationError4({
|
|
10155
|
-
value: dataPart.data,
|
|
10156
|
-
cause: `No data schema found for data part ${dataName}`
|
|
10157
|
-
});
|
|
10158
|
-
}
|
|
10141
|
+
if (metadataSchema) {
|
|
10142
|
+
for (const message of validatedMessages) {
|
|
10159
10143
|
await validateTypes2({
|
|
10160
|
-
value:
|
|
10161
|
-
schema:
|
|
10144
|
+
value: message.metadata,
|
|
10145
|
+
schema: metadataSchema
|
|
10162
10146
|
});
|
|
10163
10147
|
}
|
|
10164
10148
|
}
|
|
10165
|
-
|
|
10166
|
-
|
|
10167
|
-
|
|
10168
|
-
|
|
10169
|
-
|
|
10170
|
-
|
|
10171
|
-
|
|
10172
|
-
|
|
10173
|
-
|
|
10174
|
-
|
|
10175
|
-
|
|
10176
|
-
|
|
10177
|
-
|
|
10178
|
-
|
|
10179
|
-
|
|
10180
|
-
|
|
10149
|
+
if (dataSchemas) {
|
|
10150
|
+
for (const message of validatedMessages) {
|
|
10151
|
+
const dataParts = message.parts.filter(
|
|
10152
|
+
(part) => part.type.startsWith("data-")
|
|
10153
|
+
);
|
|
10154
|
+
for (const dataPart of dataParts) {
|
|
10155
|
+
const dataName = dataPart.type.slice(5);
|
|
10156
|
+
const dataSchema = dataSchemas[dataName];
|
|
10157
|
+
if (!dataSchema) {
|
|
10158
|
+
return {
|
|
10159
|
+
success: false,
|
|
10160
|
+
error: new TypeValidationError4({
|
|
10161
|
+
value: dataPart.data,
|
|
10162
|
+
cause: `No data schema found for data part ${dataName}`
|
|
10163
|
+
})
|
|
10164
|
+
};
|
|
10165
|
+
}
|
|
10181
10166
|
await validateTypes2({
|
|
10182
|
-
value:
|
|
10183
|
-
schema:
|
|
10167
|
+
value: dataPart.data,
|
|
10168
|
+
schema: dataSchema
|
|
10184
10169
|
});
|
|
10185
10170
|
}
|
|
10186
|
-
|
|
10187
|
-
|
|
10188
|
-
|
|
10189
|
-
|
|
10190
|
-
|
|
10171
|
+
}
|
|
10172
|
+
}
|
|
10173
|
+
if (tools) {
|
|
10174
|
+
for (const message of validatedMessages) {
|
|
10175
|
+
const toolParts = message.parts.filter(
|
|
10176
|
+
(part) => part.type.startsWith("tool-")
|
|
10177
|
+
);
|
|
10178
|
+
for (const toolPart of toolParts) {
|
|
10179
|
+
const toolName = toolPart.type.slice(5);
|
|
10180
|
+
const tool3 = tools[toolName];
|
|
10181
|
+
if (!tool3) {
|
|
10182
|
+
return {
|
|
10183
|
+
success: false,
|
|
10184
|
+
error: new TypeValidationError4({
|
|
10185
|
+
value: toolPart.input,
|
|
10186
|
+
cause: `No tool schema found for tool part ${toolName}`
|
|
10187
|
+
})
|
|
10188
|
+
};
|
|
10189
|
+
}
|
|
10190
|
+
if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error") {
|
|
10191
|
+
await validateTypes2({
|
|
10192
|
+
value: toolPart.input,
|
|
10193
|
+
schema: tool3.inputSchema
|
|
10194
|
+
});
|
|
10195
|
+
}
|
|
10196
|
+
if (toolPart.state === "output-available" && tool3.outputSchema) {
|
|
10197
|
+
await validateTypes2({
|
|
10198
|
+
value: toolPart.output,
|
|
10199
|
+
schema: tool3.outputSchema
|
|
10200
|
+
});
|
|
10201
|
+
}
|
|
10191
10202
|
}
|
|
10192
10203
|
}
|
|
10193
10204
|
}
|
|
10205
|
+
return {
|
|
10206
|
+
success: true,
|
|
10207
|
+
data: validatedMessages
|
|
10208
|
+
};
|
|
10209
|
+
} catch (error) {
|
|
10210
|
+
const err = error;
|
|
10211
|
+
return {
|
|
10212
|
+
success: false,
|
|
10213
|
+
error: err
|
|
10214
|
+
};
|
|
10194
10215
|
}
|
|
10195
|
-
|
|
10216
|
+
}
|
|
10217
|
+
async function validateUIMessages({
|
|
10218
|
+
messages,
|
|
10219
|
+
metadataSchema,
|
|
10220
|
+
dataSchemas,
|
|
10221
|
+
tools
|
|
10222
|
+
}) {
|
|
10223
|
+
const response = await safeValidateUIMessages({
|
|
10224
|
+
messages,
|
|
10225
|
+
metadataSchema,
|
|
10226
|
+
dataSchemas,
|
|
10227
|
+
tools
|
|
10228
|
+
});
|
|
10229
|
+
if (!response.success)
|
|
10230
|
+
throw response.error;
|
|
10231
|
+
return response.data;
|
|
10196
10232
|
}
|
|
10197
10233
|
|
|
10198
10234
|
// src/ui-message-stream/create-ui-message-stream.ts
|
|
@@ -10415,10 +10451,12 @@ export {
|
|
|
10415
10451
|
jsonSchema2 as jsonSchema,
|
|
10416
10452
|
lastAssistantMessageIsCompleteWithToolCalls,
|
|
10417
10453
|
modelMessageSchema,
|
|
10454
|
+
parseJsonEventStream3 as parseJsonEventStream,
|
|
10418
10455
|
parsePartialJson,
|
|
10419
10456
|
pipeTextStreamToResponse,
|
|
10420
10457
|
pipeUIMessageStreamToResponse,
|
|
10421
10458
|
readUIMessageStream,
|
|
10459
|
+
safeValidateUIMessages,
|
|
10422
10460
|
simulateReadableStream,
|
|
10423
10461
|
simulateStreamingMiddleware,
|
|
10424
10462
|
smoothStream,
|
|
@@ -10428,6 +10466,7 @@ export {
|
|
|
10428
10466
|
systemModelMessageSchema,
|
|
10429
10467
|
tool2 as tool,
|
|
10430
10468
|
toolModelMessageSchema,
|
|
10469
|
+
uiMessageChunkSchema,
|
|
10431
10470
|
userModelMessageSchema,
|
|
10432
10471
|
validateUIMessages,
|
|
10433
10472
|
wrapLanguageModel,
|