ai 5.0.272 → 5.0.273

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,18 @@
1
1
  # ai
2
2
 
3
+ ## 5.0.273
4
+
5
+ ### Patch Changes
6
+
7
+ - 223133e: fix(ai): prevent deleted tools named after Object.prototype properties from exposing persisted output to models
8
+ - 51e2b34: fix(ai): prevent unavailable tools from exposing persisted output to models
9
+ - 5f95b09: fix(ai): avoid duplicate slashes in chat reconnect URLs
10
+ - Updated dependencies [4a65dd5]
11
+ - Updated dependencies [8f63231]
12
+ - Updated dependencies [95c921d]
13
+ - Updated dependencies [c858a31]
14
+ - @ai-sdk/gateway@2.0.164
15
+
3
16
  ## 5.0.272
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1672,6 +1672,13 @@ type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
1672
1672
  }>;
1673
1673
  type DynamicToolUIPart = {
1674
1674
  type: 'dynamic-tool';
1675
+ /**
1676
+ * `false` when a static tool part was normalized to a dynamic tool part
1677
+ * because its current tool schema was unavailable or incompatible.
1678
+ *
1679
+ * This preserves its static origin across persistence boundaries.
1680
+ */
1681
+ dynamic?: false;
1675
1682
  /**
1676
1683
  * Name of the tool that is being called.
1677
1684
  */
package/dist/index.d.ts CHANGED
@@ -1672,6 +1672,13 @@ type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
1672
1672
  }>;
