@ironmussa/funny 0.1.4 → 0.1.6

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 (87) hide show
  1. package/README.md +14 -19
  2. package/bin/funny.js +37 -66
  3. package/package.json +1 -1
  4. package/packages/client/dist/assets/{AcceptInvitePage-D2QlnwXy.js → AcceptInvitePage-Dy5B7DII.js} +1 -1
  5. package/packages/client/dist/assets/{ActivityPane-kz91jVAM.js → ActivityPane-CV-MhQ_w.js} +1 -1
  6. package/packages/client/dist/assets/{AddProjectView-DWAvSEfh.js → AddProjectView-CtW0xjNI.js} +1 -1
  7. package/packages/client/dist/assets/{AllThreadsView-CEwWCoDj.js → AllThreadsView-Cf2UKLJT.js} +1 -1
  8. package/packages/client/dist/assets/{AnalyticsView-DAWyZa5z.js → AnalyticsView-YsDXUQUQ.js} +1 -1
  9. package/packages/client/dist/assets/{App-BzBTjMsb.js → App-C4O1uemY.js} +3 -3
  10. package/packages/client/dist/assets/{AutomationInboxView-zNA4E_CB.js → AutomationInboxView-Cj4jEXBW.js} +1 -1
  11. package/packages/client/dist/assets/{BrowserPanel-CLETmPIM.js → BrowserPanel-CDhQ4pqq.js} +1 -1
  12. package/packages/client/dist/assets/{BrowserPreview-D6-GY7Lk.js → BrowserPreview-mlb1GznK.js} +1 -1
  13. package/packages/client/dist/assets/{CircuitBreakerDialog-DCiRlBvD.js → CircuitBreakerDialog-IM7SsKrh.js} +1 -1
  14. package/packages/client/dist/assets/{CommandPalette-MY2bMCP4.js → CommandPalette-DeUqe9ev.js} +1 -1
  15. package/packages/client/dist/assets/{CommentsPane-tyNsUWqs.js → CommentsPane-D6mo7vNO.js} +1 -1
  16. package/packages/client/dist/assets/{CsvTable-DB3mtG8a.js → CsvTable-Bmlrdqi0.js} +1 -1
  17. package/packages/client/dist/assets/{FileSearchDialog-4lhZizzD.js → FileSearchDialog-DOht2aCz.js} +1 -1
  18. package/packages/client/dist/assets/{FileTree-DESC68xP.js → FileTree-C-k9qiIl.js} +1 -1
  19. package/packages/client/dist/assets/{FolderPicker-B5JTJeAY.js → FolderPicker-Ccn8T963.js} +1 -1
  20. package/packages/client/dist/assets/{GeneralSettingsView-SHsx-3nX.js → GeneralSettingsView-70nd75Ez.js} +2 -2
  21. package/packages/client/dist/assets/{GitProgressModal-C_W78wcH.js → GitProgressModal-D0sRB_fY.js} +1 -1
  22. package/packages/client/dist/assets/{LiveColumnsView-XMHr9OEz.js → LiveColumnsView-Dtj6sjhY.js} +1 -1
  23. package/packages/client/dist/assets/{LoginPage-CQ9fP0F4.js → LoginPage-CX5SoY9d.js} +1 -1
  24. package/packages/client/dist/assets/{MediaPreview-2jhQWqiK.js → MediaPreview-CSLd2xQQ.js} +1 -1
  25. package/packages/client/dist/assets/{MediaPreviewDialog-ZMIFbNgy.js → MediaPreviewDialog-b3uRxGUy.js} +1 -1
  26. package/packages/client/dist/assets/{MermaidBlock-Ub8VkOL4.js → MermaidBlock--PnCK6OJ.js} +1 -1
  27. package/packages/client/dist/assets/{MobilePage-C9PpVVfq.js → MobilePage-Z6RW3JRa.js} +2 -2
  28. package/packages/client/dist/assets/{MonacoEditorDialog-Co2xdBGu.js → MonacoEditorDialog-W6AzCK4P.js} +1 -1
  29. package/packages/client/dist/assets/{OrchestratorView-CJ529EFF.js → OrchestratorView-Bk_chlQ2.js} +1 -1
  30. package/packages/client/dist/assets/{PreferencesPanel-Cz4IuCEn.js → PreferencesPanel-aHOy4y8T.js} +1 -1
  31. package/packages/client/dist/assets/{PreviewBrowser-Csflu6Sr.js → PreviewBrowser-C2HgO5nb.js} +1 -1
  32. package/packages/client/dist/assets/{ProjectFilesPane-C0-WA5jW.js → ProjectFilesPane-B3eZDUID.js} +1 -1
  33. package/packages/client/dist/assets/{ProjectHeader-Bf1gaA1F.js → ProjectHeader-D8OTTLq1.js} +1 -1
  34. package/packages/client/dist/assets/{ProjectHooksSettings-DdChzrcv.js → ProjectHooksSettings-oE9zynCA.js} +1 -1
  35. package/packages/client/dist/assets/{ReviewPane-DSytotSX.js → ReviewPane-DodN13Ot.js} +1 -1
  36. package/packages/client/dist/assets/{SearchablePicker-ePO3BIOx.js → SearchablePicker-BRZ5MGoM.js} +1 -1
  37. package/packages/client/dist/assets/{SettingsDetailView-DH9yGrff.js → SettingsDetailView-1z4FmtOi.js} +1 -1
  38. package/packages/client/dist/assets/{SettingsPageContent-C8EUEhHQ.js → SettingsPageContent-CypV-sTN.js} +3 -3
  39. package/packages/client/dist/assets/{SetupWizard-DXcV9Vsz.js → SetupWizard-DCtmS7Go.js} +1 -1
  40. package/packages/client/dist/assets/{Sidebar-CnSzyO_S.js → Sidebar-DG8RI-WX.js} +1 -1
  41. package/packages/client/dist/assets/{StashTab-BZn6-Wn3.js → StashTab-CH8c3zKD.js} +1 -1
  42. package/packages/client/dist/assets/{TestRunnerPane-Cz8KHMSp.js → TestRunnerPane-Dx19F3V9.js} +1 -1
  43. package/packages/client/dist/assets/{TextSearchDialog-BWChISXp.js → TextSearchDialog-CLPa_FJZ.js} +1 -1
  44. package/packages/client/dist/assets/{ThreadPowerline-CX-bm7_6.js → ThreadPowerline-zo87eggE.js} +1 -1
  45. package/packages/client/dist/assets/{ThreadStatusPin-CjNRn4Rx.js → ThreadStatusPin-DQr-M4nV.js} +1 -1
  46. package/packages/client/dist/assets/{ThreadView-DbwUcWMo.js → ThreadView-42eEYL7W.js} +1 -1
  47. package/packages/client/dist/assets/{app-store-BwZB2xp_.js → app-store-CfgpkFla.js} +1 -1
  48. package/packages/client/dist/assets/{automation-store-DBy-NuND.js → automation-store-CeG5quCS.js} +1 -1
  49. package/packages/client/dist/assets/{browser-panel-store-Bih_qYi6.js → browser-panel-store-NtcEgowi.js} +2 -2
  50. package/packages/client/dist/assets/{button-DeEOU1Fb.js → button-CZ967bB8.js} +1 -1
  51. package/packages/client/dist/assets/{combine-ISTWP4AL.js → combine-BhTXrTft.js} +1 -1
  52. package/packages/client/dist/assets/{comment-store-Be3Fd_A7.js → comment-store-CK5G8WPn.js} +1 -1
  53. package/packages/client/dist/assets/{diff-parse-738OLLMl.js → diff-parse-PPACfn0L.js} +1 -1
  54. package/packages/client/dist/assets/{element-CuNJpCWR.js → element-A6J8F7_i.js} +1 -1
  55. package/packages/client/dist/assets/{go-to-thread-XoxeW5m_.js → go-to-thread-BNBZv0ib.js} +1 -1
  56. package/packages/client/dist/assets/{index-BsxcqNXe.js → index-DCJpZz6M.js} +2 -2
  57. package/packages/client/dist/assets/{input-DV30TVat.js → input-C2LWQS5Y.js} +1 -1
  58. package/packages/client/dist/assets/{items-_g3-I08l.js → items-azeOGVff.js} +1 -1
  59. package/packages/client/dist/assets/{job-store-C5Ten7SL.js → job-store-Bxebwj0k.js} +1 -1
  60. package/packages/client/dist/assets/{kbd-C7L0hICt.js → kbd-GnT1qEi9.js} +1 -1
  61. package/packages/client/dist/assets/{loading-state-BQjalkhM.js → loading-state-CZgfErMi.js} +1 -1
  62. package/packages/client/dist/assets/{markdown-components-D4Y3yxJk.js → markdown-components-gp0WAMTj.js} +1 -1
  63. package/packages/client/dist/assets/{native-git-store-B9ZRXl6g.js → native-git-store-KpsndLzH.js} +1 -1
  64. package/packages/client/dist/assets/{orchestrator-store-Vf7hIdtx.js → orchestrator-store-CgmJPyrE.js} +1 -1
  65. package/packages/client/dist/assets/{pipeline-approval-store-BzDMPaHv.js → pipeline-approval-store-B7WMnOHB.js} +1 -1
  66. package/packages/client/dist/assets/{pr-detail-store-ZCVq5jO-.js → pr-detail-store-DetZmOmN.js} +1 -1
  67. package/packages/client/dist/assets/{providers-CBJW4tBi.js → providers-tWTQl7V7.js} +1 -1
  68. package/packages/client/dist/assets/{sidebar-BzOM_jNz.js → sidebar-D6F-jed-.js} +1 -1
  69. package/packages/client/dist/assets/{tabs-C98UD1RJ.js → tabs-DK0DleVt.js} +1 -1
  70. package/packages/client/dist/assets/{test-store-BbGZeyOw.js → test-store-20Ippy2V.js} +1 -1
  71. package/packages/client/dist/assets/{tooltip-icon-button-z_YicoMI.js → tooltip-icon-button-DD8fKyR8.js} +1 -1
  72. package/packages/client/dist/assets/use-active-thread-id-E8-K63Gj.js +1 -0
  73. package/packages/client/dist/assets/{use-branch-switch-mtbqs9Jw.js → use-branch-switch-DiWo4rV_.js} +1 -1
  74. package/packages/client/dist/assets/{use-image-lightbox-D_bv65q5.js → use-image-lightbox-Wc7UJrhB.js} +1 -1
  75. package/packages/client/dist/assets/{use-stable-navigate-CTxO5fW7.js → use-stable-navigate-skK7Gqvr.js} +1 -1
  76. package/packages/client/dist/assets/{use-terminal-scope-DdXii8xw.js → use-terminal-scope-CFAKbZrD.js} +1 -1
  77. package/packages/client/dist/assets/{use-thread-creation-Dyd2HCG5.js → use-thread-creation-O-5GoSUZ.js} +1 -1
  78. package/packages/client/dist/assets/{use-thread-search-BIXj6zRV.js → use-thread-search-BvRo6Jmy.js} +1 -1
  79. package/packages/client/dist/assets/{use-todo-panel-D9pAUf5W.js → use-todo-panel-DE66QQ1x.js} +1 -1
  80. package/packages/client/dist/assets/{use-unified-prompt-model-groups-CjX0kT2J.js → use-unified-prompt-model-groups-BFPXD7t_.js} +1 -1
  81. package/packages/client/dist/assets/{use-ws-CeBgbigk.js → use-ws-DSu9Bw5F.js} +3 -3
  82. package/packages/client/dist/assets/{visualizer-loader-BVlcAMHr.js → visualizer-loader-Dsa-0UOJ.js} +1 -1
  83. package/packages/client/dist/assets/{watcher-store-C6B9wUDN.js → watcher-store-CPHW6IK4.js} +1 -1
  84. package/packages/client/dist/index.html +1 -1
  85. package/packages/runtime/dist/index.js +2 -2
  86. package/packages/runtime/dist/index.js.map +1 -1
  87. package/packages/client/dist/assets/use-active-thread-id-DE1fU7g0.js +0 -1
