ai 3.0.18 → 3.0.19

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
@@ -1,6 +1,3 @@
1
- // core/generate-object/generate-object.ts
2
- import zodToJsonSchema from "zod-to-json-schema";
3
-
4
1
  // spec/errors/api-call-error.ts
5
2
  var APICallError = class extends Error {
6
3
  constructor({
@@ -297,20 +294,26 @@ var NoTextGeneratedError = class extends Error {
297
294
 
298
295
  // spec/errors/no-such-tool-error.ts
299
296
  var NoSuchToolError = class extends Error {
300
- constructor({ message, toolName }) {
297
+ constructor({
298
+ toolName,
299
+ availableTools = void 0,
300
+ message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
301
+ }) {
301
302
  super(message);
302
303
  this.name = "AI_NoSuchToolError";
303
304
  this.toolName = toolName;
305
+ this.availableTools = availableTools;
304
306
  }
305
307
  static isNoSuchToolError(error) {
306
- return error instanceof Error && error.name === "AI_NoSuchToolError" && typeof error.toolName === "string";
308
+ return error instanceof Error && error.name === "AI_NoSuchToolError" && "toolName" in error && error.toolName != void 0 && typeof error.name === "string";
307
309
  }
308
310
  toJSON() {
309
311
  return {
310
312
  name: this.name,
311
313
  message: this.message,
312
314
  stack: this.stack,
313
- toolName: this.toolName
315
+ toolName: this.toolName,
316
+ availableTools: this.availableTools
314
317
  };
315
318
  }
316
319
  };
@@ -625,6 +628,12 @@ function prepareCallSettings({
625
628
  };
626
629
  }
627
630
 
631
+ // core/util/convert-zod-to-json-schema.ts
632
+ import zodToJsonSchema from "zod-to-json-schema";
633
+ function convertZodToJSONSchema(zodSchema) {
634
+ return zodToJsonSchema(zodSchema);
635
+ }
636
+
628
637
  // core/util/delay.ts
629
638
  async function delay(delayInMs) {
630
639
  return new Promise((resolve) => setTimeout(resolve, delayInMs));
@@ -716,7 +725,7 @@ async function experimental_generateObject({
716
725
  }) {
717
726
  var _a, _b;
718
727
  const retry = retryWithExponentialBackoff({ maxRetries });
719
- const jsonSchema = zodToJsonSchema(schema);
728
+ const jsonSchema = convertZodToJSONSchema(schema);
720
729
  if (mode === "auto" || mode == null) {
721
730
  mode = model.defaultObjectGenerationMode;
722
731
  }
@@ -834,9 +843,6 @@ var GenerateObjectResult = class {
834
843
  }
835
844
  };
836
845
 
837
- // core/generate-object/stream-object.ts
838
- import zodToJsonSchema2 from "zod-to-json-schema";
839
-
840
846
  // core/util/async-iterable-stream.ts
841
847
  function createAsyncIterableStream(source, transformer) {
842
848
  const transformedStream = source.pipeThrough(
@@ -1239,7 +1245,7 @@ async function experimental_streamObject({
1239
1245
  ...settings
1240
1246
  }) {
1241
1247
  const retry = retryWithExponentialBackoff({ maxRetries });
1242
- const jsonSchema = zodToJsonSchema2(schema);
1248
+ const jsonSchema = convertZodToJSONSchema(schema);
1243
1249
  if (mode === "auto" || mode == null) {
1244
1250
  mode = model.defaultObjectGenerationMode;
1245
1251
  }
@@ -1380,9 +1386,6 @@ var StreamObjectResult = class {
1380
1386
  }
1381
1387
  };
1382
1388
 
1383
- // core/generate-text/generate-text.ts
1384
- import zodToJsonSchema3 from "zod-to-json-schema";
1385
-
1386
1389
  // core/generate-text/tool-call.ts
1387
1390
  function parseToolCall({
1388
1391
  toolCall,
@@ -1390,16 +1393,13 @@ function parseToolCall({
1390
1393
  }) {
1391
1394
  const toolName = toolCall.toolName;
1392
1395
  if (tools == null) {
1393
- throw new NoSuchToolError({
1394
- message: `Tool ${toolCall.toolName} not found (no tools provided).`,
1395
- toolName: toolCall.toolName
1396
- });
1396
+ throw new NoSuchToolError({ toolName: toolCall.toolName });
1397
1397
  }
1398
1398
  const tool2 = tools[toolName];
1399
1399
  if (tool2 == null) {
1400
1400
  throw new NoSuchToolError({
1401
- message: `Tool ${toolCall.toolName} not found.`,
1402
- toolName: toolCall.toolName
1401
+ toolName: toolCall.toolName,
1402
+ availableTools: Object.keys(tools)
1403
1403
  });
1404
1404
  }
1405
1405
  const parseResult = safeParseJSON({
@@ -1414,6 +1414,7 @@ function parseToolCall({
1414
1414
  });
1415
1415
  }
1416
1416
  return {
1417
+ type: "tool-call",
1417
1418
  toolCallId: toolCall.toolCallId,
1418
1419
  toolName,
1419
1420
  args: parseResult.value
@@ -1442,7 +1443,7 @@ async function experimental_generateText({
1442
1443
  type: "function",
1443
1444
  name,
1444
1445
  description: tool2.description,
1445
- parameters: zodToJsonSchema3(tool2.parameters)
1446
+ parameters: convertZodToJSONSchema(tool2.parameters)
1446
1447
  }))
1447
1448
  },
1448
1449
  ...prepareCallSettings(settings),
@@ -1502,9 +1503,6 @@ var GenerateTextResult = class {
1502
1503
  }
1503
1504
  };
1504
1505
 
1505
- // core/generate-text/stream-text.ts
1506
- import zodToJsonSchema4 from "zod-to-json-schema";
1507
-
1508
1506
  // shared/generate-id.ts
1509
1507
  import { customAlphabet } from "nanoid/non-secure";
1510
1508
  var generateId = customAlphabet(
@@ -1539,10 +1537,7 @@ function runToolsTransformation({
1539
1537
  if (tools == null) {
1540
1538
  toolResultsStreamController.enqueue({
1541
1539
  type: "error",
1542
- error: new NoSuchToolError({
1543
- message: `Tool ${chunk.toolName} not found (no tools provided).`,
1544
- toolName: chunk.toolName
1545
- })
1540
+ error: new NoSuchToolError({ toolName: chunk.toolName })
1546
1541
  });
1547
1542
  break;
1548
1543
  }
@@ -1551,8 +1546,8 @@ function runToolsTransformation({
1551
1546
  toolResultsStreamController.enqueue({
1552
1547
  type: "error",
1553
1548
  error: new NoSuchToolError({
1554
- message: `Tool ${chunk.toolName} not found.`,
1555
- toolName: chunk.toolName
1549
+ toolName: chunk.toolName,
1550
+ availableTools: Object.keys(tools)
1556
1551
  })
1557
1552
  });
1558
1553
  break;
@@ -1562,18 +1557,15 @@ function runToolsTransformation({
1562
1557
  toolCall: chunk,
1563
1558
  tools
1564
1559
  });
1565
- controller.enqueue({
1566
- type: "tool-call",
1567
- ...toolCall
1568
- });
1560
+ controller.enqueue(toolCall);
1569
1561
  if (tool2.execute != null) {
1570
1562
  const toolExecutionId = generateId();
1571
1563
  outstandingToolCalls.add(toolExecutionId);
1572
1564
  tool2.execute(toolCall.args).then(
1573
1565
  (result) => {
1574
1566
  toolResultsStreamController.enqueue({
1575
- type: "tool-result",
1576
1567
  ...toolCall,
1568
+ type: "tool-result",
1577
1569
  result
1578
1570
  });
1579
1571
  outstandingToolCalls.delete(toolExecutionId);
@@ -1675,7 +1667,7 @@ async function experimental_streamText({
1675
1667
  type: "function",
1676
1668
  name,
1677
1669
  description: tool2.description,
1678
- parameters: zodToJsonSchema4(tool2.parameters)
1670
+ parameters: convertZodToJSONSchema(tool2.parameters)
1679
1671
  }))
1680
1672
  },
1681
1673
  ...prepareCallSettings(settings),