@warlock.js/ai-xai 4.8.2 → 4.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/cjs/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  let _warlock_js_ai_openai = require("@warlock.js/ai-openai");
3
3
 
4
- //#region ../@warlock.js/ai-xai/src/known-models.ts
4
+ //#region ../ai-xai/src/known-models.ts
5
5
  /**
6
6
  * Capability inference for xAI Grok model ids.
7
7
  *
@@ -95,7 +95,7 @@ function inferReasoningCapability(modelId) {
95
95
  }
96
96
 
97
97
  //#endregion
98
- //#region ../@warlock.js/ai-xai/src/sdk.ts
98
+ //#region ../ai-xai/src/sdk.ts
99
99
  /**
100
100
  * The xAI OpenAI-compatible base URL. xAI exposes Chat Completions at
101
101
  * `POST /v1/chat/completions` on this host, so the whole adapter rides
package/cjs/index.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["OpenAISDK"],"sources":["../../../../../../@warlock.js/ai-xai/src/known-models.ts","../../../../../../@warlock.js/ai-xai/src/sdk.ts"],"sourcesContent":["/**\n * Capability inference for xAI Grok model ids.\n *\n * xAI speaks the OpenAI Chat Completions protocol, so the wire-level\n * adapter is `OpenAISDK`. But Grok model names (`grok-4`,\n * `grok-2-vision`, …) don't match OpenAI's `gpt-*` / `o*` prefixes, so\n * OpenAI's own inference lists would mis-classify every Grok model as\n * non-vision / non-reasoning. This module supplies xAI's OWN name lists\n * and the `XaiSDK` wrapper injects the resulting capability flags into\n * each `OpenAIModelConfig` before delegating, so the right capabilities\n * are set even though the names aren't OpenAI names.\n *\n * All lists are matched as a prefix so dated / `-latest` / `-fast`\n * variants (`grok-4-0709`, `grok-2-vision-latest`,\n * `grok-3-mini-beta`) are covered without enumerating every release\n * tag. Devs can always override per-model via\n * `xai.model({ name, vision: true | false, reasoning: true | false })`\n * — explicit config wins over inference in either direction.\n */\n\n/**\n * Model-name prefixes for Grok families that accept image input\n * (vision) on the OpenAI-compatible Chat Completions endpoint.\n *\n * - `grok-4` is natively multimodal (text + image input).\n * - `grok-2-vision` is the dedicated image-understanding Grok 2 model.\n *\n * Text-only families (`grok-3`, `grok-3-mini`, the base `grok-2`\n * text model) are intentionally excluded so passing an image\n * attachment to them surfaces a clear, agent-side capability error\n * rather than an opaque xAI 400.\n */\nexport const XAI_VISION_MODEL_PREFIXES = [\"grok-4\", \"grok-2-vision\"] as const;\n\n/**\n * Model-name prefixes for Grok families that expose internal reasoning\n * and accept reasoning controls (e.g. `reasoning_effort`) on the\n * OpenAI-compatible Chat Completions endpoint.\n *\n * - `grok-4` is a reasoning-first model (it always reasons).\n * - `grok-3-mini` is the \"think\" variant of Grok 3 and reasons; the\n * full-size `grok-3` does not, so it is deliberately NOT covered by\n * the `grok-3-mini` prefix.\n */\nexport const XAI_REASONING_MODEL_PREFIXES = [\"grok-4\", \"grok-3-mini\"] as const;\n\n/**\n * A convenience list of the current public Grok chat model ids, handy\n * for menus, validation, and docs. Not exhaustive of every dated alias\n * xAI publishes — pass any id through `xai.model({ name })`; the prefix\n * inference above handles dated / `-latest` variants.\n *\n * @example\n * XAI_CHAT_MODELS.includes(\"grok-4\"); // → true\n */\nexport const XAI_CHAT_MODELS = [\n \"grok-4\",\n \"grok-3\",\n \"grok-3-mini\",\n \"grok-2-vision\",\n \"grok-2\",\n] as const;\n\n/**\n * Infer whether a given Grok model id supports vision based on xAI's\n * known-prefix list. Unknown ids default to `false` so that passing an\n * image attachment to an unsupported model surfaces a clear,\n * agent-side capability error instead of an opaque xAI 400.\n *\n * @example\n * inferVisionCapability(\"grok-4\"); // → true\n * inferVisionCapability(\"grok-2-vision-latest\"); // → true\n * inferVisionCapability(\"grok-3\"); // → false\n * inferVisionCapability(\"grok-3-mini\"); // → false\n */\nexport function inferVisionCapability(modelId: string): boolean {\n const normalized = modelId.toLowerCase();\n\n return XAI_VISION_MODEL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n\n/**\n * Infer whether a given Grok model id is a reasoning model based on\n * xAI's known-prefix list. Unknown ids default to `false` so the\n * adapter never forwards an unsupported reasoning param to a\n * non-reasoning model.\n *\n * @example\n * inferReasoningCapability(\"grok-4\"); // → true\n * inferReasoningCapability(\"grok-3-mini\"); // → true\n * inferReasoningCapability(\"grok-3\"); // → false\n * inferReasoningCapability(\"grok-2-vision\"); // → false\n */\nexport function inferReasoningCapability(modelId: string): boolean {\n const normalized = modelId.toLowerCase();\n\n return XAI_REASONING_MODEL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n","import type {\n EmbedderContract,\n ImageModelContract,\n ModelContract,\n ModelPricing,\n SDKAdapterContract,\n} from \"@warlock.js/ai\";\nimport { OpenAISDK } from \"@warlock.js/ai-openai\";\nimport type {\n XaiEmbedderConfig,\n XaiImageConfig,\n XaiModelConfig,\n XaiSDKConfig,\n} from \"./config.type\";\nimport { inferReasoningCapability, inferVisionCapability } from \"./known-models\";\n\n/**\n * The xAI OpenAI-compatible base URL. xAI exposes Chat Completions at\n * `POST /v1/chat/completions` on this host, so the whole adapter rides\n * on the OpenAI wire protocol.\n */\nconst XAI_BASE_URL = \"https://api.x.ai/v1\";\n\n/**\n * The default `provider` label stamped on every model this SDK\n * produces. Surfaces on `ModelContract.provider`, `AgentReport.model`,\n * logs, and any provider-aware middleware.\n */\nconst XAI_PROVIDER = \"xai\";\n\n/**\n * xAI Grok-backed implementation of `SDKAdapterContract`.\n *\n * **Role.** The package entry point for xAI's Grok models. xAI speaks\n * the OpenAI Chat Completions protocol, so `XaiSDK` is a *thin wrapper*\n * over the already-battle-tested {@link OpenAISDK} from\n * `@warlock.js/ai-openai` — NOT a reimplementation. It constructs one\n * internal `OpenAISDK` pointed at xAI's `baseURL` and labeled\n * `provider: \"xai\"`, then delegates `model()` / `embedder()` /\n * `image()` / `count()` to it. Construct one SDK per account and reuse\n * it everywhere.\n *\n * **Responsibility.**\n * - Owns: the xAI defaults (`baseURL` → `https://api.x.ai/v1`,\n * `provider` → `\"xai\"`) and this provider's OWN capability inference.\n * Grok model names (`grok-4`, `grok-2-vision`, …) don't match\n * OpenAI's `gpt-*` / `o*` prefixes, so before delegating `model()`\n * the wrapper injects the `vision` / `reasoning` flags inferred from\n * xAI's name lists (see `known-models.ts`). Because explicit config\n * wins over OpenAI's inference inside `OpenAIModel`, the produced\n * `ModelContract` carries the correct Grok capabilities.\n * - Does NOT own: the wire protocol, request/response mapping,\n * streaming, tool-call accumulation, error wrapping, or pricing\n * resolution — all of that is the wrapped `OpenAISDK`'s job and is\n * reused verbatim.\n *\n * Modeled as a class (see §4.2 of code-style.md — \"long-lived state\n * across many calls\"): it holds one live `OpenAISDK` (which in turn\n * holds one live `OpenAI` client), fronted by FP usage like the other\n * adapters.\n *\n * @example\n * const xai = new XaiSDK({ apiKey: process.env.XAI_API_KEY! });\n * const model = xai.model({ name: \"grok-4\", temperature: 0.7 });\n * const myAgent = ai.agent({ model });\n *\n * @example\n * // Compose into an `ai.xai` namespace for ergonomic agent wiring.\n * const ai = { agent, tool, systemPrompt, xai: new XaiSDK({ apiKey }) };\n * const fast = ai.agent({ model: ai.xai.model({ name: \"grok-3-mini\" }) });\n */\nexport class XaiSDK implements SDKAdapterContract {\n /**\n * The wrapped OpenAI-compatible adapter doing the actual wire work.\n * Constructed once with xAI's `baseURL` + `provider` and the caller's\n * `apiKey` / client options, then reused for every produced model,\n * embedder, and image model.\n */\n private readonly openai: OpenAISDK;\n\n /**\n * Optional SDK-level pricing registry, kept so `model()` can resolve\n * a per-model entry while still applying this provider's default\n * capability inference. The wrapped `OpenAISDK` also resolves\n * pricing, but we surface it here for parity and to keep the default\n * baseURL/provider injection in one place.\n */\n private readonly pricing?: Record<string, ModelPricing>;\n\n public constructor(config: XaiSDKConfig) {\n const { baseURL, provider, ...rest } = config;\n\n // Inject xAI's defaults — `baseURL` → the xAI OpenAI-compatible\n // endpoint, `provider` → \"xai\" — while still letting the caller\n // override either (e.g. a corporate proxy or a relabeled gateway).\n this.openai = new OpenAISDK({\n ...rest,\n baseURL: baseURL ?? XAI_BASE_URL,\n provider: provider ?? XAI_PROVIDER,\n });\n\n this.pricing = config.pricing;\n }\n\n /**\n * Build a `ModelContract` for a Grok model. Delegates to the wrapped\n * `OpenAISDK.model()` after injecting this provider's OWN capability\n * inference: `vision` and `reasoning` are resolved from xAI's\n * name-prefix lists (see `known-models.ts`) unless the caller set them\n * explicitly. Because explicit config wins over OpenAI's inference\n * inside `OpenAIModel`, the returned model self-identifies as\n * `provider: \"xai\"` and carries Grok's real capabilities even though\n * the model name isn't an OpenAI name.\n *\n * Pricing resolution is left to the wrapped adapter: per-model\n * `config.pricing` wins, otherwise the SDK-level registry entry keyed\n * by `config.name`, otherwise `undefined` (no cost computed).\n *\n * @example\n * xai.model({ name: \"grok-4\" }); // vision + reasoning auto-true\n * xai.model({ name: \"grok-3-mini\" }); // reasoning auto-true, vision false\n */\n public model(config: XaiModelConfig): ModelContract {\n return this.openai.model({\n ...config,\n // xAI names don't match OpenAI's vision/reasoning prefixes, so we\n // resolve them here and pass explicit flags through — explicit\n // config always wins over the OpenAI adapter's own inference.\n vision: config.vision ?? inferVisionCapability(config.name),\n reasoning: config.reasoning ?? inferReasoningCapability(config.name),\n });\n }\n\n /**\n * Rough token-count estimate. Delegates straight to the wrapped\n * `OpenAISDK.count()` (the shared character-heuristic from the core\n * package — offline, good for budgeting/quota guards, not billing).\n */\n public async count(text: string, model?: string): Promise<number> {\n return this.openai.count(text, model);\n }\n\n /**\n * Build an `EmbedderContract` by delegating to the wrapped\n * `OpenAISDK.embedder()`.\n *\n * NOTE: xAI does not currently expose a public embeddings endpoint, so\n * this is wired for protocol parity but a call to `embed()` /\n * `embedMany()` will fail upstream. Point an embedder at a dedicated\n * embeddings provider (e.g. `@warlock.js/ai-openai`) for vectors.\n */\n public embedder(config: XaiEmbedderConfig): EmbedderContract {\n return this.openai.embedder(config);\n }\n\n /**\n * Build an `ImageModelContract` by delegating to the wrapped\n * `OpenAISDK.image()` for use with `ai.image({ model, prompt })`.\n * Pricing resolution mirrors `model()` (per-model `pricing` > SDK\n * registry > `undefined`).\n */\n public image(config: XaiImageConfig): ImageModelContract {\n return this.openai.image(config);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,4BAA4B,CAAC,UAAU,eAAe;;;;;;;;;;;AAYnE,MAAa,+BAA+B,CAAC,UAAU,aAAa;;;;;;;;;;AAWpE,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;AAcA,SAAgB,sBAAsB,SAA0B;CAC9D,MAAM,aAAa,QAAQ,YAAY;CAEvC,OAAO,0BAA0B,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC;AACjF;;;;;;;;;;;;;AAcA,SAAgB,yBAAyB,SAA0B;CACjE,MAAM,aAAa,QAAQ,YAAY;CAEvC,OAAO,6BAA6B,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC;AACpF;;;;;;;;;AC5EA,MAAM,eAAe;;;;;;AAOrB,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CrB,IAAa,SAAb,MAAkD;CAkBhD,AAAO,YAAY,QAAsB;EACvC,MAAM,EAAE,SAAS,UAAU,GAAG,SAAS;EAKvC,KAAK,SAAS,IAAIA,gCAAU;GAC1B,GAAG;GACH,SAAS,WAAW;GACpB,UAAU,YAAY;EACxB,CAAC;EAED,KAAK,UAAU,OAAO;CACxB;;;;;;;;;;;;;;;;;;;CAoBA,AAAO,MAAM,QAAuC;EAClD,OAAO,KAAK,OAAO,MAAM;GACvB,GAAG;GAIH,QAAQ,OAAO,UAAU,sBAAsB,OAAO,IAAI;GAC1D,WAAW,OAAO,aAAa,yBAAyB,OAAO,IAAI;EACrE,CAAC;CACH;;;;;;CAOA,MAAa,MAAM,MAAc,OAAiC;EAChE,OAAO,KAAK,OAAO,MAAM,MAAM,KAAK;CACtC;;;;;;;;;;CAWA,AAAO,SAAS,QAA6C;EAC3D,OAAO,KAAK,OAAO,SAAS,MAAM;CACpC;;;;;;;CAQA,AAAO,MAAM,QAA4C;EACvD,OAAO,KAAK,OAAO,MAAM,MAAM;CACjC;AACF"}
1
+ {"version":3,"file":"index.cjs","names":["OpenAISDK"],"sources":["../../../../../../ai-xai/src/known-models.ts","../../../../../../ai-xai/src/sdk.ts"],"sourcesContent":["/**\n * Capability inference for xAI Grok model ids.\n *\n * xAI speaks the OpenAI Chat Completions protocol, so the wire-level\n * adapter is `OpenAISDK`. But Grok model names (`grok-4`,\n * `grok-2-vision`, …) don't match OpenAI's `gpt-*` / `o*` prefixes, so\n * OpenAI's own inference lists would mis-classify every Grok model as\n * non-vision / non-reasoning. This module supplies xAI's OWN name lists\n * and the `XaiSDK` wrapper injects the resulting capability flags into\n * each `OpenAIModelConfig` before delegating, so the right capabilities\n * are set even though the names aren't OpenAI names.\n *\n * All lists are matched as a prefix so dated / `-latest` / `-fast`\n * variants (`grok-4-0709`, `grok-2-vision-latest`,\n * `grok-3-mini-beta`) are covered without enumerating every release\n * tag. Devs can always override per-model via\n * `xai.model({ name, vision: true | false, reasoning: true | false })`\n * — explicit config wins over inference in either direction.\n */\n\n/**\n * Model-name prefixes for Grok families that accept image input\n * (vision) on the OpenAI-compatible Chat Completions endpoint.\n *\n * - `grok-4` is natively multimodal (text + image input).\n * - `grok-2-vision` is the dedicated image-understanding Grok 2 model.\n *\n * Text-only families (`grok-3`, `grok-3-mini`, the base `grok-2`\n * text model) are intentionally excluded so passing an image\n * attachment to them surfaces a clear, agent-side capability error\n * rather than an opaque xAI 400.\n */\nexport const XAI_VISION_MODEL_PREFIXES = [\"grok-4\", \"grok-2-vision\"] as const;\n\n/**\n * Model-name prefixes for Grok families that expose internal reasoning\n * and accept reasoning controls (e.g. `reasoning_effort`) on the\n * OpenAI-compatible Chat Completions endpoint.\n *\n * - `grok-4` is a reasoning-first model (it always reasons).\n * - `grok-3-mini` is the \"think\" variant of Grok 3 and reasons; the\n * full-size `grok-3` does not, so it is deliberately NOT covered by\n * the `grok-3-mini` prefix.\n */\nexport const XAI_REASONING_MODEL_PREFIXES = [\"grok-4\", \"grok-3-mini\"] as const;\n\n/**\n * A convenience list of the current public Grok chat model ids, handy\n * for menus, validation, and docs. Not exhaustive of every dated alias\n * xAI publishes — pass any id through `xai.model({ name })`; the prefix\n * inference above handles dated / `-latest` variants.\n *\n * @example\n * XAI_CHAT_MODELS.includes(\"grok-4\"); // → true\n */\nexport const XAI_CHAT_MODELS = [\n \"grok-4\",\n \"grok-3\",\n \"grok-3-mini\",\n \"grok-2-vision\",\n \"grok-2\",\n] as const;\n\n/**\n * Infer whether a given Grok model id supports vision based on xAI's\n * known-prefix list. Unknown ids default to `false` so that passing an\n * image attachment to an unsupported model surfaces a clear,\n * agent-side capability error instead of an opaque xAI 400.\n *\n * @example\n * inferVisionCapability(\"grok-4\"); // → true\n * inferVisionCapability(\"grok-2-vision-latest\"); // → true\n * inferVisionCapability(\"grok-3\"); // → false\n * inferVisionCapability(\"grok-3-mini\"); // → false\n */\nexport function inferVisionCapability(modelId: string): boolean {\n const normalized = modelId.toLowerCase();\n\n return XAI_VISION_MODEL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n\n/**\n * Infer whether a given Grok model id is a reasoning model based on\n * xAI's known-prefix list. Unknown ids default to `false` so the\n * adapter never forwards an unsupported reasoning param to a\n * non-reasoning model.\n *\n * @example\n * inferReasoningCapability(\"grok-4\"); // → true\n * inferReasoningCapability(\"grok-3-mini\"); // → true\n * inferReasoningCapability(\"grok-3\"); // → false\n * inferReasoningCapability(\"grok-2-vision\"); // → false\n */\nexport function inferReasoningCapability(modelId: string): boolean {\n const normalized = modelId.toLowerCase();\n\n return XAI_REASONING_MODEL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n","import type {\n EmbedderContract,\n ImageModelContract,\n ModelContract,\n ModelPricing,\n SDKAdapterContract,\n} from \"@warlock.js/ai\";\nimport { OpenAISDK } from \"@warlock.js/ai-openai\";\nimport type {\n XaiEmbedderConfig,\n XaiImageConfig,\n XaiModelConfig,\n XaiSDKConfig,\n} from \"./config.type\";\nimport { inferReasoningCapability, inferVisionCapability } from \"./known-models\";\n\n/**\n * The xAI OpenAI-compatible base URL. xAI exposes Chat Completions at\n * `POST /v1/chat/completions` on this host, so the whole adapter rides\n * on the OpenAI wire protocol.\n */\nconst XAI_BASE_URL = \"https://api.x.ai/v1\";\n\n/**\n * The default `provider` label stamped on every model this SDK\n * produces. Surfaces on `ModelContract.provider`, `AgentReport.model`,\n * logs, and any provider-aware middleware.\n */\nconst XAI_PROVIDER = \"xai\";\n\n/**\n * xAI Grok-backed implementation of `SDKAdapterContract`.\n *\n * **Role.** The package entry point for xAI's Grok models. xAI speaks\n * the OpenAI Chat Completions protocol, so `XaiSDK` is a *thin wrapper*\n * over the already-battle-tested {@link OpenAISDK} from\n * `@warlock.js/ai-openai` — NOT a reimplementation. It constructs one\n * internal `OpenAISDK` pointed at xAI's `baseURL` and labeled\n * `provider: \"xai\"`, then delegates `model()` / `embedder()` /\n * `image()` / `count()` to it. Construct one SDK per account and reuse\n * it everywhere.\n *\n * **Responsibility.**\n * - Owns: the xAI defaults (`baseURL` → `https://api.x.ai/v1`,\n * `provider` → `\"xai\"`) and this provider's OWN capability inference.\n * Grok model names (`grok-4`, `grok-2-vision`, …) don't match\n * OpenAI's `gpt-*` / `o*` prefixes, so before delegating `model()`\n * the wrapper injects the `vision` / `reasoning` flags inferred from\n * xAI's name lists (see `known-models.ts`). Because explicit config\n * wins over OpenAI's inference inside `OpenAIModel`, the produced\n * `ModelContract` carries the correct Grok capabilities.\n * - Does NOT own: the wire protocol, request/response mapping,\n * streaming, tool-call accumulation, error wrapping, or pricing\n * resolution — all of that is the wrapped `OpenAISDK`'s job and is\n * reused verbatim.\n *\n * Modeled as a class (see §4.2 of code-style.md — \"long-lived state\n * across many calls\"): it holds one live `OpenAISDK` (which in turn\n * holds one live `OpenAI` client), fronted by FP usage like the other\n * adapters.\n *\n * @example\n * const xai = new XaiSDK({ apiKey: process.env.XAI_API_KEY! });\n * const model = xai.model({ name: \"grok-4\", temperature: 0.7 });\n * const myAgent = ai.agent({ model });\n *\n * @example\n * // Compose into an `ai.xai` namespace for ergonomic agent wiring.\n * const ai = { agent, tool, systemPrompt, xai: new XaiSDK({ apiKey }) };\n * const fast = ai.agent({ model: ai.xai.model({ name: \"grok-3-mini\" }) });\n */\nexport class XaiSDK implements SDKAdapterContract {\n /**\n * The wrapped OpenAI-compatible adapter doing the actual wire work.\n * Constructed once with xAI's `baseURL` + `provider` and the caller's\n * `apiKey` / client options, then reused for every produced model,\n * embedder, and image model.\n */\n private readonly openai: OpenAISDK;\n\n /**\n * Optional SDK-level pricing registry, kept so `model()` can resolve\n * a per-model entry while still applying this provider's default\n * capability inference. The wrapped `OpenAISDK` also resolves\n * pricing, but we surface it here for parity and to keep the default\n * baseURL/provider injection in one place.\n */\n private readonly pricing?: Record<string, ModelPricing>;\n\n public constructor(config: XaiSDKConfig) {\n const { baseURL, provider, ...rest } = config;\n\n // Inject xAI's defaults — `baseURL` → the xAI OpenAI-compatible\n // endpoint, `provider` → \"xai\" — while still letting the caller\n // override either (e.g. a corporate proxy or a relabeled gateway).\n this.openai = new OpenAISDK({\n ...rest,\n baseURL: baseURL ?? XAI_BASE_URL,\n provider: provider ?? XAI_PROVIDER,\n });\n\n this.pricing = config.pricing;\n }\n\n /**\n * Build a `ModelContract` for a Grok model. Delegates to the wrapped\n * `OpenAISDK.model()` after injecting this provider's OWN capability\n * inference: `vision` and `reasoning` are resolved from xAI's\n * name-prefix lists (see `known-models.ts`) unless the caller set them\n * explicitly. Because explicit config wins over OpenAI's inference\n * inside `OpenAIModel`, the returned model self-identifies as\n * `provider: \"xai\"` and carries Grok's real capabilities even though\n * the model name isn't an OpenAI name.\n *\n * Pricing resolution is left to the wrapped adapter: per-model\n * `config.pricing` wins, otherwise the SDK-level registry entry keyed\n * by `config.name`, otherwise `undefined` (no cost computed).\n *\n * @example\n * xai.model({ name: \"grok-4\" }); // vision + reasoning auto-true\n * xai.model({ name: \"grok-3-mini\" }); // reasoning auto-true, vision false\n */\n public model(config: XaiModelConfig): ModelContract {\n return this.openai.model({\n ...config,\n // xAI names don't match OpenAI's vision/reasoning prefixes, so we\n // resolve them here and pass explicit flags through — explicit\n // config always wins over the OpenAI adapter's own inference.\n vision: config.vision ?? inferVisionCapability(config.name),\n reasoning: config.reasoning ?? inferReasoningCapability(config.name),\n });\n }\n\n /**\n * Rough token-count estimate. Delegates straight to the wrapped\n * `OpenAISDK.count()` (the shared character-heuristic from the core\n * package — offline, good for budgeting/quota guards, not billing).\n */\n public async count(text: string, model?: string): Promise<number> {\n return this.openai.count(text, model);\n }\n\n /**\n * Build an `EmbedderContract` by delegating to the wrapped\n * `OpenAISDK.embedder()`.\n *\n * NOTE: xAI does not currently expose a public embeddings endpoint, so\n * this is wired for protocol parity but a call to `embed()` /\n * `embedMany()` will fail upstream. Point an embedder at a dedicated\n * embeddings provider (e.g. `@warlock.js/ai-openai`) for vectors.\n */\n public embedder(config: XaiEmbedderConfig): EmbedderContract {\n return this.openai.embedder(config);\n }\n\n /**\n * Build an `ImageModelContract` by delegating to the wrapped\n * `OpenAISDK.image()` for use with `ai.image({ model, prompt })`.\n * Pricing resolution mirrors `model()` (per-model `pricing` > SDK\n * registry > `undefined`).\n */\n public image(config: XaiImageConfig): ImageModelContract {\n return this.openai.image(config);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,4BAA4B,CAAC,UAAU,eAAe;;;;;;;;;;;AAYnE,MAAa,+BAA+B,CAAC,UAAU,aAAa;;;;;;;;;;AAWpE,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;AAcA,SAAgB,sBAAsB,SAA0B;CAC9D,MAAM,aAAa,QAAQ,YAAY;CAEvC,OAAO,0BAA0B,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC;AACjF;;;;;;;;;;;;;AAcA,SAAgB,yBAAyB,SAA0B;CACjE,MAAM,aAAa,QAAQ,YAAY;CAEvC,OAAO,6BAA6B,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC;AACpF;;;;;;;;;AC5EA,MAAM,eAAe;;;;;;AAOrB,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CrB,IAAa,SAAb,MAAkD;CAkBhD,AAAO,YAAY,QAAsB;EACvC,MAAM,EAAE,SAAS,UAAU,GAAG,SAAS;EAKvC,KAAK,SAAS,IAAIA,gCAAU;GAC1B,GAAG;GACH,SAAS,WAAW;GACpB,UAAU,YAAY;EACxB,CAAC;EAED,KAAK,UAAU,OAAO;CACxB;;;;;;;;;;;;;;;;;;;CAoBA,AAAO,MAAM,QAAuC;EAClD,OAAO,KAAK,OAAO,MAAM;GACvB,GAAG;GAIH,QAAQ,OAAO,UAAU,sBAAsB,OAAO,IAAI;GAC1D,WAAW,OAAO,aAAa,yBAAyB,OAAO,IAAI;EACrE,CAAC;CACH;;;;;;CAOA,MAAa,MAAM,MAAc,OAAiC;EAChE,OAAO,KAAK,OAAO,MAAM,MAAM,KAAK;CACtC;;;;;;;;;;CAWA,AAAO,SAAS,QAA6C;EAC3D,OAAO,KAAK,OAAO,SAAS,MAAM;CACpC;;;;;;;CAQA,AAAO,MAAM,QAA4C;EACvD,OAAO,KAAK,OAAO,MAAM,MAAM;CACjC;AACF"}
@@ -1,7 +1,7 @@
1
1
  import { OpenAISDKConfig } from "@warlock.js/ai-openai";
2
2
  import { EmbedderConfig, ImageModelConfig, ModelConfig } from "@warlock.js/ai";
3
3
 
4
- //#region ../@warlock.js/ai-xai/src/config.type.d.ts
4
+ //#region ../ai-xai/src/config.type.d.ts
5
5
  /**
6
6
  * Configuration for the xAI Grok SDK adapter.
7
7
  *
@@ -1 +1 @@
1
- {"version":3,"file":"config.type.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai-xai/src/config.type.ts"],"mappings":";;;;;;AAwCA;;;;AAA0C;AAkB1C;;;;;;;;;AAyBkB;AAelB;;;;AAA8C;AAa9C;;;;AAA6C;;;;;;KAvEjC,YAAA,GAAe,eAAe;;;;;;;;;;;;;;;;;KAkB9B,cAAA,GAAiB,WAAW;;;;;;;;EAQtC,MAAA;;;;;;;;;EASA,SAAA;;;;;;;;EAQA,gBAAA;AAAA;;;;;;;;;;;;;KAeU,iBAAA,GAAoB,cAAc;;;;;;;;;;;;KAalC,cAAA,GAAiB,gBAAgB"}
1
+ {"version":3,"file":"config.type.d.mts","names":[],"sources":["../../../../../../ai-xai/src/config.type.ts"],"mappings":";;;;;;AAwCA;;;;AAA0C;AAkB1C;;;;;;;;;AAyBkB;AAelB;;;;AAA8C;AAa9C;;;;AAA6C;;;;;;KAvEjC,YAAA,GAAe,eAAe;;;;;;;;;;;;;;;;;KAkB9B,cAAA,GAAiB,WAAW;;;;;;;;EAQtC,MAAA;;;;;;;;;EASA,SAAA;;;;;;;;EAQA,gBAAA;AAAA;;;;;;;;;;;;;KAeU,iBAAA,GAAoB,cAAc;;;;;;;;;;;;KAalC,cAAA,GAAiB,gBAAgB"}
@@ -1,4 +1,4 @@
1
- //#region ../@warlock.js/ai-xai/src/known-models.d.ts
1
+ //#region ../ai-xai/src/known-models.d.ts
2
2
  /**
3
3
  * Capability inference for xAI Grok model ids.
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"known-models.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai-xai/src/known-models.ts"],"mappings":";;AAgCA;;;;AAA6E;AAY7E;;;;AAA8E;AAW9E;;;;AAMU;AAcV;;;;AAAqD;AAkBrD;;;;AAAwD;;;;;;cA7D3C,yBAAA;;;;;;;;;;;cAYA,4BAAA;;;;;;;;;;cAWA,eAAA;;;;;;;;;;;;;iBAoBG,qBAAA,CAAsB,OAAe;;;;;;;;;;;;;iBAkBrC,wBAAA,CAAyB,OAAe"}
1
+ {"version":3,"file":"known-models.d.mts","names":[],"sources":["../../../../../../ai-xai/src/known-models.ts"],"mappings":";;AAgCA;;;;AAA6E;AAY7E;;;;AAA8E;AAW9E;;;;AAMU;AAcV;;;;AAAqD;AAkBrD;;;;AAAwD;;;;;;cA7D3C,yBAAA;;;;;;;;;;;cAYA,4BAAA;;;;;;;;;;cAWA,eAAA;;;;;;;;;;;;;iBAoBG,qBAAA,CAAsB,OAAe;;;;;;;;;;;;;iBAkBrC,wBAAA,CAAyB,OAAe"}
@@ -1,4 +1,4 @@
1
- //#region ../@warlock.js/ai-xai/src/known-models.ts
1
+ //#region ../ai-xai/src/known-models.ts
2
2
  /**
3
3
  * Capability inference for xAI Grok model ids.
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"known-models.mjs","names":[],"sources":["../../../../../../@warlock.js/ai-xai/src/known-models.ts"],"sourcesContent":["/**\n * Capability inference for xAI Grok model ids.\n *\n * xAI speaks the OpenAI Chat Completions protocol, so the wire-level\n * adapter is `OpenAISDK`. But Grok model names (`grok-4`,\n * `grok-2-vision`, …) don't match OpenAI's `gpt-*` / `o*` prefixes, so\n * OpenAI's own inference lists would mis-classify every Grok model as\n * non-vision / non-reasoning. This module supplies xAI's OWN name lists\n * and the `XaiSDK` wrapper injects the resulting capability flags into\n * each `OpenAIModelConfig` before delegating, so the right capabilities\n * are set even though the names aren't OpenAI names.\n *\n * All lists are matched as a prefix so dated / `-latest` / `-fast`\n * variants (`grok-4-0709`, `grok-2-vision-latest`,\n * `grok-3-mini-beta`) are covered without enumerating every release\n * tag. Devs can always override per-model via\n * `xai.model({ name, vision: true | false, reasoning: true | false })`\n * — explicit config wins over inference in either direction.\n */\n\n/**\n * Model-name prefixes for Grok families that accept image input\n * (vision) on the OpenAI-compatible Chat Completions endpoint.\n *\n * - `grok-4` is natively multimodal (text + image input).\n * - `grok-2-vision` is the dedicated image-understanding Grok 2 model.\n *\n * Text-only families (`grok-3`, `grok-3-mini`, the base `grok-2`\n * text model) are intentionally excluded so passing an image\n * attachment to them surfaces a clear, agent-side capability error\n * rather than an opaque xAI 400.\n */\nexport const XAI_VISION_MODEL_PREFIXES = [\"grok-4\", \"grok-2-vision\"] as const;\n\n/**\n * Model-name prefixes for Grok families that expose internal reasoning\n * and accept reasoning controls (e.g. `reasoning_effort`) on the\n * OpenAI-compatible Chat Completions endpoint.\n *\n * - `grok-4` is a reasoning-first model (it always reasons).\n * - `grok-3-mini` is the \"think\" variant of Grok 3 and reasons; the\n * full-size `grok-3` does not, so it is deliberately NOT covered by\n * the `grok-3-mini` prefix.\n */\nexport const XAI_REASONING_MODEL_PREFIXES = [\"grok-4\", \"grok-3-mini\"] as const;\n\n/**\n * A convenience list of the current public Grok chat model ids, handy\n * for menus, validation, and docs. Not exhaustive of every dated alias\n * xAI publishes — pass any id through `xai.model({ name })`; the prefix\n * inference above handles dated / `-latest` variants.\n *\n * @example\n * XAI_CHAT_MODELS.includes(\"grok-4\"); // → true\n */\nexport const XAI_CHAT_MODELS = [\n \"grok-4\",\n \"grok-3\",\n \"grok-3-mini\",\n \"grok-2-vision\",\n \"grok-2\",\n] as const;\n\n/**\n * Infer whether a given Grok model id supports vision based on xAI's\n * known-prefix list. Unknown ids default to `false` so that passing an\n * image attachment to an unsupported model surfaces a clear,\n * agent-side capability error instead of an opaque xAI 400.\n *\n * @example\n * inferVisionCapability(\"grok-4\"); // → true\n * inferVisionCapability(\"grok-2-vision-latest\"); // → true\n * inferVisionCapability(\"grok-3\"); // → false\n * inferVisionCapability(\"grok-3-mini\"); // → false\n */\nexport function inferVisionCapability(modelId: string): boolean {\n const normalized = modelId.toLowerCase();\n\n return XAI_VISION_MODEL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n\n/**\n * Infer whether a given Grok model id is a reasoning model based on\n * xAI's known-prefix list. Unknown ids default to `false` so the\n * adapter never forwards an unsupported reasoning param to a\n * non-reasoning model.\n *\n * @example\n * inferReasoningCapability(\"grok-4\"); // → true\n * inferReasoningCapability(\"grok-3-mini\"); // → true\n * inferReasoningCapability(\"grok-3\"); // → false\n * inferReasoningCapability(\"grok-2-vision\"); // → false\n */\nexport function inferReasoningCapability(modelId: string): boolean {\n const normalized = modelId.toLowerCase();\n\n return XAI_REASONING_MODEL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,4BAA4B,CAAC,UAAU,eAAe;;;;;;;;;;;AAYnE,MAAa,+BAA+B,CAAC,UAAU,aAAa;;;;;;;;;;AAWpE,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;AAcA,SAAgB,sBAAsB,SAA0B;CAC9D,MAAM,aAAa,QAAQ,YAAY;CAEvC,OAAO,0BAA0B,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC;AACjF;;;;;;;;;;;;;AAcA,SAAgB,yBAAyB,SAA0B;CACjE,MAAM,aAAa,QAAQ,YAAY;CAEvC,OAAO,6BAA6B,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC;AACpF"}
1
+ {"version":3,"file":"known-models.mjs","names":[],"sources":["../../../../../../ai-xai/src/known-models.ts"],"sourcesContent":["/**\n * Capability inference for xAI Grok model ids.\n *\n * xAI speaks the OpenAI Chat Completions protocol, so the wire-level\n * adapter is `OpenAISDK`. But Grok model names (`grok-4`,\n * `grok-2-vision`, …) don't match OpenAI's `gpt-*` / `o*` prefixes, so\n * OpenAI's own inference lists would mis-classify every Grok model as\n * non-vision / non-reasoning. This module supplies xAI's OWN name lists\n * and the `XaiSDK` wrapper injects the resulting capability flags into\n * each `OpenAIModelConfig` before delegating, so the right capabilities\n * are set even though the names aren't OpenAI names.\n *\n * All lists are matched as a prefix so dated / `-latest` / `-fast`\n * variants (`grok-4-0709`, `grok-2-vision-latest`,\n * `grok-3-mini-beta`) are covered without enumerating every release\n * tag. Devs can always override per-model via\n * `xai.model({ name, vision: true | false, reasoning: true | false })`\n * — explicit config wins over inference in either direction.\n */\n\n/**\n * Model-name prefixes for Grok families that accept image input\n * (vision) on the OpenAI-compatible Chat Completions endpoint.\n *\n * - `grok-4` is natively multimodal (text + image input).\n * - `grok-2-vision` is the dedicated image-understanding Grok 2 model.\n *\n * Text-only families (`grok-3`, `grok-3-mini`, the base `grok-2`\n * text model) are intentionally excluded so passing an image\n * attachment to them surfaces a clear, agent-side capability error\n * rather than an opaque xAI 400.\n */\nexport const XAI_VISION_MODEL_PREFIXES = [\"grok-4\", \"grok-2-vision\"] as const;\n\n/**\n * Model-name prefixes for Grok families that expose internal reasoning\n * and accept reasoning controls (e.g. `reasoning_effort`) on the\n * OpenAI-compatible Chat Completions endpoint.\n *\n * - `grok-4` is a reasoning-first model (it always reasons).\n * - `grok-3-mini` is the \"think\" variant of Grok 3 and reasons; the\n * full-size `grok-3` does not, so it is deliberately NOT covered by\n * the `grok-3-mini` prefix.\n */\nexport const XAI_REASONING_MODEL_PREFIXES = [\"grok-4\", \"grok-3-mini\"] as const;\n\n/**\n * A convenience list of the current public Grok chat model ids, handy\n * for menus, validation, and docs. Not exhaustive of every dated alias\n * xAI publishes — pass any id through `xai.model({ name })`; the prefix\n * inference above handles dated / `-latest` variants.\n *\n * @example\n * XAI_CHAT_MODELS.includes(\"grok-4\"); // → true\n */\nexport const XAI_CHAT_MODELS = [\n \"grok-4\",\n \"grok-3\",\n \"grok-3-mini\",\n \"grok-2-vision\",\n \"grok-2\",\n] as const;\n\n/**\n * Infer whether a given Grok model id supports vision based on xAI's\n * known-prefix list. Unknown ids default to `false` so that passing an\n * image attachment to an unsupported model surfaces a clear,\n * agent-side capability error instead of an opaque xAI 400.\n *\n * @example\n * inferVisionCapability(\"grok-4\"); // → true\n * inferVisionCapability(\"grok-2-vision-latest\"); // → true\n * inferVisionCapability(\"grok-3\"); // → false\n * inferVisionCapability(\"grok-3-mini\"); // → false\n */\nexport function inferVisionCapability(modelId: string): boolean {\n const normalized = modelId.toLowerCase();\n\n return XAI_VISION_MODEL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n\n/**\n * Infer whether a given Grok model id is a reasoning model based on\n * xAI's known-prefix list. Unknown ids default to `false` so the\n * adapter never forwards an unsupported reasoning param to a\n * non-reasoning model.\n *\n * @example\n * inferReasoningCapability(\"grok-4\"); // → true\n * inferReasoningCapability(\"grok-3-mini\"); // → true\n * inferReasoningCapability(\"grok-3\"); // → false\n * inferReasoningCapability(\"grok-2-vision\"); // → false\n */\nexport function inferReasoningCapability(modelId: string): boolean {\n const normalized = modelId.toLowerCase();\n\n return XAI_REASONING_MODEL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,4BAA4B,CAAC,UAAU,eAAe;;;;;;;;;;;AAYnE,MAAa,+BAA+B,CAAC,UAAU,aAAa;;;;;;;;;;AAWpE,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;AAcA,SAAgB,sBAAsB,SAA0B;CAC9D,MAAM,aAAa,QAAQ,YAAY;CAEvC,OAAO,0BAA0B,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC;AACjF;;;;;;;;;;;;;AAcA,SAAgB,yBAAyB,SAA0B;CACjE,MAAM,aAAa,QAAQ,YAAY;CAEvC,OAAO,6BAA6B,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC;AACpF"}
package/esm/sdk.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { XaiEmbedderConfig, XaiImageConfig, XaiModelConfig, XaiSDKConfig } from "./config.type.mjs";
2
2
  import { EmbedderContract, ImageModelContract, ModelContract, SDKAdapterContract } from "@warlock.js/ai";
3
3
 
4
- //#region ../@warlock.js/ai-xai/src/sdk.d.ts
4
+ //#region ../ai-xai/src/sdk.d.ts
5
5
  /**
6
6
  * xAI Grok-backed implementation of `SDKAdapterContract`.
7
7
  *
package/esm/sdk.d.mts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai-xai/src/sdk.ts"],"mappings":";;;;;;AAuEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0F0D;;cA1F7C,MAAA,YAAkB,kBAAA;;;;;;;mBAOZ,MAAA;;;;;;;;mBASA,OAAA;cAEE,MAAA,EAAQ,YAAA;;;;;;;;;;;;;;;;;;;EAiCpB,KAAA,CAAM,MAAA,EAAQ,cAAA,GAAiB,aAAA;;;;;;EAgBzB,KAAA,CAAM,IAAA,UAAc,KAAA,YAAiB,OAAA;;;;;;;;;;EAa3C,QAAA,CAAS,MAAA,EAAQ,iBAAA,GAAoB,gBAAA;;;;;;;EAUrC,KAAA,CAAM,MAAA,EAAQ,cAAA,GAAiB,kBAAA;AAAA"}
1
+ {"version":3,"file":"sdk.d.mts","names":[],"sources":["../../../../../../ai-xai/src/sdk.ts"],"mappings":";;;;;;AAuEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0F0D;;cA1F7C,MAAA,YAAkB,kBAAA;;;;;;;mBAOZ,MAAA;;;;;;;;mBASA,OAAA;cAEE,MAAA,EAAQ,YAAA;;;;;;;;;;;;;;;;;;;EAiCpB,KAAA,CAAM,MAAA,EAAQ,cAAA,GAAiB,aAAA;;;;;;EAgBzB,KAAA,CAAM,IAAA,UAAc,KAAA,YAAiB,OAAA;;;;;;;;;;EAa3C,QAAA,CAAS,MAAA,EAAQ,iBAAA,GAAoB,gBAAA;;;;;;;EAUrC,KAAA,CAAM,MAAA,EAAQ,cAAA,GAAiB,kBAAA;AAAA"}
package/esm/sdk.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { inferReasoningCapability, inferVisionCapability } from "./known-models.mjs";
2
2
  import { OpenAISDK } from "@warlock.js/ai-openai";
3
3
 
4
- //#region ../@warlock.js/ai-xai/src/sdk.ts
4
+ //#region ../ai-xai/src/sdk.ts
5
5
  /**
6
6
  * The xAI OpenAI-compatible base URL. xAI exposes Chat Completions at
7
7
  * `POST /v1/chat/completions` on this host, so the whole adapter rides
package/esm/sdk.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.mjs","names":[],"sources":["../../../../../../@warlock.js/ai-xai/src/sdk.ts"],"sourcesContent":["import type {\n EmbedderContract,\n ImageModelContract,\n ModelContract,\n ModelPricing,\n SDKAdapterContract,\n} from \"@warlock.js/ai\";\nimport { OpenAISDK } from \"@warlock.js/ai-openai\";\nimport type {\n XaiEmbedderConfig,\n XaiImageConfig,\n XaiModelConfig,\n XaiSDKConfig,\n} from \"./config.type\";\nimport { inferReasoningCapability, inferVisionCapability } from \"./known-models\";\n\n/**\n * The xAI OpenAI-compatible base URL. xAI exposes Chat Completions at\n * `POST /v1/chat/completions` on this host, so the whole adapter rides\n * on the OpenAI wire protocol.\n */\nconst XAI_BASE_URL = \"https://api.x.ai/v1\";\n\n/**\n * The default `provider` label stamped on every model this SDK\n * produces. Surfaces on `ModelContract.provider`, `AgentReport.model`,\n * logs, and any provider-aware middleware.\n */\nconst XAI_PROVIDER = \"xai\";\n\n/**\n * xAI Grok-backed implementation of `SDKAdapterContract`.\n *\n * **Role.** The package entry point for xAI's Grok models. xAI speaks\n * the OpenAI Chat Completions protocol, so `XaiSDK` is a *thin wrapper*\n * over the already-battle-tested {@link OpenAISDK} from\n * `@warlock.js/ai-openai` — NOT a reimplementation. It constructs one\n * internal `OpenAISDK` pointed at xAI's `baseURL` and labeled\n * `provider: \"xai\"`, then delegates `model()` / `embedder()` /\n * `image()` / `count()` to it. Construct one SDK per account and reuse\n * it everywhere.\n *\n * **Responsibility.**\n * - Owns: the xAI defaults (`baseURL` → `https://api.x.ai/v1`,\n * `provider` → `\"xai\"`) and this provider's OWN capability inference.\n * Grok model names (`grok-4`, `grok-2-vision`, …) don't match\n * OpenAI's `gpt-*` / `o*` prefixes, so before delegating `model()`\n * the wrapper injects the `vision` / `reasoning` flags inferred from\n * xAI's name lists (see `known-models.ts`). Because explicit config\n * wins over OpenAI's inference inside `OpenAIModel`, the produced\n * `ModelContract` carries the correct Grok capabilities.\n * - Does NOT own: the wire protocol, request/response mapping,\n * streaming, tool-call accumulation, error wrapping, or pricing\n * resolution — all of that is the wrapped `OpenAISDK`'s job and is\n * reused verbatim.\n *\n * Modeled as a class (see §4.2 of code-style.md — \"long-lived state\n * across many calls\"): it holds one live `OpenAISDK` (which in turn\n * holds one live `OpenAI` client), fronted by FP usage like the other\n * adapters.\n *\n * @example\n * const xai = new XaiSDK({ apiKey: process.env.XAI_API_KEY! });\n * const model = xai.model({ name: \"grok-4\", temperature: 0.7 });\n * const myAgent = ai.agent({ model });\n *\n * @example\n * // Compose into an `ai.xai` namespace for ergonomic agent wiring.\n * const ai = { agent, tool, systemPrompt, xai: new XaiSDK({ apiKey }) };\n * const fast = ai.agent({ model: ai.xai.model({ name: \"grok-3-mini\" }) });\n */\nexport class XaiSDK implements SDKAdapterContract {\n /**\n * The wrapped OpenAI-compatible adapter doing the actual wire work.\n * Constructed once with xAI's `baseURL` + `provider` and the caller's\n * `apiKey` / client options, then reused for every produced model,\n * embedder, and image model.\n */\n private readonly openai: OpenAISDK;\n\n /**\n * Optional SDK-level pricing registry, kept so `model()` can resolve\n * a per-model entry while still applying this provider's default\n * capability inference. The wrapped `OpenAISDK` also resolves\n * pricing, but we surface it here for parity and to keep the default\n * baseURL/provider injection in one place.\n */\n private readonly pricing?: Record<string, ModelPricing>;\n\n public constructor(config: XaiSDKConfig) {\n const { baseURL, provider, ...rest } = config;\n\n // Inject xAI's defaults — `baseURL` → the xAI OpenAI-compatible\n // endpoint, `provider` → \"xai\" — while still letting the caller\n // override either (e.g. a corporate proxy or a relabeled gateway).\n this.openai = new OpenAISDK({\n ...rest,\n baseURL: baseURL ?? XAI_BASE_URL,\n provider: provider ?? XAI_PROVIDER,\n });\n\n this.pricing = config.pricing;\n }\n\n /**\n * Build a `ModelContract` for a Grok model. Delegates to the wrapped\n * `OpenAISDK.model()` after injecting this provider's OWN capability\n * inference: `vision` and `reasoning` are resolved from xAI's\n * name-prefix lists (see `known-models.ts`) unless the caller set them\n * explicitly. Because explicit config wins over OpenAI's inference\n * inside `OpenAIModel`, the returned model self-identifies as\n * `provider: \"xai\"` and carries Grok's real capabilities even though\n * the model name isn't an OpenAI name.\n *\n * Pricing resolution is left to the wrapped adapter: per-model\n * `config.pricing` wins, otherwise the SDK-level registry entry keyed\n * by `config.name`, otherwise `undefined` (no cost computed).\n *\n * @example\n * xai.model({ name: \"grok-4\" }); // vision + reasoning auto-true\n * xai.model({ name: \"grok-3-mini\" }); // reasoning auto-true, vision false\n */\n public model(config: XaiModelConfig): ModelContract {\n return this.openai.model({\n ...config,\n // xAI names don't match OpenAI's vision/reasoning prefixes, so we\n // resolve them here and pass explicit flags through — explicit\n // config always wins over the OpenAI adapter's own inference.\n vision: config.vision ?? inferVisionCapability(config.name),\n reasoning: config.reasoning ?? inferReasoningCapability(config.name),\n });\n }\n\n /**\n * Rough token-count estimate. Delegates straight to the wrapped\n * `OpenAISDK.count()` (the shared character-heuristic from the core\n * package — offline, good for budgeting/quota guards, not billing).\n */\n public async count(text: string, model?: string): Promise<number> {\n return this.openai.count(text, model);\n }\n\n /**\n * Build an `EmbedderContract` by delegating to the wrapped\n * `OpenAISDK.embedder()`.\n *\n * NOTE: xAI does not currently expose a public embeddings endpoint, so\n * this is wired for protocol parity but a call to `embed()` /\n * `embedMany()` will fail upstream. Point an embedder at a dedicated\n * embeddings provider (e.g. `@warlock.js/ai-openai`) for vectors.\n */\n public embedder(config: XaiEmbedderConfig): EmbedderContract {\n return this.openai.embedder(config);\n }\n\n /**\n * Build an `ImageModelContract` by delegating to the wrapped\n * `OpenAISDK.image()` for use with `ai.image({ model, prompt })`.\n * Pricing resolution mirrors `model()` (per-model `pricing` > SDK\n * registry > `undefined`).\n */\n public image(config: XaiImageConfig): ImageModelContract {\n return this.openai.image(config);\n }\n}\n"],"mappings":";;;;;;;;;AAqBA,MAAM,eAAe;;;;;;AAOrB,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CrB,IAAa,SAAb,MAAkD;CAkBhD,AAAO,YAAY,QAAsB;EACvC,MAAM,EAAE,SAAS,UAAU,GAAG,SAAS;EAKvC,KAAK,SAAS,IAAI,UAAU;GAC1B,GAAG;GACH,SAAS,WAAW;GACpB,UAAU,YAAY;EACxB,CAAC;EAED,KAAK,UAAU,OAAO;CACxB;;;;;;;;;;;;;;;;;;;CAoBA,AAAO,MAAM,QAAuC;EAClD,OAAO,KAAK,OAAO,MAAM;GACvB,GAAG;GAIH,QAAQ,OAAO,UAAU,sBAAsB,OAAO,IAAI;GAC1D,WAAW,OAAO,aAAa,yBAAyB,OAAO,IAAI;EACrE,CAAC;CACH;;;;;;CAOA,MAAa,MAAM,MAAc,OAAiC;EAChE,OAAO,KAAK,OAAO,MAAM,MAAM,KAAK;CACtC;;;;;;;;;;CAWA,AAAO,SAAS,QAA6C;EAC3D,OAAO,KAAK,OAAO,SAAS,MAAM;CACpC;;;;;;;CAQA,AAAO,MAAM,QAA4C;EACvD,OAAO,KAAK,OAAO,MAAM,MAAM;CACjC;AACF"}
1
+ {"version":3,"file":"sdk.mjs","names":[],"sources":["../../../../../../ai-xai/src/sdk.ts"],"sourcesContent":["import type {\n EmbedderContract,\n ImageModelContract,\n ModelContract,\n ModelPricing,\n SDKAdapterContract,\n} from \"@warlock.js/ai\";\nimport { OpenAISDK } from \"@warlock.js/ai-openai\";\nimport type {\n XaiEmbedderConfig,\n XaiImageConfig,\n XaiModelConfig,\n XaiSDKConfig,\n} from \"./config.type\";\nimport { inferReasoningCapability, inferVisionCapability } from \"./known-models\";\n\n/**\n * The xAI OpenAI-compatible base URL. xAI exposes Chat Completions at\n * `POST /v1/chat/completions` on this host, so the whole adapter rides\n * on the OpenAI wire protocol.\n */\nconst XAI_BASE_URL = \"https://api.x.ai/v1\";\n\n/**\n * The default `provider` label stamped on every model this SDK\n * produces. Surfaces on `ModelContract.provider`, `AgentReport.model`,\n * logs, and any provider-aware middleware.\n */\nconst XAI_PROVIDER = \"xai\";\n\n/**\n * xAI Grok-backed implementation of `SDKAdapterContract`.\n *\n * **Role.** The package entry point for xAI's Grok models. xAI speaks\n * the OpenAI Chat Completions protocol, so `XaiSDK` is a *thin wrapper*\n * over the already-battle-tested {@link OpenAISDK} from\n * `@warlock.js/ai-openai` — NOT a reimplementation. It constructs one\n * internal `OpenAISDK` pointed at xAI's `baseURL` and labeled\n * `provider: \"xai\"`, then delegates `model()` / `embedder()` /\n * `image()` / `count()` to it. Construct one SDK per account and reuse\n * it everywhere.\n *\n * **Responsibility.**\n * - Owns: the xAI defaults (`baseURL` → `https://api.x.ai/v1`,\n * `provider` → `\"xai\"`) and this provider's OWN capability inference.\n * Grok model names (`grok-4`, `grok-2-vision`, …) don't match\n * OpenAI's `gpt-*` / `o*` prefixes, so before delegating `model()`\n * the wrapper injects the `vision` / `reasoning` flags inferred from\n * xAI's name lists (see `known-models.ts`). Because explicit config\n * wins over OpenAI's inference inside `OpenAIModel`, the produced\n * `ModelContract` carries the correct Grok capabilities.\n * - Does NOT own: the wire protocol, request/response mapping,\n * streaming, tool-call accumulation, error wrapping, or pricing\n * resolution — all of that is the wrapped `OpenAISDK`'s job and is\n * reused verbatim.\n *\n * Modeled as a class (see §4.2 of code-style.md — \"long-lived state\n * across many calls\"): it holds one live `OpenAISDK` (which in turn\n * holds one live `OpenAI` client), fronted by FP usage like the other\n * adapters.\n *\n * @example\n * const xai = new XaiSDK({ apiKey: process.env.XAI_API_KEY! });\n * const model = xai.model({ name: \"grok-4\", temperature: 0.7 });\n * const myAgent = ai.agent({ model });\n *\n * @example\n * // Compose into an `ai.xai` namespace for ergonomic agent wiring.\n * const ai = { agent, tool, systemPrompt, xai: new XaiSDK({ apiKey }) };\n * const fast = ai.agent({ model: ai.xai.model({ name: \"grok-3-mini\" }) });\n */\nexport class XaiSDK implements SDKAdapterContract {\n /**\n * The wrapped OpenAI-compatible adapter doing the actual wire work.\n * Constructed once with xAI's `baseURL` + `provider` and the caller's\n * `apiKey` / client options, then reused for every produced model,\n * embedder, and image model.\n */\n private readonly openai: OpenAISDK;\n\n /**\n * Optional SDK-level pricing registry, kept so `model()` can resolve\n * a per-model entry while still applying this provider's default\n * capability inference. The wrapped `OpenAISDK` also resolves\n * pricing, but we surface it here for parity and to keep the default\n * baseURL/provider injection in one place.\n */\n private readonly pricing?: Record<string, ModelPricing>;\n\n public constructor(config: XaiSDKConfig) {\n const { baseURL, provider, ...rest } = config;\n\n // Inject xAI's defaults — `baseURL` → the xAI OpenAI-compatible\n // endpoint, `provider` → \"xai\" — while still letting the caller\n // override either (e.g. a corporate proxy or a relabeled gateway).\n this.openai = new OpenAISDK({\n ...rest,\n baseURL: baseURL ?? XAI_BASE_URL,\n provider: provider ?? XAI_PROVIDER,\n });\n\n this.pricing = config.pricing;\n }\n\n /**\n * Build a `ModelContract` for a Grok model. Delegates to the wrapped\n * `OpenAISDK.model()` after injecting this provider's OWN capability\n * inference: `vision` and `reasoning` are resolved from xAI's\n * name-prefix lists (see `known-models.ts`) unless the caller set them\n * explicitly. Because explicit config wins over OpenAI's inference\n * inside `OpenAIModel`, the returned model self-identifies as\n * `provider: \"xai\"` and carries Grok's real capabilities even though\n * the model name isn't an OpenAI name.\n *\n * Pricing resolution is left to the wrapped adapter: per-model\n * `config.pricing` wins, otherwise the SDK-level registry entry keyed\n * by `config.name`, otherwise `undefined` (no cost computed).\n *\n * @example\n * xai.model({ name: \"grok-4\" }); // vision + reasoning auto-true\n * xai.model({ name: \"grok-3-mini\" }); // reasoning auto-true, vision false\n */\n public model(config: XaiModelConfig): ModelContract {\n return this.openai.model({\n ...config,\n // xAI names don't match OpenAI's vision/reasoning prefixes, so we\n // resolve them here and pass explicit flags through — explicit\n // config always wins over the OpenAI adapter's own inference.\n vision: config.vision ?? inferVisionCapability(config.name),\n reasoning: config.reasoning ?? inferReasoningCapability(config.name),\n });\n }\n\n /**\n * Rough token-count estimate. Delegates straight to the wrapped\n * `OpenAISDK.count()` (the shared character-heuristic from the core\n * package — offline, good for budgeting/quota guards, not billing).\n */\n public async count(text: string, model?: string): Promise<number> {\n return this.openai.count(text, model);\n }\n\n /**\n * Build an `EmbedderContract` by delegating to the wrapped\n * `OpenAISDK.embedder()`.\n *\n * NOTE: xAI does not currently expose a public embeddings endpoint, so\n * this is wired for protocol parity but a call to `embed()` /\n * `embedMany()` will fail upstream. Point an embedder at a dedicated\n * embeddings provider (e.g. `@warlock.js/ai-openai`) for vectors.\n */\n public embedder(config: XaiEmbedderConfig): EmbedderContract {\n return this.openai.embedder(config);\n }\n\n /**\n * Build an `ImageModelContract` by delegating to the wrapped\n * `OpenAISDK.image()` for use with `ai.image({ model, prompt })`.\n * Pricing resolution mirrors `model()` (per-model `pricing` > SDK\n * registry > `undefined`).\n */\n public image(config: XaiImageConfig): ImageModelContract {\n return this.openai.image(config);\n }\n}\n"],"mappings":";;;;;;;;;AAqBA,MAAM,eAAe;;;;;;AAOrB,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CrB,IAAa,SAAb,MAAkD;CAkBhD,AAAO,YAAY,QAAsB;EACvC,MAAM,EAAE,SAAS,UAAU,GAAG,SAAS;EAKvC,KAAK,SAAS,IAAI,UAAU;GAC1B,GAAG;GACH,SAAS,WAAW;GACpB,UAAU,YAAY;EACxB,CAAC;EAED,KAAK,UAAU,OAAO;CACxB;;;;;;;;;;;;;;;;;;;CAoBA,AAAO,MAAM,QAAuC;EAClD,OAAO,KAAK,OAAO,MAAM;GACvB,GAAG;GAIH,QAAQ,OAAO,UAAU,sBAAsB,OAAO,IAAI;GAC1D,WAAW,OAAO,aAAa,yBAAyB,OAAO,IAAI;EACrE,CAAC;CACH;;;;;;CAOA,MAAa,MAAM,MAAc,OAAiC;EAChE,OAAO,KAAK,OAAO,MAAM,MAAM,KAAK;CACtC;;;;;;;;;;CAWA,AAAO,SAAS,QAA6C;EAC3D,OAAO,KAAK,OAAO,SAAS,MAAM;CACpC;;;;;;;CAQA,AAAO,MAAM,QAA4C;EACvD,OAAO,KAAK,OAAO,MAAM,MAAM;CACjC;AACF"}
package/package.json CHANGED
@@ -14,13 +14,13 @@
14
14
  "url": "https://github.com/warlockjs/ai-xai"
15
15
  },
16
16
  "dependencies": {
17
- "@warlock.js/ai-openai": "4.8.2",
18
- "@warlock.js/logger": "4.8.2"
17
+ "@warlock.js/ai-openai": "4.9.0",
18
+ "@warlock.js/logger": "4.9.0"
19
19
  },
20
20
  "peerDependencies": {
21
- "@warlock.js/ai": "4.8.2"
21
+ "@warlock.js/ai": "4.9.0"
22
22
  },
23
- "version": "4.8.2",
23
+ "version": "4.9.0",
24
24
  "main": "./cjs/index.cjs",
25
25
  "module": "./esm/index.mjs",
26
26
  "types": "./esm/index.d.mts",