@ai-sdk/xai 4.0.59 → 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 +6 -0
- package/dist/index.d.ts +5 -61
- package/dist/index.js +908 -1790
- package/dist/index.js.map +1 -1
- package/docs/01-xai.mdx +2 -12
- package/package.json +1 -1
- package/src/index.ts +0 -5
- 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/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 -98
package/dist/index.js
CHANGED
|
@@ -9,1051 +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
|
-
function prepareTools({
|
|
410
|
-
tools,
|
|
411
|
-
toolChoice
|
|
412
|
-
}) {
|
|
413
|
-
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
414
|
-
const toolWarnings = [];
|
|
415
|
-
if (tools == null) {
|
|
416
|
-
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
417
|
-
}
|
|
418
|
-
const xaiTools2 = [];
|
|
419
|
-
for (const tool of tools) {
|
|
420
|
-
if (tool.type === "provider") {
|
|
421
|
-
toolWarnings.push({
|
|
422
|
-
type: "unsupported",
|
|
423
|
-
feature: `provider-defined tool ${tool.name}`
|
|
424
|
-
});
|
|
425
|
-
} else {
|
|
426
|
-
xaiTools2.push({
|
|
427
|
-
type: "function",
|
|
428
|
-
function: {
|
|
429
|
-
name: tool.name,
|
|
430
|
-
description: tool.description,
|
|
431
|
-
parameters: tool.inputSchema,
|
|
432
|
-
...tool.strict != null ? { strict: tool.strict } : {}
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
if (toolChoice == null) {
|
|
438
|
-
return { tools: xaiTools2, toolChoice: void 0, toolWarnings };
|
|
439
|
-
}
|
|
440
|
-
const type = toolChoice.type;
|
|
441
|
-
switch (type) {
|
|
442
|
-
case "auto":
|
|
443
|
-
case "none":
|
|
444
|
-
return { tools: xaiTools2, toolChoice: type, toolWarnings };
|
|
445
|
-
case "required":
|
|
446
|
-
return { tools: xaiTools2, toolChoice: "required", toolWarnings };
|
|
447
|
-
case "tool":
|
|
448
|
-
return {
|
|
449
|
-
tools: xaiTools2,
|
|
450
|
-
toolChoice: {
|
|
451
|
-
type: "function",
|
|
452
|
-
function: { name: toolChoice.toolName }
|
|
453
|
-
},
|
|
454
|
-
toolWarnings
|
|
455
|
-
};
|
|
456
|
-
default: {
|
|
457
|
-
const _exhaustiveCheck = type;
|
|
458
|
-
throw new UnsupportedFunctionalityError2({
|
|
459
|
-
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
// src/xai-chat-language-model.ts
|
|
466
|
-
var XaiChatLanguageModel = class _XaiChatLanguageModel {
|
|
467
|
-
constructor(modelId, config) {
|
|
468
|
-
this.specificationVersion = "v4";
|
|
469
|
-
this.supportedUrls = {
|
|
470
|
-
"image/*": [/^https?:\/\/.*$/]
|
|
471
|
-
};
|
|
472
|
-
this.modelId = modelId;
|
|
473
|
-
this.config = config;
|
|
474
|
-
}
|
|
475
|
-
static [WORKFLOW_SERIALIZE](model) {
|
|
476
|
-
return serializeModelOptions({
|
|
477
|
-
modelId: model.modelId,
|
|
478
|
-
config: model.config
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
static [WORKFLOW_DESERIALIZE](options) {
|
|
482
|
-
return new _XaiChatLanguageModel(options.modelId, options.config);
|
|
483
|
-
}
|
|
484
|
-
get provider() {
|
|
485
|
-
return this.config.provider;
|
|
486
|
-
}
|
|
487
|
-
async getArgs({
|
|
488
|
-
prompt,
|
|
489
|
-
maxOutputTokens,
|
|
490
|
-
temperature,
|
|
491
|
-
topP,
|
|
492
|
-
topK,
|
|
493
|
-
frequencyPenalty,
|
|
494
|
-
presencePenalty,
|
|
495
|
-
stopSequences,
|
|
496
|
-
seed,
|
|
497
|
-
reasoning,
|
|
498
|
-
responseFormat,
|
|
499
|
-
providerOptions,
|
|
500
|
-
tools,
|
|
501
|
-
toolChoice
|
|
502
|
-
}) {
|
|
503
|
-
var _a, _b, _c;
|
|
504
|
-
const warnings = [];
|
|
505
|
-
const options = (_a = await parseProviderOptions2({
|
|
506
|
-
provider: "xai",
|
|
507
|
-
providerOptions,
|
|
508
|
-
schema: xaiLanguageModelChatOptions
|
|
509
|
-
})) != null ? _a : {};
|
|
510
|
-
if (topK != null) {
|
|
511
|
-
warnings.push({ type: "unsupported", feature: "topK" });
|
|
512
|
-
}
|
|
513
|
-
if (frequencyPenalty != null) {
|
|
514
|
-
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
515
|
-
}
|
|
516
|
-
if (presencePenalty != null) {
|
|
517
|
-
warnings.push({ type: "unsupported", feature: "presencePenalty" });
|
|
518
|
-
}
|
|
519
|
-
if (stopSequences != null) {
|
|
520
|
-
warnings.push({ type: "unsupported", feature: "stopSequences" });
|
|
521
|
-
}
|
|
522
|
-
const { messages, warnings: messageWarnings } = await convertToXaiChatMessages(prompt);
|
|
523
|
-
warnings.push(...messageWarnings);
|
|
524
|
-
const {
|
|
525
|
-
tools: xaiTools2,
|
|
526
|
-
toolChoice: xaiToolChoice,
|
|
527
|
-
toolWarnings
|
|
528
|
-
} = prepareTools({
|
|
529
|
-
tools,
|
|
530
|
-
toolChoice
|
|
531
|
-
});
|
|
532
|
-
warnings.push(...toolWarnings);
|
|
533
|
-
let reasoningEffort = options.reasoningEffort;
|
|
534
|
-
if (reasoningEffort == null && isCustomReasoning(reasoning)) {
|
|
535
|
-
if (!supportsReasoningEffort(this.modelId)) {
|
|
536
|
-
warnings.push({
|
|
537
|
-
type: "unsupported",
|
|
538
|
-
feature: "reasoning",
|
|
539
|
-
details: `reasoning "${reasoning}" is not supported by this model.`
|
|
540
|
-
});
|
|
541
|
-
} else if (reasoning === "none") {
|
|
542
|
-
reasoningEffort = "none";
|
|
543
|
-
} else {
|
|
544
|
-
reasoningEffort = mapReasoningToProviderEffort({
|
|
545
|
-
reasoning,
|
|
546
|
-
effortMap: {
|
|
547
|
-
minimal: "low",
|
|
548
|
-
low: "low",
|
|
549
|
-
medium: "medium",
|
|
550
|
-
high: "high",
|
|
551
|
-
xhigh: this.modelId === "grok-4.6" ? "xhigh" : "high"
|
|
552
|
-
},
|
|
553
|
-
warnings
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
const baseArgs = {
|
|
558
|
-
// model id
|
|
559
|
-
model: this.modelId,
|
|
560
|
-
// standard generation settings
|
|
561
|
-
logprobs: options.logprobs === true || options.topLogprobs != null ? true : void 0,
|
|
562
|
-
top_logprobs: options.topLogprobs,
|
|
563
|
-
max_completion_tokens: maxOutputTokens,
|
|
564
|
-
temperature,
|
|
565
|
-
top_p: topP,
|
|
566
|
-
seed,
|
|
567
|
-
reasoning_effort: reasoningEffort,
|
|
568
|
-
// scheduling priority
|
|
569
|
-
service_tier: options.serviceTier,
|
|
570
|
-
// parallel function calling
|
|
571
|
-
parallel_function_calling: options.parallel_function_calling,
|
|
572
|
-
// response format
|
|
573
|
-
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
|
|
574
|
-
type: "json_schema",
|
|
575
|
-
json_schema: {
|
|
576
|
-
name: (_b = responseFormat.name) != null ? _b : "response",
|
|
577
|
-
schema: responseFormat.schema,
|
|
578
|
-
strict: true
|
|
579
|
-
}
|
|
580
|
-
} : { type: "json_object" } : void 0,
|
|
581
|
-
// search parameters
|
|
582
|
-
search_parameters: options.searchParameters ? {
|
|
583
|
-
mode: options.searchParameters.mode,
|
|
584
|
-
return_citations: options.searchParameters.returnCitations,
|
|
585
|
-
from_date: options.searchParameters.fromDate,
|
|
586
|
-
to_date: options.searchParameters.toDate,
|
|
587
|
-
max_search_results: options.searchParameters.maxSearchResults,
|
|
588
|
-
sources: (_c = options.searchParameters.sources) == null ? void 0 : _c.map((source) => {
|
|
589
|
-
var _a2;
|
|
590
|
-
return {
|
|
591
|
-
type: source.type,
|
|
592
|
-
...source.type === "web" && {
|
|
593
|
-
country: source.country,
|
|
594
|
-
excluded_websites: source.excludedWebsites,
|
|
595
|
-
allowed_websites: source.allowedWebsites,
|
|
596
|
-
safe_search: source.safeSearch
|
|
597
|
-
},
|
|
598
|
-
...source.type === "x" && {
|
|
599
|
-
excluded_x_handles: source.excludedXHandles,
|
|
600
|
-
included_x_handles: (_a2 = source.includedXHandles) != null ? _a2 : source.xHandles,
|
|
601
|
-
post_favorite_count: source.postFavoriteCount,
|
|
602
|
-
post_view_count: source.postViewCount
|
|
603
|
-
},
|
|
604
|
-
...source.type === "news" && {
|
|
605
|
-
country: source.country,
|
|
606
|
-
excluded_websites: source.excludedWebsites,
|
|
607
|
-
safe_search: source.safeSearch
|
|
608
|
-
},
|
|
609
|
-
...source.type === "rss" && {
|
|
610
|
-
links: source.links
|
|
611
|
-
}
|
|
612
|
-
};
|
|
613
|
-
})
|
|
614
|
-
} : void 0,
|
|
615
|
-
// messages in xai format
|
|
616
|
-
messages,
|
|
617
|
-
// tools in xai format
|
|
618
|
-
tools: xaiTools2,
|
|
619
|
-
tool_choice: xaiToolChoice
|
|
620
|
-
};
|
|
621
|
-
return {
|
|
622
|
-
args: baseArgs,
|
|
623
|
-
warnings
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
async doGenerate(options) {
|
|
627
|
-
var _a, _b, _c, _d;
|
|
628
|
-
const { args: body, warnings } = await this.getArgs(options);
|
|
629
|
-
const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
|
|
630
|
-
const {
|
|
631
|
-
responseHeaders,
|
|
632
|
-
value: response,
|
|
633
|
-
rawValue: rawResponse
|
|
634
|
-
} = await postJsonToApi({
|
|
635
|
-
url,
|
|
636
|
-
headers: combineHeaders((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
637
|
-
body,
|
|
638
|
-
failedResponseHandler: xaiFailedResponseHandler,
|
|
639
|
-
successfulResponseHandler: createJsonResponseHandler(
|
|
640
|
-
xaiChatResponseSchema
|
|
641
|
-
),
|
|
642
|
-
abortSignal: options.abortSignal,
|
|
643
|
-
fetch: this.config.fetch
|
|
644
|
-
});
|
|
645
|
-
if (response.error != null) {
|
|
646
|
-
throw new APICallError({
|
|
647
|
-
message: response.error,
|
|
648
|
-
url,
|
|
649
|
-
requestBodyValues: body,
|
|
650
|
-
statusCode: 200,
|
|
651
|
-
responseHeaders,
|
|
652
|
-
responseBody: JSON.stringify(rawResponse),
|
|
653
|
-
isRetryable: response.code === "The service is currently unavailable"
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
const choice = response.choices[0];
|
|
657
|
-
const content = [];
|
|
658
|
-
if (choice.message.content != null && choice.message.content.length > 0) {
|
|
659
|
-
let text = choice.message.content;
|
|
660
|
-
const lastMessage = body.messages[body.messages.length - 1];
|
|
661
|
-
if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && text === lastMessage.content) {
|
|
662
|
-
text = "";
|
|
663
|
-
}
|
|
664
|
-
if (text.length > 0) {
|
|
665
|
-
content.push({ type: "text", text });
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
if (choice.message.reasoning_content != null && choice.message.reasoning_content.length > 0) {
|
|
669
|
-
content.push({
|
|
670
|
-
type: "reasoning",
|
|
671
|
-
text: choice.message.reasoning_content
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
if (choice.message.tool_calls != null) {
|
|
675
|
-
for (const toolCall of choice.message.tool_calls) {
|
|
676
|
-
content.push({
|
|
677
|
-
type: "tool-call",
|
|
678
|
-
toolCallId: toolCall.id,
|
|
679
|
-
toolName: toolCall.function.name,
|
|
680
|
-
input: toolCall.function.arguments
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
if (response.citations != null) {
|
|
685
|
-
for (const url2 of response.citations) {
|
|
686
|
-
content.push({
|
|
687
|
-
type: "source",
|
|
688
|
-
sourceType: "url",
|
|
689
|
-
id: this.config.generateId(),
|
|
690
|
-
url: url2
|
|
691
|
-
});
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
return {
|
|
695
|
-
content,
|
|
696
|
-
finishReason: {
|
|
697
|
-
unified: mapXaiFinishReason(choice.finish_reason),
|
|
698
|
-
raw: (_d = choice.finish_reason) != null ? _d : void 0
|
|
699
|
-
},
|
|
700
|
-
usage: response.usage ? convertXaiChatUsage(response.usage) : {
|
|
701
|
-
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
702
|
-
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
703
|
-
},
|
|
704
|
-
...response.service_tier != null && {
|
|
705
|
-
providerMetadata: {
|
|
706
|
-
xai: { serviceTier: response.service_tier }
|
|
707
|
-
}
|
|
708
|
-
},
|
|
709
|
-
request: { body },
|
|
710
|
-
response: {
|
|
711
|
-
...getResponseMetadata(response),
|
|
712
|
-
headers: responseHeaders,
|
|
713
|
-
body: rawResponse
|
|
714
|
-
},
|
|
715
|
-
warnings
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
async doStream(options) {
|
|
719
|
-
var _a, _b, _c;
|
|
720
|
-
const { args, warnings } = await this.getArgs(options);
|
|
721
|
-
const body = {
|
|
722
|
-
...args,
|
|
723
|
-
stream: true,
|
|
724
|
-
stream_options: {
|
|
725
|
-
include_usage: true
|
|
726
|
-
}
|
|
727
|
-
};
|
|
728
|
-
const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
|
|
729
|
-
const { responseHeaders, value: response } = await postJsonToApi({
|
|
730
|
-
url,
|
|
731
|
-
headers: combineHeaders((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
732
|
-
body,
|
|
733
|
-
failedResponseHandler: xaiFailedResponseHandler,
|
|
734
|
-
successfulResponseHandler: async ({ response: response2 }) => {
|
|
735
|
-
const responseHeaders2 = extractResponseHeaders(response2);
|
|
736
|
-
const contentType = response2.headers.get("content-type");
|
|
737
|
-
if (contentType == null ? void 0 : contentType.includes("application/json")) {
|
|
738
|
-
const responseBody = await response2.text();
|
|
739
|
-
const parsedError = await safeParseJSON({
|
|
740
|
-
text: responseBody,
|
|
741
|
-
schema: xaiStreamErrorSchema
|
|
742
|
-
});
|
|
743
|
-
if (parsedError.success) {
|
|
744
|
-
throw new APICallError({
|
|
745
|
-
message: parsedError.value.error,
|
|
746
|
-
url,
|
|
747
|
-
requestBodyValues: body,
|
|
748
|
-
statusCode: 200,
|
|
749
|
-
responseHeaders: responseHeaders2,
|
|
750
|
-
responseBody,
|
|
751
|
-
isRetryable: parsedError.value.code === "The service is currently unavailable"
|
|
752
|
-
});
|
|
753
|
-
}
|
|
754
|
-
throw new APICallError({
|
|
755
|
-
message: "Invalid JSON response",
|
|
756
|
-
url,
|
|
757
|
-
requestBodyValues: body,
|
|
758
|
-
statusCode: 200,
|
|
759
|
-
responseHeaders: responseHeaders2,
|
|
760
|
-
responseBody
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
return createEventSourceResponseHandler(xaiChatChunkSchema)({
|
|
764
|
-
response: response2,
|
|
765
|
-
url,
|
|
766
|
-
requestBodyValues: body
|
|
767
|
-
});
|
|
768
|
-
},
|
|
769
|
-
abortSignal: options.abortSignal,
|
|
770
|
-
fetch: this.config.fetch
|
|
771
|
-
});
|
|
772
|
-
let finishReason = {
|
|
773
|
-
unified: "other",
|
|
774
|
-
raw: void 0
|
|
775
|
-
};
|
|
776
|
-
let usage = void 0;
|
|
777
|
-
let serviceTier = void 0;
|
|
778
|
-
let isFirstChunk = true;
|
|
779
|
-
const contentBlocks = {};
|
|
780
|
-
const lastReasoningDeltas = {};
|
|
781
|
-
let activeReasoningBlockId = void 0;
|
|
782
|
-
const self = this;
|
|
783
|
-
return {
|
|
784
|
-
stream: response.pipeThrough(
|
|
785
|
-
new TransformStream({
|
|
786
|
-
start(controller) {
|
|
787
|
-
controller.enqueue({ type: "stream-start", warnings });
|
|
788
|
-
},
|
|
789
|
-
transform(chunk, controller) {
|
|
790
|
-
if (options.includeRawChunks) {
|
|
791
|
-
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
792
|
-
}
|
|
793
|
-
if (!chunk.success) {
|
|
794
|
-
controller.enqueue({ type: "error", error: chunk.error });
|
|
795
|
-
return;
|
|
796
|
-
}
|
|
797
|
-
const value = chunk.value;
|
|
798
|
-
if (isFirstChunk) {
|
|
799
|
-
controller.enqueue({
|
|
800
|
-
type: "response-metadata",
|
|
801
|
-
...getResponseMetadata(value)
|
|
802
|
-
});
|
|
803
|
-
isFirstChunk = false;
|
|
804
|
-
}
|
|
805
|
-
if (value.citations != null) {
|
|
806
|
-
for (const url2 of value.citations) {
|
|
807
|
-
controller.enqueue({
|
|
808
|
-
type: "source",
|
|
809
|
-
sourceType: "url",
|
|
810
|
-
id: self.config.generateId(),
|
|
811
|
-
url: url2
|
|
812
|
-
});
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
if (value.usage != null) {
|
|
816
|
-
usage = convertXaiChatUsage(value.usage);
|
|
817
|
-
}
|
|
818
|
-
if (value.service_tier != null) {
|
|
819
|
-
serviceTier = value.service_tier;
|
|
820
|
-
}
|
|
821
|
-
const choice = value.choices[0];
|
|
822
|
-
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
823
|
-
finishReason = {
|
|
824
|
-
unified: mapXaiFinishReason(choice.finish_reason),
|
|
825
|
-
raw: choice.finish_reason
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
|
-
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
829
|
-
return;
|
|
830
|
-
}
|
|
831
|
-
const delta = choice.delta;
|
|
832
|
-
const choiceIndex = choice.index;
|
|
833
|
-
if (delta.content != null && delta.content.length > 0) {
|
|
834
|
-
const textContent = delta.content;
|
|
835
|
-
if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
|
|
836
|
-
controller.enqueue({
|
|
837
|
-
type: "reasoning-end",
|
|
838
|
-
id: activeReasoningBlockId
|
|
839
|
-
});
|
|
840
|
-
contentBlocks[activeReasoningBlockId].ended = true;
|
|
841
|
-
activeReasoningBlockId = void 0;
|
|
842
|
-
}
|
|
843
|
-
const lastMessage = body.messages[body.messages.length - 1];
|
|
844
|
-
if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && textContent === lastMessage.content) {
|
|
845
|
-
return;
|
|
846
|
-
}
|
|
847
|
-
const blockId = `text-${value.id || choiceIndex}`;
|
|
848
|
-
if (contentBlocks[blockId] == null) {
|
|
849
|
-
contentBlocks[blockId] = { type: "text", ended: false };
|
|
850
|
-
controller.enqueue({
|
|
851
|
-
type: "text-start",
|
|
852
|
-
id: blockId
|
|
853
|
-
});
|
|
854
|
-
}
|
|
855
|
-
controller.enqueue({
|
|
856
|
-
type: "text-delta",
|
|
857
|
-
id: blockId,
|
|
858
|
-
delta: textContent
|
|
859
|
-
});
|
|
860
|
-
}
|
|
861
|
-
if (delta.reasoning_content != null && delta.reasoning_content.length > 0) {
|
|
862
|
-
const blockId = `reasoning-${value.id || choiceIndex}`;
|
|
863
|
-
if (lastReasoningDeltas[blockId] === delta.reasoning_content) {
|
|
864
|
-
return;
|
|
865
|
-
}
|
|
866
|
-
lastReasoningDeltas[blockId] = delta.reasoning_content;
|
|
867
|
-
if (contentBlocks[blockId] == null) {
|
|
868
|
-
contentBlocks[blockId] = { type: "reasoning", ended: false };
|
|
869
|
-
activeReasoningBlockId = blockId;
|
|
870
|
-
controller.enqueue({
|
|
871
|
-
type: "reasoning-start",
|
|
872
|
-
id: blockId
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
controller.enqueue({
|
|
876
|
-
type: "reasoning-delta",
|
|
877
|
-
id: blockId,
|
|
878
|
-
delta: delta.reasoning_content
|
|
879
|
-
});
|
|
880
|
-
}
|
|
881
|
-
if (delta.tool_calls != null && delta.tool_calls.length > 0) {
|
|
882
|
-
if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
|
|
883
|
-
controller.enqueue({
|
|
884
|
-
type: "reasoning-end",
|
|
885
|
-
id: activeReasoningBlockId
|
|
886
|
-
});
|
|
887
|
-
contentBlocks[activeReasoningBlockId].ended = true;
|
|
888
|
-
activeReasoningBlockId = void 0;
|
|
889
|
-
}
|
|
890
|
-
for (const toolCall of delta.tool_calls) {
|
|
891
|
-
const toolCallId = toolCall.id;
|
|
892
|
-
controller.enqueue({
|
|
893
|
-
type: "tool-input-start",
|
|
894
|
-
id: toolCallId,
|
|
895
|
-
toolName: toolCall.function.name
|
|
896
|
-
});
|
|
897
|
-
controller.enqueue({
|
|
898
|
-
type: "tool-input-delta",
|
|
899
|
-
id: toolCallId,
|
|
900
|
-
delta: toolCall.function.arguments
|
|
901
|
-
});
|
|
902
|
-
controller.enqueue({
|
|
903
|
-
type: "tool-input-end",
|
|
904
|
-
id: toolCallId
|
|
905
|
-
});
|
|
906
|
-
controller.enqueue({
|
|
907
|
-
type: "tool-call",
|
|
908
|
-
toolCallId,
|
|
909
|
-
toolName: toolCall.function.name,
|
|
910
|
-
input: toolCall.function.arguments
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
},
|
|
915
|
-
flush(controller) {
|
|
916
|
-
for (const [blockId, block] of Object.entries(contentBlocks)) {
|
|
917
|
-
if (!block.ended) {
|
|
918
|
-
controller.enqueue({
|
|
919
|
-
type: block.type === "text" ? "text-end" : "reasoning-end",
|
|
920
|
-
id: blockId
|
|
921
|
-
});
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
controller.enqueue({
|
|
925
|
-
type: "finish",
|
|
926
|
-
finishReason,
|
|
927
|
-
usage: usage != null ? usage : {
|
|
928
|
-
inputTokens: {
|
|
929
|
-
total: 0,
|
|
930
|
-
noCache: 0,
|
|
931
|
-
cacheRead: 0,
|
|
932
|
-
cacheWrite: 0
|
|
933
|
-
},
|
|
934
|
-
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
935
|
-
},
|
|
936
|
-
...serviceTier != null && {
|
|
937
|
-
providerMetadata: { xai: { serviceTier } }
|
|
938
|
-
}
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
})
|
|
942
|
-
),
|
|
943
|
-
request: { body },
|
|
944
|
-
response: { headers: responseHeaders }
|
|
945
|
-
};
|
|
946
|
-
}
|
|
947
|
-
};
|
|
948
|
-
var xaiUsageSchema = z4.object({
|
|
949
|
-
prompt_tokens: z4.number(),
|
|
950
|
-
completion_tokens: z4.number(),
|
|
951
|
-
total_tokens: z4.number(),
|
|
952
|
-
cost_in_usd_ticks: z4.number().nullish(),
|
|
953
|
-
prompt_tokens_details: z4.object({
|
|
954
|
-
text_tokens: z4.number().nullish(),
|
|
955
|
-
audio_tokens: z4.number().nullish(),
|
|
956
|
-
image_tokens: z4.number().nullish(),
|
|
957
|
-
cached_tokens: z4.number().nullish()
|
|
958
|
-
}).catchall(z4.json()).nullish(),
|
|
959
|
-
completion_tokens_details: z4.object({
|
|
960
|
-
reasoning_tokens: z4.number().nullish(),
|
|
961
|
-
audio_tokens: z4.number().nullish(),
|
|
962
|
-
accepted_prediction_tokens: z4.number().nullish(),
|
|
963
|
-
rejected_prediction_tokens: z4.number().nullish()
|
|
964
|
-
}).catchall(z4.json()).nullish()
|
|
965
|
-
}).catchall(z4.json());
|
|
966
|
-
var xaiChatResponseSchema = z4.object({
|
|
967
|
-
id: z4.string().nullish(),
|
|
968
|
-
created: z4.number().nullish(),
|
|
969
|
-
model: z4.string().nullish(),
|
|
970
|
-
choices: z4.array(
|
|
971
|
-
z4.object({
|
|
972
|
-
message: z4.object({
|
|
973
|
-
role: z4.enum(["assistant", "tool"]),
|
|
974
|
-
content: z4.string().nullish(),
|
|
975
|
-
reasoning_content: z4.string().nullish(),
|
|
976
|
-
tool_calls: z4.array(
|
|
977
|
-
z4.object({
|
|
978
|
-
id: z4.string(),
|
|
979
|
-
type: z4.literal("function"),
|
|
980
|
-
function: z4.object({
|
|
981
|
-
name: z4.string(),
|
|
982
|
-
arguments: z4.string()
|
|
983
|
-
})
|
|
984
|
-
})
|
|
985
|
-
).nullish()
|
|
986
|
-
}),
|
|
987
|
-
index: z4.number(),
|
|
988
|
-
finish_reason: z4.string().nullish()
|
|
989
|
-
})
|
|
990
|
-
).nullish(),
|
|
991
|
-
object: z4.literal("chat.completion").nullish(),
|
|
992
|
-
usage: xaiUsageSchema.nullish(),
|
|
993
|
-
citations: z4.array(z4.string().url()).nullish(),
|
|
994
|
-
service_tier: z4.string().nullish(),
|
|
995
|
-
code: z4.string().nullish(),
|
|
996
|
-
error: z4.string().nullish()
|
|
997
|
-
});
|
|
998
|
-
var xaiChatChunkSchema = z4.object({
|
|
999
|
-
id: z4.string().nullish(),
|
|
1000
|
-
created: z4.number().nullish(),
|
|
1001
|
-
model: z4.string().nullish(),
|
|
1002
|
-
choices: z4.array(
|
|
1003
|
-
z4.object({
|
|
1004
|
-
delta: z4.object({
|
|
1005
|
-
role: z4.enum(["assistant"]).optional(),
|
|
1006
|
-
content: z4.string().nullish(),
|
|
1007
|
-
reasoning_content: z4.string().nullish(),
|
|
1008
|
-
tool_calls: z4.array(
|
|
1009
|
-
z4.object({
|
|
1010
|
-
id: z4.string(),
|
|
1011
|
-
type: z4.literal("function"),
|
|
1012
|
-
function: z4.object({
|
|
1013
|
-
name: z4.string(),
|
|
1014
|
-
arguments: z4.string()
|
|
1015
|
-
})
|
|
1016
|
-
})
|
|
1017
|
-
).nullish()
|
|
1018
|
-
}),
|
|
1019
|
-
finish_reason: z4.string().nullish(),
|
|
1020
|
-
index: z4.number()
|
|
1021
|
-
})
|
|
1022
|
-
),
|
|
1023
|
-
usage: xaiUsageSchema.nullish(),
|
|
1024
|
-
citations: z4.array(z4.string().url()).nullish(),
|
|
1025
|
-
service_tier: z4.string().nullish()
|
|
1026
|
-
});
|
|
1027
|
-
var xaiStreamErrorSchema = z4.object({
|
|
1028
|
-
code: z4.string(),
|
|
1029
|
-
error: z4.string()
|
|
1030
|
-
});
|
|
1031
|
-
|
|
1032
12
|
// src/xai-image-model.ts
|
|
1033
13
|
import {
|
|
1034
|
-
combineHeaders
|
|
14
|
+
combineHeaders,
|
|
1035
15
|
convertImageModelFileToDataUri,
|
|
1036
16
|
createBinaryResponseHandler,
|
|
1037
|
-
createJsonResponseHandler
|
|
17
|
+
createJsonResponseHandler,
|
|
1038
18
|
createStatusCodeErrorResponseHandler,
|
|
1039
19
|
getFromApi,
|
|
1040
|
-
parseProviderOptions
|
|
1041
|
-
postJsonToApi
|
|
1042
|
-
serializeModelOptions
|
|
1043
|
-
WORKFLOW_SERIALIZE
|
|
1044
|
-
WORKFLOW_DESERIALIZE
|
|
20
|
+
parseProviderOptions,
|
|
21
|
+
postJsonToApi,
|
|
22
|
+
serializeModelOptions,
|
|
23
|
+
WORKFLOW_SERIALIZE,
|
|
24
|
+
WORKFLOW_DESERIALIZE
|
|
1045
25
|
} from "@ai-sdk/provider-utils";
|
|
1046
|
-
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
|
+
});
|
|
1047
60
|
|
|
1048
61
|
// src/xai-image-model-options.ts
|
|
1049
|
-
import { z as
|
|
1050
|
-
var xaiImageModelOptions =
|
|
1051
|
-
aspect_ratio:
|
|
1052
|
-
output_format:
|
|
1053
|
-
sync_mode:
|
|
1054
|
-
resolution:
|
|
1055
|
-
quality:
|
|
1056
|
-
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()
|
|
1057
70
|
});
|
|
1058
71
|
|
|
1059
72
|
// src/xai-image-model.ts
|
|
@@ -1067,13 +80,13 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
1067
80
|
get provider() {
|
|
1068
81
|
return this.config.provider;
|
|
1069
82
|
}
|
|
1070
|
-
static [
|
|
1071
|
-
return
|
|
83
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
84
|
+
return serializeModelOptions({
|
|
1072
85
|
modelId: model.modelId,
|
|
1073
86
|
config: model.config
|
|
1074
87
|
});
|
|
1075
88
|
}
|
|
1076
|
-
static [
|
|
89
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
1077
90
|
return new _XaiImageModel(options.modelId, options.config);
|
|
1078
91
|
}
|
|
1079
92
|
async doGenerate({
|
|
@@ -1109,7 +122,7 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
1109
122
|
feature: "mask"
|
|
1110
123
|
});
|
|
1111
124
|
}
|
|
1112
|
-
const xaiOptions = await
|
|
125
|
+
const xaiOptions = await parseProviderOptions({
|
|
1113
126
|
provider: "xai",
|
|
1114
127
|
providerOptions,
|
|
1115
128
|
schema: xaiImageModelOptions
|
|
@@ -1151,12 +164,12 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
1151
164
|
}
|
|
1152
165
|
const baseURL = (_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1";
|
|
1153
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();
|
|
1154
|
-
const { value: response, responseHeaders } = await
|
|
167
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1155
168
|
url: `${baseURL}${endpoint}`,
|
|
1156
|
-
headers:
|
|
169
|
+
headers: combineHeaders((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), headers),
|
|
1157
170
|
body,
|
|
1158
171
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
1159
|
-
successfulResponseHandler:
|
|
172
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
1160
173
|
xaiImageResponseSchema
|
|
1161
174
|
),
|
|
1162
175
|
abortSignal,
|
|
@@ -1205,97 +218,154 @@ var XaiImageModel = class _XaiImageModel {
|
|
|
1205
218
|
return value;
|
|
1206
219
|
}
|
|
1207
220
|
};
|
|
1208
|
-
var xaiImageResponseSchema =
|
|
1209
|
-
data:
|
|
1210
|
-
|
|
1211
|
-
url:
|
|
1212
|
-
b64_json:
|
|
1213
|
-
revised_prompt:
|
|
1214
|
-
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()
|
|
1215
228
|
})
|
|
1216
229
|
),
|
|
1217
|
-
usage:
|
|
1218
|
-
cost_in_usd_ticks:
|
|
230
|
+
usage: z3.object({
|
|
231
|
+
cost_in_usd_ticks: z3.number().nullish()
|
|
1219
232
|
}).nullish()
|
|
1220
233
|
});
|
|
1221
234
|
|
|
1222
235
|
// src/xai-batch.ts
|
|
1223
236
|
import {
|
|
1224
237
|
InvalidArgumentError,
|
|
1225
|
-
UnsupportedFunctionalityError as
|
|
238
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
1226
239
|
} from "@ai-sdk/provider";
|
|
1227
240
|
import {
|
|
1228
|
-
combineHeaders as
|
|
241
|
+
combineHeaders as combineHeaders3,
|
|
1229
242
|
convertImageModelFileToDataUri as convertImageModelFileToDataUri2,
|
|
1230
243
|
convertBase64ToUint8Array,
|
|
1231
244
|
convertAsyncIteratorToReadableStream,
|
|
1232
|
-
createJsonResponseHandler as
|
|
245
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1233
246
|
createBinaryResponseHandler as createBinaryResponseHandler2,
|
|
1234
247
|
createNullLanguageModelUsage,
|
|
1235
248
|
getFromApi as getFromApi2,
|
|
1236
249
|
lazySchema as lazySchema7,
|
|
1237
250
|
normalizeBatchRequestCounts,
|
|
1238
|
-
parseProviderOptions as
|
|
251
|
+
parseProviderOptions as parseProviderOptions4,
|
|
1239
252
|
postFormDataToApi,
|
|
1240
|
-
postJsonToApi as
|
|
253
|
+
postJsonToApi as postJsonToApi3,
|
|
1241
254
|
safeValidateTypes,
|
|
1242
255
|
zodSchema as zodSchema7
|
|
1243
256
|
} from "@ai-sdk/provider-utils";
|
|
1244
|
-
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
|
+
}
|
|
1245
290
|
|
|
1246
291
|
// src/files/xai-files-api.ts
|
|
1247
292
|
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
1248
|
-
import { z as
|
|
293
|
+
import { z as z4 } from "zod/v4";
|
|
1249
294
|
var xaiFilesResponseSchema = lazySchema(
|
|
1250
295
|
() => zodSchema(
|
|
1251
|
-
|
|
1252
|
-
id:
|
|
1253
|
-
object:
|
|
1254
|
-
bytes:
|
|
1255
|
-
created_at:
|
|
1256
|
-
expires_at:
|
|
1257
|
-
filename:
|
|
1258
|
-
purpose:
|
|
1259
|
-
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()
|
|
1260
305
|
})
|
|
1261
306
|
)
|
|
1262
307
|
);
|
|
1263
308
|
var xaiFileDeleteResponseSchema = lazySchema(
|
|
1264
309
|
() => zodSchema(
|
|
1265
|
-
|
|
1266
|
-
id:
|
|
1267
|
-
object:
|
|
1268
|
-
deleted:
|
|
310
|
+
z4.object({
|
|
311
|
+
id: z4.string(),
|
|
312
|
+
object: z4.string().nullish(),
|
|
313
|
+
deleted: z4.boolean()
|
|
1269
314
|
})
|
|
1270
315
|
)
|
|
1271
316
|
);
|
|
1272
317
|
|
|
1273
318
|
// src/responses/xai-responses-language-model.ts
|
|
1274
319
|
import {
|
|
1275
|
-
combineHeaders as
|
|
1276
|
-
createEventSourceResponseHandler
|
|
1277
|
-
createJsonResponseHandler as
|
|
320
|
+
combineHeaders as combineHeaders2,
|
|
321
|
+
createEventSourceResponseHandler,
|
|
322
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
1278
323
|
createProviderStreamError,
|
|
1279
|
-
isCustomReasoning
|
|
1280
|
-
mapReasoningToProviderEffort
|
|
1281
|
-
parseProviderOptions as
|
|
1282
|
-
postJsonToApi as
|
|
1283
|
-
serializeModelOptions as
|
|
1284
|
-
WORKFLOW_SERIALIZE as
|
|
1285
|
-
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
|
|
1286
331
|
} from "@ai-sdk/provider-utils";
|
|
1287
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
|
+
|
|
1288
339
|
// src/responses/convert-to-xai-responses-input.ts
|
|
1289
340
|
import {
|
|
1290
|
-
UnsupportedFunctionalityError
|
|
341
|
+
UnsupportedFunctionalityError
|
|
1291
342
|
} from "@ai-sdk/provider";
|
|
1292
343
|
import {
|
|
1293
|
-
convertToBase64
|
|
1294
|
-
getTopLevelMediaType
|
|
1295
|
-
parseProviderOptions as
|
|
1296
|
-
resolveFullMediaType
|
|
1297
|
-
resolveProviderReference
|
|
344
|
+
convertToBase64,
|
|
345
|
+
getTopLevelMediaType,
|
|
346
|
+
parseProviderOptions as parseProviderOptions2,
|
|
347
|
+
resolveFullMediaType,
|
|
348
|
+
resolveProviderReference
|
|
1298
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
|
|
1299
369
|
async function convertToXaiResponsesInput({
|
|
1300
370
|
prompt
|
|
1301
371
|
}) {
|
|
@@ -1324,7 +394,7 @@ async function convertToXaiResponsesInput({
|
|
|
1324
394
|
case "reference": {
|
|
1325
395
|
contentParts.push({
|
|
1326
396
|
type: "input_file",
|
|
1327
|
-
file_id:
|
|
397
|
+
file_id: resolveProviderReference({
|
|
1328
398
|
reference: block.data.reference,
|
|
1329
399
|
provider: "xai"
|
|
1330
400
|
})
|
|
@@ -1332,15 +402,15 @@ async function convertToXaiResponsesInput({
|
|
|
1332
402
|
break;
|
|
1333
403
|
}
|
|
1334
404
|
case "text": {
|
|
1335
|
-
throw new
|
|
405
|
+
throw new UnsupportedFunctionalityError({
|
|
1336
406
|
functionality: "text file parts"
|
|
1337
407
|
});
|
|
1338
408
|
}
|
|
1339
409
|
case "url":
|
|
1340
410
|
case "data": {
|
|
1341
|
-
if (
|
|
1342
|
-
const imageUrl = block.data.type === "url" ? block.data.url.toString() : `data:${
|
|
1343
|
-
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({
|
|
1344
414
|
provider: "xai",
|
|
1345
415
|
providerOptions: block.providerOptions,
|
|
1346
416
|
schema: xaiFilePartProviderOptions
|
|
@@ -1358,7 +428,7 @@ async function convertToXaiResponsesInput({
|
|
|
1358
428
|
file_url: block.data.url.toString()
|
|
1359
429
|
});
|
|
1360
430
|
} else {
|
|
1361
|
-
throw new
|
|
431
|
+
throw new UnsupportedFunctionalityError({
|
|
1362
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)`
|
|
1363
433
|
});
|
|
1364
434
|
}
|
|
@@ -1491,10 +561,10 @@ async function convertToXaiResponsesInput({
|
|
|
1491
561
|
break;
|
|
1492
562
|
}
|
|
1493
563
|
case "file": {
|
|
1494
|
-
if (
|
|
564
|
+
if (getTopLevelMediaType(item.mediaType) === "image" && (item.data.type === "data" || item.data.type === "url")) {
|
|
1495
565
|
outputValue.push({
|
|
1496
566
|
type: "input_image",
|
|
1497
|
-
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)}`
|
|
1498
568
|
});
|
|
1499
569
|
}
|
|
1500
570
|
break;
|
|
@@ -1575,484 +645,484 @@ function mapXaiResponsesFinishReason(finishReason) {
|
|
|
1575
645
|
}
|
|
1576
646
|
|
|
1577
647
|
// src/responses/xai-responses-api.ts
|
|
1578
|
-
import { z as
|
|
1579
|
-
var annotationSchema =
|
|
1580
|
-
|
|
1581
|
-
type:
|
|
1582
|
-
url:
|
|
1583
|
-
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()
|
|
1584
654
|
}),
|
|
1585
|
-
|
|
1586
|
-
type:
|
|
655
|
+
z6.object({
|
|
656
|
+
type: z6.string()
|
|
1587
657
|
})
|
|
1588
658
|
]);
|
|
1589
|
-
var messageContentPartSchema =
|
|
1590
|
-
type:
|
|
1591
|
-
text:
|
|
1592
|
-
logprobs:
|
|
1593
|
-
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()
|
|
1594
664
|
});
|
|
1595
|
-
var reasoningSummaryPartSchema =
|
|
1596
|
-
type:
|
|
1597
|
-
text:
|
|
665
|
+
var reasoningSummaryPartSchema = z6.object({
|
|
666
|
+
type: z6.string(),
|
|
667
|
+
text: z6.string()
|
|
1598
668
|
});
|
|
1599
|
-
var toolCallSchema =
|
|
1600
|
-
name:
|
|
1601
|
-
arguments:
|
|
1602
|
-
input:
|
|
1603
|
-
call_id:
|
|
1604
|
-
id:
|
|
1605
|
-
status:
|
|
1606
|
-
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()
|
|
1607
677
|
});
|
|
1608
|
-
var webSearchWireSourceSchema =
|
|
1609
|
-
type:
|
|
1610
|
-
url:
|
|
678
|
+
var webSearchWireSourceSchema = z6.object({
|
|
679
|
+
type: z6.literal("url"),
|
|
680
|
+
url: z6.string()
|
|
1611
681
|
});
|
|
1612
|
-
var webSearchWireActionSchema =
|
|
1613
|
-
|
|
1614
|
-
type:
|
|
1615
|
-
query:
|
|
1616
|
-
queries:
|
|
1617
|
-
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()
|
|
1618
688
|
}),
|
|
1619
|
-
|
|
1620
|
-
type:
|
|
1621
|
-
url:
|
|
1622
|
-
sources:
|
|
689
|
+
z6.object({
|
|
690
|
+
type: z6.literal("open_page"),
|
|
691
|
+
url: z6.string().nullish(),
|
|
692
|
+
sources: z6.array(z6.unknown()).nullish()
|
|
1623
693
|
}),
|
|
1624
|
-
|
|
1625
|
-
type:
|
|
1626
|
-
url:
|
|
1627
|
-
pattern:
|
|
1628
|
-
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()
|
|
1629
699
|
})
|
|
1630
700
|
]);
|
|
1631
|
-
var mcpCallSchema =
|
|
1632
|
-
name:
|
|
1633
|
-
arguments:
|
|
1634
|
-
output:
|
|
1635
|
-
error:
|
|
1636
|
-
id:
|
|
1637
|
-
status:
|
|
1638
|
-
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()
|
|
1639
709
|
});
|
|
1640
|
-
var outputItemSchema =
|
|
1641
|
-
|
|
1642
|
-
type:
|
|
710
|
+
var outputItemSchema = z6.discriminatedUnion("type", [
|
|
711
|
+
z6.object({
|
|
712
|
+
type: z6.literal("web_search_call"),
|
|
1643
713
|
...toolCallSchema.shape
|
|
1644
714
|
}),
|
|
1645
|
-
|
|
1646
|
-
type:
|
|
715
|
+
z6.object({
|
|
716
|
+
type: z6.literal("x_search_call"),
|
|
1647
717
|
...toolCallSchema.shape
|
|
1648
718
|
}),
|
|
1649
|
-
|
|
1650
|
-
type:
|
|
719
|
+
z6.object({
|
|
720
|
+
type: z6.literal("code_interpreter_call"),
|
|
1651
721
|
...toolCallSchema.shape
|
|
1652
722
|
}),
|
|
1653
|
-
|
|
1654
|
-
type:
|
|
723
|
+
z6.object({
|
|
724
|
+
type: z6.literal("code_execution_call"),
|
|
1655
725
|
...toolCallSchema.shape
|
|
1656
726
|
}),
|
|
1657
|
-
|
|
1658
|
-
type:
|
|
727
|
+
z6.object({
|
|
728
|
+
type: z6.literal("view_image_call"),
|
|
1659
729
|
...toolCallSchema.shape
|
|
1660
730
|
}),
|
|
1661
|
-
|
|
1662
|
-
type:
|
|
731
|
+
z6.object({
|
|
732
|
+
type: z6.literal("view_x_video_call"),
|
|
1663
733
|
...toolCallSchema.shape
|
|
1664
734
|
}),
|
|
1665
|
-
|
|
1666
|
-
type:
|
|
1667
|
-
id:
|
|
1668
|
-
status:
|
|
1669
|
-
queries:
|
|
1670
|
-
results:
|
|
1671
|
-
|
|
1672
|
-
file_id:
|
|
1673
|
-
filename:
|
|
1674
|
-
score:
|
|
1675
|
-
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()
|
|
1676
746
|
})
|
|
1677
747
|
).nullish()
|
|
1678
748
|
}),
|
|
1679
|
-
|
|
1680
|
-
type:
|
|
1681
|
-
id:
|
|
1682
|
-
status:
|
|
1683
|
-
prompt:
|
|
1684
|
-
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()
|
|
1685
755
|
}),
|
|
1686
|
-
|
|
1687
|
-
type:
|
|
756
|
+
z6.object({
|
|
757
|
+
type: z6.literal("custom_tool_call"),
|
|
1688
758
|
...toolCallSchema.shape
|
|
1689
759
|
}),
|
|
1690
|
-
|
|
1691
|
-
type:
|
|
760
|
+
z6.object({
|
|
761
|
+
type: z6.literal("mcp_call"),
|
|
1692
762
|
...mcpCallSchema.shape
|
|
1693
763
|
}),
|
|
1694
|
-
|
|
1695
|
-
type:
|
|
1696
|
-
role:
|
|
1697
|
-
content:
|
|
1698
|
-
id:
|
|
1699
|
-
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()
|
|
1700
770
|
}),
|
|
1701
|
-
|
|
1702
|
-
type:
|
|
1703
|
-
name:
|
|
1704
|
-
arguments:
|
|
1705
|
-
call_id:
|
|
1706
|
-
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()
|
|
1707
777
|
}),
|
|
1708
|
-
|
|
1709
|
-
type:
|
|
1710
|
-
id:
|
|
1711
|
-
summary:
|
|
1712
|
-
content:
|
|
1713
|
-
status:
|
|
1714
|
-
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()
|
|
1715
785
|
})
|
|
1716
786
|
]);
|
|
1717
|
-
var xaiResponsesUsageSchema =
|
|
1718
|
-
input_tokens:
|
|
1719
|
-
output_tokens:
|
|
1720
|
-
total_tokens:
|
|
1721
|
-
input_tokens_details:
|
|
1722
|
-
cached_tokens:
|
|
1723
|
-
}).catchall(
|
|
1724
|
-
output_tokens_details:
|
|
1725
|
-
reasoning_tokens:
|
|
1726
|
-
}).catchall(
|
|
1727
|
-
num_sources_used:
|
|
1728
|
-
num_server_side_tools_used:
|
|
1729
|
-
cost_in_usd_ticks:
|
|
1730
|
-
}).catchall(
|
|
1731
|
-
var xaiResponsesResponseSchema =
|
|
1732
|
-
id:
|
|
1733
|
-
created_at:
|
|
1734
|
-
model:
|
|
1735
|
-
object:
|
|
1736
|
-
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),
|
|
1737
807
|
usage: xaiResponsesUsageSchema.nullish(),
|
|
1738
|
-
status:
|
|
1739
|
-
service_tier:
|
|
808
|
+
status: z6.string(),
|
|
809
|
+
service_tier: z6.string().nullish()
|
|
1740
810
|
});
|
|
1741
|
-
var xaiResponsesChunkSchema =
|
|
1742
|
-
|
|
1743
|
-
type:
|
|
811
|
+
var xaiResponsesChunkSchema = z6.union([
|
|
812
|
+
z6.object({
|
|
813
|
+
type: z6.literal("response.created"),
|
|
1744
814
|
response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
|
|
1745
815
|
}),
|
|
1746
|
-
|
|
1747
|
-
type:
|
|
816
|
+
z6.object({
|
|
817
|
+
type: z6.literal("response.in_progress"),
|
|
1748
818
|
response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
|
|
1749
819
|
}),
|
|
1750
|
-
|
|
1751
|
-
type:
|
|
820
|
+
z6.object({
|
|
821
|
+
type: z6.literal("response.output_item.added"),
|
|
1752
822
|
item: outputItemSchema,
|
|
1753
|
-
output_index:
|
|
823
|
+
output_index: z6.number()
|
|
1754
824
|
}),
|
|
1755
|
-
|
|
1756
|
-
type:
|
|
825
|
+
z6.object({
|
|
826
|
+
type: z6.literal("response.output_item.done"),
|
|
1757
827
|
item: outputItemSchema,
|
|
1758
|
-
output_index:
|
|
828
|
+
output_index: z6.number()
|
|
1759
829
|
}),
|
|
1760
|
-
|
|
1761
|
-
type:
|
|
1762
|
-
item_id:
|
|
1763
|
-
output_index:
|
|
1764
|
-
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(),
|
|
1765
835
|
part: messageContentPartSchema
|
|
1766
836
|
}),
|
|
1767
|
-
|
|
1768
|
-
type:
|
|
1769
|
-
item_id:
|
|
1770
|
-
output_index:
|
|
1771
|
-
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(),
|
|
1772
842
|
part: messageContentPartSchema
|
|
1773
843
|
}),
|
|
1774
|
-
|
|
1775
|
-
type:
|
|
1776
|
-
item_id:
|
|
1777
|
-
output_index:
|
|
1778
|
-
content_index:
|
|
1779
|
-
delta:
|
|
1780
|
-
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()
|
|
1781
851
|
}),
|
|
1782
|
-
|
|
1783
|
-
type:
|
|
1784
|
-
item_id:
|
|
1785
|
-
output_index:
|
|
1786
|
-
content_index:
|
|
1787
|
-
text:
|
|
1788
|
-
logprobs:
|
|
1789
|
-
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()
|
|
1790
860
|
}),
|
|
1791
|
-
|
|
1792
|
-
type:
|
|
1793
|
-
item_id:
|
|
1794
|
-
output_index:
|
|
1795
|
-
content_index:
|
|
1796
|
-
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(),
|
|
1797
867
|
annotation: annotationSchema
|
|
1798
868
|
}),
|
|
1799
|
-
|
|
1800
|
-
type:
|
|
1801
|
-
item_id:
|
|
1802
|
-
output_index:
|
|
1803
|
-
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(),
|
|
1804
874
|
part: reasoningSummaryPartSchema
|
|
1805
875
|
}),
|
|
1806
|
-
|
|
1807
|
-
type:
|
|
1808
|
-
item_id:
|
|
1809
|
-
output_index:
|
|
1810
|
-
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(),
|
|
1811
881
|
part: reasoningSummaryPartSchema
|
|
1812
882
|
}),
|
|
1813
|
-
|
|
1814
|
-
type:
|
|
1815
|
-
item_id:
|
|
1816
|
-
output_index:
|
|
1817
|
-
summary_index:
|
|
1818
|
-
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()
|
|
1819
889
|
}),
|
|
1820
|
-
|
|
1821
|
-
type:
|
|
1822
|
-
item_id:
|
|
1823
|
-
output_index:
|
|
1824
|
-
summary_index:
|
|
1825
|
-
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()
|
|
1826
896
|
}),
|
|
1827
|
-
|
|
1828
|
-
type:
|
|
1829
|
-
item_id:
|
|
1830
|
-
output_index:
|
|
1831
|
-
content_index:
|
|
1832
|
-
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()
|
|
1833
903
|
}),
|
|
1834
|
-
|
|
1835
|
-
type:
|
|
1836
|
-
item_id:
|
|
1837
|
-
output_index:
|
|
1838
|
-
content_index:
|
|
1839
|
-
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()
|
|
1840
910
|
}),
|
|
1841
|
-
|
|
1842
|
-
type:
|
|
1843
|
-
item_id:
|
|
1844
|
-
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()
|
|
1845
915
|
}),
|
|
1846
|
-
|
|
1847
|
-
type:
|
|
1848
|
-
item_id:
|
|
1849
|
-
output_index:
|
|
916
|
+
z6.object({
|
|
917
|
+
type: z6.literal("response.web_search_call.searching"),
|
|
918
|
+
item_id: z6.string(),
|
|
919
|
+
output_index: z6.number()
|
|
1850
920
|
}),
|
|
1851
|
-
|
|
1852
|
-
type:
|
|
1853
|
-
item_id:
|
|
1854
|
-
output_index:
|
|
921
|
+
z6.object({
|
|
922
|
+
type: z6.literal("response.web_search_call.completed"),
|
|
923
|
+
item_id: z6.string(),
|
|
924
|
+
output_index: z6.number()
|
|
1855
925
|
}),
|
|
1856
|
-
|
|
1857
|
-
type:
|
|
1858
|
-
item_id:
|
|
1859
|
-
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()
|
|
1860
930
|
}),
|
|
1861
|
-
|
|
1862
|
-
type:
|
|
1863
|
-
item_id:
|
|
1864
|
-
output_index:
|
|
931
|
+
z6.object({
|
|
932
|
+
type: z6.literal("response.x_search_call.searching"),
|
|
933
|
+
item_id: z6.string(),
|
|
934
|
+
output_index: z6.number()
|
|
1865
935
|
}),
|
|
1866
|
-
|
|
1867
|
-
type:
|
|
1868
|
-
item_id:
|
|
1869
|
-
output_index:
|
|
936
|
+
z6.object({
|
|
937
|
+
type: z6.literal("response.x_search_call.completed"),
|
|
938
|
+
item_id: z6.string(),
|
|
939
|
+
output_index: z6.number()
|
|
1870
940
|
}),
|
|
1871
|
-
|
|
1872
|
-
type:
|
|
1873
|
-
item_id:
|
|
1874
|
-
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()
|
|
1875
945
|
}),
|
|
1876
|
-
|
|
1877
|
-
type:
|
|
1878
|
-
item_id:
|
|
1879
|
-
output_index:
|
|
946
|
+
z6.object({
|
|
947
|
+
type: z6.literal("response.file_search_call.searching"),
|
|
948
|
+
item_id: z6.string(),
|
|
949
|
+
output_index: z6.number()
|
|
1880
950
|
}),
|
|
1881
|
-
|
|
1882
|
-
type:
|
|
1883
|
-
item_id:
|
|
1884
|
-
output_index:
|
|
951
|
+
z6.object({
|
|
952
|
+
type: z6.literal("response.file_search_call.completed"),
|
|
953
|
+
item_id: z6.string(),
|
|
954
|
+
output_index: z6.number()
|
|
1885
955
|
}),
|
|
1886
|
-
|
|
1887
|
-
type:
|
|
1888
|
-
item_id:
|
|
1889
|
-
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()
|
|
1890
960
|
}),
|
|
1891
|
-
|
|
1892
|
-
type:
|
|
1893
|
-
item_id:
|
|
1894
|
-
output_index:
|
|
961
|
+
z6.object({
|
|
962
|
+
type: z6.literal("response.image_generation_call.generating"),
|
|
963
|
+
item_id: z6.string(),
|
|
964
|
+
output_index: z6.number()
|
|
1895
965
|
}),
|
|
1896
|
-
|
|
1897
|
-
type:
|
|
1898
|
-
item_id:
|
|
1899
|
-
output_index:
|
|
966
|
+
z6.object({
|
|
967
|
+
type: z6.literal("response.image_generation_call.completed"),
|
|
968
|
+
item_id: z6.string(),
|
|
969
|
+
output_index: z6.number()
|
|
1900
970
|
}),
|
|
1901
|
-
|
|
1902
|
-
type:
|
|
1903
|
-
item_id:
|
|
1904
|
-
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()
|
|
1905
975
|
}),
|
|
1906
|
-
|
|
1907
|
-
type:
|
|
1908
|
-
item_id:
|
|
1909
|
-
output_index:
|
|
976
|
+
z6.object({
|
|
977
|
+
type: z6.literal("response.code_execution_call.executing"),
|
|
978
|
+
item_id: z6.string(),
|
|
979
|
+
output_index: z6.number()
|
|
1910
980
|
}),
|
|
1911
|
-
|
|
1912
|
-
type:
|
|
1913
|
-
item_id:
|
|
1914
|
-
output_index:
|
|
981
|
+
z6.object({
|
|
982
|
+
type: z6.literal("response.code_execution_call.completed"),
|
|
983
|
+
item_id: z6.string(),
|
|
984
|
+
output_index: z6.number()
|
|
1915
985
|
}),
|
|
1916
|
-
|
|
1917
|
-
type:
|
|
1918
|
-
item_id:
|
|
1919
|
-
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()
|
|
1920
990
|
}),
|
|
1921
|
-
|
|
1922
|
-
type:
|
|
1923
|
-
item_id:
|
|
1924
|
-
output_index:
|
|
991
|
+
z6.object({
|
|
992
|
+
type: z6.literal("response.code_interpreter_call.executing"),
|
|
993
|
+
item_id: z6.string(),
|
|
994
|
+
output_index: z6.number()
|
|
1925
995
|
}),
|
|
1926
|
-
|
|
1927
|
-
type:
|
|
1928
|
-
item_id:
|
|
1929
|
-
output_index:
|
|
996
|
+
z6.object({
|
|
997
|
+
type: z6.literal("response.code_interpreter_call.interpreting"),
|
|
998
|
+
item_id: z6.string(),
|
|
999
|
+
output_index: z6.number()
|
|
1930
1000
|
}),
|
|
1931
|
-
|
|
1932
|
-
type:
|
|
1933
|
-
item_id:
|
|
1934
|
-
output_index:
|
|
1001
|
+
z6.object({
|
|
1002
|
+
type: z6.literal("response.code_interpreter_call.completed"),
|
|
1003
|
+
item_id: z6.string(),
|
|
1004
|
+
output_index: z6.number()
|
|
1935
1005
|
}),
|
|
1936
1006
|
// Code interpreter code streaming events
|
|
1937
|
-
|
|
1938
|
-
type:
|
|
1939
|
-
item_id:
|
|
1940
|
-
output_index:
|
|
1941
|
-
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()
|
|
1942
1012
|
}),
|
|
1943
|
-
|
|
1944
|
-
type:
|
|
1945
|
-
item_id:
|
|
1946
|
-
output_index:
|
|
1947
|
-
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()
|
|
1948
1018
|
}),
|
|
1949
|
-
|
|
1950
|
-
type:
|
|
1951
|
-
item_id:
|
|
1952
|
-
output_index:
|
|
1953
|
-
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()
|
|
1954
1024
|
}),
|
|
1955
|
-
|
|
1956
|
-
type:
|
|
1957
|
-
item_id:
|
|
1958
|
-
output_index:
|
|
1959
|
-
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()
|
|
1960
1030
|
}),
|
|
1961
1031
|
// Function call arguments streaming events (standard function tools)
|
|
1962
|
-
|
|
1963
|
-
type:
|
|
1964
|
-
item_id:
|
|
1965
|
-
output_index:
|
|
1966
|
-
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()
|
|
1967
1037
|
}),
|
|
1968
|
-
|
|
1969
|
-
type:
|
|
1970
|
-
item_id:
|
|
1971
|
-
output_index:
|
|
1972
|
-
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()
|
|
1973
1043
|
}),
|
|
1974
|
-
|
|
1975
|
-
type:
|
|
1976
|
-
item_id:
|
|
1977
|
-
output_index:
|
|
1044
|
+
z6.object({
|
|
1045
|
+
type: z6.literal("response.mcp_call.in_progress"),
|
|
1046
|
+
item_id: z6.string(),
|
|
1047
|
+
output_index: z6.number()
|
|
1978
1048
|
}),
|
|
1979
|
-
|
|
1980
|
-
type:
|
|
1981
|
-
item_id:
|
|
1982
|
-
output_index:
|
|
1049
|
+
z6.object({
|
|
1050
|
+
type: z6.literal("response.mcp_call.executing"),
|
|
1051
|
+
item_id: z6.string(),
|
|
1052
|
+
output_index: z6.number()
|
|
1983
1053
|
}),
|
|
1984
|
-
|
|
1985
|
-
type:
|
|
1986
|
-
item_id:
|
|
1987
|
-
output_index:
|
|
1054
|
+
z6.object({
|
|
1055
|
+
type: z6.literal("response.mcp_call.completed"),
|
|
1056
|
+
item_id: z6.string(),
|
|
1057
|
+
output_index: z6.number()
|
|
1988
1058
|
}),
|
|
1989
|
-
|
|
1990
|
-
type:
|
|
1991
|
-
item_id:
|
|
1992
|
-
output_index:
|
|
1059
|
+
z6.object({
|
|
1060
|
+
type: z6.literal("response.mcp_call.failed"),
|
|
1061
|
+
item_id: z6.string(),
|
|
1062
|
+
output_index: z6.number()
|
|
1993
1063
|
}),
|
|
1994
|
-
|
|
1995
|
-
type:
|
|
1996
|
-
item_id:
|
|
1997
|
-
output_index:
|
|
1998
|
-
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()
|
|
1999
1069
|
}),
|
|
2000
|
-
|
|
2001
|
-
type:
|
|
2002
|
-
item_id:
|
|
2003
|
-
output_index:
|
|
2004
|
-
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()
|
|
2005
1075
|
}),
|
|
2006
|
-
|
|
2007
|
-
type:
|
|
2008
|
-
item_id:
|
|
2009
|
-
output_index:
|
|
2010
|
-
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()
|
|
2011
1081
|
}),
|
|
2012
|
-
|
|
2013
|
-
type:
|
|
2014
|
-
item_id:
|
|
2015
|
-
output_index:
|
|
2016
|
-
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()
|
|
2017
1087
|
}),
|
|
2018
|
-
|
|
2019
|
-
type:
|
|
2020
|
-
response:
|
|
2021
|
-
incomplete_details:
|
|
1088
|
+
z6.object({
|
|
1089
|
+
type: z6.literal("response.incomplete"),
|
|
1090
|
+
response: z6.object({
|
|
1091
|
+
incomplete_details: z6.object({ reason: z6.string() }).nullish(),
|
|
2022
1092
|
usage: xaiResponsesUsageSchema.nullish(),
|
|
2023
|
-
service_tier:
|
|
1093
|
+
service_tier: z6.string().nullish()
|
|
2024
1094
|
})
|
|
2025
1095
|
}),
|
|
2026
|
-
|
|
2027
|
-
type:
|
|
2028
|
-
response:
|
|
2029
|
-
error:
|
|
2030
|
-
code:
|
|
2031
|
-
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()
|
|
2032
1102
|
}).nullish(),
|
|
2033
|
-
incomplete_details:
|
|
1103
|
+
incomplete_details: z6.object({ reason: z6.string() }).nullish(),
|
|
2034
1104
|
usage: xaiResponsesUsageSchema.nullish()
|
|
2035
1105
|
})
|
|
2036
1106
|
}),
|
|
2037
|
-
|
|
2038
|
-
type:
|
|
2039
|
-
code:
|
|
2040
|
-
message:
|
|
2041
|
-
param:
|
|
1107
|
+
z6.object({
|
|
1108
|
+
type: z6.literal("error"),
|
|
1109
|
+
code: z6.string().nullish(),
|
|
1110
|
+
message: z6.string(),
|
|
1111
|
+
param: z6.string().nullish()
|
|
2042
1112
|
}),
|
|
2043
|
-
|
|
2044
|
-
type:
|
|
1113
|
+
z6.object({
|
|
1114
|
+
type: z6.literal("response.done"),
|
|
2045
1115
|
response: xaiResponsesResponseSchema
|
|
2046
1116
|
}),
|
|
2047
|
-
|
|
2048
|
-
type:
|
|
1117
|
+
z6.object({
|
|
1118
|
+
type: z6.literal("response.completed"),
|
|
2049
1119
|
response: xaiResponsesResponseSchema
|
|
2050
1120
|
})
|
|
2051
1121
|
]);
|
|
2052
1122
|
|
|
2053
1123
|
// src/responses/xai-responses-language-model-options.ts
|
|
2054
|
-
import { z as
|
|
2055
|
-
var xaiLanguageModelResponsesOptions =
|
|
1124
|
+
import { z as z7 } from "zod/v4";
|
|
1125
|
+
var xaiLanguageModelResponsesOptions = z7.object({
|
|
2056
1126
|
/**
|
|
2057
1127
|
* Constrains how hard a reasoning model thinks before responding.
|
|
2058
1128
|
* Possible values are `none` (disables reasoning entirely; supported by
|
|
@@ -2062,32 +1132,32 @@ var xaiLanguageModelResponsesOptions = z9.object({
|
|
|
2062
1132
|
*
|
|
2063
1133
|
* @see https://docs.x.ai/docs/guides/reasoning
|
|
2064
1134
|
*/
|
|
2065
|
-
reasoningEffort:
|
|
2066
|
-
reasoningSummary:
|
|
2067
|
-
logprobs:
|
|
2068
|
-
topLogprobs:
|
|
2069
|
-
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(),
|
|
2070
1140
|
/**
|
|
2071
1141
|
* Whether to store the input message(s) and model response for later retrieval.
|
|
2072
1142
|
* Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
|
|
2073
1143
|
* otherwise the API will return an error.
|
|
2074
1144
|
* @default true
|
|
2075
1145
|
*/
|
|
2076
|
-
store:
|
|
1146
|
+
store: z7.boolean().optional(),
|
|
2077
1147
|
/**
|
|
2078
1148
|
* The ID of the previous response from the model.
|
|
2079
1149
|
*/
|
|
2080
|
-
previousResponseId:
|
|
1150
|
+
previousResponseId: z7.string().optional(),
|
|
2081
1151
|
/**
|
|
2082
1152
|
* Specify additional output data to include in the model response.
|
|
2083
1153
|
* Example values: 'file_search_call.results'.
|
|
2084
1154
|
*/
|
|
2085
|
-
include:
|
|
1155
|
+
include: z7.array(z7.enum(["file_search_call.results"])).nullish()
|
|
2086
1156
|
});
|
|
2087
1157
|
|
|
2088
1158
|
// src/responses/xai-responses-prepare-tools.ts
|
|
2089
1159
|
import {
|
|
2090
|
-
UnsupportedFunctionalityError as
|
|
1160
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
2091
1161
|
} from "@ai-sdk/provider";
|
|
2092
1162
|
import { validateTypes } from "@ai-sdk/provider-utils";
|
|
2093
1163
|
|
|
@@ -2097,25 +1167,25 @@ import {
|
|
|
2097
1167
|
lazySchema as lazySchema2,
|
|
2098
1168
|
zodSchema as zodSchema2
|
|
2099
1169
|
} from "@ai-sdk/provider-utils";
|
|
2100
|
-
import { z as
|
|
1170
|
+
import { z as z8 } from "zod/v4";
|
|
2101
1171
|
var fileSearchArgsSchema = lazySchema2(
|
|
2102
1172
|
() => zodSchema2(
|
|
2103
|
-
|
|
2104
|
-
vectorStoreIds:
|
|
2105
|
-
maxNumResults:
|
|
1173
|
+
z8.object({
|
|
1174
|
+
vectorStoreIds: z8.array(z8.string()),
|
|
1175
|
+
maxNumResults: z8.number().optional()
|
|
2106
1176
|
})
|
|
2107
1177
|
)
|
|
2108
1178
|
);
|
|
2109
1179
|
var fileSearchOutputSchema = lazySchema2(
|
|
2110
1180
|
() => zodSchema2(
|
|
2111
|
-
|
|
2112
|
-
queries:
|
|
2113
|
-
results:
|
|
2114
|
-
|
|
2115
|
-
fileId:
|
|
2116
|
-
filename:
|
|
2117
|
-
score:
|
|
2118
|
-
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()
|
|
2119
1189
|
})
|
|
2120
1190
|
).nullable()
|
|
2121
1191
|
})
|
|
@@ -2123,7 +1193,7 @@ var fileSearchOutputSchema = lazySchema2(
|
|
|
2123
1193
|
);
|
|
2124
1194
|
var fileSearchToolFactory = createProviderExecutedToolFactory({
|
|
2125
1195
|
id: "xai.file_search",
|
|
2126
|
-
inputSchema: lazySchema2(() => zodSchema2(
|
|
1196
|
+
inputSchema: lazySchema2(() => zodSchema2(z8.object({}))),
|
|
2127
1197
|
outputSchema: fileSearchOutputSchema
|
|
2128
1198
|
});
|
|
2129
1199
|
var fileSearch = (args) => fileSearchToolFactory(args);
|
|
@@ -2134,20 +1204,20 @@ import {
|
|
|
2134
1204
|
lazySchema as lazySchema3,
|
|
2135
1205
|
zodSchema as zodSchema3
|
|
2136
1206
|
} from "@ai-sdk/provider-utils";
|
|
2137
|
-
import { z as
|
|
1207
|
+
import { z as z9 } from "zod/v4";
|
|
2138
1208
|
var imageGenerationArgsSchema = lazySchema3(
|
|
2139
1209
|
() => zodSchema3(
|
|
2140
|
-
|
|
2141
|
-
action:
|
|
1210
|
+
z9.object({
|
|
1211
|
+
action: z9.enum(["auto", "generate", "edit"]).optional()
|
|
2142
1212
|
})
|
|
2143
1213
|
)
|
|
2144
1214
|
);
|
|
2145
|
-
var imageGenerationInputSchema = lazySchema3(() => zodSchema3(
|
|
1215
|
+
var imageGenerationInputSchema = lazySchema3(() => zodSchema3(z9.object({})));
|
|
2146
1216
|
var imageGenerationOutputSchema = lazySchema3(
|
|
2147
1217
|
() => zodSchema3(
|
|
2148
|
-
|
|
2149
|
-
result:
|
|
2150
|
-
prompt:
|
|
1218
|
+
z9.object({
|
|
1219
|
+
result: z9.string(),
|
|
1220
|
+
prompt: z9.string().optional()
|
|
2151
1221
|
})
|
|
2152
1222
|
)
|
|
2153
1223
|
);
|
|
@@ -2164,31 +1234,31 @@ import {
|
|
|
2164
1234
|
lazySchema as lazySchema4,
|
|
2165
1235
|
zodSchema as zodSchema4
|
|
2166
1236
|
} from "@ai-sdk/provider-utils";
|
|
2167
|
-
import { z as
|
|
1237
|
+
import { z as z10 } from "zod/v4";
|
|
2168
1238
|
var mcpServerArgsSchema = lazySchema4(
|
|
2169
1239
|
() => zodSchema4(
|
|
2170
|
-
|
|
2171
|
-
serverUrl:
|
|
2172
|
-
serverLabel:
|
|
2173
|
-
serverDescription:
|
|
2174
|
-
allowedTools:
|
|
2175
|
-
headers:
|
|
2176
|
-
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")
|
|
2177
1247
|
})
|
|
2178
1248
|
)
|
|
2179
1249
|
);
|
|
2180
1250
|
var mcpServerOutputSchema = lazySchema4(
|
|
2181
1251
|
() => zodSchema4(
|
|
2182
|
-
|
|
2183
|
-
name:
|
|
2184
|
-
arguments:
|
|
2185
|
-
result:
|
|
1252
|
+
z10.object({
|
|
1253
|
+
name: z10.string(),
|
|
1254
|
+
arguments: z10.string(),
|
|
1255
|
+
result: z10.unknown()
|
|
2186
1256
|
})
|
|
2187
1257
|
)
|
|
2188
1258
|
);
|
|
2189
1259
|
var mcpServerToolFactory = createProviderExecutedToolFactory3({
|
|
2190
1260
|
id: "xai.mcp",
|
|
2191
|
-
inputSchema: lazySchema4(() => zodSchema4(
|
|
1261
|
+
inputSchema: lazySchema4(() => zodSchema4(z10.object({}))),
|
|
2192
1262
|
outputSchema: mcpServerOutputSchema
|
|
2193
1263
|
});
|
|
2194
1264
|
var mcpServer = (args) => mcpServerToolFactory(args);
|
|
@@ -2199,43 +1269,43 @@ import {
|
|
|
2199
1269
|
lazySchema as lazySchema5,
|
|
2200
1270
|
zodSchema as zodSchema5
|
|
2201
1271
|
} from "@ai-sdk/provider-utils";
|
|
2202
|
-
import { z as
|
|
1272
|
+
import { z as z11 } from "zod/v4";
|
|
2203
1273
|
var webSearchArgsSchema = lazySchema5(
|
|
2204
1274
|
() => zodSchema5(
|
|
2205
|
-
|
|
2206
|
-
allowedDomains:
|
|
2207
|
-
excludedDomains:
|
|
2208
|
-
enableImageSearch:
|
|
2209
|
-
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()
|
|
2210
1280
|
})
|
|
2211
1281
|
)
|
|
2212
1282
|
);
|
|
2213
1283
|
var webSearchOutputSchema = lazySchema5(
|
|
2214
1284
|
() => zodSchema5(
|
|
2215
|
-
|
|
2216
|
-
action:
|
|
2217
|
-
|
|
2218
|
-
type:
|
|
2219
|
-
query:
|
|
2220
|
-
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()
|
|
2221
1291
|
}),
|
|
2222
|
-
|
|
2223
|
-
type:
|
|
2224
|
-
url:
|
|
1292
|
+
z11.object({
|
|
1293
|
+
type: z11.literal("openPage"),
|
|
1294
|
+
url: z11.string().nullish()
|
|
2225
1295
|
}),
|
|
2226
|
-
|
|
2227
|
-
type:
|
|
2228
|
-
url:
|
|
2229
|
-
pattern:
|
|
1296
|
+
z11.object({
|
|
1297
|
+
type: z11.literal("findInPage"),
|
|
1298
|
+
url: z11.string().nullish(),
|
|
1299
|
+
pattern: z11.string().nullish()
|
|
2230
1300
|
})
|
|
2231
1301
|
]).optional(),
|
|
2232
|
-
sources:
|
|
1302
|
+
sources: z11.array(z11.object({ type: z11.literal("url"), url: z11.string() })).optional()
|
|
2233
1303
|
})
|
|
2234
1304
|
)
|
|
2235
1305
|
);
|
|
2236
1306
|
var webSearchToolFactory = createProviderExecutedToolFactory4({
|
|
2237
1307
|
id: "xai.web_search",
|
|
2238
|
-
inputSchema: lazySchema5(() => zodSchema5(
|
|
1308
|
+
inputSchema: lazySchema5(() => zodSchema5(z11.object({}))),
|
|
2239
1309
|
outputSchema: webSearchOutputSchema
|
|
2240
1310
|
});
|
|
2241
1311
|
var webSearch = (args = {}) => webSearchToolFactory(args);
|
|
@@ -2246,29 +1316,29 @@ import {
|
|
|
2246
1316
|
lazySchema as lazySchema6,
|
|
2247
1317
|
zodSchema as zodSchema6
|
|
2248
1318
|
} from "@ai-sdk/provider-utils";
|
|
2249
|
-
import { z as
|
|
1319
|
+
import { z as z12 } from "zod/v4";
|
|
2250
1320
|
var xSearchArgsSchema = lazySchema6(
|
|
2251
1321
|
() => zodSchema6(
|
|
2252
|
-
|
|
2253
|
-
allowedXHandles:
|
|
2254
|
-
excludedXHandles:
|
|
2255
|
-
fromDate:
|
|
2256
|
-
toDate:
|
|
2257
|
-
enableImageUnderstanding:
|
|
2258
|
-
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()
|
|
2259
1329
|
})
|
|
2260
1330
|
)
|
|
2261
1331
|
);
|
|
2262
1332
|
var xSearchOutputSchema = lazySchema6(
|
|
2263
1333
|
() => zodSchema6(
|
|
2264
|
-
|
|
2265
|
-
query:
|
|
2266
|
-
posts:
|
|
2267
|
-
|
|
2268
|
-
author:
|
|
2269
|
-
text:
|
|
2270
|
-
url:
|
|
2271
|
-
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()
|
|
2272
1342
|
})
|
|
2273
1343
|
)
|
|
2274
1344
|
})
|
|
@@ -2276,7 +1346,7 @@ var xSearchOutputSchema = lazySchema6(
|
|
|
2276
1346
|
);
|
|
2277
1347
|
var xSearchToolFactory = createProviderExecutedToolFactory5({
|
|
2278
1348
|
id: "xai.x_search",
|
|
2279
|
-
inputSchema: lazySchema6(() => zodSchema6(
|
|
1349
|
+
inputSchema: lazySchema6(() => zodSchema6(z12.object({}))),
|
|
2280
1350
|
outputSchema: xSearchOutputSchema
|
|
2281
1351
|
});
|
|
2282
1352
|
var xSearch = (args = {}) => xSearchToolFactory(args);
|
|
@@ -2436,7 +1506,7 @@ async function prepareResponsesTools({
|
|
|
2436
1506
|
}
|
|
2437
1507
|
default: {
|
|
2438
1508
|
const _exhaustiveCheck = type;
|
|
2439
|
-
throw new
|
|
1509
|
+
throw new UnsupportedFunctionalityError2({
|
|
2440
1510
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
2441
1511
|
});
|
|
2442
1512
|
}
|
|
@@ -2517,13 +1587,13 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2517
1587
|
this.modelId = modelId;
|
|
2518
1588
|
this.config = config;
|
|
2519
1589
|
}
|
|
2520
|
-
static [
|
|
2521
|
-
return
|
|
1590
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
1591
|
+
return serializeModelOptions2({
|
|
2522
1592
|
modelId: model.modelId,
|
|
2523
1593
|
config: model.config
|
|
2524
1594
|
});
|
|
2525
1595
|
}
|
|
2526
|
-
static [
|
|
1596
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
2527
1597
|
return new _XaiResponsesLanguageModel(options.modelId, options.config);
|
|
2528
1598
|
}
|
|
2529
1599
|
get provider() {
|
|
@@ -2550,7 +1620,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2550
1620
|
}) {
|
|
2551
1621
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2552
1622
|
const warnings = [];
|
|
2553
|
-
const options = (_a = await
|
|
1623
|
+
const options = (_a = await parseProviderOptions3({
|
|
2554
1624
|
provider: "xai",
|
|
2555
1625
|
providerOptions,
|
|
2556
1626
|
schema: xaiLanguageModelResponsesOptions
|
|
@@ -2608,7 +1678,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2608
1678
|
}
|
|
2609
1679
|
}
|
|
2610
1680
|
let resolvedReasoningEffort = options.reasoningEffort;
|
|
2611
|
-
if (resolvedReasoningEffort == null &&
|
|
1681
|
+
if (resolvedReasoningEffort == null && isCustomReasoning(reasoning)) {
|
|
2612
1682
|
if (!supportsReasoningEffort(modelId)) {
|
|
2613
1683
|
warnings.push({
|
|
2614
1684
|
type: "unsupported",
|
|
@@ -2618,7 +1688,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2618
1688
|
} else if (reasoning === "none") {
|
|
2619
1689
|
resolvedReasoningEffort = "none";
|
|
2620
1690
|
} else {
|
|
2621
|
-
resolvedReasoningEffort =
|
|
1691
|
+
resolvedReasoningEffort = mapReasoningToProviderEffort({
|
|
2622
1692
|
reasoning,
|
|
2623
1693
|
effortMap: {
|
|
2624
1694
|
minimal: "low",
|
|
@@ -2713,12 +1783,12 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2713
1783
|
responseHeaders,
|
|
2714
1784
|
value: response,
|
|
2715
1785
|
rawValue: rawResponse
|
|
2716
|
-
} = await
|
|
1786
|
+
} = await postJsonToApi2({
|
|
2717
1787
|
url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
|
|
2718
|
-
headers:
|
|
1788
|
+
headers: combineHeaders2((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
2719
1789
|
body,
|
|
2720
1790
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2721
|
-
successfulResponseHandler:
|
|
1791
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
2722
1792
|
xaiResponsesResponseSchema
|
|
2723
1793
|
),
|
|
2724
1794
|
abortSignal: options.abortSignal,
|
|
@@ -2931,12 +2001,12 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2931
2001
|
...args,
|
|
2932
2002
|
stream: true
|
|
2933
2003
|
};
|
|
2934
|
-
const { responseHeaders, value: response } = await
|
|
2004
|
+
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
2935
2005
|
url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
|
|
2936
|
-
headers:
|
|
2006
|
+
headers: combineHeaders2((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
2937
2007
|
body,
|
|
2938
2008
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2939
|
-
successfulResponseHandler:
|
|
2009
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
2940
2010
|
xaiResponsesChunkSchema
|
|
2941
2011
|
),
|
|
2942
2012
|
abortSignal: options.abortSignal,
|
|
@@ -3505,13 +2575,13 @@ var xaiBatchName = "ai-sdk-text-batch";
|
|
|
3505
2575
|
var xaiBatchResultsPageSize = 1e3;
|
|
3506
2576
|
var xaiBatchProviderOptionsSchema = lazySchema7(
|
|
3507
2577
|
() => zodSchema7(
|
|
3508
|
-
|
|
2578
|
+
z13.object({
|
|
3509
2579
|
/**
|
|
3510
2580
|
* TTL in seconds for the uploaded batch input file, measured from
|
|
3511
2581
|
* upload time. xAI accepts integers between 3600 (1 hour) and
|
|
3512
2582
|
* 2592000 (30 days) inclusive. Without it the file has no expiry.
|
|
3513
2583
|
*/
|
|
3514
|
-
inputFileExpiresAfter:
|
|
2584
|
+
inputFileExpiresAfter: z13.number().int().min(3600).max(2592e3).optional()
|
|
3515
2585
|
})
|
|
3516
2586
|
)
|
|
3517
2587
|
);
|
|
@@ -3519,70 +2589,108 @@ function assertSupportedBatchRequests(requests) {
|
|
|
3519
2589
|
for (const request of requests) {
|
|
3520
2590
|
const requestType = request.type;
|
|
3521
2591
|
if (requestType !== "text" && requestType !== "image") {
|
|
3522
|
-
throw new
|
|
2592
|
+
throw new UnsupportedFunctionalityError3({
|
|
3523
2593
|
functionality: `batch request type: ${requestType}`,
|
|
3524
2594
|
message: `The xAI Batch API does not support batch requests with type "${requestType}".`
|
|
3525
2595
|
});
|
|
3526
2596
|
}
|
|
3527
2597
|
}
|
|
3528
2598
|
}
|
|
3529
|
-
var xaiBatchImageResponseSchema =
|
|
3530
|
-
data:
|
|
3531
|
-
|
|
3532
|
-
url:
|
|
3533
|
-
b64_json:
|
|
3534
|
-
revised_prompt:
|
|
3535
|
-
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()
|
|
3536
2606
|
})
|
|
3537
2607
|
),
|
|
3538
|
-
usage:
|
|
2608
|
+
usage: z13.object({ cost_in_usd_ticks: z13.number().nullish() }).nullish()
|
|
3539
2609
|
});
|
|
3540
|
-
var xaiBatchResponseZodSchema = () =>
|
|
3541
|
-
batch_id:
|
|
3542
|
-
name:
|
|
3543
|
-
create_time:
|
|
3544
|
-
expire_time:
|
|
3545
|
-
cancel_time:
|
|
3546
|
-
cancel_by_xai_message:
|
|
3547
|
-
state:
|
|
3548
|
-
num_requests:
|
|
3549
|
-
num_pending:
|
|
3550
|
-
num_success:
|
|
3551
|
-
num_error:
|
|
3552
|
-
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()
|
|
3553
2623
|
}).nullish()
|
|
3554
2624
|
});
|
|
3555
2625
|
var xaiBatchResponseSchema = lazySchema7(
|
|
3556
2626
|
() => zodSchema7(xaiBatchResponseZodSchema())
|
|
3557
2627
|
);
|
|
3558
|
-
var xaiBatchErrorSchema =
|
|
3559
|
-
code:
|
|
3560
|
-
message:
|
|
2628
|
+
var xaiBatchErrorSchema = z13.object({
|
|
2629
|
+
code: z13.union([z13.string(), z13.number()]).nullish(),
|
|
2630
|
+
message: z13.string().nullish()
|
|
3561
2631
|
});
|
|
3562
|
-
var xaiBatchResultSchema =
|
|
3563
|
-
batch_request_id:
|
|
3564
|
-
batch_result:
|
|
3565
|
-
response:
|
|
3566
|
-
chat_get_completion:
|
|
3567
|
-
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()
|
|
3568
2638
|
}).nullish(),
|
|
3569
2639
|
error: xaiBatchErrorSchema.nullish()
|
|
3570
2640
|
}).nullish(),
|
|
3571
|
-
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()
|
|
3572
2680
|
});
|
|
3573
2681
|
var xaiBatchResultsPageSchema = lazySchema7(
|
|
3574
2682
|
() => zodSchema7(
|
|
3575
|
-
|
|
3576
|
-
results:
|
|
3577
|
-
pagination_token:
|
|
2683
|
+
z13.object({
|
|
2684
|
+
results: z13.array(xaiBatchResultSchema),
|
|
2685
|
+
pagination_token: z13.string().nullish()
|
|
3578
2686
|
})
|
|
3579
2687
|
)
|
|
3580
2688
|
);
|
|
3581
2689
|
var xaiBatchListResponseSchema = lazySchema7(
|
|
3582
2690
|
() => zodSchema7(
|
|
3583
|
-
|
|
3584
|
-
batches:
|
|
3585
|
-
pagination_token:
|
|
2691
|
+
z13.object({
|
|
2692
|
+
batches: z13.array(xaiBatchResponseZodSchema()),
|
|
2693
|
+
pagination_token: z13.string().nullish()
|
|
3586
2694
|
})
|
|
3587
2695
|
)
|
|
3588
2696
|
);
|
|
@@ -3606,7 +2714,7 @@ var XaiBatch = class {
|
|
|
3606
2714
|
}
|
|
3607
2715
|
}
|
|
3608
2716
|
];
|
|
3609
|
-
const batchOptions = await
|
|
2717
|
+
const batchOptions = await parseProviderOptions4({
|
|
3610
2718
|
provider: "xai",
|
|
3611
2719
|
providerOptions: options.providerOptions,
|
|
3612
2720
|
schema: xaiBatchProviderOptionsSchema
|
|
@@ -3637,7 +2745,7 @@ var XaiBatch = class {
|
|
|
3637
2745
|
);
|
|
3638
2746
|
}
|
|
3639
2747
|
formData.append("file", file, filename);
|
|
3640
|
-
const headers =
|
|
2748
|
+
const headers = combineHeaders3(
|
|
3641
2749
|
(_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a),
|
|
3642
2750
|
options.headers
|
|
3643
2751
|
);
|
|
@@ -3646,13 +2754,13 @@ var XaiBatch = class {
|
|
|
3646
2754
|
headers,
|
|
3647
2755
|
formData,
|
|
3648
2756
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3649
|
-
successfulResponseHandler:
|
|
2757
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3650
2758
|
xaiFilesResponseSchema
|
|
3651
2759
|
),
|
|
3652
2760
|
abortSignal: options.abortSignal,
|
|
3653
2761
|
fetch: this.options.config.fetch
|
|
3654
2762
|
});
|
|
3655
|
-
const { value: batch } = await
|
|
2763
|
+
const { value: batch } = await postJsonToApi3({
|
|
3656
2764
|
url: this.getUrl("/batches"),
|
|
3657
2765
|
headers,
|
|
3658
2766
|
body: {
|
|
@@ -3660,7 +2768,7 @@ var XaiBatch = class {
|
|
|
3660
2768
|
input_file_id: uploadedFile.id
|
|
3661
2769
|
},
|
|
3662
2770
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3663
|
-
successfulResponseHandler:
|
|
2771
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3664
2772
|
xaiBatchResponseSchema
|
|
3665
2773
|
),
|
|
3666
2774
|
abortSignal: options.abortSignal,
|
|
@@ -3687,14 +2795,14 @@ var XaiBatch = class {
|
|
|
3687
2795
|
}
|
|
3688
2796
|
async doCancelBatch(options) {
|
|
3689
2797
|
var _a, _b;
|
|
3690
|
-
await
|
|
2798
|
+
await postJsonToApi3({
|
|
3691
2799
|
url: this.getUrl(
|
|
3692
2800
|
`/batches/${encodeURIComponent(options.batchId)}:cancel`
|
|
3693
2801
|
),
|
|
3694
|
-
headers:
|
|
2802
|
+
headers: combineHeaders3((_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
3695
2803
|
body: {},
|
|
3696
2804
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3697
|
-
successfulResponseHandler:
|
|
2805
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3698
2806
|
xaiBatchResponseSchema
|
|
3699
2807
|
),
|
|
3700
2808
|
abortSignal: options.abortSignal,
|
|
@@ -3713,9 +2821,9 @@ var XaiBatch = class {
|
|
|
3713
2821
|
}
|
|
3714
2822
|
const { value: page } = await getFromApi2({
|
|
3715
2823
|
url: url.toString(),
|
|
3716
|
-
headers:
|
|
2824
|
+
headers: combineHeaders3((_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
3717
2825
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3718
|
-
successfulResponseHandler:
|
|
2826
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3719
2827
|
xaiBatchListResponseSchema
|
|
3720
2828
|
),
|
|
3721
2829
|
abortSignal: options.abortSignal,
|
|
@@ -3746,9 +2854,9 @@ var XaiBatch = class {
|
|
|
3746
2854
|
var _a, _b;
|
|
3747
2855
|
const { value: batch } = await getFromApi2({
|
|
3748
2856
|
url: this.getUrl(`/batches/${encodeURIComponent(options.batchId)}`),
|
|
3749
|
-
headers:
|
|
2857
|
+
headers: combineHeaders3((_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
3750
2858
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3751
|
-
successfulResponseHandler:
|
|
2859
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3752
2860
|
xaiBatchResponseSchema
|
|
3753
2861
|
),
|
|
3754
2862
|
abortSignal: options.abortSignal,
|
|
@@ -3771,12 +2879,12 @@ var XaiBatch = class {
|
|
|
3771
2879
|
url: this.getUrl(
|
|
3772
2880
|
`/batches/${encodeURIComponent(options.batchId)}/results?${query}`
|
|
3773
2881
|
),
|
|
3774
|
-
headers:
|
|
2882
|
+
headers: combineHeaders3(
|
|
3775
2883
|
(_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a),
|
|
3776
2884
|
options.headers
|
|
3777
2885
|
),
|
|
3778
2886
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3779
|
-
successfulResponseHandler:
|
|
2887
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
3780
2888
|
xaiBatchResultsPageSchema
|
|
3781
2889
|
),
|
|
3782
2890
|
abortSignal: options.abortSignal,
|
|
@@ -3805,12 +2913,12 @@ var XaiBatch = class {
|
|
|
3805
2913
|
if ((response == null ? void 0 : response.chat_get_completion) != null) {
|
|
3806
2914
|
const validation = await safeValidateTypes({
|
|
3807
2915
|
value: response.chat_get_completion,
|
|
3808
|
-
schema:
|
|
2916
|
+
schema: zodSchema7(xaiBatchTextResponseSchema)
|
|
3809
2917
|
});
|
|
3810
2918
|
if (!validation.success) {
|
|
3811
2919
|
return invalidXaiBatchResult(result.batch_request_id);
|
|
3812
2920
|
}
|
|
3813
|
-
const conversion =
|
|
2921
|
+
const conversion = convertXaiBatchTextResponse(validation.value);
|
|
3814
2922
|
return conversion.success ? {
|
|
3815
2923
|
type: "text",
|
|
3816
2924
|
id: result.batch_request_id,
|
|
@@ -3873,7 +2981,7 @@ var XaiBatch = class {
|
|
|
3873
2981
|
}
|
|
3874
2982
|
if (seed != null) warnings.push({ type: "unsupported", feature: "seed" });
|
|
3875
2983
|
if (mask != null) warnings.push({ type: "unsupported", feature: "mask" });
|
|
3876
|
-
const xaiOptions = await
|
|
2984
|
+
const xaiOptions = await parseProviderOptions4({
|
|
3877
2985
|
provider: "xai",
|
|
3878
2986
|
providerOptions,
|
|
3879
2987
|
schema: xaiImageModelOptions
|
|
@@ -4020,7 +3128,7 @@ function invalidXaiImageBatchResult(id) {
|
|
|
4020
3128
|
}
|
|
4021
3129
|
};
|
|
4022
3130
|
}
|
|
4023
|
-
function
|
|
3131
|
+
function convertXaiBatchTextResponse(response) {
|
|
4024
3132
|
var _a, _b, _c, _d, _e, _f;
|
|
4025
3133
|
if (response.error != null) {
|
|
4026
3134
|
return {
|
|
@@ -4102,7 +3210,7 @@ function convertXaiChatBatchResponse(response) {
|
|
|
4102
3210
|
unified: mapXaiFinishReason(lastAssistantChoice == null ? void 0 : lastAssistantChoice.finish_reason),
|
|
4103
3211
|
raw: (_d = lastAssistantChoice == null ? void 0 : lastAssistantChoice.finish_reason) != null ? _d : void 0
|
|
4104
3212
|
},
|
|
4105
|
-
usage: response.usage ?
|
|
3213
|
+
usage: response.usage ? convertXaiBatchTextUsage(response.usage) : createNullLanguageModelUsage(),
|
|
4106
3214
|
response: getResponseMetadata(response),
|
|
4107
3215
|
warnings: [],
|
|
4108
3216
|
...(((_e = response.usage) == null ? void 0 : _e.cost_in_usd_ticks) != null || response.service_tier != null) && {
|
|
@@ -4116,6 +3224,26 @@ function convertXaiChatBatchResponse(response) {
|
|
|
4116
3224
|
}
|
|
4117
3225
|
};
|
|
4118
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
|
+
}
|
|
4119
3247
|
|
|
4120
3248
|
// src/realtime/xai-realtime-event-mapper.ts
|
|
4121
3249
|
function parseXaiRealtimeServerEvent(raw) {
|
|
@@ -4488,43 +3616,43 @@ var XaiRealtimeModel = class {
|
|
|
4488
3616
|
|
|
4489
3617
|
// src/tool/code-execution.ts
|
|
4490
3618
|
import { createProviderExecutedToolFactory as createProviderExecutedToolFactory6 } from "@ai-sdk/provider-utils";
|
|
4491
|
-
import { z as
|
|
4492
|
-
var codeExecutionOutputSchema =
|
|
4493
|
-
output:
|
|
4494
|
-
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")
|
|
4495
3623
|
});
|
|
4496
3624
|
var codeExecutionToolFactory = createProviderExecutedToolFactory6({
|
|
4497
3625
|
id: "xai.code_execution",
|
|
4498
|
-
inputSchema:
|
|
3626
|
+
inputSchema: z14.object({}).describe("no input parameters"),
|
|
4499
3627
|
outputSchema: codeExecutionOutputSchema
|
|
4500
3628
|
});
|
|
4501
3629
|
var codeExecution = (args = {}) => codeExecutionToolFactory(args);
|
|
4502
3630
|
|
|
4503
3631
|
// src/tool/view-image.ts
|
|
4504
3632
|
import { createProviderExecutedToolFactory as createProviderExecutedToolFactory7 } from "@ai-sdk/provider-utils";
|
|
4505
|
-
import { z as
|
|
4506
|
-
var viewImageOutputSchema =
|
|
4507
|
-
description:
|
|
4508
|
-
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")
|
|
4509
3637
|
});
|
|
4510
3638
|
var viewImageToolFactory = createProviderExecutedToolFactory7({
|
|
4511
3639
|
id: "xai.view_image",
|
|
4512
|
-
inputSchema:
|
|
3640
|
+
inputSchema: z15.object({}).describe("no input parameters"),
|
|
4513
3641
|
outputSchema: viewImageOutputSchema
|
|
4514
3642
|
});
|
|
4515
3643
|
var viewImage = (args = {}) => viewImageToolFactory(args);
|
|
4516
3644
|
|
|
4517
3645
|
// src/tool/view-x-video.ts
|
|
4518
3646
|
import { createProviderExecutedToolFactory as createProviderExecutedToolFactory8 } from "@ai-sdk/provider-utils";
|
|
4519
|
-
import { z as
|
|
4520
|
-
var viewXVideoOutputSchema =
|
|
4521
|
-
transcript:
|
|
4522
|
-
description:
|
|
4523
|
-
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")
|
|
4524
3652
|
});
|
|
4525
3653
|
var viewXVideoToolFactory = createProviderExecutedToolFactory8({
|
|
4526
3654
|
id: "xai.view_x_video",
|
|
4527
|
-
inputSchema:
|
|
3655
|
+
inputSchema: z16.object({}).describe("no input parameters"),
|
|
4528
3656
|
outputSchema: viewXVideoOutputSchema
|
|
4529
3657
|
});
|
|
4530
3658
|
var viewXVideo = (args = {}) => viewXVideoToolFactory(args);
|
|
@@ -4542,20 +3670,20 @@ var xaiTools = {
|
|
|
4542
3670
|
};
|
|
4543
3671
|
|
|
4544
3672
|
// src/version.ts
|
|
4545
|
-
var VERSION = true ? "
|
|
3673
|
+
var VERSION = true ? "5.0.0" : "0.0.0-test";
|
|
4546
3674
|
|
|
4547
3675
|
// src/files/xai-files.ts
|
|
4548
3676
|
import {
|
|
4549
3677
|
InvalidArgumentError as InvalidArgumentError2
|
|
4550
3678
|
} from "@ai-sdk/provider";
|
|
4551
3679
|
import {
|
|
4552
|
-
combineHeaders as
|
|
3680
|
+
combineHeaders as combineHeaders4,
|
|
4553
3681
|
convertInlineFileDataToUint8Array,
|
|
4554
3682
|
createBinaryStreamResponseHandler,
|
|
4555
|
-
createJsonResponseHandler as
|
|
3683
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
4556
3684
|
deleteFromApi,
|
|
4557
3685
|
getFromApi as getFromApi3,
|
|
4558
|
-
parseProviderOptions as
|
|
3686
|
+
parseProviderOptions as parseProviderOptions5,
|
|
4559
3687
|
postFormDataToApi as postFormDataToApi2,
|
|
4560
3688
|
postMultipartStreamToApi
|
|
4561
3689
|
} from "@ai-sdk/provider-utils";
|
|
@@ -4565,18 +3693,18 @@ import {
|
|
|
4565
3693
|
lazySchema as lazySchema8,
|
|
4566
3694
|
zodSchema as zodSchema8
|
|
4567
3695
|
} from "@ai-sdk/provider-utils";
|
|
4568
|
-
import { z as
|
|
3696
|
+
import { z as z17 } from "zod/v4";
|
|
4569
3697
|
var xaiFilesOptionsSchema = lazySchema8(
|
|
4570
3698
|
() => zodSchema8(
|
|
4571
|
-
|
|
4572
|
-
teamId:
|
|
4573
|
-
filePath:
|
|
3699
|
+
z17.looseObject({
|
|
3700
|
+
teamId: z17.string().optional(),
|
|
3701
|
+
filePath: z17.string().optional(),
|
|
4574
3702
|
/**
|
|
4575
3703
|
* TTL in seconds measured from upload time; xAI accepts integers
|
|
4576
3704
|
* between 3600 (1 hour) and 2592000 (30 days) inclusive.
|
|
4577
3705
|
* Omit to keep the file until it is deleted.
|
|
4578
3706
|
*/
|
|
4579
|
-
expiresAfter:
|
|
3707
|
+
expiresAfter: z17.number().int().min(3600).max(2592e3).optional()
|
|
4580
3708
|
})
|
|
4581
3709
|
)
|
|
4582
3710
|
);
|
|
@@ -4605,7 +3733,7 @@ var XaiFiles = class {
|
|
|
4605
3733
|
return fileId;
|
|
4606
3734
|
}
|
|
4607
3735
|
getHeaders(headers) {
|
|
4608
|
-
return
|
|
3736
|
+
return combineHeaders4(this.config.headers(), headers);
|
|
4609
3737
|
}
|
|
4610
3738
|
async uploadFile({
|
|
4611
3739
|
data,
|
|
@@ -4618,7 +3746,7 @@ var XaiFiles = class {
|
|
|
4618
3746
|
var _a, _b;
|
|
4619
3747
|
let xaiOptions;
|
|
4620
3748
|
try {
|
|
4621
|
-
xaiOptions = await
|
|
3749
|
+
xaiOptions = await parseProviderOptions5({
|
|
4622
3750
|
provider: "xai",
|
|
4623
3751
|
providerOptions,
|
|
4624
3752
|
schema: xaiFilesOptionsSchema
|
|
@@ -4661,7 +3789,7 @@ var XaiFiles = class {
|
|
|
4661
3789
|
headers: requestHeaders,
|
|
4662
3790
|
parts,
|
|
4663
3791
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4664
|
-
successfulResponseHandler:
|
|
3792
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
4665
3793
|
xaiFilesResponseSchema
|
|
4666
3794
|
),
|
|
4667
3795
|
abortSignal,
|
|
@@ -4689,7 +3817,7 @@ var XaiFiles = class {
|
|
|
4689
3817
|
headers: requestHeaders,
|
|
4690
3818
|
formData,
|
|
4691
3819
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4692
|
-
successfulResponseHandler:
|
|
3820
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
4693
3821
|
xaiFilesResponseSchema
|
|
4694
3822
|
),
|
|
4695
3823
|
abortSignal,
|
|
@@ -4719,7 +3847,7 @@ var XaiFiles = class {
|
|
|
4719
3847
|
url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}`,
|
|
4720
3848
|
headers: this.getHeaders(headers),
|
|
4721
3849
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4722
|
-
successfulResponseHandler:
|
|
3850
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
4723
3851
|
xaiFilesResponseSchema
|
|
4724
3852
|
),
|
|
4725
3853
|
abortSignal,
|
|
@@ -4771,7 +3899,7 @@ var XaiFiles = class {
|
|
|
4771
3899
|
url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}`,
|
|
4772
3900
|
headers: this.getHeaders(headers),
|
|
4773
3901
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4774
|
-
successfulResponseHandler:
|
|
3902
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
4775
3903
|
xaiFileDeleteResponseSchema
|
|
4776
3904
|
),
|
|
4777
3905
|
abortSignal,
|
|
@@ -4798,38 +3926,38 @@ var XaiFiles = class {
|
|
|
4798
3926
|
// src/xai-video-model.ts
|
|
4799
3927
|
import {
|
|
4800
3928
|
AISDKError,
|
|
4801
|
-
APICallError
|
|
3929
|
+
APICallError
|
|
4802
3930
|
} from "@ai-sdk/provider";
|
|
4803
3931
|
import {
|
|
4804
|
-
combineHeaders as
|
|
3932
|
+
combineHeaders as combineHeaders5,
|
|
4805
3933
|
convertUint8ArrayToBase64,
|
|
4806
|
-
createJsonResponseHandler as
|
|
4807
|
-
extractResponseHeaders
|
|
3934
|
+
createJsonResponseHandler as createJsonResponseHandler5,
|
|
3935
|
+
extractResponseHeaders,
|
|
4808
3936
|
getFromApi as getFromApi4,
|
|
4809
|
-
getTopLevelMediaType as
|
|
4810
|
-
parseProviderOptions as
|
|
4811
|
-
postJsonToApi as
|
|
4812
|
-
safeParseJSON
|
|
3937
|
+
getTopLevelMediaType as getTopLevelMediaType2,
|
|
3938
|
+
parseProviderOptions as parseProviderOptions6,
|
|
3939
|
+
postJsonToApi as postJsonToApi4,
|
|
3940
|
+
safeParseJSON
|
|
4813
3941
|
} from "@ai-sdk/provider-utils";
|
|
4814
|
-
import { z as
|
|
3942
|
+
import { z as z19 } from "zod/v4";
|
|
4815
3943
|
|
|
4816
3944
|
// src/xai-video-model-options.ts
|
|
4817
3945
|
import { lazySchema as lazySchema9, zodSchema as zodSchema9 } from "@ai-sdk/provider-utils";
|
|
4818
|
-
import { z as
|
|
4819
|
-
var nonEmptyStringSchema =
|
|
4820
|
-
var resolutionSchema =
|
|
4821
|
-
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"]);
|
|
4822
3950
|
var baseFields = {
|
|
4823
|
-
pollIntervalMs:
|
|
4824
|
-
pollTimeoutMs:
|
|
3951
|
+
pollIntervalMs: z18.number().positive().nullish(),
|
|
3952
|
+
pollTimeoutMs: z18.number().positive().nullish(),
|
|
4825
3953
|
resolution: resolutionSchema.nullish()
|
|
4826
3954
|
};
|
|
4827
|
-
var runtimeSchema =
|
|
3955
|
+
var runtimeSchema = z18.looseObject({
|
|
4828
3956
|
mode: modeSchema.optional(),
|
|
4829
3957
|
videoUrl: nonEmptyStringSchema.optional(),
|
|
4830
|
-
referenceImageUrls:
|
|
4831
|
-
referenceVoiceIds:
|
|
4832
|
-
user:
|
|
3958
|
+
referenceImageUrls: z18.array(nonEmptyStringSchema).min(1).max(7).optional(),
|
|
3959
|
+
referenceVoiceIds: z18.array(nonEmptyStringSchema).max(3).optional(),
|
|
3960
|
+
user: z18.string().optional(),
|
|
4833
3961
|
...baseFields
|
|
4834
3962
|
});
|
|
4835
3963
|
var xaiVideoModelOptionsSchema = lazySchema9(
|
|
@@ -4859,8 +3987,8 @@ function resolveStartImage(options) {
|
|
|
4859
3987
|
var _a;
|
|
4860
3988
|
return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
|
|
4861
3989
|
}
|
|
4862
|
-
var isVideoFile = (file) => file.mediaType != null &&
|
|
4863
|
-
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";
|
|
4864
3992
|
function fileToXaiUrl(file) {
|
|
4865
3993
|
if (file.type === "url") {
|
|
4866
3994
|
return file.url;
|
|
@@ -4919,7 +4047,7 @@ var XaiVideoModel = class {
|
|
|
4919
4047
|
}
|
|
4920
4048
|
async buildRequestBody(options) {
|
|
4921
4049
|
const warnings = [];
|
|
4922
|
-
const xaiOptions = await
|
|
4050
|
+
const xaiOptions = await parseProviderOptions6({
|
|
4923
4051
|
provider: "xai",
|
|
4924
4052
|
providerOptions: options.providerOptions,
|
|
4925
4053
|
schema: xaiVideoModelOptionsSchema
|
|
@@ -5127,12 +4255,12 @@ var XaiVideoModel = class {
|
|
|
5127
4255
|
} else {
|
|
5128
4256
|
endpoint = `${baseURL}/videos/generations`;
|
|
5129
4257
|
}
|
|
5130
|
-
const { value: createResponse, responseHeaders } = await
|
|
4258
|
+
const { value: createResponse, responseHeaders } = await postJsonToApi4({
|
|
5131
4259
|
url: endpoint,
|
|
5132
|
-
headers:
|
|
4260
|
+
headers: combineHeaders5(this.config.headers(), options.headers),
|
|
5133
4261
|
body,
|
|
5134
4262
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
5135
|
-
successfulResponseHandler:
|
|
4263
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
5136
4264
|
xaiCreateVideoResponseSchema
|
|
5137
4265
|
),
|
|
5138
4266
|
abortSignal: options.abortSignal,
|
|
@@ -5163,7 +4291,7 @@ var XaiVideoModel = class {
|
|
|
5163
4291
|
const { value: statusResponse, responseHeaders } = await getFromApi4({
|
|
5164
4292
|
url: `${baseURL}/videos/${encodePathSegment2(requestId)}`,
|
|
5165
4293
|
validateUrl: false,
|
|
5166
|
-
headers:
|
|
4294
|
+
headers: combineHeaders5(this.config.headers(), options.headers),
|
|
5167
4295
|
successfulResponseHandler: xaiVideoStatusResponseHandler,
|
|
5168
4296
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
5169
4297
|
abortSignal: options.abortSignal,
|
|
@@ -5251,27 +4379,27 @@ var XaiVideoModel = class {
|
|
|
5251
4379
|
};
|
|
5252
4380
|
}
|
|
5253
4381
|
};
|
|
5254
|
-
var xaiCreateVideoResponseSchema =
|
|
5255
|
-
request_id:
|
|
4382
|
+
var xaiCreateVideoResponseSchema = z19.object({
|
|
4383
|
+
request_id: z19.string().nullish()
|
|
5256
4384
|
});
|
|
5257
|
-
var xaiVideoStatusResponseSchema =
|
|
5258
|
-
status:
|
|
5259
|
-
video:
|
|
5260
|
-
url:
|
|
5261
|
-
duration:
|
|
5262
|
-
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()
|
|
5263
4391
|
}).nullish(),
|
|
5264
|
-
model:
|
|
5265
|
-
usage:
|
|
5266
|
-
cost_in_usd_ticks:
|
|
4392
|
+
model: z19.string().nullish(),
|
|
4393
|
+
usage: z19.object({
|
|
4394
|
+
cost_in_usd_ticks: z19.number().nullish()
|
|
5267
4395
|
}).nullish(),
|
|
5268
|
-
progress:
|
|
5269
|
-
error:
|
|
5270
|
-
code:
|
|
5271
|
-
message:
|
|
4396
|
+
progress: z19.number().nullish(),
|
|
4397
|
+
error: z19.object({
|
|
4398
|
+
code: z19.string().nullish(),
|
|
4399
|
+
message: z19.string().nullish()
|
|
5272
4400
|
}).nullish()
|
|
5273
4401
|
});
|
|
5274
|
-
var xaiVideoStatusJsonResponseHandler =
|
|
4402
|
+
var xaiVideoStatusJsonResponseHandler = createJsonResponseHandler5(
|
|
5275
4403
|
xaiVideoStatusResponseSchema
|
|
5276
4404
|
);
|
|
5277
4405
|
var MAX_PENDING_BODY_BYTES = 1024 * 1024;
|
|
@@ -5293,12 +4421,12 @@ async function readPendingBody({
|
|
|
5293
4421
|
if (done) break;
|
|
5294
4422
|
totalBytes += value.length;
|
|
5295
4423
|
if (totalBytes > MAX_PENDING_BODY_BYTES) {
|
|
5296
|
-
throw new
|
|
4424
|
+
throw new APICallError({
|
|
5297
4425
|
message: `xAI video status response exceeded ${MAX_PENDING_BODY_BYTES} bytes`,
|
|
5298
4426
|
url,
|
|
5299
4427
|
requestBodyValues,
|
|
5300
4428
|
statusCode: response.status,
|
|
5301
|
-
responseHeaders:
|
|
4429
|
+
responseHeaders: extractResponseHeaders(response)
|
|
5302
4430
|
});
|
|
5303
4431
|
}
|
|
5304
4432
|
chunks.push(value);
|
|
@@ -5316,12 +4444,12 @@ async function readPendingBody({
|
|
|
5316
4444
|
}
|
|
5317
4445
|
var xaiVideoStatusResponseHandler = async (options) => {
|
|
5318
4446
|
if (options.response.status === 202) {
|
|
5319
|
-
const responseHeaders =
|
|
4447
|
+
const responseHeaders = extractResponseHeaders(options.response);
|
|
5320
4448
|
const text = await readPendingBody(options);
|
|
5321
4449
|
if (text.trim().length === 0) {
|
|
5322
4450
|
return { responseHeaders, value: { status: "pending" } };
|
|
5323
4451
|
}
|
|
5324
|
-
const parsed = await
|
|
4452
|
+
const parsed = await safeParseJSON({
|
|
5325
4453
|
text,
|
|
5326
4454
|
schema: xaiVideoStatusResponseSchema
|
|
5327
4455
|
});
|
|
@@ -5335,69 +4463,69 @@ var xaiVideoStatusResponseHandler = async (options) => {
|
|
|
5335
4463
|
|
|
5336
4464
|
// src/xai-speech-model.ts
|
|
5337
4465
|
import {
|
|
5338
|
-
combineHeaders as
|
|
4466
|
+
combineHeaders as combineHeaders6,
|
|
5339
4467
|
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
|
5340
4468
|
createBinaryResponseHandler as createBinaryResponseHandler3,
|
|
5341
|
-
createJsonResponseHandler as
|
|
5342
|
-
parseProviderOptions as
|
|
5343
|
-
postJsonToApi as
|
|
4469
|
+
createJsonResponseHandler as createJsonResponseHandler6,
|
|
4470
|
+
parseProviderOptions as parseProviderOptions7,
|
|
4471
|
+
postJsonToApi as postJsonToApi5,
|
|
5344
4472
|
resolve,
|
|
5345
|
-
serializeModelOptions as
|
|
5346
|
-
WORKFLOW_DESERIALIZE as
|
|
5347
|
-
WORKFLOW_SERIALIZE as
|
|
4473
|
+
serializeModelOptions as serializeModelOptions3,
|
|
4474
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
|
|
4475
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3
|
|
5348
4476
|
} from "@ai-sdk/provider-utils";
|
|
5349
|
-
import { z as
|
|
4477
|
+
import { z as z21 } from "zod/v4";
|
|
5350
4478
|
|
|
5351
4479
|
// src/xai-speech-model-options.ts
|
|
5352
4480
|
import {
|
|
5353
4481
|
lazySchema as lazySchema10,
|
|
5354
4482
|
zodSchema as zodSchema10
|
|
5355
4483
|
} from "@ai-sdk/provider-utils";
|
|
5356
|
-
import { z as
|
|
4484
|
+
import { z as z20 } from "zod/v4";
|
|
5357
4485
|
var xaiSpeechModelOptionsSchema = lazySchema10(
|
|
5358
4486
|
() => zodSchema10(
|
|
5359
|
-
|
|
4487
|
+
z20.object({
|
|
5360
4488
|
/**
|
|
5361
4489
|
* Sample rate of the generated audio in Hz.
|
|
5362
4490
|
*/
|
|
5363
|
-
sampleRate:
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
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)
|
|
5370
4498
|
]).nullish(),
|
|
5371
4499
|
/**
|
|
5372
4500
|
* MP3 bit rate in bits per second. Only applies when outputFormat is mp3.
|
|
5373
4501
|
*/
|
|
5374
|
-
bitRate:
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
4502
|
+
bitRate: z20.union([
|
|
4503
|
+
z20.literal(32e3),
|
|
4504
|
+
z20.literal(64e3),
|
|
4505
|
+
z20.literal(96e3),
|
|
4506
|
+
z20.literal(128e3),
|
|
4507
|
+
z20.literal(192e3)
|
|
5380
4508
|
]).nullish(),
|
|
5381
4509
|
/**
|
|
5382
4510
|
* Reduce time to first audio chunk, trading some quality for latency.
|
|
5383
4511
|
*/
|
|
5384
|
-
optimizeStreamingLatency:
|
|
4512
|
+
optimizeStreamingLatency: z20.union([z20.literal(0), z20.literal(1), z20.literal(2)]).nullish(),
|
|
5385
4513
|
/**
|
|
5386
4514
|
* Normalize written-form text into spoken-form text before synthesis.
|
|
5387
4515
|
*/
|
|
5388
|
-
textNormalization:
|
|
4516
|
+
textNormalization: z20.boolean().nullish(),
|
|
5389
4517
|
/**
|
|
5390
4518
|
* Return character-level timing metadata alongside the audio. When
|
|
5391
4519
|
* enabled, the response carries per-character start/end times and the
|
|
5392
4520
|
* total duration, exposed via `providerMetadata.xai`.
|
|
5393
4521
|
*/
|
|
5394
|
-
withTimestamps:
|
|
4522
|
+
withTimestamps: z20.boolean().nullish(),
|
|
5395
4523
|
/**
|
|
5396
4524
|
* Map of phrases to spoken substitutions applied before synthesis.
|
|
5397
4525
|
* Values may be respellings (`{ 'Acme Mobile': 'Acme Mobull' }`) or IPA
|
|
5398
4526
|
* phonetics (`{ nginx: '/ˈɛndʒɪn ˈɛks/' }`).
|
|
5399
4527
|
*/
|
|
5400
|
-
replace:
|
|
4528
|
+
replace: z20.record(z20.string(), z20.string()).nullish()
|
|
5401
4529
|
})
|
|
5402
4530
|
)
|
|
5403
4531
|
);
|
|
@@ -5409,13 +4537,13 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
5409
4537
|
this.config = config;
|
|
5410
4538
|
this.specificationVersion = "v4";
|
|
5411
4539
|
}
|
|
5412
|
-
static [
|
|
5413
|
-
return
|
|
4540
|
+
static [WORKFLOW_SERIALIZE3](model) {
|
|
4541
|
+
return serializeModelOptions3({
|
|
5414
4542
|
modelId: model.modelId,
|
|
5415
4543
|
config: model.config
|
|
5416
4544
|
});
|
|
5417
4545
|
}
|
|
5418
|
-
static [
|
|
4546
|
+
static [WORKFLOW_DESERIALIZE3](options) {
|
|
5419
4547
|
return new _XaiSpeechModel(options.modelId, options.config);
|
|
5420
4548
|
}
|
|
5421
4549
|
get provider() {
|
|
@@ -5431,7 +4559,7 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
5431
4559
|
providerOptions
|
|
5432
4560
|
}) {
|
|
5433
4561
|
const warnings = [];
|
|
5434
|
-
const xaiOptions = await
|
|
4562
|
+
const xaiOptions = await parseProviderOptions7({
|
|
5435
4563
|
provider: "xai",
|
|
5436
4564
|
providerOptions,
|
|
5437
4565
|
schema: xaiSpeechModelOptionsSchema
|
|
@@ -5491,15 +4619,15 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
5491
4619
|
var _a, _b, _c;
|
|
5492
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();
|
|
5493
4621
|
const { requestBody, warnings, withTimestamps } = await this.getArgs(options);
|
|
5494
|
-
const { value, responseHeaders, rawValue } = await
|
|
4622
|
+
const { value, responseHeaders, rawValue } = await postJsonToApi5({
|
|
5495
4623
|
url: `${this.config.baseURL}/tts`,
|
|
5496
|
-
headers:
|
|
4624
|
+
headers: combineHeaders6(
|
|
5497
4625
|
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
5498
4626
|
options.headers
|
|
5499
4627
|
),
|
|
5500
4628
|
body: requestBody,
|
|
5501
4629
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
5502
|
-
successfulResponseHandler: withTimestamps ?
|
|
4630
|
+
successfulResponseHandler: withTimestamps ? createJsonResponseHandler6(xaiSpeechTimestampsResponseSchema) : createBinaryResponseHandler3(),
|
|
5503
4631
|
abortSignal: options.abortSignal,
|
|
5504
4632
|
fetch: this.config.fetch
|
|
5505
4633
|
});
|
|
@@ -5540,13 +4668,13 @@ var XaiSpeechModel = class _XaiSpeechModel {
|
|
|
5540
4668
|
};
|
|
5541
4669
|
}
|
|
5542
4670
|
};
|
|
5543
|
-
var xaiSpeechTimestampsResponseSchema =
|
|
5544
|
-
audio:
|
|
5545
|
-
content_type:
|
|
5546
|
-
duration:
|
|
5547
|
-
audio_timestamps:
|
|
5548
|
-
graph_chars:
|
|
5549
|
-
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()]))
|
|
5550
4678
|
}).nullish()
|
|
5551
4679
|
});
|
|
5552
4680
|
|
|
@@ -5555,94 +4683,94 @@ import {
|
|
|
5555
4683
|
InvalidArgumentError as InvalidArgumentError3
|
|
5556
4684
|
} from "@ai-sdk/provider";
|
|
5557
4685
|
import {
|
|
5558
|
-
combineHeaders as
|
|
4686
|
+
combineHeaders as combineHeaders7,
|
|
5559
4687
|
convertBase64ToUint8Array as convertBase64ToUint8Array3,
|
|
5560
|
-
createJsonResponseHandler as
|
|
4688
|
+
createJsonResponseHandler as createJsonResponseHandler7,
|
|
5561
4689
|
connectToWebSocket,
|
|
5562
4690
|
mediaTypeToExtension,
|
|
5563
|
-
parseProviderOptions as
|
|
4691
|
+
parseProviderOptions as parseProviderOptions8,
|
|
5564
4692
|
postFormDataToApi as postFormDataToApi3,
|
|
5565
|
-
safeParseJSON as
|
|
5566
|
-
serializeModelOptions as
|
|
4693
|
+
safeParseJSON as safeParseJSON2,
|
|
4694
|
+
serializeModelOptions as serializeModelOptions4,
|
|
5567
4695
|
toWebSocketUrl,
|
|
5568
4696
|
waitForWebSocketBufferDrain,
|
|
5569
|
-
WORKFLOW_DESERIALIZE as
|
|
5570
|
-
WORKFLOW_SERIALIZE as
|
|
4697
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4,
|
|
4698
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4
|
|
5571
4699
|
} from "@ai-sdk/provider-utils";
|
|
5572
|
-
import { z as
|
|
4700
|
+
import { z as z23 } from "zod/v4";
|
|
5573
4701
|
|
|
5574
4702
|
// src/xai-transcription-model-options.ts
|
|
5575
4703
|
import {
|
|
5576
4704
|
lazySchema as lazySchema11,
|
|
5577
4705
|
zodSchema as zodSchema11
|
|
5578
4706
|
} from "@ai-sdk/provider-utils";
|
|
5579
|
-
import { z as
|
|
4707
|
+
import { z as z22 } from "zod/v4";
|
|
5580
4708
|
var xaiTranscriptionModelOptionsSchema = lazySchema11(
|
|
5581
4709
|
() => zodSchema11(
|
|
5582
|
-
|
|
4710
|
+
z22.object({
|
|
5583
4711
|
/**
|
|
5584
4712
|
* Audio encoding for raw, headerless input audio.
|
|
5585
4713
|
*/
|
|
5586
|
-
audioFormat:
|
|
4714
|
+
audioFormat: z22.enum(["pcm", "mulaw", "alaw"]).nullish(),
|
|
5587
4715
|
/**
|
|
5588
4716
|
* Sample rate of the input audio in Hz.
|
|
5589
4717
|
*/
|
|
5590
|
-
sampleRate:
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
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)
|
|
5597
4725
|
]).nullish(),
|
|
5598
4726
|
/**
|
|
5599
4727
|
* Language code used for inverse text normalization.
|
|
5600
4728
|
*/
|
|
5601
|
-
language:
|
|
4729
|
+
language: z22.string().nullish(),
|
|
5602
4730
|
/**
|
|
5603
4731
|
* Enable inverse text normalization. Requires `language`.
|
|
5604
4732
|
*/
|
|
5605
|
-
format:
|
|
4733
|
+
format: z22.boolean().nullish(),
|
|
5606
4734
|
/**
|
|
5607
4735
|
* Enable per-channel transcription for multichannel audio.
|
|
5608
4736
|
*/
|
|
5609
|
-
multichannel:
|
|
4737
|
+
multichannel: z22.boolean().nullish(),
|
|
5610
4738
|
/**
|
|
5611
4739
|
* Number of interleaved audio channels.
|
|
5612
4740
|
*/
|
|
5613
|
-
channels:
|
|
4741
|
+
channels: z22.number().int().min(2).max(8).nullish(),
|
|
5614
4742
|
/**
|
|
5615
4743
|
* Enable speaker diarization.
|
|
5616
4744
|
*/
|
|
5617
|
-
diarize:
|
|
4745
|
+
diarize: z22.boolean().nullish(),
|
|
5618
4746
|
/**
|
|
5619
4747
|
* Terms to bias transcription toward.
|
|
5620
4748
|
*/
|
|
5621
|
-
keyterm:
|
|
4749
|
+
keyterm: z22.union([z22.string(), z22.array(z22.string())]).nullish(),
|
|
5622
4750
|
/**
|
|
5623
4751
|
* Include filler words such as "uh" and "um" in the transcript.
|
|
5624
4752
|
*/
|
|
5625
|
-
fillerWords:
|
|
4753
|
+
fillerWords: z22.boolean().nullish(),
|
|
5626
4754
|
/**
|
|
5627
4755
|
* Options for streaming speech-to-text over WebSocket.
|
|
5628
4756
|
*/
|
|
5629
|
-
streaming:
|
|
4757
|
+
streaming: z22.object({
|
|
5630
4758
|
/**
|
|
5631
4759
|
* Emit interim transcript results while speech is being processed.
|
|
5632
4760
|
*/
|
|
5633
|
-
interimResults:
|
|
4761
|
+
interimResults: z22.boolean().optional(),
|
|
5634
4762
|
/**
|
|
5635
4763
|
* Silence duration in milliseconds before an utterance-final event.
|
|
5636
4764
|
*/
|
|
5637
|
-
endpointing:
|
|
4765
|
+
endpointing: z22.number().int().min(0).max(5e3).optional(),
|
|
5638
4766
|
/**
|
|
5639
4767
|
* End-of-turn detection threshold. When set, enables Smart Turn.
|
|
5640
4768
|
*/
|
|
5641
|
-
smartTurn:
|
|
4769
|
+
smartTurn: z22.number().min(0).max(1).optional(),
|
|
5642
4770
|
/**
|
|
5643
4771
|
* Maximum silence duration in milliseconds before forcing speech_final.
|
|
5644
4772
|
*/
|
|
5645
|
-
smartTurnTimeout:
|
|
4773
|
+
smartTurnTimeout: z22.number().int().min(1).max(5e3).optional()
|
|
5646
4774
|
}).optional()
|
|
5647
4775
|
})
|
|
5648
4776
|
)
|
|
@@ -5655,13 +4783,13 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5655
4783
|
this.config = config;
|
|
5656
4784
|
this.specificationVersion = "v4";
|
|
5657
4785
|
}
|
|
5658
|
-
static [
|
|
5659
|
-
return
|
|
4786
|
+
static [WORKFLOW_SERIALIZE4](model) {
|
|
4787
|
+
return serializeModelOptions4({
|
|
5660
4788
|
modelId: model.modelId,
|
|
5661
4789
|
config: model.config
|
|
5662
4790
|
});
|
|
5663
4791
|
}
|
|
5664
|
-
static [
|
|
4792
|
+
static [WORKFLOW_DESERIALIZE4](options) {
|
|
5665
4793
|
return new _XaiTranscriptionModel(options.modelId, options.config);
|
|
5666
4794
|
}
|
|
5667
4795
|
get provider() {
|
|
@@ -5673,7 +4801,7 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5673
4801
|
providerOptions
|
|
5674
4802
|
}) {
|
|
5675
4803
|
const warnings = [];
|
|
5676
|
-
const xaiOptions = await
|
|
4804
|
+
const xaiOptions = await parseProviderOptions8({
|
|
5677
4805
|
provider: "xai",
|
|
5678
4806
|
providerOptions,
|
|
5679
4807
|
schema: xaiTranscriptionModelOptionsSchema
|
|
@@ -5719,10 +4847,10 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5719
4847
|
rawValue: rawResponse
|
|
5720
4848
|
} = await postFormDataToApi3({
|
|
5721
4849
|
url: `${(_d = this.config.baseURL) != null ? _d : "https://api.x.ai/v1"}/stt`,
|
|
5722
|
-
headers:
|
|
4850
|
+
headers: combineHeaders7((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), options.headers),
|
|
5723
4851
|
formData,
|
|
5724
4852
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
5725
|
-
successfulResponseHandler:
|
|
4853
|
+
successfulResponseHandler: createJsonResponseHandler7(
|
|
5726
4854
|
xaiTranscriptionResponseSchema
|
|
5727
4855
|
),
|
|
5728
4856
|
abortSignal: options.abortSignal,
|
|
@@ -5750,7 +4878,7 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5750
4878
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
5751
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();
|
|
5752
4880
|
const warnings = [];
|
|
5753
|
-
const xaiOptions = await
|
|
4881
|
+
const xaiOptions = await parseProviderOptions8({
|
|
5754
4882
|
provider: "xai",
|
|
5755
4883
|
providerOptions: options.providerOptions,
|
|
5756
4884
|
schema: xaiTranscriptionModelOptionsSchema
|
|
@@ -5779,7 +4907,7 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
|
|
|
5779
4907
|
inputAudioFormat: options.inputAudioFormat,
|
|
5780
4908
|
providerOptions: xaiOptions
|
|
5781
4909
|
});
|
|
5782
|
-
const headers =
|
|
4910
|
+
const headers = combineHeaders7((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), options.headers);
|
|
5783
4911
|
return {
|
|
5784
4912
|
request: { body: url.toString() },
|
|
5785
4913
|
response: {
|
|
@@ -5880,7 +5008,7 @@ function createXaiStreamingTranscriptionStream({
|
|
|
5880
5008
|
onProcessingError: finishWithError,
|
|
5881
5009
|
onMessageText: async (text) => {
|
|
5882
5010
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
5883
|
-
const parsed = await
|
|
5011
|
+
const parsed = await safeParseJSON2({ text });
|
|
5884
5012
|
if (!parsed.success) return;
|
|
5885
5013
|
const raw = parsed.value;
|
|
5886
5014
|
if (includeRawChunks) {
|
|
@@ -6041,15 +5169,15 @@ function timingFromXaiEvent(event) {
|
|
|
6041
5169
|
...event.start != null && event.duration != null ? { endSecond: event.start + event.duration } : {}
|
|
6042
5170
|
};
|
|
6043
5171
|
}
|
|
6044
|
-
var xaiTranscriptionResponseSchema =
|
|
6045
|
-
text:
|
|
6046
|
-
language:
|
|
6047
|
-
duration:
|
|
6048
|
-
words:
|
|
6049
|
-
|
|
6050
|
-
text:
|
|
6051
|
-
start:
|
|
6052
|
-
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()
|
|
6053
5181
|
})
|
|
6054
5182
|
).nullish()
|
|
6055
5183
|
});
|
|
@@ -6071,15 +5199,6 @@ function createXai(options = {}) {
|
|
|
6071
5199
|
},
|
|
6072
5200
|
`ai-sdk/xai/${VERSION}`
|
|
6073
5201
|
);
|
|
6074
|
-
const createChatLanguageModel = (modelId) => {
|
|
6075
|
-
return new XaiChatLanguageModel(modelId, {
|
|
6076
|
-
provider: "xai.chat",
|
|
6077
|
-
baseURL,
|
|
6078
|
-
headers: getHeaders,
|
|
6079
|
-
generateId,
|
|
6080
|
-
fetch: options.fetch
|
|
6081
|
-
});
|
|
6082
|
-
};
|
|
6083
5202
|
const createResponsesLanguageModel = (modelId) => {
|
|
6084
5203
|
return new XaiResponsesLanguageModel(modelId, {
|
|
6085
5204
|
provider: "xai.responses",
|
|
@@ -6166,7 +5285,6 @@ function createXai(options = {}) {
|
|
|
6166
5285
|
const provider = (modelId) => createResponsesLanguageModel(modelId);
|
|
6167
5286
|
provider.specificationVersion = "v4";
|
|
6168
5287
|
provider.languageModel = createResponsesLanguageModel;
|
|
6169
|
-
provider.chat = createChatLanguageModel;
|
|
6170
5288
|
provider.responses = createResponsesLanguageModel;
|
|
6171
5289
|
provider.embeddingModel = (modelId) => {
|
|
6172
5290
|
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|