@@ -1,3 +1,3 @@
1
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{Cr as t,Dr as n,Gn as r,Hn as i,Ht as a,I as o,It as s,Kn as c,Nt as l,Pt as u,Q as d,R as f,Y as p,Z as m,_ as h,_r as g,ar as _,b as v,h as y,hr as b,ht as x,i as S,ir as C,lr as w,ot as T,rn as E,vn as ee,y as D,yr as O,z as te,zr as k}from"./icons-sqwAEN28.js";import{o as ne}from"./markdown-DBtwZWLP.js";import{t as A}from"./useTranslation-DAPPK3Hy.js";import{E as j,G as M,L as N,M as P,N as F,P as I,W as re,d as ie,f as ae,j as L,k as oe,lt as R,q as se,w as ce,y as le,yt as ue}from"./index-BsxcqNXe.js";import{t as z}from"./button-DeEOU1Fb.js";import{B as de,Dr as fe,F as pe,I as me,L as he,Ur as B,V as ge,Xt as _e,a as ve,at as V,c as ye,ct as H,d as be,f as xe,in as Se,l as Ce,mt as U,o as we,ot as Te,pt as W,q as G,sr as Ee,st as K,ut as q,x as De,yr as Oe,z as ke}from"./items-_g3-I08l.js";import{t as J}from"./input-DV30TVat.js";import{n as Ae,t as je}from"./visualizer-loader-BVlcAMHr.js";import{t as Me}from"./app-store-BwZB2xp_.js";import{t as Y}from"./tooltip-icon-button-z_YicoMI.js";import{c as Ne,r as Pe}from"./providers-CBJW4tBi.js";import{n as Fe,t as Ie}from"./use-unified-prompt-model-groups-CjX0kT2J.js";import{r as Le,t as Re}from"./PreferencesPanel-Cz4IuCEn.js";import{t as X}from"./SettingRow-D53ijhNn.js";import{n as ze}from"./native-git-store-B9ZRXl6g.js";var Z=e(k(),1);function Be(e){let t=[];for(let n of e){if(n.disabled)continue;let e=n.models.filter(e=>Ne(e.value));e.length!==0&&t.push({...n,models:e})}return t}var Q=e(ne(),1);function Ve({showHeader:e=!0}){let{t}=A(),n=Ie(),{hiddenPromptModels:r,setPromptModelVisible:i}=ae(_e(e=>({hiddenPromptModels:e.hiddenPromptModels,setPromptModelVisible:e.setPromptModelVisible}))),a=new Set(r),o=(0,Z.useMemo)(()=>Be(n),[n]),[s,c]=(0,Z.useState)(null),l=s&&o.some(e=>e.provider===s)?s:o[0]?.provider??null,u=o.find(e=>e.provider===l)??null,d=(0,Z.useCallback)((e,n)=>{i(e,n),B.success(t(`settings.saved`),{id:`settings-saved`})},[i,t]);return(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[e&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`text-foreground text-sm font-medium`,children:t(`settings.promptModelVisibility`)}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-0.5 mb-3 text-xs`,children:t(`settings.promptModelVisibilityDesc`)})]}),(0,Q.jsxs)(K,{value:l??void 0,onValueChange:e=>c(e),children:[(0,Q.jsx)(W,{className:`w-full`,"data-testid":`settings-prompt-model-provider`,children:(0,Q.jsx)(U,{placeholder:t(`settings.promptModelVisibilityProvider`)})}),(0,Q.jsx)(H,{children:o.map(e=>(0,Q.jsx)(q,{value:e.provider,"data-testid":`settings-prompt-model-provider-${e.provider}`,children:e.providerLabel},e.provider))})]}),u&&(0,Q.jsx)(`div`,{className:`mt-3 space-y-1`,children:u.models.map(e=>{let n=!a.has(e.value);return(0,Q.jsxs)(`div`,{className:`hover:bg-muted/50 flex min-w-0 items-center justify-between gap-3 rounded-md px-2 py-1.5 transition-colors`,children:[(0,Q.jsx)(`span`,{className:`text-foreground min-w-0 flex-1 truncate text-sm`,children:e.label}),(0,Q.jsx)(Te,{className:`shrink-0`,checked:n,onCheckedChange:t=>d(e.value,t),"data-testid":`settings-prompt-model-${e.value.replace(/:/g,`-`)}`,"aria-label":t(`settings.promptModelVisibilityToggle`,{model:e.label})})]},e.value)})})]})}function He(e){let t={version:1,template:{name:e.name,description:e.description,icon:e.icon,color:e.color,model:e.model,systemPromptMode:e.systemPromptMode,systemPrompt:e.systemPrompt,disallowedTools:e.disallowedTools,mcpServers:e.mcpServers,builtinSkillsDisabled:e.builtinSkillsDisabled,customSkillPaths:e.customSkillPaths,agentName:e.agentName}};for(let[e,n]of Object.entries(t.template))n===void 0&&delete t.template[e];let n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.name.replace(/[^a-zA-Z0-9_-]/g,`_`)}.agent-template.json`,i.click(),URL.revokeObjectURL(r)}function Ue(e){let t;try{t=JSON.parse(e)}catch{return`Invalid JSON file`}if(!t||typeof t!=`object`)return`Invalid template file format`;let n=t;if(n.version!==1)return`Unsupported template version`;if(!n.template||typeof n.template!=`object`)return`Missing template data`;let r=n.template;return!r.name||typeof r.name!=`string`?`Template must have a name`:r}function We(){return new Promise(e=>{let t=document.createElement(`input`);t.type=`file`,t.accept=`.json`,t.onchange=async()=>{let n=t.files?.[0];if(!n){e(`No file selected`);return}e(Ue(await n.text()))},t.click()})}var Ge=[`#7CB9E8`,`#F4A4A4`,`#A8D5A2`,`#F9D98C`,`#C3A6E0`,`#F2A6C8`,`#89D4CF`,`#F9B97C`],Ke=[`code-review`,`coding-prefs`,`planning`];function qe(e){return e.id.startsWith(`__builtin__`)}function Je(){let{templates:e,usageStats:t,initialized:r,loadTemplates:i,createTemplate:a,deleteTemplate:c,duplicateTemplate:l}=ve(),u=oe(e=>e.user?.id),[f,p]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{r||i()},[r,i]);let m=(0,Z.useCallback)(async()=>{let e=await a({name:`New Agent Template`});e&&(p(e.id),B.success(`Template created`))},[a]),g=(0,Z.useCallback)(async()=>{let e=await We();if(typeof e==`string`){B.error(e);return}let t=await a(e);t&&(p(t.id),B.success(`Imported "${t.name}"`))},[a]),_=(0,Z.useCallback)(async e=>{await c(e),f===e&&p(null),B.success(`Template deleted`)},[c,f]),v=(0,Z.useCallback)(async e=>{let t=await l(e);t&&(p(t.id),B.success(`Template duplicated`))},[l]),y=e.filter(e=>!qe(e)&&e.userId===u),b=e.filter(e=>!qe(e)&&e.userId!==u&&e.shared),x=e.filter(e=>qe(e));return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,Q.jsx)(`div`,{children:(0,Q.jsx)(`p`,{className:`settings-row-desc`,children:`Deep Agent configurations selectable when creating threads.`})}),(0,Q.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,Q.jsxs)(z,{variant:`outline`,size:`sm`,onClick:g,"data-testid":`agent-template-import`,children:[(0,Q.jsx)(h,{className:`icon-sm mr-1.5`}),`Import`]}),(0,Q.jsxs)(z,{size:`sm`,onClick:m,"data-testid":`agent-template-create`,children:[(0,Q.jsx)(d,{className:`icon-sm mr-1.5`}),`Create`]})]})]}),y.length===0&&b.length===0&&x.length===0&&(0,Q.jsxs)(`div`,{className:`text-muted-foreground rounded-md border border-dashed p-6 text-center`,children:[(0,Q.jsx)(n,{className:`mx-auto mb-2 size-8 opacity-50`}),(0,Q.jsx)(`p`,{children:`No agent templates yet.`}),(0,Q.jsx)(`p`,{className:`text-xs`,children:`Create one to define a reusable Deep Agent configuration.`})]}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:y.map(e=>(0,Q.jsx)(`div`,{children:f===e.id?(0,Q.jsx)(Xe,{template:e,onClose:()=>p(null),onDelete:()=>_(e.id)}):(0,Q.jsx)(Ye,{template:e,threadCount:t[e.id]??0,onEdit:()=>p(e.id),onDelete:()=>_(e.id),onDuplicate:()=>v(e.id),onExport:()=>He(e)})},e.id))}),b.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`mt-6 mb-2 flex items-center gap-2`,children:[(0,Q.jsx)(o,{className:`text-muted-foreground size-3`}),(0,Q.jsx)(`h4`,{className:`text-muted-foreground text-xs font-medium`,children:`Shared Templates`})]}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:b.map(e=>(0,Q.jsx)(Ye,{template:e,threadCount:t[e.id]??0,onEdit:()=>{},onDelete:()=>{},onDuplicate:()=>v(e.id),onExport:()=>He(e),isBuiltin:!0},e.id))})]}),x.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`mt-6 mb-2 flex items-center gap-2`,children:[(0,Q.jsx)(s,{className:`text-muted-foreground size-3`}),(0,Q.jsx)(`h4`,{className:`text-muted-foreground text-xs font-medium`,children:`Built-in Templates`})]}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,Q.jsx)(Ye,{template:e,threadCount:t[e.id]??0,onEdit:()=>{},onDelete:()=>{},onDuplicate:()=>v(e.id),onExport:()=>He(e),isBuiltin:!0},e.id))})]})]})}function Ye({template:e,threadCount:t,onEdit:n,onDelete:r,onDuplicate:a,onExport:o,isBuiltin:s=!1}){return(0,Q.jsxs)(`div`,{className:R(`group flex items-center gap-3 rounded-md border bg-card p-3 transition-colors`,!s&&`cursor-pointer hover:bg-accent/50`),onClick:s?void 0:n,"data-testid":`agent-template-card-${e.id}`,children:[e.color&&(0,Q.jsx)(`div`,{className:`size-3 shrink-0 rounded-full`,style:{backgroundColor:e.color}}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`p`,{className:`truncate text-sm font-medium`,children:e.name}),s&&(0,Q.jsx)(`span`,{className:`bg-muted text-muted-foreground shrink-0 rounded px-1.5 py-0.5 text-[9px] font-medium`,children:`Built-in`})]}),e.description&&(0,Q.jsx)(`p`,{className:`text-muted-foreground truncate text-xs`,children:e.description})]}),(0,Q.jsxs)(`span`,{className:`text-muted-foreground shrink-0 text-[10px]`,"data-testid":`agent-template-thread-count-${e.id}`,children:[t,` `,t===1?`thread`:`threads`]}),e.model&&(0,Q.jsx)(`span`,{className:`bg-muted text-muted-foreground shrink-0 rounded px-1.5 py-0.5 text-[10px]`,children:e.model}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 gap-1 opacity-0 group-hover:opacity-100`,children:[(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`size-6`,onClick:e=>{e.stopPropagation(),o()},"data-testid":`agent-template-export-${e.id}`,children:(0,Q.jsx)(i,{className:`size-3`})}),(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`size-6`,onClick:e=>{e.stopPropagation(),a()},"data-testid":`agent-template-duplicate-${e.id}`,children:(0,Q.jsx)(c,{className:`size-3`})}),!s&&(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`text-destructive size-6`,onClick:e=>{e.stopPropagation(),r()},"data-testid":`agent-template-delete-${e.id}`,children:(0,Q.jsx)(v,{className:`size-3`})})]})]})}function Xe({template:e,onClose:t,onDelete:n}){let{updateTemplate:r}=ve(),i=(0,Z.useCallback)(async t=>{await r(e.id,t)},[r,e.id]);return(0,Q.jsxs)(`div`,{className:`bg-card rounded-md border`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between border-b px-4 py-3`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium`,children:`Edit Template`}),(0,Q.jsxs)(`div`,{className:`flex gap-1`,children:[(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,className:`text-destructive`,onClick:n,"data-testid":`agent-template-editor-delete`,children:(0,Q.jsx)(v,{className:`icon-sm`})}),(0,Q.jsx)(z,{variant:`outline`,size:`sm`,onClick:t,"data-testid":`agent-template-editor-close`,children:`Close editor`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1 p-4`,children:[(0,Q.jsx)(Ze,{template:e,onSave:i}),(0,Q.jsx)($,{title:`Model`,defaultOpen:!1,children:(0,Q.jsx)(Qe,{template:e,onSave:i})}),(0,Q.jsx)($,{title:`System Prompt`,defaultOpen:!!e.systemPrompt,children:(0,Q.jsx)($e,{template:e,onSave:i})}),(0,Q.jsx)($,{title:`Tools`,defaultOpen:!!e.disallowedTools?.length,children:(0,Q.jsx)(et,{template:e,onSave:i})}),(0,Q.jsx)($,{title:`Skills`,defaultOpen:!!e.builtinSkillsDisabled?.length,children:(0,Q.jsx)(tt,{template:e,onSave:i})}),(0,Q.jsx)($,{title:`MCP Servers`,defaultOpen:!!e.mcpServers?.length,children:(0,Q.jsx)(nt,{template:e,onSave:i})}),(0,Q.jsx)($,{title:`Variables`,defaultOpen:!!e.variables?.length,children:(0,Q.jsx)(it,{template:e,onSave:i})}),(0,Q.jsx)($,{title:`Sharing`,defaultOpen:!!e.shared,children:(0,Q.jsx)(at,{template:e,onSave:i})})]})]})}function $({title:e,defaultOpen:t=!1,children:n}){return(0,Q.jsxs)(ge,{defaultOpen:t,children:[(0,Q.jsxs)(ke,{className:`text-muted-foreground hover:bg-accent/50 flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs font-medium`,children:[(0,Q.jsx)(g,{className:`size-3 transition-transform [[data-state=closed]>&]:-rotate-90`}),e]}),(0,Q.jsx)(de,{children:(0,Q.jsx)(`div`,{className:`px-2 pt-1 pb-2`,children:n})})]})}function Ze({template:e,onSave:t}){return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsx)(`div`,{className:`flex gap-2`,children:(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Name`}),(0,Q.jsx)(J,{defaultValue:e.name,onBlur:n=>{n.target.value!==e.name&&t({name:n.target.value})},"data-testid":`agent-template-name`})]})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Description`}),(0,Q.jsx)(J,{defaultValue:e.description??``,placeholder:`What does this agent do?`,onBlur:n=>{let r=n.target.value||void 0;r!==(e.description??void 0)&&t({description:r})},"data-testid":`agent-template-description`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Color`}),(0,Q.jsxs)(`div`,{className:`flex gap-1.5`,children:[Ge.map(n=>(0,Q.jsx)(`button`,{className:R(`size-5 rounded-full border-2 transition-all`,e.color===n?`border-foreground scale-110`:`border-transparent`),style:{backgroundColor:n},onClick:()=>t({color:n}),"data-testid":`agent-template-color-${n}`},n)),e.color&&(0,Q.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground ml-1 text-[10px]`,onClick:()=>t({color:void 0}),children:`clear`})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Agent Name`}),(0,Q.jsx)(J,{defaultValue:e.agentName??``,placeholder:`funny-coding-assistant`,onBlur:n=>{let r=n.target.value||void 0;r!==(e.agentName??void 0)&&t({agentName:r})},"data-testid":`agent-template-agent-name`})]})]})}function Qe({template:e,onSave:t}){let n=Pe.deepagent??[];return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Default Model`}),(0,Q.jsxs)(K,{value:e.model??``,onValueChange:e=>t({model:e}),children:[(0,Q.jsx)(W,{className:`w-full`,"data-testid":`agent-template-model`,children:(0,Q.jsx)(U,{placeholder:`Use project default`})}),(0,Q.jsx)(H,{children:n.map(e=>(0,Q.jsx)(q,{value:e.value,children:e.fallback},e.value))})]}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-1 text-[10px]`,children:`Provider is always Deep Agent. Model can be overridden per-thread.`})]})}function $e({template:e,onSave:t}){let[n,r]=(0,Z.useState)(e.systemPrompt??``);return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Mode`}),(0,Q.jsx)(`div`,{className:`flex gap-1`,children:[`prepend`,`replace`,`append`].map(n=>(0,Q.jsx)(`button`,{className:R(`rounded-md px-2.5 py-1 text-xs transition-colors`,e.systemPromptMode===n?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`),onClick:()=>t({systemPromptMode:n}),"data-testid":`agent-template-prompt-mode-${n}`,children:n},n))}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-1 text-[10px]`,children:e.systemPromptMode===`replace`?`Replaces the default Deep Agent system prompt entirely.`:e.systemPromptMode===`append`?`Added after the default system prompt.`:`Added before the default system prompt.`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Prompt`}),(0,Q.jsx)(`textarea`,{className:`bg-background placeholder:text-muted-foreground focus:ring-ring w-full rounded-md border px-3 py-2 text-xs leading-relaxed focus:ring-1 focus:outline-hidden`,rows:6,value:n,onChange:e=>r(e.target.value),onBlur:()=>{n!==(e.systemPrompt??``)&&t({systemPrompt:n||void 0})},placeholder:`Enter custom system prompt instructions...`,"data-testid":`agent-template-system-prompt`})]})]})}function et({template:e,onSave:t}){let n=new Set(e.disallowedTools??[]),r=e=>{let r=new Set(n);r.has(e)?r.delete(e):r.add(e),t({disallowedTools:r.size>0?[...r]:void 0})};return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-2 text-[10px]`,children:`Uncheck tools to disable them for this agent template.`}),(0,Q.jsx)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:we.map(e=>(0,Q.jsxs)(`label`,{className:`hover:bg-accent/50 flex cursor-pointer items-center gap-2 rounded px-2 py-1 text-xs`,children:[(0,Q.jsx)(G,{checked:!n.has(e),onCheckedChange:()=>r(e),"data-testid":`agent-template-tool-${e}`}),(0,Q.jsx)(`span`,{className:`font-mono text-[11px]`,children:e})]},e))})]})}function tt({template:e,onSave:t}){let n=new Set(e.builtinSkillsDisabled??[]),r=e=>{let r=new Set(n);r.has(e)?r.delete(e):r.add(e),t({builtinSkillsDisabled:r.size>0?[...r]:void 0})};return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-2 text-[10px]`,children:`Toggle built-in skills for this agent template.`}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:Ke.map(e=>(0,Q.jsxs)(`label`,{className:`hover:bg-accent/50 flex cursor-pointer items-center gap-2 rounded px-2 py-1 text-xs`,children:[(0,Q.jsx)(G,{checked:!n.has(e),onCheckedChange:()=>r(e),"data-testid":`agent-template-skill-${e}`}),(0,Q.jsx)(`span`,{children:e}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`(built-in)`})]},e))})]})}function nt({template:e,onSave:t}){let n=e.mcpServers??[],[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(null),s=e=>{let r=n.filter((t,n)=>n!==e);t({mcpServers:r.length>0?r:void 0}),a===e&&o(null)},c=(e,r)=>{let a=[...n];r!==void 0&&r<a.length?a[r]=e:a.push(e),t({mcpServers:a}),i(!1),o(null)};return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-2 text-[10px]`,children:`Configure MCP servers that will be attached to this agent at startup.`}),n.length>0&&(0,Q.jsx)(`div`,{className:`mb-2 space-y-1`,children:n.map((e,t)=>a===t?(0,Q.jsx)(rt,{initial:e,onSave:e=>c(e,t),onCancel:()=>o(null)},t):(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded border px-2 py-1.5 text-xs`,"data-testid":`agent-template-mcp-server-${t}`,children:[(0,Q.jsx)(f,{className:`text-muted-foreground size-3 shrink-0`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,Q.jsx)(`span`,{className:`bg-muted text-muted-foreground rounded px-1 py-0.5 text-[10px]`,children:e.type}),(0,Q.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.type===`stdio`?e.command:e.url}),(0,Q.jsxs)(`div`,{className:`ml-auto flex gap-1`,children:[(0,Q.jsx)(`button`,{onClick:()=>o(t),className:`text-muted-foreground hover:text-foreground rounded p-0.5`,"data-testid":`agent-template-mcp-edit-${t}`,children:(0,Q.jsx)(T,{className:`size-3`})}),(0,Q.jsx)(`button`,{onClick:()=>s(t),className:`text-muted-foreground hover:text-destructive rounded p-0.5`,"data-testid":`agent-template-mcp-delete-${t}`,children:(0,Q.jsx)(v,{className:`size-3`})})]})]},t))}),r?(0,Q.jsx)(rt,{onSave:e=>c(e),onCancel:()=>i(!1)}):(0,Q.jsxs)(z,{variant:`outline`,size:`sm`,className:`text-xs`,onClick:()=>i(!0),"data-testid":`agent-template-mcp-add`,children:[(0,Q.jsx)(d,{className:`mr-1 size-3`}),`Add MCP Server`]})]})}function rt({initial:e,onSave:t,onCancel:n}){let[r,i]=(0,Z.useState)(e?.name??``),[a,o]=(0,Z.useState)(e?.type??`stdio`),[s,c]=(0,Z.useState)(e?.command??``),[l,u]=(0,Z.useState)(e?.url??``),[d,f]=(0,Z.useState)(()=>(e?.args??[]).join(`, `)),[p,m]=(0,Z.useState)(()=>Object.entries(e?.env??{}).map(([e,t])=>`${e}=${t}`).join(`
1
+ import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{Cr as t,Dr as n,Gn as r,Hn as i,Ht as a,I as o,It as s,Kn as c,Nt as l,Pt as u,Q as d,R as f,Y as p,Z as m,_ as h,_r as g,ar as _,b as v,h as y,hr as b,ht as x,i as S,ir as C,lr as w,ot as T,rn as E,vn as ee,y as D,yr as O,z as te,zr as k}from"./icons-sqwAEN28.js";import{o as ne}from"./markdown-DBtwZWLP.js";import{t as A}from"./useTranslation-DAPPK3Hy.js";import{E as j,G as M,L as N,M as P,N as F,P as I,W as re,d as ie,f as ae,j as L,k as oe,lt as R,q as se,w as ce,y as le,yt as ue}from"./index-DCJpZz6M.js";import{t as z}from"./button-CZ967bB8.js";import{B as de,Dr as fe,F as pe,I as me,L as he,Ur as B,V as ge,Xt as _e,a as ve,at as V,c as ye,ct as H,d as be,f as xe,in as Se,l as Ce,mt as U,o as we,ot as Te,pt as W,q as G,sr as Ee,st as K,ut as q,x as De,yr as Oe,z as ke}from"./items-azeOGVff.js";import{t as J}from"./input-C2LWQS5Y.js";import{n as Ae,t as je}from"./visualizer-loader-Dsa-0UOJ.js";import{t as Me}from"./app-store-CfgpkFla.js";import{t as Y}from"./tooltip-icon-button-DD8fKyR8.js";import{c as Ne,r as Pe}from"./providers-tWTQl7V7.js";import{n as Fe,t as Ie}from"./use-unified-prompt-model-groups-BFPXD7t_.js";import{r as Le,t as Re}from"./PreferencesPanel-aHOy4y8T.js";import{t as X}from"./SettingRow-D53ijhNn.js";import{n as ze}from"./native-git-store-KpsndLzH.js";var Z=e(k(),1);function Be(e){let t=[];for(let n of e){if(n.disabled)continue;let e=n.models.filter(e=>Ne(e.value));e.length!==0&&t.push({...n,models:e})}return t}var Q=e(ne(),1);function Ve({showHeader:e=!0}){let{t}=A(),n=Ie(),{hiddenPromptModels:r,setPromptModelVisible:i}=ae(_e(e=>({hiddenPromptModels:e.hiddenPromptModels,setPromptModelVisible:e.setPromptModelVisible}))),a=new Set(r),o=(0,Z.useMemo)(()=>Be(n),[n]),[s,c]=(0,Z.useState)(null),l=s&&o.some(e=>e.provider===s)?s:o[0]?.provider??null,u=o.find(e=>e.provider===l)??null,d=(0,Z.useCallback)((e,n)=>{i(e,n),B.success(t(`settings.saved`),{id:`settings-saved`})},[i,t]);return(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[e&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`text-foreground text-sm font-medium`,children:t(`settings.promptModelVisibility`)}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-0.5 mb-3 text-xs`,children:t(`settings.promptModelVisibilityDesc`)})]}),(0,Q.jsxs)(K,{value:l??void 0,onValueChange:e=>c(e),children:[(0,Q.jsx)(W,{className:`w-full`,"data-testid":`settings-prompt-model-provider`,children:(0,Q.jsx)(U,{placeholder:t(`settings.promptModelVisibilityProvider`)})}),(0,Q.jsx)(H,{children:o.map(e=>(0,Q.jsx)(q,{value:e.provider,"data-testid":`settings-prompt-model-provider-${e.provider}`,children:e.providerLabel},e.provider))})]}),u&&(0,Q.jsx)(`div`,{className:`mt-3 space-y-1`,children:u.models.map(e=>{let n=!a.has(e.value);return(0,Q.jsxs)(`div`,{className:`hover:bg-muted/50 flex min-w-0 items-center justify-between gap-3 rounded-md px-2 py-1.5 transition-colors`,children:[(0,Q.jsx)(`span`,{className:`text-foreground min-w-0 flex-1 truncate text-sm`,children:e.label}),(0,Q.jsx)(Te,{className:`shrink-0`,checked:n,onCheckedChange:t=>d(e.value,t),"data-testid":`settings-prompt-model-${e.value.replace(/:/g,`-`)}`,"aria-label":t(`settings.promptModelVisibilityToggle`,{model:e.label})})]},e.value)})})]})}function He(e){let t={version:1,template:{name:e.name,description:e.description,icon:e.icon,color:e.color,model:e.model,systemPromptMode:e.systemPromptMode,systemPrompt:e.systemPrompt,disallowedTools:e.disallowedTools,mcpServers:e.mcpServers,builtinSkillsDisabled:e.builtinSkillsDisabled,customSkillPaths:e.customSkillPaths,agentName:e.agentName}};for(let[e,n]of Object.entries(t.template))n===void 0&&delete t.template[e];let n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.name.replace(/[^a-zA-Z0-9_-]/g,`_`)}.agent-template.json`,i.click(),URL.revokeObjectURL(r)}function Ue(e){let t;try{t=JSON.parse(e)}catch{return`Invalid JSON file`}if(!t||typeof t!=`object`)return`Invalid template file format`;let n=t;if(n.version!==1)return`Unsupported template version`;if(!n.template||typeof n.template!=`object`)return`Missing template data`;let r=n.template;return!r.name||typeof r.name!=`string`?`Template must have a name`:r}function We(){return new Promise(e=>{let t=document.createElement(`input`);t.type=`file`,t.accept=`.json`,t.onchange=async()=>{let n=t.files?.[0];if(!n){e(`No file selected`);return}e(Ue(await n.text()))},t.click()})}var Ge=[`#7CB9E8`,`#F4A4A4`,`#A8D5A2`,`#F9D98C`,`#C3A6E0`,`#F2A6C8`,`#89D4CF`,`#F9B97C`],Ke=[`code-review`,`coding-prefs`,`planning`];function qe(e){return e.id.startsWith(`__builtin__`)}function Je(){let{templates:e,usageStats:t,initialized:r,loadTemplates:i,createTemplate:a,deleteTemplate:c,duplicateTemplate:l}=ve(),u=oe(e=>e.user?.id),[f,p]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{r||i()},[r,i]);let m=(0,Z.useCallback)(async()=>{let e=await a({name:`New Agent Template`});e&&(p(e.id),B.success(`Template created`))},[a]),g=(0,Z.useCallback)(async()=>{let e=await We();if(typeof e==`string`){B.error(e);return}let t=await a(e);t&&(p(t.id),B.success(`Imported "${t.name}"`))},[a]),_=(0,Z.useCallback)(async e=>{await c(e),f===e&&p(null),B.success(`Template deleted`)},[c,f]),v=(0,Z.useCallback)(async e=>{let t=await l(e);t&&(p(t.id),B.success(`Template duplicated`))},[l]),y=e.filter(e=>!qe(e)&&e.userId===u),b=e.filter(e=>!qe(e)&&e.userId!==u&&e.shared),x=e.filter(e=>qe(e));return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,Q.jsx)(`div`,{children:(0,Q.jsx)(`p`,{className:`settings-row-desc`,children:`Deep Agent configurations selectable when creating threads.`})}),(0,Q.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,Q.jsxs)(z,{variant:`outline`,size:`sm`,onClick:g,"data-testid":`agent-template-import`,children:[(0,Q.jsx)(h,{className:`icon-sm mr-1.5`}),`Import`]}),(0,Q.jsxs)(z,{size:`sm`,onClick:m,"data-testid":`agent-template-create`,children:[(0,Q.jsx)(d,{className:`icon-sm mr-1.5`}),`Create`]})]})]}),y.length===0&&b.length===0&&x.length===0&&(0,Q.jsxs)(`div`,{className:`text-muted-foreground rounded-md border border-dashed p-6 text-center`,children:[(0,Q.jsx)(n,{className:`mx-auto mb-2 size-8 opacity-50`}),(0,Q.jsx)(`p`,{children:`No agent templates yet.`}),(0,Q.jsx)(`p`,{className:`text-xs`,children:`Create one to define a reusable Deep Agent configuration.`})]}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:y.map(e=>(0,Q.jsx)(`div`,{children:f===e.id?(0,Q.jsx)(Xe,{template:e,onClose:()=>p(null),onDelete:()=>_(e.id)}):(0,Q.jsx)(Ye,{template:e,threadCount:t[e.id]??0,onEdit:()=>p(e.id),onDelete:()=>_(e.id),onDuplicate:()=>v(e.id),onExport:()=>He(e)})},e.id))}),b.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`mt-6 mb-2 flex items-center gap-2`,children:[(0,Q.jsx)(o,{className:`text-muted-foreground size-3`}),(0,Q.jsx)(`h4`,{className:`text-muted-foreground text-xs font-medium`,children:`Shared Templates`})]}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:b.map(e=>(0,Q.jsx)(Ye,{template:e,threadCount:t[e.id]??0,onEdit:()=>{},onDelete:()=>{},onDuplicate:()=>v(e.id),onExport:()=>He(e),isBuiltin:!0},e.id))})]}),x.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`mt-6 mb-2 flex items-center gap-2`,children:[(0,Q.jsx)(s,{className:`text-muted-foreground size-3`}),(0,Q.jsx)(`h4`,{className:`text-muted-foreground text-xs font-medium`,children:`Built-in Templates`})]}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,Q.jsx)(Ye,{template:e,threadCount:t[e.id]??0,onEdit:()=>{},onDelete:()=>{},onDuplicate:()=>v(e.id),onExport:()=>He(e),isBuiltin:!0},e.id))})]})]})}function Ye({template:e,threadCount:t,onEdit:n,onDelete:r,onDuplicate:a,onExport:o,isBuiltin:s=!1}){return(0,Q.jsxs)(`div`,{className:R(`group flex items-center gap-3 rounded-md border bg-card p-3 transition-colors`,!s&&`cursor-pointer hover:bg-accent/50`),onClick:s?void 0:n,"data-testid":`agent-template-card-${e.id}`,children:[e.color&&(0,Q.jsx)(`div`,{className:`size-3 shrink-0 rounded-full`,style:{backgroundColor:e.color}}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`p`,{className:`truncate text-sm font-medium`,children:e.name}),s&&(0,Q.jsx)(`span`,{className:`bg-muted text-muted-foreground shrink-0 rounded px-1.5 py-0.5 text-[9px] font-medium`,children:`Built-in`})]}),e.description&&(0,Q.jsx)(`p`,{className:`text-muted-foreground truncate text-xs`,children:e.description})]}),(0,Q.jsxs)(`span`,{className:`text-muted-foreground shrink-0 text-[10px]`,"data-testid":`agent-template-thread-count-${e.id}`,children:[t,` `,t===1?`thread`:`threads`]}),e.model&&(0,Q.jsx)(`span`,{className:`bg-muted text-muted-foreground shrink-0 rounded px-1.5 py-0.5 text-[10px]`,children:e.model}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 gap-1 opacity-0 group-hover:opacity-100`,children:[(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`size-6`,onClick:e=>{e.stopPropagation(),o()},"data-testid":`agent-template-export-${e.id}`,children:(0,Q.jsx)(i,{className:`size-3`})}),(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`size-6`,onClick:e=>{e.stopPropagation(),a()},"data-testid":`agent-template-duplicate-${e.id}`,children:(0,Q.jsx)(c,{className:`size-3`})}),!s&&(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`text-destructive size-6`,onClick:e=>{e.stopPropagation(),r()},"data-testid":`agent-template-delete-${e.id}`,children:(0,Q.jsx)(v,{className:`size-3`})})]})]})}function Xe({template:e,onClose:t,onDelete:n}){let{updateTemplate:r}=ve(),i=(0,Z.useCallback)(async t=>{await r(e.id,t)},[r,e.id]);return(0,Q.jsxs)(`div`,{className:`bg-card rounded-md border`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between border-b px-4 py-3`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium`,children:`Edit Template`}),(0,Q.jsxs)(`div`,{className:`flex gap-1`,children:[(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,className:`text-destructive`,onClick:n,"data-testid":`agent-template-editor-delete`,children:(0,Q.jsx)(v,{className:`icon-sm`})}),(0,Q.jsx)(z,{variant:`outline`,size:`sm`,onClick:t,"data-testid":`agent-template-editor-close`,children:`Close editor`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1 p-4`,children:[(0,Q.jsx)(Ze,{template:e,onSave:i}),(0,Q.jsx)($,{title:`Model`,defaultOpen:!1,children:(0,Q.jsx)(Qe,{template:e,onSave:i})}),(0,Q.jsx)($,{title:`System Prompt`,defaultOpen:!!e.systemPrompt,children:(0,Q.jsx)($e,{template:e,onSave:i})}),(0,Q.jsx)($,{title:`Tools`,defaultOpen:!!e.disallowedTools?.length,children:(0,Q.jsx)(et,{template:e,onSave:i})}),(0,Q.jsx)($,{title:`Skills`,defaultOpen:!!e.builtinSkillsDisabled?.length,children:(0,Q.jsx)(tt,{template:e,onSave:i})}),(0,Q.jsx)($,{title:`MCP Servers`,defaultOpen:!!e.mcpServers?.length,children:(0,Q.jsx)(nt,{template:e,onSave:i})}),(0,Q.jsx)($,{title:`Variables`,defaultOpen:!!e.variables?.length,children:(0,Q.jsx)(it,{template:e,onSave:i})}),(0,Q.jsx)($,{title:`Sharing`,defaultOpen:!!e.shared,children:(0,Q.jsx)(at,{template:e,onSave:i})})]})]})}function $({title:e,defaultOpen:t=!1,children:n}){return(0,Q.jsxs)(ge,{defaultOpen:t,children:[(0,Q.jsxs)(ke,{className:`text-muted-foreground hover:bg-accent/50 flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs font-medium`,children:[(0,Q.jsx)(g,{className:`size-3 transition-transform [[data-state=closed]>&]:-rotate-90`}),e]}),(0,Q.jsx)(de,{children:(0,Q.jsx)(`div`,{className:`px-2 pt-1 pb-2`,children:n})})]})}function Ze({template:e,onSave:t}){return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsx)(`div`,{className:`flex gap-2`,children:(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Name`}),(0,Q.jsx)(J,{defaultValue:e.name,onBlur:n=>{n.target.value!==e.name&&t({name:n.target.value})},"data-testid":`agent-template-name`})]})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Description`}),(0,Q.jsx)(J,{defaultValue:e.description??``,placeholder:`What does this agent do?`,onBlur:n=>{let r=n.target.value||void 0;r!==(e.description??void 0)&&t({description:r})},"data-testid":`agent-template-description`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Color`}),(0,Q.jsxs)(`div`,{className:`flex gap-1.5`,children:[Ge.map(n=>(0,Q.jsx)(`button`,{className:R(`size-5 rounded-full border-2 transition-all`,e.color===n?`border-foreground scale-110`:`border-transparent`),style:{backgroundColor:n},onClick:()=>t({color:n}),"data-testid":`agent-template-color-${n}`},n)),e.color&&(0,Q.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground ml-1 text-[10px]`,onClick:()=>t({color:void 0}),children:`clear`})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Agent Name`}),(0,Q.jsx)(J,{defaultValue:e.agentName??``,placeholder:`funny-coding-assistant`,onBlur:n=>{let r=n.target.value||void 0;r!==(e.agentName??void 0)&&t({agentName:r})},"data-testid":`agent-template-agent-name`})]})]})}function Qe({template:e,onSave:t}){let n=Pe.deepagent??[];return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Default Model`}),(0,Q.jsxs)(K,{value:e.model??``,onValueChange:e=>t({model:e}),children:[(0,Q.jsx)(W,{className:`w-full`,"data-testid":`agent-template-model`,children:(0,Q.jsx)(U,{placeholder:`Use project default`})}),(0,Q.jsx)(H,{children:n.map(e=>(0,Q.jsx)(q,{value:e.value,children:e.fallback},e.value))})]}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-1 text-[10px]`,children:`Provider is always Deep Agent. Model can be overridden per-thread.`})]})}function $e({template:e,onSave:t}){let[n,r]=(0,Z.useState)(e.systemPrompt??``);return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Mode`}),(0,Q.jsx)(`div`,{className:`flex gap-1`,children:[`prepend`,`replace`,`append`].map(n=>(0,Q.jsx)(`button`,{className:R(`rounded-md px-2.5 py-1 text-xs transition-colors`,e.systemPromptMode===n?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`),onClick:()=>t({systemPromptMode:n}),"data-testid":`agent-template-prompt-mode-${n}`,children:n},n))}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-1 text-[10px]`,children:e.systemPromptMode===`replace`?`Replaces the default Deep Agent system prompt entirely.`:e.systemPromptMode===`append`?`Added after the default system prompt.`:`Added before the default system prompt.`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Prompt`}),(0,Q.jsx)(`textarea`,{className:`bg-background placeholder:text-muted-foreground focus:ring-ring w-full rounded-md border px-3 py-2 text-xs leading-relaxed focus:ring-1 focus:outline-hidden`,rows:6,value:n,onChange:e=>r(e.target.value),onBlur:()=>{n!==(e.systemPrompt??``)&&t({systemPrompt:n||void 0})},placeholder:`Enter custom system prompt instructions...`,"data-testid":`agent-template-system-prompt`})]})]})}function et({template:e,onSave:t}){let n=new Set(e.disallowedTools??[]),r=e=>{let r=new Set(n);r.has(e)?r.delete(e):r.add(e),t({disallowedTools:r.size>0?[...r]:void 0})};return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-2 text-[10px]`,children:`Uncheck tools to disable them for this agent template.`}),(0,Q.jsx)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:we.map(e=>(0,Q.jsxs)(`label`,{className:`hover:bg-accent/50 flex cursor-pointer items-center gap-2 rounded px-2 py-1 text-xs`,children:[(0,Q.jsx)(G,{checked:!n.has(e),onCheckedChange:()=>r(e),"data-testid":`agent-template-tool-${e}`}),(0,Q.jsx)(`span`,{className:`font-mono text-[11px]`,children:e})]},e))})]})}function tt({template:e,onSave:t}){let n=new Set(e.builtinSkillsDisabled??[]),r=e=>{let r=new Set(n);r.has(e)?r.delete(e):r.add(e),t({builtinSkillsDisabled:r.size>0?[...r]:void 0})};return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-2 text-[10px]`,children:`Toggle built-in skills for this agent template.`}),(0,Q.jsx)(`div`,{className:`space-y-1`,children:Ke.map(e=>(0,Q.jsxs)(`label`,{className:`hover:bg-accent/50 flex cursor-pointer items-center gap-2 rounded px-2 py-1 text-xs`,children:[(0,Q.jsx)(G,{checked:!n.has(e),onCheckedChange:()=>r(e),"data-testid":`agent-template-skill-${e}`}),(0,Q.jsx)(`span`,{children:e}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`(built-in)`})]},e))})]})}function nt({template:e,onSave:t}){let n=e.mcpServers??[],[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(null),s=e=>{let r=n.filter((t,n)=>n!==e);t({mcpServers:r.length>0?r:void 0}),a===e&&o(null)},c=(e,r)=>{let a=[...n];r!==void 0&&r<a.length?a[r]=e:a.push(e),t({mcpServers:a}),i(!1),o(null)};return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-2 text-[10px]`,children:`Configure MCP servers that will be attached to this agent at startup.`}),n.length>0&&(0,Q.jsx)(`div`,{className:`mb-2 space-y-1`,children:n.map((e,t)=>a===t?(0,Q.jsx)(rt,{initial:e,onSave:e=>c(e,t),onCancel:()=>o(null)},t):(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded border px-2 py-1.5 text-xs`,"data-testid":`agent-template-mcp-server-${t}`,children:[(0,Q.jsx)(f,{className:`text-muted-foreground size-3 shrink-0`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,Q.jsx)(`span`,{className:`bg-muted text-muted-foreground rounded px-1 py-0.5 text-[10px]`,children:e.type}),(0,Q.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.type===`stdio`?e.command:e.url}),(0,Q.jsxs)(`div`,{className:`ml-auto flex gap-1`,children:[(0,Q.jsx)(`button`,{onClick:()=>o(t),className:`text-muted-foreground hover:text-foreground rounded p-0.5`,"data-testid":`agent-template-mcp-edit-${t}`,children:(0,Q.jsx)(T,{className:`size-3`})}),(0,Q.jsx)(`button`,{onClick:()=>s(t),className:`text-muted-foreground hover:text-destructive rounded p-0.5`,"data-testid":`agent-template-mcp-delete-${t}`,children:(0,Q.jsx)(v,{className:`size-3`})})]})]},t))}),r?(0,Q.jsx)(rt,{onSave:e=>c(e),onCancel:()=>i(!1)}):(0,Q.jsxs)(z,{variant:`outline`,size:`sm`,className:`text-xs`,onClick:()=>i(!0),"data-testid":`agent-template-mcp-add`,children:[(0,Q.jsx)(d,{className:`mr-1 size-3`}),`Add MCP Server`]})]})}function rt({initial:e,onSave:t,onCancel:n}){let[r,i]=(0,Z.useState)(e?.name??``),[a,o]=(0,Z.useState)(e?.type??`stdio`),[s,c]=(0,Z.useState)(e?.command??``),[l,u]=(0,Z.useState)(e?.url??``),[d,f]=(0,Z.useState)(()=>(e?.args??[]).join(`, `)),[p,m]=(0,Z.useState)(()=>Object.entries(e?.env??{}).map(([e,t])=>`${e}=${t}`).join(`
2
2
  `));return(0,Q.jsxs)(`div`,{className:`bg-muted/30 space-y-2 rounded border p-2`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-[10px]`,children:`Name`}),(0,Q.jsx)(J,{value:r,onChange:e=>i(e.target.value),placeholder:`server-name`,className:`h-7 text-xs`,"data-testid":`agent-template-mcp-name`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-[10px]`,children:`Type`}),(0,Q.jsxs)(K,{value:a,onValueChange:e=>o(e),children:[(0,Q.jsx)(W,{size:`xs`,"data-testid":`agent-template-mcp-type`,children:(0,Q.jsx)(U,{})}),(0,Q.jsxs)(H,{children:[(0,Q.jsx)(q,{value:`stdio`,children:`stdio`}),(0,Q.jsx)(q,{value:`http`,children:`http`}),(0,Q.jsx)(q,{value:`sse`,children:`sse`})]})]})]})]}),a===`stdio`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-[10px]`,children:`Command`}),(0,Q.jsx)(J,{value:s,onChange:e=>c(e.target.value),placeholder:`npx -y @modelcontextprotocol/server-...`,className:`h-7 text-xs`,"data-testid":`agent-template-mcp-command`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`label`,{className:`text-muted-foreground text-[10px]`,children:[`Args `,(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`(comma-separated)`})]}),(0,Q.jsx)(J,{value:d,onChange:e=>f(e.target.value),placeholder:`--port, 3000`,className:`h-7 text-xs`,"data-testid":`agent-template-mcp-args`})]})]}):(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-[10px]`,children:`URL`}),(0,Q.jsx)(J,{value:l,onChange:e=>u(e.target.value),placeholder:`https://...`,className:`h-7 text-xs`,"data-testid":`agent-template-mcp-url`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`label`,{className:`text-muted-foreground text-[10px]`,children:[`Environment Variables`,` `,(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`(KEY=VALUE, one per line)`})]}),(0,Q.jsx)(`textarea`,{value:p,onChange:e=>m(e.target.value),placeholder:`API_KEY=sk-...`,rows:2,className:`bg-background w-full rounded-md border px-2 py-1 text-xs`,"data-testid":`agent-template-mcp-env`})]}),(0,Q.jsxs)(`div`,{className:`flex gap-1`,children:[(0,Q.jsx)(z,{variant:`default`,size:`sm`,className:`text-xs`,onClick:()=>{if(!r.trim())return;let e=d.split(`,`).flatMap(e=>{let t=e.trim();return t?[t]:[]}),n={};p.split(`
3
- `).forEach(e=>{let t=e.indexOf(`=`);t>0&&(n[e.slice(0,t).trim()]=e.slice(t+1).trim())}),t({name:r.trim(),type:a,...a===`stdio`?{command:s.trim(),args:e.length>0?e:void 0}:{},...a===`stdio`?{}:{url:l.trim()},...Object.keys(n).length>0?{env:n}:{}})},disabled:!r.trim(),"data-testid":`agent-template-mcp-save`,children:e?`Update`:`Add`}),(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,className:`text-xs`,onClick:n,"data-testid":`agent-template-mcp-cancel`,children:`Cancel`})]})]})}function it({template:e,onSave:t}){let n=e.variables??[],r=()=>{t({variables:[...n,{name:``,description:``,defaultValue:``}]})},i=(e,r,i)=>{let a=[...n];a[e]={...a[e],[r]:i},t({variables:a})},a=e=>{let r=n.filter((t,n)=>n!==e);t({variables:r.length>0?r:void 0})};return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`p`,{className:`text-muted-foreground mb-2 text-[10px]`,children:[`Define variables that users fill in when selecting this template. Use`,` `,(0,Q.jsx)(`code`,{className:`bg-muted rounded px-1`,children:`{{VARIABLE_NAME}}`}),` in your system prompt.`]}),n.length>0&&(0,Q.jsx)(`div`,{className:`mb-2 space-y-2`,children:n.map((e,t)=>(0,Q.jsxs)(`div`,{className:`bg-muted/30 flex items-start gap-2 rounded border p-2`,"data-testid":`agent-template-variable-${t}`,children:[(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Q.jsx)(J,{value:e.name,onChange:e=>i(t,`name`,e.target.value),placeholder:`VARIABLE_NAME`,className:`h-7 font-mono text-xs`,"data-testid":`agent-template-variable-name-${t}`}),(0,Q.jsx)(J,{value:e.description??``,onChange:e=>i(t,`description`,e.target.value),placeholder:`Description (shown to user)`,className:`h-7 text-xs`,"data-testid":`agent-template-variable-desc-${t}`}),(0,Q.jsx)(J,{value:e.defaultValue??``,onChange:e=>i(t,`defaultValue`,e.target.value),placeholder:`Default value (optional)`,className:`h-7 text-xs`,"data-testid":`agent-template-variable-default-${t}`})]}),(0,Q.jsx)(`button`,{onClick:()=>a(t),className:`text-muted-foreground hover:text-destructive mt-1 rounded p-0.5`,"data-testid":`agent-template-variable-delete-${t}`,children:(0,Q.jsx)(v,{className:`size-3`})})]},t))}),(0,Q.jsxs)(z,{variant:`outline`,size:`sm`,className:`text-xs`,onClick:r,"data-testid":`agent-template-variable-add`,children:[(0,Q.jsx)(d,{className:`mr-1 size-3`}),`Add Variable`]})]})}function at({template:e,onSave:t}){return(0,Q.jsx)(`div`,{children:(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium`,children:`Share with all users`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-[10px]`,children:`Shared templates are visible to everyone on this instance.`})]}),(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2`,children:[(0,Q.jsx)(G,{checked:e.shared??!1,onCheckedChange:e=>t({shared:e===!0}),"data-testid":`agent-template-shared`}),(0,Q.jsx)(o,{className:`text-muted-foreground size-3`})]})]})})}var ot=L(`extensions-settings`);function st(){let e=oe(e=>e.user?.role===`admin`),[t,n]=(0,Z.useState)([]),[r,i]=(0,Z.useState)(!0),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),d=(0,Z.useCallback)(async()=>{i(!0);let e=await I.listInstalledExtensions();e.isOk()?n(e.value):(ot.error(`failed to list extensions`,{error:e.error.message}),B.error(`Failed to load extensions`,{description:e.error.message})),i(!1)},[]);(0,Z.useEffect)(()=>{d()},[d]);let f=(0,Z.useCallback)(async()=>{let e=a.trim();if(!e)return;c(!0);let t=await I.installExtension(e);t.isOk()?(B.success(`Installed ${t.value.extension.id}`),o(``),await d(),await je()):B.error(`Install failed`,{description:t.error.message}),c(!1)},[a,d]),h=(0,Z.useCallback)(async e=>{u(e.name);let t=await I.removeExtension(e.name);t.isOk()?(B.success(`Removed ${e.id}`,{description:`Reload the page to fully unload it.`}),await d()):B.error(`Remove failed`,{description:t.error.message}),u(null)},[d]);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`mb-2 flex items-center justify-end`,children:(0,Q.jsx)(Y,{tooltip:`Refresh`,onClick:()=>void d(),"data-testid":`extensions-refresh`,children:(0,Q.jsx)(p,{className:r?`icon-base animate-spin`:`icon-base`})})}),(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:`Visualizer plugins extend how funny renders fenced code blocks and file previews. They run with full access to your session — install only extensions you trust.`}),(0,Q.jsxs)(`div`,{className:`settings-card mb-4 flex items-start gap-2 border-amber-500/30 bg-amber-500/5 p-3`,children:[(0,Q.jsx)(D,{className:`icon-base mt-0.5 shrink-0 text-amber-500`}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-sm`,children:`Installing an extension runs its code inside your authenticated session, like installing an npm package. There is no sandbox.`})]}),e&&(0,Q.jsxs)(`div`,{className:`settings-card mb-4 p-4`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs font-medium`,children:`Install from a local package directory (on the server)`}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(J,{value:a,onChange:e=>o(e.target.value),placeholder:`/path/to/funny-visualizer-xyz`,spellCheck:!1,"data-testid":`extensions-install-path`,onKeyDown:e=>{e.key===`Enter`&&!s&&f()}}),(0,Q.jsxs)(z,{onClick:()=>void f(),disabled:s||!a.trim(),"data-testid":`extensions-install-submit`,children:[(0,Q.jsx)(x,{className:`icon-base mr-1`}),s?`Installing…`:`Install`]})]}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:[`The directory must contain a `,(0,Q.jsx)(`code`,{children:`package.json`}),` with a `,(0,Q.jsx)(`code`,{children:`funny.client`}),` `,`entry pointing at the built ESM bundle.`]})]}),t.length===0?(0,Q.jsxs)(`div`,{className:`settings-card flex flex-col items-center gap-2 px-4 py-8 text-center`,children:[(0,Q.jsx)(m,{className:`text-muted-foreground/50 size-6`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:r?`Loading…`:`No extensions installed.`})]}):(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:t.map(t=>(0,Q.jsxs)(`div`,{className:`settings-card flex items-center gap-3 px-3 py-2.5`,"data-testid":`extension-item-${t.name}`,children:[(0,Q.jsx)(m,{className:`icon-base text-muted-foreground shrink-0`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-sm font-medium`,children:t.id}),(0,Q.jsxs)(`span`,{className:`text-muted-foreground text-xs`,children:[`v`,t.version]})]}),t.description&&(0,Q.jsx)(`p`,{className:`text-muted-foreground truncate text-xs`,children:t.description})]}),e&&(0,Q.jsx)(Y,{tooltip:`Remove`,onClick:()=>void h(t),disabled:l===t.name,"data-testid":`extension-remove-${t.name}`,children:(0,Q.jsx)(v,{className:`icon-base text-destructive`})})]},t.name))})]})}function ct(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_]+/g,`-`).replace(/^-+|-+$/g,``)}function lt(){let[e,n]=(0,Z.useState)([]),[r,i]=(0,Z.useState)(new Map),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!0),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(``),[_,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(!1),S=fe(e=>e.loadProjects),C=(0,Z.useCallback)(async()=>{try{let e=await P.getSession();o(F(e.data));let t=await P.organization.list();if(t.data){n(t.data.map(e=>({id:e.id,name:e.name,slug:e.slug,createdAt:e.createdAt||``})));let r=new Map,a=e.data?.user?.id,o=await Promise.all(t.data.map(e=>P.organization.getFullOrganization({query:{organizationId:e.id}}).catch(()=>null)));for(let e=0;e<t.data.length;e++){let n=o[e];if(n?.data){let i=n.data.members?.find(e=>e.userId===a);i&&r.set(t.data[e].id,i.role)}}i(r)}}catch(e){console.error(`[OrganizationManagement] Failed to load orgs:`,e)}finally{c(!1)}},[]);(0,Z.useEffect)(()=>{C()},[C]);let w=(0,Z.useCallback)(async()=>{let e=p.trim(),t=h.trim()||ct(e);if(!(!e||!t)){x(!0);try{await P.organization.create({name:e,slug:t}),B.success(`Organization "${e}" created`),m(``),g(``),y(!1),await C()}catch(e){B.error(e.message||`Failed to create organization`)}finally{x(!1)}}},[p,h,C]),T=(0,Z.useCallback)(async e=>{try{await P.organization.setActive({organizationId:e}),o(e),await S(),B.success(`Active organization switched`)}catch(e){B.error(e.message||`Failed to switch organization`)}},[S]),E=(0,Z.useCallback)(async()=>{if(l){f(!0);try{await P.organization.delete({organizationId:l.id}),B.success(`Organization "${l.name}" deleted`),u(null),await C()}catch(e){B.error(e.message||`Failed to delete organization`)}finally{f(!1)}}},[l,C]);return s?(0,Q.jsx)(`div`,{className:`text-muted-foreground flex items-center justify-center py-12 text-sm`,children:`Loading organizations…`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`h3`,{className:`settings-section-header`,children:`Create Organization`}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-3 text-sm`,children:`Create a new organization to manage team members and projects.`}),(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-xs font-medium`,children:`Name`}),(0,Q.jsx)(J,{value:p,onChange:e=>{m(e.target.value),_||g(ct(e.target.value))},placeholder:`My Organization`,className:`text-sm`,"data-testid":`org-create-name`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-xs font-medium`,children:`Slug`}),(0,Q.jsx)(J,{value:h,onChange:e=>{g(e.target.value),y(!0)},placeholder:`my-organization`,className:`font-mono text-sm`,"data-testid":`org-create-slug`})]}),(0,Q.jsx)(z,{size:`sm`,onClick:w,disabled:b||!p.trim(),"data-testid":`org-create-submit`,children:b?`Creating...`:`Create Organization`})]})]})}),(0,Q.jsxs)(`h3`,{className:`settings-section-header`,children:[`Your Organizations (`,e.length,`)`]}),(0,Q.jsx)(`div`,{className:`settings-card`,children:e.length===0?(0,Q.jsx)(`div`,{className:`text-muted-foreground px-4 py-6 text-center text-sm`,children:`No organizations yet. Create one above to get started.`}):e.map(e=>{let n=r.get(e.id)||`member`,i=e.id===a,o=n===`owner`;return(0,Q.jsxs)(`div`,{className:`settings-row`,"data-testid":`org-item-${e.id}`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(t,{className:`icon-base text-muted-foreground shrink-0`}),(0,Q.jsx)(`p`,{className:`text-foreground truncate text-sm font-medium`,children:e.name}),(0,Q.jsx)(V,{variant:`secondary`,className:`text-xs`,children:n}),i&&(0,Q.jsx)(V,{variant:`secondary`,className:`bg-green-500/15 text-green-700 dark:text-green-400`,children:`Active`})]}),(0,Q.jsx)(`p`,{className:`text-muted-foreground ml-6 text-xs`,children:e.slug})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!i&&(0,Q.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>T(e.id),"data-testid":`org-set-active-${e.id}`,children:[(0,Q.jsx)(O,{className:`icon-sm mr-1.5`}),`Set Active`]}),o&&(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`text-muted-foreground hover:text-destructive size-8`,onClick:()=>u(e),"data-testid":`org-delete-${e.id}`,children:(0,Q.jsx)(v,{className:`icon-base`})})]})]},e.id)})}),(0,Q.jsx)(Ee,{open:!!l,onOpenChange:e=>{e||u(null)},title:`Delete Organization`,description:`Are you sure you want to delete "${l?.name}"? This action cannot be undone. All members will lose access.`,warning:`This will permanently delete the organization and all associated data.`,cancelLabel:`Cancel`,confirmLabel:`Delete`,loading:d,onCancel:()=>u(null),onConfirm:E})]})}var ut=L(`providers-settings`),dt=j.map(e=>({id:e,label:ce[e].label}));function ft(e){return/:\/\//.test(e)||/^git@/.test(e)||/^(github|gh):/i.test(e)}function pt(){let[e,t]=(0,Z.useState)([]),[n,i]=(0,Z.useState)(!0),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null),m=Fe(e=>e.fetch),h=Fe(e=>e.activeBuiltins),g=Fe(e=>e.setActiveBuiltins),_=(0,Z.useCallback)(async()=>{i(!0);let e=await N.getProviders();e.isOk()?t(e.value.providers):(ut.error(`failed to list providers`,{error:e.error.message}),B.error(`Failed to load providers`,{description:e.error.message})),i(!1)},[]);(0,Z.useEffect)(()=>{_(),m()},[_,m]);let y=(0,Z.useCallback)(async()=>{let e=a.trim();if(!e)return;c(!0);let t=ft(e)?{git:e}:{path:e},n=await N.installProvider(t);if(n.isOk()){let e=n.value.provider;B.success(`Installed ${e.id}`,{description:`Launches "${[e.spawn.command,...e.spawn.args].join(` `)}" on your runner.`}),o(``),await _(),await m(!0)}else B.error(`Install failed`,{description:n.error.message});c(!1)},[a,_,m]),b=(0,Z.useCallback)(e=>h===null||h.includes(e),[h]),S=(0,Z.useCallback)(async(e,t)=>{f(e);let n=await N.setBuiltinEnabled(e,t);n.isOk()?(g(n.value.active),B.success(`${t?`Enabled`:`Disabled`} ${e}`,{description:`Saved — your selection is restored when the runner restarts.`})):B.error(`${t?`Enable`:`Disable`} failed`,{description:n.error.message}),f(null)},[g]),C=(0,Z.useCallback)(async e=>{u(e);let t=await N.removeProvider(e);t.isOk()?(B.success(`Removed ${e}`),await _(),await m(!0)):B.error(`Remove failed`,{description:t.error.message}),u(null)},[_,m]);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:`Install ACP agent providers onto your runner. A provider is a declarative manifest pointing at an agent CLI already installed on the runner — installing one lets funny launch that binary.`}),(0,Q.jsxs)(`div`,{className:`settings-card mb-4 flex items-start gap-2 border-amber-500/30 bg-amber-500/5 p-3`,children:[(0,Q.jsx)(D,{className:`icon-base mt-0.5 shrink-0 text-amber-500`}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-sm`,children:`Installing a provider lets funny spawn the binary it declares on your runner. Install only providers you trust.`})]}),(0,Q.jsxs)(`div`,{className:`settings-card mb-4 p-4`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs font-medium`,children:`Install from a git repo or a local path on the runner`}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(J,{value:a,onChange:e=>o(e.target.value),placeholder:`github:user/funny-myagent · or /path/to/funny-myagent`,spellCheck:!1,"data-testid":`providers-install-source`,onKeyDown:e=>{e.key===`Enter`&&!s&&y()}}),(0,Q.jsxs)(z,{onClick:()=>void y(),disabled:s||!a.trim(),"data-testid":`providers-install-submit`,children:[(0,Q.jsx)(x,{className:`icon-base mr-1`}),s?`Installing…`:`Install`]})]}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:[`The package must contain a `,(0,Q.jsx)(`code`,{children:`package.json`}),` with a `,(0,Q.jsx)(`code`,{children:`funny.provider`}),` `,`entry pointing at a `,(0,Q.jsx)(`code`,{children:`funny.provider.json`}),` manifest.`]})]}),(0,Q.jsxs)(`div`,{className:`mt-2 mb-1 flex items-center justify-between px-1`,children:[(0,Q.jsx)(`h4`,{className:`text-muted-foreground text-xs font-semibold tracking-wide uppercase`,children:`Built-in providers`}),(0,Q.jsx)(Y,{tooltip:`Refresh`,onClick:()=>void _(),"data-testid":`providers-refresh`,children:(0,Q.jsx)(p,{className:n?`icon-base animate-spin`:`icon-base`})})]}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground px-1 pb-2 text-sm`,children:[`Enable or disable bundled ACP providers in the model picker. Your selection is saved and restored when the runner restarts. Set `,(0,Q.jsx)(`code`,{children:`FUNNY_PROVIDERS`}),` on the runner to change the built-in default.`]}),(0,Q.jsx)(`div`,{className:`settings-card divide-border mb-4 space-y-0 divide-y`,children:dt.map(({id:e,label:t})=>{let n=b(e);return(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3.5`,"data-testid":`builtin-provider-${e}`,children:[(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-sm font-medium`,children:t}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:e})]})}),(0,Q.jsx)(Te,{checked:n,onCheckedChange:t=>void S(e,t),disabled:d===e,"aria-label":`${n?`Disable`:`Enable`} ${t}`,"data-testid":`builtin-toggle-${e}`})]},e)})}),(0,Q.jsx)(`div`,{className:`mt-2 mb-1 px-1`,children:(0,Q.jsx)(`h4`,{className:`text-muted-foreground text-xs font-semibold tracking-wide uppercase`,children:`Installed providers`})}),e.length===0?(0,Q.jsxs)(`div`,{className:`settings-card flex flex-col items-center gap-2 px-4 py-8 text-center`,children:[(0,Q.jsx)(r,{className:`text-muted-foreground/50 size-6`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:n?`Loading…`:`No external providers installed.`})]}):(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map(e=>(0,Q.jsxs)(`div`,{className:`settings-card flex items-center gap-3 px-3 py-2.5`,"data-testid":`provider-item-${e.id}`,children:[(0,Q.jsx)(r,{className:`icon-base text-muted-foreground shrink-0`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-sm font-medium`,children:e.label}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:e.id})]}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground truncate text-xs`,children:[e.models.kind,` catalog · default `,e.models.defaultModel,` · auth `,e.auth.mode]})]}),(0,Q.jsx)(Y,{tooltip:`Remove`,onClick:()=>void C(e.id),disabled:l===e.id,"data-testid":`provider-remove-${e.id}`,children:(0,Q.jsx)(v,{className:`icon-base text-destructive`})})]},e.id))})]})}function mt(e){return e===`online`?`text-green-500`:e===`busy`?`text-yellow-500`:`text-muted-foreground`}function ht(e){return e===`online`?`Online`:e===`busy`?`Busy`:`Offline`}function gt(e){return e===`darwin`?`🍎`:e===`win32`?`🪟`:`🐧`}function _t(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function vt({runnerId:e,onAssigned:t}){let n=Me(e=>e.projects),[r,i]=(0,Z.useState)(``),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`border-border/50 bg-muted/30 mt-3 flex flex-col gap-2 rounded border p-3`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Assign a project and provide its local path on this runner's machine.`}),(0,Q.jsxs)(K,{value:r,onValueChange:i,children:[(0,Q.jsx)(W,{size:`xs`,"data-testid":`runner-assign-project-select-${e}`,children:(0,Q.jsx)(U,{placeholder:`Select project...`})}),(0,Q.jsx)(H,{children:n.map(e=>(0,Q.jsx)(q,{value:e.id,children:e.name},e.id))})]}),(0,Q.jsx)(J,{value:a,onChange:e=>o(e.target.value),placeholder:`/home/user/my-project`,className:`h-7 font-mono text-xs`,"data-testid":`runner-assign-localpath-${e}`}),(0,Q.jsx)(z,{size:`sm`,className:`h-6 text-xs`,disabled:!r||!a.trim()||s,onClick:async()=>{if(!r||!a.trim())return;c(!0);let n=await I.assignRunnerProject(e,r,a.trim());c(!1),n.isOk()?(B.success(`Project assigned`),i(``),o(``),t()):B.error(`Failed to assign project`)},"data-testid":`runner-assign-submit-${e}`,children:s?`Assigning...`:`Assign`})]})}function yt({runner:e,onDeleted:t}){let{t:n}=A(),[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)([]),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(!1),p=async()=>{let t=await I.getMyRunners();if(t.isOk()){let n=t.value.runners.find(t=>t.runnerId===e.runnerId);n&&o(n.assignedProjectIds.map(t=>({runnerId:e.runnerId,projectId:t,localPath:``,assignedAt:``})))}},m=async()=>{u(!0);let n=await I.deleteRunner(e.runnerId);u(!1),n.isOk()?(f(!1),B.success(`Runner removed`),t()):B.error(`Failed to remove runner`)},h=async t=>{(await I.unassignRunnerProject(e.runnerId,t)).isOk()?(B.success(`Project unassigned`),p()):B.error(`Failed to unassign project`)};(0,Z.useEffect)(()=>{r&&p()},[r]);let _=Me(e=>e.projects);return(0,Q.jsxs)(ge,{open:r,onOpenChange:i,className:`border-border/50 bg-card overflow-hidden rounded-lg border`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5`,"data-testid":`runner-item-${e.runnerId}`,children:[(0,Q.jsx)(C,{className:R(`size-2 shrink-0 fill-current`,mt(e.status))}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-sm font-medium`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-xs`,children:gt(e.os)}),(0,Q.jsx)(V,{variant:`outline`,className:R(`h-4 px-1.5 text-[10px]`,mt(e.status)),children:ht(e.status)})]}),(0,Q.jsxs)(`div`,{className:`text-muted-foreground truncate text-xs`,children:[e.hostname,` · last seen `,_t(e.lastHeartbeatAt),e.assignedProjectIds.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[` `,`· `,e.assignedProjectIds.length,` project`,e.assignedProjectIds.length===1?``:`s`]})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsxs)(re,{children:[(0,Q.jsx)(se,{asChild:!0,children:(0,Q.jsx)(ke,{asChild:!0,children:(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`size-6`,"data-testid":`runner-item-${e.runnerId}-expand`,children:r?(0,Q.jsx)(g,{className:`icon-sm`}):(0,Q.jsx)(b,{className:`icon-sm`})})})}),(0,Q.jsx)(M,{children:n(r?`common.collapse`:`common.expand`)})]}),(0,Q.jsx)(Y,{size:`icon`,className:`text-destructive hover:text-destructive size-6`,onClick:()=>f(!0),disabled:l,"data-testid":`runner-item-${e.runnerId}-delete`,tooltip:n(`common.delete`),children:(0,Q.jsx)(v,{className:`icon-sm`})})]})]}),(0,Q.jsx)(Ee,{open:d,onOpenChange:f,title:`Remove runner`,description:`Are you sure you want to remove "${e.name}"? This action cannot be undone.`,confirmLabel:n(`common.remove`,`Remove`),loading:l,onCancel:()=>f(!1),onConfirm:m}),(0,Q.jsx)(de,{className:`px-3 pb-3`,children:(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[a.length===0?(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`No projects assigned yet.`}):a.map(t=>(0,Q.jsxs)(`div`,{className:`hover:bg-muted/40 flex items-center justify-between rounded px-2 py-1 text-xs`,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:_.find(e=>e.id===t.projectId)?.name??t.projectId}),(0,Q.jsx)(Y,{size:`icon`,className:`text-destructive hover:text-destructive size-5`,onClick:()=>h(t.projectId),"data-testid":`runner-item-${e.runnerId}-unassign-${t.projectId}`,tooltip:n(`common.unassign`),children:(0,Q.jsx)(v,{className:`icon-xs`})})]},t.projectId)),(0,Q.jsxs)(`button`,{className:`text-primary mt-1 flex items-center gap-1 text-xs hover:underline`,onClick:()=>c(e=>!e),"data-testid":`runner-item-${e.runnerId}-add-project`,children:[(0,Q.jsx)(ee,{className:`icon-sm`}),`Assign a project`]}),s&&(0,Q.jsx)(vt,{runnerId:e.runnerId,onAssigned:()=>{c(!1),p()}})]})})]})}function bt({onLinked:e}){let[t,n]=(0,Z.useState)(``),[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),l=async()=>{let e=t.trim();if(!e)return;i(!0);let n=await I.getRunnerEnrollment(e);i(!1),n.isOk()?c(n.value):B.error(`Unknown or expired code`)};return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(J,{value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l()},placeholder:`Enter runner code, e.g. WXYZ-1234`,size:`xs`,className:`flex-1 font-mono uppercase`,"data-testid":`link-runner-code`}),(0,Q.jsx)(z,{size:`sm`,variant:`outline`,onClick:l,disabled:!t.trim()||r,className:`shrink-0`,"data-testid":`link-runner-submit`,children:r?`Checking…`:`Link a runner`}),(0,Q.jsx)(Ee,{open:!!s,onOpenChange:e=>!e&&c(null),title:`Approve this runner?`,description:s?`Link "${s.hostname}" (${s.os}, from ${s.ip||`unknown IP`}) to your account? Only approve runners you started.`:``,confirmLabel:`Approve`,loading:a,onCancel:()=>c(null),onConfirm:async()=>{if(!s)return;o(!0);let t=await I.approveRunnerEnrollment(s.userCode);o(!1),t.isOk()?(B.success(`Runner linked`),c(null),n(``),e()):B.error(`Failed to link runner`)}})]})}function xt(){let[e,t]=(0,Z.useState)([]),[n,r]=(0,Z.useState)(!0),i=async()=>{r(!0);let e=await I.getMyRunners();r(!1),e.isOk()&&t(e.value.runners)};return(0,Z.useEffect)(()=>{i();let e=setInterval(i,3e4);return()=>clearInterval(e)},[]),(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{className:`settings-card space-y-3 p-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:`Connect a new runner`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-0.5 text-sm`,children:`Start a runner on any machine, then approve the code it prints to link it to your account — no token or secret to copy.`})]}),(0,Q.jsx)(Ae,{}),(0,Q.jsxs)(`div`,{className:`border-border/50 border-t pt-3`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-2 text-xs`,children:`Already started a runner? Enter the code it printed to approve it:`}),(0,Q.jsx)(bt,{onLinked:i})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:`My Runners`}),(0,Q.jsxs)(z,{size:`sm`,variant:`ghost`,onClick:i,disabled:n,className:`h-6 text-xs`,"data-testid":`runners-refresh`,children:[(0,Q.jsx)(p,{className:R(`mr-1 icon-xs`,n&&`animate-spin`)}),`Refresh`]})]}),n&&e.length===0?(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Loading…`}):e.length===0?(0,Q.jsxs)(`div`,{className:`border-border/50 rounded-lg border border-dashed px-4 py-6 text-center`,children:[(0,Q.jsx)(f,{className:`text-muted-foreground/50 mx-auto mb-2 size-8`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`No runners connected yet.`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:`Copy the install command above and run it on any machine.`})]}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,Q.jsx)(yt,{runner:e,onDeleted:i},e.runnerId))})]})]})}var St={version:`0.1.4`,commit:`fbcacb63`,build:1436,dirty:!0,label:`0.1.4 (fbcacb63+)`},Ct=L(`system-settings`),wt=De({fg:`#abb2bf`,bg:`transparent`,newline:!0});function Tt(){let[e,t]=(0,Z.useState)(null),[n,r]=(0,Z.useState)(!0),{buildOutput:i,buildStatus:a,clearBuild:o}=ze(),s=(0,Z.useRef)(null),c=(0,Z.useCallback)(async()=>{r(!0);let e=await I.setupStatus();e.isOk()&&e.value.nativeGit&&t(e.value.nativeGit),r(!1)},[]);(0,Z.useEffect)(()=>{c()},[c]),(0,Z.useEffect)(()=>{s.current&&(s.current.scrollTop=s.current.scrollHeight)},[i]);let l=(0,Z.useCallback)(async()=>{o();let e=await I.buildNativeGit();e.isErr()&&(Ct.error(`Failed to start native git build`,{error:e.error.message}),B.error(`Failed to start build: `+e.error.message))},[o]);if(n&&!e)return(0,Q.jsx)(`div`,{className:`p-1`,children:(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Loading…`})});let u=e?.loaded&&!e?.disabled,d=a===`building`,f=a===`completed`,m=a===`failed`;return(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsx)(`div`,{children:(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:`System-level configuration and native module management.`})}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`p`,{className:`settings-row-title`,children:`Native Git (gitoxide)`}),e&&(0,Q.jsx)(V,{variant:`outline`,className:R(`h-5 px-2 text-[10px]`,u?`border-green-500/30 text-green-500`:e.disabled?`border-yellow-500/30 text-yellow-500`:`border-muted-foreground/30 text-muted-foreground`),"data-testid":`system-native-git-status`,children:u?`Active`:e.disabled?`Disabled`:`Inactive`})]}),(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:c,disabled:n,"data-testid":`system-native-git-refresh`,children:(0,Q.jsx)(p,{className:R(`icon-sm`,n&&`animate-spin`)})})]}),(0,Q.jsx)(`p`,{className:`settings-row-desc mt-1`,children:`Rust-based git implementation for 5-10x faster status, diff, log, and branch operations. When inactive, funny falls back to the standard git CLI (fully functional).`}),e&&(0,Q.jsxs)(`div`,{className:`text-muted-foreground mt-3 space-y-2 text-xs`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`w-16 font-medium`,children:`Platform`}),(0,Q.jsx)(`code`,{className:`bg-muted rounded px-1.5 py-0.5`,children:e.platform})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`w-16 font-medium`,children:`Rust`}),e.rustAvailable?(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-green-500`,children:[(0,Q.jsx)(w,{className:`size-3`}),e.rustVersion]}):(0,Q.jsxs)(`span`,{className:`text-muted-foreground flex items-center gap-1`,children:[(0,Q.jsx)(_,{className:`size-3`}),`Not installed`]})]})]}),e&&!u&&!d&&!f&&(0,Q.jsx)(`div`,{className:`mt-4`,children:e.disabled?(0,Q.jsxs)(`p`,{className:`text-xs text-yellow-500`,children:[`Native git is disabled via`,` `,(0,Q.jsx)(`code`,{className:`bg-muted rounded px-1 py-0.5`,children:`FUNNY_DISABLE_NATIVE_GIT=1`}),`. Remove this environment variable and restart funny to enable it.`]}):e.canBuild?(0,Q.jsxs)(z,{size:`sm`,onClick:l,disabled:d,"data-testid":`system-native-git-build`,children:[(0,Q.jsx)(E,{className:`icon-sm mr-1.5`}),`Build Native Module`]}):e.rustAvailable?(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`The native-git source package was not found. This is only available when running from a development checkout.`}):(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Install the Rust toolchain to build the native module:`}),(0,Q.jsx)(`code`,{className:`bg-muted block rounded px-3 py-2 text-xs`,children:`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`After installing Rust, click refresh to detect it.`})]})}),d&&(0,Q.jsx)(`div`,{className:`mt-4 space-y-2`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(C,{className:`size-3 animate-pulse fill-yellow-500 text-yellow-500`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:`Building…`})]})}),f&&(0,Q.jsxs)(`div`,{className:`mt-4 space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-green-500`,children:[(0,Q.jsx)(w,{className:`size-3.5`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:`Build successful!`})]}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Restart funny to activate native git.`})]}),m&&(0,Q.jsxs)(`div`,{className:`mt-4 space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`text-destructive flex items-center gap-2`,children:[(0,Q.jsx)(_,{className:`size-3.5`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:`Build failed`})]}),(0,Q.jsx)(z,{size:`sm`,variant:`outline`,onClick:l,"data-testid":`system-native-git-retry`,children:`Retry Build`})]}),i&&(0,Q.jsx)(`div`,{className:`mt-3`,children:(0,Q.jsx)(Se,{className:`border-border h-64 rounded border bg-[#1e1e2e]`,children:(0,Q.jsx)(`div`,{ref:s,className:`h-full overflow-y-auto p-3 font-mono text-xs leading-relaxed`,"data-testid":`system-native-git-build-output`,dangerouslySetInnerHTML:{__html:wt.toHtml(i)}})})})]})}),(0,Q.jsx)(Et,{})]})}function Et(){let[e,t]=(0,Z.useState)(!1);return(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`p`,{className:`settings-row-title`,children:`Build`}),(0,Q.jsx)(V,{variant:`outline`,className:`h-5 px-2 font-mono text-[10px]`,"data-testid":`system-build-number`,children:St.commit}),St.dirty&&(0,Q.jsx)(V,{variant:`outline`,className:`h-5 border-yellow-500/30 px-2 text-[10px] text-yellow-500`,children:`dirty`})]}),(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>{navigator.clipboard.writeText(St.label).then(()=>{t(!0),window.setTimeout(()=>t(!1),1500)})},"data-testid":`system-build-copy`,children:e?(0,Q.jsx)(w,{className:`icon-sm text-green-500`}):(0,Q.jsx)(c,{className:`icon-sm`})})]}),(0,Q.jsx)(`p`,{className:`settings-row-desc mt-1`,children:`The commit this build was made from. Compare it between two installs — including the deployed server — to tell whether they are running the exact same code.`}),(0,Q.jsx)(`code`,{className:`bg-muted mt-3 block rounded px-3 py-2 text-xs`,"data-testid":`system-build-label`,children:St.label})]})})}var Dt=[{value:`owner`,label:`Owner`},{value:`admin`,label:`Admin`},{value:`member`,label:`Member`},{value:`viewer`,label:`Viewer`}],Ot={owner:`bg-amber-500/15 text-amber-700 dark:text-amber-400`,admin:`bg-blue-500/15 text-blue-700 dark:text-blue-400`,member:`bg-green-500/15 text-green-700 dark:text-green-400`,viewer:`bg-gray-500/15 text-gray-700 dark:text-gray-400`},kt=[{value:`admin`,label:`Admin`},{value:`member`,label:`Member`}];function At(){let{t:e}=A(),[t,n]=(0,Z.useState)([]),[r,i]=(0,Z.useState)(!0),[o,s]=(0,Z.useState)(null),l=oe(e=>e.user),[d,f]=(0,Z.useState)([]),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(`member`),[_,b]=(0,Z.useState)(!1),[x,C]=(0,Z.useState)(null),[w,T]=(0,Z.useState)([]),[E,ee]=(0,Z.useState)(`member`),[D,k]=(0,Z.useState)(!1),[ne,j]=(0,Z.useState)(null),M=(0,Z.useCallback)(async()=>{try{let e=await P.organization.listMembers();e.data&&n(e.data)}catch(e){console.error(`[TeamMembers] Failed to load members:`,e)}finally{i(!1)}},[]),N=(0,Z.useCallback)(async()=>{try{let e=await P.organization.listInvitations();e.data&&f(e.data.filter(e=>e.status===`pending`))}catch(e){console.error(`[TeamMembers] Failed to load invitations:`,e)}},[]),F=(0,Z.useCallback)(async()=>{let e=await I.listInviteLinks();e.isOk()&&T(e.value)},[]),re=(0,Z.useCallback)(async()=>{let e=await I.getSmtpSettings();e.isOk()?C(e.value.configured):C(!1)},[]);(0,Z.useEffect)(()=>{M(),N(),F(),re()},[M,N,F,re]);let ie=(0,Z.useCallback)(async(e,t)=>{try{await P.organization.updateMemberRole({memberId:e,role:t}),n(n=>n.map(n=>n.id===e?{...n,role:t}:n)),B.success(`Role updated`)}catch(e){B.error(e.message||`Failed to update role`)}},[]),ae=(0,Z.useCallback)(async()=>{if(o){try{await P.organization.removeMember({memberIdOrEmail:o.userId}),n(e=>e.filter(e=>e.id!==o.id)),B.success(`Member removed`)}catch(e){B.error(e.message||`Failed to remove member`)}s(null)}},[o]),L=(0,Z.useCallback)(async()=>{if(p.trim()){b(!0);try{await P.organization.inviteMember({email:p.trim(),role:h}),B.success(`Invitation sent to ${p.trim()}`),m(``),await N()}catch(e){B.error(e.message||`Failed to send invitation`)}finally{b(!1)}}},[p,h,N]),R=(0,Z.useCallback)(async()=>{k(!0);try{let e=await I.createInviteLink({role:E,expiresInDays:7});e.isOk()?(T(t=>[e.value,...t]),B.success(`Invite link created`)):B.error(`Failed to create invite link`)}catch{B.error(`Failed to create invite link`)}finally{k(!1)}},[E]),se=(0,Z.useCallback)(async e=>{(await I.revokeInviteLink(e)).isOk()?(T(t=>t.filter(t=>t.id!==e)),B.success(`Invite link revoked`)):B.error(`Failed to revoke invite link`)},[]),ce=(0,Z.useCallback)(e=>{let t=`${window.location.origin}/invite/${e.token}`;navigator.clipboard.writeText(t),j(e.id),B.success(`Link copied to clipboard`),setTimeout(()=>j(null),2e3)},[]),le=(0,Z.useCallback)(async e=>{try{await P.organization.cancelInvitation({invitationId:e}),f(t=>t.filter(t=>t.id!==e)),B.success(`Invitation cancelled`)}catch(e){B.error(e.message||`Failed to cancel invitation`)}},[]),ue=t.filter(e=>e.role===`owner`).length;return r?(0,Q.jsx)(`div`,{className:`text-muted-foreground flex items-center justify-center py-12 text-sm`,children:`Loading members…`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`h3`,{className:`settings-section-header`,children:`Invite Member`}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[x===!1&&(0,Q.jsxs)(`div`,{className:`mb-3 flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-400`,"data-testid":`team-invite-smtp-warning`,children:[(0,Q.jsx)(u,{className:`icon-sm mt-0.5 shrink-0`}),(0,Q.jsxs)(`span`,{children:[`Email is not configured. Configure SMTP in `,(0,Q.jsx)(`strong`,{children:`Settings > Email`}),` to send invitations, or use an invite link below.`]})]}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-3 text-sm`,children:`Send an invitation to join this organization.`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(J,{type:`email`,value:p,onChange:e=>m(e.target.value),placeholder:`user@example.com`,className:`flex-1 text-sm`,disabled:x===!1,onKeyDown:e=>{e.key===`Enter`&&x&&L()},"data-testid":`team-invite-email`}),(0,Q.jsxs)(K,{value:h,onValueChange:e=>g(e),disabled:x===!1,children:[(0,Q.jsx)(W,{className:`w-[100px]`,"data-testid":`team-invite-role`,children:(0,Q.jsx)(U,{})}),(0,Q.jsx)(H,{children:kt.map(e=>(0,Q.jsx)(q,{value:e.value,children:e.label},e.value))})]}),(0,Q.jsxs)(z,{size:`sm`,onClick:L,disabled:!p.trim()||_||x===!1,"data-testid":`team-invite-send`,children:[(0,Q.jsx)(te,{className:`icon-sm mr-1.5`}),`Invite`]})]})]})}),(0,Q.jsx)(`h3`,{className:`settings-section-header`,children:`Invite Link`}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-3 text-sm`,children:`Generate a shareable link to invite people to this organization.`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(K,{value:E,onValueChange:e=>ee(e),children:[(0,Q.jsx)(W,{className:`w-[100px]`,"data-testid":`team-link-role`,children:(0,Q.jsx)(U,{})}),(0,Q.jsx)(H,{children:kt.map(e=>(0,Q.jsx)(q,{value:e.value,children:e.label},e.value))})]}),(0,Q.jsxs)(z,{size:`sm`,onClick:R,disabled:D,"data-testid":`team-link-create`,children:[(0,Q.jsx)(a,{className:`icon-sm mr-1.5`}),`Generate Link`]})]}),w.length>0&&(0,Q.jsx)(`div`,{className:`mt-3 space-y-2`,children:w.map(t=>{let n=t.expiresAt&&new Date(t.expiresAt)<new Date,r=t.maxUses!==null&&t.useCount>=t.maxUses,i=!n&&!r;return(0,Q.jsxs)(`div`,{className:`border-border/50 flex items-center gap-2 rounded-md border px-3 py-2`,"data-testid":`team-link-${t.id}`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`code`,{className:`text-muted-foreground truncate text-xs`,children:[window.location.origin,`/invite/`,t.token]}),(0,Q.jsx)(V,{variant:`secondary`,className:i?`bg-green-500/15 text-green-700 dark:text-green-400`:`bg-red-500/15 text-red-700 dark:text-red-400`,children:n?`expired`:r?`maxed`:t.role})]}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground mt-0.5 text-xs`,children:[t.useCount,` use`,t.useCount===1?``:`s`,t.expiresAt&&` · expires ${new Date(t.expiresAt).toLocaleDateString()}`]})]}),(0,Q.jsx)(Y,{size:`icon`,className:`size-7 shrink-0`,onClick:()=>ce(t),disabled:!i,"data-testid":`team-link-copy-${t.id}`,tooltip:e(`common.copyLink`),children:ne===t.id?(0,Q.jsx)(O,{className:`icon-sm text-green-500`}):(0,Q.jsx)(c,{className:`icon-sm`})}),(0,Q.jsx)(Y,{size:`icon`,className:`text-muted-foreground hover:text-destructive size-7 shrink-0`,onClick:()=>se(t.id),"data-testid":`team-link-revoke-${t.id}`,tooltip:e(`common.revoke`),children:(0,Q.jsx)(v,{className:`icon-sm`})})]},t.id)})})]})}),(0,Q.jsxs)(`h3`,{className:`settings-section-header`,children:[`Members (`,t.length,`)`]}),(0,Q.jsx)(`div`,{className:`settings-card`,children:t.map(e=>{let t=e.userId===l?.id,n=e.role===`owner`&&ue<=1;return(0,Q.jsxs)(`div`,{className:`settings-row`,"data-testid":`team-member-${e.userId}`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`p`,{className:`text-foreground truncate text-sm font-medium`,children:[e.user.name,t&&(0,Q.jsx)(`span`,{className:`text-muted-foreground ml-1 text-xs`,children:`(you)`})]}),(0,Q.jsx)(V,{variant:`secondary`,className:Ot[e.role],"data-testid":`team-member-role-badge-${e.userId}`,children:e.role})]}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:e.user.email})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(K,{value:e.role,onValueChange:t=>ie(e.id,t),disabled:n&&e.role===`owner`,children:[(0,Q.jsx)(W,{className:`h-8 w-[100px]`,"data-testid":`team-member-role-select-${e.userId}`,children:(0,Q.jsx)(U,{})}),(0,Q.jsx)(H,{children:Dt.map(e=>(0,Q.jsx)(q,{value:e.value,children:e.label},e.value))})]}),(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`text-muted-foreground hover:text-destructive size-8`,onClick:()=>s(e),disabled:n,"data-testid":`team-member-remove-${e.userId}`,children:(0,Q.jsx)(y,{className:`icon-base`})})]})]},e.id)})}),d.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`h3`,{className:`settings-section-header`,children:[`Pending Invitations (`,d.length,`)`]}),(0,Q.jsx)(`div`,{className:`settings-card`,children:d.map(e=>(0,Q.jsxs)(`div`,{className:`settings-row`,"data-testid":`team-invitation-${e.id}`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-foreground truncate text-sm`,children:e.email}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground text-xs`,children:[`Expires `,new Date(e.expiresAt).toLocaleDateString()]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(V,{variant:`secondary`,children:e.role}),(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`text-muted-foreground hover:text-destructive size-7`,onClick:()=>le(e.id),"data-testid":`team-invitation-cancel-${e.id}`,children:(0,Q.jsx)(S,{className:`icon-sm`})})]})]},e.id))})]}),(0,Q.jsx)(Ee,{open:!!o,onOpenChange:e=>{e||s(null)},title:`Remove Member`,description:`Remove ${o?.user.name} from this organization? They will lose access to all team projects.`,cancelLabel:`Cancel`,confirmLabel:`Remove`,onCancel:()=>s(null),onConfirm:ae})]})}function jt(){let{t:e}=A(),t=oe(e=>e.user),[n,r]=(0,Z.useState)([]),[i,a]=(0,Z.useState)(!0),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(`user`),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(``),b=(0,Z.useCallback)(async()=>{try{a(!0);let e=await P.admin.listUsers({query:{limit:100}});e.data?.users&&r(e.data.users.map(e=>({id:e.id,name:e.name||``,username:e.username||``,email:e.email||``,role:e.role||`user`,createdAt:e.createdAt||``})))}catch(e){console.error(`[UserManagement] Failed to list users:`,e)}finally{a(!1)}},[]);(0,Z.useEffect)(()=>{b()},[b]);let x=async()=>{if(!(!c.trim()||!f.trim())){y(``),_(!0);try{await P.admin.createUser({email:`${c.trim()}@local.host`,password:f,name:u.trim()||c.trim(),role:m,data:{username:c.trim()}}),s(!1),l(``),d(``),p(``),h(`user`),await b()}catch(t){y(t.message||e(`users.createFailed`))}finally{_(!1)}}},S=async e=>{if(e!==t?.id)try{await P.admin.removeUser({userId:e}),await b()}catch(e){console.error(`[UserManagement] Failed to remove user:`,e)}};return i?(0,Q.jsx)(`p`,{className:`text-muted-foreground p-4 text-sm`,children:e(`common.loading`)}):(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(`div`,{className:`flex items-center justify-end px-4 pt-2`,children:(0,Q.jsx)(z,{size:`sm`,variant:`outline`,onClick:()=>s(!o),children:e(o?`common.cancel`:`users.addUser`)})}),o&&(0,Q.jsxs)(`div`,{className:`border-border mx-4 space-y-3 rounded-md border p-3`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-xs font-medium`,children:e(`users.username`)}),(0,Q.jsx)(J,{value:c,onChange:e=>l(e.target.value),placeholder:e(`users.usernamePlaceholder`),autoFocus:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-xs font-medium`,children:e(`users.displayName`)}),(0,Q.jsx)(J,{value:u,onChange:e=>d(e.target.value),placeholder:e(`users.displayNamePlaceholder`)})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-xs font-medium`,children:e(`users.password`)}),(0,Q.jsx)(J,{type:`password`,value:f,onChange:e=>p(e.target.value),placeholder:e(`users.passwordPlaceholder`)})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-xs font-medium`,children:e(`users.role`)}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(z,{size:`sm`,variant:m===`user`?`default`:`outline`,onClick:()=>h(`user`),children:e(`users.roleUser`)}),(0,Q.jsx)(z,{size:`sm`,variant:m===`admin`?`default`:`outline`,onClick:()=>h(`admin`),children:e(`users.roleAdmin`)})]})]}),v&&(0,Q.jsx)(`p`,{className:`text-destructive text-xs`,children:v}),(0,Q.jsx)(z,{size:`sm`,onClick:x,disabled:g||!c.trim()||!f.trim(),children:e(g?`users.creating`:`users.create`)})]}),(0,Q.jsx)(`div`,{className:`space-y-1 px-4`,children:n.map(n=>(0,Q.jsxs)(`div`,{className:`hover:bg-accent/50 flex items-center justify-between rounded-md px-3 py-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`p`,{className:`text-foreground truncate text-sm font-medium`,children:[n.name||n.username,n.role===`admin`&&(0,Q.jsx)(`span`,{className:`text-primary ml-2 text-xs font-normal`,children:e(`users.roleAdmin`)})]}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground text-xs`,children:[`@`,n.username]})]}),n.id!==t?.id&&(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,className:`text-destructive hover:text-destructive text-xs`,onClick:()=>S(n.id),children:e(`common.delete`)})]},n.id))})]})}var Mt=[{value:`one-dark`,label:`settings.themes.oneDark`,colors:{bg:`#252931`,sidebar:`#1e2127`,accent:`#528bff`,fg:`#b8beca`}},{value:`dracula`,label:`settings.themes.dracula`,colors:{bg:`#282A36`,sidebar:`#21222C`,accent:`#BD93F9`,fg:`#F8F8F2`}},{value:`github-dark`,label:`settings.themes.githubDark`,colors:{bg:`#0d1117`,sidebar:`#010409`,accent:`#2f81f7`,fg:`#e6edf3`}},{value:`night-owl`,label:`settings.themes.nightOwl`,colors:{bg:`#011627`,sidebar:`#01111d`,accent:`#7e57c2`,fg:`#d6deeb`}},{value:`catppuccin`,label:`settings.themes.catppuccin`,colors:{bg:`#1e1e2e`,sidebar:`#181825`,accent:`#89b4fa`,fg:`#cdd6f4`}},{value:`sunrise`,label:`settings.themes.sunrise`,colors:{bg:`#FAFAFA`,sidebar:`#F5F5F5`,accent:`#171717`,fg:`#171717`}},{value:`monochrome`,label:`settings.themes.monochrome`,colors:{bg:`#ffffff`,sidebar:`#f7f7f7`,accent:`#000000`,fg:`#000000`}},{value:`monochrome-dark`,label:`settings.themes.monochromeDark`,colors:{bg:`#121212`,sidebar:`#0d0d0d`,accent:`#ededed`,fg:`#ededed`}}],Nt=new Map;function Pt(e){let t=Nt.get(e);return t||(t=new Intl.DisplayNames([e],{type:`language`}),Nt.set(e,t)),t}function Ft(e){try{let t=Pt(e).of(e);return t?t.charAt(0).toUpperCase()+t.slice(1):e}catch{return e}}function It({option:e,selected:t,onClick:n,t:r}){let{bg:i,sidebar:a,accent:o,fg:s}=e.colors;return(0,Q.jsxs)(`button`,{onClick:n,"data-testid":`preferences-theme-${e.value}`,className:R(`relative flex flex-col overflow-hidden rounded-lg border-2 transition-colors`,t?`border-primary`:`border-border/50 hover:border-border`),children:[(0,Q.jsxs)(`div`,{className:`flex h-16`,style:{backgroundColor:i},children:[(0,Q.jsx)(`div`,{className:`w-5 border-r`,style:{backgroundColor:a,borderColor:`${s}15`}}),(0,Q.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 p-2`,children:[(0,Q.jsx)(`div`,{className:`h-1.5 w-10 rounded-full`,style:{backgroundColor:s,opacity:.7}}),(0,Q.jsx)(`div`,{className:`h-1.5 w-14 rounded-full`,style:{backgroundColor:s,opacity:.3}}),(0,Q.jsx)(`div`,{className:`h-1.5 w-8 rounded-full`,style:{backgroundColor:o}})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-2.5 py-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:r(e.label)}),t&&(0,Q.jsx)(O,{className:`icon-xs text-primary`})]})]})}function Lt({activePreferencesPage:e}){let{defaultEditor:t,useInternalEditor:n,terminalShell:r,availableShells:i,fontSize:a,notificationsEnabled:o,notificationSoundEnabled:s,setDefaultEditor:c,setUseInternalEditor:l,setTerminalShell:u,setFontSize:d,setNotificationsEnabled:f,setNotificationSoundEnabled:p,fetchAvailableShells:m}=ae(_e(e=>({defaultEditor:e.defaultEditor,useInternalEditor:e.useInternalEditor,terminalShell:e.terminalShell,availableShells:e.availableShells,fontSize:e.fontSize,notificationsEnabled:e.notificationsEnabled,notificationSoundEnabled:e.notificationSoundEnabled,setDefaultEditor:e.setDefaultEditor,setUseInternalEditor:e.setUseInternalEditor,setTerminalShell:e.setTerminalShell,setFontSize:e.setFontSize,setNotificationsEnabled:e.setNotificationsEnabled,setNotificationSoundEnabled:e.setNotificationSoundEnabled,fetchAvailableShells:e.fetchAvailableShells}))),{permission:h,requestPermission:g,supported:_}=he(),{theme:v,setTheme:y}=ue(),{t:b,i18n:x}=A(),S=oe(e=>e.user?.role===`admin`),[C,w]=(0,Z.useState)({}),[T,E]=(0,Z.useState)({}),[ee,D]=(0,Z.useState)({}),[O,te]=(0,Z.useState)(``),[k,ne]=(0,Z.useState)(`587`),[j,M]=(0,Z.useState)(``),[N,P]=(0,Z.useState)(``),[F,re]=(0,Z.useState)(``),[L,R]=(0,Z.useState)(!1),[se,ce]=(0,Z.useState)(`none`),[de,fe]=(0,Z.useState)(!1),[ge,ve]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{I.getProfile().then(e=>{if(e.isOk()&&e.value){let t=e.value;E(t.providerKeys??{})}}),w({}),I.getSmtpSettings().then(e=>{e.isOk()&&(te(e.value.host),ne(e.value.port),M(e.value.user),re(e.value.from),R(e.value.hasPassword),ce(e.value.source))}),m()},[m]);let V=(0,Z.useCallback)(e=>{c(e),B.success(b(`settings.saved`),{id:`settings-saved`})},[c,b]),ye=(0,Z.useCallback)(e=>{l(e),B.success(b(`settings.saved`),{id:`settings-saved`})},[l,b]),be=(0,Z.useCallback)(e=>{u(e),B.success(b(`settings.saved`),{id:`settings-saved`})},[u,b]),xe=(0,Z.useCallback)(e=>{y(e),I.updateProfile({theme:e}),B.success(b(`settings.saved`),{id:`settings-saved`})},[y,b]),Ce=(0,Z.useCallback)(e=>{d(e),B.success(b(`settings.saved`),{id:`settings-saved`})},[d,b]),we=(0,Z.useCallback)(async e=>{if(e&&(h===`granted`?`granted`:await g())!==`granted`){B.error(b(`settings.notificationsDenied`)),f(!1);return}f(e),B.success(b(`settings.saved`),{id:`settings-saved`})},[h,g,f,b]),Te=(0,Z.useCallback)(async()=>{if(!_){B.error(b(`settings.notificationsUnsupported`));return}let e=h;if(e!==`granted`&&(e=await g()),e!==`granted`){B.error(b(`settings.notificationsDenied`));return}let t=me(b(`settings.notificationsTestTitle`),b(`settings.notificationsTestBody`),{force:!0});t.ok?B.success(b(`settings.notificationsTestSent`)):B.error(b(`settings.notificationsTestFailed`,{reason:t.reason}))},[h,_,g,b]),Ee=(0,Z.useCallback)(e=>{p(e),e&&pe(),B.success(b(`settings.saved`),{id:`settings-saved`})},[p,b]),De=(0,Z.useCallback)(()=>{pe()},[]),Oe=(0,Z.useCallback)(e=>{x.changeLanguage(e),B.success(b(`settings.saved`),{id:`settings-saved`})},[x,b]),ke=(0,Z.useCallback)(async e=>{let t=C[e];if(!t)return;D(t=>({...t,[e]:!0}));let n=await I.updateProfile({providerKey:{id:e,value:t}});n.isOk()?(E(n.value.providerKeys??{}),w(t=>({...t,[e]:``})),B.success(b(`profile.tokenSaved`))):B.error(b(`profile.saveFailed`)),D(t=>({...t,[e]:!1}))},[C,b]),J=(0,Z.useCallback)(async e=>{D(t=>({...t,[e]:!0}));let t=await I.updateProfile({providerKey:{id:e,value:null}});t.isOk()&&(E(t.value.providerKeys??{}),w(t=>({...t,[e]:``})),B.success(b(`profile.tokenCleared`))),D(t=>({...t,[e]:!1}))},[b]),Ae=(0,Z.useCallback)(async()=>{fe(!0),(await I.updateSmtpSettings({host:O,port:k,user:j,pass:N||void 0,from:F})).isOk()?(B.success(`SMTP settings saved`),N&&R(!0),ce(`database`),P(``)):B.error(`Failed to save SMTP settings`),fe(!1)},[O,k,j,N,F]),je=(0,Z.useCallback)(async()=>{ve(!0);let e=await I.testSmtpSettings();e.isOk()?B.success(`Test email sent to ${e.value.sentTo}`):B.error(`Failed to send test email. Check your SMTP settings.`),ve(!1)},[]);return!S&&Re.has(e)?(0,Q.jsx)(Se,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(`div`,{className:`max-w-4xl px-8 py-8`,children:(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,"data-testid":`preferences-admin-only`,children:`This setting is only available to administrators.`})})}):(0,Q.jsx)(Se,{className:`min-h-0 flex-1`,children:(0,Q.jsxs)(`div`,{className:`max-w-4xl px-8 py-8`,children:[e===`general`&&(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{className:`settings-card`,children:[(0,Q.jsx)(X,{title:b(`settings.defaultEditor`),description:b(`settings.defaultEditorDesc`),children:(0,Q.jsxs)(K,{value:t,onValueChange:V,children:[(0,Q.jsx)(W,{className:`w-[140px]`,"data-testid":`preferences-editor-select`,children:(0,Q.jsx)(U,{})}),(0,Q.jsx)(H,{children:Object.entries(ie).map(([e,t])=>(0,Q.jsx)(q,{value:e,children:t},e))})]})}),(0,Q.jsx)(X,{title:b(`settings.useInternalEditor`),description:b(`settings.useInternalEditorDesc`),children:(0,Q.jsx)(G,{checked:n,onCheckedChange:e=>ye(!!e),"data-testid":`preferences-internal-editor`})}),(0,Q.jsx)(X,{title:b(`settings.language`),description:b(`settings.languageDesc`),children:(0,Q.jsxs)(K,{value:x.language,onValueChange:Oe,children:[(0,Q.jsx)(W,{className:`w-[140px]`,"data-testid":`preferences-language-select`,children:(0,Q.jsx)(U,{})}),(0,Q.jsx)(H,{children:Object.keys(x.options.resources??{}).map(e=>(0,Q.jsx)(q,{value:e,children:Ft(e)},e))})]})}),(0,Q.jsx)(X,{title:b(`settings.terminalShell`),description:b(`settings.terminalShellDesc`),children:(0,Q.jsxs)(K,{value:r,onValueChange:be,children:[(0,Q.jsx)(W,{className:`w-[160px]`,"data-testid":`preferences-shell-select`,children:(0,Q.jsx)(U,{})}),(0,Q.jsxs)(H,{children:[(0,Q.jsx)(q,{value:`default`,children:b(`settings.shellDefault`)}),i.map(e=>(0,Q.jsx)(q,{value:e.id,children:e.label},e.id))]})]})}),(0,Q.jsx)(X,{title:b(`settings.notifications`),description:b(_?h===`denied`?`settings.notificationsBlocked`:`settings.notificationsDesc`:`settings.notificationsUnsupported`),children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(z,{size:`sm`,variant:`outline`,onClick:Te,disabled:!_||h===`denied`,"data-testid":`preferences-notifications-test`,children:b(`settings.notificationsTest`)}),(0,Q.jsx)(G,{checked:o&&h===`granted`,disabled:!_||h===`denied`,onCheckedChange:e=>we(!!e),"data-testid":`preferences-notifications-toggle`})]})}),(0,Q.jsx)(X,{title:b(`settings.notificationsSound`),description:b(`settings.notificationsSoundDesc`),children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(z,{size:`sm`,variant:`outline`,onClick:De,"data-testid":`preferences-notifications-sound-test`,children:b(`settings.notificationsTest`)}),(0,Q.jsx)(G,{checked:s,onCheckedChange:e=>Ee(!!e),"data-testid":`preferences-notifications-sound-toggle`})]})})]})}),e===`models`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:b(`settings.promptModelVisibilityDesc`)}),(0,Q.jsx)(`div`,{className:`settings-card overflow-visible!`,children:(0,Q.jsx)(Ve,{showHeader:!1})})]}),e===`appearance`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:b(`settings.themeDesc`)}),(0,Q.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:Mt.map(e=>(0,Q.jsx)(It,{option:e,selected:(v??`one-dark`)===e.value,onClick:()=>xe(e.value),t:b},e.value))}),(0,Q.jsx)(`h3`,{className:`settings-section-header mt-6`,children:b(`settings.fontSize`)}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsx)(X,{title:b(`settings.fontSize`),description:b(`settings.fontSizeDesc`),children:(0,Q.jsxs)(K,{value:a,onValueChange:Ce,children:[(0,Q.jsx)(W,{className:`w-[140px]`,"data-testid":`preferences-font-size-select`,children:(0,Q.jsx)(U,{})}),(0,Q.jsxs)(H,{children:[(0,Q.jsx)(q,{value:`small`,children:b(`settings.fontSizeSmall`)}),(0,Q.jsx)(q,{value:`default`,children:b(`settings.fontSizeDefault`)}),(0,Q.jsx)(q,{value:`large`,children:b(`settings.fontSizeLarge`)})]})]})})})]}),e===`github`&&(0,Q.jsx)(zt,{id:`github`,label:`GitHub token`,title:b(`profile.githubTokenLabel`),description:b(`profile.githubTokenDesc`),keyInputs:C,keyPresence:T,keySaving:ee,setKeyInputs:w,handleSave:ke,handleClear:J,saveTestId:`preferences-save-token`,inputTestId:`preferences-github-token`,clearTestId:`preferences-clear-token`,t:b}),e===`ai-keys`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:`Configure API keys for AI providers. Keys are encrypted at rest.`}),(0,Q.jsx)(`div`,{className:`settings-card divide-border space-y-0 divide-y`,children:le.filter(e=>e.id!==`github`&&e.id!==`assemblyai`).map(e=>(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsx)(`p`,{className:`settings-row-title`,children:e.label}),(0,Q.jsxs)(`p`,{className:`settings-row-desc mb-2`,children:[`Get your key at`,` `,(0,Q.jsx)(`a`,{href:e.helpUrl,target:`_blank`,rel:`noreferrer`,className:`text-primary hover:underline`,children:new URL(e.helpUrl).hostname}),`. `,e.description]}),(0,Q.jsx)(Rt,{id:e.id,label:e.label,keyInputs:C,keyPresence:T,keySaving:ee,setKeyInputs:w,handleSave:ke,handleClear:J,t:b})]},e.id))})]}),e===`speech`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:`Configure an AssemblyAI API key to enable voice dictation in the prompt input.`}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsx)(`p`,{className:`settings-row-title`,children:`AssemblyAI API Key`}),(0,Q.jsxs)(`p`,{className:`settings-row-desc mb-2`,children:[`Get your key at`,` `,(0,Q.jsx)(`a`,{href:`https://www.assemblyai.com/dashboard/signup`,target:`_blank`,rel:`noreferrer`,className:`text-primary hover:underline`,children:`assemblyai.com`}),`. The key is encrypted at rest.`]}),(0,Q.jsx)(Rt,{id:`assemblyai`,label:`AssemblyAI API Key`,keyInputs:C,keyPresence:T,keySaving:ee,setKeyInputs:w,handleSave:ke,handleClear:J,t:b})]})})]}),e===`users`&&(0,Q.jsx)(jt,{}),e===`organizations`&&(0,Q.jsx)(lt,{}),e===`team-members`&&(0,Q.jsx)(At,{}),e===`runners`&&(0,Q.jsx)(xt,{}),e===`agent-templates`&&(0,Q.jsx)(Je,{}),e===`extensions`&&(0,Q.jsx)(st,{}),e===`providers`&&(0,Q.jsx)(pt,{}),e===`system`&&(0,Q.jsx)(Tt,{}),e===`email`&&(0,Q.jsx)(Bt,{smtpHost:O,smtpPort:k,smtpUser:j,smtpPass:N,smtpFrom:F,smtpHasPassword:L,smtpSource:se,smtpSaving:de,smtpTesting:ge,setSmtpHost:te,setSmtpPort:ne,setSmtpUser:M,setSmtpPass:P,setSmtpFrom:re,handleSaveSmtp:Ae,handleTestSmtp:je})]})})}function Rt({id:e,label:t,keyInputs:n,keyPresence:r,keySaving:i,setKeyInputs:a,handleSave:o,handleClear:s,t:c}){return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(J,{type:`password`,value:n[e]??``,onChange:t=>a(n=>({...n,[e]:t.target.value})),"data-testid":`preferences-${e}-key`,placeholder:r[e]?c(`profile.tokenSaved`):`Enter your ${t}`,className:`text-sm`}),(0,Q.jsx)(z,{size:`sm`,onClick:()=>o(e),disabled:!n[e]||!!i[e],"data-testid":`preferences-save-${e}-key`,children:i[e]?c(`common.saving`):c(`common.save`)}),r[e]&&(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,className:`text-destructive hover:text-destructive shrink-0 text-xs`,onClick:()=>s(e),disabled:!!i[e],"data-testid":`preferences-clear-${e}-key`,children:c(`profile.clearToken`)})]})}function zt({id:e,title:t,description:n,keyInputs:r,keyPresence:i,keySaving:a,setKeyInputs:o,handleSave:s,handleClear:c,saveTestId:l,inputTestId:u,clearTestId:d,t:f}){return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsx)(`p`,{className:`settings-row-title`,children:t}),(0,Q.jsx)(`p`,{className:`settings-row-desc mb-2`,children:n}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(J,{type:`password`,value:r[e]??``,onChange:t=>o(n=>({...n,[e]:t.target.value})),"data-testid":u,placeholder:i[e]?f(`profile.tokenSaved`):f(`profile.tokenPlaceholder`),className:`text-sm`}),(0,Q.jsx)(z,{size:`sm`,onClick:()=>s(e),disabled:!r[e]||!!a[e],"data-testid":l,children:a[e]?f(`common.saving`):f(`common.save`)}),i[e]&&(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,className:`text-destructive hover:text-destructive shrink-0 text-xs`,onClick:()=>c(e),disabled:!!a[e],"data-testid":d,children:f(`profile.clearToken`)})]})]})})})}function Bt({smtpHost:e,smtpPort:t,smtpUser:n,smtpPass:r,smtpFrom:i,smtpHasPassword:a,smtpSource:o,smtpSaving:s,smtpTesting:c,setSmtpHost:u,setSmtpPort:d,setSmtpUser:f,setSmtpPass:p,setSmtpFrom:m,handleSaveSmtp:h,handleTestSmtp:g}){return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:o!==`none`&&(0,Q.jsx)(`span`,{className:R(`rounded-full px-2 py-0.5 text-[10px] font-medium`,o===`database`?`bg-primary/10 text-primary`:`bg-muted text-muted-foreground`),"data-testid":`preferences-smtp-status`,children:o===`database`?`Configured`:`Env vars`})}),(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:`Used for sending team invitation emails. Set via env vars (SMTP_HOST, SMTP_USER, SMTP_PASS) or configure below.`}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`space-y-3 px-4 py-3.5`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-[1fr_80px] gap-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Host`}),(0,Q.jsx)(J,{value:e,onChange:e=>u(e.target.value),placeholder:`smtp.gmail.com`,className:`text-sm`,"data-testid":`preferences-smtp-host`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Port`}),(0,Q.jsx)(J,{value:t,onChange:e=>d(e.target.value),placeholder:`587`,className:`text-sm`,"data-testid":`preferences-smtp-port`})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Username`}),(0,Q.jsx)(J,{value:n,onChange:e=>f(e.target.value),placeholder:`you@example.com`,className:`text-sm`,"data-testid":`preferences-smtp-user`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Password`}),(0,Q.jsx)(J,{type:`password`,value:r,onChange:e=>p(e.target.value),placeholder:a?`Password saved (enter new to replace)`:`App password or SMTP password`,className:`text-sm`,"data-testid":`preferences-smtp-pass`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`From address`}),(0,Q.jsx)(J,{value:i,onChange:e=>m(e.target.value),placeholder:`noreply@example.com`,className:`text-sm`,"data-testid":`preferences-smtp-from`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Q.jsxs)(z,{size:`sm`,onClick:h,disabled:!e||!n||s,"data-testid":`preferences-smtp-save`,children:[(0,Q.jsx)(l,{className:`icon-sm mr-1.5`}),s?`Saving...`:`Save SMTP`]}),(0,Q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:g,disabled:o===`none`||c,"data-testid":`preferences-smtp-test`,children:[(0,Q.jsx)(te,{className:`icon-sm mr-1.5`}),c?`Sending...`:`Send Test Email`]})]})]})})]})}function Vt(){let{t:e}=A(),t=Oe(e=>e.activePreferencesPage);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col`,children:[(0,Q.jsx)(`div`,{className:`border-border border-b px-4 py-2`,children:(0,Q.jsx)(`div`,{className:`flex min-h-8 items-center`,children:(0,Q.jsx)(ye,{children:(0,Q.jsx)(be,{children:(0,Q.jsx)(Ce,{children:(0,Q.jsx)(xe,{className:`truncate text-sm`,children:Le(t,e)})})})})})}),(0,Q.jsx)(Lt,{activePreferencesPage:t})]})}export{Vt as GeneralSettingsView};
3
+ `).forEach(e=>{let t=e.indexOf(`=`);t>0&&(n[e.slice(0,t).trim()]=e.slice(t+1).trim())}),t({name:r.trim(),type:a,...a===`stdio`?{command:s.trim(),args:e.length>0?e:void 0}:{},...a===`stdio`?{}:{url:l.trim()},...Object.keys(n).length>0?{env:n}:{}})},disabled:!r.trim(),"data-testid":`agent-template-mcp-save`,children:e?`Update`:`Add`}),(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,className:`text-xs`,onClick:n,"data-testid":`agent-template-mcp-cancel`,children:`Cancel`})]})]})}function it({template:e,onSave:t}){let n=e.variables??[],r=()=>{t({variables:[...n,{name:``,description:``,defaultValue:``}]})},i=(e,r,i)=>{let a=[...n];a[e]={...a[e],[r]:i},t({variables:a})},a=e=>{let r=n.filter((t,n)=>n!==e);t({variables:r.length>0?r:void 0})};return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`p`,{className:`text-muted-foreground mb-2 text-[10px]`,children:[`Define variables that users fill in when selecting this template. Use`,` `,(0,Q.jsx)(`code`,{className:`bg-muted rounded px-1`,children:`{{VARIABLE_NAME}}`}),` in your system prompt.`]}),n.length>0&&(0,Q.jsx)(`div`,{className:`mb-2 space-y-2`,children:n.map((e,t)=>(0,Q.jsxs)(`div`,{className:`bg-muted/30 flex items-start gap-2 rounded border p-2`,"data-testid":`agent-template-variable-${t}`,children:[(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Q.jsx)(J,{value:e.name,onChange:e=>i(t,`name`,e.target.value),placeholder:`VARIABLE_NAME`,className:`h-7 font-mono text-xs`,"data-testid":`agent-template-variable-name-${t}`}),(0,Q.jsx)(J,{value:e.description??``,onChange:e=>i(t,`description`,e.target.value),placeholder:`Description (shown to user)`,className:`h-7 text-xs`,"data-testid":`agent-template-variable-desc-${t}`}),(0,Q.jsx)(J,{value:e.defaultValue??``,onChange:e=>i(t,`defaultValue`,e.target.value),placeholder:`Default value (optional)`,className:`h-7 text-xs`,"data-testid":`agent-template-variable-default-${t}`})]}),(0,Q.jsx)(`button`,{onClick:()=>a(t),className:`text-muted-foreground hover:text-destructive mt-1 rounded p-0.5`,"data-testid":`agent-template-variable-delete-${t}`,children:(0,Q.jsx)(v,{className:`size-3`})})]},t))}),(0,Q.jsxs)(z,{variant:`outline`,size:`sm`,className:`text-xs`,onClick:r,"data-testid":`agent-template-variable-add`,children:[(0,Q.jsx)(d,{className:`mr-1 size-3`}),`Add Variable`]})]})}function at({template:e,onSave:t}){return(0,Q.jsx)(`div`,{children:(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium`,children:`Share with all users`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-[10px]`,children:`Shared templates are visible to everyone on this instance.`})]}),(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2`,children:[(0,Q.jsx)(G,{checked:e.shared??!1,onCheckedChange:e=>t({shared:e===!0}),"data-testid":`agent-template-shared`}),(0,Q.jsx)(o,{className:`text-muted-foreground size-3`})]})]})})}var ot=L(`extensions-settings`);function st(){let e=oe(e=>e.user?.role===`admin`),[t,n]=(0,Z.useState)([]),[r,i]=(0,Z.useState)(!0),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),d=(0,Z.useCallback)(async()=>{i(!0);let e=await I.listInstalledExtensions();e.isOk()?n(e.value):(ot.error(`failed to list extensions`,{error:e.error.message}),B.error(`Failed to load extensions`,{description:e.error.message})),i(!1)},[]);(0,Z.useEffect)(()=>{d()},[d]);let f=(0,Z.useCallback)(async()=>{let e=a.trim();if(!e)return;c(!0);let t=await I.installExtension(e);t.isOk()?(B.success(`Installed ${t.value.extension.id}`),o(``),await d(),await je()):B.error(`Install failed`,{description:t.error.message}),c(!1)},[a,d]),h=(0,Z.useCallback)(async e=>{u(e.name);let t=await I.removeExtension(e.name);t.isOk()?(B.success(`Removed ${e.id}`,{description:`Reload the page to fully unload it.`}),await d()):B.error(`Remove failed`,{description:t.error.message}),u(null)},[d]);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`mb-2 flex items-center justify-end`,children:(0,Q.jsx)(Y,{tooltip:`Refresh`,onClick:()=>void d(),"data-testid":`extensions-refresh`,children:(0,Q.jsx)(p,{className:r?`icon-base animate-spin`:`icon-base`})})}),(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:`Visualizer plugins extend how funny renders fenced code blocks and file previews. They run with full access to your session — install only extensions you trust.`}),(0,Q.jsxs)(`div`,{className:`settings-card mb-4 flex items-start gap-2 border-amber-500/30 bg-amber-500/5 p-3`,children:[(0,Q.jsx)(D,{className:`icon-base mt-0.5 shrink-0 text-amber-500`}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-sm`,children:`Installing an extension runs its code inside your authenticated session, like installing an npm package. There is no sandbox.`})]}),e&&(0,Q.jsxs)(`div`,{className:`settings-card mb-4 p-4`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs font-medium`,children:`Install from a local package directory (on the server)`}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(J,{value:a,onChange:e=>o(e.target.value),placeholder:`/path/to/funny-visualizer-xyz`,spellCheck:!1,"data-testid":`extensions-install-path`,onKeyDown:e=>{e.key===`Enter`&&!s&&f()}}),(0,Q.jsxs)(z,{onClick:()=>void f(),disabled:s||!a.trim(),"data-testid":`extensions-install-submit`,children:[(0,Q.jsx)(x,{className:`icon-base mr-1`}),s?`Installing…`:`Install`]})]}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:[`The directory must contain a `,(0,Q.jsx)(`code`,{children:`package.json`}),` with a `,(0,Q.jsx)(`code`,{children:`funny.client`}),` `,`entry pointing at the built ESM bundle.`]})]}),t.length===0?(0,Q.jsxs)(`div`,{className:`settings-card flex flex-col items-center gap-2 px-4 py-8 text-center`,children:[(0,Q.jsx)(m,{className:`text-muted-foreground/50 size-6`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:r?`Loading…`:`No extensions installed.`})]}):(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:t.map(t=>(0,Q.jsxs)(`div`,{className:`settings-card flex items-center gap-3 px-3 py-2.5`,"data-testid":`extension-item-${t.name}`,children:[(0,Q.jsx)(m,{className:`icon-base text-muted-foreground shrink-0`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-sm font-medium`,children:t.id}),(0,Q.jsxs)(`span`,{className:`text-muted-foreground text-xs`,children:[`v`,t.version]})]}),t.description&&(0,Q.jsx)(`p`,{className:`text-muted-foreground truncate text-xs`,children:t.description})]}),e&&(0,Q.jsx)(Y,{tooltip:`Remove`,onClick:()=>void h(t),disabled:l===t.name,"data-testid":`extension-remove-${t.name}`,children:(0,Q.jsx)(v,{className:`icon-base text-destructive`})})]},t.name))})]})}function ct(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_]+/g,`-`).replace(/^-+|-+$/g,``)}function lt(){let[e,n]=(0,Z.useState)([]),[r,i]=(0,Z.useState)(new Map),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!0),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(``),[_,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(!1),S=fe(e=>e.loadProjects),C=(0,Z.useCallback)(async()=>{try{let e=await P.getSession();o(F(e.data));let t=await P.organization.list();if(t.data){n(t.data.map(e=>({id:e.id,name:e.name,slug:e.slug,createdAt:e.createdAt||``})));let r=new Map,a=e.data?.user?.id,o=await Promise.all(t.data.map(e=>P.organization.getFullOrganization({query:{organizationId:e.id}}).catch(()=>null)));for(let e=0;e<t.data.length;e++){let n=o[e];if(n?.data){let i=n.data.members?.find(e=>e.userId===a);i&&r.set(t.data[e].id,i.role)}}i(r)}}catch(e){console.error(`[OrganizationManagement] Failed to load orgs:`,e)}finally{c(!1)}},[]);(0,Z.useEffect)(()=>{C()},[C]);let w=(0,Z.useCallback)(async()=>{let e=p.trim(),t=h.trim()||ct(e);if(!(!e||!t)){x(!0);try{await P.organization.create({name:e,slug:t}),B.success(`Organization "${e}" created`),m(``),g(``),y(!1),await C()}catch(e){B.error(e.message||`Failed to create organization`)}finally{x(!1)}}},[p,h,C]),T=(0,Z.useCallback)(async e=>{try{await P.organization.setActive({organizationId:e}),o(e),await S(),B.success(`Active organization switched`)}catch(e){B.error(e.message||`Failed to switch organization`)}},[S]),E=(0,Z.useCallback)(async()=>{if(l){f(!0);try{await P.organization.delete({organizationId:l.id}),B.success(`Organization "${l.name}" deleted`),u(null),await C()}catch(e){B.error(e.message||`Failed to delete organization`)}finally{f(!1)}}},[l,C]);return s?(0,Q.jsx)(`div`,{className:`text-muted-foreground flex items-center justify-center py-12 text-sm`,children:`Loading organizations…`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`h3`,{className:`settings-section-header`,children:`Create Organization`}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-3 text-sm`,children:`Create a new organization to manage team members and projects.`}),(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-xs font-medium`,children:`Name`}),(0,Q.jsx)(J,{value:p,onChange:e=>{m(e.target.value),_||g(ct(e.target.value))},placeholder:`My Organization`,className:`text-sm`,"data-testid":`org-create-name`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-xs font-medium`,children:`Slug`}),(0,Q.jsx)(J,{value:h,onChange:e=>{g(e.target.value),y(!0)},placeholder:`my-organization`,className:`font-mono text-sm`,"data-testid":`org-create-slug`})]}),(0,Q.jsx)(z,{size:`sm`,onClick:w,disabled:b||!p.trim(),"data-testid":`org-create-submit`,children:b?`Creating...`:`Create Organization`})]})]})}),(0,Q.jsxs)(`h3`,{className:`settings-section-header`,children:[`Your Organizations (`,e.length,`)`]}),(0,Q.jsx)(`div`,{className:`settings-card`,children:e.length===0?(0,Q.jsx)(`div`,{className:`text-muted-foreground px-4 py-6 text-center text-sm`,children:`No organizations yet. Create one above to get started.`}):e.map(e=>{let n=r.get(e.id)||`member`,i=e.id===a,o=n===`owner`;return(0,Q.jsxs)(`div`,{className:`settings-row`,"data-testid":`org-item-${e.id}`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(t,{className:`icon-base text-muted-foreground shrink-0`}),(0,Q.jsx)(`p`,{className:`text-foreground truncate text-sm font-medium`,children:e.name}),(0,Q.jsx)(V,{variant:`secondary`,className:`text-xs`,children:n}),i&&(0,Q.jsx)(V,{variant:`secondary`,className:`bg-green-500/15 text-green-700 dark:text-green-400`,children:`Active`})]}),(0,Q.jsx)(`p`,{className:`text-muted-foreground ml-6 text-xs`,children:e.slug})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!i&&(0,Q.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>T(e.id),"data-testid":`org-set-active-${e.id}`,children:[(0,Q.jsx)(O,{className:`icon-sm mr-1.5`}),`Set Active`]}),o&&(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`text-muted-foreground hover:text-destructive size-8`,onClick:()=>u(e),"data-testid":`org-delete-${e.id}`,children:(0,Q.jsx)(v,{className:`icon-base`})})]})]},e.id)})}),(0,Q.jsx)(Ee,{open:!!l,onOpenChange:e=>{e||u(null)},title:`Delete Organization`,description:`Are you sure you want to delete "${l?.name}"? This action cannot be undone. All members will lose access.`,warning:`This will permanently delete the organization and all associated data.`,cancelLabel:`Cancel`,confirmLabel:`Delete`,loading:d,onCancel:()=>u(null),onConfirm:E})]})}var ut=L(`providers-settings`),dt=j.map(e=>({id:e,label:ce[e].label}));function ft(e){return/:\/\//.test(e)||/^git@/.test(e)||/^(github|gh):/i.test(e)}function pt(){let[e,t]=(0,Z.useState)([]),[n,i]=(0,Z.useState)(!0),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null),m=Fe(e=>e.fetch),h=Fe(e=>e.activeBuiltins),g=Fe(e=>e.setActiveBuiltins),_=(0,Z.useCallback)(async()=>{i(!0);let e=await N.getProviders();e.isOk()?t(e.value.providers):(ut.error(`failed to list providers`,{error:e.error.message}),B.error(`Failed to load providers`,{description:e.error.message})),i(!1)},[]);(0,Z.useEffect)(()=>{_(),m()},[_,m]);let y=(0,Z.useCallback)(async()=>{let e=a.trim();if(!e)return;c(!0);let t=ft(e)?{git:e}:{path:e},n=await N.installProvider(t);if(n.isOk()){let e=n.value.provider;B.success(`Installed ${e.id}`,{description:`Launches "${[e.spawn.command,...e.spawn.args].join(` `)}" on your runner.`}),o(``),await _(),await m(!0)}else B.error(`Install failed`,{description:n.error.message});c(!1)},[a,_,m]),b=(0,Z.useCallback)(e=>h===null||h.includes(e),[h]),S=(0,Z.useCallback)(async(e,t)=>{f(e);let n=await N.setBuiltinEnabled(e,t);n.isOk()?(g(n.value.active),B.success(`${t?`Enabled`:`Disabled`} ${e}`,{description:`Saved — your selection is restored when the runner restarts.`})):B.error(`${t?`Enable`:`Disable`} failed`,{description:n.error.message}),f(null)},[g]),C=(0,Z.useCallback)(async e=>{u(e);let t=await N.removeProvider(e);t.isOk()?(B.success(`Removed ${e}`),await _(),await m(!0)):B.error(`Remove failed`,{description:t.error.message}),u(null)},[_,m]);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:`Install ACP agent providers onto your runner. A provider is a declarative manifest pointing at an agent CLI already installed on the runner — installing one lets funny launch that binary.`}),(0,Q.jsxs)(`div`,{className:`settings-card mb-4 flex items-start gap-2 border-amber-500/30 bg-amber-500/5 p-3`,children:[(0,Q.jsx)(D,{className:`icon-base mt-0.5 shrink-0 text-amber-500`}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-sm`,children:`Installing a provider lets funny spawn the binary it declares on your runner. Install only providers you trust.`})]}),(0,Q.jsxs)(`div`,{className:`settings-card mb-4 p-4`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs font-medium`,children:`Install from a git repo or a local path on the runner`}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(J,{value:a,onChange:e=>o(e.target.value),placeholder:`github:user/funny-myagent · or /path/to/funny-myagent`,spellCheck:!1,"data-testid":`providers-install-source`,onKeyDown:e=>{e.key===`Enter`&&!s&&y()}}),(0,Q.jsxs)(z,{onClick:()=>void y(),disabled:s||!a.trim(),"data-testid":`providers-install-submit`,children:[(0,Q.jsx)(x,{className:`icon-base mr-1`}),s?`Installing…`:`Install`]})]}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:[`The package must contain a `,(0,Q.jsx)(`code`,{children:`package.json`}),` with a `,(0,Q.jsx)(`code`,{children:`funny.provider`}),` `,`entry pointing at a `,(0,Q.jsx)(`code`,{children:`funny.provider.json`}),` manifest.`]})]}),(0,Q.jsxs)(`div`,{className:`mt-2 mb-1 flex items-center justify-between px-1`,children:[(0,Q.jsx)(`h4`,{className:`text-muted-foreground text-xs font-semibold tracking-wide uppercase`,children:`Built-in providers`}),(0,Q.jsx)(Y,{tooltip:`Refresh`,onClick:()=>void _(),"data-testid":`providers-refresh`,children:(0,Q.jsx)(p,{className:n?`icon-base animate-spin`:`icon-base`})})]}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground px-1 pb-2 text-sm`,children:[`Enable or disable bundled ACP providers in the model picker. Your selection is saved and restored when the runner restarts. Set `,(0,Q.jsx)(`code`,{children:`FUNNY_PROVIDERS`}),` on the runner to change the built-in default.`]}),(0,Q.jsx)(`div`,{className:`settings-card divide-border mb-4 space-y-0 divide-y`,children:dt.map(({id:e,label:t})=>{let n=b(e);return(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3.5`,"data-testid":`builtin-provider-${e}`,children:[(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-sm font-medium`,children:t}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:e})]})}),(0,Q.jsx)(Te,{checked:n,onCheckedChange:t=>void S(e,t),disabled:d===e,"aria-label":`${n?`Disable`:`Enable`} ${t}`,"data-testid":`builtin-toggle-${e}`})]},e)})}),(0,Q.jsx)(`div`,{className:`mt-2 mb-1 px-1`,children:(0,Q.jsx)(`h4`,{className:`text-muted-foreground text-xs font-semibold tracking-wide uppercase`,children:`Installed providers`})}),e.length===0?(0,Q.jsxs)(`div`,{className:`settings-card flex flex-col items-center gap-2 px-4 py-8 text-center`,children:[(0,Q.jsx)(r,{className:`text-muted-foreground/50 size-6`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:n?`Loading…`:`No external providers installed.`})]}):(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map(e=>(0,Q.jsxs)(`div`,{className:`settings-card flex items-center gap-3 px-3 py-2.5`,"data-testid":`provider-item-${e.id}`,children:[(0,Q.jsx)(r,{className:`icon-base text-muted-foreground shrink-0`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-sm font-medium`,children:e.label}),(0,Q.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:e.id})]}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground truncate text-xs`,children:[e.models.kind,` catalog · default `,e.models.defaultModel,` · auth `,e.auth.mode]})]}),(0,Q.jsx)(Y,{tooltip:`Remove`,onClick:()=>void C(e.id),disabled:l===e.id,"data-testid":`provider-remove-${e.id}`,children:(0,Q.jsx)(v,{className:`icon-base text-destructive`})})]},e.id))})]})}function mt(e){return e===`online`?`text-green-500`:e===`busy`?`text-yellow-500`:`text-muted-foreground`}function ht(e){return e===`online`?`Online`:e===`busy`?`Busy`:`Offline`}function gt(e){return e===`darwin`?`🍎`:e===`win32`?`🪟`:`🐧`}function _t(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function vt({runnerId:e,onAssigned:t}){let n=Me(e=>e.projects),[r,i]=(0,Z.useState)(``),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`border-border/50 bg-muted/30 mt-3 flex flex-col gap-2 rounded border p-3`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Assign a project and provide its local path on this runner's machine.`}),(0,Q.jsxs)(K,{value:r,onValueChange:i,children:[(0,Q.jsx)(W,{size:`xs`,"data-testid":`runner-assign-project-select-${e}`,children:(0,Q.jsx)(U,{placeholder:`Select project...`})}),(0,Q.jsx)(H,{children:n.map(e=>(0,Q.jsx)(q,{value:e.id,children:e.name},e.id))})]}),(0,Q.jsx)(J,{value:a,onChange:e=>o(e.target.value),placeholder:`/home/user/my-project`,className:`h-7 font-mono text-xs`,"data-testid":`runner-assign-localpath-${e}`}),(0,Q.jsx)(z,{size:`sm`,className:`h-6 text-xs`,disabled:!r||!a.trim()||s,onClick:async()=>{if(!r||!a.trim())return;c(!0);let n=await I.assignRunnerProject(e,r,a.trim());c(!1),n.isOk()?(B.success(`Project assigned`),i(``),o(``),t()):B.error(`Failed to assign project`)},"data-testid":`runner-assign-submit-${e}`,children:s?`Assigning...`:`Assign`})]})}function yt({runner:e,onDeleted:t}){let{t:n}=A(),[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)([]),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(!1),p=async()=>{let t=await I.getMyRunners();if(t.isOk()){let n=t.value.runners.find(t=>t.runnerId===e.runnerId);n&&o(n.assignedProjectIds.map(t=>({runnerId:e.runnerId,projectId:t,localPath:``,assignedAt:``})))}},m=async()=>{u(!0);let n=await I.deleteRunner(e.runnerId);u(!1),n.isOk()?(f(!1),B.success(`Runner removed`),t()):B.error(`Failed to remove runner`)},h=async t=>{(await I.unassignRunnerProject(e.runnerId,t)).isOk()?(B.success(`Project unassigned`),p()):B.error(`Failed to unassign project`)};(0,Z.useEffect)(()=>{r&&p()},[r]);let _=Me(e=>e.projects);return(0,Q.jsxs)(ge,{open:r,onOpenChange:i,className:`border-border/50 bg-card overflow-hidden rounded-lg border`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5`,"data-testid":`runner-item-${e.runnerId}`,children:[(0,Q.jsx)(C,{className:R(`size-2 shrink-0 fill-current`,mt(e.status))}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-sm font-medium`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-xs`,children:gt(e.os)}),(0,Q.jsx)(V,{variant:`outline`,className:R(`h-4 px-1.5 text-[10px]`,mt(e.status)),children:ht(e.status)})]}),(0,Q.jsxs)(`div`,{className:`text-muted-foreground truncate text-xs`,children:[e.hostname,` · last seen `,_t(e.lastHeartbeatAt),e.assignedProjectIds.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[` `,`· `,e.assignedProjectIds.length,` project`,e.assignedProjectIds.length===1?``:`s`]})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsxs)(re,{children:[(0,Q.jsx)(se,{asChild:!0,children:(0,Q.jsx)(ke,{asChild:!0,children:(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`size-6`,"data-testid":`runner-item-${e.runnerId}-expand`,children:r?(0,Q.jsx)(g,{className:`icon-sm`}):(0,Q.jsx)(b,{className:`icon-sm`})})})}),(0,Q.jsx)(M,{children:n(r?`common.collapse`:`common.expand`)})]}),(0,Q.jsx)(Y,{size:`icon`,className:`text-destructive hover:text-destructive size-6`,onClick:()=>f(!0),disabled:l,"data-testid":`runner-item-${e.runnerId}-delete`,tooltip:n(`common.delete`),children:(0,Q.jsx)(v,{className:`icon-sm`})})]})]}),(0,Q.jsx)(Ee,{open:d,onOpenChange:f,title:`Remove runner`,description:`Are you sure you want to remove "${e.name}"? This action cannot be undone.`,confirmLabel:n(`common.remove`,`Remove`),loading:l,onCancel:()=>f(!1),onConfirm:m}),(0,Q.jsx)(de,{className:`px-3 pb-3`,children:(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[a.length===0?(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`No projects assigned yet.`}):a.map(t=>(0,Q.jsxs)(`div`,{className:`hover:bg-muted/40 flex items-center justify-between rounded px-2 py-1 text-xs`,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:_.find(e=>e.id===t.projectId)?.name??t.projectId}),(0,Q.jsx)(Y,{size:`icon`,className:`text-destructive hover:text-destructive size-5`,onClick:()=>h(t.projectId),"data-testid":`runner-item-${e.runnerId}-unassign-${t.projectId}`,tooltip:n(`common.unassign`),children:(0,Q.jsx)(v,{className:`icon-xs`})})]},t.projectId)),(0,Q.jsxs)(`button`,{className:`text-primary mt-1 flex items-center gap-1 text-xs hover:underline`,onClick:()=>c(e=>!e),"data-testid":`runner-item-${e.runnerId}-add-project`,children:[(0,Q.jsx)(ee,{className:`icon-sm`}),`Assign a project`]}),s&&(0,Q.jsx)(vt,{runnerId:e.runnerId,onAssigned:()=>{c(!1),p()}})]})})]})}function bt({onLinked:e}){let[t,n]=(0,Z.useState)(``),[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),l=async()=>{let e=t.trim();if(!e)return;i(!0);let n=await I.getRunnerEnrollment(e);i(!1),n.isOk()?c(n.value):B.error(`Unknown or expired code`)};return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(J,{value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l()},placeholder:`Enter runner code, e.g. WXYZ-1234`,size:`xs`,className:`flex-1 font-mono uppercase`,"data-testid":`link-runner-code`}),(0,Q.jsx)(z,{size:`sm`,variant:`outline`,onClick:l,disabled:!t.trim()||r,className:`shrink-0`,"data-testid":`link-runner-submit`,children:r?`Checking…`:`Link a runner`}),(0,Q.jsx)(Ee,{open:!!s,onOpenChange:e=>!e&&c(null),title:`Approve this runner?`,description:s?`Link "${s.hostname}" (${s.os}, from ${s.ip||`unknown IP`}) to your account? Only approve runners you started.`:``,confirmLabel:`Approve`,loading:a,onCancel:()=>c(null),onConfirm:async()=>{if(!s)return;o(!0);let t=await I.approveRunnerEnrollment(s.userCode);o(!1),t.isOk()?(B.success(`Runner linked`),c(null),n(``),e()):B.error(`Failed to link runner`)}})]})}function xt(){let[e,t]=(0,Z.useState)([]),[n,r]=(0,Z.useState)(!0),i=async()=>{r(!0);let e=await I.getMyRunners();r(!1),e.isOk()&&t(e.value.runners)};return(0,Z.useEffect)(()=>{i();let e=setInterval(i,3e4);return()=>clearInterval(e)},[]),(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{className:`settings-card space-y-3 p-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:`Connect a new runner`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-0.5 text-sm`,children:`Start a runner on any machine, then approve the code it prints to link it to your account — no token or secret to copy.`})]}),(0,Q.jsx)(Ae,{}),(0,Q.jsxs)(`div`,{className:`border-border/50 border-t pt-3`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-2 text-xs`,children:`Already started a runner? Enter the code it printed to approve it:`}),(0,Q.jsx)(bt,{onLinked:i})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:`My Runners`}),(0,Q.jsxs)(z,{size:`sm`,variant:`ghost`,onClick:i,disabled:n,className:`h-6 text-xs`,"data-testid":`runners-refresh`,children:[(0,Q.jsx)(p,{className:R(`mr-1 icon-xs`,n&&`animate-spin`)}),`Refresh`]})]}),n&&e.length===0?(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Loading…`}):e.length===0?(0,Q.jsxs)(`div`,{className:`border-border/50 rounded-lg border border-dashed px-4 py-6 text-center`,children:[(0,Q.jsx)(f,{className:`text-muted-foreground/50 mx-auto mb-2 size-8`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`No runners connected yet.`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:`Copy the install command above and run it on any machine.`})]}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,Q.jsx)(yt,{runner:e,onDeleted:i},e.runnerId))})]})]})}var St={version:`0.1.6`,commit:`fbcacb63`,build:1436,dirty:!0,label:`0.1.6 (fbcacb63+)`},Ct=L(`system-settings`),wt=De({fg:`#abb2bf`,bg:`transparent`,newline:!0});function Tt(){let[e,t]=(0,Z.useState)(null),[n,r]=(0,Z.useState)(!0),{buildOutput:i,buildStatus:a,clearBuild:o}=ze(),s=(0,Z.useRef)(null),c=(0,Z.useCallback)(async()=>{r(!0);let e=await I.setupStatus();e.isOk()&&e.value.nativeGit&&t(e.value.nativeGit),r(!1)},[]);(0,Z.useEffect)(()=>{c()},[c]),(0,Z.useEffect)(()=>{s.current&&(s.current.scrollTop=s.current.scrollHeight)},[i]);let l=(0,Z.useCallback)(async()=>{o();let e=await I.buildNativeGit();e.isErr()&&(Ct.error(`Failed to start native git build`,{error:e.error.message}),B.error(`Failed to start build: `+e.error.message))},[o]);if(n&&!e)return(0,Q.jsx)(`div`,{className:`p-1`,children:(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Loading…`})});let u=e?.loaded&&!e?.disabled,d=a===`building`,f=a===`completed`,m=a===`failed`;return(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsx)(`div`,{children:(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:`System-level configuration and native module management.`})}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`p`,{className:`settings-row-title`,children:`Native Git (gitoxide)`}),e&&(0,Q.jsx)(V,{variant:`outline`,className:R(`h-5 px-2 text-[10px]`,u?`border-green-500/30 text-green-500`:e.disabled?`border-yellow-500/30 text-yellow-500`:`border-muted-foreground/30 text-muted-foreground`),"data-testid":`system-native-git-status`,children:u?`Active`:e.disabled?`Disabled`:`Inactive`})]}),(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:c,disabled:n,"data-testid":`system-native-git-refresh`,children:(0,Q.jsx)(p,{className:R(`icon-sm`,n&&`animate-spin`)})})]}),(0,Q.jsx)(`p`,{className:`settings-row-desc mt-1`,children:`Rust-based git implementation for 5-10x faster status, diff, log, and branch operations. When inactive, funny falls back to the standard git CLI (fully functional).`}),e&&(0,Q.jsxs)(`div`,{className:`text-muted-foreground mt-3 space-y-2 text-xs`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`w-16 font-medium`,children:`Platform`}),(0,Q.jsx)(`code`,{className:`bg-muted rounded px-1.5 py-0.5`,children:e.platform})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`w-16 font-medium`,children:`Rust`}),e.rustAvailable?(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-green-500`,children:[(0,Q.jsx)(w,{className:`size-3`}),e.rustVersion]}):(0,Q.jsxs)(`span`,{className:`text-muted-foreground flex items-center gap-1`,children:[(0,Q.jsx)(_,{className:`size-3`}),`Not installed`]})]})]}),e&&!u&&!d&&!f&&(0,Q.jsx)(`div`,{className:`mt-4`,children:e.disabled?(0,Q.jsxs)(`p`,{className:`text-xs text-yellow-500`,children:[`Native git is disabled via`,` `,(0,Q.jsx)(`code`,{className:`bg-muted rounded px-1 py-0.5`,children:`FUNNY_DISABLE_NATIVE_GIT=1`}),`. Remove this environment variable and restart funny to enable it.`]}):e.canBuild?(0,Q.jsxs)(z,{size:`sm`,onClick:l,disabled:d,"data-testid":`system-native-git-build`,children:[(0,Q.jsx)(E,{className:`icon-sm mr-1.5`}),`Build Native Module`]}):e.rustAvailable?(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`The native-git source package was not found. This is only available when running from a development checkout.`}):(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Install the Rust toolchain to build the native module:`}),(0,Q.jsx)(`code`,{className:`bg-muted block rounded px-3 py-2 text-xs`,children:`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`After installing Rust, click refresh to detect it.`})]})}),d&&(0,Q.jsx)(`div`,{className:`mt-4 space-y-2`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(C,{className:`size-3 animate-pulse fill-yellow-500 text-yellow-500`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:`Building…`})]})}),f&&(0,Q.jsxs)(`div`,{className:`mt-4 space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-green-500`,children:[(0,Q.jsx)(w,{className:`size-3.5`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:`Build successful!`})]}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Restart funny to activate native git.`})]}),m&&(0,Q.jsxs)(`div`,{className:`mt-4 space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`text-destructive flex items-center gap-2`,children:[(0,Q.jsx)(_,{className:`size-3.5`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:`Build failed`})]}),(0,Q.jsx)(z,{size:`sm`,variant:`outline`,onClick:l,"data-testid":`system-native-git-retry`,children:`Retry Build`})]}),i&&(0,Q.jsx)(`div`,{className:`mt-3`,children:(0,Q.jsx)(Se,{className:`border-border h-64 rounded border bg-[#1e1e2e]`,children:(0,Q.jsx)(`div`,{ref:s,className:`h-full overflow-y-auto p-3 font-mono text-xs leading-relaxed`,"data-testid":`system-native-git-build-output`,dangerouslySetInnerHTML:{__html:wt.toHtml(i)}})})})]})}),(0,Q.jsx)(Et,{})]})}function Et(){let[e,t]=(0,Z.useState)(!1);return(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`p`,{className:`settings-row-title`,children:`Build`}),(0,Q.jsx)(V,{variant:`outline`,className:`h-5 px-2 font-mono text-[10px]`,"data-testid":`system-build-number`,children:St.commit}),St.dirty&&(0,Q.jsx)(V,{variant:`outline`,className:`h-5 border-yellow-500/30 px-2 text-[10px] text-yellow-500`,children:`dirty`})]}),(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>{navigator.clipboard.writeText(St.label).then(()=>{t(!0),window.setTimeout(()=>t(!1),1500)})},"data-testid":`system-build-copy`,children:e?(0,Q.jsx)(w,{className:`icon-sm text-green-500`}):(0,Q.jsx)(c,{className:`icon-sm`})})]}),(0,Q.jsx)(`p`,{className:`settings-row-desc mt-1`,children:`The commit this build was made from. Compare it between two installs — including the deployed server — to tell whether they are running the exact same code.`}),(0,Q.jsx)(`code`,{className:`bg-muted mt-3 block rounded px-3 py-2 text-xs`,"data-testid":`system-build-label`,children:St.label})]})})}var Dt=[{value:`owner`,label:`Owner`},{value:`admin`,label:`Admin`},{value:`member`,label:`Member`},{value:`viewer`,label:`Viewer`}],Ot={owner:`bg-amber-500/15 text-amber-700 dark:text-amber-400`,admin:`bg-blue-500/15 text-blue-700 dark:text-blue-400`,member:`bg-green-500/15 text-green-700 dark:text-green-400`,viewer:`bg-gray-500/15 text-gray-700 dark:text-gray-400`},kt=[{value:`admin`,label:`Admin`},{value:`member`,label:`Member`}];function At(){let{t:e}=A(),[t,n]=(0,Z.useState)([]),[r,i]=(0,Z.useState)(!0),[o,s]=(0,Z.useState)(null),l=oe(e=>e.user),[d,f]=(0,Z.useState)([]),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(`member`),[_,b]=(0,Z.useState)(!1),[x,C]=(0,Z.useState)(null),[w,T]=(0,Z.useState)([]),[E,ee]=(0,Z.useState)(`member`),[D,k]=(0,Z.useState)(!1),[ne,j]=(0,Z.useState)(null),M=(0,Z.useCallback)(async()=>{try{let e=await P.organization.listMembers();e.data&&n(e.data)}catch(e){console.error(`[TeamMembers] Failed to load members:`,e)}finally{i(!1)}},[]),N=(0,Z.useCallback)(async()=>{try{let e=await P.organization.listInvitations();e.data&&f(e.data.filter(e=>e.status===`pending`))}catch(e){console.error(`[TeamMembers] Failed to load invitations:`,e)}},[]),F=(0,Z.useCallback)(async()=>{let e=await I.listInviteLinks();e.isOk()&&T(e.value)},[]),re=(0,Z.useCallback)(async()=>{let e=await I.getSmtpSettings();e.isOk()?C(e.value.configured):C(!1)},[]);(0,Z.useEffect)(()=>{M(),N(),F(),re()},[M,N,F,re]);let ie=(0,Z.useCallback)(async(e,t)=>{try{await P.organization.updateMemberRole({memberId:e,role:t}),n(n=>n.map(n=>n.id===e?{...n,role:t}:n)),B.success(`Role updated`)}catch(e){B.error(e.message||`Failed to update role`)}},[]),ae=(0,Z.useCallback)(async()=>{if(o){try{await P.organization.removeMember({memberIdOrEmail:o.userId}),n(e=>e.filter(e=>e.id!==o.id)),B.success(`Member removed`)}catch(e){B.error(e.message||`Failed to remove member`)}s(null)}},[o]),L=(0,Z.useCallback)(async()=>{if(p.trim()){b(!0);try{await P.organization.inviteMember({email:p.trim(),role:h}),B.success(`Invitation sent to ${p.trim()}`),m(``),await N()}catch(e){B.error(e.message||`Failed to send invitation`)}finally{b(!1)}}},[p,h,N]),R=(0,Z.useCallback)(async()=>{k(!0);try{let e=await I.createInviteLink({role:E,expiresInDays:7});e.isOk()?(T(t=>[e.value,...t]),B.success(`Invite link created`)):B.error(`Failed to create invite link`)}catch{B.error(`Failed to create invite link`)}finally{k(!1)}},[E]),se=(0,Z.useCallback)(async e=>{(await I.revokeInviteLink(e)).isOk()?(T(t=>t.filter(t=>t.id!==e)),B.success(`Invite link revoked`)):B.error(`Failed to revoke invite link`)},[]),ce=(0,Z.useCallback)(e=>{let t=`${window.location.origin}/invite/${e.token}`;navigator.clipboard.writeText(t),j(e.id),B.success(`Link copied to clipboard`),setTimeout(()=>j(null),2e3)},[]),le=(0,Z.useCallback)(async e=>{try{await P.organization.cancelInvitation({invitationId:e}),f(t=>t.filter(t=>t.id!==e)),B.success(`Invitation cancelled`)}catch(e){B.error(e.message||`Failed to cancel invitation`)}},[]),ue=t.filter(e=>e.role===`owner`).length;return r?(0,Q.jsx)(`div`,{className:`text-muted-foreground flex items-center justify-center py-12 text-sm`,children:`Loading members…`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`h3`,{className:`settings-section-header`,children:`Invite Member`}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[x===!1&&(0,Q.jsxs)(`div`,{className:`mb-3 flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-400`,"data-testid":`team-invite-smtp-warning`,children:[(0,Q.jsx)(u,{className:`icon-sm mt-0.5 shrink-0`}),(0,Q.jsxs)(`span`,{children:[`Email is not configured. Configure SMTP in `,(0,Q.jsx)(`strong`,{children:`Settings > Email`}),` to send invitations, or use an invite link below.`]})]}),(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-3 text-sm`,children:`Send an invitation to join this organization.`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(J,{type:`email`,value:p,onChange:e=>m(e.target.value),placeholder:`user@example.com`,className:`flex-1 text-sm`,disabled:x===!1,onKeyDown:e=>{e.key===`Enter`&&x&&L()},"data-testid":`team-invite-email`}),(0,Q.jsxs)(K,{value:h,onValueChange:e=>g(e),disabled:x===!1,children:[(0,Q.jsx)(W,{className:`w-[100px]`,"data-testid":`team-invite-role`,children:(0,Q.jsx)(U,{})}),(0,Q.jsx)(H,{children:kt.map(e=>(0,Q.jsx)(q,{value:e.value,children:e.label},e.value))})]}),(0,Q.jsxs)(z,{size:`sm`,onClick:L,disabled:!p.trim()||_||x===!1,"data-testid":`team-invite-send`,children:[(0,Q.jsx)(te,{className:`icon-sm mr-1.5`}),`Invite`]})]})]})}),(0,Q.jsx)(`h3`,{className:`settings-section-header`,children:`Invite Link`}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground mb-3 text-sm`,children:`Generate a shareable link to invite people to this organization.`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(K,{value:E,onValueChange:e=>ee(e),children:[(0,Q.jsx)(W,{className:`w-[100px]`,"data-testid":`team-link-role`,children:(0,Q.jsx)(U,{})}),(0,Q.jsx)(H,{children:kt.map(e=>(0,Q.jsx)(q,{value:e.value,children:e.label},e.value))})]}),(0,Q.jsxs)(z,{size:`sm`,onClick:R,disabled:D,"data-testid":`team-link-create`,children:[(0,Q.jsx)(a,{className:`icon-sm mr-1.5`}),`Generate Link`]})]}),w.length>0&&(0,Q.jsx)(`div`,{className:`mt-3 space-y-2`,children:w.map(t=>{let n=t.expiresAt&&new Date(t.expiresAt)<new Date,r=t.maxUses!==null&&t.useCount>=t.maxUses,i=!n&&!r;return(0,Q.jsxs)(`div`,{className:`border-border/50 flex items-center gap-2 rounded-md border px-3 py-2`,"data-testid":`team-link-${t.id}`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`code`,{className:`text-muted-foreground truncate text-xs`,children:[window.location.origin,`/invite/`,t.token]}),(0,Q.jsx)(V,{variant:`secondary`,className:i?`bg-green-500/15 text-green-700 dark:text-green-400`:`bg-red-500/15 text-red-700 dark:text-red-400`,children:n?`expired`:r?`maxed`:t.role})]}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground mt-0.5 text-xs`,children:[t.useCount,` use`,t.useCount===1?``:`s`,t.expiresAt&&` · expires ${new Date(t.expiresAt).toLocaleDateString()}`]})]}),(0,Q.jsx)(Y,{size:`icon`,className:`size-7 shrink-0`,onClick:()=>ce(t),disabled:!i,"data-testid":`team-link-copy-${t.id}`,tooltip:e(`common.copyLink`),children:ne===t.id?(0,Q.jsx)(O,{className:`icon-sm text-green-500`}):(0,Q.jsx)(c,{className:`icon-sm`})}),(0,Q.jsx)(Y,{size:`icon`,className:`text-muted-foreground hover:text-destructive size-7 shrink-0`,onClick:()=>se(t.id),"data-testid":`team-link-revoke-${t.id}`,tooltip:e(`common.revoke`),children:(0,Q.jsx)(v,{className:`icon-sm`})})]},t.id)})})]})}),(0,Q.jsxs)(`h3`,{className:`settings-section-header`,children:[`Members (`,t.length,`)`]}),(0,Q.jsx)(`div`,{className:`settings-card`,children:t.map(e=>{let t=e.userId===l?.id,n=e.role===`owner`&&ue<=1;return(0,Q.jsxs)(`div`,{className:`settings-row`,"data-testid":`team-member-${e.userId}`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`p`,{className:`text-foreground truncate text-sm font-medium`,children:[e.user.name,t&&(0,Q.jsx)(`span`,{className:`text-muted-foreground ml-1 text-xs`,children:`(you)`})]}),(0,Q.jsx)(V,{variant:`secondary`,className:Ot[e.role],"data-testid":`team-member-role-badge-${e.userId}`,children:e.role})]}),(0,Q.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:e.user.email})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(K,{value:e.role,onValueChange:t=>ie(e.id,t),disabled:n&&e.role===`owner`,children:[(0,Q.jsx)(W,{className:`h-8 w-[100px]`,"data-testid":`team-member-role-select-${e.userId}`,children:(0,Q.jsx)(U,{})}),(0,Q.jsx)(H,{children:Dt.map(e=>(0,Q.jsx)(q,{value:e.value,children:e.label},e.value))})]}),(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`text-muted-foreground hover:text-destructive size-8`,onClick:()=>s(e),disabled:n,"data-testid":`team-member-remove-${e.userId}`,children:(0,Q.jsx)(y,{className:`icon-base`})})]})]},e.id)})}),d.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`h3`,{className:`settings-section-header`,children:[`Pending Invitations (`,d.length,`)`]}),(0,Q.jsx)(`div`,{className:`settings-card`,children:d.map(e=>(0,Q.jsxs)(`div`,{className:`settings-row`,"data-testid":`team-invitation-${e.id}`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-foreground truncate text-sm`,children:e.email}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground text-xs`,children:[`Expires `,new Date(e.expiresAt).toLocaleDateString()]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(V,{variant:`secondary`,children:e.role}),(0,Q.jsx)(z,{variant:`ghost`,size:`icon`,className:`text-muted-foreground hover:text-destructive size-7`,onClick:()=>le(e.id),"data-testid":`team-invitation-cancel-${e.id}`,children:(0,Q.jsx)(S,{className:`icon-sm`})})]})]},e.id))})]}),(0,Q.jsx)(Ee,{open:!!o,onOpenChange:e=>{e||s(null)},title:`Remove Member`,description:`Remove ${o?.user.name} from this organization? They will lose access to all team projects.`,cancelLabel:`Cancel`,confirmLabel:`Remove`,onCancel:()=>s(null),onConfirm:ae})]})}function jt(){let{t:e}=A(),t=oe(e=>e.user),[n,r]=(0,Z.useState)([]),[i,a]=(0,Z.useState)(!0),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(`user`),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(``),b=(0,Z.useCallback)(async()=>{try{a(!0);let e=await P.admin.listUsers({query:{limit:100}});e.data?.users&&r(e.data.users.map(e=>({id:e.id,name:e.name||``,username:e.username||``,email:e.email||``,role:e.role||`user`,createdAt:e.createdAt||``})))}catch(e){console.error(`[UserManagement] Failed to list users:`,e)}finally{a(!1)}},[]);(0,Z.useEffect)(()=>{b()},[b]);let x=async()=>{if(!(!c.trim()||!f.trim())){y(``),_(!0);try{await P.admin.createUser({email:`${c.trim()}@local.host`,password:f,name:u.trim()||c.trim(),role:m,data:{username:c.trim()}}),s(!1),l(``),d(``),p(``),h(`user`),await b()}catch(t){y(t.message||e(`users.createFailed`))}finally{_(!1)}}},S=async e=>{if(e!==t?.id)try{await P.admin.removeUser({userId:e}),await b()}catch(e){console.error(`[UserManagement] Failed to remove user:`,e)}};return i?(0,Q.jsx)(`p`,{className:`text-muted-foreground p-4 text-sm`,children:e(`common.loading`)}):(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(`div`,{className:`flex items-center justify-end px-4 pt-2`,children:(0,Q.jsx)(z,{size:`sm`,variant:`outline`,onClick:()=>s(!o),children:e(o?`common.cancel`:`users.addUser`)})}),o&&(0,Q.jsxs)(`div`,{className:`border-border mx-4 space-y-3 rounded-md border p-3`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-xs font-medium`,children:e(`users.username`)}),(0,Q.jsx)(J,{value:c,onChange:e=>l(e.target.value),placeholder:e(`users.usernamePlaceholder`),autoFocus:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-xs font-medium`,children:e(`users.displayName`)}),(0,Q.jsx)(J,{value:u,onChange:e=>d(e.target.value),placeholder:e(`users.displayNamePlaceholder`)})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-xs font-medium`,children:e(`users.password`)}),(0,Q.jsx)(J,{type:`password`,value:f,onChange:e=>p(e.target.value),placeholder:e(`users.passwordPlaceholder`)})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground text-xs font-medium`,children:e(`users.role`)}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(z,{size:`sm`,variant:m===`user`?`default`:`outline`,onClick:()=>h(`user`),children:e(`users.roleUser`)}),(0,Q.jsx)(z,{size:`sm`,variant:m===`admin`?`default`:`outline`,onClick:()=>h(`admin`),children:e(`users.roleAdmin`)})]})]}),v&&(0,Q.jsx)(`p`,{className:`text-destructive text-xs`,children:v}),(0,Q.jsx)(z,{size:`sm`,onClick:x,disabled:g||!c.trim()||!f.trim(),children:e(g?`users.creating`:`users.create`)})]}),(0,Q.jsx)(`div`,{className:`space-y-1 px-4`,children:n.map(n=>(0,Q.jsxs)(`div`,{className:`hover:bg-accent/50 flex items-center justify-between rounded-md px-3 py-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`p`,{className:`text-foreground truncate text-sm font-medium`,children:[n.name||n.username,n.role===`admin`&&(0,Q.jsx)(`span`,{className:`text-primary ml-2 text-xs font-normal`,children:e(`users.roleAdmin`)})]}),(0,Q.jsxs)(`p`,{className:`text-muted-foreground text-xs`,children:[`@`,n.username]})]}),n.id!==t?.id&&(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,className:`text-destructive hover:text-destructive text-xs`,onClick:()=>S(n.id),children:e(`common.delete`)})]},n.id))})]})}var Mt=[{value:`one-dark`,label:`settings.themes.oneDark`,colors:{bg:`#252931`,sidebar:`#1e2127`,accent:`#528bff`,fg:`#b8beca`}},{value:`dracula`,label:`settings.themes.dracula`,colors:{bg:`#282A36`,sidebar:`#21222C`,accent:`#BD93F9`,fg:`#F8F8F2`}},{value:`github-dark`,label:`settings.themes.githubDark`,colors:{bg:`#0d1117`,sidebar:`#010409`,accent:`#2f81f7`,fg:`#e6edf3`}},{value:`night-owl`,label:`settings.themes.nightOwl`,colors:{bg:`#011627`,sidebar:`#01111d`,accent:`#7e57c2`,fg:`#d6deeb`}},{value:`catppuccin`,label:`settings.themes.catppuccin`,colors:{bg:`#1e1e2e`,sidebar:`#181825`,accent:`#89b4fa`,fg:`#cdd6f4`}},{value:`sunrise`,label:`settings.themes.sunrise`,colors:{bg:`#FAFAFA`,sidebar:`#F5F5F5`,accent:`#171717`,fg:`#171717`}},{value:`monochrome`,label:`settings.themes.monochrome`,colors:{bg:`#ffffff`,sidebar:`#f7f7f7`,accent:`#000000`,fg:`#000000`}},{value:`monochrome-dark`,label:`settings.themes.monochromeDark`,colors:{bg:`#121212`,sidebar:`#0d0d0d`,accent:`#ededed`,fg:`#ededed`}}],Nt=new Map;function Pt(e){let t=Nt.get(e);return t||(t=new Intl.DisplayNames([e],{type:`language`}),Nt.set(e,t)),t}function Ft(e){try{let t=Pt(e).of(e);return t?t.charAt(0).toUpperCase()+t.slice(1):e}catch{return e}}function It({option:e,selected:t,onClick:n,t:r}){let{bg:i,sidebar:a,accent:o,fg:s}=e.colors;return(0,Q.jsxs)(`button`,{onClick:n,"data-testid":`preferences-theme-${e.value}`,className:R(`relative flex flex-col overflow-hidden rounded-lg border-2 transition-colors`,t?`border-primary`:`border-border/50 hover:border-border`),children:[(0,Q.jsxs)(`div`,{className:`flex h-16`,style:{backgroundColor:i},children:[(0,Q.jsx)(`div`,{className:`w-5 border-r`,style:{backgroundColor:a,borderColor:`${s}15`}}),(0,Q.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 p-2`,children:[(0,Q.jsx)(`div`,{className:`h-1.5 w-10 rounded-full`,style:{backgroundColor:s,opacity:.7}}),(0,Q.jsx)(`div`,{className:`h-1.5 w-14 rounded-full`,style:{backgroundColor:s,opacity:.3}}),(0,Q.jsx)(`div`,{className:`h-1.5 w-8 rounded-full`,style:{backgroundColor:o}})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-2.5 py-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:r(e.label)}),t&&(0,Q.jsx)(O,{className:`icon-xs text-primary`})]})]})}function Lt({activePreferencesPage:e}){let{defaultEditor:t,useInternalEditor:n,terminalShell:r,availableShells:i,fontSize:a,notificationsEnabled:o,notificationSoundEnabled:s,setDefaultEditor:c,setUseInternalEditor:l,setTerminalShell:u,setFontSize:d,setNotificationsEnabled:f,setNotificationSoundEnabled:p,fetchAvailableShells:m}=ae(_e(e=>({defaultEditor:e.defaultEditor,useInternalEditor:e.useInternalEditor,terminalShell:e.terminalShell,availableShells:e.availableShells,fontSize:e.fontSize,notificationsEnabled:e.notificationsEnabled,notificationSoundEnabled:e.notificationSoundEnabled,setDefaultEditor:e.setDefaultEditor,setUseInternalEditor:e.setUseInternalEditor,setTerminalShell:e.setTerminalShell,setFontSize:e.setFontSize,setNotificationsEnabled:e.setNotificationsEnabled,setNotificationSoundEnabled:e.setNotificationSoundEnabled,fetchAvailableShells:e.fetchAvailableShells}))),{permission:h,requestPermission:g,supported:_}=he(),{theme:v,setTheme:y}=ue(),{t:b,i18n:x}=A(),S=oe(e=>e.user?.role===`admin`),[C,w]=(0,Z.useState)({}),[T,E]=(0,Z.useState)({}),[ee,D]=(0,Z.useState)({}),[O,te]=(0,Z.useState)(``),[k,ne]=(0,Z.useState)(`587`),[j,M]=(0,Z.useState)(``),[N,P]=(0,Z.useState)(``),[F,re]=(0,Z.useState)(``),[L,R]=(0,Z.useState)(!1),[se,ce]=(0,Z.useState)(`none`),[de,fe]=(0,Z.useState)(!1),[ge,ve]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{I.getProfile().then(e=>{if(e.isOk()&&e.value){let t=e.value;E(t.providerKeys??{})}}),w({}),I.getSmtpSettings().then(e=>{e.isOk()&&(te(e.value.host),ne(e.value.port),M(e.value.user),re(e.value.from),R(e.value.hasPassword),ce(e.value.source))}),m()},[m]);let V=(0,Z.useCallback)(e=>{c(e),B.success(b(`settings.saved`),{id:`settings-saved`})},[c,b]),ye=(0,Z.useCallback)(e=>{l(e),B.success(b(`settings.saved`),{id:`settings-saved`})},[l,b]),be=(0,Z.useCallback)(e=>{u(e),B.success(b(`settings.saved`),{id:`settings-saved`})},[u,b]),xe=(0,Z.useCallback)(e=>{y(e),I.updateProfile({theme:e}),B.success(b(`settings.saved`),{id:`settings-saved`})},[y,b]),Ce=(0,Z.useCallback)(e=>{d(e),B.success(b(`settings.saved`),{id:`settings-saved`})},[d,b]),we=(0,Z.useCallback)(async e=>{if(e&&(h===`granted`?`granted`:await g())!==`granted`){B.error(b(`settings.notificationsDenied`)),f(!1);return}f(e),B.success(b(`settings.saved`),{id:`settings-saved`})},[h,g,f,b]),Te=(0,Z.useCallback)(async()=>{if(!_){B.error(b(`settings.notificationsUnsupported`));return}let e=h;if(e!==`granted`&&(e=await g()),e!==`granted`){B.error(b(`settings.notificationsDenied`));return}let t=me(b(`settings.notificationsTestTitle`),b(`settings.notificationsTestBody`),{force:!0});t.ok?B.success(b(`settings.notificationsTestSent`)):B.error(b(`settings.notificationsTestFailed`,{reason:t.reason}))},[h,_,g,b]),Ee=(0,Z.useCallback)(e=>{p(e),e&&pe(),B.success(b(`settings.saved`),{id:`settings-saved`})},[p,b]),De=(0,Z.useCallback)(()=>{pe()},[]),Oe=(0,Z.useCallback)(e=>{x.changeLanguage(e),B.success(b(`settings.saved`),{id:`settings-saved`})},[x,b]),ke=(0,Z.useCallback)(async e=>{let t=C[e];if(!t)return;D(t=>({...t,[e]:!0}));let n=await I.updateProfile({providerKey:{id:e,value:t}});n.isOk()?(E(n.value.providerKeys??{}),w(t=>({...t,[e]:``})),B.success(b(`profile.tokenSaved`))):B.error(b(`profile.saveFailed`)),D(t=>({...t,[e]:!1}))},[C,b]),J=(0,Z.useCallback)(async e=>{D(t=>({...t,[e]:!0}));let t=await I.updateProfile({providerKey:{id:e,value:null}});t.isOk()&&(E(t.value.providerKeys??{}),w(t=>({...t,[e]:``})),B.success(b(`profile.tokenCleared`))),D(t=>({...t,[e]:!1}))},[b]),Ae=(0,Z.useCallback)(async()=>{fe(!0),(await I.updateSmtpSettings({host:O,port:k,user:j,pass:N||void 0,from:F})).isOk()?(B.success(`SMTP settings saved`),N&&R(!0),ce(`database`),P(``)):B.error(`Failed to save SMTP settings`),fe(!1)},[O,k,j,N,F]),je=(0,Z.useCallback)(async()=>{ve(!0);let e=await I.testSmtpSettings();e.isOk()?B.success(`Test email sent to ${e.value.sentTo}`):B.error(`Failed to send test email. Check your SMTP settings.`),ve(!1)},[]);return!S&&Re.has(e)?(0,Q.jsx)(Se,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(`div`,{className:`max-w-4xl px-8 py-8`,children:(0,Q.jsx)(`p`,{className:`text-muted-foreground text-sm`,"data-testid":`preferences-admin-only`,children:`This setting is only available to administrators.`})})}):(0,Q.jsx)(Se,{className:`min-h-0 flex-1`,children:(0,Q.jsxs)(`div`,{className:`max-w-4xl px-8 py-8`,children:[e===`general`&&(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{className:`settings-card`,children:[(0,Q.jsx)(X,{title:b(`settings.defaultEditor`),description:b(`settings.defaultEditorDesc`),children:(0,Q.jsxs)(K,{value:t,onValueChange:V,children:[(0,Q.jsx)(W,{className:`w-[140px]`,"data-testid":`preferences-editor-select`,children:(0,Q.jsx)(U,{})}),(0,Q.jsx)(H,{children:Object.entries(ie).map(([e,t])=>(0,Q.jsx)(q,{value:e,children:t},e))})]})}),(0,Q.jsx)(X,{title:b(`settings.useInternalEditor`),description:b(`settings.useInternalEditorDesc`),children:(0,Q.jsx)(G,{checked:n,onCheckedChange:e=>ye(!!e),"data-testid":`preferences-internal-editor`})}),(0,Q.jsx)(X,{title:b(`settings.language`),description:b(`settings.languageDesc`),children:(0,Q.jsxs)(K,{value:x.language,onValueChange:Oe,children:[(0,Q.jsx)(W,{className:`w-[140px]`,"data-testid":`preferences-language-select`,children:(0,Q.jsx)(U,{})}),(0,Q.jsx)(H,{children:Object.keys(x.options.resources??{}).map(e=>(0,Q.jsx)(q,{value:e,children:Ft(e)},e))})]})}),(0,Q.jsx)(X,{title:b(`settings.terminalShell`),description:b(`settings.terminalShellDesc`),children:(0,Q.jsxs)(K,{value:r,onValueChange:be,children:[(0,Q.jsx)(W,{className:`w-[160px]`,"data-testid":`preferences-shell-select`,children:(0,Q.jsx)(U,{})}),(0,Q.jsxs)(H,{children:[(0,Q.jsx)(q,{value:`default`,children:b(`settings.shellDefault`)}),i.map(e=>(0,Q.jsx)(q,{value:e.id,children:e.label},e.id))]})]})}),(0,Q.jsx)(X,{title:b(`settings.notifications`),description:b(_?h===`denied`?`settings.notificationsBlocked`:`settings.notificationsDesc`:`settings.notificationsUnsupported`),children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(z,{size:`sm`,variant:`outline`,onClick:Te,disabled:!_||h===`denied`,"data-testid":`preferences-notifications-test`,children:b(`settings.notificationsTest`)}),(0,Q.jsx)(G,{checked:o&&h===`granted`,disabled:!_||h===`denied`,onCheckedChange:e=>we(!!e),"data-testid":`preferences-notifications-toggle`})]})}),(0,Q.jsx)(X,{title:b(`settings.notificationsSound`),description:b(`settings.notificationsSoundDesc`),children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(z,{size:`sm`,variant:`outline`,onClick:De,"data-testid":`preferences-notifications-sound-test`,children:b(`settings.notificationsTest`)}),(0,Q.jsx)(G,{checked:s,onCheckedChange:e=>Ee(!!e),"data-testid":`preferences-notifications-sound-toggle`})]})})]})}),e===`models`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:b(`settings.promptModelVisibilityDesc`)}),(0,Q.jsx)(`div`,{className:`settings-card overflow-visible!`,children:(0,Q.jsx)(Ve,{showHeader:!1})})]}),e===`appearance`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:b(`settings.themeDesc`)}),(0,Q.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:Mt.map(e=>(0,Q.jsx)(It,{option:e,selected:(v??`one-dark`)===e.value,onClick:()=>xe(e.value),t:b},e.value))}),(0,Q.jsx)(`h3`,{className:`settings-section-header mt-6`,children:b(`settings.fontSize`)}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsx)(X,{title:b(`settings.fontSize`),description:b(`settings.fontSizeDesc`),children:(0,Q.jsxs)(K,{value:a,onValueChange:Ce,children:[(0,Q.jsx)(W,{className:`w-[140px]`,"data-testid":`preferences-font-size-select`,children:(0,Q.jsx)(U,{})}),(0,Q.jsxs)(H,{children:[(0,Q.jsx)(q,{value:`small`,children:b(`settings.fontSizeSmall`)}),(0,Q.jsx)(q,{value:`default`,children:b(`settings.fontSizeDefault`)}),(0,Q.jsx)(q,{value:`large`,children:b(`settings.fontSizeLarge`)})]})]})})})]}),e===`github`&&(0,Q.jsx)(zt,{id:`github`,label:`GitHub token`,title:b(`profile.githubTokenLabel`),description:b(`profile.githubTokenDesc`),keyInputs:C,keyPresence:T,keySaving:ee,setKeyInputs:w,handleSave:ke,handleClear:J,saveTestId:`preferences-save-token`,inputTestId:`preferences-github-token`,clearTestId:`preferences-clear-token`,t:b}),e===`ai-keys`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:`Configure API keys for AI providers. Keys are encrypted at rest.`}),(0,Q.jsx)(`div`,{className:`settings-card divide-border space-y-0 divide-y`,children:le.filter(e=>e.id!==`github`&&e.id!==`assemblyai`).map(e=>(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsx)(`p`,{className:`settings-row-title`,children:e.label}),(0,Q.jsxs)(`p`,{className:`settings-row-desc mb-2`,children:[`Get your key at`,` `,(0,Q.jsx)(`a`,{href:e.helpUrl,target:`_blank`,rel:`noreferrer`,className:`text-primary hover:underline`,children:new URL(e.helpUrl).hostname}),`. `,e.description]}),(0,Q.jsx)(Rt,{id:e.id,label:e.label,keyInputs:C,keyPresence:T,keySaving:ee,setKeyInputs:w,handleSave:ke,handleClear:J,t:b})]},e.id))})]}),e===`speech`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:`Configure an AssemblyAI API key to enable voice dictation in the prompt input.`}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsx)(`p`,{className:`settings-row-title`,children:`AssemblyAI API Key`}),(0,Q.jsxs)(`p`,{className:`settings-row-desc mb-2`,children:[`Get your key at`,` `,(0,Q.jsx)(`a`,{href:`https://www.assemblyai.com/dashboard/signup`,target:`_blank`,rel:`noreferrer`,className:`text-primary hover:underline`,children:`assemblyai.com`}),`. The key is encrypted at rest.`]}),(0,Q.jsx)(Rt,{id:`assemblyai`,label:`AssemblyAI API Key`,keyInputs:C,keyPresence:T,keySaving:ee,setKeyInputs:w,handleSave:ke,handleClear:J,t:b})]})})]}),e===`users`&&(0,Q.jsx)(jt,{}),e===`organizations`&&(0,Q.jsx)(lt,{}),e===`team-members`&&(0,Q.jsx)(At,{}),e===`runners`&&(0,Q.jsx)(xt,{}),e===`agent-templates`&&(0,Q.jsx)(Je,{}),e===`extensions`&&(0,Q.jsx)(st,{}),e===`providers`&&(0,Q.jsx)(pt,{}),e===`system`&&(0,Q.jsx)(Tt,{}),e===`email`&&(0,Q.jsx)(Bt,{smtpHost:O,smtpPort:k,smtpUser:j,smtpPass:N,smtpFrom:F,smtpHasPassword:L,smtpSource:se,smtpSaving:de,smtpTesting:ge,setSmtpHost:te,setSmtpPort:ne,setSmtpUser:M,setSmtpPass:P,setSmtpFrom:re,handleSaveSmtp:Ae,handleTestSmtp:je})]})})}function Rt({id:e,label:t,keyInputs:n,keyPresence:r,keySaving:i,setKeyInputs:a,handleSave:o,handleClear:s,t:c}){return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(J,{type:`password`,value:n[e]??``,onChange:t=>a(n=>({...n,[e]:t.target.value})),"data-testid":`preferences-${e}-key`,placeholder:r[e]?c(`profile.tokenSaved`):`Enter your ${t}`,className:`text-sm`}),(0,Q.jsx)(z,{size:`sm`,onClick:()=>o(e),disabled:!n[e]||!!i[e],"data-testid":`preferences-save-${e}-key`,children:i[e]?c(`common.saving`):c(`common.save`)}),r[e]&&(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,className:`text-destructive hover:text-destructive shrink-0 text-xs`,onClick:()=>s(e),disabled:!!i[e],"data-testid":`preferences-clear-${e}-key`,children:c(`profile.clearToken`)})]})}function zt({id:e,title:t,description:n,keyInputs:r,keyPresence:i,keySaving:a,setKeyInputs:o,handleSave:s,handleClear:c,saveTestId:l,inputTestId:u,clearTestId:d,t:f}){return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`px-4 py-3.5`,children:[(0,Q.jsx)(`p`,{className:`settings-row-title`,children:t}),(0,Q.jsx)(`p`,{className:`settings-row-desc mb-2`,children:n}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(J,{type:`password`,value:r[e]??``,onChange:t=>o(n=>({...n,[e]:t.target.value})),"data-testid":u,placeholder:i[e]?f(`profile.tokenSaved`):f(`profile.tokenPlaceholder`),className:`text-sm`}),(0,Q.jsx)(z,{size:`sm`,onClick:()=>s(e),disabled:!r[e]||!!a[e],"data-testid":l,children:a[e]?f(`common.saving`):f(`common.save`)}),i[e]&&(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,className:`text-destructive hover:text-destructive shrink-0 text-xs`,onClick:()=>c(e),disabled:!!a[e],"data-testid":d,children:f(`profile.clearToken`)})]})]})})})}function Bt({smtpHost:e,smtpPort:t,smtpUser:n,smtpPass:r,smtpFrom:i,smtpHasPassword:a,smtpSource:o,smtpSaving:s,smtpTesting:c,setSmtpHost:u,setSmtpPort:d,setSmtpUser:f,setSmtpPass:p,setSmtpFrom:m,handleSaveSmtp:h,handleTestSmtp:g}){return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:o!==`none`&&(0,Q.jsx)(`span`,{className:R(`rounded-full px-2 py-0.5 text-[10px] font-medium`,o===`database`?`bg-primary/10 text-primary`:`bg-muted text-muted-foreground`),"data-testid":`preferences-smtp-status`,children:o===`database`?`Configured`:`Env vars`})}),(0,Q.jsx)(`p`,{className:`text-muted-foreground px-1 pb-3 text-sm`,children:`Used for sending team invitation emails. Set via env vars (SMTP_HOST, SMTP_USER, SMTP_PASS) or configure below.`}),(0,Q.jsx)(`div`,{className:`settings-card`,children:(0,Q.jsxs)(`div`,{className:`space-y-3 px-4 py-3.5`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-[1fr_80px] gap-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Host`}),(0,Q.jsx)(J,{value:e,onChange:e=>u(e.target.value),placeholder:`smtp.gmail.com`,className:`text-sm`,"data-testid":`preferences-smtp-host`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Port`}),(0,Q.jsx)(J,{value:t,onChange:e=>d(e.target.value),placeholder:`587`,className:`text-sm`,"data-testid":`preferences-smtp-port`})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Username`}),(0,Q.jsx)(J,{value:n,onChange:e=>f(e.target.value),placeholder:`you@example.com`,className:`text-sm`,"data-testid":`preferences-smtp-user`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`Password`}),(0,Q.jsx)(J,{type:`password`,value:r,onChange:e=>p(e.target.value),placeholder:a?`Password saved (enter new to replace)`:`App password or SMTP password`,className:`text-sm`,"data-testid":`preferences-smtp-pass`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-muted-foreground mb-1 block text-xs`,children:`From address`}),(0,Q.jsx)(J,{value:i,onChange:e=>m(e.target.value),placeholder:`noreply@example.com`,className:`text-sm`,"data-testid":`preferences-smtp-from`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Q.jsxs)(z,{size:`sm`,onClick:h,disabled:!e||!n||s,"data-testid":`preferences-smtp-save`,children:[(0,Q.jsx)(l,{className:`icon-sm mr-1.5`}),s?`Saving...`:`Save SMTP`]}),(0,Q.jsxs)(z,{size:`sm`,variant:`outline`,onClick:g,disabled:o===`none`||c,"data-testid":`preferences-smtp-test`,children:[(0,Q.jsx)(te,{className:`icon-sm mr-1.5`}),c?`Sending...`:`Send Test Email`]})]})]})})]})}function Vt(){let{t:e}=A(),t=Oe(e=>e.activePreferencesPage);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col`,children:[(0,Q.jsx)(`div`,{className:`border-border border-b px-4 py-2`,children:(0,Q.jsx)(`div`,{className:`flex min-h-8 items-center`,children:(0,Q.jsx)(ye,{children:(0,Q.jsx)(be,{children:(0,Q.jsx)(Ce,{children:(0,Q.jsx)(xe,{className:`truncate text-sm`,children:Le(t,e)})})})})})}),(0,Q.jsx)(Lt,{activePreferencesPage:t})]})}export{Vt as GeneralSettingsView};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{Ct as t,Lt as n,i as r,jr as i,yr as a,zn as o,zr as s}from"./icons-sqwAEN28.js";import{o as c}from"./markdown-DBtwZWLP.js";import{t as l}from"./useTranslation-DAPPK3Hy.js";import{lt as u}from"./index-BsxcqNXe.js";import{t as d}from"./button-DeEOU1Fb.js";import{$r as f,Gr as p,Jr as m,Xr as h,qr as g}from"./items-_g3-I08l.js";var _=e(s(),1),v=e(c(),1);function y(e){let t=e/1e3,n=Math.floor(t/60),r=t%60;return n>0?`${n}:${Math.floor(r).toString().padStart(2,`0`)}`:`${r.toFixed(1)}s`}function b(e,t){let n=(0,_.useRef)(new Map),r=(0,_.useRef)(new Map),[,i]=(0,_.useState)(0);(0,_.useEffect)(()=>{t&&(n.current.clear(),r.current.clear())},[t]),(0,_.useEffect)(()=>{let t=Date.now(),i=n.current,a=r.current;for(let n of e)n.status===`running`&&!i.has(n.id)&&(i.set(n.id,n.startedAt??t),a.delete(n.id)),(n.status===`completed`||n.status===`failed`)&&!a.has(n.id)&&(!i.has(n.id)&&n.startedAt&&i.set(n.id,n.startedAt),i.has(n.id)&&a.set(n.id,n.completedAt??t)),n.status===`pending`&&(i.delete(n.id),a.delete(n.id))},[e]);let a=e.some(e=>e.status===`running`);return(0,_.useEffect)(()=>{if(!a)return;let e=setInterval(()=>i(e=>e+1),100);return()=>clearInterval(e)},[a]),e=>{let t=n.current.get(e);return t==null?null:(r.current.get(e)??Date.now())-t}}function x(e,t){let[,n]=(0,_.useState)(0),r=e.some(e=>e.status===`running`);(0,_.useEffect)(()=>{if(!r)return;let e=setInterval(()=>n(e=>e+1),100);return()=>clearInterval(e)},[r]);let i=0;for(let n of e){let e=t(n.id);e!=null&&(i+=e)}return i}function S({subItems:e,parentStatus:n}){return n===`pending`?null:(0,v.jsx)(`div`,{className:`mt-1 space-y-0.5 pl-1`,children:e.map((e,n)=>(0,v.jsxs)(`div`,{className:u(`flex items-center gap-1.5 text-[11px]`,e.status===`completed`&&`text-muted-foreground`,e.status===`running`&&`text-foreground`,e.status===`failed`&&`text-destructive`,e.status===`pending`&&`text-muted-foreground/40`),children:[(0,v.jsxs)(`div`,{className:`shrink-0`,children:[e.status===`completed`&&(0,v.jsx)(a,{className:`icon-xs text-emerald-500`}),e.status===`running`&&(0,v.jsx)(i,{className:`icon-xs text-primary`}),e.status===`failed`&&(0,v.jsx)(r,{className:`icon-xs text-destructive`}),e.status===`pending`&&(0,v.jsx)(t,{className:`icon-xs text-muted-foreground/30`})]}),(0,v.jsx)(`span`,{className:u(`truncate font-mono`,e.status===`running`&&`font-medium`),children:e.label}),e.error&&(0,v.jsx)(`pre`,{className:`bg-destructive/5 text-destructive/80 mt-0.5 max-h-60 overflow-auto rounded p-1.5 font-mono text-[11px] wrap-break-word whitespace-pre-wrap`,children:e.error})]},n))})}function C({open:e,onOpenChange:t,steps:i,title:s,autoClose:c}){let{t:C}=l(),w=i.some(e=>e.status===`running`),T=i.some(e=>e.status===`failed`),E=i.length>0&&!w&&(i.every(e=>e.status===`completed`||e.status===`failed`)||T),D=(0,_.useMemo)(()=>i.filter(e=>e.status!==`pending`),[i]),O=b(i,e),k=x(i,O),A=E&&(!c||T);return(0,v.jsx)(p,{open:e,onOpenChange:E?t:void 0,children:(0,v.jsxs)(g,{className:u(`flex max-h-[85vh] w-[calc(100vw-2rem)] max-w-lg flex-col gap-4 overflow-hidden [&>button.absolute]:hidden`,T&&`max-w-2xl`),onPointerDownOutside:e=>{E||e.preventDefault()},children:[(0,v.jsxs)(h,{className:`shrink-0`,children:[(0,v.jsx)(f,{className:`text-sm`,children:s}),(0,v.jsx)(m,{className:`sr-only`,children:C(`review.progress.description`,`Git operation progress`)})]}),(0,v.jsx)(`div`,{className:`min-h-0 flex-1 space-y-2 overflow-y-auto`,children:D.map(e=>{let t=O(e.id);return(0,v.jsxs)(`div`,{className:u(`flex items-start gap-2.5 rounded-md px-2 py-1 transition-colors`,e.status===`running`&&`bg-primary/8`),children:[(0,v.jsxs)(`div`,{className:`mt-0.5 shrink-0`,children:[e.status===`completed`&&(0,v.jsx)(a,{className:`icon-base text-emerald-500`}),e.status===`running`&&(0,v.jsx)(n,{className:`icon-base text-primary animate-spin`}),e.status===`failed`&&(0,v.jsx)(r,{className:`icon-base text-destructive`})]}),(0,v.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,v.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,v.jsx)(`span`,{className:u(`text-xs`,e.status===`completed`&&`text-muted-foreground`,e.status===`running`&&`text-foreground font-medium`,e.status===`failed`&&`text-destructive font-medium`),children:e.label}),t!=null&&(0,v.jsx)(`span`,{className:`text-muted-foreground/60 shrink-0 text-[10px] tabular-nums`,children:y(t)})]}),e.url&&e.status===`completed`&&(0,v.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary mt-0.5 flex items-center gap-1 text-[11px] hover:underline`,"data-testid":`git-progress-pr-link`,children:[(0,v.jsx)(o,{className:`icon-xs`}),e.url]}),e.subItems&&e.subItems.length>0&&(0,v.jsx)(S,{subItems:e.subItems,parentStatus:e.status}),e.error&&!(e.subItems&&e.subItems.length>0)&&(0,v.jsx)(`pre`,{className:`bg-destructive/5 text-destructive/80 mt-0.5 max-h-60 overflow-auto rounded p-1.5 font-mono text-[11px] wrap-break-word whitespace-pre-wrap`,children:e.error})]})]},e.id)})}),(0,v.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-2`,children:[(0,v.jsx)(`span`,{className:`text-muted-foreground/50 text-[10px] tabular-nums`,children:y(k)}),A&&(0,v.jsx)(d,{size:`sm`,variant:T?`outline`:`default`,onClick:()=>t(!1),"data-testid":`git-progress-done`,children:T?C(`review.progress.accept`,`Accept`):C(`review.progress.done`,`Done`)})]})]})})}export{x as a,b as i,S as n,y as r,C as t};
1
+ import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{Ct as t,Lt as n,i as r,jr as i,yr as a,zn as o,zr as s}from"./icons-sqwAEN28.js";import{o as c}from"./markdown-DBtwZWLP.js";import{t as l}from"./useTranslation-DAPPK3Hy.js";import{lt as u}from"./index-DCJpZz6M.js";import{t as d}from"./button-CZ967bB8.js";import{$r as f,Gr as p,Jr as m,Xr as h,qr as g}from"./items-azeOGVff.js";var _=e(s(),1),v=e(c(),1);function y(e){let t=e/1e3,n=Math.floor(t/60),r=t%60;return n>0?`${n}:${Math.floor(r).toString().padStart(2,`0`)}`:`${r.toFixed(1)}s`}function b(e,t){let n=(0,_.useRef)(new Map),r=(0,_.useRef)(new Map),[,i]=(0,_.useState)(0);(0,_.useEffect)(()=>{t&&(n.current.clear(),r.current.clear())},[t]),(0,_.useEffect)(()=>{let t=Date.now(),i=n.current,a=r.current;for(let n of e)n.status===`running`&&!i.has(n.id)&&(i.set(n.id,n.startedAt??t),a.delete(n.id)),(n.status===`completed`||n.status===`failed`)&&!a.has(n.id)&&(!i.has(n.id)&&n.startedAt&&i.set(n.id,n.startedAt),i.has(n.id)&&a.set(n.id,n.completedAt??t)),n.status===`pending`&&(i.delete(n.id),a.delete(n.id))},[e]);let a=e.some(e=>e.status===`running`);return(0,_.useEffect)(()=>{if(!a)return;let e=setInterval(()=>i(e=>e+1),100);return()=>clearInterval(e)},[a]),e=>{let t=n.current.get(e);return t==null?null:(r.current.get(e)??Date.now())-t}}function x(e,t){let[,n]=(0,_.useState)(0),r=e.some(e=>e.status===`running`);(0,_.useEffect)(()=>{if(!r)return;let e=setInterval(()=>n(e=>e+1),100);return()=>clearInterval(e)},[r]);let i=0;for(let n of e){let e=t(n.id);e!=null&&(i+=e)}return i}function S({subItems:e,parentStatus:n}){return n===`pending`?null:(0,v.jsx)(`div`,{className:`mt-1 space-y-0.5 pl-1`,children:e.map((e,n)=>(0,v.jsxs)(`div`,{className:u(`flex items-center gap-1.5 text-[11px]`,e.status===`completed`&&`text-muted-foreground`,e.status===`running`&&`text-foreground`,e.status===`failed`&&`text-destructive`,e.status===`pending`&&`text-muted-foreground/40`),children:[(0,v.jsxs)(`div`,{className:`shrink-0`,children:[e.status===`completed`&&(0,v.jsx)(a,{className:`icon-xs text-emerald-500`}),e.status===`running`&&(0,v.jsx)(i,{className:`icon-xs text-primary`}),e.status===`failed`&&(0,v.jsx)(r,{className:`icon-xs text-destructive`}),e.status===`pending`&&(0,v.jsx)(t,{className:`icon-xs text-muted-foreground/30`})]}),(0,v.jsx)(`span`,{className:u(`truncate font-mono`,e.status===`running`&&`font-medium`),children:e.label}),e.error&&(0,v.jsx)(`pre`,{className:`bg-destructive/5 text-destructive/80 mt-0.5 max-h-60 overflow-auto rounded p-1.5 font-mono text-[11px] wrap-break-word whitespace-pre-wrap`,children:e.error})]},n))})}function C({open:e,onOpenChange:t,steps:i,title:s,autoClose:c}){let{t:C}=l(),w=i.some(e=>e.status===`running`),T=i.some(e=>e.status===`failed`),E=i.length>0&&!w&&(i.every(e=>e.status===`completed`||e.status===`failed`)||T),D=(0,_.useMemo)(()=>i.filter(e=>e.status!==`pending`),[i]),O=b(i,e),k=x(i,O),A=E&&(!c||T);return(0,v.jsx)(p,{open:e,onOpenChange:E?t:void 0,children:(0,v.jsxs)(g,{className:u(`flex max-h-[85vh] w-[calc(100vw-2rem)] max-w-lg flex-col gap-4 overflow-hidden [&>button.absolute]:hidden`,T&&`max-w-2xl`),onPointerDownOutside:e=>{E||e.preventDefault()},children:[(0,v.jsxs)(h,{className:`shrink-0`,children:[(0,v.jsx)(f,{className:`text-sm`,children:s}),(0,v.jsx)(m,{className:`sr-only`,children:C(`review.progress.description`,`Git operation progress`)})]}),(0,v.jsx)(`div`,{className:`min-h-0 flex-1 space-y-2 overflow-y-auto`,children:D.map(e=>{let t=O(e.id);return(0,v.jsxs)(`div`,{className:u(`flex items-start gap-2.5 rounded-md px-2 py-1 transition-colors`,e.status===`running`&&`bg-primary/8`),children:[(0,v.jsxs)(`div`,{className:`mt-0.5 shrink-0`,children:[e.status===`completed`&&(0,v.jsx)(a,{className:`icon-base text-emerald-500`}),e.status===`running`&&(0,v.jsx)(n,{className:`icon-base text-primary animate-spin`}),e.status===`failed`&&(0,v.jsx)(r,{className:`icon-base text-destructive`})]}),(0,v.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,v.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,v.jsx)(`span`,{className:u(`text-xs`,e.status===`completed`&&`text-muted-foreground`,e.status===`running`&&`text-foreground font-medium`,e.status===`failed`&&`text-destructive font-medium`),children:e.label}),t!=null&&(0,v.jsx)(`span`,{className:`text-muted-foreground/60 shrink-0 text-[10px] tabular-nums`,children:y(t)})]}),e.url&&e.status===`completed`&&(0,v.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary mt-0.5 flex items-center gap-1 text-[11px] hover:underline`,"data-testid":`git-progress-pr-link`,children:[(0,v.jsx)(o,{className:`icon-xs`}),e.url]}),e.subItems&&e.subItems.length>0&&(0,v.jsx)(S,{subItems:e.subItems,parentStatus:e.status}),e.error&&!(e.subItems&&e.subItems.length>0)&&(0,v.jsx)(`pre`,{className:`bg-destructive/5 text-destructive/80 mt-0.5 max-h-60 overflow-auto rounded p-1.5 font-mono text-[11px] wrap-break-word whitespace-pre-wrap`,children:e.error})]})]},e.id)})}),(0,v.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-2`,children:[(0,v.jsx)(`span`,{className:`text-muted-foreground/50 text-[10px] tabular-nums`,children:y(k)}),A&&(0,v.jsx)(d,{size:`sm`,variant:T?`outline`:`default`,onClick:()=>t(!1),"data-testid":`git-progress-done`,children:T?C(`review.progress.accept`,`Accept`):C(`review.progress.done`,`Done`)})]})]})})}export{x as a,b as i,S as n,y as r,C as t};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{Lt as t,Q as n,an as r,i,in as a,k as o,zr as s,zt as c}from"./icons-sqwAEN28.js";import{o as l}from"./markdown-DBtwZWLP.js";import{t as u}from"./useTranslation-DAPPK3Hy.js";import{j as d,lt as f}from"./index-BsxcqNXe.js";import{t as p}from"./button-DeEOU1Fb.js";import{$ as m,An as h,Dr as g,Fn as _,It as v,J as y,Lt as b,Mn as x,Q as S,Un as C,Ur as w,Zt as T,_t as E,et as D,j as O,jn as k,m as A,nn as j,nt as M,rt as N,tt as P,yr as F}from"./items-_g3-I08l.js";import{t as I}from"./loading-state-BQjalkhM.js";import{n as L,r as R,t as z}from"./adapter-g71mvnZo.js";import{n as B,t as V}from"./ProjectHeader-Bf1gaA1F.js";import{t as H}from"./tooltip-icon-button-z_YicoMI.js";import{i as U,n as W,r as G,t as K}from"./use-thread-search-BIXj6zRV.js";import{t as ee}from"./use-minute-tick-C-e4HaZD.js";import{t as te}from"./drag-preview-D7uMScNk.js";var q=e(s(),1),J=e(l(),1);function ne({open:e,onOpenChange:t,projectId:n,onSelect:r,gridThreadIds:i}){let{t:a}=u(),o=v(n),s=e=>{r(e),t(!1)};return(0,J.jsxs)(S,{open:e,onOpenChange:t,children:[(0,J.jsx)(P,{"data-testid":`grid-thread-picker-search`,placeholder:a(`live.searchThread`,`Search thread...`)}),(0,J.jsxs)(N,{children:[(0,J.jsx)(m,{children:a(`live.noThreads`,`No threads`)}),(0,J.jsx)(D,{heading:a(`live.pickThreadTitle`,`Load an existing thread`),children:o.map(e=>{let{icon:t,className:n}=j[e.status]??j.idle,r=i?.has(e.id);return(0,J.jsxs)(M,{"data-testid":`grid-thread-pick-${e.id}`,value:`${e.title} ${e.id}`,onSelect:()=>s(e.id),children:[(0,J.jsx)(t,{className:f(`size-3.5 shrink-0`,n)}),e.title?(0,J.jsx)(A,{as:`span`,title:e.title,className:`text-sm`,containerClassName:`min-w-0 flex-1`}):(0,J.jsx)(`span`,{className:`truncate`,children:a(`common.untitled`,`Untitled`)}),r&&(0,J.jsx)(`span`,{className:`text-muted-foreground ml-auto shrink-0 text-[10px]`,children:a(`live.inGrid`,`in grid`)})]},e.id)})})]})]})}var re=(0,q.memo)(function({cellIndex:e,onCreated:t,onLoadExisting:r,initialProjectId:i,onConsumePreset:a,onRequestPickProject:s,gridThreadIds:l}){let{t:d}=u(),[f,m]=(0,q.useState)(i??null),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)(!1);(0,q.useEffect)(()=>{i&&i!==f&&(m(i),g(!1),a?.())},[i]);let y=(0,q.useCallback)(()=>{m(null),g(!1)},[]);return h?(0,J.jsx)(`div`,{className:`border-border/60 bg-muted/10 flex h-full w-full flex-col rounded-sm border-2 border-dashed`,"data-testid":`grid-empty-cell-${e}`,children:(0,J.jsx)(U,{isScratchOverride:!0,onCreated:t,onCancel:y})}):f?(0,J.jsxs)(`div`,{className:`border-border/60 bg-muted/10 flex h-full w-full flex-col rounded-sm border-2 border-dashed`,"data-testid":`grid-empty-cell-${e}`,children:[(0,J.jsx)(U,{projectIdOverride:f,onCreated:t,onCancel:y}),(0,J.jsx)(`div`,{className:`border-border/40 flex shrink-0 items-center justify-center border-t px-3 py-1.5`,children:(0,J.jsxs)(p,{variant:`ghost`,size:`sm`,className:`text-muted-foreground h-7`,"data-testid":`grid-load-existing-${e}`,onClick:()=>v(!0),children:[(0,J.jsx)(c,{className:`icon-sm`}),d(`live.loadExisting`,`Load existing thread`)]})}),(0,J.jsx)(ne,{open:_,onOpenChange:v,projectId:f,gridThreadIds:l,onSelect:r})]}):(0,J.jsxs)(`div`,{className:`border-border/60 bg-muted/10 hover:border-primary/50 hover:bg-muted/30 flex h-full w-full items-center justify-center gap-2 rounded-sm border-2 border-dashed p-4 transition-colors`,"data-testid":`grid-empty-cell-${e}`,children:[(0,J.jsxs)(p,{variant:`default`,size:`sm`,className:`h-7`,"data-testid":`grid-empty-new-${e}`,onClick:s,children:[(0,J.jsx)(n,{className:`icon-sm`}),d(`live.newThread`,`New thread`)]}),(0,J.jsxs)(p,{variant:`outline`,size:`sm`,className:`h-7`,"data-testid":`grid-empty-new-scratch-${e}`,onClick:()=>g(!0),children:[(0,J.jsx)(o,{className:`icon-sm`}),d(`live.newScratch`,`New scratch`)]})]})}),ie=(0,q.memo)(function({cellIndex:e,children:t}){let n=(0,q.useRef)(null),[r,i]=(0,q.useState)(!1);return(0,q.useEffect)(()=>{let t=n.current;if(t)return L({element:t,getData:()=>({type:`grid-cell`,cellIndex:e}),canDrop:({source:e})=>e.data.type===`grid-thread`,onDragEnter:()=>i(!0),onDragLeave:()=>i(!1),onDrop:()=>i(!1)})},[e]),(0,J.jsx)(`div`,{ref:n,className:f(`flex min-h-0 flex-1 flex-col`,r&&`rounded-sm ring-2 ring-primary`),"data-testid":`grid-drop-target-${e}`,children:t})}),Y=(0,q.memo)(function({insertIndex:e,isDragging:t,disabled:r}){let i=(0,q.useRef)(null),[a,o]=(0,q.useState)(!1);(0,q.useEffect)(()=>{let t=i.current;if(t)return L({element:t,getData:()=>({type:`grid-col-insert`,insertIndex:e}),canDrop:({source:e})=>!r&&e.data.type===`grid-thread`,onDragEnter:()=>o(!0),onDragLeave:()=>o(!1),onDrop:()=>o(!1)})},[e,r]);let s=t&&!r;return(0,J.jsx)(`div`,{ref:i,className:f(`shrink-0 self-stretch rounded-sm transition-all duration-150 overflow-hidden`,a?`w-10 bg-primary/60 ring-2 ring-primary`:s?`w-6 bg-primary/10 hover:bg-primary/20`:`w-1`),"data-testid":`grid-col-insert-${e}`,children:s&&(0,J.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,J.jsx)(n,{className:`text-primary/60 size-4`})})})});function ae({cols:e,rows:t,onChange:n}){let[i,a]=(0,q.useState)(0),[o,s]=(0,q.useState)(0),[c,l]=(0,q.useState)(!1),u=c&&i>0?i:e,d=c&&o>0?o:t;return(0,J.jsxs)(h,{open:c,onOpenChange:l,children:[(0,J.jsx)(x,{asChild:!0,children:(0,J.jsxs)(p,{variant:`ghost`,className:`h-6 min-w-0 gap-1.5 px-2 text-[10px]`,children:[(0,J.jsx)(r,{className:`icon-sm`}),e,`×`,t]})}),(0,J.jsxs)(k,{className:`w-auto p-3`,align:`start`,sideOffset:4,children:[(0,J.jsx)(`div`,{className:`grid gap-1`,style:{gridTemplateColumns:`repeat(5, 1fr)`},onMouseLeave:()=>{a(0),s(0)},children:Array.from({length:5},(e,t)=>Array.from({length:5},(e,r)=>(0,J.jsx)(`button`,{className:f(`w-5 h-5 rounded-sm border transition-colors`,r+1<=u&&t+1<=d?`bg-primary border-primary`:`bg-muted/40 border-border hover:border-muted-foreground/40`),onMouseEnter:()=>{a(r+1),s(t+1)},onClick:()=>{n(r+1,t+1),l(!1)}},`${r}-${t}`)))}),(0,J.jsxs)(`p`,{className:`text-muted-foreground mt-2 text-center text-[10px]`,children:[u,`×`,d]})]})]})}function oe({open:e,onOpenChange:t,onSelect:n,placeholder:r,title:i}){let{t:a}=u(),o=g(e=>e.projects),s=e=>{n(e),t(!1)};return(0,J.jsxs)(S,{open:e,onOpenChange:t,children:[(0,J.jsx)(P,{"data-testid":`grid-project-picker-search`,placeholder:r??a(`kanban.searchProject`,`Search project...`)}),(0,J.jsxs)(N,{children:[(0,J.jsx)(m,{children:a(`live.noProjects`,`No projects`)}),(0,J.jsx)(D,{heading:i??a(`live.pickProjectTitle`,`Select a project`),children:o.map(e=>(0,J.jsxs)(M,{"data-testid":`grid-project-pick-${e.id}`,value:`${e.name} ${e.path??``}`,onSelect:()=>s(e.id),children:[(0,J.jsx)(`span`,{className:`size-2.5 shrink-0 rounded-full`,style:{backgroundColor:e.color||_(e.name)}}),(0,J.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]})]})}var se=d(`ThreadColumn`),ce=(0,q.memo)(function({threadId:e,onRemove:n,onOpenLightbox:r}){let{t:o}=u(),s=(0,q.useRef)(null),c=(0,q.useRef)(null),l=(0,q.useRef)(null),[d,p]=(0,q.useState)(!1),m=F(t=>t.gridSelectedThreadId===e),h=F(e=>e.setGridSelectedThreadId),g=(0,q.useCallback)(()=>{h(e)},[h,e]),_=b(e=>e.registerLiveThread),v=b(e=>e.unregisterLiveThread);(0,q.useEffect)(()=>(_(e),()=>{v(e)}),[e,_,v]);let y=b(t=>t.threadDataById[e]??null),x=y===null;(0,q.useEffect)(()=>{let t=c.current,n=l.current;if(!(!t||!n))return z({element:n,getInitialData:()=>({type:`grid-thread`,threadId:e}),onGenerateDragPreview:({nativeSetDragImage:e})=>te({nativeSetDragImage:e,source:t}),onDragStart:()=>p(!0),onDrop:()=>p(!1)})},[e,x]);let{searchOpen:S,setSearchOpen:C,handleSearchNavigate:w,handleSearchClose:D}=K(s,e),k=(0,q.useRef)(!1);(0,q.useEffect)(()=>{let t=t=>{if(!t.ctrlKey||t.shiftKey||t.metaKey||t.altKey||t.key!==`f`&&t.key!==`F`)return;let n=t.target;if(n&&n.closest(`.xterm`))return;let r=c.current;if(!r||!(document.activeElement&&r.contains(document.activeElement))&&!k.current)return;t.preventDefault(),t.stopImmediatePropagation(),se.info({threadId:e},`shortcut.grid_thread_search`),C(!0);let i=r.querySelector(`[data-testid="grid-search-${e}-input"]`);i&&requestAnimationFrame(()=>i.focus())};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e,C]);let A=O(e=>e.status),M=T(y?.status??`idle`,A),N=j[M]?.icon??t,P=j[M]?.className??``;return x?(0,J.jsx)(`div`,{className:`border-border flex min-h-0 flex-1 rounded-sm border`,children:(0,J.jsx)(I,{testId:`grid-column-loading-${e}`})}):y?(0,J.jsx)(E,{threadId:e,children:(0,J.jsxs)(`div`,{ref:c,className:f(`group/col relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-sm border border-border`,d&&`opacity-50`,m&&`border-primary/25`),"data-testid":`grid-column-${e}`,"data-selected":m?`true`:void 0,onPointerDownCapture:g,onPointerEnter:()=>{k.current=!0},onPointerLeave:()=>{k.current=!1},children:[(0,J.jsx)(`div`,{ref:l,className:`shrink-0 cursor-grab active:cursor-grabbing`,children:(0,J.jsx)(V,{hideActions:!0,hideFiles:!0,hideTests:!0,hideStartup:!0,hideTerminal:!0,hideTimeline:!0,leading:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(a,{className:`icon-xs text-muted-foreground shrink-0`}),(0,J.jsx)(N,{className:f(`icon-sm shrink-0`,P)})]}),trailing:n?(0,J.jsx)(H,{tooltip:o(`live.removeFromGrid`,`Remove from grid`),onClick:n,className:`size-5 shrink-0 opacity-0 transition-opacity group-hover/col:opacity-100`,"data-testid":`grid-remove-${e}`,children:(0,J.jsx)(i,{className:`icon-xs`})}):void 0})}),(0,J.jsx)(W,{threadId:e,open:S,onClose:D,onNavigateToMessage:w,testIdPrefix:`grid-search-${e}`,className:`border-border bg-popover absolute top-9 right-2 z-30 gap-1.5 rounded-md border px-2 py-1.5 shadow-md`}),(0,J.jsx)(G,{streamRef:s,onOpenLightbox:r,className:`min-h-0 flex-1`})]})}):(0,J.jsx)(`div`,{className:`border-border text-muted-foreground flex min-h-0 flex-1 items-center justify-center rounded-sm border text-xs`,children:o(`thread.notFound`,`Thread not found`)})});function le(e,t,n){for(let r=0;r<n;r++)for(let n=0;n<t;n++){let i=e[String(r*t+n)];if(i)return i}return null}function ue({current:e,placedIds:t,firstPlaced:n,inited:r,prevHadThreads:i}){let a=e;a&&!t.has(a)&&(a=null);let o=t.size>0;return!a&&o&&(!r||!i&&o)&&(a=n),a}var X=`funny:grid-cells:v1`,de=X;function fe(){try{let e=localStorage.getItem(de);return e?JSON.parse(e):{}}catch{return{}}}var Z=d(`LiveColumnsView`),Q=`funny:grid-cols:v1`,$=`funny:grid-rows:v1`;function pe(){let{t:e}=u();ee();let t=g(e=>e.projects),r=b(e=>e.loadThreadsForProject),[i,a]=(0,q.useState)(()=>{let e=localStorage.getItem(Q);return e?Math.min(Math.max(Number(e),1),5):2}),[o,s]=(0,q.useState)(()=>{let e=localStorage.getItem($);return e?Math.min(Math.max(Number(e),1),5):2});(0,q.useEffect)(()=>{let e=b.getState();for(let n of t)e.threadIdsByProject[n.id]||r(n.id)},[(0,q.useMemo)(()=>t.map(e=>e.id).join(`,`),[t])]);let[c,l]=(0,q.useState)([]),[d,f]=(0,q.useState)(0),[m,h]=(0,q.useState)(!1),_=(0,q.useCallback)((e,t)=>{l(e),f(t),h(!0)},[]),[v,x]=(0,q.useState)(fe),S=(0,q.useMemo)(()=>new Set(Object.values(v)),[v]),T=F(e=>e.gridSelectedThreadId),D=F(e=>e.setGridSelectedThreadId),O=C(e=>e.fetchForThread),k=(0,q.useRef)(!1),A=(0,q.useRef)(!1);(0,q.useEffect)(()=>{let e=F.getState().gridSelectedThreadId,t=ue({current:e,placedIds:S,firstPlaced:le(v,i,o),inited:k.current,prevHadThreads:A.current});t!==e&&D(t),k.current=!0,A.current=S.size>0},[S,v,i,o,D]),(0,q.useEffect)(()=>{T&&O(T)},[T,O]);let[j,M]=(0,q.useState)({}),[N,P]=(0,q.useState)(null),I=(0,q.useCallback)(e=>{M(t=>{if(!(e in t))return t;let n={...t};return delete n[e],n})},[]),L=(0,q.useCallback)((e,t)=>{M(n=>({...n,[e]:t}))},[]),z=(0,q.useCallback)((e,t)=>{x(n=>{let r={...n};for(let[e,n]of Object.entries(r))n===t&&delete r[e];return r[String(e)]=t,localStorage.setItem(X,JSON.stringify(r)),r}),D(t)},[D]),V=(0,q.useCallback)(e=>{x(t=>{let n={...t};delete n[String(e)];let r=e%i;if(i<=1||!Array.from({length:o}).every((e,t)=>{let a=t*i+r;return!n[String(a)]}))return localStorage.setItem(X,JSON.stringify(n)),n;let s=i-1,c={};for(let[e,t]of Object.entries(n)){let n=Number(e),a=n%i,o=Math.floor(n/i);if(a===r)continue;let l=a>r?a-1:a;c[String(o*s+l)]=t}return a(s),M(e=>{let t={};for(let[n,a]of Object.entries(e)){let e=Number(n),o=e%i,c=Math.floor(e/i);if(o===r)continue;let l=o>r?o-1:o;t[c*s+l]=a}return t}),localStorage.setItem(Q,String(s)),localStorage.setItem(X,JSON.stringify(c)),c})},[i,o]),H=(0,q.useCallback)(t=>{if(i>=5){w.info(e(`live.gridFull`,`Grid is full`));return}let n=i,r=n+1,o=n;x(e=>{let t={};for(let[i,a]of Object.entries(e)){let e=Number(i),o=e%n,s=Math.floor(e/n);t[String(s*r+o)]=a}return localStorage.setItem(X,JSON.stringify(t)),t}),M(e=>{let i={};for(let[t,a]of Object.entries(e)){let e=Number(t),o=e%n,s=Math.floor(e/n);i[s*r+o]=a}return i[o]=t,i}),a(r),localStorage.setItem(Q,String(r)),Z.info({projectId:t,cellIndex:o},`header preset project for new column`)},[i,e]),U=(0,q.useCallback)(e=>{let t=N;t&&(t.kind===`new-column`?H(e):L(t.cellIndex,e),P(null))},[N,H,L]);(0,q.useEffect)(()=>{let e=e=>{if(!e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||e.key!==`n`&&e.key!==`N`)return;let t=e.target?.tagName;t===`INPUT`||t===`TEXTAREA`||e.target?.isContentEditable||i>=5||(e.preventDefault(),e.stopImmediatePropagation(),Z.info(`shortcut.grid_new_thread`),P({kind:`new-column`}))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[i]);let[W,G]=(0,q.useState)(!1);return(0,q.useEffect)(()=>R({onDragStart:({source:e})=>{e.data.type===`grid-thread`&&G(!0)},onDrop:({source:t,location:n})=>{if(G(!1),t.data.type!==`grid-thread`)return;let r=n.current.dropTargets;if(!r.length)return;let o=r[0].data,s=t.data.threadId;if(o.type===`grid-cell`){let e=o.cellIndex;x(t=>{let n={...t},r;for(let[e,t]of Object.entries(n))t===s&&(r=e,delete n[e]);let i=n[String(e)];return i&&r&&(n[r]=i),n[String(e)]=s,localStorage.setItem(X,JSON.stringify(n)),n});return}if(o.type===`grid-col-insert`){let t=o.insertIndex;if(i>=5){w.info(e(`live.gridFull`,`Grid is full`));return}let n=i,r=n+1;x(e=>{let i={};for(let[a,o]of Object.entries(e)){if(o===s)continue;let e=Number(a),c=e%n,l=Math.floor(e/n),u=c<t?c:c+1,d=l*r+u;i[String(d)]=o}return i[String(t)]=s,localStorage.setItem(X,JSON.stringify(i)),i}),M(e=>{let i={};for(let[a,o]of Object.entries(e)){let e=Number(a),s=e%n,c=Math.floor(e/n),l=s<t?s:s+1;i[c*r+l]=o}return i}),a(r),localStorage.setItem(Q,String(r))}}}),[i,e]),(0,J.jsxs)(`div`,{className:`flex h-full min-w-0 flex-1 flex-col overflow-hidden`,"data-testid":`grid-view`,children:[(0,J.jsxs)(`div`,{className:`border-border flex shrink-0 items-center gap-2 border-b px-4 py-2`,children:[(0,J.jsx)(p,{variant:`outline`,size:`icon`,className:`size-7`,"data-testid":`grid-new-thread`,disabled:i>=5,onClick:()=>P({kind:`new-column`}),children:(0,J.jsx)(n,{className:`icon-base`})}),(0,J.jsx)(ae,{cols:i,rows:o,onChange:(e,t)=>{a(e),s(t),localStorage.setItem(Q,String(e)),localStorage.setItem($,String(t))}}),T&&(0,J.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,"data-testid":`grid-thread-actions`,children:(0,J.jsx)(E,{threadId:T,children:(0,J.jsx)(B,{hideTimeline:!0})})})]}),(0,J.jsx)(`div`,{"data-testid":`grid-container`,className:`min-h-0 flex-1 overflow-x-auto overflow-y-hidden p-2`,children:(0,J.jsxs)(`div`,{className:`flex h-full`,children:[(0,J.jsx)(Y,{insertIndex:0,isDragging:W,disabled:i>=5}),Array.from({length:i}).flatMap((e,t)=>[(0,J.jsx)(`div`,{className:`flex h-full min-w-[280px] flex-1 flex-col gap-2`,"data-testid":`grid-col-${t}`,children:Array.from({length:o},(e,n)=>{let r=n*i+t,a=v[String(r)];return(0,J.jsx)(ie,{cellIndex:r,children:a?(0,J.jsx)(ce,{threadId:a,onRemove:()=>V(r),onOpenLightbox:_}):(0,J.jsx)(E,{threadId:null,children:(0,J.jsx)(re,{cellIndex:r,onCreated:e=>z(r,e),onLoadExisting:e=>z(r,e),initialProjectId:j[r],onConsumePreset:()=>I(r),onRequestPickProject:()=>P({kind:`cell`,cellIndex:r}),gridThreadIds:S})})},a?`col-${a}`:`empty-${r}`)})},`col-${t}`),(0,J.jsx)(Y,{insertIndex:t+1,isDragging:W,disabled:i>=5},`insert-${t+1}`)])]})}),(0,J.jsx)(oe,{open:N!==null,onOpenChange:e=>{e||P(null)},onSelect:U}),(0,J.jsx)(y,{images:c,initialIndex:d,open:m,onClose:()=>h(!1)})]})}export{pe as LiveColumnsView};
1
+ import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{Lt as t,Q as n,an as r,i,in as a,k as o,zr as s,zt as c}from"./icons-sqwAEN28.js";import{o as l}from"./markdown-DBtwZWLP.js";import{t as u}from"./useTranslation-DAPPK3Hy.js";import{j as d,lt as f}from"./index-DCJpZz6M.js";import{t as p}from"./button-CZ967bB8.js";import{$ as m,An as h,Dr as g,Fn as _,It as v,J as y,Lt as b,Mn as x,Q as S,Un as C,Ur as w,Zt as T,_t as E,et as D,j as O,jn as k,m as A,nn as j,nt as M,rt as N,tt as P,yr as F}from"./items-azeOGVff.js";import{t as I}from"./loading-state-CZgfErMi.js";import{n as L,r as R,t as z}from"./adapter-g71mvnZo.js";import{n as B,t as V}from"./ProjectHeader-D8OTTLq1.js";import{t as H}from"./tooltip-icon-button-DD8fKyR8.js";import{i as U,n as W,r as G,t as K}from"./use-thread-search-BvRo6Jmy.js";import{t as ee}from"./use-minute-tick-C-e4HaZD.js";import{t as te}from"./drag-preview-D7uMScNk.js";var q=e(s(),1),J=e(l(),1);function ne({open:e,onOpenChange:t,projectId:n,onSelect:r,gridThreadIds:i}){let{t:a}=u(),o=v(n),s=e=>{r(e),t(!1)};return(0,J.jsxs)(S,{open:e,onOpenChange:t,children:[(0,J.jsx)(P,{"data-testid":`grid-thread-picker-search`,placeholder:a(`live.searchThread`,`Search thread...`)}),(0,J.jsxs)(N,{children:[(0,J.jsx)(m,{children:a(`live.noThreads`,`No threads`)}),(0,J.jsx)(D,{heading:a(`live.pickThreadTitle`,`Load an existing thread`),children:o.map(e=>{let{icon:t,className:n}=j[e.status]??j.idle,r=i?.has(e.id);return(0,J.jsxs)(M,{"data-testid":`grid-thread-pick-${e.id}`,value:`${e.title} ${e.id}`,onSelect:()=>s(e.id),children:[(0,J.jsx)(t,{className:f(`size-3.5 shrink-0`,n)}),e.title?(0,J.jsx)(A,{as:`span`,title:e.title,className:`text-sm`,containerClassName:`min-w-0 flex-1`}):(0,J.jsx)(`span`,{className:`truncate`,children:a(`common.untitled`,`Untitled`)}),r&&(0,J.jsx)(`span`,{className:`text-muted-foreground ml-auto shrink-0 text-[10px]`,children:a(`live.inGrid`,`in grid`)})]},e.id)})})]})]})}var re=(0,q.memo)(function({cellIndex:e,onCreated:t,onLoadExisting:r,initialProjectId:i,onConsumePreset:a,onRequestPickProject:s,gridThreadIds:l}){let{t:d}=u(),[f,m]=(0,q.useState)(i??null),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)(!1);(0,q.useEffect)(()=>{i&&i!==f&&(m(i),g(!1),a?.())},[i]);let y=(0,q.useCallback)(()=>{m(null),g(!1)},[]);return h?(0,J.jsx)(`div`,{className:`border-border/60 bg-muted/10 flex h-full w-full flex-col rounded-sm border-2 border-dashed`,"data-testid":`grid-empty-cell-${e}`,children:(0,J.jsx)(U,{isScratchOverride:!0,onCreated:t,onCancel:y})}):f?(0,J.jsxs)(`div`,{className:`border-border/60 bg-muted/10 flex h-full w-full flex-col rounded-sm border-2 border-dashed`,"data-testid":`grid-empty-cell-${e}`,children:[(0,J.jsx)(U,{projectIdOverride:f,onCreated:t,onCancel:y}),(0,J.jsx)(`div`,{className:`border-border/40 flex shrink-0 items-center justify-center border-t px-3 py-1.5`,children:(0,J.jsxs)(p,{variant:`ghost`,size:`sm`,className:`text-muted-foreground h-7`,"data-testid":`grid-load-existing-${e}`,onClick:()=>v(!0),children:[(0,J.jsx)(c,{className:`icon-sm`}),d(`live.loadExisting`,`Load existing thread`)]})}),(0,J.jsx)(ne,{open:_,onOpenChange:v,projectId:f,gridThreadIds:l,onSelect:r})]}):(0,J.jsxs)(`div`,{className:`border-border/60 bg-muted/10 hover:border-primary/50 hover:bg-muted/30 flex h-full w-full items-center justify-center gap-2 rounded-sm border-2 border-dashed p-4 transition-colors`,"data-testid":`grid-empty-cell-${e}`,children:[(0,J.jsxs)(p,{variant:`default`,size:`sm`,className:`h-7`,"data-testid":`grid-empty-new-${e}`,onClick:s,children:[(0,J.jsx)(n,{className:`icon-sm`}),d(`live.newThread`,`New thread`)]}),(0,J.jsxs)(p,{variant:`outline`,size:`sm`,className:`h-7`,"data-testid":`grid-empty-new-scratch-${e}`,onClick:()=>g(!0),children:[(0,J.jsx)(o,{className:`icon-sm`}),d(`live.newScratch`,`New scratch`)]})]})}),ie=(0,q.memo)(function({cellIndex:e,children:t}){let n=(0,q.useRef)(null),[r,i]=(0,q.useState)(!1);return(0,q.useEffect)(()=>{let t=n.current;if(t)return L({element:t,getData:()=>({type:`grid-cell`,cellIndex:e}),canDrop:({source:e})=>e.data.type===`grid-thread`,onDragEnter:()=>i(!0),onDragLeave:()=>i(!1),onDrop:()=>i(!1)})},[e]),(0,J.jsx)(`div`,{ref:n,className:f(`flex min-h-0 flex-1 flex-col`,r&&`rounded-sm ring-2 ring-primary`),"data-testid":`grid-drop-target-${e}`,children:t})}),Y=(0,q.memo)(function({insertIndex:e,isDragging:t,disabled:r}){let i=(0,q.useRef)(null),[a,o]=(0,q.useState)(!1);(0,q.useEffect)(()=>{let t=i.current;if(t)return L({element:t,getData:()=>({type:`grid-col-insert`,insertIndex:e}),canDrop:({source:e})=>!r&&e.data.type===`grid-thread`,onDragEnter:()=>o(!0),onDragLeave:()=>o(!1),onDrop:()=>o(!1)})},[e,r]);let s=t&&!r;return(0,J.jsx)(`div`,{ref:i,className:f(`shrink-0 self-stretch rounded-sm transition-all duration-150 overflow-hidden`,a?`w-10 bg-primary/60 ring-2 ring-primary`:s?`w-6 bg-primary/10 hover:bg-primary/20`:`w-1`),"data-testid":`grid-col-insert-${e}`,children:s&&(0,J.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,J.jsx)(n,{className:`text-primary/60 size-4`})})})});function ae({cols:e,rows:t,onChange:n}){let[i,a]=(0,q.useState)(0),[o,s]=(0,q.useState)(0),[c,l]=(0,q.useState)(!1),u=c&&i>0?i:e,d=c&&o>0?o:t;return(0,J.jsxs)(h,{open:c,onOpenChange:l,children:[(0,J.jsx)(x,{asChild:!0,children:(0,J.jsxs)(p,{variant:`ghost`,className:`h-6 min-w-0 gap-1.5 px-2 text-[10px]`,children:[(0,J.jsx)(r,{className:`icon-sm`}),e,`×`,t]})}),(0,J.jsxs)(k,{className:`w-auto p-3`,align:`start`,sideOffset:4,children:[(0,J.jsx)(`div`,{className:`grid gap-1`,style:{gridTemplateColumns:`repeat(5, 1fr)`},onMouseLeave:()=>{a(0),s(0)},children:Array.from({length:5},(e,t)=>Array.from({length:5},(e,r)=>(0,J.jsx)(`button`,{className:f(`w-5 h-5 rounded-sm border transition-colors`,r+1<=u&&t+1<=d?`bg-primary border-primary`:`bg-muted/40 border-border hover:border-muted-foreground/40`),onMouseEnter:()=>{a(r+1),s(t+1)},onClick:()=>{n(r+1,t+1),l(!1)}},`${r}-${t}`)))}),(0,J.jsxs)(`p`,{className:`text-muted-foreground mt-2 text-center text-[10px]`,children:[u,`×`,d]})]})]})}function oe({open:e,onOpenChange:t,onSelect:n,placeholder:r,title:i}){let{t:a}=u(),o=g(e=>e.projects),s=e=>{n(e),t(!1)};return(0,J.jsxs)(S,{open:e,onOpenChange:t,children:[(0,J.jsx)(P,{"data-testid":`grid-project-picker-search`,placeholder:r??a(`kanban.searchProject`,`Search project...`)}),(0,J.jsxs)(N,{children:[(0,J.jsx)(m,{children:a(`live.noProjects`,`No projects`)}),(0,J.jsx)(D,{heading:i??a(`live.pickProjectTitle`,`Select a project`),children:o.map(e=>(0,J.jsxs)(M,{"data-testid":`grid-project-pick-${e.id}`,value:`${e.name} ${e.path??``}`,onSelect:()=>s(e.id),children:[(0,J.jsx)(`span`,{className:`size-2.5 shrink-0 rounded-full`,style:{backgroundColor:e.color||_(e.name)}}),(0,J.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]})]})}var se=d(`ThreadColumn`),ce=(0,q.memo)(function({threadId:e,onRemove:n,onOpenLightbox:r}){let{t:o}=u(),s=(0,q.useRef)(null),c=(0,q.useRef)(null),l=(0,q.useRef)(null),[d,p]=(0,q.useState)(!1),m=F(t=>t.gridSelectedThreadId===e),h=F(e=>e.setGridSelectedThreadId),g=(0,q.useCallback)(()=>{h(e)},[h,e]),_=b(e=>e.registerLiveThread),v=b(e=>e.unregisterLiveThread);(0,q.useEffect)(()=>(_(e),()=>{v(e)}),[e,_,v]);let y=b(t=>t.threadDataById[e]??null),x=y===null;(0,q.useEffect)(()=>{let t=c.current,n=l.current;if(!(!t||!n))return z({element:n,getInitialData:()=>({type:`grid-thread`,threadId:e}),onGenerateDragPreview:({nativeSetDragImage:e})=>te({nativeSetDragImage:e,source:t}),onDragStart:()=>p(!0),onDrop:()=>p(!1)})},[e,x]);let{searchOpen:S,setSearchOpen:C,handleSearchNavigate:w,handleSearchClose:D}=K(s,e),k=(0,q.useRef)(!1);(0,q.useEffect)(()=>{let t=t=>{if(!t.ctrlKey||t.shiftKey||t.metaKey||t.altKey||t.key!==`f`&&t.key!==`F`)return;let n=t.target;if(n&&n.closest(`.xterm`))return;let r=c.current;if(!r||!(document.activeElement&&r.contains(document.activeElement))&&!k.current)return;t.preventDefault(),t.stopImmediatePropagation(),se.info({threadId:e},`shortcut.grid_thread_search`),C(!0);let i=r.querySelector(`[data-testid="grid-search-${e}-input"]`);i&&requestAnimationFrame(()=>i.focus())};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e,C]);let A=O(e=>e.status),M=T(y?.status??`idle`,A),N=j[M]?.icon??t,P=j[M]?.className??``;return x?(0,J.jsx)(`div`,{className:`border-border flex min-h-0 flex-1 rounded-sm border`,children:(0,J.jsx)(I,{testId:`grid-column-loading-${e}`})}):y?(0,J.jsx)(E,{threadId:e,children:(0,J.jsxs)(`div`,{ref:c,className:f(`group/col relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-sm border border-border`,d&&`opacity-50`,m&&`border-primary/25`),"data-testid":`grid-column-${e}`,"data-selected":m?`true`:void 0,onPointerDownCapture:g,onPointerEnter:()=>{k.current=!0},onPointerLeave:()=>{k.current=!1},children:[(0,J.jsx)(`div`,{ref:l,className:`shrink-0 cursor-grab active:cursor-grabbing`,children:(0,J.jsx)(V,{hideActions:!0,hideFiles:!0,hideTests:!0,hideStartup:!0,hideTerminal:!0,hideTimeline:!0,leading:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(a,{className:`icon-xs text-muted-foreground shrink-0`}),(0,J.jsx)(N,{className:f(`icon-sm shrink-0`,P)})]}),trailing:n?(0,J.jsx)(H,{tooltip:o(`live.removeFromGrid`,`Remove from grid`),onClick:n,className:`size-5 shrink-0 opacity-0 transition-opacity group-hover/col:opacity-100`,"data-testid":`grid-remove-${e}`,children:(0,J.jsx)(i,{className:`icon-xs`})}):void 0})}),(0,J.jsx)(W,{threadId:e,open:S,onClose:D,onNavigateToMessage:w,testIdPrefix:`grid-search-${e}`,className:`border-border bg-popover absolute top-9 right-2 z-30 gap-1.5 rounded-md border px-2 py-1.5 shadow-md`}),(0,J.jsx)(G,{streamRef:s,onOpenLightbox:r,className:`min-h-0 flex-1`})]})}):(0,J.jsx)(`div`,{className:`border-border text-muted-foreground flex min-h-0 flex-1 items-center justify-center rounded-sm border text-xs`,children:o(`thread.notFound`,`Thread not found`)})});function le(e,t,n){for(let r=0;r<n;r++)for(let n=0;n<t;n++){let i=e[String(r*t+n)];if(i)return i}return null}function ue({current:e,placedIds:t,firstPlaced:n,inited:r,prevHadThreads:i}){let a=e;a&&!t.has(a)&&(a=null);let o=t.size>0;return!a&&o&&(!r||!i&&o)&&(a=n),a}var X=`funny:grid-cells:v1`,de=X;function fe(){try{let e=localStorage.getItem(de);return e?JSON.parse(e):{}}catch{return{}}}var Z=d(`LiveColumnsView`),Q=`funny:grid-cols:v1`,$=`funny:grid-rows:v1`;function pe(){let{t:e}=u();ee();let t=g(e=>e.projects),r=b(e=>e.loadThreadsForProject),[i,a]=(0,q.useState)(()=>{let e=localStorage.getItem(Q);return e?Math.min(Math.max(Number(e),1),5):2}),[o,s]=(0,q.useState)(()=>{let e=localStorage.getItem($);return e?Math.min(Math.max(Number(e),1),5):2});(0,q.useEffect)(()=>{let e=b.getState();for(let n of t)e.threadIdsByProject[n.id]||r(n.id)},[(0,q.useMemo)(()=>t.map(e=>e.id).join(`,`),[t])]);let[c,l]=(0,q.useState)([]),[d,f]=(0,q.useState)(0),[m,h]=(0,q.useState)(!1),_=(0,q.useCallback)((e,t)=>{l(e),f(t),h(!0)},[]),[v,x]=(0,q.useState)(fe),S=(0,q.useMemo)(()=>new Set(Object.values(v)),[v]),T=F(e=>e.gridSelectedThreadId),D=F(e=>e.setGridSelectedThreadId),O=C(e=>e.fetchForThread),k=(0,q.useRef)(!1),A=(0,q.useRef)(!1);(0,q.useEffect)(()=>{let e=F.getState().gridSelectedThreadId,t=ue({current:e,placedIds:S,firstPlaced:le(v,i,o),inited:k.current,prevHadThreads:A.current});t!==e&&D(t),k.current=!0,A.current=S.size>0},[S,v,i,o,D]),(0,q.useEffect)(()=>{T&&O(T)},[T,O]);let[j,M]=(0,q.useState)({}),[N,P]=(0,q.useState)(null),I=(0,q.useCallback)(e=>{M(t=>{if(!(e in t))return t;let n={...t};return delete n[e],n})},[]),L=(0,q.useCallback)((e,t)=>{M(n=>({...n,[e]:t}))},[]),z=(0,q.useCallback)((e,t)=>{x(n=>{let r={...n};for(let[e,n]of Object.entries(r))n===t&&delete r[e];return r[String(e)]=t,localStorage.setItem(X,JSON.stringify(r)),r}),D(t)},[D]),V=(0,q.useCallback)(e=>{x(t=>{let n={...t};delete n[String(e)];let r=e%i;if(i<=1||!Array.from({length:o}).every((e,t)=>{let a=t*i+r;return!n[String(a)]}))return localStorage.setItem(X,JSON.stringify(n)),n;let s=i-1,c={};for(let[e,t]of Object.entries(n)){let n=Number(e),a=n%i,o=Math.floor(n/i);if(a===r)continue;let l=a>r?a-1:a;c[String(o*s+l)]=t}return a(s),M(e=>{let t={};for(let[n,a]of Object.entries(e)){let e=Number(n),o=e%i,c=Math.floor(e/i);if(o===r)continue;let l=o>r?o-1:o;t[c*s+l]=a}return t}),localStorage.setItem(Q,String(s)),localStorage.setItem(X,JSON.stringify(c)),c})},[i,o]),H=(0,q.useCallback)(t=>{if(i>=5){w.info(e(`live.gridFull`,`Grid is full`));return}let n=i,r=n+1,o=n;x(e=>{let t={};for(let[i,a]of Object.entries(e)){let e=Number(i),o=e%n,s=Math.floor(e/n);t[String(s*r+o)]=a}return localStorage.setItem(X,JSON.stringify(t)),t}),M(e=>{let i={};for(let[t,a]of Object.entries(e)){let e=Number(t),o=e%n,s=Math.floor(e/n);i[s*r+o]=a}return i[o]=t,i}),a(r),localStorage.setItem(Q,String(r)),Z.info({projectId:t,cellIndex:o},`header preset project for new column`)},[i,e]),U=(0,q.useCallback)(e=>{let t=N;t&&(t.kind===`new-column`?H(e):L(t.cellIndex,e),P(null))},[N,H,L]);(0,q.useEffect)(()=>{let e=e=>{if(!e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||e.key!==`n`&&e.key!==`N`)return;let t=e.target?.tagName;t===`INPUT`||t===`TEXTAREA`||e.target?.isContentEditable||i>=5||(e.preventDefault(),e.stopImmediatePropagation(),Z.info(`shortcut.grid_new_thread`),P({kind:`new-column`}))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[i]);let[W,G]=(0,q.useState)(!1);return(0,q.useEffect)(()=>R({onDragStart:({source:e})=>{e.data.type===`grid-thread`&&G(!0)},onDrop:({source:t,location:n})=>{if(G(!1),t.data.type!==`grid-thread`)return;let r=n.current.dropTargets;if(!r.length)return;let o=r[0].data,s=t.data.threadId;if(o.type===`grid-cell`){let e=o.cellIndex;x(t=>{let n={...t},r;for(let[e,t]of Object.entries(n))t===s&&(r=e,delete n[e]);let i=n[String(e)];return i&&r&&(n[r]=i),n[String(e)]=s,localStorage.setItem(X,JSON.stringify(n)),n});return}if(o.type===`grid-col-insert`){let t=o.insertIndex;if(i>=5){w.info(e(`live.gridFull`,`Grid is full`));return}let n=i,r=n+1;x(e=>{let i={};for(let[a,o]of Object.entries(e)){if(o===s)continue;let e=Number(a),c=e%n,l=Math.floor(e/n),u=c<t?c:c+1,d=l*r+u;i[String(d)]=o}return i[String(t)]=s,localStorage.setItem(X,JSON.stringify(i)),i}),M(e=>{let i={};for(let[a,o]of Object.entries(e)){let e=Number(a),s=e%n,c=Math.floor(e/n),l=s<t?s:s+1;i[c*r+l]=o}return i}),a(r),localStorage.setItem(Q,String(r))}}}),[i,e]),(0,J.jsxs)(`div`,{className:`flex h-full min-w-0 flex-1 flex-col overflow-hidden`,"data-testid":`grid-view`,children:[(0,J.jsxs)(`div`,{className:`border-border flex shrink-0 items-center gap-2 border-b px-4 py-2`,children:[(0,J.jsx)(p,{variant:`outline`,size:`icon`,className:`size-7`,"data-testid":`grid-new-thread`,disabled:i>=5,onClick:()=>P({kind:`new-column`}),children:(0,J.jsx)(n,{className:`icon-base`})}),(0,J.jsx)(ae,{cols:i,rows:o,onChange:(e,t)=>{a(e),s(t),localStorage.setItem(Q,String(e)),localStorage.setItem($,String(t))}}),T&&(0,J.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,"data-testid":`grid-thread-actions`,children:(0,J.jsx)(E,{threadId:T,children:(0,J.jsx)(B,{hideTimeline:!0})})})]}),(0,J.jsx)(`div`,{"data-testid":`grid-container`,className:`min-h-0 flex-1 overflow-x-auto overflow-y-hidden p-2`,children:(0,J.jsxs)(`div`,{className:`flex h-full`,children:[(0,J.jsx)(Y,{insertIndex:0,isDragging:W,disabled:i>=5}),Array.from({length:i}).flatMap((e,t)=>[(0,J.jsx)(`div`,{className:`flex h-full min-w-[280px] flex-1 flex-col gap-2`,"data-testid":`grid-col-${t}`,children:Array.from({length:o},(e,n)=>{let r=n*i+t,a=v[String(r)];return(0,J.jsx)(ie,{cellIndex:r,children:a?(0,J.jsx)(ce,{threadId:a,onRemove:()=>V(r),onOpenLightbox:_}):(0,J.jsx)(E,{threadId:null,children:(0,J.jsx)(re,{cellIndex:r,onCreated:e=>z(r,e),onLoadExisting:e=>z(r,e),initialProjectId:j[r],onConsumePreset:()=>I(r),onRequestPickProject:()=>P({kind:`cell`,cellIndex:r}),gridThreadIds:S})})},a?`col-${a}`:`empty-${r}`)})},`col-${t}`),(0,J.jsx)(Y,{insertIndex:t+1,isDragging:W,disabled:i>=5},`insert-${t+1}`)])]})}),(0,J.jsx)(oe,{open:N!==null,onOpenChange:e=>{e||P(null)},onSelect:U}),(0,J.jsx)(y,{images:c,initialIndex:d,open:m,onClose:()=>h(!1)})]})}export{pe as LiveColumnsView};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{Ln as t,Rn as n,zr as r}from"./icons-sqwAEN28.js";import{o as i}from"./markdown-DBtwZWLP.js";import{t as a}from"./useTranslation-DAPPK3Hy.js";import{k as o}from"./index-BsxcqNXe.js";import{t as s}from"./button-DeEOU1Fb.js";import{t as c}from"./input-DV30TVat.js";var l=e(r(),1),u=e(i(),1);function d(){let{t:e}=a(),r=o(e=>e.login),[i,d]=(0,l.useState)(``),[f,p]=(0,l.useState)(``),[m,h]=(0,l.useState)(!1),[g,_]=(0,l.useState)(``),[v,y]=(0,l.useState)(!1);return(0,u.jsx)(`div`,{className:`bg-background flex min-h-screen items-center justify-center`,children:(0,u.jsxs)(`div`,{className:`border-border bg-card w-full max-w-sm space-y-6 rounded-lg border p-8 shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`h1`,{className:`text-foreground text-2xl font-semibold`,children:e(`app.title`)}),(0,u.jsx)(`p`,{className:`text-muted-foreground mt-1 text-sm`,children:e(`auth.signInPrompt`)})]}),(0,u.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),_(``),y(!0);try{await r(i,f)}catch(t){_(t.message||e(`auth.loginFailed`))}finally{y(!1)}},className:`space-y-4`,children:[(0,u.jsxs)(`div`,{className:`space-y-2`,children:[(0,u.jsx)(`label`,{htmlFor:`username`,className:`text-foreground text-sm font-medium`,children:e(`auth.username`)}),(0,u.jsx)(c,{id:`username`,type:`text`,value:i,onChange:e=>d(e.target.value),placeholder:e(`auth.usernamePlaceholder`),autoFocus:!0,required:!0})]}),(0,u.jsxs)(`div`,{className:`space-y-2`,children:[(0,u.jsx)(`label`,{htmlFor:`password`,className:`text-foreground text-sm font-medium`,children:e(`auth.password`)}),(0,u.jsxs)(`div`,{className:`relative`,children:[(0,u.jsx)(c,{id:`password`,type:m?`text`:`password`,value:f,onChange:e=>p(e.target.value),placeholder:e(`auth.passwordPlaceholder`),className:`pr-10`,required:!0}),(0,u.jsx)(`button`,{type:`button`,onClick:()=>h(e=>!e),className:`text-muted-foreground hover:text-foreground absolute inset-y-0 right-0 flex items-center px-3`,tabIndex:-1,"aria-label":e(m?`auth.hidePassword`:`auth.showPassword`),"data-testid":`login-toggle-password`,children:m?(0,u.jsx)(n,{className:`h-4 w-4`}):(0,u.jsx)(t,{className:`h-4 w-4`})})]})]}),g&&(0,u.jsx)(`p`,{className:`text-destructive text-sm`,children:g}),(0,u.jsx)(s,{type:`submit`,className:`w-full`,disabled:v||!i||!f,children:e(v?`auth.signingIn`:`auth.signIn`)})]})]})})}export{d as LoginPage};
1
+ import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{Ln as t,Rn as n,zr as r}from"./icons-sqwAEN28.js";import{o as i}from"./markdown-DBtwZWLP.js";import{t as a}from"./useTranslation-DAPPK3Hy.js";import{k as o}from"./index-DCJpZz6M.js";import{t as s}from"./button-CZ967bB8.js";import{t as c}from"./input-C2LWQS5Y.js";var l=e(r(),1),u=e(i(),1);function d(){let{t:e}=a(),r=o(e=>e.login),[i,d]=(0,l.useState)(``),[f,p]=(0,l.useState)(``),[m,h]=(0,l.useState)(!1),[g,_]=(0,l.useState)(``),[v,y]=(0,l.useState)(!1);return(0,u.jsx)(`div`,{className:`bg-background flex min-h-screen items-center justify-center`,children:(0,u.jsxs)(`div`,{className:`border-border bg-card w-full max-w-sm space-y-6 rounded-lg border p-8 shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`h1`,{className:`text-foreground text-2xl font-semibold`,children:e(`app.title`)}),(0,u.jsx)(`p`,{className:`text-muted-foreground mt-1 text-sm`,children:e(`auth.signInPrompt`)})]}),(0,u.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),_(``),y(!0);try{await r(i,f)}catch(t){_(t.message||e(`auth.loginFailed`))}finally{y(!1)}},className:`space-y-4`,children:[(0,u.jsxs)(`div`,{className:`space-y-2`,children:[(0,u.jsx)(`label`,{htmlFor:`username`,className:`text-foreground text-sm font-medium`,children:e(`auth.username`)}),(0,u.jsx)(c,{id:`username`,type:`text`,value:i,onChange:e=>d(e.target.value),placeholder:e(`auth.usernamePlaceholder`),autoFocus:!0,required:!0})]}),(0,u.jsxs)(`div`,{className:`space-y-2`,children:[(0,u.jsx)(`label`,{htmlFor:`password`,className:`text-foreground text-sm font-medium`,children:e(`auth.password`)}),(0,u.jsxs)(`div`,{className:`relative`,children:[(0,u.jsx)(c,{id:`password`,type:m?`text`:`password`,value:f,onChange:e=>p(e.target.value),placeholder:e(`auth.passwordPlaceholder`),className:`pr-10`,required:!0}),(0,u.jsx)(`button`,{type:`button`,onClick:()=>h(e=>!e),className:`text-muted-foreground hover:text-foreground absolute inset-y-0 right-0 flex items-center px-3`,tabIndex:-1,"aria-label":e(m?`auth.hidePassword`:`auth.showPassword`),"data-testid":`login-toggle-password`,children:m?(0,u.jsx)(n,{className:`h-4 w-4`}):(0,u.jsx)(t,{className:`h-4 w-4`})})]})]}),g&&(0,u.jsx)(`p`,{className:`text-destructive text-sm`,children:g}),(0,u.jsx)(s,{type:`submit`,className:`w-full`,disabled:v||!i||!f,children:e(v?`auth.signingIn`:`auth.signIn`)})]})]})})}export{d as LoginPage};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{Hn as t,On as n,zr as r}from"./icons-sqwAEN28.js";import{o as i,r as a,t as o}from"./markdown-DBtwZWLP.js";import{c as s,f as c,j as l,lt as u,o as d,s as f}from"./index-BsxcqNXe.js";import{n as p}from"./rehype-sanitize-DLZhivS4.js";import{t as m}from"./button-DeEOU1Fb.js";import{X as h,Y as g}from"./items-_g3-I08l.js";import{t as _}from"./loading-state-BQjalkhM.js";import{n as v,o as y}from"./markdown-components-D4Y3yxJk.js";var b=e(r(),1),x=e(i(),1),S=l(`media-preview`),C={png:`image`,jpg:`image`,jpeg:`image`,gif:`image`,webp:`image`,svg:`image`,bmp:`image`,avif:`image`,ico:`image`,mp3:`audio`,wav:`audio`,ogg:`audio`,flac:`audio`,m4a:`audio`,aac:`audio`,mp4:`video`,webm:`video`,mov:`video`,mkv:`video`,pdf:`pdf`,md:`markdown`,markdown:`markdown`,mdx:`markdown`,txt:`text`,log:`text`,json:`text`,yaml:`text`,yml:`text`,csv:`text`,tsv:`text`,xml:`text`,ini:`text`,toml:`text`};function w(e){let t=e.split(`.`).pop()?.toLowerCase();if(!t)return!1;let n=C[t];return n===`image`||n===`audio`||n===`video`||n===`pdf`}function T(e,t){return E(e,t)}function E(e,t){if(t){if(t.startsWith(`image/`))return`image`;if(t.startsWith(`audio/`))return`audio`;if(t.startsWith(`video/`))return`video`;if(t===`application/pdf`)return`pdf`;if(t===`text/markdown`)return`markdown`;if(t.startsWith(`text/`)||t===`application/json`)return`text`}if(e){let t=e.split(`.`).pop()?.toLowerCase();if(t&&C[t])return C[t]}return`unknown`}function D({src:e,name:t,mime:n,text:r,kind:i,className:a,onError:o}){let s=(0,b.useMemo)(()=>i??E(t,n),[i,t,n]);return(0,x.jsx)(`div`,{"data-testid":`media-preview`,"data-media-kind":s,className:u(`flex w-full flex-col overflow-hidden rounded-lg border bg-card`,a),children:(0,x.jsx)(O,{kind:s,src:e,name:t,text:r,onError:o})})}function O({kind:e,src:t,name:n,text:r,onError:i}){switch(e){case`image`:return(0,x.jsx)(k,{src:t,name:n,onError:i});case`audio`:return(0,x.jsx)(A,{src:t,name:n,onError:i});case`video`:return(0,x.jsx)(j,{src:t,name:n,onError:i});case`pdf`:return(0,x.jsx)(M,{src:t,name:n});case`markdown`:return(0,x.jsx)(P,{src:t,text:r,onError:i});case`text`:return(0,x.jsx)(F,{src:t,text:r,onError:i});default:return(0,x.jsx)(I,{src:t,name:n})}}function k({src:e,name:t,onError:n}){let r=h(),[i,a]=(0,b.useState)(!1);return(0,b.useEffect)(()=>a(!1),[e]),i?(0,x.jsx)(y,{probeUrl:e,path:t,fill:!0}):(0,x.jsxs)(`div`,{"data-testid":`media-preview-image`,className:`bg-muted/30 relative flex max-h-[70vh] min-h-[12rem] items-center justify-center overflow-hidden p-2`,children:[(0,x.jsx)(`img`,{...r.imgProps,src:e,alt:t??`preview`,loading:`lazy`,onError:()=>{a(!0),n?.(Error(`Failed to load image: ${e}`))},className:u(`max-h-[66vh] max-w-full rounded object-contain select-none`,r.zoomed?r.dragging?`cursor-grabbing`:`cursor-grab`:`cursor-zoom-in`,r.dragging?``:`transition-transform duration-150`)}),(0,x.jsx)(g,{zoom:r,className:`absolute bottom-3 left-1/2 -translate-x-1/2`})]})}function A({src:e,name:t,onError:n}){return(0,x.jsxs)(`div`,{className:`flex flex-col gap-2 p-3`,children:[t&&(0,x.jsx)(`div`,{className:`text-muted-foreground truncate text-sm`,children:t}),(0,x.jsx)(`audio`,{controls:!0,src:e,"data-testid":`media-preview-audio`,onError:()=>n?.(Error(`Failed to load audio: ${e}`)),className:`w-full`,children:`Your browser does not support the audio element.`})]})}function j({src:e,name:t,onError:n}){let[r,i]=(0,b.useState)(!1);return(0,b.useEffect)(()=>i(!1),[e]),r?(0,x.jsx)(y,{probeUrl:e,path:t,fill:!0}):(0,x.jsxs)(`video`,{controls:!0,src:e,"data-testid":`media-preview-video`,onError:()=>{i(!0),n?.(Error(`Failed to load video: ${e}`))},className:`max-h-[70vh] w-full bg-gray-950`,children:[t&&(0,x.jsx)(`track`,{kind:`metadata`,label:t}),`Your browser does not support the video element.`]})}function M({src:e,name:t}){return(0,x.jsx)(`iframe`,{src:e,title:t??`PDF preview`,"data-testid":`media-preview-pdf`,className:`h-[70vh] w-full`})}function N(e,t,n){let[r,i]=(0,b.useState)(t??null),[a,o]=(0,b.useState)(t===void 0);return(0,b.useEffect)(()=>{if(t!==void 0){i(t),o(!1);return}let r=!1;return o(!0),fetch(e).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.text()}).then(e=>{r||(i(e),o(!1))}).catch(t=>{if(r)return;let i=t instanceof Error?t:Error(String(t));S.error(`Failed to fetch text resource`,{src:e,error:i.message}),o(!1),n?.(i)}),()=>{r=!0}},[e,t,n]),{content:r,loading:a}}function P({src:e,text:t,onError:n}){let r=c(e=>e.fontSize),{content:i,loading:l}=N(e,t,n);return l?(0,x.jsx)(L,{}):i===null?(0,x.jsx)(R,{}):(0,x.jsx)(`div`,{"data-testid":`media-preview-markdown`,className:u(v,`p-4`),style:{fontSize:f[r],lineHeight:`${s[r]}px`},children:(0,x.jsx)(a,{remarkPlugins:[o],rehypePlugins:[p],children:i})})}function F({src:e,text:t,onError:n}){let r=c(e=>e.fontSize),{content:i,loading:a}=N(e,t,n);return a?(0,x.jsx)(L,{}):i===null?(0,x.jsx)(R,{}):(0,x.jsx)(`pre`,{"data-testid":`media-preview-text`,className:`text-foreground m-0 max-h-[70vh] overflow-auto p-4 font-mono wrap-break-word whitespace-pre-wrap`,style:{fontSize:d[r]},children:i})}function I({src:e,name:r}){return(0,x.jsxs)(`div`,{"data-testid":`media-preview-unknown`,className:`flex flex-col items-center gap-3 p-6 text-center`,children:[(0,x.jsx)(n,{className:`icon-xl text-muted-foreground`}),(0,x.jsxs)(`div`,{className:`text-muted-foreground text-sm`,children:[`No preview available`,r?` for ${r}`:``,`.`]}),(0,x.jsx)(m,{asChild:!0,variant:`outline`,size:`sm`,"data-testid":`media-preview-download`,children:(0,x.jsxs)(`a`,{href:e,download:r,target:`_blank`,rel:`noreferrer`,children:[(0,x.jsx)(t,{className:`icon-sm`}),`Download`]})})]})}function L(){return(0,x.jsx)(_,{fill:!1,size:`compact`,className:`p-6`,testId:`media-preview-loading`})}function R(){return(0,x.jsx)(y,{reason:`Failed to load preview.`,className:`m-4`})}export{T as n,w as r,D as t};
1
+ import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{Hn as t,On as n,zr as r}from"./icons-sqwAEN28.js";import{o as i,r as a,t as o}from"./markdown-DBtwZWLP.js";import{c as s,f as c,j as l,lt as u,o as d,s as f}from"./index-DCJpZz6M.js";import{n as p}from"./rehype-sanitize-DLZhivS4.js";import{t as m}from"./button-CZ967bB8.js";import{X as h,Y as g}from"./items-azeOGVff.js";import{t as _}from"./loading-state-CZgfErMi.js";import{n as v,o as y}from"./markdown-components-gp0WAMTj.js";var b=e(r(),1),x=e(i(),1),S=l(`media-preview`),C={png:`image`,jpg:`image`,jpeg:`image`,gif:`image`,webp:`image`,svg:`image`,bmp:`image`,avif:`image`,ico:`image`,mp3:`audio`,wav:`audio`,ogg:`audio`,flac:`audio`,m4a:`audio`,aac:`audio`,mp4:`video`,webm:`video`,mov:`video`,mkv:`video`,pdf:`pdf`,md:`markdown`,markdown:`markdown`,mdx:`markdown`,txt:`text`,log:`text`,json:`text`,yaml:`text`,yml:`text`,csv:`text`,tsv:`text`,xml:`text`,ini:`text`,toml:`text`};function w(e){let t=e.split(`.`).pop()?.toLowerCase();if(!t)return!1;let n=C[t];return n===`image`||n===`audio`||n===`video`||n===`pdf`}function T(e,t){return E(e,t)}function E(e,t){if(t){if(t.startsWith(`image/`))return`image`;if(t.startsWith(`audio/`))return`audio`;if(t.startsWith(`video/`))return`video`;if(t===`application/pdf`)return`pdf`;if(t===`text/markdown`)return`markdown`;if(t.startsWith(`text/`)||t===`application/json`)return`text`}if(e){let t=e.split(`.`).pop()?.toLowerCase();if(t&&C[t])return C[t]}return`unknown`}function D({src:e,name:t,mime:n,text:r,kind:i,className:a,onError:o}){let s=(0,b.useMemo)(()=>i??E(t,n),[i,t,n]);return(0,x.jsx)(`div`,{"data-testid":`media-preview`,"data-media-kind":s,className:u(`flex w-full flex-col overflow-hidden rounded-lg border bg-card`,a),children:(0,x.jsx)(O,{kind:s,src:e,name:t,text:r,onError:o})})}function O({kind:e,src:t,name:n,text:r,onError:i}){switch(e){case`image`:return(0,x.jsx)(k,{src:t,name:n,onError:i});case`audio`:return(0,x.jsx)(A,{src:t,name:n,onError:i});case`video`:return(0,x.jsx)(j,{src:t,name:n,onError:i});case`pdf`:return(0,x.jsx)(M,{src:t,name:n});case`markdown`:return(0,x.jsx)(P,{src:t,text:r,onError:i});case`text`:return(0,x.jsx)(F,{src:t,text:r,onError:i});default:return(0,x.jsx)(I,{src:t,name:n})}}function k({src:e,name:t,onError:n}){let r=h(),[i,a]=(0,b.useState)(!1);return(0,b.useEffect)(()=>a(!1),[e]),i?(0,x.jsx)(y,{probeUrl:e,path:t,fill:!0}):(0,x.jsxs)(`div`,{"data-testid":`media-preview-image`,className:`bg-muted/30 relative flex max-h-[70vh] min-h-[12rem] items-center justify-center overflow-hidden p-2`,children:[(0,x.jsx)(`img`,{...r.imgProps,src:e,alt:t??`preview`,loading:`lazy`,onError:()=>{a(!0),n?.(Error(`Failed to load image: ${e}`))},className:u(`max-h-[66vh] max-w-full rounded object-contain select-none`,r.zoomed?r.dragging?`cursor-grabbing`:`cursor-grab`:`cursor-zoom-in`,r.dragging?``:`transition-transform duration-150`)}),(0,x.jsx)(g,{zoom:r,className:`absolute bottom-3 left-1/2 -translate-x-1/2`})]})}function A({src:e,name:t,onError:n}){return(0,x.jsxs)(`div`,{className:`flex flex-col gap-2 p-3`,children:[t&&(0,x.jsx)(`div`,{className:`text-muted-foreground truncate text-sm`,children:t}),(0,x.jsx)(`audio`,{controls:!0,src:e,"data-testid":`media-preview-audio`,onError:()=>n?.(Error(`Failed to load audio: ${e}`)),className:`w-full`,children:`Your browser does not support the audio element.`})]})}function j({src:e,name:t,onError:n}){let[r,i]=(0,b.useState)(!1);return(0,b.useEffect)(()=>i(!1),[e]),r?(0,x.jsx)(y,{probeUrl:e,path:t,fill:!0}):(0,x.jsxs)(`video`,{controls:!0,src:e,"data-testid":`media-preview-video`,onError:()=>{i(!0),n?.(Error(`Failed to load video: ${e}`))},className:`max-h-[70vh] w-full bg-gray-950`,children:[t&&(0,x.jsx)(`track`,{kind:`metadata`,label:t}),`Your browser does not support the video element.`]})}function M({src:e,name:t}){return(0,x.jsx)(`iframe`,{src:e,title:t??`PDF preview`,"data-testid":`media-preview-pdf`,className:`h-[70vh] w-full`})}function N(e,t,n){let[r,i]=(0,b.useState)(t??null),[a,o]=(0,b.useState)(t===void 0);return(0,b.useEffect)(()=>{if(t!==void 0){i(t),o(!1);return}let r=!1;return o(!0),fetch(e).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.text()}).then(e=>{r||(i(e),o(!1))}).catch(t=>{if(r)return;let i=t instanceof Error?t:Error(String(t));S.error(`Failed to fetch text resource`,{src:e,error:i.message}),o(!1),n?.(i)}),()=>{r=!0}},[e,t,n]),{content:r,loading:a}}function P({src:e,text:t,onError:n}){let r=c(e=>e.fontSize),{content:i,loading:l}=N(e,t,n);return l?(0,x.jsx)(L,{}):i===null?(0,x.jsx)(R,{}):(0,x.jsx)(`div`,{"data-testid":`media-preview-markdown`,className:u(v,`p-4`),style:{fontSize:f[r],lineHeight:`${s[r]}px`},children:(0,x.jsx)(a,{remarkPlugins:[o],rehypePlugins:[p],children:i})})}function F({src:e,text:t,onError:n}){let r=c(e=>e.fontSize),{content:i,loading:a}=N(e,t,n);return a?(0,x.jsx)(L,{}):i===null?(0,x.jsx)(R,{}):(0,x.jsx)(`pre`,{"data-testid":`media-preview-text`,className:`text-foreground m-0 max-h-[70vh] overflow-auto p-4 font-mono wrap-break-word whitespace-pre-wrap`,style:{fontSize:d[r]},children:i})}function I({src:e,name:r}){return(0,x.jsxs)(`div`,{"data-testid":`media-preview-unknown`,className:`flex flex-col items-center gap-3 p-6 text-center`,children:[(0,x.jsx)(n,{className:`icon-xl text-muted-foreground`}),(0,x.jsxs)(`div`,{className:`text-muted-foreground text-sm`,children:[`No preview available`,r?` for ${r}`:``,`.`]}),(0,x.jsx)(m,{asChild:!0,variant:`outline`,size:`sm`,"data-testid":`media-preview-download`,children:(0,x.jsxs)(`a`,{href:e,download:r,target:`_blank`,rel:`noreferrer`,children:[(0,x.jsx)(t,{className:`icon-sm`}),`Download`]})})]})}function L(){return(0,x.jsx)(_,{fill:!1,size:`compact`,className:`p-6`,testId:`media-preview-loading`})}function R(){return(0,x.jsx)(y,{reason:`Failed to load preview.`,className:`m-4`})}export{T as n,w as r,D as t};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{jt as t,n,t as r,wt as i,zr as a}from"./icons-sqwAEN28.js";import{o}from"./markdown-DBtwZWLP.js";import{G as s,K as c,W as l,lt as u,q as d}from"./index-BsxcqNXe.js";import{t as f}from"./button-DeEOU1Fb.js";import{$r as p,Gr as m,Jr as h,Xr as g,qr as _}from"./items-_g3-I08l.js";import{a as v,i as y}from"./markdown-components-D4Y3yxJk.js";import{n as b,t as x}from"./MediaPreview-2jhQWqiK.js";var S=e(a(),1),C=e(o(),1);function w({open:e,onOpenChange:t,filePath:n}){let r=(0,S.useMemo)(()=>{if(!n)return;let e=n.split(/[?#]/)[0],t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)},[n]),i=(0,S.useMemo)(()=>n?y(n)?n:`/api/files/raw?path=${encodeURIComponent(n)}`:null,[n]),a=(0,S.useMemo)(()=>b(r),[r]);return(0,C.jsx)(m,{open:e,onOpenChange:t,children:i&&n&&(a===`image`?(0,C.jsx)(E,{src:i,name:r}):(0,C.jsxs)(_,{className:`flex max-h-[90vh] w-[90vw] max-w-5xl flex-col gap-3 p-4`,"data-testid":`media-preview-dialog`,children:[(0,C.jsx)(g,{children:(0,C.jsx)(p,{className:`truncate text-sm font-medium`,children:r??`Preview`})}),(0,C.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,C.jsx)(x,{src:i,name:r})})]}))})}function T({onClick:e,tip:t,testId:n,children:r}){return(0,C.jsxs)(l,{children:[(0,C.jsx)(d,{asChild:!0,children:(0,C.jsx)(f,{variant:`ghost`,size:`icon-sm`,onClick:e,className:`text-muted-foreground`,"data-testid":n,children:r})}),(0,C.jsx)(s,{children:t})]})}function E({src:e,name:a}){let[o,m]=(0,S.useState)(!1),y=v(),b=y.scale>1;return(0,C.jsxs)(_,{className:u(o?`h-screen max-h-screen w-screen max-w-[100vw]`:`h-[85vh] w-[90vw] max-w-5xl`,`flex flex-col gap-0 overflow-hidden p-0`),onOpenAutoFocus:e=>e.preventDefault(),"data-testid":`media-preview-dialog`,children:[(0,C.jsxs)(g,{className:`border-border shrink-0 border-b px-4 py-3`,children:[(0,C.jsx)(p,{className:`truncate text-sm font-medium`,children:a??`Preview`}),(0,C.jsx)(h,{className:`sr-only`,children:`Expanded image view`}),(0,C.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,C.jsxs)(c,{children:[(0,C.jsxs)(`span`,{className:`text-muted-foreground mr-1 text-xs`,"data-testid":`media-preview-zoom`,children:[Math.round(y.scale*100),`%`]}),(0,C.jsx)(T,{onClick:()=>y.zoomBy(1/1.2),tip:`Zoom out`,testId:`media-preview-zoom-out`,children:(0,C.jsx)(r,{className:`icon-base`})}),(0,C.jsx)(T,{onClick:()=>y.zoomBy(1.2),tip:`Zoom in`,testId:`media-preview-zoom-in`,children:(0,C.jsx)(n,{className:`icon-base`})}),(0,C.jsxs)(l,{children:[(0,C.jsx)(d,{asChild:!0,children:(0,C.jsx)(f,{variant:`ghost`,size:`icon-sm`,onClick:y.reset,className:`text-muted-foreground text-xs`,"data-testid":`media-preview-zoom-reset`,children:`1:1`})}),(0,C.jsx)(s,{children:`Reset zoom`})]}),(0,C.jsx)(T,{onClick:()=>m(e=>!e),tip:o?`Exit fullscreen`:`Fullscreen`,testId:`media-preview-fullscreen`,children:o?(0,C.jsx)(i,{className:`icon-base`}):(0,C.jsx)(t,{className:`icon-base`})})]})})]}),(0,C.jsx)(`div`,{ref:y.containerRef,className:`bg-background flex min-h-0 flex-1 items-center justify-center overflow-hidden select-none`,style:{cursor:b?y.isDragging?`grabbing`:`grab`:`default`},onPointerDown:y.onPointerDown,onPointerMove:y.onPointerMove,onPointerUp:y.onPointerUp,onPointerCancel:y.onPointerUp,"data-testid":`media-preview-image`,children:(0,C.jsx)(`img`,{src:e,alt:a??`preview`,draggable:!1,className:`max-h-full max-w-full object-contain`,style:{transform:`translate(${y.offset.x}px, ${y.offset.y}px) scale(${y.scale})`,transformOrigin:`center center`,transition:y.isDragging?`none`:`transform 120ms`}})})]})}export{w as MediaPreviewDialog};
1
+ import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{jt as t,n,t as r,wt as i,zr as a}from"./icons-sqwAEN28.js";import{o}from"./markdown-DBtwZWLP.js";import{G as s,K as c,W as l,lt as u,q as d}from"./index-DCJpZz6M.js";import{t as f}from"./button-CZ967bB8.js";import{$r as p,Gr as m,Jr as h,Xr as g,qr as _}from"./items-azeOGVff.js";import{a as v,i as y}from"./markdown-components-gp0WAMTj.js";import{n as b,t as x}from"./MediaPreview-CSLd2xQQ.js";var S=e(a(),1),C=e(o(),1);function w({open:e,onOpenChange:t,filePath:n}){let r=(0,S.useMemo)(()=>{if(!n)return;let e=n.split(/[?#]/)[0],t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)},[n]),i=(0,S.useMemo)(()=>n?y(n)?n:`/api/files/raw?path=${encodeURIComponent(n)}`:null,[n]),a=(0,S.useMemo)(()=>b(r),[r]);return(0,C.jsx)(m,{open:e,onOpenChange:t,children:i&&n&&(a===`image`?(0,C.jsx)(E,{src:i,name:r}):(0,C.jsxs)(_,{className:`flex max-h-[90vh] w-[90vw] max-w-5xl flex-col gap-3 p-4`,"data-testid":`media-preview-dialog`,children:[(0,C.jsx)(g,{children:(0,C.jsx)(p,{className:`truncate text-sm font-medium`,children:r??`Preview`})}),(0,C.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,C.jsx)(x,{src:i,name:r})})]}))})}function T({onClick:e,tip:t,testId:n,children:r}){return(0,C.jsxs)(l,{children:[(0,C.jsx)(d,{asChild:!0,children:(0,C.jsx)(f,{variant:`ghost`,size:`icon-sm`,onClick:e,className:`text-muted-foreground`,"data-testid":n,children:r})}),(0,C.jsx)(s,{children:t})]})}function E({src:e,name:a}){let[o,m]=(0,S.useState)(!1),y=v(),b=y.scale>1;return(0,C.jsxs)(_,{className:u(o?`h-screen max-h-screen w-screen max-w-[100vw]`:`h-[85vh] w-[90vw] max-w-5xl`,`flex flex-col gap-0 overflow-hidden p-0`),onOpenAutoFocus:e=>e.preventDefault(),"data-testid":`media-preview-dialog`,children:[(0,C.jsxs)(g,{className:`border-border shrink-0 border-b px-4 py-3`,children:[(0,C.jsx)(p,{className:`truncate text-sm font-medium`,children:a??`Preview`}),(0,C.jsx)(h,{className:`sr-only`,children:`Expanded image view`}),(0,C.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,C.jsxs)(c,{children:[(0,C.jsxs)(`span`,{className:`text-muted-foreground mr-1 text-xs`,"data-testid":`media-preview-zoom`,children:[Math.round(y.scale*100),`%`]}),(0,C.jsx)(T,{onClick:()=>y.zoomBy(1/1.2),tip:`Zoom out`,testId:`media-preview-zoom-out`,children:(0,C.jsx)(r,{className:`icon-base`})}),(0,C.jsx)(T,{onClick:()=>y.zoomBy(1.2),tip:`Zoom in`,testId:`media-preview-zoom-in`,children:(0,C.jsx)(n,{className:`icon-base`})}),(0,C.jsxs)(l,{children:[(0,C.jsx)(d,{asChild:!0,children:(0,C.jsx)(f,{variant:`ghost`,size:`icon-sm`,onClick:y.reset,className:`text-muted-foreground text-xs`,"data-testid":`media-preview-zoom-reset`,children:`1:1`})}),(0,C.jsx)(s,{children:`Reset zoom`})]}),(0,C.jsx)(T,{onClick:()=>m(e=>!e),tip:o?`Exit fullscreen`:`Fullscreen`,testId:`media-preview-fullscreen`,children:o?(0,C.jsx)(i,{className:`icon-base`}):(0,C.jsx)(t,{className:`icon-base`})})]})})]}),(0,C.jsx)(`div`,{ref:y.containerRef,className:`bg-background flex min-h-0 flex-1 items-center justify-center overflow-hidden select-none`,style:{cursor:b?y.isDragging?`grabbing`:`grab`:`default`},onPointerDown:y.onPointerDown,onPointerMove:y.onPointerMove,onPointerUp:y.onPointerUp,onPointerCancel:y.onPointerUp,"data-testid":`media-preview-image`,children:(0,C.jsx)(`img`,{src:e,alt:a??`preview`,draggable:!1,className:`max-h-full max-w-full object-contain`,style:{transform:`translate(${y.offset.x}px, ${y.offset.y}px) scale(${y.scale})`,transformOrigin:`center center`,transition:y.isDragging?`none`:`transform 120ms`}})})]})}export{w as MediaPreviewDialog};