UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.15 kB
import{a as resolveMergedModelProviderConfig,n as createModelProviderRouteOverrideResolver,r as findConfiguredProviderModel}from"./model-provider-config-DrdykcWe.mjs";import{n as projectConfigOntoRuntimeSourceSnapshot}from"./runtime-source-projection-DvPkX_nq.mjs";import{r as resolveModelRuntimePolicy}from"./model-runtime-policy-DJvvlwBk.mjs";import{t as canonicalizeProviderModelId}from"./provider-model-route-DWFdzg4M.mjs";import{t as hasAuthoredProviderRequestParams}from"./model-extra-params-CALSEb0J.mjs";import{p as resolveProviderRefOwnership}from"./providers-CcG8xzp1.mjs";import{t as buildAgentRuntimeAuthPlan}from"./auth-Nd9p3rup.mjs"; //!src/agents/model-native-command-auth.ts function resolveNativeCommandAuthRoute(e){const t=resolveMergedModelProviderConfig(e.config,e.provider);if(t?.auth!==`native-command`)return;const unsupported=e=>({supported:false,reason:e});if((e.providerOwnership??resolveProviderRefOwnership(e)).status!==`unowned`)return unsupported(`Native command auth requires an unowned custom provider ID`);const n=resolveModelRuntimePolicy(e);if(n.forcedByEnvironment||n.policy?.id!==`codex`)return unsupported(`Native command auth requires an explicit Codex model or provider runtime`);if(t.apiKey!==void 0)return unsupported(`Native command auth cannot be combined with an API key or profile binding`);const r=e.modelId?findConfiguredProviderModel(t,e.provider,e.modelId,t=>canonicalizeProviderModelId(e.provider,t)):void 0;const i=r?.api??t.api;const a=r?.baseUrl??t.baseUrl;const o=URL.parse(a);if(!r||i!==`openai-responses`||o?.protocol!==`https:`||o.username||o.password||o.hash||e.api!=null&&e.api!==i||e.baseUrl!=null&&e.baseUrl!==a)return unsupported(`Native command auth requires the configured HTTPS Responses endpoint and model`);const s=e.config&&projectConfigOntoRuntimeSourceSnapshot(e.config);if(createModelProviderRouteOverrideResolver({provider:e.provider,authoredConfig:s,canonicalizeModelId:t=>canonicalizeProviderModelId(e.provider,t)})(e.modelId)===`present`||hasAuthoredProviderRequestParams({...e,modelId:e.modelId}))return unsupported(`Native command auth cannot reproduce authored request transport overrides`);return{supported:true,runtimeId:`codex`,api:i,baseUrl:a}}function prepareNativeCommandAuth(e){const t=resolveNativeCommandAuthRoute({...e,api:e.modelApi,baseUrl:e.modelBaseUrl});if(t){if(!t.supported)throw new Error(t.reason);if(e.harnessId!==t.runtimeId||e.harnessAuthBootstrap!==`harness`)throw new Error(`Native command auth requires an explicit Codex harness runtime`);if(e.requiredAuthProfileId||e.sessionAuthProfileId)throw new Error(`Native command auth cannot be combined with an auth profile binding`);if(e.requestTransportOverrides===`present`||e.observedRoutes?.some(e=>e.api!==t.api||e.baseUrl!==t.baseUrl))throw new Error(`Native command auth cannot reproduce the observed provider route`);const n={...buildAgentRuntimeAuthPlan({...e,allowHarnessAuthProfileForwarding:false,credentialSource:{kind:`none`}}),selectedAuthMode:`native-command`};return{plan:n,attempts:[{kind:`implicit`,plan:n}]}}}export{resolveNativeCommandAuthRoute as n,prepareNativeCommandAuth as t};