ai 3.0.17 → 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/anthropic/dist/index.d.mts +369 -0
- package/anthropic/dist/index.d.ts +369 -0
- package/anthropic/dist/index.js +964 -0
- package/anthropic/dist/index.js.map +1 -0
- package/anthropic/dist/index.mjs +928 -0
- package/anthropic/dist/index.mjs.map +1 -0
- package/dist/index.d.mts +23 -22
- package/dist/index.d.ts +23 -22
- package/dist/index.js +57 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -38
- package/dist/index.mjs.map +1 -1
- package/google/dist/index.d.mts +22 -22
- package/google/dist/index.d.ts +22 -22
- package/google/dist/index.js.map +1 -1
- package/google/dist/index.mjs.map +1 -1
- package/mistral/dist/index.d.mts +22 -22
- package/mistral/dist/index.d.ts +22 -22
- package/mistral/dist/index.js +2 -2
- package/mistral/dist/index.js.map +1 -1
- package/mistral/dist/index.mjs +2 -2
- package/mistral/dist/index.mjs.map +1 -1
- package/openai/dist/index.d.mts +22 -22
- package/openai/dist/index.d.ts +22 -22
- package/openai/dist/index.js.map +1 -1
- package/openai/dist/index.mjs.map +1 -1
- package/package.json +14 -4
- package/spec/dist/index.d.mts +69 -25
- package/spec/dist/index.d.ts +69 -25
- package/spec/dist/index.js +71 -3
- package/spec/dist/index.js.map +1 -1
- package/spec/dist/index.mjs +69 -3
- package/spec/dist/index.mjs.map +1 -1
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({
|
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" &&
|
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
|
};
|
@@ -351,6 +354,22 @@ function calculateTokenUsage(usage) {
|
|
351
354
|
};
|
352
355
|
}
|
353
356
|
|
357
|
+
// core/util/detect-image-mimetype.ts
|
358
|
+
var mimeTypeSignatures = [
|
359
|
+
{ mimeType: "image/gif", bytes: [71, 73, 70] },
|
360
|
+
{ mimeType: "image/png", bytes: [137, 80, 78, 71] },
|
361
|
+
{ mimeType: "image/jpeg", bytes: [255, 216] },
|
362
|
+
{ mimeType: "image/webp", bytes: [82, 73, 70, 70] }
|
363
|
+
];
|
364
|
+
function detectImageMimeType(image) {
|
365
|
+
for (const { bytes, mimeType } of mimeTypeSignatures) {
|
366
|
+
if (image.length >= bytes.length && bytes.every((byte, index) => image[index] === byte)) {
|
367
|
+
return mimeType;
|
368
|
+
}
|
369
|
+
}
|
370
|
+
return void 0;
|
371
|
+
}
|
372
|
+
|
354
373
|
// core/prompt/data-content.ts
|
355
374
|
function convertDataContentToBase64String(content) {
|
356
375
|
if (typeof content === "string") {
|
@@ -403,15 +422,26 @@ function convertToLanguageModelPrompt(prompt2) {
|
|
403
422
|
role: "user",
|
404
423
|
content: message.content.map(
|
405
424
|
(part) => {
|
425
|
+
var _a;
|
406
426
|
switch (part.type) {
|
407
427
|
case "text": {
|
408
428
|
return part;
|
409
429
|
}
|
410
430
|
case "image": {
|
431
|
+
if (part.image instanceof URL) {
|
432
|
+
return {
|
433
|
+
type: "image",
|
434
|
+
image: part.image,
|
435
|
+
mimeType: part.mimeType
|
436
|
+
};
|
437
|
+
}
|
438
|
+
const imageUint8 = convertDataContentToUint8Array(
|
439
|
+
part.image
|
440
|
+
);
|
411
441
|
return {
|
412
442
|
type: "image",
|
413
|
-
image:
|
414
|
-
mimeType: part.mimeType
|
443
|
+
image: imageUint8,
|
444
|
+
mimeType: (_a = part.mimeType) != null ? _a : detectImageMimeType(imageUint8)
|
415
445
|
};
|
416
446
|
}
|
417
447
|
}
|
@@ -598,6 +628,12 @@ function prepareCallSettings({
|
|
598
628
|
};
|
599
629
|
}
|
600
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
|
+
|
601
637
|
// core/util/delay.ts
|
602
638
|
async function delay(delayInMs) {
|
603
639
|
return new Promise((resolve) => setTimeout(resolve, delayInMs));
|
@@ -689,7 +725,7 @@ async function experimental_generateObject({
|
|
689
725
|
}) {
|
690
726
|
var _a, _b;
|
691
727
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
692
|
-
const jsonSchema =
|
728
|
+
const jsonSchema = convertZodToJSONSchema(schema);
|
693
729
|
if (mode === "auto" || mode == null) {
|
694
730
|
mode = model.defaultObjectGenerationMode;
|
695
731
|
}
|
@@ -807,9 +843,6 @@ var GenerateObjectResult = class {
|
|
807
843
|
}
|
808
844
|
};
|
809
845
|
|
810
|
-
// core/generate-object/stream-object.ts
|
811
|
-
import zodToJsonSchema2 from "zod-to-json-schema";
|
812
|
-
|
813
846
|
// core/util/async-iterable-stream.ts
|
814
847
|
function createAsyncIterableStream(source, transformer) {
|
815
848
|
const transformedStream = source.pipeThrough(
|
@@ -1212,7 +1245,7 @@ async function experimental_streamObject({
|
|
1212
1245
|
...settings
|
1213
1246
|
}) {
|
1214
1247
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1215
|
-
const jsonSchema =
|
1248
|
+
const jsonSchema = convertZodToJSONSchema(schema);
|
1216
1249
|
if (mode === "auto" || mode == null) {
|
1217
1250
|
mode = model.defaultObjectGenerationMode;
|
1218
1251
|
}
|
@@ -1353,9 +1386,6 @@ var StreamObjectResult = class {
|
|
1353
1386
|
}
|
1354
1387
|
};
|
1355
1388
|
|
1356
|
-
// core/generate-text/generate-text.ts
|
1357
|
-
import zodToJsonSchema3 from "zod-to-json-schema";
|
1358
|
-
|
1359
1389
|
// core/generate-text/tool-call.ts
|
1360
1390
|
function parseToolCall({
|
1361
1391
|
toolCall,
|
@@ -1363,16 +1393,13 @@ function parseToolCall({
|
|
1363
1393
|
}) {
|
1364
1394
|
const toolName = toolCall.toolName;
|
1365
1395
|
if (tools == null) {
|
1366
|
-
throw new NoSuchToolError({
|
1367
|
-
message: `Tool ${toolCall.toolName} not found (no tools provided).`,
|
1368
|
-
toolName: toolCall.toolName
|
1369
|
-
});
|
1396
|
+
throw new NoSuchToolError({ toolName: toolCall.toolName });
|
1370
1397
|
}
|
1371
1398
|
const tool2 = tools[toolName];
|
1372
1399
|
if (tool2 == null) {
|
1373
1400
|
throw new NoSuchToolError({
|
1374
|
-
|
1375
|
-
|
1401
|
+
toolName: toolCall.toolName,
|
1402
|
+
availableTools: Object.keys(tools)
|
1376
1403
|
});
|
1377
1404
|
}
|
1378
1405
|
const parseResult = safeParseJSON({
|
@@ -1387,6 +1414,7 @@ function parseToolCall({
|
|
1387
1414
|
});
|
1388
1415
|
}
|
1389
1416
|
return {
|
1417
|
+
type: "tool-call",
|
1390
1418
|
toolCallId: toolCall.toolCallId,
|
1391
1419
|
toolName,
|
1392
1420
|
args: parseResult.value
|
@@ -1415,7 +1443,7 @@ async function experimental_generateText({
|
|
1415
1443
|
type: "function",
|
1416
1444
|
name,
|
1417
1445
|
description: tool2.description,
|
1418
|
-
parameters:
|
1446
|
+
parameters: convertZodToJSONSchema(tool2.parameters)
|
1419
1447
|
}))
|
1420
1448
|
},
|
1421
1449
|
...prepareCallSettings(settings),
|
@@ -1475,9 +1503,6 @@ var GenerateTextResult = class {
|
|
1475
1503
|
}
|
1476
1504
|
};
|
1477
1505
|
|
1478
|
-
// core/generate-text/stream-text.ts
|
1479
|
-
import zodToJsonSchema4 from "zod-to-json-schema";
|
1480
|
-
|
1481
1506
|
// shared/generate-id.ts
|
1482
1507
|
import { customAlphabet } from "nanoid/non-secure";
|
1483
1508
|
var generateId = customAlphabet(
|
@@ -1512,10 +1537,7 @@ function runToolsTransformation({
|
|
1512
1537
|
if (tools == null) {
|
1513
1538
|
toolResultsStreamController.enqueue({
|
1514
1539
|
type: "error",
|
1515
|
-
error: new NoSuchToolError({
|
1516
|
-
message: `Tool ${chunk.toolName} not found (no tools provided).`,
|
1517
|
-
toolName: chunk.toolName
|
1518
|
-
})
|
1540
|
+
error: new NoSuchToolError({ toolName: chunk.toolName })
|
1519
1541
|
});
|
1520
1542
|
break;
|
1521
1543
|
}
|
@@ -1524,8 +1546,8 @@ function runToolsTransformation({
|
|
1524
1546
|
toolResultsStreamController.enqueue({
|
1525
1547
|
type: "error",
|
1526
1548
|
error: new NoSuchToolError({
|
1527
|
-
|
1528
|
-
|
1549
|
+
toolName: chunk.toolName,
|
1550
|
+
availableTools: Object.keys(tools)
|
1529
1551
|
})
|
1530
1552
|
});
|
1531
1553
|
break;
|
@@ -1535,18 +1557,15 @@ function runToolsTransformation({
|
|
1535
1557
|
toolCall: chunk,
|
1536
1558
|
tools
|
1537
1559
|
});
|
1538
|
-
controller.enqueue(
|
1539
|
-
type: "tool-call",
|
1540
|
-
...toolCall
|
1541
|
-
});
|
1560
|
+
controller.enqueue(toolCall);
|
1542
1561
|
if (tool2.execute != null) {
|
1543
1562
|
const toolExecutionId = generateId();
|
1544
1563
|
outstandingToolCalls.add(toolExecutionId);
|
1545
1564
|
tool2.execute(toolCall.args).then(
|
1546
1565
|
(result) => {
|
1547
1566
|
toolResultsStreamController.enqueue({
|
1548
|
-
type: "tool-result",
|
1549
1567
|
...toolCall,
|
1568
|
+
type: "tool-result",
|
1550
1569
|
result
|
1551
1570
|
});
|
1552
1571
|
outstandingToolCalls.delete(toolExecutionId);
|
@@ -1648,7 +1667,7 @@ async function experimental_streamText({
|
|
1648
1667
|
type: "function",
|
1649
1668
|
name,
|
1650
1669
|
description: tool2.description,
|
1651
|
-
parameters:
|
1670
|
+
parameters: convertZodToJSONSchema(tool2.parameters)
|
1652
1671
|
}))
|
1653
1672
|
},
|
1654
1673
|
...prepareCallSettings(settings),
|