@gullabs/xai 0.8.0 → 0.9.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/README.md +28 -6
- package/dist/index.cjs +154 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +154 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ xAI has no first-party TypeScript SDK. xAI's own quickstart recommends using the
|
|
|
33
33
|
| `Grok45ConfigSchema` | Strict Zod config schema for `grok-4.5` |
|
|
34
34
|
| `Grok46ConfigSchema` | Strict Zod config schema for `grok-4.6` |
|
|
35
35
|
| `Grok47ConfigSchema` | Strict Zod config schema for `grok-4.7` |
|
|
36
|
-
| `XaiProviderOptions` | Typed `providerOptions.xai` shape for cache key, search tools, and parallel calls
|
|
36
|
+
| `XaiProviderOptions` | Typed `providerOptions.xai` shape for cache key, search tools, tool choice, turn cap, and parallel calls |
|
|
37
37
|
| `XaiFileStore` | Files API store: upload (TTL), get, list, idempotent delete, content |
|
|
38
38
|
| `XaiFileHandle` | `{ id, filename?, bytes?, expiresAt?, … }` returned by the store |
|
|
39
39
|
| `FileDeleteOptions` | `{ failClosed?, signal? }` — opt-in fail-closed delete for durable release gates |
|
|
@@ -133,9 +133,11 @@ The default registry ships three canonical models (500k token context window eac
|
|
|
133
133
|
- `grok-4.5`: `admittedReasoningEfforts: ['low', 'medium', 'high']` (live-verified 2026-08-24; `'medium'` is now accepted). `'none'` and `'xhigh'` are rejected. `'none'` remains rejected ("reasoning cannot be disabled").
|
|
134
134
|
- `grok-4.6` and `grok-4.7`: `admittedReasoningEfforts: ['low', 'medium', 'high', 'xhigh']`. `'none'` is rejected.
|
|
135
135
|
- **Structured output** — native. `output.jsonSchema` maps to the Responses API's `text.format` field with `{ type: 'json_schema', name, schema, strict: true }`, **not** `response_format` — this differs from OpenAI's own convention for the same underlying concept.
|
|
136
|
-
- **Structured output with built-in search** — admitted on `grok-4.6
|
|
137
|
-
-
|
|
136
|
+
- **Structured output with built-in search** — admitted on all three models (`grok-4.6` in fixture 18; `grok-4.5` and `grok-4.7` live-verified 2026-10-02 in fixture 32). The adapter rejects this combination on descriptors without `structuredOutputWithTools`.
|
|
137
|
+
- **Output schemas are standard JSON Schema.** A nullable field lists `'null'` in `type` (`type: ['string', 'null']`). The adapter rejects the OpenAPI `nullable` keyword and uppercase type names (`STRING`, `OBJECT`) with `bad_request` before dispatch, naming the path, and never rewrites a schema. Live on 2026-10-02 (fixture 34): xAI accepted `nullable: true` and ignored it on all three models, so the model could not return `null` and wrote `""`, `0` or the string `"null"`; uppercase type names failed at xAI with HTTP 400.
|
|
138
|
+
- **`strict: true` performs no OpenAI-style compile-time schema validation, as of the 2026-07-09 live probes.** 2026-07-09 live verification against the real xAI Responses API — 13 single-variant probes plus 1 combined probe (14 calls total, all accepted HTTP 200; the combined probe is recorded as fixture `10-non-strict-schema-accepted.json`) — verified that `text.format` with `strict: true` accepted every one of the following schema shapes that OpenAI's own strict mode rejects at compile time: schemas (root and nested) missing `additionalProperties: false`; properties omitted from `required` (optional properties); `format`, `minLength`, `pattern`, and `default` keywords; `anyOf`; `$defs`/`$ref`; `enum`/`const`; and nullable unions (`type: [T, 'null']`). `strict: false` on the same surface showed no observed behavioral divergence from `strict: true`. This adapter forwards schemas to xAI verbatim — no rewriting, no OpenAI-strict preflight, and no injection of `additionalProperties: false` or `required` completion — so OpenAI-strict schema rewriting (including `@gullabs/codex-cli`'s `toOpenAiStrictOutputSchema` helper) is unnecessary for xai as of that verification date. The one preflight added since is the dialect check in the bullet above. (Reject-don't-map still applies to genuinely invalid input the xai schema/types layer itself rejects; this note is only about strict-mode compile-time schema-shape enforcement.) `packages/xai/src/__fixtures__/10-non-strict-schema-accepted.json` records one live example combining three of these — missing root `additionalProperties: false`, an optional property, and a `format` keyword — in a single accepted call.
|
|
138
139
|
- **Sampling** — `temperature` and `topP` are forwarded verbatim. No `topK`.
|
|
140
|
+
- **`max_output_tokens`** — forwarded only when the caller sets `maxOutputTokens`. The value includes both output and reasoning tokens and defaults to 128,000 when unset (docs read 2026-10-02). Truncation surfaces as `finishReason: 'length'`, not an error.
|
|
139
141
|
- **No penalties/stop** — `presence_penalty`, `frequency_penalty`, and `stop` are not in the config schema at all; xAI hard-rejects these on reasoning models, so the schema never admits them (reject-don't-map).
|
|
140
142
|
- **Service tiers** — all three models admit `serviceTier: 'priority'` (Responses `service_tier: "priority"`, billed at 2×). Grok 4.5 was captured live on 2026-09-25 and Grok 4.6 on 2026-08-12. `'flex'` / `'standard'` / `'batch'` are rejected — xAI silently remaps unknown tiers to `default`, so this library never forwards them.
|
|
141
143
|
|
|
@@ -240,7 +242,27 @@ xAI caching is automatic — there is no explicit cache-create/cache-store API c
|
|
|
240
242
|
| `x_posts_fetched` | $5 / 1,000 posts |
|
|
241
243
|
| `x_users_fetched` | $10 / 1,000 profiles |
|
|
242
244
|
|
|
243
|
-
Enable Live Search with `providerOptions.xai.tools` (`web_search` / `x_search`). Citations land on `result.citations`.
|
|
245
|
+
Enable Live Search with `providerOptions.xai.tools` (`web_search` / `x_search`). Citations land on `result.citations`.
|
|
246
|
+
|
|
247
|
+
### Controlling the search tools
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
config: {
|
|
251
|
+
providerOptions: {
|
|
252
|
+
xai: {
|
|
253
|
+
tools: [{ type: 'web_search' }, { type: 'x_search' }],
|
|
254
|
+
toolChoice: 'required', // 'auto' | 'required' | 'none'
|
|
255
|
+
maxTurns: 3,
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
- **`toolChoice`** maps to the Responses `tool_choice` for the search tools. Left on `auto`, a model can answer without searching; `required` forces at least one search and `none` disables the declared tools. Live on 2026-10-02 (fixture 32), `required` ran 3 / 2 / 2 searches on grok-4.5 / 4.6 / 4.7 and `none` ran 0. It needs a non-empty `tools`, and the adapter rejects it together with function tools, file attachments or the request-level `toolChoice`: xAI takes one `tool_choice` per request and `required` means "at least one tool", which a function call or the implicit `attachment_search` would satisfy. Send it on every request; nothing carries over between calls.
|
|
262
|
+
- **`maxTurns`** maps to the Responses `max_turns` (integer ≥ 1, needs `tools`). xAI documents it as the cap on agentic tool-calling turns. A turn can run several searches, so it is not a search count. **xAI did not enforce it as of 2026-10-02** (fixture 33): with `max_turns: 1` the three models still ran 10 to 17 searches over several rounds. The option is forwarded verbatim so hosts get the cap when xAI enforces it. Until then, state the search budget in the prompt and assert on the observed count.
|
|
263
|
+
- **Observed count.** `result.usage.details.web_search_calls` is the number of web searches billed; `x_posts_fetched` and `x_users_fetched` are the X Search billing counters (items, not calls). All three persist to the ledger's token details. When no server tool ran, xAI reports `num_server_side_tools_used: 0` and omits the counters; the adapter prices that call exactly with no tool fee.
|
|
264
|
+
- **Cost.** There is no enforceable search cap, and every search result is fed back as input. One uncapped grok-4.7 research call used 362k input tokens, which crosses the 200k long-context threshold, and cost about $1.07.
|
|
265
|
+
`countTokens` uses `POST /v1/tokenize-text` and returns `accuracy: 'lower-bound'` (text parts only; media / file parts are `bad_request`).
|
|
244
266
|
|
|
245
267
|
| Model | Tier | Input | Cached input | Output |
|
|
246
268
|
| ---------- | ---------------------------- | ------- | ------------ | -------- |
|
|
@@ -253,9 +275,9 @@ Enable Live Search with `providerOptions.xai.tools` (`web_search` / `x_search`).
|
|
|
253
275
|
|
|
254
276
|
The `gt200k` long-context tier is selected by **gross** `inputTokens` (including cached), not billable input — at or above 200,000 tokens (`long_context_threshold`), as stated on [xAI's pricing page](https://docs.x.ai/developers/pricing). The adapter surfaces the echoed Responses `service_tier` (`'default'` or `'priority'`), so `price()` receives that served value instead of `undefined`. Custom xAI `PricingSource` implementations must price `'default'` at the standard list. Built-in `xaiPricingSource().price()` prices priority at 2× every token type after the cache discount. Fixture `23-grok-4-5-priority.json` confirms Grok 4.5's 2× total, and fixture `12-grok-4-6-xhigh-priority.json` confirms Grok 4.6; cached and `gt200k` legs follow the official 2×-after-cache-discount rule. `fast` is not admitted. Any other defined tier is unpriced (`microUsd: null`). Grok 4.5/4.6 list rates are pinned to `packages/xai/src/__fixtures__/14-v1-models-pricing.json` (live `GET /v1/models` 2026-08-12); Grok 4.7 rates come from the [September 21 release notes](https://docs.x.ai/developers/release-notes).
|
|
255
277
|
|
|
256
|
-
##
|
|
278
|
+
## Regions
|
|
257
279
|
|
|
258
|
-
|
|
280
|
+
The grok-4.6 and grok-4.7 model pages list `us-east-1`, `us-west-2`, and `us-central-1` (docs read 2026-10-02). The release notes say Grok 4.5 is available in the API console for EU users (docs read 2026-10-02). This is a hosting/deployment concern for callers, not something this library can route around; it is documented here so consumers are not surprised by data-residency constraints.
|
|
259
281
|
|
|
260
282
|
## Aliases are not registered
|
|
261
283
|
|
package/dist/index.cjs
CHANGED
|
@@ -117,6 +117,14 @@ var XaiProviderOptionsSchema = zod.z.strictObject({
|
|
|
117
117
|
parallelToolCalls: zod.z.boolean().optional().meta({
|
|
118
118
|
title: "Parallel Tool Calls",
|
|
119
119
|
description: "xAI Responses parallel_tool_calls. Not a generic contract field."
|
|
120
|
+
}),
|
|
121
|
+
toolChoice: zod.z.enum(["auto", "required", "none"]).optional().meta({
|
|
122
|
+
title: "Server Tool Choice",
|
|
123
|
+
description: "xAI Responses `tool_choice` for the server-side search tools; `required` forces at least one search, `none` disables them. Requires `tools`. Cannot be combined with function tools, file attachments or the request-level toolChoice."
|
|
124
|
+
}),
|
|
125
|
+
maxTurns: zod.z.number().int().min(1).optional().meta({
|
|
126
|
+
title: "Max Turns",
|
|
127
|
+
description: "xAI Responses `max_turns`: cap on agentic tool-calling turns for the server-side search tools. Requires `tools`. A turn can run several searches. Not enforced by xAI as of 2026-10-02."
|
|
120
128
|
})
|
|
121
129
|
}).meta({
|
|
122
130
|
title: "xAI Provider Options",
|
|
@@ -264,6 +272,7 @@ var grok45ModelDescriptor = {
|
|
|
264
272
|
sampling: "tunable",
|
|
265
273
|
caching: { explicit: false, minTokens: 0 },
|
|
266
274
|
grounding: true,
|
|
275
|
+
structuredOutputWithTools: true,
|
|
267
276
|
functionCalling: true,
|
|
268
277
|
serviceTiers: ["priority"]
|
|
269
278
|
},
|
|
@@ -309,6 +318,7 @@ var grok47ModelDescriptor = {
|
|
|
309
318
|
sampling: "tunable",
|
|
310
319
|
caching: { explicit: false, minTokens: 0 },
|
|
311
320
|
grounding: true,
|
|
321
|
+
structuredOutputWithTools: true,
|
|
312
322
|
functionCalling: true,
|
|
313
323
|
statelessReasoningReplay: true,
|
|
314
324
|
serviceTiers: ["priority"]
|
|
@@ -323,6 +333,89 @@ var xaiModelDescriptors = [
|
|
|
323
333
|
grok47ModelDescriptor
|
|
324
334
|
];
|
|
325
335
|
var xaiRegistry = core.createModelRegistry(xaiModelDescriptors);
|
|
336
|
+
var JSON_SCHEMA_TYPES = /* @__PURE__ */ new Set([
|
|
337
|
+
"string",
|
|
338
|
+
"number",
|
|
339
|
+
"integer",
|
|
340
|
+
"boolean",
|
|
341
|
+
"object",
|
|
342
|
+
"array",
|
|
343
|
+
"null"
|
|
344
|
+
]);
|
|
345
|
+
var SINGLE_SCHEMA_KEYWORDS = [
|
|
346
|
+
"additionalProperties",
|
|
347
|
+
"additionalItems",
|
|
348
|
+
"items",
|
|
349
|
+
"contains",
|
|
350
|
+
"not",
|
|
351
|
+
"if",
|
|
352
|
+
"then",
|
|
353
|
+
"else",
|
|
354
|
+
"propertyNames",
|
|
355
|
+
"unevaluatedProperties",
|
|
356
|
+
"unevaluatedItems",
|
|
357
|
+
"contentSchema"
|
|
358
|
+
];
|
|
359
|
+
var SCHEMA_ARRAY_KEYWORDS = ["items", "prefixItems", "anyOf", "oneOf", "allOf"];
|
|
360
|
+
var SCHEMA_MAP_KEYWORDS = [
|
|
361
|
+
"properties",
|
|
362
|
+
"patternProperties",
|
|
363
|
+
"dependentSchemas",
|
|
364
|
+
// Draft-07 `dependencies`: schema-valued entries are walked; array-valued
|
|
365
|
+
// entries are property-name lists and are skipped by the object check.
|
|
366
|
+
"dependencies",
|
|
367
|
+
"$defs",
|
|
368
|
+
"definitions"
|
|
369
|
+
];
|
|
370
|
+
function isPlainObject(value) {
|
|
371
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
372
|
+
}
|
|
373
|
+
function badSchema(message) {
|
|
374
|
+
return new core.LlmError(message, { kind: "bad_request", retryable: false, provider: "xai" });
|
|
375
|
+
}
|
|
376
|
+
function assertNode(node, path) {
|
|
377
|
+
const at = path.length > 0 ? path : "<root>";
|
|
378
|
+
if ("nullable" in node) {
|
|
379
|
+
throw badSchema(
|
|
380
|
+
`xAI structured output takes standard JSON Schema, which has no \`nullable\` keyword (found at \`${at}\`). xAI ignores it, so the field would be required and non-null. List 'null' in \`type\` instead, e.g. type: ['string', 'null'].`
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
const type = node["type"];
|
|
384
|
+
if (type !== void 0) {
|
|
385
|
+
const names = Array.isArray(type) ? type : [type];
|
|
386
|
+
for (const name of names) {
|
|
387
|
+
if (typeof name !== "string" || !JSON_SCHEMA_TYPES.has(name)) {
|
|
388
|
+
throw badSchema(
|
|
389
|
+
`xAI structured output takes standard JSON Schema; \`type\` ${JSON.stringify(
|
|
390
|
+
name
|
|
391
|
+
)} at \`${at}\` is not a JSON Schema type. Use lowercase string, number, integer, boolean, object, array or null.`
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const child = (segment) => path.length > 0 ? `${path}.${segment}` : segment;
|
|
397
|
+
for (const keyword of SCHEMA_MAP_KEYWORDS) {
|
|
398
|
+
const map = node[keyword];
|
|
399
|
+
if (!isPlainObject(map)) continue;
|
|
400
|
+
for (const [key, member] of Object.entries(map)) {
|
|
401
|
+
if (isPlainObject(member)) assertNode(member, child(`${keyword}.${key}`));
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
for (const keyword of SCHEMA_ARRAY_KEYWORDS) {
|
|
405
|
+
const members = node[keyword];
|
|
406
|
+
if (!Array.isArray(members)) continue;
|
|
407
|
+
members.forEach((member, index) => {
|
|
408
|
+
if (isPlainObject(member)) assertNode(member, child(`${keyword}[${index}]`));
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
for (const keyword of SINGLE_SCHEMA_KEYWORDS) {
|
|
412
|
+
const member = node[keyword];
|
|
413
|
+
if (isPlainObject(member)) assertNode(member, child(keyword));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function assertXaiOutputJsonSchema(schema) {
|
|
417
|
+
if (isPlainObject(schema)) assertNode(schema, "");
|
|
418
|
+
}
|
|
326
419
|
var xaiPricingVersion = "xai-2026-09-25";
|
|
327
420
|
var XAI_TOOL_RATE_MICRO_USD = {
|
|
328
421
|
web_search_calls: 5e3,
|
|
@@ -539,7 +632,14 @@ function mapPart(p) {
|
|
|
539
632
|
return core.assertNever(p);
|
|
540
633
|
}
|
|
541
634
|
}
|
|
542
|
-
var XAI_PROVIDER_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
635
|
+
var XAI_PROVIDER_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
636
|
+
"promptCacheKey",
|
|
637
|
+
"tools",
|
|
638
|
+
"parallelToolCalls",
|
|
639
|
+
"toolChoice",
|
|
640
|
+
"maxTurns"
|
|
641
|
+
]);
|
|
642
|
+
var XAI_SERVER_TOOL_CHOICES = /* @__PURE__ */ new Set(["auto", "required", "none"]);
|
|
543
643
|
function mapXaiProviderOptions(xaiOpts, model) {
|
|
544
644
|
if (xaiOpts === void 0) {
|
|
545
645
|
return {};
|
|
@@ -554,7 +654,7 @@ function mapXaiProviderOptions(xaiOpts, model) {
|
|
|
554
654
|
throw badXaiRequest(
|
|
555
655
|
`providerOptions.xai contains unsupported keys [${unknownKeys.join(
|
|
556
656
|
", "
|
|
557
|
-
)}] for model "${model}". Allowed keys: promptCacheKey, tools, parallelToolCalls.`
|
|
657
|
+
)}] for model "${model}". Allowed keys: promptCacheKey, tools, parallelToolCalls, toolChoice, maxTurns.`
|
|
558
658
|
);
|
|
559
659
|
}
|
|
560
660
|
const mapped = {};
|
|
@@ -577,6 +677,34 @@ function mapXaiProviderOptions(xaiOpts, model) {
|
|
|
577
677
|
}
|
|
578
678
|
mapped.parallelToolCalls = xaiOpts["parallelToolCalls"];
|
|
579
679
|
}
|
|
680
|
+
const toolChoice = xaiOpts["toolChoice"];
|
|
681
|
+
if (toolChoice !== void 0) {
|
|
682
|
+
if (typeof toolChoice !== "string" || !XAI_SERVER_TOOL_CHOICES.has(toolChoice)) {
|
|
683
|
+
throw badXaiRequest(
|
|
684
|
+
`providerOptions.xai.toolChoice must be "auto", "required" or "none" for model "${model}".`
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
if (mapped.tools === void 0 || mapped.tools.length === 0) {
|
|
688
|
+
throw badXaiRequest(
|
|
689
|
+
`providerOptions.xai.toolChoice requires a non-empty providerOptions.xai.tools for model "${model}".`
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
mapped.toolChoice = toolChoice;
|
|
693
|
+
}
|
|
694
|
+
const maxTurns = xaiOpts["maxTurns"];
|
|
695
|
+
if (maxTurns !== void 0) {
|
|
696
|
+
if (typeof maxTurns !== "number" || !Number.isInteger(maxTurns) || maxTurns < 1) {
|
|
697
|
+
throw badXaiRequest(
|
|
698
|
+
`providerOptions.xai.maxTurns must be an integer >= 1 for model "${model}".`
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
if (mapped.tools === void 0 || mapped.tools.length === 0) {
|
|
702
|
+
throw badXaiRequest(
|
|
703
|
+
`providerOptions.xai.maxTurns requires a non-empty providerOptions.xai.tools for model "${model}".`
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
mapped.maxTurns = maxTurns;
|
|
707
|
+
}
|
|
580
708
|
return mapped;
|
|
581
709
|
}
|
|
582
710
|
function parseXaiReplayState(value, model) {
|
|
@@ -946,6 +1074,7 @@ function xaiAdapter(opts) {
|
|
|
946
1074
|
const structuredOutputRequested = req.outputJsonSchema !== void 0;
|
|
947
1075
|
if (structuredOutputRequested) {
|
|
948
1076
|
const schema = req.outputJsonSchema;
|
|
1077
|
+
assertXaiOutputJsonSchema(schema);
|
|
949
1078
|
const name = isPlainRecord(schema) && typeof schema["title"] === "string" && schema["title"].length > 0 ? schema["title"] : "structured_output";
|
|
950
1079
|
params.text = {
|
|
951
1080
|
format: { type: "json_schema", name, schema, strict: true }
|
|
@@ -972,6 +1101,27 @@ function xaiAdapter(opts) {
|
|
|
972
1101
|
);
|
|
973
1102
|
}
|
|
974
1103
|
params.tools = searchTools;
|
|
1104
|
+
if (xaiProviderConfig.toolChoice !== void 0) {
|
|
1105
|
+
if (req.toolChoice !== void 0) {
|
|
1106
|
+
throw badXaiRequest(
|
|
1107
|
+
`providerOptions.xai.toolChoice and toolChoice cannot both be set for model "${model}"; xAI accepts one tool_choice per request.`
|
|
1108
|
+
);
|
|
1109
|
+
}
|
|
1110
|
+
if (req.tools !== void 0 && req.tools.length > 0) {
|
|
1111
|
+
throw badXaiRequest(
|
|
1112
|
+
`providerOptions.xai.toolChoice applies to the server-side search tools only and cannot be combined with function tools for model "${model}".`
|
|
1113
|
+
);
|
|
1114
|
+
}
|
|
1115
|
+
if (hasFileRef) {
|
|
1116
|
+
throw badXaiRequest(
|
|
1117
|
+
`providerOptions.xai.toolChoice cannot be combined with file attachments for model "${model}"; xAI's implicit attachment_search would count as the tool call.`
|
|
1118
|
+
);
|
|
1119
|
+
}
|
|
1120
|
+
params.tool_choice = xaiProviderConfig.toolChoice;
|
|
1121
|
+
}
|
|
1122
|
+
if (xaiProviderConfig.maxTurns !== void 0) {
|
|
1123
|
+
params.max_turns = xaiProviderConfig.maxTurns;
|
|
1124
|
+
}
|
|
975
1125
|
}
|
|
976
1126
|
if (req.tools !== void 0 && req.tools.length > 0) {
|
|
977
1127
|
if (req.modelDescriptor?.capabilities?.functionCalling !== true) {
|
|
@@ -1057,7 +1207,8 @@ function xaiAdapter(opts) {
|
|
|
1057
1207
|
const finishReason = mapFinishReason(response);
|
|
1058
1208
|
const expectedToolCounters = expectedServerToolCounters(
|
|
1059
1209
|
xaiProviderConfig.tools);
|
|
1060
|
-
|
|
1210
|
+
const noServerToolRan = response.usage["num_server_side_tools_used"] === 0 && response.usage["server_side_tool_usage_details"] === void 0;
|
|
1211
|
+
if ((expectedToolCounters.length > 0 || hasFileRef) && !noServerToolRan) {
|
|
1061
1212
|
usage.details["server_tools_requested"] = 1;
|
|
1062
1213
|
if (xaiProviderConfig.tools?.some((tool) => tool["type"] === "x_search") === true) {
|
|
1063
1214
|
usage.details["x_search_requested"] = 1;
|