ai 5.0.56 → 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 -73
- package/dist/index.d.mts +34 -156
- package/dist/index.d.ts +34 -156
- package/dist/index.js +82 -135
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +82 -133
- 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()
|
|
@@ -4656,7 +4658,7 @@ var DefaultStreamTextResult = class {
|
|
|
4656
4658
|
let activeReasoningContent = {};
|
|
4657
4659
|
const eventProcessor = new TransformStream({
|
|
4658
4660
|
async transform(chunk, controller) {
|
|
4659
|
-
var _a17, _b, _c
|
|
4661
|
+
var _a17, _b, _c;
|
|
4660
4662
|
controller.enqueue(chunk);
|
|
4661
4663
|
const { part } = chunk;
|
|
4662
4664
|
if (part.type === "text-delta" || part.type === "reasoning-delta" || part.type === "source" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-input-start" || part.type === "tool-input-delta" || part.type === "raw") {
|
|
@@ -4689,18 +4691,6 @@ var DefaultStreamTextResult = class {
|
|
|
4689
4691
|
activeText.providerMetadata = (_a17 = part.providerMetadata) != null ? _a17 : activeText.providerMetadata;
|
|
4690
4692
|
}
|
|
4691
4693
|
if (part.type === "text-end") {
|
|
4692
|
-
const activeText = activeTextContent[part.id];
|
|
4693
|
-
if (activeText == null) {
|
|
4694
|
-
controller.enqueue({
|
|
4695
|
-
part: {
|
|
4696
|
-
type: "error",
|
|
4697
|
-
error: `text part ${part.id} not found`
|
|
4698
|
-
},
|
|
4699
|
-
partialOutput: void 0
|
|
4700
|
-
});
|
|
4701
|
-
return;
|
|
4702
|
-
}
|
|
4703
|
-
activeText.providerMetadata = (_b = part.providerMetadata) != null ? _b : activeText.providerMetadata;
|
|
4704
4694
|
delete activeTextContent[part.id];
|
|
4705
4695
|
}
|
|
4706
4696
|
if (part.type === "reasoning-start") {
|
|
@@ -4724,7 +4714,7 @@ var DefaultStreamTextResult = class {
|
|
|
4724
4714
|
return;
|
|
4725
4715
|
}
|
|
4726
4716
|
activeReasoning.text += part.text;
|
|
4727
|
-
activeReasoning.providerMetadata = (
|
|
4717
|
+
activeReasoning.providerMetadata = (_b = part.providerMetadata) != null ? _b : activeReasoning.providerMetadata;
|
|
4728
4718
|
}
|
|
4729
4719
|
if (part.type === "reasoning-end") {
|
|
4730
4720
|
const activeReasoning = activeReasoningContent[part.id];
|
|
@@ -4738,7 +4728,7 @@ var DefaultStreamTextResult = class {
|
|
|
4738
4728
|
});
|
|
4739
4729
|
return;
|
|
4740
4730
|
}
|
|
4741
|
-
activeReasoning.providerMetadata = (
|
|
4731
|
+
activeReasoning.providerMetadata = (_c = part.providerMetadata) != null ? _c : activeReasoning.providerMetadata;
|
|
4742
4732
|
delete activeReasoningContent[part.id];
|
|
4743
4733
|
}
|
|
4744
4734
|
if (part.type === "file") {
|
|
@@ -9733,11 +9723,9 @@ var AbstractChat = class {
|
|
|
9733
9723
|
}
|
|
9734
9724
|
};
|
|
9735
9725
|
this.addToolResult = async ({
|
|
9736
|
-
state = "output-available",
|
|
9737
9726
|
tool: tool3,
|
|
9738
9727
|
toolCallId,
|
|
9739
|
-
output
|
|
9740
|
-
errorText
|
|
9728
|
+
output
|
|
9741
9729
|
}) => this.jobExecutor.run(async () => {
|
|
9742
9730
|
var _a17, _b;
|
|
9743
9731
|
const messages = this.state.messages;
|
|
@@ -9745,16 +9733,16 @@ var AbstractChat = class {
|
|
|
9745
9733
|
this.state.replaceMessage(messages.length - 1, {
|
|
9746
9734
|
...lastMessage,
|
|
9747
9735
|
parts: lastMessage.parts.map(
|
|
9748
|
-
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state
|
|
9736
|
+
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state: "output-available", output } : part
|
|
9749
9737
|
)
|
|
9750
9738
|
});
|
|
9751
9739
|
if (this.activeResponse) {
|
|
9752
9740
|
this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(
|
|
9753
9741
|
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? {
|
|
9754
9742
|
...part,
|
|
9755
|
-
state,
|
|
9743
|
+
state: "output-available",
|
|
9756
9744
|
output,
|
|
9757
|
-
errorText
|
|
9745
|
+
errorText: void 0
|
|
9758
9746
|
} : part
|
|
9759
9747
|
);
|
|
9760
9748
|
}
|
|
@@ -9963,9 +9951,7 @@ function lastAssistantMessageIsCompleteWithToolCalls({
|
|
|
9963
9951
|
return part.type === "step-start" ? index : lastIndex;
|
|
9964
9952
|
}, -1);
|
|
9965
9953
|
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolOrDynamicToolUIPart);
|
|
9966
|
-
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every(
|
|
9967
|
-
(part) => part.state === "output-available" || part.state === "output-error"
|
|
9968
|
-
);
|
|
9954
|
+
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => part.state === "output-available");
|
|
9969
9955
|
}
|
|
9970
9956
|
|
|
9971
9957
|
// src/ui/transform-text-to-ui-message-stream.ts
|
|
@@ -10151,118 +10137,82 @@ var uiMessageSchema = import_v410.z.object({
|
|
|
10151
10137
|
])
|
|
10152
10138
|
)
|
|
10153
10139
|
});
|
|
10154
|
-
async function
|
|
10140
|
+
async function validateUIMessages({
|
|
10155
10141
|
messages,
|
|
10156
10142
|
metadataSchema,
|
|
10157
10143
|
dataSchemas,
|
|
10158
10144
|
tools
|
|
10159
10145
|
}) {
|
|
10160
|
-
|
|
10161
|
-
|
|
10162
|
-
|
|
10163
|
-
success: false,
|
|
10164
|
-
error: new InvalidArgumentError({
|
|
10165
|
-
parameter: "messages",
|
|
10166
|
-
value: messages,
|
|
10167
|
-
message: "messages parameter must be provided"
|
|
10168
|
-
})
|
|
10169
|
-
};
|
|
10170
|
-
}
|
|
10171
|
-
const validatedMessages = await (0, import_provider_utils33.validateTypes)({
|
|
10146
|
+
if (messages == null) {
|
|
10147
|
+
throw new InvalidArgumentError({
|
|
10148
|
+
parameter: "messages",
|
|
10172
10149
|
value: messages,
|
|
10173
|
-
|
|
10150
|
+
message: "messages parameter must be provided"
|
|
10174
10151
|
});
|
|
10175
|
-
|
|
10176
|
-
|
|
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
|
+
}
|
|
10177
10179
|
await (0, import_provider_utils33.validateTypes)({
|
|
10178
|
-
value:
|
|
10179
|
-
schema:
|
|
10180
|
+
value: dataPart.data,
|
|
10181
|
+
schema: dataSchema
|
|
10180
10182
|
});
|
|
10181
10183
|
}
|
|
10182
10184
|
}
|
|
10183
|
-
|
|
10184
|
-
|
|
10185
|
-
|
|
10186
|
-
|
|
10187
|
-
)
|
|
10188
|
-
|
|
10189
|
-
|
|
10190
|
-
|
|
10191
|
-
|
|
10192
|
-
|
|
10193
|
-
|
|
10194
|
-
|
|
10195
|
-
|
|
10196
|
-
|
|
10197
|
-
|
|
10198
|
-
|
|
10199
|
-
}
|
|
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") {
|
|
10200
10201
|
await (0, import_provider_utils33.validateTypes)({
|
|
10201
|
-
value:
|
|
10202
|
-
schema:
|
|
10202
|
+
value: toolPart.input,
|
|
10203
|
+
schema: tool3.inputSchema
|
|
10203
10204
|
});
|
|
10204
10205
|
}
|
|
10205
|
-
|
|
10206
|
-
|
|
10207
|
-
|
|
10208
|
-
|
|
10209
|
-
|
|
10210
|
-
(part) => part.type.startsWith("tool-")
|
|
10211
|
-
);
|
|
10212
|
-
for (const toolPart of toolParts) {
|
|
10213
|
-
const toolName = toolPart.type.slice(5);
|
|
10214
|
-
const tool3 = tools[toolName];
|
|
10215
|
-
if (!tool3) {
|
|
10216
|
-
return {
|
|
10217
|
-
success: false,
|
|
10218
|
-
error: new import_provider32.TypeValidationError({
|
|
10219
|
-
value: toolPart.input,
|
|
10220
|
-
cause: `No tool schema found for tool part ${toolName}`
|
|
10221
|
-
})
|
|
10222
|
-
};
|
|
10223
|
-
}
|
|
10224
|
-
if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error") {
|
|
10225
|
-
await (0, import_provider_utils33.validateTypes)({
|
|
10226
|
-
value: toolPart.input,
|
|
10227
|
-
schema: tool3.inputSchema
|
|
10228
|
-
});
|
|
10229
|
-
}
|
|
10230
|
-
if (toolPart.state === "output-available" && tool3.outputSchema) {
|
|
10231
|
-
await (0, import_provider_utils33.validateTypes)({
|
|
10232
|
-
value: toolPart.output,
|
|
10233
|
-
schema: tool3.outputSchema
|
|
10234
|
-
});
|
|
10235
|
-
}
|
|
10206
|
+
if (toolPart.state === "output-available" && tool3.outputSchema) {
|
|
10207
|
+
await (0, import_provider_utils33.validateTypes)({
|
|
10208
|
+
value: toolPart.output,
|
|
10209
|
+
schema: tool3.outputSchema
|
|
10210
|
+
});
|
|
10236
10211
|
}
|
|
10237
10212
|
}
|
|
10238
10213
|
}
|
|
10239
|
-
return {
|
|
10240
|
-
success: true,
|
|
10241
|
-
data: validatedMessages
|
|
10242
|
-
};
|
|
10243
|
-
} catch (error) {
|
|
10244
|
-
const err = error;
|
|
10245
|
-
return {
|
|
10246
|
-
success: false,
|
|
10247
|
-
error: err
|
|
10248
|
-
};
|
|
10249
10214
|
}
|
|
10250
|
-
|
|
10251
|
-
async function validateUIMessages({
|
|
10252
|
-
messages,
|
|
10253
|
-
metadataSchema,
|
|
10254
|
-
dataSchemas,
|
|
10255
|
-
tools
|
|
10256
|
-
}) {
|
|
10257
|
-
const response = await safeValidateUIMessages({
|
|
10258
|
-
messages,
|
|
10259
|
-
metadataSchema,
|
|
10260
|
-
dataSchemas,
|
|
10261
|
-
tools
|
|
10262
|
-
});
|
|
10263
|
-
if (!response.success)
|
|
10264
|
-
throw response.error;
|
|
10265
|
-
return response.data;
|
|
10215
|
+
return validatedMessages;
|
|
10266
10216
|
}
|
|
10267
10217
|
|
|
10268
10218
|
// src/ui-message-stream/create-ui-message-stream.ts
|
|
@@ -10483,12 +10433,10 @@ function readUIMessageStream({
|
|
|
10483
10433
|
jsonSchema,
|
|
10484
10434
|
lastAssistantMessageIsCompleteWithToolCalls,
|
|
10485
10435
|
modelMessageSchema,
|
|
10486
|
-
parseJsonEventStream,
|
|
10487
10436
|
parsePartialJson,
|
|
10488
10437
|
pipeTextStreamToResponse,
|
|
10489
10438
|
pipeUIMessageStreamToResponse,
|
|
10490
10439
|
readUIMessageStream,
|
|
10491
|
-
safeValidateUIMessages,
|
|
10492
10440
|
simulateReadableStream,
|
|
10493
10441
|
simulateStreamingMiddleware,
|
|
10494
10442
|
smoothStream,
|
|
@@ -10498,7 +10446,6 @@ function readUIMessageStream({
|
|
|
10498
10446
|
systemModelMessageSchema,
|
|
10499
10447
|
tool,
|
|
10500
10448
|
toolModelMessageSchema,
|
|
10501
|
-
uiMessageChunkSchema,
|
|
10502
10449
|
userModelMessageSchema,
|
|
10503
10450
|
validateUIMessages,
|
|
10504
10451
|
wrapLanguageModel,
|