Vendor OpenClaw source as Adolf fork baseline
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
This commit is contained in:
212
extensions/xai/provider-catalog.ts
Normal file
212
extensions/xai/provider-catalog.ts
Normal file
@@ -0,0 +1,212 @@
|
||||
// Xai provider module implements model/runtime integration.
|
||||
import {
|
||||
buildLiveModelProviderConfig,
|
||||
getCachedLiveProviderModelRows,
|
||||
type LiveModelCatalogFetchGuard,
|
||||
} from "openclaw/plugin-sdk/provider-catalog-live-runtime";
|
||||
import type {
|
||||
ModelDefinitionConfig,
|
||||
ModelProviderConfig,
|
||||
} from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import {
|
||||
buildXaiCatalogModels,
|
||||
resolveXaiCatalogEntry,
|
||||
XAI_BASE_URL,
|
||||
XAI_DEFAULT_CONTEXT_WINDOW,
|
||||
XAI_IMAGE_MODELS,
|
||||
XAI_DEFAULT_MAX_TOKENS,
|
||||
} from "./model-definitions.js";
|
||||
|
||||
const PROVIDER_ID = "xai";
|
||||
const XAI_MODELS_ENDPOINT = `${XAI_BASE_URL}/models`;
|
||||
const XAI_GROK_OAUTH_BASE_URL = "https://cli-chat-proxy.grok.com/v1";
|
||||
const XAI_GROK_OAUTH_MODELS_ENDPOINT = `${XAI_GROK_OAUTH_BASE_URL}/models`;
|
||||
const XAI_MODELS_CACHE_TTL_MS = 60_000;
|
||||
const XAI_GROK_OAUTH_MODELS_CACHE_TTL_MS = 60_000;
|
||||
// Composer emits replayable Responses reasoning, but the OAuth catalog omits that capability.
|
||||
// Keep it classified here or the stream wrapper will omit encrypted reasoning from replay.
|
||||
const XAI_GROK_OAUTH_REASONING_MODEL_IDS = new Set(["grok-composer-2.5-fast"]);
|
||||
const XAI_UNKNOWN_MODEL_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
} satisfies ModelDefinitionConfig["cost"];
|
||||
|
||||
export function buildXaiProvider(
|
||||
api: ModelProviderConfig["api"] = "openai-responses",
|
||||
): ModelProviderConfig {
|
||||
return {
|
||||
baseUrl: XAI_BASE_URL,
|
||||
api,
|
||||
models: buildXaiCatalogModels(),
|
||||
};
|
||||
}
|
||||
|
||||
function buildXaiOAuthFallbackProvider(): ModelProviderConfig {
|
||||
return {
|
||||
baseUrl: XAI_GROK_OAUTH_BASE_URL,
|
||||
api: "openai-responses",
|
||||
auth: "oauth",
|
||||
models: buildXaiCatalogModels(),
|
||||
};
|
||||
}
|
||||
|
||||
export async function buildLiveXaiProvider(params: {
|
||||
apiKey?: string;
|
||||
discoveryApiKey?: string;
|
||||
fetchGuard?: LiveModelCatalogFetchGuard;
|
||||
signal?: AbortSignal;
|
||||
}): Promise<ModelProviderConfig> {
|
||||
return await buildLiveModelProviderConfig({
|
||||
providerId: PROVIDER_ID,
|
||||
endpoint: XAI_MODELS_ENDPOINT,
|
||||
providerConfig: {
|
||||
baseUrl: XAI_BASE_URL,
|
||||
api: "openai-responses",
|
||||
},
|
||||
models: buildXaiCatalogModels(),
|
||||
apiKey: params.apiKey,
|
||||
discoveryApiKey: params.discoveryApiKey,
|
||||
fetchGuard: params.fetchGuard,
|
||||
signal: params.signal,
|
||||
ttlMs: XAI_MODELS_CACHE_TTL_MS,
|
||||
auditContext: "xai-model-discovery",
|
||||
});
|
||||
}
|
||||
|
||||
function readLiveModelString(row: unknown, key: string): string | undefined {
|
||||
if (!row || typeof row !== "object" || Array.isArray(row)) {
|
||||
return undefined;
|
||||
}
|
||||
const value = (row as Record<string, unknown>)[key];
|
||||
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
||||
}
|
||||
|
||||
function readLiveModelPositiveInteger(row: unknown, keys: readonly string[]): number | undefined {
|
||||
if (!row || typeof row !== "object" || Array.isArray(row)) {
|
||||
return undefined;
|
||||
}
|
||||
const record = row as Record<string, unknown>;
|
||||
for (const key of keys) {
|
||||
const value = record[key];
|
||||
if (typeof value === "number" && Number.isSafeInteger(value) && value > 0) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function readLiveModelBoolean(row: unknown, key: string): boolean | undefined {
|
||||
if (!row || typeof row !== "object" || Array.isArray(row)) {
|
||||
return undefined;
|
||||
}
|
||||
const value = (row as Record<string, unknown>)[key];
|
||||
return typeof value === "boolean" ? value : undefined;
|
||||
}
|
||||
|
||||
function resolveXaiOauthMetadataFallback(modelId: string) {
|
||||
if (modelId === "grok-build") {
|
||||
return resolveXaiCatalogEntry("grok-build-0.1");
|
||||
}
|
||||
return resolveXaiCatalogEntry(modelId);
|
||||
}
|
||||
|
||||
function isXaiOAuthResponsesModel(row: unknown, fallback: ModelDefinitionConfig | undefined) {
|
||||
const modelId = readLiveModelString(row, "id") ?? readLiveModelString(row, "model");
|
||||
if (modelId && (XAI_IMAGE_MODELS as readonly string[]).includes(modelId)) {
|
||||
return false;
|
||||
}
|
||||
const backend =
|
||||
readLiveModelString(row, "api_backend") ??
|
||||
readLiveModelString(row, "apiBackend") ??
|
||||
readLiveModelString(row, "backend");
|
||||
if (backend) {
|
||||
const normalizedBackend = backend.toLowerCase();
|
||||
return (
|
||||
normalizedBackend === "responses" ||
|
||||
normalizedBackend === "chat" ||
|
||||
normalizedBackend === "language"
|
||||
);
|
||||
}
|
||||
return Boolean(fallback);
|
||||
}
|
||||
|
||||
function buildXaiOauthModelFromLiveRow(row: unknown): ModelDefinitionConfig | undefined {
|
||||
const modelId = readLiveModelString(row, "id") ?? readLiveModelString(row, "model");
|
||||
if (!modelId) {
|
||||
return undefined;
|
||||
}
|
||||
const fallback = resolveXaiOauthMetadataFallback(modelId);
|
||||
if (!isXaiOAuthResponsesModel(row, fallback)) {
|
||||
return undefined;
|
||||
}
|
||||
const contextWindow =
|
||||
readLiveModelPositiveInteger(row, ["context_window", "contextWindow"]) ??
|
||||
fallback?.contextWindow ??
|
||||
XAI_DEFAULT_CONTEXT_WINDOW;
|
||||
const maxTokens =
|
||||
readLiveModelPositiveInteger(row, ["max_completion_tokens", "maxCompletionTokens"]) ??
|
||||
fallback?.maxTokens ??
|
||||
XAI_DEFAULT_MAX_TOKENS;
|
||||
const supportsReasoningEffort =
|
||||
readLiveModelBoolean(row, "supports_reasoning_effort") ??
|
||||
readLiveModelBoolean(row, "supportsReasoningEffort");
|
||||
const reasoning =
|
||||
supportsReasoningEffort === true ||
|
||||
fallback?.reasoning === true ||
|
||||
XAI_GROK_OAUTH_REASONING_MODEL_IDS.has(modelId);
|
||||
|
||||
return {
|
||||
id: modelId,
|
||||
name: readLiveModelString(row, "name") ?? fallback?.name ?? modelId,
|
||||
api: "openai-responses",
|
||||
baseUrl: XAI_GROK_OAUTH_BASE_URL,
|
||||
reasoning,
|
||||
input: fallback?.input ?? ["text"],
|
||||
cost: fallback?.cost ?? XAI_UNKNOWN_MODEL_COST,
|
||||
contextWindow,
|
||||
maxTokens,
|
||||
...(fallback?.compat ? { compat: fallback.compat } : {}),
|
||||
...(fallback?.thinkingLevelMap ? { thinkingLevelMap: fallback.thinkingLevelMap } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export async function buildLiveXaiOAuthProvider(params: {
|
||||
discoveryApiKey: string;
|
||||
fetchGuard?: LiveModelCatalogFetchGuard;
|
||||
signal?: AbortSignal;
|
||||
}): Promise<ModelProviderConfig> {
|
||||
try {
|
||||
const rows = await getCachedLiveProviderModelRows({
|
||||
providerId: PROVIDER_ID,
|
||||
endpoint: XAI_GROK_OAUTH_MODELS_ENDPOINT,
|
||||
discoveryApiKey: params.discoveryApiKey,
|
||||
fetchGuard: params.fetchGuard,
|
||||
signal: params.signal,
|
||||
ttlMs: XAI_GROK_OAUTH_MODELS_CACHE_TTL_MS,
|
||||
auditContext: "xai-grok-oauth-model-discovery",
|
||||
cacheKeyParts: [
|
||||
PROVIDER_ID,
|
||||
"grok-oauth-model-rows",
|
||||
XAI_GROK_OAUTH_MODELS_ENDPOINT,
|
||||
params.discoveryApiKey,
|
||||
],
|
||||
});
|
||||
const models = rows
|
||||
.map(buildXaiOauthModelFromLiveRow)
|
||||
.filter((model): model is ModelDefinitionConfig => Boolean(model));
|
||||
if (models.length > 0) {
|
||||
return {
|
||||
baseUrl: XAI_GROK_OAUTH_BASE_URL,
|
||||
api: "openai-responses",
|
||||
auth: "oauth",
|
||||
models,
|
||||
};
|
||||
}
|
||||
} catch {
|
||||
// Grok subscription discovery is advisory. If the proxy is unavailable,
|
||||
// preserve the OAuth proxy transport instead of publishing API-key rows.
|
||||
}
|
||||
return buildXaiOAuthFallbackProvider();
|
||||
}
|
||||
Reference in New Issue
Block a user