@augmentd-labs/canvas-web 2.26.30 → 2.26.32
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-B-KQB9MF.js → CalendarApplet-BmOR4qFp.js} +1 -1
- package/dist/assets/{FiltersApplet-BQ-yLETb.js → FiltersApplet-CxaZpQCu.js} +1 -1
- package/dist/assets/{HomeFab-xOFNqlcV.js → HomeFab-BKt1jyXP.js} +1 -1
- package/dist/assets/{LensApplet-DNR6LHP1.js → LensApplet-D18yjgEC.js} +1 -1
- package/dist/assets/{NotesApplet-DyJobkzg.js → NotesApplet-PK8NaSfy.js} +1 -1
- package/dist/assets/{_agentId_-28SRDtL_.js → _agentId_-Co0qndp4.js} +0 -0
- package/dist/assets/{_contextId_-DmyCWpLx.js → _contextId_-R8NzfxSb.js} +1 -1
- package/dist/assets/{_workspaceName_-BVxMj4S4.js → _workspaceName_-Co91ZwjE.js} +1 -1
- package/dist/assets/{about-BSl71l_q.js → about-DGjWrNhr.js} +1 -1
- package/dist/assets/{add-fc-96N3K.js → add-CraODNer.js} +1 -1
- package/dist/assets/{agents-Dp0UlFhw.js → agents-w_4C2O93.js} +1 -1
- package/dist/assets/{appearance-MxLwJvKV.js → appearance-rWcSoEbj.js} +1 -1
- package/dist/assets/{apps-W1ZPkVTB.js → apps-DxIKgVBT.js} +1 -1
- package/dist/assets/backend-sync-progress-BJsLP7o5.js +7 -0
- package/dist/assets/{content-app-view-Cvqs06e8.js → content-app-view-DEW8XLJr.js} +1 -1
- package/dist/assets/{document-list-Cq4rdquK.js → document-list-CwStaizB.js} +1 -1
- package/dist/assets/{home-B5H1Bpql.js → home-CH2mPW1Z.js} +1 -1
- package/dist/assets/{index-Pdg5xeG3.js → index-DUPka8LP.js} +3 -3
- package/dist/assets/{key-bindings-CtvDqQLt.js → key-bindings-DF0r265F.js} +1 -1
- package/dist/assets/{query-debug-B3pFyO8g.js → query-debug-CZacGe0M.js} +1 -1
- package/dist/assets/{registry-DxI6UTog.js → registry-Cmoo1ljZ.js} +2 -2
- package/dist/assets/{settings-CC0TLN6V.js → settings-C4gpHQZ-.js} +1 -1
- package/dist/assets/{settings-CRzyZEHb.js → settings-D5y8cErW.js} +1 -1
- package/dist/assets/{settings-DihHqno3.js → settings-DCnrUPkq.js} +1 -1
- package/dist/assets/{settings-CG6tAbxu.js → settings-PhhiDgan.js} +6 -6
- package/dist/assets/{share-target-virrjHzV.js → share-target--IxMeQYG.js} +1 -1
- package/dist/assets/{shared-Db_2ZVQH.js → shared-EVRqnmm1.js} +1 -1
- package/dist/assets/{use-canvas-pins-BZMaPpb7.js → use-canvas-pins-D-zi5fqQ.js} +1 -1
- package/dist/assets/{useAgentModels-DPu0MHiH.js → useAgentModels-C2cV4Gw5.js} +1 -1
- package/dist/assets/{workspace-area-menu-COdiU0Xn.js → workspace-area-menu-DtsodEXC.js} +1 -1
- package/dist/assets/{workspaces-CNtUJTgB.js → workspaces-BnjERDmT.js} +1 -1
- package/dist/index.html +6 -6
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/dist/assets/backend-sync-progress-DyvV8N9D.js +0 -7
|
@@ -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{L as o,Ur as s,Vr as c,pn as l}from"./ui-76Hw0NU_.js";import{t as u}from"./utils-2pl1SbIp.js";import{t as d}from"./button-Bum-POPT.js";import{c as f,t as p}from"./api-CA6WiiYM.js";import{t as m}from"./socket-CtH3EU9m.js";import{n as h}from"./use-toast-BlLDqSUO.js";import{Cn as g,D as ee,G as te,Jt as _,K as v,Mt as ne,Vt as y,X as re,_ as ie,_t as b,a as ae,bn as oe,ht as se,it as ce,on as le,qt as ue,rt as de,u as fe,ut as pe,w as me,x,y as he,yt as ge,zt as _e}from"./workspace-46EFyEKZ.js";import{n as ve,r as ye}from"./use-canvas-pins-BZMaPpb7.js";import{u as be}from"./ObjectPropertiesCard-CFZ_LqzX.js";import{h as xe,i as S,r as Se}from"./document-list-Cq4rdquK.js";import{n as Ce}from"./use-toolbox-Ck_cLGgf.js";import{i as we}from"./color-DFEH4BfK.js";import{t as Te}from"./geo-CZfs0E-x.js";import{c as Ee}from"./backend-sync-progress-DyvV8N9D.js";import{a as De,i as Oe,n as ke,o as Ae}from"./workspace-BydSRtST.js";import{n as je,r as Me,t as Ne}from"./url-params-n7kU_WZ-.js";import{i as Pe}from"./use-menu-CaiLyPdw.js";import{n as Fe}from"./last-path-BbXWC3b3.js";import{t as Ie}from"./workspace-area-menu-COdiU0Xn.js";import{t as Le}from"./workspace-content-gate-CGZmT2kw.js";import{t as Re}from"./form-panel-DZj3WZ3z.js";import{a as ze,c as Be,i as Ve,l as He,n as Ue,o as We,r as Ge,s as Ke,t as qe}from"./content-app-view-Cvqs06e8.js";import{i as Je,o as Ye,r as Xe}from"./query-debug-B3pFyO8g.js";var C=`session.open`,Ze=`session.set`,Qe=`session.ids`,$e=`session.materialize`,et=`session.close`,w=`session.delta`,T=e(n(),1),E=t();function tt({workspaceId:e,workspaceName:t}){let[n,r]=(0,T.useState)([]),[i,a]=(0,T.useState)(new Set),s=t=>`${e}:${t.address}:${t.resyncStartedAt||``}`;(0,T.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 ge(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=m.on(`connect`,l);return m.on(`backend.resync.changed`,u),m.on(`backend.changed`,d),window.addEventListener(`focus`,l),()=>{t=!0,f?.(),m.off(`backend.resync.changed`,u),m.off(`backend.changed`,d),window.removeEventListener(`focus`,l)}},[e]);let c=n.filter(e=>!i.has(s(e)));return c.length?(0,E.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,E.jsxs)(`div`,{role:`status`,className:`mb-2 flex items-center gap-2 text-sm font-medium`,children:[(0,E.jsx)(l,{"aria-hidden":`true`,className:`h-4 w-4 animate-spin`}),(0,E.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,E.jsx)(`span`,{className:`block`,children:`Scanning storage`}),(0,E.jsx)(`span`,{className:`block truncate text-xs font-normal text-muted-foreground`,title:t,children:t})]}),(0,E.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(s)])),children:(0,E.jsx)(o,{"aria-hidden":`true`,className:`h-4 w-4`})})]}),(0,E.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,E.jsxs)(`div`,{children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,E.jsx)(`span`,{className:`truncate`,children:i}),(0,E.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:n===null?`${t} files`:`${t} / ${n}`})]}),(0,E.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,E.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 nt=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:null;function D(e){return`/${e}`.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`}function rt(e,t,n){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>rt(e,t,n));if(typeof e==`string`)return[{tree:null,kind:t,path:D(e)}];let r=nt(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:D(e)}))}function O(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 it(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 at(e,t,n=new Map){let r=nt(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:D(n)}],ids:O(r),unknown:!1}:{targets:[],ids:[],unknown:!0}}let i=[...rt(r.context,`context`,n),...rt(r.directory,`directory`,n)],a=nt(r.changed);a&&i.push(...rt(a.context,`context`,n),...rt(a.directory,`directory`,n));let o=O(r);if(i.length)return{targets:i,ids:o,unknown:!1};let s=r.reason===`content`||r.reason===`relations`;return e.startsWith(`document.updated`)&&s&&o.length?{targets:[],ids:o,unknown:!1}:{targets:[],ids:o,unknown:!0}}function k(e,t){return e===t||e===`/`||t===`/`||e.startsWith(`${t}/`)||t.startsWith(`${e}/`)}function ot(e,t){if(e.kind&&e.kind!==t.kind||e.tree&&e.tree!==t.tree)return!1;if(t.kind===`context`){let n=e=>D(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 k(e.path,t.path)}function st(e){return at(`tree.refresh`,{treeName:e?.treeName,path:e?.path||`/`})}function ct(e,t,n){if(e.unknown||e.targets.length&&(t.wholeWorkspace||e.targets.some(e=>ot(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 lt(e,t,n={}){return m.request(C,{workspace:e,specs:t,opts:n})}function ut(e,t,n){return m.request(Ze,{sessionId:e,label:t,spec:n})}function dt(e){return m.request(Qe,{sessionId:e})}function A(e,t={}){return m.request($e,{sessionId:e,...t})}function ft(e){return m.request(et,{sessionId:e})}function pt(e){return m.on(w,e)}var mt=100;function ht({workspaceRef:e,specs:t,opts:n,enabled:r=!0}){let[i,a]=(0,T.useState)([]),[o,s]=(0,T.useState)(0),[c,l]=(0,T.useState)(null),[u,d]=(0,T.useState)(null),f=(0,T.useRef)([]),p=(0,T.useRef)(new Map),h=(0,T.useRef)(null),g=(0,T.useRef)(null),ee=(0,T.useRef)(null),te=(0,T.useRef)({}),_=(0,T.useRef)(null),v=(0,T.useMemo)(()=>JSON.stringify(t),[t]),ne=(0,T.useMemo)(()=>JSON.stringify(n??{}),[n]),y=(0,T.useCallback)(()=>{let e=p.current;a(f.current.map(t=>e.get(t)).filter(Boolean))},[]),re=(0,T.useCallback)(async e=>{let t=g.current;if(!t||e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=mt){let i=e.slice(r,r+mt),a=await de(t,`/`,[],{ids:i,scope:`workspace`,limit:i.length});n.push(...a.payload||[])}return n},[]),ie=(0,T.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]),b=(0,T.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 ie(a,[],t)},[ie]);(0,T.useEffect)(()=>{if(g.current=e??null,!r||!e)return;let t=!1,n=null,i=async()=>{try{let r=await lt(e,JSON.parse(v),JSON.parse(ne));if(t){ft(r.sessionId).catch(()=>{});return}n=r.sessionId,h.current=r.sessionId,l(r.sessionId),d(null),f.current=[],p.current=new Map,await b(r.ids,r.count)}catch(e){if(t)return;d(e instanceof Error?e.message:`Failed to open query session`),l(null),h.current=null}};i();let o=m.on(`connect`,()=>{i()});return()=>{t=!0,o?.();let e=n??h.current;e&&ft(e).catch(()=>{}),h.current=null,f.current=[],p.current=new Map,l(null),a([]),s(0)}},[e,v,ne,r]),(0,T.useEffect)(()=>{if(!c)return;let e=pt(e=>{if(e.sessionId===c){if(ee.current!==null){_.current?.(ee.current,te.current);return}e.ids===void 0?ie(e.added??[],e.removed??[],e.count):b(e.ids,e.count)}});return()=>{e?.()}},[c,ie,b]);let ae=(0,T.useCallback)(async()=>{let e=h.current;if(e)try{let t=await dt(e);await b(t.ids,t.count)}catch{}},[b]),oe=(0,T.useCallback)(async(e,t)=>{let n=h.current;if(!n)throw Error(`No open query session`);let r=await ut(n,e,t);if(ee.current!==null){await _.current?.(ee.current,te.current);return}await b(r.ids,r.count)},[b]),se=(0,T.useCallback)(async(e,t={})=>{let n=h.current;if(!n)throw Error(`No open query session`);if(ee.current=e,te.current=t,e===null){await ae();return}let r=await A(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,ae]);(0,T.useEffect)(()=>{_.current=se},[se]);let ce=(0,T.useCallback)(async(e,t,n={})=>{let r=h.current;if(!r)throw Error(`No open query session`);let i=await A(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 ut(r,e,{ids:i.ids});return await b(a.ids,a.count),i.ids},[b]);return{documents:i,count:o,ready:c!==null,error:u,setCue:oe,resync:ae,rank:se,rankAndPin:ce}}function gt({data:e,className:t}){let[n,r]=(0,T.useState)(!0),{rows:i,gapIndex:a,span:o}=(0,T.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,E.jsxs)(`div`,{className:u(`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 l=a>0?i[a].distance:null;return(0,E.jsxs)(`div`,{className:u(`rounded-md border border-border bg-muted/30 text-xs`,t),children:[(0,E.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,E.jsx)(s,{className:`h-3.5 w-3.5`}):(0,E.jsx)(c,{className:`h-3.5 w-3.5`}),`Query debug`,(0,E.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`: image distances for “`,e.query,`” (`,i.length,` nearest, unfloored)`]})]}),n&&(0,E.jsxs)(`div`,{className:`space-y-2 border-t border-border px-3 py-2`,children:[(0,E.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.`,l===null?(0,E.jsxs)(E.Fragment,{children:[` `,(0,E.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,E.jsxs)(E.Fragment,{children:[` A jump at `,(0,E.jsx)(`span`,{className:`font-mono`,children:l.toFixed(4)}),` (Δ`,o.biggest.toFixed(4),`, vs typical Δ`,o.median.toFixed(4),`) stands out (a likely boundary).`]})]}),(0,E.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:(0,E.jsx)(`table`,{className:`w-full font-mono text-[11px]`,children:(0,E.jsx)(`tbody`,{children:i.map((e,t)=>(0,E.jsxs)(`tr`,{className:u(`border-b border-border/40 last:border-0`,t===a&&`border-t-2 border-t-amber-500/70`),children:[(0,E.jsx)(`td`,{className:`py-0.5 pr-3 text-muted-foreground`,children:t+1}),(0,E.jsxs)(`td`,{className:`py-0.5 pr-3`,children:[`#`,e.id]}),(0,E.jsx)(`td`,{className:`py-0.5 tabular-nums`,children:e.distance.toFixed(4)}),t===a&&(0,E.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,E.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.`]})]})]})}function _t(e,t){if(!e)return[];let n=t.split(`/`).filter(Boolean),r=e;for(let e of n)if(r=r?.children?.find(t=>t.name===e)??null,!r)return[];let i=n.length?`/${n.join(`/`)}`:``,a=(r.children??[]).filter(e=>e.type!==`canvas`).map(e=>({name:e.name,path:`${i}/${e.name}`,label:e.label,color:e.color,childCount:e.children?.length??0})).sort((e,t)=>(e.label||e.name).localeCompare(t.label||t.name,void 0,{numeric:!0,sensitivity:`base`}));return n.length>0&&a.unshift({name:`..`,path:n.length>1?`/${n.slice(0,-1).join(`/`)}`:`/`,isParent:!0}),a}var vt=new Map;function yt(e,t,n){return`${e}\0${t}\0${n}`}function bt(e,t,n,r,i,a,o=``,s=``,c=`path`){return`${yt(e,t,n)}\0${r}\0${i}\0${a}\0${o}\0${s}\0${c}`}function j(e,t,n){let r=yt(e,t,n);for(let e of vt.keys())e.startsWith(r)&&vt.delete(e)}function xt(e,t){let n=`${e}\0`;for(let[e,r]of vt){if(!e.startsWith(n))continue;let[,i,a,,,,,,o=`path`]=e.split(`\0`);ct(t,{tree:i,kind:g(i),path:a,wholeWorkspace:o.startsWith(`workspace`)},r.documents.map(e=>Number(e.id)))&&vt.delete(e)}}function St(e,t){xt(t?.workspaceName??e,st(t))}function Ct(){let{workspaceName:e}=r();return e?(0,E.jsx)(Le,{workspaceName:e,children:(0,E.jsx)(M,{})}):null}function M(){let{workspaceName:e,treeName:t}=r(),n=a(),o=i(),{showToast:s,showProgress:c}=h(),l=new URLSearchParams(n.search),Le=(()=>{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]:[]})(),[C,Ze]=(0,T.useState)(null),[Qe,$e]=(0,T.useState)(!0),[et,w]=(0,T.useState)([]),[nt,D]=(0,T.useState)(!1),[rt,O]=(0,T.useState)(0),k=Xe(),[ot,lt]=(0,T.useState)(null),[ut,dt]=(0,T.useState)(k);ut!==k&&(dt(k),k||lt(null));let[A,ft]=(0,T.useState)(`path`),[pt,mt]=(0,T.useState)(!1),[yt,Ct]=(0,T.useState)(null),[M,wt]=(0,T.useState)(null),[Et,Dt]=(0,T.useState)(``),[Ot,kt]=(0,T.useState)(!1),[At,jt]=(0,T.useState)(!1),[Mt,Nt]=(0,T.useState)(!1),[N,Pt]=(0,T.useState)(null),[P,F]=(0,T.useState)(1),[I,Ft]=(0,T.useState)(50),[L,It]=(0,T.useState)(Le),[Lt,Rt]=(0,T.useState)(null),{state:R,saveFilters:zt,setSort:Bt,setAccentColor:Vt,setMapDocuments:Ht}=Ce(),Ut=R.filters.features.allOf,z=R.filters.features.anyOf,Wt=R.filters.features.noneOf,Gt=Oe(R.filters.timeline),Kt=De(R.filters.geo),qt=Ae(R.filters.lens,R.filters.geo.includeUnlocated),B=R.filters.lens.ids,Jt=[...Gt,...Kt,...qt],Yt=R.filters.sort??ke,Xt=JSON.stringify({a:Ut,b:z,c:Wt,d:Jt,i:B,s:Yt}),Zt=JSON.stringify({a:Ut,b:z,c:Wt,d:Jt,s:Yt}),V=je(n.pathname).path,H=t??`context`,U=H===`backends`,[Qt,$t]=(0,T.useState)([]);(0,T.useEffect)(()=>{!U||!e||ge(e).then($t).catch(()=>$t([]))},[U,e]);let en=U?ae(V,Qt):null,[tn,nn]=(0,T.useState)(!1),rn=`${H}\0${V}`,[an,on]=(0,T.useState)(rn);an!==rn&&(on(rn),nn(!1));let W=l.get(`layer`)===`1`,G=l.get(`layerId`)||null,[K,sn]=(0,T.useState)(null),[q,cn]=(0,T.useState)(null),ln=(0,T.useRef)(null);(0,T.useEffect)(()=>{ln.current=q},[q]);let[un,dn]=(0,T.useState)(`left`),[fn,pn]=(0,T.useState)([]),{openM1Drawer:mn,openM2Drawer:hn,goBack:gn}=Pe(),[_n,vn]=(0,T.useState)([]),J=(0,T.useMemo)(()=>{if(!K||V===`/`||W)return null;let e=V.split(`/`).filter(Boolean),t=K;for(let n of e)if(t=t?.children?.find(e=>e.name===n)??null,!t)return null;return t},[K,V,W]),Y=J?.type===`canvas`?`canvas`:null,yn=(0,T.useRef)(null);(0,T.useEffect)(()=>{!e||!K||W||yn.current===`${e}/${H}`&&(V!==`/`&&!J||Fe(e,H,V))},[e,K,W,V,J,H]);let bn=(0,T.useMemo)(()=>W||A===`workspace`||L.length>0||g(H)!==`directory`?[]:_t(K,V),[K,V,H,W,A,L]),xn=W?null:V===`/`?K:J,X=xe(),Sn=`${H}\0${V}`,[Cn,wn]=(0,T.useState)(null),Tn=Cn?.key===Sn?Cn.views:We(xn?.metadata),En=X?.pinned&&X.view?[X.view,...Tn.filter(e=>e.id!==X.view.id)]:Tn,Dn=X?.pinned&&X.view?X.view.id:Cn?.key===Sn?Cn.activeId:En[0]?.id??Ve.id,Z=En.find(e=>e.id===Dn)??En[0]??Ve;(0,T.useEffect)(()=>{X?.selectView(Z)},[Z,X]);let On=U?void 0:X?.schema??ze(Z),kn=On?[...Ut,On]:Ut;He(Be({workspace:e??null,treeNameOrId:H,treeType:g(H),path:V,scope:A===`workspace`?`workspace`:W?`layer`:`path`,layerId:W?G:void 0,unfiledOnly:tn},{...R.filters,features:{...R.filters.features,allOf:kn}},R.geoSelection,L));let An=e=>{let t=En.find(t=>t.id===e);t&&X?.selectView(t),F(1),pn([]),wn({key:Sn,views:En,activeId:e})},jn=(t,n)=>{n&&n!==Dn&&(F(1),pn([]));let r=t.find(e=>e.id===(n??Dn));r&&X?.selectView(r),wn({key:Sn,views:t,activeId:n??Dn}),oe(e,V,{metadata:{...xn?.metadata??{},views:t}},H).catch(()=>{s({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},Mn=Y===`canvas`&&typeof J?.querySpec?.query==`string`?J.querySpec.query:``,Nn=Y===`canvas`?{label:J?.label,description:J?.description,color:J?.color}:null,{isPinned:Pn,pin:Fn,unpin:In,pins:Ln}=ve(),Rn=C?.name,Q=(0,T.useMemo)(()=>Rn&&Y===`canvas`&&!W?{workspaceName:Rn,treeName:H,path:V}:null,[Rn,Y,W,H,V]),zn=Q?Pn(Q):!1,Bn=J?.id,Vn=J?.label,Hn=(0,T.useCallback)(async()=>{if(Q)try{let e=Ln.find(e=>e.workspaceName===Q.workspaceName&&e.treeName===Q.treeName&&e.path===Q.path);e?await In(e.id):await Fn({...Q,layerId:Bn,label:Vn})}catch(e){console.error(`Failed to update home pins:`,e)}},[Q,Ln,Fn,In,Bn,Vn]),Un=e?`${e}://${V===`/`?``:V.replace(/^\//,``)}`:``,Wn=we(C?.color)||null;(0,T.useEffect)(()=>(Vt(Wn),()=>Vt(null)),[Wn,Vt]);let Gn=(0,T.useCallback)(async t=>{let n=B;if(t?.anyOf?.length&&z.length&&(n=((await v(e,V,H,{limit:0,anyOf:z,ids:B,applyCanvasSpec:!1})).payload||[]).map(e=>e.id),!n.length))return{payload:[],count:0,totalCount:0};let r=await v(e,V,H,{limit:t?.limit,offset:t?.offset,page:t?.page,sortBy:t?.sortBy,order:t?.order,allOf:[...Ut,...t?.allOf??[]],anyOf:t?.anyOf?.length?t.anyOf:z,noneOf:Wt,filters:Jt,ids:n,queries:[...L,...t?.queries??[],...t?.q?[t.q]:[]],applyCanvasSpec:!1});return{payload:r.payload||[],count:r.count??void 0,totalCount:r.totalCount??void 0}},[e,V,H,Xt,L]);(0,T.useEffect)(()=>{e&&(async()=>{$e(!0);try{let t=await p.get(`${f.workspaces}/${e}`),n;n=t&&`workspace`in t?t.workspace:t,Ze(n)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch workspace ${e}`;s({title:`Error`,description:n,variant:`destructive`}),Ze(null)}finally{$e(!1)}})()},[e,s]),(0,T.useEffect)(()=>{let e=e=>{let t=e.detail?.workspace;t&&Ze(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 Kn=(B?.length??0)>0&&!W&&!(tn&&en)&&L.length<=1,{documents:qn,count:Jn,ready:Yn,setCue:Xn,resync:Zn,rank:Qn}=ht({workspaceRef:e,specs:(0,T.useMemo)(()=>{let e={features:{allOf:kn,anyOf:z,noneOf:Wt},filters:Jt};return A!==`workspace`&&(g(H)===`directory`?e.directory={tree:H,path:V}:e.context=V),[{label:`scope`,spec:e}]},[Zt,V,H,A,On]),opts:(0,T.useMemo)(()=>({mode:`live`,debounceMs:150}),[]),enabled:Kn}),$n=Kn&&Yn,er=(0,T.useRef)(!1);(0,T.useEffect)(()=>{er.current=$n},[$n]);let tr=L.length===1?L[0].trim():``;(0,T.useEffect)(()=>{Yn&&Qn(tr?{text:tr}:null,{limit:I,offset:(P-1)*I}).catch(()=>{})},[Yn,tr,I,P,Qn]);let nr=(B??[]).join(`,`);(0,T.useEffect)(()=>{Yn&&Xn(`lens`,{ids:B??[]}).catch(()=>{})},[Yn,nr,Xn,B]);let rr=$n?qn:et,ir=$n?Jn:rt,ar=(0,T.useRef)(new Set);(0,T.useEffect)(()=>{ar.current=new Set(rr.map(e=>Number(e.id)))},[rr]);let or=R.geoSelection;(0,T.useEffect)(()=>{Ht(rr,C?.name??null)},[rr,C?.name,Ht]),(0,T.useEffect)(()=>()=>Ht([]),[Ht]);let sr=(0,T.useMemo)(()=>or?rr.filter(e=>Te(e,or,R.filters.geo.includeUnlocated)):rr,[rr,or,R.filters.geo.includeUnlocated]),cr=fe(V,kn,{treeName:H,treeType:g(H),scope:A,queries:L,anyOf:z,noneOf:Wt,filters:Jt,ids:B,layerId:W&&G?G:void 0}),lr=JSON.stringify([e,cr]),[ur,dr]=(0,T.useState)(``),[fr,pr]=(0,T.useState)(!1),mr=(0,T.useRef)(!1),hr=nt||fr||ur!==lr||$n||!!or,gr=(0,T.useRef)(0),_r=(0,T.useRef)(null);(0,T.useEffect)(()=>()=>{gr.current++,_r.current=null},[]);let vr=(0,T.useRef)(``),$=(0,T.useCallback)(async t=>{if(!e)return;if(Ee(H,V)){gr.current++,_r.current=null,vr.current=``,w([]),O(0),D(!1);return}if(er.current)return;let n=`${tn&&en?`${A}:unfiled`:A}:${On??``}`,r=(B?.length??0)>0,i=bt(e,H,V,P,I,L.join(`␟`),Zt,W&&G?G:``,n),a=r&&i===vr.current;vr.current=i;let o=bt(e,H,V,P,I,L.join(`␟`),Xt,W&&G?G:``,n),c=`${o}\0${k}`;if(t?.silent&&_r.current?.key===c){_r.current.refreshPending=!0;return}let l=++gr.current,u=t?.silent||r||k?void 0:vt.get(o);u&&(w(u.documents),O(u.totalCount),dr(lr),D(!1)),(t?.silent??(a||!!u))||D(!0);let d={key:c,refreshPending:!1};_r.current=d;try{let t;if(tn&&en)t=await b(e,en.driver,en.address,{linked:!1,limit:I,offset:(P-1)*I});else if(W&&G&&A!==`workspace`)t=await ce(e,H,G,{limit:I,page:P,queries:L,allOf:kn,anyOf:z,noneOf:Wt,filters:Jt,ids:B,sortBy:Yt.sortBy||void 0,order:Yt.order});else{let n=g(H);t=await de(e,V,kn,{limit:I,page:P,treeName:H,treeType:n,queries:L,anyOf:z,noneOf:Wt,filters:Jt,ids:B,sortBy:Yt.sortBy||void 0,order:Yt.order,scope:A,debug:k&&L.length>0,debugLimit:200})}let n=t.payload||[],i=t.totalCount||t.count||0;if(!r&&!d.refreshPending&&vt.set(o,{documents:n,totalCount:i}),l!==gr.current)return;let s=t.debug,c=s?.imageDistances??s?.distances??null;lt(c?{query:L[L.length-1]??``,distances:c}:null),w(a?e=>e.length===n.length&&e.every((e,t)=>e.id===n[t].id)?e:n:n),O(i),dr(lr)}catch(e){if(l!==gr.current)return;let t=e instanceof Error?e.message:`Failed to fetch documents`;s({title:`Error`,description:t,variant:`destructive`}),w([]),O(0)}finally{_r.current===d&&(_r.current=null),l===gr.current&&D(!1),l===gr.current&&d.refreshPending&&$({silent:!0})}},[e,V,H,G,W,P,I,C?.status,L,Xt,A,tn,k,On]);(0,T.useEffect)(()=>{$()},[$]),(0,T.useEffect)(()=>{let t=t=>{let n=t.detail;!n||n.workspaceName!==e||(cn({treeName:n.treeName||`context`,path:Me(n.path||`/`)}),dn(`left`))};return window.addEventListener(`workspace:open-to-side`,t),()=>window.removeEventListener(`workspace:open-to-side`,t)},[e,H,V]),(0,T.useEffect)(()=>{let t=t=>{let n=t.detail;if(!(n?.workspaceName&&n.workspaceName!==e)&&(e&&St(e,n),ct(st(n),{tree:H,kind:g(H),path:V,wholeWorkspace:A===`workspace`}))){if(e&&j(e,H,V),er.current){Zn();return}$({silent:!0})}};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[$,e,V,H,A,Zn]);let yr=C?.name,br=C?.id;(0,T.useEffect)(()=>{if(!e||!yr&&!br)return;let t=[yr,br].filter(Boolean).map(e=>`workspace:${e}`),n=()=>t.forEach(e=>m.emit(`subscribe`,{channel:e}));n();let r=m.on(`connect`,n),i=new Map,a=!1,o=()=>{ne(e).then(e=>{a||(i=it(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,er.current){Zn();return}$({silent:!0})}},f=t=>n=>{(t.startsWith(`tree.created`)||t.startsWith(`tree.renamed`))&&o();let r=at(t,n,i);xt(e,r);let a={tree:H,kind:g(H),path:V,wholeWorkspace:A===`workspace`},f=ln.current;f&&ct(r,{tree:f.treeName,kind:g(f.treeName),path:f.path})&&(u=f),ct(r,a,ar.current)&&(l=!0),!(!l&&!u)&&(s||=setTimeout(d,Math.max(200,c+1500-Date.now())))},p=[`document.inserted`,`document.inserted.batch`,`document.updated`,`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])=>m.on(e,t)),()=>{a=!0,s&&clearTimeout(s),r?.(),p.forEach(([e,t])=>m.off(e,t))}},[e,br,yr,H,V,A,$,Zn]);let xr=`${V}\0${H}\0${G??``}\0${A}`,[Sr,Cr]=(0,T.useState)(xr);Sr!==xr&&(Cr(xr),F(1),Rt(null));let wr=`${V}\0${H}\0${G??``}`,[Tr,Er]=(0,T.useState)(wr);Tr!==wr&&(Er(wr),ft(`path`));let Dr=(e,t)=>{let n=e===`/`?`canvas`:e.split(`/`).pop()||`canvas`;Dt(n),wt({parentPath:e,captureView:t})},Or=l.get(`createCanvas`)===`1`,[kr,Ar]=(0,T.useState)(!1);kr!==Or&&(Ar(Or),Or&&Dr(V,!1)),(0,T.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,V]);let jr=(0,T.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`),...Le]),[Nr,Pr]=(0,T.useState)(Mr);Nr!==Mr&&(Pr(Mr),It(Le),F(1));let Fr=`${Mr}\0${Y??``}\0${Mn}\0${V}\0${Lt??``}`,[Ir,Lr]=(0,T.useState)(Fr);Ir!==Fr&&(Lr(Fr),l.has(`q`)||Le.length>0||Y!==`canvas`||Lt===V||(It(Mn?[Mn]:[]),F(1)));let Rr=(0,T.useCallback)(e=>{let t=e.trim();t&&(Rt(null),It(e=>{if(e.includes(t))return e;let n=[...e,t];return jr(n),F(1),n}))},[jr,Rt,It,F]),zr=(0,T.useCallback)(e=>{It(t=>{let n=e<0?[]:t.filter((t,n)=>n!==e);return n.length===0&&Rt(V),jr(n),F(1),n})},[jr,V,Rt,It,F]),Br=L.join(` `).trim(),Vr=!!R.activeContextType&&(R.isDirty||Br!==(Y===`canvas`?Mn:R.savedSearchQuery||``));!e&&K!==null&&sn(null),(0,T.useEffect)(()=>{let t=!1;if(!e)return;let n=0,r=!1,i=(i=!1)=>{let a=++n;i&&se(e,H),te(e,H).then(i=>{!t&&a===n&&(r=!0,yn.current=`${e}/${H}`,sn(i))}).catch(()=>{!t&&a===n&&!r&&sn(null)})};i(!1);let a=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==H||i(!n?.cacheInvalidated)};window.addEventListener(`workspace:tree:refresh`,a);let o=S(e,br);return()=>{t=!0,o(),window.removeEventListener(`workspace:tree:refresh`,a)}},[e,H,br]),!(e&&Y===`canvas`&&!W)&&N!==null&&Pt(null),(0,T.useEffect)(()=>{let t=!1;if(!(!e||Y!==`canvas`||W))return re(e,V,H).then(e=>{t||Pt(e)}).catch(()=>{t||Pt(null)}),()=>{t=!0}},[e,V,H,Y,W]);let Hr=async()=>{if(C){mt(!0);try{let t=await le(e||C.id);Ze(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{mt(!1)}}},Ur=async t=>{if(!C)return;let n=c({title:`Removing…`,description:`Document from "${V}"`});try{await ue(e||C.id,[t],V,[],H,Zr,{trashIfOrphaned:!0}),j(e||C.id,H,V),w(e=>e.filter(e=>e.id!==t)),O(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(!C)return;let n=c({title:`Deleting…`,description:`Document from "${V}"`});try{await me(e||C.id,[t],V,[],H,Zr),j(e||C.id,H,V),w(e=>e.filter(e=>e.id!==t)),O(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(!C)return;let n=c({title:`Removing…`,description:`${t.length} document(s) from "${V}"`});try{await ue(e||C.id,t,V,[],H,Zr,{trashIfOrphaned:!0}),j(e||C.id,H,V),w(e=>e.filter(e=>!t.includes(e.id))),O(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(!C)return;let n=c({title:`Deleting…`,description:`${t.length} document(s)`});try{await me(e||C.id,t,V,[],H,Zr),j(e||C.id,H,V),w(e=>e.filter(e=>!t.includes(e.id))),O(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(!C)return;let n=c({title:`Destroying…`,description:`Document and its backend copies`});try{let r=await ee(e||C.id,[t]);if(r.failed?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}w(e=>e.filter(e=>e.id!==t)),O(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(!C)return;let n=c({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await ee(e||C.id,t),i=new Set(r.successful?.filter(e=>e.docDeleted).map(e=>e.id)??[]);w(e=>e.filter(e=>!i.has(e.id))),O(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:V,sourceTreeName:H}),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:V,sourceTreeName:H}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}})),s({title:`Cut`,description:`${e.length} document(s) cut to clipboard`})},Zr=g(H),Qr=async(t,n,r={})=>{if(!e)return!1;let i=r.targetTreeName??H,a=r.targetTreeType??Zr,o=r.move??yt?.operation===`cut`,s=c({title:o?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let c=await _e(e,t,n,i,a);if(c){j(e,i,t);let a=r.sourceTreeName||yt?.sourceTreeName,c=r.sourcePath||yt?.sourcePath;if((r.move??yt?.operation===`cut`)&&c&&a){let t=g(a);await ue(e,n,c,[],a,t),j(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 $(),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 pe(e,n,t,H,Zr)).length>0;return r&&(Se(e,H,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(!C||ir===0||hr||mr.current||window.prompt(`Type PURGE to permanently delete all ${ir} matching documents across all pages.`)!==`PURGE`)return;mr.current=!0,pr(!0);let t=c({title:`Purging…`,description:`${ir} matching document(s)`});try{let n=await y(e||C.id,cr,ir);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{j(e||C.id,H,V),await $({silent:!0}),mr.current=!1,pr(!1)}},ti=()=>Dr(V,!0),ni=async()=>{if(!(!e||!M||!Et.trim())){kt(!0);try{let t=Et.trim(),n=M.parentPath,r=n===`/`?`/${t}`:`${n}/${t}`,i={...R.filters,features:{...R.filters.features,allOf:kn}};await he(e,r,H,M.captureView?{metadata:{toolbox:i},querySpec:{features:i.features,filters:[...Oe(R.filters.timeline),...De(R.filters.geo)],query:Br||void 0,sort:R.filters.sort?.sortBy?R.filters.sort:null}}:{}),wt(null),se(e,H);try{let t=await te(e,H,{force:!0});sn(t)}catch{}window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e}})),o(Ne(e,r,H))}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to create canvas`,variant:`destructive`})}finally{kt(!1)}}},ri=async()=>{if(!(!e||Y!==`canvas`)){jt(!0);try{let t=N||await ie(e,V,H);Pt(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{jt(!1)}}},ii=async()=>{if(N){jt(!0);try{await x(N.code),Pt(null),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:H}})),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{jt(!1)}}},ai=async()=>{if(!e||Y!==`canvas`||V===`/`)return;let t=Nn?.label||V.split(`/`).pop()||`canvas`,n=N?` Its public link will stop working.`:``;if(window.confirm(`Delete canvas "${t}"? This cannot be undone.${n}`)){Nt(!0);try{if(N)await x(N.code),Pt(null);else if(J?.locked){s({title:`Canvas is locked`,description:`Unlock it before deleting.`,variant:`destructive`});return}await _(e,V,!1,H);let n=V.split(`/`).filter(Boolean);n.pop();let r=n.length?`/${n.join(`/`)}`:`/`;window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:H}})),o(Ne(e,r,H)),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{Nt(!1)}}},oi=(0,T.useCallback)(async t=>{if(!e||!q)return;let n={treeName:H,path:V},r=un===`left`?n:q,i=un===`left`?q:n,a=un===`left`?fn:_n;if(a.length===0){s({title:`Nothing selected`,description:`Tick documents in the focused pane first.`});return}let o=g(i.treeName),l=c({title:t?`Moving…`:`Copying…`,description:`${a.length} document(s) → "${i.path}"`});try{if(!await _e(e,i.path,a,i.treeName,o)){l.done();return}if(j(e,i.treeName,i.path),t){let t=g(r.treeName);await ue(e,a,r.path,[],r.treeName,t),j(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,q,un,H,V,fn,_n,s,c]);if((0,T.useEffect)(()=>{if(!q)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)},[q,oi]),Qe)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,E.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,E.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,E.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading workspace...`})]})});if(!C)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Workspace not found.`});let si=Y===`canvas`&&!W&&!!J,ci=!si&&!U&&xn?(0,E.jsx)(Ge,{views:En,activeId:Dn,onSelect:An,onSave:jn,accentColor:we(C.color),onOpenToSide:e=>{cn({treeName:H,path:V,viewId:e}),dn(`right`)}}):void 0,li=en||C.status!==`active`?(0,E.jsxs)(E.Fragment,{children:[en&&(0,E.jsx)(`button`,{type:`button`,onClick:()=>{nn(!tn),F(1)},"aria-pressed":tn,className:u(`min-h-10 rounded-md border px-2 text-xs`,tn&&`bg-warning/15 text-warning`),children:`Unfiled only`}),C.status!==`active`&&(0,E.jsx)(`button`,{type:`button`,onClick:Hr,disabled:pt,className:`min-h-10 rounded-md border px-2 text-xs`,children:pt?`Starting…`:`Start`})]}):void 0,ui=Ee(H,V)?V===`/Trash`?(0,E.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,E.jsx)(Je,{workspaceName:e||C.id})}):(0,E.jsx)(Ye,{workspace:e||C.id,path:V,onNavigate:t=>o(Ne(e,t,`backends`))},e):(0,E.jsx)(Ke,{navigationTabs:ci,navigationActions:li,onBack:gn,accentColor:we(C.color),urlType:W?g(H)===`directory`?`${H}-layer`:`context-layer`:Y===`canvas`?`canvas`:g(H)===`directory`?H:`context`,urlDisplay:Un,contextPath:V,treeName:H,workspaceId:e||C.id,workspaceLabel:C.label||C.name,workspaceIcon:C.icon,documentSchema:On,documents:sr,isLoading:nt,totalCount:ir,currentPage:P,pageSize:I,onPageChange:F,onPageSizeChange:e=>{Ft(e),F(1)},onRemoveDocument:V===`/`?void 0:Ur,onDeleteDocument:Wr,onDestroyDocument:qr,onRemoveDocuments:V===`/`?void 0:Gr,onDeleteDocuments:Kr,onDestroyDocuments:Jr,onCopyDocuments:Yr,onCutDocuments:Xr,onPasteDocuments:U?void 0:Qr,onImportDocuments:U?void 0:$r,onSelectionChange:pn,onBrowseTree:()=>hn(`workspaces`,`detail`,e??null),onBrowseWorkspaces:()=>mn(`workspaces`),onNavigatePath:t=>o(Ne(e,t,H)),folders:bn,onOpenFolder:t=>o(Ne(e,Me(t),H)),scope:A,onScopeChange:ft,pastedDocumentIds:yt?.documentIds,linkTree:K,onPurgeDocuments:U?void 0:ei,disablePurgeDocuments:hr,canvasInfo:Nn??void 0,isCanvasPinned:zn,onTogglePinCanvas:Q?Hn:void 0,onSaveAsCanvas:K&&Y!==`canvas`&&!W&&!U?ti:void 0,onShareCanvas:Y===`canvas`&&!W?ri:void 0,onUnshareCanvas:N?ii:void 0,onDeleteCanvas:Y===`canvas`&&!W?ai:void 0,isSharingCanvas:At,isDeletingCanvas:Mt,isCanvasShared:!!N,isCanvasLocked:!!J?.locked,backendSearchQueries:L,onBackendSearch:Rr,serverSort:R.filters.sort,onServerSortChange:Bt,onRemoveBackendQuery:zr,canSaveChanges:Vr,isSavingChanges:R.isSaving,onSaveChanges:zt,contentBanner:k&&ot?(0,E.jsx)(gt,{data:ot,className:`mb-3`}):null,children:si&&J?(0,E.jsx)(ye,{workspaceId:e||C.id,treeName:H,path:V,layerId:J.id,querySpec:J.querySpec,metadata:J.metadata,isLocked:!!J.locked,fetchDocuments:R.isDirty?Gn:void 0}):!U&&Z.kind===`columns`?(0,E.jsx)(Ue,{documents:sr,workspaceId:e||C.id,columns:Z.columns??[],onColumnsChange:e=>jn(En.map(t=>t.id===Z.id?{...t,columns:e}:t))}):!U&&Z.kind===`app`&&Z.app&&Z.app!==`notes`?(0,E.jsx)(qe,{app:Z.app,workspaceId:e||C.id,treeName:H,path:V}):null});return(0,E.jsxs)(Ie,{workspaceId:e||C.id,treeName:H,path:V,headerOnly:!0,className:`relative flex flex-col h-full min-h-0`,children:[(0,E.jsx)(tt,{workspaceId:C.id,workspaceName:C.label||C.name},C.id),Ee(H,V)&&(0,E.jsx)(be,{workspace:C.label||C.name,workspaceIcon:C.icon,tree:H,path:V,onBack:gn,onBrowseTree:()=>hn(`workspaces`,`detail`,e||C.id),onBrowseWorkspaces:()=>mn(`workspaces`),onNavigatePath:t=>o(Ne(e,t,H)),accentColor:we(C.color)}),M&&(0,E.jsx)(`div`,{className:`shrink-0 px-2 pt-2`,children:(0,E.jsx)(Re,{title:`New canvas`,onClose:()=>wt(null),children:(0,E.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ni()},className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`label`,{htmlFor:`canvas-name`,className:`mb-1 block text-sm font-medium`,children:`Name`}),(0,E.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:Et,onChange:e=>Dt(e.target.value),onKeyDown:e=>{e.key===`Escape`&&wt(null)},autoFocus:!0})]}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`span`,{className:`mb-1 block text-sm font-medium`,children:`Parent path`}),(0,E.jsx)(`div`,{className:`flex h-10 items-center rounded-md bg-muted px-3 font-mono text-sm text-muted-foreground`,children:M.parentPath===`/`?`/`:M.parentPath})]})]}),(0,E.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,E.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:M.captureView,onChange:e=>wt({...M,captureView:e.target.checked})}),(0,E.jsxs)(`span`,{children:[`Capture the current view`,(0,E.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Freezes the active filters, search and sort into the canvas.`})]})]}),(0,E.jsxs)(`div`,{className:`flex gap-2`,children:[(0,E.jsx)(d,{type:`submit`,disabled:!Et.trim()||Ot,children:Ot?`Creating…`:`Create canvas`}),(0,E.jsx)(d,{type:`button`,variant:`outline`,onClick:()=>wt(null),children:`Cancel`})]})]})})}),(0,E.jsxs)(`div`,{"data-canvas-panes":!0,className:`flex-1 min-h-0 flex gap-2`,children:[(0,E.jsx)(`div`,{"data-canvas-pane":!0,className:u(`flex-1 min-w-0 bg-background overflow-hidden`,q&&(un===`left`?`ring-2 ring-primary`:`ring-1 ring-primary/20`)),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||dn(`left`)},children:ui}),q&&e&&(0,E.jsx)(Tt,{workspaceName:e,workspaceLabel:C.label||C.name,workspaceIcon:C.icon,pane:q,isFocused:un===`right`,clipboard:yt,setClipboard:Ct,onFocus:()=>dn(`right`),onSelectionChange:vn,onNavigate:e=>cn(t=>t&&{...t,path:e,viewId:void 0}),onClose:()=>{cn(null),dn(`left`),vn([])}})]})]})}function wt(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 Tt({workspaceName:e,workspaceLabel:t,workspaceIcon:n,pane:r,isFocused:i=!1,clipboard:a,setClipboard:o,onFocus:s,onSelectionChange:c,onNavigate:l,onClose:d}){let{openM1Drawer:f,openM2Drawer:p}=Pe(),{showToast:m,showProgress:_}=h(),[v,ne]=(0,T.useState)(null),[y,re]=(0,T.useState)([]),[ie,b]=(0,T.useState)(!1),[ae,oe]=(0,T.useState)(0),[ce,le]=(0,T.useState)(1),[fe,pe]=(0,T.useState)(50),x=g(r.treeName),he=wt(v,r.path),ge=he?.type===`canvas`,ve=(0,T.useMemo)(()=>x===`directory`?_t(v,r.path):[],[v,r.path,x]),ye=r.viewId?We(he?.metadata).find(e=>e.id===r.viewId)??null:null,be=`${e}://${r.path===`/`?``:r.path.replace(/^\//,``)}`,xe=ze(ye),S=(0,T.useCallback)(async()=>{if(Ee(r.treeName,r.path)){re([]),oe(0),b(!1);return}let t=bt(e,r.treeName,r.path,ce,fe,``,xe??``),n=vt.get(t);if(n){re(n.documents),oe(n.totalCount);return}b(!0);try{let n=await de(e,r.path,xe?[xe]:[],{limit:fe,page:ce,treeName:r.treeName,treeType:x}),i=n.payload||[],a=n.totalCount||n.count||0;re(i),oe(a),vt.set(t,{documents:i,totalCount:a})}catch(e){m({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch side pane documents`,variant:`destructive`}),re([]),oe(0)}finally{b(!1)}},[e,r.path,r.treeName,x,fe,ce,m,xe]);(0,T.useEffect)(()=>{let t=!1,n=0,i=!1,a=(a=!1)=>{let o=++n;a&&se(e,r.treeName),te(e,r.treeName).then(e=>{!t&&o===n&&(i=!0,ne(e))}).catch(()=>{!t&&o===n&&!i&&ne(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,T.useEffect)(()=>{S()},[S]),(0,T.useEffect)(()=>{let t=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||(St(e,n),ct(st(n),{tree:r.treeName,kind:g(r.treeName),path:r.path})&&(j(e,r.treeName,r.path),S()))};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[S,e,r.treeName,r.path]);let Se=(0,T.useCallback)(async(t,n,i={})=>{let s=i.targetTreeName??r.treeName,c=i.targetTreeType??x,l=i.move??a?.operation===`cut`,u=_({title:l?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let r=await _e(e,t,n,s,c);if(r){j(e,s,t);let r=i.sourcePath||a?.sourcePath,c=i.sourceTreeName||a?.sourceTreeName;if((i.move??a?.operation===`cut`)&&r&&c){let t=g(c);await ue(e,n,r,[],c,t),j(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 S(),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,x,S,_,a,o]),Ce=(0,T.useCallback)(()=>{j(e,r.treeName,r.path),S()},[e,r.treeName,r.path,S]),we=(0,T.useCallback)(async t=>{let n=_({title:`Removing…`,description:`${t.length} document(s) from "${r.path}"`});try{await ue(e,t,r.path,[],r.treeName,x),Ce(),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,x,Ce,_]),Te=(0,T.useCallback)(async t=>{let n=_({title:`Deleting…`,description:`${t.length} document(s)`});try{await me(e,t,r.path,[],r.treeName,x),Ce(),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,x,Ce,_]),De=(0,T.useCallback)(async t=>{let n=_({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await ee(e,t);if(r.failed?.length&&!r.successful?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}Ce();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,Ce,_]);return(0,E.jsxs)(`div`,{className:u(`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:[d&&(0,E.jsx)(`button`,{type:`button`,onClick:d,className:`absolute right-2 top-2 z-10 px-2 py-1 text-xs rounded-md border bg-background/90 hover:bg-accent`,children:`Close`}),Ee(r.treeName,r.path)?r.path===`/Trash`?(0,E.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,E.jsx)(Je,{workspaceName:e})}):(0,E.jsx)(Ye,{workspace:e,path:r.path,onNavigate:l||(()=>{})}):(0,E.jsx)(Ke,{frameContent:!1,onBrowseWorkspaces:()=>f(`workspaces`),onBrowseTree:()=>p(`workspaces`,`detail`,e),urlType:ge?`canvas`:x===`directory`?r.treeName:`context`,urlDisplay:be,contextPath:r.path,treeName:r.treeName,workspaceId:e,workspaceLabel:t,workspaceIcon:n,documentSchema:xe,documents:y,isLoading:ie,totalCount:ae,currentPage:ce,pageSize:fe,onPageChange:le,onPageSizeChange:e=>{pe(e),le(1)},onRemoveDocument:r.path===`/`?void 0:e=>we([e]),onRemoveDocuments:r.path===`/`?void 0:we,onDeleteDocument:e=>Te([e]),onDeleteDocuments:Te,onDestroyDocument:e=>De([e]),onDestroyDocuments:De,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:Se,onSelectionChange:c,pastedDocumentIds:a?.documentIds,linkTree:v,folders:ve,onOpenFolder:l,onNavigatePath:l,canvasInfo:ge?{label:he?.label,description:he?.description,color:he?.color}:void 0,children:ye?.kind===`columns`?(0,E.jsx)(Ue,{documents:y,workspaceId:e,columns:ye.columns??[],onColumnsChange:()=>{},readOnly:!0}):ye?.kind===`app`&&ye.app&&ye.app!==`notes`?(0,E.jsx)(qe,{app:ye.app,workspaceId:e,treeName:r.treeName,path:r.path}):null})]})}export{Ct 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{L as o,Ur as s,Vr as c,pn as l}from"./ui-76Hw0NU_.js";import{t as u}from"./utils-2pl1SbIp.js";import{t as d}from"./button-Bum-POPT.js";import{c as f,t as p}from"./api-CA6WiiYM.js";import{t as m}from"./socket-CtH3EU9m.js";import{n as h}from"./use-toast-BlLDqSUO.js";import{Cn as g,D as ee,G as te,Jt as _,K as v,Mt as ne,Vt as y,X as re,_ as ie,_t as b,a as ae,bn as oe,ht as se,it as ce,on as le,qt as ue,rt as de,u as fe,ut as pe,w as me,x,y as he,yt as ge,zt as _e}from"./workspace-46EFyEKZ.js";import{n as ve,r as ye}from"./use-canvas-pins-D-zi5fqQ.js";import{u as be}from"./ObjectPropertiesCard-CFZ_LqzX.js";import{h as xe,i as S,r as Se}from"./document-list-CwStaizB.js";import{n as Ce}from"./use-toolbox-Ck_cLGgf.js";import{i as we}from"./color-DFEH4BfK.js";import{t as Te}from"./geo-CZfs0E-x.js";import{c as Ee}from"./backend-sync-progress-BJsLP7o5.js";import{a as De,i as Oe,n as ke,o as Ae}from"./workspace-BydSRtST.js";import{n as je,r as Me,t as Ne}from"./url-params-n7kU_WZ-.js";import{i as Pe}from"./use-menu-CaiLyPdw.js";import{n as Fe}from"./last-path-BbXWC3b3.js";import{t as Ie}from"./workspace-area-menu-DtsodEXC.js";import{t as Le}from"./workspace-content-gate-CGZmT2kw.js";import{t as Re}from"./form-panel-DZj3WZ3z.js";import{a as ze,c as Be,i as Ve,l as He,n as Ue,o as We,r as Ge,s as Ke,t as qe}from"./content-app-view-DEW8XLJr.js";import{i as Je,o as Ye,r as Xe}from"./query-debug-CZacGe0M.js";var C=`session.open`,Ze=`session.set`,Qe=`session.ids`,$e=`session.materialize`,et=`session.close`,w=`session.delta`,T=e(n(),1),E=t();function tt({workspaceId:e,workspaceName:t}){let[n,r]=(0,T.useState)([]),[i,a]=(0,T.useState)(new Set),s=t=>`${e}:${t.address}:${t.resyncStartedAt||``}`;(0,T.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 ge(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=m.on(`connect`,l);return m.on(`backend.resync.changed`,u),m.on(`backend.changed`,d),window.addEventListener(`focus`,l),()=>{t=!0,f?.(),m.off(`backend.resync.changed`,u),m.off(`backend.changed`,d),window.removeEventListener(`focus`,l)}},[e]);let c=n.filter(e=>!i.has(s(e)));return c.length?(0,E.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,E.jsxs)(`div`,{role:`status`,className:`mb-2 flex items-center gap-2 text-sm font-medium`,children:[(0,E.jsx)(l,{"aria-hidden":`true`,className:`h-4 w-4 animate-spin`}),(0,E.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,E.jsx)(`span`,{className:`block`,children:`Scanning storage`}),(0,E.jsx)(`span`,{className:`block truncate text-xs font-normal text-muted-foreground`,title:t,children:t})]}),(0,E.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(s)])),children:(0,E.jsx)(o,{"aria-hidden":`true`,className:`h-4 w-4`})})]}),(0,E.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,E.jsxs)(`div`,{children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,E.jsx)(`span`,{className:`truncate`,children:i}),(0,E.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:n===null?`${t} files`:`${t} / ${n}`})]}),(0,E.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,E.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 nt=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:null;function D(e){return`/${e}`.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`}function rt(e,t,n){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>rt(e,t,n));if(typeof e==`string`)return[{tree:null,kind:t,path:D(e)}];let r=nt(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:D(e)}))}function O(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 it(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 at(e,t,n=new Map){let r=nt(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:D(n)}],ids:O(r),unknown:!1}:{targets:[],ids:[],unknown:!0}}let i=[...rt(r.context,`context`,n),...rt(r.directory,`directory`,n)],a=nt(r.changed);a&&i.push(...rt(a.context,`context`,n),...rt(a.directory,`directory`,n));let o=O(r);if(i.length)return{targets:i,ids:o,unknown:!1};let s=r.reason===`content`||r.reason===`relations`;return e.startsWith(`document.updated`)&&s&&o.length?{targets:[],ids:o,unknown:!1}:{targets:[],ids:o,unknown:!0}}function k(e,t){return e===t||e===`/`||t===`/`||e.startsWith(`${t}/`)||t.startsWith(`${e}/`)}function ot(e,t){if(e.kind&&e.kind!==t.kind||e.tree&&e.tree!==t.tree)return!1;if(t.kind===`context`){let n=e=>D(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 k(e.path,t.path)}function st(e){return at(`tree.refresh`,{treeName:e?.treeName,path:e?.path||`/`})}function ct(e,t,n){if(e.unknown||e.targets.length&&(t.wholeWorkspace||e.targets.some(e=>ot(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 lt(e,t,n={}){return m.request(C,{workspace:e,specs:t,opts:n})}function ut(e,t,n){return m.request(Ze,{sessionId:e,label:t,spec:n})}function dt(e){return m.request(Qe,{sessionId:e})}function A(e,t={}){return m.request($e,{sessionId:e,...t})}function ft(e){return m.request(et,{sessionId:e})}function pt(e){return m.on(w,e)}var mt=100;function ht({workspaceRef:e,specs:t,opts:n,enabled:r=!0}){let[i,a]=(0,T.useState)([]),[o,s]=(0,T.useState)(0),[c,l]=(0,T.useState)(null),[u,d]=(0,T.useState)(null),f=(0,T.useRef)([]),p=(0,T.useRef)(new Map),h=(0,T.useRef)(null),g=(0,T.useRef)(null),ee=(0,T.useRef)(null),te=(0,T.useRef)({}),_=(0,T.useRef)(null),v=(0,T.useMemo)(()=>JSON.stringify(t),[t]),ne=(0,T.useMemo)(()=>JSON.stringify(n??{}),[n]),y=(0,T.useCallback)(()=>{let e=p.current;a(f.current.map(t=>e.get(t)).filter(Boolean))},[]),re=(0,T.useCallback)(async e=>{let t=g.current;if(!t||e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=mt){let i=e.slice(r,r+mt),a=await de(t,`/`,[],{ids:i,scope:`workspace`,limit:i.length});n.push(...a.payload||[])}return n},[]),ie=(0,T.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]),b=(0,T.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 ie(a,[],t)},[ie]);(0,T.useEffect)(()=>{if(g.current=e??null,!r||!e)return;let t=!1,n=null,i=async()=>{try{let r=await lt(e,JSON.parse(v),JSON.parse(ne));if(t){ft(r.sessionId).catch(()=>{});return}n=r.sessionId,h.current=r.sessionId,l(r.sessionId),d(null),f.current=[],p.current=new Map,await b(r.ids,r.count)}catch(e){if(t)return;d(e instanceof Error?e.message:`Failed to open query session`),l(null),h.current=null}};i();let o=m.on(`connect`,()=>{i()});return()=>{t=!0,o?.();let e=n??h.current;e&&ft(e).catch(()=>{}),h.current=null,f.current=[],p.current=new Map,l(null),a([]),s(0)}},[e,v,ne,r]),(0,T.useEffect)(()=>{if(!c)return;let e=pt(e=>{if(e.sessionId===c){if(ee.current!==null){_.current?.(ee.current,te.current);return}e.ids===void 0?ie(e.added??[],e.removed??[],e.count):b(e.ids,e.count)}});return()=>{e?.()}},[c,ie,b]);let ae=(0,T.useCallback)(async()=>{let e=h.current;if(e)try{let t=await dt(e);await b(t.ids,t.count)}catch{}},[b]),oe=(0,T.useCallback)(async(e,t)=>{let n=h.current;if(!n)throw Error(`No open query session`);let r=await ut(n,e,t);if(ee.current!==null){await _.current?.(ee.current,te.current);return}await b(r.ids,r.count)},[b]),se=(0,T.useCallback)(async(e,t={})=>{let n=h.current;if(!n)throw Error(`No open query session`);if(ee.current=e,te.current=t,e===null){await ae();return}let r=await A(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,ae]);(0,T.useEffect)(()=>{_.current=se},[se]);let ce=(0,T.useCallback)(async(e,t,n={})=>{let r=h.current;if(!r)throw Error(`No open query session`);let i=await A(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 ut(r,e,{ids:i.ids});return await b(a.ids,a.count),i.ids},[b]);return{documents:i,count:o,ready:c!==null,error:u,setCue:oe,resync:ae,rank:se,rankAndPin:ce}}function gt({data:e,className:t}){let[n,r]=(0,T.useState)(!0),{rows:i,gapIndex:a,span:o}=(0,T.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,E.jsxs)(`div`,{className:u(`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 l=a>0?i[a].distance:null;return(0,E.jsxs)(`div`,{className:u(`rounded-md border border-border bg-muted/30 text-xs`,t),children:[(0,E.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,E.jsx)(s,{className:`h-3.5 w-3.5`}):(0,E.jsx)(c,{className:`h-3.5 w-3.5`}),`Query debug`,(0,E.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`: image distances for “`,e.query,`” (`,i.length,` nearest, unfloored)`]})]}),n&&(0,E.jsxs)(`div`,{className:`space-y-2 border-t border-border px-3 py-2`,children:[(0,E.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.`,l===null?(0,E.jsxs)(E.Fragment,{children:[` `,(0,E.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,E.jsxs)(E.Fragment,{children:[` A jump at `,(0,E.jsx)(`span`,{className:`font-mono`,children:l.toFixed(4)}),` (Δ`,o.biggest.toFixed(4),`, vs typical Δ`,o.median.toFixed(4),`) stands out (a likely boundary).`]})]}),(0,E.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:(0,E.jsx)(`table`,{className:`w-full font-mono text-[11px]`,children:(0,E.jsx)(`tbody`,{children:i.map((e,t)=>(0,E.jsxs)(`tr`,{className:u(`border-b border-border/40 last:border-0`,t===a&&`border-t-2 border-t-amber-500/70`),children:[(0,E.jsx)(`td`,{className:`py-0.5 pr-3 text-muted-foreground`,children:t+1}),(0,E.jsxs)(`td`,{className:`py-0.5 pr-3`,children:[`#`,e.id]}),(0,E.jsx)(`td`,{className:`py-0.5 tabular-nums`,children:e.distance.toFixed(4)}),t===a&&(0,E.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,E.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.`]})]})]})}function _t(e,t){if(!e)return[];let n=t.split(`/`).filter(Boolean),r=e;for(let e of n)if(r=r?.children?.find(t=>t.name===e)??null,!r)return[];let i=n.length?`/${n.join(`/`)}`:``,a=(r.children??[]).filter(e=>e.type!==`canvas`).map(e=>({name:e.name,path:`${i}/${e.name}`,label:e.label,color:e.color,childCount:e.children?.length??0})).sort((e,t)=>(e.label||e.name).localeCompare(t.label||t.name,void 0,{numeric:!0,sensitivity:`base`}));return n.length>0&&a.unshift({name:`..`,path:n.length>1?`/${n.slice(0,-1).join(`/`)}`:`/`,isParent:!0}),a}var vt=new Map;function yt(e,t,n){return`${e}\0${t}\0${n}`}function bt(e,t,n,r,i,a,o=``,s=``,c=`path`){return`${yt(e,t,n)}\0${r}\0${i}\0${a}\0${o}\0${s}\0${c}`}function j(e,t,n){let r=yt(e,t,n);for(let e of vt.keys())e.startsWith(r)&&vt.delete(e)}function xt(e,t){let n=`${e}\0`;for(let[e,r]of vt){if(!e.startsWith(n))continue;let[,i,a,,,,,,o=`path`]=e.split(`\0`);ct(t,{tree:i,kind:g(i),path:a,wholeWorkspace:o.startsWith(`workspace`)},r.documents.map(e=>Number(e.id)))&&vt.delete(e)}}function St(e,t){xt(t?.workspaceName??e,st(t))}function Ct(){let{workspaceName:e}=r();return e?(0,E.jsx)(Le,{workspaceName:e,children:(0,E.jsx)(M,{})}):null}function M(){let{workspaceName:e,treeName:t}=r(),n=a(),o=i(),{showToast:s,showProgress:c}=h(),l=new URLSearchParams(n.search),Le=(()=>{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]:[]})(),[C,Ze]=(0,T.useState)(null),[Qe,$e]=(0,T.useState)(!0),[et,w]=(0,T.useState)([]),[nt,D]=(0,T.useState)(!1),[rt,O]=(0,T.useState)(0),k=Xe(),[ot,lt]=(0,T.useState)(null),[ut,dt]=(0,T.useState)(k);ut!==k&&(dt(k),k||lt(null));let[A,ft]=(0,T.useState)(`path`),[pt,mt]=(0,T.useState)(!1),[yt,Ct]=(0,T.useState)(null),[M,wt]=(0,T.useState)(null),[Et,Dt]=(0,T.useState)(``),[Ot,kt]=(0,T.useState)(!1),[At,jt]=(0,T.useState)(!1),[Mt,Nt]=(0,T.useState)(!1),[N,Pt]=(0,T.useState)(null),[P,F]=(0,T.useState)(1),[I,Ft]=(0,T.useState)(50),[L,It]=(0,T.useState)(Le),[Lt,Rt]=(0,T.useState)(null),{state:R,saveFilters:zt,setSort:Bt,setAccentColor:Vt,setMapDocuments:Ht}=Ce(),Ut=R.filters.features.allOf,z=R.filters.features.anyOf,Wt=R.filters.features.noneOf,Gt=Oe(R.filters.timeline),Kt=De(R.filters.geo),qt=Ae(R.filters.lens,R.filters.geo.includeUnlocated),B=R.filters.lens.ids,Jt=[...Gt,...Kt,...qt],Yt=R.filters.sort??ke,Xt=JSON.stringify({a:Ut,b:z,c:Wt,d:Jt,i:B,s:Yt}),Zt=JSON.stringify({a:Ut,b:z,c:Wt,d:Jt,s:Yt}),V=je(n.pathname).path,H=t??`context`,U=H===`backends`,[Qt,$t]=(0,T.useState)([]);(0,T.useEffect)(()=>{!U||!e||ge(e).then($t).catch(()=>$t([]))},[U,e]);let en=U?ae(V,Qt):null,[tn,nn]=(0,T.useState)(!1),rn=`${H}\0${V}`,[an,on]=(0,T.useState)(rn);an!==rn&&(on(rn),nn(!1));let W=l.get(`layer`)===`1`,G=l.get(`layerId`)||null,[K,sn]=(0,T.useState)(null),[q,cn]=(0,T.useState)(null),ln=(0,T.useRef)(null);(0,T.useEffect)(()=>{ln.current=q},[q]);let[un,dn]=(0,T.useState)(`left`),[fn,pn]=(0,T.useState)([]),{openM1Drawer:mn,openM2Drawer:hn,goBack:gn}=Pe(),[_n,vn]=(0,T.useState)([]),J=(0,T.useMemo)(()=>{if(!K||V===`/`||W)return null;let e=V.split(`/`).filter(Boolean),t=K;for(let n of e)if(t=t?.children?.find(e=>e.name===n)??null,!t)return null;return t},[K,V,W]),Y=J?.type===`canvas`?`canvas`:null,yn=(0,T.useRef)(null);(0,T.useEffect)(()=>{!e||!K||W||yn.current===`${e}/${H}`&&(V!==`/`&&!J||Fe(e,H,V))},[e,K,W,V,J,H]);let bn=(0,T.useMemo)(()=>W||A===`workspace`||L.length>0||g(H)!==`directory`?[]:_t(K,V),[K,V,H,W,A,L]),xn=W?null:V===`/`?K:J,X=xe(),Sn=`${H}\0${V}`,[Cn,wn]=(0,T.useState)(null),Tn=Cn?.key===Sn?Cn.views:We(xn?.metadata),En=X?.pinned&&X.view?[X.view,...Tn.filter(e=>e.id!==X.view.id)]:Tn,Dn=X?.pinned&&X.view?X.view.id:Cn?.key===Sn?Cn.activeId:En[0]?.id??Ve.id,Z=En.find(e=>e.id===Dn)??En[0]??Ve;(0,T.useEffect)(()=>{X?.selectView(Z)},[Z,X]);let On=U?void 0:X?.schema??ze(Z),kn=On?[...Ut,On]:Ut;He(Be({workspace:e??null,treeNameOrId:H,treeType:g(H),path:V,scope:A===`workspace`?`workspace`:W?`layer`:`path`,layerId:W?G:void 0,unfiledOnly:tn},{...R.filters,features:{...R.filters.features,allOf:kn}},R.geoSelection,L));let An=e=>{let t=En.find(t=>t.id===e);t&&X?.selectView(t),F(1),pn([]),wn({key:Sn,views:En,activeId:e})},jn=(t,n)=>{n&&n!==Dn&&(F(1),pn([]));let r=t.find(e=>e.id===(n??Dn));r&&X?.selectView(r),wn({key:Sn,views:t,activeId:n??Dn}),oe(e,V,{metadata:{...xn?.metadata??{},views:t}},H).catch(()=>{s({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},Mn=Y===`canvas`&&typeof J?.querySpec?.query==`string`?J.querySpec.query:``,Nn=Y===`canvas`?{label:J?.label,description:J?.description,color:J?.color}:null,{isPinned:Pn,pin:Fn,unpin:In,pins:Ln}=ve(),Rn=C?.name,Q=(0,T.useMemo)(()=>Rn&&Y===`canvas`&&!W?{workspaceName:Rn,treeName:H,path:V}:null,[Rn,Y,W,H,V]),zn=Q?Pn(Q):!1,Bn=J?.id,Vn=J?.label,Hn=(0,T.useCallback)(async()=>{if(Q)try{let e=Ln.find(e=>e.workspaceName===Q.workspaceName&&e.treeName===Q.treeName&&e.path===Q.path);e?await In(e.id):await Fn({...Q,layerId:Bn,label:Vn})}catch(e){console.error(`Failed to update home pins:`,e)}},[Q,Ln,Fn,In,Bn,Vn]),Un=e?`${e}://${V===`/`?``:V.replace(/^\//,``)}`:``,Wn=we(C?.color)||null;(0,T.useEffect)(()=>(Vt(Wn),()=>Vt(null)),[Wn,Vt]);let Gn=(0,T.useCallback)(async t=>{let n=B;if(t?.anyOf?.length&&z.length&&(n=((await v(e,V,H,{limit:0,anyOf:z,ids:B,applyCanvasSpec:!1})).payload||[]).map(e=>e.id),!n.length))return{payload:[],count:0,totalCount:0};let r=await v(e,V,H,{limit:t?.limit,offset:t?.offset,page:t?.page,sortBy:t?.sortBy,order:t?.order,allOf:[...Ut,...t?.allOf??[]],anyOf:t?.anyOf?.length?t.anyOf:z,noneOf:Wt,filters:Jt,ids:n,queries:[...L,...t?.queries??[],...t?.q?[t.q]:[]],applyCanvasSpec:!1});return{payload:r.payload||[],count:r.count??void 0,totalCount:r.totalCount??void 0}},[e,V,H,Xt,L]);(0,T.useEffect)(()=>{e&&(async()=>{$e(!0);try{let t=await p.get(`${f.workspaces}/${e}`),n;n=t&&`workspace`in t?t.workspace:t,Ze(n)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch workspace ${e}`;s({title:`Error`,description:n,variant:`destructive`}),Ze(null)}finally{$e(!1)}})()},[e,s]),(0,T.useEffect)(()=>{let e=e=>{let t=e.detail?.workspace;t&&Ze(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 Kn=(B?.length??0)>0&&!W&&!(tn&&en)&&L.length<=1,{documents:qn,count:Jn,ready:Yn,setCue:Xn,resync:Zn,rank:Qn}=ht({workspaceRef:e,specs:(0,T.useMemo)(()=>{let e={features:{allOf:kn,anyOf:z,noneOf:Wt},filters:Jt};return A!==`workspace`&&(g(H)===`directory`?e.directory={tree:H,path:V}:e.context=V),[{label:`scope`,spec:e}]},[Zt,V,H,A,On]),opts:(0,T.useMemo)(()=>({mode:`live`,debounceMs:150}),[]),enabled:Kn}),$n=Kn&&Yn,er=(0,T.useRef)(!1);(0,T.useEffect)(()=>{er.current=$n},[$n]);let tr=L.length===1?L[0].trim():``;(0,T.useEffect)(()=>{Yn&&Qn(tr?{text:tr}:null,{limit:I,offset:(P-1)*I}).catch(()=>{})},[Yn,tr,I,P,Qn]);let nr=(B??[]).join(`,`);(0,T.useEffect)(()=>{Yn&&Xn(`lens`,{ids:B??[]}).catch(()=>{})},[Yn,nr,Xn,B]);let rr=$n?qn:et,ir=$n?Jn:rt,ar=(0,T.useRef)(new Set);(0,T.useEffect)(()=>{ar.current=new Set(rr.map(e=>Number(e.id)))},[rr]);let or=R.geoSelection;(0,T.useEffect)(()=>{Ht(rr,C?.name??null)},[rr,C?.name,Ht]),(0,T.useEffect)(()=>()=>Ht([]),[Ht]);let sr=(0,T.useMemo)(()=>or?rr.filter(e=>Te(e,or,R.filters.geo.includeUnlocated)):rr,[rr,or,R.filters.geo.includeUnlocated]),cr=fe(V,kn,{treeName:H,treeType:g(H),scope:A,queries:L,anyOf:z,noneOf:Wt,filters:Jt,ids:B,layerId:W&&G?G:void 0}),lr=JSON.stringify([e,cr]),[ur,dr]=(0,T.useState)(``),[fr,pr]=(0,T.useState)(!1),mr=(0,T.useRef)(!1),hr=nt||fr||ur!==lr||$n||!!or,gr=(0,T.useRef)(0),_r=(0,T.useRef)(null);(0,T.useEffect)(()=>()=>{gr.current++,_r.current=null},[]);let vr=(0,T.useRef)(``),$=(0,T.useCallback)(async t=>{if(!e)return;if(Ee(H,V)){gr.current++,_r.current=null,vr.current=``,w([]),O(0),D(!1);return}if(er.current)return;let n=`${tn&&en?`${A}:unfiled`:A}:${On??``}`,r=(B?.length??0)>0,i=bt(e,H,V,P,I,L.join(`␟`),Zt,W&&G?G:``,n),a=r&&i===vr.current;vr.current=i;let o=bt(e,H,V,P,I,L.join(`␟`),Xt,W&&G?G:``,n),c=`${o}\0${k}`;if(t?.silent&&_r.current?.key===c){_r.current.refreshPending=!0;return}let l=++gr.current,u=t?.silent||r||k?void 0:vt.get(o);u&&(w(u.documents),O(u.totalCount),dr(lr),D(!1)),(t?.silent??(a||!!u))||D(!0);let d={key:c,refreshPending:!1};_r.current=d;try{let t;if(tn&&en)t=await b(e,en.driver,en.address,{linked:!1,limit:I,offset:(P-1)*I});else if(W&&G&&A!==`workspace`)t=await ce(e,H,G,{limit:I,page:P,queries:L,allOf:kn,anyOf:z,noneOf:Wt,filters:Jt,ids:B,sortBy:Yt.sortBy||void 0,order:Yt.order});else{let n=g(H);t=await de(e,V,kn,{limit:I,page:P,treeName:H,treeType:n,queries:L,anyOf:z,noneOf:Wt,filters:Jt,ids:B,sortBy:Yt.sortBy||void 0,order:Yt.order,scope:A,debug:k&&L.length>0,debugLimit:200})}let n=t.payload||[],i=t.totalCount||t.count||0;if(!r&&!d.refreshPending&&vt.set(o,{documents:n,totalCount:i}),l!==gr.current)return;let s=t.debug,c=s?.imageDistances??s?.distances??null;lt(c?{query:L[L.length-1]??``,distances:c}:null),w(a?e=>e.length===n.length&&e.every((e,t)=>e.id===n[t].id)?e:n:n),O(i),dr(lr)}catch(e){if(l!==gr.current)return;let t=e instanceof Error?e.message:`Failed to fetch documents`;s({title:`Error`,description:t,variant:`destructive`}),w([]),O(0)}finally{_r.current===d&&(_r.current=null),l===gr.current&&D(!1),l===gr.current&&d.refreshPending&&$({silent:!0})}},[e,V,H,G,W,P,I,C?.status,L,Xt,A,tn,k,On]);(0,T.useEffect)(()=>{$()},[$]),(0,T.useEffect)(()=>{let t=t=>{let n=t.detail;!n||n.workspaceName!==e||(cn({treeName:n.treeName||`context`,path:Me(n.path||`/`)}),dn(`left`))};return window.addEventListener(`workspace:open-to-side`,t),()=>window.removeEventListener(`workspace:open-to-side`,t)},[e,H,V]),(0,T.useEffect)(()=>{let t=t=>{let n=t.detail;if(!(n?.workspaceName&&n.workspaceName!==e)&&(e&&St(e,n),ct(st(n),{tree:H,kind:g(H),path:V,wholeWorkspace:A===`workspace`}))){if(e&&j(e,H,V),er.current){Zn();return}$({silent:!0})}};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[$,e,V,H,A,Zn]);let yr=C?.name,br=C?.id;(0,T.useEffect)(()=>{if(!e||!yr&&!br)return;let t=[yr,br].filter(Boolean).map(e=>`workspace:${e}`),n=()=>t.forEach(e=>m.emit(`subscribe`,{channel:e}));n();let r=m.on(`connect`,n),i=new Map,a=!1,o=()=>{ne(e).then(e=>{a||(i=it(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,er.current){Zn();return}$({silent:!0})}},f=t=>n=>{(t.startsWith(`tree.created`)||t.startsWith(`tree.renamed`))&&o();let r=at(t,n,i);xt(e,r);let a={tree:H,kind:g(H),path:V,wholeWorkspace:A===`workspace`},f=ln.current;f&&ct(r,{tree:f.treeName,kind:g(f.treeName),path:f.path})&&(u=f),ct(r,a,ar.current)&&(l=!0),!(!l&&!u)&&(s||=setTimeout(d,Math.max(200,c+1500-Date.now())))},p=[`document.inserted`,`document.inserted.batch`,`document.updated`,`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])=>m.on(e,t)),()=>{a=!0,s&&clearTimeout(s),r?.(),p.forEach(([e,t])=>m.off(e,t))}},[e,br,yr,H,V,A,$,Zn]);let xr=`${V}\0${H}\0${G??``}\0${A}`,[Sr,Cr]=(0,T.useState)(xr);Sr!==xr&&(Cr(xr),F(1),Rt(null));let wr=`${V}\0${H}\0${G??``}`,[Tr,Er]=(0,T.useState)(wr);Tr!==wr&&(Er(wr),ft(`path`));let Dr=(e,t)=>{let n=e===`/`?`canvas`:e.split(`/`).pop()||`canvas`;Dt(n),wt({parentPath:e,captureView:t})},Or=l.get(`createCanvas`)===`1`,[kr,Ar]=(0,T.useState)(!1);kr!==Or&&(Ar(Or),Or&&Dr(V,!1)),(0,T.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,V]);let jr=(0,T.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`),...Le]),[Nr,Pr]=(0,T.useState)(Mr);Nr!==Mr&&(Pr(Mr),It(Le),F(1));let Fr=`${Mr}\0${Y??``}\0${Mn}\0${V}\0${Lt??``}`,[Ir,Lr]=(0,T.useState)(Fr);Ir!==Fr&&(Lr(Fr),l.has(`q`)||Le.length>0||Y!==`canvas`||Lt===V||(It(Mn?[Mn]:[]),F(1)));let Rr=(0,T.useCallback)(e=>{let t=e.trim();t&&(Rt(null),It(e=>{if(e.includes(t))return e;let n=[...e,t];return jr(n),F(1),n}))},[jr,Rt,It,F]),zr=(0,T.useCallback)(e=>{It(t=>{let n=e<0?[]:t.filter((t,n)=>n!==e);return n.length===0&&Rt(V),jr(n),F(1),n})},[jr,V,Rt,It,F]),Br=L.join(` `).trim(),Vr=!!R.activeContextType&&(R.isDirty||Br!==(Y===`canvas`?Mn:R.savedSearchQuery||``));!e&&K!==null&&sn(null),(0,T.useEffect)(()=>{let t=!1;if(!e)return;let n=0,r=!1,i=(i=!1)=>{let a=++n;i&&se(e,H),te(e,H).then(i=>{!t&&a===n&&(r=!0,yn.current=`${e}/${H}`,sn(i))}).catch(()=>{!t&&a===n&&!r&&sn(null)})};i(!1);let a=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||n?.treeName&&n.treeName!==H||i(!n?.cacheInvalidated)};window.addEventListener(`workspace:tree:refresh`,a);let o=S(e,br);return()=>{t=!0,o(),window.removeEventListener(`workspace:tree:refresh`,a)}},[e,H,br]),!(e&&Y===`canvas`&&!W)&&N!==null&&Pt(null),(0,T.useEffect)(()=>{let t=!1;if(!(!e||Y!==`canvas`||W))return re(e,V,H).then(e=>{t||Pt(e)}).catch(()=>{t||Pt(null)}),()=>{t=!0}},[e,V,H,Y,W]);let Hr=async()=>{if(C){mt(!0);try{let t=await le(e||C.id);Ze(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{mt(!1)}}},Ur=async t=>{if(!C)return;let n=c({title:`Removing…`,description:`Document from "${V}"`});try{await ue(e||C.id,[t],V,[],H,Zr,{trashIfOrphaned:!0}),j(e||C.id,H,V),w(e=>e.filter(e=>e.id!==t)),O(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(!C)return;let n=c({title:`Deleting…`,description:`Document from "${V}"`});try{await me(e||C.id,[t],V,[],H,Zr),j(e||C.id,H,V),w(e=>e.filter(e=>e.id!==t)),O(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(!C)return;let n=c({title:`Removing…`,description:`${t.length} document(s) from "${V}"`});try{await ue(e||C.id,t,V,[],H,Zr,{trashIfOrphaned:!0}),j(e||C.id,H,V),w(e=>e.filter(e=>!t.includes(e.id))),O(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(!C)return;let n=c({title:`Deleting…`,description:`${t.length} document(s)`});try{await me(e||C.id,t,V,[],H,Zr),j(e||C.id,H,V),w(e=>e.filter(e=>!t.includes(e.id))),O(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(!C)return;let n=c({title:`Destroying…`,description:`Document and its backend copies`});try{let r=await ee(e||C.id,[t]);if(r.failed?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}w(e=>e.filter(e=>e.id!==t)),O(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(!C)return;let n=c({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await ee(e||C.id,t),i=new Set(r.successful?.filter(e=>e.docDeleted).map(e=>e.id)??[]);w(e=>e.filter(e=>!i.has(e.id))),O(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:V,sourceTreeName:H}),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:V,sourceTreeName:H}),window.dispatchEvent(new CustomEvent(`documents:clipboard`,{detail:{documentIds:e,operation:`cut`}})),s({title:`Cut`,description:`${e.length} document(s) cut to clipboard`})},Zr=g(H),Qr=async(t,n,r={})=>{if(!e)return!1;let i=r.targetTreeName??H,a=r.targetTreeType??Zr,o=r.move??yt?.operation===`cut`,s=c({title:o?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let c=await _e(e,t,n,i,a);if(c){j(e,i,t);let a=r.sourceTreeName||yt?.sourceTreeName,c=r.sourcePath||yt?.sourcePath;if((r.move??yt?.operation===`cut`)&&c&&a){let t=g(a);await ue(e,n,c,[],a,t),j(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 $(),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 pe(e,n,t,H,Zr)).length>0;return r&&(Se(e,H,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(!C||ir===0||hr||mr.current||window.prompt(`Type PURGE to permanently delete all ${ir} matching documents across all pages.`)!==`PURGE`)return;mr.current=!0,pr(!0);let t=c({title:`Purging…`,description:`${ir} matching document(s)`});try{let n=await y(e||C.id,cr,ir);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{j(e||C.id,H,V),await $({silent:!0}),mr.current=!1,pr(!1)}},ti=()=>Dr(V,!0),ni=async()=>{if(!(!e||!M||!Et.trim())){kt(!0);try{let t=Et.trim(),n=M.parentPath,r=n===`/`?`/${t}`:`${n}/${t}`,i={...R.filters,features:{...R.filters.features,allOf:kn}};await he(e,r,H,M.captureView?{metadata:{toolbox:i},querySpec:{features:i.features,filters:[...Oe(R.filters.timeline),...De(R.filters.geo)],query:Br||void 0,sort:R.filters.sort?.sortBy?R.filters.sort:null}}:{}),wt(null),se(e,H);try{let t=await te(e,H,{force:!0});sn(t)}catch{}window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e}})),o(Ne(e,r,H))}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to create canvas`,variant:`destructive`})}finally{kt(!1)}}},ri=async()=>{if(!(!e||Y!==`canvas`)){jt(!0);try{let t=N||await ie(e,V,H);Pt(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{jt(!1)}}},ii=async()=>{if(N){jt(!0);try{await x(N.code),Pt(null),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:H}})),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{jt(!1)}}},ai=async()=>{if(!e||Y!==`canvas`||V===`/`)return;let t=Nn?.label||V.split(`/`).pop()||`canvas`,n=N?` Its public link will stop working.`:``;if(window.confirm(`Delete canvas "${t}"? This cannot be undone.${n}`)){Nt(!0);try{if(N)await x(N.code),Pt(null);else if(J?.locked){s({title:`Canvas is locked`,description:`Unlock it before deleting.`,variant:`destructive`});return}await _(e,V,!1,H);let n=V.split(`/`).filter(Boolean);n.pop();let r=n.length?`/${n.join(`/`)}`:`/`;window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:H}})),o(Ne(e,r,H)),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{Nt(!1)}}},oi=(0,T.useCallback)(async t=>{if(!e||!q)return;let n={treeName:H,path:V},r=un===`left`?n:q,i=un===`left`?q:n,a=un===`left`?fn:_n;if(a.length===0){s({title:`Nothing selected`,description:`Tick documents in the focused pane first.`});return}let o=g(i.treeName),l=c({title:t?`Moving…`:`Copying…`,description:`${a.length} document(s) → "${i.path}"`});try{if(!await _e(e,i.path,a,i.treeName,o)){l.done();return}if(j(e,i.treeName,i.path),t){let t=g(r.treeName);await ue(e,a,r.path,[],r.treeName,t),j(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,q,un,H,V,fn,_n,s,c]);if((0,T.useEffect)(()=>{if(!q)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)},[q,oi]),Qe)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,E.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,E.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,E.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading workspace...`})]})});if(!C)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Workspace not found.`});let si=Y===`canvas`&&!W&&!!J,ci=!si&&!U&&xn?(0,E.jsx)(Ge,{views:En,activeId:Dn,onSelect:An,onSave:jn,accentColor:we(C.color),onOpenToSide:e=>{cn({treeName:H,path:V,viewId:e}),dn(`right`)}}):void 0,li=en||C.status!==`active`?(0,E.jsxs)(E.Fragment,{children:[en&&(0,E.jsx)(`button`,{type:`button`,onClick:()=>{nn(!tn),F(1)},"aria-pressed":tn,className:u(`min-h-10 rounded-md border px-2 text-xs`,tn&&`bg-warning/15 text-warning`),children:`Unfiled only`}),C.status!==`active`&&(0,E.jsx)(`button`,{type:`button`,onClick:Hr,disabled:pt,className:`min-h-10 rounded-md border px-2 text-xs`,children:pt?`Starting…`:`Start`})]}):void 0,ui=Ee(H,V)?V===`/Trash`?(0,E.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,E.jsx)(Je,{workspaceName:e||C.id})}):(0,E.jsx)(Ye,{workspace:e||C.id,path:V,onNavigate:t=>o(Ne(e,t,`backends`))},e):(0,E.jsx)(Ke,{navigationTabs:ci,navigationActions:li,onBack:gn,accentColor:we(C.color),urlType:W?g(H)===`directory`?`${H}-layer`:`context-layer`:Y===`canvas`?`canvas`:g(H)===`directory`?H:`context`,urlDisplay:Un,contextPath:V,treeName:H,workspaceId:e||C.id,workspaceLabel:C.label||C.name,workspaceIcon:C.icon,documentSchema:On,documents:sr,isLoading:nt,totalCount:ir,currentPage:P,pageSize:I,onPageChange:F,onPageSizeChange:e=>{Ft(e),F(1)},onRemoveDocument:V===`/`?void 0:Ur,onDeleteDocument:Wr,onDestroyDocument:qr,onRemoveDocuments:V===`/`?void 0:Gr,onDeleteDocuments:Kr,onDestroyDocuments:Jr,onCopyDocuments:Yr,onCutDocuments:Xr,onPasteDocuments:U?void 0:Qr,onImportDocuments:U?void 0:$r,onSelectionChange:pn,onBrowseTree:()=>hn(`workspaces`,`detail`,e??null),onBrowseWorkspaces:()=>mn(`workspaces`),onNavigatePath:t=>o(Ne(e,t,H)),folders:bn,onOpenFolder:t=>o(Ne(e,Me(t),H)),scope:A,onScopeChange:ft,pastedDocumentIds:yt?.documentIds,linkTree:K,onPurgeDocuments:U?void 0:ei,disablePurgeDocuments:hr,canvasInfo:Nn??void 0,isCanvasPinned:zn,onTogglePinCanvas:Q?Hn:void 0,onSaveAsCanvas:K&&Y!==`canvas`&&!W&&!U?ti:void 0,onShareCanvas:Y===`canvas`&&!W?ri:void 0,onUnshareCanvas:N?ii:void 0,onDeleteCanvas:Y===`canvas`&&!W?ai:void 0,isSharingCanvas:At,isDeletingCanvas:Mt,isCanvasShared:!!N,isCanvasLocked:!!J?.locked,backendSearchQueries:L,onBackendSearch:Rr,serverSort:R.filters.sort,onServerSortChange:Bt,onRemoveBackendQuery:zr,canSaveChanges:Vr,isSavingChanges:R.isSaving,onSaveChanges:zt,contentBanner:k&&ot?(0,E.jsx)(gt,{data:ot,className:`mb-3`}):null,children:si&&J?(0,E.jsx)(ye,{workspaceId:e||C.id,treeName:H,path:V,layerId:J.id,querySpec:J.querySpec,metadata:J.metadata,isLocked:!!J.locked,fetchDocuments:R.isDirty?Gn:void 0}):!U&&Z.kind===`columns`?(0,E.jsx)(Ue,{documents:sr,workspaceId:e||C.id,columns:Z.columns??[],onColumnsChange:e=>jn(En.map(t=>t.id===Z.id?{...t,columns:e}:t))}):!U&&Z.kind===`app`&&Z.app&&Z.app!==`notes`?(0,E.jsx)(qe,{app:Z.app,workspaceId:e||C.id,treeName:H,path:V}):null});return(0,E.jsxs)(Ie,{workspaceId:e||C.id,treeName:H,path:V,headerOnly:!0,className:`relative flex flex-col h-full min-h-0`,children:[(0,E.jsx)(tt,{workspaceId:C.id,workspaceName:C.label||C.name},C.id),Ee(H,V)&&(0,E.jsx)(be,{workspace:C.label||C.name,workspaceIcon:C.icon,tree:H,path:V,onBack:gn,onBrowseTree:()=>hn(`workspaces`,`detail`,e||C.id),onBrowseWorkspaces:()=>mn(`workspaces`),onNavigatePath:t=>o(Ne(e,t,H)),accentColor:we(C.color)}),M&&(0,E.jsx)(`div`,{className:`shrink-0 px-2 pt-2`,children:(0,E.jsx)(Re,{title:`New canvas`,onClose:()=>wt(null),children:(0,E.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ni()},className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`label`,{htmlFor:`canvas-name`,className:`mb-1 block text-sm font-medium`,children:`Name`}),(0,E.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:Et,onChange:e=>Dt(e.target.value),onKeyDown:e=>{e.key===`Escape`&&wt(null)},autoFocus:!0})]}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`span`,{className:`mb-1 block text-sm font-medium`,children:`Parent path`}),(0,E.jsx)(`div`,{className:`flex h-10 items-center rounded-md bg-muted px-3 font-mono text-sm text-muted-foreground`,children:M.parentPath===`/`?`/`:M.parentPath})]})]}),(0,E.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,E.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:M.captureView,onChange:e=>wt({...M,captureView:e.target.checked})}),(0,E.jsxs)(`span`,{children:[`Capture the current view`,(0,E.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Freezes the active filters, search and sort into the canvas.`})]})]}),(0,E.jsxs)(`div`,{className:`flex gap-2`,children:[(0,E.jsx)(d,{type:`submit`,disabled:!Et.trim()||Ot,children:Ot?`Creating…`:`Create canvas`}),(0,E.jsx)(d,{type:`button`,variant:`outline`,onClick:()=>wt(null),children:`Cancel`})]})]})})}),(0,E.jsxs)(`div`,{"data-canvas-panes":!0,className:`flex-1 min-h-0 flex gap-2`,children:[(0,E.jsx)(`div`,{"data-canvas-pane":!0,className:u(`flex-1 min-w-0 bg-background overflow-hidden`,q&&(un===`left`?`ring-2 ring-primary`:`ring-1 ring-primary/20`)),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||dn(`left`)},children:ui}),q&&e&&(0,E.jsx)(Tt,{workspaceName:e,workspaceLabel:C.label||C.name,workspaceIcon:C.icon,pane:q,isFocused:un===`right`,clipboard:yt,setClipboard:Ct,onFocus:()=>dn(`right`),onSelectionChange:vn,onNavigate:e=>cn(t=>t&&{...t,path:e,viewId:void 0}),onClose:()=>{cn(null),dn(`left`),vn([])}})]})]})}function wt(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 Tt({workspaceName:e,workspaceLabel:t,workspaceIcon:n,pane:r,isFocused:i=!1,clipboard:a,setClipboard:o,onFocus:s,onSelectionChange:c,onNavigate:l,onClose:d}){let{openM1Drawer:f,openM2Drawer:p}=Pe(),{showToast:m,showProgress:_}=h(),[v,ne]=(0,T.useState)(null),[y,re]=(0,T.useState)([]),[ie,b]=(0,T.useState)(!1),[ae,oe]=(0,T.useState)(0),[ce,le]=(0,T.useState)(1),[fe,pe]=(0,T.useState)(50),x=g(r.treeName),he=wt(v,r.path),ge=he?.type===`canvas`,ve=(0,T.useMemo)(()=>x===`directory`?_t(v,r.path):[],[v,r.path,x]),ye=r.viewId?We(he?.metadata).find(e=>e.id===r.viewId)??null:null,be=`${e}://${r.path===`/`?``:r.path.replace(/^\//,``)}`,xe=ze(ye),S=(0,T.useCallback)(async()=>{if(Ee(r.treeName,r.path)){re([]),oe(0),b(!1);return}let t=bt(e,r.treeName,r.path,ce,fe,``,xe??``),n=vt.get(t);if(n){re(n.documents),oe(n.totalCount);return}b(!0);try{let n=await de(e,r.path,xe?[xe]:[],{limit:fe,page:ce,treeName:r.treeName,treeType:x}),i=n.payload||[],a=n.totalCount||n.count||0;re(i),oe(a),vt.set(t,{documents:i,totalCount:a})}catch(e){m({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch side pane documents`,variant:`destructive`}),re([]),oe(0)}finally{b(!1)}},[e,r.path,r.treeName,x,fe,ce,m,xe]);(0,T.useEffect)(()=>{let t=!1,n=0,i=!1,a=(a=!1)=>{let o=++n;a&&se(e,r.treeName),te(e,r.treeName).then(e=>{!t&&o===n&&(i=!0,ne(e))}).catch(()=>{!t&&o===n&&!i&&ne(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,T.useEffect)(()=>{S()},[S]),(0,T.useEffect)(()=>{let t=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||(St(e,n),ct(st(n),{tree:r.treeName,kind:g(r.treeName),path:r.path})&&(j(e,r.treeName,r.path),S()))};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[S,e,r.treeName,r.path]);let Se=(0,T.useCallback)(async(t,n,i={})=>{let s=i.targetTreeName??r.treeName,c=i.targetTreeType??x,l=i.move??a?.operation===`cut`,u=_({title:l?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let r=await _e(e,t,n,s,c);if(r){j(e,s,t);let r=i.sourcePath||a?.sourcePath,c=i.sourceTreeName||a?.sourceTreeName;if((i.move??a?.operation===`cut`)&&r&&c){let t=g(c);await ue(e,n,r,[],c,t),j(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 S(),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,x,S,_,a,o]),Ce=(0,T.useCallback)(()=>{j(e,r.treeName,r.path),S()},[e,r.treeName,r.path,S]),we=(0,T.useCallback)(async t=>{let n=_({title:`Removing…`,description:`${t.length} document(s) from "${r.path}"`});try{await ue(e,t,r.path,[],r.treeName,x),Ce(),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,x,Ce,_]),Te=(0,T.useCallback)(async t=>{let n=_({title:`Deleting…`,description:`${t.length} document(s)`});try{await me(e,t,r.path,[],r.treeName,x),Ce(),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,x,Ce,_]),De=(0,T.useCallback)(async t=>{let n=_({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await ee(e,t);if(r.failed?.length&&!r.successful?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}Ce();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,Ce,_]);return(0,E.jsxs)(`div`,{className:u(`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:[d&&(0,E.jsx)(`button`,{type:`button`,onClick:d,className:`absolute right-2 top-2 z-10 px-2 py-1 text-xs rounded-md border bg-background/90 hover:bg-accent`,children:`Close`}),Ee(r.treeName,r.path)?r.path===`/Trash`?(0,E.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,E.jsx)(Je,{workspaceName:e})}):(0,E.jsx)(Ye,{workspace:e,path:r.path,onNavigate:l||(()=>{})}):(0,E.jsx)(Ke,{frameContent:!1,onBrowseWorkspaces:()=>f(`workspaces`),onBrowseTree:()=>p(`workspaces`,`detail`,e),urlType:ge?`canvas`:x===`directory`?r.treeName:`context`,urlDisplay:be,contextPath:r.path,treeName:r.treeName,workspaceId:e,workspaceLabel:t,workspaceIcon:n,documentSchema:xe,documents:y,isLoading:ie,totalCount:ae,currentPage:ce,pageSize:fe,onPageChange:le,onPageSizeChange:e=>{pe(e),le(1)},onRemoveDocument:r.path===`/`?void 0:e=>we([e]),onRemoveDocuments:r.path===`/`?void 0:we,onDeleteDocument:e=>Te([e]),onDeleteDocuments:Te,onDestroyDocument:e=>De([e]),onDestroyDocuments:De,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:Se,onSelectionChange:c,pastedDocumentIds:a?.documentIds,linkTree:v,folders:ve,onOpenFolder:l,onNavigatePath:l,canvasInfo:ge?{label:he?.label,description:he?.description,color:he?.color}:void 0,children:ye?.kind===`columns`?(0,E.jsx)(Ue,{documents:y,workspaceId:e,columns:ye.columns??[],onColumnsChange:()=>{},readOnly:!0}):ye?.kind===`app`&&ye.app&&ye.app!==`notes`?(0,E.jsx)(qe,{app:ye.app,workspaceId:e,treeName:r.treeName,path:r.path}):null})]})}export{Ct 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-BoCaZiqu.js";import{t as a}from"./use-settings-back-DE0SPb7h.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-BoCaZiqu.js";import{t as a}from"./use-settings-back-DE0SPb7h.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.32`}),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-BKt1jyXP.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,Sr as s,Zr as c,rn as l,rt as u}from"./ui-76Hw0NU_.js";import{t as d}from"./button-Bum-POPT.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{J as h,L as g,Ot as _,et as v,tt as y}from"./index-Pdg5xeG3.js";import{n as b}from"./page-header-BoCaZiqu.js";import{n as ee,r as x,t as te}from"./useAgentModels-DPu0MHiH.js";import{t as ne}from"./form-panel-DZj3WZ3z.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)(s,{className:`h-4 w-4 text-success`});case`inactive`:return(0,C.jsx)(s,{className:`h-4 w-4 text-warning`});case`error`:return(0,C.jsx)(s,{className:`h-4 w-4 text-destructive`});default:return(0,C.jsx)(s,{className:`h-4 w-4 text-muted-foreground`})}},g=()=>{switch(e.llmProvider){case`anthropic`:return(0,C.jsx)(c,{className:`h-4 w-4 text-warning`});case`openai`:return(0,C.jsx)(c,{className:`h-4 w-4 text-success`});case`ollama`:return(0,C.jsx)(i,{className:`h-4 w-4 text-info`});default:return(0,C.jsx)(c,{className:`h-4 w-4 text-muted-foreground`})}},_=()=>{switch(e.status){case`active`:return`text-success bg-success-subtle border-success`;case`inactive`:return`text-warning bg-warning-subtle border-warning`;case`error`:return`text-destructive bg-destructive-subtle border-destructive`;case`available`:return`text-info bg-info-subtle border-info`;default:return`text-foreground bg-muted border-border`}},v=e.status===`available`||e.status===`inactive`,y=e.status===`active`;return(0,C.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 hover:shadow-elevation-2 transition-shadow bg-card`,children:[(0,C.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[g(),(0,C.jsx)(`h3`,{className:`text-lg font-semibold truncate`,children:e.label||e.name}),e.color&&(0,C.jsx)(`div`,{className:`w-4 h-4 rounded border flex-shrink-0`,style:{backgroundColor:e.color},title:`Color: ${e.color}`})]}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground font-mono`,children:e.name}),e.description&&(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:e.description})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[h(),(0,C.jsx)(`span`,{className:`px-2 py-1 rounded-full text-xs font-medium border ${_()}`,children:e.status})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 text-sm`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider:`}),(0,C.jsx)(`div`,{className:`font-medium capitalize`,children:e.llmProvider})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Model:`}),(0,C.jsx)(`div`,{className:`font-mono text-xs`,children:e.model})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Created:`}),(0,C.jsx)(`div`,{children:new Date(e.createdAt).toLocaleDateString()})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Last Access:`}),(0,C.jsx)(`div`,{children:e.lastAccessed?new Date(e.lastAccessed).toLocaleDateString():`Never`})]})]}),e.config.mcp?.servers&&e.config.mcp.servers.length>0&&(0,C.jsxs)(`div`,{className:`text-sm`,children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`MCP Servers:`}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.config.mcp.servers.map((e,t)=>(0,C.jsx)(`span`,{className:`px-2 py-1 bg-secondary text-secondary-foreground rounded text-xs`,children:e.name},t))})]}),(0,C.jsxs)(`div`,{className:`flex gap-2 pt-2 border-t`,children:[v&&(0,C.jsxs)(d,{onClick:p,disabled: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 h();i(e),l(null)}catch(e){console.error(`Agent fetch error:`,e);let t=`Failed to fetch agents`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to fetch agents`}l(t),Q({title:`Error`,description:t,variant:`destructive`})}finally{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 g(n);i(e=>[...e,r]),T(``),D(``),k(m()),j(``),K(``),B(``),H(``),W(``),I({apiKey:``,baseUrl:e[M],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),Q({title:`Success`,description:`Agent '${r.label||r.name}' created.`}),Z(!1)}catch(e){console.error(`Agent creation error:`,e);let t=`Failed to create agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to create agent`}Q({title:`Error`,description:t,variant:`destructive`})}finally{J(!1)}}},ue=async e=>{try{let t=await v(e);i(e=>e.map(e=>e.name===t.name?t:e)),Q({title:`Success`,description:`Agent '${t.label||t.name}' started.`})}catch(e){console.error(`Agent start error:`,e);let t=`Failed to start agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to start agent`}Q({title:`Error`,description:t,variant:`destructive`})}},de=async e=>{try{await y(e),i(t=>t.map(t=>t.name===e?{...t,status:`inactive`,isActive:!1}:t)),Q({title:`Success`,description:`Agent '${e}' stopped.`})}catch(e){console.error(`Agent stop error:`,e);let t=`Failed to stop agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to stop agent`}Q({title:`Error`,description:t,variant:`destructive`})}},fe=e=>{se(`/agents/${e}`)};return(0,C.jsxs)(`div`,{className:`space-y-6`,children:[(0,C.jsx)(b,{title:`AI Agents`,description:`Create and manage your AI agents with multiple LLM providers`,actions:!Y.local&&!X&&(0,C.jsxs)(d,{onClick:()=>Z(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create agent`,title:`Create agent`,children:[(0,C.jsx)(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,Sr as s,Zr as c,rn as l,rt as u}from"./ui-76Hw0NU_.js";import{t as d}from"./button-Bum-POPT.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{J as h,L as g,Ot as _,et as v,tt as y}from"./index-DUPka8LP.js";import{n as b}from"./page-header-BoCaZiqu.js";import{n as ee,r as x,t as te}from"./useAgentModels-C2cV4Gw5.js";import{t as ne}from"./form-panel-DZj3WZ3z.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)(s,{className:`h-4 w-4 text-success`});case`inactive`:return(0,C.jsx)(s,{className:`h-4 w-4 text-warning`});case`error`:return(0,C.jsx)(s,{className:`h-4 w-4 text-destructive`});default:return(0,C.jsx)(s,{className:`h-4 w-4 text-muted-foreground`})}},g=()=>{switch(e.llmProvider){case`anthropic`:return(0,C.jsx)(c,{className:`h-4 w-4 text-warning`});case`openai`:return(0,C.jsx)(c,{className:`h-4 w-4 text-success`});case`ollama`:return(0,C.jsx)(i,{className:`h-4 w-4 text-info`});default:return(0,C.jsx)(c,{className:`h-4 w-4 text-muted-foreground`})}},_=()=>{switch(e.status){case`active`:return`text-success bg-success-subtle border-success`;case`inactive`:return`text-warning bg-warning-subtle border-warning`;case`error`:return`text-destructive bg-destructive-subtle border-destructive`;case`available`:return`text-info bg-info-subtle border-info`;default:return`text-foreground bg-muted border-border`}},v=e.status===`available`||e.status===`inactive`,y=e.status===`active`;return(0,C.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 hover:shadow-elevation-2 transition-shadow bg-card`,children:[(0,C.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[g(),(0,C.jsx)(`h3`,{className:`text-lg font-semibold truncate`,children:e.label||e.name}),e.color&&(0,C.jsx)(`div`,{className:`w-4 h-4 rounded border flex-shrink-0`,style:{backgroundColor:e.color},title:`Color: ${e.color}`})]}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground font-mono`,children:e.name}),e.description&&(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:e.description})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[h(),(0,C.jsx)(`span`,{className:`px-2 py-1 rounded-full text-xs font-medium border ${_()}`,children:e.status})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 text-sm`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider:`}),(0,C.jsx)(`div`,{className:`font-medium capitalize`,children:e.llmProvider})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Model:`}),(0,C.jsx)(`div`,{className:`font-mono text-xs`,children:e.model})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Created:`}),(0,C.jsx)(`div`,{children:new Date(e.createdAt).toLocaleDateString()})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Last Access:`}),(0,C.jsx)(`div`,{children:e.lastAccessed?new Date(e.lastAccessed).toLocaleDateString():`Never`})]})]}),e.config.mcp?.servers&&e.config.mcp.servers.length>0&&(0,C.jsxs)(`div`,{className:`text-sm`,children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`MCP Servers:`}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.config.mcp.servers.map((e,t)=>(0,C.jsx)(`span`,{className:`px-2 py-1 bg-secondary text-secondary-foreground rounded text-xs`,children:e.name},t))})]}),(0,C.jsxs)(`div`,{className:`flex gap-2 pt-2 border-t`,children:[v&&(0,C.jsxs)(d,{onClick:p,disabled: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 h();i(e),l(null)}catch(e){console.error(`Agent fetch error:`,e);let t=`Failed to fetch agents`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to fetch agents`}l(t),Q({title:`Error`,description:t,variant:`destructive`})}finally{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 g(n);i(e=>[...e,r]),T(``),D(``),k(m()),j(``),K(``),B(``),H(``),W(``),I({apiKey:``,baseUrl:e[M],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),Q({title:`Success`,description:`Agent '${r.label||r.name}' created.`}),Z(!1)}catch(e){console.error(`Agent creation error:`,e);let t=`Failed to create agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to create agent`}Q({title:`Error`,description:t,variant:`destructive`})}finally{J(!1)}}},ue=async e=>{try{let t=await v(e);i(e=>e.map(e=>e.name===t.name?t:e)),Q({title:`Success`,description:`Agent '${t.label||t.name}' started.`})}catch(e){console.error(`Agent start error:`,e);let t=`Failed to start agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to start agent`}Q({title:`Error`,description:t,variant:`destructive`})}},de=async e=>{try{await y(e),i(t=>t.map(t=>t.name===e?{...t,status:`inactive`,isActive:!1}:t)),Q({title:`Success`,description:`Agent '${e}' stopped.`})}catch(e){console.error(`Agent stop error:`,e);let t=`Failed to stop agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to stop agent`}Q({title:`Error`,description:t,variant:`destructive`})}},fe=e=>{se(`/agents/${e}`)};return(0,C.jsxs)(`div`,{className:`space-y-6`,children:[(0,C.jsx)(b,{title:`AI Agents`,description:`Create and manage your AI agents with multiple LLM providers`,actions:!Y.local&&!X&&(0,C.jsxs)(d,{onClick:()=>Z(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create agent`,title:`Create agent`,children:[(0,C.jsx)(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-76Hw0NU_.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-CaiLyPdw.js";import{t as x}from"./use-theme-DaxpiICf.js";import{St as S,a as C,bt 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-Pdg5xeG3.js";import{n as z}from"./page-header-BoCaZiqu.js";import{t as B}from"./use-settings-back-DE0SPb7h.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:C,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:C}),(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:w.map(e=>({id:e.id,label:e.name,title:e.description})),value:M,onChange:R}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:w.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:C(t),alt:``,loading:`lazy`,className:`size-full object-cover`,style:{backgroundColor:t.background}})},t.id)),d&&(0,H.jsx)(q,{label:`Your image`,isActive:!0,onSelect:()=>{},children:(0,H.jsx)(`img`,{src:e.image??void 0,alt:``,className:`size-full object-cover`})})]}),(0,H.jsx)(K,{}),(0,H.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,H.jsx)(`div`,{className:`h-20 w-32 shrink-0 rounded-md border surface-desk`,style:f?{backgroundImage:f,backgroundSize: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-76Hw0NU_.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-CaiLyPdw.js";import{t as x}from"./use-theme-DaxpiICf.js";import{St as S,a as C,bt 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-DUPka8LP.js";import{n as z}from"./page-header-BoCaZiqu.js";import{t as B}from"./use-settings-back-DE0SPb7h.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:C,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:C}),(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:w.map(e=>({id:e.id,label:e.name,title:e.description})),value:M,onChange:R}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:w.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:C(t),alt:``,loading:`lazy`,className:`size-full object-cover`,style:{backgroundColor:t.background}})},t.id)),d&&(0,H.jsx)(q,{label:`Your image`,isActive:!0,onSelect:()=>{},children:(0,H.jsx)(`img`,{src:e.image??void 0,alt:``,className:`size-full object-cover`})})]}),(0,H.jsx)(K,{}),(0,H.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,H.jsx)(`div`,{className:`h-20 w-32 shrink-0 rounded-md border surface-desk`,style:f?{backgroundImage:f,backgroundSize: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{Cn as s,Nt as c}from"./workspace-46EFyEKZ.js";import{p as l}from"./context-BGgz0Y_q.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{Cn as s,Nt as c}from"./workspace-46EFyEKZ.js";import{p as l}from"./context-BGgz0Y_q.js";import{t as u}from"./registry-Cmoo1ljZ.js";import{t as d}from"./applet-target-Bl9Je1N-.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};
|