@tom2012/cc-web 2026.5.15-c → 2026.5.15-e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/backend/dist/tracks/__tests__/verify-starter-templates.d.ts +17 -0
- package/backend/dist/tracks/__tests__/verify-starter-templates.d.ts.map +1 -0
- package/backend/dist/tracks/__tests__/verify-starter-templates.js +100 -0
- package/backend/dist/tracks/__tests__/verify-starter-templates.js.map +1 -0
- package/backend/dist/tracks/ccweb-train-adapter.d.ts +1 -1
- package/backend/dist/tracks/ccweb-train-adapter.d.ts.map +1 -1
- package/backend/dist/tracks/registry.d.ts +9 -4
- package/backend/dist/tracks/registry.d.ts.map +1 -1
- package/backend/dist/tracks/registry.js +1 -6
- package/backend/dist/tracks/registry.js.map +1 -1
- package/backend/dist/tracks/train-loader.d.ts +2 -2
- package/backend/dist/tracks/train-loader.js +2 -2
- package/backend/dist/tracks/train-loader.js.map +1 -1
- package/backend/dist/tracks/types-train.d.ts +2 -2
- package/backend/dist/tracks/types-train.d.ts.map +1 -1
- package/backend/dist/tracks/types-train.js +1 -1
- package/backend/dist/tracks/types.d.ts +1 -1
- package/backend/dist/tracks/types.js +1 -1
- package/backend/package-lock.json +20 -6
- package/backend/package.json +2 -2
- package/backend/vendor/{@train-lang/adapter-spec → @tom2012/train-adapter-spec}/dist/index.d.ts +2 -2
- package/backend/vendor/{@train-lang/adapter-spec → @tom2012/train-adapter-spec}/dist/index.js +2 -2
- package/backend/vendor/{@train-lang/adapter-spec → @tom2012/train-adapter-spec}/package.json +1 -1
- package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/index.d.ts +1 -1
- package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/index.js +1 -1
- package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/interpreter.d.ts +1 -1
- package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/interpreter.d.ts.map +1 -1
- package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/prompt-composer.d.ts +1 -1
- package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/prompt-composer.d.ts.map +1 -1
- package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/type-descriptor.d.ts +1 -1
- package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/type-descriptor.d.ts.map +1 -1
- package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/validation.d.ts +1 -1
- package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/validation.d.ts.map +1 -1
- package/backend/vendor/{@train-lang/core → @tom2012/train-core}/package.json +2 -2
- package/frontend/dist/assets/{ChatOverlay-DBAaKxpk.js → ChatOverlay-DkGLWbKQ.js} +1 -1
- package/frontend/dist/assets/{GraphPreview-Dy7HORfK.js → GraphPreview-DXZ3AviI.js} +1 -1
- package/frontend/dist/assets/{MobilePage-BYF500R6.js → MobilePage-_j-29xar.js} +3 -3
- package/frontend/dist/assets/{OfficePreview-B02NSffO.js → OfficePreview-v7w2uAKM.js} +2 -2
- package/frontend/dist/assets/{PdfPreview-b-0jofp4.js → PdfPreview-DzW3MlNU.js} +1 -1
- package/frontend/dist/assets/{ProjectPage-Cx3Bjyrr.js → ProjectPage-BQG5oG4t.js} +4 -4
- package/frontend/dist/assets/{SettingsPage-BxJJbfOI.js → SettingsPage-C23Lj2v_.js} +1 -1
- package/frontend/dist/assets/{SkillHubPage-LXCaSUZy.js → SkillHubPage-BGND7gBE.js} +1 -1
- package/frontend/dist/assets/{TrackEditor-CCPaBF-8.js → TrackEditor-D1fPK_Jb.js} +3 -3
- package/frontend/dist/assets/{chevron-down-Cds062oX.js → chevron-down-P2HTs96y.js} +1 -1
- package/frontend/dist/assets/{cssMode-BvkyBi_1.js → cssMode-DRf316-W.js} +1 -1
- package/frontend/dist/assets/{editor.main-B3ltxoX3.js → editor.main-BKXLd7u4.js} +7 -7
- package/frontend/dist/assets/{freemarker2-DIwmrs2R.js → freemarker2-HzFVoxpO.js} +1 -1
- package/frontend/dist/assets/{handlebars-DPCeFkqV.js → handlebars-DZuTrvH7.js} +1 -1
- package/frontend/dist/assets/{html-BVSttFGy.js → html-CFuwEHaY.js} +1 -1
- package/frontend/dist/assets/{htmlMode-CAW8JFGZ.js → htmlMode-GZ3cIkqy.js} +1 -1
- package/frontend/dist/assets/{index-D7m-ZPJS.js → index-CkkbnVk_.js} +1 -1
- package/frontend/dist/assets/{index-C9GRzN9U.js → index-DCWtUdhh.js} +1 -1
- package/frontend/dist/assets/{index-BcDSbsMw.js → index-DeWj_k0E.js} +2 -2
- package/frontend/dist/assets/{index-DyGxo5eZ.js → index-z4MFC7Mu.js} +1 -1
- package/frontend/dist/assets/{javascript-CRs_tnHJ.js → javascript-BG0wx3op.js} +1 -1
- package/frontend/dist/assets/{jsonMode-DeHogVoG.js → jsonMode-BfaBjVRh.js} +1 -1
- package/frontend/dist/assets/{jszip.min-B9mDszFR.js → jszip.min-BXZEE3jp.js} +1 -1
- package/frontend/dist/assets/{liquid-B9waY8_8.js → liquid-C56X6aBB.js} +1 -1
- package/frontend/dist/assets/{mdx-j0v6bMGt.js → mdx-Cw1KN-mJ.js} +1 -1
- package/frontend/dist/assets/{python-tGJySRw0.js → python-BjnRAFHZ.js} +1 -1
- package/frontend/dist/assets/{razor-CqwziRNu.js → razor-DmrYXNRF.js} +1 -1
- package/frontend/dist/assets/{select-CjGfDFOO.js → select-DAoeCy88.js} +1 -1
- package/frontend/dist/assets/{tsMode-WCbZkYd8.js → tsMode-hkEzrc7F.js} +1 -1
- package/frontend/dist/assets/{typescript-PmucNcni.js → typescript-CHfVHnEC.js} +1 -1
- package/frontend/dist/assets/{user-CRCXTKE-.js → user-CRCDBTUo.js} +1 -1
- package/frontend/dist/assets/{xml-CAoeE6X-.js → xml-Cs-AR0XK.js} +1 -1
- package/frontend/dist/assets/{yaml-C_AXAjyw.js → yaml-C3YNUfzf.js} +1 -1
- package/frontend/dist/index.html +1 -1
- package/package.json +1 -1
- /package/backend/vendor/{@train-lang/adapter-spec → @tom2012/train-adapter-spec}/dist/index.d.ts.map +0 -0
- /package/backend/vendor/{@train-lang/adapter-spec → @tom2012/train-adapter-spec}/dist/index.js.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/ast-cache.d.ts +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/ast-cache.d.ts.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/ast-cache.js +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/ast-cache.js.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/ast.d.ts +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/ast.d.ts.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/ast.js +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/ast.js.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/builder.d.ts +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/builder.d.ts.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/builder.js +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/builder.js.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/builtins.d.ts +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/builtins.d.ts.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/builtins.js +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/builtins.js.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/index.d.ts.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/index.js.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/interpreter.js +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/interpreter.js.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/lexer.d.ts +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/lexer.d.ts.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/lexer.js +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/lexer.js.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/module-loader.d.ts +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/module-loader.d.ts.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/module-loader.js +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/module-loader.js.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/parser.d.ts +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/parser.d.ts.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/parser.js +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/parser.js.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/prompt-composer.js +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/prompt-composer.js.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/runtime.d.ts +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/runtime.d.ts.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/runtime.js +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/runtime.js.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/type-descriptor.js +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/type-descriptor.js.map +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/validation.js +0 -0
- /package/backend/vendor/{@train-lang/core → @tom2012/train-core}/dist/validation.js.map +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/GraphPreview-
|
|
2
|
-
var e,t,s,i,r,n;import{c as o,u as a,r as l,a as h,g as c,b as d,w as u,t as f,j as _,d as m,E as p,P as g,M as v,e as x,f as b,X as S,h as w,i as y,S as C,W as k,_ as N,s as j,k as E,l as M,D,T as R,R as L,F as P,m as T,n as B,C as I,o as O,A,p as z,q as W,v as H,B as F,x as $,y as K,I as U,z as V,G as q,H as Y,J as G,K as X,L as J,N as Z,O as Q,Q as ee,U as te,V as se,Y as ie,Z as re,$ as ne,a0 as oe,a1 as ae,a2 as le,a3 as he,a4 as ce,a5 as de,a6 as ue,a7 as fe,a8 as _e,a9 as me,aa as pe,ab as ge,ac as ve,ad as xe,ae as be,af as Se,ag as we,ah as ye,ai as Ce,aj as ke,ak as Ne,al as je,am as Ee,an as Me,ao as De,ap as Re,aq as Le,ar as Pe,as as Te,at as Be,au as Ie,av as Oe,aw as Ae,ax as ze,ay as We,az as He,aA as Fe,aB as $e,aC as Ke,aD as Ue,aE as Ve,aF as qe,aG as Ye,aH as Ge,aI as Xe,aJ as Je,aK as Ze,aL as Qe,aM as et,aN as tt,aO as st,aP as it,aQ as rt,aR as nt,aS as ot,aT as at,aU as lt,aV as ht,aW as ct,aX as dt,aY as ut}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/GraphPreview-DXZ3AviI.js","assets/index-DeWj_k0E.js","assets/index-BmPb0Wl1.css","assets/purify.es-CgRAQgUo.js","assets/ChatOverlay-DkGLWbKQ.js","assets/chevron-down-P2HTs96y.js","assets/index-CkkbnVk_.js","assets/ChatOverlay-wklAmtGL.css","assets/select-DAoeCy88.js","assets/user-CRCDBTUo.js","assets/OfficePreview-v7w2uAKM.js","assets/PdfPreview-DzW3MlNU.js","assets/PdfPreview-Bu5q60D-.css","assets/TrackEditor-D1fPK_Jb.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var e,t,s,i,r,n;import{c as o,u as a,r as l,a as h,g as c,b as d,w as u,t as f,j as _,d as m,E as p,P as g,M as v,e as x,f as b,X as S,h as w,i as y,S as C,W as k,_ as N,s as j,k as E,l as M,D,T as R,R as L,F as P,m as T,n as B,C as I,o as O,A,p as z,q as W,v as H,B as F,x as $,y as K,I as U,z as V,G as q,H as Y,J as G,K as X,L as J,N as Z,O as Q,Q as ee,U as te,V as se,Y as ie,Z as re,$ as ne,a0 as oe,a1 as ae,a2 as le,a3 as he,a4 as ce,a5 as de,a6 as ue,a7 as fe,a8 as _e,a9 as me,aa as pe,ab as ge,ac as ve,ad as xe,ae as be,af as Se,ag as we,ah as ye,ai as Ce,aj as ke,ak as Ne,al as je,am as Ee,an as Me,ao as De,ap as Re,aq as Le,ar as Pe,as as Te,at as Be,au as Ie,av as Oe,aw as Ae,ax as ze,ay as We,az as He,aA as Fe,aB as $e,aC as Ke,aD as Ue,aE as Ve,aF as qe,aG as Ye,aH as Ge,aI as Xe,aJ as Je,aK as Ze,aL as Qe,aM as et,aN as tt,aO as st,aP as it,aQ as rt,aR as nt,aS as ot,aT as at,aU as lt,aV as ht,aW as ct,aX as dt,aY as ut}from"./index-DeWj_k0E.js";import{p as ft}from"./purify.es-CgRAQgUo.js";import{F as _t,M as mt,r as pt,a as gt,b as vt,c as xt,h as bt,o as St,d as wt,e as yt,I as Ct,C as kt,f as Nt,g as jt}from"./ChatOverlay-DkGLWbKQ.js";import{S as Et,U as Mt,T as Dt,a as Rt,b as Lt,c as Pt,R as Tt,A as Bt,d as It,e as Ot,f as At,I as zt,g as Wt,C as Ht,h as Ft,i as $t,j as Kt,k as Ut,l as Vt,m as qt,n as Yt}from"./select-DAoeCy88.js";import{C as Gt}from"./chevron-down-P2HTs96y.js";import{u as Xt,C as Jt,a as Zt}from"./index-CkkbnVk_.js";import{U as Qt,S as es}from"./user-CRCDBTUo.js";
|
|
3
3
|
/**
|
|
4
4
|
* @license lucide-react v0.309.0 - ISC
|
|
5
5
|
*
|
|
6
6
|
* This source code is licensed under the ISC license.
|
|
7
7
|
* See the LICENSE file in the root directory of this source tree.
|
|
8
|
-
*/const ts=o("AlertCircle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]),ss=o("Bot",[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]),is=o("CircleDot",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]]),rs=o("ClipboardCopy",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]),ns=o("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]),os=o("Copy",[["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"}]]),as=o("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]),ls=o("FileSpreadsheet",[["path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z",key:"1nnpy2"}],["polyline",{points:"14 2 14 8 20 8",key:"1ew0cm"}],["path",{d:"M8 13h2",key:"yr2amv"}],["path",{d:"M8 17h2",key:"2yhykz"}],["path",{d:"M14 13h2",key:"un5t4a"}],["path",{d:"M14 17h2",key:"10kma7"}]]),hs=o("GitBranch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]),cs=o("GitCommitHorizontal",[["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"}]]),ds=o("Info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]),us=o("ListRestart",[["path",{d:"M21 6H3",key:"1jwq7v"}],["path",{d:"M7 12H3",key:"13ou7f"}],["path",{d:"M7 18H3",key:"1sijw9"}],["path",{d:"M12 18a5 5 0 0 0 9-3 4.5 4.5 0 0 0-4.5-4.5c-1.33 0-2.54.54-3.41 1.41L11 14",key:"qth677"}],["path",{d:"M11 10v4h4",key:"172dkj"}]]),fs=o("MessageSquare",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]]),_s=o("MoreVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]),ms=o("Network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]),ps=o("PanelLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]),gs=o("PanelRight",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]]),vs=o("Pause",[["rect",{width:"4",height:"16",x:"6",y:"4",key:"iffhe4"}],["rect",{width:"4",height:"16",x:"14",y:"4",key:"sjin7j"}]]),xs=o("Play",[["polygon",{points:"5 3 19 12 5 21 5 3",key:"191637"}]]),bs=o("Presentation",[["path",{d:"M2 3h20",key:"91anmk"}],["path",{d:"M21 3v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V3",key:"2k9sn8"}],["path",{d:"m7 21 5-5 5 5",key:"bip4we"}]]),Ss=o("Repeat",[["path",{d:"m17 2 4 4-4 4",key:"nntrym"}],["path",{d:"M3 11v-1a4 4 0 0 1 4-4h14",key:"84bu3i"}],["path",{d:"m7 22-4-4 4-4",key:"1wqhfi"}],["path",{d:"M21 13v1a4 4 0 0 1-4 4H3",key:"1rx37r"}]]),ws=o("RotateCcw",[["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"}]]),ys=o("TrainTrack",[["path",{d:"M2 17 17 2",key:"18b09t"}],["path",{d:"m2 14 8 8",key:"1gv9hu"}],["path",{d:"m5 11 8 8",key:"189pqp"}],["path",{d:"m8 8 8 8",key:"1imecy"}],["path",{d:"m11 5 8 8",key:"ummqn6"}],["path",{d:"m14 2 8 8",key:"1vk7dn"}],["path",{d:"M7 22 22 7",key:"15mb1i"}]]),Cs=o("Workflow",[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]]),ks=o("ZoomIn",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]),Ns=o("ZoomOut",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]),js=k.lazy(()=>N(()=>import("./GraphPreview-
|
|
8
|
+
*/const ts=o("AlertCircle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]),ss=o("Bot",[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]),is=o("CircleDot",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]]),rs=o("ClipboardCopy",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]),ns=o("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]),os=o("Copy",[["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"}]]),as=o("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]),ls=o("FileSpreadsheet",[["path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z",key:"1nnpy2"}],["polyline",{points:"14 2 14 8 20 8",key:"1ew0cm"}],["path",{d:"M8 13h2",key:"yr2amv"}],["path",{d:"M8 17h2",key:"2yhykz"}],["path",{d:"M14 13h2",key:"un5t4a"}],["path",{d:"M14 17h2",key:"10kma7"}]]),hs=o("GitBranch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]),cs=o("GitCommitHorizontal",[["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"}]]),ds=o("Info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]),us=o("ListRestart",[["path",{d:"M21 6H3",key:"1jwq7v"}],["path",{d:"M7 12H3",key:"13ou7f"}],["path",{d:"M7 18H3",key:"1sijw9"}],["path",{d:"M12 18a5 5 0 0 0 9-3 4.5 4.5 0 0 0-4.5-4.5c-1.33 0-2.54.54-3.41 1.41L11 14",key:"qth677"}],["path",{d:"M11 10v4h4",key:"172dkj"}]]),fs=o("MessageSquare",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]]),_s=o("MoreVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]),ms=o("Network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]),ps=o("PanelLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]),gs=o("PanelRight",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]]),vs=o("Pause",[["rect",{width:"4",height:"16",x:"6",y:"4",key:"iffhe4"}],["rect",{width:"4",height:"16",x:"14",y:"4",key:"sjin7j"}]]),xs=o("Play",[["polygon",{points:"5 3 19 12 5 21 5 3",key:"191637"}]]),bs=o("Presentation",[["path",{d:"M2 3h20",key:"91anmk"}],["path",{d:"M21 3v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V3",key:"2k9sn8"}],["path",{d:"m7 21 5-5 5 5",key:"bip4we"}]]),Ss=o("Repeat",[["path",{d:"m17 2 4 4-4 4",key:"nntrym"}],["path",{d:"M3 11v-1a4 4 0 0 1 4-4h14",key:"84bu3i"}],["path",{d:"m7 22-4-4 4-4",key:"1wqhfi"}],["path",{d:"M21 13v1a4 4 0 0 1-4 4H3",key:"1rx37r"}]]),ws=o("RotateCcw",[["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"}]]),ys=o("TrainTrack",[["path",{d:"M2 17 17 2",key:"18b09t"}],["path",{d:"m2 14 8 8",key:"1gv9hu"}],["path",{d:"m5 11 8 8",key:"189pqp"}],["path",{d:"m8 8 8 8",key:"1imecy"}],["path",{d:"m11 5 8 8",key:"ummqn6"}],["path",{d:"m14 2 8 8",key:"1vk7dn"}],["path",{d:"M7 22 22 7",key:"15mb1i"}]]),Cs=o("Workflow",[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]]),ks=o("ZoomIn",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]),Ns=o("ZoomOut",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]),js=k.lazy(()=>N(()=>import("./GraphPreview-DXZ3AviI.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])).then(e=>({default:e.GraphPreview}))),Es=k.lazy(()=>N(()=>import("./OfficePreview-v7w2uAKM.js"),__vite__mapDeps([10,1,2,3])).then(e=>({default:e.OfficePreview}))),Ms=k.lazy(()=>N(()=>import("./PdfPreview-DzW3MlNU.js"),__vite__mapDeps([11,1,2,12])).then(e=>({default:e.PdfPreview}))),Ds=new Set(["docx","xlsx","xls","pptx"]),Rs=new Set(["pdf"]),Ls={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",kt:"kotlin",swift:"swift",c:"c",cpp:"cpp",h:"c",cs:"csharp",php:"php",sh:"bash",bash:"bash",zsh:"bash",yaml:"yaml",yml:"yaml",json:"json",toml:"toml",html:"html",htm:"html",xml:"xml",svg:"xml",css:"css",scss:"scss",less:"less",sql:"sql",graphql:"graphql",gql:"graphql",dockerfile:"docker",makefile:"makefile",r:"r",lua:"lua",dart:"dart",zig:"zig"};
|
|
9
9
|
/**
|
|
10
10
|
* @license lucide-react v0.309.0 - ISC
|
|
11
11
|
*
|
|
12
12
|
* This source code is licensed under the ISC license.
|
|
13
13
|
* See the LICENSE file in the root directory of this source tree.
|
|
14
|
-
*/const Ps=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif","tiff","tif"]);function Ts(e){return"md"===e?"Markdown":"html"===e||"htm"===e?"HTML":"高亮"}const Bs=[50,75,100,125,150,200,250,300],Is=100;function Os({filePath:e,onClose:t,onMinimize:s}){const i=a(),r=e.endsWith("/.notebook/graph.yaml"),n=r?e.replace(/\/.notebook\/graph\.yaml$/,""):"",[o,k]=l.useState(null),[N,E]=l.useState(null),[M,D]=l.useState(()=>r?"graph":"rendered"),[R,L]=l.useState(!1),[P,T]=l.useState(Is),[B,I]=l.useState(""),[O,A]=l.useState(!1),[z,W]=l.useState(!1),H=l.useRef(null),[F,$]=l.useState(!0),{resolved:K}=h(),U=e.split("/").pop()??e,V=l.useMemo(()=>function(e){const t=e.split("/").pop()??"",s=t.toLowerCase();if("dockerfile"===s)return"dockerfile";if("makefile"===s)return"makefile";const i=t.lastIndexOf(".");return i>=0?t.slice(i+1).toLowerCase():""}(e),[e]),q=Ps.has(V),Y=Ds.has(V),G=Rs.has(V),X=function(e){return"md"===e||"html"===e||"htm"===e||e in Ls}(V),J=Ls[V]||V,Z=l.useMemo(()=>{if(!q)return"";const t=w(e),s=c(),i=`${t}&t=${Date.now()}`;return s?`${i}&token=${encodeURIComponent(s)}`:i},[e,q]);l.useEffect(()=>{if($(!0),k(null),E(null),T(function(e){const t=y(C.fileZoom,{},!0)[e];return Bs.includes(t)?t:Is}(e)),W(!1),q||Y||G)return k({path:e,binary:!1,tooLarge:!1,size:0,content:null}),void D("rendered");D(e.endsWith("/.notebook/graph.yaml")?"graph":"rendered"),d(e).then(e=>{k(e),I(e.content??"")}).catch(e=>E(e instanceof Error?e.message:"Failed to load file"))},[e,q,Y,G]);const Q=l.useCallback(async()=>{A(!0);try{await u(e,B),k(e=>e?{...e,content:B,size:new Blob([B]).size}:e),W(!1)}catch(t){f.error(t instanceof Error?t.message:"保存失败")}finally{A(!1)}},[e,B]);l.useEffect(()=>{const e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&"edit"===M&&(e.preventDefault(),Q())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[M,Q]),l.useEffect(()=>{const e=async e=>{if("Escape"===e.key&&F){if(z){if(!(await i({description:"有未保存的修改,确定关闭?",confirmLabel:"放弃修改",destructive:!0})))return}t()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[F,t,z,i]);const ee=async()=>{if(z){if(!(await i({description:"有未保存的修改,确定退出编辑?",confirmLabel:"放弃修改",destructive:!0})))return}D(r?"graph":X?"rendered":"plain"),W(!1)},te=t=>{T(t),function(e,t){const s=y(C.fileZoom,{},!0);t===Is?delete s[e]:s[e]=t,j(C.fileZoom,s,!0)}(e,t)},se=(null==o?void 0:o.content)??"",ie="dark"===K?St:wt,re=P/100*12,ne=o&&!o.binary&&!o.tooLarge&&!G,oe=l.useDeferredValue(B),ae=l.useMemo(()=>{var e,t;if(!o||o.binary||o.tooLarge)return null;if(q||Y||G)return null;const s="edit"===M?oe:se;if(null==s)return null;return{bytes:new Blob([s]).size,words:((null==(e=s.match(/[\u4e00-\u9fff\u3400-\u4dbf]/g))?void 0:e.length)??0)+((null==(t=s.replace(/[\u4e00-\u9fff\u3400-\u4dbf]/g," ").match(/[a-zA-Z0-9]+/g))?void 0:t.length)??0),lines:""===s?0:s.split("\n").length}},[o,q,Y,M,oe,se]);return _.jsx("div",{className:m("fixed inset-0 z-50 flex items-center justify-center transition-all duration-200",F?"bg-black/60 backdrop-blur-sm pointer-events-auto":"bg-transparent pointer-events-none"),onClick:e=>{e.target===e.currentTarget&&$(!1)},children:_.jsxs("div",{className:m("relative flex flex-col bg-background border border-border shadow-sm transition-all duration-200 pointer-events-auto",R?"w-screen h-screen rounded-none":"w-[72vw] max-w-4xl h-[80vh] rounded-xl",!F&&!R&&"opacity-50"),onClick:()=>$(!0),onFocus:e=>{e.stopPropagation(),$(!0)},children:[_.jsxs("div",{className:"flex items-center gap-2 px-4 h-10 border-b border-border flex-shrink-0",children:[_.jsx(_t,{className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),_.jsxs("span",{className:"flex-1 text-sm text-foreground font-medium truncate",title:e,children:[U,z&&_.jsx("span",{className:"text-muted-foreground ml-1",children:"*"}),ae&&_.jsxs("span",{className:"text-muted-foreground font-normal ml-2 text-xs tabular-nums",children:[(le=ae.bytes,le<1024?`${le} B`:le<1048576?`${(le/1024).toFixed(1)} KB`:`${(le/1024/1024).toFixed(2)} MB`)," · ",ae.words.toLocaleString()," 词 · ",ae.lines.toLocaleString()," 行"]})]}),ne&&!q&&!Y&&_.jsxs("div",{className:"flex items-center rounded-md border border-border bg-muted/50 p-0.5",children:[X&&_.jsxs(_.Fragment,{children:[_.jsxs("button",{onClick:()=>"edit"===M?ee():D("plain"),className:m("p-1 rounded-md transition-colors flex items-center gap-1 text-xs","plain"===M?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),title:"纯文本",children:[_.jsx(ns,{className:"h-3 w-3"}),_.jsx("span",{className:"hidden sm:inline",children:"源码"})]}),_.jsxs("button",{onClick:()=>"edit"===M?ee():D("rendered"),className:m("p-1 rounded-md transition-colors flex items-center gap-1 text-xs","rendered"===M?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),title:Ts(V),children:[_.jsx(p,{className:"h-3 w-3"}),_.jsx("span",{className:"hidden sm:inline",children:Ts(V)})]})]}),r&&_.jsxs("button",{onClick:()=>"edit"===M?ee():D("graph"),className:m("p-1 rounded-md transition-colors flex items-center gap-1 text-xs","graph"===M?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),title:"图谱",children:[_.jsx(ms,{className:"h-3 w-3"}),_.jsx("span",{className:"hidden sm:inline",children:"图谱"})]}),_.jsxs("button",{onClick:()=>"edit"===M?ee():(I((null==o?void 0:o.content)??""),W(!1),D("edit"),void setTimeout(()=>{var e;return null==(e=H.current)?void 0:e.focus()},0)),className:m("p-1 rounded-md transition-colors flex items-center gap-1 text-xs","edit"===M?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),title:"编辑",children:[_.jsx(g,{className:"h-3 w-3"}),_.jsx("span",{className:"hidden sm:inline",children:"编辑"})]})]}),"edit"===M&&_.jsxs("button",{onClick:()=>{Q()},disabled:O||!z,className:m("flex items-center gap-1 text-xs px-2 py-1 rounded transition-colors",z?"bg-blue-600 hover:bg-blue-500 text-white":"bg-muted text-muted-foreground"),title:"保存 (⌘S)",children:[_.jsx(Et,{className:"h-3 w-3"}),O?"保存中...":"保存"]}),(ne||q||G)&&"edit"!==M&&"graph"!==M&&_.jsxs("div",{className:"flex items-center rounded-md border border-border bg-muted/50 p-0.5 gap-0.5",children:[_.jsx("button",{onClick:()=>{const e=[...Bs].reverse().find(e=>e<P);e&&te(e)},disabled:P<=Bs[0],className:"p-1 rounded-md text-muted-foreground hover:text-foreground transition-colors disabled:opacity-30",title:"缩小",children:_.jsx(Ns,{className:"h-3 w-3"})}),_.jsxs("button",{onClick:()=>te(Is),className:"px-1 text-xs text-muted-foreground hover:text-foreground transition-colors min-w-[36px] text-center",title:"重置缩放",children:[P,"%"]}),_.jsx("button",{onClick:()=>{const e=Bs.find(e=>e>P);e&&te(e)},disabled:P>=Bs[Bs.length-1],className:"p-1 rounded-md text-muted-foreground hover:text-foreground transition-colors disabled:opacity-30",title:"放大",children:_.jsx(ks,{className:"h-3 w-3"})})]}),s&&_.jsx("button",{className:"p-1 rounded text-muted-foreground hover:text-foreground transition-colors",onClick:s,title:"最小化到 dock",children:_.jsx(v,{className:"h-3.5 w-3.5"})}),_.jsx("button",{className:"p-1 rounded text-muted-foreground hover:text-foreground transition-colors",onClick:()=>L(e=>!e),title:R?"退出全屏":"全屏",children:R?_.jsx(x,{className:"h-3.5 w-3.5"}):_.jsx(b,{className:"h-3.5 w-3.5"})}),_.jsx("button",{className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors",onClick:async()=>{if(z){if(!(await i({description:"有未保存的修改,确定关闭?",confirmLabel:"放弃修改",destructive:!0})))return}t()},children:_.jsx(S,{className:"h-4 w-4"})})]}),_.jsxs("div",{className:m("flex-1 min-h-0","graph"===M?"overflow-hidden":"overflow-auto"),children:["graph"===M&&_.jsx(l.Suspense,{fallback:_.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"Loading…"}),children:_.jsx(js,{folderPath:n})}),"graph"!==M&&!o&&!N&&_.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"Loading…"}),"graph"!==M&&N&&_.jsx("p",{className:"text-sm text-red-400 p-4",children:N}),"graph"!==M&&q&&o&&_.jsx("div",{className:"flex items-center justify-center p-4 h-full",children:_.jsx("img",{src:Z,alt:U,className:"max-w-full max-h-full object-contain rounded-md",style:{transform:`scale(${P/100})`,transformOrigin:"center center"},draggable:!1})}),"graph"!==M&&Y&&o&&_.jsx(l.Suspense,{fallback:_.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"Loading…"}),children:_.jsx(Es,{filePath:e,ext:V,zoom:P})}),"graph"!==M&&G&&o&&_.jsx(l.Suspense,{fallback:_.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"Loading…"}),children:_.jsx(Ms,{filePath:e,zoom:P})}),"graph"!==M&&!q&&!Y&&!G&&o&&o.binary&&_.jsxs("div",{className:"flex flex-col items-center gap-2 py-12 text-muted-foreground p-4",children:[_.jsx(_t,{className:"h-8 w-8"}),_.jsx("p",{className:"text-sm",children:"Binary file — cannot preview"}),_.jsxs("p",{className:"text-xs text-muted-foreground",children:[(o.size/1024).toFixed(1)," KB"]})]}),"graph"!==M&&!Y&&o&&o.tooLarge&&_.jsxs("div",{className:"flex flex-col items-center gap-2 py-12 text-muted-foreground p-4",children:[_.jsx(_t,{className:"h-8 w-8"}),_.jsx("p",{className:"text-sm",children:"File too large to preview"}),_.jsxs("p",{className:"text-xs text-muted-foreground",children:[(o.size/1024/1024).toFixed(2)," MB (limit 5 MB)"]})]}),"graph"!==M&&ne&&null!==se&&_.jsxs(_.Fragment,{children:["edit"===M&&_.jsx("textarea",{ref:H,value:B,onChange:e=>{I(e.target.value),W(!0)},className:"w-full h-full bg-transparent text-foreground font-mono outline-none resize-none p-4 leading-relaxed",style:{fontSize:`${re}px`,minHeight:"100%"},spellCheck:!1}),"edit"!==M&&_.jsxs("div",{className:"p-4",style:{fontSize:`${re}px`},children:["plain"===M&&_.jsx("pre",{className:"font-mono text-foreground whitespace-pre-wrap break-words leading-relaxed",style:{fontSize:"inherit"},children:se}),"rendered"===M&&"md"===V&&_.jsx("div",{className:"prose dark:prose-invert max-w-none prose-pre:bg-muted prose-pre:border prose-pre:border-border prose-code:text-foreground",style:{fontSize:"inherit"},children:_.jsx(mt,{remarkPlugins:[gt,vt],rehypePlugins:[pt],urlTransform:(e,t,s)=>"src"===t&&"img"===s.tagName?e:yt(e),components:{code({className:e,children:t,...s}){const i=/language-(\w+)/.exec(e||"");return!i&&!e?_.jsx("code",{className:e,...s,children:t}):_.jsx(bt,{style:ie,language:(null==i?void 0:i[1])||"text",PreTag:"div",customStyle:{fontSize:"inherit",borderRadius:"6px",margin:0},children:String(t).replace(/\n$/,"")})},img:({src:t,alt:s,...i})=>_.jsx("img",{...i,src:xt(e,t,c()),alt:s??"",loading:"lazy",style:{maxWidth:"100%",height:"auto"}})},children:se})}),"rendered"===M&&("html"===V||"htm"===V)&&_.jsx("iframe",{srcDoc:ft.sanitize(se,{WHOLE_DOCUMENT:!0,ADD_TAGS:["style","link"]}),className:"w-full h-full border-0 rounded bg-white",sandbox:"",title:U,style:{minHeight:"60vh",transform:`scale(${P/100})`,transformOrigin:"top left",width:1e4/P+"%",height:1e4/P+"%"}}),"rendered"===M&&"md"!==V&&"html"!==V&&"htm"!==V&&J&&_.jsx(bt,{style:ie,language:J,showLineNumbers:!0,lineNumberStyle:{color:"dark"===K?"#555":"#aaa",fontSize:"inherit"},customStyle:{fontSize:"inherit",borderRadius:"6px",margin:0,background:"transparent"},children:se}),"rendered"===M&&!X&&_.jsx("pre",{className:"font-mono text-foreground whitespace-pre-wrap break-words leading-relaxed",style:{fontSize:"inherit"},children:se})]})]})]})]})});var le}async function As(e){var t;if("undefined"!=typeof navigator&&(null==(t=navigator.clipboard)?void 0:t.writeText))try{return await navigator.clipboard.writeText(e),!0}catch{}try{const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.left="-9999px",t.style.top="0",t.setAttribute("readonly",""),document.body.appendChild(t),t.select(),t.setSelectionRange(0,e.length);const s=document.execCommand("copy");return document.body.removeChild(t),s}catch{return!1}}const zs=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif","tiff","tif"]);function Ws(e){const t=e.lastIndexOf(".");return t>=0&&zs.has(e.slice(t+1).toLowerCase())}function Hs({projectPath:e,projectId:t}){var s;const[i,r]=l.useState(new Map),[n,o]=l.useState(new Set([e])),[h,d]=l.useState(new Set),u=E(e=>e.get(t).activePreviewPath),p=E(e=>e.get(t).filePreviews),g=E(e=>e.openFilePreview),v=E(e=>e.closeFilePreview),x=E(e=>e.minimizeFilePreview),b=!!(null==(s=p.find(e=>e.path===u))?void 0:s.minimized),[S,y]=l.useState(null),[C,k]=l.useState(!1),[N,j]=l.useState(null),[W,H]=l.useState(!1),F=a(),$=l.useRef(null),K=l.useRef(null),U=l.useRef(null),V=function(e={}){const t=e.duration??500,s=e.moveTolerance??10,i=l.useRef(null),r=l.useRef(null),n=l.useRef(!1),o=l.useCallback(()=>{i.current&&(clearTimeout(i.current),i.current=null),r.current=null},[]);return{bind:l.useCallback(e=>({onTouchStart:s=>{if(1!==s.touches.length)return;const o=s.touches[0];r.current={x:o.clientX,y:o.clientY},n.current=!1,i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{if(n.current=!0,"undefined"!=typeof navigator&&"vibrate"in navigator)try{navigator.vibrate(15)}catch{}e(o.clientX,o.clientY)},t)},onTouchMove:e=>{if(!r.current||!i.current)return;const t=e.touches[0],n=t.clientX-r.current.x,a=t.clientY-r.current.y;Math.hypot(n,a)>s&&o()},onTouchEnd:o,onTouchCancel:o}),[t,s,o]),wasTriggered:n}}();l.useEffect(()=>{if(!S)return;const e=()=>y(null);return window.addEventListener("click",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("click",e),window.removeEventListener("scroll",e,!0)}},[S]);const q=async(t,s)=>{var i;if(0===t.length)return;const r=s??e,n=t.reduce((e,t)=>e+t.size,0);k(!0),j({loaded:0,total:n});try{const s=await B(r,t,(e,t)=>{j({loaded:e,total:t})});r!==e&&o(e=>new Set(e).add(r)),G(r);const n=s.uploaded.length,a=(null==(i=s.skipped)?void 0:i.length)??0,l=s.errors.length;l>0?f.error(`上传完成:${n} 成功,${l} 失败${a?`,${a} 跳过`:""}`):a>0?f.info(`已上传 ${n} 个文件,${a} 个同名文件被跳过`):f.success(`已上传 ${n} 个文件`)}catch(a){console.error("[FileTree] Upload failed:",a),f.error(`上传失败: ${a.message}`)}finally{k(!1),j(null)}},Y=e=>e>=1073741824?(e/1073741824).toFixed(2)+" GB":e>=1048576?(e/1048576).toFixed(1)+" MB":e>=1024?(e/1024).toFixed(0)+" KB":e+" B",G=l.useCallback(async e=>{d(t=>{if(t.has(e))return t;const s=new Set(t);return s.add(e),s});try{const t=await M(e);r(s=>new Map(s).set(e,t.entries))}catch(t){console.error("[FileTree] Failed to load:",e,t),r(t=>new Map(t).set(e,[]))}finally{d(t=>{const s=new Set(t);return s.delete(e),s})}},[]);l.useEffect(()=>{r(new Map),o(new Set([e])),d(new Set),G(e)},[e,G]);const X=l.useCallback(e=>{o(t=>{const s=new Set(t);return s.has(e)?s.delete(e):(s.add(e),i.has(e)||G(e)),s})},[i,G]),J=l.useCallback(()=>{r(new Map),o(new Set([e])),d(new Set),G(e)},[e,G]),Z=(e,s)=>e.map(e=>{const r=n.has(e.path),o=h.has(e.path),a=i.get(e.path),l=e.name.startsWith(".");return _.jsxs("div",{children:[_.jsxs("div",{className:m("flex items-center gap-1 py-[3px] rounded cursor-pointer","hover:bg-muted-foreground/10",l&&"opacity-50"),style:{paddingLeft:14*s+6+"px",paddingRight:"6px",WebkitTouchCallout:"none"},onClick:s=>{if(V.wasTriggered.current)return V.wasTriggered.current=!1,void s.stopPropagation();"dir"===e.type?X(e.path):g(t,e.path)},onContextMenu:t=>{t.preventDefault(),y({x:t.clientX,y:t.clientY,filePath:e.path,fileName:e.name,type:e.type})},...V.bind((t,s)=>{y({x:t,y:s,filePath:e.path,fileName:e.name,type:e.type})}),children:[_.jsx("span",{className:"w-3 flex-shrink-0 text-muted-foreground",children:"dir"===e.type&&(o?_.jsx(L,{className:"h-2.5 w-2.5 animate-spin"}):r?_.jsx(Gt,{className:"h-2.5 w-2.5"}):_.jsx(I,{className:"h-2.5 w-2.5"}))}),"dir"===e.type?r?_.jsx(P,{className:"h-3.5 w-3.5 text-blue-400 flex-shrink-0"}):_.jsx(O,{className:"h-3.5 w-3.5 text-blue-400 flex-shrink-0"}):Ws(e.name)?_.jsx(Ct,{className:"h-3.5 w-3.5 text-green-400 flex-shrink-0"}):_.jsx(_t,{className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),_.jsx("span",{className:m("text-xs truncate leading-none","dir"===e.type?"text-foreground":"text-muted-foreground"),title:e.path,children:e.name})]}),_.jsx(A,{initial:!1,children:"dir"===e.type&&r&&_.jsxs(z.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15,ease:"easeInOut"},className:"overflow-hidden",children:[!a&&!o&&_.jsx("div",{className:"text-xs text-muted-foreground/50 py-0.5",style:{paddingLeft:14*(s+1)+6+16+"px"},children:"—"}),0===(null==a?void 0:a.length)&&_.jsx("div",{className:"text-xs text-muted-foreground/50 py-0.5",style:{paddingLeft:14*(s+1)+6+16+"px"},children:"empty"}),a&&a.length>0&&Z(a,s+1)]})})]},e.path)}),Q=i.get(e),ee=h.has(e),te=e.split("/").filter(Boolean).pop()??e;return _.jsxs(_.Fragment,{children:[u&&!b&&_.jsx(Os,{filePath:u,onClose:()=>v(t,u),onMinimize:()=>x(t,u)},u),S&&_.jsxs("div",{ref:$,className:"fixed z-50 min-w-[140px] bg-popover border border-border rounded-md shadow-md py-1",style:{left:S.x,top:S.y},onClick:e=>e.stopPropagation(),children:[_.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-accent hover:text-accent-foreground text-left",onClick:()=>{As(S.filePath.startsWith(e+"/")?S.filePath.slice(e.length+1):S.filePath).then(e=>{e?f.success("已复制相对路径"):f.error("复制失败")}),y(null)},children:[_.jsx(os,{className:"h-3.5 w-3.5"}),"复制相对路径"]}),_.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-accent hover:text-accent-foreground text-left",onClick:()=>{As(S.filePath).then(e=>{e?f.success("已复制绝对路径"):f.error("复制失败")}),y(null)},children:[_.jsx(rs,{className:"h-3.5 w-3.5"}),"复制绝对路径"]}),"file"===S.type&&_.jsxs(_.Fragment,{children:[_.jsx("div",{className:"my-1 border-t border-border"}),_.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-accent hover:text-accent-foreground text-left",onClick:()=>{(async(e,t)=>{let s=w(e);const i=c();i&&(s+=`${s.includes("?")?"&":"?"}token=${encodeURIComponent(i)}`);const r=`${s}${s.includes("?")?"&":"?"}dl=1`;try{const e=await fetch(r,{method:"HEAD"});if(!e.ok)return void f.error(`下载失败 (${e.status})`)}catch{return void f.error("下载失败:网络错误")}const n=document.createElement("a");n.href=r,n.download=t,document.body.appendChild(n),n.click(),document.body.removeChild(n)})(S.filePath,S.fileName),y(null)},children:[_.jsx(D,{className:"h-3.5 w-3.5"}),"下载"]})]}),"dir"===S.type&&_.jsxs(_.Fragment,{children:[_.jsx("div",{className:"my-1 border-t border-border"}),_.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-accent hover:text-accent-foreground text-left",disabled:C,onClick:()=>{var e;U.current=S.filePath,y(null),null==(e=K.current)||e.click()},children:[_.jsx(Mt,{className:"h-3.5 w-3.5"}),"上传文件到此文件夹"]})]}),_.jsx("div",{className:"my-1 border-t border-border"}),_.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-destructive/80 hover:text-destructive-foreground text-left",onClick:()=>{(async(t,s,r)=>{const n="dir"===r?`文件夹 "${s}" 及其所有内容`:`文件 "${s}"`;if(await F({title:"确认删除",description:`确认删除${n}?此操作不可撤销。`,destructive:!0,confirmLabel:"删除"}))try{await T(t),f.success(`已删除: ${s}`);const r=t.substring(0,t.lastIndexOf("/"));r&&i.has(r)?G(r):G(e)}catch(o){f.error(`删除失败: ${o.message}`)}})(S.filePath,S.fileName,S.type),y(null)},children:[_.jsx(R,{className:"h-3.5 w-3.5"}),"删除"]})]}),_.jsxs("div",{className:"h-full flex flex-col text-foreground select-none",children:[_.jsxs("div",{className:"flex items-center justify-between px-3 h-9 border-b border-border flex-shrink-0",children:[_.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:"Files"}),_.jsxs("div",{className:"flex items-center gap-0.5",children:[_.jsx("input",{ref:K,type:"file",multiple:!0,className:"hidden",onChange:e=>{const t=Array.from(e.target.files??[]),s=U.current;U.current=null,t.length>0&&q(t,s??void 0),e.target.value=""}}),_.jsx("button",{className:"text-muted-foreground hover:text-foreground p-0.5 rounded transition-colors",onClick:()=>{var e;U.current=null,null==(e=K.current)||e.click()},disabled:C,title:"上传文件",children:_.jsx(Mt,{className:m("h-3 w-3",C&&"animate-pulse")})}),_.jsx("button",{className:"text-muted-foreground hover:text-foreground p-0.5 rounded transition-colors",onClick:J,title:"Refresh file tree",children:_.jsx(L,{className:m("h-3 w-3",ee&&"animate-spin")})})]})]}),_.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-2 border-b border-border flex-shrink-0",children:[_.jsx(P,{className:"h-3.5 w-3.5 text-blue-400 flex-shrink-0"}),_.jsx("span",{className:"text-xs text-foreground font-medium truncate",title:e,children:te})]}),_.jsxs("div",{className:m("flex-1 overflow-y-auto py-1 min-h-0 transition-colors",W&&"bg-accent/30 ring-1 ring-inset ring-accent"),onDragOver:e=>{e.preventDefault(),H(!0)},onDragEnter:e=>{e.preventDefault(),H(!0)},onDragLeave:()=>H(!1),onDrop:e=>{e.preventDefault(),H(!1);const t=Array.from(e.dataTransfer.files);t.length>0&&q(t)},children:[C&&N&&_.jsxs("div",{className:"px-3 py-2 border-b border-border space-y-1",children:[_.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground",children:[_.jsxs("span",{children:["上传中 ",Math.floor(N.loaded/Math.max(N.total,1)*100),"%"]}),_.jsxs("span",{className:"font-mono",children:[Y(N.loaded)," / ",Y(N.total)]})]}),_.jsx("div",{className:"h-1 bg-muted rounded-full overflow-hidden",children:_.jsx("div",{className:"h-full bg-primary transition-[width] duration-150",style:{width:N.loaded/Math.max(N.total,1)*100+"%"}})})]}),W&&!C&&_.jsx("div",{className:"text-xs text-muted-foreground px-4 py-1",children:"松开以上传文件"}),ee&&!Q?_.jsx("div",{className:"text-xs text-muted-foreground px-4 py-3",children:"Loading…"}):Q&&0!==Q.length?Z(Q,0):_.jsx("div",{className:"text-xs text-muted-foreground px-4 py-3",children:"Empty folder"})]})]})]})}function Fs(e){const t=new Date(e),s=Date.now()-t.getTime();return s<36e5?`${Math.floor(s/6e4)}分钟前`:s<864e5?`${Math.floor(s/36e5)}小时前`:s<6048e5?`${Math.floor(s/864e5)}天前`:t.toLocaleDateString()}function $s({projectId:e}){const[t,s]=l.useState(null),[i,r]=l.useState(!0),[n,o]=l.useState(null),[a,h]=l.useState(null),[c,d]=l.useState(""),[u,p]=l.useState(!1),[g,v]=l.useState([]),[x,b]=l.useState(0),[S,w]=l.useState(!0),[y,C]=l.useState(!1),k=l.useCallback(async()=>{r(!0);try{s(await W(e))}catch{s(null)}finally{r(!1)}},[e]),N=l.useCallback(async(t=!1)=>{C(!0);try{const s=t?g.length:0,i=await H(e,30,s);v(e=>t?[...e,...i.commits]:i.commits),b(i.total)}catch{}finally{C(!1)}},[e,g.length]);l.useEffect(()=>{k(),N()},[e]);const j=async t=>{try{const{diff:s}=await V(e,t);o(s||"(no diff)"),h(t??"all changes")}catch{f.error("获取 diff 失败")}},E=async t=>{try{await q(e,[t]),f.success(`已暂存 ${t}`),await k()}catch{f.error("git add 失败")}},M=async()=>{if(c.trim()){p(!0);try{await Y(e,c),f.success("提交成功"),d(""),await k()}catch(t){f.error(t instanceof Error?t.message:"提交失败")}finally{p(!1)}}};if(!t&&i)return _.jsxs("div",{className:"flex flex-col items-center gap-2 py-8 text-muted-foreground/50 text-xs",children:[_.jsx(hs,{className:"h-5 w-5"}),_.jsx("p",{children:"加载中…"})]});if(!t||!t.isRepo)return _.jsxs("div",{className:"flex flex-col items-center gap-2 py-8 text-muted-foreground/50 text-xs",children:[_.jsx(hs,{className:"h-5 w-5"}),_.jsx("p",{children:t?"非 Git 仓库":"加载失败"}),_.jsx(F,{variant:"ghost",size:"sm",className:"h-6 text-xs",onClick:()=>{k()},children:"重试"})]});const D=[...t.modified??[],...t.deleted??[]],R=t.staged??[],P=t.untracked??[];return _.jsxs("div",{className:"flex flex-col h-full overflow-y-auto p-2 space-y-2 text-xs",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground font-medium",children:[_.jsx(hs,{className:"h-3 w-3"}),_.jsx("span",{children:t.branch}),(t.ahead??0)>0&&_.jsxs("span",{className:"text-blue-400",children:["↑",t.ahead]}),(t.behind??0)>0&&_.jsxs("span",{className:"text-yellow-400",children:["↓",t.behind]})]}),_.jsx(F,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>{k()},disabled:i,children:_.jsx(L,{className:m("h-3 w-3",i&&"animate-spin")})})]}),R.length>0&&_.jsxs("div",{children:[_.jsxs("div",{className:"text-muted-foreground mb-1 font-medium",children:["已暂存 (",R.length,")"]}),R.map(e=>_.jsxs("div",{className:"flex items-center gap-1 py-0.5 px-1 rounded hover:bg-muted-foreground/10",children:[_.jsx($,{className:"h-2.5 w-2.5 text-green-500 flex-shrink-0"}),_.jsx("button",{className:"flex-1 text-left truncate text-green-400",onClick:()=>{j(e)},children:e})]},e))]}),D.length>0&&_.jsxs("div",{children:[_.jsxs("div",{className:"text-muted-foreground mb-1 font-medium",children:["未暂存 (",D.length,")"]}),D.map(e=>_.jsxs("div",{className:"flex items-center gap-1 py-0.5 px-1 rounded hover:bg-muted-foreground/10",children:[_.jsx("button",{className:"flex-shrink-0 h-4 w-4 flex items-center justify-center rounded hover:bg-green-500/20 text-muted-foreground hover:text-green-400",title:"git add",onClick:()=>{E(e)},children:_.jsx(K,{className:"h-2.5 w-2.5"})}),_.jsx("button",{className:"flex-1 text-left truncate text-yellow-400",onClick:()=>{j(e)},children:e})]},e))]}),P.length>0&&_.jsxs("div",{children:[_.jsxs("div",{className:"text-muted-foreground mb-1 font-medium",children:["未跟踪 (",P.length,")"]}),P.map(e=>_.jsxs("div",{className:"flex items-center gap-1 py-0.5 px-1 rounded hover:bg-muted-foreground/10",children:[_.jsx("button",{className:"flex-shrink-0 h-4 w-4 flex items-center justify-center rounded hover:bg-green-500/20 text-muted-foreground hover:text-green-400",title:"git add",onClick:()=>{E(e)},children:_.jsx(K,{className:"h-2.5 w-2.5"})}),_.jsx("span",{className:"flex-1 truncate text-muted-foreground",children:e})]},e))]}),0===D.length&&0===R.length&&0===P.length&&_.jsx("p",{className:"text-muted-foreground/50 text-center py-4",children:"工作区干净"}),R.length>0&&_.jsxs("div",{className:"space-y-1.5 pt-1 border-t border-border",children:[_.jsx(U,{placeholder:"提交消息…",value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||M()},className:"h-7 text-xs"}),_.jsx(F,{size:"sm",className:"w-full h-7 text-xs",onClick:()=>{M()},disabled:!c.trim()||u,children:u?"提交中…":`提交 (${R.length} 文件)`})]}),(null==t?void 0:t.isRepo)&&_.jsxs("div",{className:"border-t border-border pt-2",children:[_.jsxs("button",{className:"flex items-center gap-1 text-muted-foreground font-medium mb-1 w-full text-left",onClick:()=>w(e=>!e),children:[_.jsx(Gt,{className:m("h-3 w-3 transition-transform",!S&&"-rotate-90")}),_.jsx(cs,{className:"h-3 w-3"}),_.jsxs("span",{children:["提交历史 (",x,")"]})]}),S&&_.jsxs("div",{className:"space-y-0.5",children:[g.map((e,t)=>{const s=e.parents.length>1;return _.jsxs("div",{className:"flex gap-1.5 items-start group",children:[_.jsxs("div",{className:"flex flex-col items-center flex-shrink-0 w-3",children:[_.jsx("div",{className:m("w-2 h-2 rounded-full flex-shrink-0 mt-1",0===t?"bg-blue-400":s?"bg-purple-400":"bg-muted-foreground/40")}),t<g.length-1&&_.jsx("div",{className:"w-px flex-1 bg-border min-h-[12px]"})]}),_.jsxs("div",{className:"flex-1 min-w-0 pb-1",children:[_.jsxs("div",{className:"flex items-baseline gap-1",children:[_.jsx("span",{className:"font-mono text-muted-foreground/60 text-[10px] flex-shrink-0",children:e.hashShort}),_.jsx("span",{className:"truncate leading-tight",children:e.message.split("\n")[0]})]}),_.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground/50 mt-0.5",children:[_.jsx("span",{children:e.author}),_.jsx("span",{children:Fs(e.date)}),e.branches.length>0&&e.branches.slice(0,2).map(e=>_.jsx("span",{className:"px-1 py-px rounded bg-blue-500/10 text-blue-400 text-[9px]",children:e.replace("remotes/origin/","↑")},e))]})]})]},e.hash)}),g.length<x&&_.jsx("button",{className:"w-full text-center text-[10px] text-muted-foreground hover:text-foreground py-1",onClick:()=>{N(!0)},disabled:y,children:y?"加载中...":`加载更多 (${g.length}/${x})`})]})]}),null!==n&&_.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:()=>o(null),children:[_.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),_.jsxs("div",{className:"relative z-10 w-[700px] max-w-[95vw] max-h-[80vh] flex flex-col bg-background border border-border rounded-xl shadow-sm",onClick:e=>e.stopPropagation(),children:[_.jsxs("div",{className:"flex items-center justify-between px-4 h-10 border-b border-border text-sm font-medium flex-shrink-0",children:[_.jsx("span",{className:"truncate text-muted-foreground",children:a}),_.jsx("button",{className:"text-muted-foreground hover:text-foreground",onClick:()=>o(null),children:"✕"})]}),_.jsx("pre",{className:"flex-1 overflow-auto p-3 text-[11px] font-mono whitespace-pre leading-relaxed",children:n.split("\n").map((e,t)=>_.jsx("span",{className:m("block",e.startsWith("+")&&!e.startsWith("+++")&&"text-green-400 bg-green-400/5",e.startsWith("-")&&!e.startsWith("---")&&"text-red-400 bg-red-400/5",e.startsWith("@@")&&"text-blue-400"),children:e},t))})]})]})]})}function Ks(e){if(!e)return"-";const t=e-Date.now(),s=Math.abs(t),i=t<0,r=Math.round(s/1e3);if(r<60)return i?`${r} 秒前`:`${r} 秒后`;const n=Math.round(r/60);if(n<60)return i?`${n} 分钟前`:`${n} 分钟后`;const o=Math.round(n/60);if(o<24)return i?`${o} 小时前`:`${o} 小时后`;const a=Math.round(o/24);return i?`${a} 天前`:`${a} 天后`}function Us(e){if(!e)return"";return new Date(e).toLocaleString(void 0,{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function Vs({projectId:e}){const[t,s]=l.useState(null),[i,r]=l.useState(!0),[n,o]=l.useState(null),[,a]=l.useState(0),h=l.useRef(!0),c=l.useRef(0),d=l.useCallback(async()=>{const t=++c.current;r(!0),o(null);try{const{tasks:i}=await G(e);if(!h.current||t!==c.current)return;s(i)}catch(cl){if(!h.current||t!==c.current)return;o(cl.message),s([])}finally{h.current&&t===c.current&&r(!1)}},[e]);return l.useEffect(()=>{h.current=!0,d();const e=setInterval(()=>{d()},3e4),t=setInterval(()=>a(e=>e+1),1e3);return()=>{h.current=!1,clearInterval(e),clearInterval(t)}},[d]),_.jsxs("div",{className:"h-full flex flex-col bg-muted text-foreground overflow-hidden",children:[_.jsxs("div",{className:"flex-shrink-0 px-3 py-2 flex items-center justify-between border-b border-border",children:[_.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[_.jsx(kt,{className:"size-4"}),_.jsx("span",{children:"已排程任务"})]}),_.jsx(F,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{d()},title:"刷新","aria-label":"刷新",children:_.jsx(L,{className:m("size-3.5",i&&"animate-spin")})})]}),_.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto p-2 space-y-1.5",children:[_.jsxs("div",{className:"rounded-md bg-muted-foreground/5 px-2 py-1.5 text-[11px] text-muted-foreground flex items-start gap-1.5",children:[_.jsx(ds,{className:"size-3 mt-0.5 shrink-0"}),_.jsxs("span",{className:"leading-snug",children:["best-effort 重建:从 session JSONL 反推「Claude 创建过的 schedule」,",_.jsx("strong",{className:"text-foreground/80",children:"不是"}),"权威活动列表。已触发 / 已删除 无法直接观测。"]})]}),n&&_.jsx("div",{className:"rounded-md border border-destructive/30 bg-destructive/10 text-destructive p-2 text-xs",children:n}),!n&&t&&0===t.length&&!i&&_.jsxs("div",{className:"px-2 py-6 text-center text-xs text-muted-foreground",children:[_.jsx("p",{children:"本项目最近 7 天没有创建过 schedule。"}),_.jsx("p",{className:"mt-2 leading-relaxed",children:"一次性 ScheduleWakeup 触发时间过了的会被隐藏(认为已触发); CronCreate 仅显示 7 天内创建的(与 Claude 自动过期窗口对齐)。"})]}),t&&t.map(e=>{const t=e.nextFireAt?Date.parse(e.nextFireAt):null,s="CronCreate"===e.type&&(e.recurring||/[,*\/-]/.test(e.cron??"")),i="ScheduleWakeup"===e.type&&null!==e.delaySeconds?function(e){if(e<60)return`${e} 秒后`;const t=Math.round(e/60);return t<60?`${t} 分钟后`:Math.round(t/60*10)/10+" 小时后"}(e.delaySeconds):e.cron??"?";return _.jsx("div",{className:"rounded-md border border-border bg-background px-2.5 py-2 text-xs",children:_.jsxs("div",{className:"flex items-start gap-2",children:[_.jsx("div",{className:"shrink-0 mt-0.5 text-muted-foreground",children:s?_.jsx(Ss,{className:"size-3.5"}):_.jsx(X,{className:"size-3.5"})}),_.jsxs("div",{className:"flex-1 min-w-0",children:[_.jsxs("div",{className:"flex flex-wrap items-center gap-1 mb-1",children:[_.jsx("span",{className:"text-[10px] font-mono px-1.5 rounded bg-muted-foreground/10 text-muted-foreground",children:"ScheduleWakeup"===e.type?"SW":"CC"}),e.durable&&_.jsx("span",{className:"text-[10px] px-1.5 rounded bg-primary/10 text-primary",children:"durable"}),_.jsx("code",{className:"text-[10px] bg-muted-foreground/10 px-1 rounded font-mono",children:i})]}),_.jsx("div",{className:"font-medium text-foreground line-clamp-2 leading-snug",children:e.prompt.trim()||"(无 prompt)"}),e.reason&&_.jsxs("div",{className:"mt-0.5 text-muted-foreground line-clamp-1 italic text-[11px]",children:["reason: ",e.reason]}),_.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[11px] text-muted-foreground",children:[null!==t&&_.jsxs("span",{title:Us(t),children:["下次: ",_.jsx("span",{className:"text-foreground/90",children:Ks(t)})]}),_.jsxs("span",{title:Us(e.createdAt),children:["创建: ",Ks(e.createdAt)]}),_.jsx("span",{className:"font-mono text-muted-foreground/70",children:e.sessionId.slice(0,8)})]})]})]})},`${e.sessionId}:${e.id}`)}),i&&!t&&_.jsx("div",{className:"space-y-1.5",children:[0,1].map(e=>_.jsx("div",{className:"rounded-md border border-border bg-background px-2.5 py-2 h-16 animate-pulse"},e))})]})]})}function qs(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:e<1073741824?`${(e/1024/1024).toFixed(1)} MB`:`${(e/1024/1024/1024).toFixed(2)} GB`}function Ys(e){if(!e)return"-";const t=e-Date.now(),s=Math.abs(t),i=t<0,r=Math.round(s/1e3);if(r<60)return i?`${r} 秒前`:`${r} 秒后`;const n=Math.round(r/60);if(n<60)return i?`${n} 分钟前`:`${n} 分钟后`;const o=Math.round(n/60);if(o<24)return i?`${o} 小时前`:`${o} 小时后`;const a=Math.round(o/24);return i?`${a} 天前`:`${a} 天后`}function Gs(e){return new Date(e).toLocaleString(void 0,{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function Xs({projectId:e}){const[t,s]=l.useState(null),[i,r]=l.useState(!0),[n,o]=l.useState(!1),[a,h]=l.useState(null),[,c]=l.useState(0),d=l.useRef(!0),u=l.useCallback(async()=>{h(null);try{const t=await J(e);if(!d.current)return;s(t)}catch(cl){if(!d.current)return;h(cl.message)}finally{d.current&&r(!1)}},[e]),p=l.useCallback(async()=>{o(!0);try{const t=await Z(e);if(!d.current)return;const s=[];t.copied>0&&s.push(`新增/更新 ${t.copied}`),t.deleted>0&&s.push(`删除 ${t.deleted}`),t.skipped>0&&s.push(`跳过 ${t.skipped}`),f.success(`同步完成:${s.join("·")||"无变化"}`),await u()}catch(cl){f.error(`同步失败:${cl.message}`)}finally{d.current&&o(!1)}},[e,u]);l.useEffect(()=>{d.current=!0,u();const e=setInterval(()=>{u()},3e4),t=setInterval(()=>c(e=>e+1),5e3);return()=>{d.current=!1,clearInterval(e),clearInterval(t)}},[u]);const g=(null==t?void 0:t.files.reduce((e,t)=>e+t.bytes,0))??0;return _.jsxs("div",{className:"h-full flex flex-col bg-muted text-foreground overflow-hidden",children:[_.jsxs("div",{className:"flex-shrink-0 px-3 py-2 flex items-center justify-between border-b border-border",children:[_.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[_.jsx(Q,{className:"size-4"}),_.jsx("span",{children:"聊天记录备份"})]}),_.jsx(F,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{u()},title:"刷新","aria-label":"刷新",disabled:i,children:_.jsx(L,{className:m("size-3.5",i&&"animate-spin")})})]}),_.jsx("div",{className:"flex-shrink-0 px-3 py-2 border-b border-border bg-background/40",children:_.jsxs("div",{className:"flex items-center justify-between gap-2",children:[_.jsxs("div",{className:"text-[11px] text-muted-foreground min-w-0",children:[_.jsxs("div",{children:["最后同步:"," ",_.jsx("span",{className:"text-foreground/90",title:(null==t?void 0:t.meta)?Gs(t.meta.lastBackupAt):void 0,children:(null==t?void 0:t.meta)?Ys(t.meta.lastBackupAt):"从未同步"})]}),t&&_.jsxs("div",{className:"mt-0.5 text-muted-foreground/80",children:[t.files.length," 个文件 · ",qs(g)]})]}),_.jsx(F,{size:"sm",className:"h-7 px-2.5 text-xs",onClick:()=>{p()},disabled:n||!(null==t?void 0:t.supported),children:n?"同步中…":"立即同步"})]})}),_.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto p-2 space-y-1",children:[a&&_.jsxs("div",{className:"rounded-md border border-destructive/30 bg-destructive/10 text-destructive p-2 text-xs flex items-start gap-2",children:[_.jsx(ts,{className:"size-3.5 shrink-0 mt-0.5"}),_.jsx("span",{children:a})]}),t&&!t.supported&&_.jsx("div",{className:"px-2 py-6 text-center text-xs text-muted-foreground",children:_.jsxs("p",{children:["此项目使用 ",_.jsx("code",{className:"text-[10px] bg-muted-foreground/10 px-1 rounded",children:"terminal"})," 模式,无聊天记录需备份。"]})}),(null==t?void 0:t.supported)&&0===t.files.length&&!i&&!a&&_.jsxs("div",{className:"px-2 py-6 text-center text-xs text-muted-foreground",children:[_.jsx("p",{children:"暂无已备份的聊天记录"}),_.jsx("p",{className:"mt-2 leading-relaxed text-muted-foreground/80",children:'定时每 5 分钟同步一次,也可点击右上方"立即同步"手动触发。'}),_.jsxs("p",{className:"mt-1 text-muted-foreground/70",children:["备份路径: ",_.jsx("code",{className:"text-[10px] bg-muted-foreground/10 px-1 rounded break-all",children:t.backupDir})]})]}),null==t?void 0:t.files.map(e=>_.jsxs("div",{className:"rounded-md border border-border bg-background px-2.5 py-1.5 text-xs flex items-center gap-2 hover:bg-accent/50 transition-colors",children:[_.jsx(_t,{className:"size-3.5 shrink-0 text-muted-foreground"}),_.jsxs("div",{className:"flex-1 min-w-0",children:[_.jsx("div",{className:"font-mono text-[11px] text-foreground truncate",title:e.name,children:e.name}),_.jsxs("div",{className:"text-muted-foreground/80 text-[10px] flex items-center gap-2",children:[_.jsx("span",{title:Gs(e.mtime),children:Ys(e.mtime)}),_.jsx("span",{className:"text-muted-foreground/40",children:"·"}),_.jsx("span",{children:qs(e.bytes)})]})]})]},e.name)),i&&!t&&_.jsx("div",{className:"space-y-1",children:[0,1].map(e=>_.jsx("div",{className:"rounded-md border border-border bg-background h-10 animate-pulse"},e))})]})]})}function Js({projectPath:e,projectId:t,cliTool:s}){const[i,r]=ee(C.leftPanelTab,"files"),n="claude"===s,o="terminal"!==s;let a;return a="git"===i?"git":"scheduled"===i&&n?"scheduled":"backup"===i&&o?"backup":"files",_.jsxs(Dt,{value:a,onValueChange:e=>r(e),orientation:"vertical",className:"h-full flex bg-muted text-foreground overflow-hidden",children:[_.jsxs(Rt,{className:m("flex flex-col items-center justify-start shrink-0","h-full w-9 border-r border-border rounded-none p-1 gap-1"),children:[_.jsx(Lt,{value:"files",title:"Files","aria-label":"Files",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(P,{className:"h-3.5 w-3.5"})}),_.jsx(Lt,{value:"git",title:"Git","aria-label":"Git",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(hs,{className:"h-3.5 w-3.5"})}),n&&_.jsx(Lt,{value:"scheduled",title:"已排程任务","aria-label":"Scheduled tasks",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(kt,{className:"h-3.5 w-3.5"})}),o&&_.jsx(Lt,{value:"backup",title:"聊天记录备份","aria-label":"Sessions backup",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(Q,{className:"h-3.5 w-3.5"})})]}),_.jsxs("div",{className:"flex-1 min-w-0 flex flex-col border-l border-border",children:[_.jsx(Pt,{value:"files",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx(Hs,{projectPath:e,projectId:t})}),_.jsx(Pt,{value:"git",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx($s,{projectId:t})}),n&&_.jsx(Pt,{value:"scheduled",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx(Vs,{projectId:t})}),o&&_.jsx(Pt,{value:"backup",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx(Xs,{projectId:t})})]})]})}function Zs(e){const t=Qs(e),s=l.forwardRef((e,s)=>{const{children:i,...r}=e,n=l.Children.toArray(i),o=n.find(ti);if(o){const e=o.props.children,i=n.map(t=>t===o?l.Children.count(e)>1?l.Children.only(null):l.isValidElement(e)?e.props.children:null:t);return _.jsx(t,{...r,ref:s,children:l.isValidElement(e)?l.cloneElement(e,void 0,i):null})}return _.jsx(t,{...r,ref:s,children:i})});return s.displayName=`${e}.Slot`,s}function Qs(e){const t=l.forwardRef((e,t)=>{const{children:s,...i}=e;if(l.isValidElement(s)){const e=function(e){var t,s;let i=null==(t=Object.getOwnPropertyDescriptor(e.props,"ref"))?void 0:t.get,r=i&&"isReactWarning"in i&&i.isReactWarning;if(r)return e.ref;if(i=null==(s=Object.getOwnPropertyDescriptor(e,"ref"))?void 0:s.get,r=i&&"isReactWarning"in i&&i.isReactWarning,r)return e.props.ref;return e.props.ref||e.ref}(s),r=function(e,t){const s={...t};for(const i in t){const r=e[i],n=t[i];/^on[A-Z]/.test(i)?r&&n?s[i]=(...e)=>{const t=n(...e);return r(...e),t}:r&&(s[i]=r):"style"===i?s[i]={...r,...n}:"className"===i&&(s[i]=[r,n].filter(Boolean).join(" "))}return{...e,...s}}(i,s.props);return s.type!==l.Fragment&&(r.ref=t?te(t,e):e),l.cloneElement(s,r)}return l.Children.count(s)>1?l.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var ei=Symbol("radix.slottable");function ti(e){return l.isValidElement(e)&&"function"==typeof e.type&&"__radixId"in e.type&&e.type.__radixId===ei}var si=["Enter"," "],ii=["ArrowUp","PageDown","End"],ri=["ArrowDown","PageUp","Home",...ii],ni={ltr:[...si,"ArrowRight"],rtl:[...si,"ArrowLeft"]},oi={ltr:["ArrowLeft"],rtl:["ArrowRight"]},ai="Menu",[li,hi,ci]=At(ai),[di,ui]=ie(ai,[ci,It,Ot]),fi=It(),_i=Ot(),[mi,pi]=di(ai),[gi,vi]=di(ai),xi=e=>{const{__scopeMenu:t,open:s=!1,children:i,dir:r,onOpenChange:n,modal:o=!0}=e,a=fi(t),[h,c]=l.useState(null),d=l.useRef(!1),u=se(n),f=Xt(r);return l.useEffect(()=>{const e=()=>{d.current=!0,document.addEventListener("pointerdown",t,{capture:!0,once:!0}),document.addEventListener("pointermove",t,{capture:!0,once:!0})},t=()=>d.current=!1;return document.addEventListener("keydown",e,{capture:!0}),()=>{document.removeEventListener("keydown",e,{capture:!0}),document.removeEventListener("pointerdown",t,{capture:!0}),document.removeEventListener("pointermove",t,{capture:!0})}},[]),_.jsx(Tt,{...a,children:_.jsx(mi,{scope:t,open:s,onOpenChange:u,content:h,onContentChange:c,children:_.jsx(gi,{scope:t,onClose:l.useCallback(()=>u(!1),[u]),isUsingKeyboardRef:d,dir:f,modal:o,children:i})})})};xi.displayName=ai;var bi=l.forwardRef((e,t)=>{const{__scopeMenu:s,...i}=e,r=fi(s);return _.jsx(Bt,{...r,...i,ref:t})});bi.displayName="MenuAnchor";var Si="MenuPortal",[wi,yi]=di(Si,{forceMount:void 0}),Ci=e=>{const{__scopeMenu:t,forceMount:s,children:i,container:r}=e,n=pi(Si,t);return _.jsx(wi,{scope:t,forceMount:s,children:_.jsx(re,{present:s||n.open,children:_.jsx(ne,{asChild:!0,container:r,children:i})})})};Ci.displayName=Si;var ki="MenuContent",[Ni,ji]=di(ki),Ei=l.forwardRef((e,t)=>{const s=yi(ki,e.__scopeMenu),{forceMount:i=s.forceMount,...r}=e,n=pi(ki,e.__scopeMenu),o=vi(ki,e.__scopeMenu);return _.jsx(li.Provider,{scope:e.__scopeMenu,children:_.jsx(re,{present:i||n.open,children:_.jsx(li.Slot,{scope:e.__scopeMenu,children:o.modal?_.jsx(Mi,{...r,ref:t}):_.jsx(Di,{...r,ref:t})})})})}),Mi=l.forwardRef((e,t)=>{const s=pi(ki,e.__scopeMenu),i=l.useRef(null),r=oe(t,i);return l.useEffect(()=>{const e=i.current;if(e)return he(e)},[]),_.jsx(Li,{...e,ref:r,trapFocus:s.open,disableOutsidePointerEvents:s.open,disableOutsideScroll:!0,onFocusOutside:ae(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>s.onOpenChange(!1)})}),Di=l.forwardRef((e,t)=>{const s=pi(ki,e.__scopeMenu);return _.jsx(Li,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>s.onOpenChange(!1)})}),Ri=Zs("MenuContent.ScrollLock"),Li=l.forwardRef((e,t)=>{const{__scopeMenu:s,loop:i=!1,trapFocus:r,onOpenAutoFocus:n,onCloseAutoFocus:o,disableOutsidePointerEvents:a,onEntryFocus:h,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:u,onInteractOutside:f,onDismiss:m,disableOutsideScroll:p,...g}=e,v=pi(ki,s),x=vi(ki,s),b=fi(s),S=_i(s),w=hi(s),[y,C]=l.useState(null),k=l.useRef(null),N=oe(t,k,v.onContentChange),j=l.useRef(0),E=l.useRef(""),M=l.useRef(0),D=l.useRef(null),R=l.useRef("right"),L=l.useRef(0),P=p?ue:l.Fragment,T=p?{as:Ri,allowPinchZoom:!0}:void 0,B=e=>{var t,s;const i=E.current+e,r=w().filter(e=>!e.disabled),n=document.activeElement,o=null==(t=r.find(e=>e.ref.current===n))?void 0:t.textValue,a=function(e,t,s){const i=t.length>1&&Array.from(t).every(e=>e===t[0]),r=i?t[0]:t,n=s?e.indexOf(s):-1;let o=(a=e,l=Math.max(n,0),a.map((e,t)=>a[(l+t)%a.length]));var a,l;1===r.length&&(o=o.filter(e=>e!==s));const h=o.find(e=>e.toLowerCase().startsWith(r.toLowerCase()));return h!==s?h:void 0}(r.map(e=>e.textValue),i,o),l=null==(s=r.find(e=>e.textValue===a))?void 0:s.ref.current;!function e(t){E.current=t,window.clearTimeout(j.current),""!==t&&(j.current=window.setTimeout(()=>e(""),1e3))}(i),l&&setTimeout(()=>l.focus())};l.useEffect(()=>()=>window.clearTimeout(j.current),[]),de();const I=l.useCallback(e=>{var t,s;return R.current===(null==(t=D.current)?void 0:t.side)&&function(e,t){if(!t)return!1;const s={x:e.clientX,y:e.clientY};return function(e,t){const{x:s,y:i}=e;let r=!1;for(let n=0,o=t.length-1;n<t.length;o=n++){const e=t[n],a=t[o],l=e.x,h=e.y,c=a.x,d=a.y;h>i!=d>i&&s<(c-l)*(i-h)/(d-h)+l&&(r=!r)}return r}(s,t)}(e,null==(s=D.current)?void 0:s.area)},[]);return _.jsx(Ni,{scope:s,searchRef:E,onItemEnter:l.useCallback(e=>{I(e)&&e.preventDefault()},[I]),onItemLeave:l.useCallback(e=>{var t;I(e)||(null==(t=k.current)||t.focus(),C(null))},[I]),onTriggerLeave:l.useCallback(e=>{I(e)&&e.preventDefault()},[I]),pointerGraceTimerRef:M,onPointerGraceIntentChange:l.useCallback(e=>{D.current=e},[]),children:_.jsx(P,{...T,children:_.jsx(fe,{asChild:!0,trapped:r,onMountAutoFocus:ae(n,e=>{var t;e.preventDefault(),null==(t=k.current)||t.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:_.jsx(_e,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:u,onInteractOutside:f,onDismiss:m,children:_.jsx(Wt,{asChild:!0,...S,dir:x.dir,orientation:"vertical",loop:i,currentTabStopId:y,onCurrentTabStopIdChange:C,onEntryFocus:ae(h,e=>{x.isUsingKeyboardRef.current||e.preventDefault()}),preventScrollOnEntryFocus:!0,children:_.jsx(Ht,{role:"menu","aria-orientation":"vertical","data-state":rr(v.open),"data-radix-menu-content":"",dir:x.dir,...b,...g,ref:N,style:{outline:"none",...g.style},onKeyDown:ae(g.onKeyDown,e=>{const t=e.target.closest("[data-radix-menu-content]")===e.currentTarget,s=e.ctrlKey||e.altKey||e.metaKey,i=1===e.key.length;t&&("Tab"===e.key&&e.preventDefault(),!s&&i&&B(e.key));const r=k.current;if(e.target!==r)return;if(!ri.includes(e.key))return;e.preventDefault();const n=w().filter(e=>!e.disabled).map(e=>e.ref.current);ii.includes(e.key)&&n.reverse(),function(e){const t=document.activeElement;for(const s of e){if(s===t)return;if(s.focus(),document.activeElement!==t)return}}(n)}),onBlur:ae(e.onBlur,e=>{e.currentTarget.contains(e.target)||(window.clearTimeout(j.current),E.current="")}),onPointerMove:ae(e.onPointerMove,ar(e=>{const t=e.target,s=L.current!==e.clientX;if(e.currentTarget.contains(t)&&s){const t=e.clientX>L.current?"right":"left";R.current=t,L.current=e.clientX}}))})})})})})})});Ei.displayName=ki;var Pi=l.forwardRef((e,t)=>{const{__scopeMenu:s,...i}=e;return _.jsx(le.div,{role:"group",...i,ref:t})});Pi.displayName="MenuGroup";var Ti=l.forwardRef((e,t)=>{const{__scopeMenu:s,...i}=e;return _.jsx(le.div,{...i,ref:t})});Ti.displayName="MenuLabel";var Bi="MenuItem",Ii="menu.itemSelect",Oi=l.forwardRef((e,t)=>{const{disabled:s=!1,onSelect:i,...r}=e,n=l.useRef(null),o=vi(Bi,e.__scopeMenu),a=ji(Bi,e.__scopeMenu),h=oe(t,n),c=l.useRef(!1);return _.jsx(Ai,{...r,ref:h,disabled:s,onClick:ae(e.onClick,()=>{const e=n.current;if(!s&&e){const t=new CustomEvent(Ii,{bubbles:!0,cancelable:!0});e.addEventListener(Ii,e=>null==i?void 0:i(e),{once:!0}),ce(e,t),t.defaultPrevented?c.current=!1:o.onClose()}}),onPointerDown:t=>{var s;null==(s=e.onPointerDown)||s.call(e,t),c.current=!0},onPointerUp:ae(e.onPointerUp,e=>{var t;c.current||null==(t=e.currentTarget)||t.click()}),onKeyDown:ae(e.onKeyDown,e=>{const t=""!==a.searchRef.current;s||t&&" "===e.key||si.includes(e.key)&&(e.currentTarget.click(),e.preventDefault())})})});Oi.displayName=Bi;var Ai=l.forwardRef((e,t)=>{const{__scopeMenu:s,disabled:i=!1,textValue:r,...n}=e,o=ji(Bi,s),a=_i(s),h=l.useRef(null),c=oe(t,h),[d,u]=l.useState(!1),[f,m]=l.useState("");return l.useEffect(()=>{const e=h.current;e&&m((e.textContent??"").trim())},[n.children]),_.jsx(li.ItemSlot,{scope:s,disabled:i,textValue:r??f,children:_.jsx(zt,{asChild:!0,...a,focusable:!i,children:_.jsx(le.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":i||void 0,"data-disabled":i?"":void 0,...n,ref:c,onPointerMove:ae(e.onPointerMove,ar(e=>{if(i)o.onItemLeave(e);else if(o.onItemEnter(e),!e.defaultPrevented){e.currentTarget.focus({preventScroll:!0})}})),onPointerLeave:ae(e.onPointerLeave,ar(e=>o.onItemLeave(e))),onFocus:ae(e.onFocus,()=>u(!0)),onBlur:ae(e.onBlur,()=>u(!1))})})})}),zi=l.forwardRef((e,t)=>{const{checked:s=!1,onCheckedChange:i,...r}=e;return _.jsx(qi,{scope:e.__scopeMenu,checked:s,children:_.jsx(Oi,{role:"menuitemcheckbox","aria-checked":nr(s)?"mixed":s,...r,ref:t,"data-state":or(s),onSelect:ae(r.onSelect,()=>null==i?void 0:i(!!nr(s)||!s),{checkForDefaultPrevented:!1})})})});zi.displayName="MenuCheckboxItem";var Wi="MenuRadioGroup",[Hi,Fi]=di(Wi,{value:void 0,onValueChange:()=>{}}),$i=l.forwardRef((e,t)=>{const{value:s,onValueChange:i,...r}=e,n=se(i);return _.jsx(Hi,{scope:e.__scopeMenu,value:s,onValueChange:n,children:_.jsx(Pi,{...r,ref:t})})});$i.displayName=Wi;var Ki="MenuRadioItem",Ui=l.forwardRef((e,t)=>{const{value:s,...i}=e,r=Fi(Ki,e.__scopeMenu),n=s===r.value;return _.jsx(qi,{scope:e.__scopeMenu,checked:n,children:_.jsx(Oi,{role:"menuitemradio","aria-checked":n,...i,ref:t,"data-state":or(n),onSelect:ae(i.onSelect,()=>{var e;return null==(e=r.onValueChange)?void 0:e.call(r,s)},{checkForDefaultPrevented:!1})})})});Ui.displayName=Ki;var Vi="MenuItemIndicator",[qi,Yi]=di(Vi,{checked:!1}),Gi=l.forwardRef((e,t)=>{const{__scopeMenu:s,forceMount:i,...r}=e,n=Yi(Vi,s);return _.jsx(re,{present:i||nr(n.checked)||!0===n.checked,children:_.jsx(le.span,{...r,ref:t,"data-state":or(n.checked)})})});Gi.displayName=Vi;var Xi=l.forwardRef((e,t)=>{const{__scopeMenu:s,...i}=e;return _.jsx(le.div,{role:"separator","aria-orientation":"horizontal",...i,ref:t})});Xi.displayName="MenuSeparator";var Ji=l.forwardRef((e,t)=>{const{__scopeMenu:s,...i}=e,r=fi(s);return _.jsx(Ft,{...r,...i,ref:t})});Ji.displayName="MenuArrow";var[Zi,Qi]=di("MenuSub"),er="MenuSubTrigger",tr=l.forwardRef((e,t)=>{const s=pi(er,e.__scopeMenu),i=vi(er,e.__scopeMenu),r=Qi(er,e.__scopeMenu),n=ji(er,e.__scopeMenu),o=l.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:h}=n,c={__scopeMenu:e.__scopeMenu},d=l.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return l.useEffect(()=>d,[d]),l.useEffect(()=>{const e=a.current;return()=>{window.clearTimeout(e),h(null)}},[a,h]),_.jsx(bi,{asChild:!0,...c,children:_.jsx(Ai,{id:r.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":r.contentId,"data-state":rr(s.open),...e,ref:te(t,r.onTriggerChange),onClick:t=>{var i;null==(i=e.onClick)||i.call(e,t),e.disabled||t.defaultPrevented||(t.currentTarget.focus(),s.open||s.onOpenChange(!0))},onPointerMove:ae(e.onPointerMove,ar(t=>{n.onItemEnter(t),t.defaultPrevented||e.disabled||s.open||o.current||(n.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{s.onOpenChange(!0),d()},100))})),onPointerLeave:ae(e.onPointerLeave,ar(e=>{var t,i;d();const r=null==(t=s.content)?void 0:t.getBoundingClientRect();if(r){const t=null==(i=s.content)?void 0:i.dataset.side,o="right"===t,l=o?-5:5,h=r[o?"left":"right"],c=r[o?"right":"left"];n.onPointerGraceIntentChange({area:[{x:e.clientX+l,y:e.clientY},{x:h,y:r.top},{x:c,y:r.top},{x:c,y:r.bottom},{x:h,y:r.bottom}],side:t}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>n.onPointerGraceIntentChange(null),300)}else{if(n.onTriggerLeave(e),e.defaultPrevented)return;n.onPointerGraceIntentChange(null)}})),onKeyDown:ae(e.onKeyDown,t=>{var r;const o=""!==n.searchRef.current;e.disabled||o&&" "===t.key||ni[i.dir].includes(t.key)&&(s.onOpenChange(!0),null==(r=s.content)||r.focus(),t.preventDefault())})})})});tr.displayName=er;var sr="MenuSubContent",ir=l.forwardRef((e,t)=>{const s=yi(ki,e.__scopeMenu),{forceMount:i=s.forceMount,...r}=e,n=pi(ki,e.__scopeMenu),o=vi(ki,e.__scopeMenu),a=Qi(sr,e.__scopeMenu),h=l.useRef(null),c=oe(t,h);return _.jsx(li.Provider,{scope:e.__scopeMenu,children:_.jsx(re,{present:i||n.open,children:_.jsx(li.Slot,{scope:e.__scopeMenu,children:_.jsx(Li,{id:a.contentId,"aria-labelledby":a.triggerId,...r,ref:c,align:"start",side:"rtl"===o.dir?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:e=>{var t;o.isUsingKeyboardRef.current&&(null==(t=h.current)||t.focus()),e.preventDefault()},onCloseAutoFocus:e=>e.preventDefault(),onFocusOutside:ae(e.onFocusOutside,e=>{e.target!==a.trigger&&n.onOpenChange(!1)}),onEscapeKeyDown:ae(e.onEscapeKeyDown,e=>{o.onClose(),e.preventDefault()}),onKeyDown:ae(e.onKeyDown,e=>{var t;const s=e.currentTarget.contains(e.target),i=oi[o.dir].includes(e.key);s&&i&&(n.onOpenChange(!1),null==(t=a.trigger)||t.focus(),e.preventDefault())})})})})})});function rr(e){return e?"open":"closed"}function nr(e){return"indeterminate"===e}function or(e){return nr(e)?"indeterminate":e?"checked":"unchecked"}function ar(e){return t=>"mouse"===t.pointerType?e(t):void 0}ir.displayName=sr;var lr=xi,hr=bi,cr=Ci,dr=Ei,ur=Pi,fr=Ti,_r=Oi,mr=zi,pr=$i,gr=Ui,vr=Gi,xr=Xi,br=Ji,Sr=tr,wr=ir,yr="ContextMenu",[Cr]=ie(yr,[ui]),kr=ui(),[Nr,jr]=Cr(yr),Er=e=>{const{__scopeContextMenu:t,children:s,onOpenChange:i,dir:r,modal:n=!0}=e,[o,a]=l.useState(!1),h=kr(t),c=se(i),d=l.useCallback(e=>{a(e),c(e)},[c]);return _.jsx(Nr,{scope:t,open:o,onOpenChange:d,modal:n,children:_.jsx(lr,{...h,dir:r,open:o,onOpenChange:d,modal:n,children:s})})};Er.displayName=yr;var Mr="ContextMenuTrigger",Dr=l.forwardRef((e,t)=>{const{__scopeContextMenu:s,disabled:i=!1,...r}=e,n=jr(Mr,s),o=kr(s),a=l.useRef({x:0,y:0}),h=l.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=l.useRef(0),d=l.useCallback(()=>window.clearTimeout(c.current),[]),u=e=>{a.current={x:e.clientX,y:e.clientY},n.onOpenChange(!0)};return l.useEffect(()=>d,[d]),l.useEffect(()=>{i&&d()},[i,d]),_.jsxs(_.Fragment,{children:[_.jsx(hr,{...o,virtualRef:h}),_.jsx(le.span,{"data-state":n.open?"open":"closed","data-disabled":i?"":void 0,...r,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:i?e.onContextMenu:ae(e.onContextMenu,e=>{d(),u(e),e.preventDefault()}),onPointerDown:i?e.onPointerDown:ae(e.onPointerDown,Ir(e=>{d(),c.current=window.setTimeout(()=>u(e),700)})),onPointerMove:i?e.onPointerMove:ae(e.onPointerMove,Ir(d)),onPointerCancel:i?e.onPointerCancel:ae(e.onPointerCancel,Ir(d)),onPointerUp:i?e.onPointerUp:ae(e.onPointerUp,Ir(d))})]})});Dr.displayName=Mr;var Rr=e=>{const{__scopeContextMenu:t,...s}=e,i=kr(t);return _.jsx(cr,{...i,...s})};Rr.displayName="ContextMenuPortal";var Lr="ContextMenuContent",Pr=l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=jr(Lr,s),n=kr(s),o=l.useRef(!1);return _.jsx(dr,{...n,...i,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:t=>{var s;null==(s=e.onCloseAutoFocus)||s.call(e,t),!t.defaultPrevented&&o.current&&t.preventDefault(),o.current=!1},onInteractOutside:t=>{var s;null==(s=e.onInteractOutside)||s.call(e,t),t.defaultPrevented||r.modal||(o.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Pr.displayName=Lr;l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(ur,{...r,...i,ref:t})}).displayName="ContextMenuGroup";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(fr,{...r,...i,ref:t})}).displayName="ContextMenuLabel";var Tr=l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(_r,{...r,...i,ref:t})});Tr.displayName="ContextMenuItem";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(mr,{...r,...i,ref:t})}).displayName="ContextMenuCheckboxItem";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(pr,{...r,...i,ref:t})}).displayName="ContextMenuRadioGroup";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(gr,{...r,...i,ref:t})}).displayName="ContextMenuRadioItem";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(vr,{...r,...i,ref:t})}).displayName="ContextMenuItemIndicator";var Br=l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(xr,{...r,...i,ref:t})});Br.displayName="ContextMenuSeparator";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(br,{...r,...i,ref:t})}).displayName="ContextMenuArrow";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(Sr,{...r,...i,ref:t})}).displayName="ContextMenuSubTrigger";function Ir(e){return t=>"mouse"!==t.pointerType?e(t):void 0}l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(wr,{...r,...i,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})}).displayName="ContextMenuSubContent";var Or=Rr,Ar=Pr,zr=Tr,Wr=Br;const Hr=Er,Fr=Dr,$r=l.forwardRef(({className:e,...t},s)=>_.jsx(Or,{children:_.jsx(Ar,{ref:s,className:m("z-50 min-w-[10rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",e),...t})}));$r.displayName=Ar.displayName;const Kr=l.forwardRef(({className:e,destructive:t,...s},i)=>_.jsx(zr,{ref:i,className:m("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none","focus:bg-accent focus:text-accent-foreground","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"text-red-500 focus:text-red-500 focus:bg-red-500/10",e),...s}));Kr.displayName=zr.displayName;const Ur=l.forwardRef(({className:e,...t},s)=>_.jsx(Wr,{ref:s,className:m("-mx-1 my-1 h-px bg-border",e),...t}));function Vr({kind:e,label:t,preview:s,inserted:i,unclicked:r,onLeftClick:n,onEdit:o,onDelete:a,onShare:h,onRefresh:c,footer:d,readOnly:u,noContextMenu:f,cornerHint:p,instructionsFile:v="CLAUDE.md"}){const x=l.useRef(null),b=m("agent-prompt"===e?i?"border-green-500/50 bg-green-500/10 hover:bg-green-500/15":"border-dashed border-border hover:border-border/80 hover:bg-muted-foreground/10 dark:hover:bg-muted-foreground/20":r?"border-blue-500/30 bg-blue-500/15 hover:bg-blue-500/20 dark:bg-blue-500/15 dark:hover:bg-blue-500/25":"border-transparent bg-background dark:bg-muted-foreground/10 hover:bg-muted-foreground/10 dark:hover:bg-muted-foreground/20 hover:border-muted-foreground/30"),S="agent-prompt"===e,w=!f||c?" · 右键更多":"",y="quick-prompt"===e?`点击发送${w}`:(i?`点击从 ${v} 移除`:`点击插入 ${v}`)+w,C=_.jsxs("div",{ref:x,className:m("group relative rounded-md border text-xs transition-colors cursor-pointer select-none",b),onClick:n,title:y,children:[S&&_.jsx("span",{"aria-hidden":!0,className:m("absolute top-1.5 left-1.5 h-2 w-2 rounded-full transition-colors",i?"bg-green-500 ring-1 ring-green-500/40":"border border-muted-foreground/40 bg-transparent")}),_.jsxs("div",{className:m("py-1.5",f&&p?"pr-10":f?"pr-2":"pr-7",S?"pl-5":"pl-3"),children:[_.jsx("div",{className:"font-medium truncate",children:t}),s&&s!==t&&_.jsx("div",{className:"mt-0.5 text-muted-foreground/80 truncate font-mono",children:s}),d]}),f&&p&&_.jsx("span",{"aria-hidden":!0,className:"absolute top-1.5 right-2 text-[10px] leading-none font-mono tabular-nums text-muted-foreground/60 pointer-events-none",children:p}),!f&&_.jsx("button",{onClick:e=>{e.stopPropagation(),e.preventDefault();const t=x.current;if(!t)return;const s=t.getBoundingClientRect(),i=new MouseEvent("contextmenu",{bubbles:!0,cancelable:!0,clientX:s.right-8,clientY:s.top+s.height/2,button:2});t.dispatchEvent(i)},className:m("absolute top-1 right-1 p-0.5 rounded transition-opacity","md:opacity-0 md:group-hover:opacity-100 md:focus-visible:opacity-100","hover:bg-muted-foreground/10 focus-visible:bg-muted-foreground/10","text-muted-foreground hover:text-foreground"),title:"更多","aria-label":"更多操作",children:_.jsx(_s,{className:"h-3.5 w-3.5"})})]});return!(!c&&(f||!o&&!a&&!h))?_.jsxs(Hr,{children:[_.jsx(Fr,{asChild:!0,children:C}),_.jsxs($r,{children:[c&&_.jsxs(Kr,{onSelect:c,children:[_.jsx(L,{className:"h-3.5 w-3.5"}),"更新"]}),!f&&!u&&o&&a&&_.jsxs(_.Fragment,{children:[c&&_.jsx(Ur,{}),_.jsxs(Kr,{onSelect:o,children:[_.jsx(g,{className:"h-3.5 w-3.5"}),"编辑"]}),_.jsxs(Kr,{destructive:!0,onSelect:a,children:[_.jsx(R,{className:"h-3.5 w-3.5"}),"删除"]}),h&&_.jsx(Ur,{})]}),!f&&h&&_.jsxs(Kr,{onSelect:h,children:[_.jsx(me,{className:"h-3.5 w-3.5"}),"共享到 ccweb-hub"]})]})]}):_.jsx("div",{onContextMenu:e=>e.preventDefault(),children:C})}function qr({open:e,onOpenChange:t,initialLabel:s,initialCommand:i,title:r,onSave:n}){const[o,a]=l.useState(s),[h,c]=l.useState(i),[d,u]=l.useState(!0);l.useEffect(()=>{e&&u(!0)},[e]),l.useEffect(()=>{e&&(a(s),c(i))},[e,s,i]);const f=()=>{const e=h.trim();e&&(n(o.trim()||e,e),t(!1))};return _.jsx(ye,{open:e,onOpenChange:t,modal:!1,children:_.jsxs(Ce,{noOverlay:!0,className:m("sm:max-w-2xl max-h-[85vh] flex flex-col transition-opacity",!d&&"opacity-50"),onInteractOutside:e=>{e.preventDefault(),u(!1)},onClick:()=>u(!0),children:[_.jsxs(ke,{children:[_.jsx(Ne,{children:r}),_.jsx(je,{children:"左键点击卡片会把此命令发送到 CLI。"})]}),_.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col",children:[_.jsxs("div",{className:"space-y-2",children:[_.jsx(Ee,{htmlFor:"qp-label",children:"标签"}),_.jsx(U,{id:"qp-label",placeholder:"显示名(可选,默认用命令文本)",value:o,onChange:e=>a(e.target.value),className:"text-base",autoFocus:!0})]}),_.jsxs("div",{className:"space-y-2 flex-1 flex flex-col min-h-0",children:[_.jsx(Ee,{htmlFor:"qp-command",children:"命令"}),_.jsx("textarea",{id:"qp-command",placeholder:"输入要发送的命令...",value:h,onChange:e=>c(e.target.value),className:m("flex-1 min-h-[200px] w-full rounded-md border border-input bg-background px-4 py-3","text-base leading-relaxed font-mono","ring-offset-background placeholder:text-muted-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","resize-none"),onKeyDown:e=>{"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),f())}})]})]}),_.jsxs(Me,{className:"flex items-center justify-between sm:justify-between",children:[_.jsx("span",{className:"text-xs text-muted-foreground",children:"⌘↩ 保存"}),_.jsxs("div",{className:"flex gap-2",children:[_.jsx(F,{variant:"outline",onClick:()=>t(!1),children:"取消"}),_.jsx(F,{onClick:f,disabled:!h.trim(),children:"保存"})]})]})]})})}function Yr({title:e,count:t,onAdd:s,children:i}){return _.jsxs("div",{className:"px-2 py-2",children:[_.jsxs("div",{className:"flex items-center justify-between mb-1.5 px-1",children:[_.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-muted-foreground",children:[_.jsx("span",{children:e}),_.jsxs("span",{className:"text-muted-foreground/60",children:["(",t,")"]})]}),_.jsx("button",{onClick:s,className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted-foreground/10 transition-colors",title:"新建","aria-label":"新建",children:_.jsx(K,{className:"h-3 w-3"})})]}),i]})}function Gr({projectId:e,onSend:t}){const s=a(),[i,r]=l.useState([]),[n,o]=l.useState([]),h=E(),c=h.get(e),[d,u]=l.useState({open:!1}),[f,m]=l.useState(c.shareHubOpen),[p,g]=l.useState(c.shareHubLabel),[v,x]=l.useState(c.shareHubCommand),b=l.useCallback(t=>{r(e=>{const s=e.findIndex(e=>e.id===t);if(s<0||e[s].used)return e;const i=[...e];return i[s]={...i[s],used:!0},i}),pe(e,t,!0).catch(e=>{console.error("Failed to mark shortcut used:",e)})},[e]);l.useEffect(()=>{ge(e).then(r).catch(()=>r([]))},[e]),l.useEffect(()=>{ve().then(o).catch(()=>o([]))},[]);const S=l.useCallback(e=>{const t=[],s=new Set;let i=e;const r=[];for(;i&&!s.has(i.id);)s.add(i.id),r.unshift(i),i=i.parentId?n.find(e=>e.id===i.parentId):void 0;for(const n of r)t.push(n.command);return t},[n]),w=l.useCallback(async e=>{const s=S(e);for(const i of s)try{await Promise.resolve(t(i+"\r"))}catch{return}},[S,t]),y=e=>u({open:!0,mode:"create",scope:e}),C=(t,s)=>{g(t),x(s),m(!0),h.setShareHub(e,!0,t,s)};return _.jsxs("div",{className:"h-full flex flex-col text-foreground overflow-hidden",children:[_.jsxs("div",{className:"px-3 pt-2.5 pb-2 border-b border-border/50 shrink-0",children:[_.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Quick Prompts"}),_.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground/70 leading-snug",children:"点击卡片发送命令到 CLI;新建的命令在首次点击前以浅蓝色标识"})]}),_.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[_.jsx(Yr,{title:"项目",count:i.length,onAdd:()=>y("project"),children:0===i.length?_.jsx("div",{className:"px-1 py-3 text-xs text-muted-foreground/60",children:"暂无项目命令"}):_.jsx("div",{className:"space-y-1.5",children:i.map(i=>_.jsx(Vr,{kind:"quick-prompt",label:i.label,preview:i.label!==i.command?i.command:"",unclicked:!i.used,onLeftClick:()=>(e=>{t(e.command+"\r"),b(e.id)})(i),onEdit:()=>(e=>u({open:!0,mode:"edit",scope:"project",id:e.id,label:e.label,command:e.command}))(i),onDelete:()=>{(async t=>{if(await s({title:"删除项目快捷 Prompt",description:`确认删除「${t.label}」?此操作不可撤销。`,destructive:!0,confirmLabel:"删除"}))try{await Se(e,t.id),r(e=>e.filter(e=>e.id!==t.id))}catch(i){console.error("Failed to delete shortcut:",i)}})(i)},onShare:()=>C(i.label,i.command)},i.id))})}),_.jsx("div",{className:"h-px bg-border mx-2"}),_.jsx(Yr,{title:"全局",count:n.length,onAdd:()=>y("global"),children:0===n.length?_.jsx("div",{className:"px-1 py-3 text-xs text-muted-foreground/60",children:"暂无全局命令"}):_.jsx("div",{className:"space-y-1.5",children:n.map(e=>{var t;const i=e.parentId?null==(t=n.find(t=>t.id===e.parentId))?void 0:t.label:void 0;return _.jsx(Vr,{kind:"quick-prompt",label:e.label,preview:i?"":e.label!==e.command?e.command:"",onLeftClick:()=>w(e),onEdit:()=>(e=>u({open:!0,mode:"edit",scope:"global",id:e.id,label:e.label,command:e.command}))(e),onDelete:()=>{(async e=>{const t=n.filter(t=>t.parentId===e.id);if(await s({title:"删除全局快捷 Prompt",description:t.length>0?`「${e.label}」被 ${t.length} 个其他全局命令继承。删除后这些命令的继承会断链。确认删除?`:`确认删除「${e.label}」?此操作不可撤销。`,destructive:!0,confirmLabel:"删除"}))try{await we(e.id),o(t=>t.filter(t=>t.id!==e.id))}catch(i){console.error("Failed to delete global shortcut:",i)}})(e)},onShare:()=>C(e.label,e.command),footer:i?_.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[_.jsx(xe,{className:"h-2.5 w-2.5 text-muted-foreground"}),_.jsxs("span",{className:"text-muted-foreground truncate",children:["继承: ",i,"(继承链仅可在 Dashboard 编辑)"]})]}):null},e.id)})})})]}),_.jsx(qr,{open:d.open,onOpenChange:e=>{e||u({open:!1})},initialLabel:d.open&&"edit"===d.mode?d.label:"",initialCommand:d.open&&"edit"===d.mode?d.command:"",title:d.open?"create"===d.mode?`新建${"global"===d.scope?"全局":"项目"}命令`:"编辑命令":"",onSave:(t,s)=>{(async(t,s)=>{if(d.open)try{if("create"===d.mode)if("global"===d.scope){const e=await De({label:t,command:s});o(t=>[...t,e])}else{const i=await Re(e,{label:t,command:s});r(e=>[...e,i])}else if("global"===d.scope){const e=n.find(e=>e.id===d.id),i=await Le(d.id,{label:t,command:s,parentId:(null==e?void 0:e.parentId)??null});o(e=>e.map(e=>e.id===i.id?i:e))}else{const i=await Pe(e,d.id,{label:t,command:s});r(e=>e.map(e=>e.id===i.id?i:e))}}catch(i){console.error("Failed to save shortcut:",i)}})(t,s)}}),_.jsx(be,{open:f,onOpenChange:t=>{m(t),t||h.setShareHub(e,!1)},kind:"quick-prompt",label:p,content:v})]})}Ur.displayName=Wr.displayName;function Xr({open:e,onOpenChange:t,title:s,initialLabel:i,initialCommand:r,onSave:n,instructionsFile:o="CLAUDE.md"}){const[a,h]=l.useState(i),[c,d]=l.useState(r),[u,f]=l.useState(!0);l.useEffect(()=>{e&&(h(i),d(r),f(!0))},[e,i,r]);const p=a.trim(),g=c.trim(),v=p.length>100,x=g.length>8e3,b=g.length>0&&p.length>0&&!v&&!x,S=()=>{b&&(n(p,c),t(!1))};return _.jsx(ye,{open:e,onOpenChange:t,modal:!1,children:_.jsxs(Ce,{noOverlay:!0,className:m("sm:max-w-2xl max-h-[85vh] flex flex-col transition-opacity",!u&&"opacity-50"),onInteractOutside:e=>{e.preventDefault(),f(!1)},onClick:()=>f(!0),children:[_.jsxs(ke,{children:[_.jsx(Ne,{children:s}),_.jsxs(je,{children:["This prompt can be clicked once in the sidebar to insert into ",o,", and clicked again to remove (by exact text match)."]})]}),_.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col",children:[_.jsxs("div",{className:"space-y-2",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsx(Ee,{htmlFor:"prompt-label",children:"Label"}),_.jsxs("span",{className:m("text-xs text-muted-foreground",v&&"text-red-500"),children:[p.length," / ",100]})]}),_.jsx(U,{id:"prompt-label",placeholder:"A short name for this prompt",value:a,onChange:e=>h(e.target.value),className:"text-base",autoFocus:!0})]}),_.jsxs("div",{className:"space-y-2 flex-1 flex flex-col min-h-0",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsx(Ee,{htmlFor:"prompt-command",children:"Prompt"}),_.jsxs("span",{className:m("text-xs text-muted-foreground",x&&"text-red-500"),children:[g.length," / ",8e3]})]}),_.jsx("textarea",{id:"prompt-command",placeholder:`The exact text that will be appended to ${o}...`,value:c,onChange:e=>d(e.target.value),className:m("flex-1 min-h-[200px] w-full rounded-md border border-input bg-background px-4 py-3","text-sm leading-relaxed font-mono","ring-offset-background placeholder:text-muted-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","resize-none"),onKeyDown:e=>{"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),S())}})]})]}),_.jsxs(Me,{className:"flex items-center justify-between sm:justify-between",children:[_.jsx("span",{className:"text-xs text-muted-foreground",children:"⌘↩ to save"}),_.jsxs("div",{className:"flex gap-2",children:[_.jsx(F,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),_.jsx(F,{onClick:S,disabled:!b,children:"Save"})]})]})]})})}function Jr({projectId:e}){const t=a(),[s,i]=l.useState([]),[r,n]=l.useState([]),[o,h]=l.useState("CLAUDE.md"),[c,d]=l.useState(!0),[u,m]=l.useState({open:!1}),[p,g]=l.useState({open:!1,label:"",content:""}),v=l.useCallback(async()=>{try{const t=await Te(e);i(t.global),n(t.project),t.instructionsFilename&&h(t.instructionsFilename)}catch(t){f.error(`加载提示词失败: ${t.message}`)}finally{d(!1)}},[e]);l.useEffect(()=>{d(!0),v()},[v]);const x=l.useRef(new Set),b=l.useCallback(async(t,s)=>{if(x.current.has(s.id))return;x.current.add(s.id);const r=s.inserted?"remove":"insert",a=e=>e.map(e=>e.id===s.id?{...e,inserted:!e.inserted}:e);"global"===t?i(a):n(a);try{const t=await Be(e,s.command,r);if("remove"===r&&!1===t.changed)return"not-found"===t.reason?f.error(`${o} 中找不到该提示词的精确文本,请自行编辑 ${o} 移除。`):f.warning(`该提示词当前不在 ${o} 中(可能被手动编辑过),已重新同步状态。`),void v();v()}catch(l){f.error(`操作失败: ${l.message}`),"global"===t?i(a):n(a)}finally{x.current.delete(s.id)}},[e,v,o]),S=l.useCallback(async(t,s,i,r,n)=>{try{if("create"===t)"global"===s?await Ie({label:r,command:n}):await Oe(e,{label:r,command:n}),f.success("已添加");else{if(!i)return;"global"===s?await Ae(i,{label:r,command:n}):await ze(e,i,{label:r,command:n}),f.success("已更新")}v()}catch(o){f.error(`保存失败: ${o.message}`)}},[e,v]),w=l.useCallback(async(s,i)=>{const r=i.inserted?`此提示词目前已插入当前项目的 ${o}。\n\n删除后它会在 ${o} 中成为"孤儿文本"——仅删除提示词记录,不会自动从 ${o} 移除。\n\n确认删除?`:"确认删除此提示词?此操作不可撤销。";if(await t({title:"删除提示词",description:r,destructive:!0,confirmLabel:"删除"}))try{"global"===s?await We(i.id):await He(e,i.id),f.success("已删除"),v()}catch(n){f.error(`删除失败: ${n.message}`)}},[e,v,t,o]),y=l.useCallback(e=>{g({open:!0,label:e.label,content:e.command})},[]);return _.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[_.jsxs("div",{className:"px-3 pt-2.5 pb-2 border-b border-border/50 shrink-0",children:[_.jsx("span",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"Agent Prompts"}),_.jsxs("p",{className:"mt-1 text-[11px] text-muted-foreground/70 leading-snug",children:["点击卡片插入 / 移出当前项目的 ",o,";左上角绿点表示已插入"]})]}),_.jsx(Zr,{title:"项目",count:r.length,loading:c,prompts:r,emptyText:"暂无项目提示词",instructionsFile:o,onAdd:()=>m({open:!0,mode:"create",scope:"project"}),onToggle:e=>{b("project",e)},onEdit:e=>m({open:!0,mode:"edit",scope:"project",id:e.id,label:e.label,command:e.command}),onDelete:e=>{w("project",e)},onShare:y}),_.jsx("div",{className:"h-px bg-border mx-2"}),_.jsx(Zr,{title:"全局",count:s.length,loading:c,prompts:s,emptyText:"暂无全局提示词",instructionsFile:o,onAdd:()=>m({open:!0,mode:"create",scope:"global"}),onToggle:e=>{b("global",e)},onEdit:e=>m({open:!0,mode:"edit",scope:"global",id:e.id,label:e.label,command:e.command}),onDelete:e=>{w("global",e)},onShare:y}),_.jsx(Xr,{open:u.open,onOpenChange:e=>{e||m({open:!1})},title:!1===u.open?"":"create"===u.mode?`新建${"global"===u.scope?"全局":"项目"}提示词`:`编辑${"global"===u.scope?"全局":"项目"}提示词`,initialLabel:u.open&&"edit"===u.mode?u.label:"",initialCommand:u.open&&"edit"===u.mode?u.command:"",instructionsFile:o,onSave:(e,t)=>{if(!u.open)return;const s="edit"===u.mode?u.id:null;S(u.mode,u.scope,s,e,t)}}),_.jsx(be,{open:p.open,onOpenChange:e=>g(t=>({...t,open:e})),kind:"agent-prompt",label:p.label,content:p.content})]})}function Zr({title:e,count:t,loading:s,prompts:i,emptyText:r,onAdd:n,onToggle:o,onEdit:a,onDelete:l,onShare:h,instructionsFile:c}){return _.jsxs("div",{className:"px-2 py-2",children:[_.jsxs("div",{className:"flex items-center justify-between mb-1.5 px-1",children:[_.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-muted-foreground uppercase tracking-wider",children:[_.jsx("span",{children:e}),_.jsxs("span",{className:"text-muted-foreground/60 normal-case tracking-normal",children:["(",t,")"]})]}),_.jsx("button",{onClick:n,className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted-foreground/10 transition-colors",title:"新建","aria-label":"新建",children:_.jsx(K,{className:"h-3 w-3"})})]}),s?_.jsx("div",{className:"px-1 py-3 text-xs text-muted-foreground/60",children:"加载中…"}):0===i.length?_.jsx("div",{className:"px-1 py-3 text-xs text-muted-foreground/60",children:r}):_.jsx("div",{className:"space-y-1.5",children:i.map(e=>{const t=e.command.split("\n").find(e=>e.trim())??e.command.trim();return _.jsx(Vr,{kind:"agent-prompt",label:e.label,preview:t,inserted:e.inserted,instructionsFile:c,onLeftClick:()=>o(e),onEdit:()=>a(e),onDelete:()=>l(e),onShare:()=>h(e)},e.id)})})]})}function Qr({projectId:e}){const[t,s]=l.useState([]),[i,r]=l.useState(null),[n,o]=l.useState("CLAUDE.md"),[a,h]=l.useState(!0),[c,d]=l.useState(!1),u=l.useRef(new Set),p=l.useCallback(async()=>{h(!0);try{const t=await Fe(e);s(t.items),r(t.claudeMdLineCount),t.instructionsFilename&&o(t.instructionsFilename)}catch(t){f.error(`加载失败: ${t.message}`)}finally{h(!1)}},[e]);l.useEffect(()=>{p()},[p]);const g=l.useCallback(async t=>{if(u.current.has(t.filename))return;u.current.add(t.filename),s(e=>e.map(e=>e.filename===t.filename?{...e,inserted:!e.inserted}:e));const i=t.inserted?"remove":"insert";try{const n=await $e(e,t.filename,i);if(!n.ok)return f.error("操作失败"+(n.reason?`(${n.reason})`:"")),void p();s(e=>e.map(e=>e.filename===t.filename?{...e,inserted:n.inserted}:e)),"number"==typeof n.claudeMdLineCount&&r(n.claudeMdLineCount),"insert"===i&&"refreshed"===n.reason&&f.info(`${t.name} 已更新(文件内容有变化)`)}catch(n){f.error(`操作失败: ${n.message}`),s(e=>e.map(e=>e.filename===t.filename?{...e,inserted:t.inserted}:e))}finally{u.current.delete(t.filename)}},[e,p]),v=l.useCallback(async()=>{if(c)return;const i=t.filter(e=>e.inserted);if(0===i.length)return void f.info("没有已插入的 memory 卡片");d(!0);let n=0,o=0;for(const t of i)if(u.current.has(t.filename))o++;else{u.current.add(t.filename);try{const i=await $e(e,t.filename,"insert");i.ok?(s(e=>e.map(e=>e.filename===t.filename?{...e,inserted:i.inserted}:e)),"number"==typeof i.claudeMdLineCount&&r(i.claudeMdLineCount),n++):o++}catch{o++}finally{u.current.delete(t.filename)}}d(!1),0===o?f.success(`已从磁盘更新 ${n} 个 memory 卡片`):f.error(`${n} 个更新成功,${o} 个失败`)},[e,t,c]),x=l.useCallback(async t=>{if(!u.current.has(t.filename))if(t.inserted){u.current.add(t.filename);try{const i=await $e(e,t.filename,"insert");if(!i.ok)return f.error("更新失败"+(i.reason?`(${i.reason})`:"")),void p();s(e=>e.map(e=>e.filename===t.filename?{...e,inserted:i.inserted}:e)),"number"==typeof i.claudeMdLineCount&&r(i.claudeMdLineCount),f.success(`${t.name} 已从磁盘重新加载`)}catch(i){f.error(`更新失败: ${i.message}`)}finally{u.current.delete(t.filename)}}else f.info("卡片未插入,无需更新")},[e,p]);return _.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[_.jsxs("div",{className:"px-3 pt-2.5 pb-2 border-b border-border/50 shrink-0",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsx("span",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"Memory Prompts"}),_.jsxs("div",{className:"flex items-center gap-0.5",children:[_.jsx("button",{onClick:()=>{v()},disabled:c||!t.some(e=>e.inserted),className:m("p-0.5 rounded text-muted-foreground transition-colors","hover:text-foreground hover:bg-muted-foreground/10","disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-muted-foreground"),title:`把所有已插入卡片的内容从磁盘重新加载到 ${n}`,children:_.jsx(us,{className:m("h-3.5 w-3.5",c&&"animate-spin")})}),_.jsx("button",{onClick:()=>{p()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted-foreground/10 transition-colors",title:"刷新(重新扫描 .ccweb/memory/)",children:_.jsx(L,{className:m("h-3.5 w-3.5",a&&"animate-spin")})})]})]}),_.jsxs("p",{className:"mt-1 text-[11px] text-muted-foreground/70 leading-snug",children:["来自 ",_.jsx("code",{className:"text-[11px]",children:".ccweb/memory/*.md"})," 的文件,点击插入 / 移除 ",n,"(以",_.jsx("code",{className:"text-[11px]",children:" START 名 / END 名 "}),"包裹)"]}),null!==i&&_.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground/60 font-mono tabular-nums",children:[n,": ",i," 行"]})]}),_.jsx("div",{className:"px-2 py-2 flex-1 min-h-0",children:a&&0===t.length?_.jsx("div",{className:"px-1 py-6 text-xs text-muted-foreground/60 text-center",children:"加载中…"}):0===t.length?_.jsxs("div",{className:"px-1 py-8 text-xs text-muted-foreground/60 flex flex-col items-center gap-2",children:[_.jsx(as,{className:"h-5 w-5"}),_.jsxs("div",{className:"text-center leading-relaxed",children:["暂无 memory 文件",_.jsx("br",{}),"新建 ",_.jsx("code",{className:"text-[11px]",children:".ccweb/memory/*.md"})," 文件后点刷新"]})]}):_.jsx("div",{className:"space-y-1.5",children:t.map(e=>_.jsx(Vr,{kind:"agent-prompt",noContextMenu:!0,label:e.name,preview:e.preview,inserted:e.inserted,instructionsFile:n,cornerHint:`${e.lineCount} 行`,onLeftClick:()=>{g(e)},onRefresh:e.inserted?()=>{x(e)}:void 0},e.filename))})})]})}function en({projectId:e,onSend:t}){const[s,i]=ee(C.rightPanelTab,"shortcuts"),r="prompts"===s?"prompts":"memory"===s?"memory":"shortcuts";return _.jsxs(Dt,{value:r,onValueChange:e=>i(e),orientation:"vertical",className:"h-full flex bg-muted text-foreground overflow-hidden",children:[_.jsxs("div",{className:"flex-1 min-w-0 flex flex-col border-r border-border",children:[_.jsx(Pt,{value:"shortcuts",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx(Gr,{projectId:e,onSend:t})}),_.jsx(Pt,{value:"prompts",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx(Jr,{projectId:e})}),_.jsx(Pt,{value:"memory",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx(Qr,{projectId:e})})]}),_.jsxs(Rt,{className:m("flex flex-col items-center justify-start shrink-0","h-full w-9 border-l border-border rounded-none p-1 gap-1"),children:[_.jsx(Lt,{value:"shortcuts",title:"Quick Prompts (快捷 Prompts)","aria-label":"Quick Prompts",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(Ke,{className:"h-3.5 w-3.5"})}),_.jsx(Lt,{value:"prompts",title:"Agent Prompts","aria-label":"Agent Prompts",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(Ue,{className:"h-3.5 w-3.5"})}),_.jsx(Lt,{value:"memory",title:"Memory Prompts (.ccweb/memory/*.md)","aria-label":"Memory Prompts",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(as,{className:"h-3.5 w-3.5"})})]})]})}function tn(){if("undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID)return crypto.randomUUID();if("undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues){const e=new Uint8Array(16);crypto.getRandomValues(e),e[6]=15&e[6]|64,e[8]=63&e[8]|128;const t=e=>e.toString(16).padStart(2,"0");return`${t(e[0])}${t(e[1])}${t(e[2])}${t(e[3])}-${t(e[4])}${t(e[5])}-${t(e[6])}${t(e[7])}-${t(e[8])}${t(e[9])}-${t(e[10])}${t(e[11])}${t(e[12])}${t(e[13])}${t(e[14])}${t(e[15])}`}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}async function sn(e,t,s){const i={"Content-Type":"application/json"},r=c();r&&(i.Authorization=`Bearer ${r}`);const n=await fetch(t,{method:e,headers:i,body:void 0!==s?JSON.stringify(s):void 0});if(!n.ok){let e=`HTTP ${n.status}`;try{const t=await n.json();t.error&&(e=t.error)}catch{}throw new Error(e)}return n.json()}function rn(e,t){return sn("GET",`/api/projects/${e}/flows/file/${encodeURIComponent(t)}`)}function nn(e){return sn("POST",`/api/projects/${e}/flows/abort`)}function on({node:e,allIds:t,variables:s,constants:i,onChange:r,onDelete:n}){return _.jsxs("div",{className:"rounded-xl border border-border bg-card p-4 space-y-3",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsxs("span",{className:"text-xs font-mono text-muted-foreground",children:["#",e.id]}),_.jsx(U,{value:e.name,onChange:t=>r({...e,name:t.target.value}),className:"h-8 flex-1",placeholder:"节点名称"}),_.jsx("div",{className:"text-xs px-2 py-0.5 rounded bg-accent",children:an(e.kind)}),_.jsx(F,{size:"sm",variant:"ghost",onClick:n,title:"删除节点",children:_.jsx(R,{className:"h-4 w-4"})})]}),"user-input"===e.kind&&_.jsx(hn,{node:e,allIds:t,variables:s,constants:i,onChange:r}),"llm"===e.kind&&_.jsx(cn,{node:e,allIds:t,variables:s,constants:i,onChange:r}),"system-logic"===e.kind&&_.jsx(un,{node:e,allIds:t,variables:s,constants:i,onChange:r})]})}function an(e){return"user-input"===e?"用户输入":"llm"===e?"LLM":"系统逻辑"}function ln({value:e,allIds:t,selfId:s,onChange:i,label:r="下一节点"}){return _.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:r}),_.jsxs($t,{value:null===e?"__null":String(e),onValueChange:e=>i("__null"===e?null:Number(e)),children:[_.jsx(Kt,{className:"h-8 text-xs",children:_.jsx(Ut,{})}),_.jsxs(Vt,{children:[_.jsx(qt,{value:"__null",children:"— 结束 —"}),t.filter(e=>e!==s).map(e=>_.jsxs(qt,{value:String(e),children:["#",e]},e))]})]})]})}function hn({node:e,allIds:t,variables:s,constants:i,onChange:r}){const n=t=>r({...e,userInputSchema:{fields:t}}),o=(t,s,i)=>{const r=[...e.userInputSchema.fields],o={...r[t]};delete o.outputVariable,delete o.bindVariable,delete o.bindConstant,"out"===s&&i?o.outputVariable=i:"bindVar"===s&&i?o.bindVariable=i:"bindConst"===s&&i&&(o.bindConstant=i),r[t]=o,n(r)};return _.jsxs("div",{className:"space-y-3",children:[_.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"表单字段"}),e.userInputSchema.fields.map((t,r)=>{const a=(e=>e.outputVariable?"out":e.bindVariable?"bindVar":e.bindConstant?"bindConst":"none")(t),l=t.outputVariable??t.bindVariable??t.bindConstant??"",h=("bindConst"===a?i:s).filter(e=>!!e.name);return _.jsxs("div",{className:"space-y-1.5 rounded-md border border-border/60 p-2",children:[_.jsxs("div",{className:"flex gap-1.5",children:[_.jsx(U,{value:t.key,onChange:s=>{const i=[...e.userInputSchema.fields];i[r]={...t,key:s.target.value},n(i)},placeholder:"key",className:"w-32 h-8 font-mono text-xs"}),_.jsx(U,{value:t.label,onChange:s=>{const i=[...e.userInputSchema.fields];i[r]={...t,label:s.target.value},n(i)},placeholder:"显示标签",className:"flex-1 h-8 text-xs"}),_.jsxs($t,{value:t.type,onValueChange:s=>{const i=[...e.userInputSchema.fields];i[r]={...t,type:s},n(i)},children:[_.jsx(Kt,{className:"w-24 h-8 text-xs",children:_.jsx(Ut,{})}),_.jsxs(Vt,{children:[_.jsx(qt,{value:"text",children:"单行"}),_.jsx(qt,{value:"textarea",children:"多行"})]})]}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>n(e.userInputSchema.fields.filter((e,t)=>t!==r)),children:_.jsx(S,{className:"h-3.5 w-3.5"})})]}),(s.length>0||i.length>0)&&_.jsxs("div",{className:"flex gap-1.5 items-center",children:[_.jsx("span",{className:"text-[11px] text-muted-foreground",children:"绑定"}),_.jsxs($t,{value:a,onValueChange:e=>{var t,n;const a=e,h="bindConst"===a?(null==(t=i[0])?void 0:t.name)??null:(null==(n=s[0])?void 0:n.name)??null;o(r,a,l||h)},children:[_.jsx(Kt,{className:"w-40 h-7 text-xs",children:_.jsx(Ut,{})}),_.jsxs(Vt,{children:[_.jsx(qt,{value:"none",children:"无绑定"}),_.jsx(qt,{value:"out",disabled:0===s.length,children:"输出到变量"}),_.jsx(qt,{value:"bindVar",disabled:0===s.length,children:"显示变量(只读)"}),_.jsx(qt,{value:"bindConst",disabled:0===i.length,children:"显示常量(只读)"})]})]}),"none"!==a&&_.jsxs($t,{value:l,onValueChange:e=>o(r,a,e),children:[_.jsx(Kt,{className:"flex-1 h-7 text-xs",children:_.jsx(Ut,{placeholder:"选择名字"})}),_.jsx(Vt,{children:h.map(e=>_.jsxs(qt,{value:e.name,children:[_.jsx("span",{className:"font-mono",children:e.name}),_.jsx("span",{className:"opacity-60 ml-2",children:e.description||"(无描述)"})]},e.name))})]})]})]},r)}),_.jsxs(F,{size:"sm",variant:"ghost",onClick:()=>n([...e.userInputSchema.fields,{key:"",label:"",type:"text"}]),className:"h-7 text-xs",children:[_.jsx(K,{className:"h-3.5 w-3.5 mr-1"})," 添加字段"]})]}),_.jsx(ln,{value:e.next,allIds:t,selfId:e.id,onChange:t=>r({...e,next:t})})]})}function cn({node:e,allIds:t,variables:s,constants:i,onChange:r}){const n=e.readVariables??[],o=e.writeVariables??[],a=e.readConstants??[],l=(t,s)=>{const i=e[t]??[],n=i.includes(s)?i.filter(e=>e!==s):[...i,s];r({...e,[t]:n})};return _.jsxs("div",{className:"space-y-3",children:[_.jsxs("div",{className:"space-y-1.5",children:[_.jsxs(Ee,{className:"text-xs text-muted-foreground",children:["Prompt 模板 · 插值 ",_.jsx("span",{className:"font-mono",children:"{{var:name}}"})," 或 ",_.jsx("span",{className:"font-mono",children:"{{const:name}}"})]}),_.jsx("textarea",{value:e.promptTemplate,onChange:t=>r({...e,promptTemplate:t.target.value}),className:"w-full min-h-[120px] rounded-md border border-border bg-background px-3 py-2 text-xs font-mono resize-y outline-none focus:ring-2 focus:ring-ring/30",placeholder:"例:\n根据目标 {{var:goal}} 提取 {{const:max_keywords}} 个关键词,\n写入 .ccweb/workflow_data.json 的 variables.keywords 字段。"})]}),i.length>0&&_.jsx(dn,{label:"读取常量 · prompt 头部附常量值上下文",items:i,selected:a,onToggle:e=>l("readConstants",e),accent:"green"}),s.length>0&&_.jsxs(_.Fragment,{children:[_.jsx(dn,{label:"读取变量 · prompt 头部附变量当前值",items:s,selected:n,onToggle:e=>l("readVariables",e),accent:"blue"}),_.jsx(dn,{label:"写入变量 · prompt 末尾附 LLM 写盘指令",items:s,selected:o,onToggle:e=>l("writeVariables",e),accent:"primary"})]}),_.jsxs("div",{className:"flex gap-3",children:[_.jsxs("div",{className:"flex-1 space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"超时秒数"}),_.jsx(U,{type:"number",min:1,value:e.timeoutSec,onChange:t=>r({...e,timeoutSec:Math.max(1,Number(t.target.value)||1)}),className:"h-8 text-xs"})]}),_.jsx("div",{className:"flex-1",children:_.jsx(ln,{value:e.next,allIds:t,selfId:e.id,onChange:t=>r({...e,next:t})})})]})]})}function dn({label:e,items:t,selected:s,onToggle:i,accent:r}){const n={green:"bg-emerald-500/15 border-emerald-500/40 text-emerald-700 dark:text-emerald-400",blue:"bg-blue-500/15 border-blue-500/40 text-blue-600 dark:text-blue-400",primary:"bg-primary/15 border-primary/40 text-primary"}[r];return _.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:e}),_.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.map(e=>{const t=s.includes(e.name);return _.jsx("button",{type:"button",onClick:()=>i(e.name),className:`px-2 py-1 rounded-md text-xs border transition-colors ${t?n:"bg-muted/30 border-border text-muted-foreground hover:text-foreground"}`,title:e.description||"(无描述)",children:_.jsx("span",{className:"font-mono",children:e.name})},e.name)})})]})}function un({node:e,allIds:t,variables:s,constants:i,onChange:r}){const n=t=>r({...e,branches:t});return _.jsxs("div",{className:"space-y-3",children:[_.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"分支规则 · 按顺序匹配,先命中先生效"}),e.branches.map((r,o)=>{const a=!!r.constant,l=r.constant??r.variable??"",h=(a?i:s).filter(e=>!!e.name);return _.jsxs("div",{className:"flex gap-1.5 items-center",children:[_.jsxs($t,{value:a?"const":"var",onValueChange:t=>{var a,l;const h=[...e.branches];h[o]="const"===t?{constant:(null==(a=i[0])?void 0:a.name)??"",equals:r.equals,goto:r.goto}:{variable:(null==(l=s[0])?void 0:l.name)??"",equals:r.equals,goto:r.goto},n(h)},children:[_.jsx(Kt,{className:"w-20 h-8 text-xs",children:_.jsx(Ut,{})}),_.jsxs(Vt,{children:[_.jsx(qt,{value:"var",disabled:0===s.length,children:"变量"}),_.jsx(qt,{value:"const",disabled:0===i.length,children:"常量"})]})]}),_.jsxs($t,{value:l,onValueChange:t=>{const s=[...e.branches];s[o]=a?{constant:t,equals:r.equals,goto:r.goto}:{variable:t,equals:r.equals,goto:r.goto},n(s)},children:[_.jsx(Kt,{className:"w-32 h-8 text-xs",children:_.jsx(Ut,{placeholder:"名字"})}),_.jsx(Vt,{children:h.map(e=>_.jsx(qt,{value:e.name,children:_.jsx("span",{className:"font-mono",children:e.name})},e.name))})]}),_.jsx("span",{className:"text-xs text-muted-foreground",children:"=="}),_.jsx(U,{value:"string"==typeof r.equals?r.equals:JSON.stringify(r.equals),onChange:t=>{const s=[...e.branches];let i=t.target.value;try{i=JSON.parse(t.target.value)}catch{}s[o]={...r,equals:i},n(s)},placeholder:'值(如 true, 10, "yes")',className:"w-32 h-8 font-mono text-xs"}),_.jsx("span",{className:"text-xs text-muted-foreground",children:"→"}),_.jsxs($t,{value:String(r.goto),onValueChange:t=>{const s=[...e.branches];s[o]={...r,goto:Number(t)},n(s)},children:[_.jsx(Kt,{className:"w-24 h-8 text-xs",children:_.jsx(Ut,{})}),_.jsx(Vt,{children:t.map(e=>_.jsxs(qt,{value:String(e),children:["#",e]},e))})]}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>n(e.branches.filter((e,t)=>t!==o)),children:_.jsx(S,{className:"h-3.5 w-3.5"})})]},o)}),_.jsxs(F,{size:"sm",variant:"ghost",onClick:()=>{var t;const r=s.length>0?{variable:s[0].name,equals:!0,goto:e.id}:{constant:(null==(t=i[0])?void 0:t.name)??"",equals:!0,goto:e.id};n([...e.branches,r])},className:"h-7 text-xs",disabled:0===s.length&&0===i.length,children:[_.jsx(K,{className:"h-3.5 w-3.5 mr-1"})," 添加分支"]})]}),_.jsxs("div",{className:"flex gap-3",children:[_.jsxs("div",{className:"flex-1 space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"回边上限"}),_.jsx(U,{type:"number",min:0,value:e.maxRetries,onChange:t=>r({...e,maxRetries:Math.max(0,Number(t.target.value)||0)}),className:"h-8 text-xs"})]}),_.jsx("div",{className:"flex-1",children:_.jsx(ln,{value:e.defaultGoto??null,allIds:t,selfId:e.id,onChange:t=>r({...e,defaultGoto:t}),label:"默认 (无分支命中)"})})]})]})}function fn({nodes:e,entryNodeId:t,mode:s,state:i,onNodeClick:r}){const n=l.useMemo(()=>function(e,t){const s=new Map(e.map(e=>[e.id,e])),i=[],r=new Set,n=[t];for(;n.length;){const e=n.pop();if(r.has(e))continue;const t=s.get(e);if(!t)continue;r.add(e),i.push(e);const o=[];if("user-input"===t.kind||"llm"===t.kind)null!=t.next&&o.push(t.next);else if("system-logic"===t.kind){null!=t.defaultGoto&&o.push(t.defaultGoto);for(const e of t.branches)o.push(e.goto)}for(let s=o.length-1;s>=0;s--)n.push(o[s])}for(const o of e)r.has(o.id)||i.push(o.id);return i}(e,t),[e,t]),o=l.useMemo(()=>new Map(e.map(e=>[e.id,e])),[e]),a=l.useMemo(()=>new Set(((null==i?void 0:i.history)??[]).map(e=>e.nodeId)),[null==i?void 0:i.history]);return 0===n.length?_.jsx("div",{className:"text-xs text-muted-foreground px-3 py-2",children:"空流,添加节点以构建链路"}):_.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto py-2 px-3 scrollbar-thin",children:n.map((e,t)=>{const h=o.get(e);if(!h)return null;const c="user-input"===(d=h.kind)?Qt:"llm"===d?ss:hs;var d;const u="runtime"===s?function(e,t,s,i){return"completed"===i||"failed"===i||"aborted"===i?s.has(e)?"completed":"future":t===e?"current":s.has(e)?"completed":"future"}(e,null==i?void 0:i.currentNodeId,a,null==i?void 0:i.status):null,f=[];if("system-logic"===h.kind)for(const s of h.branches){const e=n.indexOf(s.goto);-1!==e&&e<t&&f.push(s.goto)}return _.jsxs(l.Fragment,{children:[_.jsxs("button",{type:"button",onClick:()=>null==r?void 0:r(e),disabled:!r,className:m("group flex-shrink-0 flex items-center gap-1.5 px-2.5 py-1 rounded-md border text-xs transition-all","editor"===s&&["user-input"===h.kind&&"bg-amber-500/10 border-amber-500/30 text-amber-700 dark:text-amber-300","llm"===h.kind&&"bg-primary/10 border-primary/30 text-primary","system-logic"===h.kind&&"bg-purple-500/10 border-purple-500/30 text-purple-700 dark:text-purple-300",r&&"hover:scale-105 cursor-pointer"],"runtime"===s&&["completed"===u&&"bg-emerald-500/15 border-emerald-500/40 text-emerald-700 dark:text-emerald-400","current"===u&&"bg-primary/15 border-primary text-primary ring-2 ring-primary/30 animate-pulse","future"===u&&"bg-muted/40 border-border text-muted-foreground"]),title:`#${h.id} · ${h.name}`,children:["runtime"===s&&"completed"===u&&_.jsx(Jt,{className:"h-3 w-3"}),"runtime"===s&&"current"===u&&_.jsx(is,{className:"h-3 w-3"}),"runtime"===s&&"future"===u&&_.jsx(Nt,{className:"h-3 w-3"}),"editor"===s&&_.jsx(c,{className:"h-3 w-3"}),_.jsxs("span",{className:"font-mono opacity-70",children:["#",h.id]}),_.jsx("span",{className:"max-w-[7rem] truncate",children:h.name}),f.length>0&&_.jsxs("span",{className:"flex items-center gap-0.5 ml-0.5 text-[10px] opacity-70",title:`回边 → ${f.map(e=>"#"+e).join(", ")}`,children:[_.jsx(ws,{className:"h-2.5 w-2.5"}),f.map(e=>"#"+e).join("")]})]}),t<n.length-1&&_.jsx(I,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground/50"})]},e)})})}const _n={"user-input":"用户输入",llm:"LLM","system-logic":"系统逻辑"},mn={"user-input":"弹框收集用户填写的字段,系统写入到输出文件",llm:"把 prompt 模板(含 {{file:...}} 插值)通过 chat 注入 agent","system-logic":"读 JSON 文件按字段值分支跳转,支持回边循环"};function pn({open:e,onOpenChange:t,allIds:s,danglingPredecessors:i,onCreate:r}){const[n,o]=l.useState(""),[a,h]=l.useState("llm"),[c,d]=l.useState(i[0]??null),u=()=>{const e=n.trim()||`新${_n[a]}节点`;r({name:e,kind:a,wireFrom:c}),o(""),t(!1)};return _.jsx(ye,{open:e,onOpenChange:t,children:_.jsxs(Ce,{className:"max-w-md",children:[_.jsx(ke,{children:_.jsx(Ne,{children:"添加节点"})}),_.jsxs("div",{className:"space-y-3",children:[_.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"节点名称"}),_.jsx(U,{value:n,onChange:e=>o(e.target.value),placeholder:`新${_n[a]}节点`,autoFocus:!0,onKeyDown:e=>{"Enter"===e.key&&u()}})]}),_.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"类型"}),_.jsxs($t,{value:a,onValueChange:e=>h(e),children:[_.jsx(Kt,{children:_.jsx(Ut,{})}),_.jsx(Vt,{children:["user-input","llm","system-logic"].map(e=>_.jsx(qt,{value:e,children:_n[e]},e))})]}),_.jsx("p",{className:"text-xs text-muted-foreground pt-0.5",children:mn[a]})]}),s.length>0&&_.jsxs("div",{className:"space-y-1.5",children:[_.jsxs(Ee,{className:"text-xs text-muted-foreground",children:["自动接到哪个节点之后?",null!=i[0]&&_.jsxs("span",{className:"ml-1 opacity-60",children:["(默认接「#",i[0],"」未连出口的尾节点)"]})]}),_.jsxs($t,{value:null==c?"none":String(c),onValueChange:e=>d("none"===e?null:Number(e)),children:[_.jsx(Kt,{children:_.jsx(Ut,{})}),_.jsxs(Vt,{children:[_.jsx(qt,{value:"none",children:"不自动连接(之后手动配 next)"}),s.map(e=>_.jsxs(qt,{value:String(e),children:["接到 #",e," 之后",i.includes(e)&&"(推荐)"]},e))]})]})]})]}),_.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>t(!1),children:"取消"}),_.jsx(F,{size:"sm",onClick:u,children:"创建"})]})]})})}function gn({def:e,onCancel:t,onSave:s}){const[i,r]=l.useState(()=>({...e,schemaVersion:2})),[n,o]=l.useState(!1),a=l.useRef({}),h=l.useMemo(()=>i.nodes.map(e=>e.id),[i.nodes]),c=l.useMemo(()=>i.nodes.filter(e=>"user-input"===e.kind||"llm"===e.kind?null===e.next:null==e.defaultGoto&&0===e.branches.length).map(e=>e.id),[i.nodes]),d=(e,t)=>{r(s=>({...s,nodes:s.nodes.map(s=>{if("user-input"===s.kind)return{...s,userInputSchema:{fields:s.userInputSchema.fields.map(s=>{if("variable"===t&&(s.outputVariable===e||s.bindVariable===e)){const{outputVariable:e,bindVariable:t,...i}=s;return i}if("constant"===t&&s.bindConstant===e){const{bindConstant:e,...t}=s;return t}return s})}};if("llm"===s.kind){const i={...s};return"variable"===t?(i.readVariables&&(i.readVariables=i.readVariables.filter(t=>t!==e)),i.writeVariables&&(i.writeVariables=i.writeVariables.filter(t=>t!==e))):i.readConstants&&(i.readConstants=i.readConstants.filter(t=>t!==e)),i}return"system-logic"===s.kind?{...s,branches:s.branches.filter(s=>"variable"===t?s.variable!==e:s.constant!==e)}:s})}))};return _.jsxs("div",{className:"flex-1 flex flex-col min-h-0 gap-3",children:[_.jsxs("div",{className:"grid grid-cols-2 gap-3 flex-shrink-0",children:[_.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"流名称"}),_.jsx(U,{value:i.name,onChange:e=>r({...i,name:e.target.value}),className:"h-8"})]}),_.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"入口节点"}),_.jsxs($t,{value:String(i.entryNodeId),onValueChange:e=>r({...i,entryNodeId:Number(e)}),children:[_.jsx(Kt,{className:"h-8 text-xs",children:_.jsx(Ut,{})}),_.jsx(Vt,{children:h.map(e=>_.jsxs(qt,{value:String(e),children:["#",e]},e))})]})]}),_.jsxs("div",{className:"col-span-2 space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"描述(可选)"}),_.jsx(U,{value:i.description??"",onChange:e=>r({...i,description:e.target.value}),className:"h-8"})]})]}),_.jsx(vn,{constants:i.constants??[],onChange:e=>r({...i,constants:e}),onDelete:e=>{r(t=>({...t,constants:(t.constants??[]).filter(t=>t.name!==e)})),d(e,"constant")}}),_.jsx(xn,{variables:i.variables??[],constants:i.constants??[],onChange:e=>r({...i,variables:e}),onDelete:e=>{r(t=>({...t,variables:(t.variables??[]).filter(t=>t.name!==e)})),d(e,"variable")}}),_.jsx("div",{className:"flex-shrink-0 border border-border rounded-xl bg-muted/30",children:_.jsx(fn,{nodes:i.nodes,entryNodeId:i.entryNodeId,mode:"editor",onNodeClick:e=>{var t;null==(t=a.current[e])||t.scrollIntoView({behavior:"smooth",block:"center"})}})}),_.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-3 pr-1",children:i.nodes.map(e=>_.jsx("div",{ref:t=>{a.current[e.id]=t},children:_.jsx(on,{node:e,allIds:h,variables:i.variables??[],constants:i.constants??[],onChange:t=>((e,t)=>{r({...i,nodes:i.nodes.map(s=>s.id===e?t:s)})})(e.id,t),onDelete:()=>(e=>{if(i.nodes.length<=1)return;const t=i.nodes.filter(t=>t.id!==e).map(t=>"user-input"===t.kind||"llm"===t.kind?t.next===e?{...t,next:null}:t:{...t,branches:t.branches.filter(t=>t.goto!==e),defaultGoto:t.defaultGoto===e?null:t.defaultGoto??null});r({...i,nodes:t,entryNodeId:i.entryNodeId===e?t[0].id:i.entryNodeId})})(e.id)})},e.id))}),_.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 pt-2 border-t border-border",children:[_.jsxs(F,{size:"sm",variant:"outline",onClick:()=>o(!0),children:[_.jsx(K,{className:"h-4 w-4 mr-1"})," 添加节点"]}),_.jsx("div",{className:"flex-1"}),_.jsx(F,{size:"sm",variant:"ghost",onClick:t,children:"取消"}),_.jsx(F,{size:"sm",onClick:()=>s(i),children:"保存"})]}),_.jsx(pn,{open:n,onOpenChange:o,allIds:h,danglingPredecessors:c,onCreate:({name:e,kind:t,wireFrom:s})=>{const n=(Math.max(0,...h)||0)+1,o=function(e,t,s){return"user-input"===e?{id:t,name:s,kind:"user-input",userInputSchema:{fields:[{key:"",label:"",type:"text"}]},next:null}:"llm"===e?{id:t,name:s,kind:"llm",promptTemplate:"",timeoutSec:600,next:null}:{id:t,name:s,kind:"system-logic",branches:[],maxRetries:3,defaultGoto:null}}(t,n,e);let l=[...i.nodes,o];null!=s&&(l=l.map(e=>e.id!==s?e:"user-input"===e.kind||"llm"===e.kind?{...e,next:n}:{...e,defaultGoto:n})),r({...i,nodes:l}),setTimeout(()=>{var e;null==(e=a.current[n])||e.scrollIntoView({behavior:"smooth",block:"center"})},50)}})]})}function vn({constants:e,onChange:t,onDelete:s}){const i=l.useMemo(()=>{const t=new Map;for(const s of e)t.set(s.name,(t.get(s.name)??0)+1);return t},[e]),r=(s,i)=>{t(e.map((e,t)=>s===t?{...e,...i}:e))};return _.jsxs("div",{className:"flex-shrink-0 border border-border rounded-xl bg-card p-3 space-y-2",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(Ee,{className:"text-sm font-medium",children:"常量"}),_.jsx("span",{className:"text-xs text-muted-foreground",children:"流定义时固定,运行时不可写。任意 JSON(字符串/数字/布尔/数组/对象)"}),_.jsx("div",{className:"flex-1"}),_.jsxs(F,{size:"sm",variant:"ghost",onClick:()=>t([...e,{name:"",value:"",description:""}]),className:"h-7 text-xs",children:[_.jsx(K,{className:"h-3.5 w-3.5 mr-1"})," 添加常量"]})]}),0===e.length&&_.jsx("p",{className:"text-xs text-muted-foreground italic px-1",children:"暂无常量。"}),e.map((n,o)=>{const a=!!n.name&&(i.get(n.name)??0)>1;return _.jsx(bn,{name:n.name,value:n.value,description:n.description??"",duplicate:a,onChangeName:e=>r(o,{name:e.trim()}),onChangeValue:e=>r(o,{value:e}),onChangeDescription:e=>r(o,{description:e}),onRemove:()=>(i=>{const r=e[i];r.name?s(r.name):t(e.filter((e,t)=>t!==i))})(o)},o)})]})}function xn({variables:e,constants:t,onChange:s,onDelete:i}){const r=l.useMemo(()=>{const t=new Map;for(const s of e)t.set(s.name,(t.get(s.name)??0)+1);return t},[e]),n=l.useMemo(()=>new Set(t.map(e=>e.name)),[t]),o=(t,i)=>{s(e.map((e,s)=>t===s?{...e,...i}:e))};return _.jsxs("div",{className:"flex-shrink-0 border border-border rounded-xl bg-card p-3 space-y-2",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(Ee,{className:"text-sm font-medium",children:"变量"}),_.jsx("span",{className:"text-xs text-muted-foreground",children:"运行时可写。user-input 字段或 LLM 节点产出;任意 JSON"}),_.jsx("div",{className:"flex-1"}),_.jsxs(F,{size:"sm",variant:"ghost",onClick:()=>s([...e,{name:"",description:"",initialValue:void 0}]),className:"h-7 text-xs",children:[_.jsx(K,{className:"h-3.5 w-3.5 mr-1"})," 添加变量"]})]}),0===e.length&&_.jsx("p",{className:"text-xs text-muted-foreground italic px-1",children:"暂无变量。"}),e.map((t,a)=>{const l=!!t.name&&(r.get(t.name)??0)>1||n.has(t.name);return _.jsx(bn,{name:t.name,value:t.initialValue,description:t.description,duplicate:l,valuePlaceholder:"初始值(可选,留空 = undefined)",onChangeName:e=>o(a,{name:e.trim()}),onChangeValue:e=>o(a,{initialValue:e}),onChangeDescription:e=>o(a,{description:e}),onRemove:()=>(t=>{const r=e[t];r.name?i(r.name):s(e.filter((e,s)=>s!==t))})(a)},a)})]})}function bn({name:e,value:t,description:s,duplicate:i,valuePlaceholder:r,onChangeName:n,onChangeValue:o,onChangeDescription:a,onRemove:h}){const[c,d]=l.useState(()=>void 0===t?"":"string"==typeof t?t:JSON.stringify(t,null,2)),[u,f]=l.useState(!1);return _.jsx("div",{className:"space-y-1.5 rounded-md border border-border/60 p-2",children:_.jsxs("div",{className:"flex gap-1.5 items-start",children:[_.jsxs("div",{className:"flex flex-col gap-1.5 w-32",children:[_.jsx(U,{value:e,onChange:e=>n(e.target.value),placeholder:"名字",className:"h-8 font-mono text-xs "+(i?"border-destructive":"")}),i&&_.jsxs("span",{title:"名字冲突(与常量/变量重名)",className:"text-destructive flex items-center text-[10px]",children:[_.jsx(Yt,{className:"h-3 w-3 mr-1"}),"重名"]})]}),_.jsxs("div",{className:"flex-1 space-y-1",children:[_.jsx("textarea",{value:c,onChange:e=>d(e.target.value),onBlur:()=>{if(""===c.trim())return o(void 0),void f(!1);try{const e=JSON.parse(c);o(e),f(!1)}catch{o(c),f(!0)}},placeholder:r??'JSON 值(如 10, "hi", [1,2], {"k":"v"})',className:"w-full min-h-[32px] rounded-md border border-border bg-background px-2 py-1 text-xs font-mono resize-y outline-none focus:ring-2 focus:ring-ring/30",rows:1}),u&&_.jsx("span",{className:"text-[10px] text-amber-600 dark:text-amber-400",children:"非合法 JSON — 已按字符串字面量保存"})]}),_.jsx(U,{value:s,onChange:e=>a(e.target.value),placeholder:"含义(LLM 引用时使用)",className:"flex-1 h-8 text-xs"}),_.jsx(F,{size:"sm",variant:"ghost",onClick:h,className:"h-8 w-8 p-0",children:_.jsx(S,{className:"h-3.5 w-3.5"})})]})})}function Sn(e){return{schemaVersion:2,id:tn(),name:e,description:"",entryNodeId:1,constants:[],variables:[{name:"goal",description:"研究目标"}],nodes:[{id:1,name:"初始化",kind:"user-input",userInputSchema:{fields:[{key:"goal",label:"研究目标",type:"text",outputVariable:"goal"}]},next:null}]}}function wn({projectId:e,open:t,onOpenChange:s}){const i=a(),[r,n]=l.useState("project"),[o,h]=l.useState([]),[c,d]=l.useState(!1),[u,m]=l.useState(null),[p,v]=l.useState(""),x=async(t=r)=>{d(!0);try{const s="global"===t?await sn("GET","/api/global/flows"):await function(e){return sn("GET",`/api/projects/${e}/flows`)}(e);h(s.files)}catch(s){f.error(s instanceof Error?s.message:"加载失败")}finally{d(!1)}};l.useEffect(()=>{t&&x(r)},[t,e,r]),l.useEffect(()=>{v("")},[r]);const b=()=>{const e=p.trim();if(!e)return void f.error("请输入流名称");const t=e.endsWith(".json")?e:`${e}.json`;m({filename:t,def:Sn(e.replace(/\.json$/,"")),source:r}),v("")},S=async t=>{try{const s="global"===r?await function(e){return sn("GET",`/api/global/flows/file/${encodeURIComponent(e)}`)}(t):await rn(e,t);m({filename:t,def:s,source:r})}catch(s){f.error(s instanceof Error?s.message:"读取失败")}},w=async(t,s,i)=>{try{"global"===i?await function(e,t){return sn("PUT",`/api/global/flows/file/${encodeURIComponent(e)}`,t)}(t,s):await function(e,t,s){return sn("PUT",`/api/projects/${e}/flows/file/${encodeURIComponent(t)}`,s)}(e,t,s),f.success("已保存"),m(null),x()}catch(r){f.error(r instanceof Error?r.message:"保存失败")}},y=async t=>{const s="global"===r?"全局任务流":"任务流";if(await i({description:`删除${s} ${t}?此操作不可恢复。`,confirmLabel:"删除",destructive:!0}))try{"global"===r?await function(e){return sn("DELETE",`/api/global/flows/file/${encodeURIComponent(e)}`)}(t):await function(e,t){return sn("DELETE",`/api/projects/${e}/flows/file/${encodeURIComponent(t)}`)}(e,t),f.success("已删除"),x()}catch(n){f.error(n instanceof Error?n.message:"删除失败")}},C=async t=>{try{await function(e,t,s="project"){return sn("POST",`/api/projects/${e}/flows/run`,{filename:t,source:s})}(e,t,r),f.success("任务流已启动"),s(!1)}catch(i){f.error(i instanceof Error?i.message:"启动失败")}};if(u){const e="global"===u.source?"(全局)":"";return _.jsx(ye,{open:t,onOpenChange:s,children:_.jsxs(Ce,{className:"max-w-4xl h-[80vh] flex flex-col",children:[_.jsx(ke,{children:_.jsxs(Ne,{children:["编辑任务流",e," · ",u.filename]})}),_.jsx(gn,{def:u.def,onCancel:()=>m(null),onSave:e=>w(u.filename,e,u.source)})]})})}return _.jsx(ye,{open:t,onOpenChange:s,children:_.jsxs(Ce,{className:"max-w-2xl",children:[_.jsx(ke,{children:_.jsx(Ne,{className:"text-lg font-semibold",children:"任务流"})}),_.jsx(Dt,{value:r,onValueChange:e=>n(e),children:_.jsxs(Rt,{children:[_.jsx(Lt,{value:"project",children:"项目流"}),_.jsx(Lt,{value:"global",children:"我的全局流"})]})}),"global"===r&&_.jsx("p",{className:"text-xs text-muted-foreground",children:"全局流是可复用的模板,运行时仍绑定到当前项目(PTY 与文件路径来自该项目)。"}),_.jsxs("div",{className:"flex gap-2 items-center",children:[_.jsx(U,{placeholder:"global"===r?"新全局流名称":"新流名称(例:research)",value:p,onChange:e=>v(e.target.value),onKeyDown:e=>{"Enter"===e.key&&b()},className:"flex-1"}),_.jsxs(F,{onClick:b,size:"sm",children:[_.jsx(K,{className:"h-4 w-4 mr-1"})," 新建"]}),_.jsx(F,{onClick:()=>x(),size:"sm",variant:"ghost",disabled:c,children:_.jsx(L,{className:"h-4 w-4 "+(c?"animate-spin":"")})})]}),_.jsxs("div",{className:"space-y-1 max-h-[55vh] overflow-y-auto",children:[0===o.length&&!c&&_.jsx("p",{className:"text-sm text-muted-foreground py-8 text-center",children:"global"===r?"暂无全局任务流。新建一个开始。":"暂无任务流。新建一个开始。"}),o.map(e=>_.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-border hover:bg-accent transition-colors",children:[_.jsx("span",{className:"flex-1 text-sm font-mono truncate",title:e,children:e}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>C(e),title:"运行",children:_.jsx(xs,{className:"h-4 w-4"})}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>S(e),title:"编辑",children:_.jsx(g,{className:"h-4 w-4"})}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>y(e),title:"删除",children:_.jsx(R,{className:"h-4 w-4"})})]},e))]})]})})}async function yn(e,t,s){const i={"Content-Type":"application/json"},r=c();r&&(i.Authorization=`Bearer ${r}`);const n=await fetch(t,{method:e,headers:i,body:void 0!==s?JSON.stringify(s):void 0});if(!n.ok){let e=`HTTP ${n.status}`;try{const t=await n.json();t.error&&(e=t.error)}catch{}throw new Error(e)}return n.json()}function Cn(e){return yn("POST",`/api/projects/${e}/tracks/abort`)}const kn=l.lazy(()=>N(()=>import("./TrackEditor-CCPaBF-8.js"),__vite__mapDeps([13,1,2])).then(e=>({default:e.TrackEditor})));function Nn({projectId:e,open:t,onOpenChange:s}){const i=a(),[r,n]=l.useState("project"),[o,h]=l.useState([]),[c,d]=l.useState(!1),[u,m]=l.useState(null),[p,v]=l.useState(""),[x,b]=l.useState("basic"),S=async(t=r)=>{d(!0);try{const s="global"===t?await yn("GET","/api/global/tracks"):await function(e){return yn("GET",`/api/projects/${e}/tracks`)}(e);h(s.files)}catch(s){f.error(s instanceof Error?s.message:"加载失败")}finally{d(!1)}};l.useEffect(()=>{t&&S(r)},[t,e,r]),l.useEffect(()=>{v("")},[r]);const w=()=>{const e=p.trim();if(!e)return void f.error("请输入工作轨名称");const t=e.endsWith(".tr")?e:`${e}.tr`;m({filename:t,src:"ask_user"===x?'// Starter track with __ccweb_ask_user — pauses for user input.\n//\n// __ccweb_ask_user(spec) blocks until the user submits the dialog.\n// Field types: text / number / bool / enum (with variants).\n\nfai analyze(file_path: string, prompt: prompt)\n -> rating: int 0-10, comment: string maxLen=500 {\n}\n\nfunc main(input_path: string) -> object {\n let r = analyze(input_path, "请对此文件评分 0-10")\n\n // Pause and ask user to confirm or override the AI rating.\n let review = __ccweb_ask_user({\n fields: [\n { key: "decision", label: "AI 评分: " + r.rating + ",是否接受?", type: "enum", variants: ["accept", "override"] }\n ]\n })\n\n return { aiRating: r.rating, decision: review.decision, comment: r.comment }\n}\n\nexport main\n':'// Starter track — edit and save, then run.\n//\n// Reference: ~/Obsidian/Base/cc-web/工作流DSL.md (train-lang spec)\n\nfai analyze(file_path: string, prompt: prompt)\n -> rating: int 0-10, comment: string maxLen=500 {\n}\n\nfunc main(input_path: string) -> object {\n let r = analyze(input_path, "请对此文件评分 0-10,并简短说明")\n return r\n}\n\nexport main\n',source:r}),v("")},y=async t=>{try{const s="global"===r?await function(e){return yn("GET",`/api/global/tracks/file/${encodeURIComponent(e)}`)}(t):await function(e,t){return yn("GET",`/api/projects/${e}/tracks/file/${encodeURIComponent(t)}`)}(e,t);m({filename:t,src:s.source,source:r})}catch(s){f.error(s instanceof Error?s.message:"读取失败")}},C=async(t,s,i)=>{try{"global"===i?await function(e,t){return yn("PUT",`/api/global/tracks/file/${encodeURIComponent(e)}`,{source:t})}(t,s):await function(e,t,s){return yn("PUT",`/api/projects/${e}/tracks/file/${encodeURIComponent(t)}`,{source:s})}(e,t,s),f.success("已保存"),m(null),S()}catch(r){f.error(r instanceof Error?r.message:"保存失败")}},k=async t=>{const s="global"===r?"全局工作轨":"工作轨";if(await i({description:`删除${s} ${t}?此操作不可恢复。`,confirmLabel:"删除",destructive:!0}))try{"global"===r?await function(e){return yn("DELETE",`/api/global/tracks/file/${encodeURIComponent(e)}`)}(t):await function(e,t){return yn("DELETE",`/api/projects/${e}/tracks/file/${encodeURIComponent(t)}`)}(e,t),f.success("已删除"),S()}catch(n){f.error(n instanceof Error?n.message:"删除失败")}},N=async t=>{try{await function(e,t,s="project",i=[]){return yn("POST",`/api/projects/${e}/tracks/run`,{filename:t,source:s,args:i})}(e,t,r),f.success("工作轨已启动"),s(!1)}catch(i){f.error(i instanceof Error?i.message:"启动失败")}};if(u){const e="global"===u.source?"(全局)":"";return _.jsx(ye,{open:t,onOpenChange:s,children:_.jsxs(Ce,{className:"max-w-4xl h-[80vh] flex flex-col",children:[_.jsx(ke,{children:_.jsxs(Ne,{children:["编辑工作轨",e," · ",u.filename]})}),_.jsx(l.Suspense,{fallback:_.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"加载编辑器…"}),children:_.jsx(kn,{filename:u.filename,initialSource:u.src,onCancel:()=>m(null),onSave:e=>C(u.filename,e,u.source)})})]})})}return _.jsx(ye,{open:t,onOpenChange:s,children:_.jsxs(Ce,{className:"max-w-2xl",children:[_.jsx(ke,{children:_.jsx(Ne,{className:"text-lg font-semibold",children:"工作轨"})}),_.jsx(Dt,{value:r,onValueChange:e=>n(e),children:_.jsxs(Rt,{children:[_.jsx(Lt,{value:"project",children:"项目轨"}),_.jsx(Lt,{value:"global",children:"我的全局轨"})]})}),"global"===r&&_.jsx("p",{className:"text-xs text-muted-foreground",children:"全局轨是可复用的模板,运行时仍绑定到当前项目(PTY 与文件路径来自该项目)。"}),_.jsxs("div",{className:"flex gap-2 items-center",children:[_.jsx(U,{placeholder:"global"===r?"新全局轨名称":"新工作轨名称(例:review)",value:p,onChange:e=>v(e.target.value),onKeyDown:e=>{"Enter"===e.key&&w()},className:"flex-1"}),_.jsxs("select",{value:x,onChange:e=>b(e.target.value),className:"text-xs h-9 px-2 rounded-md border border-border bg-background",title:"新建时使用的初始模板",children:[_.jsx("option",{value:"basic",children:"基础模板"}),_.jsx("option",{value:"ask_user",children:"含 ask_user"})]}),_.jsxs(F,{onClick:w,size:"sm",children:[_.jsx(K,{className:"h-4 w-4 mr-1"})," 新建"]}),_.jsx(F,{onClick:()=>S(),size:"sm",variant:"ghost",disabled:c,children:_.jsx(L,{className:"h-4 w-4 "+(c?"animate-spin":"")})})]}),_.jsxs("div",{className:"space-y-1 max-h-[55vh] overflow-y-auto",children:[0===o.length&&!c&&_.jsx("p",{className:"text-sm text-muted-foreground py-8 text-center",children:"global"===r?"暂无全局工作轨。新建一个开始。":"暂无工作轨。新建一个开始。"}),o.map(e=>_.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-border hover:bg-accent transition-colors",children:[_.jsx("span",{className:"flex-1 text-sm font-mono truncate",title:e.filename,children:e.filename}),_.jsxs("span",{className:"text-xs text-muted-foreground tabular-nums",children:[Math.round(e.size/100)/10,"KB"]}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>N(e.filename),title:"运行",children:_.jsx(xs,{className:"h-4 w-4"})}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>y(e.filename),title:"编辑",children:_.jsx(g,{className:"h-4 w-4"})}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>k(e.filename),title:"删除",children:_.jsx(R,{className:"h-4 w-4"})})]},e.filename))]})]})})}function jn({projectId:e,state:t,running:s,onRefresh:i}){if(!t)return null;let r=_.jsx(Ve,{className:"h-3 w-3 animate-spin"}),n="text-blue-600 dark:text-blue-400",o="运行中";switch(t.status){case"running":r=_.jsx(Ve,{className:"h-3 w-3 animate-spin"}),n="text-blue-600 dark:text-blue-400",o="运行中";break;case"paused":r=_.jsx(Ve,{className:"h-3 w-3"}),n="text-amber-600 dark:text-amber-400",o="等待输入";break;case"completed":r=_.jsx(Jt,{className:"h-3 w-3"}),n="text-emerald-600 dark:text-emerald-400",o="已完成";break;case"failed":r=_.jsx(ts,{className:"h-3 w-3"}),n="text-red-600 dark:text-red-400",o="失败";break;case"cancelled":r=_.jsx(ts,{className:"h-3 w-3"}),n="text-muted-foreground",o="已取消";break;default:r=_.jsx(Ve,{className:"h-3 w-3"})}return _.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[_.jsxs("span",{className:`flex items-center gap-1 ${n}`,children:[r,_.jsx("span",{className:"font-medium",children:o})]}),_.jsx("span",{className:"text-muted-foreground font-mono truncate max-w-[200px]",children:t.trackFilename}),void 0!==t.currentTaskIndex&&_.jsxs("span",{className:"text-muted-foreground",children:["#",t.currentTaskIndex]}),s&&_.jsx(F,{size:"sm",variant:"ghost",onClick:async()=>{try{await Cn(e),f.success("已请求中止"),i()}catch(t){f.error(t instanceof Error?t.message:"中止失败")}},title:"中止",className:"h-6 w-6 p-0",children:_.jsx(S,{className:"h-3 w-3"})}),"failed"===t.status&&t.error&&_.jsxs("span",{className:"text-red-600 dark:text-red-400 truncate max-w-[300px] font-mono",title:`${t.error.errorType}${t.error.code?` [${t.error.code}]`:""}: ${t.error.message}`,children:[t.error.code?`[${t.error.code}] `:"",t.error.message]})]})}function En({projectId:e,open:t,request:s,onSubmitted:i}){const r=a(),[n,o]=l.useState(()=>{var e;const t={};for(const i of s.fields)switch(i.type){case"bool":t[i.key]=!1;break;case"number":t[i.key]=0;break;case"enum":t[i.key]=(null==(e=i.variants)?void 0:e[0])??"";break;default:t[i.key]=""}return t}),[h,c]=l.useState(!1),d=(e,t)=>{o(s=>({...s,[e]:t}))};return _.jsx(ye,{open:t,onOpenChange:()=>{},children:_.jsxs(Ce,{className:"max-w-lg",onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),children:[_.jsx(ke,{children:_.jsx(Ne,{children:"工作轨需要输入"})}),_.jsx("div",{className:"space-y-3",children:s.fields.map(e=>_.jsxs("div",{className:"space-y-1.5",children:[_.jsxs(Ee,{className:"text-xs text-muted-foreground",children:[e.label," ",_.jsxs("span",{className:"opacity-60 font-mono",children:["(",e.key,")"]})]}),"text"===e.type&&_.jsx(U,{value:n[e.key]??"",placeholder:e.placeholder,onChange:t=>d(e.key,t.target.value)}),"number"===e.type&&_.jsx(U,{type:"number",value:String(n[e.key]??""),placeholder:e.placeholder,onChange:t=>{const s=Number(t.target.value);d(e.key,Number.isNaN(s)?"":s)}}),"bool"===e.type&&_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx("input",{type:"checkbox",checked:!!n[e.key],onChange:t=>d(e.key,t.target.checked),className:"h-4 w-4"}),_.jsx("span",{className:"text-sm",children:n[e.key]?"是":"否"})]}),"enum"===e.type&&_.jsxs($t,{value:n[e.key]??"",onValueChange:t=>d(e.key,t),children:[_.jsx(Kt,{children:_.jsx(Ut,{placeholder:"选择..."})}),_.jsx(Vt,{children:(e.variants??[]).map(e=>_.jsx(qt,{value:e,children:e},e))})]})]},e.key))}),_.jsxs("div",{className:"flex justify-between items-center gap-2 pt-2",children:[_.jsx(F,{onClick:async()=>{if(await r({description:"中止整个工作轨运行?正在等待的 LLM 调用会被取消。",confirmLabel:"中止",destructive:!0}))try{await Cn(e),f.success("已请求中止"),i()}catch(t){f.error(t instanceof Error?t.message:"中止失败")}},variant:"ghost",size:"sm",disabled:h,className:"text-muted-foreground hover:text-destructive",children:"中止运行"}),_.jsx(F,{onClick:async()=>{c(!0);try{await function(e,t,s){return yn("POST",`/api/projects/${e}/tracks/input`,{requestId:t,data:s})}(e,s.requestId,n),i()}catch(t){f.error(t instanceof Error?t.message:"提交失败")}finally{c(!1)}},disabled:h,size:"sm",children:h?"提交中…":"提交"})]})]})})}function Mn(e){const[t,s]=l.useState(null),[i,r]=l.useState(!1),[n,o]=l.useState(null),a=l.useRef(e);a.current=e;const h=l.useCallback(async()=>{const e=a.current;if(e)try{const t=await function(e){return yn("GET",`/api/projects/${e}/tracks/state`)}(e);if(e!==a.current)return;s(t.state),r(t.running),o(t.pendingAskUser)}catch{}},[]),c=l.useRef(5e3),d=!!t||i||!!n;return l.useEffect(()=>{if(!e)return;const t=e=>{const t=e.detail;if(t&&t.type)switch(t.type){case"track_status_change":{const e=t;s(e.state),r("running"===e.state.status||"paused"===e.state.status);break}case"track_ask_user":{const e=t;o({runId:e.runId,requestId:e.requestId,fields:e.fields});break}case"track_run_complete":t.ok||o(null);break}};return window.addEventListener("ccweb:track-msg",t),()=>window.removeEventListener("ccweb:track-msg",t)},[e]),l.useEffect(()=>{if(!e)return s(null),r(!1),void o(null);let t=null;const i=d?5e3:3e4;c.current=i;const n=()=>{h(),t=setInterval(()=>{h()},i)},a=()=>{null!==t&&(clearInterval(t),t=null)},l=()=>{document.hidden?a():t||n()};return document.hidden||n(),document.addEventListener("visibilitychange",l),()=>{a(),document.removeEventListener("visibilitychange",l)}},[e,h,d]),{state:t,running:i,pendingAskUser:n,refresh:h}}var Dn=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"].reduce((e,t)=>{const s=qe(`Primitive.${t}`),i=l.forwardRef((e,i)=>{const{asChild:r,...n}=e,o=r?s:t;return"undefined"!=typeof window&&(window[Symbol.for("radix-ui")]=!0),_.jsx(o,{...n,ref:i})});return i.displayName=`Primitive.${t}`,{...e,[t]:i}},{}),Rn="horizontal",Ln=["horizontal","vertical"],Pn=l.forwardRef((e,t)=>{const{decorative:s,orientation:i=Rn,...r}=e,n=function(e){return Ln.includes(e)}(i)?i:Rn,o=s?{role:"none"}:{"aria-orientation":"vertical"===n?n:void 0,role:"separator"};return _.jsx(Dn.div,{"data-orientation":n,...o,...r,ref:t})});Pn.displayName="Separator";var Tn=Pn;const Bn=l.forwardRef(({className:e,orientation:t="horizontal",decorative:s=!0,...i},r)=>_.jsx(Tn,{ref:r,decorative:s,orientation:t,className:m("shrink-0 bg-border","horizontal"===t?"h-[1px] w-full":"h-full w-[1px]",e),...i}));Bn.displayName=Tn.displayName;const In=[{tool:"claude",label:"Claude Code",supportsContinue:!0},{tool:"codex",label:"Codex",supportsContinue:!0},{tool:"gemini",label:"Gemini CLI",supportsContinue:!0},{tool:"opencode",label:"OpenCode",supportsContinue:!1},{tool:"qwen",label:"Qwen Code",supportsContinue:!1},{tool:"terminal",label:"Bare Shell",supportsContinue:!1}];function On(e){var t;return(null==(t=In.find(t=>t.tool===e))?void 0:t.label)??String(e??"")}function An(e){var t;return(null==(t=In.find(t=>t.tool===e))?void 0:t.supportsContinue)??!1}function zn({open:e,onOpenChange:t,currentCliTool:s,loading:i,onConfirm:r}){const{t:n}=Ye(),[o,a]=l.useState(null),[h,c]=l.useState(!1),[d,u]=l.useState(null);l.useEffect(()=>{e&&(a(null),c(!1),u(null))},[e]),l.useEffect(()=>{o&&!An(o)&&c(!1)},[o]);const f=!!o&&An(o);return _.jsx(ye,{open:e,onOpenChange:t,children:_.jsxs(Ce,{className:"max-w-lg",children:[_.jsxs(ke,{children:[_.jsx(Ne,{children:n("switch_cli.title")}),_.jsx(je,{children:n("switch_cli.description",{current:On(s)})})]}),_.jsxs("div",{className:"space-y-4",children:[_.jsxs("div",{className:"space-y-2",children:[_.jsx("div",{className:"text-sm font-medium",children:n("switch_cli.target_label")}),_.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:In.map(e=>{const t=e.tool===s,r=e.tool===o;return _.jsxs("button",{type:"button",disabled:t||i,onClick:()=>a(e.tool),className:m("text-left px-3 py-2 rounded-md border text-sm transition-colors",r?"border-primary bg-accent":"border-border hover:bg-accent/50",t&&"opacity-50 cursor-not-allowed"),children:[_.jsx("div",{className:"font-medium",children:e.label}),_.jsx("div",{className:"text-xs text-muted-foreground",children:t?n("switch_cli.tag_current"):e.supportsContinue?n("switch_cli.tag_supports_continue"):n("switch_cli.tag_no_continue")})]},e.tool)})})]}),_.jsxs("div",{className:"space-y-2",children:[_.jsx("div",{className:"text-sm font-medium",children:n("switch_cli.mode_label")}),_.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[_.jsxs("button",{type:"button",disabled:i,onClick:()=>c(!1),className:m("text-left px-3 py-2 rounded-md border text-sm transition-colors",h?"border-border hover:bg-accent/50":"border-primary bg-accent"),children:[_.jsx("div",{className:"font-medium",children:n("switch_cli.mode_fresh")}),_.jsx("div",{className:"text-xs text-muted-foreground",children:n("switch_cli.mode_fresh_hint")})]}),_.jsxs("button",{type:"button",disabled:i||!o||!f,onClick:()=>c(!0),title:o&&!f?n("switch_cli.mode_continue_unsupported",{tool:On(o)}):void 0,className:m("text-left px-3 py-2 rounded-md border text-sm transition-colors",h?"border-primary bg-accent":"border-border hover:bg-accent/50",(!o||!f)&&"opacity-50 cursor-not-allowed"),children:[_.jsx("div",{className:"font-medium",children:n("switch_cli.mode_continue")}),_.jsx("div",{className:"text-xs text-muted-foreground",children:o&&!f?n("switch_cli.mode_continue_unsupported",{tool:On(o)}):n("switch_cli.mode_continue_hint")})]})]})]}),d&&_.jsx("div",{className:"text-xs text-red-500 break-words",children:d})]}),_.jsxs(Me,{children:[_.jsx(F,{variant:"outline",onClick:()=>t(!1),disabled:i,children:n("switch_cli.cancel")}),_.jsx(F,{onClick:()=>{(async()=>{if(o){u(null);try{await r(o,h)}catch(e){u(e instanceof Error?e.message:String(e))}}})()},disabled:!o||i,children:n(i?"switch_cli.confirming":"switch_cli.confirm")})]})]})})}function Wn({status:e}){return _.jsxs("span",{className:m("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",{running:"bg-green-500/10 text-green-600 border-green-500/20",stopped:"bg-muted text-muted-foreground border-border",restarting:"bg-yellow-500/10 text-yellow-600 border-yellow-500/20"}[e]),children:[_.jsx("span",{className:m("w-1.5 h-1.5 rounded-full",{"bg-green-500":"running"===e,"bg-muted-foreground":"stopped"===e,"bg-yellow-400 animate-pulse":"restarting"===e})}),e.charAt(0).toUpperCase()+e.slice(1)]})}function Hn({project:e,projectId:t,showFileTree:s,showShortcuts:i,showChatOverlay:r,onToggleFileTree:n,onToggleShortcuts:o,onToggleChatOverlay:a,onProjectUpdate:h}){const{t:c}=Ye(),d=Ge(),[u,p]=l.useState(!1),[g,v]=l.useState(!1),[w,y]=l.useState(0),[C,k]=l.useState(!1),[N,j]=l.useState(!1),[E,M]=l.useState(!1),[D,R]=l.useState(!1),[P,T]=l.useState(!1),[B,I]=l.useState(!1),O=Mn(e.id);Xe({onStart:e=>{e.projectId===t&&y(0)},onProgress:e=>{e.projectId===t&&y(e.filesTransferred)},onDone:e=>{e.projectId===t&&y(0)}}),l.useEffect(()=>{const e=()=>j(!!document.fullscreenElement);return document.addEventListener("fullscreenchange",e),()=>document.removeEventListener("fullscreenchange",e)},[]);const A=Je(e=>e.updateProject);return _.jsx("header",{className:"border-b border-border flex-shrink-0 bg-muted/50",children:_.jsxs("div",{className:"px-3 h-12 flex items-center gap-2",children:[_.jsx(F,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>d("/"),children:_.jsx(Ze,{className:"h-4 w-4"})}),_.jsx(Bn,{orientation:"vertical",className:"h-5 mx-0.5"}),_.jsx(F,{variant:"ghost",size:"icon",className:m("h-7 w-7",s&&"bg-accent"),onClick:n,title:c("project_header.toggle_file_tree"),children:_.jsx(ps,{className:"h-4 w-4"})}),_.jsx(F,{variant:"ghost",size:"icon",className:m("h-7 w-7",i&&"bg-accent"),onClick:o,title:c("project_header.toggle_right_panel"),children:_.jsx(gs,{className:"h-4 w-4"})}),"terminal"!==e.cliTool&&_.jsx(F,{variant:"ghost",size:"icon",className:m("h-7 w-7",r&&"bg-accent"),onClick:a,title:c("project_header.toggle_chat_overlay"),children:_.jsx(fs,{className:"h-4 w-4"})}),"terminal"!==e.cliTool&&_.jsxs(_.Fragment,{children:[_.jsx(F,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>T(!0),title:"任务流(旧)",children:_.jsx(Cs,{className:"h-4 w-4"})}),_.jsx(F,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>I(!0),title:"工作轨",children:_.jsx(ys,{className:"h-4 w-4"})})]}),_.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2 ml-2",children:[_.jsx("h1",{className:"font-semibold text-foreground truncate text-sm",children:e.name}),_.jsx(Wn,{status:e.status}),_.jsx(Qe,{variant:"outline",className:"text-xs",children:"unlimited"===e.permissionMode?"Unlimited":"Limited"}),O.state&&_.jsx(jn,{projectId:e.id,state:O.state,running:O.running,onRefresh:O.refresh}),_.jsxs("button",{type:"button",onClick:()=>M(!0),disabled:D,title:`${c("project_header.switch_cli_title")} (${On(e.cliTool)})`,className:"inline-flex items-center gap-1 text-xs px-2 py-0.5 rounded-full border border-border bg-background hover:bg-accent transition-colors disabled:opacity-50 flex-shrink-0",children:[_.jsx(L,{className:"h-3 w-3"}),_.jsx("span",{className:"font-medium hidden sm:inline",children:On(e.cliTool)})]}),_.jsx("span",{className:"text-xs text-muted-foreground font-mono truncate hidden lg:block",children:e.folderPath})]}),_.jsx(et,{}),_.jsx(tt,{}),_.jsx(F,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>{document.fullscreenElement?document.exitFullscreen():document.documentElement.requestFullscreen()},title:c(N?"project_header.fullscreen_exit":"project_header.fullscreen_enter"),children:N?_.jsx(x,{className:"h-3.5 w-3.5"}):_.jsx(b,{className:"h-3.5 w-3.5"})}),_.jsx(Bn,{orientation:"vertical",className:"h-5 mx-0.5"}),g?_.jsxs(F,{variant:"outline",size:"sm",className:"flex-shrink-0",onClick:()=>{(async()=>{if(g&&!C){k(!0);try{(await it(t)).cancelled?f.info(c("project_header.sync_cancelled")):f.error(c("project_header.sync_cancel_failed"))}catch(e){f.error(e instanceof Error?e.message:c("project_header.sync_cancel_failed")),k(!1)}}})()},disabled:C,title:c("project_header.sync_cancel_title"),children:[C?_.jsx(Ve,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):_.jsx(S,{className:"h-3.5 w-3.5 mr-1.5"}),_.jsx("span",{className:"tabular-nums",children:w>0?c("project_header.sync_progress_label",{files:w}):c("project_header.sync_progress_label_empty")})]}):_.jsxs(F,{variant:"outline",size:"sm",className:"flex-shrink-0",onClick:()=>{(async()=>{if(!g){v(!0),y(0);try{const e=await rt(t);e.skipped?f.info(c("project_header.sync_skipped")):e.ok?f.success(c("project_header.sync_success",{files:e.filesTransferred,seconds:Math.round(e.durationMs/1e3)})):"cancelled"===e.reason||f.error(e.reason?c("project_header.sync_failed_with_reason",{reason:e.reason}):c("project_header.sync_failed"))}catch(e){f.error(e instanceof Error?e.message:c("project_header.sync_failed"))}finally{v(!1),y(0),k(!1)}}})()},title:c("project_header.sync_button_title"),children:[_.jsx(st,{className:"h-3.5 w-3.5 mr-1.5"}),c("project_header.sync")]}),_.jsx(zn,{open:E,onOpenChange:e=>{D||M(e)},currentCliTool:e.cliTool,loading:D,onConfirm:async(t,s)=>{R(!0);try{const i=await nt(e.id,t,s);h(i),A(i),M(!1),f.success(c("switch_cli.switched_toast",{tool:On(t)}))}catch(i){const e=i instanceof Error?i.message:String(i);throw f.error(c("switch_cli.switch_failed",{reason:e})),i}finally{R(!1)}}}),_.jsx(wn,{projectId:t,open:P,onOpenChange:T}),_.jsx(Nn,{projectId:e.id,open:B,onOpenChange:I}),O.pendingAskUser&&_.jsx(En,{projectId:e.id,open:!!O.pendingAskUser,request:O.pendingAskUser,onSubmitted:()=>O.refresh()}),"stopped"===e.status&&_.jsxs(F,{variant:"outline",size:"sm",className:"flex-shrink-0",onClick:()=>{(async()=>{p(!0);try{h(await ot(e.id))}catch(t){console.error(t)}finally{p(!1)}})()},disabled:u,children:[_.jsx(xs,{className:"h-3.5 w-3.5 mr-1.5"}),"Start"]})]})})}
|
|
14
|
+
*/const Ps=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif","tiff","tif"]);function Ts(e){return"md"===e?"Markdown":"html"===e||"htm"===e?"HTML":"高亮"}const Bs=[50,75,100,125,150,200,250,300],Is=100;function Os({filePath:e,onClose:t,onMinimize:s}){const i=a(),r=e.endsWith("/.notebook/graph.yaml"),n=r?e.replace(/\/.notebook\/graph\.yaml$/,""):"",[o,k]=l.useState(null),[N,E]=l.useState(null),[M,D]=l.useState(()=>r?"graph":"rendered"),[R,L]=l.useState(!1),[P,T]=l.useState(Is),[B,I]=l.useState(""),[O,A]=l.useState(!1),[z,W]=l.useState(!1),H=l.useRef(null),[F,$]=l.useState(!0),{resolved:K}=h(),U=e.split("/").pop()??e,V=l.useMemo(()=>function(e){const t=e.split("/").pop()??"",s=t.toLowerCase();if("dockerfile"===s)return"dockerfile";if("makefile"===s)return"makefile";const i=t.lastIndexOf(".");return i>=0?t.slice(i+1).toLowerCase():""}(e),[e]),q=Ps.has(V),Y=Ds.has(V),G=Rs.has(V),X=function(e){return"md"===e||"html"===e||"htm"===e||e in Ls}(V),J=Ls[V]||V,Z=l.useMemo(()=>{if(!q)return"";const t=w(e),s=c(),i=`${t}&t=${Date.now()}`;return s?`${i}&token=${encodeURIComponent(s)}`:i},[e,q]);l.useEffect(()=>{if($(!0),k(null),E(null),T(function(e){const t=y(C.fileZoom,{},!0)[e];return Bs.includes(t)?t:Is}(e)),W(!1),q||Y||G)return k({path:e,binary:!1,tooLarge:!1,size:0,content:null}),void D("rendered");D(e.endsWith("/.notebook/graph.yaml")?"graph":"rendered"),d(e).then(e=>{k(e),I(e.content??"")}).catch(e=>E(e instanceof Error?e.message:"Failed to load file"))},[e,q,Y,G]);const Q=l.useCallback(async()=>{A(!0);try{await u(e,B),k(e=>e?{...e,content:B,size:new Blob([B]).size}:e),W(!1)}catch(t){f.error(t instanceof Error?t.message:"保存失败")}finally{A(!1)}},[e,B]);l.useEffect(()=>{const e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&"edit"===M&&(e.preventDefault(),Q())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[M,Q]),l.useEffect(()=>{const e=async e=>{if("Escape"===e.key&&F){if(z){if(!(await i({description:"有未保存的修改,确定关闭?",confirmLabel:"放弃修改",destructive:!0})))return}t()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[F,t,z,i]);const ee=async()=>{if(z){if(!(await i({description:"有未保存的修改,确定退出编辑?",confirmLabel:"放弃修改",destructive:!0})))return}D(r?"graph":X?"rendered":"plain"),W(!1)},te=t=>{T(t),function(e,t){const s=y(C.fileZoom,{},!0);t===Is?delete s[e]:s[e]=t,j(C.fileZoom,s,!0)}(e,t)},se=(null==o?void 0:o.content)??"",ie="dark"===K?St:wt,re=P/100*12,ne=o&&!o.binary&&!o.tooLarge&&!G,oe=l.useDeferredValue(B),ae=l.useMemo(()=>{var e,t;if(!o||o.binary||o.tooLarge)return null;if(q||Y||G)return null;const s="edit"===M?oe:se;if(null==s)return null;return{bytes:new Blob([s]).size,words:((null==(e=s.match(/[\u4e00-\u9fff\u3400-\u4dbf]/g))?void 0:e.length)??0)+((null==(t=s.replace(/[\u4e00-\u9fff\u3400-\u4dbf]/g," ").match(/[a-zA-Z0-9]+/g))?void 0:t.length)??0),lines:""===s?0:s.split("\n").length}},[o,q,Y,M,oe,se]);return _.jsx("div",{className:m("fixed inset-0 z-50 flex items-center justify-center transition-all duration-200",F?"bg-black/60 backdrop-blur-sm pointer-events-auto":"bg-transparent pointer-events-none"),onClick:e=>{e.target===e.currentTarget&&$(!1)},children:_.jsxs("div",{className:m("relative flex flex-col bg-background border border-border shadow-sm transition-all duration-200 pointer-events-auto",R?"w-screen h-screen rounded-none":"w-[72vw] max-w-4xl h-[80vh] rounded-xl",!F&&!R&&"opacity-50"),onClick:()=>$(!0),onFocus:e=>{e.stopPropagation(),$(!0)},children:[_.jsxs("div",{className:"flex items-center gap-2 px-4 h-10 border-b border-border flex-shrink-0",children:[_.jsx(_t,{className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),_.jsxs("span",{className:"flex-1 text-sm text-foreground font-medium truncate",title:e,children:[U,z&&_.jsx("span",{className:"text-muted-foreground ml-1",children:"*"}),ae&&_.jsxs("span",{className:"text-muted-foreground font-normal ml-2 text-xs tabular-nums",children:[(le=ae.bytes,le<1024?`${le} B`:le<1048576?`${(le/1024).toFixed(1)} KB`:`${(le/1024/1024).toFixed(2)} MB`)," · ",ae.words.toLocaleString()," 词 · ",ae.lines.toLocaleString()," 行"]})]}),ne&&!q&&!Y&&_.jsxs("div",{className:"flex items-center rounded-md border border-border bg-muted/50 p-0.5",children:[X&&_.jsxs(_.Fragment,{children:[_.jsxs("button",{onClick:()=>"edit"===M?ee():D("plain"),className:m("p-1 rounded-md transition-colors flex items-center gap-1 text-xs","plain"===M?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),title:"纯文本",children:[_.jsx(ns,{className:"h-3 w-3"}),_.jsx("span",{className:"hidden sm:inline",children:"源码"})]}),_.jsxs("button",{onClick:()=>"edit"===M?ee():D("rendered"),className:m("p-1 rounded-md transition-colors flex items-center gap-1 text-xs","rendered"===M?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),title:Ts(V),children:[_.jsx(p,{className:"h-3 w-3"}),_.jsx("span",{className:"hidden sm:inline",children:Ts(V)})]})]}),r&&_.jsxs("button",{onClick:()=>"edit"===M?ee():D("graph"),className:m("p-1 rounded-md transition-colors flex items-center gap-1 text-xs","graph"===M?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),title:"图谱",children:[_.jsx(ms,{className:"h-3 w-3"}),_.jsx("span",{className:"hidden sm:inline",children:"图谱"})]}),_.jsxs("button",{onClick:()=>"edit"===M?ee():(I((null==o?void 0:o.content)??""),W(!1),D("edit"),void setTimeout(()=>{var e;return null==(e=H.current)?void 0:e.focus()},0)),className:m("p-1 rounded-md transition-colors flex items-center gap-1 text-xs","edit"===M?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),title:"编辑",children:[_.jsx(g,{className:"h-3 w-3"}),_.jsx("span",{className:"hidden sm:inline",children:"编辑"})]})]}),"edit"===M&&_.jsxs("button",{onClick:()=>{Q()},disabled:O||!z,className:m("flex items-center gap-1 text-xs px-2 py-1 rounded transition-colors",z?"bg-blue-600 hover:bg-blue-500 text-white":"bg-muted text-muted-foreground"),title:"保存 (⌘S)",children:[_.jsx(Et,{className:"h-3 w-3"}),O?"保存中...":"保存"]}),(ne||q||G)&&"edit"!==M&&"graph"!==M&&_.jsxs("div",{className:"flex items-center rounded-md border border-border bg-muted/50 p-0.5 gap-0.5",children:[_.jsx("button",{onClick:()=>{const e=[...Bs].reverse().find(e=>e<P);e&&te(e)},disabled:P<=Bs[0],className:"p-1 rounded-md text-muted-foreground hover:text-foreground transition-colors disabled:opacity-30",title:"缩小",children:_.jsx(Ns,{className:"h-3 w-3"})}),_.jsxs("button",{onClick:()=>te(Is),className:"px-1 text-xs text-muted-foreground hover:text-foreground transition-colors min-w-[36px] text-center",title:"重置缩放",children:[P,"%"]}),_.jsx("button",{onClick:()=>{const e=Bs.find(e=>e>P);e&&te(e)},disabled:P>=Bs[Bs.length-1],className:"p-1 rounded-md text-muted-foreground hover:text-foreground transition-colors disabled:opacity-30",title:"放大",children:_.jsx(ks,{className:"h-3 w-3"})})]}),s&&_.jsx("button",{className:"p-1 rounded text-muted-foreground hover:text-foreground transition-colors",onClick:s,title:"最小化到 dock",children:_.jsx(v,{className:"h-3.5 w-3.5"})}),_.jsx("button",{className:"p-1 rounded text-muted-foreground hover:text-foreground transition-colors",onClick:()=>L(e=>!e),title:R?"退出全屏":"全屏",children:R?_.jsx(x,{className:"h-3.5 w-3.5"}):_.jsx(b,{className:"h-3.5 w-3.5"})}),_.jsx("button",{className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors",onClick:async()=>{if(z){if(!(await i({description:"有未保存的修改,确定关闭?",confirmLabel:"放弃修改",destructive:!0})))return}t()},children:_.jsx(S,{className:"h-4 w-4"})})]}),_.jsxs("div",{className:m("flex-1 min-h-0","graph"===M?"overflow-hidden":"overflow-auto"),children:["graph"===M&&_.jsx(l.Suspense,{fallback:_.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"Loading…"}),children:_.jsx(js,{folderPath:n})}),"graph"!==M&&!o&&!N&&_.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"Loading…"}),"graph"!==M&&N&&_.jsx("p",{className:"text-sm text-red-400 p-4",children:N}),"graph"!==M&&q&&o&&_.jsx("div",{className:"flex items-center justify-center p-4 h-full",children:_.jsx("img",{src:Z,alt:U,className:"max-w-full max-h-full object-contain rounded-md",style:{transform:`scale(${P/100})`,transformOrigin:"center center"},draggable:!1})}),"graph"!==M&&Y&&o&&_.jsx(l.Suspense,{fallback:_.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"Loading…"}),children:_.jsx(Es,{filePath:e,ext:V,zoom:P})}),"graph"!==M&&G&&o&&_.jsx(l.Suspense,{fallback:_.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"Loading…"}),children:_.jsx(Ms,{filePath:e,zoom:P})}),"graph"!==M&&!q&&!Y&&!G&&o&&o.binary&&_.jsxs("div",{className:"flex flex-col items-center gap-2 py-12 text-muted-foreground p-4",children:[_.jsx(_t,{className:"h-8 w-8"}),_.jsx("p",{className:"text-sm",children:"Binary file — cannot preview"}),_.jsxs("p",{className:"text-xs text-muted-foreground",children:[(o.size/1024).toFixed(1)," KB"]})]}),"graph"!==M&&!Y&&o&&o.tooLarge&&_.jsxs("div",{className:"flex flex-col items-center gap-2 py-12 text-muted-foreground p-4",children:[_.jsx(_t,{className:"h-8 w-8"}),_.jsx("p",{className:"text-sm",children:"File too large to preview"}),_.jsxs("p",{className:"text-xs text-muted-foreground",children:[(o.size/1024/1024).toFixed(2)," MB (limit 5 MB)"]})]}),"graph"!==M&&ne&&null!==se&&_.jsxs(_.Fragment,{children:["edit"===M&&_.jsx("textarea",{ref:H,value:B,onChange:e=>{I(e.target.value),W(!0)},className:"w-full h-full bg-transparent text-foreground font-mono outline-none resize-none p-4 leading-relaxed",style:{fontSize:`${re}px`,minHeight:"100%"},spellCheck:!1}),"edit"!==M&&_.jsxs("div",{className:"p-4",style:{fontSize:`${re}px`},children:["plain"===M&&_.jsx("pre",{className:"font-mono text-foreground whitespace-pre-wrap break-words leading-relaxed",style:{fontSize:"inherit"},children:se}),"rendered"===M&&"md"===V&&_.jsx("div",{className:"prose dark:prose-invert max-w-none prose-pre:bg-muted prose-pre:border prose-pre:border-border prose-code:text-foreground",style:{fontSize:"inherit"},children:_.jsx(mt,{remarkPlugins:[gt,vt],rehypePlugins:[pt],urlTransform:(e,t,s)=>"src"===t&&"img"===s.tagName?e:yt(e),components:{code({className:e,children:t,...s}){const i=/language-(\w+)/.exec(e||"");return!i&&!e?_.jsx("code",{className:e,...s,children:t}):_.jsx(bt,{style:ie,language:(null==i?void 0:i[1])||"text",PreTag:"div",customStyle:{fontSize:"inherit",borderRadius:"6px",margin:0},children:String(t).replace(/\n$/,"")})},img:({src:t,alt:s,...i})=>_.jsx("img",{...i,src:xt(e,t,c()),alt:s??"",loading:"lazy",style:{maxWidth:"100%",height:"auto"}})},children:se})}),"rendered"===M&&("html"===V||"htm"===V)&&_.jsx("iframe",{srcDoc:ft.sanitize(se,{WHOLE_DOCUMENT:!0,ADD_TAGS:["style","link"]}),className:"w-full h-full border-0 rounded bg-white",sandbox:"",title:U,style:{minHeight:"60vh",transform:`scale(${P/100})`,transformOrigin:"top left",width:1e4/P+"%",height:1e4/P+"%"}}),"rendered"===M&&"md"!==V&&"html"!==V&&"htm"!==V&&J&&_.jsx(bt,{style:ie,language:J,showLineNumbers:!0,lineNumberStyle:{color:"dark"===K?"#555":"#aaa",fontSize:"inherit"},customStyle:{fontSize:"inherit",borderRadius:"6px",margin:0,background:"transparent"},children:se}),"rendered"===M&&!X&&_.jsx("pre",{className:"font-mono text-foreground whitespace-pre-wrap break-words leading-relaxed",style:{fontSize:"inherit"},children:se})]})]})]})]})});var le}async function As(e){var t;if("undefined"!=typeof navigator&&(null==(t=navigator.clipboard)?void 0:t.writeText))try{return await navigator.clipboard.writeText(e),!0}catch{}try{const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.left="-9999px",t.style.top="0",t.setAttribute("readonly",""),document.body.appendChild(t),t.select(),t.setSelectionRange(0,e.length);const s=document.execCommand("copy");return document.body.removeChild(t),s}catch{return!1}}const zs=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif","tiff","tif"]);function Ws(e){const t=e.lastIndexOf(".");return t>=0&&zs.has(e.slice(t+1).toLowerCase())}function Hs({projectPath:e,projectId:t}){var s;const[i,r]=l.useState(new Map),[n,o]=l.useState(new Set([e])),[h,d]=l.useState(new Set),u=E(e=>e.get(t).activePreviewPath),p=E(e=>e.get(t).filePreviews),g=E(e=>e.openFilePreview),v=E(e=>e.closeFilePreview),x=E(e=>e.minimizeFilePreview),b=!!(null==(s=p.find(e=>e.path===u))?void 0:s.minimized),[S,y]=l.useState(null),[C,k]=l.useState(!1),[N,j]=l.useState(null),[W,H]=l.useState(!1),F=a(),$=l.useRef(null),K=l.useRef(null),U=l.useRef(null),V=function(e={}){const t=e.duration??500,s=e.moveTolerance??10,i=l.useRef(null),r=l.useRef(null),n=l.useRef(!1),o=l.useCallback(()=>{i.current&&(clearTimeout(i.current),i.current=null),r.current=null},[]);return{bind:l.useCallback(e=>({onTouchStart:s=>{if(1!==s.touches.length)return;const o=s.touches[0];r.current={x:o.clientX,y:o.clientY},n.current=!1,i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{if(n.current=!0,"undefined"!=typeof navigator&&"vibrate"in navigator)try{navigator.vibrate(15)}catch{}e(o.clientX,o.clientY)},t)},onTouchMove:e=>{if(!r.current||!i.current)return;const t=e.touches[0],n=t.clientX-r.current.x,a=t.clientY-r.current.y;Math.hypot(n,a)>s&&o()},onTouchEnd:o,onTouchCancel:o}),[t,s,o]),wasTriggered:n}}();l.useEffect(()=>{if(!S)return;const e=()=>y(null);return window.addEventListener("click",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("click",e),window.removeEventListener("scroll",e,!0)}},[S]);const q=async(t,s)=>{var i;if(0===t.length)return;const r=s??e,n=t.reduce((e,t)=>e+t.size,0);k(!0),j({loaded:0,total:n});try{const s=await B(r,t,(e,t)=>{j({loaded:e,total:t})});r!==e&&o(e=>new Set(e).add(r)),G(r);const n=s.uploaded.length,a=(null==(i=s.skipped)?void 0:i.length)??0,l=s.errors.length;l>0?f.error(`上传完成:${n} 成功,${l} 失败${a?`,${a} 跳过`:""}`):a>0?f.info(`已上传 ${n} 个文件,${a} 个同名文件被跳过`):f.success(`已上传 ${n} 个文件`)}catch(a){console.error("[FileTree] Upload failed:",a),f.error(`上传失败: ${a.message}`)}finally{k(!1),j(null)}},Y=e=>e>=1073741824?(e/1073741824).toFixed(2)+" GB":e>=1048576?(e/1048576).toFixed(1)+" MB":e>=1024?(e/1024).toFixed(0)+" KB":e+" B",G=l.useCallback(async e=>{d(t=>{if(t.has(e))return t;const s=new Set(t);return s.add(e),s});try{const t=await M(e);r(s=>new Map(s).set(e,t.entries))}catch(t){console.error("[FileTree] Failed to load:",e,t),r(t=>new Map(t).set(e,[]))}finally{d(t=>{const s=new Set(t);return s.delete(e),s})}},[]);l.useEffect(()=>{r(new Map),o(new Set([e])),d(new Set),G(e)},[e,G]);const X=l.useCallback(e=>{o(t=>{const s=new Set(t);return s.has(e)?s.delete(e):(s.add(e),i.has(e)||G(e)),s})},[i,G]),J=l.useCallback(()=>{r(new Map),o(new Set([e])),d(new Set),G(e)},[e,G]),Z=(e,s)=>e.map(e=>{const r=n.has(e.path),o=h.has(e.path),a=i.get(e.path),l=e.name.startsWith(".");return _.jsxs("div",{children:[_.jsxs("div",{className:m("flex items-center gap-1 py-[3px] rounded cursor-pointer","hover:bg-muted-foreground/10",l&&"opacity-50"),style:{paddingLeft:14*s+6+"px",paddingRight:"6px",WebkitTouchCallout:"none"},onClick:s=>{if(V.wasTriggered.current)return V.wasTriggered.current=!1,void s.stopPropagation();"dir"===e.type?X(e.path):g(t,e.path)},onContextMenu:t=>{t.preventDefault(),y({x:t.clientX,y:t.clientY,filePath:e.path,fileName:e.name,type:e.type})},...V.bind((t,s)=>{y({x:t,y:s,filePath:e.path,fileName:e.name,type:e.type})}),children:[_.jsx("span",{className:"w-3 flex-shrink-0 text-muted-foreground",children:"dir"===e.type&&(o?_.jsx(L,{className:"h-2.5 w-2.5 animate-spin"}):r?_.jsx(Gt,{className:"h-2.5 w-2.5"}):_.jsx(I,{className:"h-2.5 w-2.5"}))}),"dir"===e.type?r?_.jsx(P,{className:"h-3.5 w-3.5 text-blue-400 flex-shrink-0"}):_.jsx(O,{className:"h-3.5 w-3.5 text-blue-400 flex-shrink-0"}):Ws(e.name)?_.jsx(Ct,{className:"h-3.5 w-3.5 text-green-400 flex-shrink-0"}):_.jsx(_t,{className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),_.jsx("span",{className:m("text-xs truncate leading-none","dir"===e.type?"text-foreground":"text-muted-foreground"),title:e.path,children:e.name})]}),_.jsx(A,{initial:!1,children:"dir"===e.type&&r&&_.jsxs(z.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15,ease:"easeInOut"},className:"overflow-hidden",children:[!a&&!o&&_.jsx("div",{className:"text-xs text-muted-foreground/50 py-0.5",style:{paddingLeft:14*(s+1)+6+16+"px"},children:"—"}),0===(null==a?void 0:a.length)&&_.jsx("div",{className:"text-xs text-muted-foreground/50 py-0.5",style:{paddingLeft:14*(s+1)+6+16+"px"},children:"empty"}),a&&a.length>0&&Z(a,s+1)]})})]},e.path)}),Q=i.get(e),ee=h.has(e),te=e.split("/").filter(Boolean).pop()??e;return _.jsxs(_.Fragment,{children:[u&&!b&&_.jsx(Os,{filePath:u,onClose:()=>v(t,u),onMinimize:()=>x(t,u)},u),S&&_.jsxs("div",{ref:$,className:"fixed z-50 min-w-[140px] bg-popover border border-border rounded-md shadow-md py-1",style:{left:S.x,top:S.y},onClick:e=>e.stopPropagation(),children:[_.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-accent hover:text-accent-foreground text-left",onClick:()=>{As(S.filePath.startsWith(e+"/")?S.filePath.slice(e.length+1):S.filePath).then(e=>{e?f.success("已复制相对路径"):f.error("复制失败")}),y(null)},children:[_.jsx(os,{className:"h-3.5 w-3.5"}),"复制相对路径"]}),_.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-accent hover:text-accent-foreground text-left",onClick:()=>{As(S.filePath).then(e=>{e?f.success("已复制绝对路径"):f.error("复制失败")}),y(null)},children:[_.jsx(rs,{className:"h-3.5 w-3.5"}),"复制绝对路径"]}),"file"===S.type&&_.jsxs(_.Fragment,{children:[_.jsx("div",{className:"my-1 border-t border-border"}),_.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-accent hover:text-accent-foreground text-left",onClick:()=>{(async(e,t)=>{let s=w(e);const i=c();i&&(s+=`${s.includes("?")?"&":"?"}token=${encodeURIComponent(i)}`);const r=`${s}${s.includes("?")?"&":"?"}dl=1`;try{const e=await fetch(r,{method:"HEAD"});if(!e.ok)return void f.error(`下载失败 (${e.status})`)}catch{return void f.error("下载失败:网络错误")}const n=document.createElement("a");n.href=r,n.download=t,document.body.appendChild(n),n.click(),document.body.removeChild(n)})(S.filePath,S.fileName),y(null)},children:[_.jsx(D,{className:"h-3.5 w-3.5"}),"下载"]})]}),"dir"===S.type&&_.jsxs(_.Fragment,{children:[_.jsx("div",{className:"my-1 border-t border-border"}),_.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-accent hover:text-accent-foreground text-left",disabled:C,onClick:()=>{var e;U.current=S.filePath,y(null),null==(e=K.current)||e.click()},children:[_.jsx(Mt,{className:"h-3.5 w-3.5"}),"上传文件到此文件夹"]})]}),_.jsx("div",{className:"my-1 border-t border-border"}),_.jsxs("button",{className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-destructive/80 hover:text-destructive-foreground text-left",onClick:()=>{(async(t,s,r)=>{const n="dir"===r?`文件夹 "${s}" 及其所有内容`:`文件 "${s}"`;if(await F({title:"确认删除",description:`确认删除${n}?此操作不可撤销。`,destructive:!0,confirmLabel:"删除"}))try{await T(t),f.success(`已删除: ${s}`);const r=t.substring(0,t.lastIndexOf("/"));r&&i.has(r)?G(r):G(e)}catch(o){f.error(`删除失败: ${o.message}`)}})(S.filePath,S.fileName,S.type),y(null)},children:[_.jsx(R,{className:"h-3.5 w-3.5"}),"删除"]})]}),_.jsxs("div",{className:"h-full flex flex-col text-foreground select-none",children:[_.jsxs("div",{className:"flex items-center justify-between px-3 h-9 border-b border-border flex-shrink-0",children:[_.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:"Files"}),_.jsxs("div",{className:"flex items-center gap-0.5",children:[_.jsx("input",{ref:K,type:"file",multiple:!0,className:"hidden",onChange:e=>{const t=Array.from(e.target.files??[]),s=U.current;U.current=null,t.length>0&&q(t,s??void 0),e.target.value=""}}),_.jsx("button",{className:"text-muted-foreground hover:text-foreground p-0.5 rounded transition-colors",onClick:()=>{var e;U.current=null,null==(e=K.current)||e.click()},disabled:C,title:"上传文件",children:_.jsx(Mt,{className:m("h-3 w-3",C&&"animate-pulse")})}),_.jsx("button",{className:"text-muted-foreground hover:text-foreground p-0.5 rounded transition-colors",onClick:J,title:"Refresh file tree",children:_.jsx(L,{className:m("h-3 w-3",ee&&"animate-spin")})})]})]}),_.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-2 border-b border-border flex-shrink-0",children:[_.jsx(P,{className:"h-3.5 w-3.5 text-blue-400 flex-shrink-0"}),_.jsx("span",{className:"text-xs text-foreground font-medium truncate",title:e,children:te})]}),_.jsxs("div",{className:m("flex-1 overflow-y-auto py-1 min-h-0 transition-colors",W&&"bg-accent/30 ring-1 ring-inset ring-accent"),onDragOver:e=>{e.preventDefault(),H(!0)},onDragEnter:e=>{e.preventDefault(),H(!0)},onDragLeave:()=>H(!1),onDrop:e=>{e.preventDefault(),H(!1);const t=Array.from(e.dataTransfer.files);t.length>0&&q(t)},children:[C&&N&&_.jsxs("div",{className:"px-3 py-2 border-b border-border space-y-1",children:[_.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground",children:[_.jsxs("span",{children:["上传中 ",Math.floor(N.loaded/Math.max(N.total,1)*100),"%"]}),_.jsxs("span",{className:"font-mono",children:[Y(N.loaded)," / ",Y(N.total)]})]}),_.jsx("div",{className:"h-1 bg-muted rounded-full overflow-hidden",children:_.jsx("div",{className:"h-full bg-primary transition-[width] duration-150",style:{width:N.loaded/Math.max(N.total,1)*100+"%"}})})]}),W&&!C&&_.jsx("div",{className:"text-xs text-muted-foreground px-4 py-1",children:"松开以上传文件"}),ee&&!Q?_.jsx("div",{className:"text-xs text-muted-foreground px-4 py-3",children:"Loading…"}):Q&&0!==Q.length?Z(Q,0):_.jsx("div",{className:"text-xs text-muted-foreground px-4 py-3",children:"Empty folder"})]})]})]})}function Fs(e){const t=new Date(e),s=Date.now()-t.getTime();return s<36e5?`${Math.floor(s/6e4)}分钟前`:s<864e5?`${Math.floor(s/36e5)}小时前`:s<6048e5?`${Math.floor(s/864e5)}天前`:t.toLocaleDateString()}function $s({projectId:e}){const[t,s]=l.useState(null),[i,r]=l.useState(!0),[n,o]=l.useState(null),[a,h]=l.useState(null),[c,d]=l.useState(""),[u,p]=l.useState(!1),[g,v]=l.useState([]),[x,b]=l.useState(0),[S,w]=l.useState(!0),[y,C]=l.useState(!1),k=l.useCallback(async()=>{r(!0);try{s(await W(e))}catch{s(null)}finally{r(!1)}},[e]),N=l.useCallback(async(t=!1)=>{C(!0);try{const s=t?g.length:0,i=await H(e,30,s);v(e=>t?[...e,...i.commits]:i.commits),b(i.total)}catch{}finally{C(!1)}},[e,g.length]);l.useEffect(()=>{k(),N()},[e]);const j=async t=>{try{const{diff:s}=await V(e,t);o(s||"(no diff)"),h(t??"all changes")}catch{f.error("获取 diff 失败")}},E=async t=>{try{await q(e,[t]),f.success(`已暂存 ${t}`),await k()}catch{f.error("git add 失败")}},M=async()=>{if(c.trim()){p(!0);try{await Y(e,c),f.success("提交成功"),d(""),await k()}catch(t){f.error(t instanceof Error?t.message:"提交失败")}finally{p(!1)}}};if(!t&&i)return _.jsxs("div",{className:"flex flex-col items-center gap-2 py-8 text-muted-foreground/50 text-xs",children:[_.jsx(hs,{className:"h-5 w-5"}),_.jsx("p",{children:"加载中…"})]});if(!t||!t.isRepo)return _.jsxs("div",{className:"flex flex-col items-center gap-2 py-8 text-muted-foreground/50 text-xs",children:[_.jsx(hs,{className:"h-5 w-5"}),_.jsx("p",{children:t?"非 Git 仓库":"加载失败"}),_.jsx(F,{variant:"ghost",size:"sm",className:"h-6 text-xs",onClick:()=>{k()},children:"重试"})]});const D=[...t.modified??[],...t.deleted??[]],R=t.staged??[],P=t.untracked??[];return _.jsxs("div",{className:"flex flex-col h-full overflow-y-auto p-2 space-y-2 text-xs",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground font-medium",children:[_.jsx(hs,{className:"h-3 w-3"}),_.jsx("span",{children:t.branch}),(t.ahead??0)>0&&_.jsxs("span",{className:"text-blue-400",children:["↑",t.ahead]}),(t.behind??0)>0&&_.jsxs("span",{className:"text-yellow-400",children:["↓",t.behind]})]}),_.jsx(F,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>{k()},disabled:i,children:_.jsx(L,{className:m("h-3 w-3",i&&"animate-spin")})})]}),R.length>0&&_.jsxs("div",{children:[_.jsxs("div",{className:"text-muted-foreground mb-1 font-medium",children:["已暂存 (",R.length,")"]}),R.map(e=>_.jsxs("div",{className:"flex items-center gap-1 py-0.5 px-1 rounded hover:bg-muted-foreground/10",children:[_.jsx($,{className:"h-2.5 w-2.5 text-green-500 flex-shrink-0"}),_.jsx("button",{className:"flex-1 text-left truncate text-green-400",onClick:()=>{j(e)},children:e})]},e))]}),D.length>0&&_.jsxs("div",{children:[_.jsxs("div",{className:"text-muted-foreground mb-1 font-medium",children:["未暂存 (",D.length,")"]}),D.map(e=>_.jsxs("div",{className:"flex items-center gap-1 py-0.5 px-1 rounded hover:bg-muted-foreground/10",children:[_.jsx("button",{className:"flex-shrink-0 h-4 w-4 flex items-center justify-center rounded hover:bg-green-500/20 text-muted-foreground hover:text-green-400",title:"git add",onClick:()=>{E(e)},children:_.jsx(K,{className:"h-2.5 w-2.5"})}),_.jsx("button",{className:"flex-1 text-left truncate text-yellow-400",onClick:()=>{j(e)},children:e})]},e))]}),P.length>0&&_.jsxs("div",{children:[_.jsxs("div",{className:"text-muted-foreground mb-1 font-medium",children:["未跟踪 (",P.length,")"]}),P.map(e=>_.jsxs("div",{className:"flex items-center gap-1 py-0.5 px-1 rounded hover:bg-muted-foreground/10",children:[_.jsx("button",{className:"flex-shrink-0 h-4 w-4 flex items-center justify-center rounded hover:bg-green-500/20 text-muted-foreground hover:text-green-400",title:"git add",onClick:()=>{E(e)},children:_.jsx(K,{className:"h-2.5 w-2.5"})}),_.jsx("span",{className:"flex-1 truncate text-muted-foreground",children:e})]},e))]}),0===D.length&&0===R.length&&0===P.length&&_.jsx("p",{className:"text-muted-foreground/50 text-center py-4",children:"工作区干净"}),R.length>0&&_.jsxs("div",{className:"space-y-1.5 pt-1 border-t border-border",children:[_.jsx(U,{placeholder:"提交消息…",value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||M()},className:"h-7 text-xs"}),_.jsx(F,{size:"sm",className:"w-full h-7 text-xs",onClick:()=>{M()},disabled:!c.trim()||u,children:u?"提交中…":`提交 (${R.length} 文件)`})]}),(null==t?void 0:t.isRepo)&&_.jsxs("div",{className:"border-t border-border pt-2",children:[_.jsxs("button",{className:"flex items-center gap-1 text-muted-foreground font-medium mb-1 w-full text-left",onClick:()=>w(e=>!e),children:[_.jsx(Gt,{className:m("h-3 w-3 transition-transform",!S&&"-rotate-90")}),_.jsx(cs,{className:"h-3 w-3"}),_.jsxs("span",{children:["提交历史 (",x,")"]})]}),S&&_.jsxs("div",{className:"space-y-0.5",children:[g.map((e,t)=>{const s=e.parents.length>1;return _.jsxs("div",{className:"flex gap-1.5 items-start group",children:[_.jsxs("div",{className:"flex flex-col items-center flex-shrink-0 w-3",children:[_.jsx("div",{className:m("w-2 h-2 rounded-full flex-shrink-0 mt-1",0===t?"bg-blue-400":s?"bg-purple-400":"bg-muted-foreground/40")}),t<g.length-1&&_.jsx("div",{className:"w-px flex-1 bg-border min-h-[12px]"})]}),_.jsxs("div",{className:"flex-1 min-w-0 pb-1",children:[_.jsxs("div",{className:"flex items-baseline gap-1",children:[_.jsx("span",{className:"font-mono text-muted-foreground/60 text-[10px] flex-shrink-0",children:e.hashShort}),_.jsx("span",{className:"truncate leading-tight",children:e.message.split("\n")[0]})]}),_.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground/50 mt-0.5",children:[_.jsx("span",{children:e.author}),_.jsx("span",{children:Fs(e.date)}),e.branches.length>0&&e.branches.slice(0,2).map(e=>_.jsx("span",{className:"px-1 py-px rounded bg-blue-500/10 text-blue-400 text-[9px]",children:e.replace("remotes/origin/","↑")},e))]})]})]},e.hash)}),g.length<x&&_.jsx("button",{className:"w-full text-center text-[10px] text-muted-foreground hover:text-foreground py-1",onClick:()=>{N(!0)},disabled:y,children:y?"加载中...":`加载更多 (${g.length}/${x})`})]})]}),null!==n&&_.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:()=>o(null),children:[_.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),_.jsxs("div",{className:"relative z-10 w-[700px] max-w-[95vw] max-h-[80vh] flex flex-col bg-background border border-border rounded-xl shadow-sm",onClick:e=>e.stopPropagation(),children:[_.jsxs("div",{className:"flex items-center justify-between px-4 h-10 border-b border-border text-sm font-medium flex-shrink-0",children:[_.jsx("span",{className:"truncate text-muted-foreground",children:a}),_.jsx("button",{className:"text-muted-foreground hover:text-foreground",onClick:()=>o(null),children:"✕"})]}),_.jsx("pre",{className:"flex-1 overflow-auto p-3 text-[11px] font-mono whitespace-pre leading-relaxed",children:n.split("\n").map((e,t)=>_.jsx("span",{className:m("block",e.startsWith("+")&&!e.startsWith("+++")&&"text-green-400 bg-green-400/5",e.startsWith("-")&&!e.startsWith("---")&&"text-red-400 bg-red-400/5",e.startsWith("@@")&&"text-blue-400"),children:e},t))})]})]})]})}function Ks(e){if(!e)return"-";const t=e-Date.now(),s=Math.abs(t),i=t<0,r=Math.round(s/1e3);if(r<60)return i?`${r} 秒前`:`${r} 秒后`;const n=Math.round(r/60);if(n<60)return i?`${n} 分钟前`:`${n} 分钟后`;const o=Math.round(n/60);if(o<24)return i?`${o} 小时前`:`${o} 小时后`;const a=Math.round(o/24);return i?`${a} 天前`:`${a} 天后`}function Us(e){if(!e)return"";return new Date(e).toLocaleString(void 0,{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function Vs({projectId:e}){const[t,s]=l.useState(null),[i,r]=l.useState(!0),[n,o]=l.useState(null),[,a]=l.useState(0),h=l.useRef(!0),c=l.useRef(0),d=l.useCallback(async()=>{const t=++c.current;r(!0),o(null);try{const{tasks:i}=await G(e);if(!h.current||t!==c.current)return;s(i)}catch(cl){if(!h.current||t!==c.current)return;o(cl.message),s([])}finally{h.current&&t===c.current&&r(!1)}},[e]);return l.useEffect(()=>{h.current=!0,d();const e=setInterval(()=>{d()},3e4),t=setInterval(()=>a(e=>e+1),1e3);return()=>{h.current=!1,clearInterval(e),clearInterval(t)}},[d]),_.jsxs("div",{className:"h-full flex flex-col bg-muted text-foreground overflow-hidden",children:[_.jsxs("div",{className:"flex-shrink-0 px-3 py-2 flex items-center justify-between border-b border-border",children:[_.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[_.jsx(kt,{className:"size-4"}),_.jsx("span",{children:"已排程任务"})]}),_.jsx(F,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{d()},title:"刷新","aria-label":"刷新",children:_.jsx(L,{className:m("size-3.5",i&&"animate-spin")})})]}),_.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto p-2 space-y-1.5",children:[_.jsxs("div",{className:"rounded-md bg-muted-foreground/5 px-2 py-1.5 text-[11px] text-muted-foreground flex items-start gap-1.5",children:[_.jsx(ds,{className:"size-3 mt-0.5 shrink-0"}),_.jsxs("span",{className:"leading-snug",children:["best-effort 重建:从 session JSONL 反推「Claude 创建过的 schedule」,",_.jsx("strong",{className:"text-foreground/80",children:"不是"}),"权威活动列表。已触发 / 已删除 无法直接观测。"]})]}),n&&_.jsx("div",{className:"rounded-md border border-destructive/30 bg-destructive/10 text-destructive p-2 text-xs",children:n}),!n&&t&&0===t.length&&!i&&_.jsxs("div",{className:"px-2 py-6 text-center text-xs text-muted-foreground",children:[_.jsx("p",{children:"本项目最近 7 天没有创建过 schedule。"}),_.jsx("p",{className:"mt-2 leading-relaxed",children:"一次性 ScheduleWakeup 触发时间过了的会被隐藏(认为已触发); CronCreate 仅显示 7 天内创建的(与 Claude 自动过期窗口对齐)。"})]}),t&&t.map(e=>{const t=e.nextFireAt?Date.parse(e.nextFireAt):null,s="CronCreate"===e.type&&(e.recurring||/[,*\/-]/.test(e.cron??"")),i="ScheduleWakeup"===e.type&&null!==e.delaySeconds?function(e){if(e<60)return`${e} 秒后`;const t=Math.round(e/60);return t<60?`${t} 分钟后`:Math.round(t/60*10)/10+" 小时后"}(e.delaySeconds):e.cron??"?";return _.jsx("div",{className:"rounded-md border border-border bg-background px-2.5 py-2 text-xs",children:_.jsxs("div",{className:"flex items-start gap-2",children:[_.jsx("div",{className:"shrink-0 mt-0.5 text-muted-foreground",children:s?_.jsx(Ss,{className:"size-3.5"}):_.jsx(X,{className:"size-3.5"})}),_.jsxs("div",{className:"flex-1 min-w-0",children:[_.jsxs("div",{className:"flex flex-wrap items-center gap-1 mb-1",children:[_.jsx("span",{className:"text-[10px] font-mono px-1.5 rounded bg-muted-foreground/10 text-muted-foreground",children:"ScheduleWakeup"===e.type?"SW":"CC"}),e.durable&&_.jsx("span",{className:"text-[10px] px-1.5 rounded bg-primary/10 text-primary",children:"durable"}),_.jsx("code",{className:"text-[10px] bg-muted-foreground/10 px-1 rounded font-mono",children:i})]}),_.jsx("div",{className:"font-medium text-foreground line-clamp-2 leading-snug",children:e.prompt.trim()||"(无 prompt)"}),e.reason&&_.jsxs("div",{className:"mt-0.5 text-muted-foreground line-clamp-1 italic text-[11px]",children:["reason: ",e.reason]}),_.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[11px] text-muted-foreground",children:[null!==t&&_.jsxs("span",{title:Us(t),children:["下次: ",_.jsx("span",{className:"text-foreground/90",children:Ks(t)})]}),_.jsxs("span",{title:Us(e.createdAt),children:["创建: ",Ks(e.createdAt)]}),_.jsx("span",{className:"font-mono text-muted-foreground/70",children:e.sessionId.slice(0,8)})]})]})]})},`${e.sessionId}:${e.id}`)}),i&&!t&&_.jsx("div",{className:"space-y-1.5",children:[0,1].map(e=>_.jsx("div",{className:"rounded-md border border-border bg-background px-2.5 py-2 h-16 animate-pulse"},e))})]})]})}function qs(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:e<1073741824?`${(e/1024/1024).toFixed(1)} MB`:`${(e/1024/1024/1024).toFixed(2)} GB`}function Ys(e){if(!e)return"-";const t=e-Date.now(),s=Math.abs(t),i=t<0,r=Math.round(s/1e3);if(r<60)return i?`${r} 秒前`:`${r} 秒后`;const n=Math.round(r/60);if(n<60)return i?`${n} 分钟前`:`${n} 分钟后`;const o=Math.round(n/60);if(o<24)return i?`${o} 小时前`:`${o} 小时后`;const a=Math.round(o/24);return i?`${a} 天前`:`${a} 天后`}function Gs(e){return new Date(e).toLocaleString(void 0,{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function Xs({projectId:e}){const[t,s]=l.useState(null),[i,r]=l.useState(!0),[n,o]=l.useState(!1),[a,h]=l.useState(null),[,c]=l.useState(0),d=l.useRef(!0),u=l.useCallback(async()=>{h(null);try{const t=await J(e);if(!d.current)return;s(t)}catch(cl){if(!d.current)return;h(cl.message)}finally{d.current&&r(!1)}},[e]),p=l.useCallback(async()=>{o(!0);try{const t=await Z(e);if(!d.current)return;const s=[];t.copied>0&&s.push(`新增/更新 ${t.copied}`),t.deleted>0&&s.push(`删除 ${t.deleted}`),t.skipped>0&&s.push(`跳过 ${t.skipped}`),f.success(`同步完成:${s.join("·")||"无变化"}`),await u()}catch(cl){f.error(`同步失败:${cl.message}`)}finally{d.current&&o(!1)}},[e,u]);l.useEffect(()=>{d.current=!0,u();const e=setInterval(()=>{u()},3e4),t=setInterval(()=>c(e=>e+1),5e3);return()=>{d.current=!1,clearInterval(e),clearInterval(t)}},[u]);const g=(null==t?void 0:t.files.reduce((e,t)=>e+t.bytes,0))??0;return _.jsxs("div",{className:"h-full flex flex-col bg-muted text-foreground overflow-hidden",children:[_.jsxs("div",{className:"flex-shrink-0 px-3 py-2 flex items-center justify-between border-b border-border",children:[_.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[_.jsx(Q,{className:"size-4"}),_.jsx("span",{children:"聊天记录备份"})]}),_.jsx(F,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{u()},title:"刷新","aria-label":"刷新",disabled:i,children:_.jsx(L,{className:m("size-3.5",i&&"animate-spin")})})]}),_.jsx("div",{className:"flex-shrink-0 px-3 py-2 border-b border-border bg-background/40",children:_.jsxs("div",{className:"flex items-center justify-between gap-2",children:[_.jsxs("div",{className:"text-[11px] text-muted-foreground min-w-0",children:[_.jsxs("div",{children:["最后同步:"," ",_.jsx("span",{className:"text-foreground/90",title:(null==t?void 0:t.meta)?Gs(t.meta.lastBackupAt):void 0,children:(null==t?void 0:t.meta)?Ys(t.meta.lastBackupAt):"从未同步"})]}),t&&_.jsxs("div",{className:"mt-0.5 text-muted-foreground/80",children:[t.files.length," 个文件 · ",qs(g)]})]}),_.jsx(F,{size:"sm",className:"h-7 px-2.5 text-xs",onClick:()=>{p()},disabled:n||!(null==t?void 0:t.supported),children:n?"同步中…":"立即同步"})]})}),_.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto p-2 space-y-1",children:[a&&_.jsxs("div",{className:"rounded-md border border-destructive/30 bg-destructive/10 text-destructive p-2 text-xs flex items-start gap-2",children:[_.jsx(ts,{className:"size-3.5 shrink-0 mt-0.5"}),_.jsx("span",{children:a})]}),t&&!t.supported&&_.jsx("div",{className:"px-2 py-6 text-center text-xs text-muted-foreground",children:_.jsxs("p",{children:["此项目使用 ",_.jsx("code",{className:"text-[10px] bg-muted-foreground/10 px-1 rounded",children:"terminal"})," 模式,无聊天记录需备份。"]})}),(null==t?void 0:t.supported)&&0===t.files.length&&!i&&!a&&_.jsxs("div",{className:"px-2 py-6 text-center text-xs text-muted-foreground",children:[_.jsx("p",{children:"暂无已备份的聊天记录"}),_.jsx("p",{className:"mt-2 leading-relaxed text-muted-foreground/80",children:'定时每 5 分钟同步一次,也可点击右上方"立即同步"手动触发。'}),_.jsxs("p",{className:"mt-1 text-muted-foreground/70",children:["备份路径: ",_.jsx("code",{className:"text-[10px] bg-muted-foreground/10 px-1 rounded break-all",children:t.backupDir})]})]}),null==t?void 0:t.files.map(e=>_.jsxs("div",{className:"rounded-md border border-border bg-background px-2.5 py-1.5 text-xs flex items-center gap-2 hover:bg-accent/50 transition-colors",children:[_.jsx(_t,{className:"size-3.5 shrink-0 text-muted-foreground"}),_.jsxs("div",{className:"flex-1 min-w-0",children:[_.jsx("div",{className:"font-mono text-[11px] text-foreground truncate",title:e.name,children:e.name}),_.jsxs("div",{className:"text-muted-foreground/80 text-[10px] flex items-center gap-2",children:[_.jsx("span",{title:Gs(e.mtime),children:Ys(e.mtime)}),_.jsx("span",{className:"text-muted-foreground/40",children:"·"}),_.jsx("span",{children:qs(e.bytes)})]})]})]},e.name)),i&&!t&&_.jsx("div",{className:"space-y-1",children:[0,1].map(e=>_.jsx("div",{className:"rounded-md border border-border bg-background h-10 animate-pulse"},e))})]})]})}function Js({projectPath:e,projectId:t,cliTool:s}){const[i,r]=ee(C.leftPanelTab,"files"),n="claude"===s,o="terminal"!==s;let a;return a="git"===i?"git":"scheduled"===i&&n?"scheduled":"backup"===i&&o?"backup":"files",_.jsxs(Dt,{value:a,onValueChange:e=>r(e),orientation:"vertical",className:"h-full flex bg-muted text-foreground overflow-hidden",children:[_.jsxs(Rt,{className:m("flex flex-col items-center justify-start shrink-0","h-full w-9 border-r border-border rounded-none p-1 gap-1"),children:[_.jsx(Lt,{value:"files",title:"Files","aria-label":"Files",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(P,{className:"h-3.5 w-3.5"})}),_.jsx(Lt,{value:"git",title:"Git","aria-label":"Git",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(hs,{className:"h-3.5 w-3.5"})}),n&&_.jsx(Lt,{value:"scheduled",title:"已排程任务","aria-label":"Scheduled tasks",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(kt,{className:"h-3.5 w-3.5"})}),o&&_.jsx(Lt,{value:"backup",title:"聊天记录备份","aria-label":"Sessions backup",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(Q,{className:"h-3.5 w-3.5"})})]}),_.jsxs("div",{className:"flex-1 min-w-0 flex flex-col border-l border-border",children:[_.jsx(Pt,{value:"files",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx(Hs,{projectPath:e,projectId:t})}),_.jsx(Pt,{value:"git",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx($s,{projectId:t})}),n&&_.jsx(Pt,{value:"scheduled",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx(Vs,{projectId:t})}),o&&_.jsx(Pt,{value:"backup",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx(Xs,{projectId:t})})]})]})}function Zs(e){const t=Qs(e),s=l.forwardRef((e,s)=>{const{children:i,...r}=e,n=l.Children.toArray(i),o=n.find(ti);if(o){const e=o.props.children,i=n.map(t=>t===o?l.Children.count(e)>1?l.Children.only(null):l.isValidElement(e)?e.props.children:null:t);return _.jsx(t,{...r,ref:s,children:l.isValidElement(e)?l.cloneElement(e,void 0,i):null})}return _.jsx(t,{...r,ref:s,children:i})});return s.displayName=`${e}.Slot`,s}function Qs(e){const t=l.forwardRef((e,t)=>{const{children:s,...i}=e;if(l.isValidElement(s)){const e=function(e){var t,s;let i=null==(t=Object.getOwnPropertyDescriptor(e.props,"ref"))?void 0:t.get,r=i&&"isReactWarning"in i&&i.isReactWarning;if(r)return e.ref;if(i=null==(s=Object.getOwnPropertyDescriptor(e,"ref"))?void 0:s.get,r=i&&"isReactWarning"in i&&i.isReactWarning,r)return e.props.ref;return e.props.ref||e.ref}(s),r=function(e,t){const s={...t};for(const i in t){const r=e[i],n=t[i];/^on[A-Z]/.test(i)?r&&n?s[i]=(...e)=>{const t=n(...e);return r(...e),t}:r&&(s[i]=r):"style"===i?s[i]={...r,...n}:"className"===i&&(s[i]=[r,n].filter(Boolean).join(" "))}return{...e,...s}}(i,s.props);return s.type!==l.Fragment&&(r.ref=t?te(t,e):e),l.cloneElement(s,r)}return l.Children.count(s)>1?l.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var ei=Symbol("radix.slottable");function ti(e){return l.isValidElement(e)&&"function"==typeof e.type&&"__radixId"in e.type&&e.type.__radixId===ei}var si=["Enter"," "],ii=["ArrowUp","PageDown","End"],ri=["ArrowDown","PageUp","Home",...ii],ni={ltr:[...si,"ArrowRight"],rtl:[...si,"ArrowLeft"]},oi={ltr:["ArrowLeft"],rtl:["ArrowRight"]},ai="Menu",[li,hi,ci]=At(ai),[di,ui]=ie(ai,[ci,It,Ot]),fi=It(),_i=Ot(),[mi,pi]=di(ai),[gi,vi]=di(ai),xi=e=>{const{__scopeMenu:t,open:s=!1,children:i,dir:r,onOpenChange:n,modal:o=!0}=e,a=fi(t),[h,c]=l.useState(null),d=l.useRef(!1),u=se(n),f=Xt(r);return l.useEffect(()=>{const e=()=>{d.current=!0,document.addEventListener("pointerdown",t,{capture:!0,once:!0}),document.addEventListener("pointermove",t,{capture:!0,once:!0})},t=()=>d.current=!1;return document.addEventListener("keydown",e,{capture:!0}),()=>{document.removeEventListener("keydown",e,{capture:!0}),document.removeEventListener("pointerdown",t,{capture:!0}),document.removeEventListener("pointermove",t,{capture:!0})}},[]),_.jsx(Tt,{...a,children:_.jsx(mi,{scope:t,open:s,onOpenChange:u,content:h,onContentChange:c,children:_.jsx(gi,{scope:t,onClose:l.useCallback(()=>u(!1),[u]),isUsingKeyboardRef:d,dir:f,modal:o,children:i})})})};xi.displayName=ai;var bi=l.forwardRef((e,t)=>{const{__scopeMenu:s,...i}=e,r=fi(s);return _.jsx(Bt,{...r,...i,ref:t})});bi.displayName="MenuAnchor";var Si="MenuPortal",[wi,yi]=di(Si,{forceMount:void 0}),Ci=e=>{const{__scopeMenu:t,forceMount:s,children:i,container:r}=e,n=pi(Si,t);return _.jsx(wi,{scope:t,forceMount:s,children:_.jsx(re,{present:s||n.open,children:_.jsx(ne,{asChild:!0,container:r,children:i})})})};Ci.displayName=Si;var ki="MenuContent",[Ni,ji]=di(ki),Ei=l.forwardRef((e,t)=>{const s=yi(ki,e.__scopeMenu),{forceMount:i=s.forceMount,...r}=e,n=pi(ki,e.__scopeMenu),o=vi(ki,e.__scopeMenu);return _.jsx(li.Provider,{scope:e.__scopeMenu,children:_.jsx(re,{present:i||n.open,children:_.jsx(li.Slot,{scope:e.__scopeMenu,children:o.modal?_.jsx(Mi,{...r,ref:t}):_.jsx(Di,{...r,ref:t})})})})}),Mi=l.forwardRef((e,t)=>{const s=pi(ki,e.__scopeMenu),i=l.useRef(null),r=oe(t,i);return l.useEffect(()=>{const e=i.current;if(e)return he(e)},[]),_.jsx(Li,{...e,ref:r,trapFocus:s.open,disableOutsidePointerEvents:s.open,disableOutsideScroll:!0,onFocusOutside:ae(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>s.onOpenChange(!1)})}),Di=l.forwardRef((e,t)=>{const s=pi(ki,e.__scopeMenu);return _.jsx(Li,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>s.onOpenChange(!1)})}),Ri=Zs("MenuContent.ScrollLock"),Li=l.forwardRef((e,t)=>{const{__scopeMenu:s,loop:i=!1,trapFocus:r,onOpenAutoFocus:n,onCloseAutoFocus:o,disableOutsidePointerEvents:a,onEntryFocus:h,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:u,onInteractOutside:f,onDismiss:m,disableOutsideScroll:p,...g}=e,v=pi(ki,s),x=vi(ki,s),b=fi(s),S=_i(s),w=hi(s),[y,C]=l.useState(null),k=l.useRef(null),N=oe(t,k,v.onContentChange),j=l.useRef(0),E=l.useRef(""),M=l.useRef(0),D=l.useRef(null),R=l.useRef("right"),L=l.useRef(0),P=p?ue:l.Fragment,T=p?{as:Ri,allowPinchZoom:!0}:void 0,B=e=>{var t,s;const i=E.current+e,r=w().filter(e=>!e.disabled),n=document.activeElement,o=null==(t=r.find(e=>e.ref.current===n))?void 0:t.textValue,a=function(e,t,s){const i=t.length>1&&Array.from(t).every(e=>e===t[0]),r=i?t[0]:t,n=s?e.indexOf(s):-1;let o=(a=e,l=Math.max(n,0),a.map((e,t)=>a[(l+t)%a.length]));var a,l;1===r.length&&(o=o.filter(e=>e!==s));const h=o.find(e=>e.toLowerCase().startsWith(r.toLowerCase()));return h!==s?h:void 0}(r.map(e=>e.textValue),i,o),l=null==(s=r.find(e=>e.textValue===a))?void 0:s.ref.current;!function e(t){E.current=t,window.clearTimeout(j.current),""!==t&&(j.current=window.setTimeout(()=>e(""),1e3))}(i),l&&setTimeout(()=>l.focus())};l.useEffect(()=>()=>window.clearTimeout(j.current),[]),de();const I=l.useCallback(e=>{var t,s;return R.current===(null==(t=D.current)?void 0:t.side)&&function(e,t){if(!t)return!1;const s={x:e.clientX,y:e.clientY};return function(e,t){const{x:s,y:i}=e;let r=!1;for(let n=0,o=t.length-1;n<t.length;o=n++){const e=t[n],a=t[o],l=e.x,h=e.y,c=a.x,d=a.y;h>i!=d>i&&s<(c-l)*(i-h)/(d-h)+l&&(r=!r)}return r}(s,t)}(e,null==(s=D.current)?void 0:s.area)},[]);return _.jsx(Ni,{scope:s,searchRef:E,onItemEnter:l.useCallback(e=>{I(e)&&e.preventDefault()},[I]),onItemLeave:l.useCallback(e=>{var t;I(e)||(null==(t=k.current)||t.focus(),C(null))},[I]),onTriggerLeave:l.useCallback(e=>{I(e)&&e.preventDefault()},[I]),pointerGraceTimerRef:M,onPointerGraceIntentChange:l.useCallback(e=>{D.current=e},[]),children:_.jsx(P,{...T,children:_.jsx(fe,{asChild:!0,trapped:r,onMountAutoFocus:ae(n,e=>{var t;e.preventDefault(),null==(t=k.current)||t.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:_.jsx(_e,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:u,onInteractOutside:f,onDismiss:m,children:_.jsx(Wt,{asChild:!0,...S,dir:x.dir,orientation:"vertical",loop:i,currentTabStopId:y,onCurrentTabStopIdChange:C,onEntryFocus:ae(h,e=>{x.isUsingKeyboardRef.current||e.preventDefault()}),preventScrollOnEntryFocus:!0,children:_.jsx(Ht,{role:"menu","aria-orientation":"vertical","data-state":rr(v.open),"data-radix-menu-content":"",dir:x.dir,...b,...g,ref:N,style:{outline:"none",...g.style},onKeyDown:ae(g.onKeyDown,e=>{const t=e.target.closest("[data-radix-menu-content]")===e.currentTarget,s=e.ctrlKey||e.altKey||e.metaKey,i=1===e.key.length;t&&("Tab"===e.key&&e.preventDefault(),!s&&i&&B(e.key));const r=k.current;if(e.target!==r)return;if(!ri.includes(e.key))return;e.preventDefault();const n=w().filter(e=>!e.disabled).map(e=>e.ref.current);ii.includes(e.key)&&n.reverse(),function(e){const t=document.activeElement;for(const s of e){if(s===t)return;if(s.focus(),document.activeElement!==t)return}}(n)}),onBlur:ae(e.onBlur,e=>{e.currentTarget.contains(e.target)||(window.clearTimeout(j.current),E.current="")}),onPointerMove:ae(e.onPointerMove,ar(e=>{const t=e.target,s=L.current!==e.clientX;if(e.currentTarget.contains(t)&&s){const t=e.clientX>L.current?"right":"left";R.current=t,L.current=e.clientX}}))})})})})})})});Ei.displayName=ki;var Pi=l.forwardRef((e,t)=>{const{__scopeMenu:s,...i}=e;return _.jsx(le.div,{role:"group",...i,ref:t})});Pi.displayName="MenuGroup";var Ti=l.forwardRef((e,t)=>{const{__scopeMenu:s,...i}=e;return _.jsx(le.div,{...i,ref:t})});Ti.displayName="MenuLabel";var Bi="MenuItem",Ii="menu.itemSelect",Oi=l.forwardRef((e,t)=>{const{disabled:s=!1,onSelect:i,...r}=e,n=l.useRef(null),o=vi(Bi,e.__scopeMenu),a=ji(Bi,e.__scopeMenu),h=oe(t,n),c=l.useRef(!1);return _.jsx(Ai,{...r,ref:h,disabled:s,onClick:ae(e.onClick,()=>{const e=n.current;if(!s&&e){const t=new CustomEvent(Ii,{bubbles:!0,cancelable:!0});e.addEventListener(Ii,e=>null==i?void 0:i(e),{once:!0}),ce(e,t),t.defaultPrevented?c.current=!1:o.onClose()}}),onPointerDown:t=>{var s;null==(s=e.onPointerDown)||s.call(e,t),c.current=!0},onPointerUp:ae(e.onPointerUp,e=>{var t;c.current||null==(t=e.currentTarget)||t.click()}),onKeyDown:ae(e.onKeyDown,e=>{const t=""!==a.searchRef.current;s||t&&" "===e.key||si.includes(e.key)&&(e.currentTarget.click(),e.preventDefault())})})});Oi.displayName=Bi;var Ai=l.forwardRef((e,t)=>{const{__scopeMenu:s,disabled:i=!1,textValue:r,...n}=e,o=ji(Bi,s),a=_i(s),h=l.useRef(null),c=oe(t,h),[d,u]=l.useState(!1),[f,m]=l.useState("");return l.useEffect(()=>{const e=h.current;e&&m((e.textContent??"").trim())},[n.children]),_.jsx(li.ItemSlot,{scope:s,disabled:i,textValue:r??f,children:_.jsx(zt,{asChild:!0,...a,focusable:!i,children:_.jsx(le.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":i||void 0,"data-disabled":i?"":void 0,...n,ref:c,onPointerMove:ae(e.onPointerMove,ar(e=>{if(i)o.onItemLeave(e);else if(o.onItemEnter(e),!e.defaultPrevented){e.currentTarget.focus({preventScroll:!0})}})),onPointerLeave:ae(e.onPointerLeave,ar(e=>o.onItemLeave(e))),onFocus:ae(e.onFocus,()=>u(!0)),onBlur:ae(e.onBlur,()=>u(!1))})})})}),zi=l.forwardRef((e,t)=>{const{checked:s=!1,onCheckedChange:i,...r}=e;return _.jsx(qi,{scope:e.__scopeMenu,checked:s,children:_.jsx(Oi,{role:"menuitemcheckbox","aria-checked":nr(s)?"mixed":s,...r,ref:t,"data-state":or(s),onSelect:ae(r.onSelect,()=>null==i?void 0:i(!!nr(s)||!s),{checkForDefaultPrevented:!1})})})});zi.displayName="MenuCheckboxItem";var Wi="MenuRadioGroup",[Hi,Fi]=di(Wi,{value:void 0,onValueChange:()=>{}}),$i=l.forwardRef((e,t)=>{const{value:s,onValueChange:i,...r}=e,n=se(i);return _.jsx(Hi,{scope:e.__scopeMenu,value:s,onValueChange:n,children:_.jsx(Pi,{...r,ref:t})})});$i.displayName=Wi;var Ki="MenuRadioItem",Ui=l.forwardRef((e,t)=>{const{value:s,...i}=e,r=Fi(Ki,e.__scopeMenu),n=s===r.value;return _.jsx(qi,{scope:e.__scopeMenu,checked:n,children:_.jsx(Oi,{role:"menuitemradio","aria-checked":n,...i,ref:t,"data-state":or(n),onSelect:ae(i.onSelect,()=>{var e;return null==(e=r.onValueChange)?void 0:e.call(r,s)},{checkForDefaultPrevented:!1})})})});Ui.displayName=Ki;var Vi="MenuItemIndicator",[qi,Yi]=di(Vi,{checked:!1}),Gi=l.forwardRef((e,t)=>{const{__scopeMenu:s,forceMount:i,...r}=e,n=Yi(Vi,s);return _.jsx(re,{present:i||nr(n.checked)||!0===n.checked,children:_.jsx(le.span,{...r,ref:t,"data-state":or(n.checked)})})});Gi.displayName=Vi;var Xi=l.forwardRef((e,t)=>{const{__scopeMenu:s,...i}=e;return _.jsx(le.div,{role:"separator","aria-orientation":"horizontal",...i,ref:t})});Xi.displayName="MenuSeparator";var Ji=l.forwardRef((e,t)=>{const{__scopeMenu:s,...i}=e,r=fi(s);return _.jsx(Ft,{...r,...i,ref:t})});Ji.displayName="MenuArrow";var[Zi,Qi]=di("MenuSub"),er="MenuSubTrigger",tr=l.forwardRef((e,t)=>{const s=pi(er,e.__scopeMenu),i=vi(er,e.__scopeMenu),r=Qi(er,e.__scopeMenu),n=ji(er,e.__scopeMenu),o=l.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:h}=n,c={__scopeMenu:e.__scopeMenu},d=l.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return l.useEffect(()=>d,[d]),l.useEffect(()=>{const e=a.current;return()=>{window.clearTimeout(e),h(null)}},[a,h]),_.jsx(bi,{asChild:!0,...c,children:_.jsx(Ai,{id:r.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":r.contentId,"data-state":rr(s.open),...e,ref:te(t,r.onTriggerChange),onClick:t=>{var i;null==(i=e.onClick)||i.call(e,t),e.disabled||t.defaultPrevented||(t.currentTarget.focus(),s.open||s.onOpenChange(!0))},onPointerMove:ae(e.onPointerMove,ar(t=>{n.onItemEnter(t),t.defaultPrevented||e.disabled||s.open||o.current||(n.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{s.onOpenChange(!0),d()},100))})),onPointerLeave:ae(e.onPointerLeave,ar(e=>{var t,i;d();const r=null==(t=s.content)?void 0:t.getBoundingClientRect();if(r){const t=null==(i=s.content)?void 0:i.dataset.side,o="right"===t,l=o?-5:5,h=r[o?"left":"right"],c=r[o?"right":"left"];n.onPointerGraceIntentChange({area:[{x:e.clientX+l,y:e.clientY},{x:h,y:r.top},{x:c,y:r.top},{x:c,y:r.bottom},{x:h,y:r.bottom}],side:t}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>n.onPointerGraceIntentChange(null),300)}else{if(n.onTriggerLeave(e),e.defaultPrevented)return;n.onPointerGraceIntentChange(null)}})),onKeyDown:ae(e.onKeyDown,t=>{var r;const o=""!==n.searchRef.current;e.disabled||o&&" "===t.key||ni[i.dir].includes(t.key)&&(s.onOpenChange(!0),null==(r=s.content)||r.focus(),t.preventDefault())})})})});tr.displayName=er;var sr="MenuSubContent",ir=l.forwardRef((e,t)=>{const s=yi(ki,e.__scopeMenu),{forceMount:i=s.forceMount,...r}=e,n=pi(ki,e.__scopeMenu),o=vi(ki,e.__scopeMenu),a=Qi(sr,e.__scopeMenu),h=l.useRef(null),c=oe(t,h);return _.jsx(li.Provider,{scope:e.__scopeMenu,children:_.jsx(re,{present:i||n.open,children:_.jsx(li.Slot,{scope:e.__scopeMenu,children:_.jsx(Li,{id:a.contentId,"aria-labelledby":a.triggerId,...r,ref:c,align:"start",side:"rtl"===o.dir?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:e=>{var t;o.isUsingKeyboardRef.current&&(null==(t=h.current)||t.focus()),e.preventDefault()},onCloseAutoFocus:e=>e.preventDefault(),onFocusOutside:ae(e.onFocusOutside,e=>{e.target!==a.trigger&&n.onOpenChange(!1)}),onEscapeKeyDown:ae(e.onEscapeKeyDown,e=>{o.onClose(),e.preventDefault()}),onKeyDown:ae(e.onKeyDown,e=>{var t;const s=e.currentTarget.contains(e.target),i=oi[o.dir].includes(e.key);s&&i&&(n.onOpenChange(!1),null==(t=a.trigger)||t.focus(),e.preventDefault())})})})})})});function rr(e){return e?"open":"closed"}function nr(e){return"indeterminate"===e}function or(e){return nr(e)?"indeterminate":e?"checked":"unchecked"}function ar(e){return t=>"mouse"===t.pointerType?e(t):void 0}ir.displayName=sr;var lr=xi,hr=bi,cr=Ci,dr=Ei,ur=Pi,fr=Ti,_r=Oi,mr=zi,pr=$i,gr=Ui,vr=Gi,xr=Xi,br=Ji,Sr=tr,wr=ir,yr="ContextMenu",[Cr]=ie(yr,[ui]),kr=ui(),[Nr,jr]=Cr(yr),Er=e=>{const{__scopeContextMenu:t,children:s,onOpenChange:i,dir:r,modal:n=!0}=e,[o,a]=l.useState(!1),h=kr(t),c=se(i),d=l.useCallback(e=>{a(e),c(e)},[c]);return _.jsx(Nr,{scope:t,open:o,onOpenChange:d,modal:n,children:_.jsx(lr,{...h,dir:r,open:o,onOpenChange:d,modal:n,children:s})})};Er.displayName=yr;var Mr="ContextMenuTrigger",Dr=l.forwardRef((e,t)=>{const{__scopeContextMenu:s,disabled:i=!1,...r}=e,n=jr(Mr,s),o=kr(s),a=l.useRef({x:0,y:0}),h=l.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=l.useRef(0),d=l.useCallback(()=>window.clearTimeout(c.current),[]),u=e=>{a.current={x:e.clientX,y:e.clientY},n.onOpenChange(!0)};return l.useEffect(()=>d,[d]),l.useEffect(()=>{i&&d()},[i,d]),_.jsxs(_.Fragment,{children:[_.jsx(hr,{...o,virtualRef:h}),_.jsx(le.span,{"data-state":n.open?"open":"closed","data-disabled":i?"":void 0,...r,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:i?e.onContextMenu:ae(e.onContextMenu,e=>{d(),u(e),e.preventDefault()}),onPointerDown:i?e.onPointerDown:ae(e.onPointerDown,Ir(e=>{d(),c.current=window.setTimeout(()=>u(e),700)})),onPointerMove:i?e.onPointerMove:ae(e.onPointerMove,Ir(d)),onPointerCancel:i?e.onPointerCancel:ae(e.onPointerCancel,Ir(d)),onPointerUp:i?e.onPointerUp:ae(e.onPointerUp,Ir(d))})]})});Dr.displayName=Mr;var Rr=e=>{const{__scopeContextMenu:t,...s}=e,i=kr(t);return _.jsx(cr,{...i,...s})};Rr.displayName="ContextMenuPortal";var Lr="ContextMenuContent",Pr=l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=jr(Lr,s),n=kr(s),o=l.useRef(!1);return _.jsx(dr,{...n,...i,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:t=>{var s;null==(s=e.onCloseAutoFocus)||s.call(e,t),!t.defaultPrevented&&o.current&&t.preventDefault(),o.current=!1},onInteractOutside:t=>{var s;null==(s=e.onInteractOutside)||s.call(e,t),t.defaultPrevented||r.modal||(o.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Pr.displayName=Lr;l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(ur,{...r,...i,ref:t})}).displayName="ContextMenuGroup";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(fr,{...r,...i,ref:t})}).displayName="ContextMenuLabel";var Tr=l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(_r,{...r,...i,ref:t})});Tr.displayName="ContextMenuItem";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(mr,{...r,...i,ref:t})}).displayName="ContextMenuCheckboxItem";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(pr,{...r,...i,ref:t})}).displayName="ContextMenuRadioGroup";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(gr,{...r,...i,ref:t})}).displayName="ContextMenuRadioItem";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(vr,{...r,...i,ref:t})}).displayName="ContextMenuItemIndicator";var Br=l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(xr,{...r,...i,ref:t})});Br.displayName="ContextMenuSeparator";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(br,{...r,...i,ref:t})}).displayName="ContextMenuArrow";l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(Sr,{...r,...i,ref:t})}).displayName="ContextMenuSubTrigger";function Ir(e){return t=>"mouse"!==t.pointerType?e(t):void 0}l.forwardRef((e,t)=>{const{__scopeContextMenu:s,...i}=e,r=kr(s);return _.jsx(wr,{...r,...i,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})}).displayName="ContextMenuSubContent";var Or=Rr,Ar=Pr,zr=Tr,Wr=Br;const Hr=Er,Fr=Dr,$r=l.forwardRef(({className:e,...t},s)=>_.jsx(Or,{children:_.jsx(Ar,{ref:s,className:m("z-50 min-w-[10rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",e),...t})}));$r.displayName=Ar.displayName;const Kr=l.forwardRef(({className:e,destructive:t,...s},i)=>_.jsx(zr,{ref:i,className:m("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none","focus:bg-accent focus:text-accent-foreground","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"text-red-500 focus:text-red-500 focus:bg-red-500/10",e),...s}));Kr.displayName=zr.displayName;const Ur=l.forwardRef(({className:e,...t},s)=>_.jsx(Wr,{ref:s,className:m("-mx-1 my-1 h-px bg-border",e),...t}));function Vr({kind:e,label:t,preview:s,inserted:i,unclicked:r,onLeftClick:n,onEdit:o,onDelete:a,onShare:h,onRefresh:c,footer:d,readOnly:u,noContextMenu:f,cornerHint:p,instructionsFile:v="CLAUDE.md"}){const x=l.useRef(null),b=m("agent-prompt"===e?i?"border-green-500/50 bg-green-500/10 hover:bg-green-500/15":"border-dashed border-border hover:border-border/80 hover:bg-muted-foreground/10 dark:hover:bg-muted-foreground/20":r?"border-blue-500/30 bg-blue-500/15 hover:bg-blue-500/20 dark:bg-blue-500/15 dark:hover:bg-blue-500/25":"border-transparent bg-background dark:bg-muted-foreground/10 hover:bg-muted-foreground/10 dark:hover:bg-muted-foreground/20 hover:border-muted-foreground/30"),S="agent-prompt"===e,w=!f||c?" · 右键更多":"",y="quick-prompt"===e?`点击发送${w}`:(i?`点击从 ${v} 移除`:`点击插入 ${v}`)+w,C=_.jsxs("div",{ref:x,className:m("group relative rounded-md border text-xs transition-colors cursor-pointer select-none",b),onClick:n,title:y,children:[S&&_.jsx("span",{"aria-hidden":!0,className:m("absolute top-1.5 left-1.5 h-2 w-2 rounded-full transition-colors",i?"bg-green-500 ring-1 ring-green-500/40":"border border-muted-foreground/40 bg-transparent")}),_.jsxs("div",{className:m("py-1.5",f&&p?"pr-10":f?"pr-2":"pr-7",S?"pl-5":"pl-3"),children:[_.jsx("div",{className:"font-medium truncate",children:t}),s&&s!==t&&_.jsx("div",{className:"mt-0.5 text-muted-foreground/80 truncate font-mono",children:s}),d]}),f&&p&&_.jsx("span",{"aria-hidden":!0,className:"absolute top-1.5 right-2 text-[10px] leading-none font-mono tabular-nums text-muted-foreground/60 pointer-events-none",children:p}),!f&&_.jsx("button",{onClick:e=>{e.stopPropagation(),e.preventDefault();const t=x.current;if(!t)return;const s=t.getBoundingClientRect(),i=new MouseEvent("contextmenu",{bubbles:!0,cancelable:!0,clientX:s.right-8,clientY:s.top+s.height/2,button:2});t.dispatchEvent(i)},className:m("absolute top-1 right-1 p-0.5 rounded transition-opacity","md:opacity-0 md:group-hover:opacity-100 md:focus-visible:opacity-100","hover:bg-muted-foreground/10 focus-visible:bg-muted-foreground/10","text-muted-foreground hover:text-foreground"),title:"更多","aria-label":"更多操作",children:_.jsx(_s,{className:"h-3.5 w-3.5"})})]});return!(!c&&(f||!o&&!a&&!h))?_.jsxs(Hr,{children:[_.jsx(Fr,{asChild:!0,children:C}),_.jsxs($r,{children:[c&&_.jsxs(Kr,{onSelect:c,children:[_.jsx(L,{className:"h-3.5 w-3.5"}),"更新"]}),!f&&!u&&o&&a&&_.jsxs(_.Fragment,{children:[c&&_.jsx(Ur,{}),_.jsxs(Kr,{onSelect:o,children:[_.jsx(g,{className:"h-3.5 w-3.5"}),"编辑"]}),_.jsxs(Kr,{destructive:!0,onSelect:a,children:[_.jsx(R,{className:"h-3.5 w-3.5"}),"删除"]}),h&&_.jsx(Ur,{})]}),!f&&h&&_.jsxs(Kr,{onSelect:h,children:[_.jsx(me,{className:"h-3.5 w-3.5"}),"共享到 ccweb-hub"]})]})]}):_.jsx("div",{onContextMenu:e=>e.preventDefault(),children:C})}function qr({open:e,onOpenChange:t,initialLabel:s,initialCommand:i,title:r,onSave:n}){const[o,a]=l.useState(s),[h,c]=l.useState(i),[d,u]=l.useState(!0);l.useEffect(()=>{e&&u(!0)},[e]),l.useEffect(()=>{e&&(a(s),c(i))},[e,s,i]);const f=()=>{const e=h.trim();e&&(n(o.trim()||e,e),t(!1))};return _.jsx(ye,{open:e,onOpenChange:t,modal:!1,children:_.jsxs(Ce,{noOverlay:!0,className:m("sm:max-w-2xl max-h-[85vh] flex flex-col transition-opacity",!d&&"opacity-50"),onInteractOutside:e=>{e.preventDefault(),u(!1)},onClick:()=>u(!0),children:[_.jsxs(ke,{children:[_.jsx(Ne,{children:r}),_.jsx(je,{children:"左键点击卡片会把此命令发送到 CLI。"})]}),_.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col",children:[_.jsxs("div",{className:"space-y-2",children:[_.jsx(Ee,{htmlFor:"qp-label",children:"标签"}),_.jsx(U,{id:"qp-label",placeholder:"显示名(可选,默认用命令文本)",value:o,onChange:e=>a(e.target.value),className:"text-base",autoFocus:!0})]}),_.jsxs("div",{className:"space-y-2 flex-1 flex flex-col min-h-0",children:[_.jsx(Ee,{htmlFor:"qp-command",children:"命令"}),_.jsx("textarea",{id:"qp-command",placeholder:"输入要发送的命令...",value:h,onChange:e=>c(e.target.value),className:m("flex-1 min-h-[200px] w-full rounded-md border border-input bg-background px-4 py-3","text-base leading-relaxed font-mono","ring-offset-background placeholder:text-muted-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","resize-none"),onKeyDown:e=>{"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),f())}})]})]}),_.jsxs(Me,{className:"flex items-center justify-between sm:justify-between",children:[_.jsx("span",{className:"text-xs text-muted-foreground",children:"⌘↩ 保存"}),_.jsxs("div",{className:"flex gap-2",children:[_.jsx(F,{variant:"outline",onClick:()=>t(!1),children:"取消"}),_.jsx(F,{onClick:f,disabled:!h.trim(),children:"保存"})]})]})]})})}function Yr({title:e,count:t,onAdd:s,children:i}){return _.jsxs("div",{className:"px-2 py-2",children:[_.jsxs("div",{className:"flex items-center justify-between mb-1.5 px-1",children:[_.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-muted-foreground",children:[_.jsx("span",{children:e}),_.jsxs("span",{className:"text-muted-foreground/60",children:["(",t,")"]})]}),_.jsx("button",{onClick:s,className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted-foreground/10 transition-colors",title:"新建","aria-label":"新建",children:_.jsx(K,{className:"h-3 w-3"})})]}),i]})}function Gr({projectId:e,onSend:t}){const s=a(),[i,r]=l.useState([]),[n,o]=l.useState([]),h=E(),c=h.get(e),[d,u]=l.useState({open:!1}),[f,m]=l.useState(c.shareHubOpen),[p,g]=l.useState(c.shareHubLabel),[v,x]=l.useState(c.shareHubCommand),b=l.useCallback(t=>{r(e=>{const s=e.findIndex(e=>e.id===t);if(s<0||e[s].used)return e;const i=[...e];return i[s]={...i[s],used:!0},i}),pe(e,t,!0).catch(e=>{console.error("Failed to mark shortcut used:",e)})},[e]);l.useEffect(()=>{ge(e).then(r).catch(()=>r([]))},[e]),l.useEffect(()=>{ve().then(o).catch(()=>o([]))},[]);const S=l.useCallback(e=>{const t=[],s=new Set;let i=e;const r=[];for(;i&&!s.has(i.id);)s.add(i.id),r.unshift(i),i=i.parentId?n.find(e=>e.id===i.parentId):void 0;for(const n of r)t.push(n.command);return t},[n]),w=l.useCallback(async e=>{const s=S(e);for(const i of s)try{await Promise.resolve(t(i+"\r"))}catch{return}},[S,t]),y=e=>u({open:!0,mode:"create",scope:e}),C=(t,s)=>{g(t),x(s),m(!0),h.setShareHub(e,!0,t,s)};return _.jsxs("div",{className:"h-full flex flex-col text-foreground overflow-hidden",children:[_.jsxs("div",{className:"px-3 pt-2.5 pb-2 border-b border-border/50 shrink-0",children:[_.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Quick Prompts"}),_.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground/70 leading-snug",children:"点击卡片发送命令到 CLI;新建的命令在首次点击前以浅蓝色标识"})]}),_.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[_.jsx(Yr,{title:"项目",count:i.length,onAdd:()=>y("project"),children:0===i.length?_.jsx("div",{className:"px-1 py-3 text-xs text-muted-foreground/60",children:"暂无项目命令"}):_.jsx("div",{className:"space-y-1.5",children:i.map(i=>_.jsx(Vr,{kind:"quick-prompt",label:i.label,preview:i.label!==i.command?i.command:"",unclicked:!i.used,onLeftClick:()=>(e=>{t(e.command+"\r"),b(e.id)})(i),onEdit:()=>(e=>u({open:!0,mode:"edit",scope:"project",id:e.id,label:e.label,command:e.command}))(i),onDelete:()=>{(async t=>{if(await s({title:"删除项目快捷 Prompt",description:`确认删除「${t.label}」?此操作不可撤销。`,destructive:!0,confirmLabel:"删除"}))try{await Se(e,t.id),r(e=>e.filter(e=>e.id!==t.id))}catch(i){console.error("Failed to delete shortcut:",i)}})(i)},onShare:()=>C(i.label,i.command)},i.id))})}),_.jsx("div",{className:"h-px bg-border mx-2"}),_.jsx(Yr,{title:"全局",count:n.length,onAdd:()=>y("global"),children:0===n.length?_.jsx("div",{className:"px-1 py-3 text-xs text-muted-foreground/60",children:"暂无全局命令"}):_.jsx("div",{className:"space-y-1.5",children:n.map(e=>{var t;const i=e.parentId?null==(t=n.find(t=>t.id===e.parentId))?void 0:t.label:void 0;return _.jsx(Vr,{kind:"quick-prompt",label:e.label,preview:i?"":e.label!==e.command?e.command:"",onLeftClick:()=>w(e),onEdit:()=>(e=>u({open:!0,mode:"edit",scope:"global",id:e.id,label:e.label,command:e.command}))(e),onDelete:()=>{(async e=>{const t=n.filter(t=>t.parentId===e.id);if(await s({title:"删除全局快捷 Prompt",description:t.length>0?`「${e.label}」被 ${t.length} 个其他全局命令继承。删除后这些命令的继承会断链。确认删除?`:`确认删除「${e.label}」?此操作不可撤销。`,destructive:!0,confirmLabel:"删除"}))try{await we(e.id),o(t=>t.filter(t=>t.id!==e.id))}catch(i){console.error("Failed to delete global shortcut:",i)}})(e)},onShare:()=>C(e.label,e.command),footer:i?_.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[_.jsx(xe,{className:"h-2.5 w-2.5 text-muted-foreground"}),_.jsxs("span",{className:"text-muted-foreground truncate",children:["继承: ",i,"(继承链仅可在 Dashboard 编辑)"]})]}):null},e.id)})})})]}),_.jsx(qr,{open:d.open,onOpenChange:e=>{e||u({open:!1})},initialLabel:d.open&&"edit"===d.mode?d.label:"",initialCommand:d.open&&"edit"===d.mode?d.command:"",title:d.open?"create"===d.mode?`新建${"global"===d.scope?"全局":"项目"}命令`:"编辑命令":"",onSave:(t,s)=>{(async(t,s)=>{if(d.open)try{if("create"===d.mode)if("global"===d.scope){const e=await De({label:t,command:s});o(t=>[...t,e])}else{const i=await Re(e,{label:t,command:s});r(e=>[...e,i])}else if("global"===d.scope){const e=n.find(e=>e.id===d.id),i=await Le(d.id,{label:t,command:s,parentId:(null==e?void 0:e.parentId)??null});o(e=>e.map(e=>e.id===i.id?i:e))}else{const i=await Pe(e,d.id,{label:t,command:s});r(e=>e.map(e=>e.id===i.id?i:e))}}catch(i){console.error("Failed to save shortcut:",i)}})(t,s)}}),_.jsx(be,{open:f,onOpenChange:t=>{m(t),t||h.setShareHub(e,!1)},kind:"quick-prompt",label:p,content:v})]})}Ur.displayName=Wr.displayName;function Xr({open:e,onOpenChange:t,title:s,initialLabel:i,initialCommand:r,onSave:n,instructionsFile:o="CLAUDE.md"}){const[a,h]=l.useState(i),[c,d]=l.useState(r),[u,f]=l.useState(!0);l.useEffect(()=>{e&&(h(i),d(r),f(!0))},[e,i,r]);const p=a.trim(),g=c.trim(),v=p.length>100,x=g.length>8e3,b=g.length>0&&p.length>0&&!v&&!x,S=()=>{b&&(n(p,c),t(!1))};return _.jsx(ye,{open:e,onOpenChange:t,modal:!1,children:_.jsxs(Ce,{noOverlay:!0,className:m("sm:max-w-2xl max-h-[85vh] flex flex-col transition-opacity",!u&&"opacity-50"),onInteractOutside:e=>{e.preventDefault(),f(!1)},onClick:()=>f(!0),children:[_.jsxs(ke,{children:[_.jsx(Ne,{children:s}),_.jsxs(je,{children:["This prompt can be clicked once in the sidebar to insert into ",o,", and clicked again to remove (by exact text match)."]})]}),_.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col",children:[_.jsxs("div",{className:"space-y-2",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsx(Ee,{htmlFor:"prompt-label",children:"Label"}),_.jsxs("span",{className:m("text-xs text-muted-foreground",v&&"text-red-500"),children:[p.length," / ",100]})]}),_.jsx(U,{id:"prompt-label",placeholder:"A short name for this prompt",value:a,onChange:e=>h(e.target.value),className:"text-base",autoFocus:!0})]}),_.jsxs("div",{className:"space-y-2 flex-1 flex flex-col min-h-0",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsx(Ee,{htmlFor:"prompt-command",children:"Prompt"}),_.jsxs("span",{className:m("text-xs text-muted-foreground",x&&"text-red-500"),children:[g.length," / ",8e3]})]}),_.jsx("textarea",{id:"prompt-command",placeholder:`The exact text that will be appended to ${o}...`,value:c,onChange:e=>d(e.target.value),className:m("flex-1 min-h-[200px] w-full rounded-md border border-input bg-background px-4 py-3","text-sm leading-relaxed font-mono","ring-offset-background placeholder:text-muted-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","resize-none"),onKeyDown:e=>{"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),S())}})]})]}),_.jsxs(Me,{className:"flex items-center justify-between sm:justify-between",children:[_.jsx("span",{className:"text-xs text-muted-foreground",children:"⌘↩ to save"}),_.jsxs("div",{className:"flex gap-2",children:[_.jsx(F,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),_.jsx(F,{onClick:S,disabled:!b,children:"Save"})]})]})]})})}function Jr({projectId:e}){const t=a(),[s,i]=l.useState([]),[r,n]=l.useState([]),[o,h]=l.useState("CLAUDE.md"),[c,d]=l.useState(!0),[u,m]=l.useState({open:!1}),[p,g]=l.useState({open:!1,label:"",content:""}),v=l.useCallback(async()=>{try{const t=await Te(e);i(t.global),n(t.project),t.instructionsFilename&&h(t.instructionsFilename)}catch(t){f.error(`加载提示词失败: ${t.message}`)}finally{d(!1)}},[e]);l.useEffect(()=>{d(!0),v()},[v]);const x=l.useRef(new Set),b=l.useCallback(async(t,s)=>{if(x.current.has(s.id))return;x.current.add(s.id);const r=s.inserted?"remove":"insert",a=e=>e.map(e=>e.id===s.id?{...e,inserted:!e.inserted}:e);"global"===t?i(a):n(a);try{const t=await Be(e,s.command,r);if("remove"===r&&!1===t.changed)return"not-found"===t.reason?f.error(`${o} 中找不到该提示词的精确文本,请自行编辑 ${o} 移除。`):f.warning(`该提示词当前不在 ${o} 中(可能被手动编辑过),已重新同步状态。`),void v();v()}catch(l){f.error(`操作失败: ${l.message}`),"global"===t?i(a):n(a)}finally{x.current.delete(s.id)}},[e,v,o]),S=l.useCallback(async(t,s,i,r,n)=>{try{if("create"===t)"global"===s?await Ie({label:r,command:n}):await Oe(e,{label:r,command:n}),f.success("已添加");else{if(!i)return;"global"===s?await Ae(i,{label:r,command:n}):await ze(e,i,{label:r,command:n}),f.success("已更新")}v()}catch(o){f.error(`保存失败: ${o.message}`)}},[e,v]),w=l.useCallback(async(s,i)=>{const r=i.inserted?`此提示词目前已插入当前项目的 ${o}。\n\n删除后它会在 ${o} 中成为"孤儿文本"——仅删除提示词记录,不会自动从 ${o} 移除。\n\n确认删除?`:"确认删除此提示词?此操作不可撤销。";if(await t({title:"删除提示词",description:r,destructive:!0,confirmLabel:"删除"}))try{"global"===s?await We(i.id):await He(e,i.id),f.success("已删除"),v()}catch(n){f.error(`删除失败: ${n.message}`)}},[e,v,t,o]),y=l.useCallback(e=>{g({open:!0,label:e.label,content:e.command})},[]);return _.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[_.jsxs("div",{className:"px-3 pt-2.5 pb-2 border-b border-border/50 shrink-0",children:[_.jsx("span",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"Agent Prompts"}),_.jsxs("p",{className:"mt-1 text-[11px] text-muted-foreground/70 leading-snug",children:["点击卡片插入 / 移出当前项目的 ",o,";左上角绿点表示已插入"]})]}),_.jsx(Zr,{title:"项目",count:r.length,loading:c,prompts:r,emptyText:"暂无项目提示词",instructionsFile:o,onAdd:()=>m({open:!0,mode:"create",scope:"project"}),onToggle:e=>{b("project",e)},onEdit:e=>m({open:!0,mode:"edit",scope:"project",id:e.id,label:e.label,command:e.command}),onDelete:e=>{w("project",e)},onShare:y}),_.jsx("div",{className:"h-px bg-border mx-2"}),_.jsx(Zr,{title:"全局",count:s.length,loading:c,prompts:s,emptyText:"暂无全局提示词",instructionsFile:o,onAdd:()=>m({open:!0,mode:"create",scope:"global"}),onToggle:e=>{b("global",e)},onEdit:e=>m({open:!0,mode:"edit",scope:"global",id:e.id,label:e.label,command:e.command}),onDelete:e=>{w("global",e)},onShare:y}),_.jsx(Xr,{open:u.open,onOpenChange:e=>{e||m({open:!1})},title:!1===u.open?"":"create"===u.mode?`新建${"global"===u.scope?"全局":"项目"}提示词`:`编辑${"global"===u.scope?"全局":"项目"}提示词`,initialLabel:u.open&&"edit"===u.mode?u.label:"",initialCommand:u.open&&"edit"===u.mode?u.command:"",instructionsFile:o,onSave:(e,t)=>{if(!u.open)return;const s="edit"===u.mode?u.id:null;S(u.mode,u.scope,s,e,t)}}),_.jsx(be,{open:p.open,onOpenChange:e=>g(t=>({...t,open:e})),kind:"agent-prompt",label:p.label,content:p.content})]})}function Zr({title:e,count:t,loading:s,prompts:i,emptyText:r,onAdd:n,onToggle:o,onEdit:a,onDelete:l,onShare:h,instructionsFile:c}){return _.jsxs("div",{className:"px-2 py-2",children:[_.jsxs("div",{className:"flex items-center justify-between mb-1.5 px-1",children:[_.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-muted-foreground uppercase tracking-wider",children:[_.jsx("span",{children:e}),_.jsxs("span",{className:"text-muted-foreground/60 normal-case tracking-normal",children:["(",t,")"]})]}),_.jsx("button",{onClick:n,className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted-foreground/10 transition-colors",title:"新建","aria-label":"新建",children:_.jsx(K,{className:"h-3 w-3"})})]}),s?_.jsx("div",{className:"px-1 py-3 text-xs text-muted-foreground/60",children:"加载中…"}):0===i.length?_.jsx("div",{className:"px-1 py-3 text-xs text-muted-foreground/60",children:r}):_.jsx("div",{className:"space-y-1.5",children:i.map(e=>{const t=e.command.split("\n").find(e=>e.trim())??e.command.trim();return _.jsx(Vr,{kind:"agent-prompt",label:e.label,preview:t,inserted:e.inserted,instructionsFile:c,onLeftClick:()=>o(e),onEdit:()=>a(e),onDelete:()=>l(e),onShare:()=>h(e)},e.id)})})]})}function Qr({projectId:e}){const[t,s]=l.useState([]),[i,r]=l.useState(null),[n,o]=l.useState("CLAUDE.md"),[a,h]=l.useState(!0),[c,d]=l.useState(!1),u=l.useRef(new Set),p=l.useCallback(async()=>{h(!0);try{const t=await Fe(e);s(t.items),r(t.claudeMdLineCount),t.instructionsFilename&&o(t.instructionsFilename)}catch(t){f.error(`加载失败: ${t.message}`)}finally{h(!1)}},[e]);l.useEffect(()=>{p()},[p]);const g=l.useCallback(async t=>{if(u.current.has(t.filename))return;u.current.add(t.filename),s(e=>e.map(e=>e.filename===t.filename?{...e,inserted:!e.inserted}:e));const i=t.inserted?"remove":"insert";try{const n=await $e(e,t.filename,i);if(!n.ok)return f.error("操作失败"+(n.reason?`(${n.reason})`:"")),void p();s(e=>e.map(e=>e.filename===t.filename?{...e,inserted:n.inserted}:e)),"number"==typeof n.claudeMdLineCount&&r(n.claudeMdLineCount),"insert"===i&&"refreshed"===n.reason&&f.info(`${t.name} 已更新(文件内容有变化)`)}catch(n){f.error(`操作失败: ${n.message}`),s(e=>e.map(e=>e.filename===t.filename?{...e,inserted:t.inserted}:e))}finally{u.current.delete(t.filename)}},[e,p]),v=l.useCallback(async()=>{if(c)return;const i=t.filter(e=>e.inserted);if(0===i.length)return void f.info("没有已插入的 memory 卡片");d(!0);let n=0,o=0;for(const t of i)if(u.current.has(t.filename))o++;else{u.current.add(t.filename);try{const i=await $e(e,t.filename,"insert");i.ok?(s(e=>e.map(e=>e.filename===t.filename?{...e,inserted:i.inserted}:e)),"number"==typeof i.claudeMdLineCount&&r(i.claudeMdLineCount),n++):o++}catch{o++}finally{u.current.delete(t.filename)}}d(!1),0===o?f.success(`已从磁盘更新 ${n} 个 memory 卡片`):f.error(`${n} 个更新成功,${o} 个失败`)},[e,t,c]),x=l.useCallback(async t=>{if(!u.current.has(t.filename))if(t.inserted){u.current.add(t.filename);try{const i=await $e(e,t.filename,"insert");if(!i.ok)return f.error("更新失败"+(i.reason?`(${i.reason})`:"")),void p();s(e=>e.map(e=>e.filename===t.filename?{...e,inserted:i.inserted}:e)),"number"==typeof i.claudeMdLineCount&&r(i.claudeMdLineCount),f.success(`${t.name} 已从磁盘重新加载`)}catch(i){f.error(`更新失败: ${i.message}`)}finally{u.current.delete(t.filename)}}else f.info("卡片未插入,无需更新")},[e,p]);return _.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[_.jsxs("div",{className:"px-3 pt-2.5 pb-2 border-b border-border/50 shrink-0",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsx("span",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"Memory Prompts"}),_.jsxs("div",{className:"flex items-center gap-0.5",children:[_.jsx("button",{onClick:()=>{v()},disabled:c||!t.some(e=>e.inserted),className:m("p-0.5 rounded text-muted-foreground transition-colors","hover:text-foreground hover:bg-muted-foreground/10","disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-muted-foreground"),title:`把所有已插入卡片的内容从磁盘重新加载到 ${n}`,children:_.jsx(us,{className:m("h-3.5 w-3.5",c&&"animate-spin")})}),_.jsx("button",{onClick:()=>{p()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted-foreground/10 transition-colors",title:"刷新(重新扫描 .ccweb/memory/)",children:_.jsx(L,{className:m("h-3.5 w-3.5",a&&"animate-spin")})})]})]}),_.jsxs("p",{className:"mt-1 text-[11px] text-muted-foreground/70 leading-snug",children:["来自 ",_.jsx("code",{className:"text-[11px]",children:".ccweb/memory/*.md"})," 的文件,点击插入 / 移除 ",n,"(以",_.jsx("code",{className:"text-[11px]",children:" START 名 / END 名 "}),"包裹)"]}),null!==i&&_.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground/60 font-mono tabular-nums",children:[n,": ",i," 行"]})]}),_.jsx("div",{className:"px-2 py-2 flex-1 min-h-0",children:a&&0===t.length?_.jsx("div",{className:"px-1 py-6 text-xs text-muted-foreground/60 text-center",children:"加载中…"}):0===t.length?_.jsxs("div",{className:"px-1 py-8 text-xs text-muted-foreground/60 flex flex-col items-center gap-2",children:[_.jsx(as,{className:"h-5 w-5"}),_.jsxs("div",{className:"text-center leading-relaxed",children:["暂无 memory 文件",_.jsx("br",{}),"新建 ",_.jsx("code",{className:"text-[11px]",children:".ccweb/memory/*.md"})," 文件后点刷新"]})]}):_.jsx("div",{className:"space-y-1.5",children:t.map(e=>_.jsx(Vr,{kind:"agent-prompt",noContextMenu:!0,label:e.name,preview:e.preview,inserted:e.inserted,instructionsFile:n,cornerHint:`${e.lineCount} 行`,onLeftClick:()=>{g(e)},onRefresh:e.inserted?()=>{x(e)}:void 0},e.filename))})})]})}function en({projectId:e,onSend:t}){const[s,i]=ee(C.rightPanelTab,"shortcuts"),r="prompts"===s?"prompts":"memory"===s?"memory":"shortcuts";return _.jsxs(Dt,{value:r,onValueChange:e=>i(e),orientation:"vertical",className:"h-full flex bg-muted text-foreground overflow-hidden",children:[_.jsxs("div",{className:"flex-1 min-w-0 flex flex-col border-r border-border",children:[_.jsx(Pt,{value:"shortcuts",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx(Gr,{projectId:e,onSend:t})}),_.jsx(Pt,{value:"prompts",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx(Jr,{projectId:e})}),_.jsx(Pt,{value:"memory",className:"flex-1 min-h-0 mt-0 data-[state=inactive]:hidden",children:_.jsx(Qr,{projectId:e})})]}),_.jsxs(Rt,{className:m("flex flex-col items-center justify-start shrink-0","h-full w-9 border-l border-border rounded-none p-1 gap-1"),children:[_.jsx(Lt,{value:"shortcuts",title:"Quick Prompts (快捷 Prompts)","aria-label":"Quick Prompts",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(Ke,{className:"h-3.5 w-3.5"})}),_.jsx(Lt,{value:"prompts",title:"Agent Prompts","aria-label":"Agent Prompts",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(Ue,{className:"h-3.5 w-3.5"})}),_.jsx(Lt,{value:"memory",title:"Memory Prompts (.ccweb/memory/*.md)","aria-label":"Memory Prompts",className:m("h-7 w-7 p-0 rounded-md flex items-center justify-center"),children:_.jsx(as,{className:"h-3.5 w-3.5"})})]})]})}function tn(){if("undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID)return crypto.randomUUID();if("undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues){const e=new Uint8Array(16);crypto.getRandomValues(e),e[6]=15&e[6]|64,e[8]=63&e[8]|128;const t=e=>e.toString(16).padStart(2,"0");return`${t(e[0])}${t(e[1])}${t(e[2])}${t(e[3])}-${t(e[4])}${t(e[5])}-${t(e[6])}${t(e[7])}-${t(e[8])}${t(e[9])}-${t(e[10])}${t(e[11])}${t(e[12])}${t(e[13])}${t(e[14])}${t(e[15])}`}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}async function sn(e,t,s){const i={"Content-Type":"application/json"},r=c();r&&(i.Authorization=`Bearer ${r}`);const n=await fetch(t,{method:e,headers:i,body:void 0!==s?JSON.stringify(s):void 0});if(!n.ok){let e=`HTTP ${n.status}`;try{const t=await n.json();t.error&&(e=t.error)}catch{}throw new Error(e)}return n.json()}function rn(e,t){return sn("GET",`/api/projects/${e}/flows/file/${encodeURIComponent(t)}`)}function nn(e){return sn("POST",`/api/projects/${e}/flows/abort`)}function on({node:e,allIds:t,variables:s,constants:i,onChange:r,onDelete:n}){return _.jsxs("div",{className:"rounded-xl border border-border bg-card p-4 space-y-3",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsxs("span",{className:"text-xs font-mono text-muted-foreground",children:["#",e.id]}),_.jsx(U,{value:e.name,onChange:t=>r({...e,name:t.target.value}),className:"h-8 flex-1",placeholder:"节点名称"}),_.jsx("div",{className:"text-xs px-2 py-0.5 rounded bg-accent",children:an(e.kind)}),_.jsx(F,{size:"sm",variant:"ghost",onClick:n,title:"删除节点",children:_.jsx(R,{className:"h-4 w-4"})})]}),"user-input"===e.kind&&_.jsx(hn,{node:e,allIds:t,variables:s,constants:i,onChange:r}),"llm"===e.kind&&_.jsx(cn,{node:e,allIds:t,variables:s,constants:i,onChange:r}),"system-logic"===e.kind&&_.jsx(un,{node:e,allIds:t,variables:s,constants:i,onChange:r})]})}function an(e){return"user-input"===e?"用户输入":"llm"===e?"LLM":"系统逻辑"}function ln({value:e,allIds:t,selfId:s,onChange:i,label:r="下一节点"}){return _.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:r}),_.jsxs($t,{value:null===e?"__null":String(e),onValueChange:e=>i("__null"===e?null:Number(e)),children:[_.jsx(Kt,{className:"h-8 text-xs",children:_.jsx(Ut,{})}),_.jsxs(Vt,{children:[_.jsx(qt,{value:"__null",children:"— 结束 —"}),t.filter(e=>e!==s).map(e=>_.jsxs(qt,{value:String(e),children:["#",e]},e))]})]})]})}function hn({node:e,allIds:t,variables:s,constants:i,onChange:r}){const n=t=>r({...e,userInputSchema:{fields:t}}),o=(t,s,i)=>{const r=[...e.userInputSchema.fields],o={...r[t]};delete o.outputVariable,delete o.bindVariable,delete o.bindConstant,"out"===s&&i?o.outputVariable=i:"bindVar"===s&&i?o.bindVariable=i:"bindConst"===s&&i&&(o.bindConstant=i),r[t]=o,n(r)};return _.jsxs("div",{className:"space-y-3",children:[_.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"表单字段"}),e.userInputSchema.fields.map((t,r)=>{const a=(e=>e.outputVariable?"out":e.bindVariable?"bindVar":e.bindConstant?"bindConst":"none")(t),l=t.outputVariable??t.bindVariable??t.bindConstant??"",h=("bindConst"===a?i:s).filter(e=>!!e.name);return _.jsxs("div",{className:"space-y-1.5 rounded-md border border-border/60 p-2",children:[_.jsxs("div",{className:"flex gap-1.5",children:[_.jsx(U,{value:t.key,onChange:s=>{const i=[...e.userInputSchema.fields];i[r]={...t,key:s.target.value},n(i)},placeholder:"key",className:"w-32 h-8 font-mono text-xs"}),_.jsx(U,{value:t.label,onChange:s=>{const i=[...e.userInputSchema.fields];i[r]={...t,label:s.target.value},n(i)},placeholder:"显示标签",className:"flex-1 h-8 text-xs"}),_.jsxs($t,{value:t.type,onValueChange:s=>{const i=[...e.userInputSchema.fields];i[r]={...t,type:s},n(i)},children:[_.jsx(Kt,{className:"w-24 h-8 text-xs",children:_.jsx(Ut,{})}),_.jsxs(Vt,{children:[_.jsx(qt,{value:"text",children:"单行"}),_.jsx(qt,{value:"textarea",children:"多行"})]})]}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>n(e.userInputSchema.fields.filter((e,t)=>t!==r)),children:_.jsx(S,{className:"h-3.5 w-3.5"})})]}),(s.length>0||i.length>0)&&_.jsxs("div",{className:"flex gap-1.5 items-center",children:[_.jsx("span",{className:"text-[11px] text-muted-foreground",children:"绑定"}),_.jsxs($t,{value:a,onValueChange:e=>{var t,n;const a=e,h="bindConst"===a?(null==(t=i[0])?void 0:t.name)??null:(null==(n=s[0])?void 0:n.name)??null;o(r,a,l||h)},children:[_.jsx(Kt,{className:"w-40 h-7 text-xs",children:_.jsx(Ut,{})}),_.jsxs(Vt,{children:[_.jsx(qt,{value:"none",children:"无绑定"}),_.jsx(qt,{value:"out",disabled:0===s.length,children:"输出到变量"}),_.jsx(qt,{value:"bindVar",disabled:0===s.length,children:"显示变量(只读)"}),_.jsx(qt,{value:"bindConst",disabled:0===i.length,children:"显示常量(只读)"})]})]}),"none"!==a&&_.jsxs($t,{value:l,onValueChange:e=>o(r,a,e),children:[_.jsx(Kt,{className:"flex-1 h-7 text-xs",children:_.jsx(Ut,{placeholder:"选择名字"})}),_.jsx(Vt,{children:h.map(e=>_.jsxs(qt,{value:e.name,children:[_.jsx("span",{className:"font-mono",children:e.name}),_.jsx("span",{className:"opacity-60 ml-2",children:e.description||"(无描述)"})]},e.name))})]})]})]},r)}),_.jsxs(F,{size:"sm",variant:"ghost",onClick:()=>n([...e.userInputSchema.fields,{key:"",label:"",type:"text"}]),className:"h-7 text-xs",children:[_.jsx(K,{className:"h-3.5 w-3.5 mr-1"})," 添加字段"]})]}),_.jsx(ln,{value:e.next,allIds:t,selfId:e.id,onChange:t=>r({...e,next:t})})]})}function cn({node:e,allIds:t,variables:s,constants:i,onChange:r}){const n=e.readVariables??[],o=e.writeVariables??[],a=e.readConstants??[],l=(t,s)=>{const i=e[t]??[],n=i.includes(s)?i.filter(e=>e!==s):[...i,s];r({...e,[t]:n})};return _.jsxs("div",{className:"space-y-3",children:[_.jsxs("div",{className:"space-y-1.5",children:[_.jsxs(Ee,{className:"text-xs text-muted-foreground",children:["Prompt 模板 · 插值 ",_.jsx("span",{className:"font-mono",children:"{{var:name}}"})," 或 ",_.jsx("span",{className:"font-mono",children:"{{const:name}}"})]}),_.jsx("textarea",{value:e.promptTemplate,onChange:t=>r({...e,promptTemplate:t.target.value}),className:"w-full min-h-[120px] rounded-md border border-border bg-background px-3 py-2 text-xs font-mono resize-y outline-none focus:ring-2 focus:ring-ring/30",placeholder:"例:\n根据目标 {{var:goal}} 提取 {{const:max_keywords}} 个关键词,\n写入 .ccweb/workflow_data.json 的 variables.keywords 字段。"})]}),i.length>0&&_.jsx(dn,{label:"读取常量 · prompt 头部附常量值上下文",items:i,selected:a,onToggle:e=>l("readConstants",e),accent:"green"}),s.length>0&&_.jsxs(_.Fragment,{children:[_.jsx(dn,{label:"读取变量 · prompt 头部附变量当前值",items:s,selected:n,onToggle:e=>l("readVariables",e),accent:"blue"}),_.jsx(dn,{label:"写入变量 · prompt 末尾附 LLM 写盘指令",items:s,selected:o,onToggle:e=>l("writeVariables",e),accent:"primary"})]}),_.jsxs("div",{className:"flex gap-3",children:[_.jsxs("div",{className:"flex-1 space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"超时秒数"}),_.jsx(U,{type:"number",min:1,value:e.timeoutSec,onChange:t=>r({...e,timeoutSec:Math.max(1,Number(t.target.value)||1)}),className:"h-8 text-xs"})]}),_.jsx("div",{className:"flex-1",children:_.jsx(ln,{value:e.next,allIds:t,selfId:e.id,onChange:t=>r({...e,next:t})})})]})]})}function dn({label:e,items:t,selected:s,onToggle:i,accent:r}){const n={green:"bg-emerald-500/15 border-emerald-500/40 text-emerald-700 dark:text-emerald-400",blue:"bg-blue-500/15 border-blue-500/40 text-blue-600 dark:text-blue-400",primary:"bg-primary/15 border-primary/40 text-primary"}[r];return _.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:e}),_.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.map(e=>{const t=s.includes(e.name);return _.jsx("button",{type:"button",onClick:()=>i(e.name),className:`px-2 py-1 rounded-md text-xs border transition-colors ${t?n:"bg-muted/30 border-border text-muted-foreground hover:text-foreground"}`,title:e.description||"(无描述)",children:_.jsx("span",{className:"font-mono",children:e.name})},e.name)})})]})}function un({node:e,allIds:t,variables:s,constants:i,onChange:r}){const n=t=>r({...e,branches:t});return _.jsxs("div",{className:"space-y-3",children:[_.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"分支规则 · 按顺序匹配,先命中先生效"}),e.branches.map((r,o)=>{const a=!!r.constant,l=r.constant??r.variable??"",h=(a?i:s).filter(e=>!!e.name);return _.jsxs("div",{className:"flex gap-1.5 items-center",children:[_.jsxs($t,{value:a?"const":"var",onValueChange:t=>{var a,l;const h=[...e.branches];h[o]="const"===t?{constant:(null==(a=i[0])?void 0:a.name)??"",equals:r.equals,goto:r.goto}:{variable:(null==(l=s[0])?void 0:l.name)??"",equals:r.equals,goto:r.goto},n(h)},children:[_.jsx(Kt,{className:"w-20 h-8 text-xs",children:_.jsx(Ut,{})}),_.jsxs(Vt,{children:[_.jsx(qt,{value:"var",disabled:0===s.length,children:"变量"}),_.jsx(qt,{value:"const",disabled:0===i.length,children:"常量"})]})]}),_.jsxs($t,{value:l,onValueChange:t=>{const s=[...e.branches];s[o]=a?{constant:t,equals:r.equals,goto:r.goto}:{variable:t,equals:r.equals,goto:r.goto},n(s)},children:[_.jsx(Kt,{className:"w-32 h-8 text-xs",children:_.jsx(Ut,{placeholder:"名字"})}),_.jsx(Vt,{children:h.map(e=>_.jsx(qt,{value:e.name,children:_.jsx("span",{className:"font-mono",children:e.name})},e.name))})]}),_.jsx("span",{className:"text-xs text-muted-foreground",children:"=="}),_.jsx(U,{value:"string"==typeof r.equals?r.equals:JSON.stringify(r.equals),onChange:t=>{const s=[...e.branches];let i=t.target.value;try{i=JSON.parse(t.target.value)}catch{}s[o]={...r,equals:i},n(s)},placeholder:'值(如 true, 10, "yes")',className:"w-32 h-8 font-mono text-xs"}),_.jsx("span",{className:"text-xs text-muted-foreground",children:"→"}),_.jsxs($t,{value:String(r.goto),onValueChange:t=>{const s=[...e.branches];s[o]={...r,goto:Number(t)},n(s)},children:[_.jsx(Kt,{className:"w-24 h-8 text-xs",children:_.jsx(Ut,{})}),_.jsx(Vt,{children:t.map(e=>_.jsxs(qt,{value:String(e),children:["#",e]},e))})]}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>n(e.branches.filter((e,t)=>t!==o)),children:_.jsx(S,{className:"h-3.5 w-3.5"})})]},o)}),_.jsxs(F,{size:"sm",variant:"ghost",onClick:()=>{var t;const r=s.length>0?{variable:s[0].name,equals:!0,goto:e.id}:{constant:(null==(t=i[0])?void 0:t.name)??"",equals:!0,goto:e.id};n([...e.branches,r])},className:"h-7 text-xs",disabled:0===s.length&&0===i.length,children:[_.jsx(K,{className:"h-3.5 w-3.5 mr-1"})," 添加分支"]})]}),_.jsxs("div",{className:"flex gap-3",children:[_.jsxs("div",{className:"flex-1 space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"回边上限"}),_.jsx(U,{type:"number",min:0,value:e.maxRetries,onChange:t=>r({...e,maxRetries:Math.max(0,Number(t.target.value)||0)}),className:"h-8 text-xs"})]}),_.jsx("div",{className:"flex-1",children:_.jsx(ln,{value:e.defaultGoto??null,allIds:t,selfId:e.id,onChange:t=>r({...e,defaultGoto:t}),label:"默认 (无分支命中)"})})]})]})}function fn({nodes:e,entryNodeId:t,mode:s,state:i,onNodeClick:r}){const n=l.useMemo(()=>function(e,t){const s=new Map(e.map(e=>[e.id,e])),i=[],r=new Set,n=[t];for(;n.length;){const e=n.pop();if(r.has(e))continue;const t=s.get(e);if(!t)continue;r.add(e),i.push(e);const o=[];if("user-input"===t.kind||"llm"===t.kind)null!=t.next&&o.push(t.next);else if("system-logic"===t.kind){null!=t.defaultGoto&&o.push(t.defaultGoto);for(const e of t.branches)o.push(e.goto)}for(let s=o.length-1;s>=0;s--)n.push(o[s])}for(const o of e)r.has(o.id)||i.push(o.id);return i}(e,t),[e,t]),o=l.useMemo(()=>new Map(e.map(e=>[e.id,e])),[e]),a=l.useMemo(()=>new Set(((null==i?void 0:i.history)??[]).map(e=>e.nodeId)),[null==i?void 0:i.history]);return 0===n.length?_.jsx("div",{className:"text-xs text-muted-foreground px-3 py-2",children:"空流,添加节点以构建链路"}):_.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto py-2 px-3 scrollbar-thin",children:n.map((e,t)=>{const h=o.get(e);if(!h)return null;const c="user-input"===(d=h.kind)?Qt:"llm"===d?ss:hs;var d;const u="runtime"===s?function(e,t,s,i){return"completed"===i||"failed"===i||"aborted"===i?s.has(e)?"completed":"future":t===e?"current":s.has(e)?"completed":"future"}(e,null==i?void 0:i.currentNodeId,a,null==i?void 0:i.status):null,f=[];if("system-logic"===h.kind)for(const s of h.branches){const e=n.indexOf(s.goto);-1!==e&&e<t&&f.push(s.goto)}return _.jsxs(l.Fragment,{children:[_.jsxs("button",{type:"button",onClick:()=>null==r?void 0:r(e),disabled:!r,className:m("group flex-shrink-0 flex items-center gap-1.5 px-2.5 py-1 rounded-md border text-xs transition-all","editor"===s&&["user-input"===h.kind&&"bg-amber-500/10 border-amber-500/30 text-amber-700 dark:text-amber-300","llm"===h.kind&&"bg-primary/10 border-primary/30 text-primary","system-logic"===h.kind&&"bg-purple-500/10 border-purple-500/30 text-purple-700 dark:text-purple-300",r&&"hover:scale-105 cursor-pointer"],"runtime"===s&&["completed"===u&&"bg-emerald-500/15 border-emerald-500/40 text-emerald-700 dark:text-emerald-400","current"===u&&"bg-primary/15 border-primary text-primary ring-2 ring-primary/30 animate-pulse","future"===u&&"bg-muted/40 border-border text-muted-foreground"]),title:`#${h.id} · ${h.name}`,children:["runtime"===s&&"completed"===u&&_.jsx(Jt,{className:"h-3 w-3"}),"runtime"===s&&"current"===u&&_.jsx(is,{className:"h-3 w-3"}),"runtime"===s&&"future"===u&&_.jsx(Nt,{className:"h-3 w-3"}),"editor"===s&&_.jsx(c,{className:"h-3 w-3"}),_.jsxs("span",{className:"font-mono opacity-70",children:["#",h.id]}),_.jsx("span",{className:"max-w-[7rem] truncate",children:h.name}),f.length>0&&_.jsxs("span",{className:"flex items-center gap-0.5 ml-0.5 text-[10px] opacity-70",title:`回边 → ${f.map(e=>"#"+e).join(", ")}`,children:[_.jsx(ws,{className:"h-2.5 w-2.5"}),f.map(e=>"#"+e).join("")]})]}),t<n.length-1&&_.jsx(I,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground/50"})]},e)})})}const _n={"user-input":"用户输入",llm:"LLM","system-logic":"系统逻辑"},mn={"user-input":"弹框收集用户填写的字段,系统写入到输出文件",llm:"把 prompt 模板(含 {{file:...}} 插值)通过 chat 注入 agent","system-logic":"读 JSON 文件按字段值分支跳转,支持回边循环"};function pn({open:e,onOpenChange:t,allIds:s,danglingPredecessors:i,onCreate:r}){const[n,o]=l.useState(""),[a,h]=l.useState("llm"),[c,d]=l.useState(i[0]??null),u=()=>{const e=n.trim()||`新${_n[a]}节点`;r({name:e,kind:a,wireFrom:c}),o(""),t(!1)};return _.jsx(ye,{open:e,onOpenChange:t,children:_.jsxs(Ce,{className:"max-w-md",children:[_.jsx(ke,{children:_.jsx(Ne,{children:"添加节点"})}),_.jsxs("div",{className:"space-y-3",children:[_.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"节点名称"}),_.jsx(U,{value:n,onChange:e=>o(e.target.value),placeholder:`新${_n[a]}节点`,autoFocus:!0,onKeyDown:e=>{"Enter"===e.key&&u()}})]}),_.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"类型"}),_.jsxs($t,{value:a,onValueChange:e=>h(e),children:[_.jsx(Kt,{children:_.jsx(Ut,{})}),_.jsx(Vt,{children:["user-input","llm","system-logic"].map(e=>_.jsx(qt,{value:e,children:_n[e]},e))})]}),_.jsx("p",{className:"text-xs text-muted-foreground pt-0.5",children:mn[a]})]}),s.length>0&&_.jsxs("div",{className:"space-y-1.5",children:[_.jsxs(Ee,{className:"text-xs text-muted-foreground",children:["自动接到哪个节点之后?",null!=i[0]&&_.jsxs("span",{className:"ml-1 opacity-60",children:["(默认接「#",i[0],"」未连出口的尾节点)"]})]}),_.jsxs($t,{value:null==c?"none":String(c),onValueChange:e=>d("none"===e?null:Number(e)),children:[_.jsx(Kt,{children:_.jsx(Ut,{})}),_.jsxs(Vt,{children:[_.jsx(qt,{value:"none",children:"不自动连接(之后手动配 next)"}),s.map(e=>_.jsxs(qt,{value:String(e),children:["接到 #",e," 之后",i.includes(e)&&"(推荐)"]},e))]})]})]})]}),_.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>t(!1),children:"取消"}),_.jsx(F,{size:"sm",onClick:u,children:"创建"})]})]})})}function gn({def:e,onCancel:t,onSave:s}){const[i,r]=l.useState(()=>({...e,schemaVersion:2})),[n,o]=l.useState(!1),a=l.useRef({}),h=l.useMemo(()=>i.nodes.map(e=>e.id),[i.nodes]),c=l.useMemo(()=>i.nodes.filter(e=>"user-input"===e.kind||"llm"===e.kind?null===e.next:null==e.defaultGoto&&0===e.branches.length).map(e=>e.id),[i.nodes]),d=(e,t)=>{r(s=>({...s,nodes:s.nodes.map(s=>{if("user-input"===s.kind)return{...s,userInputSchema:{fields:s.userInputSchema.fields.map(s=>{if("variable"===t&&(s.outputVariable===e||s.bindVariable===e)){const{outputVariable:e,bindVariable:t,...i}=s;return i}if("constant"===t&&s.bindConstant===e){const{bindConstant:e,...t}=s;return t}return s})}};if("llm"===s.kind){const i={...s};return"variable"===t?(i.readVariables&&(i.readVariables=i.readVariables.filter(t=>t!==e)),i.writeVariables&&(i.writeVariables=i.writeVariables.filter(t=>t!==e))):i.readConstants&&(i.readConstants=i.readConstants.filter(t=>t!==e)),i}return"system-logic"===s.kind?{...s,branches:s.branches.filter(s=>"variable"===t?s.variable!==e:s.constant!==e)}:s})}))};return _.jsxs("div",{className:"flex-1 flex flex-col min-h-0 gap-3",children:[_.jsxs("div",{className:"grid grid-cols-2 gap-3 flex-shrink-0",children:[_.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"流名称"}),_.jsx(U,{value:i.name,onChange:e=>r({...i,name:e.target.value}),className:"h-8"})]}),_.jsxs("div",{className:"space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"入口节点"}),_.jsxs($t,{value:String(i.entryNodeId),onValueChange:e=>r({...i,entryNodeId:Number(e)}),children:[_.jsx(Kt,{className:"h-8 text-xs",children:_.jsx(Ut,{})}),_.jsx(Vt,{children:h.map(e=>_.jsxs(qt,{value:String(e),children:["#",e]},e))})]})]}),_.jsxs("div",{className:"col-span-2 space-y-1.5",children:[_.jsx(Ee,{className:"text-xs text-muted-foreground",children:"描述(可选)"}),_.jsx(U,{value:i.description??"",onChange:e=>r({...i,description:e.target.value}),className:"h-8"})]})]}),_.jsx(vn,{constants:i.constants??[],onChange:e=>r({...i,constants:e}),onDelete:e=>{r(t=>({...t,constants:(t.constants??[]).filter(t=>t.name!==e)})),d(e,"constant")}}),_.jsx(xn,{variables:i.variables??[],constants:i.constants??[],onChange:e=>r({...i,variables:e}),onDelete:e=>{r(t=>({...t,variables:(t.variables??[]).filter(t=>t.name!==e)})),d(e,"variable")}}),_.jsx("div",{className:"flex-shrink-0 border border-border rounded-xl bg-muted/30",children:_.jsx(fn,{nodes:i.nodes,entryNodeId:i.entryNodeId,mode:"editor",onNodeClick:e=>{var t;null==(t=a.current[e])||t.scrollIntoView({behavior:"smooth",block:"center"})}})}),_.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-3 pr-1",children:i.nodes.map(e=>_.jsx("div",{ref:t=>{a.current[e.id]=t},children:_.jsx(on,{node:e,allIds:h,variables:i.variables??[],constants:i.constants??[],onChange:t=>((e,t)=>{r({...i,nodes:i.nodes.map(s=>s.id===e?t:s)})})(e.id,t),onDelete:()=>(e=>{if(i.nodes.length<=1)return;const t=i.nodes.filter(t=>t.id!==e).map(t=>"user-input"===t.kind||"llm"===t.kind?t.next===e?{...t,next:null}:t:{...t,branches:t.branches.filter(t=>t.goto!==e),defaultGoto:t.defaultGoto===e?null:t.defaultGoto??null});r({...i,nodes:t,entryNodeId:i.entryNodeId===e?t[0].id:i.entryNodeId})})(e.id)})},e.id))}),_.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 pt-2 border-t border-border",children:[_.jsxs(F,{size:"sm",variant:"outline",onClick:()=>o(!0),children:[_.jsx(K,{className:"h-4 w-4 mr-1"})," 添加节点"]}),_.jsx("div",{className:"flex-1"}),_.jsx(F,{size:"sm",variant:"ghost",onClick:t,children:"取消"}),_.jsx(F,{size:"sm",onClick:()=>s(i),children:"保存"})]}),_.jsx(pn,{open:n,onOpenChange:o,allIds:h,danglingPredecessors:c,onCreate:({name:e,kind:t,wireFrom:s})=>{const n=(Math.max(0,...h)||0)+1,o=function(e,t,s){return"user-input"===e?{id:t,name:s,kind:"user-input",userInputSchema:{fields:[{key:"",label:"",type:"text"}]},next:null}:"llm"===e?{id:t,name:s,kind:"llm",promptTemplate:"",timeoutSec:600,next:null}:{id:t,name:s,kind:"system-logic",branches:[],maxRetries:3,defaultGoto:null}}(t,n,e);let l=[...i.nodes,o];null!=s&&(l=l.map(e=>e.id!==s?e:"user-input"===e.kind||"llm"===e.kind?{...e,next:n}:{...e,defaultGoto:n})),r({...i,nodes:l}),setTimeout(()=>{var e;null==(e=a.current[n])||e.scrollIntoView({behavior:"smooth",block:"center"})},50)}})]})}function vn({constants:e,onChange:t,onDelete:s}){const i=l.useMemo(()=>{const t=new Map;for(const s of e)t.set(s.name,(t.get(s.name)??0)+1);return t},[e]),r=(s,i)=>{t(e.map((e,t)=>s===t?{...e,...i}:e))};return _.jsxs("div",{className:"flex-shrink-0 border border-border rounded-xl bg-card p-3 space-y-2",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(Ee,{className:"text-sm font-medium",children:"常量"}),_.jsx("span",{className:"text-xs text-muted-foreground",children:"流定义时固定,运行时不可写。任意 JSON(字符串/数字/布尔/数组/对象)"}),_.jsx("div",{className:"flex-1"}),_.jsxs(F,{size:"sm",variant:"ghost",onClick:()=>t([...e,{name:"",value:"",description:""}]),className:"h-7 text-xs",children:[_.jsx(K,{className:"h-3.5 w-3.5 mr-1"})," 添加常量"]})]}),0===e.length&&_.jsx("p",{className:"text-xs text-muted-foreground italic px-1",children:"暂无常量。"}),e.map((n,o)=>{const a=!!n.name&&(i.get(n.name)??0)>1;return _.jsx(bn,{name:n.name,value:n.value,description:n.description??"",duplicate:a,onChangeName:e=>r(o,{name:e.trim()}),onChangeValue:e=>r(o,{value:e}),onChangeDescription:e=>r(o,{description:e}),onRemove:()=>(i=>{const r=e[i];r.name?s(r.name):t(e.filter((e,t)=>t!==i))})(o)},o)})]})}function xn({variables:e,constants:t,onChange:s,onDelete:i}){const r=l.useMemo(()=>{const t=new Map;for(const s of e)t.set(s.name,(t.get(s.name)??0)+1);return t},[e]),n=l.useMemo(()=>new Set(t.map(e=>e.name)),[t]),o=(t,i)=>{s(e.map((e,s)=>t===s?{...e,...i}:e))};return _.jsxs("div",{className:"flex-shrink-0 border border-border rounded-xl bg-card p-3 space-y-2",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(Ee,{className:"text-sm font-medium",children:"变量"}),_.jsx("span",{className:"text-xs text-muted-foreground",children:"运行时可写。user-input 字段或 LLM 节点产出;任意 JSON"}),_.jsx("div",{className:"flex-1"}),_.jsxs(F,{size:"sm",variant:"ghost",onClick:()=>s([...e,{name:"",description:"",initialValue:void 0}]),className:"h-7 text-xs",children:[_.jsx(K,{className:"h-3.5 w-3.5 mr-1"})," 添加变量"]})]}),0===e.length&&_.jsx("p",{className:"text-xs text-muted-foreground italic px-1",children:"暂无变量。"}),e.map((t,a)=>{const l=!!t.name&&(r.get(t.name)??0)>1||n.has(t.name);return _.jsx(bn,{name:t.name,value:t.initialValue,description:t.description,duplicate:l,valuePlaceholder:"初始值(可选,留空 = undefined)",onChangeName:e=>o(a,{name:e.trim()}),onChangeValue:e=>o(a,{initialValue:e}),onChangeDescription:e=>o(a,{description:e}),onRemove:()=>(t=>{const r=e[t];r.name?i(r.name):s(e.filter((e,s)=>s!==t))})(a)},a)})]})}function bn({name:e,value:t,description:s,duplicate:i,valuePlaceholder:r,onChangeName:n,onChangeValue:o,onChangeDescription:a,onRemove:h}){const[c,d]=l.useState(()=>void 0===t?"":"string"==typeof t?t:JSON.stringify(t,null,2)),[u,f]=l.useState(!1);return _.jsx("div",{className:"space-y-1.5 rounded-md border border-border/60 p-2",children:_.jsxs("div",{className:"flex gap-1.5 items-start",children:[_.jsxs("div",{className:"flex flex-col gap-1.5 w-32",children:[_.jsx(U,{value:e,onChange:e=>n(e.target.value),placeholder:"名字",className:"h-8 font-mono text-xs "+(i?"border-destructive":"")}),i&&_.jsxs("span",{title:"名字冲突(与常量/变量重名)",className:"text-destructive flex items-center text-[10px]",children:[_.jsx(Yt,{className:"h-3 w-3 mr-1"}),"重名"]})]}),_.jsxs("div",{className:"flex-1 space-y-1",children:[_.jsx("textarea",{value:c,onChange:e=>d(e.target.value),onBlur:()=>{if(""===c.trim())return o(void 0),void f(!1);try{const e=JSON.parse(c);o(e),f(!1)}catch{o(c),f(!0)}},placeholder:r??'JSON 值(如 10, "hi", [1,2], {"k":"v"})',className:"w-full min-h-[32px] rounded-md border border-border bg-background px-2 py-1 text-xs font-mono resize-y outline-none focus:ring-2 focus:ring-ring/30",rows:1}),u&&_.jsx("span",{className:"text-[10px] text-amber-600 dark:text-amber-400",children:"非合法 JSON — 已按字符串字面量保存"})]}),_.jsx(U,{value:s,onChange:e=>a(e.target.value),placeholder:"含义(LLM 引用时使用)",className:"flex-1 h-8 text-xs"}),_.jsx(F,{size:"sm",variant:"ghost",onClick:h,className:"h-8 w-8 p-0",children:_.jsx(S,{className:"h-3.5 w-3.5"})})]})})}function Sn(e){return{schemaVersion:2,id:tn(),name:e,description:"",entryNodeId:1,constants:[],variables:[{name:"goal",description:"研究目标"}],nodes:[{id:1,name:"初始化",kind:"user-input",userInputSchema:{fields:[{key:"goal",label:"研究目标",type:"text",outputVariable:"goal"}]},next:null}]}}function wn({projectId:e,open:t,onOpenChange:s}){const i=a(),[r,n]=l.useState("project"),[o,h]=l.useState([]),[c,d]=l.useState(!1),[u,m]=l.useState(null),[p,v]=l.useState(""),x=async(t=r)=>{d(!0);try{const s="global"===t?await sn("GET","/api/global/flows"):await function(e){return sn("GET",`/api/projects/${e}/flows`)}(e);h(s.files)}catch(s){f.error(s instanceof Error?s.message:"加载失败")}finally{d(!1)}};l.useEffect(()=>{t&&x(r)},[t,e,r]),l.useEffect(()=>{v("")},[r]);const b=()=>{const e=p.trim();if(!e)return void f.error("请输入流名称");const t=e.endsWith(".json")?e:`${e}.json`;m({filename:t,def:Sn(e.replace(/\.json$/,"")),source:r}),v("")},S=async t=>{try{const s="global"===r?await function(e){return sn("GET",`/api/global/flows/file/${encodeURIComponent(e)}`)}(t):await rn(e,t);m({filename:t,def:s,source:r})}catch(s){f.error(s instanceof Error?s.message:"读取失败")}},w=async(t,s,i)=>{try{"global"===i?await function(e,t){return sn("PUT",`/api/global/flows/file/${encodeURIComponent(e)}`,t)}(t,s):await function(e,t,s){return sn("PUT",`/api/projects/${e}/flows/file/${encodeURIComponent(t)}`,s)}(e,t,s),f.success("已保存"),m(null),x()}catch(r){f.error(r instanceof Error?r.message:"保存失败")}},y=async t=>{const s="global"===r?"全局任务流":"任务流";if(await i({description:`删除${s} ${t}?此操作不可恢复。`,confirmLabel:"删除",destructive:!0}))try{"global"===r?await function(e){return sn("DELETE",`/api/global/flows/file/${encodeURIComponent(e)}`)}(t):await function(e,t){return sn("DELETE",`/api/projects/${e}/flows/file/${encodeURIComponent(t)}`)}(e,t),f.success("已删除"),x()}catch(n){f.error(n instanceof Error?n.message:"删除失败")}},C=async t=>{try{await function(e,t,s="project"){return sn("POST",`/api/projects/${e}/flows/run`,{filename:t,source:s})}(e,t,r),f.success("任务流已启动"),s(!1)}catch(i){f.error(i instanceof Error?i.message:"启动失败")}};if(u){const e="global"===u.source?"(全局)":"";return _.jsx(ye,{open:t,onOpenChange:s,children:_.jsxs(Ce,{className:"max-w-4xl h-[80vh] flex flex-col",children:[_.jsx(ke,{children:_.jsxs(Ne,{children:["编辑任务流",e," · ",u.filename]})}),_.jsx(gn,{def:u.def,onCancel:()=>m(null),onSave:e=>w(u.filename,e,u.source)})]})})}return _.jsx(ye,{open:t,onOpenChange:s,children:_.jsxs(Ce,{className:"max-w-2xl",children:[_.jsx(ke,{children:_.jsx(Ne,{className:"text-lg font-semibold",children:"任务流"})}),_.jsx(Dt,{value:r,onValueChange:e=>n(e),children:_.jsxs(Rt,{children:[_.jsx(Lt,{value:"project",children:"项目流"}),_.jsx(Lt,{value:"global",children:"我的全局流"})]})}),"global"===r&&_.jsx("p",{className:"text-xs text-muted-foreground",children:"全局流是可复用的模板,运行时仍绑定到当前项目(PTY 与文件路径来自该项目)。"}),_.jsxs("div",{className:"flex gap-2 items-center",children:[_.jsx(U,{placeholder:"global"===r?"新全局流名称":"新流名称(例:research)",value:p,onChange:e=>v(e.target.value),onKeyDown:e=>{"Enter"===e.key&&b()},className:"flex-1"}),_.jsxs(F,{onClick:b,size:"sm",children:[_.jsx(K,{className:"h-4 w-4 mr-1"})," 新建"]}),_.jsx(F,{onClick:()=>x(),size:"sm",variant:"ghost",disabled:c,children:_.jsx(L,{className:"h-4 w-4 "+(c?"animate-spin":"")})})]}),_.jsxs("div",{className:"space-y-1 max-h-[55vh] overflow-y-auto",children:[0===o.length&&!c&&_.jsx("p",{className:"text-sm text-muted-foreground py-8 text-center",children:"global"===r?"暂无全局任务流。新建一个开始。":"暂无任务流。新建一个开始。"}),o.map(e=>_.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-border hover:bg-accent transition-colors",children:[_.jsx("span",{className:"flex-1 text-sm font-mono truncate",title:e,children:e}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>C(e),title:"运行",children:_.jsx(xs,{className:"h-4 w-4"})}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>S(e),title:"编辑",children:_.jsx(g,{className:"h-4 w-4"})}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>y(e),title:"删除",children:_.jsx(R,{className:"h-4 w-4"})})]},e))]})]})})}async function yn(e,t,s){const i={"Content-Type":"application/json"},r=c();r&&(i.Authorization=`Bearer ${r}`);const n=await fetch(t,{method:e,headers:i,body:void 0!==s?JSON.stringify(s):void 0});if(!n.ok){let e=`HTTP ${n.status}`;try{const t=await n.json();t.error&&(e=t.error)}catch{}throw new Error(e)}return n.json()}function Cn(e){return yn("POST",`/api/projects/${e}/tracks/abort`)}const kn=l.lazy(()=>N(()=>import("./TrackEditor-D1fPK_Jb.js"),__vite__mapDeps([13,1,2])).then(e=>({default:e.TrackEditor})));function Nn({projectId:e,open:t,onOpenChange:s}){const i=a(),[r,n]=l.useState("project"),[o,h]=l.useState([]),[c,d]=l.useState(!1),[u,m]=l.useState(null),[p,v]=l.useState(""),[x,b]=l.useState("basic"),S=async(t=r)=>{d(!0);try{const s="global"===t?await yn("GET","/api/global/tracks"):await function(e){return yn("GET",`/api/projects/${e}/tracks`)}(e);h(s.files)}catch(s){f.error(s instanceof Error?s.message:"加载失败")}finally{d(!1)}};l.useEffect(()=>{t&&S(r)},[t,e,r]),l.useEffect(()=>{v("")},[r]);const w=()=>{const e=p.trim();if(!e)return void f.error("请输入工作轨名称");const t=e.endsWith(".tr")?e:`${e}.tr`;m({filename:t,src:"ask_user"===x?'// Starter track with __ccweb_ask_user — pauses for user input.\n//\n// __ccweb_ask_user(spec) blocks until the user submits the dialog.\n// Field types: text / number / bool / enum (with variants).\n\nfai analyze(file_path: string, prompt: prompt)\n -> rating: int 0-10, comment: string maxLen=500 {\n}\n\nfunc main(input_path: string) -> any {\n let r = analyze(input_path, "请对此文件评分 0-10")\n\n // Pause and ask user to confirm or override the AI rating.\n let review = __ccweb_ask_user({\n fields: [\n { key: "decision", label: "AI 评分: " + r.rating + ",是否接受?", type: "enum", variants: ["accept", "override"] }\n ]\n })\n\n return { aiRating: r.rating, decision: review.decision, comment: r.comment }\n}\n\nexport main\n':'// Starter track — edit and save, then run.\n//\n// Reference: ~/Obsidian/Base/cc-web/工作流DSL.md (train-lang spec)\n\nfai analyze(file_path: string, prompt: prompt)\n -> rating: int 0-10, comment: string maxLen=500 {\n}\n\nfunc main(input_path: string) -> any {\n let r = analyze(input_path, "请对此文件评分 0-10,并简短说明")\n return r\n}\n\nexport main\n',source:r}),v("")},y=async t=>{try{const s="global"===r?await function(e){return yn("GET",`/api/global/tracks/file/${encodeURIComponent(e)}`)}(t):await function(e,t){return yn("GET",`/api/projects/${e}/tracks/file/${encodeURIComponent(t)}`)}(e,t);m({filename:t,src:s.source,source:r})}catch(s){f.error(s instanceof Error?s.message:"读取失败")}},C=async(t,s,i)=>{try{"global"===i?await function(e,t){return yn("PUT",`/api/global/tracks/file/${encodeURIComponent(e)}`,{source:t})}(t,s):await function(e,t,s){return yn("PUT",`/api/projects/${e}/tracks/file/${encodeURIComponent(t)}`,{source:s})}(e,t,s),f.success("已保存"),m(null),S()}catch(r){f.error(r instanceof Error?r.message:"保存失败")}},k=async t=>{const s="global"===r?"全局工作轨":"工作轨";if(await i({description:`删除${s} ${t}?此操作不可恢复。`,confirmLabel:"删除",destructive:!0}))try{"global"===r?await function(e){return yn("DELETE",`/api/global/tracks/file/${encodeURIComponent(e)}`)}(t):await function(e,t){return yn("DELETE",`/api/projects/${e}/tracks/file/${encodeURIComponent(t)}`)}(e,t),f.success("已删除"),S()}catch(n){f.error(n instanceof Error?n.message:"删除失败")}},N=async t=>{try{await function(e,t,s="project",i=[]){return yn("POST",`/api/projects/${e}/tracks/run`,{filename:t,source:s,args:i})}(e,t,r),f.success("工作轨已启动"),s(!1)}catch(i){f.error(i instanceof Error?i.message:"启动失败")}};if(u){const e="global"===u.source?"(全局)":"";return _.jsx(ye,{open:t,onOpenChange:s,children:_.jsxs(Ce,{className:"max-w-4xl h-[80vh] flex flex-col",children:[_.jsx(ke,{children:_.jsxs(Ne,{children:["编辑工作轨",e," · ",u.filename]})}),_.jsx(l.Suspense,{fallback:_.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"加载编辑器…"}),children:_.jsx(kn,{filename:u.filename,initialSource:u.src,onCancel:()=>m(null),onSave:e=>C(u.filename,e,u.source)})})]})})}return _.jsx(ye,{open:t,onOpenChange:s,children:_.jsxs(Ce,{className:"max-w-2xl",children:[_.jsx(ke,{children:_.jsx(Ne,{className:"text-lg font-semibold",children:"工作轨"})}),_.jsx(Dt,{value:r,onValueChange:e=>n(e),children:_.jsxs(Rt,{children:[_.jsx(Lt,{value:"project",children:"项目轨"}),_.jsx(Lt,{value:"global",children:"我的全局轨"})]})}),"global"===r&&_.jsx("p",{className:"text-xs text-muted-foreground",children:"全局轨是可复用的模板,运行时仍绑定到当前项目(PTY 与文件路径来自该项目)。"}),_.jsxs("div",{className:"flex gap-2 items-center",children:[_.jsx(U,{placeholder:"global"===r?"新全局轨名称":"新工作轨名称(例:review)",value:p,onChange:e=>v(e.target.value),onKeyDown:e=>{"Enter"===e.key&&w()},className:"flex-1"}),_.jsxs("select",{value:x,onChange:e=>b(e.target.value),className:"text-xs h-9 px-2 rounded-md border border-border bg-background",title:"新建时使用的初始模板",children:[_.jsx("option",{value:"basic",children:"基础模板"}),_.jsx("option",{value:"ask_user",children:"含 ask_user"})]}),_.jsxs(F,{onClick:w,size:"sm",children:[_.jsx(K,{className:"h-4 w-4 mr-1"})," 新建"]}),_.jsx(F,{onClick:()=>S(),size:"sm",variant:"ghost",disabled:c,children:_.jsx(L,{className:"h-4 w-4 "+(c?"animate-spin":"")})})]}),_.jsxs("div",{className:"space-y-1 max-h-[55vh] overflow-y-auto",children:[0===o.length&&!c&&_.jsx("p",{className:"text-sm text-muted-foreground py-8 text-center",children:"global"===r?"暂无全局工作轨。新建一个开始。":"暂无工作轨。新建一个开始。"}),o.map(e=>_.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-border hover:bg-accent transition-colors",children:[_.jsx("span",{className:"flex-1 text-sm font-mono truncate",title:e.filename,children:e.filename}),_.jsxs("span",{className:"text-xs text-muted-foreground tabular-nums",children:[Math.round(e.size/100)/10,"KB"]}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>N(e.filename),title:"运行",children:_.jsx(xs,{className:"h-4 w-4"})}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>y(e.filename),title:"编辑",children:_.jsx(g,{className:"h-4 w-4"})}),_.jsx(F,{size:"sm",variant:"ghost",onClick:()=>k(e.filename),title:"删除",children:_.jsx(R,{className:"h-4 w-4"})})]},e.filename))]})]})})}function jn({projectId:e,state:t,running:s,onRefresh:i}){if(!t)return null;let r=_.jsx(Ve,{className:"h-3 w-3 animate-spin"}),n="text-blue-600 dark:text-blue-400",o="运行中";switch(t.status){case"running":r=_.jsx(Ve,{className:"h-3 w-3 animate-spin"}),n="text-blue-600 dark:text-blue-400",o="运行中";break;case"paused":r=_.jsx(Ve,{className:"h-3 w-3"}),n="text-amber-600 dark:text-amber-400",o="等待输入";break;case"completed":r=_.jsx(Jt,{className:"h-3 w-3"}),n="text-emerald-600 dark:text-emerald-400",o="已完成";break;case"failed":r=_.jsx(ts,{className:"h-3 w-3"}),n="text-red-600 dark:text-red-400",o="失败";break;case"cancelled":r=_.jsx(ts,{className:"h-3 w-3"}),n="text-muted-foreground",o="已取消";break;default:r=_.jsx(Ve,{className:"h-3 w-3"})}return _.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[_.jsxs("span",{className:`flex items-center gap-1 ${n}`,children:[r,_.jsx("span",{className:"font-medium",children:o})]}),_.jsx("span",{className:"text-muted-foreground font-mono truncate max-w-[200px]",children:t.trackFilename}),void 0!==t.currentTaskIndex&&_.jsxs("span",{className:"text-muted-foreground",children:["#",t.currentTaskIndex]}),s&&_.jsx(F,{size:"sm",variant:"ghost",onClick:async()=>{try{await Cn(e),f.success("已请求中止"),i()}catch(t){f.error(t instanceof Error?t.message:"中止失败")}},title:"中止",className:"h-6 w-6 p-0",children:_.jsx(S,{className:"h-3 w-3"})}),"failed"===t.status&&t.error&&_.jsxs("span",{className:"text-red-600 dark:text-red-400 truncate max-w-[300px] font-mono",title:`${t.error.errorType}${t.error.code?` [${t.error.code}]`:""}: ${t.error.message}`,children:[t.error.code?`[${t.error.code}] `:"",t.error.message]})]})}function En({projectId:e,open:t,request:s,onSubmitted:i}){const r=a(),[n,o]=l.useState(()=>{var e;const t={};for(const i of s.fields)switch(i.type){case"bool":t[i.key]=!1;break;case"number":t[i.key]=0;break;case"enum":t[i.key]=(null==(e=i.variants)?void 0:e[0])??"";break;default:t[i.key]=""}return t}),[h,c]=l.useState(!1),d=(e,t)=>{o(s=>({...s,[e]:t}))};return _.jsx(ye,{open:t,onOpenChange:()=>{},children:_.jsxs(Ce,{className:"max-w-lg",onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>e.preventDefault(),children:[_.jsx(ke,{children:_.jsx(Ne,{children:"工作轨需要输入"})}),_.jsx("div",{className:"space-y-3",children:s.fields.map(e=>_.jsxs("div",{className:"space-y-1.5",children:[_.jsxs(Ee,{className:"text-xs text-muted-foreground",children:[e.label," ",_.jsxs("span",{className:"opacity-60 font-mono",children:["(",e.key,")"]})]}),"text"===e.type&&_.jsx(U,{value:n[e.key]??"",placeholder:e.placeholder,onChange:t=>d(e.key,t.target.value)}),"number"===e.type&&_.jsx(U,{type:"number",value:String(n[e.key]??""),placeholder:e.placeholder,onChange:t=>{const s=Number(t.target.value);d(e.key,Number.isNaN(s)?"":s)}}),"bool"===e.type&&_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx("input",{type:"checkbox",checked:!!n[e.key],onChange:t=>d(e.key,t.target.checked),className:"h-4 w-4"}),_.jsx("span",{className:"text-sm",children:n[e.key]?"是":"否"})]}),"enum"===e.type&&_.jsxs($t,{value:n[e.key]??"",onValueChange:t=>d(e.key,t),children:[_.jsx(Kt,{children:_.jsx(Ut,{placeholder:"选择..."})}),_.jsx(Vt,{children:(e.variants??[]).map(e=>_.jsx(qt,{value:e,children:e},e))})]})]},e.key))}),_.jsxs("div",{className:"flex justify-between items-center gap-2 pt-2",children:[_.jsx(F,{onClick:async()=>{if(await r({description:"中止整个工作轨运行?正在等待的 LLM 调用会被取消。",confirmLabel:"中止",destructive:!0}))try{await Cn(e),f.success("已请求中止"),i()}catch(t){f.error(t instanceof Error?t.message:"中止失败")}},variant:"ghost",size:"sm",disabled:h,className:"text-muted-foreground hover:text-destructive",children:"中止运行"}),_.jsx(F,{onClick:async()=>{c(!0);try{await function(e,t,s){return yn("POST",`/api/projects/${e}/tracks/input`,{requestId:t,data:s})}(e,s.requestId,n),i()}catch(t){f.error(t instanceof Error?t.message:"提交失败")}finally{c(!1)}},disabled:h,size:"sm",children:h?"提交中…":"提交"})]})]})})}function Mn(e){const[t,s]=l.useState(null),[i,r]=l.useState(!1),[n,o]=l.useState(null),a=l.useRef(e);a.current=e;const h=l.useCallback(async()=>{const e=a.current;if(e)try{const t=await function(e){return yn("GET",`/api/projects/${e}/tracks/state`)}(e);if(e!==a.current)return;s(t.state),r(t.running),o(t.pendingAskUser)}catch{}},[]),c=l.useRef(5e3),d=!!t||i||!!n;return l.useEffect(()=>{if(!e)return;const t=e=>{const t=e.detail;if(t&&t.type)switch(t.type){case"track_status_change":{const e=t;if(s(e.state),r("running"===e.state.status||"paused"===e.state.status),"failed"===e.state.status&&e.state.error){const t=e.state.error.code?`[${e.state.error.code}] `:"";f.error(`工作轨失败: ${t}${e.state.error.message}`)}else"cancelled"===e.state.status&&f.info("工作轨已取消");break}case"track_ask_user":{const e=t;o({runId:e.runId,requestId:e.requestId,fields:e.fields});break}case"track_run_complete":t.ok||o(null);break}};return window.addEventListener("ccweb:track-msg",t),()=>window.removeEventListener("ccweb:track-msg",t)},[e]),l.useEffect(()=>{if(!e)return s(null),r(!1),void o(null);let t=null;const i=d?5e3:3e4;c.current=i;const n=()=>{h(),t=setInterval(()=>{h()},i)},a=()=>{null!==t&&(clearInterval(t),t=null)},l=()=>{document.hidden?a():t||n()};return document.hidden||n(),document.addEventListener("visibilitychange",l),()=>{a(),document.removeEventListener("visibilitychange",l)}},[e,h,d]),{state:t,running:i,pendingAskUser:n,refresh:h}}var Dn=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"].reduce((e,t)=>{const s=qe(`Primitive.${t}`),i=l.forwardRef((e,i)=>{const{asChild:r,...n}=e,o=r?s:t;return"undefined"!=typeof window&&(window[Symbol.for("radix-ui")]=!0),_.jsx(o,{...n,ref:i})});return i.displayName=`Primitive.${t}`,{...e,[t]:i}},{}),Rn="horizontal",Ln=["horizontal","vertical"],Pn=l.forwardRef((e,t)=>{const{decorative:s,orientation:i=Rn,...r}=e,n=function(e){return Ln.includes(e)}(i)?i:Rn,o=s?{role:"none"}:{"aria-orientation":"vertical"===n?n:void 0,role:"separator"};return _.jsx(Dn.div,{"data-orientation":n,...o,...r,ref:t})});Pn.displayName="Separator";var Tn=Pn;const Bn=l.forwardRef(({className:e,orientation:t="horizontal",decorative:s=!0,...i},r)=>_.jsx(Tn,{ref:r,decorative:s,orientation:t,className:m("shrink-0 bg-border","horizontal"===t?"h-[1px] w-full":"h-full w-[1px]",e),...i}));Bn.displayName=Tn.displayName;const In=[{tool:"claude",label:"Claude Code",supportsContinue:!0},{tool:"codex",label:"Codex",supportsContinue:!0},{tool:"gemini",label:"Gemini CLI",supportsContinue:!0},{tool:"opencode",label:"OpenCode",supportsContinue:!1},{tool:"qwen",label:"Qwen Code",supportsContinue:!1},{tool:"terminal",label:"Bare Shell",supportsContinue:!1}];function On(e){var t;return(null==(t=In.find(t=>t.tool===e))?void 0:t.label)??String(e??"")}function An(e){var t;return(null==(t=In.find(t=>t.tool===e))?void 0:t.supportsContinue)??!1}function zn({open:e,onOpenChange:t,currentCliTool:s,loading:i,onConfirm:r}){const{t:n}=Ye(),[o,a]=l.useState(null),[h,c]=l.useState(!1),[d,u]=l.useState(null);l.useEffect(()=>{e&&(a(null),c(!1),u(null))},[e]),l.useEffect(()=>{o&&!An(o)&&c(!1)},[o]);const f=!!o&&An(o);return _.jsx(ye,{open:e,onOpenChange:t,children:_.jsxs(Ce,{className:"max-w-lg",children:[_.jsxs(ke,{children:[_.jsx(Ne,{children:n("switch_cli.title")}),_.jsx(je,{children:n("switch_cli.description",{current:On(s)})})]}),_.jsxs("div",{className:"space-y-4",children:[_.jsxs("div",{className:"space-y-2",children:[_.jsx("div",{className:"text-sm font-medium",children:n("switch_cli.target_label")}),_.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:In.map(e=>{const t=e.tool===s,r=e.tool===o;return _.jsxs("button",{type:"button",disabled:t||i,onClick:()=>a(e.tool),className:m("text-left px-3 py-2 rounded-md border text-sm transition-colors",r?"border-primary bg-accent":"border-border hover:bg-accent/50",t&&"opacity-50 cursor-not-allowed"),children:[_.jsx("div",{className:"font-medium",children:e.label}),_.jsx("div",{className:"text-xs text-muted-foreground",children:t?n("switch_cli.tag_current"):e.supportsContinue?n("switch_cli.tag_supports_continue"):n("switch_cli.tag_no_continue")})]},e.tool)})})]}),_.jsxs("div",{className:"space-y-2",children:[_.jsx("div",{className:"text-sm font-medium",children:n("switch_cli.mode_label")}),_.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[_.jsxs("button",{type:"button",disabled:i,onClick:()=>c(!1),className:m("text-left px-3 py-2 rounded-md border text-sm transition-colors",h?"border-border hover:bg-accent/50":"border-primary bg-accent"),children:[_.jsx("div",{className:"font-medium",children:n("switch_cli.mode_fresh")}),_.jsx("div",{className:"text-xs text-muted-foreground",children:n("switch_cli.mode_fresh_hint")})]}),_.jsxs("button",{type:"button",disabled:i||!o||!f,onClick:()=>c(!0),title:o&&!f?n("switch_cli.mode_continue_unsupported",{tool:On(o)}):void 0,className:m("text-left px-3 py-2 rounded-md border text-sm transition-colors",h?"border-primary bg-accent":"border-border hover:bg-accent/50",(!o||!f)&&"opacity-50 cursor-not-allowed"),children:[_.jsx("div",{className:"font-medium",children:n("switch_cli.mode_continue")}),_.jsx("div",{className:"text-xs text-muted-foreground",children:o&&!f?n("switch_cli.mode_continue_unsupported",{tool:On(o)}):n("switch_cli.mode_continue_hint")})]})]})]}),d&&_.jsx("div",{className:"text-xs text-red-500 break-words",children:d})]}),_.jsxs(Me,{children:[_.jsx(F,{variant:"outline",onClick:()=>t(!1),disabled:i,children:n("switch_cli.cancel")}),_.jsx(F,{onClick:()=>{(async()=>{if(o){u(null);try{await r(o,h)}catch(e){u(e instanceof Error?e.message:String(e))}}})()},disabled:!o||i,children:n(i?"switch_cli.confirming":"switch_cli.confirm")})]})]})})}function Wn({status:e}){return _.jsxs("span",{className:m("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",{running:"bg-green-500/10 text-green-600 border-green-500/20",stopped:"bg-muted text-muted-foreground border-border",restarting:"bg-yellow-500/10 text-yellow-600 border-yellow-500/20"}[e]),children:[_.jsx("span",{className:m("w-1.5 h-1.5 rounded-full",{"bg-green-500":"running"===e,"bg-muted-foreground":"stopped"===e,"bg-yellow-400 animate-pulse":"restarting"===e})}),e.charAt(0).toUpperCase()+e.slice(1)]})}function Hn({project:e,projectId:t,showFileTree:s,showShortcuts:i,showChatOverlay:r,onToggleFileTree:n,onToggleShortcuts:o,onToggleChatOverlay:a,onProjectUpdate:h}){const{t:c}=Ye(),d=Ge(),[u,p]=l.useState(!1),[g,v]=l.useState(!1),[w,y]=l.useState(0),[C,k]=l.useState(!1),[N,j]=l.useState(!1),[E,M]=l.useState(!1),[D,R]=l.useState(!1),[P,T]=l.useState(!1),[B,I]=l.useState(!1),O=Mn(e.id);Xe({onStart:e=>{e.projectId===t&&y(0)},onProgress:e=>{e.projectId===t&&y(e.filesTransferred)},onDone:e=>{e.projectId===t&&y(0)}}),l.useEffect(()=>{const e=()=>j(!!document.fullscreenElement);return document.addEventListener("fullscreenchange",e),()=>document.removeEventListener("fullscreenchange",e)},[]);const A=Je(e=>e.updateProject);return _.jsx("header",{className:"border-b border-border flex-shrink-0 bg-muted/50",children:_.jsxs("div",{className:"px-3 h-12 flex items-center gap-2",children:[_.jsx(F,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>d("/"),children:_.jsx(Ze,{className:"h-4 w-4"})}),_.jsx(Bn,{orientation:"vertical",className:"h-5 mx-0.5"}),_.jsx(F,{variant:"ghost",size:"icon",className:m("h-7 w-7",s&&"bg-accent"),onClick:n,title:c("project_header.toggle_file_tree"),children:_.jsx(ps,{className:"h-4 w-4"})}),_.jsx(F,{variant:"ghost",size:"icon",className:m("h-7 w-7",i&&"bg-accent"),onClick:o,title:c("project_header.toggle_right_panel"),children:_.jsx(gs,{className:"h-4 w-4"})}),"terminal"!==e.cliTool&&_.jsx(F,{variant:"ghost",size:"icon",className:m("h-7 w-7",r&&"bg-accent"),onClick:a,title:c("project_header.toggle_chat_overlay"),children:_.jsx(fs,{className:"h-4 w-4"})}),"terminal"!==e.cliTool&&_.jsxs(_.Fragment,{children:[_.jsx(F,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>T(!0),title:"任务流(旧)",children:_.jsx(Cs,{className:"h-4 w-4"})}),_.jsx(F,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>I(!0),title:"工作轨",children:_.jsx(ys,{className:"h-4 w-4"})})]}),_.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2 ml-2",children:[_.jsx("h1",{className:"font-semibold text-foreground truncate text-sm",children:e.name}),_.jsx(Wn,{status:e.status}),_.jsx(Qe,{variant:"outline",className:"text-xs",children:"unlimited"===e.permissionMode?"Unlimited":"Limited"}),O.state&&_.jsx(jn,{projectId:e.id,state:O.state,running:O.running,onRefresh:O.refresh}),_.jsxs("button",{type:"button",onClick:()=>M(!0),disabled:D,title:`${c("project_header.switch_cli_title")} (${On(e.cliTool)})`,className:"inline-flex items-center gap-1 text-xs px-2 py-0.5 rounded-full border border-border bg-background hover:bg-accent transition-colors disabled:opacity-50 flex-shrink-0",children:[_.jsx(L,{className:"h-3 w-3"}),_.jsx("span",{className:"font-medium hidden sm:inline",children:On(e.cliTool)})]}),_.jsx("span",{className:"text-xs text-muted-foreground font-mono truncate hidden lg:block",children:e.folderPath})]}),_.jsx(et,{}),_.jsx(tt,{}),_.jsx(F,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>{document.fullscreenElement?document.exitFullscreen():document.documentElement.requestFullscreen()},title:c(N?"project_header.fullscreen_exit":"project_header.fullscreen_enter"),children:N?_.jsx(x,{className:"h-3.5 w-3.5"}):_.jsx(b,{className:"h-3.5 w-3.5"})}),_.jsx(Bn,{orientation:"vertical",className:"h-5 mx-0.5"}),g?_.jsxs(F,{variant:"outline",size:"sm",className:"flex-shrink-0",onClick:()=>{(async()=>{if(g&&!C){k(!0);try{(await it(t)).cancelled?f.info(c("project_header.sync_cancelled")):f.error(c("project_header.sync_cancel_failed"))}catch(e){f.error(e instanceof Error?e.message:c("project_header.sync_cancel_failed")),k(!1)}}})()},disabled:C,title:c("project_header.sync_cancel_title"),children:[C?_.jsx(Ve,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):_.jsx(S,{className:"h-3.5 w-3.5 mr-1.5"}),_.jsx("span",{className:"tabular-nums",children:w>0?c("project_header.sync_progress_label",{files:w}):c("project_header.sync_progress_label_empty")})]}):_.jsxs(F,{variant:"outline",size:"sm",className:"flex-shrink-0",onClick:()=>{(async()=>{if(!g){v(!0),y(0);try{const e=await rt(t);e.skipped?f.info(c("project_header.sync_skipped")):e.ok?f.success(c("project_header.sync_success",{files:e.filesTransferred,seconds:Math.round(e.durationMs/1e3)})):"cancelled"===e.reason||f.error(e.reason?c("project_header.sync_failed_with_reason",{reason:e.reason}):c("project_header.sync_failed"))}catch(e){f.error(e instanceof Error?e.message:c("project_header.sync_failed"))}finally{v(!1),y(0),k(!1)}}})()},title:c("project_header.sync_button_title"),children:[_.jsx(st,{className:"h-3.5 w-3.5 mr-1.5"}),c("project_header.sync")]}),_.jsx(zn,{open:E,onOpenChange:e=>{D||M(e)},currentCliTool:e.cliTool,loading:D,onConfirm:async(t,s)=>{R(!0);try{const i=await nt(e.id,t,s);h(i),A(i),M(!1),f.success(c("switch_cli.switched_toast",{tool:On(t)}))}catch(i){const e=i instanceof Error?i.message:String(i);throw f.error(c("switch_cli.switch_failed",{reason:e})),i}finally{R(!1)}}}),_.jsx(wn,{projectId:t,open:P,onOpenChange:T}),_.jsx(Nn,{projectId:e.id,open:B,onOpenChange:I}),O.pendingAskUser&&_.jsx(En,{projectId:e.id,open:!!O.pendingAskUser,request:O.pendingAskUser,onSubmitted:()=>O.refresh()}),"stopped"===e.status&&_.jsxs(F,{variant:"outline",size:"sm",className:"flex-shrink-0",onClick:()=>{(async()=>{p(!0);try{h(await ot(e.id))}catch(t){console.error(t)}finally{p(!1)}})()},disabled:u,children:[_.jsx(xs,{className:"h-3.5 w-3.5 mr-1.5"}),"Start"]})]})})}
|
|
15
15
|
/**
|
|
16
16
|
* Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
|
|
17
17
|
* @license MIT
|