@lovelybunch/api 1.0.71-alpha.6 → 1.0.71-alpha.7

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 (84) hide show
  1. package/dist/routes/api/v1/resources/generate/route.js +6 -0
  2. package/dist/routes/api/v1/resources/generate-audio/route.js +6 -0
  3. package/dist/routes/api/v1/resources/generate-video/route.js +6 -0
  4. package/dist/routes/api/v1/resources/route.d.ts +4 -0
  5. package/dist/routes/api/v1/resources/route.js +5 -1
  6. package/package.json +4 -4
  7. package/static/assets/{AgentDetailPage-Bw8wHgla.js → AgentDetailPage-Opv1vviq.js} +1 -1
  8. package/static/assets/{AgentEditPage-CQ9Y3ez8.js → AgentEditPage-uLCBQAKt.js} +1 -1
  9. package/static/assets/{AgentsPage-DcgU1MPa.js → AgentsPage-CbwDfB0S.js} +1 -1
  10. package/static/assets/{AgentsSettingsPage-CgoXxqGL.js → AgentsSettingsPage-wqr9YnHr.js} +1 -1
  11. package/static/assets/{ApiKeysSettingsPage-BgqGOa4p.js → ApiKeysSettingsPage-16htmPFV.js} +1 -1
  12. package/static/assets/{ArchitectureEditPage-DrEnTloL.js → ArchitectureEditPage-Dvfb4b-o.js} +1 -1
  13. package/static/assets/{ArchitecturePage-Dpd6cyyT.js → ArchitecturePage-CzD1Oize.js} +1 -1
  14. package/static/assets/{AuthSettingsPage-wu1zFEx-.js → AuthSettingsPage-BP2zlNfC.js} +1 -1
  15. package/static/assets/{CallbackPage-DYzikcPp.js → CallbackPage-DEnicyfd.js} +1 -1
  16. package/static/assets/{CodePage-CtM-PEHU.js → CodePage-wBG-_Rs8.js} +1 -1
  17. package/static/assets/{CollapsibleSection-B23j-nZD.js → CollapsibleSection-DSatk0YZ.js} +1 -1
  18. package/static/assets/{DashboardPage-BoPCq6M9.js → DashboardPage-DmXHKAfY.js} +1 -1
  19. package/static/assets/{GitPage-DYicFQBx.js → GitPage-C-ZudM8s.js} +1 -1
  20. package/static/assets/{GitSettingsPage-B-1Nnid8.js → GitSettingsPage-DtvqZDAp.js} +1 -1
  21. package/static/assets/{IdentityPage-Cvj6SDPj.js → IdentityPage-WwVp_vBZ.js} +1 -1
  22. package/static/assets/{ImplementationStepsEditor-CCfJKk2U.js → ImplementationStepsEditor-BKDdpUue.js} +1 -1
  23. package/static/assets/{IntegrationsSettingsPage-BgLXCF-u.js → IntegrationsSettingsPage-Vhh08Jjd.js} +1 -1
  24. package/static/assets/{KnowledgeDetailPage-I9erHJXN.js → KnowledgeDetailPage-B8jlP-NF.js} +1 -1
  25. package/static/assets/{KnowledgeEditPage-BfaWotPl.js → KnowledgeEditPage-BppjRoZZ.js} +1 -1
  26. package/static/assets/{KnowledgePage-x9ShzjoT.js → KnowledgePage-CasWW1a1.js} +1 -1
  27. package/static/assets/{LoginPage-CZtwhbdN.js → LoginPage-DkguuNDQ.js} +1 -1
  28. package/static/assets/{McpSettingsPage-BHPjMqOX.js → McpSettingsPage-CZfBLxIj.js} +1 -1
  29. package/static/assets/{NewAgentPage-D-Pj_KgZ.js → NewAgentPage-BbANsmjr.js} +1 -1
  30. package/static/assets/{NewKnowledgePage-CoVnCUx6.js → NewKnowledgePage-BE18vt4E.js} +1 -1
  31. package/static/assets/{NewProposalPage-nCTq2mBC.js → NewProposalPage-BxKHijwN.js} +1 -1
  32. package/static/assets/{ProjectEditPage-d1cMZArt.js → ProjectEditPage-uwwvFm_Y.js} +1 -1
  33. package/static/assets/{ProjectPage-KwwOjk5b.js → ProjectPage-DJvT8Jwp.js} +1 -1
  34. package/static/assets/{PromptsSettingsPage-fSs6HBAk.js → PromptsSettingsPage-CWdSTKxS.js} +1 -1
  35. package/static/assets/{ProposalDetailPage-BnLOBPPT.js → ProposalDetailPage-CDyosWFj.js} +1 -1
  36. package/static/assets/{ProposalEditPage-bIYTFTmG.js → ProposalEditPage-D9b0X_vT.js} +1 -1
  37. package/static/assets/{ProposalsPage-D8W2d6g6.js → ProposalsPage-DdfAejqH.js} +1 -1
  38. package/static/assets/ResourcesPage-DCJ-ob0_.js +71 -0
  39. package/static/assets/{RulesSettingsPage-SWRxKVNH.js → RulesSettingsPage-CrIrk78x.js} +1 -1
  40. package/static/assets/{SchedulePage-DGxD8ZaL.js → SchedulePage-Dq53Q6fB.js} +1 -1
  41. package/static/assets/{TagInput-CYcNHzrk.js → TagInput-DtQl22K7.js} +1 -1
  42. package/static/assets/{TerminalPage-fabajZvk.js → TerminalPage-BcclpXIS.js} +1 -1
  43. package/static/assets/{TerminalSessionPage-DuJsKT9f.js → TerminalSessionPage-Tecaum7f.js} +1 -1
  44. package/static/assets/{UserPreferencesPage-DQMtobsK.js → UserPreferencesPage-B4jeTbEe.js} +1 -1
  45. package/static/assets/{UserSettingsPage-CFEb7pD0.js → UserSettingsPage-D_fTJGEB.js} +1 -1
  46. package/static/assets/{UtilitiesPage-qStPGLN_.js → UtilitiesPage-BVSfnezp.js} +1 -1
  47. package/static/assets/{alert-Baaj8mli.js → alert-DT5dIcQb.js} +1 -1
  48. package/static/assets/{arrow-down-CSpiROUo.js → arrow-down-D5JMw0I7.js} +1 -1
  49. package/static/assets/{arrow-left-CdJt7_wH.js → arrow-left-BbL7bi4b.js} +1 -1
  50. package/static/assets/{arrow-up-ugn3lusK.js → arrow-up-D5zdohVZ.js} +1 -1
  51. package/static/assets/{badge-fHjW-wEe.js → badge-CxMDR-vz.js} +1 -1
  52. package/static/assets/{browser-modal-D6BB5mxm.js → browser-modal-DZprh22G.js} +1 -1
  53. package/static/assets/{calendar-DXMWQL-h.js → calendar-DjIpzqju.js} +1 -1
  54. package/static/assets/{card-C9ekeZtD.js → card-Cq3qftln.js} +1 -1
  55. package/static/assets/{chevron-left-BkP_F3xd.js → chevron-left-8PdSXGp8.js} +1 -1
  56. package/static/assets/{circle-alert-DnIYekt3.js → circle-alert-CPeWHRYV.js} +1 -1
  57. package/static/assets/{circle-check-BO-qmBFl.js → circle-check-BsF5HxbR.js} +1 -1
  58. package/static/assets/{circle-check-big-BUVglreY.js → circle-check-big-DViAc1A0.js} +1 -1
  59. package/static/assets/{circle-play-84ZOWBDG.js → circle-play-C0yQlVR9.js} +1 -1
  60. package/static/assets/{circle-x-EQNlLpRR.js → circle-x-CT_9xyVN.js} +1 -1
  61. package/static/assets/{clipboard-Dv0iwZO9.js → clipboard-D-CHbLVc.js} +1 -1
  62. package/static/assets/{clock-BxO7xcX9.js → clock-D5nAa1In.js} +1 -1
  63. package/static/assets/{download-CpaVC4DU.js → download-Bl3cP1zr.js} +1 -1
  64. package/static/assets/{eye-BSR7OEmk.js → eye-DgdIekU1.js} +1 -1
  65. package/static/assets/{folder-git-2-9fWvFiHp.js → folder-git-2-BD7LL99o.js} +1 -1
  66. package/static/assets/{index-BAEEeZzi.js → index-CKcm92Kn.js} +3 -3
  67. package/static/assets/index-D9b0oysW.css +2 -0
  68. package/static/assets/{label-CRsu1MwQ.js → label-COUiN2Pd.js} +1 -1
  69. package/static/assets/{markdown-editor-Dop22vuJ.js → markdown-editor-Cln2Jo2-.js} +1 -1
  70. package/static/assets/{pause-C7KYrzQF.js → pause-CupPWZ26.js} +1 -1
  71. package/static/assets/{play-DhUf2mKM.js → play-sWUKmZEy.js} +1 -1
  72. package/static/assets/{plus-CemYz5Fm.js → plus-DM62ve-p.js} +1 -1
  73. package/static/assets/{radio-group-Dz2cO4IQ.js → radio-group-B6pYL4p4.js} +1 -1
  74. package/static/assets/{refresh-cw-BL3y7jJo.js → refresh-cw-ClU12bdt.js} +1 -1
  75. package/static/assets/{search-BvRo_rak.js → search-DHLiojAp.js} +1 -1
  76. package/static/assets/{switch-CDOrVL8G.js → switch-DC_em8xh.js} +1 -1
  77. package/static/assets/{tabs-CP_A6r0A.js → tabs-KzUqSzqd.js} +1 -1
  78. package/static/assets/{tag-BpNIhvRX.js → tag-cF4ktw0a.js} +1 -1
  79. package/static/assets/{terminal-preview-CbgoHEQH.js → terminal-preview-D-pmjUNP.js} +1 -1
  80. package/static/assets/{use-terminal-ZvK-kdxE.js → use-terminal-C1j4Pa5C.js} +1 -1
  81. package/static/assets/{zap-DOtH7YrV.js → zap-DGHMgsd8.js} +1 -1
  82. package/static/index.html +2 -2
  83. package/static/assets/ResourcesPage-Dq9DZFd7.js +0 -71
  84. package/static/assets/index-DdGUrKz8.css +0 -2
