@lovelybunch/api 1.0.75-alpha.8 → 1.0.75-alpha.9

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 (131) hide show
  1. package/dist/lib/terminal/terminal-manager.d.ts +1 -3
  2. package/dist/lib/terminal/terminal-manager.js +1 -52
  3. package/dist/routes/api/v1/ai/route.js +323 -2
  4. package/dist/routes/api/v1/chats/[id]/index.js +2 -1
  5. package/dist/routes/api/v1/chats/[id]/route.d.ts +7 -0
  6. package/dist/routes/api/v1/chats/[id]/route.js +30 -1
  7. package/dist/routes/api/v1/context/index.js +0 -2
  8. package/dist/routes/api/v1/knowledge/[filename]/index.d.ts +1 -0
  9. package/dist/routes/api/v1/knowledge/[filename]/index.js +1 -0
  10. package/dist/routes/api/v1/knowledge/[filename]/route.d.ts +3 -0
  11. package/dist/routes/api/v1/knowledge/[filename]/route.js +254 -0
  12. package/dist/routes/api/v1/knowledge/index.d.ts +1 -0
  13. package/dist/routes/api/v1/knowledge/index.js +1 -0
  14. package/dist/routes/api/v1/knowledge/route.d.ts +3 -0
  15. package/dist/routes/api/v1/knowledge/route.js +176 -0
  16. package/dist/routes/api/v1/mcp/index.js +78 -3
  17. package/dist/routes/api/v1/terminal/[proposalId]/create/route.js +2 -2
  18. package/dist/server-with-static.js +2 -0
  19. package/dist/server.js +2 -0
  20. package/package.json +4 -4
  21. package/static/assets/{ActivityPage-DSSML9J-.js → ActivityPage-OxRci_V2.js} +1 -1
  22. package/static/assets/{ApiKeysSettingsPage-Chw9PNL5.js → ApiKeysSettingsPage-C0evI19e.js} +2 -2
  23. package/static/assets/{ArchitectureEditPage-CIjqkpMz.js → ArchitectureEditPage-D7xcH6dY.js} +4 -4
  24. package/static/assets/{ArchitecturePage-Db__w054.js → ArchitecturePage-pvnlX-NW.js} +1 -1
  25. package/static/assets/{AuthSettingsPage-Bpooi8Z0.js → AuthSettingsPage-Bu0CZ1rY.js} +2 -2
  26. package/static/assets/{CallbackPage-BGLKeyjv.js → CallbackPage-D0lkjxCT.js} +1 -1
  27. package/static/assets/CodePage-BJ4PC5nb.js +2 -0
  28. package/static/assets/{CollapsibleSection-B6RO5o5R.js → CollapsibleSection-Bt_ZLnJc.js} +1 -1
  29. package/static/assets/DashboardPage-BiffPdmj.js +41 -0
  30. package/static/assets/{GitPage-DxjLaRWe.js → GitPage-TrTxZ27J.js} +2 -2
  31. package/static/assets/{GitSettingsPage-tKBXYAFm.js → GitSettingsPage-D7q5xQd_.js} +2 -2
  32. package/static/assets/{IdentityPage-D2yBjeYn.js → IdentityPage-CY0Ak2j0.js} +3 -3
  33. package/static/assets/{ImplementationStepsEditor-DWjDyZzP.js → ImplementationStepsEditor-Ctx0CvbU.js} +2 -2
  34. package/static/assets/IntegrationsSettingsPage-C2wJVdM7.js +1 -0
  35. package/static/assets/{JobDetailPage-BQmTHled.js → JobDetailPage-Phx_IlKX.js} +1 -1
  36. package/static/assets/KnowledgeDetailPage-BdTUfWqj.js +1 -0
  37. package/static/assets/KnowledgeEditPage-D8XK4IUf.js +1 -0
  38. package/static/assets/KnowledgePage-Ci9G7Br-.js +8 -0
  39. package/static/assets/{LoginPage-DptfKsWo.js → LoginPage-Dqxd7cTa.js} +1 -1
  40. package/static/assets/McpSettingsPage-10n35zXi.js +1 -0
  41. package/static/assets/NewKnowledgePage-BlJzzuh7.js +9 -0
  42. package/static/assets/{NewProposalPage-B_sDMBTK.js → NewProposalPage-BP7Ttoxk.js} +2 -2
  43. package/static/assets/{NewSkillPage-Cwy2MSr9.js → NewSkillPage-ByqN--mH.js} +1 -1
  44. package/static/assets/ProjectEditPage-DKJTY2uc.js +11 -0
  45. package/static/assets/{ProjectPage-DgUr4bVU.js → ProjectPage-2VblKCWz.js} +1 -1
  46. package/static/assets/PromptsSettingsPage-B4mOhXuo.js +1 -0
  47. package/static/assets/ProposalDetailPage-m3ysyzpj.js +1 -0
  48. package/static/assets/ProposalEditPage-3XVg_paW.js +1 -0
  49. package/static/assets/{ProposalsPage-C7n4-G05.js → ProposalsPage-B3u0aFFz.js} +3 -3
  50. package/static/assets/ResourceDetailPage-somBLUpC.js +1 -0
  51. package/static/assets/ResourcesPage-2BbjIWfF.js +41 -0
  52. package/static/assets/{RoleEditPage-Cu7ZB3yj.js → RoleEditPage-CLzX7Xhi.js} +1 -1
  53. package/static/assets/{RolePage-Sc-GFiL2.js → RolePage-qXWXZ2FZ.js} +1 -1
  54. package/static/assets/{RulesSettingsPage-DdMCzh9j.js → RulesSettingsPage-BtM7p8F6.js} +3 -3
  55. package/static/assets/SchedulePage-4tFcIBSs.js +4 -0
  56. package/static/assets/{SkillDetailPage-5sDxf3Of.js → SkillDetailPage-CroSdaju.js} +1 -1
  57. package/static/assets/{SkillEditPage-BDd2CtAS.js → SkillEditPage-Czlo8WWT.js} +1 -1
  58. package/static/assets/{SkillsPage-D2G7EfK8.js → SkillsPage-CgULbcI-.js} +2 -2
  59. package/static/assets/{SkillsSettingsPage-1N0JQOYc.js → SkillsSettingsPage-DKtpy7qk.js} +1 -1
  60. package/static/assets/SourceInput-BITn1Y15.js +1 -0
  61. package/static/assets/{TagInput-D_SdcypZ.js → TagInput-BK91_M1N.js} +1 -1
  62. package/static/assets/TerminalPage-8fwvnOo2.js +1 -0
  63. package/static/assets/TerminalSessionPage-BhO5U48p.js +13 -0
  64. package/static/assets/UserPreferencesPage-DrgYEcxO.js +1 -0
  65. package/static/assets/UserSettingsPage-Dj6lKLi8.js +1 -0
  66. package/static/assets/UtilitiesPage-Djr4qT5L.js +1 -0
  67. package/static/assets/{alert-BD5jo3SI.js → alert-CsMvyYoX.js} +1 -1
  68. package/static/assets/{arrow-down-BxcoVp6S.js → arrow-down-BZnfbld8.js} +1 -1
  69. package/static/assets/{arrow-left-CdM_IPng.js → arrow-left-WGBYWq3h.js} +1 -1
  70. package/static/assets/{arrow-up-BOJ6ob9X.js → arrow-up-BByVUPE7.js} +1 -1
  71. package/static/assets/{badge-DEiQk9C9.js → badge-AwLOflf5.js} +1 -1
  72. package/static/assets/{browser-modal-Dp1eMxt6.js → browser-modal-BzGNFfTG.js} +2 -2
  73. package/static/assets/{card-BCFxXzRk.js → card-SN5gKnu7.js} +1 -1
  74. package/static/assets/{chevron-left-C25izNzZ.js → chevron-left-C7uNq9l_.js} +1 -1
  75. package/static/assets/{plus-iamYJu5V.js → chevron-up-CHdIiLxL.js} +2 -2
  76. package/static/assets/{chevrons-up-DqbWMOjv.js → chevrons-up-TXwQuoUN.js} +1 -1
  77. package/static/assets/{circle-alert-CMRMPnbY.js → circle-alert-37E5gU9K.js} +1 -1
  78. package/static/assets/{circle-check-D5wZZPvj.js → circle-check-D02pWDME.js} +1 -1
  79. package/static/assets/{circle-check-big-NI18oHuP.js → circle-check-big-nY4PntB5.js} +1 -1
  80. package/static/assets/{circle-play-BhVU869u.js → circle-play-7EXFLo4F.js} +1 -1
  81. package/static/assets/{circle-x-BXDB-G_q.js → circle-x-By4JoTHB.js} +1 -1
  82. package/static/assets/{clipboard-DC2xmNVx.js → clipboard-BdymjxLO.js} +1 -1
  83. package/static/assets/{clock-CeCp7Pz1.js → clock-HDu44KTo.js} +1 -1
  84. package/static/assets/{download-ZF_XbTIA.js → download-Cv2G2Eg9.js} +1 -1
  85. package/static/assets/{droid-DqWsM2dp.js → droid-CPteN3f9.js} +1 -1
  86. package/static/assets/{external-link-CYBz87-P.js → external-link-DwMXcCCj.js} +1 -1
  87. package/static/assets/{eye-BT8MAvKY.js → eye-DYnjJzdb.js} +1 -1
  88. package/static/assets/{folder-git-2-BE9AIPnj.js → folder-git-2-COeWFPHS.js} +1 -1
  89. package/static/assets/index-9Tv-j_Ga.js +472 -0
  90. package/static/assets/index-GFQ5RqVh.css +2 -0
  91. package/static/assets/{info-DunFSp-x.js → info-BmtuPMhv.js} +1 -1
  92. package/static/assets/{label-vYhfrPMD.js → label-TGqbNfMO.js} +1 -1
  93. package/static/assets/{markdown-editor-BzZ8tCto.js → markdown-editor-ls1JPK_e.js} +1 -1
  94. package/static/assets/{pause-BHonpdnw.js → pause-CAWbvTiL.js} +1 -1
  95. package/static/assets/{play-CCo7tau2.js → play-DF_Qeu0H.js} +1 -1
  96. package/static/assets/{radio-group-Db-pBuyW.js → radio-group-DYTbywtK.js} +1 -1
  97. package/static/assets/{refresh-cw-Bg7vQzOw.js → refresh-cw-BFZxHqbC.js} +1 -1
  98. package/static/assets/{search-CH2zaibZ.js → search-Dr90tbch.js} +1 -1
  99. package/static/assets/select-Cs5qtMYV.js +1 -0
  100. package/static/assets/{switch-CH-VOgPo.js → switch-4TDb6YiQ.js} +1 -1
  101. package/static/assets/{tabs-XeRAjZYR.js → tabs-BrbEvF4V.js} +1 -1
  102. package/static/assets/{tag-CRP5nL5-.js → tag-DrQkepeD.js} +1 -1
  103. package/static/assets/{terminal-preview-DMJMuORo.js → terminal-preview-uuKF9_x4.js} +1 -1
  104. package/static/assets/use-terminal-BG5UXuVE.js +1 -0
  105. package/static/assets/video-DYA2WfbA.js +36 -0
  106. package/static/assets/{zap-BlzMp7dY.js → zap-h9QOsasv.js} +1 -1
  107. package/static/index.html +2 -2
  108. package/static/assets/CodePage-CrokcH-S.js +0 -2
  109. package/static/assets/DashboardPage-BaSQQ8Nv.js +0 -41
  110. package/static/assets/IntegrationsSettingsPage-Bx8-0Ig4.js +0 -1
  111. package/static/assets/KnowledgeDetailPage-QMU2bC3L.js +0 -1
  112. package/static/assets/KnowledgeEditPage-DbMJVcLc.js +0 -1
  113. package/static/assets/KnowledgePage-aU1GxZSZ.js +0 -8
  114. package/static/assets/McpSettingsPage-C3WxFwRB.js +0 -1
  115. package/static/assets/NewKnowledgePage-Cbiswrw_.js +0 -9
  116. package/static/assets/ProjectEditPage-BznWiBBc.js +0 -11
  117. package/static/assets/PromptsSettingsPage-CY0-870a.js +0 -1
  118. package/static/assets/ProposalDetailPage-K4iMXHEg.js +0 -1
  119. package/static/assets/ProposalEditPage-jZOtCMqP.js +0 -1
  120. package/static/assets/ResourcesPage-vB5-XkUv.js +0 -71
  121. package/static/assets/SchedulePage-Bkkf2wA0.js +0 -4
  122. package/static/assets/SourceInput-DlC0zwva.js +0 -1
  123. package/static/assets/TerminalPage--KZ7azvP.js +0 -1
  124. package/static/assets/TerminalSessionPage-ClvxK9ia.js +0 -13
  125. package/static/assets/UserPreferencesPage-CheOH7jZ.js +0 -1
  126. package/static/assets/UserSettingsPage-C8STDvfQ.js +0 -1
  127. package/static/assets/UtilitiesPage-9rTxR2md.js +0 -1
  128. package/static/assets/calendar-Cx5r9R7A.js +0 -6
  129. package/static/assets/index-DVTgTsDa.css +0 -2
  130. package/static/assets/index-hqVgTgRB.js +0 -462
  131. package/static/assets/use-terminal-DuGZuvd2.js +0 -1
