openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
75 lines (74 loc) • 3.14 kB
JavaScript
import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs";
import { r as resolveAgentConfig } from "./agent-scope-config-DmXgFGKP.mjs";
import { r as resolveModelRuntimePolicy } from "./model-runtime-policy-Cfudvy7O.mjs";
import { r as modelKey } from "./provider-registry-index-DhPtwFh_.mjs";
import { n as resolveConfiguredModelEntries } from "./configured-model-entries-Dhco8ams.mjs";
//#region src/agents/model-catalog-cli-wildcard.ts
/**
* Claude CLI sign-in writes `agents.*.models["anthropic/*"]` with the `claude-cli` runtime so any
* typed Claude ID runs through Claude Code. In catalog decisions that wildcard lights up only the
* models the Claude CLI catalog lists; authored rows keep their availability and typed refs still
* run. Other provider wildcards are unchanged.
*/
const CLAUDE_CLI_RUNTIME_ID = "claude-cli";
const ANTHROPIC_WILDCARD_REF = "anthropic/*";
/** Project the account menu onto canonical identities without admitting hosted-only models. */
function projectClaudeCliNativeCatalog(e, t) {
const n = e.providerOutcomes?.find((e) => e.provider === CLAUDE_CLI_RUNTIME_ID && e.listedModelIds !== void 0);
const r = t && n !== void 0;
const i = new Set(n?.listedModelIds ?? []);
const a = e.entries.filter((e) => e.provider === CLAUDE_CLI_RUNTIME_ID && i.has(e.id));
const o = new Map([...e.staticEntries ?? [], ...e.entries].filter((e) => e.provider === "anthropic").map((e) => [e.id, e]));
const s = [];
const c = [];
for (const e of a) {
const t = {
...e,
...o.get(e.id),
id: e.id,
provider: CLAUDE_CLI_RUNTIME_ID,
name: e.name,
reasoning: e.reasoning,
thinkingLevelMap: e.thinkingLevelMap
};
s.push(t);
if (r) c.push({
...t,
provider: "anthropic"
});
}
const keep = (e) => e.provider !== CLAUDE_CLI_RUNTIME_ID && !(e.provider === "anthropic" && r);
return {
...e,
entries: [...e.entries.filter(keep), ...r ? c : s],
routeVariants: [
...e.routeVariants.filter(keep),
...s,
...c
],
staticEntries: e.staticEntries?.filter((e) => e.provider !== CLAUDE_CLI_RUNTIME_ID && !(r && e.provider === "anthropic"))
};
}
/** Builds one decisions-scoped check; catalog and configured refs are read once, on first use. */
function createUnlistedClaudeCliWildcardCheck(e) {
const t = resolveAgentConfig(e.cfg, e.agentId)?.models?.[ANTHROPIC_WILDCARD_REF] ?? e.cfg.agents?.defaults?.models?.[ANTHROPIC_WILDCARD_REF];
if (normalizeProviderId(t?.agentRuntime?.id ?? "") !== CLAUDE_CLI_RUNTIME_ID) return () => false;
let n;
let r;
return (t, i) => {
if (t !== "anthropic" || normalizeProviderId(resolveModelRuntimePolicy({
config: e.cfg,
provider: t,
modelId: i,
agentId: e.agentId
}).policy?.id ?? "") !== CLAUDE_CLI_RUNTIME_ID) return false;
n ??= new Set(e.outcomes()?.flatMap((e) => e.provider === CLAUDE_CLI_RUNTIME_ID && e.listedModelIds !== void 0 ? e.listedModelIds : []));
r ??= resolveConfiguredModelEntries({
cfg: e.cfg,
agentId: e.agentId
}).byKey;
return !n.has(i) && !r.has(modelKey(t, i));
};
}
//#endregion
export { projectClaudeCliNativeCatalog as n, createUnlistedClaudeCliWildcardCheck as t };