@augmentd-labs/canvas-web 2.26.20 → 2.26.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/assets/{FiltersApplet-BpqITV13.js → FiltersApplet-DNYAQP5F.js} +1 -1
  2. package/dist/assets/{HomeFab-BAKOAkpE.js → HomeFab-CpTZdNyY.js} +2 -2
  3. package/dist/assets/LensApplet-CRa1j2WP.js +1 -0
  4. package/dist/assets/{NotesApplet-gMAMneRi.js → NotesApplet-CFK86JYj.js} +1 -1
  5. package/dist/assets/_agentId_-CHdTYJFu.js +0 -0
  6. package/dist/assets/{_contextId_-DDFyhgV2.js → _contextId_-m9zn5qav.js} +1 -1
  7. package/dist/assets/{_workspaceName_-DO9ZBx7N.js → _workspaceName_-D0z9E9Uy.js} +1 -1
  8. package/dist/assets/{about-B1_n4Iu8.js → about-pl0DXTEt.js} +1 -1
  9. package/dist/assets/{add-BnwWcDlO.js → add-B30V-yHb.js} +1 -1
  10. package/dist/assets/{agents-DquOfkFX.js → agents-Bc7_wscP.js} +1 -1
  11. package/dist/assets/{appearance-C2vu3ALt.js → appearance-DLo_2WH0.js} +1 -1
  12. package/dist/assets/{apps-BZrw8Cqo.js → apps-DzFFo5D0.js} +1 -1
  13. package/dist/assets/{content-app-view-C33Ip_rx.js → content-app-view-BUi8HG1r.js} +1 -1
  14. package/dist/assets/{home-pS7q4Wl4.js → home-C5IxNq_5.js} +1 -1
  15. package/dist/assets/index-D7EoeBID.css +2 -0
  16. package/dist/assets/{index-exXolIqD.js → index-DtZS4JJ4.js} +3 -3
  17. package/dist/assets/{key-bindings-BOtykyXR.js → key-bindings-DomR6ZNC.js} +1 -1
  18. package/dist/assets/{registry-6tE_1KPV.js → registry-BgnkvPjl.js} +2 -2
  19. package/dist/assets/settings-B4LC1yCH.js +1 -0
  20. package/dist/assets/{settings-Du8r1SXC.js → settings-BXOyceZ3.js} +1 -1
  21. package/dist/assets/{settings-Cc6OMCOX.js → settings-CUzf6xEQ.js} +3 -3
  22. package/dist/assets/{settings-vosK_LI-.js → settings-DhoHM9AU.js} +1 -1
  23. package/dist/assets/{share-target-Df10J5JB.js → share-target-CpjVaYVl.js} +1 -1
  24. package/dist/assets/{shared-C7b3QOUP.js → shared-B824Ibpc.js} +1 -1
  25. package/dist/assets/{useAgentModels-DI41aFY3.js → useAgentModels-ndLotMWH.js} +1 -1
  26. package/dist/assets/workspaces-BBgdfAM_.js +1 -0
  27. package/dist/index.html +3 -3
  28. package/dist/sw.js +1 -1
  29. package/package.json +2 -2
  30. package/dist/assets/LensApplet-DNTGwgZs.js +0 -1
  31. package/dist/assets/_agentId_-Ci4j4UYy.js +0 -0
  32. package/dist/assets/index-C10UNpew.css +0 -2
  33. package/dist/assets/settings-D7K7z_JD.js +0 -1
  34. package/dist/assets/workspaces-C9Wtka2V.js +0 -1
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{t as r}from"./socket-CtH3EU9m.js";import{r as i}from"./use-toolbox-Ck_cLGgf.js";import{n as a}from"./use-applet-target-mkjQujx6.js";import{A as o,_ as s,x as c}from"./index-exXolIqD.js";var l=e(n(),1),u=t();function d(){let e=a(),t=i()?.state,n=!!t&&(e?.mode===`context`?t.activeContextType===`context`&&t.activeContextId===e.contextId:e?.mode===`workspace`?t.activeContextType!==`context`&&t.activeWorkspaceName===e.workspaceName&&t.activeTreeName===e.treeName&&t.activeContextPath===e.path:!t.activeWorkspaceName&&!t.activeContextId),d=!n&&e?.mode===`context`?e.contextId:null;return(0,l.useEffect)(()=>{if(!d)return;let e=`context:${d}`,t=()=>r.emit(`subscribe`,{channel:e}),n=r.on(`connect`,t);return t(),()=>{n(),r.emit(`unsubscribe`,{channel:e})}},[d]),n?(0,u.jsx)(s,{}):(0,u.jsx)(o,{target:e,children:(0,u.jsx)(c,{children:(0,u.jsx)(s,{})})})}export{d as FiltersApplet};
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"./socket-CtH3EU9m.js";import{r as i}from"./use-toolbox-Ck_cLGgf.js";import{n as a}from"./use-applet-target-mkjQujx6.js";import{S as o,j as s,v as c}from"./index-DtZS4JJ4.js";var l=e(n(),1),u=t();function d(){let e=a(),t=i()?.state,n=!!t&&(e?.mode===`context`?t.activeContextType===`context`&&t.activeContextId===e.contextId:e?.mode===`workspace`?t.activeContextType!==`context`&&t.activeWorkspaceName===e.workspaceName&&t.activeTreeName===e.treeName&&t.activeContextPath===e.path:!t.activeWorkspaceName&&!t.activeContextId),d=!n&&e?.mode===`context`?e.contextId:null;return(0,l.useEffect)(()=>{if(!d)return;let e=`context:${d}`,t=()=>r.emit(`subscribe`,{channel:e}),n=r.on(`connect`,t);return t(),()=>{n(),r.emit(`unsubscribe`,{channel:e})}},[d]),n?(0,u.jsx)(c,{}):(0,u.jsx)(s,{target:e,children:(0,u.jsx)(o,{children:(0,u.jsx)(c,{})})})}export{d as FiltersApplet};
@@ -1,3 +1,3 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{yt as r}from"./react-BHzhHVTZ.js";import{g as i}from"./chunk-62JRHF6Z-vspAGgtK.js";import{L as a,Mt as o,U as s,Ur as c,W as l,hn as u,pn as d,rr as f,tt as p}from"./ui-BSqPn1LJ.js";import{t as m}from"./utils-2pl1SbIp.js";import{t as h}from"./input-BOtCd4HP.js";import{t as g}from"./label-CNoJOoe0.js";import{t as _}from"./LinkToCard-BZwwE-Dv.js";import{Vt as v}from"./workspace-CJ1PWQ29.js";import{t as y}from"./use-mobile-Db-vWu9Y.js";import{a as b,i as x,s as S,t as ee}from"./IdentityFields-C2MPM-Ab.js";import{n as C,r as te}from"./use-toolbox-Ck_cLGgf.js";import{c as ne}from"./date-time-picker-BZaA3M9_.js";import{n as w,t as re}from"./PickDocumentsCard-BlicxMqC.js";import{t as T}from"./useToastHelpers-CRrpIIdY.js";import{r as E,t as D}from"./note-save-status-DPz4VzL6.js";import{t as O}from"./DocumentBodyEditor-CE2S2X6g.js";import{a as k,i as A,n as j,o as M,r as N,s as P,t as F}from"./UploadProgressList-B2xCVzFR.js";import{D as I,E as L,O as R,k as z}from"./index-exXolIqD.js";var B=e(r(),1),V=e(n(),1),H=t();function U({onClose:e,initialData:t,draftId:n}){let r=I(void 0,void 0,`home-card:${n}`);return(0,V.useEffect)(()=>{t?.title&&r.setTitle(t.title),t?.content&&r.setContent(t.content)},[]),(0,H.jsx)(w,{title:`New Note`,icon:p,onClose:e,onSave:async e=>{let t=await r.save({mode:`workspace`,...e});return r.finish(),t},canSave:r.canSave,saving:r.saving,successMessage:`Note created`,children:(0,H.jsxs)(`div`,{className:`flex h-full flex-col gap-4 p-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-note-title`,children:`Title`}),(0,H.jsx)(h,{id:`qa-note-title`,value:r.title,onChange:e=>r.setTitle(e.target.value),placeholder:`Optional; defaults to today's date`})]}),(0,H.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1.5`,children:[(0,H.jsx)(g,{children:`Body`}),(0,H.jsx)(`div`,{className:`flex-1`,children:(0,H.jsx)(O,{kind:`markdown`,value:r.content,onChange:r.setContent,placeholder:`Write your note…`})})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:r.tags,onChange:r.setTags})]}),(0,H.jsx)(D,{...r,onRetry:r.retry}),(0,H.jsx)(P,{geotag:r.geotag,idPrefix:`qa-note-geotag`})]})})}function W({onClose:e,initialData:t}){let n=L();return(0,V.useEffect)(()=>{t?.url&&n.setUrl(t.url),t?.title&&n.setTitle(t.title)},[]),(0,H.jsx)(w,{title:`New Link`,icon:u,onClose:e,onSave:e=>n.save({mode:`workspace`,...e}),canSave:n.canSave,saving:n.saving,successMessage:`Link created`,children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-link-url`,children:`URL`}),(0,H.jsx)(h,{id:`qa-link-url`,value:n.url,onChange:e=>n.setUrl(e.target.value),placeholder:`https://example.com`,autoFocus:!0}),n.showUrlError&&(0,H.jsx)(`p`,{className:`text-xs text-destructive`,children:`Enter a valid URL, e.g. https://example.com`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-link-title`,children:`Title`}),(0,H.jsx)(h,{id:`qa-link-title`,value:n.title,onChange:e=>n.setTitle(e.target.value),placeholder:`Optional display title`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:n.tags,onChange:n.setTags})]}),(0,H.jsx)(P,{geotag:n.geotag,idPrefix:`qa-link-geotag`})]})})}function G({onClose:e,initialData:t}){let n=ne();return(0,V.useEffect)(()=>{t?.title&&n.setTitle(t.title),t?.content&&n.setDescription(t.content)},[]),(0,H.jsx)(w,{title:`New Todo`,icon:d,onClose:e,onSave:e=>n.save({mode:`workspace`,...e}),canSave:n.canSave,saving:n.saving,successMessage:`Todo created`,children:(0,H.jsxs)(`div`,{className:`flex h-full flex-col gap-4 p-4`,children:[(0,H.jsx)(b,{...n,idPrefix:`qa-todo`}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:n.tags,onChange:n.setTags})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-todo-comment`,children:`Comment`}),(0,H.jsx)(`textarea`,{id:`qa-todo-comment`,value:n.comment,onChange:e=>n.setComment(e.target.value),rows:3,placeholder:`Optional context`,className:`flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-elevation-1 transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`})]}),(0,H.jsx)(P,{geotag:n.geotag,idPrefix:`qa-todo-geotag`})]})})}function K({onClose:e,initialData:t}){let n=x();return(0,V.useEffect)(()=>{t?.title&&n.setDisplayName(t.title)},[]),(0,H.jsx)(w,{title:`New Identity`,icon:s,onClose:e,onSave:e=>n.save({mode:`workspace`,...e}),canSave:n.canSave,saving:n.saving,successMessage:`Identity created`,children:(0,H.jsxs)(`div`,{className:`flex h-full flex-col gap-4 p-4`,children:[(0,H.jsx)(ee,{idPrefix:`qa-identity`,...n,emailValid:n.emailValid}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:n.tags,onChange:n.setTags})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-identity-comment`,children:`Comment`}),(0,H.jsx)(`textarea`,{id:`qa-identity-comment`,value:n.comment,onChange:e=>n.setComment(e.target.value),rows:3,placeholder:`How you know them, where they came from…`,className:`flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-elevation-1 transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`})]})]})})}var q={jpg:`image/jpeg`,jpeg:`image/jpeg`,png:`image/png`,gif:`image/gif`,webp:`image/webp`,avif:`image/avif`,heic:`image/heic`,heif:`image/heif`,bmp:`image/bmp`,tif:`image/tiff`,tiff:`image/tiff`,svg:`image/svg+xml`,mp4:`video/mp4`,mov:`video/quicktime`,webm:`video/webm`,"3gp":`video/3gpp`};function J(e){return/^(image|video)\//.test(e.type)}async function Y(e){let t=await Promise.all(e.map(async e=>{let t=new Uint8Array(await e.slice(0,64).arrayBuffer()),n=(e,n)=>String.fromCharCode(...t.slice(e,e+n)),r=``;if(t[0]===255&&t[1]===216&&t[2]===255)r=`image/jpeg`;else if(n(0,8)===`‰PNG\r
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{yt as r}from"./react-BHzhHVTZ.js";import{g as i}from"./chunk-62JRHF6Z-vspAGgtK.js";import{L as a,Mt as o,U as s,Ur as c,W as l,hn as u,pn as d,rr as f,tt as p}from"./ui-BSqPn1LJ.js";import{t as m}from"./utils-2pl1SbIp.js";import{t as h}from"./input-BOtCd4HP.js";import{t as g}from"./label-CNoJOoe0.js";import{t as _}from"./LinkToCard-BZwwE-Dv.js";import{Vt as v}from"./workspace-CJ1PWQ29.js";import{t as y}from"./use-mobile-Db-vWu9Y.js";import{a as b,i as x,s as S,t as ee}from"./IdentityFields-C2MPM-Ab.js";import{n as C,r as te}from"./use-toolbox-Ck_cLGgf.js";import{c as ne}from"./date-time-picker-BZaA3M9_.js";import{n as w,t as re}from"./PickDocumentsCard-BlicxMqC.js";import{t as T}from"./useToastHelpers-CRrpIIdY.js";import{r as E,t as D}from"./note-save-status-DPz4VzL6.js";import{t as O}from"./DocumentBodyEditor-CE2S2X6g.js";import{a as k,i as A,n as j,o as M,r as N,s as P,t as F}from"./UploadProgressList-B2xCVzFR.js";import{A as I,D as L,O as R,k as z}from"./index-DtZS4JJ4.js";var B=e(r(),1),V=e(n(),1),H=t();function U({onClose:e,initialData:t,draftId:n}){let r=R(void 0,void 0,`home-card:${n}`);return(0,V.useEffect)(()=>{t?.title&&r.setTitle(t.title),t?.content&&r.setContent(t.content)},[]),(0,H.jsx)(w,{title:`New Note`,icon:p,onClose:e,onSave:async e=>{let t=await r.save({mode:`workspace`,...e});return r.finish(),t},canSave:r.canSave,saving:r.saving,successMessage:`Note created`,children:(0,H.jsxs)(`div`,{className:`flex h-full flex-col gap-4 p-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-note-title`,children:`Title`}),(0,H.jsx)(h,{id:`qa-note-title`,value:r.title,onChange:e=>r.setTitle(e.target.value),placeholder:`Optional; defaults to today's date`})]}),(0,H.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1.5`,children:[(0,H.jsx)(g,{children:`Body`}),(0,H.jsx)(`div`,{className:`flex-1`,children:(0,H.jsx)(O,{kind:`markdown`,value:r.content,onChange:r.setContent,placeholder:`Write your note…`})})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:r.tags,onChange:r.setTags})]}),(0,H.jsx)(D,{...r,onRetry:r.retry}),(0,H.jsx)(P,{geotag:r.geotag,idPrefix:`qa-note-geotag`})]})})}function W({onClose:e,initialData:t}){let n=L();return(0,V.useEffect)(()=>{t?.url&&n.setUrl(t.url),t?.title&&n.setTitle(t.title)},[]),(0,H.jsx)(w,{title:`New Link`,icon:u,onClose:e,onSave:e=>n.save({mode:`workspace`,...e}),canSave:n.canSave,saving:n.saving,successMessage:`Link created`,children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-link-url`,children:`URL`}),(0,H.jsx)(h,{id:`qa-link-url`,value:n.url,onChange:e=>n.setUrl(e.target.value),placeholder:`https://example.com`,autoFocus:!0}),n.showUrlError&&(0,H.jsx)(`p`,{className:`text-xs text-destructive`,children:`Enter a valid URL, e.g. https://example.com`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-link-title`,children:`Title`}),(0,H.jsx)(h,{id:`qa-link-title`,value:n.title,onChange:e=>n.setTitle(e.target.value),placeholder:`Optional display title`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:n.tags,onChange:n.setTags})]}),(0,H.jsx)(P,{geotag:n.geotag,idPrefix:`qa-link-geotag`})]})})}function G({onClose:e,initialData:t}){let n=ne();return(0,V.useEffect)(()=>{t?.title&&n.setTitle(t.title),t?.content&&n.setDescription(t.content)},[]),(0,H.jsx)(w,{title:`New Todo`,icon:d,onClose:e,onSave:e=>n.save({mode:`workspace`,...e}),canSave:n.canSave,saving:n.saving,successMessage:`Todo created`,children:(0,H.jsxs)(`div`,{className:`flex h-full flex-col gap-4 p-4`,children:[(0,H.jsx)(b,{...n,idPrefix:`qa-todo`}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:n.tags,onChange:n.setTags})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-todo-comment`,children:`Comment`}),(0,H.jsx)(`textarea`,{id:`qa-todo-comment`,value:n.comment,onChange:e=>n.setComment(e.target.value),rows:3,placeholder:`Optional context`,className:`flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-elevation-1 transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`})]}),(0,H.jsx)(P,{geotag:n.geotag,idPrefix:`qa-todo-geotag`})]})})}function K({onClose:e,initialData:t}){let n=x();return(0,V.useEffect)(()=>{t?.title&&n.setDisplayName(t.title)},[]),(0,H.jsx)(w,{title:`New Identity`,icon:s,onClose:e,onSave:e=>n.save({mode:`workspace`,...e}),canSave:n.canSave,saving:n.saving,successMessage:`Identity created`,children:(0,H.jsxs)(`div`,{className:`flex h-full flex-col gap-4 p-4`,children:[(0,H.jsx)(ee,{idPrefix:`qa-identity`,...n,emailValid:n.emailValid}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{children:`Tags`}),(0,H.jsx)(S,{tags:n.tags,onChange:n.setTags})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(g,{htmlFor:`qa-identity-comment`,children:`Comment`}),(0,H.jsx)(`textarea`,{id:`qa-identity-comment`,value:n.comment,onChange:e=>n.setComment(e.target.value),rows:3,placeholder:`How you know them, where they came from…`,className:`flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-elevation-1 transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`})]})]})})}var q={jpg:`image/jpeg`,jpeg:`image/jpeg`,png:`image/png`,gif:`image/gif`,webp:`image/webp`,avif:`image/avif`,heic:`image/heic`,heif:`image/heif`,bmp:`image/bmp`,tif:`image/tiff`,tiff:`image/tiff`,svg:`image/svg+xml`,mp4:`video/mp4`,mov:`video/quicktime`,webm:`video/webm`,"3gp":`video/3gpp`};function J(e){return/^(image|video)\//.test(e.type)}async function Y(e){let t=await Promise.all(e.map(async e=>{let t=new Uint8Array(await e.slice(0,64).arrayBuffer()),n=(e,n)=>String.fromCharCode(...t.slice(e,e+n)),r=``;if(t[0]===255&&t[1]===216&&t[2]===255)r=`image/jpeg`;else if(n(0,8)===`‰PNG\r
2
2
  
3
- `)r=`image/png`;else if([`GIF87a`,`GIF89a`].includes(n(0,6)))r=`image/gif`;else if(n(0,4)===`RIFF`&&n(8,4)===`WEBP`)r=`image/webp`;else if(n(0,5)===`%PDF-`)r=`application/pdf`;else if(n(0,4)===`PK`)r=`application/zip`;else if(n(4,4)===`ftyp`){let e=[n(8,4)],i=new DataView(t.buffer).getUint32(0);for(let r=16;r+4<=Math.min(t.length,i);r+=4)e.push(n(r,4));e.some(e=>[`avif`,`avis`].includes(e))?r=`image/avif`:e.some(e=>[`heic`,`heix`,`hevc`,`hevx`].includes(e))?r=`image/heic`:e.some(e=>[`mif1`,`msf1`].includes(e))?r=`image/heif`:e.includes(`qt `)?r=`video/quicktime`:e.some(e=>[`isom`,`iso2`,`mp41`,`mp42`,`avc1`,`M4V `].includes(e))&&(r=`video/mp4`)}let i=e.type.toLowerCase().split(`;`)[0].trim(),a=!i||[`application/octet-stream`,`binary/octet-stream`,`*/*`].includes(i),o=e.name.split(`.`).pop()?.toLowerCase()??``,s=r||a&&q[o]||i;return s===e.type?e:new File([e],e.name,{type:s,lastModified:e.lastModified})}));return{kind:t.length>0&&t.every(J)?`photo`:`file`,files:t}}function X({file:e}){let t=(0,V.useRef)(null),[n,r]=(0,V.useState)(!1);return(0,V.useEffect)(()=>{let n=t.current;if(!n)return;let r=URL.createObjectURL(e);return n.src=r,()=>{n.removeAttribute(`src`),URL.revokeObjectURL(r)}},[e]),(0,H.jsx)(`div`,{className:`flex min-h-24 items-center justify-center overflow-hidden rounded-md border border-input bg-muted/30`,children:n?(0,H.jsxs)(`p`,{className:`p-4 text-center text-sm text-muted-foreground`,children:[`Preview unavailable for `,e.name,`. You can still save the original.`]}):e.type.startsWith(`video/`)?(0,H.jsx)(`video`,{ref:t,controls:!0,preload:`metadata`,"aria-label":e.name,onError:()=>r(!0),className:`max-h-64 max-w-full`}):(0,H.jsx)(`img`,{ref:t,alt:e.name,onError:()=>r(!0),className:`max-h-64 max-w-full object-contain`})})}function ie({onClose:e,initialData:t}){let n=(0,V.useRef)(null),r=N(t?.files),i=r.items.map(e=>e.file),[a,o]=(0,V.useState)(!1),[s,c]=(0,V.useState)(!1),{state:u}=C(),d=M(u.activeWorkspaceName),f=e=>{e&&(s||r.addFiles(Array.from(e)))},p=e=>{e.preventDefault(),o(!1),f(e.dataTransfer.files)},h=i.length>0;return(0,H.jsx)(w,{title:`Upload File`,icon:l,onClose:e,onSave:async e=>{c(!0);try{let t={mode:`workspace`,...e},n=await d.geotag.capture(),i=await r.start(t,(e,t)=>k(e,t,{tags:d.tags,comment:d.comment,geo:n}));if(i.failed)throw Error(`${i.failed} file(s) failed or cancelled. Retry keeps completed uploads.`);return i.docIds}finally{c(!1)}},navigateAfterSave:!0,canSave:h,saving:s,saveProgress:(0,H.jsx)(j,{items:r.items,running:r.running,onCancel:r.cancel}),successMessage:`File(s) uploaded`,children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,H.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:()=>o(!1),onDrop:p,onClick:()=>n.current?.click(),className:m(`flex cursor-pointer flex-col items-center justify-center gap-2 rounded-md border border-dashed px-4 py-8 text-center transition-colors`,a?`border-primary bg-primary/5`:`border-input hover:bg-muted/40`),children:[(0,H.jsx)(l,{className:`h-6 w-6 text-muted-foreground touch-target`}),(0,H.jsx)(`p`,{className:`text-sm`,children:`Drag & drop files here`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`or click to browse`}),(0,H.jsx)(`input`,{ref:n,type:`file`,multiple:!0,disabled:s,className:`hidden`,onChange:e=>{f(e.target.files),e.target.value=``}})]}),r.items.filter(e=>J(e.file)).map(e=>(0,H.jsx)(X,{file:e.file},e.id)),(0,H.jsx)(F,{items:r.items,running:s,onRemove:r.removeItem}),(0,H.jsx)(A,{fields:d,idPrefix:`qa-file`,multiple:i.length>1})]})})}function ae({onClose:e,initialData:t}){let n=N(t?.files),r=(0,V.useRef)(null),i=n.items.length>0,[o,s]=(0,V.useState)(!1),{state:l}=C(),u=M(l.activeWorkspaceName),d=e=>{!o&&e&&n.addFiles([e])};return(0,H.jsx)(w,{title:`Photo/Video`,icon:c,onClose:e,onSave:async e=>{if(!i)return[];s(!0);try{let t=await u.geotag.capture(),r={mode:`workspace`,...e},i=await n.start(r,(e,n)=>k(e,n,{tags:u.tags,comment:u.comment,geo:t}));if(i.failed)throw Error(`Upload failed or cancelled. You can retry.`);return i.docIds}finally{s(!1)}},navigateAfterSave:!0,canSave:i,saving:o,saveProgress:(0,H.jsx)(j,{items:n.items,running:n.running,onCancel:n.cancel}),successMessage:`Upload saved`,children:(0,H.jsxs)(`div`,{className:m(`flex h-full flex-col gap-4 p-4`,!i&&`items-center justify-center`),children:[i?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:`flex min-h-0 w-full flex-1 flex-col gap-3 overflow-y-auto`,children:n.items.map(({id:e,file:t,status:r})=>(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(X,{file:t}),(0,H.jsxs)(`div`,{className:`flex w-full items-center gap-2 rounded border border-input px-3 py-2 text-sm`,children:[(0,H.jsx)(f,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,H.jsx)(`span`,{className:`flex-1 truncate`,children:t.name}),(0,H.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[(t.size/1024/1024).toFixed(1),` MB`]}),(0,H.jsx)(`button`,{type:`button`,disabled:o||r===`done`,onClick:()=>n.removeItem(e),"aria-label":`Remove ${t.name}`,className:`text-muted-foreground hover:text-foreground disabled:opacity-40`,children:(0,H.jsx)(a,{className:`h-3.5 w-3.5`})})]})]},e))}),(0,H.jsx)(`div`,{className:`w-full shrink-0 space-y-4`,children:(0,H.jsx)(A,{fields:u,idPrefix:`qa-photo`,multiple:n.items.length>1})})]}):(0,H.jsxs)(`button`,{type:`button`,onClick:()=>r.current?.click(),className:`flex flex-col items-center gap-2 rounded-md border border-dashed border-input px-6 py-10 text-center transition-colors hover:bg-muted/40`,children:[(0,H.jsx)(c,{className:`h-8 w-8 text-muted-foreground`}),(0,H.jsx)(`span`,{className:`text-sm`,children:`Open camera`})]}),(0,H.jsx)(`input`,{ref:r,type:`file`,accept:`image/*,video/*`,capture:`environment`,className:`hidden`,disabled:o,onChange:e=>{d(e.target.files?.[0]??null),e.target.value=``}})]})})}var Z=`shrink-0 h-viewport-card w-[min(380px,90vw)] max-md:fixed max-md:inset-2 max-md:z-40 max-md:h-auto max-md:w-auto max-md:shadow-elevation-5`;function oe({onClose:e}){let{showSuccessToast:t,showErrorToast:n}=T(),[r,i]=(0,V.useState)(null),[a,o]=(0,V.useState)(!1);return r?(0,H.jsx)(_,{sizeClassName:Z,documentCount:r.length,saving:a,onClose:e,onConfirm:async(i,a)=>{o(!0);try{await Promise.all(i.map(e=>v(a.workspaceName,e,r,a.treeName,a.treeType))),t(`${r.length} document${r.length===1?``:`s`} linked`),e()}catch(e){n(e instanceof Error?e.message:`Failed to link documents`)}finally{o(!1)}}}):(0,H.jsx)(re,{sizeClassName:Z,onConfirm:e=>{e.length&&i(e)},onClose:e})}function Q(){let e=E(`new:home-card:`);try{return Object.keys(localStorage).filter(t=>t.startsWith(e)&&t.endsWith(`:home`)).filter(e=>{let t=JSON.parse(localStorage.getItem(e)||`null`)?.value;return t&&(t.title||t.content||t.comment||t.tags?.length)}).map(t=>t.slice(e.length,-5))}catch{return[]}}var $=0;function se(){return $+=1,`card-${$}`}function ce({initialKind:e,initialData:t,onInitialCardClose:n,onCardsOpenChange:r}){let[s,c]=(0,V.useState)(!1),l=y(),u=te(),d=!!(u?.state.t1Open||u?.state.addOpen),[f,p]=(0,V.useState)(()=>e?[{id:`initial`,kind:e,initialData:t,noteDraftId:crypto.randomUUID()}]:Q().map(e=>({id:e,kind:`note`,noteDraftId:e}))),h=f.length>0,g=(0,V.useRef)(r);(0,V.useEffect)(()=>{g.current=r},[r]),(0,V.useEffect)(()=>{g.current?.(h)},[h]),d&&s&&c(!1);let _=i(),v=e=>{if(e===`sketch`){c(!1),_(z.createUrl(null));return}let t=e===`note`?Q().find(e=>!f.some(t=>t.noteDraftId===e))||crypto.randomUUID():void 0;p(n=>[...n,{id:se(),kind:e,noteDraftId:t}]),c(!1)},b=e=>{p(t=>t.filter(t=>t.id!==e)),e===`initial`&&n?.()},x=(0,H.jsxs)(`div`,{className:m(`pointer-events-none fixed right-6 z-40 flex flex-col items-end gap-2`,`bottom-fab-inset md:bottom-[calc(var(--spacing-fab-inset)+5rem)]`,f.length>0&&`max-md:hidden`,d&&`hidden`),children:[(0,H.jsx)(`div`,{className:m(`flex flex-col items-end gap-2 transition-all duration-fast`,s?`pointer-events-auto opacity-100`:`pointer-events-none translate-y-2 opacity-0`),children:(0,H.jsx)(R,{variant:`stack`,omit:[`plaintext`,`folder`,`message`],onSelect:v})}),(0,H.jsx)(`div`,{className:`pointer-events-none flex w-16 justify-center`,children:(0,H.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),"aria-label":s?`Close quick add`:`Quick add`,className:`pointer-events-auto flex h-11 w-11 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-elevation-3 transition-transform hover:scale-105`,children:s?(0,H.jsx)(a,{className:`h-5 w-5`}):(0,H.jsx)(o,{className:`h-5 w-5`})})})]});return(0,H.jsxs)(`div`,{className:`relative flex h-full w-full flex-col`,children:[f.length>0&&(0,H.jsx)(`div`,{className:`pointer-events-auto flex flex-1 items-center gap-4 overflow-x-auto p-6 md:pr-28`,children:f.map(e=>{let t=()=>b(e.id);switch(e.kind){case`note`:return(0,H.jsx)(U,{draftId:e.noteDraftId,onClose:t,initialData:e.initialData},e.id);case`link`:return(0,H.jsx)(W,{onClose:t,initialData:e.initialData},e.id);case`todo`:return(0,H.jsx)(G,{onClose:t,initialData:e.initialData},e.id);case`identity`:return(0,H.jsx)(K,{onClose:t,initialData:e.initialData},e.id);case`file`:return(0,H.jsx)(ie,{onClose:t,initialData:e.initialData},e.id);case`photo`:return(0,H.jsx)(ae,{onClose:t,initialData:e.initialData},e.id);case`existing`:return(0,H.jsx)(oe,{onClose:t},e.id);case`sketch`:return null;case`folder`:case`message`:return null}})}),l?(0,B.createPortal)(x,document.body):x]})}export{Y as n,ce as t};
3
+ `)r=`image/png`;else if([`GIF87a`,`GIF89a`].includes(n(0,6)))r=`image/gif`;else if(n(0,4)===`RIFF`&&n(8,4)===`WEBP`)r=`image/webp`;else if(n(0,5)===`%PDF-`)r=`application/pdf`;else if(n(0,4)===`PK`)r=`application/zip`;else if(n(4,4)===`ftyp`){let e=[n(8,4)],i=new DataView(t.buffer).getUint32(0);for(let r=16;r+4<=Math.min(t.length,i);r+=4)e.push(n(r,4));e.some(e=>[`avif`,`avis`].includes(e))?r=`image/avif`:e.some(e=>[`heic`,`heix`,`hevc`,`hevx`].includes(e))?r=`image/heic`:e.some(e=>[`mif1`,`msf1`].includes(e))?r=`image/heif`:e.includes(`qt `)?r=`video/quicktime`:e.some(e=>[`isom`,`iso2`,`mp41`,`mp42`,`avc1`,`M4V `].includes(e))&&(r=`video/mp4`)}let i=e.type.toLowerCase().split(`;`)[0].trim(),a=!i||[`application/octet-stream`,`binary/octet-stream`,`*/*`].includes(i),o=e.name.split(`.`).pop()?.toLowerCase()??``,s=r||a&&q[o]||i;return s===e.type?e:new File([e],e.name,{type:s,lastModified:e.lastModified})}));return{kind:t.length>0&&t.every(J)?`photo`:`file`,files:t}}function X({file:e}){let t=(0,V.useRef)(null),[n,r]=(0,V.useState)(!1);return(0,V.useEffect)(()=>{let n=t.current;if(!n)return;let r=URL.createObjectURL(e);return n.src=r,()=>{n.removeAttribute(`src`),URL.revokeObjectURL(r)}},[e]),(0,H.jsx)(`div`,{className:`flex min-h-24 items-center justify-center overflow-hidden rounded-md border border-input bg-muted/30`,children:n?(0,H.jsxs)(`p`,{className:`p-4 text-center text-sm text-muted-foreground`,children:[`Preview unavailable for `,e.name,`. You can still save the original.`]}):e.type.startsWith(`video/`)?(0,H.jsx)(`video`,{ref:t,controls:!0,preload:`metadata`,"aria-label":e.name,onError:()=>r(!0),className:`max-h-64 max-w-full`}):(0,H.jsx)(`img`,{ref:t,alt:e.name,onError:()=>r(!0),className:`max-h-64 max-w-full object-contain`})})}function ie({onClose:e,initialData:t}){let n=(0,V.useRef)(null),r=N(t?.files),i=r.items.map(e=>e.file),[a,o]=(0,V.useState)(!1),[s,c]=(0,V.useState)(!1),{state:u}=C(),d=M(u.activeWorkspaceName),f=e=>{e&&(s||r.addFiles(Array.from(e)))},p=e=>{e.preventDefault(),o(!1),f(e.dataTransfer.files)},h=i.length>0;return(0,H.jsx)(w,{title:`Upload File`,icon:l,onClose:e,onSave:async e=>{c(!0);try{let t={mode:`workspace`,...e},n=await d.geotag.capture(),i=await r.start(t,(e,t)=>k(e,t,{tags:d.tags,comment:d.comment,geo:n}));if(i.failed)throw Error(`${i.failed} file(s) failed or cancelled. Retry keeps completed uploads.`);return i.docIds}finally{c(!1)}},navigateAfterSave:!0,canSave:h,saving:s,saveProgress:(0,H.jsx)(j,{items:r.items,running:r.running,onCancel:r.cancel}),successMessage:`File(s) uploaded`,children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,H.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:()=>o(!1),onDrop:p,onClick:()=>n.current?.click(),className:m(`flex cursor-pointer flex-col items-center justify-center gap-2 rounded-md border border-dashed px-4 py-8 text-center transition-colors`,a?`border-primary bg-primary/5`:`border-input hover:bg-muted/40`),children:[(0,H.jsx)(l,{className:`h-6 w-6 text-muted-foreground touch-target`}),(0,H.jsx)(`p`,{className:`text-sm`,children:`Drag & drop files here`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`or click to browse`}),(0,H.jsx)(`input`,{ref:n,type:`file`,multiple:!0,disabled:s,className:`hidden`,onChange:e=>{f(e.target.files),e.target.value=``}})]}),r.items.filter(e=>J(e.file)).map(e=>(0,H.jsx)(X,{file:e.file},e.id)),(0,H.jsx)(F,{items:r.items,running:s,onRemove:r.removeItem}),(0,H.jsx)(A,{fields:d,idPrefix:`qa-file`,multiple:i.length>1})]})})}function ae({onClose:e,initialData:t}){let n=N(t?.files),r=(0,V.useRef)(null),i=n.items.length>0,[o,s]=(0,V.useState)(!1),{state:l}=C(),u=M(l.activeWorkspaceName),d=e=>{!o&&e&&n.addFiles([e])};return(0,H.jsx)(w,{title:`Photo/Video`,icon:c,onClose:e,onSave:async e=>{if(!i)return[];s(!0);try{let t=await u.geotag.capture(),r={mode:`workspace`,...e},i=await n.start(r,(e,n)=>k(e,n,{tags:u.tags,comment:u.comment,geo:t}));if(i.failed)throw Error(`Upload failed or cancelled. You can retry.`);return i.docIds}finally{s(!1)}},navigateAfterSave:!0,canSave:i,saving:o,saveProgress:(0,H.jsx)(j,{items:n.items,running:n.running,onCancel:n.cancel}),successMessage:`Upload saved`,children:(0,H.jsxs)(`div`,{className:m(`flex h-full flex-col gap-4 p-4`,!i&&`items-center justify-center`),children:[i?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:`flex min-h-0 w-full flex-1 flex-col gap-3 overflow-y-auto`,children:n.items.map(({id:e,file:t,status:r})=>(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(X,{file:t}),(0,H.jsxs)(`div`,{className:`flex w-full items-center gap-2 rounded border border-input px-3 py-2 text-sm`,children:[(0,H.jsx)(f,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,H.jsx)(`span`,{className:`flex-1 truncate`,children:t.name}),(0,H.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[(t.size/1024/1024).toFixed(1),` MB`]}),(0,H.jsx)(`button`,{type:`button`,disabled:o||r===`done`,onClick:()=>n.removeItem(e),"aria-label":`Remove ${t.name}`,className:`text-muted-foreground hover:text-foreground disabled:opacity-40`,children:(0,H.jsx)(a,{className:`h-3.5 w-3.5`})})]})]},e))}),(0,H.jsx)(`div`,{className:`w-full shrink-0 space-y-4`,children:(0,H.jsx)(A,{fields:u,idPrefix:`qa-photo`,multiple:n.items.length>1})})]}):(0,H.jsxs)(`button`,{type:`button`,onClick:()=>r.current?.click(),className:`flex flex-col items-center gap-2 rounded-md border border-dashed border-input px-6 py-10 text-center transition-colors hover:bg-muted/40`,children:[(0,H.jsx)(c,{className:`h-8 w-8 text-muted-foreground`}),(0,H.jsx)(`span`,{className:`text-sm`,children:`Open camera`})]}),(0,H.jsx)(`input`,{ref:r,type:`file`,accept:`image/*,video/*`,capture:`environment`,className:`hidden`,disabled:o,onChange:e=>{d(e.target.files?.[0]??null),e.target.value=``}})]})})}var Z=`shrink-0 h-viewport-card w-[min(380px,90vw)] max-md:fixed max-md:inset-2 max-md:z-40 max-md:h-auto max-md:w-auto max-md:shadow-elevation-5`;function oe({onClose:e}){let{showSuccessToast:t,showErrorToast:n}=T(),[r,i]=(0,V.useState)(null),[a,o]=(0,V.useState)(!1);return r?(0,H.jsx)(_,{sizeClassName:Z,documentCount:r.length,saving:a,onClose:e,onConfirm:async(i,a)=>{o(!0);try{await Promise.all(i.map(e=>v(a.workspaceName,e,r,a.treeName,a.treeType))),t(`${r.length} document${r.length===1?``:`s`} linked`),e()}catch(e){n(e instanceof Error?e.message:`Failed to link documents`)}finally{o(!1)}}}):(0,H.jsx)(re,{sizeClassName:Z,onConfirm:e=>{e.length&&i(e)},onClose:e})}function Q(){let e=E(`new:home-card:`);try{return Object.keys(localStorage).filter(t=>t.startsWith(e)&&t.endsWith(`:home`)).filter(e=>{let t=JSON.parse(localStorage.getItem(e)||`null`)?.value;return t&&(t.title||t.content||t.comment||t.tags?.length)}).map(t=>t.slice(e.length,-5))}catch{return[]}}var $=0;function se(){return $+=1,`card-${$}`}function ce({initialKind:e,initialData:t,onInitialCardClose:n,onCardsOpenChange:r}){let[s,c]=(0,V.useState)(!1),l=y(),u=te(),d=!!(u?.state.t1Open||u?.state.addOpen),[f,p]=(0,V.useState)(()=>e?[{id:`initial`,kind:e,initialData:t,noteDraftId:crypto.randomUUID()}]:Q().map(e=>({id:e,kind:`note`,noteDraftId:e}))),h=f.length>0,g=(0,V.useRef)(r);(0,V.useEffect)(()=>{g.current=r},[r]),(0,V.useEffect)(()=>{g.current?.(h)},[h]),d&&s&&c(!1);let _=i(),v=e=>{if(e===`sketch`){c(!1),_(I.createUrl(null));return}let t=e===`note`?Q().find(e=>!f.some(t=>t.noteDraftId===e))||crypto.randomUUID():void 0;p(n=>[...n,{id:se(),kind:e,noteDraftId:t}]),c(!1)},b=e=>{p(t=>t.filter(t=>t.id!==e)),e===`initial`&&n?.()},x=(0,H.jsxs)(`div`,{className:m(`pointer-events-none fixed right-6 z-40 flex flex-col items-end gap-2`,`bottom-fab-inset md:bottom-[calc(var(--spacing-fab-inset)+5rem)]`,f.length>0&&`max-md:hidden`,d&&`hidden`),children:[(0,H.jsx)(`div`,{className:m(`flex flex-col items-end gap-2 transition-all duration-fast`,s?`pointer-events-auto opacity-100`:`pointer-events-none translate-y-2 opacity-0`),children:(0,H.jsx)(z,{variant:`stack`,omit:[`plaintext`,`folder`,`message`],onSelect:v})}),(0,H.jsx)(`div`,{className:`pointer-events-none flex w-16 justify-center`,children:(0,H.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),"aria-label":s?`Close quick add`:`Quick add`,className:`pointer-events-auto flex h-11 w-11 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-elevation-3 transition-transform hover:scale-105`,children:s?(0,H.jsx)(a,{className:`h-5 w-5`}):(0,H.jsx)(o,{className:`h-5 w-5`})})})]});return(0,H.jsxs)(`div`,{className:`relative flex h-full w-full flex-col`,children:[f.length>0&&(0,H.jsx)(`div`,{className:`pointer-events-auto flex flex-1 items-center gap-4 overflow-x-auto p-6 md:pr-28`,children:f.map(e=>{let t=()=>b(e.id);switch(e.kind){case`note`:return(0,H.jsx)(U,{draftId:e.noteDraftId,onClose:t,initialData:e.initialData},e.id);case`link`:return(0,H.jsx)(W,{onClose:t,initialData:e.initialData},e.id);case`todo`:return(0,H.jsx)(G,{onClose:t,initialData:e.initialData},e.id);case`identity`:return(0,H.jsx)(K,{onClose:t,initialData:e.initialData},e.id);case`file`:return(0,H.jsx)(ie,{onClose:t,initialData:e.initialData},e.id);case`photo`:return(0,H.jsx)(ae,{onClose:t,initialData:e.initialData},e.id);case`existing`:return(0,H.jsx)(oe,{onClose:t},e.id);case`sketch`:return null;case`folder`:case`message`:return null}})}),l?(0,B.createPortal)(x,document.body):x]})}export{Y as n,ce as t};
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Jt as r,Ur as i,Zn as a,jr as o}from"./ui-BSqPn1LJ.js";import{t as s}from"./utils-2pl1SbIp.js";import{Ln as c,Pn as l}from"./workspace-CJ1PWQ29.js";import{t as u}from"./useDocumentThumbnail-C_rq2rXs.js";import{t as d}from"./DocumentIcon-BS10SIP6.js";import{n as f}from"./use-document-modal-PG8bQyIB.js";import{n as p}from"./use-applet-target-mkjQujx6.js";import{C as m,E as h,T as g,b as _,w as v,x as y,y as b}from"./index-DtZS4JJ4.js";var x=e(n(),1),S=t(),C=`h-8 rounded-md border border-input bg-transparent px-2 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring`,w=`h-8 rounded-md border border-input bg-transparent px-2 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`;function T({workspaceRef:e,doc:t,distance:n,onOpen:r}){let i=c(t),{blobUrl:a}=u(e,t.id,256,{enabled:i}),o=l(t);return(0,S.jsxs)(`button`,{type:`button`,onClick:()=>r(t),title:`Open ${o.title}`,className:`rounded-(--card-radius) border border-border bg-card overflow-hidden flex flex-col text-left cursor-pointer transition-colors hover:border-foreground/30 hover:bg-muted/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,S.jsx)(`div`,{className:`aspect-square bg-muted/40 flex items-center justify-center overflow-hidden`,children:i&&a?(0,S.jsx)(`img`,{src:a,alt:o.title,className:`h-full w-full object-cover`}):(0,S.jsx)(d,{document:t,size:10})}),(0,S.jsxs)(`div`,{className:`p-2 min-w-0`,children:[(0,S.jsx)(`div`,{className:`text-xs font-medium truncate`,title:o.title,children:o.title}),(0,S.jsxs)(`div`,{className:`text-[10px] text-muted-foreground truncate`,children:[o.schemaLabel,n==null?``:` · d=${n.toFixed(3)}`]})]})]})}function E(){let e=p(),t=f(),n=g(),{rateMs:c,setRateMs:l,text:u,setText:d,maxDistance:E,setMaxDistance:D,latencyMs:O,error:k}=n,A=e?.mode===`workspace`?e.workspaceName:``,j=e?.mode===`workspace`&&e.path!==`/`?e.path:null,M=n.running&&n.consumer===`applet`,N=n.running&&n.consumer!==`applet`,P=M?n.hits:[];h(M);let F=M?n.snapshotSize??n.camera?.size:null,I=!!F&&F.height>F.width,L=e=>{A&&n.start(e,`applet`,{workspaceRef:A,contextPath:j})},{setContextPath:R}=n;return(0,x.useEffect)(()=>{M&&R(j)},[M,j,R]),e?.mode===`workspace`?(0,S.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col gap-3 overflow-y-auto p-3`,children:[(0,S.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[(0,S.jsx)(`select`,{className:C,value:c,onChange:e=>l(Number(e.target.value)),title:`Frame rate. High rates (10–30 fps) are experimental; the loop never overlaps requests, so the effective rate is capped by search latency.`,children:v.map(e=>(0,S.jsx)(`option`,{value:e.ms,children:e.label},e.ms))}),(0,S.jsx)(`input`,{className:s(w,`w-44`),placeholder:`Optional text (fused mode)`,value:u,onChange:e=>d(e.target.value)}),(0,S.jsx)(`input`,{className:s(w,`w-28`),placeholder:`max distance`,inputMode:`decimal`,value:E,onChange:e=>D(e.target.value),title:`Cosine-distance floor (0 = identical). Empty = top-K.`}),M?(0,S.jsxs)(`button`,{type:`button`,onClick:n.stop,className:`flex h-8 items-center gap-1 rounded-md bg-destructive px-3 text-xs font-medium text-destructive-foreground transition-colors hover:bg-destructive/90`,children:[(0,S.jsx)(o,{className:`h-3.5 w-3.5`}),` `,n.source===`photo`?`Close photo`:`Stop`]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{type:`button`,onClick:()=>L(`camera`),disabled:N,className:`flex h-8 items-center gap-1 rounded-md bg-foreground px-3 text-xs font-medium text-background transition-colors hover:bg-foreground/90 disabled:opacity-50`,children:[(0,S.jsx)(i,{className:`h-3.5 w-3.5`}),` Camera`]}),(0,S.jsxs)(`button`,{type:`button`,onClick:()=>L(`screen`),disabled:N,className:`flex h-8 items-center gap-1 rounded-md bg-foreground px-3 text-xs font-medium text-background transition-colors hover:bg-foreground/90 disabled:opacity-50`,children:[(0,S.jsx)(r,{className:`h-3.5 w-3.5`}),` Desktop`]})]}),(0,S.jsx)(_,{consumer:`applet`,workspaceRef:A,contextPath:j,disabled:N,className:`flex h-8 items-center gap-1 rounded-md bg-foreground px-3 text-xs font-medium text-background transition-colors hover:bg-foreground/90 disabled:opacity-50`})]}),(0,S.jsxs)(`div`,{className:s(`relative shrink-0 overflow-hidden rounded-xl border border-border bg-black/80`,I?`aspect-[3/4] max-h-[60vh]`:`aspect-video max-h-80`),children:[M&&(0,S.jsx)(m,{className:`h-full w-full`,interactive:!0}),M&&(0,S.jsx)(y,{}),!M&&(0,S.jsxs)(`div`,{className:`absolute inset-0 flex items-center justify-center text-sm text-muted-foreground`,children:[(0,S.jsx)(a,{className:`mr-2 h-4 w-4`}),` camera off · or pick a photo`]})]}),M&&(0,S.jsx)(b,{className:`shrink-0`}),(0,S.jsx)(`div`,{className:`shrink-0 text-xs text-muted-foreground`,children:k?(0,S.jsx)(`span`,{className:`text-destructive`,children:k}):M?(0,S.jsxs)(S.Fragment,{children:[n.snapshot?`snapshot`:`live`,` · `,O==null?`searching…`:`${O} ms/frame`,` · `,P.length,` match`,P.length===1?``:`es`,j?` · scoped to ${j}`:``]}):N?`The Lens filter is using the camera. Stop it there first.`:`Frames are ephemeral: embedded for the query, never stored or indexed.`}),P.length===0?(0,S.jsx)(`div`,{className:`flex min-h-24 flex-1 items-center justify-center rounded-xl border border-dashed border-border text-sm text-muted-foreground`,children:M?n.snapshot?`Nothing similar in the snapshot`:`Nothing matching in view`:`Matches appear here`}):(0,S.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4`,children:P.map(e=>(0,S.jsx)(T,{workspaceRef:A,doc:e.doc,distance:e.distance,onOpen:e=>t.open(e,A)},e.doc.id))})]}):(0,S.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:`Lens searches a workspace. Bind it to a workspace path to start.`})}export{E as LensApplet};
@@ -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{L as r,Mt as i,dn as a,fi as o,oi as s,yt as c}from"./ui-BSqPn1LJ.js";import{t as l}from"./utils-2pl1SbIp.js";import{Un as u}from"./workspace-CJ1PWQ29.js";import{t as d}from"./useAddTarget-CVRPElxz.js";import{t as f}from"./note-save-status-DPz4VzL6.js";import{t as p}from"./useEditNoteFields-Bigs9ZG8.js";import{n as m}from"./use-applet-target-mkjQujx6.js";import{D as h}from"./index-exXolIqD.js";import{n as g,r as _,t as v}from"./shared-1dpCuibu.js";import{n as y,r as b}from"./use-applet-docs-Cry2SFsG.js";var x=e(n(),1),S=t();function C({doc:e,updateWorkspace:t,registerEl:n,registerBody:r,highlighted:i,onLinkTo:a,onDelete:o}){let s=p(e,t||``,!!t),{title:c,content:u,setTitle:d,setContent:m}=s,h=()=>{s.save().catch(()=>{})};return(0,S.jsxs)(`div`,{ref:t=>n(e.id,t),className:l(`group border-t border-border/60 px-4 py-3 transition-colors`,i&&`bg-primary/5`),children:[(0,S.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2`,children:[(0,S.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:[y(e.createdAt),` · #`,e.id]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground/70`,children:[(0,S.jsx)(f,{...s,onRetry:s.save}),(0,S.jsx)(g,{onLinkTo:a,onDelete:o})]})]}),(0,S.jsx)(`input`,{value:c,onChange:e=>d(e.target.value),onBlur:h,placeholder:`Untitled`,spellCheck:!1,className:`mb-1 w-full border-0 bg-transparent p-0 text-sm font-semibold text-foreground outline-none placeholder:text-muted-foreground/50`}),(0,S.jsx)(v,{value:u,onChange:m,onBlur:h,innerRef:t=>r(e.id,t)})]})}function w({target:e,onCreated:t,onCancel:n}){let i=h(e,void 0,`applet`),{title:a,content:o,setTitle:s,setContent:c,saving:l}=i,[u,d]=(0,x.useState)(null),p=async()=>{try{await i.save(e),i.finish(),t()}catch(e){d(e instanceof Error?e.message:`Failed to save note`)}};return(0,S.jsxs)(`div`,{className:`border-t border-border/60 bg-muted/30 px-4 py-3`,children:[(0,S.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between`,children:[(0,S.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:`New note`}),(0,S.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-foreground`,"aria-label":`Close note`,children:(0,S.jsx)(r,{className:`h-3 w-3`})})]}),(0,S.jsx)(`input`,{value:a,onChange:e=>s(e.target.value),placeholder:`Untitled`,autoFocus:!0,spellCheck:!1,className:`mb-1 w-full border-0 bg-transparent p-0 text-sm font-semibold text-foreground outline-none placeholder:text-muted-foreground/50`}),(0,S.jsx)(v,{value:o,onChange:c,placeholder:`Write your note…`}),(0,S.jsx)(f,{...i,onRetry:i.retry}),u&&(0,S.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:u}),(0,S.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,S.jsx)(`button`,{type:`button`,onClick:p,disabled:!o.trim()||l,className:`rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground disabled:opacity-50`,children:l?`Saving…`:`Done`})})]})}function T({autoAdd:e=!1}){let t=m(),{docs:n,loading:r,error:l,scope:f,reload:p,removeDoc:h}=b(t,u),[g,v]=(0,x.useState)(``),[y,T]=(0,x.useState)(0),[E,D]=(0,x.useState)(`desc`),[O,k]=(0,x.useState)(e),[A,j]=(0,x.useState)(null),M=(0,x.useRef)(new Map),N=(0,x.useRef)(new Map),P=(0,x.useCallback)((e,t)=>{t?M.current.set(e,t):M.current.delete(e)},[]),F=(0,x.useCallback)((e,t)=>{t?N.current.set(e,t):N.current.delete(e)},[]),I=(0,x.useCallback)(async e=>{let t=e.data?.title?`"${e.data.title}"`:`#${e.id}`;if(window.confirm(`Delete note ${t}?\n\nIt is removed from this path and moves to the workspace trash if nothing else links it.`))try{await h(e.id)}catch{}},[h]),L=(0,x.useMemo)(()=>{let e=[...n];return e.sort((e,t)=>{let n=new Date(e.createdAt).getTime()-new Date(t.createdAt).getTime();return E===`asc`?n:-n}),e},[n,E]),R=(0,x.useMemo)(()=>{let e=g.trim().toLowerCase();if(!e)return[];let t=[];for(let n of L){let r=String(n.data?.content??``),i=String(n.data?.title??``),a=r.toLowerCase().indexOf(e);a>=0?t.push({docId:n.id,offset:a}):i.toLowerCase().includes(e)&&t.push({docId:n.id,offset:-1})}return t},[g,L]),z=R.length?R[Math.min(y,R.length-1)]:null;(0,x.useEffect)(()=>{z&&M.current.get(z.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[z]);let B=(0,x.useCallback)(e=>{if(!R.length)return;let t=e?(y+1)%R.length:y;e&&T(t);let n=R[t],r=N.current.get(n.docId);r&&n.offset>=0&&(r.focus(),r.setSelectionRange(n.offset,n.offset+g.trim().length)),M.current.get(n.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[R,y,g]);return t?(0,S.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,S.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border px-3 py-2`,children:[(0,S.jsxs)(`div`,{className:`relative flex-1`,children:[(0,S.jsx)(c,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,S.jsx)(`input`,{value:g,onChange:e=>{v(e.target.value),T(0)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),B(!0))},placeholder:`Search notes…`,spellCheck:!1,className:`w-full rounded-md border border-input bg-transparent py-1 pl-7 pr-14 text-xs outline-none placeholder:text-muted-foreground focus-visible:ring-1 focus-visible:ring-ring`}),g.trim()&&(0,S.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-[10px] tabular-nums text-muted-foreground`,children:R.length?`${Math.min(y+1,R.length)}/${R.length}`:`0/0`})]}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>D(e=>e===`desc`?`asc`:`desc`),className:`rounded-md border border-border p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,title:E===`desc`?`Newest first (click for oldest first)`:`Oldest first (click for newest first)`,"aria-label":`Toggle sort order`,children:E===`desc`?(0,S.jsx)(o,{className:`h-3.5 w-3.5`}):(0,S.jsx)(s,{className:`h-3.5 w-3.5`})}),(0,S.jsxs)(`button`,{type:`button`,onClick:()=>k(!0),className:`flex items-center gap-1 rounded-md bg-primary px-2 py-1.5 text-xs text-primary-foreground`,title:`Add a note`,children:[(0,S.jsx)(i,{className:`h-3.5 w-3.5`}),`Note`]})]}),(0,S.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[O&&(0,S.jsx)(w,{target:t,onCreated:()=>{k(!1),p()},onCancel:()=>k(!1)},JSON.stringify(t)),r&&!n.length&&(0,S.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,S.jsx)(a,{className:`h-5 w-5 animate-spin text-muted-foreground`})}),l&&(0,S.jsx)(`p`,{className:`px-4 py-6 text-center text-sm text-destructive`,children:l}),!r&&!l&&!L.length&&!O&&(0,S.jsx)(`p`,{className:`px-4 py-10 text-center text-sm text-muted-foreground`,children:`No notes here yet - add the first one.`}),L.map(e=>(0,S.jsx)(C,{doc:e,updateWorkspace:f?.workspaceName??null,registerEl:P,registerBody:F,highlighted:z?.docId===e.id,onLinkTo:()=>j(e.id),onDelete:()=>I(e)},e.id))]}),A!==null&&(0,S.jsx)(_,{documentId:A,workspaceName:f?.workspaceName,onClose:()=>j(null)})]}):(0,S.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:d(t)})}export{T as NotesApplet};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{L as r,Mt as i,dn as a,fi as o,oi as s,yt as c}from"./ui-BSqPn1LJ.js";import{t as l}from"./utils-2pl1SbIp.js";import{Un as u}from"./workspace-CJ1PWQ29.js";import{t as d}from"./useAddTarget-CVRPElxz.js";import{t as f}from"./note-save-status-DPz4VzL6.js";import{t as p}from"./useEditNoteFields-Bigs9ZG8.js";import{n as m}from"./use-applet-target-mkjQujx6.js";import{O as h}from"./index-DtZS4JJ4.js";import{n as g,r as _,t as v}from"./shared-1dpCuibu.js";import{n as y,r as b}from"./use-applet-docs-Cry2SFsG.js";var x=e(n(),1),S=t();function C({doc:e,updateWorkspace:t,registerEl:n,registerBody:r,highlighted:i,onLinkTo:a,onDelete:o}){let s=p(e,t||``,!!t),{title:c,content:u,setTitle:d,setContent:m}=s,h=()=>{s.save().catch(()=>{})};return(0,S.jsxs)(`div`,{ref:t=>n(e.id,t),className:l(`group border-t border-border/60 px-4 py-3 transition-colors`,i&&`bg-primary/5`),children:[(0,S.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2`,children:[(0,S.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:[y(e.createdAt),` · #`,e.id]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground/70`,children:[(0,S.jsx)(f,{...s,onRetry:s.save}),(0,S.jsx)(g,{onLinkTo:a,onDelete:o})]})]}),(0,S.jsx)(`input`,{value:c,onChange:e=>d(e.target.value),onBlur:h,placeholder:`Untitled`,spellCheck:!1,className:`mb-1 w-full border-0 bg-transparent p-0 text-sm font-semibold text-foreground outline-none placeholder:text-muted-foreground/50`}),(0,S.jsx)(v,{value:u,onChange:m,onBlur:h,innerRef:t=>r(e.id,t)})]})}function w({target:e,onCreated:t,onCancel:n}){let i=h(e,void 0,`applet`),{title:a,content:o,setTitle:s,setContent:c,saving:l}=i,[u,d]=(0,x.useState)(null),p=async()=>{try{await i.save(e),i.finish(),t()}catch(e){d(e instanceof Error?e.message:`Failed to save note`)}};return(0,S.jsxs)(`div`,{className:`border-t border-border/60 bg-muted/30 px-4 py-3`,children:[(0,S.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between`,children:[(0,S.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:`New note`}),(0,S.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-foreground`,"aria-label":`Close note`,children:(0,S.jsx)(r,{className:`h-3 w-3`})})]}),(0,S.jsx)(`input`,{value:a,onChange:e=>s(e.target.value),placeholder:`Untitled`,autoFocus:!0,spellCheck:!1,className:`mb-1 w-full border-0 bg-transparent p-0 text-sm font-semibold text-foreground outline-none placeholder:text-muted-foreground/50`}),(0,S.jsx)(v,{value:o,onChange:c,placeholder:`Write your note…`}),(0,S.jsx)(f,{...i,onRetry:i.retry}),u&&(0,S.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:u}),(0,S.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,S.jsx)(`button`,{type:`button`,onClick:p,disabled:!o.trim()||l,className:`rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground disabled:opacity-50`,children:l?`Saving…`:`Done`})})]})}function T({autoAdd:e=!1}){let t=m(),{docs:n,loading:r,error:l,scope:f,reload:p,removeDoc:h}=b(t,u),[g,v]=(0,x.useState)(``),[y,T]=(0,x.useState)(0),[E,D]=(0,x.useState)(`desc`),[O,k]=(0,x.useState)(e),[A,j]=(0,x.useState)(null),M=(0,x.useRef)(new Map),N=(0,x.useRef)(new Map),P=(0,x.useCallback)((e,t)=>{t?M.current.set(e,t):M.current.delete(e)},[]),F=(0,x.useCallback)((e,t)=>{t?N.current.set(e,t):N.current.delete(e)},[]),I=(0,x.useCallback)(async e=>{let t=e.data?.title?`"${e.data.title}"`:`#${e.id}`;if(window.confirm(`Delete note ${t}?\n\nIt is removed from this path and moves to the workspace trash if nothing else links it.`))try{await h(e.id)}catch{}},[h]),L=(0,x.useMemo)(()=>{let e=[...n];return e.sort((e,t)=>{let n=new Date(e.createdAt).getTime()-new Date(t.createdAt).getTime();return E===`asc`?n:-n}),e},[n,E]),R=(0,x.useMemo)(()=>{let e=g.trim().toLowerCase();if(!e)return[];let t=[];for(let n of L){let r=String(n.data?.content??``),i=String(n.data?.title??``),a=r.toLowerCase().indexOf(e);a>=0?t.push({docId:n.id,offset:a}):i.toLowerCase().includes(e)&&t.push({docId:n.id,offset:-1})}return t},[g,L]),z=R.length?R[Math.min(y,R.length-1)]:null;(0,x.useEffect)(()=>{z&&M.current.get(z.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[z]);let B=(0,x.useCallback)(e=>{if(!R.length)return;let t=e?(y+1)%R.length:y;e&&T(t);let n=R[t],r=N.current.get(n.docId);r&&n.offset>=0&&(r.focus(),r.setSelectionRange(n.offset,n.offset+g.trim().length)),M.current.get(n.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[R,y,g]);return t?(0,S.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,S.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border px-3 py-2`,children:[(0,S.jsxs)(`div`,{className:`relative flex-1`,children:[(0,S.jsx)(c,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,S.jsx)(`input`,{value:g,onChange:e=>{v(e.target.value),T(0)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),B(!0))},placeholder:`Search notes…`,spellCheck:!1,className:`w-full rounded-md border border-input bg-transparent py-1 pl-7 pr-14 text-xs outline-none placeholder:text-muted-foreground focus-visible:ring-1 focus-visible:ring-ring`}),g.trim()&&(0,S.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-[10px] tabular-nums text-muted-foreground`,children:R.length?`${Math.min(y+1,R.length)}/${R.length}`:`0/0`})]}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>D(e=>e===`desc`?`asc`:`desc`),className:`rounded-md border border-border p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,title:E===`desc`?`Newest first (click for oldest first)`:`Oldest first (click for newest first)`,"aria-label":`Toggle sort order`,children:E===`desc`?(0,S.jsx)(o,{className:`h-3.5 w-3.5`}):(0,S.jsx)(s,{className:`h-3.5 w-3.5`})}),(0,S.jsxs)(`button`,{type:`button`,onClick:()=>k(!0),className:`flex items-center gap-1 rounded-md bg-primary px-2 py-1.5 text-xs text-primary-foreground`,title:`Add a note`,children:[(0,S.jsx)(i,{className:`h-3.5 w-3.5`}),`Note`]})]}),(0,S.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[O&&(0,S.jsx)(w,{target:t,onCreated:()=>{k(!1),p()},onCancel:()=>k(!1)},JSON.stringify(t)),r&&!n.length&&(0,S.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,S.jsx)(a,{className:`h-5 w-5 animate-spin text-muted-foreground`})}),l&&(0,S.jsx)(`p`,{className:`px-4 py-6 text-center text-sm text-destructive`,children:l}),!r&&!l&&!L.length&&!O&&(0,S.jsx)(`p`,{className:`px-4 py-10 text-center text-sm text-muted-foreground`,children:`No notes here yet - add the first one.`}),L.map(e=>(0,S.jsx)(C,{doc:e,updateWorkspace:f?.workspaceName??null,registerEl:P,registerBody:F,highlighted:z?.docId===e.id,onLinkTo:()=>j(e.id),onDelete:()=>I(e)},e.id))]}),A!==null&&(0,S.jsx)(_,{documentId:A,workspaceName:f?.workspaceName,onClose:()=>j(null)})]}):(0,S.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:d(t)})}export{T as NotesApplet};
@@ -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{t as o}from"./socket-CtH3EU9m.js";import{n as s}from"./use-toast-BlLDqSUO.js";import{o as c,s as l}from"./LinkToCard-BZwwE-Dv.js";import{En as u,H as d,K as ee,Vt as te,t as f}from"./workspace-CJ1PWQ29.js";import{r as ne}from"./document-list-BiogH4tf.js";import{n as re}from"./use-toolbox-Ck_cLGgf.js";import{E as ie,_ as ae,a as oe,b as se,i as ce,l as le,o as ue}from"./context-D_K4g9SQ.js";import{i as de}from"./color-DFEH4BfK.js";import{t as fe}from"./geo-CZfs0E-x.js";import{a as pe,i as me,o as he}from"./workspace-BydSRtST.js";import{i as ge}from"./use-menu-BVkqNEIx.js";import{a as _e,i as ve,n as ye,o as be,r as xe,s as Se,t as Ce}from"./content-app-view-C33Ip_rx.js";import{t as we}from"./use-workspace-identity-BVpGHkZq.js";var p=e(n(),1),m=t();function Te(e,t){if(!e||!t)return`/`;let n=`${t}://`;if(!e.startsWith(n))return`/`;let r=e.slice(n.length).replace(/^\/+/,``).replace(/\/+$/,``);return r?`/${r}`:`/`}function h(){let{contextId:e}=r(),t=a(),n=i(),h=new URLSearchParams(t.search).get(`ownerId`)||void 0,g=(0,p.useMemo)(()=>{let e=new URLSearchParams(t.search),n=e.getAll(`q`).map(e=>e.trim()).filter(Boolean),r=(e.get(`search`)||``).trim();return n.length?n:r?[r]:[]},[t.search]),{showToast:_,showProgress:Ee}=s(),{state:v,saveFilters:De,setSort:Oe,setAccentColor:y,setMapDocuments:b}=re(),{openM1Drawer:ke,openM2Drawer:Ae,goBack:je}=ge(),Me=v.filters.features.allOf,Ne=v.filters.features.anyOf,Pe=v.filters.features.noneOf,Fe=[...me(v.filters.timeline),...pe(v.filters.geo),...he(v.filters.lens,v.filters.geo.includeUnlocated)],x=JSON.stringify({a:Me,b:Ne,c:Pe,d:Fe,ids:v.filters.lens.ids,sort:v.filters.sort,geoSelection:v.geoSelection,includeUnlocated:v.filters.geo.includeUnlocated}),S=(0,p.useMemo)(()=>JSON.parse(x),[x]),[C,w]=(0,p.useState)(null),[Ie,Le]=(0,p.useState)(!0),[Re,ze]=(0,p.useState)(null),[T,E]=(0,p.useState)([]),[Be,Ve]=(0,p.useState)(!1),[He,D]=(0,p.useState)(0),[Ue,We]=(0,p.useState)([]),[O,k]=(0,p.useState)(1),[A,Ge]=(0,p.useState)(50),[j,M]=(0,p.useState)(g),[N,P]=(0,p.useState)(!1),[F,I]=(0,p.useState)(null),[L,Ke]=(0,p.useState)(!1),R=(0,p.useRef)(!1),z=F?.id===C?.id&&F?.url===C?.url?F?.path:null,qe=new URLSearchParams(t.search).get(`layer`),B=!!h,Je=we(B?void 0:C?.workspaceName||C?.workspaceId),V=C?Te(C.url,C.workspaceName):`/`,Ye=qe?`context-layer`:`context`,H=!v.liveEnabled&&typeof C?.metadata?.toolboxSearchQuery==`string`?C.metadata.toolboxSearchQuery:``,U=B?null:C?.workspaceName??null,[Xe,Ze]=(0,p.useState)(null);(0,p.useEffect)(()=>{if(!U)return;let e=!1;return ee(U,f).then(t=>{e||Ze({key:U,tree:t})}).catch(()=>{e||Ze({key:U,tree:null})}),()=>{e=!0}},[U]);let W=U&&Xe?.key===U?Xe.tree:null,G=!qe&&!B&&W?V===`/`?W:d(W,V):null,K=`${C?.workspaceName??``}\0${V}`,[q,Qe]=(0,p.useState)(null),J=q?.key===K?q.views:be(G?.metadata),Y=q?.key===K?q.activeId:J[0]?.id??ve.id,X=J.find(e=>e.id===Y)??J[0]??ve,Z=_e(X),$e=e=>{k(1),Qe({key:K,views:J,activeId:e})},et=(e,t)=>{t&&t!==Y&&k(1),Qe({key:K,views:e,activeId:t??Y}),C?.workspaceName&&u(C.workspaceName,V,{metadata:{...G?.metadata??{},views:e}},f).catch(()=>{_({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},tt=(0,p.useRef)(null);(0,p.useEffect)(()=>()=>tt.current?.abort(),[]);let Q=(0,p.useCallback)(async()=>{if(!e)return;tt.current?.abort();let t=new AbortController;tt.current=t,Ve(!0);try{let n=await ue(e,Z?[...S.a,Z]:S.a,S.d,{...S.sort,geoSelection:S.geoSelection,includeUnlocated:S.includeUnlocated,ids:S.ids,signal:t.signal,limit:A,page:O,queries:j.length?j:void 0,anyOf:S.b,noneOf:S.c,applyContextSpec:!1},h);if(t.signal.aborted)return;E(n),D(n.totalCount||n.count||n.length)}catch(e){if(t.signal.aborted)return;_({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch documents`,variant:`destructive`}),E([]),D(0)}finally{t.signal.aborted||Ve(!1)}},[e,O,A,h,j,S,_,Z]),nt=(0,p.useCallback)(async()=>{if(e){Le(!0);try{let t=B?await oe(e,h):await oe(e);if(!t)throw Error(`No context data received.`);let n=t.workspace,r=t.workspaceId||(typeof n==`string`?n:n?.id)||``,i=t.workspaceName||(typeof n==`string`?n:n?.name)||``;w({id:t.id,userId:t.userId,url:t.url,baseUrl:t.baseUrl||null,path:t.path||null,pathArray:t.pathArray||[],workspaceId:r,workspaceName:i,acl:t.acl||{},createdAt:t.createdAt,updatedAt:t.updatedAt,locked:t.locked||!1,serverContextArray:t.serverContextArray||[],clientContextArray:t.clientContextArray||[],contextBitmapArray:t.contextBitmapArray||[],featureBitmapArray:t.featureBitmapArray||[],filterArray:t.filterArray||[],pendingUrl:t.pendingUrl||null,description:t.description||null,metadata:t.metadata||{},name:t.name??null,color:t.color??null,icon:t.icon??null}),ze(null)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch context ${e}`;ze(n),w(null),_({title:`Error`,description:n,variant:`destructive`})}Le(!1)}},[e,h,B,_]);(0,p.useEffect)(()=>{nt()},[nt]);let rt=de(C?.color)||null;(0,p.useEffect)(()=>(y(rt),()=>y(null)),[rt,y]);let it=v.geoSelection,at=C?.workspaceName||C?.workspaceId||null;(0,p.useEffect)(()=>{b(T,at)},[T,at,b]),(0,p.useEffect)(()=>()=>b([]),[b]);let ot=(0,p.useMemo)(()=>it?T.filter(e=>fe(e,it,v.filters.geo.includeUnlocated)):T,[T,it,v.filters.geo.includeUnlocated]),st=C?.id,ct=C?.url;(0,p.useEffect)(()=>{st&&Q()},[st,ct,Q]),(0,p.useEffect)(()=>{let e=()=>Q();return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[Q]);let[lt,ut]=(0,p.useState)(x);lt!==x&&(ut(x),k(1));let[dt,ft]=(0,p.useState)(e);dt!==e&&(ft(e),k(1),P(!1));let[pt,mt]=(0,p.useState)(g);pt!==g&&(mt(g),M(g),k(1));let[ht,gt]=(0,p.useState)({urlSearchQueries:g,ignoreSavedSearch:N,savedContextSearchQuery:H});(ht.urlSearchQueries!==g||ht.ignoreSavedSearch!==N||ht.savedContextSearchQuery!==H)&&(gt({urlSearchQueries:g,ignoreSavedSearch:N,savedContextSearchQuery:H}),!new URLSearchParams(t.search).has(`q`)&&!g.length&&!N&&(M(H?[H]:[]),k(1)));let $=(0,p.useCallback)(e=>{let r=new URLSearchParams(t.search);r.delete(`q`),r.delete(`search`);for(let t of e)r.append(`q`,t);let i=r.toString();n(`${t.pathname}${i?`?${i}`:``}${t.hash}`)},[t.pathname,t.search,t.hash,n]),_t=(0,p.useCallback)(e=>{let t=e.trim();if(!t)return;P(!1);let n=j.includes(t)?j:[...j,t];M(n),$(n)},[j,$]),vt=(0,p.useCallback)(e=>{let t=e<0?[]:j.filter((t,n)=>n!==e);t.length===0&&P(!0),M(t),$(t)},[j,$]),yt=(j[0]||``).trim(),bt=!!v.activeContextType&&(v.isDirty||yt!==(v.savedSearchQuery||H||``));(0,p.useEffect)(()=>{if(!e)return;let t=`context:${h?`${h}/`:``}${e}`,n=()=>o.emit(`subscribe`,{channel:t}),r=()=>o.emit(`unsubscribe`,{channel:t}),i=o.on(`connect`,n);n();let a=new Map,s=(t,n)=>{let r=Date.now(),i=`${t}:${n?.id||n?.contextId||e}`;return(a.get(i)||0)+1e3>r?!1:(a.set(i,r),!0)},c=t=>{let n=t,r=n?.context||n;(r?.id===e||r?.contextId===e)&&s(`ctx:updated`,r)&&(w(e=>e?{...e,...r}:null),r.url&&Q())},l=t=>{let n=t,r=n?.id||n?.contextId||n?.context?.id,i=n?.url||n?.context?.url;r===e&&typeof i==`string`&&s(`ctx:url`,n)&&(w(e=>e?{...e,url:i}:null),Q())},u=t=>{let n=t;(n?.contextId||n?.id||n?.context?.id)===e&&s(`doc:changed`,n)&&Q()},d=[[`context.updated`,c],[`context:updated`,c],[`context.url.set`,l],[`context:url:set`,l],[`document.inserted`,u],[`document.updated`,u],[`document.removed`,u],[`document.removed.batch`,u],[`document.linked`,u],[`document.unlinked`,u],[`document.linked.batch`,u],[`document.unlinked.batch`,u],[`document.deleted`,u],[`document.deleted.batch`,u]];return d.forEach(([e,t])=>o.on(e,t)),()=>{i(),r(),d.forEach(([e,t])=>o.off(e,t))}},[e,h,Q]);let xt=async e=>{if(C)try{await se(C.id,[e],h,V),E(t=>t.filter(t=>t.id!==e)),D(e=>Math.max(0,e-1)),_({title:`Success`,description:`Document removed from context.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},St=async e=>{if(C)try{await ce(C.id,[e],h,V),E(t=>t.filter(t=>t.id!==e)),D(e=>Math.max(0,e-1)),_({title:`Success`,description:`Document deleted.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},Ct=async e=>{if(C)try{await se(C.id,e,h,V),E(t=>t.filter(t=>!e.includes(t.id))),D(t=>Math.max(0,t-e.length)),_({title:`Success`,description:`${e.length} document(s) removed.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},wt=async e=>{if(C)try{await ce(C.id,e,h,V),E(t=>t.filter(t=>!e.includes(t.id))),D(t=>Math.max(0,t-e.length)),_({title:`Success`,description:`${e.length} document(s) deleted.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},Tt=e=>{We(e),_({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},Et=async(e,t,n={})=>{if(!C)return!1;let r=Ee({title:`Pasting…`,description:`${t.length} document(s) → "${e}"`});try{let i=n.targetTreeName&&!B?await te(C.workspaceName||C.workspaceId,e,t,n.targetTreeName,n.targetTreeType):await ae(C.id,e,t,h);return r.done(i?{title:`Success`,description:`${t.length} document(s) pasted to "${e}"`}:void 0),i&&(We([]),await Q()),i}catch(e){return r.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},Dt=async(e,t)=>{if(!C)return!1;try{let n=await le(C.workspaceId,t,e);return n&&(ne(C.workspaceName||C.workspaceId,`context`,t),_({title:`Success`,description:`Imported ${e.length} document(s) to "${t}"`})),n}catch(e){return _({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},Ot=async()=>{if(!C||!z||B||R.current)return;let e={id:C.id,url:C.url,path:z};R.current=!0,Ke(!0);try{let t=await ie(e.id,`${C.workspaceName}://${e.path.replace(/^\/+/,``)}`);w(n=>n?.id===e.id&&n.url===e.url?{...n,url:t.url,path:e.path}:n),I(null),k(1),window.dispatchEvent(new CustomEvent(`contexts:refresh`,{detail:{contextId:e.id}})),_({title:`Saved`,description:`Context path updated`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Could not update context path`,variant:`destructive`})}finally{R.current=!1,Ke(!1)}};if(Ie)return(0,m.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,m.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,m.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,m.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading context...`})]})});if(Re&&!C)return(0,m.jsxs)(`div`,{className:`flex items-center justify-center h-full text-destructive`,children:[`Error: `,Re]});if(!C)return(0,m.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Context not found.`});let kt=de(C.color);return(0,m.jsx)(`div`,{className:`flex flex-col h-full min-h-0`,children:(0,m.jsx)(Se,{onBack:je,accentColor:kt,navigationTabs:G?(0,m.jsx)(xe,{views:J,activeId:Y,onSelect:$e,onSave:et,accentColor:kt}):void 0,workspaceLabel:Je?.label||C.workspaceName||C.workspaceId,workspaceIcon:Je?.icon,treeName:f,urlType:Ye,urlDisplay:C.url,contextPath:V,workspaceId:C.workspaceName||C.workspaceId,documentSchema:Z,linkTree:W,documents:ot,isLoading:Be,totalCount:He,currentPage:O,pageSize:A,onPageChange:k,onPageSizeChange:e=>{Ge(e),k(1)},onRemoveDocument:V===`/`?void 0:xt,onDeleteDocument:St,onRemoveDocuments:V===`/`?void 0:Ct,onDeleteDocuments:wt,onCopyDocuments:Tt,onPasteDocuments:Et,onImportDocuments:B?void 0:Dt,pastedDocumentIds:Ue,backendSearchQueries:j,onBackendSearch:_t,serverSort:v.filters.sort,onServerSortChange:Oe,onRemoveBackendQuery:vt,canSaveChanges:bt,isSavingChanges:v.isSaving,onSaveChanges:De,onBrowseTree:!B&&e?()=>Ae(`contexts`,`detail`,e):void 0,onBrowseWorkspaces:()=>ke(`workspaces`),onNavigatePath:B?void 0:e=>{R.current||I({id:C.id,url:C.url,path:e})},contentBanner:z?(0,m.jsxs)(`div`,{className:`border-b bg-warning/10 px-4 py-2`,role:`status`,children:[(0,m.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Set this context to the selected path? Contents stay at the current path until you apply it.`}),(0,m.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,m.jsx)(l,{items:c(z,C.workspaceName),label:`Selected context path`}),(0,m.jsx)(`button`,{type:`button`,disabled:L,onClick:()=>void Ot(),className:`shrink-0 rounded border px-3 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:L?`Setting…`:`Set`}),(0,m.jsx)(`button`,{type:`button`,disabled:L,onClick:()=>I(null),className:`shrink-0 rounded px-2 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:`Cancel`})]})]}):void 0,children:X.kind===`columns`?(0,m.jsx)(ye,{documents:ot,workspaceId:C.workspaceName||C.workspaceId,columns:X.columns??[],onColumnsChange:e=>et(J.map(t=>t.id===X.id?{...t,columns:e}:t))}):X.kind===`app`&&X.app&&X.app!==`notes`?(0,m.jsx)(Ce,{app:X.app,contextId:e,workspaceId:C.workspaceName||C.workspaceId,treeName:f,path:V}):null})})}export{h as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./socket-CtH3EU9m.js";import{n as s}from"./use-toast-BlLDqSUO.js";import{o as c,s as l}from"./LinkToCard-BZwwE-Dv.js";import{En as u,H as d,K as ee,Vt as te,t as f}from"./workspace-CJ1PWQ29.js";import{r as ne}from"./document-list-BiogH4tf.js";import{n as re}from"./use-toolbox-Ck_cLGgf.js";import{E as ie,_ as ae,a as oe,b as se,i as ce,l as le,o as ue}from"./context-D_K4g9SQ.js";import{i as de}from"./color-DFEH4BfK.js";import{t as fe}from"./geo-CZfs0E-x.js";import{a as pe,i as me,o as he}from"./workspace-BydSRtST.js";import{i as ge}from"./use-menu-BVkqNEIx.js";import{a as _e,i as ve,n as ye,o as be,r as xe,s as Se,t as Ce}from"./content-app-view-BUi8HG1r.js";import{t as we}from"./use-workspace-identity-BVpGHkZq.js";var p=e(n(),1),m=t();function Te(e,t){if(!e||!t)return`/`;let n=`${t}://`;if(!e.startsWith(n))return`/`;let r=e.slice(n.length).replace(/^\/+/,``).replace(/\/+$/,``);return r?`/${r}`:`/`}function h(){let{contextId:e}=r(),t=a(),n=i(),h=new URLSearchParams(t.search).get(`ownerId`)||void 0,g=(0,p.useMemo)(()=>{let e=new URLSearchParams(t.search),n=e.getAll(`q`).map(e=>e.trim()).filter(Boolean),r=(e.get(`search`)||``).trim();return n.length?n:r?[r]:[]},[t.search]),{showToast:_,showProgress:Ee}=s(),{state:v,saveFilters:De,setSort:Oe,setAccentColor:y,setMapDocuments:b}=re(),{openM1Drawer:ke,openM2Drawer:Ae,goBack:je}=ge(),Me=v.filters.features.allOf,Ne=v.filters.features.anyOf,Pe=v.filters.features.noneOf,Fe=[...me(v.filters.timeline),...pe(v.filters.geo),...he(v.filters.lens,v.filters.geo.includeUnlocated)],x=JSON.stringify({a:Me,b:Ne,c:Pe,d:Fe,ids:v.filters.lens.ids,sort:v.filters.sort,geoSelection:v.geoSelection,includeUnlocated:v.filters.geo.includeUnlocated}),S=(0,p.useMemo)(()=>JSON.parse(x),[x]),[C,w]=(0,p.useState)(null),[Ie,Le]=(0,p.useState)(!0),[Re,ze]=(0,p.useState)(null),[T,E]=(0,p.useState)([]),[Be,Ve]=(0,p.useState)(!1),[He,D]=(0,p.useState)(0),[Ue,We]=(0,p.useState)([]),[O,k]=(0,p.useState)(1),[A,Ge]=(0,p.useState)(50),[j,M]=(0,p.useState)(g),[N,P]=(0,p.useState)(!1),[F,I]=(0,p.useState)(null),[L,Ke]=(0,p.useState)(!1),R=(0,p.useRef)(!1),z=F?.id===C?.id&&F?.url===C?.url?F?.path:null,qe=new URLSearchParams(t.search).get(`layer`),B=!!h,Je=we(B?void 0:C?.workspaceName||C?.workspaceId),V=C?Te(C.url,C.workspaceName):`/`,Ye=qe?`context-layer`:`context`,H=!v.liveEnabled&&typeof C?.metadata?.toolboxSearchQuery==`string`?C.metadata.toolboxSearchQuery:``,U=B?null:C?.workspaceName??null,[Xe,Ze]=(0,p.useState)(null);(0,p.useEffect)(()=>{if(!U)return;let e=!1;return ee(U,f).then(t=>{e||Ze({key:U,tree:t})}).catch(()=>{e||Ze({key:U,tree:null})}),()=>{e=!0}},[U]);let W=U&&Xe?.key===U?Xe.tree:null,G=!qe&&!B&&W?V===`/`?W:d(W,V):null,K=`${C?.workspaceName??``}\0${V}`,[q,Qe]=(0,p.useState)(null),J=q?.key===K?q.views:be(G?.metadata),Y=q?.key===K?q.activeId:J[0]?.id??ve.id,X=J.find(e=>e.id===Y)??J[0]??ve,Z=_e(X),$e=e=>{k(1),Qe({key:K,views:J,activeId:e})},et=(e,t)=>{t&&t!==Y&&k(1),Qe({key:K,views:e,activeId:t??Y}),C?.workspaceName&&u(C.workspaceName,V,{metadata:{...G?.metadata??{},views:e}},f).catch(()=>{_({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},tt=(0,p.useRef)(null);(0,p.useEffect)(()=>()=>tt.current?.abort(),[]);let Q=(0,p.useCallback)(async()=>{if(!e)return;tt.current?.abort();let t=new AbortController;tt.current=t,Ve(!0);try{let n=await ue(e,Z?[...S.a,Z]:S.a,S.d,{...S.sort,geoSelection:S.geoSelection,includeUnlocated:S.includeUnlocated,ids:S.ids,signal:t.signal,limit:A,page:O,queries:j.length?j:void 0,anyOf:S.b,noneOf:S.c,applyContextSpec:!1},h);if(t.signal.aborted)return;E(n),D(n.totalCount||n.count||n.length)}catch(e){if(t.signal.aborted)return;_({title:`Error`,description:e instanceof Error?e.message:`Failed to fetch documents`,variant:`destructive`}),E([]),D(0)}finally{t.signal.aborted||Ve(!1)}},[e,O,A,h,j,S,_,Z]),nt=(0,p.useCallback)(async()=>{if(e){Le(!0);try{let t=B?await oe(e,h):await oe(e);if(!t)throw Error(`No context data received.`);let n=t.workspace,r=t.workspaceId||(typeof n==`string`?n:n?.id)||``,i=t.workspaceName||(typeof n==`string`?n:n?.name)||``;w({id:t.id,userId:t.userId,url:t.url,baseUrl:t.baseUrl||null,path:t.path||null,pathArray:t.pathArray||[],workspaceId:r,workspaceName:i,acl:t.acl||{},createdAt:t.createdAt,updatedAt:t.updatedAt,locked:t.locked||!1,serverContextArray:t.serverContextArray||[],clientContextArray:t.clientContextArray||[],contextBitmapArray:t.contextBitmapArray||[],featureBitmapArray:t.featureBitmapArray||[],filterArray:t.filterArray||[],pendingUrl:t.pendingUrl||null,description:t.description||null,metadata:t.metadata||{},name:t.name??null,color:t.color??null,icon:t.icon??null}),ze(null)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch context ${e}`;ze(n),w(null),_({title:`Error`,description:n,variant:`destructive`})}Le(!1)}},[e,h,B,_]);(0,p.useEffect)(()=>{nt()},[nt]);let rt=de(C?.color)||null;(0,p.useEffect)(()=>(y(rt),()=>y(null)),[rt,y]);let it=v.geoSelection,at=C?.workspaceName||C?.workspaceId||null;(0,p.useEffect)(()=>{b(T,at)},[T,at,b]),(0,p.useEffect)(()=>()=>b([]),[b]);let ot=(0,p.useMemo)(()=>it?T.filter(e=>fe(e,it,v.filters.geo.includeUnlocated)):T,[T,it,v.filters.geo.includeUnlocated]),st=C?.id,ct=C?.url;(0,p.useEffect)(()=>{st&&Q()},[st,ct,Q]),(0,p.useEffect)(()=>{let e=()=>Q();return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[Q]);let[lt,ut]=(0,p.useState)(x);lt!==x&&(ut(x),k(1));let[dt,ft]=(0,p.useState)(e);dt!==e&&(ft(e),k(1),P(!1));let[pt,mt]=(0,p.useState)(g);pt!==g&&(mt(g),M(g),k(1));let[ht,gt]=(0,p.useState)({urlSearchQueries:g,ignoreSavedSearch:N,savedContextSearchQuery:H});(ht.urlSearchQueries!==g||ht.ignoreSavedSearch!==N||ht.savedContextSearchQuery!==H)&&(gt({urlSearchQueries:g,ignoreSavedSearch:N,savedContextSearchQuery:H}),!new URLSearchParams(t.search).has(`q`)&&!g.length&&!N&&(M(H?[H]:[]),k(1)));let $=(0,p.useCallback)(e=>{let r=new URLSearchParams(t.search);r.delete(`q`),r.delete(`search`);for(let t of e)r.append(`q`,t);let i=r.toString();n(`${t.pathname}${i?`?${i}`:``}${t.hash}`)},[t.pathname,t.search,t.hash,n]),_t=(0,p.useCallback)(e=>{let t=e.trim();if(!t)return;P(!1);let n=j.includes(t)?j:[...j,t];M(n),$(n)},[j,$]),vt=(0,p.useCallback)(e=>{let t=e<0?[]:j.filter((t,n)=>n!==e);t.length===0&&P(!0),M(t),$(t)},[j,$]),yt=(j[0]||``).trim(),bt=!!v.activeContextType&&(v.isDirty||yt!==(v.savedSearchQuery||H||``));(0,p.useEffect)(()=>{if(!e)return;let t=`context:${h?`${h}/`:``}${e}`,n=()=>o.emit(`subscribe`,{channel:t}),r=()=>o.emit(`unsubscribe`,{channel:t}),i=o.on(`connect`,n);n();let a=new Map,s=(t,n)=>{let r=Date.now(),i=`${t}:${n?.id||n?.contextId||e}`;return(a.get(i)||0)+1e3>r?!1:(a.set(i,r),!0)},c=t=>{let n=t,r=n?.context||n;(r?.id===e||r?.contextId===e)&&s(`ctx:updated`,r)&&(w(e=>e?{...e,...r}:null),r.url&&Q())},l=t=>{let n=t,r=n?.id||n?.contextId||n?.context?.id,i=n?.url||n?.context?.url;r===e&&typeof i==`string`&&s(`ctx:url`,n)&&(w(e=>e?{...e,url:i}:null),Q())},u=t=>{let n=t;(n?.contextId||n?.id||n?.context?.id)===e&&s(`doc:changed`,n)&&Q()},d=[[`context.updated`,c],[`context:updated`,c],[`context.url.set`,l],[`context:url:set`,l],[`document.inserted`,u],[`document.updated`,u],[`document.removed`,u],[`document.removed.batch`,u],[`document.linked`,u],[`document.unlinked`,u],[`document.linked.batch`,u],[`document.unlinked.batch`,u],[`document.deleted`,u],[`document.deleted.batch`,u]];return d.forEach(([e,t])=>o.on(e,t)),()=>{i(),r(),d.forEach(([e,t])=>o.off(e,t))}},[e,h,Q]);let xt=async e=>{if(C)try{await se(C.id,[e],h,V),E(t=>t.filter(t=>t.id!==e)),D(e=>Math.max(0,e-1)),_({title:`Success`,description:`Document removed from context.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to remove document`,variant:`destructive`})}},St=async e=>{if(C)try{await ce(C.id,[e],h,V),E(t=>t.filter(t=>t.id!==e)),D(e=>Math.max(0,e-1)),_({title:`Success`,description:`Document deleted.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to delete document`,variant:`destructive`})}},Ct=async e=>{if(C)try{await se(C.id,e,h,V),E(t=>t.filter(t=>!e.includes(t.id))),D(t=>Math.max(0,t-e.length)),_({title:`Success`,description:`${e.length} document(s) removed.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to remove documents`,variant:`destructive`})}},wt=async e=>{if(C)try{await ce(C.id,e,h,V),E(t=>t.filter(t=>!e.includes(t.id))),D(t=>Math.max(0,t-e.length)),_({title:`Success`,description:`${e.length} document(s) deleted.`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Failed to delete documents`,variant:`destructive`})}},Tt=e=>{We(e),_({title:`Copied`,description:`${e.length} document(s) copied to clipboard`})},Et=async(e,t,n={})=>{if(!C)return!1;let r=Ee({title:`Pasting…`,description:`${t.length} document(s) → "${e}"`});try{let i=n.targetTreeName&&!B?await te(C.workspaceName||C.workspaceId,e,t,n.targetTreeName,n.targetTreeType):await ae(C.id,e,t,h);return r.done(i?{title:`Success`,description:`${t.length} document(s) pasted to "${e}"`}:void 0),i&&(We([]),await Q()),i}catch(e){return r.fail({title:`Error`,description:e instanceof Error?e.message:`Failed to paste documents`,variant:`destructive`}),!1}},Dt=async(e,t)=>{if(!C)return!1;try{let n=await le(C.workspaceId,t,e);return n&&(ne(C.workspaceName||C.workspaceId,`context`,t),_({title:`Success`,description:`Imported ${e.length} document(s) to "${t}"`})),n}catch(e){return _({title:`Error`,description:e instanceof Error?e.message:`Failed to import documents`,variant:`destructive`}),!1}},Ot=async()=>{if(!C||!z||B||R.current)return;let e={id:C.id,url:C.url,path:z};R.current=!0,Ke(!0);try{let t=await ie(e.id,`${C.workspaceName}://${e.path.replace(/^\/+/,``)}`);w(n=>n?.id===e.id&&n.url===e.url?{...n,url:t.url,path:e.path}:n),I(null),k(1),window.dispatchEvent(new CustomEvent(`contexts:refresh`,{detail:{contextId:e.id}})),_({title:`Saved`,description:`Context path updated`})}catch(e){_({title:`Error`,description:e instanceof Error?e.message:`Could not update context path`,variant:`destructive`})}finally{R.current=!1,Ke(!1)}};if(Ie)return(0,m.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,m.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,m.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,m.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading context...`})]})});if(Re&&!C)return(0,m.jsxs)(`div`,{className:`flex items-center justify-center h-full text-destructive`,children:[`Error: `,Re]});if(!C)return(0,m.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Context not found.`});let kt=de(C.color);return(0,m.jsx)(`div`,{className:`flex flex-col h-full min-h-0`,children:(0,m.jsx)(Se,{onBack:je,accentColor:kt,navigationTabs:G?(0,m.jsx)(xe,{views:J,activeId:Y,onSelect:$e,onSave:et,accentColor:kt}):void 0,workspaceLabel:Je?.label||C.workspaceName||C.workspaceId,workspaceIcon:Je?.icon,treeName:f,urlType:Ye,urlDisplay:C.url,contextPath:V,workspaceId:C.workspaceName||C.workspaceId,documentSchema:Z,linkTree:W,documents:ot,isLoading:Be,totalCount:He,currentPage:O,pageSize:A,onPageChange:k,onPageSizeChange:e=>{Ge(e),k(1)},onRemoveDocument:V===`/`?void 0:xt,onDeleteDocument:St,onRemoveDocuments:V===`/`?void 0:Ct,onDeleteDocuments:wt,onCopyDocuments:Tt,onPasteDocuments:Et,onImportDocuments:B?void 0:Dt,pastedDocumentIds:Ue,backendSearchQueries:j,onBackendSearch:_t,serverSort:v.filters.sort,onServerSortChange:Oe,onRemoveBackendQuery:vt,canSaveChanges:bt,isSavingChanges:v.isSaving,onSaveChanges:De,onBrowseTree:!B&&e?()=>Ae(`contexts`,`detail`,e):void 0,onBrowseWorkspaces:()=>ke(`workspaces`),onNavigatePath:B?void 0:e=>{R.current||I({id:C.id,url:C.url,path:e})},contentBanner:z?(0,m.jsxs)(`div`,{className:`border-b bg-warning/10 px-4 py-2`,role:`status`,children:[(0,m.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Set this context to the selected path? Contents stay at the current path until you apply it.`}),(0,m.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,m.jsx)(l,{items:c(z,C.workspaceName),label:`Selected context path`}),(0,m.jsx)(`button`,{type:`button`,disabled:L,onClick:()=>void Ot(),className:`shrink-0 rounded border px-3 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:L?`Setting…`:`Set`}),(0,m.jsx)(`button`,{type:`button`,disabled:L,onClick:()=>I(null),className:`shrink-0 rounded px-2 py-1 text-sm hover:bg-accent disabled:opacity-50`,children:`Cancel`})]})]}):void 0,children:X.kind===`columns`?(0,m.jsx)(ye,{documents:ot,workspaceId:C.workspaceName||C.workspaceId,columns:X.columns??[],onColumnsChange:e=>et(J.map(t=>t.id===X.id?{...t,columns:e}:t))}):X.kind===`app`&&X.app&&X.app!==`notes`?(0,m.jsx)(Ce,{app:X.app,contextId:e,workspaceId:C.workspaceName||C.workspaceId,treeName:f,path:V}):null})})}export{h as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{L as o,Vr as s,dn as c,zr as l}from"./ui-BSqPn1LJ.js";import{t as u}from"./utils-2pl1SbIp.js";import{t as d}from"./button-Bv4zA1qr.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{$t as g,En as _,K as ee,Nt as te,O as ne,Qt as re,S as v,T as ie,Ut as y,Vt as b,Z as ae,at as oe,b as se,bt as ce,d as le,dn as ue,dt as de,gt as fe,it as pe,o as me,q as x,v as he,vt as ge,yn as S}from"./workspace-CJ1PWQ29.js";import{n as _e,r as ve}from"./use-canvas-pins-CZBfEB5E.js";import{u as ye}from"./ObjectPropertiesCard-DDcRLpsW.js";import{h as be,i as C,r as xe}from"./document-list-BiogH4tf.js";import{n as Se}from"./use-toolbox-Ck_cLGgf.js";import{i as Ce}from"./color-DFEH4BfK.js";import{t as we}from"./geo-CZfs0E-x.js";import{c as Te}from"./backend-sync-progress-DWR42uQV.js";import{a as Ee,i as De,n as Oe,o as ke}from"./workspace-BydSRtST.js";import{n as Ae,r as je,t as Me}from"./url-params-n7kU_WZ-.js";import{i as Ne}from"./use-menu-BVkqNEIx.js";import{n as Pe}from"./last-path-BbXWC3b3.js";import{t as Fe}from"./workspace-area-menu-Ba_9bGKs.js";import{t as Ie}from"./workspace-content-gate-D8bzGD9i.js";import{t as Le}from"./form-panel-Dz96K7Lv.js";import{a as Re,i as ze,n as Be,o as Ve,r as He,s as Ue,t as We}from"./content-app-view-C33Ip_rx.js";import{i as Ge,o as Ke,r as qe}from"./query-debug-tVbB_8Z6.js";var w=`session.open`,Je=`session.set`,Ye=`session.ids`,Xe=`session.materialize`,Ze=`session.close`,T=`session.delta`,E=e(n(),1),D=t();function Qe({workspaceId:e,workspaceName:t}){let[n,r]=(0,E.useState)([]),[i,a]=(0,E.useState)(new Set),s=t=>`${e}:${t.address}:${t.resyncStartedAt||``}`;(0,E.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 ce(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 l=n.filter(e=>!i.has(s(e)));return l.length?(0,D.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,D.jsxs)(`div`,{role:`status`,className:`mb-2 flex items-center gap-2 text-sm font-medium`,children:[(0,D.jsx)(c,{"aria-hidden":`true`,className:`h-4 w-4 animate-spin`}),(0,D.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,D.jsx)(`span`,{className:`block`,children:`Scanning storage`}),(0,D.jsx)(`span`,{className:`block truncate text-xs font-normal text-muted-foreground`,title:t,children:t})]}),(0,D.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,...l.map(s)])),children:(0,D.jsx)(o,{"aria-hidden":`true`,className:`h-4 w-4`})})]}),(0,D.jsx)(`div`,{className:`max-h-48 space-y-3 overflow-y-auto`,children:l.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,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,D.jsx)(`span`,{className:`truncate`,children:i}),(0,D.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:n===null?`${t} files`:`${t} / ${n}`})]}),(0,D.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,D.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 $e=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:null;function et(e){return`/${e}`.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`}function tt(e,t,n){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>tt(e,t,n));if(typeof e==`string`)return[{tree:null,kind:t,path:et(e)}];let r=$e(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:et(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 nt(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 rt(e,t,n=new Map){let r=$e(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:et(n)}],ids:O(r),unknown:!1}:{targets:[],ids:[],unknown:!0}}let i=[...tt(r.context,`context`,n),...tt(r.directory,`directory`,n)],a=$e(r.changed);a&&i.push(...tt(a.context,`context`,n),...tt(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 it(e,t){if(e.kind&&e.kind!==t.kind||e.tree&&e.tree!==t.tree)return!1;if(t.kind===`context`){let n=e=>et(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 at(e){return rt(`tree.refresh`,{treeName:e?.treeName,path:e?.path||`/`})}function ot(e,t,n){if(e.unknown||e.targets.length&&(t.wholeWorkspace||e.targets.some(e=>it(e,t))))return!0;if(e.ids.length&&n){let t=n instanceof Set?n:new Set(n);if(e.ids.some(e=>t.has(e)))return!0}return!1}function st(e,t,n={}){return m.request(w,{workspace:e,specs:t,opts:n})}function ct(e,t,n){return m.request(Je,{sessionId:e,label:t,spec:n})}function lt(e){return m.request(Ye,{sessionId:e})}function A(e,t={}){return m.request(Xe,{sessionId:e,...t})}function ut(e){return m.request(Ze,{sessionId:e})}function dt(e){return m.on(T,e)}var ft=100;function pt({workspaceRef:e,specs:t,opts:n,enabled:r=!0}){let[i,a]=(0,E.useState)([]),[o,s]=(0,E.useState)(0),[c,l]=(0,E.useState)(null),[u,d]=(0,E.useState)(null),f=(0,E.useRef)([]),p=(0,E.useRef)(new Map),h=(0,E.useRef)(null),g=(0,E.useRef)(null),_=(0,E.useRef)(null),ee=(0,E.useRef)({}),te=(0,E.useRef)(null),ne=(0,E.useMemo)(()=>JSON.stringify(t),[t]),re=(0,E.useMemo)(()=>JSON.stringify(n??{}),[n]),v=(0,E.useCallback)(()=>{let e=p.current;a(f.current.map(t=>e.get(t)).filter(Boolean))},[]),ie=(0,E.useCallback)(async e=>{let t=g.current;if(!t||e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=ft){let i=e.slice(r,r+ft),a=await pe(t,`/`,[],{ids:i,scope:`workspace`,limit:i.length});n.push(...a.payload||[])}return n},[]),y=(0,E.useCallback)(async(e,t,n)=>{if(t.length>0){let e=new Set(t);f.current=f.current.filter(t=>!e.has(t));for(let t of e)p.current.delete(t)}let r=e.filter(e=>!p.current.has(e)),i=new Set(f.current);for(let t of e)i.has(t)||(f.current.push(t),i.add(t));if(n!==null&&s(n),v(),r.length===0)return;let a=await ie(r);for(let e of a)p.current.set(e.id,e);let o=new Set(a.map(e=>e.id)),c=r.filter(e=>!o.has(e));if(c.length>0){let e=new Set(c);f.current=f.current.filter(t=>!e.has(t))}v()},[ie,v]),b=(0,E.useCallback)(async(e,t)=>{let n=e??[],r=new Set(n);f.current=f.current.filter(e=>r.has(e));for(let e of p.current.keys())r.has(e)||p.current.delete(e);let i=new Set(f.current),a=n.filter(e=>!i.has(e));await y(a,[],t)},[y]);(0,E.useEffect)(()=>{if(g.current=e??null,!r||!e)return;let t=!1,n=null,i=async()=>{try{let r=await st(e,JSON.parse(ne),JSON.parse(re));if(t){ut(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&&ut(e).catch(()=>{}),h.current=null,f.current=[],p.current=new Map,l(null),a([]),s(0)}},[e,ne,re,r]),(0,E.useEffect)(()=>{if(!c)return;let e=dt(e=>{if(e.sessionId===c){if(_.current!==null){te.current?.(_.current,ee.current);return}e.ids===void 0?y(e.added??[],e.removed??[],e.count):b(e.ids,e.count)}});return()=>{e?.()}},[c,y,b]);let ae=(0,E.useCallback)(async()=>{let e=h.current;if(e)try{let t=await lt(e);await b(t.ids,t.count)}catch{}},[b]),oe=(0,E.useCallback)(async(e,t)=>{let n=h.current;if(!n)throw Error(`No open query session`);let r=await ct(n,e,t);if(_.current!==null){await te.current?.(_.current,ee.current);return}await b(r.ids,r.count)},[b]),se=(0,E.useCallback)(async(e,t={})=>{let n=h.current;if(!n)throw Error(`No open query session`);if(_.current=e,ee.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),v()},[v,ae]);(0,E.useEffect)(()=>{te.current=se},[se]);let ce=(0,E.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 ct(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 mt({data:e,className:t}){let[n,r]=(0,E.useState)(!0),{rows:i,gapIndex:a,span:o}=(0,E.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,D.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 c=a>0?i[a].distance:null;return(0,D.jsxs)(`div`,{className:u(`rounded-md border border-border bg-muted/30 text-xs`,t),children:[(0,D.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,D.jsx)(s,{className:`h-3.5 w-3.5`}):(0,D.jsx)(l,{className:`h-3.5 w-3.5`}),`Query debug`,(0,D.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`: image distances for “`,e.query,`” (`,i.length,` nearest, unfloored)`]})]}),n&&(0,D.jsxs)(`div`,{className:`space-y-2 border-t border-border px-3 py-2`,children:[(0,D.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Best-first cosine distance (0 = identical). Scroll to where the photos stop being relevant and set the image relevance floor just above that value in Settings → Database → Search tuning.`,c===null?(0,D.jsxs)(D.Fragment,{children:[` `,(0,D.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,D.jsxs)(D.Fragment,{children:[` A jump at `,(0,D.jsx)(`span`,{className:`font-mono`,children:c.toFixed(4)}),` (Δ`,o.biggest.toFixed(4),`, vs typical Δ`,o.median.toFixed(4),`) stands out (a likely boundary).`]})]}),(0,D.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:(0,D.jsx)(`table`,{className:`w-full font-mono text-[11px]`,children:(0,D.jsx)(`tbody`,{children:i.map((e,t)=>(0,D.jsxs)(`tr`,{className:u(`border-b border-border/40 last:border-0`,t===a&&`border-t-2 border-t-amber-500/70`),children:[(0,D.jsx)(`td`,{className:`py-0.5 pr-3 text-muted-foreground`,children:t+1}),(0,D.jsxs)(`td`,{className:`py-0.5 pr-3`,children:[`#`,e.id]}),(0,D.jsx)(`td`,{className:`py-0.5 tabular-nums`,children:e.distance.toFixed(4)}),t===a&&(0,D.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,D.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 ht(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 gt=new Map;function _t(e,t,n){return`${e}\0${t}\0${n}`}function vt(e,t,n,r,i,a,o=``,s=``,c=`path`){return`${_t(e,t,n)}\0${r}\0${i}\0${a}\0${o}\0${s}\0${c}`}function j(e,t,n){let r=_t(e,t,n);for(let e of gt.keys())e.startsWith(r)&&gt.delete(e)}function yt(e,t){let n=`${e}\0`;for(let[e,r]of gt){if(!e.startsWith(n))continue;let[,i,a,,,,,,o=`path`]=e.split(`\0`);ot(t,{tree:i,kind:S(i),path:a,wholeWorkspace:o.startsWith(`workspace`)},r.documents.map(e=>Number(e.id)))&&gt.delete(e)}}function bt(e,t){yt(t?.workspaceName??e,at(t))}function xt(){let{workspaceName:e}=r();return e?(0,D.jsx)(Ie,{workspaceName:e,children:(0,D.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),Ie=(()=>{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]:[]})(),[w,Je]=(0,E.useState)(null),[Ye,Xe]=(0,E.useState)(!0),[Ze,T]=(0,E.useState)([]),[$e,et]=(0,E.useState)(!1),[tt,O]=(0,E.useState)(0),k=qe(),[it,st]=(0,E.useState)(null),[ct,lt]=(0,E.useState)(k);ct!==k&&(lt(k),k||st(null));let[A,ut]=(0,E.useState)(`path`),[dt,ft]=(0,E.useState)(!1),[_t,xt]=(0,E.useState)(null),[M,St]=(0,E.useState)(null),[wt,Tt]=(0,E.useState)(``),[Et,Dt]=(0,E.useState)(!1),[Ot,kt]=(0,E.useState)(!1),[At,jt]=(0,E.useState)(!1),[N,Mt]=(0,E.useState)(null),[P,F]=(0,E.useState)(1),[I,Nt]=(0,E.useState)(50),[L,Pt]=(0,E.useState)(Ie),[Ft,It]=(0,E.useState)(null),{state:R,saveFilters:Lt,setSort:Rt,setAccentColor:zt,setMapDocuments:Bt}=Se(),Vt=R.filters.features.allOf,z=R.filters.features.anyOf,Ht=R.filters.features.noneOf,Ut=De(R.filters.timeline),Wt=Ee(R.filters.geo),Gt=ke(R.filters.lens,R.filters.geo.includeUnlocated),B=R.filters.lens.ids,Kt=[...Ut,...Wt,...Gt],qt=R.filters.sort??Oe,Jt=JSON.stringify({a:Vt,b:z,c:Ht,d:Kt,i:B,s:qt}),Yt=JSON.stringify({a:Vt,b:z,c:Ht,d:Kt,s:qt}),V=Ae(n.pathname).path,H=t??`context`,U=H===`backends`,[Xt,Zt]=(0,E.useState)([]);(0,E.useEffect)(()=>{!U||!e||ce(e).then(Zt).catch(()=>Zt([]))},[U,e]);let Qt=U?me(V,Xt):null,[$t,en]=(0,E.useState)(!1),tn=`${H}\0${V}`,[nn,rn]=(0,E.useState)(tn);nn!==tn&&(rn(tn),en(!1));let W=l.get(`layer`)===`1`,G=l.get(`layerId`)||null,[K,an]=(0,E.useState)(null),[q,on]=(0,E.useState)(null),sn=(0,E.useRef)(null);(0,E.useEffect)(()=>{sn.current=q},[q]);let[cn,ln]=(0,E.useState)(`left`),[un,dn]=(0,E.useState)([]),{openM1Drawer:fn,openM2Drawer:pn,goBack:mn}=Ne(),[hn,gn]=(0,E.useState)([]),J=(0,E.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,_n=(0,E.useRef)(null);(0,E.useEffect)(()=>{!e||!K||W||_n.current===`${e}/${H}`&&(V!==`/`&&!J||Pe(e,H,V))},[e,K,W,V,J,H]);let vn=(0,E.useMemo)(()=>W||A===`workspace`||L.length>0||S(H)!==`directory`?[]:ht(K,V),[K,V,H,W,A,L]),yn=W?null:V===`/`?K:J,X=be(),bn=`${H}\0${V}`,[xn,Sn]=(0,E.useState)(null),Cn=xn?.key===bn?xn.views:Ve(yn?.metadata),wn=X?.pinned&&X.view?[X.view,...Cn.filter(e=>e.id!==X.view.id)]:Cn,Tn=X?.pinned&&X.view?X.view.id:xn?.key===bn?xn.activeId:wn[0]?.id??ze.id,Z=wn.find(e=>e.id===Tn)??wn[0]??ze;(0,E.useEffect)(()=>{X?.selectView(Z)},[Z,X]);let En=U?void 0:X?.schema??Re(Z),Dn=En?[...Vt,En]:Vt,On=e=>{let t=wn.find(t=>t.id===e);t&&X?.selectView(t),F(1),dn([]),Sn({key:bn,views:wn,activeId:e})},kn=(t,n)=>{n&&n!==Tn&&(F(1),dn([]));let r=t.find(e=>e.id===(n??Tn));r&&X?.selectView(r),Sn({key:bn,views:t,activeId:n??Tn}),_(e,V,{metadata:{...yn?.metadata??{},views:t}},H).catch(()=>{s({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},An=Y===`canvas`&&typeof J?.querySpec?.query==`string`?J.querySpec.query:``,jn=Y===`canvas`?{label:J?.label,description:J?.description,color:J?.color}:null,{isPinned:Mn,pin:Nn,unpin:Pn,pins:Fn}=_e(),In=w?.name,Q=(0,E.useMemo)(()=>In&&Y===`canvas`&&!W?{workspaceName:In,treeName:H,path:V}:null,[In,Y,W,H,V]),Ln=Q?Mn(Q):!1,Rn=J?.id,zn=J?.label,Bn=(0,E.useCallback)(async()=>{if(Q)try{let e=Fn.find(e=>e.workspaceName===Q.workspaceName&&e.treeName===Q.treeName&&e.path===Q.path);e?await Pn(e.id):await Nn({...Q,layerId:Rn,label:zn})}catch(e){console.error(`Failed to update home pins:`,e)}},[Q,Fn,Nn,Pn,Rn,zn]),Vn=e?`${e}://${V===`/`?``:V.replace(/^\//,``)}`:``,Hn=Ce(w?.color)||null;(0,E.useEffect)(()=>(zt(Hn),()=>zt(null)),[Hn,zt]);let Un=(0,E.useCallback)(async t=>{let n=B;if(t?.anyOf?.length&&z.length&&(n=((await x(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 x(e,V,H,{limit:t?.limit,offset:t?.offset,page:t?.page,sortBy:t?.sortBy,order:t?.order,allOf:[...Vt,...t?.allOf??[]],anyOf:t?.anyOf?.length?t.anyOf:z,noneOf:Ht,filters:Kt,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,Jt,L]);(0,E.useEffect)(()=>{e&&(async()=>{Xe(!0);try{let t=await p.get(`${f.workspaces}/${e}`),n;n=t&&`workspace`in t?t.workspace:t,Je(n)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch workspace ${e}`;s({title:`Error`,description:n,variant:`destructive`}),Je(null)}finally{Xe(!1)}})()},[e,s]),(0,E.useEffect)(()=>{let e=e=>{let t=e.detail?.workspace;t&&Je(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 Wn=(B?.length??0)>0&&!W&&!($t&&Qt)&&L.length<=1,{documents:Gn,count:Kn,ready:qn,setCue:Jn,resync:Yn,rank:Xn}=pt({workspaceRef:e,specs:(0,E.useMemo)(()=>{let e={features:{allOf:Dn,anyOf:z,noneOf:Ht},filters:Kt};return A!==`workspace`&&(S(H)===`directory`?e.directory={tree:H,path:V}:e.context=V),[{label:`scope`,spec:e}]},[Yt,V,H,A,En]),opts:(0,E.useMemo)(()=>({mode:`live`,debounceMs:150}),[]),enabled:Wn}),Zn=Wn&&qn,Qn=(0,E.useRef)(!1);(0,E.useEffect)(()=>{Qn.current=Zn},[Zn]);let $n=L.length===1?L[0].trim():``;(0,E.useEffect)(()=>{qn&&Xn($n?{text:$n}:null,{limit:I,offset:(P-1)*I}).catch(()=>{})},[qn,$n,I,P,Xn]);let er=(B??[]).join(`,`);(0,E.useEffect)(()=>{qn&&Jn(`lens`,{ids:B??[]}).catch(()=>{})},[qn,er,Jn,B]);let tr=Zn?Gn:Ze,nr=Zn?Kn:tt,rr=(0,E.useRef)(new Set);(0,E.useEffect)(()=>{rr.current=new Set(tr.map(e=>Number(e.id)))},[tr]);let ir=R.geoSelection;(0,E.useEffect)(()=>{Bt(tr,w?.name??null)},[tr,w?.name,Bt]),(0,E.useEffect)(()=>()=>Bt([]),[Bt]);let ar=(0,E.useMemo)(()=>ir?tr.filter(e=>we(e,ir,R.filters.geo.includeUnlocated)):tr,[tr,ir,R.filters.geo.includeUnlocated]),or=le(V,Dn,{treeName:H,treeType:S(H),scope:A,queries:L,anyOf:z,noneOf:Ht,filters:Kt,ids:B,layerId:W&&G?G:void 0}),sr=JSON.stringify([e,or]),[cr,lr]=(0,E.useState)(``),[ur,dr]=(0,E.useState)(!1),fr=(0,E.useRef)(!1),pr=$e||ur||cr!==sr||Zn||!!ir,mr=(0,E.useRef)(0),hr=(0,E.useRef)(null);(0,E.useEffect)(()=>()=>{mr.current++,hr.current=null},[]);let gr=(0,E.useRef)(``),$=(0,E.useCallback)(async t=>{if(!e)return;if(Te(H,V)){mr.current++,hr.current=null,gr.current=``,T([]),O(0),et(!1);return}if(Qn.current)return;let n=`${$t&&Qt?`${A}:unfiled`:A}:${En??``}`,r=(B?.length??0)>0,i=vt(e,H,V,P,I,L.join(`␟`),Yt,W&&G?G:``,n),a=r&&i===gr.current;gr.current=i;let o=vt(e,H,V,P,I,L.join(`␟`),Jt,W&&G?G:``,n),c=`${o}\0${k}`;if(t?.silent&&hr.current?.key===c){hr.current.refreshPending=!0;return}let l=++mr.current,u=t?.silent||r||k?void 0:gt.get(o);u&&(T(u.documents),O(u.totalCount),lr(sr),et(!1)),(t?.silent??(a||!!u))||et(!0);let d={key:c,refreshPending:!1};hr.current=d;try{let t;t=$t&&Qt?await ge(e,Qt.driver,Qt.address,{linked:!1,limit:I,offset:(P-1)*I}):W&&G&&A!==`workspace`?await oe(e,H,G,{limit:I,page:P,queries:L,allOf:Dn,anyOf:z,noneOf:Ht,filters:Kt,ids:B,sortBy:qt.sortBy||void 0,order:qt.order}):await pe(e,V,Dn,{limit:I,page:P,treeName:H,treeType:H===`directory`||H===`backends`?`directory`:`context`,queries:L,anyOf:z,noneOf:Ht,filters:Kt,ids:B,sortBy:qt.sortBy||void 0,order:qt.order,scope:A,debug:k&&L.length>0,debugLimit:200});let n=t.payload||[],i=t.totalCount||t.count||0;if(!r&&!d.refreshPending&&gt.set(o,{documents:n,totalCount:i}),l!==mr.current)return;let s=t.debug,c=s?.imageDistances??s?.distances??null;st(c?{query:L[L.length-1]??``,distances:c}:null),T(a?e=>e.length===n.length&&e.every((e,t)=>e.id===n[t].id)?e:n:n),O(i),lr(sr)}catch(e){if(l!==mr.current)return;let t=e instanceof Error?e.message:`Failed to fetch documents`;s({title:`Error`,description:t,variant:`destructive`}),T([]),O(0)}finally{hr.current===d&&(hr.current=null),l===mr.current&&et(!1),l===mr.current&&d.refreshPending&&$({silent:!0})}},[e,V,H,G,W,P,I,w?.status,L,Jt,A,$t,k,En]);(0,E.useEffect)(()=>{$()},[$]),(0,E.useEffect)(()=>{let t=t=>{let n=t.detail;!n||n.workspaceName!==e||(on({treeName:n.treeName||`context`,path:je(n.path||`/`)}),ln(`left`))};return window.addEventListener(`workspace:open-to-side`,t),()=>window.removeEventListener(`workspace:open-to-side`,t)},[e,H,V]),(0,E.useEffect)(()=>{let t=t=>{let n=t.detail;if(!(n?.workspaceName&&n.workspaceName!==e)&&(e&&bt(e,n),ot(at(n),{tree:H,kind:S(H),path:V,wholeWorkspace:A===`workspace`}))){if(e&&j(e,H,V),Qn.current){Yn();return}$({silent:!0})}};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[$,e,V,H,A,Yn]);let _r=w?.name,vr=w?.id;(0,E.useEffect)(()=>{if(!e||!_r&&!vr)return;let t=[_r,vr].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=()=>{te(e).then(e=>{a||(i=nt(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,Qn.current){Yn();return}$({silent:!0})}},f=t=>n=>{(t.startsWith(`tree.created`)||t.startsWith(`tree.renamed`))&&o();let r=rt(t,n,i);yt(e,r);let a={tree:H,kind:S(H),path:V,wholeWorkspace:A===`workspace`},f=sn.current;f&&ot(r,{tree:f.treeName,kind:S(f.treeName),path:f.path})&&(u=f),ot(r,a,rr.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,vr,_r,H,V,A,$,Yn]);let yr=`${V}\0${H}\0${G??``}\0${A}`,[br,xr]=(0,E.useState)(yr);br!==yr&&(xr(yr),F(1),It(null));let Sr=`${V}\0${H}\0${G??``}`,[Cr,wr]=(0,E.useState)(Sr);Cr!==Sr&&(wr(Sr),ut(`path`));let Tr=(e,t)=>{let n=e===`/`?`canvas`:e.split(`/`).pop()||`canvas`;Tt(n),St({parentPath:e,captureView:t})},Er=l.get(`createCanvas`)===`1`,[Dr,Or]=(0,E.useState)(!1);Dr!==Er&&(Or(Er),Er&&Tr(V,!1)),(0,E.useEffect)(()=>{if(!Er)return;let e=new URLSearchParams(n.search);e.delete(`createCanvas`);let t=e.toString();o(`${n.pathname}${t?`?${t}`:``}${n.hash}`,{replace:!0})},[Er,V]);let kr=(0,E.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]),Ar=JSON.stringify([l.has(`q`),...Ie]),[jr,Mr]=(0,E.useState)(Ar);jr!==Ar&&(Mr(Ar),Pt(Ie),F(1));let Nr=`${Ar}\0${Y??``}\0${An}\0${V}\0${Ft??``}`,[Pr,Fr]=(0,E.useState)(Nr);Pr!==Nr&&(Fr(Nr),l.has(`q`)||Ie.length>0||Y!==`canvas`||Ft===V||(Pt(An?[An]:[]),F(1)));let Ir=(0,E.useCallback)(e=>{let t=e.trim();t&&(It(null),Pt(e=>{if(e.includes(t))return e;let n=[...e,t];return kr(n),F(1),n}))},[kr,It,Pt,F]),Lr=(0,E.useCallback)(e=>{Pt(t=>{let n=e<0?[]:t.filter((t,n)=>n!==e);return n.length===0&&It(V),kr(n),F(1),n})},[kr,V,It,Pt,F]),Rr=L.join(` `).trim(),zr=!!R.activeContextType&&(R.isDirty||Rr!==(Y===`canvas`?An:R.savedSearchQuery||``));!e&&K!==null&&an(null),(0,E.useEffect)(()=>{let t=!1;if(!e)return;let n=0,r=!1,i=(i=!1)=>{let a=++n;i&&fe(e,H),ee(e,H).then(i=>{!t&&a===n&&(r=!0,_n.current=`${e}/${H}`,an(i))}).catch(()=>{!t&&a===n&&!r&&an(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=C(e,vr);return()=>{t=!0,o(),window.removeEventListener(`workspace:tree:refresh`,a)}},[e,H,vr]),!(e&&Y===`canvas`&&!W)&&N!==null&&Mt(null),(0,E.useEffect)(()=>{let t=!1;if(!(!e||Y!==`canvas`||W))return ae(e,V,H).then(e=>{t||Mt(e)}).catch(()=>{t||Mt(null)}),()=>{t=!0}},[e,V,H,Y,W]);let Br=async()=>{if(w){ft(!0);try{let t=await ue(e||w.id);Je(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{ft(!1)}}},Vr=async t=>{if(!w)return;let n=c({title:`Removing…`,description:`Document from "${V}"`});try{await re(e||w.id,[t],V,[],H,Yr,{trashIfOrphaned:!0}),j(e||w.id,H,V),T(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`})}},Hr=async t=>{if(!w)return;let n=c({title:`Deleting…`,description:`Document from "${V}"`});try{await ie(e||w.id,[t],V,[],H,Yr),j(e||w.id,H,V),T(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`})}},Ur=async t=>{if(!w)return;let n=c({title:`Removing…`,description:`${t.length} document(s) from "${V}"`});try{await re(e||w.id,t,V,[],H,Yr,{trashIfOrphaned:!0}),j(e||w.id,H,V),T(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`})}},Wr=async t=>{if(!w)return;let n=c({title:`Deleting…`,description:`${t.length} document(s)`});try{await ie(e||w.id,t,V,[],H,Yr),j(e||w.id,H,V),T(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`})}},Gr=async t=>{if(!w)return;let n=c({title:`Destroying…`,description:`Document and its backend copies`});try{let r=await ne(e||w.id,[t]);if(r.failed?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}T(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`})}},Kr=async t=>{if(!w)return;let n=c({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await ne(e||w.id,t),i=new Set(r.successful?.filter(e=>e.docDeleted).map(e=>e.id)??[]);T(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`})}},qr=e=>{xt({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`})},Jr=e=>{xt({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`})},Yr=S(H),Xr=async(t,n,r={})=>{if(!e)return!1;let i=r.targetTreeName??H,a=r.targetTreeType??Yr,o=r.move??_t?.operation===`cut`,s=c({title:o?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let c=await b(e,t,n,i,a);if(c){j(e,i,t);let a=r.sourceTreeName||_t?.sourceTreeName,c=r.sourcePath||_t?.sourcePath;if((r.move??_t?.operation===`cut`)&&c&&a){let t=S(a);await re(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}"`}),xt(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}},Zr=async(t,n)=>{if(!e)return!1;try{let r=(await de(e,n,t,H,Yr)).length>0;return r&&(xe(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}},Qr=async()=>{if(!w||nr===0||pr||fr.current||window.prompt(`Type PURGE to permanently delete all ${nr} matching documents across all pages.`)!==`PURGE`)return;fr.current=!0,dr(!0);let t=c({title:`Purging…`,description:`${nr} matching document(s)`});try{let n=await y(e||w.id,or,nr);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||w.id,H,V),await $({silent:!0}),fr.current=!1,dr(!1)}},$r=()=>Tr(V,!0),ei=async()=>{if(!(!e||!M||!wt.trim())){Dt(!0);try{let t=wt.trim(),n=M.parentPath,r=n===`/`?`/${t}`:`${n}/${t}`,i={...R.filters,features:{...R.filters.features,allOf:Dn}};await se(e,r,H,M.captureView?{metadata:{toolbox:i},querySpec:{features:i.features,filters:[...De(R.filters.timeline),...Ee(R.filters.geo)],query:Rr||void 0,sort:R.filters.sort?.sortBy?R.filters.sort:null}}:{}),St(null),fe(e,H);try{let t=await ee(e,H,{force:!0});an(t)}catch{}window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e}})),o(Me(e,r,H))}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to create canvas`,variant:`destructive`})}finally{Dt(!1)}}},ti=async()=>{if(!(!e||Y!==`canvas`)){kt(!0);try{let t=N||await he(e,V,H);Mt(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{kt(!1)}}},ni=async()=>{if(N){kt(!0);try{await v(N.code),Mt(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{kt(!1)}}},ri=async()=>{if(!e||Y!==`canvas`||V===`/`)return;let t=jn?.label||V.split(`/`).pop()||`canvas`,n=N?` Its public link will stop working.`:``;if(window.confirm(`Delete canvas "${t}"? This cannot be undone.${n}`)){jt(!0);try{if(N)await v(N.code),Mt(null);else if(J?.locked){s({title:`Canvas is locked`,description:`Unlock it before deleting.`,variant:`destructive`});return}await g(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(Me(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{jt(!1)}}},ii=(0,E.useCallback)(async t=>{if(!e||!q)return;let n={treeName:H,path:V},r=cn===`left`?n:q,i=cn===`left`?q:n,a=cn===`left`?un:hn;if(a.length===0){s({title:`Nothing selected`,description:`Tick documents in the focused pane first.`});return}let o=S(i.treeName),l=c({title:t?`Moving…`:`Copying…`,description:`${a.length} document(s) → "${i.path}"`});try{if(!await b(e,i.path,a,i.treeName,o)){l.done();return}if(j(e,i.treeName,i.path),t){let t=S(r.treeName);await re(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,cn,H,V,un,hn,s,c]);if((0,E.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(),ii(e.key===`F6`))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[q,ii]),Ye)return(0,D.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,D.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,D.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,D.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading workspace...`})]})});if(!w)return(0,D.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Workspace not found.`});let ai=Y===`canvas`&&!W&&!!J,oi=!ai&&!U&&yn?(0,D.jsx)(He,{views:wn,activeId:Tn,onSelect:On,onSave:kn,accentColor:Ce(w.color),onOpenToSide:e=>{on({treeName:H,path:V,viewId:e}),ln(`right`)}}):void 0,si=Qt||w.status!==`active`?(0,D.jsxs)(D.Fragment,{children:[Qt&&(0,D.jsx)(`button`,{type:`button`,onClick:()=>{en(!$t),F(1)},"aria-pressed":$t,className:u(`min-h-10 rounded-md border px-2 text-xs`,$t&&`bg-warning/15 text-warning`),children:`Unfiled only`}),w.status!==`active`&&(0,D.jsx)(`button`,{type:`button`,onClick:Br,disabled:dt,className:`min-h-10 rounded-md border px-2 text-xs`,children:dt?`Starting…`:`Start`})]}):void 0,ci=Te(H,V)?V===`/Trash`?(0,D.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,D.jsx)(Ge,{workspaceName:e||w.id})}):(0,D.jsx)(Ke,{workspace:e||w.id,path:V,onNavigate:t=>o(Me(e,t,`backends`))},e):(0,D.jsx)(Ue,{navigationTabs:oi,navigationActions:si,onBack:mn,accentColor:Ce(w.color),urlType:W?S(H)===`directory`?`${H}-layer`:`context-layer`:Y===`canvas`?`canvas`:S(H)===`directory`?H:`context`,urlDisplay:Vn,contextPath:V,treeName:H,workspaceId:e||w.id,workspaceLabel:w.label||w.name,workspaceIcon:w.icon,documentSchema:En,documents:ar,isLoading:$e,totalCount:nr,currentPage:P,pageSize:I,onPageChange:F,onPageSizeChange:e=>{Nt(e),F(1)},onRemoveDocument:V===`/`?void 0:Vr,onDeleteDocument:Hr,onDestroyDocument:Gr,onRemoveDocuments:V===`/`?void 0:Ur,onDeleteDocuments:Wr,onDestroyDocuments:Kr,onCopyDocuments:qr,onCutDocuments:Jr,onPasteDocuments:U?void 0:Xr,onImportDocuments:U?void 0:Zr,onSelectionChange:dn,onBrowseTree:()=>pn(`workspaces`,`detail`,e??null),onBrowseWorkspaces:()=>fn(`workspaces`),onNavigatePath:t=>o(Me(e,t,H)),folders:vn,onOpenFolder:t=>o(Me(e,je(t),H)),scope:A,onScopeChange:ut,pastedDocumentIds:_t?.documentIds,linkTree:K,onPurgeDocuments:U?void 0:Qr,disablePurgeDocuments:pr,canvasInfo:jn??void 0,isCanvasPinned:Ln,onTogglePinCanvas:Q?Bn:void 0,onSaveAsCanvas:K&&Y!==`canvas`&&!W&&!U?$r:void 0,onShareCanvas:Y===`canvas`&&!W?ti:void 0,onUnshareCanvas:N?ni:void 0,onDeleteCanvas:Y===`canvas`&&!W?ri:void 0,isSharingCanvas:Ot,isDeletingCanvas:At,isCanvasShared:!!N,isCanvasLocked:!!J?.locked,backendSearchQueries:L,onBackendSearch:Ir,serverSort:R.filters.sort,onServerSortChange:Rt,onRemoveBackendQuery:Lr,canSaveChanges:zr,isSavingChanges:R.isSaving,onSaveChanges:Lt,contentBanner:k&&it?(0,D.jsx)(mt,{data:it,className:`mb-3`}):null,children:ai&&J?(0,D.jsx)(ve,{workspaceId:e||w.id,treeName:H,path:V,layerId:J.id,querySpec:J.querySpec,metadata:J.metadata,isLocked:!!J.locked,fetchDocuments:R.isDirty?Un:void 0}):!U&&Z.kind===`columns`?(0,D.jsx)(Be,{documents:ar,workspaceId:e||w.id,columns:Z.columns??[],onColumnsChange:e=>kn(wn.map(t=>t.id===Z.id?{...t,columns:e}:t))}):!U&&Z.kind===`app`&&Z.app&&Z.app!==`notes`?(0,D.jsx)(We,{app:Z.app,workspaceId:e||w.id,treeName:H,path:V}):null});return(0,D.jsxs)(Fe,{workspaceId:e||w.id,treeName:H,path:V,headerOnly:!0,className:`relative flex flex-col h-full min-h-0`,children:[(0,D.jsx)(Qe,{workspaceId:w.id,workspaceName:w.label||w.name},w.id),Te(H,V)&&(0,D.jsx)(ye,{workspace:w.label||w.name,workspaceIcon:w.icon,tree:H,path:V,onBack:mn,onBrowseTree:()=>pn(`workspaces`,`detail`,e||w.id),onBrowseWorkspaces:()=>fn(`workspaces`),onNavigatePath:t=>o(Me(e,t,H)),accentColor:Ce(w.color)}),M&&(0,D.jsx)(`div`,{className:`shrink-0 px-2 pt-2`,children:(0,D.jsx)(Le,{title:`New canvas`,onClose:()=>St(null),children:(0,D.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ei()},className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{htmlFor:`canvas-name`,className:`mb-1 block text-sm font-medium`,children:`Name`}),(0,D.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:wt,onChange:e=>Tt(e.target.value),onKeyDown:e=>{e.key===`Escape`&&St(null)},autoFocus:!0})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`span`,{className:`mb-1 block text-sm font-medium`,children:`Parent path`}),(0,D.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,D.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,D.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:M.captureView,onChange:e=>St({...M,captureView:e.target.checked})}),(0,D.jsxs)(`span`,{children:[`Capture the current view`,(0,D.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Freezes the active filters, search and sort into the canvas.`})]})]}),(0,D.jsxs)(`div`,{className:`flex gap-2`,children:[(0,D.jsx)(d,{type:`submit`,disabled:!wt.trim()||Et,children:Et?`Creating…`:`Create canvas`}),(0,D.jsx)(d,{type:`button`,variant:`outline`,onClick:()=>St(null),children:`Cancel`})]})]})})}),(0,D.jsxs)(`div`,{"data-canvas-panes":!0,className:`flex-1 min-h-0 flex gap-2`,children:[(0,D.jsx)(`div`,{"data-canvas-pane":!0,className:u(`flex-1 min-w-0 bg-background overflow-hidden`,q&&(cn===`left`?`ring-2 ring-primary`:`ring-1 ring-primary/20`)),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||ln(`left`)},children:ci}),q&&e&&(0,D.jsx)(Ct,{workspaceName:e,workspaceLabel:w.label||w.name,workspaceIcon:w.icon,pane:q,isFocused:cn===`right`,clipboard:_t,setClipboard:xt,onFocus:()=>ln(`right`),onSelectionChange:gn,onNavigate:e=>on(t=>t&&{...t,path:e,viewId:void 0}),onClose:()=>{on(null),ln(`left`),gn([])}})]})]})}function St(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 Ct({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}=Ne(),{showToast:m,showProgress:g}=h(),[_,te]=(0,E.useState)(null),[v,y]=(0,E.useState)([]),[ae,oe]=(0,E.useState)(!1),[se,ce]=(0,E.useState)(0),[le,ue]=(0,E.useState)(1),[de,me]=(0,E.useState)(50),x=S(r.treeName),he=St(_,r.path),ge=he?.type===`canvas`,_e=(0,E.useMemo)(()=>x===`directory`?ht(_,r.path):[],[_,r.path,x]),ve=r.viewId?Ve(he?.metadata).find(e=>e.id===r.viewId)??null:null,ye=`${e}://${r.path===`/`?``:r.path.replace(/^\//,``)}`,be=Re(ve),C=(0,E.useCallback)(async()=>{if(Te(r.treeName,r.path)){y([]),ce(0),oe(!1);return}let t=vt(e,r.treeName,r.path,le,de,``,be??``),n=gt.get(t);if(n){y(n.documents),ce(n.totalCount);return}oe(!0);try{let n=await pe(e,r.path,be?[be]:[],{limit:de,page:le,treeName:r.treeName,treeType:x}),i=n.payload||[],a=n.totalCount||n.count||0;y(i),ce(a),gt.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`}),y([]),ce(0)}finally{oe(!1)}},[e,r.path,r.treeName,x,de,le,m,be]);(0,E.useEffect)(()=>{let t=!1,n=0,i=!1,a=(a=!1)=>{let o=++n;a&&fe(e,r.treeName),ee(e,r.treeName).then(e=>{!t&&o===n&&(i=!0,te(e))}).catch(()=>{!t&&o===n&&!i&&te(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,E.useEffect)(()=>{C()},[C]),(0,E.useEffect)(()=>{let t=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||(bt(e,n),ot(at(n),{tree:r.treeName,kind:S(r.treeName),path:r.path})&&(j(e,r.treeName,r.path),C()))};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[C,e,r.treeName,r.path]);let xe=(0,E.useCallback)(async(t,n,i={})=>{let s=i.targetTreeName??r.treeName,c=i.targetTreeType??x,l=i.move??a?.operation===`cut`,u=g({title:l?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let r=await b(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=S(c);await re(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 C(),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,C,g,a,o]),Se=(0,E.useCallback)(()=>{j(e,r.treeName,r.path),C()},[e,r.treeName,r.path,C]),Ce=(0,E.useCallback)(async t=>{let n=g({title:`Removing…`,description:`${t.length} document(s) from "${r.path}"`});try{await re(e,t,r.path,[],r.treeName,x),Se(),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,Se,g]),we=(0,E.useCallback)(async t=>{let n=g({title:`Deleting…`,description:`${t.length} document(s)`});try{await ie(e,t,r.path,[],r.treeName,x),Se(),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,Se,g]),Ee=(0,E.useCallback)(async t=>{let n=g({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await ne(e,t);if(r.failed?.length&&!r.successful?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}Se();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,Se,g]);return(0,D.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,D.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`}),Te(r.treeName,r.path)?r.path===`/Trash`?(0,D.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,D.jsx)(Ge,{workspaceName:e})}):(0,D.jsx)(Ke,{workspace:e,path:r.path,onNavigate:l||(()=>{})}):(0,D.jsx)(Ue,{frameContent:!1,onBrowseWorkspaces:()=>f(`workspaces`),onBrowseTree:()=>p(`workspaces`,`detail`,e),urlType:ge?`canvas`:x===`directory`?r.treeName:`context`,urlDisplay:ye,contextPath:r.path,treeName:r.treeName,workspaceId:e,workspaceLabel:t,workspaceIcon:n,documentSchema:be,documents:v,isLoading:ae,totalCount:se,currentPage:le,pageSize:de,onPageChange:ue,onPageSizeChange:e=>{me(e),ue(1)},onRemoveDocument:r.path===`/`?void 0:e=>Ce([e]),onRemoveDocuments:r.path===`/`?void 0:Ce,onDeleteDocument:e=>we([e]),onDeleteDocuments:we,onDestroyDocument:e=>Ee([e]),onDestroyDocuments:Ee,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:xe,onSelectionChange:c,pastedDocumentIds:a?.documentIds,linkTree:_,folders:_e,onOpenFolder:l,onNavigatePath:l,canvasInfo:ge?{label:he?.label,description:he?.description,color:he?.color}:void 0,children:ve?.kind===`columns`?(0,D.jsx)(Be,{documents:v,workspaceId:e,columns:ve.columns??[],onColumnsChange:()=>{},readOnly:!0}):ve?.kind===`app`&&ve.app&&ve.app!==`notes`?(0,D.jsx)(We,{app:ve.app,workspaceId:e,treeName:r.treeName,path:r.path}):null})]})}export{xt 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,Vr as s,dn as c,zr as l}from"./ui-BSqPn1LJ.js";import{t as u}from"./utils-2pl1SbIp.js";import{t as d}from"./button-Bv4zA1qr.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{$t as g,En as _,K as ee,Nt as te,O as ne,Qt as re,S as v,T as ie,Ut as y,Vt as b,Z as ae,at as oe,b as se,bt as ce,d as le,dn as ue,dt as de,gt as fe,it as pe,o as me,q as x,v as he,vt as ge,yn as S}from"./workspace-CJ1PWQ29.js";import{n as _e,r as ve}from"./use-canvas-pins-CZBfEB5E.js";import{u as ye}from"./ObjectPropertiesCard-DDcRLpsW.js";import{h as be,i as C,r as xe}from"./document-list-BiogH4tf.js";import{n as Se}from"./use-toolbox-Ck_cLGgf.js";import{i as Ce}from"./color-DFEH4BfK.js";import{t as we}from"./geo-CZfs0E-x.js";import{c as Te}from"./backend-sync-progress-DWR42uQV.js";import{a as Ee,i as De,n as Oe,o as ke}from"./workspace-BydSRtST.js";import{n as Ae,r as je,t as Me}from"./url-params-n7kU_WZ-.js";import{i as Ne}from"./use-menu-BVkqNEIx.js";import{n as Pe}from"./last-path-BbXWC3b3.js";import{t as Fe}from"./workspace-area-menu-Ba_9bGKs.js";import{t as Ie}from"./workspace-content-gate-D8bzGD9i.js";import{t as Le}from"./form-panel-Dz96K7Lv.js";import{a as Re,i as ze,n as Be,o as Ve,r as He,s as Ue,t as We}from"./content-app-view-BUi8HG1r.js";import{i as Ge,o as Ke,r as qe}from"./query-debug-tVbB_8Z6.js";var w=`session.open`,Je=`session.set`,Ye=`session.ids`,Xe=`session.materialize`,Ze=`session.close`,T=`session.delta`,E=e(n(),1),D=t();function Qe({workspaceId:e,workspaceName:t}){let[n,r]=(0,E.useState)([]),[i,a]=(0,E.useState)(new Set),s=t=>`${e}:${t.address}:${t.resyncStartedAt||``}`;(0,E.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 ce(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 l=n.filter(e=>!i.has(s(e)));return l.length?(0,D.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,D.jsxs)(`div`,{role:`status`,className:`mb-2 flex items-center gap-2 text-sm font-medium`,children:[(0,D.jsx)(c,{"aria-hidden":`true`,className:`h-4 w-4 animate-spin`}),(0,D.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,D.jsx)(`span`,{className:`block`,children:`Scanning storage`}),(0,D.jsx)(`span`,{className:`block truncate text-xs font-normal text-muted-foreground`,title:t,children:t})]}),(0,D.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,...l.map(s)])),children:(0,D.jsx)(o,{"aria-hidden":`true`,className:`h-4 w-4`})})]}),(0,D.jsx)(`div`,{className:`max-h-48 space-y-3 overflow-y-auto`,children:l.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,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs`,children:[(0,D.jsx)(`span`,{className:`truncate`,children:i}),(0,D.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:n===null?`${t} files`:`${t} / ${n}`})]}),(0,D.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,D.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 $e=e=>e&&typeof e==`object`&&!Array.isArray(e)?e:null;function et(e){return`/${e}`.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`}function tt(e,t,n){if(e==null)return[];if(Array.isArray(e))return e.flatMap(e=>tt(e,t,n));if(typeof e==`string`)return[{tree:null,kind:t,path:et(e)}];let r=$e(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:et(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 nt(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 rt(e,t,n=new Map){let r=$e(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:et(n)}],ids:O(r),unknown:!1}:{targets:[],ids:[],unknown:!0}}let i=[...tt(r.context,`context`,n),...tt(r.directory,`directory`,n)],a=$e(r.changed);a&&i.push(...tt(a.context,`context`,n),...tt(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 it(e,t){if(e.kind&&e.kind!==t.kind||e.tree&&e.tree!==t.tree)return!1;if(t.kind===`context`){let n=e=>et(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 at(e){return rt(`tree.refresh`,{treeName:e?.treeName,path:e?.path||`/`})}function ot(e,t,n){if(e.unknown||e.targets.length&&(t.wholeWorkspace||e.targets.some(e=>it(e,t))))return!0;if(e.ids.length&&n){let t=n instanceof Set?n:new Set(n);if(e.ids.some(e=>t.has(e)))return!0}return!1}function st(e,t,n={}){return m.request(w,{workspace:e,specs:t,opts:n})}function ct(e,t,n){return m.request(Je,{sessionId:e,label:t,spec:n})}function lt(e){return m.request(Ye,{sessionId:e})}function A(e,t={}){return m.request(Xe,{sessionId:e,...t})}function ut(e){return m.request(Ze,{sessionId:e})}function dt(e){return m.on(T,e)}var ft=100;function pt({workspaceRef:e,specs:t,opts:n,enabled:r=!0}){let[i,a]=(0,E.useState)([]),[o,s]=(0,E.useState)(0),[c,l]=(0,E.useState)(null),[u,d]=(0,E.useState)(null),f=(0,E.useRef)([]),p=(0,E.useRef)(new Map),h=(0,E.useRef)(null),g=(0,E.useRef)(null),_=(0,E.useRef)(null),ee=(0,E.useRef)({}),te=(0,E.useRef)(null),ne=(0,E.useMemo)(()=>JSON.stringify(t),[t]),re=(0,E.useMemo)(()=>JSON.stringify(n??{}),[n]),v=(0,E.useCallback)(()=>{let e=p.current;a(f.current.map(t=>e.get(t)).filter(Boolean))},[]),ie=(0,E.useCallback)(async e=>{let t=g.current;if(!t||e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=ft){let i=e.slice(r,r+ft),a=await pe(t,`/`,[],{ids:i,scope:`workspace`,limit:i.length});n.push(...a.payload||[])}return n},[]),y=(0,E.useCallback)(async(e,t,n)=>{if(t.length>0){let e=new Set(t);f.current=f.current.filter(t=>!e.has(t));for(let t of e)p.current.delete(t)}let r=e.filter(e=>!p.current.has(e)),i=new Set(f.current);for(let t of e)i.has(t)||(f.current.push(t),i.add(t));if(n!==null&&s(n),v(),r.length===0)return;let a=await ie(r);for(let e of a)p.current.set(e.id,e);let o=new Set(a.map(e=>e.id)),c=r.filter(e=>!o.has(e));if(c.length>0){let e=new Set(c);f.current=f.current.filter(t=>!e.has(t))}v()},[ie,v]),b=(0,E.useCallback)(async(e,t)=>{let n=e??[],r=new Set(n);f.current=f.current.filter(e=>r.has(e));for(let e of p.current.keys())r.has(e)||p.current.delete(e);let i=new Set(f.current),a=n.filter(e=>!i.has(e));await y(a,[],t)},[y]);(0,E.useEffect)(()=>{if(g.current=e??null,!r||!e)return;let t=!1,n=null,i=async()=>{try{let r=await st(e,JSON.parse(ne),JSON.parse(re));if(t){ut(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&&ut(e).catch(()=>{}),h.current=null,f.current=[],p.current=new Map,l(null),a([]),s(0)}},[e,ne,re,r]),(0,E.useEffect)(()=>{if(!c)return;let e=dt(e=>{if(e.sessionId===c){if(_.current!==null){te.current?.(_.current,ee.current);return}e.ids===void 0?y(e.added??[],e.removed??[],e.count):b(e.ids,e.count)}});return()=>{e?.()}},[c,y,b]);let ae=(0,E.useCallback)(async()=>{let e=h.current;if(e)try{let t=await lt(e);await b(t.ids,t.count)}catch{}},[b]),oe=(0,E.useCallback)(async(e,t)=>{let n=h.current;if(!n)throw Error(`No open query session`);let r=await ct(n,e,t);if(_.current!==null){await te.current?.(_.current,ee.current);return}await b(r.ids,r.count)},[b]),se=(0,E.useCallback)(async(e,t={})=>{let n=h.current;if(!n)throw Error(`No open query session`);if(_.current=e,ee.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),v()},[v,ae]);(0,E.useEffect)(()=>{te.current=se},[se]);let ce=(0,E.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 ct(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 mt({data:e,className:t}){let[n,r]=(0,E.useState)(!0),{rows:i,gapIndex:a,span:o}=(0,E.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,D.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 c=a>0?i[a].distance:null;return(0,D.jsxs)(`div`,{className:u(`rounded-md border border-border bg-muted/30 text-xs`,t),children:[(0,D.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,D.jsx)(s,{className:`h-3.5 w-3.5`}):(0,D.jsx)(l,{className:`h-3.5 w-3.5`}),`Query debug`,(0,D.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`: image distances for “`,e.query,`” (`,i.length,` nearest, unfloored)`]})]}),n&&(0,D.jsxs)(`div`,{className:`space-y-2 border-t border-border px-3 py-2`,children:[(0,D.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Best-first cosine distance (0 = identical). Scroll to where the photos stop being relevant and set the image relevance floor just above that value in Settings → Database → Search tuning.`,c===null?(0,D.jsxs)(D.Fragment,{children:[` `,(0,D.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,D.jsxs)(D.Fragment,{children:[` A jump at `,(0,D.jsx)(`span`,{className:`font-mono`,children:c.toFixed(4)}),` (Δ`,o.biggest.toFixed(4),`, vs typical Δ`,o.median.toFixed(4),`) stands out (a likely boundary).`]})]}),(0,D.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:(0,D.jsx)(`table`,{className:`w-full font-mono text-[11px]`,children:(0,D.jsx)(`tbody`,{children:i.map((e,t)=>(0,D.jsxs)(`tr`,{className:u(`border-b border-border/40 last:border-0`,t===a&&`border-t-2 border-t-amber-500/70`),children:[(0,D.jsx)(`td`,{className:`py-0.5 pr-3 text-muted-foreground`,children:t+1}),(0,D.jsxs)(`td`,{className:`py-0.5 pr-3`,children:[`#`,e.id]}),(0,D.jsx)(`td`,{className:`py-0.5 tabular-nums`,children:e.distance.toFixed(4)}),t===a&&(0,D.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,D.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 ht(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 gt=new Map;function _t(e,t,n){return`${e}\0${t}\0${n}`}function vt(e,t,n,r,i,a,o=``,s=``,c=`path`){return`${_t(e,t,n)}\0${r}\0${i}\0${a}\0${o}\0${s}\0${c}`}function j(e,t,n){let r=_t(e,t,n);for(let e of gt.keys())e.startsWith(r)&&gt.delete(e)}function yt(e,t){let n=`${e}\0`;for(let[e,r]of gt){if(!e.startsWith(n))continue;let[,i,a,,,,,,o=`path`]=e.split(`\0`);ot(t,{tree:i,kind:S(i),path:a,wholeWorkspace:o.startsWith(`workspace`)},r.documents.map(e=>Number(e.id)))&&gt.delete(e)}}function bt(e,t){yt(t?.workspaceName??e,at(t))}function xt(){let{workspaceName:e}=r();return e?(0,D.jsx)(Ie,{workspaceName:e,children:(0,D.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),Ie=(()=>{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]:[]})(),[w,Je]=(0,E.useState)(null),[Ye,Xe]=(0,E.useState)(!0),[Ze,T]=(0,E.useState)([]),[$e,et]=(0,E.useState)(!1),[tt,O]=(0,E.useState)(0),k=qe(),[it,st]=(0,E.useState)(null),[ct,lt]=(0,E.useState)(k);ct!==k&&(lt(k),k||st(null));let[A,ut]=(0,E.useState)(`path`),[dt,ft]=(0,E.useState)(!1),[_t,xt]=(0,E.useState)(null),[M,St]=(0,E.useState)(null),[wt,Tt]=(0,E.useState)(``),[Et,Dt]=(0,E.useState)(!1),[Ot,kt]=(0,E.useState)(!1),[At,jt]=(0,E.useState)(!1),[N,Mt]=(0,E.useState)(null),[P,F]=(0,E.useState)(1),[I,Nt]=(0,E.useState)(50),[L,Pt]=(0,E.useState)(Ie),[Ft,It]=(0,E.useState)(null),{state:R,saveFilters:Lt,setSort:Rt,setAccentColor:zt,setMapDocuments:Bt}=Se(),Vt=R.filters.features.allOf,z=R.filters.features.anyOf,Ht=R.filters.features.noneOf,Ut=De(R.filters.timeline),Wt=Ee(R.filters.geo),Gt=ke(R.filters.lens,R.filters.geo.includeUnlocated),B=R.filters.lens.ids,Kt=[...Ut,...Wt,...Gt],qt=R.filters.sort??Oe,Jt=JSON.stringify({a:Vt,b:z,c:Ht,d:Kt,i:B,s:qt}),Yt=JSON.stringify({a:Vt,b:z,c:Ht,d:Kt,s:qt}),V=Ae(n.pathname).path,H=t??`context`,U=H===`backends`,[Xt,Zt]=(0,E.useState)([]);(0,E.useEffect)(()=>{!U||!e||ce(e).then(Zt).catch(()=>Zt([]))},[U,e]);let Qt=U?me(V,Xt):null,[$t,en]=(0,E.useState)(!1),tn=`${H}\0${V}`,[nn,rn]=(0,E.useState)(tn);nn!==tn&&(rn(tn),en(!1));let W=l.get(`layer`)===`1`,G=l.get(`layerId`)||null,[K,an]=(0,E.useState)(null),[q,on]=(0,E.useState)(null),sn=(0,E.useRef)(null);(0,E.useEffect)(()=>{sn.current=q},[q]);let[cn,ln]=(0,E.useState)(`left`),[un,dn]=(0,E.useState)([]),{openM1Drawer:fn,openM2Drawer:pn,goBack:mn}=Ne(),[hn,gn]=(0,E.useState)([]),J=(0,E.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,_n=(0,E.useRef)(null);(0,E.useEffect)(()=>{!e||!K||W||_n.current===`${e}/${H}`&&(V!==`/`&&!J||Pe(e,H,V))},[e,K,W,V,J,H]);let vn=(0,E.useMemo)(()=>W||A===`workspace`||L.length>0||S(H)!==`directory`?[]:ht(K,V),[K,V,H,W,A,L]),yn=W?null:V===`/`?K:J,X=be(),bn=`${H}\0${V}`,[xn,Sn]=(0,E.useState)(null),Cn=xn?.key===bn?xn.views:Ve(yn?.metadata),wn=X?.pinned&&X.view?[X.view,...Cn.filter(e=>e.id!==X.view.id)]:Cn,Tn=X?.pinned&&X.view?X.view.id:xn?.key===bn?xn.activeId:wn[0]?.id??ze.id,Z=wn.find(e=>e.id===Tn)??wn[0]??ze;(0,E.useEffect)(()=>{X?.selectView(Z)},[Z,X]);let En=U?void 0:X?.schema??Re(Z),Dn=En?[...Vt,En]:Vt,On=e=>{let t=wn.find(t=>t.id===e);t&&X?.selectView(t),F(1),dn([]),Sn({key:bn,views:wn,activeId:e})},kn=(t,n)=>{n&&n!==Tn&&(F(1),dn([]));let r=t.find(e=>e.id===(n??Tn));r&&X?.selectView(r),Sn({key:bn,views:t,activeId:n??Tn}),_(e,V,{metadata:{...yn?.metadata??{},views:t}},H).catch(()=>{s({title:`View not saved`,description:`Could not persist views to the layer`,variant:`destructive`})})},An=Y===`canvas`&&typeof J?.querySpec?.query==`string`?J.querySpec.query:``,jn=Y===`canvas`?{label:J?.label,description:J?.description,color:J?.color}:null,{isPinned:Mn,pin:Nn,unpin:Pn,pins:Fn}=_e(),In=w?.name,Q=(0,E.useMemo)(()=>In&&Y===`canvas`&&!W?{workspaceName:In,treeName:H,path:V}:null,[In,Y,W,H,V]),Ln=Q?Mn(Q):!1,Rn=J?.id,zn=J?.label,Bn=(0,E.useCallback)(async()=>{if(Q)try{let e=Fn.find(e=>e.workspaceName===Q.workspaceName&&e.treeName===Q.treeName&&e.path===Q.path);e?await Pn(e.id):await Nn({...Q,layerId:Rn,label:zn})}catch(e){console.error(`Failed to update home pins:`,e)}},[Q,Fn,Nn,Pn,Rn,zn]),Vn=e?`${e}://${V===`/`?``:V.replace(/^\//,``)}`:``,Hn=Ce(w?.color)||null;(0,E.useEffect)(()=>(zt(Hn),()=>zt(null)),[Hn,zt]);let Un=(0,E.useCallback)(async t=>{let n=B;if(t?.anyOf?.length&&z.length&&(n=((await x(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 x(e,V,H,{limit:t?.limit,offset:t?.offset,page:t?.page,sortBy:t?.sortBy,order:t?.order,allOf:[...Vt,...t?.allOf??[]],anyOf:t?.anyOf?.length?t.anyOf:z,noneOf:Ht,filters:Kt,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,Jt,L]);(0,E.useEffect)(()=>{e&&(async()=>{Xe(!0);try{let t=await p.get(`${f.workspaces}/${e}`),n;n=t&&`workspace`in t?t.workspace:t,Je(n)}catch(t){let n=t instanceof Error?t.message:`Failed to fetch workspace ${e}`;s({title:`Error`,description:n,variant:`destructive`}),Je(null)}finally{Xe(!1)}})()},[e,s]),(0,E.useEffect)(()=>{let e=e=>{let t=e.detail?.workspace;t&&Je(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 Wn=(B?.length??0)>0&&!W&&!($t&&Qt)&&L.length<=1,{documents:Gn,count:Kn,ready:qn,setCue:Jn,resync:Yn,rank:Xn}=pt({workspaceRef:e,specs:(0,E.useMemo)(()=>{let e={features:{allOf:Dn,anyOf:z,noneOf:Ht},filters:Kt};return A!==`workspace`&&(S(H)===`directory`?e.directory={tree:H,path:V}:e.context=V),[{label:`scope`,spec:e}]},[Yt,V,H,A,En]),opts:(0,E.useMemo)(()=>({mode:`live`,debounceMs:150}),[]),enabled:Wn}),Zn=Wn&&qn,Qn=(0,E.useRef)(!1);(0,E.useEffect)(()=>{Qn.current=Zn},[Zn]);let $n=L.length===1?L[0].trim():``;(0,E.useEffect)(()=>{qn&&Xn($n?{text:$n}:null,{limit:I,offset:(P-1)*I}).catch(()=>{})},[qn,$n,I,P,Xn]);let er=(B??[]).join(`,`);(0,E.useEffect)(()=>{qn&&Jn(`lens`,{ids:B??[]}).catch(()=>{})},[qn,er,Jn,B]);let tr=Zn?Gn:Ze,nr=Zn?Kn:tt,rr=(0,E.useRef)(new Set);(0,E.useEffect)(()=>{rr.current=new Set(tr.map(e=>Number(e.id)))},[tr]);let ir=R.geoSelection;(0,E.useEffect)(()=>{Bt(tr,w?.name??null)},[tr,w?.name,Bt]),(0,E.useEffect)(()=>()=>Bt([]),[Bt]);let ar=(0,E.useMemo)(()=>ir?tr.filter(e=>we(e,ir,R.filters.geo.includeUnlocated)):tr,[tr,ir,R.filters.geo.includeUnlocated]),or=le(V,Dn,{treeName:H,treeType:S(H),scope:A,queries:L,anyOf:z,noneOf:Ht,filters:Kt,ids:B,layerId:W&&G?G:void 0}),sr=JSON.stringify([e,or]),[cr,lr]=(0,E.useState)(``),[ur,dr]=(0,E.useState)(!1),fr=(0,E.useRef)(!1),pr=$e||ur||cr!==sr||Zn||!!ir,mr=(0,E.useRef)(0),hr=(0,E.useRef)(null);(0,E.useEffect)(()=>()=>{mr.current++,hr.current=null},[]);let gr=(0,E.useRef)(``),$=(0,E.useCallback)(async t=>{if(!e)return;if(Te(H,V)){mr.current++,hr.current=null,gr.current=``,T([]),O(0),et(!1);return}if(Qn.current)return;let n=`${$t&&Qt?`${A}:unfiled`:A}:${En??``}`,r=(B?.length??0)>0,i=vt(e,H,V,P,I,L.join(`␟`),Yt,W&&G?G:``,n),a=r&&i===gr.current;gr.current=i;let o=vt(e,H,V,P,I,L.join(`␟`),Jt,W&&G?G:``,n),c=`${o}\0${k}`;if(t?.silent&&hr.current?.key===c){hr.current.refreshPending=!0;return}let l=++mr.current,u=t?.silent||r||k?void 0:gt.get(o);u&&(T(u.documents),O(u.totalCount),lr(sr),et(!1)),(t?.silent??(a||!!u))||et(!0);let d={key:c,refreshPending:!1};hr.current=d;try{let t;t=$t&&Qt?await ge(e,Qt.driver,Qt.address,{linked:!1,limit:I,offset:(P-1)*I}):W&&G&&A!==`workspace`?await oe(e,H,G,{limit:I,page:P,queries:L,allOf:Dn,anyOf:z,noneOf:Ht,filters:Kt,ids:B,sortBy:qt.sortBy||void 0,order:qt.order}):await pe(e,V,Dn,{limit:I,page:P,treeName:H,treeType:H===`directory`||H===`backends`?`directory`:`context`,queries:L,anyOf:z,noneOf:Ht,filters:Kt,ids:B,sortBy:qt.sortBy||void 0,order:qt.order,scope:A,debug:k&&L.length>0,debugLimit:200});let n=t.payload||[],i=t.totalCount||t.count||0;if(!r&&!d.refreshPending&&gt.set(o,{documents:n,totalCount:i}),l!==mr.current)return;let s=t.debug,c=s?.imageDistances??s?.distances??null;st(c?{query:L[L.length-1]??``,distances:c}:null),T(a?e=>e.length===n.length&&e.every((e,t)=>e.id===n[t].id)?e:n:n),O(i),lr(sr)}catch(e){if(l!==mr.current)return;let t=e instanceof Error?e.message:`Failed to fetch documents`;s({title:`Error`,description:t,variant:`destructive`}),T([]),O(0)}finally{hr.current===d&&(hr.current=null),l===mr.current&&et(!1),l===mr.current&&d.refreshPending&&$({silent:!0})}},[e,V,H,G,W,P,I,w?.status,L,Jt,A,$t,k,En]);(0,E.useEffect)(()=>{$()},[$]),(0,E.useEffect)(()=>{let t=t=>{let n=t.detail;!n||n.workspaceName!==e||(on({treeName:n.treeName||`context`,path:je(n.path||`/`)}),ln(`left`))};return window.addEventListener(`workspace:open-to-side`,t),()=>window.removeEventListener(`workspace:open-to-side`,t)},[e,H,V]),(0,E.useEffect)(()=>{let t=t=>{let n=t.detail;if(!(n?.workspaceName&&n.workspaceName!==e)&&(e&&bt(e,n),ot(at(n),{tree:H,kind:S(H),path:V,wholeWorkspace:A===`workspace`}))){if(e&&j(e,H,V),Qn.current){Yn();return}$({silent:!0})}};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[$,e,V,H,A,Yn]);let _r=w?.name,vr=w?.id;(0,E.useEffect)(()=>{if(!e||!_r&&!vr)return;let t=[_r,vr].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=()=>{te(e).then(e=>{a||(i=nt(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,Qn.current){Yn();return}$({silent:!0})}},f=t=>n=>{(t.startsWith(`tree.created`)||t.startsWith(`tree.renamed`))&&o();let r=rt(t,n,i);yt(e,r);let a={tree:H,kind:S(H),path:V,wholeWorkspace:A===`workspace`},f=sn.current;f&&ot(r,{tree:f.treeName,kind:S(f.treeName),path:f.path})&&(u=f),ot(r,a,rr.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,vr,_r,H,V,A,$,Yn]);let yr=`${V}\0${H}\0${G??``}\0${A}`,[br,xr]=(0,E.useState)(yr);br!==yr&&(xr(yr),F(1),It(null));let Sr=`${V}\0${H}\0${G??``}`,[Cr,wr]=(0,E.useState)(Sr);Cr!==Sr&&(wr(Sr),ut(`path`));let Tr=(e,t)=>{let n=e===`/`?`canvas`:e.split(`/`).pop()||`canvas`;Tt(n),St({parentPath:e,captureView:t})},Er=l.get(`createCanvas`)===`1`,[Dr,Or]=(0,E.useState)(!1);Dr!==Er&&(Or(Er),Er&&Tr(V,!1)),(0,E.useEffect)(()=>{if(!Er)return;let e=new URLSearchParams(n.search);e.delete(`createCanvas`);let t=e.toString();o(`${n.pathname}${t?`?${t}`:``}${n.hash}`,{replace:!0})},[Er,V]);let kr=(0,E.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]),Ar=JSON.stringify([l.has(`q`),...Ie]),[jr,Mr]=(0,E.useState)(Ar);jr!==Ar&&(Mr(Ar),Pt(Ie),F(1));let Nr=`${Ar}\0${Y??``}\0${An}\0${V}\0${Ft??``}`,[Pr,Fr]=(0,E.useState)(Nr);Pr!==Nr&&(Fr(Nr),l.has(`q`)||Ie.length>0||Y!==`canvas`||Ft===V||(Pt(An?[An]:[]),F(1)));let Ir=(0,E.useCallback)(e=>{let t=e.trim();t&&(It(null),Pt(e=>{if(e.includes(t))return e;let n=[...e,t];return kr(n),F(1),n}))},[kr,It,Pt,F]),Lr=(0,E.useCallback)(e=>{Pt(t=>{let n=e<0?[]:t.filter((t,n)=>n!==e);return n.length===0&&It(V),kr(n),F(1),n})},[kr,V,It,Pt,F]),Rr=L.join(` `).trim(),zr=!!R.activeContextType&&(R.isDirty||Rr!==(Y===`canvas`?An:R.savedSearchQuery||``));!e&&K!==null&&an(null),(0,E.useEffect)(()=>{let t=!1;if(!e)return;let n=0,r=!1,i=(i=!1)=>{let a=++n;i&&fe(e,H),ee(e,H).then(i=>{!t&&a===n&&(r=!0,_n.current=`${e}/${H}`,an(i))}).catch(()=>{!t&&a===n&&!r&&an(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=C(e,vr);return()=>{t=!0,o(),window.removeEventListener(`workspace:tree:refresh`,a)}},[e,H,vr]),!(e&&Y===`canvas`&&!W)&&N!==null&&Mt(null),(0,E.useEffect)(()=>{let t=!1;if(!(!e||Y!==`canvas`||W))return ae(e,V,H).then(e=>{t||Mt(e)}).catch(()=>{t||Mt(null)}),()=>{t=!0}},[e,V,H,Y,W]);let Br=async()=>{if(w){ft(!0);try{let t=await ue(e||w.id);Je(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{ft(!1)}}},Vr=async t=>{if(!w)return;let n=c({title:`Removing…`,description:`Document from "${V}"`});try{await re(e||w.id,[t],V,[],H,Yr,{trashIfOrphaned:!0}),j(e||w.id,H,V),T(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`})}},Hr=async t=>{if(!w)return;let n=c({title:`Deleting…`,description:`Document from "${V}"`});try{await ie(e||w.id,[t],V,[],H,Yr),j(e||w.id,H,V),T(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`})}},Ur=async t=>{if(!w)return;let n=c({title:`Removing…`,description:`${t.length} document(s) from "${V}"`});try{await re(e||w.id,t,V,[],H,Yr,{trashIfOrphaned:!0}),j(e||w.id,H,V),T(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`})}},Wr=async t=>{if(!w)return;let n=c({title:`Deleting…`,description:`${t.length} document(s)`});try{await ie(e||w.id,t,V,[],H,Yr),j(e||w.id,H,V),T(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`})}},Gr=async t=>{if(!w)return;let n=c({title:`Destroying…`,description:`Document and its backend copies`});try{let r=await ne(e||w.id,[t]);if(r.failed?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}T(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`})}},Kr=async t=>{if(!w)return;let n=c({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await ne(e||w.id,t),i=new Set(r.successful?.filter(e=>e.docDeleted).map(e=>e.id)??[]);T(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`})}},qr=e=>{xt({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`})},Jr=e=>{xt({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`})},Yr=S(H),Xr=async(t,n,r={})=>{if(!e)return!1;let i=r.targetTreeName??H,a=r.targetTreeType??Yr,o=r.move??_t?.operation===`cut`,s=c({title:o?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let c=await b(e,t,n,i,a);if(c){j(e,i,t);let a=r.sourceTreeName||_t?.sourceTreeName,c=r.sourcePath||_t?.sourcePath;if((r.move??_t?.operation===`cut`)&&c&&a){let t=S(a);await re(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}"`}),xt(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}},Zr=async(t,n)=>{if(!e)return!1;try{let r=(await de(e,n,t,H,Yr)).length>0;return r&&(xe(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}},Qr=async()=>{if(!w||nr===0||pr||fr.current||window.prompt(`Type PURGE to permanently delete all ${nr} matching documents across all pages.`)!==`PURGE`)return;fr.current=!0,dr(!0);let t=c({title:`Purging…`,description:`${nr} matching document(s)`});try{let n=await y(e||w.id,or,nr);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||w.id,H,V),await $({silent:!0}),fr.current=!1,dr(!1)}},$r=()=>Tr(V,!0),ei=async()=>{if(!(!e||!M||!wt.trim())){Dt(!0);try{let t=wt.trim(),n=M.parentPath,r=n===`/`?`/${t}`:`${n}/${t}`,i={...R.filters,features:{...R.filters.features,allOf:Dn}};await se(e,r,H,M.captureView?{metadata:{toolbox:i},querySpec:{features:i.features,filters:[...De(R.filters.timeline),...Ee(R.filters.geo)],query:Rr||void 0,sort:R.filters.sort?.sortBy?R.filters.sort:null}}:{}),St(null),fe(e,H);try{let t=await ee(e,H,{force:!0});an(t)}catch{}window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e}})),o(Me(e,r,H))}catch(e){s({title:`Error`,description:e instanceof Error?e.message:`Failed to create canvas`,variant:`destructive`})}finally{Dt(!1)}}},ti=async()=>{if(!(!e||Y!==`canvas`)){kt(!0);try{let t=N||await he(e,V,H);Mt(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{kt(!1)}}},ni=async()=>{if(N){kt(!0);try{await v(N.code),Mt(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{kt(!1)}}},ri=async()=>{if(!e||Y!==`canvas`||V===`/`)return;let t=jn?.label||V.split(`/`).pop()||`canvas`,n=N?` Its public link will stop working.`:``;if(window.confirm(`Delete canvas "${t}"? This cannot be undone.${n}`)){jt(!0);try{if(N)await v(N.code),Mt(null);else if(J?.locked){s({title:`Canvas is locked`,description:`Unlock it before deleting.`,variant:`destructive`});return}await g(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(Me(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{jt(!1)}}},ii=(0,E.useCallback)(async t=>{if(!e||!q)return;let n={treeName:H,path:V},r=cn===`left`?n:q,i=cn===`left`?q:n,a=cn===`left`?un:hn;if(a.length===0){s({title:`Nothing selected`,description:`Tick documents in the focused pane first.`});return}let o=S(i.treeName),l=c({title:t?`Moving…`:`Copying…`,description:`${a.length} document(s) → "${i.path}"`});try{if(!await b(e,i.path,a,i.treeName,o)){l.done();return}if(j(e,i.treeName,i.path),t){let t=S(r.treeName);await re(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,cn,H,V,un,hn,s,c]);if((0,E.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(),ii(e.key===`F6`))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[q,ii]),Ye)return(0,D.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,D.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,D.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),(0,D.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading workspace...`})]})});if(!w)return(0,D.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Workspace not found.`});let ai=Y===`canvas`&&!W&&!!J,oi=!ai&&!U&&yn?(0,D.jsx)(He,{views:wn,activeId:Tn,onSelect:On,onSave:kn,accentColor:Ce(w.color),onOpenToSide:e=>{on({treeName:H,path:V,viewId:e}),ln(`right`)}}):void 0,si=Qt||w.status!==`active`?(0,D.jsxs)(D.Fragment,{children:[Qt&&(0,D.jsx)(`button`,{type:`button`,onClick:()=>{en(!$t),F(1)},"aria-pressed":$t,className:u(`min-h-10 rounded-md border px-2 text-xs`,$t&&`bg-warning/15 text-warning`),children:`Unfiled only`}),w.status!==`active`&&(0,D.jsx)(`button`,{type:`button`,onClick:Br,disabled:dt,className:`min-h-10 rounded-md border px-2 text-xs`,children:dt?`Starting…`:`Start`})]}):void 0,ci=Te(H,V)?V===`/Trash`?(0,D.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,D.jsx)(Ge,{workspaceName:e||w.id})}):(0,D.jsx)(Ke,{workspace:e||w.id,path:V,onNavigate:t=>o(Me(e,t,`backends`))},e):(0,D.jsx)(Ue,{navigationTabs:oi,navigationActions:si,onBack:mn,accentColor:Ce(w.color),urlType:W?S(H)===`directory`?`${H}-layer`:`context-layer`:Y===`canvas`?`canvas`:S(H)===`directory`?H:`context`,urlDisplay:Vn,contextPath:V,treeName:H,workspaceId:e||w.id,workspaceLabel:w.label||w.name,workspaceIcon:w.icon,documentSchema:En,documents:ar,isLoading:$e,totalCount:nr,currentPage:P,pageSize:I,onPageChange:F,onPageSizeChange:e=>{Nt(e),F(1)},onRemoveDocument:V===`/`?void 0:Vr,onDeleteDocument:Hr,onDestroyDocument:Gr,onRemoveDocuments:V===`/`?void 0:Ur,onDeleteDocuments:Wr,onDestroyDocuments:Kr,onCopyDocuments:qr,onCutDocuments:Jr,onPasteDocuments:U?void 0:Xr,onImportDocuments:U?void 0:Zr,onSelectionChange:dn,onBrowseTree:()=>pn(`workspaces`,`detail`,e??null),onBrowseWorkspaces:()=>fn(`workspaces`),onNavigatePath:t=>o(Me(e,t,H)),folders:vn,onOpenFolder:t=>o(Me(e,je(t),H)),scope:A,onScopeChange:ut,pastedDocumentIds:_t?.documentIds,linkTree:K,onPurgeDocuments:U?void 0:Qr,disablePurgeDocuments:pr,canvasInfo:jn??void 0,isCanvasPinned:Ln,onTogglePinCanvas:Q?Bn:void 0,onSaveAsCanvas:K&&Y!==`canvas`&&!W&&!U?$r:void 0,onShareCanvas:Y===`canvas`&&!W?ti:void 0,onUnshareCanvas:N?ni:void 0,onDeleteCanvas:Y===`canvas`&&!W?ri:void 0,isSharingCanvas:Ot,isDeletingCanvas:At,isCanvasShared:!!N,isCanvasLocked:!!J?.locked,backendSearchQueries:L,onBackendSearch:Ir,serverSort:R.filters.sort,onServerSortChange:Rt,onRemoveBackendQuery:Lr,canSaveChanges:zr,isSavingChanges:R.isSaving,onSaveChanges:Lt,contentBanner:k&&it?(0,D.jsx)(mt,{data:it,className:`mb-3`}):null,children:ai&&J?(0,D.jsx)(ve,{workspaceId:e||w.id,treeName:H,path:V,layerId:J.id,querySpec:J.querySpec,metadata:J.metadata,isLocked:!!J.locked,fetchDocuments:R.isDirty?Un:void 0}):!U&&Z.kind===`columns`?(0,D.jsx)(Be,{documents:ar,workspaceId:e||w.id,columns:Z.columns??[],onColumnsChange:e=>kn(wn.map(t=>t.id===Z.id?{...t,columns:e}:t))}):!U&&Z.kind===`app`&&Z.app&&Z.app!==`notes`?(0,D.jsx)(We,{app:Z.app,workspaceId:e||w.id,treeName:H,path:V}):null});return(0,D.jsxs)(Fe,{workspaceId:e||w.id,treeName:H,path:V,headerOnly:!0,className:`relative flex flex-col h-full min-h-0`,children:[(0,D.jsx)(Qe,{workspaceId:w.id,workspaceName:w.label||w.name},w.id),Te(H,V)&&(0,D.jsx)(ye,{workspace:w.label||w.name,workspaceIcon:w.icon,tree:H,path:V,onBack:mn,onBrowseTree:()=>pn(`workspaces`,`detail`,e||w.id),onBrowseWorkspaces:()=>fn(`workspaces`),onNavigatePath:t=>o(Me(e,t,H)),accentColor:Ce(w.color)}),M&&(0,D.jsx)(`div`,{className:`shrink-0 px-2 pt-2`,children:(0,D.jsx)(Le,{title:`New canvas`,onClose:()=>St(null),children:(0,D.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ei()},className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{htmlFor:`canvas-name`,className:`mb-1 block text-sm font-medium`,children:`Name`}),(0,D.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:wt,onChange:e=>Tt(e.target.value),onKeyDown:e=>{e.key===`Escape`&&St(null)},autoFocus:!0})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`span`,{className:`mb-1 block text-sm font-medium`,children:`Parent path`}),(0,D.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,D.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,D.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:M.captureView,onChange:e=>St({...M,captureView:e.target.checked})}),(0,D.jsxs)(`span`,{children:[`Capture the current view`,(0,D.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:`Freezes the active filters, search and sort into the canvas.`})]})]}),(0,D.jsxs)(`div`,{className:`flex gap-2`,children:[(0,D.jsx)(d,{type:`submit`,disabled:!wt.trim()||Et,children:Et?`Creating…`:`Create canvas`}),(0,D.jsx)(d,{type:`button`,variant:`outline`,onClick:()=>St(null),children:`Cancel`})]})]})})}),(0,D.jsxs)(`div`,{"data-canvas-panes":!0,className:`flex-1 min-h-0 flex gap-2`,children:[(0,D.jsx)(`div`,{"data-canvas-pane":!0,className:u(`flex-1 min-w-0 bg-background overflow-hidden`,q&&(cn===`left`?`ring-2 ring-primary`:`ring-1 ring-primary/20`)),onMouseDown:e=>{e.target.closest(`button,input,textarea,select,a`)||ln(`left`)},children:ci}),q&&e&&(0,D.jsx)(Ct,{workspaceName:e,workspaceLabel:w.label||w.name,workspaceIcon:w.icon,pane:q,isFocused:cn===`right`,clipboard:_t,setClipboard:xt,onFocus:()=>ln(`right`),onSelectionChange:gn,onNavigate:e=>on(t=>t&&{...t,path:e,viewId:void 0}),onClose:()=>{on(null),ln(`left`),gn([])}})]})]})}function St(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 Ct({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}=Ne(),{showToast:m,showProgress:g}=h(),[_,te]=(0,E.useState)(null),[v,y]=(0,E.useState)([]),[ae,oe]=(0,E.useState)(!1),[se,ce]=(0,E.useState)(0),[le,ue]=(0,E.useState)(1),[de,me]=(0,E.useState)(50),x=S(r.treeName),he=St(_,r.path),ge=he?.type===`canvas`,_e=(0,E.useMemo)(()=>x===`directory`?ht(_,r.path):[],[_,r.path,x]),ve=r.viewId?Ve(he?.metadata).find(e=>e.id===r.viewId)??null:null,ye=`${e}://${r.path===`/`?``:r.path.replace(/^\//,``)}`,be=Re(ve),C=(0,E.useCallback)(async()=>{if(Te(r.treeName,r.path)){y([]),ce(0),oe(!1);return}let t=vt(e,r.treeName,r.path,le,de,``,be??``),n=gt.get(t);if(n){y(n.documents),ce(n.totalCount);return}oe(!0);try{let n=await pe(e,r.path,be?[be]:[],{limit:de,page:le,treeName:r.treeName,treeType:x}),i=n.payload||[],a=n.totalCount||n.count||0;y(i),ce(a),gt.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`}),y([]),ce(0)}finally{oe(!1)}},[e,r.path,r.treeName,x,de,le,m,be]);(0,E.useEffect)(()=>{let t=!1,n=0,i=!1,a=(a=!1)=>{let o=++n;a&&fe(e,r.treeName),ee(e,r.treeName).then(e=>{!t&&o===n&&(i=!0,te(e))}).catch(()=>{!t&&o===n&&!i&&te(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,E.useEffect)(()=>{C()},[C]),(0,E.useEffect)(()=>{let t=t=>{let n=t.detail;n?.workspaceName&&n.workspaceName!==e||(bt(e,n),ot(at(n),{tree:r.treeName,kind:S(r.treeName),path:r.path})&&(j(e,r.treeName,r.path),C()))};return window.addEventListener(`workspace:documents:refresh`,t),()=>window.removeEventListener(`workspace:documents:refresh`,t)},[C,e,r.treeName,r.path]);let xe=(0,E.useCallback)(async(t,n,i={})=>{let s=i.targetTreeName??r.treeName,c=i.targetTreeType??x,l=i.move??a?.operation===`cut`,u=g({title:l?`Moving…`:`Pasting…`,description:`${n.length} document(s) → "${t}"`});try{let r=await b(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=S(c);await re(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 C(),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,C,g,a,o]),Se=(0,E.useCallback)(()=>{j(e,r.treeName,r.path),C()},[e,r.treeName,r.path,C]),Ce=(0,E.useCallback)(async t=>{let n=g({title:`Removing…`,description:`${t.length} document(s) from "${r.path}"`});try{await re(e,t,r.path,[],r.treeName,x),Se(),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,Se,g]),we=(0,E.useCallback)(async t=>{let n=g({title:`Deleting…`,description:`${t.length} document(s)`});try{await ie(e,t,r.path,[],r.treeName,x),Se(),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,Se,g]),Ee=(0,E.useCallback)(async t=>{let n=g({title:`Destroying…`,description:`${t.length} document(s) and their backend copies`});try{let r=await ne(e,t);if(r.failed?.length&&!r.successful?.length){n.fail({title:`Error`,description:r.failed[0].reason,variant:`destructive`});return}Se();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,Se,g]);return(0,D.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,D.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`}),Te(r.treeName,r.path)?r.path===`/Trash`?(0,D.jsx)(`div`,{className:`h-full overflow-auto p-4`,children:(0,D.jsx)(Ge,{workspaceName:e})}):(0,D.jsx)(Ke,{workspace:e,path:r.path,onNavigate:l||(()=>{})}):(0,D.jsx)(Ue,{frameContent:!1,onBrowseWorkspaces:()=>f(`workspaces`),onBrowseTree:()=>p(`workspaces`,`detail`,e),urlType:ge?`canvas`:x===`directory`?r.treeName:`context`,urlDisplay:ye,contextPath:r.path,treeName:r.treeName,workspaceId:e,workspaceLabel:t,workspaceIcon:n,documentSchema:be,documents:v,isLoading:ae,totalCount:se,currentPage:le,pageSize:de,onPageChange:ue,onPageSizeChange:e=>{me(e),ue(1)},onRemoveDocument:r.path===`/`?void 0:e=>Ce([e]),onRemoveDocuments:r.path===`/`?void 0:Ce,onDeleteDocument:e=>we([e]),onDeleteDocuments:we,onDestroyDocument:e=>Ee([e]),onDestroyDocuments:Ee,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:xe,onSelectionChange:c,pastedDocumentIds:a?.documentIds,linkTree:_,folders:_e,onOpenFolder:l,onNavigatePath:l,canvasInfo:ge?{label:he?.label,description:he?.description,color:he?.color}:void 0,children:ve?.kind===`columns`?(0,D.jsx)(Be,{documents:v,workspaceId:e,columns:ve.columns??[],onColumnsChange:()=>{},readOnly:!0}):ve?.kind===`app`&&ve.app&&ve.app!==`notes`?(0,D.jsx)(We,{app:ve.app,workspaceId:e,treeName:r.treeName,path:r.path}):null})]})}export{xt 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-GtTr9Ff_.js";import{t as a}from"./use-settings-back-Dk-DJEUO.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.20`}),e?.version&&(0,s.jsx)(l,{name:e.productName||e.appName||`Canvas Server`,detail:d||void 0,version:`v${e.version}`})]}),f.length>0&&(0,s.jsxs)(`section`,{children:[(0,s.jsx)(`h2`,{className:`mb-2 px-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:`Server components`}),(0,s.jsx)(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:f.map(([e,t])=>(0,s.jsx)(l,{name:e,version:`v${t}`},e))})]}),n&&(0,s.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Server details unavailable: `,n]}),e?.sourceUrl&&(0,s.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.license?`Licensed ${e.license}. `:``,(0,s.jsx)(`a`,{href:e.sourceUrl,target:`_blank`,rel:`noreferrer`,className:`underline underline-offset-2 hover:text-foreground`,children:`Get the source code`}),`.`]})]})]})}export{u as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{t as r}from"./api-CA6WiiYM.js";import{n as i}from"./page-header-GtTr9Ff_.js";import{t as a}from"./use-settings-back-Dk-DJEUO.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.21`}),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-BAKOAkpE.js";var a=e(),o=[`note`,`todo`,`link`,`file`,`photo`];function s(){let{kind:e}=t(),s=r();return e===`sketch`?(0,a.jsx)(n,{to:`/apps/sketch?add=1`,replace:!0}):!e||!o.includes(e)?(0,a.jsx)(n,{to:`/home`,replace:!0}):(0,a.jsx)(i,{initialKind:e,onInitialCardClose:()=>s(`/home`)})}export{s as default};
1
+ import{l as e}from"./code-editor-BOIngd5F.js";import{_ as t,a as n,g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as i}from"./HomeFab-CpTZdNyY.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,Mt as a,Pt as o,Yr as s,br as c,rt as l,tn as u}from"./ui-BSqPn1LJ.js";import{t as d}from"./button-Bv4zA1qr.js";import{t as f}from"./input-BOtCd4HP.js";import{n as p}from"./use-toast-BlLDqSUO.js";import{t as m}from"./color-DFEH4BfK.js";import{F as h,K as g,Q as _,Tt as v,Z as y}from"./index-exXolIqD.js";import{n as b}from"./page-header-GtTr9Ff_.js";import{n as ee,r as x,t as te}from"./useAgentModels-DI41aFY3.js";import{t as ne}from"./form-panel-Dz96K7Lv.js";import{t as re}from"./use-create-panel-DhSNIGtr.js";import{n as ie,t as ae}from"./useSocketSubscription-ifW-vnlb.js";var S=e(n(),1),C=t();function w({agent:e,onStart:t,onStop:n,onEnter:r}){let[a,f]=(0,S.useState)(!1),p=async()=>{f(!0);try{await t(e.name)}finally{f(!1)}},m=async()=>{f(!0);try{await n(e.name)}finally{f(!1)}},h=()=>{switch(e.status){case`active`:return(0,C.jsx)(c,{className:`h-4 w-4 text-success`});case`inactive`:return(0,C.jsx)(c,{className:`h-4 w-4 text-warning`});case`error`:return(0,C.jsx)(c,{className:`h-4 w-4 text-destructive`});default:return(0,C.jsx)(c,{className:`h-4 w-4 text-muted-foreground`})}},g=()=>{switch(e.llmProvider){case`anthropic`:return(0,C.jsx)(s,{className:`h-4 w-4 text-warning`});case`openai`:return(0,C.jsx)(s,{className:`h-4 w-4 text-success`});case`ollama`:return(0,C.jsx)(i,{className:`h-4 w-4 text-info`});default:return(0,C.jsx)(s,{className:`h-4 w-4 text-muted-foreground`})}},_=()=>{switch(e.status){case`active`:return`text-success bg-success-subtle border-success`;case`inactive`:return`text-warning bg-warning-subtle border-warning`;case`error`:return`text-destructive bg-destructive-subtle border-destructive`;case`available`:return`text-info bg-info-subtle border-info`;default:return`text-foreground bg-muted border-border`}},v=e.status===`available`||e.status===`inactive`,y=e.status===`active`;return(0,C.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 hover:shadow-elevation-2 transition-shadow bg-card`,children:[(0,C.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[g(),(0,C.jsx)(`h3`,{className:`text-lg font-semibold truncate`,children:e.label||e.name}),e.color&&(0,C.jsx)(`div`,{className:`w-4 h-4 rounded border flex-shrink-0`,style:{backgroundColor:e.color},title:`Color: ${e.color}`})]}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground font-mono`,children:e.name}),e.description&&(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:e.description})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[h(),(0,C.jsx)(`span`,{className:`px-2 py-1 rounded-full text-xs font-medium border ${_()}`,children:e.status})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 text-sm`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider:`}),(0,C.jsx)(`div`,{className:`font-medium capitalize`,children:e.llmProvider})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Model:`}),(0,C.jsx)(`div`,{className:`font-mono text-xs`,children:e.model})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Created:`}),(0,C.jsx)(`div`,{children:new Date(e.createdAt).toLocaleDateString()})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Last Access:`}),(0,C.jsx)(`div`,{children:e.lastAccessed?new Date(e.lastAccessed).toLocaleDateString():`Never`})]})]}),e.config.mcp?.servers&&e.config.mcp.servers.length>0&&(0,C.jsxs)(`div`,{className:`text-sm`,children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`MCP Servers:`}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.config.mcp.servers.map((e,t)=>(0,C.jsx)(`span`,{className:`px-2 py-1 bg-secondary text-secondary-foreground rounded text-xs`,children:e.name},t))})]}),(0,C.jsxs)(`div`,{className:`flex gap-2 pt-2 border-t`,children:[v&&(0,C.jsxs)(d,{onClick:p,disabled:a,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(o,{className:`mr-2 h-4 w-4`}),`Start`]}),y&&(0,C.jsxs)(d,{onClick:m,disabled:a,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(l,{className:`mr-2 h-4 w-4`}),`Stop`]}),(0,C.jsxs)(d,{onClick:()=>r(e.name),size:`sm`,className:`flex-1`,children:[(0,C.jsx)(u,{className:`mr-2 h-4 w-4`}),`Chat`]})]})]})}function T(){let e={anthropic:`https://api.anthropic.com`,openai:`https://api.openai.com/v1`,ollama:`http://localhost:11434/v1`},t={anthropic:`claude-3-5-sonnet-20241022`,openai:`gpt-4o`,ollama:`qwen2.5-coder:latest`},[n,i]=(0,S.useState)([]),[o,s]=(0,S.useState)(!0),[c,l]=(0,S.useState)(null),[u,T]=(0,S.useState)(``),[E,D]=(0,S.useState)(``),[O,k]=(0,S.useState)(m()),[A,j]=(0,S.useState)(``),[M,oe]=(0,S.useState)(`anthropic`),[N,P]=(0,S.useState)(t.anthropic),[F,I]=(0,S.useState)({apiKey:``,baseUrl:e.anthropic,maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),L=te(M,F.apiKey,F.baseUrl),R=L.models.find(e=>e.id===N),[z,B]=(0,S.useState)(``),[V,H]=(0,S.useState)(``),[U,W]=(0,S.useState)(``),[G,K]=(0,S.useState)(``),[q,J]=(0,S.useState)(!1),Y=v(),[X,Z]=re(),{showToast:Q}=p(),se=r(),$=ie();ae($,`agent`,{"agent:status:changed":e=>{i(t=>t.map(t=>t.id===e.agentId?{...t,status:e.status,isActive:e.isActive}:t))},"agent:created":e=>{i(t=>[...t,e.agent])},"agent:deleted":e=>{i(t=>t.filter(t=>t.id!==e.agentId))}});let ce=n=>{oe(n),P(t[n]),I({apiKey:``,baseUrl:e[n],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096})};(0,S.useEffect)(()=>((async()=>{try{s(!0);let e=await g();i(e),l(null)}catch(e){console.error(`Agent fetch error:`,e);let t=`Failed to fetch agents`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to fetch agents`}l(t),Q({title:`Error`,description:t,variant:`destructive`})}finally{s(!1)}})(),()=>{}),[$,Q]);let le=async t=>{if(t.preventDefault(),u.trim()){J(!0);try{let t=G.trim()||x(z,V,U),n={name:u,label:A||u,description:E||void 0,color:O,llmProvider:M,model:N,apiKey:F.apiKey.trim()||void 0,baseUrl:F.baseUrl.trim()||void 0,config:{type:M,model:N,identity:{role:z.trim()||void 0,identity:V.trim()||void 0,instructions:U.trim()||void 0},prompts:t?{system:t}:void 0,connectors:{[M]:{maxTokens:F.maxTokens,...M===`anthropic`?{}:{temperature:F.temperature},topP:F.topP,frequencyPenalty:F.frequencyPenalty,presencePenalty:F.presencePenalty,...M===`ollama`?{numCtx:F.numCtx}:{}}}},mcp:{enabled:!0,servers:[{name:`weather`,command:`node`,args:[`src/managers/agent/mcp-servers/weather.js`]}]}},r=await h(n);i(e=>[...e,r]),T(``),D(``),k(m()),j(``),K(``),B(``),H(``),W(``),I({apiKey:``,baseUrl:e[M],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),Q({title:`Success`,description:`Agent '${r.label||r.name}' created.`}),Z(!1)}catch(e){console.error(`Agent creation error:`,e);let t=`Failed to create agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to create agent`}Q({title:`Error`,description:t,variant:`destructive`})}finally{J(!1)}}},ue=async e=>{try{let t=await y(e);i(e=>e.map(e=>e.name===t.name?t:e)),Q({title:`Success`,description:`Agent '${t.label||t.name}' started.`})}catch(e){console.error(`Agent start error:`,e);let t=`Failed to start agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to start agent`}Q({title:`Error`,description:t,variant:`destructive`})}},de=async e=>{try{await _(e),i(t=>t.map(t=>t.name===e?{...t,status:`inactive`,isActive:!1}:t)),Q({title:`Success`,description:`Agent '${e}' stopped.`})}catch(e){console.error(`Agent stop error:`,e);let t=`Failed to stop agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to stop agent`}Q({title:`Error`,description:t,variant:`destructive`})}},fe=e=>{se(`/agents/${e}`)};return(0,C.jsxs)(`div`,{className:`space-y-6`,children:[(0,C.jsx)(b,{title:`AI Agents`,description:`Create and manage your AI agents with multiple LLM providers`,actions:!Y.local&&!X&&(0,C.jsxs)(d,{onClick:()=>Z(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create agent`,title:`Create agent`,children:[(0,C.jsx)(a,{className:`h-4 w-4 sm:mr-2`}),(0,C.jsx)(`span`,{className:`max-sm:hidden`,children:`Create Agent`})]})}),!Y.local&&X&&(0,C.jsx)(ne,{title:`Create New Agent`,onClose:()=>Z(!1),children:(0,C.jsxs)(`form`,{onSubmit:le,className:`space-y-4`,children:[(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsx)(f,{value:u,onChange:e=>T(e.target.value),placeholder:`Agent Name (e.g., 'my-assistant')`,disabled:q}),(0,C.jsx)(f,{value:A,onChange:e=>j(e.target.value),placeholder:`Agent Label (display name, optional)`,disabled:q})]}),(0,C.jsx)(f,{value:E,onChange:e=>D(e.target.value),placeholder:`Description (optional)`,disabled:q}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-provider`,className:`text-sm font-medium`,children:`LLM Provider`}),(0,C.jsxs)(`select`,{id:`agent-provider`,value:M,onChange:e=>ce(e.target.value),className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring`,disabled:q,children:[(0,C.jsx)(`option`,{value:`anthropic`,children:`Anthropic Claude`}),(0,C.jsx)(`option`,{value:`openai`,children:`OpenAI GPT`}),(0,C.jsx)(`option`,{value:`ollama`,children:`Ollama (Local)`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-model`,className:`text-sm font-medium`,children:`Model`}),(0,C.jsx)(ee,{id:`agent-model`,value:N,onChange:(e,t)=>{P(e),t?.maxTokens&&I(e=>({...e,maxTokens:t.maxTokens}))},...L,disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`Persona`}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-role`,className:`text-sm font-medium`,children:`Role`}),(0,C.jsx)(f,{id:`agent-role`,value:z,onChange:e=>B(e.target.value),placeholder:`e.g. Software Engineer`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-identity`,className:`text-sm font-medium`,children:`Identity`}),(0,C.jsx)(`textarea`,{id:`agent-identity`,value:V,onChange:e=>H(e.target.value),placeholder:`Who this agent is…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-instructions`,className:`text-sm font-medium`,children:`Instructions`}),(0,C.jsx)(`textarea`,{id:`agent-instructions`,value:U,onChange:e=>W(e.target.value),placeholder:`Behavioral instructions…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`system-prompt`,className:`text-sm font-medium`,children:`System Prompt (Optional Override)`}),(0,C.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Built from Role, Identity and Instructions unless you enter an override.`}),(0,C.jsx)(`textarea`,{id:`system-prompt`,value:G,onChange:e=>K(e.target.value),placeholder:x(z,V,U)||`System prompt sent to the LLM…`,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring min-h-[80px] resize-y`,disabled:q})]}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`api-key`,className:`text-sm font-medium`,children:`API Key (Optional)`}),(0,C.jsx)(f,{id:`api-key`,type:`password`,value:F.apiKey,onChange:e=>I(t=>({...t,apiKey:e.target.value})),placeholder:`Enter your API key`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`baseUrl`,className:`text-sm font-medium`,children:`Base URL (Optional)`}),(0,C.jsx)(f,{id:`baseUrl`,value:F.baseUrl,onChange:e=>I(t=>({...t,baseUrl:e.target.value})),placeholder:e[M],disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`LLM Parameters`}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`max-tokens`,className:`text-sm font-medium`,children:`Max Output Tokens`}),(0,C.jsx)(f,{id:`max-tokens`,type:`number`,min:`1`,max:R?.maxTokens,value:F.maxTokens,onChange:e=>I(t=>({...t,maxTokens:parseInt(e.target.value)||4096})),disabled:q})]}),M!==`anthropic`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`temperature`,className:`text-sm font-medium`,children:`Temperature`}),(0,C.jsx)(f,{id:`temperature`,type:`number`,min:`0`,max:`2`,step:`0.1`,value:F.temperature,onChange:e=>I(t=>({...t,temperature:Number.isNaN(e.target.valueAsNumber)?.7:e.target.valueAsNumber})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`top-p`,className:`text-sm font-medium`,children:`Top P`}),(0,C.jsx)(f,{id:`top-p`,type:`number`,min:`0`,max:`1`,step:`0.1`,value:F.topP,onChange:e=>I(t=>({...t,topP:Number.isNaN(e.target.valueAsNumber)?1:e.target.valueAsNumber})),disabled:q})]}),M===`ollama`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`num-ctx`,className:`text-sm font-medium`,children:`Context Length`}),(0,C.jsx)(f,{id:`num-ctx`,type:`number`,min:`1024`,max:R?.contextWindow,value:F.numCtx,onChange:e=>I(t=>({...t,numCtx:parseInt(e.target.value)||4096})),disabled:q})]})]}),M!==`ollama`&&(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`frequency-penalty`,className:`text-sm font-medium`,children:`Frequency Penalty`}),(0,C.jsx)(f,{id:`frequency-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.frequencyPenalty,onChange:e=>I(t=>({...t,frequencyPenalty:parseFloat(e.target.value)||0})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`presence-penalty`,className:`text-sm font-medium`,children:`Presence Penalty`}),(0,C.jsx)(f,{id:`presence-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.presencePenalty,onChange:e=>I(t=>({...t,presencePenalty:parseFloat(e.target.value)||0})),disabled:q})]})]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`label`,{htmlFor:`agent-color`,className:`text-sm font-medium`,children:`Agent Color`}),(0,C.jsx)(f,{id:`agent-color`,type:`color`,value:O,onChange:e=>k(e.target.value),className:`h-10 w-16 p-1`,disabled:q}),(0,C.jsx)(d,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>k(m()),disabled:q,children:`Randomize`})]}),(0,C.jsxs)(d,{type:`submit`,disabled:q||!u.trim(),children:[(0,C.jsx)(a,{className:`mr-2 h-4 w-4`}),`Create Agent`]})]})}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your Agents`}),o&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading agents...`}),c&&(0,C.jsx)(`div`,{className:`text-center text-destructive`,children:(0,C.jsx)(`p`,{children:c})}),!o&&!c&&n.length===0&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No agents found`}),n.length>0&&(0,C.jsx)(`div`,{className:`grid gap-4`,children:n.map(e=>(0,C.jsx)(w,{agent:e,onStart:ue,onStop:de,onEnter:fe},e.id))})]})]})}export{T as default};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{I as i,Mt as a,Pt as o,Yr as s,br as c,rt as l,tn as u}from"./ui-BSqPn1LJ.js";import{t as d}from"./button-Bv4zA1qr.js";import{t as f}from"./input-BOtCd4HP.js";import{n as p}from"./use-toast-BlLDqSUO.js";import{t as m}from"./color-DFEH4BfK.js";import{$ as h,Et as g,I as _,Q as v,q as y}from"./index-DtZS4JJ4.js";import{n as b}from"./page-header-GtTr9Ff_.js";import{n as ee,r as x,t as te}from"./useAgentModels-ndLotMWH.js";import{t as ne}from"./form-panel-Dz96K7Lv.js";import{t as re}from"./use-create-panel-DhSNIGtr.js";import{n as ie,t as ae}from"./useSocketSubscription-ifW-vnlb.js";var S=e(n(),1),C=t();function w({agent:e,onStart:t,onStop:n,onEnter:r}){let[a,f]=(0,S.useState)(!1),p=async()=>{f(!0);try{await t(e.name)}finally{f(!1)}},m=async()=>{f(!0);try{await n(e.name)}finally{f(!1)}},h=()=>{switch(e.status){case`active`:return(0,C.jsx)(c,{className:`h-4 w-4 text-success`});case`inactive`:return(0,C.jsx)(c,{className:`h-4 w-4 text-warning`});case`error`:return(0,C.jsx)(c,{className:`h-4 w-4 text-destructive`});default:return(0,C.jsx)(c,{className:`h-4 w-4 text-muted-foreground`})}},g=()=>{switch(e.llmProvider){case`anthropic`:return(0,C.jsx)(s,{className:`h-4 w-4 text-warning`});case`openai`:return(0,C.jsx)(s,{className:`h-4 w-4 text-success`});case`ollama`:return(0,C.jsx)(i,{className:`h-4 w-4 text-info`});default:return(0,C.jsx)(s,{className:`h-4 w-4 text-muted-foreground`})}},_=()=>{switch(e.status){case`active`:return`text-success bg-success-subtle border-success`;case`inactive`:return`text-warning bg-warning-subtle border-warning`;case`error`:return`text-destructive bg-destructive-subtle border-destructive`;case`available`:return`text-info bg-info-subtle border-info`;default:return`text-foreground bg-muted border-border`}},v=e.status===`available`||e.status===`inactive`,y=e.status===`active`;return(0,C.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-4 hover:shadow-elevation-2 transition-shadow bg-card`,children:[(0,C.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[g(),(0,C.jsx)(`h3`,{className:`text-lg font-semibold truncate`,children:e.label||e.name}),e.color&&(0,C.jsx)(`div`,{className:`w-4 h-4 rounded border flex-shrink-0`,style:{backgroundColor:e.color},title:`Color: ${e.color}`})]}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground font-mono`,children:e.name}),e.description&&(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:e.description})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[h(),(0,C.jsx)(`span`,{className:`px-2 py-1 rounded-full text-xs font-medium border ${_()}`,children:e.status})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 text-sm`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider:`}),(0,C.jsx)(`div`,{className:`font-medium capitalize`,children:e.llmProvider})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Model:`}),(0,C.jsx)(`div`,{className:`font-mono text-xs`,children:e.model})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Created:`}),(0,C.jsx)(`div`,{children:new Date(e.createdAt).toLocaleDateString()})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`Last Access:`}),(0,C.jsx)(`div`,{children:e.lastAccessed?new Date(e.lastAccessed).toLocaleDateString():`Never`})]})]}),e.config.mcp?.servers&&e.config.mcp.servers.length>0&&(0,C.jsxs)(`div`,{className:`text-sm`,children:[(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`MCP Servers:`}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.config.mcp.servers.map((e,t)=>(0,C.jsx)(`span`,{className:`px-2 py-1 bg-secondary text-secondary-foreground rounded text-xs`,children:e.name},t))})]}),(0,C.jsxs)(`div`,{className:`flex gap-2 pt-2 border-t`,children:[v&&(0,C.jsxs)(d,{onClick:p,disabled:a,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(o,{className:`mr-2 h-4 w-4`}),`Start`]}),y&&(0,C.jsxs)(d,{onClick:m,disabled:a,size:`sm`,variant:`outline`,className:`flex-1`,children:[(0,C.jsx)(l,{className:`mr-2 h-4 w-4`}),`Stop`]}),(0,C.jsxs)(d,{onClick:()=>r(e.name),size:`sm`,className:`flex-1`,children:[(0,C.jsx)(u,{className:`mr-2 h-4 w-4`}),`Chat`]})]})]})}function T(){let e={anthropic:`https://api.anthropic.com`,openai:`https://api.openai.com/v1`,ollama:`http://localhost:11434/v1`},t={anthropic:`claude-3-5-sonnet-20241022`,openai:`gpt-4o`,ollama:`qwen2.5-coder:latest`},[n,i]=(0,S.useState)([]),[o,s]=(0,S.useState)(!0),[c,l]=(0,S.useState)(null),[u,T]=(0,S.useState)(``),[E,D]=(0,S.useState)(``),[O,k]=(0,S.useState)(m()),[A,j]=(0,S.useState)(``),[M,oe]=(0,S.useState)(`anthropic`),[N,P]=(0,S.useState)(t.anthropic),[F,I]=(0,S.useState)({apiKey:``,baseUrl:e.anthropic,maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),L=te(M,F.apiKey,F.baseUrl),R=L.models.find(e=>e.id===N),[z,B]=(0,S.useState)(``),[V,H]=(0,S.useState)(``),[U,W]=(0,S.useState)(``),[G,K]=(0,S.useState)(``),[q,J]=(0,S.useState)(!1),Y=g(),[X,Z]=re(),{showToast:Q}=p(),se=r(),$=ie();ae($,`agent`,{"agent:status:changed":e=>{i(t=>t.map(t=>t.id===e.agentId?{...t,status:e.status,isActive:e.isActive}:t))},"agent:created":e=>{i(t=>[...t,e.agent])},"agent:deleted":e=>{i(t=>t.filter(t=>t.id!==e.agentId))}});let ce=n=>{oe(n),P(t[n]),I({apiKey:``,baseUrl:e[n],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096})};(0,S.useEffect)(()=>((async()=>{try{s(!0);let e=await y();i(e),l(null)}catch(e){console.error(`Agent fetch error:`,e);let t=`Failed to fetch agents`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to fetch agents`}l(t),Q({title:`Error`,description:t,variant:`destructive`})}finally{s(!1)}})(),()=>{}),[$,Q]);let le=async t=>{if(t.preventDefault(),u.trim()){J(!0);try{let t=G.trim()||x(z,V,U),n={name:u,label:A||u,description:E||void 0,color:O,llmProvider:M,model:N,apiKey:F.apiKey.trim()||void 0,baseUrl:F.baseUrl.trim()||void 0,config:{type:M,model:N,identity:{role:z.trim()||void 0,identity:V.trim()||void 0,instructions:U.trim()||void 0},prompts:t?{system:t}:void 0,connectors:{[M]:{maxTokens:F.maxTokens,...M===`anthropic`?{}:{temperature:F.temperature},topP:F.topP,frequencyPenalty:F.frequencyPenalty,presencePenalty:F.presencePenalty,...M===`ollama`?{numCtx:F.numCtx}:{}}}},mcp:{enabled:!0,servers:[{name:`weather`,command:`node`,args:[`src/managers/agent/mcp-servers/weather.js`]}]}},r=await _(n);i(e=>[...e,r]),T(``),D(``),k(m()),j(``),K(``),B(``),H(``),W(``),I({apiKey:``,baseUrl:e[M],maxTokens:4096,temperature:.7,topP:1,frequencyPenalty:0,presencePenalty:0,numCtx:4096}),Q({title:`Success`,description:`Agent '${r.label||r.name}' created.`}),Z(!1)}catch(e){console.error(`Agent creation error:`,e);let t=`Failed to create agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to create agent`}Q({title:`Error`,description:t,variant:`destructive`})}finally{J(!1)}}},ue=async e=>{try{let t=await v(e);i(e=>e.map(e=>e.name===t.name?t:e)),Q({title:`Success`,description:`Agent '${t.label||t.name}' started.`})}catch(e){console.error(`Agent start error:`,e);let t=`Failed to start agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to start agent`}Q({title:`Error`,description:t,variant:`destructive`})}},de=async e=>{try{await h(e),i(t=>t.map(t=>t.name===e?{...t,status:`inactive`,isActive:!1}:t)),Q({title:`Success`,description:`Agent '${e}' stopped.`})}catch(e){console.error(`Agent stop error:`,e);let t=`Failed to stop agent`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to stop agent`}Q({title:`Error`,description:t,variant:`destructive`})}},fe=e=>{se(`/agents/${e}`)};return(0,C.jsxs)(`div`,{className:`space-y-6`,children:[(0,C.jsx)(b,{title:`AI Agents`,description:`Create and manage your AI agents with multiple LLM providers`,actions:!Y.local&&!X&&(0,C.jsxs)(d,{onClick:()=>Z(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create agent`,title:`Create agent`,children:[(0,C.jsx)(a,{className:`h-4 w-4 sm:mr-2`}),(0,C.jsx)(`span`,{className:`max-sm:hidden`,children:`Create Agent`})]})}),!Y.local&&X&&(0,C.jsx)(ne,{title:`Create New Agent`,onClose:()=>Z(!1),children:(0,C.jsxs)(`form`,{onSubmit:le,className:`space-y-4`,children:[(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsx)(f,{value:u,onChange:e=>T(e.target.value),placeholder:`Agent Name (e.g., 'my-assistant')`,disabled:q}),(0,C.jsx)(f,{value:A,onChange:e=>j(e.target.value),placeholder:`Agent Label (display name, optional)`,disabled:q})]}),(0,C.jsx)(f,{value:E,onChange:e=>D(e.target.value),placeholder:`Description (optional)`,disabled:q}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-provider`,className:`text-sm font-medium`,children:`LLM Provider`}),(0,C.jsxs)(`select`,{id:`agent-provider`,value:M,onChange:e=>ce(e.target.value),className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring`,disabled:q,children:[(0,C.jsx)(`option`,{value:`anthropic`,children:`Anthropic Claude`}),(0,C.jsx)(`option`,{value:`openai`,children:`OpenAI GPT`}),(0,C.jsx)(`option`,{value:`ollama`,children:`Ollama (Local)`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-model`,className:`text-sm font-medium`,children:`Model`}),(0,C.jsx)(ee,{id:`agent-model`,value:N,onChange:(e,t)=>{P(e),t?.maxTokens&&I(e=>({...e,maxTokens:t.maxTokens}))},...L,disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`Persona`}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-role`,className:`text-sm font-medium`,children:`Role`}),(0,C.jsx)(f,{id:`agent-role`,value:z,onChange:e=>B(e.target.value),placeholder:`e.g. Software Engineer`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-identity`,className:`text-sm font-medium`,children:`Identity`}),(0,C.jsx)(`textarea`,{id:`agent-identity`,value:V,onChange:e=>H(e.target.value),placeholder:`Who this agent is…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`agent-instructions`,className:`text-sm font-medium`,children:`Instructions`}),(0,C.jsx)(`textarea`,{id:`agent-instructions`,value:U,onChange:e=>W(e.target.value),placeholder:`Behavioral instructions…`,disabled:q,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm min-h-[80px] resize-y`})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`system-prompt`,className:`text-sm font-medium`,children:`System Prompt (Optional Override)`}),(0,C.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Built from Role, Identity and Instructions unless you enter an override.`}),(0,C.jsx)(`textarea`,{id:`system-prompt`,value:G,onChange:e=>K(e.target.value),placeholder:x(z,V,U)||`System prompt sent to the LLM…`,className:`w-full mt-1 px-3 py-2 border border-input bg-background rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-ring min-h-[80px] resize-y`,disabled:q})]}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`api-key`,className:`text-sm font-medium`,children:`API Key (Optional)`}),(0,C.jsx)(f,{id:`api-key`,type:`password`,value:F.apiKey,onChange:e=>I(t=>({...t,apiKey:e.target.value})),placeholder:`Enter your API key`,disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`baseUrl`,className:`text-sm font-medium`,children:`Base URL (Optional)`}),(0,C.jsx)(f,{id:`baseUrl`,value:F.baseUrl,onChange:e=>I(t=>({...t,baseUrl:e.target.value})),placeholder:e[M],disabled:q})]})]}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h3`,{className:`text-lg font-medium`,children:`LLM Parameters`}),(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`max-tokens`,className:`text-sm font-medium`,children:`Max Output Tokens`}),(0,C.jsx)(f,{id:`max-tokens`,type:`number`,min:`1`,max:R?.maxTokens,value:F.maxTokens,onChange:e=>I(t=>({...t,maxTokens:parseInt(e.target.value)||4096})),disabled:q})]}),M!==`anthropic`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`temperature`,className:`text-sm font-medium`,children:`Temperature`}),(0,C.jsx)(f,{id:`temperature`,type:`number`,min:`0`,max:`2`,step:`0.1`,value:F.temperature,onChange:e=>I(t=>({...t,temperature:Number.isNaN(e.target.valueAsNumber)?.7:e.target.valueAsNumber})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`top-p`,className:`text-sm font-medium`,children:`Top P`}),(0,C.jsx)(f,{id:`top-p`,type:`number`,min:`0`,max:`1`,step:`0.1`,value:F.topP,onChange:e=>I(t=>({...t,topP:Number.isNaN(e.target.valueAsNumber)?1:e.target.valueAsNumber})),disabled:q})]}),M===`ollama`&&(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`num-ctx`,className:`text-sm font-medium`,children:`Context Length`}),(0,C.jsx)(f,{id:`num-ctx`,type:`number`,min:`1024`,max:R?.contextWindow,value:F.numCtx,onChange:e=>I(t=>({...t,numCtx:parseInt(e.target.value)||4096})),disabled:q})]})]}),M!==`ollama`&&(0,C.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`frequency-penalty`,className:`text-sm font-medium`,children:`Frequency Penalty`}),(0,C.jsx)(f,{id:`frequency-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.frequencyPenalty,onChange:e=>I(t=>({...t,frequencyPenalty:parseFloat(e.target.value)||0})),disabled:q})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`presence-penalty`,className:`text-sm font-medium`,children:`Presence Penalty`}),(0,C.jsx)(f,{id:`presence-penalty`,type:`number`,min:`-2`,max:`2`,step:`0.1`,value:F.presencePenalty,onChange:e=>I(t=>({...t,presencePenalty:parseFloat(e.target.value)||0})),disabled:q})]})]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`label`,{htmlFor:`agent-color`,className:`text-sm font-medium`,children:`Agent Color`}),(0,C.jsx)(f,{id:`agent-color`,type:`color`,value:O,onChange:e=>k(e.target.value),className:`h-10 w-16 p-1`,disabled:q}),(0,C.jsx)(d,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>k(m()),disabled:q,children:`Randomize`})]}),(0,C.jsxs)(d,{type:`submit`,disabled:q||!u.trim(),children:[(0,C.jsx)(a,{className:`mr-2 h-4 w-4`}),`Create Agent`]})]})}),(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your Agents`}),o&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading agents...`}),c&&(0,C.jsx)(`div`,{className:`text-center text-destructive`,children:(0,C.jsx)(`p`,{children:c})}),!o&&!c&&n.length===0&&(0,C.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No agents found`}),n.length>0&&(0,C.jsx)(`div`,{className:`grid gap-4`,children:n.map(e=>(0,C.jsx)(w,{agent:e,onStart:ue,onStop:de,onEnter:fe},e.id))})]})]})}export{T as default};