@augmentd-labs/canvas-web 2.26.45 → 2.27.0

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 (30) hide show
  1. package/dist/assets/{CalendarApplet-CsyUmI2B.js → CalendarApplet-Be25FsQH.js} +1 -1
  2. package/dist/assets/{FiltersApplet-CVnCAs-P.js → FiltersApplet-CuBp34Ll.js} +1 -1
  3. package/dist/assets/{HomeFab-iC5BF7LV.js → HomeFab-BVC6GyBo.js} +1 -1
  4. package/dist/assets/{LensApplet-DA0ZWS1k.js → LensApplet-cH9mu9Ek.js} +1 -1
  5. package/dist/assets/{NotesApplet-BSJ-9RKl.js → NotesApplet-D7vrAU-F.js} +1 -1
  6. package/dist/assets/{_agentId_-BrzFDu8r.js → _agentId_-D7FMIU0U.js} +0 -0
  7. package/dist/assets/{_contextId_-DS6b9Uml.js → _contextId_-nHWeEqjb.js} +1 -1
  8. package/dist/assets/{_workspaceName_-XRqfa4c6.js → _workspaceName_-Ca7l8D3u.js} +1 -1
  9. package/dist/assets/{about-hcdKJNm5.js → about-DPQIKA4h.js} +1 -1
  10. package/dist/assets/{add-CEBusWuu.js → add-C4IXcB8E.js} +1 -1
  11. package/dist/assets/{agents-wFp7Vh3p.js → agents-Cq1aDFAt.js} +1 -1
  12. package/dist/assets/{appearance-D5BUjZm8.js → appearance-DTH3zH0p.js} +1 -1
  13. package/dist/assets/{apps-65YXCnzH.js → apps-DGG9ruBT.js} +1 -1
  14. package/dist/assets/{home-vr8b8oR-.js → home-BK8Bp4d-.js} +1 -1
  15. package/dist/assets/index-NOhHv2VY.js +16 -0
  16. package/dist/assets/{key-bindings-DmqvYSaF.js → key-bindings-Cbh1Fiav.js} +1 -1
  17. package/dist/assets/{registry-g1SKt_fD.js → registry-D7HyG001.js} +2 -2
  18. package/dist/assets/{settings-CbMkpipO.js → settings-6UW5qG-V.js} +1 -1
  19. package/dist/assets/{settings-XMhqrvTu.js → settings-BbqSg6FH.js} +1 -1
  20. package/dist/assets/{settings-BWCMmkjr.js → settings-CkBpWcHX.js} +1 -1
  21. package/dist/assets/{settings-BIoSwdXv.js → settings-Ckel628s.js} +1 -1
  22. package/dist/assets/{share-target-hDXdgW6o.js → share-target-CuBCWHxv.js} +1 -1
  23. package/dist/assets/{shared-DVlDThVA.js → shared-CqqMgsnU.js} +1 -1
  24. package/dist/assets/{tree-folders-IDoobsGN.js → tree-folders-dKwIsl1U.js} +1 -1
  25. package/dist/assets/{useAgentModels-CI9XT6yc.js → useAgentModels-DTZNaSRA.js} +1 -1
  26. package/dist/assets/{workspaces-ByYQ6L3I.js → workspaces-CXhffn_p.js} +1 -1
  27. package/dist/index.html +2 -2
  28. package/dist/sw.js +1 -1
  29. package/package.json +2 -2
  30. package/dist/assets/index-CTvqbEB8.js +0 -16
