ai 5.1.0-beta.0 → 5.1.0-beta.1

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.mjs CHANGED
@@ -678,7 +678,7 @@ import {
678
678
  } from "@ai-sdk/provider-utils";
679
679
 
680
680
  // src/version.ts
681
- var VERSION = true ? "5.1.0-beta.0" : "0.0.0-test";
681
+ var VERSION = true ? "5.1.0-beta.1" : "0.0.0-test";
682
682
 
683
683
  // src/util/download/download.ts
684
684
  var download = async ({ url }) => {
@@ -10117,82 +10117,118 @@ var uiMessageSchema = z10.object({
10117
10117
  ])
10118
10118
  )
10119
10119
  });
10120
- async function validateUIMessages({
10120
+ async function safeValidateUIMessages({
10121
10121
  messages,
10122
10122
  metadataSchema,
10123
10123
  dataSchemas,
10124
10124
  tools
10125
10125
  }) {
10126
- if (messages == null) {
10127
- throw new InvalidArgumentError({
10128
- parameter: "messages",
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
- message: "messages parameter must be provided"
10139
+ schema: z10.array(uiMessageSchema)
10131
10140
  });
10132
- }
10133
- const validatedMessages = await validateTypes2({
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: dataPart.data,
10161
- schema: dataSchema
10144
+ value: message.metadata,
10145
+ schema: metadataSchema
10162
10146
  });
10163
10147
  }
10164
10148
  }
10165
- }
10166
- if (tools) {
10167
- for (const message of validatedMessages) {
10168
- const toolParts = message.parts.filter(
10169
- (part) => part.type.startsWith("tool-")
10170
- );
10171
- for (const toolPart of toolParts) {
10172
- const toolName = toolPart.type.slice(5);
10173
- const tool3 = tools[toolName];
10174
- if (!tool3) {
10175
- throw new TypeValidationError4({
10176
- value: toolPart.input,
10177
- cause: `No tool schema found for tool part ${toolName}`
10178
- });
10179
- }
10180
- if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error") {
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: toolPart.input,
10183
- schema: tool3.inputSchema
10167
+ value: dataPart.data,
10168
+ schema: dataSchema
10184
10169
  });
10185
10170
  }
10186
- if (toolPart.state === "output-available" && tool3.outputSchema) {
10187
- await validateTypes2({
10188
- value: toolPart.output,
10189
- schema: tool3.outputSchema
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
- return validatedMessages;
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
@@ -10419,6 +10455,7 @@ export {
10419
10455
  pipeTextStreamToResponse,
10420
10456
  pipeUIMessageStreamToResponse,
10421
10457
  readUIMessageStream,
10458
+ safeValidateUIMessages,
10422
10459
  simulateReadableStream,
10423
10460
  simulateStreamingMiddleware,
10424
10461
  smoothStream,