wiki-viewer 1.8.0 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/.next/standalone/.github/workflows/publish.yml +1 -1
  2. package/.next/standalone/.next/BUILD_ID +1 -1
  3. package/.next/standalone/.next/build-manifest.json +3 -3
  4. package/.next/standalone/.next/server/app/_global-error.html +1 -1
  5. package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
  6. package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  7. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  8. package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  9. package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  10. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  11. package/.next/standalone/.next/server/app/_not-found.html +1 -1
  12. package/.next/standalone/.next/server/app/_not-found.rsc +1 -1
  13. package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  14. package/.next/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  15. package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  16. package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  17. package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  18. package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  19. package/.next/standalone/.next/server/app/api/wiki/upload/route.js.nft.json +1 -1
  20. package/.next/standalone/.next/server/app/index.html +1 -1
  21. package/.next/standalone/.next/server/app/index.rsc +2 -2
  22. package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  23. package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +2 -2
  24. package/.next/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  25. package/.next/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  26. package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  27. package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  28. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0269d2e._.js +1 -1
  29. package/.next/standalone/.next/server/chunks/ssr/_0pqaawz._.js +1 -1
  30. package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
  31. package/.next/standalone/.next/server/middleware-manifest.json +1 -1
  32. package/.next/standalone/.next/server/pages/404.html +1 -1
  33. package/.next/standalone/.next/server/pages/500.html +1 -1
  34. package/.next/standalone/.next/static/chunks/{0l4842ez-0_66.js → 16r--8~rpehcz.js} +1 -1
  35. package/.next/standalone/agents/bootstrap-prompt.md +3 -1
  36. package/.next/standalone/agents/wiki-viewer-skill/SKILL.md +38 -11
  37. package/.next/standalone/package.json +1 -1
  38. package/.next/standalone/packages/wiki-viewer-mcp/README.md +6 -5
  39. package/.next/standalone/packages/wiki-viewer-mcp/dist/http-client.js +4 -0
  40. package/.next/standalone/packages/wiki-viewer-mcp/dist/index.js +4 -0
  41. package/.next/standalone/packages/wiki-viewer-mcp/package-lock.json +2 -2
  42. package/.next/standalone/packages/wiki-viewer-mcp/package.json +1 -1
  43. package/.next/standalone/packages/wiki-viewer-mcp/src/http-client.ts +6 -0
  44. package/.next/standalone/packages/wiki-viewer-mcp/src/index.ts +5 -0
  45. package/.next/standalone/src/app/api/agents/install/route.ts +20 -2
  46. package/.next/standalone/src/app/page.tsx +51 -1
  47. package/.next/standalone/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +1 -1
  49. /package/.next/standalone/.next/static/{t7B6nXaoD1jo9f61t3aeK → t_k0ztuf0V-iA-kgeez18}/_buildManifest.js +0 -0
  50. /package/.next/standalone/.next/static/{t7B6nXaoD1jo9f61t3aeK → t_k0ztuf0V-iA-kgeez18}/_clientMiddlewareManifest.js +0 -0
  51. /package/.next/standalone/.next/static/{t7B6nXaoD1jo9f61t3aeK → t_k0ztuf0V-iA-kgeez18}/_ssgManifest.js +0 -0
@@ -126,4 +126,4 @@ TOKEN=<paste token here>
126
126
  # 3. Read snapshot
127
127
  curl -s -H "Authorization: Bearer $TOKEN" \\
128
128
  -H "X-Agent-Id: ai:claude" \\
