@tianshu-ai/tianshu 0.3.24 → 0.3.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tianshu-ai/tianshu",
3
- "version": "0.3.24",
3
+ "version": "0.3.25",
4
4
  "description": "An open AI agent platform with a sidecar browser. Built in public.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/tianshu-ai/tianshu",
@@ -29,7 +29,7 @@ memory_mib: 4096`}),(0,J.jsxs)(`p`,{className:`mt-2 text-[11px] leading-relaxed
29
29
  `):`… waiting for first log line …`})]}),t&&t.builds.length===0&&!s&&(0,J.jsxs)(`p`,{className:`rounded-md border border-dashed border-gray-800 px-3 py-6 text-center text-[12px] text-gray-500`,children:[`No builds yet. Click `,(0,J.jsx)(`strong`,{children:`Build`}),` to create one from your saved Sandboxfile.`]}),t&&t.builds.length>0&&(0,J.jsx)(`ul`,{className:`space-y-2`,children:t.builds.map(e=>(0,J.jsxs)(`li`,{className:`rounded-md border border-gray-800 bg-gray-900/50 px-3 py-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1.5 py-0.5 text-[11px] text-gray-100`,children:e.buildId}),(e.roles?.browser??e.published)&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 rounded bg-emerald-900/40 px-1.5 py-0.5 text-[10px] uppercase text-emerald-300`,children:[(0,J.jsx)(W,{size:10}),` Browser`]}),e.roles?.task&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 rounded bg-sky-900/40 px-1.5 py-0.5 text-[10px] uppercase text-sky-300`,children:[(0,J.jsx)(W,{size:10}),` Task`]}),(0,J.jsx)(`span`,{className:`text-[11px] text-gray-400`,title:e.basedOnSnapshot?`layered on snapshot ${e.basedOnSnapshot}`:`image: ${e.baseImage}`,children:e.basedOnSnapshot?`↳ ${e.basedOnSnapshot.split(`-build-`).pop()??e.basedOnSnapshot}`:e.baseImage}),(0,J.jsxs)(`span`,{className:`text-[10px] text-gray-600`,children:[(e.durationMs/1e3).toFixed(1),`s · `,BF(e.builtAt)]})]}),(0,J.jsxs)(`p`,{className:`mt-1 truncate text-[11px] text-gray-500`,children:[`snapshot:`,` `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 text-gray-400`,children:e.snapshotName})]})]}),(()=>{let t=e.roles?.browser??e.published,n=e.roles?.task??!1;return(0,J.jsxs)(`div`,{className:`flex flex-shrink-0 flex-col items-stretch gap-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-stretch gap-px overflow-hidden rounded-md border border-gray-800`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>void C(e.buildId,`browser`,!1),disabled:l===e.buildId||t,className:`flex items-center gap-1 px-2 py-1 text-[11px] text-emerald-200 hover:bg-emerald-900/30 disabled:cursor-not-allowed disabled:opacity-40`,title:t?`This build is already the active Browser snapshot.`:`Pin this build as the long-lived Browser sandbox snapshot. The live VM keeps running its current snapshot until you reset.`,children:[l===e.buildId?(0,J.jsx)(db,{size:11,className:`animate-spin`}):(0,J.jsx)(Id,{size:11}),t?`Browser ✓`:`Use as Browser`]}),!t&&(0,J.jsxs)(`button`,{type:`button`,onClick:()=>void C(e.buildId,`browser`,!0),disabled:l===e.buildId,className:`flex items-center gap-1 border-l border-gray-800 px-2 py-1 text-[11px] text-emerald-300 hover:bg-emerald-900/30 disabled:cursor-not-allowed disabled:opacity-40`,title:`Pin as Browser + reset the live VM so the new snapshot takes effect immediately. Adds ~10-20s for the reset.`,children:[(0,J.jsx)(yE,{size:11}),`& Reset`]})]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>void C(e.buildId,`task`,!1),disabled:l===e.buildId||n,className:`flex items-center justify-center gap-1 rounded-md border border-gray-800 px-2 py-1 text-[11px] text-sky-200 hover:bg-sky-900/30 disabled:cursor-not-allowed disabled:opacity-40`,title:n?`This build is already the active Task snapshot.`:`Pin this build as the per-task sandbox snapshot. Future per-task sandboxes will boot from it; takes effect on the next task acquire.`,children:[l===e.buildId?(0,J.jsx)(db,{size:11,className:`animate-spin`}):(0,J.jsx)(Id,{size:11}),n?`Task ✓`:`Use as Task`]})]})})()]}),e.logTail&&(0,J.jsxs)(`details`,{className:`mt-1.5 text-[11px]`,children:[(0,J.jsx)(`summary`,{className:`cursor-pointer text-gray-500 hover:text-gray-400`,children:`Log tail`}),(0,J.jsx)(`pre`,{className:`mt-1 max-h-40 overflow-auto whitespace-pre-wrap rounded bg-gray-950 px-2 py-1 text-[11px] leading-relaxed text-gray-400`,children:e.logTail})]})]},e.buildId))})]})}function qF(){let[e,t]=(0,S.useState)(``),[n,r]=(0,S.useState)(`/workspace`),[i,a]=(0,S.useState)(`live`),[o,s]=(0,S.useState)([]),[c,l]=(0,S.useState)(!1),[u,d]=(0,S.useState)(null),[f,p]=(0,S.useState)([]),m=(0,S.useRef)(null),h=(0,S.useRef)(0),g=(0,S.useRef)(null),_=o.map(e=>e.command),v=(0,S.useCallback)(async()=>{try{p((await zF(`${RF}/builds`)).builds)}catch{}},[]);(0,S.useEffect)(()=>{v()},[v]);async function y(){let r=e.trim();if(!r||c)return;let a=++h.current,o=n.trim()||`/workspace`,u=i,f={id:a,command:r,workdir:o,target:u,startedAt:Date.now(),result:null,transportError:null};s(e=>[...e,f]),t(``),d(null),l(!0);let p=new AbortController;g.current=p;try{let e={command:r,workdir:o};u!==`live`&&(e.build_id=u);let t=await zF(`${RF}/exec`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:p.signal});s(e=>e.map(e=>e.id===a?{...e,result:t}:e))}catch(e){let t=e instanceof DOMException&&e.name===`AbortError`?`Cancelled by user. The server-side timeout (60s default) will eventually tear the preview VM down.`:e instanceof Error?e.message:String(e);s(e=>e.map(e=>e.id===a?{...e,transportError:t}:e))}finally{l(!1),g.current=null,requestAnimationFrame(()=>m.current?.focus())}}function b(){g.current&&=(g.current.abort(),null)}function x(){s([]),h.current=0}function C(e){if(_.length===0)return;let n;if(e===-1)if(u===null)n=_.length-1;else if(u===0)return;else n=u-1;else{if(u===null)return;if(u>=_.length-1){d(null),t(``);return}n=u+1}d(n),t(_[n]??``)}function w(t){if(t.key===`Enter`&&!t.shiftKey){t.preventDefault(),y();return}let n=!e.includes(`
30
30
  `);t.key===`ArrowUp`&&n?(t.preventDefault(),C(-1)):t.key===`ArrowDown`&&n&&(t.preventDefault(),C(1))}let T=i===`live`?`Live sandbox`:`Preview build ${i}`;return(0,J.jsxs)(`section`,{children:[(0,J.jsx)(eI,{title:`Shell`,description:i===`live`?`Run a one-shot command inside the running sandbox. Defaults to bash semantics; equivalent to the agent's exec tool.`:`Boot a throwaway VM from the selected build's snapshot, run the command, then tear it down. Lets you sanity-check a build before switching the tenant to it. The live sandbox is not touched.`,actions:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>void v(),className:`btn-ghost flex items-center gap-1.5 px-2 py-1 text-[11px] text-gray-400`,title:`Refresh build list`,children:[(0,J.jsx)(ZT,{size:11}),`Reload builds`]}),(0,J.jsxs)(`button`,{type:`button`,onClick:x,disabled:o.length===0,className:`btn-ghost flex items-center gap-1.5 px-2 py-1 text-[11px] text-gray-400 disabled:opacity-50`,title:`Clear command history (does not affect the sandbox)`,children:[(0,J.jsx)(yM,{size:12}),`Clear`]})]})}),o.length===0&&(0,J.jsxs)(`p`,{className:`mb-2 rounded-md border border-dashed border-gray-800 px-3 py-3 text-center text-[11px] text-gray-500`,children:[`Try`,` `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 text-gray-300`,children:`ls /workspace`}),` · `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 text-gray-300`,children:`python3 --version`}),` · `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 text-gray-300`,children:`which libreoffice`}),`.`]}),(0,J.jsx)(`div`,{className:`mb-2 max-h-[420px] space-y-2 overflow-y-auto`,children:o.map(e=>(0,J.jsx)(JF,{entry:e},e.id))}),(0,J.jsxs)(`div`,{className:`rounded-md border border-gray-800 bg-gray-950 p-2`,children:[(0,J.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2 text-[10px] text-gray-500`,children:[(0,J.jsx)(`span`,{children:`target:`}),(0,J.jsxs)(`select`,{value:i,onChange:e=>a(e.target.value),className:`rounded border px-2 py-0.5 font-mono text-[11px] text-gray-200 outline-none focus:border-blue-700 ${i===`live`?`border-emerald-700/40 bg-gray-900`:`border-amber-700/40 bg-amber-950/30`}`,title:`Run against the live sandbox or boot a throwaway preview VM from a build`,children:[(0,J.jsx)(`option`,{value:`live`,children:`Live sandbox`}),f.length>0&&(0,J.jsx)(`optgroup`,{label:`Preview build…`,children:f.map(e=>(0,J.jsxs)(`option`,{value:e.buildId,children:[e.buildId,` · `,e.baseImage,e.published?` (in use)`:``]},e.buildId))})]}),(0,J.jsx)(`span`,{className:`text-gray-600`,children:`·`}),(0,J.jsx)(`span`,{children:`workdir:`}),(0,J.jsx)(`input`,{type:`text`,value:n,onChange:e=>r(e.target.value),spellCheck:!1,className:`flex-1 rounded border border-gray-800 bg-gray-900 px-2 py-0.5 font-mono text-[11px] text-gray-200 outline-none focus:border-blue-700`})]}),(0,J.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,J.jsx)(`textarea`,{ref:m,value:e,onChange:e=>{t(e.target.value),d(null)},onKeyDown:w,disabled:c,spellCheck:!1,placeholder:`echo hello`,rows:2,className:`flex-1 resize-y rounded border border-gray-800 bg-gray-900 px-2 py-1 font-mono text-[12px] leading-relaxed text-gray-100 outline-none placeholder:text-gray-600 focus:border-blue-700 disabled:opacity-60`}),c?(0,J.jsxs)(`button`,{type:`button`,onClick:b,className:`flex items-center gap-1.5 rounded-md bg-rose-600 px-3 py-1.5 text-[11px] font-medium text-white hover:bg-rose-500`,title:`Abort the in-flight request. The preview VM is also torn down server-side after a server-enforced timeout (60s default).`,children:[(0,J.jsx)(IP,{size:12}),`Cancel`]}):(0,J.jsxs)(`button`,{type:`button`,onClick:()=>void y(),disabled:e.trim().length===0,className:`flex items-center gap-1.5 rounded-md bg-emerald-600 px-3 py-1.5 text-[11px] font-medium text-white hover:bg-emerald-500 disabled:cursor-not-allowed disabled:bg-gray-800 disabled:text-gray-500`,children:[(0,J.jsx)(xj,{size:12}),`Run`]})]}),(0,J.jsxs)(`p`,{className:`mt-1 text-[10px] text-gray-600`,children:[`Target: `,(0,J.jsx)(`strong`,{className:`text-gray-400`,children:T}),` · `,`Enter to run · Shift+Enter for a newline · ↑/↓ to walk history. Per-call timeout 60s (max 5 min). Preview boots add ~5-10s on top of the command time.`]})]})]})}function JF({entry:e}){let{result:t,transportError:n}=e,r=t===null&&n===null,i=t?.ok===!0,a=t&&!t.ok||n!=null;return(0,J.jsxs)(`div`,{className:`rounded-md border border-gray-800 bg-gray-900/50 px-3 py-2 font-mono text-[11px] leading-relaxed`,children:[(0,J.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[r?(0,J.jsx)(db,{size:11,className:`animate-spin text-gray-400`}):i?(0,J.jsx)(W,{size:11,className:`text-emerald-400`}):(0,J.jsx)(OM,{size:11,className:`text-rose-400`}),(0,J.jsx)(`code`,{className:`flex-1 break-all text-gray-200`,children:e.command}),(0,J.jsx)(`span`,{className:`rounded px-1 py-0.5 text-[9px] uppercase tracking-wide ${e.target===`live`?`bg-emerald-900/40 text-emerald-300`:`bg-amber-900/40 text-amber-300`}`,title:e.target===`live`?`Ran against the tenant's live sandbox`:`Ran against build ${e.target}'s snapshot in a throwaway preview VM`,children:e.target===`live`?`live`:`preview ${e.target}`}),(0,J.jsxs)(`span`,{className:`text-[9px] text-gray-600`,children:[`cwd:`,e.workdir]}),t&&(0,J.jsxs)(`span`,{className:i?`rounded bg-emerald-900/40 px-1.5 py-0.5 text-[9px] text-emerald-300`:`rounded bg-rose-900/40 px-1.5 py-0.5 text-[9px] text-rose-300`,children:[`exit `,t.exitCode,t.timedOut&&` · timed out`,` · `,(t.durationMs/1e3).toFixed(2),`s`]})]}),n&&(0,J.jsx)(`pre`,{className:`max-h-40 overflow-auto whitespace-pre-wrap rounded bg-rose-950/40 px-2 py-1 text-[11px] text-rose-200`,children:n}),t&&(t.stdout||t.stderr)&&(0,J.jsxs)(`div`,{className:`space-y-1`,children:[t.stdout&&(0,J.jsx)(`pre`,{className:`max-h-72 overflow-auto whitespace-pre-wrap rounded bg-gray-950 px-2 py-1 text-[11px] text-gray-200`,children:t.stdout}),t.stderr&&(0,J.jsx)(`pre`,{className:`max-h-72 overflow-auto whitespace-pre-wrap rounded bg-amber-950/30 px-2 py-1 text-[11px] text-amber-200`,children:t.stderr})]}),t&&!t.stdout&&!t.stderr&&!a&&(0,J.jsx)(`p`,{className:`text-[10px] italic text-gray-500`,children:`(no output)`})]})}function YF({refreshTick:e,onMutate:t}){let[n,r]=(0,S.useState)(!1),[i,a]=(0,S.useState)(null),[o,s]=(0,S.useState)(null),[c,l]=(0,S.useState)(!1),u=(0,S.useCallback)(async()=>{try{a(await zF(`${RF}/status`))}catch(e){s(e instanceof Error?e.message:String(e))}},[]);(0,S.useEffect)(()=>{u()},[u]);let d=(0,S.useRef)(e);(0,S.useEffect)(()=>{e!==d.current&&u()},[e,u]),(0,S.useEffect)(()=>{if(!i||!(i.state===`starting`||i.state===`stopped`))return;let e=window.setInterval(()=>void u(),2e3);return()=>window.clearInterval(e)},[i,u]);async function f(){r(!0),s(null);try{a((await zF(`${RF}/reset`,{method:`POST`})).status),t()}catch(e){s(e instanceof Error?e.message:String(e))}finally{r(!1)}}return(0,J.jsxs)(`section`,{children:[(0,J.jsx)(eI,{title:`Live sandbox`,description:`Reset the running VM. After publishing a new build, reset to make it live.`,actions:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>void u(),className:`btn-ghost flex items-center gap-1.5 px-2 py-1 text-[11px] text-gray-400`,children:[(0,J.jsx)(ZT,{size:12}),`Refresh`]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>l(!0),className:`btn-ghost flex items-center gap-1.5 px-2 py-1 text-[11px] text-gray-300`,title:`Edit cpu / memory / timeout for both Browser and Task sandboxes`,children:[(0,J.jsx)(wD,{size:12}),`Configure`]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>void f(),disabled:n,className:`flex items-center gap-1.5 rounded-md border border-rose-700/60 bg-rose-950/40 px-3 py-1.5 text-[11px] font-medium text-rose-200 hover:bg-rose-900/40 disabled:cursor-not-allowed disabled:opacity-50`,title:`Stop and rebuild the VM from the published snapshot (or default image)`,children:[n?(0,J.jsx)(db,{size:12,className:`animate-spin`}):(0,J.jsx)(yE,{size:12}),`Reset sandbox`]})]})}),o&&(0,J.jsx)(tI,{kind:`error`,text:o}),(0,J.jsx)(`div`,{className:`rounded-md border border-gray-800 bg-gray-900/40`,children:i&&(0,J.jsxs)(`dl`,{className:`grid grid-cols-3 gap-x-4 gap-y-1.5 p-3 text-[11px]`,children:[(0,J.jsx)($F,{label:`State`,children:i.runner===`nullable`?`not running`:i.state}),(0,J.jsx)($F,{label:`Runner`,children:i.runner}),(0,J.jsx)($F,{label:`Uptime`,children:VF(i.uptimeMs)}),UF(i.meta,`sandboxName`)&&(0,J.jsx)($F,{label:`Sandbox`,children:(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1`,children:UF(i.meta,`sandboxName`)})}),UF(i.meta,`activeSnapshot`)?(0,J.jsx)($F,{label:`Booted from`,children:(0,J.jsxs)(`code`,{className:`rounded bg-emerald-900/40 px-1 text-emerald-200`,children:[`snapshot · `,UF(i.meta,`activeSnapshot`)]})}):UF(i.meta,`image`)?(0,J.jsx)($F,{label:`Booted from`,children:(0,J.jsxs)(`code`,{className:`rounded bg-gray-800 px-1`,children:[`image · `,UF(i.meta,`image`)]})}):null,UF(i.meta,`image`)&&UF(i.meta,`activeSnapshot`)&&(0,J.jsx)($F,{label:`Default image`,children:(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 text-gray-400`,children:UF(i.meta,`image`)})}),i.liveMemory&&(0,J.jsx)($F,{label:`Memory`,children:(0,J.jsxs)(`span`,{title:`${HF(i.liveMemory.usedKb)} used · ${HF(i.liveMemory.availableKb)} available · ${HF(i.liveMemory.totalKb)} total`,children:[HF(i.liveMemory.usedKb),(0,J.jsxs)(`span`,{className:`text-gray-500`,children:[` / `,HF(i.liveMemory.totalKb),` (`,` `,Math.round(i.liveMemory.usedKb/i.liveMemory.totalKb*100),`%)`]})]})}),i.lastError&&(0,J.jsx)($F,{label:`Last error`,children:(0,J.jsx)(`span`,{className:`text-rose-300`,children:i.lastError})})]})}),(0,J.jsx)(QF,{open:c,onClose:()=>l(!1)})]})}function XF({refreshTick:e}){let[t,n]=(0,S.useState)(null),[r,i]=(0,S.useState)(!0),[a,o]=(0,S.useState)(null),[s,c]=(0,S.useState)(null),l=(0,S.useCallback)(async()=>{i(!0),o(null);try{n((await zF(`${RF}/task-pool`)).entries)}catch(e){o(e instanceof Error?e.message:String(e))}finally{i(!1)}},[]);(0,S.useEffect)(()=>{l()},[l,e]),(0,S.useEffect)(()=>{let e=window.setInterval(()=>void l(),5e3);return()=>window.clearInterval(e)},[l]);async function u(e){c(e),o(null);try{await zF(`${RF}/task-pool/destroy?sandbox_name=${encodeURIComponent(e)}`,{method:`POST`}),await l()}catch(e){o(e instanceof Error?e.message:String(e))}finally{c(null)}}let d=t?.filter(e=>e.poolState===`running`).length??0,f=t?.length??0;return(0,J.jsxs)(`section`,{children:[(0,J.jsx)(eI,{title:`Per-task sandbox pool`,description:f===0?`No per-task sandboxes yet. The pool spawns one when a workboard task is picked up by a worker.`:`${f} sandbox${f===1?``:`es`} (${d} running)`,actions:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>void l(),disabled:r,className:`btn-ghost flex items-center gap-1.5 px-2 py-1 text-[11px] text-gray-400`,children:[(0,J.jsx)(ZT,{size:12,className:r?`animate-spin`:``}),`Refresh`]})}),a&&(0,J.jsx)(tI,{kind:`error`,text:a}),t!==null&&t.length>0&&(0,J.jsx)(`div`,{className:`overflow-hidden rounded-md border border-gray-800`,children:(0,J.jsxs)(`table`,{className:`w-full text-[11px]`,children:[(0,J.jsx)(`thead`,{className:`bg-gray-900/60 text-[10px] uppercase tracking-wide text-gray-500`,children:(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`th`,{className:`px-3 py-1.5 text-left`,children:`State`}),(0,J.jsx)(`th`,{className:`px-3 py-1.5 text-left`,children:`Sandbox`}),(0,J.jsx)(`th`,{className:`px-3 py-1.5 text-left`,children:`Task`}),(0,J.jsx)(`th`,{className:`px-3 py-1.5 text-left`,children:`Created`}),(0,J.jsx)(`th`,{className:`px-3 py-1.5 text-right`,children:`Actions`})]})}),(0,J.jsx)(`tbody`,{className:`divide-y divide-gray-800`,children:t.map(e=>(0,J.jsxs)(`tr`,{className:`text-gray-300`,children:[(0,J.jsx)(`td`,{className:`px-3 py-1.5`,children:(0,J.jsx)(ZF,{state:e.poolState})}),(0,J.jsx)(`td`,{className:`px-3 py-1.5 font-mono text-[10px] text-gray-400`,children:(0,J.jsx)(`code`,{className:`cursor-pointer hover:text-gray-100`,title:`Click to copy`,onClick:()=>{navigator.clipboard?.writeText(e.sandboxName).catch(()=>{})},children:e.sandboxName})}),(0,J.jsxs)(`td`,{className:`px-3 py-1.5 font-mono text-[10px] text-gray-500`,children:[e.taskId.slice(0,8),`…`]}),(0,J.jsx)(`td`,{className:`px-3 py-1.5 text-[10px] text-gray-500`,children:e.createdAt?BF(e.createdAt):`—`}),(0,J.jsx)(`td`,{className:`px-3 py-1.5 text-right`,children:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>void u(e.sandboxName),disabled:s===e.sandboxName,className:`flex items-center gap-1 rounded border border-gray-800 px-2 py-0.5 text-[10px] text-rose-300 hover:bg-rose-950/40 disabled:cursor-not-allowed disabled:opacity-40`,title:e.poolState===`running`?`Stop and remove this sandbox (also kills the running task)`:`Remove the sandbox image from disk`,children:[s===e.sandboxName?(0,J.jsx)(db,{size:10,className:`animate-spin`}):(0,J.jsx)(yM,{size:10}),e.poolState===`orphan`?`Forget`:`Destroy`]})})]},e.sandboxName))})]})})]})}function ZF({state:e}){return(0,J.jsx)(`span`,{className:`inline-flex items-center rounded border px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wide ${e===`running`?`bg-emerald-900/40 text-emerald-200 border-emerald-700/50`:e===`starting`?`bg-amber-900/40 text-amber-200 border-amber-700/50`:e===`error`?`bg-rose-900/40 text-rose-200 border-rose-700/50`:e===`orphan`?`bg-gray-900/40 text-gray-400 border-gray-700/50`:`bg-gray-900/30 text-gray-300 border-gray-800`}`,children:e})}function QF({open:e,onClose:t}){return e?(0,J.jsx)(`div`,{className:`fixed inset-0 z-40 flex items-center justify-center bg-black/60 p-6`,onClick:t,children:(0,J.jsxs)(`div`,{className:`flex max-h-[80vh] w-full max-w-lg flex-col overflow-hidden rounded-lg border border-gray-800 bg-gray-950 shadow-2xl`,onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-gray-800 px-4 py-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-sm font-medium text-gray-100`,children:`Sandbox runtime parameters`}),(0,J.jsx)(`div`,{className:`mt-0.5 text-[11px] text-gray-500`,children:`Browser sandbox changes take effect on the next Reset; Task sandbox changes take effect on the next task acquire.`})]}),(0,J.jsx)(`button`,{type:`button`,onClick:t,className:`rounded p-1 text-gray-400 hover:bg-gray-800 hover:text-gray-100`,"aria-label":`Close configure dialog`,children:(0,J.jsx)(IP,{size:14})})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto px-4 pt-3 [&>div>div>div:last-child]:sticky [&>div>div>div:last-child]:bottom-0 [&>div>div>div:last-child]:bg-gray-950 [&>div>div>div:last-child]:pt-3 [&>div>div>div:last-child]:pb-3`,children:(0,J.jsx)(pF,{pluginId:`microsandbox`})})]})}):null}function $F({label:e,children:t}){return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`dt`,{className:`col-span-1 text-gray-500`,children:e}),(0,J.jsx)(`dd`,{className:`col-span-2 text-gray-300`,children:t})]})}function eI({title:e,description:t,actions:n}){return(0,J.jsxs)(`div`,{className:`mb-2 flex items-end justify-between gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-sm font-semibold text-gray-100`,children:e}),t&&(0,J.jsx)(`p`,{className:`mt-0.5 text-[11px] text-gray-500`,children:t})]}),n&&(0,J.jsx)(`div`,{className:`flex items-center gap-1.5`,children:n})]})}function tI({kind:e,text:t}){let n=e===`ok`?`border-emerald-700/40 bg-emerald-950/40 text-emerald-300`:e===`warn`?`border-amber-700/40 bg-amber-950/40 text-amber-200`:e===`error`?`border-rose-700/50 bg-rose-950/40 text-rose-300`:`border-blue-700/40 bg-blue-950/40 text-blue-200`,r=e===`ok`?W:e===`info`?db:OM;return(0,J.jsxs)(`div`,{className:`mb-2 flex items-start gap-2 rounded-md border px-3 py-2 text-[11px] ${n}`,children:[(0,J.jsx)(r,{size:12,className:e===`info`?`mt-0.5 animate-spin`:`mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{className:`break-words`,children:t})]})}function nI(e){let[t,n]=(0,S.useState)(null),[r,i]=(0,S.useState)(null),a=(0,S.useRef)(null),[o,s]=(0,S.useState)(!1),c=(0,S.useCallback)(async()=>{try{n(await zF(`${RF}/browser/status`)),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}},[]);return(0,S.useEffect)(()=>{c()},[c]),(0,S.useEffect)(()=>{if(t?.ready)return;let e=window.setInterval(()=>void c(),4e3);return()=>window.clearInterval(e)},[t?.ready,c]),rI({container:a,enabled:!!(t?.ready&&t.ports.vnc),onDraggingChange:s}),(0,J.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,J.jsx)(`div`,{className:`flex items-center justify-between border-b border-gray-800 px-4 py-2`,children:(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-gray-200`,children:[(0,J.jsx)(o_,{size:14,className:`text-brand-400`}),`Browser`]})}),r&&(0,J.jsxs)(`div`,{className:`m-3 flex items-start gap-1.5 rounded-md border border-rose-700/50 bg-rose-950/40 px-3 py-2 text-[11px] text-rose-300`,children:[(0,J.jsx)(OM,{size:12,className:`mt-px flex-shrink-0`}),(0,J.jsx)(`span`,{className:`break-all`,children:r})]}),(0,J.jsx)(`div`,{ref:a,className:`relative min-h-0 flex-1 bg-gray-950`,children:t?.ready&&t.ports.vnc?(0,J.jsx)(`iframe`,{title:`Browser viewport`,src:`http://localhost:${t.ports.vnc}/vnc.html?autoconnect=true&resize=scale&reconnect=true&reconnect_delay=1000`,style:{pointerEvents:o?`none`:void 0},className:`absolute inset-0 h-full w-full bg-gray-950`}):(0,J.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-center text-[12px] text-gray-500`,children:t?t.hint??`Browser stack not running.`:`Loading…`})})]})}function rI(e){let{container:t,enabled:n,onDraggingChange:r}=e;(0,S.useEffect)(()=>{if(!n)return;let e=t.current;if(!e)return;let i=Math.min(window.devicePixelRatio||1,2),a=null,o=!1,s=null,c={w:0,h:0},l=(e,t)=>{fetch(`${RF}/browser/resize`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({width:e,height:t})}).catch(()=>{})},u=()=>{if(!s)return;let{w:e,h:t}=s;e<320||t<240||Math.abs(e-c.w)<8&&Math.abs(t-c.h)<8||(c={w:e,h:t},s=null,l(e,t))},d=()=>{a&&clearTimeout(a),a=setTimeout(()=>{a=null,!o&&u()},300)},f=new ResizeObserver(e=>{let t=e[0];t&&(s={w:Math.round(t.contentRect.width*i),h:Math.round(t.contentRect.height*i)},d())});f.observe(e);let p=e=>{o=e,r(e),e||d()},m=()=>p(!0),h=()=>p(!1);return window.addEventListener(`mousedown`,m),window.addEventListener(`mouseup`,h),window.addEventListener(`pointerdown`,m),window.addEventListener(`pointerup`,h),window.addEventListener(`pointercancel`,h),()=>{f.disconnect(),a&&clearTimeout(a),window.removeEventListener(`mousedown`,m),window.removeEventListener(`mouseup`,h),window.removeEventListener(`pointerdown`,m),window.removeEventListener(`pointerup`,h),window.removeEventListener(`pointercancel`,h)}},[t,n,r])}var iI={components:{BrowserViewportPanel:nI,MicroSandboxAdminPage:WF}};iI.components;function aI(){let[e,t]=(0,S.useState)([]),[n,r]=(0,S.useState)([]),[i,a]=(0,S.useState)(null),[o,s]=(0,S.useState)(null),[c,l]=(0,S.useState)(!1),[u,d]=(0,S.useState)(null),[f,p]=(0,S.useState)(()=>new Set),m=(0,S.useCallback)(e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),[h,g]=(0,S.useState)(null),_=(0,S.useCallback)(async(e,n)=>{g(e),d(null);try{let r=await fetch(`/api/p/workboard/agents/${encodeURIComponent(e)}/enabled`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:!n})});if(!r.ok){let t=await r.text().catch(()=>``);d(`PATCH /agents/${e}/enabled → HTTP ${r.status}${t?`: `+t:``}`);return}t(t=>t.map(t=>t.id===e?{...t,enabled:!n}:t))}catch(e){d(e instanceof Error?e.message:String(e))}finally{g(null)}},[]),v=(0,S.useCallback)(async()=>{l(!0),d(null);try{let[e,n,i]=await Promise.all([fetch(`/api/p/workboard/agents`,{credentials:`include`}),fetch(`/api/tools`,{credentials:`include`}),fetch(`/api/skills`,{credentials:`include`})]);if(!e.ok){d(`GET /agents → HTTP ${e.status}`);return}let o=await e.json();t(o.agents),r(o.kinds),n.ok&&a((await n.json()).tools??[]),i.ok&&s((await i.json()).skills??[])}catch(e){d(e instanceof Error?e.message:String(e))}finally{l(!1)}},[]);(0,S.useEffect)(()=>{v()},[v]);let y=e=>n.find(t=>t.id===e)?.displayName??e,b=e=>`tenant-config:///workers/${e.builtinKey??e.id}/`;return(0,J.jsxs)(`div`,{className:`mx-auto max-w-5xl p-6`,children:[(0,J.jsxs)(`div`,{className:`mb-4 rounded-md border border-amber-900/40 bg-amber-950/30 px-3 py-2 text-[12px] leading-relaxed text-amber-200/90`,children:[(0,J.jsx)(`div`,{className:`font-semibold text-amber-100`,children:`Read-only listing — edit on disk`}),(0,J.jsxs)(`p`,{className:`mt-1 text-amber-200/70`,children:[`Worker config lives at`,` `,(0,J.jsx)(`code`,{className:`rounded bg-amber-950/60 px-1 py-0.5 text-amber-100`,children:`_tenant/config/workers/<slug>/`}),`. Each worker is a directory with`,` `,(0,J.jsx)(`code`,{className:`text-amber-100`,children:`agent.json`}),` and an optional`,` `,(0,J.jsx)(`code`,{className:`text-amber-100`,children:`SOUL.md`}),` /`,` `,(0,J.jsx)(`code`,{className:`text-amber-100`,children:`skills/`}),`. Edit the files directly, or ask the chat agent to do it via`,` `,(0,J.jsx)(`code`,{className:`text-amber-100`,children:`tenant_config_write`}),`. Pool picks up changes on next activate; a fs watcher follow-up will make this live.`]})]}),(0,J.jsxs)(`div`,{className:`mb-6 flex items-start justify-between gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold text-gray-100`,children:[(0,J.jsx)(js,{size:18,className:`text-brand-400`}),`Worker agents`]}),(0,J.jsx)(`p`,{className:`mt-1 max-w-3xl text-[12px] leading-relaxed text-gray-500`,children:`Inventory the workboard pool currently sees. Filesystem rows shadow same-slug DB rows; legacy DB rows still present here haven't been edited or aren't yet picked up by the merger.`})]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>void v(),disabled:c,className:`flex items-center gap-1 rounded-md border border-gray-700 px-2.5 py-1.5 text-[12px] text-gray-300 hover:bg-gray-800 disabled:opacity-50`,title:`Reload`,children:[(0,J.jsx)(ZT,{size:12,className:c?`animate-spin`:``}),`Reload`]})]}),u&&(0,J.jsx)(`div`,{className:`mb-4 rounded-md border border-red-900/40 bg-red-950/40 px-3 py-2 text-[12px] text-red-300`,children:u}),(0,J.jsx)(`div`,{className:`overflow-x-auto rounded-md border border-gray-800`,children:(0,J.jsxs)(`table`,{className:`min-w-full divide-y divide-gray-800 text-[12px]`,children:[(0,J.jsx)(`thead`,{className:`bg-gray-900/60 text-[11px] font-semibold uppercase tracking-wide text-gray-400`,children:(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`State`}),(0,J.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`Name`}),(0,J.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`Kind`}),(0,J.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`Source`}),(0,J.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`Model`}),(0,J.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`Slug`})]})}),(0,J.jsx)(`tbody`,{className:`divide-y divide-gray-800`,children:e.length===0?(0,J.jsx)(`tr`,{children:(0,J.jsx)(`td`,{colSpan:6,className:`px-3 py-8 text-center text-gray-500`,children:c?`Loading…`:`No worker agents.`})}):e.flatMap(e=>{let t=f.has(e.id);return[(0,J.jsxs)(`tr`,{className:`cursor-pointer hover:bg-gray-900/40`,onClick:()=>m(e.id),children:[(0,J.jsx)(`td`,{className:`px-3 py-2`,children:(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t?(0,J.jsx)(Fl,{size:12,className:`text-gray-500`}):(0,J.jsx)(zl,{size:12,className:`text-gray-500`}),(0,J.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e.enabled,disabled:h===e.id,onClick:t=>{t.stopPropagation(),_(e.id,e.enabled)},className:`relative inline-flex h-4 w-7 shrink-0 cursor-pointer items-center rounded-full border transition-colors ${e.enabled?`border-emerald-500/60 bg-emerald-500/80 hover:bg-emerald-500`:`border-gray-700 bg-gray-700 hover:bg-gray-600`} disabled:cursor-not-allowed disabled:opacity-50`,title:e.enabled?`Enabled — click to disable. The pool will stop claiming new tasks for this agent.`:`Disabled — click to enable. The pool will resume claiming tasks.`,children:[(0,J.jsxs)(`span`,{className:`sr-only`,children:[e.enabled?`Disable`:`Enable`,` `,e.name]}),(0,J.jsx)(`span`,{className:`pointer-events-none inline-block h-3 w-3 transform rounded-full bg-white shadow transition-transform ${e.enabled?`translate-x-3`:`translate-x-0.5`}`})]})]})}),(0,J.jsxs)(`td`,{className:`px-3 py-2`,children:[(0,J.jsx)(`div`,{className:`font-medium text-gray-100`,children:e.name}),e.description&&(0,J.jsx)(`div`,{className:`text-[11px] text-gray-500`,children:e.description})]}),(0,J.jsx)(`td`,{className:`px-3 py-2`,children:(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1.5 py-0.5 text-[11px] text-gray-300`,children:y(e.kind)})}),(0,J.jsx)(`td`,{className:`px-3 py-2`,children:e.source===`builtin`?(0,J.jsx)(`span`,{className:`rounded bg-indigo-950 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-indigo-300`,children:`builtin`}):(0,J.jsx)(`span`,{className:`rounded bg-gray-800 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-gray-400`,children:`user`})}),(0,J.jsx)(`td`,{className:`px-3 py-2 font-mono text-[11px] text-gray-400`,children:e.modelId??`—`}),(0,J.jsx)(`td`,{className:`px-3 py-2 font-mono text-[11px] text-gray-500`,children:e.builtinKey??e.id})]},`${e.id}-row`),t?(0,J.jsx)(`tr`,{className:`bg-gray-950`,children:(0,J.jsx)(`td`,{colSpan:6,className:`px-3 pb-4 pt-1`,children:(0,J.jsx)(cI,{agent:e,slotUri:b(e),toolCatalog:i,skillCatalog:o})})},`${e.id}-detail`):null]})})]})})]})}var oI=new Set([`task_list`,`task_create`,`task_update`,`task_move`,`task_delete`,`task_get_history`]);function sI(e,t,n){return e?{kind:`explicit`,items:(n?e.filter(e=>!oI.has(e)):[...e]).sort()}:t===null?{kind:`unknown`}:{kind:`effective`,items:t.map(e=>e.name).filter(e=>n?!oI.has(e):!0).sort()}}function cI({agent:e,slotUri:t,toolCatalog:n,skillCatalog:r}){let i=(0,S.useMemo)(()=>sI(e.toolsAllow,n,!0),[e.toolsAllow,n]),a=(0,S.useMemo)(()=>{if(e.effectiveSkills){let t=[...e.effectiveSkills].sort();return e.skills?{kind:`explicit`,items:t}:{kind:`effective`,items:t}}return sI(e.skills,r,!1)},[e.effectiveSkills,e.skills,r]);return(0,J.jsxs)(`div`,{className:`mt-1 space-y-3 rounded-md border border-gray-800 bg-gray-900/40 p-3`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 text-[11px] text-gray-500`,children:[(0,J.jsxs)(`span`,{children:[`slot:`,` `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1.5 py-0.5 text-gray-300`,children:t})]}),e.modelId&&(0,J.jsxs)(`span`,{children:[`model:`,` `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1.5 py-0.5 text-gray-300`,children:e.modelId})]})]}),(0,J.jsx)(lI,{title:`Allowed tools`,data:i}),(0,J.jsx)(lI,{title:`Allowed skills`,data:a}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-wide text-gray-400`,children:`System prompt (SOUL.md)`}),e.systemPrompt?(0,J.jsx)(`pre`,{className:`max-h-72 overflow-auto whitespace-pre-wrap rounded bg-gray-950 p-2 text-[11px] leading-relaxed text-gray-300`,children:e.systemPrompt}):(0,J.jsx)(`div`,{className:`text-[11px] italic text-gray-500`,children:`(none — worker uses the kind default)`})]})]})}function lI({title:e,data:t}){let n=null;return t.kind===`explicit`?n=(0,J.jsx)(`span`,{className:`rounded bg-emerald-950 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-emerald-300`,title:`agent.json declared this list explicitly`,children:`explicit`}):t.kind===`effective`&&(n=(0,J.jsx)(`span`,{className:`rounded bg-amber-950 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-amber-300`,title:`agent.json has no allow-list — worker sees every entry below`,children:`effective (no restriction)`})),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-gray-400`,children:e}),t.kind!==`unknown`&&(0,J.jsx)(`span`,{className:`rounded bg-gray-800 px-1.5 py-0.5 text-[10px] text-gray-400`,children:t.items.length}),n]}),t.kind===`unknown`?(0,J.jsx)(`div`,{className:`text-[11px] italic text-gray-500`,children:`(catalog not loaded — reload the page)`}):t.items.length===0?(0,J.jsx)(`div`,{className:`text-[11px] italic text-gray-500`,children:`(empty list — worker can call nothing)`}):(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.items.map(e=>(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1.5 py-0.5 text-[11px] text-gray-300`,children:e},e))})]})}var uI=`/api/p/workboard`,dI=`***`,fI=[{status:`ready`,label:`Ready`,color:`border-indigo-500/40 bg-indigo-500/5`,dot:`bg-indigo-400`},{status:`in_progress`,label:`In progress`,color:`border-amber-500/40 bg-amber-500/5`,dot:`bg-amber-400 animate-pulse`},{status:`done`,label:`Done`,color:`border-emerald-500/40 bg-emerald-500/5`,dot:`bg-emerald-400`}];async function pI(e){let t=await fetch(e,{credentials:`include`});if(!t.ok)throw Error(`${t.status} ${t.statusText}`);return await t.json()}async function mI(e,t,n=`POST`){let r={method:n,credentials:`include`};n!==`DELETE`&&(r.headers={"Content-Type":`application/json`},r.body=JSON.stringify(t??{}));let i=await fetch(e,r);if(!i.ok){let e=`${i.status} ${i.statusText}`;try{let t=await i.json();t.error&&(e+=` (${t.error})`)}catch{}throw Error(e)}if(i.status!==204)return await i.json()}function hI(e){if(!e)return``;let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:`${Math.floor(t/864e5)}d ago`}function gI(e,t){let n=e=>{let n=0;return t.includes(`ready`)&&(n+=e.ready),t.includes(`in_progress`)&&(n+=e.inProgress),t.includes(`done`)&&(n+=e.done),n},r=e.map(e=>({key:e.project,label:e.project,count:n(e)})).filter(e=>e.count>0),i=r.filter(e=>e.key!==dI).sort((e,t)=>e.label.localeCompare(t.label)),a=r.filter(e=>e.key===dI);return[...i,...a.map(e=>({...e,label:`Inbox`}))]}function _I(e){let[t,n]=(0,S.useState)(null),[r,i]=(0,S.useState)([]),[a,o]=(0,S.useState)(null),[s,c]=(0,S.useState)(()=>new Map),[l,u]=(0,S.useState)(null),[d,f]=(0,S.useState)(null),p=(0,S.useRef)(null),m=(0,S.useCallback)(async()=>{try{let t=new URLSearchParams;e.includeArchived&&t.set(`include_aborted`,`1`);let r=[pI(t.toString().length===0?`${uI}/tasks`:`${uI}/tasks?${t.toString()}`),pI(`${uI}/projects`),pI(`${uI}/agents`)];e.withWorker&&r.push(pI(`${uI}/workers/status`));let a=await Promise.all(r);n(a[0].tasks),i(a[1].projects);let s=a[2].agents;c(new Map(s.map(e=>[e.id,e.name]))),e.withWorker&&o(a[3]),u(null)}catch(e){u(e instanceof Error?e.message:String(e))}},[e.includeArchived,e.withWorker]);(0,S.useEffect)(()=>{m();let e=window.setInterval(()=>void m(),3e3);return()=>window.clearInterval(e)},[m]);let h=(0,S.useCallback)(async(e,t)=>{n(n=>n&&n.map(n=>n.id===e?{...n,status:t}:n)),f(e);try{await mI(`${uI}/tasks/${e}`,{status:t},`PATCH`)}catch(e){u(e instanceof Error?e.message:String(e))}finally{f(null),await m()}},[m]);return{tasks:t,projects:r,worker:a,agentNames:s,error:l,busyId:d,reload:m,moveTask:h,addTaskInColumn:(0,S.useCallback)(async(e,t)=>{try{let n=e.project&&e.project!==dI?e.project:void 0,r=(await mI(`${uI}/tasks`,{tasks:[{title:e.title,status:t,project:n,priority:e.priority||0,workerRole:e.workerRole||null,description:e.description||null}]}))?.results?.[0];if(r&&!r.ok)throw Error(r.error??`create_failed`);await m()}catch(e){u(e instanceof Error?e.message:String(e))}},[m]),patchTask:(0,S.useCallback)(async(e,t)=>{f(e);try{await mI(`${uI}/tasks/${e}`,t,`PATCH`)}catch(e){u(e instanceof Error?e.message:String(e))}finally{f(null),await m()}},[m]),deleteTask:(0,S.useCallback)(async e=>{f(e);try{let t=(await mI(`${uI}/tasks/delete`,{ids:[e]}))?.results?.[0];if(t&&!t.ok)throw Error(t.error??`delete_failed`)}catch(e){u(e instanceof Error?e.message:String(e))}finally{f(null),await m()}},[m]),bindDrag:(0,S.useCallback)(()=>({onDragStart:(e,t)=>{p.current=t,e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},onDragEnd:()=>{p.current=null},onDrop:(e,n)=>{let r=p.current||e.dataTransfer.getData(`text/plain`);if(!r)return;let i=(t??[]).find(e=>e.id===r);!i||i.status===n||h(r,n)}}),[t,h])}}function vI(e){let t=_I({includeArchived:!1,withWorker:!1}),[n,r]=(0,S.useState)(``),i=(0,S.useMemo)(()=>t.tasks?n?t.tasks.filter(e=>(e.project||dI)===n):t.tasks:null,[t.tasks,n]),a=(0,S.useMemo)(()=>gI(t.projects,[`ready`,`in_progress`,`done`]),[t.projects]),o=t.bindDrag();return(0,J.jsxs)(`div`,{className:`flex flex-col h-full bg-gray-950 text-gray-100`,children:[(0,J.jsxs)(`header`,{className:`flex items-center justify-between px-3 py-2 border-b border-gray-800 flex-shrink-0`,children:[(0,J.jsxs)(`h2`,{className:`flex items-center gap-1.5 font-semibold text-sm`,children:[(0,J.jsx)(Jv,{className:`w-4 h-4`}),` Tasks`]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>void t.reload(),className:`text-[10px] uppercase tracking-wide text-gray-400 hover:text-gray-100`,children:`Refresh`})]}),a.length>1&&(0,J.jsx)(II,{chips:a,active:n,onPick:r}),t.error&&(0,J.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] bg-red-900/40 border-b border-red-800 text-red-100 flex-shrink-0`,children:t.error}),(0,J.jsx)(`div`,{className:`flex-1 overflow-x-auto overflow-y-hidden`,children:t.tasks===null?(0,J.jsx)(`div`,{className:`flex items-center justify-center text-gray-500 py-8 h-full`,children:(0,J.jsx)(db,{className:`w-4 h-4 animate-spin`})}):(0,J.jsx)(`div`,{className:`flex gap-1.5 p-2 h-full items-stretch`,children:fI.map(e=>(0,J.jsx)(yI,{column:e,tasks:(i??[]).filter(t=>t.status===e.status).sort((t,n)=>e.status===`done`?n.createdAt-t.createdAt:t.createdAt-n.createdAt),busyId:t.busyId,compact:!0,onAddTask:r=>void t.addTaskInColumn({...r,project:r.project??n},e.status),projects:t.projects,workerRoles:MI,agentNames:t.agentNames,allTasks:t.tasks??[],onPatchTask:t.patchTask,onDragStart:o.onDragStart,onDragEnd:o.onDragEnd,onDrop:o.onDrop},e.status))})})]})}function yI({column:e,tasks:t,allTasks:n,busyId:r,compact:i,onAddTask:a,onPatchTask:o,projects:s,workerRoles:c,agentNames:l,onDragStart:u,onDragEnd:d,onDrop:f}){let[p,m]=(0,S.useState)(!1),[h,g]=(0,S.useState)(!1);return(0,J.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-[160px] rounded-lg border transition-colors ${h?`border-blue-500/60 bg-gray-900/80`:e.color}`,onDragOver:e=>{e.preventDefault(),g(!0)},onDragLeave:()=>g(!1),onDrop:t=>{t.preventDefault(),g(!1),f(t,e.status)},children:[(0,J.jsxs)(`header`,{className:`px-2 py-1.5 border-b border-gray-800/60 flex items-center gap-1.5 sticky top-0`,children:[(0,J.jsx)(`span`,{className:`w-2 h-2 rounded-full ${e.dot}`}),(0,J.jsx)(`span`,{className:`${i?`text-[11px]`:`text-xs`} font-medium`,children:e.label}),(0,J.jsx)(`span`,{className:`ml-auto ${i?`text-[10px]`:`text-[11px]`} text-gray-500`,children:t.length}),e.status===`ready`&&(0,J.jsx)(`button`,{type:`button`,title:`Add task`,onClick:()=>m(!0),className:`p-0.5 text-gray-600 hover:text-gray-200 rounded`,children:(0,J.jsx)(Zw,{className:`w-3 h-3`})})]}),(0,J.jsxs)(`ul`,{className:`flex-1 overflow-y-auto p-1.5 space-y-1.5 min-h-[40px]`,children:[t.map(e=>(0,J.jsx)(xI,{task:e,meta:bI(e,n),busy:r===e.id,compact:i,agentNames:l,onDragStart:u,onDragEnd:d,onPatch:o},e.id)),p&&(0,J.jsx)(NI,{projects:s,workerRoles:c,allTasks:n,onSubmit:e=>{a(e),m(!1)},onCancel:()=>m(!1)}),!p&&t.length===0&&(0,J.jsx)(`li`,{className:`text-center text-[10px] text-gray-600 py-3 ${e.status===`ready`?`cursor-pointer hover:text-gray-400`:``}`,onClick:e.status===`ready`?()=>m(!0):void 0,children:e.status===`ready`?`empty - click to add`:`empty`})]})]})}function bI(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[];for(let t of e.dependsOn??[]){let e=n.get(t);e&&(r.push(e),e.status!==`done`&&i.push(e))}let a=(e.dependsOn?.length??0)-r.length;return{deps:r,pendingDeps:i,blocked:e.status===`ready`&&(i.length>0||a>0)}}function xI({task:e,meta:t,busy:n,compact:r,agentNames:i,onDragStart:a,onDragEnd:o,onPatch:s}){let[c,l]=(0,S.useState)(!1),u=!!e.description?.trim()||!!e.resultSummary?.trim()||t.deps.length>0||!!e.sessionId||e.status===`in_progress`;return(0,J.jsxs)(`li`,{draggable:!0,onDragStart:t=>{t.currentTarget.style.opacity=`0.4`,a(t,e.id)},onDragEnd:e=>{e.currentTarget.style.opacity=`1`,o()},onClick:e=>{e.stopPropagation(),u&&l(e=>!e)},className:`rounded border bg-gray-900/60 hover:border-gray-700 ${t.blocked?`border-indigo-500/40`:`border-gray-800`} ${u?`cursor-pointer`:`cursor-grab`} ${n?`opacity-60`:``}`,children:[(0,J.jsxs)(`div`,{className:`px-2 py-1.5 flex items-start gap-1.5`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[(0,J.jsx)(`span`,{className:`${r?`text-[11.5px]`:`text-xs`} font-medium text-gray-100 break-words`,children:e.title}),e.priority>0&&(0,J.jsxs)(`span`,{className:`text-[9px] px-1 rounded bg-amber-900/50 text-amber-100`,children:[`p`,e.priority]}),e.workerAgentId&&(0,J.jsxs)(`span`,{className:`text-[9px] px-1 rounded bg-indigo-900/50 text-indigo-100`,title:`Assigned to ${e.workerAgentId} (slug)`,children:[`@`,i.get(e.workerAgentId)??e.workerAgentId]}),!e.workerAgentId&&e.workerRole&&(0,J.jsx)(`span`,{className:`text-[9px] px-1 rounded bg-gray-800 text-gray-400`,title:`Legacy: dispatched by kind, not pinned to a slug`,children:e.workerRole}),e.project&&e.project!==dI&&(0,J.jsxs)(`span`,{className:`text-[9px] px-1 rounded bg-gray-800 text-gray-400`,children:[`#`,e.project]}),(e.dependsOn?.length??0)>0&&(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-[9px] px-1 rounded border ${t.blocked?`text-indigo-200 bg-indigo-500/15 border-indigo-500/40`:`text-gray-400 bg-gray-700/30 border-gray-700`}`,title:t.blocked?`Waiting on: ${t.pendingDeps.map(e=>e.title).join(`, `)}`:`${t.deps.length} dependenc${t.deps.length===1?`y`:`ies`} satisfied`,children:[t.blocked?(0,J.jsx)(bb,{className:`w-2.5 h-2.5`}):(0,J.jsx)(Hy,{className:`w-2.5 h-2.5`}),t.blocked?`${t.pendingDeps.length}/${e.dependsOn.length}`:e.dependsOn.length]})]}),(e.labels??[]).includes(`awaiting-intervention`)&&(0,J.jsxs)(`div`,{className:`mt-1 flex items-start gap-1 rounded border border-rose-500/50 bg-rose-500/10 px-1.5 py-1 text-[10px] text-rose-200`,title:e.interventionReason??e.failureReason??``,onClick:e=>e.stopPropagation(),children:[(0,J.jsx)(OM,{className:`w-3 h-3 mt-px shrink-0`}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1 break-words line-clamp-3`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:`awaiting intervention`}),e.interventionAt?` (${VI(e.interventionAt)})`:``,e.interventionReason??e.failureReason?`: ${e.interventionReason??e.failureReason}`:``]}),(0,J.jsx)(`button`,{type:`button`,disabled:n,onClick:t=>{t.stopPropagation(),s(e.id,{labels:(e.labels??[]).filter(e=>e!==`awaiting-intervention`&&e!==`stalled`),attempts:0,failureReason:null,interventionReason:null,interventionAt:null})},className:`shrink-0 rounded border border-rose-500/40 px-1 py-px text-[9.5px] font-medium text-rose-100 hover:bg-rose-500/20 disabled:opacity-50`,children:`Retry`})]}),(e.labels??[]).includes(`stalled`)&&(0,J.jsxs)(`div`,{className:`mt-1 flex items-start gap-1 rounded border border-orange-500/40 bg-orange-500/5 px-1.5 py-1 text-[10px] text-orange-200`,title:e.failureReason??``,onClick:e=>e.stopPropagation(),children:[(0,J.jsx)(OM,{className:`w-3 h-3 mt-px shrink-0`}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1 break-words line-clamp-3`,children:[`stalled`,(e.attempts??0)>0?` after ${e.attempts} attempts`:``,e.failureReason?`: ${e.failureReason}`:``]}),(0,J.jsx)(`button`,{type:`button`,disabled:n,onClick:t=>{t.stopPropagation(),s(e.id,{labels:(e.labels??[]).filter(e=>e!==`stalled`),attempts:0,failureReason:null})},className:`shrink-0 rounded border border-orange-500/40 px-1 py-px text-[9.5px] font-medium text-orange-100 hover:bg-orange-500/15 disabled:opacity-50`,children:`Retry`})]}),(e.labels??[]).includes(`draft`)&&(0,J.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5`,onClick:e=>e.stopPropagation(),children:[(0,J.jsx)(`span`,{className:`inline-block rounded border border-yellow-500/40 bg-yellow-500/5 px-1.5 py-px text-[10px] text-yellow-200`,children:`draft - pool will skip`}),(0,J.jsx)(`button`,{type:`button`,disabled:n,onClick:t=>{t.stopPropagation(),s(e.id,{labels:(e.labels??[]).filter(e=>e!==`draft`)})},className:`rounded border border-yellow-500/40 px-1 py-px text-[9.5px] font-medium text-yellow-100 hover:bg-yellow-500/15 disabled:opacity-50`,children:`Publish`})]}),e.description&&!c&&(0,J.jsx)(`div`,{className:`text-[10.5px] text-gray-400 mt-0.5 line-clamp-2 whitespace-pre-line`,children:e.description}),e.resultSummary&&!c&&(0,J.jsxs)(`div`,{className:`${r?`text-[10px]`:`text-[10.5px]`} text-emerald-300/80 mt-0.5 italic line-clamp-2 whitespace-pre-line`,children:[`→ `,e.resultSummary]}),(0,J.jsxs)(`div`,{className:`text-[9.5px] text-gray-500 mt-0.5 flex items-center gap-1`,children:[(0,J.jsx)(_d,{className:`w-2.5 h-2.5`}),hI(e.endedAt??e.startedAt??e.createdAt)]})]}),u&&(0,J.jsx)(Fl,{className:`w-3 h-3 mt-0.5 text-gray-500 shrink-0 transition-transform ${c?`rotate-180`:``}`}),n&&(0,J.jsx)(db,{className:`w-3 h-3 animate-spin text-gray-400`})]}),c&&(0,J.jsxs)(`div`,{className:`px-2 pb-2 pt-0 border-t border-gray-800/60 space-y-1.5`,onClick:e=>e.stopPropagation(),children:[e.description&&(0,J.jsx)(AI,{label:`Description`,children:(0,J.jsx)(`div`,{className:`text-[10.5px] text-gray-300 whitespace-pre-line break-words max-h-48 overflow-y-auto`,children:e.description})}),e.resultSummary&&(0,J.jsx)(AI,{label:`Result`,children:(0,J.jsxs)(`div`,{className:`text-[10.5px] text-emerald-300/90 italic whitespace-pre-line break-words max-h-48 overflow-y-auto`,children:[`→ `,e.resultSummary]})}),e.resultFiles.length>0&&(0,J.jsx)(AI,{label:`Files (${e.resultFiles.length})`,children:(0,J.jsx)(`ul`,{className:`space-y-0.5`,children:e.resultFiles.map(e=>(0,J.jsx)(`li`,{children:(0,J.jsx)(jI,{path:e})},e))})}),t.deps.length>0&&(0,J.jsx)(AI,{label:`Depends on`,children:(0,J.jsx)(`ul`,{className:`space-y-0.5`,children:t.deps.map(e=>(0,J.jsxs)(`li`,{className:`text-[10px] flex items-center gap-1`,children:[e.status===`done`?(0,J.jsx)(W,{className:`w-2.5 h-2.5 text-emerald-400 shrink-0`}):(0,J.jsx)(bb,{className:`w-2.5 h-2.5 text-indigo-400 shrink-0`}),(0,J.jsx)(`span`,{className:`truncate ${e.status===`done`?`text-gray-400 line-through`:`text-indigo-200`}`,children:e.title}),(0,J.jsx)(`span`,{className:`ml-auto text-[9px] text-gray-600 shrink-0`,children:e.status.replace(`_`,` `)})]},e.id))})}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-0 text-[9.5px] text-gray-500 pt-1`,children:[(0,J.jsxs)(`div`,{children:[`Created`,(0,J.jsx)(`span`,{className:`text-gray-300`,children:new Date(e.createdAt).toLocaleString()})]}),e.startedAt&&(0,J.jsxs)(`div`,{children:[`Started`,(0,J.jsx)(`span`,{className:`text-gray-300`,children:new Date(e.startedAt).toLocaleString()})]}),e.endedAt&&(0,J.jsxs)(`div`,{children:[`Ended`,(0,J.jsx)(`span`,{className:`text-gray-300`,children:new Date(e.endedAt).toLocaleString()})]})]}),(0,J.jsx)(SI,{task:e})]})]})}function SI({task:e}){let[t,n]=(0,S.useState)(!1);return e.status===`in_progress`||e.sessionId?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`pt-1`,children:(0,J.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),n(!0)},className:`inline-flex items-center gap-1.5 rounded border border-gray-700 px-1.5 py-0.5 text-[10px] text-gray-300 hover:border-gray-500 hover:bg-gray-800`,children:[(0,J.jsx)(aD,{className:`w-3 h-3`}),`View transcript`,e.status===`in_progress`&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-300`,children:[(0,J.jsx)(`span`,{className:`w-1 h-1 rounded-full bg-amber-400 animate-pulse`}),`live`]})]})}),t&&(0,J.jsx)(CI,{task:e,onClose:()=>n(!1)})]}):null}function CI({task:e,onClose:t}){let{Modal:n}=_F(),[r,i]=(0,S.useState)(null),[a,o]=(0,S.useState)(!1),[s,c]=(0,S.useState)(null),[l,u]=(0,S.useState)(null),d=(0,S.useRef)(null),f=(0,S.useRef)(!0),p=(0,S.useCallback)(async()=>{if(e.id){o(!0);try{let t=await pI(`${uI}/tasks/${e.id}/history`);i(t.entries??[]),u(t.sessionId??null),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(!1)}}},[e.id]);(0,S.useEffect)(()=>{p()},[p]),(0,S.useEffect)(()=>{if(e.status!==`in_progress`)return;let t=setInterval(()=>void p(),3e3);return()=>clearInterval(t)},[e.status,p]),(0,S.useEffect)(()=>{if(!f.current)return;let e=d.current;e&&(e.scrollTop=e.scrollHeight)},[r]);let m=e=>{let t=e.currentTarget;f.current=t.scrollHeight-t.scrollTop-t.clientHeight<80},h=(0,S.useMemo)(()=>wI(r??[]),[r]);return(0,J.jsx)(n,{isOpen:!0,onClose:t,title:e.title,size:`lg`,className:`h-[80vh] bg-gray-950`,children:(0,J.jsxs)(`div`,{className:`flex h-full flex-col`,onDragStart:e=>e.stopPropagation(),children:[(0,J.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-gray-800 px-4 py-2 text-[10px] text-gray-500`,children:[(0,J.jsx)(aD,{className:`h-3.5 w-3.5 text-gray-500`}),(0,J.jsx)(`span`,{children:`worker transcript`}),l&&(0,J.jsxs)(`span`,{className:`font-mono text-gray-600`,children:[`· `,l]}),e.status===`in_progress`&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-300`,children:[`·`,(0,J.jsx)(`span`,{className:`h-1.5 w-1.5 animate-pulse rounded-full bg-amber-400`}),`tailing`]}),(0,J.jsx)(`div`,{className:`ml-auto`,children:(0,J.jsx)(`button`,{type:`button`,onClick:()=>void p(),disabled:a,className:`rounded p-1 text-gray-400 hover:bg-gray-800 hover:text-gray-200 disabled:opacity-50`,title:`Refresh`,children:(0,J.jsx)(ZT,{className:`h-3.5 w-3.5 ${a?`animate-spin`:``}`})})})]}),(0,J.jsxs)(`div`,{ref:d,onScroll:m,className:`flex-1 space-y-3 overflow-y-auto p-4`,children:[s&&(0,J.jsx)(`div`,{className:`rounded border border-rose-700/40 bg-rose-950/30 px-3 py-2 text-xs text-rose-200`,children:s}),r===null&&a&&(0,J.jsx)(`div`,{className:`text-xs italic text-gray-500`,children:`Loading…`}),r!==null&&h.length===0&&!a&&(0,J.jsx)(`div`,{className:`text-xs italic text-gray-500`,children:e.sessionId?`No messages yet.`:`Worker hasn't started yet.`}),h.map(e=>(0,J.jsx)(TI,{row:e},e.id))]})]})})}function wI(e){let t=new Map;for(let n of e)n.role===`tool`&&n.toolResult?.callId&&t.set(n.toolResult.callId,n.toolResult);let n=[];for(let r of e){if(r.role===`tool`)continue;let e=(r.toolCalls??[]).map(e=>({call:e,result:t.get(e.callId)}));n.push({id:r.id,createdAt:r.createdAt,role:r.role===`user`?`user`:r.role===`assistant`?`assistant`:`system`,text:r.text,calls:e})}return n}function TI({row:e}){let t=e.role===`user`;return(0,J.jsx)(`div`,{className:t?`flex justify-end`:`flex justify-start`,children:(0,J.jsxs)(`div`,{className:`flex max-w-[85%] flex-col ${t?`items-end`:`items-start`}`,children:[(0,J.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-gray-500`,children:[t?(0,J.jsx)(wN,{className:`h-3 w-3`}):(0,J.jsx)(js,{className:`h-3 w-3 text-blue-400`}),(0,J.jsx)(`span`,{children:t?`you`:e.role}),(0,J.jsx)(`span`,{className:`text-gray-700`,children:`·`}),(0,J.jsx)(`span`,{className:`text-gray-600`,children:new Date(e.createdAt).toLocaleTimeString()})]}),e.text&&(0,J.jsx)(`div`,{className:`whitespace-pre-line break-words rounded-lg border px-3 py-2 text-[13px] leading-relaxed ${t?`border-brand-400/30 bg-brand-500/10 text-gray-100`:`border-gray-800 bg-gray-900/60 text-gray-100`}`,children:e.text}),e.calls.length>0&&(0,J.jsx)(`div`,{className:`mt-1.5 flex flex-col gap-1 ${t?`items-end`:`items-start`}`,children:e.calls.map((e,t)=>(0,J.jsx)(EI,{...e},e.call.callId||`c${t}`))})]})})}function EI({call:e,result:t}){let[n,r]=(0,S.useState)(!1),i=!t,a=!!t&&t.ok===!1;return(0,J.jsxs)(`div`,{className:`flex flex-col`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>!i&&r(e=>!e),className:`flex select-none items-center gap-1.5 py-0.5 text-xs ${i?`cursor-default text-gray-500`:`cursor-pointer text-gray-500 hover:text-gray-300`}`,children:[i?(0,J.jsx)(db,{className:`h-3 w-3 animate-spin text-amber-400`}):a?(0,J.jsx)(Lu,{className:`h-3 w-3 text-rose-400/70`}):(0,J.jsx)(W,{className:`h-3 w-3 text-emerald-500/60`}),(0,J.jsx)(`code`,{className:`font-mono text-[12px] text-blue-300`,children:e.toolName}),(0,J.jsx)(`span`,{className:`font-mono text-[11px] text-gray-600`,children:DI(e.argsJson)}),i?(0,J.jsx)(`span`,{className:`text-[11px] text-gray-600`,children:`running…`}):n?(0,J.jsx)(Fl,{className:`h-3 w-3 text-gray-600`}):(0,J.jsx)(zl,{className:`h-3 w-3 text-gray-600`})]}),n&&t&&(0,J.jsx)(`pre`,{className:`mt-1 max-h-64 max-w-2xl overflow-auto whitespace-pre-wrap break-all rounded-md border px-3 py-2 text-[11px] ${a?`border-rose-700/40 bg-rose-950/30 text-rose-200`:`border-gray-800/60 bg-gray-900/60 text-gray-300`}`,children:kI(t.text||`(empty)`,4e3)})]})}function DI(e){if(!e)return`()`;let t;try{t=JSON.parse(e)}catch{return e.length>60?`(${e.slice(0,57)}…)`:`(${e})`}if(!t||typeof t!=`object`)return`(${e})`;let n=t,r=Object.keys(n);return r.length===0?`()`:r.slice(0,3).map(e=>`${e}=${OI(n[e])}`).join(` `)}function OI(e){return typeof e==`string`?e.length>40?`"${e.slice(0,37)}…"`:`"${e}"`:typeof e==`number`||typeof e==`boolean`||e==null?String(e):JSON.stringify(e).slice(0,40)}function kI(e,t){return e.length<=t?e:e.slice(0,t-1)+`
31
31
  …(truncated)`}function AI({label:e,children:t}){return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-[9px] uppercase tracking-wide text-gray-500 mb-0.5`,children:e}),t]})}function jI({path:e}){let t=mF(),n=e.replace(/^workspace:\/\/+/,`/`),r=n.split(`/`).filter(Boolean).pop()||n;return(0,J.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),t(n)},className:`inline-flex items-center gap-1 max-w-full text-[10.5px] font-mono text-emerald-300 hover:text-emerald-200 hover:underline truncate`,title:n,children:[(0,J.jsx)(Qm,{className:`w-3 h-3 shrink-0 opacity-70`}),(0,J.jsx)(`span`,{className:`truncate`,children:r})]})}var MI=[`echo`,`qianliyan`,`luban`,`xihe`,`nvwa`];function NI({projects:e,workerRoles:t,allTasks:n,onSubmit:r,onCancel:i}){let[a,o]=(0,S.useState)(``),[s,c]=(0,S.useState)(``),[l,u]=(0,S.useState)(``),[d,f]=(0,S.useState)(0),[p,m]=(0,S.useState)(``),[h,g]=(0,S.useState)([]),[_,v]=(0,S.useState)(!1),y=(0,S.useRef)(null);(0,S.useEffect)(()=>{y.current?.focus()},[]);let b=()=>{let e=a.trim();if(!e){i();return}r({title:e,description:s.trim()||void 0,project:l.trim()||void 0,priority:d||void 0,workerRole:p.trim()||void 0,dependsOn:h.length>0?h:void 0})};return(0,J.jsxs)(`li`,{className:`rounded border border-blue-500/50 bg-gray-900/70 p-1.5 space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`input`,{ref:y,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.keyCode===229||(e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),b()):e.key===`Escape`&&i())},placeholder:`Task title...`,className:`flex-1 min-w-0 bg-gray-800 border border-gray-700 rounded px-2 py-1 text-[11.5px] text-gray-100 outline-none focus:border-blue-500`}),(0,J.jsx)(`button`,{type:`button`,title:_?`Less`:`More fields`,onClick:()=>v(e=>!e),className:`p-0.5 text-gray-500 hover:text-gray-200`,children:(0,J.jsx)(Fl,{className:`w-3 h-3 transition-transform ${_?`rotate-180`:``}`})}),(0,J.jsx)(`button`,{type:`button`,onClick:i,className:`p-0.5 text-gray-500 hover:text-gray-200`,title:`Cancel`,children:(0,J.jsx)(IP,{className:`w-3 h-3`})})]}),_&&(0,J.jsxs)(`div`,{className:`space-y-2 pt-0.5`,children:[(0,J.jsx)(PI,{label:`Description`,children:(0,J.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`Optional notes for the worker...`,rows:2,className:`w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-[11px] text-gray-100 outline-none focus:border-blue-500 resize-y`})}),(0,J.jsx)(PI,{label:`Project`,children:(0,J.jsx)(`input`,{list:`workboard-add-projects`,value:l,onChange:e=>u(e.target.value),placeholder:`inbox`,className:`w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-[11px] text-gray-100 outline-none focus:border-blue-500`})}),(0,J.jsxs)(`div`,{className:`grid grid-cols-[1fr_72px] gap-2`,children:[(0,J.jsx)(PI,{label:`Worker`,children:(0,J.jsx)(`input`,{list:`workboard-add-roles`,value:p,onChange:e=>m(e.target.value),placeholder:`any`,className:`w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-[11px] text-gray-100 outline-none focus:border-blue-500`})}),(0,J.jsx)(PI,{label:`Priority`,children:(0,J.jsx)(`input`,{type:`number`,value:d,onChange:e=>f(Number(e.target.value)||0),className:`w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-[11px] text-gray-100 outline-none focus:border-blue-500`})})]}),(0,J.jsx)(PI,{label:`Depends on`,children:(0,J.jsx)(FI,{value:h,onChange:g,candidates:n,project:l})}),(0,J.jsx)(`datalist`,{id:`workboard-add-roles`,children:t.map(e=>(0,J.jsx)(`option`,{value:e},e))}),(0,J.jsx)(`datalist`,{id:`workboard-add-projects`,children:e.map(e=>(0,J.jsx)(`option`,{value:e.project},e.project))})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 pt-1`,children:[(0,J.jsx)(`span`,{className:`text-[9.5px] text-gray-600 truncate`,children:_?`Enter saves`:`Enter · Esc cancel`}),(0,J.jsx)(`button`,{type:`button`,onClick:b,disabled:!a.trim(),className:`ml-auto px-2.5 py-0.5 text-[10.5px] rounded bg-blue-700 hover:bg-blue-600 text-white disabled:opacity-50 disabled:cursor-not-allowed`,children:`Add`})]})]})}function PI({label:e,children:t}){return(0,J.jsxs)(`label`,{className:`block`,children:[(0,J.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-gray-500 mb-0.5`,children:e}),t]})}function FI({value:e,onChange:t,candidates:n,project:r,excludeId:i}){let a=(0,S.useMemo)(()=>new Map(n.map(e=>[e.id,e])),[n]),o=(0,S.useMemo)(()=>{let t=(r??``).trim();return n.filter(n=>n.id===i||e.includes(n.id)?!1:t?t===dI?!n.project||n.project===dI:n.project===t:!0)},[n,r,e,i]),s=n=>t(e.filter(e=>e!==n)),c=n=>{!n||e.includes(n)||t([...e,n])};return(0,J.jsxs)(`div`,{className:`space-y-1`,children:[e.length>0&&(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let t=a.get(e),n=t?t.title:`${e.slice(0,6)}... (deleted)`,r=t?.status===`done`;return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded border ${r?`text-emerald-200 bg-emerald-500/10 border-emerald-500/30`:`text-indigo-200 bg-indigo-500/15 border-indigo-500/40`}`,title:t?`${t.status} · ${t.id}`:e,children:[r?(0,J.jsx)(W,{className:`w-2.5 h-2.5`}):(0,J.jsx)(bb,{className:`w-2.5 h-2.5`}),(0,J.jsx)(`span`,{className:`truncate max-w-[140px]`,children:n}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>s(e),className:`text-gray-400 hover:text-gray-100`,title:`Remove`,children:(0,J.jsx)(IP,{className:`w-2.5 h-2.5`})})]},e)})}),(0,J.jsxs)(`select`,{value:``,onChange:e=>{e.target.value&&(c(e.target.value),e.target.value=``)},className:`w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-[11px] text-gray-100 outline-none focus:border-blue-500`,children:[(0,J.jsx)(`option`,{value:``,children:o.length===0?e.length===0?`(no other tasks)`:`(no more candidates)`:`Add prerequisite...`}),o.map(e=>(0,J.jsxs)(`option`,{value:e.id,children:[`[`,e.status,`] `,e.title]},e.id))]})]})}function II({chips:e,active:t,onPick:n,showAll:r,rightExtras:i}){return(0,J.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5 border-b border-gray-800 bg-gray-950/40 overflow-x-auto scrollbar-none flex-shrink-0`,children:[r&&(0,J.jsx)(LI,{active:!t,label:`All`,count:e.reduce((e,t)=>e+t.count,0),onClick:()=>n(``)}),e.map(e=>(0,J.jsx)(LI,{active:t===e.key,label:e.label,count:e.count,onClick:()=>n(t===e.key?``:e.key)},e.key||`all`)),i]})}function LI({active:e,label:t,count:n,onClick:r}){return(0,J.jsxs)(`button`,{onClick:r,className:[`shrink-0 inline-flex items-center gap-1 rounded-full text-[11px] transition-colors px-2.5 py-0.5`,e?`bg-blue-500/20 border border-blue-400/50 text-blue-200`:`text-gray-400 hover:text-gray-200 hover:bg-gray-800/60 border border-transparent`].join(` `),children:[(0,J.jsx)(`span`,{children:t}),(0,J.jsx)(`span`,{className:e?`text-blue-300/80`:`text-gray-600`,children:n})]})}function RI(e){let[t,n]=(0,S.useState)(null),r=(0,S.useCallback)(async()=>{try{n(await pI(`${uI}/workers/status`))}catch{n(null)}},[]);(0,S.useEffect)(()=>{r();let e=window.setInterval(()=>void r(),5e3);return()=>window.clearInterval(e)},[r]);let i=t?.workers??[],a=i.filter(e=>e.busy).length;return(0,J.jsxs)(`div`,{className:`px-3 py-2`,children:[(0,J.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,J.jsx)(RP,{size:14,className:`flex-shrink-0 text-gray-600`}),(0,J.jsx)(`span`,{className:`flex-1 text-sm font-medium text-gray-300`,children:`Workers`}),(0,J.jsxs)(`span`,{className:`rounded bg-gray-800 px-1.5 py-0.5 text-[9px] text-gray-600`,children:[a,`/`,i.length,` busy`]})]}),(0,J.jsx)(`div`,{className:`space-y-1.5`,children:i.length===0?(0,J.jsx)(`div`,{className:`text-[10px] text-gray-600 px-1`,children:`No workers running. Toggle echo on under Settings → Plugins → Workboard.`}):i.map(e=>(0,J.jsx)(zI,{name:e.name,kind:e.kind,busy:e.busy},e.agentId))})]})}function zI({name:e,kind:t,busy:n}){let r=BI(t);return(0,J.jsxs)(`div`,{className:`flex cursor-default items-center gap-2 rounded py-0.5 pl-1 hover:bg-gray-700/30`,title:`Agent: ${e}\nWorker type: ${t}`,children:[(0,J.jsx)(`span`,{className:`w-5 flex-shrink-0 text-center text-base`,children:r}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`truncate text-xs font-medium text-gray-200`,children:e}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:`truncate rounded bg-gray-800/80 px-1 py-px font-mono text-[9px] font-semibold uppercase tracking-wide text-gray-400`,children:t}),(0,J.jsx)(`span`,{className:`rounded px-1 py-px text-[9px] ${n?`bg-blue-900/40 text-blue-100 border border-blue-700`:`bg-gray-800/60 text-gray-600`}`,children:n?`busy`:`idle`})]})]})]})}function BI(e){return e===`echo`?`🔁`:`⚙️`}function VI(e){let t=Math.max(0,Date.now()-e),n=Math.round(t/1e3);if(n<60)return`${n}s ago`;let r=Math.round(n/60);if(r<60)return`${r}m ago`;let i=Math.round(r/60);return i<24?`${i}h ago`:`${Math.round(i/24)}d ago`}var HI={components:{WorkboardPanel:vI,WorkersSidebarSection:RI,WorkerAgentsPage:aI}};HI.components;var UI=Object.assign({"../../../../plugins/files/manifest.json":nF,"../../../../plugins/microsandbox/manifest.json":rF,"../../../../plugins/web-search/manifest.json":iF,"../../../../plugins/workboard/manifest.json":aF}),WI=Object.assign({"../../../../plugins/files/dist/client.js":LF,"../../../../plugins/microsandbox/dist/client.js":iI,"../../../../plugins/workboard/dist/client.js":HI}),GI=(()=>{let e={},t=/\/plugins\/([^/]+)\/manifest\.json$/,n=/\/plugins\/([^/]+)\/dist\/client\.js$/,r=new Map;for(let[e,t]of Object.entries(WI)){let i=n.exec(e);i&&r.set(i[1],t)}for(let[n,i]of Object.entries(UI)){let a=t.exec(n);if(!a)continue;let o=a[1],s=i?.client?.entry;if(!s)continue;let c=r.get(o);c&&(e[s]=c)}return e})();function KI(e,t){if(!e)return null;let n=GI[e];return n?n.components[t]??null:null}function qI({anchor:e,fallback:t}){let n=gr(e=>e.plugins);if(!n)return null;let r=[];for(let t of n){if(t.state!==`active`)continue;let n=t.contributes.sidebarSections??[];for(let i of n){if((i.after??``)!==e)continue;let n=t.clientEntry,a=KI(n,i.component);a&&r.push({pluginId:t.id,contribId:i.id,Component:a,order:i.order??100})}}if(r.sort((e,t)=>e.order-t.order),r.length===0)return(0,J.jsx)(J.Fragment,{children:t??null});let i={tenantId:``,userId:``,plugin:{id:``,version:``,displayName:``},isCollapsed:!1,onToggleCollapse:()=>{}};return(0,J.jsx)(J.Fragment,{children:r.map(({pluginId:e,contribId:t,Component:n})=>(0,J.jsx)(n,{...i,plugin:{id:e,version:``,displayName:e}},`${e}.${t}`))})}var JI=[`en`,`zh`],YI={en:`English`,zh:`中文`},XI=`tianshu.locale`,ZI={en:{"auth.signOut":`Sign out`,"admin.title":`Settings`,"lang.label":`Language`,"user.role.member":`member`,"user.role.admin":`admin`,"user.role.dev":`dev`},zh:{"auth.signOut":`退出登录`,"admin.title":`设置`,"lang.label":`语言`,"user.role.member":`成员`,"user.role.admin":`管理员`,"user.role.dev":`开发者`}},QI=eL(),$I=new Set;function eL(){try{let e=window.localStorage.getItem(XI);if(e===`en`||e===`zh`)return e}catch{}return typeof navigator<`u`&&(navigator.language||``).toLowerCase().startsWith(`zh`)?`zh`:`en`}function tL(){return QI}function nL(){return JI}function rL(e){if(e!==QI){QI=e;try{window.localStorage.setItem(XI,e)}catch{}for(let e of $I)e()}}function iL(e){return $I.add(e),()=>$I.delete(e)}function aL(e){return ZI[QI][e]??ZI.en[e]??e}function oL(){return(0,S.useSyncExternalStore)(iL,tL,tL)}function sL(){return oL(),aL}function cL(){let e=M(e=>e.me)?.config.branding?.name??`Tianshu`;return(0,J.jsxs)(`aside`,{className:`flex h-full w-64 flex-shrink-0 flex-col border-r border-gray-800 bg-gray-900`,children:[(0,J.jsx)(`div`,{className:`flex h-12 items-center border-b border-gray-800 px-4`,children:(0,J.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e})}),(0,J.jsxs)(`div`,{className:`space-y-1 px-2 pt-2`,children:[(0,J.jsxs)(`div`,{className:`flex cursor-pointer items-center gap-2 rounded-lg bg-gray-800 px-3 py-2 text-white`,children:[(0,J.jsx)(js,{size:14,className:`flex-shrink-0 text-blue-400`}),(0,J.jsx)(`span`,{className:`text-sm font-medium`,children:e})]}),(0,J.jsx)(`div`,{"data-testid":`sidebar-workers-anchor`,children:(0,J.jsx)(qI,{anchor:`workers`})})]}),(0,J.jsx)(`div`,{className:`mx-3 my-2 border-b border-gray-800/50`}),(0,J.jsxs)(`nav`,{className:`flex-1 space-y-0.5 overflow-y-auto px-2`,children:[(0,J.jsx)(`div`,{className:`px-1 pb-1 pt-2 text-[10px] uppercase tracking-wider text-gray-600`,children:`Channels`}),(0,J.jsxs)(`div`,{className:`flex cursor-pointer items-center gap-2 rounded-lg bg-gray-800 px-3 py-1.5 text-white`,children:[(0,J.jsx)(B_,{size:12,className:`flex-shrink-0`}),(0,J.jsx)(`span`,{className:`flex-1 truncate text-xs`,children:`webchat`}),(0,J.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider text-gray-500`,children:`active`})]}),(0,J.jsx)(`p`,{className:`px-2 pt-2 text-[10px] leading-relaxed text-gray-600`,children:`Sessions are managed by the agent, not the user (ADR-0001 §5). Additional messaging channels (Lark / Slack / …) land later.`})]}),(0,J.jsx)(lL,{})]})}function lL(){let e=M(e=>e.me),t=sL(),n=oL(),r=nL(),i=e?.userId??`…`,a=i.slice(0,1).toUpperCase(),o=`${t(e?.devTenant?`user.role.dev`:`user.role.member`)} · ${e?.tenantId??``}`,[s,c]=(0,S.useState)(!1),[l,u]=(0,S.useState)(!1),d=(0,S.useRef)(null);return(0,S.useEffect)(()=>{if(!s)return;let e=e=>{d.current&&(d.current.contains(e.target)||(c(!1),u(!1)))},t=e=>{e.key===`Escape`&&(c(!1),u(!1))};return window.addEventListener(`mousedown`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e),window.removeEventListener(`keydown`,t)}},[s]),(0,J.jsxs)(`div`,{className:`relative border-t border-gray-800`,ref:d,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>c(e=>!e),"aria-haspopup":`menu`,"aria-expanded":s,title:i,className:`flex w-full items-center gap-2 px-3 py-2 hover:bg-gray-800/60 transition-colors`,children:[(0,J.jsx)(`div`,{className:`flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-full bg-gradient-to-br from-blue-500 to-purple-600 text-[10px] font-semibold text-white`,children:a}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1 text-left`,children:[(0,J.jsx)(`div`,{className:`truncate text-[11px] text-gray-300`,children:i}),(0,J.jsx)(`div`,{className:`truncate text-[10px] text-gray-600`,children:o})]}),(0,J.jsx)(Fl,{size:12,className:`text-gray-500 transition-transform ${s?`rotate-180`:``}`})]}),s&&(0,J.jsxs)(`div`,{role:`menu`,className:`absolute bottom-full left-2 right-2 z-50 mb-1 rounded-md border border-gray-700 bg-gray-900 py-1 text-[12px] shadow-xl`,children:[(0,J.jsxs)(`div`,{className:`border-b border-gray-800 px-3 py-2`,children:[(0,J.jsx)(`div`,{className:`truncate text-gray-200`,children:i}),(0,J.jsx)(`div`,{className:`truncate text-[10px] text-gray-600`,children:o})]}),(0,J.jsxs)(Fn,{to:`admin`,role:`menuitem`,onClick:()=>c(!1),className:`flex items-center gap-2 px-3 py-1.5 text-gray-200 hover:bg-gray-800`,children:[(0,J.jsx)(ND,{size:14,className:`text-gray-500`}),(0,J.jsx)(`span`,{children:t(`admin.title`)})]}),(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-haspopup":`menu`,"aria-expanded":l,onClick:()=>u(e=>!e),className:`flex w-full items-center gap-2 px-3 py-1.5 text-gray-200 hover:bg-gray-800`,children:[(0,J.jsx)(o_,{size:14,className:`text-gray-500`}),(0,J.jsx)(`span`,{className:`flex-1 text-left`,children:t(`lang.label`)}),(0,J.jsx)(`span`,{className:`text-[10px] text-gray-500`,children:YI[n]}),(0,J.jsx)(zl,{size:12,className:`text-gray-500 transition-transform ${l?`rotate-90`:``}`})]}),l&&(0,J.jsx)(`ul`,{role:`menu`,className:`border-y border-gray-800 bg-gray-950/60`,children:r.map(e=>{let t=e===n;return(0,J.jsxs)(`li`,{role:`menuitemradio`,"aria-checked":t,tabIndex:0,onClick:()=>{rL(e),u(!1)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),rL(e),u(!1))},className:`flex cursor-pointer items-center gap-2 py-1.5 pl-9 pr-3 outline-none ${t?`text-blue-300`:`text-gray-300 hover:bg-gray-800`}`,children:[(0,J.jsx)(`span`,{className:`flex-1`,children:YI[e]}),t&&(0,J.jsx)(El,{size:13,className:`text-blue-400`})]},e)})})]})]})}function uL(e){let t=[];for(let n of e){if(n.state!==`active`)continue;let e=n.contributes.attachmentRenderers??[];for(let r of e)t.push({...r,pluginId:n.id,pluginVersion:n.version,pluginDisplayName:n.displayName,clientEntry:n.clientEntry})}return t.sort((e,t)=>{let n=e.order??100,r=t.order??100;if(n!==r)return n-r;let i=`${e.pluginId}.${e.id}`,a=`${t.pluginId}.${t.id}`;return i<a?-1:+(i>a)}),t}function dL(e,t){let n=fL(t).toLowerCase(),r=e.toLowerCase();if(r===`*/*`)return!0;let i=r.indexOf(`/`);if(i<=0)return!1;let a=r.slice(0,i),o=r.slice(i+1),s=n.indexOf(`/`);if(s<=0)return!1;let c=n.slice(0,s),l=n.slice(s+1);return a===c?o===`*`||o===l:!1}function fL(e){let t=e.indexOf(`;`);return(t<0?e:e.slice(0,t)).trim()}function pL(e,t){for(let n of e)if(dL(n.mimePattern,t))return n;return null}var mL=1024,hL=mL*1024;function gL(e){return e==null?``:e<mL?`${e} B`:e<hL?`${(e/mL).toFixed(1)} KB`:`${(e/hL).toFixed(1)} MB`}function _L(e){return`/api/p/files/raw?path=${encodeURIComponent(e)}`}function vL(e){return{path:e.path,mimeType:e.mimeType,name:e.name,size:e.size}}function yL({attachments:e,align:t}){let n=M(e=>e.me),r=gr(e=>e.plugins);if(!e||e.length===0)return null;let i=r?uL(r):[],a=e.slice(0,8);return(0,J.jsx)(`div`,{className:`mt-1.5 flex max-w-full flex-wrap gap-1.5 ${t===`end`?`justify-end`:`justify-start`}`,children:a.map(e=>{let r=pL(i,e.mimeType);if(r&&n){let i=KI(r.clientEntry,r.component);if(i)return(0,J.jsx)(i,{tenantId:n.tenantId,userId:n.userId,plugin:{id:r.pluginId,version:r.pluginVersion,displayName:r.pluginDisplayName},attachment:vL(e),align:t,rawUrl:_L},e.path)}return(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-gray-800 bg-gray-900/60 px-2 py-1 text-xs text-gray-200`,title:e.path,children:[(0,J.jsx)(sh,{size:12,className:`text-gray-400`}),(0,J.jsx)(`span`,{className:`max-w-[12rem] truncate`,children:e.name??e.path}),(0,J.jsx)(`span`,{className:`text-[10px] text-gray-500`,children:gL(e.size)})]},e.path)})})}function bL({m:e}){let t=e.role===`user`,{MarkdownBlock:n}=_F(),r=!t&&e.resolvedBlocks&&e.resolvedBlocks.length>0?e.resolvedBlocks:null,i=e.text.length>0,a=e.resolvedToolCalls??[],o=!t&&!i&&a.length===0&&!r;return(0,J.jsx)(`div`,{className:t?`flex justify-end`:`flex justify-start`,children:(0,J.jsxs)(`div`,{className:`flex max-w-[85%] flex-col ${t?`items-end`:`items-start`}`,children:[(0,J.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5 text-[11px] uppercase tracking-wider text-gray-500`,children:[t?(0,J.jsx)(wN,{size:11}):(0,J.jsx)(js,{size:11,className:`text-blue-400`}),(0,J.jsx)(`span`,{children:t?`you`:`tianshu`})]}),r?(0,J.jsx)(`div`,{className:`flex flex-col gap-1.5 ${t?`items-end`:`items-start`}`,children:r.map((e,r)=>xL(e,r,t,n))}):(0,J.jsxs)(J.Fragment,{children:[i?(0,J.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none rounded-lg border px-3.5 py-2.5 text-[14px] leading-relaxed `+(t?`border-brand-400/30 bg-brand-500/10 text-gray-100`:`border-gray-800 bg-gray-900/60 text-gray-100`),children:(0,J.jsx)(n,{noProse:!0,children:e.text})}):o?(0,J.jsx)(`div`,{className:`rounded-lg border border-gray-800 bg-gray-900/60 px-3.5 py-2.5`,children:(0,J.jsx)(kL,{})}):null,a.length>0&&(0,J.jsx)(`div`,{className:`mt-1.5 flex flex-col gap-1 ${t?`items-end`:`items-start`}`,children:a.map(e=>(0,J.jsx)(TL,{call:e},e.id))})]}),t&&e.attachments&&e.attachments.length>0&&(0,J.jsx)(yL,{attachments:e.attachments,align:`end`}),!t&&(e.meta||e.createdAt)&&(0,J.jsx)(SL,{meta:e.meta,createdAt:e.createdAt,align:`start`})]})})}function xL(e,t,n,r){return e.kind===`text`?e.text.length===0?null:(0,J.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none rounded-lg border px-3.5 py-2.5 text-[14px] leading-relaxed `+(n?`border-brand-400/30 bg-brand-500/10 text-gray-100`:`border-gray-800 bg-gray-900/60 text-gray-100`),children:(0,J.jsx)(r,{noProse:!0,children:e.text})},`t${t}`):(0,J.jsx)(TL,{call:e},`c${t}-${e.id}`)}function SL({meta:e,createdAt:t,align:n}){let r=[];if(t&&r.push(CL(t)),e?.model&&r.push(e.model),e?.usage){let{input:t,output:n,totalTokens:i}=e.usage;if(r.push(`↓${wL(t)} ↑${wL(n)}`),e.contextWindow&&e.contextWindow>0){let t=Math.round(i/e.contextWindow*100);r.push(`${t}% ctx`)}}return r.length===0?null:(0,J.jsx)(`div`,{className:`mt-1 flex flex-wrap items-center gap-1.5 text-[10px] text-gray-600 ${n===`end`?`justify-end`:`justify-start`}`,children:r.map((e,t)=>(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[t>0&&(0,J.jsx)(`span`,{className:`text-gray-700`,children:`·`}),e]},t))})}function CL(e){let t=new Date(e);return`${t.getHours().toString().padStart(2,`0`)}:${t.getMinutes().toString().padStart(2,`0`)}`}function wL(e){return e>=1e6?(e/1e6).toFixed(1)+`m`:e>=1e3?(e/1e3).toFixed(1)+`k`:String(e)}function TL({call:e}){let[t,n]=(0,S.useState)(!1),r=!e.result,i=!!e.result&&!e.result.ok,a=e.result;return(0,J.jsxs)(`div`,{className:`flex flex-col`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>!r&&n(e=>!e),className:`flex select-none items-center gap-1.5 py-0.5 text-xs transition-colors `+(r?`cursor-default text-gray-500`:`cursor-pointer text-gray-500 hover:text-gray-300`),children:[r?(0,J.jsx)(db,{size:11,className:`animate-spin text-amber-400`}):i?(0,J.jsx)(Lu,{size:11,className:`text-rose-400/70`}):(0,J.jsx)(W,{size:11,className:`text-emerald-500/60`}),(0,J.jsx)(`code`,{className:`font-mono text-[12px] text-blue-300`,children:e.name}),(0,J.jsx)(`span`,{className:`font-mono text-[11px] text-gray-600`,children:EL(e.arguments)}),r?(0,J.jsx)(`span`,{className:`text-[11px] text-gray-600`,children:`running…`}):t?(0,J.jsx)(Fl,{size:11,className:`text-gray-600`}):(0,J.jsx)(zl,{size:11,className:`text-gray-600`})]}),t&&a&&(0,J.jsx)(`pre`,{className:`mt-1 max-h-64 max-w-2xl overflow-auto whitespace-pre-wrap break-all rounded-md border px-3 py-2 text-[11px] `+(i?`border-rose-700/40 bg-rose-950/30 text-rose-200`:`border-gray-800/60 bg-gray-900/60 text-gray-300`),children:OL(a.text,4e3)})]})}function EL(e){let t=Object.keys(e);return t.length===0?`()`:t.slice(0,3).map(t=>`${t}=${DL(e[t])}`).join(` `)}function DL(e){return typeof e==`string`?e.length>40?`"${e.slice(0,37)}…"`:`"${e}"`:typeof e==`number`||typeof e==`boolean`||e==null?String(e):JSON.stringify(e).slice(0,40)}function OL(e,t){return e.length<=t?e:e.slice(0,t-1)+`
32
- …(truncated)`}function kL(){return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1`,"aria-label":`assistant is typing`,children:[(0,J.jsx)(AL,{delay:`0ms`}),(0,J.jsx)(AL,{delay:`150ms`}),(0,J.jsx)(AL,{delay:`300ms`})]})}function AL({delay:e}){return(0,J.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-gray-500`,style:{animation:`tianshuTypingDot 1.2s ease-in-out infinite`,animationDelay:e}})}function jL(e){let t=new Map;for(let n of e)n.role===`tool`&&n.toolResult&&t.set(n.toolResult.callId,n.toolResult);let n=[];for(let r of e){if(r.role===`tool`)continue;if(r.role===`assistant`&&(r.toolCalls&&r.toolCalls.length>0||r.blocks&&r.blocks.length>0)){let e=(r.toolCalls??[]).map(e=>({...e,result:t.get(e.id)})),i=r.blocks?.map(e=>e.kind===`toolCall`?{...e,result:t.get(e.id)}:e),{toolCalls:a,toolResult:o,blocks:s,...c}=r;n.push({...c,resolvedToolCalls:e.length>0?e:void 0,resolvedBlocks:i});continue}let{toolCalls:e,toolResult:i,blocks:a,...o}=r;n.push(o)}return n}function ML(e){return`att-${e.toString(36)}-${Math.random().toString(36).slice(2,6)}`}var NL=ir((e,t)=>({attachments:[],transforms:[],_nextId:1,addAttachment:n=>{let r=t()._nextId,i=ML(r);return e(e=>({_nextId:e._nextId+1,attachments:[...e.attachments,{...n,id:i}]})),i},updateAttachment:(t,n)=>e(e=>{let r=e.attachments.findIndex(e=>e.id===t);if(r<0)return{};let i=e.attachments.slice();return i[r]={...i[r],...n},{attachments:i}}),removeAttachment:t=>e(e=>({attachments:e.attachments.filter(e=>e.id!==t)})),registerDraftTransform:t=>(e(e=>e.transforms.includes(t)?{}:{transforms:[...e.transforms,t]}),()=>{e(e=>({transforms:e.transforms.filter(e=>e!==t)}))}),clearAll:()=>e({attachments:[]}),hasPending:()=>t().attachments.some(e=>e.status===`uploading`),applyTransforms:async e=>{let{transforms:n,attachments:r}=t();if(n.length===0)return e;let i=r.filter(e=>e.status===`ready`),a=e;for(let e of n)a=await e(a,i);return a}}));function PL(){let e=NL.getState();return{get attachments(){return NL.getState().attachments},addAttachment:e.addAttachment,updateAttachment:e.updateAttachment,removeAttachment:e.removeAttachment,registerDraftTransform:e.registerDraftTransform}}var FL=l(h(),1);function IL(){let e=M(e=>e.models),t=M(e=>e.preferredModel),n=M(e=>e.setPreferredModel),r=M(e=>e.me?.defaultModel?.id??null),[i,a]=(0,S.useState)(!1),[o,s]=(0,S.useState)({top:0,right:0}),c=(0,S.useRef)(null),l=(0,S.useRef)(null),u=(0,S.useCallback)(()=>{if(!c.current)return;let e=c.current.getBoundingClientRect();s({top:e.top,right:window.innerWidth-e.right})},[]);if((0,S.useEffect)(()=>{if(!i)return;u();let e=e=>{let t=e.target;c.current?.contains(t)||l.current?.contains(t)||a(!1)},t=()=>u();return document.addEventListener(`mousedown`,e),window.addEventListener(`resize`,t),()=>{document.removeEventListener(`mousedown`,e),window.removeEventListener(`resize`,t)}},[i,u]),e.length===0)return null;let d=t=>!!t&&e.some(e=>e.id===t),f=d(t)?t:d(r)?r:e[0].id,p=e.find(e=>e.id===f)?.name??f.split(`/`).pop()??`Model`,m=[];for(let t of e){let e=t.group??`Other`,n=m.find(t=>t.label===e);n||(n={label:e,items:[]},m.push(n)),n.items.push(t)}let h=e=>{a(!1),e!==f&&n(e)};return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{ref:c,type:`button`,onClick:()=>a(e=>!e),className:`inline-flex items-center gap-1 rounded-full bg-gray-700/60 py-1 pl-2.5 pr-2 text-xs font-medium text-gray-300 transition-colors hover:bg-gray-700`,title:f,children:[(0,J.jsx)(`span`,{className:`max-w-[160px] truncate`,children:p}),(0,J.jsx)(Fl,{size:12,className:`text-gray-400 transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,FL.createPortal)((0,J.jsx)(`div`,{ref:l,className:`fixed z-[9999] max-h-80 w-64 overflow-y-auto rounded-xl border border-gray-700 bg-gray-800 py-1 shadow-2xl`,style:{bottom:`calc(100vh - ${o.top}px + 8px)`,right:`${o.right}px`},children:m.map(e=>(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`px-3 pb-1 pt-2.5 text-[10px] font-semibold uppercase tracking-wider text-gray-500`,children:e.label}),e.items.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>h(e.id),className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors `+(e.id===f?`bg-gray-700/60 text-white`:`text-gray-300 hover:bg-gray-700/40`),title:e.id,children:[(0,J.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),e.reasoning&&(0,J.jsx)(`span`,{className:`shrink-0 rounded bg-amber-500/15 px-1 py-px text-[9px] text-amber-300`,children:`reasoning`}),e.id===f&&(0,J.jsx)(El,{size:14,className:`shrink-0 text-blue-400`})]},e.id))]},e.label))}),document.body)]})}function LL(){let e=M(e=>e.me),t=gr(e=>e.plugins);if(!e||!t)return null;let n=[];for(let e of t){if(e.state!==`active`)continue;let t=e.contributes.composerActions??[];for(let r of t)n.push({...r,pluginId:e.id,pluginVersion:e.version,pluginDisplayName:e.displayName,clientEntry:e.clientEntry})}if(n.sort((e,t)=>(e.order??100)-(t.order??100)),n.length===0)return null;let r=PL();return(0,J.jsx)(J.Fragment,{children:n.map(t=>{let n=KI(t.clientEntry,t.component);return n?(0,J.jsx)(n,{tenantId:e.tenantId,userId:e.userId,plugin:{id:t.pluginId,version:t.pluginVersion,displayName:t.pluginDisplayName},composer:r},`${t.pluginId}.${t.id}`):null})})}var RL=1024,zL=RL*1024;function BL(e){return e<RL?`${e} B`:e<zL?`${(e/RL).toFixed(1)} KB`:`${(e/zL).toFixed(1)} MB`}function VL(){let e=NL(e=>e.attachments),t=NL(e=>e.removeAttachment);return e.length===0?null:(0,J.jsx)(`div`,{className:`flex flex-wrap gap-2 pb-1`,children:e.map(e=>{let n=e.status===`uploading`,r=e.status===`error`;return(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs `+(r?`border-rose-700/60 bg-rose-950/40 text-rose-200`:`border-gray-700 bg-gray-800 text-gray-200`),title:r?e.error??`upload failed`:e.path??e.name,"aria-label":`attachment ${e.name}`,children:[n?(0,J.jsx)(db,{size:12,className:`animate-spin text-brand-400`}):r?(0,J.jsx)(OM,{size:12,className:`text-rose-400`}):(0,J.jsx)(sh,{size:12,className:`text-gray-400`}),(0,J.jsx)(`span`,{className:`max-w-[12rem] truncate`,children:e.name}),(0,J.jsx)(`span`,{className:`text-[10px] text-gray-500`,children:BL(e.size)}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`ml-0.5 rounded p-0.5 text-gray-500 hover:bg-gray-700 hover:text-gray-200`,"aria-label":`remove attachment`,children:(0,J.jsx)(IP,{size:11})})]},e.id)})})}function HL(){let e=M(e=>e.isStreaming),t=M(e=>e.sendPrompt),n=M(e=>e.abort),r=NL(e=>e.attachments.length),i=NL(e=>e.hasPending()),a=NL(e=>e.applyTransforms),o=NL(e=>e.clearAll),[s,c]=(0,S.useState)(``),[l,u]=(0,S.useState)(!1),d=(0,S.useRef)(null);(0,S.useEffect)(()=>{let e=d.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,240)}px`)},[s]);let f=e?!0:l||i?!1:s.trim().length>0||r>0,p=async()=>{if(e){n();return}if(l||i)return;let d=s.trimEnd();if(!(!d&&r===0)){u(!0);try{let e=await a(d),n=NL.getState().attachments.filter(e=>e.status===`ready`&&!!e.path).map(e=>({path:e.path,mimeType:e.mimeType??`application/octet-stream`,name:e.name,size:e.size}));(e.trim().length>0||n.length>0)&&t(e,n.length>0?n:void 0),c(``),o()}finally{u(!1)}}};return(0,J.jsx)(`div`,{className:`border-t border-gray-800 bg-gray-950 px-4 py-3`,children:(0,J.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-2 rounded-2xl border border-gray-800 bg-gray-900 p-3 focus-within:border-gray-700`,children:[(0,J.jsx)(VL,{}),(0,J.jsx)(`textarea`,{ref:d,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),p())},rows:1,placeholder:`Message Tianshu — Enter to send, Shift+Enter for newline`,className:`resize-none bg-transparent text-[14px] leading-relaxed text-gray-100 placeholder:text-gray-500 focus:outline-none`}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,J.jsx)(LL,{})}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(IL,{}),e?(0,J.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-lg p-1.5 text-rose-400 transition-colors hover:bg-gray-700 hover:text-rose-300`,title:`Stop`,children:(0,J.jsx)(lA,{size:18})}):(0,J.jsx)(`button`,{type:`button`,onClick:()=>void p(),disabled:!f,className:`rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-700 hover:text-white disabled:cursor-not-allowed disabled:opacity-30`,title:i?`Waiting for uploads to finish…`:`Send`,"aria-label":`Send`,children:(0,J.jsx)(_D,{size:18})})]})]})]})})}function UL({open:e,onClose:t}){let n=gr(e=>e.plugins),r=gr(e=>e.setPlugins),i=gr(e=>e.load),a=gr(e=>e.refresh),o=gr(e=>e.refreshing),[s,c]=(0,S.useState)(`installed`),[l,u]=(0,S.useState)(null),[d,f]=(0,S.useState)(null),[p,m]=(0,S.useState)(null),[h,g]=(0,S.useState)(!1);if((0,S.useEffect)(()=>{e&&i()},[e,i]),(0,S.useEffect)(()=>{if(!e||s!==`catalog`||l!==null)return;let t=!1;return f(null),ur.pluginCatalog().then(e=>{t||u(e)}).catch(e=>{t||f(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e,s,l]),(0,S.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),!e)return null;async function _(e){let t=e.state!==`active`;m(e.id),f(null);try{r((await ur.setPluginEnabled(e.id,t)).plugins)}catch(e){f(e instanceof Error?e.message:String(e))}finally{m(null)}}async function v(){g(!0),f(null);try{u(await ur.refreshPluginCatalog())}catch(e){f(e instanceof Error?e.message:String(e))}finally{g(!1)}}let y=new Set((n??[]).map(e=>e.id));return(0,J.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`plugin-manager-title`,className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4 backdrop-blur-sm`,onClick:t,children:(0,J.jsxs)(`div`,{className:`flex max-h-[80vh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-gray-700 bg-gray-900 shadow-2xl`,onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-800 px-5 py-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(pT,{size:16,className:`text-brand-400`}),(0,J.jsx)(`h2`,{id:`plugin-manager-title`,className:`text-sm font-semibold text-gray-100`,children:`Plugin Manager`})]}),(0,J.jsx)(`button`,{type:`button`,onClick:t,className:`btn-ghost p-1.5`,"aria-label":`Close`,children:(0,J.jsx)(IP,{size:16})})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-gray-800 px-3 pt-2`,children:[(0,J.jsxs)(WL,{active:s===`installed`,onClick:()=>c(`installed`),children:[`Installed`,n&&(0,J.jsx)(`span`,{className:`ml-1.5 rounded bg-gray-800 px-1.5 py-0.5 text-[9px] text-gray-400`,children:n.length})]}),(0,J.jsxs)(WL,{active:s===`catalog`,onClick:()=>c(`catalog`),children:[`Catalog`,l&&(0,J.jsx)(`span`,{className:`ml-1.5 rounded bg-gray-800 px-1.5 py-0.5 text-[9px] text-gray-400`,children:l.entries.length})]}),(0,J.jsx)(`div`,{className:`flex-1`}),s===`installed`&&(0,J.jsxs)(`button`,{type:`button`,onClick:()=>void a(),disabled:o,className:`btn-ghost flex items-center gap-1.5 px-2 py-1 text-[11px] text-gray-400`,title:`Re-discover plugins on disk (after a manual install or git pull)`,children:[(0,J.jsx)(ZT,{size:12,className:o?`animate-spin`:``}),`Refresh`]}),s===`catalog`&&l&&(0,J.jsxs)(`button`,{type:`button`,onClick:v,disabled:h,className:`btn-ghost flex items-center gap-1.5 px-2 py-1 text-[11px] text-gray-400`,title:`Re-fetch the catalog from the registry`,children:[(0,J.jsx)(ZT,{size:12,className:h?`animate-spin`:``}),`Refresh`]})]}),(0,J.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-4`,children:[d&&(0,J.jsx)(`div`,{className:`mb-3 rounded-md border border-rose-700/50 bg-rose-950/40 px-3 py-2 text-xs text-rose-300`,children:d}),s===`installed`?(0,J.jsx)(GL,{plugins:n,pendingId:p,onToggle:_}):(0,J.jsx)(qL,{catalog:l,installedIds:y})]}),(0,J.jsx)(`div`,{className:`border-t border-gray-800 px-5 py-3 text-[11px] leading-relaxed text-gray-500`,children:s===`installed`?(0,J.jsxs)(J.Fragment,{children:[`Changes persist to`,` `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 text-gray-400`,children:`<tenant>/config.json`}),` `,`and take effect immediately for new requests.`]}):(0,J.jsxs)(J.Fragment,{children:[`Catalog hosted at`,` `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 text-gray-400`,children:`tianshu-ai/plugin-registry`}),`. Install button lands in P2.`]})})]})})}function WL({active:e,onClick:t,children:n}){return(0,J.jsx)(`button`,{type:`button`,onClick:t,className:[`flex items-center rounded-t-md border-b-2 px-3 py-2 text-xs font-medium`,e?`border-brand-500 text-gray-100`:`border-transparent text-gray-500 hover:text-gray-300`].join(` `),children:n})}function GL({plugins:e,pendingId:t,onToggle:n}){return e===null?(0,J.jsxs)(`div`,{className:`flex items-center justify-center py-10 text-sm text-gray-500`,children:[(0,J.jsx)(db,{size:14,className:`mr-2 animate-spin`}),`Loading…`]}):e.length===0?(0,J.jsxs)(`div`,{className:`py-10 text-center text-sm text-gray-500`,children:[`No plugins discovered for this tenant.`,(0,J.jsxs)(`p`,{className:`mt-2 text-xs text-gray-600`,children:[`Builtin plugins ship under`,` `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 text-gray-400`,children:`packages/server/builtinConfig/plugins/`}),`. Tenant plugins live at`,` `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 text-gray-400`,children:`<tenant>/_tenant/config/plugins/`}),`. Browse the Catalog tab to find more.`]})]}):(0,J.jsx)(`ul`,{className:`space-y-2`,children:e.map(e=>(0,J.jsxs)(`li`,{className:`flex items-start justify-between gap-3 rounded-lg border border-gray-800 bg-gray-900/50 p-3`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-sm font-medium text-gray-100`,children:e.displayName}),(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 py-0.5 text-[10px] text-gray-400`,children:e.id}),(0,J.jsxs)(`span`,{className:`text-[10px] text-gray-600`,children:[`v`,e.version]}),(0,J.jsx)(YL,{source:e.source}),(0,J.jsx)(XL,{state:e.state})]}),e.description&&(0,J.jsx)(`p`,{className:`mt-1 text-xs text-gray-400`,children:e.description}),(0,J.jsx)(KL,{entry:e}),e.failedReason&&(0,J.jsxs)(`div`,{className:`mt-1 flex items-start gap-1 text-[11px] text-rose-300`,children:[(0,J.jsx)(OM,{size:11,className:`mt-px flex-shrink-0`}),(0,J.jsx)(`span`,{className:`break-all`,children:e.failedReason})]})]}),(0,J.jsx)(ZL,{active:e.state===`active`,pending:t===e.id,disabled:e.state===`failed`||e.state===`client-bundle-missing`,onClick:()=>n(e)})]},e.id))})}function KL({entry:e}){let{provided:t,requires:n,missing:r}=e.capabilities;return t.length===0&&n.length===0&&r.length===0?null:(0,J.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1.5 text-[10px]`,children:[t.map(e=>(0,J.jsxs)(`span`,{className:`rounded bg-emerald-900/40 px-1.5 py-0.5 text-emerald-300`,title:`This plugin provides ${e}`,children:[`provides `,e]},`p-${e}`)),n.filter(e=>!r.includes(e)).map(e=>(0,J.jsxs)(`span`,{className:`rounded bg-sky-900/40 px-1.5 py-0.5 text-sky-300`,title:`This plugin requires ${e} (satisfied)`,children:[`requires `,e]},`r-${e}`)),r.map(e=>(0,J.jsxs)(`span`,{className:`rounded bg-rose-900/40 px-1.5 py-0.5 text-rose-300`,title:`This plugin requires ${e}, but no provider is enabled`,children:[`missing `,e]},`m-${e}`))]})}function qL({catalog:e,installedIds:t}){return e===null?(0,J.jsxs)(`div`,{className:`flex items-center justify-center py-10 text-sm text-gray-500`,children:[(0,J.jsx)(db,{size:14,className:`mr-2 animate-spin`}),`Fetching catalog…`]}):e.entries.length===0?(0,J.jsxs)(`div`,{className:`py-10 text-center text-sm text-gray-500`,children:[`Catalog is empty.`,(0,J.jsxs)(`p`,{className:`mt-2 text-xs text-gray-600`,children:[`The registry is at`,` `,(0,J.jsx)(`a`,{href:`https://github.com/tianshu-ai/plugin-registry`,target:`_blank`,rel:`noreferrer`,className:`text-brand-400 hover:underline`,children:`tianshu-ai/plugin-registry`}),`. Submit a PR to add your plugin.`]})]}):(0,J.jsxs)(J.Fragment,{children:[e.entriesDropped>0&&(0,J.jsxs)(`div`,{className:`mb-3 rounded-md border border-amber-700/50 bg-amber-950/40 px-3 py-2 text-[11px] text-amber-300`,children:[e.entriesDropped,` catalog`,` `,e.entriesDropped===1?`entry was`:`entries were`,` dropped because`,` `,e.entriesDropped===1?`it failed`:`they failed`,` schema validation.`]}),(0,J.jsx)(`ul`,{className:`space-y-2`,children:e.entries.map(e=>(0,J.jsx)(JL,{entry:e,alreadyInstalled:t.has(e.id)},e.id))})]})}function JL({entry:e,alreadyInstalled:t}){return(0,J.jsxs)(`li`,{className:`flex items-start justify-between gap-3 rounded-lg border border-gray-800 bg-gray-900/50 p-3`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-sm font-medium text-gray-100`,children:e.displayName}),(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 py-0.5 text-[10px] text-gray-400`,children:e.id}),(0,J.jsxs)(`span`,{className:`text-[10px] text-gray-600`,children:[`v`,e.latestVersion]}),e.verified&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 rounded bg-emerald-900/40 px-1.5 py-0.5 text-[9px] uppercase text-emerald-300`,children:[(0,J.jsx)(ND,{size:10}),` verified`]}),(0,J.jsxs)(`a`,{href:e.repository,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-[10px] text-gray-500 hover:text-brand-400`,children:[e.author,` `,(0,J.jsx)(Zp,{size:9})]})]}),(0,J.jsx)(`p`,{className:`mt-1 text-xs text-gray-400`,children:e.description}),e.tags.length>0&&(0,J.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:e.tags.map(e=>(0,J.jsx)(`span`,{className:`rounded bg-gray-800 px-1.5 py-px text-[9px] text-gray-500`,children:e},e))})]}),(0,J.jsx)(`button`,{type:`button`,disabled:!0,title:`Install lands in P2`,className:`flex-shrink-0 cursor-not-allowed rounded-md bg-gray-800 px-3 py-1.5 text-[11px] font-medium text-gray-500`,children:t?`Installed`:`Install`})]})}function YL({source:e}){return(0,J.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[9px] uppercase ${e===`builtin`?`bg-gray-800 text-gray-400`:`bg-violet-900/50 text-violet-300`}`,children:e})}function XL({state:e}){switch(e){case`active`:return(0,J.jsxs)(`span`,{className:`flex items-center gap-1 rounded bg-emerald-900/50 px-1.5 py-0.5 text-[9px] uppercase text-emerald-300`,children:[(0,J.jsx)(W,{size:10}),` active`]});case`disabled`:return(0,J.jsxs)(`span`,{className:`flex items-center gap-1 rounded bg-gray-800 px-1.5 py-0.5 text-[9px] uppercase text-gray-400`,children:[(0,J.jsx)(sw,{size:10}),` disabled`]});case`failed`:return(0,J.jsxs)(`span`,{className:`flex items-center gap-1 rounded bg-rose-900/50 px-1.5 py-0.5 text-[9px] uppercase text-rose-300`,children:[(0,J.jsx)(OM,{size:10}),` failed`]});case`client-bundle-missing`:return(0,J.jsx)(`span`,{className:`rounded bg-amber-900/50 px-1.5 py-0.5 text-[9px] uppercase text-amber-300`,children:`no client bundle`})}}function ZL({active:e,pending:t,disabled:n,onClick:r}){return(0,J.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e,disabled:t||n,onClick:r,className:[`relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer items-center rounded-full transition-colors`,e?`bg-brand-600`:`bg-gray-700`,(t||n)&&`cursor-not-allowed opacity-50`].filter(Boolean).join(` `),title:n?`Plugin cannot be enabled in its current state`:e?`Click to disable`:`Click to enable`,children:[(0,J.jsx)(`span`,{className:[`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform`,e?`translate-x-5`:`translate-x-1`].join(` `)}),t&&(0,J.jsx)(db,{size:10,className:`absolute -right-4 top-1/2 -translate-y-1/2 animate-spin text-gray-400`})]})}var QL={Bot:js,Calendar:jc,FileText:Qm,FolderOpen:$h,Globe:o_,Kanban:Jv,MessageSquare:Vx,Search:fD,Terminal:xj,Wrench:PP};function $L(){let e=gr(e=>e.plugins),t=gr(e=>e.openPanel),n=gr(e=>e.setOpenPanel);if(t!==null||!e)return null;let r=[];for(let t of e){if(t.state!==`active`)continue;let e=t.contributes.topBarButtons??[];for(let n of e)r.push({...n,pluginId:t.id})}return r.sort((e,t)=>(e.order??100)-(t.order??100)),r.length===0?null:(0,J.jsx)(J.Fragment,{children:r.map(e=>{let t=`${e.pluginId}.${e.id}`,r=e.opensPanel?e.opensPanel.includes(`.`)?e.opensPanel:`${e.pluginId}.${e.opensPanel}`:null,i=QL[e.icon]??pT;return(0,J.jsx)(`button`,{type:`button`,title:e.tooltip??e.pluginId,"aria-label":e.tooltip??e.pluginId,onClick:()=>{r&&n(r)},className:`rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-800 hover:text-gray-200`,children:(0,J.jsx)(i,{size:16})},t)})})}function eR(){let e=M(e=>e.messages),t=M(e=>e.me),n=M(e=>e.sidebarOpen),r=M(e=>e.toggleSidebar);M(e=>e.isStreaming);let i=M(e=>e.streamError),a=M(e=>e.clearStreamError),o=M(e=>e.compactNotice),s=M(e=>e.clearCompactNotice),c=M(e=>e.hasMoreHistory),l=M(e=>e.loadingMore),u=M(e=>e.loadEarlier),d=(0,S.useRef)(null),f=(0,S.useRef)(null);(0,S.useEffect)(()=>{let t=e.length>0?e[e.length-1].id:null;t&&t!==f.current&&d.current?.scrollIntoView({behavior:`smooth`}),f.current=t},[e]);let[p,m]=(0,S.useState)(!1),h=t?.config.branding,g=h?.name??`Tianshu`,_=h?.emoji??`⭐`,v=e.length===0;return(0,J.jsxs)(`main`,{className:`flex h-full min-w-0 flex-1 flex-col`,children:[(0,J.jsxs)(`header`,{className:`flex h-12 items-center justify-between border-b border-gray-800 bg-gray-900/50 px-4 backdrop-blur`,children:[(0,J.jsxs)(`div`,{className:`flex items-center`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:r,className:`rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-800 hover:text-gray-200`,title:n?`Hide sidebar`:`Show sidebar`,children:n?(0,J.jsx)(zC,{size:18}):(0,J.jsx)(VC,{size:18})}),(0,J.jsx)(`h1`,{className:`ml-3 text-sm font-medium text-gray-300`,children:`main`}),(0,J.jsxs)(`span`,{className:`ml-3 text-[11px] text-gray-500`,children:[`tenant `,(0,J.jsx)(`span`,{className:`text-gray-300`,children:t?.tenantId??`…`}),` · user`,` `,(0,J.jsx)(`span`,{className:`text-gray-300`,children:t?.userId??`…`})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)($L,{}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>m(!0),className:`rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-800 hover:text-gray-200`,title:`Plugin Manager`,"aria-label":`Open Plugin Manager`,children:(0,J.jsx)(pT,{size:16})})]})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto px-4 py-6`,children:v?(0,J.jsx)(tR,{brandName:g,brandEmoji:_,tenantId:t?.tenantId??`default`}):(0,J.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-4`,children:[c&&(0,J.jsx)(`button`,{type:`button`,onClick:u,disabled:l,className:`w-full rounded-lg bg-gray-800/50 py-2 text-xs text-gray-500 hover:text-gray-300 disabled:cursor-default disabled:opacity-60`,children:l?`Loading…`:`Load earlier messages`}),jL(e).map((e,t)=>(0,J.jsx)(`div`,{className:t===0?``:`mt-4`,children:(0,J.jsx)(bL,{m:e})},e.id)),i&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-rose-700/50 bg-rose-950/40 px-3 py-2 text-sm text-rose-300`,children:[(0,J.jsx)(`span`,{className:`truncate`,children:i}),(0,J.jsx)(`button`,{type:`button`,onClick:a,className:`ml-3 text-[11px] uppercase tracking-wider text-rose-300/80 hover:text-white`,children:`dismiss`})]}),o&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-amber-700/40 bg-amber-950/30 px-3 py-2 text-sm text-amber-200`,children:[(0,J.jsxs)(`span`,{className:`truncate`,children:[`📌 Conversation history compacted (`,o.reason===`auto`?`auto`:`manual`,`):`,` `,o.summarisedCount,` earlier messages summarised,`,` `,o.keptCount,` kept verbatim.`]}),(0,J.jsx)(`button`,{type:`button`,onClick:s,className:`ml-3 text-[11px] uppercase tracking-wider text-amber-300/80 hover:text-white`,children:`dismiss`})]}),(0,J.jsx)(`div`,{ref:d})]})}),(0,J.jsx)(HL,{}),(0,J.jsx)(UL,{open:p,onClose:()=>m(!1)})]})}function tR({brandName:e,brandEmoji:t,tenantId:n}){return(0,J.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center text-center`,children:[(0,J.jsx)(`div`,{className:`mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-brand-600/20`,children:(0,J.jsx)(`span`,{className:`text-2xl`,children:t})}),(0,J.jsxs)(`h2`,{className:`mb-2 text-xl font-semibold text-gray-200`,children:[`Welcome to `,e]}),(0,J.jsxs)(`p`,{className:`max-w-md text-sm text-gray-500`,children:[`An open AI agent platform with a sidecar browser. Day 0: messages persist per-tenant in`,` `,(0,J.jsxs)(`code`,{className:`mx-0.5 rounded bg-gray-800 px-1 py-0.5 text-xs text-gray-400`,children:[`~/.tianshu/tenants/`,n,`/db.sqlite`]}),`. Tools, workspace files, browser, and worker dispatch arrive in later PRs.`]})]})}function nR(){let e=gr(e=>e.plugins),t=gr(e=>e.openPanel),n=gr(e=>e.setOpenPanel);if(!e)return null;let r=[];for(let t of e){if(t.state!==`active`)continue;let e=t.contributes.topBarButtons??[];for(let n of e){let e=n.opensPanel?n.opensPanel.includes(`.`)?n.opensPanel:`${t.id}.${n.opensPanel}`:null;r.push({...n,pluginId:t.id,panelId:e})}}return r.sort((e,t)=>(e.order??100)-(t.order??100)),(0,J.jsxs)(`div`,{className:`flex h-12 items-center gap-1 border-b border-gray-800 bg-gray-950/40 px-2`,children:[(0,J.jsx)(`div`,{className:`flex flex-1 items-center gap-0.5 overflow-x-auto`,children:r.map(e=>{let r=QL[e.icon]??pT,i=e.panelId!==null&&e.panelId===t,a=e.tooltip??e.pluginId;return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>{e.panelId&&n(i?null:e.panelId)},title:a,"aria-label":a,"aria-pressed":i,className:[`group relative flex shrink-0 items-center gap-1.5 rounded-md text-xs transition-all`,i?`bg-gray-700/70 px-2.5 py-1 font-medium text-gray-100`:`px-2 py-1 text-gray-500 hover:bg-gray-800/60 hover:text-gray-200`].join(` `),children:[(0,J.jsx)(r,{size:14}),i?(0,J.jsx)(`span`,{children:a}):(0,J.jsx)(`span`,{className:`sr-only`,children:a})]},`${e.pluginId}.${e.id}`)})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>n(null),title:`Close panel`,"aria-label":`Close panel`,className:`ml-1 rounded-md p-1 text-gray-500 hover:bg-gray-800/60 hover:text-gray-300`,children:(0,J.jsx)(IP,{size:16})})]})}var rR=`tianshu:rightPanelWidth`,iR=384,aR=280,oR=900;function sR(){try{let e=localStorage.getItem(rR),t=e?parseFloat(e):NaN;return Number.isFinite(t)?Math.min(Math.max(t,aR),oR):iR}catch{return iR}}function cR(){let e=M(e=>e.me),t=gr(e=>e.openPanel),n=gr(e=>e.plugins),[r,i]=(0,S.useState)(()=>sR()),[a,o]=(0,S.useState)(!1),s=(0,S.useRef)(null),c=(0,S.useCallback)(e=>{try{localStorage.setItem(rR,String(e))}catch{}},[]),l=(0,S.useCallback)(e=>{e.preventDefault(),s.current={startX:e.clientX,startWidth:r},o(!0);let t=r,n=0,a=e=>{if(!s.current)return;let r=s.current.startX-e.clientX;t=Math.min(Math.max(s.current.startWidth+r,aR),oR),n||=requestAnimationFrame(()=>{n=0,i(t)})},l=()=>{window.removeEventListener(`mousemove`,a),window.removeEventListener(`mouseup`,l),n&&cancelAnimationFrame(n),window.getSelection?.()?.removeAllRanges(),s.current=null,o(!1),c(t)};window.addEventListener(`mousemove`,a),window.addEventListener(`mouseup`,l)},[r,c]),u=(0,S.useCallback)(()=>{i(iR),c(iR)},[c]),d=gr(e=>e.setOpenPanel);if((0,S.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&d(null)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,d]),!t||!n)return null;let f=t.indexOf(`.`);if(f<0)return null;let p=t.slice(0,f),m=t.slice(f+1),h=n.find(e=>e.id===p);if(!h||h.state!==`active`)return null;let g=h.contributes.rightPanels?.find(e=>e.id===m);if(!g)return null;let _=KI(h.clientEntry,g.component);if(!_)return null;let v={tenantId:e?.tenantId??``,userId:e?.userId??``,plugin:{id:h.id,version:h.version,displayName:h.displayName}};return(0,J.jsxs)(`aside`,{className:`relative flex h-full flex-shrink-0 flex-col border-l border-gray-800 bg-gray-950`,style:{width:r},children:[(0,J.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize right panel`,title:`Drag to resize (double-click to reset)`,onMouseDown:l,onDoubleClick:u,className:[`group absolute -left-[3px] top-0 bottom-0 z-10 flex w-[6px] cursor-col-resize items-center justify-center`,a?`bg-blue-500/20`:`hover:bg-blue-500/10`].join(` `),children:(0,J.jsx)(`span`,{"aria-hidden":!0,className:[`h-full w-px`,a?`bg-blue-400`:`bg-transparent group-hover:bg-blue-400/60`].join(` `)})}),(0,J.jsx)(nR,{}),(0,J.jsxs)(`div`,{className:`relative flex-1 overflow-hidden`,children:[a&&(0,J.jsx)(`div`,{className:`absolute inset-0 z-10`}),(0,J.jsx)(_,{...v})]})]})}function lR(){let e=M(e=>e.init),t=M(e=>e.sidebarOpen),n=M(e=>e.meError),r=gr(e=>e.load);return(0,S.useEffect)(()=>{e(),r()},[e,r]),(0,J.jsxs)(`div`,{className:`flex h-screen overflow-hidden bg-gray-950 text-gray-100`,children:[t&&(0,J.jsx)(cL,{}),(0,J.jsx)(eR,{}),(0,J.jsx)(cR,{}),n&&(0,J.jsxs)(`div`,{className:`fixed right-4 top-4 max-w-sm rounded-md border border-rose-700/50 bg-rose-950/90 px-3 py-2 text-sm text-rose-200 shadow-lg`,children:[(0,J.jsx)(`strong`,{className:`mr-1`,children:`/api/me failed:`}),n]})]})}var uR=`tianshu_identity`,dR=/^\/tenants\/([A-Za-z0-9._-]{1,64})\/users\/([A-Za-z0-9._-]{1,64})(\/.*)?$/,fR=`default`;function pR(e){let t=e.match(dR);return t?{tenantId:t[1],userId:t[2],rest:t[3]||`/`}:null}function mR(){if(typeof document>`u`)return null;for(let e of document.cookie.split(/;\s*/)){let t=e.indexOf(`=`);if(t<=0||e.slice(0,t).trim()!==uR)continue;let n=decodeURIComponent(e.slice(t+1).trim()),r=n.indexOf(`/`);if(!(r<=0||r===n.length-1))return{tenantId:n.slice(0,r),userId:n.slice(r+1)}}return null}function hR(e,t){let n=encodeURIComponent(`${e}/${t}`);document.cookie=`${uR}=${n};Path=/;Max-Age=${720*3600};SameSite=Lax`}function gR(){document.cookie=`${uR}=;Path=/;Max-Age=0;SameSite=Lax`}function _R(e,t){if(dR.test(e))return e;let n=t??mR(),r=n?.tenantId??`default`,i=n?.userId??`dev`,a=e.startsWith(`/`)?e:`/${e}`;return`/tenants/${r}/users/${i}${a===`/`?``:a}`}function vR(){if(typeof window>`u`)return;let e=new URLSearchParams(window.location.search);if(e.has(`reset-identity`)){gR(),e.delete(`reset-identity`);let t=e.toString()?`?${e.toString()}`:``;window.location.replace(`/`+t+window.location.hash);return}let t=(e.get(`tenant`)??``).trim(),n=(e.get(`user`)??``).trim();if(t||n){let r=mR(),i=t||r?.tenantId||`default`,a=n||r?.userId||`dev`;if(!bR(i)||!bR(a)){console.warn(`[tianshu] ignoring invalid identity from URL: tenant=${i} user=${a}`);return}hR(i,a),e.delete(`tenant`),e.delete(`user`);let o=`/tenants/${i}/users/${a}${yR(window.location.pathname)}${e.toString()?`?${e.toString()}`:``}${window.location.hash}`;window.location.replace(o);return}let r=pR(window.location.pathname);if(r){let e=mR();(e?.tenantId!==r.tenantId||e?.userId!==r.userId)&&hR(r.tenantId,r.userId);return}let i=mR();if(i){let e=`/tenants/${i.tenantId}/users/${i.userId}${window.location.pathname}${window.location.search}${window.location.hash}`;window.location.replace(e);return}hR(fR,`dev`),window.location.replace(`/tenants/${fR}/users/dev${window.location.pathname}${window.location.search}${window.location.hash}`)}function yR(e){let t=e.match(dR);return t?t[3]||`/`:e||`/`}function bR(e){return/^[A-Za-z0-9._-]+$/.test(e)&&e.length<=64}function xR(){let[e,t]=(0,S.useState)(null),[n,r]=(0,S.useState)(null),[i,a]=(0,S.useState)(!1),[o,s]=(0,S.useState)(null),c=(0,S.useCallback)(async()=>{a(!0),r(null);try{let e=await fetch(`/api/mcp/servers`,{credentials:`include`});if(!e.ok){let t=await e.text().catch(()=>``);throw Error(`HTTP ${e.status}: ${t.slice(0,200)}`)}t((await e.json()).servers??[])}catch(e){r(e instanceof Error?e.message:String(e))}finally{a(!1)}},[]);(0,S.useEffect)(()=>{c()},[c]);let l=(0,S.useMemo)(()=>{let t=[{source:`plugin`,items:[]},{source:`user`,items:[]}];for(let n of e??[])t.find(e=>e.source===n.source)?.items.push(n);return t},[e]);return(0,J.jsxs)(`div`,{className:`mx-auto max-w-5xl p-6`,children:[(0,J.jsxs)(`div`,{className:`mb-6 flex items-start justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold text-gray-100`,children:[(0,J.jsx)(SD,{size:18,className:`text-brand-400`}),`MCP Servers`]}),(0,J.jsx)(`p`,{className:`mt-1 text-[12px] text-gray-500`,children:`Model Context Protocol servers visible to this agent. Plugin-contributed servers come from active plugins (read-only here — toggle the plugin to enable/disable). User-configured servers are managed directly below.`})]}),(0,J.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-2`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:c,disabled:i,className:`inline-flex items-center gap-1.5 whitespace-nowrap rounded-md border border-gray-700 px-3 py-1.5 text-[12px] text-gray-300 hover:bg-gray-800/50 disabled:opacity-50`,children:[(0,J.jsx)(ZT,{size:12,className:i?`animate-spin`:void 0}),`Refresh`]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>s(`new`),className:`inline-flex items-center gap-1.5 whitespace-nowrap rounded-md bg-brand-600 px-3 py-1.5 text-[12px] font-medium text-white hover:bg-brand-500`,children:[(0,J.jsx)(Zw,{size:12}),`Add server`]})]})]}),n&&(0,J.jsxs)(`div`,{className:`mb-4 flex items-start gap-2 rounded-md border border-rose-700/50 bg-rose-950/40 px-3 py-2 text-[12px] text-rose-300`,children:[(0,J.jsx)(OM,{size:14,className:`mt-px flex-shrink-0`}),(0,J.jsx)(`span`,{className:`break-all`,children:n})]}),e&&(0,J.jsx)(`div`,{className:`space-y-6`,children:l.map(e=>(0,J.jsx)(SR,{source:e.source,items:e.items,onEdit:e=>s(e),onChanged:c,onError:r},e.source))}),o&&(0,J.jsx)(TR,{mode:o===`new`?`create`:`edit`,initial:o===`new`?null:o,onClose:()=>s(null),onSaved:async()=>{s(null),await c()},onError:r})]})}function SR({source:e,items:t,onEdit:n,onChanged:r,onError:i}){return(0,J.jsxs)(`section`,{children:[(0,J.jsx)(`div`,{className:`mb-2 flex items-end justify-between`,children:(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-[13px] font-semibold uppercase tracking-wide text-gray-400`,children:e===`plugin`?`From plugins`:`User-configured`}),(0,J.jsx)(`p`,{className:`text-[11px] text-gray-500`,children:e===`plugin`?`Read-only — managed by the contributing plugin.`:`Add MCP servers (HTTP) to expand the agent's tool surface.`})]})}),t.length===0?(0,J.jsx)(CR,{source:e}):(0,J.jsx)(`div`,{className:`space-y-3`,children:t.map(e=>(0,J.jsx)(wR,{server:e,onEdit:n,onChanged:r,onError:i},`${e.source}.${e.sourceId}.${e.id}`))})]})}function CR({source:e}){return e===`plugin`?(0,J.jsx)(`div`,{className:`rounded-md border border-dashed border-gray-800 px-4 py-6 text-center text-[12px] text-gray-500`,children:`No plugin currently contributes an MCP server.`}):(0,J.jsxs)(`div`,{className:`rounded-md border border-dashed border-gray-800 px-4 py-6 text-center text-[12px] text-gray-500`,children:[`No user-configured MCP servers. Click `,(0,J.jsx)(`span`,{className:`text-gray-300`,children:`Add server`}),` `,`to point the agent at one (e.g. an MCP server you run locally or remotely).`]})}function wR({server:e,onEdit:t,onChanged:n,onError:r}){let[i,a]=(0,S.useState)(!1),[o,s]=(0,S.useState)(!1),c=e.snapshot,l=c?.tools??[],u=c?.lastError,d=c?.endpoint,f=(0,S.useMemo)(()=>{if(!c?.lastRefreshAt)return null;let e=Math.round((Date.now()-c.lastRefreshAt)/1e3);if(e<60)return`${e}s ago`;let t=Math.round(e/60);return t<60?`${t}m ago`:`${Math.round(t/60)}h ago`},[c?.lastRefreshAt]),p=e.enabled&&!u&&l.length>0,m=e.source===`user`,h=(0,S.useCallback)(async()=>{s(!0);try{let t=await fetch(`/api/mcp/servers/${encodeURIComponent(e.id)}/refresh`,{method:`POST`,credentials:`include`});if(!t.ok)throw Error(`HTTP ${t.status}`);await n()}catch(e){r(e instanceof Error?e.message:String(e))}finally{s(!1)}},[e.id,n,r]),g=(0,S.useCallback)(async()=>{if(!(!m||!e.userEntry)){s(!0);try{let t=await fetch(`/api/mcp/servers/${encodeURIComponent(e.id)}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:!e.enabled})});if(!t.ok)throw Error(`HTTP ${t.status}`);await n()}catch(e){r(e instanceof Error?e.message:String(e))}finally{s(!1)}}},[m,e.userEntry,e.id,e.enabled,n,r]),_=(0,S.useCallback)(async()=>{if(m&&confirm(`Remove MCP server "${e.displayName}"?`)){s(!0);try{let t=await fetch(`/api/mcp/servers/${encodeURIComponent(e.id)}`,{method:`DELETE`,credentials:`include`});if(!t.ok)throw Error(`HTTP ${t.status}`);await n()}catch(e){r(e instanceof Error?e.message:String(e))}finally{s(!1)}}},[m,e.displayName,e.id,n,r]);return(0,J.jsxs)(`div`,{className:`overflow-hidden rounded-md border border-gray-800 bg-gray-900/60`,children:[(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-gray-800 px-4 py-3`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`-my-1 -ml-1 mr-2 rounded p-1 text-gray-500 hover:bg-gray-800/60 hover:text-gray-300`,"aria-label":i?`Collapse`:`Expand`,children:i?(0,J.jsx)(Fl,{size:14}):(0,J.jsx)(zl,{size:14})}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.enabled?p?(0,J.jsx)(W,{size:14,className:`text-emerald-400`}):(0,J.jsx)(Lu,{size:14,className:`text-rose-400`}):(0,J.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-gray-500`,title:`disabled`}),(0,J.jsx)(`span`,{className:`truncate text-[13px] font-medium text-gray-100`,children:e.displayName}),(0,J.jsx)(`span`,{className:`rounded-sm px-1.5 py-0.5 text-[10px] ${m?`bg-blue-950 text-blue-300`:`bg-gray-800 text-gray-400`}`,children:m?`user`:`plugin: ${e.sourceId}`})]}),(0,J.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-4 gap-y-1 text-[11px] text-gray-500`,children:[(0,J.jsxs)(`span`,{children:[`id `,(0,J.jsx)(`code`,{className:`text-gray-400`,children:e.id})]}),d&&(0,J.jsxs)(`span`,{children:[`endpoint `,(0,J.jsx)(`code`,{className:`text-gray-400`,children:d})]}),c?.prefix&&c.prefix!==``&&(0,J.jsxs)(`span`,{children:[`prefix `,(0,J.jsx)(`code`,{className:`text-gray-400`,children:c.prefix})]}),f&&(0,J.jsxs)(`span`,{children:[`refreshed `,f]}),!e.enabled&&(0,J.jsx)(`span`,{className:`text-gray-500`,children:`(disabled)`})]})]}),(0,J.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-1.5`,children:[(0,J.jsxs)(`span`,{className:`rounded-md border border-gray-700 bg-gray-950 px-2 py-1 text-[11px] text-gray-300`,children:[e.toolCount,` tools`]}),(0,J.jsx)(`button`,{type:`button`,onClick:h,disabled:o,title:`Refresh`,className:`rounded p-1.5 text-gray-400 hover:bg-gray-800/60 hover:text-gray-200 disabled:opacity-50`,children:(0,J.jsx)(ZT,{size:12,className:o?`animate-spin`:void 0})}),m&&e.userEntry&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>t(e.userEntry),disabled:o,title:`Edit`,className:`rounded p-1.5 text-gray-400 hover:bg-gray-800/60 hover:text-gray-200 disabled:opacity-50`,children:(0,J.jsx)(vw,{size:12})}),(0,J.jsx)(`button`,{type:`button`,onClick:g,disabled:o,className:`rounded-md border border-gray-700 px-2 py-1 text-[11px] text-gray-300 hover:bg-gray-800/50 disabled:opacity-50`,children:e.enabled?`Disable`:`Enable`}),(0,J.jsx)(`button`,{type:`button`,onClick:_,disabled:o,title:`Delete`,className:`rounded p-1.5 text-rose-400 hover:bg-rose-950/40 disabled:opacity-50`,children:(0,J.jsx)(yM,{size:12})})]})]})]}),u&&(0,J.jsxs)(`div`,{className:`border-b border-gray-800 bg-rose-950/30 px-4 py-2 text-[11px] text-rose-300`,children:[(0,J.jsx)(OM,{size:12,className:`mr-1 inline-block`}),u]}),i&&(l.length===0?(0,J.jsx)(`div`,{className:`px-4 py-6 text-center text-[12px] text-gray-500`,children:d?`Server is reachable but advertised no tools.`:e.enabled?e.source===`plugin`?`Upstream not reachable yet. Plugin MCP servers usually live inside a sandbox that boots on first agent action — try running an exec/browser tool, or click Refresh after the sandbox starts.`:`Endpoint unreachable. Click Refresh to re-probe.`:`Server is disabled.`}):(0,J.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,J.jsx)(`thead`,{className:`border-b border-gray-800 text-left text-[11px] uppercase tracking-wide text-gray-500`,children:(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Tool name`}),(0,J.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Upstream`}),(0,J.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Description`})]})}),(0,J.jsx)(`tbody`,{children:l.map(e=>(0,J.jsxs)(`tr`,{className:`border-b border-gray-900 last:border-b-0`,children:[(0,J.jsx)(`td`,{className:`px-4 py-2 align-top font-mono text-[11.5px] text-gray-200`,children:e.toolName}),(0,J.jsx)(`td`,{className:`px-4 py-2 align-top font-mono text-[11.5px] text-gray-500`,children:e.upstream.name}),(0,J.jsx)(`td`,{className:`px-4 py-2 align-top text-gray-400`,children:e.upstream.description??`—`})]},e.toolName))})]}))]})}function TR({mode:e,initial:t,onClose:n,onSaved:r,onError:i}){let[a,o]=(0,S.useState)(t?.id??``),[s,c]=(0,S.useState)(t?.displayName??``),[l,u]=(0,S.useState)(t?.url??``),[d,f]=(0,S.useState)(t?.prefix??``),[p,m]=(0,S.useState)(t?.upstreamHost??``),[h,g]=(0,S.useState)(t?.enabled??!0),[_,v]=(0,S.useState)(!1),[y,b]=(0,S.useState)(null),x=async n=>{if(n.preventDefault(),b(null),!/^[a-z0-9][a-z0-9-]{0,30}$/.test(a)){b(`id must be 1-31 chars: lowercase letters, digits, dashes`);return}v(!0);try{let n={id:a,url:l,enabled:h};s&&(n.displayName=s),d!==t?.prefix&&(n.prefix=d),p&&(n.upstreamHost=p);let i=e===`create`?`/api/mcp/servers`:`/api/mcp/servers/${encodeURIComponent(a)}`,o=await fetch(i,{method:e===`create`?`POST`:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!o.ok){let e=await o.json().catch(()=>({}));throw Error(e.message??`HTTP ${o.status}`)}await r()}catch(e){i(e instanceof Error?e.message:String(e))}finally{v(!1)}},{Modal:C}=_F();return(0,J.jsx)(C,{isOpen:!0,onClose:n,size:`sm`,title:e===`create`?`Add MCP server`:`Edit ${t?.displayName??a}`,children:(0,J.jsxs)(`form`,{onSubmit:x,className:`space-y-3 p-5`,children:[(0,J.jsx)(ER,{label:`ID`,hint:`Lowercase letters / digits / dashes; used in URLs and tool prefixes.`,children:(0,J.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),disabled:e===`edit`,placeholder:`my-mcp`,className:`w-full rounded-md border border-gray-700 bg-gray-950 px-2 py-1.5 text-[13px] text-gray-100 outline-none focus:border-brand-500 disabled:opacity-60`,required:!0})}),(0,J.jsx)(ER,{label:`Display name`,hint:`Optional; defaults to id.`,children:(0,J.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`My MCP server`,className:`w-full rounded-md border border-gray-700 bg-gray-950 px-2 py-1.5 text-[13px] text-gray-100 outline-none focus:border-brand-500`})}),(0,J.jsx)(ER,{label:`URL`,hint:`Streamable HTTP MCP endpoint (must include path, e.g. /mcp).`,children:(0,J.jsx)(`input`,{type:`url`,value:l,onChange:e=>u(e.target.value),placeholder:`https://example.com/mcp`,className:`w-full rounded-md border border-gray-700 bg-gray-950 px-2 py-1.5 text-[13px] text-gray-100 outline-none focus:border-brand-500`,required:!0})}),(0,J.jsx)(ER,{label:`Tool prefix`,hint:`Prepended to every reflected tool name. Default: "<id>_". Pass empty to disable.`,children:(0,J.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`${a}_`,className:`w-full rounded-md border border-gray-700 bg-gray-950 px-2 py-1.5 text-[13px] text-gray-100 outline-none focus:border-brand-500`})}),(0,J.jsx)(ER,{label:`Upstream Host header`,hint:`Optional. Pin the request Host header (most MCP servers validate it; useful behind port-forwards).`,children:(0,J.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:`localhost:3200`,className:`w-full rounded-md border border-gray-700 bg-gray-950 px-2 py-1.5 text-[13px] text-gray-100 outline-none focus:border-brand-500`})}),(0,J.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-gray-300`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`rounded border-gray-700 bg-gray-950`}),`Enabled`]}),y&&(0,J.jsx)(`div`,{className:`rounded-md border border-rose-700/50 bg-rose-950/40 px-3 py-2 text-[11px] text-rose-300`,children:y}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-md border border-gray-700 px-3 py-1.5 text-[12px] text-gray-300 hover:bg-gray-800/50`,children:`Cancel`}),(0,J.jsx)(`button`,{type:`submit`,disabled:_,className:`rounded-md bg-brand-600 px-3 py-1.5 text-[12px] font-medium text-white hover:bg-brand-500 disabled:opacity-50`,children:_?`Saving…`:e===`create`?`Add server`:`Save`})]})]})})}function ER({label:e,hint:t,children:n}){return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-gray-300`,children:e}),n,t&&(0,J.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-500`,children:t})]})}function DR({pluginId:e,className:t}){let n=gr(t=>(t.plugins??[]).find(t=>t.id===e)??null);return!n||!n.configSchema||(n.configSchema.fields?.length??0)===0?null:(0,J.jsx)(`div`,{className:t,children:(0,J.jsx)(OR,{plugin:n})})}function OR({plugin:e}){let t=gr(e=>e.setPlugins),n=e.configSchema?.fields??[],[r,i]=(0,S.useState)(()=>PR(n,e.config)),[a,o]=(0,S.useState)(!1),[s,c]=(0,S.useState)(null),[l,u]=(0,S.useState)(null);(0,S.useEffect)(()=>{i(PR(n,e.config)),u(null)},[e.id,e.version,e.config]);let d=!LR(r,PR(n,e.config));async function f(){o(!0),c(null);try{let n=IR(r);t((await ur.setPluginConfig(e.id,n)).plugins),u(Date.now())}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(!1)}}function p(){i(PR(n,e.config)),c(null),u(null)}return n.length===0?(0,J.jsx)(`p`,{className:`text-[12px] text-gray-500`,children:`This plugin has no user-editable configuration.`}):(0,J.jsxs)(`div`,{className:`space-y-5`,children:[(0,J.jsx)(`div`,{className:`space-y-5`,children:jR(n).map((e,t)=>{if(e.kind===`field`)return(0,J.jsx)(NR,{field:e.field,value:r[e.field.key],onChange:t=>i(n=>({...n,[e.field.key]:t}))},`f:${t}:${e.field.key}`);let[n,...a]=e.fields,o=n&&n.kind===`boolean`?{field:n,value:r[n.key]===!0,onChange:e=>i(t=>({...t,[n.key]:e}))}:null,s=o?a:e.fields;return(0,J.jsx)(MR,{group:e.group,headerToggle:o,children:s.map(e=>(0,J.jsx)(NR,{field:e,value:r[e.key],onChange:t=>i(n=>({...n,[e.key]:t}))},e.key))},`g:${e.group.id}`)})}),s&&(0,J.jsx)(`div`,{className:`rounded-md border border-rose-700/50 bg-rose-950/40 px-3 py-2 text-[12px] text-rose-300`,children:s}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 border-t border-gray-800 pt-3`,children:[l&&!d&&(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-emerald-400`,children:[(0,J.jsx)(W,{size:12}),` Saved`]}),(0,J.jsx)(`button`,{type:`button`,onClick:p,disabled:!d||a,className:`ml-auto inline-flex items-center gap-1.5 whitespace-nowrap rounded-md border border-gray-700 px-3 py-1.5 text-[12px] text-gray-300 hover:bg-gray-800/50 disabled:cursor-not-allowed disabled:opacity-50`,children:`Reset`}),(0,J.jsx)(`button`,{type:`button`,onClick:f,disabled:!d||a,className:`inline-flex items-center gap-1.5 whitespace-nowrap rounded-md bg-brand-600 px-3 py-1.5 text-[12px] font-medium text-white hover:bg-brand-500 disabled:cursor-not-allowed disabled:opacity-50`,children:a?(0,J.jsx)(db,{className:`inline h-3 w-3 animate-spin`}):`Save`})]})]})}var kR=`w-full rounded-md border border-gray-700 bg-gray-900 px-3 py-1.5 text-[12px] text-gray-100 outline-none placeholder:text-gray-600 focus:border-brand-500`;function AR({active:e,onClick:t,ariaLabel:n}){return(0,J.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e,"aria-label":n,onClick:t,className:[`relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer items-center rounded-full transition-colors`,e?`bg-brand-600`:`bg-gray-700`].join(` `),children:(0,J.jsx)(`span`,{className:[`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform`,e?`translate-x-5`:`translate-x-1`].join(` `)})})}function jR(e){let t=[],n=new Map;for(let r of e){let e=r.group;if(!e){t.push({kind:`field`,field:r});continue}let i=n.get(e.id);i===void 0?(n.set(e.id,t.length),t.push({kind:`group`,group:e,fields:[r]})):t[i].fields.push(r)}return t}function MR({group:e,headerToggle:t,children:n}){let r=!n||Array.isArray(n)&&n.every(e=>e==null||e===!1);return(0,J.jsxs)(`section`,{className:`rounded-md border border-gray-800 bg-gray-900/30 p-4`,children:[(0,J.jsxs)(`header`,{className:`flex flex-wrap items-center gap-2`,children:[e.badge&&(0,J.jsx)(`span`,{className:`rounded border border-gray-700 bg-gray-800/60 px-1.5 py-0.5 font-mono text-[10px] font-semibold uppercase tracking-wide text-gray-400`,children:e.badge}),(0,J.jsx)(`h3`,{className:`text-[13px] font-semibold text-gray-100`,children:e.label}),t&&(0,J.jsx)(AR,{active:t.value,onClick:()=>t.onChange(!t.value),ariaLabel:t.field.label})]}),e.description&&(0,J.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-gray-500`,children:e.description}),!r&&(0,J.jsx)(`div`,{className:`mt-3 space-y-4`,children:n})]})}function NR({field:e,value:t,onChange:n}){if(e.kind===`boolean`){let r=t===!0;return(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-3 text-[12px]`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`font-medium text-gray-200`,children:e.label}),e.description&&(0,J.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-relaxed text-gray-500`,children:e.description})]}),(0,J.jsx)(AR,{active:r,onClick:()=>n(!r),ariaLabel:e.label})]})}if(e.kind===`number`){let r=typeof t==`number`?t:typeof t==`string`&&t.trim()!==``?Number(t):e.default??0;return(0,J.jsxs)(`div`,{className:`text-[12px]`,children:[(0,J.jsx)(`label`,{className:`mb-1 block font-medium text-gray-200`,children:e.label}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`input`,{type:`number`,value:Number.isFinite(r)?r:0,min:e.min,max:e.max,step:e.step,onChange:e=>n(Number(e.target.value)),className:`${kR} w-40`}),e.unit&&(0,J.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:e.unit})]}),e.description&&(0,J.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-gray-500`,children:e.description})]})}if(e.kind===`select`){let r=typeof t==`string`?t:e.default??e.options[0]?.value??``;return(0,J.jsxs)(`div`,{className:`text-[12px]`,children:[(0,J.jsx)(`label`,{className:`mb-1 block font-medium text-gray-200`,children:e.label}),(0,J.jsx)(`select`,{value:r,onChange:e=>n(e.target.value),className:kR,children:e.options.map(e=>(0,J.jsx)(`option`,{value:e.value,children:e.label},e.value))}),e.description&&(0,J.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-gray-500`,children:e.description})]})}if(e.kind===`secret`){let r=typeof t==`object`&&!!t&&t.__secret===!0&&t.set===!0,i=typeof t==`string`?t:``;return(0,J.jsxs)(`div`,{className:`text-[12px]`,children:[(0,J.jsxs)(`label`,{className:`mb-1 block font-medium text-gray-200`,children:[e.label,r?(0,J.jsx)(`span`,{className:`ml-2 rounded bg-emerald-700/40 px-1.5 py-0.5 text-[10px] uppercase text-emerald-300`,children:`set`}):null]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`input`,{type:`password`,value:i,placeholder:r?`••• stored — type a new value to replace, or click Clear`:e.placeholder??``,autoComplete:`new-password`,spellCheck:!1,onChange:e=>n(e.target.value),className:kR}),r&&i===``&&(0,J.jsx)(`button`,{type:`button`,className:`shrink-0 rounded border border-gray-700 bg-gray-900 px-2 py-1 text-[11px] text-gray-300 hover:border-rose-700 hover:text-rose-300`,onClick:()=>n({__secret:!0,clear:!0}),children:`Clear`})]}),e.description&&(0,J.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-gray-500`,children:e.description})]})}let r=typeof t==`string`?t:e.default??``;return(0,J.jsxs)(`div`,{className:`text-[12px]`,children:[(0,J.jsx)(`label`,{className:`mb-1 block font-medium text-gray-200`,children:e.label}),e.multiline?(0,J.jsx)(`textarea`,{value:r,rows:3,placeholder:e.placeholder,onChange:e=>n(e.target.value),className:`${kR} resize-y`}):(0,J.jsx)(`input`,{type:`text`,value:r,placeholder:e.placeholder,onChange:e=>n(e.target.value),className:kR}),e.description&&(0,J.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-gray-500`,children:e.description})]})}function PR(e,t){let n={};for(let r of e){let e=FR(t,r.key);if(e!==void 0){n[r.key]=e;continue}r.kind===`boolean`?n[r.key]=r.default??!1:r.kind===`number`?n[r.key]=r.default??0:r.kind===`secret`?n[r.key]=``:r.kind===`select`?n[r.key]=r.default??r.options[0]?.value??``:n[r.key]=r.default??``}return n}function FR(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return;n=n[e]}return n}function IR(e){let t={};for(let[n,r]of Object.entries(e)){let e=n.split(`.`),i=t;for(let t=0;t<e.length-1;t++){let n=e[t];(typeof i[n]!=`object`||i[n]===null||Array.isArray(i[n]))&&(i[n]={}),i=i[n]}i[e[e.length-1]]=r}return t}function LR(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(e[r]!==t[r])return!1;return!0}var RR=[{pluginId:`core`,pluginDisplayName:`Tianshu`,pageId:`mcp`,displayName:`MCP Servers`,icon:`Server`,kind:`core`,component:`McpServersPage`,coreComponent:xR,group:`Agent`,order:10,clientEntry:null}],zR=`Plugins`;function BR(e){let t=[...RR];if(e)for(let n of e){if(n.state!==`active`)continue;let e=n.contributes.adminPages??[];for(let r of e)t.push({pluginId:n.id,pluginDisplayName:n.displayName,pageId:r.id,displayName:r.displayName,icon:r.icon,kind:`plugin`,component:r.component,group:zR,order:r.order??100,clientEntry:n.clientEntry});let r=!!n.configSchema&&(n.configSchema?.fields?.length??0)>0,i=e.length>0,a=e.some(e=>e.id===`settings`);r&&!i&&!a&&t.push({pluginId:n.id,pluginDisplayName:n.displayName,pageId:`settings`,displayName:n.displayName,icon:`Settings`,kind:`core`,component:`PluginConfigSettingsPage`,coreComponent:(e=>(0,J.jsx)(JR,{...e,pluginId:n.id})),group:zR,order:90,clientEntry:null})}return t.sort((e,t)=>{let n=e.group??``,r=t.group??``;return n===r?e.order===t.order?e.displayName.localeCompare(t.displayName):e.order-t.order:n===``?-1:r===``?1:n.localeCompare(r)}),t}function VR(){let e=M(e=>e.me),t=M(e=>e.init),n=gr(e=>e.plugins),r=gr(e=>e.load);(0,S.useEffect)(()=>{t(),r()},[t,r]);let i=(0,S.useMemo)(()=>BR(n),[n]);return(0,J.jsxs)(`div`,{className:`flex h-screen overflow-hidden bg-gray-950 text-gray-200`,children:[(0,J.jsx)(HR,{pages:i,userLabel:e?.userId??null}),(0,J.jsx)(`main`,{className:`min-w-0 flex-1 overflow-y-auto`,children:(0,J.jsxs)(Gt,{children:[(0,J.jsx)(Ut,{index:!0,element:i.length>0?(0,J.jsx)(Ht,{to:_R(`/admin/${i[0].pluginId}/${i[0].pageId}`),replace:!0}):(0,J.jsx)(GR,{})}),(0,J.jsx)(Ut,{path:`:pluginId/:pageId`,element:(0,J.jsx)(WR,{pages:i})}),(0,J.jsx)(Ut,{path:`*`,element:(0,J.jsx)(Ht,{to:``,replace:!0})})]})})]})}function HR({pages:e,userLabel:t}){let n=sL()(`admin.title`),r=[];for(let t of e){let e=r[r.length-1],n=t.group??null;e&&e.group===n?e.pages.push(t):r.push({group:n,pages:[t]})}return(0,J.jsxs)(`aside`,{className:`flex w-56 flex-shrink-0 flex-col border-r border-gray-800 bg-gray-900`,children:[(0,J.jsxs)(`div`,{className:`flex h-14 items-center gap-2 border-b border-gray-800 px-4`,children:[(0,J.jsx)(ND,{size:16,className:`text-blue-400`}),(0,J.jsx)(`span`,{className:`text-sm font-semibold text-gray-100`,children:n})]}),(0,J.jsxs)(`nav`,{className:`flex-1 space-y-3 overflow-y-auto p-2`,children:[r.length===0&&(0,J.jsxs)(`p`,{className:`px-3 py-2 text-[11px] leading-relaxed text-gray-500`,children:[`No admin pages contributed yet. Enable a plugin that ships `,(0,J.jsx)(`code`,{children:`contributes.adminPages`}),` to see entries here.`]}),r.map((e,t)=>(0,J.jsxs)(`div`,{children:[e.group&&(0,J.jsx)(`div`,{className:`px-3 pb-1 pt-1 text-[10px] font-semibold uppercase tracking-wide text-gray-500`,children:e.group}),(0,J.jsx)(`div`,{className:`space-y-0.5`,children:e.pages.map(e=>(0,J.jsx)(UR,{page:e},`${e.pluginId}.${e.pageId}`))})]},t))]}),(0,J.jsx)(`div`,{className:`border-t border-gray-800 p-2`,children:(0,J.jsxs)(In,{to:`..`,className:`flex items-center gap-2 rounded-md px-3 py-2 text-xs text-gray-500 hover:bg-gray-800/50 hover:text-gray-300`,end:!0,children:[(0,J.jsx)(Yi,{size:12}),`Back to chat`]})}),t&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 border-t border-gray-800 px-3 py-2`,children:[(0,J.jsx)(`div`,{className:`flex h-6 w-6 items-center justify-center rounded-full bg-gradient-to-br from-blue-500 to-purple-600 text-[10px] font-semibold text-white`,children:t.slice(0,1).toUpperCase()}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`truncate text-[11px] text-gray-300`,children:t}),(0,J.jsx)(`div`,{className:`text-[10px] text-gray-600`,children:`admin`})]})]})]})}function UR({page:e}){let t=qR(e.icon);return(0,J.jsxs)(In,{to:_R(`/admin/${e.pluginId}/${e.pageId}`),className:({isActive:e})=>`flex items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors ${e?`bg-gray-800 text-white`:`text-gray-400 hover:bg-gray-800/50 hover:text-gray-200`}`,children:[t&&(0,J.jsx)(t,{size:14,className:`flex-shrink-0`}),(0,J.jsx)(`span`,{className:`truncate`,children:e.displayName})]})}function WR({pages:e}){let t=vt(),n=gt(),r=M(e=>e.me),i=e.find(e=>e.pluginId===t.pluginId&&e.pageId===t.pageId);if((0,S.useEffect)(()=>{!i&&e.length>0&&n(_R(`/admin`),{replace:!0})},[i,e,n]),!i)return(0,J.jsx)(GR,{});let a=i.kind===`core`?i.coreComponent??null:KI(i.clientEntry,i.component);return a?(0,J.jsx)(a,{tenantId:r?.tenantId??``,userId:r?.userId??``,pageId:i.pageId,plugin:{id:i.pluginId,version:``,displayName:i.pluginDisplayName}}):(0,J.jsx)(KR,{title:`Component "${i.component}" not found`,message:`Plugin ${i.pluginId}'s client bundle does not export ${i.component}. Did you forget to add it to PluginClientExports.components?`})}function GR(){return(0,J.jsxs)(`div`,{className:`mx-auto flex max-w-xl flex-col items-center justify-center px-6 py-24 text-center text-gray-400`,children:[(0,J.jsx)(wD,{size:32,className:`mb-3 text-gray-600`}),(0,J.jsx)(`h2`,{className:`mb-2 text-base font-semibold text-gray-200`,children:`Nothing to manage yet`}),(0,J.jsx)(`p`,{className:`text-sm leading-relaxed text-gray-500`,children:`The admin shell is empty until a plugin contributes an admin page. Open the Plugin Manager from the chat shell to enable a plugin that ships one (e.g. MicroSandbox).`})]})}function KR({title:e,message:t}){return(0,J.jsx)(`div`,{className:`mx-auto max-w-2xl px-6 py-12`,children:(0,J.jsxs)(`div`,{className:`rounded-md border border-rose-700/50 bg-rose-950/40 p-4 text-sm text-rose-200`,children:[(0,J.jsx)(`strong`,{className:`mb-1 block`,children:e}),(0,J.jsx)(`p`,{className:`leading-relaxed text-rose-300`,children:t})]})})}function qR(e){return e?tF[e]??null:null}function JR({pluginId:e}){let t=gr(e=>e.plugins)?.find(t=>t.id===e);return(0,J.jsxs)(`div`,{className:`mx-auto max-w-5xl p-6`,children:[(0,J.jsxs)(`div`,{className:`mb-6`,children:[(0,J.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold text-gray-100`,children:[(0,J.jsx)(wD,{size:18,className:`text-brand-400`}),t?t.displayName:e]}),t?.description&&(0,J.jsx)(`p`,{className:`mt-1 max-w-3xl text-[12px] text-gray-500`,children:t.description})]}),t?(0,J.jsxs)(`section`,{children:[(0,J.jsxs)(`div`,{className:`mb-2`,children:[(0,J.jsx)(`h2`,{className:`text-[13px] font-semibold uppercase tracking-wide text-gray-400`,children:`Configuration`}),(0,J.jsx)(`p`,{className:`text-[11px] text-gray-500`,children:`Saving re-activates the plugin so changes take effect on the next request.`})]}),(0,J.jsx)(`div`,{className:`rounded-md border border-gray-800 bg-gray-900/30 p-4`,children:(0,J.jsx)(OR,{plugin:t})})]}):(0,J.jsxs)(`div`,{className:`rounded-md border border-dashed border-gray-800 px-4 py-6 text-center text-[12px] text-gray-500`,children:[`Plugin `,(0,J.jsx)(`code`,{children:e}),` is not active.`]})]})}var YR=5e5;function XR(e){return e.startsWith(`text/`)||e.startsWith(`application/json`)?`text`:e.startsWith(`image/`)?`image`:e===`application/pdf`?`pdf`:e.startsWith(`video/`)?`video`:e.startsWith(`audio/`)?`audio`:`binary`}function ZR(e){switch(e.toLowerCase().match(/\.[a-z0-9]+$/)?.[0]??``){case`.png`:return`image/png`;case`.jpg`:case`.jpeg`:return`image/jpeg`;case`.gif`:return`image/gif`;case`.webp`:return`image/webp`;case`.svg`:return`image/svg+xml`;case`.pdf`:return`application/pdf`;case`.mp4`:return`video/mp4`;case`.webm`:return`video/webm`;case`.mp3`:return`audio/mpeg`;case`.wav`:return`audio/wav`;case`.ogg`:return`audio/ogg`;case`.json`:return`application/json; charset=utf-8`;case`.md`:return`text/markdown; charset=utf-8`;case`.html`:return`text/html; charset=utf-8`;case`.css`:return`text/css; charset=utf-8`;case`.js`:case`.jsx`:case`.ts`:case`.tsx`:return`text/javascript; charset=utf-8`;case`.csv`:return`text/csv; charset=utf-8`;case``:return`application/octet-stream`;default:return`text/plain; charset=utf-8`}}function QR(e){let t=e.replace(/^workspace:\/\/+/,`/`),n=t.split(`/`).filter(Boolean);return n[n.length-1]??t}function $R(e){let t=e.replace(/^workspace:\/\/+/,`/`);return`/api/p/files/raw?path=${encodeURIComponent(t)}`}function ez(){let{Modal:e,DocumentViewer:t}=_F(),[n,r]=(0,S.useState)(null),[i,a]=(0,S.useState)({kind:`loading`});(0,S.useEffect)(()=>{let e=e=>{let t=e.detail;t?.path&&r({path:t.path})};return window.addEventListener(`tianshu:files:open`,e),()=>window.removeEventListener(`tianshu:files:open`,e)},[]),(0,S.useEffect)(()=>{if(!n)return;a({kind:`loading`});let e=new AbortController,t=n.path.replace(/^workspace:\/\/+/,`/`);return(async()=>{try{let n=await fetch(`/api/p/files/read?path=${encodeURIComponent(t)}`,{credentials:`include`,signal:e.signal});if(n.status===404){a({kind:`error`,message:`File not found.`});return}if(n.status===413){a({kind:`binary`,mime:`application/octet-stream`,size:(await n.json()).size??0});return}if(!n.ok){a({kind:`error`,message:`read failed: HTTP ${n.status}`});return}let r=await n.json(),i=r.size??0;if(!r.binary){let e=ZR(t);a({kind:`text`,content:r.content??``,truncated:!!r.truncated,size:i,mime:e});return}let o=ZR(t),s=XR(o);if(s===`image`||s===`pdf`||s===`video`||s===`audio`){a({kind:s,mime:o});return}a({kind:`binary`,mime:o,size:i})}catch(e){if(e.name===`AbortError`)return;a({kind:`error`,message:e instanceof Error?e.message:String(e)})}})(),()=>e.abort()},[n]);let o=(0,S.useCallback)(()=>r(null),[]);if((0,S.useEffect)(()=>{if(!n)return;let e=e=>{e.key===`Escape`&&o()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n,o]),!n)return null;let s=QR(n.path),c=n.path.replace(/^workspace:\/\/+/,`/`),l=$R(c);return(0,J.jsx)(e,{isOpen:!0,onClose:o,size:`xl`,hideHeader:!0,className:`bg-gray-900`,children:(0,J.jsxs)(`div`,{className:`flex h-full max-h-[90vh] flex-col`,children:[(0,J.jsxs)(`header`,{className:`flex items-center justify-between border-b border-gray-800 px-4 py-2.5`,children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-sm`,children:[(0,J.jsx)(sh,{size:14,className:`shrink-0 text-gray-400`}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`div`,{className:`truncate font-medium text-gray-100`,title:c,children:s}),(0,J.jsx)(`div`,{className:`truncate font-mono text-[10px] text-gray-500`,children:c})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`a`,{href:l,target:`_blank`,rel:`noopener noreferrer`,className:`rounded px-2 py-1 text-[11px] text-gray-400 hover:bg-gray-800 hover:text-gray-200`,title:`Open in new tab / download`,children:`↗ raw`}),(0,J.jsx)(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-gray-400 hover:bg-gray-800 hover:text-gray-200`,"aria-label":`Close`,children:(0,J.jsx)(IP,{size:14})})]})]}),(0,J.jsxs)(`div`,{className:`flex-1 overflow-auto bg-gray-950 p-3`,children:[i.kind===`loading`&&(0,J.jsxs)(`div`,{className:`flex h-32 items-center justify-center text-gray-500`,children:[(0,J.jsx)(db,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading…`]}),i.kind===`text`&&(0,J.jsxs)(J.Fragment,{children:[i.truncated&&(0,J.jsxs)(`div`,{className:`mb-2 rounded border border-amber-900/40 bg-amber-950/30 px-2 py-1 text-[11px] text-amber-200`,children:[`Truncated at `,YR.toLocaleString(),` bytes — open in a new tab via the ↗ button to see the full file.`]}),(0,J.jsx)(t,{content:i.content,filename:s,className:`!p-0`})]}),i.kind===`image`&&(0,J.jsx)(`img`,{src:l,alt:s,className:`mx-auto max-h-[75vh] object-contain`}),i.kind===`pdf`&&(0,J.jsx)(`iframe`,{src:l,title:s,className:`h-[75vh] w-full rounded border border-gray-800 bg-white`}),i.kind===`video`&&(0,J.jsx)(`video`,{src:l,controls:!0,className:`mx-auto max-h-[75vh] w-full`,children:(0,J.jsx)(`track`,{kind:`captions`})}),i.kind===`audio`&&(0,J.jsx)(`audio`,{src:l,controls:!0,className:`mx-auto w-full`,children:(0,J.jsx)(`track`,{kind:`captions`})}),i.kind===`binary`&&(0,J.jsxs)(`div`,{className:`space-y-2 text-center text-sm text-gray-300`,children:[(0,J.jsxs)(`div`,{className:`text-gray-200`,children:[i.mime,` · `,i.size.toLocaleString(),` bytes`]}),(0,J.jsxs)(`div`,{className:`text-[12px] text-gray-500`,children:[`Binary file — preview not available. Use the`,` `,(0,J.jsx)(`span`,{className:`text-gray-300`,children:`↗ raw`}),` button to download.`]})]}),i.kind===`error`&&(0,J.jsx)(`div`,{className:`rounded border border-red-900/50 bg-red-950/40 px-3 py-2 text-[12px] text-red-300`,children:i.message})]})]})})}function tz(){return(0,J.jsxs)(Nn,{children:[(0,J.jsxs)(Gt,{children:[(0,J.jsxs)(Ut,{path:`/tenants/:tenantId/users/:userId`,children:[(0,J.jsx)(Ut,{index:!0,element:(0,J.jsx)(lR,{})}),(0,J.jsx)(Ut,{path:`admin/*`,element:(0,J.jsx)(VR,{})}),(0,J.jsx)(Ut,{path:`*`,element:(0,J.jsx)(Ht,{to:``,replace:!0})})]}),(0,J.jsx)(Ut,{path:`*`,element:(0,J.jsx)(Ht,{to:_R(`/`),replace:!0})})]}),(0,J.jsx)(ez,{})]})}var nz={sm:`max-w-md`,md:`max-w-2xl`,lg:`max-w-3xl`,xl:`max-w-5xl`},rz=`button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`;function iz({isOpen:e,onClose:t,title:n,size:r=`md`,className:i=``,hideHeader:a=!1,children:o}){let s=(0,S.useRef)(null),c=(0,S.useRef)(null);(0,S.useEffect)(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e]),(0,S.useEffect)(()=>{if(!e)return;c.current=document.activeElement instanceof HTMLElement?document.activeElement:null;let n=e=>{e.key===`Escape`&&(e.stopPropagation(),t())};window.addEventListener(`keydown`,n);let r=window.setTimeout(()=>{let e=s.current;e&&e.querySelector(rz)?.focus()},0);return()=>{window.removeEventListener(`keydown`,n),window.clearTimeout(r);let e=c.current;e&&document.body.contains(e)&&e.focus()}},[e,t]);function l(e){if(e.key!==`Tab`)return;let t=s.current;if(!t)return;let n=Array.from(t.querySelectorAll(rz)).filter(e=>!e.hasAttribute(`inert`));if(n.length===0)return;let r=n[0],i=n[n.length-1];e.shiftKey?document.activeElement===r&&(i.focus(),e.preventDefault()):document.activeElement===i&&(r.focus(),e.preventDefault())}function u(e){e.target===e.currentTarget&&t()}return e?(0,FL.createPortal)((0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4 backdrop-blur-sm`,onMouseDown:u,role:`dialog`,"aria-modal":`true`,"aria-label":n,children:(0,J.jsxs)(`div`,{ref:s,className:`flex max-h-[85vh] w-full ${nz[r]} flex-col overflow-hidden rounded-xl border border-gray-700 bg-gray-900 shadow-2xl ${i}`,onKeyDown:l,children:[!a&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-800 px-4 py-2.5`,children:[(0,J.jsx)(`div`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-gray-100`,children:n}),(0,J.jsx)(`button`,{type:`button`,onClick:t,className:`btn-ghost p-1.5`,"aria-label":`Close`,children:(0,J.jsx)(IP,{size:16})})]}),(0,J.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:o})]})}),document.body):null}function az(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var oz=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,sz=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,cz={};function lz(e,t){return((t||cz).jsx?sz:oz).test(e)}var uz=/[ \t\n\f\r]/g;function dz(e){return typeof e==`object`?e.type===`text`?fz(e.value):!1:fz(e)}function fz(e){return e.replace(uz,``)===``}var pz=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};pz.prototype.normal={},pz.prototype.property={},pz.prototype.space=void 0;function mz(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new pz(n,r,t)}function hz(e){return e.toLowerCase()}var gz=class{constructor(e,t){this.attribute=t,this.property=e}};gz.prototype.attribute=``,gz.prototype.booleanish=!1,gz.prototype.boolean=!1,gz.prototype.commaOrSpaceSeparated=!1,gz.prototype.commaSeparated=!1,gz.prototype.defined=!1,gz.prototype.mustUseProperty=!1,gz.prototype.number=!1,gz.prototype.overloadedBoolean=!1,gz.prototype.property=``,gz.prototype.spaceSeparated=!1,gz.prototype.space=void 0;var _z=s({boolean:()=>Y,booleanish:()=>yz,commaOrSpaceSeparated:()=>Cz,commaSeparated:()=>Sz,number:()=>X,overloadedBoolean:()=>bz,spaceSeparated:()=>xz}),vz=0,Y=wz(),yz=wz(),bz=wz(),X=wz(),xz=wz(),Sz=wz(),Cz=wz();function wz(){return 2**++vz}var Tz=Object.keys(_z),Ez=class extends gz{constructor(e,t,n,r){let i=-1;if(super(e,t),Dz(this,`space`,r),typeof n==`number`)for(;++i<Tz.length;){let e=Tz[i];Dz(this,Tz[i],(n&_z[e])===_z[e])}}};Ez.prototype.defined=!0;function Dz(e,t,n){n&&(e[t]=n)}function Oz(e){let t={},n={};for(let[r,i]of Object.entries(e.properties)){let a=new Ez(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(a.mustUseProperty=!0),t[r]=a,n[hz(r)]=r,n[hz(a.attribute)]=r}return new pz(t,n,e.space)}var kz=Oz({properties:{ariaActiveDescendant:null,ariaAtomic:yz,ariaAutoComplete:null,ariaBusy:yz,ariaChecked:yz,ariaColCount:X,ariaColIndex:X,ariaColSpan:X,ariaControls:xz,ariaCurrent:null,ariaDescribedBy:xz,ariaDetails:null,ariaDisabled:yz,ariaDropEffect:xz,ariaErrorMessage:null,ariaExpanded:yz,ariaFlowTo:xz,ariaGrabbed:yz,ariaHasPopup:null,ariaHidden:yz,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:xz,ariaLevel:X,ariaLive:null,ariaModal:yz,ariaMultiLine:yz,ariaMultiSelectable:yz,ariaOrientation:null,ariaOwns:xz,ariaPlaceholder:null,ariaPosInSet:X,ariaPressed:yz,ariaReadOnly:yz,ariaRelevant:null,ariaRequired:yz,ariaRoleDescription:xz,ariaRowCount:X,ariaRowIndex:X,ariaRowSpan:X,ariaSelected:yz,ariaSetSize:X,ariaSort:null,ariaValueMax:X,ariaValueMin:X,ariaValueNow:X,ariaValueText:null,role:null},transform(e,t){return t===`role`?t:`aria-`+t.slice(4).toLowerCase()}});function Az(e,t){return t in e?e[t]:t}function jz(e,t){return Az(e,t.toLowerCase())}var Mz=Oz({attributes:{acceptcharset:`accept-charset`,classname:`class`,htmlfor:`for`,httpequiv:`http-equiv`},mustUseProperty:[`checked`,`multiple`,`muted`,`selected`],properties:{abbr:null,accept:Sz,acceptCharset:xz,accessKey:xz,action:null,allow:null,allowFullScreen:Y,allowPaymentRequest:Y,allowUserMedia:Y,alpha:Y,alt:null,as:null,async:Y,autoCapitalize:null,autoComplete:xz,autoFocus:Y,autoPlay:Y,blocking:xz,capture:null,charSet:null,checked:Y,cite:null,className:xz,closedBy:null,colorSpace:null,cols:X,colSpan:X,command:null,commandFor:null,content:null,contentEditable:yz,controls:Y,controlsList:xz,coords:X|Sz,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Y,defer:Y,dir:null,dirName:null,disabled:Y,download:bz,draggable:yz,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Y,formTarget:null,headers:xz,height:X,hidden:bz,high:X,href:null,hrefLang:null,htmlFor:xz,httpEquiv:xz,id:null,imageSizes:null,imageSrcSet:null,inert:Y,inputMode:null,integrity:null,is:null,isMap:Y,itemId:null,itemProp:xz,itemRef:xz,itemScope:Y,itemType:xz,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Y,low:X,manifest:null,max:null,maxLength:X,media:null,method:null,min:null,minLength:X,multiple:Y,muted:Y,name:null,nonce:null,noModule:Y,noValidate:Y,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:Y,optimum:X,pattern:null,ping:xz,placeholder:null,playsInline:Y,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Y,referrerPolicy:null,rel:xz,required:Y,reversed:Y,rows:X,rowSpan:X,sandbox:xz,scope:null,scoped:Y,seamless:Y,selected:Y,shadowRootClonable:Y,shadowRootCustomElementRegistry:Y,shadowRootDelegatesFocus:Y,shadowRootMode:null,shadowRootSerializable:Y,shape:null,size:X,sizes:null,slot:null,span:X,spellCheck:yz,src:null,srcDoc:null,srcLang:null,srcSet:null,start:X,step:null,style:null,tabIndex:X,target:null,title:null,translate:null,type:null,typeMustMatch:Y,useMap:null,value:yz,width:X,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:xz,axis:null,background:null,bgColor:null,border:X,borderColor:null,bottomMargin:X,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Y,declare:Y,event:null,face:null,frame:null,frameBorder:null,hSpace:X,leftMargin:X,link:null,longDesc:null,lowSrc:null,marginHeight:X,marginWidth:X,noResize:Y,noHref:Y,noShade:Y,noWrap:Y,object:null,profile:null,prompt:null,rev:null,rightMargin:X,rules:null,scheme:null,scrolling:yz,standby:null,summary:null,text:null,topMargin:X,valueType:null,version:null,vAlign:null,vLink:null,vSpace:X,allowTransparency:null,autoCorrect:null,autoSave:null,credentialless:Y,disablePictureInPicture:Y,disableRemotePlayback:Y,exportParts:Sz,part:xz,prefix:null,property:null,results:X,security:null,unselectable:null},space:`html`,transform:jz}),Nz=Oz({attributes:{accentHeight:`accent-height`,alignmentBaseline:`alignment-baseline`,arabicForm:`arabic-form`,baselineShift:`baseline-shift`,capHeight:`cap-height`,className:`class`,clipPath:`clip-path`,clipRule:`clip-rule`,colorInterpolation:`color-interpolation`,colorInterpolationFilters:`color-interpolation-filters`,colorProfile:`color-profile`,colorRendering:`color-rendering`,crossOrigin:`crossorigin`,dataType:`datatype`,dominantBaseline:`dominant-baseline`,enableBackground:`enable-background`,fillOpacity:`fill-opacity`,fillRule:`fill-rule`,floodColor:`flood-color`,floodOpacity:`flood-opacity`,fontFamily:`font-family`,fontSize:`font-size`,fontSizeAdjust:`font-size-adjust`,fontStretch:`font-stretch`,fontStyle:`font-style`,fontVariant:`font-variant`,fontWeight:`font-weight`,glyphName:`glyph-name`,glyphOrientationHorizontal:`glyph-orientation-horizontal`,glyphOrientationVertical:`glyph-orientation-vertical`,hrefLang:`hreflang`,horizAdvX:`horiz-adv-x`,horizOriginX:`horiz-origin-x`,horizOriginY:`horiz-origin-y`,imageRendering:`image-rendering`,letterSpacing:`letter-spacing`,lightingColor:`lighting-color`,markerEnd:`marker-end`,markerMid:`marker-mid`,markerStart:`marker-start`,maskType:`mask-type`,navDown:`nav-down`,navDownLeft:`nav-down-left`,navDownRight:`nav-down-right`,navLeft:`nav-left`,navNext:`nav-next`,navPrev:`nav-prev`,navRight:`nav-right`,navUp:`nav-up`,navUpLeft:`nav-up-left`,navUpRight:`nav-up-right`,onAbort:`onabort`,onActivate:`onactivate`,onAfterPrint:`onafterprint`,onBeforePrint:`onbeforeprint`,onBegin:`onbegin`,onCancel:`oncancel`,onCanPlay:`oncanplay`,onCanPlayThrough:`oncanplaythrough`,onChange:`onchange`,onClick:`onclick`,onClose:`onclose`,onCopy:`oncopy`,onCueChange:`oncuechange`,onCut:`oncut`,onDblClick:`ondblclick`,onDrag:`ondrag`,onDragEnd:`ondragend`,onDragEnter:`ondragenter`,onDragExit:`ondragexit`,onDragLeave:`ondragleave`,onDragOver:`ondragover`,onDragStart:`ondragstart`,onDrop:`ondrop`,onDurationChange:`ondurationchange`,onEmptied:`onemptied`,onEnd:`onend`,onEnded:`onended`,onError:`onerror`,onFocus:`onfocus`,onFocusIn:`onfocusin`,onFocusOut:`onfocusout`,onHashChange:`onhashchange`,onInput:`oninput`,onInvalid:`oninvalid`,onKeyDown:`onkeydown`,onKeyPress:`onkeypress`,onKeyUp:`onkeyup`,onLoad:`onload`,onLoadedData:`onloadeddata`,onLoadedMetadata:`onloadedmetadata`,onLoadStart:`onloadstart`,onMessage:`onmessage`,onMouseDown:`onmousedown`,onMouseEnter:`onmouseenter`,onMouseLeave:`onmouseleave`,onMouseMove:`onmousemove`,onMouseOut:`onmouseout`,onMouseOver:`onmouseover`,onMouseUp:`onmouseup`,onMouseWheel:`onmousewheel`,onOffline:`onoffline`,onOnline:`ononline`,onPageHide:`onpagehide`,onPageShow:`onpageshow`,onPaste:`onpaste`,onPause:`onpause`,onPlay:`onplay`,onPlaying:`onplaying`,onPopState:`onpopstate`,onProgress:`onprogress`,onRateChange:`onratechange`,onRepeat:`onrepeat`,onReset:`onreset`,onResize:`onresize`,onScroll:`onscroll`,onSeeked:`onseeked`,onSeeking:`onseeking`,onSelect:`onselect`,onShow:`onshow`,onStalled:`onstalled`,onStorage:`onstorage`,onSubmit:`onsubmit`,onSuspend:`onsuspend`,onTimeUpdate:`ontimeupdate`,onToggle:`ontoggle`,onUnload:`onunload`,onVolumeChange:`onvolumechange`,onWaiting:`onwaiting`,onZoom:`onzoom`,overlinePosition:`overline-position`,overlineThickness:`overline-thickness`,paintOrder:`paint-order`,panose1:`panose-1`,pointerEvents:`pointer-events`,referrerPolicy:`referrerpolicy`,renderingIntent:`rendering-intent`,shapeRendering:`shape-rendering`,stopColor:`stop-color`,stopOpacity:`stop-opacity`,strikethroughPosition:`strikethrough-position`,strikethroughThickness:`strikethrough-thickness`,strokeDashArray:`stroke-dasharray`,strokeDashOffset:`stroke-dashoffset`,strokeLineCap:`stroke-linecap`,strokeLineJoin:`stroke-linejoin`,strokeMiterLimit:`stroke-miterlimit`,strokeOpacity:`stroke-opacity`,strokeWidth:`stroke-width`,tabIndex:`tabindex`,textAnchor:`text-anchor`,textDecoration:`text-decoration`,textRendering:`text-rendering`,transformOrigin:`transform-origin`,typeOf:`typeof`,underlinePosition:`underline-position`,underlineThickness:`underline-thickness`,unicodeBidi:`unicode-bidi`,unicodeRange:`unicode-range`,unitsPerEm:`units-per-em`,vAlphabetic:`v-alphabetic`,vHanging:`v-hanging`,vIdeographic:`v-ideographic`,vMathematical:`v-mathematical`,vectorEffect:`vector-effect`,vertAdvY:`vert-adv-y`,vertOriginX:`vert-origin-x`,vertOriginY:`vert-origin-y`,wordSpacing:`word-spacing`,writingMode:`writing-mode`,xHeight:`x-height`,playbackOrder:`playbackorder`,timelineBegin:`timelinebegin`},properties:{about:Cz,accentHeight:X,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:X,amplitude:X,arabicForm:null,ascent:X,attributeName:null,attributeType:null,azimuth:X,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:X,by:null,calcMode:null,capHeight:X,className:xz,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:X,diffuseConstant:X,direction:null,display:null,dur:null,divisor:X,dominantBaseline:null,download:Y,dx:null,dy:null,edgeMode:null,editable:null,elevation:X,enableBackground:null,end:null,event:null,exponent:X,externalResourcesRequired:null,fill:null,fillOpacity:X,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:Sz,g2:Sz,glyphName:Sz,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:X,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:X,horizOriginX:X,horizOriginY:X,id:null,ideographic:X,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:X,k:X,k1:X,k2:X,k3:X,k4:X,kernelMatrix:Cz,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:X,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskType:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:X,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:X,overlineThickness:X,paintOrder:null,panose1:null,path:null,pathLength:X,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:xz,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:X,pointsAtY:X,pointsAtZ:X,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:Cz,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:Cz,rev:Cz,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:Cz,requiredFeatures:Cz,requiredFonts:Cz,requiredFormats:Cz,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:X,specularExponent:X,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:X,strikethroughThickness:X,string:null,stroke:null,strokeDashArray:Cz,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:X,strokeOpacity:X,strokeWidth:null,style:null,surfaceScale:X,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:Cz,tabIndex:X,tableValues:null,target:null,targetX:X,targetY:X,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:Cz,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:X,underlineThickness:X,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:X,values:null,vAlphabetic:X,vMathematical:X,vectorEffect:null,vHanging:X,vIdeographic:X,version:null,vertAdvY:X,vertOriginX:X,vertOriginY:X,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:X,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:`svg`,transform:Az}),Pz=Oz({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:`xlink`,transform(e,t){return`xlink:`+t.slice(5).toLowerCase()}}),Fz=Oz({attributes:{xmlnsxlink:`xmlns:xlink`},properties:{xmlnsXLink:null,xmlns:null},space:`xmlns`,transform:jz}),Iz=Oz({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:`xml`,transform(e,t){return`xml:`+t.slice(3).toLowerCase()}}),Lz={classId:`classID`,dataType:`datatype`,itemId:`itemID`,strokeDashArray:`strokeDasharray`,strokeDashOffset:`strokeDashoffset`,strokeLineCap:`strokeLinecap`,strokeLineJoin:`strokeLinejoin`,strokeMiterLimit:`strokeMiterlimit`,typeOf:`typeof`,xLinkActuate:`xlinkActuate`,xLinkArcRole:`xlinkArcrole`,xLinkHref:`xlinkHref`,xLinkRole:`xlinkRole`,xLinkShow:`xlinkShow`,xLinkTitle:`xlinkTitle`,xLinkType:`xlinkType`,xmlnsXLink:`xmlnsXlink`},Rz=/[A-Z]/g,zz=/-[a-z]/g,Bz=/^data[-\w.:]+$/i;function Vz(e,t){let n=hz(t),r=t,i=gz;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)===`data`&&Bz.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(zz,Uz);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!zz.test(e)){let n=e.replace(Rz,Hz);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=Ez}return new i(r,t)}function Hz(e){return`-`+e.toLowerCase()}function Uz(e){return e.charAt(1).toUpperCase()}var Wz=mz([kz,Mz,Pz,Fz,Iz],`html`),Gz=mz([kz,Nz,Pz,Fz,Iz],`svg`);function Kz(e){return e.join(` `).trim()}var qz=o(((e,t)=>{var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,i=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,l=/^\s+|\s+$/g,u=`
32
+ …(truncated)`}function kL(){return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1`,"aria-label":`assistant is typing`,children:[(0,J.jsx)(AL,{delay:`0ms`}),(0,J.jsx)(AL,{delay:`150ms`}),(0,J.jsx)(AL,{delay:`300ms`})]})}function AL({delay:e}){return(0,J.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-gray-500`,style:{animation:`tianshuTypingDot 1.2s ease-in-out infinite`,animationDelay:e}})}function jL(e){let t=new Map;for(let n of e)n.role===`tool`&&n.toolResult&&t.set(n.toolResult.callId,n.toolResult);let n=[];for(let r of e){if(r.role===`tool`)continue;if(r.role===`assistant`&&(r.toolCalls&&r.toolCalls.length>0||r.blocks&&r.blocks.length>0)){let e=(r.toolCalls??[]).map(e=>({...e,result:t.get(e.id)})),i=r.blocks?.map(e=>e.kind===`toolCall`?{...e,result:t.get(e.id)}:e),{toolCalls:a,toolResult:o,blocks:s,...c}=r;n.push({...c,resolvedToolCalls:e.length>0?e:void 0,resolvedBlocks:i});continue}let{toolCalls:e,toolResult:i,blocks:a,...o}=r;n.push(o)}return n}function ML(e){return`att-${e.toString(36)}-${Math.random().toString(36).slice(2,6)}`}var NL=ir((e,t)=>({attachments:[],transforms:[],_nextId:1,addAttachment:n=>{let r=t()._nextId,i=ML(r);return e(e=>({_nextId:e._nextId+1,attachments:[...e.attachments,{...n,id:i}]})),i},updateAttachment:(t,n)=>e(e=>{let r=e.attachments.findIndex(e=>e.id===t);if(r<0)return{};let i=e.attachments.slice();return i[r]={...i[r],...n},{attachments:i}}),removeAttachment:t=>e(e=>({attachments:e.attachments.filter(e=>e.id!==t)})),registerDraftTransform:t=>(e(e=>e.transforms.includes(t)?{}:{transforms:[...e.transforms,t]}),()=>{e(e=>({transforms:e.transforms.filter(e=>e!==t)}))}),clearAll:()=>e({attachments:[]}),hasPending:()=>t().attachments.some(e=>e.status===`uploading`),applyTransforms:async e=>{let{transforms:n,attachments:r}=t();if(n.length===0)return e;let i=r.filter(e=>e.status===`ready`),a=e;for(let e of n)a=await e(a,i);return a}}));function PL(){let e=NL.getState();return{get attachments(){return NL.getState().attachments},addAttachment:e.addAttachment,updateAttachment:e.updateAttachment,removeAttachment:e.removeAttachment,registerDraftTransform:e.registerDraftTransform}}var FL=l(h(),1);function IL(){let e=M(e=>e.models),t=M(e=>e.preferredModel),n=M(e=>e.setPreferredModel),r=M(e=>e.me?.defaultModel?.id??null),[i,a]=(0,S.useState)(!1),[o,s]=(0,S.useState)({top:0,right:0}),c=(0,S.useRef)(null),l=(0,S.useRef)(null),u=(0,S.useCallback)(()=>{if(!c.current)return;let e=c.current.getBoundingClientRect();s({top:e.top,right:window.innerWidth-e.right})},[]);if((0,S.useEffect)(()=>{if(!i)return;u();let e=e=>{let t=e.target;c.current?.contains(t)||l.current?.contains(t)||a(!1)},t=()=>u();return document.addEventListener(`mousedown`,e),window.addEventListener(`resize`,t),()=>{document.removeEventListener(`mousedown`,e),window.removeEventListener(`resize`,t)}},[i,u]),e.length===0)return null;let d=t=>!!t&&e.some(e=>e.id===t),f=d(t)?t:d(r)?r:e[0].id,p=e.find(e=>e.id===f)?.name??f.split(`/`).pop()??`Model`,m=[];for(let t of e){let e=t.group??`Other`,n=m.find(t=>t.label===e);n||(n={label:e,items:[]},m.push(n)),n.items.push(t)}let h=e=>{a(!1),e!==f&&n(e)};return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{ref:c,type:`button`,onClick:()=>a(e=>!e),className:`inline-flex items-center gap-1 rounded-full bg-gray-700/60 py-1 pl-2.5 pr-2 text-xs font-medium text-gray-300 transition-colors hover:bg-gray-700`,title:f,children:[(0,J.jsx)(`span`,{className:`max-w-[160px] truncate`,children:p}),(0,J.jsx)(Fl,{size:12,className:`text-gray-400 transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,FL.createPortal)((0,J.jsx)(`div`,{ref:l,className:`fixed z-[9999] max-h-80 w-64 overflow-y-auto rounded-xl border border-gray-700 bg-gray-800 py-1 shadow-2xl`,style:{bottom:`calc(100vh - ${o.top}px + 8px)`,right:`${o.right}px`},children:m.map(e=>(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`px-3 pb-1 pt-2.5 text-[10px] font-semibold uppercase tracking-wider text-gray-500`,children:e.label}),e.items.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>h(e.id),className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors `+(e.id===f?`bg-gray-700/60 text-white`:`text-gray-300 hover:bg-gray-700/40`),title:e.id,children:[(0,J.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),e.reasoning&&(0,J.jsx)(`span`,{className:`shrink-0 rounded bg-amber-500/15 px-1 py-px text-[9px] text-amber-300`,children:`reasoning`}),e.id===f&&(0,J.jsx)(El,{size:14,className:`shrink-0 text-blue-400`})]},e.id))]},e.label))}),document.body)]})}function LL(){let e=M(e=>e.me),t=gr(e=>e.plugins);if(!e||!t)return null;let n=[];for(let e of t){if(e.state!==`active`)continue;let t=e.contributes.composerActions??[];for(let r of t)n.push({...r,pluginId:e.id,pluginVersion:e.version,pluginDisplayName:e.displayName,clientEntry:e.clientEntry})}if(n.sort((e,t)=>(e.order??100)-(t.order??100)),n.length===0)return null;let r=PL();return(0,J.jsx)(J.Fragment,{children:n.map(t=>{let n=KI(t.clientEntry,t.component);return n?(0,J.jsx)(n,{tenantId:e.tenantId,userId:e.userId,plugin:{id:t.pluginId,version:t.pluginVersion,displayName:t.pluginDisplayName},composer:r},`${t.pluginId}.${t.id}`):null})})}var RL=1024,zL=RL*1024;function BL(e){return e<RL?`${e} B`:e<zL?`${(e/RL).toFixed(1)} KB`:`${(e/zL).toFixed(1)} MB`}function VL(){let e=NL(e=>e.attachments),t=NL(e=>e.removeAttachment);return e.length===0?null:(0,J.jsx)(`div`,{className:`flex flex-wrap gap-2 pb-1`,children:e.map(e=>{let n=e.status===`uploading`,r=e.status===`error`;return(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs `+(r?`border-rose-700/60 bg-rose-950/40 text-rose-200`:`border-gray-700 bg-gray-800 text-gray-200`),title:r?e.error??`upload failed`:e.path??e.name,"aria-label":`attachment ${e.name}`,children:[n?(0,J.jsx)(db,{size:12,className:`animate-spin text-brand-400`}):r?(0,J.jsx)(OM,{size:12,className:`text-rose-400`}):(0,J.jsx)(sh,{size:12,className:`text-gray-400`}),(0,J.jsx)(`span`,{className:`max-w-[12rem] truncate`,children:e.name}),(0,J.jsx)(`span`,{className:`text-[10px] text-gray-500`,children:BL(e.size)}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`ml-0.5 rounded p-0.5 text-gray-500 hover:bg-gray-700 hover:text-gray-200`,"aria-label":`remove attachment`,children:(0,J.jsx)(IP,{size:11})})]},e.id)})})}function HL(){let e=M(e=>e.isStreaming),t=M(e=>e.sendPrompt),n=M(e=>e.abort),r=NL(e=>e.attachments.length),i=NL(e=>e.hasPending()),a=NL(e=>e.applyTransforms),o=NL(e=>e.clearAll),[s,c]=(0,S.useState)(``),[l,u]=(0,S.useState)(!1),d=(0,S.useRef)(null);(0,S.useEffect)(()=>{let e=d.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,240)}px`)},[s]);let f=e?!0:l||i?!1:s.trim().length>0||r>0,p=async()=>{if(e){n();return}if(l||i)return;let d=s.trimEnd();if(!(!d&&r===0)){u(!0);try{let e=await a(d),n=NL.getState().attachments.filter(e=>e.status===`ready`&&!!e.path).map(e=>({path:e.path,mimeType:e.mimeType??`application/octet-stream`,name:e.name,size:e.size}));(e.trim().length>0||n.length>0)&&t(e,n.length>0?n:void 0),c(``),o()}finally{u(!1)}}};return(0,J.jsx)(`div`,{className:`border-t border-gray-800 bg-gray-950 px-4 py-3`,children:(0,J.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-2 rounded-2xl border border-gray-800 bg-gray-900 p-3 focus-within:border-gray-700`,children:[(0,J.jsx)(VL,{}),(0,J.jsx)(`textarea`,{ref:d,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),p())},rows:1,placeholder:`Message Tianshu — Enter to send, Shift+Enter for newline`,className:`resize-none bg-transparent text-[14px] leading-relaxed text-gray-100 placeholder:text-gray-500 focus:outline-none`}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,J.jsx)(LL,{})}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(IL,{}),e?(0,J.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-lg p-1.5 text-rose-400 transition-colors hover:bg-gray-700 hover:text-rose-300`,title:`Stop`,children:(0,J.jsx)(lA,{size:18})}):(0,J.jsx)(`button`,{type:`button`,onClick:()=>void p(),disabled:!f,className:`rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-700 hover:text-white disabled:cursor-not-allowed disabled:opacity-30`,title:i?`Waiting for uploads to finish…`:`Send`,"aria-label":`Send`,children:(0,J.jsx)(_D,{size:18})})]})]})]})})}function UL({open:e,onClose:t}){let n=gr(e=>e.plugins),r=gr(e=>e.setPlugins),i=gr(e=>e.load),a=gr(e=>e.refresh),o=gr(e=>e.refreshing),[s,c]=(0,S.useState)(`installed`),[l,u]=(0,S.useState)(null),[d,f]=(0,S.useState)(null),[p,m]=(0,S.useState)(null),[h,g]=(0,S.useState)(!1);if((0,S.useEffect)(()=>{e&&i()},[e,i]),(0,S.useEffect)(()=>{if(!e||s!==`catalog`||l!==null)return;let t=!1;return f(null),ur.pluginCatalog().then(e=>{t||u(e)}).catch(e=>{t||f(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e,s,l]),(0,S.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),!e)return null;async function _(e){let t=e.state!==`active`;m(e.id),f(null);try{r((await ur.setPluginEnabled(e.id,t)).plugins)}catch(e){f(e instanceof Error?e.message:String(e))}finally{m(null)}}async function v(){g(!0),f(null);try{u(await ur.refreshPluginCatalog())}catch(e){f(e instanceof Error?e.message:String(e))}finally{g(!1)}}let y=new Set((n??[]).map(e=>e.id));return(0,J.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`plugin-manager-title`,className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4 backdrop-blur-sm`,onClick:t,children:(0,J.jsxs)(`div`,{className:`flex max-h-[80vh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-gray-700 bg-gray-900 shadow-2xl`,onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-800 px-5 py-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(pT,{size:16,className:`text-brand-400`}),(0,J.jsx)(`h2`,{id:`plugin-manager-title`,className:`text-sm font-semibold text-gray-100`,children:`Plugin Manager`})]}),(0,J.jsx)(`button`,{type:`button`,onClick:t,className:`btn-ghost p-1.5`,"aria-label":`Close`,children:(0,J.jsx)(IP,{size:16})})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-gray-800 px-3 pt-2`,children:[(0,J.jsxs)(WL,{active:s===`installed`,onClick:()=>c(`installed`),children:[`Installed`,n&&(0,J.jsx)(`span`,{className:`ml-1.5 rounded bg-gray-800 px-1.5 py-0.5 text-[9px] text-gray-400`,children:n.length})]}),(0,J.jsxs)(WL,{active:s===`catalog`,onClick:()=>c(`catalog`),children:[`Catalog`,l&&(0,J.jsx)(`span`,{className:`ml-1.5 rounded bg-gray-800 px-1.5 py-0.5 text-[9px] text-gray-400`,children:l.entries.length})]}),(0,J.jsx)(`div`,{className:`flex-1`}),s===`installed`&&(0,J.jsxs)(`button`,{type:`button`,onClick:()=>void a(),disabled:o,className:`btn-ghost flex items-center gap-1.5 px-2 py-1 text-[11px] text-gray-400`,title:`Re-discover plugins on disk (after a manual install or git pull)`,children:[(0,J.jsx)(ZT,{size:12,className:o?`animate-spin`:``}),`Refresh`]}),s===`catalog`&&l&&(0,J.jsxs)(`button`,{type:`button`,onClick:v,disabled:h,className:`btn-ghost flex items-center gap-1.5 px-2 py-1 text-[11px] text-gray-400`,title:`Re-fetch the catalog from the registry`,children:[(0,J.jsx)(ZT,{size:12,className:h?`animate-spin`:``}),`Refresh`]})]}),(0,J.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-4`,children:[d&&(0,J.jsx)(`div`,{className:`mb-3 rounded-md border border-rose-700/50 bg-rose-950/40 px-3 py-2 text-xs text-rose-300`,children:d}),s===`installed`?(0,J.jsx)(GL,{plugins:n,pendingId:p,onToggle:_}):(0,J.jsx)(qL,{catalog:l,installedIds:y})]}),(0,J.jsx)(`div`,{className:`border-t border-gray-800 px-5 py-3 text-[11px] leading-relaxed text-gray-500`,children:s===`installed`?(0,J.jsxs)(J.Fragment,{children:[`Changes persist to`,` `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 text-gray-400`,children:`<tenant>/config.json`}),` `,`and take effect immediately for new requests.`]}):(0,J.jsxs)(J.Fragment,{children:[`Catalog hosted at`,` `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 text-gray-400`,children:`tianshu-ai/plugin-registry`}),`. Install button lands in P2.`]})})]})})}function WL({active:e,onClick:t,children:n}){return(0,J.jsx)(`button`,{type:`button`,onClick:t,className:[`flex items-center rounded-t-md border-b-2 px-3 py-2 text-xs font-medium`,e?`border-brand-500 text-gray-100`:`border-transparent text-gray-500 hover:text-gray-300`].join(` `),children:n})}function GL({plugins:e,pendingId:t,onToggle:n}){return e===null?(0,J.jsxs)(`div`,{className:`flex items-center justify-center py-10 text-sm text-gray-500`,children:[(0,J.jsx)(db,{size:14,className:`mr-2 animate-spin`}),`Loading…`]}):e.length===0?(0,J.jsxs)(`div`,{className:`py-10 text-center text-sm text-gray-500`,children:[`No plugins discovered for this tenant.`,(0,J.jsxs)(`p`,{className:`mt-2 text-xs text-gray-600`,children:[`Builtin plugins ship under`,` `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 text-gray-400`,children:`packages/server/builtinConfig/plugins/`}),`. Tenant plugins live at`,` `,(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 text-gray-400`,children:`<tenant>/_tenant/config/plugins/`}),`. Browse the Catalog tab to find more.`]})]}):(0,J.jsx)(`ul`,{className:`space-y-2`,children:e.map(e=>(0,J.jsxs)(`li`,{className:`flex items-start justify-between gap-3 rounded-lg border border-gray-800 bg-gray-900/50 p-3`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-sm font-medium text-gray-100`,children:e.displayName}),(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 py-0.5 text-[10px] text-gray-400`,children:e.id}),(0,J.jsxs)(`span`,{className:`text-[10px] text-gray-600`,children:[`v`,e.version]}),(0,J.jsx)(YL,{source:e.source}),(0,J.jsx)(XL,{state:e.state})]}),e.description&&(0,J.jsx)(`p`,{className:`mt-1 text-xs text-gray-400`,children:e.description}),(0,J.jsx)(KL,{entry:e}),e.failedReason&&(0,J.jsxs)(`div`,{className:`mt-1 flex items-start gap-1 text-[11px] text-rose-300`,children:[(0,J.jsx)(OM,{size:11,className:`mt-px flex-shrink-0`}),(0,J.jsx)(`span`,{className:`break-all`,children:e.failedReason})]})]}),(0,J.jsx)(ZL,{active:e.state===`active`,pending:t===e.id,disabled:e.state===`failed`||e.state===`client-bundle-missing`,onClick:()=>n(e)})]},e.id))})}function KL({entry:e}){let{provided:t,requires:n,missing:r}=e.capabilities;return t.length===0&&n.length===0&&r.length===0?null:(0,J.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1.5 text-[10px]`,children:[t.map(e=>(0,J.jsxs)(`span`,{className:`rounded bg-emerald-900/40 px-1.5 py-0.5 text-emerald-300`,title:`This plugin provides ${e}`,children:[`provides `,e]},`p-${e}`)),n.filter(e=>!r.includes(e)).map(e=>(0,J.jsxs)(`span`,{className:`rounded bg-sky-900/40 px-1.5 py-0.5 text-sky-300`,title:`This plugin requires ${e} (satisfied)`,children:[`requires `,e]},`r-${e}`)),r.map(e=>(0,J.jsxs)(`span`,{className:`rounded bg-rose-900/40 px-1.5 py-0.5 text-rose-300`,title:`This plugin requires ${e}, but no provider is enabled`,children:[`missing `,e]},`m-${e}`))]})}function qL({catalog:e,installedIds:t}){return e===null?(0,J.jsxs)(`div`,{className:`flex items-center justify-center py-10 text-sm text-gray-500`,children:[(0,J.jsx)(db,{size:14,className:`mr-2 animate-spin`}),`Fetching catalog…`]}):e.entries.length===0?(0,J.jsxs)(`div`,{className:`py-10 text-center text-sm text-gray-500`,children:[`Catalog is empty.`,(0,J.jsxs)(`p`,{className:`mt-2 text-xs text-gray-600`,children:[`The registry is at`,` `,(0,J.jsx)(`a`,{href:`https://github.com/tianshu-ai/plugin-registry`,target:`_blank`,rel:`noreferrer`,className:`text-brand-400 hover:underline`,children:`tianshu-ai/plugin-registry`}),`. Submit a PR to add your plugin.`]})]}):(0,J.jsxs)(J.Fragment,{children:[e.entriesDropped>0&&(0,J.jsxs)(`div`,{className:`mb-3 rounded-md border border-amber-700/50 bg-amber-950/40 px-3 py-2 text-[11px] text-amber-300`,children:[e.entriesDropped,` catalog`,` `,e.entriesDropped===1?`entry was`:`entries were`,` dropped because`,` `,e.entriesDropped===1?`it failed`:`they failed`,` schema validation.`]}),(0,J.jsx)(`ul`,{className:`space-y-2`,children:e.entries.map(e=>(0,J.jsx)(JL,{entry:e,alreadyInstalled:t.has(e.id)},e.id))})]})}function JL({entry:e,alreadyInstalled:t}){return(0,J.jsxs)(`li`,{className:`flex items-start justify-between gap-3 rounded-lg border border-gray-800 bg-gray-900/50 p-3`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-sm font-medium text-gray-100`,children:e.displayName}),(0,J.jsx)(`code`,{className:`rounded bg-gray-800 px-1 py-0.5 text-[10px] text-gray-400`,children:e.id}),(0,J.jsxs)(`span`,{className:`text-[10px] text-gray-600`,children:[`v`,e.latestVersion]}),e.verified&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 rounded bg-emerald-900/40 px-1.5 py-0.5 text-[9px] uppercase text-emerald-300`,children:[(0,J.jsx)(ND,{size:10}),` verified`]}),(0,J.jsxs)(`a`,{href:e.repository,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-[10px] text-gray-500 hover:text-brand-400`,children:[e.author,` `,(0,J.jsx)(Zp,{size:9})]})]}),(0,J.jsx)(`p`,{className:`mt-1 text-xs text-gray-400`,children:e.description}),e.tags.length>0&&(0,J.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:e.tags.map(e=>(0,J.jsx)(`span`,{className:`rounded bg-gray-800 px-1.5 py-px text-[9px] text-gray-500`,children:e},e))})]}),(0,J.jsx)(`button`,{type:`button`,disabled:!0,title:`Install lands in P2`,className:`flex-shrink-0 cursor-not-allowed rounded-md bg-gray-800 px-3 py-1.5 text-[11px] font-medium text-gray-500`,children:t?`Installed`:`Install`})]})}function YL({source:e}){return(0,J.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[9px] uppercase ${e===`builtin`?`bg-gray-800 text-gray-400`:`bg-violet-900/50 text-violet-300`}`,children:e})}function XL({state:e}){switch(e){case`active`:return(0,J.jsxs)(`span`,{className:`flex items-center gap-1 rounded bg-emerald-900/50 px-1.5 py-0.5 text-[9px] uppercase text-emerald-300`,children:[(0,J.jsx)(W,{size:10}),` active`]});case`disabled`:return(0,J.jsxs)(`span`,{className:`flex items-center gap-1 rounded bg-gray-800 px-1.5 py-0.5 text-[9px] uppercase text-gray-400`,children:[(0,J.jsx)(sw,{size:10}),` disabled`]});case`failed`:return(0,J.jsxs)(`span`,{className:`flex items-center gap-1 rounded bg-rose-900/50 px-1.5 py-0.5 text-[9px] uppercase text-rose-300`,children:[(0,J.jsx)(OM,{size:10}),` failed`]});case`client-bundle-missing`:return(0,J.jsx)(`span`,{className:`rounded bg-amber-900/50 px-1.5 py-0.5 text-[9px] uppercase text-amber-300`,children:`no client bundle`})}}function ZL({active:e,pending:t,disabled:n,onClick:r}){return(0,J.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e,disabled:t||n,onClick:r,className:[`relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer items-center rounded-full transition-colors`,e?`bg-brand-600`:`bg-gray-700`,(t||n)&&`cursor-not-allowed opacity-50`].filter(Boolean).join(` `),title:n?`Plugin cannot be enabled in its current state`:e?`Click to disable`:`Click to enable`,children:[(0,J.jsx)(`span`,{className:[`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform`,e?`translate-x-5`:`translate-x-1`].join(` `)}),t&&(0,J.jsx)(db,{size:10,className:`absolute -right-4 top-1/2 -translate-y-1/2 animate-spin text-gray-400`})]})}var QL={Bot:js,Calendar:jc,FileText:Qm,FolderOpen:$h,Globe:o_,Kanban:Jv,MessageSquare:Vx,Search:fD,Terminal:xj,Wrench:PP};function $L(){let e=gr(e=>e.plugins),t=gr(e=>e.openPanel),n=gr(e=>e.setOpenPanel);if(t!==null||!e)return null;let r=[];for(let t of e){if(t.state!==`active`)continue;let e=t.contributes.topBarButtons??[];for(let n of e)r.push({...n,pluginId:t.id})}return r.sort((e,t)=>(e.order??100)-(t.order??100)),r.length===0?null:(0,J.jsx)(J.Fragment,{children:r.map(e=>{let t=`${e.pluginId}.${e.id}`,r=e.opensPanel?e.opensPanel.includes(`.`)?e.opensPanel:`${e.pluginId}.${e.opensPanel}`:null,i=QL[e.icon]??pT;return(0,J.jsx)(`button`,{type:`button`,title:e.tooltip??e.pluginId,"aria-label":e.tooltip??e.pluginId,onClick:()=>{r&&n(r)},className:`rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-800 hover:text-gray-200`,children:(0,J.jsx)(i,{size:16})},t)})})}function eR(){let e=M(e=>e.messages),t=M(e=>e.me),n=M(e=>e.sidebarOpen),r=M(e=>e.toggleSidebar);M(e=>e.isStreaming);let i=M(e=>e.streamError),a=M(e=>e.clearStreamError),o=M(e=>e.compactNotice),s=M(e=>e.clearCompactNotice),c=M(e=>e.hasMoreHistory),l=M(e=>e.loadingMore),u=M(e=>e.loadEarlier),d=(0,S.useRef)(null),f=(0,S.useRef)(null);(0,S.useEffect)(()=>{let t=e.length>0?e[e.length-1].id:null;t&&t!==f.current&&d.current?.scrollIntoView({behavior:`smooth`}),f.current=t},[e]);let[p,m]=(0,S.useState)(!1),h=t?.config.branding,g=h?.name??`Tianshu`,_=h?.emoji??`⭐`,v=e.length===0;return(0,J.jsxs)(`main`,{className:`flex h-full min-w-0 flex-1 flex-col`,children:[(0,J.jsxs)(`header`,{className:`flex h-12 items-center justify-between border-b border-gray-800 bg-gray-900/50 px-4 backdrop-blur`,children:[(0,J.jsxs)(`div`,{className:`flex items-center`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:r,className:`rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-800 hover:text-gray-200`,title:n?`Hide sidebar`:`Show sidebar`,children:n?(0,J.jsx)(zC,{size:18}):(0,J.jsx)(VC,{size:18})}),(0,J.jsx)(`h1`,{className:`ml-3 text-sm font-medium text-gray-300`,children:`main`}),(0,J.jsxs)(`span`,{className:`ml-3 text-[11px] text-gray-500`,children:[`tenant `,(0,J.jsx)(`span`,{className:`text-gray-300`,children:t?.tenantId??`…`}),` · user`,` `,(0,J.jsx)(`span`,{className:`text-gray-300`,children:t?.userId??`…`})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)($L,{}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>m(!0),className:`rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-800 hover:text-gray-200`,title:`Plugin Manager`,"aria-label":`Open Plugin Manager`,children:(0,J.jsx)(pT,{size:16})})]})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto px-4 py-6`,children:v?(0,J.jsx)(tR,{brandName:g,brandEmoji:_,tenantId:t?.tenantId??`default`}):(0,J.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-4`,children:[c&&(0,J.jsx)(`button`,{type:`button`,onClick:u,disabled:l,className:`w-full rounded-lg bg-gray-800/50 py-2 text-xs text-gray-500 hover:text-gray-300 disabled:cursor-default disabled:opacity-60`,children:l?`Loading…`:`Load earlier messages`}),jL(e).map((e,t)=>(0,J.jsx)(`div`,{className:t===0?``:`mt-4`,children:(0,J.jsx)(bL,{m:e})},e.id)),i&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-rose-700/50 bg-rose-950/40 px-3 py-2 text-sm text-rose-300`,children:[(0,J.jsx)(`span`,{className:`truncate`,children:i}),(0,J.jsx)(`button`,{type:`button`,onClick:a,className:`ml-3 text-[11px] uppercase tracking-wider text-rose-300/80 hover:text-white`,children:`dismiss`})]}),o&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-amber-700/40 bg-amber-950/30 px-3 py-2 text-sm text-amber-200`,children:[(0,J.jsxs)(`span`,{className:`truncate`,children:[`📌 Conversation history compacted (`,o.reason===`auto`?`auto`:`manual`,`):`,` `,o.summarisedCount,` earlier messages summarised,`,` `,o.keptCount,` kept verbatim.`]}),(0,J.jsx)(`button`,{type:`button`,onClick:s,className:`ml-3 text-[11px] uppercase tracking-wider text-amber-300/80 hover:text-white`,children:`dismiss`})]}),(0,J.jsx)(`div`,{ref:d})]})}),(0,J.jsx)(HL,{}),(0,J.jsx)(UL,{open:p,onClose:()=>m(!1)})]})}function tR({brandName:e,brandEmoji:t,tenantId:n}){return(0,J.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center text-center`,children:[(0,J.jsx)(`div`,{className:`mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-brand-600/20`,children:(0,J.jsx)(`span`,{className:`text-2xl`,children:t})}),(0,J.jsxs)(`h2`,{className:`mb-2 text-xl font-semibold text-gray-200`,children:[`Welcome to `,e]}),(0,J.jsxs)(`p`,{className:`max-w-md text-sm text-gray-500`,children:[`An open AI agent platform with a sidecar browser. Day 0: messages persist per-tenant in`,` `,(0,J.jsxs)(`code`,{className:`mx-0.5 rounded bg-gray-800 px-1 py-0.5 text-xs text-gray-400`,children:[`~/.tianshu/tenants/`,n,`/db.sqlite`]}),`. Tools, workspace files, browser, and worker dispatch arrive in later PRs.`]})]})}function nR(){let e=gr(e=>e.plugins),t=gr(e=>e.openPanel),n=gr(e=>e.setOpenPanel);if(!e)return null;let r=[];for(let t of e){if(t.state!==`active`)continue;let e=t.contributes.topBarButtons??[];for(let n of e){let e=n.opensPanel?n.opensPanel.includes(`.`)?n.opensPanel:`${t.id}.${n.opensPanel}`:null;r.push({...n,pluginId:t.id,panelId:e})}}return r.sort((e,t)=>(e.order??100)-(t.order??100)),(0,J.jsxs)(`div`,{className:`flex h-12 items-center gap-1 border-b border-gray-800 bg-gray-950/40 px-2`,children:[(0,J.jsx)(`div`,{className:`flex flex-1 items-center gap-0.5 overflow-x-auto`,children:r.map(e=>{let r=QL[e.icon]??pT,i=e.panelId!==null&&e.panelId===t,a=e.tooltip??e.pluginId;return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>{e.panelId&&n(i?null:e.panelId)},title:a,"aria-label":a,"aria-pressed":i,className:[`group relative flex shrink-0 items-center gap-1.5 rounded-md text-xs transition-all`,i?`bg-gray-700/70 px-2.5 py-1 font-medium text-gray-100`:`px-2 py-1 text-gray-500 hover:bg-gray-800/60 hover:text-gray-200`].join(` `),children:[(0,J.jsx)(r,{size:14}),i?(0,J.jsx)(`span`,{children:a}):(0,J.jsx)(`span`,{className:`sr-only`,children:a})]},`${e.pluginId}.${e.id}`)})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>n(null),title:`Close panel`,"aria-label":`Close panel`,className:`ml-1 rounded-md p-1 text-gray-500 hover:bg-gray-800/60 hover:text-gray-300`,children:(0,J.jsx)(IP,{size:16})})]})}var rR=`tianshu:rightPanelWidth`,iR=384,aR=280,oR=900;function sR(){try{let e=localStorage.getItem(rR),t=e?parseFloat(e):NaN;return Number.isFinite(t)?Math.min(Math.max(t,aR),oR):iR}catch{return iR}}function cR(){let e=M(e=>e.me),t=gr(e=>e.openPanel),n=gr(e=>e.plugins),[r,i]=(0,S.useState)(()=>sR()),[a,o]=(0,S.useState)(!1),s=(0,S.useRef)(null),c=(0,S.useCallback)(e=>{try{localStorage.setItem(rR,String(e))}catch{}},[]),l=(0,S.useCallback)(e=>{e.preventDefault(),s.current={startX:e.clientX,startWidth:r},o(!0);let t=r,n=0,a=e=>{if(!s.current)return;let r=s.current.startX-e.clientX;t=Math.min(Math.max(s.current.startWidth+r,aR),oR),n||=requestAnimationFrame(()=>{n=0,i(t)})},l=()=>{window.removeEventListener(`mousemove`,a),window.removeEventListener(`mouseup`,l),n&&cancelAnimationFrame(n),window.getSelection?.()?.removeAllRanges(),s.current=null,o(!1),c(t)};window.addEventListener(`mousemove`,a),window.addEventListener(`mouseup`,l)},[r,c]),u=(0,S.useCallback)(()=>{i(iR),c(iR)},[c]),d=gr(e=>e.setOpenPanel);if((0,S.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&d(null)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,d]),!t||!n)return null;let f=t.indexOf(`.`);if(f<0)return null;let p=t.slice(0,f),m=t.slice(f+1),h=n.find(e=>e.id===p);if(!h||h.state!==`active`)return null;let g=h.contributes.rightPanels?.find(e=>e.id===m);if(!g)return null;let _=KI(h.clientEntry,g.component);if(!_)return null;let v={tenantId:e?.tenantId??``,userId:e?.userId??``,plugin:{id:h.id,version:h.version,displayName:h.displayName}};return(0,J.jsxs)(`aside`,{className:`relative flex h-full flex-shrink-0 flex-col border-l border-gray-800 bg-gray-950`,style:{width:r},children:[(0,J.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize right panel`,title:`Drag to resize (double-click to reset)`,onMouseDown:l,onDoubleClick:u,className:[`group absolute -left-[3px] top-0 bottom-0 z-10 flex w-[6px] cursor-col-resize items-center justify-center`,a?`bg-blue-500/20`:`hover:bg-blue-500/10`].join(` `),children:(0,J.jsx)(`span`,{"aria-hidden":!0,className:[`h-full w-px`,a?`bg-blue-400`:`bg-transparent group-hover:bg-blue-400/60`].join(` `)})}),(0,J.jsx)(nR,{}),(0,J.jsxs)(`div`,{className:`relative flex-1 overflow-hidden`,children:[a&&(0,J.jsx)(`div`,{className:`absolute inset-0 z-10`}),(0,J.jsx)(_,{...v})]})]})}function lR(){let e=M(e=>e.init),t=M(e=>e.sidebarOpen),n=M(e=>e.meError),r=gr(e=>e.load);return(0,S.useEffect)(()=>{e(),r()},[e,r]),(0,J.jsxs)(`div`,{className:`flex h-screen overflow-hidden bg-gray-950 text-gray-100`,children:[t&&(0,J.jsx)(cL,{}),(0,J.jsx)(eR,{}),(0,J.jsx)(cR,{}),n&&(0,J.jsxs)(`div`,{className:`fixed right-4 top-4 max-w-sm rounded-md border border-rose-700/50 bg-rose-950/90 px-3 py-2 text-sm text-rose-200 shadow-lg`,children:[(0,J.jsx)(`strong`,{className:`mr-1`,children:`/api/me failed:`}),n]})]})}var uR=`tianshu_identity`,dR=/^\/tenants\/([A-Za-z0-9._-]{1,64})\/users\/([A-Za-z0-9._-]{1,64})(\/.*)?$/,fR=`default`;function pR(e){let t=e.match(dR);return t?{tenantId:t[1],userId:t[2],rest:t[3]||`/`}:null}function mR(){if(typeof document>`u`)return null;for(let e of document.cookie.split(/;\s*/)){let t=e.indexOf(`=`);if(t<=0||e.slice(0,t).trim()!==uR)continue;let n=decodeURIComponent(e.slice(t+1).trim()),r=n.indexOf(`/`);if(!(r<=0||r===n.length-1))return{tenantId:n.slice(0,r),userId:n.slice(r+1)}}return null}function hR(e,t){let n=encodeURIComponent(`${e}/${t}`);document.cookie=`${uR}=${n};Path=/;Max-Age=${720*3600};SameSite=Lax`}function gR(){document.cookie=`${uR}=;Path=/;Max-Age=0;SameSite=Lax`}function _R(e,t){if(dR.test(e))return e;let n=t??mR(),r=n?.tenantId??`default`,i=n?.userId??`dev`,a=e.startsWith(`/`)?e:`/${e}`;return`/tenants/${r}/users/${i}${a===`/`?``:a}`}function vR(){if(typeof window>`u`)return;let e=new URLSearchParams(window.location.search);if(e.has(`reset-identity`)){gR(),e.delete(`reset-identity`);let t=e.toString()?`?${e.toString()}`:``;window.location.replace(`/`+t+window.location.hash);return}let t=(e.get(`tenant`)??``).trim(),n=(e.get(`user`)??``).trim();if(t||n){let r=mR(),i=t||r?.tenantId||`default`,a=n||r?.userId||`dev`;if(!bR(i)||!bR(a)){console.warn(`[tianshu] ignoring invalid identity from URL: tenant=${i} user=${a}`);return}hR(i,a),e.delete(`tenant`),e.delete(`user`);let o=`/tenants/${i}/users/${a}${yR(window.location.pathname)}${e.toString()?`?${e.toString()}`:``}${window.location.hash}`;window.location.replace(o);return}let r=pR(window.location.pathname);if(r){let e=mR();(e?.tenantId!==r.tenantId||e?.userId!==r.userId)&&hR(r.tenantId,r.userId);return}let i=mR();if(i){let e=`/tenants/${i.tenantId}/users/${i.userId}${window.location.pathname}${window.location.search}${window.location.hash}`;window.location.replace(e);return}hR(fR,`dev`),window.location.replace(`/tenants/${fR}/users/dev${window.location.pathname}${window.location.search}${window.location.hash}`)}function yR(e){let t=e.match(dR);return t?t[3]||`/`:e||`/`}function bR(e){return/^[A-Za-z0-9._-]+$/.test(e)&&e.length<=64}function xR(){let[e,t]=(0,S.useState)(null),[n,r]=(0,S.useState)(null),[i,a]=(0,S.useState)(!1),[o,s]=(0,S.useState)(null),c=(0,S.useCallback)(async()=>{a(!0),r(null);try{let e=await fetch(`/api/mcp/servers`,{credentials:`include`});if(!e.ok){let t=await e.text().catch(()=>``);throw Error(`HTTP ${e.status}: ${t.slice(0,200)}`)}t((await e.json()).servers??[])}catch(e){r(e instanceof Error?e.message:String(e))}finally{a(!1)}},[]);(0,S.useEffect)(()=>{c()},[c]);let l=(0,S.useMemo)(()=>{let t=[{source:`plugin`,items:[]},{source:`user`,items:[]}];for(let n of e??[])t.find(e=>e.source===n.source)?.items.push(n);return t},[e]);return(0,J.jsxs)(`div`,{className:`mx-auto max-w-5xl p-6`,children:[(0,J.jsxs)(`div`,{className:`mb-6 flex items-start justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold text-gray-100`,children:[(0,J.jsx)(SD,{size:18,className:`text-brand-400`}),`MCP Servers`]}),(0,J.jsx)(`p`,{className:`mt-1 text-[12px] text-gray-500`,children:`Model Context Protocol servers visible to this agent. Plugin-contributed servers come from active plugins (read-only here — toggle the plugin to enable/disable). User-configured servers are managed directly below.`})]}),(0,J.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-2`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:c,disabled:i,className:`inline-flex items-center gap-1.5 whitespace-nowrap rounded-md border border-gray-700 px-3 py-1.5 text-[12px] text-gray-300 hover:bg-gray-800/50 disabled:opacity-50`,children:[(0,J.jsx)(ZT,{size:12,className:i?`animate-spin`:void 0}),`Refresh`]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>s(`new`),className:`inline-flex items-center gap-1.5 whitespace-nowrap rounded-md bg-brand-600 px-3 py-1.5 text-[12px] font-medium text-white hover:bg-brand-500`,children:[(0,J.jsx)(Zw,{size:12}),`Add server`]})]})]}),n&&(0,J.jsxs)(`div`,{className:`mb-4 flex items-start gap-2 rounded-md border border-rose-700/50 bg-rose-950/40 px-3 py-2 text-[12px] text-rose-300`,children:[(0,J.jsx)(OM,{size:14,className:`mt-px flex-shrink-0`}),(0,J.jsx)(`span`,{className:`break-all`,children:n})]}),e&&(0,J.jsx)(`div`,{className:`space-y-6`,children:l.map(e=>(0,J.jsx)(SR,{source:e.source,items:e.items,onEdit:e=>s(e),onChanged:c,onError:r},e.source))}),o&&(0,J.jsx)(TR,{mode:o===`new`?`create`:`edit`,initial:o===`new`?null:o,onClose:()=>s(null),onSaved:async()=>{s(null),await c()},onError:r})]})}function SR({source:e,items:t,onEdit:n,onChanged:r,onError:i}){return(0,J.jsxs)(`section`,{children:[(0,J.jsx)(`div`,{className:`mb-2 flex items-end justify-between`,children:(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-[13px] font-semibold uppercase tracking-wide text-gray-400`,children:e===`plugin`?`From plugins`:`User-configured`}),(0,J.jsx)(`p`,{className:`text-[11px] text-gray-500`,children:e===`plugin`?`Read-only — managed by the contributing plugin.`:`Add MCP servers (HTTP) to expand the agent's tool surface.`})]})}),t.length===0?(0,J.jsx)(CR,{source:e}):(0,J.jsx)(`div`,{className:`space-y-3`,children:t.map(e=>(0,J.jsx)(wR,{server:e,onEdit:n,onChanged:r,onError:i},`${e.source}.${e.sourceId}.${e.id}`))})]})}function CR({source:e}){return e===`plugin`?(0,J.jsx)(`div`,{className:`rounded-md border border-dashed border-gray-800 px-4 py-6 text-center text-[12px] text-gray-500`,children:`No plugin currently contributes an MCP server.`}):(0,J.jsxs)(`div`,{className:`rounded-md border border-dashed border-gray-800 px-4 py-6 text-center text-[12px] text-gray-500`,children:[`No user-configured MCP servers. Click `,(0,J.jsx)(`span`,{className:`text-gray-300`,children:`Add server`}),` `,`to point the agent at one (e.g. an MCP server you run locally or remotely).`]})}function wR({server:e,onEdit:t,onChanged:n,onError:r}){let[i,a]=(0,S.useState)(!1),[o,s]=(0,S.useState)(!1),c=e.snapshot,l=c?.tools??[],u=c?.lastError,d=c?.endpoint,f=(0,S.useMemo)(()=>{if(!c?.lastRefreshAt)return null;let e=Math.round((Date.now()-c.lastRefreshAt)/1e3);if(e<60)return`${e}s ago`;let t=Math.round(e/60);return t<60?`${t}m ago`:`${Math.round(t/60)}h ago`},[c?.lastRefreshAt]),p=e.enabled&&!u&&l.length>0,m=e.source===`user`,h=(0,S.useCallback)(async()=>{s(!0);try{let t=await fetch(`/api/mcp/servers/${encodeURIComponent(e.id)}/refresh`,{method:`POST`,credentials:`include`});if(!t.ok)throw Error(`HTTP ${t.status}`);await n()}catch(e){r(e instanceof Error?e.message:String(e))}finally{s(!1)}},[e.id,n,r]),g=(0,S.useCallback)(async()=>{if(!(!m||!e.userEntry)){s(!0);try{let t=await fetch(`/api/mcp/servers/${encodeURIComponent(e.id)}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:!e.enabled})});if(!t.ok)throw Error(`HTTP ${t.status}`);await n()}catch(e){r(e instanceof Error?e.message:String(e))}finally{s(!1)}}},[m,e.userEntry,e.id,e.enabled,n,r]),_=(0,S.useCallback)(async()=>{if(m&&confirm(`Remove MCP server "${e.displayName}"?`)){s(!0);try{let t=await fetch(`/api/mcp/servers/${encodeURIComponent(e.id)}`,{method:`DELETE`,credentials:`include`});if(!t.ok)throw Error(`HTTP ${t.status}`);await n()}catch(e){r(e instanceof Error?e.message:String(e))}finally{s(!1)}}},[m,e.displayName,e.id,n,r]);return(0,J.jsxs)(`div`,{className:`overflow-hidden rounded-md border border-gray-800 bg-gray-900/60`,children:[(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-gray-800 px-4 py-3`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`-my-1 -ml-1 mr-2 rounded p-1 text-gray-500 hover:bg-gray-800/60 hover:text-gray-300`,"aria-label":i?`Collapse`:`Expand`,children:i?(0,J.jsx)(Fl,{size:14}):(0,J.jsx)(zl,{size:14})}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.enabled?p?(0,J.jsx)(W,{size:14,className:`text-emerald-400`}):(0,J.jsx)(Lu,{size:14,className:`text-rose-400`}):(0,J.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-gray-500`,title:`disabled`}),(0,J.jsx)(`span`,{className:`truncate text-[13px] font-medium text-gray-100`,children:e.displayName}),(0,J.jsx)(`span`,{className:`rounded-sm px-1.5 py-0.5 text-[10px] ${m?`bg-blue-950 text-blue-300`:`bg-gray-800 text-gray-400`}`,children:m?`user`:`plugin: ${e.sourceId}`})]}),(0,J.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-4 gap-y-1 text-[11px] text-gray-500`,children:[(0,J.jsxs)(`span`,{children:[`id `,(0,J.jsx)(`code`,{className:`text-gray-400`,children:e.id})]}),d&&(0,J.jsxs)(`span`,{children:[`endpoint `,(0,J.jsx)(`code`,{className:`text-gray-400`,children:d})]}),c?.prefix&&c.prefix!==``&&(0,J.jsxs)(`span`,{children:[`prefix `,(0,J.jsx)(`code`,{className:`text-gray-400`,children:c.prefix})]}),f&&(0,J.jsxs)(`span`,{children:[`refreshed `,f]}),!e.enabled&&(0,J.jsx)(`span`,{className:`text-gray-500`,children:`(disabled)`})]})]}),(0,J.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-1.5`,children:[(0,J.jsxs)(`span`,{className:`rounded-md border border-gray-700 bg-gray-950 px-2 py-1 text-[11px] text-gray-300`,children:[e.toolCount,` tools`]}),(0,J.jsx)(`button`,{type:`button`,onClick:h,disabled:o,title:`Refresh`,className:`rounded p-1.5 text-gray-400 hover:bg-gray-800/60 hover:text-gray-200 disabled:opacity-50`,children:(0,J.jsx)(ZT,{size:12,className:o?`animate-spin`:void 0})}),m&&e.userEntry&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>t(e.userEntry),disabled:o,title:`Edit`,className:`rounded p-1.5 text-gray-400 hover:bg-gray-800/60 hover:text-gray-200 disabled:opacity-50`,children:(0,J.jsx)(vw,{size:12})}),(0,J.jsx)(`button`,{type:`button`,onClick:g,disabled:o,className:`rounded-md border border-gray-700 px-2 py-1 text-[11px] text-gray-300 hover:bg-gray-800/50 disabled:opacity-50`,children:e.enabled?`Disable`:`Enable`}),(0,J.jsx)(`button`,{type:`button`,onClick:_,disabled:o,title:`Delete`,className:`rounded p-1.5 text-rose-400 hover:bg-rose-950/40 disabled:opacity-50`,children:(0,J.jsx)(yM,{size:12})})]})]})]}),u&&(0,J.jsxs)(`div`,{className:`border-b border-gray-800 bg-rose-950/30 px-4 py-2 text-[11px] text-rose-300`,children:[(0,J.jsx)(OM,{size:12,className:`mr-1 inline-block`}),u]}),i&&(l.length===0?(0,J.jsx)(`div`,{className:`px-4 py-6 text-center text-[12px] text-gray-500`,children:d?`Server is reachable but advertised no tools.`:e.enabled?e.source===`plugin`?`Upstream not reachable yet. Plugin MCP servers usually live inside a sandbox that boots on first agent action — try running an exec/browser tool, or click Refresh after the sandbox starts.`:`Endpoint unreachable. Click Refresh to re-probe.`:`Server is disabled.`}):(0,J.jsxs)(`table`,{className:`w-full text-[12px]`,children:[(0,J.jsx)(`thead`,{className:`border-b border-gray-800 text-left text-[11px] uppercase tracking-wide text-gray-500`,children:(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Tool name`}),(0,J.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Upstream`}),(0,J.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Description`})]})}),(0,J.jsx)(`tbody`,{children:l.map(e=>(0,J.jsxs)(`tr`,{className:`border-b border-gray-900 last:border-b-0`,children:[(0,J.jsx)(`td`,{className:`px-4 py-2 align-top font-mono text-[11.5px] text-gray-200`,children:e.toolName}),(0,J.jsx)(`td`,{className:`px-4 py-2 align-top font-mono text-[11.5px] text-gray-500`,children:e.upstream.name}),(0,J.jsx)(`td`,{className:`px-4 py-2 align-top text-gray-400`,children:e.upstream.description??`—`})]},e.toolName))})]}))]})}function TR({mode:e,initial:t,onClose:n,onSaved:r,onError:i}){let[a,o]=(0,S.useState)(t?.id??``),[s,c]=(0,S.useState)(t?.displayName??``),[l,u]=(0,S.useState)(t?.url??``),[d,f]=(0,S.useState)(t?.prefix??``),[p,m]=(0,S.useState)(t?.upstreamHost??``),[h,g]=(0,S.useState)(t?.enabled??!0),[_,v]=(0,S.useState)(!1),[y,b]=(0,S.useState)(null),x=async n=>{if(n.preventDefault(),b(null),!/^[a-z0-9][a-z0-9-]{0,30}$/.test(a)){b(`id must be 1-31 chars: lowercase letters, digits, dashes`);return}v(!0);try{let n={id:a,url:l,enabled:h};s&&(n.displayName=s),d!==t?.prefix&&(n.prefix=d),p&&(n.upstreamHost=p);let i=e===`create`?`/api/mcp/servers`:`/api/mcp/servers/${encodeURIComponent(a)}`,o=await fetch(i,{method:e===`create`?`POST`:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!o.ok){let e=await o.json().catch(()=>({}));throw Error(e.message??`HTTP ${o.status}`)}await r()}catch(e){i(e instanceof Error?e.message:String(e))}finally{v(!1)}},{Modal:C}=_F();return(0,J.jsx)(C,{isOpen:!0,onClose:n,size:`sm`,title:e===`create`?`Add MCP server`:`Edit ${t?.displayName??a}`,children:(0,J.jsxs)(`form`,{onSubmit:x,className:`h-full space-y-3 overflow-y-auto p-5`,children:[(0,J.jsx)(ER,{label:`ID`,hint:`Lowercase letters / digits / dashes; used in URLs and tool prefixes.`,children:(0,J.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),disabled:e===`edit`,placeholder:`my-mcp`,className:`w-full rounded-md border border-gray-700 bg-gray-950 px-2 py-1.5 text-[13px] text-gray-100 outline-none focus:border-brand-500 disabled:opacity-60`,required:!0})}),(0,J.jsx)(ER,{label:`Display name`,hint:`Optional; defaults to id.`,children:(0,J.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`My MCP server`,className:`w-full rounded-md border border-gray-700 bg-gray-950 px-2 py-1.5 text-[13px] text-gray-100 outline-none focus:border-brand-500`})}),(0,J.jsx)(ER,{label:`URL`,hint:`Streamable HTTP MCP endpoint (must include path, e.g. /mcp).`,children:(0,J.jsx)(`input`,{type:`url`,value:l,onChange:e=>u(e.target.value),placeholder:`https://example.com/mcp`,className:`w-full rounded-md border border-gray-700 bg-gray-950 px-2 py-1.5 text-[13px] text-gray-100 outline-none focus:border-brand-500`,required:!0})}),(0,J.jsx)(ER,{label:`Tool prefix`,hint:`Prepended to every reflected tool name. Default: "<id>_". Pass empty to disable.`,children:(0,J.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`${a}_`,className:`w-full rounded-md border border-gray-700 bg-gray-950 px-2 py-1.5 text-[13px] text-gray-100 outline-none focus:border-brand-500`})}),(0,J.jsx)(ER,{label:`Upstream Host header`,hint:`Optional. Pin the request Host header (most MCP servers validate it; useful behind port-forwards).`,children:(0,J.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:`localhost:3200`,className:`w-full rounded-md border border-gray-700 bg-gray-950 px-2 py-1.5 text-[13px] text-gray-100 outline-none focus:border-brand-500`})}),(0,J.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-gray-300`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`rounded border-gray-700 bg-gray-950`}),`Enabled`]}),y&&(0,J.jsx)(`div`,{className:`rounded-md border border-rose-700/50 bg-rose-950/40 px-3 py-2 text-[11px] text-rose-300`,children:y}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-md border border-gray-700 px-3 py-1.5 text-[12px] text-gray-300 hover:bg-gray-800/50`,children:`Cancel`}),(0,J.jsx)(`button`,{type:`submit`,disabled:_,className:`rounded-md bg-brand-600 px-3 py-1.5 text-[12px] font-medium text-white hover:bg-brand-500 disabled:opacity-50`,children:_?`Saving…`:e===`create`?`Add server`:`Save`})]})]})})}function ER({label:e,hint:t,children:n}){return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-gray-300`,children:e}),n,t&&(0,J.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-500`,children:t})]})}function DR({pluginId:e,className:t}){let n=gr(t=>(t.plugins??[]).find(t=>t.id===e)??null);return!n||!n.configSchema||(n.configSchema.fields?.length??0)===0?null:(0,J.jsx)(`div`,{className:t,children:(0,J.jsx)(OR,{plugin:n})})}function OR({plugin:e}){let t=gr(e=>e.setPlugins),n=e.configSchema?.fields??[],[r,i]=(0,S.useState)(()=>PR(n,e.config)),[a,o]=(0,S.useState)(!1),[s,c]=(0,S.useState)(null),[l,u]=(0,S.useState)(null);(0,S.useEffect)(()=>{i(PR(n,e.config)),u(null)},[e.id,e.version,e.config]);let d=!LR(r,PR(n,e.config));async function f(){o(!0),c(null);try{let n=IR(r);t((await ur.setPluginConfig(e.id,n)).plugins),u(Date.now())}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(!1)}}function p(){i(PR(n,e.config)),c(null),u(null)}return n.length===0?(0,J.jsx)(`p`,{className:`text-[12px] text-gray-500`,children:`This plugin has no user-editable configuration.`}):(0,J.jsxs)(`div`,{className:`space-y-5`,children:[(0,J.jsx)(`div`,{className:`space-y-5`,children:jR(n).map((e,t)=>{if(e.kind===`field`)return(0,J.jsx)(NR,{field:e.field,value:r[e.field.key],onChange:t=>i(n=>({...n,[e.field.key]:t}))},`f:${t}:${e.field.key}`);let[n,...a]=e.fields,o=n&&n.kind===`boolean`?{field:n,value:r[n.key]===!0,onChange:e=>i(t=>({...t,[n.key]:e}))}:null,s=o?a:e.fields;return(0,J.jsx)(MR,{group:e.group,headerToggle:o,children:s.map(e=>(0,J.jsx)(NR,{field:e,value:r[e.key],onChange:t=>i(n=>({...n,[e.key]:t}))},e.key))},`g:${e.group.id}`)})}),s&&(0,J.jsx)(`div`,{className:`rounded-md border border-rose-700/50 bg-rose-950/40 px-3 py-2 text-[12px] text-rose-300`,children:s}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 border-t border-gray-800 pt-3`,children:[l&&!d&&(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-emerald-400`,children:[(0,J.jsx)(W,{size:12}),` Saved`]}),(0,J.jsx)(`button`,{type:`button`,onClick:p,disabled:!d||a,className:`ml-auto inline-flex items-center gap-1.5 whitespace-nowrap rounded-md border border-gray-700 px-3 py-1.5 text-[12px] text-gray-300 hover:bg-gray-800/50 disabled:cursor-not-allowed disabled:opacity-50`,children:`Reset`}),(0,J.jsx)(`button`,{type:`button`,onClick:f,disabled:!d||a,className:`inline-flex items-center gap-1.5 whitespace-nowrap rounded-md bg-brand-600 px-3 py-1.5 text-[12px] font-medium text-white hover:bg-brand-500 disabled:cursor-not-allowed disabled:opacity-50`,children:a?(0,J.jsx)(db,{className:`inline h-3 w-3 animate-spin`}):`Save`})]})]})}var kR=`w-full rounded-md border border-gray-700 bg-gray-900 px-3 py-1.5 text-[12px] text-gray-100 outline-none placeholder:text-gray-600 focus:border-brand-500`;function AR({active:e,onClick:t,ariaLabel:n}){return(0,J.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e,"aria-label":n,onClick:t,className:[`relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer items-center rounded-full transition-colors`,e?`bg-brand-600`:`bg-gray-700`].join(` `),children:(0,J.jsx)(`span`,{className:[`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform`,e?`translate-x-5`:`translate-x-1`].join(` `)})})}function jR(e){let t=[],n=new Map;for(let r of e){let e=r.group;if(!e){t.push({kind:`field`,field:r});continue}let i=n.get(e.id);i===void 0?(n.set(e.id,t.length),t.push({kind:`group`,group:e,fields:[r]})):t[i].fields.push(r)}return t}function MR({group:e,headerToggle:t,children:n}){let r=!n||Array.isArray(n)&&n.every(e=>e==null||e===!1);return(0,J.jsxs)(`section`,{className:`rounded-md border border-gray-800 bg-gray-900/30 p-4`,children:[(0,J.jsxs)(`header`,{className:`flex flex-wrap items-center gap-2`,children:[e.badge&&(0,J.jsx)(`span`,{className:`rounded border border-gray-700 bg-gray-800/60 px-1.5 py-0.5 font-mono text-[10px] font-semibold uppercase tracking-wide text-gray-400`,children:e.badge}),(0,J.jsx)(`h3`,{className:`text-[13px] font-semibold text-gray-100`,children:e.label}),t&&(0,J.jsx)(AR,{active:t.value,onClick:()=>t.onChange(!t.value),ariaLabel:t.field.label})]}),e.description&&(0,J.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-gray-500`,children:e.description}),!r&&(0,J.jsx)(`div`,{className:`mt-3 space-y-4`,children:n})]})}function NR({field:e,value:t,onChange:n}){if(e.kind===`boolean`){let r=t===!0;return(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-3 text-[12px]`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`font-medium text-gray-200`,children:e.label}),e.description&&(0,J.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-relaxed text-gray-500`,children:e.description})]}),(0,J.jsx)(AR,{active:r,onClick:()=>n(!r),ariaLabel:e.label})]})}if(e.kind===`number`){let r=typeof t==`number`?t:typeof t==`string`&&t.trim()!==``?Number(t):e.default??0;return(0,J.jsxs)(`div`,{className:`text-[12px]`,children:[(0,J.jsx)(`label`,{className:`mb-1 block font-medium text-gray-200`,children:e.label}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`input`,{type:`number`,value:Number.isFinite(r)?r:0,min:e.min,max:e.max,step:e.step,onChange:e=>n(Number(e.target.value)),className:`${kR} w-40`}),e.unit&&(0,J.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:e.unit})]}),e.description&&(0,J.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-gray-500`,children:e.description})]})}if(e.kind===`select`){let r=typeof t==`string`?t:e.default??e.options[0]?.value??``;return(0,J.jsxs)(`div`,{className:`text-[12px]`,children:[(0,J.jsx)(`label`,{className:`mb-1 block font-medium text-gray-200`,children:e.label}),(0,J.jsx)(`select`,{value:r,onChange:e=>n(e.target.value),className:kR,children:e.options.map(e=>(0,J.jsx)(`option`,{value:e.value,children:e.label},e.value))}),e.description&&(0,J.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-gray-500`,children:e.description})]})}if(e.kind===`secret`){let r=typeof t==`object`&&!!t&&t.__secret===!0&&t.set===!0,i=typeof t==`string`?t:``;return(0,J.jsxs)(`div`,{className:`text-[12px]`,children:[(0,J.jsxs)(`label`,{className:`mb-1 block font-medium text-gray-200`,children:[e.label,r?(0,J.jsx)(`span`,{className:`ml-2 rounded bg-emerald-700/40 px-1.5 py-0.5 text-[10px] uppercase text-emerald-300`,children:`set`}):null]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`input`,{type:`password`,value:i,placeholder:r?`••• stored — type a new value to replace, or click Clear`:e.placeholder??``,autoComplete:`new-password`,spellCheck:!1,onChange:e=>n(e.target.value),className:kR}),r&&i===``&&(0,J.jsx)(`button`,{type:`button`,className:`shrink-0 rounded border border-gray-700 bg-gray-900 px-2 py-1 text-[11px] text-gray-300 hover:border-rose-700 hover:text-rose-300`,onClick:()=>n({__secret:!0,clear:!0}),children:`Clear`})]}),e.description&&(0,J.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-gray-500`,children:e.description})]})}let r=typeof t==`string`?t:e.default??``;return(0,J.jsxs)(`div`,{className:`text-[12px]`,children:[(0,J.jsx)(`label`,{className:`mb-1 block font-medium text-gray-200`,children:e.label}),e.multiline?(0,J.jsx)(`textarea`,{value:r,rows:3,placeholder:e.placeholder,onChange:e=>n(e.target.value),className:`${kR} resize-y`}):(0,J.jsx)(`input`,{type:`text`,value:r,placeholder:e.placeholder,onChange:e=>n(e.target.value),className:kR}),e.description&&(0,J.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-gray-500`,children:e.description})]})}function PR(e,t){let n={};for(let r of e){let e=FR(t,r.key);if(e!==void 0){n[r.key]=e;continue}r.kind===`boolean`?n[r.key]=r.default??!1:r.kind===`number`?n[r.key]=r.default??0:r.kind===`secret`?n[r.key]=``:r.kind===`select`?n[r.key]=r.default??r.options[0]?.value??``:n[r.key]=r.default??``}return n}function FR(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return;n=n[e]}return n}function IR(e){let t={};for(let[n,r]of Object.entries(e)){let e=n.split(`.`),i=t;for(let t=0;t<e.length-1;t++){let n=e[t];(typeof i[n]!=`object`||i[n]===null||Array.isArray(i[n]))&&(i[n]={}),i=i[n]}i[e[e.length-1]]=r}return t}function LR(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(e[r]!==t[r])return!1;return!0}var RR=[{pluginId:`core`,pluginDisplayName:`Tianshu`,pageId:`mcp`,displayName:`MCP Servers`,icon:`Server`,kind:`core`,component:`McpServersPage`,coreComponent:xR,group:`Agent`,order:10,clientEntry:null}],zR=`Plugins`;function BR(e){let t=[...RR];if(e)for(let n of e){if(n.state!==`active`)continue;let e=n.contributes.adminPages??[];for(let r of e)t.push({pluginId:n.id,pluginDisplayName:n.displayName,pageId:r.id,displayName:r.displayName,icon:r.icon,kind:`plugin`,component:r.component,group:zR,order:r.order??100,clientEntry:n.clientEntry});let r=!!n.configSchema&&(n.configSchema?.fields?.length??0)>0,i=e.length>0,a=e.some(e=>e.id===`settings`);r&&!i&&!a&&t.push({pluginId:n.id,pluginDisplayName:n.displayName,pageId:`settings`,displayName:n.displayName,icon:`Settings`,kind:`core`,component:`PluginConfigSettingsPage`,coreComponent:(e=>(0,J.jsx)(JR,{...e,pluginId:n.id})),group:zR,order:90,clientEntry:null})}return t.sort((e,t)=>{let n=e.group??``,r=t.group??``;return n===r?e.order===t.order?e.displayName.localeCompare(t.displayName):e.order-t.order:n===``?-1:r===``?1:n.localeCompare(r)}),t}function VR(){let e=M(e=>e.me),t=M(e=>e.init),n=gr(e=>e.plugins),r=gr(e=>e.load);(0,S.useEffect)(()=>{t(),r()},[t,r]);let i=(0,S.useMemo)(()=>BR(n),[n]);return(0,J.jsxs)(`div`,{className:`flex h-screen overflow-hidden bg-gray-950 text-gray-200`,children:[(0,J.jsx)(HR,{pages:i,userLabel:e?.userId??null}),(0,J.jsx)(`main`,{className:`min-w-0 flex-1 overflow-y-auto`,children:(0,J.jsxs)(Gt,{children:[(0,J.jsx)(Ut,{index:!0,element:i.length>0?(0,J.jsx)(Ht,{to:_R(`/admin/${i[0].pluginId}/${i[0].pageId}`),replace:!0}):(0,J.jsx)(GR,{})}),(0,J.jsx)(Ut,{path:`:pluginId/:pageId`,element:(0,J.jsx)(WR,{pages:i})}),(0,J.jsx)(Ut,{path:`*`,element:(0,J.jsx)(Ht,{to:``,replace:!0})})]})})]})}function HR({pages:e,userLabel:t}){let n=sL()(`admin.title`),r=[];for(let t of e){let e=r[r.length-1],n=t.group??null;e&&e.group===n?e.pages.push(t):r.push({group:n,pages:[t]})}return(0,J.jsxs)(`aside`,{className:`flex w-56 flex-shrink-0 flex-col border-r border-gray-800 bg-gray-900`,children:[(0,J.jsxs)(`div`,{className:`flex h-14 items-center gap-2 border-b border-gray-800 px-4`,children:[(0,J.jsx)(ND,{size:16,className:`text-blue-400`}),(0,J.jsx)(`span`,{className:`text-sm font-semibold text-gray-100`,children:n})]}),(0,J.jsxs)(`nav`,{className:`flex-1 space-y-3 overflow-y-auto p-2`,children:[r.length===0&&(0,J.jsxs)(`p`,{className:`px-3 py-2 text-[11px] leading-relaxed text-gray-500`,children:[`No admin pages contributed yet. Enable a plugin that ships `,(0,J.jsx)(`code`,{children:`contributes.adminPages`}),` to see entries here.`]}),r.map((e,t)=>(0,J.jsxs)(`div`,{children:[e.group&&(0,J.jsx)(`div`,{className:`px-3 pb-1 pt-1 text-[10px] font-semibold uppercase tracking-wide text-gray-500`,children:e.group}),(0,J.jsx)(`div`,{className:`space-y-0.5`,children:e.pages.map(e=>(0,J.jsx)(UR,{page:e},`${e.pluginId}.${e.pageId}`))})]},t))]}),(0,J.jsx)(`div`,{className:`border-t border-gray-800 p-2`,children:(0,J.jsxs)(In,{to:`..`,className:`flex items-center gap-2 rounded-md px-3 py-2 text-xs text-gray-500 hover:bg-gray-800/50 hover:text-gray-300`,end:!0,children:[(0,J.jsx)(Yi,{size:12}),`Back to chat`]})}),t&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 border-t border-gray-800 px-3 py-2`,children:[(0,J.jsx)(`div`,{className:`flex h-6 w-6 items-center justify-center rounded-full bg-gradient-to-br from-blue-500 to-purple-600 text-[10px] font-semibold text-white`,children:t.slice(0,1).toUpperCase()}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`truncate text-[11px] text-gray-300`,children:t}),(0,J.jsx)(`div`,{className:`text-[10px] text-gray-600`,children:`admin`})]})]})]})}function UR({page:e}){let t=qR(e.icon);return(0,J.jsxs)(In,{to:_R(`/admin/${e.pluginId}/${e.pageId}`),className:({isActive:e})=>`flex items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors ${e?`bg-gray-800 text-white`:`text-gray-400 hover:bg-gray-800/50 hover:text-gray-200`}`,children:[t&&(0,J.jsx)(t,{size:14,className:`flex-shrink-0`}),(0,J.jsx)(`span`,{className:`truncate`,children:e.displayName})]})}function WR({pages:e}){let t=vt(),n=gt(),r=M(e=>e.me),i=e.find(e=>e.pluginId===t.pluginId&&e.pageId===t.pageId);if((0,S.useEffect)(()=>{!i&&e.length>0&&n(_R(`/admin`),{replace:!0})},[i,e,n]),!i)return(0,J.jsx)(GR,{});let a=i.kind===`core`?i.coreComponent??null:KI(i.clientEntry,i.component);return a?(0,J.jsx)(a,{tenantId:r?.tenantId??``,userId:r?.userId??``,pageId:i.pageId,plugin:{id:i.pluginId,version:``,displayName:i.pluginDisplayName}}):(0,J.jsx)(KR,{title:`Component "${i.component}" not found`,message:`Plugin ${i.pluginId}'s client bundle does not export ${i.component}. Did you forget to add it to PluginClientExports.components?`})}function GR(){return(0,J.jsxs)(`div`,{className:`mx-auto flex max-w-xl flex-col items-center justify-center px-6 py-24 text-center text-gray-400`,children:[(0,J.jsx)(wD,{size:32,className:`mb-3 text-gray-600`}),(0,J.jsx)(`h2`,{className:`mb-2 text-base font-semibold text-gray-200`,children:`Nothing to manage yet`}),(0,J.jsx)(`p`,{className:`text-sm leading-relaxed text-gray-500`,children:`The admin shell is empty until a plugin contributes an admin page. Open the Plugin Manager from the chat shell to enable a plugin that ships one (e.g. MicroSandbox).`})]})}function KR({title:e,message:t}){return(0,J.jsx)(`div`,{className:`mx-auto max-w-2xl px-6 py-12`,children:(0,J.jsxs)(`div`,{className:`rounded-md border border-rose-700/50 bg-rose-950/40 p-4 text-sm text-rose-200`,children:[(0,J.jsx)(`strong`,{className:`mb-1 block`,children:e}),(0,J.jsx)(`p`,{className:`leading-relaxed text-rose-300`,children:t})]})})}function qR(e){return e?tF[e]??null:null}function JR({pluginId:e}){let t=gr(e=>e.plugins)?.find(t=>t.id===e);return(0,J.jsxs)(`div`,{className:`mx-auto max-w-5xl p-6`,children:[(0,J.jsxs)(`div`,{className:`mb-6`,children:[(0,J.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold text-gray-100`,children:[(0,J.jsx)(wD,{size:18,className:`text-brand-400`}),t?t.displayName:e]}),t?.description&&(0,J.jsx)(`p`,{className:`mt-1 max-w-3xl text-[12px] text-gray-500`,children:t.description})]}),t?(0,J.jsxs)(`section`,{children:[(0,J.jsxs)(`div`,{className:`mb-2`,children:[(0,J.jsx)(`h2`,{className:`text-[13px] font-semibold uppercase tracking-wide text-gray-400`,children:`Configuration`}),(0,J.jsx)(`p`,{className:`text-[11px] text-gray-500`,children:`Saving re-activates the plugin so changes take effect on the next request.`})]}),(0,J.jsx)(`div`,{className:`rounded-md border border-gray-800 bg-gray-900/30 p-4`,children:(0,J.jsx)(OR,{plugin:t})})]}):(0,J.jsxs)(`div`,{className:`rounded-md border border-dashed border-gray-800 px-4 py-6 text-center text-[12px] text-gray-500`,children:[`Plugin `,(0,J.jsx)(`code`,{children:e}),` is not active.`]})]})}var YR=5e5;function XR(e){return e.startsWith(`text/`)||e.startsWith(`application/json`)?`text`:e.startsWith(`image/`)?`image`:e===`application/pdf`?`pdf`:e.startsWith(`video/`)?`video`:e.startsWith(`audio/`)?`audio`:`binary`}function ZR(e){switch(e.toLowerCase().match(/\.[a-z0-9]+$/)?.[0]??``){case`.png`:return`image/png`;case`.jpg`:case`.jpeg`:return`image/jpeg`;case`.gif`:return`image/gif`;case`.webp`:return`image/webp`;case`.svg`:return`image/svg+xml`;case`.pdf`:return`application/pdf`;case`.mp4`:return`video/mp4`;case`.webm`:return`video/webm`;case`.mp3`:return`audio/mpeg`;case`.wav`:return`audio/wav`;case`.ogg`:return`audio/ogg`;case`.json`:return`application/json; charset=utf-8`;case`.md`:return`text/markdown; charset=utf-8`;case`.html`:return`text/html; charset=utf-8`;case`.css`:return`text/css; charset=utf-8`;case`.js`:case`.jsx`:case`.ts`:case`.tsx`:return`text/javascript; charset=utf-8`;case`.csv`:return`text/csv; charset=utf-8`;case``:return`application/octet-stream`;default:return`text/plain; charset=utf-8`}}function QR(e){let t=e.replace(/^workspace:\/\/+/,`/`),n=t.split(`/`).filter(Boolean);return n[n.length-1]??t}function $R(e){let t=e.replace(/^workspace:\/\/+/,`/`);return`/api/p/files/raw?path=${encodeURIComponent(t)}`}function ez(){let{Modal:e,DocumentViewer:t}=_F(),[n,r]=(0,S.useState)(null),[i,a]=(0,S.useState)({kind:`loading`});(0,S.useEffect)(()=>{let e=e=>{let t=e.detail;t?.path&&r({path:t.path})};return window.addEventListener(`tianshu:files:open`,e),()=>window.removeEventListener(`tianshu:files:open`,e)},[]),(0,S.useEffect)(()=>{if(!n)return;a({kind:`loading`});let e=new AbortController,t=n.path.replace(/^workspace:\/\/+/,`/`);return(async()=>{try{let n=await fetch(`/api/p/files/read?path=${encodeURIComponent(t)}`,{credentials:`include`,signal:e.signal});if(n.status===404){a({kind:`error`,message:`File not found.`});return}if(n.status===413){a({kind:`binary`,mime:`application/octet-stream`,size:(await n.json()).size??0});return}if(!n.ok){a({kind:`error`,message:`read failed: HTTP ${n.status}`});return}let r=await n.json(),i=r.size??0;if(!r.binary){let e=ZR(t);a({kind:`text`,content:r.content??``,truncated:!!r.truncated,size:i,mime:e});return}let o=ZR(t),s=XR(o);if(s===`image`||s===`pdf`||s===`video`||s===`audio`){a({kind:s,mime:o});return}a({kind:`binary`,mime:o,size:i})}catch(e){if(e.name===`AbortError`)return;a({kind:`error`,message:e instanceof Error?e.message:String(e)})}})(),()=>e.abort()},[n]);let o=(0,S.useCallback)(()=>r(null),[]);if((0,S.useEffect)(()=>{if(!n)return;let e=e=>{e.key===`Escape`&&o()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n,o]),!n)return null;let s=QR(n.path),c=n.path.replace(/^workspace:\/\/+/,`/`),l=$R(c);return(0,J.jsx)(e,{isOpen:!0,onClose:o,size:`xl`,hideHeader:!0,className:`bg-gray-900`,children:(0,J.jsxs)(`div`,{className:`flex h-full max-h-[90vh] flex-col`,children:[(0,J.jsxs)(`header`,{className:`flex items-center justify-between border-b border-gray-800 px-4 py-2.5`,children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-sm`,children:[(0,J.jsx)(sh,{size:14,className:`shrink-0 text-gray-400`}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`div`,{className:`truncate font-medium text-gray-100`,title:c,children:s}),(0,J.jsx)(`div`,{className:`truncate font-mono text-[10px] text-gray-500`,children:c})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`a`,{href:l,target:`_blank`,rel:`noopener noreferrer`,className:`rounded px-2 py-1 text-[11px] text-gray-400 hover:bg-gray-800 hover:text-gray-200`,title:`Open in new tab / download`,children:`↗ raw`}),(0,J.jsx)(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-gray-400 hover:bg-gray-800 hover:text-gray-200`,"aria-label":`Close`,children:(0,J.jsx)(IP,{size:14})})]})]}),(0,J.jsxs)(`div`,{className:`flex-1 overflow-auto bg-gray-950 p-3`,children:[i.kind===`loading`&&(0,J.jsxs)(`div`,{className:`flex h-32 items-center justify-center text-gray-500`,children:[(0,J.jsx)(db,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading…`]}),i.kind===`text`&&(0,J.jsxs)(J.Fragment,{children:[i.truncated&&(0,J.jsxs)(`div`,{className:`mb-2 rounded border border-amber-900/40 bg-amber-950/30 px-2 py-1 text-[11px] text-amber-200`,children:[`Truncated at `,YR.toLocaleString(),` bytes — open in a new tab via the ↗ button to see the full file.`]}),(0,J.jsx)(t,{content:i.content,filename:s,className:`!p-0`})]}),i.kind===`image`&&(0,J.jsx)(`img`,{src:l,alt:s,className:`mx-auto max-h-[75vh] object-contain`}),i.kind===`pdf`&&(0,J.jsx)(`iframe`,{src:l,title:s,className:`h-[75vh] w-full rounded border border-gray-800 bg-white`}),i.kind===`video`&&(0,J.jsx)(`video`,{src:l,controls:!0,className:`mx-auto max-h-[75vh] w-full`,children:(0,J.jsx)(`track`,{kind:`captions`})}),i.kind===`audio`&&(0,J.jsx)(`audio`,{src:l,controls:!0,className:`mx-auto w-full`,children:(0,J.jsx)(`track`,{kind:`captions`})}),i.kind===`binary`&&(0,J.jsxs)(`div`,{className:`space-y-2 text-center text-sm text-gray-300`,children:[(0,J.jsxs)(`div`,{className:`text-gray-200`,children:[i.mime,` · `,i.size.toLocaleString(),` bytes`]}),(0,J.jsxs)(`div`,{className:`text-[12px] text-gray-500`,children:[`Binary file — preview not available. Use the`,` `,(0,J.jsx)(`span`,{className:`text-gray-300`,children:`↗ raw`}),` button to download.`]})]}),i.kind===`error`&&(0,J.jsx)(`div`,{className:`rounded border border-red-900/50 bg-red-950/40 px-3 py-2 text-[12px] text-red-300`,children:i.message})]})]})})}function tz(){return(0,J.jsxs)(Nn,{children:[(0,J.jsxs)(Gt,{children:[(0,J.jsxs)(Ut,{path:`/tenants/:tenantId/users/:userId`,children:[(0,J.jsx)(Ut,{index:!0,element:(0,J.jsx)(lR,{})}),(0,J.jsx)(Ut,{path:`admin/*`,element:(0,J.jsx)(VR,{})}),(0,J.jsx)(Ut,{path:`*`,element:(0,J.jsx)(Ht,{to:``,replace:!0})})]}),(0,J.jsx)(Ut,{path:`*`,element:(0,J.jsx)(Ht,{to:_R(`/`),replace:!0})})]}),(0,J.jsx)(ez,{})]})}var nz={sm:`max-w-md`,md:`max-w-2xl`,lg:`max-w-3xl`,xl:`max-w-5xl`},rz=`button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`;function iz({isOpen:e,onClose:t,title:n,size:r=`md`,className:i=``,hideHeader:a=!1,children:o}){let s=(0,S.useRef)(null),c=(0,S.useRef)(null);(0,S.useEffect)(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e]),(0,S.useEffect)(()=>{if(!e)return;c.current=document.activeElement instanceof HTMLElement?document.activeElement:null;let n=e=>{e.key===`Escape`&&(e.stopPropagation(),t())};window.addEventListener(`keydown`,n);let r=window.setTimeout(()=>{let e=s.current;e&&e.querySelector(rz)?.focus()},0);return()=>{window.removeEventListener(`keydown`,n),window.clearTimeout(r);let e=c.current;e&&document.body.contains(e)&&e.focus()}},[e,t]);function l(e){if(e.key!==`Tab`)return;let t=s.current;if(!t)return;let n=Array.from(t.querySelectorAll(rz)).filter(e=>!e.hasAttribute(`inert`));if(n.length===0)return;let r=n[0],i=n[n.length-1];e.shiftKey?document.activeElement===r&&(i.focus(),e.preventDefault()):document.activeElement===i&&(r.focus(),e.preventDefault())}function u(e){e.target===e.currentTarget&&t()}return e?(0,FL.createPortal)((0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4 backdrop-blur-sm`,onMouseDown:u,role:`dialog`,"aria-modal":`true`,"aria-label":n,children:(0,J.jsxs)(`div`,{ref:s,className:`flex max-h-[85vh] w-full ${nz[r]} flex-col overflow-hidden rounded-xl border border-gray-700 bg-gray-900 shadow-2xl ${i}`,onKeyDown:l,children:[!a&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-800 px-4 py-2.5`,children:[(0,J.jsx)(`div`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-gray-100`,children:n}),(0,J.jsx)(`button`,{type:`button`,onClick:t,className:`btn-ghost p-1.5`,"aria-label":`Close`,children:(0,J.jsx)(IP,{size:16})})]}),(0,J.jsx)(`div`,{className:`min-h-0 flex-1`,children:o})]})}),document.body):null}function az(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var oz=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,sz=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,cz={};function lz(e,t){return((t||cz).jsx?sz:oz).test(e)}var uz=/[ \t\n\f\r]/g;function dz(e){return typeof e==`object`?e.type===`text`?fz(e.value):!1:fz(e)}function fz(e){return e.replace(uz,``)===``}var pz=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};pz.prototype.normal={},pz.prototype.property={},pz.prototype.space=void 0;function mz(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new pz(n,r,t)}function hz(e){return e.toLowerCase()}var gz=class{constructor(e,t){this.attribute=t,this.property=e}};gz.prototype.attribute=``,gz.prototype.booleanish=!1,gz.prototype.boolean=!1,gz.prototype.commaOrSpaceSeparated=!1,gz.prototype.commaSeparated=!1,gz.prototype.defined=!1,gz.prototype.mustUseProperty=!1,gz.prototype.number=!1,gz.prototype.overloadedBoolean=!1,gz.prototype.property=``,gz.prototype.spaceSeparated=!1,gz.prototype.space=void 0;var _z=s({boolean:()=>Y,booleanish:()=>yz,commaOrSpaceSeparated:()=>Cz,commaSeparated:()=>Sz,number:()=>X,overloadedBoolean:()=>bz,spaceSeparated:()=>xz}),vz=0,Y=wz(),yz=wz(),bz=wz(),X=wz(),xz=wz(),Sz=wz(),Cz=wz();function wz(){return 2**++vz}var Tz=Object.keys(_z),Ez=class extends gz{constructor(e,t,n,r){let i=-1;if(super(e,t),Dz(this,`space`,r),typeof n==`number`)for(;++i<Tz.length;){let e=Tz[i];Dz(this,Tz[i],(n&_z[e])===_z[e])}}};Ez.prototype.defined=!0;function Dz(e,t,n){n&&(e[t]=n)}function Oz(e){let t={},n={};for(let[r,i]of Object.entries(e.properties)){let a=new Ez(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(a.mustUseProperty=!0),t[r]=a,n[hz(r)]=r,n[hz(a.attribute)]=r}return new pz(t,n,e.space)}var kz=Oz({properties:{ariaActiveDescendant:null,ariaAtomic:yz,ariaAutoComplete:null,ariaBusy:yz,ariaChecked:yz,ariaColCount:X,ariaColIndex:X,ariaColSpan:X,ariaControls:xz,ariaCurrent:null,ariaDescribedBy:xz,ariaDetails:null,ariaDisabled:yz,ariaDropEffect:xz,ariaErrorMessage:null,ariaExpanded:yz,ariaFlowTo:xz,ariaGrabbed:yz,ariaHasPopup:null,ariaHidden:yz,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:xz,ariaLevel:X,ariaLive:null,ariaModal:yz,ariaMultiLine:yz,ariaMultiSelectable:yz,ariaOrientation:null,ariaOwns:xz,ariaPlaceholder:null,ariaPosInSet:X,ariaPressed:yz,ariaReadOnly:yz,ariaRelevant:null,ariaRequired:yz,ariaRoleDescription:xz,ariaRowCount:X,ariaRowIndex:X,ariaRowSpan:X,ariaSelected:yz,ariaSetSize:X,ariaSort:null,ariaValueMax:X,ariaValueMin:X,ariaValueNow:X,ariaValueText:null,role:null},transform(e,t){return t===`role`?t:`aria-`+t.slice(4).toLowerCase()}});function Az(e,t){return t in e?e[t]:t}function jz(e,t){return Az(e,t.toLowerCase())}var Mz=Oz({attributes:{acceptcharset:`accept-charset`,classname:`class`,htmlfor:`for`,httpequiv:`http-equiv`},mustUseProperty:[`checked`,`multiple`,`muted`,`selected`],properties:{abbr:null,accept:Sz,acceptCharset:xz,accessKey:xz,action:null,allow:null,allowFullScreen:Y,allowPaymentRequest:Y,allowUserMedia:Y,alpha:Y,alt:null,as:null,async:Y,autoCapitalize:null,autoComplete:xz,autoFocus:Y,autoPlay:Y,blocking:xz,capture:null,charSet:null,checked:Y,cite:null,className:xz,closedBy:null,colorSpace:null,cols:X,colSpan:X,command:null,commandFor:null,content:null,contentEditable:yz,controls:Y,controlsList:xz,coords:X|Sz,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Y,defer:Y,dir:null,dirName:null,disabled:Y,download:bz,draggable:yz,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Y,formTarget:null,headers:xz,height:X,hidden:bz,high:X,href:null,hrefLang:null,htmlFor:xz,httpEquiv:xz,id:null,imageSizes:null,imageSrcSet:null,inert:Y,inputMode:null,integrity:null,is:null,isMap:Y,itemId:null,itemProp:xz,itemRef:xz,itemScope:Y,itemType:xz,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Y,low:X,manifest:null,max:null,maxLength:X,media:null,method:null,min:null,minLength:X,multiple:Y,muted:Y,name:null,nonce:null,noModule:Y,noValidate:Y,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:Y,optimum:X,pattern:null,ping:xz,placeholder:null,playsInline:Y,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Y,referrerPolicy:null,rel:xz,required:Y,reversed:Y,rows:X,rowSpan:X,sandbox:xz,scope:null,scoped:Y,seamless:Y,selected:Y,shadowRootClonable:Y,shadowRootCustomElementRegistry:Y,shadowRootDelegatesFocus:Y,shadowRootMode:null,shadowRootSerializable:Y,shape:null,size:X,sizes:null,slot:null,span:X,spellCheck:yz,src:null,srcDoc:null,srcLang:null,srcSet:null,start:X,step:null,style:null,tabIndex:X,target:null,title:null,translate:null,type:null,typeMustMatch:Y,useMap:null,value:yz,width:X,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:xz,axis:null,background:null,bgColor:null,border:X,borderColor:null,bottomMargin:X,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Y,declare:Y,event:null,face:null,frame:null,frameBorder:null,hSpace:X,leftMargin:X,link:null,longDesc:null,lowSrc:null,marginHeight:X,marginWidth:X,noResize:Y,noHref:Y,noShade:Y,noWrap:Y,object:null,profile:null,prompt:null,rev:null,rightMargin:X,rules:null,scheme:null,scrolling:yz,standby:null,summary:null,text:null,topMargin:X,valueType:null,version:null,vAlign:null,vLink:null,vSpace:X,allowTransparency:null,autoCorrect:null,autoSave:null,credentialless:Y,disablePictureInPicture:Y,disableRemotePlayback:Y,exportParts:Sz,part:xz,prefix:null,property:null,results:X,security:null,unselectable:null},space:`html`,transform:jz}),Nz=Oz({attributes:{accentHeight:`accent-height`,alignmentBaseline:`alignment-baseline`,arabicForm:`arabic-form`,baselineShift:`baseline-shift`,capHeight:`cap-height`,className:`class`,clipPath:`clip-path`,clipRule:`clip-rule`,colorInterpolation:`color-interpolation`,colorInterpolationFilters:`color-interpolation-filters`,colorProfile:`color-profile`,colorRendering:`color-rendering`,crossOrigin:`crossorigin`,dataType:`datatype`,dominantBaseline:`dominant-baseline`,enableBackground:`enable-background`,fillOpacity:`fill-opacity`,fillRule:`fill-rule`,floodColor:`flood-color`,floodOpacity:`flood-opacity`,fontFamily:`font-family`,fontSize:`font-size`,fontSizeAdjust:`font-size-adjust`,fontStretch:`font-stretch`,fontStyle:`font-style`,fontVariant:`font-variant`,fontWeight:`font-weight`,glyphName:`glyph-name`,glyphOrientationHorizontal:`glyph-orientation-horizontal`,glyphOrientationVertical:`glyph-orientation-vertical`,hrefLang:`hreflang`,horizAdvX:`horiz-adv-x`,horizOriginX:`horiz-origin-x`,horizOriginY:`horiz-origin-y`,imageRendering:`image-rendering`,letterSpacing:`letter-spacing`,lightingColor:`lighting-color`,markerEnd:`marker-end`,markerMid:`marker-mid`,markerStart:`marker-start`,maskType:`mask-type`,navDown:`nav-down`,navDownLeft:`nav-down-left`,navDownRight:`nav-down-right`,navLeft:`nav-left`,navNext:`nav-next`,navPrev:`nav-prev`,navRight:`nav-right`,navUp:`nav-up`,navUpLeft:`nav-up-left`,navUpRight:`nav-up-right`,onAbort:`onabort`,onActivate:`onactivate`,onAfterPrint:`onafterprint`,onBeforePrint:`onbeforeprint`,onBegin:`onbegin`,onCancel:`oncancel`,onCanPlay:`oncanplay`,onCanPlayThrough:`oncanplaythrough`,onChange:`onchange`,onClick:`onclick`,onClose:`onclose`,onCopy:`oncopy`,onCueChange:`oncuechange`,onCut:`oncut`,onDblClick:`ondblclick`,onDrag:`ondrag`,onDragEnd:`ondragend`,onDragEnter:`ondragenter`,onDragExit:`ondragexit`,onDragLeave:`ondragleave`,onDragOver:`ondragover`,onDragStart:`ondragstart`,onDrop:`ondrop`,onDurationChange:`ondurationchange`,onEmptied:`onemptied`,onEnd:`onend`,onEnded:`onended`,onError:`onerror`,onFocus:`onfocus`,onFocusIn:`onfocusin`,onFocusOut:`onfocusout`,onHashChange:`onhashchange`,onInput:`oninput`,onInvalid:`oninvalid`,onKeyDown:`onkeydown`,onKeyPress:`onkeypress`,onKeyUp:`onkeyup`,onLoad:`onload`,onLoadedData:`onloadeddata`,onLoadedMetadata:`onloadedmetadata`,onLoadStart:`onloadstart`,onMessage:`onmessage`,onMouseDown:`onmousedown`,onMouseEnter:`onmouseenter`,onMouseLeave:`onmouseleave`,onMouseMove:`onmousemove`,onMouseOut:`onmouseout`,onMouseOver:`onmouseover`,onMouseUp:`onmouseup`,onMouseWheel:`onmousewheel`,onOffline:`onoffline`,onOnline:`ononline`,onPageHide:`onpagehide`,onPageShow:`onpageshow`,onPaste:`onpaste`,onPause:`onpause`,onPlay:`onplay`,onPlaying:`onplaying`,onPopState:`onpopstate`,onProgress:`onprogress`,onRateChange:`onratechange`,onRepeat:`onrepeat`,onReset:`onreset`,onResize:`onresize`,onScroll:`onscroll`,onSeeked:`onseeked`,onSeeking:`onseeking`,onSelect:`onselect`,onShow:`onshow`,onStalled:`onstalled`,onStorage:`onstorage`,onSubmit:`onsubmit`,onSuspend:`onsuspend`,onTimeUpdate:`ontimeupdate`,onToggle:`ontoggle`,onUnload:`onunload`,onVolumeChange:`onvolumechange`,onWaiting:`onwaiting`,onZoom:`onzoom`,overlinePosition:`overline-position`,overlineThickness:`overline-thickness`,paintOrder:`paint-order`,panose1:`panose-1`,pointerEvents:`pointer-events`,referrerPolicy:`referrerpolicy`,renderingIntent:`rendering-intent`,shapeRendering:`shape-rendering`,stopColor:`stop-color`,stopOpacity:`stop-opacity`,strikethroughPosition:`strikethrough-position`,strikethroughThickness:`strikethrough-thickness`,strokeDashArray:`stroke-dasharray`,strokeDashOffset:`stroke-dashoffset`,strokeLineCap:`stroke-linecap`,strokeLineJoin:`stroke-linejoin`,strokeMiterLimit:`stroke-miterlimit`,strokeOpacity:`stroke-opacity`,strokeWidth:`stroke-width`,tabIndex:`tabindex`,textAnchor:`text-anchor`,textDecoration:`text-decoration`,textRendering:`text-rendering`,transformOrigin:`transform-origin`,typeOf:`typeof`,underlinePosition:`underline-position`,underlineThickness:`underline-thickness`,unicodeBidi:`unicode-bidi`,unicodeRange:`unicode-range`,unitsPerEm:`units-per-em`,vAlphabetic:`v-alphabetic`,vHanging:`v-hanging`,vIdeographic:`v-ideographic`,vMathematical:`v-mathematical`,vectorEffect:`vector-effect`,vertAdvY:`vert-adv-y`,vertOriginX:`vert-origin-x`,vertOriginY:`vert-origin-y`,wordSpacing:`word-spacing`,writingMode:`writing-mode`,xHeight:`x-height`,playbackOrder:`playbackorder`,timelineBegin:`timelinebegin`},properties:{about:Cz,accentHeight:X,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:X,amplitude:X,arabicForm:null,ascent:X,attributeName:null,attributeType:null,azimuth:X,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:X,by:null,calcMode:null,capHeight:X,className:xz,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:X,diffuseConstant:X,direction:null,display:null,dur:null,divisor:X,dominantBaseline:null,download:Y,dx:null,dy:null,edgeMode:null,editable:null,elevation:X,enableBackground:null,end:null,event:null,exponent:X,externalResourcesRequired:null,fill:null,fillOpacity:X,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:Sz,g2:Sz,glyphName:Sz,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:X,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:X,horizOriginX:X,horizOriginY:X,id:null,ideographic:X,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:X,k:X,k1:X,k2:X,k3:X,k4:X,kernelMatrix:Cz,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:X,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskType:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:X,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:X,overlineThickness:X,paintOrder:null,panose1:null,path:null,pathLength:X,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:xz,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:X,pointsAtY:X,pointsAtZ:X,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:Cz,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:Cz,rev:Cz,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:Cz,requiredFeatures:Cz,requiredFonts:Cz,requiredFormats:Cz,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:X,specularExponent:X,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:X,strikethroughThickness:X,string:null,stroke:null,strokeDashArray:Cz,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:X,strokeOpacity:X,strokeWidth:null,style:null,surfaceScale:X,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:Cz,tabIndex:X,tableValues:null,target:null,targetX:X,targetY:X,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:Cz,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:X,underlineThickness:X,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:X,values:null,vAlphabetic:X,vMathematical:X,vectorEffect:null,vHanging:X,vIdeographic:X,version:null,vertAdvY:X,vertOriginX:X,vertOriginY:X,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:X,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:`svg`,transform:Az}),Pz=Oz({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:`xlink`,transform(e,t){return`xlink:`+t.slice(5).toLowerCase()}}),Fz=Oz({attributes:{xmlnsxlink:`xmlns:xlink`},properties:{xmlnsXLink:null,xmlns:null},space:`xmlns`,transform:jz}),Iz=Oz({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:`xml`,transform(e,t){return`xml:`+t.slice(3).toLowerCase()}}),Lz={classId:`classID`,dataType:`datatype`,itemId:`itemID`,strokeDashArray:`strokeDasharray`,strokeDashOffset:`strokeDashoffset`,strokeLineCap:`strokeLinecap`,strokeLineJoin:`strokeLinejoin`,strokeMiterLimit:`strokeMiterlimit`,typeOf:`typeof`,xLinkActuate:`xlinkActuate`,xLinkArcRole:`xlinkArcrole`,xLinkHref:`xlinkHref`,xLinkRole:`xlinkRole`,xLinkShow:`xlinkShow`,xLinkTitle:`xlinkTitle`,xLinkType:`xlinkType`,xmlnsXLink:`xmlnsXlink`},Rz=/[A-Z]/g,zz=/-[a-z]/g,Bz=/^data[-\w.:]+$/i;function Vz(e,t){let n=hz(t),r=t,i=gz;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)===`data`&&Bz.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(zz,Uz);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!zz.test(e)){let n=e.replace(Rz,Hz);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=Ez}return new i(r,t)}function Hz(e){return`-`+e.toLowerCase()}function Uz(e){return e.charAt(1).toUpperCase()}var Wz=mz([kz,Mz,Pz,Fz,Iz],`html`),Gz=mz([kz,Nz,Pz,Fz,Iz],`svg`);function Kz(e){return e.join(` `).trim()}var qz=o(((e,t)=>{var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,i=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,l=/^\s+|\s+$/g,u=`
33
33
  `,d=`/`,f=`*`,p=``,m=`comment`,h=`declaration`;function g(e,t){if(typeof e!=`string`)throw TypeError(`First argument must be a string`);if(!e)return[];t||={};var l=1,g=1;function v(e){var t=e.match(r);t&&(l+=t.length);var n=e.lastIndexOf(u);g=~n?e.length-n:g+e.length}function y(){var e={line:l,column:g};return function(t){return t.position=new b(e),C(),t}}function b(e){this.start=e,this.end={line:l,column:g},this.source=t.source}b.prototype.content=e;function x(n){var r=Error(t.source+`:`+l+`:`+g+`: `+n);if(r.reason=n,r.filename=t.source,r.line=l,r.column=g,r.source=e,!t.silent)throw r}function S(t){var n=t.exec(e);if(n){var r=n[0];return v(r),e=e.slice(r.length),n}}function C(){S(i)}function w(e){var t;for(e||=[];t=T();)t!==!1&&e.push(t);return e}function T(){var t=y();if(!(d!=e.charAt(0)||f!=e.charAt(1))){for(var n=2;p!=e.charAt(n)&&(f!=e.charAt(n)||d!=e.charAt(n+1));)++n;if(n+=2,p===e.charAt(n-1))return x(`End of comment missing`);var r=e.slice(2,n-2);return g+=2,v(r),e=e.slice(n),g+=2,t({type:m,comment:r})}}function E(){var e=y(),t=S(a);if(t){if(T(),!S(o))return x(`property missing ':'`);var r=S(s),i=e({type:h,property:_(t[0].replace(n,p)),value:r?_(r[0].replace(n,p)):p});return S(c),i}}function ee(){var e=[];w(e);for(var t;t=E();)t!==!1&&(e.push(t),w(e));return e}return C(),ee()}function _(e){return e?e.replace(l,p):p}t.exports=g})),Jz=o((e=>{var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.default=r;var n=t(qz());function r(e,t){let r=null;if(!e||typeof e!=`string`)return r;let i=(0,n.default)(e),a=typeof t==`function`;return i.forEach(e=>{if(e.type!==`declaration`)return;let{property:n,value:i}=e;a?t(n,i,e):i&&(r||={},r[n]=i)}),r}})),Yz=o((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.camelCase=void 0;var t=/^--[a-zA-Z0-9_-]+$/,n=/-([a-z])/g,r=/^[^-]+$/,i=/^-(webkit|moz|ms|o|khtml)-/,a=/^-(ms)-/,o=function(e){return!e||r.test(e)||t.test(e)},s=function(e,t){return t.toUpperCase()},c=function(e,t){return`${t}-`};e.camelCase=function(e,t){return t===void 0&&(t={}),o(e)?e:(e=e.toLowerCase(),e=t.reactCompat?e.replace(a,c):e.replace(i,c),e.replace(n,s))}})),Xz=o(((e,t)=>{var n=(e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})(Jz()),r=Yz();function i(e,t){var i={};return!e||typeof e!=`string`||(0,n.default)(e,function(e,n){e&&n&&(i[(0,r.camelCase)(e,t)]=n)}),i}i.default=i,t.exports=i})),Zz=$z(`end`),Qz=$z(`start`);function $z(e){return t;function t(t){let n=t&&t.position&&t.position[e]||{};if(typeof n.line==`number`&&n.line>0&&typeof n.column==`number`&&n.column>0)return{line:n.line,column:n.column,offset:typeof n.offset==`number`&&n.offset>-1?n.offset:void 0}}}function eB(e){let t=Qz(e),n=Zz(e);if(t&&n)return{start:t,end:n}}function tB(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?rB(e.position):`start`in e||`end`in e?rB(e):`line`in e||`column`in e?nB(e):``}function nB(e){return iB(e&&e.line)+`:`+iB(e&&e.column)}function rB(e){return nB(e&&e.start)+`-`+nB(e&&e.end)}function iB(e){return e&&typeof e==`number`?e:1}var aB=class extends Error{constructor(e,t,n){super(),typeof t==`string`&&(n=t,t=void 0);let r=``,i={},a=!1;if(t&&(i=`line`in t&&`column`in t||`start`in t&&`end`in t?{place:t}:`type`in t?{ancestors:[t],place:t.position}:{...t}),typeof e==`string`?r=e:!i.cause&&e&&(a=!0,r=e.message,i.cause=e),!i.ruleId&&!i.source&&typeof n==`string`){let e=n.indexOf(`:`);e===-1?i.ruleId=n:(i.source=n.slice(0,e),i.ruleId=n.slice(e+1))}if(!i.place&&i.ancestors&&i.ancestors){let e=i.ancestors[i.ancestors.length-1];e&&(i.place=e.position)}let o=i.place&&`start`in i.place?i.place.start:i.place;this.ancestors=i.ancestors||void 0,this.cause=i.cause||void 0,this.column=o?o.column:void 0,this.fatal=void 0,this.file=``,this.message=r,this.line=o?o.line:void 0,this.name=tB(i.place)||`1:1`,this.place=i.place||void 0,this.reason=this.message,this.ruleId=i.ruleId||void 0,this.source=i.source||void 0,this.stack=a&&i.cause&&typeof i.cause.stack==`string`?i.cause.stack:``,this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};aB.prototype.file=``,aB.prototype.name=``,aB.prototype.reason=``,aB.prototype.message=``,aB.prototype.stack=``,aB.prototype.column=void 0,aB.prototype.line=void 0,aB.prototype.ancestors=void 0,aB.prototype.cause=void 0,aB.prototype.fatal=void 0,aB.prototype.place=void 0,aB.prototype.ruleId=void 0,aB.prototype.source=void 0;var oB=l(Xz(),1),sB={}.hasOwnProperty,cB=new Map,lB=/[A-Z]/g,uB=new Set([`table`,`tbody`,`thead`,`tfoot`,`tr`]),dB=new Set([`td`,`th`]);function fB(e,t){if(!t||t.Fragment===void 0)throw TypeError("Expected `Fragment` in options");let n=t.filePath||void 0,r;if(t.development){if(typeof t.jsxDEV!=`function`)throw TypeError("Expected `jsxDEV` in options when `development: true`");r=CB(n,t.jsxDEV)}else{if(typeof t.jsx!=`function`)throw TypeError("Expected `jsx` in production options");if(typeof t.jsxs!=`function`)throw TypeError("Expected `jsxs` in production options");r=SB(n,t.jsx,t.jsxs)}let i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||`react`,evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space===`svg`?Gz:Wz,stylePropertyNameCase:t.stylePropertyNameCase||`dom`,tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},a=pB(i,e,void 0);return a&&typeof a!=`string`?a:i.create(e,i.Fragment,{children:a||void 0},void 0)}function pB(e,t,n){if(t.type===`element`)return mB(e,t,n);if(t.type===`mdxFlowExpression`||t.type===`mdxTextExpression`)return hB(e,t);if(t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)return _B(e,t,n);if(t.type===`mdxjsEsm`)return gB(e,t);if(t.type===`root`)return vB(e,t,n);if(t.type===`text`)return yB(e,t)}function mB(e,t,n){let r=e.schema,i=r;t.tagName.toLowerCase()===`svg`&&r.space===`html`&&(i=Gz,e.schema=i),e.ancestors.push(t);let a=kB(e,t.tagName,!1),o=wB(e,t),s=EB(e,t);return uB.has(t.tagName)&&(s=s.filter(function(e){return typeof e==`string`?!dz(e):!0})),bB(e,o,a,t),xB(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function hB(e,t){if(t.data&&t.data.estree&&e.evaluater){let n=t.data.estree.body[0];return n.type,e.evaluater.evaluateExpression(n.expression)}AB(e,t.position)}function gB(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);AB(e,t.position)}function _B(e,t,n){let r=e.schema,i=r;t.name===`svg`&&r.space===`html`&&(i=Gz,e.schema=i),e.ancestors.push(t);let a=t.name===null?e.Fragment:kB(e,t.name,!0),o=TB(e,t),s=EB(e,t);return bB(e,o,a,t),xB(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function vB(e,t,n){let r={};return xB(r,EB(e,t)),e.create(t,e.Fragment,r,n)}function yB(e,t){return t.value}function bB(e,t,n,r){typeof n!=`string`&&n!==e.Fragment&&e.passNode&&(t.node=r)}function xB(e,t){if(t.length>0){let n=t.length>1?t:t[0];n&&(e.children=n)}}function SB(e,t,n){return r;function r(e,r,i,a){let o=Array.isArray(i.children)?n:t;return a?o(r,i,a):o(r,i)}}function CB(e,t){return n;function n(n,r,i,a){let o=Array.isArray(i.children),s=Qz(n);return t(r,i,a,o,{columnNumber:s?s.column-1:void 0,fileName:e,lineNumber:s?s.line:void 0},void 0)}}function wB(e,t){let n={},r,i;for(i in t.properties)if(i!==`children`&&sB.call(t.properties,i)){let a=DB(e,i,t.properties[i]);if(a){let[i,o]=a;e.tableCellAlignToStyle&&i===`align`&&typeof o==`string`&&dB.has(t.tagName)?r=o:n[i]=o}}if(r){let t=n.style||={};t[e.stylePropertyNameCase===`css`?`text-align`:`textAlign`]=r}return n}function TB(e,t){let n={};for(let r of t.attributes)if(r.type===`mdxJsxExpressionAttribute`)if(r.data&&r.data.estree&&e.evaluater){let t=r.data.estree.body[0];t.type;let i=t.expression;i.type;let a=i.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else AB(e,t.position);else{let i=r.name,a;if(r.value&&typeof r.value==`object`)if(r.value.data&&r.value.data.estree&&e.evaluater){let t=r.value.data.estree.body[0];t.type,a=e.evaluater.evaluateExpression(t.expression)}else AB(e,t.position);else a=r.value===null?!0:r.value;n[i]=a}return n}function EB(e,t){let n=[],r=-1,i=e.passKeys?new Map:cB;for(;++r<t.children.length;){let a=t.children[r],o;if(e.passKeys){let e=a.type===`element`?a.tagName:a.type===`mdxJsxFlowElement`||a.type===`mdxJsxTextElement`?a.name:void 0;if(e){let t=i.get(e)||0;o=e+`-`+t,i.set(e,t+1)}}let s=pB(e,a,o);s!==void 0&&n.push(s)}return n}function DB(e,t,n){let r=Vz(e.schema,t);if(!(n==null||typeof n==`number`&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?az(n):Kz(n)),r.property===`style`){let t=typeof n==`object`?n:OB(e,String(n));return e.stylePropertyNameCase===`css`&&(t=jB(t)),[`style`,t]}return[e.elementAttributeNameCase===`react`&&r.space?Lz[r.property]||r.property:r.attribute,n]}}function OB(e,t){try{return(0,oB.default)(t,{reactCompat:!0})}catch(t){if(e.ignoreInvalidStyle)return{};let n=t,r=new aB("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:n,ruleId:`style`,source:`hast-util-to-jsx-runtime`});throw r.file=e.filePath||void 0,r.url=`https://github.com/syntax-tree/hast-util-to-jsx-runtime#cannot-parse-style-attribute`,r}}function kB(e,t,n){let r;if(!n)r={type:`Literal`,value:t};else if(t.includes(`.`)){let e=t.split(`.`),n=-1,i;for(;++n<e.length;){let t=lz(e[n])?{type:`Identifier`,name:e[n]}:{type:`Literal`,value:e[n]};i=i?{type:`MemberExpression`,object:i,property:t,computed:!!(n&&t.type===`Literal`),optional:!1}:t}r=i}else r=lz(t)&&!/^[a-z]/.test(t)?{type:`Identifier`,name:t}:{type:`Literal`,value:t};if(r.type===`Literal`){let t=r.value;return sB.call(e.components,t)?e.components[t]:t}if(e.evaluater)return e.evaluater.evaluateExpression(r);AB(e)}function AB(e,t){let n=new aB("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:`mdx-estree`,source:`hast-util-to-jsx-runtime`});throw n.file=e.filePath||void 0,n.url=`https://github.com/syntax-tree/hast-util-to-jsx-runtime#cannot-handle-mdx-estrees-without-createevaluater`,n}function jB(e){let t={},n;for(n in e)sB.call(e,n)&&(t[MB(n)]=e[n]);return t}function MB(e){let t=e.replace(lB,NB);return t.slice(0,3)===`ms-`&&(t=`-`+t),t}function NB(e){return`-`+e.toLowerCase()}var PB={action:[`form`],cite:[`blockquote`,`del`,`ins`,`q`],data:[`object`],formAction:[`button`,`input`],href:[`a`,`area`,`base`,`link`],icon:[`menuitem`],itemId:null,manifest:[`html`],ping:[`a`,`area`],poster:[`video`],src:[`audio`,`embed`,`iframe`,`img`,`input`,`script`,`source`,`track`,`video`]},FB={};function IB(e,t){let n=t||FB;return LB(e,typeof n.includeImageAlt==`boolean`?n.includeImageAlt:!0,typeof n.includeHtml==`boolean`?n.includeHtml:!0)}function LB(e,t,n){if(zB(e)){if(`value`in e)return e.type===`html`&&!n?``:e.value;if(t&&`alt`in e&&e.alt)return e.alt;if(`children`in e)return RB(e.children,t,n)}return Array.isArray(e)?RB(e,t,n):``}function RB(e,t,n){let r=[],i=-1;for(;++i<e.length;)r[i]=LB(e[i],t,n);return r.join(``)}function zB(e){return!!(e&&typeof e==`object`)}var BB=document.createElement(`i`);function VB(e){let t=`&`+e+`;`;BB.innerHTML=t;let n=BB.textContent;return n.charCodeAt(n.length-1)===59&&e!==`semi`||n===t?!1:n}function HB(e,t,n,r){let i=e.length,a=0,o;if(t=t<0?-t>i?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);a<r.length;)o=r.slice(a,a+1e4),o.unshift(t,0),e.splice(...o),a+=1e4,t+=1e4}function UB(e,t){return e.length>0?(HB(e,e.length,0,t),e):t}var WB={}.hasOwnProperty;function GB(e){let t={},n=-1;for(;++n<e.length;)KB(t,e[n]);return t}function KB(e,t){let n;for(n in t){let r=(WB.call(e,n)?e[n]:void 0)||(e[n]={}),i=t[n],a;if(i)for(a in i){WB.call(r,a)||(r[a]=[]);let e=i[a];qB(r[a],Array.isArray(e)?e:e?[e]:[])}}}function qB(e,t){let n=-1,r=[];for(;++n<t.length;)(t[n].add===`after`?e:r).push(t[n]);HB(e,0,0,r)}function JB(e,t){let n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)==65535||(n&65535)==65534||n>1114111?`�`:String.fromCodePoint(n)}function YB(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var XB=oV(/[A-Za-z]/),ZB=oV(/[\dA-Za-z]/),QB=oV(/[#-'*+\--9=?A-Z^-~]/);function $B(e){return e!==null&&(e<32||e===127)}var eV=oV(/\d/),tV=oV(/[\dA-Fa-f]/),nV=oV(/[!-/:-@[-`{-~]/);function Z(e){return e!==null&&e<-2}function rV(e){return e!==null&&(e<0||e===32)}function Q(e){return e===-2||e===-1||e===32}var iV=oV(/\p{P}|\p{S}/u),aV=oV(/\s/);function oV(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function sV(e){let t=[],n=-1,r=0,i=0;for(;++n<e.length;){let a=e.charCodeAt(n),o=``;if(a===37&&ZB(e.charCodeAt(n+1))&&ZB(e.charCodeAt(n+2)))i=2;else if(a<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(a))||(o=String.fromCharCode(a));else if(a>55295&&a<57344){let t=e.charCodeAt(n+1);a<56320&&t>56319&&t<57344?(o=String.fromCharCode(a,t),i=1):o=`�`}else o=String.fromCharCode(a);o&&=(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,``),i&&=(n+=i,0)}return t.join(``)+e.slice(r)}function $(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return Q(r)?(e.enter(n),s(r)):t(r)}function s(r){return Q(r)&&a++<i?(e.consume(r),s):(e.exit(n),t(r))}}var cV={tokenize:lV};function lV(e){let t=e.attempt(this.parser.constructs.contentInitial,r,i),n;return t;function r(n){if(n===null){e.consume(n);return}return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),$(e,t,`linePrefix`)}function i(t){return e.enter(`paragraph`),a(t)}function a(t){let r=e.enter(`chunkText`,{contentType:`text`,previous:n});return n&&(n.next=r),n=r,o(t)}function o(t){if(t===null){e.exit(`chunkText`),e.exit(`paragraph`),e.consume(t);return}return Z(t)?(e.consume(t),e.exit(`chunkText`),a):(e.consume(t),o)}}var uV={tokenize:fV},dV={tokenize:pV};function fV(e){let t=this,n=[],r=0,i,a,o;return s;function s(i){if(r<n.length){let a=n[r];return t.containerState=a[1],e.attempt(a[0].continuation,c,l)(i)}return l(i)}function c(e){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&v();let n=t.events.length,a=n,o;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){o=t.events[a][1].end;break}_(r);let s=n;for(;s<t.events.length;)t.events[s][1].end={...o},s++;return HB(t.events,a+1,0,t.events.slice(n)),t.events.length=s,l(e)}return s(e)}function l(a){if(r===n.length){if(!i)return f(a);if(i.currentConstruct&&i.currentConstruct.concrete)return m(a);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(dV,u,d)(a)}function u(e){return i&&v(),_(r),f(e)}function d(e){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,m(e)}function f(n){return t.containerState={},e.attempt(dV,p,m)(n)}function p(e){return r++,n.push([t.currentConstruct,t.containerState]),f(e)}function m(n){if(n===null){i&&v(),_(0),e.consume(n);return}return i||=t.parser.flow(t.now()),e.enter(`chunkFlow`,{_tokenizer:i,contentType:`flow`,previous:a}),h(n)}function h(n){if(n===null){g(e.exit(`chunkFlow`),!0),_(0),e.consume(n);return}return Z(n)?(e.consume(n),g(e.exit(`chunkFlow`)),r=0,t.interrupt=void 0,s):(e.consume(n),h)}function g(e,n){let s=t.sliceStream(e);if(n&&s.push(null),e.previous=a,a&&(a.next=e),a=e,i.defineSkip(e.start),i.write(s),t.parser.lazy[e.start.line]){let e=i.events.length;for(;e--;)if(i.events[e][1].start.offset<o&&(!i.events[e][1].end||i.events[e][1].end.offset>o))return;let n=t.events.length,a=n,s,c;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){if(s){c=t.events[a][1].end;break}s=!0}for(_(r),e=n;e<t.events.length;)t.events[e][1].end={...c},e++;HB(t.events,a+1,0,t.events.slice(n)),t.events.length=e}}function _(r){let i=n.length;for(;i-- >r;){let r=n[i];t.containerState=r[1],r[0].exit.call(t,e)}n.length=r}function v(){i.write([null]),a=void 0,i=void 0,t.containerState._closeFlow=void 0}}function pV(e,t,n){return $(e,e.attempt(this.parser.constructs.document,t,n),`linePrefix`,this.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)}function mV(e){if(e===null||rV(e)||aV(e))return 1;if(iV(e))return 2}function hV(e,t,n){let r=[],i=-1;for(;++i<e.length;){let a=e[i].resolveAll;a&&!r.includes(a)&&(t=a(t,n),r.push(a))}return t}var gV={name:`attention`,resolveAll:_V,tokenize:vV};function _V(e,t){let n=-1,r,i,a,o,s,c,l,u;for(;++n<e.length;)if(e[n][0]===`enter`&&e[n][1].type===`attentionSequence`&&e[n][1]._close){for(r=n;r--;)if(e[r][0]===`exit`&&e[r][1].type===`attentionSequence`&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;c=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;let d={...e[r][1].end},f={...e[n][1].start};yV(d,-c),yV(f,c),o={type:c>1?`strongSequence`:`emphasisSequence`,start:d,end:{...e[r][1].end}},s={type:c>1?`strongSequence`:`emphasisSequence`,start:{...e[n][1].start},end:f},a={type:c>1?`strongText`:`emphasisText`,start:{...e[r][1].end},end:{...e[n][1].start}},i={type:c>1?`strong`:`emphasis`,start:{...o.start},end:{...s.end}},e[r][1].end={...o.start},e[n][1].start={...s.end},l=[],e[r][1].end.offset-e[r][1].start.offset&&(l=UB(l,[[`enter`,e[r][1],t],[`exit`,e[r][1],t]])),l=UB(l,[[`enter`,i,t],[`enter`,o,t],[`exit`,o,t],[`enter`,a,t]]),l=UB(l,hV(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),l=UB(l,[[`exit`,a,t],[`enter`,s,t],[`exit`,s,t],[`exit`,i,t]]),e[n][1].end.offset-e[n][1].start.offset?(u=2,l=UB(l,[[`enter`,e[n][1],t],[`exit`,e[n][1],t]])):u=0,HB(e,r-1,n-r+3,l),n=r+l.length-u-2;break}}for(n=-1;++n<e.length;)e[n][1].type===`attentionSequence`&&(e[n][1].type=`data`);return e}function vV(e,t){let n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=mV(r),a;return o;function o(t){return a=t,e.enter(`attentionSequence`),s(t)}function s(o){if(o===a)return e.consume(o),s;let c=e.exit(`attentionSequence`),l=mV(o),u=!l||l===2&&i||n.includes(o),d=!i||i===2&&l||n.includes(r);return c._open=!!(a===42?u:u&&(i||!d)),c._close=!!(a===42?d:d&&(l||!u)),t(o)}}function yV(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}var bV={name:`autolink`,tokenize:xV};function xV(e,t,n){let r=0;return i;function i(t){return e.enter(`autolink`),e.enter(`autolinkMarker`),e.consume(t),e.exit(`autolinkMarker`),e.enter(`autolinkProtocol`),a}function a(t){return XB(t)?(e.consume(t),o):t===64?n(t):l(t)}function o(e){return e===43||e===45||e===46||ZB(e)?(r=1,s(e)):l(e)}function s(t){return t===58?(e.consume(t),r=0,c):(t===43||t===45||t===46||ZB(t))&&r++<32?(e.consume(t),s):(r=0,l(t))}function c(r){return r===62?(e.exit(`autolinkProtocol`),e.enter(`autolinkMarker`),e.consume(r),e.exit(`autolinkMarker`),e.exit(`autolink`),t):r===null||r===32||r===60||$B(r)?n(r):(e.consume(r),c)}function l(t){return t===64?(e.consume(t),u):QB(t)?(e.consume(t),l):n(t)}function u(e){return ZB(e)?d(e):n(e)}function d(n){return n===46?(e.consume(n),r=0,u):n===62?(e.exit(`autolinkProtocol`).type=`autolinkEmail`,e.enter(`autolinkMarker`),e.consume(n),e.exit(`autolinkMarker`),e.exit(`autolink`),t):f(n)}function f(t){if((t===45||ZB(t))&&r++<63){let n=t===45?f:d;return e.consume(t),n}return n(t)}}var SV={partial:!0,tokenize:CV};function CV(e,t,n){return r;function r(t){return Q(t)?$(e,i,`linePrefix`)(t):i(t)}function i(e){return e===null||Z(e)?t(e):n(e)}}var wV={continuation:{tokenize:EV},exit:DV,name:`blockQuote`,tokenize:TV};function TV(e,t,n){let r=this;return i;function i(t){if(t===62){let n=r.containerState;return n.open||=(e.enter(`blockQuote`,{_container:!0}),!0),e.enter(`blockQuotePrefix`),e.enter(`blockQuoteMarker`),e.consume(t),e.exit(`blockQuoteMarker`),a}return n(t)}function a(n){return Q(n)?(e.enter(`blockQuotePrefixWhitespace`),e.consume(n),e.exit(`blockQuotePrefixWhitespace`),e.exit(`blockQuotePrefix`),t):(e.exit(`blockQuotePrefix`),t(n))}}function EV(e,t,n){let r=this;return i;function i(t){return Q(t)?$(e,a,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):a(t)}function a(r){return e.attempt(wV,t,n)(r)}}function DV(e){e.exit(`blockQuote`)}var OV={name:`characterEscape`,tokenize:kV};function kV(e,t,n){return r;function r(t){return e.enter(`characterEscape`),e.enter(`escapeMarker`),e.consume(t),e.exit(`escapeMarker`),i}function i(r){return nV(r)?(e.enter(`characterEscapeValue`),e.consume(r),e.exit(`characterEscapeValue`),e.exit(`characterEscape`),t):n(r)}}var AV={name:`characterReference`,tokenize:jV};function jV(e,t,n){let r=this,i=0,a,o;return s;function s(t){return e.enter(`characterReference`),e.enter(`characterReferenceMarker`),e.consume(t),e.exit(`characterReferenceMarker`),c}function c(t){return t===35?(e.enter(`characterReferenceMarkerNumeric`),e.consume(t),e.exit(`characterReferenceMarkerNumeric`),l):(e.enter(`characterReferenceValue`),a=31,o=ZB,u(t))}function l(t){return t===88||t===120?(e.enter(`characterReferenceMarkerHexadecimal`),e.consume(t),e.exit(`characterReferenceMarkerHexadecimal`),e.enter(`characterReferenceValue`),a=6,o=tV,u):(e.enter(`characterReferenceValue`),a=7,o=eV,u(t))}function u(s){if(s===59&&i){let i=e.exit(`characterReferenceValue`);return o===ZB&&!VB(r.sliceSerialize(i))?n(s):(e.enter(`characterReferenceMarker`),e.consume(s),e.exit(`characterReferenceMarker`),e.exit(`characterReference`),t)}return o(s)&&i++<a?(e.consume(s),u):n(s)}}var MV={partial:!0,tokenize:FV},NV={concrete:!0,name:`codeFenced`,tokenize:PV};function PV(e,t,n){let r=this,i={partial:!0,tokenize:x},a=0,o=0,s;return c;function c(e){return l(e)}function l(t){let n=r.events[r.events.length-1];return a=n&&n[1].type===`linePrefix`?n[2].sliceSerialize(n[1],!0).length:0,s=t,e.enter(`codeFenced`),e.enter(`codeFencedFence`),e.enter(`codeFencedFenceSequence`),u(t)}function u(t){return t===s?(o++,e.consume(t),u):o<3?n(t):(e.exit(`codeFencedFenceSequence`),Q(t)?$(e,d,`whitespace`)(t):d(t))}function d(n){return n===null||Z(n)?(e.exit(`codeFencedFence`),r.interrupt?t(n):e.check(MV,h,b)(n)):(e.enter(`codeFencedFenceInfo`),e.enter(`chunkString`,{contentType:`string`}),f(n))}function f(t){return t===null||Z(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),d(t)):Q(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),$(e,p,`whitespace`)(t)):t===96&&t===s?n(t):(e.consume(t),f)}function p(t){return t===null||Z(t)?d(t):(e.enter(`codeFencedFenceMeta`),e.enter(`chunkString`,{contentType:`string`}),m(t))}function m(t){return t===null||Z(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceMeta`),d(t)):t===96&&t===s?n(t):(e.consume(t),m)}function h(t){return e.attempt(i,b,g)(t)}function g(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),_}function _(t){return a>0&&Q(t)?$(e,v,`linePrefix`,a+1)(t):v(t)}function v(t){return t===null||Z(t)?e.check(MV,h,b)(t):(e.enter(`codeFlowValue`),y(t))}function y(t){return t===null||Z(t)?(e.exit(`codeFlowValue`),v(t)):(e.consume(t),y)}function b(n){return e.exit(`codeFenced`),t(n)}function x(e,t,n){let i=0;return a;function a(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c}function c(t){return e.enter(`codeFencedFence`),Q(t)?$(e,l,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):l(t)}function l(t){return t===s?(e.enter(`codeFencedFenceSequence`),u(t)):n(t)}function u(t){return t===s?(i++,e.consume(t),u):i>=o?(e.exit(`codeFencedFenceSequence`),Q(t)?$(e,d,`whitespace`)(t):d(t)):n(t)}function d(r){return r===null||Z(r)?(e.exit(`codeFencedFence`),t(r)):n(r)}}}function FV(e,t,n){let r=this;return i;function i(t){return t===null?n(t):(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}var IV={name:`codeIndented`,tokenize:RV},LV={partial:!0,tokenize:zV};function RV(e,t,n){let r=this;return i;function i(t){return e.enter(`codeIndented`),$(e,a,`linePrefix`,5)(t)}function a(e){let t=r.events[r.events.length-1];return t&&t[1].type===`linePrefix`&&t[2].sliceSerialize(t[1],!0).length>=4?o(e):n(e)}function o(t){return t===null?c(t):Z(t)?e.attempt(LV,o,c)(t):(e.enter(`codeFlowValue`),s(t))}function s(t){return t===null||Z(t)?(e.exit(`codeFlowValue`),o(t)):(e.consume(t),s)}function c(n){return e.exit(`codeIndented`),t(n)}}function zV(e,t,n){let r=this;return i;function i(t){return r.parser.lazy[r.now().line]?n(t):Z(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),i):$(e,a,`linePrefix`,5)(t)}function a(e){let a=r.events[r.events.length-1];return a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(e):Z(e)?i(e):n(e)}}var BV={name:`codeText`,previous:HV,resolve:VV,tokenize:UV};function VV(e){let t=e.length-4,n=3,r,i;if((e[n][1].type===`lineEnding`||e[n][1].type===`space`)&&(e[t][1].type===`lineEnding`||e[t][1].type===`space`)){for(r=n;++r<t;)if(e[r][1].type===`codeTextData`){e[n][1].type=`codeTextPadding`,e[t][1].type=`codeTextPadding`,n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!==`lineEnding`&&(i=r):(r===t||e[r][1].type===`lineEnding`)&&(e[i][1].type=`codeTextData`,r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function HV(e){return e!==96||this.events[this.events.length-1][1].type===`characterEscape`}function UV(e,t,n){let r=0,i,a;return o;function o(t){return e.enter(`codeText`),e.enter(`codeTextSequence`),s(t)}function s(t){return t===96?(e.consume(t),r++,s):(e.exit(`codeTextSequence`),c(t))}function c(t){return t===null?n(t):t===32?(e.enter(`space`),e.consume(t),e.exit(`space`),c):t===96?(a=e.enter(`codeTextSequence`),i=0,u(t)):Z(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c):(e.enter(`codeTextData`),l(t))}function l(t){return t===null||t===32||t===96||Z(t)?(e.exit(`codeTextData`),c(t)):(e.consume(t),l)}function u(n){return n===96?(e.consume(n),i++,u):i===r?(e.exit(`codeTextSequence`),e.exit(`codeText`),t(n)):(a.type=`codeTextData`,l(n))}}var WV=class{constructor(e){this.left=e?[...e]:[],this.right=[]}get(e){if(e<0||e>=this.left.length+this.right.length)throw RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return e<this.left.length?this.left[e]:this.right[this.right.length-e+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(e,t){let n=t??1/0;return n<this.left.length?this.left.slice(e,n):e>this.left.length?this.right.slice(this.right.length-n+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-n+this.left.length).reverse())}splice(e,t,n){let r=t||0;this.setCursor(Math.trunc(e));let i=this.right.splice(this.right.length-r,1/0);return n&&GV(this.left,n),i.reverse()}pop(){return this.setCursor(1/0),this.left.pop()}push(e){this.setCursor(1/0),this.left.push(e)}pushMany(e){this.setCursor(1/0),GV(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),GV(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0))if(e<this.left.length){let t=this.left.splice(e,1/0);GV(this.right,t.reverse())}else{let t=this.right.splice(this.left.length+this.right.length-e,1/0);GV(this.left,t.reverse())}}};function GV(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function KV(e){let t={},n=-1,r,i,a,o,s,c,l,u=new WV(e);for(;++n<u.length;){for(;n in t;)n=t[n];if(r=u.get(n),n&&r[1].type===`chunkFlow`&&u.get(n-1)[1].type===`listItemPrefix`&&(c=r[1]._tokenizer.events,a=0,a<c.length&&c[a][1].type===`lineEndingBlank`&&(a+=2),a<c.length&&c[a][1].type===`content`))for(;++a<c.length&&c[a][1].type!==`content`;)c[a][1].type===`chunkText`&&(c[a][1]._isInFirstContentOfListItem=!0,a++);if(r[0]===`enter`)r[1].contentType&&(Object.assign(t,qV(u,n)),n=t[n],l=!0);else if(r[1]._container){for(a=n,i=void 0;a--;)if(o=u.get(a),o[1].type===`lineEnding`||o[1].type===`lineEndingBlank`)o[0]===`enter`&&(i&&(u.get(i)[1].type=`lineEndingBlank`),o[1].type=`lineEnding`,i=a);else if(!(o[1].type===`linePrefix`||o[1].type===`listItemIndent`))break;i&&(r[1].end={...u.get(i)[1].start},s=u.slice(i,n),s.unshift(r),u.splice(i,n-i+1,s))}}return HB(e,0,1/0,u.slice(0)),!l}function qV(e,t){let n=e.get(t)[1],r=e.get(t)[2],i=t-1,a=[],o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));let s=o.events,c=[],l={},u,d,f=-1,p=n,m=0,h=0,g=[h];for(;p;){for(;e.get(++i)[1]!==p;);a.push(i),p._tokenizer||(u=r.sliceStream(p),p.next||u.push(null),d&&o.defineSkip(p.start),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(u),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),d=p,p=p.next}for(p=n;++f<s.length;)s[f][0]===`exit`&&s[f-1][0]===`enter`&&s[f][1].type===s[f-1][1].type&&s[f][1].start.line!==s[f][1].end.line&&(h=f+1,g.push(h),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(o.events=[],p?(p._tokenizer=void 0,p.previous=void 0):g.pop(),f=g.length;f--;){let t=s.slice(g[f],g[f+1]),n=a.pop();c.push([n,n+t.length-1]),e.splice(n,2,t)}for(c.reverse(),f=-1;++f<c.length;)l[m+c[f][0]]=m+c[f][1],m+=c[f][1]-c[f][0]-1;return l}var JV={resolve:XV,tokenize:ZV},YV={partial:!0,tokenize:QV};function XV(e){return KV(e),e}function ZV(e,t){let n;return r;function r(t){return e.enter(`content`),n=e.enter(`chunkContent`,{contentType:`content`}),i(t)}function i(t){return t===null?a(t):Z(t)?e.check(YV,o,a)(t):(e.consume(t),i)}function a(n){return e.exit(`chunkContent`),e.exit(`content`),t(n)}function o(t){return e.consume(t),e.exit(`chunkContent`),n.next=e.enter(`chunkContent`,{contentType:`content`,previous:n}),n=n.next,i}}function QV(e,t,n){let r=this;return i;function i(t){return e.exit(`chunkContent`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),$(e,a,`linePrefix`)}function a(i){if(i===null||Z(i))return n(i);let a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes(`codeIndented`)&&a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(i):e.interrupt(r.parser.constructs.flow,n,t)(i)}}function $V(e,t,n,r,i,a,o,s,c){let l=c||1/0,u=0;return d;function d(t){return t===60?(e.enter(r),e.enter(i),e.enter(a),e.consume(t),e.exit(a),f):t===null||t===32||t===41||$B(t)?n(t):(e.enter(r),e.enter(o),e.enter(s),e.enter(`chunkString`,{contentType:`string`}),h(t))}function f(n){return n===62?(e.enter(a),e.consume(n),e.exit(a),e.exit(i),e.exit(r),t):(e.enter(s),e.enter(`chunkString`,{contentType:`string`}),p(n))}function p(t){return t===62?(e.exit(`chunkString`),e.exit(s),f(t)):t===null||t===60||Z(t)?n(t):(e.consume(t),t===92?m:p)}function m(t){return t===60||t===62||t===92?(e.consume(t),p):p(t)}function h(i){return!u&&(i===null||i===41||rV(i))?(e.exit(`chunkString`),e.exit(s),e.exit(o),e.exit(r),t(i)):u<l&&i===40?(e.consume(i),u++,h):i===41?(e.consume(i),u--,h):i===null||i===32||i===40||$B(i)?n(i):(e.consume(i),i===92?g:h)}function g(t){return t===40||t===41||t===92?(e.consume(t),h):h(t)}}function eH(e,t,n,r,i,a){let o=this,s=0,c;return l;function l(t){return e.enter(r),e.enter(i),e.consume(t),e.exit(i),e.enter(a),u}function u(l){return s>999||l===null||l===91||l===93&&!c||l===94&&!s&&`_hiddenFootnoteSupport`in o.parser.constructs?n(l):l===93?(e.exit(a),e.enter(i),e.consume(l),e.exit(i),e.exit(r),t):Z(l)?(e.enter(`lineEnding`),e.consume(l),e.exit(`lineEnding`),u):(e.enter(`chunkString`,{contentType:`string`}),d(l))}function d(t){return t===null||t===91||t===93||Z(t)||s++>999?(e.exit(`chunkString`),u(t)):(e.consume(t),c||=!Q(t),t===92?f:d)}function f(t){return t===91||t===92||t===93?(e.consume(t),s++,d):d(t)}}function tH(e,t,n,r,i,a){let o;return s;function s(t){return t===34||t===39||t===40?(e.enter(r),e.enter(i),e.consume(t),e.exit(i),o=t===40?41:t,c):n(t)}function c(n){return n===o?(e.enter(i),e.consume(n),e.exit(i),e.exit(r),t):(e.enter(a),l(n))}function l(t){return t===o?(e.exit(a),c(o)):t===null?n(t):Z(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),$(e,l,`linePrefix`)):(e.enter(`chunkString`,{contentType:`string`}),u(t))}function u(t){return t===o||t===null||Z(t)?(e.exit(`chunkString`),l(t)):(e.consume(t),t===92?d:u)}function d(t){return t===o||t===92?(e.consume(t),u):u(t)}}function nH(e,t){let n;return r;function r(i){return Z(i)?(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),n=!0,r):Q(i)?$(e,r,n?`linePrefix`:`lineSuffix`)(i):t(i)}}var rH={name:`definition`,tokenize:aH},iH={partial:!0,tokenize:oH};function aH(e,t,n){let r=this,i;return a;function a(t){return e.enter(`definition`),o(t)}function o(t){return eH.call(r,e,s,n,`definitionLabel`,`definitionLabelMarker`,`definitionLabelString`)(t)}function s(t){return i=YB(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),c):n(t)}function c(t){return rV(t)?nH(e,l)(t):l(t)}function l(t){return $V(e,u,n,`definitionDestination`,`definitionDestinationLiteral`,`definitionDestinationLiteralMarker`,`definitionDestinationRaw`,`definitionDestinationString`)(t)}function u(t){return e.attempt(iH,d,d)(t)}function d(t){return Q(t)?$(e,f,`whitespace`)(t):f(t)}function f(a){return a===null||Z(a)?(e.exit(`definition`),r.parser.defined.push(i),t(a)):n(a)}}function oH(e,t,n){return r;function r(t){return rV(t)?nH(e,i)(t):n(t)}function i(t){return tH(e,a,n,`definitionTitle`,`definitionTitleMarker`,`definitionTitleString`)(t)}function a(t){return Q(t)?$(e,o,`whitespace`)(t):o(t)}function o(e){return e===null||Z(e)?t(e):n(e)}}var sH={name:`hardBreakEscape`,tokenize:cH};function cH(e,t,n){return r;function r(t){return e.enter(`hardBreakEscape`),e.consume(t),i}function i(r){return Z(r)?(e.exit(`hardBreakEscape`),t(r)):n(r)}}var lH={name:`headingAtx`,resolve:uH,tokenize:dH};function uH(e,t){let n=e.length-2,r=3,i,a;return e[r][1].type===`whitespace`&&(r+=2),n-2>r&&e[n][1].type===`whitespace`&&(n-=2),e[n][1].type===`atxHeadingSequence`&&(r===n-1||n-4>r&&e[n-2][1].type===`whitespace`)&&(n-=r+1===n?2:4),n>r&&(i={type:`atxHeadingText`,start:e[r][1].start,end:e[n][1].end},a={type:`chunkText`,start:e[r][1].start,end:e[n][1].end,contentType:`text`},HB(e,r,n-r+1,[[`enter`,i,t],[`enter`,a,t],[`exit`,a,t],[`exit`,i,t]])),e}function dH(e,t,n){let r=0;return i;function i(t){return e.enter(`atxHeading`),a(t)}function a(t){return e.enter(`atxHeadingSequence`),o(t)}function o(t){return t===35&&r++<6?(e.consume(t),o):t===null||rV(t)?(e.exit(`atxHeadingSequence`),s(t)):n(t)}function s(n){return n===35?(e.enter(`atxHeadingSequence`),c(n)):n===null||Z(n)?(e.exit(`atxHeading`),t(n)):Q(n)?$(e,s,`whitespace`)(n):(e.enter(`atxHeadingText`),l(n))}function c(t){return t===35?(e.consume(t),c):(e.exit(`atxHeadingSequence`),s(t))}function l(t){return t===null||t===35||rV(t)?(e.exit(`atxHeadingText`),s(t)):(e.consume(t),l)}}var fH=`address.article.aside.base.basefont.blockquote.body.caption.center.col.colgroup.dd.details.dialog.dir.div.dl.dt.fieldset.figcaption.figure.footer.form.frame.frameset.h1.h2.h3.h4.h5.h6.head.header.hr.html.iframe.legend.li.link.main.menu.menuitem.nav.noframes.ol.optgroup.option.p.param.search.section.summary.table.tbody.td.tfoot.th.thead.title.tr.track.ul`.split(`.`),pH=[`pre`,`script`,`style`,`textarea`],mH={concrete:!0,name:`htmlFlow`,resolveTo:_H,tokenize:vH},hH={partial:!0,tokenize:bH},gH={partial:!0,tokenize:yH};function _H(e){let t=e.length;for(;t--&&!(e[t][0]===`enter`&&e[t][1].type===`htmlFlow`););return t>1&&e[t-2][1].type===`linePrefix`&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function vH(e,t,n){let r=this,i,a,o,s,c;return l;function l(e){return u(e)}function u(t){return e.enter(`htmlFlow`),e.enter(`htmlFlowData`),e.consume(t),d}function d(s){return s===33?(e.consume(s),f):s===47?(e.consume(s),a=!0,h):s===63?(e.consume(s),i=3,r.interrupt?t:k):XB(s)?(e.consume(s),o=String.fromCharCode(s),g):n(s)}function f(a){return a===45?(e.consume(a),i=2,p):a===91?(e.consume(a),i=5,s=0,m):XB(a)?(e.consume(a),i=4,r.interrupt?t:k):n(a)}function p(i){return i===45?(e.consume(i),r.interrupt?t:k):n(i)}function m(i){return i===`CDATA[`.charCodeAt(s++)?(e.consume(i),s===6?r.interrupt?t:D:m):n(i)}function h(t){return XB(t)?(e.consume(t),o=String.fromCharCode(t),g):n(t)}function g(s){if(s===null||s===47||s===62||rV(s)){let c=s===47,l=o.toLowerCase();return!c&&!a&&pH.includes(l)?(i=1,r.interrupt?t(s):D(s)):fH.includes(o.toLowerCase())?(i=6,c?(e.consume(s),_):r.interrupt?t(s):D(s)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(s):a?v(s):y(s))}return s===45||ZB(s)?(e.consume(s),o+=String.fromCharCode(s),g):n(s)}function _(i){return i===62?(e.consume(i),r.interrupt?t:D):n(i)}function v(t){return Q(t)?(e.consume(t),v):E(t)}function y(t){return t===47?(e.consume(t),E):t===58||t===95||XB(t)?(e.consume(t),b):Q(t)?(e.consume(t),y):E(t)}function b(t){return t===45||t===46||t===58||t===95||ZB(t)?(e.consume(t),b):x(t)}function x(t){return t===61?(e.consume(t),S):Q(t)?(e.consume(t),x):y(t)}function S(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),c=t,C):Q(t)?(e.consume(t),S):w(t)}function C(t){return t===c?(e.consume(t),c=null,T):t===null||Z(t)?n(t):(e.consume(t),C)}function w(t){return t===null||t===34||t===39||t===47||t===60||t===61||t===62||t===96||rV(t)?x(t):(e.consume(t),w)}function T(e){return e===47||e===62||Q(e)?y(e):n(e)}function E(t){return t===62?(e.consume(t),ee):n(t)}function ee(t){return t===null||Z(t)?D(t):Q(t)?(e.consume(t),ee):n(t)}function D(t){return t===45&&i===2?(e.consume(t),re):t===60&&i===1?(e.consume(t),ie):t===62&&i===4?(e.consume(t),A):t===63&&i===3?(e.consume(t),k):t===93&&i===5?(e.consume(t),oe):Z(t)&&(i===6||i===7)?(e.exit(`htmlFlowData`),e.check(hH,se,O)(t)):t===null||Z(t)?(e.exit(`htmlFlowData`),O(t)):(e.consume(t),D)}function O(t){return e.check(gH,te,se)(t)}function te(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),ne}function ne(t){return t===null||Z(t)?O(t):(e.enter(`htmlFlowData`),D(t))}function re(t){return t===45?(e.consume(t),k):D(t)}function ie(t){return t===47?(e.consume(t),o=``,ae):D(t)}function ae(t){if(t===62){let n=o.toLowerCase();return pH.includes(n)?(e.consume(t),A):D(t)}return XB(t)&&o.length<8?(e.consume(t),o+=String.fromCharCode(t),ae):D(t)}function oe(t){return t===93?(e.consume(t),k):D(t)}function k(t){return t===62?(e.consume(t),A):t===45&&i===2?(e.consume(t),k):D(t)}function A(t){return t===null||Z(t)?(e.exit(`htmlFlowData`),se(t)):(e.consume(t),A)}function se(n){return e.exit(`htmlFlow`),t(n)}}function yH(e,t,n){let r=this;return i;function i(t){return Z(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a):n(t)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}function bH(e,t,n){return r;function r(r){return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),e.attempt(SV,t,n)}}var xH={name:`htmlText`,tokenize:SH};function SH(e,t,n){let r=this,i,a,o;return s;function s(t){return e.enter(`htmlText`),e.enter(`htmlTextData`),e.consume(t),c}function c(t){return t===33?(e.consume(t),l):t===47?(e.consume(t),x):t===63?(e.consume(t),y):XB(t)?(e.consume(t),w):n(t)}function l(t){return t===45?(e.consume(t),u):t===91?(e.consume(t),a=0,m):XB(t)?(e.consume(t),v):n(t)}function u(t){return t===45?(e.consume(t),p):n(t)}function d(t){return t===null?n(t):t===45?(e.consume(t),f):Z(t)?(o=d,ie(t)):(e.consume(t),d)}function f(t){return t===45?(e.consume(t),p):d(t)}function p(e){return e===62?re(e):e===45?f(e):d(e)}function m(t){return t===`CDATA[`.charCodeAt(a++)?(e.consume(t),a===6?h:m):n(t)}function h(t){return t===null?n(t):t===93?(e.consume(t),g):Z(t)?(o=h,ie(t)):(e.consume(t),h)}function g(t){return t===93?(e.consume(t),_):h(t)}function _(t){return t===62?re(t):t===93?(e.consume(t),_):h(t)}function v(t){return t===null||t===62?re(t):Z(t)?(o=v,ie(t)):(e.consume(t),v)}function y(t){return t===null?n(t):t===63?(e.consume(t),b):Z(t)?(o=y,ie(t)):(e.consume(t),y)}function b(e){return e===62?re(e):y(e)}function x(t){return XB(t)?(e.consume(t),S):n(t)}function S(t){return t===45||ZB(t)?(e.consume(t),S):C(t)}function C(t){return Z(t)?(o=C,ie(t)):Q(t)?(e.consume(t),C):re(t)}function w(t){return t===45||ZB(t)?(e.consume(t),w):t===47||t===62||rV(t)?T(t):n(t)}function T(t){return t===47?(e.consume(t),re):t===58||t===95||XB(t)?(e.consume(t),E):Z(t)?(o=T,ie(t)):Q(t)?(e.consume(t),T):re(t)}function E(t){return t===45||t===46||t===58||t===95||ZB(t)?(e.consume(t),E):ee(t)}function ee(t){return t===61?(e.consume(t),D):Z(t)?(o=ee,ie(t)):Q(t)?(e.consume(t),ee):T(t)}function D(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),i=t,O):Z(t)?(o=D,ie(t)):Q(t)?(e.consume(t),D):(e.consume(t),te)}function O(t){return t===i?(e.consume(t),i=void 0,ne):t===null?n(t):Z(t)?(o=O,ie(t)):(e.consume(t),O)}function te(t){return t===null||t===34||t===39||t===60||t===61||t===96?n(t):t===47||t===62||rV(t)?T(t):(e.consume(t),te)}function ne(e){return e===47||e===62||rV(e)?T(e):n(e)}function re(r){return r===62?(e.consume(r),e.exit(`htmlTextData`),e.exit(`htmlText`),t):n(r)}function ie(t){return e.exit(`htmlTextData`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),ae}function ae(t){return Q(t)?$(e,oe,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):oe(t)}function oe(t){return e.enter(`htmlTextData`),o(t)}}var CH={name:`labelEnd`,resolveAll:DH,resolveTo:OH,tokenize:kH},wH={tokenize:AH},TH={tokenize:jH},EH={tokenize:MH};function DH(e){let t=-1,n=[];for(;++t<e.length;){let r=e[t][1];if(n.push(e[t]),r.type===`labelImage`||r.type===`labelLink`||r.type===`labelEnd`){let e=r.type===`labelImage`?4:2;r.type=`data`,t+=e}}return e.length!==n.length&&HB(e,0,e.length,n),e}function OH(e,t){let n=e.length,r=0,i,a,o,s;for(;n--;)if(i=e[n][1],a){if(i.type===`link`||i.type===`labelLink`&&i._inactive)break;e[n][0]===`enter`&&i.type===`labelLink`&&(i._inactive=!0)}else if(o){if(e[n][0]===`enter`&&(i.type===`labelImage`||i.type===`labelLink`)&&!i._balanced&&(a=n,i.type!==`labelLink`)){r=2;break}}else i.type===`labelEnd`&&(o=n);let c={type:e[a][1].type===`labelLink`?`link`:`image`,start:{...e[a][1].start},end:{...e[e.length-1][1].end}},l={type:`label`,start:{...e[a][1].start},end:{...e[o][1].end}},u={type:`labelText`,start:{...e[a+r+2][1].end},end:{...e[o-2][1].start}};return s=[[`enter`,c,t],[`enter`,l,t]],s=UB(s,e.slice(a+1,a+r+3)),s=UB(s,[[`enter`,u,t]]),s=UB(s,hV(t.parser.constructs.insideSpan.null,e.slice(a+r+4,o-3),t)),s=UB(s,[[`exit`,u,t],e[o-2],e[o-1],[`exit`,l,t]]),s=UB(s,e.slice(o+1)),s=UB(s,[[`exit`,c,t]]),HB(e,a,e.length,s),e}function kH(e,t,n){let r=this,i=r.events.length,a,o;for(;i--;)if((r.events[i][1].type===`labelImage`||r.events[i][1].type===`labelLink`)&&!r.events[i][1]._balanced){a=r.events[i][1];break}return s;function s(t){return a?a._inactive?d(t):(o=r.parser.defined.includes(YB(r.sliceSerialize({start:a.end,end:r.now()}))),e.enter(`labelEnd`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelEnd`),c):n(t)}function c(t){return t===40?e.attempt(wH,u,o?u:d)(t):t===91?e.attempt(TH,u,o?l:d)(t):o?u(t):d(t)}function l(t){return e.attempt(EH,u,d)(t)}function u(e){return t(e)}function d(e){return a._balanced=!0,n(e)}}function AH(e,t,n){return r;function r(t){return e.enter(`resource`),e.enter(`resourceMarker`),e.consume(t),e.exit(`resourceMarker`),i}function i(t){return rV(t)?nH(e,a)(t):a(t)}function a(t){return t===41?u(t):$V(e,o,s,`resourceDestination`,`resourceDestinationLiteral`,`resourceDestinationLiteralMarker`,`resourceDestinationRaw`,`resourceDestinationString`,32)(t)}function o(t){return rV(t)?nH(e,c)(t):u(t)}function s(e){return n(e)}function c(t){return t===34||t===39||t===40?tH(e,l,n,`resourceTitle`,`resourceTitleMarker`,`resourceTitleString`)(t):u(t)}function l(t){return rV(t)?nH(e,u)(t):u(t)}function u(r){return r===41?(e.enter(`resourceMarker`),e.consume(r),e.exit(`resourceMarker`),e.exit(`resource`),t):n(r)}}function jH(e,t,n){let r=this;return i;function i(t){return eH.call(r,e,a,o,`reference`,`referenceMarker`,`referenceString`)(t)}function a(e){return r.parser.defined.includes(YB(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(e):n(e)}function o(e){return n(e)}}function MH(e,t,n){return r;function r(t){return e.enter(`reference`),e.enter(`referenceMarker`),e.consume(t),e.exit(`referenceMarker`),i}function i(r){return r===93?(e.enter(`referenceMarker`),e.consume(r),e.exit(`referenceMarker`),e.exit(`reference`),t):n(r)}}var NH={name:`labelStartImage`,resolveAll:CH.resolveAll,tokenize:PH};function PH(e,t,n){let r=this;return i;function i(t){return e.enter(`labelImage`),e.enter(`labelImageMarker`),e.consume(t),e.exit(`labelImageMarker`),a}function a(t){return t===91?(e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelImage`),o):n(t)}function o(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):t(e)}}var FH={name:`labelStartLink`,resolveAll:CH.resolveAll,tokenize:IH};function IH(e,t,n){let r=this;return i;function i(t){return e.enter(`labelLink`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelLink`),a}function a(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):t(e)}}var LH={name:`lineEnding`,tokenize:RH};function RH(e,t){return n;function n(n){return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),$(e,t,`linePrefix`)}}var zH={name:`thematicBreak`,tokenize:BH};function BH(e,t,n){let r=0,i;return a;function a(t){return e.enter(`thematicBreak`),o(t)}function o(e){return i=e,s(e)}function s(a){return a===i?(e.enter(`thematicBreakSequence`),c(a)):r>=3&&(a===null||Z(a))?(e.exit(`thematicBreak`),t(a)):n(a)}function c(t){return t===i?(e.consume(t),r++,c):(e.exit(`thematicBreakSequence`),Q(t)?$(e,s,`whitespace`)(t):s(t))}}var VH={continuation:{tokenize:GH},exit:qH,name:`list`,tokenize:WH},HH={partial:!0,tokenize:JH},UH={partial:!0,tokenize:KH};function WH(e,t,n){let r=this,i=r.events[r.events.length-1],a=i&&i[1].type===`linePrefix`?i[2].sliceSerialize(i[1],!0).length:0,o=0;return s;function s(t){let i=r.containerState.type||(t===42||t===43||t===45?`listUnordered`:`listOrdered`);if(i===`listUnordered`?!r.containerState.marker||t===r.containerState.marker:eV(t)){if(r.containerState.type||(r.containerState.type=i,e.enter(i,{_container:!0})),i===`listUnordered`)return e.enter(`listItemPrefix`),t===42||t===45?e.check(zH,n,l)(t):l(t);if(!r.interrupt||t===49)return e.enter(`listItemPrefix`),e.enter(`listItemValue`),c(t)}return n(t)}function c(t){return eV(t)&&++o<10?(e.consume(t),c):(!r.interrupt||o<2)&&(r.containerState.marker?t===r.containerState.marker:t===41||t===46)?(e.exit(`listItemValue`),l(t)):n(t)}function l(t){return e.enter(`listItemMarker`),e.consume(t),e.exit(`listItemMarker`),r.containerState.marker=r.containerState.marker||t,e.check(SV,r.interrupt?n:u,e.attempt(HH,f,d))}function u(e){return r.containerState.initialBlankLine=!0,a++,f(e)}function d(t){return Q(t)?(e.enter(`listItemPrefixWhitespace`),e.consume(t),e.exit(`listItemPrefixWhitespace`),f):n(t)}function f(n){return r.containerState.size=a+r.sliceSerialize(e.exit(`listItemPrefix`),!0).length,t(n)}}function GH(e,t,n){let r=this;return r.containerState._closeFlow=void 0,e.check(SV,i,a);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,$(e,t,`listItemIndent`,r.containerState.size+1)(n)}function a(n){return r.containerState.furtherBlankLines||!Q(n)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(n)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(UH,t,o)(n))}function o(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,$(e,e.attempt(VH,t,n),`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(i)}}function KH(e,t,n){let r=this;return $(e,i,`listItemIndent`,r.containerState.size+1);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`listItemIndent`&&i[2].sliceSerialize(i[1],!0).length===r.containerState.size?t(e):n(e)}}function qH(e){e.exit(this.containerState.type)}function JH(e,t,n){let r=this;return $(e,i,`listItemPrefixWhitespace`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:5);function i(e){let i=r.events[r.events.length-1];return!Q(e)&&i&&i[1].type===`listItemPrefixWhitespace`?t(e):n(e)}}var YH={name:`setextUnderline`,resolveTo:XH,tokenize:ZH};function XH(e,t){let n=e.length,r,i,a;for(;n--;)if(e[n][0]===`enter`){if(e[n][1].type===`content`){r=n;break}e[n][1].type===`paragraph`&&(i=n)}else e[n][1].type===`content`&&e.splice(n,1),!a&&e[n][1].type===`definition`&&(a=n);let o={type:`setextHeading`,start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type=`setextHeadingText`,a?(e.splice(i,0,[`enter`,o,t]),e.splice(a+1,0,[`exit`,e[r][1],t]),e[r][1].end={...e[a][1].end}):e[r][1]=o,e.push([`exit`,o,t]),e}function ZH(e,t,n){let r=this,i;return a;function a(t){let a=r.events.length,s;for(;a--;)if(r.events[a][1].type!==`lineEnding`&&r.events[a][1].type!==`linePrefix`&&r.events[a][1].type!==`content`){s=r.events[a][1].type===`paragraph`;break}return!r.parser.lazy[r.now().line]&&(r.interrupt||s)?(e.enter(`setextHeadingLine`),i=t,o(t)):n(t)}function o(t){return e.enter(`setextHeadingLineSequence`),s(t)}function s(t){return t===i?(e.consume(t),s):(e.exit(`setextHeadingLineSequence`),Q(t)?$(e,c,`lineSuffix`)(t):c(t))}function c(r){return r===null||Z(r)?(e.exit(`setextHeadingLine`),t(r)):n(r)}}var QH={tokenize:$H};function $H(e){let t=this,n=e.attempt(SV,r,e.attempt(this.parser.constructs.flowInitial,i,$(e,e.attempt(this.parser.constructs.flow,i,e.attempt(JV,i)),`linePrefix`)));return n;function r(r){if(r===null){e.consume(r);return}return e.enter(`lineEndingBlank`),e.consume(r),e.exit(`lineEndingBlank`),t.currentConstruct=void 0,n}function i(r){if(r===null){e.consume(r);return}return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),t.currentConstruct=void 0,n}}var eU={resolveAll:iU()},tU=rU(`string`),nU=rU(`text`);function rU(e){return{resolveAll:iU(e===`text`?aU:void 0),tokenize:t};function t(t){let n=this,r=this.parser.constructs[e],i=t.attempt(r,a,o);return a;function a(e){return c(e)?i(e):o(e)}function o(e){if(e===null){t.consume(e);return}return t.enter(`data`),t.consume(e),s}function s(e){return c(e)?(t.exit(`data`),i(e)):(t.consume(e),s)}function c(e){if(e===null)return!0;let t=r[e],i=-1;if(t)for(;++i<t.length;){let e=t[i];if(!e.previous||e.previous.call(n,n.previous))return!0}return!1}}}function iU(e){return t;function t(t,n){let r=-1,i;for(;++r<=t.length;)i===void 0?t[r]&&t[r][1].type===`data`&&(i=r,r++):(!t[r]||t[r][1].type!==`data`)&&(r!==i+2&&(t[i][1].end=t[r-1][1].end,t.splice(i+2,r-i-2),r=i+2),i=void 0);return e?e(t,n):t}}function aU(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type===`lineEnding`)&&e[n-1][1].type===`data`){let r=e[n-1][1],i=t.sliceStream(r),a=i.length,o=-1,s=0,c;for(;a--;){let e=i[a];if(typeof e==`string`){for(o=e.length;e.charCodeAt(o-1)===32;)s++,o--;if(o)break;o=-1}else if(e===-2)c=!0,s++;else if(e!==-1){a++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(s=0),s){let i={type:n===e.length||c||s<2?`lineSuffix`:`hardBreakTrailing`,start:{_bufferIndex:a?o:r.start._bufferIndex+o,_index:r.start._index+a,line:r.end.line,column:r.end.column-s,offset:r.end.offset-s},end:{...r.end}};r.end={...i.start},r.start.offset===r.end.offset?Object.assign(r,i):(e.splice(n,0,[`enter`,i,t],[`exit`,i,t]),n+=2)}n++}return e}var oU=s({attentionMarkers:()=>mU,contentInitial:()=>cU,disable:()=>hU,document:()=>sU,flow:()=>uU,flowInitial:()=>lU,insideSpan:()=>pU,string:()=>dU,text:()=>fU}),sU={42:VH,43:VH,45:VH,48:VH,49:VH,50:VH,51:VH,52:VH,53:VH,54:VH,55:VH,56:VH,57:VH,62:wV},cU={91:rH},lU={[-2]:IV,[-1]:IV,32:IV},uU={35:lH,42:zH,45:[YH,zH],60:mH,61:YH,95:zH,96:NV,126:NV},dU={38:AV,92:OV},fU={[-5]:LH,[-4]:LH,[-3]:LH,33:NH,38:AV,42:gV,60:[bV,xH],91:FH,92:[sH,OV],93:CH,95:gV,96:BV},pU={null:[gV,eU]},mU={null:[42,95]},hU={null:[]};function gU(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},a=[],o=[],s=[],c={attempt:C(x),check:C(S),consume:v,enter:y,exit:b,interrupt:C(S,{interrupt:!0})},l={code:null,containerState:{},defineSkip:h,events:[],now:m,parser:e,previous:null,sliceSerialize:f,sliceStream:p,write:d},u=t.tokenize.call(l,c);return t.resolveAll&&a.push(t),l;function d(e){return o=UB(o,e),g(),o[o.length-1]===null?(w(t,0),l.events=hV(a,l.events,l),l.events):[]}function f(e,t){return vU(p(e),t)}function p(e){return _U(o,e)}function m(){let{_bufferIndex:e,_index:t,line:n,column:i,offset:a}=r;return{_bufferIndex:e,_index:t,line:n,column:i,offset:a}}function h(e){i[e.line]=e.column,E()}function g(){let e;for(;r._index<o.length;){let t=o[r._index];if(typeof t==`string`)for(e=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===e&&r._bufferIndex<t.length;)_(t.charCodeAt(r._bufferIndex));else _(t)}}function _(e){u=u(e)}function v(e){Z(e)?(r.line++,r.column=1,r.offset+=e===-3?2:1,E()):e!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),l.previous=e}function y(e,t){let n=t||{};return n.type=e,n.start=m(),l.events.push([`enter`,n,l]),s.push(n),n}function b(e){let t=s.pop();return t.end=m(),l.events.push([`exit`,t,l]),t}function x(e,t){w(e,t.from)}function S(e,t){t.restore()}function C(e,t){return n;function n(n,r,i){let a,o,s,u;return Array.isArray(n)?f(n):`tokenize`in n?f([n]):d(n);function d(e){return t;function t(t){let n=t!==null&&e[t],r=t!==null&&e.null;return f([...Array.isArray(n)?n:n?[n]:[],...Array.isArray(r)?r:r?[r]:[]])(t)}}function f(e){return a=e,o=0,e.length===0?i:p(e[o])}function p(e){return n;function n(n){return u=T(),s=e,e.partial||(l.currentConstruct=e),e.name&&l.parser.constructs.disable.null.includes(e.name)?h(n):e.tokenize.call(t?Object.assign(Object.create(l),t):l,c,m,h)(n)}}function m(t){return e(s,u),r}function h(e){return u.restore(),++o<a.length?p(a[o]):i}}}function w(e,t){e.resolveAll&&!a.includes(e)&&a.push(e),e.resolve&&HB(l.events,t,l.events.length-t,e.resolve(l.events.slice(t),l)),e.resolveTo&&(l.events=e.resolveTo(l.events,l))}function T(){let e=m(),t=l.previous,n=l.currentConstruct,i=l.events.length,a=Array.from(s);return{from:i,restore:o};function o(){r=e,l.previous=t,l.currentConstruct=n,l.events.length=i,s=a,E()}}function E(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function _U(e,t){let n=t.start._index,r=t.start._bufferIndex,i=t.end._index,a=t.end._bufferIndex,o;if(n===i)o=[e[n].slice(r,a)];else{if(o=e.slice(n,i),r>-1){let e=o[0];typeof e==`string`?o[0]=e.slice(r):o.shift()}a>0&&o.push(e[i].slice(0,a))}return o}function vU(e,t){let n=-1,r=[],i;for(;++n<e.length;){let a=e[n],o;if(typeof a==`string`)o=a;else switch(a){case-5:o=`\r`;break;case-4:o=`
34
34
  `;break;case-3:o=`\r
35
35
  `;break;case-2:o=t?` `:` `;break;case-1:if(!t&&i)continue;o=` `;break;default:o=String.fromCharCode(a)}i=a===-2,r.push(o)}return r.join(``)}function yU(e){let t={constructs:GB([oU,...(e||{}).extensions||[]]),content:n(cV),defined:[],document:n(uV),flow:n(QH),lazy:{},string:n(tU),text:n(nU)};return t;function n(e){return n;function n(n){return gU(t,e,n)}}}function bU(e){for(;!KV(e););return e}var xU=/[\0\t\n\r]/g;function SU(){let e=1,t=``,n=!0,r;return i;function i(i,a,o){let s=[],c,l,u,d,f;for(i=t+(typeof i==`string`?i.toString():new TextDecoder(a||void 0).decode(i)),u=0,t=``,n&&=(i.charCodeAt(0)===65279&&u++,void 0);u<i.length;){if(xU.lastIndex=u,c=xU.exec(i),d=c&&c.index!==void 0?c.index:i.length,f=i.charCodeAt(d),!c){t=i.slice(u);break}if(f===10&&u===d&&r)s.push(-3),r=void 0;else switch(r&&=(s.push(-5),void 0),u<d&&(s.push(i.slice(u,d)),e+=d-u),f){case 0:s.push(65533),e++;break;case 9:for(l=Math.ceil(e/4)*4,s.push(-2);e++<l;)s.push(-1);break;case 10:s.push(-4),e=1;break;default:r=!0,e=1}u=d+1}return o&&(r&&s.push(-5),t&&s.push(t),s.push(null)),s}}var CU=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function wU(e){return e.replace(CU,TU)}function TU(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){let e=n.charCodeAt(1),t=e===120||e===88;return JB(n.slice(t?2:1),t?16:10)}return VB(n)||e}var EU={}.hasOwnProperty;function DU(e,t,n){return t&&typeof t==`object`&&(n=t,t=void 0),OU(n)(bU(yU(n).document().write(SU()(e,t,!0))))}function OU(e){let t={transforms:[],canContainEols:[`emphasis`,`fragment`,`heading`,`paragraph`,`strong`],enter:{autolink:a(Ce),autolinkProtocol:T,autolinkEmail:T,atxHeading:a(ye),blockQuote:a(me),characterEscape:T,characterReference:T,codeFenced:a(he),codeFencedFenceInfo:o,codeFencedFenceMeta:o,codeIndented:a(he,o),codeText:a(ge,o),codeTextData:T,data:T,codeFlowValue:T,definition:a(_e),definitionDestinationString:o,definitionLabelString:o,definitionTitleString:o,emphasis:a(ve),hardBreakEscape:a(be),hardBreakTrailing:a(be),htmlFlow:a(xe,o),htmlFlowData:T,htmlText:a(xe,o),htmlTextData:T,image:a(Se),label:o,link:a(Ce),listItem:a(Te),listItemValue:f,listOrdered:a(we,d),listUnordered:a(we),paragraph:a(Ee),reference:ce,referenceString:o,resourceDestinationString:o,resourceTitleString:o,setextHeading:a(ye),strong:a(De),thematicBreak:a(ke)},exit:{atxHeading:c(),atxHeadingSequence:x,autolink:c(),autolinkEmail:pe,autolinkProtocol:fe,blockQuote:c(),characterEscapeValue:E,characterReferenceMarkerHexadecimal:ue,characterReferenceMarkerNumeric:ue,characterReferenceValue:de,characterReference:j,codeFenced:c(g),codeFencedFence:h,codeFencedFenceInfo:p,codeFencedFenceMeta:m,codeFlowValue:E,codeIndented:c(_),codeText:c(ne),codeTextData:E,data:E,definition:c(),definitionDestinationString:b,definitionLabelString:v,definitionTitleString:y,emphasis:c(),hardBreakEscape:c(D),hardBreakTrailing:c(D),htmlFlow:c(O),htmlFlowData:E,htmlText:c(te),htmlTextData:E,image:c(ie),label:oe,labelText:ae,lineEnding:ee,link:c(re),listItem:c(),listOrdered:c(),listUnordered:c(),paragraph:c(),referenceString:le,resourceDestinationString:k,resourceTitleString:A,resource:se,setextHeading:c(w),setextHeadingLineSequence:C,setextHeadingText:S,strong:c(),thematicBreak:c()}};AU(t,(e||{}).mdastExtensions||[]);let n={};return r;function r(e){let r={type:`root`,children:[]},a={stack:[r],tokenStack:[],config:t,enter:s,exit:l,buffer:o,resume:u,data:n},c=[],d=-1;for(;++d<e.length;)(e[d][1].type===`listOrdered`||e[d][1].type===`listUnordered`)&&(e[d][0]===`enter`?c.push(d):d=i(e,c.pop(),d));for(d=-1;++d<e.length;){let n=t[e[d][0]];EU.call(n,e[d][1].type)&&n[e[d][1].type].call(Object.assign({sliceSerialize:e[d][2].sliceSerialize},a),e[d][1])}if(a.tokenStack.length>0){let e=a.tokenStack[a.tokenStack.length-1];(e[1]||MU).call(a,void 0,e[0])}for(r.position={start:kU(e.length>0?e[0][1].start:{line:1,column:1,offset:0}),end:kU(e.length>0?e[e.length-2][1].end:{line:1,column:1,offset:0})},d=-1;++d<t.transforms.length;)r=t.transforms[d](r)||r;return r}function i(e,t,n){let r=t-1,i=-1,a=!1,o,s,c,l;for(;++r<=n;){let t=e[r];switch(t[1].type){case`listUnordered`:case`listOrdered`:case`blockQuote`:t[0]===`enter`?i++:i--,l=void 0;break;case`lineEndingBlank`:t[0]===`enter`&&(o&&!l&&!i&&!c&&(c=r),l=void 0);break;case`linePrefix`:case`listItemValue`:case`listItemMarker`:case`listItemPrefix`:case`listItemPrefixWhitespace`:break;default:l=void 0}if(!i&&t[0]===`enter`&&t[1].type===`listItemPrefix`||i===-1&&t[0]===`exit`&&(t[1].type===`listUnordered`||t[1].type===`listOrdered`)){if(o){let i=r;for(s=void 0;i--;){let t=e[i];if(t[1].type===`lineEnding`||t[1].type===`lineEndingBlank`){if(t[0]===`exit`)continue;s&&(e[s][1].type=`lineEndingBlank`,a=!0),t[1].type=`lineEnding`,s=i}else if(!(t[1].type===`linePrefix`||t[1].type===`blockQuotePrefix`||t[1].type===`blockQuotePrefixWhitespace`||t[1].type===`blockQuoteMarker`||t[1].type===`listItemIndent`))break}c&&(!s||c<s)&&(o._spread=!0),o.end=Object.assign({},s?e[s][1].start:t[1].end),e.splice(s||r,0,[`exit`,o,t[2]]),r++,n++}if(t[1].type===`listItemPrefix`){let i={type:`listItem`,_spread:!1,start:Object.assign({},t[1].start),end:void 0};o=i,e.splice(r,0,[`enter`,i,t[2]]),r++,n++,c=void 0,l=!0}}}return e[t][1]._spread=a,n}function a(e,t){return n;function n(n){s.call(this,e(n),n),t&&t.call(this,n)}}function o(){this.stack.push({type:`fragment`,children:[]})}function s(e,t,n){this.stack[this.stack.length-1].children.push(e),this.stack.push(e),this.tokenStack.push([t,n||void 0]),e.position={start:kU(t.start),end:void 0}}function c(e){return t;function t(t){e&&e.call(this,t),l.call(this,t)}}function l(e,t){let n=this.stack.pop(),r=this.tokenStack.pop();if(r)r[0].type!==e.type&&(t?t.call(this,e,r[0]):(r[1]||MU).call(this,e,r[0]));else throw Error("Cannot close `"+e.type+"` ("+tB({start:e.start,end:e.end})+`): it’s not open`);n.position.end=kU(e.end)}function u(){return IB(this.stack.pop())}function d(){this.data.expectingFirstListItemValue=!0}function f(e){if(this.data.expectingFirstListItemValue){let t=this.stack[this.stack.length-2];t.start=Number.parseInt(this.sliceSerialize(e),10),this.data.expectingFirstListItemValue=void 0}}function p(){let e=this.resume(),t=this.stack[this.stack.length-1];t.lang=e}function m(){let e=this.resume(),t=this.stack[this.stack.length-1];t.meta=e}function h(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function g(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,``),this.data.flowCodeInside=void 0}function _(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/(\r?\n|\r)$/g,``)}function v(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=YB(this.sliceSerialize(e)).toLowerCase()}function y(){let e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function b(){let e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function x(e){let t=this.stack[this.stack.length-1];t.depth||=this.sliceSerialize(e).length}function S(){this.data.setextHeadingSlurpLineEnding=!0}function C(e){let t=this.stack[this.stack.length-1];t.depth=this.sliceSerialize(e).codePointAt(0)===61?1:2}function w(){this.data.setextHeadingSlurpLineEnding=void 0}function T(e){let t=this.stack[this.stack.length-1].children,n=t[t.length-1];(!n||n.type!==`text`)&&(n=Oe(),n.position={start:kU(e.start),end:void 0},t.push(n)),this.stack.push(n)}function E(e){let t=this.stack.pop();t.value+=this.sliceSerialize(e),t.position.end=kU(e.end)}function ee(e){let n=this.stack[this.stack.length-1];if(this.data.atHardBreak){let t=n.children[n.children.length-1];t.position.end=kU(e.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(n.type)&&(T.call(this,e),E.call(this,e))}function D(){this.data.atHardBreak=!0}function O(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function te(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function ne(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function re(){let e=this.stack[this.stack.length-1];if(this.data.inReference){let t=this.data.referenceType||`shortcut`;e.type+=`Reference`,e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function ie(){let e=this.stack[this.stack.length-1];if(this.data.inReference){let t=this.data.referenceType||`shortcut`;e.type+=`Reference`,e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function ae(e){let t=this.sliceSerialize(e),n=this.stack[this.stack.length-2];n.label=wU(t),n.identifier=YB(t).toLowerCase()}function oe(){let e=this.stack[this.stack.length-1],t=this.resume(),n=this.stack[this.stack.length-1];this.data.inReference=!0,n.type===`link`?n.children=e.children:n.alt=t}function k(){let e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function A(){let e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function se(){this.data.inReference=void 0}function ce(){this.data.referenceType=`collapsed`}function le(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=YB(this.sliceSerialize(e)).toLowerCase(),this.data.referenceType=`full`}function ue(e){this.data.characterReferenceType=e.type}function de(e){let t=this.sliceSerialize(e),n=this.data.characterReferenceType,r;n?(r=JB(t,n===`characterReferenceMarkerNumeric`?10:16),this.data.characterReferenceType=void 0):r=VB(t);let i=this.stack[this.stack.length-1];i.value+=r}function j(e){let t=this.stack.pop();t.position.end=kU(e.end)}function fe(e){E.call(this,e);let t=this.stack[this.stack.length-1];t.url=this.sliceSerialize(e)}function pe(e){E.call(this,e);let t=this.stack[this.stack.length-1];t.url=`mailto:`+this.sliceSerialize(e)}function me(){return{type:`blockquote`,children:[]}}function he(){return{type:`code`,lang:null,meta:null,value:``}}function ge(){return{type:`inlineCode`,value:``}}function _e(){return{type:`definition`,identifier:``,label:null,title:null,url:``}}function ve(){return{type:`emphasis`,children:[]}}function ye(){return{type:`heading`,depth:0,children:[]}}function be(){return{type:`break`}}function xe(){return{type:`html`,value:``}}function Se(){return{type:`image`,title:null,url:``,alt:null}}function Ce(){return{type:`link`,title:null,url:``,children:[]}}function we(e){return{type:`list`,ordered:e.type===`listOrdered`,start:null,spread:e._spread,children:[]}}function Te(e){return{type:`listItem`,spread:e._spread,checked:null,children:[]}}function Ee(){return{type:`paragraph`,children:[]}}function De(){return{type:`strong`,children:[]}}function Oe(){return{type:`text`,value:``}}function ke(){return{type:`thematicBreak`}}}function kU(e){return{line:e.line,column:e.column,offset:e.offset}}function AU(e,t){let n=-1;for(;++n<t.length;){let r=t[n];Array.isArray(r)?AU(e,r):jU(e,r)}}function jU(e,t){let n;for(n in t)if(EU.call(t,n))switch(n){case`canContainEols`:{let r=t[n];r&&e[n].push(...r);break}case`transforms`:{let r=t[n];r&&e[n].push(...r);break}case`enter`:case`exit`:{let r=t[n];r&&Object.assign(e[n],r);break}}}function MU(e,t){throw Error(e?"Cannot close `"+e.type+"` ("+tB({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+tB({start:t.start,end:t.end})+`) is open`:"Cannot close document, a token (`"+t.type+"`, "+tB({start:t.start,end:t.end})+`) is still open`)}function NU(e){let t=this;t.parser=n;function n(n){return DU(n,{...t.data(`settings`),...e,extensions:t.data(`micromarkExtensions`)||[],mdastExtensions:t.data(`fromMarkdownExtensions`)||[]})}}function PU(e,t){let n={type:`element`,tagName:`blockquote`,properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function FU(e,t){let n={type:`element`,tagName:`br`,properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:`text`,value:`
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Tianshu — AI agent platform</title>
7
7
  <meta name="description" content="An open AI agent platform with a sidecar browser. Built in public." />
8
- <script type="module" crossorigin src="/assets/index-VQh0MZzC.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-CIgKhx_9.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-Bw_emLCe.css">
10
10
  </head>
11
11
  <body class="bg-slate-950 text-slate-100">