Download src/agents/runtime-plan/materialize-model.xai.test.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 2.81 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/agents/runtime-plan/materialize-model.xai.test.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/agents/runtime-plan/materialize-model.xai.test.ts
-
curl -L -o materialize-model.xai.test.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/agents/runtime-plan/materialize-model.xai.test.ts
2.81 kB
| import { describe, expect, it } from "vitest"; | |
| import { registerSingleProviderPlugin } from "../../plugin-sdk/plugin-test-runtime.js"; | |
| import type { ProviderRuntimeModel } from "../../plugins/provider-runtime-model.types.js"; | |
| import { loadBundledPluginFacade } from "../../test-utils/bundled-plugin-public-surface.js"; | |
| import type { StreamFn } from "../runtime/index.js"; | |
| import { materializePreparedRuntimeModel } from "./materialize-model.js"; | |
| describe("xAI OAuth runtime materialization", () => { | |
| it("retains the selected concrete model through auth resolution and transport", async () => { | |
| const plugin = await loadBundledPluginFacade<{ | |
| default: Parameters<typeof registerSingleProviderPlugin>[0]; | |
| }>({ pluginId: "xai", artifactBasename: "index.js" }); | |
| const provider = await registerSingleProviderPlugin(plugin.default); | |
| const model: ProviderRuntimeModel = { | |
| provider: "xai", | |
| id: "grok-4.6", | |
| name: "Grok 4.6", | |
| api: "openai-responses", | |
| baseUrl: "https://cli-chat-proxy.grok.com/v1", | |
| params: { canonicalModelId: "grok-fixture-unselected" }, | |
| reasoning: true, | |
| input: ["text"], | |
| cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, | |
| contextWindow: 500_000, | |
| maxTokens: 64_000, | |
| }; | |
| const materialized = await materializePreparedRuntimeModel({ | |
| provider: "xai", | |
| modelId: "grok-4.6", | |
| model, | |
| config: {}, | |
| plan: { | |
| providerForAuth: "xai", | |
| authProfileProviderForAuth: "xai", | |
| selectedAuthMode: "oauth", | |
| forwardedAuthProfileId: "xai:fixture", | |
| }, | |
| forceResolve: true, | |
| resolveModel: async (request) => { | |
| expect(request.authProfileId).toBe("xai:fixture"); | |
| expect(request.authProfileMode).toBe("oauth"); | |
| return { | |
| model: provider.normalizeResolvedModel?.({ provider: "xai", modelId: "grok-4.6", model }), | |
| }; | |
| }, | |
| }); | |
| expect(materialized?.id).toBe("grok-4.6"); | |
| expect(materialized?.thinkingLevelMap?.xhigh).toBe("xhigh"); | |
| let wireModelId: string | undefined; | |
| let wireHeaders: Record<string, string> | undefined; | |
| const streamFn: StreamFn = (wireModel, _context, options) => { | |
| wireModelId = wireModel.id; | |
| wireHeaders = options?.headers; | |
| return {} as ReturnType<StreamFn>; | |
| }; | |
| const wrapped = provider.wrapStreamFn?.({ | |
| provider: "xai", | |
| modelId: "grok-4.6", | |
| model: materialized, | |
| streamFn, | |
| extraParams: { tool_stream: false }, | |
| }); | |
| if (!materialized || !wrapped) { | |
| throw new Error("expected materialized subscription stream"); | |
| } | |
| await wrapped(materialized, { messages: [] }, {}); | |
| expect(wireModelId).toBe("grok-4.6"); | |
| expect(wireHeaders?.["x-grok-model-override"]).toBe(wireModelId); | |
| }); | |
| }); | |