@augmentd-labs/canvas-web 2.26.20 → 2.26.22

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 (114) hide show
  1. package/dist/assets/{DocumentBodyEditor-CE2S2X6g.js → DocumentBodyEditor-8DNmOBS0.js} +1 -1
  2. package/dist/assets/{DocumentIcon-BS10SIP6.js → DocumentIcon-x299QNu_.js} +1 -1
  3. package/dist/assets/{EditorOverlay-BUToR_av.js → EditorOverlay-Cv1MaTok.js} +1 -1
  4. package/dist/assets/{FileForm-BxTixeDm.js → FileForm-DhQhVnoi.js} +1 -1
  5. package/dist/assets/{FiltersApplet-BpqITV13.js → FiltersApplet-gbu4I1fK.js} +1 -1
  6. package/dist/assets/{HomeFab-BAKOAkpE.js → HomeFab-CXaEEzXy.js} +2 -2
  7. package/dist/assets/{IdentityFields-C2MPM-Ab.js → IdentityFields-OPEWPlZs.js} +1 -1
  8. package/dist/assets/LensApplet-FifF2RUs.js +1 -0
  9. package/dist/assets/LinkToCard-nR7Lal_o.js +1 -0
  10. package/dist/assets/{MarkdownEditor-7OqSDr7E.js → MarkdownEditor-CNY-VmKb.js} +2 -2
  11. package/dist/assets/{MessageComposerDialog-DzLhkHyh.js → MessageComposerDialog-gbD0Gu_b.js} +1 -1
  12. package/dist/assets/{NextShell-D9gvlKY2.js → NextShell-BIYs9fCL.js} +1 -1
  13. package/dist/assets/{NotesApplet-gMAMneRi.js → NotesApplet-D94iQKg6.js} +1 -1
  14. package/dist/assets/ObjectPropertiesCard-ChvWbOpZ.js +8 -0
  15. package/dist/assets/{ObjectPropertiesCard-C3jt40tM.css → ObjectPropertiesCard-JArcZXXv.css} +1 -1
  16. package/dist/assets/{PathPickerField-cVs5sZuG.js → PathPickerField-DBe7jykL.js} +1 -1
  17. package/dist/assets/{PickDocumentsCard-BlicxMqC.js → PickDocumentsCard-Bo224P4q.js} +1 -1
  18. package/dist/assets/{SketchApplet-D8mkYmK9.js → SketchApplet-ADVOnSLI.js} +1 -1
  19. package/dist/assets/{SketchEditor-zMrm1npg.js → SketchEditor-CkgRysCG.js} +5 -5
  20. package/dist/assets/{TerminalApplet-BO2HRp0z.js → TerminalApplet-CkO4uaE3.js} +1 -1
  21. package/dist/assets/{TextDocumentEditor-7V4aFL8i.js → TextDocumentEditor-COvsHJXH.js} +1 -1
  22. package/dist/assets/{TodosApplet-swdaBT-2.js → TodosApplet-Bpf1OIH4.js} +1 -1
  23. package/dist/assets/{TodosWidget-BXF8fYer.js → TodosWidget-BIYqPXUp.js} +1 -1
  24. package/dist/assets/{UploadProgressList-B2xCVzFR.js → UploadProgressList-BXJr87lI.js} +1 -1
  25. package/dist/assets/_agentId_-wN8YJoTZ.js +0 -0
  26. package/dist/assets/{_contextId_-DDFyhgV2.js → _contextId_-CoJraYnP.js} +1 -1
  27. package/dist/assets/{_workspaceName_-DO9ZBx7N.js → _workspaceName_-CXuIfG46.js} +1 -1
  28. package/dist/assets/{about-B1_n4Iu8.js → about-CT6Ghfkb.js} +1 -1
  29. package/dist/assets/{add-BnwWcDlO.js → add-BzgCpo5S.js} +1 -1
  30. package/dist/assets/{agents-DquOfkFX.js → agents-DIJpWCkc.js} +1 -1
  31. package/dist/assets/{agents-ClK3Y2x0.js → agents-DlLq0q2s.js} +1 -1
  32. package/dist/assets/{alert-dialog-DIA-tAP5.js → alert-dialog-izlVMXfa.js} +1 -1
  33. package/dist/assets/{api-tokens-O5iFESo0.js → api-tokens-DDH7LMJ7.js} +1 -1
  34. package/dist/assets/{appearance-C2vu3ALt.js → appearance-D1EpKWaK.js} +1 -1
  35. package/dist/assets/{applet-target-DnTa2VAT.js → applet-target-ChiiXVdC.js} +1 -1
  36. package/dist/assets/{apps-BZrw8Cqo.js → apps-DX8oWukQ.js} +1 -1
  37. package/dist/assets/{auth-CUdpxbLV.js → auth-HZNJB4wv.js} +1 -1
  38. package/dist/assets/backend-sync-progress-BeI9mDEX.js +7 -0
  39. package/dist/assets/{button-Bv4zA1qr.js → button-SgR3GVvV.js} +1 -1
  40. package/dist/assets/content-app-view-DS6Nrz6M.js +1 -0
  41. package/dist/assets/{context-D_K4g9SQ.js → context-mfIOB8dN.js} +1 -1
  42. package/dist/assets/{contexts-CgydYDn-2.js → contexts-CRWqFXzJ2.js} +1 -1
  43. package/dist/assets/{contexts-B6d6Axza.js → contexts-Ef3fHwv6.js} +1 -1
  44. package/dist/assets/{date-time-picker-BZaA3M9_.js → date-time-picker-B6mkWt-g.js} +1 -1
  45. package/dist/assets/{devices-D3-_UWM0.js → devices-C3gLuNDv.js} +1 -1
  46. package/dist/assets/{document-BG_mODBn.js → document-CX543Kcz.js} +1 -1
  47. package/dist/assets/document-list-SsF3jmuq.js +2 -0
  48. package/dist/assets/{embedding-m8SZH4oN.js → embedding-BHnBCyUx.js} +1 -1
  49. package/dist/assets/{embedding-Cjrxh6MN.js → embedding-CEGjemkq.js} +1 -1
  50. package/dist/assets/{form-panel-Dz96K7Lv.js → form-panel-C34lByEH.js} +1 -1
  51. package/dist/assets/{home-pS7q4Wl4.js → home-3vhobmCu.js} +1 -1
  52. package/dist/assets/index-CiBgHujl.js +16 -0
  53. package/dist/assets/index-D7EoeBID.css +2 -0
  54. package/dist/assets/{inferd-config-editor-DagMmwW4.js → inferd-config-editor-BHUUFArV.js} +1 -1
  55. package/dist/assets/{key-bindings-BOtykyXR.js → key-bindings-BNeY-GEg.js} +1 -1
  56. package/dist/assets/{label-CNoJOoe0.js → label-Dn4gCMcc.js} +1 -1
  57. package/dist/assets/{lazy-editor-Cbva8Pe2.js → lazy-editor-BSRnneOo.js} +2 -2
  58. package/dist/assets/{logs-CdbfY8_H.js → logs-Czn2sPeP.js} +1 -1
  59. package/dist/assets/{offline-BjMpUv3N.js → offline-CsRyFUg7.js} +1 -1
  60. package/dist/assets/{page-header-GtTr9Ff_.js → page-header-DkOHw0g-.js} +1 -1
  61. package/dist/assets/{public-share-DT9Tgn_Y.js → public-share-DXxVwHKT.js} +1 -1
  62. package/dist/assets/{query-debug-tVbB_8Z6.js → query-debug-BUUG3jpK.js} +1 -1
  63. package/dist/assets/{registry-6tE_1KPV.js → registry-DTWAywyJ.js} +2 -2
  64. package/dist/assets/{remotes-DR_iJClb.js → remotes-CdEU1Y5l.js} +1 -1
  65. package/dist/assets/{roles-DERIgujv.js → roles-BYHLwWCD.js} +1 -1
  66. package/dist/assets/roles-BpVWTMmp.js +2 -0
  67. package/dist/assets/settings-DH3ZiQLR.js +14 -0
  68. package/dist/assets/{settings-vosK_LI-.js → settings-DNhy58i9.js} +1 -1
  69. package/dist/assets/{settings-Du8r1SXC.js → settings-DjnFAqIe.js} +1 -1
  70. package/dist/assets/settings-jWfP7CP8.js +1 -0
  71. package/dist/assets/{share-target-Df10J5JB.js → share-target-CgHlnZLH.js} +1 -1
  72. package/dist/assets/{shared-C7b3QOUP.js → shared-BMoiShd9.js} +1 -1
  73. package/dist/assets/{shared-1dpCuibu.js → shared-D2uRUNdC.js} +1 -1
  74. package/dist/assets/sketch-lazy-pbG2cCpW.js +2 -0
  75. package/dist/assets/{subtree-transfer-dialog-B7s4r78T.js → subtree-transfer-dialog-ChBI5llU.js} +1 -1
  76. package/dist/assets/{text-documents-D_zDMyhB.js → text-documents-BvDFBVnC.js} +1 -1
  77. package/dist/assets/ui-Byg1cZDr.js +41 -0
  78. package/dist/assets/{use-applet-docs-Cry2SFsG.js → use-applet-docs-o5NAUFBk.js} +1 -1
  79. package/dist/assets/{use-applet-target-mkjQujx6.js → use-applet-target-cO-FiyPQ.js} +1 -1
  80. package/dist/assets/{use-canvas-pins-CZBfEB5E.js → use-canvas-pins-Bth_Q--t.js} +2 -2
  81. package/dist/assets/{use-menu-BVkqNEIx.js → use-menu-BiJ8N7sS.js} +1 -1
  82. package/dist/assets/use-settings-back-CQauYjQ4.js +1 -0
  83. package/dist/assets/{use-sortable-data-DYIDDI8c.js → use-sortable-data-BW_0sXBs.js} +1 -1
  84. package/dist/assets/{use-workspace-identity-BVpGHkZq.js → use-workspace-identity-mgaofjsD.js} +1 -1
  85. package/dist/assets/{useAddTarget-CVRPElxz.js → useAddTarget-DUjaZdBQ.js} +1 -1
  86. package/dist/assets/{useAgentModels-DI41aFY3.js → useAgentModels-Sa4N8WFd.js} +1 -1
  87. package/dist/assets/{useDocumentThumbnail-C_rq2rXs.js → useDocumentThumbnail-DYLCC63L.js} +1 -1
  88. package/dist/assets/{useEditNoteFields-Bigs9ZG8.js → useEditNoteFields-zHEWwDfB.js} +1 -1
  89. package/dist/assets/{users-C9N-O1QA.js → users-CKz9kOoR.js} +1 -1
  90. package/dist/assets/{workspace-CJ1PWQ29.js → workspace-DvxC7pw1.js} +1 -1
  91. package/dist/assets/{workspace-area-menu-Ba_9bGKs.js → workspace-area-menu-UamvRNfd.js} +1 -1
  92. package/dist/assets/{workspace-content-gate-D8bzGD9i.js → workspace-content-gate-Be4tLYiB.js} +1 -1
  93. package/dist/assets/{workspace-import-form-D5JA8gzx.js → workspace-import-form-BRwc_oVg.js} +1 -1
  94. package/dist/assets/{workspaces-Dx5_N57M.js → workspaces-Da_hUIj3.js} +1 -1
  95. package/dist/assets/workspaces-gQY1mczH.js +1 -0
  96. package/dist/index.html +37 -37
  97. package/dist/sw.js +1 -1
  98. package/package.json +2 -2
  99. package/dist/assets/LensApplet-DNTGwgZs.js +0 -1
  100. package/dist/assets/LinkToCard-BZwwE-Dv.js +0 -1
  101. package/dist/assets/ObjectPropertiesCard-DDcRLpsW.js +0 -8
  102. package/dist/assets/_agentId_-Ci4j4UYy.js +0 -0
  103. package/dist/assets/backend-sync-progress-DWR42uQV.js +0 -7
  104. package/dist/assets/content-app-view-C33Ip_rx.js +0 -1
  105. package/dist/assets/document-list-BiogH4tf.js +0 -2
  106. package/dist/assets/index-C10UNpew.css +0 -2
  107. package/dist/assets/index-exXolIqD.js +0 -16
  108. package/dist/assets/roles-DswT1Lv0.js +0 -2
  109. package/dist/assets/settings-Cc6OMCOX.js +0 -14
  110. package/dist/assets/settings-D7K7z_JD.js +0 -1
  111. package/dist/assets/sketch-lazy-Q58-vPF-.js +0 -2
  112. package/dist/assets/ui-BSqPn1LJ.js +0 -41
  113. package/dist/assets/use-settings-back-Dk-DJEUO.js +0 -1
  114. package/dist/assets/workspaces-C9Wtka2V.js +0 -1
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{I as i,Mt as a,Pt as o,Yr as s,br as c,rt as l,tn as u}from"./ui-BSqPn1LJ.js";import{t as d}from"./button-Bv4zA1qr.js";import{t as f}from"./input-BOtCd4HP.js";import{n as p}from"./use-toast-BlLDqSUO.js";import{t as m}from"./color-DFEH4BfK.js";import{F as h,K as g,Q as _,Tt as v,Z as y}from"./index-exXolIqD.js";import{n as b}from"./page-header-GtTr9Ff_.js";import{n as ee,r as x,t as te}from"./useAgentModels-DI41aFY3.js";import{t as ne}from"./form-panel-Dz96K7Lv.js";import{t as re}from"./use-create-panel-DhSNIGtr.js";import{n as ie,t as ae}from"./useSocketSubscription-ifW-vnlb.js";var S=e(n(),1),C=t();function w({agent:e,onStart:t,onStop:n,onEnter:r}){let[a,f]=(0,S.useState)(!1),p=async()=>{f(!0);try{await t(e.name)}finally{f(!1)}},m=async()=>{f(!0);try{await n(e.name)}finally{f(!1)}},h=()=>{switch(e.status){case`active`:return(0,C.jsx)(c,{className:`h-4 w-4 text-success`});case`inactive`:return(0,C.jsx)(c,{className:`h-4 w-4 text-warning`});case`error`:return(0,C.jsx)(c,{className:`h-4 w-4 text-destructive`});default:return(0,C.jsx)(c,{className:`h-4 w-4 text-muted-foreground`})}},g=()=>{switch(e.llmProvider){case`anthropic`:return(0,C.jsx)(s,{className:`h-4 w-4 text-warning`});case`openai`:return(0,C.jsx)(s,{className:`h-4 w-4 text-success`});case`ollama`:return(0,C.jsx)(i,{className:`h-4 w-4 text-info`});default:return(0,C.jsx)(s,{className:`h-4 w-4 text-muted-foreground`})}},_=()=>{switch(e.status){case`active`:return`text-success bg-success-subtle border-success`;case`inactive`:return`text-warning bg-warning-subtle border-warning`;case`error`:return`text-destructive bg-destructive-subtle border-destructive`;case`available`:return`text-info bg-info-subtle border-info`;default:return`text-foreground bg-muted border-border`}},v=e.status===`available`||e.status===`inactive`,y=e.status===`active`;return(0,C.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 hover:shadow-elevation-2 transition-shadow bg-card`,children:[(0,C.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[g(),(0,C.jsx)(`h3`,{className:`text-lg font-semibold truncate`,children:e.label||e.name}),e.color&&(0,C.jsx)(`div`,{className:`w-4 h-4 rounded border flex-shrink-0`,style:{backgroundColor:e.color},title:`Color: ${e.color}`})]}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground font-mono`,children:e.name}),e.description&&(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:e.description})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[h(),(0,C.jsx)(`span`,{className:`px-2 py-1 rounded-full text-xs font-medium border ${_()}`,children:e.status})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 text-sm`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider:`}),(0,C.jsx)(`div`,{className:`font-medium capitalize`,children:e.llmProvider})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Model:`}),(0,C.jsx)(`div`,{className:`font-mono text-xs`,children:e.model})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Created:`}),(0,C.jsx)(`div`,{children:new Date(e.createdAt).toLocaleDateString()})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Last Access:`}),(0,C.jsx)(`div`,{children:e.lastAccessed?new Date(e.lastAccessed).toLocaleDateString():`Never`})]})]}),e.config.mcp?.servers&&e.config.mcp.servers.length>0&&(0,C.jsxs)(`div`,{className:`text-sm`,children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`MCP Servers:`}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.config.mcp.servers.map((e,t)=>(0,C.jsx)(`span`,{className:`px-2 py-1 bg-secondary text-secondary-foreground rounded text-xs`,children:e.name},t))})]}),(0,C.jsxs)(`div`,{className:`flex gap-2 pt-2 border-t`,children:[v&&(0,C.jsxs)(d,{onClick:p,disabled:a,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(o,{className:`mr-2 h-4 w-4`}),`Start`]}),y&&(0,C.jsxs)(d,{onClick:m,disabled:a,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(l,{className:`mr-2 h-4 w-4`}),`Stop`]}),(0,C.jsxs)(d,{onClick:()=>r(e.name),size:`sm`,className:`flex-1`,children:[(0,C.jsx)(u,{className:`mr-2 h-4 w-4`}),`Chat`]})]})]})}function T(){let e={anthropic:`https://api.anthropic.com`,openai:`https://api.openai.com/v1`,ollama:`http://localhost:11434/v1`},t={anthropic:`claude-3-5-sonnet-20241022`,openai:`gpt-4o`,ollama:`qwen2.5-coder:latest`},[n,i]=(0,S.useState)([]),[o,s]=(0,S.useState)(!0),[c,l]=(0,S.useState)(null),[u,T]=(0,S.useState)(``),[E,D]=(0,S.useState)(``),[O,k]=(0,S.useState)(m()),[A,j]=(0,S.useState)(``),[M,oe]=(0,S.useState)(`anthropic`),[N,P]=(0,S.useState)(t.anthropic),[F,I]=(0,S.useState)({apiKey:``,baseUrl:e.anthropic,maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),L=te(M,F.apiKey,F.baseUrl),R=L.models.find(e=>e.id===N),[z,B]=(0,S.useState)(``),[V,H]=(0,S.useState)(``),[U,W]=(0,S.useState)(``),[G,K]=(0,S.useState)(``),[q,J]=(0,S.useState)(!1),Y=v(),[X,Z]=re(),{showToast:Q}=p(),se=r(),$=ie();ae($,`agent`,{"agent:status:changed":e=>{i(t=>t.map(t=>t.id===e.agentId?{...t,status:e.status,isActive:e.isActive}:t))},"agent:created":e=>{i(t=>[...t,e.agent])},"agent:deleted":e=>{i(t=>t.filter(t=>t.id!==e.agentId))}});let ce=n=>{oe(n),P(t[n]),I({apiKey:``,baseUrl:e[n],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096})};(0,S.useEffect)(()=>((async()=>{try{s(!0);let e=await g();i(e),l(null)}catch(e){console.error(`Agent fetch error:`,e);let t=`Failed to fetch agents`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to fetch agents`}l(t),Q({title:`Error`,description:t,variant:`destructive`})}finally{s(!1)}})(),()=>{}),[$,Q]);let le=async t=>{if(t.preventDefault(),u.trim()){J(!0);try{let t=G.trim()||x(z,V,U),n={name:u,label:A||u,description:E||void 0,color:O,llmProvider:M,model:N,apiKey:F.apiKey.trim()||void 0,baseUrl:F.baseUrl.trim()||void 0,config:{type:M,model:N,identity:{role:z.trim()||void 0,identity:V.trim()||void 0,instructions:U.trim()||void 0},prompts:t?{system:t}:void 0,connectors:{[M]:{maxTokens:F.maxTokens,...M===`anthropic`?{}:{temperature:F.temperature},topP:F.topP,frequencyPenalty:F.frequencyPenalty,presencePenalty:F.presencePenalty,...M===`ollama`?{numCtx:F.numCtx}:{}}}},mcp:{enabled:!0,servers:[{name:`weather`,command:`node`,args:[`src/managers/agent/mcp-servers/weather.js`]}]}},r=await h(n);i(e=>[...e,r]),T(``),D(``),k(m()),j(``),K(``),B(``),H(``),W(``),I({apiKey:``,baseUrl:e[M],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),Q({title:`Success`,description:`Agent '${r.label||r.name}' created.`}),Z(!1)}catch(e){console.error(`Agent creation error:`,e);let t=`Failed to create agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to create agent`}Q({title:`Error`,description:t,variant:`destructive`})}finally{J(!1)}}},ue=async e=>{try{let t=await y(e);i(e=>e.map(e=>e.name===t.name?t:e)),Q({title:`Success`,description:`Agent '${t.label||t.name}' started.`})}catch(e){console.error(`Agent start error:`,e);let t=`Failed to start agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to start agent`}Q({title:`Error`,description:t,variant:`destructive`})}},de=async e=>{try{await _(e),i(t=>t.map(t=>t.name===e?{...t,status:`inactive`,isActive:!1}:t)),Q({title:`Success`,description:`Agent '${e}' stopped.`})}catch(e){console.error(`Agent stop error:`,e);let t=`Failed to stop agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to stop agent`}Q({title:`Error`,description:t,variant:`destructive`})}},fe=e=>{se(`/agents/${e}`)};return(0,C.jsxs)(`div`,{className:`space-y-6`,children:[(0,C.jsx)(b,{title:`AI Agents`,description:`Create and manage your AI agents with multiple LLM providers`,actions:!Y.local&&!X&&(0,C.jsxs)(d,{onClick:()=>Z(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create agent`,title:`Create agent`,children:[(0,C.jsx)(a,{className:`h-4 w-4 sm:mr-2`}),(0,C.jsx)(`span`,{className:`max-sm:hidden`,children:`Create Agent`})]})}),!Y.local&&X&&(0,C.jsx)(ne,{title:`Create New Agent`,onClose:()=>Z(!1),children:(0,C.jsxs)(`form`,{onSubmit:le,className:`space-y-4`,children:[(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsx)(f,{value:u,onChange:e=>T(e.target.value),placeholder:`Agent Name (e.g., 'my-assistant')`,disabled:q}),(0,C.jsx)(f,{value:A,onChange:e=>j(e.target.value),placeholder:`Agent Label (display name, optional)`,disabled:q})]}),(0,C.jsx)(f,{value:E,onChange:e=>D(e.target.value),placeholder:`Description (optional)`,disabled:q}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-provider`,className:`text-sm font-medium`,children:`LLM Provider`}),(0,C.jsxs)(`select`,{id:`agent-provider`,value:M,onChange:e=>ce(e.target.value),className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring`,disabled:q,children:[(0,C.jsx)(`option`,{value:`anthropic`,children:`Anthropic Claude`}),(0,C.jsx)(`option`,{value:`openai`,children:`OpenAI GPT`}),(0,C.jsx)(`option`,{value:`ollama`,children:`Ollama (Local)`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-model`,className:`text-sm font-medium`,children:`Model`}),(0,C.jsx)(ee,{id:`agent-model`,value:N,onChange:(e,t)=>{P(e),t?.maxTokens&&I(e=>({...e,maxTokens:t.maxTokens}))},...L,disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`Persona`}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-role`,className:`text-sm font-medium`,children:`Role`}),(0,C.jsx)(f,{id:`agent-role`,value:z,onChange:e=>B(e.target.value),placeholder:`e.g. Software Engineer`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-identity`,className:`text-sm font-medium`,children:`Identity`}),(0,C.jsx)(`textarea`,{id:`agent-identity`,value:V,onChange:e=>H(e.target.value),placeholder:`Who this agent is…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-instructions`,className:`text-sm font-medium`,children:`Instructions`}),(0,C.jsx)(`textarea`,{id:`agent-instructions`,value:U,onChange:e=>W(e.target.value),placeholder:`Behavioral instructions…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`system-prompt`,className:`text-sm font-medium`,children:`System Prompt (Optional Override)`}),(0,C.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Built from Role, Identity and Instructions unless you enter an override.`}),(0,C.jsx)(`textarea`,{id:`system-prompt`,value:G,onChange:e=>K(e.target.value),placeholder:x(z,V,U)||`System prompt sent to the LLM…`,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring min-h-[80px] resize-y`,disabled:q})]}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`api-key`,className:`text-sm font-medium`,children:`API Key (Optional)`}),(0,C.jsx)(f,{id:`api-key`,type:`password`,value:F.apiKey,onChange:e=>I(t=>({...t,apiKey:e.target.value})),placeholder:`Enter your API key`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`baseUrl`,className:`text-sm font-medium`,children:`Base URL (Optional)`}),(0,C.jsx)(f,{id:`baseUrl`,value:F.baseUrl,onChange:e=>I(t=>({...t,baseUrl:e.target.value})),placeholder:e[M],disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`LLM Parameters`}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`max-tokens`,className:`text-sm font-medium`,children:`Max Output Tokens`}),(0,C.jsx)(f,{id:`max-tokens`,type:`number`,min:`1`,max:R?.maxTokens,value:F.maxTokens,onChange:e=>I(t=>({...t,maxTokens:parseInt(e.target.value)||4096})),disabled:q})]}),M!==`anthropic`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`temperature`,className:`text-sm font-medium`,children:`Temperature`}),(0,C.jsx)(f,{id:`temperature`,type:`number`,min:`0`,max:`2`,step:`0.1`,value:F.temperature,onChange:e=>I(t=>({...t,temperature:Number.isNaN(e.target.valueAsNumber)?.7:e.target.valueAsNumber})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`top-p`,className:`text-sm font-medium`,children:`Top P`}),(0,C.jsx)(f,{id:`top-p`,type:`number`,min:`0`,max:`1`,step:`0.1`,value:F.topP,onChange:e=>I(t=>({...t,topP:Number.isNaN(e.target.valueAsNumber)?1:e.target.valueAsNumber})),disabled:q})]}),M===`ollama`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`num-ctx`,className:`text-sm font-medium`,children:`Context Length`}),(0,C.jsx)(f,{id:`num-ctx`,type:`number`,min:`1024`,max:R?.contextWindow,value:F.numCtx,onChange:e=>I(t=>({...t,numCtx:parseInt(e.target.value)||4096})),disabled:q})]})]}),M!==`ollama`&&(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`frequency-penalty`,className:`text-sm font-medium`,children:`Frequency Penalty`}),(0,C.jsx)(f,{id:`frequency-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.frequencyPenalty,onChange:e=>I(t=>({...t,frequencyPenalty:parseFloat(e.target.value)||0})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`presence-penalty`,className:`text-sm font-medium`,children:`Presence Penalty`}),(0,C.jsx)(f,{id:`presence-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.presencePenalty,onChange:e=>I(t=>({...t,presencePenalty:parseFloat(e.target.value)||0})),disabled:q})]})]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`label`,{htmlFor:`agent-color`,className:`text-sm font-medium`,children:`Agent Color`}),(0,C.jsx)(f,{id:`agent-color`,type:`color`,value:O,onChange:e=>k(e.target.value),className:`h-10 w-16 p-1`,disabled:q}),(0,C.jsx)(d,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>k(m()),disabled:q,children:`Randomize`})]}),(0,C.jsxs)(d,{type:`submit`,disabled:q||!u.trim(),children:[(0,C.jsx)(a,{className:`mr-2 h-4 w-4`}),`Create Agent`]})]})}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your Agents`}),o&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading agents...`}),c&&(0,C.jsx)(`div`,{className:`text-center text-destructive`,children:(0,C.jsx)(`p`,{children:c})}),!o&&!c&&n.length===0&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No agents found`}),n.length>0&&(0,C.jsx)(`div`,{className:`grid gap-4`,children:n.map(e=>(0,C.jsx)(w,{agent:e,onStart:ue,onStop:de,onEnter:fe},e.id))})]})]})}export{T as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Ft as i,I as a,Nt as o,Xr as s,nn as c,rt as l,xr as u}from"./ui-Byg1cZDr.js";import{t as d}from"./button-SgR3GVvV.js";import{t as f}from"./input-BOtCd4HP.js";import{n as p}from"./use-toast-BlLDqSUO.js";import{t as m}from"./color-DFEH4BfK.js";import{$ as h,Et as g,I as _,Q as v,q as y}from"./index-CiBgHujl.js";import{n as b}from"./page-header-DkOHw0g-.js";import{n as ee,r as x,t as te}from"./useAgentModels-Sa4N8WFd.js";import{t as ne}from"./form-panel-C34lByEH.js";import{t as re}from"./use-create-panel-DhSNIGtr.js";import{n as ie,t as ae}from"./useSocketSubscription-ifW-vnlb.js";var S=e(n(),1),C=t();function w({agent:e,onStart:t,onStop:n,onEnter:r}){let[o,f]=(0,S.useState)(!1),p=async()=>{f(!0);try{await t(e.name)}finally{f(!1)}},m=async()=>{f(!0);try{await n(e.name)}finally{f(!1)}},h=()=>{switch(e.status){case`active`:return(0,C.jsx)(u,{className:`h-4 w-4 text-success`});case`inactive`:return(0,C.jsx)(u,{className:`h-4 w-4 text-warning`});case`error`:return(0,C.jsx)(u,{className:`h-4 w-4 text-destructive`});default:return(0,C.jsx)(u,{className:`h-4 w-4 text-muted-foreground`})}},g=()=>{switch(e.llmProvider){case`anthropic`:return(0,C.jsx)(s,{className:`h-4 w-4 text-warning`});case`openai`:return(0,C.jsx)(s,{className:`h-4 w-4 text-success`});case`ollama`:return(0,C.jsx)(a,{className:`h-4 w-4 text-info`});default:return(0,C.jsx)(s,{className:`h-4 w-4 text-muted-foreground`})}},_=()=>{switch(e.status){case`active`:return`text-success bg-success-subtle border-success`;case`inactive`:return`text-warning bg-warning-subtle border-warning`;case`error`:return`text-destructive bg-destructive-subtle border-destructive`;case`available`:return`text-info bg-info-subtle border-info`;default:return`text-foreground bg-muted border-border`}},v=e.status===`available`||e.status===`inactive`,y=e.status===`active`;return(0,C.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 hover:shadow-elevation-2 transition-shadow bg-card`,children:[(0,C.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[g(),(0,C.jsx)(`h3`,{className:`text-lg font-semibold truncate`,children:e.label||e.name}),e.color&&(0,C.jsx)(`div`,{className:`w-4 h-4 rounded border flex-shrink-0`,style:{backgroundColor:e.color},title:`Color: ${e.color}`})]}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground font-mono`,children:e.name}),e.description&&(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:e.description})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[h(),(0,C.jsx)(`span`,{className:`px-2 py-1 rounded-full text-xs font-medium border ${_()}`,children:e.status})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 text-sm`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider:`}),(0,C.jsx)(`div`,{className:`font-medium capitalize`,children:e.llmProvider})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Model:`}),(0,C.jsx)(`div`,{className:`font-mono text-xs`,children:e.model})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Created:`}),(0,C.jsx)(`div`,{children:new Date(e.createdAt).toLocaleDateString()})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Last Access:`}),(0,C.jsx)(`div`,{children:e.lastAccessed?new Date(e.lastAccessed).toLocaleDateString():`Never`})]})]}),e.config.mcp?.servers&&e.config.mcp.servers.length>0&&(0,C.jsxs)(`div`,{className:`text-sm`,children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`MCP Servers:`}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.config.mcp.servers.map((e,t)=>(0,C.jsx)(`span`,{className:`px-2 py-1 bg-secondary text-secondary-foreground rounded text-xs`,children:e.name},t))})]}),(0,C.jsxs)(`div`,{className:`flex gap-2 pt-2 border-t`,children:[v&&(0,C.jsxs)(d,{onClick:p,disabled:o,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(i,{className:`mr-2 h-4 w-4`}),`Start`]}),y&&(0,C.jsxs)(d,{onClick:m,disabled:o,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(l,{className:`mr-2 h-4 w-4`}),`Stop`]}),(0,C.jsxs)(d,{onClick:()=>r(e.name),size:`sm`,className:`flex-1`,children:[(0,C.jsx)(c,{className:`mr-2 h-4 w-4`}),`Chat`]})]})]})}function T(){let e={anthropic:`https://api.anthropic.com`,openai:`https://api.openai.com/v1`,ollama:`http://localhost:11434/v1`},t={anthropic:`claude-3-5-sonnet-20241022`,openai:`gpt-4o`,ollama:`qwen2.5-coder:latest`},[n,i]=(0,S.useState)([]),[a,s]=(0,S.useState)(!0),[c,l]=(0,S.useState)(null),[u,T]=(0,S.useState)(``),[E,D]=(0,S.useState)(``),[O,k]=(0,S.useState)(m()),[A,j]=(0,S.useState)(``),[M,oe]=(0,S.useState)(`anthropic`),[N,P]=(0,S.useState)(t.anthropic),[F,I]=(0,S.useState)({apiKey:``,baseUrl:e.anthropic,maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),L=te(M,F.apiKey,F.baseUrl),R=L.models.find(e=>e.id===N),[z,B]=(0,S.useState)(``),[V,H]=(0,S.useState)(``),[U,W]=(0,S.useState)(``),[G,K]=(0,S.useState)(``),[q,J]=(0,S.useState)(!1),Y=g(),[X,Z]=re(),{showToast:Q}=p(),se=r(),$=ie();ae($,`agent`,{"agent:status:changed":e=>{i(t=>t.map(t=>t.id===e.agentId?{...t,status:e.status,isActive:e.isActive}:t))},"agent:created":e=>{i(t=>[...t,e.agent])},"agent:deleted":e=>{i(t=>t.filter(t=>t.id!==e.agentId))}});let ce=n=>{oe(n),P(t[n]),I({apiKey:``,baseUrl:e[n],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096})};(0,S.useEffect)(()=>((async()=>{try{s(!0);let e=await y();i(e),l(null)}catch(e){console.error(`Agent fetch error:`,e);let t=`Failed to fetch agents`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to fetch agents`}l(t),Q({title:`Error`,description:t,variant:`destructive`})}finally{s(!1)}})(),()=>{}),[$,Q]);let le=async t=>{if(t.preventDefault(),u.trim()){J(!0);try{let t=G.trim()||x(z,V,U),n={name:u,label:A||u,description:E||void 0,color:O,llmProvider:M,model:N,apiKey:F.apiKey.trim()||void 0,baseUrl:F.baseUrl.trim()||void 0,config:{type:M,model:N,identity:{role:z.trim()||void 0,identity:V.trim()||void 0,instructions:U.trim()||void 0},prompts:t?{system:t}:void 0,connectors:{[M]:{maxTokens:F.maxTokens,...M===`anthropic`?{}:{temperature:F.temperature},topP:F.topP,frequencyPenalty:F.frequencyPenalty,presencePenalty:F.presencePenalty,...M===`ollama`?{numCtx:F.numCtx}:{}}}},mcp:{enabled:!0,servers:[{name:`weather`,command:`node`,args:[`src/managers/agent/mcp-servers/weather.js`]}]}},r=await _(n);i(e=>[...e,r]),T(``),D(``),k(m()),j(``),K(``),B(``),H(``),W(``),I({apiKey:``,baseUrl:e[M],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),Q({title:`Success`,description:`Agent '${r.label||r.name}' created.`}),Z(!1)}catch(e){console.error(`Agent creation error:`,e);let t=`Failed to create agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to create agent`}Q({title:`Error`,description:t,variant:`destructive`})}finally{J(!1)}}},ue=async e=>{try{let t=await v(e);i(e=>e.map(e=>e.name===t.name?t:e)),Q({title:`Success`,description:`Agent '${t.label||t.name}' started.`})}catch(e){console.error(`Agent start error:`,e);let t=`Failed to start agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to start agent`}Q({title:`Error`,description:t,variant:`destructive`})}},de=async e=>{try{await h(e),i(t=>t.map(t=>t.name===e?{...t,status:`inactive`,isActive:!1}:t)),Q({title:`Success`,description:`Agent '${e}' stopped.`})}catch(e){console.error(`Agent stop error:`,e);let t=`Failed to stop agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to stop agent`}Q({title:`Error`,description:t,variant:`destructive`})}},fe=e=>{se(`/agents/${e}`)};return(0,C.jsxs)(`div`,{className:`space-y-6`,children:[(0,C.jsx)(b,{title:`AI Agents`,description:`Create and manage your AI agents with multiple LLM providers`,actions:!Y.local&&!X&&(0,C.jsxs)(d,{onClick:()=>Z(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create agent`,title:`Create agent`,children:[(0,C.jsx)(o,{className:`h-4 w-4 sm:mr-2`}),(0,C.jsx)(`span`,{className:`max-sm:hidden`,children:`Create Agent`})]})}),!Y.local&&X&&(0,C.jsx)(ne,{title:`Create New Agent`,onClose:()=>Z(!1),children:(0,C.jsxs)(`form`,{onSubmit:le,className:`space-y-4`,children:[(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsx)(f,{value:u,onChange:e=>T(e.target.value),placeholder:`Agent Name (e.g., 'my-assistant')`,disabled:q}),(0,C.jsx)(f,{value:A,onChange:e=>j(e.target.value),placeholder:`Agent Label (display name, optional)`,disabled:q})]}),(0,C.jsx)(f,{value:E,onChange:e=>D(e.target.value),placeholder:`Description (optional)`,disabled:q}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-provider`,className:`text-sm font-medium`,children:`LLM Provider`}),(0,C.jsxs)(`select`,{id:`agent-provider`,value:M,onChange:e=>ce(e.target.value),className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring`,disabled:q,children:[(0,C.jsx)(`option`,{value:`anthropic`,children:`Anthropic Claude`}),(0,C.jsx)(`option`,{value:`openai`,children:`OpenAI GPT`}),(0,C.jsx)(`option`,{value:`ollama`,children:`Ollama (Local)`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-model`,className:`text-sm font-medium`,children:`Model`}),(0,C.jsx)(ee,{id:`agent-model`,value:N,onChange:(e,t)=>{P(e),t?.maxTokens&&I(e=>({...e,maxTokens:t.maxTokens}))},...L,disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`Persona`}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-role`,className:`text-sm font-medium`,children:`Role`}),(0,C.jsx)(f,{id:`agent-role`,value:z,onChange:e=>B(e.target.value),placeholder:`e.g. Software Engineer`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-identity`,className:`text-sm font-medium`,children:`Identity`}),(0,C.jsx)(`textarea`,{id:`agent-identity`,value:V,onChange:e=>H(e.target.value),placeholder:`Who this agent is…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-instructions`,className:`text-sm font-medium`,children:`Instructions`}),(0,C.jsx)(`textarea`,{id:`agent-instructions`,value:U,onChange:e=>W(e.target.value),placeholder:`Behavioral instructions…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`system-prompt`,className:`text-sm font-medium`,children:`System Prompt (Optional Override)`}),(0,C.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Built from Role, Identity and Instructions unless you enter an override.`}),(0,C.jsx)(`textarea`,{id:`system-prompt`,value:G,onChange:e=>K(e.target.value),placeholder:x(z,V,U)||`System prompt sent to the LLM…`,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring min-h-[80px] resize-y`,disabled:q})]}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`api-key`,className:`text-sm font-medium`,children:`API Key (Optional)`}),(0,C.jsx)(f,{id:`api-key`,type:`password`,value:F.apiKey,onChange:e=>I(t=>({...t,apiKey:e.target.value})),placeholder:`Enter your API key`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`baseUrl`,className:`text-sm font-medium`,children:`Base URL (Optional)`}),(0,C.jsx)(f,{id:`baseUrl`,value:F.baseUrl,onChange:e=>I(t=>({...t,baseUrl:e.target.value})),placeholder:e[M],disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`LLM Parameters`}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`max-tokens`,className:`text-sm font-medium`,children:`Max Output Tokens`}),(0,C.jsx)(f,{id:`max-tokens`,type:`number`,min:`1`,max:R?.maxTokens,value:F.maxTokens,onChange:e=>I(t=>({...t,maxTokens:parseInt(e.target.value)||4096})),disabled:q})]}),M!==`anthropic`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`temperature`,className:`text-sm font-medium`,children:`Temperature`}),(0,C.jsx)(f,{id:`temperature`,type:`number`,min:`0`,max:`2`,step:`0.1`,value:F.temperature,onChange:e=>I(t=>({...t,temperature:Number.isNaN(e.target.valueAsNumber)?.7:e.target.valueAsNumber})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`top-p`,className:`text-sm font-medium`,children:`Top P`}),(0,C.jsx)(f,{id:`top-p`,type:`number`,min:`0`,max:`1`,step:`0.1`,value:F.topP,onChange:e=>I(t=>({...t,topP:Number.isNaN(e.target.valueAsNumber)?1:e.target.valueAsNumber})),disabled:q})]}),M===`ollama`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`num-ctx`,className:`text-sm font-medium`,children:`Context Length`}),(0,C.jsx)(f,{id:`num-ctx`,type:`number`,min:`1024`,max:R?.contextWindow,value:F.numCtx,onChange:e=>I(t=>({...t,numCtx:parseInt(e.target.value)||4096})),disabled:q})]})]}),M!==`ollama`&&(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`frequency-penalty`,className:`text-sm font-medium`,children:`Frequency Penalty`}),(0,C.jsx)(f,{id:`frequency-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.frequencyPenalty,onChange:e=>I(t=>({...t,frequencyPenalty:parseFloat(e.target.value)||0})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`presence-penalty`,className:`text-sm font-medium`,children:`Presence Penalty`}),(0,C.jsx)(f,{id:`presence-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.presencePenalty,onChange:e=>I(t=>({...t,presencePenalty:parseFloat(e.target.value)||0})),disabled:q})]})]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`label`,{htmlFor:`agent-color`,className:`text-sm font-medium`,children:`Agent Color`}),(0,C.jsx)(f,{id:`agent-color`,type:`color`,value:O,onChange:e=>k(e.target.value),className:`h-10 w-16 p-1`,disabled:q}),(0,C.jsx)(d,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>k(m()),disabled:q,children:`Randomize`})]}),(0,C.jsxs)(d,{type:`submit`,disabled:q||!u.trim(),children:[(0,C.jsx)(o,{className:`mr-2 h-4 w-4`}),`Create Agent`]})]})}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your Agents`}),a&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading agents...`}),c&&(0,C.jsx)(`div`,{className:`text-center text-destructive`,children:(0,C.jsx)(`p`,{children:c})}),!a&&!c&&n.length===0&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No agents found`}),n.length>0&&(0,C.jsx)(`div`,{className:`grid gap-4`,children:n.map(e=>(0,C.jsx)(w,{agent:e,onStart:ue,onStop:de,onEnter:fe},e.id))})]})]})}export{T as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{i as r}from"./auth-Bx9fAZmz.js";import{n as i}from"./page-header-GtTr9Ff_.js";var a=e(n(),1),o=t();function s(){let e=r()?.userType===`admin`;return(0,a.useEffect)(()=>{},[e]),e?(0,o.jsxs)(`div`,{className:`space-y-6`,children:[(0,o.jsx)(i,{title:`All Agents`,description:`Manage all AI agents across all users`}),(0,o.jsx)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:(0,o.jsxs)(`div`,{className:`text-center`,children:[(0,o.jsx)(`h2`,{className:`text-2xl font-semibold mb-2`,children:`Coming Soon`}),(0,o.jsx)(`p`,{className:`text-muted-foreground max-w-md`,children:`Global agent management is currently under development. Check back later for updates.`})]})})]}):(0,o.jsx)(`div`,{className:`text-center space-y-4`,children:(0,o.jsx)(`div`,{className:`text-destructive`,children:`Access denied. Admin privileges required.`})})}export{s as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{i as r}from"./auth-Bx9fAZmz.js";import{n as i}from"./page-header-DkOHw0g-.js";var a=e(n(),1),o=t();function s(){let e=r()?.userType===`admin`;return(0,a.useEffect)(()=>{},[e]),e?(0,o.jsxs)(`div`,{className:`space-y-6`,children:[(0,o.jsx)(i,{title:`All Agents`,description:`Manage all AI agents across all users`}),(0,o.jsx)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:(0,o.jsxs)(`div`,{className:`text-center`,children:[(0,o.jsx)(`h2`,{className:`text-2xl font-semibold mb-2`,children:`Coming Soon`}),(0,o.jsx)(`p`,{className:`text-muted-foreground max-w-md`,children:`Global agent management is currently under development. Check back later for updates.`})]})})]}):(0,o.jsx)(`div`,{className:`text-center space-y-4`,children:(0,o.jsx)(`div`,{className:`text-destructive`,children:`Access denied. Admin privileges required.`})})}export{s as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{A as r,D as i,E as a,M as o,N as s,O as c,T as l,j as u,k as d}from"./ui-BSqPn1LJ.js";import{t as f}from"./utils-2pl1SbIp.js";import{n as p}from"./button-Bv4zA1qr.js";var m=e(n(),1),h=t(),g=u,_=s,v=r,y=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(d,{className:f(`fixed inset-0 z-50 bg-scrim duration-normal data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t,ref:n}));y.displayName=d.displayName;var b=m.forwardRef(({className:e,...t},n)=>(0,h.jsxs)(v,{children:[(0,h.jsx)(y,{}),(0,h.jsx)(i,{ref:n,className:f(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-elevation-3 duration-normal data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] rounded-(--panel-radius)`,e),...t})]}));b.displayName=i.displayName;var x=({className:e,...t})=>(0,h.jsx)(`div`,{className:f(`flex flex-col space-y-2 text-center sm:text-left`,e),...t});x.displayName=`AlertDialogHeader`;var S=({className:e,...t})=>(0,h.jsx)(`div`,{className:f(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t});S.displayName=`AlertDialogFooter`;var C=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(o,{ref:n,className:f(`text-lg font-semibold`,e),...t}));C.displayName=o.displayName;var w=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(c,{ref:n,className:f(`text-sm text-muted-foreground`,e),...t}));w.displayName=c.displayName;var T=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(l,{ref:n,className:f(p(),e),...t}));T.displayName=l.displayName;var E=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(a,{ref:n,className:f(p({variant:`outline`}),`mt-2 sm:mt-0`,e),...t}));E.displayName=a.displayName;export{w as a,C as c,b as i,_ as l,T as n,S as o,E as r,x as s,g as t};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{A as r,D as i,E as a,M as o,N as s,O as c,T as l,j as u,k as d}from"./ui-Byg1cZDr.js";import{t as f}from"./utils-2pl1SbIp.js";import{n as p}from"./button-SgR3GVvV.js";var m=e(n(),1),h=t(),g=u,_=s,v=r,y=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(d,{className:f(`fixed inset-0 z-50 bg-scrim duration-normal data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t,ref:n}));y.displayName=d.displayName;var b=m.forwardRef(({className:e,...t},n)=>(0,h.jsxs)(v,{children:[(0,h.jsx)(y,{}),(0,h.jsx)(i,{ref:n,className:f(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-elevation-3 duration-normal data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] rounded-(--panel-radius)`,e),...t})]}));b.displayName=i.displayName;var x=({className:e,...t})=>(0,h.jsx)(`div`,{className:f(`flex flex-col space-y-2 text-center sm:text-left`,e),...t});x.displayName=`AlertDialogHeader`;var S=({className:e,...t})=>(0,h.jsx)(`div`,{className:f(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t});S.displayName=`AlertDialogFooter`;var C=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(o,{ref:n,className:f(`text-lg font-semibold`,e),...t}));C.displayName=o.displayName;var w=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(c,{ref:n,className:f(`text-sm text-muted-foreground`,e),...t}));w.displayName=c.displayName;var T=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(l,{ref:n,className:f(p(),e),...t}));T.displayName=l.displayName;var E=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(a,{ref:n,className:f(p({variant:`outline`}),`mt-2 sm:mt-0`,e),...t}));E.displayName=a.displayName;export{w as a,C as c,b as i,_ as l,T as n,S as o,E as r,x as s,g as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Cr as r,Hr as i,Mt as a,Y as o}from"./ui-BSqPn1LJ.js";import{t as s}from"./button-Bv4zA1qr.js";import{t as c}from"./input-BOtCd4HP.js";import{c as l,t as u}from"./api-CA6WiiYM.js";import{n as d}from"./use-toast-BlLDqSUO.js";import{n as f}from"./page-header-GtTr9Ff_.js";import{t as p}from"./use-settings-back-Dk-DJEUO.js";var m=e(n(),1),h=t();function g(){let[e,t]=(0,m.useState)([]),[n,g]=(0,m.useState)(!0),[_,v]=(0,m.useState)(null),[y,b]=(0,m.useState)(``),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(``),[T,E]=(0,m.useState)(!1),{showToast:D}=d(),O=(0,m.useRef)(null),k=(0,m.useCallback)(async()=>{try{g(!0);let e=await u.get(l.tokens),n=Array.isArray(e)?e:e.tokens||[];t(n),v(null)}catch(e){let t=e instanceof Error?e.message:`Failed to fetch tokens`;v(t),D({title:`Error`,description:t,variant:`destructive`})}finally{g(!1)}},[D]);(0,m.useEffect)(()=>{k()},[k]);let A=async()=>{if(!(!y.trim()||x)){S(!0);try{let e=await u.post(l.tokens,{name:y});b(``),await k(),e&&e.token&&(w(e.token),setTimeout(()=>{if(O.current){O.current.focus();let e=document.createRange();e.selectNodeContents(O.current);let t=window.getSelection();t&&(t.removeAllRanges(),t.addRange(e))}},100)),D({title:`Success`,description:`Token generated successfully`,variant:`default`})}catch(e){let t=e instanceof Error?e.message:`Failed to generate token`;v(t),D({title:`Error`,description:t,variant:`destructive`})}finally{S(!1)}}},j=async e=>{if(confirm(`Are you sure you want to revoke this API token? This action cannot be undone.`))try{await u.delete(`${l.tokens}/${e}`),await k(),D({title:`Success`,description:`API token revoked successfully`})}catch(e){let t=e instanceof Error?e.message:`Failed to revoke API token`;D({title:`Error`,description:t,variant:`destructive`})}},M=async e=>{try{await navigator.clipboard.writeText(e),E(!0),D({title:`Success`,description:`Token copied to clipboard`}),setTimeout(()=>E(!1),2e3)}catch{D({title:`Error`,description:`Failed to copy token to clipboard`,variant:`destructive`})}};return(0,h.jsxs)(`div`,{className:`space-y-6`,children:[(0,h.jsx)(f,{title:`API Tokens`,onBack:p(),description:`Create and manage API tokens for programmatic access`}),(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Generate New API Token`}),(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(c,{value:y,onChange:e=>b(e.target.value),placeholder:`Token Name (e.g., 'CLI Access', 'Automation')`,disabled:x,className:`flex-1`}),(0,h.jsxs)(s,{type:`button`,disabled:x||!y.trim(),onClick:A,children:[(0,h.jsx)(a,{className:`mr-2 h-4 w-4`}),x?`Generating...`:`Generate`]})]}),C&&(0,h.jsxs)(`div`,{className:`p-4 border rounded-md bg-muted/50`,children:[(0,h.jsxs)(`div`,{className:`flex justify-between items-center mb-2`,children:[(0,h.jsx)(`h3`,{className:`font-semibold`,children:`Your New API Token`}),(0,h.jsx)(s,{variant:`outline`,size:`sm`,onClick:()=>M(C),children:T?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(i,{className:`mr-2 h-4 w-4`}),`Copied`]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(r,{className:`mr-2 h-4 w-4`}),`Copy`]})})]}),(0,h.jsx)(`p`,{className:`text-sm text-muted-foreground mb-2`,children:`Make sure to copy your API token now. You won't be able to see it again!`}),(0,h.jsx)(`div`,{ref:O,tabIndex:0,className:`p-2 bg-background border rounded font-mono text-sm break-all outline-none focus:ring-2 focus:ring-ring`,children:C})]})]}),(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your API Tokens`}),n&&(0,h.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading API tokens...`}),_&&(0,h.jsx)(`div`,{className:`text-center text-destructive`,children:(0,h.jsx)(`p`,{children:_})}),!n&&!_&&e.length===0&&(0,h.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No API tokens found`}),e.length>0&&(0,h.jsx)(`div`,{className:`border rounded-md`,children:(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`w-full`,children:[(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{className:`bg-muted/50`,children:[(0,h.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Name`}),(0,h.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Created`}),(0,h.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Last Used`}),(0,h.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Expires`}),(0,h.jsx)(`th`,{className:`text-right p-3 font-medium`,children:`Actions`})]})}),(0,h.jsx)(`tbody`,{children:e.map(e=>(0,h.jsxs)(`tr`,{className:`border-t`,children:[(0,h.jsx)(`td`,{className:`p-3 font-medium`,children:e.name}),(0,h.jsx)(`td`,{className:`p-3`,children:new Date(e.createdAt).toLocaleDateString()}),(0,h.jsx)(`td`,{className:`p-3`,children:e.lastUsedAt?new Date(e.lastUsedAt).toLocaleDateString():`Never`}),(0,h.jsx)(`td`,{className:`p-3`,children:e.expiresAt?new Date(e.expiresAt).toLocaleDateString():`Never`}),(0,h.jsx)(`td`,{className:`p-3 text-right`,children:(0,h.jsx)(s,{variant:`outline`,size:`sm`,onClick:()=>j(e.id),className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,children:(0,h.jsx)(o,{className:`h-4 w-4`})})})]},e.id))})]})})})]})]})}export{g as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Nt as r,Ur as i,Y as a,wr as o}from"./ui-Byg1cZDr.js";import{t as s}from"./button-SgR3GVvV.js";import{t as c}from"./input-BOtCd4HP.js";import{c as l,t as u}from"./api-CA6WiiYM.js";import{n as d}from"./use-toast-BlLDqSUO.js";import{n as f}from"./page-header-DkOHw0g-.js";import{t as p}from"./use-settings-back-CQauYjQ4.js";var m=e(n(),1),h=t();function g(){let[e,t]=(0,m.useState)([]),[n,g]=(0,m.useState)(!0),[_,v]=(0,m.useState)(null),[y,b]=(0,m.useState)(``),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(``),[T,E]=(0,m.useState)(!1),{showToast:D}=d(),O=(0,m.useRef)(null),k=(0,m.useCallback)(async()=>{try{g(!0);let e=await u.get(l.tokens),n=Array.isArray(e)?e:e.tokens||[];t(n),v(null)}catch(e){let t=e instanceof Error?e.message:`Failed to fetch tokens`;v(t),D({title:`Error`,description:t,variant:`destructive`})}finally{g(!1)}},[D]);(0,m.useEffect)(()=>{k()},[k]);let A=async()=>{if(!(!y.trim()||x)){S(!0);try{let e=await u.post(l.tokens,{name:y});b(``),await k(),e&&e.token&&(w(e.token),setTimeout(()=>{if(O.current){O.current.focus();let e=document.createRange();e.selectNodeContents(O.current);let t=window.getSelection();t&&(t.removeAllRanges(),t.addRange(e))}},100)),D({title:`Success`,description:`Token generated successfully`,variant:`default`})}catch(e){let t=e instanceof Error?e.message:`Failed to generate token`;v(t),D({title:`Error`,description:t,variant:`destructive`})}finally{S(!1)}}},j=async e=>{if(confirm(`Are you sure you want to revoke this API token? This action cannot be undone.`))try{await u.delete(`${l.tokens}/${e}`),await k(),D({title:`Success`,description:`API token revoked successfully`})}catch(e){let t=e instanceof Error?e.message:`Failed to revoke API token`;D({title:`Error`,description:t,variant:`destructive`})}},M=async e=>{try{await navigator.clipboard.writeText(e),E(!0),D({title:`Success`,description:`Token copied to clipboard`}),setTimeout(()=>E(!1),2e3)}catch{D({title:`Error`,description:`Failed to copy token to clipboard`,variant:`destructive`})}};return(0,h.jsxs)(`div`,{className:`space-y-6`,children:[(0,h.jsx)(f,{title:`API Tokens`,onBack:p(),description:`Create and manage API tokens for programmatic access`}),(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Generate New API Token`}),(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(c,{value:y,onChange:e=>b(e.target.value),placeholder:`Token Name (e.g., 'CLI Access', 'Automation')`,disabled:x,className:`flex-1`}),(0,h.jsxs)(s,{type:`button`,disabled:x||!y.trim(),onClick:A,children:[(0,h.jsx)(r,{className:`mr-2 h-4 w-4`}),x?`Generating...`:`Generate`]})]}),C&&(0,h.jsxs)(`div`,{className:`p-4 border rounded-md bg-muted/50`,children:[(0,h.jsxs)(`div`,{className:`flex justify-between items-center mb-2`,children:[(0,h.jsx)(`h3`,{className:`font-semibold`,children:`Your New API Token`}),(0,h.jsx)(s,{variant:`outline`,size:`sm`,onClick:()=>M(C),children:T?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(i,{className:`mr-2 h-4 w-4`}),`Copied`]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(o,{className:`mr-2 h-4 w-4`}),`Copy`]})})]}),(0,h.jsx)(`p`,{className:`text-sm text-muted-foreground mb-2`,children:`Make sure to copy your API token now. You won't be able to see it again!`}),(0,h.jsx)(`div`,{ref:O,tabIndex:0,className:`p-2 bg-background border rounded font-mono text-sm break-all outline-none focus:ring-2 focus:ring-ring`,children:C})]})]}),(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your API Tokens`}),n&&(0,h.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading API tokens...`}),_&&(0,h.jsx)(`div`,{className:`text-center text-destructive`,children:(0,h.jsx)(`p`,{children:_})}),!n&&!_&&e.length===0&&(0,h.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No API tokens found`}),e.length>0&&(0,h.jsx)(`div`,{className:`border rounded-md`,children:(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`w-full`,children:[(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{className:`bg-muted/50`,children:[(0,h.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Name`}),(0,h.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Created`}),(0,h.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Last Used`}),(0,h.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Expires`}),(0,h.jsx)(`th`,{className:`text-right p-3 font-medium`,children:`Actions`})]})}),(0,h.jsx)(`tbody`,{children:e.map(e=>(0,h.jsxs)(`tr`,{className:`border-t`,children:[(0,h.jsx)(`td`,{className:`p-3 font-medium`,children:e.name}),(0,h.jsx)(`td`,{className:`p-3`,children:new Date(e.createdAt).toLocaleDateString()}),(0,h.jsx)(`td`,{className:`p-3`,children:e.lastUsedAt?new Date(e.lastUsedAt).toLocaleDateString():`Never`}),(0,h.jsx)(`td`,{className:`p-3`,children:e.expiresAt?new Date(e.expiresAt).toLocaleDateString():`Never`}),(0,h.jsx)(`td`,{className:`p-3 text-right`,children:(0,h.jsx)(s,{variant:`outline`,size:`sm`,onClick:()=>j(e.id),className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,children:(0,h.jsx)(a,{className:`h-4 w-4`})})})]},e.id))})]})})})]})]})}export{g as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Hr as r,Jt as i,et as a,qt as o}from"./ui-BSqPn1LJ.js";import{t as s}from"./utils-2pl1SbIp.js";import{a as c,i as l,n as u,o as d,r as f,s as p,t as m}from"./document-open-mode-DoImW-xs.js";import{d as h,f as g,l as _,o as v,s as y,u as b}from"./use-menu-BVkqNEIx.js";import{t as x}from"./use-theme-DaxpiICf.js";import{_t as S,a as C,c as w,d as T,f as E,i as D,l as O,m as k,n as A,o as j,p as M,r as N,s as P,t as F,u as I,vt as L,yt as R}from"./index-exXolIqD.js";import{n as z}from"./page-header-GtTr9Ff_.js";import{t as B}from"./use-settings-back-Dk-DJEUO.js";var V=e(n(),1),H=t(),U={system:i,light:a,dark:o};function W(){let{theme:e,scheme:t,density:n,resolvedScheme:i,setTheme:a,setScheme:o,setDensity:C,reset:w}=x(),T=l(),D=u(),O=h(),A=p(),j=R(),N=g();return(0,H.jsxs)(`div`,{className:`space-y-8`,children:[(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Theme`,description:`Palette, shape and typography. Each theme defines its own light and dark variants.`}),(0,H.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:k.map(t=>{let n=t.id===e;return(0,H.jsxs)(`button`,{type:`button`,onClick:()=>a(t.id),"aria-pressed":n,className:s(`focus-ring group flex flex-col gap-3 rounded-lg border p-4 text-left transition-colors`,n?`border-primary bg-accent`:`border-border hover:border-muted-foreground/40 hover:bg-accent/50`),children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:t.name}),n&&(0,H.jsx)(r,{className:`size-4 shrink-0 text-primary`})]}),(0,H.jsx)(`div`,{className:`flex gap-1.5`,"aria-hidden":!0,children:t.swatches.map(e=>(0,H.jsx)(`span`,{className:`size-6 rounded-full border border-border`,style:{backgroundColor:e}},e))}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t.description})]},t.id)})})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Colour scheme`,description:t===`system`?`Following your system setting, currently ${i}.`:`Overrides your system setting.`}),(0,H.jsx)(Y,{options:M.map(e=>{let t=U[e.id];return{id:e.id,label:e.name,icon:(0,H.jsx)(t,{className:`size-4 shrink-0`})}}),value:t,onChange:o})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Density`,description:`Controls row height, hit-target size and shell spacing across the whole app.`}),(0,H.jsx)(Y,{options:E.map(e=>({id:e.id,label:e.name,title:e.description})),value:n,onChange:C}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:E.find(e=>e.id===n)?.description})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Layout`,description:`How menus and content share the screen. Device-local, like the wallpaper.`}),(0,H.jsx)(Y,{options:y.map(e=>({id:e.id,label:e.name,title:e.description})),value:O,onChange:_}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:y.find(e=>e.id===O)?.description}),O===`strip`&&(0,H.jsxs)(`div`,{className:`mt-4`,children:[(0,H.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:`Navigation keys`}),(0,H.jsx)(Y,{options:v.map(e=>({id:e.id,label:e.name,title:e.description})),value:N,onChange:b}),(0,H.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[v.find(e=>e.id===N)?.description,` `,`Left and right walk the columns, up and down switch pin rows.`]})]})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Tree style`,description:`How workspace and context trees are drawn in the menu. Device-local.`}),(0,H.jsx)(Y,{options:S.map(e=>({id:e.id,label:e.name,title:e.description})),value:j,onChange:L}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:S.find(e=>e.id===j)?.description})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Open documents`,description:`Choose how documents open from lists, tiles and boards. Saved on this device.`}),(0,H.jsx)(Y,{options:[{id:`modal`,label:`Modal`},{id:`side`,label:`Side reading pane`}],value:D,onChange:m}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`The reading pane opens beside the content and updates as you select another document. On small screens it opens as a drawer.`})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Always-on content area`,description:`Keep a reading pane beside document lists on tablets and desktops. Remember the selected item in each folder, or show the first available item.`}),(0,H.jsx)(Y,{options:[{id:`on`,label:`On`},{id:`off`,label:`Off`}],value:T?`on`:`off`,onChange:e=>f(e===`on`)}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`On by default. The reader uses roughly half the screen; drag its divider to resize. Phones keep tap-to-open navigation. When enabled, list selections use this pane regardless of the Open documents setting.`})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Document tiles`,description:`Choose the photo and media layout for tile view. Saved on this device.`}),(0,H.jsx)(Y,{options:c,value:A,onChange:d})]}),(0,H.jsx)(G,{}),(0,H.jsx)(`section`,{children:(0,H.jsx)(`button`,{type:`button`,onClick:()=>{w(),m(`modal`)},className:`focus-ring rounded-md text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline`,children:`Reset to defaults`})})]})}function G(){let[e,t]=(0,V.useState)(j),[n,r]=(0,V.useState)(null),[i,a]=(0,V.useState)(!0),[o,s]=(0,V.useState)(!1),c=(0,V.useRef)(!1);(0,V.useEffect)(()=>{let e=!1;return w().then(()=>{e||(t(j()),a(!1))}),()=>{e=!0}},[]);let l=async(e,n)=>{if(!c.current){c.current=!0,s(!0);try{let i=n?{...e,image:await P(n)}:e;await O(i),t(i),r(null)}catch(e){r(e instanceof Error&&e.name!==`QuotaExceededError`?e.message:`Could not store the wallpaper. Free some browser storage or try a smaller image.`)}finally{c.current=!1,s(!1)}}},u=t=>{t&&l(e,t)},d=e.image!==null&&N(e.image)===null,f=I(e.image);return(0,H.jsx)(`section`,{children:(0,H.jsxs)(`fieldset`,{disabled:i||o,className:`min-w-0`,children:[(0,H.jsx)(J,{title:`Wallpaper`,description:`Background image for the desk behind all panels. Without one, the theme's desk color shows (the default).`}),(0,H.jsxs)(`div`,{role:`radiogroup`,"aria-label":`Wallpaper`,className:`grid grid-cols-3 gap-3 sm:grid-cols-4 lg:grid-cols-6`,children:[(0,H.jsx)(q,{label:`None`,isActive:e.image===null,onSelect:()=>l({...e,image:null}),children:(0,H.jsx)(`span`,{className:`flex size-full items-center justify-center surface-desk text-xs text-muted-foreground`,style:{backgroundImage:`none`},children:`None`})}),F.map(t=>(0,H.jsx)(q,{label:t.title,title:`${t.title} — suits the ${t.scheme} scheme`,isActive:N(e.image)===t.id,onSelect:()=>l({...e,image:D(t.id)}),children:(0,H.jsx)(`img`,{src:C(t),alt:``,loading:`lazy`,className:`size-full object-cover`,style:{backgroundColor:t.background}})},t.id)),d&&(0,H.jsx)(q,{label:`Your image`,isActive:!0,onSelect:()=>{},children:(0,H.jsx)(`img`,{src:e.image??void 0,alt:``,className:`size-full object-cover`})})]}),(0,H.jsx)(K,{}),(0,H.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,H.jsx)(`div`,{className:`h-20 w-32 shrink-0 rounded-md border surface-desk`,style:f?{backgroundImage:f,backgroundSize:T(e.fit),backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,"aria-hidden":!0}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsxs)(`label`,{className:`focus-ring inline-flex cursor-pointer items-center rounded-md border px-3 py-1.5 text-sm hover:bg-accent/50`,children:[d?`Change image…`:`Use your own image…`,(0,H.jsx)(`input`,{type:`file`,accept:`image/*,.gif`,className:`hidden`,onChange:e=>{u(e.target.files?.[0]),e.target.value=``}})]}),e.image&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>l({...e,image:null}),className:`focus-ring rounded-md border px-3 py-1.5 text-sm text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:`Remove`})]}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Images and animated GIFs up to 10 MB. Stored on this device.`}),(0,H.jsx)(Y,{options:A.map(e=>({id:e.id,label:e.label,title:e.description})),value:e.fit,onChange:t=>l({...e,fit:t})}),n&&(0,H.jsx)(`p`,{className:`text-xs text-destructive`,children:n}),o&&(0,H.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:`Saving wallpaper…`})]})]})]})})}function K(){let e=F.filter(e=>e.author!==`Canvas`);return e.length===0?null:(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:e.map((e,t)=>(0,H.jsxs)(`span`,{children:[t>0&&` · `,e.title,` © `,e.author,e.source&&(0,H.jsxs)(H.Fragment,{children:[` `,(0,H.jsx)(`a`,{href:e.source,target:`_blank`,rel:`noreferrer noopener`,className:`focus-ring underline underline-offset-2 hover:text-foreground`,children:new URL(e.source).hostname})]})]},e.id))})}function q({label:e,title:t,isActive:n,onSelect:i,children:a}){return(0,H.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,"aria-label":e,title:t??e,onClick:i,className:s(`focus-ring group relative aspect-video overflow-hidden rounded-md border transition-colors`,n?`border-primary ring-1 ring-primary`:`border-border hover:border-muted-foreground/40`),children:[a,n&&(0,H.jsx)(`span`,{className:`absolute right-1 top-1 rounded-full bg-primary p-0.5 text-primary-foreground`,children:(0,H.jsx)(r,{className:`size-3`})})]})}function J({title:e,description:t}){return(0,H.jsxs)(`div`,{className:`mb-3`,children:[(0,H.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t})]})}function Y({options:e,value:t,onChange:n}){return(0,H.jsx)(`div`,{role:`radiogroup`,className:`inline-flex flex-wrap gap-1 rounded-lg bg-muted p-1`,children:e.map(e=>{let r=e.id===t;return(0,H.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":r,title:e.title,onClick:()=>n(e.id),className:s(`focus-ring flex h-control items-center gap-2 rounded-md px-3 text-sm transition-colors`,r?`bg-card text-foreground shadow-elevation-1`:`text-muted-foreground hover:text-foreground`),children:[e.icon,e.label]},e.id)})})}function X(){return(0,H.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,H.jsx)(z,{className:`mb-6`,title:`Appearance`,onBack:B(),description:`Theme, colour scheme and density. Changes apply immediately and are remembered on this device.`}),(0,H.jsx)(W,{})]})}export{X as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Jt as r,Ur as i,Yt as a,et as o}from"./ui-Byg1cZDr.js";import{t as s}from"./utils-2pl1SbIp.js";import{a as c,i as l,n as u,o as d,r as f,s as p,t as m}from"./document-open-mode-DoImW-xs.js";import{d as h,f as g,l as _,o as v,s as y,u as b}from"./use-menu-BiJ8N7sS.js";import{t as x}from"./use-theme-DaxpiICf.js";import{a as S,bt as C,c as w,d as T,f as E,i as D,l as O,m as k,n as A,o as j,p as M,r as N,s as P,t as F,u as I,vt as L,yt as R}from"./index-CiBgHujl.js";import{n as z}from"./page-header-DkOHw0g-.js";import{t as B}from"./use-settings-back-CQauYjQ4.js";var V=e(n(),1),H=t(),U={system:a,light:o,dark:r};function W(){let{theme:e,scheme:t,density:n,resolvedScheme:r,setTheme:a,setScheme:o,setDensity:S,reset:w}=x(),T=l(),D=u(),O=h(),A=p(),j=C(),N=g();return(0,H.jsxs)(`div`,{className:`space-y-8`,children:[(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Theme`,description:`Palette, shape and typography. Each theme defines its own light and dark variants.`}),(0,H.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:k.map(t=>{let n=t.id===e;return(0,H.jsxs)(`button`,{type:`button`,onClick:()=>a(t.id),"aria-pressed":n,className:s(`focus-ring group flex flex-col gap-3 rounded-lg border p-4 text-left transition-colors`,n?`border-primary bg-accent`:`border-border hover:border-muted-foreground/40 hover:bg-accent/50`),children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:t.name}),n&&(0,H.jsx)(i,{className:`size-4 shrink-0 text-primary`})]}),(0,H.jsx)(`div`,{className:`flex gap-1.5`,"aria-hidden":!0,children:t.swatches.map(e=>(0,H.jsx)(`span`,{className:`size-6 rounded-full border border-border`,style:{backgroundColor:e}},e))}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t.description})]},t.id)})})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Colour scheme`,description:t===`system`?`Following your system setting, currently ${r}.`:`Overrides your system setting.`}),(0,H.jsx)(Y,{options:M.map(e=>{let t=U[e.id];return{id:e.id,label:e.name,icon:(0,H.jsx)(t,{className:`size-4 shrink-0`})}}),value:t,onChange:o})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Density`,description:`Controls row height, hit-target size and shell spacing across the whole app.`}),(0,H.jsx)(Y,{options:E.map(e=>({id:e.id,label:e.name,title:e.description})),value:n,onChange:S}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:E.find(e=>e.id===n)?.description})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Layout`,description:`How menus and content share the screen. Device-local, like the wallpaper.`}),(0,H.jsx)(Y,{options:y.map(e=>({id:e.id,label:e.name,title:e.description})),value:O,onChange:_}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:y.find(e=>e.id===O)?.description}),O===`strip`&&(0,H.jsxs)(`div`,{className:`mt-4`,children:[(0,H.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:`Navigation keys`}),(0,H.jsx)(Y,{options:v.map(e=>({id:e.id,label:e.name,title:e.description})),value:N,onChange:b}),(0,H.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[v.find(e=>e.id===N)?.description,` `,`Left and right walk the columns, up and down switch pin rows.`]})]})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Tree style`,description:`How workspace and context trees are drawn in the menu. Device-local.`}),(0,H.jsx)(Y,{options:L.map(e=>({id:e.id,label:e.name,title:e.description})),value:j,onChange:R}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:L.find(e=>e.id===j)?.description})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Open documents`,description:`Choose how documents open from lists, tiles and boards. Saved on this device.`}),(0,H.jsx)(Y,{options:[{id:`modal`,label:`Modal`},{id:`side`,label:`Side reading pane`}],value:D,onChange:m}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`The reading pane opens beside the content and updates as you select another document. On small screens it opens as a drawer.`})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Always-on content area`,description:`Keep a reading pane beside document lists on tablets and desktops. Remember the selected item in each folder, or show the first available item.`}),(0,H.jsx)(Y,{options:[{id:`on`,label:`On`},{id:`off`,label:`Off`}],value:T?`on`:`off`,onChange:e=>f(e===`on`)}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`On by default. The reader uses roughly half the screen; drag its divider to resize. Phones keep tap-to-open navigation. When enabled, list selections use this pane regardless of the Open documents setting.`})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Document tiles`,description:`Choose the photo and media layout for tile view. Saved on this device.`}),(0,H.jsx)(Y,{options:c,value:A,onChange:d})]}),(0,H.jsx)(G,{}),(0,H.jsx)(`section`,{children:(0,H.jsx)(`button`,{type:`button`,onClick:()=>{w(),m(`modal`)},className:`focus-ring rounded-md text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline`,children:`Reset to defaults`})})]})}function G(){let[e,t]=(0,V.useState)(j),[n,r]=(0,V.useState)(null),[i,a]=(0,V.useState)(!0),[o,s]=(0,V.useState)(!1),c=(0,V.useRef)(!1);(0,V.useEffect)(()=>{let e=!1;return w().then(()=>{e||(t(j()),a(!1))}),()=>{e=!0}},[]);let l=async(e,n)=>{if(!c.current){c.current=!0,s(!0);try{let i=n?{...e,image:await P(n)}:e;await O(i),t(i),r(null)}catch(e){r(e instanceof Error&&e.name!==`QuotaExceededError`?e.message:`Could not store the wallpaper. Free some browser storage or try a smaller image.`)}finally{c.current=!1,s(!1)}}},u=t=>{t&&l(e,t)},d=e.image!==null&&N(e.image)===null,f=I(e.image);return(0,H.jsx)(`section`,{children:(0,H.jsxs)(`fieldset`,{disabled:i||o,className:`min-w-0`,children:[(0,H.jsx)(J,{title:`Wallpaper`,description:`Background image for the desk behind all panels. Without one, the theme's desk color shows (the default).`}),(0,H.jsxs)(`div`,{role:`radiogroup`,"aria-label":`Wallpaper`,className:`grid grid-cols-3 gap-3 sm:grid-cols-4 lg:grid-cols-6`,children:[(0,H.jsx)(q,{label:`None`,isActive:e.image===null,onSelect:()=>l({...e,image:null}),children:(0,H.jsx)(`span`,{className:`flex size-full items-center justify-center surface-desk text-xs text-muted-foreground`,style:{backgroundImage:`none`},children:`None`})}),F.map(t=>(0,H.jsx)(q,{label:t.title,title:`${t.title} — suits the ${t.scheme} scheme`,isActive:N(e.image)===t.id,onSelect:()=>l({...e,image:D(t.id)}),children:(0,H.jsx)(`img`,{src:S(t),alt:``,loading:`lazy`,className:`size-full object-cover`,style:{backgroundColor:t.background}})},t.id)),d&&(0,H.jsx)(q,{label:`Your image`,isActive:!0,onSelect:()=>{},children:(0,H.jsx)(`img`,{src:e.image??void 0,alt:``,className:`size-full object-cover`})})]}),(0,H.jsx)(K,{}),(0,H.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,H.jsx)(`div`,{className:`h-20 w-32 shrink-0 rounded-md border surface-desk`,style:f?{backgroundImage:f,backgroundSize:T(e.fit),backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,"aria-hidden":!0}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsxs)(`label`,{className:`focus-ring inline-flex cursor-pointer items-center rounded-md border px-3 py-1.5 text-sm hover:bg-accent/50`,children:[d?`Change image…`:`Use your own image…`,(0,H.jsx)(`input`,{type:`file`,accept:`image/*,.gif`,className:`hidden`,onChange:e=>{u(e.target.files?.[0]),e.target.value=``}})]}),e.image&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>l({...e,image:null}),className:`focus-ring rounded-md border px-3 py-1.5 text-sm text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:`Remove`})]}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Images and animated GIFs up to 10 MB. Stored on this device.`}),(0,H.jsx)(Y,{options:A.map(e=>({id:e.id,label:e.label,title:e.description})),value:e.fit,onChange:t=>l({...e,fit:t})}),n&&(0,H.jsx)(`p`,{className:`text-xs text-destructive`,children:n}),o&&(0,H.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:`Saving wallpaper…`})]})]})]})})}function K(){let e=F.filter(e=>e.author!==`Canvas`);return e.length===0?null:(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:e.map((e,t)=>(0,H.jsxs)(`span`,{children:[t>0&&` · `,e.title,` © `,e.author,e.source&&(0,H.jsxs)(H.Fragment,{children:[` `,(0,H.jsx)(`a`,{href:e.source,target:`_blank`,rel:`noreferrer noopener`,className:`focus-ring underline underline-offset-2 hover:text-foreground`,children:new URL(e.source).hostname})]})]},e.id))})}function q({label:e,title:t,isActive:n,onSelect:r,children:a}){return(0,H.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,"aria-label":e,title:t??e,onClick:r,className:s(`focus-ring group relative aspect-video overflow-hidden rounded-md border transition-colors`,n?`border-primary ring-1 ring-primary`:`border-border hover:border-muted-foreground/40`),children:[a,n&&(0,H.jsx)(`span`,{className:`absolute right-1 top-1 rounded-full bg-primary p-0.5 text-primary-foreground`,children:(0,H.jsx)(i,{className:`size-3`})})]})}function J({title:e,description:t}){return(0,H.jsxs)(`div`,{className:`mb-3`,children:[(0,H.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t})]})}function Y({options:e,value:t,onChange:n}){return(0,H.jsx)(`div`,{role:`radiogroup`,className:`inline-flex flex-wrap gap-1 rounded-lg bg-muted p-1`,children:e.map(e=>{let r=e.id===t;return(0,H.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":r,title:e.title,onClick:()=>n(e.id),className:s(`focus-ring flex h-control items-center gap-2 rounded-md px-3 text-sm transition-colors`,r?`bg-card text-foreground shadow-elevation-1`:`text-muted-foreground hover:text-foreground`),children:[e.icon,e.label]},e.id)})})}function X(){return(0,H.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,H.jsx)(z,{className:`mb-6`,title:`Appearance`,onBack:B(),description:`Theme, colour scheme and density. Changes apply immediately and are remembered on this device.`}),(0,H.jsx)(W,{})]})}export{X as default};
@@ -1 +1 @@
1
- import{l as e}from"./code-editor-BOIngd5F.js";import{t}from"./use-applet-target-mkjQujx6.js";var n=e();function r({target:e,children:r}){return(0,n.jsx)(t.Provider,{value:e,children:r})}export{r as t};
1
+ import{l as e}from"./code-editor-BOIngd5F.js";import{t}from"./use-applet-target-cO-FiyPQ.js";var n=e();function r({target:e,children:r}){return(0,n.jsx)(t.Provider,{value:e,children:r})}export{r as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,r as i,v as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./utils-2pl1SbIp.js";import{Pt as s}from"./workspace-CJ1PWQ29.js";import{p as c}from"./context-D_K4g9SQ.js";import{t as l}from"./registry-6tE_1KPV.js";import{t as u}from"./applet-target-DnTa2VAT.js";var d=e(n(),1),f=t(),p=`universe`;function m(){let{appletId:e}=r(),[t,n]=a(),m=l.find(t=>t.id===e),h=t.get(`context`),g=t.get(`workspace`)||p,_=t.get(`path`)||`/`,v=t.get(`tree`)||`context`,y=t.get(`add`)===`1`,b=(0,d.useMemo)(()=>h?{mode:`context`,contextId:h}:{mode:`workspace`,workspaceName:g,path:_,treeName:v,treeType:v===`directory`?`directory`:`context`},[h,g,_,v]),[x,S]=(0,d.useState)([]),[C,w]=(0,d.useState)([]);(0,d.useEffect)(()=>{s().then(S).catch(()=>S([])),c().then(w).catch(()=>w([]))},[]);let[T,E]=(0,d.useState)(_),[D,O]=(0,d.useState)(_);D!==_&&(O(_),E(_));let k=e=>{let r=new URLSearchParams(t);r.delete(`add`);for(let[t,n]of Object.entries(e))n===null?r.delete(t):r.set(t,n);n(r,{replace:!0})};if(!m)return(0,f.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col items-center justify-center gap-3 surface-desk`,children:[(0,f.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Unknown app`,e?` "${e}"`:``,`.`]}),(0,f.jsx)(`div`,{className:`flex gap-2`,children:l.map(e=>(0,f.jsx)(i,{to:`/apps/${e.id}`,className:`rounded-md border border-border px-3 py-1.5 text-sm hover:bg-muted`,children:e.label},e.id))})]});let A=h?`context`:`path`;return(0,f.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col surface-desk p-shell gap-shell`,children:[(0,f.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 rounded-xl border bg-card px-3 py-2 shadow-elevation-2`,children:[(0,f.jsx)(m.icon,{className:`h-4 w-4 text-muted-foreground`}),(0,f.jsx)(`span`,{className:`text-sm font-semibold`,children:m.label}),(0,f.jsx)(`div`,{className:`ml-2 flex overflow-hidden rounded-md border border-border`,children:[`path`,`context`].map(e=>(0,f.jsx)(`button`,{type:`button`,onClick:()=>{e!==A&&k(e===`path`?{context:null}:{context:C[0]?.id??``,workspace:null,path:null,tree:null})},className:o(`px-2.5 py-1 text-xs capitalize transition-colors`,A===e?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e},e))}),A===`path`?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`select`,{value:g,onChange:e=>k({workspace:e.target.value,path:`/`}),className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Workspace`,children:[!x.some(e=>e.name===g)&&(0,f.jsx)(`option`,{value:g,children:g}),x.map(e=>(0,f.jsx)(`option`,{value:e.name,children:e.label||e.name},e.id))]}),(0,f.jsx)(`input`,{value:T,onChange:e=>E(e.target.value),onBlur:()=>{let e=T.trim()||`/`;e!==_&&k({path:e})},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},spellCheck:!1,placeholder:`/`,className:`h-7 w-40 rounded-md border border-input bg-transparent px-2 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`,"aria-label":`Path`})]}):(0,f.jsxs)(`select`,{value:h??``,onChange:e=>k({context:e.target.value}),className:`h-7 max-w-56 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Context`,children:[!h&&(0,f.jsx)(`option`,{value:``,children:`Pick a context…`}),C.map(e=>(0,f.jsxs)(`option`,{value:e.id,children:[e.id,e.url?` (${e.url})`:``]},e.id))]}),(0,f.jsx)(`div`,{className:`grow`})]}),(0,f.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border bg-card shadow-elevation-2`,children:A===`context`&&!h?(0,f.jsxs)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:[`Pick a context above to bind `,m.label,` to it.`]}):(0,f.jsx)(u,{target:b,children:(0,f.jsx)(m.Component,{autoAdd:y},JSON.stringify(b))})})]})}export{m as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,r as i,v as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./utils-2pl1SbIp.js";import{Pt as s}from"./workspace-DvxC7pw1.js";import{p as c}from"./context-mfIOB8dN.js";import{t as l}from"./registry-DTWAywyJ.js";import{t as u}from"./applet-target-ChiiXVdC.js";var d=e(n(),1),f=t(),p=`universe`;function m(){let{appletId:e}=r(),[t,n]=a(),m=l.find(t=>t.id===e),h=t.get(`context`),g=t.get(`workspace`)||p,_=t.get(`path`)||`/`,v=t.get(`tree`)||`context`,y=t.get(`add`)===`1`,b=(0,d.useMemo)(()=>h?{mode:`context`,contextId:h}:{mode:`workspace`,workspaceName:g,path:_,treeName:v,treeType:v===`directory`?`directory`:`context`},[h,g,_,v]),[x,S]=(0,d.useState)([]),[C,w]=(0,d.useState)([]);(0,d.useEffect)(()=>{s().then(S).catch(()=>S([])),c().then(w).catch(()=>w([]))},[]);let[T,E]=(0,d.useState)(_),[D,O]=(0,d.useState)(_);D!==_&&(O(_),E(_));let k=e=>{let r=new URLSearchParams(t);r.delete(`add`);for(let[t,n]of Object.entries(e))n===null?r.delete(t):r.set(t,n);n(r,{replace:!0})};if(!m)return(0,f.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col items-center justify-center gap-3 surface-desk`,children:[(0,f.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Unknown app`,e?` "${e}"`:``,`.`]}),(0,f.jsx)(`div`,{className:`flex gap-2`,children:l.map(e=>(0,f.jsx)(i,{to:`/apps/${e.id}`,className:`rounded-md border border-border px-3 py-1.5 text-sm hover:bg-muted`,children:e.label},e.id))})]});let A=h?`context`:`path`;return(0,f.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col surface-desk p-shell gap-shell`,children:[(0,f.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 rounded-xl border bg-card px-3 py-2 shadow-elevation-2`,children:[(0,f.jsx)(m.icon,{className:`h-4 w-4 text-muted-foreground`}),(0,f.jsx)(`span`,{className:`text-sm font-semibold`,children:m.label}),(0,f.jsx)(`div`,{className:`ml-2 flex overflow-hidden rounded-md border border-border`,children:[`path`,`context`].map(e=>(0,f.jsx)(`button`,{type:`button`,onClick:()=>{e!==A&&k(e===`path`?{context:null}:{context:C[0]?.id??``,workspace:null,path:null,tree:null})},className:o(`px-2.5 py-1 text-xs capitalize transition-colors`,A===e?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e},e))}),A===`path`?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`select`,{value:g,onChange:e=>k({workspace:e.target.value,path:`/`}),className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Workspace`,children:[!x.some(e=>e.name===g)&&(0,f.jsx)(`option`,{value:g,children:g}),x.map(e=>(0,f.jsx)(`option`,{value:e.name,children:e.label||e.name},e.id))]}),(0,f.jsx)(`input`,{value:T,onChange:e=>E(e.target.value),onBlur:()=>{let e=T.trim()||`/`;e!==_&&k({path:e})},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},spellCheck:!1,placeholder:`/`,className:`h-7 w-40 rounded-md border border-input bg-transparent px-2 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`,"aria-label":`Path`})]}):(0,f.jsxs)(`select`,{value:h??``,onChange:e=>k({context:e.target.value}),className:`h-7 max-w-56 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Context`,children:[!h&&(0,f.jsx)(`option`,{value:``,children:`Pick a context…`}),C.map(e=>(0,f.jsxs)(`option`,{value:e.id,children:[e.id,e.url?` (${e.url})`:``]},e.id))]}),(0,f.jsx)(`div`,{className:`grow`})]}),(0,f.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border bg-card shadow-elevation-2`,children:A===`context`&&!h?(0,f.jsxs)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:[`Pick a context above to bind `,m.label,` to it.`]}):(0,f.jsx)(u,{target:b,children:(0,f.jsx)(m.Component,{autoAdd:y},JSON.stringify(b))})})]})}export{m as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Ar as r,Mt as i,Nr as a,Ot as o,X as s,dn as c,pt as l}from"./ui-BSqPn1LJ.js";import{t as u}from"./utils-2pl1SbIp.js";import{t as d}from"./button-Bv4zA1qr.js";import{t as f}from"./input-BOtCd4HP.js";import{c as p,l as m,t as h}from"./api-CA6WiiYM.js";import{i as g}from"./auth-Bx9fAZmz.js";import{n as _}from"./use-toast-BlLDqSUO.js";import{n as v}from"./page-header-GtTr9Ff_.js";import{t as y}from"./use-settings-back-Dk-DJEUO.js";var b=e(n(),1);function x(){return h.get(p.admin.authConfig)}function S(e){return h.put(p.admin.authConfig,e)}function C(e,t,n){return h.post(`${p.admin.authConfig}/test`,{strategy:`ldap`,name:e,server:t,email:n})}function w(e,t,n){return h.post(`${p.admin.authConfig}/test`,{strategy:`imap`,domain:e,email:t,password:n})}var T=t(),E=0,D=()=>`row-${++E}`;function O(e){let{servers:t,...n}=e.strategies.ldap,{domains:r,...i}=e.strategies.imap;return{allowUserRegistrations:e.allowUserRegistrations,local:e.strategies.local,ldap:{...n,servers:Object.entries(t).map(([e,t])=>({...t,id:D(),name:e,originalName:e}))},imap:{...i,domains:Object.entries(r).map(([e,t])=>({...t,id:D(),domain:e}))},google:e.strategies.google??{enabled:!1,defaultUserType:`user`,defaultStatus:`active`,clientId:``,clientSecretSet:!1,allowedDomains:[],autoCreateUsers:!0,webOrigins:[]}}}function k(e){let{id:t,name:n,originalName:r,...i}=e;return{...i,...r&&r!==e.name?{previousName:r}:{}}}function A(e){return{allowUserRegistrations:e.allowUserRegistrations,strategies:{local:e.local,ldap:{enabled:e.ldap.enabled,defaultUserType:e.ldap.defaultUserType,defaultStatus:e.ldap.defaultStatus,servers:Object.fromEntries(e.ldap.servers.map(e=>[e.name.trim(),k(e)]))},imap:{enabled:e.imap.enabled,defaultUserType:e.imap.defaultUserType,defaultStatus:e.imap.defaultStatus,domains:Object.fromEntries(e.imap.domains.map(({id:e,domain:t,...n})=>[t.trim().toLowerCase(),n]))},google:e.google}}}function j({value:e,onChange:t,placeholder:n,disabled:r}){let i=e.join(`, `),[a,o]=(0,b.useState)(i),[s,c]=(0,b.useState)(i);return i!==s&&(c(i),a.split(/[\s,]+/).filter(Boolean).join(`, `)!==i&&o(i)),(0,T.jsx)(f,{className:`h-8 text-sm`,value:a,placeholder:n,disabled:r,onChange:e=>{o(e.target.value),t(e.target.value.split(/[\s,]+/).map(e=>e.trim()).filter(Boolean))}})}var M={originalName:null,url:`ldap://`,bindDN:``,bindPasswordSet:!1,bindPassword:void 0,searchBase:``,searchFilter:`(mail={{email}})`,attributes:[`mail`,`cn`,`displayName`,`memberOf`],groupAttribute:`memberOf`,tls:!1},N={domain:``,name:``,host:``,port:993,secure:!0,startTLS:!1,requireAppPassword:!1},P=`h-8 rounded-md border border-input bg-transparent px-2 text-sm outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:opacity-50`;function F({label:e,hint:t,children:n,className:r}){return(0,T.jsxs)(`label`,{className:u(`flex min-w-0 flex-col gap-1`,r),children:[(0,T.jsx)(`span`,{className:`text-xs font-medium`,children:e}),n,t&&(0,T.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:t})]})}function I({checked:e,onChange:t,disabled:n,label:r,hint:i}){return(0,T.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,T.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:e,disabled:n,onChange:e=>t(e.target.checked)}),(0,T.jsxs)(`span`,{children:[r,i&&(0,T.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:i})]})]})}function L({title:e,description:t,enabled:n,onToggle:r,disabled:i,children:a}){return(0,T.jsxs)(`section`,{className:`rounded-lg border p-4`,children:[(0,T.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`h3`,{className:`text-sm font-semibold`,children:e}),(0,T.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:t})]}),r&&(0,T.jsxs)(`label`,{className:`flex shrink-0 items-center gap-2 text-xs font-medium`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:!!n,disabled:i,onChange:e=>r(e.target.checked)}),n?`Enabled`:`Disabled`]})]}),(0,T.jsx)(`div`,{className:u(`mt-4 space-y-4`,r&&!n&&`opacity-60`),children:a})]})}function R({result:e}){return e?(0,T.jsxs)(`div`,{className:u(`flex items-start gap-2 rounded-md border p-2 text-xs`,e.ok?`border-emerald-500/40 bg-emerald-500/5`:`border-destructive/40 bg-destructive/5`),children:[e.ok?(0,T.jsx)(a,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-emerald-600`}):(0,T.jsx)(r,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive`}),(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`p`,{children:e.message}),e.user&&e.user.groups.length>0&&(0,T.jsxs)(`p`,{className:`mt-1 break-all text-muted-foreground`,children:[`Groups: `,e.user.groups.join(` · `)]})]})]}):null}function z({value:e,onChange:t,disabled:n}){return(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap gap-4`,children:[(0,T.jsx)(F,{label:`New accounts are`,children:(0,T.jsxs)(`select`,{className:P,value:e.defaultUserType,disabled:n,onChange:e=>t({defaultUserType:e.target.value}),children:[(0,T.jsx)(`option`,{value:`user`,children:`Users`}),(0,T.jsx)(`option`,{value:`admin`,children:`Admins`})]})}),(0,T.jsx)(F,{label:`Initial status`,children:(0,T.jsxs)(`select`,{className:P,value:e.defaultStatus,disabled:n,onChange:e=>t({defaultStatus:e.target.value}),children:[(0,T.jsx)(`option`,{value:`active`,children:`Active — can sign in right away`}),(0,T.jsx)(`option`,{value:`pending`,children:`Pending — an admin activates them`}),(0,T.jsx)(`option`,{value:`inactive`,children:`Inactive`})]})})]}),e.defaultUserType===`admin`&&(0,T.jsxs)(`p`,{className:`flex items-start gap-1.5 text-[11px] text-destructive`,children:[(0,T.jsx)(l,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),`Everyone who can sign in through this backend becomes a server admin on first login.`]})]})}function B({row:e,index:t,onChange:n,onRemove:r,disabled:i}){let[a,o]=(0,b.useState)(``),[l,u]=(0,b.useState)(!1),[p,m]=(0,b.useState)(null),h=async()=>{u(!0),m(null);try{m(await C(e.originalName??e.name,k(e),a.trim()||void 0))}catch(e){m({ok:!1,message:e instanceof Error?e.message:`Test failed`})}finally{u(!1)}},g=e.bindPassword===null?`cleared on save`:typeof e.bindPassword==`string`?`replaced on save`:e.bindPasswordSet?`stored — leave empty to keep it`:`none set`;return(0,T.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsxs)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:[`#`,t+1]}),(0,T.jsx)(f,{className:`h-8 max-w-[14rem] font-mono text-sm`,value:e.name,disabled:i,onChange:e=>n({name:e.target.value}),placeholder:`primary`,"aria-label":`Server name`}),(0,T.jsx)(`div`,{className:`flex-1`}),(0,T.jsx)(d,{type:`button`,size:`sm`,variant:`ghost`,onClick:r,disabled:i,"aria-label":`Remove server`,children:(0,T.jsx)(s,{className:`h-3.5 w-3.5`})})]}),(0,T.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,T.jsx)(F,{label:`Server URL`,hint:`ldap:// or ldaps://host:port`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.url,disabled:i,onChange:e=>n({url:e.target.value}),placeholder:`ldaps://dc1.example.com:636`})}),(0,T.jsx)(F,{label:`Search base`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.searchBase,disabled:i,onChange:e=>n({searchBase:e.target.value}),placeholder:`ou=users,dc=example,dc=com`})}),(0,T.jsx)(F,{label:`Bind DN`,hint:`Service account used to look users up. Empty = anonymous search.`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.bindDN,disabled:i,onChange:e=>n({bindDN:e.target.value}),placeholder:`cn=canvas,ou=services,dc=example,dc=com`})}),(0,T.jsx)(F,{label:`Bind password`,hint:(0,T.jsxs)(T.Fragment,{children:[`Currently: `,g,e.bindPasswordSet&&e.bindPassword!==null&&(0,T.jsxs)(T.Fragment,{children:[` · `,(0,T.jsx)(`button`,{type:`button`,className:`underline hover:text-foreground`,disabled:i,onClick:()=>n({bindPassword:null}),children:`clear`})]})]}),children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`password`,autoComplete:`new-password`,value:typeof e.bindPassword==`string`?e.bindPassword:``,disabled:i,onChange:e=>n({bindPassword:e.target.value===``?void 0:e.target.value}),placeholder:e.bindPasswordSet&&e.bindPassword!==null?`••••••••`:``})}),(0,T.jsx)(F,{label:`User search filter`,hint:(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`span`,{className:`font-mono`,children:`{{email}}`}),` is replaced by the address typed at sign-in.`]}),children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.searchFilter,disabled:i,onChange:e=>n({searchFilter:e.target.value})})}),(0,T.jsx)(F,{label:`Group attribute`,hint:`Group memberships drive team workspace sharing.`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.groupAttribute,disabled:i,onChange:e=>n({groupAttribute:e.target.value}),placeholder:`memberOf`})}),(0,T.jsx)(F,{label:`Attributes to read`,hint:`Comma-separated.`,className:`sm:col-span-2`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.attributes.join(`, `),disabled:i,onChange:e=>n({attributes:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})})})]}),(0,T.jsx)(I,{checked:e.tls,disabled:i,onChange:e=>n({tls:e}),label:`Accept self-signed certificates`,hint:`Skips certificate verification for ldaps://. Only for directories with a private CA.`}),(0,T.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2 border-t pt-3`,children:[(0,T.jsx)(F,{label:`Test`,hint:`Binds with the settings above (unsaved edits included). Add an e-mail to also look that user up.`,className:`min-w-[14rem] flex-1`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`email`,value:a,onChange:e=>o(e.target.value),placeholder:`someone@example.com (optional)`})}),(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:h,disabled:l||i,className:`mb-5`,children:[l&&(0,T.jsx)(c,{className:`mr-2 h-3.5 w-3.5 animate-spin`}),`Test connection`]})]}),(0,T.jsx)(R,{result:p})]})}function V({row:e,onChange:t,onRemove:n,disabled:r}){let[i,a]=(0,b.useState)(``),[o,l]=(0,b.useState)(``),[u,p]=(0,b.useState)(!1),[m,h]=(0,b.useState)(null);return(0,T.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:`@`}),(0,T.jsx)(f,{className:`h-8 max-w-[16rem] font-mono text-sm`,value:e.domain,disabled:r,onChange:e=>t({domain:e.target.value}),placeholder:`example.com`,"aria-label":`E-mail domain`}),(0,T.jsx)(`div`,{className:`flex-1`}),(0,T.jsx)(d,{type:`button`,size:`sm`,variant:`ghost`,onClick:n,disabled:r,"aria-label":`Remove domain`,children:(0,T.jsx)(s,{className:`h-3.5 w-3.5`})})]}),(0,T.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-[1fr_6rem_1fr]`,children:[(0,T.jsx)(F,{label:`IMAP host`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.host,disabled:r,onChange:e=>t({host:e.target.value}),placeholder:`imap.example.com`})}),(0,T.jsx)(F,{label:`Port`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`number`,min:1,max:65535,value:e.port,disabled:r,onChange:e=>t({port:Number(e.target.value)})})}),(0,T.jsx)(F,{label:`Label on the sign-in form`,hint:`Optional.`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,value:e.name,disabled:r,onChange:e=>t({name:e.target.value}),placeholder:`Example Mail`})})]}),(0,T.jsxs)(`div`,{className:`flex flex-wrap gap-x-6 gap-y-2`,children:[(0,T.jsx)(I,{checked:e.secure,disabled:r,onChange:e=>t({secure:e,...e?{startTLS:!1}:{}}),label:`TLS from the start`,hint:`Usually port 993.`}),(0,T.jsx)(I,{checked:e.startTLS,disabled:r||e.secure,onChange:e=>t({startTLS:e}),label:`Require STARTTLS`,hint:`Plain port 143 upgraded to TLS.`}),(0,T.jsx)(I,{checked:e.requireAppPassword,disabled:r,onChange:e=>t({requireAppPassword:e}),label:`Needs an app password`,hint:`Shown as a hint on the sign-in form.`})]}),(0,T.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2 border-t pt-3`,children:[(0,T.jsx)(F,{label:`Test sign-in`,hint:`A real IMAP login with these credentials, logged straight out. Nothing is stored.`,className:`min-w-[12rem] flex-1`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`email`,value:i,onChange:e=>a(e.target.value),placeholder:`someone@${e.domain||`example.com`}`})}),(0,T.jsx)(F,{label:`Password`,className:`mb-5 min-w-[10rem] flex-1`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`password`,autoComplete:`off`,value:o,onChange:e=>l(e.target.value)})}),(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:async()=>{p(!0),h(null);try{let{id:t,domain:n,...r}=e;h(await w(r,i.trim(),o))}catch(e){h({ok:!1,message:e instanceof Error?e.message:`Test failed`})}finally{p(!1),l(``)}},disabled:u||r||!i||!o,className:`mb-5`,children:[u&&(0,T.jsx)(c,{className:`mr-2 h-3.5 w-3.5 animate-spin`}),`Test`]})]}),(0,T.jsx)(R,{result:m})]})}function H(){let e=y(),{showToast:t}=_(),n=g()?.userType===`admin`,[r,a]=(0,b.useState)(``),[s,u]=(0,b.useState)(null),[p,h]=(0,b.useState)(null),[C,w]=(0,b.useState)(!0),[E,k]=(0,b.useState)(!1),[P,R]=(0,b.useState)(null),[H,U]=(0,b.useState)(null),W=(0,b.useCallback)(()=>x().then(e=>{let t=O(e.config);a(e.configPath),u(t),h(t),R(null)}).catch(e=>R(e instanceof Error?e.message:`Failed to load auth configuration`)).finally(()=>w(!1)),[]);(0,b.useEffect)(()=>{n&&W()},[n,W]);let G=(0,b.useMemo)(()=>!!p&&!!s&&JSON.stringify(A(p))!==JSON.stringify(A(s)),[p,s]),K=e=>h(t=>t&&e(t)),q=(e,t)=>K(n=>({...n,ldap:{...n.ldap,servers:n.ldap.servers.map(n=>n.id===e?{...n,...t}:n)}})),J=(e,t)=>K(n=>({...n,imap:{...n.imap,domains:n.imap.domains.map(n=>n.id===e?{...n,...t}:n)}})),Y=async()=>{if(!p)return;let e=p.ldap.servers.map(e=>e.name.trim()),n=p.imap.domains.map(e=>e.domain.trim().toLowerCase());if(e.some(e=>!e)||new Set(e).size!==e.length){U(`Every LDAP server needs a unique name.`);return}if(n.some(e=>!e)||new Set(n).size!==n.length){U(`Every IMAP domain must be filled in and listed once.`);return}k(!0),U(null);try{let e=O((await S(A(p))).config);u(e),h(e),t({title:`Authentication settings saved`,description:`Applied immediately — the next sign-in uses them.`})}catch(e){U(e instanceof Error?e.message.replace(/^HTTP \d+:\s*/,``):`Failed to save`)}finally{k(!1)}},X=(0,T.jsx)(v,{onBack:e,compact:!0,className:`mb-6`,title:`Authentication`,description:`Entire server · Choose how people sign in: local passwords, your LDAP directory, or their mail server over IMAP.`,actions:n&&(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>{w(!0),W()},disabled:C||E,children:[(0,T.jsx)(o,{className:`mr-2 h-3.5 w-3.5`}),`Reload`]})});return n?(0,T.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6 pb-24`,children:[X,C&&!p?(0,T.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,T.jsx)(o,{className:`h-4 w-4 animate-spin`}),`Loading…`]}):P||!p?(0,T.jsxs)(`div`,{className:`space-y-3`,children:[(0,T.jsxs)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm`,children:[(0,T.jsx)(`p`,{className:`font-medium text-destructive`,children:`Authentication settings unavailable`}),(0,T.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:P||`No config returned.`})]}),(0,T.jsx)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>{w(!0),W()},children:`Retry`})]}):(0,T.jsxs)(`div`,{className:`space-y-4`,children:[(0,T.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Config file: `,(0,T.jsx)(`span`,{className:`font-mono`,children:r}),` · Sign-in picks the backend from the account: existing users keep the method they were created with; a new address tries LDAP first (when enabled), then IMAP for a listed domain, then local.`]}),(0,T.jsxs)(L,{title:`Sign-up & local passwords`,description:`Accounts whose password is stored on this server.`,children:[(0,T.jsx)(I,{checked:p.allowUserRegistrations,onChange:e=>K(t=>({...t,allowUserRegistrations:e})),label:`Allow self-registration`,hint:`Off = only admins create accounts (and LDAP/IMAP users on first sign-in).`}),(0,T.jsx)(I,{checked:p.local.enabled,onChange:e=>K(t=>({...t,local:{...t.local,enabled:e}})),label:`Local password accounts`,hint:`Off refuses new local registrations. Existing local accounts — admins included — can still sign in, so this cannot lock you out.`}),(0,T.jsx)(I,{checked:p.local.requireEmailVerification,onChange:e=>K(t=>({...t,local:{...t.local,requireEmailVerification:e}})),label:`Require e-mail verification`,hint:`Needs working SMTP (config/smtp.json).`}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`p`,{className:`mb-2 text-xs font-medium`,children:`Password policy`}),(0,T.jsxs)(`div`,{className:`flex flex-wrap items-start gap-4`,children:[(0,T.jsx)(F,{label:`Min length`,children:(0,T.jsx)(f,{className:`h-8 w-24 text-sm`,type:`number`,min:1,max:1024,value:p.local.passwordPolicy.minLength,onChange:e=>K(t=>({...t,local:{...t.local,passwordPolicy:{...t.local.passwordPolicy,minLength:Number(e.target.value)}}}))})}),(0,T.jsx)(F,{label:`Max length`,children:(0,T.jsx)(f,{className:`h-8 w-24 text-sm`,type:`number`,min:1,max:1024,value:p.local.passwordPolicy.maxLength,onChange:e=>K(t=>({...t,local:{...t.local,passwordPolicy:{...t.local.passwordPolicy,maxLength:Number(e.target.value)}}}))})}),(0,T.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-1 pt-1`,children:[[`requireUppercase`,`Uppercase letter`],[`requireLowercase`,`Lowercase letter`],[`requireNumbers`,`Number`],[`requireSpecialChars`,`Special character`]].map(([e,t])=>(0,T.jsx)(I,{checked:p.local.passwordPolicy[e],label:t,onChange:t=>K(n=>({...n,local:{...n.local,passwordPolicy:{...n.local.passwordPolicy,[e]:t}}}))},e))})]})]})]}),(0,T.jsxs)(L,{title:`LDAP / Active Directory`,description:`Users sign in with their directory password. Servers are tried in order, so later ones act as fallbacks.`,enabled:p.ldap.enabled,onToggle:e=>K(t=>({...t,ldap:{...t.ldap,enabled:e}})),children:[(0,T.jsx)(z,{value:p.ldap,onChange:e=>K(t=>({...t,ldap:{...t.ldap,...e}}))}),p.ldap.servers.map((e,t)=>(0,T.jsx)(B,{row:e,index:t,onChange:t=>q(e.id,t),onRemove:()=>K(t=>({...t,ldap:{...t.ldap,servers:t.ldap.servers.filter(t=>t.id!==e.id)}}))},e.id)),(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>K(e=>({...e,ldap:{...e.ldap,servers:[...e.ldap.servers,{...M,id:D(),name:e.ldap.servers.length?`server${e.ldap.servers.length+1}`:`primary`}]}})),children:[(0,T.jsx)(i,{className:`mr-2 h-3.5 w-3.5`}),` Add LDAP server`]})]}),(0,T.jsxs)(L,{title:`IMAP (mail server sign-in)`,description:`Users of a listed e-mail domain sign in with their mailbox password — the server checks it by logging in to IMAP.`,enabled:p.imap.enabled,onToggle:e=>K(t=>({...t,imap:{...t.imap,enabled:e}})),children:[(0,T.jsx)(z,{value:p.imap,onChange:e=>K(t=>({...t,imap:{...t.imap,...e}}))}),p.imap.domains.map(e=>(0,T.jsx)(V,{row:e,onChange:t=>J(e.id,t),onRemove:()=>K(t=>({...t,imap:{...t.imap,domains:t.imap.domains.filter(t=>t.id!==e.id)}}))},e.id)),(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>K(e=>({...e,imap:{...e.imap,domains:[...e.imap.domains,{...N,id:D()}]}})),children:[(0,T.jsx)(i,{className:`mr-2 h-3.5 w-3.5`}),` Add mail domain`]})]}),(0,T.jsxs)(L,{title:`Google sign-in`,description:(0,T.jsxs)(T.Fragment,{children:[`One-click sign-in with a Google account via OAuth. Needs a Google Cloud OAuth client of type `,(0,T.jsx)(`em`,{children:`Web application`}),` whose authorized redirect URI is `,(0,T.jsx)(`code`,{className:`select-all`,children:`${m}/oauth/google/callback`}),`.`]}),enabled:p.google.enabled,onToggle:e=>K(t=>({...t,google:{...t.google,enabled:e}})),children:[(0,T.jsx)(z,{value:p.google,onChange:e=>K(t=>({...t,google:{...t.google,...e}}))}),(0,T.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,T.jsx)(F,{label:`OAuth client id`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:p.google.clientId,autoComplete:`off`,onChange:e=>K(t=>({...t,google:{...t.google,clientId:e.target.value}}))})}),(0,T.jsx)(F,{label:`OAuth client secret`,hint:p.google.clientSecretSet&&p.google.clientSecret===void 0?`A secret is stored; leave blank to keep it.`:void 0,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,type:`password`,autoComplete:`off`,value:p.google.clientSecret??``,placeholder:p.google.clientSecretSet?`••••••••`:``,onChange:e=>K(t=>({...t,google:{...t.google,clientSecret:e.target.value===``?void 0:e.target.value}}))})}),(0,T.jsx)(F,{label:`Allowed e-mail domains`,hint:`Comma separated. Empty = any Google account may sign in.`,children:(0,T.jsx)(j,{value:p.google.allowedDomains,placeholder:`example.com, example.org`,onChange:e=>K(t=>({...t,google:{...t.google,allowedDomains:e}}))})}),(0,T.jsx)(F,{label:`Extra web origins`,hint:`Only when the web UI is served from another origin than the API (e.g. a Vite dev server).`,children:(0,T.jsx)(j,{value:p.google.webOrigins,placeholder:`http://localhost:5173`,onChange:e=>K(t=>({...t,google:{...t.google,webOrigins:e}}))})})]}),(0,T.jsx)(I,{checked:p.google.autoCreateUsers,label:`Create an account on first sign-in`,hint:`Off: only users that already exist (by e-mail) can sign in with Google.`,onChange:e=>K(t=>({...t,google:{...t.google,autoCreateUsers:e}}))})]}),(G||H)&&(0,T.jsxs)(`div`,{className:`sticky bottom-4 z-10 rounded-lg border bg-card p-3 shadow-elevation-4`,children:[H&&(0,T.jsx)(`ul`,{className:`mb-2 space-y-0.5 text-xs text-destructive`,children:H.split(`; `).map(e=>(0,T.jsx)(`li`,{children:e},e))}),(0,T.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,T.jsx)(`span`,{className:`mr-auto text-xs text-muted-foreground`,children:G?`Unsaved changes`:``}),(0,T.jsx)(d,{type:`button`,size:`sm`,variant:`ghost`,disabled:E,onClick:()=>{h(s),U(null)},children:`Discard`}),(0,T.jsxs)(d,{type:`button`,size:`sm`,disabled:E||!G,onClick:()=>void Y(),children:[E&&(0,T.jsx)(c,{className:`mr-2 h-3.5 w-3.5 animate-spin`}),`Save`]})]})]})]})]}):(0,T.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[X,(0,T.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border p-3 text-xs`,children:[(0,T.jsx)(l,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,T.jsx)(`p`,{className:`text-muted-foreground`,children:`Authentication settings are only available to server admins.`})]})]})}export{H as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Nt as r,Ot as i,Pr as a,X as o,fn as s,jr as c,pt as l}from"./ui-Byg1cZDr.js";import{t as u}from"./utils-2pl1SbIp.js";import{t as d}from"./button-SgR3GVvV.js";import{t as f}from"./input-BOtCd4HP.js";import{c as p,l as m,t as h}from"./api-CA6WiiYM.js";import{i as g}from"./auth-Bx9fAZmz.js";import{n as _}from"./use-toast-BlLDqSUO.js";import{n as v}from"./page-header-DkOHw0g-.js";import{t as y}from"./use-settings-back-CQauYjQ4.js";var b=e(n(),1);function x(){return h.get(p.admin.authConfig)}function S(e){return h.put(p.admin.authConfig,e)}function C(e,t,n){return h.post(`${p.admin.authConfig}/test`,{strategy:`ldap`,name:e,server:t,email:n})}function w(e,t,n){return h.post(`${p.admin.authConfig}/test`,{strategy:`imap`,domain:e,email:t,password:n})}var T=t(),E=0,D=()=>`row-${++E}`;function O(e){let{servers:t,...n}=e.strategies.ldap,{domains:r,...i}=e.strategies.imap;return{allowUserRegistrations:e.allowUserRegistrations,local:e.strategies.local,ldap:{...n,servers:Object.entries(t).map(([e,t])=>({...t,id:D(),name:e,originalName:e}))},imap:{...i,domains:Object.entries(r).map(([e,t])=>({...t,id:D(),domain:e}))},google:e.strategies.google??{enabled:!1,defaultUserType:`user`,defaultStatus:`active`,clientId:``,clientSecretSet:!1,allowedDomains:[],autoCreateUsers:!0,webOrigins:[]}}}function k(e){let{id:t,name:n,originalName:r,...i}=e;return{...i,...r&&r!==e.name?{previousName:r}:{}}}function A(e){return{allowUserRegistrations:e.allowUserRegistrations,strategies:{local:e.local,ldap:{enabled:e.ldap.enabled,defaultUserType:e.ldap.defaultUserType,defaultStatus:e.ldap.defaultStatus,servers:Object.fromEntries(e.ldap.servers.map(e=>[e.name.trim(),k(e)]))},imap:{enabled:e.imap.enabled,defaultUserType:e.imap.defaultUserType,defaultStatus:e.imap.defaultStatus,domains:Object.fromEntries(e.imap.domains.map(({id:e,domain:t,...n})=>[t.trim().toLowerCase(),n]))},google:e.google}}}function j({value:e,onChange:t,placeholder:n,disabled:r}){let i=e.join(`, `),[a,o]=(0,b.useState)(i),[s,c]=(0,b.useState)(i);return i!==s&&(c(i),a.split(/[\s,]+/).filter(Boolean).join(`, `)!==i&&o(i)),(0,T.jsx)(f,{className:`h-8 text-sm`,value:a,placeholder:n,disabled:r,onChange:e=>{o(e.target.value),t(e.target.value.split(/[\s,]+/).map(e=>e.trim()).filter(Boolean))}})}var M={originalName:null,url:`ldap://`,bindDN:``,bindPasswordSet:!1,bindPassword:void 0,searchBase:``,searchFilter:`(mail={{email}})`,attributes:[`mail`,`cn`,`displayName`,`memberOf`],groupAttribute:`memberOf`,tls:!1},N={domain:``,name:``,host:``,port:993,secure:!0,startTLS:!1,requireAppPassword:!1},P=`h-8 rounded-md border border-input bg-transparent px-2 text-sm outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:opacity-50`;function F({label:e,hint:t,children:n,className:r}){return(0,T.jsxs)(`label`,{className:u(`flex min-w-0 flex-col gap-1`,r),children:[(0,T.jsx)(`span`,{className:`text-xs font-medium`,children:e}),n,t&&(0,T.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:t})]})}function I({checked:e,onChange:t,disabled:n,label:r,hint:i}){return(0,T.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,T.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:e,disabled:n,onChange:e=>t(e.target.checked)}),(0,T.jsxs)(`span`,{children:[r,i&&(0,T.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:i})]})]})}function L({title:e,description:t,enabled:n,onToggle:r,disabled:i,children:a}){return(0,T.jsxs)(`section`,{className:`rounded-lg border p-4`,children:[(0,T.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`h3`,{className:`text-sm font-semibold`,children:e}),(0,T.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:t})]}),r&&(0,T.jsxs)(`label`,{className:`flex shrink-0 items-center gap-2 text-xs font-medium`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:!!n,disabled:i,onChange:e=>r(e.target.checked)}),n?`Enabled`:`Disabled`]})]}),(0,T.jsx)(`div`,{className:u(`mt-4 space-y-4`,r&&!n&&`opacity-60`),children:a})]})}function R({result:e}){return e?(0,T.jsxs)(`div`,{className:u(`flex items-start gap-2 rounded-md border p-2 text-xs`,e.ok?`border-emerald-500/40 bg-emerald-500/5`:`border-destructive/40 bg-destructive/5`),children:[e.ok?(0,T.jsx)(a,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-emerald-600`}):(0,T.jsx)(c,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive`}),(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`p`,{children:e.message}),e.user&&e.user.groups.length>0&&(0,T.jsxs)(`p`,{className:`mt-1 break-all text-muted-foreground`,children:[`Groups: `,e.user.groups.join(` · `)]})]})]}):null}function z({value:e,onChange:t,disabled:n}){return(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap gap-4`,children:[(0,T.jsx)(F,{label:`New accounts are`,children:(0,T.jsxs)(`select`,{className:P,value:e.defaultUserType,disabled:n,onChange:e=>t({defaultUserType:e.target.value}),children:[(0,T.jsx)(`option`,{value:`user`,children:`Users`}),(0,T.jsx)(`option`,{value:`admin`,children:`Admins`})]})}),(0,T.jsx)(F,{label:`Initial status`,children:(0,T.jsxs)(`select`,{className:P,value:e.defaultStatus,disabled:n,onChange:e=>t({defaultStatus:e.target.value}),children:[(0,T.jsx)(`option`,{value:`active`,children:`Active — can sign in right away`}),(0,T.jsx)(`option`,{value:`pending`,children:`Pending — an admin activates them`}),(0,T.jsx)(`option`,{value:`inactive`,children:`Inactive`})]})})]}),e.defaultUserType===`admin`&&(0,T.jsxs)(`p`,{className:`flex items-start gap-1.5 text-[11px] text-destructive`,children:[(0,T.jsx)(l,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),`Everyone who can sign in through this backend becomes a server admin on first login.`]})]})}function B({row:e,index:t,onChange:n,onRemove:r,disabled:i}){let[a,c]=(0,b.useState)(``),[l,u]=(0,b.useState)(!1),[p,m]=(0,b.useState)(null),h=async()=>{u(!0),m(null);try{m(await C(e.originalName??e.name,k(e),a.trim()||void 0))}catch(e){m({ok:!1,message:e instanceof Error?e.message:`Test failed`})}finally{u(!1)}},g=e.bindPassword===null?`cleared on save`:typeof e.bindPassword==`string`?`replaced on save`:e.bindPasswordSet?`stored — leave empty to keep it`:`none set`;return(0,T.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsxs)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:[`#`,t+1]}),(0,T.jsx)(f,{className:`h-8 max-w-[14rem] font-mono text-sm`,value:e.name,disabled:i,onChange:e=>n({name:e.target.value}),placeholder:`primary`,"aria-label":`Server name`}),(0,T.jsx)(`div`,{className:`flex-1`}),(0,T.jsx)(d,{type:`button`,size:`sm`,variant:`ghost`,onClick:r,disabled:i,"aria-label":`Remove server`,children:(0,T.jsx)(o,{className:`h-3.5 w-3.5`})})]}),(0,T.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,T.jsx)(F,{label:`Server URL`,hint:`ldap:// or ldaps://host:port`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.url,disabled:i,onChange:e=>n({url:e.target.value}),placeholder:`ldaps://dc1.example.com:636`})}),(0,T.jsx)(F,{label:`Search base`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.searchBase,disabled:i,onChange:e=>n({searchBase:e.target.value}),placeholder:`ou=users,dc=example,dc=com`})}),(0,T.jsx)(F,{label:`Bind DN`,hint:`Service account used to look users up. Empty = anonymous search.`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.bindDN,disabled:i,onChange:e=>n({bindDN:e.target.value}),placeholder:`cn=canvas,ou=services,dc=example,dc=com`})}),(0,T.jsx)(F,{label:`Bind password`,hint:(0,T.jsxs)(T.Fragment,{children:[`Currently: `,g,e.bindPasswordSet&&e.bindPassword!==null&&(0,T.jsxs)(T.Fragment,{children:[` · `,(0,T.jsx)(`button`,{type:`button`,className:`underline hover:text-foreground`,disabled:i,onClick:()=>n({bindPassword:null}),children:`clear`})]})]}),children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`password`,autoComplete:`new-password`,value:typeof e.bindPassword==`string`?e.bindPassword:``,disabled:i,onChange:e=>n({bindPassword:e.target.value===``?void 0:e.target.value}),placeholder:e.bindPasswordSet&&e.bindPassword!==null?`••••••••`:``})}),(0,T.jsx)(F,{label:`User search filter`,hint:(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`span`,{className:`font-mono`,children:`{{email}}`}),` is replaced by the address typed at sign-in.`]}),children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.searchFilter,disabled:i,onChange:e=>n({searchFilter:e.target.value})})}),(0,T.jsx)(F,{label:`Group attribute`,hint:`Group memberships drive team workspace sharing.`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.groupAttribute,disabled:i,onChange:e=>n({groupAttribute:e.target.value}),placeholder:`memberOf`})}),(0,T.jsx)(F,{label:`Attributes to read`,hint:`Comma-separated.`,className:`sm:col-span-2`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.attributes.join(`, `),disabled:i,onChange:e=>n({attributes:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})})})]}),(0,T.jsx)(I,{checked:e.tls,disabled:i,onChange:e=>n({tls:e}),label:`Accept self-signed certificates`,hint:`Skips certificate verification for ldaps://. Only for directories with a private CA.`}),(0,T.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2 border-t pt-3`,children:[(0,T.jsx)(F,{label:`Test`,hint:`Binds with the settings above (unsaved edits included). Add an e-mail to also look that user up.`,className:`min-w-[14rem] flex-1`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`email`,value:a,onChange:e=>c(e.target.value),placeholder:`someone@example.com (optional)`})}),(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:h,disabled:l||i,className:`mb-5`,children:[l&&(0,T.jsx)(s,{className:`mr-2 h-3.5 w-3.5 animate-spin`}),`Test connection`]})]}),(0,T.jsx)(R,{result:p})]})}function V({row:e,onChange:t,onRemove:n,disabled:r}){let[i,a]=(0,b.useState)(``),[c,l]=(0,b.useState)(``),[u,p]=(0,b.useState)(!1),[m,h]=(0,b.useState)(null);return(0,T.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:`@`}),(0,T.jsx)(f,{className:`h-8 max-w-[16rem] font-mono text-sm`,value:e.domain,disabled:r,onChange:e=>t({domain:e.target.value}),placeholder:`example.com`,"aria-label":`E-mail domain`}),(0,T.jsx)(`div`,{className:`flex-1`}),(0,T.jsx)(d,{type:`button`,size:`sm`,variant:`ghost`,onClick:n,disabled:r,"aria-label":`Remove domain`,children:(0,T.jsx)(o,{className:`h-3.5 w-3.5`})})]}),(0,T.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-[1fr_6rem_1fr]`,children:[(0,T.jsx)(F,{label:`IMAP host`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.host,disabled:r,onChange:e=>t({host:e.target.value}),placeholder:`imap.example.com`})}),(0,T.jsx)(F,{label:`Port`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`number`,min:1,max:65535,value:e.port,disabled:r,onChange:e=>t({port:Number(e.target.value)})})}),(0,T.jsx)(F,{label:`Label on the sign-in form`,hint:`Optional.`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,value:e.name,disabled:r,onChange:e=>t({name:e.target.value}),placeholder:`Example Mail`})})]}),(0,T.jsxs)(`div`,{className:`flex flex-wrap gap-x-6 gap-y-2`,children:[(0,T.jsx)(I,{checked:e.secure,disabled:r,onChange:e=>t({secure:e,...e?{startTLS:!1}:{}}),label:`TLS from the start`,hint:`Usually port 993.`}),(0,T.jsx)(I,{checked:e.startTLS,disabled:r||e.secure,onChange:e=>t({startTLS:e}),label:`Require STARTTLS`,hint:`Plain port 143 upgraded to TLS.`}),(0,T.jsx)(I,{checked:e.requireAppPassword,disabled:r,onChange:e=>t({requireAppPassword:e}),label:`Needs an app password`,hint:`Shown as a hint on the sign-in form.`})]}),(0,T.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2 border-t pt-3`,children:[(0,T.jsx)(F,{label:`Test sign-in`,hint:`A real IMAP login with these credentials, logged straight out. Nothing is stored.`,className:`min-w-[12rem] flex-1`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`email`,value:i,onChange:e=>a(e.target.value),placeholder:`someone@${e.domain||`example.com`}`})}),(0,T.jsx)(F,{label:`Password`,className:`mb-5 min-w-[10rem] flex-1`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`password`,autoComplete:`off`,value:c,onChange:e=>l(e.target.value)})}),(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:async()=>{p(!0),h(null);try{let{id:t,domain:n,...r}=e;h(await w(r,i.trim(),c))}catch(e){h({ok:!1,message:e instanceof Error?e.message:`Test failed`})}finally{p(!1),l(``)}},disabled:u||r||!i||!c,className:`mb-5`,children:[u&&(0,T.jsx)(s,{className:`mr-2 h-3.5 w-3.5 animate-spin`}),`Test`]})]}),(0,T.jsx)(R,{result:m})]})}function H(){let e=y(),{showToast:t}=_(),n=g()?.userType===`admin`,[a,o]=(0,b.useState)(``),[c,u]=(0,b.useState)(null),[p,h]=(0,b.useState)(null),[C,w]=(0,b.useState)(!0),[E,k]=(0,b.useState)(!1),[P,R]=(0,b.useState)(null),[H,U]=(0,b.useState)(null),W=(0,b.useCallback)(()=>x().then(e=>{let t=O(e.config);o(e.configPath),u(t),h(t),R(null)}).catch(e=>R(e instanceof Error?e.message:`Failed to load auth configuration`)).finally(()=>w(!1)),[]);(0,b.useEffect)(()=>{n&&W()},[n,W]);let G=(0,b.useMemo)(()=>!!p&&!!c&&JSON.stringify(A(p))!==JSON.stringify(A(c)),[p,c]),K=e=>h(t=>t&&e(t)),q=(e,t)=>K(n=>({...n,ldap:{...n.ldap,servers:n.ldap.servers.map(n=>n.id===e?{...n,...t}:n)}})),J=(e,t)=>K(n=>({...n,imap:{...n.imap,domains:n.imap.domains.map(n=>n.id===e?{...n,...t}:n)}})),Y=async()=>{if(!p)return;let e=p.ldap.servers.map(e=>e.name.trim()),n=p.imap.domains.map(e=>e.domain.trim().toLowerCase());if(e.some(e=>!e)||new Set(e).size!==e.length){U(`Every LDAP server needs a unique name.`);return}if(n.some(e=>!e)||new Set(n).size!==n.length){U(`Every IMAP domain must be filled in and listed once.`);return}k(!0),U(null);try{let e=O((await S(A(p))).config);u(e),h(e),t({title:`Authentication settings saved`,description:`Applied immediately — the next sign-in uses them.`})}catch(e){U(e instanceof Error?e.message.replace(/^HTTP \d+:\s*/,``):`Failed to save`)}finally{k(!1)}},X=(0,T.jsx)(v,{onBack:e,compact:!0,className:`mb-6`,title:`Authentication`,description:`Entire server · Choose how people sign in: local passwords, your LDAP directory, or their mail server over IMAP.`,actions:n&&(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>{w(!0),W()},disabled:C||E,children:[(0,T.jsx)(i,{className:`mr-2 h-3.5 w-3.5`}),`Reload`]})});return n?(0,T.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6 pb-24`,children:[X,C&&!p?(0,T.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,T.jsx)(i,{className:`h-4 w-4 animate-spin`}),`Loading…`]}):P||!p?(0,T.jsxs)(`div`,{className:`space-y-3`,children:[(0,T.jsxs)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm`,children:[(0,T.jsx)(`p`,{className:`font-medium text-destructive`,children:`Authentication settings unavailable`}),(0,T.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:P||`No config returned.`})]}),(0,T.jsx)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>{w(!0),W()},children:`Retry`})]}):(0,T.jsxs)(`div`,{className:`space-y-4`,children:[(0,T.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Config file: `,(0,T.jsx)(`span`,{className:`font-mono`,children:a}),` · Sign-in picks the backend from the account: existing users keep the method they were created with; a new address tries LDAP first (when enabled), then IMAP for a listed domain, then local.`]}),(0,T.jsxs)(L,{title:`Sign-up & local passwords`,description:`Accounts whose password is stored on this server.`,children:[(0,T.jsx)(I,{checked:p.allowUserRegistrations,onChange:e=>K(t=>({...t,allowUserRegistrations:e})),label:`Allow self-registration`,hint:`Off = only admins create accounts (and LDAP/IMAP users on first sign-in).`}),(0,T.jsx)(I,{checked:p.local.enabled,onChange:e=>K(t=>({...t,local:{...t.local,enabled:e}})),label:`Local password accounts`,hint:`Off refuses new local registrations. Existing local accounts — admins included — can still sign in, so this cannot lock you out.`}),(0,T.jsx)(I,{checked:p.local.requireEmailVerification,onChange:e=>K(t=>({...t,local:{...t.local,requireEmailVerification:e}})),label:`Require e-mail verification`,hint:`Needs working SMTP (config/smtp.json).`}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`p`,{className:`mb-2 text-xs font-medium`,children:`Password policy`}),(0,T.jsxs)(`div`,{className:`flex flex-wrap items-start gap-4`,children:[(0,T.jsx)(F,{label:`Min length`,children:(0,T.jsx)(f,{className:`h-8 w-24 text-sm`,type:`number`,min:1,max:1024,value:p.local.passwordPolicy.minLength,onChange:e=>K(t=>({...t,local:{...t.local,passwordPolicy:{...t.local.passwordPolicy,minLength:Number(e.target.value)}}}))})}),(0,T.jsx)(F,{label:`Max length`,children:(0,T.jsx)(f,{className:`h-8 w-24 text-sm`,type:`number`,min:1,max:1024,value:p.local.passwordPolicy.maxLength,onChange:e=>K(t=>({...t,local:{...t.local,passwordPolicy:{...t.local.passwordPolicy,maxLength:Number(e.target.value)}}}))})}),(0,T.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-1 pt-1`,children:[[`requireUppercase`,`Uppercase letter`],[`requireLowercase`,`Lowercase letter`],[`requireNumbers`,`Number`],[`requireSpecialChars`,`Special character`]].map(([e,t])=>(0,T.jsx)(I,{checked:p.local.passwordPolicy[e],label:t,onChange:t=>K(n=>({...n,local:{...n.local,passwordPolicy:{...n.local.passwordPolicy,[e]:t}}}))},e))})]})]})]}),(0,T.jsxs)(L,{title:`LDAP / Active Directory`,description:`Users sign in with their directory password. Servers are tried in order, so later ones act as fallbacks.`,enabled:p.ldap.enabled,onToggle:e=>K(t=>({...t,ldap:{...t.ldap,enabled:e}})),children:[(0,T.jsx)(z,{value:p.ldap,onChange:e=>K(t=>({...t,ldap:{...t.ldap,...e}}))}),p.ldap.servers.map((e,t)=>(0,T.jsx)(B,{row:e,index:t,onChange:t=>q(e.id,t),onRemove:()=>K(t=>({...t,ldap:{...t.ldap,servers:t.ldap.servers.filter(t=>t.id!==e.id)}}))},e.id)),(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>K(e=>({...e,ldap:{...e.ldap,servers:[...e.ldap.servers,{...M,id:D(),name:e.ldap.servers.length?`server${e.ldap.servers.length+1}`:`primary`}]}})),children:[(0,T.jsx)(r,{className:`mr-2 h-3.5 w-3.5`}),` Add LDAP server`]})]}),(0,T.jsxs)(L,{title:`IMAP (mail server sign-in)`,description:`Users of a listed e-mail domain sign in with their mailbox password — the server checks it by logging in to IMAP.`,enabled:p.imap.enabled,onToggle:e=>K(t=>({...t,imap:{...t.imap,enabled:e}})),children:[(0,T.jsx)(z,{value:p.imap,onChange:e=>K(t=>({...t,imap:{...t.imap,...e}}))}),p.imap.domains.map(e=>(0,T.jsx)(V,{row:e,onChange:t=>J(e.id,t),onRemove:()=>K(t=>({...t,imap:{...t.imap,domains:t.imap.domains.filter(t=>t.id!==e.id)}}))},e.id)),(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>K(e=>({...e,imap:{...e.imap,domains:[...e.imap.domains,{...N,id:D()}]}})),children:[(0,T.jsx)(r,{className:`mr-2 h-3.5 w-3.5`}),` Add mail domain`]})]}),(0,T.jsxs)(L,{title:`Google sign-in`,description:(0,T.jsxs)(T.Fragment,{children:[`One-click sign-in with a Google account via OAuth. Needs a Google Cloud OAuth client of type `,(0,T.jsx)(`em`,{children:`Web application`}),` whose authorized redirect URI is `,(0,T.jsx)(`code`,{className:`select-all`,children:`${m}/oauth/google/callback`}),`.`]}),enabled:p.google.enabled,onToggle:e=>K(t=>({...t,google:{...t.google,enabled:e}})),children:[(0,T.jsx)(z,{value:p.google,onChange:e=>K(t=>({...t,google:{...t.google,...e}}))}),(0,T.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,T.jsx)(F,{label:`OAuth client id`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:p.google.clientId,autoComplete:`off`,onChange:e=>K(t=>({...t,google:{...t.google,clientId:e.target.value}}))})}),(0,T.jsx)(F,{label:`OAuth client secret`,hint:p.google.clientSecretSet&&p.google.clientSecret===void 0?`A secret is stored; leave blank to keep it.`:void 0,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,type:`password`,autoComplete:`off`,value:p.google.clientSecret??``,placeholder:p.google.clientSecretSet?`••••••••`:``,onChange:e=>K(t=>({...t,google:{...t.google,clientSecret:e.target.value===``?void 0:e.target.value}}))})}),(0,T.jsx)(F,{label:`Allowed e-mail domains`,hint:`Comma separated. Empty = any Google account may sign in.`,children:(0,T.jsx)(j,{value:p.google.allowedDomains,placeholder:`example.com, example.org`,onChange:e=>K(t=>({...t,google:{...t.google,allowedDomains:e}}))})}),(0,T.jsx)(F,{label:`Extra web origins`,hint:`Only when the web UI is served from another origin than the API (e.g. a Vite dev server).`,children:(0,T.jsx)(j,{value:p.google.webOrigins,placeholder:`http://localhost:5173`,onChange:e=>K(t=>({...t,google:{...t.google,webOrigins:e}}))})})]}),(0,T.jsx)(I,{checked:p.google.autoCreateUsers,label:`Create an account on first sign-in`,hint:`Off: only users that already exist (by e-mail) can sign in with Google.`,onChange:e=>K(t=>({...t,google:{...t.google,autoCreateUsers:e}}))})]}),(G||H)&&(0,T.jsxs)(`div`,{className:`sticky bottom-4 z-10 rounded-lg border bg-card p-3 shadow-elevation-4`,children:[H&&(0,T.jsx)(`ul`,{className:`mb-2 space-y-0.5 text-xs text-destructive`,children:H.split(`; `).map(e=>(0,T.jsx)(`li`,{children:e},e))}),(0,T.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,T.jsx)(`span`,{className:`mr-auto text-xs text-muted-foreground`,children:G?`Unsaved changes`:``}),(0,T.jsx)(d,{type:`button`,size:`sm`,variant:`ghost`,disabled:E,onClick:()=>{h(c),U(null)},children:`Discard`}),(0,T.jsxs)(d,{type:`button`,size:`sm`,disabled:E||!G,onClick:()=>void Y(),children:[E&&(0,T.jsx)(s,{className:`mr-2 h-3.5 w-3.5 animate-spin`}),`Save`]})]})]})]})]}):(0,T.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[X,(0,T.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border p-3 text-xs`,children:[(0,T.jsx)(l,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,T.jsx)(`p`,{className:`text-muted-foreground`,children:`Authentication settings are only available to server admins.`})]})]})}export{H as default};
@@ -0,0 +1,7 @@
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{$r as r,Ct as i,Hr as a,Jn as o,Kn as s,L as c,Nr as l,Nt as u,Q as d,X as f,Y as p,Z as m,Zr as h,_r as g,fn as ee,jn as _,li as v,ri as y,sn as b,st as x,zn as S,zt as te}from"./ui-Byg1cZDr.js";import{t as C}from"./utils-2pl1SbIp.js";import{t as w}from"./button-SgR3GVvV.js";import{t as T}from"./input-BOtCd4HP.js";import{c as ne,t as E}from"./api-CA6WiiYM.js";import{t as D}from"./socket-CtH3EU9m.js";import{n as re}from"./use-toast-BlLDqSUO.js";import{t as ie}from"./LinkToCard-nR7Lal_o.js";import{W as ae,bt as oe,gn as se,gt as ce,hn as O}from"./workspace-DvxC7pw1.js";import{i as le}from"./MessageComposerDialog-gbD0Gu_b.js";import{n as ue}from"./LinkToSidePanel-eCy3nW4R.js";import{t as de}from"./PathPickerField-DBe7jykL.js";var k=e(n(),1);function A(e){return`/workspaces/${e}/hooks`}async function fe(e){return await E.get(A(e))||[]}async function j(e,t){return(await E.get(`${A(e)}/${t}`))?.content??``}async function M(e,t,n){await E.put(`${A(e)}/${t}`,{content:n})}async function N(e,t){await E.delete(`${A(e)}/${t}`)}var pe=[`example-`,`disabled-`,`_`];function P(e){let t=e.lastIndexOf(`/`);return{dir:t===-1?``:e.slice(0,t+1),base:t===-1?e:e.slice(t+1)}}function F(e){return pe.find(t=>e.startsWith(t))??null}function me(e){return F(P(e).base)===null}function he(e){return P(e).base.startsWith(`example-`)}function ge(e){let{dir:t,base:n}=P(e),r=F(n);return t+(r?n.slice(r.length):`disabled-${n}`)}async function _e(e,t,n){if(me(t)===n)return t;let r=ge(t);return await M(e,r,await j(e,t)),await N(e,t),r}function ve(e){let t={};for(let n of e){let e;e=n.path.includes(`/`)?n.path.split(`/`)[0]:/^(?:example-|disabled-|_)?rules\.json$/.test(n.path)?`rules`:n.path.replace(/\.js$/,``),(t[e]||=[]).push(n)}return t}function ye(e){let t=e.when?.event;return Array.isArray(t)?t.map(String):t?[String(t)]:[]}function be(e){let t=e.when?.eventPathExact??e.when?.pathExact??e.when?.path;return Array.isArray(t)?t.map(String):typeof t==`string`?[t]:[]}function xe(e){let t=String(e||``).split(`/`).filter(Boolean);return t[0]===`workspace`&&t.length>=2?{backend:`workspace:${t[1]}`,rel:t.slice(2).join(`/`)}:t[0]===`device`?t.length>=3?{backend:t[2],rel:t.slice(3).join(`/`)}:null:t.length>=2?{backend:t[1],rel:t.slice(2).join(`/`)}:null}function Se(e){let t=new URLSearchParams;return e.kind&&e.kind!==`mirror`&&t.set(`addRuleKind`,e.kind),e.path&&t.set(`addRulePath`,e.path),e.target&&t.set(`addRuleTarget`,e.target),e.storeTo&&t.set(`addRuleStoreTo`,e.storeTo),e.storeFolder&&t.set(`addRuleStoreFolder`,e.storeFolder),t}function Ce(e){return String(e||``).replace(/^[a-z]+:/i,``).split(`/`).filter(Boolean).join(`/`)}var we=`rules.json`;async function Te(e){try{let t=await j(e,we),n=JSON.parse(t||`{}`);return Array.isArray(n.rules)?n.rules:[]}catch{return[]}}async function Ee(e,t){await M(e,we,JSON.stringify({$schema:`canvas.hook-rules/v1`,rules:t},null,2)+`
2
+ `)}async function De(e,t={}){let n=new URLSearchParams;t.status&&n.set(`status`,t.status),t.handler&&n.set(`handler`,t.handler),t.limit&&n.set(`limit`,String(t.limit));let r=n.toString();return await E.get(`${A(e)}/pending${r?`?${r}`:``}`)||[]}async function Oe(e,t){return await E.post(`${A(e)}/pending/decisions`,t)}async function ke(e,t){return await E.get(`${A(e)}/runs/${encodeURIComponent(t)}`)}async function Ae(e,t={}){let n=new URLSearchParams;t.limit&&n.set(`limit`,String(t.limit)),t.handler&&n.set(`handler`,t.handler),t.event&&n.set(`event`,t.event),t.failed&&n.set(`failed`,`true`);let r=n.toString();return await E.get(`${A(e)}/runs${r?`?${r}`:``}`)||[]}var I=1e4,je=`canvas.hooks.backfillLimit`;function Me(e){let t=Math.floor(Number(e));return!Number.isFinite(t)||t<1?500:Math.min(t,I)}function Ne(){try{let e=localStorage.getItem(je);return e?Me(e):500}catch{return 500}}function Pe(e){let t=Me(e);try{localStorage.setItem(je,String(t))}catch{}return t}function Fe(e){if(e.includes(`/`)){let t=e.split(`/`)[0];return t===`lib`||t===`rules`?null:t}return e.endsWith(`.js`)?e.replace(/\.js$/,``).replace(/^(?:example-|disabled-|_)/,``):null}async function Ie(e,t){return await E.post(`${A(e)}/backfill`,t)}function Le(e,t){return E.post(`${A(e)}/backfill/jobs`,t)}function L(e,t){return E.get(`${A(e)}/backfill/jobs/${t}`)}function Re(e,t){return E.delete(`${A(e)}/backfill/jobs/${t}`)}function ze(e){return E.get(`${A(e)}/backfill/jobs`)}async function R(e,t){return await E.post(`${A(e)}/run`,t)}async function z(e,t){return await E.post(`${A(e)}/runs/${t}/replay`,{})}async function Be(e){return await E.get(`${A(e)}/meta`)}async function Ve(e,t){return await E.post(`${A(e)}/generate`,t)}async function He(e,t){let n=await j(e,we),r=JSON.parse(n),i=Array.isArray(r)?r:r?.rules;if(!Array.isArray(i))throw Error(`The workspace rules file is invalid. Fix it in Rules before adding a rule.`);let a=(Array.isArray(t)?t:[t]).filter(e=>!i.some(t=>t.id===e.id));if(!a.length)return;let o=Array.isArray(r)?[...i,...a]:{...r,rules:[...i,...a]};await M(e,we,JSON.stringify(o,null,2)+`
3
+ `)}var Ue=He;function We(e,t,n,r=new Date){let i=e=>String(e).padStart(2,`0`),a={YYYY:String(r.getFullYear()),YY:i(r.getFullYear()%100),MM:i(r.getMonth()+1),DD:i(r.getDate()),HH:i(r.getHours()),mm:i(r.getMinutes()),ss:i(r.getSeconds())},o=e=>e.replace(/\{\{\s*([A-Za-z]+)\s*\}\}/g,(e,t)=>a[t]??e),s=e=>e.split(/[\\/]+/).filter(e=>e&&e!==`.`&&e!==`..`).join(`/`),c=[e,s(o(t.trim()))].filter(Boolean).join(`/`),l=s(o(n.trim()));return{root:c,added:l,result:[c,l,`<attachment filename>`].filter(Boolean).join(`/`),date:`${a.YYYY}-${a.MM}-${a.DD}`}}var B=`Applying rules to existing documents…`,Ge=new Map;function V(e){return`${e.ruleIds.length>1?`Rule ${e.ruleIndex+1}/${e.ruleIds.length}: `:``}${e.processed}${e.total===null?``:` / ${e.total}`} documents · ${e.applied} applied`}function Ke(e,t){let n=`${t.checked} checked, ${t.applied} applied${t.skipped?`, ${t.skipped} already there`:``}`;t.status===`cancelled`?e.done({title:`Cancelled`,description:n}):t.status===`failed`?e.fail({title:`Stopped before finishing`,description:`${n}: ${t.error}. The rule stays enabled; rerun it from Rules to finish.`,variant:`destructive`}):t.failed?e.done({title:`Finished with errors`,description:`${n}, ${t.failed} failed. Details in the rule’s run log.`,variant:`destructive`}):e.done({title:`Rule applied`,description:n})}function H(e,t,n){let r=Ge.get(n.id);if(r)return r;let i=new Promise(r=>{let i={channel:`workspace:${t}`},a=e({title:B,description:V(n),action:{label:`Cancel`,onClick:()=>{a.update({title:`Cancelling…`,description:V(n)}),Re(t,n.id).catch(()=>a.update({title:B,description:`Could not cancel. Try again.`}))}}}),o=()=>{u?.(),D.off(`job.progress`,c),D.off(`job.finished`,c),r()},s=e=>{if(e.status===`running`)return a.update({title:B,description:V(e)});Ke(a,e),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`)),o()},c=e=>{let t=e?.job;t?.id===n.id&&s(t)},l=()=>{D.emit(`subscribe`,i),L(t,n.id).then(s,()=>{})},u=D.on(`connect`,l);D.on(`job.progress`,c),D.on(`job.finished`,c),l()});return Ge.set(n.id,i),i.finally(()=>Ge.delete(n.id)),i}async function qe(e,t,n){let r;try{r=await Le(t,{ruleIds:n,limit:Ne()})}catch(t){e({title:B}).fail({title:`Could not start`,description:`${t instanceof Error?t.message:String(t)}. The rule stays enabled; rerun it from Rules.`,variant:`destructive`});return}return H(e,t,r)}async function Je(e,t){let n=await ze(t).catch(()=>[]);for(let r of n)r.status===`running`&&H(e,t,r)}function U(e){return`/workspaces/${e}/scripts`}async function Ye(e){return await E.get(U(e))||[]}async function Xe(e,t){return(await E.get(`${U(e)}/${t}`))?.content??``}async function Ze(e,t,n){await E.put(`${U(e)}/${t}`,{content:n})}async function Qe(e,t){await E.delete(`${U(e)}/${t}`)}var W=t(),$e=[{value:``,label:`any item`},{value:`email`,label:`an email`},{value:`message`,label:`a message`},{value:`tab`,label:`a browser tab / link`},{value:`note`,label:`a note`},{value:`file`,label:`a file`},{value:`todo`,label:`a todo / task`}],et=[{value:`document.inserted`,label:`is added`,hint:`Fires when the item is created or uploaded.`},{value:`document.updated`,label:`is updated`,hint:`Fires on every edit of the item.`},{value:`document.linked`,label:`is filed into a folder`,hint:`Fires when the item is (re)filed into a tree path — the usual pair with "is added" for folder rules.`},{value:`document.unlinked`,label:`is removed from a folder`,hint:`Fires when the item leaves a tree path.`}],tt=[{key:`toExact`,label:`recipient (To/Cc) is`,hint:`accounting@example.com`},{key:`fromExact`,label:`email sender is`,hint:`person@example.com`},{key:`senderExact`,label:`message sender is`,hint:`Sender ID`},{key:`sender`,label:`message sender contains`,hint:`Sender ID or name`},{key:`senderRegex`,label:`message sender matches regex`,hint:`Sender ID or name pattern`},{key:`body`,label:`body / text contains`,hint:`Words in the email preview or message text`},{key:`bodyRegex`,label:`body / text matches regex`,hint:`invoice\\s+\\d+`},{key:`threadExact`,label:`thread is`,hint:`Thread ID`},{key:`channelExact`,label:`channel / conversation is`,hint:`Channel or conversation ID`},{key:`platformExact`,label:`platform is`,hint:`slack, whatsapp, teams`},{key:`pathExact`,label:`is directly in the folder`,hint:`Current folder membership`},{key:`eventPathExact`,label:`is inserted / linked directly into`,hint:`Exact event destination, e.g. ctx:/foo/bar/baz. Descendant inserts do not match.`},{key:`path`,label:`is under the folder`,hint:`/projects/canvas/UI or backends:/workspace/home/foo`},{key:`mime`,label:`file type is`,hint:`image/*, application/pdf`},{key:`from`,label:`sender contains`,hint:`boss@company.tld`},{key:`to`,label:`recipient (To/Cc) contains`,hint:`invoice@my-company.tld`},{key:`subject`,label:`subject contains`,hint:`invoice`},{key:`fromRegex`,label:`sender matches regex`,hint:`@(acme|example)\\.com$`},{key:`toRegex`,label:`recipient (To/Cc) matches regex`,hint:`^(billing|accounts)@`},{key:`subjectRegex`,label:`subject matches regex`,hint:`^invoice\\s+\\d+`},{key:`urlRegex`,label:`URL matches regex`,hint:`/(invoice|receipt)/`},{key:`urlHost`,label:`website is`,hint:`youtube.com`},{key:`urlContains`,label:`URL contains`,hint:`/watch?v=`},{key:`attachment`,label:`has an attachment of type`,hint:`application/pdf, or * for any`}],nt=new Set([`toExact`,`fromExact`,`senderExact`,`threadExact`,`channelExact`,`platformExact`]),rt=e=>nt.has(e)?e.replace(/Exact$/,``):e.replace(/Regex$/,``),it=[{key:`sendFile`,label:`Send file(s) via a channel`,icon:b,tone:`text-blue-600 dark:text-blue-400 bg-blue-500/10`},{key:`extractAttachments`,label:`Extract email attachments to a folder`,icon:b,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`},{key:`moveMessage`,label:`Move the email to a mail folder`,icon:b,tone:`text-teal-600 dark:text-teal-400 bg-teal-500/10`},{key:`store`,label:`Copy/Move file(s) to a storage backend`,icon:S,tone:`text-sky-600 dark:text-sky-400 bg-sky-500/10`},{key:`download`,label:`download what the link points at`,icon:g,tone:`text-rose-600 dark:text-rose-400 bg-rose-500/10`},{key:`link`,label:`file it into a folder`,icon:o,tone:`text-emerald-600 dark:text-emerald-400 bg-emerald-500/10`},{key:`unlink`,label:`remove it from a folder`,icon:o,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`},{key:`tag`,label:`add tags`,icon:d,tone:`text-violet-600 dark:text-violet-400 bg-violet-500/10`},{key:`unstore`,label:`delete the file from a storage backend`,icon:p,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`},{key:`notify`,label:`Send me a notification`,icon:y,tone:`text-pink-600 dark:text-pink-400 bg-pink-500/10`},{key:`agent`,label:`ask an agent`,icon:r,tone:`text-indigo-600 dark:text-indigo-400 bg-indigo-500/10`},{key:`script`,label:`run a script`,icon:m,tone:`text-slate-600 dark:text-slate-300 bg-slate-500/10`},{key:`delete`,label:`delete it from Canvas`,icon:f,tone:`text-destructive bg-destructive/10`},{key:`destroy`,label:`delete it everywhere`,icon:f,tone:`text-destructive bg-destructive/10`}],at=e=>it.find(t=>t.key===e)||it[1],ot=`{{title}}{{ext}}`,G=`{{YYYY}}/{{MM}}/{{YYYY}}{{MM}}{{DD}}_{{HH}}{{mm}}{{ss}}{{ext}}`,st=[{value:`auto`,label:`whatever it is (auto)`,hint:`arXiv → the PDF · YouTube, Vimeo, TikTok… → the video · image / video / PDF links → the file · anything else → the page.`},{value:`image`,label:`the file itself (image, PDF, …)`,hint:`Fetches the bytes the URL serves.`},{value:`video`,label:`the video (yt-dlp)`,hint:`Best video + audio, merged. Needs yt-dlp on the server.`},{value:`arxiv`,label:`the arXiv paper (PDF)`,hint:`Works for abs/ and pdf/ links.`},{value:`page`,label:`the page with its images & styles`,hint:`One page, offline-readable (wget --page-requisites).`},{value:`website`,label:`the whole website (mirror)`,hint:`Follows links on the same site up to the chosen depth.`}],ct=[{value:`keep`,label:`keep the original file name`},{value:`title`,label:`use the item title as file name`},{value:`dated`,label:`photo style: 2024/07/20240714_183012.jpg`},{value:`custom`,label:`custom template…`}],K=e=>({sendDriver:`imap`,sendSource:`document`,sendSubject:`{{file.name}}`,sendMessage:``,kind:e,a:``,b:``,recursive:!1,storeFrom:``,storeFolder:``,storeName:`keep`,storeMode:`copy`,storeConflict:`rename`,attachmentMime:`application/pdf`,attachmentName:``,attachmentPath:`{{YYYY}}/{{MM}}`,includeInline:!1,dlKind:`auto`,dlDepth:`2`,dlTags:``,keepLast:!0,notePath:``,noteTitle:``,filePath:``,fileBackend:`home`,fileInsert:``,notifyReply:!1}),q={id:null,description:``,events:[`document.inserted`],schema:``,cascade:!1,approval:!1,conditions:[],actions:[K(`link`)]},lt=e=>e.split(`|`).map(e=>e.trim()).filter(Boolean);function ut(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`rule-${Math.random().toString(36).slice(2,7)}`}var J=e=>e.split(`,`).map(e=>e.trim()).filter(Boolean),dt=[{id:`send-invoices`,title:`Send invoice PDFs to accounting`,icon:b,tone:`text-blue-600 dark:text-blue-400 bg-blue-500/10`,blurb:`Send matching PDF attachments to your accounting firm’s ingestion email, or to a Slack / WhatsApp conversation. Keep the original email and files.`,build:()=>({...q,description:`Send invoice PDFs to accounting`,schema:`email`,conditions:[{field:`toExact`,value:``}],actions:[{...K(`sendFile`),sendSource:`attachments`,sendSubject:`Invoice: {{file.name}}`}]})},{id:`attachments`,title:`File PDF email attachments by month`,icon:b,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`,blurb:`Choose a recipient and extract PDF attachments into Accounting / year / month, using the email date. Add a subject or filename filter to narrow it to invoices.`,build:()=>({...q,description:`File accounting PDF attachments by month`,schema:`email`,conditions:[{field:`toExact`,value:``}],actions:[{...K(`extractAttachments`),a:`workspace:home`,storeFolder:`Accounting`}]})},{id:`store`,title:`Copy/Move file(s) to a storage backend`,icon:S,tone:`text-sky-600 dark:text-sky-400 bg-sky-500/10`,blurb:`Uploads land in the managed blob store. Pick a folder in Canvas and a folder on a storage backend — copy or move matching files and optionally recreate their sub-folder paths.`,build:({backend:e})=>({...q,description:`Copy/Move file(s) to a storage backend`,schema:`file`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:``}],actions:[{...K(`store`),a:e,recursive:!0}]})},{id:`photos`,title:`Sort photos by date`,icon:_,tone:`text-emerald-600 dark:text-emerald-400 bg-emerald-500/10`,blurb:`Images filed into a folder are stored as Photos / 2024 / 07 / 20240714_183012.jpg — by the time the photo was taken (EXIF), not uploaded.`,build:({backend:e})=>({...q,description:`Sort photos by date`,schema:`file`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:``},{field:`mime`,value:`image/*`}],actions:[{...K(`store`),a:e,storeFolder:`Photos`,storeName:`dated`}]})},{id:`mirror`,title:`Mirror a storage folder`,icon:o,tone:`text-violet-600 dark:text-violet-400 bg-violet-500/10`,blurb:`Everything that appears under a folder of a storage backend shows up 1:1 in the Directory tree.`,build:()=>({...q,description:`Mirror a storage folder`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:`backends:/workspace/home/`}],actions:[{...K(`link`),a:`dir:/`,recursive:!0}]})},{id:`mail`,title:`File mail from a sender`,icon:b,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`,blurb:`Emails from a person or domain are filed into a folder and you get a notification.`,build:()=>({...q,description:`Mail from …`,schema:`email`,conditions:[{field:`from`,value:``}],actions:[{...K(`link`),a:`/work/urgent`},{...K(`notify`),a:`New mail from {{doc.data.from}}: {{doc.data.subject}}`}]})},{id:`download`,title:`Download what links point at`,icon:g,tone:`text-rose-600 dark:text-rose-400 bg-rose-500/10`,blurb:`Bookmarks filed into a folder are fetched for real — images, videos (yt-dlp), arXiv papers, a page or a whole website — saved to a folder and filed next to the link.`,build:({backend:e})=>({...q,description:`Download what links point at`,schema:`tab`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:``}],actions:[{...K(`download`),a:e,storeFolder:`Downloads`,recursive:!0}]})},{id:`agent`,title:`Ask an agent`,icon:r,tone:`text-indigo-600 dark:text-indigo-400 bg-indigo-500/10`,blurb:`Hand new items to an agent with a prompt; save its reply as a note or get it as a notification.`,build:()=>({...q,description:`Summarize new items`,actions:[{...K(`agent`),b:`Read document #{{doc.id}} in full with canvas_get, then summarize it in three bullet points.`,notifyReply:!0}]})},{id:`blank`,title:`Start from scratch`,icon:x,tone:`text-muted-foreground bg-muted`,blurb:`An empty rule: choose what it reacts to, add conditions and actions.`,build:()=>({...q})}];function Y(e){let t=e.filter(e=>[`path`,`pathExact`,`eventPathExact`].includes(e.field));if(t.length!==1||t[0].field!==`eventPathExact`)return null;let n=lt(t[0].value);return n.length===1&&/^(ctx|context):\//.test(n[0])?n[0].replace(/^(ctx|context):/,``).replace(/\/+$/,``)||`/`:null}function ft(e){if(Y(e)!==null)return!0;let t=e.filter(e=>[`path`,`pathExact`,`eventPathExact`].includes(e.field)).flatMap(e=>lt(e.value));return t.length>0&&t.every(e=>/^(dir|directory|backends):\//.test(e))}function pt(e,t,n){let r=e=>e.replace(/\\/g,`/`).split(`/`).filter(e=>e&&e!==`.`&&e!==`..`).join(`/`),i=`${n?.treePath?`backends:${n.treePath}`:e.a}/${r(e.storeFolder.trim())}`.replace(/\/+$/,``),a=Y(t),o=e.recursive?a===null?`<sub-folders>`:r(a):``;return{root:i,recreated:o,result:[i,o,e.storeName===`keep`?`<original filename>`:e.storeName===`title`?`<title>.<ext>`:e.storeName===`dated`?G:e.b||`<filename>`].filter(Boolean).join(`/`)}}function mt(e,t=[]){let n={event:e.events.length===1?e.events[0]:e.events};e.schema&&(n.schema=e.schema);let r={},i={};for(let t of e.conditions){let e=t.field.endsWith(`Regex`),n=nt.has(t.field),a=e||n?t.value.trim()?[t.value]:[]:lt(t.value);if(e&&a.length)try{new RegExp(t.value,`i`)}catch{throw Error(`Invalid regular expression for ${tt.find(e=>e.key===t.field)?.label}: ${t.value}`)}if(!a.length)throw Error(`Enter a value for ${tt.find(e=>e.key===t.field)?.label||t.field}, or remove that condition.`);if(t.field===`urlHost`||t.field===`urlContains`||t.field===`urlRegex`){let e=t.field===`urlHost`?`host`:t.field===`urlRegex`?`regex`:`contains`,n=i[e],r=[...Array.isArray(n)?n:n==null?[]:[n],...a];i[e]=r.length===1?r[0]:r}else(r[rt(t.field)]||=[]).push(...e?a.map(e=>({regex:e})):n?a.map(e=>({equals:e})):a)}for(let[e,t]of Object.entries(r))t?.length&&(n[e]=t.length===1?t[0]:t);Object.keys(i).length&&(n.url=i);let a=e=>{let t={};return e.notePath.trim()&&(t.note={path:e.notePath.trim(),...e.noteTitle.trim()?{title:e.noteTitle.trim()}:{}}),e.filePath.trim()&&(t.file={path:e.filePath.trim(),...e.fileBackend===`data`?{backend:`data`}:{},...e.fileInsert.trim()?{insert:e.fileInsert.trim()}:{}}),e.notifyReply&&(t.notify=!0),Object.keys(t).length?t:null},o=[];for(let n of e.actions){let r=n.a.trim(),i=n.b.trim(),s=n.recursive?{recursive:!0}:{};if(n.kind===`sendFile`){if(!r)throw Error(`Choose a sending account for the file.`);if(!i)throw Error(n.sendDriver===`imap`?`Enter the destination email address.`:`Enter a configured destination conversation.`);if(![`imap`,`slack`,`whatsapp`].includes(n.sendDriver))throw Error(`Choose email, Slack or WhatsApp.`);if(![`document`,`attachments`,`download`].includes(n.sendSource))throw Error(`Choose which files to send.`);if(n.sendSource===`download`&&!o.some(e=>e.action===`download`))throw Error(`Add a Download action before sending its files.`);let e=J(n.attachmentMime);if(n.sendSource===`attachments`&&(!e.length||e.some(e=>!/^(\*|[a-z0-9!#$&^_.+-]+\/(\*|[a-z0-9!#$&^_.+-]+)|\*\/\*)$/i.test(e))))throw Error(`Enter attachment MIME types, such as application/pdf.`);if(n.sendDriver===`whatsapp`&&n.sendMessage.length>1024)throw Error(`WhatsApp file captions must be at most 1,024 characters.`);o.push({action:`sendFile`,source:n.sendSource,driver:n.sendDriver,address:r,...n.sendDriver===`imap`?{to:J(i),subject:n.sendSubject}:{target:i},...n.sendMessage?{message:n.sendMessage}:{},...n.sendSource===`attachments`?{mime:e.length===1?e[0]:e,...n.attachmentName.trim()?{filename:n.attachmentName.trim()}:{},...n.includeInline?{includeInline:!0}:{}}:{}})}if(n.kind===`link`&&r&&o.push({action:`link`,paths:J(r),...s,...i?{tags:J(i)}:{}}),n.kind===`unlink`&&r&&o.push({action:`unlink`,paths:J(r),...s}),n.kind===`tag`&&r&&o.push({action:`tag`,tags:J(r)}),n.kind===`moveMessage`){if(!r)throw Error(`Enter the mail folder to move the email to, such as INBOX/Accounting/{{YYYY}}/Expenses.`);o.push({action:`moveMessage`,folder:r})}if(n.kind===`store`&&r){if(n.storeMode===`move`&&!n.storeFrom.trim())throw Error(`Choose the source backend whose copy should be moved.`);if(n.recursive&&!ft(e.conditions))throw Error(`Choose a Directory/Backends source path, or one exact Context insertion path, to recreate the path.`);if(n.recursive&&t.find(e=>e.address===r)?.capabilities?.paths!==!0)throw Error(`This destination has not reported support for folder paths. Choose a supported backend or turn off path recreation.`);let a=n.storeFolder.trim().replace(/^\/+|\/+$/g,``),c=n.storeName===`title`?ot:n.storeName===`dated`?G:n.storeName===`custom`?i:``;o.push({action:`store`,to:r,...n.storeFrom.trim()?{from:n.storeFrom.trim()}:{},mode:n.storeMode,...a?{folder:a}:{},...s,...n.recursive&&Y(e.conditions)!==null?{pathMode:`full`}:{},...c?{key:c}:{},onConflict:n.storeConflict})}if(n.kind===`extractAttachments`){if(!r)throw Error(`Choose a destination backend for the attachments.`);if(t.find(e=>e.address===r)?.capabilities?.paths!==!0)throw Error(`Choose an attachment destination with support for folder paths.`);let e=J(n.attachmentMime);if(!e.length||e.some(e=>!/^(\*|[a-z0-9!#$&^_.+-]+\/(\*|[a-z0-9!#$&^_.+-]+)|\*\/\*)$/i.test(e)))throw Error(`Enter attachment MIME types, such as application/pdf or image/*. Use * for all attachments.`);if(![`rename`,`error`].includes(n.storeConflict))throw Error(`Choose rename or skip for attachment filename conflicts.`);o.push({action:`extractAttachments`,to:r,mime:e.length===1?e[0]:e,...n.storeFolder.trim()?{folder:n.storeFolder.trim()}:{},...n.attachmentPath.trim()?{subfolder:n.attachmentPath.trim()}:{},...n.attachmentName.trim()?{filename:n.attachmentName.trim()}:{},...n.includeInline?{includeInline:!0}:{},onConflict:n.storeConflict})}if(n.kind===`download`){let e=n.storeFolder.trim().replace(/^\/+|\/+$/g,``),t=Number(n.dlDepth);o.push({action:`download`,to:r||`workspace:home`,...e?{folder:e}:{},...s,...n.dlKind===`auto`?{}:{kind:n.dlKind},...i?{insert:J(i)}:{},...n.dlTags.trim()?{tags:J(n.dlTags)}:{},...n.dlKind===`website`&&Number.isFinite(t)&&t>0&&t!==2?{depth:t}:{}})}if(n.kind===`unstore`&&r&&o.push({action:`unstore`,from:r,...i?{ifOn:i}:{},...n.keepLast?{}:{keepLast:!1}}),n.kind===`notify`&&r&&o.push({action:`notify`,message:r}),n.kind===`delete`&&o.push({action:`delete`}),n.kind===`destroy`&&o.push({action:`destroy`}),n.kind===`agent`&&r&&i){let e=a(n);o.push({action:`agent`,slug:r,prompt:i,...e?{output:e}:{}})}if(n.kind===`script`&&r){let e=a(n);o.push({action:`script`,path:r,...e?{output:e}:{}})}}return{id:e.id||ut(e.description),enabled:!0,...e.description?{description:e.description}:{},...e.cascade?{cascade:!0}:{},...e.approval?{approval:!0}:{},...e.editable?.length?{editable:e.editable}:{},...e.ttl===void 0?{}:{ttl:e.ttl},when:n,then:o}}function ht(e){let{event:t,schema:n,from:r,to:i,subject:a,body:o,sender:s,thread:c,channel:l,platform:u,path:d,pathExact:f,eventPathExact:p,mime:m,url:h,attachment:g,...ee}=e.when;if(Object.keys(ee).length>0)return null;let _=Array.isArray(t)?t:[t];if(!_.length||!_.every(e=>typeof e==`string`&&et.some(t=>t.value===e))||n!==void 0&&typeof n!=`string`)return null;let v=[],y=(e,t)=>{let n=Array.isArray(t)?t:[t];if(e.endsWith(`Regex`)){if(!n.every(e=>typeof e==`string`))return!1;for(let t of n)v.push({field:e,value:t})}else if(nt.has(e))for(let t of n){if(!t||typeof t!=`object`||Object.keys(t).length!==1||typeof t.equals!=`string`)return!1;v.push({field:e,value:t.equals})}else if([`from`,`to`,`subject`,`body`,`sender`].includes(e))for(let t of n)if(typeof t==`string`)v.push({field:e,value:t});else if([`from`,`to`,`sender`].includes(e)&&t&&typeof t==`object`&&Object.keys(t).length===1&&typeof t.equals==`string`)v.push({field:`${e}Exact`,value:t.equals});else if(t&&typeof t==`object`&&Object.keys(t).length===1&&typeof t.regex==`string`)v.push({field:`${e}Regex`,value:t.regex});else return!1;else{if(!n.every(e=>typeof e==`string`))return!1;v.push({field:e,value:n.join(` | `)})}return!0};if(d!==void 0&&!y(`path`,d)||f!==void 0&&!y(`pathExact`,f)||p!==void 0&&!y(`eventPathExact`,p)||m!==void 0&&!y(`mime`,m)||r!==void 0&&!y(`from`,r)||i!==void 0&&!y(`to`,i)||a!==void 0&&!y(`subject`,a)||o!==void 0&&!y(`body`,o)||s!==void 0&&!y(`sender`,s)||c!==void 0&&!y(`threadExact`,c)||l!==void 0&&!y(`channelExact`,l)||u!==void 0&&!y(`platformExact`,u)||g!==void 0&&!y(`attachment`,g))return null;if(h!==void 0){if(typeof h==`string`)v.push({field:`urlContains`,value:h});else if(h&&typeof h==`object`){let e=h;if(Object.keys(e).filter(e=>e!==`host`&&e!==`contains`&&e!==`regex`).length||e.host!==void 0&&!y(`urlHost`,e.host)||e.contains!==void 0&&!y(`urlContains`,e.contains)||e.regex!==void 0&&!y(`urlRegex`,e.regex))return null}else return null}let b=e=>{let t=e.output&&typeof e.output==`object`?e.output:{};if(Object.keys(t).filter(e=>e!==`note`&&e!==`file`&&e!==`notify`).length)return null;let n=t.note&&typeof t.note==`object`?t.note:{},r=t.file&&typeof t.file==`object`?t.file:{};return Object.keys(r).filter(e=>e!==`path`&&e!==`backend`&&e!==`insert`).length?null:{notePath:typeof n.path==`string`?n.path:``,noteTitle:typeof n.title==`string`?n.title:``,filePath:typeof r.path==`string`?r.path:``,fileBackend:r.backend===`data`?`data`:`home`,fileInsert:typeof r.insert==`string`?r.insert:``,notifyReply:t.notify===!0}},x=[];for(let t of e.then||[]){if(t.approval!==void 0)return null;if(t.action===`link`&&Array.isArray(t.paths))x.push({...K(`link`),a:t.paths.join(`, `),b:Array.isArray(t.tags)?t.tags.join(`, `):``,recursive:t.recursive===!0});else if(t.action===`unlink`&&Array.isArray(t.paths))x.push({...K(`unlink`),a:t.paths.join(`, `),recursive:t.recursive===!0});else if(t.action===`tag`&&Array.isArray(t.tags))x.push({...K(`tag`),a:t.tags.join(`, `)});else if(t.action===`moveMessage`){if(Object.keys(t).some(e=>e!==`action`&&e!==`folder`)||typeof t.folder!=`string`)return null;x.push({...K(`moveMessage`),a:t.folder})}else if(t.action===`notify`&&typeof t.message==`string`)x.push({...K(`notify`),a:t.message});else if(t.action===`store`&&typeof t.to==`string`){if(t.pathMode!==void 0&&(t.pathMode!==`full`||t.recursive!==!0||Y(v)===null)||t.recursive===!0&&Y(v)!==null&&t.pathMode!==`full`||t.folder!==void 0&&typeof t.folder!=`string`||t.key!==void 0&&typeof t.key!=`string`)return null;let e=typeof t.key==`string`?t.key:``;x.push({...K(`store`),a:t.to,b:e===ot||e===G?``:e,storeFolder:typeof t.folder==`string`?t.folder:``,recursive:t.recursive===!0,storeName:e?e===ot?`title`:e===G?`dated`:`custom`:`keep`,storeFrom:typeof t.from==`string`?t.from:Array.isArray(t.from)?String(t.from[0]??``):``,storeMode:t.mode===`move`?`move`:`copy`,storeConflict:t.onConflict===`error`||t.onConflict===`overwrite`?t.onConflict:`rename`})}else if(t.action===`sendFile`){let e=new Set([`action`,`source`,`driver`,`address`,`to`,`target`,`subject`,`message`,`mime`,`filename`,`includeInline`]);if(Object.keys(t).some(t=>!e.has(t))||![`imap`,`slack`,`whatsapp`].includes(String(t.driver))||typeof t.address!=`string`||t.source!==void 0&&![`document`,`attachments`,`download`].includes(String(t.source))||[`target`,`subject`,`message`,`filename`].some(e=>t[e]!==void 0&&typeof t[e]!=`string`)||t.includeInline!==void 0&&typeof t.includeInline!=`boolean`)return null;let n=Array.isArray(t.to)?t.to:t.to===void 0?[]:[t.to],r=Array.isArray(t.mime)?t.mime:[t.mime??`*`];if(!n.every(e=>typeof e==`string`)||!r.every(e=>typeof e==`string`)||(t.driver===`imap`?t.target!==void 0:t.to!==void 0||t.subject!==void 0))return null;x.push({...K(`sendFile`),a:t.address,b:t.driver===`imap`?n.join(`, `):String(t.target||``),sendDriver:t.driver,sendSource:t.source||`document`,sendSubject:String(t.subject??`{{file.name}}`),sendMessage:String(t.message||``),attachmentMime:r.join(`, `),attachmentName:String(t.filename||``),includeInline:t.includeInline===!0})}else if(t.action===`extractAttachments`){let e=new Set([`action`,`to`,`folder`,`subfolder`,`mime`,`filename`,`includeInline`,`onConflict`]);if(Object.keys(t).some(t=>!e.has(t))||typeof t.to!=`string`||[`folder`,`subfolder`,`filename`].some(e=>t[e]!==void 0&&typeof t[e]!=`string`)||t.includeInline!==void 0&&typeof t.includeInline!=`boolean`||t.onConflict!==void 0&&t.onConflict!==`rename`&&t.onConflict!==`error`)return null;let n=Array.isArray(t.mime)?t.mime:[t.mime??`*`];if(!n.every(e=>typeof e==`string`))return null;x.push({...K(`extractAttachments`),a:t.to,storeFolder:typeof t.folder==`string`?t.folder:``,attachmentPath:typeof t.subfolder==`string`?t.subfolder:``,attachmentMime:n.join(`, `),attachmentName:typeof t.filename==`string`?t.filename:``,includeInline:t.includeInline===!0,storeConflict:t.onConflict===`error`?`error`:`rename`})}else if(t.action===`download`){let e=new Set([`action`,`to`,`folder`,`recursive`,`kind`,`insert`,`tags`,`depth`]);if(Object.keys(t).some(t=>!e.has(t)))return null;let n=typeof t.kind==`string`?t.kind:`auto`;if(!st.some(e=>e.value===n))return null;let r=Array.isArray(t.insert)?t.insert:typeof t.insert==`string`?[t.insert]:[];if(!r.every(e=>typeof e==`string`))return null;x.push({...K(`download`),a:typeof t.to==`string`?t.to:`workspace:home`,b:r.join(`, `),storeFolder:typeof t.folder==`string`?t.folder:``,recursive:t.recursive===!0,dlKind:n,dlDepth:typeof t.depth==`number`?String(t.depth):`2`,dlTags:Array.isArray(t.tags)?t.tags.join(`, `):``})}else if(t.action===`unstore`&&(typeof t.from==`string`||Array.isArray(t.from))){let e=e=>Array.isArray(e)?String(e[0]??``):typeof e==`string`?e:``;x.push({...K(`unstore`),a:e(t.from),b:e(t.ifOn),keepLast:t.keepLast!==!1})}else if(t.action===`delete`)x.push(K(`delete`));else if(t.action===`destroy`)x.push(K(`destroy`));else if(t.action===`agent`&&typeof t.slug==`string`&&typeof t.prompt==`string`){let e=b(t);if(!e)return null;x.push({...K(`agent`),a:t.slug,b:t.prompt,...e})}else if(t.action===`script`&&typeof t.path==`string`){let e=b(t);if(!e)return null;x.push({...K(`script`),a:t.path,...e})}else return null}return{id:e.id,description:e.description||``,events:_,schema:typeof n==`string`?n:``,cascade:e.cascade===!0,approval:e.approval===!0,...e.editable?.length?{editable:e.editable}:{},...e.ttl===void 0?{}:{ttl:e.ttl},conditions:v,actions:x.length?x:[K(`link`)]}}var gt=(e,t)=>t.find(t=>t.value===e)?.label?.replace(/\s\(\d+\)$/,``)||(e?String(e).replace(/^data\/schema\//,``):`any item`);function _t(e,t=$e){let n=e.when,r=ye(e).map(e=>et.find(t=>t.value===e)?.label||e).join(` or `),i=[`When ${gt(n.schema,t)} ${r}`],a=e=>Array.isArray(e)?e.join(` or `):typeof e==`object`&&e?JSON.stringify(e):String(e),o={path:`under`,pathExact:`directly in`,eventPathExact:`inserted / linked directly into`,mime:`type`,from:`from`,to:`to`,subject:`subject`,body:`body / text`,sender:`sender`,thread:`thread`,channel:`conversation`,platform:`platform`,url:`url`,attachment:`attachment`};for(let e of Object.keys(o))n[e]!==void 0&&i.push(`${o[e]} ${a(n[e])}`);return i.join(` · `)}function vt(e){let t=e.output||{},n=t.note||{},r=t.file||{};return[n.path?`reply → note ${n.path}`:``,r.path?`reply → file ${r.backend===`data`?`data:`:`home/`}${r.path}${r.insert?` (indexed at ${r.insert})`:``}`:``,t.notify?`reply → notify`:``].filter(Boolean).join(`, `)}function yt(e){if(e.action===`link`)return`file into ${e.paths?.join(`, `)}${e.recursive===!0?` (sub-folders kept)`:``}`;if(e.action===`unlink`)return`remove from ${e.paths?.join(`, `)}${e.recursive===!0?` (sub-folders kept)`:``}`;if(e.action===`tag`)return`tag ${e.tags?.join(`, `)}`;if(e.action===`store`){let t=typeof e.folder==`string`&&e.folder?`/${e.folder}`:``,n=e.key===ot?`, named by title`:e.key===G?`, by date`:typeof e.key==`string`&&e.key?`, as ${e.key}`:``;return`${e.mode===`move`?`move`:`copy`} the file to ${e.to}${t}${e.recursive===!0?e.pathMode===`full`?` (full directory path recreated)`:` (sub-folder path recreated)`:``}${n}`}if(e.action===`extractAttachments`){let t=[e.to,e.folder,e.subfolder].filter(Boolean).join(`/`);return`extract ${Array.isArray(e.mime)?e.mime.join(`, `):e.mime||`all`} attachments to ${t}${e.filename?` (filename contains ${e.filename})`:``}`}if(e.action===`moveMessage`)return`move the email to mail folder ${e.folder}`;if(e.action===`download`){let t=st.find(t=>t.value===(e.kind||`auto`)),n=typeof e.folder==`string`&&e.folder?`/${e.folder}`:``,r=Array.isArray(e.insert)&&e.insert.length?`, filed at ${e.insert.join(`, `)}`:`, filed next to the link`;return`download ${t?.value===`auto`?`the link (auto-detected)`:t?.label||e.kind} to ${e.to||`workspace:home`}${n}${e.recursive===!0?` (sub-folders kept)`:``}${r}`}if(e.action===`unstore`)return`delete the file from ${Array.isArray(e.from)?e.from.join(`, `):e.from}${e.ifOn?` once it is on ${Array.isArray(e.ifOn)?e.ifOn.join(`, `):e.ifOn}`:``}`;if(e.action===`sendFile`)return`send ${e.source===`attachments`?`matching attachments`:e.source===`download`?`downloaded files`:`the file`} via ${e.driver===`imap`?`email`:e.driver} to ${Array.isArray(e.to)?e.to.join(`, `):e.to||e.target||`…`}`;if(e.action===`notify`)return`send me a notification`;if(e.action===`delete`)return`delete from Canvas (keeps stored files/mail)`;if(e.action===`destroy`)return`⚠ delete everywhere (index + storage)`;if(e.action===`agent`){let t=vt(e);return`ask agent "${e.slug}"${t?` (${t})`:``}`}if(e.action===`script`){let t=vt(e);return`run ${e.path}${t?` (${t})`:``}`}return e.action}function bt(e){return(e.then||[]).map(yt).join(` · `)||`(no actions)`}function xt(e){return be(e).length>0&&(e.then||[]).length>0&&(e.then||[]).every(e=>e.action===`link`||e.action===`unlink`||e.action===`store`||e.action===`unstore`)}function St(e){let t={};for(let n of e){if(n.handlerType!==`rule`)continue;let e=t[n.handler]||={count:0,errors:0,last:n};e.count++,n.status===`error`&&e.errors++,n.ts>e.last.ts&&(e.last=n)}return t}function Ct(e){let t=Date.now()-new Date(e).getTime();if(!Number.isFinite(t)||t<0)return``;let 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<48?`${r}h ago`:`${Math.floor(r/24)}d ago`}function wt(e){return e.some(e=>e.address===`workspace:home`)?`workspace:home`:e.find(e=>e.address!==`workspace:data`)?.address||e[0]?.address||``}function Tt(e){if(e.kind===`document`&&e.rule)return{...ht(e.rule)||q,id:null};if(e.kind===`download`){let t=e.path?` filed under ${e.path.replace(/^(ctx|dir):/,``)}`:``;return{...q,description:`Download links${t}`,schema:`tab`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:e.path||``}],actions:[{...K(`download`),a:e.storeTo||``,storeFolder:e.storeFolder||`Downloads`,recursive:!0}]}}if(e.kind===`store`){let t=e.path||``,n=/^(?:(?:ctx|context):)?\//.test(t),r=[{field:n?`eventPathExact`:`path`,value:n&&t.startsWith(`/`)?`ctx:${t}`:t}],i=e.path?`${n?` inserted / linked directly into`:` filed under`} ${e.path.replace(/^(ctx|context|dir|directory):/,``)}`:``;return{...q,description:e.storeTo?`Copy files${i} to ${e.storeTo}${e.storeFolder?`/${e.storeFolder}`:``}`:`Copy files${i} to a storage backend`,schema:`file`,events:[`document.inserted`,`document.linked`],conditions:r,actions:[{...K(`store`),a:e.storeTo||``,storeFolder:e.storeFolder||``,recursive:ft(r)}]}}return{...q,description:`Mirror ${e.path} into ${e.target}`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:e.path||``}],actions:[{...K(`link`),a:e.target||`dir:/`,recursive:!0}]}}var X=`h-10 w-full rounded-md border bg-background px-3 text-sm outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`,Z=`h-10 text-sm`;function Q({label:e,hint:t,children:n,className:r}){return(0,W.jsxs)(`label`,{className:C(`flex min-w-0 flex-col gap-1.5`,r),children:[(0,W.jsx)(`span`,{className:`text-sm font-medium`,children:e}),n,t&&(0,W.jsx)(`span`,{className:`text-xs leading-relaxed text-muted-foreground`,children:t})]})}function $({checked:e,onChange:t,label:n,hint:r,disabled:i}){return(0,W.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e,disabled:i,onClick:()=>t(!e),className:C(`flex w-full items-start gap-3 rounded-lg border p-3 text-left transition-colors hover:bg-accent/40 disabled:cursor-not-allowed disabled:opacity-50`,e&&`border-primary/40 bg-primary/5`),children:[(0,W.jsx)(`span`,{className:C(`mt-0.5 inline-flex h-5 w-9 shrink-0 items-center rounded-full p-0.5 transition-colors`,e?`bg-primary`:`bg-muted-foreground/30`),children:(0,W.jsx)(`span`,{className:C(`h-4 w-4 rounded-full bg-background shadow transition-transform`,e&&`translate-x-4`)})}),(0,W.jsxs)(`span`,{className:`min-w-0`,children:[(0,W.jsx)(`span`,{className:`block text-sm font-medium`,children:n}),r&&(0,W.jsx)(`span`,{className:`block text-xs leading-relaxed text-muted-foreground`,children:r})]})]})}function Et({value:e,options:t,onChange:n}){return(0,W.jsx)(`div`,{className:`inline-flex h-10 rounded-md border bg-background p-1`,children:t.map(t=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>n(t.value),className:C(`rounded px-3 text-sm transition-colors`,e===t.value?`bg-primary text-primary-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:t.label},t.value))})}function Dt({active:e,onClick:t,children:n,title:r}){return(0,W.jsx)(`button`,{type:`button`,title:r,onClick:t,"aria-pressed":e,className:C(`h-9 rounded-full border px-3.5 text-sm transition-colors`,e?`border-primary bg-primary/10 font-medium text-foreground`:`text-muted-foreground hover:bg-accent hover:text-foreground`),children:n})}function Ot({step:e,title:t,hint:n}){return(0,W.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,W.jsx)(`span`,{className:`mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-primary/10 text-sm font-semibold text-primary`,children:e}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`text-base font-semibold leading-7`,children:t}),n&&(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n})]})]})}function kt({icon:e,tone:t,size:n=`md`}){return(0,W.jsx)(`span`,{className:C(`inline-flex shrink-0 items-center justify-center rounded-xl`,n===`lg`?`h-12 w-12`:`h-10 w-10`,t),children:(0,W.jsx)(e,{className:n===`lg`?`h-6 w-6`:`h-5 w-5`})})}function At({workspaceId:e,onOpenJson:t,onShowRuns:n,backfillLimit:r,prefill:d,onPrefillConsumed:p,createOnly:m=!1,onCreated:g,onCancel:_}){let{showToast:y,showProgress:b}=re(),[S,ne]=(0,k.useState)([]),[E,D]=(0,k.useState)({}),ae=e=>{Ae(e,{limit:500}).then(e=>D(St(e))).catch(()=>D({}))},[se,ce]=(0,k.useState)(!0),[O,A]=(0,k.useState)(null),[fe,j]=(0,k.useState)(!1),[M,N]=(0,k.useState)(!1),[pe,P]=(0,k.useState)([]),[F,me]=(0,k.useState)([]),[he,ge]=(0,k.useState)([]),[_e,ve]=(0,k.useState)(``),ye=(0,k.useRef)(null),[Se,Ce]=(0,k.useState)(e);e!==Se&&(Ce(e),ce(!0)),(0,k.useEffect)(()=>{Te(e).then(e=>ne(e)).finally(()=>ce(!1)),ae(e)},[e]);let[we,De]=(0,k.useState)(null);d!==we&&(De(d),d&&(A(Tt(d)),j(!1))),(0,k.useEffect)(()=>{d&&p?.()},[d,p]),(0,k.useEffect)(()=>{Ye(e).then(e=>P(e.map(e=>e.path))).catch(()=>P([]))},[e]),(0,k.useEffect)(()=>{let t=!1;return le(e).then(e=>{t||(ge([...new Map(e.map(e=>[`${e.driver}:${e.address}`,e])).values()]),ve(``))}).catch(()=>{t||(ge([]),ve(`Sending accounts could not be loaded.`))}),()=>{t=!0}},[e]),(0,k.useEffect)(()=>{oe(e).then(e=>{let t=e.filter(e=>e.kind===`storage`&&e.enabled!==!1&&e.config?.supported!==!1&&e.config?.readOnly!==!0&&e.capabilities?.write!==!1);me(t);let n=wt(t);n&&A(e=>e&&e.actions.some(e=>(e.kind===`store`||e.kind===`download`)&&!e.a)?{...e,actions:e.actions.map(e=>(e.kind===`store`||e.kind===`download`)&&!e.a?{...e,a:n}:e)}:e)}).catch(()=>me([]))},[e]);let[Oe,ke]=(0,k.useState)($e);(0,k.useEffect)(()=>{Be(e).then(e=>{e.schemas?.length&&ke([{value:``,label:`any item`},...e.schemas.map(e=>({value:e.id,label:`${e.name} (${e.count})`}))])}).catch(()=>{})},[e]);let I=async(t,n)=>{N(!0);try{return await Ee(e,t),ne(t),y({title:n,description:`rules.json updated (committed to workspace git)`}),!0}catch(e){return y({title:`Error`,description:e instanceof Error?e.message:`Failed to save rules`,variant:`destructive`}),!1}finally{N(!1)}},je=async()=>{if(!O||se||M)return;let t;try{t=mt(O,F)}catch(e){y({title:`Invalid rule`,description:e instanceof Error?e.message:`Check the rule conditions and actions`,variant:`destructive`});return}if(!t.then.length){y({title:`Add an action`,description:`Pick at least one "then" action and fill in its fields.`,variant:`destructive`});return}if(m){t.id=`${t.id}-${Math.random().toString(36).slice(2,10)}`,N(!0);try{await He(e,t),y({title:`Rule created`,description:`The rule will run for matching new items.`}),g?.()}catch(e){y({title:`Could not create rule`,description:e instanceof Error?e.message:`Failed to save rule`,variant:`destructive`})}finally{N(!1)}return}!O.id&&S.some(e=>e.id===t.id)&&(t.id=`${t.id}-${Math.random().toString(36).slice(2,10)}`);let n=O.id?S.map(e=>e.id===O.id?{...t,enabled:e.enabled!==!1}:e):[...S,t];await I(n,O.id?`Rule updated`:`Rule created`)&&(A(null),g?.())},Me=e=>I(S.map(t=>t.id===e?{...t,enabled:t.enabled===!1}:t),`Rule toggled`),Ne=e=>{confirm(`Delete rule "${e}"?`)&&I(S.filter(t=>t.id!==e),`Rule deleted`)},[Pe,Fe]=(0,k.useState)(null),Le=async t=>{Fe(t);try{let n=await Ie(e,{ruleId:t,dryRun:!0,limit:r}),i=n.results.filter(e=>e.matched).length;if(!i){y({title:`Apply to existing items`,description:`No matches among ${n.processed} existing documents (conditions evaluate against each document's current tree placements). Raise the batch size in the toolbar to cover more.`});return}if(!confirm(`Rule "${t}" matches ${i} of the first ${n.processed} of ${n.total??n.processed} existing documents. Run its actions on all of them now?`))return;await qe(b,e,[t])}catch(e){y({title:`Backfill failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{Fe(null),ae(e)}},L=(e,t)=>A(n=>n&&{...n,[e]:t}),Re=e=>{A(e.build({backend:wt(F)})),j(!1),requestAnimationFrame(()=>ye.current?.scrollIntoView({behavior:`smooth`,block:`start`}))},ze=e=>{let n=ht(e);n?(A(n),j(!1),requestAnimationFrame(()=>ye.current?.scrollIntoView({behavior:`smooth`,block:`start`}))):t?.()},[R,z]=(0,k.useState)(null),Ve=(e,t)=>t.treeType===`context`?e:t.treeName===`directory`?`dir:${e}`:`${t.treeName}:${e}`,Ue=(e,t)=>{if(!R||!O||!e.length){z(null);return}if(R.target===`storeFolder`){let t=xe(e[0]);L(`actions`,O.actions.map((e,n)=>n===R.index?{...e,storeFolder:t?.rel||``,...t?.backend&&F.some(e=>e.address===t.backend)?{a:t.backend}:{}}:e))}else if(R.target===`condition`){let n=e.map(e=>Ve(e,t)),r=t.treeType===`context`&&O.actions.some(e=>e.kind===`store`);L(`conditions`,O.conditions.map((e,t)=>t===R.index?{...e,...r?{field:`eventPathExact`}:{},value:n.join(` | `)}:e))}else{let n=e.map(e=>Ve(e,t));L(`actions`,O.actions.map((e,t)=>t===R.index?e.kind===`download`?{...e,b:n.join(`, `)}:{...e,a:n.join(`, `)}:e))}z(null)},B=(e,t,n=`Browse…`)=>(0,W.jsxs)(w,{type:`button`,size:`sm`,variant:`outline`,className:`h-10 shrink-0 px-3`,title:n,onClick:()=>z({target:e,index:t}),children:[(0,W.jsx)(s,{className:`h-4 w-4 sm:mr-1.5`}),(0,W.jsx)(`span`,{className:`hidden sm:inline`,children:`Browse`})]}),Ge=ft(O?.conditions||[]),V=!!O?.conditions.some(e=>[`path`,`pathExact`,`eventPathExact`].includes(e.field)&&e.value.trim()),Ke=e=>`${e.address}${e.address===`workspace:data`?` — managed blob store (default)`:e.address===`workspace:home`?` — workspace home folder`:e.driver?` — ${e.driver}`:``}`,H=(e,t,n,r=`workspace:home`)=>F.length?(0,W.jsxs)(`select`,{className:X,value:e,onChange:e=>t(e.target.value),children:[(0,W.jsx)(`option`,{value:``,children:n}),F.map(e=>(0,W.jsx)(`option`,{value:e.address,children:Ke(e)},e.address)),e&&!F.some(t=>t.address===e)&&(0,W.jsx)(`option`,{value:e,children:e})]}):(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:r,value:e,onChange:e=>t(e.target.value)}),Je=S.filter(xt),U=S.filter(e=>!xt(e)),Xe=({rule:e})=>{let t=e.enabled!==!1,r=ht(e)!==null,i=E[e.id],a=at(e.then?.[0]?.action||`link`),o=be(e);return(0,W.jsxs)(`div`,{className:C(`rule-card rounded-xl border bg-card p-4 transition-opacity`,!t&&`opacity-60`),children:[(0,W.jsx)(kt,{icon:a.icon,tone:a.tone}),(0,W.jsxs)(`div`,{className:`rule-card-content min-w-0 space-y-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,W.jsx)(`h3`,{className:`text-base font-semibold leading-6`,children:e.description||e.id}),e.approval===!0&&(0,W.jsx)(`span`,{className:`rounded-full bg-warning/15 px-2 py-0.5 text-xs font-medium text-warning`,children:`needs approval`}),e.cascade===!0&&(0,W.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:`incl. automation-created`}),!r&&(0,W.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground`,title:`This rule uses matchers the builder cannot show; edit it as JSON.`,children:`JSON only`})]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:_t(e,Oe)}),(0,W.jsxs)(`p`,{className:`flex items-start gap-1.5 text-sm`,children:[(0,W.jsx)(v,{className:`mt-1 h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,W.jsx)(`span`,{children:bt(e)})]}),o.length>0&&(0,W.jsx)(`p`,{className:`truncate font-mono text-xs text-muted-foreground`,title:o.join(` | `),children:o.join(` | `)}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i?(0,W.jsxs)(`button`,{type:`button`,className:C(`text-left underline-offset-2 hover:underline`,i.last.status===`error`&&`text-destructive`,!n&&`cursor-default hover:no-underline`),title:n?`Show this rule's run log`:i.last.error||i.last.skipReason||``,onClick:()=>n?.(e.id),children:[`ran `,i.count,`×`,i.errors?` (${i.errors} failed)`:``,` · last `,i.last.status,` `,Ct(i.last.ts)]}):`not run yet`})]}),(0,W.jsxs)(`div`,{className:`rule-card-actions`,children:[(0,W.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,disabled:M,title:t?`Enabled — click to pause`:`Paused — click to enable`,onClick:()=>Me(e.id),className:C(`mr-1 inline-flex h-6 w-11 items-center rounded-full p-0.5 transition-colors`,t?`bg-primary`:`bg-muted-foreground/30`),children:(0,W.jsx)(`span`,{className:C(`h-5 w-5 rounded-full bg-background shadow transition-transform`,t&&`translate-x-5`)})}),(0,W.jsxs)(w,{size:`sm`,variant:`ghost`,className:`h-9 px-2.5`,title:e.when.eventPathExact===void 0?`Apply this rule to existing items (dry-run first)`:`Requires an original insert/link event. Current folder membership cannot reconstruct its destination.`,disabled:Pe!==null||e.when.eventPathExact!==void 0,onClick:()=>Le(e.id),children:[Pe===e.id?(0,W.jsx)(ee,{className:`h-4 w-4 animate-spin`}):(0,W.jsx)(l,{className:`h-4 w-4`}),(0,W.jsx)(`span`,{className:`rule-card-action-label ml-1.5`,children:`Apply`})]}),(0,W.jsxs)(w,{size:`sm`,variant:`ghost`,className:`h-9 px-2.5`,title:r?`Edit rule`:`Edit as JSON`,onClick:()=>ze(e),children:[r?(0,W.jsx)(te,{className:`h-4 w-4`}):(0,W.jsx)(h,{className:`h-4 w-4`}),(0,W.jsx)(`span`,{className:`rule-card-action-label ml-1.5`,children:`Edit`})]}),(0,W.jsx)(w,{size:`sm`,variant:`ghost`,className:`h-9 px-2.5 text-destructive hover:text-destructive`,title:`Delete rule`,onClick:()=>Ne(e.id),children:(0,W.jsx)(f,{className:`h-4 w-4`})})]})]})},Ze=(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`h3`,{className:`text-base font-semibold`,children:`What should happen automatically?`}),fe&&(0,W.jsxs)(w,{size:`sm`,variant:`ghost`,onClick:()=>j(!1),children:[(0,W.jsx)(c,{className:`mr-1 h-4 w-4`}),` Close`]})]}),(0,W.jsx)(`div`,{className:`grid min-w-0 grid-cols-[repeat(auto-fill,minmax(min(100%,17rem),1fr))] gap-3`,children:dt.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>Re(e),className:`flex min-w-0 items-start gap-3 rounded-xl border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-accent/40`,children:[(0,W.jsx)(kt,{icon:e.icon,tone:e.tone,size:`lg`}),(0,W.jsxs)(`span`,{className:`min-w-0`,children:[(0,W.jsx)(`span`,{className:`block text-base font-semibold leading-6`,children:e.title}),(0,W.jsx)(`span`,{className:`mt-1 block break-words text-sm leading-relaxed text-muted-foreground`,children:e.blurb})]})]},e.id))})]});return(0,W.jsxs)(`div`,{className:`rule-builder min-w-0 space-y-5`,children:[!m&&(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0 flex-[1_1_20rem]`,children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Rules`}),(0,W.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Rules run automatically as items arrive or get filed — no code needed. Stored in`,` `,(0,W.jsx)(`span`,{className:`font-mono`,children:`rules.json`}),` in the workspace git.`]})]}),(0,W.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[t&&(0,W.jsxs)(w,{variant:`ghost`,onClick:t,title:`Edit rules.json directly`,children:[(0,W.jsx)(h,{className:`mr-1.5 h-4 w-4`}),` JSON`]}),(0,W.jsxs)(w,{onClick:()=>{A(null),j(!0)},disabled:fe,children:[(0,W.jsx)(u,{className:`mr-1.5 h-4 w-4`}),` New rule`]})]})]}),fe&&!O&&Ze,O&&(0,W.jsxs)(`div`,{ref:ye,className:`scroll-mt-4 space-y-6 rounded-xl border bg-card p-4 sm:p-6`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,W.jsx)(`h3`,{className:`text-lg font-semibold`,children:O.id?`Edit rule`:`New rule`}),(0,W.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>A(null),children:[(0,W.jsx)(c,{className:`mr-1 h-4 w-4`}),` Cancel`]})]}),(0,W.jsx)(Q,{label:`Name`,hint:`Shown in the list and the run log.`,children:(0,W.jsx)(T,{className:`h-11 text-base`,placeholder:`Keep UI designs in Projects/Canvas/UI`,value:O.description,onChange:e=>L(`description`,e.target.value)})}),(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsx)(Ot,{step:1,title:`When…`,hint:`What the rule reacts to. All conditions must match; repeat a condition for either/or.`}),(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-[minmax(0,220px)_1fr]`,children:[(0,W.jsx)(Q,{label:`Item`,children:(0,W.jsxs)(`select`,{className:X,value:O.schema,onChange:e=>L(`schema`,e.target.value),children:[Oe.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value)),O.schema&&!Oe.some(e=>e.value===O.schema)&&(0,W.jsx)(`option`,{value:O.schema,children:O.schema.replace(/^data\/schema\//,``)})]})}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsxs)(`span`,{className:`text-sm font-medium`,children:[`Event `,(0,W.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(any of)`})]}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:et.map(e=>{let t=O.events.includes(e.value);return(0,W.jsx)(Dt,{active:t,title:e.hint,onClick:()=>{let n=t?O.events.filter(t=>t!==e.value):[...O.events,e.value];n.length&&L(`events`,n)},children:e.label},e.value)})})]})]}),O.conditions.length>0&&(0,W.jsx)(`div`,{className:`space-y-2`,children:O.conditions.map((e,t)=>{let n=tt.find(t=>t.key===e.field);return(0,W.jsxs)(`div`,{className:`grid grid-cols-[2.25rem_1fr_auto] items-center gap-2 sm:grid-cols-[2.25rem_minmax(0,240px)_1fr_auto]`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,title:`Same condition again = either may match (OR); different conditions must all match (AND)`,children:O.conditions.slice(0,t).some(t=>rt(t.field)===rt(e.field))?`or`:`and`}),(0,W.jsx)(`select`,{className:X,value:e.field,onChange:e=>L(`conditions`,O.conditions.map((n,r)=>r===t?{...n,field:e.target.value}:n)),children:tt.map(e=>(0,W.jsx)(`option`,{value:e.key,children:e.label},e.key))}),(0,W.jsxs)(`div`,{className:`order-4 col-span-3 flex gap-2 sm:order-3 sm:col-span-1`,children:[(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:n?.hint,value:e.value,onChange:e=>L(`conditions`,O.conditions.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),[`path`,`pathExact`,`eventPathExact`].includes(e.field)&&B(`condition`,t,`Browse the workspace trees`)]}),(0,W.jsx)(w,{size:`sm`,variant:`ghost`,className:`order-3 h-10 w-10 p-0 text-muted-foreground sm:order-4`,title:`Remove condition`,onClick:()=>L(`conditions`,O.conditions.filter((e,n)=>n!==t)),children:(0,W.jsx)(c,{className:`h-4 w-4`})})]},t)})}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,W.jsxs)(w,{size:`sm`,variant:`outline`,onClick:()=>L(`conditions`,[...O.conditions,{field:O.schema===`email`?`from`:`path`,value:``}]),children:[(0,W.jsx)(u,{className:`mr-1 h-4 w-4`}),` Add condition`]}),(0,W.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Contains matches literal text. Regex is case-insensitive: enter the pattern without /…/ delimiters; | stays part of the expression. For other filters, separate alternatives with `,(0,W.jsx)(`span`,{className:`font-mono`,children:`|`}),`, e.g. `,(0,W.jsx)(`span`,{className:`font-mono`,children:`image/* | video/*`}),`.`]})]})]}),(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsx)(Ot,{step:2,title:`Then…`,hint:`Actions run in order. The item keeps its id, tags and folders unless an action says otherwise.`}),O.actions.map((t,n)=>{let r=e=>L(`actions`,O.actions.map((t,r)=>r===n?{...t,...e}:t)),i=F.find(e=>e.address===t.a),o=i?.capabilities?.paths===!0,s=Ge&&o,l=at(t.kind),u=n=>(0,W.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-dashed p-3`,children:[(0,W.jsxs)(`p`,{className:`text-sm font-medium`,children:[`What to do with the `,n]}),(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:`Save as a note at`,hint:`Context path by default, dir:/path for the directory tree.`,children:(0,W.jsx)(de,{inputClassName:Z,placeholder:`/notes/summaries (optional)`,value:t.notePath,onChange:e=>r({notePath:e}),fixedWorkspaceName:e,pickerTitle:`Save note under…`,onPickTarget:(e,t)=>r({notePath:t.treeType===`directory`?`dir:${e}`:e})})}),t.notePath.trim()&&(0,W.jsx)(Q,{label:`Note title`,children:(0,W.jsx)(T,{className:Z,placeholder:`Summary: {{doc.data.subject}}`,value:t.noteTitle,onChange:e=>r({noteTitle:e.target.value})})}),(0,W.jsx)(Q,{label:`Save as a file at`,hint:`Relative path under the workspace home folder or in the data blob store.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`logs/agent.log (optional)`,value:t.filePath,onChange:e=>r({filePath:e.target.value})})}),t.filePath.trim()&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(Q,{label:`File lives in`,children:(0,W.jsxs)(`select`,{className:X,value:t.fileBackend,onChange:e=>r({fileBackend:e.target.value}),children:[(0,W.jsx)(`option`,{value:`home`,children:`the workspace home folder`}),(0,W.jsx)(`option`,{value:`data`,children:`the data blob store`})]})}),(0,W.jsx)(Q,{label:`Also file the saved file under`,hint:`Index it as a document at this tree path.`,children:(0,W.jsx)(de,{inputClassName:Z,placeholder:`/path (optional)`,value:t.fileInsert,onChange:e=>r({fileInsert:e}),fixedWorkspaceName:e,tabs:[`context`],pickerTitle:`File under…`,onPickTarget:e=>r({fileInsert:e})})})]})]}),(0,W.jsx)($,{checked:t.notifyReply,onChange:e=>r({notifyReply:e}),label:`Send me a notification with the result`})]}),d=Y(O.conditions),f=t.kind===`store`&&t.a&&(!t.recursive||s)?pt(t,O.conditions,i):null,p=t.kind===`extractAttachments`&&t.a?We(t.a,t.storeFolder,t.attachmentPath):null;return(0,W.jsxs)(`div`,{className:`space-y-4 rounded-xl border bg-background p-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(kt,{icon:l.icon,tone:l.tone}),(0,W.jsx)(`select`,{className:C(X,`flex-1 font-medium`),value:t.kind,onChange:e=>r(K(e.target.value)),children:it.map(e=>(0,W.jsx)(`option`,{value:e.key,children:e.label},e.key))}),(0,W.jsx)(w,{size:`sm`,variant:`ghost`,className:`h-10 w-10 shrink-0 p-0 text-muted-foreground`,title:`Remove action`,disabled:O.actions.length===1,onClick:()=>L(`actions`,O.actions.filter((e,t)=>t!==n)),children:(0,W.jsx)(c,{className:`h-4 w-4`})})]}),(t.kind===`link`||t.kind===`unlink`)&&(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsx)(Q,{label:t.kind===`link`?`Folder(s)`:`Remove from folder(s)`,hint:`Context-tree path by default; dir:/path for the directory tree. Comma-separate several.`,children:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:t.kind===`link`?`/work/urgent or dir:/projects/x`:`/inbox or dir:/staging`,value:t.a,onChange:e=>r({a:e.target.value})}),B(`action`,n)]})}),t.kind===`link`&&(0,W.jsx)(Q,{label:`Tags`,hint:`Optional, comma-separated.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`custom/design, ui`,value:t.b,onChange:e=>r({b:e.target.value})})}),(0,W.jsx)($,{checked:t.recursive,onChange:e=>r({recursive:e}),label:`Recreate sub-folder path in destination`,hint:V?`The part of the item's path below the "is under the folder" prefix is appended to the target: …/foo/a/b → target/a/b.`:`Needs an "is under the folder" condition to know where sub-folders start.`,disabled:!V})]}),t.kind===`moveMessage`&&(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(Q,{label:`Mail folder`,hint:`The folder on the email's own IMAP account, with / between levels (works for servers that use . too). {{YYYY}}, {{MM}}, {{DD}} = the email's date.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`INBOX/Accounting/{{YYYY}}/Expenses`,value:t.a,onChange:e=>r({a:e.target.value})})}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Moves the message on the mail server, like dragging it in a mail client. Put this after Extract attachments so the files are copied first. The folder must already exist on the server; subscribe to it in the mailbox settings to see the moved mail in Canvas.`})]}),t.kind===`tag`&&(0,W.jsx)(Q,{label:`Tags`,hint:`Comma-separated.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`urgent, follow-up`,value:t.a,onChange:e=>r({a:e.target.value})})}),t.kind===`store`&&(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:`Storage backend`,hint:`Where the file's bytes should live. Only writable backends are listed.`,children:H(t.a,e=>r({a:e}),`pick a backend…`)}),(0,W.jsx)(Q,{label:`Destination root folder`,hint:`Choose the folder beneath which the path will be recreated. Leave empty to use the backend root.`,children:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`Projects/Canvas/UI`,value:t.storeFolder,onChange:e=>r({storeFolder:e.target.value})}),B(`storeFolder`,n,`Browse storage backends`)]})}),(0,W.jsx)(Q,{label:`File name`,children:(0,W.jsx)(`select`,{className:X,value:t.storeName,onChange:e=>r({storeName:e.target.value}),children:ct.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),(0,W.jsx)(Q,{label:`Move or copy`,hint:t.storeMode===`move`?`Remove only the selected source copy after the destination is safely stored.`:`Preserve every existing copy.`,children:(0,W.jsx)(Et,{value:t.storeMode,onChange:e=>r({storeMode:e}),options:[{value:`copy`,label:`Copy`},{value:`move`,label:`Move`}]})}),t.storeMode===`move`&&(0,W.jsx)(Q,{className:`sm:col-span-2`,label:`Move bytes from (required)`,hint:`Context membership does not identify a source copy. If the file is absent here, nothing is moved. Multiple locations on this backend make the move ambiguous; use copy.`,children:H(t.storeFrom,e=>r({storeFrom:e}),`choose a source backend…`,`workspace:data`)}),t.storeName===`custom`&&(0,W.jsx)(Q,{className:`sm:col-span-2`,label:`Name template`,hint:`Tokens: {{YYYY}} {{MM}} {{DD}} {{HH}} {{mm}} {{ss}} (photo capture time when present), {{ext}} {{basename}} {{filename}} {{title}} {{id}}, plus {{doc.…}} fields. Slashes create sub-folders.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`{{YYYY}}-{{MM}}-{{DD}} {{title}}{{ext}}`,value:t.b,onChange:e=>r({b:e.target.value})})})]}),(0,W.jsx)($,{checked:t.recursive,onChange:e=>r({recursive:e}),label:d===null?`Recreate sub-folder path in destination`:`Recreate directory path in destination`,hint:o?Ge?d===null?`The path below the source folder is appended beneath the destination root: …/UI/mobile → Root/mobile. Missing destination folders are created.`:`Only inserts or links directly into ctx:${d} trigger this rule. Its full path is appended beneath the destination root; descendant inserts do not match.`:`For Context, choose one folder with “is inserted / linked directly into”. Directory and Backends sources can include sub-folders.`:`Choose a destination that reports support for folder paths. Content-addressed blob stores cannot recreate sub-folder paths.`,disabled:!s&&!t.recursive}),f&&(0,W.jsxs)(`div`,{className:`space-y-1.5 rounded-lg bg-muted/60 px-3 py-3 text-sm`,"aria-live":`polite`,children:[(0,W.jsx)(`p`,{className:`font-medium`,children:`Destination preview`}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Root folder: `,(0,W.jsxs)(`span`,{className:`break-all font-mono`,children:[f.root,`/`]})]}),t.recursive&&(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Path added beneath it: `,(0,W.jsxs)(`span`,{className:`break-all font-mono`,children:[f.recreated||`(root)`,`/`]})]}),(0,W.jsx)(`p`,{className:`break-all font-mono`,children:f.result})]}),(0,W.jsxs)(`details`,{className:`group rounded-lg border`,children:[(0,W.jsxs)(`summary`,{className:`flex cursor-pointer select-none items-center gap-2 px-3 py-2 text-sm font-medium`,children:[(0,W.jsx)(a,{className:`h-4 w-4 transition-transform group-open:rotate-180`}),` More options`]}),(0,W.jsxs)(`div`,{className:`grid gap-4 border-t p-3 sm:grid-cols-2`,children:[t.storeMode===`copy`&&(0,W.jsx)(Q,{label:`Copy bytes from`,hint:`Optional source restriction. Default: any readable copy outside the destination backend.`,children:H(t.storeFrom,e=>r({storeFrom:e}),`any readable source`,`workspace:data (optional)`)}),(0,W.jsx)(Q,{label:`If the name is already taken`,children:(0,W.jsxs)(`select`,{className:X,value:t.storeConflict,onChange:e=>r({storeConflict:e.target.value}),children:[(0,W.jsx)(`option`,{value:`rename`,children:`add -1, -2, … to the name`}),(0,W.jsx)(`option`,{value:`error`,children:`skip the file`}),(0,W.jsx)(`option`,{value:`overwrite`,children:`overwrite the existing file`})]})})]})]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The item keeps its id and virtual tree memberships. A move removes the chosen physical source location from the backend tree.`})]}),t.kind===`extractAttachments`&&(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:`Attachment types`,hint:`MIME types, comma-separated. application/pdf for PDFs, image/* for images, or * for all.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`application/pdf`,value:t.attachmentMime,onChange:e=>r({attachmentMime:e.target.value})})}),(0,W.jsx)(Q,{label:`Attachment filename contains`,hint:`Optional: invoice, faktura, or another literal filename fragment. Every selected attachment must also match its type.`,children:(0,W.jsx)(T,{className:Z,placeholder:`Any matching filename`,value:t.attachmentName,onChange:e=>r({attachmentName:e.target.value})})}),(0,W.jsx)(Q,{label:`Storage backend`,hint:`Choose a writable backend that supports folder paths.`,children:H(t.a,e=>r({a:e}),`pick a backend…`)}),(0,W.jsx)(Q,{label:`Destination root folder`,hint:`Choose the folder beneath which date subfolders will be created. Leave empty to use the backend root.`,children:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`Accounting`,value:t.storeFolder,onChange:e=>r({storeFolder:e.target.value})}),B(`storeFolder`,n,`Browse storage backends`)]})}),(0,W.jsx)(Q,{label:`Sub-folder path template`,hint:`Appended beneath the root folder. {{YYYY}} = year, {{MM}} = month, {{DD}} = day of the email. Leave empty to file directly in the root folder.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`No subfolders`,value:t.attachmentPath,onChange:e=>r({attachmentPath:e.target.value})})}),(0,W.jsx)(Q,{label:`If the attachment name is already taken`,children:(0,W.jsxs)(`select`,{className:X,value:t.storeConflict,onChange:e=>r({storeConflict:e.target.value}),children:[(0,W.jsx)(`option`,{value:`rename`,children:`add -1, -2, … to the name`}),(0,W.jsx)(`option`,{value:`error`,children:`skip the file and report the conflict`})]})})]}),!o&&(0,W.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-400`,children:`This destination has not reported support for folder paths. Select a supported backend before saving.`}),p&&(0,W.jsxs)(`div`,{className:`space-y-1.5 rounded-lg bg-muted/60 px-3 py-3 text-sm`,"aria-live":`polite`,children:[(0,W.jsx)(`p`,{className:`font-medium`,children:`Destination preview`}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Example email dated `,p.date,`. Each email supplies its own date.`]}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Root folder: `,(0,W.jsxs)(`span`,{className:`break-all font-mono`,children:[p.root,`/`]})]}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Path added beneath it: `,(0,W.jsx)(`span`,{className:`break-all font-mono`,children:p.added?`${p.added}/`:`(none)`})]}),(0,W.jsx)(`p`,{className:`break-all font-mono`,children:p.result})]}),(0,W.jsx)($,{checked:t.includeInline,onChange:e=>r({includeInline:e}),label:`Include inline attachments`,hint:`Off by default, so signature images and embedded resources are excluded.`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Copies matching attachments and keeps the email and its original files. Missing folders are created on the backend. Dates use the email's sent date (received/content date, then creation date if absent), in the server's timezone. This does not read the invoice date from the PDF.`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Use Apply on the saved rule to process existing mail within the selected batch size. Add a subject or attachment filename condition if you need to distinguish invoices from other PDFs.`})]}),t.kind===`download`&&(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:`Download`,hint:st.find(e=>e.value===t.dlKind)?.hint,children:(0,W.jsx)(`select`,{className:X,value:t.dlKind,onChange:e=>r({dlKind:e.target.value}),children:st.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),t.dlKind===`website`?(0,W.jsx)(Q,{label:`Mirror depth`,hint:`How many link hops to follow on the same site (1–5).`,children:(0,W.jsx)(T,{type:`number`,min:1,max:5,className:C(Z,`sm:max-w-32`),value:t.dlDepth,onChange:e=>r({dlDepth:e.target.value})})}):(0,W.jsx)(`div`,{className:`hidden sm:block`}),(0,W.jsx)(Q,{label:`Storage backend`,hint:`Where the downloaded file's bytes should live.`,children:H(t.a,e=>r({a:e}),`workspace:home (default)`)}),(0,W.jsx)(Q,{label:`Folder on that backend`,hint:`Relative to the backend root.`,children:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`Downloads`,value:t.storeFolder,onChange:e=>r({storeFolder:e.target.value})}),B(`storeFolder`,n,`Browse storage backends`)]})}),(0,W.jsx)(Q,{label:`File the download under`,hint:`Leave empty to file it in the same folder(s) as the link. Comma-separate several.`,children:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`same folders as the link`,value:t.b,onChange:e=>r({b:e.target.value})}),B(`action`,n)]})}),(0,W.jsx)(Q,{label:`Tags for the download`,hint:`Optional, comma-separated.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`downloaded, custom/paper`,value:t.dlTags,onChange:e=>r({dlTags:e.target.value})})})]}),(0,W.jsx)($,{checked:t.recursive,onChange:e=>r({recursive:e}),label:`Recreate sub-folder path in destination`,hint:V?`A link filed under …/folder/a/b is downloaded into Folder/a/b.`:`Add an "is under the folder" condition to mirror sub-folders.`,disabled:!V}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`The link stays as it is; the download becomes a new file item next to it. Each link is downloaded once per rule. Videos need `,(0,W.jsx)(`span`,{className:`font-mono`,children:`yt-dlp`}),`, pages and websites `,(0,W.jsx)(`span`,{className:`font-mono`,children:`wget`}),` on the server.`]})]}),t.kind===`unstore`&&(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:`Delete the file from`,children:H(t.a,e=>r({a:e}),`pick a backend…`,`workspace:data`)}),(0,W.jsx)(Q,{label:`…but only once it is also on`,hint:`Safety: the copy is dropped only after another backend holds the file.`,children:H(t.b,e=>r({b:e}),`anywhere else`,`workspace:home (optional)`)})]}),(0,W.jsx)($,{checked:t.keepLast,onChange:e=>r({keepLast:e}),label:`Never delete the last copy`,hint:`Off means the rule may delete the only remaining copy of a file. Leave it on unless you mean exactly that.`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Deletes the stored bytes on that backend only — copies elsewhere and the item itself are kept.`})]}),t.kind===`sendFile`&&(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsx)(Q,{label:`Files to send`,children:(0,W.jsxs)(`select`,{className:X,value:t.sendSource,onChange:e=>r({sendSource:e.target.value}),children:[(0,W.jsx)(`option`,{value:`document`,children:`The file that triggered this rule`}),(0,W.jsx)(`option`,{value:`attachments`,children:`Matching attachments from the email`}),(0,W.jsx)(`option`,{value:`download`,children:`Files from an earlier Download action`})]})}),t.sendSource===`attachments`&&(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:`Attachment types`,hint:`application/pdf for invoices; * for all files.`,children:(0,W.jsx)(T,{className:Z,value:t.attachmentMime,onChange:e=>r({attachmentMime:e.target.value})})}),(0,W.jsx)(Q,{label:`Attachment filename contains`,hint:`Optional literal filename fragment.`,children:(0,W.jsx)(T,{className:Z,placeholder:`invoice`,value:t.attachmentName,onChange:e=>r({attachmentName:e.target.value})})})]}),t.sendSource===`attachments`&&(0,W.jsx)($,{checked:t.includeInline,onChange:e=>r({includeInline:e}),label:`Include inline attachments`,hint:`Signature images are excluded by default.`}),(0,W.jsx)(Q,{label:`Sending account`,hint:`Enable sending for the account in Connected services.`,children:(0,W.jsxs)(`select`,{className:X,value:t.a?`${t.sendDriver}:${t.a}`:``,onChange:e=>{let t=he.find(t=>`${t.driver}:${t.address}`===e.target.value);t&&r({a:t.address,sendDriver:t.driver,b:``})},children:[(0,W.jsx)(`option`,{value:``,disabled:!0,children:`Choose email, WhatsApp or Slack…`}),t.a&&!he.some(e=>e.driver===t.sendDriver&&e.address===t.a)&&(0,W.jsxs)(`option`,{value:`${t.sendDriver}:${t.a}`,disabled:!0,children:[t.sendDriver,`: `,t.a,` (unavailable)`]}),he.map(e=>(0,W.jsxs)(`option`,{value:`${e.driver}:${e.address}`,disabled:!e.canSend,children:[e.driver===`imap`?`Email (SMTP)`:e.driver===`whatsapp`?`WhatsApp`:`Slack`,` · `,e.from||e.address,e.canSend?``:` — sending disabled`]},`${e.driver}:${e.address}`))]})}),_e&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,role:`status`,children:_e}),(0,W.jsx)(Q,{label:t.sendDriver===`imap`?`Destination email address`:`Destination conversation`,hint:t.sendDriver===`imap`?`The accounting ingestion address; separate multiple recipients with commas.`:t.sendDriver===`slack`?`A configured Slack channel ID or name. The account needs files:write permission.`:`A configured WhatsApp chat ID, e.g. 421…@s.whatsapp.net or …@g.us.`,children:(0,W.jsx)(T,{className:Z,value:t.b,placeholder:t.sendDriver===`imap`?`invoices@accounting-firm.example`:t.sendDriver===`slack`?`C0123456789`:`421…@s.whatsapp.net`,onChange:e=>r({b:e.target.value})})}),t.sendDriver===`imap`&&(0,W.jsx)(Q,{label:`Email subject`,hint:`{{file.name}} inserts the attachment filename.`,children:(0,W.jsx)(T,{className:Z,value:t.sendSubject,onChange:e=>r({sendSubject:e.target.value})})}),(0,W.jsx)(Q,{label:t.sendDriver===`imap`?`Email body (optional)`:`Message / caption (optional)`,hint:`Templates: {{file.name}}, {{doc.data.subject}}, {{doc.data.title}}.`,children:(0,W.jsx)(`textarea`,{className:`min-h-20 w-full rounded-md border bg-background p-3 text-sm`,value:t.sendMessage,onChange:e=>r({sendMessage:e.target.value})})}),(0,W.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-3 text-sm`,"aria-label":`File delivery preview`,children:[t.sendSource===`attachments`?`Each matching email attachment`:t.sendSource===`download`?`Each downloaded file`:`The triggering file`,` → `,t.sendDriver===`imap`?`email attachment`:t.sendDriver===`slack`?`Slack file upload`:`WhatsApp document`,` → `,t.b||`choose a destination`]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Sends each file in a separate message and keeps the original. Maximum 18 MB per file. Replaying this rule does not resend the same file version to the same destination. Unconfirmed deliveries are recorded for review, not retried automatically.`}),t.sendSource===`document`&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`For files created by another automation, enable this rule’s option to also run on automation events.`})]}),t.kind===`notify`&&(0,W.jsx)(Q,{label:`Notification`,hint:`Notifies you through your bound channel, or in Canvas. Templates: {{doc.data.subject}}, {{doc.data.from}}, {{doc.data.title}}…`,children:(0,W.jsx)(T,{className:Z,placeholder:`New mail from {{doc.data.from}}: {{doc.data.subject}}`,value:t.a,onChange:e=>r({a:e.target.value})})}),t.kind===`delete`&&(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Removes the item from the Canvas index. Files, blobs and mail on storage backends stay untouched.`}),t.kind===`destroy`&&(0,W.jsx)(`p`,{className:`rounded-lg border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive`,children:`⚠ Irreversible: deletes the stored bytes too (blobs, workspace files, mail on the server), then removes the item from the index.`}),t.kind===`agent`&&(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsx)(Q,{label:`Agent`,hint:`The agent's slug.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono sm:max-w-xs`),placeholder:`assistant`,value:t.a,onChange:e=>r({a:e.target.value})})}),(0,W.jsx)(Q,{label:`Prompt`,hint:`Templates use indexed fields: {{doc.id}}, {{doc.data.subject}}, {{doc.data.bodyPreview}} (emails), {{doc.data.url}}… Ask the agent to use canvas_get for full email content. Objects are inserted as JSON.`,children:(0,W.jsx)(`textarea`,{className:`min-h-28 w-full rounded-md border bg-background p-3 text-sm outline-none focus:ring-2 focus:ring-ring`,placeholder:`Read email #{{doc.id}} in full with canvas_get and summarize it in plain markdown.
4
+
5
+ Subject: {{doc.data.subject}}
6
+ Preview: {{doc.data.bodyPreview}}`,value:t.b,onChange:e=>r({b:e.target.value})})}),u(`reply`)]}),t.kind===`script`&&(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsx)(Q,{label:`Script`,hint:`From the Scripts section of this workspace.`,children:pe.length?(0,W.jsxs)(`select`,{className:C(X,`font-mono sm:max-w-md`),value:t.a,onChange:e=>r({a:e.target.value}),children:[(0,W.jsx)(`option`,{value:``,children:`pick a script…`}),pe.map(e=>(0,W.jsx)(`option`,{value:`scripts/${e}`,children:e},e))]}):(0,W.jsx)(T,{className:C(Z,`font-mono sm:max-w-md`),placeholder:`scripts/my-script.sh`,value:t.a,onChange:e=>r({a:e.target.value})})}),u(`output`)]})]},n)}),(0,W.jsxs)(w,{size:`sm`,variant:`outline`,onClick:()=>L(`actions`,[...O.actions,K(`tag`)]),children:[(0,W.jsx)(u,{className:`mr-1 h-4 w-4`}),` Add another action`]})]}),(0,W.jsxs)(`section`,{className:`space-y-3`,children:[(0,W.jsx)(Ot,{step:3,title:`Options`}),(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsx)($,{checked:O.approval,onChange:e=>L(`approval`,e),label:`Ask me before running`,hint:`Actions are held in the Pending queue for review — approve (optionally amended) or decline — instead of running automatically.`}),(0,W.jsx)($,{checked:O.cascade,onChange:e=>L(`cascade`,e),label:`Also react to items created by automation`,hint:`Off by default so rules, hooks and agents cannot trigger each other in a loop. A server-side depth limit still stops runaway chains.`})]})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2 border-t pt-4`,children:[(0,W.jsxs)(w,{className:`h-10 px-5`,onClick:je,disabled:M||se,children:[M?(0,W.jsx)(ee,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,W.jsx)(i,{className:`mr-1.5 h-4 w-4`}),` `,O.id?`Save changes`:`Create rule`]}),(0,W.jsx)(w,{className:`h-10`,variant:`outline`,onClick:()=>{A(null),_?.()},children:`Cancel`})]})]}),R&&(0,W.jsx)(ue,{onClose:()=>z(null),children:(0,W.jsx)(ie,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,fixedWorkspaceName:e,multiple:R.target!==`storeFolder`&&!(R.target===`condition`&&O?.actions.some(e=>e.kind===`store`)),tabs:R.target===`condition`?[`context`,`directory`,`backends`]:R.target===`storeFolder`?[`backends`]:[`context`,`directory`],title:R.target===`condition`?`Choose source folder…`:R.target===`storeFolder`?`Store files under…`:`File into…`,confirmLabel:R.target===`storeFolder`?`Use folder`:`Use path`,onConfirm:Ue,onClose:()=>z(null)})}),!m&&(se?(0,W.jsx)(`p`,{className:`rounded-xl border p-6 text-center text-sm text-muted-foreground`,children:`Loading…`}):S.length===0?!fe&&!O&&(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`rounded-xl border border-dashed p-6 text-center`,children:[(0,W.jsx)(`p`,{className:`text-base font-medium`,children:`No rules yet`}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Pick a starting point below, or right-click a folder in the tree and choose “Create rule…”.`})]}),Ze]}):(0,W.jsxs)(`div`,{className:`space-y-6`,children:[Je.length>0&&(0,W.jsxs)(`section`,{className:`space-y-3`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 text-sm text-muted-foreground`,children:[(0,W.jsxs)(`h3`,{className:`flex items-center gap-2 font-semibold uppercase tracking-wide`,children:[(0,W.jsx)(o,{className:`h-4 w-4 shrink-0`}),` Folder & storage rules`]}),(0,W.jsx)(`p`,{children:`Right-click a folder in the tree to add one`})]}),(0,W.jsx)(`div`,{className:`space-y-3`,children:Je.map(e=>(0,W.jsx)(Xe,{rule:e},e.id))})]}),U.length>0&&(0,W.jsxs)(`section`,{className:`space-y-3`,children:[Je.length>0&&(0,W.jsxs)(`h3`,{className:`flex items-center gap-2 text-sm font-semibold uppercase tracking-wide text-muted-foreground`,children:[(0,W.jsx)(x,{className:`h-4 w-4`}),` Other rules`]}),(0,W.jsx)(`div`,{className:`space-y-3`,children:U.map(e=>(0,W.jsx)(Xe,{rule:e},e.id))})]})]}))]})}function jt(e,t){let n=t.split(`/`).filter(Boolean);if(e!==`backends`||n[0]!==`Trash`)return null;try{return{backend:n[1]?decodeURIComponent(n[1]):null,prefix:n.slice(2).join(`/`)}}catch{return null}}function Mt(e,t=``){return`/Trash${e?`/${encodeURIComponent(e)}`:``}${t?`/${t}`:``}`}function Nt(e,t=``){let n=new Map,r=[],i=t?`${t}/`:``;for(let t of e){if(!t.key.startsWith(i))continue;let e=t.key.slice(i.length);if(!e)continue;let a=e.indexOf(`/`);if(a>=0){let r=e.slice(0,a),o=i+r,s=n.get(o)??{id:`folder:${o}`,name:r,key:o,directory:!0,navigable:!0,items:[]};s.items.push(t),n.set(o,s)}else r.push({id:t.id,name:e,key:t.key,directory:t.type===`directory`,navigable:!1,items:[t]})}return[...n.values(),...r].sort((e,t)=>Number(t.directory)-Number(e.directory)||e.name.localeCompare(t.name)||t.items[0].deletedAt-e.items[0].deletedAt||e.id.localeCompare(t.id))}var Pt=(e,t)=>`${ne.workspaces}/${encodeURIComponent(e)}/backends/file/${encodeURIComponent(t)}/trash`;async function Ft(e,t){let n=[],r=new Set,i=null,a=null;do{let o=new URLSearchParams({limit:`1000`,...i?{cursor:i}:{}}),s=await E.get(`${Pt(e,t)}?${o}`);if(n.push(...s.items),a=s.retention?.days??null,i=s.cursor,i&&r.has(i))throw Error(`Trash listing returned a repeated cursor`);i&&r.add(i)}while(i);return{items:n,days:a}}function It(e,t,n){return Rt(e,t,n,`restore`)}function Lt(e,t,n){return Rt(e,t,n,`discard`)}async function Rt(e,t,n,r){let i=[...new Set(n)],a=[];try{for(let n=0;n<i.length;n+=100){let o=await E.post(`${Pt(e,t)}/${r}`,{ids:i.slice(n,n+100)});a.push(...o.results)}return a}finally{ce(e,`backends`),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:`backends`}})),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e}})),window.dispatchEvent(new CustomEvent(`workspace:trash:refresh`,{detail:{workspaceName:e,backend:t}}))}}async function zt(e,t){let n=jt(`backends`,t);if(!n?.backend)return;let{items:r}=await Ft(e,n.backend),i=r.filter(e=>!n.prefix||e.key===n.prefix||e.key.startsWith(`${n.prefix}/`)).sort((e,t)=>t.deletedAt-e.deletedAt),a=await It(e,n.backend,i.map(e=>e.id)),o=a.filter(e=>!e.ok);if(o.length)throw Error(`${a.length-o.length} restored; ${o.length} remain in Trash. Existing paths were kept.`)}function Bt(e,t){if(!t.length)return!1;let n=[...new Set(t.map(e=>e.key))],r=n.slice(0,5).join(`
7
+ `)+(n.length>5?`\n…and ${n.length-5} more paths`:``);return window.confirm(`Permanently delete ${t.length} Trash item(s) from ${e}?\n\n${r}\n\nDeleted folders include all their contents. This cannot be undone. Files currently at the original paths are kept.`)}async function Vt(e,t){let n=jt(`backends`,t);if(!n?.backend)return;let{items:r}=await Ft(e,n.backend),i=r.filter(e=>!n.prefix||e.key===n.prefix||e.key.startsWith(`${n.prefix}/`));if(!Bt(n.backend,i))return;let a=await Lt(e,n.backend,i.map(e=>e.id)),o=a.filter(e=>!e.ok);if(o.length)throw Error(`${a.length-o.length} deleted; ${o.length} remain in Trash. ${o[0].message||o[0].reason||`Please retry.`}`)}var Ht=new Map;function Ut(e,t,n,r,i,a){let o=JSON.stringify([t,n,r,a]),s=Ht.get(o);if(s)return s;let c=(async()=>{let o=e({title:`Resyncing…`,description:r});try{for(a?await se(t,n,r,a):await O(t,n,r);;){let e=await ae(t,n,r);i?.(e);let s=a?e.containers?.find(e=>e.name===a):void 0;if(a?s?.status!==`syncing`:!e.resyncing&&e.status!==`syncing`){let i=s?s.lastError:e.lastError;if(i)throw Error(i);o.done({title:e.resyncCancelledAt?`Resync stopped`:`Resync complete`,description:`${r}${n!==`imap`&&e.progress?` · ${e.progress.scanned} files scanned`:``}`}),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:t,treeName:`backends`}}));return}let c=n===`imap`?void 0:e.progress;o.update({title:`Resyncing…`,description:`${r}${c?` · ${c.scanned}${c.total==null?``:` / ${c.total}`} files scanned`:``}`}),await new Promise(e=>setTimeout(e,2e3))}}catch(e){throw o.fail({title:`Resync needs attention`,description:`${r}: ${e instanceof Error?e.message:String(e)}`,variant:`destructive`}),e}})();return Ht.set(o,c),c.finally(()=>{Ht.get(o)===c&&Ht.delete(o)}).catch(()=>{}),c}export{ke as A,R as B,Ce as C,j as D,Ne as E,fe as F,Pe as H,De as I,Ae as L,Fe as M,he as N,Be as O,me as P,z as R,Oe as S,Ve as T,_e as U,M as V,xe as W,qe as _,Ft as a,Ie as b,jt as c,At as d,Qe as f,Je as g,Ze as h,Vt as i,ve as j,Te as k,Mt as l,Ye as m,Bt as n,It as o,Xe as p,Lt as r,zt as s,Ut as t,Nt as u,I as v,N as w,Me as x,Ue as y,Se as z};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{yi as r}from"./ui-BSqPn1LJ.js";import{i}from"./utils-BxVxyehK.js";import{t as a}from"./utils-2pl1SbIp.js";var o=e(n(),1),s=i([`inline-flex items-center justify-center gap-2 whitespace-nowrap`,`text-sm transition-colors`,`rounded-(--btn-radius) font-(number:--btn-font-weight)`,`focus-ring`,`disabled:pointer-events-none disabled:opacity-50`,`[&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`],{variants:{variant:{default:`bg-primary text-primary-foreground shadow-elevation-1 hover:bg-primary/90`,destructive:`bg-destructive text-destructive-foreground shadow-elevation-1 hover:bg-destructive/90`,outline:`border-(length:--btn-border-width) border-input bg-background shadow-elevation-1 hover:bg-accent hover:text-accent-foreground`,secondary:`bg-secondary text-secondary-foreground shadow-elevation-1 hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-(--btn-height) px-(--btn-padding-x)`,sm:`h-control-sm rounded-(--btn-radius) px-3 text-xs`,lg:`h-control-lg rounded-(--btn-radius) px-8`,icon:`h-(--btn-height) w-(--btn-height)`}},defaultVariants:{variant:`default`,size:`default`}}),c=t(),l=o.forwardRef(({className:e,variant:t,size:n,asChild:i=!1,...o},l)=>(0,c.jsx)(i?r:`button`,{className:a(s({variant:t,size:n,className:e})),ref:l,...o}));l.displayName=`Button`;export{s as n,l as t};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{bi as r}from"./ui-Byg1cZDr.js";import{i}from"./utils-BxVxyehK.js";import{t as a}from"./utils-2pl1SbIp.js";var o=e(n(),1),s=i([`inline-flex items-center justify-center gap-2 whitespace-nowrap`,`text-sm transition-colors`,`rounded-(--btn-radius) font-(number:--btn-font-weight)`,`focus-ring`,`disabled:pointer-events-none disabled:opacity-50`,`[&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`],{variants:{variant:{default:`bg-primary text-primary-foreground shadow-elevation-1 hover:bg-primary/90`,destructive:`bg-destructive text-destructive-foreground shadow-elevation-1 hover:bg-destructive/90`,outline:`border-(length:--btn-border-width) border-input bg-background shadow-elevation-1 hover:bg-accent hover:text-accent-foreground`,secondary:`bg-secondary text-secondary-foreground shadow-elevation-1 hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-(--btn-height) px-(--btn-padding-x)`,sm:`h-control-sm rounded-(--btn-radius) px-3 text-xs`,lg:`h-control-lg rounded-(--btn-radius) px-8`,icon:`h-(--btn-height) w-(--btn-height)`}},defaultVariants:{variant:`default`,size:`default`}}),c=t(),l=o.forwardRef(({className:e,variant:t,size:n,asChild:i=!1,...o},l)=>(0,c.jsx)(i?r:`button`,{className:a(s({variant:t,size:n,className:e})),ref:l,...o}));l.displayName=`Button`;export{s as n,l as t};