@ai-sdk/xai 5.0.8 → 5.0.10
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 +15 -0
- package/dist/index.js +242 -284
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -101,7 +101,6 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
101
101
|
files,
|
|
102
102
|
mask
|
|
103
103
|
}) {
|
|
104
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
105
104
|
const warnings = [];
|
|
106
105
|
if (size != null) {
|
|
107
106
|
warnings.push({
|
|
@@ -139,22 +138,22 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
139
138
|
if (aspectRatio != null) {
|
|
140
139
|
body.aspect_ratio = aspectRatio;
|
|
141
140
|
}
|
|
142
|
-
if (
|
|
141
|
+
if (xaiOptions?.output_format != null) {
|
|
143
142
|
body.output_format = xaiOptions.output_format;
|
|
144
143
|
}
|
|
145
|
-
if (
|
|
144
|
+
if (xaiOptions?.sync_mode != null) {
|
|
146
145
|
body.sync_mode = xaiOptions.sync_mode;
|
|
147
146
|
}
|
|
148
|
-
if (
|
|
147
|
+
if (xaiOptions?.aspect_ratio != null && aspectRatio == null) {
|
|
149
148
|
body.aspect_ratio = xaiOptions.aspect_ratio;
|
|
150
149
|
}
|
|
151
|
-
if (
|
|
150
|
+
if (xaiOptions?.resolution != null) {
|
|
152
151
|
body.resolution = xaiOptions.resolution;
|
|
153
152
|
}
|
|
154
|
-
if (
|
|
153
|
+
if (xaiOptions?.quality != null) {
|
|
155
154
|
body.quality = xaiOptions.quality;
|
|
156
155
|
}
|
|
157
|
-
if (
|
|
156
|
+
if (xaiOptions?.user != null) {
|
|
158
157
|
body.user = xaiOptions.user;
|
|
159
158
|
}
|
|
160
159
|
if (imageUrls.length === 1) {
|
|
@@ -162,11 +161,11 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
162
161
|
} else if (imageUrls.length > 1) {
|
|
163
162
|
body.images = imageUrls.map((url) => ({ url, type: "image_url" }));
|
|
164
163
|
}
|
|
165
|
-
const baseURL =
|
|
166
|
-
const currentDate =
|
|
164
|
+
const baseURL = this.config.baseURL ?? "https://api.x.ai/v1";
|
|
165
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
167
166
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
168
167
|
url: `${baseURL}${endpoint}`,
|
|
169
|
-
headers: combineHeaders(
|
|
168
|
+
headers: combineHeaders(this.config.headers?.(), headers),
|
|
170
169
|
body,
|
|
171
170
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
172
171
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -199,7 +198,7 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
199
198
|
images: response.data.map((item) => ({
|
|
200
199
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {}
|
|
201
200
|
})),
|
|
202
|
-
...
|
|
201
|
+
...response.usage?.cost_in_usd_ticks != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {}
|
|
203
202
|
}
|
|
204
203
|
}
|
|
205
204
|
};
|
|
@@ -267,7 +266,7 @@ function getResponseMetadata({
|
|
|
267
266
|
return createLanguageModelResponseMetadata({
|
|
268
267
|
id,
|
|
269
268
|
model,
|
|
270
|
-
created: created
|
|
269
|
+
created: created ?? created_at
|
|
271
270
|
});
|
|
272
271
|
}
|
|
273
272
|
|
|
@@ -369,7 +368,6 @@ var xaiFilePartProviderOptions = z5.object({
|
|
|
369
368
|
async function convertToXaiResponsesInput({
|
|
370
369
|
prompt
|
|
371
370
|
}) {
|
|
372
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
373
371
|
const input = [];
|
|
374
372
|
const inputWarnings = [];
|
|
375
373
|
for (const message of prompt) {
|
|
@@ -418,7 +416,7 @@ async function convertToXaiResponsesInput({
|
|
|
418
416
|
contentParts.push({
|
|
419
417
|
type: "input_image",
|
|
420
418
|
image_url: imageUrl,
|
|
421
|
-
...
|
|
419
|
+
...filePartOptions?.imageDetail != null && {
|
|
422
420
|
detail: filePartOptions.imageDetail
|
|
423
421
|
}
|
|
424
422
|
});
|
|
@@ -456,7 +454,7 @@ async function convertToXaiResponsesInput({
|
|
|
456
454
|
for (const part of message.content) {
|
|
457
455
|
switch (part.type) {
|
|
458
456
|
case "text": {
|
|
459
|
-
const id = typeof
|
|
457
|
+
const id = typeof part.providerOptions?.xai?.itemId === "string" ? part.providerOptions.xai.itemId : void 0;
|
|
460
458
|
input.push({
|
|
461
459
|
role: "assistant",
|
|
462
460
|
content: part.text,
|
|
@@ -468,10 +466,10 @@ async function convertToXaiResponsesInput({
|
|
|
468
466
|
if (part.providerExecuted) {
|
|
469
467
|
break;
|
|
470
468
|
}
|
|
471
|
-
const id = typeof
|
|
469
|
+
const id = typeof part.providerOptions?.xai?.itemId === "string" ? part.providerOptions.xai.itemId : void 0;
|
|
472
470
|
input.push({
|
|
473
471
|
type: "function_call",
|
|
474
|
-
id: id
|
|
472
|
+
id: id ?? part.toolCallId,
|
|
475
473
|
call_id: part.toolCallId,
|
|
476
474
|
name: part.toolName,
|
|
477
475
|
arguments: JSON.stringify(part.input),
|
|
@@ -483,8 +481,8 @@ async function convertToXaiResponsesInput({
|
|
|
483
481
|
break;
|
|
484
482
|
}
|
|
485
483
|
case "reasoning": {
|
|
486
|
-
const itemId = typeof
|
|
487
|
-
const encryptedContent = typeof
|
|
484
|
+
const itemId = typeof part.providerOptions?.xai?.itemId === "string" ? part.providerOptions.xai.itemId : void 0;
|
|
485
|
+
const encryptedContent = typeof part.providerOptions?.xai?.reasoningEncryptedContent === "string" ? part.providerOptions.xai.reasoningEncryptedContent : void 0;
|
|
488
486
|
if (itemId != null || encryptedContent != null) {
|
|
489
487
|
const summaryParts = [];
|
|
490
488
|
if (part.text.length > 0) {
|
|
@@ -495,7 +493,7 @@ async function convertToXaiResponsesInput({
|
|
|
495
493
|
}
|
|
496
494
|
input.push({
|
|
497
495
|
type: "reasoning",
|
|
498
|
-
id: itemId
|
|
496
|
+
id: itemId ?? "",
|
|
499
497
|
summary: summaryParts,
|
|
500
498
|
status: "completed",
|
|
501
499
|
...encryptedContent != null && {
|
|
@@ -543,7 +541,7 @@ async function convertToXaiResponsesInput({
|
|
|
543
541
|
outputValue = output.value;
|
|
544
542
|
break;
|
|
545
543
|
case "execution-denied":
|
|
546
|
-
outputValue =
|
|
544
|
+
outputValue = output.reason ?? "tool execution denied";
|
|
547
545
|
break;
|
|
548
546
|
case "json":
|
|
549
547
|
case "error-json":
|
|
@@ -605,9 +603,8 @@ async function convertToXaiResponsesInput({
|
|
|
605
603
|
|
|
606
604
|
// src/responses/convert-xai-responses-usage.ts
|
|
607
605
|
function convertXaiResponsesUsage(usage) {
|
|
608
|
-
|
|
609
|
-
const
|
|
610
|
-
const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0;
|
|
606
|
+
const cacheReadTokens = usage.input_tokens_details?.cached_tokens ?? 0;
|
|
607
|
+
const reasoningTokens = usage.output_tokens_details?.reasoning_tokens ?? 0;
|
|
611
608
|
const inputTokensIncludesCached = cacheReadTokens <= usage.input_tokens;
|
|
612
609
|
return {
|
|
613
610
|
inputTokens: {
|
|
@@ -1384,7 +1381,7 @@ async function prepareResponsesTools({
|
|
|
1384
1381
|
tools,
|
|
1385
1382
|
toolChoice
|
|
1386
1383
|
}) {
|
|
1387
|
-
const normalizedTools =
|
|
1384
|
+
const normalizedTools = tools?.length ? tools : void 0;
|
|
1388
1385
|
const toolWarnings = [];
|
|
1389
1386
|
if (normalizedTools == null) {
|
|
1390
1387
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
@@ -1552,7 +1549,7 @@ function createXaiResponsesStreamError({
|
|
|
1552
1549
|
return createProviderStreamError({
|
|
1553
1550
|
message,
|
|
1554
1551
|
type: eventType,
|
|
1555
|
-
code: code
|
|
1552
|
+
code: code ?? void 0,
|
|
1556
1553
|
...statusCode != null ? {
|
|
1557
1554
|
statusCode,
|
|
1558
1555
|
isRetryable: isRetryableStatusCode(statusCode)
|
|
@@ -1646,13 +1643,12 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1646
1643
|
reasoning
|
|
1647
1644
|
}
|
|
1648
1645
|
}) {
|
|
1649
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1650
1646
|
const warnings = [];
|
|
1651
|
-
const options =
|
|
1647
|
+
const options = await parseProviderOptions3({
|
|
1652
1648
|
provider: "xai",
|
|
1653
1649
|
providerOptions,
|
|
1654
1650
|
schema: xaiLanguageModelResponsesOptions
|
|
1655
|
-
})
|
|
1651
|
+
}) ?? {};
|
|
1656
1652
|
if (frequencyPenalty != null) {
|
|
1657
1653
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
1658
1654
|
}
|
|
@@ -1662,27 +1658,27 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1662
1658
|
if (stopSequences != null) {
|
|
1663
1659
|
warnings.push({ type: "unsupported", feature: "stopSequences" });
|
|
1664
1660
|
}
|
|
1665
|
-
const webSearchToolName =
|
|
1661
|
+
const webSearchToolName = tools?.find(
|
|
1666
1662
|
(tool) => tool.type === "provider" && tool.id === "xai.web_search"
|
|
1667
|
-
)
|
|
1668
|
-
const xSearchToolName =
|
|
1663
|
+
)?.name;
|
|
1664
|
+
const xSearchToolName = tools?.find(
|
|
1669
1665
|
(tool) => tool.type === "provider" && tool.id === "xai.x_search"
|
|
1670
|
-
)
|
|
1671
|
-
const codeExecutionToolName =
|
|
1666
|
+
)?.name;
|
|
1667
|
+
const codeExecutionToolName = tools?.find(
|
|
1672
1668
|
(tool) => tool.type === "provider" && tool.id === "xai.code_execution"
|
|
1673
|
-
)
|
|
1674
|
-
const mcpToolName =
|
|
1669
|
+
)?.name;
|
|
1670
|
+
const mcpToolName = tools?.find(
|
|
1675
1671
|
(tool) => tool.type === "provider" && tool.id === "xai.mcp"
|
|
1676
|
-
)
|
|
1677
|
-
const fileSearchToolName =
|
|
1672
|
+
)?.name;
|
|
1673
|
+
const fileSearchToolName = tools?.find(
|
|
1678
1674
|
(tool) => tool.type === "provider" && tool.id === "xai.file_search"
|
|
1679
|
-
)
|
|
1680
|
-
const imageGenerationToolName =
|
|
1675
|
+
)?.name;
|
|
1676
|
+
const imageGenerationToolName = tools?.find(
|
|
1681
1677
|
(tool) => tool.type === "provider" && tool.id === "xai.image_generation"
|
|
1682
|
-
)
|
|
1678
|
+
)?.name;
|
|
1683
1679
|
const { input, inputWarnings } = await convertToXaiResponsesInput({
|
|
1684
1680
|
prompt,
|
|
1685
|
-
store:
|
|
1681
|
+
store: options.store ?? true
|
|
1686
1682
|
});
|
|
1687
1683
|
warnings.push(...inputWarnings);
|
|
1688
1684
|
const {
|
|
@@ -1737,12 +1733,12 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1737
1733
|
top_k: topK,
|
|
1738
1734
|
min_p: options.minP,
|
|
1739
1735
|
seed,
|
|
1740
|
-
...
|
|
1736
|
+
...responseFormat?.type === "json" && {
|
|
1741
1737
|
text: {
|
|
1742
1738
|
format: responseFormat.schema != null ? {
|
|
1743
1739
|
type: "json_schema",
|
|
1744
1740
|
strict: true,
|
|
1745
|
-
name:
|
|
1741
|
+
name: responseFormat.name ?? "response",
|
|
1746
1742
|
description: responseFormat.description,
|
|
1747
1743
|
schema: responseFormat.schema
|
|
1748
1744
|
} : { type: "json_object" }
|
|
@@ -1805,7 +1801,6 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1805
1801
|
});
|
|
1806
1802
|
}
|
|
1807
1803
|
async doGenerate(options) {
|
|
1808
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1809
1804
|
const {
|
|
1810
1805
|
args: body,
|
|
1811
1806
|
warnings,
|
|
@@ -1821,8 +1816,8 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1821
1816
|
value: response,
|
|
1822
1817
|
rawValue: rawResponse
|
|
1823
1818
|
} = await postJsonToApi2({
|
|
1824
|
-
url: `${
|
|
1825
|
-
headers: combineHeaders2(
|
|
1819
|
+
url: `${this.config.baseURL ?? "https://api.x.ai/v1"}/responses`,
|
|
1820
|
+
headers: combineHeaders2(this.config.headers?.(), options.headers),
|
|
1826
1821
|
body,
|
|
1827
1822
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
1828
1823
|
successfulResponseHandler: createJsonResponseHandler2(
|
|
@@ -1846,7 +1841,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1846
1841
|
];
|
|
1847
1842
|
for (const part of response.output) {
|
|
1848
1843
|
if (part.type === "file_search_call") {
|
|
1849
|
-
const toolName = fileSearchToolName
|
|
1844
|
+
const toolName = fileSearchToolName ?? "file_search";
|
|
1850
1845
|
content.push({
|
|
1851
1846
|
type: "tool-call",
|
|
1852
1847
|
toolCallId: part.id,
|
|
@@ -1859,19 +1854,19 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1859
1854
|
toolCallId: part.id,
|
|
1860
1855
|
toolName,
|
|
1861
1856
|
result: {
|
|
1862
|
-
queries:
|
|
1863
|
-
results:
|
|
1857
|
+
queries: part.queries ?? [],
|
|
1858
|
+
results: part.results?.map((result) => ({
|
|
1864
1859
|
fileId: result.file_id,
|
|
1865
1860
|
filename: result.filename,
|
|
1866
1861
|
score: result.score,
|
|
1867
1862
|
text: result.text
|
|
1868
|
-
}))
|
|
1863
|
+
})) ?? null
|
|
1869
1864
|
}
|
|
1870
1865
|
});
|
|
1871
1866
|
continue;
|
|
1872
1867
|
}
|
|
1873
1868
|
if (part.type === "image_generation_call") {
|
|
1874
|
-
const toolName = imageGenerationToolName
|
|
1869
|
+
const toolName = imageGenerationToolName ?? "image_generation";
|
|
1875
1870
|
content.push({
|
|
1876
1871
|
type: "tool-call",
|
|
1877
1872
|
toolCallId: part.id,
|
|
@@ -1901,17 +1896,17 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1901
1896
|
continue;
|
|
1902
1897
|
}
|
|
1903
1898
|
if (part.type === "web_search_call" || part.type === "x_search_call" || part.type === "code_interpreter_call" || part.type === "code_execution_call" || part.type === "view_image_call" || part.type === "view_x_video_call" || part.type === "custom_tool_call" || part.type === "mcp_call") {
|
|
1904
|
-
let toolName =
|
|
1905
|
-
if (webSearchSubTools.includes(
|
|
1906
|
-
toolName = webSearchToolName
|
|
1907
|
-
} else if (xSearchSubTools.includes(
|
|
1908
|
-
toolName = xSearchToolName
|
|
1899
|
+
let toolName = part.name ?? "";
|
|
1900
|
+
if (webSearchSubTools.includes(part.name ?? "") || part.type === "web_search_call") {
|
|
1901
|
+
toolName = webSearchToolName ?? "web_search";
|
|
1902
|
+
} else if (xSearchSubTools.includes(part.name ?? "") || part.type === "x_search_call") {
|
|
1903
|
+
toolName = xSearchToolName ?? "x_search";
|
|
1909
1904
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
1910
|
-
toolName = codeExecutionToolName
|
|
1905
|
+
toolName = codeExecutionToolName ?? "code_execution";
|
|
1911
1906
|
} else if (part.type === "mcp_call") {
|
|
1912
|
-
toolName =
|
|
1907
|
+
toolName = mcpToolName ?? part.name ?? "mcp";
|
|
1913
1908
|
}
|
|
1914
|
-
const toolInput = part.type === "custom_tool_call" ?
|
|
1909
|
+
const toolInput = part.type === "custom_tool_call" ? part.input ?? "" : part.type === "mcp_call" ? part.arguments ?? "" : part.arguments ?? "";
|
|
1915
1910
|
content.push({
|
|
1916
1911
|
type: "tool-call",
|
|
1917
1912
|
toolCallId: part.id,
|
|
@@ -1946,7 +1941,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1946
1941
|
sourceType: "url",
|
|
1947
1942
|
id: this.config.generateId(),
|
|
1948
1943
|
url: annotation.url,
|
|
1949
|
-
title:
|
|
1944
|
+
title: annotation.title ?? annotation.url
|
|
1950
1945
|
});
|
|
1951
1946
|
}
|
|
1952
1947
|
}
|
|
@@ -1965,7 +1960,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1965
1960
|
break;
|
|
1966
1961
|
}
|
|
1967
1962
|
case "reasoning": {
|
|
1968
|
-
const texts = part.summary.length > 0 ? part.summary.map((s) => s.text) : (
|
|
1963
|
+
const texts = part.summary.length > 0 ? part.summary.map((s) => s.text) : (part.content ?? []).map((c) => c.text);
|
|
1969
1964
|
const reasoningText = texts.filter((text) => text && text.length > 0).join("");
|
|
1970
1965
|
if (reasoningText || part.encrypted_content) {
|
|
1971
1966
|
const hasMetadata = part.encrypted_content || part.id;
|
|
@@ -1995,16 +1990,16 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1995
1990
|
content,
|
|
1996
1991
|
finishReason: {
|
|
1997
1992
|
unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response.status),
|
|
1998
|
-
raw:
|
|
1993
|
+
raw: response.status ?? void 0
|
|
1999
1994
|
},
|
|
2000
1995
|
usage: response.usage ? convertXaiResponsesUsage(response.usage) : {
|
|
2001
1996
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
2002
1997
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
2003
1998
|
},
|
|
2004
|
-
...(
|
|
1999
|
+
...(response.usage?.cost_in_usd_ticks != null || response.service_tier != null || response.prompt_cache_key != null || response.safety_identifier != null) && {
|
|
2005
2000
|
providerMetadata: {
|
|
2006
2001
|
xai: {
|
|
2007
|
-
...
|
|
2002
|
+
...response.usage?.cost_in_usd_ticks != null && {
|
|
2008
2003
|
costInUsdTicks: response.usage.cost_in_usd_ticks
|
|
2009
2004
|
},
|
|
2010
2005
|
...response.service_tier != null && {
|
|
@@ -2029,7 +2024,6 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2029
2024
|
};
|
|
2030
2025
|
}
|
|
2031
2026
|
async doStream(options) {
|
|
2032
|
-
var _a, _b, _c;
|
|
2033
2027
|
const {
|
|
2034
2028
|
args,
|
|
2035
2029
|
warnings,
|
|
@@ -2045,8 +2039,8 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2045
2039
|
stream: true
|
|
2046
2040
|
};
|
|
2047
2041
|
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
2048
|
-
url: `${
|
|
2049
|
-
headers: combineHeaders2(
|
|
2042
|
+
url: `${this.config.baseURL ?? "https://api.x.ai/v1"}/responses`,
|
|
2043
|
+
headers: combineHeaders2(this.config.headers?.(), options.headers),
|
|
2050
2044
|
body,
|
|
2051
2045
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2052
2046
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -2078,7 +2072,6 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2078
2072
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2079
2073
|
},
|
|
2080
2074
|
transform(chunk, controller) {
|
|
2081
|
-
var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
2082
2075
|
if (options.includeRawChunks) {
|
|
2083
2076
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2084
2077
|
}
|
|
@@ -2183,7 +2176,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2183
2176
|
sourceType: "url",
|
|
2184
2177
|
id: self.config.generateId(),
|
|
2185
2178
|
url: annotation.url,
|
|
2186
|
-
title:
|
|
2179
|
+
title: annotation.title ?? annotation.url
|
|
2187
2180
|
});
|
|
2188
2181
|
}
|
|
2189
2182
|
}
|
|
@@ -2198,7 +2191,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2198
2191
|
sourceType: "url",
|
|
2199
2192
|
id: self.config.generateId(),
|
|
2200
2193
|
url: annotation.url,
|
|
2201
|
-
title:
|
|
2194
|
+
title: annotation.title ?? annotation.url
|
|
2202
2195
|
});
|
|
2203
2196
|
}
|
|
2204
2197
|
return;
|
|
@@ -2207,16 +2200,16 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2207
2200
|
const response2 = event.response;
|
|
2208
2201
|
if (response2.usage) {
|
|
2209
2202
|
usage = convertXaiResponsesUsage(response2.usage);
|
|
2210
|
-
costInUsdTicks =
|
|
2203
|
+
costInUsdTicks = response2.usage.cost_in_usd_ticks ?? void 0;
|
|
2211
2204
|
}
|
|
2212
|
-
serviceTier =
|
|
2213
|
-
promptCacheKey =
|
|
2214
|
-
safetyIdentifier =
|
|
2205
|
+
serviceTier = response2.service_tier ?? void 0;
|
|
2206
|
+
promptCacheKey = response2.prompt_cache_key ?? void 0;
|
|
2207
|
+
safetyIdentifier = response2.safety_identifier ?? void 0;
|
|
2215
2208
|
if (event.type === "response.incomplete") {
|
|
2216
|
-
const reason = "incomplete_details" in response2 ?
|
|
2209
|
+
const reason = "incomplete_details" in response2 ? response2.incomplete_details?.reason : void 0;
|
|
2217
2210
|
finishReason = {
|
|
2218
2211
|
unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
|
|
2219
|
-
raw: reason
|
|
2212
|
+
raw: reason ?? "incomplete"
|
|
2220
2213
|
};
|
|
2221
2214
|
} else if ("status" in response2 && response2.status) {
|
|
2222
2215
|
finishReason = {
|
|
@@ -2227,10 +2220,10 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2227
2220
|
return;
|
|
2228
2221
|
}
|
|
2229
2222
|
if (event.type === "response.failed") {
|
|
2230
|
-
const reason =
|
|
2223
|
+
const reason = event.response.incomplete_details?.reason;
|
|
2231
2224
|
finishReason = {
|
|
2232
2225
|
unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
|
|
2233
|
-
raw: reason
|
|
2226
|
+
raw: reason ?? "error"
|
|
2234
2227
|
};
|
|
2235
2228
|
if (event.response.usage) {
|
|
2236
2229
|
usage = convertXaiResponsesUsage(event.response.usage);
|
|
@@ -2280,7 +2273,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2280
2273
|
if (event.type === "response.image_generation_call.in_progress" || event.type === "response.image_generation_call.generating" || event.type === "response.image_generation_call.completed") {
|
|
2281
2274
|
if (!seenToolCalls.has(event.item_id)) {
|
|
2282
2275
|
seenToolCalls.add(event.item_id);
|
|
2283
|
-
const toolName = imageGenerationToolName
|
|
2276
|
+
const toolName = imageGenerationToolName ?? "image_generation";
|
|
2284
2277
|
controller.enqueue({
|
|
2285
2278
|
type: "tool-input-start",
|
|
2286
2279
|
id: event.item_id,
|
|
@@ -2339,7 +2332,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2339
2332
|
return;
|
|
2340
2333
|
}
|
|
2341
2334
|
if (part.type === "file_search_call") {
|
|
2342
|
-
const toolName = fileSearchToolName
|
|
2335
|
+
const toolName = fileSearchToolName ?? "file_search";
|
|
2343
2336
|
if (!seenToolCalls.has(part.id)) {
|
|
2344
2337
|
seenToolCalls.add(part.id);
|
|
2345
2338
|
controller.enqueue({
|
|
@@ -2370,20 +2363,20 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2370
2363
|
toolCallId: part.id,
|
|
2371
2364
|
toolName,
|
|
2372
2365
|
result: {
|
|
2373
|
-
queries:
|
|
2374
|
-
results:
|
|
2366
|
+
queries: part.queries ?? [],
|
|
2367
|
+
results: part.results?.map((result) => ({
|
|
2375
2368
|
fileId: result.file_id,
|
|
2376
2369
|
filename: result.filename,
|
|
2377
2370
|
score: result.score,
|
|
2378
2371
|
text: result.text
|
|
2379
|
-
}))
|
|
2372
|
+
})) ?? null
|
|
2380
2373
|
}
|
|
2381
2374
|
});
|
|
2382
2375
|
}
|
|
2383
2376
|
return;
|
|
2384
2377
|
}
|
|
2385
2378
|
if (part.type === "image_generation_call") {
|
|
2386
|
-
const toolName = imageGenerationToolName
|
|
2379
|
+
const toolName = imageGenerationToolName ?? "image_generation";
|
|
2387
2380
|
if (!seenToolCalls.has(part.id)) {
|
|
2388
2381
|
seenToolCalls.add(part.id);
|
|
2389
2382
|
controller.enqueue({
|
|
@@ -2443,17 +2436,17 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2443
2436
|
"x_semantic_search",
|
|
2444
2437
|
"x_thread_fetch"
|
|
2445
2438
|
];
|
|
2446
|
-
let toolName =
|
|
2447
|
-
if (webSearchSubTools.includes(
|
|
2448
|
-
toolName = webSearchToolName
|
|
2449
|
-
} else if (xSearchSubTools.includes(
|
|
2450
|
-
toolName = xSearchToolName
|
|
2439
|
+
let toolName = part.name ?? "";
|
|
2440
|
+
if (webSearchSubTools.includes(part.name ?? "") || part.type === "web_search_call") {
|
|
2441
|
+
toolName = webSearchToolName ?? "web_search";
|
|
2442
|
+
} else if (xSearchSubTools.includes(part.name ?? "") || part.type === "x_search_call") {
|
|
2443
|
+
toolName = xSearchToolName ?? "x_search";
|
|
2451
2444
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
2452
|
-
toolName = codeExecutionToolName
|
|
2445
|
+
toolName = codeExecutionToolName ?? "code_execution";
|
|
2453
2446
|
} else if (part.type === "mcp_call") {
|
|
2454
|
-
toolName =
|
|
2447
|
+
toolName = mcpToolName ?? part.name ?? "mcp";
|
|
2455
2448
|
}
|
|
2456
|
-
const toolInput = part.type === "custom_tool_call" ?
|
|
2449
|
+
const toolInput = part.type === "custom_tool_call" ? part.input ?? "" : part.type === "mcp_call" ? part.arguments ?? "" : part.arguments ?? "";
|
|
2457
2450
|
const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
|
|
2458
2451
|
if (shouldEmit && !seenToolCalls.has(part.id)) {
|
|
2459
2452
|
seenToolCalls.add(part.id);
|
|
@@ -2514,7 +2507,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2514
2507
|
sourceType: "url",
|
|
2515
2508
|
id: self.config.generateId(),
|
|
2516
2509
|
url: annotation.url,
|
|
2517
|
-
title:
|
|
2510
|
+
title: annotation.title ?? annotation.url
|
|
2518
2511
|
});
|
|
2519
2512
|
}
|
|
2520
2513
|
}
|
|
@@ -2560,7 +2553,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2560
2553
|
controller.enqueue({
|
|
2561
2554
|
type: "finish",
|
|
2562
2555
|
finishReason,
|
|
2563
|
-
usage: usage
|
|
2556
|
+
usage: usage ?? {
|
|
2564
2557
|
inputTokens: {
|
|
2565
2558
|
total: 0,
|
|
2566
2559
|
noCache: 0,
|
|
@@ -2589,11 +2582,10 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2589
2582
|
}
|
|
2590
2583
|
};
|
|
2591
2584
|
function mapWebSearchAction(action) {
|
|
2592
|
-
var _a;
|
|
2593
2585
|
const parsed = webSearchWireActionSchema.safeParse(action);
|
|
2594
2586
|
if (!parsed.success) return {};
|
|
2595
2587
|
const a = parsed.data;
|
|
2596
|
-
const sources =
|
|
2588
|
+
const sources = a.sources?.flatMap((s) => {
|
|
2597
2589
|
const source = webSearchWireSourceSchema.safeParse(s);
|
|
2598
2590
|
return source.success ? [source.data] : [];
|
|
2599
2591
|
});
|
|
@@ -2751,7 +2743,6 @@ var XaiBatch = class {
|
|
|
2751
2743
|
this.provider = options.provider;
|
|
2752
2744
|
}
|
|
2753
2745
|
async doStartBatch(options) {
|
|
2754
|
-
var _a, _b;
|
|
2755
2746
|
assertSupportedBatchRequests(options.requests);
|
|
2756
2747
|
const fileParts = [];
|
|
2757
2748
|
const warnings = options.webhookUrl == null ? [] : [
|
|
@@ -2787,7 +2778,7 @@ var XaiBatch = class {
|
|
|
2787
2778
|
const file = new Blob(fileParts, { type: "application/jsonl" });
|
|
2788
2779
|
fileParts.length = 0;
|
|
2789
2780
|
const formData = new FormData();
|
|
2790
|
-
if (
|
|
2781
|
+
if (batchOptions?.inputFileExpiresAfter != null) {
|
|
2791
2782
|
formData.append(
|
|
2792
2783
|
"expires_after",
|
|
2793
2784
|
String(batchOptions.inputFileExpiresAfter)
|
|
@@ -2795,7 +2786,7 @@ var XaiBatch = class {
|
|
|
2795
2786
|
}
|
|
2796
2787
|
formData.append("file", file, filename);
|
|
2797
2788
|
const headers = combineHeaders3(
|
|
2798
|
-
|
|
2789
|
+
this.options.config.headers?.(),
|
|
2799
2790
|
options.headers
|
|
2800
2791
|
);
|
|
2801
2792
|
const { value: uploadedFile } = await postFormDataToApi({
|
|
@@ -2843,12 +2834,11 @@ var XaiBatch = class {
|
|
|
2843
2834
|
return convertXaiBatchStatus(await this.retrieveBatch(options));
|
|
2844
2835
|
}
|
|
2845
2836
|
async doCancelBatch(options) {
|
|
2846
|
-
var _a, _b;
|
|
2847
2837
|
await postJsonToApi3({
|
|
2848
2838
|
url: this.getUrl(
|
|
2849
2839
|
`/batches/${encodeURIComponent(options.batchId)}:cancel`
|
|
2850
2840
|
),
|
|
2851
|
-
headers: combineHeaders3(
|
|
2841
|
+
headers: combineHeaders3(this.options.config.headers?.(), options.headers),
|
|
2852
2842
|
body: {},
|
|
2853
2843
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2854
2844
|
successfulResponseHandler: createJsonResponseHandler3(
|
|
@@ -2860,7 +2850,6 @@ var XaiBatch = class {
|
|
|
2860
2850
|
return {};
|
|
2861
2851
|
}
|
|
2862
2852
|
async doListBatches(options) {
|
|
2863
|
-
var _a, _b;
|
|
2864
2853
|
const url = new URL(this.getUrl("/batches"));
|
|
2865
2854
|
if (options.limit != null) {
|
|
2866
2855
|
url.searchParams.set("limit", String(options.limit));
|
|
@@ -2870,7 +2859,7 @@ var XaiBatch = class {
|
|
|
2870
2859
|
}
|
|
2871
2860
|
const { value: page } = await getFromApi2({
|
|
2872
2861
|
url: url.toString(),
|
|
2873
|
-
headers: combineHeaders3(
|
|
2862
|
+
headers: combineHeaders3(this.options.config.headers?.(), options.headers),
|
|
2874
2863
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2875
2864
|
successfulResponseHandler: createJsonResponseHandler3(
|
|
2876
2865
|
xaiBatchListResponseSchema
|
|
@@ -2900,10 +2889,9 @@ var XaiBatch = class {
|
|
|
2900
2889
|
);
|
|
2901
2890
|
}
|
|
2902
2891
|
async retrieveBatch(options) {
|
|
2903
|
-
var _a, _b;
|
|
2904
2892
|
const { value: batch } = await getFromApi2({
|
|
2905
2893
|
url: this.getUrl(`/batches/${encodeURIComponent(options.batchId)}`),
|
|
2906
|
-
headers: combineHeaders3(
|
|
2894
|
+
headers: combineHeaders3(this.options.config.headers?.(), options.headers),
|
|
2907
2895
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2908
2896
|
successfulResponseHandler: createJsonResponseHandler3(
|
|
2909
2897
|
xaiBatchResponseSchema
|
|
@@ -2915,7 +2903,6 @@ var XaiBatch = class {
|
|
|
2915
2903
|
return batch;
|
|
2916
2904
|
}
|
|
2917
2905
|
async *iterateBatchResults(options) {
|
|
2918
|
-
var _a, _b, _c;
|
|
2919
2906
|
let paginationToken;
|
|
2920
2907
|
do {
|
|
2921
2908
|
const query = new URLSearchParams({
|
|
@@ -2929,7 +2916,7 @@ var XaiBatch = class {
|
|
|
2929
2916
|
`/batches/${encodeURIComponent(options.batchId)}/results?${query}`
|
|
2930
2917
|
),
|
|
2931
2918
|
headers: combineHeaders3(
|
|
2932
|
-
|
|
2919
|
+
this.options.config.headers?.(),
|
|
2933
2920
|
options.headers
|
|
2934
2921
|
),
|
|
2935
2922
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
@@ -2943,23 +2930,22 @@ var XaiBatch = class {
|
|
|
2943
2930
|
for (const result of page.results) {
|
|
2944
2931
|
yield await this.convertBatchResult(result, options.abortSignal);
|
|
2945
2932
|
}
|
|
2946
|
-
paginationToken =
|
|
2933
|
+
paginationToken = page.pagination_token ?? void 0;
|
|
2947
2934
|
} while (paginationToken != null);
|
|
2948
2935
|
}
|
|
2949
2936
|
async convertBatchResult(result, abortSignal) {
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
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) {
|
|
2937
|
+
const error = result.batch_result?.error;
|
|
2938
|
+
if ((result.error_message?.length ?? 0) > 0 || error?.code != null && error.code !== 0 && error.code !== "0" || error?.code == null && (error?.message?.length ?? 0) > 0) {
|
|
2953
2939
|
const convertedError = convertXaiBatchError(result);
|
|
2954
2940
|
return {
|
|
2955
2941
|
type: "text",
|
|
2956
2942
|
id: result.batch_request_id,
|
|
2957
|
-
status: isXaiCancellationError(error
|
|
2943
|
+
status: isXaiCancellationError(error?.code) ? "cancelled" : "failed",
|
|
2958
2944
|
error: convertedError
|
|
2959
2945
|
};
|
|
2960
2946
|
}
|
|
2961
|
-
const response =
|
|
2962
|
-
if (
|
|
2947
|
+
const response = result.batch_result?.response;
|
|
2948
|
+
if (response?.chat_get_completion != null) {
|
|
2963
2949
|
const validation = await safeValidateTypes({
|
|
2964
2950
|
value: response.chat_get_completion,
|
|
2965
2951
|
schema: zodSchema7(xaiBatchTextResponseSchema)
|
|
@@ -2980,7 +2966,7 @@ var XaiBatch = class {
|
|
|
2980
2966
|
error: conversion.error
|
|
2981
2967
|
};
|
|
2982
2968
|
}
|
|
2983
|
-
if (
|
|
2969
|
+
if (response?.image_generation != null) {
|
|
2984
2970
|
const validation = await safeValidateTypes({
|
|
2985
2971
|
value: response.image_generation,
|
|
2986
2972
|
schema: zodSchema7(xaiBatchImageResponseSchema)
|
|
@@ -3035,7 +3021,7 @@ var XaiBatch = class {
|
|
|
3035
3021
|
providerOptions,
|
|
3036
3022
|
schema: xaiImageModelOptions
|
|
3037
3023
|
});
|
|
3038
|
-
const imageUrls = (files
|
|
3024
|
+
const imageUrls = (files ?? []).map(convertImageModelFileToDataUri2);
|
|
3039
3025
|
const body = {
|
|
3040
3026
|
model: request.modelId,
|
|
3041
3027
|
prompt,
|
|
@@ -3043,27 +3029,26 @@ var XaiBatch = class {
|
|
|
3043
3029
|
response_format: "b64_json"
|
|
3044
3030
|
};
|
|
3045
3031
|
if (aspectRatio != null) body.aspect_ratio = aspectRatio;
|
|
3046
|
-
if (
|
|
3032
|
+
if (xaiOptions?.output_format != null)
|
|
3047
3033
|
body.output_format = xaiOptions.output_format;
|
|
3048
|
-
if (
|
|
3049
|
-
if (
|
|
3034
|
+
if (xaiOptions?.sync_mode != null) body.sync_mode = xaiOptions.sync_mode;
|
|
3035
|
+
if (xaiOptions?.aspect_ratio != null && aspectRatio == null)
|
|
3050
3036
|
body.aspect_ratio = xaiOptions.aspect_ratio;
|
|
3051
|
-
if (
|
|
3052
|
-
if (
|
|
3053
|
-
if (
|
|
3037
|
+
if (xaiOptions?.resolution != null) body.resolution = xaiOptions.resolution;
|
|
3038
|
+
if (xaiOptions?.quality != null) body.quality = xaiOptions.quality;
|
|
3039
|
+
if (xaiOptions?.user != null) body.user = xaiOptions.user;
|
|
3054
3040
|
if (imageUrls.length === 1) {
|
|
3055
3041
|
body.image = { url: imageUrls[0], type: "image_url" };
|
|
3056
3042
|
} else if (imageUrls.length > 1) {
|
|
3057
3043
|
body.images = imageUrls.map((url) => ({ url, type: "image_url" }));
|
|
3058
3044
|
}
|
|
3059
3045
|
return {
|
|
3060
|
-
endpoint:
|
|
3046
|
+
endpoint: files?.length ? "/v1/images/edits" : "/v1/images/generations",
|
|
3061
3047
|
body,
|
|
3062
3048
|
warnings
|
|
3063
3049
|
};
|
|
3064
3050
|
}
|
|
3065
3051
|
async convertImageBatchResponse(response, abortSignal) {
|
|
3066
|
-
var _a;
|
|
3067
3052
|
const hasAllBase64 = response.data.every((image) => image.b64_json != null);
|
|
3068
3053
|
const images = hasAllBase64 ? response.data.map((image) => image.b64_json) : await Promise.all(
|
|
3069
3054
|
response.data.map(async (image) => {
|
|
@@ -3097,23 +3082,21 @@ var XaiBatch = class {
|
|
|
3097
3082
|
images: response.data.map(
|
|
3098
3083
|
(item) => item.revised_prompt != null ? { revisedPrompt: item.revised_prompt } : {}
|
|
3099
3084
|
),
|
|
3100
|
-
...
|
|
3085
|
+
...response.usage?.cost_in_usd_ticks != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {}
|
|
3101
3086
|
}
|
|
3102
3087
|
}
|
|
3103
3088
|
};
|
|
3104
3089
|
}
|
|
3105
3090
|
getUrl(path) {
|
|
3106
|
-
|
|
3107
|
-
return `${(_a = this.options.config.baseURL) != null ? _a : "https://api.x.ai/v1"}${path}`;
|
|
3091
|
+
return `${this.options.config.baseURL ?? "https://api.x.ai/v1"}${path}`;
|
|
3108
3092
|
}
|
|
3109
3093
|
};
|
|
3110
3094
|
function convertXaiBatchStatus(batch) {
|
|
3111
|
-
var _a, _b, _c, _d, _e, _f;
|
|
3112
3095
|
const requestCounts = normalizeBatchRequestCounts({
|
|
3113
|
-
total:
|
|
3114
|
-
pending:
|
|
3115
|
-
completed:
|
|
3116
|
-
failed:
|
|
3096
|
+
total: batch.state?.num_requests,
|
|
3097
|
+
pending: batch.state?.num_pending,
|
|
3098
|
+
completed: batch.state?.num_success,
|
|
3099
|
+
failed: batch.state?.num_error != null && batch.state?.num_cancelled != null ? batch.state.num_error + batch.state.num_cancelled : void 0
|
|
3117
3100
|
});
|
|
3118
3101
|
const isCancelled = batch.cancel_time != null || batch.cancel_by_xai_message != null;
|
|
3119
3102
|
const isExpired = isPastDate(batch.expire_time);
|
|
@@ -3123,7 +3106,7 @@ function convertXaiBatchStatus(batch) {
|
|
|
3123
3106
|
...requestCounts != null ? { requestCounts } : {},
|
|
3124
3107
|
...isCancelled ? {
|
|
3125
3108
|
error: {
|
|
3126
|
-
message:
|
|
3109
|
+
message: batch.cancel_by_xai_message ?? `xAI batch "${batch.batch_id}" was cancelled.`,
|
|
3127
3110
|
code: "batch_cancelled"
|
|
3128
3111
|
}
|
|
3129
3112
|
} : isExpired ? {
|
|
@@ -3144,11 +3127,10 @@ function isPastDate(value) {
|
|
|
3144
3127
|
return !Number.isNaN(timestamp) && timestamp <= Date.now();
|
|
3145
3128
|
}
|
|
3146
3129
|
function convertXaiBatchError(result) {
|
|
3147
|
-
|
|
3148
|
-
const error = (_a = result.batch_result) == null ? void 0 : _a.error;
|
|
3130
|
+
const error = result.batch_result?.error;
|
|
3149
3131
|
return {
|
|
3150
|
-
message: result.error_message ||
|
|
3151
|
-
...
|
|
3132
|
+
message: result.error_message || error?.message || "xAI batch request failed.",
|
|
3133
|
+
...error?.code != null && error.code !== 0 && error.code !== "0" ? { code: String(error.code) } : {}
|
|
3152
3134
|
};
|
|
3153
3135
|
}
|
|
3154
3136
|
function isXaiCancellationError(code) {
|
|
@@ -3178,7 +3160,6 @@ function invalidXaiImageBatchResult(id) {
|
|
|
3178
3160
|
};
|
|
3179
3161
|
}
|
|
3180
3162
|
function convertXaiBatchTextResponse(response) {
|
|
3181
|
-
var _a, _b, _c, _d, _e, _f;
|
|
3182
3163
|
if (response.error != null) {
|
|
3183
3164
|
return {
|
|
3184
3165
|
success: false,
|
|
@@ -3201,17 +3182,14 @@ function convertXaiBatchTextResponse(response) {
|
|
|
3201
3182
|
const content = [];
|
|
3202
3183
|
const providerExecutedToolCallIds = new Set(
|
|
3203
3184
|
choices.filter((choice) => choice.message.role === "tool").flatMap(
|
|
3204
|
-
(choice) =>
|
|
3205
|
-
var _a2;
|
|
3206
|
-
return ((_a2 = choice.message.tool_calls) != null ? _a2 : []).map((toolCall) => toolCall.id);
|
|
3207
|
-
}
|
|
3185
|
+
(choice) => (choice.message.tool_calls ?? []).map((toolCall) => toolCall.id)
|
|
3208
3186
|
)
|
|
3209
3187
|
);
|
|
3210
3188
|
let lastAssistantChoice;
|
|
3211
3189
|
for (const choice of choices) {
|
|
3212
3190
|
if (choice.message.role === "tool") {
|
|
3213
3191
|
if (choice.message.content != null) {
|
|
3214
|
-
for (const toolCall of
|
|
3192
|
+
for (const toolCall of choice.message.tool_calls ?? []) {
|
|
3215
3193
|
content.push({
|
|
3216
3194
|
type: "tool-result",
|
|
3217
3195
|
toolCallId: toolCall.id,
|
|
@@ -3233,7 +3211,7 @@ function convertXaiBatchTextResponse(response) {
|
|
|
3233
3211
|
text: choice.message.reasoning_content
|
|
3234
3212
|
});
|
|
3235
3213
|
}
|
|
3236
|
-
for (const toolCall of
|
|
3214
|
+
for (const toolCall of choice.message.tool_calls ?? []) {
|
|
3237
3215
|
content.push({
|
|
3238
3216
|
type: "tool-call",
|
|
3239
3217
|
toolCallId: toolCall.id,
|
|
@@ -3243,7 +3221,7 @@ function convertXaiBatchTextResponse(response) {
|
|
|
3243
3221
|
});
|
|
3244
3222
|
}
|
|
3245
3223
|
}
|
|
3246
|
-
for (const url of
|
|
3224
|
+
for (const url of response.citations ?? []) {
|
|
3247
3225
|
content.push({
|
|
3248
3226
|
type: "source",
|
|
3249
3227
|
sourceType: "url",
|
|
@@ -3256,16 +3234,16 @@ function convertXaiBatchTextResponse(response) {
|
|
|
3256
3234
|
result: {
|
|
3257
3235
|
content,
|
|
3258
3236
|
finishReason: {
|
|
3259
|
-
unified: mapXaiFinishReason(lastAssistantChoice
|
|
3260
|
-
raw:
|
|
3237
|
+
unified: mapXaiFinishReason(lastAssistantChoice?.finish_reason),
|
|
3238
|
+
raw: lastAssistantChoice?.finish_reason ?? void 0
|
|
3261
3239
|
},
|
|
3262
3240
|
usage: response.usage ? convertXaiBatchTextUsage(response.usage) : createNullLanguageModelUsage(),
|
|
3263
3241
|
response: getResponseMetadata(response),
|
|
3264
3242
|
warnings: [],
|
|
3265
|
-
...(
|
|
3243
|
+
...(response.usage?.cost_in_usd_ticks != null || response.service_tier != null) && {
|
|
3266
3244
|
providerMetadata: {
|
|
3267
3245
|
xai: {
|
|
3268
|
-
...
|
|
3246
|
+
...response.usage?.cost_in_usd_ticks != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {},
|
|
3269
3247
|
...response.service_tier != null ? { serviceTier: response.service_tier } : {}
|
|
3270
3248
|
}
|
|
3271
3249
|
}
|
|
@@ -3274,9 +3252,8 @@ function convertXaiBatchTextResponse(response) {
|
|
|
3274
3252
|
};
|
|
3275
3253
|
}
|
|
3276
3254
|
function convertXaiBatchTextUsage(usage) {
|
|
3277
|
-
|
|
3278
|
-
const
|
|
3279
|
-
const reasoningTokens = (_d = (_c = usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0;
|
|
3255
|
+
const cacheReadTokens = usage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
3256
|
+
const reasoningTokens = usage.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
3280
3257
|
const promptTokensIncludesCached = cacheReadTokens <= usage.prompt_tokens;
|
|
3281
3258
|
return {
|
|
3282
3259
|
inputTokens: {
|
|
@@ -3296,14 +3273,13 @@ function convertXaiBatchTextUsage(usage) {
|
|
|
3296
3273
|
|
|
3297
3274
|
// src/realtime/xai-realtime-event-mapper.ts
|
|
3298
3275
|
function parseXaiRealtimeServerEvent(raw) {
|
|
3299
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
3300
3276
|
const event = raw;
|
|
3301
3277
|
const type = event.type;
|
|
3302
3278
|
switch (type) {
|
|
3303
3279
|
case "session.created":
|
|
3304
3280
|
return {
|
|
3305
3281
|
type: "session-created",
|
|
3306
|
-
sessionId:
|
|
3282
|
+
sessionId: event.session?.id,
|
|
3307
3283
|
raw
|
|
3308
3284
|
};
|
|
3309
3285
|
case "session.updated":
|
|
@@ -3332,7 +3308,7 @@ function parseXaiRealtimeServerEvent(raw) {
|
|
|
3332
3308
|
case "conversation.item.added":
|
|
3333
3309
|
return {
|
|
3334
3310
|
type: "conversation-item-added",
|
|
3335
|
-
itemId:
|
|
3311
|
+
itemId: event.item?.id ?? event.item_id,
|
|
3336
3312
|
item: event.item,
|
|
3337
3313
|
raw
|
|
3338
3314
|
};
|
|
@@ -3340,34 +3316,34 @@ function parseXaiRealtimeServerEvent(raw) {
|
|
|
3340
3316
|
return {
|
|
3341
3317
|
type: "input-transcription-completed",
|
|
3342
3318
|
itemId: event.item_id,
|
|
3343
|
-
transcript:
|
|
3319
|
+
transcript: event.transcript ?? "",
|
|
3344
3320
|
raw
|
|
3345
3321
|
};
|
|
3346
3322
|
case "response.created":
|
|
3347
3323
|
return {
|
|
3348
3324
|
type: "response-created",
|
|
3349
|
-
responseId:
|
|
3325
|
+
responseId: event.response?.id ?? event.response_id,
|
|
3350
3326
|
raw
|
|
3351
3327
|
};
|
|
3352
3328
|
case "response.done":
|
|
3353
3329
|
return {
|
|
3354
3330
|
type: "response-done",
|
|
3355
|
-
responseId:
|
|
3356
|
-
status:
|
|
3331
|
+
responseId: event.response?.id ?? event.response_id,
|
|
3332
|
+
status: event.response?.status ?? "completed",
|
|
3357
3333
|
raw
|
|
3358
3334
|
};
|
|
3359
3335
|
case "response.output_item.added":
|
|
3360
3336
|
return {
|
|
3361
3337
|
type: "output-item-added",
|
|
3362
3338
|
responseId: event.response_id,
|
|
3363
|
-
itemId:
|
|
3339
|
+
itemId: event.item?.id ?? event.item_id,
|
|
3364
3340
|
raw
|
|
3365
3341
|
};
|
|
3366
3342
|
case "response.output_item.done":
|
|
3367
3343
|
return {
|
|
3368
3344
|
type: "output-item-done",
|
|
3369
3345
|
responseId: event.response_id,
|
|
3370
|
-
itemId:
|
|
3346
|
+
itemId: event.item?.id ?? event.item_id,
|
|
3371
3347
|
raw
|
|
3372
3348
|
};
|
|
3373
3349
|
case "response.content_part.added":
|
|
@@ -3462,8 +3438,8 @@ function parseXaiRealtimeServerEvent(raw) {
|
|
|
3462
3438
|
case "error":
|
|
3463
3439
|
return {
|
|
3464
3440
|
type: "error",
|
|
3465
|
-
message:
|
|
3466
|
-
code:
|
|
3441
|
+
message: event.error?.message ?? event.message ?? "Unknown error",
|
|
3442
|
+
code: event.error?.code ?? event.code,
|
|
3467
3443
|
raw
|
|
3468
3444
|
};
|
|
3469
3445
|
default:
|
|
@@ -3536,7 +3512,6 @@ function serializeXaiRealtimeClientEvent(event) {
|
|
|
3536
3512
|
}
|
|
3537
3513
|
}
|
|
3538
3514
|
function buildXaiSessionConfig(config) {
|
|
3539
|
-
var _a;
|
|
3540
3515
|
const session = {};
|
|
3541
3516
|
if (config.instructions != null) {
|
|
3542
3517
|
session.instructions = config.instructions;
|
|
@@ -3594,7 +3569,7 @@ function buildXaiSessionConfig(config) {
|
|
|
3594
3569
|
if (config.providerOptions != null) {
|
|
3595
3570
|
const xaiOptions = config.providerOptions;
|
|
3596
3571
|
if (Array.isArray(xaiOptions.tools)) {
|
|
3597
|
-
const existingTools =
|
|
3572
|
+
const existingTools = session.tools ?? [];
|
|
3598
3573
|
session.tools = [...existingTools, ...xaiOptions.tools];
|
|
3599
3574
|
}
|
|
3600
3575
|
for (const [key, value] of Object.entries(xaiOptions)) {
|
|
@@ -3615,8 +3590,7 @@ var XaiRealtimeModel = class {
|
|
|
3615
3590
|
this.config = config;
|
|
3616
3591
|
}
|
|
3617
3592
|
async doCreateClientSecret(options) {
|
|
3618
|
-
|
|
3619
|
-
const fetchFn = (_a = this.config.fetch) != null ? _a : fetch;
|
|
3593
|
+
const fetchFn = this.config.fetch ?? fetch;
|
|
3620
3594
|
const url = `${this.config.baseURL}/realtime/client_secrets`;
|
|
3621
3595
|
const body = {};
|
|
3622
3596
|
if (options.expiresAfterSeconds != null) {
|
|
@@ -3719,7 +3693,7 @@ var xaiTools = {
|
|
|
3719
3693
|
};
|
|
3720
3694
|
|
|
3721
3695
|
// src/version.ts
|
|
3722
|
-
var VERSION = true ? "5.0.
|
|
3696
|
+
var VERSION = true ? "5.0.10" : "0.0.0-test";
|
|
3723
3697
|
|
|
3724
3698
|
// src/files/xai-files.ts
|
|
3725
3699
|
import {
|
|
@@ -3792,7 +3766,6 @@ var XaiFiles = class {
|
|
|
3792
3766
|
headers,
|
|
3793
3767
|
providerOptions
|
|
3794
3768
|
}) {
|
|
3795
|
-
var _a, _b;
|
|
3796
3769
|
let xaiOptions;
|
|
3797
3770
|
try {
|
|
3798
3771
|
xaiOptions = await parseProviderOptions5({
|
|
@@ -3812,14 +3785,14 @@ var XaiFiles = class {
|
|
|
3812
3785
|
let response;
|
|
3813
3786
|
if (data.type === "stream") {
|
|
3814
3787
|
const parts = [];
|
|
3815
|
-
if (
|
|
3788
|
+
if (xaiOptions?.expiresAfter != null) {
|
|
3816
3789
|
parts.push({
|
|
3817
3790
|
type: "field",
|
|
3818
3791
|
name: "expires_after",
|
|
3819
3792
|
value: String(xaiOptions.expiresAfter)
|
|
3820
3793
|
});
|
|
3821
3794
|
}
|
|
3822
|
-
if (
|
|
3795
|
+
if (xaiOptions?.teamId != null) {
|
|
3823
3796
|
parts.push({
|
|
3824
3797
|
type: "field",
|
|
3825
3798
|
name: "team_id",
|
|
@@ -3850,10 +3823,10 @@ var XaiFiles = class {
|
|
|
3850
3823
|
type: mediaType
|
|
3851
3824
|
});
|
|
3852
3825
|
const formData = new FormData();
|
|
3853
|
-
if (
|
|
3826
|
+
if (xaiOptions?.expiresAfter != null) {
|
|
3854
3827
|
formData.append("expires_after", String(xaiOptions.expiresAfter));
|
|
3855
3828
|
}
|
|
3856
|
-
if (
|
|
3829
|
+
if (xaiOptions?.teamId != null) {
|
|
3857
3830
|
formData.append("team_id", xaiOptions.teamId);
|
|
3858
3831
|
}
|
|
3859
3832
|
if (filename != null) {
|
|
@@ -3876,7 +3849,7 @@ var XaiFiles = class {
|
|
|
3876
3849
|
return {
|
|
3877
3850
|
warnings: [],
|
|
3878
3851
|
providerReference: { xai: response.id },
|
|
3879
|
-
...
|
|
3852
|
+
...response.filename ?? filename ? { filename: response.filename ?? filename } : {},
|
|
3880
3853
|
...mediaType != null ? { mediaType } : {},
|
|
3881
3854
|
...response.bytes != null ? { byteSize: response.bytes } : {},
|
|
3882
3855
|
...response.created_at != null ? { createdAt: new Date(response.created_at * 1e3) } : {},
|
|
@@ -3920,7 +3893,6 @@ var XaiFiles = class {
|
|
|
3920
3893
|
abortSignal,
|
|
3921
3894
|
headers
|
|
3922
3895
|
}) {
|
|
3923
|
-
var _a;
|
|
3924
3896
|
const fileId = this.getFileId(file);
|
|
3925
3897
|
const { value: content, responseHeaders } = await getFromApi3({
|
|
3926
3898
|
url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}/content`,
|
|
@@ -3931,7 +3903,7 @@ var XaiFiles = class {
|
|
|
3931
3903
|
fetch: this.config.fetch,
|
|
3932
3904
|
validateUrl: false
|
|
3933
3905
|
});
|
|
3934
|
-
const mediaType =
|
|
3906
|
+
const mediaType = responseHeaders?.["content-type"]?.split(";")[0].trim();
|
|
3935
3907
|
return {
|
|
3936
3908
|
warnings: [],
|
|
3937
3909
|
content,
|
|
@@ -4041,16 +4013,13 @@ var RESOLUTION_MAP = {
|
|
|
4041
4013
|
"640x480": "480p"
|
|
4042
4014
|
};
|
|
4043
4015
|
function getFirstFrameImage(options) {
|
|
4044
|
-
|
|
4045
|
-
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
4016
|
+
return options.frameImages?.find((frame) => frame.frameType === "first_frame")?.image;
|
|
4046
4017
|
}
|
|
4047
4018
|
function getLastFrameImage(options) {
|
|
4048
|
-
|
|
4049
|
-
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
|
|
4019
|
+
return options.frameImages?.find((frame) => frame.frameType === "last_frame")?.image;
|
|
4050
4020
|
}
|
|
4051
4021
|
function resolveStartImage(options) {
|
|
4052
|
-
|
|
4053
|
-
return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
|
|
4022
|
+
return getFirstFrameImage(options) ?? options.image;
|
|
4054
4023
|
}
|
|
4055
4024
|
var isVideoFile = (file) => file.mediaType != null && getTopLevelMediaType2(file.mediaType) === "video";
|
|
4056
4025
|
var isImageReference = (file) => file.mediaType == null || getTopLevelMediaType2(file.mediaType) === "image";
|
|
@@ -4081,31 +4050,28 @@ function resolveReferences(options, xaiOptions, warnings) {
|
|
|
4081
4050
|
}
|
|
4082
4051
|
return imageFiles.length > 0 ? imageFiles.map((reference) => ({ url: fileToXaiUrl(reference) })) : void 0;
|
|
4083
4052
|
}
|
|
4084
|
-
if (
|
|
4053
|
+
if (xaiOptions?.referenceImageUrls != null && xaiOptions.referenceImageUrls.length > 0) {
|
|
4085
4054
|
return xaiOptions.referenceImageUrls.map((url) => ({ url }));
|
|
4086
4055
|
}
|
|
4087
4056
|
}
|
|
4088
4057
|
function resolveReferenceAudios(options) {
|
|
4089
|
-
|
|
4090
|
-
const audioReferences = (_a = options.inputReferences) == null ? void 0 : _a.filter(isAudioReference);
|
|
4058
|
+
const audioReferences = options.inputReferences?.filter(isAudioReference);
|
|
4091
4059
|
return audioReferences != null && audioReferences.length > 0 ? audioReferences.map((reference) => ({ url: fileToXaiUrl(reference) })) : void 0;
|
|
4092
4060
|
}
|
|
4093
4061
|
function hasImageInputReference(options) {
|
|
4094
|
-
|
|
4095
|
-
return (_b = (_a = options.inputReferences) == null ? void 0 : _a.some(isImageReference)) != null ? _b : false;
|
|
4062
|
+
return options.inputReferences?.some(isImageReference) ?? false;
|
|
4096
4063
|
}
|
|
4097
4064
|
function hasAudioInputReference(options) {
|
|
4098
|
-
|
|
4099
|
-
return (_b = (_a = options.inputReferences) == null ? void 0 : _a.some(isAudioReference)) != null ? _b : false;
|
|
4065
|
+
return options.inputReferences?.some(isAudioReference) ?? false;
|
|
4100
4066
|
}
|
|
4101
4067
|
function resolveVideoMode(options, xaiOptions) {
|
|
4102
|
-
if (
|
|
4068
|
+
if (xaiOptions?.mode != null) {
|
|
4103
4069
|
return xaiOptions.mode;
|
|
4104
4070
|
}
|
|
4105
|
-
if (
|
|
4071
|
+
if (xaiOptions?.videoUrl != null) {
|
|
4106
4072
|
return "edit-video";
|
|
4107
4073
|
}
|
|
4108
|
-
const hasLegacyReferenceUrls =
|
|
4074
|
+
const hasLegacyReferenceUrls = xaiOptions?.referenceImageUrls != null && xaiOptions.referenceImageUrls.length > 0;
|
|
4109
4075
|
if (hasImageInputReference(options) || hasAudioInputReference(options) || hasLegacyReferenceUrls) {
|
|
4110
4076
|
return "reference-to-video";
|
|
4111
4077
|
}
|
|
@@ -4166,7 +4132,7 @@ var XaiVideoModel = class {
|
|
|
4166
4132
|
details: "xAI video editing does not support custom aspect ratio."
|
|
4167
4133
|
});
|
|
4168
4134
|
}
|
|
4169
|
-
if (isEdit && (
|
|
4135
|
+
if (isEdit && (xaiOptions?.resolution != null || options.resolution != null)) {
|
|
4170
4136
|
warnings.push({
|
|
4171
4137
|
type: "unsupported",
|
|
4172
4138
|
feature: "resolution",
|
|
@@ -4180,7 +4146,7 @@ var XaiVideoModel = class {
|
|
|
4180
4146
|
details: "xAI video extension does not support custom aspect ratio."
|
|
4181
4147
|
});
|
|
4182
4148
|
}
|
|
4183
|
-
if (isExtension && (
|
|
4149
|
+
if (isExtension && (xaiOptions?.resolution != null || options.resolution != null)) {
|
|
4184
4150
|
warnings.push({
|
|
4185
4151
|
type: "unsupported",
|
|
4186
4152
|
feature: "resolution",
|
|
@@ -4200,7 +4166,7 @@ var XaiVideoModel = class {
|
|
|
4200
4166
|
if (allowAspectRatio && options.aspectRatio != null) {
|
|
4201
4167
|
body.aspect_ratio = options.aspectRatio;
|
|
4202
4168
|
}
|
|
4203
|
-
if (allowResolution &&
|
|
4169
|
+
if (allowResolution && xaiOptions?.resolution != null) {
|
|
4204
4170
|
body.resolution = xaiOptions.resolution;
|
|
4205
4171
|
} else if (allowResolution && options.resolution != null) {
|
|
4206
4172
|
const mapped = RESOLUTION_MAP[options.resolution];
|
|
@@ -4223,7 +4189,7 @@ var XaiVideoModel = class {
|
|
|
4223
4189
|
details: `xAI ${isEdit ? "video editing" : "video extension"} does not support generateAudio.`
|
|
4224
4190
|
});
|
|
4225
4191
|
}
|
|
4226
|
-
if (
|
|
4192
|
+
if (xaiOptions?.storageOptions != null) {
|
|
4227
4193
|
const { filename, expiresAfter, publicUrl } = xaiOptions.storageOptions;
|
|
4228
4194
|
body.storage_options = {
|
|
4229
4195
|
filename,
|
|
@@ -4235,7 +4201,7 @@ var XaiVideoModel = class {
|
|
|
4235
4201
|
} : {}
|
|
4236
4202
|
};
|
|
4237
4203
|
}
|
|
4238
|
-
if (
|
|
4204
|
+
if (xaiOptions?.keyframes != null && xaiOptions.keyframes.length > 0) {
|
|
4239
4205
|
if (this.modelId !== "grok-imagine-video-1.5" || isEdit || isExtension) {
|
|
4240
4206
|
warnings.push({
|
|
4241
4207
|
type: "unsupported",
|
|
@@ -4292,13 +4258,13 @@ var XaiVideoModel = class {
|
|
|
4292
4258
|
details: "xAI reference-to-video requires at least one image reference. The video will be generated without reference images."
|
|
4293
4259
|
});
|
|
4294
4260
|
}
|
|
4295
|
-
const referenceVoiceIds = xaiOptions
|
|
4296
|
-
const referenceVoices = referenceVoiceIds
|
|
4261
|
+
const referenceVoiceIds = xaiOptions?.referenceVoiceIds;
|
|
4262
|
+
const referenceVoices = referenceVoiceIds?.map((voiceId) => ({
|
|
4297
4263
|
voice_id: voiceId
|
|
4298
4264
|
}));
|
|
4299
4265
|
const referenceAudioInputs = [
|
|
4300
|
-
...referenceAudios
|
|
4301
|
-
...referenceVoices
|
|
4266
|
+
...referenceAudios ?? [],
|
|
4267
|
+
...referenceVoices ?? []
|
|
4302
4268
|
];
|
|
4303
4269
|
if (referenceAudioInputs.length > 0) {
|
|
4304
4270
|
if (referenceAudioInputs.length > 3) {
|
|
@@ -4333,14 +4299,14 @@ var XaiVideoModel = class {
|
|
|
4333
4299
|
details: hasImageInputReference(options) || hasAudioInputReference(options) ? "xAI only supports inputReferences for reference-to-video generation. The references were ignored." : "xAI reference-to-video requires at least one image or audio reference. The references were ignored."
|
|
4334
4300
|
});
|
|
4335
4301
|
}
|
|
4336
|
-
if (
|
|
4302
|
+
if (xaiOptions?.referenceVoiceIds != null && xaiOptions.referenceVoiceIds.length > 0 && !hasReferenceImages) {
|
|
4337
4303
|
warnings.push({
|
|
4338
4304
|
type: "unsupported",
|
|
4339
4305
|
feature: "referenceVoiceIds",
|
|
4340
4306
|
details: "xAI only supports reference voices for reference-to-video generation. The reference voices were ignored."
|
|
4341
4307
|
});
|
|
4342
4308
|
}
|
|
4343
|
-
if (!isExtension &&
|
|
4309
|
+
if (!isExtension && xaiOptions?.user !== void 0) {
|
|
4344
4310
|
body.user = xaiOptions.user;
|
|
4345
4311
|
}
|
|
4346
4312
|
if (xaiOptions != null) {
|
|
@@ -4372,10 +4338,9 @@ var XaiVideoModel = class {
|
|
|
4372
4338
|
};
|
|
4373
4339
|
}
|
|
4374
4340
|
async doStart(options) {
|
|
4375
|
-
|
|
4376
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4341
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4377
4342
|
const { body, warnings, isEdit, isExtension } = await this.buildRequestBody(options);
|
|
4378
|
-
const baseURL =
|
|
4343
|
+
const baseURL = this.config.baseURL ?? "https://api.x.ai/v1";
|
|
4379
4344
|
let endpoint;
|
|
4380
4345
|
if (isEdit) {
|
|
4381
4346
|
endpoint = `${baseURL}/videos/edits`;
|
|
@@ -4413,10 +4378,9 @@ var XaiVideoModel = class {
|
|
|
4413
4378
|
};
|
|
4414
4379
|
}
|
|
4415
4380
|
async doStatus(options) {
|
|
4416
|
-
|
|
4417
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4381
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4418
4382
|
const { requestId } = options.operation;
|
|
4419
|
-
const baseURL =
|
|
4383
|
+
const baseURL = this.config.baseURL ?? "https://api.x.ai/v1";
|
|
4420
4384
|
const { value: statusResponse, responseHeaders } = await getFromApi4({
|
|
4421
4385
|
url: `${baseURL}/videos/${encodePathSegment2(requestId)}`,
|
|
4422
4386
|
validateUrl: false,
|
|
@@ -4438,7 +4402,7 @@ var XaiVideoModel = class {
|
|
|
4438
4402
|
};
|
|
4439
4403
|
}
|
|
4440
4404
|
if (statusResponse.status === "failed") {
|
|
4441
|
-
const errorDetails =
|
|
4405
|
+
const errorDetails = statusResponse.error?.message ?? statusResponse.error?.code;
|
|
4442
4406
|
return {
|
|
4443
4407
|
status: "error",
|
|
4444
4408
|
error: errorDetails != null ? `Video generation failed: ${errorDetails}` : "Video generation failed.",
|
|
@@ -4449,9 +4413,9 @@ var XaiVideoModel = class {
|
|
|
4449
4413
|
}
|
|
4450
4414
|
};
|
|
4451
4415
|
}
|
|
4452
|
-
if (statusResponse.status === "done" || statusResponse.status == null &&
|
|
4416
|
+
if (statusResponse.status === "done" || statusResponse.status == null && statusResponse.video?.url) {
|
|
4453
4417
|
const video = statusResponse.video;
|
|
4454
|
-
if (
|
|
4418
|
+
if (video?.respect_moderation === false) {
|
|
4455
4419
|
return {
|
|
4456
4420
|
status: "error",
|
|
4457
4421
|
error: "Video generation was blocked due to a content policy violation.",
|
|
@@ -4462,7 +4426,7 @@ var XaiVideoModel = class {
|
|
|
4462
4426
|
}
|
|
4463
4427
|
};
|
|
4464
4428
|
}
|
|
4465
|
-
const videoUrl =
|
|
4429
|
+
const videoUrl = video?.url ?? video?.file_output?.public_url ?? void 0;
|
|
4466
4430
|
if (!videoUrl) {
|
|
4467
4431
|
return {
|
|
4468
4432
|
status: "error",
|
|
@@ -4487,10 +4451,10 @@ var XaiVideoModel = class {
|
|
|
4487
4451
|
xai: {
|
|
4488
4452
|
requestId,
|
|
4489
4453
|
videoUrl,
|
|
4490
|
-
...
|
|
4491
|
-
...
|
|
4454
|
+
...video?.duration != null ? { duration: video.duration } : {},
|
|
4455
|
+
...statusResponse.usage?.cost_in_usd_ticks != null ? { costInUsdTicks: statusResponse.usage.cost_in_usd_ticks } : {},
|
|
4492
4456
|
...statusResponse.progress != null ? { progress: statusResponse.progress } : {},
|
|
4493
|
-
...
|
|
4457
|
+
...video?.file_output != null ? {
|
|
4494
4458
|
fileOutput: {
|
|
4495
4459
|
fileId: video.file_output.file_id,
|
|
4496
4460
|
filename: video.file_output.filename,
|
|
@@ -4508,7 +4472,7 @@ var XaiVideoModel = class {
|
|
|
4508
4472
|
} : {}
|
|
4509
4473
|
}
|
|
4510
4474
|
} : {},
|
|
4511
|
-
...
|
|
4475
|
+
...video?.storage_error != null ? { storageError: video.storage_error } : {}
|
|
4512
4476
|
}
|
|
4513
4477
|
}
|
|
4514
4478
|
};
|
|
@@ -4737,10 +4701,10 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
4737
4701
|
const output_format = {
|
|
4738
4702
|
codec
|
|
4739
4703
|
};
|
|
4740
|
-
if (
|
|
4704
|
+
if (xaiOptions?.sampleRate != null) {
|
|
4741
4705
|
output_format.sample_rate = xaiOptions.sampleRate;
|
|
4742
4706
|
}
|
|
4743
|
-
if (
|
|
4707
|
+
if (xaiOptions?.bitRate != null) {
|
|
4744
4708
|
if (codec === "mp3") {
|
|
4745
4709
|
output_format.bit_rate = xaiOptions.bitRate;
|
|
4746
4710
|
} else {
|
|
@@ -4757,20 +4721,19 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
4757
4721
|
language,
|
|
4758
4722
|
output_format,
|
|
4759
4723
|
speed,
|
|
4760
|
-
optimize_streaming_latency: xaiOptions
|
|
4761
|
-
text_normalization: xaiOptions
|
|
4762
|
-
with_timestamps: xaiOptions
|
|
4763
|
-
replace: xaiOptions
|
|
4724
|
+
optimize_streaming_latency: xaiOptions?.optimizeStreamingLatency,
|
|
4725
|
+
text_normalization: xaiOptions?.textNormalization,
|
|
4726
|
+
with_timestamps: xaiOptions?.withTimestamps,
|
|
4727
|
+
replace: xaiOptions?.replace
|
|
4764
4728
|
};
|
|
4765
4729
|
return {
|
|
4766
4730
|
requestBody,
|
|
4767
4731
|
warnings,
|
|
4768
|
-
withTimestamps:
|
|
4732
|
+
withTimestamps: xaiOptions?.withTimestamps === true
|
|
4769
4733
|
};
|
|
4770
4734
|
}
|
|
4771
4735
|
async doGenerate(options) {
|
|
4772
|
-
|
|
4773
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4736
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4774
4737
|
const { requestBody, warnings, withTimestamps } = await this.getArgs(options);
|
|
4775
4738
|
const { value, responseHeaders, rawValue } = await postJsonToApi5({
|
|
4776
4739
|
url: `${this.config.baseURL}/tts`,
|
|
@@ -4792,7 +4755,7 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
4792
4755
|
envelope = value;
|
|
4793
4756
|
audio = envelope.audio != null ? convertBase64ToUint8Array2(envelope.audio) : new Uint8Array(0);
|
|
4794
4757
|
}
|
|
4795
|
-
const traceId = responseHeaders
|
|
4758
|
+
const traceId = responseHeaders?.["x-trace-id"];
|
|
4796
4759
|
return {
|
|
4797
4760
|
audio,
|
|
4798
4761
|
warnings,
|
|
@@ -4808,9 +4771,9 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
4808
4771
|
providerMetadata: {
|
|
4809
4772
|
xai: {
|
|
4810
4773
|
...traceId != null ? { traceId } : {},
|
|
4811
|
-
...
|
|
4812
|
-
...
|
|
4813
|
-
...
|
|
4774
|
+
...envelope?.duration != null ? { duration: envelope.duration } : {},
|
|
4775
|
+
...envelope?.content_type != null ? { contentType: envelope.content_type } : {},
|
|
4776
|
+
...envelope?.audio_timestamps != null ? {
|
|
4814
4777
|
audioTimestamps: {
|
|
4815
4778
|
graphChars: envelope.audio_timestamps.graph_chars,
|
|
4816
4779
|
graphTimes: envelope.audio_timestamps.graph_times
|
|
@@ -4961,21 +4924,21 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
4961
4924
|
});
|
|
4962
4925
|
const formData = new FormData();
|
|
4963
4926
|
const transcriptionOptions = {
|
|
4964
|
-
audio_format: xaiOptions
|
|
4965
|
-
sample_rate: xaiOptions
|
|
4966
|
-
language: xaiOptions
|
|
4967
|
-
format: xaiOptions
|
|
4968
|
-
multichannel: xaiOptions
|
|
4969
|
-
channels: xaiOptions
|
|
4970
|
-
diarize: xaiOptions
|
|
4971
|
-
filler_words: xaiOptions
|
|
4927
|
+
audio_format: xaiOptions?.audioFormat,
|
|
4928
|
+
sample_rate: xaiOptions?.sampleRate,
|
|
4929
|
+
language: xaiOptions?.language,
|
|
4930
|
+
format: xaiOptions?.format,
|
|
4931
|
+
multichannel: xaiOptions?.multichannel,
|
|
4932
|
+
channels: xaiOptions?.channels,
|
|
4933
|
+
diarize: xaiOptions?.diarize,
|
|
4934
|
+
filler_words: xaiOptions?.fillerWords
|
|
4972
4935
|
};
|
|
4973
4936
|
for (const [key, value] of Object.entries(transcriptionOptions)) {
|
|
4974
4937
|
if (value != null) {
|
|
4975
4938
|
formData.append(key, String(value));
|
|
4976
4939
|
}
|
|
4977
4940
|
}
|
|
4978
|
-
if (
|
|
4941
|
+
if (xaiOptions?.keyterm != null) {
|
|
4979
4942
|
const keyterms = Array.isArray(xaiOptions.keyterm) ? xaiOptions.keyterm : [xaiOptions.keyterm];
|
|
4980
4943
|
for (const keyterm of keyterms) {
|
|
4981
4944
|
formData.append("keyterm", keyterm);
|
|
@@ -4991,16 +4954,15 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
4991
4954
|
return { formData, warnings };
|
|
4992
4955
|
}
|
|
4993
4956
|
async doGenerate(options) {
|
|
4994
|
-
|
|
4995
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4957
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4996
4958
|
const { formData, warnings } = await this.getArgs(options);
|
|
4997
4959
|
const {
|
|
4998
4960
|
value: response,
|
|
4999
4961
|
responseHeaders,
|
|
5000
4962
|
rawValue: rawResponse
|
|
5001
4963
|
} = await postFormDataToApi3({
|
|
5002
|
-
url: `${
|
|
5003
|
-
headers: combineHeaders7(
|
|
4964
|
+
url: `${this.config.baseURL ?? "https://api.x.ai/v1"}/stt`,
|
|
4965
|
+
headers: combineHeaders7(this.config.headers?.(), options.headers),
|
|
5004
4966
|
formData,
|
|
5005
4967
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
5006
4968
|
successfulResponseHandler: createJsonResponseHandler7(
|
|
@@ -5011,13 +4973,13 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5011
4973
|
});
|
|
5012
4974
|
return {
|
|
5013
4975
|
text: response.text,
|
|
5014
|
-
segments:
|
|
4976
|
+
segments: response.words?.map((word) => ({
|
|
5015
4977
|
text: word.text,
|
|
5016
4978
|
startSecond: word.start,
|
|
5017
4979
|
endSecond: word.end
|
|
5018
|
-
}))
|
|
4980
|
+
})) ?? [],
|
|
5019
4981
|
language: response.language || void 0,
|
|
5020
|
-
durationInSeconds:
|
|
4982
|
+
durationInSeconds: response.duration ?? void 0,
|
|
5021
4983
|
warnings,
|
|
5022
4984
|
response: {
|
|
5023
4985
|
timestamp: currentDate,
|
|
@@ -5028,39 +4990,38 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5028
4990
|
};
|
|
5029
4991
|
}
|
|
5030
4992
|
async doStream(options) {
|
|
5031
|
-
|
|
5032
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4993
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
5033
4994
|
const warnings = [];
|
|
5034
4995
|
const xaiOptions = await parseProviderOptions8({
|
|
5035
4996
|
provider: "xai",
|
|
5036
4997
|
providerOptions: options.providerOptions,
|
|
5037
4998
|
schema: xaiTranscriptionModelOptionsSchema
|
|
5038
4999
|
});
|
|
5039
|
-
if (
|
|
5000
|
+
if (xaiOptions?.multichannel === true && xaiOptions.channels == null) {
|
|
5040
5001
|
throw new InvalidArgumentError3({
|
|
5041
5002
|
argument: "providerOptions",
|
|
5042
5003
|
message: "providerOptions.xai.channels is required when providerOptions.xai.multichannel is true"
|
|
5043
5004
|
});
|
|
5044
5005
|
}
|
|
5045
|
-
if (
|
|
5006
|
+
if (xaiOptions?.format != null) {
|
|
5046
5007
|
warnings.push({
|
|
5047
5008
|
type: "unsupported",
|
|
5048
5009
|
feature: "providerOptions.xai.format",
|
|
5049
5010
|
details: "xAI streaming transcription does not support format."
|
|
5050
5011
|
});
|
|
5051
5012
|
}
|
|
5052
|
-
if (
|
|
5013
|
+
if (xaiOptions?.audioFormat == null && !isKnownInputAudioFormat(options.inputAudioFormat.type)) {
|
|
5053
5014
|
warnings.push({
|
|
5054
5015
|
type: "other",
|
|
5055
5016
|
message: `Unrecognized inputAudioFormat.type "${options.inputAudioFormat.type}"; falling back to raw PCM encoding. Use audio/pcm, audio/pcmu, or audio/pcma, or set providerOptions.xai.audioFormat explicitly.`
|
|
5056
5017
|
});
|
|
5057
5018
|
}
|
|
5058
5019
|
const url = buildXaiStreamingTranscriptionUrl({
|
|
5059
|
-
baseURL:
|
|
5020
|
+
baseURL: this.config.baseURL ?? "https://api.x.ai/v1",
|
|
5060
5021
|
inputAudioFormat: options.inputAudioFormat,
|
|
5061
5022
|
providerOptions: xaiOptions
|
|
5062
5023
|
});
|
|
5063
|
-
const headers = combineHeaders7(
|
|
5024
|
+
const headers = combineHeaders7(this.config.headers?.(), options.headers);
|
|
5064
5025
|
return {
|
|
5065
5026
|
request: { body: url.toString() },
|
|
5066
5027
|
response: {
|
|
@@ -5072,8 +5033,8 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5072
5033
|
url,
|
|
5073
5034
|
headers,
|
|
5074
5035
|
warnings,
|
|
5075
|
-
language:
|
|
5076
|
-
expectedDoneCount:
|
|
5036
|
+
language: xaiOptions?.language ?? void 0,
|
|
5037
|
+
expectedDoneCount: xaiOptions?.multichannel === true ? xaiOptions.channels : 1,
|
|
5077
5038
|
audio: options.audio,
|
|
5078
5039
|
abortSignal: options.abortSignal,
|
|
5079
5040
|
includeRawChunks: options.includeRawChunks
|
|
@@ -5111,7 +5072,7 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5111
5072
|
void audio.cancel().catch(() => {
|
|
5112
5073
|
});
|
|
5113
5074
|
}
|
|
5114
|
-
connection
|
|
5075
|
+
connection?.close(closeCode);
|
|
5115
5076
|
};
|
|
5116
5077
|
const finishWithError = (error) => {
|
|
5117
5078
|
if (finished) return;
|
|
@@ -5160,7 +5121,6 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5160
5121
|
onAbort: finishWithError,
|
|
5161
5122
|
onProcessingError: finishWithError,
|
|
5162
5123
|
onMessageText: async (text) => {
|
|
5163
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
5164
5124
|
const parsed = await safeParseJSON2({ text });
|
|
5165
5125
|
if (!parsed.success) return;
|
|
5166
5126
|
const raw = parsed.value;
|
|
@@ -5170,7 +5130,7 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5170
5130
|
switch (raw.type) {
|
|
5171
5131
|
case "transcript.created": {
|
|
5172
5132
|
controller.enqueue({ type: "stream-start", warnings });
|
|
5173
|
-
const socket = connection
|
|
5133
|
+
const socket = connection?.socket;
|
|
5174
5134
|
if (socket == null) {
|
|
5175
5135
|
finishWithError(new Error("WebSocket is not connected."));
|
|
5176
5136
|
break;
|
|
@@ -5180,12 +5140,12 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5180
5140
|
}
|
|
5181
5141
|
case "transcript.partial": {
|
|
5182
5142
|
const id = channelId(raw.channel_index);
|
|
5183
|
-
const channelIndex =
|
|
5143
|
+
const channelIndex = raw.channel_index ?? 0;
|
|
5184
5144
|
if (raw.is_final && raw.speech_final) {
|
|
5185
5145
|
const timing = timingFromXaiEvent(raw);
|
|
5186
5146
|
if (raw.text) {
|
|
5187
5147
|
finalizedTexts.set(channelIndex, [
|
|
5188
|
-
...
|
|
5148
|
+
...finalizedTexts.get(channelIndex) ?? [],
|
|
5189
5149
|
raw.text
|
|
5190
5150
|
]);
|
|
5191
5151
|
}
|
|
@@ -5193,16 +5153,16 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5193
5153
|
controller.enqueue({
|
|
5194
5154
|
type: "transcript-final",
|
|
5195
5155
|
id,
|
|
5196
|
-
text:
|
|
5156
|
+
text: raw.text ?? "",
|
|
5197
5157
|
...timing,
|
|
5198
5158
|
channelIndex: raw.channel_index
|
|
5199
5159
|
});
|
|
5200
5160
|
} else {
|
|
5201
|
-
pendingTexts.set(channelIndex,
|
|
5161
|
+
pendingTexts.set(channelIndex, raw.text ?? "");
|
|
5202
5162
|
controller.enqueue({
|
|
5203
5163
|
type: "transcript-partial",
|
|
5204
5164
|
id,
|
|
5205
|
-
text:
|
|
5165
|
+
text: raw.text ?? "",
|
|
5206
5166
|
startSecond: raw.start,
|
|
5207
5167
|
durationInSeconds: raw.duration,
|
|
5208
5168
|
channelIndex: raw.channel_index
|
|
@@ -5211,18 +5171,18 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5211
5171
|
break;
|
|
5212
5172
|
}
|
|
5213
5173
|
case "transcript.done": {
|
|
5214
|
-
const channelIndex =
|
|
5174
|
+
const channelIndex = raw.channel_index ?? 0;
|
|
5215
5175
|
const accumulated = [
|
|
5216
|
-
...
|
|
5176
|
+
...finalizedTexts.get(channelIndex) ?? [],
|
|
5217
5177
|
...pendingTexts.get(channelIndex) ? [pendingTexts.get(channelIndex)] : []
|
|
5218
5178
|
].join(" ");
|
|
5219
5179
|
doneTexts.set(channelIndex, raw.text || accumulated);
|
|
5220
|
-
doneDuration =
|
|
5180
|
+
doneDuration = raw.duration ?? doneDuration;
|
|
5221
5181
|
maybeFinish();
|
|
5222
5182
|
break;
|
|
5223
5183
|
}
|
|
5224
5184
|
case "error": {
|
|
5225
|
-
finishWithError(new Error(
|
|
5185
|
+
finishWithError(new Error(raw.message ?? "xAI STT error"));
|
|
5226
5186
|
break;
|
|
5227
5187
|
}
|
|
5228
5188
|
}
|
|
@@ -5254,40 +5214,39 @@ function buildXaiStreamingTranscriptionUrl({
|
|
|
5254
5214
|
inputAudioFormat,
|
|
5255
5215
|
providerOptions
|
|
5256
5216
|
}) {
|
|
5257
|
-
var _a, _b, _c, _d, _e, _f;
|
|
5258
5217
|
const url = toWebSocketUrl(`${baseURL}/stt`);
|
|
5259
5218
|
appendSearchParam(
|
|
5260
5219
|
url,
|
|
5261
5220
|
"sample_rate",
|
|
5262
|
-
|
|
5221
|
+
providerOptions?.sampleRate ?? inputAudioFormat.rate
|
|
5263
5222
|
);
|
|
5264
5223
|
appendSearchParam(
|
|
5265
5224
|
url,
|
|
5266
5225
|
"encoding",
|
|
5267
|
-
|
|
5226
|
+
providerOptions?.audioFormat ?? encodingFromInputAudioFormat(inputAudioFormat.type)
|
|
5268
5227
|
);
|
|
5269
|
-
appendSearchParam(url, "language", providerOptions
|
|
5270
|
-
appendSearchParam(url, "diarize", providerOptions
|
|
5271
|
-
appendSearchParam(url, "filler_words", providerOptions
|
|
5272
|
-
appendSearchParam(url, "multichannel", providerOptions
|
|
5273
|
-
appendSearchParam(url, "channels", providerOptions
|
|
5228
|
+
appendSearchParam(url, "language", providerOptions?.language);
|
|
5229
|
+
appendSearchParam(url, "diarize", providerOptions?.diarize);
|
|
5230
|
+
appendSearchParam(url, "filler_words", providerOptions?.fillerWords);
|
|
5231
|
+
appendSearchParam(url, "multichannel", providerOptions?.multichannel);
|
|
5232
|
+
appendSearchParam(url, "channels", providerOptions?.channels);
|
|
5274
5233
|
appendSearchParam(
|
|
5275
5234
|
url,
|
|
5276
5235
|
"interim_results",
|
|
5277
|
-
|
|
5236
|
+
providerOptions?.streaming?.interimResults
|
|
5278
5237
|
);
|
|
5279
5238
|
appendSearchParam(
|
|
5280
5239
|
url,
|
|
5281
5240
|
"endpointing",
|
|
5282
|
-
|
|
5241
|
+
providerOptions?.streaming?.endpointing
|
|
5283
5242
|
);
|
|
5284
|
-
appendSearchParam(url, "smart_turn",
|
|
5243
|
+
appendSearchParam(url, "smart_turn", providerOptions?.streaming?.smartTurn);
|
|
5285
5244
|
appendSearchParam(
|
|
5286
5245
|
url,
|
|
5287
5246
|
"smart_turn_timeout",
|
|
5288
|
-
|
|
5247
|
+
providerOptions?.streaming?.smartTurnTimeout
|
|
5289
5248
|
);
|
|
5290
|
-
if (
|
|
5249
|
+
if (providerOptions?.keyterm != null) {
|
|
5291
5250
|
const keyterms = Array.isArray(providerOptions.keyterm) ? providerOptions.keyterm : [providerOptions.keyterm];
|
|
5292
5251
|
for (const keyterm of keyterms) {
|
|
5293
5252
|
url.searchParams.append("keyterm", keyterm);
|
|
@@ -5337,9 +5296,8 @@ var xaiTranscriptionResponseSchema = z23.object({
|
|
|
5337
5296
|
|
|
5338
5297
|
// src/xai-provider.ts
|
|
5339
5298
|
function createXai(options = {}) {
|
|
5340
|
-
var _a;
|
|
5341
5299
|
const baseURL = withoutTrailingSlash(
|
|
5342
|
-
|
|
5300
|
+
options.baseURL ?? "https://api.x.ai/v1"
|
|
5343
5301
|
);
|
|
5344
5302
|
const getHeaders = () => withUserAgentSuffix(
|
|
5345
5303
|
{
|
|
@@ -5380,7 +5338,7 @@ function createXai(options = {}) {
|
|
|
5380
5338
|
const createRealtimeModel = (modelId) => {
|
|
5381
5339
|
return new XaiRealtimeModel(modelId, {
|
|
5382
5340
|
provider: "xai.realtime",
|
|
5383
|
-
baseURL: baseURL
|
|
5341
|
+
baseURL: baseURL ?? "https://api.x.ai/v1",
|
|
5384
5342
|
headers: getHeaders,
|
|
5385
5343
|
fetch: options.fetch
|
|
5386
5344
|
});
|