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/dist/index.js CHANGED
@@ -103,10 +103,12 @@ __export(src_exports, {
103
103
  jsonSchema: () => import_provider_utils35.jsonSchema,
104
104
  lastAssistantMessageIsCompleteWithToolCalls: () => lastAssistantMessageIsCompleteWithToolCalls,
105
105
  modelMessageSchema: () => modelMessageSchema,
106
+ parseJsonEventStream: () => import_provider_utils35.parseJsonEventStream,
106
107
  parsePartialJson: () => parsePartialJson,
107
108
  pipeTextStreamToResponse: () => pipeTextStreamToResponse,
108
109
  pipeUIMessageStreamToResponse: () => pipeUIMessageStreamToResponse,
109
110
  readUIMessageStream: () => readUIMessageStream,
111
+ safeValidateUIMessages: () => safeValidateUIMessages,
110
112
  simulateReadableStream: () => simulateReadableStream,
111
113
  simulateStreamingMiddleware: () => simulateStreamingMiddleware,
112
114
  smoothStream: () => smoothStream,
@@ -116,6 +118,7 @@ __export(src_exports, {
116
118
  systemModelMessageSchema: () => systemModelMessageSchema,
117
119
  tool: () => import_provider_utils35.tool,
118
120
  toolModelMessageSchema: () => toolModelMessageSchema,
121
+ uiMessageChunkSchema: () => uiMessageChunkSchema,
119
122
  userModelMessageSchema: () => userModelMessageSchema,
120
123
  validateUIMessages: () => validateUIMessages,
121
124
  wrapLanguageModel: () => wrapLanguageModel,
@@ -555,7 +558,7 @@ function resolveLanguageModel(model) {
555
558
  }
556
559
  function resolveEmbeddingModel(model) {
557
560
  if (typeof model !== "string") {
558
- if (model.specificationVersion !== "v2") {
561
+ if (model.specificationVersion !== "v3") {
559
562
  throw new UnsupportedModelVersionError({
560
563
  version: model.specificationVersion,
561
564
  provider: model.provider,
@@ -765,7 +768,7 @@ function detectMediaType({
765
768
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
766
769
 
767
770
  // src/version.ts
768
- var VERSION = true ? "5.1.0-beta.0" : "0.0.0-test";
771
+ var VERSION = true ? "5.1.0-beta.10" : "0.0.0-test";
769
772
 
770
773
  // src/util/download/download.ts
771
774
  var download = async ({ url }) => {
@@ -1055,12 +1058,12 @@ async function downloadAssets(messages, download2, supportedUrls) {
1055
1058
  }));
1056
1059
  const downloadedFiles = await download2(plannedDownloads);
1057
1060
  return Object.fromEntries(
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
- ])
1061
+ downloadedFiles.map(
1062
+ (file, index) => file == null ? null : [
1063
+ plannedDownloads[index].url.toString(),
1064
+ { data: file.data, mediaType: file.mediaType }
1065
+ ]
1066
+ ).filter((file) => file != null)
1064
1067
  );
1065
1068
  }
1066
1069
  function convertPartToLanguageModelPart(part, downloadedAssets) {
@@ -2987,11 +2990,6 @@ var uiMessageChunkSchema = import_v47.z.union([
2987
2990
  providerExecuted: import_v47.z.boolean().optional(),
2988
2991
  dynamic: import_v47.z.boolean().optional()
2989
2992
  }),
2990
- import_v47.z.strictObject({
2991
- type: import_v47.z.literal("reasoning"),
2992
- text: import_v47.z.string(),
2993
- providerMetadata: providerMetadataSchema.optional()
2994
- }),
2995
2993
  import_v47.z.strictObject({
2996
2994
  type: import_v47.z.literal("reasoning-start"),
2997
2995
  id: import_v47.z.string(),
@@ -3008,9 +3006,6 @@ var uiMessageChunkSchema = import_v47.z.union([
3008
3006
  id: import_v47.z.string(),
3009
3007
  providerMetadata: providerMetadataSchema.optional()
3010
3008
  }),
3011
- import_v47.z.strictObject({
3012
- type: import_v47.z.literal("reasoning-part-finish")
3013
- }),
3014
3009
  import_v47.z.strictObject({
3015
3010
  type: import_v47.z.literal("source-url"),
3016
3011
  sourceId: import_v47.z.string(),
@@ -3033,7 +3028,10 @@ var uiMessageChunkSchema = import_v47.z.union([
3033
3028
  providerMetadata: providerMetadataSchema.optional()
3034
3029
  }),
3035
3030
  import_v47.z.strictObject({
3036
- type: import_v47.z.string().startsWith("data-"),
3031
+ type: import_v47.z.custom(
3032
+ (value) => typeof value === "string" && value.startsWith("data-"),
3033
+ { message: 'Type must start with "data-"' }
3034
+ ),
3037
3035
  id: import_v47.z.string().optional(),
3038
3036
  data: import_v47.z.unknown(),
3039
3037
  transient: import_v47.z.boolean().optional()
@@ -6383,7 +6381,7 @@ async function generateImage({
6383
6381
  headers
6384
6382
  }) {
6385
6383
  var _a17, _b;
6386
- if (model.specificationVersion !== "v2") {
6384
+ if (model.specificationVersion !== "v3") {
6387
6385
  throw new UnsupportedModelVersionError({
6388
6386
  version: model.specificationVersion,
6389
6387
  provider: model.provider,
@@ -9723,9 +9721,11 @@ var AbstractChat = class {
9723
9721
  }
9724
9722
  };
9725
9723
  this.addToolResult = async ({
9724
+ state = "output-available",
9726
9725
  tool: tool3,
9727
9726
  toolCallId,
9728
- output
9727
+ output,
9728
+ errorText
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: "output-available", output } : part
9736
+ (part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state, output, errorText } : 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: "output-available",
9743
+ state,
9744
9744
  output,
9745
- errorText: void 0
9745
+ errorText
9746
9746
  } : part
9747
9747
  );
9748
9748
  }
@@ -9951,7 +9951,9 @@ 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((part) => part.state === "output-available");
9954
+ return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every(
9955
+ (part) => part.state === "output-available" || part.state === "output-error"
9956
+ );
9955
9957
  }
9956
9958
 
9957
9959
  // src/ui/transform-text-to-ui-message-stream.ts
@@ -10137,82 +10139,118 @@ var uiMessageSchema = import_v410.z.object({
10137
10139
  ])
10138
10140
  )
10139
10141
  });
10140
- async function validateUIMessages({
10142
+ async function safeValidateUIMessages({
10141
10143
  messages,
10142
10144
  metadataSchema,
10143
10145
  dataSchemas,
10144
10146
  tools
10145
10147
  }) {
10146
- if (messages == null) {
10147
- throw new InvalidArgumentError({
10148
- parameter: "messages",
10148
+ try {
10149
+ if (messages == null) {
10150
+ return {
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)({
10149
10160
  value: messages,
10150
- message: "messages parameter must be provided"
10161
+ schema: import_v410.z.array(uiMessageSchema)
10151
10162
  });
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
- }
10163
+ if (metadataSchema) {
10164
+ for (const message of validatedMessages) {
10179
10165
  await (0, import_provider_utils33.validateTypes)({
10180
- value: dataPart.data,
10181
- schema: dataSchema
10166
+ value: message.metadata,
10167
+ schema: metadataSchema
10182
10168
  });
10183
10169
  }
10184
10170
  }
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") {
10171
+ if (dataSchemas) {
10172
+ for (const message of validatedMessages) {
10173
+ const dataParts = message.parts.filter(
10174
+ (part) => part.type.startsWith("data-")
10175
+ );
10176
+ for (const dataPart of dataParts) {
10177
+ const dataName = dataPart.type.slice(5);
10178
+ const dataSchema = dataSchemas[dataName];
10179
+ if (!dataSchema) {
10180
+ return {
10181
+ success: false,
10182
+ error: new import_provider32.TypeValidationError({
10183
+ value: dataPart.data,
10184
+ cause: `No data schema found for data part ${dataName}`
10185
+ })
10186
+ };
10187
+ }
10201
10188
  await (0, import_provider_utils33.validateTypes)({
10202
- value: toolPart.input,
10203
- schema: tool3.inputSchema
10189
+ value: dataPart.data,
10190
+ schema: dataSchema
10204
10191
  });
10205
10192
  }
10206
- if (toolPart.state === "output-available" && tool3.outputSchema) {
10207
- await (0, import_provider_utils33.validateTypes)({
10208
- value: toolPart.output,
10209
- schema: tool3.outputSchema
10210
- });
10193
+ }
10194
+ }
10195
+ if (tools) {
10196
+ for (const message of validatedMessages) {
10197
+ const toolParts = message.parts.filter(
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
+ }
10211
10224
  }
10212
10225
  }
10213
10226
  }
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
+ };
10214
10237
  }
10215
- return validatedMessages;
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;
10216
10254
  }
10217
10255
 
10218
10256
  // src/ui-message-stream/create-ui-message-stream.ts
@@ -10433,10 +10471,12 @@ function readUIMessageStream({
10433
10471
  jsonSchema,
10434
10472
  lastAssistantMessageIsCompleteWithToolCalls,
10435
10473
  modelMessageSchema,
10474
+ parseJsonEventStream,
10436
10475
  parsePartialJson,
10437
10476
  pipeTextStreamToResponse,
10438
10477
  pipeUIMessageStreamToResponse,
10439
10478
  readUIMessageStream,
10479
+ safeValidateUIMessages,
10440
10480
  simulateReadableStream,
10441
10481
  simulateStreamingMiddleware,
10442
10482
  smoothStream,
@@ -10446,6 +10486,7 @@ function readUIMessageStream({
10446
10486
  systemModelMessageSchema,
10447
10487
  tool,
10448
10488
  toolModelMessageSchema,
10489
+ uiMessageChunkSchema,
10449
10490
  userModelMessageSchema,
10450
10491
  validateUIMessages,
10451
10492
  wrapLanguageModel,