import{h as X,d as be,q as ve,g as ye,u as T,r as w,j as n,t as P,i as Q}from"./index-CHN8jahE.js";import{u as je,a as we,b as Ne,c as Ce,d as Ee,e as ke,f as Pe}from"./use-providers-Cdxr4Jbz.js";import{B as E}from"./button-BWFTEdOr.js";import{C as _e}from"./confirm-dialog-CDLHRthd.js";import{P as re,T as se,M as q}from"./modal-D_AU4URz.js";import{S as le}from"./select-BUmRG0LY.js";import{A as N}from"./log-adapter-CeKrvZcz.js";import{c as U}from"./utils-CkSf8FUe.js";import{C as ae}from"./chevron-down-CuPdBAx-.js";import{P as Oe}from"./pencil-BMxBxIhw.js";import{C as Ie}from"./circle-check-BXZTzqw0.js";const Te=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],Ae=X("circle-x",Te);const Se=[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]],De=X("download",Se);const Le=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],Re=X("upload",Le);function Me(e,t){let l=e.slice(0,t).split(/\r\n|\n|\r/g);return[l.length,l.pop().length+1]}function Fe(e,t,l){let i=e.split(/\r\n|\n|\r/g),a="",s=(Math.log10(t+1)|0)+1;for(let r=t-1;r<=t+1;r++){let o=i[r-1];o&&(a+=r.toString().padEnd(s," "),a+=":  ",a+=o,a+=`
`,r===t&&(a+=" ".repeat(s+l+2),a+=`^
`))}return a}class f extends Error{line;column;codeblock;constructor(t,l){const[i,a]=Me(l.toml,l.ptr),s=Fe(l.toml,i,a);super(`Invalid TOML document: ${t}

${s}`,l),this.line=i,this.column=a,this.codeblock=s}}function Ue(e,t){let l=0;for(;e[t-++l]==="\\";);return--l&&l%2}function G(e,t=0,l=e.length){let i=e.indexOf(`
`,t);return e[i-1]==="\r"&&i--,i<=l?i:-1}function F(e,t){for(let l=t;l<e.length;l++){let i=e[l];if(i===`
`)return l;if(i==="\r"&&e[l+1]===`
`)return l+1;if(i<" "&&i!=="	"||i==="")throw new f("control characters are not allowed in comments",{toml:e,ptr:t})}return e.length}function k(e,t,l,i){let a;for(;(a=e[t])===" "||a==="	"||!l&&(a===`
`||a==="\r"&&e[t+1]===`
`);)t++;return i||a!=="#"?t:k(e,F(e,t),l)}function ze(e,t,l,i,a=!1){if(!i)return t=G(e,t),t<0?e.length:t;for(let s=t;s<e.length;s++){let r=e[s];if(r==="#")s=G(e,s);else{if(r===l)return s+1;if(r===i||a&&(r===`
`||r==="\r"&&e[s+1]===`
`))return s}}throw new f("cannot find end of structure",{toml:e,ptr:t})}function ie(e,t){let l=e[t],i=l===e[t+1]&&e[t+1]===e[t+2]?e.slice(t,t+3):l;t+=i.length-1;do t=e.indexOf(i,++t);while(t>-1&&l!=="'"&&Ue(e,t));return t>-1&&(t+=i.length,i.length>1&&(e[t]===l&&t++,e[t]===l&&t++)),t}let Be=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;class S extends Date{#t=!1;#n=!1;#e=null;constructor(t){let l=!0,i=!0,a="Z";if(typeof t=="string"){let s=t.match(Be);s?(s[1]||(l=!1,t=`0000-01-01T${t}`),i=!!s[2],i&&t[10]===" "&&(t=t.replace(" ","T")),s[2]&&+s[2]>23?t="":(a=s[3]||null,t=t.toUpperCase(),!a&&i&&(t+="Z"))):t=""}super(t),isNaN(this.getTime())||(this.#t=l,this.#n=i,this.#e=a)}isDateTime(){return this.#t&&this.#n}isLocal(){return!this.#t||!this.#n||!this.#e}isDate(){return this.#t&&!this.#n}isTime(){return this.#n&&!this.#t}isValid(){return this.#t||this.#n}toISOString(){let t=super.toISOString();if(this.isDate())return t.slice(0,10);if(this.isTime())return t.slice(11,23);if(this.#e===null)return t.slice(0,-1);if(this.#e==="Z")return t;let l=+this.#e.slice(1,3)*60+ +this.#e.slice(4,6);return l=this.#e[0]==="-"?l:-l,new Date(this.getTime()-l*6e4).toISOString().slice(0,-1)+this.#e}static wrapAsOffsetDateTime(t,l="Z"){let i=new S(t);return i.#e=l,i}static wrapAsLocalDateTime(t){let l=new S(t);return l.#e=null,l}static wrapAsLocalDate(t){let l=new S(t);return l.#n=!1,l.#e=null,l}static wrapAsLocalTime(t){let l=new S(t);return l.#t=!1,l.#e=null,l}}let Ge=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,$e=/^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/,Ke=/^[+-]?0[0-9_]/,Xe=/^[0-9a-f]{2,8}$/i,ee={b:"\b",t:"	",n:`
`,f:"\f",r:"\r",e:"\x1B",'"':'"',"\\":"\\"};function oe(e,t=0,l=e.length){let i=e[t]==="'",a=e[t++]===e[t]&&e[t]===e[t+1];a&&(l-=2,e[t+=2]==="\r"&&t++,e[t]===`
`&&t++);let s=0,r,o="",d=t;for(;t<l-1;){let c=e[t++];if(c===`
`||c==="\r"&&e[t]===`
`){if(!a)throw new f("newlines are not allowed in strings",{toml:e,ptr:t-1})}else if(c<" "&&c!=="	"||c==="")throw new f("control characters are not allowed in strings",{toml:e,ptr:t-1});if(r){if(r=!1,c==="x"||c==="u"||c==="U"){let p=e.slice(t,t+=c==="x"?2:c==="u"?4:8);if(!Xe.test(p))throw new f("invalid unicode escape",{toml:e,ptr:s});try{o+=String.fromCodePoint(parseInt(p,16))}catch{throw new f("invalid unicode escape",{toml:e,ptr:s})}}else if(a&&(c===`
`||c===" "||c==="	"||c==="\r")){if(t=k(e,t-1,!0),e[t]!==`
`&&e[t]!=="\r")throw new f("invalid escape: only line-ending whitespace may be escaped",{toml:e,ptr:s});t=k(e,t)}else if(c in ee)o+=ee[c];else throw new f("unrecognized escape sequence",{toml:e,ptr:s});d=t}else!i&&c==="\\"&&(s=t-1,r=!0,o+=e.slice(d,s))}return o+e.slice(d,l-1)}function qe(e,t,l,i){if(e==="true")return!0;if(e==="false")return!1;if(e==="-inf")return-1/0;if(e==="inf"||e==="+inf")return 1/0;if(e==="nan"||e==="+nan"||e==="-nan")return NaN;if(e==="-0")return i?0n:0;let a=Ge.test(e);if(a||$e.test(e)){if(Ke.test(e))throw new f("leading zeroes are not allowed",{toml:t,ptr:l});e=e.replace(/_/g,"");let r=+e;if(isNaN(r))throw new f("invalid number",{toml:t,ptr:l});if(a){if((a=!Number.isSafeInteger(r))&&!i)throw new f("integer value cannot be represented losslessly",{toml:t,ptr:l});(a||i===!0)&&(r=BigInt(e))}return r}const s=new S(e);if(!s.isValid())throw new f("invalid value",{toml:t,ptr:l});return s}function Ve(e,t,l){let i=e.slice(t,l),a=i.indexOf("#");return a>-1&&(F(e,a),i=i.slice(0,a)),[i.trimEnd(),a]}function V(e,t,l,i,a){if(i===0)throw new f("document contains excessively nested structures. aborting.",{toml:e,ptr:t});let s=e[t];if(s==="["||s==="{"){let[d,c]=s==="["?Je(e,t,i,a):He(e,t,i,a);if(l){if(c=k(e,c),e[c]===",")c++;else if(e[c]!==l)throw new f("expected comma or end of structure",{toml:e,ptr:c})}return[d,c]}let r;if(s==='"'||s==="'"){r=ie(e,t);let d=oe(e,t,r);if(l){if(r=k(e,r),e[r]&&e[r]!==","&&e[r]!==l&&e[r]!==`
`&&e[r]!=="\r")throw new f("unexpected character encountered",{toml:e,ptr:r});r+=+(e[r]===",")}return[d,r]}r=ze(e,t,",",l);let o=Ve(e,t,r-+(e[r-1]===","));if(!o[0])throw new f("incomplete key-value declaration: no value specified",{toml:e,ptr:t});return l&&o[1]>-1&&(r=k(e,t+o[1]),r+=+(e[r]===",")),[qe(o[0],e,t,a),r]}let Ze=/^[a-zA-Z0-9-_]+[ \t]*$/;function $(e,t,l="="){let i=t-1,a=[],s=e.indexOf(l,t);if(s<0)throw new f("incomplete key-value: cannot find end of key",{toml:e,ptr:t});do{let r=e[t=++i];if(r!==" "&&r!=="	")if(r==='"'||r==="'"){if(r===e[t+1]&&r===e[t+2])throw new f("multiline strings are not allowed in keys",{toml:e,ptr:t});let o=ie(e,t);if(o<0)throw new f("unfinished string encountered",{toml:e,ptr:t});i=e.indexOf(".",o);let d=e.slice(o,i<0||i>s?s:i),c=G(d);if(c>-1)throw new f("newlines are not allowed in keys",{toml:e,ptr:t+i+c});if(d.trimStart())throw new f("found extra tokens after the string part",{toml:e,ptr:o});if(s<o&&(s=e.indexOf(l,o),s<0))throw new f("incomplete key-value: cannot find end of key",{toml:e,ptr:t});a.push(oe(e,t,o))}else{i=e.indexOf(".",t);let o=e.slice(t,i<0||i>s?s:i);if(!Ze.test(o))throw new f("only letter, numbers, dashes and underscores are allowed in keys",{toml:e,ptr:t});a.push(o.trimEnd())}}while(i+1&&i<s);return[a,k(e,s+1,!0,!0)]}function He(e,t,l,i){let a={},s=new Set,r;for(t++;(r=e[t++])!=="}"&&r;){if(r===",")throw new f("expected value, found comma",{toml:e,ptr:t-1});if(r==="#")t=F(e,t);else if(r!==" "&&r!=="	"&&r!==`
`&&r!=="\r"){let o,d=a,c=!1,[p,v]=$(e,t-1);for(let g=0;g<p.length;g++){if(g&&(d=c?d[o]:d[o]={}),o=p[g],(c=Object.hasOwn(d,o))&&(typeof d[o]!="object"||s.has(d[o])))throw new f("trying to redefine an already defined value",{toml:e,ptr:t});!c&&o==="__proto__"&&Object.defineProperty(d,o,{enumerable:!0,configurable:!0,writable:!0})}if(c)throw new f("trying to redefine an already defined value",{toml:e,ptr:t});let[h,u]=V(e,v,"}",l-1,i);s.add(h),d[o]=h,t=u}}if(!r)throw new f("unfinished table encountered",{toml:e,ptr:t});return[a,t]}function Je(e,t,l,i){let a=[],s;for(t++;(s=e[t++])!=="]"&&s;){if(s===",")throw new f("expected value, found comma",{toml:e,ptr:t-1});if(s==="#")t=F(e,t);else if(s!==" "&&s!=="	"&&s!==`
`&&s!=="\r"){let r=V(e,t-1,"]",l-1,i);a.push(r[0]),t=r[1]}}if(!s)throw new f("unfinished array encountered",{toml:e,ptr:t});return[a,t]}function te(e,t,l,i){let a=t,s=l,r,o=!1,d;for(let c=0;c<e.length;c++){if(c){if(a=o?a[r]:a[r]={},s=(d=s[r]).c,i===0&&(d.t===1||d.t===2))return null;if(d.t===2){let p=a.length-1;a=a[p],s=s[p].c}}if(r=e[c],(o=Object.hasOwn(a,r))&&s[r]?.t===0&&s[r]?.d)return null;o||(r==="__proto__"&&(Object.defineProperty(a,r,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(s,r,{enumerable:!0,configurable:!0,writable:!0})),s[r]={t:c<e.length-1&&i===2?3:i,d:!1,i:0,c:{}})}if(d=s[r],d.t!==i&&!(i===1&&d.t===3)||(i===2&&(d.d||(d.d=!0,a[r]=[]),a[r].push(a={}),d.c[d.i++]=d={t:1,d:!1,i:0,c:{}}),d.d))return null;if(d.d=!0,i===1)a=o?a[r]:a[r]={};else if(i===0&&o)return null;return[r,a,d.c]}function Ye(e,{maxDepth:t=1e3,integersAsBigInt:l}={}){let i={},a={},s=i,r=a;for(let o=k(e,0);o<e.length;){if(e[o]==="["){let d=e[++o]==="[",c=$(e,o+=+d,"]");if(d){if(e[c[1]-1]!=="]")throw new f("expected end of table declaration",{toml:e,ptr:c[1]-1});c[1]++}let p=te(c[0],i,a,d?2:1);if(!p)throw new f("trying to redefine an already defined table or value",{toml:e,ptr:o});r=p[2],s=p[1],o=c[1]}else{let d=$(e,o),c=te(d[0],s,r,0);if(!c)throw new f("trying to redefine an already defined table or value",{toml:e,ptr:o});let p=V(e,d[1],void 0,t,l);c[1][c[0]]=p[0],o=p[1]}if(o=k(e,o,!0),e[o]&&e[o]!==`
`&&e[o]!=="\r")throw new f("each key-value declaration must be followed by an end-of-line",{toml:e,ptr:o});o=k(e,o)}return i}function We(){return be({queryKey:ve.system.cursorAgentModels,queryFn:()=>ye.get("/system/cursor-agent-models"),staleTime:1e3*60*10})}function Qe({value:e,onChange:t}){const{t:l}=T(),{data:i,isLoading:a,isError:s}=We(),r=i?.models??[],[o,d]=w.useState(!1),[c,p]=w.useState(""),v=w.useMemo(()=>{const h=c.trim().toLowerCase();return h?r.filter(u=>u.id.toLowerCase().includes(h)||u.label.toLowerCase().includes(h)):r},[r,c]);return n.jsxs("div",{className:"flex flex-col gap-2 flex-1 min-w-0",children:[n.jsx("input",{type:"text",value:e,onChange:h=>{const u=h.target.value;t(u===""?void 0:u)},placeholder:l("留空为 auto；或直接输入模型 ID（与 cursor-agent --model 一致）"),className:"w-full px-3 py-1.5 text-sm border border-neutral-200 rounded focus:outline-none focus:ring-1 focus:ring-neutral-900 font-mono"}),n.jsxs("button",{type:"button",onClick:()=>d(h=>!h),disabled:a,className:"flex items-center gap-1 text-xs text-neutral-600 hover:text-neutral-900 disabled:opacity-50 w-fit",children:[n.jsx(ae,{size:14,className:U("transition-transform",o&&"rotate-180")}),a?l("正在加载 cursor-agent 模型列表…"):o?l("收起列表"):l("从本机 cursor-agent 选择（{count} 个）",{count:r.length})]}),o&&!a&&n.jsxs("div",{className:"rounded-lg border border-neutral-200 bg-white shadow-sm overflow-hidden",children:[n.jsx("input",{type:"text",value:c,onChange:h=>p(h.target.value),placeholder:l("筛选模型…"),className:"w-full px-3 py-2 text-sm border-b border-neutral-100 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-neutral-300"}),n.jsxs("div",{className:"max-h-[min(50vh,22rem)] overflow-y-auto py-1",children:[n.jsx("button",{type:"button",onClick:()=>{t(void 0),d(!1),p("")},className:U("w-full px-3 py-2 text-left text-sm hover:bg-neutral-50",e?"text-neutral-700":"bg-neutral-50 font-medium"),children:l("默认 (auto)")}),v.map(h=>n.jsxs("button",{type:"button",onClick:()=>{t(h.id),d(!1),p("")},className:U("w-full px-3 py-2 text-left text-sm hover:bg-neutral-50 border-t border-neutral-100",e===h.id?"bg-blue-50/80":""),children:[n.jsx("div",{className:"font-mono text-xs text-neutral-900 break-all",children:h.id}),n.jsx("div",{className:"text-xs text-neutral-500 mt-0.5 break-words",children:h.label})]},h.id)),v.length===0&&n.jsx("div",{className:"px-3 py-4 text-xs text-neutral-400 text-center",children:l("无匹配项")})]})]}),(s||i?.error)&&n.jsxs("p",{className:"text-xs text-amber-700",children:[l("无法从本机加载模型列表（{error}）。仍可手动输入；或在安装 cursor-agent 的机器上运行",{error:i?.error??l("请求失败")}),n.jsx("code",{className:"mx-0.5 bg-neutral-100 px-1 rounded text-[11px]",children:"cursor-agent --list-models"}),l("查看 ID。")]})]})}const Z={CLAUDE_CODE:"Claude Code",GEMINI_CLI:"Gemini CLI",CURSOR_AGENT:"Cursor Agent",CODEX:"Codex"},R={key:"appendPrompt",label:"追加 Prompt",type:"textarea",rows:3,placeholder:"追加到每次 prompt 末尾的文本"},H={[N.CLAUDE_CODE]:[{key:"dangerouslySkipPermissions",label:"跳过权限确认",type:"switch"},{key:"model",label:"模型",type:"input",placeholder:"claude-sonnet-4-20250514"},{key:"effort",label:"推理强度",type:"select",options:[{value:"",label:"默认"},{value:"low",label:"Low"},{value:"medium",label:"Medium"},{value:"high",label:"High"},{value:"xhigh",label:"XHigh"},{value:"max",label:"Max"}]},R],[N.GEMINI_CLI]:[{key:"yolo",label:"跳过权限确认",type:"switch"},{key:"model",label:"模型",type:"input",placeholder:"gemini-2.5-pro"},R],[N.CURSOR_AGENT]:[{key:"force",label:"强制执行",type:"switch"},{key:"model",label:"模型",type:"cursor_model"},R],[N.CODEX]:[{key:"dangerouslyBypassApprovalsAndSandbox",label:"跳过所有确认和沙盒",type:"switch"},{key:"model",label:"模型",type:"input",placeholder:"o3"},{key:"profile",label:"Profile",type:"input",placeholder:"~/.codex/config.toml 中的 profile 名称"},R]};function ne(){return{}}function K(e,t){return{...t}}const et=JSON.stringify({env:{ANTHROPIC_API_KEY:"",ANTHROPIC_BASE_URL:""}},null,2),tt=`# Codex config.toml 配置片段 — 通过 -c 参数注入，不会修改 ~/.codex/config.toml
# 参考: https://developers.openai.com/codex/config-sample

# ─── 模型与推理 ─────────────────────────────────────────────
# model_reasoning_effort = "medium"     # minimal | low | medium | high | xhigh
# model_reasoning_summary = "auto"      # auto | concise | detailed | none
# model_verbosity = "medium"            # low | medium | high
# service_tier = "flex"                 # fast | flex

# ─── 自定义 Model Provider ──────────────────────────────────
# model_provider = "azure"
#
# [model_providers.azure]
# name = "Azure OpenAI"
# base_url = "https://YOUR_PROJECT.openai.azure.com/openai"
# env_key = "AZURE_OPENAI_API_KEY"
# env_key_instructions = "Set AZURE_OPENAI_API_KEY in Provider env"
# wire_api = "responses"
# query_params = { api-version = "2025-04-01-preview" }

# ─── OpenAI 数据驻留 ────────────────────────────────────────
# [model_providers.openai-us]
# name = "OpenAI US"
# base_url = "https://us.api.openai.com/v1"
# wire_api = "responses"
# requires_openai_auth = true

# ─── 本地 OSS (Ollama) ──────────────────────────────────────
# [model_providers.ollama]
# name = "Ollama"
# base_url = "http://localhost:11434/v1"
# wire_api = "responses"
`;function z(e){return e===N.CLAUDE_CODE?et:e===N.CODEX?tt:""}function nt(e){return e===N.CLAUDE_CODE||e===N.CODEX}const rt=Object.values(H).flat().reduce((e,t)=>(e[t.key]||(e[t.key]=t.label),e),{}),st=Object.values(H).flat().reduce((e,t)=>(t.options&&(e[t.key]=Object.fromEntries(t.options.map(l=>[l.value,l.label]))),e),{});function lt(e,t){return typeof t=="boolean"?t?Q("是"):Q("否"):typeof t=="string"&&t?st[e]?.[t]??t:String(t)}function M(e,t){return e instanceof Error?e.message:t}function at(e){return`agent-tower-provider-backup-${e.replace(/[:.]/g,"-")}.json`}function it(e,t){const l=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),i=URL.createObjectURL(l),a=document.createElement("a");a.href=i,a.download=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function ot(e){switch(e){case"CREATE":return{label:"新增",className:"text-green-700 bg-green-50"};case"OVERWRITE":return{label:"覆盖",className:"text-amber-700 bg-amber-50"};case"SKIP":return{label:"跳过",className:"text-neutral-600 bg-neutral-100"}}}function ct({type:e}){const{t}=T();return e==="LOGIN_DETECTED"||e==="INSTALLATION_FOUND"?n.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs text-green-700 bg-green-50 rounded",children:[n.jsx(Ie,{size:12}),t("可用")]}):n.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs text-neutral-500 bg-neutral-50 rounded",children:[n.jsx(Ae,{size:12}),t("不可用")]})}function B({title:e,defaultOpen:t=!1,children:l}){const[i,a]=w.useState(t);return n.jsxs("div",{className:"border border-neutral-200 rounded-lg",children:[n.jsxs("button",{type:"button",onClick:()=>a(s=>!s),className:"w-full flex items-center justify-between px-4 py-2.5 text-sm font-medium text-neutral-700 hover:bg-neutral-50 transition-colors rounded-lg",children:[e,n.jsx(ae,{size:14,className:`transition-transform ${i?"rotate-180":""}`})]}),i&&n.jsx("div",{className:"px-4 pb-4 space-y-3",children:l})]})}function dt({agentType:e,config:t,onChange:l}){const{t:i}=T(),a=H[e]??[];if(a.length===0)return n.jsx("p",{className:"text-xs text-neutral-400",children:i("该类型暂无运行配置")});const s=(r,o)=>{l({...t,[r]:o})};return n.jsx("div",{className:"space-y-3",children:a.map(r=>r.type==="textarea"?n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-neutral-700 mb-1",children:i(r.label)}),n.jsx("textarea",{value:t[r.key]??"",onChange:o=>s(r.key,o.target.value||void 0),placeholder:r.placeholder?i(r.placeholder):void 0,rows:r.rows??3,className:"w-full px-3 py-1.5 text-sm border border-neutral-200 rounded focus:outline-none focus:ring-1 focus:ring-neutral-900"})]},r.key):r.type==="cursor_model"?n.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start",children:[n.jsx("label",{className:"text-sm text-neutral-700 w-32 shrink-0 sm:pt-2",children:i(r.label)}),n.jsx(Qe,{value:t[r.key]??"",onChange:o=>s(r.key,o)})]},r.key):n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("label",{className:"text-sm text-neutral-700 w-32 shrink-0",children:i(r.label)}),r.type==="switch"&&n.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:!!t[r.key],onChange:o=>s(r.key,o.target.checked),className:"sr-only peer"}),n.jsx("div",{className:"w-9 h-5 bg-neutral-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-neutral-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-neutral-900"})]}),r.type==="input"&&n.jsx("input",{type:"text",value:t[r.key]??"",onChange:o=>s(r.key,o.target.value||void 0),placeholder:r.placeholder?i(r.placeholder):void 0,className:"flex-1 px-3 py-1.5 text-sm border border-neutral-200 rounded focus:outline-none focus:ring-1 focus:ring-neutral-900"}),r.type==="select"&&r.options&&n.jsx(le,{value:t[r.key]??"",onChange:o=>s(r.key,o||void 0),options:r.options,placeholder:i("选择...")})]},r.key))})}function ut({isOpen:e,onClose:t,initialData:l,onSave:i}){const{t:a}=T(),[s,r]=w.useState(l??{name:"",agentType:N.CLAUDE_CODE,config:ne(),settings:"",env:[],isDefault:!1}),[o,d]=w.useState("");w.useEffect(()=>{if(!l&&!s.settings){const u=z(s.agentType);u&&r(g=>({...g,settings:u}))}},[]);const c=u=>{r(g=>({...g,agentType:u,config:ne(),settings:z(u)}))},p=()=>{d("");const u=K(s.agentType,s.config),g={};for(const[j,_]of Object.entries(u))_!==void 0&&_!==""&&(g[j]=_);const y=s.settings.trim();if(y){if(s.agentType===N.CODEX)try{Ye(y)}catch(j){d(a("TOML 语法错误: {message}",{message:j instanceof Error?j.message:String(j)}));return}else if(s.agentType===N.CLAUDE_CODE)try{JSON.parse(y)}catch{d(a("JSON 语法错误"));return}}const b={};for(const{key:j,value:_}of s.env){const D=j.trim();D&&(b[D]=_)}const C={name:s.name,agentType:s.agentType,config:g,settings:y||void 0,env:Object.keys(b).length>0?b:void 0,isDefault:s.isDefault};i(C)};if(!e)return null;const v=nt(s.agentType),h=s.agentType===N.CODEX;return n.jsx(q,{isOpen:e,onClose:t,title:a(l?"编辑 Provider":"新建 Provider"),className:"max-w-2xl",children:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-neutral-700 mb-1",children:a("名称")}),n.jsx("input",{type:"text",value:s.name,onChange:u=>r(g=>({...g,name:u.target.value})),className:"w-full px-3 py-2 text-sm border border-neutral-200 rounded focus:outline-none focus:ring-1 focus:ring-neutral-900",placeholder:a("例如: Claude Code (官方)")})]}),!l&&n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs font-medium text-neutral-700 mb-1",children:a("Agent 类型")}),n.jsx(le,{value:s.agentType,onChange:u=>c(u),options:Object.values(N).map(u=>({value:u,label:Z[u]??u})),placeholder:a("选择 Agent 类型")})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",id:"isDefault",checked:s.isDefault,onChange:u=>r(g=>({...g,isDefault:u.target.checked})),className:"w-4 h-4"}),n.jsx("label",{htmlFor:"isDefault",className:"text-sm text-neutral-700",children:a("设为该类型的默认 Provider")})]}),n.jsx(B,{title:a("运行配置"),defaultOpen:!0,children:n.jsx(dt,{agentType:s.agentType,config:s.config,onChange:u=>r(g=>({...g,config:u}))})}),n.jsxs(B,{title:a("环境变量"),defaultOpen:s.env.length>0,children:[n.jsxs("p",{className:"text-xs text-neutral-500 mb-2",children:[a("注入到 Agent 进程的环境变量。Codex 的")," ",n.jsx("code",{className:"bg-neutral-100 px-1 rounded",children:"env_key"})," ",a("指定的是变量名，实际值需在此处设置。")]}),n.jsxs("div",{className:"space-y-2",children:[s.env.map((u,g)=>n.jsxs("div",{className:"flex gap-2 items-center",children:[n.jsx("input",{type:"text",value:u.key,onChange:y=>{const b=[...s.env];b[g]={...b[g],key:y.target.value},r(C=>({...C,env:b}))},placeholder:a("变量名，如 AZURE_OPENAI_API_KEY"),className:"flex-1 px-3 py-1.5 text-sm font-mono border border-neutral-200 rounded focus:outline-none focus:ring-1 focus:ring-neutral-900"}),n.jsx("input",{type:"text",value:u.value,onChange:y=>{const b=[...s.env];b[g]={...b[g],value:y.target.value},r(C=>({...C,env:b}))},placeholder:a("值"),className:"flex-1 px-3 py-1.5 text-sm font-mono border border-neutral-200 rounded focus:outline-none focus:ring-1 focus:ring-neutral-900"}),n.jsx("button",{type:"button",onClick:()=>{const y=s.env.filter((b,C)=>C!==g);r(b=>({...b,env:y}))},className:"p-1.5 text-neutral-400 hover:text-red-500",children:n.jsx(se,{size:14})})]},g)),n.jsxs(E,{variant:"outline",size:"sm",onClick:()=>r(u=>({...u,env:[...u.env,{key:"",value:""}]})),children:[n.jsx(re,{size:12,className:"mr-1"}),a("添加变量")]})]})]}),v&&n.jsxs(B,{title:a(h?"CLI 原生配置 (config.toml)":"CLI 原生配置 (settings.json)"),children:[n.jsx("p",{className:"text-xs text-neutral-500 mb-2",children:h?n.jsxs(n.Fragment,{children:[a("直接填写 Codex")," ",n.jsx("code",{className:"bg-neutral-100 px-1 rounded",children:"config.toml"})," ",a("格式的配置片段，通过")," ",n.jsx("code",{className:"bg-neutral-100 px-1 rounded",children:"-c"})," ",a("参数注入。不会修改你的")," ",n.jsx("code",{className:"bg-neutral-100 px-1 rounded",children:"~/.codex/config.toml"})," ",a("文件。")]}):n.jsxs(n.Fragment,{children:[a("对应 Claude Code 的")," ",n.jsx("code",{className:"bg-neutral-100 px-1 rounded",children:"~/.claude/settings.json"}),"，",a("通过")," ",n.jsx("code",{className:"bg-neutral-100 px-1 rounded",children:"--settings"})," ",a("参数注入。在")," ",n.jsx("code",{className:"bg-neutral-100 px-1 rounded",children:"env"})," ",a("中设置 ANTHROPIC_API_KEY、ANTHROPIC_BASE_URL 等。")]})}),n.jsx("textarea",{value:s.settings,onChange:u=>{r(g=>({...g,settings:u.target.value})),d("")},rows:10,className:"w-full px-3 py-2 text-sm font-mono border border-neutral-200 rounded focus:outline-none focus:ring-1 focus:ring-neutral-900 bg-neutral-50",placeholder:z(s.agentType)}),o&&n.jsx("p",{className:"mt-1 text-xs text-red-600",children:o})]}),n.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[n.jsx(E,{variant:"outline",onClick:t,children:a("取消")}),n.jsx(E,{onClick:p,disabled:!s.name.trim(),children:a("保存")})]})]})})}function mt({isOpen:e,onClose:t,onConfirm:l,acknowledged:i,onAcknowledgedChange:a,isLoading:s}){const{t:r}=T();return n.jsx(q,{isOpen:e,onClose:t,title:r("导出 Provider 备份"),className:"max-w-xl",action:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"outline",onClick:t,disabled:s,children:r("取消")}),n.jsx(E,{onClick:l,disabled:!i||s,children:r(s?"导出中...":"导出备份")})]}),children:n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:r("导出的备份文件将包含完整的 Provider 配置，包括环境变量、CLI settings 等敏感信息。任何拿到文件的人都可能直接使用这些 Provider。")}),n.jsxs("div",{className:"text-sm text-neutral-600 space-y-2",children:[n.jsx("p",{children:r("这个功能用于备份和迁移，不用于分享配置。")}),n.jsx("p",{children:r("导出内容只包含用户层配置：自定义 Provider，以及对内置 Provider 的覆盖。")})]}),n.jsxs("label",{className:"flex items-start gap-3 rounded-lg border border-neutral-200 px-4 py-3 text-sm text-neutral-700",children:[n.jsx("input",{type:"checkbox",checked:i,onChange:o=>a(o.target.checked),className:"mt-0.5 h-4 w-4"}),n.jsx("span",{children:r("我已知晓该备份文件包含敏感信息，只会保存在安全位置。")})]})]})})}function xt({isOpen:e,onClose:t,preview:l,backup:i,onConfirm:a,isLoading:s}){const{t:r}=T();if(!l||!i)return null;const o=l.summary.create+l.summary.overwrite,d=[...l.items].sort((c,p)=>{const v={CREATE:0,OVERWRITE:1,SKIP:2};return v[c.action]-v[p.action]});return n.jsx(q,{isOpen:e,onClose:t,title:r("导入 Provider 备份"),className:"max-w-3xl",action:n.jsxs(n.Fragment,{children:[n.jsx(E,{variant:"outline",onClick:t,disabled:s,children:r("取消")}),n.jsx(E,{onClick:a,disabled:o===0||s,children:s?r("导入中..."):r("确认导入 {count} 项",{count:o})})]}),children:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"rounded-lg border border-neutral-200 bg-neutral-50 px-4 py-3 text-sm text-neutral-600",children:[n.jsx("div",{children:r("导出时间：{value}",{value:new Date(i.exportedAt).toLocaleString()})}),n.jsx("div",{children:r("模式：完整备份（含敏感信息）")}),n.jsx("div",{children:r("文件内 Provider 数量：{count}",{count:i.providers.length})})]}),n.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[n.jsxs("div",{className:"rounded-lg border border-green-200 bg-green-50 px-4 py-3",children:[n.jsx("div",{className:"text-xs text-green-700",children:r("新增")}),n.jsx("div",{className:"text-lg font-semibold text-green-900",children:l.summary.create})]}),n.jsxs("div",{className:"rounded-lg border border-amber-200 bg-amber-50 px-4 py-3",children:[n.jsx("div",{className:"text-xs text-amber-700",children:r("覆盖")}),n.jsx("div",{className:"text-lg font-semibold text-amber-900",children:l.summary.overwrite})]}),n.jsxs("div",{className:"rounded-lg border border-neutral-200 bg-neutral-50 px-4 py-3",children:[n.jsx("div",{className:"text-xs text-neutral-500",children:r("跳过")}),n.jsx("div",{className:"text-lg font-semibold text-neutral-900",children:l.summary.skip})]})]}),n.jsx("div",{className:"max-h-[420px] overflow-y-auto space-y-3 pr-1",children:d.map(c=>{const p=ot(c.action);return n.jsxs("div",{className:"rounded-lg border border-neutral-200 px-4 py-3",children:[n.jsx("div",{className:"flex items-center justify-between gap-3",children:n.jsxs("div",{className:"min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h4",{className:"truncate text-sm font-medium text-neutral-900",children:c.incoming.name}),n.jsx("span",{className:`inline-flex rounded px-2 py-0.5 text-xs ${p.className}`,children:r(p.label)})]}),n.jsxs("div",{className:"mt-1 text-xs text-neutral-500",children:[Z[c.incoming.agentType]??c.incoming.agentType," · ",n.jsx("code",{className:"rounded bg-neutral-100 px-1 py-0.5",children:c.incoming.id})]})]})}),c.action==="OVERWRITE"&&c.existing&&n.jsx("p",{className:"mt-2 text-xs text-amber-700",children:r("将覆盖当前已有的 Provider：{name}",{name:c.existing.name})}),c.action==="SKIP"&&n.jsx("p",{className:"mt-2 text-xs text-neutral-500",children:r("当前同 ID Provider 配置一致，本次不会重复写入。")}),c.action==="CREATE"&&n.jsx("p",{className:"mt-2 text-xs text-green-700",children:r("当前不存在同 ID Provider，将直接新增。")})]},c.incoming.id)})})]})})}function Et(){const{t:e}=T(),{data:t,isLoading:l}=je(),i=we(),a=Ne(),s=Ce(),r=Ee(),o=ke(),d=Pe(),c=w.useRef(null),[p,v]=w.useState(null),[h,u]=w.useState(null),[g,y]=w.useState(!1),[b,C]=w.useState(!1),[j,_]=w.useState(null),D=m=>{i.mutate(m,{onSuccess:()=>v(null)})},ce=(m,x)=>{a.mutate({id:m,data:x},{onSuccess:()=>v(null)})},de=m=>{if(!(m.deletable??!m.builtIn)){P.error(e("系统内置 Provider 不可删除"));return}u({id:m.id,name:m.name,builtIn:m.builtIn})},ue=()=>{h&&s.mutate(h.id,{onSuccess:()=>{P.success(h.builtIn?e("已恢复默认 Provider 配置"):e("Provider 已删除")),u(null)},onError:m=>{P.error(M(m,e("删除 Provider 失败")))}})},J=()=>{y(!1),C(!1)},Y=()=>{_(null)},me=()=>{r.mutate(void 0,{onSuccess:m=>{it(at(m.exportedAt),m),P.success(e("Provider 备份已导出")),J()},onError:m=>{P.error(M(m,e("导出 Provider 备份失败")))}})},xe=()=>{c.current&&(c.current.value="",c.current.click())},fe=async m=>{const x=m.target.files?.[0];if(m.target.value="",!x)return;let O;try{O=JSON.parse(await x.text())}catch{P.error(e("备份文件不是有效的 JSON"));return}o.mutate(O,{onSuccess:I=>{_({backup:O,preview:I})},onError:I=>{P.error(M(I,e("导入预览失败")))}})},pe=()=>{j&&d.mutate(j.backup,{onSuccess:m=>{const x=m.summary.create+m.summary.overwrite;P.success(x===0?e("导入完成，当前配置无需变更"):e("导入完成：新增 {create}，覆盖 {overwrite}，跳过 {skip}",{create:m.summary.create,overwrite:m.summary.overwrite,skip:m.summary.skip})),Y()},onError:m=>{P.error(M(m,e("导入 Provider 备份失败")))}})},he=m=>{const x=m.provider,O=x.env?Object.entries(x.env).map(([I,L])=>({key:I,value:L})):[];v({id:x.id,data:{name:x.name,agentType:x.agentType,config:K(x.agentType,x.config),settings:x.settings??"",env:O,isDefault:x.isDefault}})};if(l)return n.jsx("div",{className:"p-6 text-sm text-neutral-400",children:e("加载中...")});const W=t??[];return n.jsxs("div",{className:"px-10 py-6 mx-auto w-full max-w-4xl",children:[n.jsx("input",{ref:c,type:"file",accept:".json,application/json",className:"hidden",onChange:fe}),n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsxs("div",{children:[n.jsx("h2",{className:"text-lg font-semibold text-neutral-900",children:e("Provider 配置")}),n.jsx("p",{className:"text-sm text-neutral-500 mt-1",children:e("管理 AI Agent 的连接配置和运行参数")})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs(E,{variant:"outline",onClick:xe,disabled:o.isPending||d.isPending,children:[n.jsx(Re,{size:14}),e("导入备份")]}),n.jsxs(E,{variant:"outline",onClick:()=>y(!0),disabled:r.isPending,children:[n.jsx(De,{size:14}),e("导出备份")]}),n.jsxs(E,{onClick:()=>v({}),children:[n.jsx(re,{size:14,className:"mr-1"}),e("新建 Provider")]})]})]}),W.length===0?n.jsx("div",{className:"text-center py-12 text-sm text-neutral-400",children:e("暂无 Provider 配置")}):n.jsx("div",{className:"space-y-3",children:W.map(m=>{const x=m.provider,O=m.availability,I=K(x.agentType,x.config),L=Object.entries(I).filter(([A])=>A!=="cmd");return n.jsx("div",{className:"border border-neutral-200 rounded-lg p-4 hover:border-neutral-300 transition-colors",children:n.jsxs("div",{className:"flex items-start justify-between",children:[n.jsxs("div",{className:"flex-1",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[n.jsx("h3",{className:"text-sm font-medium text-neutral-900",children:x.name}),n.jsx(ct,{type:O.type}),x.isDefault&&n.jsx("span",{className:"px-2 py-0.5 text-xs text-blue-700 bg-blue-50 rounded",children:e("默认")}),x.builtIn&&n.jsx("span",{className:"px-2 py-0.5 text-xs text-neutral-500 bg-neutral-50 rounded",children:e("内置")})]}),n.jsx("p",{className:"text-xs text-neutral-500 mb-2",children:Z[x.agentType]??x.agentType}),L.length>0&&n.jsx("div",{className:"text-xs text-neutral-600 mb-1",children:L.map(([A,ge])=>n.jsxs("span",{className:"inline-flex items-center mr-3",children:[n.jsxs("span",{className:"font-medium",children:[e(rt[A]??A),":"]})," ",lt(A,ge)]},A))}),x.settings?.trim()&&n.jsxs("div",{className:"text-xs text-neutral-600",children:[n.jsx("span",{className:"font-medium",children:e("CLI 配置:")})," ",e("已配置")]}),Object.keys(x.env).length>0&&!x.settings&&n.jsxs("div",{className:"text-xs text-neutral-600",children:[n.jsx("span",{className:"font-medium",children:e("环境变量:")})," ",Object.keys(x.env).join(", ")]})]}),n.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[n.jsx("button",{onClick:()=>he(m),className:"p-2 text-neutral-400 hover:text-neutral-900 transition-colors",title:e("编辑"),children:n.jsx(Oe,{size:14})}),n.jsx("button",{onClick:()=>de(x),className:"p-2 text-neutral-400 hover:text-red-600 transition-colors",title:x.deletable===!1?e("系统内置 Provider 不可删除"):x.builtIn?e("删除自定义覆盖并恢复默认"):e("删除"),disabled:x.deletable===!1,children:n.jsx(se,{size:14})})]})]})},x.id)})}),p&&n.jsx(ut,{isOpen:!0,onClose:()=>v(null),initialData:p.data,onSave:m=>{p.id?ce(p.id,m):D(m)}}),n.jsx(_e,{isOpen:h!==null,onClose:()=>{s.isPending||u(null)},onConfirm:ue,title:h?.builtIn?e("恢复默认 Provider"):e("删除 Provider"),description:h?.builtIn?e('确定删除 "{name}" 的自定义覆盖，并恢复系统默认配置？',{name:h?.name}):e('确定删除 "{name}"？此操作不可撤销。',{name:h?.name}),confirmText:h?.builtIn?e("恢复默认"):e("删除"),cancelText:e("取消"),variant:"danger",isLoading:s.isPending}),n.jsx(mt,{isOpen:g,onClose:J,onConfirm:me,acknowledged:b,onAcknowledgedChange:C,isLoading:r.isPending}),n.jsx(xt,{isOpen:!!j,onClose:Y,preview:j?.preview??null,backup:j?.backup??null,onConfirm:pe,isLoading:d.isPending})]})}export{Et as ProviderSettingsPage};
