UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 5.31 kB
import{t as normalizeOptionalSecretInput}from"../../normalize-secret-input-CEFJUjQX.mjs";import{a as resolveMergedModelProviderConfig}from"../../model-provider-config-DrdykcWe.mjs";import{n as buildApiKeyCredential,t as applyAuthProfileConfig}from"../../provider-auth-helpers-5o5rkp5c.mjs";import{a as SELF_HOSTED_DEFAULT_MAX_TOKENS,i as SELF_HOSTED_DEFAULT_COST,r as SELF_HOSTED_DEFAULT_CONTEXT_WINDOW}from"../../provider-self-hosted-discovery-BFyANiu_.mjs";import{t as applyProviderDefaultModel}from"../../provider-setup-BwWnv6lb.mjs";import{t as applyProviderAuthConfigPatch}from"../../provider-auth-Czspvb3-.mjs";import{r as persistProviderApiKey,t as captureProviderApiKey}from"../../provider-api-key-auth-BXg13tJg.mjs";import"../../provider-auth-api-key-Zmh0L12P.mjs";import"../../provider-catalog-shared-pOPyBmVF.mjs";import{n as normalizeBifrostBaseUrl,r as tryNormalizeBifrostBaseUrl,t as BIFROST_BASE_URL}from"../../defaults-DEkAvIu1.mjs";import{t as listBifrostModels}from"../../models-a-yKu0qm.mjs";import{n as buildBifrostConnectionConfig,t as applyBifrostModelConfig}from"../../onboard-Bld7KKBY.mjs"; //!extensions/bifrost/setup.ts function manualModel(e,t){return e.models?.providers?.bifrost?.models.find(e=>e.id===t)??{id:t,name:t,reasoning:false,input:[`text`],cost:SELF_HOSTED_DEFAULT_COST,contextWindow:128e3,maxTokens:SELF_HOSTED_DEFAULT_MAX_TOKENS}}async function configureBifrostInteractive(e){const t=resolveMergedModelProviderConfig(e.config,`bifrost`)?.baseUrl;const n=normalizeBifrostBaseUrl(await e.prompter.text({message:`Bifrost gateway base URL`,initialValue:t,placeholder:`http://localhost:8080/openai/v1`,validate:e=>{if(!e.trim())return;return tryNormalizeBifrostBaseUrl(e)?void 0:`Enter an HTTP or HTTPS gateway URL`}})||t||`http://localhost:8080/openai/v1`);const r=normalizeOptionalSecretInput(e.opts?.bifrostApiKey);const i=r??normalizeOptionalSecretInput(e.opts?.token);const a=i||await e.prompter.confirm({message:`Does this Bifrost gateway require a virtual key?`,initialValue:false})?await captureProviderApiKey(e,{provider:`bifrost`,expectedProviders:[`bifrost`],envLabel:`BIFROST_VIRTUAL_KEY`,promptMessage:`Enter Bifrost virtual key`,token:i,tokenProvider:r?`bifrost`:normalizeOptionalSecretInput(e.opts?.tokenProvider),env:e.env}):void 0;let o=applyProviderAuthConfigPatch(e.config,buildBifrostConnectionConfig(e.config,n,!a));let s;if(!e.credentialOnly){let t=[];try{t=(await listBifrostModels({config:o,apiKey:a?.apiKey,env:e.env,signal:e.signal,beforeRequest:e.assertCurrent})).models.filter(e=>e.inference?.chat!==false&&e.inference?.chatEvidence!==`unlikely`)}catch{}e.signal?.throwIfAborted();e.assertCurrent?.();const n=t.length?await e.prompter.select({message:`Bifrost model`,initialValue:t[0]?.id,options:[...t.map(e=>({value:e.id,label:e.name})),{value:``,label:`Enter model ID manually`}]}):``;if(!t.length)await e.prompter.note(`No declared chat models were discovered. Check the gateway URL and authentication, or enter a known chat model ID manually.`,`Bifrost models`);const r=n||(await e.prompter.text({message:`Bifrost model ID`,placeholder:`Model ID served by your gateway, such as ollama/qwen3:4b`,validate:e=>e.trim()?void 0:`Model ID is required`})).trim();s=t.find(e=>e.id===r)??manualModel(o,r);o=applyBifrostModelConfig(o,s)}return{profiles:a?[{profileId:`bifrost:default`,credential:buildApiKeyCredential(`bifrost`,a.input,void 0,{secretInputMode:a.mode,config:o})}]:[],configPatch:buildBifrostConnectionConfig(o,n,!a),...s?{defaultModel:`bifrost/${s.id}`}:{}}}async function configureBifrostNonInteractive(e){const t=tryNormalizeBifrostBaseUrl(normalizeOptionalSecretInput(e.opts.customBaseUrl)||resolveMergedModelProviderConfig(e.config,`bifrost`)?.baseUrl||`http://localhost:8080/openai/v1`);const n=resolveMergedModelProviderConfig(e.config,`bifrost`);const r=normalizeOptionalSecretInput(e.opts.bifrostApiKey??e.opts.customApiKey);const i=e.opts.customNoAuth===true||n?.auth===`none`&&!r;const a=i?null:await e.resolveApiKey({provider:`bifrost`,flagValue:r,allowProfile:t!==void 0&&(!n||tryNormalizeBifrostBaseUrl(n.baseUrl)===t),flagName:`--bifrost-api-key`,envVar:`BIFROST_VIRTUAL_KEY`,required:false});if(!t){e.runtime.error(`The Bifrost gateway URL must be a full http:// or https:// URL, such as ${BIFROST_BASE_URL}.`);e.runtime.exit(1);return null}if(!a&&!i){e.runtime.error(`Bifrost requires a virtual key or --custom-no-auth for anonymous inference.`);e.runtime.exit(1);return null}let o=applyProviderAuthConfigPatch(e.config,buildBifrostConnectionConfig(e.config,t,!a));const s=normalizeOptionalSecretInput(e.opts.customModelId);let c=s?manualModel(o,s):void 0;if(!c)try{c=(await listBifrostModels({config:o,apiKey:a?.key})).models.find(e=>e.inference?.chat!==false&&e.inference?.chatEvidence!==`unlikely`)}catch{}if(!c){e.runtime.error(`No Bifrost chat models were discovered. Check the gateway or pass --custom-model-id for a known chat model.`);e.runtime.exit(1);return null}if(a){if(!await persistProviderApiKey(e,`bifrost:default`,{provider:`bifrost`,resolved:a}))return null;o=applyAuthProfileConfig(o,{profileId:`bifrost:default`,provider:`bifrost`,mode:`api_key`})}return applyProviderDefaultModel(applyBifrostModelConfig(o,c),`bifrost/${c.id}`)}export{configureBifrostInteractive,configureBifrostNonInteractive};