@augmentd-labs/canvas-web 2.26.42 → 2.26.44
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.
- package/dist/assets/{CalendarApplet-D-zqm-ie.js → CalendarApplet-BNT0vegP.js} +1 -1
- package/dist/assets/{FiltersApplet-JdYOvvVo.js → FiltersApplet-BT3fR4Fu.js} +1 -1
- package/dist/assets/{HomeFab-KnJ0amal.js → HomeFab-B17r3232.js} +1 -1
- package/dist/assets/{LensApplet-DmJnK9xh.js → LensApplet-CVUc1-vK.js} +1 -1
- package/dist/assets/{NotesApplet-CQElHVk-.js → NotesApplet-Bbd61mrH.js} +1 -1
- package/dist/assets/{_agentId_-D-qxZUMa.js → _agentId_-CrBQ54X2.js} +0 -0
- package/dist/assets/{_contextId_-Dn4SYTZE.js → _contextId_-CEcdj7Ec.js} +1 -1
- package/dist/assets/{_workspaceName_-BsPptLde.js → _workspaceName_-BhZWt9RG.js} +1 -1
- package/dist/assets/{about-CYt1r_NF.js → about-CdAN00wx.js} +1 -1
- package/dist/assets/{add-Di0PTHej.js → add-COjQRnFC.js} +1 -1
- package/dist/assets/{agents-DcNNzyQt.js → agents-D_t6cQMW.js} +1 -1
- package/dist/assets/{appearance-Bs11PYYg.js → appearance-BnUcoqpz.js} +1 -1
- package/dist/assets/{apps-DN8Ux5ac.js → apps-CCC-xyI2.js} +1 -1
- package/dist/assets/backend-sync-progress-B3lZB9Ha.js +6 -0
- package/dist/assets/{document-list-CUmMhD6M.js → document-list-rzRLzfkF.js} +2 -2
- package/dist/assets/{home-7tcQ6_Mc.js → home-DrRSXywO.js} +1 -1
- package/dist/assets/index-DOXi2QgX.css +2 -0
- package/dist/assets/{index-DDoPhET6.js → index-G_67YwLB.js} +3 -3
- package/dist/assets/{key-bindings-CqCOuyv6.js → key-bindings-6SHAlZR8.js} +1 -1
- package/dist/assets/{registry-fC-KNk2X.js → registry-FfNYUpRF.js} +2 -2
- package/dist/assets/{settings-Dluo6P1Q.js → settings-CCr9Jr0Q.js} +1 -1
- package/dist/assets/{settings-BIvpUSK-.js → settings-CGncOyKY.js} +1 -1
- package/dist/assets/settings-Cv6jdSA0.js +16 -0
- package/dist/assets/{settings-B_suOk2v.js → settings-r7slYioS.js} +1 -1
- package/dist/assets/{share-target-C7PbTH7r.js → share-target-CoDDhZI5.js} +1 -1
- package/dist/assets/{shared-0beOwGSQ.js → shared-bYen6pjw.js} +1 -1
- package/dist/assets/{tree-folders-CNbp7be7.js → tree-folders-Q5iu5vpu.js} +1 -1
- package/dist/assets/{use-canvas-pins-Bhd7_wde.js → use-canvas-pins-BPCW4twY.js} +1 -1
- package/dist/assets/{useAgentModels-Dw0ibJnv.js → useAgentModels-BufYelEA.js} +1 -1
- package/dist/assets/{workspace-area-menu-B-bXURzn.js → workspace-area-menu-BN5ysUpx.js} +1 -1
- package/dist/assets/{workspaces-BTYGLm4X.js → workspaces-Dj9dNIWZ.js} +1 -1
- package/dist/index.html +7 -7
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/dist/assets/backend-sync-progress-CFe6JPuR.js +0 -6
- package/dist/assets/index-CYvpxvg6.css +0 -2
- package/dist/assets/settings-CP_46X21.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{Kn as o,L as s,Tt as c,Ur as l,Vr as u,X as d,ar as f,gr as p,kt as m,pn as h}from"./ui-CDoK3F3U.js";import{t as g}from"./utils-2pl1SbIp.js";import{t as ee}from"./button-SeUZ_Pvi.js";import{c as _,t as te}from"./api-CA6WiiYM.js";import{t as v}from"./socket-CtH3EU9m.js";import{n as ne}from"./use-toast-BlLDqSUO.js";import{h as y,o as re,s as b}from"./LinkToCard-CKVi4Nrg.js";import{At as x,D as S,G as ie,Gt as C,Kt as w,Lt as ae,W as oe,Y as se,_ as T,_n as ce,a as le,bn as E,gt as D,lt as O,mt as ue,nt as de,rn as fe,rt as pe,u as me,vt as he,w as ge,x as _e,y as ve,zt as ye}from"./workspace-C5V-ZCOE.js";import{n as be,r as xe}from"./use-canvas-pins-Bhd7_wde.js";import{u as Se}from"./ObjectPropertiesCard-D2lrTQqT.js";import{a as Ce,c as k,d as we,f as A,i as Te,l as Ee,o as De,p as Oe,r as ke,w as Ae}from"./document-list-CUmMhD6M.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-DIP1zh7I.js";import{n as He}from"./last-path-BbXWC3b3.js";import{t as Ue}from"./workspace-area-menu-B-bXURzn.js";import{t as We}from"./workspace-content-gate-C54J9Man.js";import{t as Ge}from"./form-panel-3p-ncEVK.js";import{a as Ke,c as qe,i as Je,l as Ye,n as Xe,o as Ze,r as Qe,s as $e,t as et,u as tt}from"./tree-folders-CNbp7be7.js";import{i as nt,r as rt}from"./query-debug-lD5vbJGi.js";var j=`session.open`,it=`session.set`,at=`session.ids`,ot=`session.materialize`,st=`session.close`,ct=`session.delta`,M=e(n(),1),N=t();function lt(e){let t=we(`backends`,e.path)?.backend;return(0,N.jsx)(ut,{...e},JSON.stringify([e.workspace,t]))}function ut({workspace:e,path:t,onNavigate:n}){let r=we(`backends`,t),i=r.backend,a=r.prefix,[s,l]=(0,M.useState)(null),[u,h]=(0,M.useState)(null),g=(0,M.useRef)(!1),[ee,_]=(0,M.useState)(null),[te,v]=(0,M.useState)(null),[ne,x]=(0,M.useState)(0),[S,ie]=(0,M.useState)(new Set),[C,w]=(0,M.useState)(null),ae=(0,M.useCallback)(()=>x(e=>e+1),[]),[oe,se]=(0,M.useState)(t);oe!==t&&(se(t),ie(new Set),w(null),v(null),_(null));let T=s?.revision!==ne,ce=T?[]:s.items,le=T?[]:s.backends,E=s?.days;(0,M.useEffect)(()=>{let t=!1;return(i?k(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||l({...e,revision:ne,error:null})}).catch(e=>{t||l({revision:ne,items:[],backends:[],days:null,error:e instanceof Error?e.message:String(e)})}),()=>{t=!0}},[e,i,ne]),(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,ae()},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,ae]);let D=Oe(ce,a),O=async(t,n)=>{if(!(!i||g.current||T||!n.length)&&!(t===`discard`&&!Ce(i,n))){g.current=!0,h(t),_(null),v(null),w(null);try{let r=await(t===`restore`?Ee:De)(e,i,[...n].sort((e,t)=>t.deletedAt-e.deletedAt).map(e=>e.id)),a=r.filter(e=>!e.ok);v(`${r.length-a.length} item(s) ${t===`restore`?`restored to their original paths`:`permanently deleted`}.`),a.length&&_(`${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(`; `)}`),ie(new Set)}catch(e){_(e instanceof Error?e.message:String(e))}finally{g.current=!1,h(null),ae()}}},ue=(e,t,n)=>w({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)(b,{items:re(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:[S.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 O(`restore`,D.filter(e=>S.has(e.id)).flatMap(e=>e.items)),children:[(0,N.jsx)(c,{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 O(`discard`,D.filter(e=>S.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 O(`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:ae,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.`,E?` Deleted items are kept for ${E} days.`:``]}),te&&(0,N.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:te}),(ee||s?.error)&&(0,N.jsx)(`p`,{role:`alert`,className:`px-4 py-2 text-sm text-destructive`,children:ee||s?.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=>S.has(e.id)),onChange:e=>ie(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(),ue(t.clientX,t.clientY,e)},onDoubleClick:()=>e.navigable&&n(A(i,e.key)),children:[(0,N.jsx)(`td`,{className:`p-2`,children:(0,N.jsx)(`input`,{type:`checkbox`,"aria-label":`Select ${e.name}`,checked:S.has(e.id),disabled:!!u,onChange:t=>ie(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(A(i,e.key)),children:[e.directory?(0,N.jsx)(o,{className:`h-4 w-4 shrink-0`}):(0,N.jsx)(f,{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=>ue(t.clientX,t.clientY,e),children:(0,N.jsx)(p,{className:`h-4 w-4`})})})]},e.id))})]}):(0,N.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-3`,children:[le.map(e=>(0,N.jsxs)(`button`,{onClick:()=>n(A(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)),!le.length&&(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`No file backends are available.`})]})}),C&&(0,N.jsxs)(y,{x:C.x,y:C.y,onClose:()=>w(null),className:`min-w-44 rounded-md border bg-popover p-1 shadow-elevation-3`,children:[C.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(A(i,C.row.key)),w(null)},children:[(0,N.jsx)(o,{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 O(`restore`,C.row.items),children:[(0,N.jsx)(c,{className:`h-4 w-4`}),`Restore `,C.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 O(`discard`,C.row.items),children:[(0,N.jsx)(d,{className:`h-4 w-4`}),`Delete permanently`]})]})]})}function dt({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=v.on(`connect`,l);return v.on(`backend.resync.changed`,u),v.on(`backend.changed`,d),window.addEventListener(`focus`,l),()=>{t=!0,f?.(),v.off(`backend.resync.changed`,u),v.off(`backend.changed`,d),window.removeEventListener(`focus`,l)}},[e]);let c=n.filter(e=>!i.has(o(e)));return c.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)(h,{"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,...c.map(o)])),children:(0,N.jsx)(s,{"aria-hidden":`true`,className:`h-4 w-4`})})]}),(0,N.jsx)(`div`,{className:`max-h-48 space-y-3 overflow-y-auto`,children:c.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 ft=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:null;function pt(e){return`/${e}`.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`}function mt(e,t,n){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>mt(e,t,n));if(typeof e==`string`)return[{tree:null,kind:t,path:pt(e)}];let r=ft(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:pt(e)}))}function ht(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 gt(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 _t(e,t,n=new Map){let r=ft(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:pt(n)}],ids:ht(r),unknown:!1}:{targets:[],ids:[],unknown:!0}}let i=[...mt(r.context,`context`,n),...mt(r.directory,`directory`,n)],a=ft(r.changed);a&&i.push(...mt(a.context,`context`,n),...mt(a.directory,`directory`,n));let o=ht(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 vt(e,t){return e===t||e===`/`||t===`/`||e.startsWith(`${t}/`)||t.startsWith(`${e}/`)}function yt(e,t){if(e.kind&&e.kind!==t.kind||e.tree&&e.tree!==t.tree)return!1;if(t.kind===`context`){let n=e=>pt(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 vt(e.path,t.path)}function bt(e){return _t(`tree.refresh`,{treeName:e?.treeName,path:e?.path||`/`})}function xt(e,t,n){if(e.unknown||e.targets.length&&(t.wholeWorkspace||e.targets.some(e=>yt(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 St(e,t,n={}){return v.request(j,{workspace:e,specs:t,opts:n})}function Ct(e,t,n){return v.request(it,{sessionId:e,label:t,spec:n})}function wt(e){return v.request(at,{sessionId:e})}function P(e,t={}){return v.request(ot,{sessionId:e,...t})}function Tt(e){return v.request(st,{sessionId:e})}function F(e){return v.on(ct,e)}var I=100;function Et({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),h=(0,M.useRef)(null),g=(0,M.useRef)(null),ee=(0,M.useRef)({}),_=(0,M.useRef)(null),te=(0,M.useMemo)(()=>JSON.stringify(t),[t]),ne=(0,M.useMemo)(()=>JSON.stringify(n??{}),[n]),y=(0,M.useCallback)(()=>{let e=p.current;a(f.current.map(t=>e.get(t)).filter(Boolean))},[]),re=(0,M.useCallback)(async e=>{let t=h.current;if(!t||e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=I){let i=e.slice(r,r+I),a=await de(t,`/`,[],{ids:i,scope:`workspace`,limit:i.length});n.push(...a.payload||[])}return n},[]),b=(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),y(),r.length===0)return;let a=await re(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))}y()},[re,y]),x=(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 b(a,[],t)},[b]);(0,M.useEffect)(()=>{if(h.current=e??null,!r||!e)return;let t=!1,n=null,i=async()=>{try{let r=await St(e,JSON.parse(te),JSON.parse(ne));if(t){Tt(r.sessionId).catch(()=>{});return}n=r.sessionId,m.current=r.sessionId,l(r.sessionId),d(null),f.current=[],p.current=new Map,await x(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=v.on(`connect`,()=>{i()});return()=>{t=!0,o?.();let e=n??m.current;e&&Tt(e).catch(()=>{}),m.current=null,f.current=[],p.current=new Map,l(null),a([]),s(0)}},[e,te,ne,r]),(0,M.useEffect)(()=>{if(!c)return;let e=F(e=>{if(e.sessionId===c){if(g.current!==null){_.current?.(g.current,ee.current);return}e.ids===void 0?b(e.added??[],e.removed??[],e.count):x(e.ids,e.count)}});return()=>{e?.()}},[c,b,x]);let S=(0,M.useCallback)(async()=>{let e=m.current;if(e)try{let t=await wt(e);await x(t.ids,t.count)}catch{}},[x]),ie=(0,M.useCallback)(async(e,t)=>{let n=m.current;if(!n)throw Error(`No open query session`);let r=await Ct(n,e,t);if(g.current!==null){await _.current?.(g.current,ee.current);return}await x(r.ids,r.count)},[x]),C=(0,M.useCallback)(async(e,t={})=>{let n=m.current;if(!n)throw Error(`No open query session`);if(g.current=e,ee.current=t,e===null){await S();return}let r=await P(n,{match:e,...t});for(let e of r.documents)p.current.set(e.id,e);f.current=r.ids,s(r.totalCount),y()},[y,S]);(0,M.useEffect)(()=>{_.current=C},[C]);let w=(0,M.useCallback)(async(e,t,n={})=>{let r=m.current;if(!r)throw Error(`No open query session`);let i=await P(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 Ct(r,e,{ids:i.ids});return await x(a.ids,a.count),i.ids},[x]);return{documents:i,count:o,ready:c!==null,error:u,setCue:ie,resync:S,rank:C,rankAndPin:w}}function Dt({data:e,className:t}){let[n,r]=(0,M.useState)(!0),{rows:i,gapIndex:a,span:o}=(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:g(`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 s=a>0?i[a].distance:null;return(0,N.jsxs)(`div`,{className:g(`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)(l,{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.`,s===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 Δ`,o.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:s.toFixed(4)}),` (Δ`,o.biggest.toFixed(4),`, vs typical Δ`,o.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:g(`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 `,o.first.toFixed(4),` – `,o.last.toFixed(4),` (spread `,(o.last-o.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 Ot=new Map;function L(e,t,n){return`${e}\0${t}\0${n}`}function kt(e,t,n,r,i,a,o=``,s=``,c=`path`){return`${L(e,t,n)}\0${r}\0${i}\0${a}\0${o}\0${s}\0${c}`}function R(e,t,n){let r=L(e,t,n);for(let e of Ot.keys())e.startsWith(r)&&Ot.delete(e)}function At(e,t){let n=`${e}\0`;for(let[e,r]of Ot){if(!e.startsWith(n))continue;let[,i,a,,,,,,o=`path`]=e.split(`\0`);xt(t,{tree:i,kind:E(i),path:a,wholeWorkspace:o.startsWith(`workspace`)},r.documents.map(e=>Number(e.id)))&&Ot.delete(e)}}function jt(e,t){At(t?.workspaceName??e,bt(t))}function Mt(){let{workspaceName:e}=r();return e?(0,N.jsx)(We,{workspaceName:e,children:(0,N.jsx)(z,{})}):null}function z(){let{workspaceName:e,treeName:t}=r(),n=a(),o=i(),{showToast:s,showProgress:c}=ne(),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),[h,y]=(0,M.useState)([]),[re,b]=(0,M.useState)(!1),[Ce,k]=(0,M.useState)(0),A=rt(),[Ee,De]=(0,M.useState)(null),[Oe,We]=(0,M.useState)(A);Oe!==A&&(We(A),A||De(null));let[j,it]=(0,M.useState)(`path`),[at,ot]=(0,M.useState)(!1),[st,ct]=(0,M.useState)(null),[ut,ft]=(0,M.useState)(null),[pt,mt]=(0,M.useState)(``),[ht,vt]=(0,M.useState)(!1),[yt,St]=(0,M.useState)(!1),[Ct,wt]=(0,M.useState)(!1),[P,Tt]=(0,M.useState)(null),[F,I]=(0,M.useState)(1),[L,Mt]=(0,M.useState)(50),[z,Nt]=(0,M.useState)(u),[Ft,It]=(0,M.useState)(null),{state:B,saveFilters:Lt,setSort:Rt,setAccentColor:zt,setMapDocuments:Bt}=je(),Vt=B.filters.features.allOf,Ht=B.filters.features.anyOf,Ut=B.filters.features.noneOf,Wt=Fe(B.filters.timeline),Gt=Pe(B.filters.geo),Kt=Le(B.filters.lens,B.filters.geo.includeUnlocated),V=B.filters.lens.ids,qt=[...Wt,...Gt,...Kt],Jt=B.filters.sort??Ie,Yt=JSON.stringify({a:Vt,b:Ht,c:Ut,d:qt,i:V,s:Jt}),Xt=JSON.stringify({a:Vt,b:Ht,c:Ut,d:qt,s:Jt}),H=Re(n.pathname).path,U=t??`context`,W=U===`backends`,[Zt,Qt]=(0,M.useState)([]);(0,M.useEffect)(()=>{!W||!e||he(e).then(Qt).catch(()=>Qt([]))},[W,e]);let $t=W?le(H,Zt):null,[en,tn]=(0,M.useState)(!1),nn=`${U}\0${H}`,[rn,an]=(0,M.useState)(nn);rn!==nn&&(an(nn),tn(!1));let G=l.get(`layer`)===`1`,K=l.get(`layerId`)||null,[q,on]=(0,M.useState)(null),[J,sn]=(0,M.useState)(null),cn=(0,M.useRef)(null);(0,M.useEffect)(()=>{cn.current=J},[J]);let[ln,un]=(0,M.useState)(`left`),[dn,fn]=(0,M.useState)([]),{openM1Drawer:pn,openM2Drawer:mn,goBack:hn}=Ve(),[gn,_n]=(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,vn=(0,M.useRef)(null);(0,M.useEffect)(()=>{!e||!q||G||vn.current===`${e}/${U}`&&(H!==`/`&&!Y||He(e,U,H))},[e,q,G,H,Y,U]);let yn=(0,M.useMemo)(()=>G||j===`workspace`||z.length>0?[]:et(q,H),[q,H,G,j,z]),bn=G?null:H===`/`?q:Y,Z=Ae(),xn=`${U}\0${H}`,[Sn,Cn]=(0,M.useState)(null),wn=Sn?.key===xn?Sn.views:$e(bn?.metadata),Tn=Z?.pinned&&Z.view?[Z.view,...wn.filter(e=>e.id!==Z.view.id)]:wn,En=Z?.pinned&&Z.view?Z.view.id:Sn?.key===xn?Sn.activeId:Tn[0]?.id??Ke.id,Q=Tn.find(e=>e.id===En)??Tn[0]??Ke;(0,M.useEffect)(()=>{Z?.selectView(Q)},[Q,Z]);let Dn=W?void 0:Z?.schema??Ze(Q),On=Dn?[...Vt,Dn]:Vt;tt(Ye({workspace:e??null,treeNameOrId:U,treeType:E(U),path:H,scope:j===`workspace`?`workspace`:G?`layer`:`path`,layerId:G?K:void 0,unfiledOnly:en},{...B.filters,features:{...B.filters.features,allOf:On}},B.geoSelection,z));let kn=e=>{let t=Tn.find(t=>t.id===e);t&&Z?.selectView(t),I(1),fn([]),Cn({key:xn,views:Tn,activeId:e})},An=(t,n)=>{n&&n!==En&&(I(1),fn([]));let r=t.find(e=>e.id===(n??En));r&&Z?.selectView(r),Cn({key:xn,views:t,activeId:n??En}),ce(e,H,{metadata:{...bn?.metadata??{},views:t}},U).catch(()=>{s({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},jn=X===`canvas`&&typeof Y?.querySpec?.query==`string`?Y.querySpec.query:``,Mn=X===`canvas`?{label:Y?.label,description:Y?.description,color:Y?.color}:null,{isPinned:Nn,pin:Pn,unpin:Fn,pins:In}=be(),Ln=d?.name,$=(0,M.useMemo)(()=>Ln&&X===`canvas`&&!G?{workspaceName:Ln,treeName:U,path:H}:null,[Ln,X,G,U,H]),Rn=$?Nn($):!1,zn=Y?.id,Bn=Y?.label,Vn=(0,M.useCallback)(async()=>{if($)try{let e=In.find(e=>e.workspaceName===$.workspaceName&&e.treeName===$.treeName&&e.path===$.path);e?await Fn(e.id):await Pn({...$,layerId:zn,label:Bn})}catch(e){console.error(`Failed to update home pins:`,e)}},[$,In,Pn,Fn,zn,Bn]),Hn=e?`${e}://${H===`/`?``:H.replace(/^\//,``)}`:``,Un=Me(d?.color)||null;(0,M.useEffect)(()=>(zt(Un),()=>zt(null)),[Un,zt]);let Wn=(0,M.useCallback)(async t=>{let n=V;if(t?.anyOf?.length&&Ht.length&&(n=((await ie(e,H,U,{limit:0,anyOf:Ht,ids:V,applyCanvasSpec:!1})).payload||[]).map(e=>e.id),!n.length))return{payload:[],count:0,totalCount:0};let r=await ie(e,H,U,{limit:t?.limit,offset:t?.offset,page:t?.page,sortBy:t?.sortBy,order:t?.order,allOf:[...Vt,...t?.allOf??[]],anyOf:t?.anyOf?.length?t.anyOf:Ht,noneOf:Ut,filters:qt,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,Yt,z]);(0,M.useEffect)(()=>{e&&(async()=>{m(!0);try{let t=await te.get(`${_.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 Gn=(V?.length??0)>0&&!G&&!(en&&$t)&&z.length<=1,{documents:Kn,count:qn,ready:Jn,setCue:Yn,resync:Xn,rank:Zn}=Et({workspaceRef:e,specs:(0,M.useMemo)(()=>{let e={features:{allOf:On,anyOf:Ht,noneOf:Ut},filters:qt};return j!==`workspace`&&(E(U)===`directory`?e.directory={tree:U,path:H}:e.context=H),[{label:`scope`,spec:e}]},[Xt,H,U,j,Dn]),opts:(0,M.useMemo)(()=>({mode:`live`,debounceMs:150}),[]),enabled:Gn}),Qn=Gn&&Jn,$n=(0,M.useRef)(!1);(0,M.useEffect)(()=>{$n.current=Qn},[Qn]);let er=z.length===1?z[0].trim():``;(0,M.useEffect)(()=>{Jn&&Zn(er?{text:er}:null,{limit:L,offset:(F-1)*L}).catch(()=>{})},[Jn,er,L,F,Zn]);let tr=(V??[]).join(`,`);(0,M.useEffect)(()=>{Jn&&Yn(`lens`,{ids:V??[]}).catch(()=>{})},[Jn,tr,Yn,V]);let nr=Qn?Kn:h,rr=Qn?qn:Ce,ir=(0,M.useRef)(new Set);(0,M.useEffect)(()=>{ir.current=new Set(nr.map(e=>Number(e.id)))},[nr]);let ar=B.geoSelection;(0,M.useEffect)(()=>{Bt(nr,d?.name??null)},[nr,d?.name,Bt]),(0,M.useEffect)(()=>()=>Bt([]),[Bt]);let or=(0,M.useMemo)(()=>ar?nr.filter(e=>Ne(e,ar,B.filters.geo.includeUnlocated)):nr,[nr,ar,B.filters.geo.includeUnlocated]),sr=me(H,On,{treeName:U,treeType:E(U),scope:j,queries:z,anyOf:Ht,noneOf:Ut,filters:qt,ids:V,layerId:G&&K?K:void 0}),cr=JSON.stringify([e,sr]),[lr,ur]=(0,M.useState)(``),[dr,fr]=(0,M.useState)(!1),pr=(0,M.useRef)(!1),mr=re||dr||lr!==cr||Qn||!!ar,hr=(0,M.useRef)(0),gr=(0,M.useRef)(null);(0,M.useEffect)(()=>()=>{hr.current++,gr.current=null},[]);let _r=(0,M.useRef)(``),vr=(0,M.useCallback)(async t=>{if(!e)return;if(we(U,H)){hr.current++,gr.current=null,_r.current=``,y([]),k(0),b(!1);return}if($n.current)return;let n=`${en&&$t?`${j}:unfiled`:j}:${Dn??``}`,r=(V?.length??0)>0,i=kt(e,U,H,F,L,z.join(`␟`),Xt,G&&K?K:``,n),a=r&&i===_r.current;_r.current=i;let o=kt(e,U,H,F,L,z.join(`␟`),Yt,G&&K?K:``,n),c=`${o}\0${A}`;if(t?.silent&&gr.current?.key===c){gr.current.refreshPending=!0;return}let l=++hr.current,u=t?.silent||r||A?void 0:Ot.get(o);u&&(y(u.documents),k(u.totalCount),ur(cr),b(!1)),(t?.silent??(a||!!u))||b(!0);let d={key:c,refreshPending:!1};gr.current=d;try{let t;if(en&&$t)t=await D(e,$t.driver,$t.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:On,anyOf:Ht,noneOf:Ut,filters:qt,ids:V,sortBy:Jt.sortBy||void 0,order:Jt.order});else{let n=E(U);t=await de(e,H,On,{limit:L,page:F,treeName:U,treeType:n,queries:z,anyOf:Ht,noneOf:Ut,filters:qt,ids:V,sortBy:Jt.sortBy||void 0,order:Jt.order,scope:j,debug:A&&z.length>0,debugLimit:200})}let n=t.payload||[],i=t.totalCount||t.count||0;if(!r&&!d.refreshPending&&Ot.set(o,{documents:n,totalCount:i}),l!==hr.current)return;let s=t.debug,c=s?.imageDistances??s?.distances??null;De(c?{query:z[z.length-1]??``,distances:c}:null),y(a?e=>e.length===n.length&&e.every((e,t)=>e.id===n[t].id)?e:n:n),k(i),ur(cr)}catch(e){if(l!==hr.current)return;let t=e instanceof Error?e.message:`Failed to fetch documents`;s({title:`Error`,description:t,variant:`destructive`}),y([]),k(0)}finally{gr.current===d&&(gr.current=null),l===hr.current&&b(!1),l===hr.current&&d.refreshPending&&vr({silent:!0})}},[e,H,U,K,G,F,L,d?.status,z,Yt,j,en,A,Dn]);(0,M.useEffect)(()=>{vr()},[vr]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;!n||n.workspaceName!==e||(sn({treeName:n.treeName||`context`,path:ze(n.path||`/`)}),un(`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&&jt(e,n),xt(bt(n),{tree:U,kind:E(U),path:H,wholeWorkspace:j===`workspace`}))){if(e&&R(e,U,H),$n.current){Xn();return}vr({silent:!0})}};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[vr,e,H,U,j,Xn]);let yr=d?.name,br=d?.id;(0,M.useEffect)(()=>{if(!e||!yr&&!br)return;let t=[yr,br].filter(Boolean).map(e=>`workspace:${e}`),n=()=>t.forEach(e=>v.emit(`subscribe`,{channel:e}));n();let r=v.on(`connect`,n),i=new Map,a=!1,o=()=>{x(e).then(e=>{a||(i=gt(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,$n.current){Xn();return}vr({silent:!0})}},f=t=>n=>{(t.startsWith(`tree.created`)||t.startsWith(`tree.renamed`))&&o();let r=_t(t,n,i);At(e,r);let a={tree:U,kind:E(U),path:H,wholeWorkspace:j===`workspace`},f=cn.current;f&&xt(r,{tree:f.treeName,kind:E(f.treeName),path:f.path})&&(u=f),xt(r,a,ir.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])=>v.on(e,t)),()=>{a=!0,s&&clearTimeout(s),r?.(),p.forEach(([e,t])=>v.off(e,t))}},[e,br,yr,U,H,j,vr,Xn]);let xr=`${H}\0${U}\0${K??``}\0${j}`,[Sr,Cr]=(0,M.useState)(xr);Sr!==xr&&(Cr(xr),I(1),It(null));let wr=`${H}\0${U}\0${K??``}`,[Tr,Er]=(0,M.useState)(wr);Tr!==wr&&(Er(wr),it(`path`));let Dr=(e,t)=>{let n=e===`/`?`canvas`:e.split(`/`).pop()||`canvas`;mt(n),ft({parentPath:e,captureView:t})},Or=l.get(`createCanvas`)===`1`,[kr,Ar]=(0,M.useState)(!1);kr!==Or&&(Ar(Or),Or&&Dr(H,!1)),(0,M.useEffect)(()=>{if(!Or)return;let e=new URLSearchParams(n.search);e.delete(`createCanvas`);let t=e.toString();o(`${n.pathname}${t?`?${t}`:``}${n.hash}`,{replace:!0})},[Or,H]);let jr=(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]),Mr=JSON.stringify([l.has(`q`),...u]),[Nr,Pr]=(0,M.useState)(Mr);Nr!==Mr&&(Pr(Mr),Nt(u),I(1));let Fr=`${Mr}\0${X??``}\0${jn}\0${H}\0${Ft??``}`,[Ir,Lr]=(0,M.useState)(Fr);Ir!==Fr&&(Lr(Fr),l.has(`q`)||u.length>0||X!==`canvas`||Ft===H||(Nt(jn?[jn]:[]),I(1)));let Rr=(0,M.useCallback)(e=>{let t=e.trim();t&&(It(null),Nt(e=>{if(e.includes(t))return e;let n=[...e,t];return jr(n),I(1),n}))},[jr,It,Nt,I]),zr=(0,M.useCallback)(e=>{Nt(t=>{let n=e<0?[]:t.filter((t,n)=>n!==e);return n.length===0&&It(H),jr(n),I(1),n})},[jr,H,It,Nt,I]),Br=z.join(` `).trim(),Vr=!!B.activeContextType&&(B.isDirty||Br!==(X===`canvas`?jn:B.savedSearchQuery||``));!e&&q!==null&&on(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,vn.current=`${e}/${U}`,on(i))}).catch(()=>{!t&&a===n&&!r&&on(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=Te(e,br);return()=>{t=!0,o(),window.removeEventListener(`workspace:tree:refresh`,a)}},[e,U,br]),!(e&&X===`canvas`&&!G)&&P!==null&&Tt(null),(0,M.useEffect)(()=>{let t=!1;if(!(!e||X!==`canvas`||G))return se(e,H,U).then(e=>{t||Tt(e)}).catch(()=>{t||Tt(null)}),()=>{t=!0}},[e,H,U,X,G]);let Hr=async()=>{if(d){ot(!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{ot(!1)}}},Ur=async t=>{if(!d)return;let n=c({title:`Removing…`,description:`Document from "${H}"`});try{await C(e||d.id,[t],H,[],U,Zr,{trashIfOrphaned:!0}),R(e||d.id,U,H),y(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`})}},Wr=async t=>{if(!d)return;let n=c({title:`Deleting…`,description:`Document from "${H}"`});try{await ge(e||d.id,[t],H,[],U,Zr),R(e||d.id,U,H),y(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`})}},Gr=async t=>{if(!d)return;let n=c({title:`Removing…`,description:`${t.length} document(s) from "${H}"`});try{await C(e||d.id,t,H,[],U,Zr,{trashIfOrphaned:!0}),R(e||d.id,U,H),y(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`})}},Kr=async t=>{if(!d)return;let n=c({title:`Deleting…`,description:`${t.length} document(s)`});try{await ge(e||d.id,t,H,[],U,Zr),R(e||d.id,U,H),y(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`})}},qr=async t=>{if(!d)return;let n=c({title:`Destroying…`,description:`Document and its backend copies`});try{let r=await S(e||d.id,[t]);if(r.failed?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}y(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`})}},Jr=async t=>{if(!d)return;let n=c({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await S(e||d.id,t),i=new Set(r.successful?.filter(e=>e.docDeleted).map(e=>e.id)??[]);y(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`})}},Yr=e=>{ct({documentIds:e,operation:`copy`,sourcePath:H,sourceTreeName:U}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`copy`}})),s({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},Xr=e=>{ct({documentIds:e,operation:`cut`,sourcePath:H,sourceTreeName:U}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}})),s({title:`Cut`,description:`${e.length} document(s) cut to clipboard`})},Zr=E(U),Qr=async(t,n,r={})=>{if(!e)return!1;let i=r.targetTreeName??U,a=r.targetTreeType??Zr,o=r.move??st?.operation===`cut`,s=c({title:o?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let c=await ae(e,t,n,i,a);if(c){R(e,i,t);let a=r.sourceTreeName||st?.sourceTreeName,c=r.sourcePath||st?.sourcePath;if((r.move??st?.operation===`cut`)&&c&&a){let t=E(a);await C(e,n,c,[],a,t),R(e,a,c),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:c,treeName:a}}))}s.done({title:`Success`,description:`${n.length} document(s) ${o?`moved`:`pasted`} to "${t}"`}),ct(null),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:null}));let l=performance.now();await vr(),console.info(`[paste] list refresh ${Math.round(performance.now()-l)} ms`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t,treeName:i}}))}else s.done();return c}catch(e){return s.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},$r=async(t,n)=>{if(!e)return!1;try{let r=(await O(e,n,t,U,Zr)).length>0;return r&&(ke(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}},ei=async()=>{if(!d||rr===0||mr||pr.current||window.prompt(`Type PURGE to permanently delete all ${rr} matching documents across all pages.`)!==`PURGE`)return;pr.current=!0,fr(!0);let t=c({title:`Purging…`,description:`${rr} matching document(s)`});try{let n=await ye(e||d.id,sr,rr);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 vr({silent:!0}),pr.current=!1,fr(!1)}},ti=()=>Dr(H,!0),ni=async()=>{if(!(!e||!ut||!pt.trim())){vt(!0);try{let t=pt.trim(),n=ut.parentPath,r=n===`/`?`/${t}`:`${n}/${t}`,i={...B.filters,features:{...B.filters.features,allOf:On}};await ve(e,r,U,ut.captureView?{metadata:{toolbox:i},querySpec:{features:i.features,filters:[...Fe(B.filters.timeline),...Pe(B.filters.geo)],query:Br||void 0,sort:B.filters.sort?.sortBy?B.filters.sort:null}}:{}),ft(null),ue(e,U);try{let t=await oe(e,U,{force:!0});on(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)}}},ri=async()=>{if(!(!e||X!==`canvas`)){St(!0);try{let t=P||await T(e,H,U);Tt(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)}}},ii=async()=>{if(P){St(!0);try{await _e(P.code),Tt(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)}}},ai=async()=>{if(!e||X!==`canvas`||H===`/`)return;let t=Mn?.label||H.split(`/`).pop()||`canvas`,n=P?` Its public link will stop working.`:``;if(window.confirm(`Delete canvas "${t}"? This cannot be undone.${n}`)){wt(!0);try{if(P)await _e(P.code),Tt(null);else if(Y?.locked){s({title:`Canvas is locked`,description:`Unlock it before deleting.`,variant:`destructive`});return}await w(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{wt(!1)}}},oi=(0,M.useCallback)(async t=>{if(!e||!J)return;let n={treeName:U,path:H},r=ln===`left`?n:J,i=ln===`left`?J:n,a=ln===`left`?dn:gn;if(a.length===0){s({title:`Nothing selected`,description:`Tick documents in the focused pane first.`});return}let o=E(i.treeName),l=c({title:t?`Moving…`:`Copying…`,description:`${a.length} document(s) → "${i.path}"`});try{if(!await ae(e,i.path,a,i.treeName,o)){l.done();return}if(R(e,i.treeName,i.path),t){let t=E(r.treeName);await C(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,ln,U,H,dn,gn,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(),oi(e.key===`F6`))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[J,oi]),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 si=X===`canvas`&&!G&&!!Y,ci=!si&&!W&&bn?(0,N.jsx)(Je,{views:Tn,activeId:En,onSelect:kn,onSave:An,accentColor:Me(d.color),onOpenToSide:e=>{sn({treeName:U,path:H,viewId:e}),un(`right`)}}):void 0,li=$t||d.status!==`active`?(0,N.jsxs)(N.Fragment,{children:[$t&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>{tn(!en),I(1)},"aria-pressed":en,className:g(`min-h-10 rounded-md border px-2 text-xs`,en&&`bg-warning/15 text-warning`),children:`Unfiled only`}),d.status!==`active`&&(0,N.jsx)(`button`,{type:`button`,onClick:Hr,disabled:at,className:`min-h-10 rounded-md border px-2 text-xs`,children:at?`Starting…`:`Start`})]}):void 0,ui=we(U,H)?H===`/Trash`?(0,N.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,N.jsx)(nt,{workspaceName:e||d.id})}):(0,N.jsx)(lt,{workspace:e||d.id,path:H,onNavigate:t=>o(Be(e,t,`backends`))},e):(0,N.jsx)(qe,{navigationTabs:ci,navigationActions:li,onBack:hn,accentColor:Me(d.color),urlType:G?E(U)===`directory`?`${U}-layer`:`context-layer`:X===`canvas`?`canvas`:E(U)===`directory`?U:`context`,urlDisplay:Hn,contextPath:H,treeName:U,workspaceId:e||d.id,workspaceLabel:d.label||d.name,workspaceIcon:d.icon,documentSchema:Dn,documents:or,isLoading:re,totalCount:rr,currentPage:F,pageSize:L,onPageChange:I,onPageSizeChange:e=>{Mt(e),I(1)},onRemoveDocument:H===`/`?void 0:Ur,onDeleteDocument:Wr,onDestroyDocument:qr,onRemoveDocuments:H===`/`?void 0:Gr,onDeleteDocuments:Kr,onDestroyDocuments:Jr,onCopyDocuments:Yr,onCutDocuments:Xr,onPasteDocuments:W?void 0:Qr,onImportDocuments:W?void 0:$r,onSelectionChange:fn,onBrowseTree:()=>mn(`workspaces`,`detail`,e??null),onBrowseWorkspaces:()=>pn(`workspaces`),onNavigatePath:t=>o(Be(e,t,U)),folders:yn,onOpenFolder:t=>o(Be(e,ze(t),U)),scope:j,onScopeChange:it,pastedDocumentIds:st?.documentIds,linkTree:q,onPurgeDocuments:W?void 0:ei,disablePurgeDocuments:mr,canvasInfo:Mn??void 0,isCanvasPinned:Rn,onTogglePinCanvas:$?Vn:void 0,onSaveAsCanvas:q&&X!==`canvas`&&!G&&!W?ti:void 0,onShareCanvas:X===`canvas`&&!G?ri:void 0,onUnshareCanvas:P?ii:void 0,onDeleteCanvas:X===`canvas`&&!G?ai:void 0,isSharingCanvas:yt,isDeletingCanvas:Ct,isCanvasShared:!!P,isCanvasLocked:!!Y?.locked,backendSearchQueries:z,onBackendSearch:Rr,serverSort:B.filters.sort,onServerSortChange:Rt,onRemoveBackendQuery:zr,canSaveChanges:Vr,isSavingChanges:B.isSaving,onSaveChanges:Lt,contentBanner:A&&Ee?(0,N.jsx)(Dt,{data:Ee,className:`mb-3`}):null,children:si&&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?Wn:void 0}):!W&&Q.kind===`columns`?(0,N.jsx)(Qe,{documents:or,workspaceId:e||d.id,columns:Q.columns??[],onColumnsChange:e=>An(Tn.map(t=>t.id===Q.id?{...t,columns:e}:t))}):!W&&Q.kind===`app`&&Q.app&&Q.app!==`notes`?(0,N.jsx)(Xe,{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)(dt,{workspaceId:d.id,workspaceName:d.label||d.name},d.id),we(U,H)&&(0,N.jsx)(Se,{workspace:d.label||d.name,workspaceIcon:d.icon,tree:U,path:H,onBack:hn,onBrowseTree:()=>mn(`workspaces`,`detail`,e||d.id),onBrowseWorkspaces:()=>pn(`workspaces`),onNavigatePath:t=>o(Be(e,t,U)),accentColor:Me(d.color)}),ut&&(0,N.jsx)(`div`,{className:`shrink-0 px-2 pt-2`,children:(0,N.jsx)(Ge,{title:`New canvas`,onClose:()=>ft(null),children:(0,N.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ni()},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:pt,onChange:e=>mt(e.target.value),onKeyDown:e=>{e.key===`Escape`&&ft(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:ut.parentPath===`/`?`/`:ut.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:ut.captureView,onChange:e=>ft({...ut,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)(ee,{type:`submit`,disabled:!pt.trim()||ht,children:ht?`Creating…`:`Create canvas`}),(0,N.jsx)(ee,{type:`button`,variant:`outline`,onClick:()=>ft(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:g(`flex-1 min-w-0 bg-background overflow-hidden`,J&&(ln===`left`?`ring-2 ring-primary`:`ring-1 ring-primary/20`)),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||un(`left`)},children:ui}),J&&e&&(0,N.jsx)(Pt,{workspaceName:e,workspaceLabel:d.label||d.name,workspaceIcon:d.icon,pane:J,isFocused:ln===`right`,clipboard:st,setClipboard:ct,onFocus:()=>un(`right`),onSelectionChange:_n,onNavigate:e=>sn(t=>t&&{...t,path:e,viewId:void 0}),onClose:()=>{sn(null),un(`left`),_n([])}})]})]})}function Nt(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 Pt({workspaceName:e,workspaceLabel:t,workspaceIcon:n,pane:r,isFocused:i=!1,clipboard:a,setClipboard:o,onFocus:s,onSelectionChange:c,onNavigate:l,onClose:u}){let{openM1Drawer:d,openM2Drawer:f}=Ve(),{showToast:p,showProgress:m}=ne(),[h,ee]=(0,M.useState)(null),[_,te]=(0,M.useState)([]),[v,y]=(0,M.useState)(!1),[re,b]=(0,M.useState)(0),[x,ie]=(0,M.useState)(1),[w,se]=(0,M.useState)(50),T=E(r.treeName),ce=Nt(h,r.path),le=ce?.type===`canvas`,D=(0,M.useMemo)(()=>et(h,r.path),[h,r.path]),O=r.viewId?$e(ce?.metadata).find(e=>e.id===r.viewId)??null:null,fe=`${e}://${r.path===`/`?``:r.path.replace(/^\//,``)}`,pe=Ze(O),me=(0,M.useCallback)(async()=>{if(we(r.treeName,r.path)){te([]),b(0),y(!1);return}let t=kt(e,r.treeName,r.path,x,w,``,pe??``),n=Ot.get(t);if(n){te(n.documents),b(n.totalCount);return}y(!0);try{let n=await de(e,r.path,pe?[pe]:[],{limit:w,page:x,treeName:r.treeName,treeType:T}),i=n.payload||[],a=n.totalCount||n.count||0;te(i),b(a),Ot.set(t,{documents:i,totalCount:a})}catch(e){p({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch side pane documents`,variant:`destructive`}),te([]),b(0)}finally{y(!1)}},[e,r.path,r.treeName,T,w,x,p,pe]);(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,ee(e))}).catch(()=>{!t&&o===n&&!i&&ee(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)(()=>{me()},[me]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||(jt(e,n),xt(bt(n),{tree:r.treeName,kind:E(r.treeName),path:r.path})&&(R(e,r.treeName,r.path),me()))};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[me,e,r.treeName,r.path]);let he=(0,M.useCallback)(async(t,n,i={})=>{let s=i.targetTreeName??r.treeName,c=i.targetTreeType??T,l=i.move??a?.operation===`cut`,u=m({title:l?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let r=await ae(e,t,n,s,c);if(r){R(e,s,t);let r=i.sourcePath||a?.sourcePath,c=i.sourceTreeName||a?.sourceTreeName;if((i.move??a?.operation===`cut`)&&r&&c){let t=E(c);await C(e,n,r,[],c,t),R(e,c,r),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:r,treeName:c}}))}u.done({title:`Success`,description:`${n.length} document(s) ${l?`moved`:`pasted`} to "${t}"`}),o(null),await me(),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t,treeName:s}}))}else u.done();return r}catch(e){return u.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},[e,r.treeName,T,me,m,a,o]),_e=(0,M.useCallback)(()=>{R(e,r.treeName,r.path),me()},[e,r.treeName,r.path,me]),ve=(0,M.useCallback)(async t=>{let n=m({title:`Removing…`,description:`${t.length} document(s) from "${r.path}"`});try{await C(e,t,r.path,[],r.treeName,T),_e(),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,T,_e,m]),ye=(0,M.useCallback)(async t=>{let n=m({title:`Deleting…`,description:`${t.length} document(s)`});try{await ge(e,t,r.path,[],r.treeName,T),_e(),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,T,_e,m]),be=(0,M.useCallback)(async t=>{let n=m({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await S(e,t);if(r.failed?.length&&!r.successful?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}_e();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,_e,m]);return(0,N.jsxs)(`div`,{className:g(`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`)||s()},children:[u&&(0,N.jsx)(`button`,{type:`button`,onClick:u,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`}),we(r.treeName,r.path)?r.path===`/Trash`?(0,N.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,N.jsx)(nt,{workspaceName:e})}):(0,N.jsx)(lt,{workspace:e,path:r.path,onNavigate:l||(()=>{})}):(0,N.jsx)(qe,{frameContent:!1,onBrowseWorkspaces:()=>d(`workspaces`),onBrowseTree:()=>f(`workspaces`,`detail`,e),urlType:le?`canvas`:T===`directory`?r.treeName:`context`,urlDisplay:fe,contextPath:r.path,treeName:r.treeName,workspaceId:e,workspaceLabel:t,workspaceIcon:n,documentSchema:pe,documents:_,isLoading:v,totalCount:re,currentPage:x,pageSize:w,onPageChange:ie,onPageSizeChange:e=>{se(e),ie(1)},onRemoveDocument:r.path===`/`?void 0:e=>ve([e]),onRemoveDocuments:r.path===`/`?void 0:ve,onDeleteDocument:e=>ye([e]),onDeleteDocuments:ye,onDestroyDocument:e=>be([e]),onDestroyDocuments:be,onCopyDocuments:e=>{o({documentIds:e,operation:`copy`,sourcePath:r.path,sourceTreeName:r.treeName}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`copy`}}))},onCutDocuments:e=>{o({documentIds:e,operation:`cut`,sourcePath:r.path,sourceTreeName:r.treeName}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}}))},onPasteDocuments:r.treeName===`backends`?void 0:he,onSelectionChange:c,pastedDocumentIds:a?.documentIds,linkTree:h,folders:D,onOpenFolder:l,onNavigatePath:l,canvasInfo:le?{label:ce?.label,description:ce?.description,color:ce?.color}:void 0,children:O?.kind===`columns`?(0,N.jsx)(Qe,{documents:_,workspaceId:e,columns:O.columns??[],onColumnsChange:()=>{},readOnly:!0}):O?.kind===`app`&&O.app&&O.app!==`notes`?(0,N.jsx)(Xe,{app:O.app,workspaceId:e,treeName:r.treeName,path:r.path}):null})]})}export{Mt 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{Kn as o,L as s,Tt as c,Ur as l,Vr as u,X as d,ar as f,gr as p,kt as m,pn as h}from"./ui-CDoK3F3U.js";import{t as g}from"./utils-2pl1SbIp.js";import{t as ee}from"./button-SeUZ_Pvi.js";import{c as _,t as te}from"./api-CA6WiiYM.js";import{t as v}from"./socket-CtH3EU9m.js";import{n as ne}from"./use-toast-BlLDqSUO.js";import{h as y,o as re,s as b}from"./LinkToCard-CKVi4Nrg.js";import{At as x,D as S,G as ie,Gt as C,Kt as w,Lt as ae,W as oe,Y as se,_ as T,_n as ce,a as le,bn as E,gt as D,lt as O,mt as ue,nt as de,rn as fe,rt as pe,u as me,vt as he,w as ge,x as _e,y as ve,zt as ye}from"./workspace-C5V-ZCOE.js";import{n as be,r as xe}from"./use-canvas-pins-BPCW4twY.js";import{u as Se}from"./ObjectPropertiesCard-D2lrTQqT.js";import{a as Ce,c as k,d as we,f as A,i as Te,l as Ee,o as De,p as Oe,r as ke,w as Ae}from"./document-list-rzRLzfkF.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-DIP1zh7I.js";import{n as He}from"./last-path-BbXWC3b3.js";import{t as Ue}from"./workspace-area-menu-BN5ysUpx.js";import{t as We}from"./workspace-content-gate-C54J9Man.js";import{t as Ge}from"./form-panel-3p-ncEVK.js";import{a as Ke,c as qe,i as Je,l as Ye,n as Xe,o as Ze,r as Qe,s as $e,t as et,u as tt}from"./tree-folders-Q5iu5vpu.js";import{i as nt,r as rt}from"./query-debug-lD5vbJGi.js";var j=`session.open`,it=`session.set`,at=`session.ids`,ot=`session.materialize`,st=`session.close`,ct=`session.delta`,M=e(n(),1),N=t();function lt(e){let t=we(`backends`,e.path)?.backend;return(0,N.jsx)(ut,{...e},JSON.stringify([e.workspace,t]))}function ut({workspace:e,path:t,onNavigate:n}){let r=we(`backends`,t),i=r.backend,a=r.prefix,[s,l]=(0,M.useState)(null),[u,h]=(0,M.useState)(null),g=(0,M.useRef)(!1),[ee,_]=(0,M.useState)(null),[te,v]=(0,M.useState)(null),[ne,x]=(0,M.useState)(0),[S,ie]=(0,M.useState)(new Set),[C,w]=(0,M.useState)(null),ae=(0,M.useCallback)(()=>x(e=>e+1),[]),[oe,se]=(0,M.useState)(t);oe!==t&&(se(t),ie(new Set),w(null),v(null),_(null));let T=s?.revision!==ne,ce=T?[]:s.items,le=T?[]:s.backends,E=s?.days;(0,M.useEffect)(()=>{let t=!1;return(i?k(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||l({...e,revision:ne,error:null})}).catch(e=>{t||l({revision:ne,items:[],backends:[],days:null,error:e instanceof Error?e.message:String(e)})}),()=>{t=!0}},[e,i,ne]),(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,ae()},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,ae]);let D=Oe(ce,a),O=async(t,n)=>{if(!(!i||g.current||T||!n.length)&&!(t===`discard`&&!Ce(i,n))){g.current=!0,h(t),_(null),v(null),w(null);try{let r=await(t===`restore`?Ee:De)(e,i,[...n].sort((e,t)=>t.deletedAt-e.deletedAt).map(e=>e.id)),a=r.filter(e=>!e.ok);v(`${r.length-a.length} item(s) ${t===`restore`?`restored to their original paths`:`permanently deleted`}.`),a.length&&_(`${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(`; `)}`),ie(new Set)}catch(e){_(e instanceof Error?e.message:String(e))}finally{g.current=!1,h(null),ae()}}},ue=(e,t,n)=>w({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)(b,{items:re(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:[S.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 O(`restore`,D.filter(e=>S.has(e.id)).flatMap(e=>e.items)),children:[(0,N.jsx)(c,{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 O(`discard`,D.filter(e=>S.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 O(`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:ae,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.`,E?` Deleted items are kept for ${E} days.`:``]}),te&&(0,N.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-sm`,children:te}),(ee||s?.error)&&(0,N.jsx)(`p`,{role:`alert`,className:`px-4 py-2 text-sm text-destructive`,children:ee||s?.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=>S.has(e.id)),onChange:e=>ie(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(),ue(t.clientX,t.clientY,e)},onDoubleClick:()=>e.navigable&&n(A(i,e.key)),children:[(0,N.jsx)(`td`,{className:`p-2`,children:(0,N.jsx)(`input`,{type:`checkbox`,"aria-label":`Select ${e.name}`,checked:S.has(e.id),disabled:!!u,onChange:t=>ie(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(A(i,e.key)),children:[e.directory?(0,N.jsx)(o,{className:`h-4 w-4 shrink-0`}):(0,N.jsx)(f,{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=>ue(t.clientX,t.clientY,e),children:(0,N.jsx)(p,{className:`h-4 w-4`})})})]},e.id))})]}):(0,N.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-3`,children:[le.map(e=>(0,N.jsxs)(`button`,{onClick:()=>n(A(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)),!le.length&&(0,N.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,children:`No file backends are available.`})]})}),C&&(0,N.jsxs)(y,{x:C.x,y:C.y,onClose:()=>w(null),className:`min-w-44 rounded-md border bg-popover p-1 shadow-elevation-3`,children:[C.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(A(i,C.row.key)),w(null)},children:[(0,N.jsx)(o,{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 O(`restore`,C.row.items),children:[(0,N.jsx)(c,{className:`h-4 w-4`}),`Restore `,C.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 O(`discard`,C.row.items),children:[(0,N.jsx)(d,{className:`h-4 w-4`}),`Delete permanently`]})]})]})}function dt({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=v.on(`connect`,l);return v.on(`backend.resync.changed`,u),v.on(`backend.changed`,d),window.addEventListener(`focus`,l),()=>{t=!0,f?.(),v.off(`backend.resync.changed`,u),v.off(`backend.changed`,d),window.removeEventListener(`focus`,l)}},[e]);let c=n.filter(e=>!i.has(o(e)));return c.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)(h,{"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,...c.map(o)])),children:(0,N.jsx)(s,{"aria-hidden":`true`,className:`h-4 w-4`})})]}),(0,N.jsx)(`div`,{className:`max-h-48 space-y-3 overflow-y-auto`,children:c.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 ft=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:null;function pt(e){return`/${e}`.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`}function mt(e,t,n){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>mt(e,t,n));if(typeof e==`string`)return[{tree:null,kind:t,path:pt(e)}];let r=ft(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:pt(e)}))}function ht(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 gt(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 _t(e,t,n=new Map){let r=ft(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:pt(n)}],ids:ht(r),unknown:!1}:{targets:[],ids:[],unknown:!0}}let i=[...mt(r.context,`context`,n),...mt(r.directory,`directory`,n)],a=ft(r.changed);a&&i.push(...mt(a.context,`context`,n),...mt(a.directory,`directory`,n));let o=ht(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 vt(e,t){return e===t||e===`/`||t===`/`||e.startsWith(`${t}/`)||t.startsWith(`${e}/`)}function yt(e,t){if(e.kind&&e.kind!==t.kind||e.tree&&e.tree!==t.tree)return!1;if(t.kind===`context`){let n=e=>pt(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 vt(e.path,t.path)}function bt(e){return _t(`tree.refresh`,{treeName:e?.treeName,path:e?.path||`/`})}function xt(e,t,n){if(e.unknown||e.targets.length&&(t.wholeWorkspace||e.targets.some(e=>yt(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 St(e,t,n={}){return v.request(j,{workspace:e,specs:t,opts:n})}function Ct(e,t,n){return v.request(it,{sessionId:e,label:t,spec:n})}function wt(e){return v.request(at,{sessionId:e})}function P(e,t={}){return v.request(ot,{sessionId:e,...t})}function Tt(e){return v.request(st,{sessionId:e})}function F(e){return v.on(ct,e)}var I=100;function Et({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),h=(0,M.useRef)(null),g=(0,M.useRef)(null),ee=(0,M.useRef)({}),_=(0,M.useRef)(null),te=(0,M.useMemo)(()=>JSON.stringify(t),[t]),ne=(0,M.useMemo)(()=>JSON.stringify(n??{}),[n]),y=(0,M.useCallback)(()=>{let e=p.current;a(f.current.map(t=>e.get(t)).filter(Boolean))},[]),re=(0,M.useCallback)(async e=>{let t=h.current;if(!t||e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=I){let i=e.slice(r,r+I),a=await de(t,`/`,[],{ids:i,scope:`workspace`,limit:i.length});n.push(...a.payload||[])}return n},[]),b=(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),y(),r.length===0)return;let a=await re(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))}y()},[re,y]),x=(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 b(a,[],t)},[b]);(0,M.useEffect)(()=>{if(h.current=e??null,!r||!e)return;let t=!1,n=null,i=async()=>{try{let r=await St(e,JSON.parse(te),JSON.parse(ne));if(t){Tt(r.sessionId).catch(()=>{});return}n=r.sessionId,m.current=r.sessionId,l(r.sessionId),d(null),f.current=[],p.current=new Map,await x(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=v.on(`connect`,()=>{i()});return()=>{t=!0,o?.();let e=n??m.current;e&&Tt(e).catch(()=>{}),m.current=null,f.current=[],p.current=new Map,l(null),a([]),s(0)}},[e,te,ne,r]),(0,M.useEffect)(()=>{if(!c)return;let e=F(e=>{if(e.sessionId===c){if(g.current!==null){_.current?.(g.current,ee.current);return}e.ids===void 0?b(e.added??[],e.removed??[],e.count):x(e.ids,e.count)}});return()=>{e?.()}},[c,b,x]);let S=(0,M.useCallback)(async()=>{let e=m.current;if(e)try{let t=await wt(e);await x(t.ids,t.count)}catch{}},[x]),ie=(0,M.useCallback)(async(e,t)=>{let n=m.current;if(!n)throw Error(`No open query session`);let r=await Ct(n,e,t);if(g.current!==null){await _.current?.(g.current,ee.current);return}await x(r.ids,r.count)},[x]),C=(0,M.useCallback)(async(e,t={})=>{let n=m.current;if(!n)throw Error(`No open query session`);if(g.current=e,ee.current=t,e===null){await S();return}let r=await P(n,{match:e,...t});for(let e of r.documents)p.current.set(e.id,e);f.current=r.ids,s(r.totalCount),y()},[y,S]);(0,M.useEffect)(()=>{_.current=C},[C]);let w=(0,M.useCallback)(async(e,t,n={})=>{let r=m.current;if(!r)throw Error(`No open query session`);let i=await P(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 Ct(r,e,{ids:i.ids});return await x(a.ids,a.count),i.ids},[x]);return{documents:i,count:o,ready:c!==null,error:u,setCue:ie,resync:S,rank:C,rankAndPin:w}}function Dt({data:e,className:t}){let[n,r]=(0,M.useState)(!0),{rows:i,gapIndex:a,span:o}=(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:g(`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 s=a>0?i[a].distance:null;return(0,N.jsxs)(`div`,{className:g(`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)(l,{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.`,s===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 Δ`,o.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:s.toFixed(4)}),` (Δ`,o.biggest.toFixed(4),`, vs typical Δ`,o.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:g(`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 `,o.first.toFixed(4),` – `,o.last.toFixed(4),` (spread `,(o.last-o.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 Ot=new Map;function L(e,t,n){return`${e}\0${t}\0${n}`}function kt(e,t,n,r,i,a,o=``,s=``,c=`path`){return`${L(e,t,n)}\0${r}\0${i}\0${a}\0${o}\0${s}\0${c}`}function R(e,t,n){let r=L(e,t,n);for(let e of Ot.keys())e.startsWith(r)&&Ot.delete(e)}function At(e,t){let n=`${e}\0`;for(let[e,r]of Ot){if(!e.startsWith(n))continue;let[,i,a,,,,,,o=`path`]=e.split(`\0`);xt(t,{tree:i,kind:E(i),path:a,wholeWorkspace:o.startsWith(`workspace`)},r.documents.map(e=>Number(e.id)))&&Ot.delete(e)}}function jt(e,t){At(t?.workspaceName??e,bt(t))}function Mt(){let{workspaceName:e}=r();return e?(0,N.jsx)(We,{workspaceName:e,children:(0,N.jsx)(z,{})}):null}function z(){let{workspaceName:e,treeName:t}=r(),n=a(),o=i(),{showToast:s,showProgress:c}=ne(),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),[h,y]=(0,M.useState)([]),[re,b]=(0,M.useState)(!1),[Ce,k]=(0,M.useState)(0),A=rt(),[Ee,De]=(0,M.useState)(null),[Oe,We]=(0,M.useState)(A);Oe!==A&&(We(A),A||De(null));let[j,it]=(0,M.useState)(`path`),[at,ot]=(0,M.useState)(!1),[st,ct]=(0,M.useState)(null),[ut,ft]=(0,M.useState)(null),[pt,mt]=(0,M.useState)(``),[ht,vt]=(0,M.useState)(!1),[yt,St]=(0,M.useState)(!1),[Ct,wt]=(0,M.useState)(!1),[P,Tt]=(0,M.useState)(null),[F,I]=(0,M.useState)(1),[L,Mt]=(0,M.useState)(50),[z,Nt]=(0,M.useState)(u),[Ft,It]=(0,M.useState)(null),{state:B,saveFilters:Lt,setSort:Rt,setAccentColor:zt,setMapDocuments:Bt}=je(),Vt=B.filters.features.allOf,Ht=B.filters.features.anyOf,Ut=B.filters.features.noneOf,Wt=Fe(B.filters.timeline),Gt=Pe(B.filters.geo),Kt=Le(B.filters.lens,B.filters.geo.includeUnlocated),V=B.filters.lens.ids,qt=[...Wt,...Gt,...Kt],Jt=B.filters.sort??Ie,Yt=JSON.stringify({a:Vt,b:Ht,c:Ut,d:qt,i:V,s:Jt}),Xt=JSON.stringify({a:Vt,b:Ht,c:Ut,d:qt,s:Jt}),H=Re(n.pathname).path,U=t??`context`,W=U===`backends`,[Zt,Qt]=(0,M.useState)([]);(0,M.useEffect)(()=>{!W||!e||he(e).then(Qt).catch(()=>Qt([]))},[W,e]);let $t=W?le(H,Zt):null,[en,tn]=(0,M.useState)(!1),nn=`${U}\0${H}`,[rn,an]=(0,M.useState)(nn);rn!==nn&&(an(nn),tn(!1));let G=l.get(`layer`)===`1`,K=l.get(`layerId`)||null,[q,on]=(0,M.useState)(null),[J,sn]=(0,M.useState)(null),cn=(0,M.useRef)(null);(0,M.useEffect)(()=>{cn.current=J},[J]);let[ln,un]=(0,M.useState)(`left`),[dn,fn]=(0,M.useState)([]),{openM1Drawer:pn,openM2Drawer:mn,goBack:hn}=Ve(),[gn,_n]=(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,vn=(0,M.useRef)(null);(0,M.useEffect)(()=>{!e||!q||G||vn.current===`${e}/${U}`&&(H!==`/`&&!Y||He(e,U,H))},[e,q,G,H,Y,U]);let yn=(0,M.useMemo)(()=>G||j===`workspace`||z.length>0?[]:et(q,H),[q,H,G,j,z]),bn=G?null:H===`/`?q:Y,Z=Ae(),xn=`${U}\0${H}`,[Sn,Cn]=(0,M.useState)(null),wn=Sn?.key===xn?Sn.views:$e(bn?.metadata),Tn=Z?.pinned&&Z.view?[Z.view,...wn.filter(e=>e.id!==Z.view.id)]:wn,En=Z?.pinned&&Z.view?Z.view.id:Sn?.key===xn?Sn.activeId:Tn[0]?.id??Ke.id,Q=Tn.find(e=>e.id===En)??Tn[0]??Ke;(0,M.useEffect)(()=>{Z?.selectView(Q)},[Q,Z]);let Dn=W?void 0:Z?.schema??Ze(Q),On=Dn?[...Vt,Dn]:Vt;tt(Ye({workspace:e??null,treeNameOrId:U,treeType:E(U),path:H,scope:j===`workspace`?`workspace`:G?`layer`:`path`,layerId:G?K:void 0,unfiledOnly:en},{...B.filters,features:{...B.filters.features,allOf:On}},B.geoSelection,z));let kn=e=>{let t=Tn.find(t=>t.id===e);t&&Z?.selectView(t),I(1),fn([]),Cn({key:xn,views:Tn,activeId:e})},An=(t,n)=>{n&&n!==En&&(I(1),fn([]));let r=t.find(e=>e.id===(n??En));r&&Z?.selectView(r),Cn({key:xn,views:t,activeId:n??En}),ce(e,H,{metadata:{...bn?.metadata??{},views:t}},U).catch(()=>{s({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},jn=X===`canvas`&&typeof Y?.querySpec?.query==`string`?Y.querySpec.query:``,Mn=X===`canvas`?{label:Y?.label,description:Y?.description,color:Y?.color}:null,{isPinned:Nn,pin:Pn,unpin:Fn,pins:In}=be(),Ln=d?.name,$=(0,M.useMemo)(()=>Ln&&X===`canvas`&&!G?{workspaceName:Ln,treeName:U,path:H}:null,[Ln,X,G,U,H]),Rn=$?Nn($):!1,zn=Y?.id,Bn=Y?.label,Vn=(0,M.useCallback)(async()=>{if($)try{let e=In.find(e=>e.workspaceName===$.workspaceName&&e.treeName===$.treeName&&e.path===$.path);e?await Fn(e.id):await Pn({...$,layerId:zn,label:Bn})}catch(e){console.error(`Failed to update home pins:`,e)}},[$,In,Pn,Fn,zn,Bn]),Hn=e?`${e}://${H===`/`?``:H.replace(/^\//,``)}`:``,Un=Me(d?.color)||null;(0,M.useEffect)(()=>(zt(Un),()=>zt(null)),[Un,zt]);let Wn=(0,M.useCallback)(async t=>{let n=V;if(t?.anyOf?.length&&Ht.length&&(n=((await ie(e,H,U,{limit:0,anyOf:Ht,ids:V,applyCanvasSpec:!1})).payload||[]).map(e=>e.id),!n.length))return{payload:[],count:0,totalCount:0};let r=await ie(e,H,U,{limit:t?.limit,offset:t?.offset,page:t?.page,sortBy:t?.sortBy,order:t?.order,allOf:[...Vt,...t?.allOf??[]],anyOf:t?.anyOf?.length?t.anyOf:Ht,noneOf:Ut,filters:qt,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,Yt,z]);(0,M.useEffect)(()=>{e&&(async()=>{m(!0);try{let t=await te.get(`${_.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 Gn=(V?.length??0)>0&&!G&&!(en&&$t)&&z.length<=1,{documents:Kn,count:qn,ready:Jn,setCue:Yn,resync:Xn,rank:Zn}=Et({workspaceRef:e,specs:(0,M.useMemo)(()=>{let e={features:{allOf:On,anyOf:Ht,noneOf:Ut},filters:qt};return j!==`workspace`&&(E(U)===`directory`?e.directory={tree:U,path:H}:e.context=H),[{label:`scope`,spec:e}]},[Xt,H,U,j,Dn]),opts:(0,M.useMemo)(()=>({mode:`live`,debounceMs:150}),[]),enabled:Gn}),Qn=Gn&&Jn,$n=(0,M.useRef)(!1);(0,M.useEffect)(()=>{$n.current=Qn},[Qn]);let er=z.length===1?z[0].trim():``;(0,M.useEffect)(()=>{Jn&&Zn(er?{text:er}:null,{limit:L,offset:(F-1)*L}).catch(()=>{})},[Jn,er,L,F,Zn]);let tr=(V??[]).join(`,`);(0,M.useEffect)(()=>{Jn&&Yn(`lens`,{ids:V??[]}).catch(()=>{})},[Jn,tr,Yn,V]);let nr=Qn?Kn:h,rr=Qn?qn:Ce,ir=(0,M.useRef)(new Set);(0,M.useEffect)(()=>{ir.current=new Set(nr.map(e=>Number(e.id)))},[nr]);let ar=B.geoSelection;(0,M.useEffect)(()=>{Bt(nr,d?.name??null)},[nr,d?.name,Bt]),(0,M.useEffect)(()=>()=>Bt([]),[Bt]);let or=(0,M.useMemo)(()=>ar?nr.filter(e=>Ne(e,ar,B.filters.geo.includeUnlocated)):nr,[nr,ar,B.filters.geo.includeUnlocated]),sr=me(H,On,{treeName:U,treeType:E(U),scope:j,queries:z,anyOf:Ht,noneOf:Ut,filters:qt,ids:V,layerId:G&&K?K:void 0}),cr=JSON.stringify([e,sr]),[lr,ur]=(0,M.useState)(``),[dr,fr]=(0,M.useState)(!1),pr=(0,M.useRef)(!1),mr=re||dr||lr!==cr||Qn||!!ar,hr=(0,M.useRef)(0),gr=(0,M.useRef)(null);(0,M.useEffect)(()=>()=>{hr.current++,gr.current=null},[]);let _r=(0,M.useRef)(``),vr=(0,M.useCallback)(async t=>{if(!e)return;if(we(U,H)){hr.current++,gr.current=null,_r.current=``,y([]),k(0),b(!1);return}if($n.current)return;let n=`${en&&$t?`${j}:unfiled`:j}:${Dn??``}`,r=(V?.length??0)>0,i=kt(e,U,H,F,L,z.join(`␟`),Xt,G&&K?K:``,n),a=r&&i===_r.current;_r.current=i;let o=kt(e,U,H,F,L,z.join(`␟`),Yt,G&&K?K:``,n),c=`${o}\0${A}`;if(t?.silent&&gr.current?.key===c){gr.current.refreshPending=!0;return}let l=++hr.current,u=t?.silent||r||A?void 0:Ot.get(o);u&&(y(u.documents),k(u.totalCount),ur(cr),b(!1)),(t?.silent??(a||!!u))||b(!0);let d={key:c,refreshPending:!1};gr.current=d;try{let t;if(en&&$t)t=await D(e,$t.driver,$t.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:On,anyOf:Ht,noneOf:Ut,filters:qt,ids:V,sortBy:Jt.sortBy||void 0,order:Jt.order});else{let n=E(U);t=await de(e,H,On,{limit:L,page:F,treeName:U,treeType:n,queries:z,anyOf:Ht,noneOf:Ut,filters:qt,ids:V,sortBy:Jt.sortBy||void 0,order:Jt.order,scope:j,debug:A&&z.length>0,debugLimit:200})}let n=t.payload||[],i=t.totalCount||t.count||0;if(!r&&!d.refreshPending&&Ot.set(o,{documents:n,totalCount:i}),l!==hr.current)return;let s=t.debug,c=s?.imageDistances??s?.distances??null;De(c?{query:z[z.length-1]??``,distances:c}:null),y(a?e=>e.length===n.length&&e.every((e,t)=>e.id===n[t].id)?e:n:n),k(i),ur(cr)}catch(e){if(l!==hr.current)return;let t=e instanceof Error?e.message:`Failed to fetch documents`;s({title:`Error`,description:t,variant:`destructive`}),y([]),k(0)}finally{gr.current===d&&(gr.current=null),l===hr.current&&b(!1),l===hr.current&&d.refreshPending&&vr({silent:!0})}},[e,H,U,K,G,F,L,d?.status,z,Yt,j,en,A,Dn]);(0,M.useEffect)(()=>{vr()},[vr]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;!n||n.workspaceName!==e||(sn({treeName:n.treeName||`context`,path:ze(n.path||`/`)}),un(`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&&jt(e,n),xt(bt(n),{tree:U,kind:E(U),path:H,wholeWorkspace:j===`workspace`}))){if(e&&R(e,U,H),$n.current){Xn();return}vr({silent:!0})}};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[vr,e,H,U,j,Xn]);let yr=d?.name,br=d?.id;(0,M.useEffect)(()=>{if(!e||!yr&&!br)return;let t=[yr,br].filter(Boolean).map(e=>`workspace:${e}`),n=()=>t.forEach(e=>v.emit(`subscribe`,{channel:e}));n();let r=v.on(`connect`,n),i=new Map,a=!1,o=()=>{x(e).then(e=>{a||(i=gt(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,$n.current){Xn();return}vr({silent:!0})}},f=t=>n=>{(t.startsWith(`tree.created`)||t.startsWith(`tree.renamed`))&&o();let r=_t(t,n,i);At(e,r);let a={tree:U,kind:E(U),path:H,wholeWorkspace:j===`workspace`},f=cn.current;f&&xt(r,{tree:f.treeName,kind:E(f.treeName),path:f.path})&&(u=f),xt(r,a,ir.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])=>v.on(e,t)),()=>{a=!0,s&&clearTimeout(s),r?.(),p.forEach(([e,t])=>v.off(e,t))}},[e,br,yr,U,H,j,vr,Xn]);let xr=`${H}\0${U}\0${K??``}\0${j}`,[Sr,Cr]=(0,M.useState)(xr);Sr!==xr&&(Cr(xr),I(1),It(null));let wr=`${H}\0${U}\0${K??``}`,[Tr,Er]=(0,M.useState)(wr);Tr!==wr&&(Er(wr),it(`path`));let Dr=(e,t)=>{let n=e===`/`?`canvas`:e.split(`/`).pop()||`canvas`;mt(n),ft({parentPath:e,captureView:t})},Or=l.get(`createCanvas`)===`1`,[kr,Ar]=(0,M.useState)(!1);kr!==Or&&(Ar(Or),Or&&Dr(H,!1)),(0,M.useEffect)(()=>{if(!Or)return;let e=new URLSearchParams(n.search);e.delete(`createCanvas`);let t=e.toString();o(`${n.pathname}${t?`?${t}`:``}${n.hash}`,{replace:!0})},[Or,H]);let jr=(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]),Mr=JSON.stringify([l.has(`q`),...u]),[Nr,Pr]=(0,M.useState)(Mr);Nr!==Mr&&(Pr(Mr),Nt(u),I(1));let Fr=`${Mr}\0${X??``}\0${jn}\0${H}\0${Ft??``}`,[Ir,Lr]=(0,M.useState)(Fr);Ir!==Fr&&(Lr(Fr),l.has(`q`)||u.length>0||X!==`canvas`||Ft===H||(Nt(jn?[jn]:[]),I(1)));let Rr=(0,M.useCallback)(e=>{let t=e.trim();t&&(It(null),Nt(e=>{if(e.includes(t))return e;let n=[...e,t];return jr(n),I(1),n}))},[jr,It,Nt,I]),zr=(0,M.useCallback)(e=>{Nt(t=>{let n=e<0?[]:t.filter((t,n)=>n!==e);return n.length===0&&It(H),jr(n),I(1),n})},[jr,H,It,Nt,I]),Br=z.join(` `).trim(),Vr=!!B.activeContextType&&(B.isDirty||Br!==(X===`canvas`?jn:B.savedSearchQuery||``));!e&&q!==null&&on(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,vn.current=`${e}/${U}`,on(i))}).catch(()=>{!t&&a===n&&!r&&on(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=Te(e,br);return()=>{t=!0,o(),window.removeEventListener(`workspace:tree:refresh`,a)}},[e,U,br]),!(e&&X===`canvas`&&!G)&&P!==null&&Tt(null),(0,M.useEffect)(()=>{let t=!1;if(!(!e||X!==`canvas`||G))return se(e,H,U).then(e=>{t||Tt(e)}).catch(()=>{t||Tt(null)}),()=>{t=!0}},[e,H,U,X,G]);let Hr=async()=>{if(d){ot(!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{ot(!1)}}},Ur=async t=>{if(!d)return;let n=c({title:`Removing…`,description:`Document from "${H}"`});try{await C(e||d.id,[t],H,[],U,Zr,{trashIfOrphaned:!0}),R(e||d.id,U,H),y(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`})}},Wr=async t=>{if(!d)return;let n=c({title:`Deleting…`,description:`Document from "${H}"`});try{await ge(e||d.id,[t],H,[],U,Zr),R(e||d.id,U,H),y(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`})}},Gr=async t=>{if(!d)return;let n=c({title:`Removing…`,description:`${t.length} document(s) from "${H}"`});try{await C(e||d.id,t,H,[],U,Zr,{trashIfOrphaned:!0}),R(e||d.id,U,H),y(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`})}},Kr=async t=>{if(!d)return;let n=c({title:`Deleting…`,description:`${t.length} document(s)`});try{await ge(e||d.id,t,H,[],U,Zr),R(e||d.id,U,H),y(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`})}},qr=async t=>{if(!d)return;let n=c({title:`Destroying…`,description:`Document and its backend copies`});try{let r=await S(e||d.id,[t]);if(r.failed?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}y(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`})}},Jr=async t=>{if(!d)return;let n=c({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await S(e||d.id,t),i=new Set(r.successful?.filter(e=>e.docDeleted).map(e=>e.id)??[]);y(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`})}},Yr=e=>{ct({documentIds:e,operation:`copy`,sourcePath:H,sourceTreeName:U}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`copy`}})),s({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},Xr=e=>{ct({documentIds:e,operation:`cut`,sourcePath:H,sourceTreeName:U}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}})),s({title:`Cut`,description:`${e.length} document(s) cut to clipboard`})},Zr=E(U),Qr=async(t,n,r={})=>{if(!e)return!1;let i=r.targetTreeName??U,a=r.targetTreeType??Zr,o=r.move??st?.operation===`cut`,s=c({title:o?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let c=await ae(e,t,n,i,a);if(c){R(e,i,t);let a=r.sourceTreeName||st?.sourceTreeName,c=r.sourcePath||st?.sourcePath;if((r.move??st?.operation===`cut`)&&c&&a){let t=E(a);await C(e,n,c,[],a,t),R(e,a,c),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:c,treeName:a}}))}s.done({title:`Success`,description:`${n.length} document(s) ${o?`moved`:`pasted`} to "${t}"`}),ct(null),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:null}));let l=performance.now();await vr(),console.info(`[paste] list refresh ${Math.round(performance.now()-l)} ms`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t,treeName:i}}))}else s.done();return c}catch(e){return s.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},$r=async(t,n)=>{if(!e)return!1;try{let r=(await O(e,n,t,U,Zr)).length>0;return r&&(ke(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}},ei=async()=>{if(!d||rr===0||mr||pr.current||window.prompt(`Type PURGE to permanently delete all ${rr} matching documents across all pages.`)!==`PURGE`)return;pr.current=!0,fr(!0);let t=c({title:`Purging…`,description:`${rr} matching document(s)`});try{let n=await ye(e||d.id,sr,rr);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 vr({silent:!0}),pr.current=!1,fr(!1)}},ti=()=>Dr(H,!0),ni=async()=>{if(!(!e||!ut||!pt.trim())){vt(!0);try{let t=pt.trim(),n=ut.parentPath,r=n===`/`?`/${t}`:`${n}/${t}`,i={...B.filters,features:{...B.filters.features,allOf:On}};await ve(e,r,U,ut.captureView?{metadata:{toolbox:i},querySpec:{features:i.features,filters:[...Fe(B.filters.timeline),...Pe(B.filters.geo)],query:Br||void 0,sort:B.filters.sort?.sortBy?B.filters.sort:null}}:{}),ft(null),ue(e,U);try{let t=await oe(e,U,{force:!0});on(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)}}},ri=async()=>{if(!(!e||X!==`canvas`)){St(!0);try{let t=P||await T(e,H,U);Tt(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)}}},ii=async()=>{if(P){St(!0);try{await _e(P.code),Tt(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)}}},ai=async()=>{if(!e||X!==`canvas`||H===`/`)return;let t=Mn?.label||H.split(`/`).pop()||`canvas`,n=P?` Its public link will stop working.`:``;if(window.confirm(`Delete canvas "${t}"? This cannot be undone.${n}`)){wt(!0);try{if(P)await _e(P.code),Tt(null);else if(Y?.locked){s({title:`Canvas is locked`,description:`Unlock it before deleting.`,variant:`destructive`});return}await w(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{wt(!1)}}},oi=(0,M.useCallback)(async t=>{if(!e||!J)return;let n={treeName:U,path:H},r=ln===`left`?n:J,i=ln===`left`?J:n,a=ln===`left`?dn:gn;if(a.length===0){s({title:`Nothing selected`,description:`Tick documents in the focused pane first.`});return}let o=E(i.treeName),l=c({title:t?`Moving…`:`Copying…`,description:`${a.length} document(s) → "${i.path}"`});try{if(!await ae(e,i.path,a,i.treeName,o)){l.done();return}if(R(e,i.treeName,i.path),t){let t=E(r.treeName);await C(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,ln,U,H,dn,gn,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(),oi(e.key===`F6`))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[J,oi]),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 si=X===`canvas`&&!G&&!!Y,ci=!si&&!W&&bn?(0,N.jsx)(Je,{views:Tn,activeId:En,onSelect:kn,onSave:An,accentColor:Me(d.color),onOpenToSide:e=>{sn({treeName:U,path:H,viewId:e}),un(`right`)}}):void 0,li=$t||d.status!==`active`?(0,N.jsxs)(N.Fragment,{children:[$t&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>{tn(!en),I(1)},"aria-pressed":en,className:g(`min-h-10 rounded-md border px-2 text-xs`,en&&`bg-warning/15 text-warning`),children:`Unfiled only`}),d.status!==`active`&&(0,N.jsx)(`button`,{type:`button`,onClick:Hr,disabled:at,className:`min-h-10 rounded-md border px-2 text-xs`,children:at?`Starting…`:`Start`})]}):void 0,ui=we(U,H)?H===`/Trash`?(0,N.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,N.jsx)(nt,{workspaceName:e||d.id})}):(0,N.jsx)(lt,{workspace:e||d.id,path:H,onNavigate:t=>o(Be(e,t,`backends`))},e):(0,N.jsx)(qe,{navigationTabs:ci,navigationActions:li,onBack:hn,accentColor:Me(d.color),urlType:G?E(U)===`directory`?`${U}-layer`:`context-layer`:X===`canvas`?`canvas`:E(U)===`directory`?U:`context`,urlDisplay:Hn,contextPath:H,treeName:U,workspaceId:e||d.id,workspaceLabel:d.label||d.name,workspaceIcon:d.icon,documentSchema:Dn,documents:or,isLoading:re,totalCount:rr,currentPage:F,pageSize:L,onPageChange:I,onPageSizeChange:e=>{Mt(e),I(1)},onRemoveDocument:H===`/`?void 0:Ur,onDeleteDocument:Wr,onDestroyDocument:qr,onRemoveDocuments:H===`/`?void 0:Gr,onDeleteDocuments:Kr,onDestroyDocuments:Jr,onCopyDocuments:Yr,onCutDocuments:Xr,onPasteDocuments:W?void 0:Qr,onImportDocuments:W?void 0:$r,onSelectionChange:fn,onBrowseTree:()=>mn(`workspaces`,`detail`,e??null),onBrowseWorkspaces:()=>pn(`workspaces`),onNavigatePath:t=>o(Be(e,t,U)),folders:yn,onOpenFolder:t=>o(Be(e,ze(t),U)),scope:j,onScopeChange:it,pastedDocumentIds:st?.documentIds,linkTree:q,onPurgeDocuments:W?void 0:ei,disablePurgeDocuments:mr,canvasInfo:Mn??void 0,isCanvasPinned:Rn,onTogglePinCanvas:$?Vn:void 0,onSaveAsCanvas:q&&X!==`canvas`&&!G&&!W?ti:void 0,onShareCanvas:X===`canvas`&&!G?ri:void 0,onUnshareCanvas:P?ii:void 0,onDeleteCanvas:X===`canvas`&&!G?ai:void 0,isSharingCanvas:yt,isDeletingCanvas:Ct,isCanvasShared:!!P,isCanvasLocked:!!Y?.locked,backendSearchQueries:z,onBackendSearch:Rr,serverSort:B.filters.sort,onServerSortChange:Rt,onRemoveBackendQuery:zr,canSaveChanges:Vr,isSavingChanges:B.isSaving,onSaveChanges:Lt,contentBanner:A&&Ee?(0,N.jsx)(Dt,{data:Ee,className:`mb-3`}):null,children:si&&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?Wn:void 0}):!W&&Q.kind===`columns`?(0,N.jsx)(Qe,{documents:or,workspaceId:e||d.id,columns:Q.columns??[],onColumnsChange:e=>An(Tn.map(t=>t.id===Q.id?{...t,columns:e}:t))}):!W&&Q.kind===`app`&&Q.app&&Q.app!==`notes`?(0,N.jsx)(Xe,{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)(dt,{workspaceId:d.id,workspaceName:d.label||d.name},d.id),we(U,H)&&(0,N.jsx)(Se,{workspace:d.label||d.name,workspaceIcon:d.icon,tree:U,path:H,onBack:hn,onBrowseTree:()=>mn(`workspaces`,`detail`,e||d.id),onBrowseWorkspaces:()=>pn(`workspaces`),onNavigatePath:t=>o(Be(e,t,U)),accentColor:Me(d.color)}),ut&&(0,N.jsx)(`div`,{className:`shrink-0 px-2 pt-2`,children:(0,N.jsx)(Ge,{title:`New canvas`,onClose:()=>ft(null),children:(0,N.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ni()},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:pt,onChange:e=>mt(e.target.value),onKeyDown:e=>{e.key===`Escape`&&ft(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:ut.parentPath===`/`?`/`:ut.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:ut.captureView,onChange:e=>ft({...ut,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)(ee,{type:`submit`,disabled:!pt.trim()||ht,children:ht?`Creating…`:`Create canvas`}),(0,N.jsx)(ee,{type:`button`,variant:`outline`,onClick:()=>ft(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:g(`flex-1 min-w-0 bg-background overflow-hidden`,J&&(ln===`left`?`ring-2 ring-primary`:`ring-1 ring-primary/20`)),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||un(`left`)},children:ui}),J&&e&&(0,N.jsx)(Pt,{workspaceName:e,workspaceLabel:d.label||d.name,workspaceIcon:d.icon,pane:J,isFocused:ln===`right`,clipboard:st,setClipboard:ct,onFocus:()=>un(`right`),onSelectionChange:_n,onNavigate:e=>sn(t=>t&&{...t,path:e,viewId:void 0}),onClose:()=>{sn(null),un(`left`),_n([])}})]})]})}function Nt(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 Pt({workspaceName:e,workspaceLabel:t,workspaceIcon:n,pane:r,isFocused:i=!1,clipboard:a,setClipboard:o,onFocus:s,onSelectionChange:c,onNavigate:l,onClose:u}){let{openM1Drawer:d,openM2Drawer:f}=Ve(),{showToast:p,showProgress:m}=ne(),[h,ee]=(0,M.useState)(null),[_,te]=(0,M.useState)([]),[v,y]=(0,M.useState)(!1),[re,b]=(0,M.useState)(0),[x,ie]=(0,M.useState)(1),[w,se]=(0,M.useState)(50),T=E(r.treeName),ce=Nt(h,r.path),le=ce?.type===`canvas`,D=(0,M.useMemo)(()=>et(h,r.path),[h,r.path]),O=r.viewId?$e(ce?.metadata).find(e=>e.id===r.viewId)??null:null,fe=`${e}://${r.path===`/`?``:r.path.replace(/^\//,``)}`,pe=Ze(O),me=(0,M.useCallback)(async()=>{if(we(r.treeName,r.path)){te([]),b(0),y(!1);return}let t=kt(e,r.treeName,r.path,x,w,``,pe??``),n=Ot.get(t);if(n){te(n.documents),b(n.totalCount);return}y(!0);try{let n=await de(e,r.path,pe?[pe]:[],{limit:w,page:x,treeName:r.treeName,treeType:T}),i=n.payload||[],a=n.totalCount||n.count||0;te(i),b(a),Ot.set(t,{documents:i,totalCount:a})}catch(e){p({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch side pane documents`,variant:`destructive`}),te([]),b(0)}finally{y(!1)}},[e,r.path,r.treeName,T,w,x,p,pe]);(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,ee(e))}).catch(()=>{!t&&o===n&&!i&&ee(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)(()=>{me()},[me]),(0,M.useEffect)(()=>{let t=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||(jt(e,n),xt(bt(n),{tree:r.treeName,kind:E(r.treeName),path:r.path})&&(R(e,r.treeName,r.path),me()))};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[me,e,r.treeName,r.path]);let he=(0,M.useCallback)(async(t,n,i={})=>{let s=i.targetTreeName??r.treeName,c=i.targetTreeType??T,l=i.move??a?.operation===`cut`,u=m({title:l?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let r=await ae(e,t,n,s,c);if(r){R(e,s,t);let r=i.sourcePath||a?.sourcePath,c=i.sourceTreeName||a?.sourceTreeName;if((i.move??a?.operation===`cut`)&&r&&c){let t=E(c);await C(e,n,r,[],c,t),R(e,c,r),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:r,treeName:c}}))}u.done({title:`Success`,description:`${n.length} document(s) ${l?`moved`:`pasted`} to "${t}"`}),o(null),await me(),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e,path:t,treeName:s}}))}else u.done();return r}catch(e){return u.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},[e,r.treeName,T,me,m,a,o]),_e=(0,M.useCallback)(()=>{R(e,r.treeName,r.path),me()},[e,r.treeName,r.path,me]),ve=(0,M.useCallback)(async t=>{let n=m({title:`Removing…`,description:`${t.length} document(s) from "${r.path}"`});try{await C(e,t,r.path,[],r.treeName,T),_e(),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,T,_e,m]),ye=(0,M.useCallback)(async t=>{let n=m({title:`Deleting…`,description:`${t.length} document(s)`});try{await ge(e,t,r.path,[],r.treeName,T),_e(),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,T,_e,m]),be=(0,M.useCallback)(async t=>{let n=m({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await S(e,t);if(r.failed?.length&&!r.successful?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}_e();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,_e,m]);return(0,N.jsxs)(`div`,{className:g(`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`)||s()},children:[u&&(0,N.jsx)(`button`,{type:`button`,onClick:u,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`}),we(r.treeName,r.path)?r.path===`/Trash`?(0,N.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,N.jsx)(nt,{workspaceName:e})}):(0,N.jsx)(lt,{workspace:e,path:r.path,onNavigate:l||(()=>{})}):(0,N.jsx)(qe,{frameContent:!1,onBrowseWorkspaces:()=>d(`workspaces`),onBrowseTree:()=>f(`workspaces`,`detail`,e),urlType:le?`canvas`:T===`directory`?r.treeName:`context`,urlDisplay:fe,contextPath:r.path,treeName:r.treeName,workspaceId:e,workspaceLabel:t,workspaceIcon:n,documentSchema:pe,documents:_,isLoading:v,totalCount:re,currentPage:x,pageSize:w,onPageChange:ie,onPageSizeChange:e=>{se(e),ie(1)},onRemoveDocument:r.path===`/`?void 0:e=>ve([e]),onRemoveDocuments:r.path===`/`?void 0:ve,onDeleteDocument:e=>ye([e]),onDeleteDocuments:ye,onDestroyDocument:e=>be([e]),onDestroyDocuments:be,onCopyDocuments:e=>{o({documentIds:e,operation:`copy`,sourcePath:r.path,sourceTreeName:r.treeName}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`copy`}}))},onCutDocuments:e=>{o({documentIds:e,operation:`cut`,sourcePath:r.path,sourceTreeName:r.treeName}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}}))},onPasteDocuments:r.treeName===`backends`?void 0:he,onSelectionChange:c,pastedDocumentIds:a?.documentIds,linkTree:h,folders:D,onOpenFolder:l,onNavigatePath:l,canvasInfo:le?{label:ce?.label,description:ce?.description,color:ce?.color}:void 0,children:O?.kind===`columns`?(0,N.jsx)(Qe,{documents:_,workspaceId:e,columns:O.columns??[],onColumnsChange:()=>{},readOnly:!0}):O?.kind===`app`&&O.app&&O.app!==`notes`?(0,N.jsx)(Xe,{app:O.app,workspaceId:e,treeName:r.treeName,path:r.path}):null})]})}export{Mt 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-DrDt1sQ2.js";import{t as a}from"./use-settings-back-DGmLAD63.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.
|
|
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-DrDt1sQ2.js";import{t as a}from"./use-settings-back-DGmLAD63.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.44`}),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-
|
|
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-B17r3232.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{I as i,It as a,Pt as o,Qr as s,Sr as c,rn as l,rt as u}from"./ui-CDoK3F3U.js";import{t as d}from"./button-SeUZ_Pvi.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{R as h,Y as g,kt as _,nt as v,tt as y}from"./index-DDoPhET6.js";import{n as b}from"./page-header-DrDt1sQ2.js";import{n as ee,r as x,t as te}from"./useAgentModels-Dw0ibJnv.js";import{t as ne}from"./form-panel-3p-ncEVK.js";import{t as re}from"./use-create-panel-DhSNIGtr.js";import{n as ie,t as ae}from"./useSocketSubscription-ifW-vnlb.js";var S=e(n(),1),C=t();function w({agent:e,onStart:t,onStop:n,onEnter:r}){let[o,f]=(0,S.useState)(!1),p=async()=>{f(!0);try{await t(e.name)}finally{f(!1)}},m=async()=>{f(!0);try{await n(e.name)}finally{f(!1)}},h=()=>{switch(e.status){case`active`:return(0,C.jsx)(c,{className:`h-4 w-4 text-success`});case`inactive`:return(0,C.jsx)(c,{className:`h-4 w-4 text-warning`});case`error`:return(0,C.jsx)(c,{className:`h-4 w-4 text-destructive`});default:return(0,C.jsx)(c,{className:`h-4 w-4 text-muted-foreground`})}},g=()=>{switch(e.llmProvider){case`anthropic`:return(0,C.jsx)(s,{className:`h-4 w-4 text-warning`});case`openai`:return(0,C.jsx)(s,{className:`h-4 w-4 text-success`});case`ollama`:return(0,C.jsx)(i,{className:`h-4 w-4 text-info`});default:return(0,C.jsx)(s,{className:`h-4 w-4 text-muted-foreground`})}},_=()=>{switch(e.status){case`active`:return`text-success bg-success-subtle border-success`;case`inactive`:return`text-warning bg-warning-subtle border-warning`;case`error`:return`text-destructive bg-destructive-subtle border-destructive`;case`available`:return`text-info bg-info-subtle border-info`;default:return`text-foreground bg-muted border-border`}},v=e.status===`available`||e.status===`inactive`,y=e.status===`active`;return(0,C.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 hover:shadow-elevation-2 transition-shadow bg-card`,children:[(0,C.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[g(),(0,C.jsx)(`h3`,{className:`text-lg font-semibold truncate`,children:e.label||e.name}),e.color&&(0,C.jsx)(`div`,{className:`w-4 h-4 rounded border flex-shrink-0`,style:{backgroundColor:e.color},title:`Color: ${e.color}`})]}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground font-mono`,children:e.name}),e.description&&(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:e.description})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[h(),(0,C.jsx)(`span`,{className:`px-2 py-1 rounded-full text-xs font-medium border ${_()}`,children:e.status})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 text-sm`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider:`}),(0,C.jsx)(`div`,{className:`font-medium capitalize`,children:e.llmProvider})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Model:`}),(0,C.jsx)(`div`,{className:`font-mono text-xs`,children:e.model})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Created:`}),(0,C.jsx)(`div`,{children:new Date(e.createdAt).toLocaleDateString()})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Last Access:`}),(0,C.jsx)(`div`,{children:e.lastAccessed?new Date(e.lastAccessed).toLocaleDateString():`Never`})]})]}),e.config.mcp?.servers&&e.config.mcp.servers.length>0&&(0,C.jsxs)(`div`,{className:`text-sm`,children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`MCP Servers:`}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.config.mcp.servers.map((e,t)=>(0,C.jsx)(`span`,{className:`px-2 py-1 bg-secondary text-secondary-foreground rounded text-xs`,children:e.name},t))})]}),(0,C.jsxs)(`div`,{className:`flex gap-2 pt-2 border-t`,children:[v&&(0,C.jsxs)(d,{onClick:p,disabled:o,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(a,{className:`mr-2 h-4 w-4`}),`Start`]}),y&&(0,C.jsxs)(d,{onClick:m,disabled:o,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(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,s]=(0,S.useState)(!0),[c,l]=(0,S.useState)(null),[u,T]=(0,S.useState)(``),[E,D]=(0,S.useState)(``),[O,k]=(0,S.useState)(m()),[A,j]=(0,S.useState)(``),[M,oe]=(0,S.useState)(`anthropic`),[N,P]=(0,S.useState)(t.anthropic),[F,I]=(0,S.useState)({apiKey:``,baseUrl:e.anthropic,maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),L=te(M,F.apiKey,F.baseUrl),R=L.models.find(e=>e.id===N),[z,B]=(0,S.useState)(``),[V,H]=(0,S.useState)(``),[U,W]=(0,S.useState)(``),[G,K]=(0,S.useState)(``),[q,J]=(0,S.useState)(!1),Y=_(),[X,Z]=re(),{showToast:Q}=p(),se=r(),$=ie();ae($,`agent`,{"agent:status:changed":e=>{i(t=>t.map(t=>t.id===e.agentId?{...t,status:e.status,isActive:e.isActive}:t))},"agent:created":e=>{i(t=>[...t,e.agent])},"agent:deleted":e=>{i(t=>t.filter(t=>t.id!==e.agentId))}});let ce=n=>{oe(n),P(t[n]),I({apiKey:``,baseUrl:e[n],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096})};(0,S.useEffect)(()=>((async()=>{try{s(!0);let e=await g();i(e),l(null)}catch(e){console.error(`Agent fetch error:`,e);let t=`Failed to fetch agents`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to fetch agents`}l(t),Q({title:`Error`,description:t,variant:`destructive`})}finally{s(!1)}})(),()=>{}),[$,Q]);let le=async t=>{if(t.preventDefault(),u.trim()){J(!0);try{let t=G.trim()||x(z,V,U),n={name:u,label:A||u,description:E||void 0,color:O,llmProvider:M,model:N,apiKey:F.apiKey.trim()||void 0,baseUrl:F.baseUrl.trim()||void 0,config:{type:M,model:N,identity:{role:z.trim()||void 0,identity:V.trim()||void 0,instructions:U.trim()||void 0},prompts:t?{system:t}:void 0,connectors:{[M]:{maxTokens:F.maxTokens,...M===`anthropic`?{}:{temperature:F.temperature},topP:F.topP,frequencyPenalty:F.frequencyPenalty,presencePenalty:F.presencePenalty,...M===`ollama`?{numCtx:F.numCtx}:{}}}},mcp:{enabled:!0,servers:[{name:`weather`,command:`node`,args:[`src/managers/agent/mcp-servers/weather.js`]}]}},r=await h(n);i(e=>[...e,r]),T(``),D(``),k(m()),j(``),K(``),B(``),H(``),W(``),I({apiKey:``,baseUrl:e[M],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),Q({title:`Success`,description:`Agent '${r.label||r.name}' created.`}),Z(!1)}catch(e){console.error(`Agent creation error:`,e);let t=`Failed to create agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to create agent`}Q({title:`Error`,description:t,variant:`destructive`})}finally{J(!1)}}},ue=async e=>{try{let t=await y(e);i(e=>e.map(e=>e.name===t.name?t:e)),Q({title:`Success`,description:`Agent '${t.label||t.name}' started.`})}catch(e){console.error(`Agent start error:`,e);let t=`Failed to start agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to start agent`}Q({title:`Error`,description:t,variant:`destructive`})}},de=async e=>{try{await v(e),i(t=>t.map(t=>t.name===e?{...t,status:`inactive`,isActive:!1}:t)),Q({title:`Success`,description:`Agent '${e}' stopped.`})}catch(e){console.error(`Agent stop error:`,e);let t=`Failed to stop agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to stop agent`}Q({title:`Error`,description:t,variant:`destructive`})}},fe=e=>{se(`/agents/${e}`)};return(0,C.jsxs)(`div`,{className:`space-y-6`,children:[(0,C.jsx)(b,{title:`AI Agents`,description:`Create and manage your AI agents with multiple LLM providers`,actions:!Y.local&&!X&&(0,C.jsxs)(d,{onClick:()=>Z(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create agent`,title:`Create agent`,children:[(0,C.jsx)(o,{className:`h-4 w-4 sm:mr-2`}),(0,C.jsx)(`span`,{className:`max-sm:hidden`,children:`Create Agent`})]})}),!Y.local&&X&&(0,C.jsx)(ne,{title:`Create New Agent`,onClose:()=>Z(!1),children:(0,C.jsxs)(`form`,{onSubmit:le,className:`space-y-4`,children:[(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsx)(f,{value:u,onChange:e=>T(e.target.value),placeholder:`Agent Name (e.g., 'my-assistant')`,disabled:q}),(0,C.jsx)(f,{value:A,onChange:e=>j(e.target.value),placeholder:`Agent Label (display name, optional)`,disabled:q})]}),(0,C.jsx)(f,{value:E,onChange:e=>D(e.target.value),placeholder:`Description (optional)`,disabled:q}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-provider`,className:`text-sm font-medium`,children:`LLM Provider`}),(0,C.jsxs)(`select`,{id:`agent-provider`,value:M,onChange:e=>ce(e.target.value),className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring`,disabled:q,children:[(0,C.jsx)(`option`,{value:`anthropic`,children:`Anthropic Claude`}),(0,C.jsx)(`option`,{value:`openai`,children:`OpenAI GPT`}),(0,C.jsx)(`option`,{value:`ollama`,children:`Ollama (Local)`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-model`,className:`text-sm font-medium`,children:`Model`}),(0,C.jsx)(ee,{id:`agent-model`,value:N,onChange:(e,t)=>{P(e),t?.maxTokens&&I(e=>({...e,maxTokens:t.maxTokens}))},...L,disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`Persona`}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-role`,className:`text-sm font-medium`,children:`Role`}),(0,C.jsx)(f,{id:`agent-role`,value:z,onChange:e=>B(e.target.value),placeholder:`e.g. Software Engineer`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-identity`,className:`text-sm font-medium`,children:`Identity`}),(0,C.jsx)(`textarea`,{id:`agent-identity`,value:V,onChange:e=>H(e.target.value),placeholder:`Who this agent is…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-instructions`,className:`text-sm font-medium`,children:`Instructions`}),(0,C.jsx)(`textarea`,{id:`agent-instructions`,value:U,onChange:e=>W(e.target.value),placeholder:`Behavioral instructions…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`system-prompt`,className:`text-sm font-medium`,children:`System Prompt (Optional Override)`}),(0,C.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Built from Role, Identity and Instructions unless you enter an override.`}),(0,C.jsx)(`textarea`,{id:`system-prompt`,value:G,onChange:e=>K(e.target.value),placeholder:x(z,V,U)||`System prompt sent to the LLM…`,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring min-h-[80px] resize-y`,disabled:q})]}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`api-key`,className:`text-sm font-medium`,children:`API Key (Optional)`}),(0,C.jsx)(f,{id:`api-key`,type:`password`,value:F.apiKey,onChange:e=>I(t=>({...t,apiKey:e.target.value})),placeholder:`Enter your API key`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`baseUrl`,className:`text-sm font-medium`,children:`Base URL (Optional)`}),(0,C.jsx)(f,{id:`baseUrl`,value:F.baseUrl,onChange:e=>I(t=>({...t,baseUrl:e.target.value})),placeholder:e[M],disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`LLM Parameters`}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`max-tokens`,className:`text-sm font-medium`,children:`Max Output Tokens`}),(0,C.jsx)(f,{id:`max-tokens`,type:`number`,min:`1`,max:R?.maxTokens,value:F.maxTokens,onChange:e=>I(t=>({...t,maxTokens:parseInt(e.target.value)||4096})),disabled:q})]}),M!==`anthropic`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`temperature`,className:`text-sm font-medium`,children:`Temperature`}),(0,C.jsx)(f,{id:`temperature`,type:`number`,min:`0`,max:`2`,step:`0.1`,value:F.temperature,onChange:e=>I(t=>({...t,temperature:Number.isNaN(e.target.valueAsNumber)?.7:e.target.valueAsNumber})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`top-p`,className:`text-sm font-medium`,children:`Top P`}),(0,C.jsx)(f,{id:`top-p`,type:`number`,min:`0`,max:`1`,step:`0.1`,value:F.topP,onChange:e=>I(t=>({...t,topP:Number.isNaN(e.target.valueAsNumber)?1:e.target.valueAsNumber})),disabled:q})]}),M===`ollama`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`num-ctx`,className:`text-sm font-medium`,children:`Context Length`}),(0,C.jsx)(f,{id:`num-ctx`,type:`number`,min:`1024`,max:R?.contextWindow,value:F.numCtx,onChange:e=>I(t=>({...t,numCtx:parseInt(e.target.value)||4096})),disabled:q})]})]}),M!==`ollama`&&(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`frequency-penalty`,className:`text-sm font-medium`,children:`Frequency Penalty`}),(0,C.jsx)(f,{id:`frequency-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.frequencyPenalty,onChange:e=>I(t=>({...t,frequencyPenalty:parseFloat(e.target.value)||0})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`presence-penalty`,className:`text-sm font-medium`,children:`Presence Penalty`}),(0,C.jsx)(f,{id:`presence-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.presencePenalty,onChange:e=>I(t=>({...t,presencePenalty:parseFloat(e.target.value)||0})),disabled:q})]})]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`label`,{htmlFor:`agent-color`,className:`text-sm font-medium`,children:`Agent Color`}),(0,C.jsx)(f,{id:`agent-color`,type:`color`,value:O,onChange:e=>k(e.target.value),className:`h-10 w-16 p-1`,disabled:q}),(0,C.jsx)(d,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>k(m()),disabled:q,children:`Randomize`})]}),(0,C.jsxs)(d,{type:`submit`,disabled:q||!u.trim(),children:[(0,C.jsx)(o,{className:`mr-2 h-4 w-4`}),`Create Agent`]})]})}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your Agents`}),a&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading agents...`}),c&&(0,C.jsx)(`div`,{className:`text-center text-destructive`,children:(0,C.jsx)(`p`,{children:c})}),!a&&!c&&n.length===0&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No agents found`}),n.length>0&&(0,C.jsx)(`div`,{className:`grid gap-4`,children:n.map(e=>(0,C.jsx)(w,{agent:e,onStart:ue,onStop:de,onEnter:fe},e.id))})]})]})}export{T as default};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{I as i,It as a,Pt as o,Qr as s,Sr as c,rn as l,rt as u}from"./ui-CDoK3F3U.js";import{t as d}from"./button-SeUZ_Pvi.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{R as h,Y as g,kt as _,nt as v,tt as y}from"./index-G_67YwLB.js";import{n as b}from"./page-header-DrDt1sQ2.js";import{n as ee,r as x,t as te}from"./useAgentModels-BufYelEA.js";import{t as ne}from"./form-panel-3p-ncEVK.js";import{t as re}from"./use-create-panel-DhSNIGtr.js";import{n as ie,t as ae}from"./useSocketSubscription-ifW-vnlb.js";var S=e(n(),1),C=t();function w({agent:e,onStart:t,onStop:n,onEnter:r}){let[o,f]=(0,S.useState)(!1),p=async()=>{f(!0);try{await t(e.name)}finally{f(!1)}},m=async()=>{f(!0);try{await n(e.name)}finally{f(!1)}},h=()=>{switch(e.status){case`active`:return(0,C.jsx)(c,{className:`h-4 w-4 text-success`});case`inactive`:return(0,C.jsx)(c,{className:`h-4 w-4 text-warning`});case`error`:return(0,C.jsx)(c,{className:`h-4 w-4 text-destructive`});default:return(0,C.jsx)(c,{className:`h-4 w-4 text-muted-foreground`})}},g=()=>{switch(e.llmProvider){case`anthropic`:return(0,C.jsx)(s,{className:`h-4 w-4 text-warning`});case`openai`:return(0,C.jsx)(s,{className:`h-4 w-4 text-success`});case`ollama`:return(0,C.jsx)(i,{className:`h-4 w-4 text-info`});default:return(0,C.jsx)(s,{className:`h-4 w-4 text-muted-foreground`})}},_=()=>{switch(e.status){case`active`:return`text-success bg-success-subtle border-success`;case`inactive`:return`text-warning bg-warning-subtle border-warning`;case`error`:return`text-destructive bg-destructive-subtle border-destructive`;case`available`:return`text-info bg-info-subtle border-info`;default:return`text-foreground bg-muted border-border`}},v=e.status===`available`||e.status===`inactive`,y=e.status===`active`;return(0,C.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 hover:shadow-elevation-2 transition-shadow bg-card`,children:[(0,C.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[g(),(0,C.jsx)(`h3`,{className:`text-lg font-semibold truncate`,children:e.label||e.name}),e.color&&(0,C.jsx)(`div`,{className:`w-4 h-4 rounded border flex-shrink-0`,style:{backgroundColor:e.color},title:`Color: ${e.color}`})]}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground font-mono`,children:e.name}),e.description&&(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:e.description})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[h(),(0,C.jsx)(`span`,{className:`px-2 py-1 rounded-full text-xs font-medium border ${_()}`,children:e.status})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 text-sm`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider:`}),(0,C.jsx)(`div`,{className:`font-medium capitalize`,children:e.llmProvider})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Model:`}),(0,C.jsx)(`div`,{className:`font-mono text-xs`,children:e.model})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Created:`}),(0,C.jsx)(`div`,{children:new Date(e.createdAt).toLocaleDateString()})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Last Access:`}),(0,C.jsx)(`div`,{children:e.lastAccessed?new Date(e.lastAccessed).toLocaleDateString():`Never`})]})]}),e.config.mcp?.servers&&e.config.mcp.servers.length>0&&(0,C.jsxs)(`div`,{className:`text-sm`,children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`MCP Servers:`}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.config.mcp.servers.map((e,t)=>(0,C.jsx)(`span`,{className:`px-2 py-1 bg-secondary text-secondary-foreground rounded text-xs`,children:e.name},t))})]}),(0,C.jsxs)(`div`,{className:`flex gap-2 pt-2 border-t`,children:[v&&(0,C.jsxs)(d,{onClick:p,disabled:o,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(a,{className:`mr-2 h-4 w-4`}),`Start`]}),y&&(0,C.jsxs)(d,{onClick:m,disabled:o,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(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,s]=(0,S.useState)(!0),[c,l]=(0,S.useState)(null),[u,T]=(0,S.useState)(``),[E,D]=(0,S.useState)(``),[O,k]=(0,S.useState)(m()),[A,j]=(0,S.useState)(``),[M,oe]=(0,S.useState)(`anthropic`),[N,P]=(0,S.useState)(t.anthropic),[F,I]=(0,S.useState)({apiKey:``,baseUrl:e.anthropic,maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),L=te(M,F.apiKey,F.baseUrl),R=L.models.find(e=>e.id===N),[z,B]=(0,S.useState)(``),[V,H]=(0,S.useState)(``),[U,W]=(0,S.useState)(``),[G,K]=(0,S.useState)(``),[q,J]=(0,S.useState)(!1),Y=_(),[X,Z]=re(),{showToast:Q}=p(),se=r(),$=ie();ae($,`agent`,{"agent:status:changed":e=>{i(t=>t.map(t=>t.id===e.agentId?{...t,status:e.status,isActive:e.isActive}:t))},"agent:created":e=>{i(t=>[...t,e.agent])},"agent:deleted":e=>{i(t=>t.filter(t=>t.id!==e.agentId))}});let ce=n=>{oe(n),P(t[n]),I({apiKey:``,baseUrl:e[n],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096})};(0,S.useEffect)(()=>((async()=>{try{s(!0);let e=await g();i(e),l(null)}catch(e){console.error(`Agent fetch error:`,e);let t=`Failed to fetch agents`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to fetch agents`}l(t),Q({title:`Error`,description:t,variant:`destructive`})}finally{s(!1)}})(),()=>{}),[$,Q]);let le=async t=>{if(t.preventDefault(),u.trim()){J(!0);try{let t=G.trim()||x(z,V,U),n={name:u,label:A||u,description:E||void 0,color:O,llmProvider:M,model:N,apiKey:F.apiKey.trim()||void 0,baseUrl:F.baseUrl.trim()||void 0,config:{type:M,model:N,identity:{role:z.trim()||void 0,identity:V.trim()||void 0,instructions:U.trim()||void 0},prompts:t?{system:t}:void 0,connectors:{[M]:{maxTokens:F.maxTokens,...M===`anthropic`?{}:{temperature:F.temperature},topP:F.topP,frequencyPenalty:F.frequencyPenalty,presencePenalty:F.presencePenalty,...M===`ollama`?{numCtx:F.numCtx}:{}}}},mcp:{enabled:!0,servers:[{name:`weather`,command:`node`,args:[`src/managers/agent/mcp-servers/weather.js`]}]}},r=await h(n);i(e=>[...e,r]),T(``),D(``),k(m()),j(``),K(``),B(``),H(``),W(``),I({apiKey:``,baseUrl:e[M],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),Q({title:`Success`,description:`Agent '${r.label||r.name}' created.`}),Z(!1)}catch(e){console.error(`Agent creation error:`,e);let t=`Failed to create agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to create agent`}Q({title:`Error`,description:t,variant:`destructive`})}finally{J(!1)}}},ue=async e=>{try{let t=await y(e);i(e=>e.map(e=>e.name===t.name?t:e)),Q({title:`Success`,description:`Agent '${t.label||t.name}' started.`})}catch(e){console.error(`Agent start error:`,e);let t=`Failed to start agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to start agent`}Q({title:`Error`,description:t,variant:`destructive`})}},de=async e=>{try{await v(e),i(t=>t.map(t=>t.name===e?{...t,status:`inactive`,isActive:!1}:t)),Q({title:`Success`,description:`Agent '${e}' stopped.`})}catch(e){console.error(`Agent stop error:`,e);let t=`Failed to stop agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to stop agent`}Q({title:`Error`,description:t,variant:`destructive`})}},fe=e=>{se(`/agents/${e}`)};return(0,C.jsxs)(`div`,{className:`space-y-6`,children:[(0,C.jsx)(b,{title:`AI Agents`,description:`Create and manage your AI agents with multiple LLM providers`,actions:!Y.local&&!X&&(0,C.jsxs)(d,{onClick:()=>Z(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create agent`,title:`Create agent`,children:[(0,C.jsx)(o,{className:`h-4 w-4 sm:mr-2`}),(0,C.jsx)(`span`,{className:`max-sm:hidden`,children:`Create Agent`})]})}),!Y.local&&X&&(0,C.jsx)(ne,{title:`Create New Agent`,onClose:()=>Z(!1),children:(0,C.jsxs)(`form`,{onSubmit:le,className:`space-y-4`,children:[(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsx)(f,{value:u,onChange:e=>T(e.target.value),placeholder:`Agent Name (e.g., 'my-assistant')`,disabled:q}),(0,C.jsx)(f,{value:A,onChange:e=>j(e.target.value),placeholder:`Agent Label (display name, optional)`,disabled:q})]}),(0,C.jsx)(f,{value:E,onChange:e=>D(e.target.value),placeholder:`Description (optional)`,disabled:q}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-provider`,className:`text-sm font-medium`,children:`LLM Provider`}),(0,C.jsxs)(`select`,{id:`agent-provider`,value:M,onChange:e=>ce(e.target.value),className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring`,disabled:q,children:[(0,C.jsx)(`option`,{value:`anthropic`,children:`Anthropic Claude`}),(0,C.jsx)(`option`,{value:`openai`,children:`OpenAI GPT`}),(0,C.jsx)(`option`,{value:`ollama`,children:`Ollama (Local)`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-model`,className:`text-sm font-medium`,children:`Model`}),(0,C.jsx)(ee,{id:`agent-model`,value:N,onChange:(e,t)=>{P(e),t?.maxTokens&&I(e=>({...e,maxTokens:t.maxTokens}))},...L,disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`Persona`}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-role`,className:`text-sm font-medium`,children:`Role`}),(0,C.jsx)(f,{id:`agent-role`,value:z,onChange:e=>B(e.target.value),placeholder:`e.g. Software Engineer`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-identity`,className:`text-sm font-medium`,children:`Identity`}),(0,C.jsx)(`textarea`,{id:`agent-identity`,value:V,onChange:e=>H(e.target.value),placeholder:`Who this agent is…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-instructions`,className:`text-sm font-medium`,children:`Instructions`}),(0,C.jsx)(`textarea`,{id:`agent-instructions`,value:U,onChange:e=>W(e.target.value),placeholder:`Behavioral instructions…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`system-prompt`,className:`text-sm font-medium`,children:`System Prompt (Optional Override)`}),(0,C.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Built from Role, Identity and Instructions unless you enter an override.`}),(0,C.jsx)(`textarea`,{id:`system-prompt`,value:G,onChange:e=>K(e.target.value),placeholder:x(z,V,U)||`System prompt sent to the LLM…`,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring min-h-[80px] resize-y`,disabled:q})]}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`api-key`,className:`text-sm font-medium`,children:`API Key (Optional)`}),(0,C.jsx)(f,{id:`api-key`,type:`password`,value:F.apiKey,onChange:e=>I(t=>({...t,apiKey:e.target.value})),placeholder:`Enter your API key`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`baseUrl`,className:`text-sm font-medium`,children:`Base URL (Optional)`}),(0,C.jsx)(f,{id:`baseUrl`,value:F.baseUrl,onChange:e=>I(t=>({...t,baseUrl:e.target.value})),placeholder:e[M],disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`LLM Parameters`}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`max-tokens`,className:`text-sm font-medium`,children:`Max Output Tokens`}),(0,C.jsx)(f,{id:`max-tokens`,type:`number`,min:`1`,max:R?.maxTokens,value:F.maxTokens,onChange:e=>I(t=>({...t,maxTokens:parseInt(e.target.value)||4096})),disabled:q})]}),M!==`anthropic`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`temperature`,className:`text-sm font-medium`,children:`Temperature`}),(0,C.jsx)(f,{id:`temperature`,type:`number`,min:`0`,max:`2`,step:`0.1`,value:F.temperature,onChange:e=>I(t=>({...t,temperature:Number.isNaN(e.target.valueAsNumber)?.7:e.target.valueAsNumber})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`top-p`,className:`text-sm font-medium`,children:`Top P`}),(0,C.jsx)(f,{id:`top-p`,type:`number`,min:`0`,max:`1`,step:`0.1`,value:F.topP,onChange:e=>I(t=>({...t,topP:Number.isNaN(e.target.valueAsNumber)?1:e.target.valueAsNumber})),disabled:q})]}),M===`ollama`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`num-ctx`,className:`text-sm font-medium`,children:`Context Length`}),(0,C.jsx)(f,{id:`num-ctx`,type:`number`,min:`1024`,max:R?.contextWindow,value:F.numCtx,onChange:e=>I(t=>({...t,numCtx:parseInt(e.target.value)||4096})),disabled:q})]})]}),M!==`ollama`&&(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`frequency-penalty`,className:`text-sm font-medium`,children:`Frequency Penalty`}),(0,C.jsx)(f,{id:`frequency-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.frequencyPenalty,onChange:e=>I(t=>({...t,frequencyPenalty:parseFloat(e.target.value)||0})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`presence-penalty`,className:`text-sm font-medium`,children:`Presence Penalty`}),(0,C.jsx)(f,{id:`presence-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.presencePenalty,onChange:e=>I(t=>({...t,presencePenalty:parseFloat(e.target.value)||0})),disabled:q})]})]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`label`,{htmlFor:`agent-color`,className:`text-sm font-medium`,children:`Agent Color`}),(0,C.jsx)(f,{id:`agent-color`,type:`color`,value:O,onChange:e=>k(e.target.value),className:`h-10 w-16 p-1`,disabled:q}),(0,C.jsx)(d,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>k(m()),disabled:q,children:`Randomize`})]}),(0,C.jsxs)(d,{type:`submit`,disabled:q||!u.trim(),children:[(0,C.jsx)(o,{className:`mr-2 h-4 w-4`}),`Create Agent`]})]})}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your Agents`}),a&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading agents...`}),c&&(0,C.jsx)(`div`,{className:`text-center text-destructive`,children:(0,C.jsx)(`p`,{children:c})}),!a&&!c&&n.length===0&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No agents found`}),n.length>0&&(0,C.jsx)(`div`,{className:`grid gap-4`,children:n.map(e=>(0,C.jsx)(w,{agent:e,onStart:ue,onStop:de,onEnter:fe},e.id))})]})]})}export{T as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Wr as r,Xt as i,Yt as a,et as o}from"./ui-CDoK3F3U.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-DIP1zh7I.js";import{t as x}from"./use-theme-DaxpiICf.js";import{Ct as S,St as C,a as w,c as T,d as E,f as D,i as O,l as k,m as A,n as j,o as M,p as N,r as P,s as F,t as I,u as L,xt as R}from"./index-DDoPhET6.js";import{n as z}from"./page-header-DrDt1sQ2.js";import{t as B}from"./use-settings-back-DGmLAD63.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:w,reset:T}=x(),E=l(),O=u(),k=h(),j=p(),M=S(),P=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:A.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:N.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:D.map(e=>({id:e.id,label:e.name,title:e.description})),value:n,onChange:w}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:D.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:k,onChange:_}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:y.find(e=>e.id===k)?.description}),k===`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:P,onChange:b}),(0,H.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[v.find(e=>e.id===P)?.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:R.map(e=>({id:e.id,label:e.name,title:e.description})),value:M,onChange:C}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:R.find(e=>e.id===M)?.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:O,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:E?`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:j,onChange:d})]}),(0,H.jsx)(G,{}),(0,H.jsx)(`section`,{children:(0,H.jsx)(`button`,{type:`button`,onClick:()=>{T(),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)(M),[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 T().then(()=>{e||(t(M()),a(!1))}),()=>{e=!0}},[]);let l=async(e,n)=>{if(!c.current){c.current=!0,s(!0);try{let i=n?{...e,image:await F(n)}:e;await k(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&&P(e.image)===null,f=L(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`})}),I.map(t=>(0,H.jsx)(q,{label:t.title,title:`${t.title} — suits the ${t.scheme} scheme`,isActive:P(e.image)===t.id,onSelect:()=>l({...e,image:O(t.id)}),children:(0,H.jsx)(`img`,{src:w(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:E(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:j.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=I.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{Wr as r,Xt as i,Yt as a,et as o}from"./ui-CDoK3F3U.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-DIP1zh7I.js";import{t as x}from"./use-theme-DaxpiICf.js";import{Ct as S,St as C,a as w,c as T,d as E,f as D,i as O,l as k,m as A,n as j,o as M,p as N,r as P,s as F,t as I,u as L,xt as R}from"./index-G_67YwLB.js";import{n as z}from"./page-header-DrDt1sQ2.js";import{t as B}from"./use-settings-back-DGmLAD63.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:w,reset:T}=x(),E=l(),O=u(),k=h(),j=p(),M=S(),P=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:A.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:N.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:D.map(e=>({id:e.id,label:e.name,title:e.description})),value:n,onChange:w}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:D.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:k,onChange:_}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:y.find(e=>e.id===k)?.description}),k===`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:P,onChange:b}),(0,H.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[v.find(e=>e.id===P)?.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:R.map(e=>({id:e.id,label:e.name,title:e.description})),value:M,onChange:C}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:R.find(e=>e.id===M)?.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:O,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:E?`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:j,onChange:d})]}),(0,H.jsx)(G,{}),(0,H.jsx)(`section`,{children:(0,H.jsx)(`button`,{type:`button`,onClick:()=>{T(),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)(M),[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 T().then(()=>{e||(t(M()),a(!1))}),()=>{e=!0}},[]);let l=async(e,n)=>{if(!c.current){c.current=!0,s(!0);try{let i=n?{...e,image:await F(n)}:e;await k(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&&P(e.image)===null,f=L(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`})}),I.map(t=>(0,H.jsx)(q,{label:t.title,title:`${t.title} — suits the ${t.scheme} scheme`,isActive:P(e.image)===t.id,onSelect:()=>l({...e,image:O(t.id)}),children:(0,H.jsx)(`img`,{src:w(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:E(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:j.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=I.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{bn as s,jt as c}from"./workspace-C5V-ZCOE.js";import{p as l}from"./context-t3rdtGUB.js";import{t as u}from"./registry-
|
|
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{bn as s,jt as c}from"./workspace-C5V-ZCOE.js";import{p as l}from"./context-t3rdtGUB.js";import{t as u}from"./registry-FfNYUpRF.js";import{t as d}from"./applet-target-pLdP-R76.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:s(y)},[g,_,v,y]),[S,C]=(0,f.useState)([]),[w,T]=(0,f.useState)([]);(0,f.useEffect)(()=>{c().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};
|