mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-26 16:06:16 +00:00
refactor: narrow claude cli fallback seams
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
export {
|
||||
CLAUDE_CLI_BACKEND_ID,
|
||||
isClaudeCliProvider,
|
||||
normalizeClaudeBackendConfig,
|
||||
} from "./cli-shared.js";
|
||||
export { CLAUDE_CLI_BACKEND_ID, isClaudeCliProvider } from "./cli-shared.js";
|
||||
export {
|
||||
createAnthropicBetaHeadersWrapper,
|
||||
createAnthropicFastModeWrapper,
|
||||
|
||||
5
extensions/anthropic/cli-backend-api.ts
Normal file
5
extensions/anthropic/cli-backend-api.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export {
|
||||
CLAUDE_CLI_BACKEND_ID,
|
||||
isClaudeCliProvider,
|
||||
normalizeClaudeBackendConfig,
|
||||
} from "./cli-shared.js";
|
||||
@@ -1,2 +1,3 @@
|
||||
export { buildAnthropicCliBackend } from "./cli-backend.js";
|
||||
export { normalizeClaudeBackendConfig } from "./cli-shared.js";
|
||||
export { anthropicMediaUnderstandingProvider } from "./media-understanding-provider.js";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { normalizeClaudeBackendConfig } from "../../extensions/anthropic/test-api.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { CliBackendConfig } from "../config/types.js";
|
||||
import { createEmptyPluginRegistry } from "../plugins/registry.js";
|
||||
@@ -51,24 +52,7 @@ beforeEach(() => {
|
||||
output: "jsonl",
|
||||
input: "stdin",
|
||||
},
|
||||
normalizeConfig: (config) => {
|
||||
const normalizeArgs = (args: string[] | undefined) => {
|
||||
if (!args) {
|
||||
return args;
|
||||
}
|
||||
const next = args.filter((arg) => arg !== "--dangerously-skip-permissions");
|
||||
const hasPermissionMode = next.some(
|
||||
(arg, index) =>
|
||||
arg === "--permission-mode" || next[index - 1]?.startsWith("--permission-mode="),
|
||||
);
|
||||
return hasPermissionMode ? next : [...next, "--permission-mode", "bypassPermissions"];
|
||||
};
|
||||
return {
|
||||
...config,
|
||||
args: normalizeArgs(config.args),
|
||||
resumeArgs: normalizeArgs(config.resumeArgs),
|
||||
};
|
||||
},
|
||||
normalizeConfig: normalizeClaudeBackendConfig,
|
||||
}),
|
||||
createBackendEntry({
|
||||
pluginId: "openai",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
CLAUDE_CLI_BACKEND_ID,
|
||||
normalizeClaudeBackendConfig,
|
||||
} from "../../extensions/anthropic/api.js";
|
||||
} from "../../extensions/anthropic/cli-backend-api.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { CliBackendConfig } from "../config/types.js";
|
||||
import { resolveRuntimeCliBackends } from "../plugins/cli-backends.runtime.js";
|
||||
@@ -29,6 +29,10 @@ const FALLBACK_CLI_BACKEND_POLICIES: Record<string, FallbackCliBackendPolicy> =
|
||||
},
|
||||
};
|
||||
|
||||
function resolveFallbackCliBackendPolicy(provider: string): FallbackCliBackendPolicy | undefined {
|
||||
return FALLBACK_CLI_BACKEND_POLICIES[provider];
|
||||
}
|
||||
|
||||
function normalizeBackendKey(key: string): string {
|
||||
return normalizeProviderId(key);
|
||||
}
|
||||
@@ -108,7 +112,7 @@ export function resolveCliBackendConfig(
|
||||
cfg?: OpenClawConfig,
|
||||
): ResolvedCliBackend | null {
|
||||
const normalized = normalizeBackendKey(provider);
|
||||
const fallbackPolicy = FALLBACK_CLI_BACKEND_POLICIES[normalized];
|
||||
const fallbackPolicy = resolveFallbackCliBackendPolicy(normalized);
|
||||
const configured = cfg?.agents?.defaults?.cliBackends ?? {};
|
||||
const override = pickBackendConfig(configured, normalized);
|
||||
const registered = resolveRegisteredBackend(normalized);
|
||||
@@ -140,6 +144,6 @@ export function resolveCliBackendConfig(
|
||||
return {
|
||||
id: normalized,
|
||||
config: { ...config, command },
|
||||
bundleMcp: fallbackPolicy?.bundleMcp,
|
||||
bundleMcp: fallbackPolicy?.bundleMcp === true,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user