Repository navigation
Inject live local models into supported agents #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
210d734
1700070
d4439e7
59cb010
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ import type { | |
| } from "../contracts.ts"; | ||
| import { computerProxyEnv } from "../container-computer.ts"; | ||
| import { newEventId, newId } from "../contracts.ts"; | ||
| import { applyClaudeInject, mergeLocalInject } from "./local-inject.ts"; | ||
| import { appendNative } from "./native.ts"; | ||
|
|
||
| /** Whether `claude` has been signed in. | ||
|
|
@@ -65,11 +66,12 @@ export function claudeSignedIn( | |
| * Keeping the probe and turn environments identical prevents setup from | ||
| * claiming an API-key login that the turn itself would deliberately remove. | ||
| */ | ||
| function claudeEnvironment(): NodeJS.ProcessEnv { | ||
| function claudeEnvironment(model?: string | null): NodeJS.ProcessEnv { | ||
| const env: NodeJS.ProcessEnv = { ...process.env, PATH: augmentedPath(), NPM_CONFIG_LOGLEVEL: "error" }; | ||
| delete env.ANTHROPIC_API_KEY; | ||
| delete env.CLAUDECODE; | ||
| delete env.CLAUDE_CODE_ENTRYPOINT; | ||
| const applied = applyClaudeInject(env, model); | ||
| if (!applied.injected) delete env.ANTHROPIC_API_KEY; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Use the instance environment for Claude injection. The catalog uses Pass Proposed fix-function claudeEnvironment(model?: string | null): NodeJS.ProcessEnv {
- const env: NodeJS.ProcessEnv = { ...process.env, PATH: augmentedPath(), NPM_CONFIG_LOGLEVEL: "error" };
+function claudeEnvironment(
+ model?: string | null,
+ source: NodeJS.ProcessEnv = process.env,
+): NodeJS.ProcessEnv {
+ const env: NodeJS.ProcessEnv = { ...source, PATH: augmentedPath(), NPM_CONFIG_LOGLEVEL: "error" };
...
- const injected = applyClaudeInject({}, turn.model);
+ const injected = applyClaudeInject({ ...catalogEnv }, turn.model);
...
- const env = claudeEnvironment(turn.model);
+ const env = claudeEnvironment(turn.model, catalogEnv);Also applies to: 365-366, 462-462 🤖 Prompt for AI Agents |
||
| return env; | ||
| } | ||
|
|
||
|
|
@@ -319,7 +321,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = { | |
| let models = STATIC_CLAUDE_MODELS; | ||
| const refreshModels = async () => { | ||
| try { | ||
| const resolved = readClaudeModelCatalog(catalogEnv); | ||
| const resolved = await mergeLocalInject(readClaudeModelCatalog(catalogEnv), catalogEnv); | ||
| if (resolved.options.length) models = resolved; | ||
| } catch { | ||
| // Keep the last usable catalog when settings.json is unreadable. | ||
|
|
@@ -360,7 +362,8 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = { | |
| ]; | ||
| if (sessionId) args.push("--resume", sessionId); | ||
| else args.push("--session-id", newSessionId!); | ||
| if (turn.model) args.push("--model", turn.model); | ||
| const injected = applyClaudeInject({}, turn.model); | ||
| if (injected.model) args.push("--model", injected.model); | ||
| if (turn.effort) args.push("--effort", turn.effort); | ||
| if (turn.system) args.push("--append-system-prompt", turn.system); | ||
|
|
||
|
|
@@ -456,7 +459,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = { | |
| args.push("--allowedTools", allowed.join(",")); | ||
| } | ||
|
|
||
| const env = claudeEnvironment(); | ||
| const env = claudeEnvironment(turn.model); | ||
|
|
||
| const child = spawnCli(config.cli, args, { | ||
| cwd: turn.cwd ?? homedir(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { afterEach, describe, expect, it } from "vitest"; | ||
|
|
||
| import { ensureGrokInjectSlug } from "./acp/grok.ts"; | ||
| import { | ||
| applyClaudeInject, | ||
| decodeInjectId, | ||
| encodeInjectId, | ||
| mergeLocalInject, | ||
| } from "./local-inject.ts"; | ||
|
|
||
| const scratchDirs: string[] = []; | ||
|
|
||
| afterEach(() => { | ||
| for (const dir of scratchDirs.splice(0)) rmSync(dir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| describe("inject ids", () => { | ||
| it("round-trips a host and API id", () => { | ||
| expect(decodeInjectId(encodeInjectId("omlx", "GLM-5.2-fp8"))).toEqual({ | ||
| host: "omlx", | ||
| model: "GLM-5.2-fp8", | ||
| }); | ||
| }); | ||
|
|
||
| it("rejects official cloud slugs", () => { | ||
| expect(decodeInjectId("claude-sonnet-5")).toBeNull(); | ||
| expect(decodeInjectId("gpt-5.6-sol")).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("mergeLocalInject", () => { | ||
| it("appends live host models as custom without touching official rows", async () => { | ||
| const catalog = await mergeLocalInject( | ||
| { default: "claude-sonnet-5", options: [{ id: "claude-sonnet-5", label: "Claude Sonnet 5" }] }, | ||
| { VITEST: "true", OPENMAUSBOT_PROBE_LOCAL_INJECT: "1" }, | ||
| async (url) => { | ||
| if (String(url).includes(":8080")) { | ||
| return new Response(JSON.stringify({ data: [{ id: "GLM-5.2-fp8" }, { id: "nomic-embed" }] }), { status: 200 }); | ||
| } | ||
| return new Response("nope", { status: 500 }); | ||
| }, | ||
| ); | ||
| expect(catalog.options[0]).toEqual({ id: "claude-sonnet-5", label: "Claude Sonnet 5" }); | ||
| expect(catalog.options.some((option) => option.id === "omlx::GLM-5.2-fp8" && option.custom)).toBe(true); | ||
| expect(catalog.options.some((option) => option.id.includes("nomic"))).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("applyClaudeInject", () => { | ||
| it("points Claude at the local host instead of Anthropic", () => { | ||
| const env: Record<string, string | undefined> = {}; | ||
| const applied = applyClaudeInject(env, "omlx::MiniMax-M3-4bit"); | ||
| expect(applied).toEqual({ model: "MiniMax-M3-4bit", injected: true }); | ||
| expect(env.ANTHROPIC_BASE_URL).toBe("http://127.0.0.1:8080"); | ||
| expect(env.ANTHROPIC_AUTH_TOKEN).toBe("omlx"); | ||
| expect(env.ANTHROPIC_MODEL).toBe("MiniMax-M3-4bit"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("ensureGrokInjectSlug", () => { | ||
| it("writes a config block the first time and reuses it after", () => { | ||
| const home = mkdtempSync(join(tmpdir(), "omb-grok-inject-")); | ||
| scratchDirs.push(home); | ||
| mkdirSync(join(home, ".grok"), { recursive: true }); | ||
| writeFileSync(join(home, ".grok", "config.toml"), "[cli]\nchannel = \"alpha\"\n"); | ||
| const first = ensureGrokInjectSlug("omlx::GLM-5.2-fp8", { HOME: home }); | ||
| const again = ensureGrokInjectSlug("omlx::GLM-5.2-fp8", { HOME: home }); | ||
| expect(first).toBe(again); | ||
| const text = readFileSync(join(home, ".grok", "config.toml"), "utf8"); | ||
| expect(text).toContain(`model = "GLM-5.2-fp8"`); | ||
| expect(text).toContain(`base_url = "http://127.0.0.1:8080/v1"`); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.