ai 5.0.263 → 5.0.265

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,30 @@
1
1
  # ai
2
2
 
3
+ ## 5.0.265
4
+
5
+ ### Patch Changes
6
+
7
+ - bf29419: chore: enable dead code lint rules
8
+ - 0519802: fix(ai): preserve parsed metadata and data values when validating UI messages
9
+ - Updated dependencies [0430ee6]
10
+ - Updated dependencies [bf29419]
11
+ - Updated dependencies [14ecfdc]
12
+ - @ai-sdk/gateway@2.0.157
13
+ - @ai-sdk/provider-utils@3.0.39
14
+
15
+ ## 5.0.264
16
+
17
+ ### Patch Changes
18
+
19
+ - 594787e: fix(provider): preserve opaque file URI strings for provider serialization
20
+ - 7b19d17: fix(ai): prevent duplicate content types in chat transport requests
21
+ - 907e4c9: Fix streamed tool input callbacks firing out of order on newer Node.js versions by awaiting start and delta callbacks before invoking `onInputAvailable`.
22
+ - Updated dependencies [594787e]
23
+ - Updated dependencies [391ad4a]
24
+ - @ai-sdk/provider@2.0.5
25
+ - @ai-sdk/gateway@2.0.156
26
+ - @ai-sdk/provider-utils@3.0.38
27
+
3
28
  ## 5.0.263
4
29
 
5
30
  ### Patch Changes
package/dist/index.js CHANGED
@@ -816,7 +816,7 @@ function detectMediaType({
816
816
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
817
817
 
818
818
  // src/version.ts
819
- var VERSION = true ? "5.0.263" : "0.0.0-test";
819
+ var VERSION = true ? "5.0.265" : "0.0.0-test";
820
820
 
821
821
  // src/util/download/download.ts
822
822
  var download = async ({
@@ -1026,12 +1026,14 @@ function convertToLanguageModelMessage({
1026
1026
  const { data, mediaType } = convertToLanguageModelV2DataContent(
1027
1027
  part.data
1028
1028
  );
1029
+ const originalUrl = getOriginalUrl(part.data, data);
1029
1030
  return {
1030
1031
  type: "file",
1031
1032
  data,
1032
1033
  filename: part.filename,
1033
1034
  mediaType: mediaType != null ? mediaType : part.mediaType,
1034
- providerOptions
1035
+ providerOptions,
1036
+ ...originalUrl != null ? { originalUrl } : {}
1035
1037
  };
1036
1038
  }
1037
1039
  case "reasoning": {
@@ -1127,6 +1129,9 @@ async function downloadAssets(messages, download2, supportedUrls) {
1127
1129
  ).filter((file) => file != null)
1128
1130
  );
1129
1131
  }
1132
+ function getOriginalUrl(originalData, convertedData) {
1133
+ return typeof originalData === "string" && convertedData instanceof URL && convertedData.toString() !== originalData ? originalData : void 0;
1134
+ }
1130
1135
  function convertPartToLanguageModelPart(part, downloadedAssets) {
1131
1136
  var _a16;
1132
1137
  if (part.type === "text") {
@@ -1151,11 +1156,13 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1151
1156
  const { data: convertedData, mediaType: convertedMediaType } = convertToLanguageModelV2DataContent(originalData);
1152
1157
  let mediaType = convertedMediaType != null ? convertedMediaType : part.mediaType;
1153
1158
  let data = convertedData;
1159
+ let originalUrl = getOriginalUrl(originalData, convertedData);
1154
1160
  if (data instanceof URL) {
1155
1161
  const downloadedFile = downloadedAssets[data.toString()];
1156
1162
  if (downloadedFile) {
1157
1163
  data = downloadedFile.data;
1158
1164
  mediaType != null ? mediaType : mediaType = downloadedFile.mediaType;
1165
+ originalUrl = void 0;
1159
1166
  }
1160
1167
  }
1161
1168
  switch (type) {
@@ -1169,7 +1176,8 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1169
1176
  // any image
1170
1177
  filename: void 0,
1171
1178
  data,
1172
- providerOptions: part.providerOptions
1179
+ providerOptions: part.providerOptions,
1180
+ ...originalUrl != null ? { originalUrl } : {}
1173
1181
  };
1174
1182
  }
1175
1183
  case "file": {
@@ -1181,7 +1189,8 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1181
1189
  mediaType,
1182
1190
  filename: part.filename,
1183
1191
  data,
1184
- providerOptions: part.providerOptions
1192
+ providerOptions: part.providerOptions,
1193
+ ...originalUrl != null ? { originalUrl } : {}
1185
1194
  };
1186
1195
  }
1187
1196
  }
@@ -2016,8 +2025,8 @@ var DefaultGeneratedFile = class {
2016
2025
  }
2017
2026
  };
2018
2027
  var DefaultGeneratedFileWithType = class extends DefaultGeneratedFile {
2019
- constructor(options) {
2020
- super(options);
2028
+ constructor() {
2029
+ super(...arguments);
2021
2030
  this.type = "file";
2022
2031
  }
2023
2032
  };
@@ -2985,8 +2994,6 @@ function writeToServerResponse({
2985
2994
  });
2986
2995
  }
2987
2996
  }
2988
- } catch (error) {
2989
- throw error;
2990
2997
  } finally {
2991
2998
  response.end();
2992
2999
  }
