diff --git a/src/config/schema.ts b/src/config/schema.ts index 1401b0574..76bf9ae22 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -208,7 +208,9 @@ const FIELD_LABELS: Record = { "gateway.nodes.browser.mode": "Gateway Node Browser Mode", "gateway.nodes.browser.node": "Gateway Node Browser Pin", "gateway.nodes.allowCommands": "Gateway Node Allowlist (Extra Commands)", + "gateway.xaiTools": "Configurable allowlist of Clawdbot tools enabled for xAI/Grok requests in OpenAI gateway (empty enables all).", "gateway.nodes.denyCommands": "Gateway Node Denylist", + "gateway.xaiTools": "xAI Tools", "nodeHost.browserProxy.enabled": "Node Browser Proxy Enabled", "nodeHost.browserProxy.allowProfiles": "Node Browser Proxy Allowed Profiles", "skills.load.watch": "Watch Skills", diff --git a/src/config/zod-schema.ts b/src/config/zod-schema.ts index 961ba8ecb..1537d1c64 100644 --- a/src/config/zod-schema.ts +++ b/src/config/zod-schema.ts @@ -443,6 +443,7 @@ export const OpenClawSchema = z }) .strict() .optional(), + xaiTools: z.array(z.string()).optional(), }) .strict() .optional(), diff --git a/src/gateway/openai-http.ts b/src/gateway/openai-http.ts index 2cbcb7c1f..a9a8acfeb 100644 --- a/src/gateway/openai-http.ts +++ b/src/gateway/openai-http.ts @@ -16,6 +16,7 @@ import { writeDone, } from "./http-common.js"; import { getBearerToken, resolveAgentIdForRequest, resolveSessionKey } from "./http-utils.js"; +import { loadConfig } from "../../config/config.js"; type OpenAiHttpOptions = { auth: ResolvedGatewayAuth; @@ -184,6 +185,9 @@ export async function handleOpenAiHttpRequest( const model = typeof payload.model === "string" ? payload.model : "openclaw"; const user = typeof payload.user === "string" ? payload.user : undefined; + const cfg = loadConfig(); + const isXaiModel = typeof model === "string" && model.startsWith("grok-"); + const agentId = resolveAgentIdForRequest({ req, model }); const sessionKey = resolveOpenAiSessionKey({ req, agentId, user }); const prompt = buildAgentPrompt(payload.messages); @@ -211,6 +215,7 @@ export async function handleOpenAiHttpRequest( deliver: false, messageChannel: "webchat", bestEffortDeliver: false, + clientTools: isXaiModel ? cfg.gateway?.xaiTools ?? [] : undefined, }, defaultRuntime, deps, @@ -318,6 +323,7 @@ export async function handleOpenAiHttpRequest( deliver: false, messageChannel: "webchat", bestEffortDeliver: false, + clientTools: isXaiModel ? cfg.gateway?.xaiTools ?? [] : undefined, }, defaultRuntime, deps,