ai 6.0.0-beta.55 → 6.0.0-beta.56

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,15 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.0-beta.56
4
+
5
+ ### Patch Changes
6
+
7
+ - 3794514: feat: flexible tool output content support
8
+ - Updated dependencies [3794514]
9
+ - @ai-sdk/provider-utils@4.0.0-beta.19
10
+ - @ai-sdk/provider@3.0.0-beta.8
11
+ - @ai-sdk/gateway@2.0.0-beta.35
12
+
3
13
  ## 6.0.0-beta.55
4
14
 
5
15
  ### Patch Changes
package/dist/index.js CHANGED
@@ -870,7 +870,7 @@ function detectMediaType({
870
870
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
871
871
 
872
872
  // src/version.ts
873
- var VERSION = true ? "6.0.0-beta.55" : "0.0.0-test";
873
+ var VERSION = true ? "6.0.0-beta.56" : "0.0.0-test";
874
874
 
875
875
  // src/util/download/download.ts
876
876
  var download = async ({ url }) => {
@@ -1120,7 +1120,7 @@ function convertToLanguageModelMessage({
1120
1120
  type: "tool-result",
1121
1121
  toolCallId: part.toolCallId,
1122
1122
  toolName: part.toolName,
1123
- output: part.output,
1123
+ output: mapToolResultOutput(part.output),
1124
1124
  providerOptions
1125
1125
  };
1126
1126
  }
@@ -1136,7 +1136,7 @@ function convertToLanguageModelMessage({
1136
1136
  type: "tool-result",
1137
1137
  toolCallId: part.toolCallId,
1138
1138
  toolName: part.toolName,
1139
- output: part.output,
1139
+ output: mapToolResultOutput(part.output),
1140
1140
  providerOptions: part.providerOptions
1141
1141
  })),
1142
1142
  providerOptions: message.providerOptions
@@ -1243,6 +1243,31 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1243
1243
  }
1244
1244
  }
1245
1245
  }
1246
+ function mapToolResultOutput(output) {
1247
+ if (output.type !== "content") {
1248
+ return output;
1249
+ }
1250
+ return {
1251
+ type: "content",
1252
+ value: output.value.map((item) => {
1253
+ if (item.type !== "media") {
1254
+ return item;
1255
+ }
1256
+ if (item.mediaType.startsWith("image/")) {
1257
+ return {
1258
+ type: "image-data",
1259
+ data: item.data,
1260
+ mediaType: item.mediaType
1261
+ };
1262
+ }
1263
+ return {
1264
+ type: "file-data",
1265
+ data: item.data,
1266
+ mediaType: item.mediaType
1267
+ };
1268
+ })
1269
+ };
1270
+ }
1246
1271
 
1247
1272
  // src/prompt/create-tool-model-output.ts
1248
1273
  var import_provider20 = require("@ai-sdk/provider");
@@ -1479,44 +1504,90 @@ var toolCallPartSchema = import_v44.z.object({
1479
1504
  providerOptions: providerMetadataSchema.optional(),
1480
1505
  providerExecuted: import_v44.z.boolean().optional()
1481
1506
  });
