UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.85 kB
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import"./utils-Dlk0IYAa.mjs";import{f as listProfilesForProvider}from"./order-B8e_5ABM.mjs";import{n as externalCliDiscoveryForProviderAuth}from"./external-cli-discovery-CHmIqgrd.mjs";import{i as ensureAuthProfileStoreAsync}from"./store-runtime-GNz-2GjY.mjs";import{n as resolveCodexNativeWebSearchConfig}from"./codex-native-web-search.shared-D0HrvhGP.mjs";import{t as resolveWebSearchToolPolicy}from"./web-search-tool-policy-BGyjGAPF.mjs"; //!src/agents/codex-native-web-search-core.ts 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`)}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}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}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}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`}}export{resolveCodexNativeSearchActivation as a,patchCodexNativeWebSearchPayload as i,isCodexNativeSearchEligibleModel as n,isNativeWebSearchAllowedByToolPolicy as r,hasAvailableCodexAuth as t};