@@ -0,0 +1,71 @@
1
+ import{c as re,r as n,j as e,D as fe,a as pe,b as ge,d as ve,n as te,S as ts,B as R,ah as ns,aj as Fe,H as Oe,A as se,a0 as je,v as U,w as H,x as J,y as Y,z as W,ac as Le,p as ue,ak as ia,al as oa,am as ca,an as be,ao as Re,ap as Ce,aq as da,ar as As,as as ua,at as ma,f as ha,I as Ke,ai as He,X as rs,C as Ls,g as _e,au as Je,av as xa,aw as fa,ax as pa,a5 as ga,a6 as va,s as ja,a7 as wa,aa as Be,e as ls,T as is,ay as ya}from"./index-CKcm92Kn.js";import{C as ze,b as os,a as Ue,c as Na,d as ba}from"./card-Cq3qftln.js";import{L as k}from"./label-COUiN2Pd.js";import{B as Ie}from"./badge-CxMDR-vz.js";import{c as _a}from"./clipboard-B9ndUJKl.js";import{R as Ks}from"./registry-ANRa5WBi.js";import{D as Ye}from"./download-Bl3cP1zr.js";import{C as Vs}from"./chevron-left-8PdSXGp8.js";import{C as Sa}from"./calendar-DjIpzqju.js";import{T as Ca}from"./tag-cF4ktw0a.js";import{P as cs}from"./plus-DM62ve-p.js";import{S as ka}from"./search-DHLiojAp.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 Pa=[["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"}]],ds=re("file-audio",Pa);/**
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 Ma=[["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"}]],Qe=re("file-code",Ma);/**
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 Ea=[["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"}]],us=re("file-image",Ea);/**
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 Fa=[["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"}]],ms=re("file-json",Fa);/**
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 Ia=[["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"}]],hs=re("file-play",Ia);/**
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 Ra=[["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"}]],xs=re("file-spreadsheet",Ra);/**
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 Ta=[["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"}]],fs=re("file-type",Ta);/**
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 Da=[["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"}]],Ga=re("hard-drive",Da);/**
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 Aa=[["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"}]],Se=re("image",Aa);/**
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 La=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],ps=re("maximize-2",La);/**
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 Ka=[["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"}]],xe=re("music",Ka);/**
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 Va=[["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"}]],gs=re("presentation",Va);/**
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 Oa=[["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"}]],Wa=re("upload",Oa);/**
67
+ * @license lucide-react v0.542.0 - ISC
68
+ *
69
+ * This source code is licensed under the ISC license.
70
+ * See the LICENSE file in the root directory of this source tree.
71
+ */const $a=[["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"}]],Ve=re("video",$a);async function Os(r){const c=r.startsWith("http")?r:`${Ks}${r}`,t=await fetch(c,{headers:{Accept:"application/json","User-Agent":"coconut-frontend"}});if(!t.ok)throw new Error(`Failed to fetch registry resource: ${t.status}`);return t.json()}async function Ba(){return Os("/registry/resources/root.json")}async function vs(r){return Os(r)}function Ae(r){if(r)return r.startsWith("http")?r:`${Ks}${r}`}function za({open:r,onOpenChange:c,onSelectExample:t,onCustomizeInAssistant:p}){const[h,d]=n.useState([]),[u,g]=n.useState(!1),[j,C]=n.useState(null),[w,m]=n.useState(null),[x,N]=n.useState(null),[S,b]=n.useState(!1),[y,_]=n.useState(null);n.useEffect(()=>{r&&(g(!0),C(null),m(null),N(null),_(null),Ba().then(f=>{d(f.elements??[]),f.elements&&f.elements.length>0&&A(f.elements[0])}).catch(f=>{console.error("Failed to load registry resources",f),d([]),C("Failed to load examples from registry")}).finally(()=>g(!1)))},[r]);const A=async f=>{m(f.id),_(null),N(null),b(!0);try{const M=await vs(f.endpoint);N(M)}catch(M){console.error("Failed to load resource detail",M),_("Unable to load details for this example")}finally{b(!1)}},P=()=>{x?.prompt&&(t(x.prompt),c(!1))},E=()=>{x?.prompt&&p&&(p(x.prompt),c(!1))},L=async f=>{if(w===f.id&&x?.prompt){t(x.prompt),c(!1);return}try{const M=await vs(f.endpoint);M.prompt&&(t(M.prompt),c(!1))}catch(M){console.error("Failed to load resource detail",M)}};return e.jsx(fe,{open:r,onOpenChange:c,children:e.jsxs(pe,{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(ge,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(ve,{className:"text-base sm:text-lg",children:"Example Prompts"})}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden md:hidden relative",children:[e.jsx("div",{className:"h-[40%] min-h-0 p-3 flex items-center justify-center bg-muted/30 overflow-hidden",children:S?e.jsxs("div",{className:"flex items-center text-muted-foreground",children:[e.jsx(te,{className:"h-5 w-5 animate-spin mr-2"}),"Loading..."]}):y?e.jsx("p",{className:"text-sm text-muted-foreground",children:y}):x?e.jsx("img",{src:Ae(x.imageUrl),alt:x.title,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:[u?e.jsxs("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:[e.jsx(te,{className:"h-5 w-5 animate-spin mr-2"}),"Loading examples..."]}):j?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:j}):h.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"No examples available"}):e.jsx(ts,{className:"flex-1",children:e.jsx("div",{className:"p-3 space-y-2",children:h.map(f=>e.jsxs("button",{onClick:()=>A(f),onDoubleClick:()=>L(f),className:`w-full text-left p-2 rounded-lg border-2 transition-all flex gap-3 ${w===f.id?"border-primary bg-primary/5":"border-transparent bg-muted/50 hover:bg-muted"}`,children:[f.thumbnailUrl&&e.jsx("img",{src:Ae(f.thumbnailUrl),alt:"",className:"w-12 h-12 rounded object-cover flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:f.name}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",children:f.description})]})]},f.id))})}),e.jsx("div",{className:"p-3 border-t flex-shrink-0",children:e.jsxs(R,{onClick:P,disabled:!x?.prompt||S,className:"w-full",children:[e.jsx(ns,{className:"mr-2 h-4 w-4"}),"Use This Prompt"]})})]}),x&&p&&e.jsx("div",{className:"absolute bottom-16 right-3 z-10",children:e.jsxs(R,{size:"sm",variant:"secondary",onClick:E,children:[e.jsx(Fe,{className:"mr-1.5 h-3.5 w-3.5"}),"Customize"]})})]}),e.jsxs("div",{className:"flex-1 hidden md:flex overflow-hidden",children:[e.jsxs("div",{className:"w-[35%] border-r flex flex-col",children:[u?e.jsxs("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:[e.jsx(te,{className:"h-5 w-5 animate-spin mr-2"}),"Loading examples..."]}):j?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:j}):h.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"No examples available"}):e.jsx(ts,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-3",children:h.map(f=>e.jsxs("button",{onClick:()=>A(f),onDoubleClick:()=>L(f),className:`w-full text-left p-3 rounded-lg border-2 transition-all flex gap-3 ${w===f.id?"border-primary bg-primary/5 shadow-sm":"border-transparent bg-muted/50 hover:bg-muted hover:border-muted-foreground/20"}`,children:[f.thumbnailUrl&&e.jsx("img",{src:Ae(f.thumbnailUrl),alt:"",className:"w-16 h-16 rounded object-cover flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:f.name}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 mt-1",children:f.description}),f.tags&&f.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[f.tags.slice(0,3).map(M=>e.jsx(Ie,{variant:"secondary",className:"text-[10px]",children:M},M)),f.tags.length>3&&e.jsxs(Ie,{variant:"outline",className:"text-[10px]",children:["+",f.tags.length-3]})]})]})]},f.id))})}),e.jsx("div",{className:"p-4 border-t flex-shrink-0",children:e.jsxs(R,{onClick:P,disabled:!x?.prompt||S,className:"w-full",children:[e.jsx(ns,{className:"mr-2 h-4 w-4"}),"Use This Prompt"]})})]}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden relative",children:[e.jsx("div",{className:"flex-1 min-h-0 p-6 flex items-center justify-center bg-muted/30 overflow-hidden",children:S?e.jsxs("div",{className:"flex items-center text-muted-foreground",children:[e.jsx(te,{className:"h-5 w-5 animate-spin mr-2"}),"Loading details..."]}):y?e.jsx("p",{className:"text-sm text-muted-foreground",children:y}):x?e.jsx("img",{src:Ae(x.imageUrl),alt:x.title,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"})}),x&&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 whitespace-pre-wrap",children:x.prompt})]}),x&&p&&e.jsx("div",{className:"absolute bottom-4 right-4 z-10",children:e.jsxs(R,{size:"sm",variant:"secondary",onClick:E,children:[e.jsx(Fe,{className:"mr-1.5 h-3.5 w-3.5"}),"Customize in Assistant"]})})]})]})]})})}const js="image-generator-settings";function ws(){return e.jsxs("div",{className:"relative h-4 w-4",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-primary/30"}),e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-primary animate-spin"}),e.jsx("div",{className:"absolute inset-[3px] rounded-full border border-transparent border-t-primary/60 animate-spin",style:{animationDirection:"reverse",animationDuration:"0.6s"}})]})}const qe={"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}}},ys=Object.values(qe).map(r=>({value:r.id,label:r.label})),Ns=[{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"}],Ua={value:"match_input_image",label:"Match Input"},bs=[{value:"png",label:"PNG"},{value:"jpg",label:"JPG"},{value:"webp",label:"WebP"}],_s=[{value:"60",label:"60"},{value:"70",label:"70"},{value:"80",label:"80"},{value:"90",label:"90"},{value:"100",label:"100"}],Ss=[{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 Ha({open:r,onOpenChange:c,onSave:t,onCustomizeInAssistant:p}){const d=(()=>{if(typeof window>"u")return null;try{const a=localStorage.getItem(js);return a?JSON.parse(a):null}catch{return null}})(),[u,g]=n.useState(""),[j,C]=n.useState(d?.model||"nano-banana-pro"),[w,m]=n.useState(d?.aspectRatio||"3:4"),[x,N]=n.useState(d?.resolution||"2K"),[S,b]=n.useState(d?.outputFormat||"png"),[y,_]=n.useState(d?.outputQuality||"80"),[A,P]=n.useState(d?.goFast??!0),[E,L]=n.useState(d?.safetyTolerance||"2"),[f,M]=n.useState(null),[T,$]=n.useState(!1),[F,D]=n.useState(!1),[v,z]=n.useState([]),[K,Q]=n.useState([]),[q,Z]=n.useState(!0),[V,ee]=n.useState(!1),[o,X]=n.useState(0),l=n.useRef(null),{toast:G}=Oe();n.useEffect(()=>{const a={model:j,aspectRatio:w,resolution:x,outputFormat:S,outputQuality:y,goFast:A,safetyTolerance:E};localStorage.setItem(js,JSON.stringify(a))},[j,w,x,S,y,A,E]),n.useEffect(()=>(T?(X(0),l.current=setInterval(()=>{X(a=>a+1)},1e3)):l.current&&(clearInterval(l.current),l.current=null),()=>{l.current&&clearInterval(l.current)}),[T]);const B=qe[j],ne=B.features.matchInputImage?[Ua,...Ns]:Ns,me=B.resolutionOptions||[];n.useEffect(()=>{const a=qe[j];a.defaults.resolution&&a.features.resolution&&N(a.defaults.resolution),a.defaults.outputQuality!==void 0&&_(String(a.defaults.outputQuality)),a.defaults.goFast!==void 0&&P(a.defaults.goFast),a.defaults.safetyTolerance!==void 0&&L(String(a.defaults.safetyTolerance)),m(O=>O==="match_input_image"&&!a.features.matchInputImage?"3:4":O)},[j]),n.useEffect(()=>{r&&we()},[r]);const we=async()=>{try{const O=await(await fetch(`${se}/api/v1/resources`)).json();if(O.success){const he=(O.data||[]).filter(le=>{const Ne=le.type==="image/jpeg"||le.name.toLowerCase().endsWith(".jpg")||le.name.toLowerCase().endsWith(".jpeg"),Me=le.type==="image/png"||le.name.toLowerCase().endsWith(".png");return(Ne||Me)&&le.thumbnailPath});z(he)}}catch(a){console.error("Failed to fetch image resources:",a)}},Pe=async()=>{if(!u.trim()){G({title:"Prompt required",description:"Please enter a prompt to generate an image",variant:"destructive"});return}$(!0),M(null);try{const a=q||K.length===0?[]:[...K],O=await fetch(`${se}/api/v1/resources/generate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:u,model:j,dimensions:w,resolution:B.features.resolution?x:void 0,output_format:S,output_quality:B.features.outputQuality?parseInt(y):void 0,go_fast:B.features.goFast?A:void 0,safety_tolerance:B.features.safetyTolerance?parseInt(E):void 0,image_input:a})});if(O.status===504||O.status===502||O.status===408)throw new Error("Request timed out. The image model may be warming up - please try again.");const he=O.headers.get("content-type");if(!he||!he.includes("application/json"))throw new Error("Request timed out or server error. Please try again.");const le=await O.json();if(!O.ok||!le.success){const Ne=le.error?.message||"Failed to generate image",Me=le.error?.code==="MISSING_API_TOKEN";throw new Error(Me?"Replicate API token not configured. Please add it in Settings → Integrations.":Ne)}M(le.data.imageUrl),G({title:"Image generated",description:"Your image has been generated successfully"})}catch(a){console.error("Generation error:",a);const O=a instanceof Error?a.message:"Failed to generate image.",he=O.toLowerCase().includes("timeout")||O.toLowerCase().includes("timed out");G({title:he?"Generation timed out":"Generation failed",description:O,variant:"destructive"})}finally{$(!1)}};n.useEffect(()=>{const a=O=>{r&&(O.metaKey||O.ctrlKey)&&O.key==="Enter"&&(O.preventDefault(),u.trim()&&!T&&!F&&Pe())};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[r,u,T,F]);const Te=async()=>{if(f){D(!0);try{await t(f,{prompt:u,model:j}),g(""),C("nano-banana-pro"),m("3:4"),N("2K"),b("png"),_("80"),P(!0),L("2"),M(null),Z(!0),Q([]),c(!1)}catch(a){G({title:"Save failed",description:a instanceof Error?a.message:"Failed to save image. Please try again.",variant:"destructive"})}finally{D(!1)}}},$e=()=>{!T&&!F&&c(!1)},De=()=>{Z(!0),Q([])},ie=a=>{q&&Z(!1),K.includes(a)?(Q(K.filter(O=>O!==a)),K.length===1&&Z(!0)):K.length<3?Q([...K,a]):G({title:"Maximum selection",description:"You can only select up to 3 images",variant:"destructive"})},ye=a=>{g(a)},Ge=a=>{p&&(ee(!1),c(!1),p(`"${a}" Please customize this (and respond back just the updated markdown):`))};return e.jsxs(fe,{open:r,onOpenChange:$e,children:[e.jsxs(pe,{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(ge,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(ve,{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:T?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3",children:[e.jsx(te,{className:"h-10 w-10 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating..."})]}):f?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:f,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(Se,{className:"h-12 w-12"}),e.jsx("p",{className:"text-xs",children:"Preview"}),e.jsxs(R,{size:"sm",onClick:()=>ee(!0),className:"mt-2",children:[e.jsx(Fe,{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:De,className:`flex-shrink-0 h-16 w-16 flex items-center justify-center border-2 rounded-md transition-colors text-xs ${q?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:"None"}),v.map(a=>{const O=K.includes(a.id);return e.jsx("button",{onClick:()=>ie(a.id),className:`flex-shrink-0 h-16 w-16 border-2 rounded-md overflow-hidden transition-colors ${O?"border-primary ring-2 ring-primary":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("img",{src:`${se}/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(k,{htmlFor:"prompt-mobile",className:"text-xs",children:"Prompt"}),e.jsx(je,{id:"prompt-mobile",placeholder:"Describe the image...",value:u,onChange:a=>g(a.target.value),rows:2,className:"resize-none text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{htmlFor:"model-mobile",className:"text-xs",children:"Model"}),e.jsxs(U,{value:j,onValueChange:a=>C(a),children:[e.jsx(H,{id:"model-mobile",className:"h-8 text-xs",children:e.jsx(J,{})}),e.jsx(Y,{children:ys.map(a=>e.jsx(W,{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(k,{htmlFor:"outputFormat-mobile",className:"text-xs",children:"Format"}),e.jsxs(U,{value:S,onValueChange:b,children:[e.jsx(H,{id:"outputFormat-mobile",className:"h-8 text-xs",children:e.jsx(J,{})}),e.jsx(Y,{children:bs.map(a=>e.jsx(W,{value:a.value,children:a.label},a.value))})]})]}),B.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(Le,{id:"goFast-mobile",checked:A,onCheckedChange:a=>P(a===!0)}),e.jsx(k,{htmlFor:"goFast-mobile",className:"text-xs cursor-pointer",children:"Go Fast"})]})}),B.features.safetyTolerance&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{htmlFor:"safetyTolerance-mobile",className:"text-xs",children:"Safety"}),e.jsxs(U,{value:E,onValueChange:L,children:[e.jsx(H,{id:"safetyTolerance-mobile",className:"h-8 text-xs",children:e.jsx(J,{})}),e.jsx(Y,{children:Ss.map(a=>e.jsx(W,{value:a.value,children:a.label},a.value))})]})]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[B.features.resolution&&e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(k,{htmlFor:"resolution-mobile",className:"text-xs",children:"Resolution"}),e.jsxs(U,{value:x,onValueChange:N,children:[e.jsx(H,{id:"resolution-mobile",className:"h-8 text-xs",children:e.jsx(J,{})}),e.jsx(Y,{children:me.map(a=>e.jsx(W,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(k,{htmlFor:"aspectRatio-mobile",className:"text-xs",children:"Ratio"}),e.jsxs(U,{value:w,onValueChange:m,children:[e.jsx(H,{id:"aspectRatio-mobile",className:"h-8 text-xs",children:e.jsx(J,{})}),e.jsx(Y,{children:ne.map(a=>e.jsx(W,{value:a.value,children:a.label},a.value))})]})]}),B.features.outputQuality&&e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(k,{htmlFor:"outputQuality-mobile",className:"text-xs",children:"Quality"}),e.jsxs(U,{value:y,onValueChange:_,children:[e.jsx(H,{id:"outputQuality-mobile",className:"h-8 text-xs",children:e.jsx(J,{})}),e.jsx(Y,{children:_s.map(a=>e.jsx(W,{value:a.value,children:a.label},a.value))})]})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(R,{onClick:Pe,disabled:!u.trim()||T||F,className:"flex-1 h-9",size:"sm",children:T?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ws,{}),e.jsxs("span",{children:[o,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:["Generate",e.jsx(ue,{className:"ml-1",children:"⌘↵"})]})}),e.jsx(R,{onClick:Te,disabled:!f||T||F,variant:"outline",className:"flex-1 h-9",size:"sm",children:F?e.jsx(te,{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(k,{htmlFor:"prompt",children:"Prompt"}),e.jsx(je,{id:"prompt",placeholder:"Describe the image you want to generate...",value:u,onChange:a=>g(a.target.value),rows:4,className:"resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"model",children:"Model"}),e.jsxs(U,{value:j,onValueChange:a=>C(a),children:[e.jsx(H,{id:"model",children:e.jsx(J,{})}),e.jsx(Y,{children:ys.map(a=>e.jsx(W,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"aspectRatio",children:"Aspect Ratio"}),e.jsxs(U,{value:w,onValueChange:m,children:[e.jsx(H,{id:"aspectRatio",children:e.jsx(J,{})}),e.jsx(Y,{children:ne.map(a=>e.jsx(W,{value:a.value,children:a.label},a.value))})]})]}),B.features.resolution&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"resolution",children:"Resolution"}),e.jsxs(U,{value:x,onValueChange:N,children:[e.jsx(H,{id:"resolution",children:e.jsx(J,{})}),e.jsx(Y,{children:me.map(a=>e.jsx(W,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"outputFormat",children:"Output Format"}),e.jsxs(U,{value:S,onValueChange:b,children:[e.jsx(H,{id:"outputFormat",children:e.jsx(J,{})}),e.jsx(Y,{children:bs.map(a=>e.jsx(W,{value:a.value,children:a.label},a.value))})]})]}),B.features.outputQuality&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"outputQuality",children:"Output Quality"}),e.jsxs(U,{value:y,onValueChange:_,children:[e.jsx(H,{id:"outputQuality",children:e.jsx(J,{})}),e.jsx(Y,{children:_s.map(a=>e.jsx(W,{value:a.value,children:a.label},a.value))})]})]}),B.features.goFast&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Le,{id:"goFast",checked:A,onCheckedChange:a=>P(a===!0)}),e.jsx(k,{htmlFor:"goFast",className:"cursor-pointer",children:"Go Fast"})]}),B.features.safetyTolerance&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"safetyTolerance",children:"Safety Tolerance"}),e.jsxs(U,{value:E,onValueChange:L,children:[e.jsx(H,{id:"safetyTolerance",children:e.jsx(J,{})}),e.jsx(Y,{children:Ss.map(a=>e.jsx(W,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-4",children:[e.jsx(R,{onClick:Pe,disabled:!u.trim()||T||F,className:"w-full",children:T?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ws,{}),e.jsxs("span",{children:["Generating... ",o,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-2",children:["Generate",e.jsx(ue,{children:"⌘"}),e.jsx(ue,{children:"↵"})]})}),e.jsx(R,{onClick:Te,disabled:!f||T||F,variant:"outline",className:"w-full",children:F?e.jsxs(e.Fragment,{children:[e.jsx(te,{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:T?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx(te,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating image..."})]}):f?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:f,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(Se,{className:"h-16 w-16"}),e.jsx("p",{className:"text-sm",children:"Generated image will appear here"}),e.jsxs(R,{onClick:()=>ee(!0),className:"mt-2",children:[e.jsx(Fe,{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:De,className:`flex-shrink-0 h-32 w-32 flex items-center justify-center border-2 rounded-md transition-colors ${q?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("span",{className:"text-sm font-medium",children:"None"})}),v.map(a=>{const O=K.includes(a.id);return e.jsx("button",{onClick:()=>ie(a.id),className:`flex-shrink-0 h-32 w-32 border-2 rounded-md overflow-hidden transition-colors ${O?"border-primary ring-2 ring-primary":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("img",{src:`${se}/api/v1/resources/${a.id}/thumbnail`,alt:a.name,className:"w-full h-full object-cover"})},a.id)})]})})]})]})]}),e.jsx(za,{open:V,onOpenChange:ee,onSelectExample:ye,onCustomizeInAssistant:p?Ge:void 0})]})}var Ws=["PageUp","PageDown"],$s=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Bs={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},ke="Slider",[Xe,Ja,Ya]=ca(ke),[zs,kt]=oa(ke,[Ya]),[Qa,We]=zs(ke),Us=n.forwardRef((r,c)=>{const{name:t,min:p=0,max:h=100,step:d=1,orientation:u="horizontal",disabled:g=!1,minStepsBetweenThumbs:j=0,defaultValue:C=[p],value:w,onValueChange:m=()=>{},onValueCommit:x=()=>{},inverted:N=!1,form:S,...b}=r,y=n.useRef(new Set),_=n.useRef(0),P=u==="horizontal"?qa:Xa,[E=[],L]=ia({prop:w,defaultProp:C,onChange:D=>{[...y.current][_.current]?.focus(),m(D)}}),f=n.useRef(E);function M(D){const v=tt(E,D);F(D,v)}function T(D){F(D,_.current)}function $(){const D=f.current[_.current];E[_.current]!==D&&x(E)}function F(D,v,{commit:z}={commit:!1}){const K=it(d),Q=ot(Math.round((D-p)/d)*d+p,K),q=As(Q,[p,h]);L((Z=[])=>{const V=st(Z,q,v);if(lt(V,j*d)){_.current=V.indexOf(q);const ee=String(V)!==String(Z);return ee&&z&&x(V),ee?V:Z}else return Z})}return e.jsx(Qa,{scope:r.__scopeSlider,name:t,disabled:g,min:p,max:h,valueIndexToChangeRef:_,thumbs:y.current,values:E,orientation:u,form:S,children:e.jsx(Xe.Provider,{scope:r.__scopeSlider,children:e.jsx(Xe.Slot,{scope:r.__scopeSlider,children:e.jsx(P,{"aria-disabled":g,"data-disabled":g?"":void 0,...b,ref:c,onPointerDown:be(b.onPointerDown,()=>{g||(f.current=E)}),min:p,max:h,inverted:N,onSlideStart:g?void 0:M,onSlideMove:g?void 0:T,onSlideEnd:g?void 0:$,onHomeKeyDown:()=>!g&&F(p,0,{commit:!0}),onEndKeyDown:()=>!g&&F(h,E.length-1,{commit:!0}),onStepKeyDown:({event:D,direction:v})=>{if(!g){const Q=Ws.includes(D.key)||D.shiftKey&&$s.includes(D.key)?10:1,q=_.current,Z=E[q],V=d*Q*v;F(Z+V,q,{commit:!0})}}})})})})});Us.displayName=ke;var[Hs,Js]=zs(ke,{startEdge:"left",endEdge:"right",size:"width",direction:1}),qa=n.forwardRef((r,c)=>{const{min:t,max:p,dir:h,inverted:d,onSlideStart:u,onSlideMove:g,onSlideEnd:j,onStepKeyDown:C,...w}=r,[m,x]=n.useState(null),N=Ce(c,P=>x(P)),S=n.useRef(void 0),b=da(h),y=b==="ltr",_=y&&!d||!y&&d;function A(P){const E=S.current||m.getBoundingClientRect(),L=[0,E.width],M=ss(L,_?[t,p]:[p,t]);return S.current=E,M(P-E.left)}return e.jsx(Hs,{scope:r.__scopeSlider,startEdge:_?"left":"right",endEdge:_?"right":"left",direction:_?1:-1,size:"width",children:e.jsx(Ys,{dir:b,"data-orientation":"horizontal",...w,ref:N,style:{...w.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:P=>{const E=A(P.clientX);u?.(E)},onSlideMove:P=>{const E=A(P.clientX);g?.(E)},onSlideEnd:()=>{S.current=void 0,j?.()},onStepKeyDown:P=>{const L=Bs[_?"from-left":"from-right"].includes(P.key);C?.({event:P,direction:L?-1:1})}})})}),Xa=n.forwardRef((r,c)=>{const{min:t,max:p,inverted:h,onSlideStart:d,onSlideMove:u,onSlideEnd:g,onStepKeyDown:j,...C}=r,w=n.useRef(null),m=Ce(c,w),x=n.useRef(void 0),N=!h;function S(b){const y=x.current||w.current.getBoundingClientRect(),_=[0,y.height],P=ss(_,N?[p,t]:[t,p]);return x.current=y,P(b-y.top)}return e.jsx(Hs,{scope:r.__scopeSlider,startEdge:N?"bottom":"top",endEdge:N?"top":"bottom",size:"height",direction:N?1:-1,children:e.jsx(Ys,{"data-orientation":"vertical",...C,ref:m,style:{...C.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:b=>{const y=S(b.clientY);d?.(y)},onSlideMove:b=>{const y=S(b.clientY);u?.(y)},onSlideEnd:()=>{x.current=void 0,g?.()},onStepKeyDown:b=>{const _=Bs[N?"from-bottom":"from-top"].includes(b.key);j?.({event:b,direction:_?-1:1})}})})}),Ys=n.forwardRef((r,c)=>{const{__scopeSlider:t,onSlideStart:p,onSlideMove:h,onSlideEnd:d,onHomeKeyDown:u,onEndKeyDown:g,onStepKeyDown:j,...C}=r,w=We(ke,t);return e.jsx(Re.span,{...C,ref:c,onKeyDown:be(r.onKeyDown,m=>{m.key==="Home"?(u(m),m.preventDefault()):m.key==="End"?(g(m),m.preventDefault()):Ws.concat($s).includes(m.key)&&(j(m),m.preventDefault())}),onPointerDown:be(r.onPointerDown,m=>{const x=m.target;x.setPointerCapture(m.pointerId),m.preventDefault(),w.thumbs.has(x)?x.focus():p(m)}),onPointerMove:be(r.onPointerMove,m=>{m.target.hasPointerCapture(m.pointerId)&&h(m)}),onPointerUp:be(r.onPointerUp,m=>{const x=m.target;x.hasPointerCapture(m.pointerId)&&(x.releasePointerCapture(m.pointerId),d(m))})})}),Qs="SliderTrack",qs=n.forwardRef((r,c)=>{const{__scopeSlider:t,...p}=r,h=We(Qs,t);return e.jsx(Re.span,{"data-disabled":h.disabled?"":void 0,"data-orientation":h.orientation,...p,ref:c})});qs.displayName=Qs;var Ze="SliderRange",Xs=n.forwardRef((r,c)=>{const{__scopeSlider:t,...p}=r,h=We(Ze,t),d=Js(Ze,t),u=n.useRef(null),g=Ce(c,u),j=h.values.length,C=h.values.map(x=>sa(x,h.min,h.max)),w=j>1?Math.min(...C):0,m=100-Math.max(...C);return e.jsx(Re.span,{"data-orientation":h.orientation,"data-disabled":h.disabled?"":void 0,...p,ref:g,style:{...r.style,[d.startEdge]:w+"%",[d.endEdge]:m+"%"}})});Xs.displayName=Ze;var es="SliderThumb",Zs=n.forwardRef((r,c)=>{const t=Ja(r.__scopeSlider),[p,h]=n.useState(null),d=Ce(c,g=>h(g)),u=n.useMemo(()=>p?t().findIndex(g=>g.ref.current===p):-1,[t,p]);return e.jsx(Za,{...r,ref:d,index:u})}),Za=n.forwardRef((r,c)=>{const{__scopeSlider:t,index:p,name:h,...d}=r,u=We(es,t),g=Js(es,t),[j,C]=n.useState(null),w=Ce(c,A=>C(A)),m=j?u.form||!!j.closest("form"):!0,x=ua(j),N=u.values[p],S=N===void 0?0:sa(N,u.min,u.max),b=at(p,u.values.length),y=x?.[g.size],_=y?nt(y,S,g.direction):0;return n.useEffect(()=>{if(j)return u.thumbs.add(j),()=>{u.thumbs.delete(j)}},[j,u.thumbs]),e.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[g.startEdge]:`calc(${S}% + ${_}px)`},children:[e.jsx(Xe.ItemSlot,{scope:r.__scopeSlider,children:e.jsx(Re.span,{role:"slider","aria-label":r["aria-label"]||b,"aria-valuemin":u.min,"aria-valuenow":N,"aria-valuemax":u.max,"aria-orientation":u.orientation,"data-orientation":u.orientation,"data-disabled":u.disabled?"":void 0,tabIndex:u.disabled?void 0:0,...d,ref:w,style:N===void 0?{display:"none"}:r.style,onFocus:be(r.onFocus,()=>{u.valueIndexToChangeRef.current=p})})}),m&&e.jsx(ea,{name:h??(u.name?u.name+(u.values.length>1?"[]":""):void 0),form:u.form,value:N},p)]})});Zs.displayName=es;var et="RadioBubbleInput",ea=n.forwardRef(({__scopeSlider:r,value:c,...t},p)=>{const h=n.useRef(null),d=Ce(h,p),u=ma(c);return n.useEffect(()=>{const g=h.current;if(!g)return;const j=window.HTMLInputElement.prototype,w=Object.getOwnPropertyDescriptor(j,"value").set;if(u!==c&&w){const m=new Event("input",{bubbles:!0});w.call(g,c),g.dispatchEvent(m)}},[u,c]),e.jsx(Re.input,{style:{display:"none"},...t,ref:d,defaultValue:c})});ea.displayName=et;function st(r=[],c,t){const p=[...r];return p[t]=c,p.sort((h,d)=>h-d)}function sa(r,c,t){const d=100/(t-c)*(r-c);return As(d,[0,100])}function at(r,c){return c>2?`Value ${r+1} of ${c}`:c===2?["Minimum","Maximum"][r]:void 0}function tt(r,c){if(r.length===1)return 0;const t=r.map(h=>Math.abs(h-c)),p=Math.min(...t);return t.indexOf(p)}function nt(r,c,t){const p=r/2,d=ss([0,50],[0,p]);return(p-d(c)*t)*t}function rt(r){return r.slice(0,-1).map((c,t)=>r[t+1]-c)}function lt(r,c){if(c>0){const t=rt(r);return Math.min(...t)>=c}return!0}function ss(r,c){return t=>{if(r[0]===r[1]||c[0]===c[1])return c[0];const p=(c[1]-c[0])/(r[1]-r[0]);return c[0]+p*(t-r[0])}}function it(r){return(String(r).split(".")[1]||"").length}function ot(r,c){const t=Math.pow(10,c);return Math.round(r*t)/t}var aa=Us,ct=qs,dt=Xs,ut=Zs;const Ee=n.forwardRef(({className:r,...c},t)=>e.jsxs(aa,{ref:t,className:ha("relative flex w-full touch-none select-none items-center",r),...c,children:[e.jsx(ct,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20",children:e.jsx(dt,{className:"absolute h-full bg-primary"})}),e.jsx(ut,{className:"block h-4 w-4 rounded-full border border-primary/50 bg-background shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"})]}));Ee.displayName=aa.displayName;const Cs="audio-generator-settings";function ks(){return e.jsxs("div",{className:"relative h-4 w-4",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-primary/30"}),e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-primary animate-spin"}),e.jsx("div",{className:"absolute inset-[3px] rounded-full border border-transparent border-t-primary/60 animate-spin",style:{animationDirection:"reverse",animationDuration:"0.6s"}})]})}const Ps=["English_Trustworth_Man","English_Aussie_Bloke","English_CalmWoman","English_UpsetGirl","English_Gentle-voiced_man","English_Whispering_girl","English_Diligent_Man","English_Graceful_Lady","English_ReservedYoungMan","English_PlayfulGirl","English_ManWithDeepVoice","English_MaturePartner","English_FriendlyPerson","English_MatureBoss","English_Debator","English_LovelyGirl","English_Steadymentor","English_Deep-VoicedGentleman","English_Wiselady","English_CaptivatingStoryteller","English_DecentYoungMan","English_SentimentalLady","English_ImposingManner","English_SadTeen","English_PassionateWarrior","English_WiseScholar","English_Soft-spokenGirl","English_SereneWoman","English_ConfidentWoman","English_PatientMan","English_Comedian","English_BossyLeader","English_Strong-WilledBoy","English_StressedLady","English_AssertiveQueen","English_AnimeCharacter","English_Jovialman","English_WhimsicalGirl","English_Kind-heartedGirl","Chinese (Mandarin)_Reliable_Executive","Chinese (Mandarin)_News_Anchor","Chinese (Mandarin)_Unrestrained_Young_Man","Chinese (Mandarin)_Mature_Woman","Arrogant_Miss","Robot_Armor","Chinese (Mandarin)_Kind-hearted_Antie","Chinese (Mandarin)_Refreshing_Young_Man","Chinese (Mandarin)_HK_Flight_Attendant","Chinese (Mandarin)_Humorous_Elder","Chinese (Mandarin)_Gentleman","Chinese (Mandarin)_Warm_Bestie","Chinese (Mandarin)_Stubborn_Friend","Chinese (Mandarin)_Sweet_Lady","Chinese (Mandarin)_Southern_Young_Man","Chinese (Mandarin)_Wise_Women","Chinese (Mandarin)_Gentle_Youth","Chinese (Mandarin)_Warm_Girl","Chinese (Mandarin)_Male_Announcer","Chinese (Mandarin)_Kind-hearted_Elder","Chinese (Mandarin)_Cute_Spirit","Chinese (Mandarin)_Radio_Host","Chinese (Mandarin)_Lyrical_Voice","Chinese (Mandarin)_Straightforward_Boy","Chinese (Mandarin)_Sincere_Adult","Chinese (Mandarin)_Gentle_Senior","Chinese (Mandarin)_Crisp_Girl","Chinese (Mandarin)_Pure-hearted_Boy","Chinese (Mandarin)_Soft_Girl","Chinese (Mandarin)_IntellectualGirl","Chinese (Mandarin)_Warm_HeartedGirl","Chinese (Mandarin)_Laid_BackGirl","Chinese (Mandarin)_ExplorativeGirl","Chinese (Mandarin)_Warm-HeartedAunt","Chinese (Mandarin)_BashfulGirl","Japanese_IntellectualSenior","Japanese_DecisivePrincess","Japanese_LoyalKnight","Japanese_DominantMan","Japanese_SeriousCommander","Japanese_ColdQueen","Japanese_DependableWoman","Japanese_GentleButler","Japanese_KindLady","Japanese_CalmLady","Japanese_OptimisticYouth","Japanese_GenerousIzakayaOwner","Japanese_SportyStudent","Japanese_InnocentBoy","Japanese_GracefulMaiden","Cantonese_ProfessionalHost(F)","Cantonese_GentleLady","Cantonese_ProfessionalHost(M)","Cantonese_PlayfulMan","Cantonese_CuteGirl","Cantonese_KindWoman","Korean_SweetGirl","Korean_CheerfulBoyfriend","Korean_EnchantingSister","Korean_ShyGirl","Korean_ReliableSister","Korean_StrictBoss","Korean_SassyGirl","Korean_ChildhoodFriendGirl","Korean_PlayboyCharmer","Korean_ElegantPrincess","Korean_BraveFemaleWarrior","Korean_BraveYouth","Korean_CalmLady","Korean_EnthusiasticTeen","Korean_SoothingLady","Korean_IntellectualSenior","Korean_LonelyWarrior","Korean_MatureLady","Korean_InnocentBoy","Korean_CharmingSister","Korean_AthleticStudent","Korean_BraveAdventurer","Korean_CalmGentleman","Korean_WiseElf","Korean_CheerfulCoolJunior","Korean_DecisiveQueen","Korean_ColdYoungMan","Korean_MysteriousGirl","Korean_QuirkyGirl","Korean_ConsiderateSenior","Korean_CheerfulLittleSister","Korean_DominantMan","Korean_AirheadedGirl","Korean_ReliableYouth","Korean_FriendlyBigSister","Korean_GentleBoss","Korean_ColdGirl","Korean_HaughtyLady","Korean_CharmingElderSister","Korean_IntellectualMan","Korean_CaringWoman","Korean_WiseTeacher","Korean_ConfidentBoss","Korean_AthleticGirl","Korean_PossessiveMan","Korean_GentleWoman","Korean_CockyGuy","Korean_ThoughtfulWoman","Korean_OptimisticYouth","Spanish_SereneWoman","Spanish_MaturePartner","Spanish_CaptivatingStoryteller","Spanish_Narrator","Spanish_WiseScholar","Spanish_Kind-heartedGirl","Spanish_DeterminedManager","Spanish_BossyLeader","Spanish_ReservedYoungMan","Spanish_ConfidentWoman","Spanish_ThoughtfulMan","Spanish_Strong-WilledBoy","Spanish_SophisticatedLady","Spanish_RationalMan","Spanish_AnimeCharacter","Spanish_Deep-tonedMan","Spanish_Fussyhostess","Spanish_SincereTeen","Spanish_FrankLady","Spanish_Comedian","Spanish_Debator","Spanish_ToughBoss","Spanish_Wiselady","Spanish_Steadymentor","Spanish_Jovialman","Spanish_SantaClaus","Spanish_Rudolph","Spanish_Intonategirl","Spanish_Arnold","Spanish_Ghost","Spanish_HumorousElder","Spanish_EnergeticBoy","Spanish_WhimsicalGirl","Spanish_StrictBoss","Spanish_ReliableMan","Spanish_SereneElder","Spanish_AngryMan","Spanish_AssertiveQueen","Spanish_CaringGirlfriend","Spanish_PowerfulSoldier","Spanish_PassionateWarrior","Spanish_ChattyGirl","Spanish_RomanticHusband","Spanish_CompellingGirl","Spanish_PowerfulVeteran","Spanish_SensibleManager","Spanish_ThoughtfulLady","Portuguese_SentimentalLady","Portuguese_BossyLeader","Portuguese_Wiselady","Portuguese_Strong-WilledBoy","Portuguese_Deep-VoicedGentleman","Portuguese_UpsetGirl","Portuguese_PassionateWarrior","Portuguese_AnimeCharacter","Portuguese_ConfidentWoman","Portuguese_AngryMan","Portuguese_CaptivatingStoryteller","Portuguese_Godfather","Portuguese_ReservedYoungMan","Portuguese_SmartYoungGirl","Portuguese_Kind-heartedGirl","Portuguese_Pompouslady","Portuguese_Grinch","Portuguese_Debator","Portuguese_SweetGirl","Portuguese_AttractiveGirl","Portuguese_ThoughtfulMan","Portuguese_PlayfulGirl","Portuguese_GorgeousLady","Portuguese_LovelyLady","Portuguese_SereneWoman","Portuguese_SadTeen","Portuguese_MaturePartner","Portuguese_Comedian","Portuguese_NaughtySchoolgirl","Portuguese_Narrator","Portuguese_ToughBoss","Portuguese_Fussyhostess","Portuguese_Dramatist","Portuguese_Steadymentor","Portuguese_Jovialman","Portuguese_CharmingQueen","Portuguese_SantaClaus","Portuguese_Rudolph","Portuguese_Arnold","Portuguese_CharmingSanta","Portuguese_CharmingLady","Portuguese_Ghost","Portuguese_HumorousElder","Portuguese_CalmLeader","Portuguese_GentleTeacher","Portuguese_EnergeticBoy","Portuguese_ReliableMan","Portuguese_SereneElder","Portuguese_GrimReaper","Portuguese_AssertiveQueen","Portuguese_WhimsicalGirl","Portuguese_StressedLady","Portuguese_FriendlyNeighbor","Portuguese_CaringGirlfriend","Portuguese_PowerfulSoldier","Portuguese_FascinatingBoy","Portuguese_RomanticHusband","Portuguese_StrictBoss","Portuguese_InspiringLady","Portuguese_PlayfulSpirit","Portuguese_ElegantGirl","Portuguese_CompellingGirl","Portuguese_PowerfulVeteran","Portuguese_SensibleManager","Portuguese_ThoughtfulLady","Portuguese_TheatricalActor","Portuguese_FragileBoy","Portuguese_ChattyGirl","Portuguese_Conscientiousinstructor","Portuguese_RationalMan","Portuguese_WiseScholar","Portuguese_FrankLady","Portuguese_DeterminedManager","French_Male_Speech_New","French_Female_News Anchor","French_CasualMan","French_MovieLeadFemale","French_FemaleAnchor","French_MaleNarrator","Indonesian_SweetGirl","Indonesian_ReservedYoungMan","Indonesian_CharmingGirl","Indonesian_CalmWoman","Indonesian_ConfidentWoman","Indonesian_CaringMan","Indonesian_BossyLeader","Indonesian_DeterminedBoy","Indonesian_GentleGirl","German_FriendlyMan","German_SweetLady","German_PlayfulMan","Russian_HandsomeChildhoodFriend","Russian_BrightHeroine","Russian_AmbitiousWoman","Russian_ReliableMan","Russian_CrazyQueen","Russian_PessimisticGirl","Russian_AttractiveGuy","Russian_Bad-temperedBoy","Italian_BraveHeroine","Italian_Narrator","Italian_WanderingSorcerer","Italian_DiligentLeader","Dutch_kindhearted_girl","Dutch_bossy_leader","Vietnamese_kindhearted_girl","Arabic_CalmWoman","Arabic_FriendlyGuy","Turkish_CalmWoman","Turkish_Trustworthyman","Ukrainian_CalmWoman"],Ms=[{value:"auto",label:"Auto"},{value:"happy",label:"Happy"},{value:"sad",label:"Sad"},{value:"angry",label:"Angry"},{value:"fearful",label:"Fearful"},{value:"disgusted",label:"Disgusted"},{value:"surprised",label:"Surprised"},{value:"neutral",label:"Neutral"}],Es=[{value:"English",label:"English"},{value:"Chinese",label:"Chinese"},{value:"Japanese",label:"Japanese"},{value:"Korean",label:"Korean"},{value:"Spanish",label:"Spanish"},{value:"Portuguese",label:"Portuguese"},{value:"French",label:"French"},{value:"Indonesian",label:"Indonesian"},{value:"German",label:"German"},{value:"Russian",label:"Russian"},{value:"Italian",label:"Italian"},{value:"Dutch",label:"Dutch"},{value:"Vietnamese",label:"Vietnamese"},{value:"Arabic",label:"Arabic"},{value:"Turkish",label:"Turkish"},{value:"Ukrainian",label:"Ukrainian"},{value:"Cantonese",label:"Cantonese"}],Fs=[{value:"mp3",label:"MP3"},{value:"wav",label:"WAV"},{value:"flac",label:"FLAC"}];function mt({open:r,onOpenChange:c,onSave:t}){const h=(()=>{if(typeof window>"u")return null;try{const o=localStorage.getItem(Cs);return o?JSON.parse(o):null}catch{return null}})(),[d,u]=n.useState(""),[g,j]=n.useState(h?.voiceId||"English_Trustworth_Man"),[C,w]=n.useState(h?.useCustomVoice||!1),[m,x]=n.useState(h?.customVoiceId||""),[N,S]=n.useState(h?.speed??1),[b,y]=n.useState(h?.pitch??0),[_,A]=n.useState(h?.emotion||"auto"),[P,E]=n.useState(h?.languageBoost||"English"),[L,f]=n.useState(h?.audioFormat||"mp3"),[M,T]=n.useState(null),[$,F]=n.useState(!1),[D,v]=n.useState(!1),[z,K]=n.useState(0),Q=n.useRef(null),{toast:q}=Oe();n.useEffect(()=>{const o={voiceId:g,useCustomVoice:C,customVoiceId:m,speed:N,pitch:b,emotion:_,languageBoost:P,audioFormat:L};localStorage.setItem(Cs,JSON.stringify(o))},[g,C,m,N,b,_,P,L]),n.useEffect(()=>($?(K(0),Q.current=setInterval(()=>{K(o=>o+1)},1e3)):Q.current&&(clearInterval(Q.current),Q.current=null),()=>{Q.current&&clearInterval(Q.current)}),[$]);const Z=async()=>{if(!d.trim()){q({title:"Text required",description:"Please enter text to generate audio",variant:"destructive"});return}F(!0),T(null);try{const o=C?m:g,X=await fetch(`${se}/api/v1/resources/generate-audio`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:d,voice_id:o,speed:N,pitch:b,emotion:_,language_boost:P,audio_format:L})});if(X.status===504||X.status===502||X.status===408)throw new Error("Request timed out. The audio model may be warming up - please try again.");const l=X.headers.get("content-type");if(!l||!l.includes("application/json"))throw new Error("Request timed out or server error. Please try again.");const G=await X.json();if(!X.ok||!G.success){const B=G.error?.message||"Failed to generate audio",ne=G.error?.code==="MISSING_API_TOKEN";throw new Error(ne?"Replicate API token not configured. Please add it in Settings → Integrations.":B)}T(G.data.audioUrl),q({title:"Audio generated",description:"Your audio has been generated successfully"})}catch(o){console.error("Generation error:",o);const X=o instanceof Error?o.message:"Failed to generate audio.",l=X.toLowerCase().includes("timeout")||X.toLowerCase().includes("timed out");q({title:l?"Generation timed out":"Generation failed",description:X,variant:"destructive"})}finally{F(!1)}};n.useEffect(()=>{const o=X=>{r&&(X.metaKey||X.ctrlKey)&&X.key==="Enter"&&(X.preventDefault(),d.trim()&&!$&&!D&&Z())};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[r,d,$,D]);const V=async()=>{if(M){v(!0);try{await t(M),u(""),j("English_Trustworth_Man"),w(!1),x(""),S(1),y(0),A("auto"),E("English"),f("mp3"),T(null),c(!1)}catch(o){q({title:"Save failed",description:o instanceof Error?o.message:"Failed to save audio. Please try again.",variant:"destructive"})}finally{v(!1)}}},ee=()=>{!$&&!D&&c(!1)};return e.jsx(fe,{open:r,onOpenChange:ee,children:e.jsxs(pe,{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(ge,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(ve,{className:"text-base sm:text-lg",children:"Generate Audio"})}),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:$?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3",children:[e.jsx(te,{className:"h-10 w-10 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating..."})]}):M?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(xe,{className:"h-16 w-16 text-muted-foreground/50"})}),e.jsx("div",{className:"flex-shrink-0 p-4 bg-muted/50 flex justify-center",children:e.jsx("audio",{src:M,controls:!0,className:"w-full max-w-[90%]",children:"Your browser does not support the audio tag."})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3 text-muted-foreground",children:[e.jsx(xe,{className:"h-12 w-12"}),e.jsx("p",{className:"text-xs",children:"Preview"})]})}),e.jsx("div",{className:"border-t p-3 overflow-y-auto flex-shrink-0 max-h-[55vh]",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{htmlFor:"text-mobile",className:"text-xs",children:"Text"}),e.jsx(je,{id:"text-mobile",placeholder:"Enter text to convert to speech...",value:d,onChange:o=>u(o.target.value),rows:3,className:"resize-none text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"Voice"}),e.jsxs(U,{value:C?"__custom__":g,onValueChange:o=>{o==="__custom__"?w(!0):(w(!1),j(o))},children:[e.jsx(H,{className:"h-8 text-xs",children:e.jsx(J,{})}),e.jsxs(Y,{className:"max-h-60",children:[Ps.map(o=>e.jsx(W,{value:o,className:"text-xs",children:o.replace(/_/g," ")},o)),e.jsx(W,{value:"__custom__",className:"text-xs font-medium",children:"Custom Voice ID..."})]})]}),C&&e.jsx(Ke,{placeholder:"Enter custom voice ID",value:m,onChange:o=>x(o.target.value),className:"h-8 text-xs mt-1"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(k,{className:"text-xs",children:["Speed: ",N.toFixed(1),"x"]}),e.jsx(Ee,{value:[N],onValueChange:([o])=>S(o),min:.5,max:2,step:.1,className:"w-full"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs(k,{className:"text-xs",children:["Pitch: ",b>0?"+":"",b]}),e.jsx(Ee,{value:[b],onValueChange:([o])=>y(o),min:-12,max:12,step:1,className:"w-full"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"Emotion"}),e.jsxs(U,{value:_,onValueChange:A,children:[e.jsx(H,{className:"h-8 text-xs",children:e.jsx(J,{})}),e.jsx(Y,{children:Ms.map(o=>e.jsx(W,{value:o.value,className:"text-xs",children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"Language"}),e.jsxs(U,{value:P,onValueChange:E,children:[e.jsx(H,{className:"h-8 text-xs",children:e.jsx(J,{})}),e.jsx(Y,{children:Es.map(o=>e.jsx(W,{value:o.value,className:"text-xs",children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"Format"}),e.jsxs(U,{value:L,onValueChange:f,children:[e.jsx(H,{className:"h-8 text-xs",children:e.jsx(J,{})}),e.jsx(Y,{children:Fs.map(o=>e.jsx(W,{value:o.value,className:"text-xs",children:o.label},o.value))})]})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(R,{onClick:Z,disabled:!d.trim()||$||D,className:"flex-1 h-9",size:"sm",children:$?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ks,{}),e.jsxs("span",{children:[z,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:["Generate",e.jsx(ue,{className:"ml-1",children:"⌘↵"})]})}),e.jsx(R,{onClick:V,disabled:!M||$||D,variant:"outline",className:"flex-1 h-9",size:"sm",children:D?e.jsx(te,{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-[30%] 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(k,{htmlFor:"text",children:"Text"}),e.jsx(je,{id:"text",placeholder:"Enter text to convert to speech...",value:d,onChange:o=>u(o.target.value),rows:6,className:"resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Voice"}),e.jsxs(U,{value:C?"__custom__":g,onValueChange:o=>{o==="__custom__"?w(!0):(w(!1),j(o))},children:[e.jsx(H,{children:e.jsx(J,{})}),e.jsxs(Y,{className:"max-h-80",children:[Ps.map(o=>e.jsx(W,{value:o,children:o.replace(/_/g," ")},o)),e.jsx(W,{value:"__custom__",className:"font-medium",children:"Custom Voice ID..."})]})]}),C&&e.jsx(Ke,{placeholder:"Enter custom voice ID",value:m,onChange:o=>x(o.target.value),className:"mt-2"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{children:["Speed: ",N.toFixed(1),"x"]}),e.jsx(Ee,{value:[N],onValueChange:([o])=>S(o),min:.5,max:2,step:.1,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"0.5x"}),e.jsx("span",{children:"2x"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{children:["Pitch: ",b>0?"+":"",b]}),e.jsx(Ee,{value:[b],onValueChange:([o])=>y(o),min:-12,max:12,step:1,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"-12"}),e.jsx("span",{children:"+12"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Emotion"}),e.jsxs(U,{value:_,onValueChange:A,children:[e.jsx(H,{children:e.jsx(J,{})}),e.jsx(Y,{children:Ms.map(o=>e.jsx(W,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Language Boost"}),e.jsxs(U,{value:P,onValueChange:E,children:[e.jsx(H,{children:e.jsx(J,{})}),e.jsx(Y,{children:Es.map(o=>e.jsx(W,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Audio Format"}),e.jsxs(U,{value:L,onValueChange:f,children:[e.jsx(H,{children:e.jsx(J,{})}),e.jsx(Y,{children:Fs.map(o=>e.jsx(W,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-4",children:[e.jsx(R,{onClick:Z,disabled:!d.trim()||$||D,className:"w-full",children:$?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ks,{}),e.jsxs("span",{children:["Generating... ",z,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-2",children:["Generate",e.jsx(ue,{children:"⌘"}),e.jsx(ue,{children:"↵"})]})}),e.jsx(R,{onClick:V,disabled:!M||$||D,variant:"outline",className:"w-full",children:D?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})]})]})}),e.jsx("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:$?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx(te,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating audio..."})]}):M?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(xe,{className:"h-24 w-24 text-muted-foreground/50"})}),e.jsx("div",{className:"flex-shrink-0 p-6 bg-muted/50 flex justify-center",children:e.jsx("audio",{src:M,controls:!0,className:"w-3/4 min-w-[300px]",children:"Your browser does not support the audio tag."})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[e.jsx(xe,{className:"h-16 w-16"}),e.jsx("p",{className:"text-sm",children:"Generated audio will appear here"})]})})})]})]})})}const Is="video-generator-settings";function Rs(){return e.jsxs("div",{className:"relative h-4 w-4",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-primary/30"}),e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-primary animate-spin"}),e.jsx("div",{className:"absolute inset-[3px] rounded-full border border-transparent border-t-primary/60 animate-spin",style:{animationDirection:"reverse",animationDuration:"0.6s"}})]})}const Ts=[{value:"5",label:"5 seconds"},{value:"8",label:"8 seconds"},{value:"10",label:"10 seconds"}],Ds=[{value:"480p",label:"480p"},{value:"720p",label:"720p"},{value:"1080p",label:"1080p"}],Gs=[{value:"16:9",label:"16:9 (Landscape)"},{value:"9:16",label:"9:16 (Portrait)"},{value:"1:1",label:"1:1 (Square)"}];function ht({open:r,onOpenChange:c,onSave:t}){const h=(()=>{if(typeof window>"u")return null;try{const l=localStorage.getItem(Is);return l?JSON.parse(l):null}catch{return null}})(),[d,u]=n.useState(""),[g,j]=n.useState(h?.duration||"8"),[C,w]=n.useState(h?.resolution||"720p"),[m,x]=n.useState(h?.aspectRatio||"16:9"),[N,S]=n.useState(h?.generateAudio??!0),[b,y]=n.useState(null),[_,A]=n.useState(null),[P,E]=n.useState(null),[L,f]=n.useState(0),M=n.useRef(null),[T,$]=n.useState(!1),[F,D]=n.useState(!1),[v,z]=n.useState([]),{toast:K}=Oe();n.useEffect(()=>{const l={duration:g,resolution:C,aspectRatio:m,generateAudio:N};localStorage.setItem(Is,JSON.stringify(l))},[g,C,m,N]),n.useEffect(()=>(T?(f(0),M.current=setInterval(()=>{f(l=>l+1)},1e3)):M.current&&(clearInterval(M.current),M.current=null),()=>{M.current&&clearInterval(M.current)}),[T]),n.useEffect(()=>{r&&Q()},[r]);const Q=async()=>{try{const G=await(await fetch(`${se}/api/v1/resources`)).json();if(G.success){const B=(G.data||[]).filter(ne=>{const me=ne.type==="image/jpeg"||ne.name.toLowerCase().endsWith(".jpg")||ne.name.toLowerCase().endsWith(".jpeg"),we=ne.type==="image/png"||ne.name.toLowerCase().endsWith(".png");return(me||we)&&ne.thumbnailPath});z(B)}}catch(l){console.error("Failed to fetch image resources:",l)}},q=l=>{l===_?A(null):l===b?(y(null),A(l)):b?A(l):y(l)},Z=()=>{y(null),A(null)},V=async()=>{if(!d.trim()){K({title:"Prompt required",description:"Please enter a prompt to generate a video",variant:"destructive"});return}$(!0),E(null);try{const l=await fetch(`${se}/api/v1/resources/generate-video`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:d,image:b||void 0,last_frame:_||void 0,duration:parseInt(g),resolution:C,aspect_ratio:m,generate_audio:N})});if(l.status===504||l.status===502||l.status===408)throw new Error("Request timed out. The video model may be warming up - please try again.");const G=l.headers.get("content-type");if(!G||!G.includes("application/json"))throw new Error("Request timed out or server error. Please try again.");const B=await l.json();if(!l.ok||!B.success){const ne=B.error?.message||"Failed to generate video",me=B.error?.code==="MISSING_API_TOKEN";throw new Error(me?"Replicate API token not configured. Please add it in Settings → Integrations.":ne)}E(B.data.videoUrl),K({title:"Video generated",description:"Your video has been generated successfully"})}catch(l){console.error("Generation error:",l);const G=l instanceof Error?l.message:"Failed to generate video.",B=G.toLowerCase().includes("timeout")||G.toLowerCase().includes("timed out");K({title:B?"Generation timed out":"Generation failed",description:G,variant:"destructive"})}finally{$(!1)}};n.useEffect(()=>{const l=G=>{r&&(G.metaKey||G.ctrlKey)&&G.key==="Enter"&&(G.preventDefault(),d.trim()&&!T&&!F&&V())};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[r,d,T,F]);const ee=async()=>{if(P){D(!0);try{await t(P),u(""),j("8"),w("720p"),x("16:9"),S(!0),y(null),A(null),E(null),c(!1)}catch(l){K({title:"Save failed",description:l instanceof Error?l.message:"Failed to save video. Please try again.",variant:"destructive"})}finally{D(!1)}}},o=()=>{!T&&!F&&c(!1)},X=l=>l===b?"start":l===_?"end":null;return e.jsx(fe,{open:r,onOpenChange:o,children:e.jsxs(pe,{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(ge,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(ve,{className:"text-base sm:text-lg",children:"Generate Video"})}),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:T?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3",children:[e.jsx(te,{className:"h-10 w-10 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating..."})]}):P?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("video",{src:P,controls:!0,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg",children:"Your browser does not support the video tag."})}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3 text-muted-foreground",children:[e.jsx(Ve,{className:"h-12 w-12"}),e.jsx("p",{className:"text-xs",children:"Preview"})]})}),e.jsxs("div",{className:"border-t bg-background p-2 flex-shrink-0",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2 px-1",children:"Select start and end frames (optional)"}),e.jsxs("div",{className:"flex gap-1.5 overflow-x-auto pb-1",children:[e.jsx("button",{onClick:Z,className:`flex-shrink-0 h-16 w-16 flex items-center justify-center border-2 rounded-md transition-colors text-xs ${!b&&!_?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:"None"}),v.map(l=>{const G=X(l.id);return e.jsxs("button",{onClick:()=>q(l.id),className:`relative flex-shrink-0 h-16 w-16 border-2 rounded-md overflow-hidden transition-colors ${G?"border-green-500 ring-2 ring-green-500":"border-muted hover:border-muted-foreground/50"}`,children:[e.jsx("img",{src:`${se}/api/v1/resources/${l.id}/thumbnail`,alt:l.name,className:"w-full h-full object-cover"}),G&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-green-500 text-white text-[10px] font-medium text-center py-0.5",children:G==="start"?"Start":"End"})]},l.id)})]})]}),e.jsx("div",{className:"border-t p-3 overflow-y-auto flex-shrink-0 max-h-[40vh]",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{htmlFor:"prompt-mobile",className:"text-xs",children:"Prompt"}),e.jsx(je,{id:"prompt-mobile",placeholder:"Describe the video you want to generate...",value:d,onChange:l=>u(l.target.value),rows:2,className:"resize-none text-sm"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"Duration"}),e.jsxs(U,{value:g,onValueChange:j,children:[e.jsx(H,{className:"h-8 text-xs",children:e.jsx(J,{})}),e.jsx(Y,{children:Ts.map(l=>e.jsx(W,{value:l.value,className:"text-xs",children:l.label},l.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"Resolution"}),e.jsxs(U,{value:C,onValueChange:w,children:[e.jsx(H,{className:"h-8 text-xs",children:e.jsx(J,{})}),e.jsx(Y,{children:Ds.map(l=>e.jsx(W,{value:l.value,className:"text-xs",children:l.label},l.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"Ratio"}),e.jsxs(U,{value:m,onValueChange:x,children:[e.jsx(H,{className:"h-8 text-xs",children:e.jsx(J,{})}),e.jsx(Y,{children:Gs.map(l=>e.jsx(W,{value:l.value,className:"text-xs",children:l.label},l.value))})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Le,{id:"generateAudio-mobile",checked:N,onCheckedChange:l=>S(l===!0)}),e.jsx(k,{htmlFor:"generateAudio-mobile",className:"text-xs cursor-pointer",children:"Generate audio"})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(R,{onClick:V,disabled:!d.trim()||T||F,className:"flex-1 h-9",size:"sm",children:T?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Rs,{}),e.jsxs("span",{children:[L,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:["Generate",e.jsx(ue,{className:"ml-1",children:"⌘↵"})]})}),e.jsx(R,{onClick:ee,disabled:!P||T||F,variant:"outline",className:"flex-1 h-9",size:"sm",children:F?e.jsx(te,{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(k,{htmlFor:"prompt",children:"Prompt"}),e.jsx(je,{id:"prompt",placeholder:"Describe the video you want to generate...",value:d,onChange:l=>u(l.target.value),rows:4,className:"resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"duration",children:"Duration"}),e.jsxs(U,{value:g,onValueChange:j,children:[e.jsx(H,{id:"duration",children:e.jsx(J,{})}),e.jsx(Y,{children:Ts.map(l=>e.jsx(W,{value:l.value,children:l.label},l.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"resolution",children:"Resolution"}),e.jsxs(U,{value:C,onValueChange:w,children:[e.jsx(H,{id:"resolution",children:e.jsx(J,{})}),e.jsx(Y,{children:Ds.map(l=>e.jsx(W,{value:l.value,children:l.label},l.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"aspectRatio",children:"Aspect Ratio"}),e.jsxs(U,{value:m,onValueChange:x,children:[e.jsx(H,{id:"aspectRatio",children:e.jsx(J,{})}),e.jsx(Y,{children:Gs.map(l=>e.jsx(W,{value:l.value,children:l.label},l.value))})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Le,{id:"generateAudio",checked:N,onCheckedChange:l=>S(l===!0)}),e.jsx(k,{htmlFor:"generateAudio",className:"cursor-pointer",children:"Generate audio"})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-4",children:[e.jsx(R,{onClick:V,disabled:!d.trim()||T||F,className:"w-full",children:T?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Rs,{}),e.jsxs("span",{children:["Generating... ",L,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-2",children:["Generate",e.jsx(ue,{children:"⌘"}),e.jsx(ue,{children:"↵"})]})}),e.jsx(R,{onClick:ee,disabled:!P||T||F,variant:"outline",className:"w-full",children:F?e.jsxs(e.Fragment,{children:[e.jsx(te,{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:T?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx(te,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating video..."})]}):P?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("video",{src:P,controls:!0,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg",children:"Your browser does not support the video tag."})}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[e.jsx(Ve,{className:"h-16 w-16"}),e.jsx("p",{className:"text-sm",children:"Generated video will appear here"})]})}),e.jsxs("div",{className:"border-t bg-background p-4 flex-shrink-0",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Select start and end frames (optional)"}),e.jsxs("div",{className:"flex gap-2 overflow-x-auto",children:[e.jsx("button",{onClick:Z,className:`flex-shrink-0 h-32 w-32 flex items-center justify-center border-2 rounded-md transition-colors ${!b&&!_?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("span",{className:"text-sm font-medium",children:"None"})}),v.map(l=>{const G=X(l.id);return e.jsxs("button",{onClick:()=>q(l.id),className:`relative flex-shrink-0 h-32 w-32 border-2 rounded-md overflow-hidden transition-colors ${G?"border-green-500 ring-2 ring-green-500":"border-muted hover:border-muted-foreground/50"}`,children:[e.jsx("img",{src:`${se}/api/v1/resources/${l.id}/thumbnail`,alt:l.name,className:"w-full h-full object-cover"}),G&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-green-500 text-white text-xs font-medium text-center py-1",children:G==="start"?"Start":"End"})]},l.id)})]})]})]})]})]})})}function xt({open:r,onOpenChange:c,resource:t,onCopyPath:p,onDownload:h,onNavigate:d,canNavigatePrev:u,canNavigateNext:g}){const[j,C]=n.useState(null),[w,m]=n.useState(!1),[x,N]=n.useState(!1);n.useEffect(()=>{N(!1)},[t?.id,r]);const S=t?`${se}/api/v1/resources/${t.id}`:"",b=t?.type.startsWith("image/")??!1,y=t?t.type==="image/svg+xml"||t.name.toLowerCase().endsWith(".svg"):!1,_=t?t.type==="application/pdf"||t.name.toLowerCase().endsWith(".pdf"):!1,A=t?.type.startsWith("video/")??!1,P=t?.type.startsWith("audio/")??!1,E=t?t.type.startsWith("text/")||t.type==="application/json"||t.type.includes("javascript")||t.type.includes("typescript")||t.type.includes("xml")||t.name.toLowerCase().match(/\.(txt|md|json|js|ts|jsx|tsx|css|html|xml|yaml|yml|log|sh|bash|zsh|fish)$/)!==null:!1,L=t?t.name.toLowerCase().endsWith(".md")||t.name.toLowerCase().endsWith(".markdown"):!1,f=t?t.type==="application/json"||t.name.toLowerCase().endsWith(".json"):!1,M=t?t.type==="text/html"||t.name.toLowerCase().endsWith(".html"):!1;if(n.useEffect(()=>{const v=z=>{if(r){if(z.key==="Escape"){x?N(!1):c(!1);return}if(!x){if(z.key==="ArrowLeft"&&u){z.preventDefault(),d("prev");return}z.key==="ArrowRight"&&g&&(z.preventDefault(),d("next"))}}};if(r)return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[r,c,d,u,g,x]),n.useEffect(()=>{r&&t&&(E||L||f||M)?(m(!0),fetch(S).then(v=>{if(v.ok)return v.text();throw new Error("Failed to load file")}).then(v=>{C(v)}).catch(v=>{console.error("Failed to load text content:",v),C(null)}).finally(()=>{m(!1)})):C(null)},[r,t?.id,E,L,f,M,S]),!t)return null;const T=v=>{if(v===0)return"0 B";const z=1024,K=["B","KB","MB","GB"],Q=Math.floor(Math.log(v)/Math.log(z));return parseFloat((v/Math.pow(z,Q)).toFixed(2))+" "+K[Q]},$=v=>new Date(v).toLocaleString(),F=v=>v.startsWith("image/")?e.jsx(Se,{className:"h-6 w-6"}):v.startsWith("video/")?e.jsx(Ve,{className:"h-6 w-6"}):v.startsWith("audio/")?e.jsx(xe,{className:"h-6 w-6"}):v.includes("text")||v.includes("document")||v.includes("code")?e.jsx(_e,{className:"h-6 w-6"}):v.includes("json")||v.includes("javascript")||v.includes("typescript")?e.jsx(Qe,{className:"h-6 w-6"}):e.jsx(Je,{className:"h-6 w-6"}),D=()=>{if(y)return e.jsxs(e.Fragment,{children:[e.jsx("img",{src:S,alt:t.name,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"}),e.jsx(R,{variant:"secondary",size:"icon",className:"absolute bottom-3 right-3 h-8 w-8 opacity-70 hover:opacity-100 transition-opacity",onClick:()=>N(!0),children:e.jsx(ps,{className:"h-4 w-4"})})]});if(_)return e.jsx("iframe",{src:S,className:"w-full h-full min-h-[600px] rounded-lg border",title:t.name});if(A)return e.jsx("video",{src:S,controls:!0,className:"max-w-full max-h-full rounded-lg shadow-lg",children:"Your browser does not support the video tag."});if(P)return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(xe,{className:"h-24 w-24 text-muted-foreground/50"})}),e.jsx("div",{className:"flex-shrink-0 p-6 bg-muted/30 flex justify-center",children:e.jsx("audio",{src:S,controls:!0,className:"w-3/4 min-w-[300px]",children:"Your browser does not support the audio tag."})})]});if(L&&j!==null)return w?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(xa,{remarkPlugins:[pa],rehypePlugins:[fa],children:j})});if(M&&j!==null)return w?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:j,className:"w-full h-full min-h-[600px] rounded-lg border",title:t.name,sandbox:"allow-same-origin"});if(f&&j!==null){if(w)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 v=j;try{const z=JSON.parse(j);v=JSON.stringify(z,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:v})})})}return E&&j!==null?w?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:j})})}):b?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:S,alt:t.name,className:"max-w-full max-h-full object-contain rounded-lg shadow-lg"}),e.jsx(R,{variant:"secondary",size:"icon",className:"absolute bottom-3 right-3 h-8 w-8 opacity-70 hover:opacity-100 transition-opacity",onClick:()=>N(!0),children:e.jsx(ps,{className:"h-4 w-4"})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[F(t.type),e.jsx("p",{className:"text-sm",children:"Preview not available for this file type"}),e.jsxs(R,{variant:"outline",onClick:()=>h(t),children:[e.jsx(Ye,{className:"mr-2 h-4 w-4"}),"Download to view"]})]})};return e.jsxs(e.Fragment,{children:[e.jsx(fe,{open:r,onOpenChange:c,children:e.jsxs(pe,{className:"max-w-[90vw] w-[90vw] max-h-[90vh] h-[90vh] p-0 gap-0 flex flex-col [&>button]:hidden",children:[e.jsx(ge,{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:[F(t.type),e.jsxs("div",{className:"flex-1 min-w-0 flex items-baseline gap-3",children:[e.jsx(ve,{className:"text-xl truncate",children:t.name}),e.jsx("p",{className:"text-sm text-muted-foreground flex-shrink-0",children:t.type})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>p(t),title:"Copy path to clipboard",children:e.jsx(He,{className:"h-4 w-4"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>h(t),title:"Download",children:e.jsx(Ye,{className:"h-4 w-4"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>c(!1),title:"Close",children:e.jsx(rs,{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-hidden",children:[u&&e.jsx("button",{type:"button",onClick:()=>d("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(Vs,{className:"h-5 w-5"})}),g&&e.jsx("button",{type:"button",onClick:()=>d("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(Ls,{className:"h-5 w-5"})}),D()]}),e.jsx("div",{className:"border-t p-6 flex-shrink-0 bg-background",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-x-6 gap-y-2 md:grid-cols-2 text-sm",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ga,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Size:"}),e.jsx("span",{children:T(t.size)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Sa,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Uploaded:"}),e.jsx("span",{children:$(t.uploadedAt)})]})]}),e.jsx("div",{className:"space-y-2",children:t.metadata.tags&&t.metadata.tags.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ca,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Tags:"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:t.metadata.tags.map(v=>e.jsx(Ie,{variant:"secondary",className:"text-xs",children:v},v))})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[t.metadata.description?e.jsxs(e.Fragment,{children:[e.jsx(_e,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Description:"}),e.jsx("span",{className:"truncate flex-1",title:t.metadata.description,children:t.metadata.description})]}):e.jsx("div",{className:"flex-1"}),t.metadata.generationPrompt&&e.jsxs(R,{size:"sm",className:"h-6 text-xs px-2 flex-shrink-0",onClick:()=>{navigator.clipboard.writeText(t.metadata.generationPrompt||"")},children:[e.jsx(He,{className:"h-2.5 w-2.5 mr-1"}),"Copy Prompt"]})]})]})})]})})]})}),x&&(b||y)&&e.jsxs("div",{className:"fixed inset-0 z-[100] bg-black/95 flex items-center justify-center",onClick:()=>N(!1),children:[e.jsx(R,{variant:"ghost",size:"icon",className:"absolute top-4 right-4 h-10 w-10 text-white hover:bg-white/20",onClick:()=>N(!1),children:e.jsx(rs,{className:"h-6 w-6"})}),e.jsx("img",{src:S,alt:t.name,className:"max-w-[95vw] max-h-[95vh] object-contain",onClick:v=>v.stopPropagation()})]})]})}function Pt(){const[r,c]=n.useState([]),[t,p]=n.useState(!0),[h,d]=n.useState(!1),[u,g]=n.useState(""),[j,C]=n.useState(!1),[w,m]=n.useState([]),[x,N]=n.useState(""),[S,b]=n.useState(""),[y,_]=n.useState([]),[A,P]=n.useState(!1),[E,L]=n.useState(!1),[f,M]=n.useState(!1),[T,$]=n.useState(null),[F,D]=n.useState(null),[v,z]=n.useState(null),[K,Q]=n.useState(1),q=12,Z=n.useRef(null),{toast:V}=Oe();n.useEffect(()=>{ee()},[]);const ee=async()=>{try{p(!0);const i=await(await fetch(`${se}/api/v1/resources`)).json();i.success&&c(i.data||[])}catch(s){console.error("Failed to fetch resources:",s)}finally{p(!1)}},o=s=>{s.length!==0&&_(Array.from(s))},X=async()=>{if(y.length!==0){d(!0);try{for(const s of y){const i=new FormData;if(i.append("file",s),i.append("tags",w.join(", ")),i.append("description",S),!(await fetch(`${se}/api/v1/resources`,{method:"POST",body:i})).ok)throw new Error("Upload failed")}m([]),N(""),b(""),_([]),C(!1),await ee(),V({title:"Upload successful",description:`${y.length} file(s) uploaded successfully`})}catch(s){console.error("Upload failed:",s),V({title:"Upload failed",description:"Failed to upload files. Please try again.",variant:"destructive"})}finally{d(!1)}}},l=()=>{m([]),N(""),b(""),_([]),C(!1)},G=s=>{if(s.key==="Enter"){s.preventDefault();const i=x.trim();i&&!w.includes(i)&&(m([...w,i]),N(""))}},B=s=>{m(w.filter(i=>i!==s))},ne=s=>{_(y.filter((i,I)=>I!==s))},me=async()=>{if(v)try{if((await fetch(`${se}/api/v1/resources/${v.id}`,{method:"DELETE"})).ok)await ee(),V({title:"Resource deleted",description:`${v.name} has been deleted`});else throw new Error("Delete failed")}catch(s){console.error("Failed to delete resource:",s),V({title:"Delete failed",description:"Failed to delete resource. Please try again.",variant:"destructive"})}finally{z(null)}},we=async s=>{try{const i=`.nut/resources/files/${s.path}`;await _a(i),V({title:"Path copied!",description:`Copied ${i} to clipboard`})}catch(i){console.error("Failed to copy path:",i),V({title:"Failed to copy",description:"Unable to copy path to clipboard",variant:"destructive"})}},Pe=s=>{if(s===0)return"0 B";const i=1024,I=["B","KB","MB","GB"],ae=Math.floor(Math.log(s)/Math.log(i));return parseFloat((s/Math.pow(i,ae)).toFixed(2))+" "+I[ae]},Te=(s,i)=>{const I=i.toLowerCase();return s.startsWith("image/")?s==="image/svg+xml"||I.endsWith(".svg")?e.jsx(us,{className:"h-4 w-4"}):e.jsx(Se,{className:"h-4 w-4"}):s.startsWith("video/")?e.jsx(hs,{className:"h-4 w-4"}):s.startsWith("audio/")?e.jsx(ds,{className:"h-4 w-4"}):s==="application/pdf"||I.endsWith(".pdf")?e.jsx(_e,{className:"h-4 w-4"}):I.match(/\.(js|jsx|ts|tsx|py|java|cpp|c|h|hpp|cs|go|rs|rb|php|swift|kt|scala|r|m|mm)$/)?e.jsx(Qe,{className:"h-4 w-4"}):s==="application/json"||I.endsWith(".json")?e.jsx(ms,{className:"h-4 w-4"}):s.includes("spreadsheet")||s.includes("excel")||I.match(/\.(xls|xlsx|csv)$/)?e.jsx(xs,{className:"h-4 w-4"}):s.includes("presentation")||s.includes("powerpoint")||I.match(/\.(ppt|pptx)$/)?e.jsx(gs,{className:"h-4 w-4"}):s.startsWith("text/")||s.includes("document")||s.includes("word")?e.jsx(_e,{className:"h-4 w-4"}):s.includes("font")||I.match(/\.(ttf|otf|woff|woff2|eot)$/)?e.jsx(fs,{className:"h-4 w-4"}):e.jsx(Je,{className:"h-4 w-4"})},$e=(s,i)=>{const I=i.toLowerCase();return s.startsWith("image/")?s==="image/svg+xml"||I.endsWith(".svg")?e.jsx(us,{className:"h-16 w-16"}):e.jsx(Se,{className:"h-16 w-16"}):s.startsWith("video/")?e.jsx(hs,{className:"h-16 w-16"}):s.startsWith("audio/")?e.jsx(ds,{className:"h-16 w-16"}):s==="application/pdf"||I.endsWith(".pdf")?e.jsx(_e,{className:"h-16 w-16"}):I.match(/\.(js|jsx|ts|tsx|py|java|cpp|c|h|hpp|cs|go|rs|rb|php|swift|kt|scala|r|m|mm)$/)?e.jsx(Qe,{className:"h-16 w-16"}):s==="application/json"||I.endsWith(".json")?e.jsx(ms,{className:"h-16 w-16"}):s.includes("spreadsheet")||s.includes("excel")||I.match(/\.(xls|xlsx|csv)$/)?e.jsx(xs,{className:"h-16 w-16"}):s.includes("presentation")||s.includes("powerpoint")||I.match(/\.(ppt|pptx)$/)?e.jsx(gs,{className:"h-16 w-16"}):s.startsWith("text/")||s.includes("document")||s.includes("word")?e.jsx(_e,{className:"h-16 w-16"}):s.includes("font")||I.match(/\.(ttf|otf|woff|woff2|eot)$/)?e.jsx(fs,{className:"h-16 w-16"}):e.jsx(Je,{className:"h-16 w-16"})},De=s=>{const i=s.name.toLowerCase(),I=s.type.startsWith("image/");return s.type==="image/svg+xml"||i.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:`${se}/api/v1/resources/${s.id}`,alt:s.name,className:"w-full h-full object-contain"})}):I&&s.thumbnailPath?e.jsx("img",{src:`${se}/api/v1/resources/${s.id}/thumbnail`,alt:s.name,className:"w-full h-32 object-cover rounded-md border",onError:de=>{de.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:$e(s.type,s.name)})})},ie=r.filter(s=>{if(!u)return!0;const i=u.toLowerCase();return s.name.toLowerCase().includes(i)||s.metadata.description?.toLowerCase().includes(i)||s.metadata.tags?.some(I=>I.toLowerCase().includes(i))}),ye=Math.ceil(ie.length/q),Ge=(K-1)*q,a=ie.slice(Ge,Ge+q);n.useEffect(()=>{Q(1)},[u]);const O=s=>{s.preventDefault(),s.stopPropagation()},he=s=>{s.preventDefault(),s.stopPropagation(),s.dataTransfer.files&&s.dataTransfer.files.length>0&&o(s.dataTransfer.files)},le=(s,i)=>{if(i.target.closest("button"))return;$(s);const ae=ie.findIndex(de=>de.id===s.id);D(ae>=0?ae:null)},Ne=s=>{window.open(`${se}/api/v1/resources/${s.id}?download=true`)},Me=async(s,i)=>{d(!0);try{const I=await fetch(s);if(!I.ok)throw new Error("Failed to download generated image");const ae=await I.blob(),de=`generated-image-${Date.now()}.png`,ce=new FormData;ce.append("file",ae,de),ce.append("tags",w.join(","));const oe=i?.prompt?`Generated with: "${i.prompt}"${i.model?` (${i.model})`:""}`:S;if(ce.append("description",oe),i?.prompt&&ce.append("generationPrompt",i.prompt),i?.model&&ce.append("generationModel",i.model),!(await fetch(`${se}/api/v1/resources`,{method:"POST",body:ce})).ok)throw new Error("Upload failed");await ee(),V({title:"Image saved",description:"Generated image has been saved to resources"})}catch(I){throw console.error("Failed to save generated image:",I),V({title:"Save failed",description:I instanceof Error?I.message:"Failed to save generated image",variant:"destructive"}),I}finally{d(!1)}},ta=s=>{window.dispatchEvent(new CustomEvent("customize-prompt-in-assistant",{detail:{prompt:s}}))},na=async s=>{d(!0);try{const i=await fetch(s);if(!i.ok)throw new Error("Failed to download generated audio");const I=await i.blob();let ae="mp3";const de=i.headers.get("content-type");de?.includes("wav")?ae="wav":de?.includes("flac")?ae="flac":s.includes(".wav")?ae="wav":s.includes(".flac")&&(ae="flac");const ce=`generated-audio-${Date.now()}.${ae}`,oe=new FormData;if(oe.append("file",I,ce),oe.append("tags",w.join(",")),oe.append("description",S),!(await fetch(`${se}/api/v1/resources`,{method:"POST",body:oe})).ok)throw new Error("Upload failed");await ee(),V({title:"Audio saved",description:"Generated audio has been saved to resources"})}catch(i){throw console.error("Failed to save generated audio:",i),V({title:"Save failed",description:i instanceof Error?i.message:"Failed to save generated audio",variant:"destructive"}),i}finally{d(!1)}},ra=async s=>{d(!0);try{const i=await fetch(s);if(!i.ok)throw new Error("Failed to download generated video");const I=await i.blob();let ae="mp4";(i.headers.get("content-type")?.includes("webm")||s.includes(".webm"))&&(ae="webm");const ce=`generated-video-${Date.now()}.${ae}`,oe=new FormData;if(oe.append("file",I,ce),oe.append("tags",w.join(",")),oe.append("description",S),!(await fetch(`${se}/api/v1/resources`,{method:"POST",body:oe})).ok)throw new Error("Upload failed");await ee(),V({title:"Video saved",description:"Generated video has been saved to resources"})}catch(i){throw console.error("Failed to save generated video:",i),V({title:"Save failed",description:i instanceof Error?i.message:"Failed to save generated video",variant:"destructive"}),i}finally{d(!1)}},la=s=>{if(F===null)return;const i=s==="next"?F+1:F-1;if(i<0||i>=ie.length)return;const I=ie[i];D(i),$(I)};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("h1",{className:"text-2xl font-bold tracking-tight",children:"Resources"}),e.jsx("p",{className:"text-muted-foreground",children:"Upload and generate media assets for your project"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(ga,{children:[e.jsx(va,{asChild:!0,children:e.jsxs(R,{variant:"outline",size:"sm",children:[e.jsx(Fe,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Generate"}),e.jsx(ja,{className:"h-3 w-3 ml-1 opacity-50"})]})}),e.jsxs(wa,{align:"end",className:"min-w-[var(--radix-dropdown-menu-trigger-width)]",children:[e.jsxs(Be,{onClick:()=>P(!0),children:[e.jsx(Se,{className:"h-4 w-4 mr-2"}),"Image"]}),e.jsxs(Be,{onClick:()=>L(!0),children:[e.jsx(xe,{className:"h-4 w-4 mr-2"}),"Audio"]}),e.jsxs(Be,{onClick:()=>M(!0),children:[e.jsx(Ve,{className:"h-4 w-4 mr-2"}),"Video"]})]})]}),e.jsxs(R,{size:"sm",onClick:()=>C(!j),children:[e.jsx(cs,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Upload Resources"})]})]})]}),e.jsx(fe,{open:j,onOpenChange:s=>!s&&l(),children:e.jsxs(pe,{className:"max-w-2xl",children:[e.jsxs(ge,{children:[e.jsx(ve,{children:"Upload Resource"}),e.jsx(ls,{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:O,onDrop:he,onClick:()=>Z.current?.click(),children:[e.jsx(Wa,{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:Z,type:"file",multiple:!0,className:"hidden",onChange:s=>s.target.files&&o(s.target.files)}),y.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{children:["Selected Files (",y.length,")"]}),e.jsx("div",{className:"border rounded-lg p-3 max-h-40 overflow-y-auto space-y-2",children:y.map((s,i)=>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(R,{variant:"ghost",size:"sm",onClick:()=>ne(i),className:"h-6 w-6 p-0 ml-2",children:e.jsx(is,{className:"h-3 w-3"})})]},i))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"tags",children:"Tags"}),e.jsx(Ke,{id:"tags",placeholder:"Type a tag and press Enter",value:x,onChange:s=>N(s.target.value),onKeyDown:G}),w.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:w.map(s=>e.jsxs(Ie,{variant:"secondary",className:"text-xs",children:[s,e.jsx("button",{type:"button",onClick:()=>B(s),className:"ml-1 hover:text-destructive",children:"×"})]},s))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"description",children:"Description"}),e.jsx(je,{id:"description",placeholder:"Brief description of this resource...",value:S,onChange:s=>b(s.target.value),rows:3})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(R,{variant:"outline",onClick:l,disabled:h,children:"Cancel"}),e.jsx(R,{onClick:X,disabled:y.length===0||h,children:h?"Uploading...":`Upload ${y.length>0?`(${y.length})`:""}`})]})]})]})}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs("div",{className:"relative flex-1 w-full",children:[e.jsx(ka,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(Ke,{placeholder:"Search resources...",value:u,onChange:s=>g(s.target.value),className:"pl-8"})]})}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:t?Array.from({length:6}).map((s,i)=>e.jsxs(ze,{className:"animate-pulse",children:[e.jsxs(os,{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(Ue,{children:e.jsx("div",{className:"h-20 bg-muted rounded"})})]},i)):ie.length>0?a.map(s=>e.jsxs(ze,{className:"hover:shadow-lg hover:bg-muted transition-all cursor-pointer",onClick:i=>le(s,i),children:[e.jsxs(os,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[Te(s.type,s.name),e.jsx(Na,{className:"text-sm font-medium truncate",children:s.name})]}),e.jsxs(ba,{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(R,{variant:"ghost",size:"sm",onClick:i=>{i.stopPropagation(),we(s)},title:"Copy path to clipboard",children:e.jsx(He,{className:"h-3 w-3"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:i=>{i.stopPropagation(),Ne(s)},children:e.jsx(Ye,{className:"h-3 w-3"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:i=>{i.stopPropagation(),z(s)},children:e.jsx(is,{className:"h-3 w-3"})})]})]}),e.jsxs(Ue,{className:"pt-0",children:[e.jsx("div",{className:"mb-3",children:De(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(i=>e.jsx(Ie,{variant:"secondary",className:"text-xs",children:i},i))})]})]},s.id)):e.jsx("div",{className:"col-span-full",children:e.jsx(ze,{children:e.jsxs(Ue,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(ya,{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(R,{className:"mt-4",onClick:()=>C(!0),children:[e.jsx(cs,{className:"mr-2 h-4 w-4"}),"Add First Resource"]})]})})})}),ie.length>q&&e.jsxs("div",{className:"flex items-center justify-center gap-4 pt-4 pb-8",children:[e.jsxs(R,{variant:K===1?"outline":"default",size:"sm",onClick:()=>Q(s=>Math.max(1,s-1)),disabled:K===1,children:[e.jsx(Vs,{className:"h-4 w-4 mr-1"}),"Previous"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",K," of ",ye]}),e.jsxs(R,{variant:K===ye?"outline":"default",size:"sm",onClick:()=>Q(s=>Math.min(ye,s+1)),disabled:K===ye,children:["Next",e.jsx(Ls,{className:"h-4 w-4 ml-1"})]})]}),h&&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(Ha,{open:A,onOpenChange:P,onSave:Me,onCustomizeInAssistant:ta}),e.jsx(mt,{open:E,onOpenChange:L,onSave:na}),e.jsx(ht,{open:f,onOpenChange:M,onSave:ra}),e.jsx(xt,{open:!!T,onOpenChange:s=>{s||$(null),s||D(null)},resource:T,onCopyPath:we,onDownload:Ne,onNavigate:la,canNavigatePrev:F!==null&&F>0,canNavigateNext:F!==null&&F<ie.length-1}),e.jsx(fe,{open:!!v,onOpenChange:s=>!s&&z(null),children:e.jsxs(pe,{className:"max-w-md",children:[e.jsxs(ge,{children:[e.jsx(ve,{children:"Delete Resource"}),e.jsxs(ls,{children:["Are you sure you want to delete ",e.jsx("strong",{children:v?.name}),"? This action cannot be undone."]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(R,{variant:"outline",onClick:()=>z(null),children:"Cancel"}),e.jsx(R,{variant:"destructive",onClick:me,children:"Delete"})]})]})})]})}export{Pt as default};
@@ -1,4 +1,4 @@
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-BAEEeZzi.js";import{C as T,b as I,a as z}from"./card-C9ekeZtD.js";import{L as n}from"./label-CRsu1MwQ.js";import{B as _}from"./badge-fHjW-wEe.js";import{P as D}from"./plus-CemYz5Fm.js";/**
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-CKcm92Kn.js";import{C as T,b as I,a as z}from"./card-Cq3qftln.js";import{L as n}from"./label-COUiN2Pd.js";import{B as _}from"./badge-CxMDR-vz.js";import{P as D}from"./plus-DM62ve-p.js";/**
2
2
  * @license lucide-react v0.542.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{H as Qe,ag as Xe,r as m,j as e,B as u,n as O,bg 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,bh 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-BAEEeZzi.js";import{C as J,a as ae,c as re,b as Fe}from"./card-C9ekeZtD.js";import{B as F}from"./badge-fHjW-wEe.js";import{L as v}from"./label-CRsu1MwQ.js";import{S as cs}from"./switch-CDOrVL8G.js";import{T as os,a as ms,b as ne,c as ie}from"./tabs-CP_A6r0A.js";import{R as us}from"./refresh-cw-BL3y7jJo.js";import{P as Pe}from"./plus-CemYz5Fm.js";import{P as Me}from"./play-DhUf2mKM.js";import{P as hs}from"./pause-C7KYrzQF.js";import{C as xs}from"./clock-BxO7xcX9.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...
1
+ import{H as Qe,ag as Xe,r as m,j as e,B as u,n as O,bg 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,bh 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-CKcm92Kn.js";import{C as J,a as ae,c as re,b as Fe}from"./card-Cq3qftln.js";import{B as F}from"./badge-CxMDR-vz.js";import{L as v}from"./label-COUiN2Pd.js";import{S as cs}from"./switch-DC_em8xh.js";import{T as os,a as ms,b as ne,c as ie}from"./tabs-KzUqSzqd.js";import{R as us}from"./refresh-cw-ClU12bdt.js";import{P as Pe}from"./plus-DM62ve-p.js";import{P as Me}from"./play-sWUKmZEy.js";import{P as hs}from"./pause-CupPWZ26.js";import{C as xs}from"./clock-D5nAa1In.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
2
  Example: Focus on performance optimizations`:`Example:
3
3
  Run the following command and append the output to .nut/context/knowledge/runs.md:
4
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};
@@ -1 +1 @@
1
- import{r as p,j as t,I as d,B as m,X as x}from"./index-BAEEeZzi.js";import{B as f}from"./badge-fHjW-wEe.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};
1
+ import{r as p,j as t,I as d,B as m,X as x}from"./index-CKcm92Kn.js";import{B as f}from"./badge-CxMDR-vz.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};
@@ -1 +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-BAEEeZzi.js";import{C as f,a as W}from"./card-C9ekeZtD.js";import{u as X}from"./use-terminal-ZvK-kdxE.js";import{C as _,a as Q,T as V}from"./terminal-preview-CbgoHEQH.js";import{R as Y}from"./refresh-cw-BL3y7jJo.js";import{P as M}from"./play-DhUf2mKM.js";import{C as Z}from"./circle-play-84ZOWBDG.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};
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-CKcm92Kn.js";import{C as f,a as W}from"./card-Cq3qftln.js";import{u as X}from"./use-terminal-C1j4Pa5C.js";import{C as _,a as Q,T as V}from"./terminal-preview-D-pmjUNP.js";import{R as Y}from"./refresh-cw-ClU12bdt.js";import{P as M}from"./play-sWUKmZEy.js";import{C as Z}from"./circle-play-C0yQlVR9.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};
@@ -1,4 +1,4 @@
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-BAEEeZzi.js";import{C as it,a as ot}from"./card-C9ekeZtD.js";import{B as De}from"./badge-fHjW-wEe.js";import{R as ct,a as Ce}from"./radio-group-Dz2cO4IQ.js";import{C as lt}from"./CollapsibleSection-B23j-nZD.js";import{L as he}from"./label-CRsu1MwQ.js";import{u as dt}from"./use-terminal-ZvK-kdxE.js";import{x as mt,a as ut}from"./xterm-DTxiCjtJ.js";import{A as ht}from"./arrow-down-CSpiROUo.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-BL3y7jJo.js";import{P as Se}from"./play-DhUf2mKM.js";import{P as Ae}from"./plus-CemYz5Fm.js";import{Z as bt}from"./zap-DOtH7YrV.js";/**
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-CKcm92Kn.js";import{C as it,a as ot}from"./card-Cq3qftln.js";import{B as De}from"./badge-CxMDR-vz.js";import{R as ct,a as Ce}from"./radio-group-B6pYL4p4.js";import{C as lt}from"./CollapsibleSection-DSatk0YZ.js";import{L as he}from"./label-COUiN2Pd.js";import{u as dt}from"./use-terminal-C1j4Pa5C.js";import{x as mt,a as ut}from"./xterm-DTxiCjtJ.js";import{A as ht}from"./arrow-down-D5JMw0I7.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-ClU12bdt.js";import{P as Se}from"./play-sWUKmZEy.js";import{P as Ae}from"./plus-DM62ve-p.js";import{Z as bt}from"./zap-DGHMgsd8.js";/**
2
2
  * @license lucide-react v0.542.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.