ai 6.0.60 → 6.0.62

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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.62
4
+
5
+ ### Patch Changes
6
+
7
+ - 2810850: fix(ai): improve type validation error messages with field paths and entity identifiers
8
+ - Updated dependencies [2810850]
9
+ - @ai-sdk/provider-utils@4.0.11
10
+ - @ai-sdk/provider@3.0.6
11
+ - @ai-sdk/gateway@3.0.29
12
+
13
+ ## 6.0.61
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [1524271]
18
+ - @ai-sdk/gateway@3.0.28
19
+
3
20
  ## 6.0.60
4
21
 
5
22
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1104,7 +1104,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
1104
1104
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
1105
1105
 
1106
1106
  // src/version.ts
1107
- var VERSION = true ? "6.0.60" : "0.0.0-test";
1107
+ var VERSION = true ? "6.0.62" : "0.0.0-test";
1108
1108
 
1109
1109
  // src/util/download/download.ts
1110
1110
  var download = async ({ url }) => {
@@ -5050,7 +5050,11 @@ function processUIMessageStream({
5050
5050
  if (messageMetadataSchema != null) {
5051
5051
  await (0, import_provider_utils17.validateTypes)({
5052
5052
  value: mergedMetadata,
5053
- schema: messageMetadataSchema
5053
+ schema: messageMetadataSchema,
5054
+ context: {
5055
+ field: "message.metadata",
5056
+ entityId: state.message.id
5057
+ }
5054
5058
  });
5055
5059
  }
5056
5060
  state.message.metadata = mergedMetadata;
@@ -5404,9 +5408,18 @@ function processUIMessageStream({
5404
5408
  default: {
5405
5409
  if (isDataUIMessageChunk(chunk)) {
5406
5410
  if ((dataPartSchemas == null ? void 0 : dataPartSchemas[chunk.type]) != null) {
5411
+ const partIdx = state.message.parts.findIndex(
5412
+ (p) => "id" in p && "data" in p && p.id === chunk.id && p.type === chunk.type
5413
+ );
5414
+ const actualPartIdx = partIdx >= 0 ? partIdx : state.message.parts.length;
5407
5415
  await (0, import_provider_utils17.validateTypes)({
5408
5416
  value: chunk.data,
5409
- schema: dataPartSchemas[chunk.type]
5417
+ schema: dataPartSchemas[chunk.type],
5418
+ context: {
5419
+ field: `message.parts[${actualPartIdx}].data`,
5420
+ entityName: chunk.type,
5421
+ entityId: chunk.id
5422
+ }
5410
5423
  });
5411
5424
  }
5412
5425
  const dataChunk = chunk;
@@ -8276,65 +8289,88 @@ async function safeValidateUIMessages({
8276
8289
  schema: uiMessagesSchema
8277
8290
  });
8278
8291
  if (metadataSchema) {
8279
- for (const message of validatedMessages) {
8292
+ for (const [msgIdx, message] of validatedMessages.entries()) {
8280
8293
  await (0, import_provider_utils22.validateTypes)({
8281
8294
  value: message.metadata,
8282
- schema: metadataSchema
8283
- });
8284
- }
8285
- }
8286
- if (dataSchemas) {
8287
- for (const message of validatedMessages) {
8288
- const dataParts = message.parts.filter(
8289
- (part) => part.type.startsWith("data-")
8290
- );
8291
- for (const dataPart of dataParts) {
8292
- const dataName = dataPart.type.slice(5);
8293
- const dataSchema = dataSchemas[dataName];
8294
- if (!dataSchema) {
8295
- return {
8296
- success: false,
8297
- error: new import_provider28.TypeValidationError({
8298
- value: dataPart.data,
8299
- cause: `No data schema found for data part ${dataName}`
8300
- })
8301
- };
8295
+ schema: metadataSchema,
8296
+ context: {
8297
+ field: `messages[${msgIdx}].metadata`,
8298
+ entityId: message.id
8302
8299
  }
8303
- await (0, import_provider_utils22.validateTypes)({
8304
- value: dataPart.data,
8305
- schema: dataSchema
8306
- });
8307
- }
8300
+ });
8308
8301
  }
8309
8302
  }
8310
- if (tools) {
8311
- for (const message of validatedMessages) {
8312
- const toolParts = message.parts.filter(
8313
- (part) => part.type.startsWith("tool-")
8314
- );
8315
- for (const toolPart of toolParts) {
8316
- const toolName = toolPart.type.slice(5);
8317
- const tool2 = tools[toolName];
8318
- if (!tool2) {
8319
- return {
8320
- success: false,
8321
- error: new import_provider28.TypeValidationError({
8322
- value: toolPart.input,
8323
- cause: `No tool schema found for tool part ${toolName}`
8324
- })
8325
- };
8326
- }
8327
- if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error" && toolPart.input !== void 0) {
8303
+ if (dataSchemas || tools) {
8304
+ for (const [msgIdx, message] of validatedMessages.entries()) {
8305
+ for (const [partIdx, part] of message.parts.entries()) {
8306
+ if (dataSchemas && part.type.startsWith("data-")) {
8307
+ const dataPart = part;
8308
+ const dataName = dataPart.type.slice(5);
8309
+ const dataSchema = dataSchemas[dataName];
8310
+ if (!dataSchema) {
8311
+ return {
8312
+ success: false,
8313
+ error: new import_provider28.TypeValidationError({
8314
+ value: dataPart.data,
8315
+ cause: `No data schema found for data part ${dataName}`,
8316
+ context: {
8317
+ field: `messages[${msgIdx}].parts[${partIdx}].data`,
8318
+ entityName: dataName,
8319
+ entityId: dataPart.id
8320
+ }
8321
+ })
8322
+ };
8323
+ }
8328
8324
  await (0, import_provider_utils22.validateTypes)({
8329
- value: toolPart.input,
8330
- schema: tool2.inputSchema
8325
+ value: dataPart.data,
8326
+ schema: dataSchema,
8327
+ context: {
8328
+ field: `messages[${msgIdx}].parts[${partIdx}].data`,
8329
+ entityName: dataName,
8330
+ entityId: dataPart.id
8331
+ }
8331
8332
  });
8332
8333
  }
8333
- if (toolPart.state === "output-available" && tool2.outputSchema) {
8334
- await (0, import_provider_utils22.validateTypes)({
8335
- value: toolPart.output,
8336
- schema: tool2.outputSchema
8337
- });
8334
+ if (tools && part.type.startsWith("tool-")) {
8335
+ const toolPart = part;
8336
+ const toolName = toolPart.type.slice(5);
8337
+ const tool2 = tools[toolName];
8338
+ if (!tool2) {
8339
+ return {
8340
+ success: false,
8341
+ error: new import_provider28.TypeValidationError({
8342
+ value: toolPart.input,
8343
+ cause: `No tool schema found for tool part ${toolName}`,
8344
+ context: {
8345
+ field: `messages[${msgIdx}].parts[${partIdx}].input`,
8346
+ entityName: toolName,
8347
+ entityId: toolPart.toolCallId
8348
+ }
8349
+ })
8350
+ };
8351
+ }
8352
+ if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error" && toolPart.input !== void 0) {
8353
+ await (0, import_provider_utils22.validateTypes)({
8354
+ value: toolPart.input,
8355
+ schema: tool2.inputSchema,
8356
+ context: {
8357
+ field: `messages[${msgIdx}].parts[${partIdx}].input`,
8358
+ entityName: toolName,
8359
+ entityId: toolPart.toolCallId
8360
+ }
8361
+ });
8362
+ }
8363
+ if (toolPart.state === "output-available" && tool2.outputSchema) {
8364
+ await (0, import_provider_utils22.validateTypes)({
8365
+ value: toolPart.output,
8366
+ schema: tool2.outputSchema,
8367
+ context: {
8368
+ field: `messages[${msgIdx}].parts[${partIdx}].output`,
8369
+ entityName: toolName,
8370
+ entityId: toolPart.toolCallId
8371
+ }
8372
+ });
8373
+ }
8338
8374
  }
8339
8375
  }
8340
8376
  }