@lovelybunch/api 1.0.71-alpha.1 → 1.0.71-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/lib/file-validation.d.ts +65 -0
  2. package/dist/lib/file-validation.js +125 -0
  3. package/dist/middleware/auth.d.ts +1 -0
  4. package/dist/middleware/auth.js +13 -3
  5. package/dist/routes/api/v1/events/status/route.d.ts +1 -1
  6. package/dist/routes/api/v1/jobs/[id]/run/route.d.ts +2 -2
  7. package/dist/routes/api/v1/jobs/status/route.d.ts +1 -1
  8. package/dist/routes/api/v1/proposals/[id]/route.d.ts +8 -8
  9. package/dist/routes/api/v1/resources/route.js +10 -7
  10. package/package.json +5 -4
  11. package/static/assets/AgentDetailPage-DVDnvYcy.js +1 -0
  12. package/static/assets/AgentEditPage-DRLTkdIZ.js +1 -0
  13. package/static/assets/AgentsPage-CVoYisFq.js +3 -0
  14. package/static/assets/AgentsSettingsPage-D9FDJHpC.js +6 -0
  15. package/static/assets/ApiKeysSettingsPage-DGcz0E10.js +7 -0
  16. package/static/assets/ArchitectureEditPage-PXH0HtcY.js +21 -0
  17. package/static/assets/ArchitecturePage-BiybPTif.js +1 -0
  18. package/static/assets/AuthSettingsPage-6TaOiZV7.js +11 -0
  19. package/static/assets/CallbackPage-BdZglBBj.js +1 -0
  20. package/static/assets/CodePage-B239DtM2.js +2 -0
  21. package/static/assets/CollapsibleSection-DaqBpCe-.js +1 -0
  22. package/static/assets/DashboardPage-B2FJcHVR.js +11 -0
  23. package/static/assets/GitPage-DaWE2Q-b.js +16 -0
  24. package/static/assets/GitSettingsPage-bTqUr0fn.js +6 -0
  25. package/static/assets/IdentityPage-eXzMXYy2.js +11 -0
  26. package/static/assets/ImplementationStepsEditor-CuDeossU.js +6 -0
  27. package/static/assets/IntegrationsSettingsPage-wAf_7nar.js +1 -0
  28. package/static/assets/KnowledgeDetailPage-B5ieYIze.js +1 -0
  29. package/static/assets/KnowledgeEditPage-OMUREl1n.js +1 -0
  30. package/static/assets/KnowledgePage-CKtcok1N.js +8 -0
  31. package/static/assets/LoginPage-B70_aCBv.js +1 -0
  32. package/static/assets/McpSettingsPage-DcJIlHEi.js +1 -0
  33. package/static/assets/NewAgentPage-DITLLDez.js +1 -0
  34. package/static/assets/NewKnowledgePage-C7vEg4PR.js +9 -0
  35. package/static/assets/NewProposalPage-z8wqyXIj.js +90 -0
  36. package/static/assets/ProjectEditPage-BDj8GlD_.js +11 -0
  37. package/static/assets/ProjectPage-CtoKV0l9.js +1 -0
  38. package/static/assets/PromptsSettingsPage-CI-pWQVw.js +1 -0
  39. package/static/assets/ProposalDetailPage-D6rhO9vm.js +1 -0
  40. package/static/assets/ProposalEditPage-DCy3_sbg.js +1 -0
  41. package/static/assets/ProposalsPage-DQLqm83b.js +17 -0
  42. package/static/assets/ResourcesPage-Bq9t872V.js +66 -0
  43. package/static/assets/RulesSettingsPage-MgsP5qaA.js +16 -0
  44. package/static/assets/SchedulePage-C1vDSjyh.js +4 -0
  45. package/static/assets/TagInput-Cdfvhozb.js +1 -0
  46. package/static/assets/TerminalPage-NQzi2rzj.js +1 -0
  47. package/static/assets/TerminalSessionPage-DQgbm-LP.js +13 -0
  48. package/static/assets/UserPreferencesPage-CCYsj_XY.js +1 -0
  49. package/static/assets/UserSettingsPage-DdCnaoY_.js +1 -0
  50. package/static/assets/UtilitiesPage-DGcmJSz6.js +1 -0
  51. package/static/assets/alert-BAeRxZ1d.js +1 -0
  52. package/static/assets/arrow-down-5CQhXptz.js +6 -0
  53. package/static/assets/arrow-left-DSqUNUH-.js +6 -0
  54. package/static/assets/arrow-up-CYoJSbWn.js +6 -0
  55. package/static/assets/badge-NJasrAx_.js +1 -0
  56. package/static/assets/browser-modal-x3ise3M1.js +6 -0
  57. package/static/assets/calendar-wiZSxCBM.js +6 -0
  58. package/static/assets/card-CvaBJsG6.js +1 -0
  59. package/static/assets/chevron-left-CaZHWPr-.js +6 -0
  60. package/static/assets/circle-alert-61156jM6.js +6 -0
  61. package/static/assets/circle-check-big-K_QMED_K.js +6 -0
  62. package/static/assets/circle-check-z0By2KN8.js +6 -0
  63. package/static/assets/circle-play-88lMuMRZ.js +6 -0
  64. package/static/assets/circle-x-DdTsJYO7.js +6 -0
  65. package/static/assets/clipboard-B9ndUJKl.js +1 -0
  66. package/static/assets/clipboard-BNXOfcye.js +11 -0
  67. package/static/assets/clock-BTCBJF7v.js +6 -0
  68. package/static/assets/download-BaYIFjpj.js +6 -0
  69. package/static/assets/droid-CmYuCN_q.js +4 -0
  70. package/static/assets/eye-CuSCp49Y.js +6 -0
  71. package/static/assets/folder-git-2-CiVM8o0Y.js +6 -0
  72. package/static/assets/index-B8vejVRZ.js +458 -0
  73. package/static/assets/{index-Bo1l13x2.css → index-CKwmN6yL.css} +2 -33
  74. package/static/assets/label-DtNTh--4.js +1 -0
  75. package/static/assets/markdown-editor-DUEthZ0y.css +1 -0
  76. package/static/assets/markdown-editor-DvlGlqU9.js +62 -0
  77. package/static/assets/pause-COIsHZIp.js +6 -0
  78. package/static/assets/play-a8BsF4gF.js +6 -0
  79. package/static/assets/plus-Bon5P_OK.js +6 -0
  80. package/static/assets/radio-group-DpJuX02X.js +1 -0
  81. package/static/assets/refresh-cw-CnHMzcH3.js +6 -0
  82. package/static/assets/search-BR37JgJ3.js +6 -0
  83. package/static/assets/switch-D86f4WeD.js +1 -0
  84. package/static/assets/tabs-BYrDWPwx.js +1 -0
  85. package/static/assets/tag--U3Nuedb.js +6 -0
  86. package/static/assets/terminal-preview-Be68j_3t.js +11 -0
  87. package/static/assets/use-terminal-2DGl8X5T.js +1 -0
  88. package/static/assets/xterm-DTxiCjtJ.js +9 -0
  89. package/static/assets/xterm-qxJ8_QYu.css +32 -0
  90. package/static/assets/zap-C0eIGEl_.js +6 -0
  91. package/static/index.html +2 -2
  92. package/static/assets/index-DgZp291y.js +0 -973
