openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
74 lines (73 loc) • 3.6 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import "./utils-C8YECn2Q.mjs";
import { f as listProfilesForProvider } from "./order-jOvee2J6.mjs";
import { n as externalCliDiscoveryForProviderAuth } from "./external-cli-discovery-DZ419koV.mjs";
import { i as ensureAuthProfileStoreAsync } from "./store-runtime-dW0pXLJI.mjs";
import { n as resolveCodexNativeWebSearchConfig } from "./codex-native-web-search.shared-BYcLEL59.mjs";
import { t as resolveWebSearchToolPolicy } from "./web-search-tool-policy-CLuhTMnE.mjs";
//#region src/agents/codex-native-web-search-core.ts
/** Returns whether a model API can accept the native Codex web_search tool. */
function isCodexNativeSearchEligibleModel(e) {
return e.modelApi === "openai-chatgpt-responses";
}
function hasCodexNativeWebSearchTool(e) {
if (!Array.isArray(e)) return false;
return e.some((e) => isRecord(e) && e.type === "web_search");
}
/** Checks whether OpenAI/Codex auth is available for native web search. */
async function hasAvailableCodexAuth(e) {
if (e.authStore) return listProfilesForProvider(e.authStore, "openai").length > 0;
if (Object.values(e.config?.auth?.profiles ?? {}).some((e) => e.provider === "openai" && (e.mode === "oauth" || e.mode === "token"))) return true;
if (e.agentDir) try {
const t = await ensureAuthProfileStoreAsync(e.agentDir, { externalCli: externalCliDiscoveryForProviderAuth({
cfg: e.config,
provider: "openai"
}) });
if (listProfilesForProvider(t, "openai").length > 0) return true;
} catch {}
return false;
}
/** Resolves whether native search is active or why managed search should remain. */
function resolveCodexNativeSearchActivation(e) {
const t = e.webSearchEnabled !== false && e.config?.tools?.web?.search?.enabled !== false;
const n = resolveCodexNativeWebSearchConfig(e.config);
const r = isCodexNativeSearchEligibleModel(e);
const i = e.config?.tools?.web?.search?.provider?.trim().toLowerCase();
const a = Boolean(i && i !== "auto" && i !== "openai");
const o = !t ? "globally_disabled" : !n.enabled ? "codex_not_enabled" : a ? "managed_provider_selected" : !r ? "model_not_eligible" : !isNativeWebSearchAllowedByToolPolicy(e) ? "tool_policy_denied" : void 0;
return {
codexNativeEnabled: n.enabled,
state: o ? "managed_only" : "native_active",
...o ? { inactiveReason: o } : {}
};
}
function isNativeWebSearchAllowedByToolPolicy(e) {
return resolveWebSearchToolPolicy(e).allowed;
}
/** Builds the OpenAI Responses `web_search` tool payload from config. */
function buildCodexNativeWebSearchTool(e) {
const t = resolveCodexNativeWebSearchConfig(e);
const n = {
type: "web_search",
external_web_access: t.mode === "live"
};
if (t.allowedDomains) n.filters = { allowed_domains: t.allowedDomains };
if (t.contextSize) n.search_context_size = t.contextSize;
if (t.userLocation) n.user_location = {
type: "approximate",
...t.userLocation
};
return n;
}
/** Injects a native Codex web-search tool into a mutable provider payload. */
function patchCodexNativeWebSearchPayload(e) {
if (!isRecord(e.payload)) return { status: "payload_not_object" };
const t = e.payload;
if (hasCodexNativeWebSearchTool(t.tools)) return { status: "native_tool_already_present" };
const n = Array.isArray(t.tools) ? [...t.tools] : [];
n.push(buildCodexNativeWebSearchTool(e.config));
t.tools = n;
return { status: "injected" };
}
//#endregion
export { resolveCodexNativeSearchActivation as a, patchCodexNativeWebSearchPayload as i, isCodexNativeSearchEligibleModel as n, isNativeWebSearchAllowedByToolPolicy as r, hasAvailableCodexAuth as t };