codepiper 0.1.0
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/.env.example +28 -0
- package/CHANGELOG.md +10 -0
- package/LEGAL_NOTICE.md +39 -0
- package/LICENSE +21 -0
- package/README.md +524 -0
- package/package.json +90 -0
- package/packages/cli/package.json +13 -0
- package/packages/cli/src/commands/analytics.ts +157 -0
- package/packages/cli/src/commands/attach.ts +299 -0
- package/packages/cli/src/commands/audit.ts +50 -0
- package/packages/cli/src/commands/auth.ts +261 -0
- package/packages/cli/src/commands/daemon.ts +162 -0
- package/packages/cli/src/commands/doctor.ts +303 -0
- package/packages/cli/src/commands/env-set.ts +162 -0
- package/packages/cli/src/commands/hook-forward.ts +268 -0
- package/packages/cli/src/commands/keys.ts +77 -0
- package/packages/cli/src/commands/kill.ts +19 -0
- package/packages/cli/src/commands/logs.ts +419 -0
- package/packages/cli/src/commands/model.ts +172 -0
- package/packages/cli/src/commands/policy-set.ts +185 -0
- package/packages/cli/src/commands/policy.ts +227 -0
- package/packages/cli/src/commands/providers.ts +114 -0
- package/packages/cli/src/commands/resize.ts +34 -0
- package/packages/cli/src/commands/send.ts +184 -0
- package/packages/cli/src/commands/sessions.ts +202 -0
- package/packages/cli/src/commands/slash.ts +92 -0
- package/packages/cli/src/commands/start.ts +243 -0
- package/packages/cli/src/commands/stop.ts +19 -0
- package/packages/cli/src/commands/tail.ts +137 -0
- package/packages/cli/src/commands/workflow.ts +786 -0
- package/packages/cli/src/commands/workspace.ts +127 -0
- package/packages/cli/src/lib/api.ts +78 -0
- package/packages/cli/src/lib/args.ts +72 -0
- package/packages/cli/src/lib/format.ts +93 -0
- package/packages/cli/src/main.ts +563 -0
- package/packages/core/package.json +7 -0
- package/packages/core/src/config.ts +30 -0
- package/packages/core/src/errors.ts +38 -0
- package/packages/core/src/eventBus.ts +56 -0
- package/packages/core/src/eventBusAdapter.ts +143 -0
- package/packages/core/src/index.ts +10 -0
- package/packages/core/src/sqliteEventBus.ts +336 -0
- package/packages/core/src/types.ts +63 -0
- package/packages/daemon/package.json +11 -0
- package/packages/daemon/src/api/analyticsRoutes.ts +343 -0
- package/packages/daemon/src/api/authRoutes.ts +344 -0
- package/packages/daemon/src/api/bodyLimit.ts +133 -0
- package/packages/daemon/src/api/envSetRoutes.ts +170 -0
- package/packages/daemon/src/api/gitRoutes.ts +409 -0
- package/packages/daemon/src/api/hooks.ts +588 -0
- package/packages/daemon/src/api/inputPolicy.ts +249 -0
- package/packages/daemon/src/api/notificationRoutes.ts +532 -0
- package/packages/daemon/src/api/policyRoutes.ts +234 -0
- package/packages/daemon/src/api/policySetRoutes.ts +445 -0
- package/packages/daemon/src/api/routeUtils.ts +28 -0
- package/packages/daemon/src/api/routes.ts +1004 -0
- package/packages/daemon/src/api/server.ts +1388 -0
- package/packages/daemon/src/api/settingsRoutes.ts +367 -0
- package/packages/daemon/src/api/sqliteErrors.ts +47 -0
- package/packages/daemon/src/api/stt.ts +143 -0
- package/packages/daemon/src/api/terminalRoutes.ts +200 -0
- package/packages/daemon/src/api/validation.ts +287 -0
- package/packages/daemon/src/api/validationRoutes.ts +174 -0
- package/packages/daemon/src/api/workflowRoutes.ts +567 -0
- package/packages/daemon/src/api/workspaceRoutes.ts +151 -0
- package/packages/daemon/src/api/ws.ts +1588 -0
- package/packages/daemon/src/auth/apiRateLimiter.ts +73 -0
- package/packages/daemon/src/auth/authMiddleware.ts +305 -0
- package/packages/daemon/src/auth/authService.ts +496 -0
- package/packages/daemon/src/auth/rateLimiter.ts +137 -0
- package/packages/daemon/src/config/pricing.ts +79 -0
- package/packages/daemon/src/crypto/encryption.ts +196 -0
- package/packages/daemon/src/db/db.ts +2745 -0
- package/packages/daemon/src/db/index.ts +16 -0
- package/packages/daemon/src/db/migrations.ts +182 -0
- package/packages/daemon/src/db/policyDb.ts +349 -0
- package/packages/daemon/src/db/schema.sql +408 -0
- package/packages/daemon/src/db/workflowDb.ts +464 -0
- package/packages/daemon/src/git/gitUtils.ts +544 -0
- package/packages/daemon/src/index.ts +6 -0
- package/packages/daemon/src/main.ts +525 -0
- package/packages/daemon/src/notifications/pushNotifier.ts +369 -0
- package/packages/daemon/src/providers/codexAppServerScaffold.ts +49 -0
- package/packages/daemon/src/providers/registry.ts +111 -0
- package/packages/daemon/src/providers/types.ts +82 -0
- package/packages/daemon/src/sessions/auditLogger.ts +103 -0
- package/packages/daemon/src/sessions/policyEngine.ts +165 -0
- package/packages/daemon/src/sessions/policyMatcher.ts +114 -0
- package/packages/daemon/src/sessions/policyTypes.ts +94 -0
- package/packages/daemon/src/sessions/ptyProcess.ts +141 -0
- package/packages/daemon/src/sessions/sessionManager.ts +1770 -0
- package/packages/daemon/src/sessions/tmuxSession.ts +1073 -0
- package/packages/daemon/src/sessions/transcriptManager.ts +110 -0
- package/packages/daemon/src/sessions/transcriptParser.ts +149 -0
- package/packages/daemon/src/sessions/transcriptTailer.ts +214 -0
- package/packages/daemon/src/tracking/tokenTracker.ts +168 -0
- package/packages/daemon/src/workflows/contextManager.ts +83 -0
- package/packages/daemon/src/workflows/index.ts +31 -0
- package/packages/daemon/src/workflows/resultExtractor.ts +118 -0
- package/packages/daemon/src/workflows/waitConditionPoller.ts +131 -0
- package/packages/daemon/src/workflows/workflowParser.ts +217 -0
- package/packages/daemon/src/workflows/workflowRunner.ts +969 -0
- package/packages/daemon/src/workflows/workflowTypes.ts +188 -0
- package/packages/daemon/src/workflows/workflowValidator.ts +533 -0
- package/packages/providers/claude-code/package.json +11 -0
- package/packages/providers/claude-code/src/index.ts +7 -0
- package/packages/providers/claude-code/src/overlaySettings.ts +198 -0
- package/packages/providers/claude-code/src/provider.ts +311 -0
- package/packages/web/dist/android-chrome-192x192.png +0 -0
- package/packages/web/dist/android-chrome-512x512.png +0 -0
- package/packages/web/dist/apple-touch-icon.png +0 -0
- package/packages/web/dist/assets/AnalyticsPage-BIopKWRf.js +17 -0
- package/packages/web/dist/assets/PoliciesPage-CjdLN3dl.js +11 -0
- package/packages/web/dist/assets/SessionDetailPage-BtSA0V0M.js +179 -0
- package/packages/web/dist/assets/SettingsPage-Dbbz4Ca5.js +37 -0
- package/packages/web/dist/assets/WorkflowsPage-Dv6f3GgU.js +1 -0
- package/packages/web/dist/assets/chart-vendor-DlOHLaCG.js +49 -0
- package/packages/web/dist/assets/codicon-ngg6Pgfi.ttf +0 -0
- package/packages/web/dist/assets/css.worker-BvV5MPou.js +93 -0
- package/packages/web/dist/assets/editor.worker-CKy7Pnvo.js +26 -0
- package/packages/web/dist/assets/html.worker-BLJhxQJQ.js +470 -0
- package/packages/web/dist/assets/index-BbdhRfr2.css +1 -0
- package/packages/web/dist/assets/index-hgphORiw.js +204 -0
- package/packages/web/dist/assets/json.worker-usMZ-FED.js +58 -0
- package/packages/web/dist/assets/monaco-core-B_19GPAS.css +1 -0
- package/packages/web/dist/assets/monaco-core-DQ5Mk8AK.js +1234 -0
- package/packages/web/dist/assets/monaco-react-DfZNWvtW.js +11 -0
- package/packages/web/dist/assets/monacoSetup-DvBj52bT.js +1 -0
- package/packages/web/dist/assets/pencil-Dbczxz59.js +11 -0
- package/packages/web/dist/assets/react-vendor-B5MgMUHH.js +136 -0
- package/packages/web/dist/assets/refresh-cw-B0MGsYPL.js +6 -0
- package/packages/web/dist/assets/tabs-C8LsWiR5.js +1 -0
- package/packages/web/dist/assets/terminal-vendor-Cs8KPbV3.js +9 -0
- package/packages/web/dist/assets/terminal-vendor-LcAfv9l9.css +32 -0
- package/packages/web/dist/assets/trash-2-Btlg0d4l.js +6 -0
- package/packages/web/dist/assets/ts.worker-DGHjMaqB.js +67731 -0
- package/packages/web/dist/favicon.ico +0 -0
- package/packages/web/dist/icon.svg +1 -0
- package/packages/web/dist/index.html +29 -0
- package/packages/web/dist/manifest.json +29 -0
- package/packages/web/dist/og-image.png +0 -0
- package/packages/web/dist/originals/android-chrome-192x192.png +0 -0
- package/packages/web/dist/originals/android-chrome-512x512.png +0 -0
- package/packages/web/dist/originals/apple-touch-icon.png +0 -0
- package/packages/web/dist/originals/favicon.ico +0 -0
- package/packages/web/dist/piper.svg +1 -0
- package/packages/web/dist/sounds/codepiper-soft-chime.wav +0 -0
- package/packages/web/dist/sw.js +257 -0
- package/scripts/postinstall-link-workspaces.mjs +58 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/monacoSetup-DvBj52bT.js","assets/monaco-react-DfZNWvtW.js","assets/react-vendor-B5MgMUHH.js","assets/monaco-core-DQ5Mk8AK.js","assets/monaco-core-B_19GPAS.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as u,j as t,k as ur,l as hs,o as gt,m as pt,n as wn,p as At,q as Vt,t as ps,w as dr,E as xs,x as kn,y as Rt,z as ke,A as gs,C as bs,D as We,F as Zt,G as ys,H as St,I as ft,J as vs,M as ws,K as ks,u as js}from"./react-vendor-B5MgMUHH.js";import{c as K,j as A,q as xt,i as Gt,S as mr,b as fr,G as jn,d as hr,e as pr,g as pn,s as Ns,a as Qe,t as xr,C as gr,u as q,T as Cs,v as Ss,B as Ke,P as Es,X as et,r as Rs,h as Et,L as br,w as Ae,x as yr,M as vr,y as en,z as wr,E as Ts,F as As,H as Ms,J as Ds,K as Ps,N as Ls,O as _s,Q as Fs,R as zs,U as $s,I as Is,V as Os,W as Bs,Y as Hs,_ as Us,$ as qs}from"./index-hgphORiw.js";import{_ as In}from"./monaco-core-DQ5Mk8AK.js";import{R as Vs}from"./refresh-cw-B0MGsYPL.js";import{L as On,P as Ks}from"./pencil-Dbczxz59.js";import{x as Gs,a as Ws}from"./terminal-vendor-Cs8KPbV3.js";import{T as Qs,a as Ys,b as Xs,c as kt}from"./tabs-C8LsWiR5.js";import"./chart-vendor-DlOHLaCG.js";/**
|
|
3
|
+
* @license lucide-react v0.564.0 - ISC
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the ISC license.
|
|
6
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/const Js=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],Bn=K("arrow-down",Js);/**
|
|
8
|
+
* @license lucide-react v0.564.0 - ISC
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the ISC license.
|
|
11
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/const Zs=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],kr=K("arrow-left",Zs);/**
|
|
13
|
+
* @license lucide-react v0.564.0 - ISC
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the ISC license.
|
|
16
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/const ea=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Hn=K("arrow-up",ea);/**
|
|
18
|
+
* @license lucide-react v0.564.0 - ISC
|
|
19
|
+
*
|
|
20
|
+
* This source code is licensed under the ISC license.
|
|
21
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
22
|
+
*/const ta=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742",key:"178tsu"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05",key:"1hqiys"}]],na=K("bell-off",ta);/**
|
|
23
|
+
* @license lucide-react v0.564.0 - ISC
|
|
24
|
+
*
|
|
25
|
+
* This source code is licensed under the ISC license.
|
|
26
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
27
|
+
*/const ra=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],jr=K("check",ra);/**
|
|
28
|
+
* @license lucide-react v0.564.0 - ISC
|
|
29
|
+
*
|
|
30
|
+
* This source code is licensed under the ISC license.
|
|
31
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
32
|
+
*/const sa=[["path",{d:"m7 6 5 5 5-5",key:"1lc07p"}],["path",{d:"m7 13 5 5 5-5",key:"1d48rs"}]],aa=K("chevrons-down",sa);/**
|
|
33
|
+
* @license lucide-react v0.564.0 - ISC
|
|
34
|
+
*
|
|
35
|
+
* This source code is licensed under the ISC license.
|
|
36
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
37
|
+
*/const ia=[["path",{d:"m17 11-5-5-5 5",key:"e8nh98"}],["path",{d:"m17 18-5-5-5 5",key:"2avn1x"}]],Un=K("chevrons-up",ia);/**
|
|
38
|
+
* @license lucide-react v0.564.0 - ISC
|
|
39
|
+
*
|
|
40
|
+
* This source code is licensed under the ISC license.
|
|
41
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
42
|
+
*/const oa=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Nr=K("circle",oa);/**
|
|
43
|
+
* @license lucide-react v0.564.0 - ISC
|
|
44
|
+
*
|
|
45
|
+
* This source code is licensed under the ISC license.
|
|
46
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
47
|
+
*/const la=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}]],ca=K("clipboard",la);/**
|
|
48
|
+
* @license lucide-react v0.564.0 - ISC
|
|
49
|
+
*
|
|
50
|
+
* This source code is licensed under the ISC license.
|
|
51
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
52
|
+
*/const ua=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],da=K("copy",ua);/**
|
|
53
|
+
* @license lucide-react v0.564.0 - ISC
|
|
54
|
+
*
|
|
55
|
+
* This source code is licensed under the ISC license.
|
|
56
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
57
|
+
*/const ma=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M9 10h6",key:"9gxzsh"}],["path",{d:"M12 13V7",key:"h0r20n"}],["path",{d:"M9 17h6",key:"r8uit2"}]],fa=K("file-diff",ma);/**
|
|
58
|
+
* @license lucide-react v0.564.0 - ISC
|
|
59
|
+
*
|
|
60
|
+
* This source code is licensed under the ISC license.
|
|
61
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
62
|
+
*/const ha=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M9 15h6",key:"cctwl0"}]],pa=K("file-minus",ha);/**
|
|
63
|
+
* @license lucide-react v0.564.0 - ISC
|
|
64
|
+
*
|
|
65
|
+
* This source code is licensed under the ISC license.
|
|
66
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
67
|
+
*/const xa=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]],ga=K("file-plus",xa);/**
|
|
68
|
+
* @license lucide-react v0.564.0 - ISC
|
|
69
|
+
*
|
|
70
|
+
* This source code is licensed under the ISC license.
|
|
71
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
72
|
+
*/const ba=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M12 17h.01",key:"p32p05"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}]],ya=K("file-question-mark",ba);/**
|
|
73
|
+
* @license lucide-react v0.564.0 - ISC
|
|
74
|
+
*
|
|
75
|
+
* This source code is licensed under the ISC license.
|
|
76
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
77
|
+
*/const va=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]],wa=K("file-text",va);/**
|
|
78
|
+
* @license lucide-react v0.564.0 - ISC
|
|
79
|
+
*
|
|
80
|
+
* This source code is licensed under the ISC license.
|
|
81
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
82
|
+
*/const ka=[["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["line",{x1:"3",x2:"9",y1:"12",y2:"12",key:"1dyftd"}],["line",{x1:"15",x2:"21",y1:"12",y2:"12",key:"oup4p8"}]],ja=K("git-commit-horizontal",ka);/**
|
|
83
|
+
* @license lucide-react v0.564.0 - ISC
|
|
84
|
+
*
|
|
85
|
+
* This source code is licensed under the ISC license.
|
|
86
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
87
|
+
*/const Na=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],Ca=K("history",Na);/**
|
|
88
|
+
* @license lucide-react v0.564.0 - ISC
|
|
89
|
+
*
|
|
90
|
+
* This source code is licensed under the ISC license.
|
|
91
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
92
|
+
*/const Sa=[["path",{d:"M10 8h.01",key:"1r9ogq"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M14 8h.01",key:"1primd"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"M18 8h.01",key:"emo2bl"}],["path",{d:"M6 8h.01",key:"x9i8wu"}],["path",{d:"M7 16h10",key:"wp8him"}],["path",{d:"M8 12h.01",key:"czm47f"}],["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}]],Ea=K("keyboard",Sa);/**
|
|
93
|
+
* @license lucide-react v0.564.0 - ISC
|
|
94
|
+
*
|
|
95
|
+
* This source code is licensed under the ISC license.
|
|
96
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
97
|
+
*/const Ra=[["path",{d:"M12 19v3",key:"npa21l"}],["path",{d:"M15 9.34V5a3 3 0 0 0-5.68-1.33",key:"1gzdoj"}],["path",{d:"M16.95 16.95A7 7 0 0 1 5 12v-2",key:"cqa7eg"}],["path",{d:"M18.89 13.23A7 7 0 0 0 19 12v-2",key:"16hl24"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v3a3 3 0 0 0 5.12 2.12",key:"r2i35w"}]],Ta=K("mic-off",Ra);/**
|
|
98
|
+
* @license lucide-react v0.564.0 - ISC
|
|
99
|
+
*
|
|
100
|
+
* This source code is licensed under the ISC license.
|
|
101
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
102
|
+
*/const Aa=[["path",{d:"M12 19v3",key:"npa21l"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["rect",{x:"9",y:"2",width:"6",height:"13",rx:"3",key:"s6n7sd"}]],Ma=K("mic",Aa);/**
|
|
103
|
+
* @license lucide-react v0.564.0 - ISC
|
|
104
|
+
*
|
|
105
|
+
* This source code is licensed under the ISC license.
|
|
106
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
107
|
+
*/const Da=[["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z",key:"2d38gg"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],Pa=K("octagon-x",Da);/**
|
|
108
|
+
* @license lucide-react v0.564.0 - ISC
|
|
109
|
+
*
|
|
110
|
+
* This source code is licensed under the ISC license.
|
|
111
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
112
|
+
*/const La=[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]],Cr=K("paperclip",La);/**
|
|
113
|
+
* @license lucide-react v0.564.0 - ISC
|
|
114
|
+
*
|
|
115
|
+
* This source code is licensed under the ISC license.
|
|
116
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
117
|
+
*/const _a=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],qn=K("rotate-cw",_a);/**
|
|
118
|
+
* @license lucide-react v0.564.0 - ISC
|
|
119
|
+
*
|
|
120
|
+
* This source code is licensed under the ISC license.
|
|
121
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
122
|
+
*/const Fa=[["path",{d:"M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z",key:"117uat"}],["path",{d:"M6 12h16",key:"s4cdu5"}]],za=K("send-horizontal",Fa);/**
|
|
123
|
+
* @license lucide-react v0.564.0 - ISC
|
|
124
|
+
*
|
|
125
|
+
* This source code is licensed under the ISC license.
|
|
126
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
127
|
+
*/const $a=[["path",{d:"m7 11 2-2-2-2",key:"1lz0vl"}],["path",{d:"M11 13h4",key:"1p7l4v"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}]],Ia=K("square-terminal",$a);/**
|
|
128
|
+
* @license lucide-react v0.564.0 - ISC
|
|
129
|
+
*
|
|
130
|
+
* This source code is licensed under the ISC license.
|
|
131
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
132
|
+
*/const Oa=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Ba=K("square",Oa);/**
|
|
133
|
+
* @license lucide-react v0.564.0 - ISC
|
|
134
|
+
*
|
|
135
|
+
* This source code is licensed under the ISC license.
|
|
136
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
137
|
+
*/const Ha=[["path",{d:"M13 8c0-2.76-2.46-5-5.5-5S2 5.24 2 8h2l1-1 1 1h4",key:"foxbe7"}],["path",{d:"M13 7.14A5.82 5.82 0 0 1 16.5 6c3.04 0 5.5 2.24 5.5 5h-3l-1-1-1 1h-3",key:"18arnh"}],["path",{d:"M5.89 9.71c-2.15 2.15-2.3 5.47-.35 7.43l4.24-4.25.7-.7.71-.71 2.12-2.12c-1.95-1.96-5.27-1.8-7.42.35",key:"ywahnh"}],["path",{d:"M11 15.5c.5 2.5-.17 4.5-1 6.5h4c2-5.5-.5-12-1-14",key:"ft0feo"}]],Ua=K("tree-palm",Ha),qa=50;function tn(e){let n=e[0].id,r=e[0].id;for(let s=1;s<e.length;s++)e[s].id<n&&(n=e[s].id),e[s].id>r&&(r=e[s].id);return{min:n,max:r}}function Nn({sessionId:e,source:n,limit:r=qa,order:s="desc",poll:i=!1,pollInterval:l=3e3}){const[a,c]=u.useState([]),[o,d]=u.useState(!0),[m,f]=u.useState(!1),[b,w]=u.useState(!1),x=u.useRef(null),k=u.useRef(!1),N=u.useRef(null),v=u.useRef(null);u.useEffect(()=>{let R=!1;return(async()=>{try{d(!0);const _=await A.getEvents(e,{source:n,limit:r,order:s});if(R)return;if(c(_.events),w(_.hasMore),_.events.length>0){const{min:$,max:Q}=tn(_.events);N.current=Q,v.current=$}}catch(_){R||console.error("Failed to load events:",_)}finally{R||d(!1)}})(),()=>{R=!0}},[e,n,r,s]);const y=u.useCallback(async()=>{if(!(k.current||!b||v.current===null)){k.current=!0,f(!0);try{const R=await A.getEvents(e,{source:n,before:v.current,limit:r,order:s});if(R.events.length>0){const{min:L}=tn(R.events);v.current=L,c(_=>[..._,...R.events])}w(R.hasMore)}catch(R){console.error("Failed to load more events:",R)}finally{k.current=!1,f(!1)}}},[e,n,r,s,b]);return u.useEffect(()=>{const R=x.current;if(!R)return;const L=new IntersectionObserver(_=>{var $;($=_[0])!=null&&$.isIntersecting&&b&&!k.current&&y()},{threshold:.1});return L.observe(R),()=>L.disconnect()},[b,y]),u.useEffect(()=>{if(!i||o)return;const R=setInterval(async()=>{if(N.current!==null)try{const L=await A.getEvents(e,{source:n,since:N.current,order:"asc"});if(L.events.length>0){const{min:_,max:$}=tn(L.events);N.current=$,v.current===null&&(v.current=_),c(Q=>s==="desc"?[...L.events.reverse(),...Q]:[...Q,...L.events])}}catch{}},l);return()=>clearInterval(R)},[e,n,s,i,l,o]),{events:a,loading:o,loadingMore:m,hasMore:b,loadMore:y,sentinelRef:x}}function Va({sessionId:e}){const{events:n,loading:r,loadingMore:s,hasMore:i,sentinelRef:l}=Nn({sessionId:e,order:"desc"}),[a,c]=u.useState(new Set),o=m=>{c(f=>{const b=new Set(f);return b.has(m)?b.delete(m):b.add(m),b})},d=m=>{switch(m){case"hook":return"bg-emerald-500/10 text-emerald-400 border-emerald-500/20";case"transcript":return"bg-cyan-500/10 text-cyan-400 border-cyan-500/20";case"pty":return"bg-violet-500/10 text-violet-400 border-violet-500/20";case"statusline":return"bg-amber-500/10 text-amber-400 border-amber-500/20";default:return"bg-muted/50 text-muted-foreground border-border"}};return r?t.jsx("div",{className:"flex items-center justify-center h-64",children:t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[t.jsx("div",{className:"w-4 h-4 border-2 border-cyan-500/30 border-t-cyan-500 rounded-full animate-spin"}),t.jsx("span",{className:"text-sm",children:"Loading events..."})]})}):n.length===0?t.jsx("div",{className:"flex items-center justify-center h-64",children:t.jsx("p",{className:"text-sm text-muted-foreground",children:"No events yet"})}):t.jsxs("div",{className:"space-y-1.5 p-3 md:p-4",children:[n.map(m=>{const f=a.has(m.id),b=typeof m.payload=="string"?m.payload:JSON.stringify(m.payload,null,2);return t.jsxs("div",{className:"rounded-lg border border-border bg-muted/30 cursor-pointer overflow-hidden transition-colors hover:bg-accent/50",onClick:()=>o(m.id),children:[t.jsxs("div",{className:"flex items-center justify-between px-3 md:px-4 py-2.5",children:[t.jsxs("div",{className:"flex items-center gap-2 md:gap-2.5 min-w-0",children:[t.jsx(xt,{className:`h-3 w-3 text-muted-foreground/40 transition-transform ${f?"rotate-90":""}`}),t.jsx("span",{className:`inline-flex items-center rounded-md border px-2 py-0.5 text-[10px] font-medium ${d(m.source)}`,children:m.source}),t.jsx("span",{className:"text-xs md:text-sm font-medium truncate",children:m.type})]}),t.jsx("span",{className:"text-[10px] md:text-[11px] text-muted-foreground/50 shrink-0 ml-2",children:Gt(m.timestamp)})]}),f&&t.jsx("div",{className:"border-t border-border/60 px-3 md:px-4 py-3",children:t.jsx("pre",{className:"text-xs bg-muted/80 p-3 rounded-lg overflow-x-auto font-mono text-muted-foreground/80",children:b})})]},m.id)}),t.jsx("div",{ref:l,className:"h-1"}),s&&t.jsx("div",{className:"flex items-center justify-center py-4",children:t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[t.jsx("div",{className:"w-4 h-4 border-2 border-cyan-500/30 border-t-cyan-500 rounded-full animate-spin"}),t.jsx("span",{className:"text-sm",children:"Loading more..."})]})}),!i&&n.length>0&&t.jsx("div",{className:"text-center py-3",children:t.jsx("span",{className:"text-xs text-muted-foreground/40",children:"All events loaded"})})]})}const nn="__working_tree__";function Ka({branches:e,currentBranch:n,selectedBase:r,onSelectBase:s}){const i=e.filter(l=>l!==n).sort((l,a)=>{const c=l==="main"||l==="master",o=a==="main"||a==="master";return c&&!o?-1:!c&&o?1:l.localeCompare(a)});return i.length===0?null:t.jsxs("div",{className:"hidden sm:flex items-center gap-1.5",children:[t.jsx("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground/60 font-semibold",children:"vs"}),t.jsxs(mr,{value:r??nn,onValueChange:l=>s(l===nn?null:l),children:[t.jsxs(fr,{className:"h-7 w-auto min-w-[120px] max-w-[200px] gap-1.5 border-border/60 bg-muted/30 text-xs font-mono px-2",children:[t.jsx(jn,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),t.jsx(hr,{})]}),t.jsxs(pr,{children:[t.jsx(pn,{value:nn,className:"text-xs",children:"Working tree"}),t.jsx(Ns,{}),i.map(l=>t.jsx(pn,{value:l,className:"text-xs font-mono",children:l},l))]})]})]})}function Ga({commits:e,selectedCommit:n,onSelectCommit:r}){return e.length===0?t.jsx("div",{className:"flex items-center justify-center h-32 text-muted-foreground/50",children:t.jsx("p",{className:"text-xs",children:"No commits found"})}):t.jsx("div",{className:"flex flex-col overflow-y-auto",children:e.map(s=>t.jsxs("button",{type:"button",className:Qe("flex items-start gap-2 px-3 py-2 text-left text-xs transition-colors border-b border-border/30 last:border-b-0",n===s.hash?"bg-cyan-500/10 text-foreground":"text-muted-foreground hover:bg-accent/40 hover:text-foreground"),onClick:()=>r(s.hash),children:[t.jsx(ja,{className:"h-3.5 w-3.5 mt-0.5 shrink-0 text-muted-foreground/50"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-2",children:[t.jsx("span",{className:"font-mono text-[10px] text-cyan-400/70 shrink-0",children:s.shortHash}),t.jsx("span",{className:"font-medium truncate",children:s.message})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-[10px] text-muted-foreground/50",children:[t.jsx("span",{children:s.author}),t.jsx("span",{children:"·"}),t.jsx("span",{children:Gt(s.date)})]})]})]},s.hash))})}const Wa=new Set(["png","jpg","jpeg","gif","webp","svg","ico","bmp","avif"]),Qa={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",json:"json",md:"markdown",css:"css",scss:"scss",html:"html",xml:"xml",yaml:"yaml",yml:"yaml",toml:"toml",py:"python",rs:"rust",go:"go",rb:"ruby",sh:"shell",bash:"shell",zsh:"shell",sql:"sql",graphql:"graphql",svg:"xml"};function Ya(e){var r;const n=((r=e.split(".").pop())==null?void 0:r.toLowerCase())||"";return Qa[n]||"plaintext"}function Xa(e){var r;const n=((r=e.split(".").pop())==null?void 0:r.toLowerCase())||"";return Wa.has(n)}const Ja=u.lazy(async()=>{await In(()=>import("./monacoSetup-DvBj52bT.js"),__vite__mapDeps([0,1,2,3,4]));const{DiffEditor:e}=await In(async()=>{const{DiffEditor:n}=await import("./monaco-react-DfZNWvtW.js");return{DiffEditor:n}},__vite__mapDeps([1,2]));return{default:function({original:r,modified:s,filePath:i,inline:l,monacoTheme:a}){const c=u.useRef(null),o=u.useCallback(d=>{c.current=d,requestAnimationFrame(()=>{d.layout()})},[]);return u.useEffect(()=>()=>{if(c.current){try{c.current.getModifiedEditor().setModel(null),c.current.getOriginalEditor().setModel(null)}catch{}c.current=null}},[]),t.jsx(e,{original:r,modified:s,language:Ya(i),theme:a,height:"100%",onMount:o,options:{readOnly:!0,renderSideBySide:!l,minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:12,lineNumbers:"on",folding:!0,wordWrap:"off",contextmenu:!1,scrollbar:{verticalScrollbarSize:8,horizontalScrollbarSize:8}}},i)}}});function Za(){return t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[t.jsx("div",{className:"w-4 h-4 border-2 border-cyan-500/30 border-t-cyan-500 rounded-full animate-spin"}),t.jsx("span",{className:"text-sm",children:"Loading editor..."})]})})}function ei({original:e,modified:n,filePath:r,inline:s,sessionId:i,originalRef:l,modifiedRef:a}){const{theme:c}=xr();return Xa(r)&&i?t.jsx(ti,{filePath:r,sessionId:i,originalRef:l,modifiedRef:a,hasOriginal:e!=="",hasModified:n!==""}):t.jsx(u.Suspense,{fallback:t.jsx(Za,{}),children:t.jsx(Ja,{original:e,modified:n,filePath:r,inline:s,monacoTheme:c.monacoTheme})})}function Vn(e,n,r,s){const[i,l]=u.useState(null),[a,c]=u.useState(!1),[o,d]=u.useState(!1);return u.useEffect(()=>{if(!(s&&n)){l(null),c(!1),d(!1);return}let m=!1;return c(!0),d(!1),A.getGitFileRawBlob(e,n,r).then(f=>{m||(f?l(b=>(b&&URL.revokeObjectURL(b),URL.createObjectURL(f))):d(!0),c(!1))},()=>{m||(d(!0),c(!1))}),()=>{m=!0,l(f=>(f&&URL.revokeObjectURL(f),null))}},[e,n,r,s]),{url:i,loading:a,error:o}}function ti({filePath:e,sessionId:n,originalRef:r,modifiedRef:s,hasOriginal:i,hasModified:l}){const a=e.split("/").pop()||e,c=l&&!!s,o=Vn(n,r,e,i),d=Vn(n,s,e,c);if(i&&o.loading||c&&d.loading)return t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[t.jsx("div",{className:"w-4 h-4 border-2 border-cyan-500/30 border-t-cyan-500 rounded-full animate-spin"}),t.jsx("span",{className:"text-sm",children:"Loading image..."})]})});if(l&&!s&&o.url)return t.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 p-6",children:[t.jsx(jt,{url:o.url,label:`${a} (HEAD)`}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Working tree changes — stage the file to preview the updated image"})]});if(!(o.url||d.url)){const f=i&&o.error||c&&d.error;return t.jsx("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"text-sm mb-1",children:f?"Cannot preview image diff":"Binary file"}),t.jsxs("p",{className:"text-xs text-muted-foreground/50",children:[f?"Binary file: ":"",a]})]})})}return!o.url&&d.url?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 p-6",children:[t.jsx("span",{className:"text-xs font-medium text-green-400 bg-green-500/10 px-2 py-0.5 rounded",children:"Added"}),t.jsx(jt,{url:d.url,label:a})]}):o.url&&!d.url?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 p-6",children:[t.jsx("span",{className:"text-xs font-medium text-red-400 bg-red-500/10 px-2 py-0.5 rounded",children:"Deleted"}),t.jsx(jt,{url:o.url,label:a,className:"opacity-50"})]}):t.jsxs("div",{className:"flex h-full",children:[t.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center border-r border-border/40 p-4 gap-3",children:[t.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:"Original"}),t.jsx(jt,{url:o.url,label:a})]}),t.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-4 gap-3",children:[t.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:"Modified"}),t.jsx(jt,{url:d.url,label:a})]})]})}function jt({url:e,label:n,className:r}){return t.jsx("div",{className:Qe("max-w-full max-h-[80%] overflow-auto",r),children:t.jsx("img",{src:e,alt:n,className:"max-w-full max-h-[60vh] object-contain rounded border border-border/30 bg-[repeating-conic-gradient(#1e2028_0%_25%,#1a1c24_0%_50%)_0_0/16px_16px]"})})}function ni(e){switch(e){case"M":return t.jsx(fa,{className:"h-3.5 w-3.5 text-amber-400"});case"A":return t.jsx(ga,{className:"h-3.5 w-3.5 text-emerald-400"});case"D":return t.jsx(pa,{className:"h-3.5 w-3.5 text-red-400"});case"?":return t.jsx(ya,{className:"h-3.5 w-3.5 text-muted-foreground/60"});default:return t.jsx(wa,{className:"h-3.5 w-3.5 text-muted-foreground/60"})}}function ri(e){return e.split("/").pop()||e}function Kn(e){const n=e.split("/");return n.length<=1?"":`${n.slice(0,-1).join("/")}/`}function Nt({title:e,count:n,defaultOpen:r=!0,accentColor:s,children:i,action:l}){const[a,c]=u.useState(r);return n===0?null:t.jsxs("div",{children:[t.jsxs("button",{type:"button",className:"flex items-center justify-between w-full px-3 py-1.5 text-[10px] uppercase tracking-wider font-semibold text-muted-foreground hover:text-foreground transition-colors",onClick:()=>c(!a),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[a?t.jsx(gr,{className:"h-3 w-3"}):t.jsx(xt,{className:"h-3 w-3"}),t.jsx("span",{children:e}),t.jsx("span",{className:Qe("ml-1 min-w-[18px] h-[16px] rounded-full text-[9px] font-bold flex items-center justify-center px-1",s),children:n})]}),l&&a&&t.jsx("span",{onClick:o=>o.stopPropagation(),children:l})]}),a&&t.jsx("div",{className:"space-y-0.5",children:i})]})}function rn({staged:e,unstaged:n,untracked:r,commitFiles:s,branchFiles:i,branchBase:l,selectedFile:a,onSelectFile:c,onStage:o,onUnstage:d}){return t.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[t.jsx(Nt,{title:"Staged",count:e.length,accentColor:"bg-emerald-500/20 text-emerald-400",action:d&&e.length>0?t.jsx("button",{type:"button",className:"text-[9px] text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded border border-border/60 hover:bg-accent/50 transition-colors",onClick:()=>d(e.map(m=>m.path)),children:"Unstage all"}):null,children:e.map(m=>t.jsx(Ct,{path:m.path,status:m.indexStatus,selected:a===m.path,onClick:()=>c(m.path,"staged"),actionLabel:"−",onAction:d?()=>d([m.path]):void 0},`staged-${m.path}`))}),t.jsx(Nt,{title:"Changes",count:n.length,accentColor:"bg-amber-500/20 text-amber-400",action:o&&n.length>0?t.jsx("button",{type:"button",className:"text-[9px] text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded border border-border/60 hover:bg-accent/50 transition-colors",onClick:()=>o(n.map(m=>m.path)),children:"Stage all"}):null,children:n.map(m=>t.jsx(Ct,{path:m.path,status:m.workTreeStatus,selected:a===m.path,onClick:()=>c(m.path,"unstaged"),actionLabel:"+",onAction:o?()=>o([m.path]):void 0},`unstaged-${m.path}`))}),t.jsx(Nt,{title:"Untracked",count:r.length,defaultOpen:!1,accentColor:"bg-muted/50 text-muted-foreground",action:o&&r.length>0?t.jsx("button",{type:"button",className:"text-[9px] text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded border border-border/60 hover:bg-accent/50 transition-colors",onClick:()=>o(r.map(m=>m.path)),children:"Stage all"}):null,children:r.map(m=>t.jsx(Ct,{path:m.path,status:"?",selected:a===m.path,onClick:()=>c(m.path,"untracked"),actionLabel:"+",onAction:o?()=>o([m.path]):void 0},`untracked-${m.path}`))}),s&&s.length>0&&t.jsx(Nt,{title:"Changed Files",count:s.length,accentColor:"bg-cyan-500/20 text-cyan-400",children:s.map(m=>t.jsx(Ct,{path:m.path,status:"M",selected:a===m.path,onClick:()=>c(m.path,"commit"),stat:{additions:m.additions,deletions:m.deletions}},`commit-${m.path}`))}),i&&i.length>0&&t.jsx(Nt,{title:`vs ${l??"base"}`,count:i.length,accentColor:"bg-violet-500/20 text-violet-400",children:i.map(m=>t.jsx(Ct,{path:m.path,status:m.deletions>0&&m.additions===0?"D":m.additions>0&&m.deletions===0?"A":"M",selected:a===m.path,onClick:()=>c(m.path,"branch"),stat:{additions:m.additions,deletions:m.deletions}},`branch-${m.path}`))}),e.length===0&&n.length===0&&r.length===0&&(!s||s.length===0)&&(!i||i.length===0)&&t.jsx("div",{className:"flex items-center justify-center h-32 text-muted-foreground/50",children:t.jsxs("div",{className:"text-center",children:[t.jsx(Nr,{className:"h-8 w-8 mx-auto mb-2 opacity-30"}),t.jsx("p",{className:"text-xs",children:"Clean working tree"})]})})]})}function Ct({path:e,status:n,selected:r,onClick:s,actionLabel:i,onAction:l,stat:a}){return t.jsxs("button",{type:"button",className:Qe("group flex items-center gap-2 w-full px-3 py-1 text-left text-xs transition-colors",r?"bg-cyan-500/10 text-foreground":"text-muted-foreground hover:bg-accent/40 hover:text-foreground"),onClick:s,children:[t.jsx("span",{className:"shrink-0 flex items-center overflow-hidden",children:ni(n)}),t.jsxs("span",{className:"flex-1 min-w-0 overflow-clip whitespace-nowrap text-ellipsis",title:e,children:[Kn(e)&&t.jsx("span",{className:"text-muted-foreground/40 text-[10px]",children:Kn(e)}),t.jsx("span",{className:"font-medium",children:ri(e)})]}),a&&t.jsxs("span",{className:"text-[10px] font-mono shrink-0",children:[a.additions>0&&t.jsxs("span",{className:"text-emerald-400",children:["+",a.additions]}),a.additions>0&&a.deletions>0&&t.jsx("span",{className:"text-muted-foreground/30",children:" "}),a.deletions>0&&t.jsxs("span",{className:"text-red-400",children:["−",a.deletions]})]}),l&&i&&t.jsx("button",{type:"button",className:"opacity-0 group-hover:opacity-100 shrink-0 w-5 h-5 rounded flex items-center justify-center text-[11px] font-bold border border-border/60 hover:bg-accent/80 transition-all",onClick:c=>{c.stopPropagation(),l()},children:i})]})}function si({sessionId:e}){const[n,r]=u.useState("working-tree"),[s,i]=u.useState(!0),[l,a]=u.useState(null),[c,o]=u.useState(""),[d,m]=u.useState([]),[f,b]=u.useState([]),[w,x]=u.useState(null),[k,N]=u.useState([]),[v,y]=u.useState(null),[R,L]=u.useState("unstaged"),[_,$]=u.useState(""),[Q,X]=u.useState(""),[de,g]=u.useState(!1),[ne,re]=u.useState(null),[ye,fe]=u.useState(),[Me,ge]=u.useState(),[me,je]=u.useState([]),[se,B]=u.useState(()=>localStorage.getItem(`codepiper:git:baseBranch:${e}`)||null),[Ee,V]=u.useState([]),[Re,ee]=u.useState(!1),D=d.filter(M=>M.indexStatus&&!M.isUntracked),G=d.filter(M=>M.workTreeStatus&&!M.isUntracked),pe=d.filter(M=>M.isUntracked),C=u.useCallback(async()=>{try{const M=await A.getGitStatus(e);m(M.status),o(M.branch),a(null)}catch(M){const Y=M instanceof Error?M.message:"Failed to load git status";a(Y)}},[e]),S=u.useCallback(async()=>{try{const M=await A.getGitLog(e,100);b(M.log)}catch(M){console.error("Failed to load git log:",M)}},[e]),O=u.useCallback(async()=>{try{const M=await A.getGitBranches(e);je(M.branches)}catch{}},[e]),I=u.useCallback(async M=>{try{const Y=await A.getGitDiffStat(e,"HEAD",M);V(Y.files)}catch{V([]),q.error(`Failed to compare against "${M}"`)}},[e]),W=u.useCallback(async()=>{i(!0),await Promise.all([C(),S(),O()]),i(!1)},[C,S,O]);u.useEffect(()=>{W()},[W]),u.useEffect(()=>{const M=setInterval(C,5e3);return()=>clearInterval(M)},[C]);const te=u.useCallback(M=>{B(M),M?localStorage.setItem(`codepiper:git:baseBranch:${e}`,M):localStorage.removeItem(`codepiper:git:baseBranch:${e}`),y(null),ee(!1)},[e]);u.useEffect(()=>{se?I(se):V([])},[se,I]),u.useEffect(()=>{se&&me.length>0&&!me.includes(se)&&(q.info(`Branch "${se}" no longer exists`),te(null))},[se,me,te]);const ie=u.useCallback(async(M,Y,De)=>{g(!0),re(null);try{let le,ce;switch(Y){case"branch":le=se??void 0,ce="HEAD";break;case"commit":le=De?`${De}^`:void 0,ce=De??"HEAD";break;case"staged":le="HEAD",ce=":0";break;case"untracked":le=void 0,ce="WORKING_TREE";break;default:le=":0",ce="WORKING_TREE";break}fe(le),ge(ce);const Ie={content:""},bt=async()=>{let be=!1,_e=!1;const[Oe,Ne]=await Promise.all([le?A.getGitFile(e,le,M).catch(Be=>(console.error(`Failed to load original (${le}):`,Be),be=!0,Ie)):Ie,A.getGitFile(e,ce,M).catch(Be=>(console.error(`Failed to load modified (${ce}):`,Be),_e=!0,Ie))]);return{origContent:Oe,modContent:Ne,origFailed:be,modFailed:_e}};let ue=await bt();if(ue.origFailed&&ue.modFailed&&(await new Promise(be=>setTimeout(be,200)),ue=await bt()),$(ue.origContent.content),X(ue.modContent.content),ue.origFailed&&ue.modFailed){const be="Failed to load file content from both sides";re(be),q.error(be)}else ue.modFailed&&Y!=="untracked"&&q.error(`Failed to load modified version (${ce})`)}catch(le){const ce=le instanceof Error?le.message:"Failed to load diff";console.error("Failed to load diff:",le),re(ce),q.error(ce),$(""),X("")}finally{g(!1)}},[e,se]),J=u.useCallback((M,Y)=>{y(M),L(Y),re(null),ee(!0),ie(M,Y,w||void 0)},[ie,w]),ve=u.useCallback(async M=>{x(M),y(null),ee(!1);try{const Y=await A.getGitDiffStat(e,M);N(Y.files)}catch(Y){console.error("Failed to load commit files:",Y),N([])}},[e]),xe=u.useCallback(async M=>{try{await A.stageFiles(e,M),await C(),q.success(`Staged ${M.length} file${M.length>1?"s":""}`)}catch(Y){q.error(Y instanceof Error?Y.message:"Failed to stage files")}},[e,C]),oe=u.useCallback(async M=>{try{await A.unstageFiles(e,M),await C(),q.success(`Unstaged ${M.length} file${M.length>1?"s":""}`)}catch(Y){q.error(Y instanceof Error?Y.message:"Failed to unstage files")}},[e,C]);return s?t.jsx("div",{className:"flex items-center justify-center h-64",children:t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[t.jsx("div",{className:"w-4 h-4 border-2 border-cyan-500/30 border-t-cyan-500 rounded-full animate-spin"}),t.jsx("span",{className:"text-sm",children:"Loading git info..."})]})}):l?t.jsx("div",{className:"flex items-center justify-center h-64",children:t.jsxs("div",{className:"text-center",children:[t.jsx(Ua,{className:"h-10 w-10 mx-auto mb-3 text-muted-foreground/30"}),t.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Not a git repository"}),t.jsx("p",{className:"text-xs text-muted-foreground/50",children:l})]})}):t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 md:px-4 py-2 bg-muted/20",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"flex items-center rounded-lg border border-border/60 bg-muted/30 p-0.5",children:[t.jsx("button",{type:"button",className:Qe("px-2.5 py-1 rounded-md text-xs font-medium transition-colors",n==="working-tree"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),onClick:()=>{r("working-tree"),x(null),N([]),y(null),ee(!1)},children:"Changes"}),t.jsxs("button",{type:"button",className:Qe("px-2.5 py-1 rounded-md text-xs font-medium transition-colors",n==="commits"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),onClick:()=>{r("commits"),y(null),ee(!1)},children:[t.jsx(Ca,{className:"h-3 w-3 inline mr-1"}),"Commits"]})]}),c&&t.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 text-xs text-muted-foreground",children:[t.jsx(jn,{className:"h-3 w-3"}),t.jsx("span",{className:"font-mono",children:c})]}),c&&me.length>1&&t.jsx(Ka,{branches:me,currentBranch:c,selectedBase:se,onSelectBase:te})]}),t.jsxs("button",{type:"button",className:"flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors px-2 py-1 rounded-md hover:bg-accent/50",onClick:()=>{W(),q.success("Refreshed")},children:[t.jsx(Vs,{className:"h-3 w-3"}),t.jsx("span",{className:"hidden sm:inline",children:"Refresh"})]})]}),t.jsxs("div",{className:"flex-1 min-h-0 flex",children:[t.jsx("div",{className:Qe("border-r border-border/60 flex flex-col overflow-hidden",Re?"hidden md:flex md:w-[280px] lg:w-[320px]":"w-full md:w-[280px] lg:w-[320px]","shrink-0"),children:n==="working-tree"?se?t.jsx(rn,{staged:[],unstaged:[],untracked:[],branchFiles:Ee,branchBase:se,selectedFile:v,onSelectFile:M=>{y(M),L("branch"),ee(!0),ie(M,"branch")}}):t.jsx(rn,{staged:D,unstaged:G,untracked:pe,selectedFile:v,onSelectFile:J,onStage:xe,onUnstage:oe}):t.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[t.jsx(Ga,{commits:f,selectedCommit:w,onSelectCommit:ve}),w&&k.length>0&&t.jsx("div",{className:"border-t border-border/60 flex-shrink-0 max-h-[40%] overflow-y-auto",children:t.jsx(rn,{staged:[],unstaged:[],untracked:[],commitFiles:k,selectedFile:v,onSelectFile:M=>{y(M),L("commit"),ee(!0),ie(M,"commit",w)}})})]})}),t.jsxs("div",{className:Qe("flex-1 min-w-0 flex flex-col",!Re&&"hidden md:flex"),children:[Re&&t.jsxs("div",{className:"md:hidden flex items-center gap-2 px-3 py-2 border-b border-border/60 bg-muted/10",children:[t.jsxs("button",{type:"button",className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors",onClick:()=>{ee(!1),y(null)},children:[t.jsx(kr,{className:"h-3.5 w-3.5"}),"Back"]}),v&&t.jsx("span",{className:"text-xs font-mono text-muted-foreground/70 truncate",children:v})]}),v&&!de&&ne?t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("div",{className:"text-center",children:[t.jsx(Cs,{className:"h-10 w-10 mx-auto mb-3 text-yellow-500/60"}),t.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:ne}),t.jsx("button",{type:"button",className:"text-xs px-3 py-1.5 rounded-md bg-accent/50 hover:bg-accent text-foreground transition-colors",onClick:()=>{v&&ie(v,R,w||void 0)},children:"Retry"})]})}):v&&!de?t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(ei,{original:_,modified:Q,filePath:v,sessionId:e,originalRef:ye,modifiedRef:Me})}):de?t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[t.jsx("div",{className:"w-4 h-4 border-2 border-cyan-500/30 border-t-cyan-500 rounded-full animate-spin"}),t.jsx("span",{className:"text-sm",children:"Loading diff..."})]})}):t.jsx("div",{className:"flex items-center justify-center h-full text-muted-foreground/40",children:t.jsxs("div",{className:"text-center",children:[t.jsx(ai,{className:"h-12 w-12 mx-auto mb-3 opacity-30"}),t.jsx("p",{className:"text-sm",children:n==="commits"&&!w?"Select a commit to view changes":"Select a file to view diff"})]})})]})]})]})}function ai({className:e}){return t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",className:e,role:"img","aria-label":"File diff",children:[t.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),t.jsx("path",{d:"M14 2v6h6"}),t.jsx("path",{d:"M9 15h6"}),t.jsx("path",{d:"M12 12v6"})]})}function ii({sessionId:e}){const{events:n,loading:r,loadingMore:s,hasMore:i,sentinelRef:l}=Nn({sessionId:e,source:"transcript",order:"desc"}),a=Ss(n).reverse();return r?t.jsx("div",{className:"flex items-center justify-center h-64",children:t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[t.jsx("div",{className:"w-4 h-4 border-2 border-cyan-500/30 border-t-cyan-500 rounded-full animate-spin"}),t.jsx("span",{className:"text-sm",children:"Loading conversation..."})]})}):a.length===0?t.jsx("div",{className:"flex items-center justify-center h-64",children:t.jsx("p",{className:"text-sm text-muted-foreground",children:"No messages yet"})}):t.jsxs("div",{className:"space-y-2 p-3 md:p-4",children:[a.map((c,o)=>t.jsx(oi,{message:c},`${c.timestamp.getTime()}-${o}`)),t.jsx("div",{ref:l,className:"h-1"}),s&&t.jsx("div",{className:"flex items-center justify-center py-4",children:t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[t.jsx("div",{className:"w-4 h-4 border-2 border-cyan-500/30 border-t-cyan-500 rounded-full animate-spin"}),t.jsx("span",{className:"text-sm",children:"Loading more..."})]})}),!i&&a.length>0&&t.jsx("div",{className:"text-center py-3",children:t.jsx("span",{className:"text-xs text-muted-foreground/40",children:"All messages loaded"})})]})}function oi({message:e}){const n=s=>{switch(s){case"user":return"border-cyan-500/15 bg-cyan-500/[0.03]";case"assistant":return"border-violet-500/15 bg-violet-500/[0.03]";default:return"border-amber-500/15 bg-amber-500/[0.03]"}},r=s=>{switch(s){case"user":return"text-cyan-400";case"assistant":return"text-violet-400";default:return"text-amber-400"}};return t.jsxs("div",{className:`rounded-lg border p-3 md:p-4 ${n(e.role)}`,children:[t.jsxs("div",{className:"flex items-start justify-between mb-2",children:[t.jsx("span",{className:`text-xs font-semibold capitalize ${r(e.role)}`,children:e.role}),t.jsx("span",{className:"text-[11px] text-muted-foreground/50",children:Gt(e.timestamp)})]}),t.jsx("div",{className:"text-sm whitespace-pre-wrap font-mono leading-relaxed",children:e.content}),e.tokens&&t.jsxs("div",{className:"mt-2 text-[11px] text-muted-foreground/40 font-mono",children:[e.tokens.prompt," prompt · ",e.tokens.completion," completion"]})]})}function li({sessionId:e}){const[n,r]=u.useState([]),[s,i]=u.useState([]),[l,a]=u.useState([]),[c,o]=u.useState(!0),[d,m]=u.useState(""),f=u.useCallback(async()=>{try{const[k,N,v]=await Promise.all([A.getSessionPolicySets(e),A.getEffectivePolicies(e),A.getPolicySets()]);r(k.policySets),i(N.policies),a(v.policySets)}catch{q.error("Failed to load session policies")}finally{o(!1)}},[e]);u.useEffect(()=>{f()},[f]);const b=async()=>{if(d)try{await A.applyPolicySetToSession(e,d),q.success("Policy set applied"),m(""),f()}catch(k){q.error(k instanceof Error?k.message:"Failed to apply set")}},w=async k=>{try{await A.removePolicySetFromSession(e,k),q.success("Policy set removed"),f()}catch(N){q.error(N instanceof Error?N.message:"Failed to remove set")}},x=l.filter(k=>!n.some(N=>N.id===k.id));return c?t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground py-16 justify-center",children:[t.jsx("div",{className:"w-4 h-4 border-2 border-cyan-500/30 border-t-cyan-500 rounded-full animate-spin"}),t.jsx("span",{className:"text-sm",children:"Loading policies..."})]}):t.jsxs("div",{className:"p-6 space-y-6 max-w-4xl",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[t.jsx(On,{className:"h-4 w-4 text-cyan-400"}),"Applied Policy Sets"]}),x.length>0&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(mr,{value:d,onValueChange:m,children:[t.jsx(fr,{className:"w-48 h-8 text-xs border-border bg-muted/30",children:t.jsx(hr,{placeholder:"Select a set..."})}),t.jsx(pr,{children:x.map(k=>t.jsx(pn,{value:k.id,children:k.name},k.id))})]}),t.jsxs(Ke,{size:"sm",onClick:b,disabled:!d,className:"h-8 text-xs bg-cyan-600 hover:bg-cyan-700 text-white border-0",children:[t.jsx(Es,{className:"h-3 w-3 mr-1"}),"Apply"]})]})]}),n.length===0?t.jsx("p",{className:"text-xs text-muted-foreground/50 text-center py-4 border border-dashed border-border rounded-lg",children:"No policy sets applied to this session."}):t.jsx("div",{className:"flex flex-wrap gap-2",children:n.map(k=>t.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-border bg-muted/20 text-sm",children:[t.jsx(On,{className:"h-3 w-3 text-cyan-400"}),t.jsx("span",{children:k.name}),t.jsxs("span",{className:"text-[10px] text-muted-foreground/50",children:["(",k.policyCount,")"]}),t.jsx("button",{type:"button",onClick:()=>w(k.id),className:"ml-1 text-muted-foreground hover:text-red-400 transition-colors",children:t.jsx(et,{className:"h-3 w-3"})})]},k.id))})]}),t.jsxs("div",{children:[t.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2 mb-3",children:[t.jsx(Rs,{className:"h-4 w-4 text-emerald-400"}),"Effective Policies",t.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(resolved from direct + sets + global, sorted by priority)"})]}),s.length===0?t.jsx("p",{className:"text-xs text-muted-foreground/50 text-center py-4 border border-dashed border-border rounded-lg",children:"No policies apply to this session."}):t.jsx("div",{className:"space-y-2",children:s.map(k=>t.jsxs("div",{className:"flex items-center justify-between py-2.5 px-4 rounded-lg border border-border bg-card/80",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Et,{variant:k.enabled?"success":"secondary",className:"text-[10px]",children:k.enabled?"Active":"Off"}),t.jsx("span",{className:"text-sm font-medium",children:k.name}),t.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground/50",children:["P:",k.priority]})]}),t.jsx("div",{className:"flex items-center gap-2",children:k.rules.map(N=>t.jsxs(Et,{variant:N.action==="allow"?"success":N.action==="deny"?"destructive":"warning",className:"text-[10px]",children:[N.action,N.tool?`: ${Array.isArray(N.tool)?N.tool.join(","):N.tool}`:""]},N.id))})]},k.id))})]})]})}function Gn(e,n){const r=String(e);if(typeof n!="string")throw new TypeError("Expected character");let s=0,i=r.indexOf(n);for(;i!==-1;)s++,i=r.indexOf(n,i+n.length);return s}function ci(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function ui(e,n,r){const i=ur((r||{}).ignore||[]),l=di(n);let a=-1;for(;++a<l.length;)hs(e,"text",c);function c(d,m){let f=-1,b;for(;++f<m.length;){const w=m[f],x=b?b.children:void 0;if(i(w,x?x.indexOf(w):void 0,b))return;b=w}if(b)return o(d,m)}function o(d,m){const f=m[m.length-1],b=l[a][0],w=l[a][1];let x=0;const N=f.children.indexOf(d);let v=!1,y=[];b.lastIndex=0;let R=b.exec(d.value);for(;R;){const L=R.index,_={index:R.index,input:R.input,stack:[...m,d]};let $=w(...R,_);if(typeof $=="string"&&($=$.length>0?{type:"text",value:$}:void 0),$===!1?b.lastIndex=L+1:(x!==L&&y.push({type:"text",value:d.value.slice(x,L)}),Array.isArray($)?y.push(...$):$&&y.push($),x=L+R[0].length,v=!0),!b.global)break;R=b.exec(d.value)}return v?(x<d.value.length&&y.push({type:"text",value:d.value.slice(x)}),f.children.splice(N,1,...y)):y=[d],N+y.length}}function di(e){const n=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const r=!e[0]||Array.isArray(e[0])?e:[e];let s=-1;for(;++s<r.length;){const i=r[s];n.push([mi(i[0]),fi(i[1])])}return n}function mi(e){return typeof e=="string"?new RegExp(ci(e),"g"):e}function fi(e){return typeof e=="function"?e:function(){return e}}const sn="phrasing",an=["autolink","link","image","label"];function hi(){return{transforms:[wi],enter:{literalAutolink:xi,literalAutolinkEmail:on,literalAutolinkHttp:on,literalAutolinkWww:on},exit:{literalAutolink:vi,literalAutolinkEmail:yi,literalAutolinkHttp:gi,literalAutolinkWww:bi}}}function pi(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:sn,notInConstruct:an},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:sn,notInConstruct:an},{character:":",before:"[ps]",after:"\\/",inConstruct:sn,notInConstruct:an}]}}function xi(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function on(e){this.config.enter.autolinkProtocol.call(this,e)}function gi(e){this.config.exit.autolinkProtocol.call(this,e)}function bi(e){this.config.exit.data.call(this,e);const n=this.stack[this.stack.length-1];gt(n.type==="link"),n.url="http://"+this.sliceSerialize(e)}function yi(e){this.config.exit.autolinkEmail.call(this,e)}function vi(e){this.exit(e)}function wi(e){ui(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,ki],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),ji]],{ignore:["link","linkReference"]})}function ki(e,n,r,s,i){let l="";if(!Sr(i)||(/^w/i.test(n)&&(r=n+r,n="",l="http://"),!Ni(r)))return!1;const a=Ci(r+s);if(!a[0])return!1;const c={type:"link",title:null,url:l+n+a[0],children:[{type:"text",value:n+a[0]}]};return a[1]?[c,{type:"text",value:a[1]}]:c}function ji(e,n,r,s){return!Sr(s,!0)||/[-\d_]$/.test(r)?!1:{type:"link",title:null,url:"mailto:"+n+"@"+r,children:[{type:"text",value:n+"@"+r}]}}function Ni(e){const n=e.split(".");return!(n.length<2||n[n.length-1]&&(/_/.test(n[n.length-1])||!/[a-zA-Z\d]/.test(n[n.length-1]))||n[n.length-2]&&(/_/.test(n[n.length-2])||!/[a-zA-Z\d]/.test(n[n.length-2])))}function Ci(e){const n=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!n)return[e,void 0];e=e.slice(0,n.index);let r=n[0],s=r.indexOf(")");const i=Gn(e,"(");let l=Gn(e,")");for(;s!==-1&&i>l;)e+=r.slice(0,s+1),r=r.slice(s+1),s=r.indexOf(")"),l++;return[e,r]}function Sr(e,n){const r=e.input.charCodeAt(e.index-1);return(e.index===0||pt(r)||wn(r))&&(!n||r!==47)}Er.peek=Li;function Si(){this.buffer()}function Ei(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function Ri(){this.buffer()}function Ti(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function Ai(e){const n=this.resume(),r=this.stack[this.stack.length-1];gt(r.type==="footnoteReference"),r.identifier=At(this.sliceSerialize(e)).toLowerCase(),r.label=n}function Mi(e){this.exit(e)}function Di(e){const n=this.resume(),r=this.stack[this.stack.length-1];gt(r.type==="footnoteDefinition"),r.identifier=At(this.sliceSerialize(e)).toLowerCase(),r.label=n}function Pi(e){this.exit(e)}function Li(){return"["}function Er(e,n,r,s){const i=r.createTracker(s);let l=i.move("[^");const a=r.enter("footnoteReference"),c=r.enter("reference");return l+=i.move(r.safe(r.associationId(e),{after:"]",before:l})),c(),a(),l+=i.move("]"),l}function _i(){return{enter:{gfmFootnoteCallString:Si,gfmFootnoteCall:Ei,gfmFootnoteDefinitionLabelString:Ri,gfmFootnoteDefinition:Ti},exit:{gfmFootnoteCallString:Ai,gfmFootnoteCall:Mi,gfmFootnoteDefinitionLabelString:Di,gfmFootnoteDefinition:Pi}}}function Fi(e){let n=!1;return e&&e.firstLineBlank&&(n=!0),{handlers:{footnoteDefinition:r,footnoteReference:Er},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function r(s,i,l,a){const c=l.createTracker(a);let o=c.move("[^");const d=l.enter("footnoteDefinition"),m=l.enter("label");return o+=c.move(l.safe(l.associationId(s),{before:o,after:"]"})),m(),o+=c.move("]:"),s.children&&s.children.length>0&&(c.shift(4),o+=c.move((n?`
|
|
138
|
+
`:" ")+l.indentLines(l.containerFlow(s,c.current()),n?Rr:zi))),d(),o}}function zi(e,n,r){return n===0?e:Rr(e,n,r)}function Rr(e,n,r){return(r?"":" ")+e}const $i=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];Tr.peek=Ui;function Ii(){return{canContainEols:["delete"],enter:{strikethrough:Bi},exit:{strikethrough:Hi}}}function Oi(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:$i}],handlers:{delete:Tr}}}function Bi(e){this.enter({type:"delete",children:[]},e)}function Hi(e){this.exit(e)}function Tr(e,n,r,s){const i=r.createTracker(s),l=r.enter("strikethrough");let a=i.move("~~");return a+=r.containerPhrasing(e,{...i.current(),before:a,after:"~"}),a+=i.move("~~"),l(),a}function Ui(){return"~"}function qi(e){return e.length}function Vi(e,n){const r=n||{},s=(r.align||[]).concat(),i=r.stringLength||qi,l=[],a=[],c=[],o=[];let d=0,m=-1;for(;++m<e.length;){const k=[],N=[];let v=-1;for(e[m].length>d&&(d=e[m].length);++v<e[m].length;){const y=Ki(e[m][v]);if(r.alignDelimiters!==!1){const R=i(y);N[v]=R,(o[v]===void 0||R>o[v])&&(o[v]=R)}k.push(y)}a[m]=k,c[m]=N}let f=-1;if(typeof s=="object"&&"length"in s)for(;++f<d;)l[f]=Wn(s[f]);else{const k=Wn(s);for(;++f<d;)l[f]=k}f=-1;const b=[],w=[];for(;++f<d;){const k=l[f];let N="",v="";k===99?(N=":",v=":"):k===108?N=":":k===114&&(v=":");let y=r.alignDelimiters===!1?1:Math.max(1,o[f]-N.length-v.length);const R=N+"-".repeat(y)+v;r.alignDelimiters!==!1&&(y=N.length+y+v.length,y>o[f]&&(o[f]=y),w[f]=y),b[f]=R}a.splice(1,0,b),c.splice(1,0,w),m=-1;const x=[];for(;++m<a.length;){const k=a[m],N=c[m];f=-1;const v=[];for(;++f<d;){const y=k[f]||"";let R="",L="";if(r.alignDelimiters!==!1){const _=o[f]-(N[f]||0),$=l[f];$===114?R=" ".repeat(_):$===99?_%2?(R=" ".repeat(_/2+.5),L=" ".repeat(_/2-.5)):(R=" ".repeat(_/2),L=R):L=" ".repeat(_)}r.delimiterStart!==!1&&!f&&v.push("|"),r.padding!==!1&&!(r.alignDelimiters===!1&&y==="")&&(r.delimiterStart!==!1||f)&&v.push(" "),r.alignDelimiters!==!1&&v.push(R),v.push(y),r.alignDelimiters!==!1&&v.push(L),r.padding!==!1&&v.push(" "),(r.delimiterEnd!==!1||f!==d-1)&&v.push("|")}x.push(r.delimiterEnd===!1?v.join("").replace(/ +$/,""):v.join(""))}return x.join(`
|
|
139
|
+
`)}function Ki(e){return e==null?"":String(e)}function Wn(e){const n=typeof e=="string"?e.codePointAt(0):0;return n===67||n===99?99:n===76||n===108?108:n===82||n===114?114:0}function Gi(e,n,r,s){const i=r.enter("blockquote"),l=r.createTracker(s);l.move("> "),l.shift(2);const a=r.indentLines(r.containerFlow(e,l.current()),Wi);return i(),a}function Wi(e,n,r){return">"+(r?"":" ")+e}function Qi(e,n){return Qn(e,n.inConstruct,!0)&&!Qn(e,n.notInConstruct,!1)}function Qn(e,n,r){if(typeof n=="string"&&(n=[n]),!n||n.length===0)return r;let s=-1;for(;++s<n.length;)if(e.includes(n[s]))return!0;return!1}function Yn(e,n,r,s){let i=-1;for(;++i<r.unsafe.length;)if(r.unsafe[i].character===`
|
|
140
|
+
`&&Qi(r.stack,r.unsafe[i]))return/[ \t]/.test(s.before)?"":" ";return`\\
|
|
141
|
+
`}function Yi(e,n){const r=String(e);let s=r.indexOf(n),i=s,l=0,a=0;if(typeof n!="string")throw new TypeError("Expected substring");for(;s!==-1;)s===i?++l>a&&(a=l):l=1,i=s+n.length,s=r.indexOf(n,i);return a}function Xi(e,n){return!!(n.options.fences===!1&&e.value&&!e.lang&&/[^ \r\n]/.test(e.value)&&!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(e.value))}function Ji(e){const n=e.options.fence||"`";if(n!=="`"&&n!=="~")throw new Error("Cannot serialize code with `"+n+"` for `options.fence`, expected `` ` `` or `~`");return n}function Zi(e,n,r,s){const i=Ji(r),l=e.value||"",a=i==="`"?"GraveAccent":"Tilde";if(Xi(e,r)){const f=r.enter("codeIndented"),b=r.indentLines(l,eo);return f(),b}const c=r.createTracker(s),o=i.repeat(Math.max(Yi(l,i)+1,3)),d=r.enter("codeFenced");let m=c.move(o);if(e.lang){const f=r.enter(`codeFencedLang${a}`);m+=c.move(r.safe(e.lang,{before:m,after:" ",encode:["`"],...c.current()})),f()}if(e.lang&&e.meta){const f=r.enter(`codeFencedMeta${a}`);m+=c.move(" "),m+=c.move(r.safe(e.meta,{before:m,after:`
|
|
142
|
+
`,encode:["`"],...c.current()})),f()}return m+=c.move(`
|
|
143
|
+
`),l&&(m+=c.move(l+`
|
|
144
|
+
`)),m+=c.move(o),d(),m}function eo(e,n,r){return(r?"":" ")+e}function Cn(e){const n=e.options.quote||'"';if(n!=='"'&&n!=="'")throw new Error("Cannot serialize title with `"+n+"` for `options.quote`, expected `\"`, or `'`");return n}function to(e,n,r,s){const i=Cn(r),l=i==='"'?"Quote":"Apostrophe",a=r.enter("definition");let c=r.enter("label");const o=r.createTracker(s);let d=o.move("[");return d+=o.move(r.safe(r.associationId(e),{before:d,after:"]",...o.current()})),d+=o.move("]: "),c(),!e.url||/[\0- \u007F]/.test(e.url)?(c=r.enter("destinationLiteral"),d+=o.move("<"),d+=o.move(r.safe(e.url,{before:d,after:">",...o.current()})),d+=o.move(">")):(c=r.enter("destinationRaw"),d+=o.move(r.safe(e.url,{before:d,after:e.title?" ":`
|
|
145
|
+
`,...o.current()}))),c(),e.title&&(c=r.enter(`title${l}`),d+=o.move(" "+i),d+=o.move(r.safe(e.title,{before:d,after:i,...o.current()})),d+=o.move(i),c()),a(),d}function no(e){const n=e.options.emphasis||"*";if(n!=="*"&&n!=="_")throw new Error("Cannot serialize emphasis with `"+n+"` for `options.emphasis`, expected `*`, or `_`");return n}function Tt(e){return"&#x"+e.toString(16).toUpperCase()+";"}function Kt(e,n,r){const s=Vt(e),i=Vt(n);return s===void 0?i===void 0?r==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:s===1?i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}Ar.peek=ro;function Ar(e,n,r,s){const i=no(r),l=r.enter("emphasis"),a=r.createTracker(s),c=a.move(i);let o=a.move(r.containerPhrasing(e,{after:i,before:c,...a.current()}));const d=o.charCodeAt(0),m=Kt(s.before.charCodeAt(s.before.length-1),d,i);m.inside&&(o=Tt(d)+o.slice(1));const f=o.charCodeAt(o.length-1),b=Kt(s.after.charCodeAt(0),f,i);b.inside&&(o=o.slice(0,-1)+Tt(f));const w=a.move(i);return l(),r.attentionEncodeSurroundingInfo={after:b.outside,before:m.outside},c+o+w}function ro(e,n,r){return r.options.emphasis||"*"}function so(e,n){let r=!1;return ps(e,function(s){if("value"in s&&/\r?\n|\r/.test(s.value)||s.type==="break")return r=!0,xs}),!!((!e.depth||e.depth<3)&&dr(e)&&(n.options.setext||r))}function ao(e,n,r,s){const i=Math.max(Math.min(6,e.depth||1),1),l=r.createTracker(s);if(so(e,r)){const m=r.enter("headingSetext"),f=r.enter("phrasing"),b=r.containerPhrasing(e,{...l.current(),before:`
|
|
146
|
+
`,after:`
|
|
147
|
+
`});return f(),m(),b+`
|
|
148
|
+
`+(i===1?"=":"-").repeat(b.length-(Math.max(b.lastIndexOf("\r"),b.lastIndexOf(`
|
|
149
|
+
`))+1))}const a="#".repeat(i),c=r.enter("headingAtx"),o=r.enter("phrasing");l.move(a+" ");let d=r.containerPhrasing(e,{before:"# ",after:`
|
|
150
|
+
`,...l.current()});return/^[\t ]/.test(d)&&(d=Tt(d.charCodeAt(0))+d.slice(1)),d=d?a+" "+d:a,r.options.closeAtx&&(d+=" "+a),o(),c(),d}Mr.peek=io;function Mr(e){return e.value||""}function io(){return"<"}Dr.peek=oo;function Dr(e,n,r,s){const i=Cn(r),l=i==='"'?"Quote":"Apostrophe",a=r.enter("image");let c=r.enter("label");const o=r.createTracker(s);let d=o.move("![");return d+=o.move(r.safe(e.alt,{before:d,after:"]",...o.current()})),d+=o.move("]("),c(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(c=r.enter("destinationLiteral"),d+=o.move("<"),d+=o.move(r.safe(e.url,{before:d,after:">",...o.current()})),d+=o.move(">")):(c=r.enter("destinationRaw"),d+=o.move(r.safe(e.url,{before:d,after:e.title?" ":")",...o.current()}))),c(),e.title&&(c=r.enter(`title${l}`),d+=o.move(" "+i),d+=o.move(r.safe(e.title,{before:d,after:i,...o.current()})),d+=o.move(i),c()),d+=o.move(")"),a(),d}function oo(){return"!"}Pr.peek=lo;function Pr(e,n,r,s){const i=e.referenceType,l=r.enter("imageReference");let a=r.enter("label");const c=r.createTracker(s);let o=c.move("![");const d=r.safe(e.alt,{before:o,after:"]",...c.current()});o+=c.move(d+"]["),a();const m=r.stack;r.stack=[],a=r.enter("reference");const f=r.safe(r.associationId(e),{before:o,after:"]",...c.current()});return a(),r.stack=m,l(),i==="full"||!d||d!==f?o+=c.move(f+"]"):i==="shortcut"?o=o.slice(0,-1):o+=c.move("]"),o}function lo(){return"!"}Lr.peek=co;function Lr(e,n,r){let s=e.value||"",i="`",l=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(s);)i+="`";for(/[^ \r\n]/.test(s)&&(/^[ \r\n]/.test(s)&&/[ \r\n]$/.test(s)||/^`|`$/.test(s))&&(s=" "+s+" ");++l<r.unsafe.length;){const a=r.unsafe[l],c=r.compilePattern(a);let o;if(a.atBreak)for(;o=c.exec(s);){let d=o.index;s.charCodeAt(d)===10&&s.charCodeAt(d-1)===13&&d--,s=s.slice(0,d)+" "+s.slice(o.index+1)}}return i+s+i}function co(){return"`"}function _r(e,n){const r=dr(e);return!!(!n.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(r===e.url||"mailto:"+r===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}Fr.peek=uo;function Fr(e,n,r,s){const i=Cn(r),l=i==='"'?"Quote":"Apostrophe",a=r.createTracker(s);let c,o;if(_r(e,r)){const m=r.stack;r.stack=[],c=r.enter("autolink");let f=a.move("<");return f+=a.move(r.containerPhrasing(e,{before:f,after:">",...a.current()})),f+=a.move(">"),c(),r.stack=m,f}c=r.enter("link"),o=r.enter("label");let d=a.move("[");return d+=a.move(r.containerPhrasing(e,{before:d,after:"](",...a.current()})),d+=a.move("]("),o(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(o=r.enter("destinationLiteral"),d+=a.move("<"),d+=a.move(r.safe(e.url,{before:d,after:">",...a.current()})),d+=a.move(">")):(o=r.enter("destinationRaw"),d+=a.move(r.safe(e.url,{before:d,after:e.title?" ":")",...a.current()}))),o(),e.title&&(o=r.enter(`title${l}`),d+=a.move(" "+i),d+=a.move(r.safe(e.title,{before:d,after:i,...a.current()})),d+=a.move(i),o()),d+=a.move(")"),c(),d}function uo(e,n,r){return _r(e,r)?"<":"["}zr.peek=mo;function zr(e,n,r,s){const i=e.referenceType,l=r.enter("linkReference");let a=r.enter("label");const c=r.createTracker(s);let o=c.move("[");const d=r.containerPhrasing(e,{before:o,after:"]",...c.current()});o+=c.move(d+"]["),a();const m=r.stack;r.stack=[],a=r.enter("reference");const f=r.safe(r.associationId(e),{before:o,after:"]",...c.current()});return a(),r.stack=m,l(),i==="full"||!d||d!==f?o+=c.move(f+"]"):i==="shortcut"?o=o.slice(0,-1):o+=c.move("]"),o}function mo(){return"["}function Sn(e){const n=e.options.bullet||"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bullet`, expected `*`, `+`, or `-`");return n}function fo(e){const n=Sn(e),r=e.options.bulletOther;if(!r)return n==="*"?"-":"*";if(r!=="*"&&r!=="+"&&r!=="-")throw new Error("Cannot serialize items with `"+r+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(r===n)throw new Error("Expected `bullet` (`"+n+"`) and `bulletOther` (`"+r+"`) to be different");return r}function ho(e){const n=e.options.bulletOrdered||".";if(n!=="."&&n!==")")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOrdered`, expected `.` or `)`");return n}function $r(e){const n=e.options.rule||"*";if(n!=="*"&&n!=="-"&&n!=="_")throw new Error("Cannot serialize rules with `"+n+"` for `options.rule`, expected `*`, `-`, or `_`");return n}function po(e,n,r,s){const i=r.enter("list"),l=r.bulletCurrent;let a=e.ordered?ho(r):Sn(r);const c=e.ordered?a==="."?")":".":fo(r);let o=n&&r.bulletLastUsed?a===r.bulletLastUsed:!1;if(!e.ordered){const m=e.children?e.children[0]:void 0;if((a==="*"||a==="-")&&m&&(!m.children||!m.children[0])&&r.stack[r.stack.length-1]==="list"&&r.stack[r.stack.length-2]==="listItem"&&r.stack[r.stack.length-3]==="list"&&r.stack[r.stack.length-4]==="listItem"&&r.indexStack[r.indexStack.length-1]===0&&r.indexStack[r.indexStack.length-2]===0&&r.indexStack[r.indexStack.length-3]===0&&(o=!0),$r(r)===a&&m){let f=-1;for(;++f<e.children.length;){const b=e.children[f];if(b&&b.type==="listItem"&&b.children&&b.children[0]&&b.children[0].type==="thematicBreak"){o=!0;break}}}}o&&(a=c),r.bulletCurrent=a;const d=r.containerFlow(e,s);return r.bulletLastUsed=a,r.bulletCurrent=l,i(),d}function xo(e){const n=e.options.listItemIndent||"one";if(n!=="tab"&&n!=="one"&&n!=="mixed")throw new Error("Cannot serialize items with `"+n+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return n}function go(e,n,r,s){const i=xo(r);let l=r.bulletCurrent||Sn(r);n&&n.type==="list"&&n.ordered&&(l=(typeof n.start=="number"&&n.start>-1?n.start:1)+(r.options.incrementListMarker===!1?0:n.children.indexOf(e))+l);let a=l.length+1;(i==="tab"||i==="mixed"&&(n&&n.type==="list"&&n.spread||e.spread))&&(a=Math.ceil(a/4)*4);const c=r.createTracker(s);c.move(l+" ".repeat(a-l.length)),c.shift(a);const o=r.enter("listItem"),d=r.indentLines(r.containerFlow(e,c.current()),m);return o(),d;function m(f,b,w){return b?(w?"":" ".repeat(a))+f:(w?l:l+" ".repeat(a-l.length))+f}}function bo(e,n,r,s){const i=r.enter("paragraph"),l=r.enter("phrasing"),a=r.containerPhrasing(e,s);return l(),i(),a}const yo=ur(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function vo(e,n,r,s){return(e.children.some(function(a){return yo(a)})?r.containerPhrasing:r.containerFlow).call(r,e,s)}function wo(e){const n=e.options.strong||"*";if(n!=="*"&&n!=="_")throw new Error("Cannot serialize strong with `"+n+"` for `options.strong`, expected `*`, or `_`");return n}Ir.peek=ko;function Ir(e,n,r,s){const i=wo(r),l=r.enter("strong"),a=r.createTracker(s),c=a.move(i+i);let o=a.move(r.containerPhrasing(e,{after:i,before:c,...a.current()}));const d=o.charCodeAt(0),m=Kt(s.before.charCodeAt(s.before.length-1),d,i);m.inside&&(o=Tt(d)+o.slice(1));const f=o.charCodeAt(o.length-1),b=Kt(s.after.charCodeAt(0),f,i);b.inside&&(o=o.slice(0,-1)+Tt(f));const w=a.move(i+i);return l(),r.attentionEncodeSurroundingInfo={after:b.outside,before:m.outside},c+o+w}function ko(e,n,r){return r.options.strong||"*"}function jo(e,n,r,s){return r.safe(e.value,s)}function No(e){const n=e.options.ruleRepetition||3;if(n<3)throw new Error("Cannot serialize rules with repetition `"+n+"` for `options.ruleRepetition`, expected `3` or more");return n}function Co(e,n,r){const s=($r(r)+(r.options.ruleSpaces?" ":"")).repeat(No(r));return r.options.ruleSpaces?s.slice(0,-1):s}const Or={blockquote:Gi,break:Yn,code:Zi,definition:to,emphasis:Ar,hardBreak:Yn,heading:ao,html:Mr,image:Dr,imageReference:Pr,inlineCode:Lr,link:Fr,linkReference:zr,list:po,listItem:go,paragraph:bo,root:vo,strong:Ir,text:jo,thematicBreak:Co};function So(){return{enter:{table:Eo,tableData:Xn,tableHeader:Xn,tableRow:To},exit:{codeText:Ao,table:Ro,tableData:ln,tableHeader:ln,tableRow:ln}}}function Eo(e){const n=e._align;this.enter({type:"table",align:n.map(function(r){return r==="none"?null:r}),children:[]},e),this.data.inTable=!0}function Ro(e){this.exit(e),this.data.inTable=void 0}function To(e){this.enter({type:"tableRow",children:[]},e)}function ln(e){this.exit(e)}function Xn(e){this.enter({type:"tableCell",children:[]},e)}function Ao(e){let n=this.resume();this.data.inTable&&(n=n.replace(/\\([\\|])/g,Mo));const r=this.stack[this.stack.length-1];gt(r.type==="inlineCode"),r.value=n,this.exit(e)}function Mo(e,n){return n==="|"?n:e}function Do(e){const n=e||{},r=n.tableCellPadding,s=n.tablePipeAlign,i=n.stringLength,l=r?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
|
|
151
|
+
`,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:b,table:a,tableCell:o,tableRow:c}};function a(w,x,k,N){return d(m(w,k,N),w.align)}function c(w,x,k,N){const v=f(w,k,N),y=d([v]);return y.slice(0,y.indexOf(`
|
|
152
|
+
`))}function o(w,x,k,N){const v=k.enter("tableCell"),y=k.enter("phrasing"),R=k.containerPhrasing(w,{...N,before:l,after:l});return y(),v(),R}function d(w,x){return Vi(w,{align:x,alignDelimiters:s,padding:r,stringLength:i})}function m(w,x,k){const N=w.children;let v=-1;const y=[],R=x.enter("table");for(;++v<N.length;)y[v]=f(N[v],x,k);return R(),y}function f(w,x,k){const N=w.children;let v=-1;const y=[],R=x.enter("tableRow");for(;++v<N.length;)y[v]=o(N[v],w,x,k);return R(),y}function b(w,x,k){let N=Or.inlineCode(w,x,k);return k.stack.includes("tableCell")&&(N=N.replace(/\|/g,"\\$&")),N}}function Po(){return{exit:{taskListCheckValueChecked:Jn,taskListCheckValueUnchecked:Jn,paragraph:_o}}}function Lo(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:Fo}}}function Jn(e){const n=this.stack[this.stack.length-2];gt(n.type==="listItem"),n.checked=e.type==="taskListCheckValueChecked"}function _o(e){const n=this.stack[this.stack.length-2];if(n&&n.type==="listItem"&&typeof n.checked=="boolean"){const r=this.stack[this.stack.length-1];gt(r.type==="paragraph");const s=r.children[0];if(s&&s.type==="text"){const i=n.children;let l=-1,a;for(;++l<i.length;){const c=i[l];if(c.type==="paragraph"){a=c;break}}a===r&&(s.value=s.value.slice(1),s.value.length===0?r.children.shift():r.position&&s.position&&typeof s.position.start.offset=="number"&&(s.position.start.column++,s.position.start.offset++,r.position.start=Object.assign({},s.position.start)))}}this.exit(e)}function Fo(e,n,r,s){const i=e.children[0],l=typeof e.checked=="boolean"&&i&&i.type==="paragraph",a="["+(e.checked?"x":" ")+"] ",c=r.createTracker(s);l&&c.move(a);let o=Or.listItem(e,n,r,{...s,...c.current()});return l&&(o=o.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,d)),o;function d(m){return m+a}}function zo(){return[hi(),_i(),Ii(),So(),Po()]}function $o(e){return{extensions:[pi(),Fi(e),Oi(),Do(e),Lo()]}}const Io={tokenize:Vo,partial:!0},Br={tokenize:Ko,partial:!0},Hr={tokenize:Go,partial:!0},Ur={tokenize:Wo,partial:!0},Oo={tokenize:Qo,partial:!0},qr={name:"wwwAutolink",tokenize:Uo,previous:Kr},Vr={name:"protocolAutolink",tokenize:qo,previous:Gr},$e={name:"emailAutolink",tokenize:Ho,previous:Wr},Le={};function Bo(){return{text:Le}}let Ze=48;for(;Ze<123;)Le[Ze]=$e,Ze++,Ze===58?Ze=65:Ze===91&&(Ze=97);Le[43]=$e;Le[45]=$e;Le[46]=$e;Le[95]=$e;Le[72]=[$e,Vr];Le[104]=[$e,Vr];Le[87]=[$e,qr];Le[119]=[$e,qr];function Ho(e,n,r){const s=this;let i,l;return a;function a(f){return!xn(f)||!Wr.call(s,s.previous)||En(s.events)?r(f):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),c(f))}function c(f){return xn(f)?(e.consume(f),c):f===64?(e.consume(f),o):r(f)}function o(f){return f===46?e.check(Oo,m,d)(f):f===45||f===95||kn(f)?(l=!0,e.consume(f),o):m(f)}function d(f){return e.consume(f),i=!0,o}function m(f){return l&&i&&Rt(s.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),n(f)):r(f)}}function Uo(e,n,r){const s=this;return i;function i(a){return a!==87&&a!==119||!Kr.call(s,s.previous)||En(s.events)?r(a):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(Io,e.attempt(Br,e.attempt(Hr,l),r),r)(a))}function l(a){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),n(a)}}function qo(e,n,r){const s=this;let i="",l=!1;return a;function a(f){return(f===72||f===104)&&Gr.call(s,s.previous)&&!En(s.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),e.consume(f),c):r(f)}function c(f){if(Rt(f)&&i.length<5)return i+=String.fromCodePoint(f),e.consume(f),c;if(f===58){const b=i.toLowerCase();if(b==="http"||b==="https")return e.consume(f),o}return r(f)}function o(f){return f===47?(e.consume(f),l?d:(l=!0,o)):r(f)}function d(f){return f===null||gs(f)||ke(f)||pt(f)||wn(f)?r(f):e.attempt(Br,e.attempt(Hr,m),r)(f)}function m(f){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),n(f)}}function Vo(e,n,r){let s=0;return i;function i(a){return(a===87||a===119)&&s<3?(s++,e.consume(a),i):a===46&&s===3?(e.consume(a),l):r(a)}function l(a){return a===null?r(a):n(a)}}function Ko(e,n,r){let s,i,l;return a;function a(d){return d===46||d===95?e.check(Ur,o,c)(d):d===null||ke(d)||pt(d)||d!==45&&wn(d)?o(d):(l=!0,e.consume(d),a)}function c(d){return d===95?s=!0:(i=s,s=void 0),e.consume(d),a}function o(d){return i||s||!l?r(d):n(d)}}function Go(e,n){let r=0,s=0;return i;function i(a){return a===40?(r++,e.consume(a),i):a===41&&s<r?l(a):a===33||a===34||a===38||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===60||a===63||a===93||a===95||a===126?e.check(Ur,n,l)(a):a===null||ke(a)||pt(a)?n(a):(e.consume(a),i)}function l(a){return a===41&&s++,e.consume(a),i}}function Wo(e,n,r){return s;function s(c){return c===33||c===34||c===39||c===41||c===42||c===44||c===46||c===58||c===59||c===63||c===95||c===126?(e.consume(c),s):c===38?(e.consume(c),l):c===93?(e.consume(c),i):c===60||c===null||ke(c)||pt(c)?n(c):r(c)}function i(c){return c===null||c===40||c===91||ke(c)||pt(c)?n(c):s(c)}function l(c){return Rt(c)?a(c):r(c)}function a(c){return c===59?(e.consume(c),s):Rt(c)?(e.consume(c),a):r(c)}}function Qo(e,n,r){return s;function s(l){return e.consume(l),i}function i(l){return kn(l)?r(l):n(l)}}function Kr(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||ke(e)}function Gr(e){return!Rt(e)}function Wr(e){return!(e===47||xn(e))}function xn(e){return e===43||e===45||e===46||e===95||kn(e)}function En(e){let n=e.length,r=!1;for(;n--;){const s=e[n][1];if((s.type==="labelLink"||s.type==="labelImage")&&!s._balanced){r=!0;break}if(s._gfmAutolinkLiteralWalkedInto){r=!1;break}}return e.length>0&&!r&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),r}const Yo={tokenize:sl,partial:!0};function Xo(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:tl,continuation:{tokenize:nl},exit:rl}},text:{91:{name:"gfmFootnoteCall",tokenize:el},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Jo,resolveTo:Zo}}}}function Jo(e,n,r){const s=this;let i=s.events.length;const l=s.parser.gfmFootnotes||(s.parser.gfmFootnotes=[]);let a;for(;i--;){const o=s.events[i][1];if(o.type==="labelImage"){a=o;break}if(o.type==="gfmFootnoteCall"||o.type==="labelLink"||o.type==="label"||o.type==="image"||o.type==="link")break}return c;function c(o){if(!a||!a._balanced)return r(o);const d=At(s.sliceSerialize({start:a.end,end:s.now()}));return d.codePointAt(0)!==94||!l.includes(d.slice(1))?r(o):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(o),e.exit("gfmFootnoteCallLabelMarker"),n(o))}}function Zo(e,n){let r=e.length;for(;r--;)if(e[r][1].type==="labelImage"&&e[r][0]==="enter"){e[r][1];break}e[r+1][1].type="data",e[r+3][1].type="gfmFootnoteCallLabelMarker";const s={type:"gfmFootnoteCall",start:Object.assign({},e[r+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[r+3][1].end),end:Object.assign({},e[r+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const l={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},a={type:"chunkString",contentType:"string",start:Object.assign({},l.start),end:Object.assign({},l.end)},c=[e[r+1],e[r+2],["enter",s,n],e[r+3],e[r+4],["enter",i,n],["exit",i,n],["enter",l,n],["enter",a,n],["exit",a,n],["exit",l,n],e[e.length-2],e[e.length-1],["exit",s,n]];return e.splice(r,e.length-r+1,...c),e}function el(e,n,r){const s=this,i=s.parser.gfmFootnotes||(s.parser.gfmFootnotes=[]);let l=0,a;return c;function c(f){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),o}function o(f){return f!==94?r(f):(e.enter("gfmFootnoteCallMarker"),e.consume(f),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",d)}function d(f){if(l>999||f===93&&!a||f===null||f===91||ke(f))return r(f);if(f===93){e.exit("chunkString");const b=e.exit("gfmFootnoteCallString");return i.includes(At(s.sliceSerialize(b)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),n):r(f)}return ke(f)||(a=!0),l++,e.consume(f),f===92?m:d}function m(f){return f===91||f===92||f===93?(e.consume(f),l++,d):d(f)}}function tl(e,n,r){const s=this,i=s.parser.gfmFootnotes||(s.parser.gfmFootnotes=[]);let l,a=0,c;return o;function o(x){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(x),e.exit("gfmFootnoteDefinitionLabelMarker"),d}function d(x){return x===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(x),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",m):r(x)}function m(x){if(a>999||x===93&&!c||x===null||x===91||ke(x))return r(x);if(x===93){e.exit("chunkString");const k=e.exit("gfmFootnoteDefinitionLabelString");return l=At(s.sliceSerialize(k)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(x),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),b}return ke(x)||(c=!0),a++,e.consume(x),x===92?f:m}function f(x){return x===91||x===92||x===93?(e.consume(x),a++,m):m(x)}function b(x){return x===58?(e.enter("definitionMarker"),e.consume(x),e.exit("definitionMarker"),i.includes(l)||i.push(l),We(e,w,"gfmFootnoteDefinitionWhitespace")):r(x)}function w(x){return n(x)}}function nl(e,n,r){return e.check(bs,n,e.attempt(Yo,n,r))}function rl(e){e.exit("gfmFootnoteDefinition")}function sl(e,n,r){const s=this;return We(e,i,"gfmFootnoteDefinitionIndent",5);function i(l){const a=s.events[s.events.length-1];return a&&a[1].type==="gfmFootnoteDefinitionIndent"&&a[2].sliceSerialize(a[1],!0).length===4?n(l):r(l)}}function al(e){let r=(e||{}).singleTilde;const s={name:"strikethrough",tokenize:l,resolveAll:i};return r==null&&(r=!0),{text:{126:s},insideSpan:{null:[s]},attentionMarkers:{null:[126]}};function i(a,c){let o=-1;for(;++o<a.length;)if(a[o][0]==="enter"&&a[o][1].type==="strikethroughSequenceTemporary"&&a[o][1]._close){let d=o;for(;d--;)if(a[d][0]==="exit"&&a[d][1].type==="strikethroughSequenceTemporary"&&a[d][1]._open&&a[o][1].end.offset-a[o][1].start.offset===a[d][1].end.offset-a[d][1].start.offset){a[o][1].type="strikethroughSequence",a[d][1].type="strikethroughSequence";const m={type:"strikethrough",start:Object.assign({},a[d][1].start),end:Object.assign({},a[o][1].end)},f={type:"strikethroughText",start:Object.assign({},a[d][1].end),end:Object.assign({},a[o][1].start)},b=[["enter",m,c],["enter",a[d][1],c],["exit",a[d][1],c],["enter",f,c]],w=c.parser.constructs.insideSpan.null;w&&Zt(b,b.length,0,ys(w,a.slice(d+1,o),c)),Zt(b,b.length,0,[["exit",f,c],["enter",a[o][1],c],["exit",a[o][1],c],["exit",m,c]]),Zt(a,d-1,o-d+3,b),o=d+b.length-2;break}}for(o=-1;++o<a.length;)a[o][1].type==="strikethroughSequenceTemporary"&&(a[o][1].type="data");return a}function l(a,c,o){const d=this.previous,m=this.events;let f=0;return b;function b(x){return d===126&&m[m.length-1][1].type!=="characterEscape"?o(x):(a.enter("strikethroughSequenceTemporary"),w(x))}function w(x){const k=Vt(d);if(x===126)return f>1?o(x):(a.consume(x),f++,w);if(f<2&&!r)return o(x);const N=a.exit("strikethroughSequenceTemporary"),v=Vt(x);return N._open=!v||v===2&&!!k,N._close=!k||k===2&&!!v,c(x)}}}class il{constructor(){this.map=[]}add(n,r,s){ol(this,n,r,s)}consume(n){if(this.map.sort(function(l,a){return l[0]-a[0]}),this.map.length===0)return;let r=this.map.length;const s=[];for(;r>0;)r-=1,s.push(n.slice(this.map[r][0]+this.map[r][1]),this.map[r][2]),n.length=this.map[r][0];s.push(n.slice()),n.length=0;let i=s.pop();for(;i;){for(const l of i)n.push(l);i=s.pop()}this.map.length=0}}function ol(e,n,r,s){let i=0;if(!(r===0&&s.length===0)){for(;i<e.map.length;){if(e.map[i][0]===n){e.map[i][1]+=r,e.map[i][2].push(...s);return}i+=1}e.map.push([n,r,s])}}function ll(e,n){let r=!1;const s=[];for(;n<e.length;){const i=e[n];if(r){if(i[0]==="enter")i[1].type==="tableContent"&&s.push(e[n+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[n-1][1].type==="tableDelimiterMarker"){const l=s.length-1;s[l]=s[l]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(r=!0);n+=1}return s}function cl(){return{flow:{null:{name:"table",tokenize:ul,resolveAll:dl}}}}function ul(e,n,r){const s=this;let i=0,l=0,a;return c;function c(g){let ne=s.events.length-1;for(;ne>-1;){const fe=s.events[ne][1].type;if(fe==="lineEnding"||fe==="linePrefix")ne--;else break}const re=ne>-1?s.events[ne][1].type:null,ye=re==="tableHead"||re==="tableRow"?$:o;return ye===$&&s.parser.lazy[s.now().line]?r(g):ye(g)}function o(g){return e.enter("tableHead"),e.enter("tableRow"),d(g)}function d(g){return g===124||(a=!0,l+=1),m(g)}function m(g){return g===null?r(g):St(g)?l>1?(l=0,s.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(g),e.exit("lineEnding"),w):r(g):ft(g)?We(e,m,"whitespace")(g):(l+=1,a&&(a=!1,i+=1),g===124?(e.enter("tableCellDivider"),e.consume(g),e.exit("tableCellDivider"),a=!0,m):(e.enter("data"),f(g)))}function f(g){return g===null||g===124||ke(g)?(e.exit("data"),m(g)):(e.consume(g),g===92?b:f)}function b(g){return g===92||g===124?(e.consume(g),f):f(g)}function w(g){return s.interrupt=!1,s.parser.lazy[s.now().line]?r(g):(e.enter("tableDelimiterRow"),a=!1,ft(g)?We(e,x,"linePrefix",s.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(g):x(g))}function x(g){return g===45||g===58?N(g):g===124?(a=!0,e.enter("tableCellDivider"),e.consume(g),e.exit("tableCellDivider"),k):_(g)}function k(g){return ft(g)?We(e,N,"whitespace")(g):N(g)}function N(g){return g===58?(l+=1,a=!0,e.enter("tableDelimiterMarker"),e.consume(g),e.exit("tableDelimiterMarker"),v):g===45?(l+=1,v(g)):g===null||St(g)?L(g):_(g)}function v(g){return g===45?(e.enter("tableDelimiterFiller"),y(g)):_(g)}function y(g){return g===45?(e.consume(g),y):g===58?(a=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(g),e.exit("tableDelimiterMarker"),R):(e.exit("tableDelimiterFiller"),R(g))}function R(g){return ft(g)?We(e,L,"whitespace")(g):L(g)}function L(g){return g===124?x(g):g===null||St(g)?!a||i!==l?_(g):(e.exit("tableDelimiterRow"),e.exit("tableHead"),n(g)):_(g)}function _(g){return r(g)}function $(g){return e.enter("tableRow"),Q(g)}function Q(g){return g===124?(e.enter("tableCellDivider"),e.consume(g),e.exit("tableCellDivider"),Q):g===null||St(g)?(e.exit("tableRow"),n(g)):ft(g)?We(e,Q,"whitespace")(g):(e.enter("data"),X(g))}function X(g){return g===null||g===124||ke(g)?(e.exit("data"),Q(g)):(e.consume(g),g===92?de:X)}function de(g){return g===92||g===124?(e.consume(g),X):X(g)}}function dl(e,n){let r=-1,s=!0,i=0,l=[0,0,0,0],a=[0,0,0,0],c=!1,o=0,d,m,f;const b=new il;for(;++r<e.length;){const w=e[r],x=w[1];w[0]==="enter"?x.type==="tableHead"?(c=!1,o!==0&&(Zn(b,n,o,d,m),m=void 0,o=0),d={type:"table",start:Object.assign({},x.start),end:Object.assign({},x.end)},b.add(r,0,[["enter",d,n]])):x.type==="tableRow"||x.type==="tableDelimiterRow"?(s=!0,f=void 0,l=[0,0,0,0],a=[0,r+1,0,0],c&&(c=!1,m={type:"tableBody",start:Object.assign({},x.start),end:Object.assign({},x.end)},b.add(r,0,[["enter",m,n]])),i=x.type==="tableDelimiterRow"?2:m?3:1):i&&(x.type==="data"||x.type==="tableDelimiterMarker"||x.type==="tableDelimiterFiller")?(s=!1,a[2]===0&&(l[1]!==0&&(a[0]=a[1],f=Ht(b,n,l,i,void 0,f),l=[0,0,0,0]),a[2]=r)):x.type==="tableCellDivider"&&(s?s=!1:(l[1]!==0&&(a[0]=a[1],f=Ht(b,n,l,i,void 0,f)),l=a,a=[l[1],r,0,0])):x.type==="tableHead"?(c=!0,o=r):x.type==="tableRow"||x.type==="tableDelimiterRow"?(o=r,l[1]!==0?(a[0]=a[1],f=Ht(b,n,l,i,r,f)):a[1]!==0&&(f=Ht(b,n,a,i,r,f)),i=0):i&&(x.type==="data"||x.type==="tableDelimiterMarker"||x.type==="tableDelimiterFiller")&&(a[3]=r)}for(o!==0&&Zn(b,n,o,d,m),b.consume(n.events),r=-1;++r<n.events.length;){const w=n.events[r];w[0]==="enter"&&w[1].type==="table"&&(w[1]._align=ll(n.events,r))}return e}function Ht(e,n,r,s,i,l){const a=s===1?"tableHeader":s===2?"tableDelimiter":"tableData",c="tableContent";r[0]!==0&&(l.end=Object.assign({},ht(n.events,r[0])),e.add(r[0],0,[["exit",l,n]]));const o=ht(n.events,r[1]);if(l={type:a,start:Object.assign({},o),end:Object.assign({},o)},e.add(r[1],0,[["enter",l,n]]),r[2]!==0){const d=ht(n.events,r[2]),m=ht(n.events,r[3]),f={type:c,start:Object.assign({},d),end:Object.assign({},m)};if(e.add(r[2],0,[["enter",f,n]]),s!==2){const b=n.events[r[2]],w=n.events[r[3]];if(b[1].end=Object.assign({},w[1].end),b[1].type="chunkText",b[1].contentType="text",r[3]>r[2]+1){const x=r[2]+1,k=r[3]-r[2]-1;e.add(x,k,[])}}e.add(r[3]+1,0,[["exit",f,n]])}return i!==void 0&&(l.end=Object.assign({},ht(n.events,i)),e.add(i,0,[["exit",l,n]]),l=void 0),l}function Zn(e,n,r,s,i){const l=[],a=ht(n.events,r);i&&(i.end=Object.assign({},a),l.push(["exit",i,n])),s.end=Object.assign({},a),l.push(["exit",s,n]),e.add(r+1,0,l)}function ht(e,n){const r=e[n],s=r[0]==="enter"?"start":"end";return r[1][s]}const ml={name:"tasklistCheck",tokenize:hl};function fl(){return{text:{91:ml}}}function hl(e,n,r){const s=this;return i;function i(o){return s.previous!==null||!s._gfmTasklistFirstContentOfListItem?r(o):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(o),e.exit("taskListCheckMarker"),l)}function l(o){return ke(o)?(e.enter("taskListCheckValueUnchecked"),e.consume(o),e.exit("taskListCheckValueUnchecked"),a):o===88||o===120?(e.enter("taskListCheckValueChecked"),e.consume(o),e.exit("taskListCheckValueChecked"),a):r(o)}function a(o){return o===93?(e.enter("taskListCheckMarker"),e.consume(o),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),c):r(o)}function c(o){return St(o)?n(o):ft(o)?e.check({tokenize:pl},n,r)(o):r(o)}}function pl(e,n,r){return We(e,s,"whitespace");function s(i){return i===null?r(i):n(i)}}function xl(e){return vs([Bo(),Xo(),al(e),cl(),fl()])}const gl={};function bl(e){const n=this,r=e||gl,s=n.data(),i=s.micromarkExtensions||(s.micromarkExtensions=[]),l=s.fromMarkdownExtensions||(s.fromMarkdownExtensions=[]),a=s.toMarkdownExtensions||(s.toMarkdownExtensions=[]);i.push(xl(r)),l.push(zo()),a.push($o(r))}function yl({text:e}){const[n,r]=u.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),2e3)})};return t.jsx("button",{type:"button",onClick:s,className:"absolute top-2 right-2 px-2 py-1 rounded text-[10px] font-mono opacity-0 group-hover/code:opacity-100 transition-opacity bg-white/5 hover:bg-white/10 text-muted-foreground/70 hover:text-foreground border border-white/5",children:n?"Copied!":"Copy"})}const vl={h1:({children:e})=>t.jsx("h1",{className:"text-lg font-bold text-foreground mt-5 mb-3 pb-2 border-b border-border/40 first:mt-0",children:e}),h2:({children:e})=>t.jsx("h2",{className:"text-base font-semibold text-foreground mt-5 mb-2 pb-1.5 border-b border-border/30 first:mt-0",children:e}),h3:({children:e})=>t.jsx("h3",{className:"text-sm font-semibold text-foreground mt-4 mb-2 first:mt-0",children:e}),h4:({children:e})=>t.jsx("h4",{className:"text-sm font-medium text-foreground/90 mt-3 mb-1.5 first:mt-0",children:e}),p:({children:e})=>t.jsx("p",{className:"text-sm leading-relaxed text-foreground/90 mb-3 last:mb-0",children:e}),strong:({children:e})=>t.jsx("strong",{className:"font-semibold text-foreground",children:e}),em:({children:e})=>t.jsx("em",{className:"italic text-foreground/80",children:e}),code:({children:e,className:n})=>{if(n==null?void 0:n.includes("language-")){const s=(n==null?void 0:n.replace("language-",""))||"",i=String(e).replace(/\n$/,"");return t.jsxs("div",{className:"group/code relative",children:[s&&t.jsx("div",{className:"absolute top-0 left-0 px-2.5 py-1 text-[10px] font-mono text-muted-foreground/50 uppercase tracking-wider",children:s}),t.jsx(yl,{text:i}),t.jsx("pre",{className:"overflow-x-auto text-[13px] leading-relaxed p-3 pt-7",children:t.jsx("code",{children:i})})]})}return t.jsx("code",{className:"px-1.5 py-0.5 rounded bg-cyan-500/[0.08] text-cyan-300 text-[13px] font-mono border border-cyan-500/10",children:e})},pre:({children:e})=>t.jsx("pre",{className:"my-3 rounded-lg bg-[#0e1016] border border-border/40 overflow-hidden font-mono text-foreground/90",children:e}),a:({href:e,children:n})=>t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-cyan-400 hover:text-cyan-300 underline underline-offset-2 decoration-cyan-400/30 hover:decoration-cyan-300/50 transition-colors",children:n}),ul:({children:e})=>t.jsx("ul",{className:"my-2 ml-1 space-y-1.5 text-sm list-disc list-outside pl-5 marker:text-cyan-500/60",children:e}),ol:({children:e})=>t.jsx("ol",{className:"my-2 ml-1 space-y-1.5 text-sm list-decimal list-outside pl-5 marker:text-muted-foreground/50",children:e}),li:({children:e})=>t.jsx("li",{className:"text-foreground/90 leading-relaxed",children:e}),blockquote:({children:e})=>t.jsx("blockquote",{className:"my-3 pl-4 border-l-2 border-violet-500/30 text-foreground/70 italic",children:e}),hr:()=>t.jsx("hr",{className:"my-4 border-t border-border/40"}),table:({children:e})=>t.jsx("div",{className:"my-3 overflow-x-auto rounded-lg border border-border/40",children:t.jsx("table",{className:"w-full text-sm",children:e})}),thead:({children:e})=>t.jsx("thead",{className:"bg-muted/30 border-b border-border/40",children:e}),tbody:({children:e})=>t.jsx("tbody",{className:"divide-y divide-border/20",children:e}),tr:({children:e})=>t.jsx("tr",{className:"hover:bg-muted/20 transition-colors",children:e}),th:({children:e})=>t.jsx("th",{className:"px-3 py-2 text-left text-xs font-semibold text-foreground/70 uppercase tracking-wider",children:e}),td:({children:e})=>t.jsx("td",{className:"px-3 py-2 text-foreground/80",children:e}),img:({src:e,alt:n})=>t.jsx("img",{src:e,alt:n||"",className:"my-3 max-w-full rounded-lg border border-border/20"}),del:({children:e})=>t.jsx("del",{className:"text-muted-foreground/50 line-through",children:e})},wl=u.memo(function({content:n}){return n?t.jsx("div",{className:"markdown-content",children:t.jsx(ws,{remarkPlugins:[bl],components:vl,children:n})}):null});function kl(e,n){if(e===void 0)return n;const r=e.trim().toLowerCase();return["0","false","off","no","disable","disabled"].includes(r)?!1:["1","true","on","yes","enable","enabled"].includes(r)?!0:n}function jl(e){if(!e)return;const n=e.trim().toLowerCase();if(["1","true","on","yes","enable","enabled"].includes(n))return!0;if(["0","false","off","no","disable","disabled"].includes(n))return!1}function Nl(e){if(!(typeof window>"u"))try{return jl(window.localStorage.getItem(e))}catch{return}}function cn(e){const n=Nl(e.localStorageKey);if(n!==void 0)return{enabled:n,source:"local_override"};const r=e.enabledEnv===void 0?"default":"env";return{enabled:kl(e.enabledEnv,e.defaultEnabled),source:r}}function Cl(e,n){const r=cn({enabledEnv:void 0,defaultEnabled:(n==null?void 0:n.wsPtyPasteEnabled)??!0,localStorageKey:"codepiper:feature:ws_pty_paste"}),s=cn({enabledEnv:void 0,defaultEnabled:(n==null?void 0:n.latencyProbesEnabled)??!0,localStorageKey:"codepiper:feature:terminal_latency_probes"}),i=cn({enabledEnv:void 0,defaultEnabled:(n==null?void 0:n.diagnosticsPanelEnabled)??!1,localStorageKey:"codepiper:feature:terminal_diagnostics"});return{sessionId:e,wsPtyPaste:r,latencyProbes:s,diagnosticsPanel:i}}const Qr="image/png,image/jpeg,image/gif,image/webp",Sl=10*1024*1024,gn=5,bn=12,El=new Set(["image/png","image/jpeg","image/gif","image/webp"]);function Yr(e){return El.has(e.type)?e.size>Sl?`Image too large (${(e.size/1024/1024).toFixed(1)}MB, max 10MB)`:null:"Invalid image type. Allowed: PNG, JPEG, GIF, WebP"}function Rl(e,n){const r=Number.isFinite(n)&&n>0?Math.floor(n):0,s=Math.max(0,bn-r),i=e.slice(0,s),l=i.slice(0,gn);return{accepted:l,droppedByQueueLimit:Math.max(0,e.length-s),droppedByBatchLimit:Math.max(0,i.length-l.length)}}function un(e){return e?Array.from(e.items??[]).some(n=>n.kind==="file")?!0:Array.from(e.types??[]).includes("Files"):!1}function er(e){if(!e)return[];const n=new Map,r=s=>{const i=`${s.name}:${s.type}:${s.size}:${s.lastModified}`;n.has(i)||n.set(i,s)};for(const s of Array.from(e.files??[]))s.type.startsWith("image/")&&r(s);for(const s of Array.from(e.items??[])){if(!s.type.startsWith("image/"))continue;const i=s.getAsFile();i&&r(i)}return Array.from(n.values())}function Xr(){return typeof window<"u"&&typeof navigator<"u"&&!!(navigator.clipboard&&typeof navigator.clipboard.read=="function")}async function Tl(){if(!Xr())return null;const e=await navigator.clipboard.read();for(const n of e){const r=n.types.find(l=>l.startsWith("image/"));if(!r)continue;const s=await n.getType(r),i=r.split("/")[1]||"png";return new File([s],`clipboard-${Date.now()}.${i}`,{type:r,lastModified:Date.now()})}return null}function Al(e){if(typeof e!="object"||e===null||!("status"in e))return null;const n=e.status;return typeof n=="number"&&Number.isFinite(n)?n:null}function Ml(e){return e instanceof Error?e.message.trim():typeof e=="string"?e.trim():""}function Dl(e){const n=Al(e),r=Ml(e).slice(0,140),s=r.toLowerCase();return n===413||s.includes("too large")||s.includes("payload too large")||s.includes("max 10mb")?"Image rejected: file is too large (max 10MB).":n===415||s.includes("invalid image type")||s.includes("unsupported image")?"Image rejected: unsupported format (PNG, JPEG, GIF, WebP only).":n===401||n===403?"Upload blocked by daemon auth. Refresh and try again.":n!==null&&n>=500?`Daemon upload failed (HTTP ${n}).`:n!==null&&n>0?r||`Upload failed (HTTP ${n}).`:r||"Unknown upload error."}const tr=5,Pl=50;function nr(){if(typeof window>"u")return null;const e=window.SpeechRecognition;return e||(window.webkitSpeechRecognition??null)}function Ll(){var e;return typeof window>"u"?!1:typeof MediaRecorder<"u"&&!!((e=navigator.mediaDevices)!=null&&e.getUserMedia)}function _l(){if(typeof window>"u"||typeof MediaRecorder>"u")return;const e=["audio/webm;codecs=opus","audio/webm","audio/ogg;codecs=opus","audio/ogg","audio/mp4"];for(const n of e)if(MediaRecorder.isTypeSupported(n))return n}function Fl({sessionId:e,isEnded:n}){const r=`codepiper:input:${e}`,[s,i]=u.useState(()=>{try{return sessionStorage.getItem(r)??""}catch{return""}}),[l,a]=u.useState(!1),[c,o]=u.useState(null),[d,m]=u.useState(null),[f,b]=u.useState(null),[w,x]=u.useState(!1),[k,N]=u.useState(!1),[v,y]=u.useState(!1),[R,L]=u.useState(!1),_=u.useRef(null),$=u.useRef(null),Q=u.useRef(null),X=u.useRef(null),de=u.useRef(null),g=u.useRef([]),ne=u.useRef([]),re=u.useRef(-1),ye=u.useRef("");u.useEffect(()=>{try{s?sessionStorage.setItem(r,s):sessionStorage.removeItem(r)}catch{}},[s,r]),u.useEffect(()=>{const C=_.current;C&&C.value.length>0&&(C.selectionStart=C.value.length,C.selectionEnd=C.value.length)},[]);const fe=u.useCallback(()=>{const C=_.current;if(!C)return;C.style.height="auto";const O=(parseFloat(getComputedStyle(C).lineHeight)||20)*tr;C.style.height=`${Math.min(C.scrollHeight,O)}px`},[]),Me=s.includes(`
|
|
153
|
+
`);u.useLayoutEffect(()=>{fe()},[s,fe]);const ge=u.useCallback(C=>{const S=Yr(C);if(S){o(S);return}f&&URL.revokeObjectURL(f),m(C),b(URL.createObjectURL(C))},[f]),me=u.useCallback(()=>{f&&URL.revokeObjectURL(f),m(null),b(null)},[f]),je=u.useRef(f);je.current=f,u.useEffect(()=>()=>{je.current&&URL.revokeObjectURL(je.current)},[]),u.useEffect(()=>{x(!!nr()),N(Ll())},[]);const se=u.useCallback(C=>{const S=C.trim();S&&i(O=>`${O.trim().length>0?`${O} `:O}${S}`)},[]),B=u.useCallback(()=>{if(g.current=[],de.current){for(const C of de.current.getTracks())try{C.stop()}catch{}de.current=null}X.current=null},[]);u.useEffect(()=>()=>{if(Q.current)try{Q.current.stop()}catch{}B()},[B]);const Ee=u.useCallback(()=>{var S,O;if(l||n||R)return;if(v){try{(S=Q.current)==null||S.stop(),((O=X.current)==null?void 0:O.state)==="recording"?X.current.stop():B()}finally{y(!1)}return}const C=nr();if(C){if(!Q.current){const I=new C;I.lang=navigator.language||"en-US",I.continuous=!1,I.interimResults=!0,I.maxAlternatives=1,I.onresult=W=>{var ie,J;const te=[];for(let ve=W.resultIndex;ve<W.results.length;ve++){const xe=W.results[ve];if(xe!=null&&xe.isFinal){const oe=(J=(ie=xe[0])==null?void 0:ie.transcript)==null?void 0:J.trim();oe&&te.push(oe)}}te.length>0&&se(te.join(" "))},I.onerror=W=>{const te=W.error??"unknown";o(`Voice input failed (${te}).`),y(!1)},I.onend=()=>{y(!1)},Q.current=I}try{o(null),Q.current.start(),y(!0)}catch(I){y(!1),o(I instanceof Error?I.message:"Unable to start voice input")}return}if(!k){x(!1),o("Voice input is not supported on this browser.");return}(async()=>{try{o(null);const I=await navigator.mediaDevices.getUserMedia({audio:!0});de.current=I,g.current=[];const W=_l(),te=W?new MediaRecorder(I,{mimeType:W}):new MediaRecorder(I);te.ondataavailable=ie=>{ie.data.size>0&&g.current.push(ie.data)},te.onerror=()=>{o("Voice recording failed."),y(!1)},te.onstop=()=>{const ie=[...g.current];if(B(),y(!1),ie.length===0)return;const J=te.mimeType||W||"audio/webm",ve=new Blob(ie,{type:J}),xe=J.includes("ogg")?"ogg":J.includes("mp4")?"m4a":"webm";L(!0),A.transcribeAudio(e,ve,`voice-input.${xe}`).then(({transcript:oe})=>{se(oe)}).catch(oe=>{o(oe instanceof Error?oe.message:"Voice transcription failed")}).finally(()=>{L(!1)})},X.current=te,te.start(250),y(!0)}catch(I){B(),y(!1),o(I instanceof Error?I.message:"Unable to start voice recording")}})()},[se,n,B,l,e,k,v,R]),V=u.useCallback(async()=>{var O;const C=s.trim().length>0;if(!(!(C||d!==null)||l||n))try{a(!0),o(null);let I=s;if(d){const{path:W}=await A.uploadImage(e,d);I=C?`${s}
|
|
154
|
+
|
|
155
|
+
${W}`:W,me()}await A.sendText(e,{text:I,newline:!0}),C&&(ne.current.push(s),ne.current.length>Pl&&ne.current.shift()),re.current=-1,ye.current="",i("");try{sessionStorage.removeItem(r)}catch{}(O=_.current)==null||O.focus()}catch(I){console.error("Failed to send:",I),o(I instanceof Error?I.message:"Failed to send")}finally{a(!1)}},[s,d,l,n,e,me,r]);u.useEffect(()=>{d&&!l&&V()},[d]);const Re=u.useCallback(()=>{const C=_.current;return C?!C.value.substring(0,C.selectionStart).includes(`
|
|
156
|
+
`):!0},[]),ee=u.useCallback(()=>{const C=_.current;return C?!C.value.substring(C.selectionStart).includes(`
|
|
157
|
+
`):!0},[]),D=u.useCallback(C=>{if(C.key==="Enter"&&!C.shiftKey){C.preventDefault(),V();return}if(C.key==="Escape"){s&&(C.preventDefault(),i(""),re.current=-1,ye.current="");return}if(C.key==="ArrowUp"&&(s===""||Re())){const S=ne.current;if(S.length===0)return;C.preventDefault(),re.current===-1&&(ye.current=s);const O=Math.min(re.current+1,S.length-1);re.current=O,i(S[S.length-1-O]);return}if(C.key==="ArrowDown"&&re.current>=0&&ee()){C.preventDefault();const S=re.current-1;if(re.current=S,S<0)i(ye.current);else{const O=ne.current;i(O[O.length-1-S])}return}},[V,s,Re,ee]),G=u.useCallback(C=>{var O;const S=(O=C.clipboardData)==null?void 0:O.items;if(S){for(const I of S)if(I.type.startsWith("image/")){C.preventDefault();const W=I.getAsFile();W&&ge(W);return}}},[ge]),pe=w||k;return t.jsxs("div",{className:"border-t border-border px-2.5 md:px-4 py-2.5 md:py-3 bg-card/85 backdrop-blur-sm",style:{paddingBottom:"max(0.625rem, env(safe-area-inset-bottom, 0px))"},role:"presentation",onDragOver:C=>{C.preventDefault(),C.stopPropagation()},onDrop:C=>{C.preventDefault(),C.stopPropagation();const S=C.dataTransfer.files[0];S!=null&&S.type.startsWith("image/")&&ge(S)},children:[c&&t.jsxs("div",{className:"flex items-center gap-2 mb-2 px-2 py-1.5 rounded-md bg-destructive/10 border border-destructive/20 text-destructive text-xs",children:[t.jsx("span",{className:"truncate",children:c}),t.jsx("button",{type:"button",onClick:()=>o(null),className:"shrink-0 hover:text-destructive/80",children:t.jsx(et,{className:"h-3 w-3"})})]}),d&&f&&t.jsxs("div",{className:"flex items-center gap-2 mb-2 px-1",children:[t.jsxs("div",{className:"relative group/preview",children:[t.jsx("img",{src:f,alt:"Upload preview",className:"h-16 w-16 object-cover rounded-md border border-border"}),t.jsx("button",{type:"button",onClick:me,className:"absolute -top-1.5 -right-1.5 h-5 w-5 rounded-full bg-background border border-border flex items-center justify-center opacity-0 group-hover/preview:opacity-100 transition-opacity hover:bg-destructive hover:border-destructive hover:text-destructive-foreground",children:t.jsx(et,{className:"h-3 w-3"})})]}),t.jsxs("div",{className:"text-xs text-muted-foreground/60 font-mono min-w-0",children:[t.jsx("div",{className:"truncate",children:d.name}),t.jsxs("div",{children:[(d.size/1024).toFixed(0)," KB"]})]})]}),t.jsxs("div",{className:`flex gap-2 md:gap-3 group rounded-lg border border-border/60 bg-muted/30 focus-within:border-cyan-500/40 focus-within:bg-muted/50 focus-within:shadow-[0_0_0_1px_rgba(6,182,212,0.1)] transition-all px-2.5 md:px-3 py-2 ${Me?"items-end":"items-center"}`,children:[t.jsx(xt,{className:`h-4 w-4 text-cyan-500/30 shrink-0 group-focus-within:text-cyan-400 transition-colors ${Me?"self-start mt-[5px]":""}`}),t.jsx("textarea",{ref:_,rows:1,placeholder:d?"Add a message (optional)...":"Message... (Shift+Enter for new line)",value:s,onChange:C=>i(C.target.value),onKeyDown:D,onPaste:G,disabled:l,className:"flex-1 bg-transparent text-sm font-mono text-foreground placeholder:text-muted-foreground/40 outline-none min-w-0 resize-none overflow-y-auto leading-[20px]",style:{maxHeight:`${20*tr}px`}}),(s.trim()||d)&&t.jsx("kbd",{className:"hidden sm:inline text-[10px] text-muted-foreground/40 font-mono border border-border rounded px-1.5 py-0.5 bg-muted/50 shrink-0",children:"Enter"}),t.jsx("input",{ref:$,type:"file",accept:Qr,className:"hidden",onChange:C=>{var O;const S=(O=C.target.files)==null?void 0:O[0];S&&ge(S),C.target.value=""}}),t.jsx("button",{type:"button",onClick:()=>{var C;return(C=$.current)==null?void 0:C.click()},title:"Attach image",className:`h-9 w-9 md:h-8 md:w-8 rounded-lg flex items-center justify-center transition-all shrink-0 ${d?"bg-cyan-500/20 text-cyan-400":"text-muted-foreground/40 hover:text-muted-foreground hover:bg-accent/60"}`,children:t.jsx(Cr,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:Ee,disabled:!pe||l||R,title:R?"Transcribing voice input...":pe?v?"Stop voice input":w?"Start voice input":"Start voice recording":"Voice input unsupported on this browser",className:`h-9 w-9 md:h-8 md:w-8 rounded-lg flex items-center justify-center transition-all shrink-0 ${v?"bg-emerald-500/20 text-emerald-300":R?"bg-cyan-500/20 text-cyan-300":"text-muted-foreground/40 hover:text-muted-foreground hover:bg-accent/60"} disabled:opacity-30 disabled:cursor-not-allowed`,children:v?t.jsx(Ta,{className:"h-4 w-4"}):R?t.jsx(br,{className:"h-4 w-4 animate-spin"}):t.jsx(Ma,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:V,disabled:l||!(s.trim()||d),className:"h-9 w-9 md:h-8 md:w-8 rounded-lg flex items-center justify-center bg-cyan-500/10 text-cyan-400/60 hover:bg-cyan-500/20 hover:text-cyan-400 active:bg-cyan-500/30 disabled:opacity-20 disabled:cursor-not-allowed transition-all shrink-0",children:t.jsx(za,{className:"h-4 w-4"})})]})]})}const zl={Enter:"enter",Escape:"escape",Tab:"tab",Backspace:"backspace",Delete:"delete",Insert:"insert",ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right",Home:"home",End:"end",PageUp:"pageup",PageDown:"pagedown"};function rr(e){if(e===" ")return"space";if(e.length!==1)return null;const n=e.toLowerCase();return/^[a-z0-9]$/.test(n)||/[[\]\\/\-=`;',.]/.test(n)?n:n==="^"?"^":n==="_"?"_":n==="?"?"?":null}function $l(e){return/^F([1-9]|1[0-2])$/.test(e)}function dn(e){if(e.isComposing||e.key==="Dead")return null;const n=zl[e.key];if(n)return n==="tab"&&e.shiftKey&&!e.ctrlKey&&!e.altKey&&!e.metaKey?{kind:"key",key:"shift+tab"}:{kind:"key",key:n};if($l(e.key))return{kind:"key",key:e.key.toLowerCase()};const r=typeof e.getModifierState=="function"&&e.getModifierState("AltGraph");if(!(e.metaKey||e.ctrlKey||e.altKey))return e.key.length===1?{kind:"text",text:e.key}:null;if(!e.metaKey&&e.ctrlKey&&e.altKey&&r&&e.key.length===1)return{kind:"text",text:e.key};if(!e.metaKey&&e.ctrlKey&&!e.altKey&&e.key.length===1){const s=rr(e.key);return s?{kind:"key",key:`ctrl+${s}`}:null}if(!(e.metaKey||e.ctrlKey)&&e.altKey&&e.key.length===1){const s=rr(e.key);return s?{kind:"key",key:`alt+${s}`}:null}return null}function sr(e){return typeof HTMLElement>"u"||!(e instanceof HTMLElement)||e.classList.contains("xterm-helper-textarea")?!1:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable||e.closest("[contenteditable='true']")!==null}const Il="\x1B[0m\x1B[H\x1B[2J",Ol=8,yn="\x1B",Bl=new RegExp(`${yn}\\[[0-9;?]*([A-Za-z])`,"g");function Hl(e){return(e.endsWith(`
|
|
158
|
+
`)?e.slice(0,-1):e).split(`
|
|
159
|
+
`)}function Ul(e,n){const r=Math.max(0,n-e.length);return r===0?e:[...new Array(r).fill(""),...e]}function ql(e){if(!e.includes(yn))return!1;if(e.includes(`${yn}]`))return!0;const n=e.matchAll(Bl);for(const r of n){const s=r[1];if(s&&s!=="m")return!0}return!1}function Vl(e,n,r){if(e.length!==r||n.length!==r)return null;const s=[];for(let l=0;l<r;l+=1)(e[l]??"")!==(n[l]??"")&&s.push(l);if(s.length===0)return"";if(s.length>Ol)return null;let i="\x1B[0m";for(const l of s){const a=n[l]??"";if(ql(a))return null;const c=l+1;i+=`\x1B[${c};1H\x1B[0m\x1B[2K${a}`}return i}function Kl(e,n){const r=Hl(n.content),s=Ul(r,n.rows),i={content:n.content,rows:n.rows,cols:n.cols,renderedLines:s};if(e&&e.content===i.content&&e.rows===i.rows&&e.cols===i.cols)return{kind:"noop",nextState:i};if(e&&e.rows===i.rows&&e.cols===i.cols){const l=Vl(e.renderedLines,i.renderedLines,n.rows);if(l!==null)return l.length===0?{kind:"noop",nextState:i}:{kind:"incremental",buffer:l,nextState:i}}return{kind:"full",buffer:`${Il}${i.renderedLines.join(`\r
|
|
160
|
+
`)}`,nextState:i}}const Jr=120;function ar(e,n){return{sessionId:e,startedAt:Date.now(),updatedAt:Date.now(),wsFramesReceived:0,staleFramesDropped:0,seqRegressionResets:0,seqGapEvents:0,reconnectEvents:0,reconnectRefreshFetches:0,initialFetchDrops:0,replayCursorSeq:0,inputDispatches:0,keyDispatches:0,textDispatches:0,pasteDispatches:0,keyToEchoLastMs:null,keyToEchoP50Ms:null,keyToEchoP95Ms:null,keyToEchoSamples:0,scrollToPaintLastMs:null,scrollToPaintP50Ms:null,scrollToPaintP95Ms:null,scrollToPaintSamples:0,reconnectResyncLastMs:null,reconnectResyncP50Ms:null,reconnectResyncP95Ms:null,reconnectResyncSamples:0,featureWsPtyPasteEnabled:n.wsPtyPaste.enabled,featureLatencyProbesEnabled:n.latencyProbes.enabled,featureDiagnosticsPanelEnabled:n.diagnosticsPanel.enabled,fullFrameRepaints:0,incrementalRepaints:0}}function ir(e,n){if(e.length===0)return null;const r=[...e].sort((i,l)=>i-l),s=Math.max(0,Math.min(r.length-1,Math.floor(n/100*(r.length-1))));return r[s]??null}function mn(e,n){return e.push(n),e.length>Jr&&e.shift(),{lastMs:n,p50Ms:ir(e,50),p95Ms:ir(e,95),sampleCount:e.length}}function mt(e){return e===null?"--":e>=100?`${Math.round(e)}ms`:`${e.toFixed(1)}ms`}const Gl=[{label:"Ctrl+C",key:"ctrl+c"},{label:"Ctrl+D",key:"ctrl+d"},{label:"Ctrl+L",key:"ctrl+l"},{label:"Enter",key:"enter"},{label:"Esc",key:"escape"},{label:"Tab",key:"tab"},{label:"Shift+Tab",key:"shift+tab"},{label:"⌫",key:"backspace"},{label:"Del",key:"delete"},{label:"↑",key:"up"},{label:"↓",key:"down"},{label:"←",key:"left"},{label:"→",key:"right"},{label:"PgUp",key:"pageup"},{label:"PgDn",key:"pagedown"},{label:"Home",key:"home"},{label:"End",key:"end"}],Wl=[{label:"Ctrl+C",key:"ctrl+c"},{label:"Ctrl+D",key:"ctrl+d"},{label:"Esc",key:"escape"},{label:"Tab",key:"tab"},{label:"Enter",key:"enter"},{label:"⌫",key:"backspace"},{label:"←",key:"left"},{label:"↑",key:"up"},{label:"↓",key:"down"},{label:"→",key:"right"},{label:"PgUp",key:"pageup"},{label:"PgDn",key:"pagedown"},{label:"Home",key:"home"},{label:"End",key:"end"},{label:"Ctrl+L",key:"ctrl+l"},{label:"Del",key:"delete"},{label:"Shift+Tab",key:"shift+tab"}],Se=typeof window<"u"&&(window.matchMedia("(pointer: coarse)").matches||"ontouchstart"in window);function or(e){if(!e)return!0;const n=e.trim().toLowerCase();return n==="transparent"||n==="#0000"||n==="#00000000"||n==="rgba(0,0,0,0)"||n==="rgba(0, 0, 0, 0)"}function lr(e){const n=or(e.cursor)?e.foreground||"#d4d4e0":e.cursor,r=or(e.cursorAccent)?e.background||"#0e1016":e.cursorAccent;return{...e,cursor:n,cursorAccent:r}}function Ut(e){return e==="interactive"||e==="scroll"||e==="search"}function Ql(e,n){if(n.start<0||n.deleteCount<0||n.start>e.length)return null;const r=n.start+n.deleteCount;return r>e.length?null:e.slice(0,n.start)+n.data+e.slice(r)}function Yl(e,n){if(!e)return null;const r=Math.max(0,n.cols-1),s=Math.max(0,n.rows-1);return{x:Math.min(r,Math.max(0,Math.floor(e.x))),y:Math.min(s,Math.max(0,Math.floor(e.y))),visible:e.visible!==!1}}function Xl(e,n,r){if(!e)return null;const i=(n.endsWith(`
|
|
161
|
+
`)?n.slice(0,-1):n).split(`
|
|
162
|
+
`).length,l=Math.max(0,r-i);return l===0?e:{...e,y:e.y+l}}function Jl(e,n){return e===n?!0:e&&n?e.x===n.x&&e.y===n.y&&e.visible===n.visible:!1}function cr(e){return e?e.visible?`\x1B[?25h\x1B[${e.y+1};${e.x+1}H`:"\x1B[?25l":"\x1B[?25h"}function Zl(e){return typeof e.x!="number"||typeof e.y!="number"||Number.isNaN(e.x)||Number.isNaN(e.y)?null:{x:e.x,y:e.y,visible:e.visible!==!1}}function ec({sessionId:e,sessionStatus:n,supportsConversationView:r=!0}){const{theme:s}=xr(),[i,l]=u.useState(null),a=u.useMemo(()=>Cl(e,i??void 0),[e,i]),c=u.useRef(null),o=u.useRef(null),d=u.useRef(null),[m,f]=u.useState("terminal"),[b,w]=u.useState(!1),[x,k]=u.useState(!1),[N,v]=u.useState(null),[y,R]=u.useState(!1),[L,_]=u.useState(null),[$,Q]=u.useState(!1),[X,de]=u.useState(!1),[g,ne]=u.useState(!1),[re,ye]=u.useState(0),[fe,Me]=u.useState(null),[ge,me]=u.useState(!1),[je,se]=u.useState(Se),[B,Ee]=u.useState("interactive"),V=u.useRef("interactive"),Re=u.useRef("interactive"),[ee,D]=u.useState(""),[G,pe]=u.useState(null),C=u.useRef(null),S=n==="STOPPED"||n==="CRASHED",O=r,I=Se?Wl:Gl,W=u.useRef(null),te=u.useRef(null),ie=u.useRef(null),J=u.useRef(null),ve=u.useRef(null),xe=u.useRef(null),oe=u.useRef(null),M=u.useRef(null),Y=u.useRef(null),De=u.useRef(0),le=u.useRef(0),ce=u.useRef(null),Ie=u.useRef(!1),bt=u.useRef(lr(s.terminal)),ue=u.useRef(0),be=u.useRef(""),_e=u.useRef(null),Oe=u.useRef(0),Ne=u.useRef(null),Be=u.useRef(!1),tt=u.useRef(null),nt=u.useRef(null),Rn=u.useRef(Promise.resolve()),Mt=u.useRef(0),Qt=u.useRef(null),yt=u.useRef(0),Dt=u.useRef(Ae.isConnected()),H=u.useRef(ar(e,a)),vt=u.useRef([]),Tn=u.useRef([]),An=u.useRef([]),Mn=u.useRef([]),Pt=u.useRef(null);u.useEffect(()=>{O||m!=="conversation"||f("terminal")},[O,m]),u.useEffect(()=>{let h=!1;return A.getDaemonSettings().then(({settings:p})=>{h||l(p.terminalFeatures)}).catch(()=>{h||l(null)}),()=>{h=!0}},[]),u.useEffect(()=>{let h=!1;return me(!0),A.getSessionNotificationPrefs(e).then(({prefs:p})=>{h||Me(p.enabled??null)}).catch(()=>{h||Me(null)}).finally(()=>{h||me(!1)}),()=>{h=!0}},[e]);const Zr=u.useCallback(async()=>{if(ge)return;const h=fe===!1?null:!1;me(!0);try{const{prefs:p}=await A.updateSessionNotificationPrefs(e,h);Me(p.enabled??null),q.success(p.enabled===!1?"Notifications muted for this session":"Session notifications now follow global settings")}catch(p){q.error(p instanceof Error?p.message:"Failed to update notification preference")}finally{me(!1)}},[e,fe,ge]);u.useEffect(()=>S?void 0:Ae.subscribe(`session:${e}:events`,p=>{const T=p.data;if(!T||T.type!=="terminal_mode_change")return;const j=Ut(T.mode)?T.mode:"interactive";j==="scroll"&&Date.now()<ue.current||(Ee(j),V.current=j)}),[e,S]),u.useEffect(()=>{if(B==="interactive"||S){pe(null);return}const h=async()=>{try{const T=await A.getTerminalInfo(e);if(T.scrollPosition!==void 0&&T.historySize!==void 0){const j={position:T.scrollPosition,total:T.historySize};_e.current=j,pe(j)}}catch{}};h();const p=setInterval(h,2e3);return()=>clearInterval(p)},[e,B,S]),u.useEffect(()=>{if(S){_e.current=null;return}let h=!1;return A.getTerminalInfo(e).then(p=>{h||(Ut(p.mode)&&(p.mode==="scroll"&&Date.now()<ue.current||(V.current=p.mode,Ee(T=>T===p.mode?T:p.mode))),p.scrollPosition!==void 0&&p.historySize!==void 0&&(_e.current={position:p.scrollPosition,total:p.historySize}))}).catch(()=>{}),()=>{h=!0}},[e,S]);const rt=u.useCallback(h=>{const p=H.current;p.inputDispatches+=1,h==="key"?p.keyDispatches+=1:h==="text"?p.textDispatches+=1:p.pasteDispatches+=1,p.updatedAt=Date.now(),a.latencyProbes.enabled&&(vt.current.push({kind:h,sentAt:performance.now()}),vt.current.length>Jr&&vt.current.shift())},[a.latencyProbes.enabled]),Dn=u.useCallback(()=>{if(!a.latencyProbes.enabled)return;const h=vt.current.shift();if(!h)return;const p=Math.max(0,performance.now()-h.sentAt),T=H.current,j=mn(Tn.current,p);T.keyToEchoLastMs=j.lastMs,T.keyToEchoP50Ms=j.p50Ms,T.keyToEchoP95Ms=j.p95Ms,T.keyToEchoSamples=j.sampleCount,T.updatedAt=Date.now()},[a.latencyProbes.enabled]),Lt=u.useCallback(h=>{if(!a.latencyProbes.enabled)return;const p=Math.max(0,performance.now()-h),T=H.current,j=mn(An.current,p);T.scrollToPaintLastMs=j.lastMs,T.scrollToPaintP50Ms=j.p50Ms,T.scrollToPaintP95Ms=j.p95Ms,T.scrollToPaintSamples=j.sampleCount,T.updatedAt=Date.now()},[a.latencyProbes.enabled]),Pn=u.useCallback(()=>{a.latencyProbes.enabled&&(Pt.current=performance.now())},[a.latencyProbes.enabled]),st=u.useCallback(()=>{const h=Pt.current;if(h===null||!a.latencyProbes.enabled)return;Pt.current=null;const p=Math.max(0,performance.now()-h),T=H.current,j=mn(Mn.current,p);T.reconnectResyncLastMs=j.lastMs,T.reconnectResyncP50Ms=j.p50Ms,T.reconnectResyncP95Ms=j.p95Ms,T.reconnectResyncSamples=j.sampleCount,T.updatedAt=Date.now()},[a.latencyProbes.enabled]);u.useEffect(()=>{if(!g)return;const h=setInterval(()=>{ye(p=>p+1)},500);return()=>clearInterval(h)},[g]),u.useEffect(()=>{a.diagnosticsPanel.enabled||!g||ne(!1)},[g,a.diagnosticsPanel.enabled]);const z=u.useMemo(()=>g?{capturedAt:Date.now(),terminal:{...H.current},ws:Ae.getTelemetrySnapshot(),queueDepth:Ae.getSessionInputQueueDepth(e)}:null,[g,re,e]);u.useEffect(()=>{B==="search"&&setTimeout(()=>{var h;return(h=C.current)==null?void 0:h.focus()},50)},[B]),u.useEffect(()=>{if(Se||S||m!=="terminal"||B!=="interactive")return;const h=o.current;if(!h)return;const p=setTimeout(()=>h.focus(),0);return()=>clearTimeout(p)},[m,B,S]);const He=u.useCallback((h,p,T)=>{te.current=p,ie.current=T??Y.current,W.current!==null&&cancelAnimationFrame(W.current),W.current=requestAnimationFrame(()=>{if(te.current!==null){const j=te.current,U=Yl(Xl(ie.current,j,h.rows),h),F=Kl(M.current,{content:j,rows:h.rows,cols:h.cols});F.kind==="full"||F.kind==="incremental"?(h.write(`${F.buffer}${cr(U)}`),M.current=F.nextState,F.kind==="full"?H.current.fullFrameRepaints+=1:H.current.incrementalRepaints+=1,H.current.updatedAt=Date.now()):(M.current=F.nextState,Jl(U,Y.current)||h.write(cr(U))),oe.current={content:j,rows:h.rows,cols:h.cols},Y.current=U,te.current=null,ie.current=null}W.current=null})},[]);u.useEffect(()=>{var j;const h=lr(s.terminal);bt.current=h;const p=o.current;if(!p)return;p.options.theme=h;const T=(j=oe.current)==null?void 0:j.content;T&&(oe.current=null,M.current=null,He(p,T))},[s,He]),u.useEffect(()=>{if(m!=="terminal"||!c.current)return;const h=20,p=300,T=14,j=1.2,P=Math.ceil(T*j),U=8.4,F=new Gs.Terminal({disableStdin:!0,cursorBlink:!1,cursorInactiveStyle:"outline",fontSize:T,fontFamily:'"JetBrains Mono", "Fira Code", Menlo, Monaco, "Courier New", monospace',lineHeight:j,letterSpacing:0,cols:h,rows:24,scrollback:0,allowProposedApi:!0,theme:bt.current}),lt=new Ws.WebLinksAddon;F.loadAddon(lt),F.open(c.current),o.current=F,oe.current=null,M.current=null,Y.current=null,ie.current=null,xe.current=null,De.current=0,le.current=0,ce.current=null,Ie.current=!1,H.current=ar(e,a),vt.current=[],Tn.current=[],An.current=[],Mn.current=[],Pt.current=null,Dt.current=Ae.isConnected(),requestAnimationFrame(()=>{if(!c.current)return;const E=c.current.querySelector(".xterm-viewport");if(E instanceof HTMLElement&&(E.style.overflow="hidden"),Se){const Z=c.current.querySelector(".xterm-helper-textarea");Z instanceof HTMLTextAreaElement&&(Z.setAttribute("readonly","readonly"),Z.setAttribute("inputmode","none"),Z.tabIndex=-1,Z.style.pointerEvents="none")}});const Pe=()=>{var Z;const E=(Z=c.current)==null?void 0:Z.querySelector(".xterm-rows > div");if(E){const ae=E.getBoundingClientRect().height;if(ae>0)return ae}return P},ct=()=>{var Z;const E=(Z=c.current)==null?void 0:Z.querySelector(".xterm-screen");if(E&&F.cols>0){const ae=E.getBoundingClientRect().width;if(ae>0)return ae/F.cols}return U},ut=async E=>{const Z=le.current;try{const{output:ae}=await A.getSessionOutput(e);if(!(ae&&o.current)){E!=null&&E.completeReconnectProbe&&st();return}if(E!=null&&E.dropIfLiveOutputAdvanced&&le.current!==Z){H.current.initialFetchDrops+=1,H.current.updatedAt=Date.now(),E!=null&&E.completeReconnectProbe&&st();return}ce.current=ae,He(o.current,ae),E!=null&&E.completeReconnectProbe&&st()}catch{E!=null&&E.completeReconnectProbe&&st()}},qe=()=>{try{const E=c.current;if(!E)return;const Z=E.clientHeight-4,ae=E.clientWidth,Fe=Pe(),Bt=ct(),Ve=Math.max(1,Math.floor(Z/Fe)),wt=Math.min(p,Math.max(h,Math.floor(ae/Bt)));(F.rows!==Ve||F.cols!==wt)&&F.resize(wt,Ve),(!xe.current||xe.current.cols!==wt||xe.current.rows!==Ve)&&(xe.current={cols:wt,rows:Ve},oe.current&&(M.current=null,He(F,oe.current.content)),S||(ve.current&&clearTimeout(ve.current),ve.current=setTimeout(()=>{A.resizeSession(e,wt,Ve).catch(()=>{})},200)))}catch{}};J.current=qe,requestAnimationFrame(()=>qe());const us=setTimeout(()=>{requestAnimationFrame(()=>qe())},180),ds=c.current,$n=new ResizeObserver(()=>{requestAnimationFrame(()=>qe())});$n.observe(ds);const Xt=()=>{requestAnimationFrame(()=>qe())},dt=()=>{typeof document<"u"&&document.visibilityState==="hidden"||Xt()};typeof window<"u"&&(window.addEventListener("resize",Xt),window.addEventListener("focus",dt),window.addEventListener("pageshow",dt)),typeof document<"u"&&document.addEventListener("visibilitychange",dt),k(!1),ut({dropIfLiveOutputAdvanced:!0}).finally(()=>{k(!0)}),A.getTerminalInfo(e).then(E=>{if(o.current!==F)return;const ae=typeof E.cols=="number"&&typeof E.rows=="number"&&(E.cols!==F.cols||E.rows!==F.rows);if(!S&&Ut(E.mode)&&E.mode!=="interactive"&&ae){ue.current=Date.now()+250,V.current="interactive",Ee(Fe=>Fe==="interactive"?Fe:"interactive"),A.setTerminalMode(e,"interactive").catch(()=>{}).finally(()=>{A.resizeSession(e,F.cols,F.rows).catch(()=>{}),ut()});return}Ut(E.mode)&&(E.mode==="scroll"&&Date.now()<ue.current||(V.current=E.mode,Ee(Fe=>Fe===E.mode?Fe:E.mode))),!S&&ae&&A.resizeSession(e,F.cols,F.rows).catch(()=>{})}).catch(()=>{}),w(Ae.isConnected());const ms=Ae.onConnectionChange(E=>{w(E),!Dt.current&&E&&(H.current.reconnectEvents+=1,H.current.updatedAt=Date.now()),Dt.current&&!E&&Pn(),Dt.current=E,E&&V.current==="interactive"&&(H.current.reconnectRefreshFetches+=1,H.current.updatedAt=Date.now(),ut({dropIfLiveOutputAdvanced:!0,completeReconnectProbe:!0}))}),Jt=()=>{V.current==="interactive"&&(Ie.current||(Ie.current=!0,ut().finally(()=>{Ie.current=!1})))},fs=Ae.subscribe(`session:${e}:pty`,E=>{if(E.type!=="pty_output"&&E.type!=="pty_patch")return;H.current.wsFramesReceived+=1,H.current.updatedAt=Date.now();const Z=De.current;if(typeof E.seq=="number"){if(E.seq===Z){H.current.staleFramesDropped+=1,H.current.updatedAt=Date.now();return}E.seq<Z&&(H.current.seqRegressionResets+=1,De.current=0),Z>0&&E.seq>Z+1&&(H.current.seqGapEvents+=1)}let ae=null;const Fe=E.cursor?Zl(E.cursor):void 0;if(E.type==="pty_output"&&typeof E.data=="string")ae=E.data;else if(E.type==="pty_patch"){if(typeof E.baseSeq!="number"||typeof E.start!="number"||typeof E.deleteCount!="number"||typeof E.data!="string")return;if(Z!==0&&E.baseSeq!==Z){H.current.seqGapEvents+=1,H.current.updatedAt=Date.now(),Jt();return}const Bt=ce.current;if(Bt===null){H.current.seqGapEvents+=1,H.current.updatedAt=Date.now(),Jt();return}const Ve=Ql(Bt,{start:E.start,deleteCount:E.deleteCount,data:E.data});if(Ve===null){H.current.seqGapEvents+=1,H.current.updatedAt=Date.now(),Jt();return}ae=Ve}typeof E.seq=="number"&&(De.current=E.seq,H.current.replayCursorSeq=E.seq),ae!==null&&(ce.current=ae,V.current==="interactive"&&(st(),Dn(),le.current+=1,He(F,ae,Fe)))},{getReplayCursor:()=>De.current>0?De.current:void 0});return()=>{if($n.disconnect(),clearTimeout(us),W.current!==null&&cancelAnimationFrame(W.current),ve.current&&clearTimeout(ve.current),typeof window<"u"&&(window.removeEventListener("resize",Xt),window.removeEventListener("focus",dt),window.removeEventListener("pageshow",dt)),typeof document<"u"&&document.removeEventListener("visibilitychange",dt),J.current=null,ms(),fs(),w(!1),typeof window<"u"){const E=window;E.__codepiperTerminalTransportTelemetry={...E.__codepiperTerminalTransportTelemetry??{},[e]:{...H.current,updatedAt:Date.now()}}}F.dispose(),o.current=null,xe.current=null}},[e,m,He,S,a,Pn,st,Dn]);const Ln=u.useCallback(async h=>{if(!S)try{rt("key");const p=async()=>{await A.sendKeys(e,{keys:[h]})};Ae.sendPtyKey(e,h,{onDispatchError:async()=>{try{await p()}catch(j){console.error("Failed to fallback PTY key to HTTP:",j)}}})||await p()}catch(p){console.error("Failed to send key:",p)}},[e,S,rt]),_n=u.useCallback(async h=>{if(!(S||!h))try{rt("text");const p=async()=>{await A.sendText(e,{text:h,newline:!1})};Ae.sendPtyInput(e,h,{onDispatchError:async()=>{try{await p()}catch(j){console.error("Failed to fallback PTY input to HTTP:",j)}}})||await p()}catch(p){console.error("Failed to send input text:",p)}},[e,S,rt]),Te=u.useCallback(h=>{Ee(h),V.current=h},[]),Ye=u.useCallback(()=>{Oe.current=0,Be.current=!1,tt.current=null,Ne.current&&(clearTimeout(Ne.current),Ne.current=null)},[]),at=u.useCallback(async()=>{V.current!=="interactive"&&(Te("interactive"),D(""),pe(null),be.current="",oe.current=null,M.current=null,Ye(),await A.setTerminalMode(e,"interactive").catch(()=>{}))},[e,Te,Ye]),it=u.useCallback(async h=>{await at(),h.kind==="key"?await Ln(h.key):await _n(h.text)},[at,Ln,_n]),es=u.useCallback(h=>{it({kind:"key",key:h})},[it]),Ce=u.useCallback(async()=>{await new Promise(h=>setTimeout(h,20));try{const{output:h}=await A.getSessionOutput(e);h&&o.current&&(ce.current=h,He(o.current,h))}catch{}},[e,He]),Xe=u.useCallback(async()=>{var p;Te("interactive"),D(""),pe(null),be.current="",oe.current=null,M.current=null,Ye(),(p=J.current)==null||p.call(J);const h=o.current;h&&!S&&await A.resizeSession(e,h.cols,h.rows).catch(()=>{}),await Ce()},[Te,Ce,e,S,Ye]);u.useEffect(()=>{var j;const h=Re.current;if(Re.current=B,h===B||S||m!=="terminal")return;const p=()=>{const P=o.current;!P||S||A.resizeSession(e,P.cols,P.rows).catch(()=>{})};if((j=J.current)==null||j.call(J),p(),requestAnimationFrame(()=>{var P;(P=J.current)==null||P.call(J),p()}),h==="interactive"||B==="interactive"){const P=setTimeout(()=>{var U;(U=J.current)==null||U.call(J),p(),Ce()},140);return()=>clearTimeout(P)}},[B,e,S,m,Ce]);const _t=u.useCallback(async()=>{try{await A.setTerminalMode(e,"interactive"),await Xe()}catch(h){console.error("Failed to exit mode:",h)}},[e,Xe]),we=u.useCallback(async(h,p)=>{const T=performance.now();try{let j=_e.current;if(!(p!=null&&p.edge)&&h==="up"&&V.current==="interactive"&&!j){const U=await A.getTerminalInfo(e).catch(()=>null);(U==null?void 0:U.scrollPosition)!==void 0&&U.historySize!==void 0&&(j={position:U.scrollPosition,total:U.historySize},_e.current=j)}if(!(p!=null&&p.edge)&&h==="up"){if(V.current==="interactive"&&(j==null?void 0:j.total)===0){ue.current=Date.now()+250,Ye();return}if(V.current!=="interactive"&&j&&j.total>0&&j.position>=j.total){Ye();return}}if(p!=null&&p.edge){if(await A.scrollTerminal(e,{edge:p.edge}),p.edge==="bottom"){ue.current=Date.now()+250,await Xe(),Lt(T);return}}else await A.scrollTerminal(e,{direction:h,page:p==null?void 0:p.page,lines:p==null?void 0:p.lines});V.current==="interactive"&&(ue.current=0,Te("scroll"));const P=await A.getTerminalInfo(e).catch(()=>null);if((P==null?void 0:P.scrollPosition)!==void 0){if(P.historySize!==void 0&&(_e.current={position:P.scrollPosition,total:P.historySize}),P.scrollPosition<=0){ue.current=Date.now()+250,await Xe(),Lt(T);return}P.historySize!==void 0&&pe({position:P.scrollPosition,total:P.historySize})}await Ce(),Lt(T)}catch(j){console.error("Failed to scroll:",j)}},[e,Te,Ce,Xe,Lt,Ye]),Yt=u.useCallback(async h=>{if(h.trim())try{const p=h.trim();await A.searchTerminal(e,{query:p}),be.current=p,Te("search"),await Ce()}catch(p){console.error("Failed to search:",p)}},[e,Te,Ce]),Ue=u.useCallback(async h=>{try{if(h!=="cancel"&&!be.current){const p=ee.trim();if(!p)return;await Yt(p);return}if(await A.searchTerminal(e,{action:h}),h==="cancel"){be.current="",await Xe();return}await Ce()}catch(p){console.error("Failed to perform search action:",p)}},[e,Xe,Ce,ee,Yt]),Ft=u.useCallback(async()=>{D(""),Te("search"),be.current="",ue.current=0;try{await A.setTerminalMode(e,"scroll"),await Ce()}catch(h){console.error("Failed to enter search mode:",h),Te("interactive")}},[e,Ce,Te]),ot=u.useCallback(()=>!S&&m==="terminal",[S,m]),zt=u.useCallback(async()=>{var qe;if(Ne.current=null,Be.current){Ne.current=setTimeout(zt,35);return}const h=Oe.current;if(h===0)return;const p=c.current,T=((qe=o.current)==null?void 0:qe.rows)||30,j=Math.max(8,p?p.clientHeight/T:18),P=Math.max(6,j*.35),U=h/P;if(V.current==="interactive"&&U>0){Oe.current=0;return}const F=U<0?Math.ceil(U):Math.floor(U);if(F===0)return;const lt=24,Pe=F<0?Math.max(F,-lt):Math.min(F,lt);Oe.current-=Pe*P;const ct=Math.max(1,Math.abs(Pe)),ut=Pe<0?"up":"down";Be.current=!0;try{await we(ut,{lines:ct})}finally{Be.current=!1,Oe.current!==0&&(Ne.current=setTimeout(zt,35))}},[we]),$t=u.useCallback(h=>{Oe.current+=h,Ne.current||(Ne.current=setTimeout(zt,35))},[zt]),Fn=u.useCallback((h,p,T,j)=>{var ct;if(!ot()||T)return;j();const P=c.current,U=((ct=o.current)==null?void 0:ct.rows)||30,F=Math.max(8,P?P.clientHeight/U:18),lt=Math.max(F*U,(P==null?void 0:P.clientHeight)??F*U);let Pe=h;p===1?Pe*=F:p===2&&(Pe*=lt),!(V.current==="interactive"&&Pe>0)&&$t(Pe)},[ot,$t]);u.useEffect(()=>{if(m!=="terminal")return;const h=c.current;if(!h)return;const p=T=>{Fn(T.deltaY,T.deltaMode,T.ctrlKey,()=>{T.preventDefault()})};return h.addEventListener("wheel",p,{capture:!0,passive:!1}),()=>{h.removeEventListener("wheel",p,!0)}},[Fn,m]);const ts=u.useCallback(h=>{ot()&&h.touches.length===1&&(tt.current=h.touches[0].clientY)},[ot]),ns=u.useCallback(h=>{if(!ot()||tt.current===null||h.touches.length!==1)return;h.preventDefault();const p=h.touches[0].clientY,T=tt.current-p;Math.abs(T)<10||(tt.current=p,!(V.current==="interactive"&&T>0)&&$t(T))},[ot,$t]),rs=u.useCallback(()=>{tt.current=null},[]);u.useEffect(()=>()=>{Ne.current&&clearTimeout(Ne.current),nt.current&&clearTimeout(nt.current)},[]);const he=u.useCallback((h,p)=>{nt.current&&clearTimeout(nt.current),v({tone:h,text:p}),nt.current=setTimeout(()=>{v(null),nt.current=null},2600)},[]),zn=u.useCallback(async h=>{if(S)return;const p=Yr(h);if(p){he("error",p);return}try{R(!0),_(0),Q(!1),Qt.current=null,he("info","Uploading image..."),await at();const{path:T}=await A.uploadImage(e,h,{onProgress:j=>_(j)});await A.sendText(e,{text:T,newline:!0}),_(null),he("success","Image attached")}catch(T){console.error("Failed to attach image:",T),Qt.current=h,Q(!0),_(null),he("error",Dl(T))}finally{R(!1)}},[at,S,e,he]),It=u.useCallback(h=>{Mt.current+=1,Rn.current=Rn.current.catch(()=>{}).then(()=>zn(h)).finally(()=>{Mt.current=Math.max(0,Mt.current-1)})},[zn]),Je=u.useCallback(h=>{if(h.length===0)return;const p=Rl(h,Mt.current);if(p.accepted.length===0){he("error",`Attachment queue is full (max ${bn} pending)`);return}for(const j of p.accepted)It(j);const T=p.droppedByBatchLimit+p.droppedByQueueLimit;if(T>0){he("info",`Queued ${p.accepted.length} image(s), skipped ${T} (max ${gn} per add, ${bn} pending)`);return}p.accepted.length>1&&he("info",`Queueing ${p.accepted.length} images...`)},[It,he]),ss=u.useCallback(()=>{if(y)return;const h=Qt.current;h&&It(h)},[It,y]),Ot=Xr(),as=u.useCallback(async()=>{if(!Ot){he("error","Clipboard image read is not supported on this browser");return}try{const h=await Tl();if(!h){he("error","No image found in clipboard");return}Je([h])}catch(h){if(h instanceof DOMException&&h.name==="NotAllowedError"){he("error","Clipboard permission denied");return}console.error("Failed to read image from clipboard:",h),he("error","Failed to read image from clipboard")}},[Ot,Je,he]),is=u.useCallback(h=>{Se||S||m!=="terminal"||un(h.dataTransfer)&&(h.preventDefault(),h.stopPropagation(),yt.current+=1,de(!0))},[S,m]),os=u.useCallback(h=>{Se||S||m!=="terminal"||un(h.dataTransfer)&&(h.preventDefault(),h.stopPropagation(),h.dataTransfer.dropEffect="copy",X||de(!0))},[X,S,m]),ls=u.useCallback(h=>{Se||un(h.dataTransfer)&&(h.preventDefault(),h.stopPropagation(),yt.current=Math.max(0,yt.current-1),yt.current===0&&de(!1))},[]),cs=u.useCallback(h=>{if(Se||S||m!=="terminal")return;h.preventDefault(),h.stopPropagation(),yt.current=0,de(!1);const p=er(h.dataTransfer);if(p.length===0){he("error","Drop PNG, JPEG, GIF, or WebP images");return}Je(p)},[Je,S,he,m]);return u.useEffect(()=>{if(S||m!=="terminal")return;const h=async j=>{try{await at(),rt("paste");const P=async()=>{await A.sendText(e,{text:j,newline:!1})};if(!a.wsPtyPaste.enabled){await P();return}Ae.sendPtyPaste(e,j,{onDispatchError:async()=>{try{await P()}catch(F){console.error("Failed to fallback PTY paste to HTTP:",F)}}})||await P()}catch(P){console.error("Failed to send pasted text:",P)}},p=j=>{if(!sr(j.target)){if(a.diagnosticsPanel.enabled&&j.key.toLowerCase()==="d"&&j.shiftKey&&(j.ctrlKey||j.metaKey)){j.preventDefault(),ne(P=>!P);return}if(B==="interactive"){if(j.key==="PageUp"){j.preventDefault(),we("up",{page:!0});return}const P=dn(j);if(!P)return;j.preventDefault(),it(P)}else if(B==="scroll"){switch(j.key){case"PageUp":j.preventDefault(),we("up",{page:!0});return;case"PageDown":j.preventDefault(),we("down",{page:!0});return;case"ArrowUp":j.preventDefault(),we("up");return;case"ArrowDown":j.preventDefault(),we("down");return;case"Escape":j.preventDefault(),_t();return;case"/":j.preventDefault(),Ft();return}const P=dn(j);if(!P)return;j.preventDefault(),it(P)}else if(B==="search"){if(j.key==="Escape"){j.preventDefault(),Ue("cancel");return}const P=dn(j);if(!P)return;j.preventDefault(),it(P)}}},T=j=>{var F;if(sr(j.target))return;const P=er(j.clipboardData);if(P.length>0){j.preventDefault(),Je(P);return}const U=(F=j.clipboardData)==null?void 0:F.getData("text");U&&(j.preventDefault(),h(U))};return window.addEventListener("keydown",p,{capture:!0}),window.addEventListener("paste",T,{capture:!0}),()=>{window.removeEventListener("keydown",p,!0),window.removeEventListener("paste",T,!0)}},[S,m,B,Je,we,it,at,rt,e,_t,Ft,Ue,a.wsPtyPaste.enabled,a.diagnosticsPanel.enabled]),t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-border px-2 md:px-3 py-1 md:py-1.5 bg-card/80 backdrop-blur-sm gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2 md:gap-3 min-w-0",children:[t.jsxs("div",{className:"flex gap-0.5 bg-muted/40 rounded-lg p-0.5 shrink-0",children:[t.jsxs("button",{type:"button",onClick:()=>f("terminal"),className:`flex items-center gap-1 md:gap-1.5 px-2 md:px-2.5 py-1 rounded-md text-xs font-medium transition-all ${m==="terminal"?"bg-background text-primary shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[t.jsx(yr,{className:"h-3 w-3"}),t.jsx("span",{children:"Tmux"})]}),O&&t.jsxs("button",{type:"button",onClick:()=>f("conversation"),className:`flex items-center gap-1 md:gap-1.5 px-2 md:px-2.5 py-1 rounded-md text-xs font-medium transition-all ${m==="conversation"?"bg-background text-primary shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[t.jsx(vr,{className:"h-3 w-3"}),t.jsx("span",{className:"hidden sm:inline",children:"Conversation"}),t.jsx("span",{className:"sm:hidden",children:"Chat"})]}),t.jsxs("button",{type:"button",onClick:()=>f("attach"),className:`flex items-center gap-1 md:gap-1.5 px-2 md:px-2.5 py-1 rounded-md text-xs font-medium transition-all ${m==="attach"?"bg-background text-primary shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[t.jsx(Ia,{className:"h-3 w-3"}),t.jsx("span",{children:"Attach"})]})]}),t.jsxs("div",{className:`flex items-center gap-1.5 shrink-0 ${m==="attach"?"hidden":""}`,children:[S?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:`h-1.5 w-1.5 rounded-full ${n==="CRASHED"?"bg-red-400/50":"bg-muted-foreground/30"}`}),t.jsx("span",{className:`text-[10px] font-mono hidden sm:inline ${n==="CRASHED"?"text-red-400/60":"text-muted-foreground/50"}`,children:n==="CRASHED"?"crashed":"ended"})]}):m==="terminal"?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:`h-1.5 w-1.5 rounded-full ${b?B==="interactive"?"bg-emerald-400 shadow-sm shadow-emerald-400/50":"bg-amber-400/80 shadow-sm shadow-amber-400/40":"bg-muted-foreground/30"}`}),t.jsx("span",{className:"text-[10px] text-muted-foreground/50 font-mono hidden sm:inline",children:b?B==="interactive"?"live":"history":"disconnected"}),!Se&&B==="interactive"?t.jsx("span",{className:"text-[10px] text-muted-foreground/35 font-mono hidden lg:inline",children:"type directly in tmux"}):null]}):null,m==="terminal"&&!S&&(B==="interactive"?t.jsxs("div",{className:"flex items-center gap-0.5",children:[t.jsx("button",{type:"button",onClick:()=>we("up",{page:!0}),className:"p-1 rounded text-muted-foreground/40 hover:text-foreground hover:bg-accent/60 transition-colors",title:"Scroll up (PageUp)",children:t.jsx(Un,{className:"h-3.5 w-3.5"})}),t.jsx("button",{type:"button",onClick:()=>void Ft(),className:"p-1 rounded text-muted-foreground/40 hover:text-foreground hover:bg-accent/60 transition-colors",title:"Search history (/)",children:t.jsx(en,{className:"h-3.5 w-3.5"})})]}):t.jsxs("div",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-md bg-amber-500/10 border border-amber-500/20",children:[t.jsx("span",{className:"text-[10px] font-mono text-amber-400 uppercase",children:B}),t.jsx("button",{type:"button",onClick:_t,className:"text-amber-400/60 hover:text-amber-400 transition-colors",title:"Exit mode (Esc)",children:t.jsx(et,{className:"h-3 w-3"})})]}))]})]}),t.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[m==="terminal"&&t.jsxs("button",{type:"button",onClick:()=>void Zr(),disabled:ge,title:fe===!1?"Unmute notifications for this session":"Mute notifications for this session",className:`flex items-center gap-1 px-2 py-1 rounded text-[10px] font-mono transition-colors ${fe===!1?"text-amber-300 bg-amber-500/10 hover:bg-amber-500/15":"text-muted-foreground/70 hover:text-foreground hover:bg-accent/60"} disabled:opacity-60`,children:[ge?t.jsx(br,{className:"h-3 w-3 animate-spin"}):fe===!1?t.jsx(na,{className:"h-3 w-3"}):t.jsx(wr,{className:"h-3 w-3"}),t.jsx("span",{className:"hidden lg:inline",children:fe===!1?"Muted":"Inherit"})]}),m==="terminal"&&!S&&t.jsxs("button",{type:"button",onClick:()=>se(h=>!h),title:je?"Hide actions":"Show actions",className:`flex items-center gap-1 px-2 py-1 rounded text-[10px] font-mono transition-colors ${je?"text-primary bg-primary/10 hover:bg-primary/15":"text-muted-foreground/60 hover:text-foreground hover:bg-accent/60"}`,children:[t.jsx(Ea,{className:"h-3 w-3"}),t.jsx(gr,{className:`h-3 w-3 transition-transform ${je?"rotate-180":""}`})]})]})]}),je&&m==="terminal"&&!S&&t.jsxs("div",{className:"flex items-center gap-1 border-b border-border/60 px-2 md:px-3 py-1.5 bg-muted/20 overflow-x-auto scrollbar-none",children:[t.jsx("span",{className:"text-[10px] text-muted-foreground/40 font-mono mr-1 shrink-0",children:"Keys"}),I.map(h=>t.jsx("button",{type:"button",onClick:()=>es(h.key),title:h.label,className:"px-1.5 py-1 rounded text-[10px] font-mono text-muted-foreground/60 hover:text-foreground active:bg-accent/80 hover:bg-accent/60 transition-colors border border-transparent hover:border-border active:border-border shrink-0",children:h.label},h.key)),t.jsx("div",{className:"w-px h-4 bg-border/40 mx-1 shrink-0"}),t.jsx("span",{className:"text-[10px] text-muted-foreground/30 font-mono shrink-0 hidden sm:inline",children:O?"Live only — use Chat for history":"Live terminal controls"})]}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[m==="terminal"?S?t.jsx(tc,{status:n||"STOPPED",sessionId:e,onResume:()=>window.location.reload(),onRecover:()=>window.location.reload(),canReviewConversation:O}):t.jsxs(t.Fragment,{children:[!x&&t.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center",style:{background:s.terminal.background||"hsl(var(--background))"},children:t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[t.jsx("div",{className:"w-4 h-4 border-2 border-primary/30 border-t-primary rounded-full animate-spin"}),t.jsx("span",{className:"text-sm font-mono",children:"Connecting to session..."})]})}),t.jsxs("div",{className:"relative h-full w-full px-1.5 pt-1.5 pb-2.5 md:p-2",onDragEnter:is,onDragOver:os,onDragLeave:ls,onDrop:cs,children:[t.jsx("div",{className:"h-full w-full overflow-hidden rounded-lg border border-border/70 shadow-[0_0_0_1px_rgba(0,0,0,0.32),0_18px_38px_rgba(0,0,0,0.2)]",children:t.jsx("div",{className:"h-full w-full",style:{background:s.terminal.background||"hsl(var(--background))"},children:t.jsx("div",{ref:c,className:"h-full w-full",style:{padding:"4px 0 0 0",touchAction:"none"},onTouchStart:ts,onTouchMove:ns,onTouchEnd:rs})})}),X&&!Se&&t.jsx("div",{className:"pointer-events-none absolute inset-3 md:inset-4 z-20 rounded-lg border border-cyan-400/60 bg-cyan-500/10 backdrop-blur-[1px] flex items-center justify-center",children:t.jsx("span",{className:"text-xs md:text-sm font-mono text-cyan-200/90",children:"Drop image(s) to attach"})})]})]}):m==="attach"?t.jsx(rc,{sessionId:e,sessionStatus:n}):O?t.jsx(sc,{sessionId:e,sessionStatus:n}):null,m==="terminal"&&!S&&!Se&&t.jsxs("div",{className:"pointer-events-none absolute bottom-4 right-4 z-20 flex flex-col items-end gap-2",children:[y&&L!==null&&t.jsxs("div",{className:"px-2 py-1 rounded-md text-[10px] font-mono border border-cyan-500/30 bg-cyan-500/10 text-cyan-300 backdrop-blur-sm",children:["uploading ",L,"%"]}),N&&t.jsx("div",{className:`px-2 py-1 rounded-md text-[10px] font-mono border backdrop-blur-sm ${N.tone==="success"?"bg-emerald-500/10 border-emerald-500/30 text-emerald-300":N.tone==="error"?"bg-red-500/10 border-red-500/30 text-red-300":"bg-cyan-500/10 border-cyan-500/30 text-cyan-300"}`,children:N.text}),$&&!y&&t.jsx("button",{type:"button",onClick:ss,className:"pointer-events-auto px-2 py-1 rounded-md text-[10px] font-mono border border-amber-500/35 bg-amber-500/10 text-amber-300 hover:bg-amber-500/15 transition-colors",children:"Retry upload"}),t.jsxs("div",{className:"pointer-events-auto flex items-center gap-2",children:[t.jsx("button",{type:"button",onClick:()=>void as(),disabled:y||!Ot,title:Ot?"Read image from clipboard":"Clipboard image read unsupported",className:"h-10 w-10 rounded-full border border-border/70 bg-card/85 text-muted-foreground/75 hover:text-foreground hover:bg-card shadow-lg shadow-black/20 backdrop-blur-sm transition-colors disabled:opacity-40 disabled:cursor-not-allowed flex items-center justify-center",children:t.jsx(ca,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:()=>{var h;return(h=d.current)==null?void 0:h.click()},disabled:y,title:`Attach image(s) (max ${gn} per add)`,className:"h-10 w-10 rounded-full border border-border/70 bg-card/85 text-muted-foreground/75 hover:text-foreground hover:bg-card shadow-lg shadow-black/20 backdrop-blur-sm transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center",children:t.jsx(Cr,{className:"h-4 w-4"})})]}),t.jsx("input",{ref:d,type:"file",multiple:!0,accept:Qr,className:"hidden",onChange:h=>{const p=Array.from(h.target.files??[]);p.length>0&&Je(p),h.target.value=""}})]}),m==="terminal"&&g&&z&&t.jsx("div",{className:"absolute left-3 right-3 bottom-3 z-30 pointer-events-none md:left-auto md:right-3 md:w-[420px]",children:t.jsxs("div",{className:"pointer-events-auto rounded-lg border border-border/70 bg-card/90 shadow-xl shadow-black/30 backdrop-blur-sm",children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-border/60 px-3 py-2",children:[t.jsx("div",{className:"text-[11px] font-mono text-foreground/90",children:"terminal diagnostics"}),t.jsx("button",{type:"button",onClick:()=>ne(!1),className:"text-[10px] font-mono text-muted-foreground/70 hover:text-foreground transition-colors",title:"Hide diagnostics",children:"close"})]}),t.jsxs("div",{className:"max-h-[40vh] overflow-auto px-3 py-2 text-[10px] font-mono text-muted-foreground/80",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-x-3 gap-y-1",children:[t.jsx("span",{children:"captured"}),t.jsx("span",{className:"text-right text-foreground/85",children:new Date(z.capturedAt).toLocaleTimeString()}),t.jsx("span",{children:"flags"}),t.jsxs("span",{className:"text-right text-foreground/85",children:["paste:",z.terminal.featureWsPtyPasteEnabled?"on":"off"," ","probes:",z.terminal.featureLatencyProbesEnabled?"on":"off"]}),t.jsx("span",{children:"ws state"}),t.jsx("span",{className:"text-right text-foreground/85",children:z.ws.connected?"connected":"disconnected"}),t.jsx("span",{children:"ws reconnect attempts"}),t.jsx("span",{className:"text-right text-foreground/85",children:z.ws.reconnectAttempts}),t.jsx("span",{children:"ws parse errors"}),t.jsx("span",{className:"text-right text-foreground/85",children:z.ws.parseErrors}),t.jsx("span",{children:"session queue"}),t.jsx("span",{className:"text-right text-foreground/85",children:z.queueDepth.pendingInputRequests}),t.jsx("span",{children:"paste queue active"}),t.jsx("span",{className:"text-right text-foreground/85",children:z.queueDepth.hasPendingPasteQueue?"yes":"no"})]}),t.jsx("div",{className:"my-2 h-px bg-border/60"}),t.jsxs("div",{className:"grid grid-cols-2 gap-x-3 gap-y-1",children:[t.jsx("span",{children:"dispatch key/text/paste"}),t.jsxs("span",{className:"text-right text-foreground/85",children:[z.terminal.keyDispatches,"/",z.terminal.textDispatches,"/",z.terminal.pasteDispatches]}),t.jsx("span",{children:"key→echo last/p95"}),t.jsxs("span",{className:"text-right text-foreground/85",children:[mt(z.terminal.keyToEchoLastMs),"/",mt(z.terminal.keyToEchoP95Ms)]}),t.jsx("span",{children:"scroll→paint last/p95"}),t.jsxs("span",{className:"text-right text-foreground/85",children:[mt(z.terminal.scrollToPaintLastMs),"/",mt(z.terminal.scrollToPaintP95Ms)]}),t.jsx("span",{children:"reconnect→resync last/p95"}),t.jsxs("span",{className:"text-right text-foreground/85",children:[mt(z.terminal.reconnectResyncLastMs),"/",mt(z.terminal.reconnectResyncP95Ms)]}),t.jsx("span",{children:"ws frames"}),t.jsx("span",{className:"text-right text-foreground/85",children:z.terminal.wsFramesReceived}),t.jsx("span",{children:"repaints full/inc"}),t.jsxs("span",{className:"text-right text-foreground/85",children:[z.terminal.fullFrameRepaints,"/",z.terminal.incrementalRepaints]}),t.jsx("span",{children:"stale drops / seq gaps"}),t.jsxs("span",{className:"text-right text-foreground/85",children:[z.terminal.staleFramesDropped,"/",z.terminal.seqGapEvents]}),t.jsx("span",{children:"replay cursor"}),t.jsx("span",{className:"text-right text-foreground/85",children:z.terminal.replayCursorSeq})]}),t.jsx("div",{className:"my-2 h-px bg-border/60"}),t.jsxs("div",{className:"grid grid-cols-2 gap-x-3 gap-y-1",children:[t.jsx("span",{children:"pty sent in/keys/paste"}),t.jsxs("span",{className:"text-right text-foreground/85",children:[z.ws.ptyInputSent,"/",z.ws.ptyKeySent,"/",z.ws.ptyPasteSent]}),t.jsx("span",{children:"pty ack in/keys/paste"}),t.jsxs("span",{className:"text-right text-foreground/85",children:[z.ws.ptyInputAcksReceived,"/",z.ws.ptyKeyAcksReceived,"/",z.ws.ptyPasteAcksReceived]}),t.jsx("span",{children:"pty err in/keys/paste"}),t.jsxs("span",{className:"text-right text-foreground/85",children:[z.ws.ptyInputErrorsReceived,"/",z.ws.ptyKeyErrorsReceived,"/",z.ws.ptyPasteErrorsReceived]}),t.jsx("span",{children:"fallback in/keys/paste"}),t.jsxs("span",{className:"text-right text-foreground/85",children:[z.ws.ptyInputFallbackTriggered,"/",z.ws.ptyKeyFallbackTriggered,"/",z.ws.ptyPasteFallbackTriggered]})]})]})]})})]}),m==="attach"?null:S?t.jsx("div",{className:"border-t border-border px-3 py-2.5 bg-card/80 backdrop-blur-sm",children:t.jsx("div",{className:"flex items-center justify-center gap-2 text-sm text-muted-foreground/50",children:t.jsxs("span",{className:"font-mono text-xs",children:["Session ",n==="CRASHED"?"crashed":"ended"]})})}):B==="scroll"?t.jsx("div",{className:"border-t border-border px-2 md:px-4 py-2 md:py-3 bg-card/80 backdrop-blur-sm",children:t.jsxs("div",{className:"flex items-center gap-1 md:gap-2",children:[G&&t.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground/50 tabular-nums shrink-0",children:[G.position,"/",G.total]}),t.jsxs("div",{className:"flex items-center bg-muted/30 rounded-md border border-border/40",children:[t.jsx("button",{type:"button",onClick:()=>we("up",{edge:"top"}),title:"Scroll to top",className:"h-8 w-8 flex items-center justify-center text-muted-foreground/60 hover:text-foreground hover:bg-accent/60 rounded-l-md transition-colors",children:t.jsx(Un,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:()=>we("up",{page:!0}),title:"Page up",className:"h-8 w-8 flex items-center justify-center text-muted-foreground/60 hover:text-foreground hover:bg-accent/60 transition-colors",children:t.jsx(Hn,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:()=>we("down",{page:!0}),title:"Page down",className:"h-8 w-8 flex items-center justify-center text-muted-foreground/60 hover:text-foreground hover:bg-accent/60 transition-colors",children:t.jsx(Bn,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:()=>we("down",{edge:"bottom"}),title:"Scroll to bottom",className:"h-8 w-8 flex items-center justify-center text-muted-foreground/60 hover:text-foreground hover:bg-accent/60 rounded-r-md transition-colors",children:t.jsx(aa,{className:"h-4 w-4"})})]}),t.jsx("button",{type:"button",onClick:()=>void Ft(),title:"Search (/)",className:"h-8 w-8 rounded-md flex items-center justify-center text-muted-foreground/60 hover:text-foreground hover:bg-accent/60 transition-colors shrink-0",children:t.jsx(en,{className:"h-3.5 w-3.5"})}),t.jsx("div",{className:"flex-1"}),t.jsxs("button",{type:"button",onClick:_t,title:"Exit scroll mode (Esc)",className:"h-8 px-2 rounded-md flex items-center gap-1 text-amber-400/70 hover:text-amber-400 bg-amber-500/5 hover:bg-amber-500/10 border border-amber-500/20 transition-colors shrink-0",children:[t.jsx(et,{className:"h-3.5 w-3.5"}),t.jsx("span",{className:"text-[10px] font-mono hidden sm:inline",children:"Esc"})]})]})}):B==="search"?t.jsx("div",{className:"border-t border-border px-2 md:px-4 py-2 md:py-3 bg-card/80 backdrop-blur-sm",children:t.jsxs("div",{className:"flex items-center gap-1 md:gap-2",children:[t.jsxs("div",{className:"flex-1 flex items-center gap-1.5 rounded-md border border-border/60 bg-muted/30 focus-within:border-amber-500/40 px-2 py-1.5 min-w-0",children:[t.jsx(en,{className:"h-3.5 w-3.5 text-amber-400/40 shrink-0"}),t.jsx("input",{ref:C,placeholder:"Search...",value:ee,onChange:h=>D(h.target.value),onKeyDown:h=>{h.key==="Enter"&&!h.shiftKey?(h.preventDefault(),ee.trim()?Yt(ee):Ue("next")):h.key==="Enter"&&h.shiftKey?(h.preventDefault(),Ue("previous")):h.key==="Escape"&&(h.preventDefault(),Ue("cancel"))},className:"flex-1 bg-transparent text-sm font-mono text-foreground placeholder:text-muted-foreground/40 outline-none min-w-0"}),G&&t.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground/40 tabular-nums shrink-0",children:[G.position,"/",G.total]})]}),t.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[t.jsx("button",{type:"button",onClick:()=>Ue("previous"),title:"Previous match (Shift+Enter)",className:"h-8 w-8 rounded-md flex items-center justify-center text-muted-foreground/60 hover:text-foreground hover:bg-accent/60 transition-colors",children:t.jsx(Hn,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:()=>Ue("next"),title:"Next match (Enter)",className:"h-8 w-8 rounded-md flex items-center justify-center text-muted-foreground/60 hover:text-foreground hover:bg-accent/60 transition-colors",children:t.jsx(Bn,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:()=>Ue("cancel"),title:"Cancel search (Esc)",className:"h-8 w-8 rounded-md flex items-center justify-center text-amber-400/70 hover:text-amber-400 hover:bg-amber-500/10 transition-colors",children:t.jsx(et,{className:"h-3.5 w-3.5"})})]})]})}):Se?t.jsx(Fl,{sessionId:e,isEnded:S}):null]})}function tc({status:e,sessionId:n,onResume:r,onRecover:s,canReviewConversation:i}){const l=e==="CRASHED",[a,c]=u.useState(!1),[o,d]=u.useState(!1),m=async()=>{try{c(!0),await A.resumeSession(n),r()}catch{c(!1)}},f=async()=>{try{d(!0),await A.recoverSession(n),s()}catch{d(!1)}};return t.jsx("div",{className:"h-full w-full flex items-center justify-center px-4 bg-background",children:t.jsxs("div",{className:"text-center",children:[t.jsx("pre",{className:`text-[10px] md:text-xs leading-tight font-mono select-none mb-4 md:mb-6 hidden sm:block ${l?"text-red-500/60":"text-muted-foreground/25"}`,children:l?`
|
|
163
|
+
██╗ ██╗
|
|
164
|
+
╚██╗██╔╝
|
|
165
|
+
╚███╔╝
|
|
166
|
+
██╔██╗
|
|
167
|
+
██╔╝ ██╗
|
|
168
|
+
╚═╝ ╚═╝`:`
|
|
169
|
+
███████╗████████╗ ██████╗ ██████╗
|
|
170
|
+
██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗
|
|
171
|
+
███████╗ ██║ ██║ ██║██████╔╝
|
|
172
|
+
╚════██║ ██║ ██║ ██║██╔═══╝
|
|
173
|
+
███████║ ██║ ╚██████╔╝██║
|
|
174
|
+
╚══════╝ ╚═╝ ╚═════╝ ╚═╝`}),t.jsx("div",{className:"sm:hidden mb-4",children:t.jsx("div",{className:`w-12 h-12 rounded-full mx-auto flex items-center justify-center ${l?"bg-red-500/10 border border-red-500/20":"bg-muted/30 border border-border"}`,children:t.jsx("span",{className:`text-lg ${l?"text-red-400/60":"text-muted-foreground/30"}`,children:l?"!":"■"})})}),t.jsx("p",{className:`text-sm font-mono mb-2 ${l?"text-red-400/70":"text-muted-foreground/40"}`,children:l?"Session crashed unexpectedly":"Session has ended"}),t.jsxs("div",{className:"mt-3 flex items-center justify-center gap-2",children:[t.jsx("button",{type:"button",onClick:m,disabled:a||o,className:"px-4 py-1.5 rounded-md text-xs font-mono text-primary border border-primary/30 bg-primary/10 hover:bg-primary/15 disabled:opacity-40 transition-colors",children:a?"Resuming...":"Resume"}),t.jsx("button",{type:"button",onClick:f,disabled:a||o,className:"px-4 py-1.5 rounded-md text-xs font-mono text-blue-300 border border-blue-400/30 bg-blue-500/10 hover:bg-blue-500/15 disabled:opacity-40 transition-colors",children:o?"Recovering...":"Recover"})]}),i&&t.jsx("p",{className:"text-xs text-muted-foreground/25 font-mono mt-3",children:"Switch to Conversation view to review the transcript"})]})})}function nc({text:e}){const[n,r]=u.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),2e3)})};return t.jsx("button",{type:"button",onClick:s,className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium bg-muted/50 hover:bg-accent/70 border border-border text-muted-foreground hover:text-foreground transition-colors shrink-0",children:n?t.jsxs(t.Fragment,{children:[t.jsx(jr,{className:"h-3 w-3 text-emerald-400"})," Copied!"]}):t.jsxs(t.Fragment,{children:[t.jsx(da,{className:"h-3 w-3"})," Copy"]})})}function fn({label:e,command:n,description:r}){return t.jsxs("div",{className:"rounded-lg border border-border bg-muted/30 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border/60 bg-muted/20",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:e}),t.jsx(nc,{text:n})]}),t.jsx("div",{className:"px-4 py-3",children:t.jsx("code",{className:"font-mono text-sm text-foreground/90 break-all",children:n})}),r&&t.jsx("p",{className:"px-4 pb-3 text-xs text-muted-foreground/60",children:r})]})}function rc({sessionId:e,sessionStatus:n}){const r=`codepiper-${e}`,s=`tmux attach-session -t ${r}`,i=`tmux detach-client -s ${r}`,l=`codepiper attach ${e}`,a=n==="STARTING"||n==="RUNNING"||n==="NEEDS_PERMISSION"||n==="NEEDS_INPUT";return t.jsx("div",{className:"h-full overflow-auto bg-background",children:t.jsxs("div",{className:"space-y-4 p-4 md:p-6 max-w-2xl",children:[!a&&t.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-amber-500/20 bg-amber-500/[0.04] px-3 py-2.5",children:[t.jsx(yr,{className:"h-4 w-4 text-amber-400 shrink-0"}),t.jsxs("span",{className:"text-xs text-amber-400/80",children:["Session is ",t.jsx("span",{className:"font-semibold",children:n})," — these commands are shown for reference but the tmux session is not currently active."]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("h2",{className:"text-xs font-semibold text-muted-foreground/70 uppercase tracking-wider",children:"Tmux (direct)"}),t.jsx(fn,{label:"Attach to tmux session",command:s,description:`Session name: ${r}`}),t.jsx(fn,{label:"Detach tmux client safely",command:i,description:"Run from another terminal to detach without stopping the session"})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("h2",{className:"text-xs font-semibold text-muted-foreground/70 uppercase tracking-wider",children:"CLI"}),t.jsx(fn,{label:"Attach via codepiper CLI",command:l,description:"Streams via WebSocket — daemon must be running"})]}),t.jsxs("div",{className:"rounded-lg border border-border/60 bg-muted/10 px-4 py-3 space-y-2",children:[t.jsx("h3",{className:"text-xs font-semibold text-muted-foreground/60 uppercase tracking-wider",children:"Tips"}),t.jsxs("ul",{className:"space-y-1.5 text-xs text-muted-foreground/70",children:[t.jsxs("li",{className:"flex items-start gap-2",children:[t.jsx("span",{className:"text-primary/60 mt-0.5 shrink-0 text-[8px]",children:"●"}),t.jsxs("span",{children:["To detach without stopping the session, press"," ",t.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-muted border border-border font-mono text-[11px] text-foreground/80",children:"Ctrl+B"})," ","then"," ",t.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-muted border border-border font-mono text-[11px] text-foreground/80",children:"D"})]})]}),t.jsxs("li",{className:"flex items-start gap-2",children:[t.jsx("span",{className:"text-primary/60 mt-0.5 shrink-0 text-[8px]",children:"●"}),t.jsxs("span",{children:["Typing ",t.jsx("code",{className:"font-mono",children:"exit"})," (or pressing"," ",t.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-muted border border-border font-mono text-[11px] text-foreground/80",children:"Ctrl+D"}),") stops the underlying session process."]})]}),t.jsxs("li",{className:"flex items-start gap-2",children:[t.jsx("span",{className:"text-primary/60 mt-0.5 shrink-0 text-[8px]",children:"●"}),t.jsx("span",{children:"For remote access, use SSH port forwarding:"})]}),t.jsx("li",{className:"ml-5",children:t.jsxs("code",{className:"font-mono text-xs text-primary/80 bg-primary/10 px-1.5 py-0.5 rounded border border-primary/20",children:["ssh user@host -t tmux attach-session -t ",r]})})]})]})]})})}function sc({sessionId:e,sessionStatus:n}){const{events:r,loading:s,loadingMore:i,hasMore:l,sentinelRef:a}=Nn({sessionId:e,source:"transcript",order:"desc",poll:!0,pollInterval:3e3}),c=u.useMemo(()=>uc(r),[r]),o=u.useRef(null),[d,m]=u.useState(new Set),f=u.useRef(0),b=u.useRef(0),w=u.useRef(!1),x=u.useRef(!1);u.useEffect(()=>{const y=o.current;if(!y)return;const R=()=>{const L=y.scrollHeight-y.scrollTop-y.clientHeight;w.current=L>60};return y.addEventListener("scroll",R,{passive:!0}),()=>y.removeEventListener("scroll",R)},[]),u.useLayoutEffect(()=>{const y=o.current;if(!y||s)return;if(!x.current&&c.length>0){y.scrollTop=y.scrollHeight,x.current=!0,f.current=c.length,b.current=y.scrollHeight;return}const R=c.length;if(R-f.current>0)if(w.current){const _=y.scrollHeight-b.current;_>0&&(y.scrollTop+=_)}else y.scrollTop=y.scrollHeight;f.current=R,b.current=y.scrollHeight},[c,s]);const k=y=>{m(R=>{const L=new Set(R);return L.has(y)?L.delete(y):L.add(y),L})};if(s)return t.jsx("div",{className:"flex items-center justify-center h-full bg-background",children:t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[t.jsx("div",{className:"w-4 h-4 border-2 border-primary/30 border-t-primary rounded-full animate-spin"}),t.jsx("span",{className:"text-sm",children:"Loading conversation..."})]})});if(c.length===0)return t.jsx("div",{className:"flex items-center justify-center h-full bg-background",children:t.jsxs("div",{className:"text-center",children:[t.jsx(vr,{className:"h-8 w-8 text-muted-foreground/20 mx-auto mb-3"}),t.jsx("p",{className:"text-sm text-muted-foreground/60",children:"No conversation data yet."}),t.jsx("p",{className:"text-xs text-muted-foreground/40 mt-1",children:"Send a message to get started."})]})});const N=n==="STOPPED"||n==="CRASHED",v=n==="CRASHED";return t.jsx("div",{ref:o,className:"h-full overflow-auto bg-background",children:t.jsxs("div",{className:"max-w-4xl mx-auto py-4 md:py-6 px-3 md:px-4 space-y-1",children:[l&&t.jsx("div",{ref:a,className:"flex items-center justify-center py-3",children:i?t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[t.jsx("div",{className:"w-4 h-4 border-2 border-primary/30 border-t-primary rounded-full animate-spin"}),t.jsx("span",{className:"text-xs",children:"Loading older messages..."})]}):t.jsx("span",{className:"text-xs text-muted-foreground/30",children:"Scroll up for more"})}),c.map((y,R)=>t.jsx("div",{children:y.role==="user"?t.jsx(ac,{content:y.content,timestamp:y.timestamp}):y.role==="assistant"?t.jsx(ic,{content:y.content,thinkingContent:y.thinkingContent,toolUses:y.toolUses,toolResults:y.toolResults,tokens:y.tokens,costUsd:y.costUsd,model:y.model,timestamp:y.timestamp,expandedTools:d,onToggleTool:k,msgIndex:R}):y.role==="command"?t.jsx(lc,{commandName:y.commandName||"",commandArgs:y.commandArgs,stdout:y.commandStdout,stderr:y.commandStderr,timestamp:y.timestamp}):t.jsx(oc,{content:y.content,timestamp:y.timestamp})},R)),N&&c.length>0&&t.jsx("div",{className:"pt-6 pb-2",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"flex-1 h-px bg-border"}),t.jsx("span",{className:`text-xs font-mono px-3 py-1 rounded-full border ${v?"text-red-400/70 border-red-500/20 bg-red-500/5":"text-muted-foreground/40 border-border bg-muted/30"}`,children:v?"session crashed":"session ended"}),t.jsx("div",{className:"flex-1 h-px bg-border"})]})})]})})}function ac({content:e,timestamp:n}){return t.jsxs("div",{className:"py-4",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("div",{className:"w-6 h-6 rounded-full bg-primary/15 border border-primary/20 flex items-center justify-center",children:t.jsx("span",{className:"text-[10px] text-primary font-bold",children:"U"})}),t.jsx("span",{className:"text-sm font-semibold text-primary",children:"You"}),t.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:Wt(n)})]}),t.jsx("div",{className:"ml-8 text-sm whitespace-pre-wrap leading-relaxed",children:e})]})}function ic({content:e,thinkingContent:n,toolUses:r,toolResults:s,tokens:i,costUsd:l,model:a,timestamp:c,expandedTools:o,onToggleTool:d,msgIndex:m}){return t.jsxs("div",{className:"py-4",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("div",{className:"w-6 h-6 rounded-full bg-violet-500/15 border border-violet-500/20 flex items-center justify-center",children:t.jsx("span",{className:"text-[10px] text-violet-400 font-bold",children:"C"})}),t.jsx("span",{className:"text-sm font-semibold text-violet-400",children:"Claude"}),t.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:Wt(c)}),a&&t.jsx("span",{className:"text-[10px] bg-muted/50 border border-border px-1.5 py-0.5 rounded font-mono",children:a})]}),t.jsxs("div",{className:"ml-8 space-y-3",children:[n&&t.jsxs("details",{className:"group",children:[t.jsxs("summary",{className:"text-xs text-muted-foreground/60 cursor-pointer hover:text-muted-foreground select-none flex items-center gap-1",children:[t.jsx(xt,{className:"h-3 w-3 transition-transform group-open:rotate-90"}),"Thinking..."]}),t.jsx("div",{className:"mt-2 text-xs text-muted-foreground/70 bg-muted/30 rounded-lg p-3 border-l-2 border-violet-500/20 whitespace-pre-wrap max-h-40 overflow-auto",children:n})]}),r.map((f,b)=>{const w=`${m}-tool-${b}`,x=o.has(w),k=s[b];return t.jsxs("div",{className:"rounded-lg overflow-hidden border border-border bg-muted/30",children:[t.jsxs("button",{type:"button",onClick:()=>d(w),className:"w-full flex items-center gap-2 px-3 py-2 text-xs hover:bg-accent/50 transition-colors",children:[t.jsx(xt,{className:`h-3 w-3 text-muted-foreground transition-transform ${x?"rotate-90":""}`}),t.jsx("span",{className:"font-medium text-primary font-mono",children:f.name}),(k==null?void 0:k.isError)&&t.jsx("span",{className:"text-red-400 text-[10px]",children:"(error)"})]}),x&&t.jsxs("div",{className:"border-t border-border",children:[t.jsxs("div",{className:"px-3 py-2",children:[t.jsx("div",{className:"text-[10px] text-muted-foreground/60 mb-1 uppercase tracking-wider",children:"Input"}),t.jsx("pre",{className:"text-xs bg-muted p-2 rounded-md overflow-x-auto max-h-48 overflow-y-auto font-mono",children:f.input})]}),k&&t.jsxs("div",{className:"px-3 py-2 border-t border-border/60",children:[t.jsx("div",{className:"text-[10px] text-muted-foreground/60 mb-1 uppercase tracking-wider",children:"Output"}),t.jsx("pre",{className:`text-xs p-2 rounded-md overflow-x-auto max-h-48 overflow-y-auto font-mono ${k.isError?"bg-red-500/[0.05] text-red-300":"bg-muted"}`,children:pc(k.content,2e3)})]})]})]},w)}),e&&t.jsx(wl,{content:e}),i&&t.jsxs("div",{className:"flex gap-3 text-[11px] text-muted-foreground/50 font-mono",children:[t.jsxs("span",{children:[i.input.toLocaleString()," in"]}),t.jsxs("span",{children:[i.output.toLocaleString()," out"]}),l!==void 0&&l>0&&t.jsxs("span",{children:["$",l.toFixed(4)]})]})]})]})}function oc({content:e,timestamp:n}){return t.jsxs("div",{className:"py-2 px-3 text-xs text-muted-foreground/60 flex items-center gap-2 border-l-2 border-amber-500/20 ml-8",children:[t.jsx("span",{className:"font-medium text-amber-400/80 text-[10px] uppercase tracking-wider",children:"system"}),t.jsx("span",{children:e}),t.jsx("span",{className:"ml-auto text-[10px]",children:Wt(n)})]})}function lc({commandName:e,commandArgs:n,stdout:r,stderr:s,timestamp:i}){return t.jsxs("div",{className:"py-2 ml-8",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(xt,{className:"h-3 w-3 text-muted-foreground/40"}),t.jsx("code",{className:"text-sm font-mono font-semibold text-primary",children:e}),n&&t.jsx("span",{className:"text-sm font-mono text-muted-foreground/70",children:n}),t.jsx("span",{className:"text-[10px] text-muted-foreground/40 ml-auto",children:Wt(i)})]}),r&&t.jsx("div",{className:"ml-5 mt-1 text-sm text-muted-foreground/80 font-mono whitespace-pre-wrap border-l-2 border-border/40 pl-3",children:r}),s&&t.jsx("div",{className:"ml-5 mt-1 text-sm text-red-400/80 font-mono whitespace-pre-wrap border-l-2 border-red-500/30 pl-3",children:s})]})}function qt(e){return e.replace(/\x1b\[[0-9;]*[a-zA-Z]/g,"")}function ze(e,n){const r=`<${n}>`,s=`</${n}>`,i=e.indexOf(r),l=e.indexOf(s);return i===-1||l===-1?null:e.slice(i+r.length,l).trim()}function Ge(e,n){return e.includes(`<${n}>`)}function vn(e){let n=e;for(;n.includes("<system-reminder>");){const r=n.indexOf("<system-reminder>"),s=n.indexOf("</system-reminder>");if(s===-1)break;n=n.slice(0,r)+n.slice(s+18)}return n.trim()}function cc(e){return ze(e,"persisted-output")||e}function uc(e){var s,i,l,a,c,o;const n=[],r=e.filter(d=>d.source==="transcript").sort((d,m)=>{const f=typeof d.timestamp=="string"?new Date(d.timestamp).getTime():d.timestamp,b=typeof m.timestamp=="string"?new Date(m.timestamp).getTime():m.timestamp;return f-b});for(const d of r){const m=typeof d.payload=="string"?JSON.parse(d.payload):d.payload,f=typeof d.timestamp=="string"?new Date(d.timestamp):new Date(d.timestamp),b=d.type||m.type;if(!m.isMeta){if(b==="user"){const w=dc(((s=m.message)==null?void 0:s.content)||m.content);if(Ge(w,"local-command-caveat"))continue;if(Ge(w,"command-name")){const N=ze(w,"command-name")||"",v=ze(w,"command-args")||"";n.push({role:"command",content:"",commandName:N,commandArgs:v||void 0,toolUses:[],toolResults:[],timestamp:f});continue}if(Ge(w,"local-command-stdout")){const N=qt(ze(w,"local-command-stdout")||""),v=n[n.length-1];(v==null?void 0:v.role)==="command"&&(v.commandStdout=N);continue}if(Ge(w,"local-command-stderr")){const N=qt(ze(w,"local-command-stderr")||""),v=n[n.length-1];(v==null?void 0:v.role)==="command"&&(v.commandStderr=N);continue}const x=((i=m.message)==null?void 0:i.content)||m.content,k=hn(x);k&&n.push({role:"user",content:vn(k),toolUses:[],toolResults:hc(x),timestamp:f})}else if(b==="assistant"){const w=((l=m.message)==null?void 0:l.content)||m.content,x=hn(w),k=mc(w),N=fc(w),v=((a=m.message)==null?void 0:a.usage)||m.usage;n.push({role:"assistant",content:x,thinkingContent:k,toolUses:N,toolResults:[],timestamp:f,tokens:v?{input:v.input_tokens||0,output:v.output_tokens||0}:void 0,costUsd:m.costUSD||m.cost_usd,model:((c=m.message)==null?void 0:c.model)||m.model})}else if(b==="system"){const w=m.subtype;if(w==="turn_duration"||w==="stop_hook_summary")continue;const x=m.content||"";if(w==="local_command"){if(Ge(x,"command-name")){const N=ze(x,"command-name")||"",v=ze(x,"command-args")||"";n.push({role:"command",content:"",commandName:N,commandArgs:v||void 0,toolUses:[],toolResults:[],timestamp:f});continue}if(Ge(x,"local-command-stdout")){const N=qt(ze(x,"local-command-stdout")||""),v=n[n.length-1];(v==null?void 0:v.role)==="command"&&(v.commandStdout=N);continue}if(Ge(x,"local-command-stderr")){const N=qt(ze(x,"local-command-stderr")||""),v=n[n.length-1];(v==null?void 0:v.role)==="command"&&(v.commandStderr=N);continue}}if(w==="compact_boundary"){n.push({role:"system",content:"Conversation compacted",toolUses:[],toolResults:[],timestamp:f});continue}const k=hn(((o=m.message)==null?void 0:o.content)||m.content||m.text);k&&n.push({role:"system",content:vn(k),toolUses:[],toolResults:[],timestamp:f})}}}return n}function dc(e){return e?typeof e=="string"?e:Array.isArray(e)?e.map(n=>typeof n=="string"?n:n.type==="text"?n.text||"":n.type==="tool_result"&&typeof n.content=="string"?n.content:"").join(`
|
|
175
|
+
`):"":""}function hn(e){return e?typeof e=="string"?e:Array.isArray(e)?e.filter(n=>n.type==="text").map(n=>n.text||"").join(`
|
|
176
|
+
`).trim():typeof e=="object"&&e!==null&&"text"in e?e.text:"":""}function mc(e){return Array.isArray(e)&&e.filter(r=>r.type==="thinking").map(r=>r.thinking||r.text||"").join(`
|
|
177
|
+
`).trim()||void 0}function fc(e){return Array.isArray(e)?e.filter(n=>n.type==="tool_use").map(n=>({name:n.name||"unknown",input:typeof n.input=="string"?n.input:JSON.stringify(n.input,null,2)})):[]}function hc(e){return Array.isArray(e)?e.filter(n=>n.type==="tool_result").map(n=>{let r="";return typeof n.content=="string"?r=n.content:Array.isArray(n.content)&&(r=n.content.map(s=>typeof s=="string"?s:s.text||JSON.stringify(s)).join(`
|
|
178
|
+
`)),r=vn(r),Ge(r,"persisted-output")&&(r=cc(r)),{toolName:n.tool_use_id||"unknown",content:r,isError:n.is_error}}):[]}function Wt(e){return e.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function pc(e,n){return e.length<=n?e:`${e.slice(0,n)}
|
|
179
|
+
... (truncated)`}const xc={terminal:"Terminal",git:"Git",policies:"Policies",logs:"Logs",events:"Events"};function Sc(){const{id:e,tab:n}=ks(),r=js(),{sessions:s,refresh:i}=Ts(),{counts:l}=As(),[a,c]=u.useState(null),[o,d]=u.useState(null),[m,f]=u.useState(!0),[b,w]=u.useState(!1),[x,k]=u.useState(""),[N,v]=u.useState(!1),[y,R]=u.useState([...Ms]),L=u.useMemo(()=>a?Ps(a.provider,y):Ds,[y,a]),_=u.useMemo(()=>a?Ls(_s(a.provider,y).capabilities):!0,[y,a]),$=n&&L.includes(n)?n:L[0]??"terminal",Q=u.useMemo(()=>Fs(s),[s]),X=u.useMemo(()=>a?zs(a):null,[a]),de=u.useMemo(()=>a?$s(a,Q):"",[a,Q]);u.useEffect(()=>{let D=!1;return A.getProviders().then(G=>{D||G.providers.length===0||R(G.providers)}).catch(()=>{}),()=>{D=!0}},[]),u.useEffect(()=>{e&&(!n||n!==$)&&r(`/sessions/${e}/${$}`,{replace:!0})},[$,e,r,n]);const g=u.useCallback(D=>{r(`/sessions/${e}/${D}`,{replace:!0})},[e,r]);u.useEffect(()=>{if(!e)return;const D=async()=>{try{f(!0);const C=await A.getSession(e);c(C.session)}catch(C){q.error(C instanceof Error?C.message:"Failed to fetch session"),r("/sessions")}finally{f(!1)}},G=async()=>{try{const C=await A.getGitStatus(e);d(C.branch||null)}catch{}};D(),G();const pe=setInterval(async()=>{try{const C=await A.getSession(e);c(C.session)}catch{}G()},5e3);return()=>clearInterval(pe)},[e,r]),u.useEffect(()=>{if(!e)return;let D=null;const G=()=>{document.visibilityState==="visible"&&(D&&clearTimeout(D),D=setTimeout(()=>{A.markNotificationsRead({sessionId:e,readSource:"open_session"}).catch(()=>{})},1200))};G();const pe=()=>{G()},C=()=>{document.visibilityState==="visible"&&G()};return window.addEventListener("focus",pe),document.addEventListener("visibilitychange",C),()=>{D&&clearTimeout(D),window.removeEventListener("focus",pe),document.removeEventListener("visibilitychange",C)}},[e]),u.useEffect(()=>{b||k(X??"")},[b,X]);const ne=async()=>{if(e)try{await A.stopSession(e),q.success("Session stopped");const D=await A.getSession(e);c(D.session)}catch(D){q.error(D instanceof Error?D.message:"Failed to stop session")}},re=async()=>{if(e)try{await A.killSession(e),q.success("Session killed");const D=await A.getSession(e);c(D.session)}catch(D){q.error(D instanceof Error?D.message:"Failed to kill session")}},ye=async()=>{if(e)try{const D=await A.resumeSession(e);q.success("Session resumed"),c(D.session)}catch(D){q.error(D instanceof Error?D.message:"Failed to resume session")}},fe=async()=>{if(e)try{const D=await A.recoverSession(e);q.success("Session recovered"),c(D.session)}catch(D){q.error(D instanceof Error?D.message:"Failed to recover session")}},Me=u.useCallback(()=>{a&&(k(X??""),w(!0))},[a,X]),ge=u.useCallback(()=>{k(X??""),w(!1)},[X]),me=u.useCallback(async()=>{if(!(a&&e)||N)return;const D=x.trim();v(!0);try{const G=await A.updateSessionName(e,{name:D.length>0?D:null});c(G.session),w(!1),await i(),q.success(D.length>0?"Session name updated":"Session name reset")}catch(G){q.error(G instanceof Error?G.message:"Failed to update session name")}finally{v(!1)}},[e,x,i,N,a]),je=D=>{switch(qs(D)){case"green":return"success";case"yellow":return"warning";case"red":return"destructive";case"blue":case"cyan":return"default";default:return"secondary"}};if(m)return t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[t.jsx("div",{className:"w-4 h-4 border-2 border-primary/30 border-t-primary rounded-full animate-spin"}),t.jsx("span",{className:"text-sm",children:"Loading session..."})]})});if(!a)return t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"text-muted-foreground mb-3",children:"Session not found"}),t.jsx("button",{type:"button",onClick:()=>r("/sessions"),className:"text-sm text-primary hover:underline",children:"Back to sessions"})]})});const se=a.status==="RUNNING"||a.status==="STARTING",B=a.status!=="STOPPED"&&a.status!=="CRASHED",Ee=a.status==="STOPPED"||a.status==="CRASHED",V=a.status==="STOPPED"||a.status==="CRASHED",Re=a.status==="RUNNING"||a.status==="STARTING",ee=l.bySession[a.id]??0;return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsx("div",{className:"border-b border-border px-4 md:px-6 py-2 md:py-5 pt-safe md:pt-5 bg-gradient-to-b from-primary/10 via-primary/[0.04] to-transparent",children:t.jsxs("div",{className:"flex items-start justify-between gap-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 md:gap-3 md:mb-2 flex-wrap",children:[t.jsxs("button",{type:"button",onClick:()=>r("/sessions"),className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[t.jsx(kr,{className:"h-4 w-4"}),t.jsx("span",{className:"hidden sm:inline",children:"Sessions"})]}),t.jsx("span",{className:"text-muted-foreground/30 hidden sm:inline",children:"/"}),b?t.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[t.jsx(Is,{value:x,onChange:D=>k(D.target.value),onKeyDown:D=>{D.key==="Enter"&&(D.preventDefault(),me()),D.key==="Escape"&&(D.preventDefault(),ge())},disabled:N,placeholder:Os(a.cwd),className:"h-8 w-[170px] md:w-[250px] text-sm",maxLength:80,autoFocus:!0}),t.jsx(Ke,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>void me(),disabled:N,children:t.jsx(jr,{className:"h-4 w-4"})}),t.jsx(Ke,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8",onClick:ge,disabled:N,children:t.jsx(et,{className:"h-4 w-4"})})]}):t.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[t.jsx("h1",{className:"text-base md:text-lg font-semibold truncate max-w-[210px] md:max-w-[360px]",children:de}),t.jsx(Ke,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:Me,"aria-label":"Rename session",children:t.jsx(Ks,{className:"h-3.5 w-3.5"})})]}),t.jsx(Et,{variant:"outline",className:"font-mono text-[10px] shrink-0",children:Bs(a.id,8)}),t.jsx(Hs,{provider:a.provider}),t.jsxs(Et,{variant:je(a.status),className:"shrink-0",children:[Re&&t.jsx(Nr,{className:"h-1.5 w-1.5 fill-current mr-1.5 pulse-live"}),a.status]}),ee>0&&t.jsxs(Et,{variant:"warning",className:"shrink-0",children:[t.jsx(wr,{className:"h-3 w-3 mr-1"}),ee>99?"99+":ee," unread"]})]}),t.jsxs("div",{className:"hidden md:flex items-center gap-2 text-sm text-muted-foreground flex-wrap",children:[t.jsx("span",{className:"font-mono text-xs truncate",children:a.cwd}),t.jsx("span",{className:"text-border",children:"·"}),t.jsxs("span",{children:["Created ",Gt(a.createdAt)]}),a.pid&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-border",children:"·"}),t.jsxs("span",{className:"font-mono text-xs",children:["PID: ",a.pid]})]}),o&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-border",children:"·"}),t.jsxs("span",{className:"font-mono text-xs inline-flex items-center gap-1",children:[t.jsx(jn,{className:"h-3 w-3"}),o]})]})]})]}),t.jsxs("div",{className:"flex gap-1.5 md:gap-2 shrink-0",children:[t.jsx(Us,{className:"md:hidden h-9 w-9 border border-border bg-background/80 hover:bg-accent/80"}),Ee&&t.jsxs(Ke,{variant:"outline",size:"sm",onClick:ye,className:"border-primary/30 text-primary hover:bg-primary/10 text-xs md:text-sm h-8",children:[t.jsx(qn,{className:"h-3 w-3 mr-1"}),t.jsx("span",{className:"hidden sm:inline",children:"Resume"})]}),V&&t.jsxs(Ke,{variant:"outline",size:"sm",onClick:fe,className:"border-blue-500/30 text-blue-400 hover:bg-blue-500/10 text-xs md:text-sm h-8",children:[t.jsx(qn,{className:"h-3 w-3 mr-1"}),t.jsx("span",{className:"hidden sm:inline",children:"Recover"})]}),t.jsxs(Ke,{variant:"outline",size:"sm",onClick:ne,disabled:!se,className:"border-border hover:bg-accent/60 text-xs md:text-sm h-8",children:[t.jsx(Ba,{className:"h-3 w-3 mr-1"}),t.jsx("span",{className:"hidden sm:inline",children:"Stop"})]}),t.jsxs(Ke,{variant:"destructive",size:"sm",onClick:re,disabled:!B,className:"text-xs md:text-sm h-8",children:[t.jsx(Pa,{className:"h-3 w-3 mr-1"}),t.jsx("span",{className:"hidden sm:inline",children:"Kill"})]})]})]})}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsxs(Qs,{value:$,onValueChange:g,className:"h-full flex flex-col",children:[t.jsx("div",{className:"border-b border-border px-4 md:px-6 overflow-x-auto scrollbar-none",children:t.jsx(Ys,{className:"bg-transparent h-8 md:h-10 gap-0",children:L.map(D=>t.jsx(Xs,{value:D,className:"relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:text-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none text-muted-foreground hover:text-foreground px-3 md:px-4 text-xs md:text-sm transition-colors capitalize",children:xc[D]},D))})}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-auto",children:[t.jsx(kt,{value:"terminal",className:"h-full m-0",children:t.jsx(ec,{sessionId:a.id,sessionStatus:a.status,supportsConversationView:_})}),t.jsx(kt,{value:"policies",className:"h-full m-0",children:t.jsx(li,{sessionId:a.id})}),t.jsx(kt,{value:"git",className:"h-full m-0",children:t.jsx(si,{sessionId:a.id,cwd:a.cwd})}),L.includes("logs")&&t.jsx(kt,{value:"logs",className:"h-full m-0",children:t.jsx(ii,{sessionId:a.id})}),L.includes("events")&&t.jsx(kt,{value:"events",className:"h-full m-0",children:t.jsx(Va,{sessionId:a.id})})]})]})})]})}export{Sc as SessionDetailPage};
|