129
- ${t}/api/agent/files/${e??"<path/to/file.md>"}`;await navigator.clipboard.writeText(r),n(!0),setTimeout(()=>n(!1),1500)},[e])}}(e??null),[l,c]=(0,Q.useState)(""),d=(0,Q.useRef)(null),u=window.location.origin,p=(0,Q.useCallback)(()=>IH,[]),h=(0,Q.useCallback)(()=>l.replace(/\$WIKI_URL/g,u),[l,u]),f=(0,Q.useCallback)(()=>`npx wiki-viewer-mcp register --url ${u} --id ai:myagent --name "My Agent"`,[u]),m=(0,Q.useCallback)(()=>JSON.stringify({servers:{"wiki-viewer":{command:"npx",args:["wiki-viewer-mcp"],env:{WIKI_VIEWER_URL:u,WIKI_VIEWER_TOKEN:"<token from register>",WIKI_VIEWER_AGENT_ID:"ai:myagent"}}}},null,2),[u]),g=IU(p),b=IU(h),y=IU(f),x=IU(m);return((0,Q.useEffect)(()=>{if(t)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&n()}},[t,n]),(0,Q.useEffect)(()=>{t&&d.current?.focus()},[t]),(0,Q.useEffect)(()=>{if(!t)return;o();let e=setInterval(()=>void o(),1e4);return()=>clearInterval(e)},[t,o]),(0,Q.useEffect)(()=>{t&&fetch("/api/agents/install").then(e=>e.json()).then(e=>{e.bootstrapPrompt&&c(e.bootstrapPrompt)}).catch(()=>void 0)},[t]),t)?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)("div",{className:"fixed inset-0 z-40 bg-black/20 backdrop-blur-[1px]",onClick:n,"aria-hidden":!0}),(0,X.jsxs)("aside",{ref:d,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":"AI Agent Panel",className:"fixed right-0 top-0 bottom-0 z-50 flex w-80 flex-col border-l border-border bg-background shadow-xl outline-none",children:[(0,X.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-4 py-3 shrink-0",children:[(0,X.jsxs)("div",{className:"flex items-center gap-2",children:[(0,X.jsx)(ei,{className:"h-4 w-4 text-muted-foreground"}),(0,X.jsx)("span",{className:"text-sm font-semibold",children:"AI Agent"})]}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:n,title:"Close panel (Esc)",children:(0,X.jsx)(eC,{className:"h-3.5 w-3.5"})})]}),(0,X.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-5 px-4 py-4",children:[(0,X.jsxs)("section",{className:"rounded-md border border-border bg-muted/30 p-3",children:[(0,X.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Work with this wiki using AI"}),(0,X.jsxs)("p",{className:"mt-1 text-xs leading-relaxed text-muted-foreground",children:["Connect Claude, Cursor, ChatGPT, and more. Pick by what you want — each option gives a copy-paste setup. You approve every assistant in ",(0,X.jsx)("span",{className:"font-medium text-foreground/80",children:"Agents"})," below before it gets access."]})]}),(0,X.jsxs)("section",{className:"space-y-3",children:[(0,X.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,X.jsx)("p",{className:"text-xs font-semibold text-foreground",children:"Co-write docs with you"}),(0,X.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Edits arrive as suggestions with comments you accept or revert. No MCP needed."}),(0,X.jsx)(tq,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void b.copy(),disabled:!l,children:b.copied?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(eo,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_w,{className:"h-3.5 w-3.5"})," Paste into any chatbot"]})}),(0,X.jsxs)("p",{className:"text-[10px] text-muted-foreground/50 pt-1",children:["Or install once so it sticks"," ",(0,X.jsx)("span",{className:"text-muted-foreground/40",children:"· Claude, OpenCode"}),":"]}),(0,X.jsxs)("div",{className:"flex items-center gap-2",children:[(0,X.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:IH}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void g.copy(),children:g.copied?(0,X.jsx)(eo,{className:"h-3.5 w-3.5 text-green-500"}):(0,X.jsx)(_w,{className:"h-3.5 w-3.5"})})]})]}),(0,X.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,X.jsxs)("p",{className:"text-xs font-semibold text-foreground",children:["Edit files directly"," ",(0,X.jsx)("span",{className:"font-normal text-muted-foreground/60",children:"· Claude Code, Cursor, Codex"})]}),(0,X.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Native read / search / edit tools over MCP. Run to request access:"}),(0,X.jsxs)("div",{className:"flex items-center gap-2",children:[(0,X.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:f()}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void y.copy(),children:y.copied?(0,X.jsx)(eo,{className:"h-3.5 w-3.5 text-green-500"}):(0,X.jsx)(_w,{className:"h-3.5 w-3.5"})})]}),(0,X.jsxs)("p",{className:"text-[10px] text-muted-foreground/50",children:["Approve in ",(0,X.jsx)("span",{className:"font-medium text-foreground/70",children:"Agents"}),", then add to your tool:"]}),(0,X.jsx)(tq,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void x.copy(),children:x.copied?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(eo,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_w,{className:"h-3.5 w-3.5"})," Copy config (mcp.json)"]})})]}),(0,X.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[(0,X.jsx)("span",{className:"text-[10px] text-muted-foreground/50",children:"For developers:"}),(0,X.jsxs)("button",{type:"button",onClick:()=>void a(),className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[s?(0,X.jsx)(eo,{className:"h-3 w-3 text-green-500"}):(0,X.jsx)(_w,{className:"h-3 w-3"})," curl example"]}),(0,X.jsxs)("a",{href:"/api/agents/skill",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[(0,X.jsx)(kl,{className:"h-3 w-3"})," skill"]}),(0,X.jsxs)("a",{href:"/api/agents/install",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[(0,X.jsx)(kl,{className:"h-3 w-3"})," install JSON"]})]})]}),(0,X.jsx)(IB,{}),(0,X.jsxs)("section",{className:"space-y-2",children:[(0,X.jsxs)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:["Active Connections"," ",(0,X.jsx)("span",{className:"normal-case font-normal text-muted-foreground/50",children:"(last 5 min)"})]}),(0,X.jsx)("div",{className:"rounded-md border border-border bg-muted/40 p-3",children:0===i.length?(0,X.jsxs)("p",{className:"text-xs text-muted-foreground/60 flex items-center gap-1.5",children:[(0,X.jsx)(IM,{className:"h-3.5 w-3.5"}),"No recent activity"]}):(0,X.jsx)("ul",{className:"space-y-1.5",children:i.map(e=>(0,X.jsxs)("li",{className:"flex items-center justify-between text-xs",children:[(0,X.jsx)("span",{className:"font-mono text-foreground/80 truncate",children:e.by}),(0,X.jsxs)("span",{className:"text-muted-foreground shrink-0",children:[e.opCount," op",1!==e.opCount?"s":""]})]},e.by))})})]}),(0,X.jsxs)("section",{className:"space-y-2",children:[(0,X.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Recent Activity"}),(0,X.jsx)("div",{className:"rounded-md border border-border bg-muted/40 px-3 py-1 max-h-72 overflow-y-auto",children:0===r.length?(0,X.jsx)("p",{className:"text-xs text-muted-foreground/60 py-2",children:"No events recorded"}):r.map(e=>(0,X.jsx)(IF,{event:e},`${e.path}-${e.id}`))})]}),(0,X.jsx)("section",{children:(0,X.jsx)("a",{href:"/docs/agent-collab-plan.md",target:"_blank",rel:"noreferrer",className:"text-xs text-primary underline hover:no-underline",children:"Agent collaboration docs →"})})]})]})]}):null}var I$=/[\\\/_+.#"@\[\(\{&]/,IG=/[\\\/_+.#"@\[\(\{&]/g,Iq=/[\s-]/,IV=/[\s-]/g;function IW(e){return e.toLowerCase().replace(IV," ")}var IK='[cmdk-group=""]',IY='[cmdk-group-items=""]',IX='[cmdk-item=""]',IQ=`${IX}:not([aria-disabled="true"])`,IJ="cmdk-item-select",IZ="data-value",I0=(e,t,n)=>{var r;return r=e,function e(t,n,r,i,o,s,a){if(s===n.length)return o===t.length?1:.99;var l=`${o},${s}`;if(void 0!==a[l])return a[l];for(var c,d,u,p,h=i.charAt(s),f=r.indexOf(h,o),m=0;f>=0;)(c=e(t,n,r,i,f+1,s+1,a))>m&&(f===o?c*=1:I$.test(t.charAt(f-1))?(c*=.8,(u=t.slice(o,f-1).match(IG))&&o>0&&(c*=Math.pow(.999,u.length))):Iq.test(t.charAt(f-1))?(c*=.9,(p=t.slice(o,f-1).match(IV))&&o>0&&(c*=Math.pow(.999,p.length))):(c*=.17,o>0&&(c*=Math.pow(.999,f-o))),t.charAt(f)!==n.charAt(s)&&(c*=.9999)),(c<.1&&r.charAt(f-1)===i.charAt(s+1)||i.charAt(s+1)===i.charAt(s)&&r.charAt(f-1)!==i.charAt(s))&&.1*(d=e(t,n,r,i,f+1,s+2,a))>c&&(c=.1*d),c>m&&(m=c),f=r.indexOf(h,f+1);return a[l]=m,m}(r=n&&n.length>0?`${r+" "+n.join(" ")}`:r,t,IW(r),IW(t),0,0,{})},I1=Q.createContext(void 0),I2=Q.createContext(void 0),I3=Q.createContext(void 0),I5=Q.forwardRef((e,t)=>{let n=Di(()=>{var t,n;return{search:"",value:null!=(n=null!=(t=e.value)?t:e.defaultValue)?n:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=Di(()=>new Set),i=Di(()=>new Map),o=Di(()=>new Map),s=Di(()=>new Set),a=Dn(e),{label:l,children:c,value:d,onValueChange:u,filter:p,shouldFilter:h,loop:f,disablePointerSelection:m=!1,vimBindings:g=!0,...b}=e,y=tQ(),x=tQ(),v=tQ(),E=Q.useRef(null),w=Da();Dr(()=>{if(void 0!==d){let e=d.trim();n.current.value=e,k.emit()}},[d]),Dr(()=>{w(6,_)},[]);let k=Q.useMemo(()=>({subscribe:e=>(s.current.add(e),()=>s.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,o,s,l;if(!Object.is(n.current[e],t)){if(n.current[e]=t,"search"===e)C(),A(),w(1,S);else if("value"===e){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let e=document.getElementById(v);e?e.focus():null==(i=document.getElementById(y))||i.focus()}if(w(7,()=>{var e;n.current.selectedItemId=null==(e=M())?void 0:e.id,k.emit()}),r||w(5,_),(null==(o=a.current)?void 0:o.value)!==void 0){null==(l=(s=a.current).onValueChange)||l.call(s,null!=t?t:"");return}}k.emit()}},emit:()=>{s.current.forEach(e=>e())}}),[]),T=Q.useMemo(()=>({value:(e,t,r)=>{var i;t!==(null==(i=o.current.get(e))?void 0:i.value)&&(o.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,N(t,r)),w(2,()=>{A(),k.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),w(3,()=>{C(),A(),n.current.value||S(),k.emit()}),()=>{o.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=M();w(4,()=>{C(),(null==t?void 0:t.getAttribute("id"))===e&&S(),k.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{o.current.delete(e),i.current.delete(e)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:y,inputId:v,labelId:x,listInnerRef:E}),[]);function N(e,t){var r,i;let o=null!=(i=null==(r=a.current)?void 0:r.filter)?i:I0;return e?o(e,n.current.search,t):0}function A(){if(!n.current.search||!1===a.current.shouldFilter)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),o=0;r.forEach(t=>{o=Math.max(e.get(t),o)}),t.push([n,o])});let r=E.current;O().sort((t,n)=>{var r,i;let o=t.getAttribute("id"),s=n.getAttribute("id");return(null!=(r=e.get(s))?r:0)-(null!=(i=e.get(o))?i:0)}).forEach(e=>{let t=e.closest(IY);t?t.appendChild(e.parentElement===t?e:e.closest(`${IY} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${IY} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{var t;let n=null==(t=E.current)?void 0:t.querySelector(`${IK}[${IZ}="${encodeURIComponent(e[0])}"]`);null==n||n.parentElement.appendChild(n)})}function S(){let e=O().find(e=>"true"!==e.getAttribute("aria-disabled")),t=null==e?void 0:e.getAttribute(IZ);k.setState("value",t||void 0)}function C(){var e,t,s,l;if(!n.current.search||!1===a.current.shouldFilter){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let c=0;for(let i of r.current){let r=N(null!=(t=null==(e=o.current.get(i))?void 0:e.value)?t:"",null!=(l=null==(s=o.current.get(i))?void 0:s.keywords)?l:[]);n.current.filtered.items.set(i,r),r>0&&c++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=c}function _(){var e,t,n;let r=M();r&&((null==(e=r.parentElement)?void 0:e.firstChild)===r&&(null==(n=null==(t=r.closest(IK))?void 0:t.querySelector('[cmdk-group-heading=""]'))||n.scrollIntoView({block:"nearest"})),r.scrollIntoView({block:"nearest"}))}function M(){var e;return null==(e=E.current)?void 0:e.querySelector(`${IX}[aria-selected="true"]`)}function O(){var e;return Array.from((null==(e=E.current)?void 0:e.querySelectorAll(IQ))||[])}function I(e){let t=O()[e];t&&k.setState("value",t.getAttribute(IZ))}function D(e){var t;let n=M(),r=O(),i=r.findIndex(e=>e===n),o=r[i+e];null!=(t=a.current)&&t.loop&&(o=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),o&&k.setState("value",o.getAttribute(IZ))}function R(e){let t=M(),n=null==t?void 0:t.closest(IK),r;for(;n&&!r;)r=null==(n=e>0?function(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}(n,IK):function(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}(n,IK))?void 0:n.querySelector(IQ);r?k.setState("value",r.getAttribute(IZ)):D(e)}let L=()=>I(O().length-1),P=e=>{e.preventDefault(),e.metaKey?L():e.altKey?R(1):D(1)},j=e=>{e.preventDefault(),e.metaKey?I(0):e.altKey?R(-1):D(-1)};return Q.createElement(kA.div,{ref:t,tabIndex:-1,...b,"cmdk-root":"",onKeyDown:e=>{var t;null==(t=b.onKeyDown)||t.call(b,e);let n=e.nativeEvent.isComposing||229===e.keyCode;if(!(e.defaultPrevented||n))switch(e.key){case"n":case"j":g&&e.ctrlKey&&P(e);break;case"ArrowDown":P(e);break;case"p":case"k":g&&e.ctrlKey&&j(e);break;case"ArrowUp":j(e);break;case"Home":e.preventDefault(),I(0);break;case"End":e.preventDefault(),L();break;case"Enter":{e.preventDefault();let t=M();if(t){let e=new Event(IJ);t.dispatchEvent(e)}}}}},Q.createElement("label",{"cmdk-label":"",htmlFor:T.inputId,id:T.labelId,style:Dc},l),Dl(e,e=>Q.createElement(I2.Provider,{value:k},Q.createElement(I1.Provider,{value:T},e))))}),I4=Q.forwardRef((e,t)=>{var n,r;let i=tQ(),o=Q.useRef(null),s=Q.useContext(I3),a=Q.useContext(I1),l=Dn(e),c=null!=(r=null==(n=l.current)?void 0:n.forceMount)?r:null==s?void 0:s.forceMount;Dr(()=>{if(!c)return a.item(i,null==s?void 0:s.id)},[c]);let d=Ds(i,o,[e.value,e.children,o],e.keywords),u=Q.useContext(I2),p=Do(e=>e.value&&e.value===d.current),h=Do(e=>!!c||!1===a.filter()||!e.search||e.filtered.items.get(i)>0);function f(){var e,t;m(),null==(t=(e=l.current).onSelect)||t.call(e,d.current)}function m(){u.setState("value",d.current,!0)}if(Q.useEffect(()=>{let t=o.current;if(!(!t||e.disabled))return t.addEventListener(IJ,f),()=>t.removeEventListener(IJ,f)},[h,e.onSelect,e.disabled]),!h)return null;let{disabled:g,value:b,onSelect:y,forceMount:x,keywords:v,...E}=e;return Q.createElement(kA.div,{ref:eM(o,t),...E,id:i,"cmdk-item":"",role:"option","aria-disabled":!!g,"aria-selected":!!p,"data-disabled":!!g,"data-selected":!!p,onPointerMove:g||a.getDisablePointerSelection()?void 0:m,onClick:g?void 0:f},e.children)}),I6=Q.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...o}=e,s=tQ(),a=Q.useRef(null),l=Q.useRef(null),c=tQ(),d=Q.useContext(I1),u=Do(e=>!!i||!1===d.filter()||!e.search||e.filtered.groups.has(s));Dr(()=>d.group(s),[]),Ds(s,a,[e.value,e.heading,l]);let p=Q.useMemo(()=>({id:s,forceMount:i}),[i]);return Q.createElement(kA.div,{ref:eM(a,t),...o,"cmdk-group":"",role:"presentation",hidden:!u||void 0},n&&Q.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),Dl(e,e=>Q.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},Q.createElement(I3.Provider,{value:p},e))))}),I9=Q.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=Q.useRef(null),o=Do(e=>!e.search);return n||o?Q.createElement(kA.div,{ref:eM(i,t),...r,"cmdk-separator":"",role:"separator"}):null}),I7=Q.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=null!=e.value,o=Q.useContext(I2),s=Do(e=>e.search),a=Do(e=>e.selectedItemId),l=Q.useContext(I1);return Q.useEffect(()=>{null!=e.value&&o.setState("search",e.value)},[e.value]),Q.createElement(kA.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:i?e.value:s,onChange:e=>{i||o.setState("search",e.target.value),null==n||n(e.target.value)}})}),I8=Q.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...i}=e,o=Q.useRef(null),s=Q.useRef(null),a=Do(e=>e.selectedItemId),l=Q.useContext(I1);return Q.useEffect(()=>{if(s.current&&o.current){let e=s.current,t=o.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty("--cmdk-list-height",n.toFixed(1)+"px")})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),Q.createElement(kA.div,{ref:eM(o,t),...i,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},Dl(e,e=>Q.createElement("div",{ref:eM(s,l.listInnerRef),"cmdk-list-sizer":""},e)))}),De=Q.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:o,container:s,...a}=e;return Q.createElement(rr,{open:n,onOpenChange:r},Q.createElement(rl,{container:s},Q.createElement(rd,{"cmdk-overlay":"",className:i}),Q.createElement(rf,{"aria-label":e.label,"cmdk-dialog":"",className:o},Q.createElement(I5,{ref:t,...a}))))}),Dt=Object.assign(I5,{List:I8,Item:I4,Input:I7,Group:I6,Separator:I9,Dialog:De,Empty:Q.forwardRef((e,t)=>Do(e=>0===e.filtered.count)?Q.createElement(kA.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Loading:Q.forwardRef((e,t)=>{let{progress:n,children:r,label:i="Loading...",...o}=e;return Q.createElement(kA.div,{ref:t,...o,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},Dl(e,e=>Q.createElement("div",{"aria-hidden":!0},e)))})});function Dn(e){let t=Q.useRef(e);return Dr(()=>{t.current=e}),t}var Dr="u"<typeof window?Q.useEffect:Q.useLayoutEffect;function Di(e){let t=Q.useRef();return void 0===t.current&&(t.current=e()),t}function Do(e){let t=Q.useContext(I2),n=()=>e(t.snapshot());return Q.useSyncExternalStore(t.subscribe,n,n)}function Ds(e,t,n,r=[]){let i=Q.useRef(),o=Q.useContext(I1);return Dr(()=>{var s;let a=(()=>{var e;for(let t of n){if("string"==typeof t)return t.trim();if("object"==typeof t&&"current"in t)return t.current?null==(e=t.current.textContent)?void 0:e.trim():i.current}})(),l=r.map(e=>e.trim());o.value(e,a,l),null==(s=t.current)||s.setAttribute(IZ,a),i.current=a}),i}var Da=()=>{let[e,t]=Q.useState(),n=Di(()=>new Map);return Dr(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function Dl({asChild:e,children:t},n){let r;return e&&Q.isValidElement(t)?Q.cloneElement("function"==typeof(r=t.type)?r(t.props):"render"in r?r.render(t.props):t,{ref:t.ref},n(t.props.children)):n(t)}var Dc={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};let Dd=en("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),Du=Q.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Dt,{ref:n,className:t$("flex h-full w-full flex-col overflow-hidden rounded-sm bg-popover text-popover-foreground",e),...t}));function Dp({children:e,shouldFilter:t,...n}){return(0,X.jsx)(rr,{...n,children:(0,X.jsxs)(rO,{className:"overflow-hidden p-0 shadow-golden max-w-lg",children:[(0,X.jsx)(rR,{className:"sr-only",children:"Search"}),(0,X.jsx)(Du,{shouldFilter:t,className:"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-normal [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",children:e})]})})}Du.displayName=Dt.displayName;let Dh=Q.forwardRef(({className:e,...t},n)=>(0,X.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,X.jsx)(Dd,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,X.jsx)(Dt.Input,{ref:n,className:t$("flex h-11 w-full rounded-sm bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));Dh.displayName=Dt.Input.displayName;let Df=Q.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Dt.List,{ref:n,className:t$("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));Df.displayName=Dt.List.displayName;let Dm=Q.forwardRef((e,t)=>(0,X.jsx)(Dt.Empty,{ref:t,className:"py-6 text-center text-sm text-muted-foreground",...e}));Dm.displayName=Dt.Empty.displayName;let Dg=Q.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Dt.Group,{ref:n,className:t$("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-normal [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));Dg.displayName=Dt.Group.displayName,Q.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Dt.Separator,{ref:n,className:t$("-mx-1 h-px bg-border",e),...t})).displayName=Dt.Separator.displayName;let Db=Q.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Dt.Item,{ref:n,className:t$("relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",e),...t}));Db.displayName=Dt.Item.displayName;let Dy=null,Dx=Ei(e=>({query:"",results:[],loading:!1,truncated:!1,open:!1,setQuery:t=>e({query:t}),setOpen:t=>e({open:t}),clear:()=>{Dy?.abort(),e({query:"",results:[],loading:!1,truncated:!1})},search:async t=>{Dy?.abort();let n=new AbortController;if(Dy=n,!t.trim())return void e({results:[],loading:!1,truncated:!1});e({loading:!0});try{let r=await r$("/api/wiki/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,limit:30}),signal:n.signal});if(!r.ok)return void e({results:[],loading:!1,truncated:!1});let i=await r.json();if(n.signal.aborted)return;e({results:i.matches??[],truncated:!!i.truncated,loading:!1})}catch(t){"AbortError"!==t.name&&e({loading:!1})}}}));function Dv({html:e}){let t=function(e){let t,n=[],r=/<mark>([\s\S]*?)<\/mark>/g,i=0;for(;null!==(t=r.exec(e));)t.index>i&&n.push({text:e.slice(i,t.index),mark:!1}),n.push({text:t[1]??"",mark:!0}),i=t.index+t[0].length;return i<e.length&&n.push({text:e.slice(i),mark:!1}),n}(e);return(0,X.jsx)(X.Fragment,{children:t.map((e,t)=>e.mark?(0,X.jsx)("mark",{className:"bg-yellow-200 dark:bg-yellow-700 rounded-[2px] px-[1px]",children:e.text},t):(0,X.jsx)("span",{children:e.text},t))})}function DE({onOpenFile:e}){let t=Dx(e=>e.open),n=Dx(e=>e.setOpen),r=Dx(e=>e.query),i=Dx(e=>e.setQuery),o=Dx(e=>e.results),s=Dx(e=>e.loading),a=Dx(e=>e.truncated),l=Dx(e=>e.search);return(0,Q.useEffect)(()=>{function e(e){(e.metaKey||e.ctrlKey)&&"k"===e.key.toLowerCase()&&(e.preventDefault(),n(!t))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,n]),(0,Q.useEffect)(()=>{if(!t)return;let e=setTimeout(()=>{l(r)},120);return()=>clearTimeout(e)},[r,t,l]),(0,X.jsxs)(Dp,{open:t,onOpenChange:n,shouldFilter:!1,children:[(0,X.jsx)(Dh,{placeholder:"Search files…",value:r,onValueChange:i}),(0,X.jsxs)(Df,{children:[s&&(0,X.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"Searching…"}),!s&&""!==r.trim()&&0===o.length&&(0,X.jsx)(Dm,{children:"No matches."}),o.length>0&&(0,X.jsx)(Dg,{heading:a?"Top results (refine query for more)":"Results",children:o.map(t=>(0,X.jsx)(Db,{value:t.path,onSelect:()=>{e(t.path),n(!1)},children:(0,X.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,X.jsx)("span",{className:"truncate font-mono text-xs",children:t.path}),t.snippet&&(0,X.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:(0,X.jsx)(Dv,{html:t.snippet})})]})},t.path))})]})]})}function Dw({onOpenFile:e}){let t=Dx(e=>e.query),n=Dx(e=>e.setQuery),r=Dx(e=>e.results),i=Dx(e=>e.loading),o=Dx(e=>e.search),s=Dx(e=>e.clear),[a,l]=(0,Q.useState)(0),c=(0,Q.useRef)(null);function d(t){let n=r[t];n&&(e(n.path),s())}return(0,Q.useEffect)(()=>{l(0)},[r]),(0,Q.useEffect)(()=>{let e=c.current?.querySelector(`[data-idx="${a}"]`);e?.scrollIntoView({block:"nearest"})},[a]),(0,X.jsxs)("div",{className:"flex flex-col gap-1 px-2 py-1.5",children:[(0,X.jsxs)("div",{className:"relative",children:[(0,X.jsx)(Dd,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 opacity-50"}),(0,X.jsx)("input",{type:"text",className:"w-full rounded-sm border bg-transparent py-1 pl-7 pr-2 text-xs outline-none focus:ring-1 focus:ring-ring",placeholder:"Search… (⌘K)",value:t,onChange:e=>{n(e.target.value),o(e.target.value)},onKeyDown:e=>{"Escape"===e.key?s():0!==r.length&&("ArrowDown"===e.key?(e.preventDefault(),l(e=>(e+1)%r.length)):"ArrowUp"===e.key?(e.preventDefault(),l(e=>(e-1+r.length)%r.length)):"Enter"===e.key&&(e.preventDefault(),d(a)))}})]}),""!==t.trim()&&(0,X.jsxs)("div",{ref:c,className:"max-h-64 overflow-y-auto rounded-sm border bg-popover",children:[i&&(0,X.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"Searching…"}),!i&&0===r.length&&(0,X.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"No matches"}),r.map((e,t)=>(0,X.jsxs)("button",{type:"button","data-idx":t,onClick:()=>d(t),onMouseEnter:()=>l(t),className:`block w-full px-2 py-1 text-left ${t===a?"bg-accent":"hover:bg-accent"}`,children:[(0,X.jsx)("div",{className:"truncate font-mono text-xs",children:e.path}),e.snippet&&(0,X.jsx)("div",{className:"truncate text-[10px] text-muted-foreground",children:(0,X.jsx)(Dv,{html:e.snippet})})]},e.path))]})]})}function Dk({className:e}){let t=Ek(e=>e.width),n=Ek(e=>e.setWidth);return(0,X.jsxs)(O5,{children:[(0,X.jsx)(O6,{asChild:!0,children:(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:`h-7 w-7 p-0 ${e??""}`,title:`Content width: ${EE[t]}`,children:(0,X.jsx)(w4,{className:"h-3.5 w-3.5"})})}),(0,X.jsx)(Ic,{align:"end",className:"w-36",children:Ew.map(e=>(0,X.jsxs)(Id,{onClick:()=>n(e),className:"flex items-center justify-between text-xs",children:[EE[e],e===t&&(0,X.jsx)(eo,{className:"h-3.5 w-3.5"})]},e))})]})}function DT(e){return e.split(".").pop()?.toLowerCase()??""}function DN(e,t){if("node-app"===t)return"node-app";if("app"===t)return"app";if("dir"===t)return"fallback";let n=DT(e);return n?["md","markdown"].includes(n)?"editor":"txt"===n?"text":["csv","tsv"].includes(n)?"csv":"pdf"===n?"pdf":["mmd","mermaid"].includes(n)?"mermaid":"ipynb"===n?"notebook":["png","jpg","jpeg","gif","webp","svg","avif","ico","bmp"].includes(n)?"image":["mp4","webm","mov","m4v","mp3","wav","ogg","m4a","aac"].includes(n)?"media":"docx"===n?"docx":["xlsx","xlsm"].includes(n)?"xlsx":"pptx"===n?"pptx":"html"===n?"html":["py","js","ts","tsx","jsx","go","rs","java","c","cpp","h","sh","bash","zsh","rb","php","swift","kt","lua","sql","yaml","yml","toml","json","xml","css","scss"].includes(n)?"source":"fallback":"fallback"}let DA=new Set(["txt","md","markdown","json","yaml","yml","toml","csv","tsv","xml","html","css","js","ts","tsx","jsx","sh","bash","zsh","rb","py","go","rs","java","c","cpp","h","php","swift","kt","lua","sql","scss","mmd","mermaid","ini","env","log","conf"]);function DS(e){let t=DN(e,"file");return"editor"===t||"text"===t||DA.has(DT(e))}function DC(e){return["md","markdown"].includes(DT(e))}function D_(e){return"image"===DN(e,"file")}async function DM(e){let t=await r$(`/api/wiki?dir=${encodeURIComponent(e)}`);return t.ok?(await t.json()).entries.map(t=>({name:t.name,path:e?`${e}/${t.name}`:t.name,type:t.type,size:t.size,modifiedAt:t.modifiedAt,expanded:!1})):[]}function DO(e,t,n){return e.map(e=>e.path===t?n(e):e.children?{...e,children:DO(e.children,t,n)}:e)}e.s(["default",0,function(){let e;ET(e=>e.loadedAt),(0,Q.useEffect)(()=>{ET.getState().load()},[]);let[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(()=>rU()),[a,l]=(0,Q.useState)([]),[c,d]=(0,Q.useState)(!1),[u,p]=(0,Q.useState)(!1),h=(0,Q.useCallback)(async()=>{try{let e=await fetch("/api/system/workspaces");if(!e.ok)throw Error("Failed");let t=await e.json();if(l(t.workspaces),d(t.isAdmin),t.workspaces.length>0){n(!0);let e=new URLSearchParams(window.location.search).get("ws"),r=e?t.workspaces.find(t=>t.id===e):null,o=r??[...t.workspaces].sort((e,t)=>(t.lastOpenedAt??t.createdAt).localeCompare(e.lastOpenedAt??e.createdAt))[0];if(s(o.id),i(o.rootDir),!r){let e=new URL(location.href);e.searchParams.set("ws",o.id),history.replaceState(null,"",e.toString())}}else n(!1)}catch{n(!1)}},[]);(0,Q.useEffect)(()=>{h()},[h]);let f=Eg(e=>e.currentPath),m=(0,Q.useRef)(new URLSearchParams(window.location.search).get("path")),g=(0,Q.useRef)(!1),[b,y]=(0,Q.useState)([]),[x,v]=(0,Q.useState)(!1),[E,w]=(0,Q.useState)(!1),k=(0,Q.useRef)(!1),[T,N]=(0,Q.useState)(!1),[A,S]=(0,Q.useState)(!1),[C,_]=(0,Q.useState)(null),M=(0,Q.useRef)(null),O=(0,Q.useRef)(""),[I,D]=(0,Q.useState)(null),[R,L]=(0,Q.useState)(""),[P,j]=(0,Q.useState)(null),[B,F]=(0,Q.useState)(null),[H,U]=(0,Q.useState)(""),[z,$]=(0,Q.useState)(null),[G,q]=(0,Q.useState)(null),[V,W]=(0,Q.useState)(!1),[K,Y]=(0,Q.useState)(null),[J,Z]=(0,Q.useState)(!1),[ee,et]=(0,Q.useState)(0),[en,e_]=(0,Q.useState)(!1),[eM,eO]=(0,Q.useState)(!1),[eI,eD]=(0,Q.useState)(null),[eR,eL]=(0,Q.useState)(0),[eP,ej]=(0,Q.useState)(!1),[eB,eF]=(0,Q.useState)(!1),[eH,eU]=(0,Q.useState)(""),[ez,e$]=(0,Q.useState)(!1),[eG,eq]=(0,Q.useState)(null),eV=(0,Q.useRef)(null),[eW,eK]=(0,Q.useState)(null),eY=(0,Q.useRef)(null),eX=(0,Q.useRef)(!1),eQ=(0,Q.useRef)(async()=>{});(0,Q.useEffect)(()=>{x||k.current||(k.current=!0,w(!0),DM("").then(e=>{y(e),v(!0),w(!1)}).catch(()=>{k.current=!1,w(!1)}))},[x]);let eJ=(0,Q.useCallback)(async e=>{let t=e.split("/");if(t.length<=1)return;let n=[],r="";for(let e=0;e<t.length-1;e++)r=r?`${r}/${t[e]}`:t[e],n.push({prefix:r,children:await DM(r)});y(e=>{let t=e;for(let{prefix:e,children:r}of n)t=DO(t,e,e=>({...e,children:r,expanded:!0}));return t})},[]),eZ=(0,Q.useCallback)(async e=>{let t=await DM(e);""===e?y(e=>{let n=new Map(e.map(e=>[e.path,e]));return t.map(e=>{let t=n.get(e.path);return t&&("dir"===t.type||"app"===t.type)?{...e,expanded:t.expanded,children:t.children}:e})}):y(n=>DO(n,e,e=>({...e,children:t,expanded:!0})))},[]),e0=(0,Q.useCallback)(e=>{let t=[];for(let n of e)("dir"===n.type||"app"===n.type)&&n.expanded&&n.children&&(t.push(n.path),t.push(...e0(n.children)));return t},[]),e1=(0,Q.useCallback)(async()=>{N(!0);try{let e=e0(b),t=await DM("");for(let n of(y(t),e)){let e=await DM(n);y(t=>DO(t,n,t=>({...t,children:e,expanded:!0})))}}finally{N(!1)}},[b,e0]),e2=(0,Q.useCallback)(async()=>{if(K&&(["editor","text"].includes(DN(K.name,K.nodeType))||DS(K.name))){ej(!0);try{let e=await r$(`/api/wiki/content?path=${encodeURIComponent(K.path)}`);if(e.ok){let t=await e.json();eD(t.content),eL(Number(e.headers.get("X-Wiki-Revision")??0))}}catch{}ej(!1)}},[K]);async function e3(e){if("dir"===e.type||"app"===e.type)if(e.expanded)y(t=>DO(t,e.path,e=>({...e,expanded:!1})));else if(void 0===e.children){y(t=>DO(t,e.path,e=>({...e,loading:!0})));let t=await DM(e.path);y(n=>DO(n,e.path,e=>({...e,loading:!1,children:t,expanded:!0})))}else y(t=>DO(t,e.path,e=>({...e,expanded:!0})))}async function e5(e){if(Y({path:e.path,name:e.name,nodeType:"app"===e.type?"app":"node-app"===e.type?"node-app":"file"}),eF(!1),eq(null),eD(null),eL(0),["editor","text"].includes(DN(e.name,e.type))||DS(e.name)){ej(!0);try{let t=await r$(`/api/wiki/content?path=${encodeURIComponent(e.path)}`);if(t.ok){let e=await t.json();eD(e.content),eL(Number(t.headers.get("X-Wiki-Revision")??0))}}catch{}ej(!1)}}(0,Q.useEffect)(()=>{eY.current=K},[K]),(0,Q.useEffect)(()=>{eX.current=eB},[eB]),(0,Q.useEffect)(()=>{eQ.current=e2},[e2]),(0,Q.useEffect)(()=>{if(!t)return;let e=new Map,n=new EventSource(rz("/api/wiki/watch"));return n.onmessage=t=>{var n;let r;try{r=JSON.parse(t.data)}catch{return}let{type:i,path:o}=r,s=o.split("/");if(n=s.length>1?s.slice(0,-1).join("/"):"",e.has(n)&&clearTimeout(e.get(n)),e.set(n,setTimeout(()=>{e.delete(n),eZ(n)},300)),"change"===i&&eY.current?.path===o&&!eX.current){let t=`__file__${o}`;e.has(t)&&clearTimeout(e.get(t)),e.set(t,setTimeout(()=>{e.delete(t),eQ.current()},400))}},()=>{for(let t of(n.close(),e.values()))clearTimeout(t)}},[t,eZ]),(0,Q.useEffect)(()=>{Z(!1)},[]);let e4=(0,Q.useCallback)(e=>{let t=e.split("/").pop()??e;eJ(e),e5({path:e,name:t,type:"file"})},[eJ]);(0,Q.useEffect)(()=>{if(!f||K&&K.path===f)return;let e=f.split("/").pop()??f;e5({path:f,name:e,type:"file"})},[f]),(0,Q.useEffect)(()=>{let e=new URL(window.location.href);K?e.searchParams.set("path",K.path):e.searchParams.delete("path"),window.history.replaceState(null,"",e.toString())},[K]),(0,Q.useEffect)(()=>{if(g.current||!x)return;let e=m.current;if(!e){g.current=!0;return}g.current=!0,(async()=>{let t=e.split("/"),n=t[t.length-1],r=t.slice(0,-1).join("/"),i=(await DM(r)).find(t=>t.path===e);i&&(await eJ(e),e5({path:e,name:n,type:i.type,modifiedAt:i.modifiedAt}))})()},[x,eJ]);let e6=(0,Q.useCallback)(async e=>{if(e===o)return;try{await fetch(`/api/system/workspaces/${e}/open`,{method:"POST"})}catch{}let t=new URL(location.href);t.searchParams.set("ws",e),t.searchParams.delete("path"),history.pushState(null,"",t.toString()),Y(null),eD(null),eF(!1),y([]),v(!1),k.current=!1,ET.getState().invalidate();let n=a.find(t=>t.id===e);n&&i(n.rootDir),s(e)},[o,a]);async function e9(){if(!K)return;e$(!0),eq(null);let e=await r$("/api/wiki/content",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:K.path,content:eH,baseRevision:eR})});if(e.ok){let t=await e.json();"number"==typeof t.revision&&eL(t.revision),eD(eH),eF(!1)}else eq((await e.json()).error??"Save failed");e$(!1)}let e7=(0,Q.useCallback)(async(e,t)=>{let n=Array.from(e);if(n.length){S(!0),_(null);try{for(let e of n){let n=new FormData;n.append("file",e),n.append("dir",t);let r=await r$("/api/wiki/upload",{method:"POST",body:n});if(!r.ok){let e=await r.json();_(e.error??"Upload failed"),_d(e.error??"Upload failed");break}}await eZ(t)}catch{_("Upload failed.")}finally{S(!1),M.current&&(M.current.value="")}}},[eZ]);function e8(e){O.current=e,M.current?.click()}async function te(){let e=R.trim();if(!e||null===I)return;j(null);let t=I?`${I}/${e}`:e,n=await r$("/api/wiki/folder",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});n.ok?(D(null),L(""),await eZ(I),""!==I&&y(e=>DO(e,I,e=>({...e,expanded:!0})))):j((await n.json()).error??"Failed")}async function tt(){let e=H.trim();if(!e||null===B)return;$(null);let t=e.includes(".")?e:`${e}.md`,n=B?`${B}/${t}`:t,r=await r$("/api/wiki/new-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});r.ok?(F(null),U(""),await eZ(B),""!==B&&y(e=>DO(e,B,e=>({...e,expanded:!0}))),e5({path:n,name:t,type:"file",modifiedAt:new Date().toISOString()})):$((await r.json()).error??"Failed")}async function tn(){G&&(await r$("/api/wiki",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:G})}),(K?.path===G||K?.path.startsWith(`${G}/`))&&(Y(null),eD(null)),y(e=>(function e(t,n){return t.filter(e=>e.path!==n).map(t=>t.children?{...t,children:e(t.children,n)}:t)})(e,G)),q(null))}function tr(e,t,n){e.preventDefault(),e.stopPropagation();let r=eV.current;!r||r.path===t||t.startsWith(`${r.path}/`)||(e.dataTransfer.dropEffect="move",eK("root"===n?"":t))}async function ti(e,t){e.preventDefault(),e.stopPropagation(),eK(null);let n=eV.current;if(eV.current=null,!n||n.path===t||t.startsWith(`${n.path}/`))return;let r=t?`${t}/${n.name}`:n.name;if(r!==n.path&&(await r$("/api/wiki/move",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:n.path,to:r})})).ok){let e=n.path.includes("/")?n.path.split("/").slice(0,-1).join("/"):"";await eZ(e),t!==e&&await eZ(t),K?.path===n.path&&Y({path:r,name:n.name,nodeType:K.nodeType})}}let to=K?DN(K.name,K.nodeType):null,ts=Ek(e=>e.width),ta=null===to||"editor"===to||"text"===to||"source"===to||"notebook"===to||"fallback"===to,tl=ta?Ex[ts]:"";return(0,X.jsxs)("div",{className:"flex h-screen gap-0 overflow-hidden bg-background",children:[null===t&&(0,X.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,X.jsx)(eb,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),!1===t&&(0,X.jsx)(MD,{onSelect:e=>{let t=new URL(location.href);t.searchParams.set("ws",e),t.searchParams.delete("path"),history.replaceState(null,"",t.toString()),v(!1),k.current=!1,s(e),n(!0),h()}}),!0===t&&u&&(0,X.jsxs)("div",{className:"flex-1 flex flex-col",children:[(0,X.jsx)("div",{className:"flex items-center justify-end border-b px-3 py-2 bg-muted shrink-0",children:(0,X.jsxs)(tq,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 text-xs",onClick:()=>p(!1),children:[(0,X.jsx)(eC,{className:"h-3.5 w-3.5"})," Cancel"]})}),(0,X.jsx)(MD,{onSelect:e=>{p(!1),h(),e6(e)}})]}),!0===t&&!u&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(DE,{onOpenFile:e4}),!en&&(0,X.jsxs)(Iw,{className:"flex flex-col w-72 shrink-0 overflow-hidden rounded-none border-r border-l-0 border-t-0 border-b-0",children:[(0,X.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b bg-muted shrink-0",children:[(0,X.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[(0,X.jsx)("img",{src:"/logo.svg",alt:"Wiki Viewer",className:"h-5 w-5 shrink-0"}),(0,X.jsx)("span",{className:"truncate text-xs font-semibold tracking-tight",children:"Wiki Viewer"})]}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 shrink-0",title:"Collapse sidebar",onClick:()=>e_(!0),children:(0,X.jsx)(ex,{className:"h-3.5 w-3.5"})})]}),(0,X.jsxs)("div",{className:"flex items-center justify-between gap-1 px-3 py-1.5 border-b bg-muted/50 shrink-0",children:[(0,X.jsxs)(O5,{children:[(0,X.jsx)(O6,{asChild:!0,children:(0,X.jsxs)(tq,{size:"sm",variant:"ghost",className:"h-7 gap-1 px-2 text-xs",disabled:A,children:[A?(0,X.jsx)(eb,{className:"h-3.5 w-3.5 animate-spin"}):(0,X.jsx)(ew,{className:"h-3.5 w-3.5"}),"New",(0,X.jsx)(es,{className:"h-3 w-3 opacity-60"})]})}),(0,X.jsxs)(Ic,{align:"start",className:"w-44",children:[(0,X.jsxs)(Id,{onClick:()=>{F(""),U(""),$(null)},children:[(0,X.jsx)(ed,{className:"mr-2 h-3.5 w-3.5"}),"New file"]}),(0,X.jsxs)(Id,{onClick:()=>{D(""),L(""),j(null)},children:[(0,X.jsx)(ef,{className:"mr-2 h-3.5 w-3.5"}),"New folder"]}),(0,X.jsxs)(Id,{onClick:()=>e8(""),disabled:A,children:[(0,X.jsx)(eS,{className:"mr-2 h-3.5 w-3.5"}),"Upload"]})]})]}),(0,X.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh tree",onClick:e1,disabled:T,children:T?(0,X.jsx)(eb,{className:"h-3.5 w-3.5 animate-spin"}):(0,X.jsx)(ek,{className:"h-3.5 w-3.5"})}),(0,X.jsx)(Im,{}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"AI Agent panel",onClick:()=>Eo.getState().toggle(),children:(0,X.jsx)(ei,{className:"h-3.5 w-3.5"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Settings",onClick:()=>eO(!0),children:(0,X.jsx)(eT,{className:"h-3.5 w-3.5"})})]})]}),C&&(0,X.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 text-xs text-destructive bg-destructive/10 shrink-0",children:[(0,X.jsx)(er,{className:"h-3.5 w-3.5 shrink-0"}),C]}),""===I&&(0,X.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,X.jsx)(ep,{className:"h-4 w-4 shrink-0 text-warning"}),(0,X.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:R,onChange:e=>L(e.target.value),onKeyDown:e=>{"Enter"===e.key&&te(),"Escape"===e.key&&(D(null),L(""))}}),P&&(0,X.jsx)("span",{className:"text-xs text-destructive",children:P}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:te,children:(0,X.jsx)(eo,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{D(null),L("")},children:(0,X.jsx)(eC,{className:"h-3 w-3"})})]}),""===B&&(0,X.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,X.jsx)(eu,{className:"h-4 w-4 shrink-0 text-accent"}),(0,X.jsx)("input",{autoFocus:!0,className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"filename (default .md)",value:H,onChange:e=>U(e.target.value),onKeyDown:e=>{"Enter"===e.key&&tt(),"Escape"===e.key&&(F(null),U(""))}}),z&&(0,X.jsx)("span",{className:"text-xs text-destructive",children:z}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:tt,children:(0,X.jsx)(eo,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{F(null),U("")},children:(0,X.jsx)(eC,{className:"h-3 w-3"})})]}),(0,X.jsx)("div",{className:"border-b",children:(0,X.jsx)(Dw,{onOpenFile:e4})}),(0,X.jsx)("div",{className:t$("flex-1 overflow-auto py-1",""===eW&&"ring-2 ring-inset ring-primary bg-primary/5"),onDragOver:e=>tr(e,"","root"),onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||eK(null)},onDrop:e=>ti(e,""),children:E?(0,X.jsx)("div",{className:"flex justify-center py-6",children:(0,X.jsx)(eb,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):0===b.length?(0,X.jsxs)("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center",children:[(0,X.jsx)("div",{className:"rounded-full bg-muted p-3",children:(0,X.jsx)(eu,{className:"h-6 w-6 text-muted-foreground"})}),(0,X.jsxs)("div",{className:"space-y-1",children:[(0,X.jsx)("p",{className:"text-sm font-medium",children:"No files yet"}),(0,X.jsx)("p",{className:"text-xs text-muted-foreground",children:"Upload files or add them to the configured directory"})]}),(0,X.jsxs)(tq,{size:"sm",variant:"outline",className:"w-full gap-1.5 max-w-[180px]",onClick:()=>e8(""),disabled:A,children:[A?(0,X.jsx)(eb,{className:"h-3.5 w-3.5 animate-spin"}):(0,X.jsx)(eS,{className:"h-3.5 w-3.5"}),"Upload Files"]})]}):function e(t,n=0){return t.map(t=>(0,X.jsxs)("div",{children:[(0,X.jsxs)("div",{role:"treeitem",tabIndex:0,draggable:!0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),"dir"===t.type?e3(t):"app"===t.type?(e5(t),e3(t)):e5(t))},onDragStart:e=>{eV.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t.path)},onDragOver:e=>"dir"===t.type?tr(e,t.path,"dir"):e.preventDefault(),onDragLeave:()=>eK(null),onDrop:e=>"dir"===t.type?ti(e,t.path):e.preventDefault(),className:t$("flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer group transition-colors select-none",K?.path===t.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted",eW===t.path&&"ring-2 ring-primary bg-primary-soft",t.name.startsWith(".")&&"opacity-40"),style:{paddingLeft:`${14*n+8}px`},onClick:()=>{"dir"===t.type?e3(t):"app"===t.type?(e5(t),e3(t)):e5(t)},children:["dir"===t.type||"app"===t.type?t.loading?(0,X.jsx)(eb,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground"}):t.expanded?(0,X.jsx)(es,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):(0,X.jsx)(ea,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):(0,X.jsx)("span",{className:"w-3.5 shrink-0"}),"dir"===t.type?t.expanded?(0,X.jsx)(eh,{className:t$("h-4 w-4 shrink-0",K?.path!==t.path&&"text-warning")}):(0,X.jsx)(ep,{className:t$("h-4 w-4 shrink-0",K?.path!==t.path&&"text-warning")}):"app"===t.type?(0,X.jsx)(em,{className:t$("h-4 w-4 shrink-0",K?.path!==t.path&&"text-foreground/70")}):"node-app"===t.type?(0,X.jsx)(eN,{className:t$("h-4 w-4 shrink-0",K?.path!==t.path&&"text-emerald-500")}):"html"===DN(t.name,"file")?(0,X.jsx)(em,{className:t$("h-4 w-4 shrink-0",K?.path!==t.path&&"text-foreground/60")}):D_(t.name)?(0,X.jsx)(eg,{className:t$("h-4 w-4 shrink-0",K?.path!==t.path&&"text-sunshine-700")}):DS(t.name)?(0,X.jsx)(eu,{className:t$("h-4 w-4 shrink-0",K?.path!==t.path&&"text-foreground/70")}):(0,X.jsx)(ec,{className:t$("h-4 w-4 shrink-0",K?.path!==t.path&&"text-foreground/60")}),(0,X.jsx)("span",{className:"flex-1 truncate",children:t.name}),(0,X.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:["dir"===t.type&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"New file here (default .md)",onClick:async()=>{t.expanded||await e3(t),F(t.path),U(""),$(null)},children:(0,X.jsx)(ed,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"Upload here",onClick:()=>e8(t.path),children:(0,X.jsx)(eS,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"New subfolder",onClick:()=>{D(t.path),L(""),j(null)},children:(0,X.jsx)(ef,{className:"h-3 w-3"})})]}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"file"===t.type?"Download":"Download as zip",onClick:()=>{let e,n;return e=rz(`/api/wiki/download?path=${encodeURIComponent(t.path)}`),void((n=document.createElement("a")).href=e,n.download="file"===t.type?t.name:`${t.name}.zip`,document.body.appendChild(n),n.click(),n.remove())},children:(0,X.jsx)(el,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-destructive hover:text-destructive",title:"Delete",onClick:()=>{q(t.path),W("file"!==t.type)},children:(0,X.jsx)(eA,{className:"h-3 w-3"})})]})]}),I===t.path&&"dir"===t.type&&(0,X.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(n+1)*14+8}px`},children:[(0,X.jsx)("span",{className:"w-3.5 shrink-0"}),(0,X.jsx)(ep,{className:"h-4 w-4 shrink-0 text-warning"}),(0,X.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:R,onChange:e=>L(e.target.value),onKeyDown:e=>{"Enter"===e.key&&te(),"Escape"===e.key&&(D(null),L(""))}}),P&&(0,X.jsx)("span",{className:"text-xs text-destructive",children:P}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:te,children:(0,X.jsx)(eo,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{D(null),L("")},children:(0,X.jsx)(eC,{className:"h-3 w-3"})})]}),B===t.path&&"dir"===t.type&&(0,X.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(n+1)*14+8}px`},children:[(0,X.jsx)("span",{className:"w-3.5 shrink-0"}),(0,X.jsx)(eu,{className:"h-4 w-4 shrink-0 text-accent"}),(0,X.jsx)("input",{autoFocus:!0,className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"filename (default .md)",value:H,onChange:e=>U(e.target.value),onKeyDown:e=>{"Enter"===e.key&&tt(),"Escape"===e.key&&(F(null),U(""))}}),z&&(0,X.jsx)("span",{className:"text-xs text-destructive",children:z}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:tt,children:(0,X.jsx)(eo,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{F(null),U("")},children:(0,X.jsx)(eC,{className:"h-3 w-3"})})]}),("dir"===t.type||"app"===t.type)&&t.expanded&&t.children&&t.children.length>0&&e(t.children,n+1),("dir"===t.type||"app"===t.type)&&t.expanded&&t.children?.length===0&&(0,X.jsx)("div",{className:"text-xs text-muted-foreground/50 py-0.5",style:{paddingLeft:`${(n+1)*14+8+14+6+16+6}px`},children:"Empty"})]},t.path))}(b)}),(0,X.jsx)("div",{className:"border-t px-2 py-2 bg-muted shrink-0",children:(0,X.jsxs)(O5,{children:[(0,X.jsx)(O6,{asChild:!0,children:(0,X.jsxs)(tq,{size:"sm",variant:"ghost",className:"w-full h-auto justify-between gap-2 px-2 py-1.5 text-left",title:r??"",children:[(0,X.jsxs)("span",{className:"flex flex-col min-w-0",children:[(0,X.jsx)("span",{className:"truncate text-xs font-medium",children:a.find(e=>e.id===o)?.name??"Workspace"}),(0,X.jsx)("span",{className:"truncate text-[10px] text-muted-foreground font-mono",children:r??""})]}),(0,X.jsx)(es,{className:"h-3.5 w-3.5 shrink-0 opacity-60"})]})}),(0,X.jsxs)(Ic,{align:"start",className:"w-60",children:[a.map(e=>(0,X.jsxs)(Id,{onClick:()=>void e6(e.id),className:t$("gap-2",e.id===o&&"font-medium"),children:[e.id===o?(0,X.jsx)(eo,{className:"h-3.5 w-3.5 shrink-0"}):(0,X.jsx)("span",{className:"w-3.5 shrink-0"}),(0,X.jsxs)("span",{className:"flex flex-col min-w-0",children:[(0,X.jsx)("span",{className:"truncate",children:e.name}),(0,X.jsx)("span",{className:"truncate text-[10px] text-muted-foreground font-mono",children:e.rootDir})]})]},e.id)),c&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Iu,{}),(0,X.jsxs)(Id,{onClick:()=>p(!0),children:[(0,X.jsx)(ef,{className:"mr-2 h-3.5 w-3.5"}),"Add workspace…"]})]})]})]})})]}),(0,X.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 relative",children:[en&&(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"absolute left-0 top-1/2 -translate-y-1/2 z-10 h-7 w-7 p-0 rounded-full bg-background/50 backdrop-blur-xl backdrop-saturate-150 border border-white/[0.08] text-foreground/60 hover:text-foreground/90 hover:bg-background/70 shadow-[0_0_12px_rgba(0,0,0,0.15)] [transform:translate(-50%,-50%)_translateZ(0)]",title:"Show sidebar",onClick:()=>e_(!1),children:(0,X.jsx)(ev,{className:"h-3.5 w-3.5"})}),K?"node-app"===to?(0,X.jsx)(MC,{path:K.path,title:K.name}):"app"===to||"html"===to?(e="html"===to?`/api/assets/${K.path}`:void 0,J?(0,X.jsx)(MT,{path:K.path,title:K.name,src:e,fullscreen:!0,onExit:()=>Z(!1)}):(0,X.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,X.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0",children:[(0,X.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,X.jsx)(em,{className:"h-4 w-4 shrink-0 text-accent"}),(0,X.jsx)("span",{className:"text-sm font-normal truncate",title:K.path,children:K.path})]}),(0,X.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:["html"===to&&!eB&&null!==eI&&(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Edit source",onClick:()=>{eF(!0),eU(eI),eq(null)},children:(0,X.jsx)(eE,{className:"h-3.5 w-3.5"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh",onClick:()=>et(e=>e+1),children:(0,X.jsx)(ek,{className:"h-3.5 w-3.5"})}),(0,X.jsxs)(tq,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 text-xs",onClick:()=>Z(!0),children:[(0,X.jsx)(ey,{className:"h-3.5 w-3.5"}),"Open fullscreen"]}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{Y(null),eF(!1)},children:(0,X.jsx)(eC,{className:"h-3.5 w-3.5"})})]})]}),eB&&"html"===to?(0,X.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:[(0,X.jsx)("textarea",{value:eH,onChange:e=>eU(e.target.value),spellCheck:!1,className:"flex-1 w-full min-h-0 resize-none bg-background text-foreground px-4 py-3 font-mono text-[13px] leading-relaxed outline-none border-0"}),(0,X.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[eG&&(0,X.jsx)("span",{className:"text-xs text-destructive mr-auto",children:eG}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",onClick:()=>{eF(!1),eq(null)},children:"Cancel"}),(0,X.jsxs)(tq,{size:"sm",className:"gap-1",onClick:e9,disabled:ez,children:[ez&&(0,X.jsx)(eb,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]}):(0,X.jsx)(MT,{path:K.path,title:K.name,src:e},ee)]})):(0,X.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,X.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0",children:[(0,X.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[D_(K.name)?(0,X.jsx)(eg,{className:"h-4 w-4 shrink-0 text-sunshine-700"}):DS(K.name)?(0,X.jsx)(eu,{className:"h-4 w-4 shrink-0 text-accent"}):(0,X.jsx)(ec,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),(0,X.jsx)("span",{className:"text-sm font-normal truncate",title:K.path,children:K.path})]}),(0,X.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[DS(K.name)&&!eB&&null!==eI&&(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{eF(!0),eU(eI),eq(null),DC(K.name)&&Eg.getState().loadPage(K.path)},children:(0,X.jsx)(eE,{className:"h-3.5 w-3.5"})}),DS(K.name)&&!eB&&null!==eI&&(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh",onClick:e2,disabled:eP,children:eP?(0,X.jsx)(eb,{className:"h-3.5 w-3.5 animate-spin"}):(0,X.jsx)(ek,{className:"h-3.5 w-3.5"})}),ta&&(0,X.jsx)(Dk,{}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{Y(null),eD(null),eF(!1)},children:(0,X.jsx)(eC,{className:"h-3.5 w-3.5"})})]})]}),eB?(0,X.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:DC(K.name)?(0,X.jsx)(_y,{}):(0,X.jsx)("textarea",{value:eH,onChange:e=>eU(e.target.value),spellCheck:!1,className:"flex-1 w-full min-h-0 resize-none bg-background text-foreground px-4 py-3 font-mono text-[13px] leading-relaxed outline-none border-0"})}):(0,X.jsx)("div",{className:"flex-1 overflow-auto p-4 min-h-0",children:(0,X.jsx)("div",{className:t$("mx-auto w-full",tl),children:eP?(0,X.jsx)("div",{className:"flex justify-center py-8",children:(0,X.jsx)(eb,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):"csv"===to?(0,X.jsx)(rW,{path:K.path,title:K.name}):"pdf"===to?(0,X.jsx)(Mx,{path:K.path,title:K.name}):"mermaid"===to?(0,X.jsx)(_S,{path:K.path,title:K.name}):"notebook"===to?(0,X.jsx)(Mf,{path:K.path,title:K.name}):"image"===to?(0,X.jsx)(_v,{path:K.path,title:K.name}):"media"===to?(0,X.jsx)(_E,{path:K.path,title:K.name,type:["mp4","webm","mov","m4v"].includes(DT(K.name))?"video":"audio"}):"docx"===to?(0,X.jsx)(Mg,{path:K.path,title:K.name}):"xlsx"===to?(0,X.jsx)(My,{path:K.path,title:K.name}):"pptx"===to?(0,X.jsx)(Mb,{path:K.path,title:K.name}):"source"===to?(0,X.jsx)(Mk,{path:K.path,title:K.name}):"fallback"===to?(0,X.jsx)(_x,{path:K.path,title:K.name}):null!==eI?["md","markdown"].includes(DT(K.name))?(()=>{let{data:e,body:t}=function(e){let t=IC.exec(e);if(!t)return{data:{},body:e};let n=t[1],r=e.slice(t[0].length),i=n.split(/\r?\n/).find(e=>""!==e.trim())??"";if(/^\s*(#{1,6}\s|<|>|-\s|\*\s|\d+\.\s)/.test(i))return{data:{},body:e};let o={},s=n.split(/\r?\n/),a=0;for(;a<s.length;){let e=s[a];if(!e||/^\s*#/.test(e)){a+=1;continue}let t=/^([A-Za-z_][\w-]*)\s*:\s*(.*)$/.exec(e);if(!t){a+=1;continue}let n=t[1],r=t[2];if(""===r.trim()){let e=[],t=a+1;for(;t<s.length&&/^\s+-\s+/.test(s[t]);){let n=/^\s+-\s+(.*)$/.exec(s[t]);n&&e.push(I_(n[1])),t+=1}if(e.length>0){o[n]=e,a=t;continue}o[n]="",a+=1;continue}o[n]=I_(r),a+=1}return 0===Object.keys(o).length?{data:{},body:e}:{data:o,body:r}}(eI);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(IA,{data:e}),(0,X.jsx)(IS,{markdown:t,pagePath:K.path,onNavigate:(e,t)=>{e5({path:e,name:e.split("/").pop()??e,type:"file"}),t&&setTimeout(()=>{document.getElementById(t)?.scrollIntoView({behavior:"smooth"})},200)}})]})})():(0,X.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words leading-relaxed",children:eI}):DS(K.name)?(0,X.jsx)("p",{className:"text-sm text-muted-foreground",children:"Could not load file."}):(0,X.jsx)("p",{className:"text-sm text-muted-foreground",children:"Preview not available for this file type."})})}),eB&&(0,X.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[eG&&(0,X.jsx)("span",{className:"text-xs text-destructive mr-auto",children:eG}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",onClick:()=>{eF(!1),eq(null)},children:"Cancel"}),(0,X.jsxs)(tq,{size:"sm",className:"gap-1",onClick:e9,disabled:ez,children:[ez&&(0,X.jsx)(eb,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]}):(0,X.jsx)("div",{className:"flex-1 flex flex-col items-center justify-center",children:(0,X.jsxs)("div",{className:"flex flex-col items-center gap-2 text-center px-4",children:[(0,X.jsx)(eu,{className:"h-8 w-8 text-muted-foreground"}),(0,X.jsx)("p",{className:"text-sm text-muted-foreground",children:"Select a file to view or edit"})]})})]}),(0,X.jsx)(IE,{open:eM,onOpenChange:eO}),(0,X.jsx)(Iz,{currentPath:K?.path}),(0,X.jsx)("input",{ref:M,type:"file",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&e7(e.target.files,O.current)}}),(0,X.jsx)(rP,{open:!!G,onOpenChange:e=>{e||q(null)},title:V?"Delete folder?":"Delete file?",description:V?`"${G?.split("/").pop()}" and all its contents will be permanently deleted.`:`"${G?.split("/").pop()}" will be permanently removed.`,onConfirm:tn})]})]},o??"none")}],952683)}]);
129
+ ${t}/api/agent/files/${e??"<path/to/file.md>"}`;await navigator.clipboard.writeText(r),n(!0),setTimeout(()=>n(!1),1500)},[e])}}(e??null),[l,c]=(0,Q.useState)(""),d=(0,Q.useRef)(null),u=window.location.origin,p=(0,Q.useCallback)(()=>IH,[]),h=(0,Q.useCallback)(()=>l.replace(/\$WIKI_URL/g,u),[l,u]),f=(0,Q.useCallback)(()=>`npx wiki-viewer-mcp register --url ${u} --id ai:myagent --name "My Agent"`,[u]),m=(0,Q.useCallback)(()=>JSON.stringify({servers:{"wiki-viewer":{command:"npx",args:["wiki-viewer-mcp"],env:{WIKI_VIEWER_URL:u,WIKI_VIEWER_TOKEN:"<token from register>",WIKI_VIEWER_AGENT_ID:"ai:myagent"}}}},null,2),[u]),g=IU(p),b=IU(h),y=IU(f),x=IU(m);return((0,Q.useEffect)(()=>{if(t)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&n()}},[t,n]),(0,Q.useEffect)(()=>{t&&d.current?.focus()},[t]),(0,Q.useEffect)(()=>{if(!t)return;o();let e=setInterval(()=>void o(),1e4);return()=>clearInterval(e)},[t,o]),(0,Q.useEffect)(()=>{t&&fetch("/api/agents/install").then(e=>e.json()).then(e=>{e.bootstrapPrompt&&c(e.bootstrapPrompt)}).catch(()=>void 0)},[t]),t)?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)("div",{className:"fixed inset-0 z-40 bg-black/20 backdrop-blur-[1px]",onClick:n,"aria-hidden":!0}),(0,X.jsxs)("aside",{ref:d,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":"AI Agent Panel",className:"fixed right-0 top-0 bottom-0 z-50 flex w-80 flex-col border-l border-border bg-background shadow-xl outline-none",children:[(0,X.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-4 py-3 shrink-0",children:[(0,X.jsxs)("div",{className:"flex items-center gap-2",children:[(0,X.jsx)(ei,{className:"h-4 w-4 text-muted-foreground"}),(0,X.jsx)("span",{className:"text-sm font-semibold",children:"AI Agent"})]}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:n,title:"Close panel (Esc)",children:(0,X.jsx)(eC,{className:"h-3.5 w-3.5"})})]}),(0,X.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-5 px-4 py-4",children:[(0,X.jsxs)("section",{className:"rounded-md border border-border bg-muted/30 p-3",children:[(0,X.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Work with this wiki using AI"}),(0,X.jsxs)("p",{className:"mt-1 text-xs leading-relaxed text-muted-foreground",children:["Connect Claude, Cursor, ChatGPT, and more. Pick by what you want — each option gives a copy-paste setup. You approve every assistant in ",(0,X.jsx)("span",{className:"font-medium text-foreground/80",children:"Agents"})," below before it gets access."]})]}),(0,X.jsxs)("section",{className:"space-y-3",children:[(0,X.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,X.jsx)("p",{className:"text-xs font-semibold text-foreground",children:"Co-write docs with you"}),(0,X.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Edits arrive as suggestions with comments you accept or revert. No MCP needed."}),(0,X.jsx)(tq,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void b.copy(),disabled:!l,children:b.copied?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(eo,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_w,{className:"h-3.5 w-3.5"})," Paste into any chatbot"]})}),(0,X.jsxs)("p",{className:"text-[10px] text-muted-foreground/50 pt-1",children:["Or install once so it sticks"," ",(0,X.jsx)("span",{className:"text-muted-foreground/40",children:"· Claude, OpenCode"}),":"]}),(0,X.jsxs)("div",{className:"flex items-center gap-2",children:[(0,X.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:IH}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void g.copy(),children:g.copied?(0,X.jsx)(eo,{className:"h-3.5 w-3.5 text-green-500"}):(0,X.jsx)(_w,{className:"h-3.5 w-3.5"})})]})]}),(0,X.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,X.jsxs)("p",{className:"text-xs font-semibold text-foreground",children:["Edit files directly"," ",(0,X.jsx)("span",{className:"font-normal text-muted-foreground/60",children:"· Claude Code, Cursor, Codex"})]}),(0,X.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Native read / search / edit tools over MCP. Run to request access:"}),(0,X.jsxs)("div",{className:"flex items-center gap-2",children:[(0,X.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:f()}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void y.copy(),children:y.copied?(0,X.jsx)(eo,{className:"h-3.5 w-3.5 text-green-500"}):(0,X.jsx)(_w,{className:"h-3.5 w-3.5"})})]}),(0,X.jsxs)("p",{className:"text-[10px] text-muted-foreground/50",children:["Approve in ",(0,X.jsx)("span",{className:"font-medium text-foreground/70",children:"Agents"}),", then add to your tool:"]}),(0,X.jsx)(tq,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void x.copy(),children:x.copied?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(eo,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_w,{className:"h-3.5 w-3.5"})," Copy config (mcp.json)"]})})]}),(0,X.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[(0,X.jsx)("span",{className:"text-[10px] text-muted-foreground/50",children:"For developers:"}),(0,X.jsxs)("button",{type:"button",onClick:()=>void a(),className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[s?(0,X.jsx)(eo,{className:"h-3 w-3 text-green-500"}):(0,X.jsx)(_w,{className:"h-3 w-3"})," curl example"]}),(0,X.jsxs)("a",{href:"/api/agents/skill",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[(0,X.jsx)(kl,{className:"h-3 w-3"})," skill"]}),(0,X.jsxs)("a",{href:"/api/agents/install",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[(0,X.jsx)(kl,{className:"h-3 w-3"})," install JSON"]})]})]}),(0,X.jsx)(IB,{}),(0,X.jsxs)("section",{className:"space-y-2",children:[(0,X.jsxs)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:["Active Connections"," ",(0,X.jsx)("span",{className:"normal-case font-normal text-muted-foreground/50",children:"(last 5 min)"})]}),(0,X.jsx)("div",{className:"rounded-md border border-border bg-muted/40 p-3",children:0===i.length?(0,X.jsxs)("p",{className:"text-xs text-muted-foreground/60 flex items-center gap-1.5",children:[(0,X.jsx)(IM,{className:"h-3.5 w-3.5"}),"No recent activity"]}):(0,X.jsx)("ul",{className:"space-y-1.5",children:i.map(e=>(0,X.jsxs)("li",{className:"flex items-center justify-between text-xs",children:[(0,X.jsx)("span",{className:"font-mono text-foreground/80 truncate",children:e.by}),(0,X.jsxs)("span",{className:"text-muted-foreground shrink-0",children:[e.opCount," op",1!==e.opCount?"s":""]})]},e.by))})})]}),(0,X.jsxs)("section",{className:"space-y-2",children:[(0,X.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Recent Activity"}),(0,X.jsx)("div",{className:"rounded-md border border-border bg-muted/40 px-3 py-1 max-h-72 overflow-y-auto",children:0===r.length?(0,X.jsx)("p",{className:"text-xs text-muted-foreground/60 py-2",children:"No events recorded"}):r.map(e=>(0,X.jsx)(IF,{event:e},`${e.path}-${e.id}`))})]}),(0,X.jsx)("section",{children:(0,X.jsx)("a",{href:"/docs/agent-collab-plan.md",target:"_blank",rel:"noreferrer",className:"text-xs text-primary underline hover:no-underline",children:"Agent collaboration docs →"})})]})]})]}):null}var I$=/[\\\/_+.#"@\[\(\{&]/,IG=/[\\\/_+.#"@\[\(\{&]/g,Iq=/[\s-]/,IV=/[\s-]/g;function IW(e){return e.toLowerCase().replace(IV," ")}var IK='[cmdk-group=""]',IY='[cmdk-group-items=""]',IX='[cmdk-item=""]',IQ=`${IX}:not([aria-disabled="true"])`,IJ="cmdk-item-select",IZ="data-value",I0=(e,t,n)=>{var r;return r=e,function e(t,n,r,i,o,s,a){if(s===n.length)return o===t.length?1:.99;var l=`${o},${s}`;if(void 0!==a[l])return a[l];for(var c,d,u,p,h=i.charAt(s),f=r.indexOf(h,o),m=0;f>=0;)(c=e(t,n,r,i,f+1,s+1,a))>m&&(f===o?c*=1:I$.test(t.charAt(f-1))?(c*=.8,(u=t.slice(o,f-1).match(IG))&&o>0&&(c*=Math.pow(.999,u.length))):Iq.test(t.charAt(f-1))?(c*=.9,(p=t.slice(o,f-1).match(IV))&&o>0&&(c*=Math.pow(.999,p.length))):(c*=.17,o>0&&(c*=Math.pow(.999,f-o))),t.charAt(f)!==n.charAt(s)&&(c*=.9999)),(c<.1&&r.charAt(f-1)===i.charAt(s+1)||i.charAt(s+1)===i.charAt(s)&&r.charAt(f-1)!==i.charAt(s))&&.1*(d=e(t,n,r,i,f+1,s+2,a))>c&&(c=.1*d),c>m&&(m=c),f=r.indexOf(h,f+1);return a[l]=m,m}(r=n&&n.length>0?`${r+" "+n.join(" ")}`:r,t,IW(r),IW(t),0,0,{})},I1=Q.createContext(void 0),I2=Q.createContext(void 0),I3=Q.createContext(void 0),I5=Q.forwardRef((e,t)=>{let n=Di(()=>{var t,n;return{search:"",value:null!=(n=null!=(t=e.value)?t:e.defaultValue)?n:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=Di(()=>new Set),i=Di(()=>new Map),o=Di(()=>new Map),s=Di(()=>new Set),a=Dn(e),{label:l,children:c,value:d,onValueChange:u,filter:p,shouldFilter:h,loop:f,disablePointerSelection:m=!1,vimBindings:g=!0,...b}=e,y=tQ(),x=tQ(),v=tQ(),E=Q.useRef(null),w=Da();Dr(()=>{if(void 0!==d){let e=d.trim();n.current.value=e,k.emit()}},[d]),Dr(()=>{w(6,_)},[]);let k=Q.useMemo(()=>({subscribe:e=>(s.current.add(e),()=>s.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,o,s,l;if(!Object.is(n.current[e],t)){if(n.current[e]=t,"search"===e)C(),A(),w(1,S);else if("value"===e){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let e=document.getElementById(v);e?e.focus():null==(i=document.getElementById(y))||i.focus()}if(w(7,()=>{var e;n.current.selectedItemId=null==(e=M())?void 0:e.id,k.emit()}),r||w(5,_),(null==(o=a.current)?void 0:o.value)!==void 0){null==(l=(s=a.current).onValueChange)||l.call(s,null!=t?t:"");return}}k.emit()}},emit:()=>{s.current.forEach(e=>e())}}),[]),T=Q.useMemo(()=>({value:(e,t,r)=>{var i;t!==(null==(i=o.current.get(e))?void 0:i.value)&&(o.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,N(t,r)),w(2,()=>{A(),k.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),w(3,()=>{C(),A(),n.current.value||S(),k.emit()}),()=>{o.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=M();w(4,()=>{C(),(null==t?void 0:t.getAttribute("id"))===e&&S(),k.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{o.current.delete(e),i.current.delete(e)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:y,inputId:v,labelId:x,listInnerRef:E}),[]);function N(e,t){var r,i;let o=null!=(i=null==(r=a.current)?void 0:r.filter)?i:I0;return e?o(e,n.current.search,t):0}function A(){if(!n.current.search||!1===a.current.shouldFilter)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),o=0;r.forEach(t=>{o=Math.max(e.get(t),o)}),t.push([n,o])});let r=E.current;O().sort((t,n)=>{var r,i;let o=t.getAttribute("id"),s=n.getAttribute("id");return(null!=(r=e.get(s))?r:0)-(null!=(i=e.get(o))?i:0)}).forEach(e=>{let t=e.closest(IY);t?t.appendChild(e.parentElement===t?e:e.closest(`${IY} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${IY} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{var t;let n=null==(t=E.current)?void 0:t.querySelector(`${IK}[${IZ}="${encodeURIComponent(e[0])}"]`);null==n||n.parentElement.appendChild(n)})}function S(){let e=O().find(e=>"true"!==e.getAttribute("aria-disabled")),t=null==e?void 0:e.getAttribute(IZ);k.setState("value",t||void 0)}function C(){var e,t,s,l;if(!n.current.search||!1===a.current.shouldFilter){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let c=0;for(let i of r.current){let r=N(null!=(t=null==(e=o.current.get(i))?void 0:e.value)?t:"",null!=(l=null==(s=o.current.get(i))?void 0:s.keywords)?l:[]);n.current.filtered.items.set(i,r),r>0&&c++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=c}function _(){var e,t,n;let r=M();r&&((null==(e=r.parentElement)?void 0:e.firstChild)===r&&(null==(n=null==(t=r.closest(IK))?void 0:t.querySelector('[cmdk-group-heading=""]'))||n.scrollIntoView({block:"nearest"})),r.scrollIntoView({block:"nearest"}))}function M(){var e;return null==(e=E.current)?void 0:e.querySelector(`${IX}[aria-selected="true"]`)}function O(){var e;return Array.from((null==(e=E.current)?void 0:e.querySelectorAll(IQ))||[])}function I(e){let t=O()[e];t&&k.setState("value",t.getAttribute(IZ))}function D(e){var t;let n=M(),r=O(),i=r.findIndex(e=>e===n),o=r[i+e];null!=(t=a.current)&&t.loop&&(o=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),o&&k.setState("value",o.getAttribute(IZ))}function R(e){let t=M(),n=null==t?void 0:t.closest(IK),r;for(;n&&!r;)r=null==(n=e>0?function(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}(n,IK):function(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}(n,IK))?void 0:n.querySelector(IQ);r?k.setState("value",r.getAttribute(IZ)):D(e)}let L=()=>I(O().length-1),P=e=>{e.preventDefault(),e.metaKey?L():e.altKey?R(1):D(1)},j=e=>{e.preventDefault(),e.metaKey?I(0):e.altKey?R(-1):D(-1)};return Q.createElement(kA.div,{ref:t,tabIndex:-1,...b,"cmdk-root":"",onKeyDown:e=>{var t;null==(t=b.onKeyDown)||t.call(b,e);let n=e.nativeEvent.isComposing||229===e.keyCode;if(!(e.defaultPrevented||n))switch(e.key){case"n":case"j":g&&e.ctrlKey&&P(e);break;case"ArrowDown":P(e);break;case"p":case"k":g&&e.ctrlKey&&j(e);break;case"ArrowUp":j(e);break;case"Home":e.preventDefault(),I(0);break;case"End":e.preventDefault(),L();break;case"Enter":{e.preventDefault();let t=M();if(t){let e=new Event(IJ);t.dispatchEvent(e)}}}}},Q.createElement("label",{"cmdk-label":"",htmlFor:T.inputId,id:T.labelId,style:Dc},l),Dl(e,e=>Q.createElement(I2.Provider,{value:k},Q.createElement(I1.Provider,{value:T},e))))}),I4=Q.forwardRef((e,t)=>{var n,r;let i=tQ(),o=Q.useRef(null),s=Q.useContext(I3),a=Q.useContext(I1),l=Dn(e),c=null!=(r=null==(n=l.current)?void 0:n.forceMount)?r:null==s?void 0:s.forceMount;Dr(()=>{if(!c)return a.item(i,null==s?void 0:s.id)},[c]);let d=Ds(i,o,[e.value,e.children,o],e.keywords),u=Q.useContext(I2),p=Do(e=>e.value&&e.value===d.current),h=Do(e=>!!c||!1===a.filter()||!e.search||e.filtered.items.get(i)>0);function f(){var e,t;m(),null==(t=(e=l.current).onSelect)||t.call(e,d.current)}function m(){u.setState("value",d.current,!0)}if(Q.useEffect(()=>{let t=o.current;if(!(!t||e.disabled))return t.addEventListener(IJ,f),()=>t.removeEventListener(IJ,f)},[h,e.onSelect,e.disabled]),!h)return null;let{disabled:g,value:b,onSelect:y,forceMount:x,keywords:v,...E}=e;return Q.createElement(kA.div,{ref:eM(o,t),...E,id:i,"cmdk-item":"",role:"option","aria-disabled":!!g,"aria-selected":!!p,"data-disabled":!!g,"data-selected":!!p,onPointerMove:g||a.getDisablePointerSelection()?void 0:m,onClick:g?void 0:f},e.children)}),I6=Q.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...o}=e,s=tQ(),a=Q.useRef(null),l=Q.useRef(null),c=tQ(),d=Q.useContext(I1),u=Do(e=>!!i||!1===d.filter()||!e.search||e.filtered.groups.has(s));Dr(()=>d.group(s),[]),Ds(s,a,[e.value,e.heading,l]);let p=Q.useMemo(()=>({id:s,forceMount:i}),[i]);return Q.createElement(kA.div,{ref:eM(a,t),...o,"cmdk-group":"",role:"presentation",hidden:!u||void 0},n&&Q.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),Dl(e,e=>Q.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},Q.createElement(I3.Provider,{value:p},e))))}),I9=Q.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=Q.useRef(null),o=Do(e=>!e.search);return n||o?Q.createElement(kA.div,{ref:eM(i,t),...r,"cmdk-separator":"",role:"separator"}):null}),I7=Q.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=null!=e.value,o=Q.useContext(I2),s=Do(e=>e.search),a=Do(e=>e.selectedItemId),l=Q.useContext(I1);return Q.useEffect(()=>{null!=e.value&&o.setState("search",e.value)},[e.value]),Q.createElement(kA.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:i?e.value:s,onChange:e=>{i||o.setState("search",e.target.value),null==n||n(e.target.value)}})}),I8=Q.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...i}=e,o=Q.useRef(null),s=Q.useRef(null),a=Do(e=>e.selectedItemId),l=Q.useContext(I1);return Q.useEffect(()=>{if(s.current&&o.current){let e=s.current,t=o.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty("--cmdk-list-height",n.toFixed(1)+"px")})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),Q.createElement(kA.div,{ref:eM(o,t),...i,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},Dl(e,e=>Q.createElement("div",{ref:eM(s,l.listInnerRef),"cmdk-list-sizer":""},e)))}),De=Q.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:o,container:s,...a}=e;return Q.createElement(rr,{open:n,onOpenChange:r},Q.createElement(rl,{container:s},Q.createElement(rd,{"cmdk-overlay":"",className:i}),Q.createElement(rf,{"aria-label":e.label,"cmdk-dialog":"",className:o},Q.createElement(I5,{ref:t,...a}))))}),Dt=Object.assign(I5,{List:I8,Item:I4,Input:I7,Group:I6,Separator:I9,Dialog:De,Empty:Q.forwardRef((e,t)=>Do(e=>0===e.filtered.count)?Q.createElement(kA.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Loading:Q.forwardRef((e,t)=>{let{progress:n,children:r,label:i="Loading...",...o}=e;return Q.createElement(kA.div,{ref:t,...o,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},Dl(e,e=>Q.createElement("div",{"aria-hidden":!0},e)))})});function Dn(e){let t=Q.useRef(e);return Dr(()=>{t.current=e}),t}var Dr="u"<typeof window?Q.useEffect:Q.useLayoutEffect;function Di(e){let t=Q.useRef();return void 0===t.current&&(t.current=e()),t}function Do(e){let t=Q.useContext(I2),n=()=>e(t.snapshot());return Q.useSyncExternalStore(t.subscribe,n,n)}function Ds(e,t,n,r=[]){let i=Q.useRef(),o=Q.useContext(I1);return Dr(()=>{var s;let a=(()=>{var e;for(let t of n){if("string"==typeof t)return t.trim();if("object"==typeof t&&"current"in t)return t.current?null==(e=t.current.textContent)?void 0:e.trim():i.current}})(),l=r.map(e=>e.trim());o.value(e,a,l),null==(s=t.current)||s.setAttribute(IZ,a),i.current=a}),i}var Da=()=>{let[e,t]=Q.useState(),n=Di(()=>new Map);return Dr(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function Dl({asChild:e,children:t},n){let r;return e&&Q.isValidElement(t)?Q.cloneElement("function"==typeof(r=t.type)?r(t.props):"render"in r?r.render(t.props):t,{ref:t.ref},n(t.props.children)):n(t)}var Dc={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};let Dd=en("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),Du=Q.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Dt,{ref:n,className:t$("flex h-full w-full flex-col overflow-hidden rounded-sm bg-popover text-popover-foreground",e),...t}));function Dp({children:e,shouldFilter:t,...n}){return(0,X.jsx)(rr,{...n,children:(0,X.jsxs)(rO,{className:"overflow-hidden p-0 shadow-golden max-w-lg",children:[(0,X.jsx)(rR,{className:"sr-only",children:"Search"}),(0,X.jsx)(Du,{shouldFilter:t,className:"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-normal [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",children:e})]})})}Du.displayName=Dt.displayName;let Dh=Q.forwardRef(({className:e,...t},n)=>(0,X.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,X.jsx)(Dd,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,X.jsx)(Dt.Input,{ref:n,className:t$("flex h-11 w-full rounded-sm bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));Dh.displayName=Dt.Input.displayName;let Df=Q.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Dt.List,{ref:n,className:t$("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));Df.displayName=Dt.List.displayName;let Dm=Q.forwardRef((e,t)=>(0,X.jsx)(Dt.Empty,{ref:t,className:"py-6 text-center text-sm text-muted-foreground",...e}));Dm.displayName=Dt.Empty.displayName;let Dg=Q.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Dt.Group,{ref:n,className:t$("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-normal [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));Dg.displayName=Dt.Group.displayName,Q.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Dt.Separator,{ref:n,className:t$("-mx-1 h-px bg-border",e),...t})).displayName=Dt.Separator.displayName;let Db=Q.forwardRef(({className:e,...t},n)=>(0,X.jsx)(Dt.Item,{ref:n,className:t$("relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",e),...t}));Db.displayName=Dt.Item.displayName;let Dy=null,Dx=Ei(e=>({query:"",results:[],loading:!1,truncated:!1,open:!1,setQuery:t=>e({query:t}),setOpen:t=>e({open:t}),clear:()=>{Dy?.abort(),e({query:"",results:[],loading:!1,truncated:!1})},search:async t=>{Dy?.abort();let n=new AbortController;if(Dy=n,!t.trim())return void e({results:[],loading:!1,truncated:!1});e({loading:!0});try{let r=await r$("/api/wiki/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,limit:30}),signal:n.signal});if(!r.ok)return void e({results:[],loading:!1,truncated:!1});let i=await r.json();if(n.signal.aborted)return;e({results:i.matches??[],truncated:!!i.truncated,loading:!1})}catch(t){"AbortError"!==t.name&&e({loading:!1})}}}));function Dv({html:e}){let t=function(e){let t,n=[],r=/<mark>([\s\S]*?)<\/mark>/g,i=0;for(;null!==(t=r.exec(e));)t.index>i&&n.push({text:e.slice(i,t.index),mark:!1}),n.push({text:t[1]??"",mark:!0}),i=t.index+t[0].length;return i<e.length&&n.push({text:e.slice(i),mark:!1}),n}(e);return(0,X.jsx)(X.Fragment,{children:t.map((e,t)=>e.mark?(0,X.jsx)("mark",{className:"bg-yellow-200 dark:bg-yellow-700 rounded-[2px] px-[1px]",children:e.text},t):(0,X.jsx)("span",{children:e.text},t))})}function DE({onOpenFile:e}){let t=Dx(e=>e.open),n=Dx(e=>e.setOpen),r=Dx(e=>e.query),i=Dx(e=>e.setQuery),o=Dx(e=>e.results),s=Dx(e=>e.loading),a=Dx(e=>e.truncated),l=Dx(e=>e.search);return(0,Q.useEffect)(()=>{function e(e){(e.metaKey||e.ctrlKey)&&"k"===e.key.toLowerCase()&&(e.preventDefault(),n(!t))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,n]),(0,Q.useEffect)(()=>{if(!t)return;let e=setTimeout(()=>{l(r)},120);return()=>clearTimeout(e)},[r,t,l]),(0,X.jsxs)(Dp,{open:t,onOpenChange:n,shouldFilter:!1,children:[(0,X.jsx)(Dh,{placeholder:"Search files…",value:r,onValueChange:i}),(0,X.jsxs)(Df,{children:[s&&(0,X.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"Searching…"}),!s&&""!==r.trim()&&0===o.length&&(0,X.jsx)(Dm,{children:"No matches."}),o.length>0&&(0,X.jsx)(Dg,{heading:a?"Top results (refine query for more)":"Results",children:o.map(t=>(0,X.jsx)(Db,{value:t.path,onSelect:()=>{e(t.path),n(!1)},children:(0,X.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,X.jsx)("span",{className:"truncate font-mono text-xs",children:t.path}),t.snippet&&(0,X.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:(0,X.jsx)(Dv,{html:t.snippet})})]})},t.path))})]})]})}function Dw({onOpenFile:e}){let t=Dx(e=>e.query),n=Dx(e=>e.setQuery),r=Dx(e=>e.results),i=Dx(e=>e.loading),o=Dx(e=>e.search),s=Dx(e=>e.clear),[a,l]=(0,Q.useState)(0),c=(0,Q.useRef)(null);function d(t){let n=r[t];n&&(e(n.path),s())}return(0,Q.useEffect)(()=>{l(0)},[r]),(0,Q.useEffect)(()=>{let e=c.current?.querySelector(`[data-idx="${a}"]`);e?.scrollIntoView({block:"nearest"})},[a]),(0,X.jsxs)("div",{className:"flex flex-col gap-1 px-2 py-1.5",children:[(0,X.jsxs)("div",{className:"relative",children:[(0,X.jsx)(Dd,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 opacity-50"}),(0,X.jsx)("input",{type:"text",className:"w-full rounded-sm border bg-transparent py-1 pl-7 pr-2 text-xs outline-none focus:ring-1 focus:ring-ring",placeholder:"Search… (⌘K)",value:t,onChange:e=>{n(e.target.value),o(e.target.value)},onKeyDown:e=>{"Escape"===e.key?s():0!==r.length&&("ArrowDown"===e.key?(e.preventDefault(),l(e=>(e+1)%r.length)):"ArrowUp"===e.key?(e.preventDefault(),l(e=>(e-1+r.length)%r.length)):"Enter"===e.key&&(e.preventDefault(),d(a)))}})]}),""!==t.trim()&&(0,X.jsxs)("div",{ref:c,className:"max-h-64 overflow-y-auto rounded-sm border bg-popover",children:[i&&(0,X.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"Searching…"}),!i&&0===r.length&&(0,X.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"No matches"}),r.map((e,t)=>(0,X.jsxs)("button",{type:"button","data-idx":t,onClick:()=>d(t),onMouseEnter:()=>l(t),className:`block w-full px-2 py-1 text-left ${t===a?"bg-accent":"hover:bg-accent"}`,children:[(0,X.jsx)("div",{className:"truncate font-mono text-xs",children:e.path}),e.snippet&&(0,X.jsx)("div",{className:"truncate text-[10px] text-muted-foreground",children:(0,X.jsx)(Dv,{html:e.snippet})})]},e.path))]})]})}function Dk({className:e}){let t=Ek(e=>e.width),n=Ek(e=>e.setWidth);return(0,X.jsxs)(O5,{children:[(0,X.jsx)(O6,{asChild:!0,children:(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:`h-7 w-7 p-0 ${e??""}`,title:`Content width: ${EE[t]}`,children:(0,X.jsx)(w4,{className:"h-3.5 w-3.5"})})}),(0,X.jsx)(Ic,{align:"end",className:"w-36",children:Ew.map(e=>(0,X.jsxs)(Id,{onClick:()=>n(e),className:"flex items-center justify-between text-xs",children:[EE[e],e===t&&(0,X.jsx)(eo,{className:"h-3.5 w-3.5"})]},e))})]})}function DT(e){return e.split(".").pop()?.toLowerCase()??""}function DN(e,t){if("node-app"===t)return"node-app";if("app"===t)return"app";if("dir"===t)return"fallback";let n=DT(e);return n?["md","markdown"].includes(n)?"editor":"txt"===n?"text":["csv","tsv"].includes(n)?"csv":"pdf"===n?"pdf":["mmd","mermaid"].includes(n)?"mermaid":"ipynb"===n?"notebook":["png","jpg","jpeg","gif","webp","svg","avif","ico","bmp"].includes(n)?"image":["mp4","webm","mov","m4v","mp3","wav","ogg","m4a","aac"].includes(n)?"media":"docx"===n?"docx":["xlsx","xlsm"].includes(n)?"xlsx":"pptx"===n?"pptx":"html"===n?"html":["py","js","ts","tsx","jsx","go","rs","java","c","cpp","h","sh","bash","zsh","rb","php","swift","kt","lua","sql","yaml","yml","toml","json","xml","css","scss"].includes(n)?"source":"fallback":"fallback"}let DA=new Set(["txt","md","markdown","json","yaml","yml","toml","csv","tsv","xml","html","css","js","ts","tsx","jsx","sh","bash","zsh","rb","py","go","rs","java","c","cpp","h","php","swift","kt","lua","sql","scss","mmd","mermaid","ini","env","log","conf"]);function DS(e){let t=DN(e,"file");return"editor"===t||"text"===t||DA.has(DT(e))}function DC(e){return["md","markdown"].includes(DT(e))}function D_(e){return"image"===DN(e,"file")}async function DM(e){let t=await r$(`/api/wiki?dir=${encodeURIComponent(e)}`);return t.ok?(await t.json()).entries.map(t=>({name:t.name,path:e?`${e}/${t.name}`:t.name,type:t.type,size:t.size,modifiedAt:t.modifiedAt,expanded:!1})):[]}function DO(e,t,n){return e.map(e=>e.path===t?n(e):e.children?{...e,children:DO(e.children,t,n)}:e)}e.s(["default",0,function(){let e;ET(e=>e.loadedAt),(0,Q.useEffect)(()=>{ET.getState().load()},[]);let[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(()=>rU()),[a,l]=(0,Q.useState)([]),[c,d]=(0,Q.useState)(!1),[u,p]=(0,Q.useState)(!1),[h,f]=(0,Q.useState)(null),m=(0,Q.useCallback)(async()=>{try{let e=await fetch("/api/system/workspaces");if(!e.ok)throw Error("Failed");let t=await e.json();if(l(t.workspaces),d(t.isAdmin),t.workspaces.length>0){n(!0);let e=new URLSearchParams(window.location.search).get("ws"),r=e?t.workspaces.find(t=>t.id===e):null,o=r??[...t.workspaces].sort((e,t)=>(t.lastOpenedAt??t.createdAt).localeCompare(e.lastOpenedAt??e.createdAt))[0];if(s(o.id),i(o.rootDir),!r){let e=new URL(location.href);e.searchParams.set("ws",o.id),history.replaceState(null,"",e.toString())}}else n(!1)}catch{n(!1)}},[]);(0,Q.useEffect)(()=>{m()},[m]);let g=Eg(e=>e.currentPath),b=(0,Q.useRef)(new URLSearchParams(window.location.search).get("path")),y=(0,Q.useRef)(!1),[x,v]=(0,Q.useState)([]),[E,w]=(0,Q.useState)(!1),[k,T]=(0,Q.useState)(!1),N=(0,Q.useRef)(!1),[A,S]=(0,Q.useState)(!1),[C,_]=(0,Q.useState)(!1),[M,O]=(0,Q.useState)(null),I=(0,Q.useRef)(null),D=(0,Q.useRef)(""),[R,L]=(0,Q.useState)(null),[P,j]=(0,Q.useState)(""),[B,F]=(0,Q.useState)(null),[H,U]=(0,Q.useState)(null),[z,$]=(0,Q.useState)(""),[G,q]=(0,Q.useState)(null),[V,W]=(0,Q.useState)(null),[K,Y]=(0,Q.useState)(!1),[J,Z]=(0,Q.useState)(null),[ee,et]=(0,Q.useState)(!1),[en,e_]=(0,Q.useState)(0),[eM,eO]=(0,Q.useState)(!1),[eI,eD]=(0,Q.useState)(!1),[eR,eL]=(0,Q.useState)(null),[eP,ej]=(0,Q.useState)(0),[eB,eF]=(0,Q.useState)(!1),[eH,eU]=(0,Q.useState)(!1),[ez,e$]=(0,Q.useState)(""),[eG,eq]=(0,Q.useState)(!1),[eV,eW]=(0,Q.useState)(null),eK=(0,Q.useRef)(null),[eY,eX]=(0,Q.useState)(null),eQ=(0,Q.useRef)(null),eJ=(0,Q.useRef)(!1),eZ=(0,Q.useRef)(async()=>{});(0,Q.useEffect)(()=>{E||N.current||(N.current=!0,T(!0),DM("").then(e=>{v(e),w(!0),T(!1)}).catch(()=>{N.current=!1,T(!1)}))},[E]);let e0=(0,Q.useCallback)(async e=>{let t=e.split("/");if(t.length<=1)return;let n=[],r="";for(let e=0;e<t.length-1;e++)r=r?`${r}/${t[e]}`:t[e],n.push({prefix:r,children:await DM(r)});v(e=>{let t=e;for(let{prefix:e,children:r}of n)t=DO(t,e,e=>({...e,children:r,expanded:!0}));return t})},[]),e1=(0,Q.useCallback)(async e=>{let t=await DM(e);""===e?v(e=>{let n=new Map(e.map(e=>[e.path,e]));return t.map(e=>{let t=n.get(e.path);return t&&("dir"===t.type||"app"===t.type)?{...e,expanded:t.expanded,children:t.children}:e})}):v(n=>DO(n,e,e=>({...e,children:t,expanded:!0})))},[]),e2=(0,Q.useCallback)(e=>{let t=[];for(let n of e)("dir"===n.type||"app"===n.type)&&n.expanded&&n.children&&(t.push(n.path),t.push(...e2(n.children)));return t},[]),e3=(0,Q.useCallback)(async()=>{S(!0);try{let e=e2(x),t=await DM("");for(let n of(v(t),e)){let e=await DM(n);v(t=>DO(t,n,t=>({...t,children:e,expanded:!0})))}}finally{S(!1)}},[x,e2]),e5=(0,Q.useCallback)(async()=>{if(J&&(["editor","text"].includes(DN(J.name,J.nodeType))||DS(J.name))){eF(!0);try{let e=await r$(`/api/wiki/content?path=${encodeURIComponent(J.path)}`);if(e.ok){let t=await e.json();eL(t.content),ej(Number(e.headers.get("X-Wiki-Revision")??0))}}catch{}eF(!1)}},[J]);async function e4(e){if("dir"===e.type||"app"===e.type)if(e.expanded)v(t=>DO(t,e.path,e=>({...e,expanded:!1})));else if(void 0===e.children){v(t=>DO(t,e.path,e=>({...e,loading:!0})));let t=await DM(e.path);v(n=>DO(n,e.path,e=>({...e,loading:!1,children:t,expanded:!0})))}else v(t=>DO(t,e.path,e=>({...e,expanded:!0})))}async function e6(e){if(Z({path:e.path,name:e.name,nodeType:"app"===e.type?"app":"node-app"===e.type?"node-app":"file"}),eU(!1),eW(null),eL(null),ej(0),["editor","text"].includes(DN(e.name,e.type))||DS(e.name)){eF(!0);try{let t=await r$(`/api/wiki/content?path=${encodeURIComponent(e.path)}`);if(t.ok){let e=await t.json();eL(e.content),ej(Number(t.headers.get("X-Wiki-Revision")??0))}}catch{}eF(!1)}}(0,Q.useEffect)(()=>{eQ.current=J},[J]),(0,Q.useEffect)(()=>{eJ.current=eH},[eH]),(0,Q.useEffect)(()=>{eZ.current=e5},[e5]),(0,Q.useEffect)(()=>{if(!t)return;let e=new Map,n=new EventSource(rz("/api/wiki/watch"));return n.onmessage=t=>{var n;let r;try{r=JSON.parse(t.data)}catch{return}let{type:i,path:o}=r,s=o.split("/");if(n=s.length>1?s.slice(0,-1).join("/"):"",e.has(n)&&clearTimeout(e.get(n)),e.set(n,setTimeout(()=>{e.delete(n),e1(n)},300)),"change"===i&&eQ.current?.path===o&&!eJ.current){let t=`__file__${o}`;e.has(t)&&clearTimeout(e.get(t)),e.set(t,setTimeout(()=>{e.delete(t),eZ.current()},400))}},()=>{for(let t of(n.close(),e.values()))clearTimeout(t)}},[t,e1]),(0,Q.useEffect)(()=>{et(!1)},[]);let e9=(0,Q.useCallback)(e=>{let t=e.split("/").pop()??e;e0(e),e6({path:e,name:t,type:"file"})},[e0]);(0,Q.useEffect)(()=>{if(!g||J&&J.path===g)return;let e=g.split("/").pop()??g;e6({path:g,name:e,type:"file"})},[g]),(0,Q.useEffect)(()=>{let e=new URL(window.location.href);J?e.searchParams.set("path",J.path):e.searchParams.delete("path"),window.history.replaceState(null,"",e.toString())},[J]),(0,Q.useEffect)(()=>{if(y.current||!E)return;let e=b.current;if(!e){y.current=!0;return}y.current=!0,(async()=>{let t=e.split("/"),n=t[t.length-1],r=t.slice(0,-1).join("/"),i=(await DM(r)).find(t=>t.path===e);i&&(await e0(e),e6({path:e,name:n,type:i.type,modifiedAt:i.modifiedAt}))})()},[E,e0]);let e7=(0,Q.useCallback)(async e=>{if(e===o)return;try{await fetch(`/api/system/workspaces/${e}/open`,{method:"POST"})}catch{}let t=new URL(location.href);t.searchParams.set("ws",e),t.searchParams.delete("path"),history.pushState(null,"",t.toString()),Z(null),eL(null),eU(!1),v([]),w(!1),N.current=!1,ET.getState().invalidate();let n=a.find(t=>t.id===e);n&&i(n.rootDir),s(e)},[o,a]),e8=(0,Q.useCallback)(async()=>{if(h)try{if(!(await fetch(`/api/system/workspaces/${h}`,{method:"DELETE"})).ok)throw Error("Failed");if(h===o){let e=a.filter(e=>e.id!==h);if(e.length>0){let t=[...e].sort((e,t)=>(t.lastOpenedAt??t.createdAt).localeCompare(e.lastOpenedAt??e.createdAt))[0];await e7(t.id)}else n(!1)}await m()}catch{}finally{f(null)}},[h,o,a,e7,m]);async function te(){if(!J)return;eq(!0),eW(null);let e=await r$("/api/wiki/content",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:J.path,content:ez,baseRevision:eP})});if(e.ok){let t=await e.json();"number"==typeof t.revision&&ej(t.revision),eL(ez),eU(!1)}else eW((await e.json()).error??"Save failed");eq(!1)}let tt=(0,Q.useCallback)(async(e,t)=>{let n=Array.from(e);if(n.length){_(!0),O(null);try{for(let e of n){let n=new FormData;n.append("file",e),n.append("dir",t);let r=await r$("/api/wiki/upload",{method:"POST",body:n});if(!r.ok){let e=await r.json();O(e.error??"Upload failed"),_d(e.error??"Upload failed");break}}await e1(t)}catch{O("Upload failed.")}finally{_(!1),I.current&&(I.current.value="")}}},[e1]);function tn(e){D.current=e,I.current?.click()}async function tr(){let e=P.trim();if(!e||null===R)return;F(null);let t=R?`${R}/${e}`:e,n=await r$("/api/wiki/folder",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});n.ok?(L(null),j(""),await e1(R),""!==R&&v(e=>DO(e,R,e=>({...e,expanded:!0})))):F((await n.json()).error??"Failed")}async function ti(){let e=z.trim();if(!e||null===H)return;q(null);let t=e.includes(".")?e:`${e}.md`,n=H?`${H}/${t}`:t,r=await r$("/api/wiki/new-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});r.ok?(U(null),$(""),await e1(H),""!==H&&v(e=>DO(e,H,e=>({...e,expanded:!0}))),e6({path:n,name:t,type:"file",modifiedAt:new Date().toISOString()})):q((await r.json()).error??"Failed")}async function to(){V&&(await r$("/api/wiki",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:V})}),(J?.path===V||J?.path.startsWith(`${V}/`))&&(Z(null),eL(null)),v(e=>(function e(t,n){return t.filter(e=>e.path!==n).map(t=>t.children?{...t,children:e(t.children,n)}:t)})(e,V)),W(null))}function ts(e,t,n){e.preventDefault(),e.stopPropagation();let r=eK.current;!r||r.path===t||t.startsWith(`${r.path}/`)||(e.dataTransfer.dropEffect="move",eX("root"===n?"":t))}async function ta(e,t){e.preventDefault(),e.stopPropagation(),eX(null);let n=eK.current;if(eK.current=null,!n||n.path===t||t.startsWith(`${n.path}/`))return;let r=t?`${t}/${n.name}`:n.name;if(r!==n.path&&(await r$("/api/wiki/move",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:n.path,to:r})})).ok){let e=n.path.includes("/")?n.path.split("/").slice(0,-1).join("/"):"";await e1(e),t!==e&&await e1(t),J?.path===n.path&&Z({path:r,name:n.name,nodeType:J.nodeType})}}let tl=J?DN(J.name,J.nodeType):null,tc=Ek(e=>e.width),td=null===tl||"editor"===tl||"text"===tl||"source"===tl||"notebook"===tl||"fallback"===tl,tu=td?Ex[tc]:"";return(0,X.jsxs)("div",{className:"flex h-screen gap-0 overflow-hidden bg-background",children:[null===t&&(0,X.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,X.jsx)(eb,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),!1===t&&(0,X.jsx)(MD,{onSelect:e=>{let t=new URL(location.href);t.searchParams.set("ws",e),t.searchParams.delete("path"),history.replaceState(null,"",t.toString()),w(!1),N.current=!1,s(e),n(!0),m()}}),!0===t&&u&&(0,X.jsxs)("div",{className:"flex-1 flex flex-col",children:[(0,X.jsx)("div",{className:"flex items-center justify-end border-b px-3 py-2 bg-muted shrink-0",children:(0,X.jsxs)(tq,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 text-xs",onClick:()=>p(!1),children:[(0,X.jsx)(eC,{className:"h-3.5 w-3.5"})," Cancel"]})}),(0,X.jsx)(MD,{onSelect:e=>{p(!1),m(),e7(e)}})]}),!0===t&&!u&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(DE,{onOpenFile:e9}),!eM&&(0,X.jsxs)(Iw,{className:"flex flex-col w-72 shrink-0 overflow-hidden rounded-none border-r border-l-0 border-t-0 border-b-0",children:[(0,X.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b bg-muted shrink-0",children:[(0,X.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[(0,X.jsx)("img",{src:"/logo.svg",alt:"Wiki Viewer",className:"h-5 w-5 shrink-0"}),(0,X.jsx)("span",{className:"truncate text-xs font-semibold tracking-tight",children:"Wiki Viewer"})]}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 shrink-0",title:"Collapse sidebar",onClick:()=>eO(!0),children:(0,X.jsx)(ex,{className:"h-3.5 w-3.5"})})]}),(0,X.jsxs)("div",{className:"flex items-center justify-between gap-1 px-3 py-1.5 border-b bg-muted/50 shrink-0",children:[(0,X.jsxs)(O5,{children:[(0,X.jsx)(O6,{asChild:!0,children:(0,X.jsxs)(tq,{size:"sm",variant:"ghost",className:"h-7 gap-1 px-2 text-xs",disabled:C,children:[C?(0,X.jsx)(eb,{className:"h-3.5 w-3.5 animate-spin"}):(0,X.jsx)(ew,{className:"h-3.5 w-3.5"}),"New",(0,X.jsx)(es,{className:"h-3 w-3 opacity-60"})]})}),(0,X.jsxs)(Ic,{align:"start",className:"w-44",children:[(0,X.jsxs)(Id,{onClick:()=>{U(""),$(""),q(null)},children:[(0,X.jsx)(ed,{className:"mr-2 h-3.5 w-3.5"}),"New file"]}),(0,X.jsxs)(Id,{onClick:()=>{L(""),j(""),F(null)},children:[(0,X.jsx)(ef,{className:"mr-2 h-3.5 w-3.5"}),"New folder"]}),(0,X.jsxs)(Id,{onClick:()=>tn(""),disabled:C,children:[(0,X.jsx)(eS,{className:"mr-2 h-3.5 w-3.5"}),"Upload"]})]})]}),(0,X.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh tree",onClick:e3,disabled:A,children:A?(0,X.jsx)(eb,{className:"h-3.5 w-3.5 animate-spin"}):(0,X.jsx)(ek,{className:"h-3.5 w-3.5"})}),(0,X.jsx)(Im,{}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"AI Agent panel",onClick:()=>Eo.getState().toggle(),children:(0,X.jsx)(ei,{className:"h-3.5 w-3.5"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Settings",onClick:()=>eD(!0),children:(0,X.jsx)(eT,{className:"h-3.5 w-3.5"})})]})]}),M&&(0,X.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 text-xs text-destructive bg-destructive/10 shrink-0",children:[(0,X.jsx)(er,{className:"h-3.5 w-3.5 shrink-0"}),M]}),""===R&&(0,X.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,X.jsx)(ep,{className:"h-4 w-4 shrink-0 text-warning"}),(0,X.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:P,onChange:e=>j(e.target.value),onKeyDown:e=>{"Enter"===e.key&&tr(),"Escape"===e.key&&(L(null),j(""))}}),B&&(0,X.jsx)("span",{className:"text-xs text-destructive",children:B}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:tr,children:(0,X.jsx)(eo,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{L(null),j("")},children:(0,X.jsx)(eC,{className:"h-3 w-3"})})]}),""===H&&(0,X.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,X.jsx)(eu,{className:"h-4 w-4 shrink-0 text-accent"}),(0,X.jsx)("input",{autoFocus:!0,className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"filename (default .md)",value:z,onChange:e=>$(e.target.value),onKeyDown:e=>{"Enter"===e.key&&ti(),"Escape"===e.key&&(U(null),$(""))}}),G&&(0,X.jsx)("span",{className:"text-xs text-destructive",children:G}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:ti,children:(0,X.jsx)(eo,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{U(null),$("")},children:(0,X.jsx)(eC,{className:"h-3 w-3"})})]}),(0,X.jsx)("div",{className:"border-b",children:(0,X.jsx)(Dw,{onOpenFile:e9})}),(0,X.jsx)("div",{className:t$("flex-1 overflow-auto py-1",""===eY&&"ring-2 ring-inset ring-primary bg-primary/5"),onDragOver:e=>ts(e,"","root"),onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||eX(null)},onDrop:e=>ta(e,""),children:k?(0,X.jsx)("div",{className:"flex justify-center py-6",children:(0,X.jsx)(eb,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):0===x.length?(0,X.jsxs)("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center",children:[(0,X.jsx)("div",{className:"rounded-full bg-muted p-3",children:(0,X.jsx)(eu,{className:"h-6 w-6 text-muted-foreground"})}),(0,X.jsxs)("div",{className:"space-y-1",children:[(0,X.jsx)("p",{className:"text-sm font-medium",children:"No files yet"}),(0,X.jsx)("p",{className:"text-xs text-muted-foreground",children:"Upload files or add them to the configured directory"})]}),(0,X.jsxs)(tq,{size:"sm",variant:"outline",className:"w-full gap-1.5 max-w-[180px]",onClick:()=>tn(""),disabled:C,children:[C?(0,X.jsx)(eb,{className:"h-3.5 w-3.5 animate-spin"}):(0,X.jsx)(eS,{className:"h-3.5 w-3.5"}),"Upload Files"]})]}):function e(t,n=0){return t.map(t=>(0,X.jsxs)("div",{children:[(0,X.jsxs)("div",{role:"treeitem",tabIndex:0,draggable:!0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),"dir"===t.type?e4(t):"app"===t.type?(e6(t),e4(t)):e6(t))},onDragStart:e=>{eK.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t.path)},onDragOver:e=>"dir"===t.type?ts(e,t.path,"dir"):e.preventDefault(),onDragLeave:()=>eX(null),onDrop:e=>"dir"===t.type?ta(e,t.path):e.preventDefault(),className:t$("flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer group transition-colors select-none",J?.path===t.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted",eY===t.path&&"ring-2 ring-primary bg-primary-soft",t.name.startsWith(".")&&"opacity-40"),style:{paddingLeft:`${14*n+8}px`},onClick:()=>{"dir"===t.type?e4(t):"app"===t.type?(e6(t),e4(t)):e6(t)},children:["dir"===t.type||"app"===t.type?t.loading?(0,X.jsx)(eb,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground"}):t.expanded?(0,X.jsx)(es,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):(0,X.jsx)(ea,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):(0,X.jsx)("span",{className:"w-3.5 shrink-0"}),"dir"===t.type?t.expanded?(0,X.jsx)(eh,{className:t$("h-4 w-4 shrink-0",J?.path!==t.path&&"text-warning")}):(0,X.jsx)(ep,{className:t$("h-4 w-4 shrink-0",J?.path!==t.path&&"text-warning")}):"app"===t.type?(0,X.jsx)(em,{className:t$("h-4 w-4 shrink-0",J?.path!==t.path&&"text-foreground/70")}):"node-app"===t.type?(0,X.jsx)(eN,{className:t$("h-4 w-4 shrink-0",J?.path!==t.path&&"text-emerald-500")}):"html"===DN(t.name,"file")?(0,X.jsx)(em,{className:t$("h-4 w-4 shrink-0",J?.path!==t.path&&"text-foreground/60")}):D_(t.name)?(0,X.jsx)(eg,{className:t$("h-4 w-4 shrink-0",J?.path!==t.path&&"text-sunshine-700")}):DS(t.name)?(0,X.jsx)(eu,{className:t$("h-4 w-4 shrink-0",J?.path!==t.path&&"text-foreground/70")}):(0,X.jsx)(ec,{className:t$("h-4 w-4 shrink-0",J?.path!==t.path&&"text-foreground/60")}),(0,X.jsx)("span",{className:"flex-1 truncate",children:t.name}),(0,X.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:["dir"===t.type&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"New file here (default .md)",onClick:async()=>{t.expanded||await e4(t),U(t.path),$(""),q(null)},children:(0,X.jsx)(ed,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"Upload here",onClick:()=>tn(t.path),children:(0,X.jsx)(eS,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"New subfolder",onClick:()=>{L(t.path),j(""),F(null)},children:(0,X.jsx)(ef,{className:"h-3 w-3"})})]}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"file"===t.type?"Download":"Download as zip",onClick:()=>{let e,n;return e=rz(`/api/wiki/download?path=${encodeURIComponent(t.path)}`),void((n=document.createElement("a")).href=e,n.download="file"===t.type?t.name:`${t.name}.zip`,document.body.appendChild(n),n.click(),n.remove())},children:(0,X.jsx)(el,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-destructive hover:text-destructive",title:"Delete",onClick:()=>{W(t.path),Y("file"!==t.type)},children:(0,X.jsx)(eA,{className:"h-3 w-3"})})]})]}),R===t.path&&"dir"===t.type&&(0,X.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(n+1)*14+8}px`},children:[(0,X.jsx)("span",{className:"w-3.5 shrink-0"}),(0,X.jsx)(ep,{className:"h-4 w-4 shrink-0 text-warning"}),(0,X.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:P,onChange:e=>j(e.target.value),onKeyDown:e=>{"Enter"===e.key&&tr(),"Escape"===e.key&&(L(null),j(""))}}),B&&(0,X.jsx)("span",{className:"text-xs text-destructive",children:B}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:tr,children:(0,X.jsx)(eo,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{L(null),j("")},children:(0,X.jsx)(eC,{className:"h-3 w-3"})})]}),H===t.path&&"dir"===t.type&&(0,X.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(n+1)*14+8}px`},children:[(0,X.jsx)("span",{className:"w-3.5 shrink-0"}),(0,X.jsx)(eu,{className:"h-4 w-4 shrink-0 text-accent"}),(0,X.jsx)("input",{autoFocus:!0,className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"filename (default .md)",value:z,onChange:e=>$(e.target.value),onKeyDown:e=>{"Enter"===e.key&&ti(),"Escape"===e.key&&(U(null),$(""))}}),G&&(0,X.jsx)("span",{className:"text-xs text-destructive",children:G}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:ti,children:(0,X.jsx)(eo,{className:"h-3 w-3"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{U(null),$("")},children:(0,X.jsx)(eC,{className:"h-3 w-3"})})]}),("dir"===t.type||"app"===t.type)&&t.expanded&&t.children&&t.children.length>0&&e(t.children,n+1),("dir"===t.type||"app"===t.type)&&t.expanded&&t.children?.length===0&&(0,X.jsx)("div",{className:"text-xs text-muted-foreground/50 py-0.5",style:{paddingLeft:`${(n+1)*14+8+14+6+16+6}px`},children:"Empty"})]},t.path))}(x)}),(0,X.jsx)("div",{className:"border-t px-2 py-2 bg-muted shrink-0",children:(0,X.jsxs)(O5,{children:[(0,X.jsx)(O6,{asChild:!0,children:(0,X.jsxs)(tq,{size:"sm",variant:"ghost",className:"w-full h-auto justify-between gap-2 px-2 py-1.5 text-left",title:r??"",children:[(0,X.jsxs)("span",{className:"flex flex-col min-w-0",children:[(0,X.jsx)("span",{className:"truncate text-xs font-medium",children:a.find(e=>e.id===o)?.name??"Workspace"}),(0,X.jsx)("span",{className:"truncate text-[10px] text-muted-foreground font-mono",children:r??""})]}),(0,X.jsx)(es,{className:"h-3.5 w-3.5 shrink-0 opacity-60"})]})}),(0,X.jsxs)(Ic,{align:"start",className:"w-60",children:[a.map(e=>(0,X.jsxs)(Id,{onClick:()=>void e7(e.id),className:t$("gap-2",e.id===o&&"font-medium"),children:[e.id===o?(0,X.jsx)(eo,{className:"h-3.5 w-3.5 shrink-0"}):(0,X.jsx)("span",{className:"w-3.5 shrink-0"}),(0,X.jsxs)("span",{className:"flex flex-col min-w-0 flex-1",children:[(0,X.jsx)("span",{className:"truncate",children:e.name}),(0,X.jsx)("span",{className:"truncate text-[10px] text-muted-foreground font-mono",children:e.rootDir})]}),c&&(0,X.jsx)("button",{className:"ml-auto shrink-0 rounded p-0.5 text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors",title:"Delete workspace (does not delete files)",onClick:t=>{t.stopPropagation(),f(e.id)},children:(0,X.jsx)(eA,{className:"h-3.5 w-3.5"})})]},e.id)),c&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Iu,{}),(0,X.jsxs)(Id,{onClick:()=>p(!0),children:[(0,X.jsx)(ef,{className:"mr-2 h-3.5 w-3.5"}),"Add workspace…"]})]})]})]})})]}),(0,X.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 relative",children:[eM&&(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"absolute left-0 top-1/2 -translate-y-1/2 z-10 h-7 w-7 p-0 rounded-full bg-background/50 backdrop-blur-xl backdrop-saturate-150 border border-white/[0.08] text-foreground/60 hover:text-foreground/90 hover:bg-background/70 shadow-[0_0_12px_rgba(0,0,0,0.15)] [transform:translate(-50%,-50%)_translateZ(0)]",title:"Show sidebar",onClick:()=>eO(!1),children:(0,X.jsx)(ev,{className:"h-3.5 w-3.5"})}),J?"node-app"===tl?(0,X.jsx)(MC,{path:J.path,title:J.name}):"app"===tl||"html"===tl?(e="html"===tl?`/api/assets/${J.path}`:void 0,ee?(0,X.jsx)(MT,{path:J.path,title:J.name,src:e,fullscreen:!0,onExit:()=>et(!1)}):(0,X.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,X.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0",children:[(0,X.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,X.jsx)(em,{className:"h-4 w-4 shrink-0 text-accent"}),(0,X.jsx)("span",{className:"text-sm font-normal truncate",title:J.path,children:J.path})]}),(0,X.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:["html"===tl&&!eH&&null!==eR&&(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Edit source",onClick:()=>{eU(!0),e$(eR),eW(null)},children:(0,X.jsx)(eE,{className:"h-3.5 w-3.5"})}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh",onClick:()=>e_(e=>e+1),children:(0,X.jsx)(ek,{className:"h-3.5 w-3.5"})}),(0,X.jsxs)(tq,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 text-xs",onClick:()=>et(!0),children:[(0,X.jsx)(ey,{className:"h-3.5 w-3.5"}),"Open fullscreen"]}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{Z(null),eU(!1)},children:(0,X.jsx)(eC,{className:"h-3.5 w-3.5"})})]})]}),eH&&"html"===tl?(0,X.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:[(0,X.jsx)("textarea",{value:ez,onChange:e=>e$(e.target.value),spellCheck:!1,className:"flex-1 w-full min-h-0 resize-none bg-background text-foreground px-4 py-3 font-mono text-[13px] leading-relaxed outline-none border-0"}),(0,X.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[eV&&(0,X.jsx)("span",{className:"text-xs text-destructive mr-auto",children:eV}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",onClick:()=>{eU(!1),eW(null)},children:"Cancel"}),(0,X.jsxs)(tq,{size:"sm",className:"gap-1",onClick:te,disabled:eG,children:[eG&&(0,X.jsx)(eb,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]}):(0,X.jsx)(MT,{path:J.path,title:J.name,src:e},en)]})):(0,X.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,X.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0",children:[(0,X.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[D_(J.name)?(0,X.jsx)(eg,{className:"h-4 w-4 shrink-0 text-sunshine-700"}):DS(J.name)?(0,X.jsx)(eu,{className:"h-4 w-4 shrink-0 text-accent"}):(0,X.jsx)(ec,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),(0,X.jsx)("span",{className:"text-sm font-normal truncate",title:J.path,children:J.path})]}),(0,X.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[DS(J.name)&&!eH&&null!==eR&&(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{eU(!0),e$(eR),eW(null),DC(J.name)&&Eg.getState().loadPage(J.path)},children:(0,X.jsx)(eE,{className:"h-3.5 w-3.5"})}),DS(J.name)&&!eH&&null!==eR&&(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh",onClick:e5,disabled:eB,children:eB?(0,X.jsx)(eb,{className:"h-3.5 w-3.5 animate-spin"}):(0,X.jsx)(ek,{className:"h-3.5 w-3.5"})}),td&&(0,X.jsx)(Dk,{}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{Z(null),eL(null),eU(!1)},children:(0,X.jsx)(eC,{className:"h-3.5 w-3.5"})})]})]}),eH?(0,X.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:DC(J.name)?(0,X.jsx)(_y,{}):(0,X.jsx)("textarea",{value:ez,onChange:e=>e$(e.target.value),spellCheck:!1,className:"flex-1 w-full min-h-0 resize-none bg-background text-foreground px-4 py-3 font-mono text-[13px] leading-relaxed outline-none border-0"})}):(0,X.jsx)("div",{className:"flex-1 overflow-auto p-4 min-h-0",children:(0,X.jsx)("div",{className:t$("mx-auto w-full",tu),children:eB?(0,X.jsx)("div",{className:"flex justify-center py-8",children:(0,X.jsx)(eb,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):"csv"===tl?(0,X.jsx)(rW,{path:J.path,title:J.name}):"pdf"===tl?(0,X.jsx)(Mx,{path:J.path,title:J.name}):"mermaid"===tl?(0,X.jsx)(_S,{path:J.path,title:J.name}):"notebook"===tl?(0,X.jsx)(Mf,{path:J.path,title:J.name}):"image"===tl?(0,X.jsx)(_v,{path:J.path,title:J.name}):"media"===tl?(0,X.jsx)(_E,{path:J.path,title:J.name,type:["mp4","webm","mov","m4v"].includes(DT(J.name))?"video":"audio"}):"docx"===tl?(0,X.jsx)(Mg,{path:J.path,title:J.name}):"xlsx"===tl?(0,X.jsx)(My,{path:J.path,title:J.name}):"pptx"===tl?(0,X.jsx)(Mb,{path:J.path,title:J.name}):"source"===tl?(0,X.jsx)(Mk,{path:J.path,title:J.name}):"fallback"===tl?(0,X.jsx)(_x,{path:J.path,title:J.name}):null!==eR?["md","markdown"].includes(DT(J.name))?(()=>{let{data:e,body:t}=function(e){let t=IC.exec(e);if(!t)return{data:{},body:e};let n=t[1],r=e.slice(t[0].length),i=n.split(/\r?\n/).find(e=>""!==e.trim())??"";if(/^\s*(#{1,6}\s|<|>|-\s|\*\s|\d+\.\s)/.test(i))return{data:{},body:e};let o={},s=n.split(/\r?\n/),a=0;for(;a<s.length;){let e=s[a];if(!e||/^\s*#/.test(e)){a+=1;continue}let t=/^([A-Za-z_][\w-]*)\s*:\s*(.*)$/.exec(e);if(!t){a+=1;continue}let n=t[1],r=t[2];if(""===r.trim()){let e=[],t=a+1;for(;t<s.length&&/^\s+-\s+/.test(s[t]);){let n=/^\s+-\s+(.*)$/.exec(s[t]);n&&e.push(I_(n[1])),t+=1}if(e.length>0){o[n]=e,a=t;continue}o[n]="",a+=1;continue}o[n]=I_(r),a+=1}return 0===Object.keys(o).length?{data:{},body:e}:{data:o,body:r}}(eR);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(IA,{data:e}),(0,X.jsx)(IS,{markdown:t,pagePath:J.path,onNavigate:(e,t)=>{e6({path:e,name:e.split("/").pop()??e,type:"file"}),t&&setTimeout(()=>{document.getElementById(t)?.scrollIntoView({behavior:"smooth"})},200)}})]})})():(0,X.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words leading-relaxed",children:eR}):DS(J.name)?(0,X.jsx)("p",{className:"text-sm text-muted-foreground",children:"Could not load file."}):(0,X.jsx)("p",{className:"text-sm text-muted-foreground",children:"Preview not available for this file type."})})}),eH&&(0,X.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[eV&&(0,X.jsx)("span",{className:"text-xs text-destructive mr-auto",children:eV}),(0,X.jsx)(tq,{size:"sm",variant:"ghost",onClick:()=>{eU(!1),eW(null)},children:"Cancel"}),(0,X.jsxs)(tq,{size:"sm",className:"gap-1",onClick:te,disabled:eG,children:[eG&&(0,X.jsx)(eb,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]}):(0,X.jsx)("div",{className:"flex-1 flex flex-col items-center justify-center",children:(0,X.jsxs)("div",{className:"flex flex-col items-center gap-2 text-center px-4",children:[(0,X.jsx)(eu,{className:"h-8 w-8 text-muted-foreground"}),(0,X.jsx)("p",{className:"text-sm text-muted-foreground",children:"Select a file to view or edit"})]})})]}),(0,X.jsx)(IE,{open:eI,onOpenChange:eD}),(0,X.jsx)(Iz,{currentPath:J?.path}),(0,X.jsx)("input",{ref:I,type:"file",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&tt(e.target.files,D.current)}}),(0,X.jsx)(rP,{open:!!V,onOpenChange:e=>{e||W(null)},title:K?"Delete folder?":"Delete file?",description:K?`"${V?.split("/").pop()}" and all its contents will be permanently deleted.`:`"${V?.split("/").pop()}" will be permanently removed.`,onConfirm:to}),(0,X.jsx)(rP,{open:!!h,onOpenChange:e=>{e||f(null)},title:"Delete workspace?",description:`"${a.find(e=>e.id===h)?.name??""}" will be removed from the workspace list. Files on disk are NOT deleted.`,onConfirm:e8})]})]},o??"none")}],952683)}]);
@@ -7,6 +7,8 @@ You are connecting to a running wiki-viewer instance at $WIKI_URL (e.g. `http://
7
7
 
8
8
  **Mode rule:** Every file read returns `X-Collab-State`. If `active` → use Tier-2 block-ops so the human can review. Otherwise → use Tier-1 raw fs. A raw write to an `active` .md is rejected 409 `COLLAB_ACTIVE` with the Tier-2 URL.
9
9
 
10
+ **Workspaces:** this instance may serve several root directories. Send `X-Workspace: <workspaceId>` (or `?ws=<id>`) on every request to target one; omit it only on a single-workspace instance (the server falls back to the default). Ask the human for the workspace id or read it from the `?ws=` param of the URL they shared. A token may be pinned to one workspace — a mismatched workspace returns 403.
11
+
10
12
  Set `basis` and `basisDetail` on every Tier-2 content op so the human can see where your changes came from. Prefer `suggestion.add` over direct block ops unless told otherwise.
11
13
 
12
- MCP-capable agents: `npx wiki-viewer-mcp` (set `WIKI_VIEWER_URL`, `WIKI_VIEWER_TOKEN`, `WIKI_VIEWER_AGENT_ID`) gives native **Tier-1 file tools** (read/write/edit/list/search/move/delete) and refuses to overwrite an `active` doc. It has **no Tier-2 collab tools** — to co-write a doc (suggestions/comments), call the Tier-2 HTTP endpoints directly. MCP = fast filework; Tier-2 HTTP = reviewable collaboration.
14
+ MCP-capable agents: `npx wiki-viewer-mcp` (set `WIKI_VIEWER_URL`, `WIKI_VIEWER_TOKEN`, `WIKI_VIEWER_AGENT_ID`, and optionally `WIKI_VIEWER_WORKSPACE` to target a workspace) gives native **Tier-1 file tools** (read/write/edit/list/search/move/delete) and refuses to overwrite an `active` doc. It has **no Tier-2 collab tools** — to co-write a doc (suggestions/comments), call the Tier-2 HTTP endpoints directly. MCP = fast filework; Tier-2 HTTP = reviewable collaboration.
@@ -58,7 +58,10 @@ Content-Type: application/json
58
58
  - `id` must match `^ai:[a-z][a-z0-9-]{0,30}$`. Pick something stable per agent identity (e.g. `ai:claude`, `ai:cursor`, `ai:my-script`).
59
59
  - `displayName` 1-80 chars. What the human sees in the approval UI.
60
60
  - `scope.paths` is a glob list. Use `**/*` for full repo access, or restrict to a subtree like `notes/**`.
61
- - `scope.ops` ⊆ `["read", "mutate"]`.
61
+ - `scope.ops` ⊆ `["read", "mutate"]` (add `"delete"` if you need to remove files).
62
+ - `scope.workspaceId` (optional): pin this grant to a single workspace id. Omit
63
+ to request a wildcard grant usable in any workspace (the human can still narrow
64
+ it at approval time).
62
65
 
63
66
  Response:
64
67
 
@@ -90,10 +93,34 @@ Every subsequent request:
90
93
  ```
91
94
  Authorization: Bearer <token>
92
95
  X-Agent-Id: ai:<your-name>
96
+ X-Workspace: <workspaceId> # optional but recommended (see Workspaces)
93
97
  ```
94
98
 
95
99
  The `X-Agent-Id` must match the id the token was issued for. Spoofing rejected with `401`.
96
100
 
101
+ ## Workspaces
102
+
103
+ A wiki-viewer instance can serve **multiple root directories ("workspaces")**
104
+ at once. Every file path you use is relative to **one** workspace's root.
105
+
106
+ - **Targeting a workspace:** send an `X-Workspace: <workspaceId>` header on every
107
+ request (or append `?ws=<workspaceId>` to the URL). If you omit it, the server
108
+ resolves to a default (the most-recently-opened workspace), which is correct
109
+ for a single-workspace instance but ambiguous when several exist — so prefer
110
+ to be explicit.
111
+ - **Discovering workspace ids:** `GET /api/agent/settings` returns the resolved
112
+ `root` (the active workspace's directory) for whatever `X-Workspace` you send.
113
+ The human picks/creates workspaces in the UI; ask them for the id, or read it
114
+ from the `?ws=` param in a wiki-viewer URL they pasted.
115
+ - **Scoped grants:** your token may be pinned to one workspace at approval time.
116
+ A request that resolves to a different workspace is rejected `403 FORBIDDEN`.
117
+ A token with no workspace pin works against any workspace (wildcard).
118
+ - **Isolation:** paths in workspace A never touch workspace B, even if they share
119
+ the same relative path (`notes.md` in A ≠ `notes.md` in B).
120
+
121
+ Whenever the human is working in a specific workspace, capture its id once and
122
+ send `X-Workspace: <id>` on all subsequent calls.
123
+
97
124
  ## Reading
98
125
 
99
126
  ```
@@ -214,16 +241,16 @@ Acks are advisory; events are never deleted.
214
241
 
215
242
  ## Error codes
216
243
 
217
- | Status | Code | Meaning |
218
- | ------ | ---------------------- | -------------------------------------------------- |
219
- | 401 | UNAUTHORIZED | bad/missing token or X-Agent-Id |
220
- | 403 | FORBIDDEN | scope mismatch, or `by` doesn't match `X-Agent-Id` |
221
- | 404 | FILE_NOT_FOUND | path doesn't exist under server root |
222
- | 409 | STALE_REVISION | `baseRevision` wrong, retry with included snapshot |
223
- | 409 | BLOCK_NOT_FOUND | ref no longer exists, refetch snapshot |
224
- | 409 | IDEMPOTENCY_KEY_REUSED | same key, different body |
225
- | 422 | INVALID_MARKDOWN | op's markdown failed to parse |
226
- | 429 | RATE_LIMITED | bucket exhausted, honor `Retry-After` header |
244
+ | Status | Code | Meaning |
245
+ | ------ | ---------------------- | --------------------------------------------------------------------------------------- |
246
+ | 401 | UNAUTHORIZED | bad/missing token or X-Agent-Id |
247
+ | 403 | FORBIDDEN | scope/path mismatch, workspace not covered by grant, or `by` doesn't match `X-Agent-Id` |
248
+ | 404 | FILE_NOT_FOUND | path doesn't exist under server root |
249
+ | 409 | STALE_REVISION | `baseRevision` wrong, retry with included snapshot |
250
+ | 409 | BLOCK_NOT_FOUND | ref no longer exists, refetch snapshot |
251
+ | 409 | IDEMPOTENCY_KEY_REUSED | same key, different body |
252
+ | 422 | INVALID_MARKDOWN | op's markdown failed to parse |
253
+ | 429 | RATE_LIMITED | bucket exhausted, honor `Retry-After` header |
227
254
 
228
255
  ---
229
256
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-viewer",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "Local file viewer and wiki — view markdown, HTML, PDFs, notebooks, office docs, and more from any directory",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -90,11 +90,12 @@ node dist/index.js # start MCP server
90
90
  Set three environment variables before starting the MCP server
91
91
  (the `register` command prints them for you after approval):
92
92
 
93
- | Var | Description |
94
- | ---------------------- | ------------------------------------------------------------------------ |
95
- | `WIKI_VIEWER_URL` | Base URL of your wiki-viewer instance, e.g. `https://notes.example.com` |
96
- | `WIKI_VIEWER_TOKEN` | Bearer token obtained via `wiki-viewer-mcp register` |
97
- | `WIKI_VIEWER_AGENT_ID` | Your agent ID (e.g. `ai:myagent`), sent as `X-Agent-Id` on every request |
93
+ | Var | Description |
94
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
95
+ | `WIKI_VIEWER_URL` | Base URL of your wiki-viewer instance, e.g. `https://notes.example.com` |
96
+ | `WIKI_VIEWER_TOKEN` | Bearer token obtained via `wiki-viewer-mcp register` |
97
+ | `WIKI_VIEWER_AGENT_ID` | Your agent ID (e.g. `ai:myagent`), sent as `X-Agent-Id` on every request |
98
+ | `WIKI_VIEWER_WORKSPACE` | _Optional._ Workspace id, sent as `X-Workspace` on every request. Targets one root directory when the instance serves several. Omit for single-workspace instances (the server uses its default). |
98
99
 
99
100
  ## Usage in Claude Code / Cursor / Codex
100
101
 
@@ -56,11 +56,13 @@ export class WikiViewerClient {
56
56
  baseUrl;
57
57
  token;
58
58
  agentId;
59
+ workspace;
59
60
  _fetch;
60
61
  constructor(config) {
61
62
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
62
63
  this.token = config.token;
63
64
  this.agentId = config.agentId;
65
+ this.workspace = config.workspace;
64
66
  this._fetch = config.fetch ?? globalThis.fetch;
65
67
  }
66
68
  // ── Helpers ────────────────────────────────────────────────────────────────
@@ -68,6 +70,8 @@ export class WikiViewerClient {
68
70
  return {
69
71
  Authorization: `Bearer ${this.token}`,
70
72
  "X-Agent-Id": this.agentId,
73
+ // Target a specific workspace when configured. Omitted = server default.
74
+ ...(this.workspace ? { "X-Workspace": this.workspace } : {}),
71
75
  ...extra,
72
76
  };
73
77
  }
@@ -9,6 +9,7 @@
9
9
  * WIKI_VIEWER_URL Base URL of wiki-viewer instance (required)
10
10
  * WIKI_VIEWER_TOKEN Bearer token from TOFU registration (required)
11
11
  * WIKI_VIEWER_AGENT_ID X-Agent-Id header value (required)
12
+ * WIKI_VIEWER_WORKSPACE Workspace id for X-Workspace header (optional; targets one workspace)
12
13
  *
13
14
  * Mode-awareness:
14
15
  * Before any raw write to a .md file, the shim checks the cached
@@ -62,6 +63,7 @@ export function createClient(overrides) {
62
63
  baseUrl: overrides?.baseUrl ?? requireEnv("WIKI_VIEWER_URL"),
63
64
  token: overrides?.token ?? requireEnv("WIKI_VIEWER_TOKEN"),
64
65
  agentId: overrides?.agentId ?? requireEnv("WIKI_VIEWER_AGENT_ID"),
66
+ workspace: overrides?.workspace ?? process.env.WIKI_VIEWER_WORKSPACE,
65
67
  fetch: overrides?.fetch,
66
68
  });
67
69
  }
@@ -424,6 +426,7 @@ async function runRegister() {
424
426
  "scope-paths": { type: "string", default: "**/*" },
425
427
  ops: { type: "string", default: "read,mutate" },
426
428
  timeout: { type: "string", default: "300" },
429
+ workspace: { type: "string" },
427
430
  },
428
431
  allowPositionals: true,
429
432
  });
@@ -489,6 +492,7 @@ async function runRegister() {
489
492
  WIKI_VIEWER_URL: values.url,
490
493
  WIKI_VIEWER_TOKEN: result.token,
491
494
  WIKI_VIEWER_AGENT_ID: result.agentId,
495
+ ...(values.workspace ? { WIKI_VIEWER_WORKSPACE: values.workspace } : {}),
492
496
  },
493
497
  },
494
498
  },
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "wiki-viewer-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "wiki-viewer-mcp",
9
- "version": "0.1.0",
9
+ "version": "0.2.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@modelcontextprotocol/sdk": "^1.13.0"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-viewer-mcp",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "MCP filesystem adapter for wiki-viewer agent API",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,6 +15,8 @@ export interface ClientConfig {
15
15
  baseUrl: string; // e.g. "https://notes.example.com"
16
16
  token: string; // Bearer token from TOFU registration
17
17
  agentId: string; // X-Agent-Id header
18
+ /** Target workspace id (X-Workspace header). Optional: omit for single-workspace instances. */
19
+ workspace?: string;
18
20
  /** Override fetch implementation (for testing) */
19
21
  fetch?: typeof fetch;
20
22
  }
@@ -116,12 +118,14 @@ export class WikiViewerClient {
116
118
  private readonly baseUrl: string;
117
119
  private readonly token: string;
118
120
  private readonly agentId: string;
121
+ private readonly workspace?: string;
119
122
  private readonly _fetch: typeof fetch;
120
123
 
121
124
  constructor(config: ClientConfig) {
122
125
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
123
126
  this.token = config.token;
124
127
  this.agentId = config.agentId;
128
+ this.workspace = config.workspace;
125
129
  this._fetch = config.fetch ?? globalThis.fetch;
126
130
  }
127
131
 
@@ -131,6 +135,8 @@ export class WikiViewerClient {
131
135
  return {
132
136
  Authorization: `Bearer ${this.token}`,
133
137
  "X-Agent-Id": this.agentId,
138
+ // Target a specific workspace when configured. Omitted = server default.
139
+ ...(this.workspace ? { "X-Workspace": this.workspace } : {}),
134
140
  ...extra,
135
141
  };
136
142
  }
@@ -9,6 +9,7 @@
9
9
  * WIKI_VIEWER_URL Base URL of wiki-viewer instance (required)
10
10
  * WIKI_VIEWER_TOKEN Bearer token from TOFU registration (required)
11
11
  * WIKI_VIEWER_AGENT_ID X-Agent-Id header value (required)
12
+ * WIKI_VIEWER_WORKSPACE Workspace id for X-Workspace header (optional; targets one workspace)
12
13
  *
13
14
  * Mode-awareness:
14
15
  * Before any raw write to a .md file, the shim checks the cached
@@ -76,12 +77,14 @@ export function createClient(overrides?: {
76
77
  baseUrl?: string;
77
78
  token?: string;
78
79
  agentId?: string;
80
+ workspace?: string;
79
81
  fetch?: typeof fetch;
80
82
  }): WikiViewerClient {
81
83
  return new WikiViewerClient({
82
84
  baseUrl: overrides?.baseUrl ?? requireEnv("WIKI_VIEWER_URL"),
83
85
  token: overrides?.token ?? requireEnv("WIKI_VIEWER_TOKEN"),
84
86
  agentId: overrides?.agentId ?? requireEnv("WIKI_VIEWER_AGENT_ID"),
87
+ workspace: overrides?.workspace ?? process.env.WIKI_VIEWER_WORKSPACE,
85
88
  fetch: overrides?.fetch,
86
89
  });
87
90
  }
@@ -524,6 +527,7 @@ async function runRegister() {
524
527
  "scope-paths": { type: "string", default: "**/*" },
525
528
  ops: { type: "string", default: "read,mutate" },
526
529
  timeout: { type: "string", default: "300" },
530
+ workspace: { type: "string" },
527
531
  },
528
532
  allowPositionals: true,
529
533
  });
@@ -595,6 +599,7 @@ async function runRegister() {
595
599
  WIKI_VIEWER_URL: values.url,
596
600
  WIKI_VIEWER_TOKEN: result.token,
597
601
  WIKI_VIEWER_AGENT_ID: result.agentId,
602
+ ...(values.workspace ? { WIKI_VIEWER_WORKSPACE: values.workspace } : {}),
598
603
  },
599
604
  },
600
605
  },