@@ -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,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Gr as o,Kn as s,L as c,Tt as l,Ur as u,X as d,_r as f,ar as p,kt as m,pn as ee}from"./ui-DEgHnkQu.js";import{t as h}from"./utils-2pl1SbIp.js";import{t as g}from"./button--VYZekMF.js";import{c as te,t as ne}from"./api-CA6WiiYM.js";import{t as _}from"./socket-CtH3EU9m.js";import{n as re}from"./use-toast-BlLDqSUO.js";import{h as v,o as ie,s as y}from"./LinkToCard-oi3wGP0a.js";import{At as b,D as x,G as ae,Gt as S,Kt as C,Lt as w,W as oe,Y as se,_ as T,_n as E,a as ce,gt as le,lt as D,mt as ue,nt as de,rn as fe,rt as pe,u as me,vt as he,w as ge,x as _e,xn as O,y as ve,zt as ye}from"./workspace-4hWrSEku.js";import{n as be,r as xe}from"./use-canvas-pins-q5Tncavk.js";import{u as Se}from"./ObjectPropertiesCard-DesXRw-_.js";import{D as Ce,E as we,a as Te,c as Ee,j as De,l as k,n as A,o as Oe,r as ke,u as Ae}from"./document-list-Bbbx-pTZ.js";import{n as je}from"./use-toolbox-Ck_cLGgf.js";import{i as Me}from"./color-DFEH4BfK.js";import{t as Ne}from"./geo-CZfs0E-x.js";import{a as Pe,i as Fe,n as Ie,o as Le}from"./workspace-BydSRtST.js";import{n as Re,r as ze,t as Be}from"./url-params-n7kU_WZ-.js";import{i as Ve}from"./use-menu-CKSpS96u.js";import{n as He}from"./last-path-BbXWC3b3.js";import{i as Ue,n as We,r as Ge,t as Ke}from"./document-paste-BuTC6S7_.js";import{t as qe}from"./workspace-content-gate-BlFdbi67.js";import{t as Je}from"./form-panel-CEbNKttr.js";import{a as Ye,c as Xe,i as Ze,l as Qe,n as $e,o as et,r as tt,s as nt,t as rt,u as it}from"./tree-folders-IDoobsGN.js";import{i as at,r as ot}from"./query-debug-PEWbZsOP.js";var j=`session.open`,st=`session.set`,ct=`session.ids`,lt=`session.materialize`,ut=`session.close`,dt=`session.delta`,M=e(n(),1),N=t();function ft(e){let t=Ee(`backends`,e.path)?.backend;return(0,N.jsx)(pt,{...e},JSON.stringify([e.workspace,t]))}function pt({workspace:e,path:t,onNavigate:n}){let r=Ee(`backends`,t),i=r.backend,a=r.prefix,[o,c]=(0,M.useState)(null),[u,ee]=(0,M.useState)(null),h=(0,M.useRef)(!1),[g,te]=(0,M.useState)(null),[ne,_]=(0,M.useState)(null),[re,b]=(0,M.useState)(0),[x,ae]=(0,M.useState)(new Set),[S,C]=(0,M.useState)(null),w=(0,M.useCallback)(()=>b(e=>e+1),[]),[oe,se]=(0,M.useState)(t);oe!==t&&(se(t),ae(new Set),C(null),_(null),te(null));let T=o?.revision!==re,E=T?[]:o.items,ce=T?[]:o.backends,le=o?.days;(0,M.useEffect)(()=>{let t=!1;return(i?Te(e,i).then(e=>({...e,backends:[]})):he(e).then(e=>({items:[],days:null,backends:e.filter(e=>e.driver===`file`&&e.enabled!==!1)}))).then(e=>{t||c({...e,revision:re,error:null})}).catch(e=>{t||c({revision:re,items:[],backends:[],days:null,error:e instanceof Error?e.message:String(e)})}),()=>{t=!0}},[e,i,re]),(0,M.useEffect)(()=>{let t=null,n=n=>{let r=n.detail;r?.workspaceName&&r.workspaceName!==e||r?.treeName&&r.treeName!==`backends`||(t||=setTimeout(()=>{t=null,w()},500))};return window.addEventListener(`workspace:trash:refresh`,n),window.addEventListener(`workspace:tree:refresh`,n),()=>{window.removeEventListener(`workspace:trash:refresh`,n),window.removeEventListener(`workspace:tree:refresh`,n),t&&clearTimeout(t)}},[e,w]);let D=Ae(E,a),ue=async(t,n)=>{if(!(!i||h.current||T||!n.length)&&!(t===`discard`&&!A(i,n))){h.current=!0,ee(t),te(null),_(null),C(null);try{let r=await(t===`restore`?Oe:ke)(e,i,[...n].sort((e,t)=>t.deletedAt-e.deletedAt).map(e=>e.id)),a=r.filter(e=>!e.ok);_(`${r.length-a.length} item(s) ${t===`restore`?`restored to their original paths`:`permanently deleted`}.`),a.length&&te(`${a.length} item(s) remain in Trash. ${a.slice(0,3).map(e=>`${e.key||`Item`}: ${e.reason===`precondition-failed`||e.reason===`target-exists`?`original path is occupied`:e.message||e.reason}`).join(`; `)}`),ae(new Set)}catch(e){te(e instanceof Error?e.message:String(e))}finally{h.current=!1,ee(null),w()}}},de=(e,t,n)=>C({x:e,y:t,row:n});return(0,N.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col bg-background`,"aria-label":`Backend Trash`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 border-b px-4 py-3`,children:[(0,N.jsx)(d,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,N.jsx)(y,{items:ie(t,e).map((e,t)=>t===2&&i?{...e,label:i}:e),onNavigate:n,className:`basis-48`}),(0,N.jsxs)(`div`,{className:`ml-auto flex max-w-full flex-wrap items-center gap-2`,children:[x.size>0&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm disabled:opacity-50`,disabled:!!u||T,onClick:()=>void ue(`restore`,D.filter(e=>x.has(e.id)).flatMap(e=>e.items)),children:[(0,N.jsx)(l,{className:`h-3.5 w-3.5`}),`Restore selected`]}),(0,N.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm text-destructive disabled:opacity-50`,disabled:!!u||T,onClick:()=>void ue(`discard`,D.filter(e=>x.has(e.id)).flatMap(e=>e.items)),children:[(0,N.jsx)(d,{className:`h-3.5 w-3.5`}),`Delete selected`]})]}),i&&D.length>0&&(0,N.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm text-destructive disabled:opacity-50`,disabled:!!u||T,onClick:()=>void ue(`discard`,D.flatMap(e=>e.items)),children:[(0,N.jsx)(d,{className:`h-3.5 w-3.5`}),a?`Empty this folder`:`Empty Trash`]}),(0,N.jsx)(`button`,{title:`Refresh Trash`,"aria-label":`Refresh Trash`,className:`rounded p-2 hover:bg-accent`,disabled:!!u||T,onClick:w,children:(0,N.jsx)(m,{className:`h-4 w-4 ${T?`animate-spin`:``}`})})]})]}),(0,N.jsxs)(`div`,{className:`border-b px-4 py-2 text-xs text-muted-foreground`,children:[`Restore files and folders to their original paths. Existing files are kept.`,le?` Deleted items are kept for ${le} days.`:``]}),ne&&(0,N.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:ne}),(g||o?.error)&&(0,N.jsx)(`p`,{role:`alert`,className:`px-4 py-2 text-sm text-destructive`,children:g||o?.error}),u&&(0,N.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:u===`restore`?`Restoring…`:`Deleting permanently…`}),(0,N.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:T?(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading Trash…`}):i?D.length===0?(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`This Trash folder is empty.`}):(0,N.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,N.jsx)(`thead`,{className:`border-b text-xs text-muted-foreground`,children:(0,N.jsxs)(`tr`,{children:[(0,N.jsx)(`th`,{className:`w-8 p-2`,children:(0,N.jsx)(`input`,{type:`checkbox`,"aria-label":`Select all visible items`,checked:D.length>0&&D.every(e=>x.has(e.id)),onChange:e=>ae(e.target.checked?new Set(D.map(e=>e.id)):new Set)})}),(0,N.jsx)(`th`,{className:`p-2`,children:`Name`}),(0,N.jsx)(`th`,{className:`p-2 max-sm:hidden`,children:`Original path`}),(0,N.jsx)(`th`,{className:`p-2 max-md:hidden`,children:`Deleted`}),(0,N.jsx)(`th`,{className:`p-2`,children:(0,N.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,N.jsx)(`tbody`,{children:D.map(e=>(0,N.jsxs)(`tr`,{className:`border-b border-border/50 hover:bg-accent/50`,onContextMenu:t=>{t.preventDefault(),de(t.clientX,t.clientY,e)},onDoubleClick:()=>e.navigable&&n(k(i,e.key)),children:[(0,N.jsx)(`td`,{className:`p-2`,children:(0,N.jsx)(`input`,{type:`checkbox`,"aria-label":`Select ${e.name}`,checked:x.has(e.id),disabled:!!u,onChange:t=>ae(n=>{let r=new Set(n);return t.target.checked?r.add(e.id):r.delete(e.id),r})})}),(0,N.jsx)(`td`,{className:`p-2`,children:(0,N.jsxs)(`button`,{className:`flex items-center gap-2 text-left`,onClick:()=>e.navigable&&n(k(i,e.key)),children:[e.directory?(0,N.jsx)(s,{className:`h-4 w-4 shrink-0`}):(0,N.jsx)(p,{className:`h-4 w-4 shrink-0`}),(0,N.jsxs)(`span`,{children:[e.name,e.navigable&&(0,N.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[e.items.length,` items`]})]})]})}),(0,N.jsx)(`td`,{className:`p-2 text-xs text-muted-foreground max-sm:hidden`,children:e.key}),(0,N.jsx)(`td`,{className:`p-2 text-xs text-muted-foreground max-md:hidden`,children:new Date(e.items.reduce((e,t)=>Math.max(e,t.deletedAt),0)).toLocaleString()}),(0,N.jsx)(`td`,{className:`p-2 text-right`,children:(0,N.jsx)(`button`,{title:`Actions for ${e.name}`,"aria-label":`Actions for ${e.name}`,disabled:!!u,className:`rounded p-2 hover:bg-accent`,onClick:t=>de(t.clientX,t.clientY,e),children:(0,N.jsx)(f,{className:`h-4 w-4`})})})]},e.id))})]}):(0,N.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-3`,children:[ce.map(e=>(0,N.jsxs)(`button`,{onClick:()=>n(k(e.address)),className:`flex items-center gap-3 rounded-lg border p-4 text-left hover:bg-accent`,children:[(0,N.jsx)(d,{className:`h-6 w-6 text-muted-foreground`}),(0,N.jsxs)(`span`,{children:[(0,N.jsx)(`span`,{className:`block text-sm font-medium`,children:e.label||e.address}),(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.address})]})]},e.address)),!ce.length&&(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`No file backends are available.`})]})}),S&&(0,N.jsxs)(v,{x:S.x,y:S.y,onClose:()=>C(null),className:`min-w-44 rounded-md border bg-popover p-1 shadow-elevation-3`,children:[S.row.navigable&&(0,N.jsxs)(`button`,{className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm hover:bg-accent`,onClick:()=>{n(k(i,S.row.key)),C(null)},children:[(0,N.jsx)(s,{className:`h-4 w-4`}),`Open folder`]}),(0,N.jsxs)(`button`,{disabled:!!u,className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm hover:bg-accent disabled:opacity-50`,onClick:()=>void ue(`restore`,S.row.items),children:[(0,N.jsx)(l,{className:`h-4 w-4`}),`Restore `,S.row.directory?`folder`:`file`]}),(0,N.jsxs)(`button`,{disabled:!!u||T,className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm text-destructive hover:bg-destructive/10 disabled:opacity-50`,onClick:()=>void ue(`discard`,S.row.items),children:[(0,N.jsx)(d,{className:`h-4 w-4`}),`Delete permanently`]})]})]})}function mt({workspaceId:e,workspaceName:t}){let[n,r]=(0,M.useState)([]),[i,a]=(0,M.useState)(new Set),o=t=>`${e}:${t.address}:${t.resyncStartedAt||``}`;(0,M.useEffect)(()=>{let t=!1,n=!1,i=!1,a=0,o=new Map,s=new Map,c=(e,t)=>{let n=e.filter(e=>e.address!==t.backend);if(!t.resyncing)return n;let r=e.find(e=>e.address===t.backend)||s.get(t.backend);return[...n,{address:t.backend,config:r?.config,resyncStartedAt:r?.resyncStartedAt||new Date().toISOString(),progress:t.progress??r?.progress}]},l=async()=>{if(n){i=!0;return}n=!0;let u=a;try{let n=await he(e);if(!t){s=new Map(n.map(e=>[e.address,e]));let e=n.filter(e=>e.resyncing);for(let t of o.values())t.version>u&&(e=c(e,t.event));r(e)}}catch{}finally{n=!1,i&&!t&&(i=!1,l())}},u=t=>{t.workspaceId!==e||!t.backend||typeof t.resyncing!=`boolean`||(o.set(t.backend,{version:++a,event:t}),r(e=>c(e,t)))},d=t=>{t.workspaceId===e&&l()};l();let f=_.on(`connect`,l);return _.on(`backend.resync.changed`,u),_.on(`backend.changed`,d),window.addEventListener(`focus`,l),()=>{t=!0,f?.(),_.off(`backend.resync.changed`,u),_.off(`backend.changed`,d),window.removeEventListener(`focus`,l)}},[e]);let s=n.filter(e=>!i.has(o(e)));return s.length?(0,N.jsxs)(`aside`,{"aria-label":`Storage scans for ${t}`,className:`absolute bottom-5 right-5 z-50 w-72 max-w-[calc(100vw-2.5rem)] rounded-lg border bg-popover/95 p-3 text-popover-foreground shadow-lg backdrop-blur`,children:[(0,N.jsxs)(`div`,{role:`status`,className:`mb-2 flex items-center gap-2 text-sm font-medium`,children:[(0,N.jsx)(ee,{"aria-hidden":`true`,className:`h-4 w-4 animate-spin`}),(0,N.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,N.jsx)(`span`,{className:`block`,children:`Scanning storage`}),(0,N.jsx)(`span`,{className:`block truncate text-xs font-normal text-muted-foreground`,title:t,children:t})]}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Hide scan progress for ${t}`,title:`Hide progress; scanning continues`,className:`rounded p-1 hover:bg-muted focus-visible:outline focus-visible:outline-2`,onClick:()=>a(e=>new Set([...e,...s.map(o)])),children:(0,N.jsx)(c,{"aria-hidden":`true`,className:`h-4 w-4`})})]}),(0,N.jsx)(`div`,{className:`max-h-48 space-y-3 overflow-y-auto`,children:s.map(e=>{let{scanned:t=0,total:n=null}=e.progress||{},r=n&&n>0?Math.min(100,Math.round(t/n*100)):null,i=typeof e.config?.label==`string`?e.config.label:e.address;return(0,N.jsxs)(`div`,{children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,N.jsx)(`span`,{className:`truncate`,children:i}),(0,N.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:n===null?`${t} files`:`${t} / ${n}`})]}),(0,N.jsx)(`div`,{role:`progressbar`,"aria-label":`Scanning ${i}`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":r??void 0,className:`mt-1.5 h-1 overflow-hidden rounded-full bg-muted`,children:(0,N.jsx)(`div`,{className:`h-full rounded-full bg-primary ${r===null?`animate-pulse`:`transition-all`}`,style:{width:r===null?`35%`:`${r}%`}})})]},e.address)})})]}):null}var ht=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:null;function gt(e){return`/${e}`.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`}function _t(e,t,n){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>_t(e,t,n));if(typeof e==`string`)return[{tree:null,kind:t,path:gt(e)}];let r=ht(e);if(!r)return[];let i=r.tree??r.treeId,a=typeof i==`string`?n.get(i)??null:null;return[].concat(r.paths??r.path??`/`).filter(e=>typeof e==`string`).map(e=>({tree:a,kind:t,path:gt(e)}))}function vt(e){let t=[],n=e=>{let n=Number(e);Number.isSafeInteger(n)&&n>0&&t.push(n)};return Array.isArray(e.ids)&&e.ids.forEach(n),Array.isArray(e.documentIds)&&e.documentIds.forEach(n),e.id!=null&&n(e.id),e.documentId!=null&&n(e.documentId),t}function yt(e){let t=new Map;for(let n of e)t.set(n.id,n.name),t.set(n.name,n.name);return t}function bt(e,t,n=new Map){let r=ht(t);if(!r)return{targets:[],ids:[],unknown:!0};if(e.startsWith(`tree.`)){let e=typeof r.treeName==`string`?r.treeName:null,t=r.treeType===`directory`||r.treeType===`context`?r.treeType:null,n=r.contextSpec??r.path;return typeof n==`string`?{targets:[{tree:e,kind:t,path:gt(n)}],ids:vt(r),unknown:!1}:{targets:[],ids:[],unknown:!0}}let i=[..._t(r.context,`context`,n),..._t(r.directory,`directory`,n)],a=ht(r.changed);a&&i.push(..._t(a.context,`context`,n),..._t(a.directory,`directory`,n));let o=vt(r);if(i.length)return{targets:i,ids:o,unknown:!1};let s=r.reason===`content`||r.reason===`relations`||r.reason===`moved`;return(e.startsWith(`document.updated`)||e.startsWith(`document.moved`))&&s&&o.length?{targets:[],ids:o,unknown:!1}:{targets:[],ids:o,unknown:!0}}function xt(e,t){return e===t||e===`/`||t===`/`||e.startsWith(`${t}/`)||t.startsWith(`${e}/`)}function St(e,t){if(e.kind&&e.kind!==t.kind||e.tree&&e.tree!==t.tree)return!1;if(t.kind===`context`){let n=e=>gt(e).split(`/`).filter(Boolean).map(e=>e.normalize(`NFKC`).trim().replace(/\s+/g,` `).replace(/[^\p{L}\p{N}\p{M} .+_@-]/gu,`_`).replace(/_+/g,`_`).toLowerCase()||`_`),r=new Set(n(e.path)),i=n(t.path);return r.size===0||i.length===0||i.some(e=>r.has(e))}return xt(e.path,t.path)}function Ct(e){return bt(`tree.refresh`,{treeName:e?.treeName,path:e?.path||`/`})}function wt(e,t,n){if(e.unknown||e.targets.length&&(t.wholeWorkspace||e.targets.some(e=>St(e,t))))return!0;if(e.ids.length&&n){let t=n instanceof Set?n:new Set(n);if(e.ids.some(e=>t.has(e)))return!0}return!1}function Tt(e,t,n={}){return _.request(j,{workspace:e,specs:t,opts:n})}function Et(e,t,n){return _.request(st,{sessionId:e,label:t,spec:n})}function P(e){return _.request(ct,{sessionId:e})}function Dt(e,t={}){return _.request(lt,{sessionId:e,...t})}function F(e){return _.request(ut,{sessionId:e})}function I(e){return _.on(dt,e)}var L=100;function Ot({workspaceRef:e,specs:t,opts:n,enabled:r=!0}){let[i,a]=(0,M.useState)([]),[o,s]=(0,M.useState)(0),[c,l]=(0,M.useState)(null),[u,d]=(0,M.useState)(null),f=(0,M.useRef)([]),p=(0,M.useRef)(new Map),m=(0,M.useRef)(null),ee=(0,M.useRef)(null),h=(0,M.useRef)(null),g=(0,M.useRef)({}),te=(0,M.useRef)(null),ne=(0,M.useMemo)(()=>JSON.stringify(t),[t]),re=(0,M.useMemo)(()=>JSON.stringify(n??{}),[n]),v=(0,M.useCallback)(()=>{let e=p.current;a(f.current.map(t=>e.get(t)).filter(Boolean))},[]),ie=(0,M.useCallback)(async e=>{let t=ee.current;if(!t||e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=L){let i=e.slice(r,r+L),a=await de(t,`/`,[],{ids:i,scope:`workspace`,limit:i.length});n.push(...a.payload||[])}return n},[]),y=(0,M.useCallback)(async(e,t,n)=>{if(t.length>0){let e=new Set(t);f.current=f.current.filter(t=>!e.has(t));for(let t of e)p.current.delete(t)}let r=e.filter(e=>!p.current.has(e)),i=new Set(f.current);for(let t of e)i.has(t)||(f.current.push(t),i.add(t));if(n!==null&&s(n),v(),r.length===0)return;let a=await ie(r);for(let e of a)p.current.set(e.id,e);let o=new Set(a.map(e=>e.id)),c=r.filter(e=>!o.has(e));if(c.length>0){let e=new Set(c);f.current=f.current.filter(t=>!e.has(t))}v()},[ie,v]),b=(0,M.useCallback)(async(e,t)=>{let n=e??[],r=new Set(n);f.current=f.current.filter(e=>r.has(e));for(let e of p.current.keys())r.has(e)||p.current.delete(e);let i=new Set(f.current),a=n.filter(e=>!i.has(e));await y(a,[],t)},[y]);(0,M.useEffect)(()=>{if(ee.current=e??null,!r||!e)return;let t=!1,n=null,i=async()=>{try{let r=await Tt(e,JSON.parse(ne),JSON.parse(re));if(t){F(r.sessionId).catch(()=>{});return}n=r.sessionId,m.current=r.sessionId,l(r.sessionId),d(null),f.current=[],p.current=new Map,await b(r.ids,r.count)}catch(e){if(t)return;d(e instanceof Error?e.message:`Failed to open query session`),l(null),m.current=null}};i();let o=_.on(`connect`,()=>{i()});return()=>{t=!0,o?.();let e=n??m.current;e&&F(e).catch(()=>{}),m.current=null,f.current=[],p.current=new Map,l(null),a([]),s(0)}},[e,ne,re,r]),(0,M.useEffect)(()=>{if(!c)return;let e=I(e=>{if(e.sessionId===c){if(h.current!==null){te.current?.(h.current,g.current);return}e.ids===void 0?y(e.added??[],e.removed??[],e.count):b(e.ids,e.count)}});return()=>{e?.()}},[c,y,b]);let x=(0,M.useCallback)(async()=>{let e=m.current;if(e)try{let t=await P(e);await b(t.ids,t.count)}catch{}},[b]),ae=(0,M.useCallback)(async(e,t)=>{let n=m.current;if(!n)throw Error(`No open query session`);let r=await Et(n,e,t);if(h.current!==null){await te.current?.(h.current,g.current);return}await b(r.ids,r.count)},[b]),S=(0,M.useCallback)(async(e,t={})=>{let n=m.current;if(!n)throw Error(`No open query session`);if(h.current=e,g.current=t,e===null){await x();return}let r=await Dt(n,{match:e,...t});for(let e of r.documents)p.current.set(e.id,e);f.current=r.ids,s(r.totalCount),v()},[v,x]);(0,M.useEffect)(()=>{te.current=S},[S]);let C=(0,M.useCallback)(async(e,t,n={})=>{let r=m.current;if(!r)throw Error(`No open query session`);let i=await Dt(r,{match:t,limit:n.limit??100,...n.mode?{mode:n.mode}:{}});for(let e of i.documents)p.current.set(e.id,e);let a=await Et(r,e,{ids:i.ids});return await b(a.ids,a.count),i.ids},[b]);return{documents:i,count:o,ready:c!==null,error:u,setCue:ae,resync:x,rank:S,rankAndPin:C}}function kt({data:e,className:t}){let[n,r]=(0,M.useState)(!0),{rows:i,gapIndex:a,span:s}=(0,M.useMemo)(()=>{let t=[...e.distances].sort((e,t)=>e.distance-t.distance),n=[];for(let e=1;e<t.length;e++)n.push(t[e].distance-t[e-1].distance);let r=n.length?[...n].sort((e,t)=>e-t)[Math.floor(n.length/2)]:0,i=-1,a=0;for(let e=0;e<n.length;e++)n[e]>a&&(a=n[e],i=e+1);let o=i>0&&a>=Math.max(r*4,1e-6),s=t[0]?.distance??0,c=t[t.length-1]?.distance??0;return{rows:t,gapIndex:o?i:-1,span:{first:s,last:c,biggest:a,median:r}}},[e.distances]);if(i.length===0)return(0,N.jsxs)(`div`,{className:h(`rounded-md border border-dashed border-border px-3 py-2 text-xs text-muted-foreground`,t),children:[`Query debug: no image distances for “`,e.query,`”. The dense side returned nothing: either no photos are embedded in this scope, or the image space is not ready.`]});let c=a>0?i[a].distance:null;return(0,N.jsxs)(`div`,{className:h(`rounded-md border border-border bg-muted/30 text-xs`,t),children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-1.5 px-3 py-2 text-left font-medium`,children:[n?(0,N.jsx)(o,{className:`h-3.5 w-3.5`}):(0,N.jsx)(u,{className:`h-3.5 w-3.5`}),`Query debug`,(0,N.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`: image distances for “`,e.query,`” (`,i.length,` nearest, unfloored)`]})]}),n&&(0,N.jsxs)(`div`,{className:`space-y-2 border-t border-border px-3 py-2`,children:[(0,N.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Best-first cosine distance (0 = identical). Scroll to where the photos stop being relevant and set the image relevance floor just above that value in Settings → Database → Search tuning.`,c===null?(0,N.jsxs)(N.Fragment,{children:[` `,(0,N.jsx)(`span`,{className:`text-amber-600 dark:text-amber-500`,children:`No boundary in this window`}),`; the distances step evenly (typical Δ`,s.median.toFixed(4),`), so there is nothing here to set a floor from. Relevance probably ends further down the list than this window reaches, or the model is not separating this query at all.`]}):(0,N.jsxs)(N.Fragment,{children:[` A jump at `,(0,N.jsx)(`span`,{className:`font-mono`,children:c.toFixed(4)}),` (Δ`,s.biggest.toFixed(4),`, vs typical Δ`,s.median.toFixed(4),`) stands out (a likely boundary).`]})]}),(0,N.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:(0,N.jsx)(`table`,{className:`w-full font-mono text-[11px]`,children:(0,N.jsx)(`tbody`,{children:i.map((e,t)=>(0,N.jsxs)(`tr`,{className:h(`border-b border-border/40 last:border-0`,t===a&&`border-t-2 border-t-amber-500/70`),children:[(0,N.jsx)(`td`,{className:`py-0.5 pr-3 text-muted-foreground`,children:t+1}),(0,N.jsxs)(`td`,{className:`py-0.5 pr-3`,children:[`#`,e.id]}),(0,N.jsx)(`td`,{className:`py-0.5 tabular-nums`,children:e.distance.toFixed(4)}),t===a&&(0,N.jsx)(`td`,{className:`py-0.5 pl-2 font-sans text-[10px] text-amber-600 dark:text-amber-500`,children:`← biggest gap`})]},e.id))})})}),(0,N.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Range `,s.first.toFixed(4),` – `,s.last.toFixed(4),` (spread `,(s.last-s.first).toFixed(4),`) over `,i.length,` rows. Absolute values shift with the model and are not comparable across models. After a re-embed every floor has to be picked again. A spread this narrow relative to the range means ranking is doing the work, not distance.`]})]})]})}var At=new Map;function jt(e,t,n){return`${e}\0${t}\0${n}`}function Mt(e,t,n,r,i,a,o=``,s=``,c=`path`){return`${jt(e,t,n)}\0${r}\0${i}\0${a}\0${o}\0${s}\0${c}`}function R(e,t,n){let r=jt(e,t,n);for(let e of At.keys())e.startsWith(r)&&At.delete(e)}function Nt(e,t){let n=`${e}\0`;for(let[e,r]of At){if(!e.startsWith(n))continue;let[,i,a,,,,,,o=`path`]=e.split(`\0`);wt(t,{tree:i,kind:O(i),path:a,wholeWorkspace:o.startsWith(`workspace`)},r.documents.map(e=>Number(e.id)))&&At.delete(e)}}function Pt(e,t){Nt(t?.workspaceName??e,Ct(t))}function z(){let{workspaceName:e}=r();return e?(0,N.jsx)(qe,{workspaceName:e,children:(0,N.jsx)(Ft,{})}):null}function Ft(){let{workspaceName:e,treeName:t}=r(),n=a(),o=i(),{showToast:s,showProgress:c}=re(),l=new URLSearchParams(n.search),u=(()=>{let e=l.getAll(`q`).map(e=>e.trim()).filter(Boolean);if(e.length>0)return e;let t=(l.get(`search`)||``).trim();return t?[t]:[]})(),[d,f]=(0,M.useState)(null),[p,m]=(0,M.useState)(!0),[ee,v]=(0,M.useState)([]),[ie,y]=(0,M.useState)(!1),[Te,k]=(0,M.useState)(0),A=ot(),[Oe,ke]=(0,M.useState)(null),[Ae,qe]=(0,M.useState)(A);Ae!==A&&(qe(A),A||ke(null));let[j,st]=(0,M.useState)(`path`),[ct,lt]=(0,M.useState)(!1),ut=Ge(e),[dt,pt]=(0,M.useState)(null),[ht,gt]=(0,M.useState)(``),[_t,vt]=(0,M.useState)(!1),[xt,St]=(0,M.useState)(!1),[Tt,Et]=(0,M.useState)(!1),[P,Dt]=(0,M.useState)(null),[F,I]=(0,M.useState)(1),[L,jt]=(0,M.useState)(50),[z,Ft]=(0,M.useState)(u),[It,Rt]=(0,M.useState)(null),{state:B,saveFilters:zt,setSort:Bt,setAccentColor:Vt,setMapDocuments:Ht}=je(),Ut=B.filters.features.allOf,Wt=B.filters.features.anyOf,Gt=B.filters.features.noneOf,Kt=Fe(B.filters.timeline),qt=Pe(B.filters.geo),Jt=Le(B.filters.lens,B.filters.geo.includeUnlocated),V=B.filters.lens.ids,Yt=[...Kt,...qt,...Jt],Xt=B.filters.sort??Ie,Zt=JSON.stringify({a:Ut,b:Wt,c:Gt,d:Yt,i:V,s:Xt}),Qt=JSON.stringify({a:Ut,b:Wt,c:Gt,d:Yt,s:Xt}),H=Re(n.pathname).path,U=t??`context`,W=U===`backends`,[$t,en]=(0,M.useState)([]);(0,M.useEffect)(()=>{!W||!e||he(e).then(en).catch(()=>en([]))},[W,e]);let tn=W?ce(H,$t):null,[nn,rn]=(0,M.useState)(!1),an=`${U}\0${H}`,[on,sn]=(0,M.useState)(an);on!==an&&(sn(an),rn(!1));let G=l.get(`layer`)===`1`,K=l.get(`layerId`)||null,[q,cn]=(0,M.useState)(null),[J,ln]=(0,M.useState)(null),un=(0,M.useRef)(null);(0,M.useEffect)(()=>{un.current=J},[J]);let[dn,fn]=(0,M.useState)(`left`),[pn,mn]=(0,M.useState)([]),{openM1Drawer:hn,openM2Drawer:gn,goBack:_n}=Ve(),[vn,yn]=(0,M.useState)([]),Y=(0,M.useMemo)(()=>{if(!q||H===`/`||G)return null;let e=H.split(`/`).filter(Boolean),t=q;for(let n of e)if(t=t?.children?.find(e=>e.name===n)??null,!t)return null;return t},[q,H,G]),X=Y?.type===`canvas`?`canvas`:null,bn=(0,M.useRef)(null);(0,M.useEffect)(()=>{!e||!q||G||bn.current===`${e}/${U}`&&(H!==`/`&&!Y||He(e,U,H))},[e,q,G,H,Y,U]);let xn=(0,M.useMemo)(()=>G||j===`workspace`||z.length>0?[]:rt(q,H),[q,H,G,j,z]),Sn=G?null:H===`/`?q:Y,Z=De(),Cn=`${U}\0${H}`,[wn,Tn]=(0,M.useState)(null),En=wn?.key===Cn?wn.views:nt(Sn?.metadata),Dn=Z?.pinned&&Z.view?[Z.view,...En.filter(e=>e.id!==Z.view.id)]:En,On=Z?.pinned&&Z.view?Z.view.id:wn?.key===Cn?wn.activeId:Dn[0]?.id??Ye.id,Q=Dn.find(e=>e.id===On)??Dn[0]??Ye;(0,M.useEffect)(()=>{Z?.selectView(Q)},[Q,Z]);let kn=W?void 0:Z?.schema??et(Q),An=kn?[...Ut,kn]:Ut;it(Qe({workspace:e??null,treeNameOrId:U,treeType:O(U),path:H,scope:j===`workspace`?`workspace`:G?`layer`:`path`,layerId:G?K:void 0,unfiledOnly:nn},{...B.filters,features:{...B.filters.features,allOf:An}},B.geoSelection,z));let jn=e=>{let t=Dn.find(t=>t.id===e);t&&Z?.selectView(t),I(1),mn([]),Tn({key:Cn,views:Dn,activeId:e})},Mn=(t,n)=>{n&&n!==On&&(I(1),mn([]));let r=t.find(e=>e.id===(n??On));r&&Z?.selectView(r),Tn({key:Cn,views:t,activeId:n??On}),E(e,H,{metadata:{...Sn?.metadata??{},views:t}},U).catch(()=>{s({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},Nn=X===`canvas`&&typeof Y?.querySpec?.query==`string`?Y.querySpec.query:``,Pn=X===`canvas`?{label:Y?.label,description:Y?.description,color:Y?.color}:null,{isPinned:Fn,pin:In,unpin:Ln,pins:Rn}=be(),zn=d?.name,Bn=(0,M.useMemo)(()=>zn&&X===`canvas`&&!G?{workspaceName:zn,treeName:U,path:H}:null,[zn,X,G,U,H]),Vn=Bn?Fn(Bn):!1,Hn=Y?.id,Un=Y?.label,Wn=(0,M.useCallback)(async()=>{if(Bn)try{let e=Rn.find(e=>e.workspaceName===Bn.workspaceName&&e.treeName===Bn.treeName&&e.path===Bn.path);e?await Ln(e.id):await In({...Bn,layerId:Hn,label:Un})}catch(e){console.error(`Failed to update home pins:`,e)}},[Bn,Rn,In,Ln,Hn,Un]),Gn=e?`${e}://${H===`/`?``:H.replace(/^\//,``)}`:``,Kn=Me(d?.color)||null;(0,M.useEffect)(()=>(Vt(Kn),()=>Vt(null)),[Kn,Vt]);let qn=(0,M.useCallback)(async t=>{let n=V;if(t?.anyOf?.length&&Wt.length&&(n=((await ae(e,H,U,{limit:0,anyOf:Wt,ids:V,applyCanvasSpec:!1})).payload||[]).map(e=>e.id),!n.length))return{payload:[],count:0,totalCount:0};let r=await ae(e,H,U,{limit:t?.limit,offset:t?.offset,page:t?.page,sortBy:t?.sortBy,order:t?.order,allOf:[...Ut,...t?.allOf??[]],anyOf:t?.anyOf?.length?t.anyOf:Wt,noneOf:Gt,filters:Yt,ids:n,queries:[...z,...t?.queries??[],...t?.q?[t.q]:[]],applyCanvasSpec:!1});return{payload:r.payload||[],count:r.count??void 0,totalCount:r.totalCount??void 0}},[e,H,U,Zt,z]);(0,M.useEffect)(()=>{e&&(async()=>{m(!0);try{let t=await ne.get(`${te.workspaces}/${e}`),n;n=t&&`workspace`in t?t.workspace:t,f(n)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch workspace ${e}`;s({title:`Error`,description:n,variant:`destructive`}),f(null)}finally{m(!1)}})()},[e,s]),(0,M.useEffect)(()=>{let e=e=>{let t=e.detail?.workspace;t&&f(e=>e&&(t===e.name||t===e.id)&&e.status!==`active`?{...e,status:`active`}:e)};return window.addEventListener(`workspace:autostarted`,e),()=>window.removeEventListener(`workspace:autostarted`,e)},[]);let Jn=(V?.length??0)>0&&!G&&!(nn&&tn)&&z.length<=1,{documents:Yn,count:Xn,ready:Zn,setCue:Qn,resync:$n,rank:er}=Ot({workspaceRef:e,specs:(0,M.useMemo)(()=>{let e={features:{allOf:An,anyOf:Wt,noneOf:Gt},filters:Yt};return j!==`workspace`&&(O(U)===`directory`?e.directory={tree:U,path:H}:e.context=H),[{label:`scope`,spec:e}]},[Qt,H,U,j,kn]),opts:(0,M.useMemo)(()=>({mode:`live`,debounceMs:150}),[]),enabled:Jn}),tr=Jn&&Zn,nr=(0,M.useRef)(!1);(0,M.useEffect)(()=>{nr.current=tr},[tr]);let rr=z.length===1?z[0].trim():``;(0,M.useEffect)(()=>{Zn&&er(rr?{text:rr}:null,{limit:L,offset:(F-1)*L}).catch(()=>{})},[Zn,rr,L,F,er]);let ir=(V??[]).join(`,`);(0,M.useEffect)(()=>{Zn&&Qn(`lens`,{ids:V??[]}).catch(()=>{})},[Zn,ir,Qn,V]);let ar=tr?Yn:ee,or=tr?Xn:Te,sr=(0,M.useRef)(new Set);(0,M.useEffect)(()=>{sr.current=new Set(ar.map(e=>Number(e.id)))},[ar]);let cr=B.geoSelection;(0,M.useEffect)(()=>{Ht(ar,d?.name??null)},[ar,d?.name,Ht]),(0,M.useEffect)(()=>()=>Ht([]),[Ht]);let lr=(0,M.useMemo)(()=>cr?ar.filter(e=>Ne(e,cr,B.filters.geo.includeUnlocated)):ar,[ar,cr,B.filters.geo.includeUnlocated]),ur=me(H,An,{treeName:U,treeType:O(U),scope:j,queries:z,anyOf:Wt,noneOf:Gt,filters:Yt,ids:V,layerId:G&&K?K:void 0}),dr=JSON.stringify([e,ur]),[fr,pr]=(0,M.useState)(``),[mr,hr]=(0,M.useState)(!1),gr=(0,M.useRef)(!1),_r=ie||mr||fr!==dr||tr||!!cr,vr=(0,M.useRef)(0),yr=(0,M.useRef)(null);(0,M.useEffect)(()=>()=>{vr.current++,yr.current=null},[]);let br=(0,M.useRef)(``),$=(0,M.useCallback)(async t=>{if(!e)return;if(Ee(U,H)){vr.current++,yr.current=null,br.current=``,v([]),k(0),y(!1);return}if(nr.current)return;let n=`${nn&&tn?`${j}:unfiled`:j}:${kn??``}`,r=(V?.length??0)>0,i=Mt(e,U,H,F,L,z.join(`␟`),Qt,G&&K?K:``,n),a=r&&i===br.current;br.current=i;let o=Mt(e,U,H,F,L,z.join(`␟`),Zt,G&&K?K:``,n),c=`${o}\0${A}`;if(t?.silent&&yr.current?.key===c){yr.current.refreshPending=!0;return}let l=++vr.current,u=t?.silent||r||A?void 0:At.get(o);u&&(v(u.documents),k(u.totalCount),pr(dr),y(!1)),(t?.silent??(a||!!u))||y(!0);let d={key:c,refreshPending:!1};yr.current=d;try{let t;if(nn&&tn)t=await le(e,tn.driver,tn.address,{linked:!1,limit:L,offset:(F-1)*L});else if(G&&K&&j!==`workspace`)t=await pe(e,U,K,{limit:L,page:F,queries:z,allOf:An,anyOf:Wt,noneOf:Gt,filters:Yt,ids:V,sortBy:Xt.sortBy||void 0,order:Xt.order});else{let n=O(U);t=await de(e,H,An,{limit:L,page:F,treeName:U,treeType:n,queries:z,anyOf:Wt,noneOf:Gt,filters:Yt,ids:V,sortBy:Xt.sortBy||void 0,order:Xt.order,scope:j,debug:A&&z.length>0,debugLimit:200})}let n=t.payload||[],i=t.totalCount||t.count||0;if(!r&&!d.refreshPending&&At.set(o,{documents:n,totalCount:i}),l!==vr.current)return;let s=t.debug,c=s?.imageDistances??s?.distances??null;ke(c?{query:z[z.length-1]??``,distances:c}:null),v(a?e=>e.length===n.length&&e.every((e,t)=>e.id===n[t].id)?e:n:n),k(i),pr(dr)}catch(e){if(l!==vr.current)return;let t=e instanceof Error?e.message:`Failed to fetch documents`;s({title:`Error`,description:t,variant:`destructive`}),v([]),k(0)}finally{yr.current===d&&(yr.current=null),l===vr.current&&y(!1),l===vr.current&&d.refreshPending&&$({silent:!0})}},[e,H,U,K,G,F,L,d?.status,z,Zt,j,nn,A,kn]);(0,M.useEffect)(()=>{$()},[$]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;!n||n.workspaceName!==e||(ln({treeName:n.treeName||`context`,path:ze(n.path||`/`)}),fn(`left`))};return window.addEventListener(`workspace:open-to-side`,t),()=>window.removeEventListener(`workspace:open-to-side`,t)},[e,U,H]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;if(!(n?.workspaceName&&n.workspaceName!==e)&&(e&&Pt(e,n),wt(Ct(n),{tree:U,kind:O(U),path:H,wholeWorkspace:j===`workspace`}))){if(e&&R(e,U,H),nr.current){$n();return}$({silent:!0})}};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[$,e,H,U,j,$n]);let xr=d?.name,Sr=d?.id;(0,M.useEffect)(()=>{if(!e||!xr&&!Sr)return;let t=[xr,Sr].filter(Boolean).map(e=>`workspace:${e}`),n=()=>t.forEach(e=>_.emit(`subscribe`,{channel:e}));n();let r=_.on(`connect`,n),i=new Map,a=!1,o=()=>{b(e).then(e=>{a||(i=yt(e))}).catch(()=>{})};o();let s=null,c=0,l=!1,u=null,d=()=>{if(s=null,c=Date.now(),u){let{treeName:t,path:n}=u;u=null,window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,treeName:t,path:n}}))}if(l){if(l=!1,nr.current){$n();return}$({silent:!0})}},f=t=>n=>{(t.startsWith(`tree.created`)||t.startsWith(`tree.renamed`))&&o();let r=bt(t,n,i);Nt(e,r);let a={tree:U,kind:O(U),path:H,wholeWorkspace:j===`workspace`},f=un.current;f&&wt(r,{tree:f.treeName,kind:O(f.treeName),path:f.path})&&(u=f),wt(r,a,sr.current)&&(l=!0),!(!l&&!u)&&(s||=setTimeout(d,Math.max(200,c+1500-Date.now())))},p=[`document.inserted`,`document.inserted.batch`,`document.updated`,`document.moved`,`document.moved.batch`,`document.removed`,`document.deleted`,`document.removed.batch`,`document.deleted.batch`,`document.linked`,`document.unlinked`,`document.linked.batch`,`document.unlinked.batch`,`tree.document.inserted`,`tree.document.inserted.batch`,`tree.document.removed`,`tree.document.removed.batch`,`tree.document.deleted`,`tree.document.deleted.batch`,`tree.layer.merged`,`tree.layer.subtracted`,`tree.created`,`tree.renamed`].map(e=>[e,f(e)]);return p.forEach(([e,t])=>_.on(e,t)),()=>{a=!0,s&&clearTimeout(s),r?.(),p.forEach(([e,t])=>_.off(e,t))}},[e,Sr,xr,U,H,j,$,$n]);let Cr=`${H}\0${U}\0${K??``}\0${j}`,[wr,Tr]=(0,M.useState)(Cr);wr!==Cr&&(Tr(Cr),I(1),Rt(null));let Er=`${H}\0${U}\0${K??``}`,[Dr,Or]=(0,M.useState)(Er);Dr!==Er&&(Or(Er),st(`path`));let kr=(e,t)=>{let n=e===`/`?`canvas`:e.split(`/`).pop()||`canvas`;gt(n),pt({parentPath:e,captureView:t})},Ar=l.get(`createCanvas`)===`1`,[jr,Mr]=(0,M.useState)(!1);jr!==Ar&&(Mr(Ar),Ar&&kr(H,!1)),(0,M.useEffect)(()=>{if(!Ar)return;let e=new URLSearchParams(n.search);e.delete(`createCanvas`);let t=e.toString();o(`${n.pathname}${t?`?${t}`:``}${n.hash}`,{replace:!0})},[Ar,H]);let Nr=(0,M.useCallback)(e=>{let t=new URLSearchParams(n.search);t.delete(`q`),t.delete(`search`);for(let n of e)t.append(`q`,n);let r=t.toString();o(`${n.pathname}${r?`?${r}`:``}${n.hash}`)},[n.pathname,n.search,n.hash,o]),Pr=JSON.stringify([l.has(`q`),...u]),[Fr,Ir]=(0,M.useState)(Pr);Fr!==Pr&&(Ir(Pr),Ft(u),I(1));let Lr=`${Pr}\0${X??``}\0${Nn}\0${H}\0${It??``}`,[Rr,zr]=(0,M.useState)(Lr);Rr!==Lr&&(zr(Lr),l.has(`q`)||u.length>0||X!==`canvas`||It===H||(Ft(Nn?[Nn]:[]),I(1)));let Br=(0,M.useCallback)(e=>{let t=e.trim();t&&(Rt(null),Ft(e=>{if(e.includes(t))return e;let n=[...e,t];return Nr(n),I(1),n}))},[Nr,Rt,Ft,I]),Vr=(0,M.useCallback)(e=>{Ft(t=>{let n=e<0?[]:t.filter((t,n)=>n!==e);return n.length===0&&Rt(H),Nr(n),I(1),n})},[Nr,H,Rt,Ft,I]),Hr=z.join(` `).trim(),Ur=!!B.activeContextType&&(B.isDirty||Hr!==(X===`canvas`?Nn:B.savedSearchQuery||``));!e&&q!==null&&cn(null),(0,M.useEffect)(()=>{let t=!1;if(!e)return;let n=0,r=!1,i=(i=!1)=>{let a=++n;i&&ue(e,U),oe(e,U).then(i=>{!t&&a===n&&(r=!0,bn.current=`${e}/${U}`,cn(i))}).catch(()=>{!t&&a===n&&!r&&cn(null)})};i(!1);let a=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==U||i(!n?.cacheInvalidated)};window.addEventListener(`workspace:tree:refresh`,a);let o=Ce(e,Sr);return()=>{t=!0,o(),window.removeEventListener(`workspace:tree:refresh`,a)}},[e,U,Sr]),!(e&&X===`canvas`&&!G)&&P!==null&&Dt(null),(0,M.useEffect)(()=>{let t=!1;if(!(!e||X!==`canvas`||G))return se(e,H,U).then(e=>{t||Dt(e)}).catch(()=>{t||Dt(null)}),()=>{t=!0}},[e,H,U,X,G]);let Wr=async()=>{if(d){lt(!0);try{let t=await fe(e||d.id);f(t),s({title:`Success`,description:`Workspace started successfully`}),window.dispatchEvent(new CustomEvent(`workspaces:refresh`))}catch(e){let t=e instanceof Error?e.message:`Failed to start workspace`;s({title:`Error`,description:t,variant:`destructive`})}finally{lt(!1)}}},Gr=async t=>{if(!d)return;let n=c({title:`Removing…`,description:`Document from "${H}"`});try{await S(e||d.id,[t],H,[],U,$r,{trashIfOrphaned:!0}),R(e||d.id,U,H),v(e=>e.filter(e=>e.id!==t)),k(e=>Math.max(0,e-1)),n.done({title:`Success`,description:`Document removed from workspace path.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},Kr=async t=>{if(!d)return;let n=c({title:`Deleting…`,description:`Document from "${H}"`});try{await ge(e||d.id,[t],H,[],U,$r),R(e||d.id,U,H),v(e=>e.filter(e=>e.id!==t)),k(e=>Math.max(0,e-1)),n.done({title:`Success`,description:`Document deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},qr=async t=>{if(!d)return;let n=c({title:`Removing…`,description:`${t.length} document(s) from "${H}"`});try{await S(e||d.id,t,H,[],U,$r,{trashIfOrphaned:!0}),R(e||d.id,U,H),v(e=>e.filter(e=>!t.includes(e.id))),k(e=>Math.max(0,e-t.length)),n.done({title:`Success`,description:`${t.length} document(s) removed.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},Jr=async t=>{if(!d)return;let n=c({title:`Deleting…`,description:`${t.length} document(s)`});try{await ge(e||d.id,t,H,[],U,$r),R(e||d.id,U,H),v(e=>e.filter(e=>!t.includes(e.id))),k(e=>Math.max(0,e-t.length)),n.done({title:`Success`,description:`${t.length} document(s) deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},Yr=async t=>{if(!d)return;let n=c({title:`Destroying…`,description:`Document and its backend copies`});try{let r=await x(e||d.id,[t]);if(r.failed?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}v(e=>e.filter(e=>e.id!==t)),k(e=>Math.max(0,e-1)),n.done({title:`Destroyed`,description:`Document removed from all backends.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy document`,variant:`destructive`})}},Xr=async t=>{if(!d)return;let n=c({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await x(e||d.id,t),i=new Set(r.successful?.filter(e=>e.docDeleted).map(e=>e.id)??[]);v(e=>e.filter(e=>!i.has(e.id))),k(e=>Math.max(0,e-i.size));let a=[r.successful?.length?`${r.successful.length} destroyed`:null,r.failed?.length?`${r.failed.length} failed`:null].filter(Boolean).join(`, `);r.failed?.length?n.fail({title:`Destroy incomplete`,description:a,variant:`destructive`}):n.done({title:`Destroyed`,description:a||`No documents destroyed`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy documents`,variant:`destructive`})}},Zr=t=>{e&&(We({workspaceName:e,documentIds:t,operation:`copy`,sourcePath:H,sourceTreeName:U}),s({title:`Copied`,description:`${t.length} document(s) copied to clipboard`}))},Qr=t=>{e&&(We({workspaceName:e,documentIds:t,operation:`cut`,sourcePath:H,sourceTreeName:U}),s({title:`Cut`,description:`${t.length} document(s) cut to clipboard`}))},$r=O(U),ei=async(t,n,r={})=>{if(!e)return!1;let i=r.targetTreeName??U,a=r.targetTreeType??$r,o=r.move??ut?.operation===`cut`,s=r.sourceTreeName||ut?.sourceTreeName,l=r.sourcePath||ut?.sourcePath,u=c({title:o?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let c=await Ke(e,{treeName:i,treeType:a,path:t},n,{move:o,sourcePath:l,sourceTreeName:s});return R(e,i,t),o&&l&&s&&R(e,s,l),u.done({title:`Success`,description:c}),r.move===void 0&&We(null),await $(),!0}catch(e){return u.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},ti=async(t,n)=>{if(!e)return!1;try{let r=(await D(e,n,t,U,$r)).length>0;return r&&(we(e,U,n),s({title:`Success`,description:`Imported ${t.length} document(s) to "${n}"`})),r}catch(e){return s({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},ni=async()=>{if(!d||or===0||_r||gr.current||window.prompt(`Type PURGE to permanently delete all ${or} matching documents across all pages.`)!==`PURGE`)return;gr.current=!0,hr(!0);let t=c({title:`Purging…`,description:`${or} matching document(s)`});try{let n=await ye(e||d.id,ur,or);n.deleted===n.requested?t.done({title:`Success`,description:`${n.deleted} document(s) purged.`}):t.fail({title:`Purge incomplete`,description:`${n.deleted} of ${n.requested} document(s) purged. Refresh and review the remaining results before retrying.`})}catch(e){t.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to purge documents`,variant:`destructive`})}finally{R(e||d.id,U,H),await $({silent:!0}),gr.current=!1,hr(!1)}},ri=()=>kr(H,!0),ii=async()=>{if(!(!e||!dt||!ht.trim())){vt(!0);try{let t=ht.trim(),n=dt.parentPath,r=n===`/`?`/${t}`:`${n}/${t}`,i={...B.filters,features:{...B.filters.features,allOf:An}};await ve(e,r,U,dt.captureView?{metadata:{toolbox:i},querySpec:{features:i.features,filters:[...Fe(B.filters.timeline),...Pe(B.filters.geo)],query:Hr||void 0,sort:B.filters.sort?.sortBy?B.filters.sort:null}}:{}),pt(null),ue(e,U);try{let t=await oe(e,U,{force:!0});cn(t)}catch{}window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e}})),o(Be(e,r,U))}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to create canvas`,variant:`destructive`})}finally{vt(!1)}}},ai=async()=>{if(!(!e||X!==`canvas`)){St(!0);try{let t=P||await T(e,H,U);Dt(t);let n=`${window.location.origin}${t.url}`;await navigator.clipboard?.writeText(n),s({title:`Public canvas link copied`,description:n})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to share canvas`,variant:`destructive`})}finally{St(!1)}}},oi=async()=>{if(P){St(!0);try{await _e(P.code),Dt(null),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:U}})),s({title:`Canvas unshared`,description:`The public link no longer works.`})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to unshare canvas`,variant:`destructive`})}finally{St(!1)}}},si=async()=>{if(!e||X!==`canvas`||H===`/`)return;let t=Pn?.label||H.split(`/`).pop()||`canvas`,n=P?` Its public link will stop working.`:``;if(window.confirm(`Delete canvas "${t}"? This cannot be undone.${n}`)){Et(!0);try{if(P)await _e(P.code),Dt(null);else if(Y?.locked){s({title:`Canvas is locked`,description:`Unlock it before deleting.`,variant:`destructive`});return}await C(e,H,!1,U);let n=H.split(`/`).filter(Boolean);n.pop();let r=n.length?`/${n.join(`/`)}`:`/`;window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:U}})),o(Be(e,r,U)),s({title:`Canvas deleted`,description:`"${t}" was removed.`})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to delete canvas`,variant:`destructive`})}finally{Et(!1)}}},ci=(0,M.useCallback)(async t=>{if(!e||!J)return;let n={treeName:U,path:H},r=dn===`left`?n:J,i=dn===`left`?J:n,a=dn===`left`?pn:vn;if(a.length===0){s({title:`Nothing selected`,description:`Tick documents in the focused pane first.`});return}let o=O(i.treeName),l=c({title:t?`Moving…`:`Copying…`,description:`${a.length} document(s) → "${i.path}"`});try{if(!await w(e,i.path,a,i.treeName,o)){l.done();return}if(R(e,i.treeName,i.path),t){let t=O(r.treeName);await S(e,a,r.path,[],r.treeName,t),R(e,r.treeName,r.path)}[r,i].forEach(t=>window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t.path,treeName:t.treeName}}))),l.done({title:t?`Moved`:`Copied`,description:`${a.length} document(s) → "${i.path}"`})}catch(e){l.fail({title:`Error`,description:e instanceof Error?e.message:`Transfer failed`,variant:`destructive`})}},[e,J,dn,U,H,pn,vn,s,c]);if((0,M.useEffect)(()=>{if(!J)return;let e=e=>{if(e.key!==`F5`&&e.key!==`F6`)return;let t=e.target;t.tagName!==`INPUT`&&t.tagName!==`TEXTAREA`&&(e.preventDefault(),ci(e.key===`F6`))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[J,ci]),p)return(0,N.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,N.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,N.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,N.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading workspace...`})]})});if(!d)return(0,N.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Workspace not found.`});let li=X===`canvas`&&!G&&!!Y,ui=!li&&!W&&Sn?(0,N.jsx)(Ze,{views:Dn,activeId:On,onSelect:jn,onSave:Mn,accentColor:Me(d.color),onOpenToSide:e=>{ln({treeName:U,path:H,viewId:e}),fn(`right`)}}):void 0,di=tn||d.status!==`active`?(0,N.jsxs)(N.Fragment,{children:[tn&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>{rn(!nn),I(1)},"aria-pressed":nn,className:h(`min-h-10 rounded-md border px-2 text-xs`,nn&&`bg-warning/15 text-warning`),children:`Unfiled only`}),d.status!==`active`&&(0,N.jsx)(`button`,{type:`button`,onClick:Wr,disabled:ct,className:`min-h-10 rounded-md border px-2 text-xs`,children:ct?`Starting…`:`Start`})]}):void 0,fi=Ee(U,H)?H===`/Trash`?(0,N.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,N.jsx)(at,{workspaceName:e||d.id})}):(0,N.jsx)(ft,{workspace:e||d.id,path:H,onNavigate:t=>o(Be(e,t,`backends`))},e):(0,N.jsx)(Xe,{navigationTabs:ui,navigationActions:di,onBack:_n,accentColor:Me(d.color),urlType:G?O(U)===`directory`?`${U}-layer`:`context-layer`:X===`canvas`?`canvas`:O(U)===`directory`?U:`context`,urlDisplay:Gn,contextPath:H,treeName:U,workspaceId:e||d.id,workspaceLabel:d.label||d.name,workspaceIcon:d.icon,documentSchema:kn,documents:lr,isLoading:ie,totalCount:or,currentPage:F,pageSize:L,onPageChange:I,onPageSizeChange:e=>{jt(e),I(1)},onRemoveDocument:H===`/`?void 0:Gr,onDeleteDocument:Kr,onDestroyDocument:Yr,onRemoveDocuments:H===`/`?void 0:qr,onDeleteDocuments:Jr,onDestroyDocuments:Xr,onCopyDocuments:Zr,onCutDocuments:Qr,onPasteDocuments:ei,onImportDocuments:W?void 0:ti,onSelectionChange:mn,onBrowseTree:()=>gn(`workspaces`,`detail`,e??null),onBrowseWorkspaces:()=>hn(`workspaces`),onNavigatePath:t=>o(Be(e,t,U)),folders:xn,onOpenFolder:t=>o(Be(e,ze(t),U)),scope:j,onScopeChange:st,pastedDocumentIds:ut?.documentIds,linkTree:q,onPurgeDocuments:W?void 0:ni,disablePurgeDocuments:_r,canvasInfo:Pn??void 0,isCanvasPinned:Vn,onTogglePinCanvas:Bn?Wn:void 0,onSaveAsCanvas:q&&X!==`canvas`&&!G&&!W?ri:void 0,onShareCanvas:X===`canvas`&&!G?ai:void 0,onUnshareCanvas:P?oi:void 0,onDeleteCanvas:X===`canvas`&&!G?si:void 0,isSharingCanvas:xt,isDeletingCanvas:Tt,isCanvasShared:!!P,isCanvasLocked:!!Y?.locked,backendSearchQueries:z,onBackendSearch:Br,serverSort:B.filters.sort,onServerSortChange:Bt,onRemoveBackendQuery:Vr,canSaveChanges:Ur,isSavingChanges:B.isSaving,onSaveChanges:zt,contentBanner:A&&Oe?(0,N.jsx)(kt,{data:Oe,className:`mb-3`}):null,children:li&&Y?(0,N.jsx)(xe,{workspaceId:e||d.id,treeName:U,path:H,layerId:Y.id,querySpec:Y.querySpec,metadata:Y.metadata,isLocked:!!Y.locked,fetchDocuments:B.isDirty?qn:void 0}):!W&&Q.kind===`columns`?(0,N.jsx)(tt,{documents:lr,workspaceId:e||d.id,columns:Q.columns??[],onColumnsChange:e=>Mn(Dn.map(t=>t.id===Q.id?{...t,columns:e}:t))}):!W&&Q.kind===`app`&&Q.app&&Q.app!==`notes`?(0,N.jsx)($e,{app:Q.app,workspaceId:e||d.id,treeName:U,path:H}):null});return(0,N.jsxs)(Ue,{workspaceId:e||d.id,treeName:U,path:H,headerOnly:!0,className:`relative flex flex-col h-full min-h-0`,children:[(0,N.jsx)(mt,{workspaceId:d.id,workspaceName:d.label||d.name},d.id),Ee(U,H)&&(0,N.jsx)(Se,{workspace:d.label||d.name,workspaceIcon:d.icon,tree:U,path:H,onBack:_n,onBrowseTree:()=>gn(`workspaces`,`detail`,e||d.id),onBrowseWorkspaces:()=>hn(`workspaces`),onNavigatePath:t=>o(Be(e,t,U)),accentColor:Me(d.color)}),dt&&(0,N.jsx)(`div`,{className:`shrink-0 px-2 pt-2`,children:(0,N.jsx)(Je,{title:`New canvas`,onClose:()=>pt(null),children:(0,N.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ii()},className:`space-y-4`,children:[(0,N.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`canvas-name`,className:`mb-1 block text-sm font-medium`,children:`Name`}),(0,N.jsx)(`input`,{id:`canvas-name`,className:`w-full rounded-md border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:`Canvas name…`,value:ht,onChange:e=>gt(e.target.value),onKeyDown:e=>{e.key===`Escape`&&pt(null)},autoFocus:!0})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`span`,{className:`mb-1 block text-sm font-medium`,children:`Parent path`}),(0,N.jsx)(`div`,{className:`flex h-10 items-center rounded-md bg-muted px-3 font-mono text-sm text-muted-foreground`,children:dt.parentPath===`/`?`/`:dt.parentPath})]})]}),(0,N.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,N.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:dt.captureView,onChange:e=>pt({...dt,captureView:e.target.checked})}),(0,N.jsxs)(`span`,{children:[`Capture the current view`,(0,N.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Freezes the active filters, search and sort into the canvas.`})]})]}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(g,{type:`submit`,disabled:!ht.trim()||_t,children:_t?`Creating…`:`Create canvas`}),(0,N.jsx)(g,{type:`button`,variant:`outline`,onClick:()=>pt(null),children:`Cancel`})]})]})})}),(0,N.jsxs)(`div`,{"data-canvas-panes":!0,className:`flex-1 min-h-0 flex gap-2`,children:[(0,N.jsx)(`div`,{"data-canvas-pane":!0,className:h(`flex-1 min-w-0 bg-background overflow-hidden`,J&&(dn===`left`?`ring-2 ring-primary`:`ring-1 ring-primary/20`)),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||fn(`left`)},children:fi}),J&&e&&(0,N.jsx)(Lt,{workspaceName:e,workspaceLabel:d.label||d.name,workspaceIcon:d.icon,pane:J,isFocused:dn===`right`,onFocus:()=>fn(`right`),onSelectionChange:yn,onNavigate:e=>ln(t=>t&&{...t,path:e,viewId:void 0}),onClose:()=>{ln(null),fn(`left`),yn([])}})]})]})}function It(e,t){if(!e||t===`/`)return e;let n=e;for(let e of t.split(`/`).filter(Boolean))if(n=n?.children?.find(t=>t.name===e)??null,!n)return null;return n}function Lt({workspaceName:e,workspaceLabel:t,workspaceIcon:n,pane:r,isFocused:i=!1,onFocus:a,onSelectionChange:o,onNavigate:s,onClose:c}){let{openM1Drawer:l,openM2Drawer:u}=Ve(),{showToast:d,showProgress:f}=re(),[p,m]=(0,M.useState)(null),[ee,g]=(0,M.useState)([]),[te,ne]=(0,M.useState)(!1),[_,v]=(0,M.useState)(0),[ie,y]=(0,M.useState)(1),[b,ae]=(0,M.useState)(50),C=O(r.treeName),w=It(p,r.path),se=w?.type===`canvas`,T=(0,M.useMemo)(()=>rt(p,r.path),[p,r.path]),E=r.viewId?nt(w?.metadata).find(e=>e.id===r.viewId)??null:null,ce=`${e}://${r.path===`/`?``:r.path.replace(/^\//,``)}`,le=et(E),D=(0,M.useCallback)(async()=>{if(Ee(r.treeName,r.path)){g([]),v(0),ne(!1);return}let t=Mt(e,r.treeName,r.path,ie,b,``,le??``),n=At.get(t);if(n){g(n.documents),v(n.totalCount);return}ne(!0);try{let n=await de(e,r.path,le?[le]:[],{limit:b,page:ie,treeName:r.treeName,treeType:C}),i=n.payload||[],a=n.totalCount||n.count||0;g(i),v(a),At.set(t,{documents:i,totalCount:a})}catch(e){d({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch side pane documents`,variant:`destructive`}),g([]),v(0)}finally{ne(!1)}},[e,r.path,r.treeName,C,b,ie,d,le]);(0,M.useEffect)(()=>{let t=!1,n=0,i=!1,a=(a=!1)=>{let o=++n;a&&ue(e,r.treeName),oe(e,r.treeName).then(e=>{!t&&o===n&&(i=!0,m(e))}).catch(()=>{!t&&o===n&&!i&&m(null)})};a(!1);let o=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==r.treeName||a(!n?.cacheInvalidated)};return window.addEventListener(`workspace:tree:refresh`,o),()=>{t=!0,window.removeEventListener(`workspace:tree:refresh`,o)}},[e,r.treeName]),(0,M.useEffect)(()=>{D()},[D]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||(Pt(e,n),wt(Ct(n),{tree:r.treeName,kind:O(r.treeName),path:r.path})&&(R(e,r.treeName,r.path),D()))};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[D,e,r.treeName,r.path]);let fe=Ge(e),pe=(0,M.useCallback)(async(t,n,i={})=>{let a=i.targetTreeName??r.treeName,o=i.targetTreeType??C,s=i.move??fe?.operation===`cut`,c=i.sourcePath||fe?.sourcePath,l=i.sourceTreeName||fe?.sourceTreeName,u=f({title:s?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let r=await Ke(e,{treeName:a,treeType:o,path:t},n,{move:s,sourcePath:c,sourceTreeName:l});return R(e,a,t),s&&c&&l&&R(e,l,c),u.done({title:`Success`,description:r}),i.move===void 0&&We(null),await D(),!0}catch(e){return u.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},[e,r.treeName,C,D,f,fe]),me=(0,M.useCallback)(()=>{R(e,r.treeName,r.path),D()},[e,r.treeName,r.path,D]),he=(0,M.useCallback)(async t=>{let n=f({title:`Removing…`,description:`${t.length} document(s) from "${r.path}"`});try{await S(e,t,r.path,[],r.treeName,C),me(),n.done({title:`Removed`,description:`${t.length} document(s) removed from "${r.path}"`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},[e,r.path,r.treeName,C,me,f]),_e=(0,M.useCallback)(async t=>{let n=f({title:`Deleting…`,description:`${t.length} document(s)`});try{await ge(e,t,r.path,[],r.treeName,C),me(),n.done({title:`Deleted`,description:`${t.length} document(s) deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},[e,r.path,r.treeName,C,me,f]),ve=(0,M.useCallback)(async t=>{let n=f({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await x(e,t);if(r.failed?.length&&!r.successful?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}me();let i=`${r.successful?.length??0} document(s) destroyed${r.failed?.length?` · ${r.failed.length} failed`:``}.`;r.failed?.length?n.fail({title:`Destroy incomplete`,description:i,variant:`destructive`}):n.done({title:`Destroyed`,description:i})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy documents`,variant:`destructive`})}},[e,me,f]);return(0,N.jsxs)(`div`,{className:h(`relative flex-1 min-w-0 rounded-(--sheet-radius) border bg-background overflow-hidden`,i?`ring-2 ring-primary`:`ring-1 ring-primary/20`),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||a()},children:[c&&(0,N.jsx)(`button`,{type:`button`,onClick:c,className:`absolute right-2 top-2 z-10 px-2 py-1 text-xs rounded-md border bg-background/90 hover:bg-accent`,children:`Close`}),Ee(r.treeName,r.path)?r.path===`/Trash`?(0,N.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,N.jsx)(at,{workspaceName:e})}):(0,N.jsx)(ft,{workspace:e,path:r.path,onNavigate:s||(()=>{})}):(0,N.jsx)(Xe,{frameContent:!1,onBrowseWorkspaces:()=>l(`workspaces`),onBrowseTree:()=>u(`workspaces`,`detail`,e),urlType:se?`canvas`:C===`directory`?r.treeName:`context`,urlDisplay:ce,contextPath:r.path,treeName:r.treeName,workspaceId:e,workspaceLabel:t,workspaceIcon:n,documentSchema:le,documents:ee,isLoading:te,totalCount:_,currentPage:ie,pageSize:b,onPageChange:y,onPageSizeChange:e=>{ae(e),y(1)},onRemoveDocument:r.path===`/`?void 0:e=>he([e]),onRemoveDocuments:r.path===`/`?void 0:he,onDeleteDocument:e=>_e([e]),onDeleteDocuments:_e,onDestroyDocument:e=>ve([e]),onDestroyDocuments:ve,onCopyDocuments:t=>We({workspaceName:e,documentIds:t,operation:`copy`,sourcePath:r.path,sourceTreeName:r.treeName}),onCutDocuments:t=>We({workspaceName:e,documentIds:t,operation:`cut`,sourcePath:r.path,sourceTreeName:r.treeName}),onPasteDocuments:pe,onSelectionChange:o,pastedDocumentIds:fe?.documentIds,linkTree:p,folders:T,onOpenFolder:s,onNavigatePath:s,canvasInfo:se?{label:w?.label,description:w?.description,color:w?.color}:void 0,children:E?.kind===`columns`?(0,N.jsx)(tt,{documents:ee,workspaceId:e,columns:E.columns??[],onColumnsChange:()=>{},readOnly:!0}):E?.kind===`app`&&E.app&&E.app!==`notes`?(0,N.jsx)($e,{app:E.app,workspaceId:e,treeName:r.treeName,path:r.path}):null})]})}export{z 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,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Gr as o,Kn as s,L as c,Tt as l,Ur as u,X as d,_r as f,ar as p,kt as m,pn as ee}from"./ui-DEgHnkQu.js";import{t as h}from"./utils-2pl1SbIp.js";import{t as g}from"./button--VYZekMF.js";import{c as te,t as ne}from"./api-CA6WiiYM.js";import{t as _}from"./socket-CtH3EU9m.js";import{n as re}from"./use-toast-BlLDqSUO.js";import{h as v,o as ie,s as y}from"./LinkToCard-oi3wGP0a.js";import{At as b,D as x,G as ae,Gt as S,Kt as C,Lt as w,W as oe,Y as se,_ as T,_n as E,a as ce,gt as le,lt as D,mt as ue,nt as de,rn as fe,rt as pe,u as me,vt as he,w as ge,x as _e,xn as O,y as ve,zt as ye}from"./workspace-4hWrSEku.js";import{n as be,r as xe}from"./use-canvas-pins-q5Tncavk.js";import{u as Se}from"./ObjectPropertiesCard-DesXRw-_.js";import{D as Ce,E as we,a as Te,c as Ee,j as De,l as k,n as A,o as Oe,r as ke,u as Ae}from"./document-list-Bbbx-pTZ.js";import{n as je}from"./use-toolbox-Ck_cLGgf.js";import{i as Me}from"./color-DFEH4BfK.js";import{t as Ne}from"./geo-CZfs0E-x.js";import{a as Pe,i as Fe,n as Ie,o as Le}from"./workspace-BydSRtST.js";import{n as Re,r as ze,t as Be}from"./url-params-n7kU_WZ-.js";import{i as Ve}from"./use-menu-CKSpS96u.js";import{n as He}from"./last-path-BbXWC3b3.js";import{i as Ue,n as We,r as Ge,t as Ke}from"./document-paste-BuTC6S7_.js";import{t as qe}from"./workspace-content-gate-BlFdbi67.js";import{t as Je}from"./form-panel-CEbNKttr.js";import{a as Ye,c as Xe,i as Ze,l as Qe,n as $e,o as et,r as tt,s as nt,t as rt,u as it}from"./tree-folders-dKwIsl1U.js";import{i as at,r as ot}from"./query-debug-PEWbZsOP.js";var j=`session.open`,st=`session.set`,ct=`session.ids`,lt=`session.materialize`,ut=`session.close`,dt=`session.delta`,M=e(n(),1),N=t();function ft(e){let t=Ee(`backends`,e.path)?.backend;return(0,N.jsx)(pt,{...e},JSON.stringify([e.workspace,t]))}function pt({workspace:e,path:t,onNavigate:n}){let r=Ee(`backends`,t),i=r.backend,a=r.prefix,[o,c]=(0,M.useState)(null),[u,ee]=(0,M.useState)(null),h=(0,M.useRef)(!1),[g,te]=(0,M.useState)(null),[ne,_]=(0,M.useState)(null),[re,b]=(0,M.useState)(0),[x,ae]=(0,M.useState)(new Set),[S,C]=(0,M.useState)(null),w=(0,M.useCallback)(()=>b(e=>e+1),[]),[oe,se]=(0,M.useState)(t);oe!==t&&(se(t),ae(new Set),C(null),_(null),te(null));let T=o?.revision!==re,E=T?[]:o.items,ce=T?[]:o.backends,le=o?.days;(0,M.useEffect)(()=>{let t=!1;return(i?Te(e,i).then(e=>({...e,backends:[]})):he(e).then(e=>({items:[],days:null,backends:e.filter(e=>e.driver===`file`&&e.enabled!==!1)}))).then(e=>{t||c({...e,revision:re,error:null})}).catch(e=>{t||c({revision:re,items:[],backends:[],days:null,error:e instanceof Error?e.message:String(e)})}),()=>{t=!0}},[e,i,re]),(0,M.useEffect)(()=>{let t=null,n=n=>{let r=n.detail;r?.workspaceName&&r.workspaceName!==e||r?.treeName&&r.treeName!==`backends`||(t||=setTimeout(()=>{t=null,w()},500))};return window.addEventListener(`workspace:trash:refresh`,n),window.addEventListener(`workspace:tree:refresh`,n),()=>{window.removeEventListener(`workspace:trash:refresh`,n),window.removeEventListener(`workspace:tree:refresh`,n),t&&clearTimeout(t)}},[e,w]);let D=Ae(E,a),ue=async(t,n)=>{if(!(!i||h.current||T||!n.length)&&!(t===`discard`&&!A(i,n))){h.current=!0,ee(t),te(null),_(null),C(null);try{let r=await(t===`restore`?Oe:ke)(e,i,[...n].sort((e,t)=>t.deletedAt-e.deletedAt).map(e=>e.id)),a=r.filter(e=>!e.ok);_(`${r.length-a.length} item(s) ${t===`restore`?`restored to their original paths`:`permanently deleted`}.`),a.length&&te(`${a.length} item(s) remain in Trash. ${a.slice(0,3).map(e=>`${e.key||`Item`}: ${e.reason===`precondition-failed`||e.reason===`target-exists`?`original path is occupied`:e.message||e.reason}`).join(`; `)}`),ae(new Set)}catch(e){te(e instanceof Error?e.message:String(e))}finally{h.current=!1,ee(null),w()}}},de=(e,t,n)=>C({x:e,y:t,row:n});return(0,N.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col bg-background`,"aria-label":`Backend Trash`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 border-b px-4 py-3`,children:[(0,N.jsx)(d,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,N.jsx)(y,{items:ie(t,e).map((e,t)=>t===2&&i?{...e,label:i}:e),onNavigate:n,className:`basis-48`}),(0,N.jsxs)(`div`,{className:`ml-auto flex max-w-full flex-wrap items-center gap-2`,children:[x.size>0&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm disabled:opacity-50`,disabled:!!u||T,onClick:()=>void ue(`restore`,D.filter(e=>x.has(e.id)).flatMap(e=>e.items)),children:[(0,N.jsx)(l,{className:`h-3.5 w-3.5`}),`Restore selected`]}),(0,N.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm text-destructive disabled:opacity-50`,disabled:!!u||T,onClick:()=>void ue(`discard`,D.filter(e=>x.has(e.id)).flatMap(e=>e.items)),children:[(0,N.jsx)(d,{className:`h-3.5 w-3.5`}),`Delete selected`]})]}),i&&D.length>0&&(0,N.jsxs)(`button`,{className:`flex items-center gap-1 rounded border px-2 py-1 text-sm text-destructive disabled:opacity-50`,disabled:!!u||T,onClick:()=>void ue(`discard`,D.flatMap(e=>e.items)),children:[(0,N.jsx)(d,{className:`h-3.5 w-3.5`}),a?`Empty this folder`:`Empty Trash`]}),(0,N.jsx)(`button`,{title:`Refresh Trash`,"aria-label":`Refresh Trash`,className:`rounded p-2 hover:bg-accent`,disabled:!!u||T,onClick:w,children:(0,N.jsx)(m,{className:`h-4 w-4 ${T?`animate-spin`:``}`})})]})]}),(0,N.jsxs)(`div`,{className:`border-b px-4 py-2 text-xs text-muted-foreground`,children:[`Restore files and folders to their original paths. Existing files are kept.`,le?` Deleted items are kept for ${le} days.`:``]}),ne&&(0,N.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:ne}),(g||o?.error)&&(0,N.jsx)(`p`,{role:`alert`,className:`px-4 py-2 text-sm text-destructive`,children:g||o?.error}),u&&(0,N.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:u===`restore`?`Restoring…`:`Deleting permanently…`}),(0,N.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:T?(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading Trash…`}):i?D.length===0?(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`This Trash folder is empty.`}):(0,N.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,N.jsx)(`thead`,{className:`border-b text-xs text-muted-foreground`,children:(0,N.jsxs)(`tr`,{children:[(0,N.jsx)(`th`,{className:`w-8 p-2`,children:(0,N.jsx)(`input`,{type:`checkbox`,"aria-label":`Select all visible items`,checked:D.length>0&&D.every(e=>x.has(e.id)),onChange:e=>ae(e.target.checked?new Set(D.map(e=>e.id)):new Set)})}),(0,N.jsx)(`th`,{className:`p-2`,children:`Name`}),(0,N.jsx)(`th`,{className:`p-2 max-sm:hidden`,children:`Original path`}),(0,N.jsx)(`th`,{className:`p-2 max-md:hidden`,children:`Deleted`}),(0,N.jsx)(`th`,{className:`p-2`,children:(0,N.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,N.jsx)(`tbody`,{children:D.map(e=>(0,N.jsxs)(`tr`,{className:`border-b border-border/50 hover:bg-accent/50`,onContextMenu:t=>{t.preventDefault(),de(t.clientX,t.clientY,e)},onDoubleClick:()=>e.navigable&&n(k(i,e.key)),children:[(0,N.jsx)(`td`,{className:`p-2`,children:(0,N.jsx)(`input`,{type:`checkbox`,"aria-label":`Select ${e.name}`,checked:x.has(e.id),disabled:!!u,onChange:t=>ae(n=>{let r=new Set(n);return t.target.checked?r.add(e.id):r.delete(e.id),r})})}),(0,N.jsx)(`td`,{className:`p-2`,children:(0,N.jsxs)(`button`,{className:`flex items-center gap-2 text-left`,onClick:()=>e.navigable&&n(k(i,e.key)),children:[e.directory?(0,N.jsx)(s,{className:`h-4 w-4 shrink-0`}):(0,N.jsx)(p,{className:`h-4 w-4 shrink-0`}),(0,N.jsxs)(`span`,{children:[e.name,e.navigable&&(0,N.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[e.items.length,` items`]})]})]})}),(0,N.jsx)(`td`,{className:`p-2 text-xs text-muted-foreground max-sm:hidden`,children:e.key}),(0,N.jsx)(`td`,{className:`p-2 text-xs text-muted-foreground max-md:hidden`,children:new Date(e.items.reduce((e,t)=>Math.max(e,t.deletedAt),0)).toLocaleString()}),(0,N.jsx)(`td`,{className:`p-2 text-right`,children:(0,N.jsx)(`button`,{title:`Actions for ${e.name}`,"aria-label":`Actions for ${e.name}`,disabled:!!u,className:`rounded p-2 hover:bg-accent`,onClick:t=>de(t.clientX,t.clientY,e),children:(0,N.jsx)(f,{className:`h-4 w-4`})})})]},e.id))})]}):(0,N.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-3`,children:[ce.map(e=>(0,N.jsxs)(`button`,{onClick:()=>n(k(e.address)),className:`flex items-center gap-3 rounded-lg border p-4 text-left hover:bg-accent`,children:[(0,N.jsx)(d,{className:`h-6 w-6 text-muted-foreground`}),(0,N.jsxs)(`span`,{children:[(0,N.jsx)(`span`,{className:`block text-sm font-medium`,children:e.label||e.address}),(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.address})]})]},e.address)),!ce.length&&(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`No file backends are available.`})]})}),S&&(0,N.jsxs)(v,{x:S.x,y:S.y,onClose:()=>C(null),className:`min-w-44 rounded-md border bg-popover p-1 shadow-elevation-3`,children:[S.row.navigable&&(0,N.jsxs)(`button`,{className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm hover:bg-accent`,onClick:()=>{n(k(i,S.row.key)),C(null)},children:[(0,N.jsx)(s,{className:`h-4 w-4`}),`Open folder`]}),(0,N.jsxs)(`button`,{disabled:!!u,className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm hover:bg-accent disabled:opacity-50`,onClick:()=>void ue(`restore`,S.row.items),children:[(0,N.jsx)(l,{className:`h-4 w-4`}),`Restore `,S.row.directory?`folder`:`file`]}),(0,N.jsxs)(`button`,{disabled:!!u||T,className:`flex w-full items-center gap-2 rounded px-3 py-2 text-sm text-destructive hover:bg-destructive/10 disabled:opacity-50`,onClick:()=>void ue(`discard`,S.row.items),children:[(0,N.jsx)(d,{className:`h-4 w-4`}),`Delete permanently`]})]})]})}function mt({workspaceId:e,workspaceName:t}){let[n,r]=(0,M.useState)([]),[i,a]=(0,M.useState)(new Set),o=t=>`${e}:${t.address}:${t.resyncStartedAt||``}`;(0,M.useEffect)(()=>{let t=!1,n=!1,i=!1,a=0,o=new Map,s=new Map,c=(e,t)=>{let n=e.filter(e=>e.address!==t.backend);if(!t.resyncing)return n;let r=e.find(e=>e.address===t.backend)||s.get(t.backend);return[...n,{address:t.backend,config:r?.config,resyncStartedAt:r?.resyncStartedAt||new Date().toISOString(),progress:t.progress??r?.progress}]},l=async()=>{if(n){i=!0;return}n=!0;let u=a;try{let n=await he(e);if(!t){s=new Map(n.map(e=>[e.address,e]));let e=n.filter(e=>e.resyncing);for(let t of o.values())t.version>u&&(e=c(e,t.event));r(e)}}catch{}finally{n=!1,i&&!t&&(i=!1,l())}},u=t=>{t.workspaceId!==e||!t.backend||typeof t.resyncing!=`boolean`||(o.set(t.backend,{version:++a,event:t}),r(e=>c(e,t)))},d=t=>{t.workspaceId===e&&l()};l();let f=_.on(`connect`,l);return _.on(`backend.resync.changed`,u),_.on(`backend.changed`,d),window.addEventListener(`focus`,l),()=>{t=!0,f?.(),_.off(`backend.resync.changed`,u),_.off(`backend.changed`,d),window.removeEventListener(`focus`,l)}},[e]);let s=n.filter(e=>!i.has(o(e)));return s.length?(0,N.jsxs)(`aside`,{"aria-label":`Storage scans for ${t}`,className:`absolute bottom-5 right-5 z-50 w-72 max-w-[calc(100vw-2.5rem)] rounded-lg border bg-popover/95 p-3 text-popover-foreground shadow-lg backdrop-blur`,children:[(0,N.jsxs)(`div`,{role:`status`,className:`mb-2 flex items-center gap-2 text-sm font-medium`,children:[(0,N.jsx)(ee,{"aria-hidden":`true`,className:`h-4 w-4 animate-spin`}),(0,N.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,N.jsx)(`span`,{className:`block`,children:`Scanning storage`}),(0,N.jsx)(`span`,{className:`block truncate text-xs font-normal text-muted-foreground`,title:t,children:t})]}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Hide scan progress for ${t}`,title:`Hide progress; scanning continues`,className:`rounded p-1 hover:bg-muted focus-visible:outline focus-visible:outline-2`,onClick:()=>a(e=>new Set([...e,...s.map(o)])),children:(0,N.jsx)(c,{"aria-hidden":`true`,className:`h-4 w-4`})})]}),(0,N.jsx)(`div`,{className:`max-h-48 space-y-3 overflow-y-auto`,children:s.map(e=>{let{scanned:t=0,total:n=null}=e.progress||{},r=n&&n>0?Math.min(100,Math.round(t/n*100)):null,i=typeof e.config?.label==`string`?e.config.label:e.address;return(0,N.jsxs)(`div`,{children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,N.jsx)(`span`,{className:`truncate`,children:i}),(0,N.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:n===null?`${t} files`:`${t} / ${n}`})]}),(0,N.jsx)(`div`,{role:`progressbar`,"aria-label":`Scanning ${i}`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":r??void 0,className:`mt-1.5 h-1 overflow-hidden rounded-full bg-muted`,children:(0,N.jsx)(`div`,{className:`h-full rounded-full bg-primary ${r===null?`animate-pulse`:`transition-all`}`,style:{width:r===null?`35%`:`${r}%`}})})]},e.address)})})]}):null}var ht=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:null;function gt(e){return`/${e}`.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`}function _t(e,t,n){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>_t(e,t,n));if(typeof e==`string`)return[{tree:null,kind:t,path:gt(e)}];let r=ht(e);if(!r)return[];let i=r.tree??r.treeId,a=typeof i==`string`?n.get(i)??null:null;return[].concat(r.paths??r.path??`/`).filter(e=>typeof e==`string`).map(e=>({tree:a,kind:t,path:gt(e)}))}function vt(e){let t=[],n=e=>{let n=Number(e);Number.isSafeInteger(n)&&n>0&&t.push(n)};return Array.isArray(e.ids)&&e.ids.forEach(n),Array.isArray(e.documentIds)&&e.documentIds.forEach(n),e.id!=null&&n(e.id),e.documentId!=null&&n(e.documentId),t}function yt(e){let t=new Map;for(let n of e)t.set(n.id,n.name),t.set(n.name,n.name);return t}function bt(e,t,n=new Map){let r=ht(t);if(!r)return{targets:[],ids:[],unknown:!0};if(e.startsWith(`tree.`)){let e=typeof r.treeName==`string`?r.treeName:null,t=r.treeType===`directory`||r.treeType===`context`?r.treeType:null,n=r.contextSpec??r.path;return typeof n==`string`?{targets:[{tree:e,kind:t,path:gt(n)}],ids:vt(r),unknown:!1}:{targets:[],ids:[],unknown:!0}}let i=[..._t(r.context,`context`,n),..._t(r.directory,`directory`,n)],a=ht(r.changed);a&&i.push(..._t(a.context,`context`,n),..._t(a.directory,`directory`,n));let o=vt(r);if(i.length)return{targets:i,ids:o,unknown:!1};let s=r.reason===`content`||r.reason===`relations`||r.reason===`moved`;return(e.startsWith(`document.updated`)||e.startsWith(`document.moved`))&&s&&o.length?{targets:[],ids:o,unknown:!1}:{targets:[],ids:o,unknown:!0}}function xt(e,t){return e===t||e===`/`||t===`/`||e.startsWith(`${t}/`)||t.startsWith(`${e}/`)}function St(e,t){if(e.kind&&e.kind!==t.kind||e.tree&&e.tree!==t.tree)return!1;if(t.kind===`context`){let n=e=>gt(e).split(`/`).filter(Boolean).map(e=>e.normalize(`NFKC`).trim().replace(/\s+/g,` `).replace(/[^\p{L}\p{N}\p{M} .+_@-]/gu,`_`).replace(/_+/g,`_`).toLowerCase()||`_`),r=new Set(n(e.path)),i=n(t.path);return r.size===0||i.length===0||i.some(e=>r.has(e))}return xt(e.path,t.path)}function Ct(e){return bt(`tree.refresh`,{treeName:e?.treeName,path:e?.path||`/`})}function wt(e,t,n){if(e.unknown||e.targets.length&&(t.wholeWorkspace||e.targets.some(e=>St(e,t))))return!0;if(e.ids.length&&n){let t=n instanceof Set?n:new Set(n);if(e.ids.some(e=>t.has(e)))return!0}return!1}function Tt(e,t,n={}){return _.request(j,{workspace:e,specs:t,opts:n})}function Et(e,t,n){return _.request(st,{sessionId:e,label:t,spec:n})}function P(e){return _.request(ct,{sessionId:e})}function Dt(e,t={}){return _.request(lt,{sessionId:e,...t})}function F(e){return _.request(ut,{sessionId:e})}function I(e){return _.on(dt,e)}var L=100;function Ot({workspaceRef:e,specs:t,opts:n,enabled:r=!0}){let[i,a]=(0,M.useState)([]),[o,s]=(0,M.useState)(0),[c,l]=(0,M.useState)(null),[u,d]=(0,M.useState)(null),f=(0,M.useRef)([]),p=(0,M.useRef)(new Map),m=(0,M.useRef)(null),ee=(0,M.useRef)(null),h=(0,M.useRef)(null),g=(0,M.useRef)({}),te=(0,M.useRef)(null),ne=(0,M.useMemo)(()=>JSON.stringify(t),[t]),re=(0,M.useMemo)(()=>JSON.stringify(n??{}),[n]),v=(0,M.useCallback)(()=>{let e=p.current;a(f.current.map(t=>e.get(t)).filter(Boolean))},[]),ie=(0,M.useCallback)(async e=>{let t=ee.current;if(!t||e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=L){let i=e.slice(r,r+L),a=await de(t,`/`,[],{ids:i,scope:`workspace`,limit:i.length});n.push(...a.payload||[])}return n},[]),y=(0,M.useCallback)(async(e,t,n)=>{if(t.length>0){let e=new Set(t);f.current=f.current.filter(t=>!e.has(t));for(let t of e)p.current.delete(t)}let r=e.filter(e=>!p.current.has(e)),i=new Set(f.current);for(let t of e)i.has(t)||(f.current.push(t),i.add(t));if(n!==null&&s(n),v(),r.length===0)return;let a=await ie(r);for(let e of a)p.current.set(e.id,e);let o=new Set(a.map(e=>e.id)),c=r.filter(e=>!o.has(e));if(c.length>0){let e=new Set(c);f.current=f.current.filter(t=>!e.has(t))}v()},[ie,v]),b=(0,M.useCallback)(async(e,t)=>{let n=e??[],r=new Set(n);f.current=f.current.filter(e=>r.has(e));for(let e of p.current.keys())r.has(e)||p.current.delete(e);let i=new Set(f.current),a=n.filter(e=>!i.has(e));await y(a,[],t)},[y]);(0,M.useEffect)(()=>{if(ee.current=e??null,!r||!e)return;let t=!1,n=null,i=async()=>{try{let r=await Tt(e,JSON.parse(ne),JSON.parse(re));if(t){F(r.sessionId).catch(()=>{});return}n=r.sessionId,m.current=r.sessionId,l(r.sessionId),d(null),f.current=[],p.current=new Map,await b(r.ids,r.count)}catch(e){if(t)return;d(e instanceof Error?e.message:`Failed to open query session`),l(null),m.current=null}};i();let o=_.on(`connect`,()=>{i()});return()=>{t=!0,o?.();let e=n??m.current;e&&F(e).catch(()=>{}),m.current=null,f.current=[],p.current=new Map,l(null),a([]),s(0)}},[e,ne,re,r]),(0,M.useEffect)(()=>{if(!c)return;let e=I(e=>{if(e.sessionId===c){if(h.current!==null){te.current?.(h.current,g.current);return}e.ids===void 0?y(e.added??[],e.removed??[],e.count):b(e.ids,e.count)}});return()=>{e?.()}},[c,y,b]);let x=(0,M.useCallback)(async()=>{let e=m.current;if(e)try{let t=await P(e);await b(t.ids,t.count)}catch{}},[b]),ae=(0,M.useCallback)(async(e,t)=>{let n=m.current;if(!n)throw Error(`No open query session`);let r=await Et(n,e,t);if(h.current!==null){await te.current?.(h.current,g.current);return}await b(r.ids,r.count)},[b]),S=(0,M.useCallback)(async(e,t={})=>{let n=m.current;if(!n)throw Error(`No open query session`);if(h.current=e,g.current=t,e===null){await x();return}let r=await Dt(n,{match:e,...t});for(let e of r.documents)p.current.set(e.id,e);f.current=r.ids,s(r.totalCount),v()},[v,x]);(0,M.useEffect)(()=>{te.current=S},[S]);let C=(0,M.useCallback)(async(e,t,n={})=>{let r=m.current;if(!r)throw Error(`No open query session`);let i=await Dt(r,{match:t,limit:n.limit??100,...n.mode?{mode:n.mode}:{}});for(let e of i.documents)p.current.set(e.id,e);let a=await Et(r,e,{ids:i.ids});return await b(a.ids,a.count),i.ids},[b]);return{documents:i,count:o,ready:c!==null,error:u,setCue:ae,resync:x,rank:S,rankAndPin:C}}function kt({data:e,className:t}){let[n,r]=(0,M.useState)(!0),{rows:i,gapIndex:a,span:s}=(0,M.useMemo)(()=>{let t=[...e.distances].sort((e,t)=>e.distance-t.distance),n=[];for(let e=1;e<t.length;e++)n.push(t[e].distance-t[e-1].distance);let r=n.length?[...n].sort((e,t)=>e-t)[Math.floor(n.length/2)]:0,i=-1,a=0;for(let e=0;e<n.length;e++)n[e]>a&&(a=n[e],i=e+1);let o=i>0&&a>=Math.max(r*4,1e-6),s=t[0]?.distance??0,c=t[t.length-1]?.distance??0;return{rows:t,gapIndex:o?i:-1,span:{first:s,last:c,biggest:a,median:r}}},[e.distances]);if(i.length===0)return(0,N.jsxs)(`div`,{className:h(`rounded-md border border-dashed border-border px-3 py-2 text-xs text-muted-foreground`,t),children:[`Query debug: no image distances for “`,e.query,`”. The dense side returned nothing: either no photos are embedded in this scope, or the image space is not ready.`]});let c=a>0?i[a].distance:null;return(0,N.jsxs)(`div`,{className:h(`rounded-md border border-border bg-muted/30 text-xs`,t),children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-1.5 px-3 py-2 text-left font-medium`,children:[n?(0,N.jsx)(o,{className:`h-3.5 w-3.5`}):(0,N.jsx)(u,{className:`h-3.5 w-3.5`}),`Query debug`,(0,N.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`: image distances for “`,e.query,`” (`,i.length,` nearest, unfloored)`]})]}),n&&(0,N.jsxs)(`div`,{className:`space-y-2 border-t border-border px-3 py-2`,children:[(0,N.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Best-first cosine distance (0 = identical). Scroll to where the photos stop being relevant and set the image relevance floor just above that value in Settings → Database → Search tuning.`,c===null?(0,N.jsxs)(N.Fragment,{children:[` `,(0,N.jsx)(`span`,{className:`text-amber-600 dark:text-amber-500`,children:`No boundary in this window`}),`; the distances step evenly (typical Δ`,s.median.toFixed(4),`), so there is nothing here to set a floor from. Relevance probably ends further down the list than this window reaches, or the model is not separating this query at all.`]}):(0,N.jsxs)(N.Fragment,{children:[` A jump at `,(0,N.jsx)(`span`,{className:`font-mono`,children:c.toFixed(4)}),` (Δ`,s.biggest.toFixed(4),`, vs typical Δ`,s.median.toFixed(4),`) stands out (a likely boundary).`]})]}),(0,N.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:(0,N.jsx)(`table`,{className:`w-full font-mono text-[11px]`,children:(0,N.jsx)(`tbody`,{children:i.map((e,t)=>(0,N.jsxs)(`tr`,{className:h(`border-b border-border/40 last:border-0`,t===a&&`border-t-2 border-t-amber-500/70`),children:[(0,N.jsx)(`td`,{className:`py-0.5 pr-3 text-muted-foreground`,children:t+1}),(0,N.jsxs)(`td`,{className:`py-0.5 pr-3`,children:[`#`,e.id]}),(0,N.jsx)(`td`,{className:`py-0.5 tabular-nums`,children:e.distance.toFixed(4)}),t===a&&(0,N.jsx)(`td`,{className:`py-0.5 pl-2 font-sans text-[10px] text-amber-600 dark:text-amber-500`,children:`← biggest gap`})]},e.id))})})}),(0,N.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Range `,s.first.toFixed(4),` – `,s.last.toFixed(4),` (spread `,(s.last-s.first).toFixed(4),`) over `,i.length,` rows. Absolute values shift with the model and are not comparable across models. After a re-embed every floor has to be picked again. A spread this narrow relative to the range means ranking is doing the work, not distance.`]})]})]})}var At=new Map;function jt(e,t,n){return`${e}\0${t}\0${n}`}function Mt(e,t,n,r,i,a,o=``,s=``,c=`path`){return`${jt(e,t,n)}\0${r}\0${i}\0${a}\0${o}\0${s}\0${c}`}function R(e,t,n){let r=jt(e,t,n);for(let e of At.keys())e.startsWith(r)&&At.delete(e)}function Nt(e,t){let n=`${e}\0`;for(let[e,r]of At){if(!e.startsWith(n))continue;let[,i,a,,,,,,o=`path`]=e.split(`\0`);wt(t,{tree:i,kind:O(i),path:a,wholeWorkspace:o.startsWith(`workspace`)},r.documents.map(e=>Number(e.id)))&&At.delete(e)}}function Pt(e,t){Nt(t?.workspaceName??e,Ct(t))}function z(){let{workspaceName:e}=r();return e?(0,N.jsx)(qe,{workspaceName:e,children:(0,N.jsx)(Ft,{})}):null}function Ft(){let{workspaceName:e,treeName:t}=r(),n=a(),o=i(),{showToast:s,showProgress:c}=re(),l=new URLSearchParams(n.search),u=(()=>{let e=l.getAll(`q`).map(e=>e.trim()).filter(Boolean);if(e.length>0)return e;let t=(l.get(`search`)||``).trim();return t?[t]:[]})(),[d,f]=(0,M.useState)(null),[p,m]=(0,M.useState)(!0),[ee,v]=(0,M.useState)([]),[ie,y]=(0,M.useState)(!1),[Te,k]=(0,M.useState)(0),A=ot(),[Oe,ke]=(0,M.useState)(null),[Ae,qe]=(0,M.useState)(A);Ae!==A&&(qe(A),A||ke(null));let[j,st]=(0,M.useState)(`path`),[ct,lt]=(0,M.useState)(!1),ut=Ge(e),[dt,pt]=(0,M.useState)(null),[ht,gt]=(0,M.useState)(``),[_t,vt]=(0,M.useState)(!1),[xt,St]=(0,M.useState)(!1),[Tt,Et]=(0,M.useState)(!1),[P,Dt]=(0,M.useState)(null),[F,I]=(0,M.useState)(1),[L,jt]=(0,M.useState)(50),[z,Ft]=(0,M.useState)(u),[It,Rt]=(0,M.useState)(null),{state:B,saveFilters:zt,setSort:Bt,setAccentColor:Vt,setMapDocuments:Ht}=je(),Ut=B.filters.features.allOf,Wt=B.filters.features.anyOf,Gt=B.filters.features.noneOf,Kt=Fe(B.filters.timeline),qt=Pe(B.filters.geo),Jt=Le(B.filters.lens,B.filters.geo.includeUnlocated),V=B.filters.lens.ids,Yt=[...Kt,...qt,...Jt],Xt=B.filters.sort??Ie,Zt=JSON.stringify({a:Ut,b:Wt,c:Gt,d:Yt,i:V,s:Xt}),Qt=JSON.stringify({a:Ut,b:Wt,c:Gt,d:Yt,s:Xt}),H=Re(n.pathname).path,U=t??`context`,W=U===`backends`,[$t,en]=(0,M.useState)([]);(0,M.useEffect)(()=>{!W||!e||he(e).then(en).catch(()=>en([]))},[W,e]);let tn=W?ce(H,$t):null,[nn,rn]=(0,M.useState)(!1),an=`${U}\0${H}`,[on,sn]=(0,M.useState)(an);on!==an&&(sn(an),rn(!1));let G=l.get(`layer`)===`1`,K=l.get(`layerId`)||null,[q,cn]=(0,M.useState)(null),[J,ln]=(0,M.useState)(null),un=(0,M.useRef)(null);(0,M.useEffect)(()=>{un.current=J},[J]);let[dn,fn]=(0,M.useState)(`left`),[pn,mn]=(0,M.useState)([]),{openM1Drawer:hn,openM2Drawer:gn,goBack:_n}=Ve(),[vn,yn]=(0,M.useState)([]),Y=(0,M.useMemo)(()=>{if(!q||H===`/`||G)return null;let e=H.split(`/`).filter(Boolean),t=q;for(let n of e)if(t=t?.children?.find(e=>e.name===n)??null,!t)return null;return t},[q,H,G]),X=Y?.type===`canvas`?`canvas`:null,bn=(0,M.useRef)(null);(0,M.useEffect)(()=>{!e||!q||G||bn.current===`${e}/${U}`&&(H!==`/`&&!Y||He(e,U,H))},[e,q,G,H,Y,U]);let xn=(0,M.useMemo)(()=>G||j===`workspace`||z.length>0?[]:rt(q,H),[q,H,G,j,z]),Sn=G?null:H===`/`?q:Y,Z=De(),Cn=`${U}\0${H}`,[wn,Tn]=(0,M.useState)(null),En=wn?.key===Cn?wn.views:nt(Sn?.metadata),Dn=Z?.pinned&&Z.view?[Z.view,...En.filter(e=>e.id!==Z.view.id)]:En,On=Z?.pinned&&Z.view?Z.view.id:wn?.key===Cn?wn.activeId:Dn[0]?.id??Ye.id,Q=Dn.find(e=>e.id===On)??Dn[0]??Ye;(0,M.useEffect)(()=>{Z?.selectView(Q)},[Q,Z]);let kn=W?void 0:Z?.schema??et(Q),An=kn?[...Ut,kn]:Ut;it(Qe({workspace:e??null,treeNameOrId:U,treeType:O(U),path:H,scope:j===`workspace`?`workspace`:G?`layer`:`path`,layerId:G?K:void 0,unfiledOnly:nn},{...B.filters,features:{...B.filters.features,allOf:An}},B.geoSelection,z));let jn=e=>{let t=Dn.find(t=>t.id===e);t&&Z?.selectView(t),I(1),mn([]),Tn({key:Cn,views:Dn,activeId:e})},Mn=(t,n)=>{n&&n!==On&&(I(1),mn([]));let r=t.find(e=>e.id===(n??On));r&&Z?.selectView(r),Tn({key:Cn,views:t,activeId:n??On}),E(e,H,{metadata:{...Sn?.metadata??{},views:t}},U).catch(()=>{s({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},Nn=X===`canvas`&&typeof Y?.querySpec?.query==`string`?Y.querySpec.query:``,Pn=X===`canvas`?{label:Y?.label,description:Y?.description,color:Y?.color}:null,{isPinned:Fn,pin:In,unpin:Ln,pins:Rn}=be(),zn=d?.name,Bn=(0,M.useMemo)(()=>zn&&X===`canvas`&&!G?{workspaceName:zn,treeName:U,path:H}:null,[zn,X,G,U,H]),Vn=Bn?Fn(Bn):!1,Hn=Y?.id,Un=Y?.label,Wn=(0,M.useCallback)(async()=>{if(Bn)try{let e=Rn.find(e=>e.workspaceName===Bn.workspaceName&&e.treeName===Bn.treeName&&e.path===Bn.path);e?await Ln(e.id):await In({...Bn,layerId:Hn,label:Un})}catch(e){console.error(`Failed to update home pins:`,e)}},[Bn,Rn,In,Ln,Hn,Un]),Gn=e?`${e}://${H===`/`?``:H.replace(/^\//,``)}`:``,Kn=Me(d?.color)||null;(0,M.useEffect)(()=>(Vt(Kn),()=>Vt(null)),[Kn,Vt]);let qn=(0,M.useCallback)(async t=>{let n=V;if(t?.anyOf?.length&&Wt.length&&(n=((await ae(e,H,U,{limit:0,anyOf:Wt,ids:V,applyCanvasSpec:!1})).payload||[]).map(e=>e.id),!n.length))return{payload:[],count:0,totalCount:0};let r=await ae(e,H,U,{limit:t?.limit,offset:t?.offset,page:t?.page,sortBy:t?.sortBy,order:t?.order,allOf:[...Ut,...t?.allOf??[]],anyOf:t?.anyOf?.length?t.anyOf:Wt,noneOf:Gt,filters:Yt,ids:n,queries:[...z,...t?.queries??[],...t?.q?[t.q]:[]],applyCanvasSpec:!1});return{payload:r.payload||[],count:r.count??void 0,totalCount:r.totalCount??void 0}},[e,H,U,Zt,z]);(0,M.useEffect)(()=>{e&&(async()=>{m(!0);try{let t=await ne.get(`${te.workspaces}/${e}`),n;n=t&&`workspace`in t?t.workspace:t,f(n)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch workspace ${e}`;s({title:`Error`,description:n,variant:`destructive`}),f(null)}finally{m(!1)}})()},[e,s]),(0,M.useEffect)(()=>{let e=e=>{let t=e.detail?.workspace;t&&f(e=>e&&(t===e.name||t===e.id)&&e.status!==`active`?{...e,status:`active`}:e)};return window.addEventListener(`workspace:autostarted`,e),()=>window.removeEventListener(`workspace:autostarted`,e)},[]);let Jn=(V?.length??0)>0&&!G&&!(nn&&tn)&&z.length<=1,{documents:Yn,count:Xn,ready:Zn,setCue:Qn,resync:$n,rank:er}=Ot({workspaceRef:e,specs:(0,M.useMemo)(()=>{let e={features:{allOf:An,anyOf:Wt,noneOf:Gt},filters:Yt};return j!==`workspace`&&(O(U)===`directory`?e.directory={tree:U,path:H}:e.context=H),[{label:`scope`,spec:e}]},[Qt,H,U,j,kn]),opts:(0,M.useMemo)(()=>({mode:`live`,debounceMs:150}),[]),enabled:Jn}),tr=Jn&&Zn,nr=(0,M.useRef)(!1);(0,M.useEffect)(()=>{nr.current=tr},[tr]);let rr=z.length===1?z[0].trim():``;(0,M.useEffect)(()=>{Zn&&er(rr?{text:rr}:null,{limit:L,offset:(F-1)*L}).catch(()=>{})},[Zn,rr,L,F,er]);let ir=(V??[]).join(`,`);(0,M.useEffect)(()=>{Zn&&Qn(`lens`,{ids:V??[]}).catch(()=>{})},[Zn,ir,Qn,V]);let ar=tr?Yn:ee,or=tr?Xn:Te,sr=(0,M.useRef)(new Set);(0,M.useEffect)(()=>{sr.current=new Set(ar.map(e=>Number(e.id)))},[ar]);let cr=B.geoSelection;(0,M.useEffect)(()=>{Ht(ar,d?.name??null)},[ar,d?.name,Ht]),(0,M.useEffect)(()=>()=>Ht([]),[Ht]);let lr=(0,M.useMemo)(()=>cr?ar.filter(e=>Ne(e,cr,B.filters.geo.includeUnlocated)):ar,[ar,cr,B.filters.geo.includeUnlocated]),ur=me(H,An,{treeName:U,treeType:O(U),scope:j,queries:z,anyOf:Wt,noneOf:Gt,filters:Yt,ids:V,layerId:G&&K?K:void 0}),dr=JSON.stringify([e,ur]),[fr,pr]=(0,M.useState)(``),[mr,hr]=(0,M.useState)(!1),gr=(0,M.useRef)(!1),_r=ie||mr||fr!==dr||tr||!!cr,vr=(0,M.useRef)(0),yr=(0,M.useRef)(null);(0,M.useEffect)(()=>()=>{vr.current++,yr.current=null},[]);let br=(0,M.useRef)(``),$=(0,M.useCallback)(async t=>{if(!e)return;if(Ee(U,H)){vr.current++,yr.current=null,br.current=``,v([]),k(0),y(!1);return}if(nr.current)return;let n=`${nn&&tn?`${j}:unfiled`:j}:${kn??``}`,r=(V?.length??0)>0,i=Mt(e,U,H,F,L,z.join(`␟`),Qt,G&&K?K:``,n),a=r&&i===br.current;br.current=i;let o=Mt(e,U,H,F,L,z.join(`␟`),Zt,G&&K?K:``,n),c=`${o}\0${A}`;if(t?.silent&&yr.current?.key===c){yr.current.refreshPending=!0;return}let l=++vr.current,u=t?.silent||r||A?void 0:At.get(o);u&&(v(u.documents),k(u.totalCount),pr(dr),y(!1)),(t?.silent??(a||!!u))||y(!0);let d={key:c,refreshPending:!1};yr.current=d;try{let t;if(nn&&tn)t=await le(e,tn.driver,tn.address,{linked:!1,limit:L,offset:(F-1)*L});else if(G&&K&&j!==`workspace`)t=await pe(e,U,K,{limit:L,page:F,queries:z,allOf:An,anyOf:Wt,noneOf:Gt,filters:Yt,ids:V,sortBy:Xt.sortBy||void 0,order:Xt.order});else{let n=O(U);t=await de(e,H,An,{limit:L,page:F,treeName:U,treeType:n,queries:z,anyOf:Wt,noneOf:Gt,filters:Yt,ids:V,sortBy:Xt.sortBy||void 0,order:Xt.order,scope:j,debug:A&&z.length>0,debugLimit:200})}let n=t.payload||[],i=t.totalCount||t.count||0;if(!r&&!d.refreshPending&&At.set(o,{documents:n,totalCount:i}),l!==vr.current)return;let s=t.debug,c=s?.imageDistances??s?.distances??null;ke(c?{query:z[z.length-1]??``,distances:c}:null),v(a?e=>e.length===n.length&&e.every((e,t)=>e.id===n[t].id)?e:n:n),k(i),pr(dr)}catch(e){if(l!==vr.current)return;let t=e instanceof Error?e.message:`Failed to fetch documents`;s({title:`Error`,description:t,variant:`destructive`}),v([]),k(0)}finally{yr.current===d&&(yr.current=null),l===vr.current&&y(!1),l===vr.current&&d.refreshPending&&$({silent:!0})}},[e,H,U,K,G,F,L,d?.status,z,Zt,j,nn,A,kn]);(0,M.useEffect)(()=>{$()},[$]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;!n||n.workspaceName!==e||(ln({treeName:n.treeName||`context`,path:ze(n.path||`/`)}),fn(`left`))};return window.addEventListener(`workspace:open-to-side`,t),()=>window.removeEventListener(`workspace:open-to-side`,t)},[e,U,H]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;if(!(n?.workspaceName&&n.workspaceName!==e)&&(e&&Pt(e,n),wt(Ct(n),{tree:U,kind:O(U),path:H,wholeWorkspace:j===`workspace`}))){if(e&&R(e,U,H),nr.current){$n();return}$({silent:!0})}};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[$,e,H,U,j,$n]);let xr=d?.name,Sr=d?.id;(0,M.useEffect)(()=>{if(!e||!xr&&!Sr)return;let t=[xr,Sr].filter(Boolean).map(e=>`workspace:${e}`),n=()=>t.forEach(e=>_.emit(`subscribe`,{channel:e}));n();let r=_.on(`connect`,n),i=new Map,a=!1,o=()=>{b(e).then(e=>{a||(i=yt(e))}).catch(()=>{})};o();let s=null,c=0,l=!1,u=null,d=()=>{if(s=null,c=Date.now(),u){let{treeName:t,path:n}=u;u=null,window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,treeName:t,path:n}}))}if(l){if(l=!1,nr.current){$n();return}$({silent:!0})}},f=t=>n=>{(t.startsWith(`tree.created`)||t.startsWith(`tree.renamed`))&&o();let r=bt(t,n,i);Nt(e,r);let a={tree:U,kind:O(U),path:H,wholeWorkspace:j===`workspace`},f=un.current;f&&wt(r,{tree:f.treeName,kind:O(f.treeName),path:f.path})&&(u=f),wt(r,a,sr.current)&&(l=!0),!(!l&&!u)&&(s||=setTimeout(d,Math.max(200,c+1500-Date.now())))},p=[`document.inserted`,`document.inserted.batch`,`document.updated`,`document.moved`,`document.moved.batch`,`document.removed`,`document.deleted`,`document.removed.batch`,`document.deleted.batch`,`document.linked`,`document.unlinked`,`document.linked.batch`,`document.unlinked.batch`,`tree.document.inserted`,`tree.document.inserted.batch`,`tree.document.removed`,`tree.document.removed.batch`,`tree.document.deleted`,`tree.document.deleted.batch`,`tree.layer.merged`,`tree.layer.subtracted`,`tree.created`,`tree.renamed`].map(e=>[e,f(e)]);return p.forEach(([e,t])=>_.on(e,t)),()=>{a=!0,s&&clearTimeout(s),r?.(),p.forEach(([e,t])=>_.off(e,t))}},[e,Sr,xr,U,H,j,$,$n]);let Cr=`${H}\0${U}\0${K??``}\0${j}`,[wr,Tr]=(0,M.useState)(Cr);wr!==Cr&&(Tr(Cr),I(1),Rt(null));let Er=`${H}\0${U}\0${K??``}`,[Dr,Or]=(0,M.useState)(Er);Dr!==Er&&(Or(Er),st(`path`));let kr=(e,t)=>{let n=e===`/`?`canvas`:e.split(`/`).pop()||`canvas`;gt(n),pt({parentPath:e,captureView:t})},Ar=l.get(`createCanvas`)===`1`,[jr,Mr]=(0,M.useState)(!1);jr!==Ar&&(Mr(Ar),Ar&&kr(H,!1)),(0,M.useEffect)(()=>{if(!Ar)return;let e=new URLSearchParams(n.search);e.delete(`createCanvas`);let t=e.toString();o(`${n.pathname}${t?`?${t}`:``}${n.hash}`,{replace:!0})},[Ar,H]);let Nr=(0,M.useCallback)(e=>{let t=new URLSearchParams(n.search);t.delete(`q`),t.delete(`search`);for(let n of e)t.append(`q`,n);let r=t.toString();o(`${n.pathname}${r?`?${r}`:``}${n.hash}`)},[n.pathname,n.search,n.hash,o]),Pr=JSON.stringify([l.has(`q`),...u]),[Fr,Ir]=(0,M.useState)(Pr);Fr!==Pr&&(Ir(Pr),Ft(u),I(1));let Lr=`${Pr}\0${X??``}\0${Nn}\0${H}\0${It??``}`,[Rr,zr]=(0,M.useState)(Lr);Rr!==Lr&&(zr(Lr),l.has(`q`)||u.length>0||X!==`canvas`||It===H||(Ft(Nn?[Nn]:[]),I(1)));let Br=(0,M.useCallback)(e=>{let t=e.trim();t&&(Rt(null),Ft(e=>{if(e.includes(t))return e;let n=[...e,t];return Nr(n),I(1),n}))},[Nr,Rt,Ft,I]),Vr=(0,M.useCallback)(e=>{Ft(t=>{let n=e<0?[]:t.filter((t,n)=>n!==e);return n.length===0&&Rt(H),Nr(n),I(1),n})},[Nr,H,Rt,Ft,I]),Hr=z.join(` `).trim(),Ur=!!B.activeContextType&&(B.isDirty||Hr!==(X===`canvas`?Nn:B.savedSearchQuery||``));!e&&q!==null&&cn(null),(0,M.useEffect)(()=>{let t=!1;if(!e)return;let n=0,r=!1,i=(i=!1)=>{let a=++n;i&&ue(e,U),oe(e,U).then(i=>{!t&&a===n&&(r=!0,bn.current=`${e}/${U}`,cn(i))}).catch(()=>{!t&&a===n&&!r&&cn(null)})};i(!1);let a=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==U||i(!n?.cacheInvalidated)};window.addEventListener(`workspace:tree:refresh`,a);let o=Ce(e,Sr);return()=>{t=!0,o(),window.removeEventListener(`workspace:tree:refresh`,a)}},[e,U,Sr]),!(e&&X===`canvas`&&!G)&&P!==null&&Dt(null),(0,M.useEffect)(()=>{let t=!1;if(!(!e||X!==`canvas`||G))return se(e,H,U).then(e=>{t||Dt(e)}).catch(()=>{t||Dt(null)}),()=>{t=!0}},[e,H,U,X,G]);let Wr=async()=>{if(d){lt(!0);try{let t=await fe(e||d.id);f(t),s({title:`Success`,description:`Workspace started successfully`}),window.dispatchEvent(new CustomEvent(`workspaces:refresh`))}catch(e){let t=e instanceof Error?e.message:`Failed to start workspace`;s({title:`Error`,description:t,variant:`destructive`})}finally{lt(!1)}}},Gr=async t=>{if(!d)return;let n=c({title:`Removing…`,description:`Document from "${H}"`});try{await S(e||d.id,[t],H,[],U,$r,{trashIfOrphaned:!0}),R(e||d.id,U,H),v(e=>e.filter(e=>e.id!==t)),k(e=>Math.max(0,e-1)),n.done({title:`Success`,description:`Document removed from workspace path.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},Kr=async t=>{if(!d)return;let n=c({title:`Deleting…`,description:`Document from "${H}"`});try{await ge(e||d.id,[t],H,[],U,$r),R(e||d.id,U,H),v(e=>e.filter(e=>e.id!==t)),k(e=>Math.max(0,e-1)),n.done({title:`Success`,description:`Document deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},qr=async t=>{if(!d)return;let n=c({title:`Removing…`,description:`${t.length} document(s) from "${H}"`});try{await S(e||d.id,t,H,[],U,$r,{trashIfOrphaned:!0}),R(e||d.id,U,H),v(e=>e.filter(e=>!t.includes(e.id))),k(e=>Math.max(0,e-t.length)),n.done({title:`Success`,description:`${t.length} document(s) removed.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},Jr=async t=>{if(!d)return;let n=c({title:`Deleting…`,description:`${t.length} document(s)`});try{await ge(e||d.id,t,H,[],U,$r),R(e||d.id,U,H),v(e=>e.filter(e=>!t.includes(e.id))),k(e=>Math.max(0,e-t.length)),n.done({title:`Success`,description:`${t.length} document(s) deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},Yr=async t=>{if(!d)return;let n=c({title:`Destroying…`,description:`Document and its backend copies`});try{let r=await x(e||d.id,[t]);if(r.failed?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}v(e=>e.filter(e=>e.id!==t)),k(e=>Math.max(0,e-1)),n.done({title:`Destroyed`,description:`Document removed from all backends.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy document`,variant:`destructive`})}},Xr=async t=>{if(!d)return;let n=c({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await x(e||d.id,t),i=new Set(r.successful?.filter(e=>e.docDeleted).map(e=>e.id)??[]);v(e=>e.filter(e=>!i.has(e.id))),k(e=>Math.max(0,e-i.size));let a=[r.successful?.length?`${r.successful.length} destroyed`:null,r.failed?.length?`${r.failed.length} failed`:null].filter(Boolean).join(`, `);r.failed?.length?n.fail({title:`Destroy incomplete`,description:a,variant:`destructive`}):n.done({title:`Destroyed`,description:a||`No documents destroyed`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy documents`,variant:`destructive`})}},Zr=t=>{e&&(We({workspaceName:e,documentIds:t,operation:`copy`,sourcePath:H,sourceTreeName:U}),s({title:`Copied`,description:`${t.length} document(s) copied to clipboard`}))},Qr=t=>{e&&(We({workspaceName:e,documentIds:t,operation:`cut`,sourcePath:H,sourceTreeName:U}),s({title:`Cut`,description:`${t.length} document(s) cut to clipboard`}))},$r=O(U),ei=async(t,n,r={})=>{if(!e)return!1;let i=r.targetTreeName??U,a=r.targetTreeType??$r,o=r.move??ut?.operation===`cut`,s=r.sourceTreeName||ut?.sourceTreeName,l=r.sourcePath||ut?.sourcePath,u=c({title:o?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let c=await Ke(e,{treeName:i,treeType:a,path:t},n,{move:o,sourcePath:l,sourceTreeName:s});return R(e,i,t),o&&l&&s&&R(e,s,l),u.done({title:`Success`,description:c}),r.move===void 0&&We(null),await $(),!0}catch(e){return u.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},ti=async(t,n)=>{if(!e)return!1;try{let r=(await D(e,n,t,U,$r)).length>0;return r&&(we(e,U,n),s({title:`Success`,description:`Imported ${t.length} document(s) to "${n}"`})),r}catch(e){return s({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},ni=async()=>{if(!d||or===0||_r||gr.current||window.prompt(`Type PURGE to permanently delete all ${or} matching documents across all pages.`)!==`PURGE`)return;gr.current=!0,hr(!0);let t=c({title:`Purging…`,description:`${or} matching document(s)`});try{let n=await ye(e||d.id,ur,or);n.deleted===n.requested?t.done({title:`Success`,description:`${n.deleted} document(s) purged.`}):t.fail({title:`Purge incomplete`,description:`${n.deleted} of ${n.requested} document(s) purged. Refresh and review the remaining results before retrying.`})}catch(e){t.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to purge documents`,variant:`destructive`})}finally{R(e||d.id,U,H),await $({silent:!0}),gr.current=!1,hr(!1)}},ri=()=>kr(H,!0),ii=async()=>{if(!(!e||!dt||!ht.trim())){vt(!0);try{let t=ht.trim(),n=dt.parentPath,r=n===`/`?`/${t}`:`${n}/${t}`,i={...B.filters,features:{...B.filters.features,allOf:An}};await ve(e,r,U,dt.captureView?{metadata:{toolbox:i},querySpec:{features:i.features,filters:[...Fe(B.filters.timeline),...Pe(B.filters.geo)],query:Hr||void 0,sort:B.filters.sort?.sortBy?B.filters.sort:null}}:{}),pt(null),ue(e,U);try{let t=await oe(e,U,{force:!0});cn(t)}catch{}window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e}})),o(Be(e,r,U))}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to create canvas`,variant:`destructive`})}finally{vt(!1)}}},ai=async()=>{if(!(!e||X!==`canvas`)){St(!0);try{let t=P||await T(e,H,U);Dt(t);let n=`${window.location.origin}${t.url}`;await navigator.clipboard?.writeText(n),s({title:`Public canvas link copied`,description:n})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to share canvas`,variant:`destructive`})}finally{St(!1)}}},oi=async()=>{if(P){St(!0);try{await _e(P.code),Dt(null),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:U}})),s({title:`Canvas unshared`,description:`The public link no longer works.`})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to unshare canvas`,variant:`destructive`})}finally{St(!1)}}},si=async()=>{if(!e||X!==`canvas`||H===`/`)return;let t=Pn?.label||H.split(`/`).pop()||`canvas`,n=P?` Its public link will stop working.`:``;if(window.confirm(`Delete canvas "${t}"? This cannot be undone.${n}`)){Et(!0);try{if(P)await _e(P.code),Dt(null);else if(Y?.locked){s({title:`Canvas is locked`,description:`Unlock it before deleting.`,variant:`destructive`});return}await C(e,H,!1,U);let n=H.split(`/`).filter(Boolean);n.pop();let r=n.length?`/${n.join(`/`)}`:`/`;window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:U}})),o(Be(e,r,U)),s({title:`Canvas deleted`,description:`"${t}" was removed.`})}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to delete canvas`,variant:`destructive`})}finally{Et(!1)}}},ci=(0,M.useCallback)(async t=>{if(!e||!J)return;let n={treeName:U,path:H},r=dn===`left`?n:J,i=dn===`left`?J:n,a=dn===`left`?pn:vn;if(a.length===0){s({title:`Nothing selected`,description:`Tick documents in the focused pane first.`});return}let o=O(i.treeName),l=c({title:t?`Moving…`:`Copying…`,description:`${a.length} document(s) → "${i.path}"`});try{if(!await w(e,i.path,a,i.treeName,o)){l.done();return}if(R(e,i.treeName,i.path),t){let t=O(r.treeName);await S(e,a,r.path,[],r.treeName,t),R(e,r.treeName,r.path)}[r,i].forEach(t=>window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t.path,treeName:t.treeName}}))),l.done({title:t?`Moved`:`Copied`,description:`${a.length} document(s) → "${i.path}"`})}catch(e){l.fail({title:`Error`,description:e instanceof Error?e.message:`Transfer failed`,variant:`destructive`})}},[e,J,dn,U,H,pn,vn,s,c]);if((0,M.useEffect)(()=>{if(!J)return;let e=e=>{if(e.key!==`F5`&&e.key!==`F6`)return;let t=e.target;t.tagName!==`INPUT`&&t.tagName!==`TEXTAREA`&&(e.preventDefault(),ci(e.key===`F6`))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[J,ci]),p)return(0,N.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,N.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,N.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,N.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading workspace...`})]})});if(!d)return(0,N.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Workspace not found.`});let li=X===`canvas`&&!G&&!!Y,ui=!li&&!W&&Sn?(0,N.jsx)(Ze,{views:Dn,activeId:On,onSelect:jn,onSave:Mn,accentColor:Me(d.color),onOpenToSide:e=>{ln({treeName:U,path:H,viewId:e}),fn(`right`)}}):void 0,di=tn||d.status!==`active`?(0,N.jsxs)(N.Fragment,{children:[tn&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>{rn(!nn),I(1)},"aria-pressed":nn,className:h(`min-h-10 rounded-md border px-2 text-xs`,nn&&`bg-warning/15 text-warning`),children:`Unfiled only`}),d.status!==`active`&&(0,N.jsx)(`button`,{type:`button`,onClick:Wr,disabled:ct,className:`min-h-10 rounded-md border px-2 text-xs`,children:ct?`Starting…`:`Start`})]}):void 0,fi=Ee(U,H)?H===`/Trash`?(0,N.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,N.jsx)(at,{workspaceName:e||d.id})}):(0,N.jsx)(ft,{workspace:e||d.id,path:H,onNavigate:t=>o(Be(e,t,`backends`))},e):(0,N.jsx)(Xe,{navigationTabs:ui,navigationActions:di,onBack:_n,accentColor:Me(d.color),urlType:G?O(U)===`directory`?`${U}-layer`:`context-layer`:X===`canvas`?`canvas`:O(U)===`directory`?U:`context`,urlDisplay:Gn,contextPath:H,treeName:U,workspaceId:e||d.id,workspaceLabel:d.label||d.name,workspaceIcon:d.icon,documentSchema:kn,documents:lr,isLoading:ie,totalCount:or,currentPage:F,pageSize:L,onPageChange:I,onPageSizeChange:e=>{jt(e),I(1)},onRemoveDocument:H===`/`?void 0:Gr,onDeleteDocument:Kr,onDestroyDocument:Yr,onRemoveDocuments:H===`/`?void 0:qr,onDeleteDocuments:Jr,onDestroyDocuments:Xr,onCopyDocuments:Zr,onCutDocuments:Qr,onPasteDocuments:ei,onImportDocuments:W?void 0:ti,onSelectionChange:mn,onBrowseTree:()=>gn(`workspaces`,`detail`,e??null),onBrowseWorkspaces:()=>hn(`workspaces`),onNavigatePath:t=>o(Be(e,t,U)),folders:xn,onOpenFolder:t=>o(Be(e,ze(t),U)),scope:j,onScopeChange:st,pastedDocumentIds:ut?.documentIds,linkTree:q,onPurgeDocuments:W?void 0:ni,disablePurgeDocuments:_r,canvasInfo:Pn??void 0,isCanvasPinned:Vn,onTogglePinCanvas:Bn?Wn:void 0,onSaveAsCanvas:q&&X!==`canvas`&&!G&&!W?ri:void 0,onShareCanvas:X===`canvas`&&!G?ai:void 0,onUnshareCanvas:P?oi:void 0,onDeleteCanvas:X===`canvas`&&!G?si:void 0,isSharingCanvas:xt,isDeletingCanvas:Tt,isCanvasShared:!!P,isCanvasLocked:!!Y?.locked,backendSearchQueries:z,onBackendSearch:Br,serverSort:B.filters.sort,onServerSortChange:Bt,onRemoveBackendQuery:Vr,canSaveChanges:Ur,isSavingChanges:B.isSaving,onSaveChanges:zt,contentBanner:A&&Oe?(0,N.jsx)(kt,{data:Oe,className:`mb-3`}):null,children:li&&Y?(0,N.jsx)(xe,{workspaceId:e||d.id,treeName:U,path:H,layerId:Y.id,querySpec:Y.querySpec,metadata:Y.metadata,isLocked:!!Y.locked,fetchDocuments:B.isDirty?qn:void 0}):!W&&Q.kind===`columns`?(0,N.jsx)(tt,{documents:lr,workspaceId:e||d.id,columns:Q.columns??[],onColumnsChange:e=>Mn(Dn.map(t=>t.id===Q.id?{...t,columns:e}:t))}):!W&&Q.kind===`app`&&Q.app&&Q.app!==`notes`?(0,N.jsx)($e,{app:Q.app,workspaceId:e||d.id,treeName:U,path:H}):null});return(0,N.jsxs)(Ue,{workspaceId:e||d.id,treeName:U,path:H,headerOnly:!0,className:`relative flex flex-col h-full min-h-0`,children:[(0,N.jsx)(mt,{workspaceId:d.id,workspaceName:d.label||d.name},d.id),Ee(U,H)&&(0,N.jsx)(Se,{workspace:d.label||d.name,workspaceIcon:d.icon,tree:U,path:H,onBack:_n,onBrowseTree:()=>gn(`workspaces`,`detail`,e||d.id),onBrowseWorkspaces:()=>hn(`workspaces`),onNavigatePath:t=>o(Be(e,t,U)),accentColor:Me(d.color)}),dt&&(0,N.jsx)(`div`,{className:`shrink-0 px-2 pt-2`,children:(0,N.jsx)(Je,{title:`New canvas`,onClose:()=>pt(null),children:(0,N.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ii()},className:`space-y-4`,children:[(0,N.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`canvas-name`,className:`mb-1 block text-sm font-medium`,children:`Name`}),(0,N.jsx)(`input`,{id:`canvas-name`,className:`w-full rounded-md border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:`Canvas name…`,value:ht,onChange:e=>gt(e.target.value),onKeyDown:e=>{e.key===`Escape`&&pt(null)},autoFocus:!0})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`span`,{className:`mb-1 block text-sm font-medium`,children:`Parent path`}),(0,N.jsx)(`div`,{className:`flex h-10 items-center rounded-md bg-muted px-3 font-mono text-sm text-muted-foreground`,children:dt.parentPath===`/`?`/`:dt.parentPath})]})]}),(0,N.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,N.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:dt.captureView,onChange:e=>pt({...dt,captureView:e.target.checked})}),(0,N.jsxs)(`span`,{children:[`Capture the current view`,(0,N.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Freezes the active filters, search and sort into the canvas.`})]})]}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(g,{type:`submit`,disabled:!ht.trim()||_t,children:_t?`Creating…`:`Create canvas`}),(0,N.jsx)(g,{type:`button`,variant:`outline`,onClick:()=>pt(null),children:`Cancel`})]})]})})}),(0,N.jsxs)(`div`,{"data-canvas-panes":!0,className:`flex-1 min-h-0 flex gap-2`,children:[(0,N.jsx)(`div`,{"data-canvas-pane":!0,className:h(`flex-1 min-w-0 bg-background overflow-hidden`,J&&(dn===`left`?`ring-2 ring-primary`:`ring-1 ring-primary/20`)),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||fn(`left`)},children:fi}),J&&e&&(0,N.jsx)(Lt,{workspaceName:e,workspaceLabel:d.label||d.name,workspaceIcon:d.icon,pane:J,isFocused:dn===`right`,onFocus:()=>fn(`right`),onSelectionChange:yn,onNavigate:e=>ln(t=>t&&{...t,path:e,viewId:void 0}),onClose:()=>{ln(null),fn(`left`),yn([])}})]})]})}function It(e,t){if(!e||t===`/`)return e;let n=e;for(let e of t.split(`/`).filter(Boolean))if(n=n?.children?.find(t=>t.name===e)??null,!n)return null;return n}function Lt({workspaceName:e,workspaceLabel:t,workspaceIcon:n,pane:r,isFocused:i=!1,onFocus:a,onSelectionChange:o,onNavigate:s,onClose:c}){let{openM1Drawer:l,openM2Drawer:u}=Ve(),{showToast:d,showProgress:f}=re(),[p,m]=(0,M.useState)(null),[ee,g]=(0,M.useState)([]),[te,ne]=(0,M.useState)(!1),[_,v]=(0,M.useState)(0),[ie,y]=(0,M.useState)(1),[b,ae]=(0,M.useState)(50),C=O(r.treeName),w=It(p,r.path),se=w?.type===`canvas`,T=(0,M.useMemo)(()=>rt(p,r.path),[p,r.path]),E=r.viewId?nt(w?.metadata).find(e=>e.id===r.viewId)??null:null,ce=`${e}://${r.path===`/`?``:r.path.replace(/^\//,``)}`,le=et(E),D=(0,M.useCallback)(async()=>{if(Ee(r.treeName,r.path)){g([]),v(0),ne(!1);return}let t=Mt(e,r.treeName,r.path,ie,b,``,le??``),n=At.get(t);if(n){g(n.documents),v(n.totalCount);return}ne(!0);try{let n=await de(e,r.path,le?[le]:[],{limit:b,page:ie,treeName:r.treeName,treeType:C}),i=n.payload||[],a=n.totalCount||n.count||0;g(i),v(a),At.set(t,{documents:i,totalCount:a})}catch(e){d({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch side pane documents`,variant:`destructive`}),g([]),v(0)}finally{ne(!1)}},[e,r.path,r.treeName,C,b,ie,d,le]);(0,M.useEffect)(()=>{let t=!1,n=0,i=!1,a=(a=!1)=>{let o=++n;a&&ue(e,r.treeName),oe(e,r.treeName).then(e=>{!t&&o===n&&(i=!0,m(e))}).catch(()=>{!t&&o===n&&!i&&m(null)})};a(!1);let o=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==r.treeName||a(!n?.cacheInvalidated)};return window.addEventListener(`workspace:tree:refresh`,o),()=>{t=!0,window.removeEventListener(`workspace:tree:refresh`,o)}},[e,r.treeName]),(0,M.useEffect)(()=>{D()},[D]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||(Pt(e,n),wt(Ct(n),{tree:r.treeName,kind:O(r.treeName),path:r.path})&&(R(e,r.treeName,r.path),D()))};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[D,e,r.treeName,r.path]);let fe=Ge(e),pe=(0,M.useCallback)(async(t,n,i={})=>{let a=i.targetTreeName??r.treeName,o=i.targetTreeType??C,s=i.move??fe?.operation===`cut`,c=i.sourcePath||fe?.sourcePath,l=i.sourceTreeName||fe?.sourceTreeName,u=f({title:s?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let r=await Ke(e,{treeName:a,treeType:o,path:t},n,{move:s,sourcePath:c,sourceTreeName:l});return R(e,a,t),s&&c&&l&&R(e,l,c),u.done({title:`Success`,description:r}),i.move===void 0&&We(null),await D(),!0}catch(e){return u.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},[e,r.treeName,C,D,f,fe]),me=(0,M.useCallback)(()=>{R(e,r.treeName,r.path),D()},[e,r.treeName,r.path,D]),he=(0,M.useCallback)(async t=>{let n=f({title:`Removing…`,description:`${t.length} document(s) from "${r.path}"`});try{await S(e,t,r.path,[],r.treeName,C),me(),n.done({title:`Removed`,description:`${t.length} document(s) removed from "${r.path}"`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},[e,r.path,r.treeName,C,me,f]),_e=(0,M.useCallback)(async t=>{let n=f({title:`Deleting…`,description:`${t.length} document(s)`});try{await ge(e,t,r.path,[],r.treeName,C),me(),n.done({title:`Deleted`,description:`${t.length} document(s) deleted.`})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},[e,r.path,r.treeName,C,me,f]),ve=(0,M.useCallback)(async t=>{let n=f({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await x(e,t);if(r.failed?.length&&!r.successful?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}me();let i=`${r.successful?.length??0} document(s) destroyed${r.failed?.length?` · ${r.failed.length} failed`:``}.`;r.failed?.length?n.fail({title:`Destroy incomplete`,description:i,variant:`destructive`}):n.done({title:`Destroyed`,description:i})}catch(e){n.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to destroy documents`,variant:`destructive`})}},[e,me,f]);return(0,N.jsxs)(`div`,{className:h(`relative flex-1 min-w-0 rounded-(--sheet-radius) border bg-background overflow-hidden`,i?`ring-2 ring-primary`:`ring-1 ring-primary/20`),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||a()},children:[c&&(0,N.jsx)(`button`,{type:`button`,onClick:c,className:`absolute right-2 top-2 z-10 px-2 py-1 text-xs rounded-md border bg-background/90 hover:bg-accent`,children:`Close`}),Ee(r.treeName,r.path)?r.path===`/Trash`?(0,N.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,N.jsx)(at,{workspaceName:e})}):(0,N.jsx)(ft,{workspace:e,path:r.path,onNavigate:s||(()=>{})}):(0,N.jsx)(Xe,{frameContent:!1,onBrowseWorkspaces:()=>l(`workspaces`),onBrowseTree:()=>u(`workspaces`,`detail`,e),urlType:se?`canvas`:C===`directory`?r.treeName:`context`,urlDisplay:ce,contextPath:r.path,treeName:r.treeName,workspaceId:e,workspaceLabel:t,workspaceIcon:n,documentSchema:le,documents:ee,isLoading:te,totalCount:_,currentPage:ie,pageSize:b,onPageChange:y,onPageSizeChange:e=>{ae(e),y(1)},onRemoveDocument:r.path===`/`?void 0:e=>he([e]),onRemoveDocuments:r.path===`/`?void 0:he,onDeleteDocument:e=>_e([e]),onDeleteDocuments:_e,onDestroyDocument:e=>ve([e]),onDestroyDocuments:ve,onCopyDocuments:t=>We({workspaceName:e,documentIds:t,operation:`copy`,sourcePath:r.path,sourceTreeName:r.treeName}),onCutDocuments:t=>We({workspaceName:e,documentIds:t,operation:`cut`,sourcePath:r.path,sourceTreeName:r.treeName}),onPasteDocuments:pe,onSelectionChange:o,pastedDocumentIds:fe?.documentIds,linkTree:p,folders:T,onOpenFolder:s,onNavigatePath:s,canvasInfo:se?{label:w?.label,description:w?.description,color:w?.color}:void 0,children:E?.kind===`columns`?(0,N.jsx)(tt,{documents:ee,workspaceId:e,columns:E.columns??[],onColumnsChange:()=>{},readOnly:!0}):E?.kind===`app`&&E.app&&E.app!==`notes`?(0,N.jsx)($e,{app:E.app,workspaceId:e,treeName:r.treeName,path:r.path}):null})]})}export{z 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{t as r}from"./api-CA6WiiYM.js";import{n as i}from"./page-header-NyYSXjfY.js";import{t as a}from"./use-settings-back-D_MM9diy.js";var o=e(n(),1),s=t();function c(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function l({name:e,version:t,detail:n}){return(0,s.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 px-4 py-2.5`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`div`,{className:`text-sm font-medium truncate`,children:e}),n&&(0,s.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:n})]}),(0,s.jsx)(`code`,{className:`text-xs text-muted-foreground shrink-0`,children:t})]})}function u(){let[e,t]=(0,o.useState)(null),[n,u]=(0,o.useState)(null);(0,o.useEffect)(()=>{let e=!0;return r.get(`/ping`,{skipAuth:!0}).then(n=>{e&&t(n??{})}).catch(t=>{e&&u(t instanceof Error?t.message:`Failed to reach the server`)}),()=>{e=!1}},[]);let d=[e?.commit?`commit ${e.commit.slice(0,7)}`:null,typeof e?.uptime==`number`?`up ${c(e.uptime)}`:null].filter(Boolean).join(` · `),f=Object.entries(e?.components??{}).sort(([e],[t])=>e.localeCompare(t));return(0,s.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,s.jsx)(i,{className:`mb-6`,title:`About`,onBack:a(),description:`Versions of every Canvas component this installation is running.`}),(0,s.jsxs)(`div`,{className:`space-y-6`,children:[(0,s.jsxs)(`section`,{className:`rounded-md border border-border divide-y divide-border`,children:[(0,s.jsx)(l,{name:`Canvas Web`,detail:`this interface`,version:`v2.26.45`}),e?.version&&(0,s.jsx)(l,{name:e.productName||e.appName||`Canvas Server`,detail:d||void 0,version:`v${e.version}`})]}),f.length>0&&(0,s.jsxs)(`section`,{children:[(0,s.jsx)(`h2`,{className:`mb-2 px-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:`Server components`}),(0,s.jsx)(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:f.map(([e,t])=>(0,s.jsx)(l,{name:e,version:`v${t}`},e))})]}),n&&(0,s.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Server details unavailable: `,n]}),e?.sourceUrl&&(0,s.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.license?`Licensed ${e.license}. `:``,(0,s.jsx)(`a`,{href:e.sourceUrl,target:`_blank`,rel:`noreferrer`,className:`underline underline-offset-2 hover:text-foreground`,children:`Get the source code`}),`.`]})]})]})}export{u 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{t as r}from"./api-CA6WiiYM.js";import{n as i}from"./page-header-NyYSXjfY.js";import{t as a}from"./use-settings-back-D_MM9diy.js";var o=e(n(),1),s=t();function c(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function l({name:e,version:t,detail:n}){return(0,s.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 px-4 py-2.5`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`div`,{className:`text-sm font-medium truncate`,children:e}),n&&(0,s.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:n})]}),(0,s.jsx)(`code`,{className:`text-xs text-muted-foreground shrink-0`,children:t})]})}function u(){let[e,t]=(0,o.useState)(null),[n,u]=(0,o.useState)(null);(0,o.useEffect)(()=>{let e=!0;return r.get(`/ping`,{skipAuth:!0}).then(n=>{e&&t(n??{})}).catch(t=>{e&&u(t instanceof Error?t.message:`Failed to reach the server`)}),()=>{e=!1}},[]);let d=[e?.commit?`commit ${e.commit.slice(0,7)}`:null,typeof e?.uptime==`number`?`up ${c(e.uptime)}`:null].filter(Boolean).join(` · `),f=Object.entries(e?.components??{}).sort(([e],[t])=>e.localeCompare(t));return(0,s.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,s.jsx)(i,{className:`mb-6`,title:`About`,onBack:a(),description:`Versions of every Canvas component this installation is running.`}),(0,s.jsxs)(`div`,{className:`space-y-6`,children:[(0,s.jsxs)(`section`,{className:`rounded-md border border-border divide-y divide-border`,children:[(0,s.jsx)(l,{name:`Canvas Web`,detail:`this interface`,version:`v2.27.0`}),e?.version&&(0,s.jsx)(l,{name:e.productName||e.appName||`Canvas Server`,detail:d||void 0,version:`v${e.version}`})]}),f.length>0&&(0,s.jsxs)(`section`,{children:[(0,s.jsx)(`h2`,{className:`mb-2 px-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:`Server components`}),(0,s.jsx)(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:f.map(([e,t])=>(0,s.jsx)(l,{name:e,version:`v${t}`},e))})]}),n&&(0,s.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Server details unavailable: `,n]}),e?.sourceUrl&&(0,s.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.license?`Licensed ${e.license}. `:``,(0,s.jsx)(`a`,{href:e.sourceUrl,target:`_blank`,rel:`noreferrer`,className:`underline underline-offset-2 hover:text-foreground`,children:`Get the source code`}),`.`]})]})]})}export{u as default};
@@ -1 +1 @@
1
- import{l as e}from"./code-editor-BOIngd5F.js";import{_ as t,a as n,g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as i}from"./HomeFab-iC5BF7LV.js";var a=e(),o=[`note`,`todo`,`link`,`file`,`photo`];function s(){let{kind:e}=t(),s=r();return e===`sketch`?(0,a.jsx)(n,{to:`/apps/sketch?add=1`,replace:!0}):!e||!o.includes(e)?(0,a.jsx)(n,{to:`/home`,replace:!0}):(0,a.jsx)(i,{initialKind:e,onInitialCardClose:()=>s(`/home`)})}export{s as default};
1
+ import{l as e}from"./code-editor-BOIngd5F.js";import{_ as t,a as n,g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as i}from"./HomeFab-BVC6GyBo.js";var a=e(),o=[`note`,`todo`,`link`,`file`,`photo`];function s(){let{kind:e}=t(),s=r();return e===`sketch`?(0,a.jsx)(n,{to:`/apps/sketch?add=1`,replace:!0}):!e||!o.includes(e)?(0,a.jsx)(n,{to:`/home`,replace:!0}):(0,a.jsx)(i,{initialKind:e,onInitialCardClose:()=>s(`/home`)})}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{g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Cr as i,I as a,It as o,Pt as s,ei as c,rn as l,rt as u}from"./ui-DEgHnkQu.js";import{t as d}from"./button--VYZekMF.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,H as g,Nt as _,at as v,ot as y}from"./index-CTvqbEB8.js";import{n as b}from"./page-header-NyYSXjfY.js";import{n as ee,r as x,t as te}from"./useAgentModels-CI9XT6yc.js";import{t as ne}from"./form-panel-CEbNKttr.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[s,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)(i,{className:`h-4 w-4 text-success`});case`inactive`:return(0,C.jsx)(i,{className:`h-4 w-4 text-warning`});case`error`:return(0,C.jsx)(i,{className:`h-4 w-4 text-destructive`});default:return(0,C.jsx)(i,{className:`h-4 w-4 text-muted-foreground`})}},g=()=>{switch(e.llmProvider){case`anthropic`:return(0,C.jsx)(c,{className:`h-4 w-4 text-warning`});case`openai`:return(0,C.jsx)(c,{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)(c,{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:s,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:s,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(u,{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)(l,{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,o]=(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=_(),[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{o(!0);let e=await h();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{o(!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 g(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 y(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)(s,{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)(s,{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
+ 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{Cr as i,I as a,It as o,Pt as s,ei as c,rn as l,rt as u}from"./ui-DEgHnkQu.js";import{t as d}from"./button--VYZekMF.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,H as g,Nt as _,at as v,ot as y}from"./index-NOhHv2VY.js";import{n as b}from"./page-header-NyYSXjfY.js";import{n as ee,r as x,t as te}from"./useAgentModels-DTZNaSRA.js";import{t as ne}from"./form-panel-CEbNKttr.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[s,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)(i,{className:`h-4 w-4 text-success`});case`inactive`:return(0,C.jsx)(i,{className:`h-4 w-4 text-warning`});case`error`:return(0,C.jsx)(i,{className:`h-4 w-4 text-destructive`});default:return(0,C.jsx)(i,{className:`h-4 w-4 text-muted-foreground`})}},g=()=>{switch(e.llmProvider){case`anthropic`:return(0,C.jsx)(c,{className:`h-4 w-4 text-warning`});case`openai`:return(0,C.jsx)(c,{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)(c,{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:s,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:s,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(u,{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)(l,{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,o]=(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=_(),[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{o(!0);let e=await h();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{o(!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 g(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 y(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)(s,{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)(s,{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{Kr as r,Xt as i,Yt as a,et as o}from"./ui-DEgHnkQu.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-CKSpS96u.js";import{t as x}from"./use-theme-DaxpiICf.js";import{Dt as S,Et as C,Tt as w,a as T,c as E,d as D,f as O,i as k,l as A,m as j,n as M,o as N,p as P,r as F,s as I,t as L,u as R}from"./index-CTvqbEB8.js";import{n as z}from"./page-header-NyYSXjfY.js";import{t as B}from"./use-settings-back-D_MM9diy.js";var V=e(n(),1),H=t(),U={system:i,light:o,dark:a};function W(){let{theme:e,scheme:t,density:n,resolvedScheme:i,setTheme:a,setScheme:o,setDensity:T,reset:E}=x(),D=l(),k=u(),A=h(),M=p(),N=S(),F=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:j.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:P.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:O.map(e=>({id:e.id,label:e.name,title:e.description})),value:n,onChange:T}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:O.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:A,onChange:_}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:y.find(e=>e.id===A)?.description}),A===`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:F,onChange:b}),(0,H.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[v.find(e=>e.id===F)?.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:w.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:w.find(e=>e.id===N)?.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:k,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:D?`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:M,onChange:d})]}),(0,H.jsx)(G,{}),(0,H.jsx)(`section`,{children:(0,H.jsx)(`button`,{type:`button`,onClick:()=>{E(),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)(N),[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 E().then(()=>{e||(t(N()),a(!1))}),()=>{e=!0}},[]);let l=async(e,n)=>{if(!c.current){c.current=!0,s(!0);try{let i=n?{...e,image:await I(n)}:e;await A(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&&F(e.image)===null,f=R(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`})}),L.map(t=>(0,H.jsx)(q,{label:t.title,title:`${t.title} — suits the ${t.scheme} scheme`,isActive:F(e.image)===t.id,onSelect:()=>l({...e,image:k(t.id)}),children:(0,H.jsx)(`img`,{src:T(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:D(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:M.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=L.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{Kr as r,Xt as i,Yt as a,et as o}from"./ui-DEgHnkQu.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-CKSpS96u.js";import{t as x}from"./use-theme-DaxpiICf.js";import{Dt as S,Et as C,Tt as w,a as T,c as E,d as D,f as O,i as k,l as A,m as j,n as M,o as N,p as P,r as F,s as I,t as L,u as R}from"./index-NOhHv2VY.js";import{n as z}from"./page-header-NyYSXjfY.js";import{t as B}from"./use-settings-back-D_MM9diy.js";var V=e(n(),1),H=t(),U={system:i,light:o,dark:a};function W(){let{theme:e,scheme:t,density:n,resolvedScheme:i,setTheme:a,setScheme:o,setDensity:T,reset:E}=x(),D=l(),k=u(),A=h(),M=p(),N=S(),F=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:j.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:P.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:O.map(e=>({id:e.id,label:e.name,title:e.description})),value:n,onChange:T}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:O.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:A,onChange:_}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:y.find(e=>e.id===A)?.description}),A===`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:F,onChange:b}),(0,H.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[v.find(e=>e.id===F)?.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:w.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:w.find(e=>e.id===N)?.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:k,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:D?`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:M,onChange:d})]}),(0,H.jsx)(G,{}),(0,H.jsx)(`section`,{children:(0,H.jsx)(`button`,{type:`button`,onClick:()=>{E(),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)(N),[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 E().then(()=>{e||(t(N()),a(!1))}),()=>{e=!0}},[]);let l=async(e,n)=>{if(!c.current){c.current=!0,s(!0);try{let i=n?{...e,image:await I(n)}:e;await A(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&&F(e.image)===null,f=R(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`})}),L.map(t=>(0,H.jsx)(q,{label:t.title,title:`${t.title} — suits the ${t.scheme} scheme`,isActive:F(e.image)===t.id,onSelect:()=>l({...e,image:k(t.id)}),children:(0,H.jsx)(`img`,{src:T(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:D(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:M.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=L.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 +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{jt as s,xn as c}from"./workspace-4hWrSEku.js";import{p as l}from"./context-DY40EDc6.js";import{t as u}from"./registry-g1SKt_fD.js";import{t as d}from"./applet-target-LvhUEvE5.js";var f=e(n(),1),p=t(),m=`universe`;function h(){let{appletId:e}=r(),[t,n]=a(),h=u.find(t=>t.id===e),g=t.get(`context`),_=t.get(`workspace`)||m,v=t.get(`path`)||`/`,y=t.get(`tree`)||`context`,b=t.get(`add`)===`1`,x=(0,f.useMemo)(()=>g?{mode:`context`,contextId:g}:{mode:`workspace`,workspaceName:_,path:v,treeName:y,treeType:c(y)},[g,_,v,y]),[S,C]=(0,f.useState)([]),[w,T]=(0,f.useState)([]);(0,f.useEffect)(()=>{s().then(C).catch(()=>C([])),l().then(T).catch(()=>T([]))},[]);let[E,D]=(0,f.useState)(v),[O,k]=(0,f.useState)(v);O!==v&&(k(v),D(v));let A=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(!h)return(0,p.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col items-center justify-center gap-3 surface-desk`,children:[(0,p.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Unknown app`,e?` "${e}"`:``,`.`]}),(0,p.jsx)(`div`,{className:`flex gap-2`,children:u.map(e=>(0,p.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 j=g?`context`:`path`;return(0,p.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col surface-desk p-shell gap-shell`,children:[(0,p.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,p.jsx)(h.icon,{className:`h-4 w-4 text-muted-foreground`}),(0,p.jsx)(`span`,{className:`text-sm font-semibold`,children:h.label}),(0,p.jsx)(`div`,{className:`ml-2 flex overflow-hidden rounded-md border border-border`,children:[`path`,`context`].map(e=>(0,p.jsx)(`button`,{type:`button`,onClick:()=>{e!==j&&A(e===`path`?{context:null}:{context:w[0]?.id??``,workspace:null,path:null,tree:null})},className:o(`px-2.5 py-1 text-xs capitalize transition-colors`,j===e?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e},e))}),j===`path`?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`select`,{value:_,onChange:e=>A({workspace:e.target.value,path:`/`}),className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Workspace`,children:[!S.some(e=>e.name===_)&&(0,p.jsx)(`option`,{value:_,children:_}),S.map(e=>(0,p.jsx)(`option`,{value:e.name,children:e.label||e.name},e.id))]}),(0,p.jsx)(`input`,{value:E,onChange:e=>D(e.target.value),onBlur:()=>{let e=E.trim()||`/`;e!==v&&A({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,p.jsxs)(`select`,{value:g??``,onChange:e=>A({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:[!g&&(0,p.jsx)(`option`,{value:``,children:`Pick a context…`}),w.map(e=>(0,p.jsxs)(`option`,{value:e.id,children:[e.id,e.url?` (${e.url})`:``]},e.id))]}),(0,p.jsx)(`div`,{className:`grow`})]}),(0,p.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border bg-card shadow-elevation-2`,children:j===`context`&&!g?(0,p.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 `,h.label,` to it.`]}):(0,p.jsx)(d,{target:x,children:(0,p.jsx)(h.Component,{autoAdd:b},JSON.stringify(x))})})]})}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{_ as r,r as i,v as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./utils-2pl1SbIp.js";import{jt as s,xn as c}from"./workspace-4hWrSEku.js";import{p as l}from"./context-DY40EDc6.js";import{t as u}from"./registry-D7HyG001.js";import{t as d}from"./applet-target-LvhUEvE5.js";var f=e(n(),1),p=t(),m=`universe`;function h(){let{appletId:e}=r(),[t,n]=a(),h=u.find(t=>t.id===e),g=t.get(`context`),_=t.get(`workspace`)||m,v=t.get(`path`)||`/`,y=t.get(`tree`)||`context`,b=t.get(`add`)===`1`,x=(0,f.useMemo)(()=>g?{mode:`context`,contextId:g}:{mode:`workspace`,workspaceName:_,path:v,treeName:y,treeType:c(y)},[g,_,v,y]),[S,C]=(0,f.useState)([]),[w,T]=(0,f.useState)([]);(0,f.useEffect)(()=>{s().then(C).catch(()=>C([])),l().then(T).catch(()=>T([]))},[]);let[E,D]=(0,f.useState)(v),[O,k]=(0,f.useState)(v);O!==v&&(k(v),D(v));let A=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(!h)return(0,p.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col items-center justify-center gap-3 surface-desk`,children:[(0,p.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Unknown app`,e?` "${e}"`:``,`.`]}),(0,p.jsx)(`div`,{className:`flex gap-2`,children:u.map(e=>(0,p.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 j=g?`context`:`path`;return(0,p.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col surface-desk p-shell gap-shell`,children:[(0,p.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,p.jsx)(h.icon,{className:`h-4 w-4 text-muted-foreground`}),(0,p.jsx)(`span`,{className:`text-sm font-semibold`,children:h.label}),(0,p.jsx)(`div`,{className:`ml-2 flex overflow-hidden rounded-md border border-border`,children:[`path`,`context`].map(e=>(0,p.jsx)(`button`,{type:`button`,onClick:()=>{e!==j&&A(e===`path`?{context:null}:{context:w[0]?.id??``,workspace:null,path:null,tree:null})},className:o(`px-2.5 py-1 text-xs capitalize transition-colors`,j===e?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e},e))}),j===`path`?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`select`,{value:_,onChange:e=>A({workspace:e.target.value,path:`/`}),className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Workspace`,children:[!S.some(e=>e.name===_)&&(0,p.jsx)(`option`,{value:_,children:_}),S.map(e=>(0,p.jsx)(`option`,{value:e.name,children:e.label||e.name},e.id))]}),(0,p.jsx)(`input`,{value:E,onChange:e=>D(e.target.value),onBlur:()=>{let e=E.trim()||`/`;e!==v&&A({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,p.jsxs)(`select`,{value:g??``,onChange:e=>A({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:[!g&&(0,p.jsx)(`option`,{value:``,children:`Pick a context…`}),w.map(e=>(0,p.jsxs)(`option`,{value:e.id,children:[e.id,e.url?` (${e.url})`:``]},e.id))]}),(0,p.jsx)(`div`,{className:`grow`})]}),(0,p.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border bg-card shadow-elevation-2`,children:j===`context`&&!g?(0,p.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 `,h.label,` to it.`]}):(0,p.jsx)(d,{target:x,children:(0,p.jsx)(h.Component,{autoAdd:b},JSON.stringify(x))})})]})}export{h 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{r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Hn as i,Qt as a,Rt as o,Zt as s,an as c,bn as l,hr as u}from"./ui-DEgHnkQu.js";import{B as d,ot as f}from"./workspace-4hWrSEku.js";import{n as p,r as m}from"./use-canvas-pins-q5Tncavk.js";import{t as h}from"./useToastHelpers-CRrpIIdY.js";import{h as g}from"./index-CTvqbEB8.js";import{t as _}from"./HomeFab-iC5BF7LV.js";var v=e(n(),1),y=t();function b(e){let t=`${e.workspaceName}\0${e.treeName}\0${e.path}`,[n,r]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let n=!1;return f(e.workspaceName,e.treeName).then(i=>{n||r({key:t,node:d(i,e.path)})}).catch(()=>{n||r({key:t,node:null})}),()=>{n=!0}},[t,e.workspaceName,e.treeName,e.path]),!n||n.key!==t?{state:`loading`}:n.node?{state:`ready`,node:n.node}:{state:`missing`}}function x(e){let t=`/workspaces/${encodeURIComponent(e.workspaceName)}`,n=e.path.replace(/^\//,``);return e.treeName===`context`?`${t}/path/${n}`:`${t}/trees/${encodeURIComponent(e.treeName)}/path/${n}`}var S=`application/x-canvas-pin`;function C({pin:e,onUnpin:t,onMinimize:n,onDropPin:d}){let f=b(e),[p,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(null),C=!!d&&!p,w=e=>{let t=e.currentTarget.getBoundingClientRect();return e.clientX>t.left+t.width/2?`after`:`before`},T=C?{onDragOver:e=>{e.dataTransfer.types.includes(`application/x-canvas-pin`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,_(w(e)))},onDragLeave:()=>_(null),onDrop:t=>{let n=t.dataTransfer.getData(S);_(null),!(!n||n===e.id)&&(t.preventDefault(),d?.(n,w(t)===`after`))}}:{},E=f.state===`ready`?f.node:null,D=E?.label||e.label||e.path.split(`/`).filter(Boolean).pop()||`Canvas`,O=E?.color;return(0,v.useEffect)(()=>{if(!p)return;let e=e=>{e.key===`Escape`&&h(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[p]),(0,y.jsxs)(`section`,{...T,className:p?`fixed inset-0 z-picker flex flex-col bg-background`:`flex flex-col rounded-(--card-radius) border bg-background overflow-hidden min-h-0 min-w-0 ${g?`ring-2 ring-primary/60`:``}`,children:[(0,y.jsxs)(`header`,{draggable:C,onDragStart:C?t=>{t.dataTransfer.setData(S,e.id),t.dataTransfer.effectAllowed=`move`}:void 0,className:`flex items-center gap-2 px-3 py-2 border-b bg-muted/20 shrink-0 min-w-0 ${C?`cursor-grab active:cursor-grabbing`:``}`,children:[C&&(0,y.jsx)(i,{className:`w-3.5 h-3.5 shrink-0 text-muted-foreground/60`,"aria-hidden":!0}),O&&(0,y.jsx)(`div`,{className:`w-1 h-5 rounded-full shrink-0`,style:{backgroundColor:O}}),(0,y.jsx)(l,{className:`w-4 h-4 shrink-0 text-primary`}),(0,y.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,y.jsx)(`span`,{className:`text-sm font-semibold leading-tight truncate`,children:D}),(0,y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground truncate leading-tight font-mono`,children:[e.workspaceName,`://`,e.path.replace(/^\//,``)]})]}),n&&(0,y.jsx)(`button`,{type:`button`,onClick:n,title:`Minimize to tab bar`,"aria-label":`Minimize to tab bar`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,children:(0,y.jsx)(s,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{type:`button`,onClick:()=>h(e=>!e),"aria-pressed":p,title:p?`Restore tile (Esc)`:`Fill view area`,"aria-label":p?`Restore tile`:`Fill view area`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,children:p?(0,y.jsx)(a,{className:`w-3.5 h-3.5`}):(0,y.jsx)(c,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(r,{to:x(e),title:`Open in workspace`,"aria-label":`Open in workspace`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,children:(0,y.jsx)(u,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{type:`button`,onClick:t,title:`Unpin from home`,"aria-label":`Unpin from home`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-destructive/10 hover:text-destructive transition-colors`,children:(0,y.jsx)(o,{className:`w-3.5 h-3.5`})})]}),(0,y.jsxs)(`div`,{className:`flex-1 min-h-0`,children:[f.state===`loading`&&(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:`Loading…`}),f.state===`missing`&&(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 px-4 text-center`,children:[(0,y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This canvas is no longer available.`}),(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`It may have been renamed, moved or deleted.`}),(0,y.jsx)(`button`,{type:`button`,onClick:t,className:`mt-1 px-2.5 py-1 text-xs border rounded-md hover:bg-accent`,children:`Remove pin`})]}),f.state===`ready`&&(0,y.jsx)(m,{workspaceId:e.workspaceName,treeName:e.treeName,path:e.path,layerId:f.node.id,querySpec:f.node.querySpec,metadata:f.node.metadata,readOnly:!0})]})]})}function w(e){return e.label||e.path.split(`/`).filter(Boolean).pop()||`Canvas`}function T({pins:e,onRestore:t}){let[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(e.length);return i!==e.length&&(a(e.length),e.length===0&&r(!1)),e.length===0?null:(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`div`,{className:`pointer-events-none absolute bottom-0 left-0 right-0 z-40 max-md:hidden`,children:(0,y.jsx)(`div`,{className:`pointer-events-auto flex items-end gap-1 overflow-x-auto px-3 pr-28 pb-safe-bottom`,children:e.map(e=>(0,y.jsxs)(`button`,{type:`button`,onClick:()=>t(e.id),title:`Restore ${w(e)}`,className:`flex max-w-[180px] shrink-0 items-center gap-1.5 rounded-t-lg border border-b-0 bg-background px-3 py-1.5 text-xs shadow-elevation-1 hover:bg-accent`,children:[(0,y.jsx)(l,{className:`h-3.5 w-3.5 shrink-0 text-primary`}),(0,y.jsx)(`span`,{className:`truncate`,children:w(e)})]},e.id))})}),n&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`div`,{className:`fixed inset-0 z-drawer md:hidden`,onClick:()=>r(!1),"aria-hidden":!0}),(0,y.jsx)(`div`,{className:`fixed bottom-rail-stack left-2 z-rail w-60 max-w-[calc(100vw-1rem)] rounded-xl border bg-card p-1.5 shadow-elevation-5 animate-fade-in md:hidden touch-target`,children:e.map(e=>(0,y.jsxs)(`button`,{type:`button`,onClick:()=>t(e.id),className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-sm hover:bg-accent`,children:[(0,y.jsx)(l,{className:`h-4 w-4 shrink-0 text-primary`}),(0,y.jsx)(`span`,{className:`truncate`,children:w(e)})]},e.id))})]}),(0,y.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),"aria-label":n?`Close minimized canvases`:`Minimized canvases (${e.length})`,className:`fixed bottom-rail-inset left-16 z-nav flex h-12 w-12 items-center justify-center rounded-full bg-foreground text-background shadow-elevation-4 md:hidden`,children:[(0,y.jsx)(l,{className:`h-5 w-5`}),(0,y.jsx)(`span`,{className:`absolute -top-1 -right-1 flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-semibold`,children:e.length})]})]})}function E(){let{pins:e,unpin:t,movePin:n,setMinimized:r,isLoading:i}=p(),{showErrorToast:a}=h(),[o,s]=(0,v.useState)(new Set),c=(0,v.useRef)(e);(0,v.useEffect)(()=>{c.current=e},[e]);let l=e=>{r(e,!0).catch(()=>a(`Could not save minimized state`))},u=t=>{s(e=>{let n=new Set(e);return n.delete(t),n}),e.find(e=>e.id===t)?.minimized&&r(t,!1).catch(()=>a(`Could not save restored state`))},d=(0,v.useCallback)(e=>{s(e?new Set(c.current.filter(e=>!e.minimized).map(e=>e.id)):new Set)},[]),f=e.filter(e=>!g(e,o)),m=e.filter(e=>g(e,o)),b=(t,r,i)=>{let a=e.findIndex(e=>e.id===r.id);if(a===-1)return;let o=i?e[a+1]?.id??null:r.id;n(t,o)};return(0,y.jsxs)(`div`,{className:`relative h-full`,children:[(0,y.jsx)(`div`,{className:`h-full overflow-y-auto`,children:i?(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:`Loading…`}):(0,y.jsx)(`div`,{className:`grid gap-4 p-4 h-full grid-cols-[repeat(auto-fit,minmax(min(640px,100%),1fr))] auto-rows-fr ${m.length>0?`md:pb-12`:``}`,children:f.map(e=>(0,y.jsx)(C,{pin:e,onUnpin:()=>{t(e.id)},onMinimize:()=>l(e.id),onDropPin:(t,n)=>b(t,e,n)},e.id))})}),(0,y.jsx)(`div`,{className:`pointer-events-none absolute inset-0`,children:(0,y.jsx)(_,{onCardsOpenChange:d})}),(0,y.jsx)(T,{pins:m,onRestore:u})]})}export{E 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{r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Hn as i,Qt as a,Rt as o,Zt as s,an as c,bn as l,hr as u}from"./ui-DEgHnkQu.js";import{B as d,ot as f}from"./workspace-4hWrSEku.js";import{n as p,r as m}from"./use-canvas-pins-q5Tncavk.js";import{t as h}from"./useToastHelpers-CRrpIIdY.js";import{h as g}from"./index-NOhHv2VY.js";import{t as _}from"./HomeFab-BVC6GyBo.js";var v=e(n(),1),y=t();function b(e){let t=`${e.workspaceName}\0${e.treeName}\0${e.path}`,[n,r]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let n=!1;return f(e.workspaceName,e.treeName).then(i=>{n||r({key:t,node:d(i,e.path)})}).catch(()=>{n||r({key:t,node:null})}),()=>{n=!0}},[t,e.workspaceName,e.treeName,e.path]),!n||n.key!==t?{state:`loading`}:n.node?{state:`ready`,node:n.node}:{state:`missing`}}function x(e){let t=`/workspaces/${encodeURIComponent(e.workspaceName)}`,n=e.path.replace(/^\//,``);return e.treeName===`context`?`${t}/path/${n}`:`${t}/trees/${encodeURIComponent(e.treeName)}/path/${n}`}var S=`application/x-canvas-pin`;function C({pin:e,onUnpin:t,onMinimize:n,onDropPin:d}){let f=b(e),[p,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(null),C=!!d&&!p,w=e=>{let t=e.currentTarget.getBoundingClientRect();return e.clientX>t.left+t.width/2?`after`:`before`},T=C?{onDragOver:e=>{e.dataTransfer.types.includes(`application/x-canvas-pin`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,_(w(e)))},onDragLeave:()=>_(null),onDrop:t=>{let n=t.dataTransfer.getData(S);_(null),!(!n||n===e.id)&&(t.preventDefault(),d?.(n,w(t)===`after`))}}:{},E=f.state===`ready`?f.node:null,D=E?.label||e.label||e.path.split(`/`).filter(Boolean).pop()||`Canvas`,O=E?.color;return(0,v.useEffect)(()=>{if(!p)return;let e=e=>{e.key===`Escape`&&h(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[p]),(0,y.jsxs)(`section`,{...T,className:p?`fixed inset-0 z-picker flex flex-col bg-background`:`flex flex-col rounded-(--card-radius) border bg-background overflow-hidden min-h-0 min-w-0 ${g?`ring-2 ring-primary/60`:``}`,children:[(0,y.jsxs)(`header`,{draggable:C,onDragStart:C?t=>{t.dataTransfer.setData(S,e.id),t.dataTransfer.effectAllowed=`move`}:void 0,className:`flex items-center gap-2 px-3 py-2 border-b bg-muted/20 shrink-0 min-w-0 ${C?`cursor-grab active:cursor-grabbing`:``}`,children:[C&&(0,y.jsx)(i,{className:`w-3.5 h-3.5 shrink-0 text-muted-foreground/60`,"aria-hidden":!0}),O&&(0,y.jsx)(`div`,{className:`w-1 h-5 rounded-full shrink-0`,style:{backgroundColor:O}}),(0,y.jsx)(l,{className:`w-4 h-4 shrink-0 text-primary`}),(0,y.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,y.jsx)(`span`,{className:`text-sm font-semibold leading-tight truncate`,children:D}),(0,y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground truncate leading-tight font-mono`,children:[e.workspaceName,`://`,e.path.replace(/^\//,``)]})]}),n&&(0,y.jsx)(`button`,{type:`button`,onClick:n,title:`Minimize to tab bar`,"aria-label":`Minimize to tab bar`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,children:(0,y.jsx)(s,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{type:`button`,onClick:()=>h(e=>!e),"aria-pressed":p,title:p?`Restore tile (Esc)`:`Fill view area`,"aria-label":p?`Restore tile`:`Fill view area`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,children:p?(0,y.jsx)(a,{className:`w-3.5 h-3.5`}):(0,y.jsx)(c,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(r,{to:x(e),title:`Open in workspace`,"aria-label":`Open in workspace`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,children:(0,y.jsx)(u,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{type:`button`,onClick:t,title:`Unpin from home`,"aria-label":`Unpin from home`,className:`shrink-0 flex items-center justify-center w-7 h-7 rounded-md text-muted-foreground hover:bg-destructive/10 hover:text-destructive transition-colors`,children:(0,y.jsx)(o,{className:`w-3.5 h-3.5`})})]}),(0,y.jsxs)(`div`,{className:`flex-1 min-h-0`,children:[f.state===`loading`&&(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:`Loading…`}),f.state===`missing`&&(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 px-4 text-center`,children:[(0,y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This canvas is no longer available.`}),(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`It may have been renamed, moved or deleted.`}),(0,y.jsx)(`button`,{type:`button`,onClick:t,className:`mt-1 px-2.5 py-1 text-xs border rounded-md hover:bg-accent`,children:`Remove pin`})]}),f.state===`ready`&&(0,y.jsx)(m,{workspaceId:e.workspaceName,treeName:e.treeName,path:e.path,layerId:f.node.id,querySpec:f.node.querySpec,metadata:f.node.metadata,readOnly:!0})]})]})}function w(e){return e.label||e.path.split(`/`).filter(Boolean).pop()||`Canvas`}function T({pins:e,onRestore:t}){let[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(e.length);return i!==e.length&&(a(e.length),e.length===0&&r(!1)),e.length===0?null:(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`div`,{className:`pointer-events-none absolute bottom-0 left-0 right-0 z-40 max-md:hidden`,children:(0,y.jsx)(`div`,{className:`pointer-events-auto flex items-end gap-1 overflow-x-auto px-3 pr-28 pb-safe-bottom`,children:e.map(e=>(0,y.jsxs)(`button`,{type:`button`,onClick:()=>t(e.id),title:`Restore ${w(e)}`,className:`flex max-w-[180px] shrink-0 items-center gap-1.5 rounded-t-lg border border-b-0 bg-background px-3 py-1.5 text-xs shadow-elevation-1 hover:bg-accent`,children:[(0,y.jsx)(l,{className:`h-3.5 w-3.5 shrink-0 text-primary`}),(0,y.jsx)(`span`,{className:`truncate`,children:w(e)})]},e.id))})}),n&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`div`,{className:`fixed inset-0 z-drawer md:hidden`,onClick:()=>r(!1),"aria-hidden":!0}),(0,y.jsx)(`div`,{className:`fixed bottom-rail-stack left-2 z-rail w-60 max-w-[calc(100vw-1rem)] rounded-xl border bg-card p-1.5 shadow-elevation-5 animate-fade-in md:hidden touch-target`,children:e.map(e=>(0,y.jsxs)(`button`,{type:`button`,onClick:()=>t(e.id),className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-sm hover:bg-accent`,children:[(0,y.jsx)(l,{className:`h-4 w-4 shrink-0 text-primary`}),(0,y.jsx)(`span`,{className:`truncate`,children:w(e)})]},e.id))})]}),(0,y.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),"aria-label":n?`Close minimized canvases`:`Minimized canvases (${e.length})`,className:`fixed bottom-rail-inset left-16 z-nav flex h-12 w-12 items-center justify-center rounded-full bg-foreground text-background shadow-elevation-4 md:hidden`,children:[(0,y.jsx)(l,{className:`h-5 w-5`}),(0,y.jsx)(`span`,{className:`absolute -top-1 -right-1 flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-semibold`,children:e.length})]})]})}function E(){let{pins:e,unpin:t,movePin:n,setMinimized:r,isLoading:i}=p(),{showErrorToast:a}=h(),[o,s]=(0,v.useState)(new Set),c=(0,v.useRef)(e);(0,v.useEffect)(()=>{c.current=e},[e]);let l=e=>{r(e,!0).catch(()=>a(`Could not save minimized state`))},u=t=>{s(e=>{let n=new Set(e);return n.delete(t),n}),e.find(e=>e.id===t)?.minimized&&r(t,!1).catch(()=>a(`Could not save restored state`))},d=(0,v.useCallback)(e=>{s(e?new Set(c.current.filter(e=>!e.minimized).map(e=>e.id)):new Set)},[]),f=e.filter(e=>!g(e,o)),m=e.filter(e=>g(e,o)),b=(t,r,i)=>{let a=e.findIndex(e=>e.id===r.id);if(a===-1)return;let o=i?e[a+1]?.id??null:r.id;n(t,o)};return(0,y.jsxs)(`div`,{className:`relative h-full`,children:[(0,y.jsx)(`div`,{className:`h-full overflow-y-auto`,children:i?(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:`Loading…`}):(0,y.jsx)(`div`,{className:`grid gap-4 p-4 h-full grid-cols-[repeat(auto-fit,minmax(min(640px,100%),1fr))] auto-rows-fr ${m.length>0?`md:pb-12`:``}`,children:f.map(e=>(0,y.jsx)(C,{pin:e,onUnpin:()=>{t(e.id)},onMinimize:()=>l(e.id),onDropPin:(t,n)=>b(t,e,n)},e.id))})}),(0,y.jsx)(`div`,{className:`pointer-events-none absolute inset-0`,children:(0,y.jsx)(_,{onCardsOpenChange:d})}),(0,y.jsx)(T,{pins:m,onRestore:u})]})}export{E as default};