@@ -0,0 +1,66 @@
1
+ import{c as F,r as n,j as e,D as le,a as ne,b as re,d as ie,S as Fe,B as m,ah as Me,H as He,A as E,n as ee,aj as we,a0 as be,v as T,w as I,x as D,y as L,z as U,ac as Pe,ai as qe,X as Je,C as Ye,g as te,ak as Ne,al as Xe,am as Ze,an as es,e as Te,T as Ie,I as De,ao as ss}from"./index-B8vejVRZ.js";import{C as je,b as Le,a as ve,c as as,d as ts}from"./card-CvaBJsG6.js";import{L as u}from"./label-DtNTh--4.js";import{B as ye}from"./badge-NJasrAx_.js";import{c as ls}from"./clipboard-B9ndUJKl.js";import{D as ke}from"./download-BaYIFjpj.js";import{C as ns}from"./chevron-left-CaZHWPr-.js";import{C as rs}from"./calendar-wiZSxCBM.js";import{P as Ue}from"./plus-Bon5P_OK.js";import{S as is}from"./search-BR37JgJ3.js";/**
2
+ * @license lucide-react v0.542.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const os=[["path",{d:"M17.5 22h.5a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"rslqgf"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M2 19a2 2 0 1 1 4 0v1a2 2 0 1 1-4 0v-4a6 6 0 0 1 12 0v4a2 2 0 1 1-4 0v-1a2 2 0 1 1 4 0",key:"9f7x3i"}]],Ee=F("file-audio",os);/**
7
+ * @license lucide-react v0.542.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const cs=[["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z",key:"1mlx9k"}]],Ce=F("file-code",cs);/**
12
+ * @license lucide-react v0.542.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const ds=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]],Re=F("file-image",ds);/**
17
+ * @license lucide-react v0.542.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const ms=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"1oajmo"}],["path",{d:"M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"mpwhp6"}]],_e=F("file-json",ms);/**
22
+ * @license lucide-react v0.542.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
25
+ * See the LICENSE file in the root directory of this source tree.
26
+ */const hs=[["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z",key:"1mlx9k"}],["path",{d:"M15.033 13.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z",key:"1tzo1f"}]],$e=F("file-play",hs);/**
27
+ * @license lucide-react v0.542.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ */const us=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M8 13h2",key:"yr2amv"}],["path",{d:"M14 13h2",key:"un5t4a"}],["path",{d:"M8 17h2",key:"2yhykz"}],["path",{d:"M14 17h2",key:"10kma7"}]],ze=F("file-spreadsheet",us);/**
32
+ * @license lucide-react v0.542.0 - ISC
33
+ *
34
+ * This source code is licensed under the ISC license.
35
+ * See the LICENSE file in the root directory of this source tree.
36
+ */const xs=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 13v-1h6v1",key:"1bb014"}],["path",{d:"M12 12v6",key:"3ahymv"}],["path",{d:"M11 18h2",key:"12mj7e"}]],Oe=F("file-type",xs);/**
37
+ * @license lucide-react v0.542.0 - ISC
38
+ *
39
+ * This source code is licensed under the ISC license.
40
+ * See the LICENSE file in the root directory of this source tree.
41
+ */const ps=[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]],fs=F("hard-drive",ps);/**
42
+ * @license lucide-react v0.542.0 - ISC
43
+ *
44
+ * This source code is licensed under the ISC license.
45
+ * See the LICENSE file in the root directory of this source tree.
46
+ */const gs=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],oe=F("image",gs);/**
47
+ * @license lucide-react v0.542.0 - ISC
48
+ *
49
+ * This source code is licensed under the ISC license.
50
+ * See the LICENSE file in the root directory of this source tree.
51
+ */const js=[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]],Ve=F("music",js);/**
52
+ * @license lucide-react v0.542.0 - ISC
53
+ *
54
+ * This source code is licensed under the ISC license.
55
+ * See the LICENSE file in the root directory of this source tree.
56
+ */const vs=[["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"}]],Ae=F("presentation",vs);/**
57
+ * @license lucide-react v0.542.0 - ISC
58
+ *
59
+ * This source code is licensed under the ISC license.
60
+ * See the LICENSE file in the root directory of this source tree.
61
+ */const ws=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],bs=F("upload",ws);/**
62
+ * @license lucide-react v0.542.0 - ISC
63
+ *
64
+ * This source code is licensed under the ISC license.
65
+ * See the LICENSE file in the root directory of this source tree.
66
+ */const Ns=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],ys=F("video",Ns),xe=[{id:"example-1",prompt:"A serene Japanese garden at dawn, with cherry blossoms falling gently onto a still koi pond. Morning mist rises from the water, and a traditional red wooden bridge arches gracefully in the background. Shot on medium format film with soft, diffused lighting.",imageUrl:"https://replicate.delivery/pbxt/O7kbtH7wgLIItlCyeWjm0fgPpx7OpGsT9VbYyxBXnfieVxQe/woman-by-car.jpg"},{id:"example-2",prompt:"Glossy candy-colored 3D letters in hot pink, electric orange, and lime green on a sun-drenched poolside patio with bold terrazzo tiles and vintage lounge chairs in turquoise and yellow. Shot on Kodachrome film with a Hasselblad 500C, warm golden afternoon sunlight, dramatic lens flare, punchy oversaturated colors.",imageUrl:"https://replicate.delivery/pbxt/LUSNRiITNZzwaVXiSAWYzDeMJDVgF64hxmfJY5LEXVgdFXKA/out-0.webp"},{id:"example-3",prompt:"A cozy coffee shop interior with exposed brick walls, warm Edison bulb lighting, and steam rising from freshly brewed espresso. Vintage wooden furniture, potted plants on windowsills, and rain gently pattering against large windows. Moody, intimate atmosphere.",imageUrl:"https://replicate.delivery/pbxt/IJbGk2DEcUPrq1x8z6Cg7MJsKRdYhAcEHCKlkMzxPLQfVaNA/out-0.webp"},{id:"example-4",prompt:"Futuristic neon-lit cityscape at night, towering skyscrapers with holographic advertisements, flying vehicles streaking through the sky leaving light trails. Cyberpunk aesthetic with rain-slicked streets reflecting vibrant pink and blue neon lights. Blade Runner inspired.",imageUrl:"https://replicate.delivery/pbxt/K1juSILfCPTmGRnl1gBOzZQS4gVj4YCuSHVJ8KjVPMDfXaNA/out-0.webp"},{id:"example-5",prompt:"A whimsical treehouse village suspended in an ancient forest, connected by rope bridges and spiral staircases. Warm lantern light glows from circular windows, fireflies dance in the twilight air, and moss covers the weathered wooden structures. Fantasy illustration style.",imageUrl:"https://replicate.delivery/pbxt/M2ndEILfCPTmGRnl1gBOzZQS4gVj4YCuSHVJ8KjVPMDfXaNA/out-0.webp"},{id:"example-6",prompt:"Minimalist product photography of a luxury perfume bottle on a marble surface. Soft directional lighting creates elegant shadows, with fresh white flowers blurred in the background. Clean, sophisticated aesthetic with subtle reflections.",imageUrl:"https://replicate.delivery/pbxt/N3oeJKMgDQUnHSnm2hCPaAST5hWk5ZDvTIWK9LkWQNEgYbOB/out-0.webp"},{id:"example-7",prompt:"An astronaut floating in the vastness of space, Earth visible in the background with swirling clouds and deep blue oceans. Stars scatter infinitely into the darkness. The astronaut's visor reflects distant galaxies. Photorealistic, awe-inspiring scale.",imageUrl:"https://replicate.delivery/pbxt/O4pfLMNhERVoITon3iDQbBTU6iXl6AEwUJXL0MlXROFhZcPC/out-0.webp"},{id:"example-8",prompt:"Delicious artisan pizza fresh from a wood-fired oven, with bubbling mozzarella, fresh basil leaves, and drizzled olive oil. Rustic wooden table background, natural lighting, steam rising from the crispy crust. Food photography, appetizing and warm.",imageUrl:"https://replicate.delivery/pbxt/P5qgMNOiFS5pJUpn4jERcCUV7jYm7BFxVKYM1NmYSPGiAdQD/out-0.webp"}];function ks({open:x,onOpenChange:C,onSelectExample:l}){const[d,b]=n.useState(xe.length>0?xe[0]:null),h=()=>{d&&(l(d.prompt),C(!1))},y=c=>{l(c.prompt),C(!1)};return e.jsx(le,{open:x,onOpenChange:C,children:e.jsxs(ne,{className:"max-w-[95vw] sm:max-w-[90vw] w-full sm:w-[90vw] max-h-[95vh] sm:max-h-[90vh] h-[95vh] sm:h-[90vh] p-0 gap-0 flex flex-col",children:[e.jsx(re,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(ie,{className:"text-base sm:text-lg",children:"Example Prompts"})}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden md:hidden",children:[e.jsx("div",{className:"h-[40%] min-h-0 p-3 flex items-center justify-center bg-muted/30 overflow-hidden",children:d?e.jsx("img",{src:d.imageUrl,alt:"Example",className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select an example"})}),e.jsxs("div",{className:"flex-1 min-h-0 border-t flex flex-col",children:[e.jsx(Fe,{className:"flex-1",children:e.jsx("div",{className:"p-3 space-y-2",children:xe.map(c=>e.jsxs("button",{onClick:()=>b(c),onDoubleClick:()=>y(c),className:`w-full text-left p-2 rounded-lg border-2 transition-all flex gap-3 ${d?.id===c.id?"border-primary bg-primary/5":"border-transparent bg-muted/50 hover:bg-muted"}`,children:[e.jsx("img",{src:c.imageUrl,alt:"",className:"w-12 h-12 rounded object-cover flex-shrink-0"}),e.jsx("p",{className:"text-sm line-clamp-3 flex-1",children:c.prompt})]},c.id))})}),e.jsx("div",{className:"p-3 border-t flex-shrink-0",children:e.jsxs(m,{onClick:h,disabled:!d,className:"w-full",children:[e.jsx(Me,{className:"mr-2 h-4 w-4"}),"Use This Prompt"]})})]})]}),e.jsxs("div",{className:"flex-1 hidden md:flex overflow-hidden",children:[e.jsxs("div",{className:"w-[35%] border-r flex flex-col",children:[e.jsx(Fe,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-3",children:xe.map(c=>e.jsxs("button",{onClick:()=>b(c),onDoubleClick:()=>y(c),className:`w-full text-left p-3 rounded-lg border-2 transition-all flex gap-3 ${d?.id===c.id?"border-primary bg-primary/5 shadow-sm":"border-transparent bg-muted/50 hover:bg-muted hover:border-muted-foreground/20"}`,children:[e.jsx("img",{src:c.imageUrl,alt:"",className:"w-16 h-16 rounded object-cover flex-shrink-0"}),e.jsx("p",{className:"text-sm leading-relaxed line-clamp-4 flex-1",children:c.prompt})]},c.id))})}),e.jsx("div",{className:"p-4 border-t flex-shrink-0",children:e.jsxs(m,{onClick:h,disabled:!d,className:"w-full",children:[e.jsx(Me,{className:"mr-2 h-4 w-4"}),"Use This Prompt"]})})]}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"flex-1 min-h-0 p-6 flex items-center justify-center bg-muted/30 overflow-hidden",children:d?e.jsx("img",{src:d.imageUrl,alt:"Example",className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select an example to preview"})}),d&&e.jsxs("div",{className:"border-t p-4 bg-background flex-shrink-0 max-h-[30%] overflow-y-auto",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2 font-medium",children:"Full Prompt:"}),e.jsx("p",{className:"text-sm leading-relaxed",children:d.prompt})]})]})]})]})})}const Se={"nano-banana-pro":{id:"nano-banana-pro",label:"Nano Banana Pro",replicateId:"google/nano-banana-pro",features:{resolution:!0,outputQuality:!1,goFast:!1,safetyTolerance:!1,matchInputImage:!1},resolutionOptions:[{value:"1K",label:"1K"},{value:"2K",label:"2K"},{value:"4K",label:"4K"}],defaults:{resolution:"2K"}},"flux-2-dev":{id:"flux-2-dev",label:"FLUX.2 Dev",replicateId:"black-forest-labs/flux-2-dev",features:{resolution:!1,outputQuality:!0,goFast:!0,safetyTolerance:!1,matchInputImage:!0},defaults:{outputQuality:80,goFast:!0}},"flux-2-pro":{id:"flux-2-pro",label:"FLUX.2 Pro",replicateId:"black-forest-labs/flux-2-pro",features:{resolution:!0,outputQuality:!0,goFast:!1,safetyTolerance:!0,matchInputImage:!1},resolutionOptions:[{value:"0.5 MP",label:"0.5 MP"},{value:"1 MP",label:"1 MP"},{value:"2 MP",label:"2 MP"},{value:"4 MP",label:"4 MP"}],defaults:{resolution:"2 MP",outputQuality:80,safetyTolerance:2}}},Ge=Object.values(Se).map(x=>({value:x.id,label:x.label})),We=[{value:"1:1",label:"1:1"},{value:"2:3",label:"2:3"},{value:"3:2",label:"3:2"},{value:"3:4",label:"3:4"},{value:"4:3",label:"4:3"},{value:"4:5",label:"4:5"},{value:"5:4",label:"5:4"},{value:"9:16",label:"9:16"},{value:"16:9",label:"16:9"},{value:"21:9",label:"21:9"}],Cs={value:"match_input_image",label:"Match Input"},Qe=[{value:"png",label:"PNG"},{value:"jpg",label:"JPG"},{value:"webp",label:"WebP"}],Be=[{value:"60",label:"60"},{value:"70",label:"70"},{value:"80",label:"80"},{value:"90",label:"90"},{value:"100",label:"100"}],Ke=[{value:"1",label:"1 (Strict)"},{value:"2",label:"2"},{value:"3",label:"3"},{value:"4",label:"4"},{value:"5",label:"5"},{value:"6",label:"6 (Relaxed)"}];function Ss({open:x,onOpenChange:C,onSave:l}){const[d,b]=n.useState(""),[h,y]=n.useState("nano-banana-pro"),[c,p]=n.useState("4:3"),[M,f]=n.useState("2K"),[R,k]=n.useState("png"),[z,O]=n.useState("80"),[B,g]=n.useState(!0),[V,A]=n.useState("2"),[N,G]=n.useState(null),[j,P]=n.useState(!1),[S,_]=n.useState(!1),[K,r]=n.useState([]),[i,$]=n.useState([]),[W,Z]=n.useState(!0),[ce,se]=n.useState(!1),{toast:X}=He(),w=Se[h],de=w.features.matchInputImage?[Cs,...We]:We,ae=w.resolutionOptions||[];n.useEffect(()=>{const a=Se[h];a.defaults.resolution&&a.features.resolution&&f(a.defaults.resolution),a.defaults.outputQuality!==void 0&&O(String(a.defaults.outputQuality)),a.defaults.goFast!==void 0&&g(a.defaults.goFast),a.defaults.safetyTolerance!==void 0&&A(String(a.defaults.safetyTolerance)),p(v=>v==="match_input_image"&&!a.features.matchInputImage?"4:3":v)},[h]),n.useEffect(()=>{x&&pe()},[x]);const pe=async()=>{try{const v=await(await fetch(`${E}/api/v1/resources`)).json();if(v.success){const q=(v.data||[]).filter(Q=>{const s=Q.type==="image/jpeg"||Q.name.toLowerCase().endsWith(".jpg")||Q.name.toLowerCase().endsWith(".jpeg"),t=Q.type==="image/png"||Q.name.toLowerCase().endsWith(".png");return(s||t)&&Q.thumbnailPath});r(q)}}catch(a){console.error("Failed to fetch image resources:",a)}},me=async()=>{if(!d.trim()){X({title:"Prompt required",description:"Please enter a prompt to generate an image",variant:"destructive"});return}P(!0),G(null);try{const a=W||i.length===0?[]:[...i],v=await fetch(`${E}/api/v1/resources/generate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:d,model:h,dimensions:c,resolution:w.features.resolution?M:void 0,output_format:R,output_quality:w.features.outputQuality?parseInt(z):void 0,go_fast:w.features.goFast?B:void 0,safety_tolerance:w.features.safetyTolerance?parseInt(V):void 0,image_input:a})}),q=await v.json();if(!v.ok||!q.success){const Q=q.error?.message||"Failed to generate image",s=q.error?.code==="MISSING_API_TOKEN";throw new Error(s?"Replicate API token not configured. Please add it in Settings → Integrations.":Q)}G(q.data.imageUrl),X({title:"Image generated",description:"Your image has been generated successfully"})}catch(a){console.error("Generation error:",a),X({title:"Generation failed",description:a instanceof Error?a.message:"Failed to generate image. Please try again.",variant:"destructive"})}finally{P(!1)}},he=async()=>{if(N){_(!0);try{await l(N),b(""),y("nano-banana-pro"),p("4:3"),f("2K"),k("png"),O("80"),g(!0),A("2"),G(null),Z(!0),$([]),C(!1)}catch(a){X({title:"Save failed",description:a instanceof Error?a.message:"Failed to save image. Please try again.",variant:"destructive"})}finally{_(!1)}}},fe=()=>{!j&&!S&&C(!1)},H=()=>{Z(!0),$([])},ue=a=>{W&&Z(!1),i.includes(a)?($(i.filter(v=>v!==a)),i.length===1&&Z(!0)):i.length<3?$([...i,a]):X({title:"Maximum selection",description:"You can only select up to 3 images",variant:"destructive"})},ge=a=>{b(a)};return e.jsxs(le,{open:x,onOpenChange:fe,children:[e.jsxs(ne,{className:"max-w-[95vw] sm:max-w-[90vw] w-full sm:w-[90vw] max-h-[95vh] sm:max-h-[90vh] h-[95vh] sm:h-[90vh] p-0 gap-0 flex flex-col",children:[e.jsx(re,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(ie,{className:"text-base sm:text-lg",children:"Generate Image"})}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden md:hidden",children:[e.jsx("div",{className:"flex-1 min-h-0 p-3 flex items-center justify-center bg-muted/30 overflow-hidden",children:j?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3",children:[e.jsx(ee,{className:"h-10 w-10 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating..."})]}):N?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:N,alt:"Generated",className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"})}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3 text-muted-foreground",children:[e.jsx(oe,{className:"h-12 w-12"}),e.jsx("p",{className:"text-xs",children:"Preview"}),e.jsxs(m,{size:"sm",onClick:()=>se(!0),className:"mt-2",children:[e.jsx(we,{className:"mr-2 h-4 w-4"}),"View Examples"]})]})}),e.jsx("div",{className:"border-t bg-background p-2 flex-shrink-0",children:e.jsxs("div",{className:"flex gap-1.5 overflow-x-auto pb-1",children:[e.jsx("button",{onClick:H,className:`flex-shrink-0 h-16 w-16 flex items-center justify-center border-2 rounded-md transition-colors text-xs ${W?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:"None"}),K.map(a=>{const v=i.includes(a.id);return e.jsx("button",{onClick:()=>ue(a.id),className:`flex-shrink-0 h-16 w-16 border-2 rounded-md overflow-hidden transition-colors ${v?"border-primary ring-2 ring-primary":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("img",{src:`${E}/api/v1/resources/${a.id}/thumbnail`,alt:a.name,className:"w-full h-full object-cover"})},a.id)})]})}),e.jsx("div",{className:"border-t p-3 overflow-y-auto flex-shrink-0 max-h-[45vh]",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(u,{htmlFor:"prompt-mobile",className:"text-xs",children:"Prompt"}),e.jsx(be,{id:"prompt-mobile",placeholder:"Describe the image...",value:d,onChange:a=>b(a.target.value),rows:2,className:"resize-none text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(u,{htmlFor:"model-mobile",className:"text-xs",children:"Model"}),e.jsxs(T,{value:h,onValueChange:a=>y(a),children:[e.jsx(I,{id:"model-mobile",className:"h-8 text-xs",children:e.jsx(D,{})}),e.jsx(L,{children:Ge.map(a=>e.jsx(U,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(u,{htmlFor:"outputFormat-mobile",className:"text-xs",children:"Format"}),e.jsxs(T,{value:R,onValueChange:k,children:[e.jsx(I,{id:"outputFormat-mobile",className:"h-8 text-xs",children:e.jsx(D,{})}),e.jsx(L,{children:Qe.map(a=>e.jsx(U,{value:a.value,children:a.label},a.value))})]})]}),w.features.goFast&&e.jsx("div",{className:"space-y-1 flex flex-col justify-end",children:e.jsxs("div",{className:"flex items-center space-x-2 h-8",children:[e.jsx(Pe,{id:"goFast-mobile",checked:B,onCheckedChange:a=>g(a===!0)}),e.jsx(u,{htmlFor:"goFast-mobile",className:"text-xs cursor-pointer",children:"Go Fast"})]})}),w.features.safetyTolerance&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(u,{htmlFor:"safetyTolerance-mobile",className:"text-xs",children:"Safety"}),e.jsxs(T,{value:V,onValueChange:A,children:[e.jsx(I,{id:"safetyTolerance-mobile",className:"h-8 text-xs",children:e.jsx(D,{})}),e.jsx(L,{children:Ke.map(a=>e.jsx(U,{value:a.value,children:a.label},a.value))})]})]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[w.features.resolution&&e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(u,{htmlFor:"resolution-mobile",className:"text-xs",children:"Resolution"}),e.jsxs(T,{value:M,onValueChange:f,children:[e.jsx(I,{id:"resolution-mobile",className:"h-8 text-xs",children:e.jsx(D,{})}),e.jsx(L,{children:ae.map(a=>e.jsx(U,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(u,{htmlFor:"aspectRatio-mobile",className:"text-xs",children:"Ratio"}),e.jsxs(T,{value:c,onValueChange:p,children:[e.jsx(I,{id:"aspectRatio-mobile",className:"h-8 text-xs",children:e.jsx(D,{})}),e.jsx(L,{children:de.map(a=>e.jsx(U,{value:a.value,children:a.label},a.value))})]})]}),w.features.outputQuality&&e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(u,{htmlFor:"outputQuality-mobile",className:"text-xs",children:"Quality"}),e.jsxs(T,{value:z,onValueChange:O,children:[e.jsx(I,{id:"outputQuality-mobile",className:"h-8 text-xs",children:e.jsx(D,{})}),e.jsx(L,{children:Be.map(a=>e.jsx(U,{value:a.value,children:a.label},a.value))})]})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(m,{onClick:me,disabled:!d.trim()||j||S,className:"flex-1 h-9",size:"sm",children:j?e.jsx(ee,{className:"h-4 w-4 animate-spin"}):"Generate"}),e.jsx(m,{onClick:he,disabled:!N||j||S,variant:"outline",className:"flex-1 h-9",size:"sm",children:S?e.jsx(ee,{className:"h-4 w-4 animate-spin"}):"Save"})]})]})})]}),e.jsxs("div",{className:"flex-1 hidden md:flex overflow-hidden",children:[e.jsx("div",{className:"w-[22%] border-r p-6 overflow-y-auto",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"prompt",children:"Prompt"}),e.jsx(be,{id:"prompt",placeholder:"Describe the image you want to generate...",value:d,onChange:a=>b(a.target.value),rows:4,className:"resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"model",children:"Model"}),e.jsxs(T,{value:h,onValueChange:a=>y(a),children:[e.jsx(I,{id:"model",children:e.jsx(D,{})}),e.jsx(L,{children:Ge.map(a=>e.jsx(U,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"aspectRatio",children:"Aspect Ratio"}),e.jsxs(T,{value:c,onValueChange:p,children:[e.jsx(I,{id:"aspectRatio",children:e.jsx(D,{})}),e.jsx(L,{children:de.map(a=>e.jsx(U,{value:a.value,children:a.label},a.value))})]})]}),w.features.resolution&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"resolution",children:"Resolution"}),e.jsxs(T,{value:M,onValueChange:f,children:[e.jsx(I,{id:"resolution",children:e.jsx(D,{})}),e.jsx(L,{children:ae.map(a=>e.jsx(U,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"outputFormat",children:"Output Format"}),e.jsxs(T,{value:R,onValueChange:k,children:[e.jsx(I,{id:"outputFormat",children:e.jsx(D,{})}),e.jsx(L,{children:Qe.map(a=>e.jsx(U,{value:a.value,children:a.label},a.value))})]})]}),w.features.outputQuality&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"outputQuality",children:"Output Quality"}),e.jsxs(T,{value:z,onValueChange:O,children:[e.jsx(I,{id:"outputQuality",children:e.jsx(D,{})}),e.jsx(L,{children:Be.map(a=>e.jsx(U,{value:a.value,children:a.label},a.value))})]})]}),w.features.goFast&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"goFast",checked:B,onCheckedChange:a=>g(a===!0)}),e.jsx(u,{htmlFor:"goFast",className:"cursor-pointer",children:"Go Fast"})]}),w.features.safetyTolerance&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"safetyTolerance",children:"Safety Tolerance"}),e.jsxs(T,{value:V,onValueChange:A,children:[e.jsx(I,{id:"safetyTolerance",children:e.jsx(D,{})}),e.jsx(L,{children:Ke.map(a=>e.jsx(U,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-4",children:[e.jsx(m,{onClick:me,disabled:!d.trim()||j||S,className:"w-full",children:j?e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"mr-2 h-4 w-4 animate-spin"}),"Generating..."]}):"Generate"}),e.jsx(m,{onClick:he,disabled:!N||j||S,variant:"outline",className:"w-full",children:S?e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"flex-1 min-h-0 p-6 flex items-center justify-center bg-muted/30 overflow-hidden",children:j?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx(ee,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating image..."})]}):N?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:N,alt:"Generated",className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"})}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[e.jsx(oe,{className:"h-16 w-16"}),e.jsx("p",{className:"text-sm",children:"Generated image will appear here"}),e.jsxs(m,{onClick:()=>se(!0),className:"mt-2",children:[e.jsx(we,{className:"mr-2 h-4 w-4"}),"View Examples"]})]})}),e.jsx("div",{className:"border-t bg-background p-4 flex-shrink-0",children:e.jsxs("div",{className:"flex gap-2 overflow-x-auto",children:[e.jsx("button",{onClick:H,className:`flex-shrink-0 h-32 w-32 flex items-center justify-center border-2 rounded-md transition-colors ${W?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("span",{className:"text-sm font-medium",children:"None"})}),K.map(a=>{const v=i.includes(a.id);return e.jsx("button",{onClick:()=>ue(a.id),className:`flex-shrink-0 h-32 w-32 border-2 rounded-md overflow-hidden transition-colors ${v?"border-primary ring-2 ring-primary":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("img",{src:`${E}/api/v1/resources/${a.id}/thumbnail`,alt:a.name,className:"w-full h-full object-cover"})},a.id)})]})})]})]})]}),e.jsx(ks,{open:ce,onOpenChange:se,onSelectExample:ge})]})}function Fs({open:x,onOpenChange:C,resource:l,onCopyPath:d,onDownload:b,onNavigate:h,canNavigatePrev:y,canNavigateNext:c}){const[p,M]=n.useState(null),[f,R]=n.useState(!1),k=l?`${E}/api/v1/resources/${l.id}`:"",z=l?.type.startsWith("image/")??!1,O=l?l.type==="image/svg+xml"||l.name.toLowerCase().endsWith(".svg"):!1,B=l?l.type==="application/pdf"||l.name.toLowerCase().endsWith(".pdf"):!1,g=l?.type.startsWith("video/")??!1,V=l?.type.startsWith("audio/")??!1,A=l?l.type.startsWith("text/")||l.type==="application/json"||l.type.includes("javascript")||l.type.includes("typescript")||l.type.includes("xml")||l.name.toLowerCase().match(/\.(txt|md|json|js|ts|jsx|tsx|css|html|xml|yaml|yml|log|sh|bash|zsh|fish)$/)!==null:!1,N=l?l.name.toLowerCase().endsWith(".md")||l.name.toLowerCase().endsWith(".markdown"):!1,G=l?l.type==="application/json"||l.name.toLowerCase().endsWith(".json"):!1,j=l?l.type==="text/html"||l.name.toLowerCase().endsWith(".html"):!1;if(n.useEffect(()=>{const r=i=>{if(x){if(i.key==="Escape"){C(!1);return}if(i.key==="ArrowLeft"&&y){i.preventDefault(),h("prev");return}i.key==="ArrowRight"&&c&&(i.preventDefault(),h("next"))}};if(x)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[x,C,h,y,c]),n.useEffect(()=>{x&&l&&(A||N||G||j)?(R(!0),fetch(k).then(r=>{if(r.ok)return r.text();throw new Error("Failed to load file")}).then(r=>{M(r)}).catch(r=>{console.error("Failed to load text content:",r),M(null)}).finally(()=>{R(!1)})):M(null)},[x,l?.id,A,N,G,j,k]),!l)return null;const P=r=>{if(r===0)return"0 B";const i=1024,$=["B","KB","MB","GB"],W=Math.floor(Math.log(r)/Math.log(i));return parseFloat((r/Math.pow(i,W)).toFixed(2))+" "+$[W]},S=r=>new Date(r).toLocaleString(),_=r=>r.startsWith("image/")?e.jsx(oe,{className:"h-6 w-6"}):r.startsWith("video/")?e.jsx(ys,{className:"h-6 w-6"}):r.startsWith("audio/")?e.jsx(Ve,{className:"h-6 w-6"}):r.includes("text")||r.includes("document")||r.includes("code")?e.jsx(te,{className:"h-6 w-6"}):r.includes("json")||r.includes("javascript")||r.includes("typescript")?e.jsx(Ce,{className:"h-6 w-6"}):e.jsx(Ne,{className:"h-6 w-6"}),K=()=>{if(O)return e.jsx("img",{src:k,alt:l.name,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"});if(B)return e.jsx("iframe",{src:k,className:"w-full h-full min-h-[600px] rounded-lg border",title:l.name});if(g)return e.jsx("video",{src:k,controls:!0,className:"max-w-full max-h-full rounded-lg shadow-lg",children:"Your browser does not support the video tag."});if(V)return e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 p-8",children:[e.jsx(Ve,{className:"h-16 w-16 text-muted-foreground"}),e.jsx("audio",{src:k,controls:!0,className:"w-full max-w-md",children:"Your browser does not support the audio tag."})]});if(N&&p!==null)return f?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading..."})}):e.jsx("div",{className:"w-full h-full overflow-auto p-6 prose prose-sm dark:prose-invert max-w-none",children:e.jsx(Xe,{remarkPlugins:[es],rehypePlugins:[Ze],children:p})});if(j&&p!==null)return f?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading..."})}):e.jsx("iframe",{srcDoc:p,className:"w-full h-full min-h-[600px] rounded-lg border",title:l.name,sandbox:"allow-same-origin"});if(G&&p!==null){if(f)return e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading..."})});let r=p;try{const i=JSON.parse(p);r=JSON.stringify(i,null,2)}catch{}return e.jsx("div",{className:"w-full h-full overflow-auto p-6",children:e.jsx("pre",{className:"text-xs bg-muted p-4 rounded-lg overflow-auto",children:e.jsx("code",{children:r})})})}return A&&p!==null?f?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading..."})}):e.jsx("div",{className:"w-full h-full overflow-auto p-6",children:e.jsx("pre",{className:"text-xs bg-muted p-4 rounded-lg overflow-auto whitespace-pre-wrap",children:e.jsx("code",{children:p})})}):z?e.jsx("img",{src:k,alt:l.name,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[_(l.type),e.jsx("p",{className:"text-sm",children:"Preview not available for this file type"}),e.jsxs(m,{variant:"outline",onClick:()=>b(l),children:[e.jsx(ke,{className:"mr-2 h-4 w-4"}),"Download to view"]})]})};return e.jsx(le,{open:x,onOpenChange:C,children:e.jsxs(ne,{className:"max-w-[90vw] w-[90vw] max-h-[90vh] h-[90vh] p-0 gap-0 flex flex-col [&>button]:hidden",children:[e.jsx(re,{className:"px-6 pt-6 pb-4 border-b flex-shrink-0",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[_(l.type),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx(ie,{className:"text-xl truncate",children:l.name}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:l.type})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>d(l),title:"Copy path to clipboard",children:e.jsx(qe,{className:"h-4 w-4"})}),e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>b(l),title:"Download",children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>C(!1),title:"Close",children:e.jsx(Je,{className:"h-4 w-4"})})]})]})}),e.jsx("div",{className:"flex-1 flex overflow-hidden",children:e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-1 relative flex items-center justify-center bg-muted/30 p-6 overflow-auto",children:[y&&e.jsx("button",{type:"button",onClick:()=>h("prev"),className:"absolute left-4 top-1/2 -translate-y-1/2 rounded-full border bg-background/80 p-2 shadow-sm hover:bg-background transition-colors","aria-label":"Previous resource",children:e.jsx(ns,{className:"h-5 w-5"})}),c&&e.jsx("button",{type:"button",onClick:()=>h("next"),className:"absolute right-4 top-1/2 -translate-y-1/2 rounded-full border bg-background/80 p-2 shadow-sm hover:bg-background transition-colors","aria-label":"Next resource",children:e.jsx(Ye,{className:"h-5 w-5"})}),K()]}),e.jsx("div",{className:"border-t p-6 flex-shrink-0 bg-background",children:e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold mb-3",children:"Information"}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fs,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Size:"}),e.jsx("span",{children:P(l.size)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rs,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Uploaded:"}),e.jsx("span",{children:S(l.uploadedAt)})]})]})]})}),e.jsxs("div",{className:"space-y-4",children:[l.metadata.description&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold mb-2",children:"Description"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l.metadata.description})]}),l.metadata.tags&&l.metadata.tags.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold mb-2",children:"Tags"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:l.metadata.tags.map(r=>e.jsx(ye,{variant:"secondary",children:r},r))})]})]})]})})]})})]})})}function zs(){const[x,C]=n.useState([]),[l,d]=n.useState(!0),[b,h]=n.useState(!1),[y,c]=n.useState(""),[p,M]=n.useState(!1),[f,R]=n.useState([]),[k,z]=n.useState(""),[O,B]=n.useState(""),[g,V]=n.useState([]),[A,N]=n.useState(!1),[G,j]=n.useState(null),[P,S]=n.useState(null),[_,K]=n.useState(null),r=n.useRef(null),{toast:i}=He();n.useEffect(()=>{$()},[]);const $=async()=>{try{d(!0);const t=await(await fetch(`${E}/api/v1/resources`)).json();t.success&&C(t.data||[])}catch(s){console.error("Failed to fetch resources:",s)}finally{d(!1)}},W=s=>{s.length!==0&&V(Array.from(s))},Z=async()=>{if(g.length!==0){h(!0);try{for(const s of g){const t=new FormData;if(t.append("file",s),t.append("tags",f.join(", ")),t.append("description",O),!(await fetch(`${E}/api/v1/resources`,{method:"POST",body:t})).ok)throw new Error("Upload failed")}R([]),z(""),B(""),V([]),M(!1),await $(),i({title:"Upload successful",description:`${g.length} file(s) uploaded successfully`})}catch(s){console.error("Upload failed:",s),i({title:"Upload failed",description:"Failed to upload files. Please try again.",variant:"destructive"})}finally{h(!1)}}},ce=()=>{R([]),z(""),B(""),V([]),M(!1)},se=s=>{if(s.key==="Enter"){s.preventDefault();const t=k.trim();t&&!f.includes(t)&&(R([...f,t]),z(""))}},X=s=>{R(f.filter(t=>t!==s))},w=s=>{V(g.filter((t,o)=>o!==s))},de=async()=>{if(_)try{if((await fetch(`${E}/api/v1/resources/${_.id}`,{method:"DELETE"})).ok)await $(),i({title:"Resource deleted",description:`${_.name} has been deleted`});else throw new Error("Delete failed")}catch(s){console.error("Failed to delete resource:",s),i({title:"Delete failed",description:"Failed to delete resource. Please try again.",variant:"destructive"})}finally{K(null)}},ae=async s=>{try{const t=`.nut/resources/files/${s.path}`;await ls(t),i({title:"Path copied!",description:`Copied ${t} to clipboard`})}catch(t){console.error("Failed to copy path:",t),i({title:"Failed to copy",description:"Unable to copy path to clipboard",variant:"destructive"})}},pe=s=>{if(s===0)return"0 B";const t=1024,o=["B","KB","MB","GB"],J=Math.floor(Math.log(s)/Math.log(t));return parseFloat((s/Math.pow(t,J)).toFixed(2))+" "+o[J]},me=(s,t)=>{const o=t.toLowerCase();return s.startsWith("image/")?s==="image/svg+xml"||o.endsWith(".svg")?e.jsx(Re,{className:"h-4 w-4"}):e.jsx(oe,{className:"h-4 w-4"}):s.startsWith("video/")?e.jsx($e,{className:"h-4 w-4"}):s.startsWith("audio/")?e.jsx(Ee,{className:"h-4 w-4"}):s==="application/pdf"||o.endsWith(".pdf")?e.jsx(te,{className:"h-4 w-4"}):o.match(/\.(js|jsx|ts|tsx|py|java|cpp|c|h|hpp|cs|go|rs|rb|php|swift|kt|scala|r|m|mm)$/)?e.jsx(Ce,{className:"h-4 w-4"}):s==="application/json"||o.endsWith(".json")?e.jsx(_e,{className:"h-4 w-4"}):s.includes("spreadsheet")||s.includes("excel")||o.match(/\.(xls|xlsx|csv)$/)?e.jsx(ze,{className:"h-4 w-4"}):s.includes("presentation")||s.includes("powerpoint")||o.match(/\.(ppt|pptx)$/)?e.jsx(Ae,{className:"h-4 w-4"}):s.startsWith("text/")||s.includes("document")||s.includes("word")?e.jsx(te,{className:"h-4 w-4"}):s.includes("font")||o.match(/\.(ttf|otf|woff|woff2|eot)$/)?e.jsx(Oe,{className:"h-4 w-4"}):e.jsx(Ne,{className:"h-4 w-4"})},he=(s,t)=>{const o=t.toLowerCase();return s.startsWith("image/")?s==="image/svg+xml"||o.endsWith(".svg")?e.jsx(Re,{className:"h-16 w-16"}):e.jsx(oe,{className:"h-16 w-16"}):s.startsWith("video/")?e.jsx($e,{className:"h-16 w-16"}):s.startsWith("audio/")?e.jsx(Ee,{className:"h-16 w-16"}):s==="application/pdf"||o.endsWith(".pdf")?e.jsx(te,{className:"h-16 w-16"}):o.match(/\.(js|jsx|ts|tsx|py|java|cpp|c|h|hpp|cs|go|rs|rb|php|swift|kt|scala|r|m|mm)$/)?e.jsx(Ce,{className:"h-16 w-16"}):s==="application/json"||o.endsWith(".json")?e.jsx(_e,{className:"h-16 w-16"}):s.includes("spreadsheet")||s.includes("excel")||o.match(/\.(xls|xlsx|csv)$/)?e.jsx(ze,{className:"h-16 w-16"}):s.includes("presentation")||s.includes("powerpoint")||o.match(/\.(ppt|pptx)$/)?e.jsx(Ae,{className:"h-16 w-16"}):s.startsWith("text/")||s.includes("document")||s.includes("word")?e.jsx(te,{className:"h-16 w-16"}):s.includes("font")||o.match(/\.(ttf|otf|woff|woff2|eot)$/)?e.jsx(Oe,{className:"h-16 w-16"}):e.jsx(Ne,{className:"h-16 w-16"})},fe=s=>{const t=s.name.toLowerCase(),o=s.type.startsWith("image/");return s.type==="image/svg+xml"||t.endsWith(".svg")?e.jsx("div",{className:"w-full h-32 flex items-center justify-center bg-muted/30 rounded-md border overflow-hidden p-2",children:e.jsx("img",{src:`${E}/api/v1/resources/${s.id}`,alt:s.name,className:"w-full h-full object-contain"})}):o&&s.thumbnailPath?e.jsx("img",{src:`${E}/api/v1/resources/${s.id}/thumbnail`,alt:s.name,className:"w-full h-32 object-cover rounded-md border",onError:Y=>{Y.currentTarget.style.display="none"}}):e.jsx("div",{className:"w-full h-32 flex items-center justify-center bg-muted/50 rounded-md border",children:e.jsx("div",{className:"text-muted-foreground",children:he(s.type,s.name)})})},H=x.filter(s=>{if(!y)return!0;const t=y.toLowerCase();return s.name.toLowerCase().includes(t)||s.metadata.description?.toLowerCase().includes(t)||s.metadata.tags?.some(o=>o.toLowerCase().includes(t))}),ue=s=>{s.preventDefault(),s.stopPropagation()},ge=s=>{s.preventDefault(),s.stopPropagation(),s.dataTransfer.files&&s.dataTransfer.files.length>0&&W(s.dataTransfer.files)},a=(s,t)=>{if(t.target.closest("button"))return;j(s);const J=H.findIndex(Y=>Y.id===s.id);S(J>=0?J:null)},v=s=>{window.open(`${E}/api/v1/resources/${s.id}?download=true`)},q=async s=>{h(!0);try{const t=await fetch(s);if(!t.ok)throw new Error("Failed to download generated image");const o=await t.blob(),J=`generated-image-${Date.now()}.png`,Y=new FormData;if(Y.append("file",o,J),Y.append("tags",f.join(",")),Y.append("description",O),!(await fetch(`${E}/api/v1/resources`,{method:"POST",body:Y})).ok)throw new Error("Upload failed");await $(),i({title:"Image saved",description:"Generated image has been saved to resources"})}catch(t){throw console.error("Failed to save generated image:",t),i({title:"Save failed",description:t.message||"Failed to save generated image",variant:"destructive"}),t}finally{h(!1)}},Q=s=>{if(P===null)return;const t=s==="next"?P+1:P-1;if(t<0||t>=H.length)return;const o=H[t];S(t),j(o)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-xl sm:text-2xl font-bold tracking-tight",children:"Resources"}),e.jsx("p",{className:"text-muted-foreground text-sm hidden sm:block",children:"Manage files and resources for your project"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(m,{variant:"outline",size:"sm",onClick:()=>N(!0),children:[e.jsx(we,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Generate"})]}),e.jsxs(m,{size:"sm",onClick:()=>M(!p),children:[e.jsx(Ue,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Add Resource"})]})]})]}),e.jsx(le,{open:p,onOpenChange:s=>!s&&ce(),children:e.jsxs(ne,{className:"max-w-2xl",children:[e.jsxs(re,{children:[e.jsx(ie,{children:"Upload Resource"}),e.jsx(Te,{children:"Add files to your project resources"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"border-2 border-dashed border-muted-foreground/25 rounded-lg p-8 text-center cursor-pointer hover:border-muted-foreground/50 transition-colors",onDragOver:ue,onDrop:ge,onClick:()=>r.current?.click(),children:[e.jsx(bs,{className:"mx-auto h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"mt-2 text-sm font-medium",children:"Drop files here or click to browse"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Support for images, documents, and other files"})]}),e.jsx("input",{ref:r,type:"file",multiple:!0,className:"hidden",onChange:s=>s.target.files&&W(s.target.files)}),g.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(u,{children:["Selected Files (",g.length,")"]}),e.jsx("div",{className:"border rounded-lg p-3 max-h-40 overflow-y-auto space-y-2",children:g.map((s,t)=>e.jsxs("div",{className:"flex items-center justify-between text-sm bg-muted/50 rounded px-3 py-2",children:[e.jsx("span",{className:"truncate flex-1",children:s.name}),e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>w(t),className:"h-6 w-6 p-0 ml-2",children:e.jsx(Ie,{className:"h-3 w-3"})})]},t))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"tags",children:"Tags"}),e.jsx(De,{id:"tags",placeholder:"Type a tag and press Enter",value:k,onChange:s=>z(s.target.value),onKeyDown:se}),f.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:f.map(s=>e.jsxs(ye,{variant:"secondary",className:"text-xs",children:[s,e.jsx("button",{type:"button",onClick:()=>X(s),className:"ml-1 hover:text-destructive",children:"×"})]},s))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"description",children:"Description"}),e.jsx(be,{id:"description",placeholder:"Brief description of this resource...",value:O,onChange:s=>B(s.target.value),rows:3})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(m,{variant:"outline",onClick:ce,disabled:b,children:"Cancel"}),e.jsx(m,{onClick:Z,disabled:g.length===0||b,children:b?"Uploading...":`Upload ${g.length>0?`(${g.length})`:""}`})]})]})]})}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs("div",{className:"relative flex-1 w-full",children:[e.jsx(is,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(De,{placeholder:"Search resources...",value:y,onChange:s=>c(s.target.value),className:"pl-8"})]})}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:l?Array.from({length:6}).map((s,t)=>e.jsxs(je,{className:"animate-pulse",children:[e.jsxs(Le,{children:[e.jsx("div",{className:"h-4 bg-muted rounded w-3/4"}),e.jsx("div",{className:"h-3 bg-muted rounded w-1/2"})]}),e.jsx(ve,{children:e.jsx("div",{className:"h-20 bg-muted rounded"})})]},t)):H.length>0?H.map(s=>e.jsxs(je,{className:"hover:shadow-lg hover:bg-muted transition-all cursor-pointer",onClick:t=>a(s,t),children:[e.jsxs(Le,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[me(s.type,s.name),e.jsx(as,{className:"text-sm font-medium truncate",children:s.name})]}),e.jsxs(ts,{className:"text-xs",children:[pe(s.size)," • ",new Date(s.uploadedAt).toLocaleDateString()]}),e.jsxs("div",{className:"flex justify-end space-x-1 mt-2",children:[e.jsx(m,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),ae(s)},title:"Copy path to clipboard",children:e.jsx(qe,{className:"h-3 w-3"})}),e.jsx(m,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),v(s)},children:e.jsx(ke,{className:"h-3 w-3"})}),e.jsx(m,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),K(s)},children:e.jsx(Ie,{className:"h-3 w-3"})})]})]}),e.jsxs(ve,{className:"pt-0",children:[e.jsx("div",{className:"mb-3",children:fe(s)}),s.metadata.description&&e.jsx("p",{className:"text-sm text-muted-foreground mb-2 line-clamp-2",children:s.metadata.description}),s.metadata.tags&&s.metadata.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:s.metadata.tags.map(t=>e.jsx(ye,{variant:"secondary",className:"text-xs",children:t},t))})]})]},s.id)):e.jsx("div",{className:"col-span-full",children:e.jsx(je,{children:e.jsxs(ve,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(ss,{className:"h-12 w-12 text-muted-foreground/50"}),e.jsx("h3",{className:"mt-4 text-lg font-semibold",children:"No resources yet"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground text-center max-w-sm",children:"Upload files to get started. Resources can be referenced by LLMs and team members for enhanced context."}),e.jsxs(m,{className:"mt-4",onClick:()=>M(!0),children:[e.jsx(Ue,{className:"mr-2 h-4 w-4"}),"Add First Resource"]})]})})})}),b&&e.jsx("div",{className:"fixed bottom-4 right-4 bg-background border rounded-lg shadow-lg p-4",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-primary"}),e.jsx("span",{className:"text-sm",children:"Uploading files..."})]})}),e.jsx(Ss,{open:A,onOpenChange:N,onSave:q}),e.jsx(Fs,{open:!!G,onOpenChange:s=>{s||j(null),s||S(null)},resource:G,onCopyPath:ae,onDownload:v,onNavigate:Q,canNavigatePrev:P!==null&&P>0,canNavigateNext:P!==null&&P<H.length-1}),e.jsx(le,{open:!!_,onOpenChange:s=>!s&&K(null),children:e.jsxs(ne,{className:"max-w-md",children:[e.jsxs(re,{children:[e.jsx(ie,{children:"Delete Resource"}),e.jsxs(Te,{children:["Are you sure you want to delete ",e.jsx("strong",{children:_?.name}),"? This action cannot be undone."]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(m,{variant:"outline",onClick:()=>K(null),children:"Cancel"}),e.jsx(m,{variant:"destructive",onClick:de,children:"Delete"})]})]})})]})}export{zs as default};
@@ -0,0 +1,16 @@
1
+ import{c as f,r,A as p,j as e,a1 as F,B as l,I as c,T as L}from"./index-B8vejVRZ.js";import{C as T,b as I,a as z}from"./card-CvaBJsG6.js";import{L as n}from"./label-DtNTh--4.js";import{B as _}from"./badge-NJasrAx_.js";import{P as D}from"./plus-Bon5P_OK.js";/**
2
+ * @license lucide-react v0.542.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const q=[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]],O=f("link",q);/**
7
+ * @license lucide-react v0.542.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const B=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],M=f("pen",B);/**
12
+ * @license lucide-react v0.542.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const R=[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]],w=f("unlink",R);function K(){const[v,C]=r.useState([]),[y,k]=r.useState(!1),[o,h]=r.useState(null),[u,j]=r.useState(!1),[g,N]=r.useState(null),[a,d]=r.useState({name:"",description:"",linkPath:"",targetPath:"",isActive:!1}),[i,m]=r.useState({name:"",description:"",linkPath:"",targetPath:"",isActive:!1});r.useEffect(()=>{x()},[]);const x=async()=>{try{const s=await(await fetch(`${p}/api/v1/symlinks`)).json();s.success&&C(s.symlinks)}catch(t){console.error("Error fetching symlinks:",t)}},S=async t=>{h(t);try{(await fetch(`${p}/api/v1/symlinks/${t}/toggle`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok?await x():console.error("Error toggling symlink")}catch(s){console.error("Error toggling symlink:",s)}finally{h(null)}},A=async t=>{if(confirm("Are you sure you want to delete this symlink configuration?")){h(t);try{(await fetch(`${p}/api/v1/symlinks/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json"}})).ok?await x():console.error("Error deleting symlink")}catch(s){console.error("Error deleting symlink:",s)}finally{h(null)}}},E=async()=>{if(!a.name||!a.linkPath||!a.targetPath){alert("Please fill in all required fields");return}k(!0);try{const t=await fetch(`${p}/api/v1/symlinks`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(t.ok)await x(),j(!1),d({name:"",description:"",linkPath:"",targetPath:"",isActive:!1});else{const s=await t.json();alert(s.error?.message||"Error creating symlink")}}catch(t){console.error("Error adding symlink:",t),alert("Failed to create symlink")}finally{k(!1)}},b=t=>{N(t.id),m({name:t.name,description:t.description||"",linkPath:t.linkPath,targetPath:t.targetPath,isActive:t.isActive})},P=()=>{N(null),m({name:"",description:"",linkPath:"",targetPath:"",isActive:!1})},$=async()=>{if(g){if(!i.name||!i.linkPath||!i.targetPath){alert("Please fill in all required fields");return}h(g);try{const t=await fetch(`${p}/api/v1/symlinks/${g}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(t.ok)await x(),P();else{const s=await t.json();alert(s.error?.message||"Error updating symlink")}}catch(t){console.error("Error updating symlink:",t),alert("Failed to update symlink")}finally{h(null)}}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"Symlinks Configuration"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage symlinks for easy access to project rules and configurations."})]}),e.jsx(F,{}),e.jsxs(T,{children:[e.jsx(I,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs(l,{size:"sm",variant:"outline",onClick:()=>j(!u),children:[e.jsx(D,{className:"h-4 w-4 mr-2"}),u?"Cancel":"Add Symlink"]})})}),e.jsxs(z,{children:[u&&e.jsxs("div",{className:"mb-6 p-4 border rounded-lg bg-muted/50",children:[e.jsx("h4",{className:"font-medium mb-4",children:"New Symlink Configuration"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(n,{htmlFor:"new-name",children:"Name *"}),e.jsx(c,{id:"new-name",placeholder:"e.g., Claude Rules",value:a.name,onChange:t=>d({...a,name:t.target.value})})]}),e.jsxs("div",{children:[e.jsx(n,{htmlFor:"new-description",children:"Description"}),e.jsx(c,{id:"new-description",placeholder:"e.g., Project-specific rules for Claude AI",value:a.description,onChange:t=>d({...a,description:t.target.value})})]}),e.jsxs("div",{children:[e.jsx(n,{htmlFor:"new-link-path",children:"Link Path * (relative to project root)"}),e.jsx(c,{id:"new-link-path",placeholder:"e.g., CLAUDE.md or docs/README.md",value:a.linkPath,onChange:t=>d({...a,linkPath:t.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Where the symlink will be created in your project"})]}),e.jsxs("div",{children:[e.jsx(n,{htmlFor:"new-target-path",children:"Target Path * (relative to project root)"}),e.jsx(c,{id:"new-target-path",placeholder:"e.g., .nut/rules/CLAUDE.md",value:a.targetPath,onChange:t=>d({...a,targetPath:t.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"The actual file that the symlink will point to"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"new-active",checked:a.isActive,onChange:t=>d({...a,isActive:t.target.checked}),className:"rounded"}),e.jsx(n,{htmlFor:"new-active",children:"Activate immediately"})]}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(l,{variant:"outline",onClick:()=>{j(!1),d({name:"",description:"",linkPath:"",targetPath:"",isActive:!1})},children:"Cancel"}),e.jsx(l,{onClick:E,disabled:y,children:y?"Creating...":"Create Symlink"})]})]})]}),v.length===0&&!u?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(w,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No symlinks configured"}),e.jsx("p",{className:"text-sm mt-2",children:'Click "Add Symlink" to create your first symlink configuration.'})]}):e.jsx("div",{className:"space-y-4",children:v.map(t=>e.jsx("div",{className:"border rounded-lg",children:g===t.id?e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx(n,{htmlFor:`edit-name-${t.id}`,children:"Name *"}),e.jsx(c,{id:`edit-name-${t.id}`,value:i.name,onChange:s=>m({...i,name:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(n,{htmlFor:`edit-desc-${t.id}`,children:"Description"}),e.jsx(c,{id:`edit-desc-${t.id}`,value:i.description,onChange:s=>m({...i,description:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(n,{htmlFor:`edit-link-${t.id}`,children:"Link Path *"}),e.jsx(c,{id:`edit-link-${t.id}`,value:i.linkPath,onChange:s=>m({...i,linkPath:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(n,{htmlFor:`edit-target-${t.id}`,children:"Target Path *"}),e.jsx(c,{id:`edit-target-${t.id}`,value:i.targetPath,onChange:s=>m({...i,targetPath:s.target.value})})]}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(l,{variant:"outline",size:"sm",onClick:P,children:"Cancel"}),e.jsx(l,{size:"sm",onClick:$,disabled:o===t.id,children:o===t.id?"Saving...":"Save"})]})]}):e.jsx("div",{className:"p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[t.isActive?e.jsx(O,{className:"h-4 w-4 text-green-600 flex-shrink-0"}):e.jsx(w,{className:"h-4 w-4 text-gray-400 flex-shrink-0"}),e.jsx("h4",{className:"font-medium text-sm sm:text-base",children:t.name})]}),e.jsx(_,{variant:t.isActive?"default":"secondary",className:"text-xs",children:t.isActive?"Active":"Inactive"})]}),t.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:t.description}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-2 font-mono break-all",children:[e.jsx("span",{className:"text-foreground/70",children:t.linkPath}),e.jsx("span",{className:"mx-1",children:"→"}),e.jsx("span",{children:t.targetPath})]})]}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-shrink-0",children:[e.jsx(l,{onClick:()=>S(t.id),disabled:o===t.id,variant:t.isActive?"outline":"default",size:"sm",children:o===t.id?"...":e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden sm:inline",children:t.isActive?"Disable":"Enable"}),e.jsx("span",{className:"sm:hidden",children:t.isActive?"Off":"On"})]})}),e.jsx(l,{onClick:()=>b(t),variant:"outline",size:"icon",className:"h-8 w-8",disabled:o===t.id,children:e.jsx(M,{className:"h-4 w-4"})}),e.jsx(l,{onClick:()=>A(t.id),variant:"outline",size:"icon",className:"h-8 w-8",disabled:o===t.id,children:e.jsx(L,{className:"h-4 w-4"})})]})]})})},t.id))})]})]})]})}export{K as default};
@@ -0,0 +1,4 @@
1
+ import{H as Qe,ag as Xe,r as m,j as e,B as u,n as O,be as pe,M as q,N as ge,T as fe,O as V,P as Y,Q as G,R as K,U as Q,V as X,W as Z,i as ee,h as ve,bf as Ze,C as es,q as ss,s as se,D as je,a as Ne,b as be,d as ye,e as we,I as te,v as ts,w as as,x as rs,y as ns,z as is,a5 as Se,a6 as Ce,a7 as ke,a8 as Ae,a9 as De,ae as Te,a0 as ls,ac as ds,$ as Ie,A as j}from"./index-B8vejVRZ.js";import{C as J,a as ae,c as re,b as Fe}from"./card-CvaBJsG6.js";import{B as F}from"./badge-NJasrAx_.js";import{L as v}from"./label-DtNTh--4.js";import{S as cs}from"./switch-D86f4WeD.js";import{T as os,a as ms,b as ne,c as ie}from"./tabs-BYrDWPwx.js";import{R as us}from"./refresh-cw-CnHMzcH3.js";import{P as Pe}from"./plus-Bon5P_OK.js";import{P as Me}from"./play-a8BsF4gF.js";import{P as hs}from"./pause-COIsHZIp.js";import{C as xs}from"./clock-BTCBJF7v.js";const ce=[{id:"claude",label:"Claude Code"},{id:"gemini",label:"Google Gemini"},{id:"codex",label:"OpenAI Codex"},{id:"droid",label:"Factory Droid"}],ps=[{label:"Monday",value:"monday"},{label:"Tuesday",value:"tuesday"},{label:"Wednesday",value:"wednesday"},{label:"Thursday",value:"thursday"},{label:"Friday",value:"friday"},{label:"Saturday",value:"saturday"},{label:"Sunday",value:"sunday"}],$e=["monday","tuesday","wednesday","thursday","friday"],Ee=a=>{if(!a)return"—";try{return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(a))}catch{return a}},H=a=>{if(!a)return"—";const x=new Date(a).getTime()-Date.now(),f=Math.round(x/(1e3*60));if(Number.isNaN(f))return Ee(a);if(Math.abs(f)<1)return"now";if(f>0){if(f<60)return`in ${f}m`;const b=Math.round(f/60);return b<24?`in ${b}h`:`in ${Math.round(b/24)}d`}const N=Math.abs(f);if(N<60)return`${N}m ago`;const I=Math.round(N/60);return I<24?`${I}h ago`:`${Math.round(I/24)}d ago`},gs=a=>{if(a.type==="interval"){const o=a.daysOfWeek.map(x=>x.slice(0,3).toUpperCase()).join(", ");return`Every ${a.hours}h (${o||"All days"})`}return a.description||`Cron: ${a.expression}`},fs=a=>{const o=ce.find(x=>x.id===a);return o?o.label:a},le=a=>{switch(a){case"active":case"succeeded":return"default";case"paused":case"running":return"secondary";case"failed":return"destructive";default:return"outline"}},de=()=>({name:"",model:"claude",prompt:"",hours:6,daysOfWeek:new Set($e),status:!0,anchorHour:"",agentIds:[],mcpServers:[]}),Re=a=>{if(a.schedule.type!=="interval")return de();const o=a.agentIds||(a.agentId?[a.agentId]:[]);return{name:a.name,model:ce.some(x=>x.id===a.model)?a.model:"claude",prompt:a.prompt,hours:a.schedule.hours,daysOfWeek:new Set(a.schedule.daysOfWeek),status:a.status==="active",anchorHour:a.schedule.anchorHour===void 0?"":String(a.schedule.anchorHour),agentIds:o,mcpServers:a.mcpServers||[]}},vs=a=>a?Array.isArray(a)?a.filter(o=>typeof o=="string").map(o=>o.trim()).filter(Boolean):typeof a=="string"?a.split(",").map(o=>o.trim()).filter(Boolean):[]:[];function Is(){const{toast:a}=Qe(),{refresh:o}=Xe(),[x,f]=m.useState([]),[N,I]=m.useState(!0),[L,b]=m.useState(!1),[P,y]=m.useState(!1),[n,p]=m.useState(()=>de()),[z,oe]=m.useState(!1),[w,S]=m.useState(null),[c,C]=m.useState(null),[g,M]=m.useState(null),[Oe,R]=m.useState(!1),[$,Je]=m.useState([]),[W,He]=m.useState([]),[Le,ze]=m.useState(new Set),[B,U]=m.useState({open:!1,serverToRemove:null}),k=async(s=!1)=>{try{N||b(!0);const t=await fetch(`${j}/api/v1/jobs`);if(!t.ok)throw new Error(`Failed to fetch jobs (${t.status})`);const r=await t.json();if(!r?.success)throw new Error(r?.error?.message||"Unknown error loading jobs");const i=r.data??[];if(f(i),c){const l=i.find(d=>d.id===c.id);l&&(C(l),l.schedule.type!=="cron"&&p(Re(l)))}if(g){const l=i.find(d=>d.id===g.id);l&&M(l)}s&&a({title:"Schedule refreshed",description:"Latest job information loaded."})}catch(t){console.error("Failed to load jobs:",t),a({title:"Failed to load schedule",description:t?.message??"Unknown error",variant:"destructive"})}finally{I(!1),b(!1)}};m.useEffect(()=>{k()},[]),m.useEffect(()=>{P&&(async()=>{try{const t=await fetch(`${j}/api/v1/agents`);if(t.ok){const i=await t.json(),d=(Array.isArray(i?.documents)?i.documents:[]).map(h=>({id:h.filename,name:h?.metadata?.name||h.title||h.filename,tools:vs(h?.metadata?.tools)}));if(Je(d),c){const D=(c.agentIds||(c.agentId?[c.agentId]:[])).filter(T=>!d.find(_=>_.id===T));D.length>0&&(a({title:"Some agents no longer available",description:`The following agents have been removed: ${D.join(", ")}`,variant:"destructive"}),p(T=>({...T,agentIds:T.agentIds.filter(_=>d.find(Ke=>Ke.id===_))})))}}const r=await fetch(`${j}/api/v1/mcp`);if(r.ok){const i=await r.json();if(i?.success&&Array.isArray(i.servers)&&(He(i.servers),c?.mcpServers)){const l=c.mcpServers.filter(d=>!i.servers.includes(d));l.length>0&&(a({title:"Some MCP servers are no longer available",description:`The following servers have been removed: ${l.join(", ")}`,variant:"destructive"}),p(d=>({...d,mcpServers:d.mcpServers.filter(h=>i.servers.includes(h))})))}}}catch(t){console.error("Failed to load agents or MCP servers:",t)}})()},[P,c,a]);const A=s=>{p(t=>({...t,...s}))},We=(s,t)=>{p(r=>{let i;if(t){i=[...r.agentIds,s];const l=$.find(d=>d.id===s);if(l&&l.tools.length>0){const d=new Set([...r.mcpServers,...l.tools]);return{...r,agentIds:i,mcpServers:Array.from(d).filter(h=>W.includes(h))}}}else i=r.agentIds.filter(l=>l!==s);return{...r,agentIds:i}})},Be=(s,t)=>{if(!t&&$.filter(i=>n.agentIds.includes(i.id)&&i.tools.includes(s)).length>0){U({open:!0,serverToRemove:s});return}p(r=>({...r,mcpServers:t?[...r.mcpServers,s]:r.mcpServers.filter(i=>i!==s)}))},Ue=()=>{const s=B.serverToRemove;s&&p(t=>({...t,mcpServers:t.mcpServers.filter(r=>r!==s)})),U({open:!1,serverToRemove:null})},_e=(s,t)=>{p(r=>{const i=new Set(r.daysOfWeek);return t?i.add(s):i.delete(s),i.size===0&&$e.forEach(l=>i.add(l)),{...r,daysOfWeek:i}})},E=()=>{p(de())},me=s=>{ze(t=>{const r=new Set(t);return r.has(s)?r.delete(s):r.add(s),r})},ue=s=>{M(s),R(!0)},he=()=>{C(null),E(),y(!0)},qe=s=>{if(s._error){a({title:"Cannot edit corrupted job",description:"Please fix the job file manually at .nut/jobs/"+s.id+".md",variant:"destructive"});return}if(s.schedule.type==="cron"){a({title:"Manual edit required",description:"Cron-based jobs can be edited directly in .nut/jobs/<id>.md for now.",variant:"destructive"});return}C(s),p(Re(s)),y(!0)},Ve=async s=>{if(s.preventDefault(),!n.name.trim()){a({title:"Job name required",description:"Please provide a name for the scheduled job.",variant:"destructive"});return}if(!n.prompt.trim()){a({title:"Prompt required",description:"Please provide instructions for the scheduled job.",variant:"destructive"});return}oe(!0);const t=!!c;try{const r=Number(n.anchorHour.trim()),i=n.anchorHour.trim()===""||Number.isNaN(r)?void 0:Math.min(23,Math.max(0,r)),l={name:n.name.trim(),prompt:n.prompt.trim(),model:n.model,status:n.status?"active":"paused",schedule:{type:"interval",hours:Math.max(1,Number(n.hours)||6),daysOfWeek:Array.from(n.daysOfWeek),anchorHour:i},agentIds:n.agentIds.length>0?n.agentIds:void 0,mcpServers:n.mcpServers.length>0?n.mcpServers:void 0},d=t?`${j}/api/v1/jobs/${c?.id}`:`${j}/api/v1/jobs`,D=await fetch(d,{method:t?"PATCH":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!D.ok){const T=await D.json().catch(()=>({}));throw new Error(T?.error?.message||`Failed to ${t?"update":"create"} job (${D.status})`)}a({title:t?"Scheduled job updated":"Scheduled job created",description:l.name}),y(!1),C(null),E(),await k()}catch(r){console.error("Failed to submit job:",r),a({title:`Failed to ${c?"update":"create"} job`,description:r?.message??"Unknown error",variant:"destructive"})}finally{oe(!1)}},Ye=async s=>{if(s._error){a({title:"Cannot run corrupted job",description:"Please fix the job file manually at .nut/jobs/"+s.id+".md",variant:"destructive"});return}S(s.id);try{const t=await fetch(`${j}/api/v1/jobs/${s.id}/run`,{method:"POST"});if(!t.ok){const r=await t.json().catch(()=>({}));throw new Error(r?.error?.message||`Failed to run job (${t.status})`)}a({title:"Run started",description:`${s.name} is executing.`}),await k(),await o()}catch(t){console.error("Failed to run job:",t),a({title:"Run failed to start",description:t?.message??"Unknown error",variant:"destructive"})}finally{S(null)}},Ge=async s=>{if(s._error){a({title:"Cannot update corrupted job",description:"Please fix the job file manually at .nut/jobs/"+s.id+".md",variant:"destructive"});return}S(s.id);const t=s.status==="active"?"paused":"active";try{const r=await fetch(`${j}/api/v1/jobs/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:t})});if(!r.ok){const i=await r.json().catch(()=>({}));throw new Error(i?.error?.message||`Failed to update job (${r.status})`)}a({title:t==="active"?"Job resumed":"Job paused",description:s.name}),await k(),await o()}catch(r){console.error("Failed to update job status:",r),a({title:"Failed to update job",description:r?.message??"Unknown error",variant:"destructive"})}finally{S(null)}},xe=async s=>{S(s.id);try{const t=await fetch(`${j}/api/v1/jobs/${s.id}`,{method:"DELETE"});if(!t.ok){const r=await t.json().catch(()=>({}));throw new Error(r?.error?.message||`Failed to delete job (${t.status})`)}a({title:"Scheduled job deleted",description:s.name}),c?.id===s.id&&(y(!1),C(null),E()),g?.id===s.id&&(R(!1),M(null)),await k()}catch(t){console.error("Failed to delete job:",t),a({title:"Failed to delete job",description:t?.message??"Unknown error",variant:"destructive"})}finally{S(null)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Schedule"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Automate recurring agent runs with prompts, preferred models, and guardrails."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(u,{variant:"outline",onClick:()=>k(!0),disabled:N||L,children:[L?e.jsx(O,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(us,{className:"mr-2 h-4 w-4"}),"Refresh"]}),e.jsxs(u,{onClick:he,children:[e.jsx(Pe,{className:"mr-2 h-4 w-4"}),"New Scheduled Job"]})]})]}),N?e.jsx(J,{children:e.jsxs(ae,{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(O,{className:"mr-2 h-5 w-5 animate-spin"}),"Loading scheduled jobs..."]})}):x.length===0?e.jsx(J,{className:"border-dashed",children:e.jsxs(ae,{className:"flex flex-col items-center justify-center py-16 px-6 text-center",children:[e.jsx("div",{className:"rounded-full bg-muted p-6 mb-6",children:e.jsx(pe,{className:"h-12 w-12 text-muted-foreground"})}),e.jsx(re,{className:"text-2xl mb-3",children:"No scheduled jobs yet"}),e.jsx("p",{className:"text-muted-foreground max-w-md mb-6",children:"Automate recurring tasks by scheduling an agent to run on your behalf. Set up your first job to get started."}),e.jsxs("div",{className:"bg-accent/50 rounded-lg p-6 max-w-lg space-y-3 text-sm text-left",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"h-6 w-6 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx("span",{className:"text-xs font-bold text-primary",children:"1"})}),e.jsx("p",{className:"text-muted-foreground",children:"Choose the days of the week and cadence that fit your workflow"})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"h-6 w-6 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx("span",{className:"text-xs font-bold text-primary",children:"2"})}),e.jsx("p",{className:"text-muted-foreground",children:"Provide detailed instructions so the agent can execute safely"})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"h-6 w-6 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx("span",{className:"text-xs font-bold text-primary",children:"3"})}),e.jsx("p",{className:"text-muted-foreground",children:"All runs are logged under for review"})]})]}),e.jsxs(u,{onClick:he,className:"mt-8",size:"lg",children:[e.jsx(Pe,{className:"mr-2 h-5 w-5"}),"Create Your First Job"]})]})}):e.jsx("div",{className:"grid gap-4",children:x.map(s=>s._error?e.jsx(J,{className:"border-destructive/50 bg-destructive/5",children:e.jsx(Fe,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsxs(re,{className:"text-lg truncate text-destructive",children:["Unable to load job: ",s.id]}),e.jsx(F,{variant:"destructive",className:"text-xs shrink-0",children:"Error"})]}),e.jsx("p",{className:"text-sm text-destructive/80 mt-1",children:s._error}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["Please review the job file at ",e.jsxs("code",{className:"text-xs bg-muted px-1 py-0.5 rounded",children:[".nut/jobs/",s.id,".md"]})]})]}),e.jsx("div",{className:"flex items-center gap-1.5 shrink-0",children:e.jsxs(q,{children:[e.jsx(ge,{asChild:!0,children:e.jsx(u,{size:"sm",variant:"ghost",disabled:w===s.id,className:"h-8 px-2 text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(fe,{className:"h-3.5 w-3.5"})})}),e.jsxs(V,{children:[e.jsxs(Y,{children:[e.jsx(G,{children:"Delete corrupted job?"}),e.jsxs(K,{children:["This will remove the corrupted job file ",e.jsx("strong",{children:s.id}),". This action cannot be undone."]})]}),e.jsxs(Q,{children:[e.jsx(X,{children:"Cancel"}),e.jsx(Z,{onClick:()=>xe(s),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})})]})})},s.id):e.jsxs(J,{className:"group relative overflow-hidden border-border hover:border-primary/50 transition-all hover:shadow-lg",children:[e.jsx(Fe,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(re,{className:"text-lg truncate",children:s.name}),e.jsx(F,{variant:le(s.status),className:"capitalize text-xs shrink-0",children:s.status})]}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-1",children:s.description||s.prompt||"No description provided"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx(u,{size:"sm",variant:"default",onClick:()=>Ye(s),disabled:w===s.id,className:"h-8 px-3",children:w===s.id?e.jsx(O,{className:"h-3.5 w-3.5 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(Me,{className:"mr-1.5 h-3.5 w-3.5"}),"Run"]})}),e.jsx(u,{size:"sm",variant:"outline",onClick:()=>qe(s),disabled:w===s.id,className:"h-8 px-3 text-xs",children:"Edit"}),e.jsx(u,{size:"sm",variant:"outline",onClick:()=>Ge(s),disabled:w===s.id,className:"h-8 px-2",children:s.status==="active"?e.jsx(hs,{className:"h-3.5 w-3.5"}):e.jsx(Me,{className:"h-3.5 w-3.5"})}),e.jsxs(q,{children:[e.jsx(ge,{asChild:!0,children:e.jsx(u,{size:"sm",variant:"ghost",disabled:w===s.id,className:"h-8 px-2 text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(fe,{className:"h-3.5 w-3.5"})})}),e.jsxs(V,{children:[e.jsxs(Y,{children:[e.jsx(G,{children:"Delete scheduled job?"}),e.jsxs(K,{children:["This will remove ",e.jsx("strong",{children:s.name}),". Existing run logs will remain in ",e.jsx("code",{children:".nut/jobs/logs"}),"."]})]}),e.jsxs(Q,{children:[e.jsx(X,{children:"Cancel"}),e.jsx(Z,{onClick:()=>xe(s),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]})]})}),e.jsxs(ae,{className:"space-y-3 pt-0",children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-4 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md bg-accent/30",children:[e.jsx(xs,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"font-semibold truncate",children:gs(s.schedule)})})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md bg-accent/30",children:[e.jsx(ee,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("div",{className:"font-semibold",children:fs(s.model)})]}),e.jsx("div",{className:"flex items-center gap-2 p-2 rounded-md bg-accent/30",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[10px] text-muted-foreground uppercase font-bold",children:"Next"}),e.jsx("div",{className:"font-semibold truncate",children:H(s.metadata.nextRunAt)})]})}),e.jsx("div",{className:"flex items-center gap-2 p-2 rounded-md bg-accent/30",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[10px] text-muted-foreground uppercase font-bold",children:"Last"}),e.jsx("div",{className:"font-semibold truncate",children:H(s.metadata.lastRunAt)})]})})]}),(s.agentIds&&s.agentIds.length>0||s.agentId||s.mcpServers&&s.mcpServers.length>0)&&e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs",children:[(s.agentIds||(s.agentId?[s.agentId]:[])).map(t=>e.jsxs("div",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-800",children:[e.jsx(ee,{className:"h-3 w-3 text-blue-600 dark:text-blue-400"}),e.jsx("span",{className:"font-medium text-blue-900 dark:text-blue-100",children:t.replace(".md","")})]},t)),s.mcpServers&&s.mcpServers.length>0&&s.mcpServers.map(t=>e.jsxs("div",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-purple-50 dark:bg-purple-950/20 border border-purple-200 dark:border-purple-800",children:[e.jsx(ve,{className:"h-3 w-3 text-purple-600 dark:text-purple-400"}),e.jsx("span",{className:"font-medium text-purple-900 dark:text-purple-100",children:t})]},t))]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5",children:[e.jsx(Ze,{className:"h-3 w-3"}),"Recent Runs"]}),s.runs.length>1&&e.jsxs(u,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>ue(s),children:["View All (",s.runs.length,")",e.jsx(es,{className:"ml-1 h-3 w-3"})]})]}),s.runs.length===0?e.jsx("div",{className:"rounded-md border border-dashed bg-muted/20 p-4 text-center text-xs text-muted-foreground",children:'No runs yet • Click "Run" to execute'}):e.jsxs("div",{className:"space-y-1.5",children:[s.runs.slice(0,1).map(t=>{const r=Le.has(t.id);return e.jsxs("div",{className:"rounded-md border bg-card/50 overflow-hidden transition-all",children:[e.jsxs("div",{className:"p-2.5 text-xs hover:bg-accent/50 transition-colors cursor-pointer",onClick:()=>me(t.id),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[e.jsx(F,{variant:le(t.status),className:"capitalize text-[10px] h-5",children:t.status}),e.jsx("span",{className:"text-muted-foreground truncate",children:H(t.startedAt)})]}),t.trigger==="manual"&&e.jsx(F,{variant:"outline",className:"text-[10px] h-5",children:"manual"})]}),t.error&&e.jsx("p",{className:"text-destructive font-medium mt-1 line-clamp-1",children:t.error})]}),t.summary&&e.jsx("div",{className:"px-2.5 pb-2.5",children:e.jsxs("div",{className:"rounded bg-muted/50 p-2 font-mono text-[10px] leading-relaxed text-muted-foreground relative cursor-pointer hover:bg-muted/70 transition-colors",onClick:i=>{i.stopPropagation(),me(t.id)},children:[e.jsx("div",{className:r?"":"line-clamp-2",children:t.summary}),e.jsx("div",{className:"flex justify-center mt-1",children:e.jsx("div",{className:"text-muted-foreground p-0.5",children:r?e.jsx(ss,{className:"h-3 w-3"}):e.jsx(se,{className:"h-3 w-3"})})})]})})]},t.id)}),s.runs.length>1&&e.jsxs(u,{variant:"ghost",size:"sm",className:"w-full h-7 text-xs",onClick:()=>ue(s),children:["+",s.runs.length-1," more runs"]})]})]})]})]},s.id))}),e.jsx(je,{open:P,onOpenChange:s=>{y(s),s||(C(null),E())},children:e.jsxs(Ne,{className:"max-w-4xl h-[700px] overflow-hidden flex flex-col",children:[e.jsxs(be,{className:"space-y-2 pb-4 shrink-0",children:[e.jsxs(ye,{className:"text-xl flex items-center gap-2",children:[e.jsx(pe,{className:"h-5 w-5 text-primary"}),c?"Edit Scheduled Job":"Create New Scheduled Job"]}),e.jsx(we,{className:"text-sm",children:c?"Update the prompt, cadence, or agent preference":"Automate recurring tasks by scheduling an agent"})]}),e.jsxs("form",{onSubmit:Ve,className:"flex flex-col flex-1 min-h-0",children:[e.jsxs(os,{defaultValue:"basics",className:"flex-1 flex flex-col min-h-0",children:[e.jsxs(ms,{className:"grid w-full grid-cols-3 mb-4 shrink-0",children:[e.jsx(ne,{value:"basics",children:"Basics"}),e.jsx(ne,{value:"schedule",children:"Schedule"}),e.jsx(ne,{value:"advanced",children:"Advanced"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto pr-2 -mr-2 min-h-0",children:[e.jsxs(ie,{value:"basics",className:"space-y-5 mt-0",children:[e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs(v,{htmlFor:"job-name",className:"text-sm font-medium flex items-center gap-1.5",children:["Job Name",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(te,{id:"job-name",placeholder:"e.g., Publish docs nightly",value:n.name,onChange:s=>A({name:s.target.value}),className:"h-11",required:!0})]}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsx(v,{htmlFor:"job-model",className:"text-sm font-medium",children:"AI Model"}),e.jsxs(ts,{value:n.model,onValueChange:s=>A({model:s}),children:[e.jsx(as,{id:"job-model",className:"h-11",children:e.jsx(rs,{placeholder:"Select a model"})}),e.jsx(ns,{children:ce.map(s=>e.jsx(is,{value:s.id,children:s.label},s.id))})]})]})]}),e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs(v,{className:"text-sm font-medium flex items-center gap-1.5",children:[e.jsx(ee,{className:"h-4 w-4"}),"Custom Agent",e.jsx("span",{className:"text-xs text-muted-foreground font-normal",children:"(optional)"})]}),e.jsxs(Se,{children:[e.jsx(Ce,{asChild:!0,children:e.jsxs(u,{variant:"outline",className:"w-full h-11 justify-between font-normal",children:[n.agentIds.length===0?"No agents selected":`${n.agentIds.length} agent${n.agentIds.length!==1?"s":""} selected`,e.jsx(se,{className:"h-4 w-4 opacity-50"})]})}),e.jsxs(ke,{className:"w-full min-w-[--radix-dropdown-menu-trigger-width]",children:[e.jsx(Ae,{children:"Available Agents"}),e.jsx(De,{}),$.length===0?e.jsx("div",{className:"px-2 py-1.5 text-sm text-muted-foreground",children:"No agents configured"}):$.map(s=>e.jsx(Te,{checked:n.agentIds.includes(s.id),onCheckedChange:t=>We(s.id,t),children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:s.name}),s.tools.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["MCP: ",s.tools.join(", ")]})]})},s.id))]})]})]}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs(v,{className:"text-sm font-medium flex items-center gap-1.5",children:[e.jsx(ve,{className:"h-4 w-4"}),"MCP Servers",e.jsx("span",{className:"text-xs text-muted-foreground font-normal",children:"(optional)"})]}),e.jsxs(Se,{children:[e.jsx(Ce,{asChild:!0,children:e.jsxs(u,{variant:"outline",className:"w-full h-11 justify-between font-normal",children:[n.mcpServers.length===0?"No MCP servers selected":`${n.mcpServers.length} server${n.mcpServers.length!==1?"s":""} selected`,e.jsx(se,{className:"h-4 w-4 opacity-50"})]})}),e.jsxs(ke,{className:"w-full min-w-[--radix-dropdown-menu-trigger-width]",children:[e.jsx(Ae,{children:"Available MCP Servers"}),e.jsx(De,{}),W.length===0?e.jsx("div",{className:"px-2 py-1.5 text-sm text-muted-foreground",children:"No MCP servers configured"}):W.map(s=>e.jsx(Te,{checked:n.mcpServers.includes(s),onCheckedChange:t=>Be(s,t),children:s},s))]})]})]})]}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs(v,{htmlFor:"job-prompt",className:"text-sm font-medium flex items-center gap-1.5",children:[n.agentIds.length>0?"Custom Instructions":"Instructions",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ls,{id:"job-prompt",placeholder:n.agentIds.length>0?`Additional instructions to supplement the agent's predefined behavior...
2
+ Example: Focus on performance optimizations`:`Example:
3
+ Run the following command and append the output to .nut/context/knowledge/runs.md:
4
+ pnpm docs:publish`,rows:6,value:n.prompt,onChange:s=>A({prompt:s.target.value}),className:"resize-none font-mono text-sm"}),e.jsxs("p",{className:"text-xs text-muted-foreground flex items-start gap-1.5",children:[e.jsx("span",{className:"text-amber-600 dark:text-amber-500",children:"⚠"}),e.jsx("span",{children:n.agentIds.length>0?"These custom instructions will be combined with the selected agents' predefined instructions. Jobs run with autonomous permissions.":"Provide clear, actionable instructions. Jobs run with autonomous permissions - include safety checks where needed."})]})]})]}),e.jsx(ie,{value:"schedule",className:"space-y-5 mt-0",children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-[1.2fr_1fr]",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(v,{className:"text-sm font-medium",children:"Days of the Week"}),e.jsx("div",{className:"grid grid-cols-2 gap-2.5",children:ps.map(s=>e.jsxs("label",{className:"flex items-center gap-2.5 text-sm rounded-md border border-input px-3.5 py-2.5 cursor-pointer hover:bg-accent/50 transition-colors",children:[e.jsx(ds,{checked:n.daysOfWeek.has(s.value),onCheckedChange:t=>_e(s.value,t)}),e.jsx("span",{className:"font-medium",children:s.label})]},s.value))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Select which days the job should run"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2.5",children:[e.jsx(v,{htmlFor:"job-hours",className:"text-sm font-medium",children:"Frequency (hours)"}),e.jsxs("div",{className:"relative",children:[e.jsx(te,{id:"job-hours",type:"number",min:1,value:n.hours,onChange:s=>A({hours:Number(s.target.value)||1}),className:"h-11 pr-16"}),e.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-sm text-muted-foreground",children:"hours"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"How often the job runs on selected days"})]}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs(v,{htmlFor:"job-anchor",className:"text-sm font-medium flex items-center gap-1.5",children:["Start Hour",e.jsx("span",{className:"text-xs text-muted-foreground font-normal",children:"(optional)"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(te,{id:"job-anchor",type:"number",min:0,max:23,placeholder:"Auto",value:n.anchorHour,onChange:s=>A({anchorHour:s.target.value}),className:"h-11"}),e.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-sm text-muted-foreground",children:"0-23"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Preferred starting hour in 24h format"})]})]})]})}),e.jsx(ie,{value:"advanced",className:"space-y-5 mt-0",children:e.jsxs("div",{className:"flex items-start gap-4 rounded-lg border border-border bg-accent/20 p-4",children:[e.jsx(cs,{id:"job-status",checked:n.status,onCheckedChange:s=>A({status:s}),className:"mt-1"}),e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsx(v,{htmlFor:"job-status",className:"text-base font-semibold cursor-pointer",children:n.status?"Start Active":"Start Paused"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n.status?"Job will begin running on the configured schedule immediately after creation.":"Job will be created in a paused state. You can activate it later from the schedule page."})]})]})})]})]}),e.jsxs(Ie,{className:"gap-2 sm:gap-2 pt-4 border-t mt-4",children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>y(!1),disabled:z,className:"min-w-24",children:"Cancel"}),e.jsx(u,{type:"submit",disabled:z||!n.name.trim()||!n.prompt.trim(),className:"min-w-32",children:z?e.jsxs(e.Fragment,{children:[e.jsx(O,{className:"mr-2 h-4 w-4 animate-spin"}),c?"Saving...":"Creating..."]}):e.jsx(e.Fragment,{children:c?"Save Changes":"Create Job"})})]})]})]})}),e.jsx(je,{open:Oe,onOpenChange:s=>{R(s),s||M(null)},children:e.jsxs(Ne,{className:"max-w-3xl",children:[e.jsxs(be,{children:[e.jsxs(ye,{children:["Run history — ",g?.name]}),e.jsxs(we,{children:[g?.runs?.length??0," recorded runs. Logs stored in ",e.jsxs("code",{children:[".nut/jobs/",g?.id,".md"]})," and ",e.jsxs("code",{children:[".nut/jobs/logs/",g?.id]}),"."]})]}),e.jsxs("div",{className:"max-h-[420px] space-y-3 overflow-y-auto pr-2",children:[g?.runs.map(s=>e.jsxs("div",{className:"rounded-md border border-border overflow-hidden",children:[e.jsxs("div",{className:"p-3 text-xs bg-card/50",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[e.jsx(F,{variant:le(s.status),className:"capitalize text-[10px] h-5",children:s.status}),e.jsxs("span",{className:"text-muted-foreground",children:[s.trigger," • ",Ee(s.startedAt)]}),s.finishedAt&&e.jsxs("span",{className:"text-muted-foreground",children:["• completed ",H(s.finishedAt)]})]}),s.error&&e.jsx("p",{className:"text-destructive font-medium mb-2",children:s.error}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-[10px] text-muted-foreground",children:[s.outputPath&&e.jsxs("span",{children:["log: ",e.jsx("code",{className:"bg-muted px-1 py-0.5 rounded",children:s.outputPath})]}),s.cliCommand&&e.jsxs("span",{children:["cmd: ",e.jsx("code",{className:"bg-muted px-1 py-0.5 rounded",children:s.cliCommand})]})]})]}),s.summary&&e.jsx("div",{className:"px-3 pb-3",children:e.jsx("div",{className:"rounded bg-muted/50 p-2 font-mono text-[10px] leading-relaxed text-muted-foreground whitespace-pre-wrap",children:s.summary})})]},s.id)),g&&g.runs.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No recorded runs yet."})]}),e.jsx(Ie,{children:e.jsx(u,{variant:"outline",onClick:()=>R(!1),children:"Close"})})]})}),e.jsx(q,{open:B.open,onOpenChange:s=>{s||U({open:!1,serverToRemove:null})},children:e.jsxs(V,{children:[e.jsxs(Y,{children:[e.jsx(G,{children:"Remove MCP Server?"}),e.jsxs(K,{children:["One or more selected agents require the ",e.jsx("strong",{children:B.serverToRemove})," MCP server. Removing it may lead to unexpected consequences when the job runs."]})]}),e.jsxs(Q,{children:[e.jsx(X,{children:"Cancel"}),e.jsx(Z,{onClick:Ue,children:"OK"})]})]})})]})}export{Is as default};
@@ -0,0 +1 @@
1
+ import{r as p,j as t,I as d,B as m,X as x}from"./index-B8vejVRZ.js";import{B as f}from"./badge-NJasrAx_.js";function j({tags:a,onChange:r,disabled:n,placeholder:o}){const[l,s]=p.useState(""),c=()=>{const e=l.trim();if(e){if(a.includes(e)){s("");return}r([...a,e]),s("")}},i=e=>{r(a.filter(u=>u!==e))};return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex gap-2",children:[t.jsx(d,{placeholder:o||"Add a tag",value:l,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),c())},disabled:n}),t.jsx(m,{type:"button",variant:"outline",onClick:c,disabled:n,children:"Add"})]}),a.length>0&&t.jsx("div",{className:"flex flex-wrap gap-2",children:a.map(e=>t.jsxs(f,{variant:"secondary",className:"flex items-center gap-1",children:[e,t.jsx("button",{type:"button",onClick:()=>i(e),className:"ml-1 hover:text-destructive",disabled:n,"aria-label":`Remove tag ${e}`,children:t.jsx(x,{className:"h-3 w-3"})})]},e))})]})}export{j as T};
@@ -0,0 +1 @@
1
+ import{u as U,H as J,r as i,j as e,B as r,a3 as S,q as K,s as L,X as q,n as H,a4 as G}from"./index-B8vejVRZ.js";import{C as f,a as W}from"./card-CvaBJsG6.js";import{u as X}from"./use-terminal-2DGl8X5T.js";import{C as _,a as Q,T as V}from"./terminal-preview-Be68j_3t.js";import{R as Y}from"./refresh-cw-CnHMzcH3.js";import{P as M}from"./play-a8BsF4gF.js";import{C as Z}from"./circle-play-88lMuMRZ.js";import"./xterm-DTxiCjtJ.js";function oe(){const m=U(),{sessions:p,loading:o,error:k,refreshSessions:h,createSession:j,destroySession:B}=X(),{toast:l}=J(),[x,u]=i.useState(""),[g,I]=i.useState(!1),[v,T]=i.useState(!1),[N,$]=i.useState([]),[,w]=i.useState(null),O=s=>{const t=Date.now(),a=new Date(s).getTime(),n=Math.max(0,Math.floor((t-a)/1e3));if(n<60)return`${n}s ago`;const b=Math.floor(n/60);if(b<60)return`${b}m ago`;const C=Math.floor(b/60);return C<24?`${C}h ago`:`${Math.floor(C/24)}d ago`};i.useEffect(()=>{h()},[h]),i.useEffect(()=>{y(s=>{const t={...s};return p.forEach(a=>{a.id in t||(t[a.id]=!0)}),t})},[p]),i.useEffect(()=>{try{const s=localStorage.getItem("terminal.commandHistory");s&&$(JSON.parse(s))}catch{}},[]);const D=s=>{s&&($(t=>{const a=[s,...t.filter(n=>n!==s)].slice(0,5);try{localStorage.setItem("terminal.commandHistory",JSON.stringify(a))}catch{}return a}),w(null))},c=p.filter(s=>!s.proposalId?.startsWith("cp-")).sort((s,t)=>new Date(t.lastActivity).getTime()-new Date(s.lastActivity).getTime()),[d,y]=i.useState(()=>{const s={};return p.forEach(t=>{s[t.id]=!0}),s}),R=async()=>{const s=`session-${Date.now()}`;await j(s,!1)&&(l({title:"New terminal started",description:`${s}`}),m(`/terminal/${s}`))},E=async()=>{const s=x.trim();if(!s)return;const t=`session-${Date.now()}`;I(!0);try{await j(t,!1,s)?(D(s),l({title:"Session started",description:`${t}`}),m(`/terminal/${t}`)):l({title:"Failed to start",description:"See error above",variant:"destructive"})}finally{I(!1)}},A=async()=>{const s=x.trim();if(!s)return;const t=`session-${Date.now()}`;T(!0);try{await j(t,!1,s)?(D(s),setTimeout(()=>h(),150),u(""),l({title:"Started in background",description:`${t}`,action:e.jsx(G,{altText:"Open session",onClick:()=>m(`/terminal/${t}`),children:"Open"})})):l({title:"Failed to start",description:"See error above",variant:"destructive"})}finally{T(!1)}},P=async s=>{await B(s)?(l({title:"Session closed",description:s}),setTimeout(()=>h(),100)):l({title:"Failed to close session",description:s,variant:"destructive"})},F=()=>{const s=c.every(a=>d[a.id]),t={};c.forEach(a=>{t[a.id]=!s}),y(t)},z=c.length>0&&c.every(s=>d[s.id]);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Terminal"}),e.jsx("p",{className:"text-muted-foreground hidden sm:block",children:"Manage terminal sessions"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(r,{variant:"outline",onClick:()=>h(),disabled:o,children:[e.jsx(Y,{className:`h-4 w-4 sm:mr-2 ${o?"animate-spin":""}`}),e.jsx("span",{className:"hidden sm:inline",children:"Refresh"})]}),c.length>0&&e.jsx(r,{variant:"outline",onClick:F,children:z?e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Hide All"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Show All"})]})}),e.jsxs(r,{onClick:R,disabled:o,children:[e.jsx(S,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"New Terminal"})]})]})]}),k&&e.jsx("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsx("div",{className:"text-red-600",children:k})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Sessions"}),o?e.jsx("div",{className:"space-y-2",children:[...Array(2)].map((s,t)=>e.jsx(f,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-4 w-4 rounded bg-muted animate-pulse"}),e.jsxs("div",{children:[e.jsx("div",{className:"h-4 w-40 bg-muted rounded animate-pulse mb-2"}),e.jsx("div",{className:"h-3 w-24 bg-muted rounded animate-pulse"})]})]}),e.jsx("div",{className:"h-6 w-20 bg-muted rounded animate-pulse"})]})},t))}):c.length===0?e.jsx(f,{className:"p-8",children:e.jsxs("div",{className:"flex flex-col items-center justify-center text-center space-y-3",children:[e.jsx(S,{className:"h-12 w-12 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg mb-2",children:"No active sessions"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Get started by launching a new terminal session with the"," ",e.jsx("button",{onClick:R,className:"text-primary hover:underline font-medium",children:"New Terminal"})," ","button above."]})]})]})}):e.jsx("div",{className:"space-y-2",children:c.slice(0,10).map(s=>e.jsxs(f,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(S,{className:"h-4 w-4"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.proposalId}),e.jsxs("div",{className:"text-xs text-gray-500",children:["Session ",s.id.split("-").slice(-1)[0].substring(0,8)," • Last activity ",O(s.lastActivity)]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2",children:[e.jsx("div",{className:`flex items-center gap-1 ${s.connected?"text-green-600":"text-gray-400"}`,title:s.connected?"Connected":"Disconnected",children:e.jsx("div",{className:`w-2 h-2 rounded-full ${s.connected?"bg-green-500":"bg-gray-400"}`})}),e.jsx(r,{size:"sm",variant:"outline",onClick:()=>{y(t=>({...t,[s.id]:!t[s.id]}))},"aria-label":d[s.id]?"Hide preview":"Show preview",title:d[s.id]?"Hide preview":"Show preview",children:d[s.id]?e.jsx(K,{className:"h-4 w-4"}):e.jsx(L,{className:"h-4 w-4"})}),e.jsxs(r,{size:"sm",variant:"outline",onClick:()=>m(`/terminal/${s.proposalId}`),children:[e.jsx(M,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Open"})]}),e.jsx(r,{size:"icon",variant:"destructive",onClick:()=>P(s.id),title:"Close session","aria-label":"Close session",children:e.jsx(q,{className:"h-4 w-4"})})]})]}),d[s.id]&&e.jsx("div",{className:"mt-2 w-full p-2 cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>m(`/terminal/${s.proposalId}`),title:"Click to open full terminal session",children:e.jsx(V,{sessionId:s.id,heightPx:160,maxScrollback:200})})]},s.id))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Run Custom Command"}),e.jsx(f,{children:e.jsxs(W,{className:"py-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{value:x,onChange:s=>u(s.target.value),onKeyDown:s=>{s.key==="Enter"?(s.preventDefault(),s.shiftKey?A():E()):s.key==="ArrowUp"?(s.preventDefault(),w(t=>{const a=t===null?0:Math.min((t??0)+1,N.length-1),n=N[a];return n&&u(n),a})):s.key==="ArrowDown"&&(s.preventDefault(),w(t=>{if(t===null)return null;const a=t-1;if(a<0)return u(""),null;const n=N[a];return n&&u(n),a}))},placeholder:"npm run dev",className:"flex-1 h-9 rounded-md border px-3 text-sm bg-white dark:bg-gray-900 border-gray-300 dark:border-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-500 dark:placeholder-gray-400"}),e.jsxs(r,{onClick:A,variant:"secondary",disabled:o||!x.trim()||v||g,children:[v?e.jsx(H,{className:"h-4 w-4 animate-spin sm:mr-1"}):e.jsx(Z,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Background"})]}),e.jsxs(r,{onClick:E,disabled:o||!x.trim()||g||v,children:[g?e.jsx(H,{className:"h-4 w-4 animate-spin sm:mr-2"}):e.jsx(M,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Run"})]})]}),e.jsx("div",{className:"text-xs text-muted-foreground mt-2",children:"Enter to Run • Shift+Enter to Run in background"})]})})]})]})}export{oe as default};
@@ -0,0 +1,13 @@
1
+ import{c as Ge,j as e,B as C,a5 as Ee,a6 as Le,a7 as Pe,a8 as We,a9 as Me,aa as Ze,p as oe,r as n,ab as Ye,E as Ke,l as Xe,u as Qe,H as et,k as ue,a3 as je,ac as Be,v as ye,w as ve,x as we,y as Ne,z as H,X as Oe,ad as tt,i as _e,h as Ie,s as ke,D as rt,a as st,b as nt,d as at,ae as ze,A as ce}from"./index-B8vejVRZ.js";import{C as it,a as ot}from"./card-CvaBJsG6.js";import{B as De}from"./badge-NJasrAx_.js";import{R as ct,a as Ce}from"./radio-group-DpJuX02X.js";import{C as lt}from"./CollapsibleSection-DaqBpCe-.js";import{L as he}from"./label-DtNTh--4.js";import{u as dt}from"./use-terminal-2DGl8X5T.js";import{x as mt,a as ut}from"./xterm-DTxiCjtJ.js";import{A as ht}from"./arrow-down-5CQhXptz.js";import{b as Fe,a as xt,c as gt,d as ft}from"./droid-CmYuCN_q.js";import{R as pt}from"./refresh-cw-CnHMzcH3.js";import{P as Se}from"./play-a8BsF4gF.js";import{P as Ae}from"./plus-Bon5P_OK.js";import{Z as bt}from"./zap-C0eIGEl_.js";/**
2
+ * @license lucide-react v0.542.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const jt=[["path",{d:"M10 2v8l3-3 3 3V2",key:"sqw3rj"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}]],yt=Ge("book-marked",jt);/**
7
+ * @license lucide-react v0.542.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const vt=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]],Ue=Ge("message-square",vt);var Te={exports:{}},Je;function wt(){return Je||(Je=1,(function(r,E){(function(R,j){r.exports=j()})(self,(()=>(()=>{var R={6:(d,w)=>{function x(c){try{const i=new URL(c),o=i.password&&i.username?`${i.protocol}//${i.username}:${i.password}@${i.host}`:i.username?`${i.protocol}//${i.username}@${i.host}`:`${i.protocol}//${i.host}`;return c.toLocaleLowerCase().startsWith(o.toLocaleLowerCase())}catch{return!1}}Object.defineProperty(w,"__esModule",{value:!0}),w.LinkComputer=w.WebLinkProvider=void 0,w.WebLinkProvider=class{constructor(c,i,o,u={}){this._terminal=c,this._regex=i,this._handler=o,this._options=u}provideLinks(c,i){const o=S.computeLink(c,this._regex,this._terminal,this._handler);i(this._addCallbacks(o))}_addCallbacks(c){return c.map((i=>(i.leave=this._options.leave,i.hover=(o,u)=>{if(this._options.hover){const{range:f}=i;this._options.hover(o,u,f)}},i)))}};class S{static computeLink(i,o,u,f){const J=new RegExp(o.source,(o.flags||"")+"g"),[h,m]=S._getWindowedLineStrings(i-1,u),A=h.join("");let N;const L=[];for(;N=J.exec(A);){const W=N[0];if(!x(W))continue;const[D,k]=S._mapStrIdx(u,m,0,N.index),[K,V]=S._mapStrIdx(u,D,k,W.length);if(D===-1||k===-1||K===-1||V===-1)continue;const B={start:{x:k+1,y:D+1},end:{x:V,y:K+1}};L.push({range:B,text:W,activate:f})}return L}static _getWindowedLineStrings(i,o){let u,f=i,J=i,h=0,m="";const A=[];if(u=o.buffer.active.getLine(i)){const N=u.translateToString(!0);if(u.isWrapped&&N[0]!==" "){for(h=0;(u=o.buffer.active.getLine(--f))&&h<2048&&(m=u.translateToString(!0),h+=m.length,A.push(m),u.isWrapped&&m.indexOf(" ")===-1););A.reverse()}for(A.push(N),h=0;(u=o.buffer.active.getLine(++J))&&u.isWrapped&&h<2048&&(m=u.translateToString(!0),h+=m.length,A.push(m),m.indexOf(" ")===-1););}return[A,f]}static _mapStrIdx(i,o,u,f){const J=i.buffer.active,h=J.getNullCell();let m=u;for(;f;){const A=J.getLine(o);if(!A)return[-1,-1];for(let N=m;N<A.length;++N){A.getCell(N,h);const L=h.getChars();if(h.getWidth()&&(f-=L.length||1,N===A.length-1&&L==="")){const W=J.getLine(o+1);W&&W.isWrapped&&(W.getCell(0,h),h.getWidth()===2&&(f+=1))}if(f<0)return[o,N]}o++,m=0}return[o,m]}}w.LinkComputer=S}},j={};function y(d){var w=j[d];if(w!==void 0)return w.exports;var x=j[d]={exports:{}};return R[d](x,x.exports,y),x.exports}var v={};return(()=>{var d=v;Object.defineProperty(d,"__esModule",{value:!0}),d.WebLinksAddon=void 0;const w=y(6),x=/(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function S(c,i){const o=window.open();if(o){try{o.opener=null}catch{}o.location.href=i}else console.warn("Opening link blocked as opener could not be cleared")}d.WebLinksAddon=class{constructor(c=S,i={}){this._handler=c,this._options=i}activate(c){this._terminal=c;const i=this._options,o=i.urlRegex||x;this._linkProvider=this._terminal.registerLinkProvider(new w.WebLinkProvider(this._terminal,o,this._handler,i))}dispose(){this._linkProvider?.dispose()}}})(),v})()))})(Te)),Te.exports}var Nt=wt();const kt=[{label:"Save to knowledge base",command:"Save this to the knowledge base (.nut/context/knowledge/) using the following schema as reference .nut/.schema/knowledge.schema.md",description:"Save content to knowledge base with schema reference"},{label:"Update project document",command:"Update the project document (.nut/context/project.md) using the following schema as reference .nut/.schema/project.schema.md",description:"Update project.md using schema reference"},{label:"Update architecture document",command:"Update the architecture document (.nut/context/architecture.md) using the following schema as reference .nut/.schema/architecture.schema.md",description:"Update architecture.md using schema reference"}];function Ct({onJumpToBottom:r,onSnippet:E,onSendKey:R}){return e.jsxs("div",{className:"w-full border-t border-gray-700/50 bg-[#252525] px-4 py-2.5 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r&&e.jsxs(C,{variant:"outline",size:"sm",onClick:r,className:"h-8 text-xs bg-[#2d2d2d] border-gray-600 hover:bg-[#3d3d3d] text-gray-200 hover:text-white transition-colors",title:"Jump to bottom and set focus",children:[e.jsx(ht,{className:"h-3.5 w-3.5 sm:mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Jump to Bottom"})]}),E&&e.jsxs(Ee,{children:[e.jsx(Le,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",className:"h-8 text-xs bg-[#2d2d2d] border-gray-600 hover:bg-[#3d3d3d] text-gray-200 hover:text-white transition-colors",children:[e.jsx(yt,{className:"h-3.5 w-3.5 sm:mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Snippets"})]})}),e.jsxs(Pe,{align:"start",className:"w-72",children:[e.jsx(We,{children:"Command Snippets"}),e.jsx(Me,{}),kt.map((j,y)=>e.jsxs(Ze,{onClick:()=>E(j.command),className:"cursor-pointer flex flex-col items-start py-2",children:[e.jsx("span",{className:"font-medium",children:j.label}),e.jsx("span",{className:"text-xs text-muted-foreground font-mono mt-0.5",children:j.command})]},y))]})]})]}),R&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{onClick:()=>R(""),className:"h-8 px-2 flex items-center gap-1 rounded-md bg-[#2d2d2d] border border-gray-600 hover:bg-red-900/40 hover:border-red-700 text-gray-200 hover:text-red-300 transition-colors",title:"Send Ctrl+C (interrupt)",children:[e.jsx(oe,{className:"bg-gray-700/50 border-gray-600 text-gray-300",children:"⌃"}),e.jsx(oe,{className:"bg-gray-700/50 border-gray-600 text-gray-300",children:"C"})]}),e.jsxs("button",{onClick:()=>R(""),className:"h-8 px-2 flex items-center gap-1 rounded-md bg-[#2d2d2d] border border-gray-600 hover:bg-[#3d3d3d] hover:border-gray-500 text-gray-200 hover:text-white transition-colors",title:"Send Ctrl+Z (suspend)",children:[e.jsx(oe,{className:"bg-gray-700/50 border-gray-600 text-gray-300",children:"⌃"}),e.jsx(oe,{className:"bg-gray-700/50 border-gray-600 text-gray-300",children:"Z"})]}),e.jsx("button",{onClick:()=>R("\x1B"),className:"h-8 px-2 flex items-center gap-1 rounded-md bg-[#2d2d2d] border border-gray-600 hover:bg-[#3d3d3d] hover:border-gray-500 text-gray-200 hover:text-white transition-colors",title:"Send Escape key",children:e.jsx(oe,{className:"bg-gray-700/50 border-gray-600 text-gray-300",children:"Esc"})})]})]})}function St({sessionId:r,onResize:E,onDestroy:R,pendingCommand:j,onCommandExecuted:y,showToolbar:v=!0,onSnippet:d}){const w=n.useRef(null),x=n.useRef(null),S=n.useRef(null),c=n.useRef(null),[i,o]=n.useState(!1),[u,f]=n.useState(null),[J,h]=n.useState(!0),m=n.useRef(0),A=5,N=n.useRef(null),L=n.useRef(null),W=n.useRef(j??null),D=n.useRef(!1),k=n.useRef(null),K=n.useRef(y),V=n.useRef(R),B=n.useRef(E);n.useEffect(()=>{K.current=y},[y]),n.useEffect(()=>{V.current=R},[R]),n.useEffect(()=>{B.current=E},[E]);const X=n.useCallback(P=>{!W.current||D.current||(k.current!==null&&window.clearTimeout(k.current),k.current=window.setTimeout(()=>{if(!W.current||D.current){k.current=null;return}c.current?.readyState===WebSocket.OPEN&&(c.current.send(JSON.stringify({type:"input",data:W.current+"\r"})),D.current=!0,K.current?.()),k.current=null},P))},[]);n.useEffect(()=>{if(W.current=j??null,D.current=!1,!W.current){k.current!==null&&(window.clearTimeout(k.current),k.current=null);return}const P=c.current?.readyState===WebSocket.OPEN;return X(P?200:800),()=>{k.current!==null&&(window.clearTimeout(k.current),k.current=null)}},[j,r,X]),n.useEffect(()=>{o(!1),h(!0),f(null)},[r]),n.useEffect(()=>{if(!w.current||!r)return;const P=g=>{const b=g.getBoundingClientRect();return b.width>0&&b.height>0},p=new mt.Terminal({cursorBlink:!0,fontSize:14,fontFamily:'Monaco, Menlo, "Ubuntu Mono", monospace',convertEol:!0,theme:{background:"#1e1e1e",foreground:"#d4d4d4",cursor:"#ffffff",selectionBackground:"#264f78",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#e5e5e5"}}),re=new ut.FitAddon,M=new Nt.WebLinksAddon;p.loadAddon(re),p.loadAddon(M),p.open(w.current),x.current=p,S.current=re;let _=null,F=null;const le=()=>{if(!p||!p.element||!p.element.parentElement)return;const g=p.cols??0,b=p.rows??0;if(g>0&&b>0){c.current?.readyState===WebSocket.OPEN&&c.current.send(JSON.stringify({type:"resize",cols:g,rows:b}));const $=B.current;$&&$(g,b)}},I=()=>{const g=w.current;if(g&&P(g)&&!(!p||!p.element||!p.element.parentElement))try{const b=g.getBoundingClientRect();if(b.width<10||b.height<10)return;re.fit(),le()}catch(b){console.warn("xterm fit() failed, will retry if needed:",b)}},Z=()=>{_&&cancelAnimationFrame(_),_=requestAnimationFrame(()=>{I()})},ee=()=>{if(!r)return;N.current&&(window.clearTimeout(N.current),N.current=null);const g=`${Ye}/ws/terminal/${r}`,b=new WebSocket(g);return c.current=b,b.onopen=()=>{o(!0),f(null),m.current=0,console.log("Terminal WebSocket connected"),L.current&&window.clearInterval(L.current),L.current=window.setInterval(()=>{b.readyState===WebSocket.OPEN&&b.send(JSON.stringify({type:"keepalive"}))},120*1e3),Z(),setTimeout(()=>{h(!1),Z(),setTimeout(()=>Z(),50),setTimeout(()=>Z(),150)},400),X(1200)},b.onmessage=$=>{try{const z=JSON.parse($.data);switch(z.type){case"snapshot":if(typeof z.data=="string"&&z.data.length&&x.current){const T=x.current;T.write(z.data,()=>{T.scrollToBottom()})}break;case"data":if(x.current){const T=x.current,fe=T.buffer.active.viewportY+T.rows>=T.buffer.active.baseY+T.buffer.active.cursorY;T.write(z.data,()=>{fe&&T.scrollToBottom()})}break;case"exit":x.current&&x.current.write(`\r
12
+ \x1B[31mProcess exited with code ${z.exitCode}\x1B[0m\r
13
+ `),V.current?.();break}}catch(z){console.error("Error parsing WebSocket message:",z)}},b.onclose=$=>{if(o(!1),console.log("Terminal WebSocket disconnected",$.code,$.reason),L.current&&(window.clearInterval(L.current),L.current=null),$.code!==1e3&&m.current<A&&r){m.current++;const z=Math.min(1e3*Math.pow(2,m.current-1),1e4);console.log(`Attempting to reconnect (${m.current}/${A}) in ${z}ms`),N.current=window.setTimeout(()=>{ee()},z)}else m.current>=A&&f("Connection lost. Please refresh the page to reconnect.")},b.onerror=$=>{console.error("Terminal WebSocket error:",$),m.current===0&&f("WebSocket connection failed")},b};ee(),p.onData(g=>{c.current?.readyState===WebSocket.OPEN&&c.current.send(JSON.stringify({type:"input",data:g}))});const Q=()=>{Z()},ge=new ResizeObserver(Q);w.current&&ge.observe(w.current),window.addEventListener("resize",Q),window.addEventListener("orientationchange",Q);const de=()=>{document.visibilityState==="visible"&&(F&&clearTimeout(F),F=window.setTimeout(()=>{Z()},50))};document.addEventListener("visibilitychange",de);let se=0;const me=20,ne=()=>{const g=w.current;if(g){if(P(g)){I();return}se+=1,se<me?_=requestAnimationFrame(ne):F=window.setTimeout(()=>{I()},100)}};return _=requestAnimationFrame(ne),()=>{ge.disconnect(),window.removeEventListener("resize",Q),window.removeEventListener("orientationchange",Q),document.removeEventListener("visibilitychange",de),_&&cancelAnimationFrame(_),F&&clearTimeout(F),N.current&&(window.clearTimeout(N.current),N.current=null),L.current&&(window.clearInterval(L.current),L.current=null),c.current?.readyState===WebSocket.OPEN&&c.current.close(),k.current!==null&&(window.clearTimeout(k.current),k.current=null),p.dispose()}},[r,X]);const q=n.useCallback(()=>{x.current&&(x.current.scrollToBottom(),x.current.focus())},[]),xe=n.useCallback(P=>{c.current?.readyState===WebSocket.OPEN&&(c.current.send(JSON.stringify({type:"input",data:P})),x.current&&x.current.focus())},[]),O=n.useCallback(P=>{c.current?.readyState===WebSocket.OPEN&&(c.current.send(JSON.stringify({type:"input",data:P})),x.current&&x.current.focus())},[]);return u?e.jsx("div",{className:"flex items-center justify-center h-full bg-red-50 border border-red-200 rounded-lg",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-red-600 font-medium",children:"Terminal Connection Error"}),e.jsx("div",{className:"text-red-500 text-sm mt-1",children:u})]})}):e.jsxs("div",{className:"relative h-full flex flex-col bg-[#1e1e1e] overflow-hidden",children:[!i&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-[#1e1e1e] bg-opacity-95 z-10 backdrop-blur-sm",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500 mx-auto"}),e.jsx("div",{className:"text-gray-300 mt-2",children:"Connecting to terminal..."})]})}),i&&J&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-[#1e1e1e] bg-opacity-50 z-10 transition-opacity duration-300 backdrop-blur-sm",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-pulse rounded-full h-6 w-6 bg-blue-500 mx-auto"}),e.jsx("div",{className:"text-gray-300 text-sm mt-2",children:"Loading terminal..."})]})}),e.jsx("div",{ref:w,className:"flex-1 w-full overflow-hidden",style:{minHeight:"400px"}}),v&&e.jsx(Ct,{onJumpToBottom:q,onSnippet:d||xe,onSendKey:O})]})}const At=r=>r?Array.isArray(r)?r.filter(E=>typeof E=="string").map(E=>E.trim()).filter(Boolean):typeof r=="string"?r.split(",").map(E=>E.trim()).filter(Boolean):[]:[];function Ut(){const{proposalId:r}=Ke(),E=Xe(),R=Qe(),{toast:j}=et(),y=r?.startsWith("session-"),v=n.useMemo(()=>!!r&&r.startsWith("cp-"),[r]),d=n.useMemo(()=>!!r&&r.startsWith("ag-"),[r]),w=n.useMemo(()=>d&&r?r.replace("ag-","")+".md":null,[d,r]),{sessions:x,loading:S,error:c,createSession:i,destroySession:o,refreshSessions:u}=dt(),[f,J]=n.useState([]),[h,m]=n.useState(null),[A,N]=n.useState(!1),[L,W]=n.useState(null),[D,k]=n.useState("claude"),[K,V]=n.useState(!1),[B,X]=n.useState("claude"),[q,xe]=n.useState([]),[O,P]=n.useState([]),[p,re]=n.useState([]),[M,_]=n.useState([]),[F,le]=n.useState(!1),[I,Z]=n.useState(""),[ee,Q]=n.useState(!1),[ge,de]=n.useState({}),[se,me]=n.useState(null),ne=n.useRef([]),[g,b]=n.useState("current"),[$,z]=n.useState("main"),T=n.useMemo(()=>r?`terminal.cp.config.${r}`:null,[r]);n.useEffect(()=>{if(!(!v&&!d||!T))try{const t=localStorage.getItem(T);if(t){const s=JSON.parse(t);s.cliAgent&&X(s.cliAgent),Array.isArray(s.selectedMcpServers)&&P(s.selectedMcpServers),Array.isArray(s.selectedAgentIds)&&_(s.selectedAgentIds),typeof s.automationEnabled=="boolean"&&le(s.automationEnabled),typeof s.customInstruction=="string"&&Z(s.customInstruction),typeof s.createWorktree=="boolean"&&Q(s.createWorktree),s.branchMode&&b(s.branchMode)}}catch{console.error("Failed to load config",T)}},[v,d,T]);const fe=n.useCallback(()=>{if(!T)return;const t={cliAgent:B,selectedMcpServers:O,selectedAgentIds:M,automationEnabled:F,customInstruction:I,createWorktree:ee,branchMode:g};try{localStorage.setItem(T,JSON.stringify(t))}catch{console.error("Failed to persist config",T)}},[T,B,O,M,F,I,ee,g]),te=t=>`feat/cp-${t.startsWith("cp-")?t.slice(3):t}`,Ve=async t=>{try{const s=te(t),l=await(await fetch(`${ce}/api/v1/git/branches`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s,from:$})})).json();if(!l.success){const U=l.error?.message||"Unknown error";return j({title:"Branch creation failed",description:U,variant:"destructive"}),!1}return j({title:"Branch created",description:`Created branch: ${s}`}),!0}catch{return j({title:"Branch creation failed",description:"Network error or invalid response",variant:"destructive"}),!1}},Re=async t=>{try{const s=te(t),l=await(await fetch(`${ce}/api/v1/git/worktrees`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branch:s,from:$})})).json();if(!l.success){const U=l.error?.message||"Unknown error";return j({title:"Worktree creation failed",description:U,variant:"destructive"}),!1}return j({title:"Worktree created",description:`Created branch: ${s}`}),!0}catch{return j({title:"Worktree creation failed",description:"Network error or invalid response",variant:"destructive"}),!1}};n.useEffect(()=>{(v||d)&&r&&(async()=>{try{const s=await fetch(`${ce}/api/v1/git/status`);if(s.ok){const l=await s.json();l?.success&&l.data?.branch&&z(l.data.branch)}const a=await fetch(`${ce}/api/v1/mcp`);if(a.ok){const l=await a.json();l?.success&&Array.isArray(l.servers)&&(xe(l.servers),P(U=>U.filter(G=>l.servers.includes(G))),l.mcpServers&&typeof l.mcpServers=="object"&&de(l.mcpServers))}}catch(s){console.error("Failed to load MCP servers",s)}try{const s=await fetch(`${ce}/api/v1/agents`);if(s.ok){const a=await s.json(),U=(Array.isArray(a?.documents)?a.documents:[]).map(G=>({id:G.filename,name:G?.metadata?.name||G.title||G.filename,tools:At(G?.metadata?.tools)}));re(U),_(G=>{const ie=G.filter(Y=>U.some(be=>be.id===Y));if(d&&w&&ie.length===0){const Y=U.find(be=>be.id===w);if(Y)return[Y.id]}return ie})}}catch(s){console.error("Failed to load agents",s)}})()},[v,d,r,w]),n.useEffect(()=>{const t=ne.current,s=M.filter(a=>!t.includes(a));s.length>0&&P(a=>{const l=new Set(a),U=q.length>0?new Set(q):void 0;return s.forEach(G=>{const ie=p.find(Y=>Y.id===G);ie&&ie.tools.forEach(Y=>{(!U||U.has(Y))&&l.add(Y)})}),Array.from(l)}),ne.current=M},[M,p,q]),n.useEffect(()=>{r&&u(r)},[r,u]),n.useEffect(()=>{if(!r)return;const s=x.filter(a=>a.proposalId===r).map(a=>a.id);J(s),!h&&s.length>0&&m(s[0]),h&&!s.includes(h)&&m(s.length>0?s[0]:null)},[x,r,h]);const ae=async t=>{if(!r)return;const s=t||void 0,a=await i(r,A,s);a&&(m(a),!s&&t&&W(t),setTimeout(()=>u(r),100))},qe=t=>{const a={proposalId:r,contextType:v?"change-proposal":d?"agent":"general",selectedMcpServers:O,selectedAgentIds:M,automationEnabled:F,customInstruction:I};switch(t){case"claude":return Fe(a);case"gemini":return ft(a);case"codex":return gt(a);case"droid":return xt(a);default:return Fe(a)}},pe=async()=>{v&&r&&(g==="new-branch"?await Ve(r)||console.warn("Branch creation failed, continuing with terminal creation"):g==="new-worktree"&&(await Re(r)||console.warn("Worktree creation failed, continuing with terminal creation"))),v&&ee&&g==="current"&&r&&(await Re(r)||console.warn("Worktree creation failed, continuing with terminal creation"));const s=qe(v||d?B:D);await ae(s)},$e=async t=>{if(await o(t)&&h===t){const a=f.filter(l=>l!==t);m(a.length>0?a[0]:null)}},He=t=>{$e(t)};return r?e.jsxs("div",{className:"flex flex-col h-full",children:[y&&f.length===0&&r&&e.jsx(Tt,{proposalId:r,onStart:ae,locationSearch:E.search}),e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 bg-gray-100 dark:bg-gray-800 rounded-lg",children:v||d?e.jsx(ue,{className:"h-5 w-5 text-gray-600 dark:text-gray-400"}):e.jsx(je,{className:"h-5 w-5 text-gray-600 dark:text-gray-400"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:y?"Terminal":"Coding Agent Session"}),!y&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 font-mono",children:r}),y&&e.jsxs("span",{className:"text-sm text-gray-500 font-mono",children:["(",r,")"]})]})]})}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsxs("div",{className:"hidden sm:flex items-center space-x-2 px-3 py-2 bg-gray-50 dark:bg-gray-800 rounded-lg border",children:[e.jsx(Be,{id:"enable-logging",checked:A,onCheckedChange:t=>N(t===!0)}),e.jsx("label",{htmlFor:"enable-logging",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Log sessions"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>r&&u(r),disabled:S,className:"bg-white dark:bg-gray-800",children:[e.jsx(pt,{className:`h-4 w-4 sm:mr-2 ${S?"animate-spin":""}`}),e.jsx("span",{className:"hidden sm:inline",children:"Refresh"})]}),!y&&!v&&!d&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(ye,{value:D,onValueChange:k,children:[e.jsx(ve,{className:"w-24",children:e.jsx(we,{})}),e.jsxs(Ne,{children:[e.jsx(H,{value:"claude",children:"Claude Code"}),e.jsx(H,{value:"gemini",children:"Google Gemini"}),e.jsx(H,{value:"codex",children:"OpenAI Codex"})]})]}),e.jsxs(C,{onClick:pe,disabled:S,size:"sm",variant:"default",className:"bg-green-600 hover:bg-green-700",children:[e.jsx(Se,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Start Coding"})]})]}),!v&&!d&&(!y||f.length===0)&&e.jsxs(C,{onClick:()=>ae(),disabled:S,size:"sm",children:[e.jsx(Ae,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"New Terminal"})]})]})]})]}),c&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-xl",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-1.5 bg-red-100 dark:bg-red-900/40 rounded-lg flex-shrink-0",children:e.jsx(Oe,{className:"h-4 w-4 text-red-600 dark:text-red-400"})}),e.jsx("div",{className:"text-red-800 dark:text-red-200 text-sm font-medium",children:c})]})}),f.length>0&&e.jsx("div",{className:"flex items-center gap-1 border-b dark:border-gray-700",children:f.map(t=>{const s=x.find(l=>l.id===t),a=h===t;return e.jsxs("div",{className:`flex items-center gap-2 px-4 py-3 border-b-1 cursor-pointer rounded-t-lg transition-all duration-200 ${a?"border-gray-400 bg-white dark:bg-gray-800 dark:border-gray-500 shadow-sm":"border-transparent hover:bg-gray-50 dark:hover:bg-gray-800 hover:border-gray-300"}`,onClick:()=>m(t),children:[e.jsx("div",{className:`p-1.5 rounded-md ${a?"bg-gray-200 dark:bg-gray-700":"bg-gray-100 dark:bg-gray-700"}`,children:e.jsx(je,{className:`h-3.5 w-3.5 ${a?"text-gray-700 dark:text-gray-300":"text-gray-600 dark:text-gray-400"}`})}),e.jsxs("span",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:["Terminal ",t.split("-").slice(-1)[0].substring(0,6)]}),e.jsx("div",{className:`w-2 h-2 rounded-full flex-shrink-0 ${s?.connected?"bg-green-500":"bg-gray-400"}`}),e.jsx(C,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 hover:bg-red-100 dark:hover:bg-red-900/30 rounded-md opacity-60 hover:opacity-100 transition-opacity",onClick:l=>{l.stopPropagation(),$e(t)},children:e.jsx(Oe,{className:"h-3 w-3"})})]},t)})}),e.jsx("div",{className:"flex-1 min-h-0",children:f.length===0?e.jsx(it,{className:"h-full border-0 shadow-lg",children:e.jsx(ot,{className:"flex items-center justify-center h-full p-8",children:e.jsxs("div",{className:"text-center w-full max-w-[33vw] min-w-[400px]",children:[e.jsx("div",{className:"p-2 bg-gray-100 dark:bg-gray-800 rounded-full w-fit mx-auto mb-2",children:v||d?e.jsx(ue,{className:"h-8 w-8 text-gray-600 dark:text-gray-400"}):e.jsx(je,{className:"h-8 w-8 text-gray-600 dark:text-gray-400"})}),e.jsx("h3",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100 mb-3",children:"Prepare Coding Agent"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6 leading-relaxed",children:y?"Create a new terminal session":`Configure the agent to start working on ${r}.`}),e.jsxs("div",{className:"flex flex-col items-center gap-6",children:[!y&&!v&&!d&&e.jsxs("div",{className:"flex flex-col items-center gap-4 p-6 border border-gray-200 dark:border-gray-700 rounded-xl shadow-sm bg-gradient-to-br from-white to-gray-50 dark:from-gray-800 dark:to-gray-900 w-full",children:[e.jsxs("div",{className:"w-full space-y-3",children:[e.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Choose your AI agent"}),e.jsxs(ye,{value:D,onValueChange:k,children:[e.jsx(ve,{className:"w-full h-11 bg-white dark:bg-gray-800",children:e.jsx(we,{})}),e.jsxs(Ne,{children:[e.jsx(H,{value:"claude",children:"Claude Code (default)"}),e.jsx(H,{value:"gemini",children:"Google Gemini"}),e.jsx(H,{value:"codex",children:"OpenAI Codex"})]})]})]}),e.jsxs(C,{onClick:pe,disabled:S,className:"bg-green-600 hover:bg-green-700 w-full h-11 text-base font-medium",size:"lg",children:[e.jsx(Se,{className:"h-5 w-5 mr-2"}),"Start Coding"]}),e.jsxs("div",{className:"flex items-center gap-3 w-full",children:[e.jsx("div",{className:"flex-1 h-px bg-gray-300 dark:bg-gray-600"}),e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400 font-medium",children:"or"}),e.jsx("div",{className:"flex-1 h-px bg-gray-300 dark:bg-gray-600"})]}),e.jsxs(C,{onClick:()=>ae(),disabled:S,variant:"outline",className:"w-full h-11 bg-white dark:bg-gray-800",size:"lg",children:[e.jsx(Ae,{className:"h-5 w-5 mr-2"}),"New Terminal"]})]}),!y&&(v||d)&&e.jsxs("div",{className:"flex flex-col items-center gap-4 p-6 border border-gray-200 dark:border-gray-700 rounded-xl shadow-sm bg-gradient-to-br from-white to-gray-50 dark:from-gray-800 dark:to-gray-900 w-full",children:[e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsxs(C,{variant:"outline",onClick:()=>V(!0),className:"flex-1 h-11 bg-white dark:bg-gray-800",size:"lg",children:[e.jsx(tt,{className:"h-5 w-5 mr-2"}),"Configure"]}),e.jsxs(C,{onClick:pe,disabled:S,className:"flex-1 bg-green-600 hover:bg-green-700 h-11 text-base font-medium",size:"lg",children:[e.jsx(Se,{className:"h-5 w-5 mr-2"}),"Start Coding"]})]}),e.jsxs("div",{className:"w-full space-y-3",children:[e.jsx("div",{className:"text-xs uppercase font-semibold text-gray-500 dark:text-gray-400",children:"Current Configuration"}),e.jsxs("div",{className:"text-left text-sm text-gray-700 dark:text-gray-300 bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ue,{className:"h-3.5 w-3.5 text-gray-500 dark:text-gray-400"}),e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-400",children:"Coding Agent:"}),e.jsx("span",{className:"font-mono text-sm",children:B==="claude"?"Claude Code":B.charAt(0).toUpperCase()+B.slice(1)})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(_e,{className:"h-3.5 w-3.5 text-gray-500 dark:text-gray-400 mt-0.5"}),e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-400",children:"Custom Agents:"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:M.length?M.map(t=>{const s=p.find(a=>a.id===t);return e.jsx(De,{variant:"secondary",className:"font-mono text-xs",children:s?.name||t},t)}):e.jsx("span",{className:"font-mono text-sm text-gray-500",children:"None"})})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ie,{className:"h-3.5 w-3.5 text-gray-500 dark:text-gray-400 mt-0.5"}),e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-400",children:"MCP Servers:"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:O.length?O.map(t=>e.jsx(De,{variant:"secondary",className:"font-mono text-xs",children:t},t)):e.jsx("span",{className:"font-mono text-sm text-gray-500",children:"None"})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(bt,{className:"h-3.5 w-3.5 text-gray-500 dark:text-gray-400"}),e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-400",children:"Automation:"}),e.jsx("span",{className:"font-mono text-sm",children:F?"Enabled":"Disabled"})]}),v&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"h-3.5 w-3.5 text-gray-500 dark:text-gray-400"}),e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-400",children:"Branch:"}),e.jsx("span",{className:"font-mono text-sm",children:g==="current"?`Current (${$})`:g==="new-branch"?`New branch (${te(r||"")})`:`New worktree (${te(r||"")})`})]})]}),I&&e.jsxs("div",{className:"text-left text-sm bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:[e.jsxs("div",{className:"font-medium text-blue-700 dark:text-blue-300 mb-1 flex items-center gap-2",children:[e.jsx(Ue,{className:"h-3.5 w-3.5"}),"Custom Instructions"]}),e.jsx("div",{className:"text-gray-700 dark:text-gray-300 font-mono",children:I})]})]})]}),y&&f.length===0&&e.jsx("div",{className:"p-6 border border-gray-200 dark:border-gray-700 rounded-xl shadow-sm bg-gradient-to-br from-white to-gray-50 dark:from-gray-800 dark:to-gray-900 w-full",children:e.jsxs(C,{onClick:()=>ae(),disabled:S,className:"w-full h-11 text-base font-medium",size:"lg",children:[e.jsx(Ae,{className:"h-5 w-5 mr-2"}),"New Terminal"]})})]})]})})}):h?e.jsx("div",{className:"h-full overflow-hidden rounded-b-lg",children:e.jsx(St,{sessionId:h,onDestroy:()=>He(h),pendingCommand:L,onCommandExecuted:()=>W(null),showToolbar:!0})}):null}),e.jsx(rt,{open:K,onOpenChange:V,children:e.jsxs(st,{className:"max-w-3xl max-h-[85vh] overflow-y-auto",children:[e.jsxs(nt,{children:[e.jsx(at,{children:"Configure Coding Agent"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Customize the coding agent's capabilities and configure it's environment."})]}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(ue,{className:"h-4 w-4"}),"Coding Agent"]}),e.jsxs(ye,{value:B,onValueChange:t=>X(t),children:[e.jsx(ve,{className:"w-full",children:e.jsx(we,{placeholder:"Select coding agent"})}),e.jsxs(Ne,{children:[e.jsx(H,{value:"claude",children:"Claude Code"}),e.jsx(H,{value:"gemini",children:"Google Gemini"}),e.jsx(H,{value:"codex",children:"OpenAI Codex"}),e.jsx(H,{value:"droid",children:"Factory Droid"})]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(_e,{className:"h-4 w-4"}),"Custom Agents"]}),e.jsxs("div",{className:"text-xs text-gray-500",children:[M.length," of ",p.length," selected"]})]}),e.jsxs(Ee,{children:[e.jsx(Le,{asChild:!0,children:e.jsxs(C,{variant:"outline",className:"w-full justify-between",children:[M.length===0?"Select agents...":M.length===p.length?"All agents selected":`${M.length} agent${M.length!==1?"s":""} selected`,e.jsx(ke,{className:"h-4 w-4 opacity-50"})]})}),e.jsxs(Pe,{className:"w-full min-w-[--radix-dropdown-menu-trigger-width]",children:[e.jsxs(We,{className:"flex items-center justify-between",children:[e.jsx("span",{children:"Available Agents"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(C,{size:"sm",variant:"ghost",className:"h-5 px-1 text-xs",onClick:t=>{t.preventDefault(),_(p.map(s=>s.id))},children:"All"}),e.jsx(C,{size:"sm",variant:"ghost",className:"h-5 px-1 text-xs",onClick:t=>{t.preventDefault(),_([])},children:"None"})]})]}),e.jsx(Me,{}),p.length===0?e.jsx("div",{className:"px-2 py-1.5 text-sm text-gray-500",children:"No agents found"}):p.map(t=>e.jsx(ze,{checked:M.includes(t.id),onCheckedChange:s=>{_(a=>s?a.includes(t.id)?a:[...a,t.id]:a.filter(l=>l!==t.id))},children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:t.name}),t.tools.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["MCP servers: ",t.tools.join(", ")]}),t.tools.length===0&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"Inherits available MCP servers"})]})},t.id))]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4"}),"MCP Servers"]}),e.jsxs("div",{className:"text-xs text-gray-500",children:[O.length," of ",q.length," selected"]})]}),e.jsxs(Ee,{children:[e.jsx(Le,{asChild:!0,children:e.jsxs(C,{variant:"outline",className:"w-full justify-between",children:[O.length===0?"Select MCP servers...":O.length===q.length?"All servers selected":`${O.length} server${O.length!==1?"s":""} selected`,e.jsx(ke,{className:"h-4 w-4 opacity-50"})]})}),e.jsxs(Pe,{className:"w-full min-w-[--radix-dropdown-menu-trigger-width]",children:[e.jsxs(We,{className:"flex items-center justify-between",children:[e.jsx("span",{children:"Available Servers"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(C,{size:"sm",variant:"ghost",className:"h-5 px-1 text-xs",onClick:t=>{t.preventDefault(),P(q)},children:"All"}),e.jsx(C,{size:"sm",variant:"ghost",className:"h-5 px-1 text-xs",onClick:t=>{t.preventDefault(),P([])},children:"None"})]})]}),e.jsx(Me,{}),q.length===0?e.jsx("div",{className:"px-2 py-1.5 text-sm text-gray-500",children:"No MCP servers found"}):q.map(t=>e.jsx(ze,{checked:O.includes(t),onCheckedChange:s=>{P(a=>s?a.includes(t)?a:[...a,t]:a.filter(l=>l!==t))},children:t},t))]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Ue,{className:"h-4 w-4"}),"Additional instructions"]}),e.jsxs("div",{className:"text-xs text-gray-500",children:[I.length,"/500"]})]}),e.jsx("textarea",{className:"w-full min-h-[80px] rounded-md border p-3 text-sm bg-gray-50 dark:bg-gray-900/50 border-gray-300 dark:border-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-500 dark:placeholder-gray-400 resize-none",placeholder:"Add specific instructions to guide the coding agent...",value:I,onChange:t=>Z(t.target.value),rows:3}),I.length>500&&e.jsx("div",{className:"text-xs text-red-600 mt-1",children:"Custom instruction is too long (max 500 characters)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 border rounded-md bg-amber-50/50 dark:bg-amber-900/20 border-amber-200 dark:border-amber-800",children:[e.jsx(Be,{id:"automation",checked:F,onCheckedChange:t=>le(t===!0),className:"data-[state=checked]:bg-red-600 data-[state=checked]:border-red-600 data-[state=checked]:text-white border-red-400",disabled:B==="droid"}),e.jsx("label",{htmlFor:"automation",className:"text-sm font-medium text-red-600 dark:text-red-400 cursor-pointer",children:"Full environment access (recommended in containers only)"})]}),B==="droid"&&e.jsxs("p",{className:"text-xs text-muted-foreground px-1",children:[e.jsx("span",{className:"font-medium",children:"Droid:"})," Automation level is set in the REPL. Press ",e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded text-[10px] font-mono",children:"shift+tab"})," to cycle through Off → Low → Medium → High."]})]}),v&&e.jsx(lt,{title:"Advanced Settings",description:"Configure branch and worktree options",defaultOpen:!1,children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx(he,{className:"text-sm font-medium mb-3 block",children:"Branch Management"}),e.jsxs(ct,{value:g,onValueChange:t=>b(t),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ce,{value:"current",id:"branch-current"}),e.jsxs(he,{htmlFor:"branch-current",className:"cursor-pointer font-normal",children:["Stay on current branch (",e.jsx("code",{className:"text-xs font-mono bg-muted px-1 py-0.5 rounded",children:$}),")"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ce,{value:"new-branch",id:"branch-new"}),e.jsxs(he,{htmlFor:"branch-new",className:"cursor-pointer font-normal",children:["Create new branch: ",e.jsx("code",{className:"text-xs font-mono bg-muted px-1 py-0.5 rounded",children:te(r||"")})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ce,{value:"new-worktree",id:"branch-worktree"}),e.jsxs(he,{htmlFor:"branch-worktree",className:"cursor-pointer font-normal",children:["Create new worktree: ",e.jsx("code",{className:"text-xs font-mono bg-muted px-1 py-0.5 rounded",children:te(r||"")})]})]})]})]})})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(C,{variant:"outline",onClick:()=>V(!1),children:"Close"}),e.jsx(C,{onClick:()=>{if(I.length>500){me("Please shorten the custom instruction to 500 characters.");return}me(null),fe(),V(!1)},children:"Save"})]}),se&&e.jsx("div",{className:"text-xs text-red-600 text-right",children:se})]})]})})]}):e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-red-600 font-medium",children:"Invalid Proposal ID"}),e.jsx(C,{onClick:()=>R("/proposals"),className:"mt-4",children:"Back to Proposals"})]})})}function Tt({proposalId:r,onStart:E,locationSearch:R}){return n.useEffect(()=>{if(!r)return;const j=new URLSearchParams(R);if(!j.has("autostart"))return;const y=`terminal.autostart.${r}`;if(sessionStorage.getItem(y)==="done")return;sessionStorage.setItem(y,"done");const d=j.get("run")||void 0;E(d||void 0)},[r]),null}export{Ut as default};
@@ -0,0 +1 @@
1
+ import{r as n,H as k,aU as N,A as g,j as e,a1 as P,v as h,w as u,x as m,y as f,z as a,I as b,B as y}from"./index-B8vejVRZ.js";import{C as w,b as F,c as T,d as L,a as D}from"./card-CvaBJsG6.js";import{L as o}from"./label-DtNTh--4.js";const r={theme:"coconut",defaultEditor:"cursor",terminalShell:"bash",autoSaveInterval:60,notifications:{email:!1,desktop:!1,slack:!1}};function U(s){return{theme:s?.theme??r.theme,defaultEditor:s?.defaultEditor??r.defaultEditor,terminalShell:s?.terminalShell??r.terminalShell,autoSaveInterval:s?.autoSaveInterval??r.autoSaveInterval,notifications:{email:s?.notifications?.email??r.notifications.email,desktop:s?.notifications?.desktop??r.notifications.desktop,slack:s?.notifications?.slack??r.notifications.slack}}}function B(){const[s,v]=n.useState(r),[C,E]=n.useState(!0),[c,x]=n.useState(!1),{toast:d}=k(),{theme:j,setTheme:p}=N();n.useEffect(()=>{S()},[]),n.useEffect(()=>{s.theme!==j&&p(s.theme)},[s.theme,j,p]);const S=async()=>{try{const l=await(await fetch(`${g}/api/v1/user/settings`)).json();l.success&&v(U(l.data.preferences))}catch(t){console.error("Failed to load preferences:",t),d({title:"Error",description:"Failed to load user preferences",variant:"destructive"})}finally{E(!1)}},I=async()=>{x(!0);try{const l=await(await fetch(`${g}/api/v1/user/settings`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({preferences:s})})).json();if(l.success)d({title:"Preferences saved",description:"Your personal preferences have been updated."});else throw new Error(l.error)}catch(t){console.error("Failed to save preferences:",t),d({title:"Error",description:"Failed to save preferences",variant:"destructive"})}finally{x(!1)}},i=t=>{v(l=>({...l,...t,notifications:{...l.notifications,...t.notifications}}))};return C?e.jsx("div",{children:"Loading..."}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"User Preferences"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure defaults for editors, shells, themes, and notifications."})]}),e.jsx(P,{}),e.jsxs(w,{children:[e.jsxs(F,{children:[e.jsx(T,{children:"Workspace Defaults"}),e.jsx(L,{children:"Set the defaults Coconut uses when creating sessions and surfaces."})]}),e.jsxs(D,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"theme",children:"Theme"}),e.jsxs(h,{value:s.theme,onValueChange:t=>i({theme:t}),children:[e.jsx(u,{id:"theme",children:e.jsx(m,{placeholder:"Select theme"})}),e.jsxs(f,{children:[e.jsx(a,{value:"coconut",children:"Coconut"}),e.jsx(a,{value:"system",children:"System"}),e.jsx(a,{value:"light",children:"Light"}),e.jsx(a,{value:"dark",children:"Dark"})]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"System follows your OS preference. Coconut is the default branded theme."})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"defaultEditor",children:"Default Editor"}),e.jsxs(h,{value:s.defaultEditor,onValueChange:t=>i({defaultEditor:t}),children:[e.jsx(u,{id:"defaultEditor",children:e.jsx(m,{placeholder:"Select editor"})}),e.jsxs(f,{children:[e.jsx(a,{value:"cursor",children:"Cursor"}),e.jsx(a,{value:"vscode",children:"VS Code"}),e.jsx(a,{value:"vim",children:"Vim"}),e.jsx(a,{value:"emacs",children:"Emacs"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"terminalShell",children:"Preferred Shell"}),e.jsxs(h,{value:s.terminalShell,onValueChange:t=>i({terminalShell:t}),children:[e.jsx(u,{id:"terminalShell",children:e.jsx(m,{placeholder:"Select shell"})}),e.jsxs(f,{children:[e.jsx(a,{value:"bash",children:"Bash"}),e.jsx(a,{value:"zsh",children:"Zsh"}),e.jsx(a,{value:"fish",children:"Fish"}),e.jsx(a,{value:"sh",children:"sh"}),e.jsx(a,{value:"system",children:"System Default"})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"autoSaveInterval",children:"Auto-save Interval (seconds)"}),e.jsx(b,{id:"autoSaveInterval",type:"number",min:10,max:600,value:s.autoSaveInterval,onChange:t=>i({autoSaveInterval:Number.parseInt(t.target.value,10)||r.autoSaveInterval})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Controls how often Coconut persists draft work to disk."})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(y,{variant:"outline",onClick:S,disabled:c,children:"Reset"}),e.jsx(y,{onClick:I,disabled:c,children:c?"Saving...":"Save Preferences"})]})]})}export{B as default};
@@ -0,0 +1 @@
1
+ import{r as a,H as I,A as S,j as e,a1 as D,B as g,I as p,v as F,w as P,x as z,y as L,z as A,L as R}from"./index-B8vejVRZ.js";import{C as q,b as T,c as M,d as O,a as U}from"./card-CvaBJsG6.js";import{L as c}from"./label-DtNTh--4.js";import{C as B,a as H}from"./clipboard-BNXOfcye.js";const m=[{id:"software-engineer",title:"Software Engineer",description:"Builds, refactors, and reviews high-quality code across stacks. Excellent at translating specs into implementation and optimizing system performance. Strong at debugging, architecture patterns, and accelerating development velocity."},{id:"product-strategist",title:"Product Strategist",description:"Defines product direction, clarifies requirements, and aligns work with user and business goals. Skilled in roadmap planning, prioritization, and transforming ambiguous ideas into actionable plans."},{id:"researcher",title:"Researcher",description:"Investigates topics deeply, synthesizes information, and produces evidence-based insights. Strong at literature review, competitive analysis, and generating clear summaries to inform decisions."},{id:"designer",title:"Designer",description:"Creates intuitive interfaces, user flows, and visual assets. Focused on usability, accessibility, and crafting polished experiences. Strong at wireframing and turning requirements into elegant solutions."},{id:"qa-engineer",title:"QA Engineer",description:"Identifies bugs, edge cases, and reliability gaps. Produces test plans, automated tests, and reproducible reports. Strong at ensuring product quality and preventing regressions."},{id:"devops-engineer",title:"DevOps Engineer",description:"Manages infrastructure, deployments, and operational reliability. Skilled with CI/CD, observability, automation, and environment provisioning. Ensures systems are scalable and fault-tolerant."},{id:"data-analyst",title:"Data Analyst",description:"Analyzes data, defines metrics, and generates actionable insights. Strong in SQL, visualization, experimentation, and turning raw data into strategic recommendations."},{id:"marketer",title:"Marketer",description:"Creates campaigns, messaging, and positioning to reach target audiences. Skilled in content, funnels, and brand strategy. Strong at synthesizing market needs and shaping demand."},{id:"sales-partnerships-agent",title:"Sales & Partnerships Agent",description:"Identifies prospects, crafts outreach, and develops strategic relationships. Strong at value articulation, objection handling, and mapping product capabilities to customer needs."},{id:"growth-operator",title:"Growth Operator",description:"Optimizes acquisition, activation, and retention through experimentation. Skilled in funnel analysis, rapid testing, and leveraging data for compounding growth."},{id:"customer-success-specialist",title:"Customer Success Specialist",description:"Ensures users succeed by providing onboarding, guidance, and proactive support. Strong at diagnosing user challenges and improving long-term satisfaction and retention."},{id:"orchestration-engineer",title:"Orchestration Engineer",description:"Coordinates multi-agent workflows, dependencies, and handoffs. Strong at breaking large tasks into sequenced steps and ensuring agents operate cohesively and efficiently."},{id:"context-curator",title:"Context Curator",description:"Maintains clean, accurate project context by organizing files, logs, and knowledge. Strong at eliminating ambiguity, ensuring agents have the right information at the right time."},{id:"documentation-writer",title:"Documentation Writer",description:"Produces clear technical docs, guides, READMEs, and CP summaries. Strong at structuring complex information and keeping knowledge bases up to date and accessible."}];function G(){const[n,h]=a.useState({}),[r,d]=a.useState(null),[f,x]=a.useState(!1),[b,N]=a.useState(!0),[u,v]=a.useState(!1),{toast:o}=I();a.useEffect(()=>{j()},[]);const j=async()=>{try{try{const t=await fetch(`${S}/api/v1/config`),s=await t.json();if(t.ok&&s?.success){const i=s.data?.coconut||{};d(i.id??null),(i.firstName||i.lastName||i.email||i.role||i.roleDescription)&&h({firstName:i.firstName,lastName:i.lastName,email:i.email,role:i.role,roleDescription:i.roleDescription})}else d(null)}catch(t){console.error("Failed to load coconut config:",t),d(null)}}catch(t){console.error("Failed to load settings:",t),o({title:"Error",description:"Failed to load user settings",variant:"destructive"})}finally{N(!1)}},w=async()=>{v(!0);try{const s=await(await fetch(`${S}/api/v1/config`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({coconut:{...n,id:r||void 0}})})).json();if(s.success)o({title:"Success",description:"Settings saved successfully"});else throw new Error(s.error||"Failed to save settings")}catch(t){console.error("Failed to save settings:",t),o({title:"Error",description:"Failed to save settings",variant:"destructive"})}finally{v(!1)}},l=t=>{h(s=>{const i={...s,...t};if(t.role!==void 0){const C=m.find(E=>E.id===t.role);C?.description&&(i.roleDescription=C.description)}return i})},y=a.useMemo(()=>n.role&&m.find(s=>s.id===n.role)?.description||null,[n.role]),k=async()=>{if(r)try{await navigator.clipboard.writeText(r),x(!0),o({title:"Copied",description:"Coconut ID copied to clipboard."}),setTimeout(()=>x(!1),1500)}catch(t){console.error("Failed to copy coconut ID:",t),o({title:"Copy failed",description:"Unable to copy the Coconut ID to the clipboard.",variant:"destructive"})}};return b?e.jsx("div",{children:"Loading..."}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"Coconut Settings"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage the Coconut's profile information."})]}),e.jsx(D,{}),e.jsx("div",{className:"rounded-lg border border-dashed bg-muted/40 p-4",children:r?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground",children:"Coconut ID"}),e.jsx("p",{className:"mt-1 font-mono text-sm",children:r})]}),e.jsxs(g,{variant:"outline",size:"sm",onClick:k,children:[f?e.jsx(B,{className:"h-4 w-4"}):e.jsx(H,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2",children:f?"Copied":"Copy"})]})]}):e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground",children:"Coconut ID not configured"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Add an `id` under the `coconut` section in `.nut/config.json` to register this Coconut instance."})]})}),e.jsxs(q,{children:[e.jsxs(T,{children:[e.jsx(M,{children:"Coconut Profile"}),e.jsx(O,{children:"Update the Coconut's identifying details and role."})]}),e.jsxs(U,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(c,{htmlFor:"firstName",children:"First Name"}),e.jsx(p,{id:"firstName",value:n.firstName||"",onChange:t=>l({firstName:t.target.value}),placeholder:"Enter first name"})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"lastName",children:"Last Name"}),e.jsx(p,{id:"lastName",value:n.lastName||"",onChange:t=>l({lastName:t.target.value}),placeholder:"Enter last name"})]})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"email",children:"Email"}),e.jsx(p,{id:"email",type:"email",value:n.email||"",onChange:t=>l({email:t.target.value}),placeholder:"Enter email address"})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"role",children:"Role"}),e.jsxs(F,{value:n.role,onValueChange:t=>l({role:t}),children:[e.jsx(P,{children:e.jsx(z,{placeholder:"Select role"})}),e.jsx(L,{children:m.map(t=>e.jsx(A,{value:t.id,children:t.title},t.id))})]}),y&&e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:y})]})]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["You can also manage the Coconut's identity to other agents on the"," ",e.jsx(R,{to:"/identity",className:"underline underline-offset-4 hover:text-primary",children:"Identity page"}),"."]}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(g,{variant:"outline",onClick:j,disabled:u,children:"Cancel"}),e.jsx(g,{onClick:w,disabled:u,children:u?"Saving...":"Save Changes"})]})]})}export{G as default};
@@ -0,0 +1 @@
1
+ import{u as k,H as w,r as n,j as e,B as g,af as b,L as C,A as S,a4 as I}from"./index-B8vejVRZ.js";import{C as R,a as B}from"./card-CvaBJsG6.js";import{u as Q}from"./use-terminal-2DGl8X5T.js";import{C as $}from"./circle-play-88lMuMRZ.js";import{P as O}from"./play-a8BsF4gF.js";function L(){const o=k(),{loading:l,createSession:d,refreshSessions:j}=Q(),{toast:i}=w(),[m,u]=n.useState(!1),[x,h]=n.useState(!1),[,f]=n.useState([]),[c,y]=n.useState({});n.useEffect(()=>{try{const t=localStorage.getItem("terminal.commandHistory");t&&f(JSON.parse(t))}catch{}},[]),n.useEffect(()=>{(async()=>{try{const s=await fetch(`${S}/api/v1/context/architecture`);if(!s.ok)return;const a=await s.json();a?.success&&a?.document?.metadata?.commands&&y(a.document.metadata.commands)}catch{}})()},[]);const p=t=>{t&&f(s=>{const a=[t,...s.filter(r=>r!==t)].slice(0,5);try{localStorage.setItem("terminal.commandHistory",JSON.stringify(a))}catch{}return a})},N=async t=>{const s=(t||"").trim();if(!s)return;const a=`session-${Date.now()}`;u(!0);try{await d(a,!1,s)?(p(s),i({title:"Session started",description:`${a}`}),o(`/terminal/${a}`)):i({title:"Failed to start",description:"See error above",variant:"destructive"})}finally{u(!1)}},v=async t=>{const s=(t||"").trim();if(!s)return;const a=`session-${Date.now()}`;h(!0);try{await d(a,!1,s)?(p(s),setTimeout(()=>j(),150),i({title:"Started in background",description:`${a}`,action:e.jsx(I,{altText:"Open session",onClick:()=>o(`/terminal/${a}`),children:"Open"})})):i({title:"Failed to start",description:"See error above",variant:"destructive"})}finally{h(!1)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Utilities"}),e.jsx("p",{className:"text-muted-foreground",children:"Quick commands and shortcuts"})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Quick Commands"}),e.jsx(R,{children:e.jsx(B,{className:"pt-6",children:c&&Object.keys(c).length>0?e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"rounded-md border divide-y",children:Object.entries(c).map(([t,s])=>e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 p-2",children:[e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col sm:flex-row sm:items-center gap-1 sm:gap-2",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:t}),e.jsx("span",{className:"text-muted-foreground hidden sm:inline",children:":"}),e.jsx("span",{className:"truncate max-w-full",children:e.jsx("code",{className:"bg-muted px-2 py-0.5 rounded text-xs",children:s})})]}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-shrink-0",children:[e.jsxs(g,{onClick:()=>v(s),variant:"secondary",size:"sm",disabled:l||x||m,title:"Run in background",children:[e.jsx($,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Background"})]}),e.jsxs(g,{onClick:()=>N(s),size:"sm",disabled:l||m||x,title:"Run",children:[e.jsx(O,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Run"})]})]})]},t))})}):e.jsxs("div",{className:"flex flex-col items-center justify-center text-center space-y-3 py-8",children:[e.jsx(b,{className:"h-12 w-12 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg mb-2",children:"No quick commands configured"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-md leading-relaxed",children:"Quick commands let you run common tasks with one click, like starting your development server or running build scripts."}),e.jsxs("p",{className:"text-sm text-muted-foreground max-w-md mt-2",children:["Set them up in the"," ",e.jsx(C,{to:"/context/architecture/edit",className:"text-primary hover:underline font-medium",children:"Quick Commands section"}),"."]})]})]})})})]})]})}export{L as default};
@@ -0,0 +1 @@
1
+ import{r,j as a,f as o}from"./index-B8vejVRZ.js";const v=r.forwardRef(({className:e,variant:t="default",...s},d)=>{const l="relative w-full rounded-lg border px-4 py-3 text-sm [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",i=t==="destructive"?"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive":"bg-background text-foreground";return a.jsx("div",{ref:d,role:"alert",className:o(l,i,e),...s})});v.displayName="Alert";const c=r.forwardRef(({className:e,...t},s)=>a.jsx("div",{ref:s,className:o("text-sm [&_p]:leading-relaxed",e),...t}));c.displayName="AlertDescription";export{v as A,c as a};
@@ -0,0 +1,6 @@
1
+ import{c as o}from"./index-B8vejVRZ.js";/**
2
+ * @license lucide-react v0.542.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const e=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],c=o("arrow-down",e);export{c as A};
@@ -0,0 +1,6 @@
1
+ import{c as o}from"./index-B8vejVRZ.js";/**
2
+ * @license lucide-react v0.542.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const e=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],r=o("arrow-left",e);export{r as A};
@@ -0,0 +1,6 @@
1
+ import{c as o}from"./index-B8vejVRZ.js";/**
2
+ * @license lucide-react v0.542.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const r=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],c=o("arrow-up",r);export{c as A};
@@ -0,0 +1 @@
1
+ import{j as o,f as n,bb as a}from"./index-B8vejVRZ.js";const s=a("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function i({className:r,variant:e,...t}){return o.jsx("div",{className:n(s({variant:e}),r),...t})}export{i as B};
@@ -0,0 +1,6 @@
1
+ import{c as J,r,j as e,D as W,a as Y,b as z,d as K,I as Q,n as A,S as V,f as X,$ as Z,B as R}from"./index-B8vejVRZ.js";import{B as y}from"./badge-NJasrAx_.js";import{S as O}from"./search-BR37JgJ3.js";/**
2
+ * @license lucide-react v0.542.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const ee=[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]],oe=J("library",ee),te="https://registry.coconut.dev";async function B(a){const n=a.startsWith("http")?a:`${te}${a}`,i=await fetch(n,{headers:{Accept:"application/json","User-Agent":"coconut-frontend"}});if(!i.ok)throw new Error(`Failed to fetch registry resource: ${i.status}`);return i.json()}async function se(a){const n=`/registry/${a}/root.json`;return B(n)}async function ce(a){return B(a)}const re="Browse Registry",ae="Import";function de({open:a,categoryId:n,onOpenChange:i,title:F=re,confirmLabel:M=ae,filterTags:d,onConfirm:I,getDetail:_,renderPreview:$}){const[u,v]=r.useState([]),[U,N]=r.useState(!1),[w,S]=r.useState(null),[o,E]=r.useState(null),[x,b]=r.useState({}),[T,g]=r.useState(!1),[L,j]=r.useState(null),[f,C]=r.useState(""),[p,k]=r.useState(!1);r.useEffect(()=>{if(!a)return;N(!0),S(null),E(null),j(null),g(!1),b({}),C("");const t=Array.isArray(n)?n:[n];Promise.all(t.map(s=>se(s))).then(s=>{const l=s.flatMap(h=>h.elements??[]);v(l)}).catch(s=>{console.error("Failed to load registry category",s),v([]),S("Failed to load registry entries")}).finally(()=>N(!1))},[a,n]);const D=r.useMemo(()=>{let t=u;if(d&&d.length>0&&(t=t.filter(l=>{const h=l.tags??[];return d.some(G=>h.some(H=>H.toLowerCase()===G.toLowerCase()))})),!f.trim())return t;const s=f.trim().toLowerCase();return t.filter(l=>[l.name,l.description,l.preview,...l.tags??[]].filter(Boolean).join(" ").toLowerCase().includes(s))},[u,f,d]),c=r.useMemo(()=>o?u.find(t=>t.id===o)??null:null,[u,o]),m=r.useMemo(()=>o?x[o]?.detail??null:null,[o,x]),P=async t=>{if(E(t.id),j(null),!x?.[t.id]?.detail){g(!0);try{const s=await _(t);b(l=>({...l??{},[t.id]:{detail:s,fetchedAt:Date.now()}}))}catch(s){console.error("Failed to load registry element detail",s),j("Unable to load detail for this entry")}finally{g(!1)}}},q=async()=>{if(!(!c||!m)){k(!0);try{await I(c,m),i(!1)}catch(t){console.error("Failed to import registry element",t)}finally{k(!1)}}};return e.jsx(W,{open:a,onOpenChange:i,children:e.jsxs(Y,{className:"max-w-5xl h-[80vh] flex flex-col",children:[e.jsx(z,{children:e.jsx(K,{children:F})}),e.jsx("div",{className:"flex flex-col gap-4",children:e.jsxs("div",{className:"relative",children:[e.jsx(O,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(Q,{value:f,onChange:t=>C(t.target.value),placeholder:"Search registry entries",className:"pl-9"})]})}),e.jsxs("div",{className:"flex-1 flex gap-4 min-h-0",children:[e.jsx("div",{className:"w-1/3 border-r pr-3",children:U?e.jsxs("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:[e.jsx(A,{className:"h-4 w-4 animate-spin mr-2"}),"Loading entries…"]}):w?e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:w}):D.length===0?e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"No entries found"}):e.jsx(V,{className:"h-full",children:e.jsx("div",{className:"space-y-1 pb-4",children:D.map(t=>e.jsxs("button",{onClick:()=>P(t),className:X("w-full rounded-md border border-transparent p-3 text-left transition-colors hover:border-border hover:bg-muted/40",o===t.id&&"border-primary bg-muted"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:t.name}),e.jsx("p",{className:"mt-1 line-clamp-2 text-xs text-muted-foreground",children:t.description||t.preview})]}),t.version&&e.jsxs(y,{variant:"outline",className:"text-[10px] font-medium uppercase",children:["v",t.version]})]}),t.tags&&t.tags.length>0&&e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[t.tags.slice(0,4).map(s=>e.jsx(y,{variant:"secondary",className:"text-[10px] font-normal",children:s},s)),t.tags.length>4&&e.jsxs(y,{variant:"outline",className:"text-[10px] font-normal",children:["+",t.tags.length-4]})]})]},t.id))})})}),e.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:T?e.jsxs("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:[e.jsx(A,{className:"h-5 w-5 animate-spin mr-2"}),"Loading detail…"]}):L?e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:L}):c?e.jsx("div",{className:"h-full overflow-hidden",children:$(c,m)}):e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:"Select an entry to preview"})})]}),e.jsxs(Z,{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:c?`Selected: ${c.name}`:"No entry selected"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(R,{variant:"outline",onClick:()=>i(!1),disabled:p,children:"Cancel"}),e.jsx(R,{onClick:q,disabled:!c||!m||p,children:p?"Importing…":M})]})]})]})})}export{oe as L,te as R,de as a,ce as f};