@hienlh/ppm 0.19.8 → 0.19.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/assets/skills/ppm/SKILL.md +1 -1
- package/assets/skills/ppm/references/http-api.md +2 -1
- package/dist/web/assets/{accounts-settings-section-D65EHybd.js → accounts-settings-section-C1YP1iCb.js} +1 -1
- package/dist/web/assets/{ai-resource-editor-DmOGQ_1E.js → ai-resource-editor-iMqzzz5c.js} +1 -1
- package/dist/web/assets/{ai-settings-section-Dlv_XYy3.js → ai-settings-section-B-1z-PRb.js} +1 -1
- package/dist/web/assets/{ai-settings-section-DP53HaV9.js → ai-settings-section-BJPgHUqk.js} +1 -1
- package/dist/web/assets/{appearance-settings-section-WuJwZW7v.js → appearance-settings-section-2XZgB0mV.js} +1 -1
- package/dist/web/assets/chat-tab-Bn4vZVZJ.js +15 -0
- package/dist/web/assets/{code-editor-8BjOSWul.js → code-editor-DN5GJXT3.js} +2 -2
- package/dist/web/assets/{conflict-editor-D2JPf7dR.js → conflict-editor-BpdoTEfv.js} +1 -1
- package/dist/web/assets/{csv-preview-DfHSVE7o.js → csv-preview-C3DoHISX.js} +1 -1
- package/dist/web/assets/{database-viewer-BwSf-V1L.js → database-viewer-CxZ2fdcd.js} +1 -1
- package/dist/web/assets/{diff-viewer-CQU6j7uQ.js → diff-viewer-DxzD_YSO.js} +1 -1
- package/dist/web/assets/{explorer-body-B2FmdPAx.js → explorer-body-Bpe6UX0b.js} +1 -1
- package/dist/web/assets/{explorer-window-content-CtSMepys.js → explorer-window-content-DixZaLLP.js} +1 -1
- package/dist/web/assets/{extension-manager-section-CBRXxG8W.js → extension-manager-section-D_rKLp-o.js} +1 -1
- package/dist/web/assets/{extension-webview-yfMof39w.js → extension-webview-kEtrZoRZ.js} +1 -1
- package/dist/web/assets/{files-settings-section-Dxn0H4jj.js → files-settings-section-B0wLfQ9S.js} +1 -1
- package/dist/web/assets/{general-settings-section-C3ccyyOe.js → general-settings-section-DZ3xpgwh.js} +1 -1
- package/dist/web/assets/{git-log-panel-d2XBsNFP.js → git-log-panel-BNicD2In.js} +1 -1
- package/dist/web/assets/{glide-data-grid-5Un6IKEP.js → glide-data-grid-CdK5dW5L.js} +1 -1
- package/dist/web/assets/{group-chat-tab-COcbheaZ.js → group-chat-tab-D-HXdnoU.js} +1 -1
- package/dist/web/assets/{index-DB-bD6Cx.js → index-DdMq4zqb.js} +5 -5
- package/dist/web/assets/{jira-watcher-section-BmDvZZ76.js → jira-watcher-section-DL_boZNh.js} +1 -1
- package/dist/web/assets/{keybindings-store-DAMW7K3e.js → keybindings-store-DQkz4a35.js} +1 -1
- package/dist/web/assets/{keyboard-shortcuts-section-BsZKKzf2.js → keyboard-shortcuts-section-DzQzV49E.js} +1 -1
- package/dist/web/assets/{markdown-renderer-BtrHvth9.js → markdown-renderer-BfoCOrL8.js} +1 -1
- package/dist/web/assets/{markdown-renderer-Dy4Vz3VW.js → markdown-renderer-C35QMvZp.js} +1 -1
- package/dist/web/assets/{mobile-explorer-sheet-BL1t1Ptr.js → mobile-explorer-sheet-ZHfT5IN3.js} +1 -1
- package/dist/web/assets/{notification-store-DIwuBHMP.js → notification-store-J1yP_Ebb.js} +1 -1
- package/dist/web/assets/{notifications-settings-section-CpnG8Ep4.js → notifications-settings-section-BXCaGBVc.js} +1 -1
- package/dist/web/assets/{pdf-preview-9Olujr_E.js → pdf-preview-DbRFOtQD.js} +1 -1
- package/dist/web/assets/{postgres-viewer-qQtI_Qan.js → postgres-viewer-BrQRqTso.js} +1 -1
- package/dist/web/assets/{ppmbot-settings-section-C_yNqYo1.js → ppmbot-settings-section-BEV23_SM.js} +1 -1
- package/dist/web/assets/{process-table-DH95ASxx.js → process-table-CG8d5eXs.js} +1 -1
- package/dist/web/assets/{proxy-settings-section-7OpR2hAD.js → proxy-settings-section-Cw0Wtsv0.js} +1 -1
- package/dist/web/assets/{query-audit-section-CHncxP-Z.js → query-audit-section-50B7mQal.js} +1 -1
- package/dist/web/assets/{remote-desktop-mobile-sheet-Db21Gh-Y.js → remote-desktop-mobile-sheet-DhcAyXE5.js} +2 -2
- package/dist/web/assets/{remote-desktop-mobile-view-CiKtuPVS.js → remote-desktop-mobile-view-DPF_b_jd.js} +1 -1
- package/dist/web/assets/{remote-desktop-readiness-gate-BSBIPU4d.js → remote-desktop-readiness-gate-J7E6355i.js} +1 -1
- package/dist/web/assets/{remote-desktop-window-content-CJOxXllZ.js → remote-desktop-window-content-0xsAifZH.js} +1 -1
- package/dist/web/assets/{schedules-settings-section-Q5X3kNJ8.js → schedules-settings-section-BFzMEPTd.js} +1 -1
- package/dist/web/assets/{settings-body-5804QGDH.js → settings-body-CUTsPLea.js} +2 -2
- package/dist/web/assets/{settings-tab-DgJP4K6b.js → settings-tab-DVV26vPK.js} +1 -1
- package/dist/web/assets/{settings-window-content-lyNwahx3.js → settings-window-content-z64J3tfm.js} +1 -1
- package/dist/web/assets/{sql-query-editor-DH3H3gvx.js → sql-query-editor-CwOcDbp4.js} +1 -1
- package/dist/web/assets/{sqlite-viewer-DkmaTXae.js → sqlite-viewer-DYdcqZv1.js} +1 -1
- package/dist/web/assets/streaming-store-9_9j70zt.js +1 -0
- package/dist/web/assets/{system-monitor-body-KuahlPOb.js → system-monitor-body-CugdEvdh.js} +2 -2
- package/dist/web/assets/{system-monitor-tab-BK-nYh25.js → system-monitor-tab-jnPQtmvK.js} +1 -1
- package/dist/web/assets/{system-monitor-window-content-C5TkD158.js → system-monitor-window-content-CJfcQqc2.js} +1 -1
- package/dist/web/assets/{tab-host-window-content-BwDnxvbx.js → tab-host-window-content-5Ga7BheG.js} +1 -1
- package/dist/web/assets/{team-member-sheet-Cg82OxYB.js → team-member-sheet-8FDCVZMG.js} +2 -2
- package/dist/web/assets/{team-member-window-content-FxBRzgMW.js → team-member-window-content-0JRiWRdG.js} +1 -1
- package/dist/web/assets/{terminal-tab-Bro7kJBK.js → terminal-tab-CkxJIjii.js} +1 -1
- package/dist/web/assets/{tool-cards-BDmz33Y9.js → tool-cards-DuTlfeWN.js} +2 -2
- package/dist/web/assets/{use-accounts-data-CvfdFWm3.js → use-accounts-data--pdg01TI.js} +1 -1
- package/dist/web/assets/{use-monaco-theme-D3Owwbo5.js → use-monaco-theme-DOhDvEKJ.js} +1 -1
- package/dist/web/assets/{use-remote-desktop-display-choice-DOg4xZ-8.js → use-remote-desktop-display-choice-B3VIBQxC.js} +1 -1
- package/dist/web/assets/{use-websocket-4y-ICdd7.js → use-websocket-D9MsDysx.js} +1 -1
- package/dist/web/assets/{video-preview-C70-MurL.js → video-preview-VL2Br0YM.js} +1 -1
- package/dist/web/index.html +2 -2
- package/dist/web/sw.js +1 -1
- package/package.json +1 -1
- package/src/providers/codex-app-server/codex-provider.ts +4 -0
- package/src/server/index.ts +2 -2
- package/src/server/routes/chat-global.ts +53 -0
- package/src/server/routes/chat.ts +3 -0
- package/src/server/ws/chat.ts +15 -3
- package/src/types/chat.ts +2 -0
- package/src/web/components/chat/codex-usage-panel.tsx +13 -33
- package/src/web/components/chat/message-input.tsx +3 -4
- package/src/web/hooks/use-global-events.ts +12 -2
- package/src/web/lib/slash-items-cache.ts +5 -4
- package/src/web/lib/sync-running-sessions.ts +17 -15
- package/src/web/stores/streaming-store.ts +27 -14
- package/dist/web/assets/chat-tab-B3tKoaUT.js +0 -15
- package/dist/web/assets/streaming-store-DDst3zA7.js +0 -1
- package/src/server/routes/chat-unread.ts +0 -36
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.19.11] - 2026-09-14
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- **Codex quota reset times appear in the chat panel** — the usage panel beside the chat input now shows when both the five-hour and weekly limits reset, matching Settings.
|
|
7
|
+
|
|
8
|
+
## [0.19.10] - 2026-09-14
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- **Newly installed Codex skills appear in the chat picker** — the browser skill cache now expires after one minute and is checked when reopening the picker. Refresh also clears the Codex provider cache, so installing AgentKit no longer leaves the picker stuck on the old list.
|
|
12
|
+
|
|
13
|
+
## [0.19.9] - 2026-09-14
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- **"Screen awake" turns itself off again** — once it came on it stayed on, because a session that went idle while the connection was down, or one whose id the provider re-keyed, was left marked as running with nothing able to clear it. Also stops the tab spinner lingering for the same reason.
|
|
17
|
+
|
|
3
18
|
## [0.19.8] - 2026-09-13
|
|
4
19
|
|
|
5
20
|
### Changed
|
|
@@ -71,4 +71,4 @@ This skill covers the `ppm` CLI, its HTTP API, and its config DB. It does **not*
|
|
|
71
71
|
- Third-party extensions (inspect via `ppm ext list`).
|
|
72
72
|
- The Claude Agent SDK internals (separate skill).
|
|
73
73
|
|
|
74
|
-
<!-- Generated for PPM v0.19.
|
|
74
|
+
<!-- Generated for PPM v0.19.11 at build time. Re-run `ppm export skill --install` to refresh. -->
|
|
@@ -43,6 +43,7 @@ _Base URL: `http://localhost:8080` (default; override via `ppm config set port <
|
|
|
43
43
|
|
|
44
44
|
## /api/chat
|
|
45
45
|
|
|
46
|
+
- `GET /api/chat/sessions/running`
|
|
46
47
|
- `POST /api/chat/sessions/read`
|
|
47
48
|
|
|
48
49
|
## /api/cloud
|
|
@@ -341,4 +342,4 @@ _Base URL: `http://localhost:8080` (default; override via `ppm config set port <
|
|
|
341
342
|
- `ws://<host>/ws/terminal` — PTY terminal multiplexer
|
|
342
343
|
- `ws://<host>/ws/extensions` — extension host channel
|
|
343
344
|
|
|
344
|
-
<!-- Generated from src/server/routes/ for PPM v0.19.
|
|
345
|
+
<!-- Generated from src/server/routes/ for PPM v0.19.11 -->
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./copy-BewHj66E.js";import{t as i}from"./download-DG3_9xXy.js";import{t as a}from"./flask-conical-tp8gyZGh.js";import{t as o}from"./key-round-CQpDrDxg.js";import{t as s}from"./loader-circle-DPMrnLQ2.js";import{t as c}from"./x-YDu4m2Iq.js";import{n as l,r as u}from"./api-client-oY1tC3tM.js";import{n as d}from"./utils-C9OjCrou.js";import"./portal-container-context-a399Hd9F.js";import{n as f}from"./use-is-mobile-CYW3FJFE.js";import{n as p,t as m}from"./button-2WCAS8dI.js";import{t as h}from"./mobile-bottom-sheet-B3uDlD79.js";import"./use-visual-viewport-D9O48HQt.js";import{$t as g,B as _,G as v,H as y,Hn as b,M as x,Pn as S,Qt as C,U as w,V as T,W as E,X as D,Xt as O,Y as k,Yn as A,Yt as j,Zt as M,en as N,jn as P,nn as F,or as I,tr as ee,wr as te}from"./index-DB-bD6Cx.js";import{addAccount as ne,deleteAccount as re,exchangeOAuthCode as ie,getAISettings as ae,getAccountSettings as oe,getOAuthUrl as se,getUsageHistory as ce,importAccounts as le,patchAccount as ue,testAccountToken as de,testExport as fe,testRawToken as pe,updateAccountSettings as L}from"./api-settings-BVfemzZW.js";import{a as R,c as z,i as B,l as me,n as he,o as V,r as H,t as ge,u as U}from"./use-accounts-data-CvfdFWm3.js";var W=e(t(),1),G=n(),K=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],q=Array.from({length:24},(e,t)=>t);function _e(e,t){let n=Array.from({length:7},()=>Array.from({length:24},()=>({sum:0,count:0,avg:0})));for(let r of e){let e=t===`5h`?r.five_hour_util:r.weekly_util;if(e==null)continue;let i=new Date(r.recorded_at+(r.recorded_at.endsWith(`Z`)?``:`Z`)),a=(i.getDay()+6)%7,o=i.getHours();n[a][o].sum+=e,n[a][o].count+=1}for(let e of n)for(let t of e)t.avg=t.count>0?t.sum/t.count:0;return n}function ve(e){return e.map(e=>{let t=e.reduce((e,t)=>e+t.sum,0),n=e.reduce((e,t)=>e+t.count,0);return n>0?t/n:0})}function ye(e){return q.map(t=>{let n=0,r=0;for(let i of e)n+=i[t].sum,r+=i[t].count;return r>0?n/r:0})}function J(e){return e===0?`bg-surface-elevated`:e<.3?`bg-success/30`:e<.5?`bg-success/60`:e<.7?`bg-warning/50`:e<.9?`bg-warning/80`:`bg-error/80`}function be(e){return e<.3?`bg-success`:e<.7?`bg-warning`:`bg-error`}function xe({accountId:e}){let[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(!0),[a,o]=(0,W.useState)(`5h`);(0,W.useEffect)(()=>{i(!0),ce(e).then(n).catch(()=>n([])).finally(()=>i(!1))},[e]);let c=(0,W.useMemo)(()=>t?_e(t,a):null,[t,a]),l=(0,W.useMemo)(()=>c?ve(c):[],[c]),u=(0,W.useMemo)(()=>c?ye(c):[],[c]),d=Math.max(...l,.01);if(Math.max(...u,.01),r)return(0,G.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,G.jsx)(s,{className:`size-3 animate-spin text-text-subtle`})});if(!t||t.length===0)return(0,G.jsx)(`div`,{className:`text-[10px] text-text-subtle py-2 text-center`,children:`No usage history yet`});let f=t.length,p=new Set(t.map(e=>new Date(e.recorded_at+(e.recorded_at.endsWith(`Z`)?``:`Z`)).toDateString())).size;return(0,G.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Usage Pattern (7d)`}),(0,G.jsxs)(`div`,{className:`flex gap-0.5 text-[9px]`,children:[(0,G.jsx)(`button`,{onClick:()=>o(`5h`),className:`px-1.5 py-0.5 rounded cursor-pointer transition-colors ${a===`5h`?`bg-primary/15 text-primary`:`text-text-subtle hover:text-text-secondary`}`,title:`5-hour rolling window limit — resets every 5 hours`,children:`5h`}),(0,G.jsx)(`button`,{onClick:()=>o(`weekly`),className:`px-1.5 py-0.5 rounded cursor-pointer transition-colors ${a===`weekly`?`bg-primary/15 text-primary`:`text-text-subtle hover:text-text-secondary`}`,title:`Weekly limit — resets every 7 days`,children:`Wk`})]})]}),(0,G.jsxs)(`p`,{className:`text-[9px] text-text-subtle leading-tight`,children:[`Avg `,a===`5h`?`5-hour`:`weekly`,` limit usage over `,p,`d (`,f,` samples). Higher % = closer to rate limit. Hover cells for details.`]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by day of week`}),(0,G.jsx)(`div`,{className:`flex flex-col gap-[2px] mt-0.5`,children:K.map((e,t)=>{let n=l[t]??0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-[8px] text-text-subtle w-5 shrink-0 text-right tabular-nums`,children:e}),(0,G.jsx)(`div`,{className:`flex-1 h-2.5 bg-surface-elevated rounded-sm overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-sm transition-all ${be(n)}`,style:{width:`${Math.round(n/d*100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-[8px] text-text-subtle w-6 shrink-0 text-right tabular-nums`,children:[Math.round(n*100),`%`]})]},e)})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by hour (0h-23h)`}),(0,G.jsx)(`div`,{className:`flex gap-[1px] mt-0.5`,children:q.map(e=>{let t=u[e]??0;return(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-[1px]`,children:[(0,G.jsx)(`div`,{className:`w-full aspect-square rounded-[2px] ${J(t)}`,title:`${e}:00 — avg ${Math.round(t*100)}% usage`}),e%6==0&&(0,G.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})]},e)})})]}),c&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Day x Hour heatmap`}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-[1px] mt-0.5`,children:[K.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,G.jsx)(`span`,{className:`text-[7px] text-text-subtle w-4 shrink-0 text-right`,children:e.charAt(0)}),q.map(n=>{let r=c[t][n];return(0,G.jsx)(`div`,{className:`flex-1 aspect-square rounded-[1px] ${J(r.avg)}`,title:`${e} ${n}:00 — ${r.count>0?`avg ${Math.round(r.avg*100)}% (${r.count} samples)`:`no data`}`},n)})]},e)),(0,G.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,G.jsx)(`span`,{className:`w-4 shrink-0`}),q.map(e=>(0,G.jsx)(`div`,{className:`flex-1 text-center`,children:e%6==0&&(0,G.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})},e))]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[8px] text-text-subtle`,children:[(0,G.jsx)(`span`,{children:`Low`}),(0,G.jsxs)(`div`,{className:`flex gap-[2px]`,children:[(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-success/30`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-success/60`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-warning/50`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-warning/80`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-error/80`})]}),(0,G.jsx)(`span`,{children:`High`}),(0,G.jsx)(`span`,{className:`ml-1`,children:`|`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-surface-elevated border border-border/30`}),(0,G.jsx)(`span`,{children:`No data`})]})]})}function Se({profile:e,accountId:t,onClose:n}){let r=[[`Name`,e.account?.display_name],[`Email`,e.account?.email],[`Org`,e.organization?.name],[`Type`,e.organization?.organization_type],[`Tier`,e.organization?.rate_limit_tier],[`Status`,e.organization?.subscription_status]];return(0,G.jsxs)(`section`,{className:`space-y-2 border-t border-border pt-3`,"data-testid":`account-profile-panel`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium`,children:`Profile`}),(0,G.jsx)(`button`,{className:`p-2 text-muted-foreground hover:text-foreground cursor-pointer`,onClick:n,"aria-label":`Close profile`,children:(0,G.jsx)(c,{className:`size-4`})})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-[80px_1fr] gap-x-3 gap-y-1 text-xs`,children:r.map(([e,t])=>t?(0,G.jsxs)(`span`,{className:`contents`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,G.jsx)(`span`,{className:`break-all`,children:t})]},e):null)}),(0,G.jsx)(xe,{accountId:t})]})}function Ce({display:e,onConfirm:t,onCancel:n}){let r=f(),i=(0,G.jsxs)(`div`,{className:`space-y-4`,"data-testid":`account-delete-confirm`,children:[(0,G.jsxs)(`p`,{className:`text-sm`,children:[`Remove `,(0,G.jsx)(`span`,{className:`font-medium`,children:e}),`?`]}),(0,G.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`The stored token is deleted from this machine. Any export you already made keeps working.`}),(0,G.jsxs)(`div`,{className:`flex flex-col-reverse md:flex-row gap-2 md:justify-end pt-2`,children:[(0,G.jsx)(m,{variant:`outline`,onClick:n,className:`min-h-11`,children:`Cancel`}),(0,G.jsx)(m,{variant:`destructive`,autoFocus:!1,onClick:t,className:`min-h-11`,children:`Remove account`})]})]});return r?(0,G.jsx)(h,{open:!0,onClose:n,children:(0,G.jsxs)(`div`,{className:`px-4 pb-4`,children:[(0,G.jsx)(`h2`,{className:`text-base font-semibold mb-3`,children:`Remove account`}),i]})}):(0,G.jsx)(j,{open:!0,onOpenChange:e=>{e||n()},children:(0,G.jsxs)(O,{className:`sm:max-w-sm`,children:[(0,G.jsx)(g,{children:(0,G.jsx)(N,{className:`text-sm`,children:`Remove account`})}),i]})})}function we({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(``),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(null),[h,_]=(0,W.useState)(``),[v,y]=(0,W.useState)(!1),[b,x]=(0,W.useState)(`idle`);function S(){p(null),_(``),x(`idle`),d(null)}function w(){t(!1),S(),i(``),o(``),d(null)}async function T(){y(!0),d(null);try{let{url:e,state:t}=await se();p(t),x(`waiting`),window.open(e,`_blank`)}catch(e){d(e.message)}y(!1)}async function E(){if(!(!h.trim()||!f)){y(!0),d(null);try{let e=h.trim();e.includes(`#`)&&(e=e.split(`#`)[0]??e);let t=await ie(e,f);w(),n(t?.status===`disabled`?`Signed in. This account is still disabled — enable it to use it.`:`Account connected via OAuth!`)}catch(e){d(e.message)}y(!1)}}async function A(){if(r.trim()){l(!0),d(null);try{let e=await ne({apiKey:r.trim(),label:a.trim()||void 0});w(),n(e?.status===`disabled`?`Token updated. This account is still disabled — enable it to use it.`:`Account added!`)}catch(e){d(e.message)}l(!1)}}let P=r.trim()?r.trim().startsWith(`sk-ant-oat`)?`OAuth token (Claude Max/Pro)`:r.trim().startsWith(`sk-ant-api`)?`API key`:`Unknown format`:``;return(0,G.jsx)(j,{open:e,onOpenChange:e=>{e||w()},children:(0,G.jsxs)(O,{className:`sm:max-w-md`,children:[(0,G.jsxs)(g,{children:[(0,G.jsx)(N,{className:`text-sm`,children:`Add Claude Account`}),(0,G.jsx)(M,{className:`text-xs leading-relaxed`,children:`Connect via OAuth (recommended) or paste a token manually.`})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: Login with Claude`}),b===`idle`?(0,G.jsx)(m,{size:`sm`,className:`w-full h-8 text-xs`,onClick:T,disabled:v,children:v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Opening...`]}):`Login with Claude`}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Authorize in the opened tab, then paste the code:`}),(0,G.jsx)(D,{placeholder:`Paste code here...`,value:h,onChange:e=>_(e.target.value),className:`text-xs h-8 font-mono`,autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,G.jsx)(m,{size:`sm`,className:`flex-1 h-7 text-xs`,onClick:E,disabled:!h.trim()||v,children:v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Connecting...`]}):`Connect`}),(0,G.jsx)(m,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:S,children:`Cancel`})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 border-t`}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste token`}),(0,G.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(k,{htmlFor:`add-token`,className:`text-xs`,children:`Token`}),(0,G.jsx)(D,{id:`add-token`,type:`password`,placeholder:`sk-ant-...`,value:r,onChange:e=>i(e.target.value),className:`text-xs h-8 font-mono`}),P&&(0,G.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Detected: `,P]})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(k,{htmlFor:`add-label`,className:`text-xs`,children:`Label (optional)`}),(0,G.jsx)(D,{id:`add-label`,placeholder:`e.g. Personal, Work`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`})]})]}),u&&(0,G.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:u}),(0,G.jsxs)(C,{children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7`,onClick:w,children:`Cancel`}),(0,G.jsx)(m,{size:`sm`,className:`text-xs h-7`,onClick:A,disabled:!r.trim()||c,children:c?`Adding...`:`Add Token`})]})]})})}function Te(e){let t=new Blob([e],{type:`application/json`}),n=document.createElement(`a`);n.href=URL.createObjectURL(t),n.download=`ppm-accounts-backup.json`,n.click(),URL.revokeObjectURL(n.href)}function Ee({open:e,onOpenChange:t,accounts:n,preselectId:a,onMessage:o}){let c=n.filter(e=>e.hasRefreshToken),[l,d]=(0,W.useState)(new Set),[f,p]=(0,W.useState)(``),[h,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)(!1),[b,x]=(0,W.useState)(!1),[S,w]=(0,W.useState)(!1);e&&!S&&(d(a?new Set([a]):new Set(c.map(e=>e.id))),w(!0)),!e&&S&&w(!1);function T(){t(!1),p(``),_(!1),y(!1)}async function E(e){if(l.size===0)return;x(!0);let t=f.trim()||`ppm-hienlh`;try{let n={"Content-Type":`application/json`},r=u();r&&(n.Authorization=`Bearer ${r}`);let i=await fetch(`/api/accounts/export`,{method:`POST`,headers:n,body:JSON.stringify({password:t,accountIds:[...l],includeRefreshToken:h,refreshBeforeExport:v})});if(!i.ok){let e=await i.json();throw Error(e.error??`Export failed: ${i.status}`)}let a=await i.text();e&&await F(a)?o?.(`Backup copied to clipboard!`):(Te(a),o?.(`Backup downloaded.`)),T()}catch{}x(!1)}let A=l.size>0&&!b;return(0,G.jsx)(j,{open:e,onOpenChange:e=>{e||T()},children:(0,G.jsxs)(O,{className:`sm:max-w-md`,children:[(0,G.jsxs)(g,{children:[(0,G.jsxs)(N,{className:`text-sm flex items-center gap-1.5`,children:[(0,G.jsx)(I,{className:`size-3.5`}),` Export Accounts`]}),(0,G.jsx)(M,{className:`text-xs`,children:`Select accounts and set a password to protect the backup.`})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Accounts to export`}),(0,G.jsx)(`button`,{className:`text-[10px] text-primary hover:underline cursor-pointer`,onClick:()=>d(l.size===c.length?new Set:new Set(c.map(e=>e.id))),children:l.size===c.length?`Deselect all`:`Select all`})]}),c.length===0?(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground p-2 border rounded`,children:`No exportable accounts.`}):(0,G.jsx)(`div`,{className:`max-h-36 overflow-y-auto space-y-1 border rounded p-2`,children:c.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`exp-${e.id}`,checked:l.has(e.id),onChange:t=>{let n=new Set(l);t.target.checked?n.add(e.id):n.delete(e.id),d(n)},className:`size-3.5 accent-primary cursor-pointer`}),(0,G.jsx)(`label`,{htmlFor:`exp-${e.id}`,className:`text-xs cursor-pointer truncate`,children:e.label??e.email??e.id.slice(0,8)})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(k,{className:`text-xs`,children:[`Password `,(0,G.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,G.jsx)(D,{type:`password`,placeholder:`Leave empty for default`,value:f,onChange:e=>p(e.target.value),className:`text-xs h-8`,autoComplete:`new-password`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`exp-full`,checked:h,onChange:e=>_(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,G.jsx)(`label`,{htmlFor:`exp-full`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens (full transfer)`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`exp-refresh`,checked:v,onChange:e=>y(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,G.jsx)(`label`,{htmlFor:`exp-refresh`,className:`text-[11px] cursor-pointer`,children:`Refresh tokens before export`})]}),h?(0,G.jsxs)(`div`,{className:`rounded-md border border-error/30 bg-error/5 p-2.5`,children:[(0,G.jsx)(`p`,{className:`text-[10px] font-medium text-error`,children:`Full transfer — source accounts will expire`}),(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Refresh tokens included. Source machine expires in ~1h after target refreshes.`})]}):v?(0,G.jsx)(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 p-2.5`,children:(0,G.jsx)(`p`,{className:`text-[10px] font-medium text-warning`,children:`Refresh before export — invalidates previous shares`})}):(0,G.jsx)(`div`,{className:`rounded-md border border-success/30 bg-success/5 p-2.5`,children:(0,G.jsx)(`p`,{className:`text-[10px] font-medium text-success`,children:`Share current token (safe)`})}),(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Encrypted with AES-256-GCM + scrypt.`})]}),(0,G.jsxs)(C,{className:`gap-1.5 flex-col sm:flex-row`,children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:T,children:`Cancel`}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,disabled:!A,onClick:()=>E(!0),children:[(0,G.jsx)(r,{className:`size-3 mr-1`}),` Copy`]}),(0,G.jsx)(m,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!A,onClick:()=>E(!1),children:b?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(i,{className:`size-3 mr-1`}),` Download`]})})]})]})})}function De({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(``),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(null);function f(){t(!1),i(``),o(``),d(null)}async function p(){if(r.trim()){l(!0),d(null);try{let e=await le({data:r.trim(),password:a.trim()||`ppm-hienlh`});f(),n(`Imported ${e.imported} account(s)`)}catch(e){d(e.message||`Import failed`)}l(!1)}}return(0,G.jsx)(j,{open:e,onOpenChange:e=>{e||f()},children:(0,G.jsxs)(O,{className:`sm:max-w-md`,children:[(0,G.jsxs)(g,{children:[(0,G.jsxs)(N,{className:`text-sm flex items-center gap-1.5`,children:[(0,G.jsx)(I,{className:`size-3.5`}),` Import Accounts`]}),(0,G.jsx)(M,{className:`text-xs`,children:`Paste backup data and enter the export password. Imported accounts are temporary (~1h).`})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(k,{className:`text-xs`,children:`Backup data`}),(0,G.jsx)(`textarea`,{value:r,onChange:e=>i(e.target.value),placeholder:`Paste backup JSON here...`,rows:4,className:`w-full text-xs p-2 rounded border border-border bg-background font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(k,{className:`text-xs`,children:[`Password `,(0,G.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,G.jsx)(D,{type:`password`,placeholder:`Leave empty for default`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`,autoComplete:`current-password`})]})]}),u&&(0,G.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:u}),(0,G.jsxs)(C,{children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:f,children:`Cancel`}),(0,G.jsx)(m,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!r.trim()||c,onClick:p,children:c?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Importing...`]}):`Import`})]})]})})}var Y=typeof window<`u`?window.matchMedia(`(min-width: 768px)`):null;function Oe(e){return Y?.addEventListener(`change`,e),()=>Y?.removeEventListener(`change`,e)}function ke(){return Y?.matches??!0}function X(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(!0);return(0,W.useEffect)(()=>{r(!0),oe().then(t).finally(()=>r(!1))},[]),n?(0,G.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Loading...`}):e?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Rotation Strategy`}),(0,G.jsxs)(_,{value:e.strategy,onValueChange:async e=>{t(await L({strategy:e}))},children:[(0,G.jsx)(w,{className:`w-full h-9 text-xs`,children:(0,G.jsx)(E,{})}),(0,G.jsxs)(T,{children:[(0,G.jsx)(y,{value:`round-robin`,children:`Round-robin`}),(0,G.jsx)(y,{value:`fill-first`,children:`Fill-first`}),(0,G.jsx)(y,{value:`lowest-usage`,children:`Lowest usage`})]})]}),(0,G.jsxs)(`p`,{className:`text-[10px] text-text-subtle`,children:[e.strategy===`round-robin`&&`Cycles through accounts evenly`,e.strategy===`fill-first`&&`Uses one account until its limit, then moves on`,e.strategy===`lowest-usage`&&`Picks the account with the lowest current usage`]})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Max Retry`}),(0,G.jsx)(`input`,{type:`number`,min:0,value:e.maxRetry,className:`w-full h-9 text-xs border rounded-md px-3 bg-background`,onChange:async e=>{let n=parseInt(e.target.value,10);!isNaN(n)&&n>=0&&t(await L({maxRetry:n}))}}),(0,G.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`How many accounts to try on failure. 0 = try all available accounts.`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Cooldown parking`}),(0,G.jsx)(v,{checked:e.cooldownEnabled,onCheckedChange:async e=>{t(await L({cooldownEnabled:e}))}})]}),(0,G.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Park a failing account (rate limit / usage limit / auth error) until it recovers. Off: accounts stay selectable — rotation still skips accounts already ≥95% on the 5-hour limit.`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs border-t border-border pt-3`,children:[(0,G.jsx)(`span`,{className:`text-text-subtle`,children:`Active accounts`}),(0,G.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.activeCount})]})]}):(0,G.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Failed to load settings`})}function Ae({open:e,onOpenChange:t}){let n=(0,W.useSyncExternalStore)(Oe,ke);return e?n?(0,G.jsx)(j,{open:e,onOpenChange:t,children:(0,G.jsxs)(O,{className:`sm:max-w-sm`,children:[(0,G.jsx)(g,{children:(0,G.jsxs)(N,{className:`text-sm flex items-center gap-2`,children:[(0,G.jsx)(b,{className:`size-4`}),` Rotation & Retry`]})}),(0,G.jsx)(X,{})]})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 transition-opacity duration-200 opacity-100`,onClick:()=>t(!1),style:{backgroundColor:`rgba(0,0,0,0.5)`}}),(0,G.jsxs)(`div`,{className:d(`fixed bottom-0 left-0 right-0 z-50 bg-background rounded-t-2xl border-t border-border shadow-2xl`,`transition-transform duration-300 ease-out max-h-[85vh] overflow-y-auto`,`translate-y-0`),children:[(0,G.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,G.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-border`})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,G.jsxs)(`span`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,G.jsx)(b,{className:`size-4`}),` Rotation & Retry`]}),(0,G.jsx)(`button`,{onClick:()=>t(!1),className:`flex items-center justify-center size-7 rounded-md hover:bg-surface-elevated transition-colors`,children:(0,G.jsx)(c,{className:`size-4`})})]}),(0,G.jsx)(`div`,{className:`px-4 py-4 pb-8`,children:(0,G.jsx)(X,{})})]})]}):null}var je=p(`inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2`,{variants:{variant:{default:`border-transparent bg-primary text-primary-foreground shadow`,secondary:`border-transparent bg-secondary text-secondary-foreground`,destructive:`border-transparent bg-destructive text-destructive-foreground shadow`,outline:`text-foreground`}},defaultVariants:{variant:`default`}});function Z({className:e,variant:t,...n}){return(0,G.jsx)(`div`,{className:d(je({variant:t}),e),...n})}function Me(e){let t=Math.floor(Date.now()/1e3);return e>t?`${Math.floor((e-t)/60)}m`:`exp`}function Ne({accounts:e}){let[t,n]=(0,W.useState)([]),[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(!1),[c,l]=(0,W.useState)(new Map),u=e.filter(e=>e.hasRefreshToken);async function d(){if(u.length!==0){i(!0);try{let e=await fe(u.map(e=>e.id),a);n(t=>[...t,{round:t.length+1,time:new Date().toLocaleTimeString(),includeRefresh:a,items:e}])}catch{}i(!1)}}async function f(e,t){l(t=>new Map(t).set(e,{loading:!0}));try{let n=await pe(t);l(t=>new Map(t).set(e,{loading:!1,...n}))}catch(t){l(n=>new Map(n).set(e,{loading:!1,status:`error`,error:t.message}))}}function p(e,t){return[{key:`r${e.round}-pre-${t.id}`,label:`Pre-export`,token:t.preExportTokenFull,preview:t.preExportToken,expires:t.preExportExpires},{key:`r${e.round}-exp-${t.id}`,label:`Exported`,token:t.exportedTokenFull,preview:t.exportedToken,expires:t.exportedExpires},{key:`r${e.round}-post-${t.id}`,label:`Post-export`,token:t.postExportTokenFull,preview:t.postExportToken,expires:t.postExportExpires}]}function h(){for(let e of t)for(let t of e.items)for(let n of p(e,t))n.token&&f(n.key,n.token)}return(0,G.jsxs)(`section`,{className:`border-t pt-4 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium`,children:`Simulate export`}),t.length>0&&(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[t.length,` round(s)`]})]}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Every run appends a round. Earlier rounds are kept so tokens can be compared across runs.`}),u.length===0?(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No OAuth account with a refresh token to export.`}):(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(v,{id:`sim-include-refresh`,checked:a,onCheckedChange:o,className:`cursor-pointer`}),(0,G.jsx)(k,{htmlFor:`sim-include-refresh`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens`})]}),(0,G.jsx)(m,{size:`sm`,className:`h-7 text-xs cursor-pointer`,disabled:r,onClick:()=>void d(),children:r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):`Run export #${t.length+1}`})]}),t.length>0&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`w-full h-7 text-[11px] cursor-pointer`,onClick:h,children:[`Test all tokens (`,t.reduce((e,t)=>e+t.items.length*3,0),`)`]}),t.map(e=>(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`p`,{className:`text-xs font-medium text-primary`,children:[`Round #`,e.round]}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.time}),(0,G.jsx)(Z,{variant:e.includeRefresh?`destructive`:`secondary`,className:`text-[9px] px-1 py-0`,children:e.includeRefresh?`with refresh`:`access only`})]}),e.items.map(t=>(0,G.jsxs)(`div`,{className:`p-2 rounded-lg border bg-card space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-[11px] font-medium`,children:t.label??t.email??t.id.slice(0,8)}),t.tokenChanged&&(0,G.jsx)(Z,{variant:`secondary`,className:`text-[9px] px-1 py-0`,children:`DB token changed`})]}),p(e,t).map(e=>{let t=c.get(e.key);return(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,G.jsx)(`span`,{className:`w-20 shrink-0 text-muted-foreground text-[10px]`,children:e.label}),(0,G.jsx)(`code`,{className:`flex-1 truncate font-mono text-[10px] bg-muted px-1 rounded`,children:e.preview??`N/A`}),e.expires&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:Me(e.expires)}),e.token?(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`h-6 text-[10px] px-1.5 cursor-pointer shrink-0`,disabled:t?.loading,onClick:()=>void f(e.key,e.token),children:t?.loading?(0,G.jsx)(s,{className:`size-3 animate-spin`}):`Test`}):(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`-`}),t&&!t.loading&&(0,G.jsx)(`span`,{className:`text-[10px] font-medium shrink-0 ${t.status?.startsWith(`valid`)?`text-success`:`text-error`}`,children:t.status})]},e.key)})]},`r${e.round}-${t.id}`))]},e.round))]})]})}function Pe(e){let t=Math.floor(Date.now()/1e3),n=Math.floor(Math.abs(e-t)/60);return e>t?`${n}m left`:`expired ${n}m ago`}function Fe({open:e,onOpenChange:t,accounts:n}){let[r,i]=(0,W.useState)(new Map),[o,c]=(0,W.useState)(!1);async function l(e){i(t=>new Map(t).set(e,{loading:!0}));try{let t=await de(e,o);i(n=>new Map(n).set(e,{loading:!1,result:t}))}catch(t){i(n=>new Map(n).set(e,{loading:!1,error:t.message}))}}function u(){for(let e of n.filter(e=>e.expiresAt!==null))l(e.id)}return(0,G.jsx)(j,{open:e,onOpenChange:t,children:(0,G.jsxs)(O,{className:`sm:max-w-xl max-h-[85vh] flex flex-col`,children:[(0,G.jsxs)(g,{children:[(0,G.jsxs)(N,{className:`text-sm flex items-center gap-1.5`,children:[(0,G.jsx)(a,{className:`size-4`}),` Token Test`]}),(0,G.jsx)(M,{className:`text-xs`,children:`Probe stored tokens for validity. Nothing is modified.`})]}),(0,G.jsxs)(`div`,{className:`space-y-4 overflow-y-auto flex-1 pr-1`,children:[(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium`,children:`Current tokens`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(v,{id:`token-test-refresh`,checked:o,onCheckedChange:c,className:`cursor-pointer`}),(0,G.jsx)(k,{htmlFor:`token-test-refresh`,className:`text-[11px] cursor-pointer`,children:`Also test refresh`})]}),(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`h-7 text-xs cursor-pointer`,onClick:u,children:`Test all`})]})]}),n.length===0&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No accounts to test.`}),(0,G.jsx)(`div`,{className:`space-y-1.5`,children:n.map(e=>{let t=r.get(e.id),n=t?.result?.accessToken.status;return(0,G.jsxs)(`div`,{className:`p-2 rounded border bg-card space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium truncate block`,children:e.label??e.email??e.id.slice(0,8)}),e.expiresAt&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:Pe(e.expiresAt)})]}),(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`h-7 text-xs cursor-pointer shrink-0`,disabled:t?.loading,onClick:()=>void l(e.id),children:t?.loading?(0,G.jsx)(s,{className:`size-3 animate-spin`}):`Test`})]}),t&&!t.loading&&(0,G.jsxs)(`div`,{className:`text-[11px] pl-2 border-l-2 border-muted`,children:[t.error&&(0,G.jsx)(`p`,{className:`text-error`,children:t.error}),n&&(0,G.jsxs)(`span`,{className:n.startsWith(`valid`)?`text-success`:`text-error`,children:[n,t.result?.accessToken.code?` (${t.result.accessToken.code})`:``]})]})]},e.id)})})]}),(0,G.jsx)(Ne,{accounts:n})]}),(0,G.jsx)(C,{children:(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Close`})})]})})}function Q(){let{usages:e,accounts:t,activeAccountId:n,initialLoading:r,refreshing:c,flashIds:l,reload:u}=ge(),[d,f]=(0,W.useState)(null),[p,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(null),[v,y]=(0,W.useState)(null),[x,S]=(0,W.useState)(null),[C,w]=(0,W.useState)(null);function T(e){u(),e&&f(e)}async function E(e,t){h(e);try{await ue(e,{status:t===`disabled`?`active`:`disabled`})}catch(e){f(e.message)}h(null),u()}async function D(){if(g){try{await re(g.id),f(`Account "${g.display}" removed.`),u()}catch(e){f(`Failed to remove: ${e.message}`)}_(null)}}let O=new Map(t.map(e=>[e.id,e])),k=e[0]?.usage.lastFetchedAt;return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(R,{description:`Connect multiple Claude accounts. PPM rotates between them automatically to avoid rate limits.`,onRefresh:()=>void u(),refreshing:c,disabled:r,actions:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(m,{size:`sm`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`add`),children:[(0,G.jsx)(A,{className:`size-4`}),` Add account`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>{S(null),w(`export`)},children:[(0,G.jsx)(i,{className:`size-4`}),` Export`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`import`),children:[(0,G.jsx)(P,{className:`size-4`}),` Import`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`rotation`),children:[(0,G.jsx)(b,{className:`size-4`}),` Rotation`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`token-test`),children:[(0,G.jsx)(a,{className:`size-4`}),` Token test`]})]})}),(0,G.jsx)(V,{message:d,onDismiss:()=>f(null)}),(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium`,children:`Accounts`}),k&&(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`usage `,me(new Date(k).getTime())]})]}),r?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-xs text-muted-foreground`,children:[(0,G.jsx)(s,{className:`size-4 animate-spin`}),` Loading accounts...`]}):e.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,G.jsx)(o,{className:`size-5 text-muted-foreground`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No accounts connected yet.`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Add one to start using PPM.`})]}):(0,G.jsx)(H,{children:e.map(e=>(0,G.jsx)(he,{layout:`strip`,entry:e,isActive:e.accountId===n,accountInfo:O.get(e.accountId),onToggle:E,toggling:p===e.accountId,onDelete:(e,t)=>_({id:e,display:t}),onExport:e=>{S(e),w(`export`)},onViewProfile:(e,t)=>y({profile:e,accountId:t}),flash:l.has(e.accountId)},e.accountId))})]}),v&&(0,G.jsx)(Se,{profile:v.profile,accountId:v.accountId,onClose:()=>y(null)}),g&&(0,G.jsx)(Ce,{display:g.display,onConfirm:()=>void D(),onCancel:()=>_(null)}),(0,G.jsx)(we,{open:C===`add`,onOpenChange:e=>w(e?`add`:null),onSuccess:T}),(0,G.jsx)(Ee,{open:C===`export`,onOpenChange:e=>{w(e?`export`:null),e||S(null)},accounts:t,preselectId:x,onMessage:f}),(0,G.jsx)(De,{open:C===`import`,onOpenChange:e=>w(e?`import`:null),onSuccess:T}),(0,G.jsx)(Ae,{open:C===`rotation`,onOpenChange:e=>w(e?`rotation`:null)}),(0,G.jsx)(Fe,{open:C===`token-test`,onOpenChange:e=>w(e?`token-test`:null),accounts:t})]})}function Ie({open:e,onOpenChange:t,label:n,onLabelChange:r,apiKey:i,onApiKeyChange:a,adding:c,onAddApiKey:l,deviceWaiting:u,onStartDevice:d,device:f,error:p}){return(0,G.jsx)(j,{open:e,onOpenChange:t,children:(0,G.jsxs)(O,{className:`sm:max-w-md`,children:[(0,G.jsxs)(g,{children:[(0,G.jsx)(N,{className:`text-sm`,children:`Add Codex Account`}),(0,G.jsxs)(M,{className:`text-xs leading-relaxed`,children:[`Each account keeps its own login (its own `,(0,G.jsx)(`code`,{children:`CODEX_HOME`}),`).`]})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: sign in with ChatGPT`}),(0,G.jsx)(m,{size:`sm`,className:`w-full cursor-pointer gap-1.5`,onClick:d,disabled:u,children:u?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-4 animate-spin`}),` Waiting for authorization...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ee,{className:`size-4`}),` Sign in with ChatGPT`]})}),f&&(0,G.jsxs)(`div`,{className:`rounded-md border border-primary/40 bg-primary/10 p-2.5 space-y-1.5`,children:[(0,G.jsx)(`p`,{className:`text-[11px]`,children:`Enter this code to authorize:`}),(0,G.jsx)(`div`,{className:`font-mono text-lg tracking-widest`,children:f.userCode}),(0,G.jsxs)(`a`,{href:f.verificationUrl,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-primary hover:underline text-[11px]`,children:[(0,G.jsx)(te,{className:`size-3`}),` `,f.verificationUrl]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 border-t`}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste an API key`}),(0,G.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(k,{htmlFor:`codex-api-key`,className:`text-xs`,children:`OpenAI API key`}),(0,G.jsx)(D,{id:`codex-api-key`,type:`password`,placeholder:`sk-...`,value:i,onChange:e=>a(e.target.value),className:`text-xs font-mono`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(k,{htmlFor:`codex-label`,className:`text-xs`,children:`Label (optional)`}),(0,G.jsx)(D,{id:`codex-label`,placeholder:`e.g. Personal, Work`,value:n,onChange:e=>r(e.target.value),className:`text-xs`})]})]}),p&&(0,G.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:p}),(0,G.jsxs)(C,{children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Cancel`}),(0,G.jsxs)(m,{size:`sm`,className:`text-xs cursor-pointer gap-1.5`,onClick:l,disabled:!i.trim()||c,children:[c?(0,G.jsx)(s,{className:`size-3.5 animate-spin`}):(0,G.jsx)(o,{className:`size-3.5`}),`Add key`]})]})]})})}function Le({mode:e,onOpenChange:t,password:n,onPasswordChange:r,busy:a,onExport:o,onImport:c,error:l}){let u=(0,W.useRef)(null),d=e===`export`;return(0,G.jsx)(j,{open:e!==null,onOpenChange:t,children:(0,G.jsxs)(O,{className:`sm:max-w-md`,children:[(0,G.jsxs)(g,{children:[(0,G.jsxs)(N,{className:`text-sm flex items-center gap-1.5`,children:[(0,G.jsx)(I,{className:`size-4`}),` `,d?`Export Codex Accounts`:`Import Codex Accounts`]}),(0,G.jsx)(M,{className:`text-xs leading-relaxed`,children:d?`Writes a password-encrypted file containing each account's login.`:`Reads a backup file. The password must be the one it was exported with.`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(k,{htmlFor:`codex-backup-password`,className:`text-xs`,children:`Password`}),(0,G.jsx)(D,{id:`codex-backup-password`,type:`password`,placeholder:d?`Choose a password`:`Password used for the export`,value:n,onChange:e=>r(e.target.value),className:`text-xs`,autoComplete:d?`new-password`:`current-password`}),(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`A backup holds full logins — keep the file and its password together.`})]}),l&&(0,G.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:l}),(0,G.jsx)(`input`,{ref:u,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&c(t)}}),(0,G.jsxs)(C,{children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Cancel`}),(0,G.jsxs)(m,{size:`sm`,className:`text-xs cursor-pointer gap-1.5`,disabled:!n.trim()||a,onClick:()=>d?o():u.current?.click(),children:[a?(0,G.jsx)(s,{className:`size-3.5 animate-spin`}):d?(0,G.jsx)(i,{className:`size-3.5`}):(0,G.jsx)(P,{className:`size-3.5`}),d?`Download backup`:`Choose file`]})]})]})})}var Re=[{value:`round-robin`,label:`Round-robin`,hint:`Take the next account each time.`},{value:`fill-first`,label:`Fill-first`,hint:`Stay on one account until it runs out.`},{value:`lowest-usage`,label:`Lowest usage`,hint:`Pick whichever has the most left.`}];function ze({open:e,onOpenChange:t,strategy:n,onChange:r}){return(0,G.jsx)(j,{open:e,onOpenChange:t,children:(0,G.jsxs)(O,{className:`sm:max-w-md`,children:[(0,G.jsxs)(g,{children:[(0,G.jsx)(N,{className:`text-sm`,children:`Codex Rotation`}),(0,G.jsx)(M,{className:`text-xs leading-relaxed`,children:`How a new chat chooses among your Codex accounts.`})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:Re.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(e.value),"aria-current":n===e.value?`true`:void 0,className:d(`w-full text-left rounded-md border px-3 py-2.5 min-h-11 cursor-pointer transition-colors`,n===e.value?`border-primary bg-primary/10`:`border-border hover:bg-accent/50 active:bg-accent`),children:[(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:e.label}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]},e.value))}),(0,G.jsx)(C,{children:(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Done`})})]})})}function $(e){return e==null?null:Math.round(e*100)}function Be({usage:e}){return(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(z,{label:`5-Hour Session`,pct:$(e.fiveHour),reset:U(e.session)}),(0,G.jsx)(z,{label:`Weekly`,pct:$(e.sevenDay),reset:U(e.weekly)})]})}var Ve=2e3,He=21e4;function Ue(e){let[t,n]=(0,W.useState)([]),[r,i]=(0,W.useState)(`round-robin`),[a,o]=(0,W.useState)({}),[s,c]=(0,W.useState)(!1),[d,f]=(0,W.useState)(``),[p,m]=(0,W.useState)(``),[h,g]=(0,W.useState)(!1),[_,v]=(0,W.useState)(null),[y,b]=(0,W.useState)(null),[x,S]=(0,W.useState)(!1),[C,w]=(0,W.useState)(``),[T,E]=(0,W.useState)(!1),[D,O]=(0,W.useState)(!1),[k,A]=(0,W.useState)(null),j=(0,W.useRef)(null),M=(0,W.useRef)(null),N=(0,W.useCallback)(async()=>{c(!0);try{let e=await l.get(`/api/codex-accounts`);n(e.accounts),i(e.strategy),l.get(`/api/codex-accounts/usage`).then(o).catch(()=>{})}finally{c(!1)}},[]);(0,W.useEffect)(()=>{N()},[N]);let P=async()=>{if(d.trim()){g(!0),v(null);try{await l.post(`/api/codex-accounts/api-key`,{apiKey:d.trim(),label:p.trim()||void 0}),f(``),m(``),e(),await N()}catch(e){v(e.message)}finally{g(!1)}}},F=(0,W.useCallback)(t=>{let n=Date.now()+He,r=!1;j.current=()=>{r=!0};let i=e=>{r=!0,j.current=null,M.current=null,e&&v(e),b(null),S(!1)},a=async()=>{if(r)return;let o=null;try{o=await l.get(`/api/codex-accounts/device-login/${t}/status`)}catch{}if(!r){if(o?.state===`done`){i(),m(``),e(),await N();return}if(o?.state===`error`){i(o.error);return}if(Date.now()>n){i(`Device login timed out.`);return}setTimeout(a,Ve)}};a()},[N]);return(0,W.useEffect)(()=>()=>{j.current?.();let e=M.current;e&&l.del(`/api/codex-accounts/device-login/${e}`).catch(()=>{})},[]),{accounts:t,strategy:r,usages:a,loading:s,apiKey:d,setApiKey:f,label:p,setLabel:m,adding:h,err:_,setErr:v,device:y,deviceWaiting:x,backupPassword:C,setBackupPassword:w,exporting:T,importing:D,msg:k,setMsg:A,load:N,addApiKey:P,startDevice:async()=>{v(null);try{let e=await l.post(`/api/codex-accounts/device-login`,{label:p.trim()||void 0});b(e),S(!0),M.current=e.id,F(e.id)}catch(e){v(e.message)}},remove:async e=>{await l.del(`/api/codex-accounts/${e}`),await N()},changeStrategy:async e=>{i(e);try{await l.put(`/api/codex-accounts/strategy`,{strategy:e})}catch{}},doExport:async()=>{if(!C.trim()){v(`Set a backup password first.`);return}E(!0),v(null),A(null);try{let t={"Content-Type":`application/json`},n=u();n&&(t.Authorization=`Bearer ${n}`);let r=await fetch(`/api/codex-accounts/export`,{method:`POST`,headers:t,body:JSON.stringify({password:C})});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error??`Export failed: ${r.status}`)}let i=await r.text(),a=new Blob([i],{type:`application/json`}),o=document.createElement(`a`);o.href=URL.createObjectURL(a),o.download=`ppm-codex-accounts-backup.json`,o.click(),URL.revokeObjectURL(o.href),A(`Backup downloaded.`),e()}catch(e){v(e.message)}finally{E(!1)}},doImport:async t=>{if(!C.trim()){v(`Enter the backup password first.`);return}O(!0),v(null),A(null);try{let n=await t.text(),r=await l.post(`/api/codex-accounts/import`,{data:n,password:C});A(`Imported ${r.imported}${r.skipped?`, skipped ${r.skipped}`:``}.`),e(),await N()}catch(e){v(e.message)}finally{O(!1)}}}}function We(){let[e,t]=(0,W.useState)(null),n=Ue(()=>t(null));return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(R,{description:(0,G.jsxs)(G.Fragment,{children:[`Each Codex account keeps its own login (`,(0,G.jsx)(`code`,{children:`CODEX_HOME`}),`). One is picked per chat by the rotation setting.`]}),onRefresh:()=>void n.load(),refreshing:n.loading,actions:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(m,{size:`sm`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`add`),children:[(0,G.jsx)(A,{className:`size-4`}),` Add account`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`export`),children:[(0,G.jsx)(i,{className:`size-4`}),` Export`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`import`),children:[(0,G.jsx)(P,{className:`size-4`}),` Import`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`rotation`),children:[(0,G.jsx)(b,{className:`size-4`}),` Rotation`]})]})}),(0,G.jsx)(V,{message:n.msg??n.err,onDismiss:()=>{n.setMsg(null),n.setErr(null)}}),(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium`,children:`Codex Accounts`}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground capitalize`,children:n.strategy.replace(`-`,` `)})]}),n.loading&&n.accounts.length===0?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-xs text-muted-foreground`,children:[(0,G.jsx)(s,{className:`size-4 animate-spin`}),` Loading accounts...`]}):n.accounts.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,G.jsx)(o,{className:`size-5 text-muted-foreground`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No Codex accounts yet.`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Chats use your default `,(0,G.jsx)(`code`,{children:`~/.codex`}),` login until you add one.`]})]}):(0,G.jsx)(H,{children:n.accounts.map(e=>{let t=n.usages[e.id]??{};return(0,G.jsxs)(B,{dense:!0,className:`min-w-[300px] shrink-0 snap-start`,"data-testid":`account-card`,"data-account-id":e.id,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium truncate flex-1 min-w-0`,children:e.label}),(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-text-subtle border border-border rounded px-1 shrink-0`,children:e.type}),e.planType&&(0,G.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:e.planType}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>void n.remove(e.id),title:`Remove account`,"aria-label":`Remove account`,className:`p-2 rounded cursor-pointer text-text-subtle hover:text-error hover:bg-surface-elevated transition-colors shrink-0`,children:(0,G.jsx)(S,{className:`size-4`})})]}),(0,G.jsx)(Be,{usage:t})]},e.id)})})]}),(0,G.jsx)(Ie,{open:e===`add`,onOpenChange:e=>t(e?`add`:null),label:n.label,onLabelChange:n.setLabel,apiKey:n.apiKey,onApiKeyChange:n.setApiKey,adding:n.adding,onAddApiKey:()=>void n.addApiKey(),deviceWaiting:n.deviceWaiting,onStartDevice:()=>void n.startDevice(),device:n.device,error:n.err}),(0,G.jsx)(Le,{mode:e===`export`?`export`:e===`import`?`import`:null,onOpenChange:e=>{e||t(null)},password:n.backupPassword,onPasswordChange:n.setBackupPassword,busy:n.exporting||n.importing,onExport:()=>void n.doExport(),onImport:e=>void n.doImport(e),error:n.err}),(0,G.jsx)(ze,{open:e===`rotation`,onOpenChange:e=>t(e?`rotation`:null),strategy:n.strategy,onChange:e=>void n.changeStrategy(e)})]})}var Ge=[{id:`claude`,label:`Claude`},{id:`codex`,label:`Codex`}];function Ke(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(`claude`);(0,W.useEffect)(()=>{let e=!1;return ae().then(n=>{e||t(new Set(Object.keys(n.providers??{})))}).catch(()=>{e||t(new Set([`claude`]))}),()=>{e=!0}},[]);let i=Ge.filter(t=>t.id===`claude`||e?.has(t.id)),a=i.length>1;return(0,G.jsxs)(`div`,{className:`space-y-4`,"data-testid":`accounts-pane`,"data-provider":n,children:[a&&(0,G.jsx)(`div`,{className:`flex gap-1 border-b border-border/50`,children:i.map(e=>(0,G.jsxs)(`button`,{onClick:()=>r(e.id),"data-testid":`accounts-tab-${e.id}`,"aria-current":n===e.id?`page`:void 0,className:`flex items-center gap-1.5 px-3 py-2 text-xs rounded-t transition-colors cursor-pointer ${n===e.id?`text-primary border-b-2 border-primary font-medium`:`text-text-subtle hover:text-text-secondary`}`,children:[(0,G.jsx)(x,{providerId:e.id}),e.label]},e.id))}),e===null&&!a&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,G.jsx)(s,{className:`size-3 animate-spin`}),` Checking configured providers...`]}),n===`claude`?(0,G.jsx)(Q,{}):(0,G.jsx)(We,{})]})}export{Ke as AccountsSettingsSection};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./copy-BewHj66E.js";import{t as i}from"./download-DG3_9xXy.js";import{t as a}from"./flask-conical-tp8gyZGh.js";import{t as o}from"./key-round-CQpDrDxg.js";import{t as s}from"./loader-circle-DPMrnLQ2.js";import{t as c}from"./x-YDu4m2Iq.js";import{n as l,r as u}from"./api-client-oY1tC3tM.js";import{n as d}from"./utils-C9OjCrou.js";import"./portal-container-context-a399Hd9F.js";import{n as f}from"./use-is-mobile-CYW3FJFE.js";import{n as p,t as m}from"./button-2WCAS8dI.js";import{t as h}from"./mobile-bottom-sheet-B3uDlD79.js";import"./use-visual-viewport-D9O48HQt.js";import{$t as g,B as _,G as v,H as y,Hn as b,M as x,Pn as S,Qt as C,U as w,V as T,W as E,X as D,Xt as O,Y as k,Yn as A,Yt as j,Zt as M,en as N,jn as P,nn as F,or as I,tr as ee,wr as te}from"./index-DdMq4zqb.js";import{addAccount as ne,deleteAccount as re,exchangeOAuthCode as ie,getAISettings as ae,getAccountSettings as oe,getOAuthUrl as se,getUsageHistory as ce,importAccounts as le,patchAccount as ue,testAccountToken as de,testExport as fe,testRawToken as pe,updateAccountSettings as L}from"./api-settings-BVfemzZW.js";import{a as R,c as z,i as B,l as me,n as he,o as V,r as H,t as ge,u as U}from"./use-accounts-data--pdg01TI.js";var W=e(t(),1),G=n(),K=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],q=Array.from({length:24},(e,t)=>t);function _e(e,t){let n=Array.from({length:7},()=>Array.from({length:24},()=>({sum:0,count:0,avg:0})));for(let r of e){let e=t===`5h`?r.five_hour_util:r.weekly_util;if(e==null)continue;let i=new Date(r.recorded_at+(r.recorded_at.endsWith(`Z`)?``:`Z`)),a=(i.getDay()+6)%7,o=i.getHours();n[a][o].sum+=e,n[a][o].count+=1}for(let e of n)for(let t of e)t.avg=t.count>0?t.sum/t.count:0;return n}function ve(e){return e.map(e=>{let t=e.reduce((e,t)=>e+t.sum,0),n=e.reduce((e,t)=>e+t.count,0);return n>0?t/n:0})}function ye(e){return q.map(t=>{let n=0,r=0;for(let i of e)n+=i[t].sum,r+=i[t].count;return r>0?n/r:0})}function J(e){return e===0?`bg-surface-elevated`:e<.3?`bg-success/30`:e<.5?`bg-success/60`:e<.7?`bg-warning/50`:e<.9?`bg-warning/80`:`bg-error/80`}function be(e){return e<.3?`bg-success`:e<.7?`bg-warning`:`bg-error`}function xe({accountId:e}){let[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(!0),[a,o]=(0,W.useState)(`5h`);(0,W.useEffect)(()=>{i(!0),ce(e).then(n).catch(()=>n([])).finally(()=>i(!1))},[e]);let c=(0,W.useMemo)(()=>t?_e(t,a):null,[t,a]),l=(0,W.useMemo)(()=>c?ve(c):[],[c]),u=(0,W.useMemo)(()=>c?ye(c):[],[c]),d=Math.max(...l,.01);if(Math.max(...u,.01),r)return(0,G.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,G.jsx)(s,{className:`size-3 animate-spin text-text-subtle`})});if(!t||t.length===0)return(0,G.jsx)(`div`,{className:`text-[10px] text-text-subtle py-2 text-center`,children:`No usage history yet`});let f=t.length,p=new Set(t.map(e=>new Date(e.recorded_at+(e.recorded_at.endsWith(`Z`)?``:`Z`)).toDateString())).size;return(0,G.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Usage Pattern (7d)`}),(0,G.jsxs)(`div`,{className:`flex gap-0.5 text-[9px]`,children:[(0,G.jsx)(`button`,{onClick:()=>o(`5h`),className:`px-1.5 py-0.5 rounded cursor-pointer transition-colors ${a===`5h`?`bg-primary/15 text-primary`:`text-text-subtle hover:text-text-secondary`}`,title:`5-hour rolling window limit — resets every 5 hours`,children:`5h`}),(0,G.jsx)(`button`,{onClick:()=>o(`weekly`),className:`px-1.5 py-0.5 rounded cursor-pointer transition-colors ${a===`weekly`?`bg-primary/15 text-primary`:`text-text-subtle hover:text-text-secondary`}`,title:`Weekly limit — resets every 7 days`,children:`Wk`})]})]}),(0,G.jsxs)(`p`,{className:`text-[9px] text-text-subtle leading-tight`,children:[`Avg `,a===`5h`?`5-hour`:`weekly`,` limit usage over `,p,`d (`,f,` samples). Higher % = closer to rate limit. Hover cells for details.`]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by day of week`}),(0,G.jsx)(`div`,{className:`flex flex-col gap-[2px] mt-0.5`,children:K.map((e,t)=>{let n=l[t]??0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-[8px] text-text-subtle w-5 shrink-0 text-right tabular-nums`,children:e}),(0,G.jsx)(`div`,{className:`flex-1 h-2.5 bg-surface-elevated rounded-sm overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-sm transition-all ${be(n)}`,style:{width:`${Math.round(n/d*100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-[8px] text-text-subtle w-6 shrink-0 text-right tabular-nums`,children:[Math.round(n*100),`%`]})]},e)})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by hour (0h-23h)`}),(0,G.jsx)(`div`,{className:`flex gap-[1px] mt-0.5`,children:q.map(e=>{let t=u[e]??0;return(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-[1px]`,children:[(0,G.jsx)(`div`,{className:`w-full aspect-square rounded-[2px] ${J(t)}`,title:`${e}:00 — avg ${Math.round(t*100)}% usage`}),e%6==0&&(0,G.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})]},e)})})]}),c&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Day x Hour heatmap`}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-[1px] mt-0.5`,children:[K.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,G.jsx)(`span`,{className:`text-[7px] text-text-subtle w-4 shrink-0 text-right`,children:e.charAt(0)}),q.map(n=>{let r=c[t][n];return(0,G.jsx)(`div`,{className:`flex-1 aspect-square rounded-[1px] ${J(r.avg)}`,title:`${e} ${n}:00 — ${r.count>0?`avg ${Math.round(r.avg*100)}% (${r.count} samples)`:`no data`}`},n)})]},e)),(0,G.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,G.jsx)(`span`,{className:`w-4 shrink-0`}),q.map(e=>(0,G.jsx)(`div`,{className:`flex-1 text-center`,children:e%6==0&&(0,G.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})},e))]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[8px] text-text-subtle`,children:[(0,G.jsx)(`span`,{children:`Low`}),(0,G.jsxs)(`div`,{className:`flex gap-[2px]`,children:[(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-success/30`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-success/60`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-warning/50`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-warning/80`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-error/80`})]}),(0,G.jsx)(`span`,{children:`High`}),(0,G.jsx)(`span`,{className:`ml-1`,children:`|`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-surface-elevated border border-border/30`}),(0,G.jsx)(`span`,{children:`No data`})]})]})}function Se({profile:e,accountId:t,onClose:n}){let r=[[`Name`,e.account?.display_name],[`Email`,e.account?.email],[`Org`,e.organization?.name],[`Type`,e.organization?.organization_type],[`Tier`,e.organization?.rate_limit_tier],[`Status`,e.organization?.subscription_status]];return(0,G.jsxs)(`section`,{className:`space-y-2 border-t border-border pt-3`,"data-testid":`account-profile-panel`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium`,children:`Profile`}),(0,G.jsx)(`button`,{className:`p-2 text-muted-foreground hover:text-foreground cursor-pointer`,onClick:n,"aria-label":`Close profile`,children:(0,G.jsx)(c,{className:`size-4`})})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-[80px_1fr] gap-x-3 gap-y-1 text-xs`,children:r.map(([e,t])=>t?(0,G.jsxs)(`span`,{className:`contents`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,G.jsx)(`span`,{className:`break-all`,children:t})]},e):null)}),(0,G.jsx)(xe,{accountId:t})]})}function Ce({display:e,onConfirm:t,onCancel:n}){let r=f(),i=(0,G.jsxs)(`div`,{className:`space-y-4`,"data-testid":`account-delete-confirm`,children:[(0,G.jsxs)(`p`,{className:`text-sm`,children:[`Remove `,(0,G.jsx)(`span`,{className:`font-medium`,children:e}),`?`]}),(0,G.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`The stored token is deleted from this machine. Any export you already made keeps working.`}),(0,G.jsxs)(`div`,{className:`flex flex-col-reverse md:flex-row gap-2 md:justify-end pt-2`,children:[(0,G.jsx)(m,{variant:`outline`,onClick:n,className:`min-h-11`,children:`Cancel`}),(0,G.jsx)(m,{variant:`destructive`,autoFocus:!1,onClick:t,className:`min-h-11`,children:`Remove account`})]})]});return r?(0,G.jsx)(h,{open:!0,onClose:n,children:(0,G.jsxs)(`div`,{className:`px-4 pb-4`,children:[(0,G.jsx)(`h2`,{className:`text-base font-semibold mb-3`,children:`Remove account`}),i]})}):(0,G.jsx)(j,{open:!0,onOpenChange:e=>{e||n()},children:(0,G.jsxs)(O,{className:`sm:max-w-sm`,children:[(0,G.jsx)(g,{children:(0,G.jsx)(N,{className:`text-sm`,children:`Remove account`})}),i]})})}function we({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(``),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(null),[h,_]=(0,W.useState)(``),[v,y]=(0,W.useState)(!1),[b,x]=(0,W.useState)(`idle`);function S(){p(null),_(``),x(`idle`),d(null)}function w(){t(!1),S(),i(``),o(``),d(null)}async function T(){y(!0),d(null);try{let{url:e,state:t}=await se();p(t),x(`waiting`),window.open(e,`_blank`)}catch(e){d(e.message)}y(!1)}async function E(){if(!(!h.trim()||!f)){y(!0),d(null);try{let e=h.trim();e.includes(`#`)&&(e=e.split(`#`)[0]??e);let t=await ie(e,f);w(),n(t?.status===`disabled`?`Signed in. This account is still disabled — enable it to use it.`:`Account connected via OAuth!`)}catch(e){d(e.message)}y(!1)}}async function A(){if(r.trim()){l(!0),d(null);try{let e=await ne({apiKey:r.trim(),label:a.trim()||void 0});w(),n(e?.status===`disabled`?`Token updated. This account is still disabled — enable it to use it.`:`Account added!`)}catch(e){d(e.message)}l(!1)}}let P=r.trim()?r.trim().startsWith(`sk-ant-oat`)?`OAuth token (Claude Max/Pro)`:r.trim().startsWith(`sk-ant-api`)?`API key`:`Unknown format`:``;return(0,G.jsx)(j,{open:e,onOpenChange:e=>{e||w()},children:(0,G.jsxs)(O,{className:`sm:max-w-md`,children:[(0,G.jsxs)(g,{children:[(0,G.jsx)(N,{className:`text-sm`,children:`Add Claude Account`}),(0,G.jsx)(M,{className:`text-xs leading-relaxed`,children:`Connect via OAuth (recommended) or paste a token manually.`})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: Login with Claude`}),b===`idle`?(0,G.jsx)(m,{size:`sm`,className:`w-full h-8 text-xs`,onClick:T,disabled:v,children:v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Opening...`]}):`Login with Claude`}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Authorize in the opened tab, then paste the code:`}),(0,G.jsx)(D,{placeholder:`Paste code here...`,value:h,onChange:e=>_(e.target.value),className:`text-xs h-8 font-mono`,autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,G.jsx)(m,{size:`sm`,className:`flex-1 h-7 text-xs`,onClick:E,disabled:!h.trim()||v,children:v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Connecting...`]}):`Connect`}),(0,G.jsx)(m,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:S,children:`Cancel`})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 border-t`}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste token`}),(0,G.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(k,{htmlFor:`add-token`,className:`text-xs`,children:`Token`}),(0,G.jsx)(D,{id:`add-token`,type:`password`,placeholder:`sk-ant-...`,value:r,onChange:e=>i(e.target.value),className:`text-xs h-8 font-mono`}),P&&(0,G.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Detected: `,P]})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(k,{htmlFor:`add-label`,className:`text-xs`,children:`Label (optional)`}),(0,G.jsx)(D,{id:`add-label`,placeholder:`e.g. Personal, Work`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`})]})]}),u&&(0,G.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:u}),(0,G.jsxs)(C,{children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7`,onClick:w,children:`Cancel`}),(0,G.jsx)(m,{size:`sm`,className:`text-xs h-7`,onClick:A,disabled:!r.trim()||c,children:c?`Adding...`:`Add Token`})]})]})})}function Te(e){let t=new Blob([e],{type:`application/json`}),n=document.createElement(`a`);n.href=URL.createObjectURL(t),n.download=`ppm-accounts-backup.json`,n.click(),URL.revokeObjectURL(n.href)}function Ee({open:e,onOpenChange:t,accounts:n,preselectId:a,onMessage:o}){let c=n.filter(e=>e.hasRefreshToken),[l,d]=(0,W.useState)(new Set),[f,p]=(0,W.useState)(``),[h,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)(!1),[b,x]=(0,W.useState)(!1),[S,w]=(0,W.useState)(!1);e&&!S&&(d(a?new Set([a]):new Set(c.map(e=>e.id))),w(!0)),!e&&S&&w(!1);function T(){t(!1),p(``),_(!1),y(!1)}async function E(e){if(l.size===0)return;x(!0);let t=f.trim()||`ppm-hienlh`;try{let n={"Content-Type":`application/json`},r=u();r&&(n.Authorization=`Bearer ${r}`);let i=await fetch(`/api/accounts/export`,{method:`POST`,headers:n,body:JSON.stringify({password:t,accountIds:[...l],includeRefreshToken:h,refreshBeforeExport:v})});if(!i.ok){let e=await i.json();throw Error(e.error??`Export failed: ${i.status}`)}let a=await i.text();e&&await F(a)?o?.(`Backup copied to clipboard!`):(Te(a),o?.(`Backup downloaded.`)),T()}catch{}x(!1)}let A=l.size>0&&!b;return(0,G.jsx)(j,{open:e,onOpenChange:e=>{e||T()},children:(0,G.jsxs)(O,{className:`sm:max-w-md`,children:[(0,G.jsxs)(g,{children:[(0,G.jsxs)(N,{className:`text-sm flex items-center gap-1.5`,children:[(0,G.jsx)(I,{className:`size-3.5`}),` Export Accounts`]}),(0,G.jsx)(M,{className:`text-xs`,children:`Select accounts and set a password to protect the backup.`})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Accounts to export`}),(0,G.jsx)(`button`,{className:`text-[10px] text-primary hover:underline cursor-pointer`,onClick:()=>d(l.size===c.length?new Set:new Set(c.map(e=>e.id))),children:l.size===c.length?`Deselect all`:`Select all`})]}),c.length===0?(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground p-2 border rounded`,children:`No exportable accounts.`}):(0,G.jsx)(`div`,{className:`max-h-36 overflow-y-auto space-y-1 border rounded p-2`,children:c.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`exp-${e.id}`,checked:l.has(e.id),onChange:t=>{let n=new Set(l);t.target.checked?n.add(e.id):n.delete(e.id),d(n)},className:`size-3.5 accent-primary cursor-pointer`}),(0,G.jsx)(`label`,{htmlFor:`exp-${e.id}`,className:`text-xs cursor-pointer truncate`,children:e.label??e.email??e.id.slice(0,8)})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(k,{className:`text-xs`,children:[`Password `,(0,G.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,G.jsx)(D,{type:`password`,placeholder:`Leave empty for default`,value:f,onChange:e=>p(e.target.value),className:`text-xs h-8`,autoComplete:`new-password`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`exp-full`,checked:h,onChange:e=>_(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,G.jsx)(`label`,{htmlFor:`exp-full`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens (full transfer)`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`exp-refresh`,checked:v,onChange:e=>y(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,G.jsx)(`label`,{htmlFor:`exp-refresh`,className:`text-[11px] cursor-pointer`,children:`Refresh tokens before export`})]}),h?(0,G.jsxs)(`div`,{className:`rounded-md border border-error/30 bg-error/5 p-2.5`,children:[(0,G.jsx)(`p`,{className:`text-[10px] font-medium text-error`,children:`Full transfer — source accounts will expire`}),(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Refresh tokens included. Source machine expires in ~1h after target refreshes.`})]}):v?(0,G.jsx)(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 p-2.5`,children:(0,G.jsx)(`p`,{className:`text-[10px] font-medium text-warning`,children:`Refresh before export — invalidates previous shares`})}):(0,G.jsx)(`div`,{className:`rounded-md border border-success/30 bg-success/5 p-2.5`,children:(0,G.jsx)(`p`,{className:`text-[10px] font-medium text-success`,children:`Share current token (safe)`})}),(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Encrypted with AES-256-GCM + scrypt.`})]}),(0,G.jsxs)(C,{className:`gap-1.5 flex-col sm:flex-row`,children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:T,children:`Cancel`}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,disabled:!A,onClick:()=>E(!0),children:[(0,G.jsx)(r,{className:`size-3 mr-1`}),` Copy`]}),(0,G.jsx)(m,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!A,onClick:()=>E(!1),children:b?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(i,{className:`size-3 mr-1`}),` Download`]})})]})]})})}function De({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(``),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(null);function f(){t(!1),i(``),o(``),d(null)}async function p(){if(r.trim()){l(!0),d(null);try{let e=await le({data:r.trim(),password:a.trim()||`ppm-hienlh`});f(),n(`Imported ${e.imported} account(s)`)}catch(e){d(e.message||`Import failed`)}l(!1)}}return(0,G.jsx)(j,{open:e,onOpenChange:e=>{e||f()},children:(0,G.jsxs)(O,{className:`sm:max-w-md`,children:[(0,G.jsxs)(g,{children:[(0,G.jsxs)(N,{className:`text-sm flex items-center gap-1.5`,children:[(0,G.jsx)(I,{className:`size-3.5`}),` Import Accounts`]}),(0,G.jsx)(M,{className:`text-xs`,children:`Paste backup data and enter the export password. Imported accounts are temporary (~1h).`})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(k,{className:`text-xs`,children:`Backup data`}),(0,G.jsx)(`textarea`,{value:r,onChange:e=>i(e.target.value),placeholder:`Paste backup JSON here...`,rows:4,className:`w-full text-xs p-2 rounded border border-border bg-background font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(k,{className:`text-xs`,children:[`Password `,(0,G.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,G.jsx)(D,{type:`password`,placeholder:`Leave empty for default`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`,autoComplete:`current-password`})]})]}),u&&(0,G.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:u}),(0,G.jsxs)(C,{children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:f,children:`Cancel`}),(0,G.jsx)(m,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!r.trim()||c,onClick:p,children:c?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Importing...`]}):`Import`})]})]})})}var Y=typeof window<`u`?window.matchMedia(`(min-width: 768px)`):null;function Oe(e){return Y?.addEventListener(`change`,e),()=>Y?.removeEventListener(`change`,e)}function ke(){return Y?.matches??!0}function X(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(!0);return(0,W.useEffect)(()=>{r(!0),oe().then(t).finally(()=>r(!1))},[]),n?(0,G.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Loading...`}):e?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Rotation Strategy`}),(0,G.jsxs)(_,{value:e.strategy,onValueChange:async e=>{t(await L({strategy:e}))},children:[(0,G.jsx)(w,{className:`w-full h-9 text-xs`,children:(0,G.jsx)(E,{})}),(0,G.jsxs)(T,{children:[(0,G.jsx)(y,{value:`round-robin`,children:`Round-robin`}),(0,G.jsx)(y,{value:`fill-first`,children:`Fill-first`}),(0,G.jsx)(y,{value:`lowest-usage`,children:`Lowest usage`})]})]}),(0,G.jsxs)(`p`,{className:`text-[10px] text-text-subtle`,children:[e.strategy===`round-robin`&&`Cycles through accounts evenly`,e.strategy===`fill-first`&&`Uses one account until its limit, then moves on`,e.strategy===`lowest-usage`&&`Picks the account with the lowest current usage`]})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Max Retry`}),(0,G.jsx)(`input`,{type:`number`,min:0,value:e.maxRetry,className:`w-full h-9 text-xs border rounded-md px-3 bg-background`,onChange:async e=>{let n=parseInt(e.target.value,10);!isNaN(n)&&n>=0&&t(await L({maxRetry:n}))}}),(0,G.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`How many accounts to try on failure. 0 = try all available accounts.`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Cooldown parking`}),(0,G.jsx)(v,{checked:e.cooldownEnabled,onCheckedChange:async e=>{t(await L({cooldownEnabled:e}))}})]}),(0,G.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Park a failing account (rate limit / usage limit / auth error) until it recovers. Off: accounts stay selectable — rotation still skips accounts already ≥95% on the 5-hour limit.`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs border-t border-border pt-3`,children:[(0,G.jsx)(`span`,{className:`text-text-subtle`,children:`Active accounts`}),(0,G.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.activeCount})]})]}):(0,G.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Failed to load settings`})}function Ae({open:e,onOpenChange:t}){let n=(0,W.useSyncExternalStore)(Oe,ke);return e?n?(0,G.jsx)(j,{open:e,onOpenChange:t,children:(0,G.jsxs)(O,{className:`sm:max-w-sm`,children:[(0,G.jsx)(g,{children:(0,G.jsxs)(N,{className:`text-sm flex items-center gap-2`,children:[(0,G.jsx)(b,{className:`size-4`}),` Rotation & Retry`]})}),(0,G.jsx)(X,{})]})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 transition-opacity duration-200 opacity-100`,onClick:()=>t(!1),style:{backgroundColor:`rgba(0,0,0,0.5)`}}),(0,G.jsxs)(`div`,{className:d(`fixed bottom-0 left-0 right-0 z-50 bg-background rounded-t-2xl border-t border-border shadow-2xl`,`transition-transform duration-300 ease-out max-h-[85vh] overflow-y-auto`,`translate-y-0`),children:[(0,G.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,G.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-border`})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,G.jsxs)(`span`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,G.jsx)(b,{className:`size-4`}),` Rotation & Retry`]}),(0,G.jsx)(`button`,{onClick:()=>t(!1),className:`flex items-center justify-center size-7 rounded-md hover:bg-surface-elevated transition-colors`,children:(0,G.jsx)(c,{className:`size-4`})})]}),(0,G.jsx)(`div`,{className:`px-4 py-4 pb-8`,children:(0,G.jsx)(X,{})})]})]}):null}var je=p(`inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2`,{variants:{variant:{default:`border-transparent bg-primary text-primary-foreground shadow`,secondary:`border-transparent bg-secondary text-secondary-foreground`,destructive:`border-transparent bg-destructive text-destructive-foreground shadow`,outline:`text-foreground`}},defaultVariants:{variant:`default`}});function Z({className:e,variant:t,...n}){return(0,G.jsx)(`div`,{className:d(je({variant:t}),e),...n})}function Me(e){let t=Math.floor(Date.now()/1e3);return e>t?`${Math.floor((e-t)/60)}m`:`exp`}function Ne({accounts:e}){let[t,n]=(0,W.useState)([]),[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(!1),[c,l]=(0,W.useState)(new Map),u=e.filter(e=>e.hasRefreshToken);async function d(){if(u.length!==0){i(!0);try{let e=await fe(u.map(e=>e.id),a);n(t=>[...t,{round:t.length+1,time:new Date().toLocaleTimeString(),includeRefresh:a,items:e}])}catch{}i(!1)}}async function f(e,t){l(t=>new Map(t).set(e,{loading:!0}));try{let n=await pe(t);l(t=>new Map(t).set(e,{loading:!1,...n}))}catch(t){l(n=>new Map(n).set(e,{loading:!1,status:`error`,error:t.message}))}}function p(e,t){return[{key:`r${e.round}-pre-${t.id}`,label:`Pre-export`,token:t.preExportTokenFull,preview:t.preExportToken,expires:t.preExportExpires},{key:`r${e.round}-exp-${t.id}`,label:`Exported`,token:t.exportedTokenFull,preview:t.exportedToken,expires:t.exportedExpires},{key:`r${e.round}-post-${t.id}`,label:`Post-export`,token:t.postExportTokenFull,preview:t.postExportToken,expires:t.postExportExpires}]}function h(){for(let e of t)for(let t of e.items)for(let n of p(e,t))n.token&&f(n.key,n.token)}return(0,G.jsxs)(`section`,{className:`border-t pt-4 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium`,children:`Simulate export`}),t.length>0&&(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[t.length,` round(s)`]})]}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Every run appends a round. Earlier rounds are kept so tokens can be compared across runs.`}),u.length===0?(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No OAuth account with a refresh token to export.`}):(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(v,{id:`sim-include-refresh`,checked:a,onCheckedChange:o,className:`cursor-pointer`}),(0,G.jsx)(k,{htmlFor:`sim-include-refresh`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens`})]}),(0,G.jsx)(m,{size:`sm`,className:`h-7 text-xs cursor-pointer`,disabled:r,onClick:()=>void d(),children:r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):`Run export #${t.length+1}`})]}),t.length>0&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`w-full h-7 text-[11px] cursor-pointer`,onClick:h,children:[`Test all tokens (`,t.reduce((e,t)=>e+t.items.length*3,0),`)`]}),t.map(e=>(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`p`,{className:`text-xs font-medium text-primary`,children:[`Round #`,e.round]}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.time}),(0,G.jsx)(Z,{variant:e.includeRefresh?`destructive`:`secondary`,className:`text-[9px] px-1 py-0`,children:e.includeRefresh?`with refresh`:`access only`})]}),e.items.map(t=>(0,G.jsxs)(`div`,{className:`p-2 rounded-lg border bg-card space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-[11px] font-medium`,children:t.label??t.email??t.id.slice(0,8)}),t.tokenChanged&&(0,G.jsx)(Z,{variant:`secondary`,className:`text-[9px] px-1 py-0`,children:`DB token changed`})]}),p(e,t).map(e=>{let t=c.get(e.key);return(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,G.jsx)(`span`,{className:`w-20 shrink-0 text-muted-foreground text-[10px]`,children:e.label}),(0,G.jsx)(`code`,{className:`flex-1 truncate font-mono text-[10px] bg-muted px-1 rounded`,children:e.preview??`N/A`}),e.expires&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:Me(e.expires)}),e.token?(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`h-6 text-[10px] px-1.5 cursor-pointer shrink-0`,disabled:t?.loading,onClick:()=>void f(e.key,e.token),children:t?.loading?(0,G.jsx)(s,{className:`size-3 animate-spin`}):`Test`}):(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`-`}),t&&!t.loading&&(0,G.jsx)(`span`,{className:`text-[10px] font-medium shrink-0 ${t.status?.startsWith(`valid`)?`text-success`:`text-error`}`,children:t.status})]},e.key)})]},`r${e.round}-${t.id}`))]},e.round))]})]})}function Pe(e){let t=Math.floor(Date.now()/1e3),n=Math.floor(Math.abs(e-t)/60);return e>t?`${n}m left`:`expired ${n}m ago`}function Fe({open:e,onOpenChange:t,accounts:n}){let[r,i]=(0,W.useState)(new Map),[o,c]=(0,W.useState)(!1);async function l(e){i(t=>new Map(t).set(e,{loading:!0}));try{let t=await de(e,o);i(n=>new Map(n).set(e,{loading:!1,result:t}))}catch(t){i(n=>new Map(n).set(e,{loading:!1,error:t.message}))}}function u(){for(let e of n.filter(e=>e.expiresAt!==null))l(e.id)}return(0,G.jsx)(j,{open:e,onOpenChange:t,children:(0,G.jsxs)(O,{className:`sm:max-w-xl max-h-[85vh] flex flex-col`,children:[(0,G.jsxs)(g,{children:[(0,G.jsxs)(N,{className:`text-sm flex items-center gap-1.5`,children:[(0,G.jsx)(a,{className:`size-4`}),` Token Test`]}),(0,G.jsx)(M,{className:`text-xs`,children:`Probe stored tokens for validity. Nothing is modified.`})]}),(0,G.jsxs)(`div`,{className:`space-y-4 overflow-y-auto flex-1 pr-1`,children:[(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium`,children:`Current tokens`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(v,{id:`token-test-refresh`,checked:o,onCheckedChange:c,className:`cursor-pointer`}),(0,G.jsx)(k,{htmlFor:`token-test-refresh`,className:`text-[11px] cursor-pointer`,children:`Also test refresh`})]}),(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`h-7 text-xs cursor-pointer`,onClick:u,children:`Test all`})]})]}),n.length===0&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No accounts to test.`}),(0,G.jsx)(`div`,{className:`space-y-1.5`,children:n.map(e=>{let t=r.get(e.id),n=t?.result?.accessToken.status;return(0,G.jsxs)(`div`,{className:`p-2 rounded border bg-card space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium truncate block`,children:e.label??e.email??e.id.slice(0,8)}),e.expiresAt&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:Pe(e.expiresAt)})]}),(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`h-7 text-xs cursor-pointer shrink-0`,disabled:t?.loading,onClick:()=>void l(e.id),children:t?.loading?(0,G.jsx)(s,{className:`size-3 animate-spin`}):`Test`})]}),t&&!t.loading&&(0,G.jsxs)(`div`,{className:`text-[11px] pl-2 border-l-2 border-muted`,children:[t.error&&(0,G.jsx)(`p`,{className:`text-error`,children:t.error}),n&&(0,G.jsxs)(`span`,{className:n.startsWith(`valid`)?`text-success`:`text-error`,children:[n,t.result?.accessToken.code?` (${t.result.accessToken.code})`:``]})]})]},e.id)})})]}),(0,G.jsx)(Ne,{accounts:n})]}),(0,G.jsx)(C,{children:(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Close`})})]})})}function Q(){let{usages:e,accounts:t,activeAccountId:n,initialLoading:r,refreshing:c,flashIds:l,reload:u}=ge(),[d,f]=(0,W.useState)(null),[p,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(null),[v,y]=(0,W.useState)(null),[x,S]=(0,W.useState)(null),[C,w]=(0,W.useState)(null);function T(e){u(),e&&f(e)}async function E(e,t){h(e);try{await ue(e,{status:t===`disabled`?`active`:`disabled`})}catch(e){f(e.message)}h(null),u()}async function D(){if(g){try{await re(g.id),f(`Account "${g.display}" removed.`),u()}catch(e){f(`Failed to remove: ${e.message}`)}_(null)}}let O=new Map(t.map(e=>[e.id,e])),k=e[0]?.usage.lastFetchedAt;return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(R,{description:`Connect multiple Claude accounts. PPM rotates between them automatically to avoid rate limits.`,onRefresh:()=>void u(),refreshing:c,disabled:r,actions:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(m,{size:`sm`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`add`),children:[(0,G.jsx)(A,{className:`size-4`}),` Add account`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>{S(null),w(`export`)},children:[(0,G.jsx)(i,{className:`size-4`}),` Export`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`import`),children:[(0,G.jsx)(P,{className:`size-4`}),` Import`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`rotation`),children:[(0,G.jsx)(b,{className:`size-4`}),` Rotation`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`token-test`),children:[(0,G.jsx)(a,{className:`size-4`}),` Token test`]})]})}),(0,G.jsx)(V,{message:d,onDismiss:()=>f(null)}),(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium`,children:`Accounts`}),k&&(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`usage `,me(new Date(k).getTime())]})]}),r?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-xs text-muted-foreground`,children:[(0,G.jsx)(s,{className:`size-4 animate-spin`}),` Loading accounts...`]}):e.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,G.jsx)(o,{className:`size-5 text-muted-foreground`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No accounts connected yet.`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Add one to start using PPM.`})]}):(0,G.jsx)(H,{children:e.map(e=>(0,G.jsx)(he,{layout:`strip`,entry:e,isActive:e.accountId===n,accountInfo:O.get(e.accountId),onToggle:E,toggling:p===e.accountId,onDelete:(e,t)=>_({id:e,display:t}),onExport:e=>{S(e),w(`export`)},onViewProfile:(e,t)=>y({profile:e,accountId:t}),flash:l.has(e.accountId)},e.accountId))})]}),v&&(0,G.jsx)(Se,{profile:v.profile,accountId:v.accountId,onClose:()=>y(null)}),g&&(0,G.jsx)(Ce,{display:g.display,onConfirm:()=>void D(),onCancel:()=>_(null)}),(0,G.jsx)(we,{open:C===`add`,onOpenChange:e=>w(e?`add`:null),onSuccess:T}),(0,G.jsx)(Ee,{open:C===`export`,onOpenChange:e=>{w(e?`export`:null),e||S(null)},accounts:t,preselectId:x,onMessage:f}),(0,G.jsx)(De,{open:C===`import`,onOpenChange:e=>w(e?`import`:null),onSuccess:T}),(0,G.jsx)(Ae,{open:C===`rotation`,onOpenChange:e=>w(e?`rotation`:null)}),(0,G.jsx)(Fe,{open:C===`token-test`,onOpenChange:e=>w(e?`token-test`:null),accounts:t})]})}function Ie({open:e,onOpenChange:t,label:n,onLabelChange:r,apiKey:i,onApiKeyChange:a,adding:c,onAddApiKey:l,deviceWaiting:u,onStartDevice:d,device:f,error:p}){return(0,G.jsx)(j,{open:e,onOpenChange:t,children:(0,G.jsxs)(O,{className:`sm:max-w-md`,children:[(0,G.jsxs)(g,{children:[(0,G.jsx)(N,{className:`text-sm`,children:`Add Codex Account`}),(0,G.jsxs)(M,{className:`text-xs leading-relaxed`,children:[`Each account keeps its own login (its own `,(0,G.jsx)(`code`,{children:`CODEX_HOME`}),`).`]})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: sign in with ChatGPT`}),(0,G.jsx)(m,{size:`sm`,className:`w-full cursor-pointer gap-1.5`,onClick:d,disabled:u,children:u?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-4 animate-spin`}),` Waiting for authorization...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ee,{className:`size-4`}),` Sign in with ChatGPT`]})}),f&&(0,G.jsxs)(`div`,{className:`rounded-md border border-primary/40 bg-primary/10 p-2.5 space-y-1.5`,children:[(0,G.jsx)(`p`,{className:`text-[11px]`,children:`Enter this code to authorize:`}),(0,G.jsx)(`div`,{className:`font-mono text-lg tracking-widest`,children:f.userCode}),(0,G.jsxs)(`a`,{href:f.verificationUrl,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-primary hover:underline text-[11px]`,children:[(0,G.jsx)(te,{className:`size-3`}),` `,f.verificationUrl]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 border-t`}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste an API key`}),(0,G.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(k,{htmlFor:`codex-api-key`,className:`text-xs`,children:`OpenAI API key`}),(0,G.jsx)(D,{id:`codex-api-key`,type:`password`,placeholder:`sk-...`,value:i,onChange:e=>a(e.target.value),className:`text-xs font-mono`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(k,{htmlFor:`codex-label`,className:`text-xs`,children:`Label (optional)`}),(0,G.jsx)(D,{id:`codex-label`,placeholder:`e.g. Personal, Work`,value:n,onChange:e=>r(e.target.value),className:`text-xs`})]})]}),p&&(0,G.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:p}),(0,G.jsxs)(C,{children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Cancel`}),(0,G.jsxs)(m,{size:`sm`,className:`text-xs cursor-pointer gap-1.5`,onClick:l,disabled:!i.trim()||c,children:[c?(0,G.jsx)(s,{className:`size-3.5 animate-spin`}):(0,G.jsx)(o,{className:`size-3.5`}),`Add key`]})]})]})})}function Le({mode:e,onOpenChange:t,password:n,onPasswordChange:r,busy:a,onExport:o,onImport:c,error:l}){let u=(0,W.useRef)(null),d=e===`export`;return(0,G.jsx)(j,{open:e!==null,onOpenChange:t,children:(0,G.jsxs)(O,{className:`sm:max-w-md`,children:[(0,G.jsxs)(g,{children:[(0,G.jsxs)(N,{className:`text-sm flex items-center gap-1.5`,children:[(0,G.jsx)(I,{className:`size-4`}),` `,d?`Export Codex Accounts`:`Import Codex Accounts`]}),(0,G.jsx)(M,{className:`text-xs leading-relaxed`,children:d?`Writes a password-encrypted file containing each account's login.`:`Reads a backup file. The password must be the one it was exported with.`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(k,{htmlFor:`codex-backup-password`,className:`text-xs`,children:`Password`}),(0,G.jsx)(D,{id:`codex-backup-password`,type:`password`,placeholder:d?`Choose a password`:`Password used for the export`,value:n,onChange:e=>r(e.target.value),className:`text-xs`,autoComplete:d?`new-password`:`current-password`}),(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`A backup holds full logins — keep the file and its password together.`})]}),l&&(0,G.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:l}),(0,G.jsx)(`input`,{ref:u,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&c(t)}}),(0,G.jsxs)(C,{children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Cancel`}),(0,G.jsxs)(m,{size:`sm`,className:`text-xs cursor-pointer gap-1.5`,disabled:!n.trim()||a,onClick:()=>d?o():u.current?.click(),children:[a?(0,G.jsx)(s,{className:`size-3.5 animate-spin`}):d?(0,G.jsx)(i,{className:`size-3.5`}):(0,G.jsx)(P,{className:`size-3.5`}),d?`Download backup`:`Choose file`]})]})]})})}var Re=[{value:`round-robin`,label:`Round-robin`,hint:`Take the next account each time.`},{value:`fill-first`,label:`Fill-first`,hint:`Stay on one account until it runs out.`},{value:`lowest-usage`,label:`Lowest usage`,hint:`Pick whichever has the most left.`}];function ze({open:e,onOpenChange:t,strategy:n,onChange:r}){return(0,G.jsx)(j,{open:e,onOpenChange:t,children:(0,G.jsxs)(O,{className:`sm:max-w-md`,children:[(0,G.jsxs)(g,{children:[(0,G.jsx)(N,{className:`text-sm`,children:`Codex Rotation`}),(0,G.jsx)(M,{className:`text-xs leading-relaxed`,children:`How a new chat chooses among your Codex accounts.`})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:Re.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(e.value),"aria-current":n===e.value?`true`:void 0,className:d(`w-full text-left rounded-md border px-3 py-2.5 min-h-11 cursor-pointer transition-colors`,n===e.value?`border-primary bg-primary/10`:`border-border hover:bg-accent/50 active:bg-accent`),children:[(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:e.label}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]},e.value))}),(0,G.jsx)(C,{children:(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Done`})})]})})}function $(e){return e==null?null:Math.round(e*100)}function Be({usage:e}){return(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(z,{label:`5-Hour Session`,pct:$(e.fiveHour),reset:U(e.session)}),(0,G.jsx)(z,{label:`Weekly`,pct:$(e.sevenDay),reset:U(e.weekly)})]})}var Ve=2e3,He=21e4;function Ue(e){let[t,n]=(0,W.useState)([]),[r,i]=(0,W.useState)(`round-robin`),[a,o]=(0,W.useState)({}),[s,c]=(0,W.useState)(!1),[d,f]=(0,W.useState)(``),[p,m]=(0,W.useState)(``),[h,g]=(0,W.useState)(!1),[_,v]=(0,W.useState)(null),[y,b]=(0,W.useState)(null),[x,S]=(0,W.useState)(!1),[C,w]=(0,W.useState)(``),[T,E]=(0,W.useState)(!1),[D,O]=(0,W.useState)(!1),[k,A]=(0,W.useState)(null),j=(0,W.useRef)(null),M=(0,W.useRef)(null),N=(0,W.useCallback)(async()=>{c(!0);try{let e=await l.get(`/api/codex-accounts`);n(e.accounts),i(e.strategy),l.get(`/api/codex-accounts/usage`).then(o).catch(()=>{})}finally{c(!1)}},[]);(0,W.useEffect)(()=>{N()},[N]);let P=async()=>{if(d.trim()){g(!0),v(null);try{await l.post(`/api/codex-accounts/api-key`,{apiKey:d.trim(),label:p.trim()||void 0}),f(``),m(``),e(),await N()}catch(e){v(e.message)}finally{g(!1)}}},F=(0,W.useCallback)(t=>{let n=Date.now()+He,r=!1;j.current=()=>{r=!0};let i=e=>{r=!0,j.current=null,M.current=null,e&&v(e),b(null),S(!1)},a=async()=>{if(r)return;let o=null;try{o=await l.get(`/api/codex-accounts/device-login/${t}/status`)}catch{}if(!r){if(o?.state===`done`){i(),m(``),e(),await N();return}if(o?.state===`error`){i(o.error);return}if(Date.now()>n){i(`Device login timed out.`);return}setTimeout(a,Ve)}};a()},[N]);return(0,W.useEffect)(()=>()=>{j.current?.();let e=M.current;e&&l.del(`/api/codex-accounts/device-login/${e}`).catch(()=>{})},[]),{accounts:t,strategy:r,usages:a,loading:s,apiKey:d,setApiKey:f,label:p,setLabel:m,adding:h,err:_,setErr:v,device:y,deviceWaiting:x,backupPassword:C,setBackupPassword:w,exporting:T,importing:D,msg:k,setMsg:A,load:N,addApiKey:P,startDevice:async()=>{v(null);try{let e=await l.post(`/api/codex-accounts/device-login`,{label:p.trim()||void 0});b(e),S(!0),M.current=e.id,F(e.id)}catch(e){v(e.message)}},remove:async e=>{await l.del(`/api/codex-accounts/${e}`),await N()},changeStrategy:async e=>{i(e);try{await l.put(`/api/codex-accounts/strategy`,{strategy:e})}catch{}},doExport:async()=>{if(!C.trim()){v(`Set a backup password first.`);return}E(!0),v(null),A(null);try{let t={"Content-Type":`application/json`},n=u();n&&(t.Authorization=`Bearer ${n}`);let r=await fetch(`/api/codex-accounts/export`,{method:`POST`,headers:t,body:JSON.stringify({password:C})});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error??`Export failed: ${r.status}`)}let i=await r.text(),a=new Blob([i],{type:`application/json`}),o=document.createElement(`a`);o.href=URL.createObjectURL(a),o.download=`ppm-codex-accounts-backup.json`,o.click(),URL.revokeObjectURL(o.href),A(`Backup downloaded.`),e()}catch(e){v(e.message)}finally{E(!1)}},doImport:async t=>{if(!C.trim()){v(`Enter the backup password first.`);return}O(!0),v(null),A(null);try{let n=await t.text(),r=await l.post(`/api/codex-accounts/import`,{data:n,password:C});A(`Imported ${r.imported}${r.skipped?`, skipped ${r.skipped}`:``}.`),e(),await N()}catch(e){v(e.message)}finally{O(!1)}}}}function We(){let[e,t]=(0,W.useState)(null),n=Ue(()=>t(null));return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(R,{description:(0,G.jsxs)(G.Fragment,{children:[`Each Codex account keeps its own login (`,(0,G.jsx)(`code`,{children:`CODEX_HOME`}),`). One is picked per chat by the rotation setting.`]}),onRefresh:()=>void n.load(),refreshing:n.loading,actions:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(m,{size:`sm`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`add`),children:[(0,G.jsx)(A,{className:`size-4`}),` Add account`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`export`),children:[(0,G.jsx)(i,{className:`size-4`}),` Export`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`import`),children:[(0,G.jsx)(P,{className:`size-4`}),` Import`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`rotation`),children:[(0,G.jsx)(b,{className:`size-4`}),` Rotation`]})]})}),(0,G.jsx)(V,{message:n.msg??n.err,onDismiss:()=>{n.setMsg(null),n.setErr(null)}}),(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium`,children:`Codex Accounts`}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground capitalize`,children:n.strategy.replace(`-`,` `)})]}),n.loading&&n.accounts.length===0?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-xs text-muted-foreground`,children:[(0,G.jsx)(s,{className:`size-4 animate-spin`}),` Loading accounts...`]}):n.accounts.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,G.jsx)(o,{className:`size-5 text-muted-foreground`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No Codex accounts yet.`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Chats use your default `,(0,G.jsx)(`code`,{children:`~/.codex`}),` login until you add one.`]})]}):(0,G.jsx)(H,{children:n.accounts.map(e=>{let t=n.usages[e.id]??{};return(0,G.jsxs)(B,{dense:!0,className:`min-w-[300px] shrink-0 snap-start`,"data-testid":`account-card`,"data-account-id":e.id,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium truncate flex-1 min-w-0`,children:e.label}),(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-text-subtle border border-border rounded px-1 shrink-0`,children:e.type}),e.planType&&(0,G.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:e.planType}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>void n.remove(e.id),title:`Remove account`,"aria-label":`Remove account`,className:`p-2 rounded cursor-pointer text-text-subtle hover:text-error hover:bg-surface-elevated transition-colors shrink-0`,children:(0,G.jsx)(S,{className:`size-4`})})]}),(0,G.jsx)(Be,{usage:t})]},e.id)})})]}),(0,G.jsx)(Ie,{open:e===`add`,onOpenChange:e=>t(e?`add`:null),label:n.label,onLabelChange:n.setLabel,apiKey:n.apiKey,onApiKeyChange:n.setApiKey,adding:n.adding,onAddApiKey:()=>void n.addApiKey(),deviceWaiting:n.deviceWaiting,onStartDevice:()=>void n.startDevice(),device:n.device,error:n.err}),(0,G.jsx)(Le,{mode:e===`export`?`export`:e===`import`?`import`:null,onOpenChange:e=>{e||t(null)},password:n.backupPassword,onPasswordChange:n.setBackupPassword,busy:n.exporting||n.importing,onExport:()=>void n.doExport(),onImport:e=>void n.doImport(e),error:n.err}),(0,G.jsx)(ze,{open:e===`rotation`,onOpenChange:e=>t(e?`rotation`:null),strategy:n.strategy,onChange:e=>void n.changeStrategy(e)})]})}var Ge=[{id:`claude`,label:`Claude`},{id:`codex`,label:`Codex`}];function Ke(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(`claude`);(0,W.useEffect)(()=>{let e=!1;return ae().then(n=>{e||t(new Set(Object.keys(n.providers??{})))}).catch(()=>{e||t(new Set([`claude`]))}),()=>{e=!0}},[]);let i=Ge.filter(t=>t.id===`claude`||e?.has(t.id)),a=i.length>1;return(0,G.jsxs)(`div`,{className:`space-y-4`,"data-testid":`accounts-pane`,"data-provider":n,children:[a&&(0,G.jsx)(`div`,{className:`flex gap-1 border-b border-border/50`,children:i.map(e=>(0,G.jsxs)(`button`,{onClick:()=>r(e.id),"data-testid":`accounts-tab-${e.id}`,"aria-current":n===e.id?`page`:void 0,className:`flex items-center gap-1.5 px-3 py-2 text-xs rounded-t transition-colors cursor-pointer ${n===e.id?`text-primary border-b-2 border-primary font-medium`:`text-text-subtle hover:text-text-secondary`}`,children:[(0,G.jsx)(x,{providerId:e.id}),e.label]},e.id))}),e===null&&!a&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,G.jsx)(s,{className:`size-3 animate-spin`}),` Checking configured providers...`]}),n===`claude`?(0,G.jsx)(Q,{}):(0,G.jsx)(We,{})]})}export{Ke as AccountsSettingsSection};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./loader-circle-DPMrnLQ2.js";import{t as i}from"./save-CipGrG1k.js";import{s as a}from"./api-client-oY1tC3tM.js";import"./vendor-mermaid-CKKtYuTV.js";import"./settings-store-DWUx3865.js";import{n as o}from"./utils-C9OjCrou.js";import{F as s,I as c,L as l,Mn as u,Nn as d,R as f,or as p,s as m,z as h}from"./index-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./loader-circle-DPMrnLQ2.js";import{t as i}from"./save-CipGrG1k.js";import{s as a}from"./api-client-oY1tC3tM.js";import"./vendor-mermaid-CKKtYuTV.js";import"./settings-store-DWUx3865.js";import{n as o}from"./utils-C9OjCrou.js";import{F as s,I as c,L as l,Mn as u,Nn as d,R as f,or as p,s as m,z as h}from"./index-DdMq4zqb.js";import{t as g}from"./use-monaco-theme-DOhDvEKJ.js";var _=e(t(),1),v=n();function y({metadata:e}){let t=e?.filePath,n=e?.name,o=e?.resourceType??`skill`,y=e?.scope??`user`,x=e?.readOnly===!0,S=e?.shadowed===!0,C=e?.shadowedBy,w=e?.project??``,[T,E]=(0,_.useState)(``),[D,O]=(0,_.useState)(``),[k,A]=(0,_.useState)(!0),[j,M]=(0,_.useState)(null),[N,P]=(0,_.useState)(!1),F=g(),I=(0,_.useRef)(``),L=T!==D;(0,_.useEffect)(()=>{let e=!1;return A(!0),M(null),f(t,w).then(t=>{e||(E(t.content),O(t.content),I.current=t.content)}).catch(t=>{e||M(t.message)}).finally(()=>{e||A(!1)}),()=>{e=!0}},[t,w]);let R=(0,_.useCallback)(async()=>{if(x||N)return;let e=I.current;if(e!==D){P(!0);try{await h(t,e,w),O(e),E(e),a.success(`Saved`),l.getState().reload()}catch(e){a.error(e.message)}finally{P(!1)}}},[t,w,D,x,N]);(0,_.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&(e.preventDefault(),R())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[R]);let z=c[o];return(0,v.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border px-3 py-2 shrink-0`,children:[(0,v.jsx)(z,{className:`size-4 text-text-subtle`}),(0,v.jsx)(`span`,{className:`text-sm font-semibold`,children:n}),(0,v.jsx)(s,{scope:y}),L&&!x&&(0,v.jsx)(`span`,{className:`size-1.5 rounded-full bg-primary`,title:`Unsaved changes`}),(0,v.jsx)(`div`,{className:`flex-1`}),(0,v.jsxs)(`span`,{className:`hidden sm:block text-[11px] text-text-subtle`,children:[o,` · markdown`]}),!x&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(`button`,{onClick:()=>E(D),disabled:!L||N,className:`flex items-center gap-1 rounded px-2 py-1 text-xs text-text-secondary hover:bg-surface-elevated disabled:opacity-40`,children:[(0,v.jsx)(u,{className:`size-3.5`}),` Revert`]}),(0,v.jsxs)(`button`,{onClick:()=>void R(),disabled:!L||N,className:`flex items-center gap-1 rounded bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-40`,children:[N?(0,v.jsx)(r,{className:`size-3.5 animate-spin`}):(0,v.jsx)(i,{className:`size-3.5`}),` Save`]})]})]}),x&&(0,v.jsx)(b,{icon:p,tone:`muted`,children:`Bundled resource — read-only. Duplicate it (from the AI Resources panel) to make an editable copy.`}),S&&C&&(0,v.jsxs)(b,{icon:d,tone:`warn`,children:[`This `,o,` is overridden by another “`,C.name,`” from a higher-priority source (`,C.source,`). It is currently inactive.`]}),(0,v.jsx)(`div`,{className:`min-h-0 flex-1`,children:k?(0,v.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,v.jsx)(r,{className:`size-5 animate-spin text-primary`})}):j?(0,v.jsx)(`div`,{className:`p-6 text-center text-sm text-destructive`,children:j}):(0,v.jsx)(m,{height:`100%`,language:`markdown`,theme:F,value:T,onChange:e=>{let t=e??``;I.current=t,E(t)},options:{readOnly:x,minimap:{enabled:!1},fontSize:13,wordWrap:`on`,scrollBeyondLastLine:!1,lineNumbers:`on`}})})]})}function b({icon:e,tone:t,children:n}){return(0,v.jsxs)(`div`,{className:o(`flex items-start gap-2 px-3 py-2 text-[12px] shrink-0 border-b border-border`,t===`warn`?`bg-amber-500/10 text-amber-300`:`bg-surface-elevated text-text-secondary`),children:[(0,v.jsx)(e,{className:`mt-0.5 size-3.5 shrink-0`}),(0,v.jsx)(`span`,{children:n})]})}export{y as AiResourceEditor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import{n as r}from"./api-client-oY1tC3tM.js";import{B as i,G as a,H as o,M as s,Pn as c,U as l,V as u,W as d,X as f,Y as p,cn as m,qn as h,wr as g}from"./index-DB-bD6Cx.js";import{getAISettings as _,updateAISettings as v}from"./api-settings-BVfemzZW.js";var y=e(t(),1),b=n(),x=[{value:`low`,label:`Low`},{value:`medium`,label:`Medium`},{value:`high`,label:`High`},{value:`xhigh`,label:`Extra`},{value:`max`,label:`Max`}],S=[{value:`bypassPermissions`,label:`Bypass permissions (default)`},{value:`default`,label:`Ask before edits`},{value:`acceptEdits`,label:`Edit automatically`},{value:`plan`,label:`Plan mode`}],C={claude:`Claude`,cursor:`Cursor`,codex:`Codex`,gemini:`Gemini`};function w({compact:e}={}){let[t,n]=(0,y.useState)(null),[c,h]=(0,y.useState)(``),[w,E]=(0,y.useState)([]),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(null),[N,P]=(0,y.useState)(0);(0,y.useEffect)(()=>{_().then(e=>{n(e),h(e.default_provider??`claude`)}).catch(e=>M(e.message))},[]),(0,y.useEffect)(()=>{c&&(O(!0),r.get(`/api/settings/ai/providers/${c}/models`).then(E).catch(()=>E([])).finally(()=>O(!1)))},[c]);let F=t?Object.keys(t.providers).filter(e=>e!==`mock`).map(e=>({id:e,name:C[e]??e})):[],I=t?.providers[c],L=I?.type===`agent-sdk`||!I?.type&&c===`claude`,R=async(e,r)=>{if(t){A(!0),M(null);try{n(await v({providers:{[c]:{[e]:r}}})),P(e=>e+1)}catch(e){M(e.message)}finally{A(!1)}}},z=e?`text-[11px]`:`text-sm`,B=e?`text-xs`:`text-sm`,V=e?`space-y-2`:`space-y-4`,H=e?`space-y-1.5`:`space-y-3`,U=e?`space-y-1`:`space-y-1.5`;if(!t)return(0,b.jsxs)(`div`,{className:H,children:[(0,b.jsx)(`h3`,{className:`${B} font-medium text-text-secondary`,children:`AI Settings`}),(0,b.jsx)(`p`,{className:`${z} text-text-subtle`,children:j?`Error: ${j}`:`Loading...`})]});let W=L?w:[{value:`__default__`,label:`Auto (default)`},...w];return(0,b.jsxs)(`div`,{className:V,children:[(0,b.jsx)(`h3`,{className:`${B} font-medium text-text-secondary`,children:`AI Settings`}),F.length>1&&(0,b.jsx)(`div`,{className:`flex gap-0.5 border-b border-border/50 -mx-1 px-1`,children:F.map(e=>(0,b.jsxs)(`button`,{onClick:()=>h(e.id),className:`flex items-center gap-1 px-2 py-1 text-[11px] rounded-t transition-colors ${c===e.id?`text-primary border-b-2 border-primary font-medium`:`text-text-subtle hover:text-text-secondary`}`,children:[(0,b.jsx)(s,{providerId:e.id}),(0,b.jsx)(`span`,{className:`capitalize`,children:e.name})]},e.id))}),(0,b.jsxs)(`div`,{className:H,children:[c===`codex`&&(0,b.jsxs)(`button`,{type:`button`,onClick:()=>m(`accounts`),className:`w-full flex items-center justify-between gap-2 rounded-md border border-border px-2.5 py-2 text-left cursor-pointer hover:bg-surface-elevated transition-colors`,children:[(0,b.jsx)(`span`,{className:`${z} text-text-secondary`,children:`Codex accounts & login`}),(0,b.jsx)(g,{className:`size-3.5 text-text-subtle shrink-0`})]}),w.length>0&&(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-model`,className:e?z:void 0,children:`Model`}),(0,b.jsxs)(i,{value:L?I?.model??w[0]?.value:I?.model||`__default__`,onValueChange:e=>R(`model`,e===`__default__`?void 0:e),disabled:D,children:[(0,b.jsx)(l,{id:`ai-model`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,b.jsx)(d,{placeholder:D?`Loading models...`:`Select model`})}),(0,b.jsx)(u,{className:`max-h-[300px]`,children:W.map(e=>(0,b.jsx)(o,{value:e.value,children:e.label},e.value))})]})]}),L&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-base-url`,className:e?z:void 0,children:`Base URL`}),(0,b.jsx)(f,{id:`ai-base-url`,type:`url`,defaultValue:I?.base_url??``,placeholder:`https://api.anthropic.com (default)`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{R(`base_url`,e.target.value.trim()||void 0)}},`baseurl-${c}-${N}`)]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-api-key`,className:e?z:void 0,children:`API Key / Token`}),(0,b.jsx)(f,{id:`ai-api-key`,type:`password`,defaultValue:I?.api_key??``,placeholder:`sk-ant-... (optional, overrides accounts)`,className:e?`h-7 text-[11px] font-mono`:`font-mono`,onBlur:e=>{let t=e.target.value.trim();t.startsWith(`••••`)||R(`api_key`,t||void 0)}},`apikey-${c}-${N}`),(0,b.jsx)(`p`,{className:`${e?`text-[9px]`:`text-[11px]`} text-muted-foreground`,children:`Direct API key or OAuth token. Leave empty to use connected accounts.`})]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-effort`,className:e?z:void 0,children:`Effort`}),(0,b.jsxs)(i,{value:I?.effort??`high`,onValueChange:e=>R(`effort`,e),children:[(0,b.jsx)(l,{id:`ai-effort`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,b.jsx)(d,{})}),(0,b.jsx)(u,{children:x.map(e=>(0,b.jsx)(o,{value:e.value,children:e.label},e.value))})]})]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-max-turns`,className:e?z:void 0,children:`Max Turns (1-500)`}),(0,b.jsx)(f,{id:`ai-max-turns`,type:`number`,min:1,max:500,defaultValue:I?.max_turns??100,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseInt(e.target.value);isNaN(t)||R(`max_turns`,t)}},`turns-${c}-${N}`)]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-budget`,className:e?z:void 0,children:`Max Budget (USD)`}),(0,b.jsx)(f,{id:`ai-budget`,type:`number`,step:.1,min:.01,max:50,defaultValue:I?.max_budget_usd??``,placeholder:`No limit`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseFloat(e.target.value);R(`max_budget_usd`,isNaN(t)?void 0:t)}},`budget-${c}-${N}`)]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-thinking`,className:e?z:void 0,children:`Thinking Budget (tokens)`}),(0,b.jsx)(f,{id:`ai-thinking`,type:`number`,min:0,defaultValue:I?.thinking_budget_tokens??``,placeholder:`Adaptive (model decides)`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseInt(e.target.value);R(`thinking_budget_tokens`,isNaN(t)?void 0:t)}},`thinking-${c}-${N}`)]}),(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(p,{htmlFor:`ai-agent-teams`,className:e?z:void 0,children:`Agent Teams`}),(0,b.jsx)(`p`,{className:`${e?`text-[9px]`:`text-[11px]`} text-muted-foreground`,children:`Experimental. Enables multi-agent collaboration with shared tasks and messaging. Uses ~7x more tokens.`})]}),(0,b.jsx)(a,{id:`ai-agent-teams`,checked:I?.agent_teams??!1,onCheckedChange:e=>R(`agent_teams`,e)})]}),I?.agent_teams&&(0,b.jsx)(T,{compact:e}),(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(p,{htmlFor:`ai-context-1m`,className:e?z:void 0,children:`1M Context Window`}),(0,b.jsx)(`p`,{className:`${e?`text-[9px]`:`text-[11px]`} text-muted-foreground`,children:`Requires an entitled account (Max/Team/Enterprise) and an Opus 4 / Sonnet 4 model. Other accounts will error.`})]}),(0,b.jsx)(a,{id:`ai-context-1m`,checked:I?.context_1m??!1,onCheckedChange:e=>R(`context_1m`,e)})]}),(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(p,{htmlFor:`ai-inherit-mcp`,className:e?z:void 0,children:`Inherit Claude Code MCP`}),(0,b.jsx)(`p`,{className:`${e?`text-[9px]`:`text-[11px]`} text-muted-foreground`,children:`Auto-load MCP servers from Claude Code's ~/.claude.json (global + per-project). Your own MCP servers override inherited ones.`})]}),(0,b.jsx)(a,{id:`ai-inherit-mcp`,checked:I?.inherit_claude_mcp??!0,onCheckedChange:e=>R(`inherit_claude_mcp`,e)})]})]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-permission-mode`,className:e?z:void 0,children:`Default Permission Mode`}),(0,b.jsxs)(i,{value:I?.permission_mode??`bypassPermissions`,onValueChange:e=>R(`permission_mode`,e),children:[(0,b.jsx)(l,{id:`ai-permission-mode`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,b.jsx)(d,{})}),(0,b.jsx)(u,{children:S.map(e=>(0,b.jsx)(o,{value:e.value,children:e.label},e.value))})]})]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-system-prompt`,className:e?z:void 0,children:`Additional Instructions`}),(0,b.jsx)(`textarea`,{id:`ai-system-prompt`,rows:e?3:4,defaultValue:I?.system_prompt??``,placeholder:`Enter additional instructions for ${c}...`,className:`w-full rounded-md border border-input bg-background px-3 py-2 ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${e?`text-[11px]`:`text-sm`}`,onBlur:e=>{R(`system_prompt`,e.target.value.trim()||void 0)}},`sysprompt-${c}-${N}`)]})]}),k&&(0,b.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`Saving...`}),j&&(0,b.jsx)(`p`,{className:`text-xs text-error`,children:j})]})}function T({compact:e}){let[t,n]=(0,y.useState)([]),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(null),l=(0,y.useCallback)(async()=>{a(!0);try{n(await r.get(`/api/teams`)??[])}catch{}a(!1)},[]);(0,y.useEffect)(()=>{l()},[l]);let u=async e=>{try{await r.del(`/api/teams/${encodeURIComponent(e)}`),n(t=>t.filter(t=>t.name!==e)),s(null)}catch{}};return t.length===0&&!i?null:(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,b.jsxs)(p,{className:e?`text-[11px]`:void 0,children:[`Teams (`,t.length,`)`]}),(0,b.jsx)(`button`,{onClick:l,className:`text-text-subtle hover:text-foreground p-1`,"aria-label":`Refresh teams`,children:(0,b.jsx)(h,{className:`size-3 ${i?`animate-spin`:``}`})})]}),t.map(e=>(0,b.jsxs)(`div`,{className:`flex items-center justify-between p-2 rounded bg-surface-elevated text-xs`,children:[(0,b.jsxs)(`div`,{className:`min-w-0`,children:[(0,b.jsx)(`div`,{className:`font-medium truncate`,children:e.name}),e.description&&(0,b.jsx)(`div`,{className:`text-text-subtle truncate`,children:e.description}),(0,b.jsxs)(`div`,{className:`text-text-subtle`,children:[e.members?.length??e.memberCount??0,` members`,e.createdAt?` · ${new Date(e.createdAt).toLocaleDateString()}`:``]})]}),o===e.name?(0,b.jsxs)(`div`,{className:`flex gap-1 shrink-0 ml-2`,children:[(0,b.jsx)(`button`,{onClick:()=>u(e.name),className:`px-2 py-1 bg-error text-white rounded text-[10px]`,children:`Delete`}),(0,b.jsx)(`button`,{onClick:()=>s(null),className:`px-2 py-1 bg-panel-2 text-text rounded text-[10px]`,children:`Cancel`})]}):(0,b.jsx)(`button`,{onClick:()=>s(e.name),className:`shrink-0 text-text-subtle hover:text-error p-1 ml-2`,"aria-label":`Delete team ${e.name}`,children:(0,b.jsx)(c,{className:`size-3.5`})})]},e.name))]})}export{w as t};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import{n as r}from"./api-client-oY1tC3tM.js";import{B as i,G as a,H as o,M as s,Pn as c,U as l,V as u,W as d,X as f,Y as p,cn as m,qn as h,wr as g}from"./index-DdMq4zqb.js";import{getAISettings as _,updateAISettings as v}from"./api-settings-BVfemzZW.js";var y=e(t(),1),b=n(),x=[{value:`low`,label:`Low`},{value:`medium`,label:`Medium`},{value:`high`,label:`High`},{value:`xhigh`,label:`Extra`},{value:`max`,label:`Max`}],S=[{value:`bypassPermissions`,label:`Bypass permissions (default)`},{value:`default`,label:`Ask before edits`},{value:`acceptEdits`,label:`Edit automatically`},{value:`plan`,label:`Plan mode`}],C={claude:`Claude`,cursor:`Cursor`,codex:`Codex`,gemini:`Gemini`};function w({compact:e}={}){let[t,n]=(0,y.useState)(null),[c,h]=(0,y.useState)(``),[w,E]=(0,y.useState)([]),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(null),[N,P]=(0,y.useState)(0);(0,y.useEffect)(()=>{_().then(e=>{n(e),h(e.default_provider??`claude`)}).catch(e=>M(e.message))},[]),(0,y.useEffect)(()=>{c&&(O(!0),r.get(`/api/settings/ai/providers/${c}/models`).then(E).catch(()=>E([])).finally(()=>O(!1)))},[c]);let F=t?Object.keys(t.providers).filter(e=>e!==`mock`).map(e=>({id:e,name:C[e]??e})):[],I=t?.providers[c],L=I?.type===`agent-sdk`||!I?.type&&c===`claude`,R=async(e,r)=>{if(t){A(!0),M(null);try{n(await v({providers:{[c]:{[e]:r}}})),P(e=>e+1)}catch(e){M(e.message)}finally{A(!1)}}},z=e?`text-[11px]`:`text-sm`,B=e?`text-xs`:`text-sm`,V=e?`space-y-2`:`space-y-4`,H=e?`space-y-1.5`:`space-y-3`,U=e?`space-y-1`:`space-y-1.5`;if(!t)return(0,b.jsxs)(`div`,{className:H,children:[(0,b.jsx)(`h3`,{className:`${B} font-medium text-text-secondary`,children:`AI Settings`}),(0,b.jsx)(`p`,{className:`${z} text-text-subtle`,children:j?`Error: ${j}`:`Loading...`})]});let W=L?w:[{value:`__default__`,label:`Auto (default)`},...w];return(0,b.jsxs)(`div`,{className:V,children:[(0,b.jsx)(`h3`,{className:`${B} font-medium text-text-secondary`,children:`AI Settings`}),F.length>1&&(0,b.jsx)(`div`,{className:`flex gap-0.5 border-b border-border/50 -mx-1 px-1`,children:F.map(e=>(0,b.jsxs)(`button`,{onClick:()=>h(e.id),className:`flex items-center gap-1 px-2 py-1 text-[11px] rounded-t transition-colors ${c===e.id?`text-primary border-b-2 border-primary font-medium`:`text-text-subtle hover:text-text-secondary`}`,children:[(0,b.jsx)(s,{providerId:e.id}),(0,b.jsx)(`span`,{className:`capitalize`,children:e.name})]},e.id))}),(0,b.jsxs)(`div`,{className:H,children:[c===`codex`&&(0,b.jsxs)(`button`,{type:`button`,onClick:()=>m(`accounts`),className:`w-full flex items-center justify-between gap-2 rounded-md border border-border px-2.5 py-2 text-left cursor-pointer hover:bg-surface-elevated transition-colors`,children:[(0,b.jsx)(`span`,{className:`${z} text-text-secondary`,children:`Codex accounts & login`}),(0,b.jsx)(g,{className:`size-3.5 text-text-subtle shrink-0`})]}),w.length>0&&(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-model`,className:e?z:void 0,children:`Model`}),(0,b.jsxs)(i,{value:L?I?.model??w[0]?.value:I?.model||`__default__`,onValueChange:e=>R(`model`,e===`__default__`?void 0:e),disabled:D,children:[(0,b.jsx)(l,{id:`ai-model`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,b.jsx)(d,{placeholder:D?`Loading models...`:`Select model`})}),(0,b.jsx)(u,{className:`max-h-[300px]`,children:W.map(e=>(0,b.jsx)(o,{value:e.value,children:e.label},e.value))})]})]}),L&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-base-url`,className:e?z:void 0,children:`Base URL`}),(0,b.jsx)(f,{id:`ai-base-url`,type:`url`,defaultValue:I?.base_url??``,placeholder:`https://api.anthropic.com (default)`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{R(`base_url`,e.target.value.trim()||void 0)}},`baseurl-${c}-${N}`)]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-api-key`,className:e?z:void 0,children:`API Key / Token`}),(0,b.jsx)(f,{id:`ai-api-key`,type:`password`,defaultValue:I?.api_key??``,placeholder:`sk-ant-... (optional, overrides accounts)`,className:e?`h-7 text-[11px] font-mono`:`font-mono`,onBlur:e=>{let t=e.target.value.trim();t.startsWith(`••••`)||R(`api_key`,t||void 0)}},`apikey-${c}-${N}`),(0,b.jsx)(`p`,{className:`${e?`text-[9px]`:`text-[11px]`} text-muted-foreground`,children:`Direct API key or OAuth token. Leave empty to use connected accounts.`})]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-effort`,className:e?z:void 0,children:`Effort`}),(0,b.jsxs)(i,{value:I?.effort??`high`,onValueChange:e=>R(`effort`,e),children:[(0,b.jsx)(l,{id:`ai-effort`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,b.jsx)(d,{})}),(0,b.jsx)(u,{children:x.map(e=>(0,b.jsx)(o,{value:e.value,children:e.label},e.value))})]})]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-max-turns`,className:e?z:void 0,children:`Max Turns (1-500)`}),(0,b.jsx)(f,{id:`ai-max-turns`,type:`number`,min:1,max:500,defaultValue:I?.max_turns??100,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseInt(e.target.value);isNaN(t)||R(`max_turns`,t)}},`turns-${c}-${N}`)]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-budget`,className:e?z:void 0,children:`Max Budget (USD)`}),(0,b.jsx)(f,{id:`ai-budget`,type:`number`,step:.1,min:.01,max:50,defaultValue:I?.max_budget_usd??``,placeholder:`No limit`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseFloat(e.target.value);R(`max_budget_usd`,isNaN(t)?void 0:t)}},`budget-${c}-${N}`)]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-thinking`,className:e?z:void 0,children:`Thinking Budget (tokens)`}),(0,b.jsx)(f,{id:`ai-thinking`,type:`number`,min:0,defaultValue:I?.thinking_budget_tokens??``,placeholder:`Adaptive (model decides)`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseInt(e.target.value);R(`thinking_budget_tokens`,isNaN(t)?void 0:t)}},`thinking-${c}-${N}`)]}),(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(p,{htmlFor:`ai-agent-teams`,className:e?z:void 0,children:`Agent Teams`}),(0,b.jsx)(`p`,{className:`${e?`text-[9px]`:`text-[11px]`} text-muted-foreground`,children:`Experimental. Enables multi-agent collaboration with shared tasks and messaging. Uses ~7x more tokens.`})]}),(0,b.jsx)(a,{id:`ai-agent-teams`,checked:I?.agent_teams??!1,onCheckedChange:e=>R(`agent_teams`,e)})]}),I?.agent_teams&&(0,b.jsx)(T,{compact:e}),(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(p,{htmlFor:`ai-context-1m`,className:e?z:void 0,children:`1M Context Window`}),(0,b.jsx)(`p`,{className:`${e?`text-[9px]`:`text-[11px]`} text-muted-foreground`,children:`Requires an entitled account (Max/Team/Enterprise) and an Opus 4 / Sonnet 4 model. Other accounts will error.`})]}),(0,b.jsx)(a,{id:`ai-context-1m`,checked:I?.context_1m??!1,onCheckedChange:e=>R(`context_1m`,e)})]}),(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(p,{htmlFor:`ai-inherit-mcp`,className:e?z:void 0,children:`Inherit Claude Code MCP`}),(0,b.jsx)(`p`,{className:`${e?`text-[9px]`:`text-[11px]`} text-muted-foreground`,children:`Auto-load MCP servers from Claude Code's ~/.claude.json (global + per-project). Your own MCP servers override inherited ones.`})]}),(0,b.jsx)(a,{id:`ai-inherit-mcp`,checked:I?.inherit_claude_mcp??!0,onCheckedChange:e=>R(`inherit_claude_mcp`,e)})]})]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-permission-mode`,className:e?z:void 0,children:`Default Permission Mode`}),(0,b.jsxs)(i,{value:I?.permission_mode??`bypassPermissions`,onValueChange:e=>R(`permission_mode`,e),children:[(0,b.jsx)(l,{id:`ai-permission-mode`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,b.jsx)(d,{})}),(0,b.jsx)(u,{children:S.map(e=>(0,b.jsx)(o,{value:e.value,children:e.label},e.value))})]})]}),(0,b.jsxs)(`div`,{className:U,children:[(0,b.jsx)(p,{htmlFor:`ai-system-prompt`,className:e?z:void 0,children:`Additional Instructions`}),(0,b.jsx)(`textarea`,{id:`ai-system-prompt`,rows:e?3:4,defaultValue:I?.system_prompt??``,placeholder:`Enter additional instructions for ${c}...`,className:`w-full rounded-md border border-input bg-background px-3 py-2 ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${e?`text-[11px]`:`text-sm`}`,onBlur:e=>{R(`system_prompt`,e.target.value.trim()||void 0)}},`sysprompt-${c}-${N}`)]})]}),k&&(0,b.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`Saving...`}),j&&(0,b.jsx)(`p`,{className:`text-xs text-error`,children:j})]})}function T({compact:e}){let[t,n]=(0,y.useState)([]),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(null),l=(0,y.useCallback)(async()=>{a(!0);try{n(await r.get(`/api/teams`)??[])}catch{}a(!1)},[]);(0,y.useEffect)(()=>{l()},[l]);let u=async e=>{try{await r.del(`/api/teams/${encodeURIComponent(e)}`),n(t=>t.filter(t=>t.name!==e)),s(null)}catch{}};return t.length===0&&!i?null:(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,b.jsxs)(p,{className:e?`text-[11px]`:void 0,children:[`Teams (`,t.length,`)`]}),(0,b.jsx)(`button`,{onClick:l,className:`text-text-subtle hover:text-foreground p-1`,"aria-label":`Refresh teams`,children:(0,b.jsx)(h,{className:`size-3 ${i?`animate-spin`:``}`})})]}),t.map(e=>(0,b.jsxs)(`div`,{className:`flex items-center justify-between p-2 rounded bg-surface-elevated text-xs`,children:[(0,b.jsxs)(`div`,{className:`min-w-0`,children:[(0,b.jsx)(`div`,{className:`font-medium truncate`,children:e.name}),e.description&&(0,b.jsx)(`div`,{className:`text-text-subtle truncate`,children:e.description}),(0,b.jsxs)(`div`,{className:`text-text-subtle`,children:[e.members?.length??e.memberCount??0,` members`,e.createdAt?` · ${new Date(e.createdAt).toLocaleDateString()}`:``]})]}),o===e.name?(0,b.jsxs)(`div`,{className:`flex gap-1 shrink-0 ml-2`,children:[(0,b.jsx)(`button`,{onClick:()=>u(e.name),className:`px-2 py-1 bg-error text-white rounded text-[10px]`,children:`Delete`}),(0,b.jsx)(`button`,{onClick:()=>s(null),className:`px-2 py-1 bg-panel-2 text-text rounded text-[10px]`,children:`Cancel`})]}):(0,b.jsx)(`button`,{onClick:()=>s(e.name),className:`shrink-0 text-text-subtle hover:text-error p-1 ml-2`,"aria-label":`Delete team ${e.name}`,children:(0,b.jsx)(c,{className:`size-3.5`})})]},e.name))]})}export{w as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import"./api-client-oY1tC3tM.js";import"./portal-container-context-a399Hd9F.js";import"./panel-store-BRrnDO_i.js";import"./window-store-DGKf9rPG.js";import"./tab-store-PZsP5ZwG.js";import"./use-is-mobile-CYW3FJFE.js";import{t as e}from"./ai-settings-section-
|
|
1
|
+
import"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import"./api-client-oY1tC3tM.js";import"./portal-container-context-a399Hd9F.js";import"./panel-store-BRrnDO_i.js";import"./window-store-DGKf9rPG.js";import"./tab-store-PZsP5ZwG.js";import"./use-is-mobile-CYW3FJFE.js";import{t as e}from"./ai-settings-section-B-1z-PRb.js";export{e as AISettingsSection};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import{c as r,l as i,s as a,u as o}from"./vendor-ui-CaeeFO0B.js";import{t as s}from"./check-DN75Ucvz.js";import{t as c}from"./text-wrap-oiekm5SB.js";import{s as l}from"./api-client-oY1tC3tM.js";import"./vendor-mermaid-CKKtYuTV.js";import{t as u}from"./settings-store-DWUx3865.js";import{n as d}from"./utils-C9OjCrou.js";import"./portal-container-context-a399Hd9F.js";import{n as f,t as p}from"./button-2WCAS8dI.js";import{n as m,r as h,t as g}from"./resolve-theme-b_yGlUFQ.js";import{$t as _,G as v,It as y,Pn as b,Qt as x,X as S,Xt as C,Yn as w,Yt as T,Zt as E,en as D,g as O,m as k}from"./index-DB-bD6Cx.js";import{t as A}from"./separator-BzGoTlR7.js";var j=n();function M(){let e=u(e=>e.themeStyle),t=u(e=>e.themeMode),n=u(e=>e.customThemeId),r=u(e=>e.customThemes),i=u(e=>e.setThemeStyle),a=u(e=>e.setThemeMode),o=g(e,t,r,n);return(0,j.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:m.map(e=>{let t=h[e];if(!t)return null;let n=o.id===e;return(0,j.jsxs)(`button`,{onClick:()=>{i(t.style),a(t.mode)},className:d(`relative flex items-center gap-2 rounded-lg border p-2 text-left transition-colors min-h-11`,n?`border-primary ring-[3px] ring-accent-wash`:`border-border hover:bg-accent/40`),children:[(0,j.jsx)(O,{swatch:t.swatch}),(0,j.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,j.jsx)(`span`,{className:`block truncate text-xs font-medium text-text`,children:t.name.replace(/ (Dark|Light)$/,``)}),(0,j.jsx)(`span`,{className:`block text-[10px] text-text-3 capitalize`,children:t.mode})]}),n&&(0,j.jsx)(s,{className:`absolute top-1 right-1 size-3.5 text-primary`})]},e)})})}var N=e(t(),1);function P({className:e,orientation:t=`horizontal`,...n}){return(0,j.jsx)(i,{"data-slot":`tabs`,"data-orientation":t,orientation:t,className:d(`group/tabs flex gap-2 data-[orientation=horizontal]:flex-col`,e),...n})}var F=f(`group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-[orientation=horizontal]/tabs:h-9 group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none`,{variants:{variant:{default:`bg-muted`,line:`gap-1 bg-transparent`}},defaultVariants:{variant:`default`}});function I({className:e,variant:t=`default`,...n}){return(0,j.jsx)(r,{"data-slot":`tabs-list`,"data-variant":t,className:d(F({variant:t}),e),...n})}function L({className:e,...t}){return(0,j.jsx)(o,{"data-slot":`tabs-trigger`,className:d(`relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,`group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent`,`data-[state=active]:bg-background data-[state=active]:text-foreground dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 dark:data-[state=active]:text-foreground`,`after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100`,e),...t})}function R({className:e,...t}){return(0,j.jsx)(a,{"data-slot":`tabs-content`,className:d(`flex-1 outline-none`,e),...t})}function z({open:e,onOpenChange:t}){let n=u(e=>e.importThemeFrom),r=u(e=>e.setCustomTheme),[i,a]=(0,N.useState)(`url`),[o,s]=(0,N.useState)(``),[c,d]=(0,N.useState)(``),[f,m]=(0,N.useState)(``),[h,g]=(0,N.useState)(!1),v=()=>{s(``),d(``),m(``),a(`url`)},y=async()=>{let e=i===`url`?o.trim():c.trim();if(!e){l.error(`Nothing to import`);return}g(!0);try{let a=await n({source:i===`url`?`url`:i===`upload`?`upload`:`json`,value:e,name:f.trim()||void 0});l.success(a.length>1?`Imported ${a.length} themes`:`Imported "${a[0]?.name}"`),a[0]&&r(a[0].id),v(),t(!1)}catch(e){l.error(e.message||`Import failed`)}finally{g(!1)}},b=async e=>{if(e)try{d(await e.text()),m(e.name.replace(/\.json$/i,``))}catch{l.error(`Could not read file`)}};return(0,j.jsx)(T,{open:e,onOpenChange:t,children:(0,j.jsxs)(C,{className:`max-w-md`,children:[(0,j.jsxs)(_,{children:[(0,j.jsx)(D,{children:`Import theme`}),(0,j.jsx)(E,{className:`text-text-3`,children:`Import a VSCode color theme. Single-mode themes apply to both dark and light.`})]}),(0,j.jsxs)(P,{value:i,onValueChange:e=>a(e),children:[(0,j.jsxs)(I,{className:`w-full`,children:[(0,j.jsx)(L,{value:`url`,className:`flex-1`,children:`URL`}),(0,j.jsx)(L,{value:`json`,className:`flex-1`,children:`Paste JSON`}),(0,j.jsx)(L,{value:`upload`,className:`flex-1`,children:`Upload`})]}),(0,j.jsxs)(R,{value:`url`,className:`space-y-2 pt-2`,children:[(0,j.jsx)(S,{placeholder:`https://…/theme.json or Marketplace .vsix URL`,value:o,onChange:e=>s(e.target.value)}),(0,j.jsx)(`p`,{className:`text-[11px] text-text-3`,children:`Only https URLs; private/internal addresses are blocked.`})]}),(0,j.jsx)(R,{value:`json`,className:`pt-2`,children:(0,j.jsx)(`textarea`,{className:`w-full h-40 rounded-md border border-border bg-surface p-2 text-xs font-mono text-text focus:outline-none focus:border-ring`,placeholder:`{ "name": "My Theme", "type": "dark", "colors": { … }, "tokenColors": [ … ] }`,value:c,onChange:e=>d(e.target.value)})}),(0,j.jsxs)(R,{value:`upload`,className:`space-y-2 pt-2`,children:[(0,j.jsx)(`input`,{type:`file`,accept:`.json,application/json`,onChange:e=>b(e.target.files?.[0]),className:`block w-full text-xs text-text-2 file:mr-3 file:rounded file:border file:border-border file:bg-panel-2 file:px-2 file:py-1 file:text-text`}),c&&(0,j.jsxs)(`p`,{className:`text-[11px] text-success`,children:[`File loaded (`,c.length,` chars)`]})]})]}),(0,j.jsx)(S,{placeholder:`Optional name`,value:f,onChange:e=>m(e.target.value)}),(0,j.jsxs)(x,{children:[(0,j.jsx)(p,{variant:`outline`,onClick:()=>t(!1),disabled:h,children:`Cancel`}),(0,j.jsx)(p,{onClick:y,disabled:h,children:h?`Importing…`:`Import`})]})]})})}function B(){let e=u(e=>e.customThemes),t=u(e=>e.themeStyle),n=u(e=>e.customThemeId),r=u(e=>e.setCustomTheme),i=u(e=>e.deleteCustomTheme),[a,o]=(0,N.useState)(!1);return(0,j.jsxs)(`section`,{className:`space-y-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,j.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:`Imported themes`}),(0,j.jsxs)(p,{size:`sm`,variant:`outline`,className:`h-7 gap-1 text-xs`,onClick:()=>o(!0),children:[(0,j.jsx)(w,{className:`size-3.5`}),` Import`]})]}),e.length===0?(0,j.jsx)(`p`,{className:`text-[11px] text-text-3`,children:`No imported themes yet. Import a VSCode theme from a URL, .vsix, or JSON.`}):(0,j.jsx)(`ul`,{className:`space-y-1`,children:e.map(e=>{let a=t===`custom`&&n===e.id;return(0,j.jsxs)(`li`,{className:d(`flex items-center gap-2 rounded-md border px-2 py-1.5`,a?`border-primary bg-primary/10`:`border-border`),children:[(0,j.jsx)(O,{swatch:e.swatch}),(0,j.jsxs)(`button`,{className:`flex-1 min-w-0 text-left`,onClick:()=>r(e.id),children:[(0,j.jsx)(`span`,{className:`block truncate text-xs text-text`,children:e.name}),(0,j.jsx)(`span`,{className:`block text-[10px] text-text-3`,children:e.mode})]}),a&&(0,j.jsx)(s,{className:`size-4 text-primary shrink-0`}),(0,j.jsx)(`button`,{className:`text-text-3 hover:text-error transition-colors shrink-0`,title:`Delete`,onClick:()=>void i(e.id),children:(0,j.jsx)(b,{className:`size-3.5`})})]},e.id)})}),(0,j.jsx)(z,{open:a,onOpenChange:o})]})}var V=[{value:`default`,label:`Default`},{value:`boxed`,label:`Boxed`},{value:`pill`,label:`Pill`}],H=[{value:`auto`,label:`Auto`},{value:`windows`,label:`Windows`},{value:`macos`,label:`macOS`}];function U({options:e,value:t,onChange:n}){return(0,j.jsx)(`div`,{className:`flex gap-2`,children:e.map(e=>(0,j.jsx)(p,{variant:t===e.value?`default`:`outline`,onClick:()=>n(e.value),className:d(`flex-1 cursor-pointer`,t===e.value&&`ring-2 ring-primary`),children:e.label},e.value))})}function W(){let{theme:e,setTheme:t,tabWrap:n,toggleTabWrap:r,editorTabStyle:i,setEditorTabStyle:a,explorerSkin:o,setExplorerSkin:s}=u(y(e=>({theme:e.themeMode,setTheme:e.setThemeMode,tabWrap:e.tabWrap,toggleTabWrap:e.toggleTabWrap,editorTabStyle:e.editorTabStyle,setEditorTabStyle:e.setEditorTabStyle,explorerSkin:e.explorerSkin,setExplorerSkin:e.setExplorerSkin})));return(0,j.jsxs)(`div`,{className:`space-y-6`,children:[(0,j.jsxs)(`section`,{className:`space-y-3`,children:[(0,j.jsx)(`h3`,{className:`text-sm font-medium`,children:`Theme`}),(0,j.jsx)(M,{}),(0,j.jsx)(`div`,{className:`flex gap-2`,children:k.map(n=>{let r=n.icon;return(0,j.jsxs)(p,{variant:e===n.value?`default`:`outline`,onClick:()=>t(n.value),className:d(`flex-1 gap-2 cursor-pointer`,e===n.value&&`ring-2 ring-primary`),children:[(0,j.jsx)(r,{className:`size-4`}),n.label]},n.value)})})]}),(0,j.jsx)(A,{}),(0,j.jsx)(B,{}),(0,j.jsx)(A,{}),(0,j.jsxs)(`section`,{className:`flex items-center justify-between gap-4`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,j.jsx)(c,{className:`size-4 text-muted-foreground shrink-0`}),(0,j.jsxs)(`div`,{className:`min-w-0`,children:[(0,j.jsx)(`p`,{className:`text-sm font-medium`,children:`Wrap Tabs`}),(0,j.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Stack tabs in rows instead of scrolling`})]})]}),(0,j.jsx)(v,{checked:n,onCheckedChange:r})]}),(0,j.jsxs)(`section`,{className:`space-y-2`,children:[(0,j.jsx)(`h3`,{className:`text-sm font-medium`,children:`Tab Style`}),(0,j.jsx)(U,{options:V,value:i,onChange:a})]}),(0,j.jsxs)(`section`,{className:`space-y-2`,children:[(0,j.jsx)(`h3`,{className:`text-sm font-medium`,children:`Explorer Skin`}),(0,j.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Chrome the OS File Explorer window wears. Auto follows the host platform.`}),(0,j.jsx)(U,{options:H,value:o,onChange:s})]})]})}export{W as AppearanceSettingsSection};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import{c as r,l as i,s as a,u as o}from"./vendor-ui-CaeeFO0B.js";import{t as s}from"./check-DN75Ucvz.js";import{t as c}from"./text-wrap-oiekm5SB.js";import{s as l}from"./api-client-oY1tC3tM.js";import"./vendor-mermaid-CKKtYuTV.js";import{t as u}from"./settings-store-DWUx3865.js";import{n as d}from"./utils-C9OjCrou.js";import"./portal-container-context-a399Hd9F.js";import{n as f,t as p}from"./button-2WCAS8dI.js";import{n as m,r as h,t as g}from"./resolve-theme-b_yGlUFQ.js";import{$t as _,G as v,It as y,Pn as b,Qt as x,X as S,Xt as C,Yn as w,Yt as T,Zt as E,en as D,g as O,m as k}from"./index-DdMq4zqb.js";import{t as A}from"./separator-BzGoTlR7.js";var j=n();function M(){let e=u(e=>e.themeStyle),t=u(e=>e.themeMode),n=u(e=>e.customThemeId),r=u(e=>e.customThemes),i=u(e=>e.setThemeStyle),a=u(e=>e.setThemeMode),o=g(e,t,r,n);return(0,j.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:m.map(e=>{let t=h[e];if(!t)return null;let n=o.id===e;return(0,j.jsxs)(`button`,{onClick:()=>{i(t.style),a(t.mode)},className:d(`relative flex items-center gap-2 rounded-lg border p-2 text-left transition-colors min-h-11`,n?`border-primary ring-[3px] ring-accent-wash`:`border-border hover:bg-accent/40`),children:[(0,j.jsx)(O,{swatch:t.swatch}),(0,j.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,j.jsx)(`span`,{className:`block truncate text-xs font-medium text-text`,children:t.name.replace(/ (Dark|Light)$/,``)}),(0,j.jsx)(`span`,{className:`block text-[10px] text-text-3 capitalize`,children:t.mode})]}),n&&(0,j.jsx)(s,{className:`absolute top-1 right-1 size-3.5 text-primary`})]},e)})})}var N=e(t(),1);function P({className:e,orientation:t=`horizontal`,...n}){return(0,j.jsx)(i,{"data-slot":`tabs`,"data-orientation":t,orientation:t,className:d(`group/tabs flex gap-2 data-[orientation=horizontal]:flex-col`,e),...n})}var F=f(`group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-[orientation=horizontal]/tabs:h-9 group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none`,{variants:{variant:{default:`bg-muted`,line:`gap-1 bg-transparent`}},defaultVariants:{variant:`default`}});function I({className:e,variant:t=`default`,...n}){return(0,j.jsx)(r,{"data-slot":`tabs-list`,"data-variant":t,className:d(F({variant:t}),e),...n})}function L({className:e,...t}){return(0,j.jsx)(o,{"data-slot":`tabs-trigger`,className:d(`relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,`group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent`,`data-[state=active]:bg-background data-[state=active]:text-foreground dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 dark:data-[state=active]:text-foreground`,`after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100`,e),...t})}function R({className:e,...t}){return(0,j.jsx)(a,{"data-slot":`tabs-content`,className:d(`flex-1 outline-none`,e),...t})}function z({open:e,onOpenChange:t}){let n=u(e=>e.importThemeFrom),r=u(e=>e.setCustomTheme),[i,a]=(0,N.useState)(`url`),[o,s]=(0,N.useState)(``),[c,d]=(0,N.useState)(``),[f,m]=(0,N.useState)(``),[h,g]=(0,N.useState)(!1),v=()=>{s(``),d(``),m(``),a(`url`)},y=async()=>{let e=i===`url`?o.trim():c.trim();if(!e){l.error(`Nothing to import`);return}g(!0);try{let a=await n({source:i===`url`?`url`:i===`upload`?`upload`:`json`,value:e,name:f.trim()||void 0});l.success(a.length>1?`Imported ${a.length} themes`:`Imported "${a[0]?.name}"`),a[0]&&r(a[0].id),v(),t(!1)}catch(e){l.error(e.message||`Import failed`)}finally{g(!1)}},b=async e=>{if(e)try{d(await e.text()),m(e.name.replace(/\.json$/i,``))}catch{l.error(`Could not read file`)}};return(0,j.jsx)(T,{open:e,onOpenChange:t,children:(0,j.jsxs)(C,{className:`max-w-md`,children:[(0,j.jsxs)(_,{children:[(0,j.jsx)(D,{children:`Import theme`}),(0,j.jsx)(E,{className:`text-text-3`,children:`Import a VSCode color theme. Single-mode themes apply to both dark and light.`})]}),(0,j.jsxs)(P,{value:i,onValueChange:e=>a(e),children:[(0,j.jsxs)(I,{className:`w-full`,children:[(0,j.jsx)(L,{value:`url`,className:`flex-1`,children:`URL`}),(0,j.jsx)(L,{value:`json`,className:`flex-1`,children:`Paste JSON`}),(0,j.jsx)(L,{value:`upload`,className:`flex-1`,children:`Upload`})]}),(0,j.jsxs)(R,{value:`url`,className:`space-y-2 pt-2`,children:[(0,j.jsx)(S,{placeholder:`https://…/theme.json or Marketplace .vsix URL`,value:o,onChange:e=>s(e.target.value)}),(0,j.jsx)(`p`,{className:`text-[11px] text-text-3`,children:`Only https URLs; private/internal addresses are blocked.`})]}),(0,j.jsx)(R,{value:`json`,className:`pt-2`,children:(0,j.jsx)(`textarea`,{className:`w-full h-40 rounded-md border border-border bg-surface p-2 text-xs font-mono text-text focus:outline-none focus:border-ring`,placeholder:`{ "name": "My Theme", "type": "dark", "colors": { … }, "tokenColors": [ … ] }`,value:c,onChange:e=>d(e.target.value)})}),(0,j.jsxs)(R,{value:`upload`,className:`space-y-2 pt-2`,children:[(0,j.jsx)(`input`,{type:`file`,accept:`.json,application/json`,onChange:e=>b(e.target.files?.[0]),className:`block w-full text-xs text-text-2 file:mr-3 file:rounded file:border file:border-border file:bg-panel-2 file:px-2 file:py-1 file:text-text`}),c&&(0,j.jsxs)(`p`,{className:`text-[11px] text-success`,children:[`File loaded (`,c.length,` chars)`]})]})]}),(0,j.jsx)(S,{placeholder:`Optional name`,value:f,onChange:e=>m(e.target.value)}),(0,j.jsxs)(x,{children:[(0,j.jsx)(p,{variant:`outline`,onClick:()=>t(!1),disabled:h,children:`Cancel`}),(0,j.jsx)(p,{onClick:y,disabled:h,children:h?`Importing…`:`Import`})]})]})})}function B(){let e=u(e=>e.customThemes),t=u(e=>e.themeStyle),n=u(e=>e.customThemeId),r=u(e=>e.setCustomTheme),i=u(e=>e.deleteCustomTheme),[a,o]=(0,N.useState)(!1);return(0,j.jsxs)(`section`,{className:`space-y-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,j.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:`Imported themes`}),(0,j.jsxs)(p,{size:`sm`,variant:`outline`,className:`h-7 gap-1 text-xs`,onClick:()=>o(!0),children:[(0,j.jsx)(w,{className:`size-3.5`}),` Import`]})]}),e.length===0?(0,j.jsx)(`p`,{className:`text-[11px] text-text-3`,children:`No imported themes yet. Import a VSCode theme from a URL, .vsix, or JSON.`}):(0,j.jsx)(`ul`,{className:`space-y-1`,children:e.map(e=>{let a=t===`custom`&&n===e.id;return(0,j.jsxs)(`li`,{className:d(`flex items-center gap-2 rounded-md border px-2 py-1.5`,a?`border-primary bg-primary/10`:`border-border`),children:[(0,j.jsx)(O,{swatch:e.swatch}),(0,j.jsxs)(`button`,{className:`flex-1 min-w-0 text-left`,onClick:()=>r(e.id),children:[(0,j.jsx)(`span`,{className:`block truncate text-xs text-text`,children:e.name}),(0,j.jsx)(`span`,{className:`block text-[10px] text-text-3`,children:e.mode})]}),a&&(0,j.jsx)(s,{className:`size-4 text-primary shrink-0`}),(0,j.jsx)(`button`,{className:`text-text-3 hover:text-error transition-colors shrink-0`,title:`Delete`,onClick:()=>void i(e.id),children:(0,j.jsx)(b,{className:`size-3.5`})})]},e.id)})}),(0,j.jsx)(z,{open:a,onOpenChange:o})]})}var V=[{value:`default`,label:`Default`},{value:`boxed`,label:`Boxed`},{value:`pill`,label:`Pill`}],H=[{value:`auto`,label:`Auto`},{value:`windows`,label:`Windows`},{value:`macos`,label:`macOS`}];function U({options:e,value:t,onChange:n}){return(0,j.jsx)(`div`,{className:`flex gap-2`,children:e.map(e=>(0,j.jsx)(p,{variant:t===e.value?`default`:`outline`,onClick:()=>n(e.value),className:d(`flex-1 cursor-pointer`,t===e.value&&`ring-2 ring-primary`),children:e.label},e.value))})}function W(){let{theme:e,setTheme:t,tabWrap:n,toggleTabWrap:r,editorTabStyle:i,setEditorTabStyle:a,explorerSkin:o,setExplorerSkin:s}=u(y(e=>({theme:e.themeMode,setTheme:e.setThemeMode,tabWrap:e.tabWrap,toggleTabWrap:e.toggleTabWrap,editorTabStyle:e.editorTabStyle,setEditorTabStyle:e.setEditorTabStyle,explorerSkin:e.explorerSkin,setExplorerSkin:e.setExplorerSkin})));return(0,j.jsxs)(`div`,{className:`space-y-6`,children:[(0,j.jsxs)(`section`,{className:`space-y-3`,children:[(0,j.jsx)(`h3`,{className:`text-sm font-medium`,children:`Theme`}),(0,j.jsx)(M,{}),(0,j.jsx)(`div`,{className:`flex gap-2`,children:k.map(n=>{let r=n.icon;return(0,j.jsxs)(p,{variant:e===n.value?`default`:`outline`,onClick:()=>t(n.value),className:d(`flex-1 gap-2 cursor-pointer`,e===n.value&&`ring-2 ring-primary`),children:[(0,j.jsx)(r,{className:`size-4`}),n.label]},n.value)})})]}),(0,j.jsx)(A,{}),(0,j.jsx)(B,{}),(0,j.jsx)(A,{}),(0,j.jsxs)(`section`,{className:`flex items-center justify-between gap-4`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,j.jsx)(c,{className:`size-4 text-muted-foreground shrink-0`}),(0,j.jsxs)(`div`,{className:`min-w-0`,children:[(0,j.jsx)(`p`,{className:`text-sm font-medium`,children:`Wrap Tabs`}),(0,j.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Stack tabs in rows instead of scrolling`})]})]}),(0,j.jsx)(v,{checked:n,onCheckedChange:r})]}),(0,j.jsxs)(`section`,{className:`space-y-2`,children:[(0,j.jsx)(`h3`,{className:`text-sm font-medium`,children:`Tab Style`}),(0,j.jsx)(U,{options:V,value:i,onChange:a})]}),(0,j.jsxs)(`section`,{className:`space-y-2`,children:[(0,j.jsx)(`h3`,{className:`text-sm font-medium`,children:`Explorer Skin`}),(0,j.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Chrome the OS File Explorer window wears. Auto follows the host platform.`}),(0,j.jsx)(U,{options:H,value:o,onChange:s})]})]})}export{W as AppearanceSettingsSection};
|