1673
1673
  type DynamicToolUIPart = {
1674
1674
  type: 'dynamic-tool';
1675
+ /**
1676
+ * `false` when a static tool part was normalized to a dynamic tool part
1677
+ * because its current tool schema was unavailable or incompatible.
1678
+ *
1679
+ * This preserves its static origin across persistence boundaries.
1680
+ */
1681
+ dynamic?: false;
1675
1682
  /**
1676
1683
  * Name of the tool that is being called.
1677
1684
  */
package/dist/index.js CHANGED
@@ -817,7 +817,7 @@ function detectMediaType({
817
817
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
818
818
 
819
819
  // src/version.ts
820
- var VERSION = true ? "5.0.272" : "0.0.0-test";
820
+ var VERSION = true ? "5.0.273" : "0.0.0-test";
821
821
 
822
822
  // src/util/download/download.ts
823
823
  var download = async ({
@@ -6388,6 +6388,20 @@ var DefaultStreamTextResult = class {
6388
6388
  }
6389
6389
  };
6390
6390
 
6391
+ // src/util/get-own.ts
6392
+ function getOwn(obj, key) {
6393
+ return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
6394
+ }
6395
+
6396
+ // src/ui/unavailable-tool.ts
6397
+ function markToolPartAsUnavailable(part) {
6398
+ part.dynamic = false;
6399
+ return part;
6400
+ }
6401
+ function isToolPartFromUnavailableTool(part) {
6402
+ return part.type === "dynamic-tool" && part.dynamic === false;
6403
+ }
6404
+
6391
6405
  // src/ui/convert-to-model-messages.ts
6392
6406
  function convertToModelMessages(messages, options) {
6393
6407
  const modelMessages = [];
@@ -6399,6 +6413,25 @@ function convertToModelMessages(messages, options) {
6399
6413
  )
6400
6414
  }));
6401
6415
  }
6416
+ function createModelOutput({
6417
+ toolPart,
6418
+ toolName,
6419
+ output,
6420
+ errorMode
6421
+ }) {
6422
+ const tool2 = getOwn(options == null ? void 0 : options.tools, toolName);
6423
+ if (errorMode === "none" && tool2 == null && isToolPartFromUnavailableTool(toolPart)) {
6424
+ return {
6425
+ type: "text",
6426
+ value: "Tool output omitted because the tool is no longer available."
6427
+ };
6428
+ }
6429
+ return createToolModelOutput({
6430
+ output,
6431
+ tool: tool2,
6432
+ errorMode
6433
+ });
6434
+ }
6402
6435
  for (const message of messages) {
6403
6436
  switch (message.role) {
6404
6437
  case "system": {
@@ -6452,7 +6485,7 @@ function convertToModelMessages(messages, options) {
6452
6485
  case "assistant": {
6453
6486
  if (message.parts != null) {
6454
6487
  let processBlock2 = function() {
6455
- var _a16, _b, _c;
6488
+ var _a16, _b;
6456
6489
  if (block.length === 0) {
6457
6490
  return;
6458
6491
  }
@@ -6504,9 +6537,10 @@ function convertToModelMessages(messages, options) {
6504
6537
  type: "tool-result",
6505
6538
  toolCallId: part.toolCallId,
6506
6539
  toolName,
6507
- output: createToolModelOutput({
6540
+ output: createModelOutput({
6541
+ toolPart: part,
6542
+ toolName,
6508
6543
  output: part.state === "output-error" ? part.errorText : part.output,
6509
- tool: (_b = options == null ? void 0 : options.tools) == null ? void 0 : _b[toolName],
6510
6544
  errorMode: part.state === "output-error" ? "json" : "none"
6511
6545
  }),
6512
6546
  ...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
@@ -6514,7 +6548,7 @@ function convertToModelMessages(messages, options) {
6514
6548
  }
6515
6549
  }
6516
6550
  } else if (isDataUIPart(part)) {
6517
- const dataPart = (_c = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _c.call(
6551
+ const dataPart = (_b = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _b.call(
6518
6552
  options,
6519
6553
  part
6520
6554
  );
@@ -6537,7 +6571,6 @@ function convertToModelMessages(messages, options) {
6537
6571
  modelMessages.push({
6538
6572
  role: "tool",
6539
6573
  content: toolParts.map((toolPart) => {
6540
- var _a17;
6541
6574
  switch (toolPart.state) {
6542
6575
  case "output-error":
6543
6576
  case "output-available": {
@@ -6546,9 +6579,10 @@ function convertToModelMessages(messages, options) {
6546
6579
  type: "tool-result",
6547
6580
  toolCallId: toolPart.toolCallId,
6548
6581
  toolName,
6549
- output: createToolModelOutput({
6582
+ output: createModelOutput({
6583
+ toolPart,
6584
+ toolName,
6550
6585
  output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
6551
- tool: (_a17 = options == null ? void 0 : options.tools) == null ? void 0 : _a17[toolName],
6552
6586
  errorMode: toolPart.state === "output-error" ? "text" : "none"
6553
6587
  }),
6554
6588
  ...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
@@ -6741,11 +6775,6 @@ var DefaultEmbedResult = class {
6741
6775
  }
6742
6776
  };
6743
6777
 
6744
- // src/util/get-own.ts
6745
- function getOwn(obj, key) {
6746
- return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
6747
- }
6748
-
6749
6778
  // src/util/set-own.ts
6750
6779
  function setOwn(object2, key, value) {
6751
6780
  Object.defineProperty(object2, key, {
@@ -9778,7 +9807,9 @@ var import_provider_utils31 = require("@ai-sdk/provider-utils");
9778
9807
  var import_provider_utils30 = require("@ai-sdk/provider-utils");
9779
9808
  function appendPathToUrl(url, path) {
9780
9809
  const queryOrFragmentStart = url.search(/[?#]/);
9781
- return queryOrFragmentStart === -1 ? `${url}${path}` : `${url.slice(0, queryOrFragmentStart)}${path}${url.slice(queryOrFragmentStart)}`;
9810
+ const urlPath = queryOrFragmentStart === -1 ? url : url.slice(0, queryOrFragmentStart);
9811
+ const suffix = queryOrFragmentStart === -1 ? "" : url.slice(queryOrFragmentStart);
9812
+ return `${urlPath.endsWith("/") && path.startsWith("/") ? urlPath.slice(0, -1) : urlPath}${path}${suffix}`;
9782
9813
  }
9783
9814
  var HttpChatTransport = class {
9784
9815
  constructor({
@@ -10413,20 +10444,20 @@ function asDynamicToolPart(toolPart) {
10413
10444
  ...toolPart.callProviderMetadata === void 0 ? {} : { callProviderMetadata: toolPart.callProviderMetadata }
10414
10445
  };
10415
10446
  if (toolPart.state === "output-available") {
10416
- return {
10447
+ return markToolPartAsUnavailable({
10417
10448
  ...common,
10418
10449
  state: "output-available",
10419
10450
  input: toolPart.input,
10420
10451
  output: toolPart.output,
10421
10452
  ...toolPart.preliminary === void 0 ? {} : { preliminary: toolPart.preliminary }
10422
- };
10453
+ });
10423
10454
  }
10424
- return {
10455
+ return markToolPartAsUnavailable({
10425
10456
  ...common,
10426
10457
  state: "output-error",
10427
10458
  input: toolPart.input,
10428
10459
  errorText: toolPart.errorText
10429
- };
10460
+ });
10430
10461
  }
10431
10462
  var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
10432
10463
  () => (0, import_provider_utils33.zodSchema)(
@@ -10482,6 +10513,7 @@ var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
10482
10513
  }),
10483
10514
  import_v48.z.object({
10484
10515
  type: import_v48.z.literal("dynamic-tool"),
10516
+ dynamic: import_v48.z.literal(false).optional(),
10485
10517
  toolName: import_v48.z.string(),
10486
10518
  toolCallId: import_v48.z.string(),
10487
10519
  state: import_v48.z.literal("input-streaming"),
@@ -10493,6 +10525,7 @@ var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
10493
10525
  }),
10494
10526
  import_v48.z.object({
10495
10527
  type: import_v48.z.literal("dynamic-tool"),
10528
+ dynamic: import_v48.z.literal(false).optional(),
10496
10529
  toolName: import_v48.z.string(),
10497
10530
  toolCallId: import_v48.z.string(),
10498
10531
  state: import_v48.z.literal("input-available"),
@@ -10504,6 +10537,7 @@ var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
10504
10537
  }),
10505
10538
  import_v48.z.object({
10506
10539
  type: import_v48.z.literal("dynamic-tool"),
10540
+ dynamic: import_v48.z.literal(false).optional(),
10507
10541
  toolName: import_v48.z.string(),
10508
10542
  toolCallId: import_v48.z.string(),
10509
10543
  state: import_v48.z.literal("output-available"),
@@ -10516,6 +10550,7 @@ var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
10516
10550
  }),
10517
10551
  import_v48.z.object({
10518
10552
  type: import_v48.z.literal("dynamic-tool"),
10553
+ dynamic: import_v48.z.literal(false).optional(),
10519
10554
  toolName: import_v48.z.string(),
10520
10555
  toolCallId: import_v48.z.string(),
10521
10556
  state: import_v48.z.literal("output-error"),
@@ -10715,7 +10750,7 @@ async function safeValidateUIMessages({
10715
10750
  }
10716
10751
  const toolPart = part;
10717
10752
  const toolName = toolPart.type.slice(5);
10718
- const tool2 = tools[toolName];
10753
+ const tool2 = getOwn(tools, toolName);
10719
10754
  if (!tool2 && (toolPart.state === "output-available" || toolPart.state === "output-error")) {
10720
10755
  message.parts[partIdx] = asDynamicToolPart(toolPart);
10721
10756
  continue;