fix(opencode): tighten OpenCode auth detection, reserve GOOGLE_API_KEY/GROK_API_KEY, and deduplicate key lists

This commit is contained in:
cryppadotta committed 2026-12-01 17:45:49 +00:00
1 parent de3acad65f
commit 657a89630e
12 files changed
+126 -59

No files matched your search

@@ -54,7 +54,9 @@ const RESERVED: &[&str] = &[
"GH_TOKEN",
"GITHUB_ENTERPRISE_TOKEN",
"GITHUB_TOKEN",
"GOOGLE_API_KEY",
"GOOGLE_GENERATIVE_AI_API_KEY",
"GROK_API_KEY",
"GROQ_API_KEY",
"HOME",
"KIMI_API_KEY",
@@ -244,6 +246,8 @@ mod tests {
"[\"PAPERCLIP_RUNTIME_NOTIFICATION_CONTEXT\"]",
"[\"PAPERCLIP_RUNTIME_NOTIFICATION_HELPER\"]",
"[\"OPENAI_API_KEY\"]",
"[\"GOOGLE_API_KEY\"]",
"[\"GROK_API_KEY\"]",
"[\"KIMI_API_KEY\"]",
"[\"PAPERCLIP_NATIVE_MCP_NAME\"]",
"[\"PAPERCLIP_NATIVE_MCP_URL\"]",
@@ -89,14 +89,18 @@ describe("configured environment authority", () => {
expect(createSanitizedAcpxSpawnInput(selected, "pi").env.KIMI_API_KEY).toBe("selected-kimi-secret");
});
it("reserves Google provider credentials from generic task projections", () => {
it("reserves Google and Grok provider credentials from generic task projections", () => {
const projected = configuredEnvironmentProjection({
GEMINI_API_KEY: "selected-gemini-secret",
GOOGLE_API_KEY: "selected-google-secret",
GOOGLE_GENERATIVE_AI_API_KEY: "selected-google-genai-secret",
GROK_API_KEY: "selected-grok-secret",
CUSTOM_FLAG: "allowed",
});
expect(projected.GEMINI_API_KEY).toBeUndefined();
expect(projected.GOOGLE_API_KEY).toBeUndefined();
expect(projected.GOOGLE_GENERATIVE_AI_API_KEY).toBeUndefined();
expect(projected.GROK_API_KEY).toBeUndefined();
expect(JSON.parse(projected[CONFIGURED_ENVIRONMENT_KEYS]!)).toEqual(["CUSTOM_FLAG"]);
});
@@ -109,7 +113,7 @@ describe("configured environment authority", () => {
} finally { vi.unstubAllEnvs(); }
});
it.each(["not-json", "[1]", '["NODE_OPTIONS"]', '["PAPERCLIP_API_KEY"]', '["PAPERCLIP_RUNNER_BOOTSTRAP_TICKET"]', '["OPENAI_API_KEY"]', '["KIMI_API_KEY"]', '["PAPERCLIP_NATIVE_MCP_NAME"]', '["PAPERCLIP_NATIVE_MCP_URL"]', '["PAPERCLIP_NATIVE_MCP_TOKEN"]', '["LD_PRELOAD"]', '["bad=name"]', '["CUSTOM","CUSTOM"]', '["MISSING"]'])
it.each(["not-json", "[1]", '["NODE_OPTIONS"]', '["PAPERCLIP_API_KEY"]', '["PAPERCLIP_RUNNER_BOOTSTRAP_TICKET"]', '["OPENAI_API_KEY"]', '["GOOGLE_API_KEY"]', '["GROK_API_KEY"]', '["KIMI_API_KEY"]', '["PAPERCLIP_NATIVE_MCP_NAME"]', '["PAPERCLIP_NATIVE_MCP_URL"]', '["PAPERCLIP_NATIVE_MCP_TOKEN"]', '["LD_PRELOAD"]', '["bad=name"]', '["CUSTOM","CUSTOM"]', '["MISSING"]'])
("rejects malformed or reserved projection %s", raw => {
expect(() => configuredEnvironment({ [CONFIGURED_ENVIRONMENT_KEYS]: raw })).toThrow("Invalid configured environment");
});
@@ -40,8 +40,8 @@ export const GENERATED_RUNTIME_ENVIRONMENT_KEYS: ReadonlySet<string> = new Set([
export const PROVIDER_CREDENTIAL_ENVIRONMENT_KEYS: readonly string[] = [
"OPENAI_API_KEY", "CODEX_API_KEY", "ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN", "CLAUDE_CODE_OAUTH_TOKEN",
"AWS_BEARER_TOKEN_BEDROCK", "OPENROUTER_API_KEY", "GEMINI_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEY",
"XAI_API_KEY", "GROQ_API_KEY", "OPENCODE_API_KEY", "CURSOR_API_KEY", "CURSOR_AUTH_TOKEN",
"AWS_BEARER_TOKEN_BEDROCK", "OPENROUTER_API_KEY", "GEMINI_API_KEY", "GOOGLE_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEY",
"XAI_API_KEY", "GROK_API_KEY", "GROQ_API_KEY", "OPENCODE_API_KEY", "CURSOR_API_KEY", "CURSOR_AUTH_TOKEN",
"COPILOT_GITHUB_TOKEN", "KIMI_API_KEY", "GH_TOKEN", "GITHUB_TOKEN", "GH_ENTERPRISE_TOKEN", "GITHUB_ENTERPRISE_TOKEN", "PAPERCLIP_GIT_TOKEN",
];
@@ -112,6 +112,7 @@ it("keeps the selected key while removing conflicting explicitly projected Googl
CLOUDSDK_CONFIG: "/foreign/cloud", AGY_ACP_FORCE_FILE_STORAGE: "0", TASK_INPUT: "retained",
});
expect(projected.GEMINI_API_KEY).toBeUndefined();
expect(projected.GOOGLE_API_KEY).toBeUndefined();
const source = { ...projected, GEMINI_API_KEY: "selected-key" };
const env = createSanitizedAcpxSpawnInput(source, "antigravity").env;
expect(env.GEMINI_API_KEY).toBe("selected-key");
@@ -17,16 +17,6 @@ import { redactOpenCodeModelRequest } from "./output-custody.js";
import { attributeUnsupportedToolMedia } from "./tool-media-attribution.js";
import { createUpstreamServedTap, type UpstreamServed } from "./upstream-served.js";
export const OPENCODE_DIRECT_PROVIDER_API_KEY_ENV_KEYS = [
"GOOGLE_GENERATIVE_AI_API_KEY",
"GEMINI_API_KEY",
"OPENAI_API_KEY",
"ANTHROPIC_API_KEY",
"XAI_API_KEY",
"GROQ_API_KEY",
"OPENCODE_API_KEY",
] as const;
export type OpenCodeProviderProtocol =
| "openai_compatible_gateway"
| "google"
@@ -94,6 +84,10 @@ const DIRECT_PROVIDER_DEFAULTS: Readonly<
},
};
export const OPENCODE_DIRECT_PROVIDER_API_KEY_ENV_KEYS: readonly string[] = Object.values(
DIRECT_PROVIDER_DEFAULTS,
).flatMap((spec) => spec.envKeys);
export function resolveOpenCodeProviderRoute(
modelProvider: string | undefined,
explicitEnvironment: NodeJS.ProcessEnv | undefined,
@@ -12,6 +12,7 @@ export { createRunnerdCodexAppServerArgs, resolveRunnerdAcpxPermissionMode, trus
import { applyProviderObservabilityEnvironment, redactObservabilityDiagnostic } from "../drivers/agent-observability.js";
import type { RunnerExecutionDriver } from "../control-plane/runner-execution-driver.js";
import { resolvePinnedOpenCodeCommand } from "../drivers/opencode/opencode-server-driver.js";
import { OPENCODE_DIRECT_PROVIDER_API_KEY_ENV_KEYS } from "../drivers/opencode/provider-proxy.js";
import { bindAcpxCandidateAdmission, isAntigravityNativeTarget, parseAcpxCandidateAdmission, type AcpxCandidateAdmission, type AcpxCandidateStartupAdmission } from "../drivers/acpx/candidate-admission.js";
import { ACPX_CAPABILITY_PROFILES } from "../drivers/acpx/capability-profiles.js";
import { resolveClaudeEffort, admittedClaudeEffort } from "../drivers/acpx/claude-effort.js";
@@ -4051,13 +4052,7 @@ export const OPEN_CODE_RUNNER_ENVIRONMENT_KEYS = new Set([
"WINDIR",
"RUST_BACKTRACE",
"OPENROUTER_API_KEY",
"OPENAI_API_KEY",
"ANTHROPIC_API_KEY",
"GEMINI_API_KEY",
"GOOGLE_GENERATIVE_AI_API_KEY",
"XAI_API_KEY",
"GROQ_API_KEY",
"OPENCODE_API_KEY",
...OPENCODE_DIRECT_PROVIDER_API_KEY_ENV_KEYS,
"PAPERCLIP_OPENROUTER_PROXY_URL",
"PAPERCLIP_OPENROUTER_PROXY_TOKEN",
]);
@@ -4072,13 +4067,7 @@ export function createSanitizedOpenCodeRunnerEnvironment(
"PAPERCLIP_AGENT_PRIVATE_KEY",
"PAPERCLIP_OPENROUTER_PROXY_URL",
"PAPERCLIP_OPENROUTER_PROXY_TOKEN",
"OPENAI_API_KEY",
"ANTHROPIC_API_KEY",
"GEMINI_API_KEY",
"GOOGLE_GENERATIVE_AI_API_KEY",
"XAI_API_KEY",
"GROQ_API_KEY",
"OPENCODE_API_KEY",
...OPENCODE_DIRECT_PROVIDER_API_KEY_ENV_KEYS,
]) {
delete candidate[key];
if (source?.[key] !== undefined) candidate[key] = source[key];
+17
View File
@@ -82,6 +82,23 @@ export function aiConnectionSourceSlug(
return metadata.success ? aiConnectionCatalogSlug(metadata.data.provider, metadata.data.routing) : null;
}
/** OpenCode provider -> environment variable keys (ordered by precedence). */
export const OPENCODE_PROVIDER_CREDENTIAL_ENV_KEYS = {
openrouter: ["OPENROUTER_API_KEY"],
google: ["GOOGLE_GENERATIVE_AI_API_KEY", "GEMINI_API_KEY"],
anthropic: ["ANTHROPIC_API_KEY"],
openai: ["OPENAI_API_KEY"],
xai: ["XAI_API_KEY"],
groq: ["GROQ_API_KEY"],
opencode: ["OPENCODE_API_KEY"],
} as const satisfies Readonly<Record<string, readonly string[]>>;
export type OpenCodeCredentialProvider = keyof typeof OPENCODE_PROVIDER_CREDENTIAL_ENV_KEYS;
export const OPENCODE_CREDENTIAL_ENV_KEYS: readonly string[] = Object.values(
OPENCODE_PROVIDER_CREDENTIAL_ENV_KEYS,
).flat();
/** Existing integrations only. This table describes compatibility, never routing. */
export const AI_CONNECTION_CAPABILITIES: Record<
AiProvider,
@@ -166,6 +166,27 @@ describe("managed AI connections", () => {
expect(defaultAiConnectionForHire("opencode_local", { model: "google/gemini-2.5-flash", env: { GOOGLE_GENERATIVE_AI_API_KEY: "explicit" } }, manager)).toBeUndefined();
expect(defaultAiConnectionForHire("opencode_local", { model: "anthropic/claude-sonnet-4-5", env: { PAPERCLIP_OPENCODE_PROVIDERS: "{}" } }, router)).toBeUndefined();
expect(defaultAiConnectionForHire("opencode_local", { model: "anthropic/claude-sonnet-4-5", env: { OPENCODE_AUTH_JSON: "{}" } }, router)).toBeUndefined();
expect(defaultAiConnectionForHire("opencode_local", { model: "groq/llama-3.3-70b-versatile", env: { GROQ_API_KEY: "explicit" } }, router)).toBeUndefined();
// Non-OpenCode provider config keys and blank values must not drop inherited OpenCode connections.
expect(defaultAiConnectionForHire("opencode_local", { model: "google/gemini-2.5-flash", env: { GOOGLE_GEMINI_BASE_URL: "https://generativelanguage.example.test" } }, manager)).toEqual({
provider: "google",
method: "api_key",
mode: "responsible_user",
});
expect(defaultAiConnectionForHire("opencode_local", { model: "google/gemini-2.5-flash", env: { GOOGLE_API_KEY: "bare-google-key" } }, manager)).toEqual({
provider: "google",
method: "api_key",
mode: "responsible_user",
});
expect(defaultAiConnectionForHire("opencode_local", { model: "google/gemini-2.5-flash", env: { GEMINI_API_KEY: "", GOOGLE_GENERATIVE_AI_API_KEY: { type: "plain", value: " " } } }, manager)).toEqual({
provider: "google",
method: "api_key",
mode: "responsible_user",
});
expect(defaultAiConnectionForHire("opencode_local", { model: "anthropic/claude-sonnet-4-5", env: { ANTHROPIC_BASE_URL: "https://proxy.example.test", CLAUDE_CONFIG_DIR: "/tmp/claude" } }, router)).toEqual(router);
expect(defaultAiConnectionForHire("opencode_local", { model: "openai/gpt-5", env: { OPENAI_BASE_URL: "https://proxy.example.test", CODEX_HOME: "/tmp/codex" } }, router)).toEqual(router);
expect(defaultAiConnectionForHire("opencode_local", { model: "google/gemini-2.5-flash", env: { GOOGLE_API_KEY: "bare-google-key", GOOGLE_GEMINI_BASE_URL: "https://proxy.example.test" } }, router)).toEqual(router);
});
it.each([200, 401])("reverifies native Pi OpenRouter keys without requiring the Legacy Pi CLI (HTTP %s)", async status => {
@@ -1,10 +1,16 @@
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";
import { OPENCODE_CREDENTIAL_ENV_KEYS } from "@paperclipai/shared";
import { ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS } from "@paperclipai/plugin-sdk";
import {
PROVIDER_CREDENTIAL_ENVIRONMENT_KEYS,
configuredEnvironmentProjection,
} from "../../../packages/paperclip-runner/src/configured-environment.js";
import {
ACPX_CREDENTIAL_BINDING_ENV, ACPX_CREDENTIAL_NAMES, createAcpxCredentialBinding, createAcpxSidecarHostEnvironment, createSanitizedAcpxSpawnInput,
} from "../../../packages/paperclip-runner/src/drivers/acpx/environment.js";
import { OPENCODE_DIRECT_PROVIDER_API_KEY_ENV_KEYS } from "../../../packages/paperclip-runner/src/drivers/opencode/provider-proxy.js";
import { OPEN_CODE_RUNNER_ENVIRONMENT_KEYS } from "../../../packages/paperclip-runner/src/live/runnerd-codex-transport.js";
const runnerSource = (file: string) =>
@@ -15,6 +21,7 @@ const rustAcpxCredentialNames = (agent: string) =>
names(new RegExp(`"${agent}" => &\\[([^\\]]*)\\]`, "u").exec(acpxSidecar)?.[1]);
const rustCandidateAgents = names(/if matches!\(agent, ([^)]*)\) \{[^}]*keys\.push\("PAPERCLIP_ACPX_CREDENTIAL_BINDING"\)/u.exec(acpxSidecar)?.[1]);
const rustOpenCodeNames = names(/const OPENCODE_PROVIDER_ENVIRONMENT_KEYS: &\[&str\] = &\[([^\]]*)\];/u.exec(runnerSource("codex_provider.rs"))?.[1]);
const rustConfiguredReservedNames = names(/const RESERVED: &\[&str\] = &\[([^\]]*)\];/u.exec(runnerSource("configured_environment.rs"))?.[1]);
const acpxAgents = Object.keys(ACPX_CREDENTIAL_NAMES) as (keyof typeof ACPX_CREDENTIAL_NAMES)[];
const providers = Object.entries(ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS);
@@ -56,10 +63,30 @@ describe("plugin Runner provider credential names", () => {
}
});
it("keeps OpenCode and reserved provider credential lists synchronized across shared, SDK, TS Runner, and Rust Runner", () => {
const sdkOpenCodeKeys = [...new Set(ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS.opencode.flat())]
.filter((name) => name !== "PAPERCLIP_AI_PROVIDER_URL" && name !== "PAPERCLIP_AI_PROVIDER_KEY")
.sort();
const sharedOpenCodeKeys = [...new Set(OPENCODE_CREDENTIAL_ENV_KEYS)].sort();
const proxyOpenCodeKeys = [...new Set(["OPENROUTER_API_KEY", ...OPENCODE_DIRECT_PROVIDER_API_KEY_ENV_KEYS])].sort();
expect(sharedOpenCodeKeys).toEqual(sdkOpenCodeKeys);
expect(proxyOpenCodeKeys).toEqual(sharedOpenCodeKeys);
for (const name of sharedOpenCodeKeys) {
expect(OPEN_CODE_RUNNER_ENVIRONMENT_KEYS.has(name), `${name} in OPEN_CODE_RUNNER_ENVIRONMENT_KEYS`).toBe(true);
expect(rustOpenCodeNames, `${name} in Rust OPENCODE_PROVIDER_ENVIRONMENT_KEYS`).toContain(name);
expect(PROVIDER_CREDENTIAL_ENVIRONMENT_KEYS, `${name} in TS PROVIDER_CREDENTIAL_ENVIRONMENT_KEYS`).toContain(name);
}
for (const name of PROVIDER_CREDENTIAL_ENVIRONMENT_KEYS) {
expect(rustConfiguredReservedNames, `${name} in Rust configured_environment::RESERVED`).toContain(name);
}
});
it("still strips Google and Gemini routing variables from the Antigravity process", () => {
const routing = { GOOGLE_API_KEY: "fixture-google", GOOGLE_APPLICATION_CREDENTIALS: "/controller/private/adc.json",
GOOGLE_CLOUD_PROJECT: "fixture-project", GOOGLE_GEMINI_BASE_URL: "https://router.example.test", GEMINI_HOME: "/controller/private/gemini" };
const environment = { GEMINI_API_KEY: "fixture-gemini", ...routing, PAPERCLIP_CONFIGURED_ENV_KEYS: JSON.stringify(Object.keys(routing)) };
const projectedRouting = configuredEnvironmentProjection(routing);
expect(projectedRouting.GOOGLE_API_KEY).toBeUndefined();
const environment = { ...projectedRouting, GEMINI_API_KEY: "fixture-gemini", GOOGLE_API_KEY: "fixture-google" };
const binding = createAcpxCredentialBinding(environment, "antigravity", "session");
const host = createAcpxSidecarHostEnvironment({ ...environment, [ACPX_CREDENTIAL_BINDING_ENV]: binding }, "antigravity", "session");
const spawned = createSanitizedAcpxSpawnInput(host, "antigravity").env;
+4 -25
View File
@@ -40,6 +40,8 @@ import { listOpenRouterModels } from "../services/openrouter-models.js";
import { withManagedAiProbe, stripAiAuthBindings } from "../services/ai-connection-runtime.js";
import {
ADAPTER_AUTH_MISSING_CHECK_CODE,
OPENCODE_CREDENTIAL_ENV_KEYS,
OPENCODE_PROVIDER_CREDENTIAL_ENV_KEYS,
aiConnectionBindingSchema,
aiConnectionMetadataSchema,
aiRoutingModel,
@@ -2373,30 +2375,7 @@ export function agentRoutes(
codex_local: ["OPENAI_API_KEY", "CODEX_API_KEY"],
grok_local: ["XAI_API_KEY"],
// OpenCode reaches its models through provider API keys configured as env vars.
opencode_local: [
"OPENROUTER_API_KEY",
"OPENAI_API_KEY",
"ANTHROPIC_API_KEY",
"GEMINI_API_KEY",
"GOOGLE_GENERATIVE_AI_API_KEY",
"XAI_API_KEY",
"GROQ_API_KEY",
"OPENCODE_API_KEY",
],
};
// Group OpenCode inheritable keys by provider so Google alias keys
// (GEMINI_API_KEY / GOOGLE_GENERATIVE_AI_API_KEY) behave as one credential
// and hire inheritance never mixes multiple provider keys (which fails closed
// under Plugin Runner single-provider credential-set validation).
const OPENCODE_INHERITABLE_PROVIDER_CREDENTIAL_GROUPS: Readonly<Record<string, readonly string[]>> = {
openrouter: ["OPENROUTER_API_KEY"],
openai: ["OPENAI_API_KEY"],
anthropic: ["ANTHROPIC_API_KEY"],
google: ["GEMINI_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEY"],
xai: ["XAI_API_KEY"],
groq: ["GROQ_API_KEY"],
opencode: ["OPENCODE_API_KEY"],
opencode_local: OPENCODE_CREDENTIAL_ENV_KEYS,
};
function isInheritableCredentialReference(value: unknown): value is Record<string, unknown> {
@@ -2458,7 +2437,7 @@ export function agentRoutes(
credentialKeys.some((key) => existingEnv[key] !== undefined);
if (childHasOpenCodeCredential) return noInheritance;
const parentProviderGroups = Object.entries(OPENCODE_INHERITABLE_PROVIDER_CREDENTIAL_GROUPS)
const parentProviderGroups = Object.entries(OPENCODE_PROVIDER_CREDENTIAL_ENV_KEYS)
.filter(([, keys]) => keys.some((key) => isInheritableCredentialReference(parentEnv[key])));
if (parentProviderGroups.length === 0) return noInheritance;
@@ -1,5 +1,6 @@
import {
AI_PROVIDERS,
OPENCODE_PROVIDER_CREDENTIAL_ENV_KEYS,
aiRuntimeConnectionBindingSchema,
isAiConnectionCompatible,
type AiConnectionBinding,
@@ -27,6 +28,24 @@ const OPENCODE_CUSTOM_AUTH_ENV_KEYS = [
"PAPERCLIP_OPENCODE_PROVIDERS",
] as const;
function hasNonEmptyEnvBinding(value: unknown): boolean {
if (typeof value === "string") return value.trim().length > 0;
if (value && typeof value === "object" && !Array.isArray(value)) {
const record = value as Record<string, unknown>;
if (record.type === "plain") return typeof record.value === "string" && record.value.trim().length > 0;
if (record.type === "secret_ref") return typeof record.secretId === "string" && record.secretId.trim().length > 0;
if (record.type === "user_secret_ref") return typeof record.userSecretId === "string" && record.userSecretId.trim().length > 0;
}
return false;
}
function openCodeModelProvider(model: unknown): string | undefined {
if (typeof model !== "string") return undefined;
const slash = model.indexOf("/");
if (slash <= 0) return undefined;
return model.slice(0, slash).trim().toLowerCase() || undefined;
}
/** A hire inherits a connection choice, never its manager's credentials or identity. */
export function defaultAiConnectionForHire(
adapterType: string,
@@ -42,9 +61,17 @@ export function defaultAiConnectionForHire(
const isOpenCode =
adapterType === "opencode_local"
|| (adapterType === "paperclip_runner" && config.provider === "opencode");
const hasOpenCodeChildAuth = (provider: string | undefined) => {
if (OPENCODE_CUSTOM_AUTH_ENV_KEYS.some((key) => hasNonEmptyEnvBinding(env[key]))) return true;
const keys = provider && Object.hasOwn(OPENCODE_PROVIDER_CREDENTIAL_ENV_KEYS, provider)
? OPENCODE_PROVIDER_CREDENTIAL_ENV_KEYS[provider as keyof typeof OPENCODE_PROVIDER_CREDENTIAL_ENV_KEYS]
: undefined;
return keys ? keys.some((key) => hasNonEmptyEnvBinding(env[key])) : false;
};
const hasChildAuth = (provider: AiProvider) =>
PROVIDER_AUTH_ENV_KEYS[provider].some((key) => env[key] !== undefined)
|| (isOpenCode && OPENCODE_CUSTOM_AUTH_ENV_KEYS.some((key) => env[key] !== undefined));
isOpenCode
? hasOpenCodeChildAuth(provider)
: PROVIDER_AUTH_ENV_KEYS[provider].some((key) => hasNonEmptyEnvBinding(env[key]));
const withChildAuthPrecedence = (binding: AiConnectionBinding) =>
hasChildAuth(binding.provider) ? undefined : binding;
if (inherited.data.mode === "router") {
@@ -52,9 +79,13 @@ export function defaultAiConnectionForHire(
// the new agent. Never silently replace an incompatible pool with local auth.
// OpenCode also supports explicitly configured providers whose models are
// outside the managed OpenRouter catalog. Their auth still takes precedence.
const matchedProvider = AI_PROVIDERS.find((provider) =>
if (isOpenCode) {
return hasOpenCodeChildAuth(openCodeModelProvider(config.model) ?? "openrouter")
? undefined
: inherited.data;
}
const childProvider = AI_PROVIDERS.find((provider) =>
compatible({ provider, method: "api_key", mode: "responsible_user" }));
const childProvider = matchedProvider ?? (isOpenCode ? "openrouter" : undefined);
return childProvider && hasChildAuth(childProvider) ? undefined : inherited.data;
}
if (inherited.data.mode !== "delegated" && compatible(inherited.data)) {
@@ -65,7 +65,7 @@
"packages/shared/src/aggregator-apps.ts": "2a69a54ee0cb305170275b6f4e97689c107defb1",
"packages/shared/src/ai-connection-router.ts": "9fbd89c385a4d5827bc68e1c7f6a66e00453d413",
"packages/shared/src/ai-connection-usage.ts": "4b51573ee92f8a2ae0f80dd15288a0e59b4dddc7",
"packages/shared/src/ai-connections.ts": "aa3ba73576179f54f998dcd2634ce579f71620c7",
"packages/shared/src/ai-connections.ts": "13819a7d1f09f1a157c36a4c1856352acaebb197",
"packages/shared/src/ai-provider-routing.ts": "e1f1fdefc23c76efe425e937852e61fe028cccc1",
"packages/shared/src/analytics-consent.test.ts": "0c69d867d4f108cb57c07b4e71633e058cb7506b",
"packages/shared/src/analytics-consent.ts": "00c4bfbd24ac3a288a68caae52468dfcd26df3e7",