@augmentd-labs/canvas-web 2.26.45 → 2.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CalendarApplet-CsyUmI2B.js → CalendarApplet-Be25FsQH.js} +1 -1
- package/dist/assets/{FiltersApplet-CVnCAs-P.js → FiltersApplet-CuBp34Ll.js} +1 -1
- package/dist/assets/{HomeFab-iC5BF7LV.js → HomeFab-BVC6GyBo.js} +1 -1
- package/dist/assets/{LensApplet-DA0ZWS1k.js → LensApplet-cH9mu9Ek.js} +1 -1
- package/dist/assets/{NotesApplet-BSJ-9RKl.js → NotesApplet-D7vrAU-F.js} +1 -1
- package/dist/assets/{_agentId_-BrzFDu8r.js → _agentId_-D7FMIU0U.js} +0 -0
- package/dist/assets/{_contextId_-DS6b9Uml.js → _contextId_-nHWeEqjb.js} +1 -1
- package/dist/assets/{_workspaceName_-XRqfa4c6.js → _workspaceName_-Ca7l8D3u.js} +1 -1
- package/dist/assets/{about-hcdKJNm5.js → about-DPQIKA4h.js} +1 -1
- package/dist/assets/{add-CEBusWuu.js → add-C4IXcB8E.js} +1 -1
- package/dist/assets/{agents-wFp7Vh3p.js → agents-Cq1aDFAt.js} +1 -1
- package/dist/assets/{appearance-D5BUjZm8.js → appearance-DTH3zH0p.js} +1 -1
- package/dist/assets/{apps-65YXCnzH.js → apps-DGG9ruBT.js} +1 -1
- package/dist/assets/{home-vr8b8oR-.js → home-BK8Bp4d-.js} +1 -1
- package/dist/assets/index-NOhHv2VY.js +16 -0
- package/dist/assets/{key-bindings-DmqvYSaF.js → key-bindings-Cbh1Fiav.js} +1 -1
- package/dist/assets/{registry-g1SKt_fD.js → registry-D7HyG001.js} +2 -2
- package/dist/assets/{settings-CbMkpipO.js → settings-6UW5qG-V.js} +1 -1
- package/dist/assets/{settings-XMhqrvTu.js → settings-BbqSg6FH.js} +1 -1
- package/dist/assets/{settings-BWCMmkjr.js → settings-CkBpWcHX.js} +1 -1
- package/dist/assets/{settings-BIoSwdXv.js → settings-Ckel628s.js} +1 -1
- package/dist/assets/{share-target-hDXdgW6o.js → share-target-CuBCWHxv.js} +1 -1
- package/dist/assets/{shared-DVlDThVA.js → shared-CqqMgsnU.js} +1 -1
- package/dist/assets/{tree-folders-IDoobsGN.js → tree-folders-dKwIsl1U.js} +1 -1
- package/dist/assets/{useAgentModels-CI9XT6yc.js → useAgentModels-DTZNaSRA.js} +1 -1
- package/dist/assets/{workspaces-ByYQ6L3I.js → workspaces-CXhffn_p.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/dist/assets/index-CTvqbEB8.js +0 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_t as r,gt as i,ht as a}from"./index-
|
|
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,gt as i,ht as a}from"./index-NOhHv2VY.js";import{n as o}from"./page-header-NyYSXjfY.js";import{t as s}from"./use-settings-back-D_MM9diy.js";var c=e(n(),1),l=t();function u(){let[e,t]=(0,c.useState)(i),[n,u]=(0,c.useState)(``),d=e=>{if(e.previousTree&&e.previousTree===e.nextTree){u(`Choose a different shortcut: that combination is already assigned.`);return}try{r(e),t(e),u(`Saved on this device.`)}catch{u(`Could not save shortcuts in this browser.`)}};return(0,l.jsxs)(`div`,{className:`mx-auto max-w-4xl`,children:[(0,l.jsx)(o,{className:`mb-6`,title:`Key bindings`,onBack:s(),description:`Web UI shortcuts, saved on this device and available offline.`}),(0,l.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,l.jsx)(`h2`,{className:`font-medium`,children:`Tree navigation`}),(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Cycle the open workspace menu’s tabs in their displayed order, including Pins and Layers. Swipe left for next or right for previous over the tab bar. Shortcuts pause while typing or using a dialog.`}),[`previousTree`,`nextTree`].map(t=>(0,l.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,l.jsx)(`label`,{htmlFor:t,className:`min-w-32 text-sm`,children:t===`previousTree`?`Previous tree`:`Next tree`}),(0,l.jsxs)(`select`,{id:t,className:`rounded-md border bg-background p-2 text-sm`,value:e[t].split(`+`).slice(0,-1).join(`+`),onChange:n=>d({...e,[t]:n.target.value?`${n.target.value}+${e[t].slice(-1)||a[t].slice(-1)}`:``}),children:[(0,l.jsx)(`option`,{value:``,children:`Disabled`}),[`Alt`,`Alt+Shift`,`Ctrl+Shift`,`Meta+Shift`].map(e=>(0,l.jsx)(`option`,{value:e,children:e},e))]}),(0,l.jsx)(`select`,{"aria-label":`${t===`previousTree`?`Previous`:`Next`} tree key`,disabled:!e[t],className:`rounded-md border bg-background p-2 text-sm disabled:opacity-50`,value:e[t].slice(-1)||a[t].slice(-1),onChange:n=>d({...e,[t]:`${e[t].split(`+`).slice(0,-1).join(`+`)}+${n.target.value}`}),children:`ABCDEFGHIJKLMNOPQRSTUVWXYZ`.split(``).map(e=>(0,l.jsx)(`option`,{value:e,children:e},e))})]},t)),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Browsers and operating systems may reserve combinations. Choose another if a shortcut does not reach Canvas. Letters refer to physical keyboard positions (Q/W on a US keyboard); Meta is Command on Mac.`}),(0,l.jsx)(`button`,{type:`button`,className:`rounded-md border px-3 py-2 text-sm hover:bg-accent`,onClick:()=>d({...a}),children:`Restore defaults`}),(0,l.jsx)(`p`,{role:`status`,className:`text-sm`,children:n})]})]})}export{u as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalApplet-BZJx2ztD.js","assets/rolldown-runtime-C0FnF6B9.js","assets/code-editor-BOIngd5F.js","assets/ui-DEgHnkQu.js","assets/react-BHzhHVTZ.js","assets/use-applet-target-BlpVWlnA.js","assets/workspace-4hWrSEku.js","assets/button--VYZekMF.js","assets/utils-BxVxyehK.js","assets/utils-2pl1SbIp.js","assets/input-BOtCd4HP.js","assets/api-CA6WiiYM.js","assets/alert-dialog-BKtaX1_a.js","assets/use-toolbox-Ck_cLGgf.js","assets/TerminalApplet-BrP-ENHg.css","assets/NotesApplet-
|
|
2
|
-
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"./preload-helper-Czpn1I53.js";import{$r as i,St as a,Xr as o,ct as s,hn as c,it as l,tt as u}from"./ui-DEgHnkQu.js";var d=e(n(),1),f=t();function p(e){let t=(0,d.lazy)(e);return function(e){return(0,f.jsx)(d.Suspense,{fallback:(0,f.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,role:`status`,children:`Opening app…`}),children:(0,f.jsx)(t,{...e})})}}var m=p(()=>r(()=>import(`./TerminalApplet-BZJx2ztD.js`).then(e=>({default:e.TerminalApplet})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]))),h=p(()=>r(()=>import(`./NotesApplet-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalApplet-BZJx2ztD.js","assets/rolldown-runtime-C0FnF6B9.js","assets/code-editor-BOIngd5F.js","assets/ui-DEgHnkQu.js","assets/react-BHzhHVTZ.js","assets/use-applet-target-BlpVWlnA.js","assets/workspace-4hWrSEku.js","assets/button--VYZekMF.js","assets/utils-BxVxyehK.js","assets/utils-2pl1SbIp.js","assets/input-BOtCd4HP.js","assets/api-CA6WiiYM.js","assets/alert-dialog-BKtaX1_a.js","assets/use-toolbox-Ck_cLGgf.js","assets/TerminalApplet-BrP-ENHg.css","assets/NotesApplet-D7vrAU-F.js","assets/useAddTarget-BvuFR5pN.js","assets/context-DY40EDc6.js","assets/note-save-status-DPz4VzL6.js","assets/useEditNoteFields-DsVKIHWm.js","assets/tags-YamdPoBK.js","assets/index-NOhHv2VY.js","assets/preload-helper-Czpn1I53.js","assets/chunk-62JRHF6Z-vspAGgtK.js","assets/label-RuOXXC8t.js","assets/socket-hM4c-ZSl.js","assets/socket-CtH3EU9m.js","assets/auth-Bx9fAZmz.js","assets/use-toast-BlLDqSUO.js","assets/LinkToCard-oi3wGP0a.js","assets/useEscapeClose-DR_xKT_k.js","assets/useToastHelpers-CRrpIIdY.js","assets/layer-style-Byl5LNFR.js","assets/color-DFEH4BfK.js","assets/DocumentIcon-0ya9gycp.js","assets/use-canvas-pins-q5Tncavk.js","assets/TodosWidget-DGftEAbs.js","assets/ObjectPropertiesCard-DesXRw-_.js","assets/use-mobile-Db-vWu9Y.js","assets/IdentityFields-CB3Ap0bl.js","assets/date-time-picker-p3vy4nst.js","assets/relation-events-CKio19hE.js","assets/map-BxCwdK0d.js","assets/map-BcsP_QXj.css","assets/public-share-0DqS7L2Q.js","assets/text-documents-wu6fzOuw.js","assets/blobs-WiXP9QRi.js","assets/useDocumentThumbnail-CZIaXkIi.js","assets/markdown-view-BBBZtNSR.js","assets/sanitize-DrVcFY1Q.js","assets/MessageComposerDialog-CLrwtB76.js","assets/markdown-it-DRESbtwK.js","assets/punycode.es6-ZbLrB_Dn.js","assets/lazy-editor-CShGeIep.js","assets/LinkToSidePanel-eCy3nW4R.js","assets/DocumentBodyEditor-C8AEpqX3.js","assets/use-document-modal-PG8bQyIB.js","assets/sketch-lazy-CtjOUfVz.js","assets/geo-CZfs0E-x.js","assets/ObjectPropertiesCard-Docu7O5V.css","assets/document-list-Bbbx-pTZ.js","assets/document-open-mode-DoImW-xs.js","assets/PickDocumentsCard-DVdBxx3s.js","assets/sha256-65KIjGvZ.js","assets/rule-builder-CziPqpNe.js","assets/PathPickerField-CSIa7jSl.js","assets/rule-builder-DU-e9TWi.css","assets/workspace-access-C9nZlBBZ.js","assets/search-COMZIxA7.js","assets/use-sortable-data-D7zS2qCC.js","assets/workspace-BydSRtST.js","assets/document-list-DAYdk5vh.css","assets/url-params-n7kU_WZ-.js","assets/use-canvas-pins-C57Vbkrq.css","assets/use-menu-CKSpS96u.js","assets/last-path-BbXWC3b3.js","assets/document-paste-BuTC6S7_.js","assets/workspace-content-gate-BlFdbi67.js","assets/use-theme-DaxpiICf.js","assets/index-CoVFQpP3.css","assets/shared-CLjTxih0.js","assets/use-applet-docs-C08GAUm3.js","assets/TodosApplet-DY7JzeZS.js","assets/LensApplet-cH9mu9Ek.js","assets/FiltersApplet-CuBp34Ll.js","assets/SketchApplet--3uyqpmo.js","assets/CalendarApplet-Be25FsQH.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
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"./preload-helper-Czpn1I53.js";import{$r as i,St as a,Xr as o,ct as s,hn as c,it as l,tt as u}from"./ui-DEgHnkQu.js";var d=e(n(),1),f=t();function p(e){let t=(0,d.lazy)(e);return function(e){return(0,f.jsx)(d.Suspense,{fallback:(0,f.jsx)(`p`,{className:`p-4 text-sm text-muted-foreground`,role:`status`,children:`Opening app…`}),children:(0,f.jsx)(t,{...e})})}}var m=p(()=>r(()=>import(`./TerminalApplet-BZJx2ztD.js`).then(e=>({default:e.TerminalApplet})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]))),h=p(()=>r(()=>import(`./NotesApplet-D7vrAU-F.js`).then(e=>({default:e.NotesApplet})),__vite__mapDeps([15,1,2,3,4,9,8,6,7,10,11,12,16,13,17,18,19,20,5,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81]))),g=p(()=>r(()=>import(`./TodosApplet-DY7JzeZS.js`).then(e=>({default:e.TodosApplet})),__vite__mapDeps([82,1,2,3,4,9,8,6,7,10,11,12,16,13,17,40,20,41,5,80,29,30,31,28,32,33,34,54,81]))),_=p(()=>r(()=>import(`./LensApplet-cH9mu9Ek.js`).then(e=>({default:e.LensApplet})),__vite__mapDeps([83,1,2,3,4,9,8,6,7,10,11,12,47,44,34,56,5,13,21,22,23,24,25,26,27,28,29,30,31,32,33,35,36,37,38,39,20,16,17,40,41,42,43,45,46,48,49,50,51,52,53,54,18,19,55,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79]))),v=p(()=>r(()=>import(`./FiltersApplet-CuBp34Ll.js`).then(e=>({default:e.FiltersApplet})),__vite__mapDeps([84,1,2,26,11,25,13,5,6,4,7,3,8,9,10,12,21,22,23,24,27,28,29,30,31,32,33,34,35,36,37,38,39,20,16,17,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,18,19,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79]))),y=p(()=>r(()=>import(`./SketchApplet--3uyqpmo.js`).then(e=>({default:e.SketchApplet})),__vite__mapDeps([85,1,2,3,4,7,8,9,6,10,11,12,47,44,31,28,57,22,5,13,81,17]))),b=p(()=>r(()=>import(`./CalendarApplet-Be25FsQH.js`).then(e=>({default:e.CalendarApplet})),__vite__mapDeps([86,1,2,23,22,3,4,9,8,29,7,6,10,11,12,30,31,28,32,33,34,16,13,17,40,20,41,5,21,24,25,26,27,35,36,37,38,39,42,43,44,45,46,47,48,49,50,51,52,53,54,18,19,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]))),x=[{id:`terminal`,category:`utilities`,label:`Terminal`,icon:l,modes:[`context`],description:`Shell sessions for this context`,Component:m},{id:`filters`,category:`utilities`,label:`Filters`,icon:s,modes:[`context`,`global`],description:`Search and filter a workspace or a live context`,Component:v},{id:`notes`,category:`productivity`,label:`Notes`,icon:u,modes:[`context`],description:`All notes in the current context, editable in place`,Component:h},{id:`todo`,category:`productivity`,label:`Todos`,icon:c,modes:[`context`],description:`Todos in the current context, done items hidden by default`,Component:g},{id:`calendar`,category:`productivity`,label:`Calendar`,icon:o,modes:[`context`],description:`Day, week, month, year and schedule views of the events and due tasks in the current context`,Component:b},{id:`sketch`,category:`creative`,label:`Sketch`,icon:i,modes:[`context`],description:`Quick-sketch into the current context; tap a sketch to keep editing`,Component:y},{id:`lens`,category:`media`,label:`Lens`,icon:a,modes:[`context`],description:`Point a camera at things; matching documents surface live`,Component:_}];function S(e){return x.filter(t=>t.modes.includes(e))}export{S as n,x as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as ee,g as r,v as i}from"./chunk-62JRHF6Z-vspAGgtK.js";import{G as te,X as a,kt as o}from"./ui-DEgHnkQu.js";import{t as s}from"./utils-2pl1SbIp.js";import{t as c}from"./button--VYZekMF.js";import{t as l}from"./input-BOtCd4HP.js";import{n as ne}from"./use-toast-BlLDqSUO.js";import{t as re}from"./use-mobile-Db-vWu9Y.js";import{E as ie,a as ae,c as oe,f as u,r as d,v as se,w as ce,x as le}from"./context-DY40EDc6.js";import{t as f}from"./PathPickerField-CSIa7jSl.js";import{i as ue}from"./use-menu-CKSpS96u.js";import{Ct as p,bt as de}from"./index-CTvqbEB8.js";import{n as fe}from"./page-header-NyYSXjfY.js";var m=e(n(),1),h=t(),g=[{value:`documentRead`,label:`Read`},{value:`documentWrite`,label:`Write`},{value:`documentReadWrite`,label:`Read & write`}];function _(){let{contextId:e,tab:t}=ee(),[n]=i(),_=n.get(`ownerId`)||void 0,v=r(),{showToast:y}=ne(),{selectEntity:b,goBack:x,closeM2:S}=ue(),C=re(),w=p(t),T=_?`?ownerId=${encodeURIComponent(_)}`:``;(0,m.useEffect)(()=>{t!==w&&e&&v(`/contexts/${e}/settings/${w}${T}`,{replace:!0})},[t,w,e,T,v]);let[E,D]=(0,m.useState)(null),[pe,me]=(0,m.useState)(!0),[O,k]=(0,m.useState)(!1),[A,j]=(0,m.useState)(!1),[M,N]=(0,m.useState)(``),[P,F]=(0,m.useState)(``),[I,L]=(0,m.useState)(null),[R,z]=(0,m.useState)(``),[B,V]=(0,m.useState)(``),[H,he]=(0,m.useState)(),[U,W]=(0,m.useState)([]),[G,K]=(0,m.useState)(!1),[q,J]=(0,m.useState)(``),[Y,ge]=(0,m.useState)(g[0].value),[X,Z]=(0,m.useState)(null);(0,m.useEffect)(()=>{if(!e)return;let t=!1;return ae(e,_).then(e=>{t||(D(e),b(e.id),N(e.name||``),F(e.description||``),L(typeof e.metadata?.ui?.color==`string`?e.metadata.ui.color:null),z(e.url||``),V(e.baseUrl||``))}).catch(()=>{t||y({title:`Error`,description:`Failed to load context`,variant:`destructive`})}).finally(()=>{t||me(!1)}),()=>{t=!0}},[e,_,b,y]);let Q=(t=e)=>{t&&(K(!0),u(t).then(W).catch(()=>W([])).finally(()=>K(!1)))};(0,m.useEffect)(()=>{if(w!==`shares`||!e)return;let t=!1;return u(e).then(e=>{t||W(e)}).catch(()=>{t||W([])}),()=>{t=!0}},[w,e]);let _e=async t=>{if(t.preventDefault(),e){k(!0);try{let t=await se(e,{name:M.trim(),description:P.trim(),metadata:{...E?.metadata,ui:{...E?.metadata?.ui,color:I}}},_);D(t),window.dispatchEvent(new CustomEvent(`contexts:refresh`)),y({title:`Saved`,description:`Context updated`})}catch(e){y({title:`Error`,description:e instanceof Error?e.message:`Save failed`,variant:`destructive`})}finally{k(!1)}}},ve=async t=>{if(t.preventDefault(),e){k(!0);try{await Promise.all([ie(e,R.trim(),_,H),ce(e,{baseUrl:B.trim()||null},_)]),window.dispatchEvent(new CustomEvent(`contexts:refresh`)),y({title:`Saved`,description:`Context URL updated`})}catch(e){y({title:`Error`,description:e instanceof Error?e.message:`Save failed`,variant:`destructive`})}finally{k(!1)}}},ye=async()=>{if(e&&window.confirm(`Delete context "${e}"? This cannot be undone.`)){j(!0);try{await d(e,_),S(),b(null),y({title:`Deleted`,description:`Context "${e}" removed`}),v(`/contexts`,{replace:!0})}catch(e){y({title:`Error`,description:e instanceof Error?e.message:`Delete failed`,variant:`destructive`})}finally{j(!1)}}},be=async t=>{if(t.preventDefault(),!(!e||!q.trim())){Z(`grant`);try{await oe(e,q.trim(),Y),J(``),Q(),y({title:`Shared`,description:`Access granted to ${q.trim()}`})}catch(e){y({title:`Error`,description:e instanceof Error?e.message:`Failed to grant access`,variant:`destructive`})}finally{Z(null)}}},xe=async t=>{if(e&&window.confirm(`Revoke ${t.userEmail}'s access to "${e}"?`)){Z(t.userEmail);try{await le(e,t.userEmail),Q(),y({title:`Revoked`,description:`${t.userEmail} no longer has access`})}catch(e){y({title:`Error`,description:e instanceof Error?e.message:`Failed to revoke access`,variant:`destructive`})}finally{Z(null)}}};if(pe)return(0,h.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:`Loading...`});if(!E)return(0,h.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:`Context not found`});let $=de.find(e=>e.id===w),Se=`/contexts/${e}${T}`;return(0,h.jsx)(`div`,{className:`h-full min-h-0 overflow-y-auto`,children:(0,h.jsxs)(`div`,{className:`mx-auto max-w-3xl p-6 pb-12 max-md:px-4 max-md:pb-rail-stack`,children:[(0,h.jsx)(fe,{compact:!0,className:`mb-6 border-b pb-4`,title:`${$.label} - ${E.name||E.id}`,description:$.description,backTo:Se,onBack:C?x:void 0}),w===`general`&&(0,h.jsxs)(`div`,{className:`space-y-6`,children:[(0,h.jsxs)(`form`,{onSubmit:_e,className:`space-y-4 rounded-lg border p-4`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{className:`text-sm font-medium`,children:`Context ID`}),(0,h.jsx)(`div`,{className:`mt-1 flex h-10 items-center rounded-md bg-muted px-3 font-mono text-sm text-muted-foreground`,children:E.id})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`ctx-name`,className:`text-sm font-medium`,children:`Name`}),(0,h.jsx)(l,{id:`ctx-name`,value:M,onChange:e=>N(e.target.value),placeholder:`My Context`})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`ctx-description`,className:`text-sm font-medium`,children:`Description`}),(0,h.jsx)(l,{id:`ctx-description`,value:P,onChange:e=>F(e.target.value),placeholder:`Optional description`})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`ctx-color`,className:`text-sm font-medium`,children:`Color`}),(0,h.jsxs)(`div`,{className:`mt-1 flex items-center gap-2`,children:[(0,h.jsx)(l,{id:`ctx-color`,type:`color`,value:/^#[0-9a-f]{6}$/i.test(I||E.color||``)?I||E.color:`#808080`,onChange:e=>L(e.target.value),className:`h-10 w-16 p-1`,disabled:O}),(0,h.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,disabled:O||I===null,onClick:()=>L(null),children:`Use inherited color`})]}),(0,h.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:I===null?`Using the tree folder or workspace color.`:`Applies only to this context.`})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{className:`text-sm font-medium`,children:`Workspace`}),(0,h.jsx)(`div`,{className:`mt-1 flex h-10 items-center rounded-md bg-muted px-3 text-sm text-muted-foreground`,children:E.workspaceName||E.workspaceId||E.workspace})]}),(0,h.jsx)(c,{type:`submit`,disabled:O,children:O?`Saving...`:`Save Changes`})]}),(0,h.jsxs)(`section`,{className:`rounded-lg border border-destructive/30 p-4`,children:[(0,h.jsx)(`h2`,{className:`mb-3 text-sm font-semibold text-destructive`,children:`Danger Zone`}),(0,h.jsxs)(c,{variant:`destructive`,disabled:A,onClick:ye,children:[(0,h.jsx)(a,{className:`mr-2 h-4 w-4`}),A?`Deleting...`:`Delete Context`]})]})]}),w===`location`&&(0,h.jsxs)(`form`,{onSubmit:ve,className:`space-y-4 rounded-lg border p-4`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`ctx-url`,className:`text-sm font-medium`,children:`URL`}),(0,h.jsx)(f,{id:`ctx-url`,value:R,onChange:z,fixedWorkspaceName:E.workspaceName,pickerTitle:`Switch context to…`,placeholder:`workspace://path`,onPickTarget:(e,t)=>{z(`${t.workspaceName}://${e.replace(/^\/+/,``)}`),he(t.treeName)}}),H&&(0,h.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Destination tree: `,H]})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`label`,{htmlFor:`ctx-base-url`,className:`text-sm font-medium`,children:[`Base URL `,(0,h.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional)`})]}),(0,h.jsx)(f,{id:`ctx-base-url`,value:B,onChange:V,fixedWorkspaceName:E.workspaceName,placeholder:`workspace://base/path`,pickerTitle:`Pick a base path…`})]}),(0,h.jsx)(c,{type:`submit`,disabled:O,children:O?`Saving...`:`Save Changes`})]}),w===`shares`&&(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`h2`,{className:`text-sm font-semibold`,children:`People with access`}),(0,h.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Only the context owner can see and change this list.`})]}),(0,h.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>Q(),disabled:G,children:[(0,h.jsx)(o,{className:s(`mr-2 h-3.5 w-3.5`,G&&`animate-spin`)}),`Refresh`]})]}),U.length===0?(0,h.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`Not shared with anyone.`}):U.map(e=>(0,h.jsxs)(`div`,{className:`flex items-start justify-between gap-3 rounded-md border p-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`div`,{className:`truncate text-sm font-medium`,children:e.userEmail}),(0,h.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[g.find(t=>t.value===e.accessLevel)?.label||e.accessLevel||`unknown access`,e.sharedAt&&` - since ${new Date(e.sharedAt).toLocaleDateString()}`]})]}),(0,h.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,className:`text-destructive hover:text-destructive`,disabled:X===e.userEmail,onClick:()=>xe(e),children:(0,h.jsx)(te,{className:`h-3.5 w-3.5`})})]},e.userEmail))]}),(0,h.jsxs)(`form`,{onSubmit:be,className:`space-y-4 rounded-lg border p-4`,children:[(0,h.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Grant access`}),(0,h.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`share-email`,className:`text-sm font-medium`,children:`User email`}),(0,h.jsx)(l,{id:`share-email`,type:`email`,value:q,onChange:e=>J(e.target.value),placeholder:`person@example.com`}),(0,h.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`The user must already have an account on this server.`})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`share-level`,className:`text-sm font-medium`,children:`Access level`}),(0,h.jsx)(`select`,{id:`share-level`,value:Y,onChange:e=>ge(e.target.value),className:`mt-1 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring`,children:g.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,h.jsx)(c,{type:`submit`,disabled:X===`grant`||!q.trim(),children:X===`grant`?`Sharing...`:`Share context`})]})]})]})})}export{_ as default};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as ee,g as r,v as i}from"./chunk-62JRHF6Z-vspAGgtK.js";import{G as te,X as a,kt as o}from"./ui-DEgHnkQu.js";import{t as s}from"./utils-2pl1SbIp.js";import{t as c}from"./button--VYZekMF.js";import{t as l}from"./input-BOtCd4HP.js";import{n as ne}from"./use-toast-BlLDqSUO.js";import{t as re}from"./use-mobile-Db-vWu9Y.js";import{E as ie,a as ae,c as oe,f as u,r as d,v as se,w as ce,x as le}from"./context-DY40EDc6.js";import{t as f}from"./PathPickerField-CSIa7jSl.js";import{i as ue}from"./use-menu-CKSpS96u.js";import{Ct as p,bt as de}from"./index-NOhHv2VY.js";import{n as fe}from"./page-header-NyYSXjfY.js";var m=e(n(),1),h=t(),g=[{value:`documentRead`,label:`Read`},{value:`documentWrite`,label:`Write`},{value:`documentReadWrite`,label:`Read & write`}];function _(){let{contextId:e,tab:t}=ee(),[n]=i(),_=n.get(`ownerId`)||void 0,v=r(),{showToast:y}=ne(),{selectEntity:b,goBack:x,closeM2:S}=ue(),C=re(),w=p(t),T=_?`?ownerId=${encodeURIComponent(_)}`:``;(0,m.useEffect)(()=>{t!==w&&e&&v(`/contexts/${e}/settings/${w}${T}`,{replace:!0})},[t,w,e,T,v]);let[E,D]=(0,m.useState)(null),[pe,me]=(0,m.useState)(!0),[O,k]=(0,m.useState)(!1),[A,j]=(0,m.useState)(!1),[M,N]=(0,m.useState)(``),[P,F]=(0,m.useState)(``),[I,L]=(0,m.useState)(null),[R,z]=(0,m.useState)(``),[B,V]=(0,m.useState)(``),[H,he]=(0,m.useState)(),[U,W]=(0,m.useState)([]),[G,K]=(0,m.useState)(!1),[q,J]=(0,m.useState)(``),[Y,ge]=(0,m.useState)(g[0].value),[X,Z]=(0,m.useState)(null);(0,m.useEffect)(()=>{if(!e)return;let t=!1;return ae(e,_).then(e=>{t||(D(e),b(e.id),N(e.name||``),F(e.description||``),L(typeof e.metadata?.ui?.color==`string`?e.metadata.ui.color:null),z(e.url||``),V(e.baseUrl||``))}).catch(()=>{t||y({title:`Error`,description:`Failed to load context`,variant:`destructive`})}).finally(()=>{t||me(!1)}),()=>{t=!0}},[e,_,b,y]);let Q=(t=e)=>{t&&(K(!0),u(t).then(W).catch(()=>W([])).finally(()=>K(!1)))};(0,m.useEffect)(()=>{if(w!==`shares`||!e)return;let t=!1;return u(e).then(e=>{t||W(e)}).catch(()=>{t||W([])}),()=>{t=!0}},[w,e]);let _e=async t=>{if(t.preventDefault(),e){k(!0);try{let t=await se(e,{name:M.trim(),description:P.trim(),metadata:{...E?.metadata,ui:{...E?.metadata?.ui,color:I}}},_);D(t),window.dispatchEvent(new CustomEvent(`contexts:refresh`)),y({title:`Saved`,description:`Context updated`})}catch(e){y({title:`Error`,description:e instanceof Error?e.message:`Save failed`,variant:`destructive`})}finally{k(!1)}}},ve=async t=>{if(t.preventDefault(),e){k(!0);try{await Promise.all([ie(e,R.trim(),_,H),ce(e,{baseUrl:B.trim()||null},_)]),window.dispatchEvent(new CustomEvent(`contexts:refresh`)),y({title:`Saved`,description:`Context URL updated`})}catch(e){y({title:`Error`,description:e instanceof Error?e.message:`Save failed`,variant:`destructive`})}finally{k(!1)}}},ye=async()=>{if(e&&window.confirm(`Delete context "${e}"? This cannot be undone.`)){j(!0);try{await d(e,_),S(),b(null),y({title:`Deleted`,description:`Context "${e}" removed`}),v(`/contexts`,{replace:!0})}catch(e){y({title:`Error`,description:e instanceof Error?e.message:`Delete failed`,variant:`destructive`})}finally{j(!1)}}},be=async t=>{if(t.preventDefault(),!(!e||!q.trim())){Z(`grant`);try{await oe(e,q.trim(),Y),J(``),Q(),y({title:`Shared`,description:`Access granted to ${q.trim()}`})}catch(e){y({title:`Error`,description:e instanceof Error?e.message:`Failed to grant access`,variant:`destructive`})}finally{Z(null)}}},xe=async t=>{if(e&&window.confirm(`Revoke ${t.userEmail}'s access to "${e}"?`)){Z(t.userEmail);try{await le(e,t.userEmail),Q(),y({title:`Revoked`,description:`${t.userEmail} no longer has access`})}catch(e){y({title:`Error`,description:e instanceof Error?e.message:`Failed to revoke access`,variant:`destructive`})}finally{Z(null)}}};if(pe)return(0,h.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:`Loading...`});if(!E)return(0,h.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:`Context not found`});let $=de.find(e=>e.id===w),Se=`/contexts/${e}${T}`;return(0,h.jsx)(`div`,{className:`h-full min-h-0 overflow-y-auto`,children:(0,h.jsxs)(`div`,{className:`mx-auto max-w-3xl p-6 pb-12 max-md:px-4 max-md:pb-rail-stack`,children:[(0,h.jsx)(fe,{compact:!0,className:`mb-6 border-b pb-4`,title:`${$.label} - ${E.name||E.id}`,description:$.description,backTo:Se,onBack:C?x:void 0}),w===`general`&&(0,h.jsxs)(`div`,{className:`space-y-6`,children:[(0,h.jsxs)(`form`,{onSubmit:_e,className:`space-y-4 rounded-lg border p-4`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{className:`text-sm font-medium`,children:`Context ID`}),(0,h.jsx)(`div`,{className:`mt-1 flex h-10 items-center rounded-md bg-muted px-3 font-mono text-sm text-muted-foreground`,children:E.id})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`ctx-name`,className:`text-sm font-medium`,children:`Name`}),(0,h.jsx)(l,{id:`ctx-name`,value:M,onChange:e=>N(e.target.value),placeholder:`My Context`})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`ctx-description`,className:`text-sm font-medium`,children:`Description`}),(0,h.jsx)(l,{id:`ctx-description`,value:P,onChange:e=>F(e.target.value),placeholder:`Optional description`})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`ctx-color`,className:`text-sm font-medium`,children:`Color`}),(0,h.jsxs)(`div`,{className:`mt-1 flex items-center gap-2`,children:[(0,h.jsx)(l,{id:`ctx-color`,type:`color`,value:/^#[0-9a-f]{6}$/i.test(I||E.color||``)?I||E.color:`#808080`,onChange:e=>L(e.target.value),className:`h-10 w-16 p-1`,disabled:O}),(0,h.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,disabled:O||I===null,onClick:()=>L(null),children:`Use inherited color`})]}),(0,h.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:I===null?`Using the tree folder or workspace color.`:`Applies only to this context.`})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{className:`text-sm font-medium`,children:`Workspace`}),(0,h.jsx)(`div`,{className:`mt-1 flex h-10 items-center rounded-md bg-muted px-3 text-sm text-muted-foreground`,children:E.workspaceName||E.workspaceId||E.workspace})]}),(0,h.jsx)(c,{type:`submit`,disabled:O,children:O?`Saving...`:`Save Changes`})]}),(0,h.jsxs)(`section`,{className:`rounded-lg border border-destructive/30 p-4`,children:[(0,h.jsx)(`h2`,{className:`mb-3 text-sm font-semibold text-destructive`,children:`Danger Zone`}),(0,h.jsxs)(c,{variant:`destructive`,disabled:A,onClick:ye,children:[(0,h.jsx)(a,{className:`mr-2 h-4 w-4`}),A?`Deleting...`:`Delete Context`]})]})]}),w===`location`&&(0,h.jsxs)(`form`,{onSubmit:ve,className:`space-y-4 rounded-lg border p-4`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`ctx-url`,className:`text-sm font-medium`,children:`URL`}),(0,h.jsx)(f,{id:`ctx-url`,value:R,onChange:z,fixedWorkspaceName:E.workspaceName,pickerTitle:`Switch context to…`,placeholder:`workspace://path`,onPickTarget:(e,t)=>{z(`${t.workspaceName}://${e.replace(/^\/+/,``)}`),he(t.treeName)}}),H&&(0,h.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Destination tree: `,H]})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`label`,{htmlFor:`ctx-base-url`,className:`text-sm font-medium`,children:[`Base URL `,(0,h.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional)`})]}),(0,h.jsx)(f,{id:`ctx-base-url`,value:B,onChange:V,fixedWorkspaceName:E.workspaceName,placeholder:`workspace://base/path`,pickerTitle:`Pick a base path…`})]}),(0,h.jsx)(c,{type:`submit`,disabled:O,children:O?`Saving...`:`Save Changes`})]}),w===`shares`&&(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`h2`,{className:`text-sm font-semibold`,children:`People with access`}),(0,h.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Only the context owner can see and change this list.`})]}),(0,h.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>Q(),disabled:G,children:[(0,h.jsx)(o,{className:s(`mr-2 h-3.5 w-3.5`,G&&`animate-spin`)}),`Refresh`]})]}),U.length===0?(0,h.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`Not shared with anyone.`}):U.map(e=>(0,h.jsxs)(`div`,{className:`flex items-start justify-between gap-3 rounded-md border p-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`div`,{className:`truncate text-sm font-medium`,children:e.userEmail}),(0,h.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[g.find(t=>t.value===e.accessLevel)?.label||e.accessLevel||`unknown access`,e.sharedAt&&` - since ${new Date(e.sharedAt).toLocaleDateString()}`]})]}),(0,h.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,className:`text-destructive hover:text-destructive`,disabled:X===e.userEmail,onClick:()=>xe(e),children:(0,h.jsx)(te,{className:`h-3.5 w-3.5`})})]},e.userEmail))]}),(0,h.jsxs)(`form`,{onSubmit:be,className:`space-y-4 rounded-lg border p-4`,children:[(0,h.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Grant access`}),(0,h.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`share-email`,className:`text-sm font-medium`,children:`User email`}),(0,h.jsx)(l,{id:`share-email`,type:`email`,value:q,onChange:e=>J(e.target.value),placeholder:`person@example.com`}),(0,h.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`The user must already have an account on this server.`})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{htmlFor:`share-level`,className:`text-sm font-medium`,children:`Access level`}),(0,h.jsx)(`select`,{id:`share-level`,value:Y,onChange:e=>ge(e.target.value),className:`mt-1 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring`,children:g.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,h.jsx)(c,{type:`submit`,disabled:X===`grant`||!q.trim(),children:X===`grant`?`Sharing...`:`Share context`})]})]})]})})}export{_ as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as ee}from"./chunk-62JRHF6Z-vspAGgtK.js";import{X as i}from"./ui-DEgHnkQu.js";import{t as a}from"./button--VYZekMF.js";import{t as o}from"./input-BOtCd4HP.js";import{n as te}from"./use-toast-BlLDqSUO.js";import{jt as ne}from"./workspace-4hWrSEku.js";import{t as re}from"./use-mobile-Db-vWu9Y.js";import{p as ie}from"./context-DY40EDc6.js";import{t as s}from"./color-DFEH4BfK.js";import{i as ae}from"./use-menu-CKSpS96u.js";import{K as oe,Q as se,St as ce,U as le,X as ue,Z as de,et as fe,it as pe,nt as me,q as he,rt as ge,st as _e,tt as ve,yt as ye}from"./index-CTvqbEB8.js";import{n as be}from"./page-header-NyYSXjfY.js";import{n as xe,r as Se,t as Ce}from"./useAgentModels-CI9XT6yc.js";var c=e(n(),1),l=t(),we={anthropic:`claude-3-5-sonnet-20241022`,openai:`gpt-4o`,ollama:`qwen2.5-coder:latest`,"lm-studio":``,vllm:``,custom:``},u={anthropic:`https://api.anthropic.com`,openai:`https://api.openai.com/v1`,ollama:`http://localhost:11434/v1`,"lm-studio":`http://localhost:1234/v1`,vllm:`http://localhost:8000/v1`,custom:``};function d(e){return u[e]||``}function f({label:e,hint:t,children:n}){return(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`label`,{className:`text-sm font-medium`,children:e}),t&&(0,l.jsx)(`p`,{className:`mb-1 mt-0.5 text-xs text-muted-foreground`,children:t}),(0,l.jsx)(`div`,{className:t?void 0:`mt-1`,children:n})]})}var p=`w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring resize-y`,m=`w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring`;function h(){let{agentId:e,tab:t}=r(),n=ee(),{showToast:u}=te(),{selectEntity:h,goBack:Te}=ae(),Ee=re(),g=ce(t);(0,c.useEffect)(()=>{t!==g&&e&&n(`/agents/${encodeURIComponent(e)}/settings/${g}`,{replace:!0})},[t,g,e,n]);let[_,v]=(0,c.useState)(null),[De,Oe]=(0,c.useState)(!0),[ke,Ae]=(0,c.useState)(null),[je,Me]=(0,c.useState)(!1),[Ne,Pe]=(0,c.useState)(!1),[Fe,Ie]=(0,c.useState)(``),[Le,Re]=(0,c.useState)(``),[ze,Be]=(0,c.useState)(``),[Ve,y]=(0,c.useState)(s()),[b,He]=(0,c.useState)(``),[x,Ue]=(0,c.useState)(``),[S,We]=(0,c.useState)(``),[C,Ge]=(0,c.useState)(``),[w,Ke]=(0,c.useState)(`anthropic`),[T,qe]=(0,c.useState)(``),[E,D]=(0,c.useState)(``),[O,k]=(0,c.useState)(``),[Je,Ye]=(0,c.useState)(.7),[Xe,A]=(0,c.useState)(4096),[Ze,Qe]=(0,c.useState)(1),$e=Ce(w,T,E,_?.id),et=$e.models.find(e=>e.id===O),[tt,j]=(0,c.useState)([]),[M,N]=(0,c.useState)(``),[nt,P]=(0,c.useState)(``),[F,I]=(0,c.useState)(``),[L,R]=(0,c.useState)(``),[rt,it]=(0,c.useState)(!1),[at,ot]=(0,c.useState)(null),[z,B]=(0,c.useState)(null),[st,ct]=(0,c.useState)(null),[V,H]=(0,c.useState)(!1),[U,W]=(0,c.useState)(null),[G,K]=(0,c.useState)(``),[q,J]=(0,c.useState)(!1),[Y,lt]=(0,c.useState)(`context`),[X,ut]=(0,c.useState)(``),[dt,ft]=(0,c.useState)(`/`),[Z,pt]=(0,c.useState)(``),[mt,ht]=(0,c.useState)(!0),[Q,gt]=(0,c.useState)(!1),[_t,vt]=(0,c.useState)([]),[yt,bt]=(0,c.useState)([]),[$,xt]=(0,c.useState)(null),[St,Ct]=(0,c.useState)(`{}`),[wt,Tt]=(0,c.useState)(null),[Et,Dt]=(0,c.useState)(e);Et!==e&&(Dt(e),Oe(!0),v(null)),(0,c.useEffect)(()=>{if(!e)return;let t=!1;return oe(e).then(async e=>{if(t)return;let n=e.config?.identity||{};v(e),h(e.id),Ie(e.name||``),Re(e.label||``),Be(e.description||``),y(e.color||s()),He(n.role||``),Ue(n.identity||``),We(n.instructions||``),Ge(e.config?.prompts?.system||``),Ke(e.llmProvider||`anthropic`),qe(e.config?.apiKey||``),D(e.config?.baseUrl||d(e.llmProvider)),k(e.model||we[e.llmProvider]||``);let r=e.config?.connectors?.[e.llmProvider];r&&(Ye(r.temperature??.7),A(r.maxTokens??4096),Qe(r.topP??1)),Ct(JSON.stringify(e.config?.tools??{},null,2)),Tt(null),Ae(null);try{j(await se(e.id))}catch{j([])}}).catch(e=>{t||Ae(e instanceof Error?e.message:`Failed to load agent`)}).finally(()=>{t||Oe(!1)}),()=>{t=!0}},[e,h]),(0,c.useEffect)(()=>{if(g!==`access`&&g!==`tools`||!_?.id)return;let e=_.id,t=!1;return Promise.all([he(_.id).catch(()=>null),ne().catch(()=>[]),ie().catch(()=>[]),ue(_.id).catch(()=>null)]).then(([n,r,ee,i])=>{t||(B(n),vt(r),bt(ee),xt(i?i.tools:[]),ct(e))}),()=>{t=!0}},[g,_?.id]);let Ot=()=>{let e=Se(b,x,S),t;try{let e=JSON.parse(St);e&&typeof e==`object`&&!Array.isArray(e)&&(t=e)}catch{}return{...t===void 0?{}:{tools:t},name:Fe.trim(),label:Le.trim(),description:ze.trim()||void 0,color:Ve,llmProvider:w,model:O,apiKey:T.trim()||(w===_?.llmProvider?void 0:``),baseUrl:E||void 0,config:{type:w,model:O,identity:{role:b.trim()||void 0,identity:x.trim()||void 0,instructions:S.trim()||void 0},prompts:C.trim()||e?{system:C.trim()||e}:void 0,connectors:{[w]:{...w===`anthropic`?{}:{temperature:Je},maxTokens:Xe,topP:Ze}}}}},kt=async e=>{if(e.preventDefault(),_){Me(!0);try{let e=await _e(_.id,Ot());v(e),window.dispatchEvent(new CustomEvent(`agents:refresh`)),u({title:`Saved`,description:`Agent updated`}),e.name&&e.name!==_.name&&n(`/agents/${encodeURIComponent(e.name)}/settings/${g}`,{replace:!0})}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Save failed`,variant:`destructive`})}finally{Me(!1)}}},At=async()=>{if(_&&window.confirm(`Delete agent "${_.label||_.name}"? This cannot be undone.`)){Pe(!0);try{await le(_.id),window.dispatchEvent(new CustomEvent(`agents:refresh`)),u({title:`Deleted`,description:`Agent removed`}),n(`/agents`)}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Delete failed`,variant:`destructive`})}finally{Pe(!1)}}},jt=()=>{N(``),P(``),I(``),R(``)},Mt=async()=>{if(!(!_||!L.trim()&&!F.trim())){it(!0);try{let e=await de(_.id,L.trim()?{source:L.trim()}:{name:M,description:nt,content:F});j(e),jt(),window.dispatchEvent(new CustomEvent(`agents:refresh`)),u({title:`Installed`,description:`Skill saved`})}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Skill install failed`,variant:`destructive`})}finally{it(!1)}}},Nt=async e=>{if(_){ot(e);try{let t=await fe(_.id,e);j(t),(M===e||L===e)&&jt(),window.dispatchEvent(new CustomEvent(`agents:refresh`)),u({title:`Removed`,description:`Skill "${e}" removed`})}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Skill remove failed`,variant:`destructive`})}finally{ot(null)}}},Pt=()=>Y===`global`?{type:`global`}:Y===`context`?Z?{type:`context`,context:Z}:null:X?Y===`path`?{type:`path`,workspace:X,path:dt.trim()||`/`}:{type:`workspace`,workspace:X}:null,Ft=async()=>{if(!_||V)return;let e=Pt(),t=[];if(mt&&t.push(`read`),Q&&t.push(`write`),!e||!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(G.trim())||t.length===0||!q&&z?.grants.some(e=>e.id===G.trim())){u({title:`Invalid binding`,description:`Choose a unique connection name (letters, numbers, hyphens or underscores), scope and permissions`,variant:`destructive`});return}if(!(e.type===`global`&&!window.confirm(`Global scope lets this agent ${Q?`read and write`:`read`} ALL your workspaces. Continue?`))){H(!0);try{let n=await pe(_.id,G.trim(),{label:z?.grants.find(e=>e.id===G.trim())?.label||G.trim(),binding:e,permissions:t});B(n.access),W(n.tokens[0]?.token??null),K(``),J(!1),u({title:`Connection saved`,description:`Other connections and their tokens are unchanged`})}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Bind failed`,variant:`destructive`})}finally{H(!1)}}},It=async e=>{if(!(!_||V)){H(!0);try{let t=await ge(_.id,e);B(t.access),W(t.tokens[0]?.token??null),u({title:`Rotated`,description:`New token minted — the previous one no longer works`})}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Rotate failed`,variant:`destructive`})}finally{H(!1)}}},Lt=e=>{K(e.id),J(!0),lt(e.binding.type),ut(e.binding.workspace||``),ft(e.binding.path||`/`),pt(e.binding.context||``),ht(e.permissions.includes(`read`)),gt(e.permissions.includes(`write`))},Rt=async e=>{if(!(!_||V)){H(!0);try{let t=await me(_.id,e);B(t.access),W(null),G===e&&(K(``),J(!1))}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Revoke failed`,variant:`destructive`})}finally{H(!1)}}},zt=async()=>{if(!(!_||V)&&window.confirm(`Revoke this agent's canvas access? All its connection tokens stop working immediately.`)){H(!0);try{await ve(_.id),B(null),W(null),u({title:`Revoked`,description:`Agent access removed`})}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Revoke failed`,variant:`destructive`})}finally{H(!1)}}},Bt=e=>{if(e.type===`global`)return`Global — all workspaces`;if(e.type===`context`){let t=yt.find(t=>t.id===e.context);return`Context ${t?`${t.id} (${t.url})`:e.context} — follows the context live`}let t=e.workspaceName||e.workspace;return e.type===`path`?`Workspace ${t}, path ${e.path||`/`}`:`Workspace ${t} (whole tree)`};if(De)return(0,l.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:`Loading...`});if(!_||ke)return(0,l.jsx)(`div`,{className:`p-6 text-sm text-destructive`,children:ke||`Agent not found`});let Vt=ye.find(e=>e.id===g),Ht=encodeURIComponent(_.name||_.id),Ut=g===`identity`||g===`provider`||g===`models`||g===`tools`;return(0,l.jsx)(`div`,{className:`h-full min-h-0 overflow-y-auto`,children:(0,l.jsxs)(`div`,{className:`mx-auto max-w-5xl p-6 pb-12 max-md:px-4 max-md:pb-rail-stack`,children:[(0,l.jsx)(be,{compact:!0,className:`mb-6 border-b pb-4`,title:`${Vt.label} - ${_.label||_.name}`,description:Vt.description,backTo:`/agents/${Ht}`,onBack:Ee?Te:void 0}),(0,l.jsxs)(`form`,{onSubmit:kt,className:`space-y-6`,children:[g===`identity`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,l.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,l.jsx)(f,{label:`Name`,hint:`ID: ${_.id}`,children:(0,l.jsx)(o,{value:Fe,onChange:e=>Ie(e.target.value),placeholder:`lucy`})}),(0,l.jsx)(f,{label:`Label`,children:(0,l.jsx)(o,{value:Le,onChange:e=>Re(e.target.value),placeholder:`Display name`})})]}),(0,l.jsx)(f,{label:`Description`,children:(0,l.jsx)(o,{value:ze,onChange:e=>Be(e.target.value),placeholder:`Short description`})}),(0,l.jsx)(f,{label:`Color`,children:(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(o,{type:`color`,value:Ve,onChange:e=>y(e.target.value),className:`h-10 w-16 p-1`}),(0,l.jsx)(a,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>y(s()),children:`Randomize`})]})})]}),(0,l.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Persona`}),(0,l.jsx)(f,{label:`Role`,children:(0,l.jsx)(o,{value:b,onChange:e=>He(e.target.value),placeholder:`e.g. Software Engineer`})}),(0,l.jsx)(f,{label:`Identity`,children:(0,l.jsx)(`textarea`,{value:x,onChange:e=>Ue(e.target.value),placeholder:`Who this agent is…`,className:`${p} min-h-[80px]`})}),(0,l.jsx)(f,{label:`Instructions`,children:(0,l.jsx)(`textarea`,{value:S,onChange:e=>We(e.target.value),placeholder:`Behavioral instructions…`,className:`${p} min-h-[80px]`})}),(0,l.jsx)(f,{label:`System Prompt`,hint:`Compiled from Role + Identity + Instructions. Override manually.`,children:(0,l.jsx)(`textarea`,{value:C,onChange:e=>Ge(e.target.value),placeholder:`System prompt sent to the LLM…`,className:`${p} min-h-[140px] font-mono text-xs`})})]}),(0,l.jsxs)(`section`,{className:`rounded-lg border border-destructive/30 p-4`,children:[(0,l.jsx)(`h2`,{className:`mb-3 text-sm font-semibold text-destructive`,children:`Danger Zone`}),(0,l.jsxs)(a,{type:`button`,variant:`destructive`,disabled:Ne,onClick:At,children:[(0,l.jsx)(i,{className:`mr-2 h-4 w-4`}),Ne?`Deleting...`:`Delete Agent`]})]})]}),g===`provider`&&(0,l.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,l.jsx)(f,{label:`Provider`,children:(0,l.jsxs)(`select`,{value:w,onChange:e=>{let t=e.target.value;Ke(t),qe(``),k(we[t]||``),D(d(t))},className:`w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring`,children:[(0,l.jsx)(`option`,{value:`anthropic`,children:`Anthropic Claude`}),(0,l.jsx)(`option`,{value:`openai`,children:`OpenAI GPT`}),(0,l.jsx)(`option`,{value:`ollama`,children:`Ollama (Local)`}),(0,l.jsx)(`option`,{value:`lm-studio`,children:`LM Studio (Local)`}),(0,l.jsx)(`option`,{value:`vllm`,children:`vLLM (Local)`}),(0,l.jsx)(`option`,{value:`custom`,children:`Custom`})]})}),(0,l.jsx)(f,{label:`API Key`,hint:[`ollama`,`lm-studio`,`vllm`].includes(w)?`Any value works for local providers.`:void 0,children:(0,l.jsx)(o,{type:`password`,value:T,onChange:e=>qe(e.target.value),placeholder:w===`ollama`?`ollama`:w===`lm-studio`?`lm-studio`:`sk-…`})}),(0,l.jsx)(f,{label:`Host / Base URL`,children:(0,l.jsx)(o,{value:E,onChange:e=>D(e.target.value),placeholder:d(w)||`https://api.example.com`})})]}),g===`models`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Main Model`}),(0,l.jsx)(f,{label:`Model`,children:(0,l.jsx)(xe,{value:O,onChange:(e,t)=>{k(e),t?.maxTokens&&A(t.maxTokens)},...$e})}),(0,l.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-3`,children:[w!==`anthropic`&&(0,l.jsx)(f,{label:`Temperature`,children:(0,l.jsx)(o,{type:`number`,min:0,max:2,step:.1,value:Je,onChange:e=>Ye(Number.isNaN(e.target.valueAsNumber)?.7:e.target.valueAsNumber)})}),(0,l.jsx)(f,{label:`Max Output Tokens`,children:(0,l.jsx)(o,{type:`number`,min:1,max:et?.maxTokens,value:Xe,onChange:e=>A(parseInt(e.target.value)||4096)})}),(0,l.jsx)(f,{label:`Top P`,children:(0,l.jsx)(o,{type:`number`,min:0,max:1,step:.1,value:Ze,onChange:e=>Qe(Number.isNaN(e.target.valueAsNumber)?1:e.target.valueAsNumber)})})]})]}),[`Governance`,`Memory Management`,`Subagent / Tool Use`].map(e=>(0,l.jsxs)(`section`,{className:`rounded-lg border border-dashed p-4`,children:[(0,l.jsxs)(`h2`,{className:`text-sm font-semibold text-muted-foreground`,children:[e,` Model`]}),(0,l.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Coming soon`})]},e))]}),g===`tools`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Runtime Tools`}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Injected at start (pi defineTool): coding tools plus canvas tools scoped by the token binding (Access / ACL). Definitions live in the runtime — read-only here until the agent-runtime workspace lands.`})]}),$===null?(0,l.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`Loading…`}):$.length===0?(0,l.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`No tools resolved.`}):(0,l.jsx)(`div`,{className:`space-y-1.5`,children:$.map(e=>(0,l.jsxs)(`details`,{className:`rounded-md border px-3 py-2`,children:[(0,l.jsxs)(`summary`,{className:`cursor-pointer text-sm`,children:[(0,l.jsx)(`code`,{className:`font-mono text-xs font-medium`,children:e.name}),(0,l.jsx)(`span`,{className:`ml-2 rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,children:e.source})]}),e.description&&(0,l.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap text-xs text-muted-foreground`,children:e.description}),e.parameters!=null&&(0,l.jsx)(`pre`,{className:`mt-2 overflow-x-auto rounded bg-muted p-2 font-mono text-[11px]`,children:JSON.stringify(e.parameters,null,2)})]},e.name))}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:z?z.grants.map(e=>`${e.label}: ${Bt(e.binding)}`).join(`; `):`Unbound — no canvas tools are injected. Bind under Access / ACL.`})]}),(0,l.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Tools Config`}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`config.tools JSON, merged server-side — e.g. {"canvas": {"enabled": false}} gates the canvas tools. Saved with Save Changes.`})]}),(0,l.jsx)(`textarea`,{value:St,onChange:e=>{Ct(e.target.value);try{JSON.parse(e.target.value),Tt(null)}catch(e){Tt(e instanceof Error?e.message:`Invalid JSON`)}},className:`${p} min-h-[120px] font-mono text-xs`}),wt&&(0,l.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Invalid JSON (not saved): `,wt]})]}),(0,l.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Skills`}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Installed skills are saved immediately, independent of Save Changes.`})]}),tt.length===0?(0,l.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`No skills installed.`}):tt.map(e=>(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-3 rounded-md border p-3`,children:[(0,l.jsxs)(`div`,{className:`min-w-0`,children:[(0,l.jsx)(`div`,{className:`truncate text-sm font-medium`,children:e.name}),(0,l.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.package?e.source:e.description||`No description`})]}),(0,l.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,l.jsx)(a,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{N(e.name),P(e.description||``),I(e.content||``),R(e.source||``)},children:`Edit`}),(0,l.jsx)(a,{type:`button`,variant:`destructive`,size:`sm`,disabled:at===(e.source||e.name),onClick:()=>Nt(e.source||e.name),children:at===(e.source||e.name)?`Removing…`:`Remove`})]})]},e.name)),(0,l.jsxs)(`div`,{className:`space-y-4 rounded-md border p-4`,children:[(0,l.jsx)(f,{label:`Package Source`,hint:`Use this for whole pi packages. Leave empty to save inline SKILL.md content.`,children:(0,l.jsx)(o,{value:L,onChange:e=>R(e.target.value),placeholder:`npm:@foo/pi-tools or git:github.com/badlogic/pi-doom`})}),(0,l.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,l.jsx)(f,{label:`Name`,children:(0,l.jsx)(o,{value:M,onChange:e=>N(e.target.value),placeholder:`skill-name, or read from frontmatter`,disabled:!!L.trim()})}),(0,l.jsx)(f,{label:`Description`,children:(0,l.jsx)(o,{value:nt,onChange:e=>P(e.target.value),placeholder:`What this skill helps with`,disabled:!!L.trim()})})]}),(0,l.jsx)(f,{label:`SKILL.md Content`,children:(0,l.jsx)(`textarea`,{value:F,onChange:e=>I(e.target.value),placeholder:`# Skill instructions…`,disabled:!!L.trim(),className:`${p} min-h-[160px] font-mono text-xs`})}),(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(a,{type:`button`,disabled:rt||!L.trim()&&!F.trim(),onClick:Mt,children:rt?`Saving…`:`Install / Update Skill`}),(0,l.jsx)(a,{type:`button`,variant:`outline`,onClick:jt,children:`Clear`})]})]})]}),(0,l.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`MCP Servers`}),(_.config?.mcp?.servers||[]).length===0?(0,l.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`No MCP servers configured.`}):(_.config?.mcp?.servers||[]).map((e,t)=>(0,l.jsxs)(`div`,{className:`rounded-md border p-3`,children:[(0,l.jsx)(`div`,{className:`text-sm font-medium`,children:e.name}),(0,l.jsxs)(`div`,{className:`font-mono text-xs text-muted-foreground`,children:[e.command,` `,(e.args||[]).join(` `)]})]},t))]})]}),g===`access`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Canvas Access`}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Add named connections to workspaces, paths or contexts, with permissions for each. Every connection has its own scoped token. Overlapping grants are additive: a whole-workspace grant is not restricted by a context on that workspace.`})]}),st===_.id?z?(0,l.jsxs)(`div`,{className:`space-y-2`,children:[z.grants.map(e=>(0,l.jsxs)(`div`,{className:`space-y-2 rounded-md border p-3`,children:[(0,l.jsx)(`div`,{className:`text-sm font-medium`,children:e.label||e.id}),(0,l.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:Bt(e.binding)}),(0,l.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`Permissions: `,e.permissions.join(`, `)]}),(0,l.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,l.jsx)(a,{type:`button`,variant:`outline`,size:`sm`,disabled:V,onClick:()=>Lt(e),children:`Edit`}),(0,l.jsx)(a,{type:`button`,variant:`outline`,size:`sm`,disabled:V,onClick:()=>It(e.id),children:`Rotate Token`}),(0,l.jsx)(a,{type:`button`,variant:`destructive`,size:`sm`,disabled:V,onClick:()=>Rt(e.id),children:`Remove`})]})]},e.id)),(0,l.jsx)(a,{type:`button`,variant:`destructive`,size:`sm`,disabled:V,onClick:zt,children:`Revoke All Access`})]}):(0,l.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`Unbound — this agent has no canvas access.`}):(0,l.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`Loading…`}),U&&(0,l.jsxs)(`div`,{className:`space-y-2 rounded-md border border-warning/50 bg-warning/10 p-3`,children:[(0,l.jsx)(`div`,{className:`text-xs font-medium`,children:`Agent token — shown once, store it now`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`code`,{className:`flex-1 truncate rounded bg-background px-2 py-1 font-mono text-xs`,children:U}),(0,l.jsx)(a,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>navigator.clipboard?.writeText(U),children:`Copy`}),(0,l.jsx)(a,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>W(null),children:`Dismiss`})]}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Managed agents receive their connections automatically. External runtimes use the CANVAS_CONNECTIONS JSON array.`})]})]}),(0,l.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:q?`Edit Connection`:`Add Connection`}),(0,l.jsx)(f,{label:`Connection name`,hint:`Agents use this name to select the scope for each tool call.`,children:(0,l.jsx)(o,{value:G,disabled:q,onChange:e=>K(e.target.value),placeholder:`bar, baz, baf`})}),(0,l.jsx)(f,{label:`Scope`,hint:`Context bindings follow the context live; global spans all workspaces.`,children:(0,l.jsxs)(`select`,{value:Y,onChange:e=>lt(e.target.value),className:m,children:[(0,l.jsx)(`option`,{value:`context`,children:`Context (follows live)`}),(0,l.jsx)(`option`,{value:`workspace`,children:`Workspace`}),(0,l.jsx)(`option`,{value:`path`,children:`Workspace path`}),(0,l.jsx)(`option`,{value:`global`,children:`Global (all workspaces)`})]})}),Y===`context`&&(0,l.jsx)(f,{label:`Context`,children:(0,l.jsxs)(`select`,{value:Z,onChange:e=>pt(e.target.value),className:m,children:[(0,l.jsx)(`option`,{value:``,children:`Select a context…`}),yt.map(e=>(0,l.jsxs)(`option`,{value:e.id,children:[e.id,` — `,e.url]},e.id))]})}),(Y===`workspace`||Y===`path`)&&(0,l.jsx)(f,{label:`Workspace`,children:(0,l.jsxs)(`select`,{value:X,onChange:e=>ut(e.target.value),className:m,children:[(0,l.jsx)(`option`,{value:``,children:`Select a workspace…`}),_t.map(e=>(0,l.jsx)(`option`,{value:e.name||e.id,children:e.label||e.name},e.id))]})}),Y===`path`&&(0,l.jsx)(f,{label:`Base path`,hint:`The agent is clamped to this subtree.`,children:(0,l.jsx)(o,{value:dt,onChange:e=>ft(e.target.value),placeholder:`/work/projects/foo`})}),(0,l.jsx)(f,{label:`Permissions`,children:(0,l.jsxs)(`div`,{className:`flex gap-4 text-sm`,children:[(0,l.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`input`,{type:`checkbox`,checked:mt,onChange:e=>ht(e.target.checked)}),` read`]}),(0,l.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`input`,{type:`checkbox`,checked:Q,onChange:e=>gt(e.target.checked)}),` write`]})]})}),(0,l.jsx)(a,{type:`button`,disabled:V,onClick:Ft,children:V?`Working…`:q?`Save Connection`:`Add Connection`}),q&&(0,l.jsx)(a,{type:`button`,variant:`outline`,onClick:()=>{K(``),J(!1)},children:`Cancel Edit`})]})]}),g===`memory`&&(0,l.jsxs)(`section`,{className:`rounded-lg border border-dashed p-6 text-center`,children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold text-muted-foreground`,children:`Memory Engine`}),(0,l.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Loop-based memory management. Settings coming soon.`})]}),g===`integrations`&&(0,l.jsxs)(`section`,{className:`rounded-lg border border-dashed p-6 text-center`,children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold text-muted-foreground`,children:`Integrations`}),(0,l.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`IMAP, chat, SQL and REST API accounts. Coming soon.`})]}),Ut&&(0,l.jsx)(a,{type:`submit`,disabled:je,children:je?`Saving…`:`Save Changes`})]})]})})}export{h as default};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as ee}from"./chunk-62JRHF6Z-vspAGgtK.js";import{X as i}from"./ui-DEgHnkQu.js";import{t as a}from"./button--VYZekMF.js";import{t as o}from"./input-BOtCd4HP.js";import{n as te}from"./use-toast-BlLDqSUO.js";import{jt as ne}from"./workspace-4hWrSEku.js";import{t as re}from"./use-mobile-Db-vWu9Y.js";import{p as ie}from"./context-DY40EDc6.js";import{t as s}from"./color-DFEH4BfK.js";import{i as ae}from"./use-menu-CKSpS96u.js";import{K as oe,Q as se,St as ce,U as le,X as ue,Z as de,et as fe,it as pe,nt as me,q as he,rt as ge,st as _e,tt as ve,yt as ye}from"./index-NOhHv2VY.js";import{n as be}from"./page-header-NyYSXjfY.js";import{n as xe,r as Se,t as Ce}from"./useAgentModels-DTZNaSRA.js";var c=e(n(),1),l=t(),we={anthropic:`claude-3-5-sonnet-20241022`,openai:`gpt-4o`,ollama:`qwen2.5-coder:latest`,"lm-studio":``,vllm:``,custom:``},u={anthropic:`https://api.anthropic.com`,openai:`https://api.openai.com/v1`,ollama:`http://localhost:11434/v1`,"lm-studio":`http://localhost:1234/v1`,vllm:`http://localhost:8000/v1`,custom:``};function d(e){return u[e]||``}function f({label:e,hint:t,children:n}){return(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`label`,{className:`text-sm font-medium`,children:e}),t&&(0,l.jsx)(`p`,{className:`mb-1 mt-0.5 text-xs text-muted-foreground`,children:t}),(0,l.jsx)(`div`,{className:t?void 0:`mt-1`,children:n})]})}var p=`w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring resize-y`,m=`w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring`;function h(){let{agentId:e,tab:t}=r(),n=ee(),{showToast:u}=te(),{selectEntity:h,goBack:Te}=ae(),Ee=re(),g=ce(t);(0,c.useEffect)(()=>{t!==g&&e&&n(`/agents/${encodeURIComponent(e)}/settings/${g}`,{replace:!0})},[t,g,e,n]);let[_,v]=(0,c.useState)(null),[De,Oe]=(0,c.useState)(!0),[ke,Ae]=(0,c.useState)(null),[je,Me]=(0,c.useState)(!1),[Ne,Pe]=(0,c.useState)(!1),[Fe,Ie]=(0,c.useState)(``),[Le,Re]=(0,c.useState)(``),[ze,Be]=(0,c.useState)(``),[Ve,y]=(0,c.useState)(s()),[b,He]=(0,c.useState)(``),[x,Ue]=(0,c.useState)(``),[S,We]=(0,c.useState)(``),[C,Ge]=(0,c.useState)(``),[w,Ke]=(0,c.useState)(`anthropic`),[T,qe]=(0,c.useState)(``),[E,D]=(0,c.useState)(``),[O,k]=(0,c.useState)(``),[Je,Ye]=(0,c.useState)(.7),[Xe,A]=(0,c.useState)(4096),[Ze,Qe]=(0,c.useState)(1),$e=Ce(w,T,E,_?.id),et=$e.models.find(e=>e.id===O),[tt,j]=(0,c.useState)([]),[M,N]=(0,c.useState)(``),[nt,P]=(0,c.useState)(``),[F,I]=(0,c.useState)(``),[L,R]=(0,c.useState)(``),[rt,it]=(0,c.useState)(!1),[at,ot]=(0,c.useState)(null),[z,B]=(0,c.useState)(null),[st,ct]=(0,c.useState)(null),[V,H]=(0,c.useState)(!1),[U,W]=(0,c.useState)(null),[G,K]=(0,c.useState)(``),[q,J]=(0,c.useState)(!1),[Y,lt]=(0,c.useState)(`context`),[X,ut]=(0,c.useState)(``),[dt,ft]=(0,c.useState)(`/`),[Z,pt]=(0,c.useState)(``),[mt,ht]=(0,c.useState)(!0),[Q,gt]=(0,c.useState)(!1),[_t,vt]=(0,c.useState)([]),[yt,bt]=(0,c.useState)([]),[$,xt]=(0,c.useState)(null),[St,Ct]=(0,c.useState)(`{}`),[wt,Tt]=(0,c.useState)(null),[Et,Dt]=(0,c.useState)(e);Et!==e&&(Dt(e),Oe(!0),v(null)),(0,c.useEffect)(()=>{if(!e)return;let t=!1;return oe(e).then(async e=>{if(t)return;let n=e.config?.identity||{};v(e),h(e.id),Ie(e.name||``),Re(e.label||``),Be(e.description||``),y(e.color||s()),He(n.role||``),Ue(n.identity||``),We(n.instructions||``),Ge(e.config?.prompts?.system||``),Ke(e.llmProvider||`anthropic`),qe(e.config?.apiKey||``),D(e.config?.baseUrl||d(e.llmProvider)),k(e.model||we[e.llmProvider]||``);let r=e.config?.connectors?.[e.llmProvider];r&&(Ye(r.temperature??.7),A(r.maxTokens??4096),Qe(r.topP??1)),Ct(JSON.stringify(e.config?.tools??{},null,2)),Tt(null),Ae(null);try{j(await se(e.id))}catch{j([])}}).catch(e=>{t||Ae(e instanceof Error?e.message:`Failed to load agent`)}).finally(()=>{t||Oe(!1)}),()=>{t=!0}},[e,h]),(0,c.useEffect)(()=>{if(g!==`access`&&g!==`tools`||!_?.id)return;let e=_.id,t=!1;return Promise.all([he(_.id).catch(()=>null),ne().catch(()=>[]),ie().catch(()=>[]),ue(_.id).catch(()=>null)]).then(([n,r,ee,i])=>{t||(B(n),vt(r),bt(ee),xt(i?i.tools:[]),ct(e))}),()=>{t=!0}},[g,_?.id]);let Ot=()=>{let e=Se(b,x,S),t;try{let e=JSON.parse(St);e&&typeof e==`object`&&!Array.isArray(e)&&(t=e)}catch{}return{...t===void 0?{}:{tools:t},name:Fe.trim(),label:Le.trim(),description:ze.trim()||void 0,color:Ve,llmProvider:w,model:O,apiKey:T.trim()||(w===_?.llmProvider?void 0:``),baseUrl:E||void 0,config:{type:w,model:O,identity:{role:b.trim()||void 0,identity:x.trim()||void 0,instructions:S.trim()||void 0},prompts:C.trim()||e?{system:C.trim()||e}:void 0,connectors:{[w]:{...w===`anthropic`?{}:{temperature:Je},maxTokens:Xe,topP:Ze}}}}},kt=async e=>{if(e.preventDefault(),_){Me(!0);try{let e=await _e(_.id,Ot());v(e),window.dispatchEvent(new CustomEvent(`agents:refresh`)),u({title:`Saved`,description:`Agent updated`}),e.name&&e.name!==_.name&&n(`/agents/${encodeURIComponent(e.name)}/settings/${g}`,{replace:!0})}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Save failed`,variant:`destructive`})}finally{Me(!1)}}},At=async()=>{if(_&&window.confirm(`Delete agent "${_.label||_.name}"? This cannot be undone.`)){Pe(!0);try{await le(_.id),window.dispatchEvent(new CustomEvent(`agents:refresh`)),u({title:`Deleted`,description:`Agent removed`}),n(`/agents`)}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Delete failed`,variant:`destructive`})}finally{Pe(!1)}}},jt=()=>{N(``),P(``),I(``),R(``)},Mt=async()=>{if(!(!_||!L.trim()&&!F.trim())){it(!0);try{let e=await de(_.id,L.trim()?{source:L.trim()}:{name:M,description:nt,content:F});j(e),jt(),window.dispatchEvent(new CustomEvent(`agents:refresh`)),u({title:`Installed`,description:`Skill saved`})}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Skill install failed`,variant:`destructive`})}finally{it(!1)}}},Nt=async e=>{if(_){ot(e);try{let t=await fe(_.id,e);j(t),(M===e||L===e)&&jt(),window.dispatchEvent(new CustomEvent(`agents:refresh`)),u({title:`Removed`,description:`Skill "${e}" removed`})}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Skill remove failed`,variant:`destructive`})}finally{ot(null)}}},Pt=()=>Y===`global`?{type:`global`}:Y===`context`?Z?{type:`context`,context:Z}:null:X?Y===`path`?{type:`path`,workspace:X,path:dt.trim()||`/`}:{type:`workspace`,workspace:X}:null,Ft=async()=>{if(!_||V)return;let e=Pt(),t=[];if(mt&&t.push(`read`),Q&&t.push(`write`),!e||!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(G.trim())||t.length===0||!q&&z?.grants.some(e=>e.id===G.trim())){u({title:`Invalid binding`,description:`Choose a unique connection name (letters, numbers, hyphens or underscores), scope and permissions`,variant:`destructive`});return}if(!(e.type===`global`&&!window.confirm(`Global scope lets this agent ${Q?`read and write`:`read`} ALL your workspaces. Continue?`))){H(!0);try{let n=await pe(_.id,G.trim(),{label:z?.grants.find(e=>e.id===G.trim())?.label||G.trim(),binding:e,permissions:t});B(n.access),W(n.tokens[0]?.token??null),K(``),J(!1),u({title:`Connection saved`,description:`Other connections and their tokens are unchanged`})}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Bind failed`,variant:`destructive`})}finally{H(!1)}}},It=async e=>{if(!(!_||V)){H(!0);try{let t=await ge(_.id,e);B(t.access),W(t.tokens[0]?.token??null),u({title:`Rotated`,description:`New token minted — the previous one no longer works`})}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Rotate failed`,variant:`destructive`})}finally{H(!1)}}},Lt=e=>{K(e.id),J(!0),lt(e.binding.type),ut(e.binding.workspace||``),ft(e.binding.path||`/`),pt(e.binding.context||``),ht(e.permissions.includes(`read`)),gt(e.permissions.includes(`write`))},Rt=async e=>{if(!(!_||V)){H(!0);try{let t=await me(_.id,e);B(t.access),W(null),G===e&&(K(``),J(!1))}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Revoke failed`,variant:`destructive`})}finally{H(!1)}}},zt=async()=>{if(!(!_||V)&&window.confirm(`Revoke this agent's canvas access? All its connection tokens stop working immediately.`)){H(!0);try{await ve(_.id),B(null),W(null),u({title:`Revoked`,description:`Agent access removed`})}catch(e){u({title:`Error`,description:e instanceof Error?e.message:`Revoke failed`,variant:`destructive`})}finally{H(!1)}}},Bt=e=>{if(e.type===`global`)return`Global — all workspaces`;if(e.type===`context`){let t=yt.find(t=>t.id===e.context);return`Context ${t?`${t.id} (${t.url})`:e.context} — follows the context live`}let t=e.workspaceName||e.workspace;return e.type===`path`?`Workspace ${t}, path ${e.path||`/`}`:`Workspace ${t} (whole tree)`};if(De)return(0,l.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:`Loading...`});if(!_||ke)return(0,l.jsx)(`div`,{className:`p-6 text-sm text-destructive`,children:ke||`Agent not found`});let Vt=ye.find(e=>e.id===g),Ht=encodeURIComponent(_.name||_.id),Ut=g===`identity`||g===`provider`||g===`models`||g===`tools`;return(0,l.jsx)(`div`,{className:`h-full min-h-0 overflow-y-auto`,children:(0,l.jsxs)(`div`,{className:`mx-auto max-w-5xl p-6 pb-12 max-md:px-4 max-md:pb-rail-stack`,children:[(0,l.jsx)(be,{compact:!0,className:`mb-6 border-b pb-4`,title:`${Vt.label} - ${_.label||_.name}`,description:Vt.description,backTo:`/agents/${Ht}`,onBack:Ee?Te:void 0}),(0,l.jsxs)(`form`,{onSubmit:kt,className:`space-y-6`,children:[g===`identity`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,l.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,l.jsx)(f,{label:`Name`,hint:`ID: ${_.id}`,children:(0,l.jsx)(o,{value:Fe,onChange:e=>Ie(e.target.value),placeholder:`lucy`})}),(0,l.jsx)(f,{label:`Label`,children:(0,l.jsx)(o,{value:Le,onChange:e=>Re(e.target.value),placeholder:`Display name`})})]}),(0,l.jsx)(f,{label:`Description`,children:(0,l.jsx)(o,{value:ze,onChange:e=>Be(e.target.value),placeholder:`Short description`})}),(0,l.jsx)(f,{label:`Color`,children:(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(o,{type:`color`,value:Ve,onChange:e=>y(e.target.value),className:`h-10 w-16 p-1`}),(0,l.jsx)(a,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>y(s()),children:`Randomize`})]})})]}),(0,l.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Persona`}),(0,l.jsx)(f,{label:`Role`,children:(0,l.jsx)(o,{value:b,onChange:e=>He(e.target.value),placeholder:`e.g. Software Engineer`})}),(0,l.jsx)(f,{label:`Identity`,children:(0,l.jsx)(`textarea`,{value:x,onChange:e=>Ue(e.target.value),placeholder:`Who this agent is…`,className:`${p} min-h-[80px]`})}),(0,l.jsx)(f,{label:`Instructions`,children:(0,l.jsx)(`textarea`,{value:S,onChange:e=>We(e.target.value),placeholder:`Behavioral instructions…`,className:`${p} min-h-[80px]`})}),(0,l.jsx)(f,{label:`System Prompt`,hint:`Compiled from Role + Identity + Instructions. Override manually.`,children:(0,l.jsx)(`textarea`,{value:C,onChange:e=>Ge(e.target.value),placeholder:`System prompt sent to the LLM…`,className:`${p} min-h-[140px] font-mono text-xs`})})]}),(0,l.jsxs)(`section`,{className:`rounded-lg border border-destructive/30 p-4`,children:[(0,l.jsx)(`h2`,{className:`mb-3 text-sm font-semibold text-destructive`,children:`Danger Zone`}),(0,l.jsxs)(a,{type:`button`,variant:`destructive`,disabled:Ne,onClick:At,children:[(0,l.jsx)(i,{className:`mr-2 h-4 w-4`}),Ne?`Deleting...`:`Delete Agent`]})]})]}),g===`provider`&&(0,l.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,l.jsx)(f,{label:`Provider`,children:(0,l.jsxs)(`select`,{value:w,onChange:e=>{let t=e.target.value;Ke(t),qe(``),k(we[t]||``),D(d(t))},className:`w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring`,children:[(0,l.jsx)(`option`,{value:`anthropic`,children:`Anthropic Claude`}),(0,l.jsx)(`option`,{value:`openai`,children:`OpenAI GPT`}),(0,l.jsx)(`option`,{value:`ollama`,children:`Ollama (Local)`}),(0,l.jsx)(`option`,{value:`lm-studio`,children:`LM Studio (Local)`}),(0,l.jsx)(`option`,{value:`vllm`,children:`vLLM (Local)`}),(0,l.jsx)(`option`,{value:`custom`,children:`Custom`})]})}),(0,l.jsx)(f,{label:`API Key`,hint:[`ollama`,`lm-studio`,`vllm`].includes(w)?`Any value works for local providers.`:void 0,children:(0,l.jsx)(o,{type:`password`,value:T,onChange:e=>qe(e.target.value),placeholder:w===`ollama`?`ollama`:w===`lm-studio`?`lm-studio`:`sk-…`})}),(0,l.jsx)(f,{label:`Host / Base URL`,children:(0,l.jsx)(o,{value:E,onChange:e=>D(e.target.value),placeholder:d(w)||`https://api.example.com`})})]}),g===`models`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Main Model`}),(0,l.jsx)(f,{label:`Model`,children:(0,l.jsx)(xe,{value:O,onChange:(e,t)=>{k(e),t?.maxTokens&&A(t.maxTokens)},...$e})}),(0,l.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-3`,children:[w!==`anthropic`&&(0,l.jsx)(f,{label:`Temperature`,children:(0,l.jsx)(o,{type:`number`,min:0,max:2,step:.1,value:Je,onChange:e=>Ye(Number.isNaN(e.target.valueAsNumber)?.7:e.target.valueAsNumber)})}),(0,l.jsx)(f,{label:`Max Output Tokens`,children:(0,l.jsx)(o,{type:`number`,min:1,max:et?.maxTokens,value:Xe,onChange:e=>A(parseInt(e.target.value)||4096)})}),(0,l.jsx)(f,{label:`Top P`,children:(0,l.jsx)(o,{type:`number`,min:0,max:1,step:.1,value:Ze,onChange:e=>Qe(Number.isNaN(e.target.valueAsNumber)?1:e.target.valueAsNumber)})})]})]}),[`Governance`,`Memory Management`,`Subagent / Tool Use`].map(e=>(0,l.jsxs)(`section`,{className:`rounded-lg border border-dashed p-4`,children:[(0,l.jsxs)(`h2`,{className:`text-sm font-semibold text-muted-foreground`,children:[e,` Model`]}),(0,l.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Coming soon`})]},e))]}),g===`tools`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Runtime Tools`}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Injected at start (pi defineTool): coding tools plus canvas tools scoped by the token binding (Access / ACL). Definitions live in the runtime — read-only here until the agent-runtime workspace lands.`})]}),$===null?(0,l.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`Loading…`}):$.length===0?(0,l.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`No tools resolved.`}):(0,l.jsx)(`div`,{className:`space-y-1.5`,children:$.map(e=>(0,l.jsxs)(`details`,{className:`rounded-md border px-3 py-2`,children:[(0,l.jsxs)(`summary`,{className:`cursor-pointer text-sm`,children:[(0,l.jsx)(`code`,{className:`font-mono text-xs font-medium`,children:e.name}),(0,l.jsx)(`span`,{className:`ml-2 rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground`,children:e.source})]}),e.description&&(0,l.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap text-xs text-muted-foreground`,children:e.description}),e.parameters!=null&&(0,l.jsx)(`pre`,{className:`mt-2 overflow-x-auto rounded bg-muted p-2 font-mono text-[11px]`,children:JSON.stringify(e.parameters,null,2)})]},e.name))}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:z?z.grants.map(e=>`${e.label}: ${Bt(e.binding)}`).join(`; `):`Unbound — no canvas tools are injected. Bind under Access / ACL.`})]}),(0,l.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Tools Config`}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`config.tools JSON, merged server-side — e.g. {"canvas": {"enabled": false}} gates the canvas tools. Saved with Save Changes.`})]}),(0,l.jsx)(`textarea`,{value:St,onChange:e=>{Ct(e.target.value);try{JSON.parse(e.target.value),Tt(null)}catch(e){Tt(e instanceof Error?e.message:`Invalid JSON`)}},className:`${p} min-h-[120px] font-mono text-xs`}),wt&&(0,l.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Invalid JSON (not saved): `,wt]})]}),(0,l.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Skills`}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Installed skills are saved immediately, independent of Save Changes.`})]}),tt.length===0?(0,l.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`No skills installed.`}):tt.map(e=>(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-3 rounded-md border p-3`,children:[(0,l.jsxs)(`div`,{className:`min-w-0`,children:[(0,l.jsx)(`div`,{className:`truncate text-sm font-medium`,children:e.name}),(0,l.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.package?e.source:e.description||`No description`})]}),(0,l.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,l.jsx)(a,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{N(e.name),P(e.description||``),I(e.content||``),R(e.source||``)},children:`Edit`}),(0,l.jsx)(a,{type:`button`,variant:`destructive`,size:`sm`,disabled:at===(e.source||e.name),onClick:()=>Nt(e.source||e.name),children:at===(e.source||e.name)?`Removing…`:`Remove`})]})]},e.name)),(0,l.jsxs)(`div`,{className:`space-y-4 rounded-md border p-4`,children:[(0,l.jsx)(f,{label:`Package Source`,hint:`Use this for whole pi packages. Leave empty to save inline SKILL.md content.`,children:(0,l.jsx)(o,{value:L,onChange:e=>R(e.target.value),placeholder:`npm:@foo/pi-tools or git:github.com/badlogic/pi-doom`})}),(0,l.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,l.jsx)(f,{label:`Name`,children:(0,l.jsx)(o,{value:M,onChange:e=>N(e.target.value),placeholder:`skill-name, or read from frontmatter`,disabled:!!L.trim()})}),(0,l.jsx)(f,{label:`Description`,children:(0,l.jsx)(o,{value:nt,onChange:e=>P(e.target.value),placeholder:`What this skill helps with`,disabled:!!L.trim()})})]}),(0,l.jsx)(f,{label:`SKILL.md Content`,children:(0,l.jsx)(`textarea`,{value:F,onChange:e=>I(e.target.value),placeholder:`# Skill instructions…`,disabled:!!L.trim(),className:`${p} min-h-[160px] font-mono text-xs`})}),(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(a,{type:`button`,disabled:rt||!L.trim()&&!F.trim(),onClick:Mt,children:rt?`Saving…`:`Install / Update Skill`}),(0,l.jsx)(a,{type:`button`,variant:`outline`,onClick:jt,children:`Clear`})]})]})]}),(0,l.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`MCP Servers`}),(_.config?.mcp?.servers||[]).length===0?(0,l.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`No MCP servers configured.`}):(_.config?.mcp?.servers||[]).map((e,t)=>(0,l.jsxs)(`div`,{className:`rounded-md border p-3`,children:[(0,l.jsx)(`div`,{className:`text-sm font-medium`,children:e.name}),(0,l.jsxs)(`div`,{className:`font-mono text-xs text-muted-foreground`,children:[e.command,` `,(e.args||[]).join(` `)]})]},t))]})]}),g===`access`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Canvas Access`}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Add named connections to workspaces, paths or contexts, with permissions for each. Every connection has its own scoped token. Overlapping grants are additive: a whole-workspace grant is not restricted by a context on that workspace.`})]}),st===_.id?z?(0,l.jsxs)(`div`,{className:`space-y-2`,children:[z.grants.map(e=>(0,l.jsxs)(`div`,{className:`space-y-2 rounded-md border p-3`,children:[(0,l.jsx)(`div`,{className:`text-sm font-medium`,children:e.label||e.id}),(0,l.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:Bt(e.binding)}),(0,l.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`Permissions: `,e.permissions.join(`, `)]}),(0,l.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,l.jsx)(a,{type:`button`,variant:`outline`,size:`sm`,disabled:V,onClick:()=>Lt(e),children:`Edit`}),(0,l.jsx)(a,{type:`button`,variant:`outline`,size:`sm`,disabled:V,onClick:()=>It(e.id),children:`Rotate Token`}),(0,l.jsx)(a,{type:`button`,variant:`destructive`,size:`sm`,disabled:V,onClick:()=>Rt(e.id),children:`Remove`})]})]},e.id)),(0,l.jsx)(a,{type:`button`,variant:`destructive`,size:`sm`,disabled:V,onClick:zt,children:`Revoke All Access`})]}):(0,l.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`Unbound — this agent has no canvas access.`}):(0,l.jsx)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:`Loading…`}),U&&(0,l.jsxs)(`div`,{className:`space-y-2 rounded-md border border-warning/50 bg-warning/10 p-3`,children:[(0,l.jsx)(`div`,{className:`text-xs font-medium`,children:`Agent token — shown once, store it now`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`code`,{className:`flex-1 truncate rounded bg-background px-2 py-1 font-mono text-xs`,children:U}),(0,l.jsx)(a,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>navigator.clipboard?.writeText(U),children:`Copy`}),(0,l.jsx)(a,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>W(null),children:`Dismiss`})]}),(0,l.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Managed agents receive their connections automatically. External runtimes use the CANVAS_CONNECTIONS JSON array.`})]})]}),(0,l.jsxs)(`section`,{className:`space-y-4 rounded-lg border p-4`,children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold`,children:q?`Edit Connection`:`Add Connection`}),(0,l.jsx)(f,{label:`Connection name`,hint:`Agents use this name to select the scope for each tool call.`,children:(0,l.jsx)(o,{value:G,disabled:q,onChange:e=>K(e.target.value),placeholder:`bar, baz, baf`})}),(0,l.jsx)(f,{label:`Scope`,hint:`Context bindings follow the context live; global spans all workspaces.`,children:(0,l.jsxs)(`select`,{value:Y,onChange:e=>lt(e.target.value),className:m,children:[(0,l.jsx)(`option`,{value:`context`,children:`Context (follows live)`}),(0,l.jsx)(`option`,{value:`workspace`,children:`Workspace`}),(0,l.jsx)(`option`,{value:`path`,children:`Workspace path`}),(0,l.jsx)(`option`,{value:`global`,children:`Global (all workspaces)`})]})}),Y===`context`&&(0,l.jsx)(f,{label:`Context`,children:(0,l.jsxs)(`select`,{value:Z,onChange:e=>pt(e.target.value),className:m,children:[(0,l.jsx)(`option`,{value:``,children:`Select a context…`}),yt.map(e=>(0,l.jsxs)(`option`,{value:e.id,children:[e.id,` — `,e.url]},e.id))]})}),(Y===`workspace`||Y===`path`)&&(0,l.jsx)(f,{label:`Workspace`,children:(0,l.jsxs)(`select`,{value:X,onChange:e=>ut(e.target.value),className:m,children:[(0,l.jsx)(`option`,{value:``,children:`Select a workspace…`}),_t.map(e=>(0,l.jsx)(`option`,{value:e.name||e.id,children:e.label||e.name},e.id))]})}),Y===`path`&&(0,l.jsx)(f,{label:`Base path`,hint:`The agent is clamped to this subtree.`,children:(0,l.jsx)(o,{value:dt,onChange:e=>ft(e.target.value),placeholder:`/work/projects/foo`})}),(0,l.jsx)(f,{label:`Permissions`,children:(0,l.jsxs)(`div`,{className:`flex gap-4 text-sm`,children:[(0,l.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`input`,{type:`checkbox`,checked:mt,onChange:e=>ht(e.target.checked)}),` read`]}),(0,l.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`input`,{type:`checkbox`,checked:Q,onChange:e=>gt(e.target.checked)}),` write`]})]})}),(0,l.jsx)(a,{type:`button`,disabled:V,onClick:Ft,children:V?`Working…`:q?`Save Connection`:`Add Connection`}),q&&(0,l.jsx)(a,{type:`button`,variant:`outline`,onClick:()=>{K(``),J(!1)},children:`Cancel Edit`})]})]}),g===`memory`&&(0,l.jsxs)(`section`,{className:`rounded-lg border border-dashed p-6 text-center`,children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold text-muted-foreground`,children:`Memory Engine`}),(0,l.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Loop-based memory management. Settings coming soon.`})]}),g===`integrations`&&(0,l.jsxs)(`section`,{className:`rounded-lg border border-dashed p-6 text-center`,children:[(0,l.jsx)(`h2`,{className:`text-sm font-semibold text-muted-foreground`,children:`Integrations`}),(0,l.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`IMAP, chat, SQL and REST API accounts. Coming soon.`})]}),Ut&&(0,l.jsx)(a,{type:`submit`,disabled:je,children:je?`Saving…`:`Save Changes`})]})]})})}export{h as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{pi as i}from"./ui-DEgHnkQu.js";import{t as a}from"./input-BOtCd4HP.js";import{jt as o}from"./workspace-4hWrSEku.js";import{p as s}from"./context-DY40EDc6.js";import{i as c,m as l,p as u}from"./use-menu-CKSpS96u.js";import{$ as d,bt as f,xt as p,yt as m}from"./index-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{pi as i}from"./ui-DEgHnkQu.js";import{t as a}from"./input-BOtCd4HP.js";import{jt as o}from"./workspace-4hWrSEku.js";import{p as s}from"./context-DY40EDc6.js";import{i as c,m as l,p as u}from"./use-menu-CKSpS96u.js";import{$ as d,bt as f,xt as p,yt as m}from"./index-NOhHv2VY.js";import{n as h}from"./page-header-NyYSXjfY.js";var g=e(n(),1),_=t(),v=[{id:`workspace`,label:`Workspace`,path:`workspaces`,description:`Files, search, devices and sharing for one workspace. These settings override account defaults.`,sections:p,load:async()=>(await o()).map(e=>({id:e.name,label:e.label||e.name}))},{id:`context`,label:`Context`,path:`contexts`,description:`Choose the tree and path a context opens, and who can access that view. File storage belongs to its workspace.`,sections:f,load:async()=>(await s()).map(e=>({id:e.id,label:e.name||e.id}))},{id:`agent`,label:`Agent`,path:`agents`,description:`Configure one assistant: its instructions, chat model, tools and access to Canvas.`,sections:m,load:async()=>(await d()).map(e=>({id:e.id,label:e.label||e.name}))}];function y({to:e,label:t,description:n,icon:a}){return(0,_.jsxs)(r,{to:e,className:`group flex items-start gap-3 rounded-lg border bg-card p-4 transition-colors hover:border-primary/50 hover:bg-accent/30 focus-visible:outline focus-visible:outline-2 focus-visible:outline-primary`,children:[(0,_.jsx)(a,{className:`mt-0.5 h-5 w-5 shrink-0 text-muted-foreground`}),(0,_.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,_.jsx)(`span`,{className:`block text-sm font-semibold`,children:t}),(0,_.jsx)(`span`,{className:`mt-1 block text-sm leading-relaxed text-muted-foreground`,children:n})]}),(0,_.jsx)(i,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground group-hover:text-primary`})]})}function b({group:e,query:t}){let[n,r]=(0,g.useState)([]),[i,a]=(0,g.useState)(``),[o,s]=(0,g.useState)(`loading`),[c,u]=(0,g.useState)(0);(0,g.useEffect)(()=>{let t=!1;return e.load().then(e=>{t||(r(e),s(`ready`))}).catch(()=>{t||s(`error`)}),()=>{t=!0}},[e,c]);let d=e.sections.filter(n=>l(t,e.label,n.label,n.description));return d.length?(0,_.jsxs)(`section`,{id:e.id,className:`scroll-mt-6 space-y-3`,children:[(0,_.jsx)(`h2`,{className:`text-lg font-semibold`,children:e.label}),(0,_.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),(0,_.jsxs)(`label`,{className:`block max-w-md text-sm font-medium`,children:[`Choose a `,e.label.toLowerCase(),(0,_.jsxs)(`select`,{className:`mt-2 h-10 w-full rounded-md border bg-background px-3 text-sm`,value:i,disabled:o!==`ready`||!n.length,onChange:e=>a(e.target.value),children:[(0,_.jsx)(`option`,{value:``,children:o===`loading`?`Loading…`:o===`error`?`Unable to load list`:n.length?`Select ${e.label.toLowerCase()}…`:`No ${e.path} available`}),n.map(e=>(0,_.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]}),o===`error`&&(0,_.jsxs)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:[`The list could not be loaded. `,(0,_.jsx)(`button`,{type:`button`,className:`underline`,onClick:()=>{s(`loading`),u(e=>e+1)},children:`Retry`})]}),(0,_.jsxs)(`details`,{open:!!(i||t.trim()),children:[(0,_.jsx)(`summary`,{className:`cursor-pointer py-2 text-sm text-muted-foreground`,children:i?`Settings for ${n.find(e=>e.id===i)?.label||i}`:`What you can configure (${d.length})`}),(0,_.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))] gap-3`,children:d.map(t=>i?(0,_.jsx)(y,{to:`/${e.path}/${encodeURIComponent(i)}/settings/${t.id}`,...t},t.id):(0,_.jsxs)(`div`,{className:`rounded-lg border border-dashed p-4`,children:[(0,_.jsx)(`p`,{className:`text-sm font-medium`,children:t.label}),(0,_.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:t.description})]},t.id))})]})]}):null}function x(){let{state:e}=c(),[t,n]=(0,g.useState)(``),r=u.filter(t=>t.id!==`server`||e.user?.userType===`admin`).map(e=>({...e,items:e.items.filter(n=>l(t,e.label,n.label,n.description))})).filter(e=>e.items.length),i=v.some(e=>e.sections.some(n=>l(t,e.label,n.label,n.description)));return(0,_.jsxs)(`div`,{className:`mx-auto max-w-6xl space-y-8 pb-8 max-md:pb-rail-stack`,children:[(0,_.jsx)(h,{title:`Settings`,description:`Start with what you want to change. Each section explains where your changes apply.`}),(0,_.jsx)(a,{type:`search`,className:`max-w-xl`,"aria-label":`Search all settings`,placeholder:`Find a setting: offline, folders, models, sharing…`,value:t,onChange:e=>n(e.target.value)}),r.filter(e=>e.id===`device`||e.id===`account`).map(e=>(0,_.jsxs)(`section`,{className:`space-y-3`,children:[(0,_.jsx)(`h2`,{className:`text-lg font-semibold`,children:e.label}),(0,_.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),(0,_.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))] gap-3`,children:e.items.map(e=>(0,_.jsx)(y,{to:e.path,...e},e.path))})]},e.id)),v.map(e=>(0,_.jsx)(b,{group:e,query:t},e.id)),r.filter(e=>e.id===`server`||e.id===`information`).map(e=>(0,_.jsxs)(`section`,{className:`space-y-3`,children:[(0,_.jsx)(`h2`,{className:`text-lg font-semibold`,children:e.label}),(0,_.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),(0,_.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))] gap-3`,children:e.items.map(e=>(0,_.jsx)(y,{to:e.path,...e},e.path))})]},e.id)),!r.length&&!i&&(0,_.jsxs)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:[`No settings match “`,t,`”. Try a shorter phrase or clear the search.`]})]})}export{x as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{a as t,i as n,l as r,n as i,r as a,t as o,u as s}from"./code-editor-BOIngd5F.js";import{_t as c}from"./react-BHzhHVTZ.js";import{_ as l,g as u,v as d}from"./chunk-62JRHF6Z-vspAGgtK.js";import{An as f,Bn as p,Bt as m,Cn as h,Ct as g,Er as _,Fn as v,G as y,Gr as b,H as x,It as S,J as C,Jn as w,Kr as T,Kt as E,L as D,Mt as O,Nt as k,Pt as A,Qt as j,Rr as M,Si as N,Tt as P,U as F,Ur as ee,Wn as te,X as I,Xn as ne,Xt as L,Z as R,Zn as re,_t as ie,an as ae,bt as oe,cn as se,ct as ce,ft as le,hr as ue,ii as de,kt as z,mr as B,pn as fe,pr as pe,pt as me,rt as he,st as ge,vn as _e,xr as ve,yi as V,yr as H}from"./ui-DEgHnkQu.js";import{t as ye}from"./utils-2pl1SbIp.js";import{t as U}from"./button--VYZekMF.js";import{t as W}from"./input-BOtCd4HP.js";import{t as G}from"./label-RuOXXC8t.js";import{c as be,l as xe,t as K}from"./api-CA6WiiYM.js";import{t as Se}from"./socket-CtH3EU9m.js";import{n as q}from"./use-toast-BlLDqSUO.js";import{t as Ce}from"./LinkToCard-oi3wGP0a.js";import{$ as we,A as Te,Bt as Ee,Et as De,F as Oe,I as ke,P as Ae,Q as je,Qt as Me,T as Ne,U as J,V as Y,Vt as Pe,Wt as Fe,Zt as Ie,_t as Le,cn as Re,d as ze,et as Be,f as Ve,gn as X,it as He,jt as Ue,k as We,ln as Ge,mn as Ke,mt as qe,n as Je,nn as Ye,pn as Xe,r as Ze,rn as Qe,sn as $e,st as et,tn as tt,vt as nt,wt as rt,xt as it}from"./workspace-4hWrSEku.js";import{a as at,c as ot,i as st,n as ct,o as lt,r as ut,s as dt,t as ft}from"./alert-dialog-BKtaX1_a.js";import{t as pt}from"./use-mobile-Db-vWu9Y.js";import{t as mt}from"./useEscapeClose-DR_xKT_k.js";import{o as ht}from"./layer-style-Byl5LNFR.js";import{i as gt,t as _t}from"./color-DFEH4BfK.js";import{a as vt,o as yt,s as bt,t as xt}from"./MessageComposerDialog-CLrwtB76.js";import{n as St}from"./LinkToSidePanel-eCy3nW4R.js";import{n as Ct}from"./use-document-modal-PG8bQyIB.js";import{A as wt,C as Tt,D as Et,E as Dt,F as Ot,L as kt,M as At,N as jt,O as Mt,P as Nt,S as Pt,T as Ft,_ as It,a as Lt,b as Rt,c as zt,d as Bt,f as Vt,g as Ht,h as Ut,i as Wt,k as Gt,n as Kt,p as qt,r as Jt,t as Yt,v as Xt,w as Zt,y as Qt}from"./rule-builder-CziPqpNe.js";import{t as $t}from"./workspace-access-C9nZlBBZ.js";import{i as en}from"./use-menu-CKSpS96u.js";import{t as tn}from"./use-theme-DaxpiICf.js";import{Ot as nn,ct as rn,dt as an,ft as on,lt as sn,mt as cn,pt as ln,ut as un,wt as dn,xt as fn}from"./index-CTvqbEB8.js";import{n as pn}from"./page-header-NyYSXjfY.js";import{c as mn,f as hn,l as gn,m as _n,n as vn,o as yn,p as bn,r as xn,s as Sn,t as Cn}from"./inferd-config-editor-Dpdj90iN.js";import{n as wn,t as Tn}from"./useSocketSubscription-ifW-vnlb.js";import{a as En,n as Dn,o as On,r as kn,t as An}from"./devices-CAa1bRxk.js";import{a as jn,i as Mn,n as Nn,o as Pn,t as Fn}from"./query-debug-PEWbZsOP.js";import{a as In,i as Ln,r as Rn,t as zn}from"./workspace-import-form-CWs9ZTts.js";var Z=e(s(),1),Bn=`workspace:backups`,Vn=e=>`${be.workspaces}/${encodeURIComponent(e)}/db/backups`,Hn=e=>K.get(Vn(e)),Un=e=>K.post(Vn(e),{action:`backup`}),Wn=(e,t)=>K.post(Vn(e),{action:`restore`,backupId:t,confirm:!0}),Gn=new Map;function Kn(e,t,n){let r=JSON.stringify([t,n.id]),i=Gn.get(r);if(i)return i;let a=(async()=>{let r=n.action===`restore`,i=e({title:r?`Restoring workspace database`:`Backing up workspace database`,description:r?`Stopping the workspace and preserving its current database…`:`Copying and verifying all datasets…`});try{let e=n;for(;e.status===`running`;){let n=await Hn(t),r=n.jobs.find(t=>t.id===e.id);if(!r)throw Error(`The server restarted. Refresh the backup list to check the result.`);e=r,window.dispatchEvent(new CustomEvent(Bn,{detail:{workspace:t,status:n}})),e.status===`running`&&await new Promise(e=>setTimeout(e,1500))}if(e.status===`failed`)throw Error(e.error||`Database operation failed`);i.done({title:r?`Workspace database restored`:`Workspace backup verified`,description:r?`The workspace is stopped. Start it when you are ready; search indexes will rebuild.`:`Documents, relations and virtual tree placements are saved.`})}catch(e){throw i.fail({title:`Workspace backup needs attention`,description:e instanceof Error?e.message:String(e),variant:`destructive`}),e}})();return Gn.set(r,a),a.finally(()=>Gn.delete(r)).catch(()=>{}),a}var Q=r(),qn={startup:`Startup`,hourly:`Hourly`,manual:`Manual`,"pre-restore":`Before restore`};function Jn({workspaceId:e,onRestored:t}){let{showToast:n,showProgress:r}=q(),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!1),f=(0,Z.useRef)(!1),p=(0,Z.useRef)(!1),m=(0,Z.useRef)(0),h=(0,Z.useCallback)(()=>{let t=++m.current;return Hn(e).then(n=>{if(!(!f.current||t!==m.current)){a(n),s(null);for(let t of n.jobs.filter(e=>e.status===`running`))Kn(r,e,t).catch(()=>{})}}).catch(e=>{f.current&&t===m.current&&s(e instanceof Error?e.message:String(e))})},[e,r]);(0,Z.useEffect)(()=>{f.current=!0,h();let t=t=>{let n=t.detail;n.workspace===e&&a(n.status)};return window.addEventListener(Bn,t),()=>{f.current=!1,window.removeEventListener(Bn,t)}},[e,h]);let g=async i=>{if(!p.current){p.current=!0,d(!0);try{let n=i?await Wn(e,i.id):await Un(e);f.current&&a(e=>e&&{...e,jobs:[n,...e.jobs]}),await Kn(r,e,n),i&&t()}catch(e){n({title:`Database operation did not complete`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}finally{p.current=!1,f.current&&(d(!1),h())}}},_=u||!!i?.jobs.some(e=>e.status===`running`),v=i?.jobs[0];return(0,Q.jsxs)(`div`,{className:`min-w-0 space-y-5`,children:[(0,Q.jsxs)(`section`,{className:`space-y-4 rounded border p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Q.jsx)(V,{className:`h-5 w-5 text-muted-foreground`}),(0,Q.jsx)(`h2`,{className:`font-semibold`,children:`Workspace checkpoints`}),(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,className:`ml-auto`,disabled:_||!i||!!o,onClick:()=>void g(),children:[_?(0,Q.jsx)(fe,{className:`mr-2 h-4 w-4 animate-spin`}):(0,Q.jsx)(V,{className:`mr-2 h-4 w-4`}),`Back up now`]})]}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Save a checkpoint before a bulk action. Each backup includes every document, relation and virtual tree placement in this workspace’s database.`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-x-5 gap-y-2 text-sm`,children:[(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:i?.retention.hourly??24}),` hourly backups`]}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:i?.retention.startup??14}),` startup backups`]}),(0,Q.jsx)(`span`,{children:`Manual checkpoints kept`})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Hourly backups run while the workspace is active. These checkpoints cover the database only; files in storage backends and workspace settings need their own backups.`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`h2`,{className:`text-sm font-semibold`,children:[`Verified checkpoints`,i?` · ${i.backups.length}`:``]}),(0,Q.jsx)(U,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>void h(),"aria-label":`Refresh backups`,children:(0,Q.jsx)(z,{className:`h-4 w-4`})})]}),o&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:o}),v&&(0,Q.jsx)(`p`,{role:`status`,className:`text-sm ${v.status===`failed`?`text-destructive`:`text-muted-foreground`}`,children:v.status===`running`?`Database operation in progress…`:v.status===`failed`?v.error:v.action===`restore`?`Database restored. The workspace is stopped and ready to start.`:`Backup complete and verified.`}),!i&&!o&&(0,Q.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Loading backups…`}),i?.backups.length===0&&(0,Q.jsx)(`p`,{className:`rounded border border-dashed p-6 text-sm text-muted-foreground`,children:`No verified checkpoints yet. Create one before your next bulk action.`}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:i?.backups.map(e=>(0,Q.jsxs)(`article`,{className:`flex min-w-0 flex-wrap items-center gap-3 rounded border p-3`,children:[(0,Q.jsx)(T,{className:`h-4 w-4 shrink-0 text-muted-foreground`,"aria-label":`Verified`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 basis-40`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:new Date(e.createdAt).toLocaleString()}),(0,Q.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[qn[e.kind],` · `,Y(e.bytes),` · `,(e.datasets.documents?.count??0).toLocaleString(),` documents`]})]}),(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,disabled:_,onClick:()=>l(e),children:[(0,Q.jsx)(P,{className:`mr-2 h-3.5 w-3.5`}),`Restore`]})]},e.id))}),(0,Q.jsx)(ft,{open:!!c,onOpenChange:e=>{e||l(null)},children:(0,Q.jsxs)(st,{className:`max-w-[calc(100vw-2rem)] sm:max-w-lg`,children:[(0,Q.jsxs)(dt,{children:[(0,Q.jsx)(ot,{children:`Restore this workspace checkpoint?`}),(0,Q.jsxs)(at,{children:[`The workspace will stop and its current database will be backed up first. Documents, relations and virtual tree placements will return to `,c?new Date(c.createdAt).toLocaleString():`the selected checkpoint`,`. Files in storage backends and workspace settings will stay as they are. The workspace stays stopped after restoration.`]})]}),(0,Q.jsxs)(lt,{children:[(0,Q.jsx)(ut,{children:`Cancel`}),(0,Q.jsx)(ct,{disabled:_,onClick:()=>{c&&g(c)},children:`Back up current & restore`})]})]})})]})}var Yn={collect:`Collect unused blobs`,verify:`Verify integrity`,compact:`Compact index`},Xn=e=>e.status===`queued`||e.status===`running`,Zn=e=>`${be.workspaces}/${encodeURIComponent(e)}/cache/maintenance`,Qn=e=>K.get(Zn(e)),$n=(e,t,n)=>K.post(Zn(e),{store:t,action:n,...n===`verify`?{confirm:!0}:{}});function er(e){if(e.status===`failed`)return e.error||`Maintenance failed`;if(e.status===`queued`)return`Waiting for active storage operations…`;if(e.status===`running`)return e.action===`verify`?`Reading and checking stored content…`:`Processing the cache index…`;let t=e.result||{};return e.action===`compact`?`${(t.compactedCount||0).toLocaleString()} keys compacted`:e.action===`verify`?`${(t.verifiedContent||0).toLocaleString()} blobs verified · ${(t.badContentCount||0).toLocaleString()} corrupted blobs removed · ${Y(t.reclaimedSize||0)} reclaimed`:`${(t.reclaimedCount||0).toLocaleString()} unused blobs removed · ${Y(t.reclaimedSize||0)} reclaimed`}var tr=new Map,nr=`workspace:cache-maintenance`;function rr(e,t,n){let r=JSON.stringify([t,n.id]),i=tr.get(r);if(i)return i;let a=(async()=>{let r=e({title:Yn[n.action],description:`${n.store} · ${er(n)}`});try{let e=n;for(;Xn(e);){let i=await Qn(t),a=i.jobs.find(e=>e.id===n.id);if(!a)throw Error(`Maintenance receipt is no longer available. The server may have restarted; refresh the cache settings.`);if(e=a,window.dispatchEvent(new CustomEvent(nr,{detail:{workspace:t,status:i}})),!Xn(e))break;r.update({title:Yn[e.action],description:`${e.store} · ${er(e)}`}),await new Promise(e=>setTimeout(e,2e3))}if(e.status===`failed`)throw Error(er(e));r.done({title:`${Yn[e.action]} complete`,description:`${e.store} · ${er(e)}`})}catch(e){throw r.fail({title:`Cache maintenance needs attention`,description:`${n.store} · ${e instanceof Error?e.message:String(e)}`,variant:`destructive`}),e}})();return tr.set(r,a),a.finally(()=>{tr.get(r)===a&&tr.delete(r)}).catch(()=>{}),a}function ir({workspaceId:e,children:t}){let{showToast:n,showProgress:r}=q(),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(`workspace:cache`),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(null),m=(0,Z.useRef)(!1),h=(0,Z.useRef)(!1),g=(0,Z.useCallback)(()=>Qn(e).then(t=>{if(h.current){a(t),p(null);for(let n of t.jobs.filter(Xn))rr(r,e,n).catch(()=>{})}}).catch(e=>{h.current&&p(e instanceof Error?e.message:`Cannot load maintenance status`)}),[e,r]);(0,Z.useEffect)(()=>{h.current=!0,g();let t=t=>{let{workspace:n,status:r}=t.detail;n===e&&(a(r),p(null))};return window.addEventListener(nr,t),()=>{h.current=!1,window.removeEventListener(nr,t)}},[e,g]);let _=async t=>{if(!(m.current||i?.jobs.some(Xn))){m.current=!0,l(!0);try{let n=await $n(e,o,t);h.current&&a(e=>e&&{...e,jobs:[n,...e.jobs.filter(e=>e.id!==n.id)]}),rr(r,e,n).catch(()=>{})}catch(e){n({title:`Could not start maintenance`,description:e instanceof Error?e.message:String(e),variant:`destructive`}),g()}finally{m.current=!1,h.current&&l(!1)}}},v=c||!!i?.jobs.some(Xn),y=i?.stores.find(e=>e.id===o),b=i?.jobs[0];return(0,Q.jsxs)(`section`,{className:`space-y-4 rounded-(--panel-radius) border p-4`,"aria-label":`Workspace cache maintenance`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`h2`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[(0,Q.jsx)(ve,{className:`h-4 w-4 shrink-0`}),`Workspace cache`]}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Thumbnails, cached resources and pending transfers. Maintenance runs only when requested.`})]}),t&&(0,Q.jsx)(`fieldset`,{disabled:v,children:t})]}),(0,Q.jsxs)(`div`,{className:`space-y-3 border-t pt-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`label`,{htmlFor:`cache-maintenance-store`,className:`text-xs font-medium`,children:`Store`}),(0,Q.jsxs)(`select`,{id:`cache-maintenance-store`,value:o,onChange:e=>s(e.target.value),disabled:v,className:`min-w-0 max-w-full rounded-md border bg-background px-2 py-1.5 text-xs`,children:[(0,Q.jsx)(`option`,{value:`workspace:cache`,children:`workspace:cache`}),(0,Q.jsx)(`option`,{value:`workspace:data`,children:`workspace:data`})]}),(0,Q.jsx)(U,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>void g(),"aria-label":`Refresh cache maintenance status`,className:`ml-auto h-8 w-8`,children:(0,Q.jsx)(z,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o===`workspace:data`?`Managed document blobs. Referenced content is kept during collection.`:`Working cache, including content awaiting transfer. Referenced content is kept during collection.`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsxs)(U,{type:`button`,variant:`outline`,size:`sm`,disabled:v||!y?.canCollect||!!f,onClick:()=>void _(`collect`),children:[(0,Q.jsx)(I,{className:`mr-2 h-3.5 w-3.5`}),`Collect unused blobs`]}),(0,Q.jsxs)(U,{type:`button`,variant:`outline`,size:`sm`,disabled:v||!y?.canCompact||!!f,onClick:()=>void _(`compact`),children:[(0,Q.jsx)(V,{className:`mr-2 h-3.5 w-3.5`}),`Compact index`]}),(0,Q.jsxs)(U,{type:`button`,variant:`outline`,size:`sm`,disabled:v||!y?.canVerify||!!f,onClick:()=>d(!0),children:[(0,Q.jsx)(le,{className:`mr-2 h-3.5 w-3.5`}),`Verify integrity`]})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Collection removes unreferenced blobs. Compaction trims index history. Verification reads every blob and may remove corrupted content. Storage writes may wait during maintenance.`}),!i&&!f&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,role:`status`,children:`Loading maintenance status…`}),y&&!y.canCollect&&!y.canVerify&&!y.canCompact&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Update canvas-stored to enable maintenance for this store.`}),f&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,role:`alert`,children:f}),b&&(0,Q.jsxs)(`div`,{className:`rounded-md bg-muted/50 p-3 text-xs`,role:`status`,"aria-live":`polite`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[Xn(b)&&(0,Q.jsx)(fe,{className:`h-3.5 w-3.5 animate-spin`}),Yn[b.action],` · `,b.store]}),(0,Q.jsx)(`p`,{className:`mt-1 ${b.status===`failed`?`text-destructive`:`text-muted-foreground`}`,children:er(b)}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:b.finishedAt?`Finished ${new Date(b.finishedAt).toLocaleString()}`:`Requested ${new Date(b.createdAt).toLocaleString()}`})]})]}),(0,Q.jsx)(ft,{open:u,onOpenChange:d,children:(0,Q.jsxs)(st,{className:`max-w-[calc(100vw-2rem)] sm:max-w-lg`,children:[(0,Q.jsxs)(dt,{children:[(0,Q.jsxs)(ot,{children:[`Verify `,o,`?`]}),(0,Q.jsx)(at,{children:`This reads all stored content and can take a long time. Corrupted blobs and their index entries may be removed. Keep a recovery backup before running it. Storage writes may wait until it finishes.`})]}),(0,Q.jsxs)(lt,{children:[(0,Q.jsx)(ut,{children:`Cancel`}),(0,Q.jsx)(ct,{disabled:v,onClick:()=>void _(`verify`),children:`Verify and repair`})]})]})})]})}var ar=e=>e.status===`queued`||e.status===`running`,or=e=>`${be.workspaces}/${encodeURIComponent(e)}/db`,sr=e=>K.get(`${or(e)}/maintenance`),cr={"reindex:timelines":`reindex/timelines`,"reindex:mime":`reindex/mime`,"reindex:search":`reindex/search`,optimize:`optimize`};function lr(e,t,n={}){let r=cr[t];return t===`reindex:search`?K.post(`${or(e)}/${r}${n.rebuild?`?rebuild=true`:``}`,{}):K.post(`${or(e)}/${r}`,t===`optimize`&&n.space?{space:n.space}:{})}function ur(e){switch(e.action){case`reindex:timelines`:return`Rebuild timelines`;case`reindex:mime`:return`Rebuild file types`;case`reindex:search`:return e.options.rebuild?`Rebuild word search`:`Index missing documents`;default:return e.options.space?`Optimize ${e.options.space}`:`Optimize indexes`}}var dr=e=>typeof e==`number`?e.toLocaleString():`0`;function fr(e){if(e.status===`failed`)return e.error||`Maintenance failed`;if(e.status===`queued`)return`Waiting for the database…`;if(e.status===`running`){let t=e.progress;return t?e.action===`reindex:search`?`${dr(t.indexed)} indexed`:`${dr(t.scanned)}${typeof t.total==`number`?` / ${dr(t.total)}`:``} documents scanned`:`Working…`}let t=e.result||{};return e.action===`reindex:timelines`?`${dr(t.created)} created, ${dr(t.updated)} updated (${dr(t.scanned)} scanned)`:e.action===`reindex:mime`?`${dr(t.ticked)} of ${dr(t.scanned)} documents across ${dr(t.keys)} file types`:e.action===`reindex:search`?`${dr(t.indexed)} newly indexed (${dr(t.alreadyIndexed)} of ${dr(t.totalDocs)} already were)`:`Indexes compacted`}var pr=new Map;function mr(e,t,n){let r=JSON.stringify([t,n.id]),i=pr.get(r);if(i)return i;let a=(async()=>{let r=e({title:ur(n),description:fr(n)});try{let e=n;for(;ar(e);){let i=(await sr(t)).jobs.find(e=>e.id===n.id);if(!i)throw Error(`Maintenance receipt is no longer available. The workspace may have restarted; run it again.`);if(e=i,!ar(e))break;r.update({title:ur(e),description:fr(e)}),await new Promise(e=>setTimeout(e,2e3))}if(e.status===`failed`)throw Error(fr(e));return r.done({title:`${ur(e)} complete`,description:fr(e)}),e}catch(e){throw r.fail({title:`${ur(n)} needs attention`,description:e instanceof Error?e.message:String(e),variant:`destructive`}),e}})();return pr.set(r,a),a.finally(()=>{pr.get(r)===a&&pr.delete(r)}).catch(()=>{}),a}function hr({workspaceId:e,backend:t,onSaved:n}){let r=t?.config||{},i=()=>({name:String(r.label||``),bucket:String(r.bucket||``),prefix:String(r.prefix||``),endpoint:String(r.endpoint||``),region:String(r.region||`us-east-1`),accessKeyId:``,secretAccessKey:``,sessionToken:``}),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(i),[l,u]=(0,Z.useState)(r.forcePathStyle!==!1),[d,f]=(0,Z.useState)(r.readOnly===!0),[p,h]=(0,Z.useState)(r.watch===!0),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(!1),{showToast:b}=q(),x=e=>({value:s[e],onChange:t=>c(n=>({...n,[e]:t.target.value}))});return a?(0,Q.jsxs)(`form`,{onSubmit:async r=>{r.preventDefault(),y(!0);try{let r={label:s.name.trim(),bucket:s.bucket.trim(),prefix:s.prefix.trim(),endpoint:s.endpoint.trim(),region:s.region.trim()||`us-east-1`,forcePathStyle:l,readOnly:d,watch:p,...Object.fromEntries([`accessKeyId`,`secretAccessKey`,`sessionToken`].flatMap(e=>{let t=s[e].trim();return t?[[e,t]]:[]})),...g?{sessionToken:``}:{}};t?await Xe(e,`s3`,t.address,r):await Je(e,`s3`,r),o(!1),c(i()),b({title:t?`S3 backend updated`:`S3 backend added`,description:`Use Re-sync to check indexing progress, and filing policies to automate copies.`}),await n()}catch(e){b({title:`Could not connect S3`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}finally{y(!1)}},className:`w-full space-y-3 rounded-lg border p-4`,children:[(0,Q.jsxs)(`h2`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[(0,Q.jsx)(ve,{className:`h-4 w-4`}),t?`Edit S3 connection`:`Add S3-compatible bucket`]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Amazon S3, MinIO, Garage, RustFS or Ceph RGW. Connect an existing bucket, optionally scoped to a prefix. Supports browsing, reads and filing copies; mirror policies and overwrites are unavailable.`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[`Name`,(0,Q.jsx)(W,{...x(`name`),required:!0,placeholder:`Accounting archive`})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[`Bucket`,(0,Q.jsx)(W,{...x(`bucket`),disabled:!!t,required:!0,placeholder:`accounting`})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[`Endpoint (blank for Amazon S3)`,(0,Q.jsx)(W,{...x(`endpoint`),disabled:!!t,type:`url`,placeholder:`https://s3.example.com`})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[`Region`,(0,Q.jsx)(W,{...x(`region`),required:!0,placeholder:`us-east-1`})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs sm:col-span-2`,children:[`Prefix (optional)`,(0,Q.jsx)(W,{...x(`prefix`),disabled:!!t,placeholder:`Augmentd/Accounting`})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[`Access key ID`,(0,Q.jsx)(W,{...x(`accessKeyId`),required:!t,autoComplete:`off`,placeholder:t?`Leave blank to keep stored value`:``})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[`Secret access key`,(0,Q.jsx)(W,{...x(`secretAccessKey`),type:`password`,required:!t,autoComplete:`off`,placeholder:t?`Leave blank to keep stored value`:``})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs sm:col-span-2`,children:[`Session token (optional)`,(0,Q.jsx)(W,{...x(`sessionToken`),disabled:g,type:`password`,autoComplete:`off`,placeholder:t?`Leave blank to keep stored value`:``})]}),t&&(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked)}),`Clear stored session token`]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-4 text-xs`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked)}),`Path-style addressing`]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked)}),`Read-only`]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>h(e.target.checked)}),`Poll for changes`]})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Writable connections test conflict protection using a temporary object, then delete it. The key needs list/read/write access and delete access under .canvas-probe/. Initial indexing reads file bytes; polling can incur request and download charges. Upload limit: 5 GiB per file.`}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(U,{type:`button`,variant:`ghost`,disabled:v,onClick:()=>{o(!1),c(i())},children:`Cancel`}),(0,Q.jsx)(U,{disabled:v,children:v?`Checking connection…`:`Save connection`})]})]}):(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>{c(i()),u(r.forcePathStyle!==!1),f(r.readOnly===!0),h(r.watch===!0),_(!1),o(!0)},children:[t?(0,Q.jsx)(m,{className:`mr-2 h-3.5 w-3.5`}):(0,Q.jsx)(A,{className:`mr-2 h-3.5 w-3.5`}),t?`Edit S3 connection`:`Add S3 bucket`]})}function gr({workspaceId:e,isActive:t,currentMode:n,onChanged:r}){let[i,a]=(0,Z.useState)(n===`workspace`?`workspace`:`secrets`),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(!1);return(0,Q.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,Q.jsx)(`h2`,{className:`font-semibold text-sm`,children:`Workspace protection`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Protect service credentials with a PIN or password. Optionally require it to start the whole workspace. Files and document contents are not encrypted.`}),t&&(0,Q.jsx)(`p`,{className:`text-sm`,children:`Stop the workspace before changing protection.`}),(0,Q.jsxs)(`form`,{className:`space-y-3`,onSubmit:async t=>{if(t.preventDefault(),h(``),o!==c){h(`PIN/password confirmation does not match`);return}_(!0);try{let t=await K.put(`${be.workspaces}/${e}/protection`,{mode:i,passphrase:o,currentPassphrase:u||void 0});p(t.recoveryKey),s(``),l(``),d(``)}catch(e){h(e instanceof Error?e.message:`Could not save protection`)}finally{_(!1)}},children:[(0,Q.jsxs)(`label`,{className:`block text-sm space-y-1`,children:[`Protection mode`,(0,Q.jsxs)(`select`,{className:`block rounded border bg-background p-2 w-full`,value:i,onChange:e=>a(e.target.value),disabled:t||g,children:[(0,Q.jsx)(`option`,{value:`secrets`,children:`Secrets only — allow start without integrations`}),(0,Q.jsx)(`option`,{value:`workspace`,children:`Whole workspace — require PIN/password to start`})]})]}),(0,Q.jsxs)(`label`,{className:`block text-sm space-y-1`,children:[`Current PIN/password or recovery key (if already protected)`,(0,Q.jsx)(W,{type:`password`,autoComplete:`current-password`,value:u,onChange:e=>d(e.target.value),disabled:t||g})]}),(0,Q.jsxs)(`label`,{className:`block text-sm space-y-1`,children:[`New PIN/password`,(0,Q.jsx)(W,{type:`password`,autoComplete:`new-password`,minLength:4,maxLength:1024,required:!0,value:o,onChange:e=>s(e.target.value),disabled:t||g})]}),(0,Q.jsxs)(`label`,{className:`block text-sm space-y-1`,children:[`Confirm new PIN/password`,(0,Q.jsx)(W,{type:`password`,autoComplete:`new-password`,required:!0,value:c,onChange:e=>l(e.target.value),disabled:t||g})]}),(0,Q.jsx)(U,{disabled:t||g||!!f,children:g?`Saving…`:`Save protection`})]}),m&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:m}),f&&(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border p-3`,children:[(0,Q.jsx)(`p`,{className:`text-sm`,children:`Save this recovery key now. It is shown only once and replaces any previous recovery key.`}),(0,Q.jsx)(`code`,{className:`block break-all select-all`,children:f}),(0,Q.jsx)(U,{variant:`outline`,onClick:()=>{p(``),r()},children:`I saved the recovery key`})]})]})}var _r=`h-8 rounded-md border bg-background px-2 text-sm outline-none focus:ring-2 focus:ring-ring`;function vr({title:e,hint:t,children:n}){let[r,i]=(0,Z.useState)(!1);return(0,Q.jsxs)(`section`,{className:`overflow-hidden rounded-lg border`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),"aria-expanded":r,className:`flex w-full items-center justify-between gap-4 px-4 py-3 text-left transition-colors hover:bg-muted/40`,children:[(0,Q.jsxs)(`span`,{className:`min-w-0`,children:[(0,Q.jsx)(`span`,{className:`block text-sm font-medium`,children:e}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:t})]}),(0,Q.jsx)(b,{className:ye(`h-4 w-4 shrink-0 text-muted-foreground transition-transform motion-reduce:transition-none`,r&&`rotate-180`)})]}),r&&(0,Q.jsx)(`div`,{className:`border-t p-4`,children:n})]})}function yr({workspaceName:e,value:t,onChange:n,disabled:r}){let[i,a]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`label`,{className:`text-xs font-medium`,children:[`Only this folder `,(0,Q.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional)`})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(W,{value:t,disabled:r,onChange:e=>n(e.target.value),placeholder:`Whole workspace`,className:`h-8 font-mono text-sm`}),(0,Q.jsx)(U,{type:`button`,size:`sm`,variant:`outline`,disabled:r,onClick:()=>a(!0),title:`Pick a folder or context from the tree`,children:(0,Q.jsx)(ne,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Includes everything below it. Pick from the tree, or type `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`ctx://work/project`}),` or`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`dir://photos`}),`.`]}),i&&(0,Q.jsx)(St,{onClose:()=>a(!1),children:(0,Q.jsx)(Ce,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,fixedWorkspaceName:e,multiple:!1,onClose:()=>a(!1),onConfirm:(e,t)=>{let r=e[0];r&&n(`${t.treeType===`directory`?`dir`:`ctx`}://${r.replace(/^\/+/,``)}`),a(!1)}})})]})}function br({workspaceId:e,workspaceName:t,refreshKey:n,onRefresh:r}){let{showToast:i}=q(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),l=(0,Z.useCallback)(()=>Sn(e).then(e=>o(e.queue??null)).catch(()=>{}),[e]);(0,Z.useEffect)(()=>{l();let e=window.setInterval(()=>{o(e=>(e&&(e.pending>0||e.draining)&&l(),e))},3e3);return()=>window.clearInterval(e)},[l,n]);let u=async()=>{if(a){c(!0);try{let e=await tt(!a.paused,t);i({title:e.paused?`Indexing paused`:`Indexing resumed`,description:e.paused?`${e.pending.toLocaleString()} document(s) on hold. Resume any time; a server restart also resumes.`:`${e.pending.toLocaleString()} document(s) being indexed.`}),await l()}catch(e){i({title:`Error`,description:e instanceof Error?e.message:`Failed to pause or resume indexing (admin only)`,variant:`destructive`})}finally{c(!1)}}},d=!!a?.draining,f=a?a.paused?`bg-warning`:d?`bg-success`:`bg-muted-foreground/40`:`bg-muted-foreground/40`;return(0,Q.jsxs)(`section`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2 rounded-lg border bg-muted/30 px-4 py-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-sm`,children:[(0,Q.jsxs)(`span`,{className:`relative flex h-2 w-2 shrink-0`,"aria-hidden":!0,children:[d&&(0,Q.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full bg-success opacity-60 motion-reduce:hidden`}),(0,Q.jsx)(`span`,{className:ye(`relative inline-flex h-2 w-2 rounded-full`,f)})]}),(0,Q.jsx)(`span`,{className:`font-medium`,children:a?a.pending>0?(0,Q.jsxs)(Q.Fragment,{children:[a.pending.toLocaleString(),` `,(0,Q.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`document(s) waiting to be indexed`})]}):a.paused?`Paused`:`Up to date`:`Inference service not reachable`}),a?.paused&&a.pending>0&&(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`(paused)`}),a?.ingestDisabled&&(0,Q.jsx)(`span`,{className:`rounded bg-warning-subtle px-1.5 py-0.5 text-[10px] font-medium text-warning`,title:`CANVAS_INFERD_INGEST_DISABLED=true: new documents are not indexed for meaning search; what is already indexed still works`,children:`indexing turned off on the server`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[a&&(0,Q.jsx)(U,{type:`button`,size:`sm`,variant:`ghost`,disabled:s,onClick:u,title:a.paused?`Resume; the waiting documents get indexed`:`Pause after the current batch. Stops the CPU-heavy model work; new documents are still found by word search.`,children:s?`…`:a.paused?`Resume`:`Pause`}),(0,Q.jsx)(U,{type:`button`,size:`sm`,variant:`ghost`,onClick:r,title:`Reload`,children:(0,Q.jsx)(z,{className:`h-3.5 w-3.5`})})]})]})}function xr({workspaceId:e,tables:t,error:n,onChanged:r}){let{showToast:i}=q(),[a,o]=(0,Z.useState)(null),s=t.filter(e=>!e.active),c=async t=>{if(window.confirm(`Reclaim "${t.name}"?\n\nThis permanently deletes the index built with ${t.model||`that model`}. Switching back to it afterwards means indexing every document again instead of being instant.\n\nThis is the only step here that cannot be undone.`)){o(t.name);try{let n=await xn(e,t.name);if(!n.dropped)throw Error(n.error||`Failed to drop the vector table`);i({title:`Deleted`,description:`Removed '${n.name||t.name}'.`}),r()}catch(e){i({title:`Error`,description:e instanceof Error?e.message:`Failed to delete`,variant:`destructive`})}finally{o(null)}}};return n?(0,Q.jsxs)(`section`,{className:`rounded-lg border border-destructive/40 bg-destructive-subtle p-4`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium text-destructive`,children:`Stored indexes unavailable`}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n})]}):s.length===0?null:(0,Q.jsx)(vr,{title:`Previous models (${s.length})`,hint:`Indexes built with models you switched away from. They stay on disk so switching back is instant. Deleting one frees the space for good.`,children:(0,Q.jsx)(`div`,{className:`divide-y`,children:s.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-2 first:pt-0 last:pb-0`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`p`,{className:`truncate font-mono text-xs`,children:[e.model||`unknown model`,e.dim?` · ${e.dim}-d`:``]}),(0,Q.jsxs)(`p`,{className:`truncate font-mono text-[11px] text-muted-foreground`,children:[`└─ `,e.name]})]}),(0,Q.jsxs)(U,{type:`button`,size:`sm`,variant:`ghost`,className:`text-destructive hover:text-destructive`,disabled:a===e.name,onClick:()=>c(e),title:`Permanently delete the index built with this model`,children:[(0,Q.jsx)(I,{className:`mr-1.5 h-3.5 w-3.5`}),a===e.name?`Deleting…`:`Delete`]})]},e.name))})})}function Sr({workspaceId:e,workspaceName:t,spaces:n,onDone:r}){let{showToast:i}=q(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(!1);return(0,Q.jsxs)(vr,{title:`Index existing documents`,hint:`Add documents that are not in meaning search yet, for example after switching models. Limit it to one folder to try a model on a small set first.`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-medium`,children:`Content type`}),(0,Q.jsxs)(`select`,{className:`${_r} w-full`,value:a,onChange:e=>o(e.target.value),children:[(0,Q.jsx)(`option`,{value:``,children:`All content types`}),n.map(e=>(0,Q.jsx)(`option`,{value:e,children:vn(e)},e))]})]}),(0,Q.jsx)(yr,{workspaceName:t,value:s,onChange:c,disabled:d})]}),(0,Q.jsxs)(`label`,{className:`mt-3 flex items-start gap-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:l,onChange:e=>u(e.target.checked)}),(0,Q.jsxs)(`span`,{children:[`Also redo documents that are already indexed`,l&&s.trim()&&(0,Q.jsx)(`span`,{className:`mt-1 block text-[11px] text-warning`,children:`Even with a folder limit, this clears the whole index for the chosen content type, not just that folder. Leave it off unless you want to redo everything.`})]})]}),(0,Q.jsx)(U,{type:`button`,size:`sm`,className:`mt-3`,onClick:async()=>{f(!0);try{let t=await gn(e,{space:a||void 0,reindex:l,scope:s.trim()||void 0});t.ingestDisabled?i({title:`Indexing is turned off on the server`,description:`CANVAS_INFERD_INGEST_DISABLED=true: nothing was queued. What is already indexed still works.`,variant:`destructive`}):i({title:`Indexing queued`,description:`${t.enqueued.toLocaleString()} document(s) queued${t.scope?` under ${t.scope}`:``}. The status line above shows progress.`}),r()}catch(e){i({title:`Indexing failed to start`,description:e instanceof Error?e.message:`Failed to queue`,variant:`destructive`})}finally{f(!1)}},disabled:d,children:d?`Queueing…`:`Start indexing`})]})}var Cr=[{provider:`blip`,model:`HuggingFaceTB/SmolVLM-500M-Instruct`,task:`instruct`,label:`SmolVLM 500M: follows your instructions (recommended)`,note:`About 500 MB. Follows the instructions below, so you can ask for what matters to you, such as style, materials or setting.`},{provider:`blip`,model:`HuggingFaceTB/SmolVLM-256M-Instruct`,task:`instruct`,label:`SmolVLM 256M: smaller, follows your instructions`,note:`About 250 MB. Same instructions, less detail; for servers short on memory.`},{provider:`blip`,model:`onnx-community/Florence-2-base-ft`,task:`florence2`,label:`Florence-2 base: detailed, fixed style`,note:`Writes several detailed sentences, but ignores instructions.`},{provider:`blip`,model:`Xenova/vit-gpt2-image-captioning`,task:`caption`,label:`vit-gpt2: one short sentence (smallest)`,note:`One terse sentence per image, sometimes repetitive. Uses the least memory.`}],wr=`custom`,Tr=[{value:`instruct`,label:`Follows instructions (instruct VLM)`},{value:`florence2`,label:`Florence-2 family`},{value:`caption`,label:`Plain captioner, image only`}],Er=`Describe this photograph in two or three sentences. If it shows a building or interior, name the architectural style, the main materials and the setting. Describe only what is visible.`;function Dr({workspaceId:e,workspaceName:t,config:n,saving:r,onSave:i}){let{showToast:a}=q(),o=n.workspace||{},s=n.effective||{},c=Cr[0],l=o.summarize?.image||s.summarize?.image||{},[u,d]=(0,Z.useState)(()=>s.summarize?.image?.enabled===!0||o.summarize?.image?.enabled===!0),[f,p]=(0,Z.useState)(()=>{let e=Cr.find(e=>e.provider===(l.provider||c.provider)&&e.model===l.model);return e?`${e.provider}::${e.model}`:l.model?wr:`${c.provider}::${c.model}`}),[m,h]=(0,Z.useState)(()=>Cr.some(e=>e.model===l.model)?``:l.model||``),[g,_]=(0,Z.useState)(()=>l.task||`instruct`),[v,y]=(0,Z.useState)(()=>l.prompt||``),[b,x]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)(null),[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(``),M=Cr.find(e=>`${e.provider}::${e.model}`===f),N=f===wr,P=N?{provider:c.provider,model:m.trim(),task:g,label:`Custom`,note:``}:M||c,F=P.task===`instruct`,ee=(0,Z.useCallback)(()=>Sn(e).then(e=>C(e.summarize||null)).catch(()=>{}),[e]);(0,Z.useEffect)(()=>{ee();let e=window.setInterval(()=>{C(e=>(e?.running&&ee(),e))},2e3);return()=>window.clearInterval(e)},[ee]);let te=async()=>{await i({...o,summarize:{...o.summarize||{},image:{enabled:u,provider:P.provider,model:P.model,task:P.task,...F&&v.trim()?{prompt:v.trim()}:{}}}}),x(!1)},I=async()=>{D(!0);try{C(await _n(e)),a({title:`Stopping image descriptions`,description:`The current image finishes first; the rest are left for a later run.`})}catch(e){a({title:`Could not stop`,description:e instanceof Error?e.message:`Failed to stop`,variant:`destructive`})}finally{D(!1)}},ne=async(t=!1)=>{T(!0);try{let n=await bn(e,{force:t,scope:A.trim()||void 0});C(n),a({title:t?`Describing all images again`:`Describing images`,description:`${n.total.toLocaleString()} image(s)${n.scope?` under ${n.scope}`:``}. The first run downloads the model, which can take a few minutes.`})}catch(e){a({title:`Image descriptions failed to start`,description:e instanceof Error?e.message:`Failed to start`,variant:`destructive`})}finally{T(!1)}},L=s.summarize?.image?.enabled===!0,R=S?.running===!0,re=S?.errors?.[0]?.error;return(0,Q.jsx)(vr,{title:`Image descriptions`,hint:`A vision model writes a few sentences about each image, so you can find photos by what is in them.`,children:(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:u,disabled:r,onChange:e=>{d(e.target.checked),x(!0)}}),`Describe images`]}),(0,Q.jsxs)(`select`,{className:_r,value:f,disabled:r||!u,onChange:e=>{p(e.target.value),x(!0)},children:[Cr.map(e=>(0,Q.jsx)(`option`,{value:`${e.provider}::${e.model}`,children:e.label},`${e.provider}::${e.model}`)),(0,Q.jsx)(`option`,{value:wr,children:`Custom model…`})]}),!N&&(0,Q.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:P.model})]}),N&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(W,{className:`h-8 w-72 font-mono text-xs`,placeholder:`org/model-id (Hugging Face, ONNX)`,value:m,disabled:r||!u,onChange:e=>{h(e.target.value),x(!0)}}),(0,Q.jsx)(`select`,{className:_r,value:g,disabled:r||!u,onChange:e=>{_(e.target.value),x(!0)},children:Tr.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),u&&P.note&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:P.note}),u&&F&&(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`textarea`,{className:`w-full rounded-md border border-input bg-transparent p-2 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`,rows:3,placeholder:Er,value:v,disabled:r,onChange:e=>{y(e.target.value),x(!0)}}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`What to ask about every image. Leave empty to use the default shown above. Descriptions become searchable, so ask for the details you would search by.`})]}),S&&(S.running||S.total>0||S.finishedAt)&&(0,Q.jsxs)(`p`,{className:ye(`text-xs`,S.aborted?`text-destructive`:`text-muted-foreground`),children:[R?`Running`:S.aborted?`Stopped`:S.cancelled?`Cancelled`:`Last run`,S.scope?(0,Q.jsxs)(Q.Fragment,{children:[` under `,(0,Q.jsx)(`span`,{className:`font-mono`,children:S.scope})]}):null,`: `,S.described,`/`,S.total,` described`,S.skipped?`, ${S.skipped} skipped`:``,S.failed?`, ${S.failed} failed`:``,S.aborted?`. ${S.abortedReason||`The model stopped working`}. The remaining images were not tried; run again to retry.`:S.cancelled?`. Stopped by you. The remaining images were left untouched; run again to continue.`:re?`. ${re}`:``]}),(0,Q.jsx)(yr,{workspaceName:t,value:A,onChange:j,disabled:r||R}),(0,Q.jsxs)(`label`,{className:`flex items-start gap-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:O,disabled:r||R,onChange:e=>k(e.target.checked)}),(0,Q.jsxs)(`span`,{children:[`Also redo images that already have a description`,O&&(0,Q.jsxs)(`span`,{className:`mt-1 block text-[11px] text-warning`,children:[`Replaces existing descriptions`,A.trim()?` in that folder`:``,`, including ones written by another model. Leave this off to describe only images that have none yet.`]})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Turn on and save, then run. Descriptions are generated on this server; the first run downloads the model.`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(U,{size:`sm`,variant:`outline`,onClick:()=>void te(),disabled:r||!b,children:`Save`}),(0,Q.jsx)(U,{size:`sm`,onClick:()=>void ne(O),disabled:r||b||w||R||!L,title:L?b?`Save your changes first`:O?`Describe every image again, replacing existing descriptions`:`Describe images that have no description yet`:`Turn on image descriptions and save first`,children:R||w?`Running…`:O?`Describe all again`:`Describe missing`}),R&&(0,Q.jsx)(U,{size:`sm`,variant:`destructive`,onClick:()=>void I(),disabled:E,title:`Finish the current image, then stop. The rest are left for later.`,children:E?`Stopping…`:`Stop`})]})]})]})})}function Or({workspaceId:e,workspaceName:t}){let{showToast:n}=q(),[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)([]),[s,c]=(0,Z.useState)(),[l,u]=(0,Z.useState)(!0),[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)([]),[_,v]=(0,Z.useState)(0),y=(0,Z.useCallback)(()=>yn(e).then(e=>{i(e),m(null)}).catch(e=>m(e instanceof Error?e.message:`Failed to load the search settings`)).finally(()=>u(!1)),[e]),b=(0,Z.useCallback)(()=>mn(e).then(e=>{o(e.tables||[]),c(e.error)}).catch(e=>c(e instanceof Error?e.message:`Failed to list stored indexes`)),[e]);(0,Z.useEffect)(()=>{y(),b()},[y,b]);let x=()=>{u(!0),y(),b(),v(e=>e+1)},S=async t=>{f(!0);try{let r=await hn(e,t);g(r.movedSpaces||[]),r.movedSpaces?.length?n({title:`Saved: now index your existing documents`,description:`${r.movedSpaces.map(vn).join(`, `)}: new model in use. New documents use it right away; existing ones need indexing (button on the row).`}):r.applied===!1?n({title:`Saved: applies on next start`,description:`The workspace is not running, so the changes take effect when it starts.`}):n({title:`Saved`,description:`Search settings updated.`}),await y(),await b()}catch(e){n({title:`Save failed`,description:e instanceof Error?e.message:`Failed to save`,variant:`destructive`})}finally{f(!1)}},C=async t=>{try{let r=await gn(e,{space:t});if(r.ingestDisabled){n({title:`Indexing is turned off on the server`,description:`CANVAS_INFERD_INGEST_DISABLED=true: nothing was queued. What is already indexed still works.`,variant:`destructive`});return}n({title:`Indexing ${vn(t).toLowerCase()}`,description:`${r.enqueued.toLocaleString()} document(s) queued. The status line above shows progress.`}),g(e=>e.filter(e=>e!==t)),v(e=>e+1),b()}catch(e){n({title:`Indexing failed to start`,description:e instanceof Error?e.message:`Failed to queue`,variant:`destructive`})}};if(l)return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(z,{className:`h-4 w-4 animate-spin`}),`Loading search settings…`]});if(p||!r)return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`rounded-lg border border-destructive/40 bg-destructive-subtle p-4 text-sm`,children:[(0,Q.jsx)(`p`,{className:`font-medium text-destructive`,children:`Search settings unavailable`}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:p||`No config returned.`})]}),(0,Q.jsx)(U,{type:`button`,size:`sm`,variant:`outline`,onClick:x,children:`Try again`})]});let w=Object.keys(r.effective.spaces||{}).sort();return(0,Q.jsxs)(`div`,{className:`space-y-5`,children:[(0,Q.jsx)(br,{workspaceId:e,workspaceName:t,refreshKey:_,onRefresh:x}),(0,Q.jsx)(Cn,{value:r.workspace||{},effective:r.effective||{},inherited:r.inherited||{},resolvedSpaces:r.spaces,invalid:r.invalid,attention:h,onFill:C,saving:d,saveLabel:`Save models`,onSave:S},JSON.stringify(r.workspace)),(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsx)(Dr,{workspaceId:e,workspaceName:t,config:r,saving:d,onSave:S},`summarize:${JSON.stringify(r.workspace?.summarize||{})}`),(0,Q.jsx)(Sr,{workspaceId:e,workspaceName:t,spaces:w,onDone:()=>{b(),v(e=>e+1)}}),(0,Q.jsx)(xr,{workspaceId:e,tables:a,error:s,onChanged:()=>{b()}})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`These settings are saved with the workspace (in its `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`workspace.json`}),`), so they move with it. Anything not set here comes from your personal defaults, then the server's. Changes apply immediately, with no restart.`]})]})}function kr(e){let n=(e||``).split(`.`).pop()?.toLowerCase();switch(n){case`js`:case`mjs`:case`ts`:return[a({typescript:n===`ts`})];case`json`:return[i()];case`sh`:case`bash`:return[t.define(o)];default:return[]}}function Ar({value:e,onChange:t,path:r,className:i=``}){let a=(0,Z.useMemo)(()=>kr(r),[r]),{resolvedScheme:o}=tn();return(0,Q.jsx)(n,{value:e,onChange:t,extensions:a,theme:o===`dark`?`dark`:`light`,className:i,basicSetup:{lineNumbers:!0,foldGutter:!0,highlightActiveLine:!0,bracketMatching:!0,autocompletion:!1}})}function jr(e,t){if(![`download`,`store`].includes(e.action)||e.recursive===!0&&!t)return null;let n=String(e.folder||``);return n.includes(`{{`)?null:[n,(e.recursive===!0?e.pathMode===`full`?t?.path:t?.rel:``)||``].join(`/`).split(`/`).filter(e=>e&&e!==`.`&&e!==`..`).join(`/`)}function Mr(e,t){if(![`download`,`store`].includes(e.action)||typeof e.to!=`string`)return null;if(e.recursive===!0&&!t)return`Missing filing path — decline and trigger the rule again`;let n=jr(e,t);return n===null?null:`${e.to}/${n}`}function Nr(e,t){let n=jr(e,t);if(n===null||e.recursive!==!0||e.autoLink===!0)return{...e};let r={...e,folder:n};return delete r.recursive,delete r.pathMode,r}function Pr(e,t){let n=structuredClone({actions:e.actions});for(let[r,i]of Object.entries(t)){if(!e.editable.includes(r))continue;let t=r.split(`.`);if(t[0]!==`actions`||t.some(e=>[`__proto__`,`prototype`,`constructor`].includes(e)))continue;let a=n;for(let e of t.slice(0,-1)){if(!a[e]||typeof a[e]!=`object`){a={};break}a=a[e]}a[t[t.length-1]]=i}return n.actions}var Fr=[`pending`,`approved`,`declined`,`failed`,`expired`,`all`],Ir={pending:`text-warning dark:text-warning`,approved:`text-success dark:text-success`,declined:`text-muted-foreground`,failed:`text-destructive`,expired:`text-muted-foreground line-through`};function Lr(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`now`;if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h`:`${Math.floor(r/24)}d`}function Rr(e,t){return t.split(`.`).reduce((e,t)=>typeof e==`object`&&e?e[t]:void 0,e)}function zr(e){let t=e.split(`.`);return t.slice(Math.max(t.length-2,2)).join(`.`)}var Br=/(body|content|message|text|prompt)$/i,Vr=2e3;function Hr({workspaceId:e,id:t,children:n}){let{open:r}=Ct(),{showToast:i}=q(),[a,o]=(0,Z.useState)(!1),s=async n=>{n.stopPropagation(),o(!0);try{r(await Be(e,t),e)}catch(e){i({title:`Document ${t} not available`,description:e instanceof Error?e.message:void 0,variant:`destructive`})}finally{o(!1)}};return(0,Q.jsx)(`button`,{type:`button`,disabled:a,onClick:e=>void s(e),className:`text-primary underline-offset-2 hover:underline disabled:opacity-60`,title:`Open document ${t}`,children:n??`doc ${t}`})}function Ur({workspaceId:e,text:t}){let n=t.split(/(\bdoc \d+\b)/);return(0,Q.jsx)(Q.Fragment,{children:n.map((t,n)=>{let r=/^doc (\d+)$/.exec(t);return r?(0,Q.jsx)(Hr,{workspaceId:e,id:Number(r[1])},n):(0,Q.jsx)(Z.Fragment,{children:t},n)})})}function Wr({action:e,amend:t,onAmend:n}){return e.editable?.length?(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.editable.map(r=>{let i=Rr(e,r),a=typeof i==`string`,o=r in t?t[r]:i,s=a?String(o??``):JSON.stringify(o,null,2),c=a&&(Br.test(r)||s.length>80);return(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsxs)(`span`,{className:`font-medium text-muted-foreground`,children:[zr(r),(0,Q.jsx)(`span`,{className:`ml-1.5 font-mono text-[10px] opacity-60`,children:r}),r in t&&(0,Q.jsx)(`span`,{className:`ml-1.5 text-warning dark:text-warning`,children:`edited`})]}),c?(0,Q.jsx)(`textarea`,{className:`mt-1 w-full rounded-md border bg-background px-2 py-1.5 font-mono text-xs outline-none focus:ring-2 focus:ring-ring min-h-[100px]`,value:s,onChange:e=>n(r,e.target.value)}):(0,Q.jsx)(`input`,{className:`mt-1 w-full h-8 rounded-md border bg-background px-2 font-mono text-xs outline-none focus:ring-2 focus:ring-ring`,value:s,onChange:e=>{if(a){n(r,e.target.value);return}try{n(r,JSON.parse(e.target.value))}catch{n(r,e.target.value)}}})]},r)})}):null}function Gr({workspaceId:e,onPendingCount:t}){let{showToast:n}=q(),r=wn(),[i,a]=(0,Z.useState)(`pending`),[o,s]=(0,Z.useState)([]),[c,l]=(0,Z.useState)(0),[u,d]=(0,Z.useState)(!0),[f,p]=(0,Z.useState)(new Set),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)({}),[v,y]=(0,Z.useState)(!1),x=(0,Z.useRef)(0),S=(0,Z.useCallback)(()=>{let r=++x.current,a=i===`pending`?null:Mt(e,{status:`pending`,limit:1}).then(({total:e})=>e);return Mt(e,{status:i===`all`?void 0:i,limit:200}).then(async({actions:e,total:n})=>{let i=a===null?n:await a;r===x.current&&(s(e),l(n),p(t=>new Set(e.filter(e=>e.status===`pending`&&t.has(e.actionId)).map(e=>e.actionId))),t?.(i))}).catch(()=>{r===x.current&&n({title:`Error`,description:`Failed to load pending actions`,variant:`destructive`})}).finally(()=>{r===x.current&&d(!1)})},[e,i]),C=(0,Z.useCallback)(async()=>{d(!0),await S()},[S]),[w,E]=(0,Z.useState)(`${e}|${i}`),O=`${e}|${i}`;O!==w&&(E(O),d(!0)),(0,Z.useEffect)(()=>{S()},[S]);let k=(0,Z.useRef)(S);(0,Z.useEffect)(()=>{k.current=S});let A=(0,Z.useRef)(null),j=(0,Z.useRef)(0);(0,Z.useEffect)(()=>()=>{A.current!==null&&window.clearTimeout(A.current)},[]),Tn(r,`workspace:${e}`,(0,Z.useMemo)(()=>{let e=()=>{if(A.current!==null)return;let e=Math.max(0,j.current+Vr-Date.now());A.current=window.setTimeout(()=>{A.current=null,j.current=Date.now(),k.current()},e)};return{"action.proposed":e,"action.approved":e,"action.declined":e,"action.failed":e}},[]));let[M,N]=(0,Z.useState)(null),P=M?.state===`running`;(0,Z.useEffect)(()=>{let t=!1;return Xt(e).then(e=>{t||N(e)}).catch(()=>{}),()=>{t=!0}},[e]),(0,Z.useEffect)(()=>{if(!P)return;let t=window.setInterval(()=>{Xt(e).then(e=>{N(e),k.current()}).catch(()=>{})},Vr);return()=>window.clearInterval(t)},[e,P]);let F=async(t,r,i)=>{if(window.confirm(i))try{N(await kt(e,{decision:t,nothingToDo:r}))}catch(e){n({title:`Could not start`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}},te=o.filter(e=>e.status===`pending`),I=te.length>0&&te.every(e=>f.has(e.actionId)),ne=()=>{p(I?new Set:new Set(te.map(e=>e.actionId)))},L=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},R=(e,t,n)=>{_(r=>({...r,[e]:{...r[e],[t]:n}}))},re=async(t,r)=>{if(!(!t.length&&!r.length)){y(!0);try{let i=await qt(e,{approve:t.map(e=>{let t=g[e];return t&&Object.keys(t).length?{actionId:e,amend:t}:e}),decline:r}),a=i.results.filter(e=>e.status===`error`||e.status===`failed`);a.length?n({title:`${a.length} of ${i.decided} failed`,description:a.map(e=>`${e.actionId}: ${e.error??`execution failed`}`).join(`; `),variant:`destructive`}):n({title:t.length&&r.length?`Decisions applied`:t.length?`Approved ${t.length}`:`Declined ${r.length}`,description:t.length?`Approved actions executed with their original provenance.`:void 0}),_(e=>{let n={...e};for(let e of[...t,...r])delete n[e];return n}),p(new Set),m&&[...t,...r].includes(m)&&h(null),await C()}catch(e){n({title:`Decision failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{y(!1)}}};return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`select`,{className:`h-8 rounded-md border bg-background px-2 text-xs outline-none focus:ring-2 focus:ring-ring`,value:i,onChange:e=>a(e.target.value),children:Fr.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))}),(0,Q.jsx)(U,{size:`sm`,variant:`ghost`,onClick:()=>void C(),title:`Reload`,children:(0,Q.jsx)(z,{className:`h-4 w-4`})}),c>o.length&&(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Showing `,o.length,` of `,c]})]}),f.size>0&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[f.size,` selected`]}),(0,Q.jsxs)(U,{size:`sm`,disabled:v,onClick:()=>void re([...f],[]),children:[(0,Q.jsx)(T,{className:`mr-1 h-3.5 w-3.5`}),` Approve`]}),(0,Q.jsxs)(U,{size:`sm`,variant:`outline`,disabled:v,onClick:()=>void re([],[...f]),children:[(0,Q.jsx)(D,{className:`mr-1 h-3.5 w-3.5`}),` Decline`]})]})]}),i===`pending`&&(c>0||M)&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap text-xs`,children:[c>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(U,{size:`sm`,variant:`outline`,disabled:P||v,onClick:()=>void F(`approve`,!1,`Approve and run all ${c} pending actions?`),children:`Approve all`}),(0,Q.jsx)(U,{size:`sm`,variant:`outline`,disabled:P||v,title:`Declines the actions whose document is gone or has nothing for them to work on, such as an email without a matching attachment`,onClick:()=>void F(`decline`,!0,`Decline the pending actions that have nothing to do? The rest of the ${c} stay in the queue.`),children:`Decline those with nothing to do`}),(0,Q.jsx)(U,{size:`sm`,variant:`outline`,disabled:P||v,onClick:()=>void F(`decline`,!1,`Decline all ${c} pending actions?`),children:`Decline all`})]}),M&&(0,Q.jsxs)(`span`,{className:M.state===`failed`?`text-destructive`:`text-muted-foreground`,children:[M.state===`running`?`Running: `:M.state===`failed`?`Stopped (${M.error}): `:`Last run: `,M.decision===`approve`?`approved`:`declined`,` `,M.decided,` of `,M.total,M.kept>0&&`, kept ${M.kept}`,M.failed>0&&`, ${M.failed} failed`]})]}),(0,Q.jsx)(`div`,{className:`border rounded-lg overflow-auto max-h-[560px]`,children:u?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground p-3`,children:`Loading...`}):o.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground p-3`,children:i===`pending`?`Nothing waiting for review. Rules or hooks with approval enabled queue their actions here.`:`No ${i===`all`?``:i+` `}actions recorded.`}):(0,Q.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Q.jsx)(`thead`,{className:`text-xs text-muted-foreground border-b sticky top-0 bg-background`,children:(0,Q.jsxs)(`tr`,{children:[(0,Q.jsx)(`th`,{className:`px-3 py-2 w-8`,children:te.length>0&&(0,Q.jsx)(`input`,{type:`checkbox`,checked:I,onChange:ne,title:`Select all pending`})}),(0,Q.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Proposed action`}),(0,Q.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Handler`}),(0,Q.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Age`}),(0,Q.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Status`}),(0,Q.jsx)(`th`,{className:`px-2 py-2 w-40`})]})}),(0,Q.jsx)(`tbody`,{children:o.map(t=>{let n=t.status===`pending`||t.status===`failed`,r=m===t.actionId,i=r?Pr(t,n?g[t.actionId]??{}:{}):t.actions,a=t.envelope?.payload?.document;return(0,Q.jsxs)(Z.Fragment,{children:[(0,Q.jsxs)(`tr`,{className:`border-b last:border-0 align-top hover:bg-muted/40 cursor-pointer`,onClick:()=>h(r?null:t.actionId),children:[(0,Q.jsx)(`td`,{className:`px-3 py-2`,onClick:e=>e.stopPropagation(),children:t.status===`pending`&&(0,Q.jsx)(`input`,{type:`checkbox`,checked:f.has(t.actionId),onChange:()=>L(t.actionId)})}),(0,Q.jsxs)(`td`,{className:`px-3 py-2`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 font-medium`,children:[r?(0,Q.jsx)(b,{className:`h-3 w-3 shrink-0`}):(0,Q.jsx)(ee,{className:`h-3 w-3 shrink-0`}),t.title,t.editable?.length>0&&(0,Q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide rounded bg-muted-foreground/15 px-1 py-0.5 text-muted-foreground shrink-0`,children:`editable`})]}),t.summary&&(0,Q.jsx)(`span`,{className:`block text-xs text-muted-foreground pl-4`,children:(0,Q.jsx)(Ur,{workspaceId:e,text:t.summary})})]}),(0,Q.jsxs)(`td`,{className:`px-3 py-2 font-mono text-xs whitespace-nowrap`,children:[(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[t.handlerType,`:`]}),t.handler,t.event&&(0,Q.jsxs)(`span`,{className:`block text-muted-foreground`,children:[t.event,a?.id!=null&&(0,Q.jsxs)(Q.Fragment,{children:[` · `,(0,Q.jsx)(Hr,{workspaceId:e,id:a.id})]})]})]}),(0,Q.jsx)(`td`,{className:`px-3 py-2 text-xs whitespace-nowrap`,title:t.ts,children:Lr(t.ts)}),(0,Q.jsxs)(`td`,{className:`px-3 py-2 text-xs`,children:[(0,Q.jsx)(`span`,{className:Ir[t.status],children:t.status}),t.amended&&(0,Q.jsx)(`span`,{className:`block text-muted-foreground`,children:`amended`}),t.decidedBy&&(0,Q.jsx)(`span`,{className:`block text-muted-foreground truncate max-w-[120px]`,title:t.decidedBy,children:t.decidedBy})]}),(0,Q.jsx)(`td`,{className:`px-2 py-2 whitespace-nowrap text-right`,onClick:e=>e.stopPropagation(),children:n&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(U,{size:`sm`,className:`h-7 px-2`,disabled:v,title:t.status===`failed`?`Retry (re-approve)`:`Approve and execute`,onClick:()=>void re([t.actionId],[]),children:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})}),t.status===`pending`&&(0,Q.jsx)(U,{size:`sm`,variant:`ghost`,className:`h-7 px-2 text-muted-foreground`,disabled:v,title:`Decline`,onClick:()=>void re([],[t.actionId]),children:(0,Q.jsx)(D,{className:`h-3.5 w-3.5`})})]})})]}),r&&(0,Q.jsxs)(`tr`,{className:`border-b last:border-0 bg-muted/20`,children:[(0,Q.jsx)(`td`,{className:`px-3 py-3`}),(0,Q.jsxs)(`td`,{className:`px-3 py-3 space-y-3`,colSpan:5,children:[n&&t.editable?.length>0&&(0,Q.jsx)(Wr,{action:t,amend:g[t.actionId]??{},onAmend:(e,n)=>R(t.actionId,e,n)}),i.map((e,n)=>{let r=Mr(e,t.pathMatch);return r&&(0,Q.jsxs)(`p`,{className:`text-xs`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Destination folder: `}),(0,Q.jsx)(`span`,{className:`font-mono break-all`,children:r})]},n)}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:`Actions on approve`}),(0,Q.jsx)(`pre`,{className:`mt-1 rounded border bg-background p-2 font-mono text-xs overflow-auto max-h-56`,children:JSON.stringify(i.map(e=>Nr(e,t.pathMatch)),null,2)})]}),(0,Q.jsxs)(`details`,{className:`text-xs text-muted-foreground`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer`,children:`Rule action settings`}),(0,Q.jsx)(`pre`,{className:`mt-1 rounded border bg-background p-2 font-mono overflow-auto max-h-56`,children:JSON.stringify(i,null,2)})]}),t.result&&t.result.length>0&&(0,Q.jsx)(`div`,{className:`text-xs font-mono`,children:t.result.map((e,t)=>(0,Q.jsxs)(`span`,{className:`mr-2 ${e.status===`error`?`text-destructive`:`text-muted-foreground`}`,children:[e.action,`:`,e.status,e.error?` (${e.error})`:``]},t))}),(0,Q.jsxs)(`p`,{className:`text-[11px] text-muted-foreground font-mono`,children:[t.actionId,` · origin `,t.provenance?.origin,t.provenance?.causedBy?` · causedBy ${t.provenance.causedBy}`:``,t.expiresAt?` · expires ${new Date(t.expiresAt).toLocaleString()}`:``]})]})]})]},t.actionId)})})]})})]})}var Kr=`#!/usr/bin/env bash
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{a as t,i as n,l as r,n as i,r as a,t as o,u as s}from"./code-editor-BOIngd5F.js";import{_t as c}from"./react-BHzhHVTZ.js";import{_ as l,g as u,v as d}from"./chunk-62JRHF6Z-vspAGgtK.js";import{An as f,Bn as p,Bt as m,Cn as h,Ct as g,Er as _,Fn as v,G as y,Gr as b,H as x,It as S,J as C,Jn as w,Kr as T,Kt as E,L as D,Mt as O,Nt as k,Pt as A,Qt as j,Rr as M,Si as N,Tt as P,U as F,Ur as ee,Wn as te,X as I,Xn as ne,Xt as L,Z as R,Zn as re,_t as ie,an as ae,bt as oe,cn as se,ct as ce,ft as le,hr as ue,ii as de,kt as z,mr as B,pn as fe,pr as pe,pt as me,rt as he,st as ge,vn as _e,xr as ve,yi as V,yr as H}from"./ui-DEgHnkQu.js";import{t as ye}from"./utils-2pl1SbIp.js";import{t as U}from"./button--VYZekMF.js";import{t as W}from"./input-BOtCd4HP.js";import{t as G}from"./label-RuOXXC8t.js";import{c as be,l as xe,t as K}from"./api-CA6WiiYM.js";import{t as Se}from"./socket-CtH3EU9m.js";import{n as q}from"./use-toast-BlLDqSUO.js";import{t as Ce}from"./LinkToCard-oi3wGP0a.js";import{$ as we,A as Te,Bt as Ee,Et as De,F as Oe,I as ke,P as Ae,Q as je,Qt as Me,T as Ne,U as J,V as Y,Vt as Pe,Wt as Fe,Zt as Ie,_t as Le,cn as Re,d as ze,et as Be,f as Ve,gn as X,it as He,jt as Ue,k as We,ln as Ge,mn as Ke,mt as qe,n as Je,nn as Ye,pn as Xe,r as Ze,rn as Qe,sn as $e,st as et,tn as tt,vt as nt,wt as rt,xt as it}from"./workspace-4hWrSEku.js";import{a as at,c as ot,i as st,n as ct,o as lt,r as ut,s as dt,t as ft}from"./alert-dialog-BKtaX1_a.js";import{t as pt}from"./use-mobile-Db-vWu9Y.js";import{t as mt}from"./useEscapeClose-DR_xKT_k.js";import{o as ht}from"./layer-style-Byl5LNFR.js";import{i as gt,t as _t}from"./color-DFEH4BfK.js";import{a as vt,o as yt,s as bt,t as xt}from"./MessageComposerDialog-CLrwtB76.js";import{n as St}from"./LinkToSidePanel-eCy3nW4R.js";import{n as Ct}from"./use-document-modal-PG8bQyIB.js";import{A as wt,C as Tt,D as Et,E as Dt,F as Ot,L as kt,M as At,N as jt,O as Mt,P as Nt,S as Pt,T as Ft,_ as It,a as Lt,b as Rt,c as zt,d as Bt,f as Vt,g as Ht,h as Ut,i as Wt,k as Gt,n as Kt,p as qt,r as Jt,t as Yt,v as Xt,w as Zt,y as Qt}from"./rule-builder-CziPqpNe.js";import{t as $t}from"./workspace-access-C9nZlBBZ.js";import{i as en}from"./use-menu-CKSpS96u.js";import{t as tn}from"./use-theme-DaxpiICf.js";import{Ot as nn,ct as rn,dt as an,ft as on,lt as sn,mt as cn,pt as ln,ut as un,wt as dn,xt as fn}from"./index-NOhHv2VY.js";import{n as pn}from"./page-header-NyYSXjfY.js";import{c as mn,f as hn,l as gn,m as _n,n as vn,o as yn,p as bn,r as xn,s as Sn,t as Cn}from"./inferd-config-editor-Dpdj90iN.js";import{n as wn,t as Tn}from"./useSocketSubscription-ifW-vnlb.js";import{a as En,n as Dn,o as On,r as kn,t as An}from"./devices-CAa1bRxk.js";import{a as jn,i as Mn,n as Nn,o as Pn,t as Fn}from"./query-debug-PEWbZsOP.js";import{a as In,i as Ln,r as Rn,t as zn}from"./workspace-import-form-CWs9ZTts.js";var Z=e(s(),1),Bn=`workspace:backups`,Vn=e=>`${be.workspaces}/${encodeURIComponent(e)}/db/backups`,Hn=e=>K.get(Vn(e)),Un=e=>K.post(Vn(e),{action:`backup`}),Wn=(e,t)=>K.post(Vn(e),{action:`restore`,backupId:t,confirm:!0}),Gn=new Map;function Kn(e,t,n){let r=JSON.stringify([t,n.id]),i=Gn.get(r);if(i)return i;let a=(async()=>{let r=n.action===`restore`,i=e({title:r?`Restoring workspace database`:`Backing up workspace database`,description:r?`Stopping the workspace and preserving its current database…`:`Copying and verifying all datasets…`});try{let e=n;for(;e.status===`running`;){let n=await Hn(t),r=n.jobs.find(t=>t.id===e.id);if(!r)throw Error(`The server restarted. Refresh the backup list to check the result.`);e=r,window.dispatchEvent(new CustomEvent(Bn,{detail:{workspace:t,status:n}})),e.status===`running`&&await new Promise(e=>setTimeout(e,1500))}if(e.status===`failed`)throw Error(e.error||`Database operation failed`);i.done({title:r?`Workspace database restored`:`Workspace backup verified`,description:r?`The workspace is stopped. Start it when you are ready; search indexes will rebuild.`:`Documents, relations and virtual tree placements are saved.`})}catch(e){throw i.fail({title:`Workspace backup needs attention`,description:e instanceof Error?e.message:String(e),variant:`destructive`}),e}})();return Gn.set(r,a),a.finally(()=>Gn.delete(r)).catch(()=>{}),a}var Q=r(),qn={startup:`Startup`,hourly:`Hourly`,manual:`Manual`,"pre-restore":`Before restore`};function Jn({workspaceId:e,onRestored:t}){let{showToast:n,showProgress:r}=q(),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!1),f=(0,Z.useRef)(!1),p=(0,Z.useRef)(!1),m=(0,Z.useRef)(0),h=(0,Z.useCallback)(()=>{let t=++m.current;return Hn(e).then(n=>{if(!(!f.current||t!==m.current)){a(n),s(null);for(let t of n.jobs.filter(e=>e.status===`running`))Kn(r,e,t).catch(()=>{})}}).catch(e=>{f.current&&t===m.current&&s(e instanceof Error?e.message:String(e))})},[e,r]);(0,Z.useEffect)(()=>{f.current=!0,h();let t=t=>{let n=t.detail;n.workspace===e&&a(n.status)};return window.addEventListener(Bn,t),()=>{f.current=!1,window.removeEventListener(Bn,t)}},[e,h]);let g=async i=>{if(!p.current){p.current=!0,d(!0);try{let n=i?await Wn(e,i.id):await Un(e);f.current&&a(e=>e&&{...e,jobs:[n,...e.jobs]}),await Kn(r,e,n),i&&t()}catch(e){n({title:`Database operation did not complete`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}finally{p.current=!1,f.current&&(d(!1),h())}}},_=u||!!i?.jobs.some(e=>e.status===`running`),v=i?.jobs[0];return(0,Q.jsxs)(`div`,{className:`min-w-0 space-y-5`,children:[(0,Q.jsxs)(`section`,{className:`space-y-4 rounded border p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Q.jsx)(V,{className:`h-5 w-5 text-muted-foreground`}),(0,Q.jsx)(`h2`,{className:`font-semibold`,children:`Workspace checkpoints`}),(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,className:`ml-auto`,disabled:_||!i||!!o,onClick:()=>void g(),children:[_?(0,Q.jsx)(fe,{className:`mr-2 h-4 w-4 animate-spin`}):(0,Q.jsx)(V,{className:`mr-2 h-4 w-4`}),`Back up now`]})]}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Save a checkpoint before a bulk action. Each backup includes every document, relation and virtual tree placement in this workspace’s database.`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-x-5 gap-y-2 text-sm`,children:[(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:i?.retention.hourly??24}),` hourly backups`]}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:i?.retention.startup??14}),` startup backups`]}),(0,Q.jsx)(`span`,{children:`Manual checkpoints kept`})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Hourly backups run while the workspace is active. These checkpoints cover the database only; files in storage backends and workspace settings need their own backups.`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`h2`,{className:`text-sm font-semibold`,children:[`Verified checkpoints`,i?` · ${i.backups.length}`:``]}),(0,Q.jsx)(U,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>void h(),"aria-label":`Refresh backups`,children:(0,Q.jsx)(z,{className:`h-4 w-4`})})]}),o&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:o}),v&&(0,Q.jsx)(`p`,{role:`status`,className:`text-sm ${v.status===`failed`?`text-destructive`:`text-muted-foreground`}`,children:v.status===`running`?`Database operation in progress…`:v.status===`failed`?v.error:v.action===`restore`?`Database restored. The workspace is stopped and ready to start.`:`Backup complete and verified.`}),!i&&!o&&(0,Q.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Loading backups…`}),i?.backups.length===0&&(0,Q.jsx)(`p`,{className:`rounded border border-dashed p-6 text-sm text-muted-foreground`,children:`No verified checkpoints yet. Create one before your next bulk action.`}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:i?.backups.map(e=>(0,Q.jsxs)(`article`,{className:`flex min-w-0 flex-wrap items-center gap-3 rounded border p-3`,children:[(0,Q.jsx)(T,{className:`h-4 w-4 shrink-0 text-muted-foreground`,"aria-label":`Verified`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 basis-40`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:new Date(e.createdAt).toLocaleString()}),(0,Q.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[qn[e.kind],` · `,Y(e.bytes),` · `,(e.datasets.documents?.count??0).toLocaleString(),` documents`]})]}),(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,disabled:_,onClick:()=>l(e),children:[(0,Q.jsx)(P,{className:`mr-2 h-3.5 w-3.5`}),`Restore`]})]},e.id))}),(0,Q.jsx)(ft,{open:!!c,onOpenChange:e=>{e||l(null)},children:(0,Q.jsxs)(st,{className:`max-w-[calc(100vw-2rem)] sm:max-w-lg`,children:[(0,Q.jsxs)(dt,{children:[(0,Q.jsx)(ot,{children:`Restore this workspace checkpoint?`}),(0,Q.jsxs)(at,{children:[`The workspace will stop and its current database will be backed up first. Documents, relations and virtual tree placements will return to `,c?new Date(c.createdAt).toLocaleString():`the selected checkpoint`,`. Files in storage backends and workspace settings will stay as they are. The workspace stays stopped after restoration.`]})]}),(0,Q.jsxs)(lt,{children:[(0,Q.jsx)(ut,{children:`Cancel`}),(0,Q.jsx)(ct,{disabled:_,onClick:()=>{c&&g(c)},children:`Back up current & restore`})]})]})})]})}var Yn={collect:`Collect unused blobs`,verify:`Verify integrity`,compact:`Compact index`},Xn=e=>e.status===`queued`||e.status===`running`,Zn=e=>`${be.workspaces}/${encodeURIComponent(e)}/cache/maintenance`,Qn=e=>K.get(Zn(e)),$n=(e,t,n)=>K.post(Zn(e),{store:t,action:n,...n===`verify`?{confirm:!0}:{}});function er(e){if(e.status===`failed`)return e.error||`Maintenance failed`;if(e.status===`queued`)return`Waiting for active storage operations…`;if(e.status===`running`)return e.action===`verify`?`Reading and checking stored content…`:`Processing the cache index…`;let t=e.result||{};return e.action===`compact`?`${(t.compactedCount||0).toLocaleString()} keys compacted`:e.action===`verify`?`${(t.verifiedContent||0).toLocaleString()} blobs verified · ${(t.badContentCount||0).toLocaleString()} corrupted blobs removed · ${Y(t.reclaimedSize||0)} reclaimed`:`${(t.reclaimedCount||0).toLocaleString()} unused blobs removed · ${Y(t.reclaimedSize||0)} reclaimed`}var tr=new Map,nr=`workspace:cache-maintenance`;function rr(e,t,n){let r=JSON.stringify([t,n.id]),i=tr.get(r);if(i)return i;let a=(async()=>{let r=e({title:Yn[n.action],description:`${n.store} · ${er(n)}`});try{let e=n;for(;Xn(e);){let i=await Qn(t),a=i.jobs.find(e=>e.id===n.id);if(!a)throw Error(`Maintenance receipt is no longer available. The server may have restarted; refresh the cache settings.`);if(e=a,window.dispatchEvent(new CustomEvent(nr,{detail:{workspace:t,status:i}})),!Xn(e))break;r.update({title:Yn[e.action],description:`${e.store} · ${er(e)}`}),await new Promise(e=>setTimeout(e,2e3))}if(e.status===`failed`)throw Error(er(e));r.done({title:`${Yn[e.action]} complete`,description:`${e.store} · ${er(e)}`})}catch(e){throw r.fail({title:`Cache maintenance needs attention`,description:`${n.store} · ${e instanceof Error?e.message:String(e)}`,variant:`destructive`}),e}})();return tr.set(r,a),a.finally(()=>{tr.get(r)===a&&tr.delete(r)}).catch(()=>{}),a}function ir({workspaceId:e,children:t}){let{showToast:n,showProgress:r}=q(),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(`workspace:cache`),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(null),m=(0,Z.useRef)(!1),h=(0,Z.useRef)(!1),g=(0,Z.useCallback)(()=>Qn(e).then(t=>{if(h.current){a(t),p(null);for(let n of t.jobs.filter(Xn))rr(r,e,n).catch(()=>{})}}).catch(e=>{h.current&&p(e instanceof Error?e.message:`Cannot load maintenance status`)}),[e,r]);(0,Z.useEffect)(()=>{h.current=!0,g();let t=t=>{let{workspace:n,status:r}=t.detail;n===e&&(a(r),p(null))};return window.addEventListener(nr,t),()=>{h.current=!1,window.removeEventListener(nr,t)}},[e,g]);let _=async t=>{if(!(m.current||i?.jobs.some(Xn))){m.current=!0,l(!0);try{let n=await $n(e,o,t);h.current&&a(e=>e&&{...e,jobs:[n,...e.jobs.filter(e=>e.id!==n.id)]}),rr(r,e,n).catch(()=>{})}catch(e){n({title:`Could not start maintenance`,description:e instanceof Error?e.message:String(e),variant:`destructive`}),g()}finally{m.current=!1,h.current&&l(!1)}}},v=c||!!i?.jobs.some(Xn),y=i?.stores.find(e=>e.id===o),b=i?.jobs[0];return(0,Q.jsxs)(`section`,{className:`space-y-4 rounded-(--panel-radius) border p-4`,"aria-label":`Workspace cache maintenance`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`h2`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[(0,Q.jsx)(ve,{className:`h-4 w-4 shrink-0`}),`Workspace cache`]}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Thumbnails, cached resources and pending transfers. Maintenance runs only when requested.`})]}),t&&(0,Q.jsx)(`fieldset`,{disabled:v,children:t})]}),(0,Q.jsxs)(`div`,{className:`space-y-3 border-t pt-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`label`,{htmlFor:`cache-maintenance-store`,className:`text-xs font-medium`,children:`Store`}),(0,Q.jsxs)(`select`,{id:`cache-maintenance-store`,value:o,onChange:e=>s(e.target.value),disabled:v,className:`min-w-0 max-w-full rounded-md border bg-background px-2 py-1.5 text-xs`,children:[(0,Q.jsx)(`option`,{value:`workspace:cache`,children:`workspace:cache`}),(0,Q.jsx)(`option`,{value:`workspace:data`,children:`workspace:data`})]}),(0,Q.jsx)(U,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>void g(),"aria-label":`Refresh cache maintenance status`,className:`ml-auto h-8 w-8`,children:(0,Q.jsx)(z,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o===`workspace:data`?`Managed document blobs. Referenced content is kept during collection.`:`Working cache, including content awaiting transfer. Referenced content is kept during collection.`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsxs)(U,{type:`button`,variant:`outline`,size:`sm`,disabled:v||!y?.canCollect||!!f,onClick:()=>void _(`collect`),children:[(0,Q.jsx)(I,{className:`mr-2 h-3.5 w-3.5`}),`Collect unused blobs`]}),(0,Q.jsxs)(U,{type:`button`,variant:`outline`,size:`sm`,disabled:v||!y?.canCompact||!!f,onClick:()=>void _(`compact`),children:[(0,Q.jsx)(V,{className:`mr-2 h-3.5 w-3.5`}),`Compact index`]}),(0,Q.jsxs)(U,{type:`button`,variant:`outline`,size:`sm`,disabled:v||!y?.canVerify||!!f,onClick:()=>d(!0),children:[(0,Q.jsx)(le,{className:`mr-2 h-3.5 w-3.5`}),`Verify integrity`]})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Collection removes unreferenced blobs. Compaction trims index history. Verification reads every blob and may remove corrupted content. Storage writes may wait during maintenance.`}),!i&&!f&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,role:`status`,children:`Loading maintenance status…`}),y&&!y.canCollect&&!y.canVerify&&!y.canCompact&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Update canvas-stored to enable maintenance for this store.`}),f&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,role:`alert`,children:f}),b&&(0,Q.jsxs)(`div`,{className:`rounded-md bg-muted/50 p-3 text-xs`,role:`status`,"aria-live":`polite`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[Xn(b)&&(0,Q.jsx)(fe,{className:`h-3.5 w-3.5 animate-spin`}),Yn[b.action],` · `,b.store]}),(0,Q.jsx)(`p`,{className:`mt-1 ${b.status===`failed`?`text-destructive`:`text-muted-foreground`}`,children:er(b)}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:b.finishedAt?`Finished ${new Date(b.finishedAt).toLocaleString()}`:`Requested ${new Date(b.createdAt).toLocaleString()}`})]})]}),(0,Q.jsx)(ft,{open:u,onOpenChange:d,children:(0,Q.jsxs)(st,{className:`max-w-[calc(100vw-2rem)] sm:max-w-lg`,children:[(0,Q.jsxs)(dt,{children:[(0,Q.jsxs)(ot,{children:[`Verify `,o,`?`]}),(0,Q.jsx)(at,{children:`This reads all stored content and can take a long time. Corrupted blobs and their index entries may be removed. Keep a recovery backup before running it. Storage writes may wait until it finishes.`})]}),(0,Q.jsxs)(lt,{children:[(0,Q.jsx)(ut,{children:`Cancel`}),(0,Q.jsx)(ct,{disabled:v,onClick:()=>void _(`verify`),children:`Verify and repair`})]})]})})]})}var ar=e=>e.status===`queued`||e.status===`running`,or=e=>`${be.workspaces}/${encodeURIComponent(e)}/db`,sr=e=>K.get(`${or(e)}/maintenance`),cr={"reindex:timelines":`reindex/timelines`,"reindex:mime":`reindex/mime`,"reindex:search":`reindex/search`,optimize:`optimize`};function lr(e,t,n={}){let r=cr[t];return t===`reindex:search`?K.post(`${or(e)}/${r}${n.rebuild?`?rebuild=true`:``}`,{}):K.post(`${or(e)}/${r}`,t===`optimize`&&n.space?{space:n.space}:{})}function ur(e){switch(e.action){case`reindex:timelines`:return`Rebuild timelines`;case`reindex:mime`:return`Rebuild file types`;case`reindex:search`:return e.options.rebuild?`Rebuild word search`:`Index missing documents`;default:return e.options.space?`Optimize ${e.options.space}`:`Optimize indexes`}}var dr=e=>typeof e==`number`?e.toLocaleString():`0`;function fr(e){if(e.status===`failed`)return e.error||`Maintenance failed`;if(e.status===`queued`)return`Waiting for the database…`;if(e.status===`running`){let t=e.progress;return t?e.action===`reindex:search`?`${dr(t.indexed)} indexed`:`${dr(t.scanned)}${typeof t.total==`number`?` / ${dr(t.total)}`:``} documents scanned`:`Working…`}let t=e.result||{};return e.action===`reindex:timelines`?`${dr(t.created)} created, ${dr(t.updated)} updated (${dr(t.scanned)} scanned)`:e.action===`reindex:mime`?`${dr(t.ticked)} of ${dr(t.scanned)} documents across ${dr(t.keys)} file types`:e.action===`reindex:search`?`${dr(t.indexed)} newly indexed (${dr(t.alreadyIndexed)} of ${dr(t.totalDocs)} already were)`:`Indexes compacted`}var pr=new Map;function mr(e,t,n){let r=JSON.stringify([t,n.id]),i=pr.get(r);if(i)return i;let a=(async()=>{let r=e({title:ur(n),description:fr(n)});try{let e=n;for(;ar(e);){let i=(await sr(t)).jobs.find(e=>e.id===n.id);if(!i)throw Error(`Maintenance receipt is no longer available. The workspace may have restarted; run it again.`);if(e=i,!ar(e))break;r.update({title:ur(e),description:fr(e)}),await new Promise(e=>setTimeout(e,2e3))}if(e.status===`failed`)throw Error(fr(e));return r.done({title:`${ur(e)} complete`,description:fr(e)}),e}catch(e){throw r.fail({title:`${ur(n)} needs attention`,description:e instanceof Error?e.message:String(e),variant:`destructive`}),e}})();return pr.set(r,a),a.finally(()=>{pr.get(r)===a&&pr.delete(r)}).catch(()=>{}),a}function hr({workspaceId:e,backend:t,onSaved:n}){let r=t?.config||{},i=()=>({name:String(r.label||``),bucket:String(r.bucket||``),prefix:String(r.prefix||``),endpoint:String(r.endpoint||``),region:String(r.region||`us-east-1`),accessKeyId:``,secretAccessKey:``,sessionToken:``}),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(i),[l,u]=(0,Z.useState)(r.forcePathStyle!==!1),[d,f]=(0,Z.useState)(r.readOnly===!0),[p,h]=(0,Z.useState)(r.watch===!0),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(!1),{showToast:b}=q(),x=e=>({value:s[e],onChange:t=>c(n=>({...n,[e]:t.target.value}))});return a?(0,Q.jsxs)(`form`,{onSubmit:async r=>{r.preventDefault(),y(!0);try{let r={label:s.name.trim(),bucket:s.bucket.trim(),prefix:s.prefix.trim(),endpoint:s.endpoint.trim(),region:s.region.trim()||`us-east-1`,forcePathStyle:l,readOnly:d,watch:p,...Object.fromEntries([`accessKeyId`,`secretAccessKey`,`sessionToken`].flatMap(e=>{let t=s[e].trim();return t?[[e,t]]:[]})),...g?{sessionToken:``}:{}};t?await Xe(e,`s3`,t.address,r):await Je(e,`s3`,r),o(!1),c(i()),b({title:t?`S3 backend updated`:`S3 backend added`,description:`Use Re-sync to check indexing progress, and filing policies to automate copies.`}),await n()}catch(e){b({title:`Could not connect S3`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}finally{y(!1)}},className:`w-full space-y-3 rounded-lg border p-4`,children:[(0,Q.jsxs)(`h2`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[(0,Q.jsx)(ve,{className:`h-4 w-4`}),t?`Edit S3 connection`:`Add S3-compatible bucket`]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Amazon S3, MinIO, Garage, RustFS or Ceph RGW. Connect an existing bucket, optionally scoped to a prefix. Supports browsing, reads and filing copies; mirror policies and overwrites are unavailable.`}),(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[`Name`,(0,Q.jsx)(W,{...x(`name`),required:!0,placeholder:`Accounting archive`})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[`Bucket`,(0,Q.jsx)(W,{...x(`bucket`),disabled:!!t,required:!0,placeholder:`accounting`})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[`Endpoint (blank for Amazon S3)`,(0,Q.jsx)(W,{...x(`endpoint`),disabled:!!t,type:`url`,placeholder:`https://s3.example.com`})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[`Region`,(0,Q.jsx)(W,{...x(`region`),required:!0,placeholder:`us-east-1`})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs sm:col-span-2`,children:[`Prefix (optional)`,(0,Q.jsx)(W,{...x(`prefix`),disabled:!!t,placeholder:`Augmentd/Accounting`})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[`Access key ID`,(0,Q.jsx)(W,{...x(`accessKeyId`),required:!t,autoComplete:`off`,placeholder:t?`Leave blank to keep stored value`:``})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[`Secret access key`,(0,Q.jsx)(W,{...x(`secretAccessKey`),type:`password`,required:!t,autoComplete:`off`,placeholder:t?`Leave blank to keep stored value`:``})]}),(0,Q.jsxs)(`label`,{className:`space-y-1 text-xs sm:col-span-2`,children:[`Session token (optional)`,(0,Q.jsx)(W,{...x(`sessionToken`),disabled:g,type:`password`,autoComplete:`off`,placeholder:t?`Leave blank to keep stored value`:``})]}),t&&(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked)}),`Clear stored session token`]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-4 text-xs`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked)}),`Path-style addressing`]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked)}),`Read-only`]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>h(e.target.checked)}),`Poll for changes`]})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Writable connections test conflict protection using a temporary object, then delete it. The key needs list/read/write access and delete access under .canvas-probe/. Initial indexing reads file bytes; polling can incur request and download charges. Upload limit: 5 GiB per file.`}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(U,{type:`button`,variant:`ghost`,disabled:v,onClick:()=>{o(!1),c(i())},children:`Cancel`}),(0,Q.jsx)(U,{disabled:v,children:v?`Checking connection…`:`Save connection`})]})]}):(0,Q.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>{c(i()),u(r.forcePathStyle!==!1),f(r.readOnly===!0),h(r.watch===!0),_(!1),o(!0)},children:[t?(0,Q.jsx)(m,{className:`mr-2 h-3.5 w-3.5`}):(0,Q.jsx)(A,{className:`mr-2 h-3.5 w-3.5`}),t?`Edit S3 connection`:`Add S3 bucket`]})}function gr({workspaceId:e,isActive:t,currentMode:n,onChanged:r}){let[i,a]=(0,Z.useState)(n===`workspace`?`workspace`:`secrets`),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(!1);return(0,Q.jsxs)(`section`,{className:`space-y-3 rounded-lg border p-4`,children:[(0,Q.jsx)(`h2`,{className:`font-semibold text-sm`,children:`Workspace protection`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Protect service credentials with a PIN or password. Optionally require it to start the whole workspace. Files and document contents are not encrypted.`}),t&&(0,Q.jsx)(`p`,{className:`text-sm`,children:`Stop the workspace before changing protection.`}),(0,Q.jsxs)(`form`,{className:`space-y-3`,onSubmit:async t=>{if(t.preventDefault(),h(``),o!==c){h(`PIN/password confirmation does not match`);return}_(!0);try{let t=await K.put(`${be.workspaces}/${e}/protection`,{mode:i,passphrase:o,currentPassphrase:u||void 0});p(t.recoveryKey),s(``),l(``),d(``)}catch(e){h(e instanceof Error?e.message:`Could not save protection`)}finally{_(!1)}},children:[(0,Q.jsxs)(`label`,{className:`block text-sm space-y-1`,children:[`Protection mode`,(0,Q.jsxs)(`select`,{className:`block rounded border bg-background p-2 w-full`,value:i,onChange:e=>a(e.target.value),disabled:t||g,children:[(0,Q.jsx)(`option`,{value:`secrets`,children:`Secrets only — allow start without integrations`}),(0,Q.jsx)(`option`,{value:`workspace`,children:`Whole workspace — require PIN/password to start`})]})]}),(0,Q.jsxs)(`label`,{className:`block text-sm space-y-1`,children:[`Current PIN/password or recovery key (if already protected)`,(0,Q.jsx)(W,{type:`password`,autoComplete:`current-password`,value:u,onChange:e=>d(e.target.value),disabled:t||g})]}),(0,Q.jsxs)(`label`,{className:`block text-sm space-y-1`,children:[`New PIN/password`,(0,Q.jsx)(W,{type:`password`,autoComplete:`new-password`,minLength:4,maxLength:1024,required:!0,value:o,onChange:e=>s(e.target.value),disabled:t||g})]}),(0,Q.jsxs)(`label`,{className:`block text-sm space-y-1`,children:[`Confirm new PIN/password`,(0,Q.jsx)(W,{type:`password`,autoComplete:`new-password`,required:!0,value:c,onChange:e=>l(e.target.value),disabled:t||g})]}),(0,Q.jsx)(U,{disabled:t||g||!!f,children:g?`Saving…`:`Save protection`})]}),m&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:m}),f&&(0,Q.jsxs)(`div`,{className:`space-y-2 rounded border p-3`,children:[(0,Q.jsx)(`p`,{className:`text-sm`,children:`Save this recovery key now. It is shown only once and replaces any previous recovery key.`}),(0,Q.jsx)(`code`,{className:`block break-all select-all`,children:f}),(0,Q.jsx)(U,{variant:`outline`,onClick:()=>{p(``),r()},children:`I saved the recovery key`})]})]})}var _r=`h-8 rounded-md border bg-background px-2 text-sm outline-none focus:ring-2 focus:ring-ring`;function vr({title:e,hint:t,children:n}){let[r,i]=(0,Z.useState)(!1);return(0,Q.jsxs)(`section`,{className:`overflow-hidden rounded-lg border`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),"aria-expanded":r,className:`flex w-full items-center justify-between gap-4 px-4 py-3 text-left transition-colors hover:bg-muted/40`,children:[(0,Q.jsxs)(`span`,{className:`min-w-0`,children:[(0,Q.jsx)(`span`,{className:`block text-sm font-medium`,children:e}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:t})]}),(0,Q.jsx)(b,{className:ye(`h-4 w-4 shrink-0 text-muted-foreground transition-transform motion-reduce:transition-none`,r&&`rotate-180`)})]}),r&&(0,Q.jsx)(`div`,{className:`border-t p-4`,children:n})]})}function yr({workspaceName:e,value:t,onChange:n,disabled:r}){let[i,a]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`label`,{className:`text-xs font-medium`,children:[`Only this folder `,(0,Q.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional)`})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(W,{value:t,disabled:r,onChange:e=>n(e.target.value),placeholder:`Whole workspace`,className:`h-8 font-mono text-sm`}),(0,Q.jsx)(U,{type:`button`,size:`sm`,variant:`outline`,disabled:r,onClick:()=>a(!0),title:`Pick a folder or context from the tree`,children:(0,Q.jsx)(ne,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Includes everything below it. Pick from the tree, or type `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`ctx://work/project`}),` or`,` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`dir://photos`}),`.`]}),i&&(0,Q.jsx)(St,{onClose:()=>a(!1),children:(0,Q.jsx)(Ce,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,fixedWorkspaceName:e,multiple:!1,onClose:()=>a(!1),onConfirm:(e,t)=>{let r=e[0];r&&n(`${t.treeType===`directory`?`dir`:`ctx`}://${r.replace(/^\/+/,``)}`),a(!1)}})})]})}function br({workspaceId:e,workspaceName:t,refreshKey:n,onRefresh:r}){let{showToast:i}=q(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),l=(0,Z.useCallback)(()=>Sn(e).then(e=>o(e.queue??null)).catch(()=>{}),[e]);(0,Z.useEffect)(()=>{l();let e=window.setInterval(()=>{o(e=>(e&&(e.pending>0||e.draining)&&l(),e))},3e3);return()=>window.clearInterval(e)},[l,n]);let u=async()=>{if(a){c(!0);try{let e=await tt(!a.paused,t);i({title:e.paused?`Indexing paused`:`Indexing resumed`,description:e.paused?`${e.pending.toLocaleString()} document(s) on hold. Resume any time; a server restart also resumes.`:`${e.pending.toLocaleString()} document(s) being indexed.`}),await l()}catch(e){i({title:`Error`,description:e instanceof Error?e.message:`Failed to pause or resume indexing (admin only)`,variant:`destructive`})}finally{c(!1)}}},d=!!a?.draining,f=a?a.paused?`bg-warning`:d?`bg-success`:`bg-muted-foreground/40`:`bg-muted-foreground/40`;return(0,Q.jsxs)(`section`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2 rounded-lg border bg-muted/30 px-4 py-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-sm`,children:[(0,Q.jsxs)(`span`,{className:`relative flex h-2 w-2 shrink-0`,"aria-hidden":!0,children:[d&&(0,Q.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full bg-success opacity-60 motion-reduce:hidden`}),(0,Q.jsx)(`span`,{className:ye(`relative inline-flex h-2 w-2 rounded-full`,f)})]}),(0,Q.jsx)(`span`,{className:`font-medium`,children:a?a.pending>0?(0,Q.jsxs)(Q.Fragment,{children:[a.pending.toLocaleString(),` `,(0,Q.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`document(s) waiting to be indexed`})]}):a.paused?`Paused`:`Up to date`:`Inference service not reachable`}),a?.paused&&a.pending>0&&(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`(paused)`}),a?.ingestDisabled&&(0,Q.jsx)(`span`,{className:`rounded bg-warning-subtle px-1.5 py-0.5 text-[10px] font-medium text-warning`,title:`CANVAS_INFERD_INGEST_DISABLED=true: new documents are not indexed for meaning search; what is already indexed still works`,children:`indexing turned off on the server`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[a&&(0,Q.jsx)(U,{type:`button`,size:`sm`,variant:`ghost`,disabled:s,onClick:u,title:a.paused?`Resume; the waiting documents get indexed`:`Pause after the current batch. Stops the CPU-heavy model work; new documents are still found by word search.`,children:s?`…`:a.paused?`Resume`:`Pause`}),(0,Q.jsx)(U,{type:`button`,size:`sm`,variant:`ghost`,onClick:r,title:`Reload`,children:(0,Q.jsx)(z,{className:`h-3.5 w-3.5`})})]})]})}function xr({workspaceId:e,tables:t,error:n,onChanged:r}){let{showToast:i}=q(),[a,o]=(0,Z.useState)(null),s=t.filter(e=>!e.active),c=async t=>{if(window.confirm(`Reclaim "${t.name}"?\n\nThis permanently deletes the index built with ${t.model||`that model`}. Switching back to it afterwards means indexing every document again instead of being instant.\n\nThis is the only step here that cannot be undone.`)){o(t.name);try{let n=await xn(e,t.name);if(!n.dropped)throw Error(n.error||`Failed to drop the vector table`);i({title:`Deleted`,description:`Removed '${n.name||t.name}'.`}),r()}catch(e){i({title:`Error`,description:e instanceof Error?e.message:`Failed to delete`,variant:`destructive`})}finally{o(null)}}};return n?(0,Q.jsxs)(`section`,{className:`rounded-lg border border-destructive/40 bg-destructive-subtle p-4`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium text-destructive`,children:`Stored indexes unavailable`}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n})]}):s.length===0?null:(0,Q.jsx)(vr,{title:`Previous models (${s.length})`,hint:`Indexes built with models you switched away from. They stay on disk so switching back is instant. Deleting one frees the space for good.`,children:(0,Q.jsx)(`div`,{className:`divide-y`,children:s.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-2 first:pt-0 last:pb-0`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`p`,{className:`truncate font-mono text-xs`,children:[e.model||`unknown model`,e.dim?` · ${e.dim}-d`:``]}),(0,Q.jsxs)(`p`,{className:`truncate font-mono text-[11px] text-muted-foreground`,children:[`└─ `,e.name]})]}),(0,Q.jsxs)(U,{type:`button`,size:`sm`,variant:`ghost`,className:`text-destructive hover:text-destructive`,disabled:a===e.name,onClick:()=>c(e),title:`Permanently delete the index built with this model`,children:[(0,Q.jsx)(I,{className:`mr-1.5 h-3.5 w-3.5`}),a===e.name?`Deleting…`:`Delete`]})]},e.name))})})}function Sr({workspaceId:e,workspaceName:t,spaces:n,onDone:r}){let{showToast:i}=q(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(!1);return(0,Q.jsxs)(vr,{title:`Index existing documents`,hint:`Add documents that are not in meaning search yet, for example after switching models. Limit it to one folder to try a model on a small set first.`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-medium`,children:`Content type`}),(0,Q.jsxs)(`select`,{className:`${_r} w-full`,value:a,onChange:e=>o(e.target.value),children:[(0,Q.jsx)(`option`,{value:``,children:`All content types`}),n.map(e=>(0,Q.jsx)(`option`,{value:e,children:vn(e)},e))]})]}),(0,Q.jsx)(yr,{workspaceName:t,value:s,onChange:c,disabled:d})]}),(0,Q.jsxs)(`label`,{className:`mt-3 flex items-start gap-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:l,onChange:e=>u(e.target.checked)}),(0,Q.jsxs)(`span`,{children:[`Also redo documents that are already indexed`,l&&s.trim()&&(0,Q.jsx)(`span`,{className:`mt-1 block text-[11px] text-warning`,children:`Even with a folder limit, this clears the whole index for the chosen content type, not just that folder. Leave it off unless you want to redo everything.`})]})]}),(0,Q.jsx)(U,{type:`button`,size:`sm`,className:`mt-3`,onClick:async()=>{f(!0);try{let t=await gn(e,{space:a||void 0,reindex:l,scope:s.trim()||void 0});t.ingestDisabled?i({title:`Indexing is turned off on the server`,description:`CANVAS_INFERD_INGEST_DISABLED=true: nothing was queued. What is already indexed still works.`,variant:`destructive`}):i({title:`Indexing queued`,description:`${t.enqueued.toLocaleString()} document(s) queued${t.scope?` under ${t.scope}`:``}. The status line above shows progress.`}),r()}catch(e){i({title:`Indexing failed to start`,description:e instanceof Error?e.message:`Failed to queue`,variant:`destructive`})}finally{f(!1)}},disabled:d,children:d?`Queueing…`:`Start indexing`})]})}var Cr=[{provider:`blip`,model:`HuggingFaceTB/SmolVLM-500M-Instruct`,task:`instruct`,label:`SmolVLM 500M: follows your instructions (recommended)`,note:`About 500 MB. Follows the instructions below, so you can ask for what matters to you, such as style, materials or setting.`},{provider:`blip`,model:`HuggingFaceTB/SmolVLM-256M-Instruct`,task:`instruct`,label:`SmolVLM 256M: smaller, follows your instructions`,note:`About 250 MB. Same instructions, less detail; for servers short on memory.`},{provider:`blip`,model:`onnx-community/Florence-2-base-ft`,task:`florence2`,label:`Florence-2 base: detailed, fixed style`,note:`Writes several detailed sentences, but ignores instructions.`},{provider:`blip`,model:`Xenova/vit-gpt2-image-captioning`,task:`caption`,label:`vit-gpt2: one short sentence (smallest)`,note:`One terse sentence per image, sometimes repetitive. Uses the least memory.`}],wr=`custom`,Tr=[{value:`instruct`,label:`Follows instructions (instruct VLM)`},{value:`florence2`,label:`Florence-2 family`},{value:`caption`,label:`Plain captioner, image only`}],Er=`Describe this photograph in two or three sentences. If it shows a building or interior, name the architectural style, the main materials and the setting. Describe only what is visible.`;function Dr({workspaceId:e,workspaceName:t,config:n,saving:r,onSave:i}){let{showToast:a}=q(),o=n.workspace||{},s=n.effective||{},c=Cr[0],l=o.summarize?.image||s.summarize?.image||{},[u,d]=(0,Z.useState)(()=>s.summarize?.image?.enabled===!0||o.summarize?.image?.enabled===!0),[f,p]=(0,Z.useState)(()=>{let e=Cr.find(e=>e.provider===(l.provider||c.provider)&&e.model===l.model);return e?`${e.provider}::${e.model}`:l.model?wr:`${c.provider}::${c.model}`}),[m,h]=(0,Z.useState)(()=>Cr.some(e=>e.model===l.model)?``:l.model||``),[g,_]=(0,Z.useState)(()=>l.task||`instruct`),[v,y]=(0,Z.useState)(()=>l.prompt||``),[b,x]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)(null),[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(``),M=Cr.find(e=>`${e.provider}::${e.model}`===f),N=f===wr,P=N?{provider:c.provider,model:m.trim(),task:g,label:`Custom`,note:``}:M||c,F=P.task===`instruct`,ee=(0,Z.useCallback)(()=>Sn(e).then(e=>C(e.summarize||null)).catch(()=>{}),[e]);(0,Z.useEffect)(()=>{ee();let e=window.setInterval(()=>{C(e=>(e?.running&&ee(),e))},2e3);return()=>window.clearInterval(e)},[ee]);let te=async()=>{await i({...o,summarize:{...o.summarize||{},image:{enabled:u,provider:P.provider,model:P.model,task:P.task,...F&&v.trim()?{prompt:v.trim()}:{}}}}),x(!1)},I=async()=>{D(!0);try{C(await _n(e)),a({title:`Stopping image descriptions`,description:`The current image finishes first; the rest are left for a later run.`})}catch(e){a({title:`Could not stop`,description:e instanceof Error?e.message:`Failed to stop`,variant:`destructive`})}finally{D(!1)}},ne=async(t=!1)=>{T(!0);try{let n=await bn(e,{force:t,scope:A.trim()||void 0});C(n),a({title:t?`Describing all images again`:`Describing images`,description:`${n.total.toLocaleString()} image(s)${n.scope?` under ${n.scope}`:``}. The first run downloads the model, which can take a few minutes.`})}catch(e){a({title:`Image descriptions failed to start`,description:e instanceof Error?e.message:`Failed to start`,variant:`destructive`})}finally{T(!1)}},L=s.summarize?.image?.enabled===!0,R=S?.running===!0,re=S?.errors?.[0]?.error;return(0,Q.jsx)(vr,{title:`Image descriptions`,hint:`A vision model writes a few sentences about each image, so you can find photos by what is in them.`,children:(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:u,disabled:r,onChange:e=>{d(e.target.checked),x(!0)}}),`Describe images`]}),(0,Q.jsxs)(`select`,{className:_r,value:f,disabled:r||!u,onChange:e=>{p(e.target.value),x(!0)},children:[Cr.map(e=>(0,Q.jsx)(`option`,{value:`${e.provider}::${e.model}`,children:e.label},`${e.provider}::${e.model}`)),(0,Q.jsx)(`option`,{value:wr,children:`Custom model…`})]}),!N&&(0,Q.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:P.model})]}),N&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(W,{className:`h-8 w-72 font-mono text-xs`,placeholder:`org/model-id (Hugging Face, ONNX)`,value:m,disabled:r||!u,onChange:e=>{h(e.target.value),x(!0)}}),(0,Q.jsx)(`select`,{className:_r,value:g,disabled:r||!u,onChange:e=>{_(e.target.value),x(!0)},children:Tr.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),u&&P.note&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:P.note}),u&&F&&(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`textarea`,{className:`w-full rounded-md border border-input bg-transparent p-2 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`,rows:3,placeholder:Er,value:v,disabled:r,onChange:e=>{y(e.target.value),x(!0)}}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`What to ask about every image. Leave empty to use the default shown above. Descriptions become searchable, so ask for the details you would search by.`})]}),S&&(S.running||S.total>0||S.finishedAt)&&(0,Q.jsxs)(`p`,{className:ye(`text-xs`,S.aborted?`text-destructive`:`text-muted-foreground`),children:[R?`Running`:S.aborted?`Stopped`:S.cancelled?`Cancelled`:`Last run`,S.scope?(0,Q.jsxs)(Q.Fragment,{children:[` under `,(0,Q.jsx)(`span`,{className:`font-mono`,children:S.scope})]}):null,`: `,S.described,`/`,S.total,` described`,S.skipped?`, ${S.skipped} skipped`:``,S.failed?`, ${S.failed} failed`:``,S.aborted?`. ${S.abortedReason||`The model stopped working`}. The remaining images were not tried; run again to retry.`:S.cancelled?`. Stopped by you. The remaining images were left untouched; run again to continue.`:re?`. ${re}`:``]}),(0,Q.jsx)(yr,{workspaceName:t,value:A,onChange:j,disabled:r||R}),(0,Q.jsxs)(`label`,{className:`flex items-start gap-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:O,disabled:r||R,onChange:e=>k(e.target.checked)}),(0,Q.jsxs)(`span`,{children:[`Also redo images that already have a description`,O&&(0,Q.jsxs)(`span`,{className:`mt-1 block text-[11px] text-warning`,children:[`Replaces existing descriptions`,A.trim()?` in that folder`:``,`, including ones written by another model. Leave this off to describe only images that have none yet.`]})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Turn on and save, then run. Descriptions are generated on this server; the first run downloads the model.`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(U,{size:`sm`,variant:`outline`,onClick:()=>void te(),disabled:r||!b,children:`Save`}),(0,Q.jsx)(U,{size:`sm`,onClick:()=>void ne(O),disabled:r||b||w||R||!L,title:L?b?`Save your changes first`:O?`Describe every image again, replacing existing descriptions`:`Describe images that have no description yet`:`Turn on image descriptions and save first`,children:R||w?`Running…`:O?`Describe all again`:`Describe missing`}),R&&(0,Q.jsx)(U,{size:`sm`,variant:`destructive`,onClick:()=>void I(),disabled:E,title:`Finish the current image, then stop. The rest are left for later.`,children:E?`Stopping…`:`Stop`})]})]})]})})}function Or({workspaceId:e,workspaceName:t}){let{showToast:n}=q(),[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)([]),[s,c]=(0,Z.useState)(),[l,u]=(0,Z.useState)(!0),[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)([]),[_,v]=(0,Z.useState)(0),y=(0,Z.useCallback)(()=>yn(e).then(e=>{i(e),m(null)}).catch(e=>m(e instanceof Error?e.message:`Failed to load the search settings`)).finally(()=>u(!1)),[e]),b=(0,Z.useCallback)(()=>mn(e).then(e=>{o(e.tables||[]),c(e.error)}).catch(e=>c(e instanceof Error?e.message:`Failed to list stored indexes`)),[e]);(0,Z.useEffect)(()=>{y(),b()},[y,b]);let x=()=>{u(!0),y(),b(),v(e=>e+1)},S=async t=>{f(!0);try{let r=await hn(e,t);g(r.movedSpaces||[]),r.movedSpaces?.length?n({title:`Saved: now index your existing documents`,description:`${r.movedSpaces.map(vn).join(`, `)}: new model in use. New documents use it right away; existing ones need indexing (button on the row).`}):r.applied===!1?n({title:`Saved: applies on next start`,description:`The workspace is not running, so the changes take effect when it starts.`}):n({title:`Saved`,description:`Search settings updated.`}),await y(),await b()}catch(e){n({title:`Save failed`,description:e instanceof Error?e.message:`Failed to save`,variant:`destructive`})}finally{f(!1)}},C=async t=>{try{let r=await gn(e,{space:t});if(r.ingestDisabled){n({title:`Indexing is turned off on the server`,description:`CANVAS_INFERD_INGEST_DISABLED=true: nothing was queued. What is already indexed still works.`,variant:`destructive`});return}n({title:`Indexing ${vn(t).toLowerCase()}`,description:`${r.enqueued.toLocaleString()} document(s) queued. The status line above shows progress.`}),g(e=>e.filter(e=>e!==t)),v(e=>e+1),b()}catch(e){n({title:`Indexing failed to start`,description:e instanceof Error?e.message:`Failed to queue`,variant:`destructive`})}};if(l)return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(z,{className:`h-4 w-4 animate-spin`}),`Loading search settings…`]});if(p||!r)return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`rounded-lg border border-destructive/40 bg-destructive-subtle p-4 text-sm`,children:[(0,Q.jsx)(`p`,{className:`font-medium text-destructive`,children:`Search settings unavailable`}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:p||`No config returned.`})]}),(0,Q.jsx)(U,{type:`button`,size:`sm`,variant:`outline`,onClick:x,children:`Try again`})]});let w=Object.keys(r.effective.spaces||{}).sort();return(0,Q.jsxs)(`div`,{className:`space-y-5`,children:[(0,Q.jsx)(br,{workspaceId:e,workspaceName:t,refreshKey:_,onRefresh:x}),(0,Q.jsx)(Cn,{value:r.workspace||{},effective:r.effective||{},inherited:r.inherited||{},resolvedSpaces:r.spaces,invalid:r.invalid,attention:h,onFill:C,saving:d,saveLabel:`Save models`,onSave:S},JSON.stringify(r.workspace)),(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsx)(Dr,{workspaceId:e,workspaceName:t,config:r,saving:d,onSave:S},`summarize:${JSON.stringify(r.workspace?.summarize||{})}`),(0,Q.jsx)(Sr,{workspaceId:e,workspaceName:t,spaces:w,onDone:()=>{b(),v(e=>e+1)}}),(0,Q.jsx)(xr,{workspaceId:e,tables:a,error:s,onChanged:()=>{b()}})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`These settings are saved with the workspace (in its `,(0,Q.jsx)(`span`,{className:`font-mono`,children:`workspace.json`}),`), so they move with it. Anything not set here comes from your personal defaults, then the server's. Changes apply immediately, with no restart.`]})]})}function kr(e){let n=(e||``).split(`.`).pop()?.toLowerCase();switch(n){case`js`:case`mjs`:case`ts`:return[a({typescript:n===`ts`})];case`json`:return[i()];case`sh`:case`bash`:return[t.define(o)];default:return[]}}function Ar({value:e,onChange:t,path:r,className:i=``}){let a=(0,Z.useMemo)(()=>kr(r),[r]),{resolvedScheme:o}=tn();return(0,Q.jsx)(n,{value:e,onChange:t,extensions:a,theme:o===`dark`?`dark`:`light`,className:i,basicSetup:{lineNumbers:!0,foldGutter:!0,highlightActiveLine:!0,bracketMatching:!0,autocompletion:!1}})}function jr(e,t){if(![`download`,`store`].includes(e.action)||e.recursive===!0&&!t)return null;let n=String(e.folder||``);return n.includes(`{{`)?null:[n,(e.recursive===!0?e.pathMode===`full`?t?.path:t?.rel:``)||``].join(`/`).split(`/`).filter(e=>e&&e!==`.`&&e!==`..`).join(`/`)}function Mr(e,t){if(![`download`,`store`].includes(e.action)||typeof e.to!=`string`)return null;if(e.recursive===!0&&!t)return`Missing filing path — decline and trigger the rule again`;let n=jr(e,t);return n===null?null:`${e.to}/${n}`}function Nr(e,t){let n=jr(e,t);if(n===null||e.recursive!==!0||e.autoLink===!0)return{...e};let r={...e,folder:n};return delete r.recursive,delete r.pathMode,r}function Pr(e,t){let n=structuredClone({actions:e.actions});for(let[r,i]of Object.entries(t)){if(!e.editable.includes(r))continue;let t=r.split(`.`);if(t[0]!==`actions`||t.some(e=>[`__proto__`,`prototype`,`constructor`].includes(e)))continue;let a=n;for(let e of t.slice(0,-1)){if(!a[e]||typeof a[e]!=`object`){a={};break}a=a[e]}a[t[t.length-1]]=i}return n.actions}var Fr=[`pending`,`approved`,`declined`,`failed`,`expired`,`all`],Ir={pending:`text-warning dark:text-warning`,approved:`text-success dark:text-success`,declined:`text-muted-foreground`,failed:`text-destructive`,expired:`text-muted-foreground line-through`};function Lr(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`now`;if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h`:`${Math.floor(r/24)}d`}function Rr(e,t){return t.split(`.`).reduce((e,t)=>typeof e==`object`&&e?e[t]:void 0,e)}function zr(e){let t=e.split(`.`);return t.slice(Math.max(t.length-2,2)).join(`.`)}var Br=/(body|content|message|text|prompt)$/i,Vr=2e3;function Hr({workspaceId:e,id:t,children:n}){let{open:r}=Ct(),{showToast:i}=q(),[a,o]=(0,Z.useState)(!1),s=async n=>{n.stopPropagation(),o(!0);try{r(await Be(e,t),e)}catch(e){i({title:`Document ${t} not available`,description:e instanceof Error?e.message:void 0,variant:`destructive`})}finally{o(!1)}};return(0,Q.jsx)(`button`,{type:`button`,disabled:a,onClick:e=>void s(e),className:`text-primary underline-offset-2 hover:underline disabled:opacity-60`,title:`Open document ${t}`,children:n??`doc ${t}`})}function Ur({workspaceId:e,text:t}){let n=t.split(/(\bdoc \d+\b)/);return(0,Q.jsx)(Q.Fragment,{children:n.map((t,n)=>{let r=/^doc (\d+)$/.exec(t);return r?(0,Q.jsx)(Hr,{workspaceId:e,id:Number(r[1])},n):(0,Q.jsx)(Z.Fragment,{children:t},n)})})}function Wr({action:e,amend:t,onAmend:n}){return e.editable?.length?(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.editable.map(r=>{let i=Rr(e,r),a=typeof i==`string`,o=r in t?t[r]:i,s=a?String(o??``):JSON.stringify(o,null,2),c=a&&(Br.test(r)||s.length>80);return(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsxs)(`span`,{className:`font-medium text-muted-foreground`,children:[zr(r),(0,Q.jsx)(`span`,{className:`ml-1.5 font-mono text-[10px] opacity-60`,children:r}),r in t&&(0,Q.jsx)(`span`,{className:`ml-1.5 text-warning dark:text-warning`,children:`edited`})]}),c?(0,Q.jsx)(`textarea`,{className:`mt-1 w-full rounded-md border bg-background px-2 py-1.5 font-mono text-xs outline-none focus:ring-2 focus:ring-ring min-h-[100px]`,value:s,onChange:e=>n(r,e.target.value)}):(0,Q.jsx)(`input`,{className:`mt-1 w-full h-8 rounded-md border bg-background px-2 font-mono text-xs outline-none focus:ring-2 focus:ring-ring`,value:s,onChange:e=>{if(a){n(r,e.target.value);return}try{n(r,JSON.parse(e.target.value))}catch{n(r,e.target.value)}}})]},r)})}):null}function Gr({workspaceId:e,onPendingCount:t}){let{showToast:n}=q(),r=wn(),[i,a]=(0,Z.useState)(`pending`),[o,s]=(0,Z.useState)([]),[c,l]=(0,Z.useState)(0),[u,d]=(0,Z.useState)(!0),[f,p]=(0,Z.useState)(new Set),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)({}),[v,y]=(0,Z.useState)(!1),x=(0,Z.useRef)(0),S=(0,Z.useCallback)(()=>{let r=++x.current,a=i===`pending`?null:Mt(e,{status:`pending`,limit:1}).then(({total:e})=>e);return Mt(e,{status:i===`all`?void 0:i,limit:200}).then(async({actions:e,total:n})=>{let i=a===null?n:await a;r===x.current&&(s(e),l(n),p(t=>new Set(e.filter(e=>e.status===`pending`&&t.has(e.actionId)).map(e=>e.actionId))),t?.(i))}).catch(()=>{r===x.current&&n({title:`Error`,description:`Failed to load pending actions`,variant:`destructive`})}).finally(()=>{r===x.current&&d(!1)})},[e,i]),C=(0,Z.useCallback)(async()=>{d(!0),await S()},[S]),[w,E]=(0,Z.useState)(`${e}|${i}`),O=`${e}|${i}`;O!==w&&(E(O),d(!0)),(0,Z.useEffect)(()=>{S()},[S]);let k=(0,Z.useRef)(S);(0,Z.useEffect)(()=>{k.current=S});let A=(0,Z.useRef)(null),j=(0,Z.useRef)(0);(0,Z.useEffect)(()=>()=>{A.current!==null&&window.clearTimeout(A.current)},[]),Tn(r,`workspace:${e}`,(0,Z.useMemo)(()=>{let e=()=>{if(A.current!==null)return;let e=Math.max(0,j.current+Vr-Date.now());A.current=window.setTimeout(()=>{A.current=null,j.current=Date.now(),k.current()},e)};return{"action.proposed":e,"action.approved":e,"action.declined":e,"action.failed":e}},[]));let[M,N]=(0,Z.useState)(null),P=M?.state===`running`;(0,Z.useEffect)(()=>{let t=!1;return Xt(e).then(e=>{t||N(e)}).catch(()=>{}),()=>{t=!0}},[e]),(0,Z.useEffect)(()=>{if(!P)return;let t=window.setInterval(()=>{Xt(e).then(e=>{N(e),k.current()}).catch(()=>{})},Vr);return()=>window.clearInterval(t)},[e,P]);let F=async(t,r,i)=>{if(window.confirm(i))try{N(await kt(e,{decision:t,nothingToDo:r}))}catch(e){n({title:`Could not start`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}},te=o.filter(e=>e.status===`pending`),I=te.length>0&&te.every(e=>f.has(e.actionId)),ne=()=>{p(I?new Set:new Set(te.map(e=>e.actionId)))},L=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},R=(e,t,n)=>{_(r=>({...r,[e]:{...r[e],[t]:n}}))},re=async(t,r)=>{if(!(!t.length&&!r.length)){y(!0);try{let i=await qt(e,{approve:t.map(e=>{let t=g[e];return t&&Object.keys(t).length?{actionId:e,amend:t}:e}),decline:r}),a=i.results.filter(e=>e.status===`error`||e.status===`failed`);a.length?n({title:`${a.length} of ${i.decided} failed`,description:a.map(e=>`${e.actionId}: ${e.error??`execution failed`}`).join(`; `),variant:`destructive`}):n({title:t.length&&r.length?`Decisions applied`:t.length?`Approved ${t.length}`:`Declined ${r.length}`,description:t.length?`Approved actions executed with their original provenance.`:void 0}),_(e=>{let n={...e};for(let e of[...t,...r])delete n[e];return n}),p(new Set),m&&[...t,...r].includes(m)&&h(null),await C()}catch(e){n({title:`Decision failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{y(!1)}}};return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`select`,{className:`h-8 rounded-md border bg-background px-2 text-xs outline-none focus:ring-2 focus:ring-ring`,value:i,onChange:e=>a(e.target.value),children:Fr.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))}),(0,Q.jsx)(U,{size:`sm`,variant:`ghost`,onClick:()=>void C(),title:`Reload`,children:(0,Q.jsx)(z,{className:`h-4 w-4`})}),c>o.length&&(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Showing `,o.length,` of `,c]})]}),f.size>0&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[f.size,` selected`]}),(0,Q.jsxs)(U,{size:`sm`,disabled:v,onClick:()=>void re([...f],[]),children:[(0,Q.jsx)(T,{className:`mr-1 h-3.5 w-3.5`}),` Approve`]}),(0,Q.jsxs)(U,{size:`sm`,variant:`outline`,disabled:v,onClick:()=>void re([],[...f]),children:[(0,Q.jsx)(D,{className:`mr-1 h-3.5 w-3.5`}),` Decline`]})]})]}),i===`pending`&&(c>0||M)&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap text-xs`,children:[c>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(U,{size:`sm`,variant:`outline`,disabled:P||v,onClick:()=>void F(`approve`,!1,`Approve and run all ${c} pending actions?`),children:`Approve all`}),(0,Q.jsx)(U,{size:`sm`,variant:`outline`,disabled:P||v,title:`Declines the actions whose document is gone or has nothing for them to work on, such as an email without a matching attachment`,onClick:()=>void F(`decline`,!0,`Decline the pending actions that have nothing to do? The rest of the ${c} stay in the queue.`),children:`Decline those with nothing to do`}),(0,Q.jsx)(U,{size:`sm`,variant:`outline`,disabled:P||v,onClick:()=>void F(`decline`,!1,`Decline all ${c} pending actions?`),children:`Decline all`})]}),M&&(0,Q.jsxs)(`span`,{className:M.state===`failed`?`text-destructive`:`text-muted-foreground`,children:[M.state===`running`?`Running: `:M.state===`failed`?`Stopped (${M.error}): `:`Last run: `,M.decision===`approve`?`approved`:`declined`,` `,M.decided,` of `,M.total,M.kept>0&&`, kept ${M.kept}`,M.failed>0&&`, ${M.failed} failed`]})]}),(0,Q.jsx)(`div`,{className:`border rounded-lg overflow-auto max-h-[560px]`,children:u?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground p-3`,children:`Loading...`}):o.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground p-3`,children:i===`pending`?`Nothing waiting for review. Rules or hooks with approval enabled queue their actions here.`:`No ${i===`all`?``:i+` `}actions recorded.`}):(0,Q.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Q.jsx)(`thead`,{className:`text-xs text-muted-foreground border-b sticky top-0 bg-background`,children:(0,Q.jsxs)(`tr`,{children:[(0,Q.jsx)(`th`,{className:`px-3 py-2 w-8`,children:te.length>0&&(0,Q.jsx)(`input`,{type:`checkbox`,checked:I,onChange:ne,title:`Select all pending`})}),(0,Q.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Proposed action`}),(0,Q.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Handler`}),(0,Q.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Age`}),(0,Q.jsx)(`th`,{className:`text-left font-medium px-3 py-2`,children:`Status`}),(0,Q.jsx)(`th`,{className:`px-2 py-2 w-40`})]})}),(0,Q.jsx)(`tbody`,{children:o.map(t=>{let n=t.status===`pending`||t.status===`failed`,r=m===t.actionId,i=r?Pr(t,n?g[t.actionId]??{}:{}):t.actions,a=t.envelope?.payload?.document;return(0,Q.jsxs)(Z.Fragment,{children:[(0,Q.jsxs)(`tr`,{className:`border-b last:border-0 align-top hover:bg-muted/40 cursor-pointer`,onClick:()=>h(r?null:t.actionId),children:[(0,Q.jsx)(`td`,{className:`px-3 py-2`,onClick:e=>e.stopPropagation(),children:t.status===`pending`&&(0,Q.jsx)(`input`,{type:`checkbox`,checked:f.has(t.actionId),onChange:()=>L(t.actionId)})}),(0,Q.jsxs)(`td`,{className:`px-3 py-2`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 font-medium`,children:[r?(0,Q.jsx)(b,{className:`h-3 w-3 shrink-0`}):(0,Q.jsx)(ee,{className:`h-3 w-3 shrink-0`}),t.title,t.editable?.length>0&&(0,Q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide rounded bg-muted-foreground/15 px-1 py-0.5 text-muted-foreground shrink-0`,children:`editable`})]}),t.summary&&(0,Q.jsx)(`span`,{className:`block text-xs text-muted-foreground pl-4`,children:(0,Q.jsx)(Ur,{workspaceId:e,text:t.summary})})]}),(0,Q.jsxs)(`td`,{className:`px-3 py-2 font-mono text-xs whitespace-nowrap`,children:[(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[t.handlerType,`:`]}),t.handler,t.event&&(0,Q.jsxs)(`span`,{className:`block text-muted-foreground`,children:[t.event,a?.id!=null&&(0,Q.jsxs)(Q.Fragment,{children:[` · `,(0,Q.jsx)(Hr,{workspaceId:e,id:a.id})]})]})]}),(0,Q.jsx)(`td`,{className:`px-3 py-2 text-xs whitespace-nowrap`,title:t.ts,children:Lr(t.ts)}),(0,Q.jsxs)(`td`,{className:`px-3 py-2 text-xs`,children:[(0,Q.jsx)(`span`,{className:Ir[t.status],children:t.status}),t.amended&&(0,Q.jsx)(`span`,{className:`block text-muted-foreground`,children:`amended`}),t.decidedBy&&(0,Q.jsx)(`span`,{className:`block text-muted-foreground truncate max-w-[120px]`,title:t.decidedBy,children:t.decidedBy})]}),(0,Q.jsx)(`td`,{className:`px-2 py-2 whitespace-nowrap text-right`,onClick:e=>e.stopPropagation(),children:n&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(U,{size:`sm`,className:`h-7 px-2`,disabled:v,title:t.status===`failed`?`Retry (re-approve)`:`Approve and execute`,onClick:()=>void re([t.actionId],[]),children:(0,Q.jsx)(T,{className:`h-3.5 w-3.5`})}),t.status===`pending`&&(0,Q.jsx)(U,{size:`sm`,variant:`ghost`,className:`h-7 px-2 text-muted-foreground`,disabled:v,title:`Decline`,onClick:()=>void re([],[t.actionId]),children:(0,Q.jsx)(D,{className:`h-3.5 w-3.5`})})]})})]}),r&&(0,Q.jsxs)(`tr`,{className:`border-b last:border-0 bg-muted/20`,children:[(0,Q.jsx)(`td`,{className:`px-3 py-3`}),(0,Q.jsxs)(`td`,{className:`px-3 py-3 space-y-3`,colSpan:5,children:[n&&t.editable?.length>0&&(0,Q.jsx)(Wr,{action:t,amend:g[t.actionId]??{},onAmend:(e,n)=>R(t.actionId,e,n)}),i.map((e,n)=>{let r=Mr(e,t.pathMatch);return r&&(0,Q.jsxs)(`p`,{className:`text-xs`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Destination folder: `}),(0,Q.jsx)(`span`,{className:`font-mono break-all`,children:r})]},n)}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:`Actions on approve`}),(0,Q.jsx)(`pre`,{className:`mt-1 rounded border bg-background p-2 font-mono text-xs overflow-auto max-h-56`,children:JSON.stringify(i.map(e=>Nr(e,t.pathMatch)),null,2)})]}),(0,Q.jsxs)(`details`,{className:`text-xs text-muted-foreground`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer`,children:`Rule action settings`}),(0,Q.jsx)(`pre`,{className:`mt-1 rounded border bg-background p-2 font-mono overflow-auto max-h-56`,children:JSON.stringify(i,null,2)})]}),t.result&&t.result.length>0&&(0,Q.jsx)(`div`,{className:`text-xs font-mono`,children:t.result.map((e,t)=>(0,Q.jsxs)(`span`,{className:`mr-2 ${e.status===`error`?`text-destructive`:`text-muted-foreground`}`,children:[e.action,`:`,e.status,e.error?` (${e.error})`:``]},t))}),(0,Q.jsxs)(`p`,{className:`text-[11px] text-muted-foreground font-mono`,children:[t.actionId,` · origin `,t.provenance?.origin,t.provenance?.causedBy?` · causedBy ${t.provenance.causedBy}`:``,t.expiresAt?` · expires ${new Date(t.expiresAt).toLocaleString()}`:``]})]})]})]},t.actionId)})})]})})]})}var Kr=`#!/usr/bin/env bash
|
|
2
2
|
# Called from a hook via: spawn('bash', [script, ...args])
|
|
3
3
|
set -euo pipefail
|
|
4
4
|
`;function qr({workspaceId:e,prefillRule:t,onPrefillConsumed:n,initialSection:r,initialRunsHandler:i,initialRunId:a}){let{showToast:o}=q(),[s,c]=(0,Z.useState)(r??`rules`),[l,u]=(0,Z.useState)(t);t!==l&&(u(t),t&&c(`rules`));let[d,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)([]),[_,y]=(0,Z.useState)(!0),[x,C]=(0,Z.useState)(null),[w,T]=(0,Z.useState)(``),[E,M]=(0,Z.useState)(!1),[N,F]=(0,Z.useState)(!1),[ee,ne]=(0,Z.useState)(!1),[L,re]=(0,Z.useState)(null),[ie,se]=(0,Z.useState)(`document.inserted`),[le,ue]=(0,Z.useState)(``),[B,fe]=(0,Z.useState)([]),[pe,me]=(0,Z.useState)(!1),[he,_e]=(0,Z.useState)([]),[ve,V]=(0,Z.useState)(!1),[H,ye]=(0,Z.useState)(i||null),[G,be]=(0,Z.useState)(a?{runId:a,run:null}:null),K=e=>{be(t=>t?.runId===e?null:{runId:e,run:null})};(0,Z.useEffect)(()=>{if(!G||G.run||G.error)return;let t=!1;return Pt(e,G.runId).then(e=>{t||be(t=>t?.runId===e.runId?{runId:e.runId,run:e}:t)}).catch(e=>{t||be(t=>t?.runId===G.runId?{...t,error:e instanceof Error?e.message:`Failed to load run`}:t)}),()=>{t=!0}},[e,G]);let[Se,Ce]=(0,Z.useState)(null),[we,Te]=(0,Z.useState)(!1),[Ee,De]=(0,Z.useState)(0),[Oe,ke]=(0,Z.useState)(null),[Ae,je]=(0,Z.useState)(()=>It()),[Me,Ne]=(0,Z.useState)(()=>String(It())),J=()=>{let e=Nt(Vt(Me));je(e),Ne(String(e))};(0,Z.useEffect)(()=>{let t=!1;return Mt(e,{status:`pending`,limit:1}).then(({total:e})=>{t||De(e)}).catch(()=>{}),()=>{t=!0}},[e]),mt(()=>Te(!1),we);let Y=async t=>{if(confirm(`Replay ${t.handlerType} "${t.handler}" for ${t.event} (docs ${(t.docIds||[]).join(`, `)})?`)){Ce(t.runId);try{let n=await wt(e,t.runId);o({title:`Replayed`,description:`${t.handler} → ${n.status}`}),await Ie()}catch(e){o({title:`Replay failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{Ce(null)}}},Pe=s===`scripts`?{list:Wt,get:Jt,save:Lt,del:Kt}:{list:Et,get:Qt,save:jt,del:Ut},Fe=s===`hooks`||s===`scripts`,Ie=async()=>{if(s!==`rules`&&s!==`pending`){if(s===`runs`){try{y(!0),_e(await Gt(e,{limit:100,failed:ve||void 0,handler:H||void 0}))}catch{o({title:`Error`,description:`Failed to load hook runs`,variant:`destructive`})}finally{y(!1)}return}try{y(!0),h(await Pe.list(e))}catch{o({title:`Error`,description:`Failed to load ${s}`,variant:`destructive`})}finally{y(!1)}}};(0,Z.useEffect)(()=>{Ie()},[e,s,ve,H]);let Le=e=>{e!==s&&(E&&!confirm(`Discard unsaved changes?`)||(c(e),C(null),T(``),M(!1),ne(!1)))},Re=async t=>{if(!(E&&!confirm(`Discard unsaved changes?`)))try{C(t),T(await Pe.get(e,t)),M(!1)}catch{o({title:`Error`,description:`Failed to open ${t}`,variant:`destructive`})}},ze=async()=>{if(x)try{F(!0),await Pe.save(e,x,w),M(!1),o({title:`Saved`,description:`${x} saved`}),await Ie()}catch{o({title:`Error`,description:`Failed to save ${x}`,variant:`destructive`})}finally{F(!1)}},Be=async t=>{let n=Dt(t);try{let r=await Ot(e,t,!n);x===t&&C(r),await Ie(),o({title:n?`Disabled`:`Enabled`,description:r})}catch{o({title:`Error`,description:`Failed to toggle ${t}`,variant:`destructive`})}},Ve=async t=>{let n=Zt(t);if(!n||!Dt(t)&&!confirm(`${t} is disabled. Run it anyway?`))return;let r=n.startsWith(`document.`);if(!(r&&!confirm(`Run ${t} against up to ${Ae} existing documents (event ${n})?`))){ke(t);try{if(r){let r=await Bt(e,{hookFile:t,event:n,limit:Ae});o({title:`Run finished`,description:`${r.processed} documents processed, ${r.failed} failed. Details in the Runs tab`,...r.failed?{variant:`destructive`}:{}})}else{let r=await At(e,{hookFile:t,event:n});o({title:r.status===`error`?`Run failed`:`Run finished`,description:r.status===`error`?`${t}: ${r.error||`see the Runs tab`}`:`${t} → ${r.status}${r.durationMs==null?``:` in ${r.durationMs}ms`}`,...r.status===`error`?{variant:`destructive`}:{}})}}catch(e){o({title:`Run failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{ke(null)}}},X=async t=>{if(confirm(`Delete ${s===`hooks`?`hook`:`script`} ${t}?`))try{await Pe.del(e,t),x===t&&(C(null),T(``),M(!1)),await Ie(),o({title:`Deleted`,description:`${t} deleted`})}catch{o({title:`Error`,description:`Failed to delete ${t}`,variant:`destructive`})}},He=async()=>{if(!L)try{re(await Rt(e))}catch{o({title:`Error`,description:`Failed to load hook metadata`,variant:`destructive`})}},Ue=async()=>{ne(!ee),s===`hooks`&&await He()},We=async()=>{p(!d),await He()},Ge=async()=>{let t=le.trim().replace(/^\/+/,``);if(!t){o({title:`Error`,description:`Give the script a name (e.g. on-image.sh)`,variant:`destructive`});return}try{me(!0),await Lt(e,t,Kr),ne(!1),ue(``),await Ie(),await Re(t)}catch{o({title:`Error`,description:`Failed to create script`,variant:`destructive`})}finally{me(!1)}},Ke=e=>{fe(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},qe=async()=>{if(!le.trim()){o({title:`Error`,description:`Give the hook a name`,variant:`destructive`});return}try{me(!0);let{path:t}=await Ht(e,{event:ie,name:le.trim(),actions:B});ne(!1),ue(``),fe([]),await Ie(),await Re(t),o({title:`Created`,description:`${t}. Edit the TODOs, then enable it`})}catch{o({title:`Error`,description:`Failed to create hook`,variant:`destructive`})}finally{me(!1)}},Je=s===`hooks`?Tt(m):{scripts:m},Ye=`${xe}/workspaces/${e}/git/internal`;return(0,Q.jsxs)(`div`,{className:`@container space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3 @3xl:flex-row @3xl:items-start @3xl:justify-between`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 @3xl:min-w-[18rem] @3xl:flex-1`,children:[(0,Q.jsx)(`h3`,{className:`text-lg font-medium`,children:`Automation`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Rules are simple click-to-build automations (Outlook-style). Hooks are their programmable big brother; scripts are the shell helpers hooks spawn. Everything commits to the workspace git repo.`})]}),(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-col gap-2 @3xl:max-w-[60%] @3xl:flex-row @3xl:items-center`,children:(0,Q.jsx)(`div`,{className:`w-full min-w-0 @3xl:w-auto`,children:(0,Q.jsx)(bt,{className:`border-b-0`,active:s,onChange:Le,tabs:[{id:`pending`,label:Ee>0?`Pending (${Ee})`:`Pending`,icon:f},{id:`rules`,label:`Rules`,icon:ge},{id:`hooks`,label:`Hooks`,icon:te},{id:`scripts`,label:`Scripts`,icon:R},{id:`runs`,label:`Runs`,icon:v}]})})})]}),(s===`runs`||Fe)&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[s===`runs`&&(0,Q.jsxs)(Q.Fragment,{children:[H&&(0,Q.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-full border bg-muted/50 px-2.5 py-1 font-mono text-xs hover:bg-muted`,title:`Showing runs of this rule / hook only — click to clear`,onClick:()=>ye(null),children:[H,` `,(0,Q.jsx)(D,{className:`h-3 w-3`})]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:ve,onChange:e=>V(e.target.checked)}),`failed only`]}),(0,Q.jsxs)(U,{size:`sm`,variant:`ghost`,onClick:Ie,title:`Reload`,children:[(0,Q.jsx)(z,{className:`mr-1.5 h-4 w-4`}),` Reload`]})]}),Fe&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(U,{size:`sm`,variant:`ghost`,onClick:Ie,title:`Reload`,children:[(0,Q.jsx)(z,{className:`mr-1.5 h-4 w-4`}),` Reload`]}),(0,Q.jsxs)(U,{size:`sm`,variant:`ghost`,onClick:We,title:`Hook context API & classifier reference`,children:[(0,Q.jsx)(de,{className:`mr-1.5 h-4 w-4`}),` Reference`]}),(0,Q.jsxs)(U,{size:`sm`,variant:`outline`,onClick:Ue,children:[(0,Q.jsx)(A,{className:`mr-2 h-4 w-4`}),` `,s===`hooks`?`New Hook`:`New Script`]})]})]}),s===`pending`&&(0,Q.jsx)(Gr,{workspaceId:e,onPendingCount:De}),s===`rules`&&(0,Q.jsx)(Yt,{workspaceId:e,backfillLimit:Ae,onShowRuns:e=>{ye(e),Le(`runs`)},prefill:t,onPrefillConsumed:n,onOpenJson:async()=>{try{await Qt(e,`rules.json`)}catch{await jt(e,`rules.json`,JSON.stringify({$schema:`canvas.hook-rules/v1`,rules:[]},null,2)+`
|