@kaitranntt/ccs 7.69.1-dev.1 → 7.69.1-dev.3

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.
Files changed (53) hide show
  1. package/dist/ui/assets/accounts-DN0lP-yj.js +1 -0
  2. package/dist/ui/assets/{alert-dialog-QyEXocpn.js → alert-dialog-BA39vaYL.js} +1 -1
  3. package/dist/ui/assets/api-D2cjf1H4.js +4 -0
  4. package/dist/ui/assets/{auth-section-BszF77uT.js → auth-section-BNX8_9MJ.js} +1 -1
  5. package/dist/ui/assets/{backups-section-D6RgaOx1.js → backups-section-Bt0FA5zl.js} +1 -1
  6. package/dist/ui/assets/channels-FaDUjf3Y.js +1 -0
  7. package/dist/ui/assets/{checkbox-Dzwkj_Pg.js → checkbox-DHF-UBrH.js} +1 -1
  8. package/dist/ui/assets/claude-extension-D-skBToQ.js +1 -0
  9. package/dist/ui/assets/cliproxy-CD7z-_q8.js +3 -0
  10. package/dist/ui/assets/cliproxy-ai-providers-QSOOqh8F.js +15 -0
  11. package/dist/ui/assets/cliproxy-control-panel-D9dLU28p.js +1 -0
  12. package/dist/ui/assets/codex-CHO5_hku.js +27 -0
  13. package/dist/ui/assets/confirm-dialog-BICDz_zm.js +1 -0
  14. package/dist/ui/assets/copilot-BnQrRCuJ.js +3 -0
  15. package/dist/ui/assets/{cursor-BrcDgu6X.js → cursor-CXopLKfC.js} +1 -1
  16. package/dist/ui/assets/droid-CLFg9ELE.js +2 -0
  17. package/dist/ui/assets/{globalenv-section-DoX37DqB.js → globalenv-section-NPjCcYBN.js} +1 -1
  18. package/dist/ui/assets/{health-D_gdcxnc.js → health-B_3JpCrY.js} +1 -1
  19. package/dist/ui/assets/index-B5Egq7qY.js +1 -0
  20. package/dist/ui/assets/index-BY2j-o67.js +1 -0
  21. package/dist/ui/assets/{index-CTGpqIx6.js → index-BcUkpsGj.js} +1 -1
  22. package/dist/ui/assets/{index-DoVPk3vW.js → index-BgGHTjTd.js} +1 -1
  23. package/dist/ui/assets/index-DNmWbKbN.js +72 -0
  24. package/dist/ui/assets/index-DZddoGfE.js +1 -0
  25. package/dist/ui/assets/logs-Bb1OVYeK.js +1 -0
  26. package/dist/ui/assets/{masked-input-C2H-Ax0Z.js → masked-input-b4-lEKNq.js} +1 -1
  27. package/dist/ui/assets/proxy-status-widget-s89zaj3X.js +1 -0
  28. package/dist/ui/assets/{raw-json-settings-editor-panel-WxTn7-hS.js → raw-json-settings-editor-panel-Dr_BNQwQ.js} +1 -1
  29. package/dist/ui/assets/{searchable-select-1zOULoec.js → searchable-select-FJPe_YWv.js} +1 -1
  30. package/dist/ui/assets/{separator-BCfZ54mZ.js → separator-DJ0ku_ak.js} +1 -1
  31. package/dist/ui/assets/{shared-DlTbnc9n.js → shared-DyQlJnbj.js} +1 -1
  32. package/dist/ui/assets/{table-Bx2cnkWN.js → table-6Yg65ZZH.js} +1 -1
  33. package/dist/ui/assets/{updates-SiZKOnUD.js → updates-DSCXb6Au.js} +1 -1
  34. package/dist/ui/index.html +1 -1
  35. package/lib/mcp/ccs-browser-server.cjs +119 -27
  36. package/package.json +1 -1
  37. package/dist/ui/assets/accounts-D9eEaNx9.js +0 -1
  38. package/dist/ui/assets/api-7vQe0xOg.js +0 -4
  39. package/dist/ui/assets/channels-B1vgnNJX.js +0 -1
  40. package/dist/ui/assets/claude-extension-CKO4bJ22.js +0 -1
  41. package/dist/ui/assets/cliproxy-ai-providers-CmbFYVoR.js +0 -15
  42. package/dist/ui/assets/cliproxy-control-panel-M8ZfUq3C.js +0 -1
  43. package/dist/ui/assets/cliproxy-kHd-oC5W.js +0 -3
  44. package/dist/ui/assets/codex-BJ0RdMuh.js +0 -27
  45. package/dist/ui/assets/confirm-dialog-BlSaX2gK.js +0 -1
  46. package/dist/ui/assets/copilot-NJKZQXQ_.js +0 -3
  47. package/dist/ui/assets/droid-B9u9ZB-a.js +0 -2
  48. package/dist/ui/assets/index-BNU4Hhe_.js +0 -1
  49. package/dist/ui/assets/index-DFEMq3KP.js +0 -1
  50. package/dist/ui/assets/index-DOn6k1jF.js +0 -72
  51. package/dist/ui/assets/index-h08p9xL5.js +0 -1
  52. package/dist/ui/assets/logs-DtH4YMt4.js +0 -1
  53. package/dist/ui/assets/proxy-status-widget-BOrsn86w.js +0 -1
@@ -1,6 +1,34 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { WebSocket } = require('ws');
3
+ function loadWebSocketImplementation() {
4
+ if (typeof globalThis.WebSocket === 'function') {
5
+ return globalThis.WebSocket;
6
+ }
7
+
8
+ try {
9
+ const { WebSocket } = require('undici');
10
+ if (typeof WebSocket === 'function') {
11
+ return WebSocket;
12
+ }
13
+ } catch {
14
+ // Fall through to the legacy ws dependency when available.
15
+ }
16
+
17
+ try {
18
+ const { WebSocket } = require('ws');
19
+ if (typeof WebSocket === 'function') {
20
+ return WebSocket;
21
+ }
22
+ } catch {
23
+ // Surface a dedicated error below if no implementation is available.
24
+ }
25
+
26
+ throw new Error(
27
+ 'Browser MCP could not find a WebSocket implementation. Tried globalThis.WebSocket, undici, and ws.'
28
+ );
29
+ }
30
+
31
+ const WebSocket = loadWebSocketImplementation();
4
32
 
5
33
  const PROTOCOL_VERSION = '2024-11-05';
6
34
  const SERVER_NAME = 'ccs-browser';
@@ -29,6 +57,66 @@ const NAVIGATION_POLL_INTERVAL_MS = 100;
29
57
  let inputBuffer = Buffer.alloc(0);
30
58
  let requestCounter = 0;
31
59
 
60
+ function addSocketListener(socket, eventName, handler) {
61
+ if (typeof socket.addEventListener === 'function') {
62
+ socket.addEventListener(eventName, handler);
63
+ return;
64
+ }
65
+
66
+ if (typeof socket.on === 'function') {
67
+ socket.on(eventName, handler);
68
+ }
69
+ }
70
+
71
+ async function getSocketMessageText(message) {
72
+ const data = message && typeof message === 'object' && 'data' in message ? message.data : message;
73
+
74
+ if (typeof data === 'string') {
75
+ return data;
76
+ }
77
+
78
+ if (Buffer.isBuffer(data)) {
79
+ return data.toString('utf8');
80
+ }
81
+
82
+ if (data instanceof ArrayBuffer) {
83
+ return Buffer.from(data).toString('utf8');
84
+ }
85
+
86
+ if (ArrayBuffer.isView(data)) {
87
+ return Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString('utf8');
88
+ }
89
+
90
+ if (data && typeof data.text === 'function') {
91
+ return await data.text();
92
+ }
93
+
94
+ return String(data);
95
+ }
96
+
97
+ function closeSocket(socket) {
98
+ if (typeof socket.close === 'function') {
99
+ socket.close();
100
+ }
101
+ }
102
+
103
+ function abortSocket(socket) {
104
+ if (typeof socket.terminate === 'function') {
105
+ socket.terminate();
106
+ return;
107
+ }
108
+
109
+ closeSocket(socket);
110
+ }
111
+
112
+ function toSocketError(error) {
113
+ if (error instanceof Error) {
114
+ return error;
115
+ }
116
+
117
+ return new Error('Browser MCP lost the DevTools websocket connection.');
118
+ }
119
+
32
120
  function shouldExposeTools() {
33
121
  return Boolean(process.env.CCS_BROWSER_DEVTOOLS_HTTP_URL);
34
122
  }
@@ -298,7 +386,7 @@ async function sendCdpCommand(page, method, params = {}) {
298
386
  const timer = setTimeout(() => {
299
387
  if (!settled) {
300
388
  settled = true;
301
- ws.terminate();
389
+ abortSocket(ws);
302
390
  reject(new Error('Browser MCP timed out waiting for a DevTools response.'));
303
391
  }
304
392
  }, CDP_TIMEOUT_MS);
@@ -309,10 +397,10 @@ async function sendCdpCommand(page, method, params = {}) {
309
397
  }
310
398
  clearTimeout(timer);
311
399
  settled = true;
312
- reject(error);
400
+ reject(toSocketError(error));
313
401
  }
314
402
 
