@augmentd-labs/canvas-web 2.26.19 → 2.26.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/DocumentBodyEditor-CE2S2X6g.js +1 -0
- package/dist/assets/DocumentIcon-BS10SIP6.js +1 -0
- package/dist/assets/EditorOverlay-BUToR_av.js +1 -0
- package/dist/assets/FileForm-BxTixeDm.js +1 -0
- package/dist/assets/FiltersApplet-BpqITV13.js +1 -0
- package/dist/assets/HomeFab-BAKOAkpE.js +3 -0
- package/dist/assets/IdentityFields-C2MPM-Ab.js +1 -0
- package/dist/assets/LensApplet-DNTGwgZs.js +1 -0
- package/dist/assets/LinkToCard-BZwwE-Dv.js +1 -0
- package/dist/assets/LinkToSidePanel-eCy3nW4R.js +1 -0
- package/dist/assets/{LocationTab-BONJQfYM.js → LocationTab-DAtqAQ3l.js} +1 -1
- package/dist/assets/{MarkdownEditor-CkobBLtI.js → MarkdownEditor-7OqSDr7E.js} +1 -1
- package/dist/assets/MessageComposerDialog-DzLhkHyh.js +4 -0
- package/dist/assets/{NextShell-Byg6OtC2.js → NextShell-D9gvlKY2.js} +1 -1
- package/dist/assets/NotesApplet-gMAMneRi.js +1 -0
- package/dist/assets/ObjectPropertiesCard-C3jt40tM.css +1 -0
- package/dist/assets/ObjectPropertiesCard-DDcRLpsW.js +8 -0
- package/dist/assets/PathPickerField-cVs5sZuG.js +1 -0
- package/dist/assets/PickDocumentsCard-BlicxMqC.js +1 -0
- package/dist/assets/SketchApplet-D8mkYmK9.js +1 -0
- package/dist/assets/{SketchEditor-C9_lu3Ot.js → SketchEditor-zMrm1npg.js} +4 -4
- package/dist/assets/TerminalApplet-BO2HRp0z.js +20 -0
- package/dist/assets/TerminalApplet-BrP-ENHg.css +1 -0
- package/dist/assets/TextDocumentEditor-7V4aFL8i.js +1 -0
- package/dist/assets/TodosApplet-swdaBT-2.js +1 -0
- package/dist/assets/TodosWidget-BXF8fYer.js +1 -0
- package/dist/assets/UploadProgressList-B2xCVzFR.js +1 -0
- package/dist/assets/_agentId_-Ci4j4UYy.js +0 -0
- package/dist/assets/_contextId_-DDFyhgV2.js +1 -0
- package/dist/assets/_workspaceName_-DO9ZBx7N.js +1 -0
- package/dist/assets/about-B1_n4Iu8.js +1 -0
- package/dist/assets/add-BnwWcDlO.js +1 -0
- package/dist/assets/admin-Bhg9QBHL.js +5 -0
- package/dist/assets/agents-ClK3Y2x0.js +1 -0
- package/dist/assets/agents-DquOfkFX.js +1 -0
- package/dist/assets/alert-dialog-DIA-tAP5.js +1 -0
- package/dist/assets/api-CA6WiiYM.js +1 -0
- package/dist/assets/api-tokens-O5iFESo0.js +1 -0
- package/dist/assets/appearance-C2vu3ALt.js +1 -0
- package/dist/assets/applet-target-DnTa2VAT.js +1 -0
- package/dist/assets/apps-BZrw8Cqo.js +1 -0
- package/dist/assets/auth-Bx9fAZmz.js +1 -0
- package/dist/assets/auth-CUdpxbLV.js +1 -0
- package/dist/assets/backend-sync-progress-DU-e9TWi.css +1 -0
- package/dist/assets/backend-sync-progress-DWR42uQV.js +7 -0
- package/dist/assets/blobs-WiXP9QRi.js +1 -0
- package/dist/assets/button-Bv4zA1qr.js +1 -0
- package/dist/assets/chunk-62JRHF6Z-vspAGgtK.js +3 -0
- package/dist/assets/{chunk-K2UTITRG-zQFDOW3Q.js → chunk-K2UTITRG-BvHe9UPk.js} +3 -3
- package/dist/assets/code-editor-BOIngd5F.js +40 -0
- package/dist/assets/color-DFEH4BfK.js +1 -0
- package/dist/assets/content-app-view-C33Ip_rx.js +1 -0
- package/dist/assets/context-D_K4g9SQ.js +1 -0
- package/dist/assets/contexts-B6d6Axza.js +1 -0
- package/dist/assets/contexts-CgydYDn-2.js +1 -0
- package/dist/assets/date-time-picker-BZaA3M9_.js +1 -0
- package/dist/assets/desk-dI_FvLsK.js +1 -0
- package/dist/assets/devices-CAa1bRxk.js +1 -0
- package/dist/assets/devices-D3-_UWM0.js +1 -0
- package/dist/assets/document-BG_mODBn.js +1 -0
- package/dist/assets/document-list-BiogH4tf.js +2 -0
- package/dist/assets/document-list-DAYdk5vh.css +1 -0
- package/dist/assets/document-open-mode-DoImW-xs.js +1 -0
- package/dist/assets/embedding-Cjrxh6MN.js +1 -0
- package/dist/assets/embedding-m8SZH4oN.js +1 -0
- package/dist/assets/form-panel-Dz96K7Lv.js +1 -0
- package/dist/assets/geo-CZfs0E-x.js +1 -0
- package/dist/assets/home-pS7q4Wl4.js +1 -0
- package/dist/assets/image-GAAHSSAO-CI-0hUck.js +1 -0
- package/dist/assets/index-C10UNpew.css +2 -0
- package/dist/assets/index-exXolIqD.js +16 -0
- package/dist/assets/inferd-config-editor-DagMmwW4.js +1 -0
- package/dist/assets/input-BOtCd4HP.js +1 -0
- package/dist/assets/key-bindings-BOtykyXR.js +1 -0
- package/dist/assets/label-CNoJOoe0.js +1 -0
- package/dist/assets/last-path-BbXWC3b3.js +1 -0
- package/dist/assets/layer-style-Byl5LNFR.js +1 -0
- package/dist/assets/lazy-editor-Cbva8Pe2.js +2 -0
- package/dist/assets/logs-CdbfY8_H.js +1 -0
- package/dist/assets/{markdown-html-XoABNf32.js → markdown-html-CZMGihx6.js} +1 -1
- package/dist/assets/markdown-view-BBBZtNSR.js +2 -0
- package/dist/assets/note-save-status-DPz4VzL6.js +1 -0
- package/dist/assets/offline-BjMpUv3N.js +1 -0
- package/dist/assets/page-header-GtTr9Ff_.js +1 -0
- package/dist/assets/public-share-DT9Tgn_Y.js +1 -0
- package/dist/assets/query-debug-tVbB_8Z6.js +1 -0
- package/dist/assets/react-BHzhHVTZ.js +164 -0
- package/dist/assets/registry-6tE_1KPV.js +2 -0
- package/dist/assets/relation-events-CKio19hE.js +1 -0
- package/dist/assets/remotes-DR_iJClb.js +1 -0
- package/dist/assets/role-C5I0Plgn.js +1 -0
- package/dist/assets/roles-DERIgujv.js +2 -0
- package/dist/assets/roles-DswT1Lv0.js +2 -0
- package/dist/assets/settings-Cc6OMCOX.js +14 -0
- package/dist/assets/settings-D7K7z_JD.js +1 -0
- package/dist/assets/settings-Du8r1SXC.js +1 -0
- package/dist/assets/settings-vosK_LI-.js +1 -0
- package/dist/assets/share-target-Df10J5JB.js +1 -0
- package/dist/assets/shared-1dpCuibu.js +1 -0
- package/dist/assets/shared-C7b3QOUP.js +1 -0
- package/dist/assets/sketch-lazy-Q58-vPF-.js +2 -0
- package/dist/assets/socket-CtH3EU9m.js +1 -0
- package/dist/assets/subtree-transfer-dialog-B7s4r78T.js +1 -0
- package/dist/assets/tags-YamdPoBK.js +1 -0
- package/dist/assets/text-documents-D_zDMyhB.js +2 -0
- package/dist/assets/{ui-BqHBdBU4.js → ui-BSqPn1LJ.js} +2 -2
- package/dist/assets/url-params-n7kU_WZ-.js +1 -0
- package/dist/assets/use-applet-docs-Cry2SFsG.js +1 -0
- package/dist/assets/use-applet-target-mkjQujx6.js +1 -0
- package/dist/assets/use-canvas-pins-C57Vbkrq.css +1 -0
- package/dist/assets/use-canvas-pins-CZBfEB5E.js +3 -0
- package/dist/assets/use-create-panel-DhSNIGtr.js +1 -0
- package/dist/assets/use-document-modal-PG8bQyIB.js +1 -0
- package/dist/assets/use-menu-BVkqNEIx.js +1 -0
- package/dist/assets/use-mobile-Db-vWu9Y.js +1 -0
- package/dist/assets/use-settings-back-Dk-DJEUO.js +1 -0
- package/dist/assets/use-sortable-data-DYIDDI8c.js +1 -0
- package/dist/assets/{use-theme-Bd8sb5Ox.js → use-theme-DaxpiICf.js} +1 -1
- package/dist/assets/use-toast-BlLDqSUO.js +1 -0
- package/dist/assets/use-toolbox-Ck_cLGgf.js +1 -0
- package/dist/assets/use-workspace-identity-BVpGHkZq.js +1 -0
- package/dist/assets/useAddTarget-CVRPElxz.js +1 -0
- package/dist/assets/useAgentModels-DI41aFY3.js +3 -0
- package/dist/assets/useDocumentThumbnail-C_rq2rXs.js +1 -0
- package/dist/assets/useEditNoteFields-Bigs9ZG8.js +1 -0
- package/dist/assets/useEscapeClose-DR_xKT_k.js +1 -0
- package/dist/assets/useSocketSubscription-ifW-vnlb.js +1 -0
- package/dist/assets/useToastHelpers-CRrpIIdY.js +1 -0
- package/dist/assets/users-C9N-O1QA.js +1 -0
- package/dist/assets/workspace-BydSRtST.js +1 -0
- package/dist/assets/workspace-CJ1PWQ29.js +1 -0
- package/dist/assets/workspace-access-C9nZlBBZ.js +1 -0
- package/dist/assets/workspace-area-menu-Ba_9bGKs.js +1 -0
- package/dist/assets/workspace-content-gate-D8bzGD9i.js +1 -0
- package/dist/assets/workspace-import-form-D5JA8gzx.js +1 -0
- package/dist/assets/workspaces-C9Wtka2V.js +1 -0
- package/dist/assets/workspaces-Dx5_N57M.js +1 -0
- package/dist/index.html +69 -14
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/dist/assets/EditorOverlay-B384ALjA.js +0 -1
- package/dist/assets/TextDocumentEditor-DBVWuJaR.js +0 -1
- package/dist/assets/alert-dialog-BC58hyW-.js +0 -1
- package/dist/assets/blobs-CtDkR2hC.js +0 -1
- package/dist/assets/code-editor-BQnKd3jw.js +0 -40
- package/dist/assets/document-list-BmUv3zzK.js +0 -19
- package/dist/assets/document-list-r-TfV16D.css +0 -1
- package/dist/assets/image-GAAHSSAO-BoD-NvEF.js +0 -1
- package/dist/assets/index-BhcdilCi.css +0 -2
- package/dist/assets/index-DRji5GQn.js +0 -61
- package/dist/assets/react-BzqgEMSQ.js +0 -164
- package/dist/assets/subtree-transfer-dialog-DRz8kLqY.js +0 -1
- package/dist/assets/text-documents-BvR9-zf4.js +0 -3
- package/dist/assets/useAddTarget-CgZfKokT.js +0 -1
- package/dist/assets/workspace-BSXnX2Me.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.xterm{cursor:text;-webkit-user-select:none;user-select:none;position:relative}.xterm.focus,.xterm:focus{outline:none}.xterm .xterm-helpers{z-index:5;position:absolute;top:0}.xterm .xterm-helper-textarea{opacity:0;z-index:-5;white-space:nowrap;resize:none;border:0;width:0;height:0;margin:0;padding:0;position:absolute;top:0;left:-9999em;overflow:hidden}.xterm .composition-view{color:#fff;white-space:nowrap;z-index:1;background:#000;display:none;position:absolute}.xterm .composition-view.active{display:block}.xterm .xterm-viewport{cursor:default;background-color:#000;position:absolute;inset:0;overflow-y:scroll}.xterm .xterm-screen{position:relative}.xterm .xterm-screen canvas{position:absolute;top:0;left:0}.xterm-char-measure-element{visibility:hidden;line-height:normal;display:inline-block;position:absolute;top:0;left:-9999em}.xterm.enable-mouse-events{cursor:default}.xterm.xterm-cursor-pointer,.xterm .xterm-cursor-pointer{cursor:pointer}.xterm.column-select.focus{cursor:crosshair}.xterm .xterm-accessibility:not(.debug),.xterm .xterm-message{z-index:10;color:#0000;pointer-events:none;position:absolute;inset:0}.xterm .xterm-accessibility-tree:not(.debug) ::selection{color:#0000}.xterm .xterm-accessibility-tree{-webkit-user-select:text;user-select:text;white-space:pre;font-family:monospace}.xterm .xterm-accessibility-tree>div{transform-origin:0;width:fit-content}.xterm .live-region{width:1px;height:1px;position:absolute;left:-9999px;overflow:hidden}.xterm-dim{opacity:1!important}.xterm-underline-1{text-decoration:underline}.xterm-underline-2{-webkit-text-decoration:underline double;text-decoration:underline double}.xterm-underline-3{-webkit-text-decoration:underline wavy;text-decoration:underline wavy}.xterm-underline-4{-webkit-text-decoration:underline dotted;text-decoration:underline dotted}.xterm-underline-5{-webkit-text-decoration:underline dashed;text-decoration:underline dashed}.xterm-overline{text-decoration:overline}.xterm-overline.xterm-underline-1{text-decoration:underline overline}.xterm-overline.xterm-underline-2{-webkit-text-decoration:overline double underline;text-decoration:overline double underline}.xterm-overline.xterm-underline-3{-webkit-text-decoration:overline wavy underline;text-decoration:overline wavy underline}.xterm-overline.xterm-underline-4{-webkit-text-decoration:overline dotted underline;text-decoration:overline dotted underline}.xterm-overline.xterm-underline-5{-webkit-text-decoration:overline dashed underline;text-decoration:overline dashed underline}.xterm-strikethrough{text-decoration:line-through}.xterm-screen .xterm-decoration-container .xterm-decoration{z-index:6;position:absolute}.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer{z-index:7}.xterm-decoration-overview-ruler{z-index:8;pointer-events:none;position:absolute;top:0;right:0}.xterm-decoration-top{z-index:2;position:relative}.xterm .xterm-scrollable-element>.scrollbar{cursor:default}.xterm .xterm-scrollable-element>.scrollbar>.scra{cursor:pointer;font-size:11px!important}.xterm .xterm-scrollable-element>.visible{opacity:1;z-index:11;background:0 0;transition:opacity .1s linear}.xterm .xterm-scrollable-element>.invisible{opacity:0;pointer-events:none}.xterm .xterm-scrollable-element>.invisible.fade{transition:opacity .8s linear}.xterm .xterm-scrollable-element>.shadow{display:none;position:absolute}.xterm .xterm-scrollable-element>.shadow.top{width:100%;height:3px;box-shadow:var(--vscode-scrollbar-shadow,#000) 0 6px 6px -6px inset;display:block;top:0;left:3px}.xterm .xterm-scrollable-element>.shadow.left{width:3px;height:100%;box-shadow:var(--vscode-scrollbar-shadow,#000) 6px 0 6px -6px inset;display:block;top:3px;left:0}.xterm .xterm-scrollable-element>.shadow.top-left-corner{width:3px;height:3px;display:block;top:0;left:0}.xterm .xterm-scrollable-element>.shadow.top.left{box-shadow:var(--vscode-scrollbar-shadow,#000) 6px 0 6px -6px inset}
|
|
@@ -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{Ct as r}from"./ui-BSqPn1LJ.js";import{t as i}from"./button-Bv4zA1qr.js";import{In as a,Un as o}from"./workspace-CJ1PWQ29.js";import{a as s,i as c,n as l,o as u,r as d,t as f}from"./text-documents-D_zDMyhB.js";import{t as p}from"./useToastHelpers-CRrpIIdY.js";import{t as m}from"./note-save-status-DPz4VzL6.js";import{t as h}from"./useEditNoteFields-Bigs9ZG8.js";import{t as g}from"./DocumentBodyEditor-CE2S2X6g.js";import{t as _}from"./EditorOverlay-BUToR_av.js";var v=e(n(),1),y=t();function b({doc:e,workspaceName:t,onSaved:n,onClose:b,onDetails:x}){let{showSuccessToast:S,showErrorToast:C}=p(),w=e.schema===o,T=c(e),E=T&&s(e),D=d(e)??`markdown`,O=u(t,e.id,{mode:`text`,enabled:T&&!E,maxTextLength:l,version:e.checksumArray?.[0]??null}),[k,A]=(0,v.useState)(w?String(e.data?.content??``):``),j=h(e,t,w),M=w?j.content:k,N=w?j.setContent:A,[P,F]=(0,v.useState)(null),I=`${e.id}:${e.checksumArray?.[0]??``}`;T&&O.text!=null&&P!==I&&(F(I),N(O.text));let[L,R]=(0,v.useState)(!1),z=w||O.text!=null&&!O.loading,B=async()=>{R(!0);try{let r;w?await j.save():r=await f(t,e,M),S(`Document saved`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n(r)}catch(e){C(e instanceof Error?e.message:`Failed to save document`)}finally{R(!1)}},V=w?String(e.data?.title??`Note`):a(e)||`document-${e.id}`;return(0,y.jsx)(_,{onClose:b,onDetails:x,title:(0,y.jsx)(`span`,{className:`truncate text-sm font-medium`,children:V}),actions:(0,y.jsxs)(y.Fragment,{children:[w&&(0,y.jsx)(m,{...j,onRetry:j.save}),(0,y.jsxs)(i,{size:`sm`,onClick:B,disabled:L||!z||E,children:[(0,y.jsx)(r,{className:`mr-1.5 h-4 w-4`}),L?`Saving…`:`Save`]})]}),children:(0,y.jsx)(`div`,{className:`flex h-full min-h-0 flex-col px-4 py-4 md:px-8`,children:(0,y.jsx)(`div`,{className:`mx-auto flex min-h-0 w-full max-w-full flex-1 flex-col overflow-auto md:w-[700px] md:min-w-[320px] md:resize-x`,children:E?(0,y.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`This file is too large to edit here (`,`>`,Math.round(l/1e3),` kB) — download it instead.`]}):O.error?(0,y.jsx)(`p`,{className:`text-sm text-destructive`,children:O.error}):z?(0,y.jsx)(g,{kind:w?`markdown`:D,value:M,onChange:N,placeholder:w?`Write your note…`:void 0,fill:!0}):(0,y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading content…`})})})})}export{b as default};
|
|
@@ -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{Hr as r,L as i,Mt as a,Nr as o,dn as s,dr as c,fi as l,kr as u,oi as d,ur as f,yt as p}from"./ui-BSqPn1LJ.js";import{t as m}from"./utils-2pl1SbIp.js";import{Gn as h,On as g,wn as _}from"./workspace-CJ1PWQ29.js";import{o as v,t as y}from"./useAddTarget-CVRPElxz.js";import{a as b,i as x,o as S,r as C,s as w,t as T}from"./date-time-picker-BZaA3M9_.js";import{n as E}from"./use-applet-target-mkjQujx6.js";import{n as D,r as O,t as k}from"./shared-1dpCuibu.js";import{n as A,r as j,t as M}from"./use-applet-docs-Cry2SFsG.js";var N=e(n(),1),P=t(),F=`2.1`,I=new Set([`completed`,`cancelled`]);function L({doc:e,updateWorkspace:t,registerEl:n,registerBody:i,highlighted:a,onLinkTo:c,onDelete:l,onStatusSaved:d}){let[f,p]=(0,N.useState)(String(e.data?.title??``)),[h,v]=(0,N.useState)(String(e.data?.description??``)),[y,x]=(0,N.useState)(e.data?.status||`pending`),[w,E]=(0,N.useState)(b(e.data?.dueDate)),[O,j]=(0,N.useState)(`idle`),{replicating:F,label:L}=g(e),R=(0,N.useRef)({title:String(e.data?.title??``),description:String(e.data?.description??``)}),z=(0,N.useRef)(null),B=(0,N.useRef)(0),V=(0,N.useCallback)(async n=>{if(!t||!n.title.trim())return!1;let r=++B.current;j(`saving`);try{let i=S(n.due),a={...e.data||{},title:n.title.trim(),...n.description.trim()?{description:n.description.trim()}:{description:void 0},status:n.status,completed:n.status===`completed`};return i?a.dueDate=i:delete a.dueDate,await _(t,{id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,data:a,metadata:e.metadata}),r!==B.current||(R.current={title:n.title,description:n.description},j(`saved`),setTimeout(()=>j(e=>e===`saved`?`idle`:e),1500),!0)}catch{return r===B.current&&j(`error`),!1}},[e.id,e.schema,e.schemaVersion,e.data,e.metadata,t]),H=(0,N.useCallback)((e,t)=>{(e!==R.current.title||t!==R.current.description)&&(j(`dirty`),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>V({title:e,description:t,status:y,due:w}),M))},[V,y,w]),U=(0,N.useCallback)(()=>{z.current&&=(clearTimeout(z.current),null),V({title:f,description:h,status:y,due:w})},[V,f,h,y,w]);(0,N.useEffect)(()=>()=>{z.current&&clearTimeout(z.current)},[]);let W=(0,N.useCallback)(async()=>{let t=y,n=y===`completed`?`pending`:`completed`;x(n),await V({title:f,description:h,status:n,due:w})?d(e.id,n):x(t)},[y,V,f,h,w,e.id,d]),G=(0,N.useCallback)(e=>{E(e),z.current&&=(clearTimeout(z.current),null),V({title:f,description:h,status:y,due:e})},[V,f,h,y]),K=I.has(y);return(0,P.jsxs)(`div`,{ref:t=>n(e.id,t),className:m(`group border-t border-border/60 px-4 py-3 transition-colors`,a&&`bg-primary/5`),children:[(0,P.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2`,children:[(0,P.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:[(0,P.jsxs)(`span`,{className:`shrink-0`,children:[A(e.createdAt),` · #`,e.id,y!==`pending`&&(0,P.jsxs)(`span`,{children:[` · `,C[y]??y]})]}),(0,P.jsx)(T,{value:w,onChange:G,compact:!0,placeholder:`No due date`,className:`w-[168px] shrink-0 normal-case tracking-normal`})]}),(0,P.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground/70`,children:[O===`saving`&&(0,P.jsx)(s,{className:`inline h-3 w-3 animate-spin`}),F&&(0,P.jsx)(`span`,{className:`whitespace-nowrap`,children:L}),O===`saved`&&(0,P.jsx)(r,{className:`inline h-3 w-3 text-success`}),O===`dirty`&&`·`,O===`error`&&(0,P.jsx)(`span`,{className:`text-destructive`,children:`save failed`}),(0,P.jsx)(D,{onLinkTo:c,onDelete:l})]})]}),(0,P.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,P.jsx)(`button`,{type:`button`,onClick:W,className:`mt-0.5 shrink-0 text-muted-foreground transition-colors hover:text-foreground`,"aria-label":K?`Mark as pending`:`Mark as completed`,title:K?`Mark as pending`:`Mark as completed`,children:K?(0,P.jsx)(o,{className:`h-4 w-4 text-success`}):(0,P.jsx)(u,{className:`h-4 w-4`})}),(0,P.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,P.jsx)(`input`,{value:f,onChange:e=>{p(e.target.value),H(e.target.value,h)},onBlur:U,placeholder:`Untitled`,spellCheck:!1,className:m(`mb-1 w-full border-0 bg-transparent p-0 text-sm font-semibold outline-none placeholder:text-muted-foreground/50`,K?`text-muted-foreground line-through`:`text-foreground`)}),(0,P.jsx)(k,{value:h,onChange:e=>{v(e),H(f,e)},onBlur:U,placeholder:`Description…`,innerRef:t=>i(e.id,t)})]})]})]})}function R({target:e,onCreated:t,onCancel:n}){let[r,a]=(0,N.useState)(``),[o,s]=(0,N.useState)(``),[c,l]=(0,N.useState)(w()),[u,d]=(0,N.useState)(!1),[f,p]=(0,N.useState)(null);return(0,P.jsxs)(`div`,{className:`border-t border-border/60 bg-muted/30 px-4 py-3`,children:[(0,P.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between`,children:[(0,P.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:`New todo`}),(0,P.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-foreground`,"aria-label":`Discard draft`,children:(0,P.jsx)(i,{className:`h-3 w-3`})})]}),(0,P.jsx)(`input`,{value:r,onChange:e=>a(e.target.value),placeholder:`What needs doing?`,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,P.jsx)(k,{value:o,onChange:s,placeholder:`Description (optional)…`}),(0,P.jsx)(`div`,{className:`mt-2`,children:(0,P.jsx)(T,{value:c,onChange:l,compact:!0,placeholder:`No due date`,className:`w-[188px]`})}),f&&(0,P.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:f}),(0,P.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,P.jsx)(`button`,{type:`button`,onClick:async()=>{if(!(!r.trim()||!e||u)){d(!0),p(null);try{await v(e,[{schema:h,schemaVersion:F,data:x({title:r,description:o,status:`pending`,priority:``,due:c}),metadata:{features:[]}}]),t()}catch(e){p(e instanceof Error?e.message:`Failed to create todo`),d(!1)}}},disabled:!r.trim()||u,className:`rounded-md bg-primary px-2.5 py-1 text-xs text-primary-foreground disabled:opacity-50`,children:u?`Saving…`:`Save todo`})})]})}function z({autoAdd:e=!1}){let t=E(),{docs:n,setDocs:r,loading:i,error:o,scope:u,reload:g,removeDoc:_}=j(t,h),[v,b]=(0,N.useState)(``),[x,S]=(0,N.useState)(0),[C,w]=(0,N.useState)(`desc`),[T,D]=(0,N.useState)(!1),[k,A]=(0,N.useState)(e),[M,F]=(0,N.useState)(null),z=(0,N.useRef)(new Map),B=(0,N.useRef)(new Map),V=(0,N.useCallback)((e,t)=>{t?z.current.set(e,t):z.current.delete(e)},[]),H=(0,N.useCallback)((e,t)=>{t?B.current.set(e,t):B.current.delete(e)},[]),U=(0,N.useCallback)(async e=>{let t=e.data?.title?`"${e.data.title}"`:`#${e.id}`;if(window.confirm(`Delete todo ${t}?\n\nIt is removed from this path and moves to the workspace trash if nothing else links it.`))try{await _(e.id)}catch{}},[_]),W=(0,N.useCallback)((e,t)=>{r(n=>n.map(n=>n.id===e?{...n,data:{...n.data||{},status:t,completed:t===`completed`}}:n))},[r]),G=(0,N.useMemo)(()=>{let e=T?[...n]:n.filter(e=>!I.has(String(e.data?.status??`pending`)));return e.sort((e,t)=>{let n=new Date(e.createdAt).getTime()-new Date(t.createdAt).getTime();return C===`asc`?n:-n}),e},[n,C,T]),K=(0,N.useMemo)(()=>n.filter(e=>I.has(String(e.data?.status??`pending`))).length,[n]),q=(0,N.useMemo)(()=>{let e=v.trim().toLowerCase();if(!e)return[];let t=[];for(let n of G){let r=String(n.data?.description??``),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},[v,G]),J=q.length?q[Math.min(x,q.length-1)]:null;(0,N.useEffect)(()=>{J&&z.current.get(J.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[J]);let Y=(0,N.useCallback)(e=>{if(!q.length)return;let t=e?(x+1)%q.length:x;e&&S(t);let n=q[t],r=B.current.get(n.docId);r&&n.offset>=0&&(r.focus(),r.setSelectionRange(n.offset,n.offset+v.trim().length)),z.current.get(n.docId)?.scrollIntoView({block:`center`,behavior:`smooth`})},[q,x,v]);return t?(0,P.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,P.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border px-3 py-2`,children:[(0,P.jsxs)(`div`,{className:`relative flex-1`,children:[(0,P.jsx)(p,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,P.jsx)(`input`,{value:v,onChange:e=>{b(e.target.value),S(0)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),Y(!0))},placeholder:`Search todos…`,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`}),v.trim()&&(0,P.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-[10px] tabular-nums text-muted-foreground`,children:q.length?`${Math.min(x+1,q.length)}/${q.length}`:`0/0`})]}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>D(e=>!e),className:m(`rounded-md border p-1.5 transition-colors`,T?`border-foreground text-foreground`:`border-border text-muted-foreground hover:bg-muted hover:text-foreground`),title:T?`Hide done items`:`Show done items${K?` (${K})`:``}`,"aria-label":T?`Hide done items`:`Show done items`,children:T?(0,P.jsx)(f,{className:`h-3.5 w-3.5`}):(0,P.jsx)(c,{className:`h-3.5 w-3.5`})}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>w(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:C===`desc`?`Newest first (click for oldest first)`:`Oldest first (click for newest first)`,"aria-label":`Toggle sort order`,children:C===`desc`?(0,P.jsx)(l,{className:`h-3.5 w-3.5`}):(0,P.jsx)(d,{className:`h-3.5 w-3.5`})}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>A(!0),className:`flex items-center gap-1 rounded-md bg-primary px-2 py-1.5 text-xs text-primary-foreground`,title:`Add a todo`,children:[(0,P.jsx)(a,{className:`h-3.5 w-3.5`}),`Todo`]})]}),(0,P.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[k&&(0,P.jsx)(R,{target:t,onCreated:()=>{A(!1),g()},onCancel:()=>A(!1)}),i&&!n.length&&(0,P.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,P.jsx)(s,{className:`h-5 w-5 animate-spin text-muted-foreground`})}),o&&(0,P.jsx)(`p`,{className:`px-4 py-6 text-center text-sm text-destructive`,children:o}),!i&&!o&&!G.length&&!k&&(0,P.jsx)(`p`,{className:`px-4 py-10 text-center text-sm text-muted-foreground`,children:K?`Nothing pending - ${K} done item${K>1?`s`:``} hidden.`:`No todos here yet - add the first one.`}),G.map(e=>(0,P.jsx)(L,{doc:e,updateWorkspace:u?.workspaceName??null,registerEl:V,registerBody:H,highlighted:J?.docId===e.id,onLinkTo:()=>F(e.id),onDelete:()=>U(e),onStatusSaved:W},e.id))]}),M!==null&&(0,P.jsx)(O,{documentId:M,workspaceName:u?.workspaceName,onClose:()=>F(null)})]}):(0,P.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:y(t)})}export{z as TodosApplet};
|
|
@@ -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{Hr as r,Kr as i,dn as a,er as o,pn as s}from"./ui-BSqPn1LJ.js";import{Gn as c,On as l}from"./workspace-CJ1PWQ29.js";import{_ as u,g as d,h as f,m as p,p as m}from"./ObjectPropertiesCard-DDcRLpsW.js";import{r as h}from"./date-time-picker-BZaA3M9_.js";import{n as g}from"./use-document-modal-PG8bQyIB.js";var _=e(n(),1),v=new Map;function y(e){v.set(e.type,e)}function b(e){return v.get(e)}function x(){return[...v.values()]}var S=450,C=10;function w(e,t){let{open:n}=g(),r=(0,_.useRef)(null),i=(0,_.useRef)(null),a=(0,_.useRef)(!1),o=()=>{e&&n(e,t)},s=()=>{r.current&&=(clearTimeout(r.current),null)};return{activationProps:{role:`button`,tabIndex:0,onClick:()=>{if(a.current){a.current=!1;return}o()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())},onContextMenu:e=>{e.preventDefault(),o()},onPointerDown:e=>{e.pointerType===`touch`&&(i.current={x:e.clientX,y:e.clientY},a.current=!1,s(),r.current=setTimeout(()=>{a.current=!0,o()},S))},onPointerMove:e=>{i.current&&Math.hypot(e.clientX-i.current.x,e.clientY-i.current.y)>C&&s()},onPointerUp:s,onPointerCancel:s,onPointerLeave:s},stopRowActivation:e=>e.stopPropagation()}}var T=t(),E=`data/schema/task`;function D({doc:e,workspaceId:t,readOnly:n,onChanged:s}){let c=u(e),[g,v]=(0,_.useState)(!1),{replicating:y,label:b}=l(e),x=c.status===`completed`,S=c.status??`pending`,C=f(c),{activationProps:E,stopRowActivation:D}=w(e,t),O=async()=>{if(!(n||g)){v(!0);try{await d(t,e,x?`pending`:`completed`),s()}catch{}finally{v(!1)}}};return(0,T.jsxs)(`div`,{...E,title:`Open details`,className:`canvas-no-drag flex cursor-pointer items-start gap-2.5 rounded-md border bg-card px-2.5 py-2 transition-colors hover:bg-accent/50 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring ${y?`opacity-60`:``}`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:e=>{D(e),O()},disabled:n||g||y,"aria-pressed":x,title:x?`Mark not done`:`Mark done`,className:`canvas-no-drag mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded border transition-colors ${x?`border-success bg-success text-success-foreground`:`border-input hover:border-success`} ${n?`cursor-default opacity-70`:``}`,children:g?(0,T.jsx)(a,{className:`h-2.5 w-2.5 animate-spin`}):x&&(0,T.jsx)(r,{className:`h-3 w-3`})}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsx)(`div`,{className:`truncate text-sm ${x?`text-muted-foreground line-through`:``}`,children:c.title||`Todo ${e.id}`}),(0,T.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px]`,children:[(0,T.jsx)(`span`,{className:`rounded-full px-1.5 py-0.5 ${m[S]}`,children:h[S]}),c.dueDate&&(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 ${C?`font-medium text-destructive`:`text-muted-foreground`}`,children:[(0,T.jsx)(i,{className:`h-3 w-3`}),p(c.dueDate)]}),typeof c.priority==`number`&&(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-muted-foreground`,children:[(0,T.jsx)(o,{className:`h-3 w-3`}),`P`,c.priority]}),y&&(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,role:`status`,children:[(0,T.jsx)(a,{className:`h-3 w-3 animate-spin`}),b]})]})]})]})}function O({config:e,setConfig:t,canvas:n}){let r=typeof e.pageSize==`number`?e.pageSize:50,[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(!0),[l,d]=(0,_.useState)(0),f=n.interactive===!1,p=n.readOnly!==!0,[m,h]=(0,_.useState)(e.hideDone===!0),g=p?e.hideDone===!0:m,v=n=>{p?t({...e,hideDone:n}):h(n)};(0,_.useEffect)(()=>{let e=!1;return(async()=>{s(!0);try{let t=await n.fetchDocuments({limit:r,allOf:[E],sortBy:`tasks`,order:`asc`});if(e)return;a((t.payload||[]).filter(e=>e.schema===c))}catch{e||a([])}finally{e||s(!1)}})(),()=>{e=!0}},[n,r,l]),(0,_.useEffect)(()=>{let e=()=>d(e=>e+1);return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[]);let y=(0,_.useCallback)(()=>d(e=>e+1),[]),b=g?i.filter(e=>u(e).status!==`completed`):i,x=i.filter(e=>{let t=u(e).status;return t!==`completed`&&t!==`cancelled`}).length;return(0,T.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,T.jsxs)(`div`,{className:`canvas-no-drag flex items-center justify-between gap-2 border-b px-1 pb-2`,children:[(0,T.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[x,` open`]}),(0,T.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>v(e.target.checked),className:`h-3 w-3`}),`Hide done`]})]}),(0,T.jsx)(`div`,{className:`flex-1 space-y-1.5 overflow-y-auto p-1`,children:o&&i.length===0?(0,T.jsx)(`div`,{className:`p-3 text-sm text-muted-foreground`,children:`Loading todos…`}):b.length===0?(0,T.jsx)(`div`,{className:`p-3 text-sm text-muted-foreground`,children:`No todos in this canvas' context.`}):b.map(e=>(0,T.jsx)(D,{doc:e,workspaceId:n.workspaceId,readOnly:f,onChanged:y},e.id))})]})}y({type:`todos`,name:`Todos`,icon:s,defaultSize:{w:4,h:6,minW:3,minH:3},mobileHeight:.6,defaultConfig:{pageSize:50,hideDone:!1},component:O});export{y as a,x as i,w as n,b as r,D 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{Fr as r,Hr as i,L as a,an as o,dn as s,in as c,rr as l}from"./ui-BSqPn1LJ.js";import{t as u}from"./utils-2pl1SbIp.js";import{t as d}from"./button-Bv4zA1qr.js";import{t as f}from"./label-CNoJOoe0.js";import{At as p}from"./workspace-CJ1PWQ29.js";import{o as m,s as h}from"./IdentityFields-C2MPM-Ab.js";import{n as g}from"./tags-YamdPoBK.js";import{a as _,i as v,l as y,o as b,r as x}from"./useAddTarget-CVRPElxz.js";import{r as S}from"./relation-events-CKio19hE.js";import{a as C,n as w,r as T}from"./blobs-WiXP9QRi.js";import{t as E}from"./sha256-65KIjGvZ.js";var D=e(n(),1);function O(e){let[t,n]=(0,D.useState)(null);return(0,D.useEffect)(()=>{if(!e)return;let t=!1;return p(e).then(r=>{t||n({workspace:e,tags:r})}).catch(()=>{}),()=>{t=!0}},[e]),t&&t.workspace===e?t.tags:[]}var k=t();function A(e){if(e.manual){let t=`${e.manual.lat.toFixed(5)}, ${e.manual.lon.toFixed(5)}`;return e.manualLabel?`${e.manualLabel} · ${t}`:`Custom pin · ${t}`}if(!e.supported)return`Needs a secure (https) connection, or pick a point on the map`;if(e.permission===`denied`)return`Blocked. Allow location for this site, or pick a point on the map`;if(e.error)return e.error;if(e.busy)return`Getting your location…`;if(e.enabled&&e.fix){let{lat:t,lon:n,accuracy:r}=e.fix;return`${t.toFixed(5)}, ${n.toFixed(5)}${r==null?``:` · ±${r} m`}`}return e.enabled?`Location will be attached when you save`:`Attach where you are, or pick any point on the map`}function j({geotag:e,idPrefix:t=`geotag`}){let[n,r]=(0,D.useState)(!1),i=!e.supported||e.permission===`denied`,l=!e.manual&&(!e.supported||e.permission===`denied`||!!e.error);return(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,k.jsxs)(`div`,{role:`switch`,"aria-checked":e.enabled,"aria-disabled":i,"aria-label":`Geotag this document`,"aria-describedby":`${t}-hint`,tabIndex:i?-1:0,onClick:()=>!i&&e.setEnabled(!e.enabled),onKeyDown:t=>{i||(t.key===` `||t.key===`Enter`)&&(t.preventDefault(),e.setEnabled(!e.enabled))},className:u(`flex flex-1 items-center justify-between gap-3 select-none outline-none rounded focus-visible:ring-2 focus-visible:ring-ring`,i?`cursor-not-allowed opacity-50`:`cursor-pointer`),children:[(0,k.jsxs)(`span`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[e.busy?(0,k.jsx)(s,{className:`h-4 w-4 shrink-0 animate-spin text-muted-foreground`}):(0,k.jsx)(o,{className:u(`h-4 w-4 shrink-0`,e.enabled?`text-info`:`text-muted-foreground`)}),`Geotag`]}),(0,k.jsx)(`div`,{className:u(`relative h-5 w-10 shrink-0 rounded-full transition-colors`,e.enabled?`bg-info`:`bg-muted-foreground/30`),children:(0,k.jsx)(`div`,{className:u(`absolute top-[2px] h-4 w-4 rounded-full bg-background shadow-elevation-1 transition-transform`,e.enabled?`translate-x-[22px]`:`translate-x-[2px]`)})})]}),(0,k.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,k.jsxs)(`button`,{type:`button`,onClick:()=>r(!0),title:`Pick a point on the map`,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,k.jsx)(c,{className:`h-3.5 w-3.5`}),e.manual?`Change pin`:`Pick on map`]}),e.manual&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>e.setManual(null),"aria-label":`Remove custom pin`,title:`Remove custom pin`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,k.jsx)(a,{className:`h-3.5 w-3.5`})})]})]}),(0,k.jsx)(`p`,{id:`${t}-hint`,className:u(`text-xs`,l?`text-warning`:`text-muted-foreground`),children:A(e)}),n&&(0,k.jsx)(m,{initial:e.manual??e.fix??null,onPick:t=>e.setManual(t),onClose:()=>r(!1)})]})}var M=`data/schema/file`,N=`3.0`;function P(e){let[t,n]=(0,D.useState)([]),[r,i]=(0,D.useState)(``);return{tags:t,setTags:n,comment:r,setComment:i,suggestions:O(e),geotag:S()}}function F(e,t,n={}){let r=g(n.tags??[]),i=n.comment?.trim();return{schema:M,schemaVersion:N,data:{},checksumArray:[`sha256/${e.checksum}`],locations:[{url:e.url,metadata:{filename:t.name}}],...i?{comment:i}:{},metadata:{contentType:t.type,size:e.size,...r.length?{features:r}:{},...n.geo?{geo:n.geo}:{}}}}var I=`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`;function L({fields:e,idPrefix:t=`file`,multiple:n=!1}){return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsx)(f,{children:`Tags`}),(0,k.jsx)(h,{tags:e.tags,onChange:e.setTags,suggestions:e.suggestions})]}),(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsx)(f,{htmlFor:`${t}-comment`,children:`Comment`}),(0,k.jsx)(`textarea`,{id:`${t}-comment`,value:e.comment,onChange:t=>e.setComment(t.target.value),rows:3,placeholder:`Optional; searchable, and the only text a photo has`,className:I}),n&&e.tags.length+e.comment.trim().length>0&&(0,k.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Applied to every file in this upload`})]}),(0,k.jsx)(j,{geotag:e.geotag,idPrefix:`${t}-geotag`})]})}var R=3;function z(e){return`${e.name}:${e.size}:${e.lastModified}`}function B(e=[]){let[t,n]=(0,D.useState)(()=>e.map(e=>({id:z(e),file:e,status:`queued`,progress:0}))),[r,i]=(0,D.useState)(!1),a=(0,D.useRef)(t),o=(0,D.useRef)(null),s=(0,D.useRef)(null);(0,D.useEffect)(()=>()=>s.current?.abort(),[]);let c=(0,D.useCallback)(e=>{a.current=e,n(e)},[]),l=(0,D.useCallback)((e,t)=>{let r=a.current.map(n=>n.id===e?{...n,...t}:n);a.current=r,n(r)},[]),u=(0,D.useCallback)(e=>{let t=new Set(a.current.map(e=>e.id)),n=e.filter(e=>!t.has(z(e))).map(e=>({id:z(e),file:e,status:`queued`,progress:0}));n.length&&c([...a.current,...n])},[c]),d=(0,D.useCallback)(e=>{c(a.current.filter(t=>t.id!==e))},[c]),f=(0,D.useCallback)(()=>{s.current?.abort(),s.current=null,c([]),i(!1)},[c]),p=(0,D.useCallback)(()=>{s.current?.abort()},[]);return{items:t,running:r,addFiles:u,removeItem:d,reset:f,start:(0,D.useCallback)(async(e,t)=>{if(!e)throw Error(`No active workspace or context to add to`);let{workspaceName:n,treeName:r,path:u}=await _(e),d=r===`backends`?await v(n,u):null,f=JSON.stringify([n,r,u]);o.current!==null&&o.current!==f&&c(a.current.map(({id:e,file:t})=>({id:e,file:t,status:`queued`,progress:0}))),o.current=f;let p=new AbortController;s.current=p,i(!0);let m=a.current.filter(e=>e.status!==`done`);for(let e of m)l(e.id,{status:`queued`,progress:0,error:void 0});try{if(d){let e=0;await Promise.all(Array.from({length:Math.min(R,m.length)},async()=>{for(;e<m.length&&!p.signal.aborted;){let t=m[e++];try{l(t.id,{status:`uploading`,progress:0,resumed:!1});let e=await T(n,{...d,key:y(d.key,t.file.name)},t.file,{signal:p.signal,onProgress:(e,n)=>l(t.id,{progress:n?e/n:0})});l(t.id,{status:`done`,progress:1,docId:e.docId??void 0})}catch(e){l(t.id,{status:`error`,error:e instanceof Error?e.message:`Upload failed`})}}}))}else{let r=new Map;for(let e of m){if(p.signal.aborted)throw new DOMException(`cancelled`,`AbortError`);if(!(e.file.size>=8388608)){l(e.id,{status:`hashing`});try{let t=await E(e.file,t=>l(e.id,{progress:t}));r.set(e.id,t),l(e.id,{status:`checking`,progress:0})}catch(t){l(e.id,{status:`error`,error:t instanceof Error?t.message:`Failed to read file`})}}}let i={};if(r.size)try{i=await w(n,[...new Set(r.values())])}catch{i={}}let a=m.filter(e=>r.has(e.id)||e.file.size>=8388608),o=0;await Promise.all(Array.from({length:Math.min(R,a.length)},async()=>{for(;o<a.length;){if(p.signal.aborted)return;let s=a[o++],c=r.get(s.id);try{let r=c?i[c]??null:null;r?l(s.id,{status:`linking`,progress:1,resumed:!0}):(l(s.id,{status:`uploading`,progress:0}),r=await C(n,s.file,{sha256:c,signal:p.signal,onProgress:(e,t)=>l(s.id,{progress:t?e/t:0})}),l(s.id,{status:`linking`,progress:1}));let a=await b(e,[t(r,s.file)],{refresh:!1});l(s.id,{status:`done`,docId:a[0]})}catch(e){let t=e instanceof DOMException&&e.name===`AbortError`;l(s.id,{status:`error`,error:t?`Cancelled`:e instanceof Error?e.message:`Upload failed`})}}}))}}finally{if(p.signal.aborted)for(let e of a.current)e.status!==`done`&&e.status!==`error`&&l(e.id,{status:`error`,error:`Cancelled`});i(!1),s.current===p&&(s.current=null),a.current.some(e=>e.status===`done`)&&x(e)}let h=a.current;return{done:h.filter(e=>e.status===`done`).length,resumed:h.filter(e=>e.status===`done`&&e.resumed).length,failed:h.filter(e=>e.status===`error`).length,total:h.length,docIds:h.flatMap(e=>e.status===`done`&&e.docId!=null?[e.docId]:[])}},[l,c]),cancel:p}}function V(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function H(e){switch(e.status){case`hashing`:return`hashing`;case`checking`:return`checking`;case`uploading`:return`${Math.round(e.progress*100)}%`;case`linking`:return`saving`;case`done`:return e.resumed?`already uploaded`:`done`;case`error`:return e.error||`failed`;default:return V(e.file.size)}}function U({item:e}){switch(e.status){case`done`:return(0,k.jsx)(i,{className:`h-3.5 w-3.5 shrink-0 text-green-600 dark:text-green-500`});case`error`:return(0,k.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-destructive`});case`queued`:return(0,k.jsx)(l,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`});default:return(0,k.jsx)(s,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground`})}}function W({item:e}){if(e.status===`queued`)return null;let t=e.status===`done`||e.status===`error`||e.status===`linking`?1:e.status===`checking`?0:e.progress;return(0,k.jsx)(`div`,{className:`h-1 w-full overflow-hidden rounded-full bg-muted`,children:(0,k.jsx)(`div`,{className:u(`h-full rounded-full transition-[width] duration-normal`,e.status===`error`?`bg-destructive`:e.status===`done`?`bg-green-600 dark:bg-green-500`:`bg-primary`),style:{width:`${Math.round(t*100)}%`}})})}function G({items:e,running:t,onRemove:n}){let r=e.filter(e=>e.status===`done`).length,i=e.filter(e=>e.status===`error`).length;return(0,k.jsx)(k.Fragment,{children:e.length>0&&(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsxs)(f,{children:[e.length,` file(s)`,r>0&&(0,k.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[`— `,r,` done`,i>0?`, ${i} failed`:``]})]}),(0,k.jsx)(`ul`,{className:`max-h-48 space-y-1 overflow-y-auto`,children:e.map(e=>(0,k.jsxs)(`li`,{className:`flex flex-col gap-1 rounded border border-input px-2 py-1 text-sm`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(U,{item:e}),(0,k.jsx)(`span`,{className:`flex-1 truncate`,title:e.file.name,children:e.file.name}),(0,k.jsx)(`span`,{className:u(`shrink-0 text-xs`,e.status===`error`?`text-destructive`:`text-muted-foreground`),title:e.status===`error`?e.error:void 0,children:H(e)}),!t&&e.status!==`done`&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>n(e.id),className:`text-muted-foreground hover:text-foreground`,"aria-label":`Remove ${e.file.name}`,children:(0,k.jsx)(a,{className:`h-3.5 w-3.5`})})]}),(0,k.jsx)(W,{item:e})]},e.id))})]})})}function K({items:e,running:t,onCancel:n}){return(0,k.jsxs)(`div`,{className:`space-y-4 overflow-y-auto p-4`,children:[(0,k.jsx)(`h2`,{className:`text-sm font-medium`,children:`Uploading files`}),!t&&(0,k.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Preparing / finishing upload…`}),(0,k.jsx)(G,{items:e,running:!0,onRemove:()=>{}}),(0,k.jsx)(d,{variant:`outline`,size:`sm`,disabled:!t,onClick:n,children:`Cancel upload`})]})}export{F as a,O as c,L as i,K as n,P as o,B as r,j as s,G as t};
|
|
Binary file
|
|
@@ -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{_ 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};
|
|
@@ -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{_ 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)&>.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)))&>.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&>.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};
|
|
@@ -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{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};
|
|
@@ -0,0 +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};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{c as e,t}from"./api-CA6WiiYM.js";function n(e={}){let t=new URLSearchParams;e.tail&&t.set(`tail`,String(e.tail)),e.level&&t.set(`level`,e.level),e.module&&t.set(`module`,e.module);let n=t.toString();return n?`?${n}`:``}function r(){let e=localStorage.getItem(`authToken`);if(!e)throw Error(`Authentication required`);let t=localStorage.getItem(`appName`)||window.location.hostname;return{Authorization:`Bearer ${e}`,"X-App-Name":t,Accept:`text/event-stream`}}var i={users:{async listUsers(n){let r=new URLSearchParams;n?.status&&r.append(`status`,n.status),n?.userType&&r.append(`userType`,n.userType);let i=r.toString(),a=i?`${e.admin.users}?${i}`:e.admin.users;return await t.get(a)},async getUser(n){return await t.get(`${e.admin.users}/${n}`)},async createUser(n){return await t.post(e.admin.users,n)},async updateUser(n,r){return await t.put(`${e.admin.users}/${n}`,r)},async deleteUser(n){await t.delete(`${e.admin.users}/${n}`)}},workspaces:{async listAllWorkspaces(){return await t.get(e.admin.workspaces)},async createWorkspace(n){return await t.post(e.admin.workspaces,n)},async deleteWorkspace(n){await t.delete(`${e.admin.workspaces}/${n}`)}},logs:{async getLogs(r={}){return(await t.get(`${e.admin.logs}${n(r)}`)).logs||[]},async streamLogs(t={},i={}){let{signal:a,onEntry:o,onError:s}=i;try{let i=await fetch(`${e.admin.logsStream}${n(t)}`,{method:`GET`,headers:r(),credentials:`include`,signal:a});if(!i.ok)throw Error(`Failed to open log stream (${i.status})`);if(!i.body)throw Error(`Streaming is not supported by this browser`);let s=i.body.getReader(),c=new TextDecoder,l=``,u=e=>{let t=e.split(`
|
|
2
|
+
`),n=`message`,r=[];for(let e of t)if(!(!e||e.startsWith(`:`))){if(e.startsWith(`event:`)){n=e.slice(6).trim();continue}e.startsWith(`data:`)&&r.push(e.slice(5).trim())}if(n!==`log`||r.length===0)return;let i=JSON.parse(r.join(`
|
|
3
|
+
`));o?.(i)};try{for(;;){let{done:e,value:t}=await s.read();if(e)break;l+=c.decode(t,{stream:!0});let n=l.split(`
|
|
4
|
+
|
|
5
|
+
`);l=n.pop()||``;for(let e of n)u(e)}l.trim()&&u(l)}finally{s.releaseLock()}}catch(e){if(a?.aborted)return;let t=e instanceof Error?e:Error(String(e));throw s?.(t),t}}}};export{i 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{i as r}from"./auth-Bx9fAZmz.js";import{n as i}from"./page-header-GtTr9Ff_.js";var a=e(n(),1),o=t();function s(){let e=r()?.userType===`admin`;return(0,a.useEffect)(()=>{},[e]),e?(0,o.jsxs)(`div`,{className:`space-y-6`,children:[(0,o.jsx)(i,{title:`All Agents`,description:`Manage all AI agents across all users`}),(0,o.jsx)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:(0,o.jsxs)(`div`,{className:`text-center`,children:[(0,o.jsx)(`h2`,{className:`text-2xl font-semibold mb-2`,children:`Coming Soon`}),(0,o.jsx)(`p`,{className:`text-muted-foreground max-w-md`,children:`Global agent management is currently under development. Check back later for updates.`})]})})]}):(0,o.jsx)(`div`,{className:`text-center space-y-4`,children:(0,o.jsx)(`div`,{className:`text-destructive`,children:`Access denied. Admin privileges required.`})})}export{s as default};
|
|
@@ -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{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};
|
|
@@ -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{A as r,D as i,E as a,M as o,N as s,O as c,T as l,j as u,k as d}from"./ui-BSqPn1LJ.js";import{t as f}from"./utils-2pl1SbIp.js";import{n as p}from"./button-Bv4zA1qr.js";var m=e(n(),1),h=t(),g=u,_=s,v=r,y=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(d,{className:f(`fixed inset-0 z-50 bg-scrim duration-normal data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t,ref:n}));y.displayName=d.displayName;var b=m.forwardRef(({className:e,...t},n)=>(0,h.jsxs)(v,{children:[(0,h.jsx)(y,{}),(0,h.jsx)(i,{ref:n,className:f(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-elevation-3 duration-normal data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] rounded-(--panel-radius)`,e),...t})]}));b.displayName=i.displayName;var x=({className:e,...t})=>(0,h.jsx)(`div`,{className:f(`flex flex-col space-y-2 text-center sm:text-left`,e),...t});x.displayName=`AlertDialogHeader`;var S=({className:e,...t})=>(0,h.jsx)(`div`,{className:f(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t});S.displayName=`AlertDialogFooter`;var C=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(o,{ref:n,className:f(`text-lg font-semibold`,e),...t}));C.displayName=o.displayName;var w=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(c,{ref:n,className:f(`text-sm text-muted-foreground`,e),...t}));w.displayName=c.displayName;var T=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(l,{ref:n,className:f(p(),e),...t}));T.displayName=l.displayName;var E=m.forwardRef(({className:e,...t},n)=>(0,h.jsx)(a,{ref:n,className:f(p({variant:`outline`}),`mt-2 sm:mt-0`,e),...t}));E.displayName=a.displayName;export{w as a,C as c,b as i,_ as l,T as n,S as o,E as r,x as s,g as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,`status`)&&Object.prototype.hasOwnProperty.call(e,`payload`)}var t=`.workspace`;Object.freeze([`**/.*`,`**/.*/**`,`**/node_modules/**`,`**/__pycache__/**`,`**/bower_components/**`,`**/vendor/bundle/**`,`**/target/debug/**`,`**/target/release/**`,`**/*.swp`,`**/*.tmp`,`**/Cache/**`,`**/Caches/**`,`**/CachedData/**`]),Object.freeze([t,`${t}/**`]);function n(e){return String(e||``).replace(/^\/+/,``).split(`/`).map(encodeURIComponent).join(`/`)}function r(e){let t=String(e||`/`);return t.startsWith(`/`)?t:`/${t}`}var i={login:()=>`/auth/login`,logout:()=>`/auth/logout`,me:()=>`/auth/me`,status:()=>`/auth/status`,tokens:()=>`/auth/tokens`,token:e=>`/auth/tokens/${e}`,tokenRefresh:()=>`/auth/token/refresh`,devices:()=>`/auth/devices`,device:e=>`/auth/devices/${e}`,deviceRegister:()=>`/auth/devices/register`},a={collection:()=>`/workspaces`,byId:e=>`/workspaces/${e}`,start:e=>`/workspaces/${e}/start`,stop:e=>`/workspaces/${e}/stop`,status:e=>`/workspaces/${e}/status`,stats:e=>`/workspaces/${e}/stats`,tree:e=>`/workspaces/${e}/tree`,trees:e=>`/workspaces/${e}/trees`,treePath:(e,t,n)=>`/workspaces/${e}/trees/${encodeURIComponent(t)}/path${r(n)}`,pins:e=>`/workspaces/${e}/pins`,pin:(e,t)=>`/workspaces/${e}/pins/${encodeURIComponent(t)}`,pinsOrder:e=>`/workspaces/${e}/pins/order`,documents:e=>`/workspaces/${e}/documents`,documentsRemove:e=>`/workspaces/${e}/documents/remove`,treeByName:(e,t)=>`/workspaces/${e}/trees/${t}`,blobs:e=>`/workspaces/${e}/blobs`,dotfiles:e=>`/workspaces/${e}/dotfiles`,dotfilesStatus:e=>`/workspaces/${e}/dotfiles/status`,dotfilesInit:e=>`/workspaces/${e}/dotfiles/init`,backends:(e,t=null)=>`/workspaces/${e}/backends${t?`/${encodeURIComponent(t)}`:``}`,backend:(e,t,n)=>`/workspaces/${e}/backends/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,backendSync:(e,t,n)=>`${a.backend(e,t,n)}/sync`,backendUsage:(e,t,n)=>`${a.backend(e,t,n)}/usage`,backendDocuments:(e,t,n)=>`${a.backend(e,t,n)}/documents`,backendObjects:(e,t,n)=>`${a.backend(e,t,n)}/objects`,backendObject:(e,t,r,i)=>`${a.backend(e,t,r)}/objects/${n(i)}`,backendObjectRename:(e,t,n)=>`${a.backend(e,t,n)}/objects/rename`,backendChanges:(e,t,n)=>`${a.backend(e,t,n)}/changes`,mirrors:e=>`/workspaces/${e}/mirrors`,mirror:(e,t)=>`/workspaces/${e}/mirrors/${encodeURIComponent(t)}`,mirrorStatus:(e,t)=>`${a.mirror(e,t)}/status`,syncConflicts:e=>`/workspaces/${e}/sync/conflicts`,syncConflictResolve:(e,t)=>`/workspaces/${e}/sync/conflicts/${t}/resolve`,hooks:e=>`/workspaces/${e}/hooks`,hook:(e,t)=>`/workspaces/${e}/hooks/${t}`,hookRuns:e=>`/workspaces/${e}/hooks/runs`,hookReplay:(e,t)=>`/workspaces/${e}/hooks/runs/${t}/replay`,hooksExplain:e=>`/workspaces/${e}/hooks/explain`,hooksBackfill:e=>`/workspaces/${e}/hooks/backfill`},o={collection:()=>`/contexts`,byId:e=>`/contexts/${e}`,tree:e=>`/contexts/${e}/tree`,treePaths:e=>`/contexts/${e}/tree/paths`,documents:e=>`/contexts/${e}/documents`,document:(e,t)=>`/contexts/${e}/documents/${t}`,documentsRemove:e=>`/contexts/${e}/documents/remove`,blobs:e=>`/contexts/${e}/blobs`,dotfiles:e=>`/contexts/${e}/dotfiles`,url:e=>`/contexts/${e}/url`},s={collection:()=>`/agents`,byId:e=>`/agents/${e}`,status:e=>`/agents/${e}/status`,prompt:e=>`/agents/${e}/prompt`},c={collection:()=>`/roles`,byId:e=>`/roles/${e}`},l=()=>`/ping`,u=class extends Error{constructor(e,{code:t,statusCode:n,status:r,cause:i,retryable:a,reason:o,stoppedAt:s,hint:c}={}){super(e),this.name=`CanvasError`,this.code=t||`CANVAS_ERROR`,this.statusCode=n??r,this.status=r??n,i&&(this.cause=i),Object.assign(this,{retryable:a,reason:o,stoppedAt:s,hint:c})}},d=new Set([`ECONNREFUSED`,`ENOTFOUND`,`ETIMEDOUT`,`ECONNRESET`,`EAI_AGAIN`,`EPIPE`,`UND_ERR_CONNECT_TIMEOUT`,`UND_ERR_SOCKET`]),f=new Set([`ConnectionRefused`,`ConnectionClosed`,`FailedToOpenSocket`,`DNSException`,`Timeout`]);function p(e,t=new Set,n=0){if(!e||typeof e!=`object`||n>6)return t;if(typeof e.code==`string`&&t.add(e.code),Array.isArray(e.errors))for(let r of e.errors)p(r,t,n+1);return e.cause&&p(e.cause,t,n+1),t}function m(e){for(let t of p(e))if(d.has(t)||f.has(t))return!0;return!1}function h(t){if(!e(t))return t;if(t.status===`error`){let e=t.message||`Request failed`,n=typeof t.payload==`string`?t.payload.trim():``;throw new u(n&&!e.includes(n)?`${e}: ${n}`:e,{retryable:t.retryable,reason:t.reason,stoppedAt:t.stoppedAt,hint:t.hint,code:t.code,statusCode:t.statusCode,status:t.statusCode})}return t.payload}function g(e){let t=e[Symbol.asyncIterator]();return new ReadableStream({async pull(e){let{value:n,done:r}=await t.next();if(r){e.close();return}e.enqueue(typeof n==`string`?new TextEncoder().encode(n):n)},cancel(e){return t.return?t.return(e).then(()=>void 0):void 0}})}var _=e=>!!e&&typeof e==`object`&&typeof e.pipe==`function`&&typeof e[Symbol.asyncIterator]==`function`;function v(e){return e==null?{}:typeof e==`string`||typeof Blob<`u`&&e instanceof Blob||e instanceof ArrayBuffer||ArrayBuffer.isView(e)||typeof URLSearchParams<`u`&&e instanceof URLSearchParams?{body:e}:typeof ReadableStream<`u`&&e instanceof ReadableStream?{body:e,duplex:`half`}:_(e)?{body:g(e),duplex:`half`}:{body:JSON.stringify(e),isJson:!0}}function y(e){return{login:t=>e.post(i.login(),{strategy:`auto`,...t}),logout:()=>e.post(i.logout()),me:()=>e.get(i.me()),status:()=>e.get(i.status()),tokens:{list:()=>e.get(i.tokens()),create:t=>e.post(i.tokens(),t),delete:t=>e.delete(i.token(t)),update:(t,n)=>e.put(i.token(t),n)},devices:{register:t=>e.post(i.deviceRegister(),t),list:()=>e.get(i.devices()),update:(t,n)=>e.patch(i.device(t),n),remove:t=>e.delete(i.device(t))}}}var b=a;function x(e){return{list:()=>e.get(b.collection()),get:t=>e.get(b.byId(t)),create:t=>e.post(b.collection(),t),update:(t,n)=>e.put(b.byId(t),n),delete:t=>e.delete(b.byId(t)),start:(t,n={})=>e.post(b.start(t),n),stop:t=>e.post(b.stop(t)),status:t=>e.get(b.status(t)),stats:t=>e.get(b.stats(t)),tree:t=>e.get(b.tree(t)),trees:t=>e.get(b.trees(t)),removeTreePath:(t,n,r,{recursive:i=!1,purge:a=!1,destroy:o=!1}={})=>e.delete(b.treePath(t,n,r),{params:{recursive:i,...a?{purge:!0}:{},...o?{destroy:!0}:{}}}),documents:(t,n)=>e.get(b.documents(t),{params:n}),insertDocuments:(t,n)=>e.post(b.documents(t),n),uploadBlob:(t,n)=>e.request(`POST`,b.blobs(t),{data:n,headers:{"Content-Type":`application/octet-stream`}}),dotfiles:{list:(t,n)=>e.get(b.dotfiles(t),{params:n}),create:(t,n,r={})=>e.post(b.dotfiles(t),{dotfiles:Array.isArray(n)?n:[n],...r}),update:(t,n,r={})=>e.put(b.dotfiles(t),{documents:n,...r}),delete:(t,n)=>e.delete(b.dotfiles(t),{data:n}),status:t=>e.get(b.dotfilesStatus(t)),init:t=>e.post(b.dotfilesInit(t))},backends:{list:(t,n=null)=>e.get(b.backends(t,n)),get:(t,n,r)=>e.get(b.backend(t,n,r)),add:(t,n,r)=>e.post(b.backends(t,n),r),update:(t,n,r,i)=>e.patch(b.backend(t,n,r),i),remove:(t,n,r)=>e.delete(b.backend(t,n,r)),sync:(t,n,r)=>e.post(b.backendSync(t,n,r)),usage:(t,n,r)=>e.get(b.backendUsage(t,n,r)),documents:(t,n,r,i={})=>e.get(b.backendDocuments(t,n,r),{params:i}),objects:(t,n,r,i={})=>e.get(b.backendObjects(t,n,r),{params:i}),changes:(t,n,r,i={})=>e.get(b.backendChanges(t,n,r),{params:i}),putObject:(t,n,r,i,a,{headers:o={},params:s}={})=>e.request(`PUT`,b.backendObject(t,n,r,i),{data:a,...s?{params:s}:{},headers:{"Content-Type":`application/octet-stream`,...o}}),deleteObject:(t,n,r,i,{ifMatch:a,origin:o}={})=>e.delete(b.backendObject(t,n,r,i),{headers:{...a?{"If-Match":a}:{},...o?{"X-Canvas-Origin":o}:{}}}),renameObject:(t,n,r,i)=>e.post(b.backendObjectRename(t,n,r),i)},sync:{mirrors:t=>e.get(b.mirrors(t)),reportMirror:(t,n,r)=>e.post(b.mirrorStatus(t,n),r),forgetMirror:(t,n)=>e.delete(b.mirror(t,n)),conflicts:t=>e.get(b.syncConflicts(t)),resolveConflict:(t,n,r)=>e.post(b.syncConflictResolve(t,n),{keep:r})},hooks:{list:t=>e.get(b.hooks(t)),get:(t,n)=>e.get(b.hook(t,n)),set:(t,n,r)=>e.put(b.hook(t,n),{content:r}),delete:(t,n)=>e.delete(b.hook(t,n)),runs:(t,n={})=>e.get(b.hookRuns(t),{params:n}),explain:(t,n)=>e.post(b.hooksExplain(t),n),backfill:(t,n)=>e.post(b.hooksBackfill(t),n),replay:(t,n)=>e.post(b.hookReplay(t,n))}}}var S=o;function C(e){return{list:()=>e.get(S.collection()),get:t=>e.get(S.byId(t)),create:t=>e.post(S.collection(),t),update:(t,n)=>e.put(S.byId(t),n),delete:t=>e.delete(S.byId(t)),tree:t=>e.get(S.tree(t)),documents:(t,n)=>e.get(S.documents(t),{params:n}),insertDocuments:(t,n)=>e.post(S.documents(t),n),uploadBlob:(t,n)=>e.request(`POST`,S.blobs(t),{data:n,headers:{"Content-Type":`application/octet-stream`}}),dotfiles:t=>e.get(S.dotfiles(t)),url:t=>e.get(S.url(t)),setUrl:(t,n)=>e.post(S.url(t),{url:n})}}function w(e){return{list:()=>e.get(s.collection()),get:t=>e.get(s.byId(t)),status:t=>e.get(s.status(t)),prompt:(t,n)=>e.post(s.prompt(t),n)}}function ee(e){return{list:()=>e.get(c.collection()),get:t=>e.get(c.byId(t))}}function te(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e||{}))if(r!=null){if(Array.isArray(r))for(let e of r)e!=null&&t.append(n,String(e));else t.append(n,String(r))}return t}function ne(e){let t=null,n=e;for(let e=0;n&&typeof n==`object`&&e<6;e++){if(typeof n.code==`string`&&(t=n),Array.isArray(n.errors)&&n.errors.length){let e=n.errors.find(e=>e&&typeof e.code==`string`);e&&(t=e)}n=n.cause}return t}var T=class{constructor({baseUrl:e,apiBase:t=`/rest/v2`,getToken:n,token:r,timeout:i=3e4,userAgent:a,appName:o,headers:s={},unwrap:c=!0,fetch:l}={}){if(!e)throw new u(`baseUrl is required`);this.baseUrl=String(e).replace(/\/$/,``),this.apiBase=t,this.getToken=n||(()=>r||null),this.timeout=i,this.userAgent=a,this.appName=o,this.defaultHeaders=s,this.unwrapEnvelopes=c,this._fetch=l||((...e)=>globalThis.fetch(...e)),this.auth=y(this),this.workspaces=x(this),this.contexts=C(this),this.agents=w(this),this.roles=ee(this)}async request(t,n,{params:r,data:i,headers:a,timeout:o,signal:s}={}){let c=new URL(this.baseUrl+this.apiBase+n),l=te(r);for(let[e,t]of l)c.searchParams.append(e,t);let{body:d,duplex:f,isJson:p}=v(i),m={...this.defaultHeaders,...a||{}},g=e=>Object.keys(m).some(t=>t.toLowerCase()===e);p&&!g(`content-type`)&&(m[`Content-Type`]=`application/json`),this.userAgent&&!g(`user-agent`)&&(m[`User-Agent`]=this.userAgent),this.appName&&!g(`x-app-name`)&&(m[`X-App-Name`]=this.appName);let _=this.getToken();_&&!g(`authorization`)&&(m.Authorization=`Bearer ${_}`);let y=o??this.timeout,b=[];y&&b.push(AbortSignal.timeout(y)),s&&b.push(s);let x=b.length>1?AbortSignal.any(b):b[0],S;try{S=await this._fetch(c,{method:t,headers:m,...d===void 0?{}:{body:d},...f?{duplex:f}:{},...x?{signal:x}:{}})}catch(e){if(e?.name===`TimeoutError`||e?.cause?.name===`TimeoutError`)throw new u(`Request timed out after ${y}ms`,{code:`TIMEOUT`,cause:e});if(e?.name===`AbortError`)throw new u(`Request aborted`,{code:`ABORTED`,cause:e});let t=ne(e)||e.cause||e;throw new u(t?.message||e.message||`Request failed`,{cause:t})}let C=await this._parseBody(S);if(e(C))return C.status===`error`||this.unwrapEnvelopes?h(C):C;if(S.ok)return C;throw new u(C&&typeof C==`object`&&C.message||(typeof C==`string`&&C.trim()?C.trim().slice(0,200):``)||`HTTP ${S.status}${S.statusText?` ${S.statusText}`:``}`,{statusCode:S.status,status:S.status})}async _parseBody(e){if(e.status===204)return null;let t=e.headers.get(`content-type`)||``,n=await e.text();if(!n)return null;if(t.includes(`application/json`))try{return JSON.parse(n)}catch(t){throw new u(`Invalid JSON in response`,{statusCode:e.status,status:e.status,cause:t})}return n}get(e,t){return this.request(`GET`,e,t)}post(e,t,n){return this.request(`POST`,e,{...n,data:t??{}})}put(e,t,n){return this.request(`PUT`,e,{...n,data:t??{}})}patch(e,t,n){return this.request(`PATCH`,e,{...n,data:t??{}})}delete(e,t){return this.request(`DELETE`,e,t)}ping(){return this.get(l())}};function E(){return`${window.location.origin}/rest/v2`}var D=E(),O=D.split(`/rest`)[0],k={login:`${D}/auth/login`,register:`${D}/auth/register`,logout:`${D}/auth/logout`,me:`${D}/auth/me`,authConfig:`${D}/auth/config`,verifyEmailRequest:`${D}/auth/verify-email`,tokens:`${D}/auth/tokens`,users:`${D}/users`,currentUser:`${D}/auth/me`,workspaces:`${D}/workspaces`,contexts:`${D}/contexts`,inferd:`${D}/inferd`,admin:{users:`${D}/admin/users`,workspaces:`${D}/admin/workspaces`,logs:`${D}/admin/logs`,logsStream:`${D}/admin/logs/stream`,inferd:`${D}/admin/inferd`,authConfig:`${D}/admin/auth-config`},roles:`${D}/roles`,roleTemplates:`${D}/role-templates`,devices:`${D}/auth/devices`,ws:O},A=null;function j(e){A=e}function M(e,t){e.message.includes(`socket.io`)||e.message.includes(`websocket`)||(console.error(`API Error:`,e,t),A&&A(e,t))}function N(e,t){return!e.statusCode&&e.code!==`ABORTED`&&e.code!==`TIMEOUT`&&(t||/fetch failed|failed to fetch|networkerror|load failed/i.test(e.message))}var P=typeof navigator<`u`&&navigator.onLine===!1,F=new Set;function I(e){if(P!==e){P=e;for(let e of F)e(P)}}function L(){return P}function R(){I(!0)}function z(){I(!1)}var B=/Network error:/i;function V(e){return e!=null&&B.test(e)}function H(e){return F.add(e),()=>{F.delete(e)}}typeof window<`u`&&window.addEventListener(`offline`,()=>I(!0));var U=!1;function W(){let e=localStorage.getItem(`appName`);return e||(e=window.location.hostname,localStorage.setItem(`appName`,e)),e}function G(e){e&&localStorage.removeItem(`authToken`),U=!0,window.location.pathname.includes(`/login`)||(window.location.href=`/login`)}function K(){return localStorage.getItem(`authToken`)}function q(e){return e?e.startsWith(`canvas-`)&&e.length>10?!0:/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/.test(e):!1}function J(e,t){if(U&&!e&&!t)throw Error(`Authentication required`);if(e)return;let n=K();if(!n)throw console.warn(`Attempting authenticated request without token`),t||G(!1),Error(`Authentication required`);if(!q(n))throw console.warn(`Invalid token format detected, clearing`),t||G(!0),Error(`Invalid authentication token format`)}function Y(e){throw!e&&!U&&(console.error(`Authentication failed, redirecting to login`),G(!0)),Error(`Authentication required`)}function X(e){if(e.startsWith(D))return e.slice(D.length);if(e.startsWith(`http`))throw Error(`api.* endpoints must live under API_URL (${D}); got ${e}`);return e}var re=(e,t={})=>fetch(e,{...t,credentials:`include`}).then(e=>(e.headers.get(`x-canvas-offline`)===`fallback`?R():z(),e),e=>{throw!t.signal?.aborted&&!(e instanceof Error&&e.name===`AbortError`)&&R(),e});function Z(e,t){return new T({baseUrl:D,apiBase:``,getToken:e?K:()=>null,appName:W(),timeout:0,unwrap:!t,fetch:re})}var Q={authed:Z(!0,!1),anon:Z(!1,!1),authedEnvelope:Z(!0,!0),anonEnvelope:Z(!1,!0)};function ie(e,t){return t?e?Q.anonEnvelope:Q.authedEnvelope:e?Q.anon:Q.authed}async function $(e,t,n,r={}){let{skipAuth:i=!1,noAuthRedirect:a=!1,envelope:o=!1,headers:s,signal:c,body:l}=r;J(i,a);let d=ie(i,o);try{let r=await d.request(e,X(t),{data:n===void 0?l??void 0:n,headers:s,signal:c??void 0});return U=!1,r===null?void 0:r}catch(n){if(n instanceof u){if(n.code===`WORKSPACE_STOPPED`){let e=t.match(/\/workspaces\/([^/?#]+)/)?.[1];throw e&&window.dispatchEvent(new CustomEvent(`workspace:stopped`,{detail:{refs:[decodeURIComponent(e)]}})),n}if(n.code===`ABORTED`)throw new DOMException(`Request aborted`,`AbortError`);if(n.statusCode===401&&!i&&Y(a),N(n,m(n)))throw Error(`Network error: server unreachable. Check your connection and try again.`)}throw console.error(`API Error: ${t}`,n),n instanceof Error&&M(n,`${e} ${t}`),n}}var ae={async get(e,t={}){return $(`GET`,e,void 0,t)},async post(e,t,n={}){return $(`POST`,e,t,n)},async put(e,t,n={}){return $(`PUT`,e,t,n)},async patch(e,t,n={}){return $(`PATCH`,e,t,n)},async delete(e,t={}){return $(`DELETE`,e,void 0,t)},async getEnvelope(e,t={}){return $(`GET`,e,void 0,{...t,envelope:!0})},async postEnvelope(e,t,n={}){return $(`POST`,e,t,{...n,envelope:!0})},setAuthToken(e){if(!e){console.warn(`Attempted to set empty auth token`);return}if(!q(e)){console.error(`Attempted to set invalid token format:`,e.substring(0,10)+`...`);return}localStorage.setItem(`authToken`,e),console.log(`Auth token set successfully`),U=!1},clearAuthToken(){localStorage.removeItem(`authToken`),console.log(`Auth token cleared`)},isAuthenticated(){let e=K();return!!e&&q(e)},async stream(e,t,n={}){let{onOpen:r,onChunk:i,onError:a,onComplete:o,signal:s}=n;try{J(!1,!1);let n=K(),a,c={"X-App-Name":W(),...n?{Authorization:`Bearer ${n}`}:{}};t!==void 0&&(typeof t==`object`&&t&&!(t instanceof FormData)&&!(t instanceof URLSearchParams)&&!(t instanceof Blob)?(a=JSON.stringify(t),c[`Content-Type`]=`application/json`):a=t);let l=e.startsWith(`http`)?e:`${D}${e}`,u=await fetch(l,{method:`POST`,credentials:`include`,headers:c,body:a,signal:s});if(!u.ok){u.status===401&&Y(!1);let e=null;try{e=await u.json()}catch{}let t=e?.message||e?.error||u.statusText||`Request failed`;throw Error(`HTTP ${u.status}: ${t}`)}if(U=!1,r?.(),!u.body)throw Error(`Response body is null - streaming not supported`);if(typeof u.body.getReader!=`function`){console.warn(`ReadableStream.getReader not available, falling back to text response`);let e=await u.text();i&&i(e),o&&o();return}let d=u.body.getReader(),f=new TextDecoder;try{for(;;){if(s?.aborted)throw d.cancel(),Error(`Stream aborted`);let{done:e,value:t}=await d.read();if(e){o&&o();break}let n=f.decode(t,{stream:!0});n&&i&&i(n)}}finally{d.releaseLock()}}catch(e){throw console.error(`Streaming error:`,e),a&&a(e instanceof Error?e:Error(String(e))),e}}};export{R as a,k as c,H as i,D as l,V as n,z as o,L as r,j as s,ae as t,O as u};
|
|
@@ -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{Cr as r,Hr as i,Mt as a,Y as o}from"./ui-BSqPn1LJ.js";import{t as s}from"./button-Bv4zA1qr.js";import{t as c}from"./input-BOtCd4HP.js";import{c as l,t as u}from"./api-CA6WiiYM.js";import{n as d}from"./use-toast-BlLDqSUO.js";import{n as f}from"./page-header-GtTr9Ff_.js";import{t as p}from"./use-settings-back-Dk-DJEUO.js";var m=e(n(),1),h=t();function g(){let[e,t]=(0,m.useState)([]),[n,g]=(0,m.useState)(!0),[_,v]=(0,m.useState)(null),[y,b]=(0,m.useState)(``),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(``),[T,E]=(0,m.useState)(!1),{showToast:D}=d(),O=(0,m.useRef)(null),k=(0,m.useCallback)(async()=>{try{g(!0);let e=await u.get(l.tokens),n=Array.isArray(e)?e:e.tokens||[];t(n),v(null)}catch(e){let t=e instanceof Error?e.message:`Failed to fetch tokens`;v(t),D({title:`Error`,description:t,variant:`destructive`})}finally{g(!1)}},[D]);(0,m.useEffect)(()=>{k()},[k]);let A=async()=>{if(!(!y.trim()||x)){S(!0);try{let e=await u.post(l.tokens,{name:y});b(``),await k(),e&&e.token&&(w(e.token),setTimeout(()=>{if(O.current){O.current.focus();let e=document.createRange();e.selectNodeContents(O.current);let t=window.getSelection();t&&(t.removeAllRanges(),t.addRange(e))}},100)),D({title:`Success`,description:`Token generated successfully`,variant:`default`})}catch(e){let t=e instanceof Error?e.message:`Failed to generate token`;v(t),D({title:`Error`,description:t,variant:`destructive`})}finally{S(!1)}}},j=async e=>{if(confirm(`Are you sure you want to revoke this API token? This action cannot be undone.`))try{await u.delete(`${l.tokens}/${e}`),await k(),D({title:`Success`,description:`API token revoked successfully`})}catch(e){let t=e instanceof Error?e.message:`Failed to revoke API token`;D({title:`Error`,description:t,variant:`destructive`})}},M=async e=>{try{await navigator.clipboard.writeText(e),E(!0),D({title:`Success`,description:`Token copied to clipboard`}),setTimeout(()=>E(!1),2e3)}catch{D({title:`Error`,description:`Failed to copy token to clipboard`,variant:`destructive`})}};return(0,h.jsxs)(`div`,{className:`space-y-6`,children:[(0,h.jsx)(f,{title:`API Tokens`,onBack:p(),description:`Create and manage API tokens for programmatic access`}),(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Generate New API Token`}),(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(c,{value:y,onChange:e=>b(e.target.value),placeholder:`Token Name (e.g., 'CLI Access', 'Automation')`,disabled:x,className:`flex-1`}),(0,h.jsxs)(s,{type:`button`,disabled:x||!y.trim(),onClick:A,children:[(0,h.jsx)(a,{className:`mr-2 h-4 w-4`}),x?`Generating...`:`Generate`]})]}),C&&(0,h.jsxs)(`div`,{className:`p-4 border rounded-md bg-muted/50`,children:[(0,h.jsxs)(`div`,{className:`flex justify-between items-center mb-2`,children:[(0,h.jsx)(`h3`,{className:`font-semibold`,children:`Your New API Token`}),(0,h.jsx)(s,{variant:`outline`,size:`sm`,onClick:()=>M(C),children:T?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(i,{className:`mr-2 h-4 w-4`}),`Copied`]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(r,{className:`mr-2 h-4 w-4`}),`Copy`]})})]}),(0,h.jsx)(`p`,{className:`text-sm text-muted-foreground mb-2`,children:`Make sure to copy your API token now. You won't be able to see it again!`}),(0,h.jsx)(`div`,{ref:O,tabIndex:0,className:`p-2 bg-background border rounded font-mono text-sm break-all outline-none focus:ring-2 focus:ring-ring`,children:C})]})]}),(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your API Tokens`}),n&&(0,h.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading API tokens...`}),_&&(0,h.jsx)(`div`,{className:`text-center text-destructive`,children:(0,h.jsx)(`p`,{children:_})}),!n&&!_&&e.length===0&&(0,h.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No API tokens found`}),e.length>0&&(0,h.jsx)(`div`,{className:`border rounded-md`,children:(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`w-full`,children:[(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{className:`bg-muted/50`,children:[(0,h.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Name`}),(0,h.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Created`}),(0,h.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Last Used`}),(0,h.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`Expires`}),(0,h.jsx)(`th`,{className:`text-right p-3 font-medium`,children:`Actions`})]})}),(0,h.jsx)(`tbody`,{children:e.map(e=>(0,h.jsxs)(`tr`,{className:`border-t`,children:[(0,h.jsx)(`td`,{className:`p-3 font-medium`,children:e.name}),(0,h.jsx)(`td`,{className:`p-3`,children:new Date(e.createdAt).toLocaleDateString()}),(0,h.jsx)(`td`,{className:`p-3`,children:e.lastUsedAt?new Date(e.lastUsedAt).toLocaleDateString():`Never`}),(0,h.jsx)(`td`,{className:`p-3`,children:e.expiresAt?new Date(e.expiresAt).toLocaleDateString():`Never`}),(0,h.jsx)(`td`,{className:`p-3 text-right`,children:(0,h.jsx)(s,{variant:`outline`,size:`sm`,onClick:()=>j(e.id),className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,children:(0,h.jsx)(o,{className:`h-4 w-4`})})})]},e.id))})]})})})]})]})}export{g as default};
|
|
@@ -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{Hr as r,Jt as i,et as a,qt as o}from"./ui-BSqPn1LJ.js";import{t as s}from"./utils-2pl1SbIp.js";import{a as c,i as l,n as u,o as d,r as f,s as p,t as m}from"./document-open-mode-DoImW-xs.js";import{d as h,f as g,l as _,o as v,s as y,u as b}from"./use-menu-BVkqNEIx.js";import{t as x}from"./use-theme-DaxpiICf.js";import{_t as S,a as C,c as w,d as T,f as E,i as D,l as O,m as k,n as A,o as j,p as M,r as N,s as P,t as F,u as I,vt as L,yt as R}from"./index-exXolIqD.js";import{n as z}from"./page-header-GtTr9Ff_.js";import{t as B}from"./use-settings-back-Dk-DJEUO.js";var V=e(n(),1),H=t(),U={system:i,light:a,dark:o};function W(){let{theme:e,scheme:t,density:n,resolvedScheme:i,setTheme:a,setScheme:o,setDensity:C,reset:w}=x(),T=l(),D=u(),O=h(),A=p(),j=R(),N=g();return(0,H.jsxs)(`div`,{className:`space-y-8`,children:[(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Theme`,description:`Palette, shape and typography. Each theme defines its own light and dark variants.`}),(0,H.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:k.map(t=>{let n=t.id===e;return(0,H.jsxs)(`button`,{type:`button`,onClick:()=>a(t.id),"aria-pressed":n,className:s(`focus-ring group flex flex-col gap-3 rounded-lg border p-4 text-left transition-colors`,n?`border-primary bg-accent`:`border-border hover:border-muted-foreground/40 hover:bg-accent/50`),children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium`,children:t.name}),n&&(0,H.jsx)(r,{className:`size-4 shrink-0 text-primary`})]}),(0,H.jsx)(`div`,{className:`flex gap-1.5`,"aria-hidden":!0,children:t.swatches.map(e=>(0,H.jsx)(`span`,{className:`size-6 rounded-full border border-border`,style:{backgroundColor:e}},e))}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t.description})]},t.id)})})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Colour scheme`,description:t===`system`?`Following your system setting, currently ${i}.`:`Overrides your system setting.`}),(0,H.jsx)(Y,{options:M.map(e=>{let t=U[e.id];return{id:e.id,label:e.name,icon:(0,H.jsx)(t,{className:`size-4 shrink-0`})}}),value:t,onChange:o})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Density`,description:`Controls row height, hit-target size and shell spacing across the whole app.`}),(0,H.jsx)(Y,{options:E.map(e=>({id:e.id,label:e.name,title:e.description})),value:n,onChange:C}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:E.find(e=>e.id===n)?.description})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Layout`,description:`How menus and content share the screen. Device-local, like the wallpaper.`}),(0,H.jsx)(Y,{options:y.map(e=>({id:e.id,label:e.name,title:e.description})),value:O,onChange:_}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:y.find(e=>e.id===O)?.description}),O===`strip`&&(0,H.jsxs)(`div`,{className:`mt-4`,children:[(0,H.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:`Navigation keys`}),(0,H.jsx)(Y,{options:v.map(e=>({id:e.id,label:e.name,title:e.description})),value:N,onChange:b}),(0,H.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[v.find(e=>e.id===N)?.description,` `,`Left and right walk the columns, up and down switch pin rows.`]})]})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Tree style`,description:`How workspace and context trees are drawn in the menu. Device-local.`}),(0,H.jsx)(Y,{options:S.map(e=>({id:e.id,label:e.name,title:e.description})),value:j,onChange:L}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:S.find(e=>e.id===j)?.description})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Open documents`,description:`Choose how documents open from lists, tiles and boards. Saved on this device.`}),(0,H.jsx)(Y,{options:[{id:`modal`,label:`Modal`},{id:`side`,label:`Side reading pane`}],value:D,onChange:m}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`The reading pane opens beside the content and updates as you select another document. On small screens it opens as a drawer.`})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Always-on content area`,description:`Keep a reading pane beside document lists on tablets and desktops. Remember the selected item in each folder, or show the first available item.`}),(0,H.jsx)(Y,{options:[{id:`on`,label:`On`},{id:`off`,label:`Off`}],value:T?`on`:`off`,onChange:e=>f(e===`on`)}),(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`On by default. The reader uses roughly half the screen; drag its divider to resize. Phones keep tap-to-open navigation. When enabled, list selections use this pane regardless of the Open documents setting.`})]}),(0,H.jsxs)(`section`,{children:[(0,H.jsx)(J,{title:`Document tiles`,description:`Choose the photo and media layout for tile view. Saved on this device.`}),(0,H.jsx)(Y,{options:c,value:A,onChange:d})]}),(0,H.jsx)(G,{}),(0,H.jsx)(`section`,{children:(0,H.jsx)(`button`,{type:`button`,onClick:()=>{w(),m(`modal`)},className:`focus-ring rounded-md text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline`,children:`Reset to defaults`})})]})}function G(){let[e,t]=(0,V.useState)(j),[n,r]=(0,V.useState)(null),[i,a]=(0,V.useState)(!0),[o,s]=(0,V.useState)(!1),c=(0,V.useRef)(!1);(0,V.useEffect)(()=>{let e=!1;return w().then(()=>{e||(t(j()),a(!1))}),()=>{e=!0}},[]);let l=async(e,n)=>{if(!c.current){c.current=!0,s(!0);try{let i=n?{...e,image:await P(n)}:e;await O(i),t(i),r(null)}catch(e){r(e instanceof Error&&e.name!==`QuotaExceededError`?e.message:`Could not store the wallpaper. Free some browser storage or try a smaller image.`)}finally{c.current=!1,s(!1)}}},u=t=>{t&&l(e,t)},d=e.image!==null&&N(e.image)===null,f=I(e.image);return(0,H.jsx)(`section`,{children:(0,H.jsxs)(`fieldset`,{disabled:i||o,className:`min-w-0`,children:[(0,H.jsx)(J,{title:`Wallpaper`,description:`Background image for the desk behind all panels. Without one, the theme's desk color shows (the default).`}),(0,H.jsxs)(`div`,{role:`radiogroup`,"aria-label":`Wallpaper`,className:`grid grid-cols-3 gap-3 sm:grid-cols-4 lg:grid-cols-6`,children:[(0,H.jsx)(q,{label:`None`,isActive:e.image===null,onSelect:()=>l({...e,image:null}),children:(0,H.jsx)(`span`,{className:`flex size-full items-center justify-center surface-desk text-xs text-muted-foreground`,style:{backgroundImage:`none`},children:`None`})}),F.map(t=>(0,H.jsx)(q,{label:t.title,title:`${t.title} — suits the ${t.scheme} scheme`,isActive:N(e.image)===t.id,onSelect:()=>l({...e,image:D(t.id)}),children:(0,H.jsx)(`img`,{src:C(t),alt:``,loading:`lazy`,className:`size-full object-cover`,style:{backgroundColor:t.background}})},t.id)),d&&(0,H.jsx)(q,{label:`Your image`,isActive:!0,onSelect:()=>{},children:(0,H.jsx)(`img`,{src:e.image??void 0,alt:``,className:`size-full object-cover`})})]}),(0,H.jsx)(K,{}),(0,H.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,H.jsx)(`div`,{className:`h-20 w-32 shrink-0 rounded-md border surface-desk`,style:f?{backgroundImage:f,backgroundSize:T(e.fit),backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,"aria-hidden":!0}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsxs)(`label`,{className:`focus-ring inline-flex cursor-pointer items-center rounded-md border px-3 py-1.5 text-sm hover:bg-accent/50`,children:[d?`Change image…`:`Use your own image…`,(0,H.jsx)(`input`,{type:`file`,accept:`image/*,.gif`,className:`hidden`,onChange:e=>{u(e.target.files?.[0]),e.target.value=``}})]}),e.image&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>l({...e,image:null}),className:`focus-ring rounded-md border px-3 py-1.5 text-sm text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:`Remove`})]}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Images and animated GIFs up to 10 MB. Stored on this device.`}),(0,H.jsx)(Y,{options:A.map(e=>({id:e.id,label:e.label,title:e.description})),value:e.fit,onChange:t=>l({...e,fit:t})}),n&&(0,H.jsx)(`p`,{className:`text-xs text-destructive`,children:n}),o&&(0,H.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:`Saving wallpaper…`})]})]})]})})}function K(){let e=F.filter(e=>e.author!==`Canvas`);return e.length===0?null:(0,H.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:e.map((e,t)=>(0,H.jsxs)(`span`,{children:[t>0&&` · `,e.title,` © `,e.author,e.source&&(0,H.jsxs)(H.Fragment,{children:[` `,(0,H.jsx)(`a`,{href:e.source,target:`_blank`,rel:`noreferrer noopener`,className:`focus-ring underline underline-offset-2 hover:text-foreground`,children:new URL(e.source).hostname})]})]},e.id))})}function q({label:e,title:t,isActive:n,onSelect:i,children:a}){return(0,H.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,"aria-label":e,title:t??e,onClick:i,className:s(`focus-ring group relative aspect-video overflow-hidden rounded-md border transition-colors`,n?`border-primary ring-1 ring-primary`:`border-border hover:border-muted-foreground/40`),children:[a,n&&(0,H.jsx)(`span`,{className:`absolute right-1 top-1 rounded-full bg-primary p-0.5 text-primary-foreground`,children:(0,H.jsx)(r,{className:`size-3`})})]})}function J({title:e,description:t}){return(0,H.jsxs)(`div`,{className:`mb-3`,children:[(0,H.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t})]})}function Y({options:e,value:t,onChange:n}){return(0,H.jsx)(`div`,{role:`radiogroup`,className:`inline-flex flex-wrap gap-1 rounded-lg bg-muted p-1`,children:e.map(e=>{let r=e.id===t;return(0,H.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":r,title:e.title,onClick:()=>n(e.id),className:s(`focus-ring flex h-control items-center gap-2 rounded-md px-3 text-sm transition-colors`,r?`bg-card text-foreground shadow-elevation-1`:`text-muted-foreground hover:text-foreground`),children:[e.icon,e.label]},e.id)})})}function X(){return(0,H.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,H.jsx)(z,{className:`mb-6`,title:`Appearance`,onBack:B(),description:`Theme, colour scheme and density. Changes apply immediately and are remembered on this device.`}),(0,H.jsx)(W,{})]})}export{X as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{l as e}from"./code-editor-BOIngd5F.js";import{t}from"./use-applet-target-mkjQujx6.js";var n=e();function r({target:e,children:r}){return(0,n.jsx)(t.Provider,{value:e,children:r})}export{r as t};
|
|
@@ -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{_ as r,r as i,v as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./utils-2pl1SbIp.js";import{Pt as s}from"./workspace-CJ1PWQ29.js";import{p as c}from"./context-D_K4g9SQ.js";import{t as l}from"./registry-6tE_1KPV.js";import{t as u}from"./applet-target-DnTa2VAT.js";var d=e(n(),1),f=t(),p=`universe`;function m(){let{appletId:e}=r(),[t,n]=a(),m=l.find(t=>t.id===e),h=t.get(`context`),g=t.get(`workspace`)||p,_=t.get(`path`)||`/`,v=t.get(`tree`)||`context`,y=t.get(`add`)===`1`,b=(0,d.useMemo)(()=>h?{mode:`context`,contextId:h}:{mode:`workspace`,workspaceName:g,path:_,treeName:v,treeType:v===`directory`?`directory`:`context`},[h,g,_,v]),[x,S]=(0,d.useState)([]),[C,w]=(0,d.useState)([]);(0,d.useEffect)(()=>{s().then(S).catch(()=>S([])),c().then(w).catch(()=>w([]))},[]);let[T,E]=(0,d.useState)(_),[D,O]=(0,d.useState)(_);D!==_&&(O(_),E(_));let k=e=>{let r=new URLSearchParams(t);r.delete(`add`);for(let[t,n]of Object.entries(e))n===null?r.delete(t):r.set(t,n);n(r,{replace:!0})};if(!m)return(0,f.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col items-center justify-center gap-3 surface-desk`,children:[(0,f.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Unknown app`,e?` "${e}"`:``,`.`]}),(0,f.jsx)(`div`,{className:`flex gap-2`,children:l.map(e=>(0,f.jsx)(i,{to:`/apps/${e.id}`,className:`rounded-md border border-border px-3 py-1.5 text-sm hover:bg-muted`,children:e.label},e.id))})]});let A=h?`context`:`path`;return(0,f.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col surface-desk p-shell gap-shell`,children:[(0,f.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 rounded-xl border bg-card px-3 py-2 shadow-elevation-2`,children:[(0,f.jsx)(m.icon,{className:`h-4 w-4 text-muted-foreground`}),(0,f.jsx)(`span`,{className:`text-sm font-semibold`,children:m.label}),(0,f.jsx)(`div`,{className:`ml-2 flex overflow-hidden rounded-md border border-border`,children:[`path`,`context`].map(e=>(0,f.jsx)(`button`,{type:`button`,onClick:()=>{e!==A&&k(e===`path`?{context:null}:{context:C[0]?.id??``,workspace:null,path:null,tree:null})},className:o(`px-2.5 py-1 text-xs capitalize transition-colors`,A===e?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e},e))}),A===`path`?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`select`,{value:g,onChange:e=>k({workspace:e.target.value,path:`/`}),className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Workspace`,children:[!x.some(e=>e.name===g)&&(0,f.jsx)(`option`,{value:g,children:g}),x.map(e=>(0,f.jsx)(`option`,{value:e.name,children:e.label||e.name},e.id))]}),(0,f.jsx)(`input`,{value:T,onChange:e=>E(e.target.value),onBlur:()=>{let e=T.trim()||`/`;e!==_&&k({path:e})},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},spellCheck:!1,placeholder:`/`,className:`h-7 w-40 rounded-md border border-input bg-transparent px-2 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`,"aria-label":`Path`})]}):(0,f.jsxs)(`select`,{value:h??``,onChange:e=>k({context:e.target.value}),className:`h-7 max-w-56 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Context`,children:[!h&&(0,f.jsx)(`option`,{value:``,children:`Pick a context…`}),C.map(e=>(0,f.jsxs)(`option`,{value:e.id,children:[e.id,e.url?` (${e.url})`:``]},e.id))]}),(0,f.jsx)(`div`,{className:`grow`})]}),(0,f.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border bg-card shadow-elevation-2`,children:A===`context`&&!h?(0,f.jsxs)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:[`Pick a context above to bind `,m.label,` to it.`]}):(0,f.jsx)(u,{target:b,children:(0,f.jsx)(m.Component,{autoAdd:y},JSON.stringify(b))})})]})}export{m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./utils-BxVxyehK.js";import{c as t,l as n,t as r}from"./api-CA6WiiYM.js";import{t as i}from"./socket-CtH3EU9m.js";async function a(e,n,a=`auto`){try{let o=await r.post(t.login,{email:e,password:n,strategy:a},{skipAuth:!0});console.log(`Login response:`,o);let s=o;if(`token`in s)return console.log(`Setting auth token (direct):`,s.token.substring(0,10)+`...`),r.setAuthToken(s.token),i.connect(s.token),o;if(s&&`payload`in s&&s.payload&&s.payload.token)return console.log(`Setting auth token (nested):`,s.payload.token.substring(0,10)+`...`),r.setAuthToken(s.payload.token),i.connect(s.payload.token),o;throw console.error(`Invalid login response structure:`,o),Error(`Invalid login response: missing token`)}catch(e){throw console.error(`Login error:`,e),r.clearAuthToken(),e}}async function o(e,n,i){try{return await r.post(t.register,{name:e,email:n,password:i},{skipAuth:!0})}catch(e){throw console.error(`Registration failed:`,e),e}}function s(e){return e instanceof Error&&/^Network error/i.test(e.message)}function c(){let t=localStorage.getItem(`authToken`);if(!t)return!1;if(t.startsWith(`canvas-`))return!0;try{return e(t).exp*1e3>Date.now()}catch{return!1}}function l(){let t=localStorage.getItem(`authToken`);if(!t||t.startsWith(`canvas-`))return null;try{let n=e(t);return n.exp*1e3<Date.now()?(r.clearAuthToken(),null):{id:n.sub,email:n.email,userType:n.userType||`user`}}catch(e){return console.error(`Failed to decode token:`,e),r.clearAuthToken(),null}}async function u(){try{if(!r.isAuthenticated())return console.log(`Not authenticated, skipping getCurrentUser request`),null;let e=await r.get(t.me);return console.log(`Current user response:`,e),e&&e?(i.isConnected()||i.reconnect(),e):(console.warn(`Invalid user profile response structure:`,e),null)}catch(e){if(console.error(`Failed to get current user:`,e),s(e))throw e;return e instanceof Error&&(e.message.includes(`USER_NOT_FOUND_IN_DATABASE`)||e.message.includes(`Your session is invalid`)||e.message.includes(`Authentication required`)||e.message.includes(`user account no longer exists`))?(console.warn(`Authentication error detected, clearing token:`,e.message),r.clearAuthToken(),i.disconnect(),null):null}}function d(){return r.isAuthenticated()}function f(){let e=new URL(`${n}/oauth/google/login`);e.searchParams.set(`origin`,window.location.origin),window.location.assign(e.toString())}async function p(e){let t=await r.post(`${n}/oauth/google/exchange`,{code:e},{skipAuth:!0});if(!t?.token)throw Error(`Invalid login response: missing token`);r.setAuthToken(t.token),i.connect(t.token)}async function m(){try{let e=await r.get(t.authConfig,{skipAuth:!0});return e||e}catch(e){return console.error(`Failed to get auth config:`,e),{strategies:{local:{enabled:!0},imap:{enabled:!1,domains:[]}}}}}async function h(e){try{await r.post(t.verifyEmailRequest,{email:e},{skipAuth:!0})}catch(e){throw console.error(`Failed to request email verification:`,e),e}}export{c as a,a as c,f as d,l as i,o as l,m as n,d as o,u as r,s,p as t,h as u};
|
|
@@ -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{Ar as r,Mt as i,Nr as a,Ot as o,X as s,dn as c,pt as l}from"./ui-BSqPn1LJ.js";import{t as u}from"./utils-2pl1SbIp.js";import{t as d}from"./button-Bv4zA1qr.js";import{t as f}from"./input-BOtCd4HP.js";import{c as p,l as m,t as h}from"./api-CA6WiiYM.js";import{i as g}from"./auth-Bx9fAZmz.js";import{n as _}from"./use-toast-BlLDqSUO.js";import{n as v}from"./page-header-GtTr9Ff_.js";import{t as y}from"./use-settings-back-Dk-DJEUO.js";var b=e(n(),1);function x(){return h.get(p.admin.authConfig)}function S(e){return h.put(p.admin.authConfig,e)}function C(e,t,n){return h.post(`${p.admin.authConfig}/test`,{strategy:`ldap`,name:e,server:t,email:n})}function w(e,t,n){return h.post(`${p.admin.authConfig}/test`,{strategy:`imap`,domain:e,email:t,password:n})}var T=t(),E=0,D=()=>`row-${++E}`;function O(e){let{servers:t,...n}=e.strategies.ldap,{domains:r,...i}=e.strategies.imap;return{allowUserRegistrations:e.allowUserRegistrations,local:e.strategies.local,ldap:{...n,servers:Object.entries(t).map(([e,t])=>({...t,id:D(),name:e,originalName:e}))},imap:{...i,domains:Object.entries(r).map(([e,t])=>({...t,id:D(),domain:e}))},google:e.strategies.google??{enabled:!1,defaultUserType:`user`,defaultStatus:`active`,clientId:``,clientSecretSet:!1,allowedDomains:[],autoCreateUsers:!0,webOrigins:[]}}}function k(e){let{id:t,name:n,originalName:r,...i}=e;return{...i,...r&&r!==e.name?{previousName:r}:{}}}function A(e){return{allowUserRegistrations:e.allowUserRegistrations,strategies:{local:e.local,ldap:{enabled:e.ldap.enabled,defaultUserType:e.ldap.defaultUserType,defaultStatus:e.ldap.defaultStatus,servers:Object.fromEntries(e.ldap.servers.map(e=>[e.name.trim(),k(e)]))},imap:{enabled:e.imap.enabled,defaultUserType:e.imap.defaultUserType,defaultStatus:e.imap.defaultStatus,domains:Object.fromEntries(e.imap.domains.map(({id:e,domain:t,...n})=>[t.trim().toLowerCase(),n]))},google:e.google}}}function j({value:e,onChange:t,placeholder:n,disabled:r}){let i=e.join(`, `),[a,o]=(0,b.useState)(i),[s,c]=(0,b.useState)(i);return i!==s&&(c(i),a.split(/[\s,]+/).filter(Boolean).join(`, `)!==i&&o(i)),(0,T.jsx)(f,{className:`h-8 text-sm`,value:a,placeholder:n,disabled:r,onChange:e=>{o(e.target.value),t(e.target.value.split(/[\s,]+/).map(e=>e.trim()).filter(Boolean))}})}var M={originalName:null,url:`ldap://`,bindDN:``,bindPasswordSet:!1,bindPassword:void 0,searchBase:``,searchFilter:`(mail={{email}})`,attributes:[`mail`,`cn`,`displayName`,`memberOf`],groupAttribute:`memberOf`,tls:!1},N={domain:``,name:``,host:``,port:993,secure:!0,startTLS:!1,requireAppPassword:!1},P=`h-8 rounded-md border border-input bg-transparent px-2 text-sm outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:opacity-50`;function F({label:e,hint:t,children:n,className:r}){return(0,T.jsxs)(`label`,{className:u(`flex min-w-0 flex-col gap-1`,r),children:[(0,T.jsx)(`span`,{className:`text-xs font-medium`,children:e}),n,t&&(0,T.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:t})]})}function I({checked:e,onChange:t,disabled:n,label:r,hint:i}){return(0,T.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,T.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:e,disabled:n,onChange:e=>t(e.target.checked)}),(0,T.jsxs)(`span`,{children:[r,i&&(0,T.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:i})]})]})}function L({title:e,description:t,enabled:n,onToggle:r,disabled:i,children:a}){return(0,T.jsxs)(`section`,{className:`rounded-lg border p-4`,children:[(0,T.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`h3`,{className:`text-sm font-semibold`,children:e}),(0,T.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:t})]}),r&&(0,T.jsxs)(`label`,{className:`flex shrink-0 items-center gap-2 text-xs font-medium`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:!!n,disabled:i,onChange:e=>r(e.target.checked)}),n?`Enabled`:`Disabled`]})]}),(0,T.jsx)(`div`,{className:u(`mt-4 space-y-4`,r&&!n&&`opacity-60`),children:a})]})}function R({result:e}){return e?(0,T.jsxs)(`div`,{className:u(`flex items-start gap-2 rounded-md border p-2 text-xs`,e.ok?`border-emerald-500/40 bg-emerald-500/5`:`border-destructive/40 bg-destructive/5`),children:[e.ok?(0,T.jsx)(a,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-emerald-600`}):(0,T.jsx)(r,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive`}),(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`p`,{children:e.message}),e.user&&e.user.groups.length>0&&(0,T.jsxs)(`p`,{className:`mt-1 break-all text-muted-foreground`,children:[`Groups: `,e.user.groups.join(` · `)]})]})]}):null}function z({value:e,onChange:t,disabled:n}){return(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap gap-4`,children:[(0,T.jsx)(F,{label:`New accounts are`,children:(0,T.jsxs)(`select`,{className:P,value:e.defaultUserType,disabled:n,onChange:e=>t({defaultUserType:e.target.value}),children:[(0,T.jsx)(`option`,{value:`user`,children:`Users`}),(0,T.jsx)(`option`,{value:`admin`,children:`Admins`})]})}),(0,T.jsx)(F,{label:`Initial status`,children:(0,T.jsxs)(`select`,{className:P,value:e.defaultStatus,disabled:n,onChange:e=>t({defaultStatus:e.target.value}),children:[(0,T.jsx)(`option`,{value:`active`,children:`Active — can sign in right away`}),(0,T.jsx)(`option`,{value:`pending`,children:`Pending — an admin activates them`}),(0,T.jsx)(`option`,{value:`inactive`,children:`Inactive`})]})})]}),e.defaultUserType===`admin`&&(0,T.jsxs)(`p`,{className:`flex items-start gap-1.5 text-[11px] text-destructive`,children:[(0,T.jsx)(l,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),`Everyone who can sign in through this backend becomes a server admin on first login.`]})]})}function B({row:e,index:t,onChange:n,onRemove:r,disabled:i}){let[a,o]=(0,b.useState)(``),[l,u]=(0,b.useState)(!1),[p,m]=(0,b.useState)(null),h=async()=>{u(!0),m(null);try{m(await C(e.originalName??e.name,k(e),a.trim()||void 0))}catch(e){m({ok:!1,message:e instanceof Error?e.message:`Test failed`})}finally{u(!1)}},g=e.bindPassword===null?`cleared on save`:typeof e.bindPassword==`string`?`replaced on save`:e.bindPasswordSet?`stored — leave empty to keep it`:`none set`;return(0,T.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsxs)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:[`#`,t+1]}),(0,T.jsx)(f,{className:`h-8 max-w-[14rem] font-mono text-sm`,value:e.name,disabled:i,onChange:e=>n({name:e.target.value}),placeholder:`primary`,"aria-label":`Server name`}),(0,T.jsx)(`div`,{className:`flex-1`}),(0,T.jsx)(d,{type:`button`,size:`sm`,variant:`ghost`,onClick:r,disabled:i,"aria-label":`Remove server`,children:(0,T.jsx)(s,{className:`h-3.5 w-3.5`})})]}),(0,T.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,T.jsx)(F,{label:`Server URL`,hint:`ldap:// or ldaps://host:port`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.url,disabled:i,onChange:e=>n({url:e.target.value}),placeholder:`ldaps://dc1.example.com:636`})}),(0,T.jsx)(F,{label:`Search base`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.searchBase,disabled:i,onChange:e=>n({searchBase:e.target.value}),placeholder:`ou=users,dc=example,dc=com`})}),(0,T.jsx)(F,{label:`Bind DN`,hint:`Service account used to look users up. Empty = anonymous search.`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.bindDN,disabled:i,onChange:e=>n({bindDN:e.target.value}),placeholder:`cn=canvas,ou=services,dc=example,dc=com`})}),(0,T.jsx)(F,{label:`Bind password`,hint:(0,T.jsxs)(T.Fragment,{children:[`Currently: `,g,e.bindPasswordSet&&e.bindPassword!==null&&(0,T.jsxs)(T.Fragment,{children:[` · `,(0,T.jsx)(`button`,{type:`button`,className:`underline hover:text-foreground`,disabled:i,onClick:()=>n({bindPassword:null}),children:`clear`})]})]}),children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`password`,autoComplete:`new-password`,value:typeof e.bindPassword==`string`?e.bindPassword:``,disabled:i,onChange:e=>n({bindPassword:e.target.value===``?void 0:e.target.value}),placeholder:e.bindPasswordSet&&e.bindPassword!==null?`••••••••`:``})}),(0,T.jsx)(F,{label:`User search filter`,hint:(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`span`,{className:`font-mono`,children:`{{email}}`}),` is replaced by the address typed at sign-in.`]}),children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.searchFilter,disabled:i,onChange:e=>n({searchFilter:e.target.value})})}),(0,T.jsx)(F,{label:`Group attribute`,hint:`Group memberships drive team workspace sharing.`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.groupAttribute,disabled:i,onChange:e=>n({groupAttribute:e.target.value}),placeholder:`memberOf`})}),(0,T.jsx)(F,{label:`Attributes to read`,hint:`Comma-separated.`,className:`sm:col-span-2`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.attributes.join(`, `),disabled:i,onChange:e=>n({attributes:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})})})]}),(0,T.jsx)(I,{checked:e.tls,disabled:i,onChange:e=>n({tls:e}),label:`Accept self-signed certificates`,hint:`Skips certificate verification for ldaps://. Only for directories with a private CA.`}),(0,T.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2 border-t pt-3`,children:[(0,T.jsx)(F,{label:`Test`,hint:`Binds with the settings above (unsaved edits included). Add an e-mail to also look that user up.`,className:`min-w-[14rem] flex-1`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`email`,value:a,onChange:e=>o(e.target.value),placeholder:`someone@example.com (optional)`})}),(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:h,disabled:l||i,className:`mb-5`,children:[l&&(0,T.jsx)(c,{className:`mr-2 h-3.5 w-3.5 animate-spin`}),`Test connection`]})]}),(0,T.jsx)(R,{result:p})]})}function V({row:e,onChange:t,onRemove:n,disabled:r}){let[i,a]=(0,b.useState)(``),[o,l]=(0,b.useState)(``),[u,p]=(0,b.useState)(!1),[m,h]=(0,b.useState)(null);return(0,T.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:`@`}),(0,T.jsx)(f,{className:`h-8 max-w-[16rem] font-mono text-sm`,value:e.domain,disabled:r,onChange:e=>t({domain:e.target.value}),placeholder:`example.com`,"aria-label":`E-mail domain`}),(0,T.jsx)(`div`,{className:`flex-1`}),(0,T.jsx)(d,{type:`button`,size:`sm`,variant:`ghost`,onClick:n,disabled:r,"aria-label":`Remove domain`,children:(0,T.jsx)(s,{className:`h-3.5 w-3.5`})})]}),(0,T.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-[1fr_6rem_1fr]`,children:[(0,T.jsx)(F,{label:`IMAP host`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:e.host,disabled:r,onChange:e=>t({host:e.target.value}),placeholder:`imap.example.com`})}),(0,T.jsx)(F,{label:`Port`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`number`,min:1,max:65535,value:e.port,disabled:r,onChange:e=>t({port:Number(e.target.value)})})}),(0,T.jsx)(F,{label:`Label on the sign-in form`,hint:`Optional.`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,value:e.name,disabled:r,onChange:e=>t({name:e.target.value}),placeholder:`Example Mail`})})]}),(0,T.jsxs)(`div`,{className:`flex flex-wrap gap-x-6 gap-y-2`,children:[(0,T.jsx)(I,{checked:e.secure,disabled:r,onChange:e=>t({secure:e,...e?{startTLS:!1}:{}}),label:`TLS from the start`,hint:`Usually port 993.`}),(0,T.jsx)(I,{checked:e.startTLS,disabled:r||e.secure,onChange:e=>t({startTLS:e}),label:`Require STARTTLS`,hint:`Plain port 143 upgraded to TLS.`}),(0,T.jsx)(I,{checked:e.requireAppPassword,disabled:r,onChange:e=>t({requireAppPassword:e}),label:`Needs an app password`,hint:`Shown as a hint on the sign-in form.`})]}),(0,T.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2 border-t pt-3`,children:[(0,T.jsx)(F,{label:`Test sign-in`,hint:`A real IMAP login with these credentials, logged straight out. Nothing is stored.`,className:`min-w-[12rem] flex-1`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`email`,value:i,onChange:e=>a(e.target.value),placeholder:`someone@${e.domain||`example.com`}`})}),(0,T.jsx)(F,{label:`Password`,className:`mb-5 min-w-[10rem] flex-1`,children:(0,T.jsx)(f,{className:`h-8 text-sm`,type:`password`,autoComplete:`off`,value:o,onChange:e=>l(e.target.value)})}),(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:async()=>{p(!0),h(null);try{let{id:t,domain:n,...r}=e;h(await w(r,i.trim(),o))}catch(e){h({ok:!1,message:e instanceof Error?e.message:`Test failed`})}finally{p(!1),l(``)}},disabled:u||r||!i||!o,className:`mb-5`,children:[u&&(0,T.jsx)(c,{className:`mr-2 h-3.5 w-3.5 animate-spin`}),`Test`]})]}),(0,T.jsx)(R,{result:m})]})}function H(){let e=y(),{showToast:t}=_(),n=g()?.userType===`admin`,[r,a]=(0,b.useState)(``),[s,u]=(0,b.useState)(null),[p,h]=(0,b.useState)(null),[C,w]=(0,b.useState)(!0),[E,k]=(0,b.useState)(!1),[P,R]=(0,b.useState)(null),[H,U]=(0,b.useState)(null),W=(0,b.useCallback)(()=>x().then(e=>{let t=O(e.config);a(e.configPath),u(t),h(t),R(null)}).catch(e=>R(e instanceof Error?e.message:`Failed to load auth configuration`)).finally(()=>w(!1)),[]);(0,b.useEffect)(()=>{n&&W()},[n,W]);let G=(0,b.useMemo)(()=>!!p&&!!s&&JSON.stringify(A(p))!==JSON.stringify(A(s)),[p,s]),K=e=>h(t=>t&&e(t)),q=(e,t)=>K(n=>({...n,ldap:{...n.ldap,servers:n.ldap.servers.map(n=>n.id===e?{...n,...t}:n)}})),J=(e,t)=>K(n=>({...n,imap:{...n.imap,domains:n.imap.domains.map(n=>n.id===e?{...n,...t}:n)}})),Y=async()=>{if(!p)return;let e=p.ldap.servers.map(e=>e.name.trim()),n=p.imap.domains.map(e=>e.domain.trim().toLowerCase());if(e.some(e=>!e)||new Set(e).size!==e.length){U(`Every LDAP server needs a unique name.`);return}if(n.some(e=>!e)||new Set(n).size!==n.length){U(`Every IMAP domain must be filled in and listed once.`);return}k(!0),U(null);try{let e=O((await S(A(p))).config);u(e),h(e),t({title:`Authentication settings saved`,description:`Applied immediately — the next sign-in uses them.`})}catch(e){U(e instanceof Error?e.message.replace(/^HTTP \d+:\s*/,``):`Failed to save`)}finally{k(!1)}},X=(0,T.jsx)(v,{onBack:e,compact:!0,className:`mb-6`,title:`Authentication`,description:`Entire server · Choose how people sign in: local passwords, your LDAP directory, or their mail server over IMAP.`,actions:n&&(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>{w(!0),W()},disabled:C||E,children:[(0,T.jsx)(o,{className:`mr-2 h-3.5 w-3.5`}),`Reload`]})});return n?(0,T.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6 pb-24`,children:[X,C&&!p?(0,T.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,T.jsx)(o,{className:`h-4 w-4 animate-spin`}),`Loading…`]}):P||!p?(0,T.jsxs)(`div`,{className:`space-y-3`,children:[(0,T.jsxs)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm`,children:[(0,T.jsx)(`p`,{className:`font-medium text-destructive`,children:`Authentication settings unavailable`}),(0,T.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:P||`No config returned.`})]}),(0,T.jsx)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>{w(!0),W()},children:`Retry`})]}):(0,T.jsxs)(`div`,{className:`space-y-4`,children:[(0,T.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Config file: `,(0,T.jsx)(`span`,{className:`font-mono`,children:r}),` · Sign-in picks the backend from the account: existing users keep the method they were created with; a new address tries LDAP first (when enabled), then IMAP for a listed domain, then local.`]}),(0,T.jsxs)(L,{title:`Sign-up & local passwords`,description:`Accounts whose password is stored on this server.`,children:[(0,T.jsx)(I,{checked:p.allowUserRegistrations,onChange:e=>K(t=>({...t,allowUserRegistrations:e})),label:`Allow self-registration`,hint:`Off = only admins create accounts (and LDAP/IMAP users on first sign-in).`}),(0,T.jsx)(I,{checked:p.local.enabled,onChange:e=>K(t=>({...t,local:{...t.local,enabled:e}})),label:`Local password accounts`,hint:`Off refuses new local registrations. Existing local accounts — admins included — can still sign in, so this cannot lock you out.`}),(0,T.jsx)(I,{checked:p.local.requireEmailVerification,onChange:e=>K(t=>({...t,local:{...t.local,requireEmailVerification:e}})),label:`Require e-mail verification`,hint:`Needs working SMTP (config/smtp.json).`}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`p`,{className:`mb-2 text-xs font-medium`,children:`Password policy`}),(0,T.jsxs)(`div`,{className:`flex flex-wrap items-start gap-4`,children:[(0,T.jsx)(F,{label:`Min length`,children:(0,T.jsx)(f,{className:`h-8 w-24 text-sm`,type:`number`,min:1,max:1024,value:p.local.passwordPolicy.minLength,onChange:e=>K(t=>({...t,local:{...t.local,passwordPolicy:{...t.local.passwordPolicy,minLength:Number(e.target.value)}}}))})}),(0,T.jsx)(F,{label:`Max length`,children:(0,T.jsx)(f,{className:`h-8 w-24 text-sm`,type:`number`,min:1,max:1024,value:p.local.passwordPolicy.maxLength,onChange:e=>K(t=>({...t,local:{...t.local,passwordPolicy:{...t.local.passwordPolicy,maxLength:Number(e.target.value)}}}))})}),(0,T.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-1 pt-1`,children:[[`requireUppercase`,`Uppercase letter`],[`requireLowercase`,`Lowercase letter`],[`requireNumbers`,`Number`],[`requireSpecialChars`,`Special character`]].map(([e,t])=>(0,T.jsx)(I,{checked:p.local.passwordPolicy[e],label:t,onChange:t=>K(n=>({...n,local:{...n.local,passwordPolicy:{...n.local.passwordPolicy,[e]:t}}}))},e))})]})]})]}),(0,T.jsxs)(L,{title:`LDAP / Active Directory`,description:`Users sign in with their directory password. Servers are tried in order, so later ones act as fallbacks.`,enabled:p.ldap.enabled,onToggle:e=>K(t=>({...t,ldap:{...t.ldap,enabled:e}})),children:[(0,T.jsx)(z,{value:p.ldap,onChange:e=>K(t=>({...t,ldap:{...t.ldap,...e}}))}),p.ldap.servers.map((e,t)=>(0,T.jsx)(B,{row:e,index:t,onChange:t=>q(e.id,t),onRemove:()=>K(t=>({...t,ldap:{...t.ldap,servers:t.ldap.servers.filter(t=>t.id!==e.id)}}))},e.id)),(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>K(e=>({...e,ldap:{...e.ldap,servers:[...e.ldap.servers,{...M,id:D(),name:e.ldap.servers.length?`server${e.ldap.servers.length+1}`:`primary`}]}})),children:[(0,T.jsx)(i,{className:`mr-2 h-3.5 w-3.5`}),` Add LDAP server`]})]}),(0,T.jsxs)(L,{title:`IMAP (mail server sign-in)`,description:`Users of a listed e-mail domain sign in with their mailbox password — the server checks it by logging in to IMAP.`,enabled:p.imap.enabled,onToggle:e=>K(t=>({...t,imap:{...t.imap,enabled:e}})),children:[(0,T.jsx)(z,{value:p.imap,onChange:e=>K(t=>({...t,imap:{...t.imap,...e}}))}),p.imap.domains.map(e=>(0,T.jsx)(V,{row:e,onChange:t=>J(e.id,t),onRemove:()=>K(t=>({...t,imap:{...t.imap,domains:t.imap.domains.filter(t=>t.id!==e.id)}}))},e.id)),(0,T.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>K(e=>({...e,imap:{...e.imap,domains:[...e.imap.domains,{...N,id:D()}]}})),children:[(0,T.jsx)(i,{className:`mr-2 h-3.5 w-3.5`}),` Add mail domain`]})]}),(0,T.jsxs)(L,{title:`Google sign-in`,description:(0,T.jsxs)(T.Fragment,{children:[`One-click sign-in with a Google account via OAuth. Needs a Google Cloud OAuth client of type `,(0,T.jsx)(`em`,{children:`Web application`}),` whose authorized redirect URI is `,(0,T.jsx)(`code`,{className:`select-all`,children:`${m}/oauth/google/callback`}),`.`]}),enabled:p.google.enabled,onToggle:e=>K(t=>({...t,google:{...t.google,enabled:e}})),children:[(0,T.jsx)(z,{value:p.google,onChange:e=>K(t=>({...t,google:{...t.google,...e}}))}),(0,T.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,T.jsx)(F,{label:`OAuth client id`,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,value:p.google.clientId,autoComplete:`off`,onChange:e=>K(t=>({...t,google:{...t.google,clientId:e.target.value}}))})}),(0,T.jsx)(F,{label:`OAuth client secret`,hint:p.google.clientSecretSet&&p.google.clientSecret===void 0?`A secret is stored; leave blank to keep it.`:void 0,children:(0,T.jsx)(f,{className:`h-8 font-mono text-sm`,type:`password`,autoComplete:`off`,value:p.google.clientSecret??``,placeholder:p.google.clientSecretSet?`••••••••`:``,onChange:e=>K(t=>({...t,google:{...t.google,clientSecret:e.target.value===``?void 0:e.target.value}}))})}),(0,T.jsx)(F,{label:`Allowed e-mail domains`,hint:`Comma separated. Empty = any Google account may sign in.`,children:(0,T.jsx)(j,{value:p.google.allowedDomains,placeholder:`example.com, example.org`,onChange:e=>K(t=>({...t,google:{...t.google,allowedDomains:e}}))})}),(0,T.jsx)(F,{label:`Extra web origins`,hint:`Only when the web UI is served from another origin than the API (e.g. a Vite dev server).`,children:(0,T.jsx)(j,{value:p.google.webOrigins,placeholder:`http://localhost:5173`,onChange:e=>K(t=>({...t,google:{...t.google,webOrigins:e}}))})})]}),(0,T.jsx)(I,{checked:p.google.autoCreateUsers,label:`Create an account on first sign-in`,hint:`Off: only users that already exist (by e-mail) can sign in with Google.`,onChange:e=>K(t=>({...t,google:{...t.google,autoCreateUsers:e}}))})]}),(G||H)&&(0,T.jsxs)(`div`,{className:`sticky bottom-4 z-10 rounded-lg border bg-card p-3 shadow-elevation-4`,children:[H&&(0,T.jsx)(`ul`,{className:`mb-2 space-y-0.5 text-xs text-destructive`,children:H.split(`; `).map(e=>(0,T.jsx)(`li`,{children:e},e))}),(0,T.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,T.jsx)(`span`,{className:`mr-auto text-xs text-muted-foreground`,children:G?`Unsaved changes`:``}),(0,T.jsx)(d,{type:`button`,size:`sm`,variant:`ghost`,disabled:E,onClick:()=>{h(s),U(null)},children:`Discard`}),(0,T.jsxs)(d,{type:`button`,size:`sm`,disabled:E||!G,onClick:()=>void Y(),children:[E&&(0,T.jsx)(c,{className:`mr-2 h-3.5 w-3.5 animate-spin`}),`Save`]})]})]})]})]}):(0,T.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[X,(0,T.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border p-3 text-xs`,children:[(0,T.jsx)(l,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,T.jsx)(`p`,{className:`text-muted-foreground`,children:`Authentication settings are only available to server admins.`})]})]})}export{H as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.rule-builder{container:rule-builder/inline-size}.rule-card{grid-template-columns:auto minmax(0,1fr);align-items:start;gap:.75rem 1rem;display:grid}.rule-card-content{overflow-wrap:anywhere}.rule-card-actions{flex-wrap:wrap;grid-column:1/-1;justify-content:flex-end;align-items:center;gap:.25rem;min-width:0;display:flex}.rule-card-action-label{display:none}@container rule-builder (width>=24rem){.rule-card-action-label{display:inline}}@container rule-builder (width>=48rem){.rule-card{grid-template-columns:auto minmax(0,1fr) auto}.rule-card-actions{grid-column:auto}}
|