@kaitranntt/ccs 7.69.1-dev.3 → 7.69.1-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cliproxy/binary/version-cache.d.ts +10 -0
- package/dist/cliproxy/binary/version-cache.d.ts.map +1 -1
- package/dist/cliproxy/binary/version-cache.js +29 -7
- package/dist/cliproxy/binary/version-cache.js.map +1 -1
- package/dist/cliproxy/binary/version-checker.d.ts +14 -3
- package/dist/cliproxy/binary/version-checker.d.ts.map +1 -1
- package/dist/cliproxy/binary/version-checker.js +65 -36
- package/dist/cliproxy/binary/version-checker.js.map +1 -1
- package/dist/ui/assets/accounts-DamxGxu1.js +1 -0
- package/dist/ui/assets/{alert-dialog-BA39vaYL.js → alert-dialog-sars2LJq.js} +1 -1
- package/dist/ui/assets/{api-D2cjf1H4.js → api-DHF10LeP.js} +1 -1
- package/dist/ui/assets/{auth-section-BNX8_9MJ.js → auth-section-BNmbrWhd.js} +1 -1
- package/dist/ui/assets/{backups-section-Bt0FA5zl.js → backups-section-DGURGm2o.js} +1 -1
- package/dist/ui/assets/channels-B0j9pbpo.js +1 -0
- package/dist/ui/assets/{checkbox-DHF-UBrH.js → checkbox-DQIFU7Wu.js} +1 -1
- package/dist/ui/assets/claude-extension-qxiVTjYL.js +1 -0
- package/dist/ui/assets/{cliproxy-CD7z-_q8.js → cliproxy-CdvU0y2i.js} +1 -1
- package/dist/ui/assets/{cliproxy-ai-providers-QSOOqh8F.js → cliproxy-ai-providers-zgUBcUcJ.js} +1 -1
- package/dist/ui/assets/{cliproxy-control-panel-D9dLU28p.js → cliproxy-control-panel-S6FdJjgh.js} +1 -1
- package/dist/ui/assets/codex-B79sHpGl.js +27 -0
- package/dist/ui/assets/{confirm-dialog-BICDz_zm.js → confirm-dialog-DwrX5gr_.js} +1 -1
- package/dist/ui/assets/{copilot-BnQrRCuJ.js → copilot-CgE4vyvS.js} +1 -1
- package/dist/ui/assets/{cursor-CXopLKfC.js → cursor-rYsOav5G.js} +1 -1
- package/dist/ui/assets/{droid-CLFg9ELE.js → droid-CQlRU59Q.js} +1 -1
- package/dist/ui/assets/{globalenv-section-NPjCcYBN.js → globalenv-section-DSQ3m4Ei.js} +1 -1
- package/dist/ui/assets/{health-B_3JpCrY.js → health-DE-wdzdl.js} +1 -1
- package/dist/ui/assets/{index-B5Egq7qY.js → index-BcJqrfhu.js} +1 -1
- package/dist/ui/assets/{index-BgGHTjTd.js → index-BwtPYSbP.js} +1 -1
- package/dist/ui/assets/{index-BY2j-o67.js → index-C5VFMOG4.js} +1 -1
- package/dist/ui/assets/index-CqJW-L_1.js +1 -0
- package/dist/ui/assets/{index-BcUkpsGj.js → index-D1jFmelj.js} +1 -1
- package/dist/ui/assets/index-g2g1k0QS.js +72 -0
- package/dist/ui/assets/{logs-Bb1OVYeK.js → logs-CDpci_AI.js} +1 -1
- package/dist/ui/assets/{masked-input-b4-lEKNq.js → masked-input-DXzbXJrE.js} +1 -1
- package/dist/ui/assets/{proxy-status-widget-s89zaj3X.js → proxy-status-widget-DCQBVSBP.js} +1 -1
- package/dist/ui/assets/{raw-json-settings-editor-panel-Dr_BNQwQ.js → raw-json-settings-editor-panel-Db_WTo0f.js} +1 -1
- package/dist/ui/assets/{searchable-select-FJPe_YWv.js → searchable-select-CHzzY0Km.js} +1 -1
- package/dist/ui/assets/{separator-DJ0ku_ak.js → separator-Bd4OFZm5.js} +1 -1
- package/dist/ui/assets/{shared-DyQlJnbj.js → shared-B8K097LC.js} +1 -1
- package/dist/ui/assets/{table-6Yg65ZZH.js → table-7IypCMku.js} +1 -1
- package/dist/ui/assets/updates-4X5hHhUg.js +1 -0
- package/dist/ui/index.html +1 -1
- package/dist/web-server/routes/cliproxy-stats-routes.d.ts +37 -0
- package/dist/web-server/routes/cliproxy-stats-routes.d.ts.map +1 -1
- package/dist/web-server/routes/cliproxy-stats-routes.js +56 -10
- package/dist/web-server/routes/cliproxy-stats-routes.js.map +1 -1
- package/package.json +1 -1
- package/dist/ui/assets/accounts-DN0lP-yj.js +0 -1
- package/dist/ui/assets/channels-FaDUjf3Y.js +0 -1
- package/dist/ui/assets/claude-extension-D-skBToQ.js +0 -1
- package/dist/ui/assets/codex-CHO5_hku.js +0 -27
- package/dist/ui/assets/index-DNmWbKbN.js +0 -72
- package/dist/ui/assets/index-DZddoGfE.js +0 -1
- package/dist/ui/assets/updates-DSCXb6Au.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as Q}from"./react-vendor-CNOkPC89.js";import{t as j}from"./notifications-B2HqRBj7.js";import{bb as X,bc as Ne,a as Z,C as b,j as v,k as y,B as E,b as N,r as q,s as H,t as W,v as Y,w as k,I as le,bi as we,bj as ae,bk as ke,Q as Se,R as Pe,U,V,n as A,bd as Ee,c as Ce}from"./index-DNmWbKbN.js";import{a as Te,u as ie,b as Ae}from"./tanstack-CrmUhA7Z.js";import{a as Re}from"./raw-json-settings-editor-panel-Dr_BNQwQ.js";import{ax as _e,aB as De,N as Oe,L as Me,S as Be,aX as Fe,x as Le,I as Ie,T as Ke,ad as Ue,ah as Ve,p as oe}from"./icons-KVCk4_U8.js";import{S as R}from"./separator-DJ0ku_ak.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function $e(s){try{const r=JSON.parse(s);return!r||typeof r!="object"||Array.isArray(r)?{settings:null,parseError:"JSON root must be an object."}:{settings:r,parseError:null}}catch(r){return{settings:null,parseError:r.message}}}async function ze(){const s=await fetch(X("/droid/diagnostics"));if(!s.ok)throw new Error("Failed to fetch Droid diagnostics");return s.json()}async function Je(){const s=await fetch(X("/droid/settings/raw"));if(!s.ok)throw new Error("Failed to fetch Droid raw settings");return s.json()}async function Qe(s){const r=await fetch(X("/droid/settings/raw"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(r.status===409)throw new Ne("Droid raw settings changed externally");if(!r.ok){const n=await r.json().catch(()=>null);throw new Error(n?.error||"Failed to save Droid raw settings")}return r.json()}function qe(){const s=Te(),r=ie({queryKey:["droid-diagnostics"],queryFn:ze,refetchInterval:1e4}),n=ie({queryKey:["droid-raw-settings"],queryFn:Je}),i=Ae({mutationFn:Qe,onSuccess:(l,d)=>{s.setQueryData(["droid-raw-settings"],o=>{const t=o?.path??"~/.factory/settings.json",c=o?.resolvedPath??t,m=$e(d.rawText);return{path:t,resolvedPath:c,exists:!0,mtime:l.mtime,rawText:d.rawText,settings:m.settings,parseError:m.parseError}}),s.invalidateQueries({queryKey:["droid-diagnostics"]})}});return Q.useMemo(()=>({diagnostics:r.data,diagnosticsLoading:r.isLoading,diagnosticsError:r.error,refetchDiagnostics:r.refetch,rawSettings:n.data,rawSettingsLoading:n.isLoading,rawSettingsError:n.error,refetchRawSettings:n.refetch,saveRawSettings:i.mutate,saveRawSettingsAsync:i.mutateAsync,isSavingRawSettings:i.isPending}),[r.data,r.isLoading,r.error,r.refetch,n.data,n.isLoading,n.error,n.refetch,i.mutate,i.mutateAsync,i.isPending])}const He=["customModels","custom_models"],We={low:4e3,medium:12e3,high:3e4,max:5e4,xhigh:64e3},Ye=["low","medium","high","max","xhigh"];function p(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function h(s){return typeof s=="string"&&s.trim()?s.trim():null}function D(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function G(s){if(!s)return"unknown";const r=s.toLowerCase();return r==="anthropic"?"anthropic":r==="openai"?"openai":r==="generic-chat-completion-api"?"generic-chat-completion-api":"unknown"}function Ge(s,r,n){return`${s}:${r}:${encodeURIComponent(String(n))}`}function Xe(s){const r=s.indexOf(":"),n=s.indexOf(":",r+1);if(r<=0||n<=r+1)return null;const i=s.slice(0,r),l=s.slice(r+1,n),d=s.slice(n+1);if(i!=="customModels"&&i!=="custom_models"||l!=="array"&&l!=="object")return null;const o=decodeURIComponent(d);if(l==="array"){const t=Number.parseInt(o,10);return!Number.isInteger(t)||t<0?null:{rootKey:i,locationType:l,locationKey:t}}return{rootKey:i,locationType:l,locationKey:o}}function Ze(s){return!s||s<=0?null:s<=4e3?"low":s<=12e3?"medium":s<=3e4?"high":s<=5e4?"max":"xhigh"}function es(s){return Object.prototype.hasOwnProperty.call(s,"extraArgs")?"extraArgs":Object.prototype.hasOwnProperty.call(s,"extra_args")?"extra_args":"extraArgs"}function de(s){return JSON.parse(JSON.stringify(s))}function ss(s){const r=[];for(const n of He){const i=s[n];if(Array.isArray(i)){i.forEach((l,d)=>{p(l)&&r.push({rootKey:n,locationType:"array",locationKey:d,entry:l})});continue}if(p(i))for(const[l,d]of Object.entries(i))p(d)&&r.push({rootKey:n,locationType:"object",locationKey:l,entry:d})}return r}function ce(s,r){const n=Xe(r);if(!n)return null;const i=s[n.rootKey];if(n.locationType==="array"){if(!Array.isArray(i))return null;const o=i[n.locationKey];if(!p(o))return null;const t=h(o.provider);return{entry:o,providerKind:G(t)}}if(!p(i))return null;const l=i[n.locationKey];if(!p(l))return null;const d=h(l.provider);return{entry:l,providerKind:G(d)}}function rs(s,r){const n=r.extraArgs??r.extra_args,i=p(n)?n:null;if(!i)return{effort:null,anthropicBudgetTokens:null};const l=h(i.reasoning_effort)??h(i.reasoningEffort),d=p(i.reasoning)?i.reasoning:null,o=d?h(d.effort):null,t=p(i.thinking)?i.thinking:null,c=t?h(t.type):null,m=t?D(t.budget_tokens)??D(t.budgetTokens):null;return s==="openai"?{effort:o??l,anthropicBudgetTokens:null}:s==="anthropic"?c==="enabled"?{effort:Ze(m)??"high",anthropicBudgetTokens:m}:{effort:o??l,anthropicBudgetTokens:m}:{effort:l??o,anthropicBudgetTokens:null}}function ts(s){if(!s)return null;const r=s.trim().toLowerCase();return!r||r==="default"||r==="unset"||r==="off"||r==="none"||r==="disabled"?null:r}function ue(s){const r=es(s),n=s[r],i=p(n)?{...n}:{};return{extraArgsKey:r,extraArgs:i}}function me(s,r,n){if(Object.keys(n).length===0){delete s[r];return}s[r]=n}function ns(s){return ss(s).map(({rootKey:r,locationType:n,locationKey:i,entry:l})=>{const d=h(l.displayName)??h(l.model_display_name)??"Unnamed model",o=h(l.model)??"",t=h(l.provider)??"unknown",c=G(t),m=rs(c,l);return{id:Ge(r,n,i),rootKey:r,locationType:n,locationKey:i,displayName:d,model:o,provider:t,providerKind:c,effort:m.effort,anthropicBudgetTokens:m.anthropicBudgetTokens}})}function as(s,r,n){const i=de(s),l=ce(i,r);if(!l)return null;const d=ts(n),{extraArgsKey:o,extraArgs:t}=ue(l.entry);if(l.providerKind==="openai")if(delete t.reasoning_effort,delete t.reasoningEffort,!d)delete t.reasoning;else{const c=p(t.reasoning)?t.reasoning:{};t.reasoning={...c,effort:d}}else if(l.providerKind==="anthropic")if(delete t.reasoning_effort,delete t.reasoningEffort,delete t.reasoning,!d)delete t.thinking;else{const c=p(t.thinking)?{...t.thinking}:{},m=D(c.budget_tokens)??D(c.budgetTokens);delete c.budgetTokens,t.thinking={...c,type:"enabled",budget_tokens:m??We[d]??3e4}}else delete t.reasoning,delete t.reasoningEffort,d?t.reasoning_effort=d:delete t.reasoning_effort;return me(l.entry,o,t),i}function is(s,r,n){const i=de(s),l=ce(i,r);if(!l||l.providerKind!=="anthropic")return null;const{extraArgsKey:d,extraArgs:o}=ue(l.entry),t=p(o.thinking)?{...o.thinking}:{};if(t.type="enabled",n===null)delete t.budget_tokens,delete t.budgetTokens;else{const c=Math.max(1024,Math.floor(n));t.budget_tokens=c,delete t.budgetTokens}return o.thinking=t,me(l.entry,d,o),i}const $="__unset__";function os(s){return s.providerKind==="openai"?"Writes: extraArgs.reasoning.effort":s.providerKind==="anthropic"?"Writes: extraArgs.thinking.{type,budget_tokens}":"Writes: extraArgs.reasoning_effort"}function ls({models:s,disabled:r,disabledReason:n,onEffortChange:i,onAnthropicBudgetChange:l}){const{t:d}=Z();return e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(_e,{className:"h-4 w-4"}),d("droidSettings.reasoningControls"),e.jsx(E,{variant:"outline",className:"text-[10px] font-normal",children:"customModels"})]})}),e.jsxs(N,{className:"space-y-3",children:[n&&e.jsx("p",{className:"text-xs text-amber-600",children:n}),s.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No BYOK custom models found in settings.json (`customModels` or `custom_models`)."}):e.jsx("div",{className:"space-y-2",children:s.map(o=>e.jsxs("div",{className:"rounded-md border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium truncate",children:o.displayName}),e.jsx("p",{className:"text-[11px] font-mono text-muted-foreground truncate",children:o.model||"(missing model id)"})]}),e.jsx(E,{variant:"outline",className:"font-mono text-[10px] shrink-0",children:o.provider})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-medium",children:d("codex.reasoningEffortCapitalized")}),e.jsxs(q,{value:o.effort??$,onValueChange:t=>i(o.id,t===$?null:t),disabled:r,children:[e.jsx(H,{className:"h-8 text-xs",children:e.jsx(W,{placeholder:"Use provider default"})}),e.jsxs(Y,{children:[e.jsx(k,{value:$,children:"Use provider default"}),Ye.map(t=>e.jsx(k,{value:t,children:t},t))]})]})]}),o.providerKind==="anthropic"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-medium",children:d("codex.thinkingBudgetTokens")}),e.jsx(le,{type:"number",min:1024,step:1024,value:o.anthropicBudgetTokens??"",placeholder:"auto",className:"h-8 text-xs",disabled:r,onChange:t=>{const c=t.target.value.trim();if(!c){l(o.id,null);return}const m=Number.parseInt(c,10);Number.isFinite(m)&&l(o.id,Math.max(1024,m))}})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:os(o)})]},o.id))})]})]})}const T="__unset__",ds=[{key:"reasoningEffort",label:"Reasoning Effort",description:"none | medium | high | max",options:[{value:"none",label:"none"},{value:"medium",label:"medium"},{value:"high",label:"high"},{value:"max",label:"max"}]},{key:"autonomyLevel",label:"Autonomy Level",description:"suggest | aggressive | full",options:[{value:"suggest",label:"suggest"},{value:"aggressive",label:"aggressive"},{value:"full",label:"full"}]},{key:"diffMode",label:"Diff Mode",description:"auto | none | inline | split",options:[{value:"auto",label:"auto"},{value:"none",label:"none"},{value:"inline",label:"inline"},{value:"split",label:"split"}]}],cs=[{key:"todoEnabled",label:"Todo Enabled"},{key:"todoAutoRefresh",label:"Todo Auto Refresh"},{key:"autoCompactEnabled",label:"Auto Compact Enabled"},{key:"soundEnabled",label:"Sound Enabled"}],us=[{key:"maxTurns",label:"Max Turns",min:1,step:1},{key:"maxToolCalls",label:"Max Tool Calls",min:1,step:1},{key:"autoCompactThreshold",label:"Auto Compact Threshold",min:1e3,step:1e3}];function ms(s){return s===!0?"true":s===!1?"false":T}function xs(s){return s==="true"?!0:s==="false"?!1:null}function gs({values:s,disabled:r,disabledReason:n,onEnumSettingChange:i,onBooleanSettingChange:l,onNumberSettingChange:d}){const{t:o}=Z();return e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(De,{className:"h-4 w-4"}),o("droidSettings.quickControls"),e.jsx(E,{variant:"outline",className:"text-[10px] font-normal",children:"settings.json"})]})}),e.jsxs(N,{className:"space-y-4",children:[n&&e.jsx("p",{className:"text-xs text-amber-600",children:n}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[ds.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsxs(q,{value:s[t.key]??T,onValueChange:c=>i(t.key,c===T?null:c),disabled:r,children:[e.jsx(H,{className:"h-8 text-xs",children:e.jsx(W,{placeholder:o("codex.useDefault")})}),e.jsxs(Y,{children:[e.jsx(k,{value:T,children:o("codex.useDefault")}),t.options.map(c=>e.jsx(k,{value:c.value,children:c.label},c.value))]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t.description})]},t.key)),us.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsx(le,{type:"number",min:t.min,step:t.step,value:s[t.key]??"",onChange:c=>{const m=c.target.value.trim();if(!m){d(t.key,null);return}const S=Number.parseInt(m,10);Number.isFinite(S)&&d(t.key,Math.max(t.min,S))},className:"h-8 text-xs",disabled:r})]},t.key)),cs.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsxs(q,{value:ms(s[t.key]),onValueChange:c=>l(t.key,xs(c)),disabled:r,children:[e.jsx(H,{className:"h-8 text-xs",children:e.jsx(W,{placeholder:o("codex.useDefault")})}),e.jsxs(Y,{children:[e.jsx(k,{value:T,children:o("codex.useDefault")}),e.jsx(k,{value:"true",children:"true"}),e.jsx(k,{value:"false",children:"false"})]})]})]},t.key))]})]})]})}const fs=[{id:"droid-cli-overview",label:"Droid CLI Overview",url:"https://docs.factory.ai/cli/",description:"Primary entry docs for setup, auth, and core CLI usage."},{id:"droid-byok-overview",label:"BYOK Overview",url:"https://docs.factory.ai/cli/byok/overview/",description:"BYOK model/provider shape, provider values, and migration notes."},{id:"droid-settings-reference",label:"settings.json Reference",url:"https://docs.factory.ai/cli/configuration/settings/",description:"Supported settings keys, defaults, and allowed values."}],ps=[{provider:"anthropic",label:"Anthropic Messages API",apiFormat:"Messages API",url:"https://docs.anthropic.com/en/api/messages"},{provider:"openai",label:"OpenAI Responses API",apiFormat:"Responses API",url:"https://platform.openai.com/docs/api-reference/responses"},{provider:"generic-chat-completion-api",label:"OpenAI Chat Completions Spec",apiFormat:"Chat Completions API",url:"https://platform.openai.com/docs/api-reference/chat"}];function hs(s){const r=/https?:\/\/[^\s)]+/g,n=[];let i=0,l;for(;(l=r.exec(s))!==null;){const[d]=l,o=l.index;o>i&&n.push(s.slice(i,o)),n.push(e.jsx("a",{href:d,target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:d},`${d}-${o}`)),i=o+d.length}return i<s.length&&n.push(s.slice(i)),n.length>0?n:[s]}function js(s){return!s||!Number.isFinite(s)?"N/A":new Date(s).toLocaleString()}function bs(s){return!s||s<=0?"0 B":s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(2)} MB`}function vs(s){try{const r=JSON.parse(s);return!r||typeof r!="object"||Array.isArray(r)?{valid:!1,error:"JSON root must be an object."}:{valid:!0,value:r}}catch(r){return{valid:!1,error:r.message}}}function z(s){return typeof s=="string"?s:null}function J(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function _(s){return typeof s=="boolean"?s:null}function g({label:s,value:r,mono:n=!1}){return e.jsxs("div",{className:"flex items-start justify-between gap-3 text-sm",children:[e.jsx("span",{className:"text-muted-foreground shrink-0",children:s}),e.jsx("span",{className:Ce("text-right break-all",n&&"font-mono text-xs"),children:r})]})}function _s(){const{t:s}=Z(),{diagnostics:r,diagnosticsLoading:n,diagnosticsError:i,refetchDiagnostics:l,rawSettings:d,rawSettingsLoading:o,refetchRawSettings:t,saveRawSettingsAsync:c,isSavingRawSettings:m}=qe(),[S,O]=Q.useState(null),M=d?.rawText??"{}",B=S??M,ee=S!==null&&S!==M,u=vs(B),F=u.valid?{valid:!0}:{valid:!1,error:u.error},se=x=>{if(x===M){O(null);return}O(x)},L=x=>{se(JSON.stringify(x,null,2)+`
|
|
1
|
+
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as Q}from"./react-vendor-CNOkPC89.js";import{t as j}from"./notifications-B2HqRBj7.js";import{bb as X,bc as Ne,a as Z,C as b,j as v,k as y,B as E,b as N,r as q,s as H,t as W,v as Y,w as k,I as le,bi as we,bj as ae,bk as ke,Q as Se,R as Pe,U,V,n as A,bd as Ee,c as Ce}from"./index-g2g1k0QS.js";import{a as Te,u as ie,b as Ae}from"./tanstack-CrmUhA7Z.js";import{a as Re}from"./raw-json-settings-editor-panel-Db_WTo0f.js";import{ax as _e,aB as De,N as Oe,L as Me,S as Be,aX as Fe,x as Le,I as Ie,T as Ke,ad as Ue,ah as Ve,p as oe}from"./icons-KVCk4_U8.js";import{S as R}from"./separator-Bd4OFZm5.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function $e(s){try{const r=JSON.parse(s);return!r||typeof r!="object"||Array.isArray(r)?{settings:null,parseError:"JSON root must be an object."}:{settings:r,parseError:null}}catch(r){return{settings:null,parseError:r.message}}}async function ze(){const s=await fetch(X("/droid/diagnostics"));if(!s.ok)throw new Error("Failed to fetch Droid diagnostics");return s.json()}async function Je(){const s=await fetch(X("/droid/settings/raw"));if(!s.ok)throw new Error("Failed to fetch Droid raw settings");return s.json()}async function Qe(s){const r=await fetch(X("/droid/settings/raw"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(r.status===409)throw new Ne("Droid raw settings changed externally");if(!r.ok){const n=await r.json().catch(()=>null);throw new Error(n?.error||"Failed to save Droid raw settings")}return r.json()}function qe(){const s=Te(),r=ie({queryKey:["droid-diagnostics"],queryFn:ze,refetchInterval:1e4}),n=ie({queryKey:["droid-raw-settings"],queryFn:Je}),i=Ae({mutationFn:Qe,onSuccess:(l,d)=>{s.setQueryData(["droid-raw-settings"],o=>{const t=o?.path??"~/.factory/settings.json",c=o?.resolvedPath??t,m=$e(d.rawText);return{path:t,resolvedPath:c,exists:!0,mtime:l.mtime,rawText:d.rawText,settings:m.settings,parseError:m.parseError}}),s.invalidateQueries({queryKey:["droid-diagnostics"]})}});return Q.useMemo(()=>({diagnostics:r.data,diagnosticsLoading:r.isLoading,diagnosticsError:r.error,refetchDiagnostics:r.refetch,rawSettings:n.data,rawSettingsLoading:n.isLoading,rawSettingsError:n.error,refetchRawSettings:n.refetch,saveRawSettings:i.mutate,saveRawSettingsAsync:i.mutateAsync,isSavingRawSettings:i.isPending}),[r.data,r.isLoading,r.error,r.refetch,n.data,n.isLoading,n.error,n.refetch,i.mutate,i.mutateAsync,i.isPending])}const He=["customModels","custom_models"],We={low:4e3,medium:12e3,high:3e4,max:5e4,xhigh:64e3},Ye=["low","medium","high","max","xhigh"];function p(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function h(s){return typeof s=="string"&&s.trim()?s.trim():null}function D(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function G(s){if(!s)return"unknown";const r=s.toLowerCase();return r==="anthropic"?"anthropic":r==="openai"?"openai":r==="generic-chat-completion-api"?"generic-chat-completion-api":"unknown"}function Ge(s,r,n){return`${s}:${r}:${encodeURIComponent(String(n))}`}function Xe(s){const r=s.indexOf(":"),n=s.indexOf(":",r+1);if(r<=0||n<=r+1)return null;const i=s.slice(0,r),l=s.slice(r+1,n),d=s.slice(n+1);if(i!=="customModels"&&i!=="custom_models"||l!=="array"&&l!=="object")return null;const o=decodeURIComponent(d);if(l==="array"){const t=Number.parseInt(o,10);return!Number.isInteger(t)||t<0?null:{rootKey:i,locationType:l,locationKey:t}}return{rootKey:i,locationType:l,locationKey:o}}function Ze(s){return!s||s<=0?null:s<=4e3?"low":s<=12e3?"medium":s<=3e4?"high":s<=5e4?"max":"xhigh"}function es(s){return Object.prototype.hasOwnProperty.call(s,"extraArgs")?"extraArgs":Object.prototype.hasOwnProperty.call(s,"extra_args")?"extra_args":"extraArgs"}function de(s){return JSON.parse(JSON.stringify(s))}function ss(s){const r=[];for(const n of He){const i=s[n];if(Array.isArray(i)){i.forEach((l,d)=>{p(l)&&r.push({rootKey:n,locationType:"array",locationKey:d,entry:l})});continue}if(p(i))for(const[l,d]of Object.entries(i))p(d)&&r.push({rootKey:n,locationType:"object",locationKey:l,entry:d})}return r}function ce(s,r){const n=Xe(r);if(!n)return null;const i=s[n.rootKey];if(n.locationType==="array"){if(!Array.isArray(i))return null;const o=i[n.locationKey];if(!p(o))return null;const t=h(o.provider);return{entry:o,providerKind:G(t)}}if(!p(i))return null;const l=i[n.locationKey];if(!p(l))return null;const d=h(l.provider);return{entry:l,providerKind:G(d)}}function rs(s,r){const n=r.extraArgs??r.extra_args,i=p(n)?n:null;if(!i)return{effort:null,anthropicBudgetTokens:null};const l=h(i.reasoning_effort)??h(i.reasoningEffort),d=p(i.reasoning)?i.reasoning:null,o=d?h(d.effort):null,t=p(i.thinking)?i.thinking:null,c=t?h(t.type):null,m=t?D(t.budget_tokens)??D(t.budgetTokens):null;return s==="openai"?{effort:o??l,anthropicBudgetTokens:null}:s==="anthropic"?c==="enabled"?{effort:Ze(m)??"high",anthropicBudgetTokens:m}:{effort:o??l,anthropicBudgetTokens:m}:{effort:l??o,anthropicBudgetTokens:null}}function ts(s){if(!s)return null;const r=s.trim().toLowerCase();return!r||r==="default"||r==="unset"||r==="off"||r==="none"||r==="disabled"?null:r}function ue(s){const r=es(s),n=s[r],i=p(n)?{...n}:{};return{extraArgsKey:r,extraArgs:i}}function me(s,r,n){if(Object.keys(n).length===0){delete s[r];return}s[r]=n}function ns(s){return ss(s).map(({rootKey:r,locationType:n,locationKey:i,entry:l})=>{const d=h(l.displayName)??h(l.model_display_name)??"Unnamed model",o=h(l.model)??"",t=h(l.provider)??"unknown",c=G(t),m=rs(c,l);return{id:Ge(r,n,i),rootKey:r,locationType:n,locationKey:i,displayName:d,model:o,provider:t,providerKind:c,effort:m.effort,anthropicBudgetTokens:m.anthropicBudgetTokens}})}function as(s,r,n){const i=de(s),l=ce(i,r);if(!l)return null;const d=ts(n),{extraArgsKey:o,extraArgs:t}=ue(l.entry);if(l.providerKind==="openai")if(delete t.reasoning_effort,delete t.reasoningEffort,!d)delete t.reasoning;else{const c=p(t.reasoning)?t.reasoning:{};t.reasoning={...c,effort:d}}else if(l.providerKind==="anthropic")if(delete t.reasoning_effort,delete t.reasoningEffort,delete t.reasoning,!d)delete t.thinking;else{const c=p(t.thinking)?{...t.thinking}:{},m=D(c.budget_tokens)??D(c.budgetTokens);delete c.budgetTokens,t.thinking={...c,type:"enabled",budget_tokens:m??We[d]??3e4}}else delete t.reasoning,delete t.reasoningEffort,d?t.reasoning_effort=d:delete t.reasoning_effort;return me(l.entry,o,t),i}function is(s,r,n){const i=de(s),l=ce(i,r);if(!l||l.providerKind!=="anthropic")return null;const{extraArgsKey:d,extraArgs:o}=ue(l.entry),t=p(o.thinking)?{...o.thinking}:{};if(t.type="enabled",n===null)delete t.budget_tokens,delete t.budgetTokens;else{const c=Math.max(1024,Math.floor(n));t.budget_tokens=c,delete t.budgetTokens}return o.thinking=t,me(l.entry,d,o),i}const $="__unset__";function os(s){return s.providerKind==="openai"?"Writes: extraArgs.reasoning.effort":s.providerKind==="anthropic"?"Writes: extraArgs.thinking.{type,budget_tokens}":"Writes: extraArgs.reasoning_effort"}function ls({models:s,disabled:r,disabledReason:n,onEffortChange:i,onAnthropicBudgetChange:l}){const{t:d}=Z();return e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(_e,{className:"h-4 w-4"}),d("droidSettings.reasoningControls"),e.jsx(E,{variant:"outline",className:"text-[10px] font-normal",children:"customModels"})]})}),e.jsxs(N,{className:"space-y-3",children:[n&&e.jsx("p",{className:"text-xs text-amber-600",children:n}),s.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No BYOK custom models found in settings.json (`customModels` or `custom_models`)."}):e.jsx("div",{className:"space-y-2",children:s.map(o=>e.jsxs("div",{className:"rounded-md border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium truncate",children:o.displayName}),e.jsx("p",{className:"text-[11px] font-mono text-muted-foreground truncate",children:o.model||"(missing model id)"})]}),e.jsx(E,{variant:"outline",className:"font-mono text-[10px] shrink-0",children:o.provider})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-medium",children:d("codex.reasoningEffortCapitalized")}),e.jsxs(q,{value:o.effort??$,onValueChange:t=>i(o.id,t===$?null:t),disabled:r,children:[e.jsx(H,{className:"h-8 text-xs",children:e.jsx(W,{placeholder:"Use provider default"})}),e.jsxs(Y,{children:[e.jsx(k,{value:$,children:"Use provider default"}),Ye.map(t=>e.jsx(k,{value:t,children:t},t))]})]})]}),o.providerKind==="anthropic"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-medium",children:d("codex.thinkingBudgetTokens")}),e.jsx(le,{type:"number",min:1024,step:1024,value:o.anthropicBudgetTokens??"",placeholder:"auto",className:"h-8 text-xs",disabled:r,onChange:t=>{const c=t.target.value.trim();if(!c){l(o.id,null);return}const m=Number.parseInt(c,10);Number.isFinite(m)&&l(o.id,Math.max(1024,m))}})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:os(o)})]},o.id))})]})]})}const T="__unset__",ds=[{key:"reasoningEffort",label:"Reasoning Effort",description:"none | medium | high | max",options:[{value:"none",label:"none"},{value:"medium",label:"medium"},{value:"high",label:"high"},{value:"max",label:"max"}]},{key:"autonomyLevel",label:"Autonomy Level",description:"suggest | aggressive | full",options:[{value:"suggest",label:"suggest"},{value:"aggressive",label:"aggressive"},{value:"full",label:"full"}]},{key:"diffMode",label:"Diff Mode",description:"auto | none | inline | split",options:[{value:"auto",label:"auto"},{value:"none",label:"none"},{value:"inline",label:"inline"},{value:"split",label:"split"}]}],cs=[{key:"todoEnabled",label:"Todo Enabled"},{key:"todoAutoRefresh",label:"Todo Auto Refresh"},{key:"autoCompactEnabled",label:"Auto Compact Enabled"},{key:"soundEnabled",label:"Sound Enabled"}],us=[{key:"maxTurns",label:"Max Turns",min:1,step:1},{key:"maxToolCalls",label:"Max Tool Calls",min:1,step:1},{key:"autoCompactThreshold",label:"Auto Compact Threshold",min:1e3,step:1e3}];function ms(s){return s===!0?"true":s===!1?"false":T}function xs(s){return s==="true"?!0:s==="false"?!1:null}function gs({values:s,disabled:r,disabledReason:n,onEnumSettingChange:i,onBooleanSettingChange:l,onNumberSettingChange:d}){const{t:o}=Z();return e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(De,{className:"h-4 w-4"}),o("droidSettings.quickControls"),e.jsx(E,{variant:"outline",className:"text-[10px] font-normal",children:"settings.json"})]})}),e.jsxs(N,{className:"space-y-4",children:[n&&e.jsx("p",{className:"text-xs text-amber-600",children:n}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[ds.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsxs(q,{value:s[t.key]??T,onValueChange:c=>i(t.key,c===T?null:c),disabled:r,children:[e.jsx(H,{className:"h-8 text-xs",children:e.jsx(W,{placeholder:o("codex.useDefault")})}),e.jsxs(Y,{children:[e.jsx(k,{value:T,children:o("codex.useDefault")}),t.options.map(c=>e.jsx(k,{value:c.value,children:c.label},c.value))]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t.description})]},t.key)),us.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsx(le,{type:"number",min:t.min,step:t.step,value:s[t.key]??"",onChange:c=>{const m=c.target.value.trim();if(!m){d(t.key,null);return}const S=Number.parseInt(m,10);Number.isFinite(S)&&d(t.key,Math.max(t.min,S))},className:"h-8 text-xs",disabled:r})]},t.key)),cs.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsxs(q,{value:ms(s[t.key]),onValueChange:c=>l(t.key,xs(c)),disabled:r,children:[e.jsx(H,{className:"h-8 text-xs",children:e.jsx(W,{placeholder:o("codex.useDefault")})}),e.jsxs(Y,{children:[e.jsx(k,{value:T,children:o("codex.useDefault")}),e.jsx(k,{value:"true",children:"true"}),e.jsx(k,{value:"false",children:"false"})]})]})]},t.key))]})]})]})}const fs=[{id:"droid-cli-overview",label:"Droid CLI Overview",url:"https://docs.factory.ai/cli/",description:"Primary entry docs for setup, auth, and core CLI usage."},{id:"droid-byok-overview",label:"BYOK Overview",url:"https://docs.factory.ai/cli/byok/overview/",description:"BYOK model/provider shape, provider values, and migration notes."},{id:"droid-settings-reference",label:"settings.json Reference",url:"https://docs.factory.ai/cli/configuration/settings/",description:"Supported settings keys, defaults, and allowed values."}],ps=[{provider:"anthropic",label:"Anthropic Messages API",apiFormat:"Messages API",url:"https://docs.anthropic.com/en/api/messages"},{provider:"openai",label:"OpenAI Responses API",apiFormat:"Responses API",url:"https://platform.openai.com/docs/api-reference/responses"},{provider:"generic-chat-completion-api",label:"OpenAI Chat Completions Spec",apiFormat:"Chat Completions API",url:"https://platform.openai.com/docs/api-reference/chat"}];function hs(s){const r=/https?:\/\/[^\s)]+/g,n=[];let i=0,l;for(;(l=r.exec(s))!==null;){const[d]=l,o=l.index;o>i&&n.push(s.slice(i,o)),n.push(e.jsx("a",{href:d,target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:d},`${d}-${o}`)),i=o+d.length}return i<s.length&&n.push(s.slice(i)),n.length>0?n:[s]}function js(s){return!s||!Number.isFinite(s)?"N/A":new Date(s).toLocaleString()}function bs(s){return!s||s<=0?"0 B":s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(2)} MB`}function vs(s){try{const r=JSON.parse(s);return!r||typeof r!="object"||Array.isArray(r)?{valid:!1,error:"JSON root must be an object."}:{valid:!0,value:r}}catch(r){return{valid:!1,error:r.message}}}function z(s){return typeof s=="string"?s:null}function J(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function _(s){return typeof s=="boolean"?s:null}function g({label:s,value:r,mono:n=!1}){return e.jsxs("div",{className:"flex items-start justify-between gap-3 text-sm",children:[e.jsx("span",{className:"text-muted-foreground shrink-0",children:s}),e.jsx("span",{className:Ce("text-right break-all",n&&"font-mono text-xs"),children:r})]})}function _s(){const{t:s}=Z(),{diagnostics:r,diagnosticsLoading:n,diagnosticsError:i,refetchDiagnostics:l,rawSettings:d,rawSettingsLoading:o,refetchRawSettings:t,saveRawSettingsAsync:c,isSavingRawSettings:m}=qe(),[S,O]=Q.useState(null),M=d?.rawText??"{}",B=S??M,ee=S!==null&&S!==M,u=vs(B),F=u.valid?{valid:!0}:{valid:!1,error:u.error},se=x=>{if(x===M){O(null);return}O(x)},L=x=>{se(JSON.stringify(x,null,2)+`
|
|
2
2
|
`)},I=(x,w)=>{if(!u.valid){j.error(s("droidPage.fixJsonBeforeQuickSettings"));return}const P={...u.value};w==null?delete P[x]:P[x]=w,L(P)},xe=u.valid?{reasoningEffort:z(u.value.reasoningEffort),autonomyLevel:z(u.value.autonomyLevel),diffMode:z(u.value.diffMode),maxTurns:J(u.value.maxTurns),maxToolCalls:J(u.value.maxToolCalls),autoCompactThreshold:J(u.value.autoCompactThreshold),todoEnabled:_(u.value.todoEnabled),todoAutoRefresh:_(u.value.todoAutoRefresh),autoCompactEnabled:_(u.value.autoCompactEnabled),soundEnabled:_(u.value.soundEnabled)}:{reasoningEffort:null,autonomyLevel:null,diffMode:null,maxTurns:null,maxToolCalls:null,autoCompactThreshold:null,todoEnabled:null,todoAutoRefresh:null,autoCompactEnabled:null,soundEnabled:null},ge=u.valid?ns(u.value):[],fe=async()=>{await Promise.all([l(),t()])},pe=async()=>{if(!F.valid){j.error(s("droidPage.invalidJson",{value:F.error}));return}try{await c({rawText:B,expectedMtime:d?.exists?d.mtime:void 0}),O(null),j.success(s("droidPage.saved"))}catch(x){Ee(x)?j.error(s("droidPage.changedExternally")):j.error(x.message||s("droidPage.failedSave"))}},re=r?.byok.customModels??[],te=Q.useMemo(()=>Object.entries(r?.byok.providerBreakdown??{}).sort((x,w)=>w[1]-x[1]),[r?.byok.providerBreakdown]),he=()=>{if(n)return e.jsxs("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:[e.jsx(Me,{className:"h-5 w-5 animate-spin mr-2"}),s("droidPage.loadingDiagnostics")]});if(i||!r)return e.jsx("div",{className:"flex h-full items-center justify-center text-destructive px-6 text-center",children:s("droidPage.failedDiagnostics")});const x=r.docsReference??{notes:[],links:[],providerDocs:[],providerValues:[],settingsHierarchy:[]},w=x.notes??[],P=x.links??[],ne=x.providerDocs??[],je=P.length>0?P:fs,be=ne.length>0?ne:ps,ve=x.providerValues??[],ye=x.settingsHierarchy??[],K="mt-0 h-full border-0 p-0 data-[state=inactive]:hidden";return e.jsxs(Se,{defaultValue:"byok",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Pe,{className:"grid w-full grid-cols-3",children:[e.jsx(U,{value:"overview",children:s("droidPage.overview")}),e.jsx(U,{value:"byok",children:s("droidPage.byok")}),e.jsx(U,{value:"docs",children:s("droidPage.docs")})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden px-4 pb-4 pt-3",children:[e.jsx(V,{value:"overview",className:K,children:e.jsx(A,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 pr-1",children:[e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Be,{className:"h-4 w-4"}),s("droidPage.runtimeInstall")]})}),e.jsxs(N,{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("droidPage.status")}),e.jsx(E,{variant:r.binary.installed?"default":"secondary",children:r.binary.installed?s("droidPage.detected"):s("droidPage.notFound")})]}),e.jsx(g,{label:s("droidPage.detectionSource"),value:r.binary.source,mono:!0}),e.jsx(g,{label:s("droidPage.binaryPath"),value:r.binary.path||s("droidPage.notFound"),mono:!0}),e.jsx(g,{label:s("droidPage.installDirectory"),value:r.binary.installDir||"N/A",mono:!0}),e.jsx(g,{label:s("droidPage.version"),value:r.binary.version||"Unknown",mono:!0}),e.jsx(g,{label:s("droidPage.overridePath"),value:r.binary.overridePath||"Not set",mono:!0})]})]}),e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Fe,{className:"h-4 w-4"}),s("droidPage.configFiles")]})}),e.jsx(N,{className:"space-y-3",children:[r.files.settings,r.files.legacyConfig].map(a=>e.jsxs("div",{className:"rounded-md border p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:a.label}),a.exists?e.jsx(Le,{className:"h-4 w-4 text-green-600"}):e.jsx(Ie,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(g,{label:s("droidPage.path"),value:a.path,mono:!0}),e.jsx(g,{label:s("droidPage.resolved"),value:a.resolvedPath,mono:!0}),e.jsx(g,{label:s("droidPage.size"),value:bs(a.sizeBytes)}),e.jsx(g,{label:s("droidPage.lastModified"),value:js(a.mtimeMs)}),a.parseError&&e.jsx("p",{className:"text-xs text-amber-600",children:s("droidPage.parseWarning",{value:a.parseError})}),a.readError&&e.jsx("p",{className:"text-xs text-destructive",children:s("droidPage.readWarning",{value:a.readError})})]},a.label))})]}),r.warnings.length>0&&e.jsxs(b,{className:"border-amber-200 bg-amber-50/50 dark:bg-amber-950/20",children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Ke,{className:"h-4 w-4 text-amber-600"}),s("droidPage.warnings")]})}),e.jsx(N,{className:"space-y-1.5",children:r.warnings.map(a=>e.jsxs("p",{className:"text-sm text-amber-800 dark:text-amber-300",children:["- ",a]},a))})]})]})})}),e.jsx(V,{value:"byok",className:K,children:e.jsx(A,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 pr-1",children:[e.jsx(gs,{values:xe,disabled:o||!u.valid,disabledReason:u.valid?null:`Quick settings disabled: ${u.error}`,onEnumSettingChange:(a,f)=>{I(a,f)},onBooleanSettingChange:(a,f)=>{I(a,f)},onNumberSettingChange:(a,f)=>{I(a,f)}}),e.jsx(ls,{models:ge,disabled:o||!u.valid,disabledReason:u.valid?null:`${s("droidPage.byok")}: ${u.error}`,onEffortChange:(a,f)=>{if(!u.valid){j.error(s("droidPage.fixJsonBeforeReasoning"));return}const C=as(u.value,a,f);if(!C){j.error(s("droidPage.unableUpdateReasoning"));return}L(C)},onAnthropicBudgetChange:(a,f)=>{if(!u.valid){j.error(s("droidPage.fixJsonBeforeBudget"));return}const C=is(u.value,a,f);if(!C){j.error(s("droidPage.anthropicOnlyBudget"));return}L(C)}}),e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Ue,{className:"h-4 w-4"}),s("droidPage.byokSummary")]})}),e.jsxs(N,{className:"space-y-2",children:[e.jsx(g,{label:s("droidPage.activeModelSelector"),value:r.byok.activeModelSelector||"Not set",mono:!0}),e.jsx(g,{label:s("droidPage.customModels"),value:String(r.byok.customModelCount)}),e.jsx(g,{label:s("droidPage.ccsManaged"),value:String(r.byok.ccsManagedCount)}),e.jsx(g,{label:s("droidPage.userManaged"),value:String(r.byok.userManagedCount)}),e.jsx(g,{label:s("droidPage.malformedEntries"),value:String(r.byok.invalidModelEntryCount)}),e.jsx(R,{}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("droidPage.providers")}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[te.length===0&&e.jsx(E,{variant:"secondary",className:"font-mono",children:s("droidPage.none")}),te.map(([a,f])=>e.jsxs(E,{variant:"outline",className:"font-mono text-xs",children:[a,": ",f]},a))]})]})]})]}),e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsx(y,{className:"text-base",children:s("droidPage.customModelsTitle")})}),e.jsx(N,{children:e.jsxs("div",{className:"rounded-md border overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-[2fr_1fr_2fr] bg-muted/40 px-3 py-2 text-xs font-medium",children:[e.jsx("span",{children:s("droidPage.modelName")}),e.jsx("span",{children:s("droidPage.provider")}),e.jsx("span",{children:s("droidPage.baseUrl")})]}),e.jsx(A,{className:"h-52",children:e.jsxs("div",{className:"divide-y",children:[re.length===0&&e.jsx("div",{className:"px-3 py-4 text-xs text-muted-foreground",children:s("droidPage.noCustomModels")}),re.map(a=>e.jsxs("div",{className:"grid grid-cols-[2fr_1fr_2fr] gap-2 px-3 py-2 text-xs",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:a.displayName}),e.jsx("p",{className:"text-muted-foreground font-mono truncate",children:a.model})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate",children:a.provider}),e.jsx("p",{className:"text-muted-foreground",children:a.apiKeyPreview||"no-key"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate",title:a.baseUrl,children:a.host||a.baseUrl}),e.jsx("p",{className:"text-muted-foreground font-mono truncate",children:a.baseUrl})]})]},`${a.displayName}-${a.model}-${a.baseUrl}`))]})})]})})]})]})})}),e.jsx(V,{value:"docs",className:K,children:e.jsx(A,{className:"h-full",children:e.jsx("div",{className:"space-y-4 pr-1",children:e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Ve,{className:"h-4 w-4"}),s("droidPage.docsAlignedNotes")]})}),e.jsxs(N,{className:"space-y-2 text-sm",children:[w.map((a,f)=>e.jsxs("p",{className:"text-muted-foreground",children:["- ",hs(a)]},`${f}-${a}`)),e.jsx(R,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:s("droidPage.factoryDocs")}),e.jsx("div",{className:"space-y-1.5",children:je.map(a=>e.jsxs("a",{href:a.url,target:"_blank",rel:"noreferrer",className:"block rounded-md border px-2.5 py-2 transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium",children:a.label}),e.jsx(oe,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),e.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:a.description}),e.jsx("p",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground/90 underline underline-offset-2",children:a.url})]},a.id))})]}),e.jsx(R,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:s("droidPage.providerFactCheckDocs")}),e.jsx("div",{className:"space-y-1.5",children:be.map(a=>e.jsxs("a",{href:a.url,target:"_blank",rel:"noreferrer",className:"block rounded-md border px-2.5 py-2 transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium",children:a.label}),e.jsx(oe,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["provider: ",a.provider," | format: ",a.apiFormat]}),e.jsx("p",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground/90 underline underline-offset-2",children:a.url})]},`${a.provider}-${a.url}`))})]}),e.jsx(R,{}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("droidPage.providerValues",{value:ve.join(", ")})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("droidPage.settingsHierarchy",{value:ye.join(" -> ")})})]})]})})})})]})]})};return e.jsx("div",{className:"h-full min-h-0 overflow-hidden",children:e.jsxs(we,{direction:"horizontal",className:"h-full",children:[e.jsx(ae,{defaultSize:45,minSize:35,children:e.jsx("div",{className:"h-full border-r bg-muted/20",children:he()})}),e.jsx(ke,{className:"w-2 bg-border hover:bg-primary/20 transition-colors cursor-col-resize flex items-center justify-center group",children:e.jsx(Oe,{className:"w-3 h-3 text-muted-foreground group-hover:text-primary"})}),e.jsx(ae,{defaultSize:55,minSize:35,children:e.jsx(Re,{title:s("droidPage.settingsTitle"),pathLabel:d?.path||"~/.factory/settings.json",loading:o,parseWarning:d?.parseError,value:B,dirty:ee,saving:m,saveDisabled:!ee||m||o||!F.valid,onChange:x=>{se(x)},onSave:pe,onRefresh:fe})})]})})}export{_s as DroidPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as g}from"./react-vendor-CNOkPC89.js";import{
|
|
1
|
+
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as g}from"./react-vendor-CNOkPC89.js";import{bp as C,bq as w,a as G,br as y,be as k,bg as S,n as R,aF as A,d as f,I as j}from"./index-g2g1k0QS.js";import{R as N,w as D,x as L,as as T,a9 as I}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function _(){const{state:s}=C(),n=w(),[o,r]=g.useState(""),[c,m]=g.useState(""),b=g.useCallback(async()=>{try{n.setGlobalEnvLoading(!0),n.setGlobalEnvError(null);const a=await fetch("/api/global-env");if(!a.ok)throw new Error("Failed to load Global Env config");const l=await a.json();n.setGlobalEnvConfig(l)}catch(a){n.setGlobalEnvError(a.message)}finally{n.setGlobalEnvLoading(!1)}},[n]),i=g.useCallback(async a=>{const l=s.globalEnvConfig;if(!l)return;const x={...l,...a};n.setGlobalEnvConfig(x);try{n.setGlobalEnvSaving(!0),n.setGlobalEnvError(null);const d=await fetch("/api/global-env",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)});if(!d.ok){const h=await d.json();throw new Error(h.error||"Failed to save")}const v=await d.json();n.setGlobalEnvConfig(v.config),n.setGlobalEnvSuccess(!0),setTimeout(()=>n.setGlobalEnvSuccess(!1),1500)}catch(d){n.setGlobalEnvConfig(l),n.setGlobalEnvError(d.message)}finally{n.setGlobalEnvSaving(!1)}},[s.globalEnvConfig,n]),E=g.useCallback(()=>{if(!o.trim()||!s.globalEnvConfig)return;const a={...s.globalEnvConfig.env,[o.trim()]:c};i({env:a}),r(""),m("")},[o,c,s.globalEnvConfig,i]),u=g.useCallback(a=>{if(!s.globalEnvConfig)return;const l={...s.globalEnvConfig.env};delete l[a],i({env:l})},[s.globalEnvConfig,i]);return{config:s.globalEnvConfig,loading:s.globalEnvLoading,saving:s.globalEnvSaving,error:s.globalEnvError,success:s.globalEnvSuccess,newEnvKey:o,setNewEnvKey:r,newEnvValue:c,setNewEnvValue:m,fetchConfig:b,saveConfig:i,addEnvVar:E,removeEnvVar:u}}function q(){const{t:s}=G(),{config:n,loading:o,saving:r,error:c,success:m,newEnvKey:b,setNewEnvKey:i,newEnvValue:E,setNewEnvValue:u,fetchConfig:a,saveConfig:l,addEnvVar:x,removeEnvVar:d}=_(),{fetchRawConfig:v}=y();g.useEffect(()=>{a(),v()},[a,v]);const h=()=>{l({enabled:!n?.enabled})};return o?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(N,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${c||m?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[c&&e.jsxs(k,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(D,{className:"h-4 w-4"}),e.jsx(S,{children:c})]}),m&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(L,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(R,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsGlobalEnv.description")}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:n?.enabled?s("settingsGlobalEnv.enabled"):s("settingsGlobalEnv.disabled")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n?.enabled?s("settingsGlobalEnv.enabledDesc"):s("settingsGlobalEnv.disabledDesc")})]}),e.jsx(A,{checked:n?.enabled??!0,onCheckedChange:h})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsGlobalEnv.envVars")}),n?.env&&Object.keys(n.env).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(n.env).map(([t,p])=>e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg border bg-background",children:[e.jsx("code",{className:"flex-1 font-mono text-sm truncate",children:t}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("code",{className:"font-mono text-sm px-2 py-1 bg-muted rounded",children:p}),e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>d(t),disabled:r,className:"h-8 w-8 p-0 text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(T,{className:"w-4 h-4"})})]},t))}):e.jsx("div",{className:"p-4 rounded-lg border border-dashed text-center text-muted-foreground",children:e.jsx("p",{children:s("settingsGlobalEnv.noneConfigured")})}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:s("settingsGlobalEnv.addNew")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{value:b,onChange:t=>i(t.target.value.toUpperCase()),placeholder:s("settingsGlobalEnv.keyName"),className:"flex-1 font-mono text-sm h-9",disabled:r}),e.jsx("span",{className:"flex items-center text-muted-foreground",children:"="}),e.jsx(j,{value:E,onChange:t=>u(t.target.value),placeholder:s("settingsGlobalEnv.value"),className:"flex-1 font-mono text-sm h-9",disabled:r}),e.jsxs(f,{size:"sm",onClick:x,disabled:r||!b.trim(),className:"h-9",children:[e.jsx(I,{className:"w-4 h-4 mr-1"}),s("settingsGlobalEnv.add")]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:s("settingsGlobalEnv.quickAdd")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[[{key:"DISABLE_BUG_COMMAND",value:"1"},{key:"DISABLE_ERROR_REPORTING",value:"1"},{key:"DISABLE_TELEMETRY",value:"1"}].map(({key:t,value:p})=>!n?.env?.[t]&&e.jsxs(f,{variant:"outline",size:"sm",onClick:()=>{i(t),u(p)},className:"text-xs font-mono",children:["+ ",t]},t)),n?.env&&["DISABLE_BUG_COMMAND","DISABLE_ERROR_REPORTING","DISABLE_TELEMETRY"].every(t=>n.env[t])&&e.jsx("span",{className:"text-sm text-muted-foreground",children:s("settingsGlobalEnv.allConfigured")})]})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(f,{variant:"outline",size:"sm",onClick:()=>{a(),v()},disabled:o||r,className:"w-full",children:[e.jsx(N,{className:`w-4 h-4 mr-2 ${o?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{q as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{a as N,c as l,d as p,M as k,N as C,O as S,B as R,S as h}from"./index-DNmWbKbN.js";import{u as W,a as E,b as O}from"./tanstack-CrmUhA7Z.js";import{t as g}from"./notifications-B2HqRBj7.js";import{r as j}from"./react-vendor-CNOkPC89.js";import{b5 as y,C as P,$ as I,o as M,Z as T,i as $,U as H,e as A,b6 as z,s as F,Y as B,R as D}from"./icons-KVCk4_U8.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const q={sm:{dimension:80,strokeWidth:6,fontSize:"text-lg",labelSize:"text-[10px]"},md:{dimension:120,strokeWidth:8,fontSize:"text-3xl",labelSize:"text-xs"},lg:{dimension:160,strokeWidth:10,fontSize:"text-4xl",labelSize:"text-sm"}},G={ok:{stroke:"#22C55E",glow:"rgba(34, 197, 94, 0.4)"},warning:{stroke:"#EAB308",glow:"rgba(234, 179, 8, 0.4)"},error:{stroke:"#EF4444",glow:"rgba(239, 68, 68, 0.4)"}};function K({passed:s,total:t,status:a,size:r="md"}){const{t:i}=N(),o=q[r],c=G[a],n=t>0?Math.round(s/t*100):0,d=(o.dimension-o.strokeWidth)/2,u=2*Math.PI*d,f=u-n/100*u,x=o.dimension/2;return e.jsxs("div",{className:"relative inline-flex items-center justify-center",children:[e.jsxs("svg",{width:o.dimension,height:o.dimension,className:"transform -rotate-90",style:{filter:`drop-shadow(0 0 8px ${c.glow})`},children:[e.jsx("circle",{cx:x,cy:x,r:d,fill:"none",stroke:"currentColor",strokeWidth:o.strokeWidth,className:"text-muted/30"}),e.jsx("circle",{cx:x,cy:x,r:d,fill:"none",stroke:c.stroke,strokeWidth:o.strokeWidth,strokeLinecap:"round",strokeDasharray:u,strokeDashoffset:f,className:"transition-all duration-1000 ease-out"}),n>0&&e.jsx("circle",{cx:x+d*Math.cos(n/100*2*Math.PI-Math.PI/2),cy:x+d*Math.sin(n/100*2*Math.PI-Math.PI/2),r:o.strokeWidth/2,fill:c.stroke,className:"animate-pulse",style:{filter:`drop-shadow(0 0 4px ${c.glow})`}})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("span",{className:l("font-mono font-bold tracking-tight",o.fontSize),children:n}),e.jsx("span",{className:l("font-mono uppercase tracking-widest text-muted-foreground",o.labelSize),children:i("health.healthLabel")})]})]})}function b({label:s,value:t,color:a,bgColor:r}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full animate-pulse",r)}),e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:s}),e.jsx("span",{className:l("font-mono font-bold text-sm",a),children:t})]})}function L({total:s,passed:t,warnings:a,errors:r,info:i}){const{t:o}=N(),c=t/s*100,n=a/s*100,d=r/s*100,u=i/s*100;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"h-2 rounded-full overflow-hidden bg-muted/50 flex",children:[d>0&&e.jsx("div",{className:"h-full bg-red-500 transition-all duration-500",style:{width:`${d}%`}}),n>0&&e.jsx("div",{className:"h-full bg-yellow-500 transition-all duration-500",style:{width:`${n}%`}}),u>0&&e.jsx("div",{className:"h-full bg-blue-500 transition-all duration-500",style:{width:`${u}%`}}),c>0&&e.jsx("div",{className:"h-full bg-green-500 transition-all duration-500",style:{width:`${c}%`}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:o("health.checks")}),e.jsx("span",{className:"font-mono font-bold text-lg",children:s})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsx(b,{label:"OK",value:t,color:"text-green-500",bgColor:"bg-green-500"}),e.jsx(b,{label:"WARN",value:a,color:"text-yellow-500",bgColor:"bg-yellow-500"}),e.jsx(b,{label:"ERR",value:r,color:"text-red-500",bgColor:"bg-red-500"}),e.jsx(b,{label:"INFO",value:i,color:"text-blue-500",bgColor:"bg-blue-500"})]})]})]})}function Q(){return W({queryKey:["health"],queryFn:async()=>(await fetch("/api/health")).json(),refetchInterval:3e4})}function U(){const s=E();return O({mutationFn:async t=>{const a=await fetch(`/api/health/fix/${t}`,{method:"POST"}),r=await a.json();if(!a.ok)throw new Error(r.message);return r},onSuccess:t=>{s.invalidateQueries({queryKey:["health"]}),g.success(t.message)},onError:t=>{g.error(t.message)}})}const Z={ok:{dot:"bg-green-500",label:"OK",labelColor:"text-green-500"},warning:{dot:"bg-yellow-500",label:"WARN",labelColor:"text-yellow-500"},error:{dot:"bg-red-500",label:"ERR",labelColor:"text-red-500"},info:{dot:"bg-blue-500",label:"INFO",labelColor:"text-blue-500"}};function Y({check:s}){const{t}=N(),a=U(),r=Z[s.status],[i,o]=j.useState(!1),c=s.details||s.fix,n=d=>{navigator.clipboard.writeText(d),g.success(t("health.copied"))};return c?e.jsx(k,{open:i,onOpenChange:o,children:e.jsxs("div",{className:l("group rounded-lg border transition-all duration-150",i?"border-border bg-muted/30":"border-transparent hover:border-border/50 hover:bg-muted/50"),children:[e.jsx(C,{asChild:!0,children:e.jsxs("button",{className:"w-full flex items-center gap-3 px-3 py-2 text-left",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),e.jsx(P,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",i&&"rotate-90")})]})}),e.jsx(S,{children:e.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-2 ml-7",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s.message}),s.details&&e.jsx("pre",{className:"text-xs font-mono text-muted-foreground bg-background/50 rounded p-2 overflow-x-auto border border-border/50",children:s.details}),s.fix&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 bg-background/50 rounded px-2 py-1.5 border border-border/50",children:[e.jsx(I,{className:"w-3 h-3 text-muted-foreground shrink-0"}),e.jsx("code",{className:"text-xs font-mono flex-1 truncate",children:s.fix}),e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>s.fix&&n(s.fix),className:"h-5 w-5 p-0",children:e.jsx(M,{className:"w-3 h-3"})})]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",onClick:()=>a.mutate(s.id),disabled:a.isPending,className:"h-7 px-3 text-xs",children:[e.jsx(y,{className:"w-3 h-3 mr-1"}),t("health.applyFix")]})]})]})})]})}):e.jsxs("div",{className:l("group flex items-center gap-3 px-3 py-2 rounded-lg","hover:bg-muted/50 transition-colors duration-150","border border-transparent hover:border-border/50"),children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",variant:"ghost",onClick:()=>a.mutate(s.id),disabled:a.isPending,className:"h-6 px-2 text-xs opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(y,{className:"w-3 h-3 mr-1"}),t("health.fix")]})]})}const J={Monitor:z,Settings:A,Users:H,Shield:$,Zap:T};function V({group:s,defaultOpen:t=!0}){const[a,r]=j.useState(t),i=J[s.icon]||z,o=s.checks.filter(m=>m.status==="ok").length,c=s.checks.length,n=s.checks.some(m=>m.status==="error"),d=s.checks.some(m=>m.status==="warning"),u=Math.round(o/c*100),f=n?"text-red-500":d?"text-yellow-500":"text-green-500",x=n?"bg-red-500":d?"bg-yellow-500":"bg-green-500";return e.jsx(k,{open:a,onOpenChange:r,children:e.jsxs("div",{className:l("rounded-lg border transition-all duration-200",n?"border-red-500/30":d?"border-yellow-500/30":"border-border"),children:[e.jsx(C,{asChild:!0,children:e.jsxs("button",{className:l("w-full flex items-center gap-3 p-3 text-left rounded-lg","hover:bg-muted/50 transition-colors duration-150",a&&"rounded-b-none border-b border-border/50"),children:[e.jsx("div",{className:l("p-1.5 rounded-md",n?"bg-red-500/10 text-red-500":d?"bg-yellow-500/10 text-yellow-500":"bg-muted text-muted-foreground"),children:e.jsx(i,{className:"w-4 h-4"})}),e.jsx("span",{className:"flex-1 text-sm font-semibold",children:s.name}),!a&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("div",{className:"w-16 h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:l("h-full transition-all duration-500",x),style:{width:`${u}%`}})})}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",f),children:[o,"/",c]}),e.jsx(F,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",a&&"rotate-180")})]})}),e.jsx(S,{children:e.jsx("div",{className:"p-2 space-y-0.5",children:s.checks.map(m=>e.jsx(Y,{check:m},m.id))})})]})})}function X(s){return s.errors>0?"error":s.warnings>0?"warning":"ok"}function _(s,t){const a=Math.floor((Date.now()-s)/1e3);if(a<5)return t("health.justNow");if(a<60)return t("health.secondsAgo",{count:a});const r=Math.floor(a/60);if(r<60)return t("health.minutesAgo",{count:r});const i=Math.floor(r/60);return t("health.hoursAgo",{count:i})}function ee(s){return[...s].sort((t,a)=>{const r=t.checks.filter(n=>n.status==="error").length,i=a.checks.filter(n=>n.status==="error").length,o=t.checks.filter(n=>n.status==="warning").length,c=a.checks.filter(n=>n.status==="warning").length;return r!==i?i-r:c-o})}function se(){return e.jsxs("div",{className:"font-mono text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500",children:"$"}),e.jsx("span",{children:"ccs doctor"})]})}function te(){return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsx("div",{className:"rounded-xl border bg-gradient-to-br from-background to-muted/20 p-6",children:e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsx(h,{className:"w-[120px] h-[120px] rounded-full"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(h,{className:"h-5 w-48"}),e.jsx(h,{className:"h-8 w-64"}),e.jsx(h,{className:"h-4 w-32"})]})]})}),e.jsx(h,{className:"h-16 w-full rounded-lg"}),e.jsx("div",{className:"space-y-3",children:[1,2,3,4].map(s=>e.jsx(h,{className:"h-20 rounded-lg"},s))})]})}function xe(){const{t:s}=N(),{data:t,isLoading:a,refetch:r,dataUpdatedAt:i}=Q(),o=i,[c,n]=j.useState(0);j.useEffect(()=>{const m=setInterval(()=>n(v=>v+1),1e3);return()=>clearInterval(m)},[]);const d=()=>{navigator.clipboard.writeText("ccs doctor"),g.success(s("health.copied"))},u=()=>{r(),g.info(s("health.refreshing"))};if(a&&!t)return e.jsx(te,{});const f=t?X(t.summary):"ok",x=t?.groups?ee(t.groups):[];return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsxs("div",{className:l("relative overflow-hidden rounded-xl border p-6","bg-gradient-to-br from-background via-background to-muted/30"),children:[e.jsx("div",{className:"absolute inset-0 opacity-[0.02] pointer-events-none",style:{backgroundImage:"repeating-linear-gradient(0deg, transparent, transparent 2px, currentColor 2px, currentColor 3px)"}}),e.jsx("div",{className:"absolute inset-0 opacity-[0.03] pointer-events-none",children:e.jsx("div",{className:"absolute inset-0",style:{backgroundImage:"radial-gradient(circle at 1px 1px, currentColor 1px, transparent 0)",backgroundSize:"24px 24px"}})}),e.jsxs("div",{className:"relative flex flex-col md:flex-row items-start md:items-center gap-6",children:[t&&e.jsx("div",{className:"shrink-0",children:e.jsx(K,{passed:t.summary.passed,total:t.summary.total-t.summary.info,status:f,size:"md"})}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(se,{}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("h1",{className:"text-2xl font-bold font-mono tracking-tight",children:s("health.systemHealth")}),t?.version&&e.jsx(R,{variant:"outline",className:"font-mono text-xs bg-muted/50",children:s("health.build",{version:t.version})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(B,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:s("health.lastScan")}),e.jsx("span",{className:"font-mono",children:o?_(o,s):"--"}),e.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsx("span",{className:"text-muted-foreground",children:s("health.autoRefresh")}),e.jsx("span",{className:"font-mono text-green-500",children:"30s"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs(p,{variant:"outline",size:"sm",onClick:d,className:"gap-2 font-mono text-xs",children:[e.jsx(I,{className:"w-3 h-3"}),"ccs doctor",e.jsx(M,{className:"w-3 h-3 opacity-50"})]}),e.jsxs(p,{variant:"outline",size:"sm",onClick:u,disabled:a,className:"gap-2",children:[e.jsx(D,{className:l("w-4 h-4",a&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:s("health.refresh")}),e.jsx("kbd",{className:"hidden md:inline-flex h-5 items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground",children:"R"})]})]})]})]}),t&&e.jsx("div",{className:"rounded-lg border bg-card p-4",children:e.jsx(L,{total:t.summary.total,passed:t.summary.passed,warnings:t.summary.warnings,errors:t.summary.errors,info:t.summary.info})}),x.length>0&&e.jsx("div",{className:"space-y-3",children:x.map((m,v)=>e.jsx(V,{group:m,defaultOpen:v<2||m.checks.some(w=>w.status==="error"||w.status==="warning")},m.id))}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{children:[s("health.version")," ",e.jsx("span",{className:"font-mono",children:t?.version??"--"})]}),e.jsxs("span",{children:[s("health.platform")," ",e.jsx("span",{className:"font-mono",children:typeof navigator<"u"?navigator.platform:"linux"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),e.jsx("span",{children:s("health.liveMonitoring")})]})]})]})}export{xe as HealthPage};
|
|
1
|
+
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{a as N,c as l,d as p,M as k,N as C,O as S,B as R,S as h}from"./index-g2g1k0QS.js";import{u as W,a as E,b as O}from"./tanstack-CrmUhA7Z.js";import{t as g}from"./notifications-B2HqRBj7.js";import{r as j}from"./react-vendor-CNOkPC89.js";import{b5 as y,C as P,$ as I,o as M,Z as T,i as $,U as H,e as A,b6 as z,s as F,Y as B,R as D}from"./icons-KVCk4_U8.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const q={sm:{dimension:80,strokeWidth:6,fontSize:"text-lg",labelSize:"text-[10px]"},md:{dimension:120,strokeWidth:8,fontSize:"text-3xl",labelSize:"text-xs"},lg:{dimension:160,strokeWidth:10,fontSize:"text-4xl",labelSize:"text-sm"}},G={ok:{stroke:"#22C55E",glow:"rgba(34, 197, 94, 0.4)"},warning:{stroke:"#EAB308",glow:"rgba(234, 179, 8, 0.4)"},error:{stroke:"#EF4444",glow:"rgba(239, 68, 68, 0.4)"}};function K({passed:s,total:t,status:a,size:r="md"}){const{t:i}=N(),o=q[r],c=G[a],n=t>0?Math.round(s/t*100):0,d=(o.dimension-o.strokeWidth)/2,u=2*Math.PI*d,f=u-n/100*u,x=o.dimension/2;return e.jsxs("div",{className:"relative inline-flex items-center justify-center",children:[e.jsxs("svg",{width:o.dimension,height:o.dimension,className:"transform -rotate-90",style:{filter:`drop-shadow(0 0 8px ${c.glow})`},children:[e.jsx("circle",{cx:x,cy:x,r:d,fill:"none",stroke:"currentColor",strokeWidth:o.strokeWidth,className:"text-muted/30"}),e.jsx("circle",{cx:x,cy:x,r:d,fill:"none",stroke:c.stroke,strokeWidth:o.strokeWidth,strokeLinecap:"round",strokeDasharray:u,strokeDashoffset:f,className:"transition-all duration-1000 ease-out"}),n>0&&e.jsx("circle",{cx:x+d*Math.cos(n/100*2*Math.PI-Math.PI/2),cy:x+d*Math.sin(n/100*2*Math.PI-Math.PI/2),r:o.strokeWidth/2,fill:c.stroke,className:"animate-pulse",style:{filter:`drop-shadow(0 0 4px ${c.glow})`}})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("span",{className:l("font-mono font-bold tracking-tight",o.fontSize),children:n}),e.jsx("span",{className:l("font-mono uppercase tracking-widest text-muted-foreground",o.labelSize),children:i("health.healthLabel")})]})]})}function b({label:s,value:t,color:a,bgColor:r}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full animate-pulse",r)}),e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:s}),e.jsx("span",{className:l("font-mono font-bold text-sm",a),children:t})]})}function L({total:s,passed:t,warnings:a,errors:r,info:i}){const{t:o}=N(),c=t/s*100,n=a/s*100,d=r/s*100,u=i/s*100;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"h-2 rounded-full overflow-hidden bg-muted/50 flex",children:[d>0&&e.jsx("div",{className:"h-full bg-red-500 transition-all duration-500",style:{width:`${d}%`}}),n>0&&e.jsx("div",{className:"h-full bg-yellow-500 transition-all duration-500",style:{width:`${n}%`}}),u>0&&e.jsx("div",{className:"h-full bg-blue-500 transition-all duration-500",style:{width:`${u}%`}}),c>0&&e.jsx("div",{className:"h-full bg-green-500 transition-all duration-500",style:{width:`${c}%`}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:o("health.checks")}),e.jsx("span",{className:"font-mono font-bold text-lg",children:s})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsx(b,{label:"OK",value:t,color:"text-green-500",bgColor:"bg-green-500"}),e.jsx(b,{label:"WARN",value:a,color:"text-yellow-500",bgColor:"bg-yellow-500"}),e.jsx(b,{label:"ERR",value:r,color:"text-red-500",bgColor:"bg-red-500"}),e.jsx(b,{label:"INFO",value:i,color:"text-blue-500",bgColor:"bg-blue-500"})]})]})]})}function Q(){return W({queryKey:["health"],queryFn:async()=>(await fetch("/api/health")).json(),refetchInterval:3e4})}function U(){const s=E();return O({mutationFn:async t=>{const a=await fetch(`/api/health/fix/${t}`,{method:"POST"}),r=await a.json();if(!a.ok)throw new Error(r.message);return r},onSuccess:t=>{s.invalidateQueries({queryKey:["health"]}),g.success(t.message)},onError:t=>{g.error(t.message)}})}const Z={ok:{dot:"bg-green-500",label:"OK",labelColor:"text-green-500"},warning:{dot:"bg-yellow-500",label:"WARN",labelColor:"text-yellow-500"},error:{dot:"bg-red-500",label:"ERR",labelColor:"text-red-500"},info:{dot:"bg-blue-500",label:"INFO",labelColor:"text-blue-500"}};function Y({check:s}){const{t}=N(),a=U(),r=Z[s.status],[i,o]=j.useState(!1),c=s.details||s.fix,n=d=>{navigator.clipboard.writeText(d),g.success(t("health.copied"))};return c?e.jsx(k,{open:i,onOpenChange:o,children:e.jsxs("div",{className:l("group rounded-lg border transition-all duration-150",i?"border-border bg-muted/30":"border-transparent hover:border-border/50 hover:bg-muted/50"),children:[e.jsx(C,{asChild:!0,children:e.jsxs("button",{className:"w-full flex items-center gap-3 px-3 py-2 text-left",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),e.jsx(P,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",i&&"rotate-90")})]})}),e.jsx(S,{children:e.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-2 ml-7",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s.message}),s.details&&e.jsx("pre",{className:"text-xs font-mono text-muted-foreground bg-background/50 rounded p-2 overflow-x-auto border border-border/50",children:s.details}),s.fix&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 bg-background/50 rounded px-2 py-1.5 border border-border/50",children:[e.jsx(I,{className:"w-3 h-3 text-muted-foreground shrink-0"}),e.jsx("code",{className:"text-xs font-mono flex-1 truncate",children:s.fix}),e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>s.fix&&n(s.fix),className:"h-5 w-5 p-0",children:e.jsx(M,{className:"w-3 h-3"})})]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",onClick:()=>a.mutate(s.id),disabled:a.isPending,className:"h-7 px-3 text-xs",children:[e.jsx(y,{className:"w-3 h-3 mr-1"}),t("health.applyFix")]})]})]})})]})}):e.jsxs("div",{className:l("group flex items-center gap-3 px-3 py-2 rounded-lg","hover:bg-muted/50 transition-colors duration-150","border border-transparent hover:border-border/50"),children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",variant:"ghost",onClick:()=>a.mutate(s.id),disabled:a.isPending,className:"h-6 px-2 text-xs opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(y,{className:"w-3 h-3 mr-1"}),t("health.fix")]})]})}const J={Monitor:z,Settings:A,Users:H,Shield:$,Zap:T};function V({group:s,defaultOpen:t=!0}){const[a,r]=j.useState(t),i=J[s.icon]||z,o=s.checks.filter(m=>m.status==="ok").length,c=s.checks.length,n=s.checks.some(m=>m.status==="error"),d=s.checks.some(m=>m.status==="warning"),u=Math.round(o/c*100),f=n?"text-red-500":d?"text-yellow-500":"text-green-500",x=n?"bg-red-500":d?"bg-yellow-500":"bg-green-500";return e.jsx(k,{open:a,onOpenChange:r,children:e.jsxs("div",{className:l("rounded-lg border transition-all duration-200",n?"border-red-500/30":d?"border-yellow-500/30":"border-border"),children:[e.jsx(C,{asChild:!0,children:e.jsxs("button",{className:l("w-full flex items-center gap-3 p-3 text-left rounded-lg","hover:bg-muted/50 transition-colors duration-150",a&&"rounded-b-none border-b border-border/50"),children:[e.jsx("div",{className:l("p-1.5 rounded-md",n?"bg-red-500/10 text-red-500":d?"bg-yellow-500/10 text-yellow-500":"bg-muted text-muted-foreground"),children:e.jsx(i,{className:"w-4 h-4"})}),e.jsx("span",{className:"flex-1 text-sm font-semibold",children:s.name}),!a&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("div",{className:"w-16 h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:l("h-full transition-all duration-500",x),style:{width:`${u}%`}})})}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",f),children:[o,"/",c]}),e.jsx(F,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",a&&"rotate-180")})]})}),e.jsx(S,{children:e.jsx("div",{className:"p-2 space-y-0.5",children:s.checks.map(m=>e.jsx(Y,{check:m},m.id))})})]})})}function X(s){return s.errors>0?"error":s.warnings>0?"warning":"ok"}function _(s,t){const a=Math.floor((Date.now()-s)/1e3);if(a<5)return t("health.justNow");if(a<60)return t("health.secondsAgo",{count:a});const r=Math.floor(a/60);if(r<60)return t("health.minutesAgo",{count:r});const i=Math.floor(r/60);return t("health.hoursAgo",{count:i})}function ee(s){return[...s].sort((t,a)=>{const r=t.checks.filter(n=>n.status==="error").length,i=a.checks.filter(n=>n.status==="error").length,o=t.checks.filter(n=>n.status==="warning").length,c=a.checks.filter(n=>n.status==="warning").length;return r!==i?i-r:c-o})}function se(){return e.jsxs("div",{className:"font-mono text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500",children:"$"}),e.jsx("span",{children:"ccs doctor"})]})}function te(){return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsx("div",{className:"rounded-xl border bg-gradient-to-br from-background to-muted/20 p-6",children:e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsx(h,{className:"w-[120px] h-[120px] rounded-full"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(h,{className:"h-5 w-48"}),e.jsx(h,{className:"h-8 w-64"}),e.jsx(h,{className:"h-4 w-32"})]})]})}),e.jsx(h,{className:"h-16 w-full rounded-lg"}),e.jsx("div",{className:"space-y-3",children:[1,2,3,4].map(s=>e.jsx(h,{className:"h-20 rounded-lg"},s))})]})}function xe(){const{t:s}=N(),{data:t,isLoading:a,refetch:r,dataUpdatedAt:i}=Q(),o=i,[c,n]=j.useState(0);j.useEffect(()=>{const m=setInterval(()=>n(v=>v+1),1e3);return()=>clearInterval(m)},[]);const d=()=>{navigator.clipboard.writeText("ccs doctor"),g.success(s("health.copied"))},u=()=>{r(),g.info(s("health.refreshing"))};if(a&&!t)return e.jsx(te,{});const f=t?X(t.summary):"ok",x=t?.groups?ee(t.groups):[];return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsxs("div",{className:l("relative overflow-hidden rounded-xl border p-6","bg-gradient-to-br from-background via-background to-muted/30"),children:[e.jsx("div",{className:"absolute inset-0 opacity-[0.02] pointer-events-none",style:{backgroundImage:"repeating-linear-gradient(0deg, transparent, transparent 2px, currentColor 2px, currentColor 3px)"}}),e.jsx("div",{className:"absolute inset-0 opacity-[0.03] pointer-events-none",children:e.jsx("div",{className:"absolute inset-0",style:{backgroundImage:"radial-gradient(circle at 1px 1px, currentColor 1px, transparent 0)",backgroundSize:"24px 24px"}})}),e.jsxs("div",{className:"relative flex flex-col md:flex-row items-start md:items-center gap-6",children:[t&&e.jsx("div",{className:"shrink-0",children:e.jsx(K,{passed:t.summary.passed,total:t.summary.total-t.summary.info,status:f,size:"md"})}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(se,{}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("h1",{className:"text-2xl font-bold font-mono tracking-tight",children:s("health.systemHealth")}),t?.version&&e.jsx(R,{variant:"outline",className:"font-mono text-xs bg-muted/50",children:s("health.build",{version:t.version})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(B,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:s("health.lastScan")}),e.jsx("span",{className:"font-mono",children:o?_(o,s):"--"}),e.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsx("span",{className:"text-muted-foreground",children:s("health.autoRefresh")}),e.jsx("span",{className:"font-mono text-green-500",children:"30s"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs(p,{variant:"outline",size:"sm",onClick:d,className:"gap-2 font-mono text-xs",children:[e.jsx(I,{className:"w-3 h-3"}),"ccs doctor",e.jsx(M,{className:"w-3 h-3 opacity-50"})]}),e.jsxs(p,{variant:"outline",size:"sm",onClick:u,disabled:a,className:"gap-2",children:[e.jsx(D,{className:l("w-4 h-4",a&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:s("health.refresh")}),e.jsx("kbd",{className:"hidden md:inline-flex h-5 items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground",children:"R"})]})]})]})]}),t&&e.jsx("div",{className:"rounded-lg border bg-card p-4",children:e.jsx(L,{total:t.summary.total,passed:t.summary.passed,warnings:t.summary.warnings,errors:t.summary.errors,info:t.summary.info})}),x.length>0&&e.jsx("div",{className:"space-y-3",children:x.map((m,v)=>e.jsx(V,{group:m,defaultOpen:v<2||m.checks.some(w=>w.status==="error"||w.status==="warning")},m.id))}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{children:[s("health.version")," ",e.jsx("span",{className:"font-mono",children:t?.version??"--"})]}),e.jsxs("span",{children:[s("health.platform")," ",e.jsx("span",{className:"font-mono",children:typeof navigator<"u"?navigator.platform:"linux"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),e.jsx("span",{children:s("health.liveMonitoring")})]})]})]})}export{xe as HealthPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as y}from"./react-vendor-CNOkPC89.js";import{bt as se,bu as re,a as q,c as u,aF as ne,L as le,I as de,bv as ie,be as oe,bg as ce,n as be,d as R}from"./index-DNmWbKbN.js";import{M as ue}from"./masked-input-b4-lEKNq.js";import{p as me,R as P,w as ge,x as xe,u as B,n as fe,t as he,s as pe}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function ye(){const{state:s}=se(),t=re(),x=y.useCallback(async()=>{try{t.setWebSearchLoading(!0),t.setWebSearchError(null);const d=await fetch("/api/websearch");if(!d.ok)throw new Error("Failed to load WebSearch config");const c=await d.json();t.setWebSearchConfig(c)}catch(d){t.setWebSearchError(d.message)}finally{t.setWebSearchLoading(!1)}},[t]),i=y.useCallback(async()=>{try{t.setWebSearchStatusLoading(!0);const d=await fetch("/api/websearch/status");if(!d.ok)throw new Error("Failed to load status");const c=await d.json();t.setWebSearchStatus(c)}catch{}finally{t.setWebSearchStatusLoading(!1)}},[t]),k=y.useCallback(async d=>{const c=s.webSearchConfig;if(!c)return!1;const m={...c,...d,providers:{...c.providers,...d.providers},apiKeys:c.apiKeys};t.setWebSearchConfig(m);try{t.setWebSearchSaving(!0),t.setWebSearchError(null);const f={enabled:m.enabled,providers:m.providers};d.apiKeys&&(f.apiKeys=d.apiKeys);const h=await fetch("/api/websearch",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)});if(!h.ok){const g=await h.json();throw new Error(g.error||"Failed to save")}const v=await h.json();return t.setWebSearchConfig(v.websearch),await i(),t.setWebSearchSuccess(!0),setTimeout(()=>t.setWebSearchSuccess(!1),1500),!0}catch(f){return t.setWebSearchConfig(c),t.setWebSearchError(f.message),!1}finally{t.setWebSearchSaving(!1)}},[s.webSearchConfig,t,i]);return{config:s.webSearchConfig,status:s.webSearchStatus,loading:s.webSearchLoading,statusLoading:s.webSearchStatusLoading,saving:s.webSearchSaving,error:s.webSearchError,success:s.webSearchSuccess,fetchConfig:x,fetchStatus:i,saveConfig:k}}const ke={green:{accent:"from-emerald-500 via-lime-400 to-transparent",badge:"border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-200",glow:"bg-emerald-500/18 dark:bg-emerald-500/22",surface:"border-emerald-500/30 bg-gradient-to-br from-emerald-500/10 via-background to-background dark:from-emerald-500/14",switchFrame:"border-emerald-500/20 bg-emerald-500/10"},blue:{accent:"from-sky-500 via-blue-500 to-transparent",badge:"border-sky-500/25 bg-sky-500/10 text-sky-800 dark:text-sky-200",glow:"bg-sky-500/18 dark:bg-sky-500/22",surface:"border-sky-500/30 bg-gradient-to-br from-sky-500/10 via-background to-background dark:from-sky-500/14",switchFrame:"border-sky-500/20 bg-sky-500/10"},amber:{accent:"from-amber-500 via-orange-500 to-transparent",badge:"border-amber-500/25 bg-amber-500/10 text-amber-800 dark:text-amber-200",glow:"bg-amber-500/18 dark:bg-amber-500/22",surface:"border-amber-500/30 bg-gradient-to-br from-amber-500/10 via-background to-background dark:from-amber-500/14",switchFrame:"border-amber-500/20 bg-amber-500/10"},cyan:{accent:"from-cyan-500 via-teal-400 to-transparent",badge:"border-cyan-500/25 bg-cyan-500/10 text-cyan-800 dark:text-cyan-200",glow:"bg-cyan-500/18 dark:bg-cyan-500/22",surface:"border-cyan-500/30 bg-gradient-to-br from-cyan-500/10 via-background to-background dark:from-cyan-500/14",switchFrame:"border-cyan-500/20 bg-cyan-500/10"},slate:{accent:"from-slate-500 via-slate-400 to-transparent",badge:"border-slate-500/20 bg-slate-500/10 text-slate-700 dark:text-slate-300",glow:"bg-slate-500/18 dark:bg-slate-500/22",surface:"border-slate-400/30 bg-gradient-to-br from-slate-500/8 via-background to-background dark:from-slate-500/12",switchFrame:"border-slate-400/20 bg-slate-500/10"}};function ve(s){switch(s){case"ready":return{chip:"border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-200",dot:"bg-emerald-500"};case"setup":return{chip:"border-amber-500/25 bg-amber-500/10 text-amber-800 dark:text-amber-200",dot:"bg-amber-500"};case"idle":return{chip:"border-border/80 bg-muted/60 text-muted-foreground",dot:"bg-muted-foreground/70"}}}function M({title:s,description:t,detail:x,badge:i,badgeTone:k,statusLabel:d,statusTone:c,enabled:m,saving:f,onToggle:h,fields:v=[],docsUrl:g,installCommand:N,footerNote:S,children:C}){const{t:E}=q(),j=ke[k],_=ve(c);return e.jsxs("div",{className:u("group relative overflow-hidden rounded-2xl border px-4 py-4 shadow-sm transition-all duration-200",m?j.surface:"border-border/70 bg-gradient-to-br from-background via-background to-muted/25",m&&"shadow-[0_18px_40px_-28px_rgba(15,23,42,0.55)]"),children:[e.jsx("div",{className:u("absolute inset-x-0 top-0 h-px bg-gradient-to-r",j.accent)}),e.jsx("div",{className:u("pointer-events-none absolute -right-6 -top-8 h-28 w-28 rounded-full blur-3xl",j.glow)}),e.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-[0.045]",style:{backgroundImage:"radial-gradient(circle at 1px 1px, currentColor 1px, transparent 0)",backgroundSize:"22px 22px"}}),e.jsxs("div",{className:"relative flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsx("p",{className:"text-sm font-semibold tracking-tight",children:s}),e.jsx("span",{className:u("rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.18em]",j.badge),children:i}),e.jsxs("span",{className:u("inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-[10px] font-medium",_.chip),children:[e.jsx("span",{className:u("h-1.5 w-1.5 rounded-full",_.dot)}),d]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm leading-6 text-foreground/90",children:t}),x&&e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:x})]})]}),e.jsx("div",{className:u("flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border bg-background/75 backdrop-blur-sm",m?j.switchFrame:"border-border/70"),children:e.jsx(ne,{checked:m,onCheckedChange:h,disabled:f})})]}),m&&v.length>0&&e.jsx("div",{className:"relative mt-4 rounded-xl border border-border/65 bg-background/70 p-3 shadow-[inset_0_1px_0_rgba(255,255,255,0.35)] backdrop-blur-sm",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:v.map(b=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(le,{htmlFor:b.id,className:"text-[11px] font-medium text-muted-foreground",children:b.label}),b.saved&&e.jsx("span",{className:"text-[11px] font-medium text-emerald-600 dark:text-emerald-400",children:E("settings.saved")})]}),e.jsx(de,{id:b.id,value:b.value,type:b.type??"text",placeholder:b.placeholder,onBlur:b.onBlur,onChange:T=>b.onChange(T.target.value),onKeyDown:b.onKeyDown,className:"h-8 border-border/70 bg-background/80 text-sm",disabled:f}),b.helpText&&e.jsx("p",{className:"text-[11px] text-muted-foreground",children:b.helpText})]},b.id))})}),m&&C&&e.jsx("div",{className:"relative mt-4 rounded-xl border border-border/65 bg-background/70 p-3 shadow-[inset_0_1px_0_rgba(255,255,255,0.35)] backdrop-blur-sm",children:C}),(S||N||g)&&e.jsxs("div",{className:"relative mt-4 space-y-2 rounded-xl border border-border/65 bg-muted/30 p-3",children:[S&&e.jsx("p",{className:"text-xs text-muted-foreground",children:S}),N&&e.jsx("code",{className:"block rounded-lg border border-border/60 bg-background/85 px-2.5 py-2 text-[11px] text-muted-foreground",children:N}),g&&e.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs font-medium text-primary hover:underline",children:[e.jsx(me,{className:"h-3 w-3"}),E("settingsWebsearch.viewDocs")]})]})]})}const Y=[{id:"exa",title:"Exa",defaultEnabled:!1},{id:"tavily",title:"Tavily",defaultEnabled:!1},{id:"brave",title:"Brave",defaultEnabled:!1},{id:"searxng",title:"SearXNG",defaultEnabled:!1},{id:"duckduckgo",title:"DuckDuckGo",defaultEnabled:!0},{id:"legacy",title:"Legacy CLI",defaultEnabled:!1}],U=[{id:"exa",title:"Exa",description:"Highest-priority API backend when enabled. Best for strong relevance and extracted text.",badge:"EXA_API_KEY",badgeTone:"amber",defaultEnabled:!1,fallbackDetail:"Set EXA_API_KEY",footerNote:"Runs before every other provider in the chain when enabled and ready.",fields:[{key:"max_results",label:"Max results",type:"number",placeholder:"5",helpText:"Clamp between 1 and 10 results.",defaultValue:5,min:1,max:10}]},{id:"tavily",title:"Tavily",description:"Agent-oriented API backend with concise web result content.",badge:"TAVILY_API_KEY",badgeTone:"cyan",defaultEnabled:!1,fallbackDetail:"Set TAVILY_API_KEY",footerNote:"Runs after Exa and before Brave when enabled and ready.",fields:[{key:"max_results",label:"Max results",type:"number",placeholder:"5",helpText:"Clamp between 1 and 10 results.",defaultValue:5,min:1,max:10}]},{id:"brave",title:"Brave Search",description:"API-backed search with clean metadata and broad web coverage.",badge:"BRAVE_API_KEY",badgeTone:"blue",defaultEnabled:!1,fallbackDetail:"Set BRAVE_API_KEY",footerNote:"Runs after Exa and Tavily, before DuckDuckGo.",fields:[{key:"max_results",label:"Max results",type:"number",placeholder:"5",helpText:"Clamp between 1 and 10 results.",defaultValue:5,min:1,max:10}]},{id:"searxng",title:"SearXNG",description:"Configurable JSON backend for self-hosted or public SearXNG instances.",badge:"SELF-HOSTED",badgeTone:"cyan",defaultEnabled:!1,fallbackDetail:"Set a valid base URL",footerNote:"Runs after Brave and before DuckDuckGo when enabled and ready.",fields:[{key:"url",label:"Base URL",type:"text",placeholder:"https://search.example.com",helpText:"Paste the instance base URL only. CCS appends /search?format=json for you and rejects embedded credentials.",defaultValue:""},{key:"max_results",label:"Max results",type:"number",placeholder:"5",helpText:"Clamp between 1 and 10 results.",defaultValue:5,min:1,max:10}]},{id:"duckduckgo",title:"DuckDuckGo",description:"Zero-setup floor. Keep this on unless you want no built-in fallback at all.",badge:"DEFAULT",badgeTone:"green",defaultEnabled:!0,fallbackDetail:"Built-in",footerNote:"Last real backend in the chain. No API key needed.",fields:[{key:"max_results",label:"Max results",type:"number",placeholder:"5",helpText:"Clamp between 1 and 10 results.",defaultValue:5,min:1,max:10}]}],V=[{id:"gemini",title:"Gemini CLI",description:"Optional legacy LLM fallback. Used only if every enabled real backend fails.",badge:"LEGACY",badgeTone:"slate",defaultEnabled:!1,fallbackDetail:"Optional fallback",footerNote:"Legacy path. Useful for compatibility, not the preferred search backend.",fields:[{key:"model",label:"Model",type:"text",placeholder:"gemini-2.5-flash",helpText:"CLI model passed to Gemini when this fallback runs.",defaultValue:"gemini-2.5-flash"},{key:"timeout",label:"Timeout (seconds)",type:"number",placeholder:"55",helpText:"Clamp between 5 and 300 seconds.",defaultValue:55,min:5,max:300}]},{id:"opencode",title:"OpenCode",description:"Optional legacy LLM fallback via OpenCode.",badge:"LEGACY",badgeTone:"slate",defaultEnabled:!1,fallbackDetail:"Optional fallback",footerNote:"Legacy path. Runs after Gemini in the fallback portion of the chain.",fields:[{key:"model",label:"Model",type:"text",placeholder:"opencode/grok-code",helpText:"OpenCode model passed to the CLI runner.",defaultValue:"opencode/grok-code"},{key:"timeout",label:"Timeout (seconds)",type:"number",placeholder:"90",helpText:"Clamp between 5 and 300 seconds.",defaultValue:90,min:5,max:300}]},{id:"grok",title:"Grok CLI",description:"Optional legacy xAI fallback. Requires the Grok CLI and GROK_API_KEY.",badge:"LEGACY",badgeTone:"slate",defaultEnabled:!1,fallbackDetail:"Optional fallback",footerNote:"Last step in the full fallback chain.",fields:[{key:"timeout",label:"Timeout (seconds)",type:"number",placeholder:"55",helpText:"Clamp between 5 and 300 seconds.",defaultValue:55,min:5,max:300}]}];function D(s,t){return t&&s?.available?"ready":t?"setup":"idle"}function I(s,t){return t&&s?.available?"Ready":t?"Needs setup":"Disabled"}function je(s){switch(s){case"ready":return"border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-200";case"setup":return"border-amber-500/25 bg-amber-500/10 text-amber-800 dark:text-amber-200";case"idle":return"border-border/80 bg-background/85 text-muted-foreground"}}function we(s){switch(s){case"ready":return"bg-emerald-500";case"setup":return"bg-amber-500";case"idle":return"bg-border"}}function z(s){switch(s){case"ready":return"bg-emerald-500 shadow-[0_0_0_6px_rgba(16,185,129,0.12)]";case"setup":return"bg-amber-500 shadow-[0_0_0_6px_rgba(245,158,11,0.12)]";case"idle":return"bg-border"}}function X(s){switch(s){case"ready":return"bg-gradient-to-b from-emerald-500/55 to-border";case"setup":return"bg-gradient-to-b from-amber-500/55 to-border";case"idle":return"bg-border"}}function Ne(s,t){if(s.type==="number"){const i=Number.parseInt(t.trim(),10);if(!Number.isFinite(i))return s.defaultValue;const k=s.min??i,d=s.max??i;return Math.min(d,Math.max(k,i))}return t.trim()||String(s.defaultValue)}function H(s,t,x){const i=s?.[t]?.[x.key];return String(i??x.defaultValue)}function Se(s){return s==="exa"||s==="tavily"||s==="brave"}function Ce(s){if(!s?.configured)return"Not stored";if(!s.available&&s.source==="global_env")return"Stored in dashboard, but Global Env is disabled";switch(s.source){case"global_env":return"Stored in dashboard";case"process_env":return"Detected from shell env";case"both":return"Stored in dashboard + shell env";case"none":return"Not stored"}}function Ie(){const{t:s}=q(),{config:t,status:x,loading:i,statusLoading:k,saving:d,error:c,success:m,fetchConfig:f,fetchStatus:h,saveConfig:v}=ye(),{fetchRawConfig:g}=ie(),[N,S]=y.useState({}),[C,E]=y.useState({}),[j,_]=y.useState(null),[b,T]=y.useState(null),[W,J]=y.useState(!1);y.useEffect(()=>{f(),h(),g()},[f,h,g]);const L=y.useMemo(()=>new Map((x?.providers??[]).map(a=>[a.id,a])),[x?.providers]),w=V.filter(a=>t?.providers?.[a.id]?.enabled??a.defaultEnabled),Z=w.some(a=>L.get(a.id)?.available),F=w.length===0?"Off":w.length===1?`${w[0].title} enabled`:`${w.length} enabled`,G=async(a,l)=>{const r=t?.providers??{};await v({providers:{...r,[a]:{...r[a],enabled:!l}}})&&await g()},Q=(a,l,r)=>{S(n=>({...n,[`${a}.${l}`]:r}))},ee=async(a,l)=>{if(!t)return;const r=`${a}.${l.key}`,n=t.providers??{},p=n[a]??{},o=p[l.key]??l.defaultValue,A=Ne(l,N[r]??H(n,a,l));if(S(K=>({...K,[r]:String(A)})),String(o)===String(A))return;await v({providers:{...n,[a]:{...p,[l.key]:A}}})&&(await g(),_(r),setTimeout(()=>{_(K=>K===r?null:K)},1200))},ae=async a=>{const l=C[a]?.trim()??"";if(!l)return;await v({apiKeys:{[a]:l}})&&(await g(),E(n=>({...n,[a]:""})),T(a),setTimeout(()=>{T(n=>n===a?null:n)},1200))},te=async a=>{await v({apiKeys:{[a]:""}})&&(await g(),E(r=>({...r,[a]:""})),T(a),setTimeout(()=>{T(r=>r===a?null:r)},1200))},O=a=>(a.fields??[]).map(l=>{const r=`${a.id}.${l.key}`;return{id:r,label:l.label,value:N[r]??H(t?.providers??{},a.id,l),placeholder:l.placeholder,type:l.type,helpText:l.helpText,saved:j===r,onChange:n=>Q(a.id,l.key,n),onBlur:()=>{ee(a.id,l)},onKeyDown:n=>{n.key==="Enter"&&n.currentTarget.blur()}}});return i?e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(P,{className:"h-5 w-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${c||m?"translate-y-0 opacity-100":"pointer-events-none -translate-y-2 opacity-0"}`,children:[c&&e.jsxs(oe,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(ge,{className:"h-4 w-4"}),e.jsx(ce,{children:c})]}),m&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-green-200 bg-green-50 px-3 py-2 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(xe,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(be,{className:"flex-1",children:e.jsxs("div",{className:"space-y-6 p-5",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-2xl border bg-gradient-to-br from-background via-background to-muted/30 p-4 shadow-sm",children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-px bg-gradient-to-r from-primary/70 via-primary/20 to-transparent"}),e.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-[0.035]",style:{backgroundImage:"repeating-linear-gradient(0deg, transparent, transparent 2px, currentColor 2px, currentColor 3px)"}}),e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"inline-flex h-8 w-8 items-center justify-center rounded-xl border border-primary/20 bg-primary/8 text-primary",children:e.jsx(B,{className:"h-4 w-4"})}),e.jsx("p",{className:"text-sm font-semibold tracking-tight",children:"Execution chain"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:k?s("settingsWebsearch.checking"):x?.readiness.message})]}),e.jsx(R,{variant:"ghost",size:"sm",onClick:h,disabled:k,children:e.jsx(P,{className:`h-4 w-4 ${k?"animate-spin":""}`})})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:Y.map((a,l)=>{const r=a.id==="legacy"?w.length>0:t?.providers?.[a.id]?.enabled??a.defaultEnabled,n=a.id==="legacy"?Z?"ready":w.length>0?"setup":"idle":D(L.get(a.id),r),p=a.id==="legacy"?F:I(L.get(a.id),r);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:u("inline-flex items-center gap-2 rounded-full border px-3 py-1.5 text-[11px] font-medium",je(n)),children:[e.jsx("span",{className:u("h-1.5 w-1.5 rounded-full",we(n))}),e.jsxs("span",{children:[a.title," · ",p]})]}),l<Y.length-1&&e.jsx("span",{className:"h-px w-4 rounded-full bg-border/80"})]},a.id)})})]})]}),e.jsxs("div",{className:"relative overflow-hidden rounded-2xl border bg-gradient-to-br from-background via-background to-muted/25 p-4 shadow-sm",children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-px bg-gradient-to-r from-sky-500/70 via-emerald-500/25 to-transparent"}),e.jsxs("div",{className:"relative space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border border-sky-500/20 bg-sky-500/10 text-sky-700 dark:text-sky-300",children:e.jsx(B,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold tracking-tight",children:"Primary backends"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Real backends run top-down before any legacy CLI fallback."})]})]}),e.jsx("div",{className:"space-y-3",children:U.map((a,l)=>{const r=L.get(a.id),n=t?.providers?.[a.id]?.enabled??a.defaultEnabled,p=D(r,n),o=Se(a.id)?a.id:null;return e.jsxs("div",{className:"grid grid-cols-[20px_minmax(0,1fr)] items-start gap-3",children:[e.jsx("div",{className:"flex h-full justify-center",children:e.jsxs("div",{className:"flex h-full flex-col items-center",children:[e.jsx("span",{className:u("mt-5 h-3 w-3 rounded-full ring-4 ring-background",z(p))}),l<U.length-1&&e.jsx("span",{className:u("mt-1 w-px flex-1",X(p))})]})}),e.jsx(M,{title:a.title,description:a.description,detail:r?.detail??a.fallbackDetail,badge:a.badge,badgeTone:a.badgeTone,statusLabel:I(r,n),statusTone:D(r,n),enabled:n,saving:d,onToggle:()=>{G(a.id,n)},fields:O(a),children:o&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-[0.18em] text-muted-foreground",children:"API Key"}),e.jsx("p",{className:"mt-1 text-sm text-foreground/90",children:Ce(t?.apiKeys?.[o])}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t?.apiKeys?.[o]?.maskedValue?`${t.apiKeys[o]?.envVar} ${t.apiKeys[o]?.maskedValue}`:`Store ${a.badge} here so the backend is ready immediately after you enable it.`})]}),b===a.id&&e.jsx("span",{className:"text-[11px] font-medium text-emerald-600 dark:text-emerald-400",children:"Saved"})]}),e.jsx(ue,{id:`${a.id}.api-key`,value:C[o]??"",onChange:A=>E($=>({...$,[o]:A.target.value})),placeholder:t?.apiKeys?.[o]?.configured?"Enter a new key to rotate the stored secret":`Paste ${a.badge}`,className:"bg-background/80 font-mono text-sm",disabled:d}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(R,{size:"sm",onClick:()=>{ae(o)},disabled:d||!(C[o]?.trim()??"").length,children:t?.apiKeys?.[o]?.configured?"Update key":"Save key"}),(t?.apiKeys?.[o]?.source==="global_env"||t?.apiKeys?.[o]?.source==="both")&&e.jsx(R,{variant:"outline",size:"sm",onClick:()=>{te(o)},disabled:d,children:"Remove stored key"})]})]})})]},a.id)})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",onClick:()=>J(a=>!a),className:u("flex w-full items-center justify-between gap-3 rounded-xl px-1 py-1 text-left transition-colors","hover:bg-muted/10"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border border-slate-400/20 bg-slate-500/10 text-slate-700 dark:text-slate-300",children:e.jsx(fe,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold tracking-tight",children:"Legacy CLI fallbacks"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Runs only after every enabled real backend fails."})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"rounded-full border border-border/80 bg-background/85 px-2.5 py-1 text-[11px] font-medium text-muted-foreground",children:F}),W?e.jsx(he,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(pe,{className:"h-4 w-4 text-muted-foreground"})]})]}),W&&e.jsxs("div",{className:"relative overflow-hidden rounded-2xl border bg-gradient-to-br from-background via-background to-muted/20 p-3 shadow-sm",children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-px bg-gradient-to-r from-slate-500/60 via-slate-400/18 to-transparent"}),e.jsx("div",{className:"relative space-y-3",children:V.map((a,l)=>{const r=L.get(a.id),n=t?.providers?.[a.id]?.enabled??a.defaultEnabled,p=D(r,n);return e.jsxs("div",{className:"grid grid-cols-[20px_minmax(0,1fr)] items-start gap-3",children:[e.jsx("div",{className:"flex h-full justify-center",children:e.jsxs("div",{className:"flex h-full flex-col items-center",children:[e.jsx("span",{className:u("mt-5 h-3 w-3 rounded-full ring-4 ring-background",z(p))}),l<V.length-1&&e.jsx("span",{className:u("mt-1 w-px flex-1",X(p))})]})}),e.jsx(M,{title:a.title,description:a.description,detail:r?.detail??a.fallbackDetail,badge:a.badge,badgeTone:a.badgeTone,statusLabel:I(r,n),statusTone:D(r,n),enabled:n,saving:d,onToggle:()=>{G(a.id,n)},fields:O(a),docsUrl:r?.docsUrl,installCommand:r?.installCommand,footerNote:a.footerNote})]},a.id)})})]})]})]})}),e.jsx("div",{className:"border-t bg-background p-4",children:e.jsxs(R,{variant:"outline",size:"sm",onClick:()=>{f(),h(),g()},disabled:i||d,className:"w-full",children:[e.jsx(P,{className:`mr-2 h-4 w-4 ${i?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{Ie as default};
|
|
1
|
+
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as y}from"./react-vendor-CNOkPC89.js";import{bp as se,bq as re,a as H,c as u,aF as ne,L as le,I as de,br as ie,be as oe,bg as ce,n as be,d as R}from"./index-g2g1k0QS.js";import{M as ue}from"./masked-input-DXzbXJrE.js";import{p as me,R as P,w as ge,x as xe,u as B,n as fe,t as he,s as pe}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function ye(){const{state:s}=se(),t=re(),x=y.useCallback(async()=>{try{t.setWebSearchLoading(!0),t.setWebSearchError(null);const d=await fetch("/api/websearch");if(!d.ok)throw new Error("Failed to load WebSearch config");const c=await d.json();t.setWebSearchConfig(c)}catch(d){t.setWebSearchError(d.message)}finally{t.setWebSearchLoading(!1)}},[t]),i=y.useCallback(async()=>{try{t.setWebSearchStatusLoading(!0);const d=await fetch("/api/websearch/status");if(!d.ok)throw new Error("Failed to load status");const c=await d.json();t.setWebSearchStatus(c)}catch{}finally{t.setWebSearchStatusLoading(!1)}},[t]),k=y.useCallback(async d=>{const c=s.webSearchConfig;if(!c)return!1;const m={...c,...d,providers:{...c.providers,...d.providers},apiKeys:c.apiKeys};t.setWebSearchConfig(m);try{t.setWebSearchSaving(!0),t.setWebSearchError(null);const f={enabled:m.enabled,providers:m.providers};d.apiKeys&&(f.apiKeys=d.apiKeys);const h=await fetch("/api/websearch",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)});if(!h.ok){const g=await h.json();throw new Error(g.error||"Failed to save")}const v=await h.json();return t.setWebSearchConfig(v.websearch),await i(),t.setWebSearchSuccess(!0),setTimeout(()=>t.setWebSearchSuccess(!1),1500),!0}catch(f){return t.setWebSearchConfig(c),t.setWebSearchError(f.message),!1}finally{t.setWebSearchSaving(!1)}},[s.webSearchConfig,t,i]);return{config:s.webSearchConfig,status:s.webSearchStatus,loading:s.webSearchLoading,statusLoading:s.webSearchStatusLoading,saving:s.webSearchSaving,error:s.webSearchError,success:s.webSearchSuccess,fetchConfig:x,fetchStatus:i,saveConfig:k}}const ke={green:{accent:"from-emerald-500 via-lime-400 to-transparent",badge:"border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-200",glow:"bg-emerald-500/18 dark:bg-emerald-500/22",surface:"border-emerald-500/30 bg-gradient-to-br from-emerald-500/10 via-background to-background dark:from-emerald-500/14",switchFrame:"border-emerald-500/20 bg-emerald-500/10"},blue:{accent:"from-sky-500 via-blue-500 to-transparent",badge:"border-sky-500/25 bg-sky-500/10 text-sky-800 dark:text-sky-200",glow:"bg-sky-500/18 dark:bg-sky-500/22",surface:"border-sky-500/30 bg-gradient-to-br from-sky-500/10 via-background to-background dark:from-sky-500/14",switchFrame:"border-sky-500/20 bg-sky-500/10"},amber:{accent:"from-amber-500 via-orange-500 to-transparent",badge:"border-amber-500/25 bg-amber-500/10 text-amber-800 dark:text-amber-200",glow:"bg-amber-500/18 dark:bg-amber-500/22",surface:"border-amber-500/30 bg-gradient-to-br from-amber-500/10 via-background to-background dark:from-amber-500/14",switchFrame:"border-amber-500/20 bg-amber-500/10"},cyan:{accent:"from-cyan-500 via-teal-400 to-transparent",badge:"border-cyan-500/25 bg-cyan-500/10 text-cyan-800 dark:text-cyan-200",glow:"bg-cyan-500/18 dark:bg-cyan-500/22",surface:"border-cyan-500/30 bg-gradient-to-br from-cyan-500/10 via-background to-background dark:from-cyan-500/14",switchFrame:"border-cyan-500/20 bg-cyan-500/10"},slate:{accent:"from-slate-500 via-slate-400 to-transparent",badge:"border-slate-500/20 bg-slate-500/10 text-slate-700 dark:text-slate-300",glow:"bg-slate-500/18 dark:bg-slate-500/22",surface:"border-slate-400/30 bg-gradient-to-br from-slate-500/8 via-background to-background dark:from-slate-500/12",switchFrame:"border-slate-400/20 bg-slate-500/10"}};function ve(s){switch(s){case"ready":return{chip:"border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-200",dot:"bg-emerald-500"};case"setup":return{chip:"border-amber-500/25 bg-amber-500/10 text-amber-800 dark:text-amber-200",dot:"bg-amber-500"};case"idle":return{chip:"border-border/80 bg-muted/60 text-muted-foreground",dot:"bg-muted-foreground/70"}}}function M({title:s,description:t,detail:x,badge:i,badgeTone:k,statusLabel:d,statusTone:c,enabled:m,saving:f,onToggle:h,fields:v=[],docsUrl:g,installCommand:N,footerNote:S,children:C}){const{t:E}=H(),j=ke[k],_=ve(c);return e.jsxs("div",{className:u("group relative overflow-hidden rounded-2xl border px-4 py-4 shadow-sm transition-all duration-200",m?j.surface:"border-border/70 bg-gradient-to-br from-background via-background to-muted/25",m&&"shadow-[0_18px_40px_-28px_rgba(15,23,42,0.55)]"),children:[e.jsx("div",{className:u("absolute inset-x-0 top-0 h-px bg-gradient-to-r",j.accent)}),e.jsx("div",{className:u("pointer-events-none absolute -right-6 -top-8 h-28 w-28 rounded-full blur-3xl",j.glow)}),e.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-[0.045]",style:{backgroundImage:"radial-gradient(circle at 1px 1px, currentColor 1px, transparent 0)",backgroundSize:"22px 22px"}}),e.jsxs("div",{className:"relative flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsx("p",{className:"text-sm font-semibold tracking-tight",children:s}),e.jsx("span",{className:u("rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.18em]",j.badge),children:i}),e.jsxs("span",{className:u("inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-[10px] font-medium",_.chip),children:[e.jsx("span",{className:u("h-1.5 w-1.5 rounded-full",_.dot)}),d]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm leading-6 text-foreground/90",children:t}),x&&e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:x})]})]}),e.jsx("div",{className:u("flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border bg-background/75 backdrop-blur-sm",m?j.switchFrame:"border-border/70"),children:e.jsx(ne,{checked:m,onCheckedChange:h,disabled:f})})]}),m&&v.length>0&&e.jsx("div",{className:"relative mt-4 rounded-xl border border-border/65 bg-background/70 p-3 shadow-[inset_0_1px_0_rgba(255,255,255,0.35)] backdrop-blur-sm",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:v.map(b=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(le,{htmlFor:b.id,className:"text-[11px] font-medium text-muted-foreground",children:b.label}),b.saved&&e.jsx("span",{className:"text-[11px] font-medium text-emerald-600 dark:text-emerald-400",children:E("settings.saved")})]}),e.jsx(de,{id:b.id,value:b.value,type:b.type??"text",placeholder:b.placeholder,onBlur:b.onBlur,onChange:T=>b.onChange(T.target.value),onKeyDown:b.onKeyDown,className:"h-8 border-border/70 bg-background/80 text-sm",disabled:f}),b.helpText&&e.jsx("p",{className:"text-[11px] text-muted-foreground",children:b.helpText})]},b.id))})}),m&&C&&e.jsx("div",{className:"relative mt-4 rounded-xl border border-border/65 bg-background/70 p-3 shadow-[inset_0_1px_0_rgba(255,255,255,0.35)] backdrop-blur-sm",children:C}),(S||N||g)&&e.jsxs("div",{className:"relative mt-4 space-y-2 rounded-xl border border-border/65 bg-muted/30 p-3",children:[S&&e.jsx("p",{className:"text-xs text-muted-foreground",children:S}),N&&e.jsx("code",{className:"block rounded-lg border border-border/60 bg-background/85 px-2.5 py-2 text-[11px] text-muted-foreground",children:N}),g&&e.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs font-medium text-primary hover:underline",children:[e.jsx(me,{className:"h-3 w-3"}),E("settingsWebsearch.viewDocs")]})]})]})}const Y=[{id:"exa",title:"Exa",defaultEnabled:!1},{id:"tavily",title:"Tavily",defaultEnabled:!1},{id:"brave",title:"Brave",defaultEnabled:!1},{id:"searxng",title:"SearXNG",defaultEnabled:!1},{id:"duckduckgo",title:"DuckDuckGo",defaultEnabled:!0},{id:"legacy",title:"Legacy CLI",defaultEnabled:!1}],U=[{id:"exa",title:"Exa",description:"Highest-priority API backend when enabled. Best for strong relevance and extracted text.",badge:"EXA_API_KEY",badgeTone:"amber",defaultEnabled:!1,fallbackDetail:"Set EXA_API_KEY",footerNote:"Runs before every other provider in the chain when enabled and ready.",fields:[{key:"max_results",label:"Max results",type:"number",placeholder:"5",helpText:"Clamp between 1 and 10 results.",defaultValue:5,min:1,max:10}]},{id:"tavily",title:"Tavily",description:"Agent-oriented API backend with concise web result content.",badge:"TAVILY_API_KEY",badgeTone:"cyan",defaultEnabled:!1,fallbackDetail:"Set TAVILY_API_KEY",footerNote:"Runs after Exa and before Brave when enabled and ready.",fields:[{key:"max_results",label:"Max results",type:"number",placeholder:"5",helpText:"Clamp between 1 and 10 results.",defaultValue:5,min:1,max:10}]},{id:"brave",title:"Brave Search",description:"API-backed search with clean metadata and broad web coverage.",badge:"BRAVE_API_KEY",badgeTone:"blue",defaultEnabled:!1,fallbackDetail:"Set BRAVE_API_KEY",footerNote:"Runs after Exa and Tavily, before DuckDuckGo.",fields:[{key:"max_results",label:"Max results",type:"number",placeholder:"5",helpText:"Clamp between 1 and 10 results.",defaultValue:5,min:1,max:10}]},{id:"searxng",title:"SearXNG",description:"Configurable JSON backend for self-hosted or public SearXNG instances.",badge:"SELF-HOSTED",badgeTone:"cyan",defaultEnabled:!1,fallbackDetail:"Set a valid base URL",footerNote:"Runs after Brave and before DuckDuckGo when enabled and ready.",fields:[{key:"url",label:"Base URL",type:"text",placeholder:"https://search.example.com",helpText:"Paste the instance base URL only. CCS appends /search?format=json for you and rejects embedded credentials.",defaultValue:""},{key:"max_results",label:"Max results",type:"number",placeholder:"5",helpText:"Clamp between 1 and 10 results.",defaultValue:5,min:1,max:10}]},{id:"duckduckgo",title:"DuckDuckGo",description:"Zero-setup floor. Keep this on unless you want no built-in fallback at all.",badge:"DEFAULT",badgeTone:"green",defaultEnabled:!0,fallbackDetail:"Built-in",footerNote:"Last real backend in the chain. No API key needed.",fields:[{key:"max_results",label:"Max results",type:"number",placeholder:"5",helpText:"Clamp between 1 and 10 results.",defaultValue:5,min:1,max:10}]}],V=[{id:"gemini",title:"Gemini CLI",description:"Optional legacy LLM fallback. Used only if every enabled real backend fails.",badge:"LEGACY",badgeTone:"slate",defaultEnabled:!1,fallbackDetail:"Optional fallback",footerNote:"Legacy path. Useful for compatibility, not the preferred search backend.",fields:[{key:"model",label:"Model",type:"text",placeholder:"gemini-2.5-flash",helpText:"CLI model passed to Gemini when this fallback runs.",defaultValue:"gemini-2.5-flash"},{key:"timeout",label:"Timeout (seconds)",type:"number",placeholder:"55",helpText:"Clamp between 5 and 300 seconds.",defaultValue:55,min:5,max:300}]},{id:"opencode",title:"OpenCode",description:"Optional legacy LLM fallback via OpenCode.",badge:"LEGACY",badgeTone:"slate",defaultEnabled:!1,fallbackDetail:"Optional fallback",footerNote:"Legacy path. Runs after Gemini in the fallback portion of the chain.",fields:[{key:"model",label:"Model",type:"text",placeholder:"opencode/grok-code",helpText:"OpenCode model passed to the CLI runner.",defaultValue:"opencode/grok-code"},{key:"timeout",label:"Timeout (seconds)",type:"number",placeholder:"90",helpText:"Clamp between 5 and 300 seconds.",defaultValue:90,min:5,max:300}]},{id:"grok",title:"Grok CLI",description:"Optional legacy xAI fallback. Requires the Grok CLI and GROK_API_KEY.",badge:"LEGACY",badgeTone:"slate",defaultEnabled:!1,fallbackDetail:"Optional fallback",footerNote:"Last step in the full fallback chain.",fields:[{key:"timeout",label:"Timeout (seconds)",type:"number",placeholder:"55",helpText:"Clamp between 5 and 300 seconds.",defaultValue:55,min:5,max:300}]}];function D(s,t){return t&&s?.available?"ready":t?"setup":"idle"}function I(s,t){return t&&s?.available?"Ready":t?"Needs setup":"Disabled"}function je(s){switch(s){case"ready":return"border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-200";case"setup":return"border-amber-500/25 bg-amber-500/10 text-amber-800 dark:text-amber-200";case"idle":return"border-border/80 bg-background/85 text-muted-foreground"}}function we(s){switch(s){case"ready":return"bg-emerald-500";case"setup":return"bg-amber-500";case"idle":return"bg-border"}}function z(s){switch(s){case"ready":return"bg-emerald-500 shadow-[0_0_0_6px_rgba(16,185,129,0.12)]";case"setup":return"bg-amber-500 shadow-[0_0_0_6px_rgba(245,158,11,0.12)]";case"idle":return"bg-border"}}function X(s){switch(s){case"ready":return"bg-gradient-to-b from-emerald-500/55 to-border";case"setup":return"bg-gradient-to-b from-amber-500/55 to-border";case"idle":return"bg-border"}}function Ne(s,t){if(s.type==="number"){const i=Number.parseInt(t.trim(),10);if(!Number.isFinite(i))return s.defaultValue;const k=s.min??i,d=s.max??i;return Math.min(d,Math.max(k,i))}return t.trim()||String(s.defaultValue)}function q(s,t,x){const i=s?.[t]?.[x.key];return String(i??x.defaultValue)}function Se(s){return s==="exa"||s==="tavily"||s==="brave"}function Ce(s){if(!s?.configured)return"Not stored";if(!s.available&&s.source==="global_env")return"Stored in dashboard, but Global Env is disabled";switch(s.source){case"global_env":return"Stored in dashboard";case"process_env":return"Detected from shell env";case"both":return"Stored in dashboard + shell env";case"none":return"Not stored"}}function Ie(){const{t:s}=H(),{config:t,status:x,loading:i,statusLoading:k,saving:d,error:c,success:m,fetchConfig:f,fetchStatus:h,saveConfig:v}=ye(),{fetchRawConfig:g}=ie(),[N,S]=y.useState({}),[C,E]=y.useState({}),[j,_]=y.useState(null),[b,T]=y.useState(null),[W,J]=y.useState(!1);y.useEffect(()=>{f(),h(),g()},[f,h,g]);const L=y.useMemo(()=>new Map((x?.providers??[]).map(a=>[a.id,a])),[x?.providers]),w=V.filter(a=>t?.providers?.[a.id]?.enabled??a.defaultEnabled),Z=w.some(a=>L.get(a.id)?.available),F=w.length===0?"Off":w.length===1?`${w[0].title} enabled`:`${w.length} enabled`,G=async(a,l)=>{const r=t?.providers??{};await v({providers:{...r,[a]:{...r[a],enabled:!l}}})&&await g()},Q=(a,l,r)=>{S(n=>({...n,[`${a}.${l}`]:r}))},ee=async(a,l)=>{if(!t)return;const r=`${a}.${l.key}`,n=t.providers??{},p=n[a]??{},o=p[l.key]??l.defaultValue,A=Ne(l,N[r]??q(n,a,l));if(S(K=>({...K,[r]:String(A)})),String(o)===String(A))return;await v({providers:{...n,[a]:{...p,[l.key]:A}}})&&(await g(),_(r),setTimeout(()=>{_(K=>K===r?null:K)},1200))},ae=async a=>{const l=C[a]?.trim()??"";if(!l)return;await v({apiKeys:{[a]:l}})&&(await g(),E(n=>({...n,[a]:""})),T(a),setTimeout(()=>{T(n=>n===a?null:n)},1200))},te=async a=>{await v({apiKeys:{[a]:""}})&&(await g(),E(r=>({...r,[a]:""})),T(a),setTimeout(()=>{T(r=>r===a?null:r)},1200))},O=a=>(a.fields??[]).map(l=>{const r=`${a.id}.${l.key}`;return{id:r,label:l.label,value:N[r]??q(t?.providers??{},a.id,l),placeholder:l.placeholder,type:l.type,helpText:l.helpText,saved:j===r,onChange:n=>Q(a.id,l.key,n),onBlur:()=>{ee(a.id,l)},onKeyDown:n=>{n.key==="Enter"&&n.currentTarget.blur()}}});return i?e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(P,{className:"h-5 w-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${c||m?"translate-y-0 opacity-100":"pointer-events-none -translate-y-2 opacity-0"}`,children:[c&&e.jsxs(oe,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(ge,{className:"h-4 w-4"}),e.jsx(ce,{children:c})]}),m&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-green-200 bg-green-50 px-3 py-2 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(xe,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(be,{className:"flex-1",children:e.jsxs("div",{className:"space-y-6 p-5",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-2xl border bg-gradient-to-br from-background via-background to-muted/30 p-4 shadow-sm",children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-px bg-gradient-to-r from-primary/70 via-primary/20 to-transparent"}),e.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-[0.035]",style:{backgroundImage:"repeating-linear-gradient(0deg, transparent, transparent 2px, currentColor 2px, currentColor 3px)"}}),e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"inline-flex h-8 w-8 items-center justify-center rounded-xl border border-primary/20 bg-primary/8 text-primary",children:e.jsx(B,{className:"h-4 w-4"})}),e.jsx("p",{className:"text-sm font-semibold tracking-tight",children:"Execution chain"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:k?s("settingsWebsearch.checking"):x?.readiness.message})]}),e.jsx(R,{variant:"ghost",size:"sm",onClick:h,disabled:k,children:e.jsx(P,{className:`h-4 w-4 ${k?"animate-spin":""}`})})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:Y.map((a,l)=>{const r=a.id==="legacy"?w.length>0:t?.providers?.[a.id]?.enabled??a.defaultEnabled,n=a.id==="legacy"?Z?"ready":w.length>0?"setup":"idle":D(L.get(a.id),r),p=a.id==="legacy"?F:I(L.get(a.id),r);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:u("inline-flex items-center gap-2 rounded-full border px-3 py-1.5 text-[11px] font-medium",je(n)),children:[e.jsx("span",{className:u("h-1.5 w-1.5 rounded-full",we(n))}),e.jsxs("span",{children:[a.title," · ",p]})]}),l<Y.length-1&&e.jsx("span",{className:"h-px w-4 rounded-full bg-border/80"})]},a.id)})})]})]}),e.jsxs("div",{className:"relative overflow-hidden rounded-2xl border bg-gradient-to-br from-background via-background to-muted/25 p-4 shadow-sm",children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-px bg-gradient-to-r from-sky-500/70 via-emerald-500/25 to-transparent"}),e.jsxs("div",{className:"relative space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border border-sky-500/20 bg-sky-500/10 text-sky-700 dark:text-sky-300",children:e.jsx(B,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold tracking-tight",children:"Primary backends"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Real backends run top-down before any legacy CLI fallback."})]})]}),e.jsx("div",{className:"space-y-3",children:U.map((a,l)=>{const r=L.get(a.id),n=t?.providers?.[a.id]?.enabled??a.defaultEnabled,p=D(r,n),o=Se(a.id)?a.id:null;return e.jsxs("div",{className:"grid grid-cols-[20px_minmax(0,1fr)] items-start gap-3",children:[e.jsx("div",{className:"flex h-full justify-center",children:e.jsxs("div",{className:"flex h-full flex-col items-center",children:[e.jsx("span",{className:u("mt-5 h-3 w-3 rounded-full ring-4 ring-background",z(p))}),l<U.length-1&&e.jsx("span",{className:u("mt-1 w-px flex-1",X(p))})]})}),e.jsx(M,{title:a.title,description:a.description,detail:r?.detail??a.fallbackDetail,badge:a.badge,badgeTone:a.badgeTone,statusLabel:I(r,n),statusTone:D(r,n),enabled:n,saving:d,onToggle:()=>{G(a.id,n)},fields:O(a),children:o&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-[0.18em] text-muted-foreground",children:"API Key"}),e.jsx("p",{className:"mt-1 text-sm text-foreground/90",children:Ce(t?.apiKeys?.[o])}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t?.apiKeys?.[o]?.maskedValue?`${t.apiKeys[o]?.envVar} ${t.apiKeys[o]?.maskedValue}`:`Store ${a.badge} here so the backend is ready immediately after you enable it.`})]}),b===a.id&&e.jsx("span",{className:"text-[11px] font-medium text-emerald-600 dark:text-emerald-400",children:"Saved"})]}),e.jsx(ue,{id:`${a.id}.api-key`,value:C[o]??"",onChange:A=>E($=>({...$,[o]:A.target.value})),placeholder:t?.apiKeys?.[o]?.configured?"Enter a new key to rotate the stored secret":`Paste ${a.badge}`,className:"bg-background/80 font-mono text-sm",disabled:d}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(R,{size:"sm",onClick:()=>{ae(o)},disabled:d||!(C[o]?.trim()??"").length,children:t?.apiKeys?.[o]?.configured?"Update key":"Save key"}),(t?.apiKeys?.[o]?.source==="global_env"||t?.apiKeys?.[o]?.source==="both")&&e.jsx(R,{variant:"outline",size:"sm",onClick:()=>{te(o)},disabled:d,children:"Remove stored key"})]})]})})]},a.id)})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",onClick:()=>J(a=>!a),className:u("flex w-full items-center justify-between gap-3 rounded-xl px-1 py-1 text-left transition-colors","hover:bg-muted/10"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border border-slate-400/20 bg-slate-500/10 text-slate-700 dark:text-slate-300",children:e.jsx(fe,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold tracking-tight",children:"Legacy CLI fallbacks"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Runs only after every enabled real backend fails."})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"rounded-full border border-border/80 bg-background/85 px-2.5 py-1 text-[11px] font-medium text-muted-foreground",children:F}),W?e.jsx(he,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(pe,{className:"h-4 w-4 text-muted-foreground"})]})]}),W&&e.jsxs("div",{className:"relative overflow-hidden rounded-2xl border bg-gradient-to-br from-background via-background to-muted/20 p-3 shadow-sm",children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-px bg-gradient-to-r from-slate-500/60 via-slate-400/18 to-transparent"}),e.jsx("div",{className:"relative space-y-3",children:V.map((a,l)=>{const r=L.get(a.id),n=t?.providers?.[a.id]?.enabled??a.defaultEnabled,p=D(r,n);return e.jsxs("div",{className:"grid grid-cols-[20px_minmax(0,1fr)] items-start gap-3",children:[e.jsx("div",{className:"flex h-full justify-center",children:e.jsxs("div",{className:"flex h-full flex-col items-center",children:[e.jsx("span",{className:u("mt-5 h-3 w-3 rounded-full ring-4 ring-background",z(p))}),l<V.length-1&&e.jsx("span",{className:u("mt-1 w-px flex-1",X(p))})]})}),e.jsx(M,{title:a.title,description:a.description,detail:r?.detail??a.fallbackDetail,badge:a.badge,badgeTone:a.badgeTone,statusLabel:I(r,n),statusTone:D(r,n),enabled:n,saving:d,onToggle:()=>{G(a.id,n)},fields:O(a),docsUrl:r?.docsUrl,installCommand:r?.installCommand,footerNote:a.footerNote})]},a.id)})})]})]})]})}),e.jsx("div",{className:"border-t bg-background p-4",children:e.jsxs(R,{variant:"outline",size:"sm",onClick:()=>{f(),h(),g()},disabled:i||d,className:"w-full",children:[e.jsx(P,{className:`mr-2 h-4 w-4 ${i?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{Ie as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as n}from"./react-vendor-CNOkPC89.js";import{bt as Oe,bu as He,Y as L,a as ae,I as B,aF as D,r as Ve,s as Ue,t as ze,v as We,w as ue,d as V,bv as Ge,bw as Ye,bx as qe,be as se,bg as te,n as Je}from"./index-DNmWbKbN.js";import{C as U}from"./default-ports-1QQSffYX.js";import{ba as he,R as re,h as Xe,x as fe,W as Qe,w as Ze,az as es,bb as ss,T as ye,aG as ts,p as rs,bc as as}from"./icons-KVCk4_U8.js";import{P as os}from"./proxy-status-widget-s89zaj3X.js";import{R as H}from"./antigravity-responsibility-constants-Bvh4Ybz0.js";import{t as T}from"./notifications-B2HqRBj7.js";import"./tanstack-CrmUhA7Z.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-BA39vaYL.js";function ns(){const{state:s}=Oe(),t=He(),[g,o]=n.useState(null),[u,b]=n.useState(null),[y,j]=n.useState(null),[p,C]=n.useState(null),[S,P]=n.useState(null),w=n.useCallback(async()=>{try{t.setProxyLoading(!0),t.setProxyError(null);const d=await L.cliproxyServer.get();t.setProxyConfig(d)}catch(d){t.setProxyError(d.message)}finally{t.setProxyLoading(!1)}},[t]),A=n.useCallback(async d=>{const x=s.proxyConfig;if(!x)return;const h={remote:{...x.remote,...d.remote},fallback:{...x.fallback,...d.fallback},local:{...x.local,...d.local}};t.setProxyConfig(h),t.setProxyTestResult(null);try{t.setProxySaving(!0),t.setProxyError(null);const a=await L.cliproxyServer.update(d);t.setProxyConfig(a),t.setProxySuccess(!0),setTimeout(()=>t.setProxySuccess(!1),1500)}catch(a){t.setProxyConfig(x),t.setProxyError(a.message)}finally{t.setProxySaving(!1)}},[s.proxyConfig,t]),E=n.useCallback(async d=>{const{host:x,port:h,protocol:a,authToken:c}=d;if(!x){t.setProxyError("Host is required");return}try{t.setProxyTesting(!0),t.setProxyError(null),t.setProxyTestResult(null);const k=h?parseInt(h,10):void 0,l=await L.cliproxyServer.test({host:x,port:k||void 0,protocol:a,authToken:c||void 0});t.setProxyTestResult(l)}catch(k){t.setProxyError(k.message)}finally{t.setProxyTesting(!1)}},[t]);return{config:s.proxyConfig,loading:s.proxyLoading,saving:s.proxySaving,error:s.proxyError,success:s.proxySuccess,testResult:s.proxyTestResult,testing:s.proxyTesting,editedHost:g,setEditedHost:o,editedPort:u,setEditedPort:b,editedAuthToken:y,setEditedAuthToken:j,editedManagementKey:p,setEditedManagementKey:C,editedLocalPort:S,setEditedLocalPort:P,fetchConfig:w,saveConfig:A,testConnection:E}}function is({config:s,saving:t,displayLocalPort:g,setEditedLocalPort:o,onSaveLocalPort:u,onSaveConfig:b}){const{t:y}=ae(),j=s.local;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:y("settingsProxy.localProxy")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:y("settingsProxy.port")}),e.jsx(B,{type:"text",inputMode:"numeric",value:g,onChange:p=>o(p.target.value.replace(/\D/g,"")),onBlur:u,placeholder:`${U}`,className:"font-mono max-w-32",disabled:t})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:y("settingsProxy.autoStart")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:y("settingsProxy.localAutoStartDesc")})]}),e.jsx(D,{checked:j.auto_start??!0,onCheckedChange:p=>b({local:{...j,auto_start:p}}),disabled:t})]})]})]})}function ls({config:s,saving:t,testing:g,testResult:o,displayHost:u,displayPort:b,displayAuthToken:y,displayManagementKey:j,setEditedHost:p,setEditedPort:C,setEditedAuthToken:S,setEditedManagementKey:P,onSaveHost:w,onSavePort:A,onSaveAuthToken:E,onSaveManagementKey:d,onSaveConfig:x,onTestConnection:h}){const{t:a}=ae(),c=s.remote,k=l=>l==="https"?443:U;return e.jsxs("div",{className:"space-y-4 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(he,{className:"w-4 h-4"}),a("settingsProxy.remoteConfigTitle")]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.host")}),e.jsx(B,{value:u,onChange:l=>p(l.target.value),onBlur:w,placeholder:a("settingsProxy.hostPlaceholder"),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm text-muted-foreground",children:[a("settingsProxy.port")," ",e.jsxs("span",{className:"text-xs opacity-70",children:["(",a("settingsProxy.defaultPort",{value:k(s.remote.protocol||"http")}),")"]})]}),e.jsx(B,{type:"text",inputMode:"numeric",value:b,onChange:l=>C(l.target.value.replace(/\D/g,"")),onBlur:A,placeholder:a("settingsProxy.portPlaceholder",{value:k(s.remote.protocol||"http")}),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.protocol")}),e.jsxs(Ve,{value:s.remote.protocol||"http",onValueChange:l=>x({remote:{...c,protocol:l}}),disabled:t,children:[e.jsx(Ue,{children:e.jsx(ze,{})}),e.jsxs(We,{children:[e.jsx(ue,{value:"http",children:a("settingsProxy.http")}),e.jsx(ue,{value:"https",children:a("settingsProxy.https")})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.apiKeyOptional")}),e.jsx(B,{type:"password",value:y,onChange:l=>S(l.target.value),onBlur:E,placeholder:a("settingsProxy.apiKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.apiKeyDesc")})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.managementKeyOptional")}),e.jsx(B,{type:"password",value:j,onChange:l=>P(l.target.value),onBlur:d,placeholder:a("settingsProxy.managementKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.managementKeyDesc")})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(V,{onClick:h,disabled:g||!u,variant:"outline",className:"w-full",children:g?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-4 h-4 mr-2 animate-spin"}),a("settingsProxy.testing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{className:"w-4 h-4 mr-2"}),a("settingsProxy.testConnection")]})}),o&&e.jsx("div",{className:`p-3 rounded-md ${o.reachable?"bg-green-50 border border-green-200 dark:bg-green-900/20 dark:border-green-900/50":"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50"}`,children:e.jsx("div",{className:"flex items-center gap-2",children:o.reachable?e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"w-4 h-4 text-green-600 dark:text-green-400"}),e.jsx("span",{className:"text-sm font-medium text-green-700 dark:text-green-300",children:a("settingsProxy.connectedLatency",{value:o.latencyMs})})]}):e.jsxs(e.Fragment,{children:[e.jsx(Qe,{className:"w-4 h-4 text-red-600 dark:text-red-400"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:o.error||a("settingsProxy.connectionFailed")})]})})})]})]})}const pe="ccs_debug_mode",cs=["kiro","ghcp"];function ds(s){return s.trim().replace(/\s+/g," ").toUpperCase()}function Cs(){const{t:s}=ae(),{config:t,loading:g,saving:o,error:u,success:b,testResult:y,testing:j,editedHost:p,setEditedHost:C,editedPort:S,setEditedPort:P,editedAuthToken:w,setEditedAuthToken:A,editedManagementKey:E,setEditedManagementKey:d,editedLocalPort:x,setEditedLocalPort:h,fetchConfig:a,saveConfig:c,testConnection:k}=ns(),{fetchRawConfig:l}=Ge(),[_,be]=n.useState(()=>{try{return localStorage.getItem(pe)==="true"}catch{return!1}}),[je,z]=n.useState(!1),[Pe,oe]=n.useState(!0),[f,ne]=n.useState(!1),[ke,R]=n.useState(!1),[ie,I]=n.useState(""),K=n.useRef(!1),W=ds(ie)===H,ve=r=>{be(r);try{localStorage.setItem(pe,String(r))}catch{}},G=n.useCallback(async()=>{try{oe(!0);const r=await fetch("/api/settings/auth/antigravity-risk");if(!r.ok)throw new Error(s("settingsProxy.failedLoadAgyMode"));const i=await r.json();z(i.antigravityAckBypass===!0)}catch(r){T.error(r instanceof Error?r.message:s("settingsProxy.failedLoadAgyMode")),z(!1)}finally{oe(!1)}},[s]),F=n.useCallback(async r=>{if(!(K.current||f||o))try{K.current=!0,ne(!0);const i=await fetch("/api/settings/auth/antigravity-risk",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravityAckBypass:r})}),O=await i.json();if(!i.ok)throw new Error(O.error||s("settingsProxy.failedUpdateAgyMode"));const $e=O.antigravityAckBypass===!0,me=await fetch("/api/settings/auth/antigravity-risk",{cache:"no-store"});if(!me.ok)throw new Error(s("settingsProxy.failedVerifyAgyMode"));const ge=(await me.json()).antigravityAckBypass===!0;if(ge!==r)throw new Error(s("settingsProxy.notPersistedAgyMode"));z(ge&&$e),R(!1),I(""),T.success(s(r?"settingsProxy.agyModeEnabled":"settingsProxy.agyModeDisabled")),await l()}catch(i){T.error(i instanceof Error?i.message:s("settingsProxy.failedUpdateAgyMode"))}finally{K.current=!1,ne(!1)}},[f,l,o,s]),Ne=n.useCallback(r=>{if(!(K.current||f||o)){if(r){R(!0);return}R(!1),I(""),F(!1)}},[f,F,o]),Ce=n.useCallback(()=>{if(!W){T.error(s("settingsProxy.typePhraseToContinue",{value:H}));return}F(!0)},[W,F,s]),[v,Y]=n.useState("plus"),[Se,we]=n.useState(!1),q=Ye(),{data:Ae}=qe(),le=Ae?.running??!1,J=n.useCallback(async()=>{try{const r=await L.cliproxyServer.getBackend();Y(r.backend)}catch(r){console.error("[Proxy] Failed to fetch backend:",r)}},[]),X=n.useCallback(async()=>{try{const i=(await L.cliproxy.list()).variants.some(O=>cs.includes(O.provider));we(i)}catch(r){console.error("[Proxy] Failed to check variants:",r)}},[]),ce=r=>{const i=v;Y(r),q.mutate({backend:r},{onError:()=>{Y(i)}})};if(n.useEffect(()=>{if(_&&t){const r={...t,remote:{...t.remote,auth_token:t.remote.auth_token?"[REDACTED]":void 0,management_key:t.remote.management_key?"[REDACTED]":void 0}};console.log("[CCS Debug] Debug mode enabled - proxy config:",r)}},[_,t]),n.useEffect(()=>{a(),G(),l(),J(),X()},[a,G,l,J,X]),g||!t)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(re,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})});const m=t.remote.enabled??!1,$=!m&&le,N=t.remote,M=t.fallback,Ee=t.remote.host??"",Te=t.remote.port!==void 0?t.remote.port.toString():"",Be=t.remote.auth_token??"",Me=t.remote.management_key??"",De=(t.local.port??U).toString(),Q=p??Ee,Z=S??Te,ee=w??Be,de=E??Me,xe=x??De,Le=()=>{const r=p??Q;r!==t.remote.host&&c({remote:{...N,host:r}}),C(null)},_e=()=>{const r=(S??Z).trim();if(r===""){t.remote.port!==void 0&&c({remote:{...N,port:void 0}}),P(null);return}const i=Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidPortOrEmpty")),P(null);return}i!==t.remote.port&&c({remote:{...N,port:i}}),P(null)},Re=()=>{const r=w??ee;r!==t.remote.auth_token&&c({remote:{...N,auth_token:r}}),A(null)},Ie=()=>{const r=E??de;r!==t.remote.management_key&&c({remote:{...N,management_key:r||void 0}}),d(null)},Ke=()=>{const r=(x??xe).trim(),i=r===""?U:Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidLocalPort")),h(null);return}i!==t.local.port&&c({local:{...t.local,port:i}}),h(null)},Fe=()=>{k({host:Q,port:Z,protocol:t.remote.protocol||"http",authToken:ee})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${u||b?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[u&&e.jsxs(se,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(Ze,{className:"h-4 w-4"}),e.jsx(te,{children:u})]}),b&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(fe,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsProxy.description",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})}),!m&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.instanceStatus")}),e.jsx(os,{})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.connectionMode")}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!1}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(es,{className:`w-5 h-5 ${m?"text-muted-foreground":"text-primary"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.local")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.localDesc",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]}),e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!0}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(he,{className:`w-5 h-5 ${m?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.remote")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.remoteDesc",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ss,{className:"w-4 h-4"}),s("settingsProxy.backendBinary")]}),!m&&le&&e.jsxs(se,{className:"py-2 border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-900/20 [&>svg]:top-2.5",children:[e.jsx(ye,{className:"h-4 w-4 text-amber-600"}),e.jsx(te,{className:"text-amber-700 dark:text-amber-400",children:s("settingsProxy.stopProxyToSwitch")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>ce("plus"),disabled:q.isPending||$,className:`p-4 rounded-lg border-2 text-left transition-all ${v==="plus"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${$?"opacity-60 cursor-not-allowed":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendPlusApi")}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-400",children:s("settingsProxy.default")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.plusDesc")})]}),e.jsxs("button",{onClick:()=>ce("original"),disabled:q.isPending||$,className:`p-4 rounded-lg border-2 text-left transition-all ${v==="original"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${$?"opacity-60 cursor-not-allowed":""}`,children:[e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendApi")})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.originalDesc")})]})]}),v==="original"&&Se&&e.jsxs(se,{variant:"destructive",className:"py-2",children:[e.jsx(ye,{className:"h-4 w-4"}),e.jsx(te,{children:s("settingsProxy.variantsIncompatible")})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ts,{className:"w-4 h-4 text-amber-700 dark:text-amber-300"}),s("settingsProxy.safety")]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-amber-400/35 bg-amber-50/70 p-4 dark:border-amber-800/60 dark:bg-amber-950/25",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.agyModeTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.agyModeDesc")})]}),e.jsx(D,{"aria-labelledby":"agy-power-user-mode-label","aria-describedby":"agy-power-user-mode-description",checked:je,disabled:Pe||f||o,onCheckedChange:Ne})]}),e.jsx("p",{id:"agy-power-user-mode-description",className:"text-xs text-amber-800/90 dark:text-amber-200/90",children:s("settingsProxy.agyWarning")}),ke&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/40 bg-rose-500/[0.08] p-3.5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.finalConfirm")}),e.jsx("p",{className:"text-xs leading-relaxed text-rose-800/95 dark:text-rose-200/90",children:s("settingsProxy.finalConfirmDesc")})]}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step1")}),e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"mt-1 inline-flex items-center gap-1.5 text-xs font-medium text-rose-800 underline decoration-rose-500/60 underline-offset-2 transition-colors hover:text-rose-700 dark:text-rose-200",children:[s("settingsProxy.readIssue"),e.jsx(rs,{className:"h-3.5 w-3.5"})]})]}),e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step2")}),e.jsxs("p",{className:"mt-1 text-xs text-rose-800/95 dark:text-rose-200/90",children:[s("settingsProxy.typePrefix")," ",e.jsx("code",{className:"rounded bg-background/80 px-1 py-0.5 font-mono",children:H})," ",s("settingsProxy.typeSuffix")]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{value:ie,onChange:r=>I(r.target.value),placeholder:H,disabled:f||o,className:"font-mono text-xs","aria-label":s("settingsProxy.typePhraseAria")}),e.jsx("p",{className:"text-[11px] text-rose-800/90 dark:text-rose-200/80",children:s("settingsProxy.exactPhrase")})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(V,{variant:"outline",size:"sm",onClick:()=>{R(!1),I("")},disabled:f||o,children:s("settingsBackups.cancel")}),e.jsx(V,{size:"sm",variant:"destructive",onClick:Ce,disabled:!W||f||o,children:s("settingsProxy.enableAgyMode")})]})]}),e.jsx("span",{id:"agy-power-user-mode-label",className:"sr-only",children:s("settingsProxy.toggleAgyMode")})]})]}),m&&e.jsx(ls,{config:t,saving:o,testing:j,testResult:y,displayHost:Q,displayPort:Z,displayAuthToken:ee,displayManagementKey:de,setEditedHost:C,setEditedPort:P,setEditedAuthToken:A,setEditedManagementKey:d,onSaveHost:Le,onSavePort:_e,onSaveAuthToken:Re,onSaveManagementKey:Ie,onSaveConfig:c,onTestConnection:Fe}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.fallbackSettings")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.enableFallback")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.enableFallbackDesc")})]}),e.jsx(D,{checked:M.enabled??!0,onCheckedChange:r=>c({fallback:{...M,enabled:r}}),disabled:o||!m})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.autoStartLocal")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.autoStartLocalDesc")})]}),e.jsx(D,{checked:M.auto_start??!1,onCheckedChange:r=>c({fallback:{...M,auto_start:r}}),disabled:o||!m||!M.enabled})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(as,{className:"w-4 h-4"}),s("settingsProxy.advanced")]}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.debugMode")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.debugModeDesc")})]}),e.jsx(D,{checked:_,onCheckedChange:ve,disabled:o})]}),_&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 pl-0.5",children:s("settingsProxy.debugModeEnabled")})]})]}),!m&&e.jsx(is,{config:t,saving:o,displayLocalPort:xe,setEditedLocalPort:h,onSaveLocalPort:Ke,onSaveConfig:c})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(V,{variant:"outline",size:"sm",onClick:()=>{a(),G(),l(),J(),X()},disabled:g||o||f,className:"w-full",children:[e.jsx(re,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{Cs as default};
|
|
1
|
+
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as n}from"./react-vendor-CNOkPC89.js";import{bp as Oe,bq as He,Y as L,a as ae,I as B,aF as D,r as Ve,s as Ue,t as ze,v as We,w as ue,d as V,br as Ge,bs as Ye,bt as qe,be as se,bg as te,n as Je}from"./index-g2g1k0QS.js";import{C as U}from"./default-ports-1QQSffYX.js";import{ba as he,R as re,h as Xe,x as fe,W as Qe,w as Ze,az as es,bb as ss,T as pe,aG as ts,p as rs,bc as as}from"./icons-KVCk4_U8.js";import{P as os}from"./proxy-status-widget-DCQBVSBP.js";import{R as H}from"./antigravity-responsibility-constants-Bvh4Ybz0.js";import{t as T}from"./notifications-B2HqRBj7.js";import"./tanstack-CrmUhA7Z.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-sars2LJq.js";function ns(){const{state:s}=Oe(),t=He(),[g,o]=n.useState(null),[u,b]=n.useState(null),[p,j]=n.useState(null),[y,C]=n.useState(null),[S,P]=n.useState(null),w=n.useCallback(async()=>{try{t.setProxyLoading(!0),t.setProxyError(null);const d=await L.cliproxyServer.get();t.setProxyConfig(d)}catch(d){t.setProxyError(d.message)}finally{t.setProxyLoading(!1)}},[t]),A=n.useCallback(async d=>{const x=s.proxyConfig;if(!x)return;const h={remote:{...x.remote,...d.remote},fallback:{...x.fallback,...d.fallback},local:{...x.local,...d.local}};t.setProxyConfig(h),t.setProxyTestResult(null);try{t.setProxySaving(!0),t.setProxyError(null);const a=await L.cliproxyServer.update(d);t.setProxyConfig(a),t.setProxySuccess(!0),setTimeout(()=>t.setProxySuccess(!1),1500)}catch(a){t.setProxyConfig(x),t.setProxyError(a.message)}finally{t.setProxySaving(!1)}},[s.proxyConfig,t]),E=n.useCallback(async d=>{const{host:x,port:h,protocol:a,authToken:c}=d;if(!x){t.setProxyError("Host is required");return}try{t.setProxyTesting(!0),t.setProxyError(null),t.setProxyTestResult(null);const k=h?parseInt(h,10):void 0,l=await L.cliproxyServer.test({host:x,port:k||void 0,protocol:a,authToken:c||void 0});t.setProxyTestResult(l)}catch(k){t.setProxyError(k.message)}finally{t.setProxyTesting(!1)}},[t]);return{config:s.proxyConfig,loading:s.proxyLoading,saving:s.proxySaving,error:s.proxyError,success:s.proxySuccess,testResult:s.proxyTestResult,testing:s.proxyTesting,editedHost:g,setEditedHost:o,editedPort:u,setEditedPort:b,editedAuthToken:p,setEditedAuthToken:j,editedManagementKey:y,setEditedManagementKey:C,editedLocalPort:S,setEditedLocalPort:P,fetchConfig:w,saveConfig:A,testConnection:E}}function is({config:s,saving:t,displayLocalPort:g,setEditedLocalPort:o,onSaveLocalPort:u,onSaveConfig:b}){const{t:p}=ae(),j=s.local;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:p("settingsProxy.localProxy")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:p("settingsProxy.port")}),e.jsx(B,{type:"text",inputMode:"numeric",value:g,onChange:y=>o(y.target.value.replace(/\D/g,"")),onBlur:u,placeholder:`${U}`,className:"font-mono max-w-32",disabled:t})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:p("settingsProxy.autoStart")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("settingsProxy.localAutoStartDesc")})]}),e.jsx(D,{checked:j.auto_start??!0,onCheckedChange:y=>b({local:{...j,auto_start:y}}),disabled:t})]})]})]})}function ls({config:s,saving:t,testing:g,testResult:o,displayHost:u,displayPort:b,displayAuthToken:p,displayManagementKey:j,setEditedHost:y,setEditedPort:C,setEditedAuthToken:S,setEditedManagementKey:P,onSaveHost:w,onSavePort:A,onSaveAuthToken:E,onSaveManagementKey:d,onSaveConfig:x,onTestConnection:h}){const{t:a}=ae(),c=s.remote,k=l=>l==="https"?443:U;return e.jsxs("div",{className:"space-y-4 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(he,{className:"w-4 h-4"}),a("settingsProxy.remoteConfigTitle")]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.host")}),e.jsx(B,{value:u,onChange:l=>y(l.target.value),onBlur:w,placeholder:a("settingsProxy.hostPlaceholder"),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm text-muted-foreground",children:[a("settingsProxy.port")," ",e.jsxs("span",{className:"text-xs opacity-70",children:["(",a("settingsProxy.defaultPort",{value:k(s.remote.protocol||"http")}),")"]})]}),e.jsx(B,{type:"text",inputMode:"numeric",value:b,onChange:l=>C(l.target.value.replace(/\D/g,"")),onBlur:A,placeholder:a("settingsProxy.portPlaceholder",{value:k(s.remote.protocol||"http")}),className:"font-mono",disabled:t})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.protocol")}),e.jsxs(Ve,{value:s.remote.protocol||"http",onValueChange:l=>x({remote:{...c,protocol:l}}),disabled:t,children:[e.jsx(Ue,{children:e.jsx(ze,{})}),e.jsxs(We,{children:[e.jsx(ue,{value:"http",children:a("settingsProxy.http")}),e.jsx(ue,{value:"https",children:a("settingsProxy.https")})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.apiKeyOptional")}),e.jsx(B,{type:"password",value:p,onChange:l=>S(l.target.value),onBlur:E,placeholder:a("settingsProxy.apiKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.apiKeyDesc")})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:a("settingsProxy.managementKeyOptional")}),e.jsx(B,{type:"password",value:j,onChange:l=>P(l.target.value),onBlur:d,placeholder:a("settingsProxy.managementKeyPlaceholder"),className:"font-mono",disabled:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settingsProxy.managementKeyDesc")})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(V,{onClick:h,disabled:g||!u,variant:"outline",className:"w-full",children:g?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-4 h-4 mr-2 animate-spin"}),a("settingsProxy.testing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{className:"w-4 h-4 mr-2"}),a("settingsProxy.testConnection")]})}),o&&e.jsx("div",{className:`p-3 rounded-md ${o.reachable?"bg-green-50 border border-green-200 dark:bg-green-900/20 dark:border-green-900/50":"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50"}`,children:e.jsx("div",{className:"flex items-center gap-2",children:o.reachable?e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"w-4 h-4 text-green-600 dark:text-green-400"}),e.jsx("span",{className:"text-sm font-medium text-green-700 dark:text-green-300",children:a("settingsProxy.connectedLatency",{value:o.latencyMs})})]}):e.jsxs(e.Fragment,{children:[e.jsx(Qe,{className:"w-4 h-4 text-red-600 dark:text-red-400"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:o.error||a("settingsProxy.connectionFailed")})]})})})]})]})}const ye="ccs_debug_mode",cs=["kiro","ghcp"];function ds(s){return s.trim().replace(/\s+/g," ").toUpperCase()}function Cs(){const{t:s}=ae(),{config:t,loading:g,saving:o,error:u,success:b,testResult:p,testing:j,editedHost:y,setEditedHost:C,editedPort:S,setEditedPort:P,editedAuthToken:w,setEditedAuthToken:A,editedManagementKey:E,setEditedManagementKey:d,editedLocalPort:x,setEditedLocalPort:h,fetchConfig:a,saveConfig:c,testConnection:k}=ns(),{fetchRawConfig:l}=Ge(),[_,be]=n.useState(()=>{try{return localStorage.getItem(ye)==="true"}catch{return!1}}),[je,z]=n.useState(!1),[Pe,oe]=n.useState(!0),[f,ne]=n.useState(!1),[ke,R]=n.useState(!1),[ie,I]=n.useState(""),K=n.useRef(!1),W=ds(ie)===H,ve=r=>{be(r);try{localStorage.setItem(ye,String(r))}catch{}},G=n.useCallback(async()=>{try{oe(!0);const r=await fetch("/api/settings/auth/antigravity-risk");if(!r.ok)throw new Error(s("settingsProxy.failedLoadAgyMode"));const i=await r.json();z(i.antigravityAckBypass===!0)}catch(r){T.error(r instanceof Error?r.message:s("settingsProxy.failedLoadAgyMode")),z(!1)}finally{oe(!1)}},[s]),F=n.useCallback(async r=>{if(!(K.current||f||o))try{K.current=!0,ne(!0);const i=await fetch("/api/settings/auth/antigravity-risk",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravityAckBypass:r})}),O=await i.json();if(!i.ok)throw new Error(O.error||s("settingsProxy.failedUpdateAgyMode"));const $e=O.antigravityAckBypass===!0,me=await fetch("/api/settings/auth/antigravity-risk",{cache:"no-store"});if(!me.ok)throw new Error(s("settingsProxy.failedVerifyAgyMode"));const ge=(await me.json()).antigravityAckBypass===!0;if(ge!==r)throw new Error(s("settingsProxy.notPersistedAgyMode"));z(ge&&$e),R(!1),I(""),T.success(s(r?"settingsProxy.agyModeEnabled":"settingsProxy.agyModeDisabled")),await l()}catch(i){T.error(i instanceof Error?i.message:s("settingsProxy.failedUpdateAgyMode"))}finally{K.current=!1,ne(!1)}},[f,l,o,s]),Ne=n.useCallback(r=>{if(!(K.current||f||o)){if(r){R(!0);return}R(!1),I(""),F(!1)}},[f,F,o]),Ce=n.useCallback(()=>{if(!W){T.error(s("settingsProxy.typePhraseToContinue",{value:H}));return}F(!0)},[W,F,s]),[v,Y]=n.useState("plus"),[Se,we]=n.useState(!1),q=Ye(),{data:Ae}=qe(),le=Ae?.running??!1,J=n.useCallback(async()=>{try{const r=await L.cliproxyServer.getBackend();Y(r.backend)}catch(r){console.error("[Proxy] Failed to fetch backend:",r)}},[]),X=n.useCallback(async()=>{try{const i=(await L.cliproxy.list()).variants.some(O=>cs.includes(O.provider));we(i)}catch(r){console.error("[Proxy] Failed to check variants:",r)}},[]),ce=r=>{const i=v;Y(r),q.mutate({backend:r},{onError:()=>{Y(i)}})};if(n.useEffect(()=>{if(_&&t){const r={...t,remote:{...t.remote,auth_token:t.remote.auth_token?"[REDACTED]":void 0,management_key:t.remote.management_key?"[REDACTED]":void 0}};console.log("[CCS Debug] Debug mode enabled - proxy config:",r)}},[_,t]),n.useEffect(()=>{a(),G(),l(),J(),X()},[a,G,l,J,X]),g||!t)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(re,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})});const m=t.remote.enabled??!1,$=!m&&le,N=t.remote,M=t.fallback,Ee=t.remote.host??"",Te=t.remote.port!==void 0?t.remote.port.toString():"",Be=t.remote.auth_token??"",Me=t.remote.management_key??"",De=(t.local.port??U).toString(),Q=y??Ee,Z=S??Te,ee=w??Be,de=E??Me,xe=x??De,Le=()=>{const r=y??Q;r!==t.remote.host&&c({remote:{...N,host:r}}),C(null)},_e=()=>{const r=(S??Z).trim();if(r===""){t.remote.port!==void 0&&c({remote:{...N,port:void 0}}),P(null);return}const i=Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidPortOrEmpty")),P(null);return}i!==t.remote.port&&c({remote:{...N,port:i}}),P(null)},Re=()=>{const r=w??ee;r!==t.remote.auth_token&&c({remote:{...N,auth_token:r}}),A(null)},Ie=()=>{const r=E??de;r!==t.remote.management_key&&c({remote:{...N,management_key:r||void 0}}),d(null)},Ke=()=>{const r=(x??xe).trim(),i=r===""?U:Number(r);if(!Number.isInteger(i)||i<1||i>65535){T.error(s("settingsProxy.invalidLocalPort")),h(null);return}i!==t.local.port&&c({local:{...t.local,port:i}}),h(null)},Fe=()=>{k({host:Q,port:Z,protocol:t.remote.protocol||"http",authToken:ee})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${u||b?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[u&&e.jsxs(se,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(Ze,{className:"h-4 w-4"}),e.jsx(te,{children:u})]}),b&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(fe,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsProxy.description",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})}),!m&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.instanceStatus")}),e.jsx(os,{})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.connectionMode")}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!1}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(es,{className:`w-5 h-5 ${m?"text-muted-foreground":"text-primary"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.local")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.localDesc",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]}),e.jsxs("button",{onClick:()=>c({remote:{...N,enabled:!0}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${m?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(he,{className:`w-5 h-5 ${m?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:"font-medium",children:s("settingsProxy.remote")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.remoteDesc",{backend:s(v==="plus"?"settingsProxy.backendPlus":"settingsProxy.backend")})})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ss,{className:"w-4 h-4"}),s("settingsProxy.backendBinary")]}),!m&&le&&e.jsxs(se,{className:"py-2 border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-900/20 [&>svg]:top-2.5",children:[e.jsx(pe,{className:"h-4 w-4 text-amber-600"}),e.jsx(te,{className:"text-amber-700 dark:text-amber-400",children:s("settingsProxy.stopProxyToSwitch")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>ce("plus"),disabled:q.isPending||$,className:`p-4 rounded-lg border-2 text-left transition-all ${v==="plus"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${$?"opacity-60 cursor-not-allowed":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendPlusApi")}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-400",children:s("settingsProxy.default")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.plusDesc")})]}),e.jsxs("button",{onClick:()=>ce("original"),disabled:q.isPending||$,className:`p-4 rounded-lg border-2 text-left transition-all ${v==="original"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${$?"opacity-60 cursor-not-allowed":""}`,children:[e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsx("span",{className:"font-medium",children:s("settingsProxy.backendApi")})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.originalDesc")})]})]}),v==="original"&&Se&&e.jsxs(se,{variant:"destructive",className:"py-2",children:[e.jsx(pe,{className:"h-4 w-4"}),e.jsx(te,{children:s("settingsProxy.variantsIncompatible")})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ts,{className:"w-4 h-4 text-amber-700 dark:text-amber-300"}),s("settingsProxy.safety")]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-amber-400/35 bg-amber-50/70 p-4 dark:border-amber-800/60 dark:bg-amber-950/25",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.agyModeTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.agyModeDesc")})]}),e.jsx(D,{"aria-labelledby":"agy-power-user-mode-label","aria-describedby":"agy-power-user-mode-description",checked:je,disabled:Pe||f||o,onCheckedChange:Ne})]}),e.jsx("p",{id:"agy-power-user-mode-description",className:"text-xs text-amber-800/90 dark:text-amber-200/90",children:s("settingsProxy.agyWarning")}),ke&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/40 bg-rose-500/[0.08] p-3.5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.finalConfirm")}),e.jsx("p",{className:"text-xs leading-relaxed text-rose-800/95 dark:text-rose-200/90",children:s("settingsProxy.finalConfirmDesc")})]}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step1")}),e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"mt-1 inline-flex items-center gap-1.5 text-xs font-medium text-rose-800 underline decoration-rose-500/60 underline-offset-2 transition-colors hover:text-rose-700 dark:text-rose-200",children:[s("settingsProxy.readIssue"),e.jsx(rs,{className:"h-3.5 w-3.5"})]})]}),e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:s("settingsProxy.step2")}),e.jsxs("p",{className:"mt-1 text-xs text-rose-800/95 dark:text-rose-200/90",children:[s("settingsProxy.typePrefix")," ",e.jsx("code",{className:"rounded bg-background/80 px-1 py-0.5 font-mono",children:H})," ",s("settingsProxy.typeSuffix")]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{value:ie,onChange:r=>I(r.target.value),placeholder:H,disabled:f||o,className:"font-mono text-xs","aria-label":s("settingsProxy.typePhraseAria")}),e.jsx("p",{className:"text-[11px] text-rose-800/90 dark:text-rose-200/80",children:s("settingsProxy.exactPhrase")})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(V,{variant:"outline",size:"sm",onClick:()=>{R(!1),I("")},disabled:f||o,children:s("settingsBackups.cancel")}),e.jsx(V,{size:"sm",variant:"destructive",onClick:Ce,disabled:!W||f||o,children:s("settingsProxy.enableAgyMode")})]})]}),e.jsx("span",{id:"agy-power-user-mode-label",className:"sr-only",children:s("settingsProxy.toggleAgyMode")})]})]}),m&&e.jsx(ls,{config:t,saving:o,testing:j,testResult:p,displayHost:Q,displayPort:Z,displayAuthToken:ee,displayManagementKey:de,setEditedHost:C,setEditedPort:P,setEditedAuthToken:A,setEditedManagementKey:d,onSaveHost:Le,onSavePort:_e,onSaveAuthToken:Re,onSaveManagementKey:Ie,onSaveConfig:c,onTestConnection:Fe}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsProxy.fallbackSettings")}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.enableFallback")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.enableFallbackDesc")})]}),e.jsx(D,{checked:M.enabled??!0,onCheckedChange:r=>c({fallback:{...M,enabled:r}}),disabled:o||!m})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.autoStartLocal")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.autoStartLocalDesc")})]}),e.jsx(D,{checked:M.auto_start??!1,onCheckedChange:r=>c({fallback:{...M,auto_start:r}}),disabled:o||!m||!M.enabled})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(as,{className:"w-4 h-4"}),s("settingsProxy.advanced")]}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("settingsProxy.debugMode")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settingsProxy.debugModeDesc")})]}),e.jsx(D,{checked:_,onCheckedChange:ve,disabled:o})]}),_&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 pl-0.5",children:s("settingsProxy.debugModeEnabled")})]})]}),!m&&e.jsx(is,{config:t,saving:o,displayLocalPort:xe,setEditedLocalPort:h,onSaveLocalPort:Ke,onSaveConfig:c})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(V,{variant:"outline",size:"sm",onClick:()=>{a(),G(),l(),J(),X()},disabled:g||o||f,className:"w-full",children:[e.jsx(re,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{Cs as default};
|