openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
225 lines (224 loc) • 7.71 kB
JavaScript
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs";
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs";
import { i as parseModelCatalogRef } from "./model-catalog-refs-Bk2MNoCv.mjs";
import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs";
import "./session-key-CqAyZeVk.mjs";
import { i as listAgentIds, s as readAgentRosterProperty } from "./agent-roster-t1ooUdXp.mjs";
import { b as resolveNativeModelPrimary, r as resolveAgentConfig } from "./agent-scope-config-DmXgFGKP.mjs";
import { r as collectConfiguredModelRefs } from "./configured-model-refs-DtaDJ1Vw.mjs";
import { o as resolveAgentModelFallbackValues } from "./model-input-DrM4DWHG.mjs";
import { l as resolveAgentModelFallbacksOverride } from "./agent-scope-BwB8YH6y.mjs";
import { a as normalizeOptionalAgentRuntimeId, r as isDefaultAgentRuntimeId } from "./agent-runtime-id-D8s1CaYB.mjs";
import { r as resolveModelRuntimePolicy } from "./model-runtime-policy-Cfudvy7O.mjs";
import { b as readUtilityModelSetting, i as buildModelAliasIndex, y as resolveModelRefFromString } from "./model-selection-shared-9Kz63Hhm.mjs";
import { a as resolveSubagentConfiguredModelSelection, n as resolveDefaultModelForAgent, r as resolveEffectiveModelFallbacks } from "./model-selection-config-Bvf5WqHo.mjs";
import { o as resolveOpenAIImplicitAgentRuntime } from "./openai-routing-Dakz1nVk.mjs";
//#region src/config/codex-plugin-diagnostics.ts
const CODEX_PLUGIN_ID = "codex";
const OPENAI_PROVIDER_ID = "openai";
function codexPluginEntryEnabled(e) {
for (const [t, n] of Object.entries(e.plugins?.entries ?? {})) if (normalizeLowercaseStringOrEmpty(t) === CODEX_PLUGIN_ID) return n?.enabled;
}
function configuredRuntimeNeedsCodex(e) {
const t = normalizeOptionalAgentRuntimeId(e.runtimeId);
if (t === CODEX_PLUGIN_ID) return true;
if (!isDefaultAgentRuntimeId(t)) return false;
return resolveOpenAIImplicitAgentRuntime({
provider: OPENAI_PROVIDER_ID,
modelId: e.modelId,
config: e.cfg,
agentId: e.agentId,
env: e.env
}) === CODEX_PLUGIN_ID;
}
/** Resolves effective runtime policy for one canonical provider/model route. */
function configuredModelRouteNeedsCodex(e) {
if (normalizeProviderId(e.route.provider) !== OPENAI_PROVIDER_ID) return false;
const t = resolveModelRuntimePolicy({
config: e.cfg,
provider: OPENAI_PROVIDER_ID,
modelId: e.route.modelId,
agentId: e.agentId
}).policy?.id;
return configuredRuntimeNeedsCodex({
cfg: e.cfg,
env: e.env,
agentId: e.agentId,
modelId: e.route.modelId,
runtimeId: t
});
}
function resolveEffectiveSelectedModelRefs(e) {
const { cfg: t, agentId: n } = e;
const r = resolveNativeModelPrimary(t, n);
const i = resolveAgentModelFallbacksOverride(t, n) ?? resolveAgentModelFallbackValues(t.agents?.defaults?.model);
const a = resolveSubagentConfiguredModelSelection({
cfg: t,
agentId: n
}) ?? r;
const o = resolveEffectiveModelFallbacks({
cfg: t,
agentId: n,
sessionKey: `agent:${n}:subagent:codex-diagnostic`,
hasSessionModelOverride: true,
modelOverrideSource: "auto"
}) ?? [];
const s = /* @__PURE__ */ new Set();
for (const e of [
r,
...i,
a,
...o
]) {
const t = e?.trim();
if (t) s.add(t);
}
return {
complete: Boolean(r?.trim() && a?.trim()),
values: s
};
}
function configuredRefTargetsAgent(e) {
const t = /^agents\.list\.(\d+)\./.exec(e.path);
if (t) {
const n = readAgentRosterProperty(e.sourceConfigBeforeMigrations ?? e.cfg);
const r = n?.kind === "list" && Array.isArray(n.value) ? n.value[Number(t[1])] : void 0;
return isRecord(r) && typeof r.id === "string" && normalizeAgentId(r.id) === e.agentId;
}
const n = /^agents\.entries\.([^.]+)\./.exec(e.path);
return !n || normalizeAgentId(n[1] ?? "") === e.agentId;
}
function configuredRefIsEffectiveForAgent(e) {
if (!configuredRefTargetsAgent(e)) return false;
if (/^agents\.(?:defaults|list\.\d+|entries\.[^.]+)\.(?:model|subagents\.model)(?:\.|$)/.test(e.path)) return e.selectedModelRefs.has(e.value);
if (e.path.endsWith(".heartbeat.model")) return (resolveAgentConfig(e.cfg, e.agentId)?.heartbeat?.model?.trim() || e.cfg.agents?.defaults?.heartbeat?.model?.trim()) === e.value;
if (/\.utilityModel(?:\.|$)/.test(e.path)) {
const t = readUtilityModelSetting(e.cfg, e.agentId);
return t.kind !== "disabled" && (t.kind === "explicit" && t.modelRef === e.value || t.fallbacks.some((t) => t.trim() === e.value));
}
return true;
}
function configuredProviderPoliciesNeedCodex(e, t, n) {
for (const r of n) {
const n = resolveModelRuntimePolicy({
config: e,
provider: OPENAI_PROVIDER_ID,
agentId: r
}).policy;
if (n?.id?.trim() && configuredRuntimeNeedsCodex({
cfg: e,
env: t,
agentId: r,
runtimeId: n.id
})) return true;
}
for (const [r, i] of Object.entries(e.models?.providers ?? {})) {
if (normalizeProviderId(r) !== OPENAI_PROVIDER_ID) continue;
for (const r of i.models ?? []) {
if (!r.agentRuntime?.id?.trim()) continue;
const i = parseModelCatalogRef(r.id);
const a = i?.provider === OPENAI_PROVIDER_ID ? i.modelId : r.id.trim();
if (a && a !== "*" && n.some((n) => configuredModelRouteNeedsCodex({
cfg: e,
env: t,
agentId: n,
route: {
provider: OPENAI_PROVIDER_ID,
modelId: a
}
}))) return true;
}
}
return false;
}
function configuredModelRefsNeedCodex(e) {
const t = collectConfiguredModelRefs(e.sourceConfigBeforeMigrations ?? e.cfg);
let n = true;
for (const r of e.agentIds) {
const i = resolveEffectiveSelectedModelRefs({
cfg: e.cfg,
agentId: r
});
n &&= i.complete;
const a = resolveDefaultModelForAgent({
cfg: e.cfg,
agentId: r,
manifestPlugins: []
});
const o = buildModelAliasIndex({
cfg: e.cfg,
defaultProvider: a.provider,
manifestPlugins: []
});
for (const s of t) {
if (s.capability === "decision" || !configuredRefIsEffectiveForAgent({
cfg: e.cfg,
sourceConfigBeforeMigrations: e.sourceConfigBeforeMigrations,
path: s.path,
value: s.value,
agentId: r,
selectedModelRefs: i.values
})) continue;
const t = resolveModelRefFromString({
cfg: e.cfg,
raw: s.value,
defaultProvider: a.provider,
aliasIndex: o,
allowManifestNormalization: false
});
const c = t ? {
provider: t.ref.provider,
modelId: t.ref.model
} : void 0;
if (c && configuredModelRouteNeedsCodex({
cfg: e.cfg,
env: e.env,
agentId: r,
route: c
})) return {
complete: n,
needsCodex: true
};
}
}
return {
complete: n,
needsCodex: false
};
}
function defaultOpenAiRouteNeedsCodex(e, t, n) {
return n.some((n) => {
const r = resolveModelRuntimePolicy({
config: e,
provider: OPENAI_PROVIDER_ID,
agentId: n
}).policy?.id;
return configuredRuntimeNeedsCodex({
cfg: e,
env: t,
agentId: n,
runtimeId: r
});
});
}
function configNeedsCodexForOpenAi(e, t, n) {
const r = listAgentIds(e);
const i = configuredModelRefsNeedCodex({
cfg: e,
env: t,
agentIds: r,
sourceConfigBeforeMigrations: n
});
if (i.needsCodex) return true;
if (configuredProviderPoliciesNeedCodex(e, t, r)) return true;
return i.complete ? false : defaultOpenAiRouteNeedsCodex(e, t, r);
}
/** Suppresses missing Codex diagnostics when no effective OpenAI route selects it. */
function shouldSuppressMissingCodexPluginDiagnostics(e, t = process.env, n) {
const r = codexPluginEntryEnabled(e);
if (r === true) return false;
return r === false || !configNeedsCodexForOpenAi(e, t, n);
}
//#endregion
export { shouldSuppressMissingCodexPluginDiagnostics as n, configuredModelRouteNeedsCodex as t };