UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

104 lines (103 loc) • 4.28 kB
import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs"; import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs"; import "./session-key-CqAyZeVk.mjs"; import { o as resolveAgentEntry } from "./agent-scope-config-DmXgFGKP.mjs"; import { a as normalizeOptionalAgentRuntimeId, r as isDefaultAgentRuntimeId } from "./agent-runtime-id-D8s1CaYB.mjs"; import { n as resolveModelRouteIntent, r as resolveModelRuntimePolicy, t as resolveAgentRuntimePolicyAgentId } from "./model-runtime-policy-Cfudvy7O.mjs"; import { u as resolveOpenAIModelRoutes } from "./model-catalog-entry-pfJ-_t4l.mjs"; import { t as canonicalizeProviderModelId } from "./provider-model-route-hB9HZIqE.mjs"; import { n as resolveDefaultModelForAgent } from "./model-selection-config-Bvf5WqHo.mjs"; import { t as hasAuthoredProviderRequestParams } from "./model-extra-params-D2Glrj-b.mjs"; //#region src/agents/openai-routing.ts /** * OpenAI provider routing decisions shared by model selection, auth profiles, and runtime setup. * * Custom OpenAI-compatible base URLs intentionally bypass Codex-runtime defaults. */ /** Canonical provider id for OpenAI-hosted model routes. */ const OPENAI_PROVIDER_ID = "openai"; /** Returns true for provider ids that normalize to OpenAI. */ function isOpenAIProvider(e) { return normalizeProviderId(e ?? "") === OPENAI_PROVIDER_ID; } /** Canonicalizes shipped OpenAI model aliases at runtime boundaries. */ function canonicalizeOpenAIModelId(e, t) { return isOpenAIProvider(e) ? canonicalizeProviderModelId(OPENAI_PROVIDER_ID, t) : t; } /** Resolves the provider-owned implicit runtime for one concrete OpenAI route. */ function resolveOpenAIImplicitAgentRuntime(e, t) { if (!isOpenAIProvider(e.provider)) return null; const n = e.modelId; const r = resolveAgentRuntimePolicyAgentId(e); const i = e.config ? resolveDefaultModelForAgent({ cfg: e.config, agentId: r, allowManifestNormalization: false, allowPluginNormalization: false }) : void 0; const a = hasAuthoredProviderRequestParams({ config: e.config, provider: e.provider ?? "openai", modelId: n, agentId: r }); const o = e.requestTransportOverrides === "present" || a ? "present" : "none"; const s = resolveOpenAIModelRoutes({ provider: e.provider, modelId: n, api: e.api, baseUrl: e.baseUrl, config: e.config, env: e.env, agentId: r, requestTransportOverrides: o, primaryModel: i, routeIntent: e.routeIntent ?? resolveModelRouteIntent({ ...e, primaryModel: i }) }, t); if (!s) return "openclaw"; return s.kind !== "incompatible" && s.defaultRuntimeId === "codex" ? "codex" : "openclaw"; } /** Parses the provider portion from a provider/model ref. */ function parseModelRefProvider(e) { if (typeof e !== "string") return; const t = e.trim().indexOf("/"); if (t <= 0) return; return normalizeProviderId(e.trim().slice(0, t)); } /** Reads the retired whole-agent runtime opt-out from pre-admission plugin-setup config. */ function resolveRetiredAgentRuntimeOptOut(e) { const t = e.agentId ? normalizeAgentId(e.agentId) : void 0; const n = t && e.config ? resolveAgentEntry(e.config, t) : void 0; return normalizeOptionalAgentRuntimeId(n?.agentRuntime?.id ?? e.config?.agents?.defaults?.agentRuntime?.id); } /** Returns true when selected model config should ensure the Codex plugin exists. */ function modelSelectionShouldEnsureCodexPlugin(e) { const t = parseModelRefProvider(e.model); if (t !== "openai") return false; const n = e.model?.trim(); const r = n?.indexOf("/") ?? -1; const i = r >= 0 ? n?.slice(r + 1) : void 0; const a = resolveModelRuntimePolicy({ config: e.config, provider: t, modelId: i, agentId: e.agentId }).policy; const o = normalizeOptionalAgentRuntimeId(a?.id); if (o && !isDefaultAgentRuntimeId(o)) return o === "codex"; if (!a) { const t = resolveRetiredAgentRuntimeOptOut(e); if (t && !isDefaultAgentRuntimeId(t)) return t === "codex"; } return resolveOpenAIImplicitAgentRuntime({ provider: t, modelId: i, config: e.config, agentId: e.agentId }) === "codex"; } //#endregion export { parseModelRefProvider as a, modelSelectionShouldEnsureCodexPlugin as i, canonicalizeOpenAIModelId as n, resolveOpenAIImplicitAgentRuntime as o, isOpenAIProvider as r, OPENAI_PROVIDER_ID as t };