ai 5.0.55 → 5.1.0-beta.0
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 +7 -67
- package/dist/index.d.mts +34 -156
- package/dist/index.d.ts +34 -156
- package/dist/index.js +79 -120
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -118
- 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/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -103,12 +103,10 @@ __export(src_exports, {
|
|
|
103
103
|
jsonSchema: () => import_provider_utils35.jsonSchema,
|
|
104
104
|
lastAssistantMessageIsCompleteWithToolCalls: () => lastAssistantMessageIsCompleteWithToolCalls,
|
|
105
105
|
modelMessageSchema: () => modelMessageSchema,
|
|
106
|
-
parseJsonEventStream: () => import_provider_utils35.parseJsonEventStream,
|
|
107
106
|
parsePartialJson: () => parsePartialJson,
|
|
108
107
|
pipeTextStreamToResponse: () => pipeTextStreamToResponse,
|
|
109
108
|
pipeUIMessageStreamToResponse: () => pipeUIMessageStreamToResponse,
|
|
110
109
|
readUIMessageStream: () => readUIMessageStream,
|
|
111
|
-
safeValidateUIMessages: () => safeValidateUIMessages,
|
|
112
110
|
simulateReadableStream: () => simulateReadableStream,
|
|
113
111
|
simulateStreamingMiddleware: () => simulateStreamingMiddleware,
|
|
114
112
|
smoothStream: () => smoothStream,
|
|
@@ -118,7 +116,6 @@ __export(src_exports, {
|
|
|
118
116
|
systemModelMessageSchema: () => systemModelMessageSchema,
|
|
119
117
|
tool: () => import_provider_utils35.tool,
|
|
120
118
|
toolModelMessageSchema: () => toolModelMessageSchema,
|
|
121
|
-
uiMessageChunkSchema: () => uiMessageChunkSchema,
|
|
122
119
|
userModelMessageSchema: () => userModelMessageSchema,
|
|
123
120
|
validateUIMessages: () => validateUIMessages,
|
|
124
121
|
wrapLanguageModel: () => wrapLanguageModel,
|
|
@@ -768,7 +765,7 @@ function detectMediaType({
|
|
|
768
765
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
769
766
|
|
|
770
767
|
// src/version.ts
|
|
771
|
-
var VERSION = true ? "5.0.
|
|
768
|
+
var VERSION = true ? "5.1.0-beta.0" : "0.0.0-test";
|
|
772
769
|
|
|
773
770
|
// src/util/download/download.ts
|
|
774
771
|
var download = async ({ url }) => {
|
|
@@ -1058,12 +1055,12 @@ async function downloadAssets(messages, download2, supportedUrls) {
|
|
|
1058
1055
|
}));
|
|
1059
1056
|
const downloadedFiles = await download2(plannedDownloads);
|
|
1060
1057
|
return Object.fromEntries(
|
|
1061
|
-
downloadedFiles.
|
|
1062
|
-
(
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
)
|
|
1058
|
+
downloadedFiles.filter(
|
|
1059
|
+
(downloadedFile) => (downloadedFile == null ? void 0 : downloadedFile.data) != null
|
|
1060
|
+
).map(({ data, mediaType }, index) => [
|
|
1061
|
+
plannedDownloads[index].url.toString(),
|
|
1062
|
+
{ data, mediaType }
|
|
1063
|
+
])
|
|
1067
1064
|
);
|
|
1068
1065
|
}
|
|
1069
1066
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
@@ -2990,6 +2987,11 @@ var uiMessageChunkSchema = import_v47.z.union([
|
|
|
2990
2987
|
providerExecuted: import_v47.z.boolean().optional(),
|
|
2991
2988
|
dynamic: import_v47.z.boolean().optional()
|
|
2992
2989
|
}),
|
|
2990
|
+
import_v47.z.strictObject({
|
|
2991
|
+
type: import_v47.z.literal("reasoning"),
|
|
2992
|
+
text: import_v47.z.string(),
|
|
2993
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
2994
|
+
}),
|
|
2993
2995
|
import_v47.z.strictObject({
|
|
2994
2996
|
type: import_v47.z.literal("reasoning-start"),
|
|
2995
2997
|
id: import_v47.z.string(),
|
|
@@ -3006,6 +3008,9 @@ var uiMessageChunkSchema = import_v47.z.union([
|
|
|
3006
3008
|
id: import_v47.z.string(),
|
|
3007
3009
|
providerMetadata: providerMetadataSchema.optional()
|
|
3008
3010
|
}),
|
|
3011
|
+
import_v47.z.strictObject({
|
|
3012
|
+
type: import_v47.z.literal("reasoning-part-finish")
|
|
3013
|
+
}),
|
|
3009
3014
|
import_v47.z.strictObject({
|
|
3010
3015
|
type: import_v47.z.literal("source-url"),
|
|
3011
3016
|
sourceId: import_v47.z.string(),
|
|
@@ -3028,10 +3033,7 @@ var uiMessageChunkSchema = import_v47.z.union([
|
|
|
3028
3033
|
providerMetadata: providerMetadataSchema.optional()
|
|
3029
3034
|
}),
|
|
3030
3035
|
import_v47.z.strictObject({
|
|
3031
|
-
type: import_v47.z.
|
|
3032
|
-
(value) => typeof value === "string" && value.startsWith("data-"),
|
|
3033
|
-
{ message: 'Type must start with "data-"' }
|
|
3034
|
-
),
|
|
3036
|
+
type: import_v47.z.string().startsWith("data-"),
|
|
3035
3037
|
id: import_v47.z.string().optional(),
|
|
3036
3038
|
data: import_v47.z.unknown(),
|
|
3037
3039
|
transient: import_v47.z.boolean().optional()
|
|
@@ -9721,11 +9723,9 @@ var AbstractChat = class {
|
|
|
9721
9723
|
}
|
|
9722
9724
|
};
|
|
9723
9725
|
this.addToolResult = async ({
|
|
9724
|
-
state = "output-available",
|
|
9725
9726
|
tool: tool3,
|
|
9726
9727
|
toolCallId,
|
|
9727
|
-
output
|
|
9728
|
-
errorText
|
|
9728
|
+
output
|
|
9729
9729
|
}) => this.jobExecutor.run(async () => {
|
|
9730
9730
|
var _a17, _b;
|
|
9731
9731
|
const messages = this.state.messages;
|
|
@@ -9733,16 +9733,16 @@ var AbstractChat = class {
|
|
|
9733
9733
|
this.state.replaceMessage(messages.length - 1, {
|
|
9734
9734
|
...lastMessage,
|
|
9735
9735
|
parts: lastMessage.parts.map(
|
|
9736
|
-
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state
|
|
9736
|
+
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state: "output-available", output } : part
|
|
9737
9737
|
)
|
|
9738
9738
|
});
|
|
9739
9739
|
if (this.activeResponse) {
|
|
9740
9740
|
this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(
|
|
9741
9741
|
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? {
|
|
9742
9742
|
...part,
|
|
9743
|
-
state,
|
|
9743
|
+
state: "output-available",
|
|
9744
9744
|
output,
|
|
9745
|
-
errorText
|
|
9745
|
+
errorText: void 0
|
|
9746
9746
|
} : part
|
|
9747
9747
|
);
|
|
9748
9748
|
}
|
|
@@ -9951,9 +9951,7 @@ function lastAssistantMessageIsCompleteWithToolCalls({
|
|
|
9951
9951
|
return part.type === "step-start" ? index : lastIndex;
|
|
9952
9952
|
}, -1);
|
|
9953
9953
|
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolOrDynamicToolUIPart);
|
|
9954
|
-
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every(
|
|
9955
|
-
(part) => part.state === "output-available" || part.state === "output-error"
|
|
9956
|
-
);
|
|
9954
|
+
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => part.state === "output-available");
|
|
9957
9955
|
}
|
|
9958
9956
|
|
|
9959
9957
|
// src/ui/transform-text-to-ui-message-stream.ts
|
|
@@ -10139,118 +10137,82 @@ var uiMessageSchema = import_v410.z.object({
|
|
|
10139
10137
|
])
|
|
10140
10138
|
)
|
|
10141
10139
|
});
|
|
10142
|
-
async function
|
|
10140
|
+
async function validateUIMessages({
|
|
10143
10141
|
messages,
|
|
10144
10142
|
metadataSchema,
|
|
10145
10143
|
dataSchemas,
|
|
10146
10144
|
tools
|
|
10147
10145
|
}) {
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
success: false,
|
|
10152
|
-
error: new InvalidArgumentError({
|
|
10153
|
-
parameter: "messages",
|
|
10154
|
-
value: messages,
|
|
10155
|
-
message: "messages parameter must be provided"
|
|
10156
|
-
})
|
|
10157
|
-
};
|
|
10158
|
-
}
|
|
10159
|
-
const validatedMessages = await (0, import_provider_utils33.validateTypes)({
|
|
10146
|
+
if (messages == null) {
|
|
10147
|
+
throw new InvalidArgumentError({
|
|
10148
|
+
parameter: "messages",
|
|
10160
10149
|
value: messages,
|
|
10161
|
-
|
|
10150
|
+
message: "messages parameter must be provided"
|
|
10162
10151
|
});
|
|
10163
|
-
|
|
10164
|
-
|
|
10152
|
+
}
|
|
10153
|
+
const validatedMessages = await (0, import_provider_utils33.validateTypes)({
|
|
10154
|
+
value: messages,
|
|
10155
|
+
schema: import_v410.z.array(uiMessageSchema)
|
|
10156
|
+
});
|
|
10157
|
+
if (metadataSchema) {
|
|
10158
|
+
for (const message of validatedMessages) {
|
|
10159
|
+
await (0, import_provider_utils33.validateTypes)({
|
|
10160
|
+
value: message.metadata,
|
|
10161
|
+
schema: metadataSchema
|
|
10162
|
+
});
|
|
10163
|
+
}
|
|
10164
|
+
}
|
|
10165
|
+
if (dataSchemas) {
|
|
10166
|
+
for (const message of validatedMessages) {
|
|
10167
|
+
const dataParts = message.parts.filter(
|
|
10168
|
+
(part) => part.type.startsWith("data-")
|
|
10169
|
+
);
|
|
10170
|
+
for (const dataPart of dataParts) {
|
|
10171
|
+
const dataName = dataPart.type.slice(5);
|
|
10172
|
+
const dataSchema = dataSchemas[dataName];
|
|
10173
|
+
if (!dataSchema) {
|
|
10174
|
+
throw new import_provider32.TypeValidationError({
|
|
10175
|
+
value: dataPart.data,
|
|
10176
|
+
cause: `No data schema found for data part ${dataName}`
|
|
10177
|
+
});
|
|
10178
|
+
}
|
|
10165
10179
|
await (0, import_provider_utils33.validateTypes)({
|
|
10166
|
-
value:
|
|
10167
|
-
schema:
|
|
10180
|
+
value: dataPart.data,
|
|
10181
|
+
schema: dataSchema
|
|
10168
10182
|
});
|
|
10169
10183
|
}
|
|
10170
10184
|
}
|
|
10171
|
-
|
|
10172
|
-
|
|
10173
|
-
|
|
10174
|
-
|
|
10175
|
-
)
|
|
10176
|
-
|
|
10177
|
-
|
|
10178
|
-
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
|
|
10183
|
-
|
|
10184
|
-
|
|
10185
|
-
|
|
10186
|
-
|
|
10187
|
-
}
|
|
10185
|
+
}
|
|
10186
|
+
if (tools) {
|
|
10187
|
+
for (const message of validatedMessages) {
|
|
10188
|
+
const toolParts = message.parts.filter(
|
|
10189
|
+
(part) => part.type.startsWith("tool-")
|
|
10190
|
+
);
|
|
10191
|
+
for (const toolPart of toolParts) {
|
|
10192
|
+
const toolName = toolPart.type.slice(5);
|
|
10193
|
+
const tool3 = tools[toolName];
|
|
10194
|
+
if (!tool3) {
|
|
10195
|
+
throw new import_provider32.TypeValidationError({
|
|
10196
|
+
value: toolPart.input,
|
|
10197
|
+
cause: `No tool schema found for tool part ${toolName}`
|
|
10198
|
+
});
|
|
10199
|
+
}
|
|
10200
|
+
if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error") {
|
|
10188
10201
|
await (0, import_provider_utils33.validateTypes)({
|
|
10189
|
-
value:
|
|
10190
|
-
schema:
|
|
10202
|
+
value: toolPart.input,
|
|
10203
|
+
schema: tool3.inputSchema
|
|
10191
10204
|
});
|
|
10192
10205
|
}
|
|
10193
|
-
|
|
10194
|
-
|
|
10195
|
-
|
|
10196
|
-
|
|
10197
|
-
|
|
10198
|
-
(part) => part.type.startsWith("tool-")
|
|
10199
|
-
);
|
|
10200
|
-
for (const toolPart of toolParts) {
|
|
10201
|
-
const toolName = toolPart.type.slice(5);
|
|
10202
|
-
const tool3 = tools[toolName];
|
|
10203
|
-
if (!tool3) {
|
|
10204
|
-
return {
|
|
10205
|
-
success: false,
|
|
10206
|
-
error: new import_provider32.TypeValidationError({
|
|
10207
|
-
value: toolPart.input,
|
|
10208
|
-
cause: `No tool schema found for tool part ${toolName}`
|
|
10209
|
-
})
|
|
10210
|
-
};
|
|
10211
|
-
}
|
|
10212
|
-
if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error") {
|
|
10213
|
-
await (0, import_provider_utils33.validateTypes)({
|
|
10214
|
-
value: toolPart.input,
|
|
10215
|
-
schema: tool3.inputSchema
|
|
10216
|
-
});
|
|
10217
|
-
}
|
|
10218
|
-
if (toolPart.state === "output-available" && tool3.outputSchema) {
|
|
10219
|
-
await (0, import_provider_utils33.validateTypes)({
|
|
10220
|
-
value: toolPart.output,
|
|
10221
|
-
schema: tool3.outputSchema
|
|
10222
|
-
});
|
|
10223
|
-
}
|
|
10206
|
+
if (toolPart.state === "output-available" && tool3.outputSchema) {
|
|
10207
|
+
await (0, import_provider_utils33.validateTypes)({
|
|
10208
|
+
value: toolPart.output,
|
|
10209
|
+
schema: tool3.outputSchema
|
|
10210
|
+
});
|
|
10224
10211
|
}
|
|
10225
10212
|
}
|
|
10226
10213
|
}
|
|
10227
|
-
return {
|
|
10228
|
-
success: true,
|
|
10229
|
-
data: validatedMessages
|
|
10230
|
-
};
|
|
10231
|
-
} catch (error) {
|
|
10232
|
-
const err = error;
|
|
10233
|
-
return {
|
|
10234
|
-
success: false,
|
|
10235
|
-
error: err
|
|
10236
|
-
};
|
|
10237
10214
|
}
|
|
10238
|
-
|
|
10239
|
-
async function validateUIMessages({
|
|
10240
|
-
messages,
|
|
10241
|
-
metadataSchema,
|
|
10242
|
-
dataSchemas,
|
|
10243
|
-
tools
|
|
10244
|
-
}) {
|
|
10245
|
-
const response = await safeValidateUIMessages({
|
|
10246
|
-
messages,
|
|
10247
|
-
metadataSchema,
|
|
10248
|
-
dataSchemas,
|
|
10249
|
-
tools
|
|
10250
|
-
});
|
|
10251
|
-
if (!response.success)
|
|
10252
|
-
throw response.error;
|
|
10253
|
-
return response.data;
|
|
10215
|
+
return validatedMessages;
|
|
10254
10216
|
}
|
|
10255
10217
|
|
|
10256
10218
|
// src/ui-message-stream/create-ui-message-stream.ts
|
|
@@ -10471,12 +10433,10 @@ function readUIMessageStream({
|
|
|
10471
10433
|
jsonSchema,
|
|
10472
10434
|
lastAssistantMessageIsCompleteWithToolCalls,
|
|
10473
10435
|
modelMessageSchema,
|
|
10474
|
-
parseJsonEventStream,
|
|
10475
10436
|
parsePartialJson,
|
|
10476
10437
|
pipeTextStreamToResponse,
|
|
10477
10438
|
pipeUIMessageStreamToResponse,
|
|
10478
10439
|
readUIMessageStream,
|
|
10479
|
-
safeValidateUIMessages,
|
|
10480
10440
|
simulateReadableStream,
|
|
10481
10441
|
simulateStreamingMiddleware,
|
|
10482
10442
|
smoothStream,
|
|
@@ -10486,7 +10446,6 @@ function readUIMessageStream({
|
|
|
10486
10446
|
systemModelMessageSchema,
|
|
10487
10447
|
tool,
|
|
10488
10448
|
toolModelMessageSchema,
|
|
10489
|
-
uiMessageChunkSchema,
|
|
10490
10449
|
userModelMessageSchema,
|
|
10491
10450
|
validateUIMessages,
|
|
10492
10451
|
wrapLanguageModel,
|