@ai-sdk/xai 4.0.44 → 4.0.48
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 +32 -0
- package/dist/index.d.ts +60 -20
- package/dist/index.js +1183 -635
- package/dist/index.js.map +1 -1
- package/docs/01-xai.mdx +60 -0
- package/package.json +2 -2
- package/src/responses/xai-responses-api.ts +47 -18
- package/src/responses/xai-responses-batch.ts +558 -0
- package/src/responses/xai-responses-language-model.ts +159 -4
- package/src/tool/web-search.ts +38 -15
- package/src/xai-chat-language-model.ts +29 -22
- package/src/xai-provider.ts +6 -5
- package/src/xai-video-model.ts +12 -1
package/dist/index.js
CHANGED
|
@@ -969,19 +969,20 @@ var xaiUsageSchema = z4.object({
|
|
|
969
969
|
prompt_tokens: z4.number(),
|
|
970
970
|
completion_tokens: z4.number(),
|
|
971
971
|
total_tokens: z4.number(),
|
|
972
|
+
cost_in_usd_ticks: z4.number().nullish(),
|
|
972
973
|
prompt_tokens_details: z4.object({
|
|
973
974
|
text_tokens: z4.number().nullish(),
|
|
974
975
|
audio_tokens: z4.number().nullish(),
|
|
975
976
|
image_tokens: z4.number().nullish(),
|
|
976
977
|
cached_tokens: z4.number().nullish()
|
|
977
|
-
}).nullish(),
|
|
978
|
+
}).catchall(z4.json()).nullish(),
|
|
978
979
|
completion_tokens_details: z4.object({
|
|
979
980
|
reasoning_tokens: z4.number().nullish(),
|
|
980
981
|
audio_tokens: z4.number().nullish(),
|
|
981
982
|
accepted_prediction_tokens: z4.number().nullish(),
|
|
982
983
|
rejected_prediction_tokens: z4.number().nullish()
|
|
983
|
-
}).nullish()
|
|
984
|
-
});
|
|
984
|
+
}).catchall(z4.json()).nullish()
|
|
985
|
+
}).catchall(z4.json());
|
|
985
986
|
var xaiChatResponseSchema = z4.object({
|
|
986
987
|
id: z4.string().nullish(),
|
|
987
988
|
created: z4.number().nullish(),
|
|
@@ -1238,11 +1239,50 @@ var xaiImageResponseSchema = z6.object({
|
|
|
1238
1239
|
}).nullish()
|
|
1239
1240
|
});
|
|
1240
1241
|
|
|
1242
|
+
// src/responses/xai-responses-batch.ts
|
|
1243
|
+
import {
|
|
1244
|
+
InvalidArgumentError
|
|
1245
|
+
} from "@ai-sdk/provider";
|
|
1246
|
+
import {
|
|
1247
|
+
combineHeaders as combineHeaders4,
|
|
1248
|
+
convertAsyncIteratorToReadableStream,
|
|
1249
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
1250
|
+
createNullLanguageModelUsage,
|
|
1251
|
+
getFromApi as getFromApi2,
|
|
1252
|
+
lazySchema as lazySchema7,
|
|
1253
|
+
normalizeBatchRequestCounts,
|
|
1254
|
+
postFormDataToApi,
|
|
1255
|
+
postJsonToApi as postJsonToApi4,
|
|
1256
|
+
safeValidateTypes,
|
|
1257
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4,
|
|
1258
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4,
|
|
1259
|
+
zodSchema as zodSchema7
|
|
1260
|
+
} from "@ai-sdk/provider-utils";
|
|
1261
|
+
import { z as z15 } from "zod/v4";
|
|
1262
|
+
|
|
1263
|
+
// src/files/xai-files-api.ts
|
|
1264
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
1265
|
+
import { z as z7 } from "zod/v4";
|
|
1266
|
+
var xaiFilesResponseSchema = lazySchema(
|
|
1267
|
+
() => zodSchema(
|
|
1268
|
+
z7.object({
|
|
1269
|
+
id: z7.string(),
|
|
1270
|
+
object: z7.string().nullish(),
|
|
1271
|
+
bytes: z7.number().nullish(),
|
|
1272
|
+
created_at: z7.number().nullish(),
|
|
1273
|
+
filename: z7.string().nullish(),
|
|
1274
|
+
purpose: z7.string().nullish(),
|
|
1275
|
+
status: z7.string().nullish()
|
|
1276
|
+
})
|
|
1277
|
+
)
|
|
1278
|
+
);
|
|
1279
|
+
|
|
1241
1280
|
// src/responses/xai-responses-language-model.ts
|
|
1242
1281
|
import {
|
|
1243
1282
|
combineHeaders as combineHeaders3,
|
|
1244
1283
|
createEventSourceResponseHandler as createEventSourceResponseHandler2,
|
|
1245
1284
|
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1285
|
+
createProviderStreamError,
|
|
1246
1286
|
isCustomReasoning as isCustomReasoning2,
|
|
1247
1287
|
mapReasoningToProviderEffort as mapReasoningToProviderEffort2,
|
|
1248
1288
|
parseProviderOptions as parseProviderOptions5,
|
|
@@ -1542,461 +1582,484 @@ function mapXaiResponsesFinishReason(finishReason) {
|
|
|
1542
1582
|
}
|
|
1543
1583
|
|
|
1544
1584
|
// src/responses/xai-responses-api.ts
|
|
1545
|
-
import { z as
|
|
1546
|
-
var annotationSchema =
|
|
1547
|
-
|
|
1548
|
-
type:
|
|
1549
|
-
url:
|
|
1550
|
-
title:
|
|
1585
|
+
import { z as z8 } from "zod/v4";
|
|
1586
|
+
var annotationSchema = z8.union([
|
|
1587
|
+
z8.object({
|
|
1588
|
+
type: z8.literal("url_citation"),
|
|
1589
|
+
url: z8.string(),
|
|
1590
|
+
title: z8.string().optional()
|
|
1551
1591
|
}),
|
|
1552
|
-
|
|
1553
|
-
type:
|
|
1592
|
+
z8.object({
|
|
1593
|
+
type: z8.string()
|
|
1554
1594
|
})
|
|
1555
1595
|
]);
|
|
1556
|
-
var messageContentPartSchema =
|
|
1557
|
-
type:
|
|
1558
|
-
text:
|
|
1559
|
-
logprobs:
|
|
1560
|
-
annotations:
|
|
1596
|
+
var messageContentPartSchema = z8.object({
|
|
1597
|
+
type: z8.string(),
|
|
1598
|
+
text: z8.string().optional(),
|
|
1599
|
+
logprobs: z8.array(z8.any()).optional(),
|
|
1600
|
+
annotations: z8.array(annotationSchema).optional()
|
|
1561
1601
|
});
|
|
1562
|
-
var reasoningSummaryPartSchema =
|
|
1563
|
-
type:
|
|
1564
|
-
text:
|
|
1602
|
+
var reasoningSummaryPartSchema = z8.object({
|
|
1603
|
+
type: z8.string(),
|
|
1604
|
+
text: z8.string()
|
|
1565
1605
|
});
|
|
1566
|
-
var toolCallSchema =
|
|
1567
|
-
name:
|
|
1568
|
-
arguments:
|
|
1569
|
-
input:
|
|
1570
|
-
call_id:
|
|
1571
|
-
id:
|
|
1572
|
-
status:
|
|
1573
|
-
action:
|
|
1606
|
+
var toolCallSchema = z8.object({
|
|
1607
|
+
name: z8.string().optional(),
|
|
1608
|
+
arguments: z8.string().optional(),
|
|
1609
|
+
input: z8.string().optional(),
|
|
1610
|
+
call_id: z8.string().optional(),
|
|
1611
|
+
id: z8.string(),
|
|
1612
|
+
status: z8.string(),
|
|
1613
|
+
action: z8.any().optional()
|
|
1574
1614
|
});
|
|
1575
|
-
var
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
output: z7.string().optional(),
|
|
1579
|
-
error: z7.string().optional(),
|
|
1580
|
-
id: z7.string(),
|
|
1581
|
-
status: z7.string(),
|
|
1582
|
-
server_label: z7.string().optional()
|
|
1615
|
+
var webSearchWireSourceSchema = z8.object({
|
|
1616
|
+
type: z8.literal("url"),
|
|
1617
|
+
url: z8.string()
|
|
1583
1618
|
});
|
|
1584
|
-
var
|
|
1585
|
-
|
|
1586
|
-
type:
|
|
1619
|
+
var webSearchWireActionSchema = z8.discriminatedUnion("type", [
|
|
1620
|
+
z8.object({
|
|
1621
|
+
type: z8.literal("search"),
|
|
1622
|
+
query: z8.string().nullish(),
|
|
1623
|
+
queries: z8.array(z8.string()).nullish(),
|
|
1624
|
+
sources: z8.array(z8.unknown()).nullish()
|
|
1625
|
+
}),
|
|
1626
|
+
z8.object({
|
|
1627
|
+
type: z8.literal("open_page"),
|
|
1628
|
+
url: z8.string().nullish(),
|
|
1629
|
+
sources: z8.array(z8.unknown()).nullish()
|
|
1630
|
+
}),
|
|
1631
|
+
z8.object({
|
|
1632
|
+
type: z8.literal("find_in_page"),
|
|
1633
|
+
url: z8.string().nullish(),
|
|
1634
|
+
pattern: z8.string().nullish(),
|
|
1635
|
+
sources: z8.array(z8.unknown()).nullish()
|
|
1636
|
+
})
|
|
1637
|
+
]);
|
|
1638
|
+
var mcpCallSchema = z8.object({
|
|
1639
|
+
name: z8.string().optional(),
|
|
1640
|
+
arguments: z8.string().optional(),
|
|
1641
|
+
output: z8.string().optional(),
|
|
1642
|
+
error: z8.string().optional(),
|
|
1643
|
+
id: z8.string(),
|
|
1644
|
+
status: z8.string(),
|
|
1645
|
+
server_label: z8.string().optional()
|
|
1646
|
+
});
|
|
1647
|
+
var outputItemSchema = z8.discriminatedUnion("type", [
|
|
1648
|
+
z8.object({
|
|
1649
|
+
type: z8.literal("web_search_call"),
|
|
1587
1650
|
...toolCallSchema.shape
|
|
1588
1651
|
}),
|
|
1589
|
-
|
|
1590
|
-
type:
|
|
1652
|
+
z8.object({
|
|
1653
|
+
type: z8.literal("x_search_call"),
|
|
1591
1654
|
...toolCallSchema.shape
|
|
1592
1655
|
}),
|
|
1593
|
-
|
|
1594
|
-
type:
|
|
1656
|
+
z8.object({
|
|
1657
|
+
type: z8.literal("code_interpreter_call"),
|
|
1595
1658
|
...toolCallSchema.shape
|
|
1596
1659
|
}),
|
|
1597
|
-
|
|
1598
|
-
type:
|
|
1660
|
+
z8.object({
|
|
1661
|
+
type: z8.literal("code_execution_call"),
|
|
1599
1662
|
...toolCallSchema.shape
|
|
1600
1663
|
}),
|
|
1601
|
-
|
|
1602
|
-
type:
|
|
1664
|
+
z8.object({
|
|
1665
|
+
type: z8.literal("view_image_call"),
|
|
1603
1666
|
...toolCallSchema.shape
|
|
1604
1667
|
}),
|
|
1605
|
-
|
|
1606
|
-
type:
|
|
1668
|
+
z8.object({
|
|
1669
|
+
type: z8.literal("view_x_video_call"),
|
|
1607
1670
|
...toolCallSchema.shape
|
|
1608
1671
|
}),
|
|
1609
|
-
|
|
1610
|
-
type:
|
|
1611
|
-
id:
|
|
1612
|
-
status:
|
|
1613
|
-
queries:
|
|
1614
|
-
results:
|
|
1615
|
-
|
|
1616
|
-
file_id:
|
|
1617
|
-
filename:
|
|
1618
|
-
score:
|
|
1619
|
-
text:
|
|
1672
|
+
z8.object({
|
|
1673
|
+
type: z8.literal("file_search_call"),
|
|
1674
|
+
id: z8.string(),
|
|
1675
|
+
status: z8.string(),
|
|
1676
|
+
queries: z8.array(z8.string()).optional(),
|
|
1677
|
+
results: z8.array(
|
|
1678
|
+
z8.object({
|
|
1679
|
+
file_id: z8.string(),
|
|
1680
|
+
filename: z8.string(),
|
|
1681
|
+
score: z8.number(),
|
|
1682
|
+
text: z8.string()
|
|
1620
1683
|
})
|
|
1621
1684
|
).nullish()
|
|
1622
1685
|
}),
|
|
1623
|
-
|
|
1624
|
-
type:
|
|
1625
|
-
id:
|
|
1626
|
-
status:
|
|
1627
|
-
prompt:
|
|
1628
|
-
result:
|
|
1686
|
+
z8.object({
|
|
1687
|
+
type: z8.literal("image_generation_call"),
|
|
1688
|
+
id: z8.string(),
|
|
1689
|
+
status: z8.string(),
|
|
1690
|
+
prompt: z8.string().nullish(),
|
|
1691
|
+
result: z8.string().nullish()
|
|
1629
1692
|
}),
|
|
1630
|
-
|
|
1631
|
-
type:
|
|
1693
|
+
z8.object({
|
|
1694
|
+
type: z8.literal("custom_tool_call"),
|
|
1632
1695
|
...toolCallSchema.shape
|
|
1633
1696
|
}),
|
|
1634
|
-
|
|
1635
|
-
type:
|
|
1697
|
+
z8.object({
|
|
1698
|
+
type: z8.literal("mcp_call"),
|
|
1636
1699
|
...mcpCallSchema.shape
|
|
1637
1700
|
}),
|
|
1638
|
-
|
|
1639
|
-
type:
|
|
1640
|
-
role:
|
|
1641
|
-
content:
|
|
1642
|
-
id:
|
|
1643
|
-
status:
|
|
1701
|
+
z8.object({
|
|
1702
|
+
type: z8.literal("message"),
|
|
1703
|
+
role: z8.string(),
|
|
1704
|
+
content: z8.array(messageContentPartSchema),
|
|
1705
|
+
id: z8.string(),
|
|
1706
|
+
status: z8.string()
|
|
1644
1707
|
}),
|
|
1645
|
-
|
|
1646
|
-
type:
|
|
1647
|
-
name:
|
|
1648
|
-
arguments:
|
|
1649
|
-
call_id:
|
|
1650
|
-
id:
|
|
1708
|
+
z8.object({
|
|
1709
|
+
type: z8.literal("function_call"),
|
|
1710
|
+
name: z8.string(),
|
|
1711
|
+
arguments: z8.string(),
|
|
1712
|
+
call_id: z8.string(),
|
|
1713
|
+
id: z8.string()
|
|
1651
1714
|
}),
|
|
1652
|
-
|
|
1653
|
-
type:
|
|
1654
|
-
id:
|
|
1655
|
-
summary:
|
|
1656
|
-
content:
|
|
1657
|
-
status:
|
|
1658
|
-
encrypted_content:
|
|
1715
|
+
z8.object({
|
|
1716
|
+
type: z8.literal("reasoning"),
|
|
1717
|
+
id: z8.string(),
|
|
1718
|
+
summary: z8.array(reasoningSummaryPartSchema),
|
|
1719
|
+
content: z8.array(z8.object({ type: z8.string(), text: z8.string() })).nullish(),
|
|
1720
|
+
status: z8.string(),
|
|
1721
|
+
encrypted_content: z8.string().nullish()
|
|
1659
1722
|
})
|
|
1660
1723
|
]);
|
|
1661
|
-
var xaiResponsesUsageSchema =
|
|
1662
|
-
input_tokens:
|
|
1663
|
-
output_tokens:
|
|
1664
|
-
total_tokens:
|
|
1665
|
-
input_tokens_details:
|
|
1666
|
-
cached_tokens:
|
|
1667
|
-
}).optional(),
|
|
1668
|
-
output_tokens_details:
|
|
1669
|
-
reasoning_tokens:
|
|
1670
|
-
}).optional(),
|
|
1671
|
-
num_sources_used:
|
|
1672
|
-
num_server_side_tools_used:
|
|
1673
|
-
cost_in_usd_ticks:
|
|
1674
|
-
});
|
|
1675
|
-
var xaiResponsesResponseSchema =
|
|
1676
|
-
id:
|
|
1677
|
-
created_at:
|
|
1678
|
-
model:
|
|
1679
|
-
object:
|
|
1680
|
-
output:
|
|
1724
|
+
var xaiResponsesUsageSchema = z8.object({
|
|
1725
|
+
input_tokens: z8.number(),
|
|
1726
|
+
output_tokens: z8.number(),
|
|
1727
|
+
total_tokens: z8.number().optional(),
|
|
1728
|
+
input_tokens_details: z8.object({
|
|
1729
|
+
cached_tokens: z8.number().optional()
|
|
1730
|
+
}).catchall(z8.json()).optional(),
|
|
1731
|
+
output_tokens_details: z8.object({
|
|
1732
|
+
reasoning_tokens: z8.number().optional()
|
|
1733
|
+
}).catchall(z8.json()).optional(),
|
|
1734
|
+
num_sources_used: z8.number().optional(),
|
|
1735
|
+
num_server_side_tools_used: z8.number().optional(),
|
|
1736
|
+
cost_in_usd_ticks: z8.number().nullish()
|
|
1737
|
+
}).catchall(z8.json());
|
|
1738
|
+
var xaiResponsesResponseSchema = z8.object({
|
|
1739
|
+
id: z8.string().nullish(),
|
|
1740
|
+
created_at: z8.number().nullish(),
|
|
1741
|
+
model: z8.string().nullish(),
|
|
1742
|
+
object: z8.literal("response"),
|
|
1743
|
+
output: z8.array(outputItemSchema),
|
|
1681
1744
|
usage: xaiResponsesUsageSchema.nullish(),
|
|
1682
|
-
status:
|
|
1683
|
-
service_tier:
|
|
1745
|
+
status: z8.string(),
|
|
1746
|
+
service_tier: z8.string().nullish()
|
|
1684
1747
|
});
|
|
1685
|
-
var xaiResponsesChunkSchema =
|
|
1686
|
-
|
|
1687
|
-
type:
|
|
1748
|
+
var xaiResponsesChunkSchema = z8.union([
|
|
1749
|
+
z8.object({
|
|
1750
|
+
type: z8.literal("response.created"),
|
|
1688
1751
|
response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
|
|
1689
1752
|
}),
|
|
1690
|
-
|
|
1691
|
-
type:
|
|
1753
|
+
z8.object({
|
|
1754
|
+
type: z8.literal("response.in_progress"),
|
|
1692
1755
|
response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
|
|
1693
1756
|
}),
|
|
1694
|
-
|
|
1695
|
-
type:
|
|
1757
|
+
z8.object({
|
|
1758
|
+
type: z8.literal("response.output_item.added"),
|
|
1696
1759
|
item: outputItemSchema,
|
|
1697
|
-
output_index:
|
|
1760
|
+
output_index: z8.number()
|
|
1698
1761
|
}),
|
|
1699
|
-
|
|
1700
|
-
type:
|
|
1762
|
+
z8.object({
|
|
1763
|
+
type: z8.literal("response.output_item.done"),
|
|
1701
1764
|
item: outputItemSchema,
|
|
1702
|
-
output_index:
|
|
1765
|
+
output_index: z8.number()
|
|
1703
1766
|
}),
|
|
1704
|
-
|
|
1705
|
-
type:
|
|
1706
|
-
item_id:
|
|
1707
|
-
output_index:
|
|
1708
|
-
content_index:
|
|
1767
|
+
z8.object({
|
|
1768
|
+
type: z8.literal("response.content_part.added"),
|
|
1769
|
+
item_id: z8.string(),
|
|
1770
|
+
output_index: z8.number(),
|
|
1771
|
+
content_index: z8.number(),
|
|
1709
1772
|
part: messageContentPartSchema
|
|
1710
1773
|
}),
|
|
1711
|
-
|
|
1712
|
-
type:
|
|
1713
|
-
item_id:
|
|
1714
|
-
output_index:
|
|
1715
|
-
content_index:
|
|
1774
|
+
z8.object({
|
|
1775
|
+
type: z8.literal("response.content_part.done"),
|
|
1776
|
+
item_id: z8.string(),
|
|
1777
|
+
output_index: z8.number(),
|
|
1778
|
+
content_index: z8.number(),
|
|
1716
1779
|
part: messageContentPartSchema
|
|
1717
1780
|
}),
|
|
1718
|
-
|
|
1719
|
-
type:
|
|
1720
|
-
item_id:
|
|
1721
|
-
output_index:
|
|
1722
|
-
content_index:
|
|
1723
|
-
delta:
|
|
1724
|
-
logprobs:
|
|
1781
|
+
z8.object({
|
|
1782
|
+
type: z8.literal("response.output_text.delta"),
|
|
1783
|
+
item_id: z8.string(),
|
|
1784
|
+
output_index: z8.number(),
|
|
1785
|
+
content_index: z8.number(),
|
|
1786
|
+
delta: z8.string(),
|
|
1787
|
+
logprobs: z8.array(z8.any()).optional()
|
|
1725
1788
|
}),
|
|
1726
|
-
|
|
1727
|
-
type:
|
|
1728
|
-
item_id:
|
|
1729
|
-
output_index:
|
|
1730
|
-
content_index:
|
|
1731
|
-
text:
|
|
1732
|
-
logprobs:
|
|
1733
|
-
annotations:
|
|
1789
|
+
z8.object({
|
|
1790
|
+
type: z8.literal("response.output_text.done"),
|
|
1791
|
+
item_id: z8.string(),
|
|
1792
|
+
output_index: z8.number(),
|
|
1793
|
+
content_index: z8.number(),
|
|
1794
|
+
text: z8.string(),
|
|
1795
|
+
logprobs: z8.array(z8.any()).optional(),
|
|
1796
|
+
annotations: z8.array(annotationSchema).optional()
|
|
1734
1797
|
}),
|
|
1735
|
-
|
|
1736
|
-
type:
|
|
1737
|
-
item_id:
|
|
1738
|
-
output_index:
|
|
1739
|
-
content_index:
|
|
1740
|
-
annotation_index:
|
|
1798
|
+
z8.object({
|
|
1799
|
+
type: z8.literal("response.output_text.annotation.added"),
|
|
1800
|
+
item_id: z8.string(),
|
|
1801
|
+
output_index: z8.number(),
|
|
1802
|
+
content_index: z8.number(),
|
|
1803
|
+
annotation_index: z8.number(),
|
|
1741
1804
|
annotation: annotationSchema
|
|
1742
1805
|
}),
|
|
1743
|
-
|
|
1744
|
-
type:
|
|
1745
|
-
item_id:
|
|
1746
|
-
output_index:
|
|
1747
|
-
summary_index:
|
|
1806
|
+
z8.object({
|
|
1807
|
+
type: z8.literal("response.reasoning_summary_part.added"),
|
|
1808
|
+
item_id: z8.string(),
|
|
1809
|
+
output_index: z8.number(),
|
|
1810
|
+
summary_index: z8.number(),
|
|
1748
1811
|
part: reasoningSummaryPartSchema
|
|
1749
1812
|
}),
|
|
1750
|
-
|
|
1751
|
-
type:
|
|
1752
|
-
item_id:
|
|
1753
|
-
output_index:
|
|
1754
|
-
summary_index:
|
|
1813
|
+
z8.object({
|
|
1814
|
+
type: z8.literal("response.reasoning_summary_part.done"),
|
|
1815
|
+
item_id: z8.string(),
|
|
1816
|
+
output_index: z8.number(),
|
|
1817
|
+
summary_index: z8.number(),
|
|
1755
1818
|
part: reasoningSummaryPartSchema
|
|
1756
1819
|
}),
|
|
1757
|
-
|
|
1758
|
-
type:
|
|
1759
|
-
item_id:
|
|
1760
|
-
output_index:
|
|
1761
|
-
summary_index:
|
|
1762
|
-
delta:
|
|
1820
|
+
z8.object({
|
|
1821
|
+
type: z8.literal("response.reasoning_summary_text.delta"),
|
|
1822
|
+
item_id: z8.string(),
|
|
1823
|
+
output_index: z8.number(),
|
|
1824
|
+
summary_index: z8.number(),
|
|
1825
|
+
delta: z8.string()
|
|
1763
1826
|
}),
|
|
1764
|
-
|
|
1765
|
-
type:
|
|
1766
|
-
item_id:
|
|
1767
|
-
output_index:
|
|
1768
|
-
summary_index:
|
|
1769
|
-
text:
|
|
1827
|
+
z8.object({
|
|
1828
|
+
type: z8.literal("response.reasoning_summary_text.done"),
|
|
1829
|
+
item_id: z8.string(),
|
|
1830
|
+
output_index: z8.number(),
|
|
1831
|
+
summary_index: z8.number(),
|
|
1832
|
+
text: z8.string()
|
|
1770
1833
|
}),
|
|
1771
|
-
|
|
1772
|
-
type:
|
|
1773
|
-
item_id:
|
|
1774
|
-
output_index:
|
|
1775
|
-
content_index:
|
|
1776
|
-
delta:
|
|
1834
|
+
z8.object({
|
|
1835
|
+
type: z8.literal("response.reasoning_text.delta"),
|
|
1836
|
+
item_id: z8.string(),
|
|
1837
|
+
output_index: z8.number(),
|
|
1838
|
+
content_index: z8.number(),
|
|
1839
|
+
delta: z8.string()
|
|
1777
1840
|
}),
|
|
1778
|
-
|
|
1779
|
-
type:
|
|
1780
|
-
item_id:
|
|
1781
|
-
output_index:
|
|
1782
|
-
content_index:
|
|
1783
|
-
text:
|
|
1841
|
+
z8.object({
|
|
1842
|
+
type: z8.literal("response.reasoning_text.done"),
|
|
1843
|
+
item_id: z8.string(),
|
|
1844
|
+
output_index: z8.number(),
|
|
1845
|
+
content_index: z8.number(),
|
|
1846
|
+
text: z8.string()
|
|
1784
1847
|
}),
|
|
1785
|
-
|
|
1786
|
-
type:
|
|
1787
|
-
item_id:
|
|
1788
|
-
output_index:
|
|
1848
|
+
z8.object({
|
|
1849
|
+
type: z8.literal("response.web_search_call.in_progress"),
|
|
1850
|
+
item_id: z8.string(),
|
|
1851
|
+
output_index: z8.number()
|
|
1789
1852
|
}),
|
|
1790
|
-
|
|
1791
|
-
type:
|
|
1792
|
-
item_id:
|
|
1793
|
-
output_index:
|
|
1853
|
+
z8.object({
|
|
1854
|
+
type: z8.literal("response.web_search_call.searching"),
|
|
1855
|
+
item_id: z8.string(),
|
|
1856
|
+
output_index: z8.number()
|
|
1794
1857
|
}),
|
|
1795
|
-
|
|
1796
|
-
type:
|
|
1797
|
-
item_id:
|
|
1798
|
-
output_index:
|
|
1858
|
+
z8.object({
|
|
1859
|
+
type: z8.literal("response.web_search_call.completed"),
|
|
1860
|
+
item_id: z8.string(),
|
|
1861
|
+
output_index: z8.number()
|
|
1799
1862
|
}),
|
|
1800
|
-
|
|
1801
|
-
type:
|
|
1802
|
-
item_id:
|
|
1803
|
-
output_index:
|
|
1863
|
+
z8.object({
|
|
1864
|
+
type: z8.literal("response.x_search_call.in_progress"),
|
|
1865
|
+
item_id: z8.string(),
|
|
1866
|
+
output_index: z8.number()
|
|
1804
1867
|
}),
|
|
1805
|
-
|
|
1806
|
-
type:
|
|
1807
|
-
item_id:
|
|
1808
|
-
output_index:
|
|
1868
|
+
z8.object({
|
|
1869
|
+
type: z8.literal("response.x_search_call.searching"),
|
|
1870
|
+
item_id: z8.string(),
|
|
1871
|
+
output_index: z8.number()
|
|
1809
1872
|
}),
|
|
1810
|
-
|
|
1811
|
-
type:
|
|
1812
|
-
item_id:
|
|
1813
|
-
output_index:
|
|
1873
|
+
z8.object({
|
|
1874
|
+
type: z8.literal("response.x_search_call.completed"),
|
|
1875
|
+
item_id: z8.string(),
|
|
1876
|
+
output_index: z8.number()
|
|
1814
1877
|
}),
|
|
1815
|
-
|
|
1816
|
-
type:
|
|
1817
|
-
item_id:
|
|
1818
|
-
output_index:
|
|
1878
|
+
z8.object({
|
|
1879
|
+
type: z8.literal("response.file_search_call.in_progress"),
|
|
1880
|
+
item_id: z8.string(),
|
|
1881
|
+
output_index: z8.number()
|
|
1819
1882
|
}),
|
|
1820
|
-
|
|
1821
|
-
type:
|
|
1822
|
-
item_id:
|
|
1823
|
-
output_index:
|
|
1883
|
+
z8.object({
|
|
1884
|
+
type: z8.literal("response.file_search_call.searching"),
|
|
1885
|
+
item_id: z8.string(),
|
|
1886
|
+
output_index: z8.number()
|
|
1824
1887
|
}),
|
|
1825
|
-
|
|
1826
|
-
type:
|
|
1827
|
-
item_id:
|
|
1828
|
-
output_index:
|
|
1888
|
+
z8.object({
|
|
1889
|
+
type: z8.literal("response.file_search_call.completed"),
|
|
1890
|
+
item_id: z8.string(),
|
|
1891
|
+
output_index: z8.number()
|
|
1829
1892
|
}),
|
|
1830
|
-
|
|
1831
|
-
type:
|
|
1832
|
-
item_id:
|
|
1833
|
-
output_index:
|
|
1893
|
+
z8.object({
|
|
1894
|
+
type: z8.literal("response.image_generation_call.in_progress"),
|
|
1895
|
+
item_id: z8.string(),
|
|
1896
|
+
output_index: z8.number()
|
|
1834
1897
|
}),
|
|
1835
|
-
|
|
1836
|
-
type:
|
|
1837
|
-
item_id:
|
|
1838
|
-
output_index:
|
|
1898
|
+
z8.object({
|
|
1899
|
+
type: z8.literal("response.image_generation_call.generating"),
|
|
1900
|
+
item_id: z8.string(),
|
|
1901
|
+
output_index: z8.number()
|
|
1839
1902
|
}),
|
|
1840
|
-
|
|
1841
|
-
type:
|
|
1842
|
-
item_id:
|
|
1843
|
-
output_index:
|
|
1903
|
+
z8.object({
|
|
1904
|
+
type: z8.literal("response.image_generation_call.completed"),
|
|
1905
|
+
item_id: z8.string(),
|
|
1906
|
+
output_index: z8.number()
|
|
1844
1907
|
}),
|
|
1845
|
-
|
|
1846
|
-
type:
|
|
1847
|
-
item_id:
|
|
1848
|
-
output_index:
|
|
1908
|
+
z8.object({
|
|
1909
|
+
type: z8.literal("response.code_execution_call.in_progress"),
|
|
1910
|
+
item_id: z8.string(),
|
|
1911
|
+
output_index: z8.number()
|
|
1849
1912
|
}),
|
|
1850
|
-
|
|
1851
|
-
type:
|
|
1852
|
-
item_id:
|
|
1853
|
-
output_index:
|
|
1913
|
+
z8.object({
|
|
1914
|
+
type: z8.literal("response.code_execution_call.executing"),
|
|
1915
|
+
item_id: z8.string(),
|
|
1916
|
+
output_index: z8.number()
|
|
1854
1917
|
}),
|
|
1855
|
-
|
|
1856
|
-
type:
|
|
1857
|
-
item_id:
|
|
1858
|
-
output_index:
|
|
1918
|
+
z8.object({
|
|
1919
|
+
type: z8.literal("response.code_execution_call.completed"),
|
|
1920
|
+
item_id: z8.string(),
|
|
1921
|
+
output_index: z8.number()
|
|
1859
1922
|
}),
|
|
1860
|
-
|
|
1861
|
-
type:
|
|
1862
|
-
item_id:
|
|
1863
|
-
output_index:
|
|
1923
|
+
z8.object({
|
|
1924
|
+
type: z8.literal("response.code_interpreter_call.in_progress"),
|
|
1925
|
+
item_id: z8.string(),
|
|
1926
|
+
output_index: z8.number()
|
|
1864
1927
|
}),
|
|
1865
|
-
|
|
1866
|
-
type:
|
|
1867
|
-
item_id:
|
|
1868
|
-
output_index:
|
|
1928
|
+
z8.object({
|
|
1929
|
+
type: z8.literal("response.code_interpreter_call.executing"),
|
|
1930
|
+
item_id: z8.string(),
|
|
1931
|
+
output_index: z8.number()
|
|
1869
1932
|
}),
|
|
1870
|
-
|
|
1871
|
-
type:
|
|
1872
|
-
item_id:
|
|
1873
|
-
output_index:
|
|
1933
|
+
z8.object({
|
|
1934
|
+
type: z8.literal("response.code_interpreter_call.interpreting"),
|
|
1935
|
+
item_id: z8.string(),
|
|
1936
|
+
output_index: z8.number()
|
|
1874
1937
|
}),
|
|
1875
|
-
|
|
1876
|
-
type:
|
|
1877
|
-
item_id:
|
|
1878
|
-
output_index:
|
|
1938
|
+
z8.object({
|
|
1939
|
+
type: z8.literal("response.code_interpreter_call.completed"),
|
|
1940
|
+
item_id: z8.string(),
|
|
1941
|
+
output_index: z8.number()
|
|
1879
1942
|
}),
|
|
1880
1943
|
// Code interpreter code streaming events
|
|
1881
|
-
|
|
1882
|
-
type:
|
|
1883
|
-
item_id:
|
|
1884
|
-
output_index:
|
|
1885
|
-
delta:
|
|
1944
|
+
z8.object({
|
|
1945
|
+
type: z8.literal("response.code_interpreter_call_code.delta"),
|
|
1946
|
+
item_id: z8.string(),
|
|
1947
|
+
output_index: z8.number(),
|
|
1948
|
+
delta: z8.string()
|
|
1886
1949
|
}),
|
|
1887
|
-
|
|
1888
|
-
type:
|
|
1889
|
-
item_id:
|
|
1890
|
-
output_index:
|
|
1891
|
-
code:
|
|
1950
|
+
z8.object({
|
|
1951
|
+
type: z8.literal("response.code_interpreter_call_code.done"),
|
|
1952
|
+
item_id: z8.string(),
|
|
1953
|
+
output_index: z8.number(),
|
|
1954
|
+
code: z8.string()
|
|
1892
1955
|
}),
|
|
1893
|
-
|
|
1894
|
-
type:
|
|
1895
|
-
item_id:
|
|
1896
|
-
output_index:
|
|
1897
|
-
delta:
|
|
1956
|
+
z8.object({
|
|
1957
|
+
type: z8.literal("response.custom_tool_call_input.delta"),
|
|
1958
|
+
item_id: z8.string(),
|
|
1959
|
+
output_index: z8.number(),
|
|
1960
|
+
delta: z8.string()
|
|
1898
1961
|
}),
|
|
1899
|
-
|
|
1900
|
-
type:
|
|
1901
|
-
item_id:
|
|
1902
|
-
output_index:
|
|
1903
|
-
input:
|
|
1962
|
+
z8.object({
|
|
1963
|
+
type: z8.literal("response.custom_tool_call_input.done"),
|
|
1964
|
+
item_id: z8.string(),
|
|
1965
|
+
output_index: z8.number(),
|
|
1966
|
+
input: z8.string()
|
|
1904
1967
|
}),
|
|
1905
1968
|
// Function call arguments streaming events (standard function tools)
|
|
1906
|
-
|
|
1907
|
-
type:
|
|
1908
|
-
item_id:
|
|
1909
|
-
output_index:
|
|
1910
|
-
delta:
|
|
1969
|
+
z8.object({
|
|
1970
|
+
type: z8.literal("response.function_call_arguments.delta"),
|
|
1971
|
+
item_id: z8.string(),
|
|
1972
|
+
output_index: z8.number(),
|
|
1973
|
+
delta: z8.string()
|
|
1911
1974
|
}),
|
|
1912
|
-
|
|
1913
|
-
type:
|
|
1914
|
-
item_id:
|
|
1915
|
-
output_index:
|
|
1916
|
-
arguments:
|
|
1975
|
+
z8.object({
|
|
1976
|
+
type: z8.literal("response.function_call_arguments.done"),
|
|
1977
|
+
item_id: z8.string(),
|
|
1978
|
+
output_index: z8.number(),
|
|
1979
|
+
arguments: z8.string()
|
|
1917
1980
|
}),
|
|
1918
|
-
|
|
1919
|
-
type:
|
|
1920
|
-
item_id:
|
|
1921
|
-
output_index:
|
|
1981
|
+
z8.object({
|
|
1982
|
+
type: z8.literal("response.mcp_call.in_progress"),
|
|
1983
|
+
item_id: z8.string(),
|
|
1984
|
+
output_index: z8.number()
|
|
1922
1985
|
}),
|
|
1923
|
-
|
|
1924
|
-
type:
|
|
1925
|
-
item_id:
|
|
1926
|
-
output_index:
|
|
1986
|
+
z8.object({
|
|
1987
|
+
type: z8.literal("response.mcp_call.executing"),
|
|
1988
|
+
item_id: z8.string(),
|
|
1989
|
+
output_index: z8.number()
|
|
1927
1990
|
}),
|
|
1928
|
-
|
|
1929
|
-
type:
|
|
1930
|
-
item_id:
|
|
1931
|
-
output_index:
|
|
1991
|
+
z8.object({
|
|
1992
|
+
type: z8.literal("response.mcp_call.completed"),
|
|
1993
|
+
item_id: z8.string(),
|
|
1994
|
+
output_index: z8.number()
|
|
1932
1995
|
}),
|
|
1933
|
-
|
|
1934
|
-
type:
|
|
1935
|
-
item_id:
|
|
1936
|
-
output_index:
|
|
1996
|
+
z8.object({
|
|
1997
|
+
type: z8.literal("response.mcp_call.failed"),
|
|
1998
|
+
item_id: z8.string(),
|
|
1999
|
+
output_index: z8.number()
|
|
1937
2000
|
}),
|
|
1938
|
-
|
|
1939
|
-
type:
|
|
1940
|
-
item_id:
|
|
1941
|
-
output_index:
|
|
1942
|
-
delta:
|
|
2001
|
+
z8.object({
|
|
2002
|
+
type: z8.literal("response.mcp_call_arguments.delta"),
|
|
2003
|
+
item_id: z8.string(),
|
|
2004
|
+
output_index: z8.number(),
|
|
2005
|
+
delta: z8.string()
|
|
1943
2006
|
}),
|
|
1944
|
-
|
|
1945
|
-
type:
|
|
1946
|
-
item_id:
|
|
1947
|
-
output_index:
|
|
1948
|
-
arguments:
|
|
2007
|
+
z8.object({
|
|
2008
|
+
type: z8.literal("response.mcp_call_arguments.done"),
|
|
2009
|
+
item_id: z8.string(),
|
|
2010
|
+
output_index: z8.number(),
|
|
2011
|
+
arguments: z8.string().optional()
|
|
1949
2012
|
}),
|
|
1950
|
-
|
|
1951
|
-
type:
|
|
1952
|
-
item_id:
|
|
1953
|
-
output_index:
|
|
1954
|
-
delta:
|
|
2013
|
+
z8.object({
|
|
2014
|
+
type: z8.literal("response.mcp_call_output.delta"),
|
|
2015
|
+
item_id: z8.string(),
|
|
2016
|
+
output_index: z8.number(),
|
|
2017
|
+
delta: z8.string()
|
|
1955
2018
|
}),
|
|
1956
|
-
|
|
1957
|
-
type:
|
|
1958
|
-
item_id:
|
|
1959
|
-
output_index:
|
|
1960
|
-
output:
|
|
2019
|
+
z8.object({
|
|
2020
|
+
type: z8.literal("response.mcp_call_output.done"),
|
|
2021
|
+
item_id: z8.string(),
|
|
2022
|
+
output_index: z8.number(),
|
|
2023
|
+
output: z8.string().optional()
|
|
1961
2024
|
}),
|
|
1962
|
-
|
|
1963
|
-
type:
|
|
1964
|
-
response:
|
|
1965
|
-
incomplete_details:
|
|
2025
|
+
z8.object({
|
|
2026
|
+
type: z8.literal("response.incomplete"),
|
|
2027
|
+
response: z8.object({
|
|
2028
|
+
incomplete_details: z8.object({ reason: z8.string() }).nullish(),
|
|
1966
2029
|
usage: xaiResponsesUsageSchema.nullish(),
|
|
1967
|
-
service_tier:
|
|
2030
|
+
service_tier: z8.string().nullish()
|
|
1968
2031
|
})
|
|
1969
2032
|
}),
|
|
1970
|
-
|
|
1971
|
-
type:
|
|
1972
|
-
response:
|
|
1973
|
-
error:
|
|
1974
|
-
code:
|
|
1975
|
-
message:
|
|
2033
|
+
z8.object({
|
|
2034
|
+
type: z8.literal("response.failed"),
|
|
2035
|
+
response: z8.object({
|
|
2036
|
+
error: z8.object({
|
|
2037
|
+
code: z8.string().nullish(),
|
|
2038
|
+
message: z8.string()
|
|
1976
2039
|
}).nullish(),
|
|
1977
|
-
incomplete_details:
|
|
2040
|
+
incomplete_details: z8.object({ reason: z8.string() }).nullish(),
|
|
1978
2041
|
usage: xaiResponsesUsageSchema.nullish()
|
|
1979
2042
|
})
|
|
1980
2043
|
}),
|
|
1981
|
-
|
|
1982
|
-
type:
|
|
1983
|
-
code:
|
|
1984
|
-
message:
|
|
1985
|
-
param:
|
|
2044
|
+
z8.object({
|
|
2045
|
+
type: z8.literal("error"),
|
|
2046
|
+
code: z8.string().nullish(),
|
|
2047
|
+
message: z8.string(),
|
|
2048
|
+
param: z8.string().nullish()
|
|
1986
2049
|
}),
|
|
1987
|
-
|
|
1988
|
-
type:
|
|
2050
|
+
z8.object({
|
|
2051
|
+
type: z8.literal("response.done"),
|
|
1989
2052
|
response: xaiResponsesResponseSchema
|
|
1990
2053
|
}),
|
|
1991
|
-
|
|
1992
|
-
type:
|
|
2054
|
+
z8.object({
|
|
2055
|
+
type: z8.literal("response.completed"),
|
|
1993
2056
|
response: xaiResponsesResponseSchema
|
|
1994
2057
|
})
|
|
1995
2058
|
]);
|
|
1996
2059
|
|
|
1997
2060
|
// src/responses/xai-responses-language-model-options.ts
|
|
1998
|
-
import { z as
|
|
1999
|
-
var xaiLanguageModelResponsesOptions =
|
|
2061
|
+
import { z as z9 } from "zod/v4";
|
|
2062
|
+
var xaiLanguageModelResponsesOptions = z9.object({
|
|
2000
2063
|
/**
|
|
2001
2064
|
* Constrains how hard a reasoning model thinks before responding.
|
|
2002
2065
|
* Possible values are `none` (disables reasoning entirely; supported by
|
|
@@ -2006,27 +2069,27 @@ var xaiLanguageModelResponsesOptions = z8.object({
|
|
|
2006
2069
|
*
|
|
2007
2070
|
* @see https://docs.x.ai/docs/guides/reasoning
|
|
2008
2071
|
*/
|
|
2009
|
-
reasoningEffort:
|
|
2010
|
-
reasoningSummary:
|
|
2011
|
-
logprobs:
|
|
2012
|
-
topLogprobs:
|
|
2013
|
-
serviceTier:
|
|
2072
|
+
reasoningEffort: z9.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
|
|
2073
|
+
reasoningSummary: z9.enum(["auto", "concise", "detailed"]).optional(),
|
|
2074
|
+
logprobs: z9.boolean().optional(),
|
|
2075
|
+
topLogprobs: z9.number().int().min(0).max(8).optional(),
|
|
2076
|
+
serviceTier: z9.enum(["default", "priority"]).optional(),
|
|
2014
2077
|
/**
|
|
2015
2078
|
* Whether to store the input message(s) and model response for later retrieval.
|
|
2016
2079
|
* Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
|
|
2017
2080
|
* otherwise the API will return an error.
|
|
2018
2081
|
* @default true
|
|
2019
2082
|
*/
|
|
2020
|
-
store:
|
|
2083
|
+
store: z9.boolean().optional(),
|
|
2021
2084
|
/**
|
|
2022
2085
|
* The ID of the previous response from the model.
|
|
2023
2086
|
*/
|
|
2024
|
-
previousResponseId:
|
|
2087
|
+
previousResponseId: z9.string().optional(),
|
|
2025
2088
|
/**
|
|
2026
2089
|
* Specify additional output data to include in the model response.
|
|
2027
2090
|
* Example values: 'file_search_call.results'.
|
|
2028
2091
|
*/
|
|
2029
|
-
include:
|
|
2092
|
+
include: z9.array(z9.enum(["file_search_call.results"])).nullish()
|
|
2030
2093
|
});
|
|
2031
2094
|
|
|
2032
2095
|
// src/responses/xai-responses-prepare-tools.ts
|
|
@@ -2038,28 +2101,28 @@ import { validateTypes } from "@ai-sdk/provider-utils";
|
|
|
2038
2101
|
// src/tool/file-search.ts
|
|
2039
2102
|
import {
|
|
2040
2103
|
createProviderExecutedToolFactory,
|
|
2041
|
-
lazySchema,
|
|
2042
|
-
zodSchema
|
|
2104
|
+
lazySchema as lazySchema2,
|
|
2105
|
+
zodSchema as zodSchema2
|
|
2043
2106
|
} from "@ai-sdk/provider-utils";
|
|
2044
|
-
import { z as
|
|
2045
|
-
var fileSearchArgsSchema =
|
|
2046
|
-
() =>
|
|
2047
|
-
|
|
2048
|
-
vectorStoreIds:
|
|
2049
|
-
maxNumResults:
|
|
2107
|
+
import { z as z10 } from "zod/v4";
|
|
2108
|
+
var fileSearchArgsSchema = lazySchema2(
|
|
2109
|
+
() => zodSchema2(
|
|
2110
|
+
z10.object({
|
|
2111
|
+
vectorStoreIds: z10.array(z10.string()),
|
|
2112
|
+
maxNumResults: z10.number().optional()
|
|
2050
2113
|
})
|
|
2051
2114
|
)
|
|
2052
2115
|
);
|
|
2053
|
-
var fileSearchOutputSchema =
|
|
2054
|
-
() =>
|
|
2055
|
-
|
|
2056
|
-
queries:
|
|
2057
|
-
results:
|
|
2058
|
-
|
|
2059
|
-
fileId:
|
|
2060
|
-
filename:
|
|
2061
|
-
score:
|
|
2062
|
-
text:
|
|
2116
|
+
var fileSearchOutputSchema = lazySchema2(
|
|
2117
|
+
() => zodSchema2(
|
|
2118
|
+
z10.object({
|
|
2119
|
+
queries: z10.array(z10.string()),
|
|
2120
|
+
results: z10.array(
|
|
2121
|
+
z10.object({
|
|
2122
|
+
fileId: z10.string(),
|
|
2123
|
+
filename: z10.string(),
|
|
2124
|
+
score: z10.number().min(0).max(1),
|
|
2125
|
+
text: z10.string()
|
|
2063
2126
|
})
|
|
2064
2127
|
).nullable()
|
|
2065
2128
|
})
|
|
@@ -2067,7 +2130,7 @@ var fileSearchOutputSchema = lazySchema(
|
|
|
2067
2130
|
);
|
|
2068
2131
|
var fileSearchToolFactory = createProviderExecutedToolFactory({
|
|
2069
2132
|
id: "xai.file_search",
|
|
2070
|
-
inputSchema:
|
|
2133
|
+
inputSchema: lazySchema2(() => zodSchema2(z10.object({}))),
|
|
2071
2134
|
outputSchema: fileSearchOutputSchema
|
|
2072
2135
|
});
|
|
2073
2136
|
var fileSearch = (args) => fileSearchToolFactory(args);
|
|
@@ -2075,23 +2138,23 @@ var fileSearch = (args) => fileSearchToolFactory(args);
|
|
|
2075
2138
|
// src/tool/image-generation.ts
|
|
2076
2139
|
import {
|
|
2077
2140
|
createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
|
|
2078
|
-
lazySchema as
|
|
2079
|
-
zodSchema as
|
|
2141
|
+
lazySchema as lazySchema3,
|
|
2142
|
+
zodSchema as zodSchema3
|
|
2080
2143
|
} from "@ai-sdk/provider-utils";
|
|
2081
|
-
import { z as
|
|
2082
|
-
var imageGenerationArgsSchema =
|
|
2083
|
-
() =>
|
|
2084
|
-
|
|
2085
|
-
action:
|
|
2144
|
+
import { z as z11 } from "zod/v4";
|
|
2145
|
+
var imageGenerationArgsSchema = lazySchema3(
|
|
2146
|
+
() => zodSchema3(
|
|
2147
|
+
z11.object({
|
|
2148
|
+
action: z11.enum(["auto", "generate", "edit"]).optional()
|
|
2086
2149
|
})
|
|
2087
2150
|
)
|
|
2088
2151
|
);
|
|
2089
|
-
var imageGenerationInputSchema =
|
|
2090
|
-
var imageGenerationOutputSchema =
|
|
2091
|
-
() =>
|
|
2092
|
-
|
|
2093
|
-
result:
|
|
2094
|
-
prompt:
|
|
2152
|
+
var imageGenerationInputSchema = lazySchema3(() => zodSchema3(z11.object({})));
|
|
2153
|
+
var imageGenerationOutputSchema = lazySchema3(
|
|
2154
|
+
() => zodSchema3(
|
|
2155
|
+
z11.object({
|
|
2156
|
+
result: z11.string(),
|
|
2157
|
+
prompt: z11.string().optional()
|
|
2095
2158
|
})
|
|
2096
2159
|
)
|
|
2097
2160
|
);
|
|
@@ -2105,34 +2168,34 @@ var imageGeneration = (args = {}) => imageGenerationToolFactory(args);
|
|
|
2105
2168
|
// src/tool/mcp-server.ts
|
|
2106
2169
|
import {
|
|
2107
2170
|
createProviderExecutedToolFactory as createProviderExecutedToolFactory3,
|
|
2108
|
-
lazySchema as
|
|
2109
|
-
zodSchema as
|
|
2171
|
+
lazySchema as lazySchema4,
|
|
2172
|
+
zodSchema as zodSchema4
|
|
2110
2173
|
} from "@ai-sdk/provider-utils";
|
|
2111
|
-
import { z as
|
|
2112
|
-
var mcpServerArgsSchema =
|
|
2113
|
-
() =>
|
|
2114
|
-
|
|
2115
|
-
serverUrl:
|
|
2116
|
-
serverLabel:
|
|
2117
|
-
serverDescription:
|
|
2118
|
-
allowedTools:
|
|
2119
|
-
headers:
|
|
2120
|
-
authorization:
|
|
2174
|
+
import { z as z12 } from "zod/v4";
|
|
2175
|
+
var mcpServerArgsSchema = lazySchema4(
|
|
2176
|
+
() => zodSchema4(
|
|
2177
|
+
z12.object({
|
|
2178
|
+
serverUrl: z12.string().describe("The URL of the MCP server"),
|
|
2179
|
+
serverLabel: z12.string().optional().describe("A label for the MCP server"),
|
|
2180
|
+
serverDescription: z12.string().optional().describe("Description of the MCP server"),
|
|
2181
|
+
allowedTools: z12.array(z12.string()).optional().describe("List of allowed tool names"),
|
|
2182
|
+
headers: z12.record(z12.string(), z12.string()).optional().describe("Custom headers to send"),
|
|
2183
|
+
authorization: z12.string().optional().describe("Authorization header value")
|
|
2121
2184
|
})
|
|
2122
2185
|
)
|
|
2123
2186
|
);
|
|
2124
|
-
var mcpServerOutputSchema =
|
|
2125
|
-
() =>
|
|
2126
|
-
|
|
2127
|
-
name:
|
|
2128
|
-
arguments:
|
|
2129
|
-
result:
|
|
2187
|
+
var mcpServerOutputSchema = lazySchema4(
|
|
2188
|
+
() => zodSchema4(
|
|
2189
|
+
z12.object({
|
|
2190
|
+
name: z12.string(),
|
|
2191
|
+
arguments: z12.string(),
|
|
2192
|
+
result: z12.unknown()
|
|
2130
2193
|
})
|
|
2131
2194
|
)
|
|
2132
2195
|
);
|
|
2133
2196
|
var mcpServerToolFactory = createProviderExecutedToolFactory3({
|
|
2134
2197
|
id: "xai.mcp",
|
|
2135
|
-
inputSchema:
|
|
2198
|
+
inputSchema: lazySchema4(() => zodSchema4(z12.object({}))),
|
|
2136
2199
|
outputSchema: mcpServerOutputSchema
|
|
2137
2200
|
});
|
|
2138
2201
|
var mcpServer = (args) => mcpServerToolFactory(args);
|
|
@@ -2140,37 +2203,46 @@ var mcpServer = (args) => mcpServerToolFactory(args);
|
|
|
2140
2203
|
// src/tool/web-search.ts
|
|
2141
2204
|
import {
|
|
2142
2205
|
createProviderExecutedToolFactory as createProviderExecutedToolFactory4,
|
|
2143
|
-
lazySchema as
|
|
2144
|
-
zodSchema as
|
|
2206
|
+
lazySchema as lazySchema5,
|
|
2207
|
+
zodSchema as zodSchema5
|
|
2145
2208
|
} from "@ai-sdk/provider-utils";
|
|
2146
|
-
import { z as
|
|
2147
|
-
var webSearchArgsSchema =
|
|
2148
|
-
() =>
|
|
2149
|
-
|
|
2150
|
-
allowedDomains:
|
|
2151
|
-
excludedDomains:
|
|
2152
|
-
enableImageSearch:
|
|
2153
|
-
enableImageUnderstanding:
|
|
2209
|
+
import { z as z13 } from "zod/v4";
|
|
2210
|
+
var webSearchArgsSchema = lazySchema5(
|
|
2211
|
+
() => zodSchema5(
|
|
2212
|
+
z13.object({
|
|
2213
|
+
allowedDomains: z13.array(z13.string()).max(5).optional(),
|
|
2214
|
+
excludedDomains: z13.array(z13.string()).max(5).optional(),
|
|
2215
|
+
enableImageSearch: z13.boolean().optional(),
|
|
2216
|
+
enableImageUnderstanding: z13.boolean().optional()
|
|
2154
2217
|
})
|
|
2155
2218
|
)
|
|
2156
2219
|
);
|
|
2157
|
-
var webSearchOutputSchema =
|
|
2158
|
-
() =>
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2220
|
+
var webSearchOutputSchema = lazySchema5(
|
|
2221
|
+
() => zodSchema5(
|
|
2222
|
+
z13.object({
|
|
2223
|
+
action: z13.discriminatedUnion("type", [
|
|
2224
|
+
z13.object({
|
|
2225
|
+
type: z13.literal("search"),
|
|
2226
|
+
query: z13.string().optional(),
|
|
2227
|
+
queries: z13.array(z13.string()).optional()
|
|
2228
|
+
}),
|
|
2229
|
+
z13.object({
|
|
2230
|
+
type: z13.literal("openPage"),
|
|
2231
|
+
url: z13.string().nullish()
|
|
2232
|
+
}),
|
|
2233
|
+
z13.object({
|
|
2234
|
+
type: z13.literal("findInPage"),
|
|
2235
|
+
url: z13.string().nullish(),
|
|
2236
|
+
pattern: z13.string().nullish()
|
|
2166
2237
|
})
|
|
2167
|
-
)
|
|
2238
|
+
]).optional(),
|
|
2239
|
+
sources: z13.array(z13.object({ type: z13.literal("url"), url: z13.string() })).optional()
|
|
2168
2240
|
})
|
|
2169
2241
|
)
|
|
2170
2242
|
);
|
|
2171
2243
|
var webSearchToolFactory = createProviderExecutedToolFactory4({
|
|
2172
2244
|
id: "xai.web_search",
|
|
2173
|
-
inputSchema:
|
|
2245
|
+
inputSchema: lazySchema5(() => zodSchema5(z13.object({}))),
|
|
2174
2246
|
outputSchema: webSearchOutputSchema
|
|
2175
2247
|
});
|
|
2176
2248
|
var webSearch = (args = {}) => webSearchToolFactory(args);
|
|
@@ -2178,32 +2250,32 @@ var webSearch = (args = {}) => webSearchToolFactory(args);
|
|
|
2178
2250
|
// src/tool/x-search.ts
|
|
2179
2251
|
import {
|
|
2180
2252
|
createProviderExecutedToolFactory as createProviderExecutedToolFactory5,
|
|
2181
|
-
lazySchema as
|
|
2182
|
-
zodSchema as
|
|
2253
|
+
lazySchema as lazySchema6,
|
|
2254
|
+
zodSchema as zodSchema6
|
|
2183
2255
|
} from "@ai-sdk/provider-utils";
|
|
2184
|
-
import { z as
|
|
2185
|
-
var xSearchArgsSchema =
|
|
2186
|
-
() =>
|
|
2187
|
-
|
|
2188
|
-
allowedXHandles:
|
|
2189
|
-
excludedXHandles:
|
|
2190
|
-
fromDate:
|
|
2191
|
-
toDate:
|
|
2192
|
-
enableImageUnderstanding:
|
|
2193
|
-
enableVideoUnderstanding:
|
|
2256
|
+
import { z as z14 } from "zod/v4";
|
|
2257
|
+
var xSearchArgsSchema = lazySchema6(
|
|
2258
|
+
() => zodSchema6(
|
|
2259
|
+
z14.object({
|
|
2260
|
+
allowedXHandles: z14.array(z14.string()).max(10).optional(),
|
|
2261
|
+
excludedXHandles: z14.array(z14.string()).max(10).optional(),
|
|
2262
|
+
fromDate: z14.string().optional(),
|
|
2263
|
+
toDate: z14.string().optional(),
|
|
2264
|
+
enableImageUnderstanding: z14.boolean().optional(),
|
|
2265
|
+
enableVideoUnderstanding: z14.boolean().optional()
|
|
2194
2266
|
})
|
|
2195
2267
|
)
|
|
2196
2268
|
);
|
|
2197
|
-
var xSearchOutputSchema =
|
|
2198
|
-
() =>
|
|
2199
|
-
|
|
2200
|
-
query:
|
|
2201
|
-
posts:
|
|
2202
|
-
|
|
2203
|
-
author:
|
|
2204
|
-
text:
|
|
2205
|
-
url:
|
|
2206
|
-
likes:
|
|
2269
|
+
var xSearchOutputSchema = lazySchema6(
|
|
2270
|
+
() => zodSchema6(
|
|
2271
|
+
z14.object({
|
|
2272
|
+
query: z14.string(),
|
|
2273
|
+
posts: z14.array(
|
|
2274
|
+
z14.object({
|
|
2275
|
+
author: z14.string(),
|
|
2276
|
+
text: z14.string(),
|
|
2277
|
+
url: z14.string(),
|
|
2278
|
+
likes: z14.number()
|
|
2207
2279
|
})
|
|
2208
2280
|
)
|
|
2209
2281
|
})
|
|
@@ -2211,7 +2283,7 @@ var xSearchOutputSchema = lazySchema5(
|
|
|
2211
2283
|
);
|
|
2212
2284
|
var xSearchToolFactory = createProviderExecutedToolFactory5({
|
|
2213
2285
|
id: "xai.x_search",
|
|
2214
|
-
inputSchema:
|
|
2286
|
+
inputSchema: lazySchema6(() => zodSchema6(z14.object({}))),
|
|
2215
2287
|
outputSchema: xSearchOutputSchema
|
|
2216
2288
|
});
|
|
2217
2289
|
var xSearch = (args = {}) => xSearchToolFactory(args);
|
|
@@ -2379,6 +2451,64 @@ async function prepareResponsesTools({
|
|
|
2379
2451
|
}
|
|
2380
2452
|
|
|
2381
2453
|
// src/responses/xai-responses-language-model.ts
|
|
2454
|
+
function createXaiResponsesStreamError({
|
|
2455
|
+
message,
|
|
2456
|
+
code,
|
|
2457
|
+
eventType,
|
|
2458
|
+
data
|
|
2459
|
+
}) {
|
|
2460
|
+
const statusCode = getHttpStatusCode(code);
|
|
2461
|
+
return createProviderStreamError({
|
|
2462
|
+
message,
|
|
2463
|
+
type: eventType,
|
|
2464
|
+
code: code != null ? code : void 0,
|
|
2465
|
+
...statusCode != null ? {
|
|
2466
|
+
statusCode,
|
|
2467
|
+
isRetryable: isRetryableStatusCode(statusCode)
|
|
2468
|
+
} : getXaiResponsesStreamErrorMetadata(code),
|
|
2469
|
+
data
|
|
2470
|
+
});
|
|
2471
|
+
}
|
|
2472
|
+
function getXaiResponsesStreamErrorMetadata(code) {
|
|
2473
|
+
switch (code) {
|
|
2474
|
+
case "rate_limit_exceeded":
|
|
2475
|
+
case "rate_limit_error":
|
|
2476
|
+
return { statusCode: 429, isRetryable: true };
|
|
2477
|
+
case "insufficient_quota":
|
|
2478
|
+
return { statusCode: 429, isRetryable: false };
|
|
2479
|
+
case "api_error":
|
|
2480
|
+
case "internal_server_error":
|
|
2481
|
+
case "server_error":
|
|
2482
|
+
return { statusCode: 500, isRetryable: true };
|
|
2483
|
+
case "overloaded_error":
|
|
2484
|
+
case "service_unavailable":
|
|
2485
|
+
return { statusCode: 503, isRetryable: true };
|
|
2486
|
+
case "timeout":
|
|
2487
|
+
case "timeout_error":
|
|
2488
|
+
return { statusCode: 504, isRetryable: true };
|
|
2489
|
+
case "authentication_error":
|
|
2490
|
+
case "invalid_api_key":
|
|
2491
|
+
return { statusCode: 401, isRetryable: false };
|
|
2492
|
+
case "permission_error":
|
|
2493
|
+
return { statusCode: 403, isRetryable: false };
|
|
2494
|
+
case "not_found_error":
|
|
2495
|
+
case "model_not_found":
|
|
2496
|
+
return { statusCode: 404, isRetryable: false };
|
|
2497
|
+
case "bad_request":
|
|
2498
|
+
case "context_length_exceeded":
|
|
2499
|
+
case "invalid_request_error":
|
|
2500
|
+
return { statusCode: 400, isRetryable: false };
|
|
2501
|
+
default:
|
|
2502
|
+
return {};
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
function getHttpStatusCode(value) {
|
|
2506
|
+
const statusCode = typeof value === "string" && /^\d{3}$/.test(value) ? Number(value) : value;
|
|
2507
|
+
return typeof statusCode === "number" && Number.isInteger(statusCode) && statusCode >= 400 && statusCode <= 599 ? statusCode : void 0;
|
|
2508
|
+
}
|
|
2509
|
+
function isRetryableStatusCode(statusCode) {
|
|
2510
|
+
return statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500;
|
|
2511
|
+
}
|
|
2382
2512
|
var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
2383
2513
|
constructor(modelId, config) {
|
|
2384
2514
|
this.specificationVersion = "v4";
|
|
@@ -2679,6 +2809,14 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2679
2809
|
input: toolInput,
|
|
2680
2810
|
providerExecuted: true
|
|
2681
2811
|
});
|
|
2812
|
+
if (part.type === "web_search_call") {
|
|
2813
|
+
content.push({
|
|
2814
|
+
type: "tool-result",
|
|
2815
|
+
toolCallId: part.id,
|
|
2816
|
+
toolName,
|
|
2817
|
+
result: mapWebSearchAction(part.action)
|
|
2818
|
+
});
|
|
2819
|
+
}
|
|
2682
2820
|
continue;
|
|
2683
2821
|
}
|
|
2684
2822
|
switch (part.type) {
|
|
@@ -2977,10 +3115,29 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2977
3115
|
if (event.response.usage) {
|
|
2978
3116
|
usage = convertXaiResponsesUsage(event.response.usage);
|
|
2979
3117
|
}
|
|
3118
|
+
if (event.response.error != null) {
|
|
3119
|
+
controller.enqueue({
|
|
3120
|
+
type: "error",
|
|
3121
|
+
error: createXaiResponsesStreamError({
|
|
3122
|
+
message: event.response.error.message,
|
|
3123
|
+
code: event.response.error.code,
|
|
3124
|
+
eventType: event.type,
|
|
3125
|
+
data: event
|
|
3126
|
+
})
|
|
3127
|
+
});
|
|
3128
|
+
}
|
|
2980
3129
|
return;
|
|
2981
3130
|
}
|
|
2982
3131
|
if (event.type === "error") {
|
|
2983
|
-
controller.enqueue({
|
|
3132
|
+
controller.enqueue({
|
|
3133
|
+
type: "error",
|
|
3134
|
+
error: createXaiResponsesStreamError({
|
|
3135
|
+
message: event.message,
|
|
3136
|
+
code: event.code,
|
|
3137
|
+
eventType: event.type,
|
|
3138
|
+
data: event
|
|
3139
|
+
})
|
|
3140
|
+
});
|
|
2984
3141
|
return;
|
|
2985
3142
|
}
|
|
2986
3143
|
if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
|
|
@@ -3207,7 +3364,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
3207
3364
|
type: "tool-result",
|
|
3208
3365
|
toolCallId: part.id,
|
|
3209
3366
|
toolName,
|
|
3210
|
-
result: {}
|
|
3367
|
+
result: part.type === "web_search_call" ? mapWebSearchAction(part.action) : {}
|
|
3211
3368
|
});
|
|
3212
3369
|
}
|
|
3213
3370
|
return;
|
|
@@ -3309,6 +3466,410 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
3309
3466
|
};
|
|
3310
3467
|
}
|
|
3311
3468
|
};
|
|
3469
|
+
function mapWebSearchAction(action) {
|
|
3470
|
+
var _a;
|
|
3471
|
+
const parsed = webSearchWireActionSchema.safeParse(action);
|
|
3472
|
+
if (!parsed.success) return {};
|
|
3473
|
+
const a = parsed.data;
|
|
3474
|
+
const sources = (_a = a.sources) == null ? void 0 : _a.flatMap((s) => {
|
|
3475
|
+
const source = webSearchWireSourceSchema.safeParse(s);
|
|
3476
|
+
return source.success ? [source.data] : [];
|
|
3477
|
+
});
|
|
3478
|
+
const sourcesExtra = sources != null && sources.length > 0 ? { sources } : {};
|
|
3479
|
+
switch (a.type) {
|
|
3480
|
+
case "search":
|
|
3481
|
+
return {
|
|
3482
|
+
action: {
|
|
3483
|
+
type: "search",
|
|
3484
|
+
...a.query != null && { query: a.query },
|
|
3485
|
+
...a.queries != null && { queries: a.queries }
|
|
3486
|
+
},
|
|
3487
|
+
...sourcesExtra
|
|
3488
|
+
};
|
|
3489
|
+
case "open_page":
|
|
3490
|
+
return { action: { type: "openPage", url: a.url }, ...sourcesExtra };
|
|
3491
|
+
case "find_in_page":
|
|
3492
|
+
return {
|
|
3493
|
+
action: { type: "findInPage", url: a.url, pattern: a.pattern },
|
|
3494
|
+
...sourcesExtra
|
|
3495
|
+
};
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3498
|
+
|
|
3499
|
+
// src/responses/xai-responses-batch.ts
|
|
3500
|
+
var xaiBatchEndpoint = "/v1/responses";
|
|
3501
|
+
var xaiBatchName = "ai-sdk-text-batch";
|
|
3502
|
+
var xaiBatchResultsPageSize = 1e3;
|
|
3503
|
+
var xaiBatchResponseSchema = lazySchema7(
|
|
3504
|
+
() => zodSchema7(
|
|
3505
|
+
z15.object({
|
|
3506
|
+
batch_id: z15.string(),
|
|
3507
|
+
name: z15.string().nullish(),
|
|
3508
|
+
create_time: z15.string().nullish(),
|
|
3509
|
+
expire_time: z15.string().nullish(),
|
|
3510
|
+
cancel_time: z15.string().nullish(),
|
|
3511
|
+
cancel_by_xai_message: z15.string().nullish(),
|
|
3512
|
+
state: z15.object({
|
|
3513
|
+
num_requests: z15.number().nullish(),
|
|
3514
|
+
num_pending: z15.number().nullish(),
|
|
3515
|
+
num_success: z15.number().nullish(),
|
|
3516
|
+
num_error: z15.number().nullish(),
|
|
3517
|
+
num_cancelled: z15.number().nullish()
|
|
3518
|
+
}).nullish()
|
|
3519
|
+
})
|
|
3520
|
+
)
|
|
3521
|
+
);
|
|
3522
|
+
var xaiBatchErrorSchema = z15.object({
|
|
3523
|
+
code: z15.union([z15.string(), z15.number()]).nullish(),
|
|
3524
|
+
message: z15.string().nullish()
|
|
3525
|
+
});
|
|
3526
|
+
var xaiBatchResultSchema = z15.object({
|
|
3527
|
+
batch_request_id: z15.string(),
|
|
3528
|
+
batch_result: z15.object({
|
|
3529
|
+
response: z15.object({
|
|
3530
|
+
chat_get_completion: z15.unknown().nullish()
|
|
3531
|
+
}).nullish(),
|
|
3532
|
+
error: xaiBatchErrorSchema.nullish()
|
|
3533
|
+
}).nullish(),
|
|
3534
|
+
error_message: z15.string().nullish()
|
|
3535
|
+
});
|
|
3536
|
+
var xaiBatchResultsPageSchema = lazySchema7(
|
|
3537
|
+
() => zodSchema7(
|
|
3538
|
+
z15.object({
|
|
3539
|
+
results: z15.array(xaiBatchResultSchema),
|
|
3540
|
+
pagination_token: z15.string().nullish()
|
|
3541
|
+
})
|
|
3542
|
+
)
|
|
3543
|
+
);
|
|
3544
|
+
var XaiResponsesBatch = class {
|
|
3545
|
+
constructor(options) {
|
|
3546
|
+
this.options = options;
|
|
3547
|
+
}
|
|
3548
|
+
async startBatch(options) {
|
|
3549
|
+
var _a, _b;
|
|
3550
|
+
const fileParts = [];
|
|
3551
|
+
const warnings = options.webhookUrl == null ? [] : [
|
|
3552
|
+
{
|
|
3553
|
+
warning: {
|
|
3554
|
+
type: "unsupported",
|
|
3555
|
+
feature: "webhookUrl",
|
|
3556
|
+
details: "The xAI Batch API does not support per-batch webhook URLs."
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3559
|
+
];
|
|
3560
|
+
for (const request of options.requests) {
|
|
3561
|
+
const preparedRequest = await this.options.prepareRequest(request);
|
|
3562
|
+
fileParts.push(
|
|
3563
|
+
JSON.stringify({
|
|
3564
|
+
custom_id: request.id,
|
|
3565
|
+
method: "POST",
|
|
3566
|
+
url: xaiBatchEndpoint,
|
|
3567
|
+
body: preparedRequest.body
|
|
3568
|
+
}),
|
|
3569
|
+
"\n"
|
|
3570
|
+
);
|
|
3571
|
+
for (const warning of preparedRequest.warnings) {
|
|
3572
|
+
warnings.push({ requestId: request.id, warning });
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
const filename = "batch.jsonl";
|
|
3576
|
+
const file = new Blob(fileParts, { type: "application/jsonl" });
|
|
3577
|
+
fileParts.length = 0;
|
|
3578
|
+
const formData = new FormData();
|
|
3579
|
+
formData.append("file", file, filename);
|
|
3580
|
+
const headers = combineHeaders4(
|
|
3581
|
+
(_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a),
|
|
3582
|
+
options.headers
|
|
3583
|
+
);
|
|
3584
|
+
const { value: uploadedFile } = await postFormDataToApi({
|
|
3585
|
+
url: this.getUrl("/files"),
|
|
3586
|
+
headers,
|
|
3587
|
+
formData,
|
|
3588
|
+
failedResponseHandler: xaiFailedResponseHandler,
|
|
3589
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
3590
|
+
xaiFilesResponseSchema
|
|
3591
|
+
),
|
|
3592
|
+
abortSignal: options.abortSignal,
|
|
3593
|
+
fetch: this.options.config.fetch
|
|
3594
|
+
});
|
|
3595
|
+
const { value: batch } = await postJsonToApi4({
|
|
3596
|
+
url: this.getUrl("/batches"),
|
|
3597
|
+
headers,
|
|
3598
|
+
body: {
|
|
3599
|
+
name: xaiBatchName,
|
|
3600
|
+
input_file_id: uploadedFile.id
|
|
3601
|
+
},
|
|
3602
|
+
failedResponseHandler: xaiFailedResponseHandler,
|
|
3603
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
3604
|
+
xaiBatchResponseSchema
|
|
3605
|
+
),
|
|
3606
|
+
abortSignal: options.abortSignal,
|
|
3607
|
+
fetch: this.options.config.fetch
|
|
3608
|
+
});
|
|
3609
|
+
return {
|
|
3610
|
+
batchId: batch.batch_id,
|
|
3611
|
+
...convertXaiBatchStatus(batch),
|
|
3612
|
+
warnings
|
|
3613
|
+
};
|
|
3614
|
+
}
|
|
3615
|
+
async getBatchStatus(options) {
|
|
3616
|
+
return convertXaiBatchStatus(await this.retrieveBatch(options));
|
|
3617
|
+
}
|
|
3618
|
+
async getBatchResults(options) {
|
|
3619
|
+
const batch = await this.retrieveBatch(options);
|
|
3620
|
+
if (convertXaiBatchStatus(batch).status === "pending") {
|
|
3621
|
+
throw new InvalidArgumentError({
|
|
3622
|
+
argument: "batchId",
|
|
3623
|
+
message: `xAI batch "${options.batchId}" is not complete.`
|
|
3624
|
+
});
|
|
3625
|
+
}
|
|
3626
|
+
return convertAsyncIteratorToReadableStream(
|
|
3627
|
+
this.iterateBatchResults(options)
|
|
3628
|
+
);
|
|
3629
|
+
}
|
|
3630
|
+
async retrieveBatch(options) {
|
|
3631
|
+
var _a, _b;
|
|
3632
|
+
const { value: batch } = await getFromApi2({
|
|
3633
|
+
url: this.getUrl(`/batches/${encodeURIComponent(options.batchId)}`),
|
|
3634
|
+
headers: combineHeaders4((_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
3635
|
+
failedResponseHandler: xaiFailedResponseHandler,
|
|
3636
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
3637
|
+
xaiBatchResponseSchema
|
|
3638
|
+
),
|
|
3639
|
+
abortSignal: options.abortSignal,
|
|
3640
|
+
fetch: this.options.config.fetch,
|
|
3641
|
+
validateUrl: false
|
|
3642
|
+
});
|
|
3643
|
+
return batch;
|
|
3644
|
+
}
|
|
3645
|
+
async *iterateBatchResults(options) {
|
|
3646
|
+
var _a, _b, _c;
|
|
3647
|
+
let paginationToken;
|
|
3648
|
+
do {
|
|
3649
|
+
const query = new URLSearchParams({
|
|
3650
|
+
limit: String(xaiBatchResultsPageSize)
|
|
3651
|
+
});
|
|
3652
|
+
if (paginationToken != null) {
|
|
3653
|
+
query.set("pagination_token", paginationToken);
|
|
3654
|
+
}
|
|
3655
|
+
const { value: page } = await getFromApi2({
|
|
3656
|
+
url: this.getUrl(
|
|
3657
|
+
`/batches/${encodeURIComponent(options.batchId)}/results?${query}`
|
|
3658
|
+
),
|
|
3659
|
+
headers: combineHeaders4(
|
|
3660
|
+
(_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a),
|
|
3661
|
+
options.headers
|
|
3662
|
+
),
|
|
3663
|
+
failedResponseHandler: xaiFailedResponseHandler,
|
|
3664
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
3665
|
+
xaiBatchResultsPageSchema
|
|
3666
|
+
),
|
|
3667
|
+
abortSignal: options.abortSignal,
|
|
3668
|
+
fetch: this.options.config.fetch,
|
|
3669
|
+
validateUrl: false
|
|
3670
|
+
});
|
|
3671
|
+
for (const result of page.results) {
|
|
3672
|
+
yield await this.convertBatchResult(result);
|
|
3673
|
+
}
|
|
3674
|
+
paginationToken = (_c = page.pagination_token) != null ? _c : void 0;
|
|
3675
|
+
} while (paginationToken != null);
|
|
3676
|
+
}
|
|
3677
|
+
async convertBatchResult(result) {
|
|
3678
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3679
|
+
const error = (_a = result.batch_result) == null ? void 0 : _a.error;
|
|
3680
|
+
if (((_c = (_b = result.error_message) == null ? void 0 : _b.length) != null ? _c : 0) > 0 || (error == null ? void 0 : error.code) != null && error.code !== 0 && error.code !== "0" || (error == null ? void 0 : error.code) == null && ((_e = (_d = error == null ? void 0 : error.message) == null ? void 0 : _d.length) != null ? _e : 0) > 0) {
|
|
3681
|
+
const convertedError = convertXaiBatchError(result);
|
|
3682
|
+
return {
|
|
3683
|
+
id: result.batch_request_id,
|
|
3684
|
+
status: isXaiCancellationError(error == null ? void 0 : error.code) ? "cancelled" : "failed",
|
|
3685
|
+
error: convertedError
|
|
3686
|
+
};
|
|
3687
|
+
}
|
|
3688
|
+
const response = (_f = result.batch_result) == null ? void 0 : _f.response;
|
|
3689
|
+
if ((response == null ? void 0 : response.chat_get_completion) != null) {
|
|
3690
|
+
const validation = await safeValidateTypes({
|
|
3691
|
+
value: response.chat_get_completion,
|
|
3692
|
+
schema: xaiChatResponseSchema
|
|
3693
|
+
});
|
|
3694
|
+
if (!validation.success) {
|
|
3695
|
+
return invalidXaiBatchResult(result.batch_request_id);
|
|
3696
|
+
}
|
|
3697
|
+
const conversion = convertXaiChatBatchResponse(validation.value);
|
|
3698
|
+
return conversion.success ? {
|
|
3699
|
+
id: result.batch_request_id,
|
|
3700
|
+
status: "succeeded",
|
|
3701
|
+
result: conversion.result
|
|
3702
|
+
} : {
|
|
3703
|
+
id: result.batch_request_id,
|
|
3704
|
+
status: "failed",
|
|
3705
|
+
error: conversion.error
|
|
3706
|
+
};
|
|
3707
|
+
}
|
|
3708
|
+
return invalidXaiBatchResult(result.batch_request_id);
|
|
3709
|
+
}
|
|
3710
|
+
getUrl(path) {
|
|
3711
|
+
var _a;
|
|
3712
|
+
return `${(_a = this.options.config.baseURL) != null ? _a : "https://api.x.ai/v1"}${path}`;
|
|
3713
|
+
}
|
|
3714
|
+
};
|
|
3715
|
+
var XaiResponsesBatchLanguageModel = class _XaiResponsesBatchLanguageModel extends XaiResponsesLanguageModel {
|
|
3716
|
+
static [WORKFLOW_SERIALIZE4](model) {
|
|
3717
|
+
return XaiResponsesLanguageModel[WORKFLOW_SERIALIZE4](model);
|
|
3718
|
+
}
|
|
3719
|
+
static [WORKFLOW_DESERIALIZE4](options) {
|
|
3720
|
+
return new _XaiResponsesBatchLanguageModel(options.modelId, options.config);
|
|
3721
|
+
}
|
|
3722
|
+
constructor(modelId, config) {
|
|
3723
|
+
super(modelId, config);
|
|
3724
|
+
this.batch = new XaiResponsesBatch({
|
|
3725
|
+
config,
|
|
3726
|
+
prepareRequest: async (request) => {
|
|
3727
|
+
const { args: body, warnings } = await this.getArgs(request.options);
|
|
3728
|
+
return { body, warnings };
|
|
3729
|
+
}
|
|
3730
|
+
});
|
|
3731
|
+
}
|
|
3732
|
+
experimental_doStartBatch(options) {
|
|
3733
|
+
return this.batch.startBatch(options);
|
|
3734
|
+
}
|
|
3735
|
+
experimental_doGetBatchStatus(options) {
|
|
3736
|
+
return this.batch.getBatchStatus(options);
|
|
3737
|
+
}
|
|
3738
|
+
experimental_doGetBatchResults(options) {
|
|
3739
|
+
return this.batch.getBatchResults(options);
|
|
3740
|
+
}
|
|
3741
|
+
};
|
|
3742
|
+
function convertXaiBatchStatus(batch) {
|
|
3743
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3744
|
+
const requestCounts = normalizeBatchRequestCounts({
|
|
3745
|
+
total: (_a = batch.state) == null ? void 0 : _a.num_requests,
|
|
3746
|
+
pending: (_b = batch.state) == null ? void 0 : _b.num_pending,
|
|
3747
|
+
completed: (_c = batch.state) == null ? void 0 : _c.num_success,
|
|
3748
|
+
failed: ((_d = batch.state) == null ? void 0 : _d.num_error) != null && ((_e = batch.state) == null ? void 0 : _e.num_cancelled) != null ? batch.state.num_error + batch.state.num_cancelled : void 0
|
|
3749
|
+
});
|
|
3750
|
+
const isCancelled = batch.cancel_time != null || batch.cancel_by_xai_message != null;
|
|
3751
|
+
const isExpired = isPastDate(batch.expire_time);
|
|
3752
|
+
const status = isCancelled || isExpired ? "failed" : requestCounts != null && requestCounts.total > 0 && requestCounts.pending === 0 ? "completed" : "pending";
|
|
3753
|
+
return {
|
|
3754
|
+
status,
|
|
3755
|
+
...requestCounts != null ? { requestCounts } : {},
|
|
3756
|
+
...isCancelled ? {
|
|
3757
|
+
error: {
|
|
3758
|
+
message: (_f = batch.cancel_by_xai_message) != null ? _f : `xAI batch "${batch.batch_id}" was cancelled.`,
|
|
3759
|
+
code: "batch_cancelled"
|
|
3760
|
+
}
|
|
3761
|
+
} : isExpired ? {
|
|
3762
|
+
error: {
|
|
3763
|
+
message: `xAI batch "${batch.batch_id}" expired.`,
|
|
3764
|
+
code: "batch_expired"
|
|
3765
|
+
}
|
|
3766
|
+
} : {},
|
|
3767
|
+
...batch.create_time != null ? { createdAt: batch.create_time } : {},
|
|
3768
|
+
...batch.expire_time != null ? { expiresAt: batch.expire_time } : {}
|
|
3769
|
+
};
|
|
3770
|
+
}
|
|
3771
|
+
function isPastDate(value) {
|
|
3772
|
+
if (value == null) {
|
|
3773
|
+
return false;
|
|
3774
|
+
}
|
|
3775
|
+
const timestamp = Date.parse(value);
|
|
3776
|
+
return !Number.isNaN(timestamp) && timestamp <= Date.now();
|
|
3777
|
+
}
|
|
3778
|
+
function convertXaiBatchError(result) {
|
|
3779
|
+
var _a;
|
|
3780
|
+
const error = (_a = result.batch_result) == null ? void 0 : _a.error;
|
|
3781
|
+
return {
|
|
3782
|
+
message: result.error_message || (error == null ? void 0 : error.message) || "xAI batch request failed.",
|
|
3783
|
+
...(error == null ? void 0 : error.code) != null && error.code !== 0 && error.code !== "0" ? { code: String(error.code) } : {}
|
|
3784
|
+
};
|
|
3785
|
+
}
|
|
3786
|
+
function isXaiCancellationError(code) {
|
|
3787
|
+
const normalizedCode = String(code).toLowerCase();
|
|
3788
|
+
return code === 1 || normalizedCode === "1" || normalizedCode === "cancelled" || normalizedCode === "batch_cancelled";
|
|
3789
|
+
}
|
|
3790
|
+
function invalidXaiBatchResult(id) {
|
|
3791
|
+
return {
|
|
3792
|
+
id,
|
|
3793
|
+
status: "failed",
|
|
3794
|
+
error: {
|
|
3795
|
+
message: "xAI returned an invalid Responses batch result.",
|
|
3796
|
+
code: "invalid_response"
|
|
3797
|
+
}
|
|
3798
|
+
};
|
|
3799
|
+
}
|
|
3800
|
+
function convertXaiChatBatchResponse(response) {
|
|
3801
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3802
|
+
if (response.error != null) {
|
|
3803
|
+
return {
|
|
3804
|
+
success: false,
|
|
3805
|
+
error: {
|
|
3806
|
+
message: response.error,
|
|
3807
|
+
...response.code != null ? { code: response.code } : {}
|
|
3808
|
+
}
|
|
3809
|
+
};
|
|
3810
|
+
}
|
|
3811
|
+
const choice = (_a = response.choices) == null ? void 0 : _a[0];
|
|
3812
|
+
if (choice == null) {
|
|
3813
|
+
return {
|
|
3814
|
+
success: false,
|
|
3815
|
+
error: {
|
|
3816
|
+
message: "xAI returned a batch response without any choices.",
|
|
3817
|
+
code: "invalid_response"
|
|
3818
|
+
}
|
|
3819
|
+
};
|
|
3820
|
+
}
|
|
3821
|
+
if ((_b = choice.message.tool_calls) == null ? void 0 : _b.length) {
|
|
3822
|
+
return unsupportedXaiBatchContent("tool_calls");
|
|
3823
|
+
}
|
|
3824
|
+
const content = [];
|
|
3825
|
+
if (choice.message.content) {
|
|
3826
|
+
content.push({ type: "text", text: choice.message.content });
|
|
3827
|
+
}
|
|
3828
|
+
if (choice.message.reasoning_content) {
|
|
3829
|
+
content.push({
|
|
3830
|
+
type: "reasoning",
|
|
3831
|
+
text: choice.message.reasoning_content
|
|
3832
|
+
});
|
|
3833
|
+
}
|
|
3834
|
+
for (const url of (_c = response.citations) != null ? _c : []) {
|
|
3835
|
+
content.push({
|
|
3836
|
+
type: "source",
|
|
3837
|
+
sourceType: "url",
|
|
3838
|
+
id: url,
|
|
3839
|
+
url
|
|
3840
|
+
});
|
|
3841
|
+
}
|
|
3842
|
+
return {
|
|
3843
|
+
success: true,
|
|
3844
|
+
result: {
|
|
3845
|
+
content,
|
|
3846
|
+
finishReason: {
|
|
3847
|
+
unified: mapXaiFinishReason(choice.finish_reason),
|
|
3848
|
+
raw: (_d = choice.finish_reason) != null ? _d : void 0
|
|
3849
|
+
},
|
|
3850
|
+
usage: response.usage ? convertXaiChatUsage(response.usage) : createNullLanguageModelUsage(),
|
|
3851
|
+
response: getResponseMetadata(response),
|
|
3852
|
+
warnings: [],
|
|
3853
|
+
...(((_e = response.usage) == null ? void 0 : _e.cost_in_usd_ticks) != null || response.service_tier != null) && {
|
|
3854
|
+
providerMetadata: {
|
|
3855
|
+
xai: {
|
|
3856
|
+
...((_f = response.usage) == null ? void 0 : _f.cost_in_usd_ticks) != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {},
|
|
3857
|
+
...response.service_tier != null ? { serviceTier: response.service_tier } : {}
|
|
3858
|
+
}
|
|
3859
|
+
}
|
|
3860
|
+
}
|
|
3861
|
+
}
|
|
3862
|
+
};
|
|
3863
|
+
}
|
|
3864
|
+
function unsupportedXaiBatchContent(type) {
|
|
3865
|
+
return {
|
|
3866
|
+
success: false,
|
|
3867
|
+
error: {
|
|
3868
|
+
message: `xAI returned "${type}" content, but tool content is not supported in AI SDK text batches.`,
|
|
3869
|
+
code: "unsupported_content"
|
|
3870
|
+
}
|
|
3871
|
+
};
|
|
3872
|
+
}
|
|
3312
3873
|
|
|
3313
3874
|
// src/realtime/xai-realtime-event-mapper.ts
|
|
3314
3875
|
function parseXaiRealtimeServerEvent(raw) {
|
|
@@ -3681,43 +4242,43 @@ var XaiRealtimeModel = class {
|
|
|
3681
4242
|
|
|
3682
4243
|
// src/tool/code-execution.ts
|
|
3683
4244
|
import { createProviderExecutedToolFactory as createProviderExecutedToolFactory6 } from "@ai-sdk/provider-utils";
|
|
3684
|
-
import { z as
|
|
3685
|
-
var codeExecutionOutputSchema =
|
|
3686
|
-
output:
|
|
3687
|
-
error:
|
|
4245
|
+
import { z as z16 } from "zod/v4";
|
|
4246
|
+
var codeExecutionOutputSchema = z16.object({
|
|
4247
|
+
output: z16.string().describe("the output of the code execution"),
|
|
4248
|
+
error: z16.string().optional().describe("any error that occurred")
|
|
3688
4249
|
});
|
|
3689
4250
|
var codeExecutionToolFactory = createProviderExecutedToolFactory6({
|
|
3690
4251
|
id: "xai.code_execution",
|
|
3691
|
-
inputSchema:
|
|
4252
|
+
inputSchema: z16.object({}).describe("no input parameters"),
|
|
3692
4253
|
outputSchema: codeExecutionOutputSchema
|
|
3693
4254
|
});
|
|
3694
4255
|
var codeExecution = (args = {}) => codeExecutionToolFactory(args);
|
|
3695
4256
|
|
|
3696
4257
|
// src/tool/view-image.ts
|
|
3697
4258
|
import { createProviderExecutedToolFactory as createProviderExecutedToolFactory7 } from "@ai-sdk/provider-utils";
|
|
3698
|
-
import { z as
|
|
3699
|
-
var viewImageOutputSchema =
|
|
3700
|
-
description:
|
|
3701
|
-
objects:
|
|
4259
|
+
import { z as z17 } from "zod/v4";
|
|
4260
|
+
var viewImageOutputSchema = z17.object({
|
|
4261
|
+
description: z17.string().describe("description of the image"),
|
|
4262
|
+
objects: z17.array(z17.string()).optional().describe("objects detected in the image")
|
|
3702
4263
|
});
|
|
3703
4264
|
var viewImageToolFactory = createProviderExecutedToolFactory7({
|
|
3704
4265
|
id: "xai.view_image",
|
|
3705
|
-
inputSchema:
|
|
4266
|
+
inputSchema: z17.object({}).describe("no input parameters"),
|
|
3706
4267
|
outputSchema: viewImageOutputSchema
|
|
3707
4268
|
});
|
|
3708
4269
|
var viewImage = (args = {}) => viewImageToolFactory(args);
|
|
3709
4270
|
|
|
3710
4271
|
// src/tool/view-x-video.ts
|
|
3711
4272
|
import { createProviderExecutedToolFactory as createProviderExecutedToolFactory8 } from "@ai-sdk/provider-utils";
|
|
3712
|
-
import { z as
|
|
3713
|
-
var viewXVideoOutputSchema =
|
|
3714
|
-
transcript:
|
|
3715
|
-
description:
|
|
3716
|
-
duration:
|
|
4273
|
+
import { z as z18 } from "zod/v4";
|
|
4274
|
+
var viewXVideoOutputSchema = z18.object({
|
|
4275
|
+
transcript: z18.string().optional().describe("transcript of the video"),
|
|
4276
|
+
description: z18.string().describe("description of the video content"),
|
|
4277
|
+
duration: z18.number().optional().describe("duration in seconds")
|
|
3717
4278
|
});
|
|
3718
4279
|
var viewXVideoToolFactory = createProviderExecutedToolFactory8({
|
|
3719
4280
|
id: "xai.view_x_video",
|
|
3720
|
-
inputSchema:
|
|
4281
|
+
inputSchema: z18.object({}).describe("no input parameters"),
|
|
3721
4282
|
outputSchema: viewXVideoOutputSchema
|
|
3722
4283
|
});
|
|
3723
4284
|
var viewXVideo = (args = {}) => viewXVideoToolFactory(args);
|
|
@@ -3735,45 +4296,28 @@ var xaiTools = {
|
|
|
3735
4296
|
};
|
|
3736
4297
|
|
|
3737
4298
|
// src/version.ts
|
|
3738
|
-
var VERSION = true ? "4.0.
|
|
4299
|
+
var VERSION = true ? "4.0.48" : "0.0.0-test";
|
|
3739
4300
|
|
|
3740
4301
|
// src/files/xai-files.ts
|
|
3741
4302
|
import {
|
|
3742
|
-
combineHeaders as
|
|
4303
|
+
combineHeaders as combineHeaders5,
|
|
3743
4304
|
convertInlineFileDataToUint8Array,
|
|
3744
|
-
createJsonResponseHandler as
|
|
4305
|
+
createJsonResponseHandler as createJsonResponseHandler5,
|
|
3745
4306
|
parseProviderOptions as parseProviderOptions6,
|
|
3746
|
-
postFormDataToApi
|
|
4307
|
+
postFormDataToApi as postFormDataToApi2
|
|
3747
4308
|
} from "@ai-sdk/provider-utils";
|
|
3748
4309
|
|
|
3749
|
-
// src/files/xai-files-api.ts
|
|
3750
|
-
import { lazySchema as lazySchema6, zodSchema as zodSchema6 } from "@ai-sdk/provider-utils";
|
|
3751
|
-
import { z as z17 } from "zod/v4";
|
|
3752
|
-
var xaiFilesResponseSchema = lazySchema6(
|
|
3753
|
-
() => zodSchema6(
|
|
3754
|
-
z17.object({
|
|
3755
|
-
id: z17.string(),
|
|
3756
|
-
object: z17.string().nullish(),
|
|
3757
|
-
bytes: z17.number().nullish(),
|
|
3758
|
-
created_at: z17.number().nullish(),
|
|
3759
|
-
filename: z17.string().nullish(),
|
|
3760
|
-
purpose: z17.string().nullish(),
|
|
3761
|
-
status: z17.string().nullish()
|
|
3762
|
-
})
|
|
3763
|
-
)
|
|
3764
|
-
);
|
|
3765
|
-
|
|
3766
4310
|
// src/files/xai-files-options.ts
|
|
3767
4311
|
import {
|
|
3768
|
-
lazySchema as
|
|
3769
|
-
zodSchema as
|
|
4312
|
+
lazySchema as lazySchema8,
|
|
4313
|
+
zodSchema as zodSchema8
|
|
3770
4314
|
} from "@ai-sdk/provider-utils";
|
|
3771
|
-
import { z as
|
|
3772
|
-
var xaiFilesOptionsSchema =
|
|
3773
|
-
() =>
|
|
3774
|
-
|
|
3775
|
-
teamId:
|
|
3776
|
-
filePath:
|
|
4315
|
+
import { z as z19 } from "zod/v4";
|
|
4316
|
+
var xaiFilesOptionsSchema = lazySchema8(
|
|
4317
|
+
() => zodSchema8(
|
|
4318
|
+
z19.looseObject({
|
|
4319
|
+
teamId: z19.string().optional(),
|
|
4320
|
+
filePath: z19.string().optional()
|
|
3777
4321
|
})
|
|
3778
4322
|
)
|
|
3779
4323
|
);
|
|
@@ -3812,12 +4356,12 @@ var XaiFiles = class {
|
|
|
3812
4356
|
if ((xaiOptions == null ? void 0 : xaiOptions.teamId) != null) {
|
|
3813
4357
|
formData.append("team_id", xaiOptions.teamId);
|
|
3814
4358
|
}
|
|
3815
|
-
const { value: response } = await
|
|
4359
|
+
const { value: response } = await postFormDataToApi2({
|
|
3816
4360
|
url: `${this.config.baseURL}/files`,
|
|
3817
|
-
headers:
|
|
4361
|
+
headers: combineHeaders5(this.config.headers()),
|
|
3818
4362
|
formData,
|
|
3819
4363
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3820
|
-
successfulResponseHandler:
|
|
4364
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
3821
4365
|
xaiFilesResponseSchema
|
|
3822
4366
|
),
|
|
3823
4367
|
fetch: this.config.fetch
|
|
@@ -3844,42 +4388,46 @@ import {
|
|
|
3844
4388
|
APICallError as APICallError2
|
|
3845
4389
|
} from "@ai-sdk/provider";
|
|
3846
4390
|
import {
|
|
3847
|
-
combineHeaders as
|
|
4391
|
+
combineHeaders as combineHeaders6,
|
|
3848
4392
|
convertUint8ArrayToBase64,
|
|
3849
|
-
createJsonResponseHandler as
|
|
4393
|
+
createJsonResponseHandler as createJsonResponseHandler6,
|
|
3850
4394
|
extractResponseHeaders as extractResponseHeaders2,
|
|
3851
|
-
getFromApi as
|
|
4395
|
+
getFromApi as getFromApi3,
|
|
3852
4396
|
getTopLevelMediaType as getTopLevelMediaType3,
|
|
3853
4397
|
parseProviderOptions as parseProviderOptions7,
|
|
3854
|
-
postJsonToApi as
|
|
4398
|
+
postJsonToApi as postJsonToApi5,
|
|
3855
4399
|
safeParseJSON as safeParseJSON2
|
|
3856
4400
|
} from "@ai-sdk/provider-utils";
|
|
3857
|
-
import { z as
|
|
4401
|
+
import { z as z21 } from "zod/v4";
|
|
3858
4402
|
|
|
3859
4403
|
// src/xai-video-model-options.ts
|
|
3860
|
-
import { lazySchema as
|
|
3861
|
-
import { z as
|
|
3862
|
-
var nonEmptyStringSchema =
|
|
3863
|
-
var resolutionSchema =
|
|
3864
|
-
var modeSchema =
|
|
4404
|
+
import { lazySchema as lazySchema9, zodSchema as zodSchema9 } from "@ai-sdk/provider-utils";
|
|
4405
|
+
import { z as z20 } from "zod/v4";
|
|
4406
|
+
var nonEmptyStringSchema = z20.string().min(1);
|
|
4407
|
+
var resolutionSchema = z20.enum(["480p", "720p", "1080p"]);
|
|
4408
|
+
var modeSchema = z20.enum(["edit-video", "extend-video", "reference-to-video"]);
|
|
3865
4409
|
var baseFields = {
|
|
3866
|
-
pollIntervalMs:
|
|
3867
|
-
pollTimeoutMs:
|
|
4410
|
+
pollIntervalMs: z20.number().positive().nullish(),
|
|
4411
|
+
pollTimeoutMs: z20.number().positive().nullish(),
|
|
3868
4412
|
resolution: resolutionSchema.nullish()
|
|
3869
4413
|
};
|
|
3870
|
-
var runtimeSchema =
|
|
4414
|
+
var runtimeSchema = z20.looseObject({
|
|
3871
4415
|
mode: modeSchema.optional(),
|
|
3872
4416
|
videoUrl: nonEmptyStringSchema.optional(),
|
|
3873
|
-
referenceImageUrls:
|
|
3874
|
-
referenceVoiceIds:
|
|
3875
|
-
user:
|
|
4417
|
+
referenceImageUrls: z20.array(nonEmptyStringSchema).min(1).max(7).optional(),
|
|
4418
|
+
referenceVoiceIds: z20.array(nonEmptyStringSchema).max(3).optional(),
|
|
4419
|
+
user: z20.string().optional(),
|
|
3876
4420
|
...baseFields
|
|
3877
4421
|
});
|
|
3878
|
-
var xaiVideoModelOptionsSchema =
|
|
3879
|
-
() =>
|
|
4422
|
+
var xaiVideoModelOptionsSchema = lazySchema9(
|
|
4423
|
+
() => zodSchema9(runtimeSchema)
|
|
3880
4424
|
);
|
|
3881
4425
|
|
|
3882
4426
|
// src/xai-video-model.ts
|
|
4427
|
+
function encodePathSegment(value) {
|
|
4428
|
+
const encodedValue = encodeURIComponent(value);
|
|
4429
|
+
return encodedValue === "." ? "%252E" : encodedValue === ".." ? "%252E%252E" : encodedValue;
|
|
4430
|
+
}
|
|
3883
4431
|
var RESOLUTION_MAP = {
|
|
3884
4432
|
"1920x1080": "1080p",
|
|
3885
4433
|
"1280x720": "720p",
|
|
@@ -4166,12 +4714,12 @@ var XaiVideoModel = class {
|
|
|
4166
4714
|
} else {
|
|
4167
4715
|
endpoint = `${baseURL}/videos/generations`;
|
|
4168
4716
|
}
|
|
4169
|
-
const { value: createResponse, responseHeaders } = await
|
|
4717
|
+
const { value: createResponse, responseHeaders } = await postJsonToApi5({
|
|
4170
4718
|
url: endpoint,
|
|
4171
|
-
headers:
|
|
4719
|
+
headers: combineHeaders6(this.config.headers(), options.headers),
|
|
4172
4720
|
body,
|
|
4173
4721
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4174
|
-
successfulResponseHandler:
|
|
4722
|
+
successfulResponseHandler: createJsonResponseHandler6(
|
|
4175
4723
|
xaiCreateVideoResponseSchema
|
|
4176
4724
|
),
|
|
4177
4725
|
abortSignal: options.abortSignal,
|
|
@@ -4199,10 +4747,10 @@ var XaiVideoModel = class {
|
|
|
4199
4747
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4200
4748
|
const { requestId } = options.operation;
|
|
4201
4749
|
const baseURL = (_d = this.config.baseURL) != null ? _d : "https://api.x.ai/v1";
|
|
4202
|
-
const { value: statusResponse, responseHeaders } = await
|
|
4203
|
-
url: `${baseURL}/videos/${requestId}`,
|
|
4750
|
+
const { value: statusResponse, responseHeaders } = await getFromApi3({
|
|
4751
|
+
url: `${baseURL}/videos/${encodePathSegment(requestId)}`,
|
|
4204
4752
|
validateUrl: false,
|
|
4205
|
-
headers:
|
|
4753
|
+
headers: combineHeaders6(this.config.headers(), options.headers),
|
|
4206
4754
|
successfulResponseHandler: xaiVideoStatusResponseHandler,
|
|
4207
4755
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4208
4756
|
abortSignal: options.abortSignal,
|
|
@@ -4290,27 +4838,27 @@ var XaiVideoModel = class {
|
|
|
4290
4838
|
};
|
|
4291
4839
|
}
|
|
4292
4840
|
};
|
|
4293
|
-
var xaiCreateVideoResponseSchema =
|
|
4294
|
-
request_id:
|
|
4841
|
+
var xaiCreateVideoResponseSchema = z21.object({
|
|
4842
|
+
request_id: z21.string().nullish()
|
|
4295
4843
|
});
|
|
4296
|
-
var xaiVideoStatusResponseSchema =
|
|
4297
|
-
status:
|
|
4298
|
-
video:
|
|
4299
|
-
url:
|
|
4300
|
-
duration:
|
|
4301
|
-
respect_moderation:
|
|
4844
|
+
var xaiVideoStatusResponseSchema = z21.object({
|
|
4845
|
+
status: z21.string().nullish(),
|
|
4846
|
+
video: z21.object({
|
|
4847
|
+
url: z21.string(),
|
|
4848
|
+
duration: z21.number().nullish(),
|
|
4849
|
+
respect_moderation: z21.boolean().nullish()
|
|
4302
4850
|
}).nullish(),
|
|
4303
|
-
model:
|
|
4304
|
-
usage:
|
|
4305
|
-
cost_in_usd_ticks:
|
|
4851
|
+
model: z21.string().nullish(),
|
|
4852
|
+
usage: z21.object({
|
|
4853
|
+
cost_in_usd_ticks: z21.number().nullish()
|
|
4306
4854
|
}).nullish(),
|
|
4307
|
-
progress:
|
|
4308
|
-
error:
|
|
4309
|
-
code:
|
|
4310
|
-
message:
|
|
4855
|
+
progress: z21.number().nullish(),
|
|
4856
|
+
error: z21.object({
|
|
4857
|
+
code: z21.string().nullish(),
|
|
4858
|
+
message: z21.string().nullish()
|
|
4311
4859
|
}).nullish()
|
|
4312
4860
|
});
|
|
4313
|
-
var xaiVideoStatusJsonResponseHandler =
|
|
4861
|
+
var xaiVideoStatusJsonResponseHandler = createJsonResponseHandler6(
|
|
4314
4862
|
xaiVideoStatusResponseSchema
|
|
4315
4863
|
);
|
|
4316
4864
|
var MAX_PENDING_BODY_BYTES = 1024 * 1024;
|
|
@@ -4374,69 +4922,69 @@ var xaiVideoStatusResponseHandler = async (options) => {
|
|
|
4374
4922
|
|
|
4375
4923
|
// src/xai-speech-model.ts
|
|
4376
4924
|
import {
|
|
4377
|
-
combineHeaders as
|
|
4925
|
+
combineHeaders as combineHeaders7,
|
|
4378
4926
|
convertBase64ToUint8Array,
|
|
4379
4927
|
createBinaryResponseHandler as createBinaryResponseHandler2,
|
|
4380
|
-
createJsonResponseHandler as
|
|
4928
|
+
createJsonResponseHandler as createJsonResponseHandler7,
|
|
4381
4929
|
parseProviderOptions as parseProviderOptions8,
|
|
4382
|
-
postJsonToApi as
|
|
4930
|
+
postJsonToApi as postJsonToApi6,
|
|
4383
4931
|
resolve,
|
|
4384
4932
|
serializeModelOptions as serializeModelOptions4,
|
|
4385
|
-
WORKFLOW_DESERIALIZE as
|
|
4386
|
-
WORKFLOW_SERIALIZE as
|
|
4933
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE5,
|
|
4934
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE5
|
|
4387
4935
|
} from "@ai-sdk/provider-utils";
|
|
4388
|
-
import { z as
|
|
4936
|
+
import { z as z23 } from "zod/v4";
|
|
4389
4937
|
|
|
4390
4938
|
// src/xai-speech-model-options.ts
|
|
4391
4939
|
import {
|
|
4392
|
-
lazySchema as
|
|
4393
|
-
zodSchema as
|
|
4940
|
+
lazySchema as lazySchema10,
|
|
4941
|
+
zodSchema as zodSchema10
|
|
4394
4942
|
} from "@ai-sdk/provider-utils";
|
|
4395
|
-
import { z as
|
|
4396
|
-
var xaiSpeechModelOptionsSchema =
|
|
4397
|
-
() =>
|
|
4398
|
-
|
|
4943
|
+
import { z as z22 } from "zod/v4";
|
|
4944
|
+
var xaiSpeechModelOptionsSchema = lazySchema10(
|
|
4945
|
+
() => zodSchema10(
|
|
4946
|
+
z22.object({
|
|
4399
4947
|
/**
|
|
4400
4948
|
* Sample rate of the generated audio in Hz.
|
|
4401
4949
|
*/
|
|
4402
|
-
sampleRate:
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4950
|
+
sampleRate: z22.union([
|
|
4951
|
+
z22.literal(8e3),
|
|
4952
|
+
z22.literal(16e3),
|
|
4953
|
+
z22.literal(22050),
|
|
4954
|
+
z22.literal(24e3),
|
|
4955
|
+
z22.literal(44100),
|
|
4956
|
+
z22.literal(48e3)
|
|
4409
4957
|
]).nullish(),
|
|
4410
4958
|
/**
|
|
4411
4959
|
* MP3 bit rate in bits per second. Only applies when outputFormat is mp3.
|
|
4412
4960
|
*/
|
|
4413
|
-
bitRate:
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4961
|
+
bitRate: z22.union([
|
|
4962
|
+
z22.literal(32e3),
|
|
4963
|
+
z22.literal(64e3),
|
|
4964
|
+
z22.literal(96e3),
|
|
4965
|
+
z22.literal(128e3),
|
|
4966
|
+
z22.literal(192e3)
|
|
4419
4967
|
]).nullish(),
|
|
4420
4968
|
/**
|
|
4421
4969
|
* Reduce time to first audio chunk, trading some quality for latency.
|
|
4422
4970
|
*/
|
|
4423
|
-
optimizeStreamingLatency:
|
|
4971
|
+
optimizeStreamingLatency: z22.union([z22.literal(0), z22.literal(1), z22.literal(2)]).nullish(),
|
|
4424
4972
|
/**
|
|
4425
4973
|
* Normalize written-form text into spoken-form text before synthesis.
|
|
4426
4974
|
*/
|
|
4427
|
-
textNormalization:
|
|
4975
|
+
textNormalization: z22.boolean().nullish(),
|
|
4428
4976
|
/**
|
|
4429
4977
|
* Return character-level timing metadata alongside the audio. When
|
|
4430
4978
|
* enabled, the response carries per-character start/end times and the
|
|
4431
4979
|
* total duration, exposed via `providerMetadata.xai`.
|
|
4432
4980
|
*/
|
|
4433
|
-
withTimestamps:
|
|
4981
|
+
withTimestamps: z22.boolean().nullish(),
|
|
4434
4982
|
/**
|
|
4435
4983
|
* Map of phrases to spoken substitutions applied before synthesis.
|
|
4436
4984
|
* Values may be respellings (`{ 'Acme Mobile': 'Acme Mobull' }`) or IPA
|
|
4437
4985
|
* phonetics (`{ nginx: '/ˈɛndʒɪn ˈɛks/' }`).
|
|
4438
4986
|
*/
|
|
4439
|
-
replace:
|
|
4987
|
+
replace: z22.record(z22.string(), z22.string()).nullish()
|
|
4440
4988
|
})
|
|
4441
4989
|
)
|
|
4442
4990
|
);
|
|
@@ -4448,13 +4996,13 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
4448
4996
|
this.config = config;
|
|
4449
4997
|
this.specificationVersion = "v4";
|
|
4450
4998
|
}
|
|
4451
|
-
static [
|
|
4999
|
+
static [WORKFLOW_SERIALIZE5](model) {
|
|
4452
5000
|
return serializeModelOptions4({
|
|
4453
5001
|
modelId: model.modelId,
|
|
4454
5002
|
config: model.config
|
|
4455
5003
|
});
|
|
4456
5004
|
}
|
|
4457
|
-
static [
|
|
5005
|
+
static [WORKFLOW_DESERIALIZE5](options) {
|
|
4458
5006
|
return new _XaiSpeechModel(options.modelId, options.config);
|
|
4459
5007
|
}
|
|
4460
5008
|
get provider() {
|
|
@@ -4530,15 +5078,15 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
4530
5078
|
var _a, _b, _c;
|
|
4531
5079
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4532
5080
|
const { requestBody, warnings, withTimestamps } = await this.getArgs(options);
|
|
4533
|
-
const { value, responseHeaders, rawValue } = await
|
|
5081
|
+
const { value, responseHeaders, rawValue } = await postJsonToApi6({
|
|
4534
5082
|
url: `${this.config.baseURL}/tts`,
|
|
4535
|
-
headers:
|
|
5083
|
+
headers: combineHeaders7(
|
|
4536
5084
|
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
4537
5085
|
options.headers
|
|
4538
5086
|
),
|
|
4539
5087
|
body: requestBody,
|
|
4540
5088
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4541
|
-
successfulResponseHandler: withTimestamps ?
|
|
5089
|
+
successfulResponseHandler: withTimestamps ? createJsonResponseHandler7(xaiSpeechTimestampsResponseSchema) : createBinaryResponseHandler2(),
|
|
4542
5090
|
abortSignal: options.abortSignal,
|
|
4543
5091
|
fetch: this.config.fetch
|
|
4544
5092
|
});
|
|
@@ -4579,109 +5127,109 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
4579
5127
|
};
|
|
4580
5128
|
}
|
|
4581
5129
|
};
|
|
4582
|
-
var xaiSpeechTimestampsResponseSchema =
|
|
4583
|
-
audio:
|
|
4584
|
-
content_type:
|
|
4585
|
-
duration:
|
|
4586
|
-
audio_timestamps:
|
|
4587
|
-
graph_chars:
|
|
4588
|
-
graph_times:
|
|
5130
|
+
var xaiSpeechTimestampsResponseSchema = z23.object({
|
|
5131
|
+
audio: z23.string().nullish(),
|
|
5132
|
+
content_type: z23.string().nullish(),
|
|
5133
|
+
duration: z23.number().nullish(),
|
|
5134
|
+
audio_timestamps: z23.object({
|
|
5135
|
+
graph_chars: z23.array(z23.string()),
|
|
5136
|
+
graph_times: z23.array(z23.tuple([z23.number(), z23.number()]))
|
|
4589
5137
|
}).nullish()
|
|
4590
5138
|
});
|
|
4591
5139
|
|
|
4592
5140
|
// src/xai-transcription-model.ts
|
|
4593
5141
|
import {
|
|
4594
|
-
InvalidArgumentError
|
|
5142
|
+
InvalidArgumentError as InvalidArgumentError2
|
|
4595
5143
|
} from "@ai-sdk/provider";
|
|
4596
5144
|
import {
|
|
4597
|
-
combineHeaders as
|
|
5145
|
+
combineHeaders as combineHeaders8,
|
|
4598
5146
|
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
|
4599
|
-
createJsonResponseHandler as
|
|
5147
|
+
createJsonResponseHandler as createJsonResponseHandler8,
|
|
4600
5148
|
connectToWebSocket,
|
|
4601
5149
|
mediaTypeToExtension,
|
|
4602
5150
|
parseProviderOptions as parseProviderOptions9,
|
|
4603
|
-
postFormDataToApi as
|
|
5151
|
+
postFormDataToApi as postFormDataToApi3,
|
|
4604
5152
|
safeParseJSON as safeParseJSON3,
|
|
4605
5153
|
serializeModelOptions as serializeModelOptions5,
|
|
4606
5154
|
toWebSocketUrl,
|
|
4607
5155
|
waitForWebSocketBufferDrain,
|
|
4608
|
-
WORKFLOW_DESERIALIZE as
|
|
4609
|
-
WORKFLOW_SERIALIZE as
|
|
5156
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE6,
|
|
5157
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE6
|
|
4610
5158
|
} from "@ai-sdk/provider-utils";
|
|
4611
|
-
import { z as
|
|
5159
|
+
import { z as z25 } from "zod/v4";
|
|
4612
5160
|
|
|
4613
5161
|
// src/xai-transcription-model-options.ts
|
|
4614
5162
|
import {
|
|
4615
|
-
lazySchema as
|
|
4616
|
-
zodSchema as
|
|
5163
|
+
lazySchema as lazySchema11,
|
|
5164
|
+
zodSchema as zodSchema11
|
|
4617
5165
|
} from "@ai-sdk/provider-utils";
|
|
4618
|
-
import { z as
|
|
4619
|
-
var xaiTranscriptionModelOptionsSchema =
|
|
4620
|
-
() =>
|
|
4621
|
-
|
|
5166
|
+
import { z as z24 } from "zod/v4";
|
|
5167
|
+
var xaiTranscriptionModelOptionsSchema = lazySchema11(
|
|
5168
|
+
() => zodSchema11(
|
|
5169
|
+
z24.object({
|
|
4622
5170
|
/**
|
|
4623
5171
|
* Audio encoding for raw, headerless input audio.
|
|
4624
5172
|
*/
|
|
4625
|
-
audioFormat:
|
|
5173
|
+
audioFormat: z24.enum(["pcm", "mulaw", "alaw"]).nullish(),
|
|
4626
5174
|
/**
|
|
4627
5175
|
* Sample rate of the input audio in Hz.
|
|
4628
5176
|
*/
|
|
4629
|
-
sampleRate:
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
5177
|
+
sampleRate: z24.union([
|
|
5178
|
+
z24.literal(8e3),
|
|
5179
|
+
z24.literal(16e3),
|
|
5180
|
+
z24.literal(22050),
|
|
5181
|
+
z24.literal(24e3),
|
|
5182
|
+
z24.literal(44100),
|
|
5183
|
+
z24.literal(48e3)
|
|
4636
5184
|
]).nullish(),
|
|
4637
5185
|
/**
|
|
4638
5186
|
* Language code used for inverse text normalization.
|
|
4639
5187
|
*/
|
|
4640
|
-
language:
|
|
5188
|
+
language: z24.string().nullish(),
|
|
4641
5189
|
/**
|
|
4642
5190
|
* Enable inverse text normalization. Requires `language`.
|
|
4643
5191
|
*/
|
|
4644
|
-
format:
|
|
5192
|
+
format: z24.boolean().nullish(),
|
|
4645
5193
|
/**
|
|
4646
5194
|
* Enable per-channel transcription for multichannel audio.
|
|
4647
5195
|
*/
|
|
4648
|
-
multichannel:
|
|
5196
|
+
multichannel: z24.boolean().nullish(),
|
|
4649
5197
|
/**
|
|
4650
5198
|
* Number of interleaved audio channels.
|
|
4651
5199
|
*/
|
|
4652
|
-
channels:
|
|
5200
|
+
channels: z24.number().int().min(2).max(8).nullish(),
|
|
4653
5201
|
/**
|
|
4654
5202
|
* Enable speaker diarization.
|
|
4655
5203
|
*/
|
|
4656
|
-
diarize:
|
|
5204
|
+
diarize: z24.boolean().nullish(),
|
|
4657
5205
|
/**
|
|
4658
5206
|
* Terms to bias transcription toward.
|
|
4659
5207
|
*/
|
|
4660
|
-
keyterm:
|
|
5208
|
+
keyterm: z24.union([z24.string(), z24.array(z24.string())]).nullish(),
|
|
4661
5209
|
/**
|
|
4662
5210
|
* Include filler words such as "uh" and "um" in the transcript.
|
|
4663
5211
|
*/
|
|
4664
|
-
fillerWords:
|
|
5212
|
+
fillerWords: z24.boolean().nullish(),
|
|
4665
5213
|
/**
|
|
4666
5214
|
* Options for streaming speech-to-text over WebSocket.
|
|
4667
5215
|
*/
|
|
4668
|
-
streaming:
|
|
5216
|
+
streaming: z24.object({
|
|
4669
5217
|
/**
|
|
4670
5218
|
* Emit interim transcript results while speech is being processed.
|
|
4671
5219
|
*/
|
|
4672
|
-
interimResults:
|
|
5220
|
+
interimResults: z24.boolean().optional(),
|
|
4673
5221
|
/**
|
|
4674
5222
|
* Silence duration in milliseconds before an utterance-final event.
|
|
4675
5223
|
*/
|
|
4676
|
-
endpointing:
|
|
5224
|
+
endpointing: z24.number().int().min(0).max(5e3).optional(),
|
|
4677
5225
|
/**
|
|
4678
5226
|
* End-of-turn detection threshold. When set, enables Smart Turn.
|
|
4679
5227
|
*/
|
|
4680
|
-
smartTurn:
|
|
5228
|
+
smartTurn: z24.number().min(0).max(1).optional(),
|
|
4681
5229
|
/**
|
|
4682
5230
|
* Maximum silence duration in milliseconds before forcing speech_final.
|
|
4683
5231
|
*/
|
|
4684
|
-
smartTurnTimeout:
|
|
5232
|
+
smartTurnTimeout: z24.number().int().min(1).max(5e3).optional()
|
|
4685
5233
|
}).optional()
|
|
4686
5234
|
})
|
|
4687
5235
|
)
|
|
@@ -4694,13 +5242,13 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
4694
5242
|
this.config = config;
|
|
4695
5243
|
this.specificationVersion = "v4";
|
|
4696
5244
|
}
|
|
4697
|
-
static [
|
|
5245
|
+
static [WORKFLOW_SERIALIZE6](model) {
|
|
4698
5246
|
return serializeModelOptions5({
|
|
4699
5247
|
modelId: model.modelId,
|
|
4700
5248
|
config: model.config
|
|
4701
5249
|
});
|
|
4702
5250
|
}
|
|
4703
|
-
static [
|
|
5251
|
+
static [WORKFLOW_DESERIALIZE6](options) {
|
|
4704
5252
|
return new _XaiTranscriptionModel(options.modelId, options.config);
|
|
4705
5253
|
}
|
|
4706
5254
|
get provider() {
|
|
@@ -4756,12 +5304,12 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
4756
5304
|
value: response,
|
|
4757
5305
|
responseHeaders,
|
|
4758
5306
|
rawValue: rawResponse
|
|
4759
|
-
} = await
|
|
5307
|
+
} = await postFormDataToApi3({
|
|
4760
5308
|
url: `${(_d = this.config.baseURL) != null ? _d : "https://api.x.ai/v1"}/stt`,
|
|
4761
|
-
headers:
|
|
5309
|
+
headers: combineHeaders8((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), options.headers),
|
|
4762
5310
|
formData,
|
|
4763
5311
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4764
|
-
successfulResponseHandler:
|
|
5312
|
+
successfulResponseHandler: createJsonResponseHandler8(
|
|
4765
5313
|
xaiTranscriptionResponseSchema
|
|
4766
5314
|
),
|
|
4767
5315
|
abortSignal: options.abortSignal,
|
|
@@ -4795,7 +5343,7 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
4795
5343
|
schema: xaiTranscriptionModelOptionsSchema
|
|
4796
5344
|
});
|
|
4797
5345
|
if ((xaiOptions == null ? void 0 : xaiOptions.multichannel) === true && xaiOptions.channels == null) {
|
|
4798
|
-
throw new
|
|
5346
|
+
throw new InvalidArgumentError2({
|
|
4799
5347
|
argument: "providerOptions",
|
|
4800
5348
|
message: "providerOptions.xai.channels is required when providerOptions.xai.multichannel is true"
|
|
4801
5349
|
});
|
|
@@ -4818,7 +5366,7 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
4818
5366
|
inputAudioFormat: options.inputAudioFormat,
|
|
4819
5367
|
providerOptions: xaiOptions
|
|
4820
5368
|
});
|
|
4821
|
-
const headers =
|
|
5369
|
+
const headers = combineHeaders8((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), options.headers);
|
|
4822
5370
|
return {
|
|
4823
5371
|
request: { body: url.toString() },
|
|
4824
5372
|
response: {
|
|
@@ -5080,15 +5628,15 @@ function timingFromXaiEvent(event) {
|
|
|
5080
5628
|
...event.start != null && event.duration != null ? { endSecond: event.start + event.duration } : {}
|
|
5081
5629
|
};
|
|
5082
5630
|
}
|
|
5083
|
-
var xaiTranscriptionResponseSchema =
|
|
5084
|
-
text:
|
|
5085
|
-
language:
|
|
5086
|
-
duration:
|
|
5087
|
-
words:
|
|
5088
|
-
|
|
5089
|
-
text:
|
|
5090
|
-
start:
|
|
5091
|
-
end:
|
|
5631
|
+
var xaiTranscriptionResponseSchema = z25.object({
|
|
5632
|
+
text: z25.string(),
|
|
5633
|
+
language: z25.string().nullish(),
|
|
5634
|
+
duration: z25.number().nullish(),
|
|
5635
|
+
words: z25.array(
|
|
5636
|
+
z25.object({
|
|
5637
|
+
text: z25.string(),
|
|
5638
|
+
start: z25.number(),
|
|
5639
|
+
end: z25.number()
|
|
5092
5640
|
})
|
|
5093
5641
|
).nullish()
|
|
5094
5642
|
});
|
|
@@ -5120,7 +5668,7 @@ function createXai(options = {}) {
|
|
|
5120
5668
|
});
|
|
5121
5669
|
};
|
|
5122
5670
|
const createResponsesLanguageModel = (modelId) => {
|
|
5123
|
-
return new
|
|
5671
|
+
return new XaiResponsesBatchLanguageModel(modelId, {
|
|
5124
5672
|
provider: "xai.responses",
|
|
5125
5673
|
baseURL,
|
|
5126
5674
|
headers: getHeaders,
|