@@ -1 +0,0 @@
1
- import{j as e,S as ne,a2 as k,r as b,b5 as q,J as f,a6 as ie,b4 as ae,B as C,I as u,w as R,Q as oe,V as le,F as ce,s as de}from"./index-hqVgTgRB.js";import{C as L,b as T,c as O,d as $,a as U}from"./card-BCFxXzRk.js";import{L as h}from"./label-vYhfrPMD.js";import{B as P}from"./badge-DEiQk9C9.js";import{S as I}from"./switch-CH-VOgPo.js";import{A as B,a as z}from"./alert-BD5jo3SI.js";import{R as me,L as he}from"./browser-modal-Dp1eMxt6.js";import{R as xe}from"./registry-ANRa5WBi.js";import{C as J}from"./circle-alert-CMRMPnbY.js";import{P as Y}from"./plus-iamYJu5V.js";import{C as ve}from"./circle-check-big-NI18oHuP.js";import"./search-CH2zaibZ.js";function K(t){if(t){if(Array.isArray(t)){const n=t.map(l=>{if(typeof l=="string")return l.trim();if(typeof l=="number")return`${l}`}).filter(l=>typeof l=="string"&&l.length>0);return n.length>0?n:void 0}if(typeof t=="string"){const n=t.split(",").map(l=>l.trim()).filter(l=>l.length>0);return n.length>0?n:void 0}}}function V(t,n){const l=t.name||n.name,x=n.description||t.description||"",a={registryId:t.id,registryEndpoint:t.endpoint,registrySource:xe,author:t.author||n.author};(n.version||t.version)&&(a.version=n.version||t.version);const d=K(n.tags)||K(t.tags);d&&(a.tags=d),n.capabilities&&Array.isArray(n.capabilities)&&(a.capabilities=n.capabilities),n.requirements&&typeof n.requirements=="object"&&(a.requirements=n.requirements),n.links&&typeof n.links=="object"&&(a.links=n.links),n.metadata&&typeof n.metadata=="object"&&(a.mcpMetadata=n.metadata);for(const[i,p]of Object.entries(a))p==null&&delete a[i];return{name:l,command:n.configuration.command,args:n.configuration.args,url:n.configuration.url,env:n.configuration.env,enabled:!0,description:x,metadata:Object.keys(a).length>0?a:void 0}}async function pe(t){const n=t.startsWith("http")?t:`https://registry.coconut.dev${t}`,l=await fetch(n,{headers:{Accept:"application/json","User-Agent":"coconut-frontend"}});if(!l.ok)throw new Error(`Failed to fetch MCP server detail: ${l.status}`);return l.json()}function ue({open:t,onOpenChange:n,onImport:l}){return e.jsx(me,{open:t,onOpenChange:n,categoryId:"mcp-servers",title:"Coconut Registry – MCP Servers",confirmLabel:"Add Server",getDetail:x=>pe(x.endpoint),renderPreview:(x,a)=>{if(!a)return e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:"Select an MCP server to preview"});const d=V(x,a),i=d.metadata??{},p=typeof i.version=="string"?i.version:void 0,y=Array.isArray(x.tags)?x.tags:[],w=Array.isArray(i.capabilities)?i.capabilities.filter(j=>typeof j=="string"):[];return e.jsx("div",{className:"h-full min-h-0 overflow-hidden rounded-md border",children:e.jsx(ne,{className:"h-full",children:e.jsx("div",{className:"space-y-6 p-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:x.name}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a.description})]}),p&&e.jsxs(P,{variant:"outline",children:["v",p]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Registry ID: ",e.jsx("span",{className:"font-mono",children:x.id})]}),y.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:y.map(j=>e.jsx(P,{variant:"secondary",children:j},j))}),e.jsxs("div",{className:"space-y-2 rounded-md border p-3 bg-muted/50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"Configuration"}),e.jsx(P,{variant:"outline",className:"text-xs",children:d.url?"HTTP":"stdio"})]}),e.jsxs("div",{className:"space-y-1 text-sm font-mono",children:[d.url?e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"URL:"})," ",e.jsx("span",{className:"text-foreground break-all",children:d.url})]}):e.jsxs(e.Fragment,{children:[d.command&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Command:"})," ",e.jsx("span",{className:"text-foreground",children:d.command})]}),d.args&&d.args.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Args:"})," ",e.jsx("span",{className:"text-foreground",children:d.args.join(" ")})]})]}),d.env&&Object.keys(d.env).length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Env:"})," ",e.jsx("span",{className:"text-foreground",children:JSON.stringify(d.env)})]})]})]}),w.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"Capabilities"}),e.jsx("ul",{className:"list-disc pl-5 text-sm text-muted-foreground space-y-1",children:w.map(j=>e.jsx("li",{children:j},j))})]}),a.documentation&&e.jsxs("div",{className:"space-y-3",children:[a.documentation.overview&&e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium mb-2",children:"Overview"}),e.jsx(k,{className:"[&_.prose]:max-w-none text-sm",children:a.documentation.overview})]}),a.documentation.installation&&e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium mb-2",children:"Installation"}),e.jsx(k,{className:"[&_.prose]:max-w-none text-sm",children:a.documentation.installation})]}),a.documentation.usage&&e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium mb-2",children:"Usage"}),e.jsx(k,{className:"[&_.prose]:max-w-none text-sm",children:a.documentation.usage})]}),a.documentation.examples&&e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium mb-2",children:"Examples"}),e.jsx(k,{className:"[&_.prose]:max-w-none text-sm",children:a.documentation.examples})]})]})]})})})})},onConfirm:async(x,a)=>{const d=V(x,a);await l({summary:x,detail:a,payload:d})}})}function ke(){const[t,n]=b.useState({}),[l,x]=b.useState(!0),[a,d]=b.useState(!1),[i,p]=b.useState({name:"",command:"",args:"",url:"",env:"",description:"",enabled:!0}),[y,w]=b.useState(!1),[j,M]=b.useState(null),[o,N]=b.useState({name:"",command:"",args:"",url:"",env:"",description:"",enabled:!0}),[G,_]=b.useState(!1);b.useEffect(()=>{D()},[]);const D=async()=>{try{x(!0);const s=await q("/api/v1/mcp/raw-config");n(s||{})}catch(s){console.error("Failed to load MCP config:",s),f({title:"Error",description:"Failed to load MCP configuration",variant:"destructive"})}finally{x(!1)}},E=async s=>{try{d(!0),await q("/api/v1/mcp/raw-config",{method:"PUT",body:JSON.stringify(s)}),n(s),f({title:"Success",description:"MCP configuration saved successfully"})}catch(r){console.error("Failed to save MCP config:",r),f({title:"Error",description:"Failed to save MCP configuration",variant:"destructive"})}finally{d(!1)}},W=()=>{if(!i.name){f({title:"Error",description:"Server name is required",variant:"destructive"});return}const s=i.command.trim().length>0,r=i.url.trim().length>0;if(!s&&!r){f({title:"Error",description:"Either Command (for stdio) or URL (for HTTP) is required",variant:"destructive"});return}if(s&&r){f({title:"Error",description:"Provide either Command or URL, not both",variant:"destructive"});return}const c={name:i.name,enabled:i.enabled,description:i.description||void 0};if(s?(c.type="stdio",c.command=i.command,i.args.trim()&&(c.args=i.args.split(" ").filter(g=>g.trim()))):(c.type="http",c.url=i.url),i.env.trim())try{c.env=JSON.parse(i.env)}catch{f({title:"Error",description:"Invalid JSON format for environment variables",variant:"destructive"});return}const v={...t,mcpServers:{...t.mcpServers,[i.name]:c}};E(v),p({name:"",command:"",args:"",url:"",env:"",description:"",enabled:!0}),w(!1)},Q=(s,r)=>{const c={...t,mcpServers:{...t.mcpServers,[s]:{...t.mcpServers[s],enabled:r}}};E(c)},X=s=>{const{[s]:r,...c}=t.mcpServers||{},v={...t,mcpServers:c};E(v)},Z=s=>{const r=t.mcpServers?.[s];r&&(N({name:r.name||s,command:r.command||"",args:r.args?.join(" ")||"",url:r.url||"",env:r.env?JSON.stringify(r.env,null,2):"",description:r.description||"",enabled:r.enabled!==!1}),M(s))},ee=s=>{const r=o.command.trim().length>0,c=o.url.trim().length>0;if(!r&&!c){f({title:"Error",description:"Either Command (for stdio) or URL (for HTTP) is required",variant:"destructive"});return}if(r&&c){f({title:"Error",description:"Provide either Command or URL, not both",variant:"destructive"});return}const v={name:o.name,enabled:o.enabled,description:o.description||void 0};if(r?(v.type="stdio",v.command=o.command,o.args.trim()&&(v.args=o.args.split(" ").filter(A=>A.trim()))):(v.type="http",v.url=o.url),o.env.trim())try{v.env=JSON.parse(o.env)}catch{f({title:"Error",description:"Invalid JSON format for environment variables",variant:"destructive"});return}const{[s]:g,...m}=t.mcpServers||{},S={...t,mcpServers:{...m,[s]:v}};E(S),M(null)},se=()=>{M(null),N({name:"",command:"",args:"",url:"",env:"",description:"",enabled:!0})},F=s=>{const r={...t,globalSettings:{...t.globalSettings,...s}};E(r)},re=async s=>{const{payload:r}=s;let c=r.name.toLowerCase().replace(/\s+/g,"-");const v=t.mcpServers||{};let g=c,m=1;for(;v[g];)g=`${c}-${m}`,m++;const S={name:g,enabled:r.enabled!==!1,description:r.description,env:r.env};r.url?(S.type="http",S.url=r.url):r.command&&(S.type="stdio",S.command=r.command,S.args=r.args);const A={...t,mcpServers:{...t.mcpServers,[g]:S}};await E(A);const te=r.url?"HTTP":"stdio";f({title:"Success",description:`MCP server "${g}" (${te}) added from registry`})};if(l)return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"MCP Settings"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading configuration..."})]})});const H=t.mcpServers||{};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"MCP Settings"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure Model Context Protocol servers and settings."})]}),e.jsx(ie,{}),Object.keys(H).length===0&&!y&&e.jsxs(B,{children:[e.jsx(J,{className:"h-4 w-4"}),e.jsx(z,{children:"No MCP servers configured yet. Add your first server to get started."})]}),e.jsxs(L,{children:[e.jsx(T,{children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs(O,{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"h-5 w-5"}),"MCP Servers"]}),e.jsx($,{className:"hidden sm:block",children:"Configure and manage Model Context Protocol servers for enhanced AI capabilities."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(C,{size:"sm",variant:"outline",onClick:()=>_(!0),children:[e.jsx(he,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Registry"})]}),e.jsxs(C,{size:"sm",onClick:()=>w(!y),variant:y?"outline":"default",children:[e.jsx(Y,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:y?"Cancel":"Add Server"})]})]})]})}),e.jsxs(U,{children:[y&&e.jsxs("div",{className:"space-y-4 p-3 sm:p-4 border rounded-lg mb-4",children:[e.jsx("h4",{className:"font-medium",children:"Add MCP Server"}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"serverName",children:"Server Name"}),e.jsx(u,{id:"serverName",value:i.name,onChange:s=>p({...i,name:s.target.value}),placeholder:"e.g., filesystem-server"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{htmlFor:"serverCommand",children:"Command"}),e.jsx(u,{id:"serverCommand",value:i.command,onChange:s=>p({...i,command:s.target.value}),placeholder:"e.g., npx @modelcontextprotocol/server-filesystem"})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"serverArgs",children:"Arguments (space-separated)"}),e.jsx(u,{id:"serverArgs",value:i.args,onChange:s=>p({...i,args:s.target.value}),placeholder:"e.g., /path/to/allowed/directory"})]})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"serverUrl",children:"URL"}),e.jsx(u,{id:"serverUrl",value:i.url,onChange:s=>p({...i,url:s.target.value}),placeholder:"e.g., https://mcp.example.com/api"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Provide either Command (for stdio) or URL (for HTTP/SSE), not both."})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"serverDescription",children:"Description (optional)"}),e.jsx(u,{id:"serverDescription",value:i.description,onChange:s=>p({...i,description:s.target.value}),placeholder:"Brief description of what this server provides"})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"serverEnv",children:"Environment Variables (JSON)"}),e.jsx(R,{id:"serverEnv",value:i.env,onChange:s=>p({...i,env:s.target.value}),placeholder:'{"KEY": "value", "ANOTHER_KEY": "another_value"}',rows:3})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(I,{id:"serverEnabled",checked:i.enabled,onCheckedChange:s=>p({...i,enabled:s})}),e.jsx(h,{htmlFor:"serverEnabled",children:"Enable server"})]}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsxs(C,{onClick:W,disabled:a,children:[e.jsx(Y,{className:"h-4 w-4 mr-2"}),"Add Server"]}),e.jsx(C,{variant:"outline",onClick:()=>w(!1),children:"Cancel"})]})]}),e.jsx("div",{className:"space-y-4",children:Object.entries(H).map(([s,r])=>{const c=r.enabled!==!1,v=r.name||s,g=j===s;return e.jsx("div",{className:"border rounded-lg",children:g?e.jsxs("div",{className:"space-y-4 p-3 sm:p-4",children:[e.jsx("h4",{className:"font-medium",children:"Edit MCP Server"}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:`edit-name-${s}`,children:"Server Name"}),e.jsx(u,{id:`edit-name-${s}`,value:o.name,onChange:m=>N({...o,name:m.target.value}),placeholder:"e.g., filesystem-server"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{htmlFor:`edit-command-${s}`,children:"Command"}),e.jsx(u,{id:`edit-command-${s}`,value:o.command,onChange:m=>N({...o,command:m.target.value}),placeholder:"e.g., npx @modelcontextprotocol/server-filesystem"})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:`edit-args-${s}`,children:"Arguments (space-separated)"}),e.jsx(u,{id:`edit-args-${s}`,value:o.args,onChange:m=>N({...o,args:m.target.value}),placeholder:"e.g., /path/to/allowed/directory"})]})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:`edit-url-${s}`,children:"URL"}),e.jsx(u,{id:`edit-url-${s}`,value:o.url,onChange:m=>N({...o,url:m.target.value}),placeholder:"e.g., https://mcp.example.com/api"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Provide either Command (for stdio) or URL (for HTTP/SSE), not both."})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:`edit-description-${s}`,children:"Description (optional)"}),e.jsx(u,{id:`edit-description-${s}`,value:o.description,onChange:m=>N({...o,description:m.target.value}),placeholder:"Brief description of what this server provides"})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:`edit-env-${s}`,children:"Environment Variables (JSON)"}),e.jsx(R,{id:`edit-env-${s}`,value:o.env,onChange:m=>N({...o,env:m.target.value}),placeholder:'{"KEY": "value", "ANOTHER_KEY": "another_value"}',rows:3})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(I,{id:`edit-enabled-${s}`,checked:o.enabled,onCheckedChange:m=>N({...o,enabled:m})}),e.jsx(h,{htmlFor:`edit-enabled-${s}`,children:"Enable server"})]}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(C,{onClick:()=>ee(s),disabled:a,children:"Save Changes"}),e.jsx(C,{variant:"outline",onClick:se,children:"Cancel"})]})]}):e.jsx("div",{className:"p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0 flex-1",children:[c?e.jsx(ve,{className:"h-4 w-4 text-green-500 shrink-0 mt-0.5"}):e.jsx(J,{className:"h-4 w-4 text-gray-400 shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h4",{className:"font-medium text-sm sm:text-base",children:v}),e.jsx(P,{variant:c?"default":"secondary",className:"text-xs",children:c?"Enabled":"Disabled"}),e.jsx(P,{variant:"outline",className:"text-xs",children:r.url?"HTTP":"stdio"})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:r.description||r.url||r.command}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 break-all",children:r.url?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium",children:"URL:"})," ",r.url]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium",children:"Command:"})," ",r.command," ",r.args?.join(" ")]})})]})]}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 shrink-0",children:[e.jsx(I,{checked:c,onCheckedChange:m=>Q(s,m),disabled:a}),e.jsx(C,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>Z(s),children:e.jsx(oe,{className:"h-4 w-4"})}),e.jsx(C,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>X(s),disabled:a,children:e.jsx(le,{className:"h-4 w-4"})})]})]})})},s)})})]})]}),e.jsxs(L,{children:[e.jsxs(T,{children:[e.jsxs(O,{className:"flex items-center gap-2",children:[e.jsx(ce,{className:"h-5 w-5"}),"Configuration File"]}),e.jsxs($,{children:["The MCP configuration is stored in ",e.jsx("code",{className:"text-xs bg-muted px-1 py-0.5 rounded",children:".nut/mcp/config.json"})]})]}),e.jsxs(U,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(h,{htmlFor:"configJson",children:"Current Configuration (JSON)"}),e.jsx(R,{id:"configJson",value:JSON.stringify(t,null,2),readOnly:!0,rows:12,className:"font-mono text-sm",placeholder:"Loading configuration..."}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"This is a read-only view of the current configuration. Use the forms above to make changes."})]}),e.jsxs(B,{children:[e.jsx(J,{className:"h-4 w-4"}),e.jsx(z,{children:"Configuration changes are automatically saved to the MCP config file. This file can also be edited manually if you prefer working with JSON directly."})]})]})]}),e.jsxs(L,{children:[e.jsxs(T,{children:[e.jsxs(O,{className:"flex items-center gap-2",children:[e.jsx(de,{className:"h-5 w-5"}),"Global Settings"]}),e.jsx($,{children:"Configure global MCP behavior and connection settings."})]}),e.jsx(U,{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{htmlFor:"timeout",children:"Connection Timeout (ms)"}),e.jsx(u,{id:"timeout",type:"number",value:t.globalSettings?.timeout||3e4,onChange:s=>F({timeout:parseInt(s.target.value)}),placeholder:"30000"})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"retryAttempts",children:"Retry Attempts"}),e.jsx(u,{id:"retryAttempts",type:"number",value:t.globalSettings?.retryAttempts||3,onChange:s=>F({retryAttempts:parseInt(s.target.value)}),placeholder:"3"})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"logLevel",children:"Log Level"}),e.jsxs("select",{id:"logLevel",className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",value:t.globalSettings?.logLevel||"info",onChange:s=>F({logLevel:s.target.value}),children:[e.jsx("option",{value:"debug",children:"Debug"}),e.jsx("option",{value:"info",children:"Info"}),e.jsx("option",{value:"warn",children:"Warning"}),e.jsx("option",{value:"error",children:"Error"})]})]})]})})]}),e.jsx("div",{className:"flex justify-end space-x-2",children:e.jsx(C,{variant:"outline",onClick:D,disabled:l,children:"Reload Configuration"})}),e.jsx(ue,{open:G,onOpenChange:_,onImport:re})]})}export{ke as default};
@@ -1,9 +0,0 @@
1
- import{u as S,a as y,r,j as e,B as j,H as E,a7 as T,L,I as b,A as I}from"./index-hqVgTgRB.js";import{C as i,b as c,c as l,a as d}from"./card-BCFxXzRk.js";import{L as m}from"./label-vYhfrPMD.js";import{M as A}from"./markdown-editor-BzZ8tCto.js";import{T as B}from"./TagInput-D_SdcypZ.js";import{S as P}from"./SourceInput-DlC0zwva.js";import{A as M}from"./arrow-left-CdM_IPng.js";import"./badge-DEiQk9C9.js";import"./plus-iamYJu5V.js";import"./external-link-CYBz87-P.js";function U(){const g=S(),{toast:s}=y(),[u,x]=r.useState(!1),[a,f]=r.useState(""),[n,v]=r.useState(""),[h,w]=r.useState([]),[p,C]=r.useState([]),k=async()=>{if(!a.trim()){s({title:"Error",description:"Please provide a title for the knowledge document",variant:"destructive"});return}if(!n.trim()){s({title:"Error",description:"Please provide content for the knowledge document",variant:"destructive"});return}x(!0);try{const o=await(await fetch(`${I}/api/v1/context/knowledge`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:a.trim(),content:n.trim(),metadata:{tags:h,sources:p}})})).json();if(o.success){s({title:"Success",description:"Knowledge document created successfully"});const N=o.document.filename.replace(".md","");g(`/context/knowledge/${N}`)}else s({title:"Error",description:o.error||"Failed to create knowledge document",variant:"destructive"})}catch(t){console.error("Error creating document:",t),s({title:"Error",description:"Failed to create knowledge document",variant:"destructive"})}finally{x(!1)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{children:e.jsx("h1",{className:"text-3xl font-bold",children:"Create Knowledge Document"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(j,{onClick:k,disabled:u||!a.trim()||!n.trim(),size:"sm",children:[u?e.jsx(E,{className:"w-4 h-4 animate-spin"}):e.jsx(T,{className:"w-4 h-4"}),"Create Document"]}),e.jsx(j,{variant:"ghost",size:"sm",asChild:!0,children:e.jsx(L,{to:"/context/knowledge",className:"flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(M,{className:"h-4 w-4"})})})]})]}),e.jsxs(i,{children:[e.jsx(c,{children:e.jsx(l,{children:"Basic Information"})}),e.jsx(d,{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx(m,{htmlFor:"title",children:"Title *"}),e.jsx(b,{id:"title",value:a,onChange:t=>f(t.target.value),placeholder:"Enter document title...",className:"text-lg"})]})})]}),e.jsxs(i,{children:[e.jsx(c,{children:e.jsx(l,{children:"Metadata"})}),e.jsxs(d,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Tags"}),e.jsx(B,{tags:h,onChange:w,placeholder:"Add a tag"})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Sources"}),e.jsx(P,{sources:p,onChange:C})]})]})]}),e.jsxs(i,{children:[e.jsx(c,{children:e.jsx(l,{children:"Content *"})}),e.jsx(d,{children:e.jsx(A,{value:n,onChange:t=>v(t||""),placeholder:`Enter your knowledge content in Markdown...
2
-
3
- You can use:
4
- - **Bold text**
5
- - *Italic text*
6
- - # Headers
7
- - - Lists
8
- - [Links](https://example.com)
9
- - Code blocks and more!`})})]})]})}export{U as default};
@@ -1,11 +0,0 @@
1
- import{u as L,a as I,r as i,A as S,j as e,B as C,L as M,a7 as A,I as p,h as B,i as D,k as T,l as O,m as j}from"./index-hqVgTgRB.js";import{C as m,a as x,b,c as P}from"./card-BCFxXzRk.js";import{L as l}from"./label-vYhfrPMD.js";import{M as V}from"./markdown-editor-BzZ8tCto.js";import{A as W}from"./arrow-left-CdM_IPng.js";import{C as z}from"./circle-check-big-NI18oHuP.js";function K(){const E=L(),{toast:d}=I(),[a,v]=i.useState({project:{name:"",description:"",website:"",version:"1.0.0",stage:"development"}}),[u,g]=i.useState(""),[F,f]=i.useState(!0),[y,w]=i.useState(!1);i.useEffect(()=>{fetch(`${S}/api/v1/context/project`).then(t=>t.json()).then(t=>{if(t.success){const s=t.document;v({project:{name:s.metadata.project?.name||"",description:s.metadata.project?.description||"",website:s.metadata.project?.website||s.metadata.project?.repository||"",version:s.metadata.project?.version||"1.0.0",stage:s.metadata.project?.stage||"development"}}),g(s.content.trim())}f(!1)}).catch(t=>{console.error("Failed to load context:",t),d({title:"Error",description:"Failed to load project context",variant:"destructive"}),f(!1)})},[d]);const k=async()=>{w(!0);try{const s={project:Object.fromEntries(Object.entries(a.project).map(([o,r])=>[o,typeof r=="string"?r.trim():r]))},n=await(await fetch(`${S}/api/v1/context/project`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:u,metadata:s})})).json();if(n.success)d({title:"Success",description:"Project context saved successfully",action:e.jsx(z,{className:"h-4 w-4"})}),E("/context/project");else throw new Error(n.error||"Failed to save context")}catch(t){console.error("Save error:",t),d({title:"Error",description:"Failed to save project context",variant:"destructive"})}finally{w(!1)}},c=(t,s)=>{v(N=>{const n={...N},o=t.split(".");let r=n;for(let h=0;h<o.length-1;h++)r=r[o[h]];return r[o[o.length-1]]=s,n})};return F?e.jsx("div",{className:"space-y-6",children:e.jsx(m,{children:e.jsx(x,{className:"pt-6",children:e.jsx("div",{className:"text-center",children:e.jsx("p",{children:"Loading..."})})})})}):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:"Edit Project Overview"}),e.jsx("p",{className:"text-muted-foreground",children:"Edit project information and documentation"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs(M,{to:"/context/project",children:[e.jsx(W,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Back"})]})}),e.jsxs(C,{size:"sm",onClick:k,disabled:y,children:[e.jsx(A,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:y?"Saving...":"Save"})]})]})]}),e.jsxs(m,{children:[e.jsx(b,{children:e.jsx(P,{children:"Project Information"})}),e.jsxs(x,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"project-name",children:"Project Name"}),e.jsx(p,{id:"project-name",value:a.project.name,onChange:t=>c("project.name",t.target.value),placeholder:"My Awesome Project"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"project-version",children:"Version"}),e.jsx(p,{id:"project-version",value:a.project.version,onChange:t=>c("project.version",t.target.value),placeholder:"1.0.0"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"project-description",children:"Description"}),e.jsx(p,{id:"project-description",value:a.project.description,onChange:t=>c("project.description",t.target.value),placeholder:"Brief description of what this project does"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"project-website",children:"Website"}),e.jsx(p,{id:"project-website",value:a.project.website,onChange:t=>c("project.website",t.target.value),placeholder:"https://yourproject.com"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"project-stage",children:"Development Stage"}),e.jsxs(B,{value:a.project.stage,onValueChange:t=>c("project.stage",t),children:[e.jsx(D,{children:e.jsx(T,{placeholder:"Select stage"})}),e.jsxs(O,{children:[e.jsx(j,{value:"prototype",children:"Prototype"}),e.jsx(j,{value:"development",children:"Development"}),e.jsx(j,{value:"mvp",children:"MVP"}),e.jsx(j,{value:"production",children:"Production"})]})]})]})]})]})]}),e.jsxs(m,{children:[e.jsx(b,{children:e.jsx(P,{children:"Documentation"})}),e.jsx(x,{children:e.jsx(V,{value:u,onChange:t=>g(t||""),placeholder:`Write your project documentation in markdown...
2
-
3
- ## What is this project?
4
-
5
- Describe what your project does, who it's for, and why it exists.
6
-
7
- ## Current State
8
-
9
- - Development stage
10
- - Key features that are working
11
- - What's planned for next releases`,height:800})})]})]})}export{K as default};
@@ -1 +0,0 @@
1
- import{j as e,a6 as p,B as r,Q as h,am as j,V as u,I as l,h as g,i as f,k as v,l as N,m as y}from"./index-hqVgTgRB.js";import{C as t,b as i,c as n,d as c,a as d}from"./card-BCFxXzRk.js";import{L as a}from"./label-vYhfrPMD.js";import{B as o}from"./badge-DEiQk9C9.js";import{P as w}from"./plus-iamYJu5V.js";import{E as b}from"./eye-BT8MAvKY.js";import{D as C}from"./download-ZF_XbTIA.js";function T(){const m=[{id:"1",name:"Code Review Assistant",description:"Prompt for AI agents to perform thorough code reviews",category:"Code Review",usage:"cursor-cli, claude-code",lastUpdated:"2 days ago",active:!0},{id:"2",name:"Architecture Advisor",description:"System prompt for architectural decision guidance",category:"Architecture",usage:"gemini-cli, claude-code",lastUpdated:"1 week ago",active:!0},{id:"3",name:"Bug Analysis Expert",description:"Specialized prompt for debugging and error analysis",category:"Debugging",usage:"cursor-cli",lastUpdated:"3 days ago",active:!1},{id:"4",name:"Documentation Generator",description:"Prompt for generating comprehensive code documentation",category:"Documentation",usage:"github-copilot, claude-code",lastUpdated:"5 days ago",active:!0}],x=["Code Review","Architecture","Debugging","Documentation","Testing","Refactoring","Security","Performance"];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"System Prompts"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage system prompts used by AI agents and integrations for consistent behavior."})]}),e.jsx(p,{}),e.jsxs(t,{children:[e.jsx(i,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(n,{children:"Prompt Library"}),e.jsx(c,{children:"Pre-configured prompts for different AI agents and use cases."})]}),e.jsxs(r,{size:"sm",children:[e.jsx(w,{className:"h-4 w-4 mr-2"}),"New Prompt"]})]})}),e.jsx(d,{children:e.jsx("div",{className:"space-y-4",children:m.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-4 border rounded-lg",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("h4",{className:"font-medium",children:s.name}),e.jsx(o,{variant:s.active?"default":"secondary",children:s.active?"Active":"Inactive"}),e.jsx(o,{variant:"outline",children:s.category})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s.description}),e.jsxs("div",{className:"flex items-center space-x-4 mt-2",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Used by: ",s.usage]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Updated: ",s.lastUpdated]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(r,{variant:"outline",size:"sm",children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",children:e.jsx(h,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",children:e.jsx(j,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",children:e.jsx(u,{className:"h-4 w-4"})})]})]},s.id))})})]}),e.jsxs(t,{children:[e.jsxs(i,{children:[e.jsx(n,{children:"Create New Prompt"}),e.jsx(c,{children:"Design a new system prompt for your AI agents and integrations."})]}),e.jsxs(d,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(a,{htmlFor:"promptName",children:"Prompt Name"}),e.jsx(l,{id:"promptName",placeholder:"Enter prompt name"})]}),e.jsxs("div",{children:[e.jsx(a,{htmlFor:"promptCategory",children:"Category"}),e.jsxs(g,{children:[e.jsx(f,{children:e.jsx(v,{placeholder:"Select category"})}),e.jsx(N,{children:x.map(s=>e.jsx(y,{value:s.toLowerCase(),children:s},s))})]})]})]}),e.jsxs("div",{children:[e.jsx(a,{htmlFor:"promptDescription",children:"Description"}),e.jsx(l,{id:"promptDescription",placeholder:"Brief description of the prompt's purpose"})]}),e.jsxs("div",{children:[e.jsx(a,{htmlFor:"targetIntegrations",children:"Target Integrations"}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:["cursor-cli","claude-code","gemini-cli","github-copilot"].map(s=>e.jsxs("label",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",className:"rounded"}),e.jsx("span",{className:"text-sm",children:s})]},s))})]}),e.jsxs("div",{children:[e.jsx(a,{htmlFor:"promptContent",children:"Prompt Content"}),e.jsx("textarea",{id:"promptContent",className:"w-full min-h-[200px] p-3 border rounded-md font-mono text-sm",placeholder:"You are an expert code reviewer. Your task is to..."})]}),e.jsxs("div",{children:[e.jsx(a,{htmlFor:"promptVariables",children:"Variables (JSON format)"}),e.jsx("textarea",{id:"promptVariables",className:"w-full min-h-[100px] p-3 border rounded-md font-mono text-sm",placeholder:'{"language": "typescript", "framework": "react", "style": "functional"}'})]}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(r,{variant:"outline",children:"Preview"}),e.jsx(r,{variant:"outline",children:"Save as Draft"}),e.jsx(r,{children:"Save & Activate"})]})]})]}),e.jsxs(t,{children:[e.jsxs(i,{children:[e.jsx(n,{children:"Prompt Templates"}),e.jsx(c,{children:"Import and export prompt templates for sharing across teams."})]}),e.jsxs(d,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(r,{variant:"outline",size:"sm",children:[e.jsx(C,{className:"h-4 w-4 mr-2"}),"Import Template"]}),e.jsx(r,{variant:"outline",size:"sm",children:"Export All Prompts"}),e.jsx(r,{variant:"outline",size:"sm",children:"Export Selected"})]}),e.jsx("div",{className:"p-4 border-2 border-dashed rounded-lg text-center",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Drag and drop prompt template files here, or click to browse"})})]})]})]})}export{T as default};
@@ -1 +0,0 @@
1
- import{P as ae,u as re,r as l,a as ne,j as e,B as n,L as c,Q as le,R as ie,U as oe,V as ce,W as de,Y as me,Z as he,_ as xe,$ as pe,a0 as ue,a1 as je,a2 as O,a3 as I,q as fe,D as F,a4 as R,b as B,d as V,f as z,g as H,h as ge,i as ve,k as Ne,l as Ce,m as ye,a5 as _,w as we,a6 as be,A as f}from"./index-hqVgTgRB.js";import{c as Se}from"./clipboard-B9ndUJKl.js";import{C as d,b as h,a as m,c as p,d as J}from"./card-BCFxXzRk.js";import{B as x}from"./badge-DEiQk9C9.js";import{L as q}from"./label-vYhfrPMD.js";import{g as M,C as De,a as Ae}from"./status-utils-BDOyevaX.js";import{A as w}from"./arrow-left-CdM_IPng.js";import{C as ke,a as Te}from"./clipboard-DC2xmNVx.js";import{I as Ee}from"./info-DunFSp-x.js";import{D as Pe}from"./download-ZF_XbTIA.js";import{C as $e}from"./calendar-Cx5r9R7A.js";import{C as Ue}from"./clock-CeCp7Pz1.js";function Q(r){switch(r){case"high":case"critical":return"destructive";case"medium":return"secondary";default:return"outline"}}function Me(){const{id:r}=ae(),W=re(),[s,g]=l.useState(null),[Y,b]=l.useState(!0),[v,S]=l.useState(null),[D,A]=l.useState(!1),[k,T]=l.useState(!1),[E,P]=l.useState(!1),[u,N]=l.useState(""),[Z,C]=l.useState(!1),[G,y]=l.useState(!1),[j,$]=l.useState("draft"),[K,U]=l.useState(!1),{toast:L}=ne();l.useEffect(()=>{async function t(){if(r)try{b(!0);const o=await(await fetch(`${f}/api/v1/proposals/${r}`)).json();o.success?g(o.data):S(o.error?.message||"Failed to fetch proposal")}catch(a){S(a instanceof Error?a.message:"Unknown error")}finally{b(!1)}}t()},[r]);const X=async()=>{if(r){A(!0);try{const a=await(await fetch(`${f}/api/v1/proposals/${r}`,{method:"DELETE"})).json();a.success?W("/proposals"):alert(a.error?.message||"Failed to delete proposal")}catch(t){alert(`Error deleting proposal: ${t instanceof Error?t.message:"Unknown error"}`)}finally{A(!1)}}},ee=async()=>{if(!(!s||!r||j===s.status)){T(!0);try{const a=await(await fetch(`${f}/api/v1/proposals/${r}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:j})})).json();a.success?(g(a.data),C(!1)):alert(a.error?.message||"Failed to update status")}catch(t){alert(`Error updating status: ${t instanceof Error?t.message:"Unknown error"}`)}finally{T(!1)}}},se=async()=>{if(!(!s||!r||!u.trim())){P(!0);try{const t={id:`comment-${Date.now()}`,content:u,author:"current-user",createdAt:new Date().toISOString()},a=[...s.comments||[],t],i=await(await fetch(`${f}/api/v1/proposals/${r}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({comments:a})})).json();i.success?(g(i.data),N(""),y(!1)):alert(i.error?.message||"Failed to add comment")}catch(t){alert(`Error adding comment: ${t instanceof Error?t.message:"Unknown error"}`)}finally{P(!1)}}},te=()=>{if(!s)return;const t={...s,exportedAt:new Date().toISOString()},a=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),o=URL.createObjectURL(a),i=document.createElement("a");i.href=o,i.download=`proposal-${s.id}.json`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(o)};return Y?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"h-8 bg-muted rounded w-3/4 animate-pulse"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(n,{variant:"ghost",size:"sm",asChild:!0,className:"px-2 hover:bg-transparent",children:e.jsx(c,{to:"/proposals",className:"flex items-center text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(w,{className:"h-4 w-4"})})})})]}),e.jsxs(d,{children:[e.jsx(h,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-8 bg-muted rounded w-3/4 animate-pulse"}),e.jsx("div",{className:"h-4 bg-muted rounded w-1/2 animate-pulse"})]})}),e.jsx(m,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-4 bg-muted rounded animate-pulse"}),e.jsx("div",{className:"h-4 bg-muted rounded w-5/6 animate-pulse"}),e.jsx("div",{className:"h-4 bg-muted rounded w-4/6 animate-pulse"})]})})]})]}):v||!s?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{children:e.jsx("h3",{className:"text-lg font-semibold text-destructive",children:v||"Proposal not found"})}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(n,{variant:"ghost",size:"sm",asChild:!0,className:"px-2 hover:bg-transparent",children:e.jsx(c,{to:"/proposals",className:"flex items-center text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(w,{className:"h-4 w-4"})})})})]}),e.jsx(d,{children:e.jsx(m,{className:"pt-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx("h3",{className:"text-lg font-semibold text-destructive",children:v||"Proposal not found"}),e.jsxs("p",{className:"text-muted-foreground mt-2",children:['The proposal with ID "',r,'" could not be found.']}),e.jsx(n,{asChild:!0,className:"mt-4",children:e.jsx(c,{to:"/proposals",children:"Back to Proposals"})})]})})})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold tracking-tight min-w-0",children:s.title||s.intent}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(n,{variant:"ghost",size:"sm",asChild:!0,children:e.jsx(c,{to:"/proposals",className:"flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(w,{className:"h-4 w-4"})})}),e.jsx(n,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs(c,{to:`/proposals/${r}/edit`,children:[e.jsx(le,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Edit"})]})}),e.jsxs(ie,{children:[e.jsx(oe,{asChild:!0,children:e.jsxs(n,{variant:"destructive",size:"sm",disabled:D,children:[e.jsx(ce,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:D?"Deleting...":"Delete"})]})}),e.jsxs(de,{children:[e.jsxs(me,{children:[e.jsx(he,{children:"Are you absolutely sure?"}),e.jsxs(xe,{children:["This action cannot be undone. This will permanently delete the change proposal",e.jsxs("span",{className:"font-semibold",children:[' "',s.title||s.intent,'"']})," and remove it from the system."]})]}),e.jsxs(pe,{children:[e.jsx(ue,{children:"Cancel"}),e.jsx(je,{onClick:X,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete Proposal"})]})]})]})]})]}),e.jsxs("button",{type:"button",onClick:async()=>{const t=`.nut/proposals/${s.id}.md`;try{await Se(t),U(!0),L({title:"Copied!",description:`${t} copied to clipboard`}),setTimeout(()=>U(!1),2e3)}catch(a){console.error("Failed to copy path:",a),L({title:"Error",description:"Failed to copy to clipboard",variant:"destructive"})}},className:"inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors font-mono",children:[e.jsx("span",{children:`.nut/proposals/${s.id}.md`}),K?e.jsx(ke,{className:"h-3.5 w-3.5"}):e.jsx(Te,{className:"h-3.5 w-3.5"})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[e.jsxs(d,{children:[e.jsx(h,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(p,{children:"Task Details"}),e.jsxs("div",{className:"flex gap-2",children:[s.metadata.priority&&e.jsx(x,{variant:Q(s.metadata.priority),children:s.metadata.priority}),e.jsx(x,{variant:M(s.status),children:s.status})]})]})}),e.jsx(m,{className:"space-y-4",children:s.content?e.jsx(O,{children:s.content}):e.jsx("p",{className:"text-muted-foreground",children:"No detailed content available for this proposal."})})]}),s.planSteps&&s.planSteps.length>0&&e.jsxs(d,{children:[e.jsxs(h,{children:[e.jsx(p,{children:"Implementation Steps"}),e.jsxs(J,{children:[s.planSteps.length," step",s.planSteps.length!==1?"s":""," planned"]})]}),e.jsx(m,{children:e.jsx("div",{className:"space-y-3",children:s.planSteps.map((t,a)=>e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full bg-muted text-xs font-medium",children:a+1}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:t.description}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:e.jsx(x,{variant:"outline",className:"text-xs",children:t.status})})]})]},t.id))})})]}),s.comments&&s.comments.length>0&&e.jsxs(d,{children:[e.jsxs(h,{children:[e.jsx(p,{children:"Comments"}),e.jsxs(J,{children:[s.comments.length," comment",s.comments.length!==1?"s":""]})]}),e.jsx(m,{children:e.jsx("div",{className:"space-y-4",children:s.comments.map((t,a)=>e.jsxs("div",{className:"border-l-2 border-muted pl-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(I,{className:"h-3 w-3"}),e.jsx("span",{children:t.author}),e.jsx("span",{children:"•"}),e.jsx("span",{children:new Date(t.createdAt).toLocaleString()})]}),e.jsx(O,{className:"prose-sm prose-p:mb-2 prose-ul:my-2 prose-ol:my-2",children:t.content})]},t.id||a))})})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(d,{children:[e.jsx(h,{children:e.jsx(p,{children:"Task Actions"})}),e.jsxs(m,{className:"space-y-2",children:[e.jsx(n,{variant:"default",className:"w-full justify-start bg-blue-600 hover:bg-blue-700",asChild:!0,children:e.jsxs(c,{to:`/terminal/${r}?reviewOnly=true`,children:[e.jsx(Ee,{className:"h-4 w-4 mr-2"}),"Review Task"]})}),e.jsx(n,{variant:"default",className:"w-full justify-start",asChild:!0,children:e.jsxs(c,{to:`/terminal/${r}?startOnly=true`,children:[e.jsx(fe,{className:"h-4 w-4 mr-2"}),"Prepare Agent"]})}),e.jsxs(F,{open:Z,onOpenChange:C,children:[e.jsx(R,{asChild:!0,children:e.jsx(n,{variant:"outline",className:"w-full justify-start",onClick:()=>$(s?.status||"draft"),children:"Change Status"})}),e.jsxs(B,{children:[e.jsxs(V,{children:[e.jsx(z,{children:"Change Task Status"}),e.jsx(H,{children:"Update the status of this task."})]}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx(q,{htmlFor:"status",children:"Status"}),e.jsxs(ge,{value:j,onValueChange:t=>$(t),children:[e.jsx(ve,{children:e.jsx(Ne,{placeholder:"Select status"})}),e.jsx(Ce,{children:De.map(t=>e.jsx(ye,{value:t,children:Ae(t)},t))})]})]})}),e.jsxs(_,{children:[e.jsx(n,{variant:"outline",onClick:()=>C(!1),children:"Cancel"}),e.jsx(n,{onClick:ee,disabled:k||j===s?.status,children:k?"Updating...":"Update Status"})]})]})]}),e.jsxs(F,{open:G,onOpenChange:y,children:[e.jsx(R,{asChild:!0,children:e.jsx(n,{variant:"outline",className:"w-full justify-start",children:"Add Comment"})}),e.jsxs(B,{children:[e.jsxs(V,{children:[e.jsx(z,{children:"Add Comment"}),e.jsx(H,{children:"Add a comment to this change proposal."})]}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx(q,{htmlFor:"comment",children:"Comment"}),e.jsx(we,{id:"comment",placeholder:"Enter your comment...",value:u,onChange:t=>N(t.target.value),rows:4})]})}),e.jsxs(_,{children:[e.jsx(n,{variant:"outline",onClick:()=>{y(!1),N("")},children:"Cancel"}),e.jsx(n,{onClick:se,disabled:E||!u.trim(),children:E?"Adding...":"Add Comment"})]})]})]}),e.jsxs(n,{variant:"outline",className:"w-full justify-start",onClick:te,children:[e.jsx(Pe,{className:"h-4 w-4 mr-2"}),"Export"]})]})]}),e.jsxs(d,{children:[e.jsx(h,{children:e.jsx(p,{children:"Information"})}),e.jsxs(m,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(I,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:"Author:"}),e.jsx("span",{children:s.author.name})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx($e,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:"Created:"}),e.jsx("span",{children:new Date(s.metadata.createdAt).toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ue,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:"Updated:"}),e.jsx("span",{children:new Date(s.metadata.updatedAt).toLocaleString()})]}),e.jsx(be,{}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-sm",children:"Status:"}),e.jsx("div",{className:"mt-1",children:e.jsx(x,{variant:M(s.status),children:s.status})})]}),s.metadata.priority&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-sm",children:"Priority:"}),e.jsx("div",{className:"mt-1",children:e.jsx(x,{variant:Q(s.metadata.priority),children:s.metadata.priority})})]}),s.metadata.tags&&s.metadata.tags.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-sm",children:"Tags:"}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:s.metadata.tags.map(t=>e.jsx(x,{variant:"outline",className:"text-xs",children:t},t))})]})]})]})]})]})]})}export{Me as default};
@@ -1 +0,0 @@
1
- import{P as R,u as U,a as H,r as o,A as k,j as e,B as m,L as x,I as O,h as A,i as L,k as D,l as F,m as r,X as V,a7 as _}from"./index-hqVgTgRB.js";import{L as j}from"./label-vYhfrPMD.js";import{C as f,b as I,a as v,c as q,d as J}from"./card-BCFxXzRk.js";import{M as K}from"./markdown-editor-BzZ8tCto.js";import{C as W}from"./CollapsibleSection-B6RO5o5R.js";import{I as X,L as G}from"./ImplementationStepsEditor-DWjDyZzP.js";import{T as Q}from"./TagInput-D_SdcypZ.js";import{A as N}from"./arrow-left-CdM_IPng.js";import"./plus-iamYJu5V.js";import"./badge-DEiQk9C9.js";function oe(){const{id:i}=R(),$=U(),{toast:y}=H(),[z,S]=o.useState(!0),[h,C]=o.useState(!1),[w,b]=o.useState(null),[l,d]=o.useState({title:"",description:"",priority:"medium",status:"draft",author:{id:"current-user",name:"Current User",email:"user@example.com"}}),[p,E]=o.useState([]),[P,T]=o.useState([]);o.useEffect(()=>{i&&B()},[i]);const B=async()=>{try{S(!0);const t=await fetch(`${k}/api/v1/proposals/${i}`),s=await t.json();if(s.success||s.data||t.ok){const a=s.data||s;d({title:a.title||a.intent||"",description:a.content||"",priority:a.metadata?.priority||"medium",status:a.status||"draft",author:{id:a.author?.id||"current-user",name:a.author?.name||"Current User",email:a.author?.email||"user@example.com"}});const g=Array.isArray(a.planSteps)?a.planSteps:[];E(g.map((c,u)=>({id:c.id||`step-${u+1}`,description:c.description||"",status:c.status||"pending"}))),T(a.metadata?.tags||[])}else b(s.error?.message||"Failed to fetch proposal")}catch(t){b(t instanceof Error?t.message:"An error occurred")}finally{S(!1)}},M=async t=>{t.preventDefault(),C(!0);try{const s=p.map(n=>({id:n.id,description:n.description.trim(),status:n.status})).filter(n=>n.description.length>0),a=P.map(n=>n.trim()).filter(n=>n.length>0),g={title:l.title,status:l.status,planSteps:s,metadata:{priority:l.priority,tags:a},content:l.description},c=await fetch(`${k}/api/v1/proposals/${i}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)}),u=await c.json();if(u.success||c.ok)y({title:"Success",description:"Proposal updated successfully."}),$(`/proposals/${i}`);else throw new Error(u.error?.message||"Failed to update proposal")}catch(s){y({title:"Error",description:`Failed to update proposal: ${s instanceof Error?s.message:"An error occurred"}`,variant:"destructive"})}finally{C(!1)}};return z?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:"Edit Proposal"}),e.jsx("p",{className:"text-muted-foreground",children:"Loading proposal data..."})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(m,{variant:"ghost",size:"sm",asChild:!0,className:"px-2 hover:bg-transparent",children:e.jsx(x,{to:`/proposals/${i}`,className:"flex items-center text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(N,{className:"h-4 w-4"})})})})]}),e.jsxs(f,{children:[e.jsx(I,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-6 bg-muted rounded w-1/2 animate-pulse"}),e.jsx("div",{className:"h-4 bg-muted rounded w-3/4 animate-pulse"})]})}),e.jsx(v,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"h-10 bg-muted rounded animate-pulse"}),e.jsx("div",{className:"h-64 bg-muted rounded animate-pulse"})]})})]})]}):w?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{children:e.jsx("h3",{className:"text-lg font-semibold text-destructive",children:"Error"})}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(m,{variant:"ghost",size:"sm",asChild:!0,className:"px-2 hover:bg-transparent",children:e.jsx(x,{to:"/proposals",className:"flex items-center text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(N,{className:"h-4 w-4"})})})})]}),e.jsx(f,{children:e.jsx(v,{className:"pt-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx("h3",{className:"text-lg font-semibold text-destructive",children:"Error"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:w})]})})})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:"Edit Proposal"}),e.jsxs("p",{className:"text-muted-foreground",children:["Editing ",i]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(m,{variant:"ghost",size:"sm",asChild:!0,children:e.jsx(x,{to:`/proposals/${i}`,className:"flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(N,{className:"h-4 w-4"})})})})]}),e.jsx("form",{onSubmit:M,children:e.jsxs(f,{children:[e.jsxs(I,{children:[e.jsx(q,{children:"Task Details"}),e.jsx(J,{children:"Update the information for your change proposal"})]}),e.jsxs(v,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"title",children:"Title *"}),e.jsx(O,{id:"title",placeholder:"Brief description of what you want to change",value:l.title,onChange:t=>d(s=>({...s,title:t.target.value})),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"description",children:"Description"}),e.jsx(K,{value:l.description,onChange:t=>d(s=>({...s,description:t||""})),placeholder:"Write your proposal description in markdown...",height:400})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"status",children:"Status"}),e.jsxs(A,{value:l.status,onValueChange:t=>d(s=>({...s,status:t})),children:[e.jsx(L,{children:e.jsx(D,{placeholder:"Select status"})}),e.jsxs(F,{children:[e.jsx(r,{value:"draft",children:"Draft"}),e.jsx(r,{value:"proposed",children:"Proposed"}),e.jsx(r,{value:"in-review",children:"In Review"}),e.jsx(r,{value:"approved",children:"Approved"}),e.jsx(r,{value:"code-complete",children:"Code Complete"}),e.jsx(r,{value:"rejected",children:"Rejected"}),e.jsx(r,{value:"merged",children:"Merged"})]})]})]}),e.jsx(W,{defaultOpen:!0,icon:e.jsx(G,{className:"h-4 w-4"}),title:"Optional Implementation Detail",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"priority",children:"Priority"}),e.jsxs(A,{value:l.priority,onValueChange:t=>d(s=>({...s,priority:t})),children:[e.jsx(L,{children:e.jsx(D,{placeholder:"Select priority"})}),e.jsxs(F,{children:[e.jsx(r,{value:"low",children:"Low"}),e.jsx(r,{value:"medium",children:"Medium"}),e.jsx(r,{value:"high",children:"High"}),e.jsx(r,{value:"critical",children:"Critical"})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Implementation Steps"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Keep the implementation plan accurate as work progresses."})]}),p.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[p.length," step",p.length===1?"":"s"]})]}),e.jsx(X,{steps:p,onChange:E,disabled:h})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Tags"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Tags power filtering and discovery across the proposal list."}),e.jsx(Q,{tags:P,onChange:T,disabled:h,placeholder:"Add a tag (e.g. backend, rollout)"})]})]})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(m,{type:"button",variant:"outline",asChild:!0,children:e.jsxs(x,{to:`/proposals/${i}`,children:[e.jsx(V,{className:"mr-2 h-4 w-4"}),"Cancel"]})}),e.jsx(m,{type:"submit",disabled:h||!l.title,children:h?e.jsx(e.Fragment,{children:"Saving..."}):e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"mr-2 h-4 w-4"}),"Save Changes"]})})]})]})]})})]})}export{oe as ProposalEditPage};
@@ -1,71 +0,0 @@
1
- import{c as oe,r as t,j as e,D as pe,b as ge,d as ve,f as je,H as le,S as is,B as R,al as os,n as Ee,a as $e,A as ae,w as ye,h as W,i as B,k as $,l as U,m as G,ag as Oe,x as me,an as ca,ao as da,ap as ua,aq as be,ar as Fe,as as _e,at as ma,au as Bs,av as ha,aw as xa,e as fa,I as We,am as Xe,X as cs,C as $s,F as we,ax as Ze,ay as pa,az as ga,aA as va,a9 as ja,aa as ya,v as ba,ab as wa,ae as Je,g as ds,V as us,aB as Na}from"./index-hqVgTgRB.js";import{C as Ye,b as ms,a as Qe,c as _a,d as Sa}from"./card-BCFxXzRk.js";import{L as C}from"./label-vYhfrPMD.js";import{B as Me}from"./badge-DEiQk9C9.js";import{c as Ca}from"./clipboard-B9ndUJKl.js";import{R as Us}from"./registry-ANRa5WBi.js";import{D as es}from"./download-ZF_XbTIA.js";import{C as zs}from"./chevron-left-C25izNzZ.js";import{C as ka}from"./calendar-Cx5r9R7A.js";import{T as Pa}from"./tag-CRP5nL5-.js";import{P as hs}from"./plus-iamYJu5V.js";import{S as Ea}from"./search-CH2zaibZ.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 Ma=[["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"}]],xs=oe("file-audio",Ma);/**
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 Fa=[["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"}]],ss=oe("file-code",Fa);/**
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 Ia=[["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"}]],fs=oe("file-image",Ia);/**
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 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:"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"}]],ps=oe("file-json",Ra);/**
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 Ta=[["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"}]],gs=oe("file-play",Ta);/**
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 Da=[["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"}]],vs=oe("file-spreadsheet",Da);/**
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 Ga=[["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"}]],js=oe("file-type",Ga);/**
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 Aa=[["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"}]],La=oe("hard-drive",Aa);/**
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 Ka=[["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"}]],Ne=oe("image",Ka);/**
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 Va=[["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"}]],ys=oe("maximize-2",Va);/**
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 Oa=[["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"}]],fe=oe("music",Oa);/**
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 Wa=[["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"}]],bs=oe("presentation",Wa);/**
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 Ba=[["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"}]],$a=oe("upload",Ba);/**
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 Ua=[["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"}]],Be=oe("video",Ua);async function qs(l){const c=l.startsWith("http")?l:`${Us}${l}`,n=await fetch(c,{headers:{Accept:"application/json","User-Agent":"coconut-frontend"}});if(!n.ok)throw new Error(`Failed to fetch registry resource: ${n.status}`);return n.json()}async function za(){return qs("/registry/resources/root.json")}async function ws(l){return qs(l)}function Ke(l){if(l)return l.startsWith("http")?l:`${Us}${l}`}function qa({open:l,onOpenChange:c,onSelectExample:n,onCustomizeInAssistant:p}){const[m,u]=t.useState([]),[j,h]=t.useState(!1),[N,P]=t.useState(null),[S,d]=t.useState(null),[x,y]=t.useState(null),[E,w]=t.useState(!1),[b,_]=t.useState(null);t.useEffect(()=>{l&&(h(!0),P(null),d(null),y(null),_(null),za().then(v=>{u(v.elements??[]),v.elements&&v.elements.length>0&&z(v.elements[0])}).catch(v=>{console.error("Failed to load registry resources",v),u([]),P("Failed to load examples from registry")}).finally(()=>h(!1)))},[l]);const z=async v=>{d(v.id),_(null),y(null),w(!0);try{const k=await ws(v.endpoint);y(k)}catch(k){console.error("Failed to load resource detail",k),_("Unable to load details for this example")}finally{w(!1)}},M=()=>{x?.prompt&&(n(x.prompt),c(!1))},T=()=>{x?.prompt&&p&&(p(x.prompt),c(!1))},A=async v=>{if(S===v.id&&x?.prompt){n(x.prompt),c(!1);return}try{const k=await ws(v.endpoint);k.prompt&&(n(k.prompt),c(!1))}catch(k){console.error("Failed to load resource detail",k)}};return e.jsx(pe,{open:l,onOpenChange:c,children:e.jsxs(ge,{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(ve,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(je,{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:E?e.jsxs("div",{className:"flex items-center text-muted-foreground",children:[e.jsx(le,{className:"h-5 w-5 animate-spin mr-2"}),"Loading..."]}):b?e.jsx("p",{className:"text-sm text-muted-foreground",children:b}):x?e.jsx("img",{src:Ke(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:[j?e.jsxs("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:[e.jsx(le,{className:"h-5 w-5 animate-spin mr-2"}),"Loading examples..."]}):N?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:N}):m.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"No examples available"}):e.jsx(is,{className:"flex-1",children:e.jsx("div",{className:"p-3 space-y-2",children:m.map(v=>e.jsxs("button",{onClick:()=>z(v),onDoubleClick:()=>A(v),className:`w-full text-left p-2 rounded-lg border-2 transition-all flex gap-3 ${S===v.id?"border-primary bg-primary/5":"border-transparent bg-muted/50 hover:bg-muted"}`,children:[v.thumbnailUrl&&e.jsx("img",{src:Ke(v.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:v.name}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",children:v.description})]})]},v.id))})}),e.jsx("div",{className:"p-3 border-t flex-shrink-0",children:e.jsxs(R,{onClick:M,disabled:!x?.prompt||E,className:"w-full",children:[e.jsx(os,{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:T,children:[e.jsx(Ee,{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:[j?e.jsxs("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:[e.jsx(le,{className:"h-5 w-5 animate-spin mr-2"}),"Loading examples..."]}):N?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:N}):m.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"No examples available"}):e.jsx(is,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-3",children:m.map(v=>e.jsxs("button",{onClick:()=>z(v),onDoubleClick:()=>A(v),className:`w-full text-left p-3 rounded-lg border-2 transition-all flex gap-3 ${S===v.id?"border-primary bg-primary/5 shadow-sm":"border-transparent bg-muted/50 hover:bg-muted hover:border-muted-foreground/20"}`,children:[v.thumbnailUrl&&e.jsx("img",{src:Ke(v.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:v.name}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 mt-1",children:v.description}),v.tags&&v.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[v.tags.slice(0,3).map(k=>e.jsx(Me,{variant:"secondary",className:"text-[10px]",children:k},k)),v.tags.length>3&&e.jsxs(Me,{variant:"outline",className:"text-[10px]",children:["+",v.tags.length-3]})]})]})]},v.id))})}),e.jsx("div",{className:"p-4 border-t flex-shrink-0",children:e.jsxs(R,{onClick:M,disabled:!x?.prompt||E,className:"w-full",children:[e.jsx(os,{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:E?e.jsxs("div",{className:"flex items-center text-muted-foreground",children:[e.jsx(le,{className:"h-5 w-5 animate-spin mr-2"}),"Loading details..."]}):b?e.jsx("p",{className:"text-sm text-muted-foreground",children:b}):x?e.jsx("img",{src:Ke(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:T,children:[e.jsx(Ee,{className:"mr-1.5 h-3.5 w-3.5"}),"Customize in Assistant"]})})]})]})]})})}const Ns="image-generator-settings";function _s(){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 Ve={"nano-banana-pro":{id:"nano-banana-pro",label:"Nano Banana Pro",replicateId:"google/nano-banana-pro",features:{resolution:!0,outputQuality:!1,quality:!1,goFast:!1,safetyTolerance:!1,matchInputImage:!1,background:!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,quality:!1,goFast:!0,safetyTolerance:!1,matchInputImage:!0,background:!1},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,quality:!1,goFast:!1,safetyTolerance:!0,matchInputImage:!1,background:!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}},"gpt-image-1.5":{id:"gpt-image-1.5",label:"GPT Image 1.5",replicateId:"openai/gpt-image-1.5",features:{resolution:!1,outputQuality:!1,quality:!0,goFast:!1,safetyTolerance:!1,matchInputImage:!1,background:!0},aspectRatioOptions:[{value:"1:1",label:"1:1"},{value:"3:2",label:"3:2"},{value:"2:3",label:"2:3"}],defaults:{aspectRatio:"1:1",quality:"high",background:"auto"}}},Ss=Object.values(Ve).map(l=>({value:l.id,label:l.label})),Cs=[{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"}],Ha={value:"match_input_image",label:"Match Input"},ks=[{value:"png",label:"PNG"},{value:"jpg",label:"JPG"},{value:"webp",label:"WebP"}],Ps=[{value:"60",label:"60"},{value:"70",label:"70"},{value:"80",label:"80"},{value:"90",label:"90"},{value:"100",label:"100"}],Es=[{value:"low",label:"Low"},{value:"medium",label:"Medium"},{value:"high",label:"High"}],Ms=[{value:"auto",label:"Auto"},{value:"transparent",label:"Transparent"},{value:"opaque",label:"Opaque"}],Fs=[{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 Ja({open:l,onOpenChange:c,onSave:n,onCustomizeInAssistant:p}){const m=a=>a.aspectRatioOptions?a.aspectRatioOptions:a.features.matchInputImage?[Ha,...Cs]:Cs,u=(a,s)=>typeof s!="string"?!1:new Set(m(a).map(f=>f.value)).has(s),h=(()=>{if(typeof window>"u")return null;try{const a=localStorage.getItem(Ns);return a?JSON.parse(a):null}catch{return null}})(),N=h?.model||"nano-banana-pro",P=Ve[N],S=u(P,h?.aspectRatio)?h?.aspectRatio:P.defaults.aspectRatio||"16:9",[d,x]=t.useState(""),[y,E]=t.useState(N),[w,b]=t.useState(S),[_,z]=t.useState(h?.resolution||"2K"),[M,T]=t.useState(h?.outputFormat||"png"),[A,v]=t.useState(h?.outputQuality||"80"),[k,q]=t.useState(h?.quality||"high"),[L,D]=t.useState(h?.goFast??!0),[I,g]=t.useState(h?.safetyTolerance||"2"),[K,Y]=t.useState(h?.background||"auto"),[H,ee]=t.useState(null),[V,O]=t.useState(!1),[Q,o]=t.useState(!1),[te,i]=t.useState([]),[F,se]=t.useState([]),[X,re]=t.useState(!0),[ue,he]=t.useState(!1),[Ie,Re]=t.useState(0),xe=t.useRef(null),{toast:ie}=$e();t.useEffect(()=>{const a={model:y,aspectRatio:w,resolution:_,outputFormat:M,outputQuality:A,quality:k,goFast:L,safetyTolerance:I,background:K};localStorage.setItem(Ns,JSON.stringify(a))},[y,w,_,M,A,k,L,I,K]),t.useEffect(()=>(V?(Re(0),xe.current=setInterval(()=>{Re(a=>a+1)},1e3)):xe.current&&(clearInterval(xe.current),xe.current=null),()=>{xe.current&&clearInterval(xe.current)}),[V]);const J=Ve[y],Ce=m(J),Te=J.resolutionOptions||[];t.useEffect(()=>{const a=Ve[y];a.defaults.resolution&&a.features.resolution&&z(a.defaults.resolution),a.defaults.outputQuality!==void 0&&v(String(a.defaults.outputQuality)),a.defaults.quality!==void 0&&a.features.quality&&q(String(a.defaults.quality)),a.defaults.goFast!==void 0&&D(a.defaults.goFast),a.defaults.safetyTolerance!==void 0&&g(String(a.defaults.safetyTolerance)),a.defaults.background!==void 0&&a.features.background&&Y(String(a.defaults.background)),b(s=>{const r=m(a).map(f=>f.value);return r.includes(s)?s:a.defaults.aspectRatio||r[0]||"16:9"})},[y]),t.useEffect(()=>{l&&ze()},[l]);const ze=async()=>{try{const s=await(await fetch(`${ae}/api/v1/resources`)).json();if(s.success){const r=(s.data||[]).filter(f=>{const Z=f.type==="image/jpeg"||f.name.toLowerCase().endsWith(".jpg")||f.name.toLowerCase().endsWith(".jpeg"),ne=f.type==="image/png"||f.name.toLowerCase().endsWith(".png");return(Z||ne)&&f.thumbnailPath});i(r)}}catch(a){console.error("Failed to fetch image resources:",a)}},ke=async()=>{if(!d.trim()){ie({title:"Prompt required",description:"Please enter a prompt to generate an image",variant:"destructive"});return}O(!0),ee(null);try{const a=X||F.length===0?[]:[...F],s=new AbortController,r=setTimeout(()=>s.abort(),3e5),f=await fetch(`${ae}/api/v1/resources/generate`,{method:"POST",headers:{"Content-Type":"application/json"},signal:s.signal,body:JSON.stringify({prompt:d,model:y,dimensions:w,resolution:J.features.resolution?_:void 0,output_format:M,output_quality:J.features.outputQuality?parseInt(A):void 0,quality:J.features.quality?k:void 0,go_fast:J.features.goFast?L:void 0,safety_tolerance:J.features.safetyTolerance?parseInt(I):void 0,background:J.features.background?K:void 0,image_input:a})});if(clearTimeout(r),f.status===504||f.status===502||f.status===408)throw new Error("Request timed out. The image model may be warming up - please try again.");const Z=f.headers.get("content-type");if(!Z||!Z.includes("application/json"))throw new Error("Request timed out or server error. Please try again.");const ne=await f.json();if(!f.ok||!ne.success){const de=ne.error?.message||"Failed to generate image",ce=ne.error?.code==="MISSING_API_TOKEN";throw new Error(ce?"Replicate API token not configured. Please add it in Settings → Integrations.":de)}ee(ne.data.imageUrl),ie({title:"Image generated",description:"Your image has been generated successfully"})}catch(a){console.error("Generation error:",a);const s=a instanceof Error&&a.name==="AbortError",r=s?"Request timed out after 5 minutes. The model may be overloaded - please try again.":a instanceof Error?a.message:"Failed to generate image.",f=s||r.toLowerCase().includes("timeout")||r.toLowerCase().includes("timed out");ie({title:f?"Generation timed out":"Generation failed",description:r,variant:"destructive"})}finally{O(!1)}};t.useEffect(()=>{const a=s=>{l&&(s.metaKey||s.ctrlKey)&&s.key==="Enter"&&(s.preventDefault(),d.trim()&&!V&&!Q&&ke())};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[l,d,V,Q]);const De=async()=>{if(H){o(!0);try{await n(H,{prompt:d,model:y}),x(""),E("nano-banana-pro"),b("16:9"),z("2K"),T("png"),v("80"),q("high"),D(!0),g("2"),Y("auto"),ee(null),re(!0),se([]),c(!1)}catch(a){ie({title:"Save failed",description:a instanceof Error?a.message:"Failed to save image. Please try again.",variant:"destructive"})}finally{o(!1)}}},Ge=()=>{!V&&!Q&&c(!1)},Ae=()=>{re(!0),se([])},Le=a=>{X&&re(!1),F.includes(a)?(se(F.filter(s=>s!==a)),F.length===1&&re(!0)):F.length<3?se([...F,a]):ie({title:"Maximum selection",description:"You can only select up to 3 images",variant:"destructive"})},qe=a=>{x(a)},He=a=>{p&&(he(!1),c(!1),p(`"${a}" Please customize this (and respond back just the updated markdown):`))};return e.jsxs(pe,{open:l,onOpenChange:Ge,children:[e.jsxs(ge,{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(ve,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(je,{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:V?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3",children:[e.jsx(le,{className:"h-10 w-10 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating..."})]}):H?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:H,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(Ne,{className:"h-12 w-12"}),e.jsx("p",{className:"text-xs",children:"Preview"}),e.jsxs(R,{size:"sm",onClick:()=>he(!0),className:"mt-2",children:[e.jsx(Ee,{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:Ae,className:`flex-shrink-0 h-16 w-16 flex items-center justify-center border-2 rounded-md transition-colors text-xs ${X?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:"None"}),te.map(a=>{const s=F.includes(a.id);return e.jsx("button",{onClick:()=>Le(a.id),className:`flex-shrink-0 h-16 w-16 border-2 rounded-md overflow-hidden transition-colors ${s?"border-primary ring-2 ring-primary":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("img",{src:`${ae}/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(C,{htmlFor:"prompt-mobile",className:"text-xs",children:"Prompt"}),e.jsx(ye,{id:"prompt-mobile",placeholder:"Describe the image...",value:d,onChange:a=>x(a.target.value),rows:2,className:"resize-none text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"model-mobile",className:"text-xs",children:"Model"}),e.jsxs(W,{value:y,onValueChange:a=>E(a),children:[e.jsx(B,{id:"model-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ss.map(a=>e.jsx(G,{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(C,{htmlFor:"outputFormat-mobile",className:"text-xs",children:"Format"}),e.jsxs(W,{value:M,onValueChange:T,children:[e.jsx(B,{id:"outputFormat-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:ks.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.background&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"background-mobile",className:"text-xs",children:"Background"}),e.jsxs(W,{value:K,onValueChange:Y,children:[e.jsx(B,{id:"background-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ms.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.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(Oe,{id:"goFast-mobile",checked:L,onCheckedChange:a=>D(a===!0)}),e.jsx(C,{htmlFor:"goFast-mobile",className:"text-xs cursor-pointer",children:"Go Fast"})]})}),J.features.safetyTolerance&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"safetyTolerance-mobile",className:"text-xs",children:"Safety"}),e.jsxs(W,{value:I,onValueChange:g,children:[e.jsx(B,{id:"safetyTolerance-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Fs.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[J.features.resolution&&e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(C,{htmlFor:"resolution-mobile",className:"text-xs",children:"Resolution"}),e.jsxs(W,{value:_,onValueChange:z,children:[e.jsx(B,{id:"resolution-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Te.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(C,{htmlFor:"aspectRatio-mobile",className:"text-xs",children:"Ratio"}),e.jsxs(W,{value:w,onValueChange:b,children:[e.jsx(B,{id:"aspectRatio-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ce.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.outputQuality&&e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(C,{htmlFor:"outputQuality-mobile",className:"text-xs",children:"Quality"}),e.jsxs(W,{value:A,onValueChange:v,children:[e.jsx(B,{id:"outputQuality-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ps.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.quality&&e.jsxs("div",{className:"space-y-1 flex-1 min-w-[80px]",children:[e.jsx(C,{htmlFor:"quality-mobile",className:"text-xs",children:"Quality"}),e.jsxs(W,{value:k,onValueChange:q,children:[e.jsx(B,{id:"quality-mobile",className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Es.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(R,{onClick:ke,disabled:!d.trim()||V||Q,className:"flex-1 h-9",size:"sm",children:V?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(_s,{}),e.jsxs("span",{children:[Ie,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:["Generate",e.jsx(me,{className:"ml-1",children:"⌘↵"})]})}),e.jsx(R,{onClick:De,disabled:!H||V||Q,variant:"outline",className:"flex-1 h-9",size:"sm",children:Q?e.jsx(le,{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(C,{htmlFor:"prompt",children:"Prompt"}),e.jsx(ye,{id:"prompt",placeholder:"Describe the image you want to generate...",value:d,onChange:a=>x(a.target.value),rows:4,className:"resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"model",children:"Model"}),e.jsxs(W,{value:y,onValueChange:a=>E(a),children:[e.jsx(B,{id:"model",children:e.jsx($,{})}),e.jsx(U,{children:Ss.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"aspectRatio",children:"Aspect Ratio"}),e.jsxs(W,{value:w,onValueChange:b,children:[e.jsx(B,{id:"aspectRatio",children:e.jsx($,{})}),e.jsx(U,{children:Ce.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.resolution&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"resolution",children:"Resolution"}),e.jsxs(W,{value:_,onValueChange:z,children:[e.jsx(B,{id:"resolution",children:e.jsx($,{})}),e.jsx(U,{children:Te.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"outputFormat",children:"Output Format"}),e.jsxs(W,{value:M,onValueChange:T,children:[e.jsx(B,{id:"outputFormat",children:e.jsx($,{})}),e.jsx(U,{children:ks.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.background&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"background",children:"Background"}),e.jsxs(W,{value:K,onValueChange:Y,children:[e.jsx(B,{id:"background",children:e.jsx($,{})}),e.jsx(U,{children:Ms.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.outputQuality&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"outputQuality",children:"Output Quality"}),e.jsxs(W,{value:A,onValueChange:v,children:[e.jsx(B,{id:"outputQuality",children:e.jsx($,{})}),e.jsx(U,{children:Ps.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.quality&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"quality",children:"Quality"}),e.jsxs(W,{value:k,onValueChange:q,children:[e.jsx(B,{id:"quality",children:e.jsx($,{})}),e.jsx(U,{children:Es.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),J.features.goFast&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Oe,{id:"goFast",checked:L,onCheckedChange:a=>D(a===!0)}),e.jsx(C,{htmlFor:"goFast",className:"cursor-pointer",children:"Go Fast"})]}),J.features.safetyTolerance&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"safetyTolerance",children:"Safety Tolerance"}),e.jsxs(W,{value:I,onValueChange:g,children:[e.jsx(B,{id:"safetyTolerance",children:e.jsx($,{})}),e.jsx(U,{children:Fs.map(a=>e.jsx(G,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-4",children:[e.jsx(R,{onClick:ke,disabled:!d.trim()||V||Q,className:"w-full",children:V?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(_s,{}),e.jsxs("span",{children:["Generating... ",Ie,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-2",children:["Generate",e.jsx(me,{children:"⌘"}),e.jsx(me,{children:"↵"})]})}),e.jsx(R,{onClick:De,disabled:!H||V||Q,variant:"outline",className:"w-full",children:Q?e.jsxs(e.Fragment,{children:[e.jsx(le,{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:V?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx(le,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating image..."})]}):H?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:H,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(Ne,{className:"h-16 w-16"}),e.jsx("p",{className:"text-sm",children:"Generated image will appear here"}),e.jsxs(R,{onClick:()=>he(!0),className:"mt-2",children:[e.jsx(Ee,{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:Ae,className:`flex-shrink-0 h-32 w-32 flex items-center justify-center border-2 rounded-md transition-colors ${X?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("span",{className:"text-sm font-medium",children:"None"})}),te.map(a=>{const s=F.includes(a.id);return e.jsx("button",{onClick:()=>Le(a.id),className:`flex-shrink-0 h-32 w-32 border-2 rounded-md overflow-hidden transition-colors ${s?"border-primary ring-2 ring-primary":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("img",{src:`${ae}/api/v1/resources/${a.id}/thumbnail`,alt:a.name,className:"w-full h-full object-cover"})},a.id)})]})})]})]})]}),e.jsx(qa,{open:ue,onOpenChange:he,onSelectExample:qe,onCustomizeInAssistant:p?He:void 0})]})}var Hs=["PageUp","PageDown"],Js=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Ys={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Se="Slider",[as,Ya,Qa]=ua(Se),[Qs,Et]=da(Se,[Qa]),[Xa,Ue]=Qs(Se),Xs=t.forwardRef((l,c)=>{const{name:n,min:p=0,max:m=100,step:u=1,orientation:j="horizontal",disabled:h=!1,minStepsBetweenThumbs:N=0,defaultValue:P=[p],value:S,onValueChange:d=()=>{},onValueCommit:x=()=>{},inverted:y=!1,form:E,...w}=l,b=t.useRef(new Set),_=t.useRef(0),M=j==="horizontal"?Za:et,[T=[],A]=ca({prop:S,defaultProp:P,onChange:I=>{[...b.current][_.current]?.focus(),d(I)}}),v=t.useRef(T);function k(I){const g=lt(T,I);D(I,g)}function q(I){D(I,_.current)}function L(){const I=v.current[_.current];T[_.current]!==I&&x(T)}function D(I,g,{commit:K}={commit:!1}){const Y=ct(u),H=dt(Math.round((I-p)/u)*u+p,Y),ee=Bs(H,[p,m]);A((V=[])=>{const O=tt(V,ee,g);if(ot(O,N*u)){_.current=O.indexOf(ee);const Q=String(O)!==String(V);return Q&&K&&x(O),Q?O:V}else return V})}return e.jsx(Xa,{scope:l.__scopeSlider,name:n,disabled:h,min:p,max:m,valueIndexToChangeRef:_,thumbs:b.current,values:T,orientation:j,form:E,children:e.jsx(as.Provider,{scope:l.__scopeSlider,children:e.jsx(as.Slot,{scope:l.__scopeSlider,children:e.jsx(M,{"aria-disabled":h,"data-disabled":h?"":void 0,...w,ref:c,onPointerDown:be(w.onPointerDown,()=>{h||(v.current=T)}),min:p,max:m,inverted:y,onSlideStart:h?void 0:k,onSlideMove:h?void 0:q,onSlideEnd:h?void 0:L,onHomeKeyDown:()=>!h&&D(p,0,{commit:!0}),onEndKeyDown:()=>!h&&D(m,T.length-1,{commit:!0}),onStepKeyDown:({event:I,direction:g})=>{if(!h){const H=Hs.includes(I.key)||I.shiftKey&&Js.includes(I.key)?10:1,ee=_.current,V=T[ee],O=u*H*g;D(V+O,ee,{commit:!0})}}})})})})});Xs.displayName=Se;var[Zs,ea]=Qs(Se,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Za=t.forwardRef((l,c)=>{const{min:n,max:p,dir:m,inverted:u,onSlideStart:j,onSlideMove:h,onSlideEnd:N,onStepKeyDown:P,...S}=l,[d,x]=t.useState(null),y=_e(c,M=>x(M)),E=t.useRef(void 0),w=ma(m),b=w==="ltr",_=b&&!u||!b&&u;function z(M){const T=E.current||d.getBoundingClientRect(),A=[0,T.width],k=ls(A,_?[n,p]:[p,n]);return E.current=T,k(M-T.left)}return e.jsx(Zs,{scope:l.__scopeSlider,startEdge:_?"left":"right",endEdge:_?"right":"left",direction:_?1:-1,size:"width",children:e.jsx(sa,{dir:w,"data-orientation":"horizontal",...S,ref:y,style:{...S.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:M=>{const T=z(M.clientX);j?.(T)},onSlideMove:M=>{const T=z(M.clientX);h?.(T)},onSlideEnd:()=>{E.current=void 0,N?.()},onStepKeyDown:M=>{const A=Ys[_?"from-left":"from-right"].includes(M.key);P?.({event:M,direction:A?-1:1})}})})}),et=t.forwardRef((l,c)=>{const{min:n,max:p,inverted:m,onSlideStart:u,onSlideMove:j,onSlideEnd:h,onStepKeyDown:N,...P}=l,S=t.useRef(null),d=_e(c,S),x=t.useRef(void 0),y=!m;function E(w){const b=x.current||S.current.getBoundingClientRect(),_=[0,b.height],M=ls(_,y?[p,n]:[n,p]);return x.current=b,M(w-b.top)}return e.jsx(Zs,{scope:l.__scopeSlider,startEdge:y?"bottom":"top",endEdge:y?"top":"bottom",size:"height",direction:y?1:-1,children:e.jsx(sa,{"data-orientation":"vertical",...P,ref:d,style:{...P.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:w=>{const b=E(w.clientY);u?.(b)},onSlideMove:w=>{const b=E(w.clientY);j?.(b)},onSlideEnd:()=>{x.current=void 0,h?.()},onStepKeyDown:w=>{const _=Ys[y?"from-bottom":"from-top"].includes(w.key);N?.({event:w,direction:_?-1:1})}})})}),sa=t.forwardRef((l,c)=>{const{__scopeSlider:n,onSlideStart:p,onSlideMove:m,onSlideEnd:u,onHomeKeyDown:j,onEndKeyDown:h,onStepKeyDown:N,...P}=l,S=Ue(Se,n);return e.jsx(Fe.span,{...P,ref:c,onKeyDown:be(l.onKeyDown,d=>{d.key==="Home"?(j(d),d.preventDefault()):d.key==="End"?(h(d),d.preventDefault()):Hs.concat(Js).includes(d.key)&&(N(d),d.preventDefault())}),onPointerDown:be(l.onPointerDown,d=>{const x=d.target;x.setPointerCapture(d.pointerId),d.preventDefault(),S.thumbs.has(x)?x.focus():p(d)}),onPointerMove:be(l.onPointerMove,d=>{d.target.hasPointerCapture(d.pointerId)&&m(d)}),onPointerUp:be(l.onPointerUp,d=>{const x=d.target;x.hasPointerCapture(d.pointerId)&&(x.releasePointerCapture(d.pointerId),u(d))})})}),aa="SliderTrack",ta=t.forwardRef((l,c)=>{const{__scopeSlider:n,...p}=l,m=Ue(aa,n);return e.jsx(Fe.span,{"data-disabled":m.disabled?"":void 0,"data-orientation":m.orientation,...p,ref:c})});ta.displayName=aa;var ts="SliderRange",na=t.forwardRef((l,c)=>{const{__scopeSlider:n,...p}=l,m=Ue(ts,n),u=ea(ts,n),j=t.useRef(null),h=_e(c,j),N=m.values.length,P=m.values.map(x=>ia(x,m.min,m.max)),S=N>1?Math.min(...P):0,d=100-Math.max(...P);return e.jsx(Fe.span,{"data-orientation":m.orientation,"data-disabled":m.disabled?"":void 0,...p,ref:h,style:{...l.style,[u.startEdge]:S+"%",[u.endEdge]:d+"%"}})});na.displayName=ts;var ns="SliderThumb",la=t.forwardRef((l,c)=>{const n=Ya(l.__scopeSlider),[p,m]=t.useState(null),u=_e(c,h=>m(h)),j=t.useMemo(()=>p?n().findIndex(h=>h.ref.current===p):-1,[n,p]);return e.jsx(st,{...l,ref:u,index:j})}),st=t.forwardRef((l,c)=>{const{__scopeSlider:n,index:p,name:m,...u}=l,j=Ue(ns,n),h=ea(ns,n),[N,P]=t.useState(null),S=_e(c,z=>P(z)),d=N?j.form||!!N.closest("form"):!0,x=ha(N),y=j.values[p],E=y===void 0?0:ia(y,j.min,j.max),w=nt(p,j.values.length),b=x?.[h.size],_=b?rt(b,E,h.direction):0;return t.useEffect(()=>{if(N)return j.thumbs.add(N),()=>{j.thumbs.delete(N)}},[N,j.thumbs]),e.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[h.startEdge]:`calc(${E}% + ${_}px)`},children:[e.jsx(as.ItemSlot,{scope:l.__scopeSlider,children:e.jsx(Fe.span,{role:"slider","aria-label":l["aria-label"]||w,"aria-valuemin":j.min,"aria-valuenow":y,"aria-valuemax":j.max,"aria-orientation":j.orientation,"data-orientation":j.orientation,"data-disabled":j.disabled?"":void 0,tabIndex:j.disabled?void 0:0,...u,ref:S,style:y===void 0?{display:"none"}:l.style,onFocus:be(l.onFocus,()=>{j.valueIndexToChangeRef.current=p})})}),d&&e.jsx(ra,{name:m??(j.name?j.name+(j.values.length>1?"[]":""):void 0),form:j.form,value:y},p)]})});la.displayName=ns;var at="RadioBubbleInput",ra=t.forwardRef(({__scopeSlider:l,value:c,...n},p)=>{const m=t.useRef(null),u=_e(m,p),j=xa(c);return t.useEffect(()=>{const h=m.current;if(!h)return;const N=window.HTMLInputElement.prototype,S=Object.getOwnPropertyDescriptor(N,"value").set;if(j!==c&&S){const d=new Event("input",{bubbles:!0});S.call(h,c),h.dispatchEvent(d)}},[j,c]),e.jsx(Fe.input,{style:{display:"none"},...n,ref:u,defaultValue:c})});ra.displayName=at;function tt(l=[],c,n){const p=[...l];return p[n]=c,p.sort((m,u)=>m-u)}function ia(l,c,n){const u=100/(n-c)*(l-c);return Bs(u,[0,100])}function nt(l,c){return c>2?`Value ${l+1} of ${c}`:c===2?["Minimum","Maximum"][l]:void 0}function lt(l,c){if(l.length===1)return 0;const n=l.map(m=>Math.abs(m-c)),p=Math.min(...n);return n.indexOf(p)}function rt(l,c,n){const p=l/2,u=ls([0,50],[0,p]);return(p-u(c)*n)*n}function it(l){return l.slice(0,-1).map((c,n)=>l[n+1]-c)}function ot(l,c){if(c>0){const n=it(l);return Math.min(...n)>=c}return!0}function ls(l,c){return n=>{if(l[0]===l[1]||c[0]===c[1])return c[0];const p=(c[1]-c[0])/(l[1]-l[0]);return c[0]+p*(n-l[0])}}function ct(l){return(String(l).split(".")[1]||"").length}function dt(l,c){const n=Math.pow(10,c);return Math.round(l*n)/n}var oa=Xs,ut=ta,mt=na,ht=la;const Pe=t.forwardRef(({className:l,...c},n)=>e.jsxs(oa,{ref:n,className:fa("relative flex w-full touch-none select-none items-center",l),...c,children:[e.jsx(ut,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20",children:e.jsx(mt,{className:"absolute h-full bg-primary"})}),e.jsx(ht,{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"})]}));Pe.displayName=oa.displayName;const Is="audio-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=["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"],Ds=[{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"}],Gs=[{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"}],As=[{value:"mp3",label:"MP3"},{value:"wav",label:"WAV"},{value:"flac",label:"FLAC"}];function xt({open:l,onOpenChange:c,onSave:n}){const m=(()=>{if(typeof window>"u")return null;try{const o=localStorage.getItem(Is);return o?JSON.parse(o):null}catch{return null}})(),[u,j]=t.useState(""),[h,N]=t.useState(m?.voiceId||"English_Trustworth_Man"),[P,S]=t.useState(m?.useCustomVoice||!1),[d,x]=t.useState(m?.customVoiceId||""),[y,E]=t.useState(m?.speed??1),[w,b]=t.useState(m?.pitch??0),[_,z]=t.useState(m?.emotion||"auto"),[M,T]=t.useState(m?.languageBoost||"English"),[A,v]=t.useState(m?.audioFormat||"mp3"),[k,q]=t.useState(null),[L,D]=t.useState(!1),[I,g]=t.useState(!1),[K,Y]=t.useState(0),H=t.useRef(null),{toast:ee}=$e();t.useEffect(()=>{const o={voiceId:h,useCustomVoice:P,customVoiceId:d,speed:y,pitch:w,emotion:_,languageBoost:M,audioFormat:A};localStorage.setItem(Is,JSON.stringify(o))},[h,P,d,y,w,_,M,A]),t.useEffect(()=>(L?(Y(0),H.current=setInterval(()=>{Y(o=>o+1)},1e3)):H.current&&(clearInterval(H.current),H.current=null),()=>{H.current&&clearInterval(H.current)}),[L]);const V=async()=>{if(!u.trim()){ee({title:"Text required",description:"Please enter text to generate audio",variant:"destructive"});return}D(!0),q(null);try{const o=P?d:h,te=new AbortController,i=setTimeout(()=>te.abort(),3e5),F=await fetch(`${ae}/api/v1/resources/generate-audio`,{method:"POST",headers:{"Content-Type":"application/json"},signal:te.signal,body:JSON.stringify({text:u,voice_id:o,speed:y,pitch:w,emotion:_,language_boost:M,audio_format:A})});if(clearTimeout(i),F.status===504||F.status===502||F.status===408)throw new Error("Request timed out. The audio model may be warming up - please try again.");const se=F.headers.get("content-type");if(!se||!se.includes("application/json"))throw new Error("Request timed out or server error. Please try again.");const X=await F.json();if(!F.ok||!X.success){const re=X.error?.message||"Failed to generate audio",ue=X.error?.code==="MISSING_API_TOKEN";throw new Error(ue?"Replicate API token not configured. Please add it in Settings → Integrations.":re)}q(X.data.audioUrl),ee({title:"Audio generated",description:"Your audio has been generated successfully"})}catch(o){console.error("Generation error:",o);const te=o instanceof Error&&o.name==="AbortError",i=te?"Request timed out after 5 minutes. The model may be overloaded - please try again.":o instanceof Error?o.message:"Failed to generate audio.",F=te||i.toLowerCase().includes("timeout")||i.toLowerCase().includes("timed out");ee({title:F?"Generation timed out":"Generation failed",description:i,variant:"destructive"})}finally{D(!1)}};t.useEffect(()=>{const o=te=>{l&&(te.metaKey||te.ctrlKey)&&te.key==="Enter"&&(te.preventDefault(),u.trim()&&!L&&!I&&V())};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[l,u,L,I]);const O=async()=>{if(k){g(!0);try{await n(k),j(""),N("English_Trustworth_Man"),S(!1),x(""),E(1),b(0),z("auto"),T("English"),v("mp3"),q(null),c(!1)}catch(o){ee({title:"Save failed",description:o instanceof Error?o.message:"Failed to save audio. Please try again.",variant:"destructive"})}finally{g(!1)}}},Q=()=>{!L&&!I&&c(!1)};return e.jsx(pe,{open:l,onOpenChange:Q,children:e.jsxs(ge,{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(ve,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(je,{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:L?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3",children:[e.jsx(le,{className:"h-10 w-10 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating..."})]}):k?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(fe,{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:k,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(fe,{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(C,{htmlFor:"text-mobile",className:"text-xs",children:"Text"}),e.jsx(ye,{id:"text-mobile",placeholder:"Enter text to convert to speech...",value:u,onChange:o=>j(o.target.value),rows:3,className:"resize-none text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Voice"}),e.jsxs(W,{value:P?"__custom__":h,onValueChange:o=>{o==="__custom__"?S(!0):(S(!1),N(o))},children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsxs(U,{className:"max-h-60",children:[Ts.map(o=>e.jsx(G,{value:o,className:"text-xs",children:o.replace(/_/g," ")},o)),e.jsx(G,{value:"__custom__",className:"text-xs font-medium",children:"Custom Voice ID..."})]})]}),P&&e.jsx(We,{placeholder:"Enter custom voice ID",value:d,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(C,{className:"text-xs",children:["Speed: ",y.toFixed(1),"x"]}),e.jsx(Pe,{value:[y],onValueChange:([o])=>E(o),min:.5,max:2,step:.1,className:"w-full"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs(C,{className:"text-xs",children:["Pitch: ",w>0?"+":"",w]}),e.jsx(Pe,{value:[w],onValueChange:([o])=>b(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(C,{className:"text-xs",children:"Emotion"}),e.jsxs(W,{value:_,onValueChange:z,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ds.map(o=>e.jsx(G,{value:o.value,className:"text-xs",children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Language"}),e.jsxs(W,{value:M,onValueChange:T,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Gs.map(o=>e.jsx(G,{value:o.value,className:"text-xs",children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Format"}),e.jsxs(W,{value:A,onValueChange:v,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:As.map(o=>e.jsx(G,{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:V,disabled:!u.trim()||L||I,className:"flex-1 h-9",size:"sm",children:L?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Rs,{}),e.jsxs("span",{children:[K,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:["Generate",e.jsx(me,{className:"ml-1",children:"⌘↵"})]})}),e.jsx(R,{onClick:O,disabled:!k||L||I,variant:"outline",className:"flex-1 h-9",size:"sm",children:I?e.jsx(le,{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(C,{htmlFor:"text",children:"Text"}),e.jsx(ye,{id:"text",placeholder:"Enter text to convert to speech...",value:u,onChange:o=>j(o.target.value),rows:6,className:"resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Voice"}),e.jsxs(W,{value:P?"__custom__":h,onValueChange:o=>{o==="__custom__"?S(!0):(S(!1),N(o))},children:[e.jsx(B,{children:e.jsx($,{})}),e.jsxs(U,{className:"max-h-80",children:[Ts.map(o=>e.jsx(G,{value:o,children:o.replace(/_/g," ")},o)),e.jsx(G,{value:"__custom__",className:"font-medium",children:"Custom Voice ID..."})]})]}),P&&e.jsx(We,{placeholder:"Enter custom voice ID",value:d,onChange:o=>x(o.target.value),className:"mt-2"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{children:["Speed: ",y.toFixed(1),"x"]}),e.jsx(Pe,{value:[y],onValueChange:([o])=>E(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(C,{children:["Pitch: ",w>0?"+":"",w]}),e.jsx(Pe,{value:[w],onValueChange:([o])=>b(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(C,{children:"Emotion"}),e.jsxs(W,{value:_,onValueChange:z,children:[e.jsx(B,{children:e.jsx($,{})}),e.jsx(U,{children:Ds.map(o=>e.jsx(G,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Language Boost"}),e.jsxs(W,{value:M,onValueChange:T,children:[e.jsx(B,{children:e.jsx($,{})}),e.jsx(U,{children:Gs.map(o=>e.jsx(G,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Audio Format"}),e.jsxs(W,{value:A,onValueChange:v,children:[e.jsx(B,{children:e.jsx($,{})}),e.jsx(U,{children:As.map(o=>e.jsx(G,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-4",children:[e.jsx(R,{onClick:V,disabled:!u.trim()||L||I,className:"w-full",children:L?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Rs,{}),e.jsxs("span",{children:["Generating... ",K,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-2",children:["Generate",e.jsx(me,{children:"⌘"}),e.jsx(me,{children:"↵"})]})}),e.jsx(R,{onClick:O,disabled:!k||L||I,variant:"outline",className:"w-full",children:I?e.jsxs(e.Fragment,{children:[e.jsx(le,{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:L?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx(le,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating audio..."})]}):k?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(fe,{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:k,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(fe,{className:"h-16 w-16"}),e.jsx("p",{className:"text-sm",children:"Generated audio will appear here"})]})})})]})]})})}const Ls="video-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 Vs=[{value:"5",label:"5 seconds"},{value:"8",label:"8 seconds"},{value:"10",label:"10 seconds"}],Os=[{value:"480p",label:"480p"},{value:"720p",label:"720p"},{value:"1080p",label:"1080p"}],Ws=[{value:"16:9",label:"16:9 (Landscape)"},{value:"9:16",label:"9:16 (Portrait)"},{value:"1:1",label:"1:1 (Square)"}];function ft({open:l,onOpenChange:c,onSave:n}){const m=(()=>{if(typeof window>"u")return null;try{const i=localStorage.getItem(Ls);return i?JSON.parse(i):null}catch{return null}})(),[u,j]=t.useState(""),[h,N]=t.useState(m?.duration||"8"),[P,S]=t.useState(m?.resolution||"720p"),[d,x]=t.useState(m?.aspectRatio||"16:9"),[y,E]=t.useState(m?.generateAudio??!0),[w,b]=t.useState(null),[_,z]=t.useState(null),[M,T]=t.useState(null),[A,v]=t.useState(0),k=t.useRef(null),[q,L]=t.useState(!1),[D,I]=t.useState(!1),[g,K]=t.useState([]),{toast:Y}=$e();t.useEffect(()=>{const i={duration:h,resolution:P,aspectRatio:d,generateAudio:y};localStorage.setItem(Ls,JSON.stringify(i))},[h,P,d,y]),t.useEffect(()=>(q?(v(0),k.current=setInterval(()=>{v(i=>i+1)},1e3)):k.current&&(clearInterval(k.current),k.current=null),()=>{k.current&&clearInterval(k.current)}),[q]),t.useEffect(()=>{l&&H()},[l]);const H=async()=>{try{const F=await(await fetch(`${ae}/api/v1/resources`)).json();if(F.success){const se=(F.data||[]).filter(X=>{const re=X.type==="image/jpeg"||X.name.toLowerCase().endsWith(".jpg")||X.name.toLowerCase().endsWith(".jpeg"),ue=X.type==="image/png"||X.name.toLowerCase().endsWith(".png");return(re||ue)&&X.thumbnailPath});K(se)}}catch(i){console.error("Failed to fetch image resources:",i)}},ee=i=>{i===_?z(null):i===w?(b(null),z(i)):w?z(i):b(i)},V=()=>{b(null),z(null)},O=async()=>{if(!u.trim()){Y({title:"Prompt required",description:"Please enter a prompt to generate a video",variant:"destructive"});return}L(!0),T(null);try{const i=new AbortController,F=setTimeout(()=>i.abort(),3e5),se=await fetch(`${ae}/api/v1/resources/generate-video`,{method:"POST",headers:{"Content-Type":"application/json"},signal:i.signal,body:JSON.stringify({prompt:u,image:w||void 0,last_frame:_||void 0,duration:parseInt(h),resolution:P,aspect_ratio:d,generate_audio:y})});if(clearTimeout(F),se.status===504||se.status===502||se.status===408)throw new Error("Request timed out. The video model may be warming up - please try again.");const X=se.headers.get("content-type");if(!X||!X.includes("application/json"))throw new Error("Request timed out or server error. Please try again.");const re=await se.json();if(!se.ok||!re.success){const ue=re.error?.message||"Failed to generate video",he=re.error?.code==="MISSING_API_TOKEN";throw new Error(he?"Replicate API token not configured. Please add it in Settings → Integrations.":ue)}T(re.data.videoUrl),Y({title:"Video generated",description:"Your video has been generated successfully"})}catch(i){console.error("Generation error:",i);const F=i instanceof Error&&i.name==="AbortError",se=F?"Request timed out after 5 minutes. The model may be overloaded - please try again.":i instanceof Error?i.message:"Failed to generate video.",X=F||se.toLowerCase().includes("timeout")||se.toLowerCase().includes("timed out");Y({title:X?"Generation timed out":"Generation failed",description:se,variant:"destructive"})}finally{L(!1)}};t.useEffect(()=>{const i=F=>{l&&(F.metaKey||F.ctrlKey)&&F.key==="Enter"&&(F.preventDefault(),u.trim()&&!q&&!D&&O())};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[l,u,q,D]);const Q=async()=>{if(M){I(!0);try{await n(M),j(""),N("8"),S("720p"),x("16:9"),E(!0),b(null),z(null),T(null),c(!1)}catch(i){Y({title:"Save failed",description:i instanceof Error?i.message:"Failed to save video. Please try again.",variant:"destructive"})}finally{I(!1)}}},o=()=>{!q&&!D&&c(!1)},te=i=>i===w?"start":i===_?"end":null;return e.jsx(pe,{open:l,onOpenChange:o,children:e.jsxs(ge,{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(ve,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-3 sm:pb-4 border-b flex-shrink-0",children:e.jsx(je,{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:q?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-3",children:[e.jsx(le,{className:"h-10 w-10 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating..."})]}):M?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("video",{src:M,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(Be,{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:V,className:`flex-shrink-0 h-16 w-16 flex items-center justify-center border-2 rounded-md transition-colors text-xs ${!w&&!_?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:"None"}),g.map(i=>{const F=te(i.id);return e.jsxs("button",{onClick:()=>ee(i.id),className:`relative flex-shrink-0 h-16 w-16 border-2 rounded-md overflow-hidden transition-colors ${F?"border-green-500 ring-2 ring-green-500":"border-muted hover:border-muted-foreground/50"}`,children:[e.jsx("img",{src:`${ae}/api/v1/resources/${i.id}/thumbnail`,alt:i.name,className:"w-full h-full object-cover"}),F&&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:F==="start"?"Start":"End"})]},i.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(C,{htmlFor:"prompt-mobile",className:"text-xs",children:"Prompt"}),e.jsx(ye,{id:"prompt-mobile",placeholder:"Describe the video you want to generate...",value:u,onChange:i=>j(i.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(C,{className:"text-xs",children:"Duration"}),e.jsxs(W,{value:h,onValueChange:N,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Vs.map(i=>e.jsx(G,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Resolution"}),e.jsxs(W,{value:P,onValueChange:S,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Os.map(i=>e.jsx(G,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs",children:"Ratio"}),e.jsxs(W,{value:d,onValueChange:x,children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx($,{})}),e.jsx(U,{children:Ws.map(i=>e.jsx(G,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Oe,{id:"generateAudio-mobile",checked:y,onCheckedChange:i=>E(i===!0)}),e.jsx(C,{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:O,disabled:!u.trim()||q||D,className:"flex-1 h-9",size:"sm",children:q?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ks,{}),e.jsxs("span",{children:[A,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:["Generate",e.jsx(me,{className:"ml-1",children:"⌘↵"})]})}),e.jsx(R,{onClick:Q,disabled:!M||q||D,variant:"outline",className:"flex-1 h-9",size:"sm",children:D?e.jsx(le,{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(C,{htmlFor:"prompt",children:"Prompt"}),e.jsx(ye,{id:"prompt",placeholder:"Describe the video you want to generate...",value:u,onChange:i=>j(i.target.value),rows:4,className:"resize-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"duration",children:"Duration"}),e.jsxs(W,{value:h,onValueChange:N,children:[e.jsx(B,{id:"duration",children:e.jsx($,{})}),e.jsx(U,{children:Vs.map(i=>e.jsx(G,{value:i.value,children:i.label},i.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"resolution",children:"Resolution"}),e.jsxs(W,{value:P,onValueChange:S,children:[e.jsx(B,{id:"resolution",children:e.jsx($,{})}),e.jsx(U,{children:Os.map(i=>e.jsx(G,{value:i.value,children:i.label},i.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"aspectRatio",children:"Aspect Ratio"}),e.jsxs(W,{value:d,onValueChange:x,children:[e.jsx(B,{id:"aspectRatio",children:e.jsx($,{})}),e.jsx(U,{children:Ws.map(i=>e.jsx(G,{value:i.value,children:i.label},i.value))})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Oe,{id:"generateAudio",checked:y,onCheckedChange:i=>E(i===!0)}),e.jsx(C,{htmlFor:"generateAudio",className:"cursor-pointer",children:"Generate audio"})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-4",children:[e.jsx(R,{onClick:O,disabled:!u.trim()||q||D,className:"w-full",children:q?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ks,{}),e.jsxs("span",{children:["Generating... ",A,"s"]})]}):e.jsxs("span",{className:"flex items-center gap-2",children:["Generate",e.jsx(me,{children:"⌘"}),e.jsx(me,{children:"↵"})]})}),e.jsx(R,{onClick:Q,disabled:!M||q||D,variant:"outline",className:"w-full",children:D?e.jsxs(e.Fragment,{children:[e.jsx(le,{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:q?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx(le,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating video..."})]}):M?e.jsx("div",{className:"w-full h-full min-h-0 flex items-center justify-center overflow-hidden",children:e.jsx("video",{src:M,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(Be,{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:V,className:`flex-shrink-0 h-32 w-32 flex items-center justify-center border-2 rounded-md transition-colors ${!w&&!_?"border-primary bg-primary/10":"border-muted hover:border-muted-foreground/50"}`,children:e.jsx("span",{className:"text-sm font-medium",children:"None"})}),g.map(i=>{const F=te(i.id);return e.jsxs("button",{onClick:()=>ee(i.id),className:`relative flex-shrink-0 h-32 w-32 border-2 rounded-md overflow-hidden transition-colors ${F?"border-green-500 ring-2 ring-green-500":"border-muted hover:border-muted-foreground/50"}`,children:[e.jsx("img",{src:`${ae}/api/v1/resources/${i.id}/thumbnail`,alt:i.name,className:"w-full h-full object-cover"}),F&&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:F==="start"?"Start":"End"})]},i.id)})]})]})]})]})]})})}function pt({open:l,onOpenChange:c,resource:n,onCopyPath:p,onDownload:m,onNavigate:u,canNavigatePrev:j,canNavigateNext:h}){const[N,P]=t.useState(null),[S,d]=t.useState(!1),[x,y]=t.useState(!1);t.useEffect(()=>{y(!1)},[n?.id,l]);const E=n?`${ae}/api/v1/resources/${n.id}`:"",w=n?.type.startsWith("image/")??!1,b=n?n.type==="image/svg+xml"||n.name.toLowerCase().endsWith(".svg"):!1,_=n?n.type==="application/pdf"||n.name.toLowerCase().endsWith(".pdf"):!1,z=n?.type.startsWith("video/")??!1,M=n?.type.startsWith("audio/")??!1,T=n?n.type.startsWith("text/")||n.type==="application/json"||n.type.includes("javascript")||n.type.includes("typescript")||n.type.includes("xml")||n.name.toLowerCase().match(/\.(txt|md|json|js|ts|jsx|tsx|css|html|xml|yaml|yml|log|sh|bash|zsh|fish)$/)!==null:!1,A=n?n.name.toLowerCase().endsWith(".md")||n.name.toLowerCase().endsWith(".markdown"):!1,v=n?n.type==="application/json"||n.name.toLowerCase().endsWith(".json"):!1,k=n?n.type==="text/html"||n.name.toLowerCase().endsWith(".html"):!1;if(t.useEffect(()=>{const g=K=>{if(l){if(K.key==="Escape"){x?y(!1):c(!1);return}if(!x){if(K.key==="ArrowLeft"&&j){K.preventDefault(),u("prev");return}K.key==="ArrowRight"&&h&&(K.preventDefault(),u("next"))}}};if(l)return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[l,c,u,j,h,x]),t.useEffect(()=>{l&&n&&(T||A||v||k)?(d(!0),fetch(E).then(g=>{if(g.ok)return g.text();throw new Error("Failed to load file")}).then(g=>{P(g)}).catch(g=>{console.error("Failed to load text content:",g),P(null)}).finally(()=>{d(!1)})):P(null)},[l,n?.id,T,A,v,k,E]),!n)return null;const q=g=>{if(g===0)return"0 B";const K=1024,Y=["B","KB","MB","GB"],H=Math.floor(Math.log(g)/Math.log(K));return parseFloat((g/Math.pow(K,H)).toFixed(2))+" "+Y[H]},L=g=>new Date(g).toLocaleString(),D=g=>g.startsWith("image/")?e.jsx(Ne,{className:"h-6 w-6"}):g.startsWith("video/")?e.jsx(Be,{className:"h-6 w-6"}):g.startsWith("audio/")?e.jsx(fe,{className:"h-6 w-6"}):g.includes("text")||g.includes("document")||g.includes("code")?e.jsx(we,{className:"h-6 w-6"}):g.includes("json")||g.includes("javascript")||g.includes("typescript")?e.jsx(ss,{className:"h-6 w-6"}):e.jsx(Ze,{className:"h-6 w-6"}),I=()=>{if(b)return e.jsxs(e.Fragment,{children:[e.jsx("img",{src:E,alt:n.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:()=>y(!0),children:e.jsx(ys,{className:"h-4 w-4"})})]});if(_)return e.jsx("iframe",{src:E,className:"w-full h-full min-h-[600px] rounded-lg border",title:n.name});if(z)return e.jsx("video",{src:E,controls:!0,className:"max-w-full max-h-full rounded-lg shadow-lg",children:"Your browser does not support the video tag."});if(M)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(fe,{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:E,controls:!0,className:"w-3/4 min-w-[300px]",children:"Your browser does not support the audio tag."})})]});if(A&&N!==null)return S?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(pa,{remarkPlugins:[va],rehypePlugins:[ga],children:N})});if(k&&N!==null)return S?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:N,className:"w-full h-full min-h-[600px] rounded-lg border",title:n.name,sandbox:"allow-same-origin"});if(v&&N!==null){if(S)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 g=N;try{const K=JSON.parse(N);g=JSON.stringify(K,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:g})})})}return T&&N!==null?S?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:N})})}):w?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:E,alt:n.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:()=>y(!0),children:e.jsx(ys,{className:"h-4 w-4"})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 text-muted-foreground",children:[D(n.type),e.jsx("p",{className:"text-sm",children:"Preview not available for this file type"}),e.jsxs(R,{variant:"outline",onClick:()=>m(n),children:[e.jsx(es,{className:"mr-2 h-4 w-4"}),"Download to view"]})]})};return e.jsxs(e.Fragment,{children:[e.jsx(pe,{open:l,onOpenChange:c,children:e.jsxs(ge,{className:"max-w-[90vw] w-[90vw] max-h-[90vh] h-[90vh] p-0 gap-0 flex flex-col [&>button]:hidden",children:[e.jsx(ve,{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:[D(n.type),e.jsxs("div",{className:"flex-1 min-w-0 flex items-baseline gap-3",children:[e.jsx(je,{className:"text-xl truncate",children:n.name}),e.jsx("p",{className:"text-sm text-muted-foreground flex-shrink-0",children:n.type})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>p(n),title:"Copy path to clipboard",children:e.jsx(Xe,{className:"h-4 w-4"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>m(n),title:"Download",children:e.jsx(es,{className:"h-4 w-4"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>c(!1),title:"Close",children:e.jsx(cs,{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:[j&&e.jsx("button",{type:"button",onClick:()=>u("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(zs,{className:"h-5 w-5"})}),h&&e.jsx("button",{type:"button",onClick:()=>u("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($s,{className:"h-5 w-5"})}),I()]}),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(La,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Size:"}),e.jsx("span",{children:q(n.size)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ka,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Uploaded:"}),e.jsx("span",{children:L(n.uploadedAt)})]})]}),e.jsx("div",{className:"space-y-2",children:n.metadata.tags&&n.metadata.tags.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Pa,{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:n.metadata.tags.map(g=>e.jsx(Me,{variant:"secondary",className:"text-xs",children:g},g))})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[n.metadata.description?e.jsxs(e.Fragment,{children:[e.jsx(we,{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:n.metadata.description,children:n.metadata.description})]}):e.jsx("div",{className:"flex-1"}),n.metadata.generationPrompt&&e.jsxs(R,{size:"sm",className:"h-6 text-xs px-2 flex-shrink-0",onClick:()=>{navigator.clipboard.writeText(n.metadata.generationPrompt||"")},children:[e.jsx(Xe,{className:"h-2.5 w-2.5 mr-1"}),"Copy Prompt"]})]})]})})]})})]})}),x&&(w||b)&&e.jsxs("div",{className:"fixed inset-0 z-[100] bg-black/95 flex items-center justify-center",onClick:()=>y(!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:()=>y(!1),children:e.jsx(cs,{className:"h-6 w-6"})}),e.jsx("img",{src:E,alt:n.name,className:"max-w-[95vw] max-h-[95vh] object-contain",onClick:g=>g.stopPropagation()})]})]})}function Mt(){const[l,c]=t.useState([]),[n,p]=t.useState(!0),[m,u]=t.useState(!1),[j,h]=t.useState(""),[N,P]=t.useState(!1),[S,d]=t.useState([]),[x,y]=t.useState(""),[E,w]=t.useState(""),[b,_]=t.useState([]),[z,M]=t.useState(!1),[T,A]=t.useState(!1),[v,k]=t.useState(!1),[q,L]=t.useState(null),[D,I]=t.useState(null),[g,K]=t.useState(null),[Y,H]=t.useState(1),ee=12,V=t.useRef(null),{toast:O}=$e();t.useEffect(()=>{Q()},[]);const Q=async()=>{try{p(!0);const r=await(await fetch(`${ae}/api/v1/resources`)).json();r.success&&c(r.data||[])}catch(s){console.error("Failed to fetch resources:",s)}finally{p(!1)}},o=s=>{s.length!==0&&_(Array.from(s))},te=async()=>{if(b.length!==0){u(!0);try{for(const s of b){const r=new FormData;if(r.append("file",s),r.append("tags",S.join(", ")),r.append("description",E),!(await fetch(`${ae}/api/v1/resources`,{method:"POST",body:r})).ok)throw new Error("Upload failed")}d([]),y(""),w(""),_([]),P(!1),await Q(),O({title:"Upload successful",description:`${b.length} file(s) uploaded successfully`})}catch(s){console.error("Upload failed:",s),O({title:"Upload failed",description:"Failed to upload files. Please try again.",variant:"destructive"})}finally{u(!1)}}},i=()=>{d([]),y(""),w(""),_([]),P(!1)},F=s=>{if(s.key==="Enter"){s.preventDefault();const r=x.trim();r&&!S.includes(r)&&(d([...S,r]),y(""))}},se=s=>{d(S.filter(r=>r!==s))},X=s=>{_(b.filter((r,f)=>f!==s))},re=async()=>{if(g)try{if((await fetch(`${ae}/api/v1/resources/${g.id}`,{method:"DELETE"})).ok)await Q(),O({title:"Resource deleted",description:`${g.name} has been deleted`});else throw new Error("Delete failed")}catch(s){console.error("Failed to delete resource:",s),O({title:"Delete failed",description:"Failed to delete resource. Please try again.",variant:"destructive"})}finally{K(null)}},ue=async s=>{try{const r=`.nut/resources/files/${s.path}`;await Ca(r),O({title:"Path copied!",description:`Copied ${r} to clipboard`})}catch(r){console.error("Failed to copy path:",r),O({title:"Failed to copy",description:"Unable to copy path to clipboard",variant:"destructive"})}},he=s=>{if(s===0)return"0 B";const r=1024,f=["B","KB","MB","GB"],Z=Math.floor(Math.log(s)/Math.log(r));return parseFloat((s/Math.pow(r,Z)).toFixed(2))+" "+f[Z]},Ie=(s,r)=>{const f=r.toLowerCase();return s.startsWith("image/")?s==="image/svg+xml"||f.endsWith(".svg")?e.jsx(fs,{className:"h-4 w-4"}):e.jsx(Ne,{className:"h-4 w-4"}):s.startsWith("video/")?e.jsx(gs,{className:"h-4 w-4"}):s.startsWith("audio/")?e.jsx(xs,{className:"h-4 w-4"}):s==="application/pdf"||f.endsWith(".pdf")?e.jsx(we,{className:"h-4 w-4"}):f.match(/\.(js|jsx|ts|tsx|py|java|cpp|c|h|hpp|cs|go|rs|rb|php|swift|kt|scala|r|m|mm)$/)?e.jsx(ss,{className:"h-4 w-4"}):s==="application/json"||f.endsWith(".json")?e.jsx(ps,{className:"h-4 w-4"}):s.includes("spreadsheet")||s.includes("excel")||f.match(/\.(xls|xlsx|csv)$/)?e.jsx(vs,{className:"h-4 w-4"}):s.includes("presentation")||s.includes("powerpoint")||f.match(/\.(ppt|pptx)$/)?e.jsx(bs,{className:"h-4 w-4"}):s.startsWith("text/")||s.includes("document")||s.includes("word")?e.jsx(we,{className:"h-4 w-4"}):s.includes("font")||f.match(/\.(ttf|otf|woff|woff2|eot)$/)?e.jsx(js,{className:"h-4 w-4"}):e.jsx(Ze,{className:"h-4 w-4"})},Re=(s,r)=>{const f=r.toLowerCase();return s.startsWith("image/")?s==="image/svg+xml"||f.endsWith(".svg")?e.jsx(fs,{className:"h-16 w-16"}):e.jsx(Ne,{className:"h-16 w-16"}):s.startsWith("video/")?e.jsx(gs,{className:"h-16 w-16"}):s.startsWith("audio/")?e.jsx(xs,{className:"h-16 w-16"}):s==="application/pdf"||f.endsWith(".pdf")?e.jsx(we,{className:"h-16 w-16"}):f.match(/\.(js|jsx|ts|tsx|py|java|cpp|c|h|hpp|cs|go|rs|rb|php|swift|kt|scala|r|m|mm)$/)?e.jsx(ss,{className:"h-16 w-16"}):s==="application/json"||f.endsWith(".json")?e.jsx(ps,{className:"h-16 w-16"}):s.includes("spreadsheet")||s.includes("excel")||f.match(/\.(xls|xlsx|csv)$/)?e.jsx(vs,{className:"h-16 w-16"}):s.includes("presentation")||s.includes("powerpoint")||f.match(/\.(ppt|pptx)$/)?e.jsx(bs,{className:"h-16 w-16"}):s.startsWith("text/")||s.includes("document")||s.includes("word")?e.jsx(we,{className:"h-16 w-16"}):s.includes("font")||f.match(/\.(ttf|otf|woff|woff2|eot)$/)?e.jsx(js,{className:"h-16 w-16"}):e.jsx(Ze,{className:"h-16 w-16"})},xe=s=>{const r=s.name.toLowerCase(),f=s.type.startsWith("image/");return s.type==="image/svg+xml"||r.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:`${ae}/api/v1/resources/${s.id}`,alt:s.name,className:"w-full h-full object-contain"})}):f&&s.thumbnailPath?e.jsx("img",{src:`${ae}/api/v1/resources/${s.id}/thumbnail`,alt:s.name,className:"w-full h-32 object-cover rounded-md border",onError:ne=>{ne.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:Re(s.type,s.name)})})},ie=l.filter(s=>{if(!j)return!0;const r=j.toLowerCase();return s.name.toLowerCase().includes(r)||s.metadata.description?.toLowerCase().includes(r)||s.metadata.tags?.some(f=>f.toLowerCase().includes(r))}),J=Math.ceil(ie.length/ee),Ce=(Y-1)*ee,Te=ie.slice(Ce,Ce+ee);t.useEffect(()=>{H(1)},[j]);const ze=s=>{s.preventDefault(),s.stopPropagation()},ke=s=>{s.preventDefault(),s.stopPropagation(),s.dataTransfer.files&&s.dataTransfer.files.length>0&&o(s.dataTransfer.files)},De=(s,r)=>{if(r.target.closest("button"))return;L(s);const Z=ie.findIndex(ne=>ne.id===s.id);I(Z>=0?Z:null)},Ge=s=>{window.open(`${ae}/api/v1/resources/${s.id}?download=true`)},Ae=async(s,r)=>{u(!0);try{const f=await fetch(s);if(!f.ok)throw new Error("Failed to download generated image");const Z=await f.blob(),ne=`generated-image-${Date.now()}.png`,de=new FormData;de.append("file",Z,ne),de.append("tags",S.join(","));const ce=r?.prompt?`Generated with: "${r.prompt}"${r.model?` (${r.model})`:""}`:E;if(de.append("description",ce),r?.prompt&&de.append("generationPrompt",r.prompt),r?.model&&de.append("generationModel",r.model),!(await fetch(`${ae}/api/v1/resources`,{method:"POST",body:de})).ok)throw new Error("Upload failed");await Q(),O({title:"Image saved",description:"Generated image has been saved to resources"})}catch(f){throw console.error("Failed to save generated image:",f),O({title:"Save failed",description:f instanceof Error?f.message:"Failed to save generated image",variant:"destructive"}),f}finally{u(!1)}},Le=s=>{window.dispatchEvent(new CustomEvent("customize-prompt-in-assistant",{detail:{prompt:s}}))},qe=async s=>{u(!0);try{const r=await fetch(s);if(!r.ok)throw new Error("Failed to download generated audio");const f=await r.blob();let Z="mp3";const ne=r.headers.get("content-type");ne?.includes("wav")?Z="wav":ne?.includes("flac")?Z="flac":s.includes(".wav")?Z="wav":s.includes(".flac")&&(Z="flac");const de=`generated-audio-${Date.now()}.${Z}`,ce=new FormData;if(ce.append("file",f,de),ce.append("tags",S.join(",")),ce.append("description",E),!(await fetch(`${ae}/api/v1/resources`,{method:"POST",body:ce})).ok)throw new Error("Upload failed");await Q(),O({title:"Audio saved",description:"Generated audio has been saved to resources"})}catch(r){throw console.error("Failed to save generated audio:",r),O({title:"Save failed",description:r instanceof Error?r.message:"Failed to save generated audio",variant:"destructive"}),r}finally{u(!1)}},He=async s=>{u(!0);try{const r=await fetch(s);if(!r.ok)throw new Error("Failed to download generated video");const f=await r.blob();let Z="mp4";(r.headers.get("content-type")?.includes("webm")||s.includes(".webm"))&&(Z="webm");const de=`generated-video-${Date.now()}.${Z}`,ce=new FormData;if(ce.append("file",f,de),ce.append("tags",S.join(",")),ce.append("description",E),!(await fetch(`${ae}/api/v1/resources`,{method:"POST",body:ce})).ok)throw new Error("Upload failed");await Q(),O({title:"Video saved",description:"Generated video has been saved to resources"})}catch(r){throw console.error("Failed to save generated video:",r),O({title:"Save failed",description:r instanceof Error?r.message:"Failed to save generated video",variant:"destructive"}),r}finally{u(!1)}},a=s=>{if(D===null)return;const r=s==="next"?D+1:D-1;if(r<0||r>=ie.length)return;const f=ie[r];I(r),L(f)};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(ja,{children:[e.jsx(ya,{asChild:!0,children:e.jsxs(R,{variant:"outline",size:"sm",children:[e.jsx(Ee,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Generate"}),e.jsx(ba,{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(Je,{onClick:()=>M(!0),children:[e.jsx(Ne,{className:"h-4 w-4 mr-2"}),"Image"]}),e.jsxs(Je,{onClick:()=>A(!0),children:[e.jsx(fe,{className:"h-4 w-4 mr-2"}),"Audio"]}),e.jsxs(Je,{onClick:()=>k(!0),children:[e.jsx(Be,{className:"h-4 w-4 mr-2"}),"Video"]})]})]}),e.jsxs(R,{size:"sm",onClick:()=>P(!N),children:[e.jsx(hs,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Upload Resources"})]})]})]}),e.jsx(pe,{open:N,onOpenChange:s=>!s&&i(),children:e.jsxs(ge,{className:"max-w-2xl",children:[e.jsxs(ve,{children:[e.jsx(je,{children:"Upload Resource"}),e.jsx(ds,{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:ze,onDrop:ke,onClick:()=>V.current?.click(),children:[e.jsx($a,{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:V,type:"file",multiple:!0,className:"hidden",onChange:s=>s.target.files&&o(s.target.files)}),b.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{children:["Selected Files (",b.length,")"]}),e.jsx("div",{className:"border rounded-lg p-3 max-h-40 overflow-y-auto space-y-2",children:b.map((s,r)=>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:()=>X(r),className:"h-6 w-6 p-0 ml-2",children:e.jsx(us,{className:"h-3 w-3"})})]},r))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"tags",children:"Tags"}),e.jsx(We,{id:"tags",placeholder:"Type a tag and press Enter",value:x,onChange:s=>y(s.target.value),onKeyDown:F}),S.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:S.map(s=>e.jsxs(Me,{variant:"secondary",className:"text-xs",children:[s,e.jsx("button",{type:"button",onClick:()=>se(s),className:"ml-1 hover:text-destructive",children:"×"})]},s))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"description",children:"Description"}),e.jsx(ye,{id:"description",placeholder:"Brief description of this resource...",value:E,onChange:s=>w(s.target.value),rows:3})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(R,{variant:"outline",onClick:i,disabled:m,children:"Cancel"}),e.jsx(R,{onClick:te,disabled:b.length===0||m,children:m?"Uploading...":`Upload ${b.length>0?`(${b.length})`:""}`})]})]})]})}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs("div",{className:"relative flex-1 w-full",children:[e.jsx(Ea,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(We,{placeholder:"Search resources...",value:j,onChange:s=>h(s.target.value),className:"pl-8"})]})}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:n?Array.from({length:6}).map((s,r)=>e.jsxs(Ye,{className:"animate-pulse",children:[e.jsxs(ms,{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(Qe,{children:e.jsx("div",{className:"h-20 bg-muted rounded"})})]},r)):ie.length>0?Te.map(s=>e.jsxs(Ye,{className:"hover:shadow-lg hover:bg-muted transition-all cursor-pointer",onClick:r=>De(s,r),children:[e.jsxs(ms,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[Ie(s.type,s.name),e.jsx(_a,{className:"text-sm font-medium truncate",children:s.name})]}),e.jsxs(Sa,{className:"text-xs",children:[he(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:r=>{r.stopPropagation(),ue(s)},title:"Copy path to clipboard",children:e.jsx(Xe,{className:"h-3 w-3"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:r=>{r.stopPropagation(),Ge(s)},children:e.jsx(es,{className:"h-3 w-3"})}),e.jsx(R,{variant:"ghost",size:"sm",onClick:r=>{r.stopPropagation(),K(s)},children:e.jsx(us,{className:"h-3 w-3"})})]})]}),e.jsxs(Qe,{className:"pt-0",children:[e.jsx("div",{className:"mb-3",children:xe(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(r=>e.jsx(Me,{variant:"secondary",className:"text-xs",children:r},r))})]})]},s.id)):e.jsx("div",{className:"col-span-full",children:e.jsx(Ye,{children:e.jsxs(Qe,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(Na,{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:()=>P(!0),children:[e.jsx(hs,{className:"mr-2 h-4 w-4"}),"Add First Resource"]})]})})})}),ie.length>ee&&e.jsxs("div",{className:"flex items-center justify-center gap-4 pt-4 pb-8",children:[e.jsxs(R,{variant:Y===1?"outline":"default",size:"sm",onClick:()=>H(s=>Math.max(1,s-1)),disabled:Y===1,children:[e.jsx(zs,{className:"h-4 w-4 mr-1"}),"Previous"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",Y," of ",J]}),e.jsxs(R,{variant:Y===J?"outline":"default",size:"sm",onClick:()=>H(s=>Math.min(J,s+1)),disabled:Y===J,children:["Next",e.jsx($s,{className:"h-4 w-4 ml-1"})]})]}),m&&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(Ja,{open:z,onOpenChange:M,onSave:Ae,onCustomizeInAssistant:Le}),e.jsx(xt,{open:T,onOpenChange:A,onSave:qe}),e.jsx(ft,{open:v,onOpenChange:k,onSave:He}),e.jsx(pt,{open:!!q,onOpenChange:s=>{s||L(null),s||I(null)},resource:q,onCopyPath:ue,onDownload:Ge,onNavigate:a,canNavigatePrev:D!==null&&D>0,canNavigateNext:D!==null&&D<ie.length-1}),e.jsx(pe,{open:!!g,onOpenChange:s=>!s&&K(null),children:e.jsxs(ge,{className:"max-w-md",children:[e.jsxs(ve,{children:[e.jsx(je,{children:"Delete Resource"}),e.jsxs(ds,{children:["Are you sure you want to delete ",e.jsx("strong",{children:g?.name}),"? This action cannot be undone."]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(R,{variant:"outline",onClick:()=>K(null),children:"Cancel"}),e.jsx(R,{variant:"destructive",onClick:re,children:"Delete"})]})]})})]})}export{Mt as default};