@ai-sdk/xai 4.0.58 → 5.0.0
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 +16 -0
- package/dist/index.d.ts +5 -61
- package/dist/index.js +909 -1811
- package/dist/index.js.map +1 -1
- package/docs/01-xai.mdx +2 -12
- package/package.json +3 -3
- package/src/index.ts +0 -5
- package/src/responses/xai-responses-prepare-tools.ts +1 -2
- package/src/xai-batch.ts +86 -12
- package/src/xai-error.ts +2 -2
- package/src/xai-provider.ts +0 -18
- package/src/convert-to-xai-chat-messages.ts +0 -181
- package/src/convert-xai-chat-usage.ts +0 -29
- package/src/remove-additional-properties.ts +0 -24
- package/src/xai-chat-language-model-options.ts +0 -141
- package/src/xai-chat-language-model.ts +0 -778
- package/src/xai-chat-prompt.ts +0 -48
- package/src/xai-prepare-tools.ts +0 -99
package/dist/index.js
CHANGED
|
@@ -9,1071 +9,64 @@ import {
|
|
|
9
9
|
withUserAgentSuffix
|
|
10
10
|
} from "@ai-sdk/provider-utils";
|
|
11
11
|
|
|
12
|
-
// src/xai-chat-language-model.ts
|
|
13
|
-
import {
|
|
14
|
-
APICallError
|
|
15
|
-
} from "@ai-sdk/provider";
|
|
16
|
-
import {
|
|
17
|
-
combineHeaders,
|
|
18
|
-
createEventSourceResponseHandler,
|
|
19
|
-
createJsonResponseHandler,
|
|
20
|
-
extractResponseHeaders,
|
|
21
|
-
isCustomReasoning,
|
|
22
|
-
mapReasoningToProviderEffort,
|
|
23
|
-
parseProviderOptions as parseProviderOptions2,
|
|
24
|
-
postJsonToApi,
|
|
25
|
-
safeParseJSON,
|
|
26
|
-
serializeModelOptions,
|
|
27
|
-
WORKFLOW_SERIALIZE,
|
|
28
|
-
WORKFLOW_DESERIALIZE
|
|
29
|
-
} from "@ai-sdk/provider-utils";
|
|
30
|
-
import { z as z4 } from "zod/v4";
|
|
31
|
-
|
|
32
|
-
// src/convert-to-xai-chat-messages.ts
|
|
33
|
-
import {
|
|
34
|
-
UnsupportedFunctionalityError
|
|
35
|
-
} from "@ai-sdk/provider";
|
|
36
|
-
import {
|
|
37
|
-
convertToBase64,
|
|
38
|
-
getTopLevelMediaType,
|
|
39
|
-
parseProviderOptions,
|
|
40
|
-
resolveFullMediaType,
|
|
41
|
-
resolveProviderReference
|
|
42
|
-
} from "@ai-sdk/provider-utils";
|
|
43
|
-
|
|
44
|
-
// src/xai-file-part-options.ts
|
|
45
|
-
import { z } from "zod/v4";
|
|
46
|
-
var xaiFilePartProviderOptions = z.object({
|
|
47
|
-
/**
|
|
48
|
-
* Controls the resolution at which the model processes the image.
|
|
49
|
-
* `low` processes the image at reduced resolution and consumes fewer
|
|
50
|
-
* input tokens, `high` processes the image at full resolution, and
|
|
51
|
-
* `auto` lets the API decide. Defaults to full resolution when not set.
|
|
52
|
-
*
|
|
53
|
-
* Note: the xAI API silently ignores invalid values, so the value is
|
|
54
|
-
* validated client-side.
|
|
55
|
-
*
|
|
56
|
-
* @see https://docs.x.ai/developers/model-capabilities/images/understanding
|
|
57
|
-
*/
|
|
58
|
-
imageDetail: z.enum(["low", "high", "auto"]).optional()
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// src/convert-to-xai-chat-messages.ts
|
|
62
|
-
async function convertToXaiChatMessages(prompt) {
|
|
63
|
-
var _a;
|
|
64
|
-
const messages = [];
|
|
65
|
-
const warnings = [];
|
|
66
|
-
for (const { role, content } of prompt) {
|
|
67
|
-
switch (role) {
|
|
68
|
-
case "system": {
|
|
69
|
-
messages.push({ role: "system", content });
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
case "user": {
|
|
73
|
-
if (content.length === 1 && content[0].type === "text") {
|
|
74
|
-
messages.push({ role: "user", content: content[0].text });
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
const userContent = [];
|
|
78
|
-
for (const part of content) {
|
|
79
|
-
switch (part.type) {
|
|
80
|
-
case "text": {
|
|
81
|
-
userContent.push({ type: "text", text: part.text });
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
case "file": {
|
|
85
|
-
switch (part.data.type) {
|
|
86
|
-
case "reference": {
|
|
87
|
-
userContent.push({
|
|
88
|
-
type: "file",
|
|
89
|
-
file: {
|
|
90
|
-
file_id: resolveProviderReference({
|
|
91
|
-
reference: part.data.reference,
|
|
92
|
-
provider: "xai"
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
case "text": {
|
|
99
|
-
throw new UnsupportedFunctionalityError({
|
|
100
|
-
functionality: "text file parts"
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
case "url":
|
|
104
|
-
case "data": {
|
|
105
|
-
if (getTopLevelMediaType(part.mediaType) === "image") {
|
|
106
|
-
const filePartOptions = await parseProviderOptions({
|
|
107
|
-
provider: "xai",
|
|
108
|
-
providerOptions: part.providerOptions,
|
|
109
|
-
schema: xaiFilePartProviderOptions
|
|
110
|
-
});
|
|
111
|
-
userContent.push({
|
|
112
|
-
type: "image_url",
|
|
113
|
-
image_url: {
|
|
114
|
-
url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`,
|
|
115
|
-
...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
|
|
116
|
-
detail: filePartOptions.imageDetail
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
} else {
|
|
121
|
-
throw new UnsupportedFunctionalityError({
|
|
122
|
-
functionality: `file part media type ${part.mediaType}`
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
messages.push({ role: "user", content: userContent });
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
case "assistant": {
|
|
136
|
-
let text = "";
|
|
137
|
-
const toolCalls = [];
|
|
138
|
-
for (const part of content) {
|
|
139
|
-
switch (part.type) {
|
|
140
|
-
case "text": {
|
|
141
|
-
text += part.text;
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
case "tool-call": {
|
|
145
|
-
toolCalls.push({
|
|
146
|
-
id: part.toolCallId,
|
|
147
|
-
type: "function",
|
|
148
|
-
function: {
|
|
149
|
-
name: part.toolName,
|
|
150
|
-
arguments: JSON.stringify(part.input)
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
messages.push({
|
|
158
|
-
role: "assistant",
|
|
159
|
-
content: text,
|
|
160
|
-
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
161
|
-
});
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
case "tool": {
|
|
165
|
-
for (const toolResponse of content) {
|
|
166
|
-
if (toolResponse.type === "tool-approval-response") {
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
const output = toolResponse.output;
|
|
170
|
-
let contentValue;
|
|
171
|
-
switch (output.type) {
|
|
172
|
-
case "text":
|
|
173
|
-
case "error-text":
|
|
174
|
-
contentValue = output.value;
|
|
175
|
-
break;
|
|
176
|
-
case "execution-denied":
|
|
177
|
-
contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
|
|
178
|
-
break;
|
|
179
|
-
case "content":
|
|
180
|
-
case "json":
|
|
181
|
-
case "error-json":
|
|
182
|
-
contentValue = JSON.stringify(output.value);
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
messages.push({
|
|
186
|
-
role: "tool",
|
|
187
|
-
tool_call_id: toolResponse.toolCallId,
|
|
188
|
-
content: contentValue
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
default: {
|
|
194
|
-
const _exhaustiveCheck = role;
|
|
195
|
-
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return { messages, warnings };
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// src/convert-xai-chat-usage.ts
|
|
203
|
-
function convertXaiChatUsage(usage) {
|
|
204
|
-
var _a, _b, _c, _d;
|
|
205
|
-
const cacheReadTokens = (_b = (_a = usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0;
|
|
206
|
-
const reasoningTokens = (_d = (_c = usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0;
|
|
207
|
-
const promptTokensIncludesCached = cacheReadTokens <= usage.prompt_tokens;
|
|
208
|
-
return {
|
|
209
|
-
inputTokens: {
|
|
210
|
-
total: promptTokensIncludesCached ? usage.prompt_tokens : usage.prompt_tokens + cacheReadTokens,
|
|
211
|
-
noCache: promptTokensIncludesCached ? usage.prompt_tokens - cacheReadTokens : usage.prompt_tokens,
|
|
212
|
-
cacheRead: cacheReadTokens,
|
|
213
|
-
cacheWrite: void 0
|
|
214
|
-
},
|
|
215
|
-
outputTokens: {
|
|
216
|
-
total: usage.completion_tokens + reasoningTokens,
|
|
217
|
-
text: usage.completion_tokens,
|
|
218
|
-
reasoning: reasoningTokens
|
|
219
|
-
},
|
|
220
|
-
raw: usage
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// src/get-response-metadata.ts
|
|
225
|
-
import { createLanguageModelResponseMetadata } from "@ai-sdk/provider-utils";
|
|
226
|
-
function getResponseMetadata({
|
|
227
|
-
id,
|
|
228
|
-
model,
|
|
229
|
-
created,
|
|
230
|
-
created_at
|
|
231
|
-
}) {
|
|
232
|
-
return createLanguageModelResponseMetadata({
|
|
233
|
-
id,
|
|
234
|
-
model,
|
|
235
|
-
created: created != null ? created : created_at
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// src/map-xai-finish-reason.ts
|
|
240
|
-
function mapXaiFinishReason(finishReason) {
|
|
241
|
-
switch (finishReason) {
|
|
242
|
-
case "stop":
|
|
243
|
-
return "stop";
|
|
244
|
-
case "length":
|
|
245
|
-
return "length";
|
|
246
|
-
case "tool_calls":
|
|
247
|
-
case "function_call":
|
|
248
|
-
return "tool-calls";
|
|
249
|
-
case "content_filter":
|
|
250
|
-
return "content-filter";
|
|
251
|
-
default:
|
|
252
|
-
return "other";
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// src/supports-reasoning-effort.ts
|
|
257
|
-
var modelsWithoutReasoningEffort = /^grok-4\.20(-\d{4})?-(non-)?reasoning$/;
|
|
258
|
-
function supportsReasoningEffort(modelId) {
|
|
259
|
-
return !modelsWithoutReasoningEffort.test(modelId);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// src/xai-chat-language-model-options.ts
|
|
263
|
-
import { z as z2 } from "zod/v4";
|
|
264
|
-
var webSourceSchema = z2.object({
|
|
265
|
-
type: z2.literal("web"),
|
|
266
|
-
country: z2.string().length(2).optional(),
|
|
267
|
-
excludedWebsites: z2.array(z2.string()).max(5).optional(),
|
|
268
|
-
allowedWebsites: z2.array(z2.string()).max(5).optional(),
|
|
269
|
-
safeSearch: z2.boolean().optional()
|
|
270
|
-
});
|
|
271
|
-
var xSourceSchema = z2.object({
|
|
272
|
-
type: z2.literal("x"),
|
|
273
|
-
excludedXHandles: z2.array(z2.string()).optional(),
|
|
274
|
-
includedXHandles: z2.array(z2.string()).optional(),
|
|
275
|
-
postFavoriteCount: z2.number().int().optional(),
|
|
276
|
-
postViewCount: z2.number().int().optional(),
|
|
277
|
-
/**
|
|
278
|
-
* @deprecated use `includedXHandles` instead
|
|
279
|
-
*/
|
|
280
|
-
xHandles: z2.array(z2.string()).optional()
|
|
281
|
-
});
|
|
282
|
-
var newsSourceSchema = z2.object({
|
|
283
|
-
type: z2.literal("news"),
|
|
284
|
-
country: z2.string().length(2).optional(),
|
|
285
|
-
excludedWebsites: z2.array(z2.string()).max(5).optional(),
|
|
286
|
-
safeSearch: z2.boolean().optional()
|
|
287
|
-
});
|
|
288
|
-
var rssSourceSchema = z2.object({
|
|
289
|
-
type: z2.literal("rss"),
|
|
290
|
-
links: z2.array(z2.string().url()).max(1)
|
|
291
|
-
// currently only supports one RSS link
|
|
292
|
-
});
|
|
293
|
-
var searchSourceSchema = z2.discriminatedUnion("type", [
|
|
294
|
-
webSourceSchema,
|
|
295
|
-
xSourceSchema,
|
|
296
|
-
newsSourceSchema,
|
|
297
|
-
rssSourceSchema
|
|
298
|
-
]);
|
|
299
|
-
var xaiLanguageModelChatOptions = z2.object({
|
|
300
|
-
/**
|
|
301
|
-
* Constrains how hard a reasoning model thinks before responding.
|
|
302
|
-
*
|
|
303
|
-
* - `none`: Disables reasoning entirely (supported by `grok-4.3` and newer
|
|
304
|
-
* reasoning models). When set, no thinking tokens are used.
|
|
305
|
-
* - `low` (default): Uses some reasoning tokens, but still fast.
|
|
306
|
-
* - `medium`: More thinking for less-latency-sensitive applications.
|
|
307
|
-
* - `high`: Uses more reasoning tokens for deeper thinking.
|
|
308
|
-
* - `xhigh`: Uses the most reasoning tokens (supported by `grok-4.6`).
|
|
309
|
-
*
|
|
310
|
-
* Note: Not every Grok model accepts every value. Refer to xAI's docs for
|
|
311
|
-
* the values supported by your selected model.
|
|
312
|
-
*
|
|
313
|
-
* @see https://docs.x.ai/docs/guides/reasoning
|
|
314
|
-
*/
|
|
315
|
-
reasoningEffort: z2.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
|
|
316
|
-
logprobs: z2.boolean().optional(),
|
|
317
|
-
topLogprobs: z2.number().int().min(0).max(8).optional(),
|
|
318
|
-
serviceTier: z2.enum(["default", "priority"]).optional(),
|
|
319
|
-
/**
|
|
320
|
-
* Whether to enable parallel function calling during tool use.
|
|
321
|
-
* When true, the model can call multiple functions in parallel.
|
|
322
|
-
* When false, the model will call functions sequentially.
|
|
323
|
-
* Defaults to true.
|
|
324
|
-
*/
|
|
325
|
-
parallel_function_calling: z2.boolean().optional(),
|
|
326
|
-
/**
|
|
327
|
-
* @deprecated xAI has deprecated Live Search (`search_parameters`) in favor
|
|
328
|
-
* of the Agent Tools API. Requests using this option now return a "Live
|
|
329
|
-
* search is deprecated" error. Use the `web_search` / `x_search` tools
|
|
330
|
-
* instead (e.g. `xai.tools.webSearch()`, `xai.tools.xSearch()`) with
|
|
331
|
-
* `xai.responses(modelId)`.
|
|
332
|
-
*
|
|
333
|
-
* @see https://docs.x.ai/docs/guides/tools/overview
|
|
334
|
-
*/
|
|
335
|
-
searchParameters: z2.object({
|
|
336
|
-
/**
|
|
337
|
-
* search mode preference
|
|
338
|
-
* - "off": disables search completely
|
|
339
|
-
* - "auto": model decides whether to search (default)
|
|
340
|
-
* - "on": always enables search
|
|
341
|
-
*/
|
|
342
|
-
mode: z2.enum(["off", "auto", "on"]),
|
|
343
|
-
/**
|
|
344
|
-
* whether to return citations in the response
|
|
345
|
-
* defaults to true
|
|
346
|
-
*/
|
|
347
|
-
returnCitations: z2.boolean().optional(),
|
|
348
|
-
/**
|
|
349
|
-
* start date for search data (ISO8601 format: YYYY-MM-DD)
|
|
350
|
-
*/
|
|
351
|
-
fromDate: z2.string().optional(),
|
|
352
|
-
/**
|
|
353
|
-
* end date for search data (ISO8601 format: YYYY-MM-DD)
|
|
354
|
-
*/
|
|
355
|
-
toDate: z2.string().optional(),
|
|
356
|
-
/**
|
|
357
|
-
* maximum number of search results to consider
|
|
358
|
-
* defaults to 20
|
|
359
|
-
*/
|
|
360
|
-
maxSearchResults: z2.number().min(1).max(50).optional(),
|
|
361
|
-
/**
|
|
362
|
-
* data sources to search from.
|
|
363
|
-
* defaults to [{ type: 'web' }, { type: 'x' }] if not specified.
|
|
364
|
-
*
|
|
365
|
-
* @example
|
|
366
|
-
* sources: [{ type: 'web', country: 'US' }, { type: 'x' }]
|
|
367
|
-
*/
|
|
368
|
-
sources: z2.array(searchSourceSchema).optional()
|
|
369
|
-
}).optional()
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
// src/xai-error.ts
|
|
373
|
-
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
374
|
-
import { z as z3 } from "zod/v4";
|
|
375
|
-
var chatCompletionsErrorSchema = z3.object({
|
|
376
|
-
error: z3.object({
|
|
377
|
-
message: z3.string(),
|
|
378
|
-
type: z3.string().nullish(),
|
|
379
|
-
param: z3.any().nullish(),
|
|
380
|
-
code: z3.union([z3.string(), z3.number()]).nullish()
|
|
381
|
-
})
|
|
382
|
-
});
|
|
383
|
-
var responsesErrorSchema = z3.object({
|
|
384
|
-
code: z3.string(),
|
|
385
|
-
error: z3.string()
|
|
386
|
-
});
|
|
387
|
-
var speechErrorSchema = z3.object({
|
|
388
|
-
error: z3.string()
|
|
389
|
-
});
|
|
390
|
-
var xaiErrorDataSchema = z3.union([
|
|
391
|
-
chatCompletionsErrorSchema,
|
|
392
|
-
responsesErrorSchema,
|
|
393
|
-
speechErrorSchema
|
|
394
|
-
]);
|
|
395
|
-
var xaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
396
|
-
errorSchema: xaiErrorDataSchema,
|
|
397
|
-
errorToMessage: (data) => {
|
|
398
|
-
if (typeof data.error === "string") {
|
|
399
|
-
return "code" in data ? `${data.code}: ${data.error}` : data.error;
|
|
400
|
-
}
|
|
401
|
-
return data.error.message;
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
// src/xai-prepare-tools.ts
|
|
406
|
-
import {
|
|
407
|
-
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
408
|
-
} from "@ai-sdk/provider";
|
|
409
|
-
|
|
410
|
-
// src/remove-additional-properties.ts
|
|
411
|
-
function removeAdditionalPropertiesFalse(value) {
|
|
412
|
-
if (Array.isArray(value)) {
|
|
413
|
-
return value.map(removeAdditionalPropertiesFalse);
|
|
414
|
-
}
|
|
415
|
-
if (value == null || typeof value !== "object") {
|
|
416
|
-
return value;
|
|
417
|
-
}
|
|
418
|
-
const result = {};
|
|
419
|
-
for (const [key, propertyValue] of Object.entries(value)) {
|
|
420
|
-
if (key === "additionalProperties" && propertyValue === false) {
|
|
421
|
-
continue;
|
|
422
|
-
}
|
|
423
|
-
result[key] = removeAdditionalPropertiesFalse(propertyValue);
|
|
424
|
-
}
|
|
425
|
-
return result;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// src/xai-prepare-tools.ts
|
|
429
|
-
function prepareTools({
|
|
430
|
-
tools,
|
|
431
|
-
toolChoice
|
|
432
|
-
}) {
|
|
433
|
-
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
434
|
-
const toolWarnings = [];
|
|
435
|
-
if (tools == null) {
|
|
436
|
-
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
437
|
-
}
|
|
438
|
-
const xaiTools2 = [];
|
|
439
|
-
for (const tool of tools) {
|
|
440
|
-
if (tool.type === "provider") {
|
|
441
|
-
toolWarnings.push({
|
|
442
|
-
type: "unsupported",
|
|
443
|
-
feature: `provider-defined tool ${tool.name}`
|
|
444
|
-
});
|
|
445
|
-
} else {
|
|
446
|
-
xaiTools2.push({
|
|
447
|
-
type: "function",
|
|
448
|
-
function: {
|
|
449
|
-
name: tool.name,
|
|
450
|
-
description: tool.description,
|
|
451
|
-
parameters: removeAdditionalPropertiesFalse(tool.inputSchema),
|
|
452
|
-
...tool.strict != null ? { strict: tool.strict } : {}
|
|
453
|
-
}
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
if (toolChoice == null) {
|
|
458
|
-
return { tools: xaiTools2, toolChoice: void 0, toolWarnings };
|
|
459
|
-
}
|
|
460
|
-
const type = toolChoice.type;
|
|
461
|
-
switch (type) {
|
|
462
|
-
case "auto":
|
|
463
|
-
case "none":
|
|
464
|
-
return { tools: xaiTools2, toolChoice: type, toolWarnings };
|
|
465
|
-
case "required":
|
|
466
|
-
return { tools: xaiTools2, toolChoice: "required", toolWarnings };
|
|
467
|
-
case "tool":
|
|
468
|
-
return {
|
|
469
|
-
tools: xaiTools2,
|
|
470
|
-
toolChoice: {
|
|
471
|
-
type: "function",
|
|
472
|
-
function: { name: toolChoice.toolName }
|
|
473
|
-
},
|
|
474
|
-
toolWarnings
|
|
475
|
-
};
|
|
476
|
-
default: {
|
|
477
|
-
const _exhaustiveCheck = type;
|
|
478
|
-
throw new UnsupportedFunctionalityError2({
|
|
479
|
-
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
// src/xai-chat-language-model.ts
|
|
486
|
-
var XaiChatLanguageModel = class _XaiChatLanguageModel {
|
|
487
|
-
constructor(modelId, config) {
|
|
488
|
-
this.specificationVersion = "v4";
|
|
489
|
-
this.supportedUrls = {
|
|
490
|
-
"image/*": [/^https?:\/\/.*$/]
|
|
491
|
-
};
|
|
492
|
-
this.modelId = modelId;
|
|
493
|
-
this.config = config;
|
|
494
|
-
}
|
|
495
|
-
static [WORKFLOW_SERIALIZE](model) {
|
|
496
|
-
return serializeModelOptions({
|
|
497
|
-
modelId: model.modelId,
|
|
498
|
-
config: model.config
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
static [WORKFLOW_DESERIALIZE](options) {
|
|
502
|
-
return new _XaiChatLanguageModel(options.modelId, options.config);
|
|
503
|
-
}
|
|
504
|
-
get provider() {
|
|
505
|
-
return this.config.provider;
|
|
506
|
-
}
|
|
507
|
-
async getArgs({
|
|
508
|
-
prompt,
|
|
509
|
-
maxOutputTokens,
|
|
510
|
-
temperature,
|
|
511
|
-
topP,
|
|
512
|
-
topK,
|
|
513
|
-
frequencyPenalty,
|
|
514
|
-
presencePenalty,
|
|
515
|
-
stopSequences,
|
|
516
|
-
seed,
|
|
517
|
-
reasoning,
|
|
518
|
-
responseFormat,
|
|
519
|
-
providerOptions,
|
|
520
|
-
tools,
|
|
521
|
-
toolChoice
|
|
522
|
-
}) {
|
|
523
|
-
var _a, _b, _c;
|
|
524
|
-
const warnings = [];
|
|
525
|
-
const options = (_a = await parseProviderOptions2({
|
|
526
|
-
provider: "xai",
|
|
527
|
-
providerOptions,
|
|
528
|
-
schema: xaiLanguageModelChatOptions
|
|
529
|
-
})) != null ? _a : {};
|
|
530
|
-
if (topK != null) {
|
|
531
|
-
warnings.push({ type: "unsupported", feature: "topK" });
|
|
532
|
-
}
|
|
533
|
-
if (frequencyPenalty != null) {
|
|
534
|
-
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
535
|
-
}
|
|
536
|
-
if (presencePenalty != null) {
|
|
537
|
-
warnings.push({ type: "unsupported", feature: "presencePenalty" });
|
|
538
|
-
}
|
|
539
|
-
if (stopSequences != null) {
|
|
540
|
-
warnings.push({ type: "unsupported", feature: "stopSequences" });
|
|
541
|
-
}
|
|
542
|
-
const { messages, warnings: messageWarnings } = await convertToXaiChatMessages(prompt);
|
|
543
|
-
warnings.push(...messageWarnings);
|
|
544
|
-
const {
|
|
545
|
-
tools: xaiTools2,
|
|
546
|
-
toolChoice: xaiToolChoice,
|
|
547
|
-
toolWarnings
|
|
548
|
-
} = prepareTools({
|
|
549
|
-
tools,
|
|
550
|
-
toolChoice
|
|
551
|
-
});
|
|
552
|
-
warnings.push(...toolWarnings);
|
|
553
|
-
let reasoningEffort = options.reasoningEffort;
|
|
554
|
-
if (reasoningEffort == null && isCustomReasoning(reasoning)) {
|
|
555
|
-
if (!supportsReasoningEffort(this.modelId)) {
|
|
556
|
-
warnings.push({
|
|
557
|
-
type: "unsupported",
|
|
558
|
-
feature: "reasoning",
|
|
559
|
-
details: `reasoning "${reasoning}" is not supported by this model.`
|
|
560
|
-
});
|
|
561
|
-
} else if (reasoning === "none") {
|
|
562
|
-
reasoningEffort = "none";
|
|
563
|
-
} else {
|
|
564
|
-
reasoningEffort = mapReasoningToProviderEffort({
|
|
565
|
-
reasoning,
|
|
566
|
-
effortMap: {
|
|
567
|
-
minimal: "low",
|
|
568
|
-
low: "low",
|
|
569
|
-
medium: "medium",
|
|
570
|
-
high: "high",
|
|
571
|
-
xhigh: this.modelId === "grok-4.6" ? "xhigh" : "high"
|
|
572
|
-
},
|
|
573
|
-
warnings
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
const baseArgs = {
|
|
578
|
-
// model id
|
|
579
|
-
model: this.modelId,
|
|
580
|
-
// standard generation settings
|
|
581
|
-
logprobs: options.logprobs === true || options.topLogprobs != null ? true : void 0,
|
|
582
|
-
top_logprobs: options.topLogprobs,
|
|
583
|
-
max_completion_tokens: maxOutputTokens,
|
|
584
|
-
temperature,
|
|
585
|
-
top_p: topP,
|
|
586
|
-
seed,
|
|
587
|
-
reasoning_effort: reasoningEffort,
|
|
588
|
-
// scheduling priority
|
|
589
|
-
service_tier: options.serviceTier,
|
|
590
|
-
// parallel function calling
|
|
591
|
-
parallel_function_calling: options.parallel_function_calling,
|
|
592
|
-
// response format
|
|
593
|
-
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
|
|
594
|
-
type: "json_schema",
|
|
595
|
-
json_schema: {
|
|
596
|
-
name: (_b = responseFormat.name) != null ? _b : "response",
|
|
597
|
-
schema: responseFormat.schema,
|
|
598
|
-
strict: true
|
|
599
|
-
}
|
|
600
|
-
} : { type: "json_object" } : void 0,
|
|
601
|
-
// search parameters
|
|
602
|
-
search_parameters: options.searchParameters ? {
|
|
603
|
-
mode: options.searchParameters.mode,
|
|
604
|
-
return_citations: options.searchParameters.returnCitations,
|
|
605
|
-
from_date: options.searchParameters.fromDate,
|
|
606
|
-
to_date: options.searchParameters.toDate,
|
|
607
|
-
max_search_results: options.searchParameters.maxSearchResults,
|
|
608
|
-
sources: (_c = options.searchParameters.sources) == null ? void 0 : _c.map((source) => {
|
|
609
|
-
var _a2;
|
|
610
|
-
return {
|
|
611
|
-
type: source.type,
|
|
612
|
-
...source.type === "web" && {
|
|
613
|
-
country: source.country,
|
|
614
|
-
excluded_websites: source.excludedWebsites,
|
|
615
|
-
allowed_websites: source.allowedWebsites,
|
|
616
|
-
safe_search: source.safeSearch
|
|
617
|
-
},
|
|
618
|
-
...source.type === "x" && {
|
|
619
|
-
excluded_x_handles: source.excludedXHandles,
|
|
620
|
-
included_x_handles: (_a2 = source.includedXHandles) != null ? _a2 : source.xHandles,
|
|
621
|
-
post_favorite_count: source.postFavoriteCount,
|
|
622
|
-
post_view_count: source.postViewCount
|
|
623
|
-
},
|
|
624
|
-
...source.type === "news" && {
|
|
625
|
-
country: source.country,
|
|
626
|
-
excluded_websites: source.excludedWebsites,
|
|
627
|
-
safe_search: source.safeSearch
|
|
628
|
-
},
|
|
629
|
-
...source.type === "rss" && {
|
|
630
|
-
links: source.links
|
|
631
|
-
}
|
|
632
|
-
};
|
|
633
|
-
})
|
|
634
|
-
} : void 0,
|
|
635
|
-
// messages in xai format
|
|
636
|
-
messages,
|
|
637
|
-
// tools in xai format
|
|
638
|
-
tools: xaiTools2,
|
|
639
|
-
tool_choice: xaiToolChoice
|
|
640
|
-
};
|
|
641
|
-
return {
|
|
642
|
-
args: baseArgs,
|
|
643
|
-
warnings
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
async doGenerate(options) {
|
|
647
|
-
var _a, _b, _c, _d;
|
|
648
|
-
const { args: body, warnings } = await this.getArgs(options);
|
|
649
|
-
const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
|
|
650
|
-
const {
|
|
651
|
-
responseHeaders,
|
|
652
|
-
value: response,
|
|
653
|
-
rawValue: rawResponse
|
|
654
|
-
} = await postJsonToApi({
|
|
655
|
-
url,
|
|
656
|
-
headers: combineHeaders((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
657
|
-
body,
|
|
658
|
-
failedResponseHandler: xaiFailedResponseHandler,
|
|
659
|
-
successfulResponseHandler: createJsonResponseHandler(
|
|
660
|
-
xaiChatResponseSchema
|
|
661
|
-
),
|
|
662
|
-
abortSignal: options.abortSignal,
|
|
663
|
-
fetch: this.config.fetch
|
|
664
|
-
});
|
|
665
|
-
if (response.error != null) {
|
|
666
|
-
throw new APICallError({
|
|
667
|
-
message: response.error,
|
|
668
|
-
url,
|
|
669
|
-
requestBodyValues: body,
|
|
670
|
-
statusCode: 200,
|
|
671
|
-
responseHeaders,
|
|
672
|
-
responseBody: JSON.stringify(rawResponse),
|
|
673
|
-
isRetryable: response.code === "The service is currently unavailable"
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
const choice = response.choices[0];
|
|
677
|
-
const content = [];
|
|
678
|
-
if (choice.message.content != null && choice.message.content.length > 0) {
|
|
679
|
-
let text = choice.message.content;
|
|
680
|
-
const lastMessage = body.messages[body.messages.length - 1];
|
|
681
|
-
if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && text === lastMessage.content) {
|
|
682
|
-
text = "";
|
|
683
|
-
}
|
|
684
|
-
if (text.length > 0) {
|
|
685
|
-
content.push({ type: "text", text });
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
if (choice.message.reasoning_content != null && choice.message.reasoning_content.length > 0) {
|
|
689
|
-
content.push({
|
|
690
|
-
type: "reasoning",
|
|
691
|
-
text: choice.message.reasoning_content
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
if (choice.message.tool_calls != null) {
|
|
695
|
-
for (const toolCall of choice.message.tool_calls) {
|
|
696
|
-
content.push({
|
|
697
|
-
type: "tool-call",
|
|
698
|
-
toolCallId: toolCall.id,
|
|
699
|
-
toolName: toolCall.function.name,
|
|
700
|
-
input: toolCall.function.arguments
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
if (response.citations != null) {
|
|
705
|
-
for (const url2 of response.citations) {
|
|
706
|
-
content.push({
|
|
707
|
-
type: "source",
|
|
708
|
-
sourceType: "url",
|
|
709
|
-
id: this.config.generateId(),
|
|
710
|
-
url: url2
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
return {
|
|
715
|
-
content,
|
|
716
|
-
finishReason: {
|
|
717
|
-
unified: mapXaiFinishReason(choice.finish_reason),
|
|
718
|
-
raw: (_d = choice.finish_reason) != null ? _d : void 0
|
|
719
|
-
},
|
|
720
|
-
usage: response.usage ? convertXaiChatUsage(response.usage) : {
|
|
721
|
-
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
722
|
-
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
723
|
-
},
|
|
724
|
-
...response.service_tier != null && {
|
|
725
|
-
providerMetadata: {
|
|
726
|
-
xai: { serviceTier: response.service_tier }
|
|
727
|
-
}
|
|
728
|
-
},
|
|
729
|
-
request: { body },
|
|
730
|
-
response: {
|
|
731
|
-
...getResponseMetadata(response),
|
|
732
|
-
headers: responseHeaders,
|
|
733
|
-
body: rawResponse
|
|
734
|
-
},
|
|
735
|
-
warnings
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
|
-
async doStream(options) {
|
|
739
|
-
var _a, _b, _c;
|
|
740
|
-
const { args, warnings } = await this.getArgs(options);
|
|
741
|
-
const body = {
|
|
742
|
-
...args,
|
|
743
|
-
stream: true,
|
|
744
|
-
stream_options: {
|
|
745
|
-
include_usage: true
|
|
746
|
-
}
|
|
747
|
-
};
|
|
748
|
-
const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
|
|
749
|
-
const { responseHeaders, value: response } = await postJsonToApi({
|
|
750
|
-
url,
|
|
751
|
-
headers: combineHeaders((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
752
|
-
body,
|
|
753
|
-
failedResponseHandler: xaiFailedResponseHandler,
|
|
754
|
-
successfulResponseHandler: async ({ response: response2 }) => {
|
|
755
|
-
const responseHeaders2 = extractResponseHeaders(response2);
|
|
756
|
-
const contentType = response2.headers.get("content-type");
|
|
757
|
-
if (contentType == null ? void 0 : contentType.includes("application/json")) {
|
|
758
|
-
const responseBody = await response2.text();
|
|
759
|
-
const parsedError = await safeParseJSON({
|
|
760
|
-
text: responseBody,
|
|
761
|
-
schema: xaiStreamErrorSchema
|
|
762
|
-
});
|
|
763
|
-
if (parsedError.success) {
|
|
764
|
-
throw new APICallError({
|
|
765
|
-
message: parsedError.value.error,
|
|
766
|
-
url,
|
|
767
|
-
requestBodyValues: body,
|
|
768
|
-
statusCode: 200,
|
|
769
|
-
responseHeaders: responseHeaders2,
|
|
770
|
-
responseBody,
|
|
771
|
-
isRetryable: parsedError.value.code === "The service is currently unavailable"
|
|
772
|
-
});
|
|
773
|
-
}
|
|
774
|
-
throw new APICallError({
|
|
775
|
-
message: "Invalid JSON response",
|
|
776
|
-
url,
|
|
777
|
-
requestBodyValues: body,
|
|
778
|
-
statusCode: 200,
|
|
779
|
-
responseHeaders: responseHeaders2,
|
|
780
|
-
responseBody
|
|
781
|
-
});
|
|
782
|
-
}
|
|
783
|
-
return createEventSourceResponseHandler(xaiChatChunkSchema)({
|
|
784
|
-
response: response2,
|
|
785
|
-
url,
|
|
786
|
-
requestBodyValues: body
|
|
787
|
-
});
|
|
788
|
-
},
|
|
789
|
-
abortSignal: options.abortSignal,
|
|
790
|
-
fetch: this.config.fetch
|
|
791
|
-
});
|
|
792
|
-
let finishReason = {
|
|
793
|
-
unified: "other",
|
|
794
|
-
raw: void 0
|
|
795
|
-
};
|
|
796
|
-
let usage = void 0;
|
|
797
|
-
let serviceTier = void 0;
|
|
798
|
-
let isFirstChunk = true;
|
|
799
|
-
const contentBlocks = {};
|
|
800
|
-
const lastReasoningDeltas = {};
|
|
801
|
-
let activeReasoningBlockId = void 0;
|
|
802
|
-
const self = this;
|
|
803
|
-
return {
|
|
804
|
-
stream: response.pipeThrough(
|
|
805
|
-
new TransformStream({
|
|
806
|
-
start(controller) {
|
|
807
|
-
controller.enqueue({ type: "stream-start", warnings });
|
|
808
|
-
},
|
|
809
|
-
transform(chunk, controller) {
|
|
810
|
-
if (options.includeRawChunks) {
|
|
811
|
-
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
812
|
-
}
|
|
813
|
-
if (!chunk.success) {
|
|
814
|
-
controller.enqueue({ type: "error", error: chunk.error });
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
817
|
-
const value = chunk.value;
|
|
818
|
-
if (isFirstChunk) {
|
|
819
|
-
controller.enqueue({
|
|
820
|
-
type: "response-metadata",
|
|
821
|
-
...getResponseMetadata(value)
|
|
822
|
-
});
|
|
823
|
-
isFirstChunk = false;
|
|
824
|
-
}
|
|
825
|
-
if (value.citations != null) {
|
|
826
|
-
for (const url2 of value.citations) {
|
|
827
|
-
controller.enqueue({
|
|
828
|
-
type: "source",
|
|
829
|
-
sourceType: "url",
|
|
830
|
-
id: self.config.generateId(),
|
|
831
|
-
url: url2
|
|
832
|
-
});
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
if (value.usage != null) {
|
|
836
|
-
usage = convertXaiChatUsage(value.usage);
|
|
837
|
-
}
|
|
838
|
-
if (value.service_tier != null) {
|
|
839
|
-
serviceTier = value.service_tier;
|
|
840
|
-
}
|
|
841
|
-
const choice = value.choices[0];
|
|
842
|
-
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
843
|
-
finishReason = {
|
|
844
|
-
unified: mapXaiFinishReason(choice.finish_reason),
|
|
845
|
-
raw: choice.finish_reason
|
|
846
|
-
};
|
|
847
|
-
}
|
|
848
|
-
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
849
|
-
return;
|
|
850
|
-
}
|
|
851
|
-
const delta = choice.delta;
|
|
852
|
-
const choiceIndex = choice.index;
|
|
853
|
-
if (delta.content != null && delta.content.length > 0) {
|
|
854
|
-
const textContent = delta.content;
|
|
855
|
-
if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
|
|
856
|
-
controller.enqueue({
|
|
857
|
-
type: "reasoning-end",
|
|
858
|
-
id: activeReasoningBlockId
|
|
859
|
-
});
|
|
860
|
-
contentBlocks[activeReasoningBlockId].ended = true;
|
|
861
|
-
activeReasoningBlockId = void 0;
|
|
862
|
-
}
|
|
863
|
-
const lastMessage = body.messages[body.messages.length - 1];
|
|
864
|
-
if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && textContent === lastMessage.content) {
|
|
865
|
-
return;
|
|
866
|
-
}
|
|
867
|
-
const blockId = `text-${value.id || choiceIndex}`;
|
|
868
|
-
if (contentBlocks[blockId] == null) {
|
|
869
|
-
contentBlocks[blockId] = { type: "text", ended: false };
|
|
870
|
-
controller.enqueue({
|
|
871
|
-
type: "text-start",
|
|
872
|
-
id: blockId
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
controller.enqueue({
|
|
876
|
-
type: "text-delta",
|
|
877
|
-
id: blockId,
|
|
878
|
-
delta: textContent
|
|
879
|
-
});
|
|
880
|
-
}
|
|
881
|
-
if (delta.reasoning_content != null && delta.reasoning_content.length > 0) {
|
|
882
|
-
const blockId = `reasoning-${value.id || choiceIndex}`;
|
|
883
|
-
if (lastReasoningDeltas[blockId] === delta.reasoning_content) {
|
|
884
|
-
return;
|
|
885
|
-
}
|
|
886
|
-
lastReasoningDeltas[blockId] = delta.reasoning_content;
|
|
887
|
-
if (contentBlocks[blockId] == null) {
|
|
888
|
-
contentBlocks[blockId] = { type: "reasoning", ended: false };
|
|
889
|
-
activeReasoningBlockId = blockId;
|
|
890
|
-
controller.enqueue({
|
|
891
|
-
type: "reasoning-start",
|
|
892
|
-
id: blockId
|
|
893
|
-
});
|
|
894
|
-
}
|
|
895
|
-
controller.enqueue({
|
|
896
|
-
type: "reasoning-delta",
|
|
897
|
-
id: blockId,
|
|
898
|
-
delta: delta.reasoning_content
|
|
899
|
-
});
|
|
900
|
-
}
|
|
901
|
-
if (delta.tool_calls != null && delta.tool_calls.length > 0) {
|
|
902
|
-
if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
|
|
903
|
-
controller.enqueue({
|
|
904
|
-
type: "reasoning-end",
|
|
905
|
-
id: activeReasoningBlockId
|
|
906
|
-
});
|
|
907
|
-
contentBlocks[activeReasoningBlockId].ended = true;
|
|
908
|
-
activeReasoningBlockId = void 0;
|
|
909
|
-
}
|
|
910
|
-
for (const toolCall of delta.tool_calls) {
|
|
911
|
-
const toolCallId = toolCall.id;
|
|
912
|
-
controller.enqueue({
|
|
913
|
-
type: "tool-input-start",
|
|
914
|
-
id: toolCallId,
|
|
915
|
-
toolName: toolCall.function.name
|
|
916
|
-
});
|
|
917
|
-
controller.enqueue({
|
|
918
|
-
type: "tool-input-delta",
|
|
919
|
-
id: toolCallId,
|
|
920
|
-
delta: toolCall.function.arguments
|
|
921
|
-
});
|
|
922
|
-
controller.enqueue({
|
|
923
|
-
type: "tool-input-end",
|
|
924
|
-
id: toolCallId
|
|
925
|
-
});
|
|
926
|
-
controller.enqueue({
|
|
927
|
-
type: "tool-call",
|
|
928
|
-
toolCallId,
|
|
929
|
-
toolName: toolCall.function.name,
|
|
930
|
-
input: toolCall.function.arguments
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
},
|
|
935
|
-
flush(controller) {
|
|
936
|
-
for (const [blockId, block] of Object.entries(contentBlocks)) {
|
|
937
|
-
if (!block.ended) {
|
|
938
|
-
controller.enqueue({
|
|
939
|
-
type: block.type === "text" ? "text-end" : "reasoning-end",
|
|
940
|
-
id: blockId
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
controller.enqueue({
|
|
945
|
-
type: "finish",
|
|
946
|
-
finishReason,
|
|
947
|
-
usage: usage != null ? usage : {
|
|
948
|
-
inputTokens: {
|
|
949
|
-
total: 0,
|
|
950
|
-
noCache: 0,
|
|
951
|
-
cacheRead: 0,
|
|
952
|
-
cacheWrite: 0
|
|
953
|
-
},
|
|
954
|
-
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
955
|
-
},
|
|
956
|
-
...serviceTier != null && {
|
|
957
|
-
providerMetadata: { xai: { serviceTier } }
|
|
958
|
-
}
|
|
959
|
-
});
|
|
960
|
-
}
|
|
961
|
-
})
|
|
962
|
-
),
|
|
963
|
-
request: { body },
|
|
964
|
-
response: { headers: responseHeaders }
|
|
965
|
-
};
|
|
966
|
-
}
|
|
967
|
-
};
|
|
968
|
-
var xaiUsageSchema = z4.object({
|
|
969
|
-
prompt_tokens: z4.number(),
|
|
970
|
-
completion_tokens: z4.number(),
|
|
971
|
-
total_tokens: z4.number(),
|
|
972
|
-
cost_in_usd_ticks: z4.number().nullish(),
|
|
973
|
-
prompt_tokens_details: z4.object({
|
|
974
|
-
text_tokens: z4.number().nullish(),
|
|
975
|
-
audio_tokens: z4.number().nullish(),
|
|
976
|
-
image_tokens: z4.number().nullish(),
|
|
977
|
-
cached_tokens: z4.number().nullish()
|
|
978
|
-
}).catchall(z4.json()).nullish(),
|
|
979
|
-
completion_tokens_details: z4.object({
|
|
980
|
-
reasoning_tokens: z4.number().nullish(),
|
|
981
|
-
audio_tokens: z4.number().nullish(),
|
|
982
|
-
accepted_prediction_tokens: z4.number().nullish(),
|
|
983
|
-
rejected_prediction_tokens: z4.number().nullish()
|
|
984
|
-
}).catchall(z4.json()).nullish()
|
|
985
|
-
}).catchall(z4.json());
|
|
986
|
-
var xaiChatResponseSchema = z4.object({
|
|
987
|
-
id: z4.string().nullish(),
|
|
988
|
-
created: z4.number().nullish(),
|
|
989
|
-
model: z4.string().nullish(),
|
|
990
|
-
choices: z4.array(
|
|
991
|
-
z4.object({
|
|
992
|
-
message: z4.object({
|
|
993
|
-
role: z4.enum(["assistant", "tool"]),
|
|
994
|
-
content: z4.string().nullish(),
|
|
995
|
-
reasoning_content: z4.string().nullish(),
|
|
996
|
-
tool_calls: z4.array(
|
|
997
|
-
z4.object({
|
|
998
|
-
id: z4.string(),
|
|
999
|
-
type: z4.literal("function"),
|
|
1000
|
-
function: z4.object({
|
|
1001
|
-
name: z4.string(),
|
|
1002
|
-
arguments: z4.string()
|
|
1003
|
-
})
|
|
1004
|
-
})
|
|
1005
|
-
).nullish()
|
|
1006
|
-
}),
|
|
1007
|
-
index: z4.number(),
|
|
1008
|
-
finish_reason: z4.string().nullish()
|
|
1009
|
-
})
|
|
1010
|
-
).nullish(),
|
|
1011
|
-
object: z4.literal("chat.completion").nullish(),
|
|
1012
|
-
usage: xaiUsageSchema.nullish(),
|
|
1013
|
-
citations: z4.array(z4.string().url()).nullish(),
|
|
1014
|
-
service_tier: z4.string().nullish(),
|
|
1015
|
-
code: z4.string().nullish(),
|
|
1016
|
-
error: z4.string().nullish()
|
|
1017
|
-
});
|
|
1018
|
-
var xaiChatChunkSchema = z4.object({
|
|
1019
|
-
id: z4.string().nullish(),
|
|
1020
|
-
created: z4.number().nullish(),
|
|
1021
|
-
model: z4.string().nullish(),
|
|
1022
|
-
choices: z4.array(
|
|
1023
|
-
z4.object({
|
|
1024
|
-
delta: z4.object({
|
|
1025
|
-
role: z4.enum(["assistant"]).optional(),
|
|
1026
|
-
content: z4.string().nullish(),
|
|
1027
|
-
reasoning_content: z4.string().nullish(),
|
|
1028
|
-
tool_calls: z4.array(
|
|
1029
|
-
z4.object({
|
|
1030
|
-
id: z4.string(),
|
|
1031
|
-
type: z4.literal("function"),
|
|
1032
|
-
function: z4.object({
|
|
1033
|
-
name: z4.string(),
|
|
1034
|
-
arguments: z4.string()
|
|
1035
|
-
})
|
|
1036
|
-
})
|
|
1037
|
-
).nullish()
|
|
1038
|
-
}),
|
|
1039
|
-
finish_reason: z4.string().nullish(),
|
|
1040
|
-
index: z4.number()
|
|
1041
|
-
})
|
|
1042
|
-
),
|
|
1043
|
-
usage: xaiUsageSchema.nullish(),
|
|
1044
|
-
citations: z4.array(z4.string().url()).nullish(),
|
|
1045
|
-
service_tier: z4.string().nullish()
|
|
1046
|
-
});
|
|
1047
|
-
var xaiStreamErrorSchema = z4.object({
|
|
1048
|
-
code: z4.string(),
|
|
1049
|
-
error: z4.string()
|
|
1050
|
-
});
|
|
1051
|
-
|
|
1052
12
|
// src/xai-image-model.ts
|
|
1053
13
|
import {
|
|
1054
|
-
combineHeaders
|
|
14
|
+
combineHeaders,
|
|
1055
15
|
convertImageModelFileToDataUri,
|
|
1056
16
|
createBinaryResponseHandler,
|
|
1057
|
-
createJsonResponseHandler
|
|
17
|
+
createJsonResponseHandler,
|
|
1058
18
|
createStatusCodeErrorResponseHandler,
|
|
1059
19
|
getFromApi,
|
|
1060
|
-
parseProviderOptions
|
|
1061
|
-
postJsonToApi
|
|
1062
|
-
serializeModelOptions
|
|
1063
|
-
WORKFLOW_SERIALIZE
|
|
1064
|
-
WORKFLOW_DESERIALIZE
|
|
20
|
+
parseProviderOptions,
|
|
21
|
+
postJsonToApi,
|
|
22
|
+
serializeModelOptions,
|
|
23
|
+
WORKFLOW_SERIALIZE,
|
|
24
|
+
WORKFLOW_DESERIALIZE
|
|
1065
25
|
} from "@ai-sdk/provider-utils";
|
|
1066
|
-
import { z as
|
|
26
|
+
import { z as z3 } from "zod/v4";
|
|
27
|
+
|
|
28
|
+
// src/xai-error.ts
|
|
29
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
30
|
+
import { z } from "zod/v4";
|
|
31
|
+
var apiErrorSchema = z.object({
|
|
32
|
+
error: z.object({
|
|
33
|
+
message: z.string(),
|
|
34
|
+
type: z.string().nullish(),
|
|
35
|
+
param: z.any().nullish(),
|
|
36
|
+
code: z.union([z.string(), z.number()]).nullish()
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
var responsesErrorSchema = z.object({
|
|
40
|
+
code: z.string(),
|
|
41
|
+
error: z.string()
|
|
42
|
+
});
|
|
43
|
+
var speechErrorSchema = z.object({
|
|
44
|
+
error: z.string()
|
|
45
|
+
});
|
|
46
|
+
var xaiErrorDataSchema = z.union([
|
|
47
|
+
apiErrorSchema,
|
|
48
|
+
responsesErrorSchema,
|
|
49
|
+
speechErrorSchema
|
|
50
|
+
]);
|
|
51
|
+
var xaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
52
|
+
errorSchema: xaiErrorDataSchema,
|
|
53
|
+
errorToMessage: (data) => {
|
|
54
|
+
if (typeof data.error === "string") {
|
|
55
|
+
return "code" in data ? `${data.code}: ${data.error}` : data.error;
|
|
56
|
+
}
|
|
57
|
+
return data.error.message;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
1067
60
|
|
|
1068
61
|
// src/xai-image-model-options.ts
|
|
1069
|
-
import { z as
|
|
1070
|
-
var xaiImageModelOptions =
|
|
1071
|
-
aspect_ratio:
|
|
1072
|
-
output_format:
|
|
1073
|
-
sync_mode:
|
|
1074
|
-
resolution:
|
|
1075
|
-
quality:
|
|
1076
|
-
user:
|
|
62
|
+
import { z as z2 } from "zod/v4";
|
|
63
|
+
var xaiImageModelOptions = z2.object({
|
|
64
|
+
aspect_ratio: z2.string().optional(),
|
|
65
|
+
output_format: z2.string().optional(),
|
|
66
|
+
sync_mode: z2.boolean().optional(),
|
|
67
|
+
resolution: z2.enum(["1k", "2k"]).optional(),
|
|
68
|
+
quality: z2.enum(["low", "medium", "high"]).optional(),
|
|
69
|
+
user: z2.string().optional()
|
|
1077
70
|
});
|
|
1078
71
|
|
|
1079
72
|
// src/xai-image-model.ts
|
|
@@ -1087,13 +80,13 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
1087
80
|
get provider() {
|
|
1088
81
|
return this.config.provider;
|
|
1089
82
|
}
|
|
1090
|
-
static [
|
|
1091
|
-
return
|
|
83
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
84
|
+
return serializeModelOptions({
|
|
1092
85
|
modelId: model.modelId,
|
|
1093
86
|
config: model.config
|
|
1094
87
|
});
|
|
1095
88
|
}
|
|
1096
|
-
static [
|
|
89
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
1097
90
|
return new _XaiImageModel(options.modelId, options.config);
|
|
1098
91
|
}
|
|
1099
92
|
async doGenerate({
|
|
@@ -1129,7 +122,7 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
1129
122
|
feature: "mask"
|
|
1130
123
|
});
|
|
1131
124
|
}
|
|
1132
|
-
const xaiOptions = await
|
|
125
|
+
const xaiOptions = await parseProviderOptions({
|
|
1133
126
|
provider: "xai",
|
|
1134
127
|
providerOptions,
|
|
1135
128
|
schema: xaiImageModelOptions
|
|
@@ -1171,12 +164,12 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
1171
164
|
}
|
|
1172
165
|
const baseURL = (_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1";
|
|
1173
166
|
const currentDate = (_d = (_c = (_b = this.config._internal) == null ? void 0 : _b.currentDate) == null ? void 0 : _c.call(_b)) != null ? _d : /* @__PURE__ */ new Date();
|
|
1174
|
-
const { value: response, responseHeaders } = await
|
|
167
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1175
168
|
url: `${baseURL}${endpoint}`,
|
|
1176
|
-
headers:
|
|
169
|
+
headers: combineHeaders((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), headers),
|
|
1177
170
|
body,
|
|
1178
171
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
1179
|
-
successfulResponseHandler:
|
|
172
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
1180
173
|
xaiImageResponseSchema
|
|
1181
174
|
),
|
|
1182
175
|
abortSignal,
|
|
@@ -1225,97 +218,154 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
1225
218
|
return value;
|
|
1226
219
|
}
|
|
1227
220
|
};
|
|
1228
|
-
var xaiImageResponseSchema =
|
|
1229
|
-
data:
|
|
1230
|
-
|
|
1231
|
-
url:
|
|
1232
|
-
b64_json:
|
|
1233
|
-
revised_prompt:
|
|
1234
|
-
respect_moderation:
|
|
221
|
+
var xaiImageResponseSchema = z3.object({
|
|
222
|
+
data: z3.array(
|
|
223
|
+
z3.object({
|
|
224
|
+
url: z3.string().nullish(),
|
|
225
|
+
b64_json: z3.string().nullish(),
|
|
226
|
+
revised_prompt: z3.string().nullish(),
|
|
227
|
+
respect_moderation: z3.boolean().nullish()
|
|
1235
228
|
})
|
|
1236
229
|
),
|
|
1237
|
-
usage:
|
|
1238
|
-
cost_in_usd_ticks:
|
|
230
|
+
usage: z3.object({
|
|
231
|
+
cost_in_usd_ticks: z3.number().nullish()
|
|
1239
232
|
}).nullish()
|
|
1240
233
|
});
|
|
1241
234
|
|
|
1242
235
|
// src/xai-batch.ts
|
|
1243
236
|
import {
|
|
1244
237
|
InvalidArgumentError,
|
|
1245
|
-
UnsupportedFunctionalityError as
|
|
238
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
1246
239
|
} from "@ai-sdk/provider";
|
|
1247
240
|
import {
|
|
1248
|
-
combineHeaders as
|
|
241
|
+
combineHeaders as combineHeaders3,
|
|
1249
242
|
convertImageModelFileToDataUri as convertImageModelFileToDataUri2,
|
|
1250
243
|
convertBase64ToUint8Array,
|
|
1251
244
|
convertAsyncIteratorToReadableStream,
|
|
1252
|
-
createJsonResponseHandler as
|
|
245
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1253
246
|
createBinaryResponseHandler as createBinaryResponseHandler2,
|
|
1254
247
|
createNullLanguageModelUsage,
|
|
1255
248
|
getFromApi as getFromApi2,
|
|
1256
249
|
lazySchema as lazySchema7,
|
|
1257
250
|
normalizeBatchRequestCounts,
|
|
1258
|
-
parseProviderOptions as
|
|
251
|
+
parseProviderOptions as parseProviderOptions4,
|
|
1259
252
|
postFormDataToApi,
|
|
1260
|
-
postJsonToApi as
|
|
253
|
+
postJsonToApi as postJsonToApi3,
|
|
1261
254
|
safeValidateTypes,
|
|
1262
255
|
zodSchema as zodSchema7
|
|
1263
256
|
} from "@ai-sdk/provider-utils";
|
|
1264
|
-
import { z as
|
|
257
|
+
import { z as z13 } from "zod/v4";
|
|
258
|
+
|
|
259
|
+
// src/get-response-metadata.ts
|
|
260
|
+
import { createLanguageModelResponseMetadata } from "@ai-sdk/provider-utils";
|
|
261
|
+
function getResponseMetadata({
|
|
262
|
+
id,
|
|
263
|
+
model,
|
|
264
|
+
created,
|
|
265
|
+
created_at
|
|
266
|
+
}) {
|
|
267
|
+
return createLanguageModelResponseMetadata({
|
|
268
|
+
id,
|
|
269
|
+
model,
|
|
270
|
+
created: created != null ? created : created_at
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/map-xai-finish-reason.ts
|
|
275
|
+
function mapXaiFinishReason(finishReason) {
|
|
276
|
+
switch (finishReason) {
|
|
277
|
+
case "stop":
|
|
278
|
+
return "stop";
|
|
279
|
+
case "length":
|
|
280
|
+
return "length";
|
|
281
|
+
case "tool_calls":
|
|
282
|
+
case "function_call":
|
|
283
|
+
return "tool-calls";
|
|
284
|
+
case "content_filter":
|
|
285
|
+
return "content-filter";
|
|
286
|
+
default:
|
|
287
|
+
return "other";
|
|
288
|
+
}
|
|
289
|
+
}
|
|
1265
290
|
|
|
1266
291
|
// src/files/xai-files-api.ts
|
|
1267
292
|
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
1268
|
-
import { z as
|
|
293
|
+
import { z as z4 } from "zod/v4";
|
|
1269
294
|
var xaiFilesResponseSchema = lazySchema(
|
|
1270
295
|
() => zodSchema(
|
|
1271
|
-
|
|
1272
|
-
id:
|
|
1273
|
-
object:
|
|
1274
|
-
bytes:
|
|
1275
|
-
created_at:
|
|
1276
|
-
expires_at:
|
|
1277
|
-
filename:
|
|
1278
|
-
purpose:
|
|
1279
|
-
status:
|
|
296
|
+
z4.object({
|
|
297
|
+
id: z4.string(),
|
|
298
|
+
object: z4.string().nullish(),
|
|
299
|
+
bytes: z4.number().nullish(),
|
|
300
|
+
created_at: z4.number().nullish(),
|
|
301
|
+
expires_at: z4.number().nullish(),
|
|
302
|
+
filename: z4.string().nullish(),
|
|
303
|
+
purpose: z4.string().nullish(),
|
|
304
|
+
status: z4.string().nullish()
|
|
1280
305
|
})
|
|
1281
306
|
)
|
|
1282
307
|
);
|
|
1283
308
|
var xaiFileDeleteResponseSchema = lazySchema(
|
|
1284
309
|
() => zodSchema(
|
|
1285
|
-
|
|
1286
|
-
id:
|
|
1287
|
-
object:
|
|
1288
|
-
deleted:
|
|
310
|
+
z4.object({
|
|
311
|
+
id: z4.string(),
|
|
312
|
+
object: z4.string().nullish(),
|
|
313
|
+
deleted: z4.boolean()
|
|
1289
314
|
})
|
|
1290
315
|
)
|
|
1291
316
|
);
|
|
1292
317
|
|
|
1293
318
|
// src/responses/xai-responses-language-model.ts
|
|
1294
319
|
import {
|
|
1295
|
-
combineHeaders as
|
|
1296
|
-
createEventSourceResponseHandler
|
|
1297
|
-
createJsonResponseHandler as
|
|
320
|
+
combineHeaders as combineHeaders2,
|
|
321
|
+
createEventSourceResponseHandler,
|
|
322
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
1298
323
|
createProviderStreamError,
|
|
1299
|
-
isCustomReasoning
|
|
1300
|
-
mapReasoningToProviderEffort
|
|
1301
|
-
parseProviderOptions as
|
|
1302
|
-
postJsonToApi as
|
|
1303
|
-
serializeModelOptions as
|
|
1304
|
-
WORKFLOW_SERIALIZE as
|
|
1305
|
-
WORKFLOW_DESERIALIZE as
|
|
324
|
+
isCustomReasoning,
|
|
325
|
+
mapReasoningToProviderEffort,
|
|
326
|
+
parseProviderOptions as parseProviderOptions3,
|
|
327
|
+
postJsonToApi as postJsonToApi2,
|
|
328
|
+
serializeModelOptions as serializeModelOptions2,
|
|
329
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
330
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
1306
331
|
} from "@ai-sdk/provider-utils";
|
|
1307
332
|
|
|
333
|
+
// src/supports-reasoning-effort.ts
|
|
334
|
+
var modelsWithoutReasoningEffort = /^grok-4\.20(-\d{4})?-(non-)?reasoning$/;
|
|
335
|
+
function supportsReasoningEffort(modelId) {
|
|
336
|
+
return !modelsWithoutReasoningEffort.test(modelId);
|
|
337
|
+
}
|
|
338
|
+
|
|
1308
339
|
// src/responses/convert-to-xai-responses-input.ts
|
|
1309
340
|
import {
|
|
1310
|
-
UnsupportedFunctionalityError
|
|
341
|
+
UnsupportedFunctionalityError
|
|
1311
342
|
} from "@ai-sdk/provider";
|
|
1312
343
|
import {
|
|
1313
|
-
convertToBase64
|
|
1314
|
-
getTopLevelMediaType
|
|
1315
|
-
parseProviderOptions as
|
|
1316
|
-
resolveFullMediaType
|
|
1317
|
-
resolveProviderReference
|
|
344
|
+
convertToBase64,
|
|
345
|
+
getTopLevelMediaType,
|
|
346
|
+
parseProviderOptions as parseProviderOptions2,
|
|
347
|
+
resolveFullMediaType,
|
|
348
|
+
resolveProviderReference
|
|
1318
349
|
} from "@ai-sdk/provider-utils";
|
|
350
|
+
|
|
351
|
+
// src/xai-file-part-options.ts
|
|
352
|
+
import { z as z5 } from "zod/v4";
|
|
353
|
+
var xaiFilePartProviderOptions = z5.object({
|
|
354
|
+
/**
|
|
355
|
+
* Controls the resolution at which the model processes the image.
|
|
356
|
+
* `low` processes the image at reduced resolution and consumes fewer
|
|
357
|
+
* input tokens, `high` processes the image at full resolution, and
|
|
358
|
+
* `auto` lets the API decide. Defaults to full resolution when not set.
|
|
359
|
+
*
|
|
360
|
+
* Note: the xAI API silently ignores invalid values, so the value is
|
|
361
|
+
* validated client-side.
|
|
362
|
+
*
|
|
363
|
+
* @see https://docs.x.ai/developers/model-capabilities/images/understanding
|
|
364
|
+
*/
|
|
365
|
+
imageDetail: z5.enum(["low", "high", "auto"]).optional()
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
// src/responses/convert-to-xai-responses-input.ts
|
|
1319
369
|
async function convertToXaiResponsesInput({
|
|
1320
370
|
prompt
|
|
1321
371
|
}) {
|
|
@@ -1344,7 +394,7 @@ async function convertToXaiResponsesInput({
|
|
|
1344
394
|
case "reference": {
|
|
1345
395
|
contentParts.push({
|
|
1346
396
|
type: "input_file",
|
|
1347
|
-
file_id:
|
|
397
|
+
file_id: resolveProviderReference({
|
|
1348
398
|
reference: block.data.reference,
|
|
1349
399
|
provider: "xai"
|
|
1350
400
|
})
|
|
@@ -1352,15 +402,15 @@ async function convertToXaiResponsesInput({
|
|
|
1352
402
|
break;
|
|
1353
403
|
}
|
|
1354
404
|
case "text": {
|
|
1355
|
-
throw new
|
|
405
|
+
throw new UnsupportedFunctionalityError({
|
|
1356
406
|
functionality: "text file parts"
|
|
1357
407
|
});
|
|
1358
408
|
}
|
|
1359
409
|
case "url":
|
|
1360
410
|
case "data": {
|
|
1361
|
-
if (
|
|
1362
|
-
const imageUrl = block.data.type === "url" ? block.data.url.toString() : `data:${
|
|
1363
|
-
const filePartOptions = await
|
|
411
|
+
if (getTopLevelMediaType(block.mediaType) === "image") {
|
|
412
|
+
const imageUrl = block.data.type === "url" ? block.data.url.toString() : `data:${resolveFullMediaType({ part: block })};base64,${convertToBase64(block.data.data)}`;
|
|
413
|
+
const filePartOptions = await parseProviderOptions2({
|
|
1364
414
|
provider: "xai",
|
|
1365
415
|
providerOptions: block.providerOptions,
|
|
1366
416
|
schema: xaiFilePartProviderOptions
|
|
@@ -1378,7 +428,7 @@ async function convertToXaiResponsesInput({
|
|
|
1378
428
|
file_url: block.data.url.toString()
|
|
1379
429
|
});
|
|
1380
430
|
} else {
|
|
1381
|
-
throw new
|
|
431
|
+
throw new UnsupportedFunctionalityError({
|
|
1382
432
|
functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`
|
|
1383
433
|
});
|
|
1384
434
|
}
|
|
@@ -1511,10 +561,10 @@ async function convertToXaiResponsesInput({
|
|
|
1511
561
|
break;
|
|
1512
562
|
}
|
|
1513
563
|
case "file": {
|
|
1514
|
-
if (
|
|
564
|
+
if (getTopLevelMediaType(item.mediaType) === "image" && (item.data.type === "data" || item.data.type === "url")) {
|
|
1515
565
|
outputValue.push({
|
|
1516
566
|
type: "input_image",
|
|
1517
|
-
image_url: item.data.type === "url" ? item.data.url.toString() : `data:${
|
|
567
|
+
image_url: item.data.type === "url" ? item.data.url.toString() : `data:${resolveFullMediaType({ part: item })};base64,${convertToBase64(item.data.data)}`
|
|
1518
568
|
});
|
|
1519
569
|
}
|
|
1520
570
|
break;
|
|
@@ -1595,484 +645,484 @@ function mapXaiResponsesFinishReason(finishReason) {
|
|
|
1595
645
|
}
|
|
1596
646
|
|
|
1597
647
|
// src/responses/xai-responses-api.ts
|
|
1598
|
-
import { z as
|
|
1599
|
-
var annotationSchema =
|
|
1600
|
-
|
|
1601
|
-
type:
|
|
1602
|
-
url:
|
|
1603
|
-
title:
|
|
648
|
+
import { z as z6 } from "zod/v4";
|
|
649
|
+
var annotationSchema = z6.union([
|
|
650
|
+
z6.object({
|
|
651
|
+
type: z6.literal("url_citation"),
|
|
652
|
+
url: z6.string(),
|
|
653
|
+
title: z6.string().optional()
|
|
1604
654
|
}),
|
|
1605
|
-
|
|
1606
|
-
type:
|
|
655
|
+
z6.object({
|
|
656
|
+
type: z6.string()
|
|
1607
657
|
})
|
|
1608
658
|
]);
|
|
1609
|
-
var messageContentPartSchema =
|
|
1610
|
-
type:
|
|
1611
|
-
text:
|
|
1612
|
-
logprobs:
|
|
1613
|
-
annotations:
|
|
659
|
+
var messageContentPartSchema = z6.object({
|
|
660
|
+
type: z6.string(),
|
|
661
|
+
text: z6.string().optional(),
|
|
662
|
+
logprobs: z6.array(z6.any()).optional(),
|
|
663
|
+
annotations: z6.array(annotationSchema).optional()
|
|
1614
664
|
});
|
|
1615
|
-
var reasoningSummaryPartSchema =
|
|
1616
|
-
type:
|
|
1617
|
-
text:
|
|
665
|
+
var reasoningSummaryPartSchema = z6.object({
|
|
666
|
+
type: z6.string(),
|
|
667
|
+
text: z6.string()
|
|
1618
668
|
});
|
|
1619
|
-
var toolCallSchema =
|
|
1620
|
-
name:
|
|
1621
|
-
arguments:
|
|
1622
|
-
input:
|
|
1623
|
-
call_id:
|
|
1624
|
-
id:
|
|
1625
|
-
status:
|
|
1626
|
-
action:
|
|
669
|
+
var toolCallSchema = z6.object({
|
|
670
|
+
name: z6.string().optional(),
|
|
671
|
+
arguments: z6.string().optional(),
|
|
672
|
+
input: z6.string().optional(),
|
|
673
|
+
call_id: z6.string().optional(),
|
|
674
|
+
id: z6.string(),
|
|
675
|
+
status: z6.string(),
|
|
676
|
+
action: z6.any().optional()
|
|
1627
677
|
});
|
|
1628
|
-
var webSearchWireSourceSchema =
|
|
1629
|
-
type:
|
|
1630
|
-
url:
|
|
678
|
+
var webSearchWireSourceSchema = z6.object({
|
|
679
|
+
type: z6.literal("url"),
|
|
680
|
+
url: z6.string()
|
|
1631
681
|
});
|
|
1632
|
-
var webSearchWireActionSchema =
|
|
1633
|
-
|
|
1634
|
-
type:
|
|
1635
|
-
query:
|
|
1636
|
-
queries:
|
|
1637
|
-
sources:
|
|
682
|
+
var webSearchWireActionSchema = z6.discriminatedUnion("type", [
|
|
683
|
+
z6.object({
|
|
684
|
+
type: z6.literal("search"),
|
|
685
|
+
query: z6.string().nullish(),
|
|
686
|
+
queries: z6.array(z6.string()).nullish(),
|
|
687
|
+
sources: z6.array(z6.unknown()).nullish()
|
|
1638
688
|
}),
|
|
1639
|
-
|
|
1640
|
-
type:
|
|
1641
|
-
url:
|
|
1642
|
-
sources:
|
|
689
|
+
z6.object({
|
|
690
|
+
type: z6.literal("open_page"),
|
|
691
|
+
url: z6.string().nullish(),
|
|
692
|
+
sources: z6.array(z6.unknown()).nullish()
|
|
1643
693
|
}),
|
|
1644
|
-
|
|
1645
|
-
type:
|
|
1646
|
-
url:
|
|
1647
|
-
pattern:
|
|
1648
|
-
sources:
|
|
694
|
+
z6.object({
|
|
695
|
+
type: z6.literal("find_in_page"),
|
|
696
|
+
url: z6.string().nullish(),
|
|
697
|
+
pattern: z6.string().nullish(),
|
|
698
|
+
sources: z6.array(z6.unknown()).nullish()
|
|
1649
699
|
})
|
|
1650
700
|
]);
|
|
1651
|
-
var mcpCallSchema =
|
|
1652
|
-
name:
|
|
1653
|
-
arguments:
|
|
1654
|
-
output:
|
|
1655
|
-
error:
|
|
1656
|
-
id:
|
|
1657
|
-
status:
|
|
1658
|
-
server_label:
|
|
701
|
+
var mcpCallSchema = z6.object({
|
|
702
|
+
name: z6.string().optional(),
|
|
703
|
+
arguments: z6.string().optional(),
|
|
704
|
+
output: z6.string().optional(),
|
|
705
|
+
error: z6.string().optional(),
|
|
706
|
+
id: z6.string(),
|
|
707
|
+
status: z6.string(),
|
|
708
|
+
server_label: z6.string().optional()
|
|
1659
709
|
});
|
|
1660
|
-
var outputItemSchema =
|
|
1661
|
-
|
|
1662
|
-
type:
|
|
710
|
+
var outputItemSchema = z6.discriminatedUnion("type", [
|
|
711
|
+
z6.object({
|
|
712
|
+
type: z6.literal("web_search_call"),
|
|
1663
713
|
...toolCallSchema.shape
|
|
1664
714
|
}),
|
|
1665
|
-
|
|
1666
|
-
type:
|
|
715
|
+
z6.object({
|
|
716
|
+
type: z6.literal("x_search_call"),
|
|
1667
717
|
...toolCallSchema.shape
|
|
1668
718
|
}),
|
|
1669
|
-
|
|
1670
|
-
type:
|
|
719
|
+
z6.object({
|
|
720
|
+
type: z6.literal("code_interpreter_call"),
|
|
1671
721
|
...toolCallSchema.shape
|
|
1672
722
|
}),
|
|
1673
|
-
|
|
1674
|
-
type:
|
|
723
|
+
z6.object({
|
|
724
|
+
type: z6.literal("code_execution_call"),
|
|
1675
725
|
...toolCallSchema.shape
|
|
1676
726
|
}),
|
|
1677
|
-
|
|
1678
|
-
type:
|
|
727
|
+
z6.object({
|
|
728
|
+
type: z6.literal("view_image_call"),
|
|
1679
729
|
...toolCallSchema.shape
|
|
1680
730
|
}),
|
|
1681
|
-
|
|
1682
|
-
type:
|
|
731
|
+
z6.object({
|
|
732
|
+
type: z6.literal("view_x_video_call"),
|
|
1683
733
|
...toolCallSchema.shape
|
|
1684
734
|
}),
|
|
1685
|
-
|
|
1686
|
-
type:
|
|
1687
|
-
id:
|
|
1688
|
-
status:
|
|
1689
|
-
queries:
|
|
1690
|
-
results:
|
|
1691
|
-
|
|
1692
|
-
file_id:
|
|
1693
|
-
filename:
|
|
1694
|
-
score:
|
|
1695
|
-
text:
|
|
735
|
+
z6.object({
|
|
736
|
+
type: z6.literal("file_search_call"),
|
|
737
|
+
id: z6.string(),
|
|
738
|
+
status: z6.string(),
|
|
739
|
+
queries: z6.array(z6.string()).optional(),
|
|
740
|
+
results: z6.array(
|
|
741
|
+
z6.object({
|
|
742
|
+
file_id: z6.string(),
|
|
743
|
+
filename: z6.string(),
|
|
744
|
+
score: z6.number(),
|
|
745
|
+
text: z6.string()
|
|
1696
746
|
})
|
|
1697
747
|
).nullish()
|
|
1698
748
|
}),
|
|
1699
|
-
|
|
1700
|
-
type:
|
|
1701
|
-
id:
|
|
1702
|
-
status:
|
|
1703
|
-
prompt:
|
|
1704
|
-
result:
|
|
749
|
+
z6.object({
|
|
750
|
+
type: z6.literal("image_generation_call"),
|
|
751
|
+
id: z6.string(),
|
|
752
|
+
status: z6.string(),
|
|
753
|
+
prompt: z6.string().nullish(),
|
|
754
|
+
result: z6.string().nullish()
|
|
1705
755
|
}),
|
|
1706
|
-
|
|
1707
|
-
type:
|
|
756
|
+
z6.object({
|
|
757
|
+
type: z6.literal("custom_tool_call"),
|
|
1708
758
|
...toolCallSchema.shape
|
|
1709
759
|
}),
|
|
1710
|
-
|
|
1711
|
-
type:
|
|
760
|
+
z6.object({
|
|
761
|
+
type: z6.literal("mcp_call"),
|
|
1712
762
|
...mcpCallSchema.shape
|
|
1713
763
|
}),
|
|
1714
|
-
|
|
1715
|
-
type:
|
|
1716
|
-
role:
|
|
1717
|
-
content:
|
|
1718
|
-
id:
|
|
1719
|
-
status:
|
|
764
|
+
z6.object({
|
|
765
|
+
type: z6.literal("message"),
|
|
766
|
+
role: z6.string(),
|
|
767
|
+
content: z6.array(messageContentPartSchema),
|
|
768
|
+
id: z6.string(),
|
|
769
|
+
status: z6.string()
|
|
1720
770
|
}),
|
|
1721
|
-
|
|
1722
|
-
type:
|
|
1723
|
-
name:
|
|
1724
|
-
arguments:
|
|
1725
|
-
call_id:
|
|
1726
|
-
id:
|
|
771
|
+
z6.object({
|
|
772
|
+
type: z6.literal("function_call"),
|
|
773
|
+
name: z6.string(),
|
|
774
|
+
arguments: z6.string(),
|
|
775
|
+
call_id: z6.string(),
|
|
776
|
+
id: z6.string()
|
|
1727
777
|
}),
|
|
1728
|
-
|
|
1729
|
-
type:
|
|
1730
|
-
id:
|
|
1731
|
-
summary:
|
|
1732
|
-
content:
|
|
1733
|
-
status:
|
|
1734
|
-
encrypted_content:
|
|
778
|
+
z6.object({
|
|
779
|
+
type: z6.literal("reasoning"),
|
|
780
|
+
id: z6.string(),
|
|
781
|
+
summary: z6.array(reasoningSummaryPartSchema),
|
|
782
|
+
content: z6.array(z6.object({ type: z6.string(), text: z6.string() })).nullish(),
|
|
783
|
+
status: z6.string(),
|
|
784
|
+
encrypted_content: z6.string().nullish()
|
|
1735
785
|
})
|
|
1736
786
|
]);
|
|
1737
|
-
var xaiResponsesUsageSchema =
|
|
1738
|
-
input_tokens:
|
|
1739
|
-
output_tokens:
|
|
1740
|
-
total_tokens:
|
|
1741
|
-
input_tokens_details:
|
|
1742
|
-
cached_tokens:
|
|
1743
|
-
}).catchall(
|
|
1744
|
-
output_tokens_details:
|
|
1745
|
-
reasoning_tokens:
|
|
1746
|
-
}).catchall(
|
|
1747
|
-
num_sources_used:
|
|
1748
|
-
num_server_side_tools_used:
|
|
1749
|
-
cost_in_usd_ticks:
|
|
1750
|
-
}).catchall(
|
|
1751
|
-
var xaiResponsesResponseSchema =
|
|
1752
|
-
id:
|
|
1753
|
-
created_at:
|
|
1754
|
-
model:
|
|
1755
|
-
object:
|
|
1756
|
-
output:
|
|
787
|
+
var xaiResponsesUsageSchema = z6.object({
|
|
788
|
+
input_tokens: z6.number(),
|
|
789
|
+
output_tokens: z6.number(),
|
|
790
|
+
total_tokens: z6.number().optional(),
|
|
791
|
+
input_tokens_details: z6.object({
|
|
792
|
+
cached_tokens: z6.number().optional()
|
|
793
|
+
}).catchall(z6.json()).optional(),
|
|
794
|
+
output_tokens_details: z6.object({
|
|
795
|
+
reasoning_tokens: z6.number().optional()
|
|
796
|
+
}).catchall(z6.json()).optional(),
|
|
797
|
+
num_sources_used: z6.number().optional(),
|
|
798
|
+
num_server_side_tools_used: z6.number().optional(),
|
|
799
|
+
cost_in_usd_ticks: z6.number().nullish()
|
|
800
|
+
}).catchall(z6.json());
|
|
801
|
+
var xaiResponsesResponseSchema = z6.object({
|
|
802
|
+
id: z6.string().nullish(),
|
|
803
|
+
created_at: z6.number().nullish(),
|
|
804
|
+
model: z6.string().nullish(),
|
|
805
|
+
object: z6.literal("response"),
|
|
806
|
+
output: z6.array(outputItemSchema),
|
|
1757
807
|
usage: xaiResponsesUsageSchema.nullish(),
|
|
1758
|
-
status:
|
|
1759
|
-
service_tier:
|
|
808
|
+
status: z6.string(),
|
|
809
|
+
service_tier: z6.string().nullish()
|
|
1760
810
|
});
|
|
1761
|
-
var xaiResponsesChunkSchema =
|
|
1762
|
-
|
|
1763
|
-
type:
|
|
811
|
+
var xaiResponsesChunkSchema = z6.union([
|
|
812
|
+
z6.object({
|
|
813
|
+
type: z6.literal("response.created"),
|
|
1764
814
|
response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
|
|
1765
815
|
}),
|
|
1766
|
-
|
|
1767
|
-
type:
|
|
816
|
+
z6.object({
|
|
817
|
+
type: z6.literal("response.in_progress"),
|
|
1768
818
|
response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
|
|
1769
819
|
}),
|
|
1770
|
-
|
|
1771
|
-
type:
|
|
820
|
+
z6.object({
|
|
821
|
+
type: z6.literal("response.output_item.added"),
|
|
1772
822
|
item: outputItemSchema,
|
|
1773
|
-
output_index:
|
|
823
|
+
output_index: z6.number()
|
|
1774
824
|
}),
|
|
1775
|
-
|
|
1776
|
-
type:
|
|
825
|
+
z6.object({
|
|
826
|
+
type: z6.literal("response.output_item.done"),
|
|
1777
827
|
item: outputItemSchema,
|
|
1778
|
-
output_index:
|
|
828
|
+
output_index: z6.number()
|
|
1779
829
|
}),
|
|
1780
|
-
|
|
1781
|
-
type:
|
|
1782
|
-
item_id:
|
|
1783
|
-
output_index:
|
|
1784
|
-
content_index:
|
|
830
|
+
z6.object({
|
|
831
|
+
type: z6.literal("response.content_part.added"),
|
|
832
|
+
item_id: z6.string(),
|
|
833
|
+
output_index: z6.number(),
|
|
834
|
+
content_index: z6.number(),
|
|
1785
835
|
part: messageContentPartSchema
|
|
1786
836
|
}),
|
|
1787
|
-
|
|
1788
|
-
type:
|
|
1789
|
-
item_id:
|
|
1790
|
-
output_index:
|
|
1791
|
-
content_index:
|
|
837
|
+
z6.object({
|
|
838
|
+
type: z6.literal("response.content_part.done"),
|
|
839
|
+
item_id: z6.string(),
|
|
840
|
+
output_index: z6.number(),
|
|
841
|
+
content_index: z6.number(),
|
|
1792
842
|
part: messageContentPartSchema
|
|
1793
843
|
}),
|
|
1794
|
-
|
|
1795
|
-
type:
|
|
1796
|
-
item_id:
|
|
1797
|
-
output_index:
|
|
1798
|
-
content_index:
|
|
1799
|
-
delta:
|
|
1800
|
-
logprobs:
|
|
844
|
+
z6.object({
|
|
845
|
+
type: z6.literal("response.output_text.delta"),
|
|
846
|
+
item_id: z6.string(),
|
|
847
|
+
output_index: z6.number(),
|
|
848
|
+
content_index: z6.number(),
|
|
849
|
+
delta: z6.string(),
|
|
850
|
+
logprobs: z6.array(z6.any()).optional()
|
|
1801
851
|
}),
|
|
1802
|
-
|
|
1803
|
-
type:
|
|
1804
|
-
item_id:
|
|
1805
|
-
output_index:
|
|
1806
|
-
content_index:
|
|
1807
|
-
text:
|
|
1808
|
-
logprobs:
|
|
1809
|
-
annotations:
|
|
852
|
+
z6.object({
|
|
853
|
+
type: z6.literal("response.output_text.done"),
|
|
854
|
+
item_id: z6.string(),
|
|
855
|
+
output_index: z6.number(),
|
|
856
|
+
content_index: z6.number(),
|
|
857
|
+
text: z6.string(),
|
|
858
|
+
logprobs: z6.array(z6.any()).optional(),
|
|
859
|
+
annotations: z6.array(annotationSchema).optional()
|
|
1810
860
|
}),
|
|
1811
|
-
|
|
1812
|
-
type:
|
|
1813
|
-
item_id:
|
|
1814
|
-
output_index:
|
|
1815
|
-
content_index:
|
|
1816
|
-
annotation_index:
|
|
861
|
+
z6.object({
|
|
862
|
+
type: z6.literal("response.output_text.annotation.added"),
|
|
863
|
+
item_id: z6.string(),
|
|
864
|
+
output_index: z6.number(),
|
|
865
|
+
content_index: z6.number(),
|
|
866
|
+
annotation_index: z6.number(),
|
|
1817
867
|
annotation: annotationSchema
|
|
1818
868
|
}),
|
|
1819
|
-
|
|
1820
|
-
type:
|
|
1821
|
-
item_id:
|
|
1822
|
-
output_index:
|
|
1823
|
-
summary_index:
|
|
869
|
+
z6.object({
|
|
870
|
+
type: z6.literal("response.reasoning_summary_part.added"),
|
|
871
|
+
item_id: z6.string(),
|
|
872
|
+
output_index: z6.number(),
|
|
873
|
+
summary_index: z6.number(),
|
|
1824
874
|
part: reasoningSummaryPartSchema
|
|
1825
875
|
}),
|
|
1826
|
-
|
|
1827
|
-
type:
|
|
1828
|
-
item_id:
|
|
1829
|
-
output_index:
|
|
1830
|
-
summary_index:
|
|
876
|
+
z6.object({
|
|
877
|
+
type: z6.literal("response.reasoning_summary_part.done"),
|
|
878
|
+
item_id: z6.string(),
|
|
879
|
+
output_index: z6.number(),
|
|
880
|
+
summary_index: z6.number(),
|
|
1831
881
|
part: reasoningSummaryPartSchema
|
|
1832
882
|
}),
|
|
1833
|
-
|
|
1834
|
-
type:
|
|
1835
|
-
item_id:
|
|
1836
|
-
output_index:
|
|
1837
|
-
summary_index:
|
|
1838
|
-
delta:
|
|
883
|
+
z6.object({
|
|
884
|
+
type: z6.literal("response.reasoning_summary_text.delta"),
|
|
885
|
+
item_id: z6.string(),
|
|
886
|
+
output_index: z6.number(),
|
|
887
|
+
summary_index: z6.number(),
|
|
888
|
+
delta: z6.string()
|
|
1839
889
|
}),
|
|
1840
|
-
|
|
1841
|
-
type:
|
|
1842
|
-
item_id:
|
|
1843
|
-
output_index:
|
|
1844
|
-
summary_index:
|
|
1845
|
-
text:
|
|
890
|
+
z6.object({
|
|
891
|
+
type: z6.literal("response.reasoning_summary_text.done"),
|
|
892
|
+
item_id: z6.string(),
|
|
893
|
+
output_index: z6.number(),
|
|
894
|
+
summary_index: z6.number(),
|
|
895
|
+
text: z6.string()
|
|
1846
896
|
}),
|
|
1847
|
-
|
|
1848
|
-
type:
|
|
1849
|
-
item_id:
|
|
1850
|
-
output_index:
|
|
1851
|
-
content_index:
|
|
1852
|
-
delta:
|
|
897
|
+
z6.object({
|
|
898
|
+
type: z6.literal("response.reasoning_text.delta"),
|
|
899
|
+
item_id: z6.string(),
|
|
900
|
+
output_index: z6.number(),
|
|
901
|
+
content_index: z6.number(),
|
|
902
|
+
delta: z6.string()
|
|
1853
903
|
}),
|
|
1854
|
-
|
|
1855
|
-
type:
|
|
1856
|
-
item_id:
|
|
1857
|
-
output_index:
|
|
1858
|
-
content_index:
|
|
1859
|
-
text:
|
|
904
|
+
z6.object({
|
|
905
|
+
type: z6.literal("response.reasoning_text.done"),
|
|
906
|
+
item_id: z6.string(),
|
|
907
|
+
output_index: z6.number(),
|
|
908
|
+
content_index: z6.number(),
|
|
909
|
+
text: z6.string()
|
|
1860
910
|
}),
|
|
1861
|
-
|
|
1862
|
-
type:
|
|
1863
|
-
item_id:
|
|
1864
|
-
output_index:
|
|
911
|
+
z6.object({
|
|
912
|
+
type: z6.literal("response.web_search_call.in_progress"),
|
|
913
|
+
item_id: z6.string(),
|
|
914
|
+
output_index: z6.number()
|
|
1865
915
|
}),
|
|
1866
|
-
|
|
1867
|
-
type:
|
|
1868
|
-
item_id:
|
|
1869
|
-
output_index:
|
|
916
|
+
z6.object({
|
|
917
|
+
type: z6.literal("response.web_search_call.searching"),
|
|
918
|
+
item_id: z6.string(),
|
|
919
|
+
output_index: z6.number()
|
|
1870
920
|
}),
|
|
1871
|
-
|
|
1872
|
-
type:
|
|
1873
|
-
item_id:
|
|
1874
|
-
output_index:
|
|
921
|
+
z6.object({
|
|
922
|
+
type: z6.literal("response.web_search_call.completed"),
|
|
923
|
+
item_id: z6.string(),
|
|
924
|
+
output_index: z6.number()
|
|
1875
925
|
}),
|
|
1876
|
-
|
|
1877
|
-
type:
|
|
1878
|
-
item_id:
|
|
1879
|
-
output_index:
|
|
926
|
+
z6.object({
|
|
927
|
+
type: z6.literal("response.x_search_call.in_progress"),
|
|
928
|
+
item_id: z6.string(),
|
|
929
|
+
output_index: z6.number()
|
|
1880
930
|
}),
|
|
1881
|
-
|
|
1882
|
-
type:
|
|
1883
|
-
item_id:
|
|
1884
|
-
output_index:
|
|
931
|
+
z6.object({
|
|
932
|
+
type: z6.literal("response.x_search_call.searching"),
|
|
933
|
+
item_id: z6.string(),
|
|
934
|
+
output_index: z6.number()
|
|
1885
935
|
}),
|
|
1886
|
-
|
|
1887
|
-
type:
|
|
1888
|
-
item_id:
|
|
1889
|
-
output_index:
|
|
936
|
+
z6.object({
|
|
937
|
+
type: z6.literal("response.x_search_call.completed"),
|
|
938
|
+
item_id: z6.string(),
|
|
939
|
+
output_index: z6.number()
|
|
1890
940
|
}),
|
|
1891
|
-
|
|
1892
|
-
type:
|
|
1893
|
-
item_id:
|
|
1894
|
-
output_index:
|
|
941
|
+
z6.object({
|
|
942
|
+
type: z6.literal("response.file_search_call.in_progress"),
|
|
943
|
+
item_id: z6.string(),
|
|
944
|
+
output_index: z6.number()
|
|
1895
945
|
}),
|
|
1896
|
-
|
|
1897
|
-
type:
|
|
1898
|
-
item_id:
|
|
1899
|
-
output_index:
|
|
946
|
+
z6.object({
|
|
947
|
+
type: z6.literal("response.file_search_call.searching"),
|
|
948
|
+
item_id: z6.string(),
|
|
949
|
+
output_index: z6.number()
|
|
1900
950
|
}),
|
|
1901
|
-
|
|
1902
|
-
type:
|
|
1903
|
-
item_id:
|
|
1904
|
-
output_index:
|
|
951
|
+
z6.object({
|
|
952
|
+
type: z6.literal("response.file_search_call.completed"),
|
|
953
|
+
item_id: z6.string(),
|
|
954
|
+
output_index: z6.number()
|
|
1905
955
|
}),
|
|
1906
|
-
|
|
1907
|
-
type:
|
|
1908
|
-
item_id:
|
|
1909
|
-
output_index:
|
|
956
|
+
z6.object({
|
|
957
|
+
type: z6.literal("response.image_generation_call.in_progress"),
|
|
958
|
+
item_id: z6.string(),
|
|
959
|
+
output_index: z6.number()
|
|
1910
960
|
}),
|
|
1911
|
-
|
|
1912
|
-
type:
|
|
1913
|
-
item_id:
|
|
1914
|
-
output_index:
|
|
961
|
+
z6.object({
|
|
962
|
+
type: z6.literal("response.image_generation_call.generating"),
|
|
963
|
+
item_id: z6.string(),
|
|
964
|
+
output_index: z6.number()
|
|
1915
965
|
}),
|
|
1916
|
-
|
|
1917
|
-
type:
|
|
1918
|
-
item_id:
|
|
1919
|
-
output_index:
|
|
966
|
+
z6.object({
|
|
967
|
+
type: z6.literal("response.image_generation_call.completed"),
|
|
968
|
+
item_id: z6.string(),
|
|
969
|
+
output_index: z6.number()
|
|
1920
970
|
}),
|
|
1921
|
-
|
|
1922
|
-
type:
|
|
1923
|
-
item_id:
|
|
1924
|
-
output_index:
|
|
971
|
+
z6.object({
|
|
972
|
+
type: z6.literal("response.code_execution_call.in_progress"),
|
|
973
|
+
item_id: z6.string(),
|
|
974
|
+
output_index: z6.number()
|
|
1925
975
|
}),
|
|
1926
|
-
|
|
1927
|
-
type:
|
|
1928
|
-
item_id:
|
|
1929
|
-
output_index:
|
|
976
|
+
z6.object({
|
|
977
|
+
type: z6.literal("response.code_execution_call.executing"),
|
|
978
|
+
item_id: z6.string(),
|
|
979
|
+
output_index: z6.number()
|
|
1930
980
|
}),
|
|
1931
|
-
|
|
1932
|
-
type:
|
|
1933
|
-
item_id:
|
|
1934
|
-
output_index:
|
|
981
|
+
z6.object({
|
|
982
|
+
type: z6.literal("response.code_execution_call.completed"),
|
|
983
|
+
item_id: z6.string(),
|
|
984
|
+
output_index: z6.number()
|
|
1935
985
|
}),
|
|
1936
|
-
|
|
1937
|
-
type:
|
|
1938
|
-
item_id:
|
|
1939
|
-
output_index:
|
|
986
|
+
z6.object({
|
|
987
|
+
type: z6.literal("response.code_interpreter_call.in_progress"),
|
|
988
|
+
item_id: z6.string(),
|
|
989
|
+
output_index: z6.number()
|
|
1940
990
|
}),
|
|
1941
|
-
|
|
1942
|
-
type:
|
|
1943
|
-
item_id:
|
|
1944
|
-
output_index:
|
|
991
|
+
z6.object({
|
|
992
|
+
type: z6.literal("response.code_interpreter_call.executing"),
|
|
993
|
+
item_id: z6.string(),
|
|
994
|
+
output_index: z6.number()
|
|
1945
995
|
}),
|
|
1946
|
-
|
|
1947
|
-
type:
|
|
1948
|
-
item_id:
|
|
1949
|
-
output_index:
|
|
996
|
+
z6.object({
|
|
997
|
+
type: z6.literal("response.code_interpreter_call.interpreting"),
|
|
998
|
+
item_id: z6.string(),
|
|
999
|
+
output_index: z6.number()
|
|
1950
1000
|
}),
|
|
1951
|
-
|
|
1952
|
-
type:
|
|
1953
|
-
item_id:
|
|
1954
|
-
output_index:
|
|
1001
|
+
z6.object({
|
|
1002
|
+
type: z6.literal("response.code_interpreter_call.completed"),
|
|
1003
|
+
item_id: z6.string(),
|
|
1004
|
+
output_index: z6.number()
|
|
1955
1005
|
}),
|
|
1956
1006
|
// Code interpreter code streaming events
|
|
1957
|
-
|
|
1958
|
-
type:
|
|
1959
|
-
item_id:
|
|
1960
|
-
output_index:
|
|
1961
|
-
delta:
|
|
1007
|
+
z6.object({
|
|
1008
|
+
type: z6.literal("response.code_interpreter_call_code.delta"),
|
|
1009
|
+
item_id: z6.string(),
|
|
1010
|
+
output_index: z6.number(),
|
|
1011
|
+
delta: z6.string()
|
|
1962
1012
|
}),
|
|
1963
|
-
|
|
1964
|
-
type:
|
|
1965
|
-
item_id:
|
|
1966
|
-
output_index:
|
|
1967
|
-
code:
|
|
1013
|
+
z6.object({
|
|
1014
|
+
type: z6.literal("response.code_interpreter_call_code.done"),
|
|
1015
|
+
item_id: z6.string(),
|
|
1016
|
+
output_index: z6.number(),
|
|
1017
|
+
code: z6.string()
|
|
1968
1018
|
}),
|
|
1969
|
-
|
|
1970
|
-
type:
|
|
1971
|
-
item_id:
|
|
1972
|
-
output_index:
|
|
1973
|
-
delta:
|
|
1019
|
+
z6.object({
|
|
1020
|
+
type: z6.literal("response.custom_tool_call_input.delta"),
|
|
1021
|
+
item_id: z6.string(),
|
|
1022
|
+
output_index: z6.number(),
|
|
1023
|
+
delta: z6.string()
|
|
1974
1024
|
}),
|
|
1975
|
-
|
|
1976
|
-
type:
|
|
1977
|
-
item_id:
|
|
1978
|
-
output_index:
|
|
1979
|
-
input:
|
|
1025
|
+
z6.object({
|
|
1026
|
+
type: z6.literal("response.custom_tool_call_input.done"),
|
|
1027
|
+
item_id: z6.string(),
|
|
1028
|
+
output_index: z6.number(),
|
|
1029
|
+
input: z6.string()
|
|
1980
1030
|
}),
|
|
1981
1031
|
// Function call arguments streaming events (standard function tools)
|
|
1982
|
-
|
|
1983
|
-
type:
|
|
1984
|
-
item_id:
|
|
1985
|
-
output_index:
|
|
1986
|
-
delta:
|
|
1032
|
+
z6.object({
|
|
1033
|
+
type: z6.literal("response.function_call_arguments.delta"),
|
|
1034
|
+
item_id: z6.string(),
|
|
1035
|
+
output_index: z6.number(),
|
|
1036
|
+
delta: z6.string()
|
|
1987
1037
|
}),
|
|
1988
|
-
|
|
1989
|
-
type:
|
|
1990
|
-
item_id:
|
|
1991
|
-
output_index:
|
|
1992
|
-
arguments:
|
|
1038
|
+
z6.object({
|
|
1039
|
+
type: z6.literal("response.function_call_arguments.done"),
|
|
1040
|
+
item_id: z6.string(),
|
|
1041
|
+
output_index: z6.number(),
|
|
1042
|
+
arguments: z6.string()
|
|
1993
1043
|
}),
|
|
1994
|
-
|
|
1995
|
-
type:
|
|
1996
|
-
item_id:
|
|
1997
|
-
output_index:
|
|
1044
|
+
z6.object({
|
|
1045
|
+
type: z6.literal("response.mcp_call.in_progress"),
|
|
1046
|
+
item_id: z6.string(),
|
|
1047
|
+
output_index: z6.number()
|
|
1998
1048
|
}),
|
|
1999
|
-
|
|
2000
|
-
type:
|
|
2001
|
-
item_id:
|
|
2002
|
-
output_index:
|
|
1049
|
+
z6.object({
|
|
1050
|
+
type: z6.literal("response.mcp_call.executing"),
|
|
1051
|
+
item_id: z6.string(),
|
|
1052
|
+
output_index: z6.number()
|
|
2003
1053
|
}),
|
|
2004
|
-
|
|
2005
|
-
type:
|
|
2006
|
-
item_id:
|
|
2007
|
-
output_index:
|
|
1054
|
+
z6.object({
|
|
1055
|
+
type: z6.literal("response.mcp_call.completed"),
|
|
1056
|
+
item_id: z6.string(),
|
|
1057
|
+
output_index: z6.number()
|
|
2008
1058
|
}),
|
|
2009
|
-
|
|
2010
|
-
type:
|
|
2011
|
-
item_id:
|
|
2012
|
-
output_index:
|
|
1059
|
+
z6.object({
|
|
1060
|
+
type: z6.literal("response.mcp_call.failed"),
|
|
1061
|
+
item_id: z6.string(),
|
|
1062
|
+
output_index: z6.number()
|
|
2013
1063
|
}),
|
|
2014
|
-
|
|
2015
|
-
type:
|
|
2016
|
-
item_id:
|
|
2017
|
-
output_index:
|
|
2018
|
-
delta:
|
|
1064
|
+
z6.object({
|
|
1065
|
+
type: z6.literal("response.mcp_call_arguments.delta"),
|
|
1066
|
+
item_id: z6.string(),
|
|
1067
|
+
output_index: z6.number(),
|
|
1068
|
+
delta: z6.string()
|
|
2019
1069
|
}),
|
|
2020
|
-
|
|
2021
|
-
type:
|
|
2022
|
-
item_id:
|
|
2023
|
-
output_index:
|
|
2024
|
-
arguments:
|
|
1070
|
+
z6.object({
|
|
1071
|
+
type: z6.literal("response.mcp_call_arguments.done"),
|
|
1072
|
+
item_id: z6.string(),
|
|
1073
|
+
output_index: z6.number(),
|
|
1074
|
+
arguments: z6.string().optional()
|
|
2025
1075
|
}),
|
|
2026
|
-
|
|
2027
|
-
type:
|
|
2028
|
-
item_id:
|
|
2029
|
-
output_index:
|
|
2030
|
-
delta:
|
|
1076
|
+
z6.object({
|
|
1077
|
+
type: z6.literal("response.mcp_call_output.delta"),
|
|
1078
|
+
item_id: z6.string(),
|
|
1079
|
+
output_index: z6.number(),
|
|
1080
|
+
delta: z6.string()
|
|
2031
1081
|
}),
|
|
2032
|
-
|
|
2033
|
-
type:
|
|
2034
|
-
item_id:
|
|
2035
|
-
output_index:
|
|
2036
|
-
output:
|
|
1082
|
+
z6.object({
|
|
1083
|
+
type: z6.literal("response.mcp_call_output.done"),
|
|
1084
|
+
item_id: z6.string(),
|
|
1085
|
+
output_index: z6.number(),
|
|
1086
|
+
output: z6.string().optional()
|
|
2037
1087
|
}),
|
|
2038
|
-
|
|
2039
|
-
type:
|
|
2040
|
-
response:
|
|
2041
|
-
incomplete_details:
|
|
1088
|
+
z6.object({
|
|
1089
|
+
type: z6.literal("response.incomplete"),
|
|
1090
|
+
response: z6.object({
|
|
1091
|
+
incomplete_details: z6.object({ reason: z6.string() }).nullish(),
|
|
2042
1092
|
usage: xaiResponsesUsageSchema.nullish(),
|
|
2043
|
-
service_tier:
|
|
1093
|
+
service_tier: z6.string().nullish()
|
|
2044
1094
|
})
|
|
2045
1095
|
}),
|
|
2046
|
-
|
|
2047
|
-
type:
|
|
2048
|
-
response:
|
|
2049
|
-
error:
|
|
2050
|
-
code:
|
|
2051
|
-
message:
|
|
1096
|
+
z6.object({
|
|
1097
|
+
type: z6.literal("response.failed"),
|
|
1098
|
+
response: z6.object({
|
|
1099
|
+
error: z6.object({
|
|
1100
|
+
code: z6.string().nullish(),
|
|
1101
|
+
message: z6.string()
|
|
2052
1102
|
}).nullish(),
|
|
2053
|
-
incomplete_details:
|
|
1103
|
+
incomplete_details: z6.object({ reason: z6.string() }).nullish(),
|
|
2054
1104
|
usage: xaiResponsesUsageSchema.nullish()
|
|
2055
1105
|
})
|
|
2056
1106
|
}),
|
|
2057
|
-
|
|
2058
|
-
type:
|
|
2059
|
-
code:
|
|
2060
|
-
message:
|
|
2061
|
-
param:
|
|
1107
|
+
z6.object({
|
|
1108
|
+
type: z6.literal("error"),
|
|
1109
|
+
code: z6.string().nullish(),
|
|
1110
|
+
message: z6.string(),
|
|
1111
|
+
param: z6.string().nullish()
|
|
2062
1112
|
}),
|
|
2063
|
-
|
|
2064
|
-
type:
|
|
1113
|
+
z6.object({
|
|
1114
|
+
type: z6.literal("response.done"),
|
|
2065
1115
|
response: xaiResponsesResponseSchema
|
|
2066
1116
|
}),
|
|
2067
|
-
|
|
2068
|
-
type:
|
|
1117
|
+
z6.object({
|
|
1118
|
+
type: z6.literal("response.completed"),
|
|
2069
1119
|
response: xaiResponsesResponseSchema
|
|
2070
1120
|
})
|
|
2071
1121
|
]);
|
|
2072
1122
|
|
|
2073
1123
|
// src/responses/xai-responses-language-model-options.ts
|
|
2074
|
-
import { z as
|
|
2075
|
-
var xaiLanguageModelResponsesOptions =
|
|
1124
|
+
import { z as z7 } from "zod/v4";
|
|
1125
|
+
var xaiLanguageModelResponsesOptions = z7.object({
|
|
2076
1126
|
/**
|
|
2077
1127
|
* Constrains how hard a reasoning model thinks before responding.
|
|
2078
1128
|
* Possible values are `none` (disables reasoning entirely; supported by
|
|
@@ -2082,32 +1132,32 @@ var xaiLanguageModelResponsesOptions = z9.object({
|
|
|
2082
1132
|
*
|
|
2083
1133
|
* @see https://docs.x.ai/docs/guides/reasoning
|
|
2084
1134
|
*/
|
|
2085
|
-
reasoningEffort:
|
|
2086
|
-
reasoningSummary:
|
|
2087
|
-
logprobs:
|
|
2088
|
-
topLogprobs:
|
|
2089
|
-
serviceTier:
|
|
1135
|
+
reasoningEffort: z7.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
|
|
1136
|
+
reasoningSummary: z7.enum(["auto", "concise", "detailed"]).optional(),
|
|
1137
|
+
logprobs: z7.boolean().optional(),
|
|
1138
|
+
topLogprobs: z7.number().int().min(0).max(8).optional(),
|
|
1139
|
+
serviceTier: z7.enum(["default", "priority"]).optional(),
|
|
2090
1140
|
/**
|
|
2091
1141
|
* Whether to store the input message(s) and model response for later retrieval.
|
|
2092
1142
|
* Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
|
|
2093
1143
|
* otherwise the API will return an error.
|
|
2094
1144
|
* @default true
|
|
2095
1145
|
*/
|
|
2096
|
-
store:
|
|
1146
|
+
store: z7.boolean().optional(),
|
|
2097
1147
|
/**
|
|
2098
1148
|
* The ID of the previous response from the model.
|
|
2099
1149
|
*/
|
|
2100
|
-
previousResponseId:
|
|
1150
|
+
previousResponseId: z7.string().optional(),
|
|
2101
1151
|
/**
|
|
2102
1152
|
* Specify additional output data to include in the model response.
|
|
2103
1153
|
* Example values: 'file_search_call.results'.
|
|
2104
1154
|
*/
|
|
2105
|
-
include:
|
|
1155
|
+
include: z7.array(z7.enum(["file_search_call.results"])).nullish()
|
|
2106
1156
|
});
|
|
2107
1157
|
|
|
2108
1158
|
// src/responses/xai-responses-prepare-tools.ts
|
|
2109
1159
|
import {
|
|
2110
|
-
UnsupportedFunctionalityError as
|
|
1160
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
2111
1161
|
} from "@ai-sdk/provider";
|
|
2112
1162
|
import { validateTypes } from "@ai-sdk/provider-utils";
|
|
2113
1163
|
|
|
@@ -2117,25 +1167,25 @@ import {
|
|
|
2117
1167
|
lazySchema as lazySchema2,
|
|
2118
1168
|
zodSchema as zodSchema2
|
|
2119
1169
|
} from "@ai-sdk/provider-utils";
|
|
2120
|
-
import { z as
|
|
1170
|
+
import { z as z8 } from "zod/v4";
|
|
2121
1171
|
var fileSearchArgsSchema = lazySchema2(
|
|
2122
1172
|
() => zodSchema2(
|
|
2123
|
-
|
|
2124
|
-
vectorStoreIds:
|
|
2125
|
-
maxNumResults:
|
|
1173
|
+
z8.object({
|
|
1174
|
+
vectorStoreIds: z8.array(z8.string()),
|
|
1175
|
+
maxNumResults: z8.number().optional()
|
|
2126
1176
|
})
|
|
2127
1177
|
)
|
|
2128
1178
|
);
|
|
2129
1179
|
var fileSearchOutputSchema = lazySchema2(
|
|
2130
1180
|
() => zodSchema2(
|
|
2131
|
-
|
|
2132
|
-
queries:
|
|
2133
|
-
results:
|
|
2134
|
-
|
|
2135
|
-
fileId:
|
|
2136
|
-
filename:
|
|
2137
|
-
score:
|
|
2138
|
-
text:
|
|
1181
|
+
z8.object({
|
|
1182
|
+
queries: z8.array(z8.string()),
|
|
1183
|
+
results: z8.array(
|
|
1184
|
+
z8.object({
|
|
1185
|
+
fileId: z8.string(),
|
|
1186
|
+
filename: z8.string(),
|
|
1187
|
+
score: z8.number().min(0).max(1),
|
|
1188
|
+
text: z8.string()
|
|
2139
1189
|
})
|
|
2140
1190
|
).nullable()
|
|
2141
1191
|
})
|
|
@@ -2143,7 +1193,7 @@ var fileSearchOutputSchema = lazySchema2(
|
|
|
2143
1193
|
);
|
|
2144
1194
|
var fileSearchToolFactory = createProviderExecutedToolFactory({
|
|
2145
1195
|
id: "xai.file_search",
|
|
2146
|
-
inputSchema: lazySchema2(() => zodSchema2(
|
|
1196
|
+
inputSchema: lazySchema2(() => zodSchema2(z8.object({}))),
|
|
2147
1197
|
outputSchema: fileSearchOutputSchema
|
|
2148
1198
|
});
|
|
2149
1199
|
var fileSearch = (args) => fileSearchToolFactory(args);
|
|
@@ -2154,20 +1204,20 @@ import {
|
|
|
2154
1204
|
lazySchema as lazySchema3,
|
|
2155
1205
|
zodSchema as zodSchema3
|
|
2156
1206
|
} from "@ai-sdk/provider-utils";
|
|
2157
|
-
import { z as
|
|
1207
|
+
import { z as z9 } from "zod/v4";
|
|
2158
1208
|
var imageGenerationArgsSchema = lazySchema3(
|
|
2159
1209
|
() => zodSchema3(
|
|
2160
|
-
|
|
2161
|
-
action:
|
|
1210
|
+
z9.object({
|
|
1211
|
+
action: z9.enum(["auto", "generate", "edit"]).optional()
|
|
2162
1212
|
})
|
|
2163
1213
|
)
|
|
2164
1214
|
);
|
|
2165
|
-
var imageGenerationInputSchema = lazySchema3(() => zodSchema3(
|
|
1215
|
+
var imageGenerationInputSchema = lazySchema3(() => zodSchema3(z9.object({})));
|
|
2166
1216
|
var imageGenerationOutputSchema = lazySchema3(
|
|
2167
1217
|
() => zodSchema3(
|
|
2168
|
-
|
|
2169
|
-
result:
|
|
2170
|
-
prompt:
|
|
1218
|
+
z9.object({
|
|
1219
|
+
result: z9.string(),
|
|
1220
|
+
prompt: z9.string().optional()
|
|
2171
1221
|
})
|
|
2172
1222
|
)
|
|
2173
1223
|
);
|
|
@@ -2184,31 +1234,31 @@ import {
|
|
|
2184
1234
|
lazySchema as lazySchema4,
|
|
2185
1235
|
zodSchema as zodSchema4
|
|
2186
1236
|
} from "@ai-sdk/provider-utils";
|
|
2187
|
-
import { z as
|
|
1237
|
+
import { z as z10 } from "zod/v4";
|
|
2188
1238
|
var mcpServerArgsSchema = lazySchema4(
|
|
2189
1239
|
() => zodSchema4(
|
|
2190
|
-
|
|
2191
|
-
serverUrl:
|
|
2192
|
-
serverLabel:
|
|
2193
|
-
serverDescription:
|
|
2194
|
-
allowedTools:
|
|
2195
|
-
headers:
|
|
2196
|
-
authorization:
|
|
1240
|
+
z10.object({
|
|
1241
|
+
serverUrl: z10.string().describe("The URL of the MCP server"),
|
|
1242
|
+
serverLabel: z10.string().optional().describe("A label for the MCP server"),
|
|
1243
|
+
serverDescription: z10.string().optional().describe("Description of the MCP server"),
|
|
1244
|
+
allowedTools: z10.array(z10.string()).optional().describe("List of allowed tool names"),
|
|
1245
|
+
headers: z10.record(z10.string(), z10.string()).optional().describe("Custom headers to send"),
|
|
1246
|
+
authorization: z10.string().optional().describe("Authorization header value")
|
|
2197
1247
|
})
|
|
2198
1248
|
)
|
|
2199
1249
|
);
|
|
2200
1250
|
var mcpServerOutputSchema = lazySchema4(
|
|
2201
1251
|
() => zodSchema4(
|
|
2202
|
-
|
|
2203
|
-
name:
|
|
2204
|
-
arguments:
|
|
2205
|
-
result:
|
|
1252
|
+
z10.object({
|
|
1253
|
+
name: z10.string(),
|
|
1254
|
+
arguments: z10.string(),
|
|
1255
|
+
result: z10.unknown()
|
|
2206
1256
|
})
|
|
2207
1257
|
)
|
|
2208
1258
|
);
|
|
2209
1259
|
var mcpServerToolFactory = createProviderExecutedToolFactory3({
|
|
2210
1260
|
id: "xai.mcp",
|
|
2211
|
-
inputSchema: lazySchema4(() => zodSchema4(
|
|
1261
|
+
inputSchema: lazySchema4(() => zodSchema4(z10.object({}))),
|
|
2212
1262
|
outputSchema: mcpServerOutputSchema
|
|
2213
1263
|
});
|
|
2214
1264
|
var mcpServer = (args) => mcpServerToolFactory(args);
|
|
@@ -2219,43 +1269,43 @@ import {
|
|
|
2219
1269
|
lazySchema as lazySchema5,
|
|
2220
1270
|
zodSchema as zodSchema5
|
|
2221
1271
|
} from "@ai-sdk/provider-utils";
|
|
2222
|
-
import { z as
|
|
1272
|
+
import { z as z11 } from "zod/v4";
|
|
2223
1273
|
var webSearchArgsSchema = lazySchema5(
|
|
2224
1274
|
() => zodSchema5(
|
|
2225
|
-
|
|
2226
|
-
allowedDomains:
|
|
2227
|
-
excludedDomains:
|
|
2228
|
-
enableImageSearch:
|
|
2229
|
-
enableImageUnderstanding:
|
|
1275
|
+
z11.object({
|
|
1276
|
+
allowedDomains: z11.array(z11.string()).max(5).optional(),
|
|
1277
|
+
excludedDomains: z11.array(z11.string()).max(5).optional(),
|
|
1278
|
+
enableImageSearch: z11.boolean().optional(),
|
|
1279
|
+
enableImageUnderstanding: z11.boolean().optional()
|
|
2230
1280
|
})
|
|
2231
1281
|
)
|
|
2232
1282
|
);
|
|
2233
1283
|
var webSearchOutputSchema = lazySchema5(
|
|
2234
1284
|
() => zodSchema5(
|
|
2235
|
-
|
|
2236
|
-
action:
|
|
2237
|
-
|
|
2238
|
-
type:
|
|
2239
|
-
query:
|
|
2240
|
-
queries:
|
|
1285
|
+
z11.object({
|
|
1286
|
+
action: z11.discriminatedUnion("type", [
|
|
1287
|
+
z11.object({
|
|
1288
|
+
type: z11.literal("search"),
|
|
1289
|
+
query: z11.string().optional(),
|
|
1290
|
+
queries: z11.array(z11.string()).optional()
|
|
2241
1291
|
}),
|
|
2242
|
-
|
|
2243
|
-
type:
|
|
2244
|
-
url:
|
|
1292
|
+
z11.object({
|
|
1293
|
+
type: z11.literal("openPage"),
|
|
1294
|
+
url: z11.string().nullish()
|
|
2245
1295
|
}),
|
|
2246
|
-
|
|
2247
|
-
type:
|
|
2248
|
-
url:
|
|
2249
|
-
pattern:
|
|
1296
|
+
z11.object({
|
|
1297
|
+
type: z11.literal("findInPage"),
|
|
1298
|
+
url: z11.string().nullish(),
|
|
1299
|
+
pattern: z11.string().nullish()
|
|
2250
1300
|
})
|
|
2251
1301
|
]).optional(),
|
|
2252
|
-
sources:
|
|
1302
|
+
sources: z11.array(z11.object({ type: z11.literal("url"), url: z11.string() })).optional()
|
|
2253
1303
|
})
|
|
2254
1304
|
)
|
|
2255
1305
|
);
|
|
2256
1306
|
var webSearchToolFactory = createProviderExecutedToolFactory4({
|
|
2257
1307
|
id: "xai.web_search",
|
|
2258
|
-
inputSchema: lazySchema5(() => zodSchema5(
|
|
1308
|
+
inputSchema: lazySchema5(() => zodSchema5(z11.object({}))),
|
|
2259
1309
|
outputSchema: webSearchOutputSchema
|
|
2260
1310
|
});
|
|
2261
1311
|
var webSearch = (args = {}) => webSearchToolFactory(args);
|
|
@@ -2266,29 +1316,29 @@ import {
|
|
|
2266
1316
|
lazySchema as lazySchema6,
|
|
2267
1317
|
zodSchema as zodSchema6
|
|
2268
1318
|
} from "@ai-sdk/provider-utils";
|
|
2269
|
-
import { z as
|
|
1319
|
+
import { z as z12 } from "zod/v4";
|
|
2270
1320
|
var xSearchArgsSchema = lazySchema6(
|
|
2271
1321
|
() => zodSchema6(
|
|
2272
|
-
|
|
2273
|
-
allowedXHandles:
|
|
2274
|
-
excludedXHandles:
|
|
2275
|
-
fromDate:
|
|
2276
|
-
toDate:
|
|
2277
|
-
enableImageUnderstanding:
|
|
2278
|
-
enableVideoUnderstanding:
|
|
1322
|
+
z12.object({
|
|
1323
|
+
allowedXHandles: z12.array(z12.string()).max(10).optional(),
|
|
1324
|
+
excludedXHandles: z12.array(z12.string()).max(10).optional(),
|
|
1325
|
+
fromDate: z12.string().optional(),
|
|
1326
|
+
toDate: z12.string().optional(),
|
|
1327
|
+
enableImageUnderstanding: z12.boolean().optional(),
|
|
1328
|
+
enableVideoUnderstanding: z12.boolean().optional()
|
|
2279
1329
|
})
|
|
2280
1330
|
)
|
|
2281
1331
|
);
|
|
2282
1332
|
var xSearchOutputSchema = lazySchema6(
|
|
2283
1333
|
() => zodSchema6(
|
|
2284
|
-
|
|
2285
|
-
query:
|
|
2286
|
-
posts:
|
|
2287
|
-
|
|
2288
|
-
author:
|
|
2289
|
-
text:
|
|
2290
|
-
url:
|
|
2291
|
-
likes:
|
|
1334
|
+
z12.object({
|
|
1335
|
+
query: z12.string(),
|
|
1336
|
+
posts: z12.array(
|
|
1337
|
+
z12.object({
|
|
1338
|
+
author: z12.string(),
|
|
1339
|
+
text: z12.string(),
|
|
1340
|
+
url: z12.string(),
|
|
1341
|
+
likes: z12.number()
|
|
2292
1342
|
})
|
|
2293
1343
|
)
|
|
2294
1344
|
})
|
|
@@ -2296,7 +1346,7 @@ var xSearchOutputSchema = lazySchema6(
|
|
|
2296
1346
|
);
|
|
2297
1347
|
var xSearchToolFactory = createProviderExecutedToolFactory5({
|
|
2298
1348
|
id: "xai.x_search",
|
|
2299
|
-
inputSchema: lazySchema6(() => zodSchema6(
|
|
1349
|
+
inputSchema: lazySchema6(() => zodSchema6(z12.object({}))),
|
|
2300
1350
|
outputSchema: xSearchOutputSchema
|
|
2301
1351
|
});
|
|
2302
1352
|
var xSearch = (args = {}) => xSearchToolFactory(args);
|
|
@@ -2417,7 +1467,7 @@ async function prepareResponsesTools({
|
|
|
2417
1467
|
type: "function",
|
|
2418
1468
|
name: tool.name,
|
|
2419
1469
|
description: tool.description,
|
|
2420
|
-
parameters:
|
|
1470
|
+
parameters: tool.inputSchema,
|
|
2421
1471
|
...tool.strict != null ? { strict: tool.strict } : {}
|
|
2422
1472
|
});
|
|
2423
1473
|
}
|
|
@@ -2456,7 +1506,7 @@ async function prepareResponsesTools({
|
|
|
2456
1506
|
}
|
|
2457
1507
|
default: {
|
|
2458
1508
|
const _exhaustiveCheck = type;
|
|
2459
|
-
throw new
|
|
1509
|
+
throw new UnsupportedFunctionalityError2({
|
|
2460
1510
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
2461
1511
|
});
|
|
2462
1512
|
}
|
|
@@ -2537,13 +1587,13 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2537
1587
|
this.modelId = modelId;
|
|
2538
1588
|
this.config = config;
|
|
2539
1589
|
}
|
|
2540
|
-
static [
|
|
2541
|
-
return
|
|
1590
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
1591
|
+
return serializeModelOptions2({
|
|
2542
1592
|
modelId: model.modelId,
|
|
2543
1593
|
config: model.config
|
|
2544
1594
|
});
|
|
2545
1595
|
}
|
|
2546
|
-
static [
|
|
1596
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
2547
1597
|
return new _XaiResponsesLanguageModel(options.modelId, options.config);
|
|
2548
1598
|
}
|
|
2549
1599
|
get provider() {
|
|
@@ -2570,7 +1620,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2570
1620
|
}) {
|
|
2571
1621
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2572
1622
|
const warnings = [];
|
|
2573
|
-
const options = (_a = await
|
|
1623
|
+
const options = (_a = await parseProviderOptions3({
|
|
2574
1624
|
provider: "xai",
|
|
2575
1625
|
providerOptions,
|
|
2576
1626
|
schema: xaiLanguageModelResponsesOptions
|
|
@@ -2628,7 +1678,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2628
1678
|
}
|
|
2629
1679
|
}
|
|
2630
1680
|
let resolvedReasoningEffort = options.reasoningEffort;
|
|
2631
|
-
if (resolvedReasoningEffort == null &&
|
|
1681
|
+
if (resolvedReasoningEffort == null && isCustomReasoning(reasoning)) {
|
|
2632
1682
|
if (!supportsReasoningEffort(modelId)) {
|
|
2633
1683
|
warnings.push({
|
|
2634
1684
|
type: "unsupported",
|
|
@@ -2638,7 +1688,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2638
1688
|
} else if (reasoning === "none") {
|
|
2639
1689
|
resolvedReasoningEffort = "none";
|
|
2640
1690
|
} else {
|
|
2641
|
-
resolvedReasoningEffort =
|
|
1691
|
+
resolvedReasoningEffort = mapReasoningToProviderEffort({
|
|
2642
1692
|
reasoning,
|
|
2643
1693
|
effortMap: {
|
|
2644
1694
|
minimal: "low",
|
|
@@ -2733,12 +1783,12 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2733
1783
|
responseHeaders,
|
|
2734
1784
|
value: response,
|
|
2735
1785
|
rawValue: rawResponse
|
|
2736
|
-
} = await
|
|
1786
|
+
} = await postJsonToApi2({
|
|
2737
1787
|
url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
|
|
2738
|
-
headers:
|
|
1788
|
+
headers: combineHeaders2((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
2739
1789
|
body,
|
|
2740
1790
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2741
|
-
successfulResponseHandler:
|
|
1791
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
2742
1792
|
xaiResponsesResponseSchema
|
|
2743
1793
|
),
|
|
2744
1794
|
abortSignal: options.abortSignal,
|
|
@@ -2951,12 +2001,12 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2951
2001
|
...args,
|
|
2952
2002
|
stream: true
|
|
2953
2003
|
};
|
|
2954
|
-
const { responseHeaders, value: response } = await
|
|
2004
|
+
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
2955
2005
|
url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
|
|
2956
|
-
headers:
|
|
2006
|
+
headers: combineHeaders2((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
2957
2007
|
body,
|
|
2958
2008
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2959
|
-
successfulResponseHandler:
|
|
2009
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
2960
2010
|
xaiResponsesChunkSchema
|
|
2961
2011
|
),
|
|
2962
2012
|
abortSignal: options.abortSignal,
|
|
@@ -3525,13 +2575,13 @@ var xaiBatchName = "ai-sdk-text-batch";
|
|
|
3525
2575
|
var xaiBatchResultsPageSize = 1e3;
|
|
3526
2576
|
var xaiBatchProviderOptionsSchema = lazySchema7(
|
|
3527
2577
|
() => zodSchema7(
|
|
3528
|
-
|
|
2578
|
+
z13.object({
|
|
3529
2579
|
/**
|
|
3530
2580
|
* TTL in seconds for the uploaded batch input file, measured from
|
|
3531
2581
|
* upload time. xAI accepts integers between 3600 (1 hour) and
|
|
3532
2582
|
* 2592000 (30 days) inclusive. Without it the file has no expiry.
|
|
3533
2583
|
*/
|
|
3534
|
-
inputFileExpiresAfter:
|
|
2584
|
+
inputFileExpiresAfter: z13.number().int().min(3600).max(2592e3).optional()
|
|
3535
2585
|
})
|
|
3536
2586
|
)
|
|
3537
2587
|
);
|
|
@@ -3539,70 +2589,108 @@ function assertSupportedBatchRequests(requests) {
|
|
|
3539
2589
|
for (const request of requests) {
|
|
3540
2590
|
const requestType = request.type;
|
|
3541
2591
|
if (requestType !== "text" && requestType !== "image") {
|
|
3542
|
-
throw new
|
|
2592
|
+
throw new UnsupportedFunctionalityError3({
|
|
3543
2593
|
functionality: `batch request type: ${requestType}`,
|
|
3544
2594
|
message: `The xAI Batch API does not support batch requests with type "${requestType}".`
|
|
3545
2595
|
});
|
|
3546
2596
|
}
|
|
3547
2597
|
}
|
|
3548
2598
|
}
|
|
3549
|
-
var xaiBatchImageResponseSchema =
|
|
3550
|
-
data:
|
|
3551
|
-
|
|
3552
|
-
url:
|
|
3553
|
-
b64_json:
|
|
3554
|
-
revised_prompt:
|
|
3555
|
-
respect_moderation:
|
|
2599
|
+
var xaiBatchImageResponseSchema = z13.object({
|
|
2600
|
+
data: z13.array(
|
|
2601
|
+
z13.object({
|
|
2602
|
+
url: z13.string().nullish(),
|
|
2603
|
+
b64_json: z13.string().nullish(),
|
|
2604
|
+
revised_prompt: z13.string().nullish(),
|
|
2605
|
+
respect_moderation: z13.boolean().nullish()
|
|
3556
2606
|
})
|
|
3557
2607
|
),
|
|
3558
|
-
usage:
|
|
2608
|
+
usage: z13.object({ cost_in_usd_ticks: z13.number().nullish() }).nullish()
|
|
3559
2609
|
});
|
|
3560
|
-
var xaiBatchResponseZodSchema = () =>
|
|
3561
|
-
batch_id:
|
|
3562
|
-
name:
|
|
3563
|
-
create_time:
|
|
3564
|
-
expire_time:
|
|
3565
|
-
cancel_time:
|
|
3566
|
-
cancel_by_xai_message:
|
|
3567
|
-
state:
|
|
3568
|
-
num_requests:
|
|
3569
|
-
num_pending:
|
|
3570
|
-
num_success:
|
|
3571
|
-
num_error:
|
|
3572
|
-
num_cancelled:
|
|
2610
|
+
var xaiBatchResponseZodSchema = () => z13.object({
|
|
2611
|
+
batch_id: z13.string(),
|
|
2612
|
+
name: z13.string().nullish(),
|
|
2613
|
+
create_time: z13.string().nullish(),
|
|
2614
|
+
expire_time: z13.string().nullish(),
|
|
2615
|
+
cancel_time: z13.string().nullish(),
|
|
2616
|
+
cancel_by_xai_message: z13.string().nullish(),
|
|
2617
|
+
state: z13.object({
|
|
2618
|
+
num_requests: z13.number().nullish(),
|
|
2619
|
+
num_pending: z13.number().nullish(),
|
|
2620
|
+
num_success: z13.number().nullish(),
|
|
2621
|
+
num_error: z13.number().nullish(),
|
|
2622
|
+
num_cancelled: z13.number().nullish()
|
|
3573
2623
|
}).nullish()
|
|
3574
2624
|
});
|
|
3575
2625
|
var xaiBatchResponseSchema = lazySchema7(
|
|
3576
2626
|
() => zodSchema7(xaiBatchResponseZodSchema())
|
|
3577
2627
|
);
|
|
3578
|
-
var xaiBatchErrorSchema =
|
|
3579
|
-
code:
|
|
3580
|
-
message:
|
|
2628
|
+
var xaiBatchErrorSchema = z13.object({
|
|
2629
|
+
code: z13.union([z13.string(), z13.number()]).nullish(),
|
|
2630
|
+
message: z13.string().nullish()
|
|
3581
2631
|
});
|
|
3582
|
-
var xaiBatchResultSchema =
|
|
3583
|
-
batch_request_id:
|
|
3584
|
-
batch_result:
|
|
3585
|
-
response:
|
|
3586
|
-
chat_get_completion:
|
|
3587
|
-
image_generation:
|
|
2632
|
+
var xaiBatchResultSchema = z13.object({
|
|
2633
|
+
batch_request_id: z13.string(),
|
|
2634
|
+
batch_result: z13.object({
|
|
2635
|
+
response: z13.object({
|
|
2636
|
+
chat_get_completion: z13.unknown().nullish(),
|
|
2637
|
+
image_generation: z13.unknown().nullish()
|
|
3588
2638
|
}).nullish(),
|
|
3589
2639
|
error: xaiBatchErrorSchema.nullish()
|
|
3590
2640
|
}).nullish(),
|
|
3591
|
-
error_message:
|
|
2641
|
+
error_message: z13.string().nullish()
|
|
2642
|
+
});
|
|
2643
|
+
var xaiBatchTextResponseSchema = z13.object({
|
|
2644
|
+
id: z13.string().nullish(),
|
|
2645
|
+
created: z13.number().nullish(),
|
|
2646
|
+
model: z13.string().nullish(),
|
|
2647
|
+
choices: z13.array(
|
|
2648
|
+
z13.object({
|
|
2649
|
+
message: z13.object({
|
|
2650
|
+
role: z13.enum(["assistant", "tool"]),
|
|
2651
|
+
content: z13.string().nullish(),
|
|
2652
|
+
reasoning_content: z13.string().nullish(),
|
|
2653
|
+
tool_calls: z13.array(
|
|
2654
|
+
z13.object({
|
|
2655
|
+
id: z13.string(),
|
|
2656
|
+
type: z13.literal("function"),
|
|
2657
|
+
function: z13.object({
|
|
2658
|
+
name: z13.string(),
|
|
2659
|
+
arguments: z13.string()
|
|
2660
|
+
})
|
|
2661
|
+
})
|
|
2662
|
+
).nullish()
|
|
2663
|
+
}),
|
|
2664
|
+
index: z13.number(),
|
|
2665
|
+
finish_reason: z13.string().nullish()
|
|
2666
|
+
})
|
|
2667
|
+
).nullish(),
|
|
2668
|
+
usage: z13.object({
|
|
2669
|
+
prompt_tokens: z13.number(),
|
|
2670
|
+
completion_tokens: z13.number(),
|
|
2671
|
+
total_tokens: z13.number(),
|
|
2672
|
+
cost_in_usd_ticks: z13.number().nullish(),
|
|
2673
|
+
prompt_tokens_details: z13.object({ cached_tokens: z13.number().nullish() }).nullish(),
|
|
2674
|
+
completion_tokens_details: z13.object({ reasoning_tokens: z13.number().nullish() }).nullish()
|
|
2675
|
+
}).nullish(),
|
|
2676
|
+
citations: z13.array(z13.string().url()).nullish(),
|
|
2677
|
+
service_tier: z13.string().nullish(),
|
|
2678
|
+
code: z13.string().nullish(),
|
|
2679
|
+
error: z13.string().nullish()
|
|
3592
2680
|
});
|
|
3593
2681
|
var xaiBatchResultsPageSchema = lazySchema7(
|
|
3594
2682
|
() => zodSchema7(
|
|
3595
|
-
|
|
3596
|
-
results:
|
|
3597
|
-
pagination_token:
|
|
2683
|
+
z13.object({
|
|
2684
|
+
results: z13.array(xaiBatchResultSchema),
|
|
2685
|
+
pagination_token: z13.string().nullish()
|
|
3598
2686
|
})
|
|
3599
2687
|
)
|
|
3600
2688
|
);
|
|
3601
2689
|
var xaiBatchListResponseSchema = lazySchema7(
|
|
3602
2690
|
() => zodSchema7(
|
|
3603
|
-
|
|
3604
|
-
batches:
|
|
3605
|
-
pagination_token:
|
|
2691
|
+
z13.object({
|
|
2692
|
+
batches: z13.array(xaiBatchResponseZodSchema()),
|
|
2693
|
+
pagination_token: z13.string().nullish()
|
|
3606
2694
|
})
|
|
3607
2695
|
)
|
|
3608
2696
|
);
|
|
@@ -3626,7 +2714,7 @@ var XaiBatch = class {
|
|
|
3626
2714
|
}
|
|
3627
2715
|
}
|
|
3628
2716
|
];
|
|
3629
|
-
const batchOptions = await
|
|
2717
|
+
const batchOptions = await parseProviderOptions4({
|
|
3630
2718
|
provider: "xai",
|
|
3631
2719
|
providerOptions: options.providerOptions,
|
|
3632
2720
|
schema: xaiBatchProviderOptionsSchema
|
|
@@ -3657,7 +2745,7 @@ var XaiBatch = class {
|
|
|
3657
2745
|
);
|
|
3658
2746
|
}
|
|
3659
2747
|
formData.append("file", file, filename);
|
|
3660
|
-
const headers =
|
|
2748
|
+
const headers = combineHeaders3(
|
|
3661
2749
|
(_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a),
|
|
3662
2750
|
options.headers
|
|
3663
2751
|
);
|
|
@@ -3666,13 +2754,13 @@ var XaiBatch = class {
|
|
|
3666
2754
|
headers,
|
|
3667
2755
|
formData,
|
|
3668
2756
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3669
|
-
successfulResponseHandler:
|
|
2757
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3670
2758
|
xaiFilesResponseSchema
|
|
3671
2759
|
),
|
|
3672
2760
|
abortSignal: options.abortSignal,
|
|
3673
2761
|
fetch: this.options.config.fetch
|
|
3674
2762
|
});
|
|
3675
|
-
const { value: batch } = await
|
|
2763
|
+
const { value: batch } = await postJsonToApi3({
|
|
3676
2764
|
url: this.getUrl("/batches"),
|
|
3677
2765
|
headers,
|
|
3678
2766
|
body: {
|
|
@@ -3680,7 +2768,7 @@ var XaiBatch = class {
|
|
|
3680
2768
|
input_file_id: uploadedFile.id
|
|
3681
2769
|
},
|
|
3682
2770
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3683
|
-
successfulResponseHandler:
|
|
2771
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3684
2772
|
xaiBatchResponseSchema
|
|
3685
2773
|
),
|
|
3686
2774
|
abortSignal: options.abortSignal,
|
|
@@ -3707,14 +2795,14 @@ var XaiBatch = class {
|
|
|
3707
2795
|
}
|
|
3708
2796
|
async doCancelBatch(options) {
|
|
3709
2797
|
var _a, _b;
|
|
3710
|
-
await
|
|
2798
|
+
await postJsonToApi3({
|
|
3711
2799
|
url: this.getUrl(
|
|
3712
2800
|
`/batches/${encodeURIComponent(options.batchId)}:cancel`
|
|
3713
2801
|
),
|
|
3714
|
-
headers:
|
|
2802
|
+
headers: combineHeaders3((_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
3715
2803
|
body: {},
|
|
3716
2804
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3717
|
-
successfulResponseHandler:
|
|
2805
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3718
2806
|
xaiBatchResponseSchema
|
|
3719
2807
|
),
|
|
3720
2808
|
abortSignal: options.abortSignal,
|
|
@@ -3733,9 +2821,9 @@ var XaiBatch = class {
|
|
|
3733
2821
|
}
|
|
3734
2822
|
const { value: page } = await getFromApi2({
|
|
3735
2823
|
url: url.toString(),
|
|
3736
|
-
headers:
|
|
2824
|
+
headers: combineHeaders3((_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
3737
2825
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3738
|
-
successfulResponseHandler:
|
|
2826
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3739
2827
|
xaiBatchListResponseSchema
|
|
3740
2828
|
),
|
|
3741
2829
|
abortSignal: options.abortSignal,
|
|
@@ -3766,9 +2854,9 @@ var XaiBatch = class {
|
|
|
3766
2854
|
var _a, _b;
|
|
3767
2855
|
const { value: batch } = await getFromApi2({
|
|
3768
2856
|
url: this.getUrl(`/batches/${encodeURIComponent(options.batchId)}`),
|
|
3769
|
-
headers:
|
|
2857
|
+
headers: combineHeaders3((_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
3770
2858
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3771
|
-
successfulResponseHandler:
|
|
2859
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3772
2860
|
xaiBatchResponseSchema
|
|
3773
2861
|
),
|
|
3774
2862
|
abortSignal: options.abortSignal,
|
|
@@ -3791,12 +2879,12 @@ var XaiBatch = class {
|
|
|
3791
2879
|
url: this.getUrl(
|
|
3792
2880
|
`/batches/${encodeURIComponent(options.batchId)}/results?${query}`
|
|
3793
2881
|
),
|
|
3794
|
-
headers:
|
|
2882
|
+
headers: combineHeaders3(
|
|
3795
2883
|
(_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a),
|
|
3796
2884
|
options.headers
|
|
3797
2885
|
),
|
|
3798
2886
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3799
|
-
successfulResponseHandler:
|
|
2887
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3800
2888
|
xaiBatchResultsPageSchema
|
|
3801
2889
|
),
|
|
3802
2890
|
abortSignal: options.abortSignal,
|
|
@@ -3825,12 +2913,12 @@ var XaiBatch = class {
|
|
|
3825
2913
|
if ((response == null ? void 0 : response.chat_get_completion) != null) {
|
|
3826
2914
|
const validation = await safeValidateTypes({
|
|
3827
2915
|
value: response.chat_get_completion,
|
|
3828
|
-
schema:
|
|
2916
|
+
schema: zodSchema7(xaiBatchTextResponseSchema)
|
|
3829
2917
|
});
|
|
3830
2918
|
if (!validation.success) {
|
|
3831
2919
|
return invalidXaiBatchResult(result.batch_request_id);
|
|
3832
2920
|
}
|
|
3833
|
-
const conversion =
|
|
2921
|
+
const conversion = convertXaiBatchTextResponse(validation.value);
|
|
3834
2922
|
return conversion.success ? {
|
|
3835
2923
|
type: "text",
|
|
3836
2924
|
id: result.batch_request_id,
|
|
@@ -3893,7 +2981,7 @@ var XaiBatch = class {
|
|
|
3893
2981
|
}
|
|
3894
2982
|
if (seed != null) warnings.push({ type: "unsupported", feature: "seed" });
|
|
3895
2983
|
if (mask != null) warnings.push({ type: "unsupported", feature: "mask" });
|
|
3896
|
-
const xaiOptions = await
|
|
2984
|
+
const xaiOptions = await parseProviderOptions4({
|
|
3897
2985
|
provider: "xai",
|
|
3898
2986
|
providerOptions,
|
|
3899
2987
|
schema: xaiImageModelOptions
|
|
@@ -4040,7 +3128,7 @@ function invalidXaiImageBatchResult(id) {
|
|
|
4040
3128
|
}
|
|
4041
3129
|
};
|
|
4042
3130
|
}
|
|
4043
|
-
function
|
|
3131
|
+
function convertXaiBatchTextResponse(response) {
|
|
4044
3132
|
var _a, _b, _c, _d, _e, _f;
|
|
4045
3133
|
if (response.error != null) {
|
|
4046
3134
|
return {
|
|
@@ -4122,7 +3210,7 @@ function convertXaiChatBatchResponse(response) {
|
|
|
4122
3210
|
unified: mapXaiFinishReason(lastAssistantChoice == null ? void 0 : lastAssistantChoice.finish_reason),
|
|
4123
3211
|
raw: (_d = lastAssistantChoice == null ? void 0 : lastAssistantChoice.finish_reason) != null ? _d : void 0
|
|
4124
3212
|
},
|
|
4125
|
-
usage: response.usage ?
|
|
3213
|
+
usage: response.usage ? convertXaiBatchTextUsage(response.usage) : createNullLanguageModelUsage(),
|
|
4126
3214
|
response: getResponseMetadata(response),
|
|
4127
3215
|
warnings: [],
|
|
4128
3216
|
...(((_e = response.usage) == null ? void 0 : _e.cost_in_usd_ticks) != null || response.service_tier != null) && {
|
|
@@ -4136,6 +3224,26 @@ function convertXaiChatBatchResponse(response) {
|
|
|
4136
3224
|
}
|
|
4137
3225
|
};
|
|
4138
3226
|
}
|
|
3227
|
+
function convertXaiBatchTextUsage(usage) {
|
|
3228
|
+
var _a, _b, _c, _d;
|
|
3229
|
+
const cacheReadTokens = (_b = (_a = usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0;
|
|
3230
|
+
const reasoningTokens = (_d = (_c = usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0;
|
|
3231
|
+
const promptTokensIncludesCached = cacheReadTokens <= usage.prompt_tokens;
|
|
3232
|
+
return {
|
|
3233
|
+
inputTokens: {
|
|
3234
|
+
total: promptTokensIncludesCached ? usage.prompt_tokens : usage.prompt_tokens + cacheReadTokens,
|
|
3235
|
+
noCache: promptTokensIncludesCached ? usage.prompt_tokens - cacheReadTokens : usage.prompt_tokens,
|
|
3236
|
+
cacheRead: cacheReadTokens,
|
|
3237
|
+
cacheWrite: void 0
|
|
3238
|
+
},
|
|
3239
|
+
outputTokens: {
|
|
3240
|
+
total: usage.completion_tokens + reasoningTokens,
|
|
3241
|
+
text: usage.completion_tokens,
|
|
3242
|
+
reasoning: reasoningTokens
|
|
3243
|
+
},
|
|
3244
|
+
raw: usage
|
|
3245
|
+
};
|
|
3246
|
+
}
|
|
4139
3247
|
|
|
4140
3248
|
// src/realtime/xai-realtime-event-mapper.ts
|
|
4141
3249
|
function parseXaiRealtimeServerEvent(raw) {
|
|
@@ -4508,43 +3616,43 @@ var XaiRealtimeModel = class {
|
|
|
4508
3616
|
|
|
4509
3617
|
// src/tool/code-execution.ts
|
|
4510
3618
|
import { createProviderExecutedToolFactory as createProviderExecutedToolFactory6 } from "@ai-sdk/provider-utils";
|
|
4511
|
-
import { z as
|
|
4512
|
-
var codeExecutionOutputSchema =
|
|
4513
|
-
output:
|
|
4514
|
-
error:
|
|
3619
|
+
import { z as z14 } from "zod/v4";
|
|
3620
|
+
var codeExecutionOutputSchema = z14.object({
|
|
3621
|
+
output: z14.string().describe("the output of the code execution"),
|
|
3622
|
+
error: z14.string().optional().describe("any error that occurred")
|
|
4515
3623
|
});
|
|
4516
3624
|
var codeExecutionToolFactory = createProviderExecutedToolFactory6({
|
|
4517
3625
|
id: "xai.code_execution",
|
|
4518
|
-
inputSchema:
|
|
3626
|
+
inputSchema: z14.object({}).describe("no input parameters"),
|
|
4519
3627
|
outputSchema: codeExecutionOutputSchema
|
|
4520
3628
|
});
|
|
4521
3629
|
var codeExecution = (args = {}) => codeExecutionToolFactory(args);
|
|
4522
3630
|
|
|
4523
3631
|
// src/tool/view-image.ts
|
|
4524
3632
|
import { createProviderExecutedToolFactory as createProviderExecutedToolFactory7 } from "@ai-sdk/provider-utils";
|
|
4525
|
-
import { z as
|
|
4526
|
-
var viewImageOutputSchema =
|
|
4527
|
-
description:
|
|
4528
|
-
objects:
|
|
3633
|
+
import { z as z15 } from "zod/v4";
|
|
3634
|
+
var viewImageOutputSchema = z15.object({
|
|
3635
|
+
description: z15.string().describe("description of the image"),
|
|
3636
|
+
objects: z15.array(z15.string()).optional().describe("objects detected in the image")
|
|
4529
3637
|
});
|
|
4530
3638
|
var viewImageToolFactory = createProviderExecutedToolFactory7({
|
|
4531
3639
|
id: "xai.view_image",
|
|
4532
|
-
inputSchema:
|
|
3640
|
+
inputSchema: z15.object({}).describe("no input parameters"),
|
|
4533
3641
|
outputSchema: viewImageOutputSchema
|
|
4534
3642
|
});
|
|
4535
3643
|
var viewImage = (args = {}) => viewImageToolFactory(args);
|
|
4536
3644
|
|
|
4537
3645
|
// src/tool/view-x-video.ts
|
|
4538
3646
|
import { createProviderExecutedToolFactory as createProviderExecutedToolFactory8 } from "@ai-sdk/provider-utils";
|
|
4539
|
-
import { z as
|
|
4540
|
-
var viewXVideoOutputSchema =
|
|
4541
|
-
transcript:
|
|
4542
|
-
description:
|
|
4543
|
-
duration:
|
|
3647
|
+
import { z as z16 } from "zod/v4";
|
|
3648
|
+
var viewXVideoOutputSchema = z16.object({
|
|
3649
|
+
transcript: z16.string().optional().describe("transcript of the video"),
|
|
3650
|
+
description: z16.string().describe("description of the video content"),
|
|
3651
|
+
duration: z16.number().optional().describe("duration in seconds")
|
|
4544
3652
|
});
|
|
4545
3653
|
var viewXVideoToolFactory = createProviderExecutedToolFactory8({
|
|
4546
3654
|
id: "xai.view_x_video",
|
|
4547
|
-
inputSchema:
|
|
3655
|
+
inputSchema: z16.object({}).describe("no input parameters"),
|
|
4548
3656
|
outputSchema: viewXVideoOutputSchema
|
|
4549
3657
|
});
|
|
4550
3658
|
var viewXVideo = (args = {}) => viewXVideoToolFactory(args);
|
|
@@ -4562,20 +3670,20 @@ var xaiTools = {
|
|
|
4562
3670
|
};
|
|
4563
3671
|
|
|
4564
3672
|
// src/version.ts
|
|
4565
|
-
var VERSION = true ? "
|
|
3673
|
+
var VERSION = true ? "5.0.0" : "0.0.0-test";
|
|
4566
3674
|
|
|
4567
3675
|
// src/files/xai-files.ts
|
|
4568
3676
|
import {
|
|
4569
3677
|
InvalidArgumentError as InvalidArgumentError2
|
|
4570
3678
|
} from "@ai-sdk/provider";
|
|
4571
3679
|
import {
|
|
4572
|
-
combineHeaders as
|
|
3680
|
+
combineHeaders as combineHeaders4,
|
|
4573
3681
|
convertInlineFileDataToUint8Array,
|
|
4574
3682
|
createBinaryStreamResponseHandler,
|
|
4575
|
-
createJsonResponseHandler as
|
|
3683
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
4576
3684
|
deleteFromApi,
|
|
4577
3685
|
getFromApi as getFromApi3,
|
|
4578
|
-
parseProviderOptions as
|
|
3686
|
+
parseProviderOptions as parseProviderOptions5,
|
|
4579
3687
|
postFormDataToApi as postFormDataToApi2,
|
|
4580
3688
|
postMultipartStreamToApi
|
|
4581
3689
|
} from "@ai-sdk/provider-utils";
|
|
@@ -4585,18 +3693,18 @@ import {
|
|
|
4585
3693
|
lazySchema as lazySchema8,
|
|
4586
3694
|
zodSchema as zodSchema8
|
|
4587
3695
|
} from "@ai-sdk/provider-utils";
|
|
4588
|
-
import { z as
|
|
3696
|
+
import { z as z17 } from "zod/v4";
|
|
4589
3697
|
var xaiFilesOptionsSchema = lazySchema8(
|
|
4590
3698
|
() => zodSchema8(
|
|
4591
|
-
|
|
4592
|
-
teamId:
|
|
4593
|
-
filePath:
|
|
3699
|
+
z17.looseObject({
|
|
3700
|
+
teamId: z17.string().optional(),
|
|
3701
|
+
filePath: z17.string().optional(),
|
|
4594
3702
|
/**
|
|
4595
3703
|
* TTL in seconds measured from upload time; xAI accepts integers
|
|
4596
3704
|
* between 3600 (1 hour) and 2592000 (30 days) inclusive.
|
|
4597
3705
|
* Omit to keep the file until it is deleted.
|
|
4598
3706
|
*/
|
|
4599
|
-
expiresAfter:
|
|
3707
|
+
expiresAfter: z17.number().int().min(3600).max(2592e3).optional()
|
|
4600
3708
|
})
|
|
4601
3709
|
)
|
|
4602
3710
|
);
|
|
@@ -4625,7 +3733,7 @@ var XaiFiles = class {
|
|
|
4625
3733
|
return fileId;
|
|
4626
3734
|
}
|
|
4627
3735
|
getHeaders(headers) {
|
|
4628
|
-
return
|
|
3736
|
+
return combineHeaders4(this.config.headers(), headers);
|
|
4629
3737
|
}
|
|
4630
3738
|
async uploadFile({
|
|
4631
3739
|
data,
|
|
@@ -4638,7 +3746,7 @@ var XaiFiles = class {
|
|
|
4638
3746
|
var _a, _b;
|
|
4639
3747
|
let xaiOptions;
|
|
4640
3748
|
try {
|
|
4641
|
-
xaiOptions = await
|
|
3749
|
+
xaiOptions = await parseProviderOptions5({
|
|
4642
3750
|
provider: "xai",
|
|
4643
3751
|
providerOptions,
|
|
4644
3752
|
schema: xaiFilesOptionsSchema
|
|
@@ -4681,7 +3789,7 @@ var XaiFiles = class {
|
|
|
4681
3789
|
headers: requestHeaders,
|
|
4682
3790
|
parts,
|
|
4683
3791
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4684
|
-
successfulResponseHandler:
|
|
3792
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
4685
3793
|
xaiFilesResponseSchema
|
|
4686
3794
|
),
|
|
4687
3795
|
abortSignal,
|
|
@@ -4709,7 +3817,7 @@ var XaiFiles = class {
|
|
|
4709
3817
|
headers: requestHeaders,
|
|
4710
3818
|
formData,
|
|
4711
3819
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4712
|
-
successfulResponseHandler:
|
|
3820
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
4713
3821
|
xaiFilesResponseSchema
|
|
4714
3822
|
),
|
|
4715
3823
|
abortSignal,
|
|
@@ -4739,7 +3847,7 @@ var XaiFiles = class {
|
|
|
4739
3847
|
url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}`,
|
|
4740
3848
|
headers: this.getHeaders(headers),
|
|
4741
3849
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4742
|
-
successfulResponseHandler:
|
|
3850
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
4743
3851
|
xaiFilesResponseSchema
|
|
4744
3852
|
),
|
|
4745
3853
|
abortSignal,
|
|
@@ -4791,7 +3899,7 @@ var XaiFiles = class {
|
|
|
4791
3899
|
url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}`,
|
|
4792
3900
|
headers: this.getHeaders(headers),
|
|
4793
3901
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4794
|
-
successfulResponseHandler:
|
|
3902
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
4795
3903
|
xaiFileDeleteResponseSchema
|
|
4796
3904
|
),
|
|
4797
3905
|
abortSignal,
|
|
@@ -4818,38 +3926,38 @@ var XaiFiles = class {
|
|
|
4818
3926
|
// src/xai-video-model.ts
|
|
4819
3927
|
import {
|
|
4820
3928
|
AISDKError,
|
|
4821
|
-
APICallError
|
|
3929
|
+
APICallError
|
|
4822
3930
|
} from "@ai-sdk/provider";
|
|
4823
3931
|
import {
|
|
4824
|
-
combineHeaders as
|
|
3932
|
+
combineHeaders as combineHeaders5,
|
|
4825
3933
|
convertUint8ArrayToBase64,
|
|
4826
|
-
createJsonResponseHandler as
|
|
4827
|
-
extractResponseHeaders
|
|
3934
|
+
createJsonResponseHandler as createJsonResponseHandler5,
|
|
3935
|
+
extractResponseHeaders,
|
|
4828
3936
|
getFromApi as getFromApi4,
|
|
4829
|
-
getTopLevelMediaType as
|
|
4830
|
-
parseProviderOptions as
|
|
4831
|
-
postJsonToApi as
|
|
4832
|
-
safeParseJSON
|
|
3937
|
+
getTopLevelMediaType as getTopLevelMediaType2,
|
|
3938
|
+
parseProviderOptions as parseProviderOptions6,
|
|
3939
|
+
postJsonToApi as postJsonToApi4,
|
|
3940
|
+
safeParseJSON
|
|
4833
3941
|
} from "@ai-sdk/provider-utils";
|
|
4834
|
-
import { z as
|
|
3942
|
+
import { z as z19 } from "zod/v4";
|
|
4835
3943
|
|
|
4836
3944
|
// src/xai-video-model-options.ts
|
|
4837
3945
|
import { lazySchema as lazySchema9, zodSchema as zodSchema9 } from "@ai-sdk/provider-utils";
|
|
4838
|
-
import { z as
|
|
4839
|
-
var nonEmptyStringSchema =
|
|
4840
|
-
var resolutionSchema =
|
|
4841
|
-
var modeSchema =
|
|
3946
|
+
import { z as z18 } from "zod/v4";
|
|
3947
|
+
var nonEmptyStringSchema = z18.string().min(1);
|
|
3948
|
+
var resolutionSchema = z18.enum(["480p", "720p", "1080p"]);
|
|
3949
|
+
var modeSchema = z18.enum(["edit-video", "extend-video", "reference-to-video"]);
|
|
4842
3950
|
var baseFields = {
|
|
4843
|
-
pollIntervalMs:
|
|
4844
|
-
pollTimeoutMs:
|
|
3951
|
+
pollIntervalMs: z18.number().positive().nullish(),
|
|
3952
|
+
pollTimeoutMs: z18.number().positive().nullish(),
|
|
4845
3953
|
resolution: resolutionSchema.nullish()
|
|
4846
3954
|
};
|
|
4847
|
-
var runtimeSchema =
|
|
3955
|
+
var runtimeSchema = z18.looseObject({
|
|
4848
3956
|
mode: modeSchema.optional(),
|
|
4849
3957
|
videoUrl: nonEmptyStringSchema.optional(),
|
|
4850
|
-
referenceImageUrls:
|
|
4851
|
-
referenceVoiceIds:
|
|
4852
|
-
user:
|
|
3958
|
+
referenceImageUrls: z18.array(nonEmptyStringSchema).min(1).max(7).optional(),
|
|
3959
|
+
referenceVoiceIds: z18.array(nonEmptyStringSchema).max(3).optional(),
|
|
3960
|
+
user: z18.string().optional(),
|
|
4853
3961
|
...baseFields
|
|
4854
3962
|
});
|
|
4855
3963
|
var xaiVideoModelOptionsSchema = lazySchema9(
|
|
@@ -4879,8 +3987,8 @@ function resolveStartImage(options) {
|
|
|
4879
3987
|
var _a;
|
|
4880
3988
|
return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
|
|
4881
3989
|
}
|
|
4882
|
-
var isVideoFile = (file) => file.mediaType != null &&
|
|
4883
|
-
var isImageReference = (file) => file.mediaType == null ||
|
|
3990
|
+
var isVideoFile = (file) => file.mediaType != null && getTopLevelMediaType2(file.mediaType) === "video";
|
|
3991
|
+
var isImageReference = (file) => file.mediaType == null || getTopLevelMediaType2(file.mediaType) === "image";
|
|
4884
3992
|
function fileToXaiUrl(file) {
|
|
4885
3993
|
if (file.type === "url") {
|
|
4886
3994
|
return file.url;
|
|
@@ -4939,7 +4047,7 @@ var XaiVideoModel = class {
|
|
|
4939
4047
|
}
|
|
4940
4048
|
async buildRequestBody(options) {
|
|
4941
4049
|
const warnings = [];
|
|
4942
|
-
const xaiOptions = await
|
|
4050
|
+
const xaiOptions = await parseProviderOptions6({
|
|
4943
4051
|
provider: "xai",
|
|
4944
4052
|
providerOptions: options.providerOptions,
|
|
4945
4053
|
schema: xaiVideoModelOptionsSchema
|
|
@@ -5147,12 +4255,12 @@ var XaiVideoModel = class {
|
|
|
5147
4255
|
} else {
|
|
5148
4256
|
endpoint = `${baseURL}/videos/generations`;
|
|
5149
4257
|
}
|
|
5150
|
-
const { value: createResponse, responseHeaders } = await
|
|
4258
|
+
const { value: createResponse, responseHeaders } = await postJsonToApi4({
|
|
5151
4259
|
url: endpoint,
|
|
5152
|
-
headers:
|
|
4260
|
+
headers: combineHeaders5(this.config.headers(), options.headers),
|
|
5153
4261
|
body,
|
|
5154
4262
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
5155
|
-
successfulResponseHandler:
|
|
4263
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
5156
4264
|
xaiCreateVideoResponseSchema
|
|
5157
4265
|
),
|
|
5158
4266
|
abortSignal: options.abortSignal,
|
|
@@ -5183,7 +4291,7 @@ var XaiVideoModel = class {
|
|
|
5183
4291
|
const { value: statusResponse, responseHeaders } = await getFromApi4({
|
|
5184
4292
|
url: `${baseURL}/videos/${encodePathSegment2(requestId)}`,
|
|
5185
4293
|
validateUrl: false,
|
|
5186
|
-
headers:
|
|
4294
|
+
headers: combineHeaders5(this.config.headers(), options.headers),
|
|
5187
4295
|
successfulResponseHandler: xaiVideoStatusResponseHandler,
|
|
5188
4296
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
5189
4297
|
abortSignal: options.abortSignal,
|
|
@@ -5271,27 +4379,27 @@ var XaiVideoModel = class {
|
|
|
5271
4379
|
};
|
|
5272
4380
|
}
|
|
5273
4381
|
};
|
|
5274
|
-
var xaiCreateVideoResponseSchema =
|
|
5275
|
-
request_id:
|
|
4382
|
+
var xaiCreateVideoResponseSchema = z19.object({
|
|
4383
|
+
request_id: z19.string().nullish()
|
|
5276
4384
|
});
|
|
5277
|
-
var xaiVideoStatusResponseSchema =
|
|
5278
|
-
status:
|
|
5279
|
-
video:
|
|
5280
|
-
url:
|
|
5281
|
-
duration:
|
|
5282
|
-
respect_moderation:
|
|
4385
|
+
var xaiVideoStatusResponseSchema = z19.object({
|
|
4386
|
+
status: z19.string().nullish(),
|
|
4387
|
+
video: z19.object({
|
|
4388
|
+
url: z19.string(),
|
|
4389
|
+
duration: z19.number().nullish(),
|
|
4390
|
+
respect_moderation: z19.boolean().nullish()
|
|
5283
4391
|
}).nullish(),
|
|
5284
|
-
model:
|
|
5285
|
-
usage:
|
|
5286
|
-
cost_in_usd_ticks:
|
|
4392
|
+
model: z19.string().nullish(),
|
|
4393
|
+
usage: z19.object({
|
|
4394
|
+
cost_in_usd_ticks: z19.number().nullish()
|
|
5287
4395
|
}).nullish(),
|
|
5288
|
-
progress:
|
|
5289
|
-
error:
|
|
5290
|
-
code:
|
|
5291
|
-
message:
|
|
4396
|
+
progress: z19.number().nullish(),
|
|
4397
|
+
error: z19.object({
|
|
4398
|
+
code: z19.string().nullish(),
|
|
4399
|
+
message: z19.string().nullish()
|
|
5292
4400
|
}).nullish()
|
|
5293
4401
|
});
|
|
5294
|
-
var xaiVideoStatusJsonResponseHandler =
|
|
4402
|
+
var xaiVideoStatusJsonResponseHandler = createJsonResponseHandler5(
|
|
5295
4403
|
xaiVideoStatusResponseSchema
|
|
5296
4404
|
);
|
|
5297
4405
|
var MAX_PENDING_BODY_BYTES = 1024 * 1024;
|
|
@@ -5313,12 +4421,12 @@ async function readPendingBody({
|
|
|
5313
4421
|
if (done) break;
|
|
5314
4422
|
totalBytes += value.length;
|
|
5315
4423
|
if (totalBytes > MAX_PENDING_BODY_BYTES) {
|
|
5316
|
-
throw new
|
|
4424
|
+
throw new APICallError({
|
|
5317
4425
|
message: `xAI video status response exceeded ${MAX_PENDING_BODY_BYTES} bytes`,
|
|
5318
4426
|
url,
|
|
5319
4427
|
requestBodyValues,
|
|
5320
4428
|
statusCode: response.status,
|
|
5321
|
-
responseHeaders:
|
|
4429
|
+
responseHeaders: extractResponseHeaders(response)
|
|
5322
4430
|
});
|
|
5323
4431
|
}
|
|
5324
4432
|
chunks.push(value);
|
|
@@ -5336,12 +4444,12 @@ async function readPendingBody({
|
|
|
5336
4444
|
}
|
|
5337
4445
|
var xaiVideoStatusResponseHandler = async (options) => {
|
|
5338
4446
|
if (options.response.status === 202) {
|
|
5339
|
-
const responseHeaders =
|
|
4447
|
+
const responseHeaders = extractResponseHeaders(options.response);
|
|
5340
4448
|
const text = await readPendingBody(options);
|
|
5341
4449
|
if (text.trim().length === 0) {
|
|
5342
4450
|
return { responseHeaders, value: { status: "pending" } };
|
|
5343
4451
|
}
|
|
5344
|
-
const parsed = await
|
|
4452
|
+
const parsed = await safeParseJSON({
|
|
5345
4453
|
text,
|
|
5346
4454
|
schema: xaiVideoStatusResponseSchema
|
|
5347
4455
|
});
|
|
@@ -5355,69 +4463,69 @@ var xaiVideoStatusResponseHandler = async (options) => {
|
|
|
5355
4463
|
|
|
5356
4464
|
// src/xai-speech-model.ts
|
|
5357
4465
|
import {
|
|
5358
|
-
combineHeaders as
|
|
4466
|
+
combineHeaders as combineHeaders6,
|
|
5359
4467
|
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
|
5360
4468
|
createBinaryResponseHandler as createBinaryResponseHandler3,
|
|
5361
|
-
createJsonResponseHandler as
|
|
5362
|
-
parseProviderOptions as
|
|
5363
|
-
postJsonToApi as
|
|
4469
|
+
createJsonResponseHandler as createJsonResponseHandler6,
|
|
4470
|
+
parseProviderOptions as parseProviderOptions7,
|
|
4471
|
+
postJsonToApi as postJsonToApi5,
|
|
5364
4472
|
resolve,
|
|
5365
|
-
serializeModelOptions as
|
|
5366
|
-
WORKFLOW_DESERIALIZE as
|
|
5367
|
-
WORKFLOW_SERIALIZE as
|
|
4473
|
+
serializeModelOptions as serializeModelOptions3,
|
|
4474
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
|
|
4475
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3
|
|
5368
4476
|
} from "@ai-sdk/provider-utils";
|
|
5369
|
-
import { z as
|
|
4477
|
+
import { z as z21 } from "zod/v4";
|
|
5370
4478
|
|
|
5371
4479
|
// src/xai-speech-model-options.ts
|
|
5372
4480
|
import {
|
|
5373
4481
|
lazySchema as lazySchema10,
|
|
5374
4482
|
zodSchema as zodSchema10
|
|
5375
4483
|
} from "@ai-sdk/provider-utils";
|
|
5376
|
-
import { z as
|
|
4484
|
+
import { z as z20 } from "zod/v4";
|
|
5377
4485
|
var xaiSpeechModelOptionsSchema = lazySchema10(
|
|
5378
4486
|
() => zodSchema10(
|
|
5379
|
-
|
|
4487
|
+
z20.object({
|
|
5380
4488
|
/**
|
|
5381
4489
|
* Sample rate of the generated audio in Hz.
|
|
5382
4490
|
*/
|
|
5383
|
-
sampleRate:
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
4491
|
+
sampleRate: z20.union([
|
|
4492
|
+
z20.literal(8e3),
|
|
4493
|
+
z20.literal(16e3),
|
|
4494
|
+
z20.literal(22050),
|
|
4495
|
+
z20.literal(24e3),
|
|
4496
|
+
z20.literal(44100),
|
|
4497
|
+
z20.literal(48e3)
|
|
5390
4498
|
]).nullish(),
|
|
5391
4499
|
/**
|
|
5392
4500
|
* MP3 bit rate in bits per second. Only applies when outputFormat is mp3.
|
|
5393
4501
|
*/
|
|
5394
|
-
bitRate:
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
4502
|
+
bitRate: z20.union([
|
|
4503
|
+
z20.literal(32e3),
|
|
4504
|
+
z20.literal(64e3),
|
|
4505
|
+
z20.literal(96e3),
|
|
4506
|
+
z20.literal(128e3),
|
|
4507
|
+
z20.literal(192e3)
|
|
5400
4508
|
]).nullish(),
|
|
5401
4509
|
/**
|
|
5402
4510
|
* Reduce time to first audio chunk, trading some quality for latency.
|
|
5403
4511
|
*/
|
|
5404
|
-
optimizeStreamingLatency:
|
|
4512
|
+
optimizeStreamingLatency: z20.union([z20.literal(0), z20.literal(1), z20.literal(2)]).nullish(),
|
|
5405
4513
|
/**
|
|
5406
4514
|
* Normalize written-form text into spoken-form text before synthesis.
|
|
5407
4515
|
*/
|
|
5408
|
-
textNormalization:
|
|
4516
|
+
textNormalization: z20.boolean().nullish(),
|
|
5409
4517
|
/**
|
|
5410
4518
|
* Return character-level timing metadata alongside the audio. When
|
|
5411
4519
|
* enabled, the response carries per-character start/end times and the
|
|
5412
4520
|
* total duration, exposed via `providerMetadata.xai`.
|
|
5413
4521
|
*/
|
|
5414
|
-
withTimestamps:
|
|
4522
|
+
withTimestamps: z20.boolean().nullish(),
|
|
5415
4523
|
/**
|
|
5416
4524
|
* Map of phrases to spoken substitutions applied before synthesis.
|
|
5417
4525
|
* Values may be respellings (`{ 'Acme Mobile': 'Acme Mobull' }`) or IPA
|
|
5418
4526
|
* phonetics (`{ nginx: '/ˈɛndʒɪn ˈɛks/' }`).
|
|
5419
4527
|
*/
|
|
5420
|
-
replace:
|
|
4528
|
+
replace: z20.record(z20.string(), z20.string()).nullish()
|
|
5421
4529
|
})
|
|
5422
4530
|
)
|
|
5423
4531
|
);
|
|
@@ -5429,13 +4537,13 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
5429
4537
|
this.config = config;
|
|
5430
4538
|
this.specificationVersion = "v4";
|
|
5431
4539
|
}
|
|
5432
|
-
static [
|
|
5433
|
-
return
|
|
4540
|
+
static [WORKFLOW_SERIALIZE3](model) {
|
|
4541
|
+
return serializeModelOptions3({
|
|
5434
4542
|
modelId: model.modelId,
|
|
5435
4543
|
config: model.config
|
|
5436
4544
|
});
|
|
5437
4545
|
}
|
|
5438
|
-
static [
|
|
4546
|
+
static [WORKFLOW_DESERIALIZE3](options) {
|
|
5439
4547
|
return new _XaiSpeechModel(options.modelId, options.config);
|
|
5440
4548
|
}
|
|
5441
4549
|
get provider() {
|
|
@@ -5451,7 +4559,7 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
5451
4559
|
providerOptions
|
|
5452
4560
|
}) {
|
|
5453
4561
|
const warnings = [];
|
|
5454
|
-
const xaiOptions = await
|
|
4562
|
+
const xaiOptions = await parseProviderOptions7({
|
|
5455
4563
|
provider: "xai",
|
|
5456
4564
|
providerOptions,
|
|
5457
4565
|
schema: xaiSpeechModelOptionsSchema
|
|
@@ -5511,15 +4619,15 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
5511
4619
|
var _a, _b, _c;
|
|
5512
4620
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
5513
4621
|
const { requestBody, warnings, withTimestamps } = await this.getArgs(options);
|
|
5514
|
-
const { value, responseHeaders, rawValue } = await
|
|
4622
|
+
const { value, responseHeaders, rawValue } = await postJsonToApi5({
|
|
5515
4623
|
url: `${this.config.baseURL}/tts`,
|
|
5516
|
-
headers:
|
|
4624
|
+
headers: combineHeaders6(
|
|
5517
4625
|
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
5518
4626
|
options.headers
|
|
5519
4627
|
),
|
|
5520
4628
|
body: requestBody,
|
|
5521
4629
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
5522
|
-
successfulResponseHandler: withTimestamps ?
|
|
4630
|
+
successfulResponseHandler: withTimestamps ? createJsonResponseHandler6(xaiSpeechTimestampsResponseSchema) : createBinaryResponseHandler3(),
|
|
5523
4631
|
abortSignal: options.abortSignal,
|
|
5524
4632
|
fetch: this.config.fetch
|
|
5525
4633
|
});
|
|
@@ -5560,13 +4668,13 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
5560
4668
|
};
|
|
5561
4669
|
}
|
|
5562
4670
|
};
|
|
5563
|
-
var xaiSpeechTimestampsResponseSchema =
|
|
5564
|
-
audio:
|
|
5565
|
-
content_type:
|
|
5566
|
-
duration:
|
|
5567
|
-
audio_timestamps:
|
|
5568
|
-
graph_chars:
|
|
5569
|
-
graph_times:
|
|
4671
|
+
var xaiSpeechTimestampsResponseSchema = z21.object({
|
|
4672
|
+
audio: z21.string().nullish(),
|
|
4673
|
+
content_type: z21.string().nullish(),
|
|
4674
|
+
duration: z21.number().nullish(),
|
|
4675
|
+
audio_timestamps: z21.object({
|
|
4676
|
+
graph_chars: z21.array(z21.string()),
|
|
4677
|
+
graph_times: z21.array(z21.tuple([z21.number(), z21.number()]))
|
|
5570
4678
|
}).nullish()
|
|
5571
4679
|
});
|
|
5572
4680
|
|
|
@@ -5575,94 +4683,94 @@ import {
|
|
|
5575
4683
|
InvalidArgumentError as InvalidArgumentError3
|
|
5576
4684
|
} from "@ai-sdk/provider";
|
|
5577
4685
|
import {
|
|
5578
|
-
combineHeaders as
|
|
4686
|
+
combineHeaders as combineHeaders7,
|
|
5579
4687
|
convertBase64ToUint8Array as convertBase64ToUint8Array3,
|
|
5580
|
-
createJsonResponseHandler as
|
|
4688
|
+
createJsonResponseHandler as createJsonResponseHandler7,
|
|
5581
4689
|
connectToWebSocket,
|
|
5582
4690
|
mediaTypeToExtension,
|
|
5583
|
-
parseProviderOptions as
|
|
4691
|
+
parseProviderOptions as parseProviderOptions8,
|
|
5584
4692
|
postFormDataToApi as postFormDataToApi3,
|
|
5585
|
-
safeParseJSON as
|
|
5586
|
-
serializeModelOptions as
|
|
4693
|
+
safeParseJSON as safeParseJSON2,
|
|
4694
|
+
serializeModelOptions as serializeModelOptions4,
|
|
5587
4695
|
toWebSocketUrl,
|
|
5588
4696
|
waitForWebSocketBufferDrain,
|
|
5589
|
-
WORKFLOW_DESERIALIZE as
|
|
5590
|
-
WORKFLOW_SERIALIZE as
|
|
4697
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4,
|
|
4698
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4
|
|
5591
4699
|
} from "@ai-sdk/provider-utils";
|
|
5592
|
-
import { z as
|
|
4700
|
+
import { z as z23 } from "zod/v4";
|
|
5593
4701
|
|
|
5594
4702
|
// src/xai-transcription-model-options.ts
|
|
5595
4703
|
import {
|
|
5596
4704
|
lazySchema as lazySchema11,
|
|
5597
4705
|
zodSchema as zodSchema11
|
|
5598
4706
|
} from "@ai-sdk/provider-utils";
|
|
5599
|
-
import { z as
|
|
4707
|
+
import { z as z22 } from "zod/v4";
|
|
5600
4708
|
var xaiTranscriptionModelOptionsSchema = lazySchema11(
|
|
5601
4709
|
() => zodSchema11(
|
|
5602
|
-
|
|
4710
|
+
z22.object({
|
|
5603
4711
|
/**
|
|
5604
4712
|
* Audio encoding for raw, headerless input audio.
|
|
5605
4713
|
*/
|
|
5606
|
-
audioFormat:
|
|
4714
|
+
audioFormat: z22.enum(["pcm", "mulaw", "alaw"]).nullish(),
|
|
5607
4715
|
/**
|
|
5608
4716
|
* Sample rate of the input audio in Hz.
|
|
5609
4717
|
*/
|
|
5610
|
-
sampleRate:
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
4718
|
+
sampleRate: z22.union([
|
|
4719
|
+
z22.literal(8e3),
|
|
4720
|
+
z22.literal(16e3),
|
|
4721
|
+
z22.literal(22050),
|
|
4722
|
+
z22.literal(24e3),
|
|
4723
|
+
z22.literal(44100),
|
|
4724
|
+
z22.literal(48e3)
|
|
5617
4725
|
]).nullish(),
|
|
5618
4726
|
/**
|
|
5619
4727
|
* Language code used for inverse text normalization.
|
|
5620
4728
|
*/
|
|
5621
|
-
language:
|
|
4729
|
+
language: z22.string().nullish(),
|
|
5622
4730
|
/**
|
|
5623
4731
|
* Enable inverse text normalization. Requires `language`.
|
|
5624
4732
|
*/
|
|
5625
|
-
format:
|
|
4733
|
+
format: z22.boolean().nullish(),
|
|
5626
4734
|
/**
|
|
5627
4735
|
* Enable per-channel transcription for multichannel audio.
|
|
5628
4736
|
*/
|
|
5629
|
-
multichannel:
|
|
4737
|
+
multichannel: z22.boolean().nullish(),
|
|
5630
4738
|
/**
|
|
5631
4739
|
* Number of interleaved audio channels.
|
|
5632
4740
|
*/
|
|
5633
|
-
channels:
|
|
4741
|
+
channels: z22.number().int().min(2).max(8).nullish(),
|
|
5634
4742
|
/**
|
|
5635
4743
|
* Enable speaker diarization.
|
|
5636
4744
|
*/
|
|
5637
|
-
diarize:
|
|
4745
|
+
diarize: z22.boolean().nullish(),
|
|
5638
4746
|
/**
|
|
5639
4747
|
* Terms to bias transcription toward.
|
|
5640
4748
|
*/
|
|
5641
|
-
keyterm:
|
|
4749
|
+
keyterm: z22.union([z22.string(), z22.array(z22.string())]).nullish(),
|
|
5642
4750
|
/**
|
|
5643
4751
|
* Include filler words such as "uh" and "um" in the transcript.
|
|
5644
4752
|
*/
|
|
5645
|
-
fillerWords:
|
|
4753
|
+
fillerWords: z22.boolean().nullish(),
|
|
5646
4754
|
/**
|
|
5647
4755
|
* Options for streaming speech-to-text over WebSocket.
|
|
5648
4756
|
*/
|
|
5649
|
-
streaming:
|
|
4757
|
+
streaming: z22.object({
|
|
5650
4758
|
/**
|
|
5651
4759
|
* Emit interim transcript results while speech is being processed.
|
|
5652
4760
|
*/
|
|
5653
|
-
interimResults:
|
|
4761
|
+
interimResults: z22.boolean().optional(),
|
|
5654
4762
|
/**
|
|
5655
4763
|
* Silence duration in milliseconds before an utterance-final event.
|
|
5656
4764
|
*/
|
|
5657
|
-
endpointing:
|
|
4765
|
+
endpointing: z22.number().int().min(0).max(5e3).optional(),
|
|
5658
4766
|
/**
|
|
5659
4767
|
* End-of-turn detection threshold. When set, enables Smart Turn.
|
|
5660
4768
|
*/
|
|
5661
|
-
smartTurn:
|
|
4769
|
+
smartTurn: z22.number().min(0).max(1).optional(),
|
|
5662
4770
|
/**
|
|
5663
4771
|
* Maximum silence duration in milliseconds before forcing speech_final.
|
|
5664
4772
|
*/
|
|
5665
|
-
smartTurnTimeout:
|
|
4773
|
+
smartTurnTimeout: z22.number().int().min(1).max(5e3).optional()
|
|
5666
4774
|
}).optional()
|
|
5667
4775
|
})
|
|
5668
4776
|
)
|
|
@@ -5675,13 +4783,13 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5675
4783
|
this.config = config;
|
|
5676
4784
|
this.specificationVersion = "v4";
|
|
5677
4785
|
}
|
|
5678
|
-
static [
|
|
5679
|
-
return
|
|
4786
|
+
static [WORKFLOW_SERIALIZE4](model) {
|
|
4787
|
+
return serializeModelOptions4({
|
|
5680
4788
|
modelId: model.modelId,
|
|
5681
4789
|
config: model.config
|
|
5682
4790
|
});
|
|
5683
4791
|
}
|
|
5684
|
-
static [
|
|
4792
|
+
static [WORKFLOW_DESERIALIZE4](options) {
|
|
5685
4793
|
return new _XaiTranscriptionModel(options.modelId, options.config);
|
|
5686
4794
|
}
|
|
5687
4795
|
get provider() {
|
|
@@ -5693,7 +4801,7 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5693
4801
|
providerOptions
|
|
5694
4802
|
}) {
|
|
5695
4803
|
const warnings = [];
|
|
5696
|
-
const xaiOptions = await
|
|
4804
|
+
const xaiOptions = await parseProviderOptions8({
|
|
5697
4805
|
provider: "xai",
|
|
5698
4806
|
providerOptions,
|
|
5699
4807
|
schema: xaiTranscriptionModelOptionsSchema
|
|
@@ -5739,10 +4847,10 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5739
4847
|
rawValue: rawResponse
|
|
5740
4848
|
} = await postFormDataToApi3({
|
|
5741
4849
|
url: `${(_d = this.config.baseURL) != null ? _d : "https://api.x.ai/v1"}/stt`,
|
|
5742
|
-
headers:
|
|
4850
|
+
headers: combineHeaders7((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), options.headers),
|
|
5743
4851
|
formData,
|
|
5744
4852
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
5745
|
-
successfulResponseHandler:
|
|
4853
|
+
successfulResponseHandler: createJsonResponseHandler7(
|
|
5746
4854
|
xaiTranscriptionResponseSchema
|
|
5747
4855
|
),
|
|
5748
4856
|
abortSignal: options.abortSignal,
|
|
@@ -5770,7 +4878,7 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5770
4878
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
5771
4879
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
5772
4880
|
const warnings = [];
|
|
5773
|
-
const xaiOptions = await
|
|
4881
|
+
const xaiOptions = await parseProviderOptions8({
|
|
5774
4882
|
provider: "xai",
|
|
5775
4883
|
providerOptions: options.providerOptions,
|
|
5776
4884
|
schema: xaiTranscriptionModelOptionsSchema
|
|
@@ -5799,7 +4907,7 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5799
4907
|
inputAudioFormat: options.inputAudioFormat,
|
|
5800
4908
|
providerOptions: xaiOptions
|
|
5801
4909
|
});
|
|
5802
|
-
const headers =
|
|
4910
|
+
const headers = combineHeaders7((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), options.headers);
|
|
5803
4911
|
return {
|
|
5804
4912
|
request: { body: url.toString() },
|
|
5805
4913
|
response: {
|
|
@@ -5900,7 +5008,7 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5900
5008
|
onProcessingError: finishWithError,
|
|
5901
5009
|
onMessageText: async (text) => {
|
|
5902
5010
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
5903
|
-
const parsed = await
|
|
5011
|
+
const parsed = await safeParseJSON2({ text });
|
|
5904
5012
|
if (!parsed.success) return;
|
|
5905
5013
|
const raw = parsed.value;
|
|
5906
5014
|
if (includeRawChunks) {
|
|
@@ -6061,15 +5169,15 @@ function timingFromXaiEvent(event) {
|
|
|
6061
5169
|
...event.start != null && event.duration != null ? { endSecond: event.start + event.duration } : {}
|
|
6062
5170
|
};
|
|
6063
5171
|
}
|
|
6064
|
-
var xaiTranscriptionResponseSchema =
|
|
6065
|
-
text:
|
|
6066
|
-
language:
|
|
6067
|
-
duration:
|
|
6068
|
-
words:
|
|
6069
|
-
|
|
6070
|
-
text:
|
|
6071
|
-
start:
|
|
6072
|
-
end:
|
|
5172
|
+
var xaiTranscriptionResponseSchema = z23.object({
|
|
5173
|
+
text: z23.string(),
|
|
5174
|
+
language: z23.string().nullish(),
|
|
5175
|
+
duration: z23.number().nullish(),
|
|
5176
|
+
words: z23.array(
|
|
5177
|
+
z23.object({
|
|
5178
|
+
text: z23.string(),
|
|
5179
|
+
start: z23.number(),
|
|
5180
|
+
end: z23.number()
|
|
6073
5181
|
})
|
|
6074
5182
|
).nullish()
|
|
6075
5183
|
});
|
|
@@ -6091,15 +5199,6 @@ function createXai(options = {}) {
|
|
|
6091
5199
|
},
|
|
6092
5200
|
`ai-sdk/xai/${VERSION}`
|
|
6093
5201
|
);
|
|
6094
|
-
const createChatLanguageModel = (modelId) => {
|
|
6095
|
-
return new XaiChatLanguageModel(modelId, {
|
|
6096
|
-
provider: "xai.chat",
|
|
6097
|
-
baseURL,
|
|
6098
|
-
headers: getHeaders,
|
|
6099
|
-
generateId,
|
|
6100
|
-
fetch: options.fetch
|
|
6101
|
-
});
|
|
6102
|
-
};
|
|
6103
5202
|
const createResponsesLanguageModel = (modelId) => {
|
|
6104
5203
|
return new XaiResponsesLanguageModel(modelId, {
|
|
6105
5204
|
provider: "xai.responses",
|
|
@@ -6186,7 +5285,6 @@ function createXai(options = {}) {
|
|
|
6186
5285
|
const provider = (modelId) => createResponsesLanguageModel(modelId);
|
|
6187
5286
|
provider.specificationVersion = "v4";
|
|
6188
5287
|
provider.languageModel = createResponsesLanguageModel;
|
|
6189
|
-
provider.chat = createChatLanguageModel;
|
|
6190
5288
|
provider.responses = createResponsesLanguageModel;
|
|
6191
5289
|
provider.embeddingModel = (modelId) => {
|
|
6192
5290
|
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|