@kaitranntt/ccs 7.50.0-dev.5 → 7.50.0-dev.7
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/README.md +32 -4
- package/config/base-iflow.settings.json +4 -4
- package/dist/auth/account-context.d.ts +6 -0
- package/dist/auth/account-context.d.ts.map +1 -1
- package/dist/auth/account-context.js +13 -4
- package/dist/auth/account-context.js.map +1 -1
- package/dist/auth/auth-commands.d.ts.map +1 -1
- package/dist/auth/auth-commands.js +3 -0
- package/dist/auth/auth-commands.js.map +1 -1
- package/dist/auth/commands/create-command-env.d.ts +3 -0
- package/dist/auth/commands/create-command-env.d.ts.map +1 -0
- package/dist/auth/commands/create-command-env.js +55 -0
- package/dist/auth/commands/create-command-env.js.map +1 -0
- package/dist/auth/commands/create-command.d.ts.map +1 -1
- package/dist/auth/commands/create-command.js +132 -29
- package/dist/auth/commands/create-command.js.map +1 -1
- package/dist/auth/commands/list-command.d.ts.map +1 -1
- package/dist/auth/commands/list-command.js +2 -0
- package/dist/auth/commands/list-command.js.map +1 -1
- package/dist/auth/commands/types.d.ts +1 -0
- package/dist/auth/commands/types.d.ts.map +1 -1
- package/dist/auth/commands/types.js +22 -0
- package/dist/auth/commands/types.js.map +1 -1
- package/dist/auth/profile-registry.d.ts +1 -0
- package/dist/auth/profile-registry.d.ts.map +1 -1
- package/dist/auth/profile-registry.js +38 -7
- package/dist/auth/profile-registry.js.map +1 -1
- package/dist/cliproxy/config/env-builder.d.ts.map +1 -1
- package/dist/cliproxy/config/env-builder.js +57 -0
- package/dist/cliproxy/config/env-builder.js.map +1 -1
- package/dist/config/migration-manager.d.ts.map +1 -1
- package/dist/config/migration-manager.js +16 -0
- package/dist/config/migration-manager.js.map +1 -1
- package/dist/management/instance-manager.d.ts +1 -0
- package/dist/management/instance-manager.d.ts.map +1 -1
- package/dist/management/instance-manager.js +13 -8
- package/dist/management/instance-manager.js.map +1 -1
- package/dist/management/profile-context-sync-lock.d.ts +14 -0
- package/dist/management/profile-context-sync-lock.d.ts.map +1 -0
- package/dist/management/profile-context-sync-lock.js +174 -0
- package/dist/management/profile-context-sync-lock.js.map +1 -0
- package/dist/management/shared-manager.d.ts +6 -0
- package/dist/management/shared-manager.d.ts.map +1 -1
- package/dist/management/shared-manager.js +46 -6
- package/dist/management/shared-manager.js.map +1 -1
- package/dist/ui/assets/accounts-hMd2X1rs.js +1 -0
- package/dist/ui/assets/{alert-dialog-Cbz7hjbH.js → alert-dialog-DYqj_ln8.js} +1 -1
- package/dist/ui/assets/{api-CtPIBYPJ.js → api-DUB7WunM.js} +1 -1
- package/dist/ui/assets/{auth-section-DDB-gXA-.js → auth-section-BPGGH-pS.js} +1 -1
- package/dist/ui/assets/{backups-section-f3TrZYc_.js → backups-section-taD9idsR.js} +1 -1
- package/dist/ui/assets/{checkbox-DyM_OviW.js → checkbox-C2wWJ45q.js} +1 -1
- package/dist/ui/assets/cliproxy-DQBcXCu5.js +3 -0
- package/dist/ui/assets/{cliproxy-control-panel-D-0qYG1v.js → cliproxy-control-panel-D_JZc88E.js} +1 -1
- package/dist/ui/assets/{confirm-dialog-B1DNTIER.js → confirm-dialog-CQGjNqDg.js} +1 -1
- package/dist/ui/assets/{copilot-CsbHY1RT.js → copilot-C55LbvKL.js} +1 -1
- package/dist/ui/assets/{cursor-Dae1NLqC.js → cursor-DRxLX6HL.js} +1 -1
- package/dist/ui/assets/{droid-BQLHOVuB.js → droid-DlECj4OZ.js} +1 -1
- package/dist/ui/assets/{globalenv-section-DryB5ety.js → globalenv-section-BZl3-nsE.js} +1 -1
- package/dist/ui/assets/{health-DXE1K5e_.js → health-KcXhO7a4.js} +1 -1
- package/dist/ui/assets/{index-BOyrh__4.js → index-BtROiILs.js} +2 -2
- package/dist/ui/assets/{index-BDygjMjY.js → index-Cl4dUJFw.js} +1 -1
- package/dist/ui/assets/{index-BGM7ArZ-.js → index-D7S6Q5bp.js} +1 -1
- package/dist/ui/assets/{index-Dt0OpGYK.js → index-fsXcStKP.js} +1 -1
- package/dist/ui/assets/{index-n1iv9ylt.js → index-mxDT1Fbu.js} +1 -1
- package/dist/ui/assets/{proxy-status-widget-Bvi7eWkI.js → proxy-status-widget-BxkoV1g7.js} +1 -1
- package/dist/ui/assets/{separator-DrB7U5vm.js → separator-lXjk7_Ls.js} +1 -1
- package/dist/ui/assets/{shared-ByrShSly.js → shared-NtPxxEp6.js} +1 -1
- package/dist/ui/assets/{switch-JJlvFHut.js → switch-lf-m6i0R.js} +1 -1
- package/dist/ui/assets/{updates-BUBIr73T.js → updates-Dok03EVa.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/dist/web-server/model-pricing.d.ts.map +1 -1
- package/dist/web-server/model-pricing.js +114 -22
- package/dist/web-server/model-pricing.js.map +1 -1
- package/dist/web-server/routes/account-route-helpers.d.ts +17 -0
- package/dist/web-server/routes/account-route-helpers.d.ts.map +1 -0
- package/dist/web-server/routes/account-route-helpers.js +34 -0
- package/dist/web-server/routes/account-route-helpers.js.map +1 -0
- package/dist/web-server/routes/account-routes.d.ts.map +1 -1
- package/dist/web-server/routes/account-routes.js +36 -27
- package/dist/web-server/routes/account-routes.js.map +1 -1
- package/dist/web-server/routes/config-routes.d.ts.map +1 -1
- package/dist/web-server/routes/config-routes.js +59 -0
- package/dist/web-server/routes/config-routes.js.map +1 -1
- package/package.json +4 -2
- package/scripts/maintainability-check.js +163 -0
- package/dist/ui/assets/accounts-Cv9gdSl_.js +0 -1
- package/dist/ui/assets/cliproxy-nwnHc6Ex.js +0 -3
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execFileSync, spawnSync } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const PROJECT_ROOT = path.resolve(__dirname, '..');
|
|
7
|
+
const BASELINE_FILE = path.join('docs', 'metrics', 'maintainability-baseline.json');
|
|
8
|
+
const BASELINE_SCRIPT = path.join(PROJECT_ROOT, 'scripts', 'maintainability-baseline.js');
|
|
9
|
+
|
|
10
|
+
const PROTECTED_BRANCHES = new Set(['main', 'dev']);
|
|
11
|
+
const HOTFIX_PREFIXES = ['hotfix/', 'kai/hotfix-'];
|
|
12
|
+
|
|
13
|
+
function hasFlag(name) {
|
|
14
|
+
return process.argv.slice(2).includes(name);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function detectBranchName() {
|
|
18
|
+
try {
|
|
19
|
+
return execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
|
|
20
|
+
cwd: PROJECT_ROOT,
|
|
21
|
+
encoding: 'utf8',
|
|
22
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
23
|
+
}).trim();
|
|
24
|
+
} catch {
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isProtectedBranch(branchName) {
|
|
30
|
+
if (!branchName) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (PROTECTED_BRANCHES.has(branchName)) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return HOTFIX_PREFIXES.some(prefix => branchName.startsWith(prefix));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function detectMode() {
|
|
42
|
+
if (hasFlag('--strict')) {
|
|
43
|
+
return 'strict';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (hasFlag('--warn')) {
|
|
47
|
+
return 'warn';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (hasFlag('--off')) {
|
|
51
|
+
return 'off';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const explicitMode = (process.env.CCS_MAINTAINABILITY_MODE || '').toLowerCase().trim();
|
|
55
|
+
if (explicitMode === 'strict' || explicitMode === 'warn' || explicitMode === 'off') {
|
|
56
|
+
return explicitMode;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const eventName = process.env.GITHUB_EVENT_NAME || '';
|
|
60
|
+
if (eventName === 'pull_request' || eventName === 'pull_request_target') {
|
|
61
|
+
return 'warn';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const gitHubRef = process.env.GITHUB_REF || '';
|
|
65
|
+
if (gitHubRef.startsWith('refs/heads/')) {
|
|
66
|
+
const branchFromRef = gitHubRef.slice('refs/heads/'.length);
|
|
67
|
+
if (isProtectedBranch(branchFromRef)) {
|
|
68
|
+
return 'strict';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return isProtectedBranch(detectBranchName()) ? 'strict' : 'warn';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function runBaselineCheck() {
|
|
76
|
+
return spawnSync('node', [BASELINE_SCRIPT, '--check', BASELINE_FILE], {
|
|
77
|
+
cwd: PROJECT_ROOT,
|
|
78
|
+
encoding: 'utf8',
|
|
79
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function writeStreams(result) {
|
|
84
|
+
if (result.stdout) {
|
|
85
|
+
process.stdout.write(result.stdout);
|
|
86
|
+
}
|
|
87
|
+
if (result.stderr) {
|
|
88
|
+
process.stderr.write(result.stderr);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function tryParseJson(stdout) {
|
|
93
|
+
if (!stdout) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
return JSON.parse(stdout);
|
|
99
|
+
} catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function formatViolations(violations) {
|
|
105
|
+
if (!Array.isArray(violations) || violations.length === 0) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return violations.map(violation => {
|
|
110
|
+
if (!violation || typeof violation !== 'object') {
|
|
111
|
+
return '- unknown violation';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const metric = violation.metric || 'unknown';
|
|
115
|
+
const baseline = typeof violation.baseline === 'number' ? violation.baseline : 'n/a';
|
|
116
|
+
const current = typeof violation.current === 'number' ? violation.current : 'n/a';
|
|
117
|
+
return `- ${metric}: baseline=${baseline}, current=${current}`;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function main() {
|
|
122
|
+
const mode = detectMode();
|
|
123
|
+
|
|
124
|
+
if (mode === 'off') {
|
|
125
|
+
console.log('[i] Maintainability gate disabled (mode=off).');
|
|
126
|
+
process.exit(0);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const result = runBaselineCheck();
|
|
130
|
+
if (mode === 'strict') {
|
|
131
|
+
writeStreams(result);
|
|
132
|
+
process.exit(result.status === null ? 1 : result.status);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (result.status === 0) {
|
|
136
|
+
writeStreams(result);
|
|
137
|
+
process.exit(0);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const parsed = tryParseJson(result.stdout);
|
|
141
|
+
const branchName = detectBranchName();
|
|
142
|
+
|
|
143
|
+
console.log('[!] Maintainability regression detected (warning-only mode).');
|
|
144
|
+
if (branchName) {
|
|
145
|
+
console.log(`[i] Branch: ${branchName}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (parsed && Array.isArray(parsed.violations) && parsed.violations.length > 0) {
|
|
149
|
+
console.log('[i] Violations:');
|
|
150
|
+
for (const line of formatViolations(parsed.violations)) {
|
|
151
|
+
console.log(line);
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
writeStreams(result);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
console.log('[i] This is non-blocking on PR/feature branches to support parallel workflow.');
|
|
158
|
+
console.log(
|
|
159
|
+
'[i] Use strict mode when needed: bun run maintainability:check:strict'
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
main();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-DIWAxjEp.js";import{r as x}from"./react-vendor-CNOkPC89.js";import{u as R,a as y,b as v,d as _,f as k,g as F}from"./tanstack-Hn82hibe.js";import{c as p,W as C,b as m,a5 as L,a6 as P,a7 as q,a8 as K,a9 as M,L as j,I as T}from"./index-BOyrh__4.js";import{A as $,a as G,b as E,c as H,d as Q,e as O,f as Z,g as B}from"./alert-dialog-Cbz7hjbH.js";import{t as h}from"./notifications-B2HqRBj7.js";import{w as I,k as b,ah as V,z as U,m as z,a0 as W}from"./icons-D7XDTBCN.js";import{C as J}from"./checkbox-DyM_OviW.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";function X({className:n,...t}){return e.jsx("div",{"data-slot":"table-container",className:"relative w-full overflow-x-auto",children:e.jsx("table",{"data-slot":"table",className:p("w-full caption-bottom text-sm",n),...t})})}function Y({className:n,...t}){return e.jsx("thead",{"data-slot":"table-header",className:p("[&_tr]:border-b",n),...t})}function ee({className:n,...t}){return e.jsx("tbody",{"data-slot":"table-body",className:p("[&_tr:last-child]:border-0",n),...t})}function S({className:n,...t}){return e.jsx("tr",{"data-slot":"table-row",className:p("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",n),...t})}function te({className:n,...t}){return e.jsx("th",{"data-slot":"table-head",className:p("text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",n),...t})}function se({className:n,...t}){return e.jsx("td",{"data-slot":"table-cell",className:p("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",n),...t})}function ae(){return R({queryKey:["accounts"],queryFn:()=>C.accounts.list()})}function ne(){const n=y();return v({mutationFn:t=>C.accounts.setDefault(t),onSuccess:(t,r)=>{n.invalidateQueries({queryKey:["accounts"]}),h.success(`Default account set to "${r}"`)},onError:t=>{h.error(t.message)}})}function re(){const n=y();return v({mutationFn:()=>C.accounts.resetDefault(),onSuccess:()=>{n.invalidateQueries({queryKey:["accounts"]}),h.success("Default account reset to CCS")},onError:t=>{h.error(t.message)}})}function le(){const n=y();return v({mutationFn:t=>C.accounts.delete(t),onSuccess:(t,r)=>{n.invalidateQueries({queryKey:["accounts"]}),h.success(`Account "${r}" deleted`)},onError:t=>{h.error(t.message)}})}function oe({data:n,defaultAccount:t}){const r=ne(),c=le(),l=re(),[i,d]=x.useState(null),g=_({data:n,columns:[{accessorKey:"name",header:"Name",size:200,cell:({row:s})=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:s.original.name}),s.original.name===t&&e.jsx("span",{className:"text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded border border-primary/20",children:"default"})]})},{accessorKey:"type",header:"Type",size:100,cell:({row:s})=>e.jsx("span",{className:"capitalize text-muted-foreground",children:s.original.type||"oauth"})},{accessorKey:"created",header:"Created",size:150,cell:({row:s})=>{const a=new Date(s.original.created);return e.jsx("span",{className:"text-muted-foreground",children:a.toLocaleDateString()})}},{accessorKey:"last_used",header:"Last Used",size:150,cell:({row:s})=>{if(!s.original.last_used)return e.jsx("span",{className:"text-muted-foreground/50",children:"-"});const a=new Date(s.original.last_used);return e.jsx("span",{className:"text-muted-foreground",children:a.toLocaleDateString()})}},{id:"context",header:"Context",size:170,cell:({row:s})=>{if(s.original.type==="cliproxy")return e.jsx("span",{className:"text-muted-foreground/50",children:"-"});if((s.original.context_mode||"isolated")==="shared"){const o=s.original.context_group||"default";return e.jsxs("span",{className:"text-muted-foreground",children:["shared (",o,")"]})}return e.jsx("span",{className:"text-muted-foreground",children:"isolated"})}},{id:"actions",header:"Actions",size:180,cell:({row:s})=>{const a=s.original.name===t,o=r.isPending||c.isPending;return e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(m,{variant:a?"secondary":"default",size:"sm",className:"h-8 px-2",disabled:a||o,onClick:()=>r.mutate(s.original.name),children:[e.jsx(b,{className:`w-3 h-3 mr-1 ${a?"opacity-50":""}`}),a?"Active":"Set Default"]}),e.jsx(m,{variant:"ghost",size:"sm",className:"h-8 px-2 text-destructive hover:text-destructive hover:bg-destructive/10",disabled:a||o,onClick:()=>d(s.original.name),title:a?"Cannot delete default account":"Delete account",children:e.jsx(V,{className:"w-4 h-4"})})]})}}],getCoreRowModel:F()});return n.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:["No accounts found. Use"," ",e.jsx("code",{className:"text-sm bg-muted px-1 rounded",children:"ccs auth create"})," to add accounts."]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"border rounded-md",children:e.jsxs(X,{children:[e.jsx(Y,{children:g.getHeaderGroups().map(s=>e.jsx(S,{children:s.headers.map(a=>{const o={name:"w-[200px]",type:"w-[100px]",created:"w-[150px]",last_used:"w-[150px]",context:"w-[170px]",actions:"w-[180px]"}[a.id]||"w-auto";return e.jsx(te,{className:o,children:a.isPlaceholder?null:k(a.column.columnDef.header,a.getContext())},a.id)})},s.id))}),e.jsx(ee,{children:g.getRowModel().rows.map(s=>e.jsx(S,{children:s.getVisibleCells().map(a=>e.jsx(se,{children:k(a.column.columnDef.cell,a.getContext())},a.id))},s.id))})]})}),t&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(m,{variant:"outline",size:"sm",onClick:()=>l.mutate(),disabled:l.isPending,children:[e.jsx(I,{className:"w-4 h-4 mr-2"}),"Reset to CCS Default"]})})]}),e.jsx($,{open:!!i,onOpenChange:s=>!s&&d(null),children:e.jsxs(G,{children:[e.jsxs(E,{children:[e.jsx(H,{children:"Delete Account"}),e.jsxs(Q,{children:['Are you sure you want to delete the account "',i,'"? This will remove the profile and all its session data. This action cannot be undone.']})]}),e.jsxs(O,{children:[e.jsx(Z,{children:"Cancel"}),e.jsx(B,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>{i&&(c.mutate(i),d(null))},children:"Delete"})]})]})})]})}function ce({open:n,onClose:t}){const[r,c]=x.useState(""),[l,i]=x.useState(!1),[d,N]=x.useState(""),[g,s]=x.useState(!1),a=/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(r),o=d.trim().toLowerCase(),f=o.length===0||/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(o),w=r&&a?[`ccs auth create ${r}`,l?o.length>0?`--context-group ${o}`:"--share-context":""].filter(Boolean).join(" "):"ccs auth create <name>",D=async()=>{!a||l&&!f||(await navigator.clipboard.writeText(w),s(!0),setTimeout(()=>s(!1),2e3))},A=()=>{c(""),i(!1),N(""),s(!1),t()};return e.jsx(L,{open:n,onOpenChange:u=>!u&&A(),children:e.jsxs(P,{className:"sm:max-w-md",children:[e.jsxs(q,{children:[e.jsx(K,{children:"Create New Account"}),e.jsx(M,{children:"Auth profiles require Claude CLI login. Run the command below in your terminal."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"profile-name",children:"Profile Name"}),e.jsx(T,{id:"profile-name",value:r,onChange:u=>c(u.target.value),placeholder:"e.g., work, personal, client",autoComplete:"off"}),r&&!a&&e.jsx("p",{className:"text-xs text-destructive",children:"Name must start with a letter and contain only letters, numbers, dashes, or underscores."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{id:"share-context",checked:l,onCheckedChange:u=>i(u===!0)}),e.jsx(j,{htmlFor:"share-context",className:"cursor-pointer",children:"Share project context with other accounts"})]}),l&&e.jsxs("div",{className:"space-y-2 pl-6",children:[e.jsx(j,{htmlFor:"context-group",children:"Context Group (optional)"}),e.jsx(T,{id:"context-group",value:d,onChange:u=>N(u.target.value),placeholder:"default, sprint-a, client-x",autoComplete:"off"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave empty to use the default shared group."}),d.trim().length>0&&!f&&e.jsx("p",{className:"text-xs text-destructive",children:"Group must start with a letter and use only letters, numbers, dashes, or underscores."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{children:"Command"}),e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted rounded-md font-mono text-sm",children:[e.jsx(U,{className:"w-4 h-4 text-muted-foreground shrink-0"}),e.jsx("code",{className:"flex-1 break-all",children:w}),e.jsx(m,{variant:"ghost",size:"sm",className:"shrink-0 h-8 px-2",onClick:D,disabled:!a||l&&!f,children:g?e.jsx(b,{className:"w-4 h-4 text-green-500"}):e.jsx(z,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[e.jsx("p",{children:"After running the command:"}),e.jsxs("ol",{className:"list-decimal list-inside pl-2 space-y-0.5",children:[e.jsx("li",{children:"Complete the Claude login in your browser"}),e.jsx("li",{children:"Return here and refresh to see the new account"})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(m,{variant:"ghost",onClick:A,children:"Close"}),e.jsx(m,{onClick:D,disabled:!a||l&&!f,children:g?e.jsxs(e.Fragment,{children:[e.jsx(b,{className:"w-4 h-4 mr-2"}),"Copied!"]}):e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-4 h-4 mr-2"}),"Copy Command"]})})]})]})]})})}function Ne(){const{data:n,isLoading:t,refetch:r}=ae(),[c,l]=x.useState(!1);return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-8",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Accounts"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Manage multi-account Claude sessions (profiles.json)"})]}),e.jsxs(m,{onClick:()=>l(!0),children:[e.jsx(W,{className:"w-4 h-4 mr-2"}),"Create Account"]})]}),t?e.jsx("div",{className:"text-muted-foreground",children:"Loading accounts..."}):e.jsx(oe,{data:n?.accounts||[],defaultAccount:n?.default??null,onRefresh:r}),e.jsx(ce,{open:c,onClose:()=>l(!1)})]})}export{Ne as AccountsPage};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-DIWAxjEp.js";import{r}from"./react-vendor-CNOkPC89.js";import{a as Le,u as js,b as Bs}from"./tanstack-Hn82hibe.js";import{b as E,C as vs,a as Ns,c as H,P as we,L as W,I as re,q as Ie,r as Fe,s as Ue,t as Ke,v as he,a1 as bs,a2 as Gs,a3 as $s,a4 as Qs,u as ys,a5 as qe,a6 as He,a7 as Be,a8 as Ge,a9 as ws,aa as as,ab as Vs,ac as zs,ad as Js,ae as ks,W as Ne,B as U,af as Ee,ag as ns,ah as Ws,ai as Ys,aj as Xs,ak as Zs,al as is,am as rs,an as et,w as Cs,m as $e,ao as st,ap as tt,aq as at,l as nt,ar as it,as as rt,at as ot,au as lt,av as ct,aw as dt,ax as oe,T as le,o as ce,p as de,ay as ut,az as mt,aA as xt,aB as os,aC as pt,aD as ht,aE as ft,aF as gt,aG as jt,aH as vt,aI as Nt,O as bt,Q as yt,R as ls,U as cs,aJ as wt,aK as kt,aL as Ct,aM as At,aN as St,aO as Pt,aP as Tt,aQ as Mt,aR as Ot,aS as Et,aT as Rt,S as _t}from"./index-BOyrh__4.js";import{C as Re}from"./default-ports-1QQSffYX.js";import{t as K}from"./notifications-B2HqRBj7.js";import{c as As,L as J,n as me,z as Dt,k as se,m as Ss,ao as Qe,R as Ve,o as xe,a1 as ge,T as ze,$ as Lt,ap as Ps,aq as It,ar as ke,Z as je,I as Ts,g as Ft,a3 as Ms,as as Ut,ai as Kt,X as Je,a0 as Os,t as Es,u as _e,at as qt,q as ds,au as Ht,ah as Rs,r as Bt,av as us,l as Gt,a2 as $t,al as Qt,aw as _s}from"./icons-D7XDTBCN.js";import{R as be,A as ms,D as Pe,i as Vt,a as zt,P as Jt}from"./proxy-status-widget-Bvi7eWkI.js";import{C as ye}from"./checkbox-DyM_OviW.js";import{C as Wt}from"./confirm-dialog-B1DNTIER.js";import{S as We}from"./separator-DrB7U5vm.js";import{S as Ds}from"./switch-JJlvFHut.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-Cbz7hjbH.js";const fe={agy:{provider:"agy",displayName:"Antigravity",defaultModel:"claude-opus-4-6-thinking",models:[{id:"claude-opus-4-6-thinking",name:"Claude Opus 4.6 Thinking",description:"Latest flagship, extended thinking",extendedContext:!1,presetMapping:{default:"claude-opus-4-6-thinking",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-6-thinking",haiku:"claude-sonnet-4-6"}},{id:"claude-opus-4-5-thinking",name:"Claude Opus 4.5 Thinking",description:"Previous flagship, extended thinking",presetMapping:{default:"claude-opus-4-5-thinking",opus:"claude-opus-4-5-thinking",sonnet:"claude-sonnet-4-6-thinking",haiku:"claude-sonnet-4-6"}},{id:"claude-sonnet-4-6-thinking",name:"Claude Sonnet 4.6 Thinking",description:"Latest Sonnet with extended thinking",presetMapping:{default:"claude-sonnet-4-6-thinking",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-6-thinking",haiku:"claude-sonnet-4-6"}},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6",description:"Latest Sonnet baseline",presetMapping:{default:"claude-sonnet-4-6",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-6",haiku:"claude-sonnet-4-6"}},{id:"claude-sonnet-4-5-thinking",name:"Claude Sonnet 4.5 Thinking",description:"Balanced with extended thinking",presetMapping:{default:"claude-sonnet-4-5-thinking",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-5-thinking",haiku:"claude-sonnet-4-5"}},{id:"claude-sonnet-4-5",name:"Claude Sonnet 4.5",description:"Fast and capable",presetMapping:{default:"claude-sonnet-4-5",opus:"claude-opus-4-6-thinking",sonnet:"claude-sonnet-4-5",haiku:"claude-sonnet-4-5"}},{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",description:"Google latest model via Antigravity",extendedContext:!0,presetMapping:{default:"gemini-3-pro-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash",description:"Fast Gemini model via Antigravity",extendedContext:!0,presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}}]},gemini:{provider:"gemini",displayName:"Gemini",defaultModel:"gemini-2.5-pro",models:[{id:"gemini-3-pro-preview",name:"Gemini 3 Pro",tier:"paid",description:"Latest model, requires paid Google account",extendedContext:!0,presetMapping:{default:"gemini-3-pro-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash",tier:"paid",description:"Fast Gemini 3 model, requires paid Google account",extendedContext:!0,presetMapping:{default:"gemini-3-flash-preview",opus:"gemini-3-pro-preview",sonnet:"gemini-3-pro-preview",haiku:"gemini-3-flash-preview"}},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro",description:"Stable, works with free Google account",extendedContext:!0,presetMapping:{default:"gemini-2.5-pro",opus:"gemini-2.5-pro",sonnet:"gemini-2.5-pro",haiku:"gemini-2.5-flash"}}]},codex:{provider:"codex",displayName:"Codex",defaultModel:"gpt-5.3-codex",models:[{id:"gpt-5.3-codex",name:"GPT-5.3 Codex",description:"Supports up to xhigh effort",presetMapping:{default:"gpt-5.3-codex",opus:"gpt-5.3-codex",sonnet:"gpt-5.3-codex",haiku:"gpt-5-mini"}},{id:"gpt-5.2-codex",name:"GPT-5.2 Codex",description:"Previous stable Codex model",presetMapping:{default:"gpt-5.2-codex",opus:"gpt-5.2-codex",sonnet:"gpt-5.2-codex",haiku:"gpt-5-mini"}},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"Fast, capped at high effort (no xhigh)",presetMapping:{default:"gpt-5-mini",opus:"gpt-5.3-codex",sonnet:"gpt-5-mini",haiku:"gpt-5-mini"}},{id:"gpt-5.1-codex-max",name:"Codex Max (5.1)",description:"Legacy most capable Codex model",presetMapping:{default:"gpt-5.1-codex-max",opus:"gpt-5.1-codex-max",sonnet:"gpt-5.1-codex-max",haiku:"gpt-5.1-codex-mini"}},{id:"gpt-5.2",name:"GPT 5.2",description:"Latest GPT model",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.2",haiku:"gpt-5.2"}},{id:"gpt-5.1-codex-mini",name:"Codex Mini",description:"Fast and efficient Codex model"}]},qwen:{provider:"qwen",displayName:"Qwen",defaultModel:"qwen3-coder-plus",models:[{id:"qwen3-coder-plus",name:"Qwen3 Coder Plus",description:"Code-focused model (1M context)",presetMapping:{default:"qwen3-coder-plus",opus:"qwen3-max",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-flash"}},{id:"qwen3-max",name:"Qwen3 Max",description:"Flagship model (256K context)",presetMapping:{default:"qwen3-max",opus:"qwen3-max",sonnet:"qwen3-coder-plus",haiku:"qwen3-coder-flash"}},{id:"qwen3-max-preview",name:"Qwen3 Max Preview",description:"Preview with thinking support (256K)",presetMapping:{default:"qwen3-max-preview",opus:"qwen3-max-preview",sonnet:"qwen3-max",haiku:"qwen3-coder-flash"}},{id:"qwen3-235b",name:"Qwen3 235B",description:"Large 235B A22B model",presetMapping:{default:"qwen3-235b",opus:"qwen3-max",sonnet:"qwen3-235b",haiku:"qwen3-coder-flash"}},{id:"qwen3-vl-plus",name:"Qwen3 VL Plus",description:"Vision-language multimodal"},{id:"qwen3-coder-flash",name:"Qwen3 Coder Flash",description:"Fast code generation"},{id:"qwen3-32b",name:"Qwen3 32B",description:"Qwen3 32B model"}]},iflow:{provider:"iflow",displayName:"iFlow",defaultModel:"iflow-default",models:[{id:"iflow-default",name:"iFlow Default",description:"Default iFlow model"}]},kimi:{provider:"kimi",displayName:"Kimi (Moonshot)",defaultModel:"kimi-k2.5",models:[{id:"kimi-k2.5",name:"Kimi K2.5",description:"Latest multimodal model (262K context)",presetMapping:{default:"kimi-k2.5",opus:"kimi-k2.5",sonnet:"kimi-k2-thinking",haiku:"kimi-k2"}},{id:"kimi-k2-thinking",name:"Kimi K2 Thinking",description:"Extended reasoning model",presetMapping:{default:"kimi-k2-thinking",opus:"kimi-k2.5",sonnet:"kimi-k2-thinking",haiku:"kimi-k2"}},{id:"kimi-k2",name:"Kimi K2",description:"Flagship coding model"}]},kiro:{provider:"kiro",displayName:"Kiro (AWS)",defaultModel:"kiro-claude-sonnet-4-5",models:[{id:"kiro-claude-opus-4-5",name:"Kiro Claude Opus 4.5",description:"Claude Opus 4.5 via Kiro (2.2x credit)",presetMapping:{default:"kiro-claude-opus-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4-5",name:"Kiro Claude Sonnet 4.5",description:"Claude Sonnet 4.5 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4-5",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4-5",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-sonnet-4",name:"Kiro Claude Sonnet 4",description:"Claude Sonnet 4 via Kiro (1.3x credit)",presetMapping:{default:"kiro-claude-sonnet-4",opus:"kiro-claude-opus-4-5",sonnet:"kiro-claude-sonnet-4",haiku:"kiro-claude-haiku-4-5"}},{id:"kiro-claude-haiku-4-5",name:"Kiro Claude Haiku 4.5",description:"Claude Haiku 4.5 via Kiro (0.4x credit)"}]},ghcp:{provider:"ghcp",displayName:"GitHub Copilot (OAuth)",defaultModel:"claude-sonnet-4.5",models:[{id:"claude-opus-4.5",name:"Claude Opus 4.5",description:"Anthropic Claude Opus 4.5 via GitHub Copilot",presetMapping:{default:"claude-opus-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4.5",name:"Claude Sonnet 4.5",description:"Anthropic Claude Sonnet 4.5 via GitHub Copilot",presetMapping:{default:"claude-sonnet-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"}},{id:"claude-sonnet-4",name:"Claude Sonnet 4",description:"Anthropic Claude Sonnet 4 via GitHub Copilot"},{id:"claude-haiku-4.5",name:"Claude Haiku 4.5",description:"Anthropic Claude Haiku 4.5 via GitHub Copilot"},{id:"gpt-5.2",name:"GPT-5.2",description:"OpenAI GPT-5.2 via GitHub Copilot",presetMapping:{default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.1",haiku:"gpt-5-mini"}},{id:"gpt-5.1",name:"GPT-5.1",description:"OpenAI GPT-5.1 via GitHub Copilot"},{id:"gpt-5",name:"GPT-5",description:"OpenAI GPT-5 via GitHub Copilot"},{id:"gpt-5-mini",name:"GPT-5 Mini",description:"OpenAI GPT-5 Mini via GitHub Copilot"},{id:"gemini-3-pro",name:"Gemini 3 Pro",description:"Google Gemini 3 Pro via GitHub Copilot"}]},claude:{provider:"claude",displayName:"Claude (Anthropic)",defaultModel:"claude-sonnet-4-5-20250929",models:[{id:"claude-opus-4-6",name:"Claude Opus 4.6",description:"Latest flagship model",extendedContext:!0,presetMapping:{default:"claude-opus-4-6",opus:"claude-opus-4-6",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-opus-4-5-20251101",name:"Claude Opus 4.5",description:"Most capable Claude model",extendedContext:!0,presetMapping:{default:"claude-opus-4-5-20251101",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-5-20250929",name:"Claude Sonnet 4.5",description:"Balanced performance and speed",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-5-20250929",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-5-20250929",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-sonnet-4-20250514",name:"Claude Sonnet 4",description:"Previous generation Sonnet",extendedContext:!0,presetMapping:{default:"claude-sonnet-4-20250514",opus:"claude-opus-4-5-20251101",sonnet:"claude-sonnet-4-20250514",haiku:"claude-haiku-4-5-20251001"}},{id:"claude-haiku-4-5-20251001",name:"Claude Haiku 4.5",description:"Fast and efficient"}]}},Te="ccs-internal-managed";async function Yt(){try{const s=await fetch("/api/settings/auth/tokens/raw");return s.ok?(await s.json())?.apiKey?.value??Te:Te}catch{return Te}}async function De(s,a){const t=fe[s];if(!t)return{success:!1};const n=t.models[0],i=n?.presetMapping||{default:t.defaultModel,opus:t.defaultModel,sonnet:t.defaultModel,haiku:t.defaultModel},o=await Yt(),c={env:{ANTHROPIC_BASE_URL:`http://127.0.0.1:${Re}/api/provider/${s}`,ANTHROPIC_AUTH_TOKEN:o,ANTHROPIC_MODEL:i.default,ANTHROPIC_DEFAULT_OPUS_MODEL:i.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:i.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:i.haiku}};try{return{success:(await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:c})})).ok,presetName:n?.name||t.defaultModel}}catch{return{success:!1}}}function Xt({currentProgress:s,allSteps:a}){return e.jsx("div",{className:"flex justify-center gap-1 pt-2",children:a.map((t,n)=>e.jsx("div",{className:`w-2 h-2 rounded-full transition-colors ${s>=n?"bg-primary":"bg-muted"}`},t))})}function Zt({providers:s,onSelect:a}){return e.jsx("div",{className:"grid gap-2",children:s.map(t=>e.jsxs("button",{onClick:()=>a(t.id),className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:t.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:t.description})]}),e.jsx(As,{className:"w-4 h-4 text-muted-foreground"})]},t.id))})}function ea({selectedProvider:s,providers:a,authCommand:t,isRefreshing:n,isPending:i,onBack:o,onStartAuth:l,onRefresh:c}){const[j,h]=r.useState(!1),x=async b=>{await navigator.clipboard.writeText(b),h(!0),setTimeout(()=>h(!1),2e3)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Authenticate with ",a.find(b=>b.id===s)?.name," to add an account"]}),e.jsx(E,{onClick:l,disabled:i,className:"w-full gap-2",size:"lg",children:i?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 animate-spin"}),"Authenticating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"w-4 h-4"}),"Authenticate in Browser"]})}),i&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Complete the OAuth flow in your browser..."})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or use terminal"})})]}),e.jsx(vs,{children:e.jsxs(Ns,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Dt,{className:"w-4 h-4"}),"Run this command in your terminal:"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-3 py-2 bg-muted rounded-md font-mono text-sm",children:t}),e.jsx(E,{variant:"outline",size:"icon",onClick:()=>x(t),children:j?e.jsx(se,{className:"w-4 h-4 text-green-500"}):e.jsx(Ss,{className:"w-4 h-4"})})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(E,{variant:"ghost",onClick:o,disabled:i,children:[e.jsx(Qe,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs(E,{variant:"outline",onClick:c,disabled:n||i,children:[e.jsx(Ve,{className:`w-4 h-4 mr-2 ${n?"animate-spin":""}`}),n?"Checking...":"Refresh Status"]})]})]})}function sa({accounts:s,privacyMode:a,onSelect:t,onAddNew:n,onBack:i}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:["Select an account (",s.length,")"]}),e.jsx("div",{className:"grid gap-2 max-h-[320px] overflow-y-auto pr-1",children:s.map(o=>e.jsxs("button",{type:"button",onClick:()=>t(o),className:"flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-muted flex items-center justify-center",children:e.jsx(xe,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("div",{className:H("font-medium",a&&we),children:o.email||o.id}),o.isDefault&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"Default account"})]})]}),e.jsx(As,{className:"w-4 h-4 text-muted-foreground"})]},o.id))}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"Or"})})]}),e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 p-3 border-2 border-dashed border-primary/50 rounded-lg hover:border-primary hover:bg-primary/5 transition-colors text-left",onClick:n,children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(me,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-primary",children:"Add new account"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Authenticate with a different account"})]})]}),e.jsx("div",{className:"flex items-center justify-between pt-2",children:e.jsxs(E,{variant:"ghost",onClick:i,children:[e.jsx(Qe,{className:"w-4 h-4 mr-2"}),"Back"]})})]})}const xs="__custom__";function ta({selectedProvider:s,selectedAccount:a,variantName:t,modelName:n,isPending:i,privacyMode:o,onVariantNameChange:l,onModelChange:c,onBack:j,onSkip:h,onCreate:x}){const b=fe[s]?.models||[],u=n&&!b.some(f=>f.id===n),[v,C]=r.useState(u),m=f=>{f===xs?(C(!0),c("")):(C(!1),c(f))};return e.jsxs("div",{className:"space-y-4",children:[a&&e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/50 rounded-md text-sm",children:[e.jsx(xe,{className:"w-4 h-4"}),e.jsxs("span",{children:["Using:"," ",e.jsx("span",{className:H(o&&we),children:a.email||a.id})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"variant-name",children:"Variant Name *"}),e.jsx(re,{id:"variant-name",value:t,onChange:f=>l(f.target.value),placeholder:"e.g., my-gemini, g3, flash"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Use this name to invoke: ccs ",t||"<name>",' "prompt"']})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{children:"Model"}),v?e.jsxs("div",{className:"space-y-2",children:[e.jsx(re,{value:n,onChange:f=>c(f.target.value),placeholder:"e.g., gemini-2.5-pro, claude-opus-4-5"}),e.jsx("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:()=>C(!1),children:"Choose from presets instead"})]}):e.jsxs(Ie,{value:b.some(f=>f.id===n)?n:"",onValueChange:m,children:[e.jsx(Fe,{children:e.jsx(Ue,{placeholder:"Select a model"})}),e.jsxs(Ke,{children:[b.map(f=>e.jsx(he,{value:f.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:f.name}),f.description&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",f.description]})]})},f.id)),e.jsx(he,{value:xs,children:e.jsx("span",{className:"text-primary",children:"Custom model name..."})})]})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:v?"Enter any model name supported by CLIProxy":`Default: ${fe[s]?.defaultModel||"provider default"}`})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(E,{variant:"ghost",onClick:j,children:[e.jsx(Qe,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{variant:"ghost",onClick:h,children:"Skip"}),e.jsx(E,{onClick:x,disabled:!t||i,children:i?"Creating...":"Create Variant"})]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:"Skip if you just wanted to add an account without creating a variant"})]})}function aa({variantName:s,onClose:a}){return e.jsxs("div",{className:"space-y-4 text-center",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center",children:e.jsx(se,{className:"w-8 h-8 text-green-600 dark:text-green-400"})})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-lg",children:"Variant Created!"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Your custom variant is ready to use"})]}),e.jsx(vs,{children:e.jsxs(Ns,{className:"p-4 space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Usage:"}),e.jsxs("code",{className:"block px-3 py-2 bg-muted rounded-md font-mono text-sm",children:["ccs ",s,' "your prompt here"']})]})}),e.jsx(E,{onClick:a,className:"w-full",children:"Done"})]})}function na({open:s,onClose:a}){const[t,n]=r.useState("provider"),[i,o]=r.useState(""),[l,c]=r.useState(null),[j,h]=r.useState(""),[x,b]=r.useState(""),[u,v]=r.useState(!1),[C,m]=r.useState(!1),{data:f,refetch:p}=bs(),O=Gs(),P=$s(),k=Qs(),{privacyMode:_}=ys(),y=f?.authStatus.find(T=>T.provider===i),R=r.useMemo(()=>y?.accounts||[],[y?.accounts]);r.useEffect(()=>{if(!s){const T=setTimeout(()=>{n("provider"),o(""),c(null),h(""),b(""),m(!1)},0);return()=>clearTimeout(T)}},[s]),r.useEffect(()=>{if(t==="auth"&&R.length>0&&!C){const T=setTimeout(()=>{n("account")},0);return()=>clearTimeout(T)}},[t,R,C]);const N=async()=>{v(!0),await p(),v(!1)},F=()=>{const T=(y?.accounts?.length||0)===0;P.mutate({provider:i},{onSuccess:async M=>{if(T){const I=await De(i);I.success&&I.presetName?K.success(`Applied "${I.presetName}" preset`):I.success||K.warning("Account added, but failed to apply default preset")}M.account&&(c(M.account),n("variant")),p()}})},w=T=>{o(T),(f?.authStatus.find($=>$.provider===T)?.accounts||[]).length===0?n("auth"):n("account")},g=T=>{c(T),n("variant")},A=async()=>{if(!(!j||!i))try{await O.mutateAsync({name:j,provider:i,model:x||void 0,account:l?.id}),n("success")}catch(T){console.error("Failed to create variant:",T)}},L=`ccs ${i} --auth --add`,B=zs(t),G=T=>{if(!T&&(P.isPending&&i&&k.mutate(i),t==="success"||t==="provider")){a();return}};return e.jsx(qe,{open:s,onOpenChange:G,children:e.jsxs(He,{className:"sm:max-w-lg",onPointerDownOutside:T=>{t!=="success"&&t!=="provider"&&T.preventDefault()},onEscapeKeyDown:T=>{(P.isPending||O.isPending)&&T.preventDefault()},children:[e.jsxs(Be,{children:[e.jsxs(Ge,{className:"flex items-center gap-2",children:[e.jsx(ge,{className:"w-5 h-5 text-primary"}),"Quick Setup Wizard"]}),e.jsxs(ws,{children:[t==="provider"&&"Select a provider to get started",t==="auth"&&"Authenticate with your provider",t==="account"&&"Select which account to use",t==="variant"&&"Create your custom variant",t==="success"&&"Setup complete!"]})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[t==="provider"&&e.jsx(Zt,{providers:as,onSelect:w}),t==="auth"&&e.jsx(ea,{selectedProvider:i,providers:as,authCommand:L,isRefreshing:u,isPending:P.isPending,onBack:()=>n("provider"),onStartAuth:F,onRefresh:N}),t==="account"&&e.jsx(sa,{accounts:R,privacyMode:_,onSelect:g,onAddNew:()=>{m(!0),n("auth")},onBack:()=>n("provider")}),t==="variant"&&e.jsx(ta,{selectedProvider:i,selectedAccount:l,variantName:j,modelName:x,isPending:O.isPending,privacyMode:_,onVariantNameChange:h,onModelChange:b,onBack:()=>R.length>0?n("account"):n("provider"),onSkip:a,onCreate:A}),t==="success"&&e.jsx(aa,{variantName:j,onClose:a})]}),e.jsx(Xt,{currentProgress:B,allSteps:Vs})]})})}const ia=3e3,ra=300*1e3;async function Me(s){const a=await s.text();if(!a)return{};try{return JSON.parse(a)}catch{const t=s.status>=400?`Request failed with status ${s.status}`:void 0;return t?{error:t}:{}}}const ie={provider:null,isAuthenticating:!1,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:!1};function oa(){const[s,a]=r.useState(ie),t=r.useRef(null),n=r.useRef(null),i=r.useRef(0),o=r.useRef(!1),l=Le(),c=r.useCallback(()=>{n.current&&(clearInterval(n.current),n.current=null)},[]);r.useEffect(()=>()=>{t.current?.abort(),c(),o.current=!1},[c]);const j=r.useCallback(async(u,v)=>{if(Date.now()-i.current>ra){c(),a(C=>({...C,isAuthenticating:!1,error:"Authentication timed out. Please try again."}));return}try{const m=await(await fetch(`/api/cliproxy/auth/${u}/status?state=${encodeURIComponent(v)}`)).json();if(m.status==="ok")c(),l.invalidateQueries({queryKey:["cliproxy-auth"]}),l.invalidateQueries({queryKey:["account-quota"]}),K.success(`${u} authentication successful`),o.current=!1,a(ie);else if(m.status==="auth_url"){const f=m.url||m.auth_url;f&&(a(p=>({...p,authUrl:f})),o.current||(o.current=!0,window.open(f,"_blank")))}else if(m.status==="device_code"){c();const f=m.user_code&&m.verification_url?`Open ${m.verification_url} and enter code: ${m.user_code}`:"Switch to Device Code method and try again.";K.error("Provider returned Device Code flow in callback mode"),a(p=>({...p,isAuthenticating:!1,error:f}))}else if(m.status==="error"){c();const f=m.error||"Authentication failed";K.error(f),a(p=>({...p,isAuthenticating:!1,error:f}))}}catch{}},[l,c]),h=r.useCallback(async(u,v)=>{if(!Js(u)){a({...ie,error:`Unknown provider: ${u}`});return}t.current?.abort(),c(),o.current=!1;const C=new AbortController;t.current=C;const f=(v?.flowType||(ks(u)?"device_code":"authorization_code"))==="device_code",p=v?.startEndpoint||(f?"start":"start-url"),O={nickname:v?.nickname,kiroMethod:v?.kiroMethod,riskAcknowledgement:v?.riskAcknowledgement};a({provider:u,isAuthenticating:!0,error:null,authUrl:null,oauthState:null,isSubmittingCallback:!1,isDeviceCodeFlow:f});try{if(p==="start")fetch(`/api/cliproxy/auth/${u}/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(O),signal:C.signal}).then(async P=>{const k=await Me(P),_=k.success===!0;if(P.ok&&_)l.invalidateQueries({queryKey:["cliproxy-auth"]}),l.invalidateQueries({queryKey:["account-quota"]}),o.current=!1,a(ie);else{const y=typeof k.error=="string"?k.error:"Authentication failed";K.error(y),a(R=>({...R,isAuthenticating:!1,error:y}))}}).catch(P=>{if(P instanceof Error&&P.name==="AbortError")return;const k=P instanceof Error?P.message:"Authentication failed";K.error(k),a(_=>({..._,isAuthenticating:!1,error:k}))});else{const P=await fetch(`/api/cliproxy/auth/${u}/start-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(O),signal:C.signal}),k=await Me(P),_=k.success===!0;if(!P.ok||!_){const N=typeof k.error=="string"?k.error:"Failed to start OAuth";throw new Error(N)}const y=typeof k.authUrl=="string"?k.authUrl:null,R=typeof k.state=="string"?k.state:null;a(N=>({...N,authUrl:y,oauthState:R})),y&&(o.current=!0,window.open(y,"_blank")),R&&(i.current=Date.now(),n.current=setInterval(()=>{j(u,R)},ia))}}catch(P){if(P instanceof Error&&P.name==="AbortError"){o.current=!1,a(ie);return}const k=P instanceof Error?P.message:"Authentication failed";K.error(k),a(_=>({..._,isAuthenticating:!1,error:k}))}},[j,c,l]),x=r.useCallback(()=>{const u=s.provider;t.current?.abort(),c(),o.current=!1,a(ie),u&&Ne.cliproxy.auth.cancel(u).catch(()=>{})},[s.provider,c]),b=r.useCallback(async u=>{if(s.provider){a(v=>({...v,isSubmittingCallback:!0,error:null}));try{const v=await fetch(`/api/cliproxy/auth/${s.provider}/submit-callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({redirectUrl:u})}),C=await Me(v),m=C.success===!0;if(v.ok&&m)c(),l.invalidateQueries({queryKey:["cliproxy-auth"]}),l.invalidateQueries({queryKey:["account-quota"]}),K.success(`${s.provider} authentication successful`),a(ie);else{const f=typeof C.error=="string"?C.error:"Callback submission failed";throw new Error(f)}}catch(v){const C=v instanceof Error?v.message:"Failed to submit callback";K.error(C),a(m=>({...m,isSubmittingCallback:!1,error:C}))}}},[s.provider,l,c]);return r.useMemo(()=>({...s,startAuth:h,cancelAuth:x,submitCallback:b}),[s,h,x,b])}function Ls({className:s,showAcknowledgement:a=!1,acknowledgementPhrase:t=be,acknowledgementText:n="",onAcknowledgementTextChange:i,disabled:o=!1,showProxySettingsLink:l=!1}){const c="OAuth Account Safety Warning",j="Issue #509 · Gemini + AGY OAuth risk",h=e.jsxs(e.Fragment,{children:["Issue #509 documents suspension/ban reports tied to ",e.jsx("code",{className:"font-mono",children:"ccs agy"})," ","and shared-account usage between ",e.jsx("code",{className:"font-mono",children:"ccs gemini"})," and"," ",e.jsx("code",{className:"font-mono",children:"ccs agy"}),"."]}),x=e.jsx(e.Fragment,{children:"Continue only if you accept full responsibility for OAuth and account-access risk."});return e.jsxs("section",{role:"alert",className:H("relative overflow-hidden rounded-xl border border-amber-500/30 bg-gradient-to-br from-amber-50 via-background to-rose-50/70 shadow-sm dark:from-amber-950/20 dark:to-rose-950/20",s),children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-0.5 bg-gradient-to-r from-amber-500 via-orange-500 to-rose-500"}),e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"mt-0.5 inline-flex h-7 w-7 items-center justify-center rounded-md bg-amber-500/15 text-amber-700 dark:text-amber-400",children:e.jsx(ze,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:c}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j})]})]}),e.jsx(U,{variant:"outline",className:"border-amber-500/40 text-amber-700 dark:text-amber-300",children:"High Risk"})]}),e.jsxs("div",{className:"space-y-2 text-sm leading-relaxed",children:[e.jsx("p",{children:h}),e.jsx("p",{className:"font-medium text-amber-900 dark:text-amber-200",children:x}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"CCS is provided as-is and does not take responsibility for suspension, bans, or access loss from upstream providers."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 rounded-md border border-amber-500/30 bg-amber-500/10 px-2.5 py-1 text-xs font-medium text-amber-800 transition-colors hover:bg-amber-500/15 dark:text-amber-200",children:["Read issue #509",e.jsx(me,{className:"h-3.5 w-3.5"})]}),l&&e.jsxs("a",{href:"/settings?tab=proxy",className:"inline-flex items-center gap-1.5 rounded-md border border-amber-500/30 bg-amber-500/10 px-2.5 py-1 text-xs font-medium text-amber-800 transition-colors hover:bg-amber-500/15 dark:text-amber-200",children:[e.jsx(Lt,{className:"h-3.5 w-3.5"}),"Gemini + AGY controls: Settings > Proxy"]}),e.jsx("span",{className:"rounded-md border border-border/70 bg-muted/60 px-2.5 py-1 text-xs text-muted-foreground",children:"Applies to CLI and dashboard auth"})]}),a&&i&&e.jsxs("div",{className:"rounded-lg border border-amber-500/25 bg-amber-500/5 p-2.5",children:[e.jsxs(W,{htmlFor:"account-risk-ack-text",className:"text-xs leading-5",children:["Type exact phrase to continue:"," ",e.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono",children:t})]}),e.jsx(re,{id:"account-risk-ack-text",value:n,onChange:C=>i(C.target.value),placeholder:t,disabled:o,className:"mt-2 font-mono text-xs"})]})]})]})}function la({className:s,value:a,onChange:t,disabled:n=!1}){const i=[a.reviewedIssue509,a.understandsBanRisk,a.acceptsFullResponsibility,a.typedPhrase.trim().replace(/\s+/g," ").toUpperCase()===ms].filter(Boolean).length,o=i/4*100,l=c=>{t({...a,...c})};return e.jsxs("section",{role:"alert",className:H("relative overflow-hidden rounded-xl border border-rose-500/35 bg-gradient-to-br from-rose-50 via-background to-amber-50/70 p-4 shadow-sm dark:from-rose-950/20 dark:to-amber-950/20",s),children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-0.5 bg-gradient-to-r from-rose-500 via-orange-500 to-amber-500"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"mt-0.5 inline-flex h-7 w-7 items-center justify-center rounded-md bg-rose-500/15 text-rose-700 dark:text-rose-300",children:e.jsx(ze,{className:"h-4 w-4"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold leading-5",children:"Antigravity OAuth Responsibility"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Complete all 4 steps before you can authenticate."})]})]}),e.jsx(U,{variant:"outline",className:"border-rose-500/40 text-rose-700 dark:text-rose-300",children:"Mandatory"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"Completion"}),e.jsxs("span",{children:[i,"/4 steps"]})]}),e.jsx(Ee,{value:o,className:"h-2"})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/20 bg-rose-500/5 p-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ye,{id:"agy-step-reviewed-issue",checked:a.reviewedIssue509,onCheckedChange:c=>l({reviewedIssue509:!!c}),disabled:n}),e.jsx(W,{htmlFor:"agy-step-reviewed-issue",className:"text-xs leading-5",children:"Step 1: I reviewed issue #509 and understand AGY OAuth can trigger account bans/suspensions."})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ye,{id:"agy-step-understands-risk",checked:a.understandsBanRisk,onCheckedChange:c=>l({understandsBanRisk:!!c}),disabled:n}),e.jsx(W,{htmlFor:"agy-step-understands-risk",className:"text-xs leading-5",children:"Step 2: I understand this OAuth action is my own decision and I accept the upstream risk."})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ye,{id:"agy-step-accept-responsibility",checked:a.acceptsFullResponsibility,onCheckedChange:c=>l({acceptsFullResponsibility:!!c}),disabled:n}),e.jsx(W,{htmlFor:"agy-step-accept-responsibility",className:"text-xs leading-5",children:"Step 3: I accept full responsibility. CCS is not liable for suspension, bans, or access loss."})]})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-amber-500/25 bg-amber-500/5 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-200",children:[e.jsx(Ps,{className:"h-3.5 w-3.5"}),"Step 4: Type exact phrase to continue"]}),e.jsx(re,{value:a.typedPhrase,onChange:c=>l({typedPhrase:c.target.value}),placeholder:ms,disabled:n,className:"font-mono text-xs"})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 rounded-md border border-rose-500/30 bg-rose-500/10 px-2.5 py-1 font-medium text-rose-800 transition-colors hover:bg-rose-500/15 dark:text-rose-200",children:["Read issue #509",e.jsx(me,{className:"h-3.5 w-3.5"})]})})]})]})}function ca(s){return s.trim().replace(/\s+/g," ").toUpperCase()}function da({open:s,onClose:a,provider:t,displayName:n,isFirstAccount:i=!1}){const[o,l]=r.useState(""),[c,j]=r.useState(""),[h,x]=r.useState(!1),[b,u]=r.useState(null),[v,C]=r.useState(""),[m,f]=r.useState(Pe),[p,O]=r.useState(!1),[P,k]=r.useState(!1),[_,y]=r.useState(ns),R=r.useRef(!1),N=oa(),F=Ws(),w=t==="kiro",g=t==="gemini",A=t==="agy"&&!p,L=t==="agy"&&P,B=Vt(m),G=ca(v)===be,T=ks(t),M=Ys(t),I=Xs(_),$=w?I.flowType==="device_code":T,Q=N.isAuthenticating||F.isPending,Y=o.trim(),X=b||N.error,d=r.useCallback(async()=>{const S=await fetch("/api/settings/auth/antigravity-risk");if(!S.ok)throw new Error("Failed to load Antigravity power user setting");return(await S.json()).antigravityAckBypass===!0},[]),D=()=>{l(""),j(""),x(!1),u(null),C(""),f(Pe),O(!1),k(!1),y(ns),R.current=!1,a()};r.useEffect(()=>{s&&(C(""),f(Pe),u(null))},[t,s]),r.useEffect(()=>{let S=!1;if(!s||t!=="agy"){O(!1),k(!1);return}return(async()=>{try{k(!0);const ee=await d();S||O(ee)}catch{S||O(!1)}finally{S||k(!1)}})(),()=>{S=!0}},[d,s,t]),r.useEffect(()=>{if(!s||t!=="agy"||!N.error||!p)return;const S=N.error.toLowerCase();if(!(S.includes("agy_risk_ack_required")||S.includes("responsibility acknowledgement")||S.includes("responsibility checklist")))return;let ee=!1;return(async()=>{try{k(!0);const ve=await d();if(ee)return;O(ve),ve||u("Power user mode is off. Complete the AGY checklist and retry.")}catch{if(ee)return;O(!1),u("Power user mode is off. Complete the AGY checklist and retry.")}finally{ee||k(!1)}})(),()=>{ee=!0}},[p,N.error,d,s,t]),r.useEffect(()=>{!N.isAuthenticating&&!N.error&&N.provider===null&&s&&R.current&&(R.current=!1,(async()=>{try{const te=await De(t);te.success&&te.presetName&&i&&K.success(`Applied "${te.presetName}" preset`)}catch{}D()})())},[N.isAuthenticating,N.error,N.provider]);const V=()=>{N.cancelAuth(),D()},Z=async()=>{N.authUrl&&(await navigator.clipboard.writeText(N.authUrl),x(!0),setTimeout(()=>x(!1),2e3))},pe=()=>{c.trim()&&N.submitCallback(c.trim())},Ce=()=>{if(L){u("Loading Antigravity safety settings. Please wait a moment and retry.");return}if(A&&!B){u("Complete all Antigravity responsibility steps before authenticating this provider.");return}if(g&&!G){u(`Type "${be}" to acknowledge the account safety warning before authenticating this provider.`);return}if(M&&!Y){u(`Nickname is required for ${n} accounts.`);return}u(null),R.current=!0,N.startAuth(t,{nickname:Y||void 0,kiroMethod:w?_:void 0,flowType:w?I.flowType:void 0,startEndpoint:w?I.startEndpoint:void 0,riskAcknowledgement:A?{version:zt,reviewedIssue509:m.reviewedIssue509,understandsBanRisk:m.understandsBanRisk,acceptsFullResponsibility:m.acceptsFullResponsibility,typedPhrase:m.typedPhrase}:void 0})},Ae=()=>{R.current=!0,F.mutate(void 0,{onSuccess:async()=>{const S=await De("kiro");S.success&&S.presetName&&i&&K.success(`Applied "${S.presetName}" preset`),D()}})},Se=S=>{S||V()},z=N.isAuthenticating;return e.jsx(qe,{open:s,onOpenChange:Se,children:e.jsxs(He,{className:"sm:max-w-md",onInteractOutside:S=>{z&&S.preventDefault()},children:[e.jsxs(Be,{children:[e.jsxs(Ge,{children:["Add ",n," Account"]}),e.jsx(ws,{children:w?"Choose a Kiro auth method, then authenticate via browser or import from Kiro IDE.":$?"Click Authenticate. A verification code will appear for you to enter on the provider website.":"Click Authenticate to get an OAuth URL. Open it in any browser to sign in."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[A&&!z&&e.jsx(la,{value:m,onChange:S=>{f(S),u(null)},disabled:Q}),t==="agy"&&p&&!z&&e.jsxs("div",{className:"rounded-lg border border-amber-400/35 bg-amber-50/70 p-3 text-xs text-amber-900 dark:border-amber-800/60 dark:bg-amber-950/25 dark:text-amber-100",children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5 font-semibold",children:[e.jsx(Ps,{className:"h-3.5 w-3.5"}),"Power user mode enabled"]}),"AGY responsibility checklist is skipped from Settings ",">"," Proxy. You accept full responsibility for OAuth/account risk."]}),g&&!z&&e.jsx(Ls,{showAcknowledgement:!0,acknowledgementPhrase:be,acknowledgementText:v,onAcknowledgementTextChange:S=>{C(S),u(null)},disabled:Q}),w&&!z&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"kiro-auth-method",children:"Auth Method"}),e.jsxs(Ie,{value:_,onValueChange:S=>{y(S),u(null)},children:[e.jsx(Fe,{id:"kiro-auth-method",children:e.jsx(Ue,{placeholder:"Select Kiro auth method"})}),e.jsx(Ke,{children:Zs.map(S=>e.jsx(he,{value:S.id,children:S.label},S.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:I.description})]}),!z&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"nickname",children:M?"Nickname (required)":"Nickname (optional)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(re,{id:"nickname",value:o,onChange:S=>{l(S.target.value),u(null)},placeholder:"e.g., work, personal",disabled:Q,className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:M?"Required for this provider. Use a unique friendly name (e.g., work, personal).":"A friendly name to identify this account. Auto-generated from email if left empty."})]}),z&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx(J,{className:"w-4 h-4 inline mr-2 animate-spin"}),"Waiting for authentication..."]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:N.isDeviceCodeFlow?"A verification code dialog will appear shortly. Enter the code on the provider website.":"Complete the authentication in your browser. This dialog closes automatically."})]}),N.authUrl&&!N.isDeviceCodeFlow&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{className:"text-xs",children:"Open this URL in any browser to sign in:"}),e.jsxs("div",{className:"p-3 bg-muted rounded-md",children:[e.jsx("p",{className:"text-xs text-muted-foreground break-all font-mono line-clamp-3",children:N.authUrl}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(E,{variant:"outline",size:"sm",onClick:Z,children:h?e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"w-3 h-3 mr-1"}),"Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ss,{className:"w-3 h-3 mr-1"}),"Copy"]})}),e.jsxs(E,{variant:"outline",size:"sm",onClick:()=>{if(!N.authUrl)return;const S=window.open(N.authUrl,"_blank");(!S||S.closed||typeof S.closed>"u")&&K.warning("Popup blocked. Copy the URL above and open it manually in your browser.",{duration:5e3})},children:[e.jsx(me,{className:"w-3 h-3 mr-1"}),"Open"]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"callback-url",className:"text-xs",children:"Redirect didn't work? Paste the callback URL:"}),e.jsx(re,{id:"callback-url",value:c,onChange:S=>j(S.target.value),placeholder:"Paste the redirect URL here...",className:"font-mono text-xs"}),e.jsx(E,{variant:"secondary",size:"sm",onClick:pe,disabled:!c.trim()||N.isSubmittingCallback,children:N.isSubmittingCallback?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-3 h-3 mr-1 animate-spin"}),"Submitting..."]}):"Submit Callback"})]})]}),!N.authUrl&&!N.isDeviceCodeFlow&&e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:"Preparing sign-in URL..."})]}),X&&e.jsx("p",{className:"text-xs text-center text-destructive",children:X}),F.isPending&&e.jsxs("p",{className:"text-sm text-center text-muted-foreground",children:[e.jsx(J,{className:"w-4 h-4 inline mr-2 animate-spin"}),"Importing token from Kiro IDE..."]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx(E,{variant:"ghost",onClick:V,children:"Cancel"}),w&&!z&&e.jsx(E,{variant:"outline",onClick:Ae,disabled:Q,children:F.isPending?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 mr-2 animate-spin"}),"Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(It,{className:"w-4 h-4 mr-2"}),"Import from IDE"]})}),!z&&e.jsxs(E,{onClick:Ce,disabled:Q||L||M&&!Y||A&&!B||g&&!G,children:[e.jsx(me,{className:"w-4 h-4 mr-2"}),"Authenticate"]})]})]})]})})}const Ye="[1m]";function ua(s){return s.toLowerCase().startsWith("gemini-")}function Xe(s){return s.toLowerCase().endsWith(Ye.toLowerCase())}function ma(s){return!s||Xe(s)?s:`${s}${Ye}`}function Is(s){return s&&(Xe(s)?s.slice(0,-Ye.length):s)}const ps=["ANTHROPIC_MODEL"],xa=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function pa(s){const a=s?.env||{};return xa.filter(t=>!a[t]?.trim())}function ha(s){const[a,t]=r.useState(null),[n,i]=r.useState(!1),o=Le(),{data:l,isLoading:c,refetch:j}=js({queryKey:["settings",s],queryFn:async()=>{const w=await fetch(`/api/settings/${s}/raw`);return w.ok?w.json():{profile:s,settings:{env:{}},mtime:Date.now(),path:`~/.ccs/profiles/${s}/settings.json`}}}),h=l?.settings,x=r.useMemo(()=>a!==null?a:h?JSON.stringify(h,null,2):`{
|
|
2
|
-
"env": {}
|
|
3
|
-
}`,[a,h]),b=r.useCallback(w=>{t(w)},[]),u=r.useMemo(()=>{try{return JSON.parse(x)}catch{return h||{env:{}}}},[x,h]),v=u?.env?.ANTHROPIC_MODEL,C=u?.env?.ANTHROPIC_DEFAULT_OPUS_MODEL,m=u?.env?.ANTHROPIC_DEFAULT_SONNET_MODEL,f=u?.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL,p=r.useMemo(()=>{const w=u?.env||{};return ps.some(g=>{const A=w[g];return A&&Xe(A)})},[u]),O=r.useCallback((w,g)=>{const A={...u?.env||{},[w]:g},L={...u,env:A};t(JSON.stringify(L,null,2))},[u]),P=r.useCallback(w=>{const g=u?.env||{},A={};for(const G of ps){const T=g[G];T&&(A[G]=w?ma(T):Is(T))}const L={...g,...A};delete L.CCS_EXTENDED_CONTEXT;const B={...u,env:L};t(JSON.stringify(B,null,2))},[u]),k=r.useCallback(w=>{const g={...u?.env||{},...w},A={...u,env:g};t(JSON.stringify(A,null,2))},[u]),_=r.useMemo(()=>{try{return JSON.parse(x),!0}catch{return!1}},[x]),y=r.useMemo(()=>a===null?!1:a!==JSON.stringify(h,null,2),[a,h]),R=r.useMemo(()=>pa(u),[u]),N=Bs({mutationFn:async()=>{const w=JSON.parse(x),g=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:w,expectedMtime:l?.mtime})});if(g.status===409)throw new Error("CONFLICT");if(!g.ok)throw new Error("Failed to save");return g.json()},onSuccess:w=>{o.invalidateQueries({queryKey:["settings",s]}),t(null),w?.warning?K.success("Settings saved",{description:w.warning}):K.success("Settings saved")},onError:w=>{w.message==="CONFLICT"?i(!0):K.error(w.message)}}),F=async w=>{i(!1),w?(await j(),N.mutate()):t(null)};return{data:l,isLoading:c,refetch:j,rawJsonContent:x,rawJsonEdits:a,isRawJsonValid:_,hasChanges:y,currentSettings:u,currentModel:v,opusModel:C,sonnetModel:m,haikuModel:f,extendedContextEnabled:p,toggleExtendedContext:P,handleRawJsonChange:b,updateEnvValue:O,updateEnvValues:k,saveMutation:{mutate:()=>N.mutate(),isPending:N.isPending},conflictDialog:n,setConflictDialog:i,handleConflictResolve:F,missingRequiredFields:R}}const fa=/-(medium|high|xhigh)$/i;function ga(s){if(!s)return;const a=s.trim().match(fa);if(a?.[1])return a[1].toLowerCase()}function Oe(s){if(!s)return null;const a=ga(s);return a?{label:`Pinned ${a}`,explicit:!0}:{label:"Auto effort",explicit:!1}}function ne({label:s,description:a,value:t,onChange:n,catalog:i,allModels:o,disabled:l}){const c=new Set(i?.models.map(x=>x.id)||[]),j=i?.provider==="codex",h=j?Oe(t):null;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:s}),a&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:a})]}),e.jsxs(Ie,{value:t||"",onValueChange:n,disabled:l,children:[e.jsx(Fe,{className:"h-9",children:e.jsx(Ue,{placeholder:"Select model",children:t&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:t}),h&&e.jsx(U,{variant:h.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:h.label})]})})}),e.jsxs(Ke,{className:"max-h-[300px]",children:[i&&i.models.length>0&&e.jsxs(is,{children:[e.jsx(rs,{className:"text-xs text-primary",children:"Recommended"}),i.models.map(x=>{const b=j?Oe(x.id):null;return e.jsx(he,{value:x.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:x.id}),x.tier==="paid"&&e.jsx(U,{variant:"outline",className:"text-[9px] h-4 px-1",children:"PAID"}),b&&e.jsx(U,{variant:b.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:b.label}),t===x.id&&e.jsx(se,{className:"w-3 h-3 text-primary ml-auto"})]})},x.id)})]}),o.length>0&&e.jsxs(is,{children:[e.jsxs(rs,{className:"text-xs text-muted-foreground",children:["All Models (",o.length,")"]}),o.filter(x=>!c.has(x.id)).map(x=>{const b=j?Oe(x.id):null;return e.jsx(he,{value:x.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:x.id}),b&&e.jsx(U,{variant:b.explicit?"secondary":"outline",className:"text-[9px] h-4 px-1 uppercase",children:b.label}),t===x.id&&e.jsx(se,{className:"w-3 h-3 text-primary ml-auto"})]})},x.id)})]}),(!i||i.models.length===0)&&o.length===0&&e.jsx("div",{className:"py-2 px-3 text-xs text-muted-foreground",children:"No models available"})]})]})]})}function ja({open:s,onClose:a,currentValues:t,onApply:n,onSave:i,isSaving:o,catalog:l,allModels:c}){const[j,h]=r.useState(t),[x,b]=r.useState(""),u=v=>{v?(h(t),b("")):a()};return e.jsx(qe,{open:s,onOpenChange:u,children:e.jsxs(He,{className:"sm:max-w-md",children:[e.jsx(Be,{children:e.jsxs(Ge,{className:"flex items-center gap-2",children:[e.jsx(ge,{className:"w-4 h-4"}),"Custom Preset"]})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"preset-name",children:"Preset Name (optional)"}),e.jsx(re,{id:"preset-name",value:x,onChange:v=>b(v.target.value),placeholder:"e.g., My Custom Config",className:"text-sm"})]}),e.jsx(We,{}),l?.provider==="codex"&&e.jsxs("p",{className:"text-[11px] text-muted-foreground rounded-md border bg-muted/30 px-2.5 py-2",children:["Codex tip: suffixes ",e.jsx("code",{children:"-medium"}),", ",e.jsx("code",{children:"-high"}),", and ",e.jsx("code",{children:"-xhigh"})," ","pin effort. Unsuffixed models use Thinking settings."]}),e.jsx(ne,{label:"Default Model",description:"Used when no specific tier is requested",value:j.default,onChange:v=>h({...j,default:v}),catalog:l,allModels:c}),e.jsx(ne,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:j.opus,onChange:v=>h({...j,opus:v}),catalog:l,allModels:c}),e.jsx(ne,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:j.sonnet,onChange:v=>h({...j,sonnet:v}),catalog:l,allModels:c}),e.jsx(ne,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:j.haiku,onChange:v=>h({...j,haiku:v}),catalog:l,allModels:c})]}),e.jsxs(et,{className:"gap-2 sm:gap-0",children:[e.jsx(E,{variant:"outline",onClick:a,children:"Cancel"}),i&&e.jsxs(E,{variant:"secondary",onClick:()=>i(j,x||void 0),disabled:o||!x.trim(),children:[o?e.jsx(J,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(ke,{className:"w-4 h-4 mr-1"}),"Save Preset"]}),e.jsxs(E,{onClick:()=>n(j,x||void 0),children:[e.jsx(je,{className:"w-4 h-4 mr-1"}),"Apply Preset"]})]})]})})}function ue({label:s,command:a}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:s}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:a}),e.jsx(Cs,{value:a,size:"icon",className:"h-6 w-6"})]})]})}function va({provider:s,displayName:a,defaultTarget:t,data:n,authStatus:i}){const o=t||"claude",l=o==="droid";return e.jsx($e,{className:"h-full",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[e.jsx(Ts,{className:"w-4 h-4"}),"Provider Information"]}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Provider"}),e.jsx("span",{className:"font-mono",children:a})]}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"File Path"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:n.path}),e.jsx(Cs,{value:n.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Last Modified"}),e.jsx("span",{className:"text-xs",children:new Date(n.mtime).toLocaleString()})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Status"}),i.authenticated?e.jsxs(U,{variant:"outline",className:"w-fit text-green-600 border-green-200 bg-green-50",children:[e.jsx(Ft,{className:"w-3 h-3 mr-1"}),"Authenticated"]}):e.jsx(U,{variant:"outline",className:"w-fit text-muted-foreground",children:"Not connected"})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Default Target"}),e.jsx("span",{className:"font-mono",children:o})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Quick Usage"}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsx(ue,{label:"Run with prompt",command:`ccs ${s} "your prompt"`}),e.jsx(ue,{label:l?"Droid alias (explicit)":"Run on Droid",command:l?`ccsd ${s} "your prompt"`:`ccs ${s} --target droid "your prompt"`}),e.jsx(ue,{label:l?"Override to Claude":"Override target",command:`ccs ${s} --target claude "your prompt"`}),e.jsx(ue,{label:"Change model",command:`ccs ${s} --config`}),e.jsx(ue,{label:"Add account",command:`ccs ${s} --add`}),e.jsx(ue,{label:"List accounts",command:`ccs ${s} --accounts`})]})]})]})})}const Na={sm:{container:"w-6 h-6",icon:"w-4 h-4",text:"text-xs"},md:{container:"w-8 h-8",icon:"w-5 h-5",text:"text-sm"},lg:{container:"w-12 h-12",icon:"w-8 h-8",text:"text-lg"}};function Ze({provider:s,className:a,size:t="md"}){const n=st(s),i=Na[t],o=tt(s);return e.jsx("div",{className:H("flex items-center justify-center rounded-md",o&&(at(s)?"bg-gray-900 p-1":"bg-white p-1"),i.container,a),children:o?e.jsx("img",{src:o,alt:`${s} logo`,className:H(i.icon,"object-contain")}):e.jsx("span",{className:H("font-semibold",n.textClass,i.text),children:n.letter})})}function ba({displayName:s,logoProvider:a,provider:t,data:n,isLoading:i,hasChanges:o,isRawJsonValid:l,isSaving:c,isRemoteMode:j,port:h,onRefetch:x,onSave:b}){return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ze,{provider:a||t,size:"lg"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s}),j&&e.jsxs(U,{variant:"secondary",className:"text-xs gap-1 bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",children:[e.jsx(Ms,{className:"w-3 h-3"}),"Remote"]}),h&&e.jsxs(U,{variant:"outline",className:"text-xs gap-1 font-mono",children:[e.jsx(Ut,{className:"w-3 h-3"}),":",h]}),!j&&n?.path&&e.jsx(U,{variant:"outline",className:"text-xs",children:n.path.replace(/^.*[\\/]/,"")})]}),j?e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400 mt-0.5",children:"Traffic auto-routed to remote server"}):n&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(n.mtime).toLocaleString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{variant:"ghost",size:"sm",onClick:x,disabled:i,children:e.jsx(Ve,{className:`w-4 h-4 ${i?"animate-spin":""}`})}),e.jsx(E,{size:"sm",onClick:b,disabled:c||!o||!l,children:c?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Kt,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function ya({model:s,provider:a,enabled:t,onToggle:n,disabled:i,className:o}){if(!s?.extendedContext)return null;const l=ua(s.id);return e.jsxs("div",{className:H("rounded-lg border p-3 space-y-2",t?"border-primary/50 bg-primary/5":"border-border bg-muted/30",o),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(je,{className:H("w-4 h-4",t?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:"text-sm font-medium",children:"Extended Context"}),e.jsx(U,{variant:t?"default":"secondary",className:"text-[10px] h-5 px-1.5",children:"1M tokens"})]}),e.jsx(Ds,{checked:t,onCheckedChange:n,disabled:i})]}),e.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted-foreground",children:[e.jsx(Ts,{className:"w-3.5 h-3.5 mt-0.5 shrink-0"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{children:"Enables 1M token context window instead of default 200K."}),e.jsx("p",{className:"text-[10px]",children:l?e.jsxs("span",{className:"text-primary",children:["Auto-enabled for ",a," Gemini models"]}):e.jsxs("span",{children:["Opt-in for ",a," Claude models via --1m flag"]})}),t&&e.jsx("p",{className:"text-amber-600 dark:text-amber-500",children:"Note: 2x input pricing applies for tokens beyond 200K"})]})]})]})}function wa({catalog:s,savedPresets:a,currentModel:t,opusModel:n,sonnetModel:i,haikuModel:o,providerModels:l,provider:c,extendedContextEnabled:j,onExtendedContextToggle:h,onApplyPreset:x,onUpdateEnvValue:b,onOpenCustomPreset:u,onDeletePreset:v,isDeletePending:C}){const m=s&&s.models.length>0||a.length>0,f=r.useMemo(()=>{if(!s||!t)return;const p=Is(t);return s.models.find(O=>O.id===p)},[s,t]);return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(ge,{className:"w-4 h-4"}),"Presets"]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"Apply pre-configured model mappings"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[s?.models.slice(0,4).map(p=>e.jsxs(E,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>{const O=p.presetMapping||{default:p.id,opus:p.id,sonnet:p.id,haiku:p.id};x({ANTHROPIC_MODEL:O.default,ANTHROPIC_DEFAULT_OPUS_MODEL:O.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:O.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:O.haiku})},children:[e.jsx(je,{className:"w-3 h-3"}),p.name]},p.id)),a.map(p=>e.jsxs("div",{className:"group relative",children:[e.jsxs(E,{variant:"secondary",size:"sm",className:"text-xs h-7 gap-1 pr-6",onClick:()=>{x({ANTHROPIC_MODEL:p.default,ANTHROPIC_DEFAULT_OPUS_MODEL:p.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:p.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:p.haiku})},children:[e.jsx(ke,{className:"w-3 h-3 fill-current"}),p.name]}),e.jsx(E,{variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-7 w-5 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:O=>{O.stopPropagation(),v(p.name)},disabled:C,children:e.jsx(Je,{className:"w-3 h-3"})})]},p.name)),e.jsxs(E,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1 border-primary/50 text-primary hover:bg-primary/10 hover:border-primary",onClick:u,children:[e.jsx(Os,{className:"w-3 h-3"}),"Custom"]})]})]}),e.jsx(We,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-2",children:"Model Mapping"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Configure which models to use for each tier"}),c==="codex"&&e.jsxs("p",{className:"text-[11px] text-muted-foreground mb-3 rounded-md border bg-muted/30 px-2.5 py-2",children:["Codex tip: suffixes ",e.jsx("code",{children:"-medium"}),", ",e.jsx("code",{children:"-high"}),", and ",e.jsx("code",{children:"-xhigh"})," ","pin reasoning effort. Unsuffixed models use Thinking settings."]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(ne,{label:"Default Model",description:"Used when no specific tier is requested",value:t,onChange:p=>b("ANTHROPIC_MODEL",p),catalog:s,allModels:l}),f?.extendedContext&&h&&e.jsx(ya,{model:f,provider:c,enabled:j??!1,onToggle:h}),e.jsx(ne,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:n,onChange:p=>b("ANTHROPIC_DEFAULT_OPUS_MODEL",p),catalog:s,allModels:l}),e.jsx(ne,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:i,onChange:p=>b("ANTHROPIC_DEFAULT_SONNET_MODEL",p),catalog:s,allModels:l}),e.jsx(ne,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:o,onChange:p=>b("ANTHROPIC_DEFAULT_HAIKU_MODEL",p),catalog:s,allModels:l})]})]})]})}function hs(s){const a=Math.max(0,Math.min(100,s));return a<=20?"bg-destructive":a<=50?"bg-yellow-500":"bg-green-500"}function fs(s){if(!s)return"";try{const a=new Date(s),n=new Date().getTime()-a.getTime();if(n<0)return"just now";const i=Math.floor(n/(1e3*60)),o=Math.floor(n/(1e3*60*60)),l=Math.floor(n/(1e3*60*60*24));return l>0?`${l}d ago`:o>0?`${o}h ago`:i>0?`${i}m ago`:"just now"}catch{return""}}function ka(s){if(!s)return!1;try{const a=new Date(s);return new Date().getTime()-a.getTime()<3600*1e3}catch{return!1}}function Ca({account:s,onSetDefault:a,onRemove:t,onPauseToggle:n,isRemoving:i,isPausingAccount:o,privacyMode:l,showQuota:c,selectable:j,selected:h,onSelectChange:x}){const b=s.provider.toLowerCase(),u=b==="codex",v=b==="claude"||b==="anthropic",{data:C}=nt(c),{data:m,isLoading:f}=it(b,s.id,c),p=C?.accountStats?.[s.email||s.id]?.lastUsedAt,O=ka(p),P=rt(s.provider,m),k=ot(s.provider,m),_=u&&m&<(m)?ct(m.windows):null,y=[{label:"5h",value:_?.fiveHourWindow?.remainingPercent??null},{label:"Weekly",value:_?.weeklyWindow?.remainingPercent??null}].filter(g=>g.value!==null),R=v&&m&&dt(m)?[{label:"5h",value:m.coreUsage?.fiveHour?.remainingPercent??m.windows.find(g=>g.rateLimitType==="five_hour")?.remainingPercent??null},{label:"Weekly",value:m.coreUsage?.weekly?.remainingPercent??m.windows.find(g=>["seven_day","seven_day_opus","seven_day_sonnet","seven_day_oauth_apps","seven_day_cowork"].includes(g.rateLimitType))?.remainingPercent??null}].filter(g=>g.value!==null):[],N=u?y:v?R:[],F=P!==null?pt(P):null,w=F!==null?Number(F):null;return e.jsxs("div",{className:H("flex flex-col gap-2 p-3 rounded-lg border transition-colors overflow-hidden",s.isDefault?"border-primary/30 bg-primary/5":"border-border hover:bg-muted/30",s.paused&&"opacity-75",h&&"ring-2 ring-primary/50 bg-primary/5"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[j&&e.jsx("button",{type:"button",onClick:()=>x?.(!h),className:H("flex items-center justify-center w-5 h-5 rounded border-2 transition-colors shrink-0",h?"bg-primary border-primary text-primary-foreground":"border-muted-foreground/30 hover:border-primary/50"),"aria-label":h?"Deselect account":"Select account",children:h&&e.jsx(se,{className:"w-3 h-3"})}),n&&e.jsx(oe,{children:e.jsxs(le,{children:[e.jsx(ce,{asChild:!0,children:e.jsx(E,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:()=>n(!s.paused),disabled:o,children:o?e.jsx(J,{className:"w-4 h-4 animate-spin"}):s.paused?e.jsx(Es,{className:"w-4 h-4 text-emerald-500"}):e.jsx(_e,{className:"w-4 h-4 text-muted-foreground hover:text-foreground"})})}),e.jsx(de,{side:"top",children:s.paused?"Resume account":"Pause account"})]})}),e.jsxs("div",{className:"relative shrink-0",children:[e.jsx("div",{className:H("flex items-center justify-center w-8 h-8 rounded-full",s.isDefault?"bg-primary/10":"bg-muted"),children:e.jsx(xe,{className:"w-4 h-4"})}),s.tier&&s.tier!=="unknown"&&s.tier!=="free"&&e.jsx("span",{className:H("absolute -bottom-0.5 -right-0.5 text-[7px] font-bold uppercase px-1 py-px rounded","ring-1 ring-background",s.tier==="ultra"?"bg-violet-500/20 text-violet-600 dark:bg-violet-500/30 dark:text-violet-300":"bg-yellow-500/20 text-yellow-700 dark:bg-yellow-500/25 dark:text-yellow-400"),children:s.tier==="ultra"?"U":"P"})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:H("font-medium text-sm truncate",l&&we),children:s.email||s.id}),s.isDefault&&e.jsxs(U,{variant:"secondary",className:"text-[10px] h-4 px-1.5 gap-0.5",children:[e.jsx(ke,{className:"w-2.5 h-2.5 fill-current"}),"Default"]}),s.paused&&e.jsxs(U,{variant:"outline",className:"text-[10px] h-4 px-1.5 border-yellow-500 text-yellow-600",children:[e.jsx(_e,{className:"w-2 h-2 mr-0.5"}),"Paused"]})]}),s.provider==="agy"&&e.jsx("div",{className:"flex items-center gap-1.5 mt-1",children:s.projectId?e.jsx(oe,{children:e.jsxs(le,{children:[e.jsx(ce,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(qt,{className:"w-3 h-3","aria-hidden":"true"}),e.jsx("span",{className:H("font-mono max-w-[180px] truncate",l&&we),title:s.projectId,children:s.projectId})]})}),e.jsx(de,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:"GCP Project ID (read-only)"})})]})}):e.jsx(oe,{children:e.jsxs(le,{children:[e.jsx(ce,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-amber-600 dark:text-amber-500",children:[e.jsx(ze,{className:"w-3 h-3","aria-label":"Warning"}),e.jsx("span",{children:"Project ID: N/A"})]})}),e.jsx(de,{side:"bottom",className:"max-w-[250px]",children:e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("p",{className:"font-medium text-amber-600",children:"Missing Project ID"}),e.jsx("p",{children:"This may cause errors. Remove the account and re-add it to fetch the project ID."})]})})]})})}),s.lastUsedAt&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mt-0.5",children:[e.jsx(ds,{className:"w-3 h-3"}),"Last used: ",new Date(s.lastUsedAt).toLocaleDateString()]})]})]}),e.jsxs(ut,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(E,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",children:e.jsx(Ht,{className:"w-4 h-4"})})}),e.jsxs(xt,{align:"end",children:[!s.isDefault&&e.jsxs(os,{onClick:a,children:[e.jsx(ke,{className:"w-4 h-4 mr-2"}),"Set as default"]}),e.jsxs(os,{className:"text-destructive focus:text-destructive",onClick:t,disabled:i,children:[e.jsx(Rs,{className:"w-4 h-4 mr-2"}),i?"Removing...":"Remove account"]})]})]})]}),c&&e.jsx("div",{className:"pl-11",children:f?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(J,{className:"w-3 h-3 animate-spin"}),e.jsx("span",{children:"Loading quota..."})]}):w!==null?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex items-center gap-1.5 text-xs",children:O?e.jsxs(e.Fragment,{children:[e.jsx(Bt,{className:"w-3 h-3 text-emerald-500"}),e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["Active · ",fs(p)]})]}):p?e.jsxs(e.Fragment,{children:[e.jsx(ds,{className:"w-3 h-3 text-muted-foreground"}),e.jsxs("span",{className:"text-muted-foreground",children:["Last used ",fs(p)]})]}):e.jsxs(e.Fragment,{children:[e.jsx(us,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Not used yet"})]})}),e.jsx(oe,{children:e.jsxs(le,{children:[e.jsx(ce,{asChild:!0,children:N.length>0?e.jsx("div",{className:"space-y-1.5",children:N.map(g=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-10 text-[10px] text-muted-foreground",children:g.label}),e.jsx(Ee,{value:Math.max(0,Math.min(100,g.value)),className:"h-2 flex-1",indicatorClassName:hs(g.value)}),e.jsxs("span",{className:"text-xs font-medium w-10 text-right",children:[g.value,"%"]})]},g.label))}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ee,{value:Math.max(0,Math.min(100,w)),className:"h-2 flex-1",indicatorClassName:hs(w)}),e.jsxs("span",{className:"text-xs font-medium w-10 text-right",children:[F,"%"]})]})}),e.jsx(de,{side:"bottom",className:"max-w-xs",children:e.jsx(ht,{quota:m,resetTime:k})})]})})]}):m?.success?e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(U,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-muted-foreground/50 text-muted-foreground",children:[e.jsx(us,{className:"w-3 h-3"}),"No limits"]})}):m?.needsReauth?e.jsx(oe,{children:e.jsxs(le,{children:[e.jsx(ce,{asChild:!0,children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(U,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-amber-500/50 text-amber-600 dark:text-amber-400",children:[e.jsx(Gt,{className:"w-3 h-3"}),"Reauth"]})})}),e.jsx(de,{side:"bottom",className:"max-w-[220px]",children:e.jsx("p",{className:"text-xs",children:m.error?.includes("No refresh token")?"No refresh token available. Remove and re-add account to fix.":m.error?.includes("refresh")||m.error?.includes("Invalid")?`Auto-refresh failed: ${m.error}`:`Token issue: ${m.error||"Re-authenticate required"}`})})]})}):m?.error||m&&!m.success?e.jsx(oe,{children:e.jsxs(le,{children:[e.jsx(ce,{asChild:!0,children:e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(U,{variant:"outline",className:"text-[10px] h-5 px-2 gap-1 border-muted-foreground/50 text-muted-foreground",children:[e.jsx($t,{className:"w-3 h-3"}),"N/A"]})})}),e.jsx(de,{side:"bottom",children:e.jsx("p",{className:"text-xs",children:m?.error||"Quota information unavailable"})})]})}):null})]})}function Aa({selectedCount:s,onPauseSelected:a,onResumeSelected:t,onClearSelection:n,isPausing:i,isResuming:o}){if(s<1)return null;const l=i||o;return e.jsxs("div",{className:"flex items-center gap-3 p-2 bg-muted/50 rounded-lg border mt-2",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[s," selected"]}),e.jsx(E,{variant:"ghost",size:"sm",className:"text-xs h-6 px-2",onClick:n,disabled:l,children:"Clear"}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsxs(E,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:a,disabled:l,children:[i?e.jsx(J,{className:"w-3 h-3 animate-spin"}):e.jsx(_e,{className:"w-3 h-3"}),"Pause Selected"]}),e.jsxs(E,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:t,disabled:l,children:[o?e.jsx(J,{className:"w-3 h-3 animate-spin"}):e.jsx(Es,{className:"w-3 h-3"}),"Resume Selected"]})]})]})}function Sa({accounts:s,onAddAccount:a,onSetDefault:t,onRemoveAccount:n,onPauseToggle:i,onSoloMode:o,onBulkPause:l,onBulkResume:c,isRemovingAccount:j,isPausingAccount:h,isSoloingAccount:x,isBulkPausing:b,isBulkResuming:u,privacyMode:v,showQuota:C,isKiro:m,kiroNoIncognito:f,onKiroNoIncognitoChange:p,kiroSettingsLoading:O}){const[P,k]=r.useState(new Set),_=r.useMemo(()=>new Set(s.map(M=>M.id)),[s]),y=r.useMemo(()=>new Set([...P].filter(M=>_.has(M))),[P,_]),R=!!(l&&c),N=y.size,F=s.length>0&&y.size===s.length,w=y.size>0&&y.size<s.length,g=r.useCallback(M=>{k(I=>{const $=new Set(I);return $.has(M)?$.delete(M):$.add(M),$})},[]),A=r.useCallback(()=>{k(new Set(s.map(M=>M.id)))},[s]),L=r.useCallback(()=>{k(new Set)},[]),B=r.useCallback(()=>{F?L():A()},[F,A,L]),G=r.useCallback(()=>{l&&y.size>0&&(l(Array.from(y)),k(new Set))},[l,y]),T=r.useCallback(()=>{c&&y.size>0&&(c(Array.from(y)),k(new Set))},[c,y]);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2",children:[R&&s.length>0&&e.jsx(ye,{checked:F,onCheckedChange:B,"aria-label":"Select all accounts",className:w?"data-[state=checked]:bg-primary/50":"",...w?{"data-state":"indeterminate"}:{}}),e.jsx(xe,{className:"w-4 h-4"}),"Accounts",s.length>0&&e.jsx(U,{variant:"secondary",className:"text-xs",children:s.length})]}),e.jsxs(E,{variant:"default",size:"sm",className:"h-7 text-xs gap-1",onClick:a,children:[e.jsx(Os,{className:"w-3 h-3"}),"Add"]})]}),R&&N>0&&e.jsx(Aa,{selectedCount:N,onPauseSelected:G,onResumeSelected:T,onClearSelection:L,isPausing:!!b,isResuming:!!u}),s.length>0?e.jsx("div",{className:"space-y-2",children:s.map(M=>e.jsx(Ca,{account:M,onSetDefault:()=>t(M.id),onRemove:()=>n(M.id),onPauseToggle:i?I=>i(M.id,I):void 0,onSoloMode:o?()=>o(M.id):void 0,isRemoving:j,isPausingAccount:h,isSoloingAccount:x,privacyMode:v,showQuota:C,selectable:R,selected:y.has(M.id),onSelectChange:()=>g(M.id)},M.id))}):e.jsxs("div",{className:"py-6 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed",children:[e.jsx(xe,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No accounts connected"}),e.jsx("p",{className:"text-xs opacity-70",children:"Add an account to get started"})]}),m&&p&&e.jsx("div",{className:"mt-3 pt-3 border-t border-dashed",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Ms,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Use incognito"})]}),e.jsx(Ds,{checked:!f,onCheckedChange:M=>p(!M),disabled:O,className:"scale-90"})]})})]})}function Pa({provider:s,catalog:a,savedPresets:t,currentModel:n,opusModel:i,sonnetModel:o,haikuModel:l,providerModels:c,extendedContextEnabled:j,onExtendedContextToggle:h,onApplyPreset:x,onUpdateEnvValue:b,onOpenCustomPreset:u,onDeletePreset:v,isDeletePending:C,accounts:m,onAddAccount:f,onSetDefault:p,onRemoveAccount:O,onPauseToggle:P,onSoloMode:k,onBulkPause:_,onBulkResume:y,isRemovingAccount:R,isPausingAccount:N,isSoloingAccount:F,isBulkPausing:w,isBulkResuming:g,privacyMode:A,isRemoteMode:L}){const B=s.toLowerCase(),G=(ft.includes(B)||["anthropic","antigravity","gemini-cli","copilot","github-copilot"].includes(B))&&!L,T=s==="kiro",[M,I]=r.useState(!0),[$,Q]=r.useState(!0),[Y,X]=r.useState(!1),d=r.useCallback(async()=>{if(T)try{Q(!0);const Z=(await Ne.config.get()).cliproxy;I(Z?.kiro_no_incognito??!0)}catch{I(!0)}finally{Q(!1)}},[T]),D=r.useCallback(async V=>{I(V),X(!0);try{const Z=await Ne.config.get(),pe=Z.cliproxy??{};await Ne.config.update({...Z,cliproxy:{...pe,kiro_no_incognito:V}})}catch{I(!V)}finally{X(!1)}},[]);return r.useEffect(()=>{d()},[d]),e.jsx($e,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsx(wa,{catalog:a,savedPresets:t,currentModel:n,opusModel:i,sonnetModel:o,haikuModel:l,providerModels:c,provider:s,extendedContextEnabled:j,onExtendedContextToggle:h,onApplyPreset:x,onUpdateEnvValue:b,onOpenCustomPreset:u,onDeletePreset:v,isDeletePending:C}),e.jsx(We,{}),e.jsx(Sa,{accounts:m,onAddAccount:f,onSetDefault:p,onRemoveAccount:O,onPauseToggle:P,onSoloMode:k,onBulkPause:_,onBulkResume:y,isRemovingAccount:R,isPausingAccount:N,isSoloingAccount:F,isBulkPausing:w,isBulkResuming:g,privacyMode:A,showQuota:G,isKiro:T,kiroNoIncognito:M,onKiroNoIncognitoChange:D,kiroSettingsLoading:$||Y})]})})}function gs({provider:s,displayName:a,authStatus:t,catalog:n,logoProvider:i,baseProvider:o,isRemoteMode:l,port:c,defaultTarget:j,onAddAccount:h,onSetDefault:x,onRemoveAccount:b,onPauseToggle:u,onSoloMode:v,onBulkPause:C,onBulkResume:m,isRemovingAccount:f,isPausingAccount:p,isSoloingAccount:O,isBulkPausing:P,isBulkResuming:k}){const[_,y]=r.useState(!1),{privacyMode:R}=ys(),{data:N}=gt(),{data:F}=jt(s),w=vt(),g=Nt(),A=F?.presets||[],L=o||s,B=r.useMemo(()=>{if(!N?.models)return[];const ae={gemini:["google"],agy:["antigravity"],codex:["openai"],qwen:["alibaba","qwen"],iflow:["iflow"],kiro:["kiro","aws"],ghcp:["github","copilot"],kimi:["kimi","moonshot"]}[L.toLowerCase()]||[L.toLowerCase()];return N.models.filter(ts=>ae.some(Hs=>ts.owned_by.toLowerCase().includes(Hs)))},[N,L]),G=(o||s).toLowerCase(),{data:T,isLoading:M,refetch:I,rawJsonContent:$,rawJsonEdits:Q,isRawJsonValid:Y,hasChanges:X,currentModel:d,opusModel:D,sonnetModel:V,haikuModel:Z,extendedContextEnabled:pe,toggleExtendedContext:Ce,handleRawJsonChange:Ae,updateEnvValue:Se,updateEnvValues:z,saveMutation:S,conflictDialog:te,handleConflictResolve:ee,missingRequiredFields:es}=ha(s),ve=r.useMemo(()=>(t.accounts||[]).map(q=>({...q,provider:q.provider||o||s})),[t.accounts,o,s]),{data:Fs}=js({queryKey:["auth-tokens-raw"],queryFn:async()=>{const q=await fetch("/api/settings/auth/tokens/raw");return q.ok?q.json():{apiKey:{value:"ccs-internal-managed"}}},staleTime:6e4}),ss=Fs?.apiKey?.value??"ccs-internal-managed",Us=q=>{z({ANTHROPIC_BASE_URL:`http://127.0.0.1:${c??Re}/api/provider/${G}`,ANTHROPIC_AUTH_TOKEN:ss,...q}),K.success(`Applied "${q.ANTHROPIC_MODEL?.split("/").pop()||"preset"}" preset`)},Ks=(q,ae)=>{z({ANTHROPIC_BASE_URL:`http://127.0.0.1:${c??Re}/api/provider/${G}`,ANTHROPIC_AUTH_TOKEN:ss,ANTHROPIC_MODEL:q.default,ANTHROPIC_DEFAULT_OPUS_MODEL:q.opus,ANTHROPIC_DEFAULT_SONNET_MODEL:q.sonnet,ANTHROPIC_DEFAULT_HAIKU_MODEL:q.haiku}),K.success(`Applied ${ae?`"${ae}"`:"custom"} preset`),y(!1)},qs=(q,ae)=>{if(!ae){K.error("Please enter a preset name to save");return}w.mutate({profile:s,data:{name:ae,...q}}),y(!1)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(ba,{provider:s,displayName:a,logoProvider:i,data:T,isLoading:M,hasChanges:X,isRawJsonValid:Y,isSaving:S.isPending,isRemoteMode:l,port:c,onRefetch:I,onSave:()=>S.mutate()}),M?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(J,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):e.jsxs("div",{className:"flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex flex-col overflow-hidden bg-muted/5",children:e.jsxs(bt,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(yt,{className:"w-full",children:[e.jsx(ls,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(ls,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(cs,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(Pa,{provider:s,catalog:n,savedPresets:A,currentModel:d,opusModel:D,sonnetModel:V,haikuModel:Z,providerModels:B,extendedContextEnabled:pe,onExtendedContextToggle:Ce,onApplyPreset:Us,onUpdateEnvValue:Se,onOpenCustomPreset:()=>y(!0),onDeletePreset:q=>g.mutate({profile:s,name:q}),isDeletePending:g.isPending,accounts:ve,onAddAccount:h,onSetDefault:x,onRemoveAccount:b,onPauseToggle:u,onSoloMode:v,onBulkPause:C,onBulkResume:m,isRemovingAccount:f,isPausingAccount:p,isSoloingAccount:O,isBulkPausing:P,isBulkResuming:k,privacyMode:R,isRemoteMode:l})}),e.jsx(cs,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(va,{provider:s,displayName:a,defaultTarget:j,data:T,authStatus:t})})]})]})}),e.jsxs("div",{className:"flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-2 bg-muted/30 border-b flex items-center gap-2 shrink-0 h-[45px]",children:[e.jsx(Qt,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Raw Configuration (JSON)"})]}),e.jsx(wt,{rawJsonContent:$,isRawJsonValid:Y,rawJsonEdits:Q,onRawJsonChange:Ae,profileEnv:T?.settings?.env,missingRequiredFields:es})]})]}),e.jsx(Wt,{open:te,title:"File Modified Externally",description:"This settings file was modified by another process. Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>ee(!0),onCancel:()=>ee(!1)}),e.jsx(ja,{open:_,onClose:()=>y(!1),currentValues:{default:d||"",opus:D||"",sonnet:V||"",haiku:Z||""},onApply:Ks,onSave:qs,isSaving:w.isPending,catalog:n,allModels:B})]})}function Ta({status:s,isSelected:a,onSelect:t}){const n=s.accounts?.length||0;return e.jsxs("button",{className:H("w-full flex items-center gap-3 px-3 py-2.5 rounded-lg transition-colors cursor-pointer text-left",a?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:t,children:[e.jsx(Ze,{provider:s.provider,size:"md"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm truncate",children:s.displayName}),n>0&&e.jsx(U,{variant:"secondary",className:"text-[10px] h-4 px-1",children:n})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:s.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"w-3 h-3 text-green-600"}),e.jsx("span",{className:"text-xs text-green-600",children:"Connected"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Je,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Not connected"})]})})]})]})}function Ma({variant:s,parentAuth:a,isSelected:t,onSelect:n,onDelete:i,isDeleting:o}){return e.jsxs("button",{className:H("group w-full flex items-center gap-3 px-3 py-2 rounded-lg transition-colors cursor-pointer text-left pl-6",t?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:n,children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ze,{provider:s.provider,size:"sm"}),e.jsx(_s,{className:"w-2.5 h-2.5 absolute -bottom-0.5 -right-0.5 text-muted-foreground"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm truncate",children:s.name}),e.jsx(U,{variant:"outline",className:"text-[9px] h-4 px-1",children:"variant"}),e.jsx(U,{variant:"outline",className:"text-[9px] h-4 px-1 uppercase",children:s.target||"claude"})]}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:a?.authenticated?e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"w-3 h-3 text-green-600"}),e.jsxs("span",{className:"text-xs text-muted-foreground truncate",children:["via ",s.provider]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Je,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Parent not connected"})]})})]}),e.jsx(E,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 hover:text-destructive",onClick:l=>{l.stopPropagation(),i()},disabled:o,children:e.jsx(Rs,{className:"w-3 h-3"})})]})}function Oa({onSetup:s}){return e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20",children:e.jsxs("div",{className:"text-center max-w-md px-8",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-muted flex items-center justify-center mx-auto mb-6",children:e.jsx(je,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"CCS Profile Manager"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Manage OAuth authentication, account preferences, and model selection for CLIProxy providers. Configure how CCS routes requests to different AI backends."}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-6",children:["For live usage stats and real-time monitoring, visit the"," ",e.jsx("a",{href:"/cliproxy/control-panel",className:"text-primary hover:underline",children:"Control Panel"}),"."]}),e.jsxs(E,{onClick:s,className:"gap-2",children:[e.jsx(ge,{className:"w-4 h-4"}),"Quick Setup"]})]})})}function za(){const s=Le(),{data:a,isLoading:t}=bs(),{data:n,isFetching:i}=kt(),{data:o}=Ct(),l=At(),c=St(),j=Pt(),h=Tt(),x=Mt(),b=Ot(),u=Et(),v=Rt(),[C,m]=r.useState(()=>typeof window<"u"?localStorage.getItem("cliproxy-selected-provider"):null),[f,p]=r.useState(null),[O,P]=r.useState(!1),[k,_]=r.useState(null),y=r.useMemo(()=>a?.authStatus||[],[a?.authStatus]),R=a?.source==="remote",N=r.useMemo(()=>n?.variants||[],[n?.variants]),F=d=>{m(d),d&&localStorage.setItem("cliproxy-selected-provider",d)},w=r.useMemo(()=>f?null:C&&y.some(d=>d.provider===C)?C:y.length>0&&(y.find(D=>(D.accounts?.length||0)>0)?.provider||y[0]?.provider)||null,[C,f,y]),g=y.find(d=>d.provider===w),A=N.find(d=>d.name===f),L=A?y.find(d=>d.provider===A.provider):void 0,B=(A?.provider||g?.provider||"").toLowerCase().trim(),G=B==="gemini"||B==="agy",T=()=>{s.invalidateQueries({queryKey:["cliproxy"]}),s.invalidateQueries({queryKey:["cliproxy-auth"]})},M=(d,D,V)=>{j.isPending||h.isPending||(V?j.mutate({provider:d,accountId:D}):h.mutate({provider:d,accountId:D}))},I=(d,D)=>{x.isPending||x.mutate({provider:d,accountId:D})},$=(d,D)=>{b.isPending||b.mutate({provider:d,accountIds:D})},Q=(d,D)=>{u.isPending||u.mutate({provider:d,accountIds:D})},Y=d=>{F(d),p(null)},X=d=>{p(d),F(null)};return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex",children:[e.jsxs("div",{className:"w-80 border-r flex flex-col bg-muted/30",children:[e.jsxs("div",{className:"p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(je,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:o?.backendLabel??"CLIProxy"})]}),e.jsx(E,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:T,disabled:i,children:e.jsx(Ve,{className:H("w-4 h-4",i&&"animate-spin")})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"CCS-level account management"}),e.jsxs(E,{variant:"default",size:"sm",className:"w-full gap-2",onClick:()=>P(!0),children:[e.jsx(ge,{className:"w-4 h-4"}),"Quick Setup"]})]}),e.jsx($e,{className:"flex-1",children:e.jsxs("div",{className:"p-2",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide px-3 py-2",children:"Providers"}),t?e.jsx("div",{className:"space-y-2 px-2",children:[1,2,3,4].map(d=>e.jsx(_t,{className:"h-14 w-full rounded-lg"},d))}):e.jsx("div",{className:"space-y-1",children:y.map(d=>e.jsx(Ta,{status:d,isSelected:w===d.provider,onSelect:()=>Y(d.provider)},d.provider))}),N.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide px-3 py-2 mt-4 flex items-center gap-1.5",children:[e.jsx(_s,{className:"w-3 h-3"}),"Variants"]}),e.jsx("div",{className:"space-y-1",children:N.map(d=>e.jsx(Ma,{variant:d,parentAuth:y.find(D=>D.provider===d.provider),isSelected:f===d.name,onSelect:()=>X(d.name),onDelete:()=>v.mutate(d.name),isDeleting:v.isPending},d.name))})]})]})}),e.jsx("div",{className:"p-3 border-t",children:e.jsx(Jt,{})}),e.jsx("div",{className:"p-3 border-t bg-background text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[y.length," provider",y.length!==1?"s":""]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(se,{className:"w-3 h-3 text-green-600"}),y.filter(d=>d.authenticated).length," connected"]})]})})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-background",children:[G&&e.jsx(Ls,{showProxySettingsLink:!0,className:"mx-4 mt-4"}),A&&L?e.jsx(gs,{provider:A.name,displayName:`${A.name} (${A.provider} variant)`,authStatus:L,catalog:fe[A.provider],logoProvider:A.provider,baseProvider:A.provider,defaultTarget:A.target,isRemoteMode:R,port:A.port,onAddAccount:()=>_({provider:A.provider,displayName:L.displayName,isFirstAccount:(L.accounts?.length||0)===0}),onSetDefault:d=>l.mutate({provider:A.provider,accountId:d}),onRemoveAccount:d=>c.mutate({provider:A.provider,accountId:d}),onPauseToggle:(d,D)=>M(A.provider,d,D),onSoloMode:d=>I(A.provider,d),onBulkPause:d=>$(A.provider,d),onBulkResume:d=>Q(A.provider,d),isRemovingAccount:c.isPending,isPausingAccount:j.isPending||h.isPending,isSoloingAccount:x.isPending,isBulkPausing:b.isPending,isBulkResuming:u.isPending}):g?e.jsx(gs,{provider:g.provider,displayName:g.displayName,authStatus:g,catalog:fe[g.provider],isRemoteMode:R,onAddAccount:()=>_({provider:g.provider,displayName:g.displayName,isFirstAccount:(g.accounts?.length||0)===0}),onSetDefault:d=>l.mutate({provider:g.provider,accountId:d}),onRemoveAccount:d=>c.mutate({provider:g.provider,accountId:d}),onPauseToggle:(d,D)=>M(g.provider,d,D),onSoloMode:d=>I(g.provider,d),onBulkPause:d=>$(g.provider,d),onBulkResume:d=>Q(g.provider,d),isRemovingAccount:c.isPending,isPausingAccount:j.isPending||h.isPending,isSoloingAccount:x.isPending,isBulkPausing:b.isPending,isBulkResuming:u.isPending}):e.jsx(Oa,{onSetup:()=>P(!0)})]}),e.jsx(na,{open:O,onClose:()=>P(!1)}),e.jsx(da,{open:k!==null,onClose:()=>_(null),provider:k?.provider||"",displayName:k?.displayName||"",isFirstAccount:k?.isFirstAccount||!1})]})}export{za as CliproxyPage};
|