1482
- var outputSchema = import_v44.z.discriminatedUnion("type", [
1483
- import_v44.z.object({
1484
- type: import_v44.z.literal("text"),
1485
- value: import_v44.z.string()
1486
- }),
1487
- import_v44.z.object({
1488
- type: import_v44.z.literal("json"),
1489
- value: jsonValueSchema
1490
- }),
1491
- import_v44.z.object({
1492
- type: import_v44.z.literal("execution-denied"),
1493
- reason: import_v44.z.string().optional()
1494
- }),
1495
- import_v44.z.object({
1496
- type: import_v44.z.literal("error-text"),
1497
- value: import_v44.z.string()
1498
- }),
1499
- import_v44.z.object({
1500
- type: import_v44.z.literal("error-json"),
1501
- value: jsonValueSchema
1502
- }),
1503
- import_v44.z.object({
1504
- type: import_v44.z.literal("content"),
1505
- value: import_v44.z.array(
1506
- import_v44.z.union([
1507
- import_v44.z.object({
1508
- type: import_v44.z.literal("text"),
1509
- text: import_v44.z.string()
1510
- }),
1511
- import_v44.z.object({
1512
- type: import_v44.z.literal("media"),
1513
- data: import_v44.z.string(),
1514
- mediaType: import_v44.z.string()
1515
- })
1516
- ])
1517
- )
1518
- })
1519
- ]);
1507
+ var outputSchema = import_v44.z.discriminatedUnion(
1508
+ "type",
1509
+ [
1510
+ import_v44.z.object({
1511
+ type: import_v44.z.literal("text"),
1512
+ value: import_v44.z.string(),
1513
+ providerOptions: providerMetadataSchema.optional()
1514
+ }),
1515
+ import_v44.z.object({
1516
+ type: import_v44.z.literal("json"),
1517
+ value: jsonValueSchema,
1518
+ providerOptions: providerMetadataSchema.optional()
1519
+ }),
1520
+ import_v44.z.object({
1521
+ type: import_v44.z.literal("execution-denied"),
1522
+ reason: import_v44.z.string().optional(),
1523
+ providerOptions: providerMetadataSchema.optional()
1524
+ }),
1525
+ import_v44.z.object({
1526
+ type: import_v44.z.literal("error-text"),
1527
+ value: import_v44.z.string(),
1528
+ providerOptions: providerMetadataSchema.optional()
1529
+ }),
1530
+ import_v44.z.object({
1531
+ type: import_v44.z.literal("error-json"),
1532
+ value: jsonValueSchema,
1533
+ providerOptions: providerMetadataSchema.optional()
1534
+ }),
1535
+ import_v44.z.object({
1536
+ type: import_v44.z.literal("content"),
1537
+ value: import_v44.z.array(
1538
+ import_v44.z.union([
1539
+ import_v44.z.object({
1540
+ type: import_v44.z.literal("text"),
1541
+ text: import_v44.z.string(),
1542
+ providerOptions: providerMetadataSchema.optional()
1543
+ }),
1544
+ import_v44.z.object({
1545
+ type: import_v44.z.literal("media"),
1546
+ data: import_v44.z.string(),
1547
+ mediaType: import_v44.z.string()
1548
+ }),
1549
+ import_v44.z.object({
1550
+ type: import_v44.z.literal("file-data"),
1551
+ data: import_v44.z.string(),
1552
+ mediaType: import_v44.z.string(),
1553
+ filename: import_v44.z.string().optional(),
1554
+ providerOptions: providerMetadataSchema.optional()
1555
+ }),
1556
+ import_v44.z.object({
1557
+ type: import_v44.z.literal("file-url"),
1558
+ url: import_v44.z.string(),
1559
+ providerOptions: providerMetadataSchema.optional()
1560
+ }),
1561
+ import_v44.z.object({
1562
+ type: import_v44.z.literal("file-id"),
1563
+ fileId: import_v44.z.union([import_v44.z.string(), import_v44.z.record(import_v44.z.string(), import_v44.z.string())]),
1564
+ providerOptions: providerMetadataSchema.optional()
1565
+ }),
1566
+ import_v44.z.object({
1567
+ type: import_v44.z.literal("image-data"),
1568
+ data: import_v44.z.string(),
1569
+ mediaType: import_v44.z.string(),
1570
+ providerOptions: providerMetadataSchema.optional()
1571
+ }),
1572
+ import_v44.z.object({
1573
+ type: import_v44.z.literal("image-url"),
1574
+ url: import_v44.z.string(),
1575
+ providerOptions: providerMetadataSchema.optional()
1576
+ }),
1577
+ import_v44.z.object({
1578
+ type: import_v44.z.literal("image-file-id"),
1579
+ fileId: import_v44.z.union([import_v44.z.string(), import_v44.z.record(import_v44.z.string(), import_v44.z.string())]),
1580
+ providerOptions: providerMetadataSchema.optional()
1581
+ }),
1582
+ import_v44.z.object({
1583
+ type: import_v44.z.literal("custom"),
1584
+ providerOptions: providerMetadataSchema.optional()
1585
+ })
1586
+ ])
1587
+ )
1588
+ })
1589
+ ]
1590
+ );
1520
1591
  var toolResultPartSchema = import_v44.z.object({
1521
1592
  type: import_v44.z.literal("tool-result"),
1522
1593
  toolCallId: import_v44.z.string(),
@@ -6498,9 +6569,7 @@ var BasicAgent = class {
6498
6569
  */
6499
6570
  respond(options) {
6500
6571
  return this.stream({
6501
- prompt: convertToModelMessages(options.messages, {
6502
- tools: this.tools
6503
- })
6572
+ prompt: convertToModelMessages(options.messages, { tools: this.tools })
6504
6573
  }).toUIMessageStreamResponse();
6505
6574
  }
6506
6575
  };