315
- ws.on('open', () => {
403
+ addSocketListener(ws, 'open', () => {
316
404
  ws.send(
317
405
  JSON.stringify({
318
406
  id: requestId,
@@ -322,39 +410,43 @@ async function sendCdpCommand(page, method, params = {}) {
322
410
  );
323
411
  });
324
412
 
325
- ws.on('message', (data) => {
326
- if (settled) {
327
- return;
328
- }
413
+ addSocketListener(ws, 'message', (data) => {
414
+ void (async () => {
415
+ const raw = await getSocketMessageText(data);
329
416
 
330
- let message;
331
- try {
332
- message = JSON.parse(data.toString());
333
- } catch {
334
- return;
335
- }
417
+ if (settled) {
418
+ return;
419
+ }
336
420
 
337
- if (message.id !== requestId) {
338
- return;
339
- }
421
+ let message;
422
+ try {
423
+ message = JSON.parse(raw);
424
+ } catch {
425
+ return;
426
+ }
340
427
 
341
- clearTimeout(timer);
342
- settled = true;
343
- ws.close();
428
+ if (message.id !== requestId) {
429
+ return;
430
+ }
344
431
 
345
- if (message.error) {
346
- reject(new Error(message.error.message || 'DevTools request failed.'));
347
- return;
348
- }
432
+ clearTimeout(timer);
433
+ settled = true;
434
+ closeSocket(ws);
435
+
436
+ if (message.error) {
437
+ reject(new Error(message.error.message || 'DevTools request failed.'));
438
+ return;
439
+ }
349
440
 
350
- resolve(message.result || null);
441
+ resolve(message.result || null);
442
+ })().catch(settleError);
351
443
  });
352
444
 
353
- ws.on('error', (error) => {
445
+ addSocketListener(ws, 'error', (error) => {
354
446
  settleError(error);
355
447
  });
356
448
 
357
- ws.on('close', () => {
449
+ addSocketListener(ws, 'close', () => {
358
450
  if (settled) {
359
451
  return;
360
452
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaitranntt/ccs",
3
- "version": "7.69.1-dev.1",
3
+ "version": "7.69.1-dev.3",
4
4
  "description": "Claude Code Switch - Instant profile switching between Claude, GLM, Kimi, and more",
5
5
  "keywords": [
6
6
  "cli",
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as C,h as ve}from"./react-vendor-CNOkPC89.js";import{u as Ce,a as $,b as F,e as ke,f as ee,g as we}from"./tanstack-CrmUhA7Z.js";import{T as Pe,a as Ae,b as te,c as De,d as _e,e as Te}from"./table-Bx2cnkWN.js";import{Y as O,a as z,ag as de,ah as ue,ai as xe,aj as me,ak as he,L as T,I as V,x as D,aC as Se,d as b,B as P,C as M,b as R,e as Ge,f as Me,g as Re,n as Oe,j as I,k as q,_ as Q}from"./index-DOn6k1jF.js";import{A as ze,a as $e,b as Fe,c as Le,d as Ke,e as He,f as Ie,g as qe}from"./alert-dialog-QyEXocpn.js";import{t as k}from"./notifications-B2HqRBj7.js";import{b0 as W,b1 as E,b2 as pe,aG as ge,_ as fe,b3 as Ee,b4 as Ue,m as Y,as as Be,Q as Qe,a6 as U,T as J,x as Ze,$ as Xe,o as se,U as Ve,a9 as ae,Z as ne}from"./icons-KVCk4_U8.js";import{C as re}from"./checkbox-Dzwkj_Pg.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function Z(a){return Array.from(a).sort((r,t)=>r.localeCompare(t))}function We(a){const r=new Map;for(const n of a){if(n.context_mode!=="shared")continue;const h=n.context_group||"default",m=r.get(h)??{group:h,sharedCount:0,deeperCount:0,accountNames:[]};m.sharedCount+=1,m.accountNames.push(n.name),n.continuity_mode==="deeper"&&(m.deeperCount+=1),r.set(h,m)}const t=Array.from(r.values()).sort((n,h)=>n.group.localeCompare(h.group)),u=a.map(n=>{if(n.context_mode!=="shared")return{...n,sameGroupPeerCount:0,sameGroupDeeperPeerCount:0};const h=n.context_group||"default",m=r.get(h),y=Math.max((m?.sharedCount??1)-1,0),x=Math.max((m?.deeperCount??0)-(n.continuity_mode==="deeper"?1:0),0);return{...n,sameGroupPeerCount:y,sameGroupDeeperPeerCount:x}}),s=u.filter(n=>n.context_mode==="shared").length,i=u.filter(n=>n.context_mode==="shared"&&n.continuity_mode==="deeper").length,c=u.filter(n=>n.context_inferred).length,p=u.filter(n=>n.context_mode==="shared"&&n.continuity_mode!=="deeper"&&n.continuity_inferred).length;return{accounts:u,sharedCount:s,sharedStandardCount:Math.max(s-i,0),deeperSharedCount:i,isolatedCount:u.length-s,legacyContextCount:c,legacyContinuityCount:p,sharedAloneCount:u.filter(n=>n.context_mode==="shared"&&n.sameGroupPeerCount===0).length,sharedPeerAccountCount:u.filter(n=>n.sameGroupPeerCount>0).length,deeperReadyAccountCount:u.filter(n=>n.continuity_mode==="deeper"&&n.sameGroupDeeperPeerCount>0).length,sharedPeerGroups:Z(t.filter(n=>n.sharedCount>=2).map(n=>n.group)),deeperReadyGroups:Z(t.filter(n=>n.deeperCount>=2).map(n=>n.group)),sharedGroups:Z(t.map(n=>n.group)),groupSummaries:t}}function Ye(){return Ce({queryKey:["accounts"],queryFn:()=>O.accounts.list(),select:a=>{const r=a.accounts.filter(i=>i.type!=="cliproxy"),t=We(r),u=a.accounts.length-r.length,s=t.accounts.some(i=>i.name===a.default)?a.default:null;return{accounts:t.accounts,default:s,cliproxyCount:u,legacyContextCount:t.legacyContextCount,legacyContinuityCount:t.legacyContinuityCount,sharedCount:t.sharedCount,sharedStandardCount:t.sharedStandardCount,deeperSharedCount:t.deeperSharedCount,isolatedCount:t.isolatedCount,sharedAloneCount:t.sharedAloneCount,sharedPeerAccountCount:t.sharedPeerAccountCount,deeperReadyAccountCount:t.deeperReadyAccountCount,sharedPeerGroups:t.sharedPeerGroups,deeperReadyGroups:t.deeperReadyGroups,sharedGroups:t.sharedGroups,groupSummaries:t.groupSummaries,plainCcsLane:a.plain_ccs_lane??null}}})}function Je(){const a=$();return F({mutationFn:r=>O.accounts.setDefault(r),onSuccess:(r,t)=>{a.invalidateQueries({queryKey:["accounts"]}),k.success(`Default account set to "${t}"`)},onError:r=>{k.error(r.message)}})}function et(){const a=$();return F({mutationFn:()=>O.accounts.resetDefault(),onSuccess:()=>{a.invalidateQueries({queryKey:["accounts"]}),k.success("Default account reset to CCS")},onError:r=>{k.error(r.message)}})}function tt(){const a=$();return F({mutationFn:r=>O.accounts.delete(r),onSuccess:(r,t)=>{a.invalidateQueries({queryKey:["accounts"]}),k.success(`Account "${t}" deleted`)},onError:r=>{k.error(r.message)}})}function be(){const a=$();return F({mutationFn:({name:r,context_mode:t,context_group:u,continuity_mode:s})=>O.accounts.updateContext(r,{context_mode:t,context_group:u,continuity_mode:s}),onSuccess:(r,t)=>{a.invalidateQueries({queryKey:["accounts"]});const u=t.context_mode==="shared"?t.continuity_mode==="deeper"?`shared (${(t.context_group||"default").trim().toLowerCase().replace(/\s+/g,"-")}, deeper continuity)`:`shared (${(t.context_group||"default").trim().toLowerCase().replace(/\s+/g,"-")}, standard)`:"isolated";k.success(`Updated "${t.name}" context to ${u}`)},onError:r=>{k.error(r.message)}})}function st(){const a=$();return F({mutationFn:async r=>{const t=r.filter(i=>i.context_inferred||i.continuity_inferred),s=(await Promise.allSettled(t.map(i=>{const c=i.context_mode==="shared";return O.accounts.updateContext(i.name,{context_mode:c?"shared":"isolated",context_group:c?i.context_group||"default":void 0,continuity_mode:c?i.continuity_mode==="deeper"?"deeper":"standard":void 0})}))).filter(i=>i.status==="rejected").length;return{updatedCount:t.length-s,failedCount:s}},onSuccess:({updatedCount:r,failedCount:t})=>{if(a.invalidateQueries({queryKey:["accounts"]}),t>0&&r>0){k.error(`Confirmed ${r} legacy account${r>1?"s":""}, but ${t} update${t>1?"s":""} failed. Refreshed account state.`);return}if(t>0){k.error(`Failed to confirm ${t} legacy account${t>1?"s":""}. Refreshed account state.`);return}if(r>0){k.success(`Confirmed explicit sync mode for ${r} legacy account${r>1?"s":""}`);return}k.info("No legacy accounts need confirmation")},onError:r=>{a.invalidateQueries({queryKey:["accounts"]}),k.error(r.message)}})}const oe=64,at=/^[a-zA-Z][a-zA-Z0-9_-]*$/;function nt({account:a,groupSummaries:r,plainCcsLane:t,onClose:u}){const{t:s}=z(),i=be(),[c,p]=C.useState(a.context_mode==="shared"?"shared":"isolated"),[n,h]=C.useState(a.context_group||"default"),[m,y]=C.useState(a.continuity_mode==="deeper"?"deeper":"standard"),x=C.useMemo(()=>n.trim().toLowerCase().replace(/\s+/g,"-"),[n]),l=C.useMemo(()=>r.find(g=>g.group===x),[r,x]),N=x.length>0&&x.length<=oe&&at.test(x),o=c==="isolated"||N,d=c==="shared"?Math.max((l?.sharedCount??0)-(a.context_mode==="shared"&&a.context_group===x?1:0),0):0,f=c==="shared"?Math.max((l?.deeperCount??0)-(a.continuity_mode==="deeper"&&a.context_group===x?1:0),0):0,v=t?.account_name===a.name,j=!!t&&!v,S=`ccs auth default ${a.name}`,_=`ccs auth backup ${a.name}`,w=(g,K,G,H)=>{if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(g.key))return;g.preventDefault();const je=G.indexOf(K),ye=g.key==="ArrowLeft"||g.key==="ArrowUp"?-1:1,Ne=(je+ye+G.length)%G.length;H(G[Ne])},L=t?t.kind==="native"?s("continuityOverview.lane.native"):t.kind==="account-default"?s("continuityOverview.lane.accountDefault",{name:t.account_name||""}):t.kind==="account-inherited"?s("continuityOverview.lane.accountInherited",{name:t.account_name||""}):t.kind==="profile-default"?s("continuityOverview.lane.profileDefault",{name:t.profile_name||"default"}):t.label:"",A=()=>{o&&i.mutate({name:a.name,context_mode:c,context_group:c==="shared"?x:void 0,continuity_mode:c==="shared"?m:void 0},{onSuccess:()=>{u()}})},B=g=>{g||u()};return e.jsx(de,{open:!0,onOpenChange:B,children:e.jsxs(ue,{className:"sm:max-w-md",children:[e.jsxs(xe,{children:[e.jsx(me,{children:s("editAccountContext.title")}),e.jsx(he,{children:s("editAccountContext.description",{name:a.name})})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(T,{className:"text-sm font-semibold",children:s("editAccountContext.syncMode")})}),e.jsxs("div",{className:"flex p-0.5 bg-muted/60 hover:bg-muted/80 transition-colors rounded-xl border border-border/40 w-full",role:"radiogroup","aria-label":s("editAccountContext.syncMode"),children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":c==="isolated",tabIndex:c==="isolated"?0:-1,onClick:()=>p("isolated"),onKeyDown:g=>w(g,c,["isolated","shared"],p),className:`flex-1 flex justify-center items-center gap-2 px-3 py-1.5 rounded-[10px] text-sm font-medium transition-all duration-200 overflow-hidden ${c==="isolated"?"bg-background text-blue-600 dark:text-blue-400 shadow-sm ring-1 ring-border/50":"text-muted-foreground hover:text-foreground hover:bg-muted/50"}`,children:[e.jsx(W,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:s("editAccountContext.isolatedOption")})]}),e.jsxs("button",{type:"button",role:"radio","aria-checked":c==="shared",tabIndex:c==="shared"?0:-1,onClick:()=>p("shared"),onKeyDown:g=>w(g,c,["isolated","shared"],p),className:`flex-1 flex justify-center items-center gap-2 px-3 py-1.5 rounded-[10px] text-sm font-medium transition-all duration-200 overflow-hidden ${c==="shared"?"bg-background text-emerald-600 dark:text-emerald-400 shadow-sm ring-1 ring-border/50":"text-muted-foreground hover:text-foreground hover:bg-muted/50"}`,children:[e.jsx(E,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:s("editAccountContext.sharedOption")})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground pt-1 px-1",children:s(c==="isolated"?"editAccountContext.isolatedModeHint":"editAccountContext.sharedModeHint")})]}),c==="shared"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"context-group",children:s("editAccountContext.historySyncGroup")}),e.jsx(V,{id:"context-group",value:n,onChange:g=>h(g.target.value),placeholder:s("editAccountContext.groupPlaceholder"),autoComplete:"off"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("editAccountContext.groupHint",{max:oe})}),!N&&e.jsx("p",{className:"text-xs text-destructive",children:s("editAccountContext.invalidGroup")})]}),c==="shared"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(T,{className:"text-sm font-semibold",children:s("editAccountContext.continuityDepth")})}),e.jsxs("div",{className:"flex p-0.5 bg-muted/60 hover:bg-muted/80 transition-colors rounded-xl border border-border/40 w-full",role:"radiogroup","aria-label":s("editAccountContext.continuityDepth"),children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":m==="standard",tabIndex:m==="standard"?0:-1,onClick:()=>y("standard"),onKeyDown:g=>w(g,m,["standard","deeper"],y),className:`flex-1 flex justify-center items-center gap-2 px-3 py-1.5 rounded-[10px] text-sm font-medium transition-all duration-200 overflow-hidden ${m==="standard"?"bg-background text-emerald-600 dark:text-emerald-400 shadow-sm ring-1 ring-border/50":"text-muted-foreground hover:text-foreground hover:bg-muted/50"}`,children:[e.jsx(E,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:s("editAccountContext.standardOption")})]}),e.jsxs("button",{type:"button",role:"radio","aria-checked":m==="deeper",tabIndex:m==="deeper"?0:-1,onClick:()=>y("deeper"),onKeyDown:g=>w(g,m,["standard","deeper"],y),className:`flex-1 flex justify-center items-center gap-2 px-3 py-1.5 rounded-[10px] text-sm font-medium transition-all duration-200 overflow-hidden ${m==="deeper"?"bg-background text-indigo-600 dark:text-indigo-400 shadow-sm ring-1 ring-border/50":"text-muted-foreground hover:text-foreground hover:bg-muted/50"}`,children:[e.jsx(pe,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:s("editAccountContext.deeperOption")})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground pt-1 px-1",children:s(m==="standard"?"editAccountContext.standardHint":"editAccountContext.deeperHint")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("editAccountContext.credentialsIsolated")}),j&&e.jsx("div",{className:"rounded-[14px] border border-amber-200 bg-amber-50/50 p-4 text-xs shadow-sm dark:border-amber-900/40 dark:bg-amber-900/10",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-foreground",children:s("continuityOverview.plainLaneTitle")}),e.jsx("p",{className:"text-muted-foreground leading-relaxed",children:s("continuityOverview.plainLaneDescription",{lane:L||"plain ccs",name:a.name})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"rounded-md border bg-background px-2 py-2 font-mono text-[11px] flex items-start gap-2",children:[e.jsx("span",{className:"flex-1 break-all",children:"ccs -r"}),e.jsx(D,{value:"ccs -r",size:"icon"})]}),e.jsxs("div",{className:"rounded-md border bg-background px-2 py-2 font-mono text-[11px] flex items-start gap-2",children:[e.jsx("span",{className:"flex-1 break-all",children:"ccs auth backup default"}),e.jsx(D,{value:"ccs auth backup default",size:"icon"})]}),e.jsxs("div",{className:"rounded-md border bg-background px-2 py-2 font-mono text-[11px] flex items-start gap-2",children:[e.jsx("span",{className:"flex-1 break-all",children:_}),e.jsx(D,{value:_,size:"icon"})]}),e.jsxs("div",{className:"rounded-md border bg-background px-2 py-2 font-mono text-[11px] flex items-start gap-2",children:[e.jsx("span",{className:"flex-1 break-all",children:S}),e.jsx(D,{value:S,size:"icon"})]})]})]})}),e.jsx("div",{className:`rounded-[14px] border p-4 text-xs shadow-sm transition-colors ${c==="isolated"?"bg-blue-50/50 border-blue-200 dark:bg-blue-900/10 dark:border-blue-800/40":"bg-muted/40 border-border/60"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[c==="isolated"?e.jsx(ge,{className:"h-4 w-4 text-blue-500 mt-0.5 shrink-0"}):e.jsx(fe,{className:"h-4 w-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{className:"space-y-1.5 flex-1 text-muted-foreground leading-relaxed",children:[c==="isolated"?e.jsx("p",{className:"text-foreground font-medium selection:bg-blue-200",children:s("editAccountContext.isolatedImplication")}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-foreground font-medium",children:s("editAccountContext.sameGroupRule",{group:x})})," ",d>0?s("editAccountContext.sameGroupPeerCount",{count:d}):s("editAccountContext.noSameGroupPeer")]}),m==="deeper"&&e.jsx("p",{children:f>0?s("editAccountContext.deeperReady",{count:f}):e.jsx("span",{className:"text-amber-600 dark:text-amber-500",children:s("editAccountContext.deeperNeedsPeers")})})]}),e.jsx("p",{className:`pt-1.5 text-[11px] ${c==="isolated"?"text-blue-700/70 dark:text-blue-300/60":"text-muted-foreground/70"}`,children:s("editAccountContext.resumeOriginalWarning")})]})]})})]}),e.jsxs(Se,{children:[e.jsx(b,{variant:"outline",onClick:u,disabled:i.isPending,children:s("editAccountContext.cancel")}),e.jsx(b,{onClick:A,disabled:!o||i.isPending,children:i.isPending?s("editAccountContext.saving"):s("editAccountContext.save")})]})]})})}function ce({data:a,defaultAccount:r,groupSummaries:t,plainCcsLane:u}){const{t:s}=z(),i=Je(),c=tt(),p=et(),n=be(),[h,m]=C.useState(null),[y,x]=C.useState(null),l=[{accessorKey:"name",header:s("accountsTable.name"),size:200,cell:({row:o})=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:o.original.name}),o.original.name===r&&e.jsx("span",{className:"text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded border border-primary/20",children:s("accountsTable.defaultBadge")})]})},{accessorKey:"type",header:s("accountsTable.type"),size:100,cell:({row:o})=>e.jsx("span",{className:"capitalize text-muted-foreground",children:o.original.type||"oauth"})},{accessorKey:"created",header:s("accountsTable.created"),size:150,cell:({row:o})=>{const d=new Date(o.original.created);return e.jsx("span",{className:"text-muted-foreground",children:d.toLocaleDateString()})}},{accessorKey:"last_used",header:s("accountsTable.lastUsed"),size:150,cell:({row:o})=>{if(!o.original.last_used)return e.jsx("span",{className:"text-muted-foreground/50",children:"-"});const d=new Date(o.original.last_used);return e.jsx("span",{className:"text-muted-foreground",children:d.toLocaleDateString()})}},{id:"context",header:s("accountsTable.historySync"),size:170,cell:({row:o})=>{if(o.original.type==="cliproxy")return e.jsx("span",{className:"text-muted-foreground/50",children:"-"});if((o.original.context_mode||"isolated")==="shared"){const f=o.original.context_group||"default",v=o.original.continuity_mode==="deeper";return e.jsxs("div",{className:"flex flex-col items-start gap-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx(P,{variant:"outline",className:`font-mono text-[10px] uppercase px-1.5 py-0 border ${v?"text-indigo-700 border-indigo-300/60 bg-indigo-50/50 dark:text-indigo-300 dark:border-indigo-900/40 dark:bg-indigo-900/20":"text-emerald-700 border-emerald-300/60 bg-emerald-50/50 dark:text-emerald-300 dark:border-emerald-900/40 dark:bg-emerald-900/20"}`,children:s(v?"accountsTable.badges.deeper":"accountsTable.badges.shared")}),e.jsx("span",{className:"text-xs font-semibold text-foreground/80",children:f})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground whitespace-nowrap",children:o.original.sameGroupPeerCount>0?s("accountsTable.sameGroupPeerCount",{count:o.original.sameGroupPeerCount}):s("accountsTable.noSameGroupPeer")})]})}return o.original.context_inferred?e.jsxs("div",{className:"flex flex-col items-start gap-1",children:[e.jsx(P,{variant:"outline",className:"text-amber-700 border-amber-300/60 bg-amber-50/50 dark:text-amber-400 dark:border-amber-900/40 dark:bg-amber-900/20 font-mono text-[10px] uppercase px-1.5 py-0",children:s("accountsTable.badges.legacy")}),e.jsx("p",{className:"text-[10px] text-amber-700/80 dark:text-amber-400/80 whitespace-nowrap",children:s("accountsTable.legacyReview")})]}):e.jsx("div",{className:"flex flex-col items-start gap-1.5",children:e.jsx(P,{variant:"secondary",className:"font-mono text-[10px] uppercase px-1.5 py-0 text-muted-foreground bg-muted/60 border-transparent shadow-none",children:s("accountsTable.badges.isolated")})})}},{id:"actions",header:s("accountsTable.actions"),size:220,cell:({row:o})=>{const d=o.original.name===r,f=i.isPending||c.isPending||n.isPending,v=o.original.type==="cliproxy",j=o.original.context_inferred||o.original.continuity_inferred;return e.jsxs("div",{className:"flex items-center gap-1",children:[!v&&e.jsxs(b,{variant:"outline",size:"sm",className:"h-8 px-2",disabled:f,onClick:()=>x(o.original),title:s("accountsTable.syncTitle"),children:[e.jsx(Ee,{className:"w-3.5 h-3.5 mr-1"}),s("accountsTable.sync")]}),!v&&j&&e.jsxs(b,{variant:"ghost",size:"sm",className:"h-8 px-2 text-amber-700 hover:text-amber-700 hover:bg-amber-500/10 dark:text-amber-400 dark:hover:text-amber-400",disabled:f,onClick:()=>n.mutate({name:o.original.name,context_mode:o.original.context_mode==="shared"?"shared":"isolated",context_group:o.original.context_mode==="shared"?o.original.context_group||"default":void 0,continuity_mode:o.original.context_mode==="shared"?o.original.continuity_mode==="deeper"?"deeper":"standard":void 0}),title:s("accountsTable.confirmLegacyTitle"),children:[e.jsx(Ue,{className:"w-3 h-3 mr-1"}),s("accountsTable.confirm")]}),e.jsxs(b,{variant:d?"secondary":"default",size:"sm",className:"h-8 px-2",disabled:d||f,onClick:()=>i.mutate(o.original.name),children:[e.jsx(Y,{className:`w-3 h-3 mr-1 ${d?"opacity-50":""}`}),s(d?"accountsTable.active":"accountsTable.setDefault")]}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-8 px-2 text-destructive hover:text-destructive hover:bg-destructive/10",disabled:d||f,onClick:()=>m(o.original.name),title:s(d?"accountsTable.cannotDeleteDefault":"accountsTable.deleteAccount"),children:e.jsx(Be,{className:"w-4 h-4"})})]})}}],N=ke({data:a,columns:l,getCoreRowModel:we()});return a.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:s("accountsTable.noAccounts")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"border rounded-md",children:e.jsxs(Pe,{children:[e.jsx(Ae,{children:N.getHeaderGroups().map(o=>e.jsx(te,{children:o.headers.map(d=>{const f={name:"w-[200px]",type:"w-[100px]",created:"w-[150px]",last_used:"w-[150px]",context:"w-[170px]",actions:"w-[290px]"}[d.id]||"w-auto";return e.jsx(De,{className:f,children:d.isPlaceholder?null:ee(d.column.columnDef.header,d.getContext())},d.id)})},o.id))}),e.jsx(_e,{children:N.getRowModel().rows.map(o=>e.jsx(te,{children:o.getVisibleCells().map(d=>e.jsx(Te,{children:ee(d.column.columnDef.cell,d.getContext())},d.id))},o.id))})]})}),r&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>p.mutate(),disabled:p.isPending,children:[e.jsx(Qe,{className:"w-4 h-4 mr-2"}),s("accountsTable.resetToDefault")]})})]}),y&&e.jsx(nt,{account:y,groupSummaries:t,plainCcsLane:u,onClose:()=>x(null)}),e.jsx(ze,{open:!!h,onOpenChange:o=>!o&&m(null),children:e.jsxs($e,{children:[e.jsxs(Fe,{children:[e.jsx(Le,{children:s("accountsTable.deleteDialogTitle")}),e.jsx(Ke,{children:s("accountsTable.deleteDialogDesc",{name:h??""})})]}),e.jsxs(He,{children:[e.jsx(Ie,{children:s("accountsTable.cancel")}),e.jsx(qe,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>{h&&(c.mutate(h),m(null))},children:s("accountsTable.delete")})]})]})})]})}const X=({titleKey:a,descKey:r})=>{const{t}=z();return e.jsxs(Ge,{children:[e.jsx(Me,{asChild:!0,children:e.jsx(b,{variant:"ghost",size:"icon","aria-label":t(a),className:"h-5 w-5 rounded-full hover:bg-muted text-muted-foreground/70 transition-colors",children:e.jsx(fe,{className:"h-3 w-3"})})}),e.jsxs(Re,{className:"w-72 p-4 rounded-xl shadow-lg border-border/50 text-sm",side:"top",align:"center",children:[e.jsx("p",{className:"font-semibold tracking-tight",children:t(a)}),e.jsx("p",{className:"mt-1.5 text-muted-foreground leading-relaxed",children:t(r)})]})]})};function ie({totalAccounts:a,primaryAccountName:r,isolatedCount:t,sharedStandardCount:u,deeperSharedCount:s,sharedAloneCount:i,sharedPeerAccountCount:c,deeperReadyAccountCount:p,sharedPeerGroups:n,deeperReadyGroups:h,legacyTargetCount:m,cliproxyCount:y,plainCcsLane:x}){const{t:l}=z(),N=x?x.kind==="native"?l("continuityOverview.lane.native"):x.kind==="account-default"?l("continuityOverview.lane.accountDefault",{name:x.account_name||""}):x.kind==="account-inherited"?l("continuityOverview.lane.accountInherited",{name:x.account_name||""}):x.kind==="profile-default"?l("continuityOverview.lane.profileDefault",{name:x.profile_name||"default"}):x.label:"",o=a<2?"single":n.length===0?t===a?"isolated":"shared-alone":h.length===0?"shared-standard":t>0||i>0||p<c||h.length<n.length?"partial":"ready",d=h[0]||n[0]||"default",f=h.length>0&&(t>0||u>0||n.length>h.length),j={ready:e.jsx(Ze,{className:"h-6 w-6 text-emerald-600 dark:text-emerald-400"}),"shared-standard":e.jsx(E,{className:"h-6 w-6 text-blue-600 dark:text-blue-400"}),single:e.jsx(ge,{className:"h-6 w-6 text-stone-400"}),isolated:e.jsx(W,{className:"h-6 w-6 text-amber-600 dark:text-amber-400"}),"shared-alone":e.jsx(J,{className:"h-6 w-6 text-amber-600 dark:text-amber-400"}),partial:e.jsx(J,{className:"h-6 w-6 text-amber-600 dark:text-amber-400"})}[o],S=!!r&&x?.account_name===r,_=a>0&&!!x&&(!r||!S),w=a>1&&o!=="ready";return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(M,{className:"flex flex-col justify-between overflow-hidden relative group p-0 border-border bg-card shadow-sm hover:shadow-md transition-shadow duration-300",children:e.jsxs(R,{className:"p-6 flex flex-col h-full bg-gradient-to-br from-card to-muted/20 space-y-4",children:[e.jsx("div",{className:"flex items-start justify-between gap-4",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start gap-4",children:[e.jsx("div",{className:"rounded-2xl bg-background p-3 shadow-sm ring-1 ring-border/50 self-start shrink-0",children:j}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"text-lg font-semibold tracking-tight",children:l(`continuityReadiness.messages.${o}.title`,{group:d})}),e.jsx(P,{variant:o==="ready"?"default":"secondary",className:"rounded-full px-2.5 py-0.5 font-medium shadow-sm",children:l(`continuityReadiness.state.${o}`)})]}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-lg leading-relaxed",children:l(`continuityReadiness.messages.${o}.description`,{group:d,count:i})})]})]})}),e.jsxs("div",{className:"mt-auto pt-4 flex flex-wrap items-center gap-2",children:[y>0&&e.jsx(P,{variant:"outline",className:"text-blue-700 bg-blue-50/50 border-blue-200/60 dark:border-blue-900/40 dark:bg-blue-900/20 dark:text-blue-300",children:l("historySyncLearningMap.cliproxyManaged",{count:y})}),m>0&&e.jsx(P,{variant:"outline",className:"text-amber-700 bg-amber-50/50 border-amber-200/60 dark:border-amber-900/40 dark:bg-amber-900/20 dark:text-amber-300",children:l("historySyncLearningMap.legacyConfirmation",{count:m})}),n.length>0&&h.length===0&&e.jsx(P,{variant:"secondary",className:"font-mono text-[11px] px-2 bg-muted/50 text-muted-foreground border-transparent",children:l("continuityOverview.recommendBadge",{group:d})}),f&&e.jsx(P,{variant:"secondary",className:"font-mono text-[11px] px-2 bg-muted/50 text-muted-foreground border-transparent",children:l("continuityOverview.partialBadge",{group:d})})]})]})}),(_||w)&&e.jsx(M,{className:"border-dashed",children:e.jsxs(R,{className:"p-5 space-y-4",children:[_&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:l("continuityOverview.plainLaneTitle")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l("continuityOverview.plainLaneDescription",{lane:N||"plain ccs"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"rounded-md border bg-background px-2 py-2 font-mono text-[11px] flex items-start gap-2",children:[e.jsx("span",{className:"flex-1 break-all",children:"ccs -r"}),e.jsx(D,{value:"ccs -r",size:"icon"})]}),e.jsxs("div",{className:"rounded-md border bg-background px-2 py-2 font-mono text-[11px] flex items-start gap-2",children:[e.jsx("span",{className:"flex-1 break-all",children:"ccs auth backup default"}),e.jsx(D,{value:"ccs auth backup default",size:"icon"})]}),r?e.jsxs("div",{className:"rounded-md border bg-background px-2 py-2 font-mono text-[11px] flex items-start gap-2",children:[e.jsx("span",{className:"flex-1 break-all",children:`ccs auth default ${r}`}),e.jsx(D,{value:`ccs auth default ${r}`,size:"icon"})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:l("continuityOverview.setDefaultHint")})]})]}),w&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:l("continuityReadiness.stepsTitle")}),e.jsxs("ol",{className:"space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:l("continuityReadiness.steps.syncBoth")}),e.jsx("li",{children:l("continuityReadiness.steps.sameGroup",{group:d})}),e.jsx("li",{children:l("continuityReadiness.steps.enableDeeper")}),e.jsx("li",{children:l("continuityReadiness.steps.resumeOriginal")})]})]})]})}),e.jsxs("div",{className:"flex flex-col md:flex-row items-center gap-3",children:[e.jsxs("div",{className:"flex-1 w-full flex items-center justify-between p-3.5 rounded-xl border border-blue-300/40 bg-blue-50/50 dark:border-blue-900/30 dark:bg-blue-900/10 shadow-sm transition-colors hover:bg-blue-100/40 dark:hover:bg-blue-900/20",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(W,{className:"h-4 w-4 text-blue-700/80 dark:text-blue-400/80"}),e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-blue-900 dark:text-blue-200",children:l("historySyncLearningMap.isolated")}),e.jsx(X,{titleKey:"accountsPage.isolated",descKey:"accountsPage.isolatedDesc"})]}),e.jsx("span",{className:"text-lg font-mono font-bold text-blue-900 dark:text-blue-200",children:t})]}),e.jsx(U,{className:"hidden md:block h-4 w-4 text-muted-foreground/40 shrink-0"}),e.jsxs("div",{className:"flex-1 w-full flex items-center justify-between p-3.5 rounded-xl border border-emerald-300/40 bg-emerald-50/50 dark:border-emerald-900/30 dark:bg-emerald-900/10 shadow-sm transition-colors hover:bg-emerald-100/40 dark:hover:bg-emerald-900/20",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{className:"h-4 w-4 text-emerald-700/80 dark:text-emerald-400/80"}),e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-emerald-900 dark:text-emerald-200",children:l("historySyncLearningMap.shared")}),e.jsx(X,{titleKey:"accountsPage.sharedStandard",descKey:"accountsPage.sharedStandardDesc"})]}),e.jsx("span",{className:"text-lg font-mono font-bold text-emerald-900 dark:text-emerald-200",children:u})]}),e.jsx(U,{className:"hidden md:block h-4 w-4 text-muted-foreground/40 shrink-0"}),e.jsxs("div",{className:"flex-1 w-full flex items-center justify-between p-3.5 rounded-xl border border-indigo-300/40 bg-indigo-50/50 dark:border-indigo-900/30 dark:bg-indigo-900/10 shadow-sm transition-colors hover:bg-indigo-100/40 dark:hover:bg-indigo-900/20",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{className:"h-4 w-4 text-indigo-700/80 dark:text-indigo-400/80"}),e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-indigo-900 dark:text-indigo-200",children:l("historySyncLearningMap.deeper")}),e.jsx(X,{titleKey:"accountsPage.sharedDeeper",descKey:"accountsPage.sharedDeeperDesc"})]}),e.jsx("span",{className:"text-lg font-mono font-bold text-indigo-900 dark:text-indigo-200",children:s})]})]})]})}const le=64;function rt({open:a,onClose:r}){const{t}=z(),[u,s]=C.useState(""),[i,c]=C.useState(!1),[p,n]=C.useState(""),[h,m]=C.useState(!1),[y,x]=C.useState(!1),l=/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(u),N=p.trim().toLowerCase().replace(/\s+/g,"-"),o=N.length===0||N.length<=le&&/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(N),d=u&&l?[`ccs auth create ${u}`,i?N.length>0?`--context-group ${N}`:"--share-context":"",i&&h?"--deeper-continuity":""].filter(Boolean).join(" "):t("createAuthProfileDialog.commandFallback"),f=async()=>{!l||i&&!o||(await navigator.clipboard.writeText(d),x(!0),setTimeout(()=>x(!1),2e3))},v=()=>{s(""),c(!1),n(""),m(!1),x(!1),r()};return e.jsx(de,{open:a,onOpenChange:j=>!j&&v(),children:e.jsxs(ue,{className:"sm:max-w-md",children:[e.jsxs(xe,{children:[e.jsx(me,{children:t("createAuthProfileDialog.title")}),e.jsx(he,{children:t("createAuthProfileDialog.description")})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"profile-name",children:t("createAuthProfileDialog.profileName")}),e.jsx(V,{id:"profile-name",value:u,onChange:j=>s(j.target.value),placeholder:t("createAuthProfileDialog.profileNamePlaceholder"),autoComplete:"off"}),u&&!l&&e.jsx("p",{className:"text-xs text-destructive",children:t("createAuthProfileDialog.invalidProfileName")})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{id:"share-context",checked:i,onCheckedChange:j=>c(j===!0)}),e.jsx(T,{htmlFor:"share-context",className:"cursor-pointer",children:t("createAuthProfileDialog.enableSharedHistory")})]}),i&&e.jsxs("div",{className:"space-y-2 pl-6",children:[e.jsx(T,{htmlFor:"context-group",children:t("createAuthProfileDialog.historySyncGroupOptional")}),e.jsx(V,{id:"context-group",value:p,onChange:j=>n(j.target.value),placeholder:t("createAuthProfileDialog.historySyncGroupPlaceholder"),autoComplete:"off"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("createAuthProfileDialog.historySyncGroupHint")}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx(re,{id:"deeper-continuity",checked:h,onCheckedChange:j=>m(j===!0)}),e.jsx(T,{htmlFor:"deeper-continuity",className:"cursor-pointer",children:t("createAuthProfileDialog.deeperContinuity")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("createAuthProfileDialog.deeperContinuityHint")}),p.trim().length>0&&!o&&e.jsx("p",{className:"text-xs text-destructive",children:t("createAuthProfileDialog.invalidContextGroup",{max:le})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:t("createAuthProfileDialog.command")}),e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted rounded-md font-mono text-sm",children:[e.jsx(Xe,{className:"w-4 h-4 text-muted-foreground shrink-0"}),e.jsx("code",{className:"flex-1 break-all",children:d}),e.jsx(b,{variant:"ghost",size:"sm",className:"shrink-0 h-8 px-2",onClick:f,disabled:!l||i&&!o,children:y?e.jsx(Y,{className:"w-4 h-4 text-green-500"}):e.jsx(se,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[e.jsx("p",{children:t("createAuthProfileDialog.afterRunPrefix")}),e.jsxs("ol",{className:"list-decimal list-inside pl-2 space-y-0.5",children:[e.jsx("li",{children:t("createAuthProfileDialog.afterRunStep1")}),e.jsx("li",{children:t("createAuthProfileDialog.afterRunStep2")})]}),e.jsx("p",{className:"pt-1",children:t("createAuthProfileDialog.poolingHint")})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(b,{variant:"ghost",onClick:v,children:t("createAuthProfileDialog.close")}),e.jsx(b,{onClick:f,disabled:!l||i&&!o,children:y?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"w-4 h-4 mr-2"}),t("createAuthProfileDialog.copied")]}):e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"w-4 h-4 mr-2"}),t("createAuthProfileDialog.copyCommand")]})})]})]})]})})}function bt(){const{t:a}=z(),r=ve(),{data:t,isLoading:u}=Ye(),s=st(),[i,c]=C.useState(!1),p=t?.accounts||[],n=t?.cliproxyCount||0,h=t?.legacyContextCount||0,m=t?.legacyContinuityCount||0,y=t?.sharedCount||0,x=t?.sharedStandardCount||0,l=t?.deeperSharedCount||0,N=t?.isolatedCount||0,o=t?.sharedAloneCount||0,d=t?.sharedPeerAccountCount||0,f=t?.deeperReadyAccountCount||0,v=t?.sharedPeerGroups||[],j=t?.deeperReadyGroups||[],S=t?.sharedGroups||[],_=t?.groupSummaries||[],w=t?.plainCcsLane||null,L=p.filter(H=>H.context_inferred||H.continuity_inferred),A=L.length,B=A>0,g=()=>r("/cliproxy?provider=claude"),K=()=>r("/cliproxy?provider=claude&action=auth"),G=()=>s.mutate(L);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hidden h-full min-h-0 lg:flex",children:[e.jsxs("div",{className:"w-80 border-r flex flex-col bg-muted/20 shrink-0",children:[e.jsxs("div",{className:"p-4 border-b bg-background space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{className:"h-5 w-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:a("accountsPage.title")})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[a("accountsPage.managePrefix"),e.jsx("code",{className:"mx-1 rounded bg-muted px-1 py-0.5",children:"ccs auth"}),a("accountsPage.manageSuffix")]})]}),e.jsx(Oe,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:a("accountsPage.primaryActions")}),e.jsxs(b,{size:"sm",className:"w-full justify-start",onClick:()=>c(!0),children:[e.jsx(ae,{className:"w-4 h-4 mr-2"}),a("accountsPage.createAccount")]}),e.jsxs(b,{size:"sm",className:"w-full justify-start",onClick:K,children:[e.jsx(ne,{className:"w-4 h-4 mr-2"}),a("accountsPage.authClaudeInPool")]}),e.jsxs(b,{variant:"outline",size:"sm",className:"w-full justify-start",onClick:g,children:[a("accountsPage.openClaudePoolSettings"),e.jsx(U,{className:"w-4 h-4 ml-auto"})]})]}),B?e.jsxs("section",{className:"space-y-2",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:a("accountsPage.migrationFollowup")}),e.jsxs("div",{className:"rounded-md border border-amber-500/50 bg-amber-500/10 p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(J,{className:"h-4 w-4 mt-0.5 text-amber-700 dark:text-amber-400 shrink-0"}),e.jsxs("div",{className:"space-y-1 text-xs",children:[h>0&&e.jsx("p",{className:"text-amber-800 dark:text-amber-300",children:a("accountsPage.legacyContextPending",{count:h})}),m>0&&e.jsx("p",{className:"text-amber-800 dark:text-amber-300",children:a("accountsPage.legacyContinuityPending",{count:m})})]})]}),e.jsx(b,{variant:"secondary",size:"sm",className:"w-full justify-start",onClick:G,disabled:s.isPending||A===0,children:s.isPending?a("accountsPage.confirmingLegacy"):a("accountsPage.confirmLegacy",{count:A})})]})]}):e.jsx("div",{className:"rounded-md border bg-background px-3 py-2 text-xs text-muted-foreground",children:a("accountsPage.noLegacyFollowup")}),e.jsxs(M,{children:[e.jsxs(I,{className:"pb-2",children:[e.jsx(q,{className:"text-sm",children:a("accountsPage.quickCommands")}),e.jsx(Q,{children:a("accountsPage.quickCommandsDesc")})]}),e.jsxs(R,{className:"space-y-2",children:[e.jsxs("div",{className:"rounded-md border bg-background px-2 py-2 font-mono text-[11px] flex items-start gap-2",children:[e.jsx("span",{className:"flex-1 break-all",children:"ccs auth create work --context-group sprint-a --deeper-continuity"}),e.jsx(D,{value:"ccs auth create work --context-group sprint-a --deeper-continuity",size:"icon"})]}),e.jsxs("div",{className:"rounded-md border bg-background px-2 py-2 font-mono text-[11px] flex items-start gap-2",children:[e.jsx("span",{className:"flex-1 break-all",children:"ccs cliproxy auth claude"}),e.jsx(D,{value:"ccs cliproxy auth claude",size:"icon"})]})]})]})]})})]}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col bg-background",children:[e.jsxs("div",{className:"px-5 py-4 border-b bg-background",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{variant:"outline",children:a("accountsPage.workspaceBadge")}),e.jsx(P,{variant:"secondary",children:a("accountsPage.historySyncBadge")})]}),e.jsx("h2",{className:"mt-2 text-xl font-semibold tracking-tight",children:a("accountsPage.authAccounts")}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:[a("accountsPage.tableScopePrefix"),e.jsx("code",{className:"mx-1 rounded bg-muted px-1 py-0.5",children:"ccs auth"}),a("accountsPage.tableScopeMiddle"),e.jsx("code",{className:"mx-1 rounded bg-muted px-1 py-0.5",children:a("accountsTable.sync")}),a("accountsPage.tableScopeSuffix")]})]}),e.jsxs("div",{className:"flex-1 min-h-0 p-5 space-y-4 overflow-y-auto",children:[e.jsx(ie,{totalAccounts:p.length,primaryAccountName:p.length===1?p[0]?.name:null,isolatedCount:N,sharedStandardCount:x,deeperSharedCount:l,sharedAloneCount:o,sharedPeerAccountCount:d,deeperReadyAccountCount:f,sharedGroups:S,sharedPeerGroups:v,deeperReadyGroups:j,legacyTargetCount:A,cliproxyCount:n,plainCcsLane:w}),e.jsxs(M,{className:"flex flex-col",children:[e.jsxs(I,{className:"pb-3",children:[e.jsx(q,{className:"text-lg",children:a("accountsPage.accountMatrix")}),e.jsx(Q,{children:a("accountsPage.sharedTotalDesc",{count:y})})]}),e.jsx(R,{children:u?e.jsx("div",{className:"text-muted-foreground",children:a("accountsPage.loadingAccounts")}):e.jsx(ce,{data:p,defaultAccount:t?.default??null,groupSummaries:_,plainCcsLane:w})})]})]})]})]}),e.jsxs("div",{className:"p-4 space-y-4 lg:hidden",children:[e.jsxs(M,{children:[e.jsxs(I,{children:[e.jsx(q,{className:"text-lg",children:a("accountsPage.title")}),e.jsxs(Q,{children:[a("accountsPage.managePrefix"),e.jsx("code",{className:"mx-1 rounded bg-muted px-1 py-0.5",children:"ccs auth"}),a("accountsPage.mobileManageSuffix")]})]}),e.jsxs(R,{className:"space-y-2",children:[e.jsxs(b,{className:"w-full",onClick:()=>c(!0),children:[e.jsx(ae,{className:"w-4 h-4 mr-2"}),a("accountsPage.createAccount")]}),e.jsxs(b,{variant:"outline",className:"w-full",onClick:g,children:[a("accountsPage.openCliProxyClaudePool"),e.jsx(U,{className:"w-4 h-4 ml-2"})]}),e.jsxs(b,{variant:"outline",className:"w-full",onClick:K,children:[a("accountsPage.authClaudeInPool"),e.jsx(ne,{className:"w-4 h-4 ml-2"})]}),e.jsx(b,{variant:"outline",className:"w-full",onClick:G,disabled:s.isPending||A===0,children:s.isPending?a("accountsPage.confirmingLegacy"):a("accountsPage.confirmLegacy",{count:A})})]})]}),e.jsx(ie,{totalAccounts:p.length,primaryAccountName:p.length===1?p[0]?.name:null,isolatedCount:N,sharedStandardCount:x,deeperSharedCount:l,sharedAloneCount:o,sharedPeerAccountCount:d,deeperReadyAccountCount:f,sharedGroups:S,sharedPeerGroups:v,deeperReadyGroups:j,legacyTargetCount:A,cliproxyCount:n,plainCcsLane:w}),e.jsxs(M,{children:[e.jsx(I,{className:"pb-3",children:e.jsx(q,{className:"text-base",children:a("accountsPage.accountMatrix")})}),e.jsx(R,{children:u?e.jsx("div",{className:"text-muted-foreground",children:a("accountsPage.loadingAccounts")}):e.jsx(ce,{data:p,defaultAccount:t?.default??null,groupSummaries:_,plainCcsLane:w})})]})]}),e.jsx(rt,{open:i,onClose:()=>c(!1)})]})}export{bt as AccountsPage};
@@ -1,4 +0,0 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as u,h as qe}from"./react-vendor-CNOkPC89.js";import{B as M,c as Q,T as Ve,p as We,q as Ye,r as Ge,s as Xe,t as Ze,v as es,w as xe,d as w,a as B,n as ne,L as D,I as H,x as J,y as Ee,z as ss,A as ts,D as as,E as rs,S as ve,F as ee,G as pe,H as Re,J as ns,K as is,M as Ae,N as _e,O as Le,Q as ls,R as os,U as be,V as we,W as se,X as cs,Y as De,Z as Ne,C as Me,b as Qe,j as ds,k as ms,_ as us,$ as xs,a0 as hs,a1 as ps,a2 as gs,a3 as fs,a4 as js,a5 as Ns,a6 as vs,a7 as bs}from"./index-DOn6k1jF.js";import{a as ws,u as ge,b as Ce}from"./tanstack-CrmUhA7Z.js";import{C as fe}from"./confirm-dialog-BlSaX2gK.js";import{t as E}from"./notifications-B2HqRBj7.js";import{L as te,R as X,as as Fe,at as Cs,a9 as ae,_ as ys,au as Ie,aa as re,C as He,av as ks,a7 as Ss,aw as Ps,p as je,X as Os,ax as Ts,Z as Ue,ay as $e,n as ye,az as ke,aA as Es,aB as he,a6 as Rs,ad as As,aC as _s,w as ze,aD as Ls,x as Ke,o as Ds,aE as Ms}from"./icons-KVCk4_U8.js";import{M as Je}from"./masked-input-C2H-Ax0Z.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-QyEXocpn.js";function Qs({className:s,showTooltip:r=!0}){const a=e.jsxs(M,{variant:"outline",className:Q("bg-accent/10 border-accent/30 text-accent","dark:bg-accent/20 dark:border-accent/40 dark:text-accent-foreground",s),children:[e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"mr-1 h-3 w-3"}),"OpenRouter"]});return r?e.jsxs(Ve,{children:[e.jsx(We,{asChild:!0,children:a}),e.jsx(Ye,{children:e.jsx("p",{children:"Access 349+ models via OpenRouter"})})]}):a}function Se(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(a=>a.test(s))}function Be(s){return s?.env?(s.env.ANTHROPIC_BASE_URL||"").toLowerCase().includes("openrouter.ai"):!1}function Fs(s){return{opus:s.ANTHROPIC_DEFAULT_OPUS_MODEL||void 0,sonnet:s.ANTHROPIC_DEFAULT_SONNET_MODEL||void 0,haiku:s.ANTHROPIC_DEFAULT_HAIKU_MODEL||void 0}}function Is(s,r){const a={...s};return r.opus?a.ANTHROPIC_DEFAULT_OPUS_MODEL=r.opus:delete a.ANTHROPIC_DEFAULT_OPUS_MODEL,r.sonnet?a.ANTHROPIC_DEFAULT_SONNET_MODEL=r.sonnet:delete a.ANTHROPIC_DEFAULT_SONNET_MODEL,r.haiku?a.ANTHROPIC_DEFAULT_HAIKU_MODEL=r.haiku:delete a.ANTHROPIC_DEFAULT_HAIKU_MODEL,a}function Hs({profileName:s,target:r,data:a,settings:d,isLoading:c,isSaving:g,isTargetSaving:h,hasChanges:f,isRawJsonValid:t,onTargetChange:p,onRefresh:x,onDelete:v,onSave:C}){const y=g||h,j=c||y;return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s}),a?.path&&e.jsx(M,{variant:"outline",className:"text-xs",children:a.path.replace(/^.*\//,"")}),Be(d)&&e.jsx(Qs,{className:"ml-1"})]}),a&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(a.mtime).toLocaleString()]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Default target:"}),e.jsxs(Ge,{value:r,onValueChange:k=>{j||p(k)},disabled:j,children:[e.jsx(Xe,{className:"h-7 w-[170px] text-xs",disabled:j,children:e.jsx(Ze,{})}),e.jsxs(es,{children:[e.jsx(xe,{value:"claude",children:"Claude Code"}),e.jsx(xe,{value:"droid",children:"Factory Droid"}),e.jsx(xe,{value:"codex",children:"Codex CLI"})]})]}),h&&e.jsx(te,{className:"w-3.5 h-3.5 animate-spin text-muted-foreground"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{variant:"ghost",size:"sm",onClick:x,disabled:j,children:e.jsx(X,{className:`w-4 h-4 ${c?"animate-spin":""}`})}),v&&e.jsx(w,{variant:"ghost",size:"sm",onClick:v,disabled:y,children:e.jsx(Fe,{className:"w-4 h-4 text-destructive"})}),e.jsx(w,{size:"sm",onClick:C,disabled:y||!f||!t,children:g?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Cs,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function Us({currentSettings:s,newEnvKey:r,newEnvValue:a,onNewEnvKeyChange:d,onNewEnvValueChange:c,onEnvValueChange:g,onAddEnvVar:h}){const{t:f}=B();return e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-4",children:s?.env&&Object.keys(s.env).length>0?e.jsx(e.Fragment,{children:Object.entries(s.env).map(([t,p])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(D,{className:"text-xs font-medium flex items-center gap-2 text-muted-foreground",children:[t,Se(t)&&e.jsx(M,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:f("envEditor.sensitive")})]}),Se(t)?e.jsx(Je,{value:p,onChange:x=>g(t,x.target.value),className:"font-mono text-sm h-8"}):e.jsx(H,{value:p,onChange:x=>g(t,x.target.value),className:"font-mono text-sm h-8"})]},t))}):e.jsxs("div",{className:"py-8 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed text-sm",children:[e.jsx("p",{children:f("envEditor.none")}),e.jsx("p",{className:"text-xs mt-1 opacity-70",children:f("envEditor.noneHint")})]})})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(D,{className:"text-xs font-medium text-muted-foreground",children:f("envEditor.addVariable")}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(H,{placeholder:f("envEditor.keyPlaceholder"),value:r,onChange:t=>d(t.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:t=>t.key==="Enter"&&r.trim()&&h()}),e.jsx(H,{placeholder:f("envEditor.valuePlaceholder"),value:a,onChange:t=>c(t.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:t=>t.key==="Enter"&&r.trim()&&h()}),e.jsx(w,{variant:"outline",size:"sm",className:"h-8",onClick:h,disabled:!r.trim(),children:e.jsx(ae,{className:"w-4 h-4"})})]})]})]})}function $s({profileName:s,target:r,data:a}){const{t:d}=B(),c=r==="droid";return e.jsx(ne,{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(ys,{className:"w-4 h-4"}),d("profileEditor.profileInfo")]}),e.jsx("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:a&&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:d("profileEditor.profileName")}),e.jsx("span",{className:"font-mono",children:a.profile})]}),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:d("profileEditor.filePath")}),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:a.path}),e.jsx(J,{value:a.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:d("profileEditor.lastModified")}),e.jsx("span",{className:"text-xs",children:new Date(a.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:d("profileEditor.defaultTarget")}),e.jsx("span",{className:"font-mono",children:r})]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:d("profileEditor.quickUsage")}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsxs("div",{children:[e.jsx(D,{className:"text-xs text-muted-foreground",children:d("profileEditor.runWithProfile")}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs ",s,' "prompt"']}),e.jsx(J,{value:`ccs ${s} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(D,{className:"text-xs text-muted-foreground",children:d(c?"profileEditor.droidAliasExplicit":"profileEditor.runOnDroid")}),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:`ccs-droid ${s} "prompt"`}),e.jsx(J,{value:`ccs-droid ${s} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(D,{className:"text-xs text-muted-foreground",children:d(c?"profileEditor.overrideToClaude":"profileEditor.runOnDroidWithFlag")}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs ",s," --target ",c?"claude":"droid",' "prompt"']}),e.jsx(J,{value:`ccs ${s} --target ${c?"claude":"droid"} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(D,{className:"text-xs text-muted-foreground",children:d("profileEditor.setAsDefault")}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs default ",s]}),e.jsx(J,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function zs({value:s,onChange:r,placeholder:a="Search models...",className:d}){const[c,g]=u.useState(""),[h,f]=u.useState(null),{models:t,isLoading:p,isError:x,isFetching:v}=Ee(),C=ss(),y=u.useMemo(()=>ts(t,c,{category:h??void 0}),[t,c,h]),j=u.useMemo(()=>as(t,2),[t]),k=!c.trim()&&!h,R=u.useMemo(()=>{const n={anthropic:[],openai:[],google:[],meta:[],mistral:[],opensource:[],other:[]};y.forEach(m=>{n[m.category].push(m)});for(const m of Object.keys(n))n[m]=rs(n[m]);return n},[y]),N=u.useCallback(()=>{C()},[C]),S=t.find(n=>n.id===s);return p&&t.length===0?e.jsxs("div",{className:Q("space-y-2",d),children:[e.jsx(ve,{className:"h-10 w-full"}),e.jsx(ve,{className:"h-32 w-full"})]}):e.jsxs("div",{className:Q("space-y-2 w-full min-w-0 overflow-hidden",d),children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Ie,{className:"text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2"}),e.jsx(H,{value:c,onChange:n=>g(n.target.value),placeholder:a,className:"pl-9"})]}),e.jsx(w,{variant:"outline",size:"icon",onClick:N,disabled:v,title:"Refresh models",children:v?e.jsx(te,{className:"h-4 w-4 animate-spin"}):e.jsx(X,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs(M,{variant:h===null?"default":"outline",className:"cursor-pointer",onClick:()=>f(null),children:["All (",t.length,")"]}),Object.keys(ee).map(n=>{const m=R[n].length;return m===0?null:e.jsxs(M,{variant:h===n?"default":"outline",className:"cursor-pointer",onClick:()=>f(n),children:[ee[n]," (",m,")"]},n)})]}),S&&e.jsxs("div",{className:"bg-muted rounded-md p-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:S.name}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:[pe(S.pricing)," |"," ",Re(S.context_length)]})]}),e.jsx(ne,{className:"h-72 w-full rounded-md border",children:x?e.jsxs("div",{className:"text-destructive p-4 text-center",children:["Failed to load models."," ",e.jsx(w,{variant:"link",onClick:N,children:"Retry"})]}):y.length===0?e.jsxs("div",{className:"text-muted-foreground p-4 text-center",children:['No models found matching "',c,'"']}):e.jsxs("div",{className:"space-y-6 p-3",children:[k&&j.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"text-muted-foreground bg-background sticky top-0 mb-2 flex items-center gap-1.5 py-1.5 text-xs font-semibold border-b pb-2",children:[e.jsx(re,{className:"h-3 w-3 text-accent"}),e.jsx("span",{children:"Newest Models"})]}),e.jsx("div",{className:"space-y-1",children:j.map(n=>e.jsx(Pe,{model:n,isSelected:n.id===s,onClick:()=>r(n.id),showAge:!0},n.id))})]}),Object.keys(ee).map(n=>{const m=R[n];return m.length===0?null:e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground bg-background sticky top-0 mb-2 py-1.5 text-xs font-semibold border-b pb-2",children:ee[n]}),e.jsx("div",{className:"space-y-1",children:m.map(o=>e.jsx(Pe,{model:o,isSelected:o.id===s,onClick:()=>r(o.id)},o.id))})]},n)})]})})]})}function Pe({model:s,isSelected:r,onClick:a,showAge:d=!1}){return e.jsxs("button",{type:"button",onClick:a,className:Q("group flex w-full items-center gap-2 rounded-md px-3 py-2 text-left text-sm transition-colors","hover:bg-accent hover:text-accent-foreground",r&&"bg-accent text-accent-foreground"),children:[e.jsx("span",{className:"flex-1 min-w-0 truncate font-medium",children:s.name}),e.jsxs("span",{className:Q("flex shrink-0 items-center gap-1 text-xs whitespace-nowrap",r?"text-accent-foreground/80":"text-muted-foreground group-hover:text-accent-foreground/80"),children:[d&&s.created&&e.jsx(M,{variant:"outline",className:Q("text-[10px] px-1",r?"border-accent-foreground/30 text-accent-foreground/80":"text-accent border-accent/30 group-hover:text-accent-foreground/80 group-hover:border-accent-foreground/30"),children:ns(s.created)}),s.isFree?e.jsx(M,{variant:"secondary",className:Q("text-[10px] px-1",r?"bg-accent-foreground/20 text-accent-foreground":"group-hover:bg-accent-foreground/20 group-hover:text-accent-foreground"),children:"Free"}):s.isExacto?e.jsxs(e.Fragment,{children:[e.jsx(M,{variant:"outline",className:Q("text-[10px] px-1 border-emerald-500/50 text-emerald-600",r?"border-accent-foreground/30 text-accent-foreground/80":"group-hover:border-accent-foreground/30 group-hover:text-accent-foreground/80"),children:"Exacto"}),e.jsx("span",{className:"tabular-nums",children:pe(s.pricing)})]}):e.jsx("span",{className:"tabular-nums",children:pe(s.pricing)}),e.jsx("span",{className:"tabular-nums",children:Re(s.context_length)})]})]})}function Ks({selectedModel:s,value:r,onChange:a,className:d}){const{t:c}=B(),{models:g}=Ee(),h=u.useMemo(()=>s?is(s,g):{},[s,g]),f=()=>{a(h)},t=(x,v)=>{a({...r,[x]:v||void 0})},p=s&&Object.keys(h).length>0;return e.jsxs(Ae,{className:Q("group",d),children:[e.jsxs(_e,{className:"flex items-center gap-2 text-sm font-medium hover:underline",children:[e.jsx(He,{className:"h-4 w-4 transition-transform group-data-[state=open]:rotate-90"}),c("modelTierMapping.title"),e.jsxs("span",{className:"text-muted-foreground font-normal",children:["(",c("modelTierMapping.advanced"),")"]})]}),e.jsxs(Le,{className:"space-y-3 pt-3",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:c("modelTierMapping.description")}),p&&e.jsxs(w,{type:"button",variant:"outline",size:"sm",onClick:f,children:[e.jsx(ks,{className:"mr-1 h-4 w-4"}),c("modelTierMapping.autoSuggest",{provider:s?.split("/")[0]})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(D,{htmlFor:"tier-opus",className:"text-right",children:"Opus"}),e.jsx(H,{id:"tier-opus",value:r.opus??"",onChange:x=>t("opus",x.target.value),placeholder:c("modelTierMapping.opusPlaceholder")})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(D,{htmlFor:"tier-sonnet",className:"text-right",children:"Sonnet"}),e.jsx(H,{id:"tier-sonnet",value:r.sonnet??"",onChange:x=>t("sonnet",x.target.value),placeholder:c("modelTierMapping.sonnetPlaceholder")})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(D,{htmlFor:"tier-haiku",className:"text-right",children:"Haiku"}),e.jsx(H,{id:"tier-haiku",value:r.haiku??"",onChange:x=>t("haiku",x.target.value),placeholder:c("modelTierMapping.haikuPlaceholder")})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:c("modelTierMapping.footer")})]})]})}function Js({profileName:s,target:r,data:a,currentSettings:d,newEnvKey:c,newEnvValue:g,onNewEnvKeyChange:h,onNewEnvValueChange:f,onEnvValueChange:t,onAddEnvVar:p,onEnvBulkChange:x}){const v=Be(d),C=d?.env,y=u.useMemo(()=>Fs(C??{}),[C]),j=C??{},k=o=>{if(x){const U={...j,ANTHROPIC_MODEL:o,ANTHROPIC_DEFAULT_OPUS_MODEL:o,ANTHROPIC_DEFAULT_SONNET_MODEL:o,ANTHROPIC_DEFAULT_HAIKU_MODEL:o};x(U)}else t("ANTHROPIC_MODEL",o),t("ANTHROPIC_DEFAULT_OPUS_MODEL",o),t("ANTHROPIC_DEFAULT_SONNET_MODEL",o),t("ANTHROPIC_DEFAULT_HAIKU_MODEL",o);E.success(se.t("commonToast.appliedModelAllTiers"),{duration:2e3})},R=o=>{if(x){const U=Is(j,o);x(U)}else o.opus!==void 0&&t("ANTHROPIC_DEFAULT_OPUS_MODEL",o.opus||""),o.sonnet!==void 0&&t("ANTHROPIC_DEFAULT_SONNET_MODEL",o.sonnet||""),o.haiku!==void 0&&t("ANTHROPIC_DEFAULT_HAIKU_MODEL",o.haiku||"")},[N,S]=u.useState(!1),n=new Set(["ANTHROPIC_AUTH_TOKEN"]),m=Object.entries(j).filter(([o])=>!n.has(o));return e.jsx("div",{className:"h-full w-full min-w-0 flex flex-col",children:e.jsxs(ls,{defaultValue:"env",className:"h-full w-full min-w-0 flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(os,{className:"w-full",children:[e.jsx(be,{value:"env",className:"flex-1",children:v?"Configuration":"Environment Variables"}),e.jsx(be,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col min-w-0",children:[e.jsx(we,{value:"env",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden min-w-0",children:v?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsxs("div",{className:"h-full overflow-y-auto overflow-x-hidden p-4 space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(D,{className:"text-sm font-medium",children:"Model Selection"}),e.jsx(zs,{value:j.ANTHROPIC_MODEL,onChange:k,placeholder:"Search OpenRouter models..."})]}),e.jsx(Ks,{selectedModel:j.ANTHROPIC_MODEL,value:y,onChange:R}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{className:"text-sm font-medium",children:"API Key"}),e.jsx(Je,{value:j.ANTHROPIC_AUTH_TOKEN||"",onChange:o=>t("ANTHROPIC_AUTH_TOKEN",o.target.value),placeholder:"sk-or-v1-...",className:"font-mono text-sm"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your API key from"," ",e.jsx("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"openrouter.ai/keys"})]})]}),m.length>0&&e.jsxs(Ae,{open:N,onOpenChange:S,children:[e.jsxs(_e,{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors group",children:[e.jsx(He,{className:Q("h-4 w-4 transition-transform",N&&"rotate-90")}),e.jsx(Ss,{className:"h-4 w-4"}),e.jsx("span",{children:"Additional Variables"}),e.jsxs("span",{className:"text-xs font-normal opacity-70",children:["(",m.length,")"]})]}),e.jsx(Le,{className:"pt-4",children:e.jsx("div",{className:"space-y-3 border rounded-lg p-3 bg-muted/30",children:m.map(([o,U])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(D,{className:"text-xs text-muted-foreground",children:o}),e.jsx(H,{value:U,onChange:$=>t(o,$.target.value),className:"font-mono text-xs h-8"})]},o))})})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(D,{className:"text-xs font-medium text-muted-foreground",children:"Add Environment Variable"}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(H,{placeholder:"VARIABLE_NAME",value:c,onChange:o=>h(o.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:o=>o.key==="Enter"&&c.trim()&&p()}),e.jsx(H,{placeholder:"value",value:g,onChange:o=>f(o.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:o=>o.key==="Enter"&&c.trim()&&p()}),e.jsx(w,{variant:"outline",size:"sm",className:"h-8",onClick:p,disabled:!c.trim(),children:e.jsx(ae,{className:"w-4 h-4"})})]})]})]}):e.jsx(Us,{currentSettings:d,newEnvKey:c,newEnvValue:g,onNewEnvKeyChange:h,onNewEnvValueChange:f,onEnvValueChange:t,onAddEnvVar:p})}),e.jsx(we,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx($s,{profileName:s,target:r,data:a})})]})]})})}function Bs({profileName:s,profileTarget:r,onDelete:a,onHasChangesUpdate:d}){const[c,g]=u.useState({}),[h,f]=u.useState(!1),[t,p]=u.useState(null),[x,v]=u.useState(""),[C,y]=u.useState(""),j=ws(),{data:k,isLoading:R,isError:N,refetch:S}=ge({queryKey:["settings",s],queryFn:async()=>{const l=await fetch(`/api/settings/${s}/raw`);if(!l.ok)throw new Error(`Failed to load settings: ${l.status}`);return l.json()}}),n=k?.settings,m=u.useMemo(()=>{if(t!==null)try{return JSON.parse(t)}catch{}if(n)return{...n,env:{...n.env,...c}}},[n,c,t]),o=u.useMemo(()=>t!==null?t:n?JSON.stringify(n,null,2):"",[t,n]),U=u.useCallback(l=>{p(l)},[]),$=u.useCallback(l=>{const b={...m??{}},_=b.ccs_image&&typeof b.ccs_image=="object"?{...b.ccs_image}:{};l?_.native_read=!0:delete _.native_read,Object.keys(_).length>0?b.ccs_image=_:delete b.ccs_image,p(JSON.stringify(b,null,2))},[m]),q=(l,b)=>{const _={...m?.env||{},[l]:b};g(Y=>({...Y,[l]:b})),p(JSON.stringify({...m,env:_},null,2))},K=l=>{const b={...m?.env||{},...l};g(_=>({..._,...l})),p(JSON.stringify({...m,env:b},null,2))},Z=()=>{if(!x.trim())return;const l=x.trim(),b=C,_={...m?.env||{},[l]:b};g(Y=>({...Y,[l]:b})),p(JSON.stringify({...m,env:_},null,2)),v(""),y("")},P=u.useMemo(()=>{try{return JSON.parse(o),!0}catch{return!1}},[o]),F=u.useMemo(()=>t!==null?t!==JSON.stringify(n,null,2):Object.keys(c).length>0,[t,c,n]),T=u.useDeferredValue(o),z=u.useMemo(()=>{if(!F||!P)return null;try{return JSON.parse(T)}catch{return null}},[F,P,T]),{data:V,isFetching:ie,isError:W,isPlaceholderData:le}=ge({queryKey:["settings",s,"image-analysis-status-preview",T],enabled:z!==null,placeholderData:l=>l,queryFn:async()=>{const l=await fetch(`/api/settings/${s}/image-analysis-status`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:z})});if(!l.ok)throw new Error(`Failed to preview image-analysis status: ${l.status}`);return l.json()}}),oe=F&&P&&!W?V?.imageAnalysisStatus??k?.imageAnalysisStatus:k?.imageAnalysisStatus,ce=F&&P&&!W&&V?.imageAnalysisStatus?"editor":"saved",de=F?P?W?"saved":ie&&(!V?.imageAnalysisStatus||le)?"refreshing":"preview":"invalid":"saved",me=m?.ccs_image?.native_read===!0,ue=u.useMemo(()=>{const l=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"],b=m?.env||{};return l.filter(_=>!b[_]?.trim())},[m]);u.useEffect(()=>{d?.(F)},[F,d]);const i=Ce({mutationFn:async()=>{let l;try{l=JSON.parse(o)}catch{l={...k?.settings,env:{...k?.settings?.env,...c}}}const b=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:l,expectedMtime:k?.mtime})});if(b.status===409)throw new Error("CONFLICT");if(!b.ok)throw new Error("Failed to save");return b.json()},onSuccess:()=>{j.invalidateQueries({queryKey:["settings",s]}),j.invalidateQueries({queryKey:["profiles"]}),g({}),p(null),E.success(se.t("commonToast.settingsSaved"))},onError:l=>{l.message==="CONFLICT"?f(!0):E.error(l.message)}}),A=Ce({mutationFn:async l=>(await De.profiles.update(s,{target:l}),l),onSuccess:()=>{j.invalidateQueries({queryKey:["profiles"]}),E.success(se.t("commonToast.defaultTargetUpdated"))},onError:(l,b)=>{const _=b==="droid"?"Factory Droid":b==="codex"?"Codex CLI":"Claude Code",Y=l.message.trim()?`: ${l.message}`:"";E.error(se.t("commonToast.failedUpdateDefaultTarget",{target:_,suffix:Y}))}}),O=r||"claude",I=i.isPending||A.isPending,L=async l=>{f(!1),l?(await S(),i.mutate()):(g({}),p(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(Hs,{profileName:s,target:O,data:k,settings:m,isLoading:R,isSaving:i.isPending,isTargetSaving:A.isPending,hasChanges:F,isRawJsonValid:P,onTargetChange:l=>{I||l!==O&&A.mutate(l)},onRefresh:()=>{I||S()},onDelete:a,onSave:()=>{I||i.mutate()}}),R?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(te,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):N?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load settings."}),e.jsxs(w,{variant:"outline",size:"sm",onClick:()=>S(),children:[e.jsx(X,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):e.jsxs("div",{className:"min-h-0 flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden bg-muted/5",children:e.jsx(Js,{profileName:s,target:O,data:k,currentSettings:m,newEnvKey:x,newEnvValue:C,onNewEnvKeyChange:v,onNewEnvValueChange:y,onEnvValueChange:q,onEnvBulkChange:K,onAddEnvVar:Z})}),e.jsxs("div",{className:"flex min-h-0 min-w-0 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(Ps,{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(cs,{rawJsonContent:o,isRawJsonValid:P,rawJsonEdits:t,settings:n,profileTarget:O,imageAnalysisStatus:oe,imageAnalysisStatusSource:ce,imageAnalysisStatusPreviewState:de,nativeReadPreferenceOverride:me,onToggleNativeRead:$,onChange:U,missingRequiredFields:ue})]})]}),e.jsx(fe,{open:h,title:"File Modified Externally",description:"Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>L(!0),onCancel:()=>L(!1)})]},s)}const Oe="ccs:openrouter-banner-dismissed";function qs({onCreateClick:s}){const[r,a]=u.useState(!0),{modelCount:d,isLoading:c}=Ne();u.useEffect(()=>{const h=localStorage.getItem(Oe)==="true";a(h)},[]);const g=()=>{localStorage.setItem(Oe,"true"),a(!0)};return r?null:e.jsx("div",{className:"bg-gradient-to-r from-accent to-accent/90 text-white px-4 py-3 relative shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between gap-4 max-w-screen-xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"p-1.5 bg-white/20 rounded-md shrink-0",children:e.jsx(re,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:"NEW: OpenRouter Integration"}),e.jsxs("p",{className:"text-xs text-white/80 truncate",children:["Browse ",c?"300+":`${d}+`," models from OpenAI, Anthropic, Google, Meta and more."]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s&&e.jsx(w,{size:"sm",variant:"secondary",onClick:s,className:"bg-white text-accent hover:bg-white/90 h-8",children:"Try it now"}),e.jsxs("a",{href:"https://openrouter.ai",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-white/80 hover:text-white hidden sm:flex items-center gap-1",children:["Learn more",e.jsx(je,{className:"w-3 h-3"})]}),e.jsxs(w,{size:"icon",variant:"ghost",onClick:g,className:"h-7 w-7 text-white/70 hover:text-white hover:bg-white/20",children:[e.jsx(Os,{className:"w-4 h-4"}),e.jsx("span",{className:"sr-only",children:"Dismiss"})]})]})]})})}function Vs(){return ge({queryKey:["profiles","local-runtime-readiness"],queryFn:()=>De.profiles.getLocalRuntimeReadiness(),staleTime:15e3,refetchOnWindowFocus:!1})}function G({badge:s,badgeClassName:r,className:a,title:d,description:c,visual:g,highlights:h,actionLabel:f,actionClassName:t,onAction:p,footer:x}){return e.jsxs(Me,{className:Q("flex h-full flex-col border shadow-sm",a),children:[e.jsxs(ds,{className:"space-y-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[g,e.jsx(M,{variant:"secondary",className:r,children:s})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ms,{className:"text-base",children:d}),e.jsx(us,{className:"text-sm leading-6",children:c})]})]}),e.jsxs(Qe,{className:"mt-auto flex flex-1 flex-col gap-4 pt-0",children:[e.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:h.map(v=>e.jsxs("div",{className:"flex items-center gap-2",children:[v.icon,e.jsx("span",{children:v.label})]},v.label))}),e.jsxs(w,{onClick:p,className:t,children:[f,e.jsx(Rs,{className:"ml-2 h-4 w-4"})]}),x?e.jsx("div",{className:"text-xs text-muted-foreground",children:x}):null]})]})}function Te(s,r,a){return s?s.status==="ready"?{badge:a("openrouterQuickStart.localRuntimeReadyBadge"),badgeClassName:"bg-emerald-500/10 text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-200",actionLabel:a("openrouterQuickStart.localRuntimeUseAction",{label:r}),description:a("openrouterQuickStart.localRuntimeReadyDescription"),footer:a("openrouterQuickStart.localRuntimeReadyFooter",{endpoint:s.endpoint})}:s.status==="missing-model"?{badge:a("openrouterQuickStart.localRuntimeNeedsModelBadge"),badgeClassName:"bg-amber-500/10 text-amber-700 dark:bg-amber-500/20 dark:text-amber-200",actionLabel:a("openrouterQuickStart.localRuntimeFinishAction",{label:r}),description:a("openrouterQuickStart.localRuntimeNeedsModelDescription"),footer:a("openrouterQuickStart.localRuntimeMissingModelFooter",{command:s.commandHint})}:{badge:a("openrouterQuickStart.localRuntimeOfflineBadge"),badgeClassName:"bg-muted text-muted-foreground",actionLabel:a("openrouterQuickStart.localRuntimeSetupAction",{label:r}),description:a("openrouterQuickStart.localRuntimeOfflineDescription"),footer:a("openrouterQuickStart.localRuntimeOfflineFooter",{command:s.commandHint})}:{badge:a("openrouterQuickStart.localRuntimeCheckingBadge"),badgeClassName:"bg-muted text-muted-foreground",actionLabel:a("openrouterQuickStart.localRuntimeSetupAction",{label:r}),description:a("openrouterQuickStart.localRuntimeCheckingDescription"),footer:a("openrouterQuickStart.localRuntimeCheckingFooter")}}function Ws({hasProfiles:s,profileCount:r,onOpenRouterClick:a,onAlibabaCodingPlanClick:d,onCliproxyClick:c,onCustomClick:g,onOllamaClick:h,onLlamacppClick:f}){const{t}=B(),{modelCount:p,isLoading:x}=Ne(),{data:v}=Vs(),C=x?"300+":`${p}+`,y=s?t("openrouterQuickStart.profileSummaryCount",{count:r}):t("openrouterQuickStart.profileSummaryEmpty"),j=t(s?"openrouterQuickStart.summaryExistingTitle":"openrouterQuickStart.summaryEmptyTitle"),k=s?t("openrouterQuickStart.summaryExistingDescription",{count:r}):t("openrouterQuickStart.summaryEmptyDescription"),R=v?.runtimes.find(m=>m.id==="ollama"),N=v?.runtimes.find(m=>m.id==="llamacpp"),S=Te(R,t("openrouterQuickStart.localOllamaLabel"),t),n=Te(N,t("openrouterQuickStart.localLlamacppLabel"),t);return e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-auto bg-muted/20 p-4 sm:p-6",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-7xl flex-col gap-5",children:[e.jsx(Me,{className:"border-dashed bg-background/90 shadow-sm",children:e.jsxs(Qe,{className:"flex flex-col gap-4 p-5 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(M,{variant:"secondary",children:y}),e.jsx(M,{variant:"outline",children:t("openrouterQuickStart.summaryBadgeDefaultQuality")}),e.jsx(M,{variant:"outline",children:t("openrouterQuickStart.summaryBadgeLocalLane")})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-xl font-semibold",children:j}),e.jsx("p",{className:"max-w-3xl text-sm leading-6 text-muted-foreground",children:k})]})]}),e.jsx(w,{variant:"outline",onClick:g,className:"shrink-0",children:t("openrouterQuickStart.createCustomProfile")})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ts,{className:"h-4 w-4 text-accent"}),e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-[0.12em] text-foreground/70",children:t("openrouterQuickStart.qualityLanesTitle")})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx(G,{badge:t("openrouterQuickStart.recommended"),title:t("openrouterQuickStart.title"),description:t("openrouterQuickStart.description",{modelCountLabel:C}),visual:e.jsx("div",{className:"rounded-lg bg-accent/10 p-2",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"h-5 w-5"})}),highlights:[{icon:e.jsx(Ue,{className:"h-3.5 w-3.5 text-accent"}),label:t("openrouterQuickStart.featureOneApi")},{icon:e.jsx(re,{className:"h-3.5 w-3.5 text-accent"}),label:t("openrouterQuickStart.qualityLaneHighlightDefaultQuality")}],actionLabel:t("openrouterQuickStart.createOpenRouterProfile"),actionClassName:"w-full bg-accent text-white hover:bg-accent/90",onAction:a,footer:e.jsxs(e.Fragment,{children:[t("openrouterQuickStart.getApiKeyAt")," ",e.jsxs("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-accent hover:underline",children:["openrouter.ai/keys",e.jsx(je,{className:"h-3 w-3"})]})]})}),e.jsx(G,{badge:t("alibabaCodingPlanQuickStart.recommended"),badgeClassName:"bg-orange-500/10 text-orange-700 dark:bg-orange-500/20 dark:text-orange-200",title:t("alibabaCodingPlanQuickStart.title"),description:t("openrouterQuickStart.alibabaLaneDescription"),visual:e.jsx("div",{className:"rounded-lg bg-orange-500/10 p-2",children:e.jsx("img",{src:"/assets/providers/alibabacloud-color.svg",alt:"Alibaba Coding Plan",className:"h-5 w-5"})}),highlights:[{icon:e.jsx($e,{className:"h-3.5 w-3.5 text-orange-600"}),label:t("alibabaCodingPlanQuickStart.featureEndpoint")},{icon:e.jsx(ye,{className:"h-3.5 w-3.5 text-orange-600"}),label:t("openrouterQuickStart.alibabaLaneHighlightQuality")}],actionLabel:t("alibabaCodingPlanQuickStart.createAlibabaProfile"),actionClassName:"w-full bg-orange-600 text-white hover:bg-orange-600/90",onAction:d,footer:e.jsxs(e.Fragment,{children:[t("alibabaCodingPlanQuickStart.readGuideAt")," ",e.jsxs("a",{href:"https://www.alibabacloud.com/help/en/model-studio/coding-plan",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-orange-700 hover:underline dark:text-orange-400",children:["Alibaba Cloud Model Studio",e.jsx(je,{className:"h-3 w-3"})]})]})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4 text-emerald-600"}),e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-[0.12em] text-foreground/70",children:t("openrouterQuickStart.localRuntimesTitle")})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx(G,{badge:S.badge,badgeClassName:S.badgeClassName,title:t("openrouterQuickStart.localOllamaTitle"),description:S.description,visual:e.jsx("div",{className:"rounded-lg bg-emerald-500/10 p-2",children:e.jsx("img",{src:"/icons/ollama.svg",alt:"Ollama",className:"h-5 w-5"})}),highlights:[{icon:e.jsx(Es,{className:"h-3.5 w-3.5 text-emerald-600"}),label:t("openrouterQuickStart.localOllamaHighlight")},{icon:e.jsx(re,{className:"h-3.5 w-3.5 text-emerald-600"}),label:R?.detectedModelCount&&R.detectedModelCount>0?t("openrouterQuickStart.localDetectedModels",{count:R.detectedModelCount}):t("openrouterQuickStart.localNoModelsDetected")}],actionLabel:S.actionLabel,actionClassName:"w-full bg-emerald-600 text-white hover:bg-emerald-600/90",onAction:h,footer:e.jsx("span",{children:S.footer})}),e.jsx(G,{badge:n.badge,badgeClassName:n.badgeClassName,title:t("openrouterQuickStart.localLlamacppTitle"),description:n.description,visual:e.jsx("div",{className:"rounded-lg bg-sky-500/10 p-2",children:e.jsx("img",{src:"/assets/providers/llama-cpp.svg",alt:"llama.cpp",className:"h-5 w-5"})}),highlights:[{icon:e.jsx(he,{className:"h-3.5 w-3.5 text-sky-600"}),label:t("openrouterQuickStart.localLlamacppHighlight")},{icon:e.jsx(ke,{className:"h-3.5 w-3.5 text-sky-600"}),label:N?.detectedModelCount&&N.detectedModelCount>0?t("openrouterQuickStart.localDetectedModels",{count:N.detectedModelCount}):t("openrouterQuickStart.localWaitingServer")}],actionLabel:n.actionLabel,actionClassName:"w-full bg-sky-600 text-white hover:bg-sky-600/90",onAction:f,footer:e.jsx("span",{children:n.footer})})]})]}),e.jsx("div",{className:"grid gap-4 lg:grid-cols-2",children:e.jsx(G,{badge:t("openrouterQuickStart.runtimeProviderBadge"),badgeClassName:"bg-emerald-500/10 text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-200",title:t("openrouterQuickStart.runtimeProviderTitle"),description:t("openrouterQuickStart.runtimeProviderManagedDescription"),visual:e.jsx("div",{className:"rounded-lg bg-emerald-500/10 p-2",children:e.jsx(he,{className:"h-5 w-5 text-emerald-700 dark:text-emerald-300"})}),highlights:[{icon:e.jsx(he,{className:"h-3.5 w-3.5 text-emerald-600"}),label:t("openrouterQuickStart.runtimeProviderFeatureConnectors")},{icon:e.jsx(ye,{className:"h-3.5 w-3.5 text-emerald-600"}),label:t("openrouterQuickStart.runtimeProviderFeatureSecrets")}],actionLabel:t("openrouterQuickStart.runtimeProviderTitle"),actionClassName:"w-full bg-emerald-600 text-white hover:bg-emerald-600/90",onAction:c,footer:e.jsx("span",{children:t("openrouterQuickStart.runtimeProviderFooter")})})})]})})}function Ys({onCreateClick:s}){const{modelCount:r,isLoading:a}=Ne();return e.jsx("div",{className:"p-3 border-t bg-gradient-to-r from-accent/5 to-accent/10 dark:from-accent/10 dark:to-accent/15",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 bg-accent/10 dark:bg-accent/20 rounded shrink-0",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"",className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-accent dark:text-accent-foreground",children:"OpenRouter"}),e.jsxs("p",{className:"text-[10px] text-muted-foreground truncate",children:[a?"300+":`${r}+`," models available"]})]}),e.jsxs(w,{size:"sm",variant:"ghost",onClick:s,className:"h-7 px-2 text-accent hover:text-accent hover:bg-accent/10 dark:hover:bg-accent/20",children:[e.jsx(Ue,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:"Add"})]})]})})}function Gs({onCreateClick:s}){const{t:r}=B();return e.jsx("div",{className:"p-3 border-t bg-gradient-to-r from-orange-500/5 to-orange-500/10 dark:from-orange-500/10 dark:to-orange-500/15",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 bg-orange-500/10 dark:bg-orange-500/20 rounded shrink-0",children:e.jsx("img",{src:"/assets/providers/alibabacloud-color.svg",alt:"",className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-orange-700 dark:text-orange-300",children:r("alibabaCodingPlanPromo.title")}),e.jsx("p",{className:"text-[10px] text-muted-foreground truncate",children:r("alibabaCodingPlanPromo.subtitle")})]}),e.jsxs(w,{size:"sm",variant:"ghost",onClick:s,className:"h-7 px-2 text-orange-700 dark:text-orange-300 hover:text-orange-700 hover:bg-orange-500/10 dark:hover:bg-orange-500/20",children:[e.jsx($e,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:r("alibabaCodingPlanPromo.add")})]})]})})}function mt(){const{t:s}=B(),r=qe(),{data:a,isLoading:d,isError:c,refetch:g}=xs(),h=hs(),f=ps(),t=gs(),p=fs(),x=js(),v=Ns(),[C,y]=u.useState(null),[j,k]=u.useState(""),[R,N]=u.useState(!1),[S,n]=u.useState("normal"),[m,o]=u.useState(null),[U,$]=u.useState(!1),[q,K]=u.useState(null),Z=u.useRef(null);vs();const P=u.useMemo(()=>a?.profiles||[],[a?.profiles]),F=u.useMemo(()=>P.filter(i=>i.name.toLowerCase().includes(j.toLowerCase())),[P,j]),T=C?P.find(i=>i.name===C):null,z=i=>{U&&C!==i?K(i):y(i)},V=i=>{h.mutate(i,{onSuccess:()=>{C===i&&(y(null),$(!1),K(null)),o(null)}})},ie=i=>{N(!1),z(i)},W=i=>{z(i)},le=(i,A)=>{const O=JSON.stringify(A,null,2)+`
2
- `,I=new Blob([O],{type:"application/json"}),L=URL.createObjectURL(I),l=document.createElement("a");l.href=L,l.download=i,document.body.appendChild(l),l.click(),l.remove(),URL.revokeObjectURL(L)},oe=async()=>{try{const i=await f.mutateAsync();if(i.orphans.length===0){E.success("No orphan profile settings found");return}const A=i.orphans.filter(l=>l.validation.valid).length;if(!window.confirm(`Found ${i.orphans.length} orphan settings file(s). Register ${A} valid profile(s) now?`))return;const I=await t.mutateAsync({}),L=I.skipped.length>0?`, skipped ${I.skipped.length}`:"";E.success(`Registered ${I.registered.length} profile(s)${L}`)}catch(i){E.error(i.message)}},ce=async()=>{if(!T)return;const i=window.prompt(`Copy profile "${T.name}" to new profile name:`,`${T.name}-copy`);if(!i)return;const A=i.trim();if(!A){E.error("Destination profile name cannot be empty");return}try{const O=await p.mutateAsync({name:T.name,data:{destination:A}});z(A),O.warnings&&O.warnings.length>0&&E.info(O.warnings.join(`
3
- `))}catch(O){E.error(O.message)}},de=async()=>{if(T)try{const i=await x.mutateAsync({name:T.name});le(`${T.name}.ccs-profile.json`,i.bundle),i.redacted?E.info("Export created with redacted token. Use include-secrets flow in CLI if needed."):E.success("Profile export downloaded")}catch(i){E.error(i.message)}},me=()=>{Z.current?.click()},ue=async i=>{const A=i.target.files?.[0];if(i.target.value="",!!A)try{const O=await A.text(),I=JSON.parse(O),L=await v.mutateAsync({bundle:I});L.name&&z(L.name),L.warnings&&L.warnings.length>0&&E.info(L.warnings.join(`
4
- `))}catch(O){E.error(O.message||"Failed to import profile bundle")}};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsx(qs,{onCreateClick:()=>N(!0)}),e.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",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:"mb-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(As,{className:"w-5 h-5 text-primary"}),e.jsx("div",{className:"min-w-0",children:e.jsx("h1",{className:"font-semibold",children:"Profiles"})})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(w,{size:"sm",variant:"outline",onClick:()=>void oe(),disabled:f.isPending||t.isPending,"aria-label":"Discover orphan profiles",title:"Discover orphan profiles",children:e.jsx(X,{className:`w-4 h-4 ${f.isPending?"animate-spin":""}`})}),e.jsx(w,{size:"sm",variant:"outline",onClick:me,disabled:v.isPending,"aria-label":"Import profile bundle",title:"Import profile bundle",children:e.jsx(_s,{className:"w-4 h-4"})}),e.jsxs(w,{size:"sm",onClick:()=>{N(!0)},children:[e.jsx(ae,{className:"w-4 h-4 mr-1"}),s("apiProfiles.new")]})]})]}),e.jsx("p",{className:"mb-3 text-xs leading-4 text-muted-foreground",children:"Premium APIs, local runtimes, custom endpoints"}),e.jsxs("div",{className:"relative",children:[e.jsx(Ie,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(H,{placeholder:s("apiProfiles.searchPlaceholder"),className:"pl-8 h-9",value:j,onChange:i=>k(i.target.value)})]})]}),e.jsx(ne,{className:"flex-1 min-h-0",children:d?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:s("apiProfiles.loadingProfiles")}):c?e.jsx("div",{className:"p-4 text-center",children:e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(ze,{className:"w-12 h-12 mx-auto text-destructive/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:s("apiProfiles.failedLoadTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s("apiProfiles.failedLoadDesc")})]}),e.jsxs(w,{size:"sm",variant:"outline",onClick:()=>g(),children:[e.jsx(X,{className:"w-4 h-4 mr-1"}),s("apiProfiles.retry")]})]})}):F.length===0?e.jsx("div",{className:"p-4 text-center",children:P.length===0?e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(Ls,{className:"w-12 h-12 mx-auto text-muted-foreground/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:s("apiProfiles.noProfilesYet")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s("apiProfiles.noProfilesDesc")})]}),e.jsxs(w,{size:"sm",variant:"outline",onClick:()=>{N(!0)},children:[e.jsx(ae,{className:"w-4 h-4 mr-1"}),s("apiProfiles.createProfile")]})]}):e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:s("apiProfiles.noProfileMatch",{query:j})})}):e.jsx("div",{className:"p-2 space-y-1",children:F.map(i=>e.jsx(Xs,{profile:i,isSelected:C===i.name,onSelect:()=>W(i.name),onDelete:()=>o(i.name)},i.name))})}),P.length>0&&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.jsx("span",{children:s("apiProfiles.profileCount",{count:P.length})}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ke,{className:"w-3 h-3 text-green-600"}),s("apiProfiles.configuredCount",{count:P.filter(i=>i.configured).length})]})]})}),e.jsx(Ys,{onCreateClick:()=>{n("openrouter"),N(!0)}}),e.jsx(Gs,{onCreateClick:()=>{n("alibaba-coding-plan"),N(!0)}})]}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col min-w-0 overflow-hidden",children:T?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-4 py-2 border-b bg-background flex items-center justify-end gap-2",children:[e.jsxs(w,{size:"sm",variant:"outline",onClick:()=>void ce(),disabled:p.isPending,children:[e.jsx(Ds,{className:"w-4 h-4 mr-1"}),"Copy"]}),e.jsxs(w,{size:"sm",variant:"outline",onClick:()=>void de(),disabled:x.isPending,children:[e.jsx(Ms,{className:"w-4 h-4 mr-1"}),"Export"]})]}),e.jsx(Bs,{profileName:T.name,profileTarget:T.target,onDelete:()=>o(T.name),onHasChangesUpdate:$},T.name)]}):e.jsx(Ws,{hasProfiles:P.length>0,profileCount:P.length,onCliproxyClick:()=>{r("/cliproxy/ai-providers")},onOpenRouterClick:()=>{n("openrouter"),N(!0)},onAlibabaCodingPlanClick:()=>{n("alibaba-coding-plan"),N(!0)},onOllamaClick:()=>{n("ollama"),N(!0)},onLlamacppClick:()=>{n("llamacpp"),N(!0)},onCustomClick:()=>{n("normal"),N(!0)}})})]}),e.jsx("input",{ref:Z,type:"file",accept:".json,application/json",className:"hidden",onChange:i=>void ue(i)}),e.jsx(bs,{open:R,onOpenChange:N,onSuccess:ie,initialMode:S}),e.jsx(fe,{open:!!m,title:s("apiProfiles.deleteProfileTitle"),description:s("apiProfiles.deleteProfileDesc",{name:m??""}),confirmText:s("apiProfiles.delete"),variant:"destructive",onConfirm:()=>m&&V(m),onCancel:()=>o(null)}),e.jsx(fe,{open:!!q,title:s("apiProfiles.unsavedChangesTitle"),description:s("apiProfiles.unsavedChangesDesc",{current:C??"",next:q??""}),confirmText:s("apiProfiles.discardSwitch"),variant:"destructive",onConfirm:()=>{$(!1),y(q),K(null)},onCancel:()=>K(null)})]})}function Xs({profile:s,isSelected:r,onSelect:a,onDelete:d}){return e.jsxs("div",{className:Q("group flex items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer transition-colors",r?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:a,children:[s.configured?e.jsx(Ke,{className:"w-4 h-4 text-green-600 shrink-0"}):e.jsx(ze,{className:"w-4 h-4 text-yellow-600 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:s.name}),e.jsx(M,{variant:"outline",className:"text-[10px] h-4 px-1.5 uppercase",children:s.target||"claude"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground truncate flex-1",children:s.settingsPath}),e.jsx(J,{value:s.settingsPath,size:"icon",className:"h-5 w-5 opacity-0 group-hover:opacity-100 transition-opacity"})]})]}),e.jsx(w,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",onClick:c=>{c.stopPropagation(),d()},children:e.jsx(Fe,{className:"w-3.5 h-3.5 text-destructive"})})]})}export{mt as ApiPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as i}from"./react-vendor-CNOkPC89.js";import{bv as F,be as y,bg as w,n as L,B as $,L as M,aF as A,I as O,d as P}from"./index-DOn6k1jF.js";import{R as U,w as N,x as B,ab as V,at as K,as as _,aG as q}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const R={selected:[],unattended:!1};async function k(t,a){try{const c=await t.json();return typeof c.error=="string"&&c.error.trim().length>0?c.error:a}catch{return a}}function G(){const[t,a]=i.useState(R),[c,o]=i.useState(null),[v,g]=i.useState(!0),[j,x]=i.useState(!1),[C,u]=i.useState(null),[h,b]=i.useState(null),m=i.useCallback(r=>{b(r),window.setTimeout(()=>b(null),1500)},[]),f=i.useCallback(async()=>{try{g(!0),u(null);const r=await fetch("/api/channels");if(!r.ok)throw new Error(await k(r,"Failed to load Official Channels settings"));const n=await r.json();return a(n.config??R),o(n.status??null),!0}catch(r){return u(r instanceof Error?r.message:"Unknown error"),!1}finally{g(!1)}},[]),S=i.useCallback(async(r,n="Settings saved")=>{try{x(!0),u(null);const s=await fetch("/api/channels",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!s.ok)throw new Error(await k(s,"Failed to save Official Channels settings"));const d=await s.json();return a(l=>d.config??{...l,...r}),m(n),!0}catch(s){return u(s instanceof Error?s.message:"Unknown error"),!1}finally{x(!1)}},[m]),T=i.useCallback(async(r,n)=>{try{x(!0),u(null);const s=await fetch(`/api/channels/${r}/token`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:n})});if(!s.ok)throw new Error(await k(s,`Failed to save ${r} token`));return await f()?(m(`${r} token saved`),!0):!1}catch(s){return u(s instanceof Error?s.message:"Unknown error"),!1}finally{x(!1)}},[f,m]),E=i.useCallback(async r=>{try{x(!0),u(null);const n=await fetch(`/api/channels/${r}/token`,{method:"DELETE"});if(!n.ok)throw new Error(await k(n,`Failed to clear ${r} token`));return await f()?(m(`${r} token cleared`),!0):!1}catch(n){return u(n instanceof Error?n.message:"Unknown error"),!1}finally{x(!1)}},[f,m]);return{config:t,status:c,loading:v,saving:j,error:C,success:h,fetchConfig:f,updateConfig:S,saveToken:T,clearToken:E}}const J={telegram:"",discord:"",imessage:""};function Y(t){return t==="ready"?"border-green-200 bg-green-50 text-green-900 dark:border-green-900/60 dark:bg-green-950/40 dark:text-green-100":t==="limited"?"border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-900/60 dark:bg-amber-950/40 dark:text-amber-100":"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-900/60 dark:bg-blue-950/40 dark:text-blue-100"}function z(t){return t==="ready"?"default":t==="not_selected"?"secondary":t==="unavailable"?"destructive":"outline"}function H(t){return t==="ready"?"default":t==="partial"?"outline":t==="blocked"?"destructive":"secondary"}function Q(t,a){return t.length===0?"None selected":t.map(c=>a?.find(o=>o.id===c)?.displayName??c).join(", ")}function ne(){const{config:t,status:a,loading:c,saving:o,error:v,success:g,fetchConfig:j,updateConfig:x,saveToken:C,clearToken:u}=G(),{fetchRawConfig:h}=F(),[b,m]=i.useState(J),f=Q(t.selected,a?.channels);i.useEffect(()=>{j(),h()},[j,h]);const S=async()=>{await Promise.all([j(),h()])},T=async(s,d)=>{const l=d?[...new Set([...t.selected,s])]:t.selected.filter(D=>D!==s);await x({selected:l},d?`${s} selected for auto-enable`:`${s} removed from auto-enable`)&&await Promise.all([j(),h()])},E=(s,d)=>{m(l=>({...l,[s]:d}))},r=async s=>{await C(s,b[s])&&(m(l=>({...l,[s]:""})),await h())},n=async s=>{await u(s)&&(m(l=>({...l,[s]:""})),await h())};return c?e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(U,{className:"h-5 w-5 animate-spin"}),e.jsx("span",{children:"Loading"})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${v||g?"translate-y-0 opacity-100":"pointer-events-none -translate-y-2 opacity-0"}`,children:[v&&e.jsxs(y,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(N,{className:"h-4 w-4"}),e.jsx(w,{children:v})]}),g&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-green-200 bg-green-50 px-3 py-2 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(B,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:g})]})]}),e.jsx(L,{className:"flex-1",children:e.jsxs("div",{className:"space-y-6 p-5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(V,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:"Official Channels"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Configure official Claude channels here, then run ",e.jsx("code",{children:"ccs"})," normally on a supported native Claude session."]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["CCS stores only channel selection in ",e.jsx("code",{children:"config.yaml"}),". Claude keeps the machine-level channel state under ",e.jsx("code",{children:"~/.claude/channels/"}),"."]})]})]}),a&&e.jsxs("div",{className:`rounded-xl border p-4 ${Y(a.summary.state)}`,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{variant:a.summary.state==="ready"?"default":"outline",children:a.summary.title}),e.jsx("span",{className:"text-sm font-medium",children:f})]}),e.jsx("p",{className:"text-sm",children:a.summary.message}),e.jsx("p",{className:"text-sm opacity-90",children:a.summary.nextStep})]}),e.jsxs("div",{className:"min-w-[220px] rounded-lg border border-current/10 bg-background/60 p-3 text-sm text-foreground",children:[e.jsx("p",{className:"font-medium",children:"Machine checks"}),e.jsxs("div",{className:"mt-2 space-y-1 text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:"Bun"}),e.jsx("span",{children:a.bunInstalled?"Installed":"Missing"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:"Claude Code"}),e.jsx("span",{children:a.claudeVersion.current?`v${a.claudeVersion.current}`:"Unknown"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:"Claude auth"}),e.jsx("span",{children:a.auth.authMethod??"Unknown"})]})]})]})]}),a.summary.blockers.length>0&&e.jsx("div",{className:"mt-3 space-y-1 text-sm",children:a.summary.blockers.map(s=>e.jsx("p",{children:s},s))})]}),a&&e.jsxs("div",{className:"rounded-lg border bg-muted/20 p-4",children:[e.jsx("p",{className:"font-medium",children:"Fastest path"}),e.jsxs("div",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("p",{children:"1. Turn on the channels you want below."}),e.jsx("p",{children:"2. Save Telegram or Discord bot tokens here if that channel needs one."}),e.jsxs("p",{children:["3. Run ",e.jsx("code",{children:"ccs"})," or a native Claude account profile. CCS adds"," ",e.jsx("code",{children:"--channels"})," for you on supported runs."]}),e.jsx("p",{children:a.supportMessage})]}),e.jsxs("details",{className:"mt-3 rounded-lg border bg-background p-4",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium",children:"Advanced notes and scope"}),e.jsxs("div",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("p",{children:a.accountStatusCaveat}),e.jsx("p",{children:a.stateScopeMessage})]})]})]}),a&&e.jsxs("div",{className:"rounded-lg border bg-background p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium",children:["If you run ",e.jsx("code",{children:"ccs"})," now"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a.launchPreview.detail})]}),e.jsx($,{variant:H(a.launchPreview.state),children:a.launchPreview.title})]}),e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"rounded-md bg-muted px-3 py-2 font-mono text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"You type:"})," ",a.launchPreview.command]}),e.jsxs("div",{className:"rounded-md bg-muted px-3 py-2 font-mono text-sm break-all",children:[e.jsx("span",{className:"text-muted-foreground",children:"CCS adds:"})," ",a.launchPreview.appendedArgs.length>0?a.launchPreview.appendedArgs.join(" "):"(nothing yet)"]})]}),a.launchPreview.skippedMessages.length>0&&e.jsx("div",{className:"mt-3 space-y-1 text-sm text-muted-foreground",children:a.launchPreview.skippedMessages.map(s=>e.jsx("p",{children:s},s))})]}),a?.claudeVersion.message&&a.claudeVersion.state!=="supported"&&e.jsxs(y,{children:[e.jsx(N,{className:"h-4 w-4"}),e.jsx(w,{children:a.claudeVersion.message})]}),a?.auth.message&&a.auth.state!=="eligible"&&e.jsxs(y,{children:[e.jsx(N,{className:"h-4 w-4"}),e.jsx(w,{children:a.auth.message})]}),a?.auth.orgRequirementMessage&&e.jsxs(y,{children:[e.jsx(N,{className:"h-4 w-4"}),e.jsx(w,{children:a.auth.orgRequirementMessage})]}),e.jsx("div",{className:"space-y-4",children:a?.channels.map(s=>{const d=t.selected.includes(s.id),l=b[s.id];return e.jsxs("div",{className:"rounded-lg border p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(M,{className:"text-base font-medium",children:s.displayName}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s.summary}),e.jsx("p",{className:"mt-2 font-mono text-xs text-muted-foreground",children:s.pluginSpec})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx($,{variant:z(s.setup.state),children:s.setup.label}),e.jsx(A,{checked:d,disabled:o||!!s.unavailableReason&&!d,onCheckedChange:p=>void T(s.id,p)})]})]}),e.jsxs("div",{className:"rounded-lg bg-muted/30 p-4 text-sm text-muted-foreground space-y-2",children:[e.jsx("p",{children:s.setup.detail}),e.jsx("p",{children:s.setup.nextStep})]}),s.requiresToken&&e.jsxs("div",{className:"space-y-3 rounded-lg bg-muted/30 p-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:!s.tokenConfigured&&s.tokenSource==="process_env"?`The current CCS process already has ${s.envKey}. Save it here only if you want persistent Claude channel state.`:s.tokenConfigured&&s.processEnvAvailable?`${s.envKey} is saved in Claude channel state, and the current CCS process env also provides it.`:`Save ${s.envKey} in Claude's official channel env file. The dashboard never reads the token value back after save.`}),s.tokenConfigured&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Saving here writes the same ",e.jsx("code",{children:".env"})," file as"," ",e.jsxs("code",{children:["/",s.id,":configure"]}),", so you do not need to run the configure command again after a successful save."]}),e.jsx(O,{type:"password",value:l,onChange:p=>E(s.id,p.target.value),placeholder:s.tokenConfigured?`Configured. Enter a new ${s.envKey} to replace it.`:!s.tokenConfigured&&s.tokenSource==="process_env"?`Using current CCS process env. Enter a new ${s.envKey} to save it for Claude.`:`Paste ${s.envKey}`,disabled:o}),s.tokenPath&&s.tokenSource!=="process_env"&&e.jsx("div",{className:"text-xs text-muted-foreground break-all",children:s.tokenPath}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(P,{onClick:()=>void r(s.id),disabled:o||!l.trim(),children:[e.jsx(K,{className:"mr-2 h-4 w-4"}),"Save Token"]}),e.jsxs(P,{variant:"outline",onClick:()=>void n(s.id),disabled:o||!s.tokenConfigured,children:[e.jsx(_,{className:"mr-2 h-4 w-4"}),"Clear Saved Token"]})]})]}),e.jsxs("details",{className:"rounded-lg border bg-background p-4",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium",children:"Claude-side setup commands"}),e.jsx("div",{className:"mt-3 space-y-2",children:(s.manualSetupCommands??[]).map(p=>e.jsx("div",{className:"rounded-md bg-muted px-3 py-2 font-mono text-sm break-all",children:p},p))})]})]},s.id)})}),e.jsx(y,{children:e.jsxs(w,{children:["CCS injects ",e.jsx("code",{children:"--channels"})," only for the current Claude session. Telegram, Discord, and iMessage stop receiving messages when that Claude session exits."]})}),e.jsx("div",{className:"rounded-lg border p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4 rounded-lg bg-muted/30 p-4",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx(q,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600"}),e.jsxs("div",{children:[e.jsx(M,{className:"text-sm font-medium",children:"Skip permission prompts on launch"}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:["Optional advanced behavior. CCS adds ",e.jsx("code",{children:"--dangerously-skip-permissions"})," ","only when at least one selected channel is being auto-enabled and you did not already pass a permission flag yourself."]})]})]}),e.jsx(A,{checked:t.unattended,disabled:o,onCheckedChange:s=>void(async()=>{await x({unattended:s},s?"Unattended mode enabled":"Unattended mode disabled")&&await h()})()})]})}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(P,{variant:"outline",onClick:()=>void S(),disabled:o,children:[e.jsx(U,{className:`mr-2 h-4 w-4 ${o?"animate-spin":""}`}),"Refresh"]})})]})})]})}export{ne as default};
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as W}from"./react-vendor-CNOkPC89.js";import{bb as Ce,B as p,d as y,n as se,C as u,j as f,k as j,_ as v,b as h,I as H,r as te,s as ae,t as ne,v as ie,w as re,x as F,Q as we,R as Ee,U as le,V as de,c as xe}from"./index-DOn6k1jF.js";import{u as K,a as J,b as V}from"./tanstack-CrmUhA7Z.js";import{t as E}from"./notifications-B2HqRBj7.js";import{aa as Pe,a9 as ke,L as U,at as De,as as Be,R as Ie,T as oe,ah as Te,a7 as Re}from"./icons-KVCk4_U8.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const L=["claude-extension-bindings"];async function P(s,a){const n=await fetch(Ce(s),{headers:{"Content-Type":"application/json"},...a});if(!n.ok){const l=await n.json().catch(()=>null);throw new Error(l?.error||`Request failed (${n.status})`)}return n.status===204?void 0:await n.json()}function qe(){return K({queryKey:["claude-extension-options"],queryFn:()=>P("/claude-extension/profiles")})}function Ae(s,a="vscode"){return K({queryKey:["claude-extension-setup",s,a],enabled:!!s,queryFn:()=>P(`/claude-extension/setup?profile=${encodeURIComponent(s||"")}&host=${encodeURIComponent(a)}`)})}function $e(){return K({queryKey:L,queryFn:()=>P("/claude-extension/bindings")})}function Le(s){return K({queryKey:["claude-extension-binding-status",s],enabled:!!s,queryFn:()=>P(`/claude-extension/bindings/${encodeURIComponent(s||"")}/verify`)})}function Oe(){const s=J();return V({mutationFn:a=>P("/claude-extension/bindings",{method:"POST",body:JSON.stringify(a)}),onSuccess:()=>{s.invalidateQueries({queryKey:L}),E.success("Binding created")},onError:a=>E.error(a.message)})}function Qe(){const s=J();return V({mutationFn:({id:a,binding:n})=>P(`/claude-extension/bindings/${encodeURIComponent(a)}`,{method:"PUT",body:JSON.stringify(n)}),onSuccess:(a,n)=>{s.invalidateQueries({queryKey:L}),s.invalidateQueries({queryKey:["claude-extension-binding-status",n.id]}),E.success("Binding saved")},onError:a=>E.error(a.message)})}function Ue(){const s=J();return V({mutationFn:a=>P(`/claude-extension/bindings/${encodeURIComponent(a)}`,{method:"DELETE"}),onSuccess:()=>{s.invalidateQueries({queryKey:L}),E.success("Binding deleted")},onError:a=>E.error(a.message)})}function ge(s,a){const n=J();return V({mutationFn:({id:l,target:S})=>P(`/claude-extension/bindings/${encodeURIComponent(l)}/${s}`,{method:"POST",body:JSON.stringify({target:S})}),onSuccess:l=>{n.invalidateQueries({queryKey:L}),n.setQueryData(["claude-extension-binding-status",l.bindingId],l),E.success(a)},onError:l=>E.error(l.message)})}function Fe(){return ge("apply","Binding applied")}function Ke(){return ge("reset","Managed values removed")}const Je=[];function ce(s){return{name:"",profile:s,host:"vscode",ideSettingsPath:"",notes:""}}function q(s){return{name:s.name,profile:s.profile,host:s.host,ideSettingsPath:s.ideSettingsPath||"",notes:s.notes||""}}function Ve(s){return{name:s.name.trim(),profile:s.profile.trim(),host:s.host,ideSettingsPath:s.ideSettingsPath.trim()||void 0,notes:s.notes.trim()||void 0}}function me(s){return s?.state==="applied"}function Me({state:s}){const a=s==="applied"?"border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300":s==="drifted"?"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300":s==="missing"?"border-destructive/30 bg-destructive/10 text-destructive":"border-border bg-muted text-muted-foreground";return e.jsx(p,{variant:"outline",className:a,children:s})}function _e(s){return s.replace(/[\\/]/g,"$&​")}function o({label:s,value:a,mono:n=!1,copyValue:l}){const S=typeof l=="string"&&l.trim().length>0;return e.jsxs("div",{className:"grid gap-2 text-sm sm:grid-cols-[112px_minmax(0,1fr)] sm:items-start",children:[e.jsx("span",{className:"text-muted-foreground",children:s}),S?e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx("div",{className:"min-w-0 flex-1 rounded-md border bg-muted/25 px-3 py-2",children:e.jsx("span",{className:"block text-left font-mono text-xs leading-5 [overflow-wrap:anywhere]",children:_e(a)})}),e.jsx(F,{value:l,label:`Copy ${s.toLowerCase()}`,className:"shrink-0"})]}):e.jsx("span",{className:xe("text-left sm:text-right",n&&"font-mono text-xs leading-5 [overflow-wrap:anywhere]"),children:a})]})}function ue({title:s,description:a,value:n}){return e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsx(f,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(j,{className:"text-base",children:s}),e.jsx(v,{className:"mt-1",children:a})]}),e.jsx(F,{value:n,label:`Copy ${s}`})]})}),e.jsx(h,{children:e.jsx("pre",{className:"max-h-[360px] overflow-auto rounded-lg border bg-muted/30 p-4 text-xs leading-6",children:n})})]})}function he({title:s,description:a,status:n,applyLabel:l,resetLabel:S,onApply:x,onReset:C,disabled:D,busy:B}){return e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsx(f,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(j,{className:"text-base",children:s}),e.jsx(v,{className:"mt-1",children:a})]}),n?e.jsx(Me,{state:n.state}):null]})}),e.jsxs(h,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{label:"Path",value:n?.path||"Save a binding first",mono:!0,copyValue:n?.path}),e.jsx(o,{label:"File",value:n?n.exists?"Present":"Not created yet":"Unavailable"})]}),e.jsx("div",{className:"rounded-lg border bg-muted/25 p-3 text-sm text-muted-foreground",children:n?.message||"Verify the binding after saving to inspect the current file state."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{size:"sm",className:"flex-1",onClick:x,disabled:D||B,children:[B?e.jsx(U,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,l]}),e.jsx(y,{size:"sm",variant:"outline",className:"flex-1",onClick:C,disabled:D||B,children:S})]})]})]})}function ze({binding:s,isSelected:a,onSelect:n}){return e.jsx("button",{onClick:n,className:xe("w-full rounded-lg border px-3 py-3 text-left transition-colors",a?"border-primary/40 bg-primary/10":"border-border/60 bg-card hover:bg-muted/40"),children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.name}),e.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:[s.profile," · ",s.host]})]}),e.jsx(p,{variant:"outline",className:"shrink-0",children:s.usesDefaultIdeSettingsPath?"Default path":"Custom path"})]})})}function as(){const s=qe(),a=$e(),n=Oe(),l=Qe(),S=Ue(),x=Fe(),C=Ke(),D=s.data?.profiles??[],B=s.data?.hosts??[],w=a.data?.bindings??Je,pe=D[0]?.name??"default",[fe,I]=W.useState(!1),[O,T]=W.useState(null),[G,k]=W.useState(()=>ce("default")),c=fe||w.length===0,b=!c&&w.length>0?w.find(t=>t.id===O)??(O?null:w[0]):null,g=b?.id??null,r=c||!b||O?G:q(b),Y=Ae(r.profile,r.host),A=Le(c?void 0:g||void 0),d=B.find(t=>t.id===r.host),M=D.find(t=>t.name===r.profile),_=s.error||a.error||Y.error||A.error,je=`${w.length} saved`,X=n.isPending||l.isPending,ve=x.isPending&&x.variables?.target==="shared"||C.isPending&&C.variables?.target==="shared",be=x.isPending&&x.variables?.target==="ide"||C.isPending&&C.variables?.target==="ide",Z=r.name.trim().length>0&&r.profile.trim().length>0,i=Y.data,m=A.data,ee=Math.max((i?.env.length??0)-6,0),Ne=i?.env.slice(0,6)??[];function z(){I(!0),T(null),k(ce(pe))}async function ye(){if(!Z)return;const t=Ve(r);if(!c&&g){const Q=await l.mutateAsync({id:g,binding:t});I(!1),T(Q.binding.id),k(q(Q.binding));return}const N=await n.mutateAsync(t);I(!1),T(N.binding.id),k(q(N.binding))}async function Se(){if(!g||!b||!window.confirm(`Delete binding "${b.name}"?`))return;await S.mutateAsync(g);const t=w.filter(N=>N.id!==g);t.length>0?(T(t[0].id),I(!1),k(q(t[0]))):z()}function $(t,N){if(!c&&b&&!O){T(b.id),k({...q(b),[t]:N}),I(!1);return}k(Q=>({...Q,[t]:N}))}function R(t,N){if(g){if(N==="apply"){x.mutate({id:g,target:t});return}C.mutate({id:g,target:t})}}return e.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex w-[348px] shrink-0 flex-col border-r bg-muted/30 xl:w-[372px]",children:[e.jsx("div",{className:"border-b bg-background p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"rounded-lg border bg-muted/40 p-2",children:e.jsx(Pe,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-semibold",children:"Claude Extension"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Saved IDE bindings for CCS profiles"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p,{variant:"secondary",children:je}),d?e.jsx(p,{variant:"outline",children:d.label}):null]})]}),e.jsxs(y,{size:"sm",onClick:z,className:"gap-1.5",children:[e.jsx(ke,{className:"h-3.5 w-3.5"}),"New"]})]})}),e.jsx(se,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 p-5",children:[e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:c?"Create binding":"Binding editor"}),e.jsx(v,{children:"Save a profile + IDE path once, then apply or reset it from the dashboard."})]}),e.jsxs(h,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"Binding name"}),e.jsx(H,{value:r.name,onChange:t=>$("name",t.target.value),placeholder:"VS Code · work profile"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"CCS profile"}),e.jsxs(te,{value:r.profile,onValueChange:t=>$("profile",t),children:[e.jsx(ae,{children:e.jsx(ne,{placeholder:"Select a profile"})}),e.jsx(ie,{children:D.map(t=>e.jsxs(re,{value:t.name,children:[t.label," (",t.profileType,")"]},t.name))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:M?.description||"Choose which CCS profile the IDE should inherit."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"IDE host"}),e.jsxs(te,{value:r.host,onValueChange:t=>$("host",t),children:[e.jsx(ae,{children:e.jsx(ne,{placeholder:"Select a host"})}),e.jsx(ie,{children:B.map(t=>e.jsx(re,{value:t.id,children:t.label},t.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"IDE settings path"}),e.jsx(H,{value:r.ideSettingsPath,onChange:t=>$("ideSettingsPath",t.target.value),placeholder:d?.defaultSettingsPath||"Leave blank for the default user settings path"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Leave blank to use the default user settings path for"," ",d?.label||"this IDE","."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"Notes"}),e.jsx(H,{value:r.notes,onChange:t=>$("notes",t.target.value),placeholder:"Optional reminder for this machine or workspace"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{className:"flex-1 gap-1.5",onClick:()=>void ye(),disabled:!Z||X,children:[X?e.jsx(U,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(De,{className:"h-3.5 w-3.5"}),c?"Create":"Save"]}),e.jsx(y,{variant:"outline",onClick:z,children:"Reset form"})]}),c?null:e.jsxs(y,{variant:"outline",className:"w-full gap-1.5 text-destructive hover:text-destructive",onClick:()=>void Se(),disabled:S.isPending,children:[e.jsx(Be,{className:"h-3.5 w-3.5"}),"Delete binding"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"px-1 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Saved bindings"}),e.jsx("div",{className:"space-y-2",children:w.length>0?w.map(t=>e.jsx(ze,{binding:t,isSelected:t.id===g&&!c,onSelect:()=>{I(!1),T(t.id),k(q(t))}},t.id)):e.jsx(u,{className:"border-dashed border-border/60 bg-card/60",children:e.jsx(h,{className:"pt-6 text-sm text-muted-foreground",children:"No saved bindings yet. Create one to manage apply, reset, and drift checks from the dashboard."})})})]})]})})]}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(se,{className:"h-full",children:e.jsxs("div",{className:"w-full space-y-6 p-6 xl:p-7 2xl:p-8",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[M?e.jsx(p,{variant:"outline",children:M.label}):null,d?e.jsx(p,{variant:"outline",children:d.label}):null,c?e.jsx(p,{variant:"secondary",children:"Draft"}):null,m?.sharedSettings&&me(m.sharedSettings)&&me(m.ideSettings)?e.jsx(p,{className:"bg-emerald-600 hover:bg-emerald-600",children:"In sync"}):null]}),e.jsxs("div",{className:"max-w-5xl",children:[e.jsx("h2",{className:"text-2xl font-semibold tracking-tight",children:b?.name||"Claude extension binding"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Manage the shared Claude settings file and the IDE-local settings file as two scoped targets."})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{variant:"outline",onClick:()=>void A.refetch(),disabled:c||A.isFetching,children:[A.isFetching?e.jsx(U,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(Ie,{className:"mr-1.5 h-3.5 w-3.5"}),"Verify"]}),i?e.jsx(F,{value:i.sharedSettings.command,label:"Copy persist command"}):null]})]}),_?e.jsx(u,{className:"border-destructive/40 bg-destructive/5",children:e.jsxs(h,{className:"flex items-start gap-3 pt-6 text-sm text-destructive",children:[e.jsx(oe,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("div",{children:_.message})]})}):null,_?null:e.jsxs(we,{defaultValue:"overview",className:"flex flex-col gap-6",children:[e.jsxs(Ee,{className:"w-full justify-start",children:[e.jsx(le,{value:"overview",children:"Overview"}),e.jsx(le,{value:"advanced",children:"Advanced"})]}),e.jsxs(de,{value:"overview",className:"mt-0 space-y-6",children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsx(he,{title:"Shared Claude settings",description:"Writes the managed env block inside ~/.claude/settings.json so CLI and IDE behavior stay aligned.",status:m?.sharedSettings,applyLabel:"Apply shared",resetLabel:"Reset shared",onApply:()=>R("shared","apply"),onReset:()=>R("shared","reset"),disabled:c,busy:ve}),e.jsx(he,{title:`${d?.label||"IDE"} settings.json`,description:"Writes only the Anthropic extension keys so unrelated editor preferences stay untouched.",status:m?.ideSettings,applyLabel:"Apply IDE",resetLabel:"Reset IDE",onApply:()=>R("ide","apply"),onReset:()=>R("ide","reset"),disabled:c,busy:be})]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1.15fr)_minmax(320px,0.85fr)]",children:[e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:"Resolved binding"}),e.jsx(v,{children:"The binding uses the same profile resolution as `ccs persist` and `ccs env`."})]}),e.jsxs(h,{className:"space-y-3",children:[e.jsx(o,{label:"Profile",value:i?.profile.label||r.profile||"Not selected"}),e.jsx(o,{label:"Profile type",value:i?.profile.profileType||"Unknown"}),e.jsx(o,{label:"IDE host",value:d?.label||"Not selected"}),e.jsx(o,{label:"IDE path mode",value:r.ideSettingsPath.trim()?"Custom path":"Default user path"}),e.jsx(o,{label:"Effective IDE path",value:m?.ideSettings.path||r.ideSettingsPath.trim()||d?.defaultSettingsPath||"Unavailable",mono:!0,copyValue:m?.ideSettings.path||r.ideSettingsPath.trim()||d?.defaultSettingsPath}),e.jsx(o,{label:"Persist command",value:i?.sharedSettings.command||"Save a valid binding first",mono:!0}),r.notes.trim()?e.jsx(o,{label:"Notes",value:r.notes.trim()}):null]})]}),e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:"Managed payload"}),e.jsx(v,{children:"Keep the main view short. The full JSON stays in the Advanced tab."})]}),e.jsxs(h,{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[Ne.map(t=>e.jsx(p,{variant:"secondary",className:"font-mono text-[10px]",children:t.name},t.name)),ee>0?e.jsxs(p,{variant:"outline",children:["+",ee," more"]}):null]}),e.jsx("div",{className:"rounded-lg border bg-muted/25 p-4 text-sm",children:i?.env.length?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"font-medium",children:["CCS will inject ",i.env.length," environment values."]}),e.jsx("div",{className:"text-muted-foreground",children:"The IDE-local target receives the extension schema. The shared target receives the same env block through Claude settings."})]}):e.jsx("div",{className:"text-muted-foreground",children:"This profile resolves to native Claude defaults, so apply/reset mainly clears existing CCS-managed overrides."})}),c?e.jsx("div",{className:"rounded-lg border border-dashed bg-muted/15 p-4 text-sm text-muted-foreground",children:"Save this draft to unlock apply, reset, and verify actions."}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{className:"flex-1",onClick:()=>R("all","apply"),disabled:x.isPending,children:[x.isPending&&x.variables?.target==="all"?e.jsx(U,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,"Apply both targets"]}),e.jsx(y,{variant:"outline",className:"flex-1",onClick:()=>R("all","reset"),disabled:C.isPending,children:"Reset both targets"})]})]})]})]}),i&&(i.warnings.length>0||i.notes.length>0)?e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:"Warnings"}),e.jsx(v,{children:"Operational details that can break the binding even when JSON is correct."})]}),e.jsx(h,{className:"space-y-3",children:i.warnings.length>0?i.warnings.map(t=>e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-amber-400/40 bg-amber-50/60 p-3 text-sm dark:bg-amber-950/10",children:[e.jsx(oe,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600"}),e.jsx("span",{children:t})]},t)):e.jsx("div",{className:"rounded-lg border bg-muted/20 p-3 text-sm text-muted-foreground",children:"No runtime warnings for this binding."})})]}),e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:"Notes"}),e.jsx(v,{children:"Short context from CCS about account continuity and host-specific behavior."})]}),e.jsx(h,{className:"space-y-3",children:i.notes.length>0?i.notes.map(t=>e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border bg-muted/30 p-3 text-sm",children:[e.jsx(Te,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{children:t})]},t)):e.jsx("div",{className:"rounded-lg border bg-muted/20 p-3 text-sm text-muted-foreground",children:"No extra notes for this binding."})})]})]}):null]}),e.jsx(de,{value:"advanced",className:"mt-0 space-y-6",children:i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsx(ue,{title:"Shared Claude settings JSON",description:"Managed env block for ~/.claude/settings.json.",value:i.sharedSettings.json}),e.jsx(ue,{title:`${d?.label||"IDE"} settings JSON`,description:`Anthropic extension snippet for ${d?.settingsTargetLabel||"settings.json"}.`,value:i.ideSettings.json})]}),e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsx(f,{children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(j,{className:"text-base",children:"Resolved environment payload"}),e.jsx(v,{children:"Exact environment values that the extension receives after CCS expands this profile."})]}),e.jsx(F,{value:JSON.stringify(i.env,null,2),label:"Copy environment payload"})]})}),e.jsx(h,{children:i.env.length>0?e.jsx("pre",{className:"max-h-[420px] overflow-auto rounded-lg border bg-muted/30 p-4 text-xs leading-6",children:JSON.stringify(i.env,null,2)}):e.jsx("div",{className:"rounded-lg border bg-muted/20 p-4 text-sm text-muted-foreground",children:"No env payload. This binding resolves to native Claude defaults."})})]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:"Shared target metadata"}),e.jsx(v,{children:"Useful when debugging drift or comparing with manual edits."})]}),e.jsxs(h,{className:"space-y-3",children:[e.jsx(o,{label:"Target path",value:m?.sharedSettings.path||i.sharedSettings.path,mono:!0,copyValue:m?.sharedSettings.path||i.sharedSettings.path}),e.jsx(o,{label:"Command",value:i.sharedSettings.command,mono:!0}),e.jsx(o,{label:"Current state",value:m?.sharedSettings.state||"Not verified"})]})]}),e.jsxs(u,{className:"border-border/60 bg-card/80",children:[e.jsxs(f,{children:[e.jsx(j,{className:"text-base",children:"IDE target metadata"}),e.jsx(v,{children:"Current file path plus the extension setting key used for this host."})]}),e.jsxs(h,{className:"space-y-3",children:[e.jsx(o,{label:"Target path",value:m?.ideSettings.path||r.ideSettingsPath.trim()||d?.defaultSettingsPath||i.ideSettings.path,mono:!0,copyValue:m?.ideSettings.path||r.ideSettingsPath.trim()||d?.defaultSettingsPath||i.ideSettings.path}),e.jsx(o,{label:"Settings key",value:d?.settingsKey||"Unknown",mono:!0}),e.jsx(o,{label:"Current state",value:m?.ideSettings.state||"Not verified"})]})]})]})]}):e.jsx(u,{className:"border-border/60 bg-card/80",children:e.jsxs(h,{className:"flex min-h-[240px] items-center justify-center gap-3 text-sm text-muted-foreground",children:[e.jsx(Re,{className:"h-5 w-5"}),"Choose a profile and IDE host to preview the generated payload."]})})})]})]})})})]})}export{as as ClaudeExtensionPage};