@ai-sdk/xai 5.0.8 → 5.0.11
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 +34 -0
- package/dist/index.js +248 -284
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/xai-image-model.ts +11 -0
package/dist/index.js
CHANGED
|
@@ -77,6 +77,12 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
77
77
|
this.specificationVersion = "v4";
|
|
78
78
|
this.maxImagesPerCall = 3;
|
|
79
79
|
}
|
|
80
|
+
get supportsFileInputs() {
|
|
81
|
+
return this.modelId === "grok-imagine-image" || this.modelId === "grok-imagine-image-pro" ? true : void 0;
|
|
82
|
+
}
|
|
83
|
+
get supportsMaskInputs() {
|
|
84
|
+
return this.supportsFileInputs === true ? false : void 0;
|
|
85
|
+
}
|
|
80
86
|
get provider() {
|
|
81
87
|
return this.config.provider;
|
|
82
88
|
}
|
|
@@ -101,7 +107,6 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
101
107
|
files,
|
|
102
108
|
mask
|
|
103
109
|
}) {
|
|
104
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
105
110
|
const warnings = [];
|
|
106
111
|
if (size != null) {
|
|
107
112
|
warnings.push({
|
|
@@ -139,22 +144,22 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
139
144
|
if (aspectRatio != null) {
|
|
140
145
|
body.aspect_ratio = aspectRatio;
|
|
141
146
|
}
|
|
142
|
-
if (
|
|
147
|
+
if (xaiOptions?.output_format != null) {
|
|
143
148
|
body.output_format = xaiOptions.output_format;
|
|
144
149
|
}
|
|
145
|
-
if (
|
|
150
|
+
if (xaiOptions?.sync_mode != null) {
|
|
146
151
|
body.sync_mode = xaiOptions.sync_mode;
|
|
147
152
|
}
|
|
148
|
-
if (
|
|
153
|
+
if (xaiOptions?.aspect_ratio != null && aspectRatio == null) {
|
|
149
154
|
body.aspect_ratio = xaiOptions.aspect_ratio;
|
|
150
155
|
}
|
|
151
|
-
if (
|
|
156
|
+
if (xaiOptions?.resolution != null) {
|
|
152
157
|
body.resolution = xaiOptions.resolution;
|
|
153
158
|
}
|
|
154
|
-
if (
|
|
159
|
+
if (xaiOptions?.quality != null) {
|
|
155
160
|
body.quality = xaiOptions.quality;
|
|
156
161
|
}
|
|
157
|
-
if (
|
|
162
|
+
if (xaiOptions?.user != null) {
|
|
158
163
|
body.user = xaiOptions.user;
|
|
159
164
|
}
|
|
160
165
|
if (imageUrls.length === 1) {
|
|
@@ -162,11 +167,11 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
162
167
|
} else if (imageUrls.length > 1) {
|
|
163
168
|
body.images = imageUrls.map((url) => ({ url, type: "image_url" }));
|
|
164
169
|
}
|
|
165
|
-
const baseURL =
|
|
166
|
-
const currentDate =
|
|
170
|
+
const baseURL = this.config.baseURL ?? "https://api.x.ai/v1";
|
|
171
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
167
172
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
168
173
|
url: `${baseURL}${endpoint}`,
|
|
169
|
-
headers: combineHeaders(
|
|
174
|
+
headers: combineHeaders(this.config.headers?.(), headers),
|
|
170
175
|
body,
|
|
171
176
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
172
177
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -199,7 +204,7 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
199
204
|
images: response.data.map((item) => ({
|
|
200
205
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {}
|
|
201
206
|
})),
|
|
202
|
-
...
|
|
207
|
+
...response.usage?.cost_in_usd_ticks != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {}
|
|
203
208
|
}
|
|
204
209
|
}
|
|
205
210
|
};
|
|
@@ -267,7 +272,7 @@ function getResponseMetadata({
|
|
|
267
272
|
return createLanguageModelResponseMetadata({
|
|
268
273
|
id,
|
|
269
274
|
model,
|
|
270
|
-
created: created
|
|
275
|
+
created: created ?? created_at
|
|
271
276
|
});
|
|
272
277
|
}
|
|
273
278
|
|
|
@@ -369,7 +374,6 @@ var xaiFilePartProviderOptions = z5.object({
|
|
|
369
374
|
async function convertToXaiResponsesInput({
|
|
370
375
|
prompt
|
|
371
376
|
}) {
|
|
372
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
373
377
|
const input = [];
|
|
374
378
|
const inputWarnings = [];
|
|
375
379
|
for (const message of prompt) {
|
|
@@ -418,7 +422,7 @@ async function convertToXaiResponsesInput({
|
|
|
418
422
|
contentParts.push({
|
|
419
423
|
type: "input_image",
|
|
420
424
|
image_url: imageUrl,
|
|
421
|
-
...
|
|
425
|
+
...filePartOptions?.imageDetail != null && {
|
|
422
426
|
detail: filePartOptions.imageDetail
|
|
423
427
|
}
|
|
424
428
|
});
|
|
@@ -456,7 +460,7 @@ async function convertToXaiResponsesInput({
|
|
|
456
460
|
for (const part of message.content) {
|
|
457
461
|
switch (part.type) {
|
|
458
462
|
case "text": {
|
|
459
|
-
const id = typeof
|
|
463
|
+
const id = typeof part.providerOptions?.xai?.itemId === "string" ? part.providerOptions.xai.itemId : void 0;
|
|
460
464
|
input.push({
|
|
461
465
|
role: "assistant",
|
|
462
466
|
content: part.text,
|
|
@@ -468,10 +472,10 @@ async function convertToXaiResponsesInput({
|
|
|
468
472
|
if (part.providerExecuted) {
|
|
469
473
|
break;
|
|
470
474
|
}
|
|
471
|
-
const id = typeof
|
|
475
|
+
const id = typeof part.providerOptions?.xai?.itemId === "string" ? part.providerOptions.xai.itemId : void 0;
|
|
472
476
|
input.push({
|
|
473
477
|
type: "function_call",
|
|
474
|
-
id: id
|
|
478
|
+
id: id ?? part.toolCallId,
|
|
475
479
|
call_id: part.toolCallId,
|
|
476
480
|
name: part.toolName,
|
|
477
481
|
arguments: JSON.stringify(part.input),
|
|
@@ -483,8 +487,8 @@ async function convertToXaiResponsesInput({
|
|
|
483
487
|
break;
|
|
484
488
|
}
|
|
485
489
|
case "reasoning": {
|
|
486
|
-
const itemId = typeof
|
|
487
|
-
const encryptedContent = typeof
|
|
490
|
+
const itemId = typeof part.providerOptions?.xai?.itemId === "string" ? part.providerOptions.xai.itemId : void 0;
|
|
491
|
+
const encryptedContent = typeof part.providerOptions?.xai?.reasoningEncryptedContent === "string" ? part.providerOptions.xai.reasoningEncryptedContent : void 0;
|
|
488
492
|
if (itemId != null || encryptedContent != null) {
|
|
489
493
|
const summaryParts = [];
|
|
490
494
|
if (part.text.length > 0) {
|
|
@@ -495,7 +499,7 @@ async function convertToXaiResponsesInput({
|
|
|
495
499
|
}
|
|
496
500
|
input.push({
|
|
497
501
|
type: "reasoning",
|
|
498
|
-
id: itemId
|
|
502
|
+
id: itemId ?? "",
|
|
499
503
|
summary: summaryParts,
|
|
500
504
|
status: "completed",
|
|
501
505
|
...encryptedContent != null && {
|
|
@@ -543,7 +547,7 @@ async function convertToXaiResponsesInput({
|
|
|
543
547
|
outputValue = output.value;
|
|
544
548
|
break;
|
|
545
549
|
case "execution-denied":
|
|
546
|
-
outputValue =
|
|
550
|
+
outputValue = output.reason ?? "tool execution denied";
|
|
547
551
|
break;
|
|
548
552
|
case "json":
|
|
549
553
|
case "error-json":
|
|
@@ -605,9 +609,8 @@ async function convertToXaiResponsesInput({
|
|
|
605
609
|
|
|
606
610
|
// src/responses/convert-xai-responses-usage.ts
|
|
607
611
|
function convertXaiResponsesUsage(usage) {
|
|
608
|
-
|
|
609
|
-
const
|
|
610
|
-
const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0;
|
|
612
|
+
const cacheReadTokens = usage.input_tokens_details?.cached_tokens ?? 0;
|
|
613
|
+
const reasoningTokens = usage.output_tokens_details?.reasoning_tokens ?? 0;
|
|
611
614
|
const inputTokensIncludesCached = cacheReadTokens <= usage.input_tokens;
|
|
612
615
|
return {
|
|
613
616
|
inputTokens: {
|
|
@@ -1384,7 +1387,7 @@ async function prepareResponsesTools({
|
|
|
1384
1387
|
tools,
|
|
1385
1388
|
toolChoice
|
|
1386
1389
|
}) {
|
|
1387
|
-
const normalizedTools =
|
|
1390
|
+
const normalizedTools = tools?.length ? tools : void 0;
|
|
1388
1391
|
const toolWarnings = [];
|
|
1389
1392
|
if (normalizedTools == null) {
|
|
1390
1393
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
@@ -1552,7 +1555,7 @@ function createXaiResponsesStreamError({
|
|
|
1552
1555
|
return createProviderStreamError({
|
|
1553
1556
|
message,
|
|
1554
1557
|
type: eventType,
|
|
1555
|
-
code: code
|
|
1558
|
+
code: code ?? void 0,
|
|
1556
1559
|
...statusCode != null ? {
|
|
1557
1560
|
statusCode,
|
|
1558
1561
|
isRetryable: isRetryableStatusCode(statusCode)
|
|
@@ -1646,13 +1649,12 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1646
1649
|
reasoning
|
|
1647
1650
|
}
|
|
1648
1651
|
}) {
|
|
1649
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1650
1652
|
const warnings = [];
|
|
1651
|
-
const options =
|
|
1653
|
+
const options = await parseProviderOptions3({
|
|
1652
1654
|
provider: "xai",
|
|
1653
1655
|
providerOptions,
|
|
1654
1656
|
schema: xaiLanguageModelResponsesOptions
|
|
1655
|
-
})
|
|
1657
|
+
}) ?? {};
|
|
1656
1658
|
if (frequencyPenalty != null) {
|
|
1657
1659
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
1658
1660
|
}
|
|
@@ -1662,27 +1664,27 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1662
1664
|
if (stopSequences != null) {
|
|
1663
1665
|
warnings.push({ type: "unsupported", feature: "stopSequences" });
|
|
1664
1666
|
}
|
|
1665
|
-
const webSearchToolName =
|
|
1667
|
+
const webSearchToolName = tools?.find(
|
|
1666
1668
|
(tool) => tool.type === "provider" && tool.id === "xai.web_search"
|
|
1667
|
-
)
|
|
1668
|
-
const xSearchToolName =
|
|
1669
|
+
)?.name;
|
|
1670
|
+
const xSearchToolName = tools?.find(
|
|
1669
1671
|
(tool) => tool.type === "provider" && tool.id === "xai.x_search"
|
|
1670
|
-
)
|
|
1671
|
-
const codeExecutionToolName =
|
|
1672
|
+
)?.name;
|
|
1673
|
+
const codeExecutionToolName = tools?.find(
|
|
1672
1674
|
(tool) => tool.type === "provider" && tool.id === "xai.code_execution"
|
|
1673
|
-
)
|
|
1674
|
-
const mcpToolName =
|
|
1675
|
+
)?.name;
|
|
1676
|
+
const mcpToolName = tools?.find(
|
|
1675
1677
|
(tool) => tool.type === "provider" && tool.id === "xai.mcp"
|
|
1676
|
-
)
|
|
1677
|
-
const fileSearchToolName =
|
|
1678
|
+
)?.name;
|
|
1679
|
+
const fileSearchToolName = tools?.find(
|
|
1678
1680
|
(tool) => tool.type === "provider" && tool.id === "xai.file_search"
|
|
1679
|
-
)
|
|
1680
|
-
const imageGenerationToolName =
|
|
1681
|
+
)?.name;
|
|
1682
|
+
const imageGenerationToolName = tools?.find(
|
|
1681
1683
|
(tool) => tool.type === "provider" && tool.id === "xai.image_generation"
|
|
1682
|
-
)
|
|
1684
|
+
)?.name;
|
|
1683
1685
|
const { input, inputWarnings } = await convertToXaiResponsesInput({
|
|
1684
1686
|
prompt,
|
|
1685
|
-
store:
|
|
1687
|
+
store: options.store ?? true
|
|
1686
1688
|
});
|
|
1687
1689
|
warnings.push(...inputWarnings);
|
|
1688
1690
|
const {
|
|
@@ -1737,12 +1739,12 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1737
1739
|
top_k: topK,
|
|
1738
1740
|
min_p: options.minP,
|
|
1739
1741
|
seed,
|
|
1740
|
-
...
|
|
1742
|
+
...responseFormat?.type === "json" && {
|
|
1741
1743
|
text: {
|
|
1742
1744
|
format: responseFormat.schema != null ? {
|
|
1743
1745
|
type: "json_schema",
|
|
1744
1746
|
strict: true,
|
|
1745
|
-
name:
|
|
1747
|
+
name: responseFormat.name ?? "response",
|
|
1746
1748
|
description: responseFormat.description,
|
|
1747
1749
|
schema: responseFormat.schema
|
|
1748
1750
|
} : { type: "json_object" }
|
|
@@ -1805,7 +1807,6 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1805
1807
|
});
|
|
1806
1808
|
}
|
|
1807
1809
|
async doGenerate(options) {
|
|
1808
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1809
1810
|
const {
|
|
1810
1811
|
args: body,
|
|
1811
1812
|
warnings,
|
|
@@ -1821,8 +1822,8 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1821
1822
|
value: response,
|
|
1822
1823
|
rawValue: rawResponse
|
|
1823
1824
|
} = await postJsonToApi2({
|
|
1824
|
-
url: `${
|
|
1825
|
-
headers: combineHeaders2(
|
|
1825
|
+
url: `${this.config.baseURL ?? "https://api.x.ai/v1"}/responses`,
|
|
1826
|
+
headers: combineHeaders2(this.config.headers?.(), options.headers),
|
|
1826
1827
|
body,
|
|
1827
1828
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
1828
1829
|
successfulResponseHandler: createJsonResponseHandler2(
|
|
@@ -1846,7 +1847,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1846
1847
|
];
|
|
1847
1848
|
for (const part of response.output) {
|
|
1848
1849
|
if (part.type === "file_search_call") {
|
|
1849
|
-
const toolName = fileSearchToolName
|
|
1850
|
+
const toolName = fileSearchToolName ?? "file_search";
|
|
1850
1851
|
content.push({
|
|
1851
1852
|
type: "tool-call",
|
|
1852
1853
|
toolCallId: part.id,
|
|
@@ -1859,19 +1860,19 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1859
1860
|
toolCallId: part.id,
|
|
1860
1861
|
toolName,
|
|
1861
1862
|
result: {
|
|
1862
|
-
queries:
|
|
1863
|
-
results:
|
|
1863
|
+
queries: part.queries ?? [],
|
|
1864
|
+
results: part.results?.map((result) => ({
|
|
1864
1865
|
fileId: result.file_id,
|
|
1865
1866
|
filename: result.filename,
|
|
1866
1867
|
score: result.score,
|
|
1867
1868
|
text: result.text
|
|
1868
|
-
}))
|
|
1869
|
+
})) ?? null
|
|
1869
1870
|
}
|
|
1870
1871
|
});
|
|
1871
1872
|
continue;
|
|
1872
1873
|
}
|
|
1873
1874
|
if (part.type === "image_generation_call") {
|
|
1874
|
-
const toolName = imageGenerationToolName
|
|
1875
|
+
const toolName = imageGenerationToolName ?? "image_generation";
|
|
1875
1876
|
content.push({
|
|
1876
1877
|
type: "tool-call",
|
|
1877
1878
|
toolCallId: part.id,
|
|
@@ -1901,17 +1902,17 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1901
1902
|
continue;
|
|
1902
1903
|
}
|
|
1903
1904
|
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
|
|
1905
|
+
let toolName = part.name ?? "";
|
|
1906
|
+
if (webSearchSubTools.includes(part.name ?? "") || part.type === "web_search_call") {
|
|
1907
|
+
toolName = webSearchToolName ?? "web_search";
|
|
1908
|
+
} else if (xSearchSubTools.includes(part.name ?? "") || part.type === "x_search_call") {
|
|
1909
|
+
toolName = xSearchToolName ?? "x_search";
|
|
1909
1910
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
1910
|
-
toolName = codeExecutionToolName
|
|
1911
|
+
toolName = codeExecutionToolName ?? "code_execution";
|
|
1911
1912
|
} else if (part.type === "mcp_call") {
|
|
1912
|
-
toolName =
|
|
1913
|
+
toolName = mcpToolName ?? part.name ?? "mcp";
|
|
1913
1914
|
}
|
|
1914
|
-
const toolInput = part.type === "custom_tool_call" ?
|
|
1915
|
+
const toolInput = part.type === "custom_tool_call" ? part.input ?? "" : part.type === "mcp_call" ? part.arguments ?? "" : part.arguments ?? "";
|
|
1915
1916
|
content.push({
|
|
1916
1917
|
type: "tool-call",
|
|
1917
1918
|
toolCallId: part.id,
|
|
@@ -1946,7 +1947,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1946
1947
|
sourceType: "url",
|
|
1947
1948
|
id: this.config.generateId(),
|
|
1948
1949
|
url: annotation.url,
|
|
1949
|
-
title:
|
|
1950
|
+
title: annotation.title ?? annotation.url
|
|
1950
1951
|
});
|
|
1951
1952
|
}
|
|
1952
1953
|
}
|
|
@@ -1965,7 +1966,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1965
1966
|
break;
|
|
1966
1967
|
}
|
|
1967
1968
|
case "reasoning": {
|
|
1968
|
-
const texts = part.summary.length > 0 ? part.summary.map((s) => s.text) : (
|
|
1969
|
+
const texts = part.summary.length > 0 ? part.summary.map((s) => s.text) : (part.content ?? []).map((c) => c.text);
|
|
1969
1970
|
const reasoningText = texts.filter((text) => text && text.length > 0).join("");
|
|
1970
1971
|
if (reasoningText || part.encrypted_content) {
|
|
1971
1972
|
const hasMetadata = part.encrypted_content || part.id;
|
|
@@ -1995,16 +1996,16 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1995
1996
|
content,
|
|
1996
1997
|
finishReason: {
|
|
1997
1998
|
unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response.status),
|
|
1998
|
-
raw:
|
|
1999
|
+
raw: response.status ?? void 0
|
|
1999
2000
|
},
|
|
2000
2001
|
usage: response.usage ? convertXaiResponsesUsage(response.usage) : {
|
|
2001
2002
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
2002
2003
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
2003
2004
|
},
|
|
2004
|
-
...(
|
|
2005
|
+
...(response.usage?.cost_in_usd_ticks != null || response.service_tier != null || response.prompt_cache_key != null || response.safety_identifier != null) && {
|
|
2005
2006
|
providerMetadata: {
|
|
2006
2007
|
xai: {
|
|
2007
|
-
...
|
|
2008
|
+
...response.usage?.cost_in_usd_ticks != null && {
|
|
2008
2009
|
costInUsdTicks: response.usage.cost_in_usd_ticks
|
|
2009
2010
|
},
|
|
2010
2011
|
...response.service_tier != null && {
|
|
@@ -2029,7 +2030,6 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2029
2030
|
};
|
|
2030
2031
|
}
|
|
2031
2032
|
async doStream(options) {
|
|
2032
|
-
var _a, _b, _c;
|
|
2033
2033
|
const {
|
|
2034
2034
|
args,
|
|
2035
2035
|
warnings,
|
|
@@ -2045,8 +2045,8 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2045
2045
|
stream: true
|
|
2046
2046
|
};
|
|
2047
2047
|
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
2048
|
-
url: `${
|
|
2049
|
-
headers: combineHeaders2(
|
|
2048
|
+
url: `${this.config.baseURL ?? "https://api.x.ai/v1"}/responses`,
|
|
2049
|
+
headers: combineHeaders2(this.config.headers?.(), options.headers),
|
|
2050
2050
|
body,
|
|
2051
2051
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2052
2052
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -2078,7 +2078,6 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2078
2078
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2079
2079
|
},
|
|
2080
2080
|
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
2081
|
if (options.includeRawChunks) {
|
|
2083
2082
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2084
2083
|
}
|
|
@@ -2183,7 +2182,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2183
2182
|
sourceType: "url",
|
|
2184
2183
|
id: self.config.generateId(),
|
|
2185
2184
|
url: annotation.url,
|
|
2186
|
-
title:
|
|
2185
|
+
title: annotation.title ?? annotation.url
|
|
2187
2186
|
});
|
|
2188
2187
|
}
|
|
2189
2188
|
}
|
|
@@ -2198,7 +2197,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2198
2197
|
sourceType: "url",
|
|
2199
2198
|
id: self.config.generateId(),
|
|
2200
2199
|
url: annotation.url,
|
|
2201
|
-
title:
|
|
2200
|
+
title: annotation.title ?? annotation.url
|
|
2202
2201
|
});
|
|
2203
2202
|
}
|
|
2204
2203
|
return;
|
|
@@ -2207,16 +2206,16 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2207
2206
|
const response2 = event.response;
|
|
2208
2207
|
if (response2.usage) {
|
|
2209
2208
|
usage = convertXaiResponsesUsage(response2.usage);
|
|
2210
|
-
costInUsdTicks =
|
|
2209
|
+
costInUsdTicks = response2.usage.cost_in_usd_ticks ?? void 0;
|
|
2211
2210
|
}
|
|
2212
|
-
serviceTier =
|
|
2213
|
-
promptCacheKey =
|
|
2214
|
-
safetyIdentifier =
|
|
2211
|
+
serviceTier = response2.service_tier ?? void 0;
|
|
2212
|
+
promptCacheKey = response2.prompt_cache_key ?? void 0;
|
|
2213
|
+
safetyIdentifier = response2.safety_identifier ?? void 0;
|
|
2215
2214
|
if (event.type === "response.incomplete") {
|
|
2216
|
-
const reason = "incomplete_details" in response2 ?
|
|
2215
|
+
const reason = "incomplete_details" in response2 ? response2.incomplete_details?.reason : void 0;
|
|
2217
2216
|
finishReason = {
|
|
2218
2217
|
unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
|
|
2219
|
-
raw: reason
|
|
2218
|
+
raw: reason ?? "incomplete"
|
|
2220
2219
|
};
|
|
2221
2220
|
} else if ("status" in response2 && response2.status) {
|
|
2222
2221
|
finishReason = {
|
|
@@ -2227,10 +2226,10 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2227
2226
|
return;
|
|
2228
2227
|
}
|
|
2229
2228
|
if (event.type === "response.failed") {
|
|
2230
|
-
const reason =
|
|
2229
|
+
const reason = event.response.incomplete_details?.reason;
|
|
2231
2230
|
finishReason = {
|
|
2232
2231
|
unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
|
|
2233
|
-
raw: reason
|
|
2232
|
+
raw: reason ?? "error"
|
|
2234
2233
|
};
|
|
2235
2234
|
if (event.response.usage) {
|
|
2236
2235
|
usage = convertXaiResponsesUsage(event.response.usage);
|
|
@@ -2280,7 +2279,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2280
2279
|
if (event.type === "response.image_generation_call.in_progress" || event.type === "response.image_generation_call.generating" || event.type === "response.image_generation_call.completed") {
|
|
2281
2280
|
if (!seenToolCalls.has(event.item_id)) {
|
|
2282
2281
|
seenToolCalls.add(event.item_id);
|
|
2283
|
-
const toolName = imageGenerationToolName
|
|
2282
|
+
const toolName = imageGenerationToolName ?? "image_generation";
|
|
2284
2283
|
controller.enqueue({
|
|
2285
2284
|
type: "tool-input-start",
|
|
2286
2285
|
id: event.item_id,
|
|
@@ -2339,7 +2338,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2339
2338
|
return;
|
|
2340
2339
|
}
|
|
2341
2340
|
if (part.type === "file_search_call") {
|
|
2342
|
-
const toolName = fileSearchToolName
|
|
2341
|
+
const toolName = fileSearchToolName ?? "file_search";
|
|
2343
2342
|
if (!seenToolCalls.has(part.id)) {
|
|
2344
2343
|
seenToolCalls.add(part.id);
|
|
2345
2344
|
controller.enqueue({
|
|
@@ -2370,20 +2369,20 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2370
2369
|
toolCallId: part.id,
|
|
2371
2370
|
toolName,
|
|
2372
2371
|
result: {
|
|
2373
|
-
queries:
|
|
2374
|
-
results:
|
|
2372
|
+
queries: part.queries ?? [],
|
|
2373
|
+
results: part.results?.map((result) => ({
|
|
2375
2374
|
fileId: result.file_id,
|
|
2376
2375
|
filename: result.filename,
|
|
2377
2376
|
score: result.score,
|
|
2378
2377
|
text: result.text
|
|
2379
|
-
}))
|
|
2378
|
+
})) ?? null
|
|
2380
2379
|
}
|
|
2381
2380
|
});
|
|
2382
2381
|
}
|
|
2383
2382
|
return;
|
|
2384
2383
|
}
|
|
2385
2384
|
if (part.type === "image_generation_call") {
|
|
2386
|
-
const toolName = imageGenerationToolName
|
|
2385
|
+
const toolName = imageGenerationToolName ?? "image_generation";
|
|
2387
2386
|
if (!seenToolCalls.has(part.id)) {
|
|
2388
2387
|
seenToolCalls.add(part.id);
|
|
2389
2388
|
controller.enqueue({
|
|
@@ -2443,17 +2442,17 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2443
2442
|
"x_semantic_search",
|
|
2444
2443
|
"x_thread_fetch"
|
|
2445
2444
|
];
|
|
2446
|
-
let toolName =
|
|
2447
|
-
if (webSearchSubTools.includes(
|
|
2448
|
-
toolName = webSearchToolName
|
|
2449
|
-
} else if (xSearchSubTools.includes(
|
|
2450
|
-
toolName = xSearchToolName
|
|
2445
|
+
let toolName = part.name ?? "";
|
|
2446
|
+
if (webSearchSubTools.includes(part.name ?? "") || part.type === "web_search_call") {
|
|
2447
|
+
toolName = webSearchToolName ?? "web_search";
|
|
2448
|
+
} else if (xSearchSubTools.includes(part.name ?? "") || part.type === "x_search_call") {
|
|
2449
|
+
toolName = xSearchToolName ?? "x_search";
|
|
2451
2450
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
2452
|
-
toolName = codeExecutionToolName
|
|
2451
|
+
toolName = codeExecutionToolName ?? "code_execution";
|
|
2453
2452
|
} else if (part.type === "mcp_call") {
|
|
2454
|
-
toolName =
|
|
2453
|
+
toolName = mcpToolName ?? part.name ?? "mcp";
|
|
2455
2454
|
}
|
|
2456
|
-
const toolInput = part.type === "custom_tool_call" ?
|
|
2455
|
+
const toolInput = part.type === "custom_tool_call" ? part.input ?? "" : part.type === "mcp_call" ? part.arguments ?? "" : part.arguments ?? "";
|
|
2457
2456
|
const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
|
|
2458
2457
|
if (shouldEmit && !seenToolCalls.has(part.id)) {
|
|
2459
2458
|
seenToolCalls.add(part.id);
|
|
@@ -2514,7 +2513,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2514
2513
|
sourceType: "url",
|
|
2515
2514
|
id: self.config.generateId(),
|
|
2516
2515
|
url: annotation.url,
|
|
2517
|
-
title:
|
|
2516
|
+
title: annotation.title ?? annotation.url
|
|
2518
2517
|
});
|
|
2519
2518
|
}
|
|
2520
2519
|
}
|
|
@@ -2560,7 +2559,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2560
2559
|
controller.enqueue({
|
|
2561
2560
|
type: "finish",
|
|
2562
2561
|
finishReason,
|
|
2563
|
-
usage: usage
|
|
2562
|
+
usage: usage ?? {
|
|
2564
2563
|
inputTokens: {
|
|
2565
2564
|
total: 0,
|
|
2566
2565
|
noCache: 0,
|
|
@@ -2589,11 +2588,10 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2589
2588
|
}
|
|
2590
2589
|
};
|
|
2591
2590
|
function mapWebSearchAction(action) {
|
|
2592
|
-
var _a;
|
|
2593
2591
|
const parsed = webSearchWireActionSchema.safeParse(action);
|
|
2594
2592
|
if (!parsed.success) return {};
|
|
2595
2593
|
const a = parsed.data;
|
|
2596
|
-
const sources =
|
|
2594
|
+
const sources = a.sources?.flatMap((s) => {
|
|
2597
2595
|
const source = webSearchWireSourceSchema.safeParse(s);
|
|
2598
2596
|
return source.success ? [source.data] : [];
|
|
2599
2597
|
});
|
|
@@ -2751,7 +2749,6 @@ var XaiBatch = class {
|
|
|
2751
2749
|
this.provider = options.provider;
|
|
2752
2750
|
}
|
|
2753
2751
|
async doStartBatch(options) {
|
|
2754
|
-
var _a, _b;
|
|
2755
2752
|
assertSupportedBatchRequests(options.requests);
|
|
2756
2753
|
const fileParts = [];
|
|
2757
2754
|
const warnings = options.webhookUrl == null ? [] : [
|
|
@@ -2787,7 +2784,7 @@ var XaiBatch = class {
|
|
|
2787
2784
|
const file = new Blob(fileParts, { type: "application/jsonl" });
|
|
2788
2785
|
fileParts.length = 0;
|
|
2789
2786
|
const formData = new FormData();
|
|
2790
|
-
if (
|
|
2787
|
+
if (batchOptions?.inputFileExpiresAfter != null) {
|
|
2791
2788
|
formData.append(
|
|
2792
2789
|
"expires_after",
|
|
2793
2790
|
String(batchOptions.inputFileExpiresAfter)
|
|
@@ -2795,7 +2792,7 @@ var XaiBatch = class {
|
|
|
2795
2792
|
}
|
|
2796
2793
|
formData.append("file", file, filename);
|
|
2797
2794
|
const headers = combineHeaders3(
|
|
2798
|
-
|
|
2795
|
+
this.options.config.headers?.(),
|
|
2799
2796
|
options.headers
|
|
2800
2797
|
);
|
|
2801
2798
|
const { value: uploadedFile } = await postFormDataToApi({
|
|
@@ -2843,12 +2840,11 @@ var XaiBatch = class {
|
|
|
2843
2840
|
return convertXaiBatchStatus(await this.retrieveBatch(options));
|
|
2844
2841
|
}
|
|
2845
2842
|
async doCancelBatch(options) {
|
|
2846
|
-
var _a, _b;
|
|
2847
2843
|
await postJsonToApi3({
|
|
2848
2844
|
url: this.getUrl(
|
|
2849
2845
|
`/batches/${encodeURIComponent(options.batchId)}:cancel`
|
|
2850
2846
|
),
|
|
2851
|
-
headers: combineHeaders3(
|
|
2847
|
+
headers: combineHeaders3(this.options.config.headers?.(), options.headers),
|
|
2852
2848
|
body: {},
|
|
2853
2849
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2854
2850
|
successfulResponseHandler: createJsonResponseHandler3(
|
|
@@ -2860,7 +2856,6 @@ var XaiBatch = class {
|
|
|
2860
2856
|
return {};
|
|
2861
2857
|
}
|
|
2862
2858
|
async doListBatches(options) {
|
|
2863
|
-
var _a, _b;
|
|
2864
2859
|
const url = new URL(this.getUrl("/batches"));
|
|
2865
2860
|
if (options.limit != null) {
|
|
2866
2861
|
url.searchParams.set("limit", String(options.limit));
|
|
@@ -2870,7 +2865,7 @@ var XaiBatch = class {
|
|
|
2870
2865
|
}
|
|
2871
2866
|
const { value: page } = await getFromApi2({
|
|
2872
2867
|
url: url.toString(),
|
|
2873
|
-
headers: combineHeaders3(
|
|
2868
|
+
headers: combineHeaders3(this.options.config.headers?.(), options.headers),
|
|
2874
2869
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2875
2870
|
successfulResponseHandler: createJsonResponseHandler3(
|
|
2876
2871
|
xaiBatchListResponseSchema
|
|
@@ -2900,10 +2895,9 @@ var XaiBatch = class {
|
|
|
2900
2895
|
);
|
|
2901
2896
|
}
|
|
2902
2897
|
async retrieveBatch(options) {
|
|
2903
|
-
var _a, _b;
|
|
2904
2898
|
const { value: batch } = await getFromApi2({
|
|
2905
2899
|
url: this.getUrl(`/batches/${encodeURIComponent(options.batchId)}`),
|
|
2906
|
-
headers: combineHeaders3(
|
|
2900
|
+
headers: combineHeaders3(this.options.config.headers?.(), options.headers),
|
|
2907
2901
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2908
2902
|
successfulResponseHandler: createJsonResponseHandler3(
|
|
2909
2903
|
xaiBatchResponseSchema
|
|
@@ -2915,7 +2909,6 @@ var XaiBatch = class {
|
|
|
2915
2909
|
return batch;
|
|
2916
2910
|
}
|
|
2917
2911
|
async *iterateBatchResults(options) {
|
|
2918
|
-
var _a, _b, _c;
|
|
2919
2912
|
let paginationToken;
|
|
2920
2913
|
do {
|
|
2921
2914
|
const query = new URLSearchParams({
|
|
@@ -2929,7 +2922,7 @@ var XaiBatch = class {
|
|
|
2929
2922
|
`/batches/${encodeURIComponent(options.batchId)}/results?${query}`
|
|
2930
2923
|
),
|
|
2931
2924
|
headers: combineHeaders3(
|
|
2932
|
-
|
|
2925
|
+
this.options.config.headers?.(),
|
|
2933
2926
|
options.headers
|
|
2934
2927
|
),
|
|
2935
2928
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
@@ -2943,23 +2936,22 @@ var XaiBatch = class {
|
|
|
2943
2936
|
for (const result of page.results) {
|
|
2944
2937
|
yield await this.convertBatchResult(result, options.abortSignal);
|
|
2945
2938
|
}
|
|
2946
|
-
paginationToken =
|
|
2939
|
+
paginationToken = page.pagination_token ?? void 0;
|
|
2947
2940
|
} while (paginationToken != null);
|
|
2948
2941
|
}
|
|
2949
2942
|
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) {
|
|
2943
|
+
const error = result.batch_result?.error;
|
|
2944
|
+
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
2945
|
const convertedError = convertXaiBatchError(result);
|
|
2954
2946
|
return {
|
|
2955
2947
|
type: "text",
|
|
2956
2948
|
id: result.batch_request_id,
|
|
2957
|
-
status: isXaiCancellationError(error
|
|
2949
|
+
status: isXaiCancellationError(error?.code) ? "cancelled" : "failed",
|
|
2958
2950
|
error: convertedError
|
|
2959
2951
|
};
|
|
2960
2952
|
}
|
|
2961
|
-
const response =
|
|
2962
|
-
if (
|
|
2953
|
+
const response = result.batch_result?.response;
|
|
2954
|
+
if (response?.chat_get_completion != null) {
|
|
2963
2955
|
const validation = await safeValidateTypes({
|
|
2964
2956
|
value: response.chat_get_completion,
|
|
2965
2957
|
schema: zodSchema7(xaiBatchTextResponseSchema)
|
|
@@ -2980,7 +2972,7 @@ var XaiBatch = class {
|
|
|
2980
2972
|
error: conversion.error
|
|
2981
2973
|
};
|
|
2982
2974
|
}
|
|
2983
|
-
if (
|
|
2975
|
+
if (response?.image_generation != null) {
|
|
2984
2976
|
const validation = await safeValidateTypes({
|
|
2985
2977
|
value: response.image_generation,
|
|
2986
2978
|
schema: zodSchema7(xaiBatchImageResponseSchema)
|
|
@@ -3035,7 +3027,7 @@ var XaiBatch = class {
|
|
|
3035
3027
|
providerOptions,
|
|
3036
3028
|
schema: xaiImageModelOptions
|
|
3037
3029
|
});
|
|
3038
|
-
const imageUrls = (files
|
|
3030
|
+
const imageUrls = (files ?? []).map(convertImageModelFileToDataUri2);
|
|
3039
3031
|
const body = {
|
|
3040
3032
|
model: request.modelId,
|
|
3041
3033
|
prompt,
|
|
@@ -3043,27 +3035,26 @@ var XaiBatch = class {
|
|
|
3043
3035
|
response_format: "b64_json"
|
|
3044
3036
|
};
|
|
3045
3037
|
if (aspectRatio != null) body.aspect_ratio = aspectRatio;
|
|
3046
|
-
if (
|
|
3038
|
+
if (xaiOptions?.output_format != null)
|
|
3047
3039
|
body.output_format = xaiOptions.output_format;
|
|
3048
|
-
if (
|
|
3049
|
-
if (
|
|
3040
|
+
if (xaiOptions?.sync_mode != null) body.sync_mode = xaiOptions.sync_mode;
|
|
3041
|
+
if (xaiOptions?.aspect_ratio != null && aspectRatio == null)
|
|
3050
3042
|
body.aspect_ratio = xaiOptions.aspect_ratio;
|
|
3051
|
-
if (
|
|
3052
|
-
if (
|
|
3053
|
-
if (
|
|
3043
|
+
if (xaiOptions?.resolution != null) body.resolution = xaiOptions.resolution;
|
|
3044
|
+
if (xaiOptions?.quality != null) body.quality = xaiOptions.quality;
|
|
3045
|
+
if (xaiOptions?.user != null) body.user = xaiOptions.user;
|
|
3054
3046
|
if (imageUrls.length === 1) {
|
|
3055
3047
|
body.image = { url: imageUrls[0], type: "image_url" };
|
|
3056
3048
|
} else if (imageUrls.length > 1) {
|
|
3057
3049
|
body.images = imageUrls.map((url) => ({ url, type: "image_url" }));
|
|
3058
3050
|
}
|
|
3059
3051
|
return {
|
|
3060
|
-
endpoint:
|
|
3052
|
+
endpoint: files?.length ? "/v1/images/edits" : "/v1/images/generations",
|
|
3061
3053
|
body,
|
|
3062
3054
|
warnings
|
|
3063
3055
|
};
|
|
3064
3056
|
}
|
|
3065
3057
|
async convertImageBatchResponse(response, abortSignal) {
|
|
3066
|
-
var _a;
|
|
3067
3058
|
const hasAllBase64 = response.data.every((image) => image.b64_json != null);
|
|
3068
3059
|
const images = hasAllBase64 ? response.data.map((image) => image.b64_json) : await Promise.all(
|
|
3069
3060
|
response.data.map(async (image) => {
|
|
@@ -3097,23 +3088,21 @@ var XaiBatch = class {
|
|
|
3097
3088
|
images: response.data.map(
|
|
3098
3089
|
(item) => item.revised_prompt != null ? { revisedPrompt: item.revised_prompt } : {}
|
|
3099
3090
|
),
|
|
3100
|
-
...
|
|
3091
|
+
...response.usage?.cost_in_usd_ticks != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {}
|
|
3101
3092
|
}
|
|
3102
3093
|
}
|
|
3103
3094
|
};
|
|
3104
3095
|
}
|
|
3105
3096
|
getUrl(path) {
|
|
3106
|
-
|
|
3107
|
-
return `${(_a = this.options.config.baseURL) != null ? _a : "https://api.x.ai/v1"}${path}`;
|
|
3097
|
+
return `${this.options.config.baseURL ?? "https://api.x.ai/v1"}${path}`;
|
|
3108
3098
|
}
|
|
3109
3099
|
};
|
|
3110
3100
|
function convertXaiBatchStatus(batch) {
|
|
3111
|
-
var _a, _b, _c, _d, _e, _f;
|
|
3112
3101
|
const requestCounts = normalizeBatchRequestCounts({
|
|
3113
|
-
total:
|
|
3114
|
-
pending:
|
|
3115
|
-
completed:
|
|
3116
|
-
failed:
|
|
3102
|
+
total: batch.state?.num_requests,
|
|
3103
|
+
pending: batch.state?.num_pending,
|
|
3104
|
+
completed: batch.state?.num_success,
|
|
3105
|
+
failed: batch.state?.num_error != null && batch.state?.num_cancelled != null ? batch.state.num_error + batch.state.num_cancelled : void 0
|
|
3117
3106
|
});
|
|
3118
3107
|
const isCancelled = batch.cancel_time != null || batch.cancel_by_xai_message != null;
|
|
3119
3108
|
const isExpired = isPastDate(batch.expire_time);
|
|
@@ -3123,7 +3112,7 @@ function convertXaiBatchStatus(batch) {
|
|
|
3123
3112
|
...requestCounts != null ? { requestCounts } : {},
|
|
3124
3113
|
...isCancelled ? {
|
|
3125
3114
|
error: {
|
|
3126
|
-
message:
|
|
3115
|
+
message: batch.cancel_by_xai_message ?? `xAI batch "${batch.batch_id}" was cancelled.`,
|
|
3127
3116
|
code: "batch_cancelled"
|
|
3128
3117
|
}
|
|
3129
3118
|
} : isExpired ? {
|
|
@@ -3144,11 +3133,10 @@ function isPastDate(value) {
|
|
|
3144
3133
|
return !Number.isNaN(timestamp) && timestamp <= Date.now();
|
|
3145
3134
|
}
|
|
3146
3135
|
function convertXaiBatchError(result) {
|
|
3147
|
-
|
|
3148
|
-
const error = (_a = result.batch_result) == null ? void 0 : _a.error;
|
|
3136
|
+
const error = result.batch_result?.error;
|
|
3149
3137
|
return {
|
|
3150
|
-
message: result.error_message ||
|
|
3151
|
-
...
|
|
3138
|
+
message: result.error_message || error?.message || "xAI batch request failed.",
|
|
3139
|
+
...error?.code != null && error.code !== 0 && error.code !== "0" ? { code: String(error.code) } : {}
|
|
3152
3140
|
};
|
|
3153
3141
|
}
|
|
3154
3142
|
function isXaiCancellationError(code) {
|
|
@@ -3178,7 +3166,6 @@ function invalidXaiImageBatchResult(id) {
|
|
|
3178
3166
|
};
|
|
3179
3167
|
}
|
|
3180
3168
|
function convertXaiBatchTextResponse(response) {
|
|
3181
|
-
var _a, _b, _c, _d, _e, _f;
|
|
3182
3169
|
if (response.error != null) {
|
|
3183
3170
|
return {
|
|
3184
3171
|
success: false,
|
|
@@ -3201,17 +3188,14 @@ function convertXaiBatchTextResponse(response) {
|
|
|
3201
3188
|
const content = [];
|
|
3202
3189
|
const providerExecutedToolCallIds = new Set(
|
|
3203
3190
|
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
|
-
}
|
|
3191
|
+
(choice) => (choice.message.tool_calls ?? []).map((toolCall) => toolCall.id)
|
|
3208
3192
|
)
|
|
3209
3193
|
);
|
|
3210
3194
|
let lastAssistantChoice;
|
|
3211
3195
|
for (const choice of choices) {
|
|
3212
3196
|
if (choice.message.role === "tool") {
|
|
3213
3197
|
if (choice.message.content != null) {
|
|
3214
|
-
for (const toolCall of
|
|
3198
|
+
for (const toolCall of choice.message.tool_calls ?? []) {
|
|
3215
3199
|
content.push({
|
|
3216
3200
|
type: "tool-result",
|
|
3217
3201
|
toolCallId: toolCall.id,
|
|
@@ -3233,7 +3217,7 @@ function convertXaiBatchTextResponse(response) {
|
|
|
3233
3217
|
text: choice.message.reasoning_content
|
|
3234
3218
|
});
|
|
3235
3219
|
}
|
|
3236
|
-
for (const toolCall of
|
|
3220
|
+
for (const toolCall of choice.message.tool_calls ?? []) {
|
|
3237
3221
|
content.push({
|
|
3238
3222
|
type: "tool-call",
|
|
3239
3223
|
toolCallId: toolCall.id,
|
|
@@ -3243,7 +3227,7 @@ function convertXaiBatchTextResponse(response) {
|
|
|
3243
3227
|
});
|
|
3244
3228
|
}
|
|
3245
3229
|
}
|
|
3246
|
-
for (const url of
|
|
3230
|
+
for (const url of response.citations ?? []) {
|
|
3247
3231
|
content.push({
|
|
3248
3232
|
type: "source",
|
|
3249
3233
|
sourceType: "url",
|
|
@@ -3256,16 +3240,16 @@ function convertXaiBatchTextResponse(response) {
|
|
|
3256
3240
|
result: {
|
|
3257
3241
|
content,
|
|
3258
3242
|
finishReason: {
|
|
3259
|
-
unified: mapXaiFinishReason(lastAssistantChoice
|
|
3260
|
-
raw:
|
|
3243
|
+
unified: mapXaiFinishReason(lastAssistantChoice?.finish_reason),
|
|
3244
|
+
raw: lastAssistantChoice?.finish_reason ?? void 0
|
|
3261
3245
|
},
|
|
3262
3246
|
usage: response.usage ? convertXaiBatchTextUsage(response.usage) : createNullLanguageModelUsage(),
|
|
3263
3247
|
response: getResponseMetadata(response),
|
|
3264
3248
|
warnings: [],
|
|
3265
|
-
...(
|
|
3249
|
+
...(response.usage?.cost_in_usd_ticks != null || response.service_tier != null) && {
|
|
3266
3250
|
providerMetadata: {
|
|
3267
3251
|
xai: {
|
|
3268
|
-
...
|
|
3252
|
+
...response.usage?.cost_in_usd_ticks != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {},
|
|
3269
3253
|
...response.service_tier != null ? { serviceTier: response.service_tier } : {}
|
|
3270
3254
|
}
|
|
3271
3255
|
}
|
|
@@ -3274,9 +3258,8 @@ function convertXaiBatchTextResponse(response) {
|
|
|
3274
3258
|
};
|
|
3275
3259
|
}
|
|
3276
3260
|
function convertXaiBatchTextUsage(usage) {
|
|
3277
|
-
|
|
3278
|
-
const
|
|
3279
|
-
const reasoningTokens = (_d = (_c = usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0;
|
|
3261
|
+
const cacheReadTokens = usage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
3262
|
+
const reasoningTokens = usage.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
3280
3263
|
const promptTokensIncludesCached = cacheReadTokens <= usage.prompt_tokens;
|
|
3281
3264
|
return {
|
|
3282
3265
|
inputTokens: {
|
|
@@ -3296,14 +3279,13 @@ function convertXaiBatchTextUsage(usage) {
|
|
|
3296
3279
|
|
|
3297
3280
|
// src/realtime/xai-realtime-event-mapper.ts
|
|
3298
3281
|
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
3282
|
const event = raw;
|
|
3301
3283
|
const type = event.type;
|
|
3302
3284
|
switch (type) {
|
|
3303
3285
|
case "session.created":
|
|
3304
3286
|
return {
|
|
3305
3287
|
type: "session-created",
|
|
3306
|
-
sessionId:
|
|
3288
|
+
sessionId: event.session?.id,
|
|
3307
3289
|
raw
|
|
3308
3290
|
};
|
|
3309
3291
|
case "session.updated":
|
|
@@ -3332,7 +3314,7 @@ function parseXaiRealtimeServerEvent(raw) {
|
|
|
3332
3314
|
case "conversation.item.added":
|
|
3333
3315
|
return {
|
|
3334
3316
|
type: "conversation-item-added",
|
|
3335
|
-
itemId:
|
|
3317
|
+
itemId: event.item?.id ?? event.item_id,
|
|
3336
3318
|
item: event.item,
|
|
3337
3319
|
raw
|
|
3338
3320
|
};
|
|
@@ -3340,34 +3322,34 @@ function parseXaiRealtimeServerEvent(raw) {
|
|
|
3340
3322
|
return {
|
|
3341
3323
|
type: "input-transcription-completed",
|
|
3342
3324
|
itemId: event.item_id,
|
|
3343
|
-
transcript:
|
|
3325
|
+
transcript: event.transcript ?? "",
|
|
3344
3326
|
raw
|
|
3345
3327
|
};
|
|
3346
3328
|
case "response.created":
|
|
3347
3329
|
return {
|
|
3348
3330
|
type: "response-created",
|
|
3349
|
-
responseId:
|
|
3331
|
+
responseId: event.response?.id ?? event.response_id,
|
|
3350
3332
|
raw
|
|
3351
3333
|
};
|
|
3352
3334
|
case "response.done":
|
|
3353
3335
|
return {
|
|
3354
3336
|
type: "response-done",
|
|
3355
|
-
responseId:
|
|
3356
|
-
status:
|
|
3337
|
+
responseId: event.response?.id ?? event.response_id,
|
|
3338
|
+
status: event.response?.status ?? "completed",
|
|
3357
3339
|
raw
|
|
3358
3340
|
};
|
|
3359
3341
|
case "response.output_item.added":
|
|
3360
3342
|
return {
|
|
3361
3343
|
type: "output-item-added",
|
|
3362
3344
|
responseId: event.response_id,
|
|
3363
|
-
itemId:
|
|
3345
|
+
itemId: event.item?.id ?? event.item_id,
|
|
3364
3346
|
raw
|
|
3365
3347
|
};
|
|
3366
3348
|
case "response.output_item.done":
|
|
3367
3349
|
return {
|
|
3368
3350
|
type: "output-item-done",
|
|
3369
3351
|
responseId: event.response_id,
|
|
3370
|
-
itemId:
|
|
3352
|
+
itemId: event.item?.id ?? event.item_id,
|
|
3371
3353
|
raw
|
|
3372
3354
|
};
|
|
3373
3355
|
case "response.content_part.added":
|
|
@@ -3462,8 +3444,8 @@ function parseXaiRealtimeServerEvent(raw) {
|
|
|
3462
3444
|
case "error":
|
|
3463
3445
|
return {
|
|
3464
3446
|
type: "error",
|
|
3465
|
-
message:
|
|
3466
|
-
code:
|
|
3447
|
+
message: event.error?.message ?? event.message ?? "Unknown error",
|
|
3448
|
+
code: event.error?.code ?? event.code,
|
|
3467
3449
|
raw
|
|
3468
3450
|
};
|
|
3469
3451
|
default:
|
|
@@ -3536,7 +3518,6 @@ function serializeXaiRealtimeClientEvent(event) {
|
|
|
3536
3518
|
}
|
|
3537
3519
|
}
|
|
3538
3520
|
function buildXaiSessionConfig(config) {
|
|
3539
|
-
var _a;
|
|
3540
3521
|
const session = {};
|
|
3541
3522
|
if (config.instructions != null) {
|
|
3542
3523
|
session.instructions = config.instructions;
|
|
@@ -3594,7 +3575,7 @@ function buildXaiSessionConfig(config) {
|
|
|
3594
3575
|
if (config.providerOptions != null) {
|
|
3595
3576
|
const xaiOptions = config.providerOptions;
|
|
3596
3577
|
if (Array.isArray(xaiOptions.tools)) {
|
|
3597
|
-
const existingTools =
|
|
3578
|
+
const existingTools = session.tools ?? [];
|
|
3598
3579
|
session.tools = [...existingTools, ...xaiOptions.tools];
|
|
3599
3580
|
}
|
|
3600
3581
|
for (const [key, value] of Object.entries(xaiOptions)) {
|
|
@@ -3615,8 +3596,7 @@ var XaiRealtimeModel = class {
|
|
|
3615
3596
|
this.config = config;
|
|
3616
3597
|
}
|
|
3617
3598
|
async doCreateClientSecret(options) {
|
|
3618
|
-
|
|
3619
|
-
const fetchFn = (_a = this.config.fetch) != null ? _a : fetch;
|
|
3599
|
+
const fetchFn = this.config.fetch ?? fetch;
|
|
3620
3600
|
const url = `${this.config.baseURL}/realtime/client_secrets`;
|
|
3621
3601
|
const body = {};
|
|
3622
3602
|
if (options.expiresAfterSeconds != null) {
|
|
@@ -3719,7 +3699,7 @@ var xaiTools = {
|
|
|
3719
3699
|
};
|
|
3720
3700
|
|
|
3721
3701
|
// src/version.ts
|
|
3722
|
-
var VERSION = true ? "5.0.
|
|
3702
|
+
var VERSION = true ? "5.0.11" : "0.0.0-test";
|
|
3723
3703
|
|
|
3724
3704
|
// src/files/xai-files.ts
|
|
3725
3705
|
import {
|
|
@@ -3792,7 +3772,6 @@ var XaiFiles = class {
|
|
|
3792
3772
|
headers,
|
|
3793
3773
|
providerOptions
|
|
3794
3774
|
}) {
|
|
3795
|
-
var _a, _b;
|
|
3796
3775
|
let xaiOptions;
|
|
3797
3776
|
try {
|
|
3798
3777
|
xaiOptions = await parseProviderOptions5({
|
|
@@ -3812,14 +3791,14 @@ var XaiFiles = class {
|
|
|
3812
3791
|
let response;
|
|
3813
3792
|
if (data.type === "stream") {
|
|
3814
3793
|
const parts = [];
|
|
3815
|
-
if (
|
|
3794
|
+
if (xaiOptions?.expiresAfter != null) {
|
|
3816
3795
|
parts.push({
|
|
3817
3796
|
type: "field",
|
|
3818
3797
|
name: "expires_after",
|
|
3819
3798
|
value: String(xaiOptions.expiresAfter)
|
|
3820
3799
|
});
|
|
3821
3800
|
}
|
|
3822
|
-
if (
|
|
3801
|
+
if (xaiOptions?.teamId != null) {
|
|
3823
3802
|
parts.push({
|
|
3824
3803
|
type: "field",
|
|
3825
3804
|
name: "team_id",
|
|
@@ -3850,10 +3829,10 @@ var XaiFiles = class {
|
|
|
3850
3829
|
type: mediaType
|
|
3851
3830
|
});
|
|
3852
3831
|
const formData = new FormData();
|
|
3853
|
-
if (
|
|
3832
|
+
if (xaiOptions?.expiresAfter != null) {
|
|
3854
3833
|
formData.append("expires_after", String(xaiOptions.expiresAfter));
|
|
3855
3834
|
}
|
|
3856
|
-
if (
|
|
3835
|
+
if (xaiOptions?.teamId != null) {
|
|
3857
3836
|
formData.append("team_id", xaiOptions.teamId);
|
|
3858
3837
|
}
|
|
3859
3838
|
if (filename != null) {
|
|
@@ -3876,7 +3855,7 @@ var XaiFiles = class {
|
|
|
3876
3855
|
return {
|
|
3877
3856
|
warnings: [],
|
|
3878
3857
|
providerReference: { xai: response.id },
|
|
3879
|
-
...
|
|
3858
|
+
...response.filename ?? filename ? { filename: response.filename ?? filename } : {},
|
|
3880
3859
|
...mediaType != null ? { mediaType } : {},
|
|
3881
3860
|
...response.bytes != null ? { byteSize: response.bytes } : {},
|
|
3882
3861
|
...response.created_at != null ? { createdAt: new Date(response.created_at * 1e3) } : {},
|
|
@@ -3920,7 +3899,6 @@ var XaiFiles = class {
|
|
|
3920
3899
|
abortSignal,
|
|
3921
3900
|
headers
|
|
3922
3901
|
}) {
|
|
3923
|
-
var _a;
|
|
3924
3902
|
const fileId = this.getFileId(file);
|
|
3925
3903
|
const { value: content, responseHeaders } = await getFromApi3({
|
|
3926
3904
|
url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}/content`,
|
|
@@ -3931,7 +3909,7 @@ var XaiFiles = class {
|
|
|
3931
3909
|
fetch: this.config.fetch,
|
|
3932
3910
|
validateUrl: false
|
|
3933
3911
|
});
|
|
3934
|
-
const mediaType =
|
|
3912
|
+
const mediaType = responseHeaders?.["content-type"]?.split(";")[0].trim();
|
|
3935
3913
|
return {
|
|
3936
3914
|
warnings: [],
|
|
3937
3915
|
content,
|
|
@@ -4041,16 +4019,13 @@ var RESOLUTION_MAP = {
|
|
|
4041
4019
|
"640x480": "480p"
|
|
4042
4020
|
};
|
|
4043
4021
|
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;
|
|
4022
|
+
return options.frameImages?.find((frame) => frame.frameType === "first_frame")?.image;
|
|
4046
4023
|
}
|
|
4047
4024
|
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;
|
|
4025
|
+
return options.frameImages?.find((frame) => frame.frameType === "last_frame")?.image;
|
|
4050
4026
|
}
|
|
4051
4027
|
function resolveStartImage(options) {
|
|
4052
|
-
|
|
4053
|
-
return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
|
|
4028
|
+
return getFirstFrameImage(options) ?? options.image;
|
|
4054
4029
|
}
|
|
4055
4030
|
var isVideoFile = (file) => file.mediaType != null && getTopLevelMediaType2(file.mediaType) === "video";
|
|
4056
4031
|
var isImageReference = (file) => file.mediaType == null || getTopLevelMediaType2(file.mediaType) === "image";
|
|
@@ -4081,31 +4056,28 @@ function resolveReferences(options, xaiOptions, warnings) {
|
|
|
4081
4056
|
}
|
|
4082
4057
|
return imageFiles.length > 0 ? imageFiles.map((reference) => ({ url: fileToXaiUrl(reference) })) : void 0;
|
|
4083
4058
|
}
|
|
4084
|
-
if (
|
|
4059
|
+
if (xaiOptions?.referenceImageUrls != null && xaiOptions.referenceImageUrls.length > 0) {
|
|
4085
4060
|
return xaiOptions.referenceImageUrls.map((url) => ({ url }));
|
|
4086
4061
|
}
|
|
4087
4062
|
}
|
|
4088
4063
|
function resolveReferenceAudios(options) {
|
|
4089
|
-
|
|
4090
|
-
const audioReferences = (_a = options.inputReferences) == null ? void 0 : _a.filter(isAudioReference);
|
|
4064
|
+
const audioReferences = options.inputReferences?.filter(isAudioReference);
|
|
4091
4065
|
return audioReferences != null && audioReferences.length > 0 ? audioReferences.map((reference) => ({ url: fileToXaiUrl(reference) })) : void 0;
|
|
4092
4066
|
}
|
|
4093
4067
|
function hasImageInputReference(options) {
|
|
4094
|
-
|
|
4095
|
-
return (_b = (_a = options.inputReferences) == null ? void 0 : _a.some(isImageReference)) != null ? _b : false;
|
|
4068
|
+
return options.inputReferences?.some(isImageReference) ?? false;
|
|
4096
4069
|
}
|
|
4097
4070
|
function hasAudioInputReference(options) {
|
|
4098
|
-
|
|
4099
|
-
return (_b = (_a = options.inputReferences) == null ? void 0 : _a.some(isAudioReference)) != null ? _b : false;
|
|
4071
|
+
return options.inputReferences?.some(isAudioReference) ?? false;
|
|
4100
4072
|
}
|
|
4101
4073
|
function resolveVideoMode(options, xaiOptions) {
|
|
4102
|
-
if (
|
|
4074
|
+
if (xaiOptions?.mode != null) {
|
|
4103
4075
|
return xaiOptions.mode;
|
|
4104
4076
|
}
|
|
4105
|
-
if (
|
|
4077
|
+
if (xaiOptions?.videoUrl != null) {
|
|
4106
4078
|
return "edit-video";
|
|
4107
4079
|
}
|
|
4108
|
-
const hasLegacyReferenceUrls =
|
|
4080
|
+
const hasLegacyReferenceUrls = xaiOptions?.referenceImageUrls != null && xaiOptions.referenceImageUrls.length > 0;
|
|
4109
4081
|
if (hasImageInputReference(options) || hasAudioInputReference(options) || hasLegacyReferenceUrls) {
|
|
4110
4082
|
return "reference-to-video";
|
|
4111
4083
|
}
|
|
@@ -4166,7 +4138,7 @@ var XaiVideoModel = class {
|
|
|
4166
4138
|
details: "xAI video editing does not support custom aspect ratio."
|
|
4167
4139
|
});
|
|
4168
4140
|
}
|
|
4169
|
-
if (isEdit && (
|
|
4141
|
+
if (isEdit && (xaiOptions?.resolution != null || options.resolution != null)) {
|
|
4170
4142
|
warnings.push({
|
|
4171
4143
|
type: "unsupported",
|
|
4172
4144
|
feature: "resolution",
|
|
@@ -4180,7 +4152,7 @@ var XaiVideoModel = class {
|
|
|
4180
4152
|
details: "xAI video extension does not support custom aspect ratio."
|
|
4181
4153
|
});
|
|
4182
4154
|
}
|
|
4183
|
-
if (isExtension && (
|
|
4155
|
+
if (isExtension && (xaiOptions?.resolution != null || options.resolution != null)) {
|
|
4184
4156
|
warnings.push({
|
|
4185
4157
|
type: "unsupported",
|
|
4186
4158
|
feature: "resolution",
|
|
@@ -4200,7 +4172,7 @@ var XaiVideoModel = class {
|
|
|
4200
4172
|
if (allowAspectRatio && options.aspectRatio != null) {
|
|
4201
4173
|
body.aspect_ratio = options.aspectRatio;
|
|
4202
4174
|
}
|
|
4203
|
-
if (allowResolution &&
|
|
4175
|
+
if (allowResolution && xaiOptions?.resolution != null) {
|
|
4204
4176
|
body.resolution = xaiOptions.resolution;
|
|
4205
4177
|
} else if (allowResolution && options.resolution != null) {
|
|
4206
4178
|
const mapped = RESOLUTION_MAP[options.resolution];
|
|
@@ -4223,7 +4195,7 @@ var XaiVideoModel = class {
|
|
|
4223
4195
|
details: `xAI ${isEdit ? "video editing" : "video extension"} does not support generateAudio.`
|
|
4224
4196
|
});
|
|
4225
4197
|
}
|
|
4226
|
-
if (
|
|
4198
|
+
if (xaiOptions?.storageOptions != null) {
|
|
4227
4199
|
const { filename, expiresAfter, publicUrl } = xaiOptions.storageOptions;
|
|
4228
4200
|
body.storage_options = {
|
|
4229
4201
|
filename,
|
|
@@ -4235,7 +4207,7 @@ var XaiVideoModel = class {
|
|
|
4235
4207
|
} : {}
|
|
4236
4208
|
};
|
|
4237
4209
|
}
|
|
4238
|
-
if (
|
|
4210
|
+
if (xaiOptions?.keyframes != null && xaiOptions.keyframes.length > 0) {
|
|
4239
4211
|
if (this.modelId !== "grok-imagine-video-1.5" || isEdit || isExtension) {
|
|
4240
4212
|
warnings.push({
|
|
4241
4213
|
type: "unsupported",
|
|
@@ -4292,13 +4264,13 @@ var XaiVideoModel = class {
|
|
|
4292
4264
|
details: "xAI reference-to-video requires at least one image reference. The video will be generated without reference images."
|
|
4293
4265
|
});
|
|
4294
4266
|
}
|
|
4295
|
-
const referenceVoiceIds = xaiOptions
|
|
4296
|
-
const referenceVoices = referenceVoiceIds
|
|
4267
|
+
const referenceVoiceIds = xaiOptions?.referenceVoiceIds;
|
|
4268
|
+
const referenceVoices = referenceVoiceIds?.map((voiceId) => ({
|
|
4297
4269
|
voice_id: voiceId
|
|
4298
4270
|
}));
|
|
4299
4271
|
const referenceAudioInputs = [
|
|
4300
|
-
...referenceAudios
|
|
4301
|
-
...referenceVoices
|
|
4272
|
+
...referenceAudios ?? [],
|
|
4273
|
+
...referenceVoices ?? []
|
|
4302
4274
|
];
|
|
4303
4275
|
if (referenceAudioInputs.length > 0) {
|
|
4304
4276
|
if (referenceAudioInputs.length > 3) {
|
|
@@ -4333,14 +4305,14 @@ var XaiVideoModel = class {
|
|
|
4333
4305
|
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
4306
|
});
|
|
4335
4307
|
}
|
|
4336
|
-
if (
|
|
4308
|
+
if (xaiOptions?.referenceVoiceIds != null && xaiOptions.referenceVoiceIds.length > 0 && !hasReferenceImages) {
|
|
4337
4309
|
warnings.push({
|
|
4338
4310
|
type: "unsupported",
|
|
4339
4311
|
feature: "referenceVoiceIds",
|
|
4340
4312
|
details: "xAI only supports reference voices for reference-to-video generation. The reference voices were ignored."
|
|
4341
4313
|
});
|
|
4342
4314
|
}
|
|
4343
|
-
if (!isExtension &&
|
|
4315
|
+
if (!isExtension && xaiOptions?.user !== void 0) {
|
|
4344
4316
|
body.user = xaiOptions.user;
|
|
4345
4317
|
}
|
|
4346
4318
|
if (xaiOptions != null) {
|
|
@@ -4372,10 +4344,9 @@ var XaiVideoModel = class {
|
|
|
4372
4344
|
};
|
|
4373
4345
|
}
|
|
4374
4346
|
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();
|
|
4347
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4377
4348
|
const { body, warnings, isEdit, isExtension } = await this.buildRequestBody(options);
|
|
4378
|
-
const baseURL =
|
|
4349
|
+
const baseURL = this.config.baseURL ?? "https://api.x.ai/v1";
|
|
4379
4350
|
let endpoint;
|
|
4380
4351
|
if (isEdit) {
|
|
4381
4352
|
endpoint = `${baseURL}/videos/edits`;
|
|
@@ -4413,10 +4384,9 @@ var XaiVideoModel = class {
|
|
|
4413
4384
|
};
|
|
4414
4385
|
}
|
|
4415
4386
|
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();
|
|
4387
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4418
4388
|
const { requestId } = options.operation;
|
|
4419
|
-
const baseURL =
|
|
4389
|
+
const baseURL = this.config.baseURL ?? "https://api.x.ai/v1";
|
|
4420
4390
|
const { value: statusResponse, responseHeaders } = await getFromApi4({
|
|
4421
4391
|
url: `${baseURL}/videos/${encodePathSegment2(requestId)}`,
|
|
4422
4392
|
validateUrl: false,
|
|
@@ -4438,7 +4408,7 @@ var XaiVideoModel = class {
|
|
|
4438
4408
|
};
|
|
4439
4409
|
}
|
|
4440
4410
|
if (statusResponse.status === "failed") {
|
|
4441
|
-
const errorDetails =
|
|
4411
|
+
const errorDetails = statusResponse.error?.message ?? statusResponse.error?.code;
|
|
4442
4412
|
return {
|
|
4443
4413
|
status: "error",
|
|
4444
4414
|
error: errorDetails != null ? `Video generation failed: ${errorDetails}` : "Video generation failed.",
|
|
@@ -4449,9 +4419,9 @@ var XaiVideoModel = class {
|
|
|
4449
4419
|
}
|
|
4450
4420
|
};
|
|
4451
4421
|
}
|
|
4452
|
-
if (statusResponse.status === "done" || statusResponse.status == null &&
|
|
4422
|
+
if (statusResponse.status === "done" || statusResponse.status == null && statusResponse.video?.url) {
|
|
4453
4423
|
const video = statusResponse.video;
|
|
4454
|
-
if (
|
|
4424
|
+
if (video?.respect_moderation === false) {
|
|
4455
4425
|
return {
|
|
4456
4426
|
status: "error",
|
|
4457
4427
|
error: "Video generation was blocked due to a content policy violation.",
|
|
@@ -4462,7 +4432,7 @@ var XaiVideoModel = class {
|
|
|
4462
4432
|
}
|
|
4463
4433
|
};
|
|
4464
4434
|
}
|
|
4465
|
-
const videoUrl =
|
|
4435
|
+
const videoUrl = video?.url ?? video?.file_output?.public_url ?? void 0;
|
|
4466
4436
|
if (!videoUrl) {
|
|
4467
4437
|
return {
|
|
4468
4438
|
status: "error",
|
|
@@ -4487,10 +4457,10 @@ var XaiVideoModel = class {
|
|
|
4487
4457
|
xai: {
|
|
4488
4458
|
requestId,
|
|
4489
4459
|
videoUrl,
|
|
4490
|
-
...
|
|
4491
|
-
...
|
|
4460
|
+
...video?.duration != null ? { duration: video.duration } : {},
|
|
4461
|
+
...statusResponse.usage?.cost_in_usd_ticks != null ? { costInUsdTicks: statusResponse.usage.cost_in_usd_ticks } : {},
|
|
4492
4462
|
...statusResponse.progress != null ? { progress: statusResponse.progress } : {},
|
|
4493
|
-
...
|
|
4463
|
+
...video?.file_output != null ? {
|
|
4494
4464
|
fileOutput: {
|
|
4495
4465
|
fileId: video.file_output.file_id,
|
|
4496
4466
|
filename: video.file_output.filename,
|
|
@@ -4508,7 +4478,7 @@ var XaiVideoModel = class {
|
|
|
4508
4478
|
} : {}
|
|
4509
4479
|
}
|
|
4510
4480
|
} : {},
|
|
4511
|
-
...
|
|
4481
|
+
...video?.storage_error != null ? { storageError: video.storage_error } : {}
|
|
4512
4482
|
}
|
|
4513
4483
|
}
|
|
4514
4484
|
};
|
|
@@ -4737,10 +4707,10 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
4737
4707
|
const output_format = {
|
|
4738
4708
|
codec
|
|
4739
4709
|
};
|
|
4740
|
-
if (
|
|
4710
|
+
if (xaiOptions?.sampleRate != null) {
|
|
4741
4711
|
output_format.sample_rate = xaiOptions.sampleRate;
|
|
4742
4712
|
}
|
|
4743
|
-
if (
|
|
4713
|
+
if (xaiOptions?.bitRate != null) {
|
|
4744
4714
|
if (codec === "mp3") {
|
|
4745
4715
|
output_format.bit_rate = xaiOptions.bitRate;
|
|
4746
4716
|
} else {
|
|
@@ -4757,20 +4727,19 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
4757
4727
|
language,
|
|
4758
4728
|
output_format,
|
|
4759
4729
|
speed,
|
|
4760
|
-
optimize_streaming_latency: xaiOptions
|
|
4761
|
-
text_normalization: xaiOptions
|
|
4762
|
-
with_timestamps: xaiOptions
|
|
4763
|
-
replace: xaiOptions
|
|
4730
|
+
optimize_streaming_latency: xaiOptions?.optimizeStreamingLatency,
|
|
4731
|
+
text_normalization: xaiOptions?.textNormalization,
|
|
4732
|
+
with_timestamps: xaiOptions?.withTimestamps,
|
|
4733
|
+
replace: xaiOptions?.replace
|
|
4764
4734
|
};
|
|
4765
4735
|
return {
|
|
4766
4736
|
requestBody,
|
|
4767
4737
|
warnings,
|
|
4768
|
-
withTimestamps:
|
|
4738
|
+
withTimestamps: xaiOptions?.withTimestamps === true
|
|
4769
4739
|
};
|
|
4770
4740
|
}
|
|
4771
4741
|
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();
|
|
4742
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4774
4743
|
const { requestBody, warnings, withTimestamps } = await this.getArgs(options);
|
|
4775
4744
|
const { value, responseHeaders, rawValue } = await postJsonToApi5({
|
|
4776
4745
|
url: `${this.config.baseURL}/tts`,
|
|
@@ -4792,7 +4761,7 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
4792
4761
|
envelope = value;
|
|
4793
4762
|
audio = envelope.audio != null ? convertBase64ToUint8Array2(envelope.audio) : new Uint8Array(0);
|
|
4794
4763
|
}
|
|
4795
|
-
const traceId = responseHeaders
|
|
4764
|
+
const traceId = responseHeaders?.["x-trace-id"];
|
|
4796
4765
|
return {
|
|
4797
4766
|
audio,
|
|
4798
4767
|
warnings,
|
|
@@ -4808,9 +4777,9 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
4808
4777
|
providerMetadata: {
|
|
4809
4778
|
xai: {
|
|
4810
4779
|
...traceId != null ? { traceId } : {},
|
|
4811
|
-
...
|
|
4812
|
-
...
|
|
4813
|
-
...
|
|
4780
|
+
...envelope?.duration != null ? { duration: envelope.duration } : {},
|
|
4781
|
+
...envelope?.content_type != null ? { contentType: envelope.content_type } : {},
|
|
4782
|
+
...envelope?.audio_timestamps != null ? {
|
|
4814
4783
|
audioTimestamps: {
|
|
4815
4784
|
graphChars: envelope.audio_timestamps.graph_chars,
|
|
4816
4785
|
graphTimes: envelope.audio_timestamps.graph_times
|
|
@@ -4961,21 +4930,21 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
4961
4930
|
});
|
|
4962
4931
|
const formData = new FormData();
|
|
4963
4932
|
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
|
|
4933
|
+
audio_format: xaiOptions?.audioFormat,
|
|
4934
|
+
sample_rate: xaiOptions?.sampleRate,
|
|
4935
|
+
language: xaiOptions?.language,
|
|
4936
|
+
format: xaiOptions?.format,
|
|
4937
|
+
multichannel: xaiOptions?.multichannel,
|
|
4938
|
+
channels: xaiOptions?.channels,
|
|
4939
|
+
diarize: xaiOptions?.diarize,
|
|
4940
|
+
filler_words: xaiOptions?.fillerWords
|
|
4972
4941
|
};
|
|
4973
4942
|
for (const [key, value] of Object.entries(transcriptionOptions)) {
|
|
4974
4943
|
if (value != null) {
|
|
4975
4944
|
formData.append(key, String(value));
|
|
4976
4945
|
}
|
|
4977
4946
|
}
|
|
4978
|
-
if (
|
|
4947
|
+
if (xaiOptions?.keyterm != null) {
|
|
4979
4948
|
const keyterms = Array.isArray(xaiOptions.keyterm) ? xaiOptions.keyterm : [xaiOptions.keyterm];
|
|
4980
4949
|
for (const keyterm of keyterms) {
|
|
4981
4950
|
formData.append("keyterm", keyterm);
|
|
@@ -4991,16 +4960,15 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
4991
4960
|
return { formData, warnings };
|
|
4992
4961
|
}
|
|
4993
4962
|
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();
|
|
4963
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
4996
4964
|
const { formData, warnings } = await this.getArgs(options);
|
|
4997
4965
|
const {
|
|
4998
4966
|
value: response,
|
|
4999
4967
|
responseHeaders,
|
|
5000
4968
|
rawValue: rawResponse
|
|
5001
4969
|
} = await postFormDataToApi3({
|
|
5002
|
-
url: `${
|
|
5003
|
-
headers: combineHeaders7(
|
|
4970
|
+
url: `${this.config.baseURL ?? "https://api.x.ai/v1"}/stt`,
|
|
4971
|
+
headers: combineHeaders7(this.config.headers?.(), options.headers),
|
|
5004
4972
|
formData,
|
|
5005
4973
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
5006
4974
|
successfulResponseHandler: createJsonResponseHandler7(
|
|
@@ -5011,13 +4979,13 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5011
4979
|
});
|
|
5012
4980
|
return {
|
|
5013
4981
|
text: response.text,
|
|
5014
|
-
segments:
|
|
4982
|
+
segments: response.words?.map((word) => ({
|
|
5015
4983
|
text: word.text,
|
|
5016
4984
|
startSecond: word.start,
|
|
5017
4985
|
endSecond: word.end
|
|
5018
|
-
}))
|
|
4986
|
+
})) ?? [],
|
|
5019
4987
|
language: response.language || void 0,
|
|
5020
|
-
durationInSeconds:
|
|
4988
|
+
durationInSeconds: response.duration ?? void 0,
|
|
5021
4989
|
warnings,
|
|
5022
4990
|
response: {
|
|
5023
4991
|
timestamp: currentDate,
|
|
@@ -5028,39 +4996,38 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5028
4996
|
};
|
|
5029
4997
|
}
|
|
5030
4998
|
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();
|
|
4999
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
5033
5000
|
const warnings = [];
|
|
5034
5001
|
const xaiOptions = await parseProviderOptions8({
|
|
5035
5002
|
provider: "xai",
|
|
5036
5003
|
providerOptions: options.providerOptions,
|
|
5037
5004
|
schema: xaiTranscriptionModelOptionsSchema
|
|
5038
5005
|
});
|
|
5039
|
-
if (
|
|
5006
|
+
if (xaiOptions?.multichannel === true && xaiOptions.channels == null) {
|
|
5040
5007
|
throw new InvalidArgumentError3({
|
|
5041
5008
|
argument: "providerOptions",
|
|
5042
5009
|
message: "providerOptions.xai.channels is required when providerOptions.xai.multichannel is true"
|
|
5043
5010
|
});
|
|
5044
5011
|
}
|
|
5045
|
-
if (
|
|
5012
|
+
if (xaiOptions?.format != null) {
|
|
5046
5013
|
warnings.push({
|
|
5047
5014
|
type: "unsupported",
|
|
5048
5015
|
feature: "providerOptions.xai.format",
|
|
5049
5016
|
details: "xAI streaming transcription does not support format."
|
|
5050
5017
|
});
|
|
5051
5018
|
}
|
|
5052
|
-
if (
|
|
5019
|
+
if (xaiOptions?.audioFormat == null && !isKnownInputAudioFormat(options.inputAudioFormat.type)) {
|
|
5053
5020
|
warnings.push({
|
|
5054
5021
|
type: "other",
|
|
5055
5022
|
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
5023
|
});
|
|
5057
5024
|
}
|
|
5058
5025
|
const url = buildXaiStreamingTranscriptionUrl({
|
|
5059
|
-
baseURL:
|
|
5026
|
+
baseURL: this.config.baseURL ?? "https://api.x.ai/v1",
|
|
5060
5027
|
inputAudioFormat: options.inputAudioFormat,
|
|
5061
5028
|
providerOptions: xaiOptions
|
|
5062
5029
|
});
|
|
5063
|
-
const headers = combineHeaders7(
|
|
5030
|
+
const headers = combineHeaders7(this.config.headers?.(), options.headers);
|
|
5064
5031
|
return {
|
|
5065
5032
|
request: { body: url.toString() },
|
|
5066
5033
|
response: {
|
|
@@ -5072,8 +5039,8 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5072
5039
|
url,
|
|
5073
5040
|
headers,
|
|
5074
5041
|
warnings,
|
|
5075
|
-
language:
|
|
5076
|
-
expectedDoneCount:
|
|
5042
|
+
language: xaiOptions?.language ?? void 0,
|
|
5043
|
+
expectedDoneCount: xaiOptions?.multichannel === true ? xaiOptions.channels : 1,
|
|
5077
5044
|
audio: options.audio,
|
|
5078
5045
|
abortSignal: options.abortSignal,
|
|
5079
5046
|
includeRawChunks: options.includeRawChunks
|
|
@@ -5111,7 +5078,7 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5111
5078
|
void audio.cancel().catch(() => {
|
|
5112
5079
|
});
|
|
5113
5080
|
}
|
|
5114
|
-
connection
|
|
5081
|
+
connection?.close(closeCode);
|
|
5115
5082
|
};
|
|
5116
5083
|
const finishWithError = (error) => {
|
|
5117
5084
|
if (finished) return;
|
|
@@ -5160,7 +5127,6 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5160
5127
|
onAbort: finishWithError,
|
|
5161
5128
|
onProcessingError: finishWithError,
|
|
5162
5129
|
onMessageText: async (text) => {
|
|
5163
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
5164
5130
|
const parsed = await safeParseJSON2({ text });
|
|
5165
5131
|
if (!parsed.success) return;
|
|
5166
5132
|
const raw = parsed.value;
|
|
@@ -5170,7 +5136,7 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5170
5136
|
switch (raw.type) {
|
|
5171
5137
|
case "transcript.created": {
|
|
5172
5138
|
controller.enqueue({ type: "stream-start", warnings });
|
|
5173
|
-
const socket = connection
|
|
5139
|
+
const socket = connection?.socket;
|
|
5174
5140
|
if (socket == null) {
|
|
5175
5141
|
finishWithError(new Error("WebSocket is not connected."));
|
|
5176
5142
|
break;
|
|
@@ -5180,12 +5146,12 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5180
5146
|
}
|
|
5181
5147
|
case "transcript.partial": {
|
|
5182
5148
|
const id = channelId(raw.channel_index);
|
|
5183
|
-
const channelIndex =
|
|
5149
|
+
const channelIndex = raw.channel_index ?? 0;
|
|
5184
5150
|
if (raw.is_final && raw.speech_final) {
|
|
5185
5151
|
const timing = timingFromXaiEvent(raw);
|
|
5186
5152
|
if (raw.text) {
|
|
5187
5153
|
finalizedTexts.set(channelIndex, [
|
|
5188
|
-
...
|
|
5154
|
+
...finalizedTexts.get(channelIndex) ?? [],
|
|
5189
5155
|
raw.text
|
|
5190
5156
|
]);
|
|
5191
5157
|
}
|
|
@@ -5193,16 +5159,16 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5193
5159
|
controller.enqueue({
|
|
5194
5160
|
type: "transcript-final",
|
|
5195
5161
|
id,
|
|
5196
|
-
text:
|
|
5162
|
+
text: raw.text ?? "",
|
|
5197
5163
|
...timing,
|
|
5198
5164
|
channelIndex: raw.channel_index
|
|
5199
5165
|
});
|
|
5200
5166
|
} else {
|
|
5201
|
-
pendingTexts.set(channelIndex,
|
|
5167
|
+
pendingTexts.set(channelIndex, raw.text ?? "");
|
|
5202
5168
|
controller.enqueue({
|
|
5203
5169
|
type: "transcript-partial",
|
|
5204
5170
|
id,
|
|
5205
|
-
text:
|
|
5171
|
+
text: raw.text ?? "",
|
|
5206
5172
|
startSecond: raw.start,
|
|
5207
5173
|
durationInSeconds: raw.duration,
|
|
5208
5174
|
channelIndex: raw.channel_index
|
|
@@ -5211,18 +5177,18 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5211
5177
|
break;
|
|
5212
5178
|
}
|
|
5213
5179
|
case "transcript.done": {
|
|
5214
|
-
const channelIndex =
|
|
5180
|
+
const channelIndex = raw.channel_index ?? 0;
|
|
5215
5181
|
const accumulated = [
|
|
5216
|
-
...
|
|
5182
|
+
...finalizedTexts.get(channelIndex) ?? [],
|
|
5217
5183
|
...pendingTexts.get(channelIndex) ? [pendingTexts.get(channelIndex)] : []
|
|
5218
5184
|
].join(" ");
|
|
5219
5185
|
doneTexts.set(channelIndex, raw.text || accumulated);
|
|
5220
|
-
doneDuration =
|
|
5186
|
+
doneDuration = raw.duration ?? doneDuration;
|
|
5221
5187
|
maybeFinish();
|
|
5222
5188
|
break;
|
|
5223
5189
|
}
|
|
5224
5190
|
case "error": {
|
|
5225
|
-
finishWithError(new Error(
|
|
5191
|
+
finishWithError(new Error(raw.message ?? "xAI STT error"));
|
|
5226
5192
|
break;
|
|
5227
5193
|
}
|
|
5228
5194
|
}
|
|
@@ -5254,40 +5220,39 @@ function buildXaiStreamingTranscriptionUrl({
|
|
|
5254
5220
|
inputAudioFormat,
|
|
5255
5221
|
providerOptions
|
|
5256
5222
|
}) {
|
|
5257
|
-
var _a, _b, _c, _d, _e, _f;
|
|
5258
5223
|
const url = toWebSocketUrl(`${baseURL}/stt`);
|
|
5259
5224
|
appendSearchParam(
|
|
5260
5225
|
url,
|
|
5261
5226
|
"sample_rate",
|
|
5262
|
-
|
|
5227
|
+
providerOptions?.sampleRate ?? inputAudioFormat.rate
|
|
5263
5228
|
);
|
|
5264
5229
|
appendSearchParam(
|
|
5265
5230
|
url,
|
|
5266
5231
|
"encoding",
|
|
5267
|
-
|
|
5232
|
+
providerOptions?.audioFormat ?? encodingFromInputAudioFormat(inputAudioFormat.type)
|
|
5268
5233
|
);
|
|
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
|
|
5234
|
+
appendSearchParam(url, "language", providerOptions?.language);
|
|
5235
|
+
appendSearchParam(url, "diarize", providerOptions?.diarize);
|
|
5236
|
+
appendSearchParam(url, "filler_words", providerOptions?.fillerWords);
|
|
5237
|
+
appendSearchParam(url, "multichannel", providerOptions?.multichannel);
|
|
5238
|
+
appendSearchParam(url, "channels", providerOptions?.channels);
|
|
5274
5239
|
appendSearchParam(
|
|
5275
5240
|
url,
|
|
5276
5241
|
"interim_results",
|
|
5277
|
-
|
|
5242
|
+
providerOptions?.streaming?.interimResults
|
|
5278
5243
|
);
|
|
5279
5244
|
appendSearchParam(
|
|
5280
5245
|
url,
|
|
5281
5246
|
"endpointing",
|
|
5282
|
-
|
|
5247
|
+
providerOptions?.streaming?.endpointing
|
|
5283
5248
|
);
|
|
5284
|
-
appendSearchParam(url, "smart_turn",
|
|
5249
|
+
appendSearchParam(url, "smart_turn", providerOptions?.streaming?.smartTurn);
|
|
5285
5250
|
appendSearchParam(
|
|
5286
5251
|
url,
|
|
5287
5252
|
"smart_turn_timeout",
|
|
5288
|
-
|
|
5253
|
+
providerOptions?.streaming?.smartTurnTimeout
|
|
5289
5254
|
);
|
|
5290
|
-
if (
|
|
5255
|
+
if (providerOptions?.keyterm != null) {
|
|
5291
5256
|
const keyterms = Array.isArray(providerOptions.keyterm) ? providerOptions.keyterm : [providerOptions.keyterm];
|
|
5292
5257
|
for (const keyterm of keyterms) {
|
|
5293
5258
|
url.searchParams.append("keyterm", keyterm);
|
|
@@ -5337,9 +5302,8 @@ var xaiTranscriptionResponseSchema = z23.object({
|
|
|
5337
5302
|
|
|
5338
5303
|
// src/xai-provider.ts
|
|
5339
5304
|
function createXai(options = {}) {
|
|
5340
|
-
var _a;
|
|
5341
5305
|
const baseURL = withoutTrailingSlash(
|
|
5342
|
-
|
|
5306
|
+
options.baseURL ?? "https://api.x.ai/v1"
|
|
5343
5307
|
);
|
|
5344
5308
|
const getHeaders = () => withUserAgentSuffix(
|
|
5345
5309
|
{
|
|
@@ -5380,7 +5344,7 @@ function createXai(options = {}) {
|
|
|
5380
5344
|
const createRealtimeModel = (modelId) => {
|
|
5381
5345
|
return new XaiRealtimeModel(modelId, {
|
|
5382
5346
|
provider: "xai.realtime",
|
|
5383
|
-
baseURL: baseURL
|
|
5347
|
+
baseURL: baseURL ?? "https://api.x.ai/v1",
|
|
5384
5348
|
headers: getHeaders,
|
|
5385
5349
|
fetch: options.fetch
|
|
5386
5350
|
});
|