@@ -4616,8 +4623,10 @@ function runToolsTransformation({
4616
4623
  }
4617
4624
  });
4618
4625
  }
4626
+ const activeToolCallToolNames = /* @__PURE__ */ new Map();
4619
4627
  const forwardStream = new TransformStream({
4620
4628
  async transform(chunk, controller) {
4629
+ var _a16, _b, _c, _d;
4621
4630
  const chunkType = chunk.type;
4622
4631
  switch (chunkType) {
4623
4632
  case "stream-start":
@@ -4627,9 +4636,6 @@ function runToolsTransformation({
4627
4636
  case "reasoning-start":
4628
4637
  case "reasoning-delta":
4629
4638
  case "reasoning-end":
4630
- case "tool-input-start":
4631
- case "tool-input-delta":
4632
- case "tool-input-end":
4633
4639
  case "source":
4634
4640
  case "response-metadata":
4635
4641
  case "error":
@@ -4637,6 +4643,36 @@ function runToolsTransformation({
4637
4643
  controller.enqueue(chunk);
4638
4644
  break;
4639
4645
  }
4646
+ case "tool-input-start": {
4647
+ activeToolCallToolNames.set(chunk.id, chunk.toolName);
4648
+ await ((_b = (_a16 = tools == null ? void 0 : tools[chunk.toolName]) == null ? void 0 : _a16.onInputStart) == null ? void 0 : _b.call(_a16, {
4649
+ toolCallId: chunk.id,
4650
+ messages,
4651
+ abortSignal,
4652
+ experimental_context
4653
+ }));
4654
+ controller.enqueue(chunk);
4655
+ break;
4656
+ }
4657
+ case "tool-input-delta": {
4658
+ const toolName = activeToolCallToolNames.get(chunk.id);
4659
+ if (toolName != null) {
4660
+ await ((_d = (_c = tools == null ? void 0 : tools[toolName]) == null ? void 0 : _c.onInputDelta) == null ? void 0 : _d.call(_c, {
4661
+ inputTextDelta: chunk.delta,
4662
+ toolCallId: chunk.id,
4663
+ messages,
4664
+ abortSignal,
4665
+ experimental_context
4666
+ }));
4667
+ }
4668
+ controller.enqueue(chunk);
4669
+ break;
4670
+ }
4671
+ case "tool-input-end": {
4672
+ activeToolCallToolNames.delete(chunk.id);
4673
+ controller.enqueue(chunk);
4674
+ break;
4675
+ }
4640
4676
  case "file": {
4641
4677
  controller.enqueue({
4642
4678
  type: "file",
@@ -5381,7 +5417,6 @@ var DefaultStreamTextResult = class {
5381
5417
  const stepToolCalls = [];
5382
5418
  const stepToolOutputs = [];
5383
5419
  let warnings;
5384
- const activeToolCallToolNames = {};
5385
5420
  let stepFinishReason = "unknown";
5386
5421
  let stepUsage = {
5387
5422
  inputTokens: void 0,
@@ -5499,16 +5534,7 @@ var DefaultStreamTextResult = class {
5499
5534
  break;
5500
5535
  }
5501
5536
  case "tool-input-start": {
5502
- activeToolCallToolNames[chunk.id] = chunk.toolName;
5503
5537
  const tool2 = stepToolSet == null ? void 0 : stepToolSet[chunk.toolName];
5504
- if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
5505
- await tool2.onInputStart({
5506
- toolCallId: chunk.id,
5507
- messages: stepInputMessages,
5508
- abortSignal,
5509
- experimental_context
5510
- });
5511
- }
5512
5538
  controller.enqueue({
5513
5539
  ...chunk,
5514
5540
  dynamic: (tool2 == null ? void 0 : tool2.type) === "dynamic"
@@ -5516,22 +5542,10 @@ var DefaultStreamTextResult = class {
5516
5542
  break;
5517
5543
  }
5518
5544
  case "tool-input-end": {
5519
- delete activeToolCallToolNames[chunk.id];
5520
5545
  controller.enqueue(chunk);
5521
5546
  break;
5522
5547
  }
5523
5548
  case "tool-input-delta": {
5524
- const toolName = activeToolCallToolNames[chunk.id];
5525
- const tool2 = stepToolSet == null ? void 0 : stepToolSet[toolName];
5526
- if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
5527
- await tool2.onInputDelta({
5528
- inputTextDelta: chunk.delta,
5529
- toolCallId: chunk.id,
5530
- messages: stepInputMessages,
5531
- abortSignal,
5532
- experimental_context
5533
- });
5534
- }
5535
5549
  controller.enqueue(chunk);
5536
5550
  break;
5537
5551
  }
@@ -6637,7 +6651,6 @@ async function embedMany({
6637
6651
  }),
6638
6652
  tracer,
6639
6653
  fn: async (span) => {
6640
- var _a16;
6641
6654
  const [
6642
6655
  maxEmbeddingsPerCall,
6643
6656
  maxInputBytesPerCall,
@@ -6670,7 +6683,7 @@ async function embedMany({
6670
6683
  }),
6671
6684
  tracer,
6672
6685
  fn: async (doEmbedSpan) => {
6673
- var _a17;
6686
+ var _a16;
6674
6687
  const modelResponse = await model.doEmbed({
6675
6688
  values,
6676
6689
  abortSignal,
@@ -6678,7 +6691,7 @@ async function embedMany({
6678
6691
  providerOptions
6679
6692
  });
6680
6693
  const embeddings3 = modelResponse.embeddings;
6681
- const usage2 = (_a17 = modelResponse.usage) != null ? _a17 : { tokens: NaN };
6694
+ const usage2 = (_a16 = modelResponse.usage) != null ? _a16 : { tokens: NaN };
6682
6695
  doEmbedSpan.setAttributes(
6683
6696
  selectTelemetryAttributes({
6684
6697
  telemetry,
@@ -6756,7 +6769,7 @@ async function embedMany({
6756
6769
  }),
6757
6770
  tracer,
6758
6771
  fn: async (doEmbedSpan) => {
6759
- var _a17;
6772
+ var _a16;
6760
6773
  const modelResponse = await model.doEmbed({
6761
6774
  values: chunk,
6762
6775
  abortSignal,
@@ -6764,7 +6777,7 @@ async function embedMany({
6764
6777
  providerOptions
6765
6778
  });
6766
6779
  const embeddings2 = modelResponse.embeddings;
6767
- const usage = (_a17 = modelResponse.usage) != null ? _a17 : { tokens: NaN };
6780
+ const usage = (_a16 = modelResponse.usage) != null ? _a16 : { tokens: NaN };
6768
6781
  doEmbedSpan.setAttributes(
6769
6782
  selectTelemetryAttributes({
6770
6783
  telemetry,
@@ -6801,7 +6814,7 @@ async function embedMany({
6801
6814
  result.providerMetadata
6802
6815
  )) {
6803
6816
  providerMetadata[providerName] = {
6804
- ...(_a16 = providerMetadata[providerName]) != null ? _a16 : {},
6817
+ ...providerMetadata[providerName],
6805
6818
  ...metadata
6806
6819
  };
6807
6820
  }
@@ -9625,7 +9638,7 @@ var HttpChatTransport = class {
9625
9638
  const response = await fetch2(api, {
9626
9639
  method: "POST",
9627
9640
  headers: {
9628
- "Content-Type": "application/json",
9641
+ "content-type": "application/json",
9629
9642
  ...headers
9630
9643
  },
9631
9644
  body: JSON.stringify(body),
@@ -10423,7 +10436,7 @@ async function safeValidateUIMessages({
10423
10436
  }
10424
10437
  if (metadataSchema) {
10425
10438
  for (const message of validatedMessages) {
10426
- await (0, import_provider_utils33.validateTypes)({
10439
+ message.metadata = await (0, import_provider_utils33.validateTypes)({
10427
10440
  value: message.metadata,
10428
10441
  schema: metadataSchema
10429
10442
  });
@@ -10446,7 +10459,7 @@ async function safeValidateUIMessages({
10446
10459
  })
10447
10460
  };
10448
10461
  }
10449
- await (0, import_provider_utils33.validateTypes)({
10462
+ dataPart.data = await (0, import_provider_utils33.validateTypes)({
10450
10463
  value: dataPart.data,
10451
10464
  schema: dataSchema
10452
10465
  });