import{t as e}from"./rolldown-runtime-CNxR59P3.js";import{K as t,Kl as n,M as r,O as i,Tt as a,Ul as o,X as s,Yl as c,at as l,bs as u,bt as d,g as f,go as p,it as m,nu as h,vs as ee,xs as te,ys as ne,yt as g}from"./model-selection-p21GBPS6.js";import{F as _,a as re,d as ie,f as v,j as ae}from"./agent-scope-DW6ZDCxj.js";import{n as oe}from"./model-catalog-CH3Up6he.js";import{f as y}from"./onboard-helpers-lK6pmfqQ.js";import{t as se}from"./enable-De_FYckP.js";import{a as b,c as ce,d as x,f as S,i as C,l as w,n as T,o as le,s as ue,t as E,u as de}from"./auth-choice.apply-helpers-CSr3csU8.js";import{n as fe,t as D}from"./openai-codex-model-default-B5TBE2IR.js";import{$ as pe,A as me,At as he,B as ge,C as _e,Ct as ve,D as ye,Dt as be,E as xe,Et as Se,F as Ce,Ft as O,G as we,H as Te,I as Ee,It as k,J as De,K as Oe,L as ke,Lt as A,M as Ae,Mt as j,N as je,Nt as M,O as Me,Ot as Ne,P as Pe,Pt as N,Q as Fe,R as Ie,Rt as P,S as Le,St as F,T as Re,Tt as ze,U as Be,V as Ve,W as He,X as Ue,Y as We,Z as Ge,_ as I,_t as L,a as R,at as z,b as Ke,bt as qe,c as Je,ct as Ye,d as Xe,dt as Ze,et as Qe,f as $e,ft as et,gt as tt,h as B,ht as nt,i as rt,it as V,j as it,jt as at,k as ot,kt as st,l as ct,lt,m as ut,mt as dt,n as H,nt as U,ot as ft,p as pt,pt as mt,q as ht,r as gt,rt as W,s as _t,st as vt,t as yt,tt as bt,u as xt,ut as St,v as Ct,vt as G,w as wt,wt as Tt,x as Et,xt as Dt,y as Ot,yt as kt,z as At}from"./auth-token-KE_i2bMo.js";import{n as K,t as q}from"./oauth-env-DSLBTWb1.js";import{a as jt,c as Mt,i as Nt,n as Pt,o as J,r as Ft,s as It,t as Lt}from"./provider-auth-helpers-DP6PsUfa.js";import{a as Y,i as Rt,n as zt,o as Bt,r as Vt,t as X}from"./openai-model-default-BDHHfSs8.js";import{r as Z,s as Ht}from"./model-picker-CVTiccWc.js";import{i as Ut,n as Wt}from"./ollama-setup-CCMVRp6u.js";import{randomBytes as Gt}from"node:crypto";import{createServer as Kt}from"node:http";const qt=`anthropic/claude-sonnet-4-6`;async function Jt(e){let t=b(e.opts?.secretInputMode);if(e.authChoice===`setup-token`||e.authChoice===`oauth`||e.authChoice===`token`){let r=e.config;await e.prompter.note(["Run `claude setup-token` in your terminal.",`Then paste the generated token below.`].join(`
`),`Anthropic setup-token`);let i=await ce({prompter:e.prompter,explicitMode:t,copy:{modeMessage:`How do you want to provide this setup token?`,plaintextLabel:`Paste setup token now`,plaintextHint:`Stores the token directly in the auth profile`}}),a=``,o;if(i===`ref`){let t=await ue({provider:`anthropic-setup-token`,config:e.config,prompter:e.prompter,preferredEnvVar:`ANTHROPIC_SETUP_TOKEN`,copy:{sourceMessage:`Where is this Anthropic setup token stored?`,envVarPlaceholder:`ANTHROPIC_SETUP_TOKEN`}});a=t.resolvedValue.trim(),o=t.ref}else{let t=await e.prompter.text({message:`Paste Anthropic setup-token`,validate:e=>H(String(e??``))});a=String(t??``).trim()}let s=H(a);if(s)throw Error(s);let c=await e.prompter.text({message:`Token name (blank = default)`,placeholder:`default`}),l=`anthropic`,u=yt({provider:l,name:String(c??``)});return n({profileId:u,agentDir:e.agentDir,credential:{type:`token`,provider:l,token:a,...o?{tokenRef:o}:{}}}),r=B(r,{profileId:u,provider:l,mode:`token`}),e.setDefaultModel&&(r=K(r,qt)),{config:r}}if(e.authChoice===`apiKey`){if(e.opts?.tokenProvider&&e.opts.tokenProvider!==`anthropic`)return null;let n=e.config;return await C({token:e.opts?.token,tokenProvider:e.opts?.tokenProvider??`anthropic`,secretInputMode:t,config:n,expectedProviders:[`anthropic`],provider:`anthropic`,envLabel:`ANTHROPIC_API_KEY`,promptMessage:`Enter Anthropic API key`,normalize:x,validate:S,prompter:e.prompter,setCredential:async(t,n)=>vt(t,e.agentDir,{secretInputMode:n})}),n=B(n,{profileId:`anthropic:default`,provider:`anthropic`,mode:`api_key`}),e.setDefaultModel&&(n=K(n,qt)),{config:n}}return null}async function Yt(e){if(e.authChoice!==`huggingface-api-key`)return null;let t=e.config,n,r=E(e),i=b(e.opts?.secretInputMode),a=await C({token:e.opts?.token,tokenProvider:e.opts?.tokenProvider,secretInputMode:i,config:t,expectedProviders:[`huggingface`],provider:`huggingface`,envLabel:`Hugging Face token`,promptMessage:`Enter Hugging Face API key (HF token)`,normalize:x,validate:S,prompter:e.prompter,setCredential:async(t,n)=>Ze(t,e.agentDir,{secretInputMode:n}),noteMessage:[`Hugging Face Inference Providers offer OpenAI-compatible chat completions.`,`Create a token at: https://huggingface.co/settings/tokens (fine-grained, 'Make calls to Inference Providers').`].join(`
`),noteTitle:`Hugging Face`});t=B(t,{profileId:`huggingface:default`,provider:`huggingface`,mode:`api_key`});let o=await m(a),s=[];for(let e of o){let t=`huggingface/${e.id}`,n=e.name??e.id;s.push({value:t,label:n}),s.push({value:`${t}:cheapest`,label:`${n} (cheapest)`}),s.push({value:`${t}:fastest`,label:`${n} (fastest)`})}let c=Qe;s.sort((e,t)=>e.value===c?-1:t.value===c?1:e.label.localeCompare(t.label,void 0,{sensitivity:`base`}));let u=s.length===0?c:s.length===1?s[0].value:await e.prompter.select({message:`Default Hugging Face model`,options:s,initialValue:s.some(e=>e.value===c)?c:s[0].value});l(u)&&await e.prompter.note(`Provider locked — router will choose backend by cost or speed.`,`Hugging Face`);let d=await w({config:t,setDefaultModel:e.setDefaultModel,defaultModel:u,applyDefaultConfig:e=>{let t=I(e),n=t.agents?.defaults?.model;return de({cfg:{...t,agents:{...t.agents,defaults:{...t.agents?.defaults,model:{...n&&typeof n==`object`&&`fallbacks`in n?{fallbacks:n.fallbacks}:{},primary:u}}}},modelRef:u})},applyProviderConfig:I,noteDefault:u,noteAgentModel:r,prompter:e.prompter});return t=d.config,n=d.agentModelOverride??n,{config:t,agentModelOverride:n}}async function Xt(e){let t=e.config,n,r=E(e),i=b(e.opts?.secretInputMode),o=c(e.agentDir,{allowKeychainPrompt:!1}),s=a({cfg:t,store:o,provider:`openrouter`}).find(e=>!!o.profiles[e]),l=s?o.profiles[s]:void 0,u=`openrouter:default`,d=`api_key`,f=!1;s&&l?.type&&(u=s,d=l.type===`oauth`?`oauth`:l.type===`token`?`token`:`api_key`,f=!0),!f&&e.opts?.token&&e.opts?.tokenProvider===`openrouter`&&(await F(x(e.opts.token),e.agentDir,{secretInputMode:i}),f=!0),f||=(await C({token:e.opts?.token,tokenProvider:e.opts?.tokenProvider,secretInputMode:i,config:t,expectedProviders:[`openrouter`],provider:`openrouter`,envLabel:`OPENROUTER_API_KEY`,promptMessage:`Enter OpenRouter API key`,normalize:x,validate:S,prompter:e.prompter,setCredential:async(t,n)=>F(t,e.agentDir,{secretInputMode:n})}),!0),f&&(t=B(t,{profileId:u,provider:`openrouter`,mode:d}));let p=await w({config:t,setDefaultModel:e.setDefaultModel,defaultModel:U,applyDefaultConfig:Ae,applyProviderConfig:je,noteDefault:U,noteAgentModel:r,prompter:e.prompter});return t=p.config,n=p.agentModelOverride??n,{config:t,agentModelOverride:n}}const Zt=`opencode/claude-opus-4-6`,Qt={openrouter:`openrouter-api-key`,litellm:`litellm-api-key`,"vercel-ai-gateway":`ai-gateway-api-key`,"cloudflare-ai-gateway":`cloudflare-ai-gateway-api-key`,moonshot:`moonshot-api-key`,"kimi-code":`kimi-code-api-key`,"kimi-coding":`kimi-code-api-key`,google:`gemini-api-key`,zai:`zai-api-key`,xiaomi:`xiaomi-api-key`,synthetic:`synthetic-api-key`,venice:`venice-api-key`,together:`together-api-key`,huggingface:`huggingface-api-key`,mistral:`mistral-api-key`,opencode:`opencode-zen`,"opencode-go":`opencode-go`,kilocode:`kilocode-api-key`,qianfan:`qianfan-api-key`},$t={"zai-coding-global":`coding-global`,"zai-coding-cn":`coding-cn`,"zai-global":`global`,"zai-cn":`cn`},en={"ai-gateway-api-key":{provider:`vercel-ai-gateway`,profileId:`vercel-ai-gateway:default`,expectedProviders:[`vercel-ai-gateway`],envLabel:`AI_GATEWAY_API_KEY`,promptMessage:`Enter Vercel AI Gateway API key`,setCredential:be,defaultModel:V,applyDefaultConfig:Fe,applyProviderConfig:pe,noteDefault:V},"moonshot-api-key":{provider:`moonshot`,profileId:`moonshot:default`,expectedProviders:[`moonshot`],envLabel:`MOONSHOT_API_KEY`,promptMessage:`Enter Moonshot API key`,setCredential:G,defaultModel:k,applyDefaultConfig:Me,applyProviderConfig:me},"moonshot-api-key-cn":{provider:`moonshot`,profileId:`moonshot:default`,expectedProviders:[`moonshot`],envLabel:`MOONSHOT_API_KEY`,promptMessage:`Enter Moonshot API key (.cn)`,setCredential:G,defaultModel:k,applyDefaultConfig:ot,applyProviderConfig:it},"kimi-code-api-key":{provider:`kimi-coding`,profileId:`kimi-coding:default`,expectedProviders:[`kimi-code`,`kimi-coding`],envLabel:`KIMI_API_KEY`,promptMessage:`Enter Kimi Coding API key`,setCredential:mt,defaultModel:M,applyDefaultConfig:Ke,applyProviderConfig:Et,noteDefault:M,noteMessage:[`Kimi Coding uses a dedicated endpoint and API key.`,`Get your API key at: https://www.kimi.com/code/en`].join(`
`),noteTitle:`Kimi Coding`},"xiaomi-api-key":{provider:`xiaomi`,profileId:`xiaomi:default`,expectedProviders:[`xiaomi`],envLabel:`XIAOMI_API_KEY`,promptMessage:`Enter Xiaomi API key`,setCredential:he,defaultModel:z,applyDefaultConfig:He,applyProviderConfig:we,noteDefault:z},"mistral-api-key":{provider:`mistral`,profileId:`mistral:default`,expectedProviders:[`mistral`],envLabel:`MISTRAL_API_KEY`,promptMessage:`Enter Mistral API key`,setCredential:tt,defaultModel:N,applyDefaultConfig:Le,applyProviderConfig:_e,noteDefault:N},"venice-api-key":{provider:`venice`,profileId:`venice:default`,expectedProviders:[`venice`],envLabel:`VENICE_API_KEY`,promptMessage:`Enter Venice AI API key`,setCredential:Se,defaultModel:s,applyDefaultConfig:ge,applyProviderConfig:Ve,noteDefault:s,noteMessage:[`Venice AI provides privacy-focused inference with uncensored models.`,`Get your API key at: https://venice.ai/settings/api`,`Supports 'private' (fully private) and 'anonymized' (proxy) modes.`].join(`
`),noteTitle:`Venice AI`},"opencode-zen":{provider:`opencode`,profileId:`opencode:default`,expectedProviders:[`opencode`,`opencode-go`],envLabel:`OPENCODE_API_KEY`,promptMessage:`Enter OpenCode API key`,setCredential:Dt,defaultModel:Zt,applyDefaultConfig:_t,applyProviderConfig:Je,noteDefault:Zt,noteMessage:[`OpenCode uses one API key across the Zen and Go catalogs.`,`Zen provides access to Claude, GPT, Gemini, and more models.`,`Get your API key at: https://opencode.ai/auth`,`Choose the Zen catalog when you want the curated multi-model proxy.`].join(`
`),noteTitle:`OpenCode`},"opencode-go":{provider:`opencode-go`,profileId:`opencode-go:default`,expectedProviders:[`opencode`,`opencode-go`],envLabel:`OPENCODE_API_KEY`,promptMessage:`Enter OpenCode API key`,setCredential:qe,defaultModel:R,applyDefaultConfig:gt,applyProviderConfig:rt,noteDefault:R,noteMessage:[`OpenCode uses one API key across the Zen and Go catalogs.`,`Go provides access to Kimi, GLM, and MiniMax models through the Go catalog.`,`Get your API key at: https://opencode.ai/auth`,`Choose the Go catalog when you want the OpenCode-hosted Kimi/GLM/MiniMax lineup.`].join(`
`),noteTitle:`OpenCode`},"together-api-key":{provider:`together`,profileId:`together:default`,expectedProviders:[`together`],envLabel:`TOGETHER_API_KEY`,promptMessage:`Enter Together AI API key`,setCredential:ze,defaultModel:W,applyDefaultConfig:Ie,applyProviderConfig:At,noteDefault:W,noteMessage:[`Together AI provides access to leading open-source models including Llama, DeepSeek, Qwen, and more.`,`Get your API key at: https://api.together.xyz/settings/api-keys`].join(`
`),noteTitle:`Together AI`},"qianfan-api-key":{provider:`qianfan`,profileId:`qianfan:default`,expectedProviders:[`qianfan`],envLabel:`QIANFAN_API_KEY`,promptMessage:`Enter QIANFAN API key`,setCredential:ve,defaultModel:A,applyDefaultConfig:Pe,applyProviderConfig:Ce,noteDefault:A,noteMessage:[`Get your API key at: https://console.bce.baidu.com/qianfan/ais/console/apiKey`,`API key format: bce-v3/ALTAK-...`].join(`
`),noteTitle:`QIANFAN`},"kilocode-api-key":{provider:`kilocode`,profileId:`kilocode:default`,expectedProviders:[`kilocode`],envLabel:`KILOCODE_API_KEY`,promptMessage:`Enter Kilo Gateway API key`,setCredential:et,defaultModel:g,applyDefaultConfig:Ct,applyProviderConfig:Ot,noteDefault:g},"modelstudio-api-key-cn":{provider:`modelstudio`,profileId:`modelstudio:default`,expectedProviders:[`modelstudio`],envLabel:`MODELSTUDIO_API_KEY`,promptMessage:`Enter Alibaba Cloud Model Studio Coding Plan API key (China)`,setCredential:L,defaultModel:O,applyDefaultConfig:Re,applyProviderConfig:ye,noteDefault:O,noteMessage:[`Get your API key at: https://bailian.console.aliyun.com/`,`Endpoint: coding.dashscope.aliyuncs.com`,`Models: qwen3.5-plus, glm-4.7, kimi-k2.5, MiniMax-M2.5, etc.`].join(`
`),noteTitle:`Alibaba Cloud Model Studio Coding Plan (China)`,normalize:e=>String(e??``).trim(),validate:e=>String(e??``).trim()?void 0:`Required`},"modelstudio-api-key":{provider:`modelstudio`,profileId:`modelstudio:default`,expectedProviders:[`modelstudio`],envLabel:`MODELSTUDIO_API_KEY`,promptMessage:`Enter Alibaba Cloud Model Studio Coding Plan API key (Global/Intl)`,setCredential:L,defaultModel:O,applyDefaultConfig:wt,applyProviderConfig:xe,noteDefault:O,noteMessage:[`Get your API key at: https://bailian.console.aliyun.com/`,`Endpoint: coding-intl.dashscope.aliyuncs.com`,`Models: qwen3.5-plus, glm-4.7, kimi-k2.5, MiniMax-M2.5, etc.`].join(`
`),noteTitle:`Alibaba Cloud Model Studio Coding Plan (Global/Intl)`,normalize:e=>String(e??``).trim(),validate:e=>String(e??``).trim()?void 0:`Required`},"synthetic-api-key":{provider:`synthetic`,profileId:`synthetic:default`,expectedProviders:[`synthetic`],envLabel:`SYNTHETIC_API_KEY`,promptMessage:`Enter Synthetic API key`,setCredential:Tt,defaultModel:t,applyDefaultConfig:Ee,applyProviderConfig:ke,normalize:e=>String(e??``).trim(),validate:e=>String(e??``).trim()?void 0:`Required`}};async function tn(e){let t=e.config,n,r=E(e),i=T(e,()=>t,e=>t=e,()=>n,e=>n=e),o=e.authChoice,s=le(e.opts?.tokenProvider),l=b(e.opts?.secretInputMode);o===`apiKey`&&e.opts?.tokenProvider&&s!==`anthropic`&&s!==`openai`&&(o=Qt[s??``]??o);async function u({provider:r,profileId:a,expectedProviders:o,envLabel:c,promptMessage:u,setCredential:d,defaultModel:f,applyDefaultConfig:p,applyProviderConfig:m,noteMessage:h,noteTitle:ee,tokenProvider:te=s,normalize:ne=x,validate:g=S,noteDefault:_=f}){return await C({token:e.opts?.token,provider:r,tokenProvider:te,secretInputMode:l,config:t,expectedProviders:o,envLabel:c,promptMessage:u,setCredential:async(e,t)=>{await d(e,t)},noteMessage:h,noteTitle:ee,normalize:ne,validate:g,prompter:e.prompter}),t=B(t,{profileId:a,provider:r,mode:`api_key`}),await i({defaultModel:f,applyDefaultConfig:p,applyProviderConfig:m,noteDefault:_}),{config:t,agentModelOverride:n}}if(o===`openrouter-api-key`)return Xt(e);if(o===`litellm-api-key`){let r=c(e.agentDir,{allowKeychainPrompt:!1}),o=a({cfg:t,store:r,provider:`litellm`}).find(e=>!!r.profiles[e]),u=o?r.profiles[o]:void 0,d=`litellm:default`,f=!!(o&&u?.type===`api_key`);return f&&o&&(d=o),f||=(await C({token:e.opts?.token,tokenProvider:s,secretInputMode:l,config:t,expectedProviders:[`litellm`],provider:`litellm`,envLabel:`LITELLM_API_KEY`,promptMessage:`Enter LiteLLM API key`,normalize:x,validate:S,prompter:e.prompter,setCredential:async(t,n)=>dt(t,e.agentDir,{secretInputMode:n}),noteMessage:`LiteLLM provides a unified API to 100+ LLM providers.
Get your API key from your LiteLLM proxy or https://litellm.ai
Default proxy runs on http://localhost:4000`,noteTitle:`LiteLLM`}),!0),f&&(t=B(t,{profileId:d,provider:`litellm`,mode:`api_key`})),await i({defaultModel:bt,applyDefaultConfig:De,applyProviderConfig:We,noteDefault:bt}),{config:t,agentModelOverride:n}}let f=en[o];if(f)return await u({provider:f.provider,profileId:f.profileId,expectedProviders:f.expectedProviders,envLabel:f.envLabel,promptMessage:f.promptMessage,setCredential:async(t,n)=>f.setCredential(t,e.agentDir,{secretInputMode:n??l}),defaultModel:f.defaultModel,applyDefaultConfig:f.applyDefaultConfig,applyProviderConfig:f.applyProviderConfig,noteDefault:f.noteDefault,noteMessage:f.noteMessage,noteTitle:f.noteTitle,tokenProvider:f.tokenProvider,normalize:f.normalize,validate:f.validate});if(o===`cloudflare-ai-gateway-api-key`){let r=e.opts?.cloudflareAiGatewayAccountId?.trim()??``,a=e.opts?.cloudflareAiGatewayGatewayId?.trim()??``;return await(async()=>{if(!r){let t=await e.prompter.text({message:`Enter Cloudflare Account ID`,validate:e=>String(e??``).trim()?void 0:`Account ID is required`});r=String(t??``).trim()}if(!a){let t=await e.prompter.text({message:`Enter Cloudflare AI Gateway ID`,validate:e=>String(e??``).trim()?void 0:`Gateway ID is required`});a=String(t??``).trim()}})(),await C({token:e.opts?.cloudflareAiGatewayApiKey,tokenProvider:`cloudflare-ai-gateway`,secretInputMode:l,config:t,expectedProviders:[`cloudflare-ai-gateway`],provider:`cloudflare-ai-gateway`,envLabel:`CLOUDFLARE_AI_GATEWAY_API_KEY`,promptMessage:`Enter Cloudflare AI Gateway API key`,normalize:x,validate:S,prompter:e.prompter,setCredential:async(t,n)=>lt(r,a,t,e.agentDir,{secretInputMode:n})}),t=B(t,{profileId:`cloudflare-ai-gateway:default`,provider:`cloudflare-ai-gateway`,mode:`api_key`}),await i({defaultModel:d,applyDefaultConfig:t=>Ue(t,{accountId:r||e.opts?.cloudflareAiGatewayAccountId,gatewayId:a||e.opts?.cloudflareAiGatewayGatewayId}),applyProviderConfig:t=>Ge(t,{accountId:r||e.opts?.cloudflareAiGatewayAccountId,gatewayId:a||e.opts?.cloudflareAiGatewayGatewayId}),noteDefault:d}),{config:t,agentModelOverride:n}}if(o===`gemini-api-key`){if(await C({token:e.opts?.token,provider:`google`,tokenProvider:s,secretInputMode:l,config:t,expectedProviders:[`google`],envLabel:`GEMINI_API_KEY`,promptMessage:`Enter Gemini API key`,normalize:x,validate:S,prompter:e.prompter,setCredential:async(t,n)=>St(t,e.agentDir,{secretInputMode:n})}),t=B(t,{profileId:`google:default`,provider:`google`,mode:`api_key`}),e.setDefaultModel){let n=Bt(t);t=n.next,n.changed&&await e.prompter.note(`Default model set to ${Y}`,`Model configured`)}else n=Y,await r(Y);return{config:t,agentModelOverride:n}}if(o===`zai-api-key`||o===`zai-coding-global`||o===`zai-coding-cn`||o===`zai-global`||o===`zai-cn`){let r=$t[o],a=await C({token:e.opts?.token,provider:`zai`,tokenProvider:s,secretInputMode:l,config:t,expectedProviders:[`zai`],envLabel:`ZAI_API_KEY`,promptMessage:`Enter Z.AI API key`,normalize:x,validate:S,prompter:e.prompter,setCredential:async(t,n)=>at(t,e.agentDir,{secretInputMode:n})}),c;if(!r){let t=await Rt({apiKey:a});t?(r=t.endpoint,c=t.modelId,await e.prompter.note(t.note,`Z.AI endpoint`)):r=await e.prompter.select({message:`Select Z.AI endpoint`,options:[{value:`coding-global`,label:`Coding-Plan-Global`,hint:`GLM Coding Plan Global (api.z.ai)`},{value:`coding-cn`,label:`Coding-Plan-CN`,hint:`GLM Coding Plan CN (open.bigmodel.cn)`},{value:`global`,label:`Global`,hint:`Z.AI Global (api.z.ai)`},{value:`cn`,label:`CN`,hint:`Z.AI CN (open.bigmodel.cn)`}],initialValue:`global`})}t=B(t,{profileId:`zai:default`,provider:`zai`,mode:`api_key`});let u=c?`zai/${c}`:ft;return await i({defaultModel:u,applyDefaultConfig:e=>Oe(e,{endpoint:r,...c?{modelId:c}:{}}),applyProviderConfig:e=>ht(e,{endpoint:r,...c?{modelId:c}:{}}),noteDefault:u}),{config:t,agentModelOverride:n}}return o===`huggingface-api-key`?Yt({...e,authChoice:o}):null}const nn=`byteplus-plan/ark-code-latest`;async function rn(e){if(e.authChoice!==`byteplus-api-key`)return null;let t=b(e.opts?.secretInputMode);return await C({token:e.opts?.byteplusApiKey,tokenProvider:`byteplus`,secretInputMode:t,config:e.config,expectedProviders:[`byteplus`],provider:`byteplus`,envLabel:`BYTEPLUS_API_KEY`,promptMessage:`Enter BytePlus API key`,normalize:x,validate:S,prompter:e.prompter,setCredential:async(t,n)=>Ye(t,e.agentDir,{secretInputMode:n})}),{config:Z(B(e.config,{profileId:`byteplus:default`,provider:`byteplus`,mode:`api_key`}),nn),agentModelOverride:nn}}async function Q(e,t){if(e.authChoice!==t.authChoice)return null;let r=se(e.config,t.pluginId),i=r.config;if(!r.enabled)return await e.prompter.note(`${t.label} plugin is disabled (${r.reason??`blocked`}).`,t.label),{config:i};let a=e.agentId??v(i),o=v(i),s=e.agentDir??(a===o?h():re(i,a)),c=ie(i,a)??ae(),l=Nt(It({config:i,workspaceDir:c}),t.providerId);if(!l)return await e.prompter.note(`${t.label} auth plugin is not available. Enable it and re-run the wizard.`,t.label),{config:i};let u=Ft(l,t.methodId)??l.auth[0];if(!u)return await e.prompter.note(`${t.label} auth method missing.`,t.label),{config:i};let d=q(),f=await u.run({config:i,agentDir:s,workspaceDir:c,prompter:e.prompter,runtime:e.runtime,isRemote:d,openUrl:async e=>{await y(e)},oauth:{createVpsAwareHandlers:e=>J(e)}});f.configPatch&&(i=Pt(i,f.configPatch));for(let e of f.profiles)n({profileId:e.profileId,credential:e.credential,agentDir:s}),i=B(i,{profileId:e.profileId,provider:e.credential.provider,mode:e.credential.type===`token`?`token`:e.credential.type,...`email`in e.credential&&e.credential.email?{email:e.credential.email}:{}});let p;return f.defaultModel&&(e.setDefaultModel?(i=Lt(i,f.defaultModel),await e.prompter.note(`Default model set to ${f.defaultModel}`,`Model configured`)):e.agentId&&(p=f.defaultModel,await e.prompter.note(`Default model set to ${f.defaultModel} for agent "${e.agentId}".`,`Model configured`))),f.notes&&f.notes.length>0&&await e.prompter.note(f.notes.join(`
`),`Provider notes`),{config:i,agentModelOverride:p}}async function an(e){return await Q(e,{authChoice:`copilot-proxy`,pluginId:`copilot-proxy`,providerId:`copilot-proxy`,methodId:`local`,label:`Copilot Proxy`})}async function on(e){if(e.authChoice!==`github-copilot`)return null;let t=e.config;if(await e.prompter.note([`This will open a GitHub device login to authorize Copilot.`,`Requires an active GitHub Copilot subscription.`].join(`
`),`GitHub Copilot`),!process.stdin.isTTY)return await e.prompter.note(`GitHub Copilot login requires an interactive TTY.`,`GitHub Copilot`),{config:t};try{await Mt({yes:!0},e.runtime)}catch(n){return await e.prompter.note(`GitHub Copilot login failed: ${String(n)}`,`GitHub Copilot`),{config:t}}if(t=B(t,{profileId:`github-copilot:github`,provider:`github-copilot`,mode:`token`}),e.setDefaultModel){let n=`github-copilot/gpt-4o`;t={...t,agents:{...t.agents,defaults:{...t.agents?.defaults,model:{..._(t.agents?.defaults?.model),primary:n}}}},await e.prompter.note(`Default model set to ${n}`,`Model configured`)}return{config:t}}async function sn(e){return e.authChoice===`google-gemini-cli`?(await e.prompter.note([`This is an unofficial integration and is not endorsed by Google.`,`Some users have reported account restrictions or suspensions after using third-party Gemini CLI and Antigravity OAuth clients.`,`Proceed only if you understand and accept this risk.`].join(`
`),`Google Gemini CLI caution`),await e.prompter.confirm({message:`Continue with Google Gemini CLI OAuth?`,initialValue:!1})?await Q(e,{authChoice:`google-gemini-cli`,pluginId:`google-gemini-cli-auth`,providerId:`google-gemini-cli`,methodId:`oauth`,label:`Google Gemini CLI`}):(await e.prompter.note(`Skipped Google Gemini CLI OAuth setup.`,`Setup skipped`),{config:e.config})):null}async function cn(e){let t=e.config,n,r=T(e,()=>t,e=>t=e,()=>n,e=>n=e),i=b(e.opts?.secretInputMode),a=async n=>{await C({token:e.opts?.token,tokenProvider:e.opts?.tokenProvider,secretInputMode:i,config:t,expectedProviders:[`minimax`,`minimax-cn`],provider:`minimax`,envLabel:`MINIMAX_API_KEY`,promptMessage:n.promptMessage,normalize:x,validate:S,prompter:e.prompter,setCredential:async(t,r)=>nt(t,e.agentDir,n.profileId,{secretInputMode:r})})},o=async e=>(await a({profileId:e.profileId,promptMessage:e.promptMessage}),t=B(t,{profileId:e.profileId,provider:e.provider,mode:`api_key`}),await r({defaultModel:`${e.modelRefPrefix}/${e.modelId}`,applyDefaultConfig:t=>e.applyDefaultConfig(t,e.modelId),applyProviderConfig:t=>e.applyProviderConfig(t,e.modelId)}),{config:t,agentModelOverride:n});return e.authChoice===`minimax-portal`?await Q(e,{authChoice:`minimax-portal`,pluginId:`minimax-portal-auth`,providerId:`minimax-portal`,methodId:await e.prompter.select({message:`Select MiniMax endpoint`,options:[{value:`oauth`,label:`Global`,hint:`OAuth for international users`},{value:`oauth-cn`,label:`CN`,hint:`OAuth for users in China`}]}),label:`MiniMax`}):e.authChoice===`minimax-cloud`||e.authChoice===`minimax-api`||e.authChoice===`minimax-api-lightning`?await o({profileId:`minimax:default`,provider:`minimax`,promptMessage:`Enter MiniMax API key`,modelRefPrefix:`minimax`,modelId:e.authChoice===`minimax-api-lightning`?`MiniMax-M2.5-highspeed`:`MiniMax-M2.5`,applyDefaultConfig:ct,applyProviderConfig:Xe}):e.authChoice===`minimax-api-key-cn`?await o({profileId:`minimax-cn:default`,provider:`minimax-cn`,promptMessage:`Enter MiniMax China API key`,modelRefPrefix:`minimax-cn`,modelId:`MiniMax-M2.5`,applyDefaultConfig:xt,applyProviderConfig:$e}):e.authChoice===`minimax`?(await r({defaultModel:`lmstudio/minimax-m2.5-gs32`,applyDefaultConfig:pt,applyProviderConfig:ut}),{config:t,agentModelOverride:n}):null}function ln(e,t){let n=String(e??``).trim();if(!n)throw Error(`Missing OAuth redirect URL or authorization code.`);if(!(/^https?:\/\//i.test(n)||n.includes(`://`)||n.includes(`?`)))return{code:n,state:t};let r=te(n,t);if(`error`in r)throw Error(r.error);if(r.state!==t)throw Error(`Invalid OAuth state`);return r}function un(e){return`${ee}?${new URLSearchParams({client_id:e.clientId,redirect_uri:e.redirectUri,response_type:`code`,scope:e.scopes.join(` `),state:e.state,code_challenge:e.challenge,code_challenge_method:`S256`}).toString()}`}async function dn(e){let t=new URL(e.redirectUri);if(t.protocol!==`http:`)throw Error(`Chutes OAuth redirect URI must be http:// (got ${e.redirectUri})`);let n=t.hostname||`127.0.0.1`;if(!p(n))throw Error(`Chutes OAuth redirect hostname must be loopback (got ${n}). Use http://127.0.0.1:<port>/...`);let r=t.port?Number.parseInt(t.port,10):80,i=t.pathname||`/`;return await new Promise((a,o)=>{let s=null,c=Kt((n,r)=>{try{let o=new URL(n.url??`/`,t.origin);if(o.pathname!==i){r.statusCode=404,r.setHeader(`Content-Type`,`text/plain; charset=utf-8`),r.end(`Not found`);return}let l=o.searchParams.get(`code`)?.trim(),u=o.searchParams.get(`state`)?.trim();if(!l){r.statusCode=400,r.setHeader(`Content-Type`,`text/plain; charset=utf-8`),r.end(`Missing code`);return}if(!u||u!==e.expectedState){r.statusCode=400,r.setHeader(`Content-Type`,`text/plain; charset=utf-8`),r.end(`Invalid state`);return}r.statusCode=200,r.setHeader(`Content-Type`,`text/html; charset=utf-8`),r.end([`<!doctype html>`,`<html><head><meta charset='utf-8' /></head>`,`<body><h2>Chutes OAuth complete</h2>`,`<p>You can close this window and return to OpenClaw.</p></body></html>`].join(``)),s&&clearTimeout(s),c.close(),a({code:l,state:u})}catch(e){s&&clearTimeout(s),c.close(),o(e)}});c.once(`error`,e=>{s&&clearTimeout(s),c.close(),o(e)}),c.listen(r,n,()=>{e.onProgress?.(`Waiting for OAuth callback on ${t.origin}${i}…`)}),s=setTimeout(()=>{try{c.close()}catch{}o(Error(`OAuth callback timeout`))},e.timeoutMs)})}async function fn(e){let t=e.createPkce??u,n=e.createState??(()=>Gt(16).toString(`hex`)),{verifier:r,challenge:i}=t(),a=n(),o=e.timeoutMs??180*1e3,s=un({clientId:e.app.clientId,redirectUri:e.app.redirectUri,scopes:e.app.scopes,state:a,challenge:i}),c;if(e.manual)await e.onAuth({url:s}),e.onProgress?.(`Waiting for redirect URL…`),c=ln(await e.onPrompt({message:`Paste the redirect URL (or authorization code)`,placeholder:`${e.app.redirectUri}?code=...&state=...`}),a);else{let t=dn({redirectUri:e.app.redirectUri,expectedState:a,timeoutMs:o,onProgress:e.onProgress}).catch(async()=>(e.onProgress?.(`OAuth callback not detected; paste redirect URL…`),ln(await e.onPrompt({message:`Paste the redirect URL (or authorization code)`,placeholder:`${e.app.redirectUri}?code=...&state=...`}),a)));await e.onAuth({url:s}),c=await t}return e.onProgress?.(`Exchanging code for tokens…`),await ne({app:e.app,code:c.code,codeVerifier:r,fetchFn:e.fetchFn})}async function pn(e){if(e.authChoice===`chutes`){let t=e.config,n=q(),r=process.env.CHUTES_OAUTH_REDIRECT_URI?.trim()||`http://127.0.0.1:1456/oauth-callback`,i=process.env.CHUTES_OAUTH_SCOPES?.trim()||`openid profile chutes:invoke`,a=process.env.CHUTES_CLIENT_ID?.trim()||String(await e.prompter.text({message:`Enter Chutes OAuth client id`,placeholder:`cid_xxx`,validate:e=>e?.trim()?void 0:`Required`})).trim(),o=process.env.CHUTES_CLIENT_SECRET?.trim()||void 0;await e.prompter.note(n?[`You are running in a remote/VPS environment.`,`A URL will be shown for you to open in your LOCAL browser.`,`After signing in, paste the redirect URL back here.`,``,`Redirect URI: ${r}`].join(`
`):[`Browser will open for Chutes authentication.`,`If the callback doesn't auto-complete, paste the redirect URL.`,``,`Redirect URI: ${r}`].join(`
`),`Chutes OAuth`);let s=e.prompter.progress(`Starting OAuth flow…`);try{let{onAuth:c,onPrompt:l}=J({isRemote:n,prompter:e.prompter,runtime:e.runtime,spin:s,openUrl:y,localBrowserMessage:`Complete sign-in in browser…`}),u=await fn({app:{clientId:a,clientSecret:o,redirectUri:r,scopes:i.split(/\s+/).filter(Boolean)},manual:n,onAuth:c,onPrompt:l,onProgress:e=>s.update(e)});s.stop(`Chutes OAuth complete`);let d=await j(`chutes`,u,e.agentDir);t=B(t,{profileId:d,provider:`chutes`,mode:`oauth`})}catch(t){s.stop(`Chutes OAuth failed`),e.runtime.error(String(t)),await e.prompter.note([`Trouble with OAuth?`,`Verify CHUTES_CLIENT_ID (and CHUTES_CLIENT_SECRET if required).`,`Verify the OAuth app redirect URI includes: ${r}`,`Chutes docs: https://chutes.ai/docs/sign-in-with-chutes/overview`].join(`
`),`OAuth help`)}return{config:t}}return null}async function mn(e){if(e.authChoice!==`ollama`)return null;let{config:t,defaultModelId:n}=await Ut({cfg:e.config,prompter:e.prompter,agentDir:e.agentDir}),r=`ollama/${n}`,i=K(t,r);return e.setDefaultModel?(await Wt({config:i,prompter:e.prompter}),{config:i}):{config:t,agentModelOverride:r}}async function hn(e){let t=b(e.opts?.secretInputMode),n=E(e),r=e.authChoice;if(r===`apiKey`&&e.opts?.tokenProvider===`openai`&&(r=`openai-api-key`),r===`openai-api-key`){let r=e.config,i;return await C({token:e.opts?.token,tokenProvider:e.opts?.tokenProvider,secretInputMode:t,config:r,expectedProviders:[`openai`],provider:`openai`,envLabel:`OPENAI_API_KEY`,promptMessage:`Enter OpenAI API key`,normalize:x,validate:S,prompter:e.prompter,setCredential:async(t,n)=>kt(t,e.agentDir,{secretInputMode:n})}),r=B(r,{profileId:`openai:default`,provider:`openai`,mode:`api_key`}),await(async()=>{let t=await w({config:r,setDefaultModel:e.setDefaultModel,defaultModel:X,applyDefaultConfig:zt,applyProviderConfig:Vt,noteDefault:X,noteAgentModel:n,prompter:e.prompter});return r=t.config,i=t.agentModelOverride??i,{config:r,agentModelOverride:i}})()}if(e.authChoice===`openai-codex`){let t=e.config,r,i;try{i=await jt({prompter:e.prompter,runtime:e.runtime,isRemote:q(),openUrl:async e=>{await y(e)},localBrowserMessage:`Complete sign-in in browser…`})}catch{return{config:t,agentModelOverride:r}}if(i){let a=await j(`openai-codex`,i,e.agentDir,{syncSiblingAgents:!0});if(t=B(t,{profileId:a,provider:`openai-codex`,mode:`oauth`}),e.setDefaultModel){let n=fe(t);t=n.next,n.changed&&await e.prompter.note(`Default model set to ${D}`,`Model configured`)}else r=D,await n(D)}return{config:t,agentModelOverride:r}}return null}async function gn(e){return await Q(e,{authChoice:`qwen-portal`,pluginId:`qwen-portal-auth`,providerId:`qwen-portal`,methodId:`device`,label:`Qwen`})}function _n(e,t){let n=e.agents?.defaults?.model,r=n&&typeof n==`object`&&`fallbacks`in n?n.fallbacks:void 0;return{...e,agents:{...e.agents,defaults:{...e.agents?.defaults,model:{...r?{fallbacks:r}:void 0,primary:t}}}}}async function vn(e){if(e.authChoice!==`vllm`)return null;let{config:t,modelRef:n}=await Ht({cfg:e.config,prompter:e.prompter,agentDir:e.agentDir});return e.setDefaultModel?(await e.prompter.note(`Default model set to ${n}`,`Model configured`),{config:_n(t,n)}):{config:t,agentModelOverride:n}}const yn=`volcengine-plan/ark-code-latest`;async function bn(e){if(e.authChoice!==`volcengine-api-key`)return null;let t=b(e.opts?.secretInputMode);return await C({token:e.opts?.volcengineApiKey,tokenProvider:`volcengine`,secretInputMode:t,config:e.config,expectedProviders:[`volcengine`],provider:`volcengine`,envLabel:`VOLCANO_ENGINE_API_KEY`,promptMessage:`Enter Volcano Engine API key`,normalize:x,validate:S,prompter:e.prompter,setCredential:async(t,n)=>Ne(t,e.agentDir,{secretInputMode:n})}),{config:Z(B(e.config,{profileId:`volcengine:default`,provider:`volcengine`,mode:`api_key`}),yn),agentModelOverride:yn}}async function xn(e){if(e.authChoice!==`xai-api-key`)return null;let t=e.config,n,r=E(e),i=b(e.opts?.secretInputMode);await C({token:e.opts?.xaiApiKey,tokenProvider:`xai`,secretInputMode:i,config:t,expectedProviders:[`xai`],provider:`xai`,envLabel:`XAI_API_KEY`,promptMessage:`Enter xAI API key`,normalize:x,validate:S,prompter:e.prompter,setCredential:async(t,n)=>st(t,e.agentDir,{secretInputMode:n})}),t=B(t,{profileId:`xai:default`,provider:`xai`,mode:`api_key`});{let i=await w({config:t,setDefaultModel:e.setDefaultModel,defaultModel:P,applyDefaultConfig:Te,applyProviderConfig:Be,noteDefault:P,noteAgentModel:r,prompter:e.prompter});t=i.config,n=i.agentModelOverride??n}return{config:t,agentModelOverride:n}}async function Sn(e){let t=[Jt,vn,mn,hn,pn,tn,cn,on,sn,an,gn,xn,bn,rn];for(let n of t){let t=await n(e);if(t)return t}return{config:e.config}}async function $(e,t,n){let a=f({cfg:e,agentId:n?.agentId}),s=[],l=await oe({config:e,useCache:!1});l.length>0&&(l.some(e=>e.provider===a.provider&&e.id===a.model)||s.push(`Model not found: ${a.provider}/${a.model}. Update agents.defaults.model or run /models list.`));let u=c(n?.agentDir),d=o(u,a.provider).length>0,p=r(a.provider),m=i(e,a.provider);!d&&!p&&!m&&s.push(`No auth configured for provider "${a.provider}". The agent may fail until credentials are added.`),a.provider===`openai`&&o(u,`openai-codex`).length>0&&s.push(`Detected OpenAI Codex OAuth. Consider setting agents.defaults.model to ${D}.`),s.length>0&&await t.note(s.join(`
`),`Model check`)}const Cn={oauth:`anthropic`,"setup-token":`anthropic`,"claude-cli":`anthropic`,token:`anthropic`,apiKey:`anthropic`,vllm:`vllm`,ollama:`ollama`,"openai-codex":`openai-codex`,"codex-cli":`openai-codex`,chutes:`chutes`,"openai-api-key":`openai`,"openrouter-api-key":`openrouter`,"kilocode-api-key":`kilocode`,"ai-gateway-api-key":`vercel-ai-gateway`,"cloudflare-ai-gateway-api-key":`cloudflare-ai-gateway`,"moonshot-api-key":`moonshot`,"moonshot-api-key-cn":`moonshot`,"kimi-code-api-key":`kimi-coding`,"gemini-api-key":`google`,"google-gemini-cli":`google-gemini-cli`,"mistral-api-key":`mistral`,"zai-api-key":`zai`,"zai-coding-global":`zai`,"zai-coding-cn":`zai`,"zai-global":`zai`,"zai-cn":`zai`,"xiaomi-api-key":`xiaomi`,"synthetic-api-key":`synthetic`,"venice-api-key":`venice`,"together-api-key":`together`,"huggingface-api-key":`huggingface`,"github-copilot":`github-copilot`,"copilot-proxy":`copilot-proxy`,"minimax-cloud":`minimax`,"minimax-api":`minimax`,"minimax-api-key-cn":`minimax-cn`,"minimax-api-lightning":`minimax`,minimax:`lmstudio`,"opencode-zen":`opencode`,"opencode-go":`opencode-go`,"xai-api-key":`xai`,"litellm-api-key":`litellm`,"qwen-portal":`qwen-portal`,"volcengine-api-key":`volcengine`,"byteplus-api-key":`byteplus`,"minimax-portal":`minimax-portal`,"qianfan-api-key":`qianfan`,"custom-api-key":`custom`};function wn(e){return Cn[e]}var Tn=e({applyAuthChoice:()=>Sn,resolvePreferredProviderForAuthChoice:()=>wn,warnIfModelConfigLooksOff:()=>$});export{Sn as i,wn as n,$ as r,Tn as t};
