@timqi/pier 0.1.2 → 0.1.4
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/README.md +8 -3
- package/dist/agent/config.js +63 -59
- package/dist/agent/events.js +1 -2
- package/dist/agent/listing.js +38 -15
- package/dist/agent/packages.js +347 -0
- package/dist/agent/pi.js +33 -59
- package/dist/channels/config.js +30 -20
- package/dist/channels/routes.js +0 -3
- package/dist/channels/slack-api.js +19 -10
- package/dist/channels/slack-cli.js +503 -0
- package/dist/channels/slack-directory.js +2 -2
- package/dist/channels/slack-outbound.js +1 -1
- package/dist/channels/slack-thread.js +41 -0
- package/dist/channels/slack-transcript.js +107 -0
- package/dist/channels/slack.js +9 -17
- package/dist/channels/types.js +0 -1
- package/dist/cli.js +158 -7
- package/dist/core/identity.js +20 -11
- package/dist/core/reply.js +16 -15
- package/dist/core/router.js +4 -1
- package/dist/core/types.js +7 -0
- package/dist/db.js +28 -0
- package/dist/extensions/index.js +1 -20
- package/dist/main.js +34 -42
- package/dist/paths.js +3 -0
- package/dist/secrets.js +2 -1
- package/dist/settings.js +5 -0
- package/dist/socket.js +95 -0
- package/dist/tasks/agent.js +5 -6
- package/dist/tasks/callbacks.js +2 -2
- package/dist/tasks/cli.js +215 -0
- package/dist/tasks/definitions.js +3 -3
- package/dist/tasks/execution.js +1 -3
- package/dist/tasks/groups.js +2 -5
- package/dist/tasks/messages.js +18 -158
- package/dist/tasks/operations.js +323 -0
- package/dist/tasks/routes.js +1 -11
- package/dist/tasks/runs.js +5 -20
- package/dist/tasks/service.js +18 -43
- package/dist/tasks/store.js +15 -15
- package/dist/tools.js +63 -85
- package/dist/vault.js +107 -0
- package/dist/web/auth.js +2 -1
- package/dist/web/config.js +25 -11
- package/dist/web/explorer.js +5 -3
- package/dist/web/instance.js +6 -18
- package/dist/web/packages.js +84 -0
- package/dist/web/public/assets/{activity-DOr8dWeX.js → activity-NLS8W9yl.js} +2 -2
- package/dist/web/public/assets/activity-NLS8W9yl.js.br +0 -0
- package/dist/web/public/assets/activity-NLS8W9yl.js.gz +0 -0
- package/dist/web/public/assets/boards-DleegoiC.js +1 -0
- package/dist/web/public/assets/boards-DleegoiC.js.br +0 -0
- package/dist/web/public/assets/boards-DleegoiC.js.gz +0 -0
- package/dist/web/public/assets/explorer-vJvV1Sx0.js +4 -0
- package/dist/web/public/assets/explorer-vJvV1Sx0.js.br +0 -0
- package/dist/web/public/assets/explorer-vJvV1Sx0.js.gz +0 -0
- package/dist/web/public/assets/index-Bs-gol9o.css +2 -0
- package/dist/web/public/assets/index-Bs-gol9o.css.br +0 -0
- package/dist/web/public/assets/index-Bs-gol9o.css.gz +0 -0
- package/dist/web/public/assets/index-Cyp2DKKF.js +85 -0
- package/dist/web/public/assets/index-Cyp2DKKF.js.br +0 -0
- package/dist/web/public/assets/index-Cyp2DKKF.js.gz +0 -0
- package/dist/web/public/assets/runs-C5FveZ75.js +1 -0
- package/dist/web/public/assets/runs-C5FveZ75.js.br +0 -0
- package/dist/web/public/assets/runs-C5FveZ75.js.gz +0 -0
- package/dist/web/public/assets/settings-nJHIBbAz.js +5 -0
- package/dist/web/public/assets/settings-nJHIBbAz.js.br +0 -0
- package/dist/web/public/assets/settings-nJHIBbAz.js.gz +0 -0
- package/dist/web/public/assets/task-runs-CJJ2j5Ks.js +3 -0
- package/dist/web/public/assets/task-runs-CJJ2j5Ks.js.br +0 -0
- package/dist/web/public/assets/task-runs-CJJ2j5Ks.js.gz +0 -0
- package/dist/web/public/assets/tasks-R2Pv0Abg.js +4 -0
- package/dist/web/public/assets/tasks-R2Pv0Abg.js.br +0 -0
- package/dist/web/public/assets/tasks-R2Pv0Abg.js.gz +0 -0
- package/dist/web/public/index.html +2 -2
- package/dist/web/public/index.html.br +0 -0
- package/dist/web/public/index.html.gz +0 -0
- package/dist/web/server.js +3 -1
- package/dist/web/vault.js +68 -0
- package/docs/deploy.md +42 -8
- package/package.json +1 -1
- package/skills/pier-help/SKILL.md +10 -6
- package/skills/pier-slack/SKILL.md +52 -71
- package/skills/pier-tasks/SKILL.md +48 -145
- package/skills/pier-vault/SKILL.md +36 -0
- package/dist/channels/slack-tool.js +0 -416
- package/dist/tasks/tool.js +0 -416
- package/dist/web/public/assets/activity-DOr8dWeX.js.br +0 -0
- package/dist/web/public/assets/activity-DOr8dWeX.js.gz +0 -0
- package/dist/web/public/assets/boards-CneyR23E.js +0 -1
- package/dist/web/public/assets/boards-CneyR23E.js.br +0 -0
- package/dist/web/public/assets/boards-CneyR23E.js.gz +0 -0
- package/dist/web/public/assets/explorer-D0srXT1c.js +0 -4
- package/dist/web/public/assets/explorer-D0srXT1c.js.br +0 -0
- package/dist/web/public/assets/explorer-D0srXT1c.js.gz +0 -0
- package/dist/web/public/assets/index-DbFu15NN.js +0 -85
- package/dist/web/public/assets/index-DbFu15NN.js.br +0 -0
- package/dist/web/public/assets/index-DbFu15NN.js.gz +0 -0
- package/dist/web/public/assets/index-eqQLVS8Q.css +0 -2
- package/dist/web/public/assets/index-eqQLVS8Q.css.br +0 -0
- package/dist/web/public/assets/index-eqQLVS8Q.css.gz +0 -0
- package/dist/web/public/assets/runs-Cv0A-e08.js +0 -1
- package/dist/web/public/assets/runs-Cv0A-e08.js.br +0 -0
- package/dist/web/public/assets/runs-Cv0A-e08.js.gz +0 -0
- package/dist/web/public/assets/settings-VmCjhGBd.js +0 -5
- package/dist/web/public/assets/settings-VmCjhGBd.js.br +0 -0
- package/dist/web/public/assets/settings-VmCjhGBd.js.gz +0 -0
- package/dist/web/public/assets/task-runs-CqpTV644.js +0 -3
- package/dist/web/public/assets/task-runs-CqpTV644.js.br +0 -0
- package/dist/web/public/assets/task-runs-CqpTV644.js.gz +0 -0
- package/dist/web/public/assets/tasks-BffPVgXg.js +0 -4
- package/dist/web/public/assets/tasks-BffPVgXg.js.br +0 -0
- package/dist/web/public/assets/tasks-BffPVgXg.js.gz +0 -0
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/tasks-BffPVgXg.js","assets/task-runs-CqpTV644.js","assets/runs-Cv0A-e08.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":2,"stroke-linecap":`round`,"stroke-linejoin":`round`},t=([e,n,r])=>{let i=document.createElementNS(`http://www.w3.org/2000/svg`,e);return Object.keys(n).forEach(e=>{i.setAttribute(e,String(n[e]))}),r?.length&&r.forEach(e=>{let n=t(e);i.appendChild(n)}),i},n=(n,r={})=>t([`svg`,{...e,...r},n]),r=[[`path`,{d:`m12 19-7-7 7-7`}],[`path`,{d:`M19 12H5`}]],i=[[`path`,{d:`M7 7h10v10`}],[`path`,{d:`M7 17 17 7`}]],a=[[`path`,{d:`m5 12 7-7 7 7`}],[`path`,{d:`M12 19V5`}]],o=[[`path`,{d:`M20 6 9 17l-5-5`}]],s=[[`path`,{d:`m6 9 6 6 6-6`}]],c=[[`path`,{d:`m15 18-6-6 6-6`}]],l=[[`path`,{d:`m9 18 6-6-6-6`}]],u=[[`circle`,{cx:`12`,cy:`12`,r:`10`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`}],[`path`,{d:`M12 17h.01`}]],d=[[`circle`,{cx:`12`,cy:`12`,r:`10`}],[`path`,{d:`M12 6v6l4 2`}]],ee=[[`path`,{d:`M20 4v7a4 4 0 0 1-4 4H4`}],[`path`,{d:`m9 10-5 5 5 5`}]],f=[[`path`,{d:`M12 15V3`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}],[`path`,{d:`m7 10 5 5 5-5`}]],p=[[`circle`,{cx:`12`,cy:`12`,r:`1`}],[`circle`,{cx:`19`,cy:`12`,r:`1`}],[`circle`,{cx:`5`,cy:`12`,r:`1`}]],te=[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`}]],ne=[[`path`,{d:`M12 10v6`}],[`path`,{d:`M9 13h6`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`}]],re=[[`rect`,{width:`7`,height:`9`,x:`3`,y:`3`,rx:`1`}],[`rect`,{width:`7`,height:`5`,x:`14`,y:`3`,rx:`1`}],[`rect`,{width:`7`,height:`9`,x:`14`,y:`12`,rx:`1`}],[`rect`,{width:`7`,height:`5`,x:`3`,y:`16`,rx:`1`}]],ie=[[`path`,{d:`M13 5h8`}],[`path`,{d:`M13 12h8`}],[`path`,{d:`M13 19h8`}],[`path`,{d:`m3 17 2 2 4-4`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`}]],m=[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`}]],ae=[[`path`,{d:`M4 5h16`}],[`path`,{d:`M4 12h16`}],[`path`,{d:`M4 19h16`}]],oe=[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`}]],se=[[`path`,{d:`M5 12h14`}]],ce=[[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`}],[`line`,{x1:`8`,x2:`16`,y1:`21`,y2:`21`}],[`line`,{x1:`12`,x2:`12`,y1:`17`,y2:`21`}]],h=[[`path`,{d:`M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401`}]],le=[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`}]],ue=[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`}],[`path`,{d:`m15 5 4 4`}]],de=[[`path`,{d:`M5 12h14`}],[`path`,{d:`M12 5v14`}]],fe=[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`}],[`path`,{d:`M21 3v5h-5`}]],pe=[[`path`,{d:`m21 21-4.34-4.34`}],[`circle`,{cx:`11`,cy:`11`,r:`8`}]],me=[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`}],[`circle`,{cx:`12`,cy:`12`,r:`3`}]],he=[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}]],ge=[[`circle`,{cx:`12`,cy:`12`,r:`4`}],[`path`,{d:`M12 2v2`}],[`path`,{d:`M12 20v2`}],[`path`,{d:`m4.93 4.93 1.41 1.41`}],[`path`,{d:`m17.66 17.66 1.41 1.41`}],[`path`,{d:`M2 12h2`}],[`path`,{d:`M20 12h2`}],[`path`,{d:`m6.34 17.66-1.41 1.41`}],[`path`,{d:`m19.07 4.93-1.41 1.41`}]],_e=[[`path`,{d:`M9 14 4 9l5-5`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`}]],ve=[[`path`,{d:`M18 6 6 18`}],[`path`,{d:`m6 6 12 12`}]],g=(e,t=`h-3.5 w-3.5`)=>n(e,{class:`flex-none ${t}`,"aria-hidden":`true`,focusable:`false`});function ye(){let e={ArrowUp:a,ChevronLeft:c,ChevronRight:l,Clock:d,Ellipsis:p,LayoutDashboard:re,ListTodo:ie,Menu:ae,Plus:de,RotateCw:fe,Search:pe,Settings:me,Square:he,Undo2:_e,X:ve};for(let t of document.querySelectorAll(`[data-icon]`)){let n=e[t.dataset.icon];if(!n)throw Error(`Unknown shell icon: ${t.dataset.icon}`);t.replaceChildren(g(n,`h-full w-full`))}let t=g(s);t.setAttribute(`stroke`,`#737373`),document.documentElement.style.setProperty(`--select-chevron`,`url("data:image/svg+xml,${encodeURIComponent(t.outerHTML)}")`)}var be=/[\u201c\u201d"\u2018\u2019'()\uff08\uff09\u300c\u300d\u300e\u300f\u3010\u3011\u300a\u300b\u3008\u3009[\]]/;function xe(e){let t=[],n=e=>`\uE010${t.push(e)-1}\uE011`,r=e.replace(/```[\s\S]*?```/g,e=>n(e)).replace(/`[^`\n]+`/g,e=>n(e));return r=r.replace(/\*\*(\S|\S[\s\S]*?\S)\*\*/g,(e,t)=>{let n=``,r=``,i=t;for(;i.length>1&&be.test(i[0]);)n+=i[0],i=i.slice(1);for(;i.length>1&&be.test(i.at(-1));)r=i.at(-1)+r,i=i.slice(0,-1);return n||r?`${n}**${i}**${r}`:e}),r.replace(/\uE010(\d+)\uE011/g,(e,n)=>t[Number(n)]??``)}var _=e=>!e.text.trim()&&e.suggestions.length===0,Se=e=>e===`xhigh`?`Extra high`:e[0].toUpperCase()+e.slice(1),Ce=e=>{if(e<1e3)return String(e);let t=e/1e3;return t>=9.95?`${Math.round(t)}K`:`${t.toFixed(1)}K`},we=/(?:^|\n)[ \t]*-{3,}[ \t]*\r?\n((?:[ \t]*\[[^\]\r\n]+\][ \t]*(?:[||][ \t]*)?)+)\s*$/,Te=/\[([^\]\r\n]+)\]/g,Ee=5,De=/<silent>([\s\S]*?)<\/silent>/gi;function Oe(e){let t=[...e.matchAll(De)].map(e=>(e[1]??``).trim()).filter(Boolean);return t.length?t.join(` · `):void 0}function ke(e,t){let n=Ae(e),r=Oe(e),i=we.exec(n);if(!i?.[1])return{text:n,suggestions:[],meta:t,silence:r};let a=[...i[1].matchAll(Te)].map(e=>(e[1]??``).trim()).filter(Boolean).slice(0,Ee);return a.length?{text:n.slice(0,i.index).trimEnd(),suggestions:a,meta:t,silence:r}:{text:n,suggestions:[],meta:t,silence:r}}var Ae=e=>xe(e.replace(De,``).trim()),v=/^(?:\s|[-*+>]|\d+[.)])/;function je(e,t=0){let n=e.lastIndexOf(`
|
|
3
|
-
`)+1,r=``,i=!1,a=t,o=-1,s=``;for(let c=t;c<n;){let t=e.indexOf(`
|
|
4
|
-
`,c),n=e.slice(c,t);c=t+1;let l=/^\s*(`{3,}|~{3,})(.*)$/.exec(n);if(!r&&!i&&!n.trim()){o<0&&s&&(o=c);continue}!r&&!i&&o>=0&&!(v.test(s)&&v.test(n))&&(a=o);let u=l?.[1]??``;if(!r&&u&&!i?r=u:r&&u[0]===r[0]&&u.length>=r.length&&!l?.[2]?.trim()&&(r=``),!r&&(!u||i))for(let e of n.matchAll(/<(\/?)silent>/gi))i=!e[1];o=-1,s=n}return a}var y=/^\[(?:([^\n[\]<>]*)<([^\n[\]<>]+)>)? ?((?:\d{4}-\d{2}-\d{2} )?\d{1,2}:\d{2})?\]\n/;function Me(e){let t=y.exec(e);return!t?.[2]&&!t?.[3]?{text:e}:{...t[1]?{name:t[1]}:{},...t[2]?{id:t[2]}:{},...t[3]?{when:t[3]}:{},text:e.slice(t[0].length)}}var Ne=/(?:\n\[[^\]\n]*(?:\]\(\s*<?file:\/\/[^\n]*|$))+$/,Pe=/^\s*`[^`\n]{40,}`\s+(\S[\s\S]*)$/;function Fe(e){if(!e)return e;let{text:t}=Me(e);return t===e?e:t.replace(Ne,``).replace(Pe,`$1`).replace(/\s+/g,` `).trim()||e}function Ie(e){let t,n=!1;return()=>(n=!0,t??=(async()=>{for(;n;)n=!1,await e()})().finally(()=>{t=void 0}))}var b=(e,t,n=`POST`)=>fetch(e,{method:n,headers:{"content-type":`application/json`},body:JSON.stringify(t)});async function x(e,t){return(await e.json().catch(()=>({}))).error??`${t} (${e.status})`}async function Le(e,t,n){let r;try{r=await fetch(e,n)}catch(e){return{ok:!1,error:`${t}: ${String(e)}`}}if(!r.ok)return{ok:!1,error:await x(r,t)};try{return{ok:!0,value:await r.json()}}catch(e){return{ok:!1,error:`${t}: ${String(e)}`}}}async function Re(e,t,n){let r=await Le(e,t,n);if(!r.ok)throw Error(r.error);return r.value}async function ze(e,t,n){try{let r=await fetch(e,{method:t});return r.ok?void 0:await x(r,n)}catch(e){return`${n}: ${String(e)}`}}function Be(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Ve(e){if(Array.isArray(e))return e}function He(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function Ue(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
5
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function We(e,t){return Ve(e)||He(e,t)||Ge(e,t)||Ue()}function Ge(e,t){if(e){if(typeof e==`string`)return Be(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Be(e,t):void 0}}var Ke=Object.entries,qe=Object.setPrototypeOf,Je=Object.isFrozen,Ye=Object.getPrototypeOf,Xe=Object.getOwnPropertyDescriptor,S=Object.freeze,C=Object.seal,Ze=Object.create,Qe=typeof Reflect<`u`&&Reflect,$e=Qe.apply,et=Qe.construct;S||=function(e){return e},C||=function(e){return e},$e||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},et||=function(e){return new e(...[...arguments].slice(1))};var tt=E(Array.prototype.forEach),nt=E(Array.prototype.lastIndexOf),rt=E(Array.prototype.pop),it=E(Array.prototype.push),at=E(Array.prototype.splice),ot=Array.isArray,st=E(String.prototype.toLowerCase),ct=E(String.prototype.toString),lt=E(String.prototype.match),ut=E(String.prototype.replace),dt=E(String.prototype.indexOf),ft=E(String.prototype.trim),pt=E(Number.prototype.toString),mt=E(Boolean.prototype.toString),ht=typeof BigInt>`u`?null:E(BigInt.prototype.toString),gt=typeof Symbol>`u`?null:E(Symbol.prototype.toString),w=E(Object.prototype.hasOwnProperty),_t=E(Object.prototype.toString),T=E(RegExp.prototype.test),vt=yt(TypeError);function E(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return $e(e,t,n)}}function yt(e){return function(){return et(e,[...arguments])}}function D(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:st;if(qe&&qe(e,null),!ot(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(Je(t)||(t[r]=e),i=e)}e[i]=!0}return e}function bt(e){for(let t=0;t<e.length;t++)w(e,t)||(e[t]=null);return e}function O(e){let t=Ze(null);for(let r of Ke(e)){var n=We(r,2);let i=n[0],a=n[1];w(e,i)&&(t[i]=ot(a)?bt(a):a&&typeof a==`object`&&a.constructor===Object?O(a):a)}return t}function xt(e){switch(typeof e){case`string`:return e;case`number`:return pt(e);case`boolean`:return mt(e);case`bigint`:return ht?ht(e):`0`;case`symbol`:return gt?gt(e):`Symbol()`;case`undefined`:return _t(e);case`function`:case`object`:{if(e===null)return _t(e);let t=e,n=St(t,`toString`);if(typeof n==`function`){let e=n(t);return typeof e==`string`?e:_t(e)}return _t(e)}default:return _t(e)}}function St(e,t){for(;e!==null;){let n=Xe(e,t);if(n){if(n.get)return E(n.get);if(typeof n.value==`function`)return E(n.value)}e=Ye(e)}function n(){return null}return n}function Ct(e){try{return T(e,``),!0}catch{return!1}}var wt=S(`a.abbr.acronym.address.area.article.aside.audio.b.bdi.bdo.big.blink.blockquote.body.br.button.canvas.caption.center.cite.code.col.colgroup.content.data.datalist.dd.decorator.del.details.dfn.dialog.dir.div.dl.dt.element.em.fieldset.figcaption.figure.font.footer.form.h1.h2.h3.h4.h5.h6.head.header.hgroup.hr.html.i.img.input.ins.kbd.label.legend.li.main.map.mark.marquee.menu.menuitem.meter.nav.nobr.ol.optgroup.option.output.p.picture.pre.progress.q.rp.rt.ruby.s.samp.search.section.select.shadow.slot.small.source.spacer.span.strike.strong.style.sub.summary.sup.table.tbody.td.template.textarea.tfoot.th.thead.time.tr.track.tt.u.ul.var.video.wbr`.split(`.`)),Tt=S(`svg.a.altglyph.altglyphdef.altglyphitem.animatecolor.animatemotion.animatetransform.circle.clippath.defs.desc.ellipse.enterkeyhint.exportparts.filter.font.g.glyph.glyphref.hkern.image.inputmode.line.lineargradient.marker.mask.metadata.mpath.part.path.pattern.polygon.polyline.radialgradient.rect.stop.style.switch.symbol.text.textpath.title.tref.tspan.view.vkern`.split(`.`)),Et=S([`feBlend`,`feColorMatrix`,`feComponentTransfer`,`feComposite`,`feConvolveMatrix`,`feDiffuseLighting`,`feDisplacementMap`,`feDistantLight`,`feDropShadow`,`feFlood`,`feFuncA`,`feFuncB`,`feFuncG`,`feFuncR`,`feGaussianBlur`,`feImage`,`feMerge`,`feMergeNode`,`feMorphology`,`feOffset`,`fePointLight`,`feSpecularLighting`,`feSpotLight`,`feTile`,`feTurbulence`]),Dt=S([`animate`,`color-profile`,`cursor`,`discard`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`foreignobject`,`hatch`,`hatchpath`,`mesh`,`meshgradient`,`meshpatch`,`meshrow`,`missing-glyph`,`script`,`set`,`solidcolor`,`unknown`,`use`]),Ot=S(`math.menclose.merror.mfenced.mfrac.mglyph.mi.mlabeledtr.mmultiscripts.mn.mo.mover.mpadded.mphantom.mroot.mrow.ms.mspace.msqrt.mstyle.msub.msup.msubsup.mtable.mtd.mtext.mtr.munder.munderover.mprescripts`.split(`.`)),kt=S([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),At=S([`#text`]),jt=S(`accept.action.align.alt.autocapitalize.autocomplete.autopictureinpicture.autoplay.background.bgcolor.border.capture.cellpadding.cellspacing.checked.cite.class.clear.color.cols.colspan.command.commandfor.controls.controlslist.coords.crossorigin.datetime.decoding.default.dir.disabled.disablepictureinpicture.disableremoteplayback.download.draggable.enctype.enterkeyhint.exportparts.face.for.headers.height.hidden.high.href.hreflang.id.inert.inputmode.integrity.ismap.kind.label.lang.list.loading.loop.low.max.maxlength.media.method.min.minlength.multiple.muted.name.nonce.noshade.novalidate.nowrap.open.optimum.part.pattern.placeholder.playsinline.popover.popovertarget.popovertargetaction.poster.preload.pubdate.radiogroup.readonly.rel.required.rev.reversed.role.rows.rowspan.spellcheck.scope.selected.shape.size.sizes.slot.span.srclang.start.src.srcset.step.style.summary.tabindex.title.translate.type.usemap.valign.value.width.wrap.xmlns`.split(`.`)),Mt=S(`accent-height.accumulate.additive.alignment-baseline.amplitude.ascent.attributename.attributetype.azimuth.basefrequency.baseline-shift.begin.bias.by.class.clip.clippathunits.clip-path.clip-rule.color.color-interpolation.color-interpolation-filters.color-profile.color-rendering.cx.cy.d.dx.dy.diffuseconstant.direction.display.divisor.dominant-baseline.dur.edgemode.elevation.end.exponent.fill.fill-opacity.fill-rule.filter.filterunits.flood-color.flood-opacity.font-family.font-size.font-size-adjust.font-stretch.font-style.font-variant.font-weight.fx.fy.g1.g2.glyph-name.glyphref.gradientunits.gradienttransform.height.href.id.image-rendering.in.in2.intercept.k.k1.k2.k3.k4.kerning.keypoints.keysplines.keytimes.lang.lengthadjust.letter-spacing.kernelmatrix.kernelunitlength.lighting-color.local.marker-end.marker-mid.marker-start.markerheight.markerunits.markerwidth.maskcontentunits.maskunits.max.mask.mask-type.media.method.mode.min.name.numoctaves.offset.operator.opacity.order.orient.orientation.origin.overflow.paint-order.path.pathlength.patterncontentunits.patterntransform.patternunits.pointer-events.points.preservealpha.preserveaspectratio.primitiveunits.r.rx.ry.radius.refx.refy.repeatcount.repeatdur.restart.result.rotate.scale.seed.shape-rendering.slope.specularconstant.specularexponent.spreadmethod.startoffset.stddeviation.stitchtiles.stop-color.stop-opacity.stroke-dasharray.stroke-dashoffset.stroke-linecap.stroke-linejoin.stroke-miterlimit.stroke-opacity.stroke.stroke-width.style.surfacescale.systemlanguage.tabindex.tablevalues.targetx.targety.transform.transform-origin.text-anchor.text-decoration.text-orientation.text-rendering.textlength.type.u1.u2.unicode.values.vector-effect.viewbox.visibility.version.vert-adv-y.vert-origin-x.vert-origin-y.width.word-spacing.wrap.writing-mode.xchannelselector.ychannelselector.x.x1.x2.xmlns.y.y1.y2.z.zoomandpan`.split(`.`)),Nt=S(`accent.accentunder.align.bevelled.close.columnalign.columnlines.columnspacing.columnspan.denomalign.depth.dir.display.displaystyle.encoding.fence.frame.height.href.id.largeop.length.linethickness.lquote.lspace.mathbackground.mathcolor.mathsize.mathvariant.maxsize.minsize.movablelimits.notation.numalign.open.rowalign.rowlines.rowspacing.rowspan.rspace.rquote.scriptlevel.scriptminsize.scriptsizemultiplier.selection.separator.separators.stretchy.subscriptshift.supscriptshift.symmetric.voffset.width.xmlns`.split(`.`)),Pt=S([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),Ft=C(/{{[\w\W]*|^[\w\W]*}}/g),It=C(/<%[\w\W]*|^[\w\W]*%>/g),Lt=C(/\${[\w\W]*/g),Rt=C(/^data-[\-\w.\u00B7-\uFFFF]+$/),zt=C(/^aria-[\-\w]+$/),Bt=C(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Vt=C(/^(?:\w+script|data):/i),Ht=C(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Ut=C(/^html$/i),Wt=C(/^[a-z][.\w]*(-[.\w]+)+$/i),Gt=C(/<[/\w!]/g),Kt=C(/<[/\w]/g),qt=C(/<\/no(script|embed|frames)/i),Jt=C(/\/>/i),k={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},Yt=[`style`,`script`,`xmp`,`iframe`,`noembed`,`noframes`,`plaintext`,`noscript`],Xt=S(D({},Yt)),Zt=function(){let e={};return tt(Yt,t=>{e[t]=C(RegExp(`</`+t+`(?=[\\t\\n\\f\\r />])`,`i`))}),S(e)}(),Qt=function(){return typeof window>`u`?null:window},$t=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},en=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},tn=function(e,t,n,r){return w(e,t)&&ot(e[t])?D(r.base?O(r.base):{},e[t],r.transform):n},nn=function(e,t,n){let r=w(e,t)?e[t]:void 0;return r&&typeof r==`object`?O(r):n()};function rn(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Qt(),t=e=>rn(e);if(t.version=`3.4.14`,t.removed=[],!e||!e.document||e.document.nodeType!==k.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,ee=St(d,`cloneNode`),f=St(d,`remove`),p=St(d,`nextSibling`),te=St(d,`childNodes`),ne=St(d,`parentNode`),re=St(d,`shadowRoot`),ie=St(d,`attributes`),m=o&&o.prototype?St(o.prototype,`nodeType`):null,ae=o&&o.prototype?St(o.prototype,`nodeName`):null,oe=o&&o.prototype?St(o.prototype,`ownerDocument`):null,se=function(e){return m?m(e):e.nodeType},ce=function(e){return ae?ae(e):e.nodeName};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let h,le=``,ue,de=!1,fe=0,pe=function(){if(fe>0)throw vt(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},me=function(e){pe(),fe++;try{return h.createHTML(e)}finally{fe--}},he=function(e){pe(),fe++;try{return h.createScriptURL(e)}finally{fe--}},ge=function(){return de||=(ue=$t(u,i),!0),ue},_e=n,ve=_e.implementation,g=_e.createNodeIterator,ye=_e.createDocumentFragment,be=_e.getElementsByTagName,xe=r.importNode,_=en();t.isSupported=typeof Ke==`function`&&typeof ne==`function`&&ve&&ve.createHTMLDocument!==void 0;let Se=Ft,Ce=It,we=Lt,Te=Rt,Ee=zt,De=Vt,Oe=Ht,ke=Wt,Ae=Bt,v=null,je=D({},[...wt,...Tt,...Et,...Ot,...At]),y=null,Me=D({},[...jt,...Mt,...Nt,...Pt]),Ne=Object.seal(Ze(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),Pe=null,Fe=null,Ie=Object.seal(Ze(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),b=!0,x=!0,Le=!1,Re=!0,ze=!1,Be=!0,Ve=!1,He=!1,Ue=null,We=null,Ge=!1,qe=!1,Je=!1,Ye=!1,Xe=!0,Qe=!1,$e=`user-content-`,et=!0,pt=!1,mt={},ht=null,gt=D({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),_t=null,E=D({},[`audio`,`video`,`img`,`source`,`image`,`track`]),yt=null,bt=D({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Yt=`http://www.w3.org/1998/Math/MathML`,an=`http://www.w3.org/2000/svg`,A=`http://www.w3.org/1999/xhtml`,on=A,sn=!1,cn=null,ln=D({},[Yt,an,A],ct),j=S([`mi`,`mo`,`mn`,`ms`,`mtext`]),un=D({},j),M=S([`annotation-xml`]),dn=D({},M),fn=D({},[`title`,`style`,`font`,`a`,`script`]),pn=null,mn=[`application/xhtml+xml`,`text/html`],N=null,hn=null,gn=n.createElement(`form`),_n=function(e){return e instanceof RegExp||e instanceof Function},vn=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(hn&&hn===e)return;(!e||typeof e!=`object`)&&(e={}),e=O(e),pn=mn.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,N=pn===`application/xhtml+xml`?ct:st,v=tn(e,`ALLOWED_TAGS`,je,{transform:N}),y=tn(e,`ALLOWED_ATTR`,Me,{transform:N}),cn=tn(e,`ALLOWED_NAMESPACES`,ln,{transform:ct}),yt=tn(e,`ADD_URI_SAFE_ATTR`,bt,{transform:N,base:bt}),_t=tn(e,`ADD_DATA_URI_TAGS`,E,{transform:N,base:E}),ht=tn(e,`FORBID_CONTENTS`,gt,{transform:N}),Pe=tn(e,`FORBID_TAGS`,O({}),{transform:N}),Fe=tn(e,`FORBID_ATTR`,O({}),{transform:N}),mt=w(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?O(e.USE_PROFILES):e.USE_PROFILES:!1,b=e.ALLOW_ARIA_ATTR!==!1,x=e.ALLOW_DATA_ATTR!==!1,Le=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Re=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,ze=e.SAFE_FOR_TEMPLATES||!1,Be=e.SAFE_FOR_XML!==!1,Ve=e.WHOLE_DOCUMENT||!1,qe=e.RETURN_DOM||!1,Je=e.RETURN_DOM_FRAGMENT||!1,Ye=e.RETURN_TRUSTED_TYPE||!1,Ge=e.FORCE_BODY||!1,Xe=e.SANITIZE_DOM!==!1,Qe=e.SANITIZE_NAMED_PROPS||!1,et=e.KEEP_CONTENT!==!1,pt=e.IN_PLACE||!1,Ae=Ct(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:Bt,on=typeof e.NAMESPACE==`string`?e.NAMESPACE:A,un=nn(e,`MATHML_TEXT_INTEGRATION_POINTS`,()=>D({},j)),dn=nn(e,`HTML_INTEGRATION_POINTS`,()=>D({},M));let t=nn(e,`CUSTOM_ELEMENT_HANDLING`,()=>Ze(null));if(Ne=Ze(null),w(t,`tagNameCheck`)&&_n(t.tagNameCheck)&&(Ne.tagNameCheck=t.tagNameCheck),w(t,`attributeNameCheck`)&&_n(t.attributeNameCheck)&&(Ne.attributeNameCheck=t.attributeNameCheck),w(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(Ne.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),C(Ne),ze&&(x=!1),Je&&(qe=!0),mt&&(v=D({},At),y=Ze(null),mt.html===!0&&(D(v,wt),D(y,jt)),mt.svg===!0&&(D(v,Tt),D(y,Mt),D(y,Pt)),mt.svgFilters===!0&&(D(v,Et),D(y,Mt),D(y,Pt)),mt.mathMl===!0&&(D(v,Ot),D(y,Nt),D(y,Pt))),Ie.tagCheck=null,Ie.attributeCheck=null,w(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?Ie.tagCheck=e.ADD_TAGS:ot(e.ADD_TAGS)&&(v===je&&(v=O(v)),D(v,e.ADD_TAGS,N))),w(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?Ie.attributeCheck=e.ADD_ATTR:ot(e.ADD_ATTR)&&(y===Me&&(y=O(y)),D(y,e.ADD_ATTR,N))),w(e,`ADD_FORBID_CONTENTS`)&&ot(e.ADD_FORBID_CONTENTS)&&(ht===gt&&(ht=O(ht)),D(ht,e.ADD_FORBID_CONTENTS,N)),et&&(v[`#text`]=!0),Ve&&D(v,[`html`,`head`,`body`]),v.table&&(D(v,[`tbody`]),delete Pe.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw vt(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw vt(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=h;h=e.TRUSTED_TYPES_POLICY;try{le=me(``)}catch(e){throw h=t,e}}else e.TRUSTED_TYPES_POLICY===null?(h=void 0,le=``):(h===void 0&&(h=ge()),h&&typeof le==`string`&&(le=me(``)));S&&S(e),hn=e},yn=D({},[...Tt,...Et,...Dt]),bn=D({},[...Ot,...kt]),xn=function(e,t,n){return t.namespaceURI===A?e===`svg`:t.namespaceURI===Yt?e===`svg`&&(n===`annotation-xml`||un[n]):!!yn[e]},Sn=function(e,t,n){return t.namespaceURI===A?e===`math`:t.namespaceURI===an?e===`math`&&dn[n]:!!bn[e]},Cn=function(e,t,n){return t.namespaceURI===an&&!dn[n]||t.namespaceURI===Yt&&!un[n]?!1:!bn[e]&&(fn[e]||!yn[e])},wn=function(e){let t=ne(e);(!t||!t.tagName)&&(t={namespaceURI:on,tagName:`template`});let n=st(e.tagName),r=st(t.tagName);return cn[e.namespaceURI]?e.namespaceURI===an?xn(n,t,r):e.namespaceURI===Yt?Sn(n,t,r):e.namespaceURI===A?Cn(n,t,r):!!(pn===`application/xhtml+xml`&&cn[e.namespaceURI]):!1},Tn=function(e){it(t.removed,{element:e});try{ne(e).removeChild(e)}catch{if(f(e),!ne(e))throw vt(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},En=function(e,t,n){try{e.removeAttributeNode(t)}catch{try{e.removeAttribute(n)}catch{}}},Dn=function(e){An(e);let t=te(e);if(t){let e=[];tt(t,t=>{it(e,t)}),tt(e,e=>{try{f(e)}catch{}})}let n=ie(e);if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;typeof i==`string`&&En(e,r,i)}},On=function(e,n,r){if(!r)try{r=n.getAttributeNode(e)}catch{r=null}it(t.removed,{attribute:r||null,from:n});try{r?n.removeAttributeNode(r):n.removeAttribute(e)}catch{try{n.removeAttribute(e)}catch{}}if(e===`is`){if(qe||Je)try{Tn(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},kn=function(e){let t=ie(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;typeof i!=`string`||y[N(i)]||En(e,r,i)}},An=function(e){let t=[e];for(;t.length>0;){let e=t.pop();se(e)===k.element&&kn(e);let n=te(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},jn=function(e,t){return Be?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},Mn=function(e){if(!Be)return;let t=[e];for(;t.length>0;){let e=t.pop(),n=se(e);if(n===k.processingInstruction||n===k.comment&&T(Kt,e.data)){try{f(e)}catch{}continue}if(n===k.element){let t=e,n=N(ce(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&jn(`for`,n)&&t.removeAttribute(`for`)}catch{}}let r=te(e);if(r)for(let e=r.length-1;e>=0;--e)t.push(r[e])}},Nn=function(e){let t=null,r=null;if(Ge)e=`<remove></remove>`+e;else{let t=lt(e,/^[\r\n\t ]+/);r=t&&t[0]}pn===`application/xhtml+xml`&&on===A&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=h?me(e):e;if(on===A)try{t=new l().parseFromString(i,pn)}catch{}if(!t||!t.documentElement){t=ve.createDocument(on,`template`,null);try{t.documentElement.innerHTML=sn?le:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),on===A?be.call(t,Ve?`html`:`body`)[0]:Ve?t.documentElement:a},Pn=function(e){let t=oe?oe(e):e.ownerDocument;return g.call(t||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},Fn=function(e){return e=ut(e,Se,` `),e=ut(e,Ce,` `),e=ut(e,we,` `),e},In=function(e){e.normalize();let t=oe?oe(e):e.ownerDocument,n=g.call(t||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),r=n.nextNode();for(;r;)r.data=Fn(r.data),r=n.nextNode();let i=e.querySelectorAll?.call(e,`template`);i&&tt(i,e=>{P(e.content)&&In(e.content)})},Ln=function(e){let t=ae?ae(e):null;return typeof t!=`string`||N(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==ie(e)||typeof e.removeAttribute!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==m(e)||e.childNodes!==te(e)},P=function(e){if(!m||typeof e!=`object`||!e)return!1;try{return m(e)===k.documentFragment}catch{return!1}},Rn=function(e){if(!m||typeof e!=`object`||!e)return!1;try{return typeof m(e)==`number`}catch{return!1}};function F(e,n,r){e.length!==0&&tt(e,e=>{e.call(t,n,r,hn)})}let zn=function(e,t){return!!(Be&&e.hasChildNodes()&&!Rn(e.firstElementChild)&&T(Gt,e.textContent)&&T(Gt,e.innerHTML)||Be&&e.namespaceURI===A&&Xt[t]&&(Rn(e.firstElementChild)||typeof e.textContent==`string`&&T(Zt[t],e.textContent))||e.nodeType===k.processingInstruction||Be&&e.nodeType===k.comment&&T(Kt,e.data))},Bn=function(e,t){return e instanceof RegExp?T(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},Vn=function(e,t,n){if(!Pe[t]&&qn(t)&&Bn(Ne.tagNameCheck,t))return!1;if(et&&!ht[t]){let t=ne(e),r=te(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?ee(r[a],!0):r[a];t.insertBefore(i,p(e))}}}return Tn(e),!0},Hn=function(e,t,n,r){return e.length===0?t:t===n||t===r?O(t):t},Un=function(e,t){return e===t||ne(e)!==null?!1:(pt&&An(e),!0)},Wn=function(e,n){if(F(_.beforeSanitizeElements,e,null),Un(e,n))return!0;if(Ln(e))return Tn(e),!0;let r=N(ce(e));if(v=Hn(_.uponSanitizeElement,v,je,Ue),F(_.uponSanitizeElement,e,{tagName:r,allowedTags:v}),Un(e,n))return!0;if(zn(e,r))return Tn(e),!0;if(Pe[r]||!(Ie.tagCheck instanceof Function&&Ie.tagCheck(r))&&!v[r]){let t=Vn(e,r,n);return t===!1&&F(_.afterSanitizeElements,e,null),t}if(se(e)===k.element&&!wn(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&T(qt,e.innerHTML))return Tn(e),!0;if(ze&&e.nodeType===k.text){let n=Fn(e.textContent);e.textContent!==n&&(it(t.removed,{element:e.cloneNode()}),e.textContent=n)}return F(_.afterSanitizeElements,e,null),!1},Gn=function(e,t,r){if(Fe[t]||jn(t,e)||Xe&&(t===`id`||t===`name`)&&(r in n||r in gn))return!1;let i=y[t]||Ie.attributeCheck instanceof Function&&Ie.attributeCheck(t,e);return x&&T(Te,t)||b&&T(Ee,t)?!0:i?yt[t]||T(Ae,ut(r,Oe,``))||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&dt(r,`data:`)===0&&_t[e]||Le&&!T(De,ut(r,Oe,``))?!0:!r:qn(e)&&Bn(Ne.tagNameCheck,e)&&Bn(Ne.attributeNameCheck,t,e)||t===`is`&&Ne.allowCustomizedBuiltInElements&&Bn(Ne.tagNameCheck,r)},Kn=D({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),qn=function(e){return!Kn[st(e)]&&T(ke,e)},Jn=function(e,t,n,r){if(h&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return me(r);case`TrustedScriptURL`:return he(r)}return r},Yn=function(e,n,r,i){try{r?e.setAttributeNS(r,n,i):e.setAttribute(n,i),Ln(e)?Tn(e):rt(t.removed)}catch{On(n,e)}},Xn=function(e){F(_.beforeSanitizeAttributes,e,null);let t=e.attributes;if(!t||Ln(e))return;y=Hn(_.uponSanitizeAttribute,y,Me,We);let n={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:y,forceKeepAttr:void 0},r=t.length,i=N(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=N(o),u=c,d=o===`value`?u:ft(u);if(n.attrName=l,n.attrValue=d,n.keepAttr=!0,n.forceKeepAttr=void 0,F(_.uponSanitizeAttribute,e,n),d=n.attrValue,Qe&&(l===`id`||l===`name`)&&dt(d,$e)!==0&&(On(o,e,a),d=$e+d),Be&&T(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){On(o,e,a);continue}if(l===`attributename`&<(d,`href`)){On(o,e,a);continue}if(!n.forceKeepAttr){if(!n.keepAttr){On(o,e,a);continue}if(!Re&&T(Jt,d)){On(o,e,a);continue}if(ze&&(d=Fn(d)),!Gn(i,l,d)){On(o,e,a);continue}d=Jn(i,l,s,d),d!==u&&Yn(e,o,s,d)}}F(_.afterSanitizeAttributes,e,null)},Zn=function(e){let t=null,n=Pn(e);for(F(_.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(F(_.uponSanitizeShadowNode,t,null),Wn(t,e),Xn(t),P(t.content)&&Zn(t.content),se(t)===k.element){let e=re(t);P(e)&&(Qn(e),Zn(e))}F(_.afterSanitizeShadowDOM,e,null)},Qn=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){Zn(e.shadow);continue}let n=e.node,r=se(n)===k.element,i=te(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=ae?ae(n):null;if(typeof e==`string`&&N(e)===`template`){let e=n.content;P(e)&&t.push({node:e,shadow:null})}}if(r){let e=re(n);P(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(sn=!e,sn&&(e=`<!-->`),typeof e!=`string`&&!Rn(e)&&(e=xt(e),typeof e!=`string`))throw vt(`dirty is not a string, aborting`);if(!t.isSupported)return e;He?(v=Ue,y=We):vn(n),(_.uponSanitizeElement.length>0||_.uponSanitizeAttribute.length>0)&&(v=O(v)),_.uponSanitizeAttribute.length>0&&(y=O(y)),t.removed=[];let c=pt&&typeof e!=`string`&&Rn(e);if(c){Mn(e);let t=ce(e);if(typeof t==`string`){let n=N(t);if(!v[n]||Pe[n])throw Dn(e),vt(`root node is forbidden and cannot be sanitized in-place`)}if(Ln(e))throw Dn(e),vt(`root node is clobbered and cannot be sanitized in-place`);try{Qn(e)}catch(t){throw Dn(e),t}}else if(Rn(e))i=Nn(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===k.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),Qn(a);else{if(!qe&&!ze&&!Ve&&e.indexOf(`<`)===-1)return h&&Ye?me(e):e;if(i=Nn(e),!i)return qe?null:Ye?le:``}i&&Ge&&Tn(i.firstChild);let l=c?e:i;try{let e=Pn(l);for(;o=e.nextNode();)Wn(o,l),Xn(o),P(o.content)&&Zn(o.content)}catch(n){throw c&&(Dn(e),tt(t.removed,e=>{e.element&&An(e.element)})),n}if(c)return tt(t.removed,e=>{e.element&&An(e.element)}),ze&&In(e),e;if(qe){if(ze&&In(i),Je)for(s=ye.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(y.shadowroot||y.shadowrootmode)&&(s=xe.call(r,s,!0)),s}let u=Ve?i.outerHTML:i.innerHTML;return Ve&&v[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&T(Ut,i.ownerDocument.doctype.name)&&(u=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
|
|
6
|
-
`+u),ze&&(u=Fn(u)),h&&Ye?me(u):u},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};vn(e),He=!0,Ue=v,We=y},t.clearConfig=function(){hn=null,He=!1,Ue=null,We=null,h=ue,le=``},t.isValidAttribute=function(e,t,n){hn||vn({});let r=N(e),i=N(t);return Gn(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&w(_,e)&&it(_[e],t)},t.removeHook=function(e,t){if(w(_,e)){if(t!==void 0){let n=nt(_[e],t);return n===-1?void 0:at(_[e],n,1)[0]}return rt(_[e])}},t.removeHooks=function(e){w(_,e)&&(_[e]=[])},t.removeAllHooks=function(){_=en()},t}var an=rn();function A(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var on=A();function sn(e){on=e}var cn={exec:()=>null};function ln(e){let t=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),i=t[r];return i||(i=e(r),t[r]=i),i}}function j(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(M.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var un=((e=``)=>{try{return!!RegExp(`(?<=1)(?<!1)`+e)}catch{return!1}})(),M={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:ln(e=>RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:ln(e=>RegExp(`^ {0,${e}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:ln(e=>RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:ln(e=>RegExp(`^ {0,${e}}#`)),htmlBeginRegex:ln(e=>RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`,`i`)),blockquoteBeginRegex:ln(e=>RegExp(`^ {0,${e}}>`))},dn=/^(?:[ \t]*(?:\n|$))+/,fn=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,pn=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,mn=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,N=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hn=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,gn=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_n=j(gn).replace(/bull/g,hn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),vn=j(gn).replace(/bull/g,hn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),yn=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,bn=/^[^\n]+/,xn=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Sn=j(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,xn).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Cn=j(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,hn).getRegex(),wn=`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|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,Tn=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,En=j(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,Tn).replace(`tag`,wn).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Dn=e=>j(yn).replace(`hr`,mn).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace(`list`,e).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,wn).getRegex(),On=Dn(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),kn=Dn(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),An={blockquote:j(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,kn).getRegex(),code:fn,def:Sn,fences:pn,heading:N,hr:mn,html:En,lheading:_n,list:Cn,newline:dn,paragraph:On,table:cn,text:bn},jn=j(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,mn).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,wn).getRegex(),Mn={...An,lheading:vn,table:jn,paragraph:j(yn).replace(`hr`,mn).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,jn).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,wn).getRegex()},Nn={...An,html:j(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,Tn).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:cn,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:j(yn).replace(`hr`,mn).replace(`heading`,` *#{1,6} *[^
|
|
7
|
-
]`).replace(`lheading`,_n).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},Pn=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Fn=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,In=/^( {2,}|\\)\n(?!\s*$)/,Ln=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,P=/[\p{P}\p{S}]/u,Rn=/[\s\p{P}\p{S}]/u,F=/[^\s\p{P}\p{S}]/u,zn=j(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,Rn).getRegex(),Bn=/[\p{Pi}\p{Ps}"']/u,Vn=/(?!~)[\p{P}\p{S}]/u,Hn=/(?!~)[\s\p{P}\p{S}]/u,Un=/(?:[^\s\p{P}\p{S}]|~)/u,Wn=j(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,un?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),Gn=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Kn=j(Gn,`u`).replace(/punct/g,P).getRegex(),qn=j(Gn,`u`).replace(/punct/g,Vn).getRegex(),Jn=j(/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,`u`).replace(/openQuote/g,Bn).replace(/punct/g,P).getRegex(),Yn=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,Xn=j(Yn,`gu`).replace(/notPunctSpace/g,F).replace(/punctSpace/g,Rn).replace(/punct/g,P).getRegex(),Zn=j(Yn,`gu`).replace(/notPunctSpace/g,Un).replace(/punctSpace/g,Hn).replace(/punct/g,Vn).getRegex(),Qn=j(`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,F).replace(/punctSpace/g,Rn).replace(/punct/g,P).getRegex(),$n=j(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,F).replace(/punctSpace/g,Rn).replace(/punct/g,P).getRegex(),er=j(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,F).replace(/punctSpace/g,Rn).replace(/punct/g,P).getRegex(),tr=j(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,P).getRegex(),nr=j(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,F).replace(/punctSpace/g,Rn).replace(/punct/g,P).getRegex(),rr=j(/\\(punct)/,`gu`).replace(/punct/g,P).getRegex(),ir=j(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),ar=j(Tn).replace(`(?:-->|$)`,`-->`).getRegex(),or=j(`^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,ar).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),sr=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,cr=j(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace(`label`,sr).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),lr=j(/^!?\[(label)\]\[(ref)\]/).replace(`label`,sr).replace(`ref`,xn).getRegex(),ur=j(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,xn).getRegex(),dr=j(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,lr).replace(`nolink`,ur).getRegex(),fr=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,pr={_backpedal:cn,anyPunctuation:rr,autolink:ir,blockSkip:Wn,br:In,code:Fn,del:cn,delLDelim:cn,delRDelim:cn,emStrongLDelim:Kn,emStrongRDelimAst:Xn,emStrongRDelimUnd:$n,escape:Pn,link:cr,nolink:ur,punctuation:zn,reflink:lr,reflinkSearch:dr,tag:or,text:Ln,url:cn},mr={...pr,emStrongLDelim:Jn,emStrongRDelimAst:Qn,emStrongRDelimUnd:er,link:j(/^!?\[(label)\]\((.*?)\)/).replace(`label`,sr).getRegex(),reflink:j(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,sr).getRegex()},hr={...pr,emStrongRDelimAst:Zn,emStrongLDelim:qn,delLDelim:tr,delRDelim:nr,url:j(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,fr).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:j(/^(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace(`protocol`,fr).getRegex()},gr={...hr,br:j(In).replace(`{2,}`,`*`).getRegex(),text:j(hr.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},_r={normal:An,gfm:Mn,pedantic:Nn},vr={normal:pr,gfm:hr,breaks:gr,pedantic:mr},yr={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},br=e=>yr[e];function xr(e,t){if(t){if(M.escapeTest.test(e))return e.replace(M.escapeReplace,br)}else if(M.escapeTestNoEncode.test(e))return e.replace(M.escapeReplaceNoEncode,br);return e}function Sr(e){try{e=encodeURI(e).replace(M.percentDecode,`%`)}catch{return null}return e}function Cr(e,t){let n=e.replace(M.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(M.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t){if(n.length>t)n.splice(t);else for(;n.length<t;)n.push(``)}for(;r<n.length;r++)n[r]=n[r].trim().replace(M.slashPipe,`|`);return n}function wr(e,t,n){let r=e.length;if(r===0)return``;let i=0;for(;i<r;){let a=e.charAt(r-i-1);if(a===t&&!n)i++;else if(a!==t&&n)i++;else break}return e.slice(0,r-i)}function Tr(e){let t=e.split(`
|
|
8
|
-
`),n=t.length-1;for(;n>=0&&M.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
|
|
9
|
-
`)}function Er(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function Dr(e,t=0){let n=t,r=``;for(let t of e)if(t===` `){let e=4-n%4;r+=` `.repeat(e),n+=e}else r+=t,n++;return r}function Or(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function kr(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
|
|
10
|
-
`).map(e=>{let t=e.match(n.other.beginningSpace);if(t===null)return e;let[r]=t;return r.length>=i.length?e.slice(i.length):e}).join(`
|
|
11
|
-
`)}var Ar=class{options;rules;lexer;constructor(e){this.options=e||on}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:`space`,raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=this.options.pedantic?t[0]:Tr(t[0]);return{type:`code`,raw:e,codeBlockStyle:`indented`,text:e.replace(this.rules.other.codeRemoveIndent,``)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=kr(e,t[3]||``,this.rules);return{type:`code`,raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,`$1`):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=wr(e,`#`);(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:`heading`,raw:wr(t[0],`
|
|
12
|
-
`),depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:`hr`,raw:wr(t[0],`
|
|
13
|
-
`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=wr(t[0],`
|
|
14
|
-
`).split(`
|
|
15
|
-
`),n=``,r=``,i=[];for(;e.length>0;){let t=!1,a=[],o;for(o=0;o<e.length;o++)if(this.rules.other.blockquoteStart.test(e[o]))a.push(e[o]),t=!0;else if(!t)a.push(e[o]);else break;e=e.slice(o);let s=a.join(`
|
|
16
|
-
`),c=s.replace(this.rules.other.blockquoteSetextReplace,`
|
|
17
|
-
$1`).replace(this.rules.other.blockquoteSetextReplace2,``);n=n?`${n}
|
|
18
|
-
${s}`:s,r=r?`${r}
|
|
19
|
-
${c}`:c;let l=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(c,i,!0),this.lexer.state.top=l,e.length===0)break;let u=i.at(-1);if(u?.type===`code`)break;if(u?.type===`blockquote`){let t=u,a=e.join(`
|
|
20
|
-
`),o=t.raw+`
|
|
21
|
-
`+a.replace(this.rules.other.blockquoteSetextReplace2,``),s=this.blockquote(o);i[i.length-1]=s,n=`${n}
|
|
22
|
-
${a}`,r=r.substring(0,r.length-t.text.length)+s.text;break}if(u?.type===`list`){let t=u,a=t.raw+`
|
|
23
|
-
`+e.join(`
|
|
24
|
-
`),o=this.list(a);i[i.length-1]=o,n=n.substring(0,n.length-u.raw.length)+o.raw,r=r.substring(0,r.length-t.raw.length)+o.raw,e=a.substring(i.at(-1).raw.length).split(`
|
|
25
|
-
`);continue}}return{type:`blockquote`,raw:n,tokens:i,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,i={type:`list`,raw:``,ordered:r,start:r?+n.slice(0,-1):``,loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:`[*+-]`);let a=this.rules.other.listItemRegex(n),o=!1;for(;e;){let n=!1,r=``,s=``;if(!(t=a.exec(e))||this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let c=Dr(t[2].split(`
|
|
26
|
-
`,1)[0],t[1].length),l=e.split(`
|
|
27
|
-
`,1)[0],u=!c.trim(),d=0;if(this.options.pedantic?(d=2,s=c.trimStart()):u?d=t[1].length+1:(d=c.search(this.rules.other.nonSpaceChar),d=d>4?1:d,s=c.slice(d),d+=t[1].length),u&&this.rules.other.blankLine.test(l)&&(r+=l+`
|
|
28
|
-
`,e=e.substring(l.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(d),n=this.rules.other.hrRegex(d),i=this.rules.other.fencesBeginRegex(d),a=this.rules.other.headingBeginRegex(d),o=this.rules.other.htmlBeginRegex(d),ee=this.rules.other.blockquoteBeginRegex(d);for(;e;){let f=e.split(`
|
|
29
|
-
`,1)[0],p;if(l=f,this.options.pedantic?(l=l.replace(this.rules.other.listReplaceNesting,` `),p=l):p=l.replace(this.rules.other.tabCharGlobal,` `),i.test(l)||a.test(l)||o.test(l)||ee.test(l)||t.test(l)||n.test(l))break;if(p.search(this.rules.other.nonSpaceChar)>=d||!l.trim())s+=`
|
|
30
|
-
`+p.slice(d);else{if(u||c.replace(this.rules.other.tabCharGlobal,` `).search(this.rules.other.nonSpaceChar)>=4||i.test(c)||a.test(c)||n.test(c))break;s+=`
|
|
31
|
-
`+l}u=!l.trim(),r+=f+`
|
|
32
|
-
`,e=e.substring(f.length+1),c=p.slice(d)}}i.loose||(o?i.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(o=!0)),i.items.push({type:`list_item`,raw:r,task:!!this.options.gfm&&this.rules.other.listIsTask.test(s),loose:!1,text:s,tokens:[]}),i.raw+=r}let s=i.items.at(-1);if(s)s.raw=s.raw.trimEnd(),s.text=s.text.trimEnd();else return;i.raw=i.raw.trimEnd();for(let e of i.items)if(this.lexer.state.top=!1,e.tokens=this.lexer.blockTokens(e.text,[]),!i.loose){let t=e.tokens.filter(e=>e.type===`space`);i.loose=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw))}for(let e of i.items){let t=e.tokens[0];if(e.task&&(t?.type===`text`||t?.type===`paragraph`)){e.text=e.text.replace(this.rules.other.listReplaceTask,``),t.raw=t.raw.replace(this.rules.other.listReplaceTask,``),t.text=t.text.replace(this.rules.other.listReplaceTask,``);for(let e=this.lexer.inlineQueue.length-1;e>=0;e--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[e].src)){this.lexer.inlineQueue[e].src=this.lexer.inlineQueue[e].src.replace(this.rules.other.listReplaceTask,``);break}let n=this.rules.other.listTaskCheckbox.exec(e.raw);if(n){let t={type:`checkbox`,raw:n[0]+` `,checked:n[0]!==`[ ]`};e.checked=t.checked,i.loose?e.tokens[0]&&[`paragraph`,`text`].includes(e.tokens[0].type)&&`tokens`in e.tokens[0]&&e.tokens[0].tokens?(e.tokens[0].raw=t.raw+e.tokens[0].raw,e.tokens[0].text=t.raw+e.tokens[0].text,e.tokens[0].tokens.unshift(t)):e.tokens.unshift({type:`paragraph`,raw:t.raw,text:t.raw,tokens:[t]}):e.tokens.unshift(t)}}else e.task&&=!1}if(i.loose)for(let e of i.items){e.loose=!0;for(let t of e.tokens)t.type===`text`&&(t.type=`paragraph`)}return i}}html(e){let t=this.rules.block.html.exec(e);if(t){let e=Tr(t[0]);return{type:`html`,block:!0,raw:e,pre:t[1]===`pre`||t[1]===`script`||t[1]===`style`,text:e}}}def(e){let t=this.rules.block.def.exec(e);if(t){let e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal,` `),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,`$1`).replace(this.rules.inline.anyPunctuation,`$1`):``,r=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,`$1`):t[3];return{type:`def`,tag:e,raw:wr(t[0],`
|
|
33
|
-
`),href:n,title:r}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=Cr(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,``).split(`|`),i=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,``).split(`
|
|
34
|
-
`):[],a={type:`table`,raw:wr(t[0],`
|
|
35
|
-
`),header:[],align:[],rows:[]};if(n.length===r.length){for(let e of r)this.rules.other.tableAlignRight.test(e)?a.align.push(`right`):this.rules.other.tableAlignCenter.test(e)?a.align.push(`center`):this.rules.other.tableAlignLeft.test(e)?a.align.push(`left`):a.align.push(null);for(let e=0;e<n.length;e++)a.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:a.align[e]});for(let e of i)a.rows.push(Cr(e,a.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:a.align[t]})));return a}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let e=t[1].trim();return{type:`heading`,raw:wr(t[0],`
|
|
36
|
-
`),depth:t[2].charAt(0)===`=`?1:2,text:e,tokens:this.lexer.inline(e)}}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let e=t[1].charAt(t[1].length-1)===`
|
|
37
|
-
`?t[1].slice(0,-1):t[1];return{type:`paragraph`,raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:`text`,raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:`escape`,raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:`html`,raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=wr(e.slice(0,-1),`\\`);if((e.length-t.length)%2==0)return}else{let e=Er(t[2],`()`);if(e===-2)return;if(e>-1){let n=(t[0].indexOf(`!`)===0?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=``}}let n=t[2],r=``;if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):``;return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),Or(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,`$1`),title:r&&r.replace(this.rules.inline.anyPunctuation,`$1`)},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal,` `).toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:`text`,raw:e,text:e}}return Or(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=``){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||!r[1]&&!r[2]&&!r[3]&&!r[4]||r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[3])||!n||this.rules.inline.punctuation.exec(n))){let i=[...r[0]].length-1,a,o,s=i,c=0,l=r[0][0],u=n===l,d=l===`*`?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(d.lastIndex=0,t=t.slice(-1*e.length+i);(r=d.exec(t))!==null;){if(a=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!a)continue;if(o=[...a].length,r[3]||r[4]){s+=o;continue}if(r[5]||r[6]){if(i%3&&!((i+o)%3)){c+=o;continue}if(u)break}if(s-=o,s>0)continue;o=Math.min(o,o+s+c);let t=[...r[0]][0].length,n=e.slice(0,i+r.index+t+o);if(Math.min(i,o)%2){let e=n.slice(1,-1);return{type:`em`,raw:n,text:e,tokens:this.lexer.inlineTokens(e)}}let l=n.slice(2,-2);return{type:`strong`,raw:n,text:l,tokens:this.lexer.inlineTokens(l)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal,` `),n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:`codespan`,raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:`br`,raw:t[0]}}del(e,t,n=``){let r=this.rules.inline.delLDelim.exec(e);if(r&&(!r[1]||!n||this.rules.inline.punctuation.exec(n))){let n=[...r[0]].length-1,i,a,o=n,s=this.rules.inline.delRDelim;for(s.lastIndex=0,t=t.slice(-1*e.length+n);(r=s.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(a=[...i].length,a!==n))continue;if(r[3]||r[4]){o+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o);let t=[...r[0]][0].length,s=e.slice(0,n+r.index+t+a),c=s.slice(n,-n);return{type:`del`,raw:s,text:c,tokens:this.lexer.inlineTokens(c)}}}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return t[2]===`@`?(e=t[1],n=`mailto:`+e):(e=t[1],n=e),{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if(t[2]===`@`)e=t[0],n=`mailto:`+e;else{let r;do r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??``;while(r!==t[0]);e=t[0],n=t[1]===`www.`?`http://`+t[0]:t[0]}return{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:`text`,raw:t[0],text:t[0],escaped:e}}}},jr=class e{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||on,this.options.tokenizer=this.options.tokenizer||new Ar,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:M,block:_r.normal,inline:vr.normal};this.options.pedantic?(t.block=_r.pedantic,t.inline=vr.pedantic):this.options.gfm&&(t.block=_r.gfm,t.inline=this.options.breaks?vr.breaks:vr.gfm),this.tokenizer.rules=t}static get rules(){return{block:_r,inline:vr}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(M.carriageReturn,`
|
|
38
|
-
`),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(M.tabCharGlobal,` `).replace(M.spaceLine,``));let r=1/0;for(;e;){if(e.length<r)r=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}let i;if(this.options.extensions?.block?.some(n=>(i=n.call({lexer:this},e,t))?(e=e.substring(i.raw.length),t.push(i),!0):!1))continue;if(i=this.tokenizer.space(e)){e=e.substring(i.raw.length);let n=t.at(-1);i.raw.length===1&&n!==void 0?n.raw+=`
|
|
39
|
-
`:t.push(i);continue}if(i=this.tokenizer.code(e)){e=e.substring(i.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=(n.raw.endsWith(`
|
|
40
|
-
`)?``:`
|
|
41
|
-
`)+i.raw,n.text+=`
|
|
42
|
-
`+i.text,this.inlineQueue.at(-1).src=n.text):t.push(i);continue}if(i=this.tokenizer.fences(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.heading(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.hr(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.blockquote(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.list(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.html(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.def(e)){e=e.substring(i.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=(n.raw.endsWith(`
|
|
43
|
-
`)?``:`
|
|
44
|
-
`)+i.raw,n.text+=`
|
|
45
|
-
`+i.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},t.push(i));continue}if(i=this.tokenizer.table(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.lheading(e)){e=e.substring(i.raw.length),t.push(i);continue}let a=e;if(this.options.extensions?.startBlock){let t=1/0,n=e.slice(1),r;this.options.extensions.startBlock.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(a=e.substring(0,t+1))}if(this.state.top&&(i=this.tokenizer.paragraph(a))){let r=t.at(-1);n&&r?.type===`paragraph`?(r.raw+=(r.raw.endsWith(`
|
|
46
|
-
`)?``:`
|
|
47
|
-
`)+i.raw,r.text+=`
|
|
48
|
-
`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=r.text):t.push(i),n=a.length!==e.length,e=e.substring(i.raw.length);continue}if(i=this.tokenizer.text(e)){e=e.substring(i.raw.length);let n=t.at(-1);n?.type===`text`?(n.raw+=(n.raw.endsWith(`
|
|
49
|
-
`)?``:`
|
|
50
|
-
`)+i.raw,n.text+=`
|
|
51
|
-
`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(i);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){this.tokenizer.lexer=this;let n=e;if(this.tokens.links){let e=Object.keys(this.tokens.links);e.length>0&&(n=n.replace(this.tokenizer.rules.inline.reflinkSearch,t=>e.includes(t.slice(t.lastIndexOf(`[`)+1,-1))?`[`+`a`.repeat(t.length-2)+`]`:t))}n=n.replace(this.tokenizer.rules.inline.anyPunctuation,e=>`+`.repeat(e.length)),n=n.replace(this.tokenizer.rules.inline.blockSkip,(e,t,n)=>{let r=n?n.length:0;return e.slice(0,r)+`[`+`a`.repeat(e.length-r-2)+`]`}),n=this.options.hooks?.emStrongMask?.call({lexer:this},n)??n;let r=!1,i=``,a=1/0;for(;e;){if(e.length<a)a=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}r||(i=``),r=!1;let o;if(this.options.extensions?.inline?.some(n=>(o=n.call({lexer:this},e,t))?(e=e.substring(o.raw.length),t.push(o),!0):!1))continue;if(o=this.tokenizer.escape(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.tag(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.link(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(o.raw.length);let n=t.at(-1);o.type===`text`&&n?.type===`text`?(n.raw+=o.raw,n.text+=o.text):t.push(o);continue}if(o=this.tokenizer.emStrong(e,n,i)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.codespan(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.br(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.del(e,n,i)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.autolink(e)){e=e.substring(o.raw.length),t.push(o);continue}if(!this.state.inLink&&(o=this.tokenizer.url(e))){e=e.substring(o.raw.length),t.push(o);continue}let s=e;if(this.options.extensions?.startInline){let t=1/0,n=e.slice(1),r;this.options.extensions.startInline.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(s=e.substring(0,t+1))}if(o=this.tokenizer.inlineText(s)){e=e.substring(o.raw.length),o.raw.slice(-1)!==`_`&&(i=o.raw.slice(-1)),r=!0;let n=t.at(-1);n?.type===`text`?(n.raw+=o.raw,n.text+=o.text):t.push(o);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return t}infiniteLoopError(e){let t=`Infinite loop on byte: `+e;if(this.options.silent)console.error(t);else throw Error(t)}},Mr=class{options;parser;constructor(e){this.options=e||on}space(e){return``}code({text:e,lang:t,escaped:n}){let r=(t||``).match(M.notSpaceStart)?.[0],i=e.replace(M.endingNewline,``)+`
|
|
52
|
-
`;return r?`<pre><code class="language-`+xr(r)+`">`+(n?i:xr(i,!0))+`</code></pre>
|
|
53
|
-
`:`<pre><code>`+(n?i:xr(i,!0))+`</code></pre>
|
|
54
|
-
`}blockquote({tokens:e}){return`<blockquote>
|
|
55
|
-
${this.parser.parse(e)}</blockquote>
|
|
56
|
-
`}html({text:e}){return e}def(e){return``}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
57
|
-
`}hr(e){return`<hr>
|
|
58
|
-
`}list(e){let t=e.ordered,n=e.start,r=``;for(let t=0;t<e.items.length;t++){let n=e.items[t];r+=this.listitem(n)}let i=t?`ol`:`ul`,a=t&&n!==1?` start="`+n+`"`:``;return`<`+i+a+`>
|
|
59
|
-
`+r+`</`+i+`>
|
|
60
|
-
`}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>
|
|
61
|
-
`}checkbox({checked:e}){return`<input `+(e?`checked="" `:``)+`disabled="" type="checkbox"> `}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
|
|
62
|
-
`}table(e){let t=``,n=``;for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let r=``;for(let t=0;t<e.rows.length;t++){let i=e.rows[t];n=``;for(let e=0;e<i.length;e++)n+=this.tablecell(i[e]);r+=this.tablerow({text:n})}return r&&=`<tbody>${r}</tbody>`,`<table>
|
|
63
|
-
<thead>
|
|
64
|
-
`+t+`</thead>
|
|
65
|
-
`+r+`</table>
|
|
66
|
-
`}tablerow({text:e}){return`<tr>
|
|
67
|
-
${e}</tr>
|
|
68
|
-
`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?`th`:`td`;return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
|
|
69
|
-
`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${xr(e,!0)}</code>`}br(e){return`<br>`}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=Sr(e);if(i===null)return r;e=i;let a=`<a href="`+e+`"`;return t&&(a+=` title="`+xr(t)+`"`),a+=`>`+r+`</a>`,a}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=Sr(e);if(i===null)return xr(n);e=i;let a=`<img src="${e}" alt="${xr(n)}"`;return t&&(a+=` title="${xr(t)}"`),a+=`>`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:xr(e.text)}},Nr=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}checkbox({raw:e}){return e}},Pr=class e{options;renderer;textRenderer;constructor(e){this.options=e||on,this.options.renderer=this.options.renderer||new Mr,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Nr}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e){this.renderer.parser=this;let t=``;for(let n=0;n<e.length;n++){let r=e[n];if(this.options.extensions?.renderers?.[r.type]){let e=r,n=this.options.extensions.renderers[e.type].call({parser:this},e);if(n!==!1||![`space`,`hr`,`heading`,`code`,`table`,`blockquote`,`list`,`checkbox`,`html`,`def`,`paragraph`,`text`].includes(e.type)){t+=n||``;continue}}let i=r;switch(i.type){case`space`:t+=this.renderer.space(i);break;case`hr`:t+=this.renderer.hr(i);break;case`heading`:t+=this.renderer.heading(i);break;case`code`:t+=this.renderer.code(i);break;case`table`:t+=this.renderer.table(i);break;case`blockquote`:t+=this.renderer.blockquote(i);break;case`list`:t+=this.renderer.list(i);break;case`checkbox`:t+=this.renderer.checkbox(i);break;case`html`:t+=this.renderer.html(i);break;case`def`:t+=this.renderer.def(i);break;case`paragraph`:t+=this.renderer.paragraph(i);break;case`text`:t+=this.renderer.text(i);break;default:{let e=`Token with "`+i.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return t}parseInline(e,t=this.renderer){this.renderer.parser=this;let n=``;for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let e=this.options.extensions.renderers[i.type].call({parser:this},i);if(e!==!1||![`escape`,`html`,`link`,`image`,`checkbox`,`strong`,`em`,`codespan`,`br`,`del`,`text`].includes(i.type)){n+=e||``;continue}}let a=i;switch(a.type){case`escape`:n+=t.text(a);break;case`html`:n+=t.html(a);break;case`link`:n+=t.link(a);break;case`image`:n+=t.image(a);break;case`checkbox`:n+=t.checkbox(a);break;case`strong`:n+=t.strong(a);break;case`em`:n+=t.em(a);break;case`codespan`:n+=t.codespan(a);break;case`br`:n+=t.br(a);break;case`del`:n+=t.del(a);break;case`text`:n+=t.text(a);break;default:{let e=`Token with "`+a.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}},Fr=class{options;block;constructor(e){this.options=e||on}static passThroughHooks=new Set([`preprocess`,`postprocess`,`processAllTokens`,`emStrongMask`]);static passThroughHooksRespectAsync=new Set([`preprocess`,`postprocess`,`processAllTokens`]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?jr.lex:jr.lexInline}provideParser(e=this.block){return e?Pr.parse:Pr.parseInline}},Ir=new class{defaults=A();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Pr;Renderer=Mr;TextRenderer=Nr;Lexer=jr;Tokenizer=Ar;Hooks=Fr;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case`table`:{let e=r;for(let r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case`list`:{let e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(r=>{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new Mr(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new Ar(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new Fr;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];t[r]=Fr.passThroughHooks.has(n)?e=>{if(this.defaults.async&&Fr.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return jr.lex(e,t??this.defaults)}parser(e,t){return Pr.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(typeof t>`u`||t===null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer(e):e?jr.lex:jr.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser(e):e?Pr.parse:Pr.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer(e):e?jr.lex:jr.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser(e):e?Pr.parse:Pr.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=`
|
|
70
|
-
Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+xr(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function I(e,t){return Ir.parse(e,t)}I.options=I.setOptions=function(e){return Ir.setOptions(e),I.defaults=Ir.defaults,sn(I.defaults),I},I.getDefaults=A,I.defaults=on;function Lr(...e){return Ir.use(...e),I.defaults=Ir.defaults,sn(I.defaults),I}I.use=Lr,I.walkTokens=function(e,t){return Ir.walkTokens(e,t)},I.parseInline=Ir.parseInline,I.Parser=Pr,I.parser=Pr.parse,I.Renderer=Mr,I.TextRenderer=Nr,I.Lexer=jr,I.lexer=jr.lex,I.Tokenizer=Ar,I.Hooks=Fr,I.parse=I,I.options,I.setOptions,I.walkTokens,I.parseInline,Pr.parse,jr.lex;var L=e=>{let t=document.querySelector(e);if(!t)throw Error(`missing element: ${e}`);return t};function Rr(e){let t=Math.round((Date.now()-e)/6e4);return t<1?`now`:t<60?`${t}m`:t<1440?`${Math.round(t/60)}h`:`${Math.round(t/1440)}d`}var zr=e=>{let t=Rr(e);return t===`now`?`just now`:`${t} ago`};function R(e,t,...n){let r=document.createElement(e);return t&&(r.className=t),r.append(...n),r}var Br=e=>e.split(`/`).filter(Boolean).pop()??e,Vr=e=>`New session in ${Br(e)}`;function Hr(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}`} ${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`}function Ur(e){let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function Wr(e,t,n){return{visible:!1,show(n,r){this.visible=!0,e.classList.remove(`hidden`),e.classList.add(`flex`),t(n,r)},hide(){n?.(),this.visible=!1,e.classList.add(`hidden`),e.classList.remove(`flex`)}}}function Gr(e){let t=R(`span`,`help`);return t.innerHTML=an.sanitize(I.parseInline(e,{async:!1})),Kr(t),t}function Kr(e){for(let t of e.querySelectorAll(`a`))(t.getAttribute(`href`)??``).startsWith(`#`)||(t.target=`_blank`,t.rel=`noreferrer`)}async function qr(e){if(navigator.clipboard)return navigator.clipboard.writeText(e);let t=document.createElement(`textarea`);t.value=e,t.className=`fixed opacity-0`,document.body.append(t),t.select();let n=document.execCommand(`copy`);if(t.remove(),!n)throw Error(`clipboard unavailable`)}function Jr(e,t){let n=R(`button`,e,`Copy`);n.title=`Copy to clipboard`;let r;return n.onclick=async e=>{e.stopPropagation(),n.textContent=await qr(t()).then(()=>`Copied`,()=>`Failed`),clearTimeout(r),r=setTimeout(()=>n.textContent=`Copy`,1200)},n}function Yr(e,t){let n=document.createElement(`details`);n.className=e;let r=R(`summary`,`flex cursor-pointer select-none items-center gap-1.5`);return r.append(g(l,`chev h-3 w-3`),...t),n.append(r),{el:n,summary:r}}var Xr=(e,t=!1)=>Zr(e,`${t?`btn btn-primary`:`btn`} text-[12.5px]`),Zr=(e,t=``)=>{let n=R(`button`,t,e);return n.type=`button`,n},Qr=e=>R(`span`,`mr-1 flex-none font-medium max-md:hidden`,e),$r=(...e)=>R(`div`,`toolbar flex min-h-10 flex-none flex-wrap items-center gap-2 px-4 py-2`,...e);function ei(e,t,n){let r=R(`div`,`inline-flex flex-none items-center gap-0.5 rounded-full bg-neutral-100 p-1`);for(let[i,a]of e){let e=a===t,o=Zr(i,`cursor-pointer whitespace-nowrap rounded-full px-3 py-1 text-[12px] transition-colors ${e?`bg-white font-medium text-neutral-800 shadow-xs`:`text-neutral-500 hover:text-neutral-700`}`);o.setAttribute(`aria-pressed`,String(e)),o.onclick=()=>n(a),r.append(o)}return r}function ti(e,t,n){let r=Zr(e,`flex cursor-pointer items-center gap-1.5 rounded-full px-3.5 py-2 text-[13px] transition-colors ${t?`bg-indigo-50 font-medium text-indigo-700 ring-1 ring-indigo-200/70`:`text-neutral-600 hover:bg-neutral-100`}`);return r.onclick=n,r}var ni=`rounded-3xl border border-neutral-200 bg-white shadow-sm`,ri=`border-b border-neutral-200/70 bg-neutral-50/50`;function ii(e,t,...n){let r=R(`section`,ni),i=R(`div`,`rounded-t-3xl ${ri} px-5 py-4`);return i.append(R(`h2`,`text-[14px] font-semibold text-neutral-800`,e)),t&&i.append(R(`p`,`mt-1 text-[12px] leading-normal text-neutral-500`,t)),r.append(i,R(`div`,`flex flex-col gap-4 px-5 py-5`,...n)),r}function ai(e,t,n={}){let r=R(`div`,`flex flex-col gap-1.5`),i=R(`div`,`flex items-center gap-1.5`,R(`span`,`field-label`,e));return n.help&&i.append(n.help),r.append(i,t),n.hint&&r.append(R(`span`,`text-[11.5px] leading-snug text-neutral-400`,n.hint)),r}var oi=`w-full rounded-xl border border-neutral-200 bg-neutral-50/60 px-3 py-2.5 text-[12.5px] transition-colors placeholder:text-neutral-400 hover:border-neutral-300 focus:border-indigo-400 focus:ring-2 focus:ring-indigo-100 focus:outline-none`,si=(e,t,n,r=!1)=>{let i=document.createElement(`input`);return i.className=r?`${oi} font-mono`:oi,i.value=e,i.placeholder=t,i.oninput=()=>n(i.value),i},ci=(e=``,t=`text`)=>{let n=document.createElement(`input`);return n.type=t,n.className=oi,n.value=e,n},li=(e,t)=>{let n=document.createElement(`select`);return n.className=`${oi} select`,n.append(...e.map(([e,t])=>new Option(e,t))),n.value=t,n},ui=(e=``,t=4)=>{let n=document.createElement(`textarea`);return n.className=`${oi} resize-y font-mono`,n.value=e,n.rows=t,n.spellcheck=!1,n};function di(e,t,n,r,i){let a=document.createElement(`input`);a.type=`checkbox`,a.className=`peer sr-only`,a.checked=n,a.onchange=()=>r(a.checked);let o=R(`span`,`relative h-4 w-7 flex-none rounded-full bg-neutral-300 transition-colors after:absolute after:left-0.5 after:top-0.5 after:h-3 after:w-3 after:rounded-full after:bg-white dark:after:bg-neutral-950 after:shadow-sm after:transition-transform peer-checked:bg-indigo-600 peer-checked:after:translate-x-3 peer-focus-visible:ring-2 peer-focus-visible:ring-indigo-200`),s=R(`label`,`flex cursor-pointer gap-2.5 ${e?`items-start`:`items-center`}`);if(s.append(a,o),e){let n=R(`span`,`flex items-center gap-1.5`,R(`span`,`text-[13px] text-neutral-700`,e));i&&n.append(i);let r=R(`span`,`flex min-w-0 flex-col`,n);t&&r.append(R(`span`,`text-[11.5px] leading-snug text-neutral-400`,t)),s.append(r)}return s}var fi={idle:`text-neutral-400`,saving:`text-neutral-400`,saved:`text-green-700`,failed:`text-red-600`};function pi(e,t,n){e.className=`text-[11.5px] ${fi[t]}`,e.textContent=n}var mi=(e,t,n)=>R(`span`,`inline-flex flex-none items-center gap-1 rounded-full px-1.5 py-px text-[10px] font-medium uppercase tracking-wide ring-1 ${t}`,...n?[R(`span`,`inline-block h-1.5 w-1.5 flex-none rounded-full ${n}`)]:[],e),hi=e=>R(`p`,`rounded-lg border border-dashed border-neutral-200 px-3 py-4 text-center text-[12.5px] text-neutral-400`,e);function gi(e,t,n=`left`){let r=R(`span`,`group relative inline-flex`),i=Zr(``,`flex h-4 w-4 cursor-help items-center justify-center text-neutral-400 transition-colors group-hover:text-indigo-500`);i.append(g(u,`h-full w-full`)),i.setAttribute(`aria-label`,e);let a=R(`span`,`absolute ${n===`right`?`right-0`:`left-0`} top-full z-20 hidden w-[min(27rem,calc(100vw-3rem))] pt-1.5 group-hover:block`),o=R(`span`,`flex flex-col gap-2 rounded-xl border border-neutral-200 bg-white p-3.5 text-[12px] font-normal normal-case leading-[1.55] tracking-normal text-neutral-600 shadow-xl`);o.append(R(`span`,`text-[12.5px] font-semibold text-neutral-800`,e));let s=R(`ol`,`flex list-decimal flex-col gap-1.5 pl-4`);for(let e of t){let t=R(`li`,`marker:text-neutral-400`);t.append(typeof e==`string`?Gr(e):e),s.append(t)}return o.append(s),a.append(o),i.onclick=()=>{let e=a.classList.contains(`hidden`);a.classList.toggle(`hidden`,!e),a.classList.toggle(`block`,e),i.classList.toggle(`text-indigo-500`,e)},r.append(i,a),r}var _i=(e,t)=>R(`span`,`flex flex-col gap-1`,Gr(e),t),vi=e=>`[${e.split(`/`).pop()??`file`}](file://${encodeURI(e).replace(/\(/g,`%28`).replace(/\)/g,`%29`)})`,yi=/^ {0,3}(`{3,}|~{3,})/;function bi(e){let t=[],n,r=0;for(let i of e.split(`
|
|
71
|
-
`)){let e=yi.exec(i)?.[1];if(n!==void 0)t.push([r,r+i.length]),e&&e[0]===n[0]&&e.length>=n.length&&(n=void 0);else if(e)n=e,t.push([r,r+i.length]);else{let e=[...i.matchAll(/`+/g)];for(let n=0;n<e.length;n++){let i=e[n],a=n+1;for(;a<e.length&&e[a][0].length!==i[0].length;)a++;if(a===e.length)break;t.push([r+i.index,r+e[a].index+e[a][0].length]),n=a}}r+=i.length+1}return t}function xi(e,t,n){let r=bi(e),i=``,a=0;for(let o of e.matchAll(t)){let t=o.index,s=t+o[0].length;r.some(([e,n])=>t<n&&s>e)||(i+=e.slice(a,t)+n(o),a=s)}return i+e.slice(a)}var Si=/^\[[^\]\n]*\]\(\s*<?file:\/\/(\/[^)>\s]*)>?\s*\)$/;function Ci(e){let t=e.split(`
|
|
72
|
-
`),n=t.length;for(;n>0&&Si.test(t[n-1].trim());)n--;let r=t.slice(n).map(e=>{let t=Si.exec(e.trim())[1];try{return decodeURIComponent(t)}catch{return t}});return{text:t.slice(0,n).join(`
|
|
73
|
-
`).trimEnd(),paths:r}}var wi=`modulepreload`,Ti=function(e){return`/`+e},Ei={},Di=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Ti(t,n),t=s(t),t in Ei)return;Ei[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:wi,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Oi,ki;function Ai(){return ki??=Di(()=>import(`./hljs-tWqyD59G.js`).then(e=>Oi=e.default,e=>{console.warn(`highlighting unavailable — code stays plain text`,e)}),[]),ki}async function ji(e){let t=await Ai();if(t)for(let n of e.querySelectorAll(`pre code[class]`)){let e=/(?:language|lang)-(\S+)/.exec(n.className)?.[1]?.toLowerCase();!e||!t.getLanguage(e)||(n.innerHTML=t.highlight(n.textContent??``,{language:e}).value)}}var Mi={ts:`typescript`,tsx:`typescript`,mts:`typescript`,cts:`typescript`,js:`javascript`,jsx:`javascript`,mjs:`javascript`,cjs:`javascript`,py:`python`,rs:`rust`,sh:`bash`,zsh:`bash`,md:`markdown`,yml:`yaml`,html:`xml`,htm:`xml`,svg:`xml`,patch:`diff`};async function Ni(e){let t=await Ai(),n=e.split(`.`).pop()?.toLowerCase()??``,r=Mi[n]??n;return t?.getLanguage(r)?r:null}function Pi(e,t){let n=document.createElement(`span`);return Oi&&t&&e.length<=500?n.innerHTML=Oi.highlight(e,{language:t}).value:n.textContent=e,n}var Fi=2e4;function Ii(e){let t=e.split(`
|
|
74
|
-
`);return t.at(-1)===``&&t.pop(),t.map((e,t)=>({nums:[t+1],text:e,tone:``}))}function Li(e,t){let n=e.length<=Fi?t:null,r=Math.max(2,...e.map(e=>e.nums.reduce((e,t)=>Math.max(e,String(t).length),0))),i=R(`div`,`py-2 font-mono text-[12px] leading-[1.5]`);for(let t of e){let e=R(`div`,`flex pl-2 pr-4 ${t.tone===`add`?`bg-emerald-50`:t.tone===`del`?`bg-red-50`:``}`);for(let n of t.nums){let t=R(`span`,`flex-none select-none pr-1.5 text-right text-neutral-300`,n===``?``:String(n));t.style.width=`calc(${r}ch + 0.375rem)`,e.append(t)}e.append(Ri(t,n)),i.append(e)}return i}function Ri(e,t){let n=`min-w-0 flex-1 whitespace-pre-wrap [overflow-wrap:anywhere]`;if(!e.mark||e.mark[0]>=e.mark[1]){let r=Pi(e.text,t);return r.className=n,r}let[r,i]=e.mark,a=Pi(e.text.slice(r,i),t);return a.className=`rounded-xs ${e.tone===`add`?`bg-emerald-200/80`:`bg-red-200/70`}`,R(`span`,n,Pi(e.text.slice(0,r),t),a,Pi(e.text.slice(i),t))}var zi=L(`#image-dialog`),z=L(`#image-stage`),Bi=L(`#image-full`),Vi=L(`#image-prev`),Hi=L(`#image-next`),Ui=L(`#image-close`),Wi=[],Gi=0;function Ki(e){Wi.length<2||(Gi=(Gi+e+Wi.length)%Wi.length,Yi(!1),Bi.src=Wi[Gi])}var qi=2.5,Ji=()=>z.dataset.zoom!==void 0;function Yi(e,t){if(!e){delete z.dataset.zoom,Bi.style.cssText=``;return}let n=Bi.getBoundingClientRect(),r=z.getBoundingClientRect(),i=t?(t.x-n.left)/n.width:.5,a=t?(t.y-n.top)/n.height:.5,o=n.width*qi,s=n.height*qi;z.dataset.zoom=``,Bi.style.width=`${String(o)}px`,Bi.style.height=`${String(s)}px`,z.scrollLeft=i*o-r.width/2,z.scrollTop=a*s-r.height/2}function Xi(e){let t=e.closest(`[data-gallery]`);Wi=t?[...t.querySelectorAll(`img.thumb`)].map(e=>e.src):[e.src],Gi=Math.max(0,Wi.indexOf(e.src)),Bi.src=e.src;let n=Wi.length<2?`none`:`flex`;Vi.style.display=n,Hi.style.display=n,zi.showModal()}var Zi=4,Qi,$i=!1;z.onpointerdown=e=>{$i=!1,!(!Ji()||e.button!==0)&&(Qi={x:e.clientX,y:e.clientY,left:z.scrollLeft,top:z.scrollTop},z.setPointerCapture(e.pointerId))},z.onpointermove=e=>{if(!Qi)return;let t=e.clientX-Qi.x,n=e.clientY-Qi.y;(Math.abs(t)>Zi||Math.abs(n)>Zi)&&($i=!0),z.scrollLeft=Qi.left-t,z.scrollTop=Qi.top-n};var ea=()=>{Qi=void 0};z.onpointerup=ea,z.onpointercancel=ea,z.onclick=e=>{$i||(e.target===Bi?Yi(!Ji(),{x:e.clientX,y:e.clientY}):zi.close())},Ui.onclick=()=>zi.close(),zi.onclose=()=>Yi(!1),Vi.onclick=()=>Ki(-1),Hi.onclick=()=>Ki(1),zi.onkeydown=e=>{(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&(e.preventDefault(),Ki(e.key===`ArrowLeft`?-1:1))};function ta(e){let t=e.querySelector(`:scope > .thumbs`);if(t)return t;let n=R(`div`,`thumbs`);return e.append(n),n}function na(e){let t=document.createElement(`img`);return t.src=e,t.loading=`lazy`,t.className=`thumb`,t.onclick=()=>Xi(t),t}var ra=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`avif`,`bmp`]),ia=524288,aa=L(`#file-dialog`),oa=L(`#file-name`),sa=L(`#file-text`),ca=L(`#file-download`);L(`#file-close`).onclick=()=>aa.close();var la=e=>e.split(`.`).pop()?.toLowerCase()??``,ua=(e,t,n=!1)=>`/api/sessions/${encodeURIComponent(e)}/files?path=${encodeURIComponent(t)}${n?`&download=1`:``}`;function da(e,t){return xi(e,/\]\(\s*<?file:\/\/(\/[^)>\s]*)>?\s*\)/g,e=>{let n=e[1];try{n=decodeURIComponent(n)}catch{}return`](${ua(t,n)})`})}var fa=e=>/^\/api\/sessions\/[^/]+\/files\?/.test(e);function pa(e,t){let n=Br(t)||`file`,r=ua(e,t);return ra.has(la(n))?va(r,n):ya(r,n)}function ma(e){return new URLSearchParams(e.slice(e.indexOf(`?`)+1)).get(`path`)??``}var ha=(e,t=`text-neutral-500`)=>R(`div`,`px-3 py-2 text-[12.5px] ${t}`,e),ga=0;async function _a(e,t){let n=++ga;oa.textContent=t,ca.href=`${e}&download=1`,sa.replaceChildren(ha(`loading…`)),aa.showModal();let r=e=>{n===ga&&sa.replaceChildren(e)},i;try{i=await fetch(e)}catch(e){return r(ha(`failed to load: ${String(e)}`,`text-red-600`))}if(!i.ok)return r(ha(await x(i,`failed to load`),`text-red-600`));let a=i.headers.get(`content-type`)??``;if(!a.startsWith(`text/`)&&!a.startsWith(`image/svg+xml`))return r(ha(`Binary file — use Download.`));let o=await i.text(),s=o.length>ia?`${o.slice(0,ia)}\n…`:o,c=await Ni(t);r(Li(Ii(s),c))}function va(e,t){let n=na(e);return n.alt=t,n}function ya(e,t){let n=la(t),r=R(`span`,`inline-flex max-w-full items-center gap-2.5 rounded-lg border border-neutral-200 bg-neutral-50 px-2.5 py-1.5 no-underline`),i=R(`span`,`flex h-7 w-7 flex-none items-center justify-center rounded-md bg-indigo-50 text-[10px] font-semibold uppercase text-indigo-600`,n.slice(0,4)||`file`),a=R(`span`,`min-w-0 truncate text-[13px] font-medium text-neutral-800`,t),o=R(`span`,`ml-1 flex flex-none items-center gap-0.5`),s=R(`button`,`icon-btn h-6 w-6 text-[13px]`,g(te));s.setAttribute(`aria-label`,`Preview`),s.title=`Preview`,s.onclick=r=>{r.preventDefault(),n===`pdf`?window.open(e,`_blank`,`noopener`):_a(e,t)},o.append(s);let c=document.createElement(`a`);return c.className=`icon-btn h-6 w-6 text-[13px] no-underline`,c.href=`${e}&download=1`,c.download=t,c.title=`Download`,c.append(g(f)),c.setAttribute(`aria-label`,`Download`),o.append(c),r.append(i,a,o),r}function ba(e){let t=new Set;for(let n of e)n.parentElement&&t.add(n.parentElement);for(let n of t){let t=[...n.children].filter(t=>e.includes(t));if([...n.childNodes].every(e=>e.nodeType===Node.TEXT_NODE?!e.textContent?.trim():t.includes(e))){n.classList.add(`thumbs`);continue}let r=R(`div`,`thumbs`);r.append(...t),n.after(r)}}function xa(e){let t=[];for(let n of e.querySelectorAll(`img`)){let e=n.getAttribute(`src`)??``;if(!fa(e))continue;let r=va(e,Br(ma(e)));n.replaceWith(r),t.push(r)}for(let n of e.querySelectorAll(`a`)){let e=n.getAttribute(`href`)??``;if(!fa(e))continue;let r=Br(ma(e))||n.textContent?.trim()||`file`,i=ra.has(la(r))?va(e,r):ya(e,r);n.replaceWith(i),t.push(i)}t.length&&ba(t)}var Sa=null,Ca=`max-w-full cursor-pointer break-words rounded-full border border-indigo-200 bg-indigo-50 px-2.5 py-0.5 text-left text-[12.5px] text-indigo-700 transition-colors hover:border-indigo-300 hover:bg-indigo-100`;function wa(){Sa=null}function Ta(e,t,n){if(Sa?.remove(),Sa=null,!t.length)return;let r=R(`div`,`mt-1.5 flex flex-wrap gap-1.5`);for(let e of t){let t=R(`button`,Ca,e);t.type=`button`,t.onclick=()=>{Sa===r&&(Sa=null),r.remove(),n(e)},r.append(t)}e.append(r),Sa=r}var Ea=8e3,Da=[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`],Oa=e=>typeof e==`string`&&Da.includes(e),ka,Aa;function ja(e,t){ka=e,Aa=t}var Ma=e=>e.slice(0,8),Na=e=>`system-card group relative mt-1.5 rounded-xl px-4 py-2.5 ${e}`,Pa=e=>R(`div`,Na(e));function Fa(e){let t=e.length>240||e.split(`
|
|
75
|
-
`).length>4,n=[`max-h-[4lh]`,`overflow-hidden`],r=R(`div`,`mt-1 whitespace-pre-wrap break-words text-[12.5px] leading-normal text-neutral-500 ${n.join(` `)}`,e),i=R(`button`,`mt-1 hidden w-fit rounded-md px-1 py-1 text-[11px] pointer-coarse:min-h-11 pointer-coarse:px-2 text-neutral-500 hover:bg-neutral-100 hover:text-neutral-700`,`Show full message`);return i.setAttribute(`type`,`button`),i.setAttribute(`aria-expanded`,`false`),i.onclick=()=>{let e=r.getBoundingClientRect().height;r.getAnimations().forEach(e=>e.cancel());let t=r.classList.toggle(n[0]),a=r.getBoundingClientRect().height,o=matchMedia(`(prefers-reduced-motion: reduce)`).matches;r.animate(o?[{opacity:.8},{opacity:1}]:[{maxHeight:`${e}px`,opacity:.8},{maxHeight:`${a}px`,opacity:1}],{duration:o?120:180,easing:`cubic-bezier(0.2, 0.8, 0.2, 1)`}),i.textContent=t?`Show full message`:`Collapse message`,i.setAttribute(`aria-expanded`,String(!t)),r.tabIndex=-1,r.focus({preventScroll:!0})},queueMicrotask(()=>{(r.clientHeight?r.scrollHeight>r.clientHeight+1:t)?i.classList.remove(`hidden`):r.classList.remove(...n)}),[r,i]}function Ia(e){let t=R(`div`,`flex flex-wrap items-center gap-x-2 gap-y-1 text-[11px] text-neutral-500`,e.glyph);t.append(R(`span`,`run-label flex-none font-semibold ${e.labelCls}`,e.label)),e.taskName&&t.append(R(`span`,`min-w-0 grow basis-0 truncate text-[12.5px] font-medium text-neutral-800 max-md:order-1 max-md:basis-full max-md:whitespace-normal max-md:line-clamp-2`,e.taskName));let n=R(`div`,`ml-auto flex min-w-0 flex-wrap items-center gap-x-2 font-mono`);if(e.note&&n.append(R(`span`,`flex-none`,e.note)),e.model){let t=R(`span`,`flex-none rounded bg-black/[0.05] px-1.5 py-px font-medium text-neutral-700 dark:bg-neutral-200`,e.model.id);t.title=`${e.model.provider} / ${e.model.id}`,n.append(t)}if(e.thinking){let t=R(`span`,`flex-none`,e.thinking);t.title=`Reasoning effort`,n.append(t)}let r=R(`button`,`flex-none hover:underline`,Ma(e.runId));if(r.title=`Run ${e.runId}`,r.onclick=()=>ka.showRun(e.runId),n.append(r),e.sessionId&&e.sessionId!==`console`){let t=e.sessionId,r=R(`button`,`flex-none text-indigo-600 hover:underline`,Ma(t));r.title=`Open session ${t}`,r.onclick=()=>ka.select(t),n.append(r)}return t.append(n),t}var La={queued:{edge:`border-l-amber-400`,label:`text-amber-700`,glyph:m},running:{edge:`border-l-fuchsia-500`,label:`text-fuchsia-700`,glyph:m},succeeded:{edge:`border-l-green-500`,label:`text-green-700`,glyph:o},failed:{edge:`border-l-red-500`,label:`text-red-600`,glyph:ve},cancelled:{edge:`border-l-neutral-300`,label:`text-neutral-500`,glyph:se},interrupted:{edge:`border-l-amber-400`,label:`text-amber-700`,glyph:le},skipped:{edge:`border-l-neutral-300`,label:`text-neutral-500`,glyph:se}},Ra=e=>g(La[e].glyph,`h-3 w-3 ${e===`queued`||e===`running`?`spinner`:``} ${La[e].label}`),za=new Map,Ba=new WeakMap;async function Va(e,t){let n=await ze(e,`POST`,t);n&&Aa.append(`error`,n)}function Ha(e){for(let[e,t]of za)t.isConnected||za.delete(e);let t=za.get(e.runId);t||(t=Pa(La[e.state].edge),t.dataset.kind=`background-run`,Aa.el.append(t),za.set(e.runId,t)),t.className=Na(La[e.state].edge);let n=e.state===`queued`||e.state===`running`;t.toggleAttribute(`data-active`,n);let r=`/api/task-runs/${e.runId}`,i=Math.max(0,Math.round(((e.finishedAt??Date.now())-(e.startedAt??e.queuedAt))/1e3)),a=Ia({glyph:Ra(e.state),label:`run · ${e.state}`,labelCls:La[e.state].label,taskName:e.taskName,note:`${e.sessionMode??`task`} · depth ${String(e.depth)} · ${String(i)}s`,runId:e.runId,sessionId:e.targetSessionId}),o=R(`div`,`flex flex-none items-center gap-2 text-[11px] font-semibold text-neutral-700`);if(n){let t=R(`button`,`hover:underline`,`Stop`);t.onclick=()=>{window.confirm(`Stop "${e.taskName}"?`)&&Va(`${r}/cancel`,`could not stop the run`)},o.append(t)}o.childElementCount&&a.append(o);let s=Ba.get(t);!s&&e.prompt!==null&&(s=Fa(e.prompt),Ba.set(t,s)),t.replaceChildren(a,...s??[]),Aa.scroll()}var B=null,Ua=null,Wa=null,Ga=!1;function Ka(){if(!Ua)return;Ua.text=Ua.text.slice(-4e3),Ua.pre.textContent=Ua.text;let e=Ua.text.split(`
|
|
76
|
-
`).filter(Boolean).pop()??`thinking…`,t=Ua.summary.lastElementChild;t.textContent=e.length>90?`…`+e.slice(-90):e}function qa(){if(Wa){Ga=!0;return}Ga=!1,Ka(),Wa=setTimeout(()=>{Wa=null,Ga&&qa()},80)}function Ja(){Wa&&clearTimeout(Wa),Wa=null,Ga&&Ka(),Ga=!1}var Ya=new WeakMap,Xa=e=>{let t=Ya.get(e)??[];return Ya.set(e,t),t};function Za(){B&&!B.toolRows.size&&fo(`done`)}var Qa=null;function $a(){B=null,Qa=null,Ua=null,Ja(),za.clear()}function eo(){let e=Qa;return!e||B?.el===e||(Qa=null,e!==Aa.el.lastElementChild)?null:(e.remove(),e.dataset.adopted=`1`,no(e,e.dataset.status),e)}var to={running:`text-green-700 open:bg-green-50`,done:`text-neutral-400 hover:text-neutral-600 open:bg-black/[0.02] open:text-neutral-500 dark:open:bg-neutral-100`,failed:`text-red-600 open:bg-red-50`,interrupted:`text-amber-700 open:bg-amber-50`};function no(e,t){e.dataset.status=t,e.className=`px-2 py-1 rounded-xl text-[11.5px] leading-normal open:border open:border-neutral-200 open:px-3 open:py-2 ${to[t]}`}var ro={failed:ve,interrupted:le};function io(e){return e===`running`?g(m,`spinner`):e===`done`?R(`span`,`hidden`):g(ro[e],`h-3 w-3`)}function ao(e){if(B)return B;let t=io(`running`),n=R(`span`,`min-w-0 truncate`,`working…`),{el:r}=Yr(``,[t,n]);r.dataset.kind=`activity`,no(r,`running`);let i=R(`div`,`mt-1.5 flex max-h-64 flex-col gap-1 overflow-y-auto overscroll-contain border-t border-black/5 pt-1.5 dark:border-neutral-200`);return r.append(i),co(r,i),Aa.el.append(r),Qa=r,Aa.scroll(),B={el:r,statusIcon:t,headline:n,rowsEl:i,toolRows:new Map,thinking:null,steps:0,failedSteps:0,startTs:e,sawError:!1},B}function oo(e,t=``){let n=ao(e);Ja(),n.thinking=null;let r=R(`div`,`whitespace-pre-wrap break-words text-[13px] text-neutral-600`,t);r.dataset.raw=t;let i=R(`div`,`rounded-lg bg-neutral-50 px-2 py-1.5`,R(`span`,`text-[10px] font-medium text-neutral-400`,`Update`),r);return i.dataset.kind=`progress`,n.rowsEl.append(i),uo(n,`running`,`writing…`),lo(n),Aa.scroll(),r}function so(e){let t=e.closest(`details[data-kind="activity"]`);e.parentElement?.remove(),t&&!t.lastElementChild?.childElementCount&&(B?.el===t&&(B=null),Qa===t&&(Qa=null),t.remove())}function co(e,t){t.dataset.follow=`1`,t.addEventListener(`scroll`,()=>{let e=t.scrollHeight-t.scrollTop-t.clientHeight<24;t.dataset.follow=e?`1`:``}),e.addEventListener(`toggle`,()=>{e.open&&(t.scrollTop=t.scrollHeight,t.dataset.follow=`1`)})}function lo(e){Aa.bulk()||!e.el.open||!e.rowsEl.dataset.follow||(e.rowsEl.scrollTop=e.rowsEl.scrollHeight)}function uo(e,t,n){let r=Math.max(1,Math.round((Date.now()-e.startTs)/1e3)),i=`${e.steps?`${e.steps} step${e.steps===1?``:`s`}`:`Progress`} · ${r}s`;e.headline.textContent=t===`running`&&n?`${i} · ${n}`:t===`done`?`Completed · ${i}`:`${i} · ${t}`,no(e.el,t);let a=io(t);e.statusIcon.replaceWith(a),e.statusIcon=a}function fo(e){if(!B)return;Ja();for(let{statusEl:e}of B.toolRows.values())e.textContent===`running…`&&(e.textContent=`interrupted`);let t=B.steps>0&&B.failedSteps===B.steps;uo(B,(B.sawError||t)&&e===`done`?`failed`:e===`done`&&B.toolRows.size?`interrupted`:e),B=null}function po(){B&&(B.sawError=!0)}function mo(e){let t=e.slice(0,400).replace(/\s+/g,` `);return t.length>100?t.slice(0,100)+`…`:t}function ho(e,t,n,r){let i=ao(e);i.steps+=1,Ja(),i.thinking=null;let a=JSON.stringify(r,null,2)??``,o=R(`span`,`ml-auto flex-none text-neutral-400`,`running…`),s=R(`span`,`min-w-0 truncate text-neutral-500`,mo(a)),{el:c}=Yr(`rounded-md px-1 py-0.5 font-mono text-[12.5px] hover:bg-black/[0.03] dark:hover:bg-neutral-100`,[R(`span`,`flex-none font-semibold`,n),s,o]),l=R(`pre`,`max-h-40 overflow-y-auto whitespace-pre-wrap break-words rounded bg-black/[0.04] p-1.5 text-[12px] dark:bg-neutral-100`,a),u=R(`pre`,`hidden max-h-56 overflow-y-auto whitespace-pre-wrap break-words rounded bg-black/[0.04] p-1.5 text-[12px] dark:bg-neutral-100`);c.append(R(`div`,`mt-1 flex flex-col gap-1 pl-4`,l,u)),Xa(i.el).push({tool:n,call:t,preview:s,argsPre:l,outputPre:u}),i.toolRows.set(t,{el:c,statusEl:o,outputPre:u}),i.rowsEl.append(c),lo(i),uo(i,`running`,n),Aa.scroll()}function go(e,t,n){let r=B;if(!r)return;let i=r.toolRows.get(e);r.toolRows.delete(e),i&&(i.statusEl.textContent=t?`failed`:`ok`,i.statusEl.className=`ml-auto flex-none ${t?`text-red-600`:`text-green-700`}`,i.el.classList.toggle(`bg-red-50`,t),i.el.classList.toggle(`text-red-700`,t),n&&(i.outputPre.textContent=n.length>8e3?n.slice(0,Ea)+`…`:n,i.outputPre.classList.remove(`hidden`)),t&&(r.failedSteps+=1)),uo(r,`running`)}function _o(e,t){let n=ao(e);if(!n.thinking){Ja();let{el:e,summary:t}=Yr(`rounded-md px-1 py-0.5 text-[12.5px] italic text-neutral-500 hover:bg-black/[0.03] dark:hover:bg-neutral-100`,[R(`span`,`min-w-0 truncate`,`thinking…`)]),r=R(`div`,`mt-1 max-h-56 overflow-y-auto whitespace-pre-wrap break-words pl-4 not-italic text-neutral-500`,``);e.append(r),n.rowsEl.append(e),n.thinking={pre:r,summary:t,text:``},Ua=n.thinking,lo(n),uo(n,`running`,`thinking…`)}n.thinking.text+=t,qa()}var vo=0;function yo(e,t=0,n=!1,r){let i=Date.now()-t,a=ao(i).el;for(let t of e){if(t.kind===`progress`){oo(i,t.text??``);continue}if(t.kind===`thinking`){_o(i,t.text??``);continue}let e=t.id??`replay-${++vo}`;ho(i,e,t.toolName??``,t.args),t.done&&go(e,t.isError??!1,t.output??``)}r!==void 0&&e.some(e=>e.kind===`tool`&&e.args===void 0)&&bo(a,r),!n&&fo(e.some(e=>e.kind===`tool`&&!e.done)?`interrupted`:`done`)}function bo(e,t){let n=()=>{e.open&&(e.removeEventListener(`toggle`,n),xo(e,t))};e.addEventListener(`toggle`,n)}async function xo(e,t){let n=ka.sessionId(),r=Xa(e),i=new Set(r.filter(e=>!e.argsPre.textContent)),a=e=>{for(let t of i)t.argsPre.textContent=e};if(a(`loading…`),!n)return a(`no session`);let o=await Le(`/api/sessions/${n}/turns/${t}/steps`,`could not load these steps`);if(!o.ok)return a(o.error);let s=o.value.steps.filter(e=>e.kind===`tool`);for(let[e,t]of r.entries()){if(!i.has(t))continue;let n=s[e];if(!(n&&(n.id?n.id===t.call:n.toolName===t.tool))){t.argsPre.textContent=`detail no longer available — reload the session`;continue}let r=JSON.stringify(n.args,null,2)??``;t.argsPre.textContent=r,t.preview.textContent=mo(r),n.output&&(t.outputPre.textContent=n.output,t.outputPre.classList.remove(`hidden`))}}var So,V=L(`#turns`);function Co(e){So=e,ja(e,{el:V,append:H,scroll:jo,bulk:()=>wo})}var wo=!1,To=()=>V.scrollHeight-V.scrollTop-V.clientHeight<80,Eo=!0,Do=0;V.addEventListener(`scroll`,()=>{let e=V.scrollTop,t=e<Do-4;Do=e,!wo&&(t||To())&&(Eo=To())},{passive:!0});var Oo=0;function ko(){!Eo||wo||Oo||(Oo=requestAnimationFrame(()=>{Oo=0,Eo&&!wo&&(V.scrollTop=V.scrollHeight)}))}new ResizeObserver(ko).observe(V),V.addEventListener(`load`,ko,!0),new MutationObserver(ko).observe(V,{childList:!0,subtree:!0,characterData:!0});function Ao(){To()&&(Eo=!0)}function jo(e=!1){wo||(e&&(Eo=!0),Eo&&(V.scrollTop=V.scrollHeight))}var Mo=1200;function No(e,t){let n=V.querySelector(`[data-kind="${e}"][data-at="${t}"]`);return n?(Fo(n),!0):!1}function Po(){let e=V.querySelectorAll(`[data-kind="background-run"][data-active]`),t=e[e.length-1];return t?(Fo(t),!0):!1}function Fo(e){Eo=!1,e.scrollIntoView({block:e.offsetHeight>V.clientHeight?`start`:`center`}),e.dataset.reveal=``,setTimeout(()=>delete e.dataset.reveal,Mo)}var Io=500,Lo=0,Ro=0,zo=null;function Bo(){for(;V.childElementCount>Io;){let e=V.firstElementChild;e.remove(),e!==zo&&(e.dataset.kind===`user`&&Lo++,Ro++)}Ro&&(zo||(zo=R(`div`,`px-5 py-2 text-center text-[11.5px] italic text-neutral-400`),zo.dataset.kind=`trim`),zo.textContent=`${Ro} earlier row${Ro===1?``:`s`} not shown — still in the transcript, not on this screen`,V.firstElementChild!==zo&&V.prepend(zo))}var Vo={user:{row:``,body:`text-inherit`},assistant:{row:``,body:`text-neutral-900`},error:{row:`border-l-red-400 bg-red-50`,body:`text-red-700`},system:{row:`system-card border-l-cyan-500`,body:`text-neutral-500`}};function H(e,t,n=!1,r){Za();let i=e===`assistant`?eo():null,a=Vo[e],o=e===`user`&&r!==void 0&&ns(r)?r:void 0,s=o===void 0&&V.lastElementChild?.dataset.kind===e,c=R(`div`,`group relative ${a.row}`);c.dataset.kind=e,s&&(c.dataset.grouped=``),wo||(c.dataset.enter=``);let l=e===`user`?Ci(t):null,u=l?.text??t,d=e===`user`?Me(u):null,ee=d?.id||d?.when?d:null,f=ee?.id&&ee.id!==`web`?ee:null,p=R(`div`,`whitespace-pre-wrap break-words ${a.body}`,ee?.text??u);(l?.paths.length||ee)&&(p.dataset.raw=t),n&&os(p,t),r!==void 0&&rs(c,r),f&&c.append(Ho(f)),c.append(p);let te=So.sessionId();if(l?.paths.length&&te){let e=ta(c);for(let t of l.paths)e.append(pa(te,t))}if(e===`user`){Ko?.(),V.querySelector(`.message-edit`)?.remove();let e=R(`button`,`message-edit absolute right-full top-1 flex h-8 w-8 items-center justify-center rounded-full`);e.title=`Edit latest message — resends it and replaces the reply`,e.setAttribute(`type`,`button`),e.setAttribute(`aria-label`,`Edit message`),e.append(g(ue)),e.onclick=()=>Jo(c,p),c.append(e)}if(o!==void 0){let e=R(`div`,`my-3 text-center text-[11px] text-neutral-400`);e.dataset.kind=`time`,e.dataset.at=String(o),$o(e),Qo??=setInterval(es,6e4),e.title=Hr(o),V.append(e)}return i&&V.append(i),V.append(c),Bo(),jo(),p}function Ho(e){let t=R(`div`,`mb-1 flex flex-wrap items-baseline gap-x-2 gap-y-1 text-[11.5px] leading-tight opacity-85`),n=e?.name??e?.id;if(n){let r=R(`span`,`font-semibold text-inherit`,n);e?.id&&(r.title=e.id),t.append(r)}return t}var Uo={"task-delegation":[i,`delegated`,`text-cyan-700`],"task-callback":[ee,`callback`,`text-cyan-700`],decision:[u,`decision needed`,`text-amber-700`]};function Wo(e){let t=e.indexOf(`
|
|
77
|
-
|
|
78
|
-
`);if(t<0)return[null,e];let n=e.slice(0,t);return n.length>600||n.split(`
|
|
79
|
-
`).length>6?[null,e]:[n,e.slice(t+2)]}function Go(e,t){let n=t.kind===`task-message`?t.messageKind:t.kind,[r,i,a]=Uo[n]??[ee,n.replace(`_`,` `),`text-cyan-700`];Za();let o=t.kind===`task-callback`?t.state:void 0,s=Pa(o?La[o].edge:n===`decision`?`border-l-amber-400`:`border-l-cyan-500`);s.dataset.kind=`system`;let[c,l]=Wo(e),u=Ia({glyph:o?Ra(o):g(r,`h-3 w-3 ${a}`),label:o?`${i} \u00b7 ${o}`:i,labelCls:o?La[o].label:a,...t.source?{taskName:t.source.taskName,model:t.source.model,thinking:t.source.thinking}:c?{taskName:c.split(`
|
|
80
|
-
`)[0]}:{},runId:t.runId,sessionId:t.sourceSessionId});s.append(u),s.append(...Fa(l)),V.append(s),Bo(),jo()}var Ko=null,qo=e=>e.isConnected&&V.querySelector(`.message-edit`)?.parentElement===e;function Jo(e,t){if(!qo(e))return;if(So.sessionState()!==`idle`){H(`error`,`can't edit while streaming — stop the turn first`);return}if(e.querySelector(`textarea`))return;let n=document.createElement(`textarea`);n.value=t.dataset.raw??t.textContent??``,n.className=`block w-full resize-none rounded-xl border border-indigo-300 bg-white px-3 py-2 text-neutral-900 focus:outline-none`,n.setAttribute(`aria-label`,`Edit latest message`);let r=Xr(`Send edit`,!0),i=Xr(`Cancel`),a=R(`div`,`message-editor`,n,R(`div`,`mt-2 flex flex-wrap justify-end gap-2`,i,r)),o=()=>{n.style.height=`auto`,n.style.height=`${Math.min(n.scrollHeight,192)}px`,r.disabled=!n.value.trim()};n.oninput=o,e.dataset.editing=``,t.classList.add(`hidden`),t.after(a),o(),n.focus(),n.setSelectionRange(n.value.length,n.value.length);let s=()=>{a.remove(),t.classList.remove(`hidden`),delete e.dataset.editing,Ko=null};Ko=s,i.onclick=()=>{s(),e.querySelector(`.message-edit`)?.focus({preventScroll:!0})},r.onclick=()=>{let t=n.value.trim();t&&Yo(e,t)},a.onkeydown=e=>{e.isComposing||e.keyCode===229||(e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),i.click()),e.key===`Enter`&&!e.shiftKey&&e.target===n&&(e.preventDefault(),r.click()))}}async function Yo(e,t){let n=So.sessionId();if(!n||!qo(e))return;if(So.sessionState()!==`idle`){H(`error`,`can't edit while streaming — stop the turn first`);return}Ko?.();let r=[...V.querySelectorAll(`[data-kind="user"]`)],i=Lo+r.indexOf(e),a=r[r.length-2]?.dataset.at;Zo=a===void 0?null:Number(a);let o=e.previousElementSibling;for(o?.dataset.kind===`time`&&o.remove();e.nextElementSibling;)e.nextElementSibling.remove();e.remove(),So.ownTurn(t),H(`user`,t,!1,Date.now()),jo(!0);let s=await b(`/api/sessions/${n}/turns/${i}/edit`,{text:t});if(!s.ok){let e=await x(s,`edit failed`);await So.reload(n),H(`error`,e)}}var Xo=6e5,Zo=null,Qo;function $o(e){let t=Number(e.dataset.at);e.textContent=`${Hr(t).slice(0,16)} · ${zr(t)}`}function es(){let e=V.querySelectorAll(`[data-kind="time"]`);for(let t of e)$o(t);e.length||(clearInterval(Qo),Qo=void 0)}var ts=(e,t)=>new Date(e).toDateString()===new Date(t).toDateString();function ns(e){let t=Zo;return Zo=e,t===null||e-t>=Xo||!ts(t,e)}function rs(e,t){e.dataset.at=String(t),e.dataset.time=Hr(t).slice(11)}function is(e){for(let t of e.querySelectorAll(`pre`)){let e=t.querySelector(`code`);if(!e)continue;let n=R(`div`,`group/code relative`);t.replaceWith(n),n.append(t,Jr(`absolute right-1.5 top-1.5 cursor-pointer rounded border border-black/[0.08] bg-white/85 px-1.5 py-0.5 text-[11px] text-neutral-500 opacity-0 transition-opacity hover:bg-white hover:text-neutral-800 focus:opacity-100 group-hover/code:opacity-100 pointer-coarse:opacity-100 dark:border-neutral-200`,()=>e.textContent??``))}}function as(e){let t=So.sessionId(),n=R(`div`,``);return n.innerHTML=an.sanitize(I.parse(t?da(e,t):e,{async:!1})),Kr(n),n}function os(e,t){e.replaceChildren(...as(t).childNodes),e.classList.remove(`whitespace-pre-wrap`),e.classList.add(`md`),ji(e),is(e),xa(e)}function ss(e,t,n,r=!1){let{text:i,suggestions:a}=ke(t);return _({text:i,suggestions:a})?cs(e,Oe(t)):os(e,i),r&&Ta(e.parentElement??e,a,e=>So.send(`auto`,e)),n&&rs(e.parentElement??e,n.completedAt),e}function cs(e,t){e.classList.remove(`md`,`whitespace-pre-wrap`),e.replaceChildren(R(`span`,`text-[12.5px] italic text-neutral-400`,t?`Stayed silent — ${t}`:`Stayed silent.`))}var ls=(e,t,n=!1)=>ss(H(`assistant`,``),e,t,n),U=null,us=null,ds=!1,fs=0,ps=0;function ms(e){let t=e.dataset.raw??``;for(;e.childNodes.length>ps;)e.lastChild.remove();let n=je(t,fs);n>fs&&(e.append(...as(Ae(t.slice(fs,n))).childNodes),fs=n,ps=e.childNodes.length),e.append(...as(ke(t.slice(fs)).text).childNodes),e.classList.remove(`whitespace-pre-wrap`),e.classList.add(`md`)}function hs(){if(us){ds=!0;return}ds=!1,U&&(ms(U),jo()),us=setTimeout(()=>{us=null,ds&&hs()},80)}function gs(){us&&clearTimeout(us),us=null,ds=!1}function _s(e){U||(U=oo(Date.now()),fs=0,ps=0),U.dataset.raw=(U.dataset.raw??``)+e,hs()}function vs(){if(!U)return;let e=U;U=null,gs(),e.classList.remove(`md`),e.classList.add(`whitespace-pre-wrap`),e.textContent=e.dataset.raw??``}function ys(){if(!U)return;let e=U.dataset.raw;return so(U),U=null,gs(),e}function bs(e,t){e===``&&vs();let n=ys();fo(`done`);let r=e??n;r&&ls(r,t,!0)}function xs(){let e=ys();fo(`interrupted`),e&&ls(e)}function Ss(){Ko?.(),clearInterval(Qo),Qo=void 0,V.replaceChildren(),Lo=0,Ro=0,zo=null,Zo=null,U=null,gs(),$a(),wa()}function Cs(e){if(!e){V.querySelector(`[data-kind="loading"]`)?.remove();return}let t=R(`div`,`flex flex-col gap-3 px-5 py-4`);t.dataset.kind=`loading`;for(let e of[`w-2/5`,`w-4/5`,`w-3/5`,`w-1/3`,`w-2/3`])t.append(R(`div`,`skeleton h-3.5 ${e}`));V.append(t)}function ws(e,t,n){Cs(!1);let r=new Map(n.map(e=>[e.runId,e])),i=e=>[...r].filter(([,t])=>t.queuedAt<=e).map(([e])=>e),a=e=>{for(let t of e){let e=r.get(t);e&&(Ha(e),r.delete(t))}},o=e.reduce((e,t,n)=>t.role===`assistant`?n:e,-1);wo=!0;try{for(let[n,r]of e.entries()){let s=t===`streaming`&&n===e.length-1&&r.role===`assistant`,c=r.steps;if(c?.length&&(yo(c,r.meta?.durationMs,s,n),r.meta&&a(i(r.meta.completedAt))),r.text){if(r.role===`system`&&r.origin){a(r.origin.kind===`task-message`?[r.origin.runId]:r.origin.runIds??[r.origin.runId]),Go(r.text,r.origin);continue}s?_s(r.text):r.role===`assistant`?ls(r.text,r.meta,t===`idle`&&n===o):H(r.role,r.text,!1,r.at)}}for(let e of r.values())Ha(e)}finally{wo=!1}jo(!0)}var Ts=window.fetch.bind(window),Es=20,Ds=6e4,Os=[],ks=new Map,As=e=>e instanceof Error?e.stack??`${e.name}: ${e.message}`:void 0;function js(e,t){let n=t===void 0?e:`${e}: ${String(t)}`,r=Date.now();return r-(ks.get(n)??-6e4)<Ds||(ks.size>100&&ks.clear(),ks.set(n,r),Os=Os.filter(e=>r-e<6e4),Os.length>=Es)?null:(Os.push(r),Ts(`/api/client-log`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({message:n,stack:As(t),view:location.hash||`/`}),keepalive:!0}).catch(()=>{}),H(`error`,n))}function Ms(){window.__pierReporting=!0,window.addEventListener(`error`,e=>{!e.error&&e.message.includes(`ResizeObserver loop`)||js(`script error: ${e.message}`,e.error)}),window.addEventListener(`unhandledrejection`,e=>{js(`unhandled rejection`,e.reason)})}var Ns=window.fetch.bind(window),Ps=()=>{location.assign(`/login?next=${encodeURIComponent(location.pathname+location.hash)}`)};function Fs(){window.fetch=async(...e)=>{let t=await Ns(...e);return t.status===401&&Ps(),t}}function Is(e,t){if(e.readyState!==EventSource.CLOSED)return;let n=()=>{let e=js(`${t} stream disconnected`);if(!e)return;let n=Xr(`Reload`);n.classList.add(`ml-2`,`align-middle`),n.onclick=()=>location.reload(),e.append(` `,n)};Ns(`/api/sessions`).then(e=>e.status===401?Ps():n(),n)}var Ls=/Mac|iP(?:hone|ad|od)/.test(navigator.userAgent),Rs=Ls?`⌘`:`Ctrl+`,zs=Ls?`⇧`:`Shift+`,Bs=e=>{let t=e.startsWith(`meta+`),n=t?e.slice(5):e;return n.startsWith(`shift+`)?{key:n.slice(6),shift:!0,meta:t}:{key:n,shift:!1,meta:t}};function Vs(e){let{key:t,shift:n,meta:r}=Bs(e);return`${r?`⌘`:Rs}${n?zs:``}${t.toUpperCase()}`}var Hs=()=>document.querySelector(`dialog[open]`)!==null,Us={"[":`{`,"]":`}`},Ws=`pointer-events-none fixed z-50 flex items-center gap-2 whitespace-nowrap rounded-md bg-neutral-800 px-2 py-1 text-[11.5px] text-neutral-100 shadow-lg`;function Gs(e,t,n){e.removeAttribute(`title`);let r=null,i=()=>{r?.remove(),r=null,document.removeEventListener(`keydown`,i,!0)};e.addEventListener(`pointerenter`,a=>{if(a.pointerType!==`mouse`)return;i(),r=R(`div`,Ws,t,R(`kbd`,`rounded bg-white/15 px-1 py-px font-sans text-[10.5px]`,n)),document.body.append(r);let o=e.getBoundingClientRect(),s=o.bottom+6,c=s+r.offsetHeight+8<=window.innerHeight;r.style.top=`${c?s:Math.max(8,o.top-r.offsetHeight-6)}px`,r.style.left=`${Math.max(8,Math.min(o.left,window.innerWidth-r.offsetWidth-8))}px`,document.addEventListener(`keydown`,i,!0)}),e.addEventListener(`pointerleave`,i),e.addEventListener(`pointerdown`,i)}function Ks(e,t,n,r,i){Gs(e,n,Vs(t)),Xs(t,r,i)}function qs(e,t,n,r){Gs(e,t,`Esc`),document.addEventListener(`keydown`,e=>{e.key!==`Escape`||e.isComposing||e.defaultPrevented||Hs()||!r()||(e.preventDefault(),n())})}var Js=`input, textarea, select, [contenteditable]`;function Ys(e,t,n,r,i){Gs(e,n,t[0].toUpperCase()),document.addEventListener(`keydown`,e=>{e.metaKey||e.ctrlKey||e.altKey||e.isComposing||e.defaultPrevented||!e.key||!t.includes(e.key.toLowerCase())||e.target?.closest?.(Js)||Hs()||!i()||(e.preventDefault(),r())})}function Xs(e,t,n){let{key:r,shift:i,meta:a}=Bs(e),o=Us[r];document.addEventListener(`keydown`,e=>{if(!e.key||e.altKey||e.shiftKey!==i)return;let s=e.key.toLowerCase();(s===r||s===o)&&((a?!e.metaKey:!e.metaKey&&!e.ctrlKey)||n?.()||(e.preventDefault(),e.stopPropagation(),t()))},!0)}var W,Zs=L(`#composer`),G=L(`#input`),Qs=L(`#send`),$s=L(`#send-arrow`),ec=L(`#send-queue`),tc=L(`#stop`),nc=L(`#queue-panel`),rc=L(`#queue-rows`),ic=L(`#queue-label`),ac=R(`div`,`hidden max-h-48 overflow-y-auto border-t border-neutral-200 px-4 py-2 text-[13px]`);ac.id=`recovery-panel`,nc.after(ac);var oc=L(`#image-strip`),sc=L(`#attach-input`),cc=!1,lc=0,uc=new Set,dc=[],fc=[];function pc(){let e=window.visualViewport;if(!e)return;let t=()=>{let t=e.scale<=1.05&&window.innerHeight-e.height-e.offsetTop>80;t?document.body.dataset.kb=``:delete document.body.dataset.kb,document.body.style.height=t?`${String(e.height)}px`:``,t&&window.scrollY&&window.scrollTo(0,0)};e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t)}function mc(){let e=Zs.parentElement,t=[nc,ac,Zs],n=new ResizeObserver(()=>{let n=t.reduce((e,t)=>e+t.offsetHeight,0);e.style.setProperty(`--dock-h`,`${String(n)}px`)});for(let e of t)n.observe(e,{box:`border-box`})}function hc(){G.focus()}function gc(e){let t=fc.indexOf(e);return t<0?!1:(fc.splice(t,1),!0)}function _c(e){fc.push(e)}function vc(){fc=[]}function yc(){let e=W.sessionState()===`streaming`,t=W.sessionId()!==null,n=W.starting();Qs.disabled=!t,Qs.className=`flex h-7 w-7 flex-none items-center justify-center rounded-lg ${t?e?`cursor-pointer bg-amber-100 text-amber-700 hover:bg-amber-200 active:bg-amber-300`:`cursor-pointer bg-indigo-600 text-white hover:bg-indigo-500 active:bg-indigo-700 dark:text-neutral-50`:`cursor-default bg-neutral-100 text-neutral-400`}`,Qs.title=t?e?`Queue — delivered when the turn ends`:`Send`:n?`Starting the session…`:`No session`,G.placeholder=n?`Starting the session…`:`Message…`,$s.classList.toggle(`hidden`,e),ec.classList.toggle(`hidden`,!e),tc.classList.toggle(`hidden`,!e),tc.classList.toggle(`flex`,e)}function bc(){let e=W.chatVisible()&&cc;nc.classList.toggle(`hidden`,!e),nc.classList.toggle(`flex`,e),ac.classList.toggle(`hidden`,!W.chatVisible()||!ac.childElementCount)}function xc(e,t=!1){let n=W.sessionId();if(ac.replaceChildren(...e.map(e=>{let t=R(`details`,`py-1`),r=e.status===`submitting`?`Handing off`:e.status===`not-submitted`?`Not submitted`:`Acceptance unknown`,i=e.status===`submitting`?``:`; automatic queue paused`;t.append(R(`summary`,`cursor-pointer break-words text-amber-700`,`Queue recovery: ${r}${i} (in memory)`));for(let n of[...e.steering,...e.followUp]){let e=R(`div`,`flex items-start gap-2 border-t border-neutral-100 py-1`);e.append(R(`span`,`min-w-0 flex-1 whitespace-pre-wrap break-words`,n),Jr(`flex-none cursor-pointer px-1 text-neutral-500 hover:text-neutral-800`,()=>n)),t.append(e)}e.error&&t.append(R(`div`,`break-words text-red-600`,e.error));let a=R(`button`,`cursor-pointer py-1 text-neutral-500 disabled:cursor-default disabled:opacity-40`,`Acknowledge`);return a.type=`button`,a.disabled=e.status===`submitting`,a.title=`Remove this recovery copy without sending it`,a.onclick=async()=>{if(!n||!confirm(`Remove this recovery copy? This does not resend the messages.`))return;let t=await b(`/api/sessions/${n}/queue/recovery/${e.id}/ack`,{}),r=t.ok?null:await x(t,`Could not acknowledge queue recovery`);W.sessionId()===n&&(r===null?await W.reload(n):H(`error`,r))},t.append(a),t})),t){let e=R(`div`,`flex flex-wrap items-center gap-x-2 py-1 text-amber-700`,`Automatic queue paused: acceptance unknown (in memory)`),t=R(`button`,`cursor-pointer underline`,`Recall queue`);t.title=`Clear the live queue and return its messages to the composer`,t.onclick=()=>void Rc(),e.append(t),ac.prepend(e)}bc()}function Sc(e,t){++lc;let n=[...e.map(e=>({mode:`steer`,text:e})),...t.map(e=>({mode:`queued`,text:e}))];cc=n.length>0,ic.textContent=n.length>1?`Queued · ${n.length}`:`Queued`,bc(),rc.replaceChildren(...n.map(e=>{let t=R(`li`,`flex items-start gap-2 text-[13px] leading-[18px]`);return e.mode===`steer`&&t.append(R(`span`,`flex-none rounded bg-indigo-100 px-1 py-0.5 text-[10.5px] font-semibold uppercase tracking-wide text-indigo-700`,e.mode)),t.append(R(`span`,`min-w-0 whitespace-pre-wrap break-words text-neutral-700`,e.text)),t}))}var Cc=8;function wc(){let e=W.sessionId();e&&dc.length?jc.set(e,dc):e&&jc.delete(e),oc.classList.toggle(`hidden`,dc.length===0),oc.classList.toggle(`flex`,dc.length>0),oc.replaceChildren(...dc.map((e,t)=>{let n=e.mimeType.startsWith(`image/`)?na(`data:${e.mimeType};base64,${e.data}`):R(`span`,`flex h-16 max-w-40 items-center truncate rounded-md border border-neutral-200 bg-neutral-50 px-2 text-[12px] text-neutral-700`,e.name??`file`),r=R(`button`,`absolute -right-1.5 -top-1.5 flex h-4 w-4 cursor-pointer items-center justify-center rounded-full bg-neutral-700 text-[10px] leading-none text-white hover:bg-red-600`,g(ve,`h-3 w-3`));return r.setAttribute(`type`,`button`),r.setAttribute(`aria-label`,`Remove ${e.name??`attachment`}`),r.onclick=()=>{dc.splice(t,1),wc()},R(`div`,`relative`,n,r)}))}function Tc(e){if(dc.length>=Cc){H(`error`,`attachment limit is ${Cc} files per message`);return}if(e.size>33554432){H(`error`,`${e.name||`file`} is too large (32MB max)`);return}let t=new FileReader;t.onload=()=>{let n=t.result;dc.push({data:n.slice(n.indexOf(`,`)+1),mimeType:e.type||`application/octet-stream`,name:e.name||void 0}),wc()},t.readAsDataURL(e)}async function Ec(e){let t=[];for(let n of e){let e=await b(`/api/inbox`,n);if(!e.ok)return null;let{path:r}=await e.json();t.push(vi(r))}return t}var Dc=`pier.draft.`,Oc=e=>`${Dc}${e}`,kc=0;function Ac(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n?.startsWith(Dc)&&e.push(n)}for(let t of e){let e=localStorage.getItem(t);e&&!sessionStorage.getItem(t)&&sessionStorage.setItem(t,e),localStorage.removeItem(t)}}catch(e){console.warn(`could not move older drafts out of localStorage`,e)}}var jc=new Map;function Mc(e=W.sessionId(),t=G.value){e&&(t?sessionStorage.setItem(Oc(e),t):sessionStorage.removeItem(Oc(e)))}function Nc(e){++kc,G.value=sessionStorage.getItem(Oc(e))??``,Pc(),dc=jc.get(e)??[],wc()}function Pc(){let e=G.style.height;G.style.height=`auto`;let t=`${Math.min(G.scrollHeight,192)}px`;G.style.height=t,t!==e&&jo()}var Fc=!1;async function Ic(e,t){let n=(t??G.value).trim(),r=t===void 0?dc:[],i=W.sessionId();if(!(!n&&r.length===0||!i)){if(t===void 0){if(Fc)return;Fc=!0,G.value=``,Pc(),Mc(),dc=[],wc()}try{let t=[];if(r.length){let e=await Ec(r);if(e===null){H(`error`,`attachment upload failed`),G.value=[n,G.value.trim()].filter(Boolean).join(`
|
|
81
|
-
`),Pc(),Mc(),dc=r,wc();return}t=e}let a=[n,...t].filter(Boolean).join(`
|
|
82
|
-
`),o=W.sessionState()===`idle`&&e===`auto`;o?W.setState(`streaming`):yc(),(o||e===`steer`)&&(_c(a),H(`user`,a,!1,Date.now()),jo(!0));let s=await b(`/api/sessions/${i}/messages`,{text:a,mode:e});if(!s.ok){let e=await x(s,`send failed`);await W.reload(i),H(`error`,e)}}finally{t===void 0&&(Fc=!1)}}}async function Lc(e){let t=W.sessionId();if(!t)return;Sc([],[]);let n=await b(`/api/sessions/${t}/queue/deliver`,{mode:e});if(!n.ok){let r=await x(n,`Queue ${e} failed`);await W.reload(t),W.sessionId()===t&&H(`error`,r)}}async function Rc(){let e=W.sessionId();if(!e||uc.has(e))return;uc.add(e);let t=lc,n=kc,r=document.activeElement;try{Mc();let i=await fetch(`/api/sessions/${e}/queue/recall`,{method:`POST`});if(!i.ok){let t=await x(i,`Could not recall queued messages`);W.sessionId()===e&&H(`error`,t);return}let{messages:a}=await i.json(),o=W.sessionId()===e;if(a.length)try{let t=o?G.value:sessionStorage.getItem(Oc(e))??``,i=(t?[t,...a]:a).join(`
|
|
83
|
-
`);o&&(G.value=i,Pc(),n===kc&&W.chatVisible()&&document.activeElement===r&&G.focus()),Mc(e,i)}catch(t){H(`error`,`Could not save recalled messages for session ${e}: ${String(t)}\nRecalled messages (not saved):\n${a.join(`
|
|
84
|
-
`)}`)}o&&t===lc&&Sc([],[])}finally{uc.delete(e)}}function zc(e){W=e,Ac(),pc(),mc();let t=()=>{let e=W.sessionId();e&&fetch(`/api/sessions/${e}/abort`,{method:`POST`})};tc.onclick=t,qs(tc,`Stop the running turn`,t,()=>W.sessionState()===`streaming`&&W.chatVisible()),L(`#queue-steer`).onclick=()=>void Lc(`steer`),L(`#queue-restart`).onclick=()=>void Lc(`restart`),L(`#queue-recall`).onclick=()=>void Rc(),Zs.onsubmit=e=>{e.preventDefault(),Ic(`auto`)},Ys(G,[`/`],`Write a message`,hc,W.chatVisible),G.onfocus=Ao,G.oninput=()=>{Pc(),Mc()};let n=!matchMedia(`(pointer: coarse)`).matches;G.onkeydown=e=>{e.isComposing||e.keyCode===229||n&&e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Ic(`auto`))},G.onpaste=e=>{for(let t of e.clipboardData?.items??[]){let e=t.kind===`file`?t.getAsFile():null;e&&Tc(e)}let t=e.clipboardData?.getData(`text/plain`)??``,n=t.trim();!n||n===t||(e.preventDefault(),G.setRangeText(n,G.selectionStart??0,G.selectionEnd??0,`end`),Pc(),Mc())},V.ondragover=e=>e.preventDefault(),V.ondrop=e=>{e.preventDefault();for(let t of e.dataTransfer?.files??[])Tc(t)},L(`#attach`).onclick=()=>sc.click(),sc.onchange=()=>{for(let e of sc.files??[])Tc(e);sc.value=``},yc()}var Bc=`pier.push`,Vc=`/sw.js`,Hc=()=>/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.maxTouchPoints>1&&/Macintosh/.test(navigator.userAgent),Uc=()=>matchMedia(`(display-mode: standalone)`).matches||navigator.standalone===!0;function Wc(){return window.isSecureContext?Hc()&&!Uc()?`On iPhone and iPad, notifications work only from the installed app: Share → Add to Home Screen, then open Pier from that icon.`:!(`serviceWorker`in navigator)||!(`PushManager`in window)||!(`Notification`in window)?`This browser has no Web Push support.`:``:`Notifications need HTTPS. Reach this Pier through its public URL, not over plain http.`}var Gc=[[/iPhone/,`iPhone`],[/iPad/,`iPad`],[/Android/,`Android`],[/Macintosh/,`Mac`],[/Windows/,`Windows`]],Kc=[[/Edg\//,`Edge`],[/Chrome\//,`Chrome`],[/Firefox\//,`Firefox`],[/Safari\//,`Safari`]];function qc(){let e=navigator.userAgent,t=(t,n)=>t.find(([t])=>t.test(e))?.[1]??n;return`${t(Gc,`Linux`)} · ${t(Kc,`browser`)}${Uc()?` (installed)`:``}`}var Jc=e=>{let t=atob(e.replace(/-/g,`+`).replace(/_/g,`/`)),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},Yc=null;async function Xc(){return!(`serviceWorker`in navigator)||!window.isSecureContext?null:(Yc??=await navigator.serviceWorker.register(Vc,{scope:`/`}).catch(e=>(console.warn(`service worker registration failed`,e),null)),Yc)}var Zc=(e,t)=>{let n=e?new Uint8Array(e):null;return n?.length===t.length&&n.every((e,n)=>e===t[n])};async function Qc(e){let{publicKey:t}=await Re(`/api/push`,`Could not read this instance's push key`),n=Jc(t),r=await e.pushManager.getSubscription();if(r){if(Zc(r.options.applicationServerKey,n))return r;await r.unsubscribe()}return e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:n})}async function $c(e){return b(`/api/push/subscribe`,{...e.toJSON(),label:qc()})}async function el(){rl();let e=await Xc();if(!(!e||localStorage.getItem(Bc)!==`on`)&&!(!(`Notification`in window)||Notification.permission!==`granted`))try{await $c(await Qc(e))}catch(e){console.warn(`re-registering this browser for notifications failed`,e)}}var tl=null,nl=null;function rl(){window.addEventListener(`beforeinstallprompt`,e=>{e.preventDefault(),tl=e,nl?.()}),window.addEventListener(`appinstalled`,()=>{tl=null,nl?.()})}function il(e){let t=navigator;(e>0?t.setAppBadge?.(e):t.clearAppBadge?.())?.catch(()=>{})}function al(){let e=R(`span`,`text-[11.5px]`,``),t=Xr(`Send a test notification`),n=R(`div`,`flex items-center gap-3`,t,e),r=R(`div`,`flex flex-col gap-4`),i=()=>localStorage.getItem(Bc)===`on`;async function a(){pi(e,`saving`,`asking this browser…`);let t=await Notification.requestPermission();if(t!==`granted`)return localStorage.setItem(Bc,`off`),c(),pi(e,`failed`,t===`denied`?`Notifications are blocked for this site — allow them in the browser's site settings, then try again.`:`No answer to the permission prompt.`);let n=await Xc();if(!n)return pi(e,`failed`,`This browser refused to register a service worker.`);try{let t=await $c(await Qc(n));if(!t.ok)return pi(e,`failed`,await x(t,`Could not register this browser`));localStorage.setItem(Bc,`on`),c(),pi(e,`saved`,`This browser will be notified when a turn finishes unseen.`)}catch(t){pi(e,`failed`,`Could not subscribe: ${String(t)}`)}}async function o(){localStorage.setItem(Bc,`off`),c();let t=await(await Xc())?.pushManager.getSubscription();t&&(await b(`/api/push/unsubscribe`,{endpoint:t.endpoint}),await t.unsubscribe()),pi(e,`idle`,`This browser will not be notified.`)}t.onclick=()=>{pi(e,`saving`,`sending…`),(async()=>{let t=await b(`/api/push/test`,{});if(!t.ok)return pi(e,`failed`,await x(t,`Could not send`));let{sent:n,failed:r}=await t.json();pi(e,r?`failed`:`saved`,`Handed ${String(n)} device(s) to their push service${r?`, ${String(r)} refused`:``}.`)})()};function s(){if(!tl)return[];let e=Xr(`Install Pier`,!0);return e.onclick=()=>{let e=tl;e&&e.prompt().then(()=>e.userChoice).finally(()=>{tl=null,c()})},[R(`div`,`flex items-center gap-3`,e,R(`span`,`text-[11.5px] leading-snug text-neutral-500`,`Its own window and icon — and where notifications look like an app's.`))]}function c(){let e=Wc();if(e){r.replaceChildren(...s(),R(`p`,`text-[12.5px] leading-snug text-neutral-500`,e));return}let c=i()&&Notification.permission===`granted`;t.disabled=!c,r.replaceChildren(...s(),di(`Notify this device`,`A turn that finishes while nobody is looking at it becomes a notification here. Per browser — each device is enabled on its own.`,c,e=>void(e?a():o())),n)}return nl=c,c(),ii(`Notifications`,`Web Push, so a finished turn reaches you with the workbench closed. Installed — Chrome's address-bar icon, or Share → Add to Home Screen on iOS — Pier notifies you the way an app does.`,r)}var K=null,ol=null,sl=null;function cl(e){K&&!K.contains(e.target)&&e.target!==sl&&q()}var ll={ArrowDown:1,ArrowUp:-1},ul={n:1,j:1,p:-1,k:-1},dl=()=>K!==null;function fl(e){if(!(e.altKey||e.metaKey||e.shiftKey||!e.key))return e.ctrlKey?ul[e.key.toLowerCase()]:ll[e.key]}function pl(e,t){let n=[...e.querySelectorAll(`button:not(:disabled)`)];if(!n.length)return!1;let r=n.indexOf(document.activeElement);return n[t===`first`?0:t===`last`?n.length-1:r<0?t>0?0:n.length-1:(r+t+n.length)%n.length]?.focus(),!0}function ml(e){if(e.dataset.menu===`true`)return{rows:e,ends:!0};let t=e.querySelector(`[data-list]`);return t?{rows:t,ends:!1}:null}function hl(e){let t=K?ml(K):null;if(t){let n=(t.ends?e.key===`Home`?`first`:e.key===`End`?`last`:void 0:void 0)??fl(e);if(n!==void 0&&pl(t.rows,n)){e.preventDefault();return}}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),q())}function gl(e){K&&!K.contains(e.target)&&q()}function q(){if(!K)return;document.removeEventListener(`pointerdown`,cl,!0),document.removeEventListener(`focusin`,cl,!0),document.removeEventListener(`keydown`,hl,!0),window.removeEventListener(`scroll`,gl,!0),window.removeEventListener(`resize`,q);let e=K;K=null,sl?.remove(),sl=null,e.contains(document.activeElement)&&ol?.focus({preventScroll:!0}),ol?.removeAttribute(`aria-expanded`),ol=null,e.inert=!0,e.dataset.closing=``,Promise.allSettled(e.getAnimations().map(e=>e.finished)).then(()=>e.remove())}var _l=null;function vl(e){let t=e.getBoundingClientRect(),n={top:t.bottom+4,left:t.left};return t.width||t.height?n:_l?.anchor===e?{top:_l.top,left:_l.left}:n}var yl=()=>window.innerWidth<640;function bl(e,t){q(),document.querySelectorAll(`.glass-menu[data-closing]`).forEach(e=>e.remove());let n=yl();K=R(`div`,`glass-menu fixed z-50 border border-neutral-200 p-2 font-sans leading-6 ${n?`rounded-3xl inset-x-2 bottom-2 max-h-[70dvh] overflow-y-auto pb-[calc(0.25rem+env(safe-area-inset-bottom))] text-[16px]`:`rounded-2xl min-w-60 max-w-[min(42rem,calc(100vw-1rem))] max-h-[calc(100dvh-1rem)] overflow-y-auto text-[15px]`}`),K.dataset.presentation=n?`sheet`:`popover`,K.append(t);let r=e.closest(`dialog[open]`)??document.body;if(n&&(sl=R(`div`,`fixed inset-0 z-50 bg-black/15`),sl.onclick=e=>{e.stopPropagation(),q()},r.append(sl)),r.append(K),!n){let t=vl(e);_l={anchor:e,...t},K.style.top=`${Math.max(8,Math.min(t.top,window.innerHeight-K.offsetHeight-8))}px`,K.style.left=`${Math.max(8,Math.min(t.left,window.innerWidth-K.offsetWidth-8))}px`}ol=e,ol.setAttribute(`aria-expanded`,`true`),K.tabIndex=-1,(K.querySelector(`button, input, select, [tabindex='0']`)??K).focus({preventScroll:!0}),document.addEventListener(`pointerdown`,cl,!0),document.addEventListener(`focusin`,cl,!0),document.addEventListener(`keydown`,hl,!0),window.addEventListener(`scroll`,gl,!0),window.addEventListener(`resize`,q)}function xl(e){let t=R(`button`,`flex w-full cursor-pointer items-center gap-2 rounded-xl px-3 text-left transition-colors hover:bg-indigo-50 hover:text-indigo-700 active:bg-indigo-100 ${yl()?`min-h-12 py-3`:`min-h-10 py-2`}`,...e.checked===void 0?[]:[g(o,`h-3 w-3 text-indigo-600 ${e.checked?``:`invisible`}`)],R(`span`,`min-w-0 truncate`,e.label));if(e.hint){let n=R(`span`,`ml-auto max-w-28 shrink-[999] truncate text-[13px] text-neutral-500`,e.hint);n.title=e.hint,t.append(n)}return t.onclick=()=>e.onSelect(),t}function Sl(e,t,n){let r=R(`div`,``);if(n&&yl()){let e=R(`button`,`icon-btn h-11 w-11`,g(ve));e.setAttribute(`aria-label`,`Close session actions`),e.onclick=q,r.append(R(`div`,`flex items-center gap-3 border-b border-neutral-200 px-3 pb-1 mb-1`,R(`span`,`min-w-0 flex-1 truncate text-sm font-medium text-neutral-500`,n),e))}for(let e of t)e.separatorBefore&&r.append(R(`hr`,`my-2 border-neutral-200`)),r.append(xl(e));bl(e,r),K&&(K.dataset.menu=`true`,K.setAttribute(`aria-label`,n?`Actions for ${n}`:`Actions`),K.setAttribute(`role`,`group`))}var Cl=async e=>{let t=await Le(`/api/fs/ls${e?.startsWith(`/`)?`?path=${encodeURIComponent(e)}`:``}`,`Could not list directories`);return t.ok?t.value:null},wl=e=>e.entries.filter(e=>e.dir&&!e.name.startsWith(`.`)).map(e=>e.name),Tl=`flex w-full min-h-10 cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-left transition-colors hover:bg-indigo-50 hover:text-indigo-700 active:bg-indigo-100`,El=`font-mono text-[0.875rem]`,Dl=(e,t,n)=>{let r=Zr(e,`${Tl} ${t}`);return r.onclick=n,r};function Ol(e,t){let n=R(`div`,`mt-2 flex-none border-t border-neutral-200 pt-2`),r=Dl(`New folder`,`text-neutral-500`,()=>{let r=document.createElement(`input`);r.className=`w-full rounded-xl border-0 bg-neutral-100 px-3 py-2 ${El} focus:outline-none`,r.placeholder=`folder-name`;let i=R(`p`,`hidden px-3 pt-1 text-[0.8125rem] text-red-600`);r.onkeydown=async n=>{if(n.key!==`Enter`)return;n.preventDefault();let a=await b(`/api/fs/mkdir`,{path:e,name:r.value});if(!a.ok){i.textContent=(await a.json()).error??`could not create`,i.classList.remove(`hidden`);return}t((await a.json()).path)},n.replaceChildren(r,i),r.focus()});return r.prepend(g(de)),n.append(r),n}function kl(e,t,n){let r=e=>{n(e),q()};async function i(t){let n=await Cl(t);if(!n)return;let a=R(`div`,`flex max-h-[60dvh] w-full flex-col sm:w-88`),o=Zr(`Use`,`btn btn-primary ml-auto flex-none px-3 py-1 text-[0.8125rem]`);o.onclick=()=>r(n.path);let s=document.createElement(`input`);s.className=`min-w-0 flex-1 border-0 bg-transparent ${El} text-neutral-600 focus:outline-none`,s.value=n.path,s.spellcheck=!1,s.title=`Type or paste a path, then Enter`,s.onfocus=()=>s.select();let c=R(`p`,`hidden flex-none px-3 pb-1 text-[0.8125rem] text-red-600`);s.onkeydown=async e=>{if(e.key!==`Enter`)return;e.preventDefault(),e.stopPropagation();let t=s.value.trim();if(!t)return;let n=await Cl(t);if(!n){c.textContent=`${t} is not a folder this can read`,c.classList.remove(`hidden`);return}r(n.path)};let l=R(`div`,`mb-2 flex flex-none items-center gap-2 border-b border-neutral-200 px-3 pb-2 pt-1`,s,o),u=R(`div`,`min-h-0 flex-1 overflow-y-auto`);u.dataset.list=``,n.parent&&u.append(Dl(`../`,`${El} text-neutral-500`,()=>void i(n.parent)));let d=wl(n);for(let e of d)u.append(Dl(e,`truncate`,()=>void i(`${n.path}/${e}`.replace(`//`,`/`))));d.length||u.append(R(`p`,`px-3 py-2 text-[0.8125rem] text-neutral-400`,`No sub-folders.`)),a.append(l,c,u,Ol(n.path,e=>void i(e))),bl(e,a)}i(t)}function Al(e,t,n,r){Sl(e,[...t.map(e=>({label:e.path,...e.hint?{hint:e.hint}:{},checked:e.path===n,onSelect:()=>{q(),r(e.path)}})),{label:`Browse…`,onSelect:()=>kl(e,n||void 0,r)}])}var jl=(e,t)=>n=>{e.value=n,e.dispatchEvent(new Event(`input`,{bubbles:!0})),t?.(n)};function Ml(e,t){let n=Zr(`Browse…`,`flex-none cursor-pointer rounded-md border border-neutral-300 px-2 py-1 text-[12px] text-neutral-600 hover:bg-neutral-100`);return n.onclick=()=>kl(n,e.value.trim()||void 0,jl(e,t)),n}function Nl(e,t,n){let r=document.createElement(`input`);return r.className=`min-w-0 flex-1 rounded-md border border-neutral-300 bg-white px-2 py-1 font-mono text-[12.5px] focus:border-indigo-400 focus:outline-none`,r.value=e,r.placeholder=t,r.oninput=()=>n(r.value),{el:R(`div`,`flex items-center gap-1.5`,r,Ml(r,n)),input:r}}var J=L(`#sidebar`),Pl=L(`#drawer-scrim`),Fl=L(`#mobile-title`),Il=L(`#mobile-menu`),Ll=L(`#session-meta`);function Rl(){delete J.dataset.open,Pl.classList.add(`hidden`),Kl()}function zl(e,t){Fl.textContent=e,Fl.classList.toggle(`cursor-pointer`,t),Il.classList.toggle(`hidden`,!t)}var Bl=`pier.railClosed`;localStorage.getItem(Bl)===`1`&&(document.body.dataset.rail=`closed`);function Vl(e){document.body.dataset.rail=e?`closed`:``,localStorage.setItem(Bl,e?`1`:`0`),Kl()}function Hl(){if(J.dataset.open!==void 0)return Rl();J.dataset.open=``,Pl.classList.remove(`hidden`),Kl()}var Ul=window.matchMedia(`(width < 48rem)`),Wl=()=>Ul.matches;function Gl(){Wl()?L(`#mobile-bar`).append(Ll):L(`#chat-menu`).before(Ll)}function Kl(){let e=Wl()&&J.dataset.open!==void 0,t=L(`main`);t.inert=e,J.inert=Wl()?!e:document.body.dataset.rail===`closed`,L(`#drawer-toggle`).setAttribute(`aria-expanded`,String(e)),e&&!J.contains(document.activeElement)&&L(`#new-session`).focus(),J.inert&&J.contains(document.activeElement)&&L(Wl()?`#drawer-toggle`:`#rail-toggle`).focus()}var ql=[L(`#rail-toggle`),L(`#drawer-toggle`)],Jl=`attention absolute -right-0.5 -top-0.5 rounded-full bg-amber-500`,Yl=e=>e===1?R(`span`,`${Jl} h-2 w-2`):R(`span`,`${Jl} flex h-3.5 min-w-3.5 items-center justify-center px-0.5 text-[9px] font-semibold text-white`,e>9?`9+`:String(e));function Xl(e){for(let t of ql)t.querySelector(`.attention`)?.remove(),e&&t.append(Yl(e))}var Zl=20,Ql=.35,$l=8;function eu(){let e=-1,t=0,n=!1,r=!1,i=1,a=e=>{J.style.transition=`none`,J.style.transform=`translateX(${String(e-i)}px)`,Pl.style.transition=`none`,Pl.classList.remove(`hidden`),Pl.style.opacity=String(e/i)},o=t=>{J.style.transition=``,J.style.transform=``,Pl.style.transition=``,Pl.style.opacity=``,t?(J.dataset.open=``,Pl.classList.remove(`hidden`),Kl()):Rl(),e=-1,r=!1};window.addEventListener(`touchstart`,a=>{if(r||(e=-1,!Wl()||a.touches.length!==1))return;let o=a.touches[0],s=J.dataset.open!==void 0;if(i=J.offsetWidth||1,s){if(o.clientX>i)return}else{if(o.clientX>Zl||a.target?.closest(`button, a, input, textarea, select`))return;a.preventDefault()}e=o.clientX,t=o.clientY,n=!s},{passive:!1}),window.addEventListener(`touchmove`,o=>{if(e<0)return;let s=o.touches[0],c=s.clientX-e;if(!r){if(Math.abs(s.clientY-t)>Math.abs(c))return void(e=-1);if(Math.abs(c)<$l)return;r=!0}o.preventDefault(),a(Math.max(0,Math.min(i,n?c:i+c)))},{passive:!1});let s=()=>{if(e<0)return;if(!r)return void(e=-1);let t=J.getBoundingClientRect().right;o(n?t>i*Ql:t>i*.65)};window.addEventListener(`touchend`,s),window.addEventListener(`touchcancel`,s)}function tu(e){eu(),Kl(),Gl(),Ul.addEventListener(`change`,()=>{Rl(),Gl()}),L(`#drawer-toggle`).setAttribute(`aria-controls`,`sidebar`),J.addEventListener(`keydown`,e=>{if(!(!Wl()||J.dataset.open===void 0||e.defaultPrevented||e.isComposing)){if(e.key===`Escape`)e.preventDefault(),e.stopPropagation(),Rl();else if(e.key===`Tab`){let t=[...J.querySelectorAll(`button, a[href], summary`)].filter(e=>e.getClientRects().length&&!e.matches(`:disabled`)),n=e.shiftKey?t.at(-1):t[0],r=e.shiftKey?t[0]:t.at(-1);document.activeElement===r&&(e.preventDefault(),n?.focus())}}}),L(`#drawer-toggle`).onclick=Hl,Pl.onclick=Rl,Il.onclick=()=>e.sessionMenu(Il),Fl.onclick=()=>{Il.classList.contains(`hidden`)||e.sessionInfo(Fl)};let t=L(`#rail-toggle`);t.onclick=()=>Vl(document.body.dataset.rail!==`closed`),Ks(t,`meta+b`,`Toggle sidebar`,()=>Wl()?Hl():Vl(document.body.dataset.rail!==`closed`))}var Y,nu=L(`#session-list`),ru=L(`#new-session`),iu=e=>e.modified??e.createdAt;function au(e){return{top:e.filter(e=>e.rank!==void 0).sort((e,t)=>(e.rank??0)-(t.rank??0)),rest:e.filter(e=>e.rank===void 0).sort((e,t)=>t.createdAt-e.createdAt)}}function ou(e,t){let{top:n,rest:r}=au(e),i=[...n,...r].slice(0,t);return{rows:i,hidden:e.length-i.length}}function su(e,t,n){let{top:r,rest:i}=au(e),a=[...r,...i];if(!a.length)return;let o=a.findIndex(e=>e.id===t),s=o<0?a[0]:a[(o+n+a.length)%a.length];return s&&s.id!==t?s.id:void 0}var cu=8,lu=e=>[...new Set([...e].sort((e,t)=>t.createdAt-e.createdAt).map(e=>e.cwd))];function uu(e){let t=lu(e),n=new Set(t);return t.filter(e=>{let t=e.lastIndexOf(`/`),r=e.indexOf(`.`,t+2);return r<0||!n.has(e.slice(0,r))})}var du=`session-more hidden h-7 w-7 flex-none cursor-pointer items-center justify-center rounded-lg text-neutral-400 hover:bg-neutral-200 hover:text-neutral-700`,fu=e=>e.unread,pu=e=>`${e} subagent${e>1?`s`:``} running`;function mu(e){let t=e.state===`streaming`?[`bg-green-500 animate-pulse`,`working…`]:fu(e)?[`bg-amber-500`,`turn finished — not viewed yet`]:e.activeRuns>0?[`bg-sky-500`,pu(e.activeRuns)]:null;if(!t)return[];let n=R(`span`,`h-2 w-2 flex-none rounded-full ${t[0]}`);return n.title=t[1],[n]}async function hu(e){let t=window.prompt(`Session name — empty resets it to the first message`,e.title??``);if(t===null)return;let n=e.title,r=t=>{e.title=t,Su(),Y.onTitleChanged()};r(t.trim()||void 0),(await b(`/api/sessions/${e.id}/rename`,{name:t})).ok||r(n)}var gu=`flex-none text-xs font-medium uppercase leading-5 text-neutral-500`,_u=e=>e.channel&&e.channel!==`web`?[R(`span`,gu,e.channel[0]??``)]:[];function vu(e,t=R(`button`,du,g(p))){let n=e.id===Y.currentId(),r=R(`li`,`flex items-center gap-1 hover:bg-neutral-100 ${n?`bg-indigo-50 hover:bg-indigo-50`:``}`);t.setAttribute(`type`,`button`),t.setAttribute(`aria-label`,`Session actions: ${e.title??`untitled`}`),t.title=`Session actions`,t.onclick=n=>{n.stopPropagation(),Y.sessionMenu(t,e)};let i=R(`button`,`session-open flex min-w-0 flex-1 cursor-pointer items-center gap-1.5 rounded-lg text-left`,R(`span`,`min-w-0 flex-1 truncate`,e.title??`untitled`),...mu(e));return i.setAttribute(`type`,`button`),n&&i.setAttribute(`aria-current`,`page`),i.onclick=()=>Y.select(e.id),r.dataset.sessionId=e.id,r.append(i,..._u(e),t),r.title=[e.cwd,`active ${Rr(iu(e))} ago · created ${new Date(e.createdAt).toLocaleDateString()}`,...e.channel&&e.channel!==`web`?[`answering ${e.channel}`]:[]].join(`
|
|
85
|
-
`),r}var yu=()=>`${Y.currentId()??``}\n${xu}\n${JSON.stringify(Y.sessions())}`,bu=``,xu=20;function Su(){let e=yu();if(e===bu)return;bu=e;let t=Y.sessions(),n=t.filter(fu);Xl(n.length),il(n.length);let{rows:r,hidden:i}=ou(t,xu),a=nu.querySelector(`.session-more[aria-expanded='true']`),o=a?.closest(`[data-session-id]`)?.dataset.sessionId,s=r.map(e=>vu(e,e.id===o?a:void 0));if(i>0){let e=R(`button`,`session-open w-full cursor-pointer rounded-lg text-left text-sm text-neutral-500`,`Load more (${i})`);e.id=`session-load-more`,e.setAttribute(`type`,`button`),e.onclick=()=>{xu+=20,Su(),nu.querySelectorAll(`.session-open`)[r.length]?.focus()},s.push(R(`li`,`hover:bg-neutral-100`,e))}let c=document.activeElement,l=c?.closest(`[data-session-id]`)?.dataset.sessionId,u=c?.classList.contains(`session-more`)?`.session-more`:`.session-open`;if(nu.replaceChildren(...s.length?[R(`ul`,`pb-1`,...s)]:[R(`p`,`px-3 py-2 text-sm leading-normal text-neutral-500`,`No sessions yet — create one.`)]),l){let e=[...nu.querySelectorAll(`[data-session-id]`)].find(e=>e.dataset.sessionId===l);e?.querySelector(`.session-open`)?.focus({preventScroll:!0}),u===`.session-more`&&e?.querySelector(u)?.focus({preventScroll:!0})}else c?.id===`session-load-more`&&(nu.querySelector(`#session-load-more`)??nu.querySelector(`.session-open`)??L(`#new-session`)).focus({preventScroll:!0});td()}function Cu(){if(ru.getAttribute(`aria-expanded`)===`true`)return q();let e=Y.sessions().find(e=>e.id===Y.currentId())?.cwd,t=uu(Y.sessions()).slice(0,cu);if(e&&!t.includes(e)&&t.unshift(e),!t.length)return kl(ru,void 0,Y.createSession);Al(ru,t.map(e=>({path:e,hint:Br(e)})),e,Y.createSession)}function wu(e){Y=e,ru.onclick=Cu,Ks(ru,`shift+o`,`New session`,Cu,Hs);let t=e=>{let t=su(Y.sessions(),Y.currentId(),e);t&&Y.select(t)};Xs(`shift+[`,()=>t(-1),Hs),Xs(`shift+]`,()=>t(1),Hs)}var Tu,Eu=L(`#palette`),Du=L(`#palette-input`),Ou=L(`#palette-list`),ku=L(`#palette-count`),Au=[{name:`tasks`,icon:ie,label:`Tasks`,detail:`Automation — task definitions and schedules`},{name:`runs`,icon:ie,label:`Runs`,detail:`Automation — executions, subagents, decisions and callbacks`},{name:`activity`,icon:ie,label:`Activity`,detail:`Automation — sessions and relationships`},{name:`boards`,icon:re,label:`Boards`,detail:`Console — the static pages Pier publishes`},{name:`settings`,icon:me,label:`Settings`,detail:`Console — models and providers, agent files and extensions, channels, password, sign out, security`}],ju=7,Mu=3,Nu=8,Pu=80,Fu=``,Iu,Lu,Ru;function zu(e){Fu!==e&&(clearTimeout(Ru),Lu?.abort(),Lu=void 0,Fu=e,Iu=void 0,e&&(Ru=setTimeout(()=>{let t=Lu=new AbortController;Le(`/api/search?q=${encodeURIComponent(e)}`,`Search unavailable`,{signal:t.signal}).then(n=>{t.signal.aborted||Fu!==e||(Lu=void 0,Iu=n.ok?{hits:n.value.hits}:{error:n.error},Eu.open&&ed())})},Pu)))}var Bu=[],Vu=0;function Hu(e){if(Bu.length){Vu=(e+Bu.length)%Bu.length;for(let[e,{el:t}]of Bu.entries())t.classList.toggle(`bg-indigo-50`,e===Vu),t.setAttribute(`aria-selected`,String(e===Vu));Bu[Vu]?.el.scrollIntoView({block:`nearest`})}}var Uu=e=>e.hit?.at??e.session?.createdAt;function Wu(e){let t=R(`span`,`min-w-0 flex-1 truncate text-neutral-500`),[n=``,r=``]=e.replaceAll(/\s+/g,` `).split(``,2),[i=``,a=``]=r.split(``,2);return t.append(n,R(`span`,`font-medium text-neutral-800`,i),a),t}var Gu=`flex min-w-0 flex-1 items-baseline gap-2`,Ku=`shrink-0 truncate`,qu=`min-w-[2.5em] truncate text-[0.8125rem] text-neutral-400`,Ju=`flex-none text-[0.75rem] tabular-nums text-neutral-400`,Yu=`flex h-7 w-7 flex-none items-center justify-center rounded-[8px] bg-neutral-100 text-neutral-500`;function Xu(e){let t=R(`li`,`palette-row flex cursor-pointer items-center gap-3 rounded-[10px] px-2 leading-5 ${e.hit?`py-1.5`:`min-h-10`}`);t.setAttribute(`role`,`option`),t.append(R(`span`,Yu,g(e.icon,`h-4 w-4`)));let n=R(`div`,`flex min-w-0 flex-1 flex-col`),r=R(`div`,`flex items-center gap-2`);e.session&&r.append(...mu(e.session));let i=R(`span`,Gu,R(`span`,`${Ku} ${e.detail?`max-w-[calc(100%-3em)]`:`max-w-full`}`,e.label));e.detail&&i.append(R(`span`,qu,e.detail)),r.append(i);let a=Uu(e);return a!==void 0&&r.append(R(`span`,Ju,Rr(a))),n.append(r),e.hit&&n.append(R(`div`,`flex items-baseline gap-2 text-[0.8125rem] leading-5`,R(`span`,`flex-none text-[0.75rem] text-neutral-400`,e.hit.role===`user`?`You`:`Agent`),Wu(e.hit.snippet))),t.append(n),t.onclick=e.open,t}var Zu=e=>R(`li`,`px-2 pb-1.5 pt-4 text-[0.6875rem] font-semibold leading-4 tracking-[0.02em] text-neutral-400 first:pt-2`,e);function Qu(e,t){let n=R(`li`,`px-2 py-2 pl-12 text-[0.8125rem] leading-5 text-neutral-400`,e);return t&&(n.title=t),n}var $u=e=>e.channel&&e.channel!==`web`?e.channel:``;function ed(){let e=Du.value.trim(),t=e.toLowerCase(),n=e=>e.toLowerCase().includes(t),r=e=>()=>{Eu.close(),e()},i=Tu.sessions(),a=new Map(i.map(e=>[e.id,e])),{top:o,rest:s}=au(i),c=[...o,...s],l=e=>({icon:oe,label:e.title??Vr(e.cwd),detail:[Br(e.cwd),$u(e)].filter(Boolean).join(` · `),open:r(()=>void Tu.select(e.id)),session:e}),u=e=>({icon:ne,label:Vr(e),detail:e,open:r(()=>void Tu.createSession(e))}),d=Au.filter(t=>!e||n(`${t.label} ${t.detail}`)).map(({name:e,icon:t,label:n,detail:i})=>({icon:t,label:n,detail:i,open:r(()=>Tu.openConsole(e))})),ee={icon:ne,label:`New session in…`,detail:`Pick a directory`,open:r(Cu)},f=[];if(e){let t=uu(i).filter(e=>n(Br(e))).slice(0,Mu),o=c.filter(e=>n(`${e.title??``} ${e.cwd} ${$u(e)}`)).slice(0,Nu),s=new Set(o.map(e=>e.id)),p=o.map(l);if(Fu!==e||!Iu)p.push(Qu(`Searching messages…`));else if(`error`in Iu)p.push(Qu(`Message search unavailable`,Iu.error));else{for(let e of Iu.hits){if(p.length>=Nu)break;let t=a.get(e.sessionId);!t||s.has(t.id)||p.push({...l(t),hit:e,open:r(()=>void Tu.select(t.id).then(()=>No(e.role,e.at)))})}p.length||p.push(Qu(`No sessions match`))}f.push([`Actions`,[...t.map(u),...n(ee.label)?[ee]:[],...d]],[`Sessions`,p])}else{let e=c.filter(e=>e.state===`streaming`),t=a.get(Tu.currentId()??``);f.push([`Running`,e.map(l)],[`Recent`,c.filter(e=>e.state!==`streaming`).slice(0,ju).map(l)],[`Actions`,[...t?[u(t.cwd)]:[],ee]],[`Console`,d])}Bu=[];let p=[];for(let[e,t]of f)if(t.length){p.push(Zu(e));for(let e of t){if(e instanceof HTMLElement){p.push(e);continue}let t=Xu(e);Bu.push({el:t,open:e.open}),p.push(t)}}Ou.replaceChildren(...p.length?p:[Qu(`Nothing matches`)]),ku.textContent=`${Bu.length} ${Bu.length===1?`row`:`rows`}`,Hu(Math.min(Vu,Math.max(0,Bu.length-1)))}function td(){Eu.open&&ed()}function nd(){if(Eu.open)return Eu.close();Du.value=``,Vu=0,zu(``),ed(),Eu.showModal(),Du.focus(),Tu.loadSessions().then(td)}function rd(e){Tu=e;let t=L(`#open-palette`);t.onclick=nd,Ks(t,`k`,`Search sessions, messages and Console`,nd,()=>Eu.open||dl()),Eu.onclick=e=>{e.target===Eu&&Eu.close()},Eu.onclose=()=>zu(``),Du.oninput=()=>{Vu=0,zu(Du.value.trim()),ed()},Du.onkeydown=e=>{let t=fl(e);if(t!==void 0){e.preventDefault(),Hu(Vu+t);return}e.key===`Enter`&&!e.ctrlKey&&(e.preventDefault(),Bu[Vu]?.open())}}var id=0,ad=e=>`${e.provider}/${e.id}`,od=null;async function sd(){let{modelMenu:e}=await Re(`/api/settings`,`Could not read the pinned model menu`);return e}function cd(e){let t=R(`button`,`flex w-full min-w-0 cursor-pointer items-center gap-2 px-3 py-1.5 text-left hover:bg-neutral-100`,g(o,`h-3 w-3 text-indigo-600 ${e.checked?``:`invisible`}`),R(`span`,`truncate`,e.label));return e.hint&&t.append(R(`span`,`ml-auto flex-none text-[11.5px] text-neutral-400`,e.hint)),e.title&&(t.title=e.title),t.onclick=()=>e.onSelect(),t}function ld({models:e,current:t,thinkingLevel:n,thinkingLevels:r,onPick:i,onThinkingPick:a}){let o=n,s=R(`div`,`flex w-full min-w-0 flex-col sm:min-w-72`),c=R(`div`,`flex flex-col gap-2 border-b border-neutral-200 px-2 py-2`),u=document.createElement(`input`);if(u.type=`search`,u.placeholder=`Search models`,u.setAttribute(`aria-label`,`Search models`),u.className=`w-full rounded-md border border-neutral-300 px-2 py-1.5 text-[12.5px] focus:border-indigo-400 focus:outline-none`,c.append(u),r.length){let e=document.createElement(`details`),t=R(`span`,`ml-auto font-medium text-indigo-700`,Se(o)),n=R(`summary`,`flex min-h-11 cursor-pointer list-none items-center gap-2 rounded-xl px-3 text-sm text-neutral-700 hover:bg-neutral-100 [&::-webkit-details-marker]:hidden`,R(`span`,`font-medium`,`Reasoning effort`),t,g(l,`chev h-3 w-3 text-neutral-400`)),i=R(`fieldset`,`grid grid-cols-2 gap-1 rounded-xl bg-neutral-50 p-1`);i.append(R(`legend`,`sr-only`,`Reasoning effort`));let s=`reasoning-${++id}`;for(let e of r){let n=document.createElement(`input`);n.type=`radio`,n.name=s,n.value=e,n.checked=e===o,n.className=`peer sr-only`,n.onchange=()=>{n.checked&&(o=e,t.textContent=Se(o),p(u.value),a(o))},i.append(R(`label`,`relative cursor-pointer`,n,R(`span`,`flex min-h-11 items-center rounded-lg border border-transparent px-3 text-sm text-neutral-700 hover:bg-neutral-100 peer-checked:border-indigo-200 peer-checked:bg-indigo-50 peer-checked:font-semibold peer-checked:text-indigo-700 peer-focus-visible:outline-2 peer-focus-visible:outline-indigo-500`,Se(e))))}e.append(n,i),c.append(e)}let d=R(`div`,`max-h-72 overflow-y-auto py-1`),ee=new Map(e.map(e=>[ad(e),e])),f=e=>{let n=(od??[]).map(e=>({e,model:ee.get(ad(e))})).filter(t=>!!t.model&&(!e||ad(t.model).toLowerCase().includes(e)));n.length&&d.append(R(`div`,`px-3 pb-0.5 pt-1 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,`Pinned`),...n.map(({e,model:n})=>cd({label:n.id,hint:Se(e.thinking),title:e.note,checked:!!t&&ad(t)===ad(n)&&o===e.thinking,onSelect:()=>i(n,e.thinking)})),R(`div`,`my-1 border-t border-neutral-100`))},p=n=>{d.replaceChildren();let r=n.trim().toLowerCase();f(r);let a=new Map;for(let t of e){if(r&&!ad(t).toLowerCase().includes(r))continue;let e=a.get(t.provider);e?e.push(t):a.set(t.provider,[t])}if(!a.size){d.append(R(`div`,`px-3 py-2 text-[12.5px] text-neutral-400`,e.length?`No matching models.`:`No models available.`));return}for(let[e,n]of a){let a=n.some(e=>!!t&&ad(t)===ad(e)),o=document.createElement(`details`);o.open=a||r.length>0;let s=R(`summary`,`flex cursor-pointer select-none items-center gap-1.5 px-3 py-1 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400 hover:bg-neutral-100`,g(l,`chev h-3 w-3`),R(`span`,`truncate`,e),R(`span`,`ml-auto flex-none normal-case text-neutral-300`,String(n.length)));o.append(s,...n.map(e=>cd({label:e.id,checked:!!t&&ad(t)===ad(e),onSelect:()=>i(e)}))),d.append(o)}};return u.oninput=()=>p(u.value),p(``),sd().then(e=>{let t=JSON.stringify(e)!==JSON.stringify(od);od=e,t&&p(u.value)}).catch(e=>js(`model menu unavailable`,e)),s.append(c,d),queueMicrotask(()=>u.focus()),s}function ud(e,t,n,r){let i=Zr(t.model?`${t.model.id}${t.thinking?` · ${Se(t.thinking)}`:``}`:t.thinking?`Pi default · ${Se(t.thinking)}`:`Pi default`,`${oi} flex cursor-pointer items-center gap-1.5 truncate text-left hover:bg-neutral-50 ${t.model?`text-neutral-700`:`text-neutral-400`}`);return i.title=t.model?`${t.model.provider}/${t.model.id}`:`Whatever the project and Pi pick`,i.onclick=()=>{let e=ld({models:n,current:t.model,thinkingLevel:t.thinking??`medium`,thinkingLevels:[...Da],onPick:(e,n)=>{q(),r({model:e,thinking:n??t.thinking})},onThinkingPick:e=>{t={...t,thinking:e},r(t)}}),a=Zr(`Pi default`,`w-full cursor-pointer px-3 py-1.5 text-left text-[12.5px] text-neutral-500 hover:bg-neutral-100`);a.onclick=()=>{q(),r({model:null,thinking:null})};let o=R(`div`,`flex flex-col`);o.append(e,R(`div`,`border-t border-neutral-200`),a),bl(i,o)},ai(e,i)}var X;function dd(e){X=e,Xs(fd,()=>{X.currentSession()&&(q(),X.toggleFiles())},Hs)}var fd=`i`,pd=L(`#chat-title`),md=L(`#chat-menu`),hd=L(`#session-meta`),gd=null,_d=new Map,vd=e=>`${e.provider}/${e.id}`,Z=null,yd=null,bd=null,xd=null;function Sd(){Z=null,yd=null,bd=null,xd=null,jd()}function Cd(e,t,n,r){Z=e,yd=t,bd=n,xd=r,Dd()}function wd(e){xd=e.completedAt,yd&&={...yd,tokens:e.tokens},jd()}var Td=null;function Ed(e){Td=e===null?null:Vr(e),Dd()}function Dd(){let e=X.currentSession();e&&(Td=null),pd.textContent=e?e.title??Vr(e.cwd):Td??X.currentId()??`no session`,pd.classList.toggle(`cursor-pointer`,!!e),pd.title=e?`Session info`:``,pd.onclick=e?()=>Md(pd,e):null,md.classList.toggle(`hidden`,!e),e&&(md.onclick=()=>Ld(md,e)),jd(),X.syncBar()}var Od=70,kd=(e,t)=>Math.min(100,Math.round(e/t.contextWindow*100)),Ad=e=>e.tokens===null?`?/${Ce(e.contextWindow)}`:`${Ce(e.tokens)}/${Ce(e.contextWindow)} · ${100-kd(e.tokens,e)}% left`;function jd(){let e=yd,t=e?.tokens??null,n=X.currentId(),r=X.currentSession()?.activeRuns??0,i=[];if(r>0){let e=R(`button`,`flex flex-none cursor-pointer items-center gap-1 rounded bg-sky-50 px-1.5 py-px font-medium text-sky-700 hover:bg-sky-100`,g(m,`spinner h-3 w-3`),`${r} running`);e.title=`${pu(r)} · show the newest`,e.onclick=()=>{Po()||H(`error`,`no run card left in this transcript — reload the session to see it`)},i.push(e)}if(!n&&Td&&i.push(R(`span`,`flex flex-none items-center gap-1.5 text-neutral-500`,g(m,`spinner`),`starting…`)),n){let e=(e,t)=>{let r=R(`button`,`flex-none cursor-pointer font-mono ${t}`,e);return r.title=`Change model or reasoning`,r.onclick=()=>void Nd(r,n),r};Z&&i.push(e(Z.id,`rounded bg-indigo-50 px-1.5 py-px font-medium text-indigo-700 hover:bg-indigo-100`)),bd&&i.push(e(bd,`text-neutral-500 hover:text-indigo-700`))}let a=0;if(e&&t!==null){a=kd(t,e);let n=a>=90?`text-red-700`:a>=Od?`text-amber-700`:`text-neutral-500`;i.push(R(`span`,`flex-none font-mono ${n}`,Ce(t).toLowerCase()))}let o=i.flatMap((e,t)=>t===0?[e]:[R(`span`,`text-neutral-300`,`·`),e]);hd.replaceChildren(...o),hd.classList.toggle(`hidden`,i.length===0),hd.classList.toggle(`flex`,i.length>0),hd.toggleAttribute(`data-urgent`,!n&&!!Td||r>0||a>=Od)}function Md(e,t,n=!1){let i=[[`Directory`,t.cwd],[`Session`,t.id]],a=t.id===X.currentId();if(a&&(i.push([`Model`,Z?.id??`—`]),i.push([`Reasoning`,bd??`—`]),i.push([`Context`,yd?Ad(yd):`—`])),i.push([`Created`,Hr(t.createdAt),zr(t.createdAt)]),a){let e=xd;i.push(e===null?[`Last reply`,`—`]:[`Last reply`,Hr(e),zr(e)])}let o=R(`div`,`w-[min(26rem,calc(100vw-2rem))] max-sm:w-full rounded-xl bg-white px-3 py-3 font-sans text-[15px] leading-normal`),s=R(`button`,`icon-btn h-11 w-11 sm:h-8 sm:w-8`,g(ve));s.setAttribute(`aria-label`,`Close session info`),s.onclick=q;let c=R(`div`,`sticky top-0 z-10 flex items-start gap-2 bg-white pb-2`,R(`div`,`min-w-0 flex-1`,R(`div`,`text-sm font-medium text-neutral-500`,`Session info`),R(`h2`,`mt-1 [overflow-wrap:anywhere] text-lg leading-7 font-semibold text-neutral-900`,t.title??Vr(t.cwd))),s);if(n){let n=R(`button`,`icon-btn h-11 w-11 sm:h-8 sm:w-8`,g(r));n.setAttribute(`aria-label`,`Back to session actions`),n.onclick=()=>Ld(e,t),c.prepend(n)}o.append(c);let l=R(`dl`,``);for(let[e,t,n]of i){let r=e===`Directory`||e===`Session`,i=R(`dd`,`min-w-0 flex items-start gap-2 text-neutral-700 ${r?`font-mono text-sm leading-6`:``}`,R(`span`,`min-w-0 flex-1 [overflow-wrap:anywhere]`,t));if(r){let n=Jr(`min-h-11 min-w-11 sm:min-h-8 shrink-0 cursor-pointer rounded-lg px-2 py-1 text-[13px] font-sans text-neutral-500 hover:bg-neutral-100 focus-visible:outline-2`,()=>t);n.setAttribute(`aria-label`,`Copy ${e.toLowerCase()}`),i.append(n)}n&&i.firstElementChild?.append(R(`span`,`ml-2 inline-block font-sans text-[13px] leading-5 text-neutral-500`,n));let a=e===`Model`||e===`Created`;l.append(R(`div`,`grid gap-1 py-1.5 sm:grid-cols-[5.5rem_minmax(0,1fr)] sm:gap-3 ${a?`mt-2 border-t border-neutral-200 pt-2.5`:``}`,R(`dt`,`text-[15px] text-neutral-500`,e===`Session`?`Session ID`:e),i))}o.append(l),bl(e,o)}async function Nd(e,t,n){let i=R(`div`,`px-3 py-3 text-[15px] text-neutral-500`,`Loading models…`),a=R(`div`,`w-[min(24rem,calc(100vw-2rem))] min-w-0 max-sm:w-full`,i),o=i;if(n){let t=R(`button`,`icon-btn h-11 w-11`,g(r));t.setAttribute(`aria-label`,`Back to session actions`),t.onclick=()=>Ld(e,n);let i=R(`button`,`icon-btn h-11 w-11`,g(ve));i.setAttribute(`aria-label`,`Close model picker`),i.onclick=q;let o=R(`span`,`min-w-0 flex-1 truncate text-sm font-medium`,n.title??Vr(n.cwd));o.title=o.textContent??``,a.prepend(R(`div`,`flex items-center gap-2 border-b border-neutral-200 pb-2 mb-2`,t,o,i))}bl(e,a);let s=()=>o.isConnected&&!o.closest(`[inert]`),c=``,l=(n,r,i)=>{let s=JSON.stringify([n,r,i]);if(s===c)return;c=s;let l=ld({models:n,current:t===X.currentId()?Z:null,thinkingLevel:r,thinkingLevels:i,onPick:(e,n)=>{q(),Pd(t,e,n)},onThinkingPick:e=>void Id(t,e)});o.replaceWith(l),o=l,bl(e,a)},u=t===X.currentId()&&Z?_d.get(vd(Z)):void 0;gd&&u&&bd&&l(gd,bd,u);try{let[e,n]=await Promise.all([Re(`/api/sessions/${t}/models`,`Could not load models`),Re(`/api/sessions/${t}/thinking`,`Could not read the reasoning level`)]);if(gd=e,t===X.currentId()&&Z&&_d.set(vd(Z),n.levels),!s())return;l(e,n.level,n.levels)}catch(e){c?H(`error`,`model options are stale: ${String(e)}`):s()?(i.textContent=`Could not load models: ${String(e)}`,i.setAttribute(`role`,`alert`)):H(`error`,`model options failed: ${String(e)}`)}}async function Pd(e,t,n){await Fd(e,t)&&n&&await Id(e,n)}async function Fd(e,t){let n=Z;e===X.currentId()&&(Z=t,Dd());let r=await b(`/api/sessions/${e}/model`,t);if(!r.ok){let{error:t}=await r.json().catch(()=>({}));return e===X.currentId()&&(Z=n,Dd()),H(`error`,`model change failed: ${t??r.status}`),!1}let{model:i}=await r.json();return e===X.currentId()&&i&&(Z=i,Dd()),!0}async function Id(e,t){let n=await b(`/api/sessions/${e}/thinking`,{level:t});if(!n.ok){H(`error`,`reasoning change failed: ${n.status}`);return}let{level:r}=await n.json();e===X.currentId()&&(bd=r,jd())}function Ld(e,t){let n=t.id===X.currentId();Sl(e,[{label:`Rename…`,onSelect:()=>{q(),hu(t)}},{label:`Session info`,onSelect:()=>Md(e,t,!0)},{label:`New session here`,separatorBefore:!0,hint:Br(t.cwd),onSelect:()=>{q(),X.createSession(t.cwd)}},{label:`Browse files`,hint:n?Vs(fd):``,onSelect:()=>{q(),X.openFiles(n?void 0:t.cwd)}},{label:`Model & reasoning…`,separatorBefore:!0,hint:n?Z?.id??`…`:``,onSelect:()=>void Nd(e,t.id,t)}],t.title??Vr(t.cwd))}var Rd=`pier.theme`,zd=[`system`,`light`,`dark`],Bd=window.matchMedia(`(prefers-color-scheme: dark)`),Vd={system:ce,light:ge,dark:h},Hd=()=>{let e=null;try{e=localStorage.getItem(Rd)}catch{return`system`}return e===`light`||e===`dark`?e:`system`},Ud=()=>{let e=Hd();return e===`system`?Bd.matches?`dark`:`light`:e};function Wd(){let e=Ud();document.documentElement.dataset.theme=e;let t=getComputedStyle(document.documentElement).getPropertyValue(`--workbench-canvas`).trim();L(`meta[name="theme-color"]`).setAttribute(`content`,t),window.dispatchEvent(new Event(`pier:theme`))}function Gd(){let e=L(`#theme-toggle`),t=()=>{let t=Hd();e.title=`Theme: ${t}${t===`system`?` (${Ud()})`:``}`,e.replaceChildren(g(Vd[t])),e.setAttribute(`aria-label`,e.title),Wd()};e.onclick=()=>{let e=zd[(zd.indexOf(Hd())+1)%zd.length];try{e===`system`?localStorage.removeItem(Rd):localStorage.setItem(Rd,e)}catch{}t()},Bd.addEventListener(`change`,t),t()}var Kd=`https://github.com/timqi/pier`,qd=[`text-neutral-400`,`hover:text-neutral-700`],Jd=[`rounded-full`,`bg-emerald-50`,`px-1.5`,`text-emerald-700`,`ring-1`,`ring-inset`,`ring-emerald-600/20`,`hover:bg-emerald-100`],Yd=18e5,Xd=null,Zd=L(`#version`);function Qd(e){let t=Xd?.available===!0&&Xd.latest!==null;Zd.textContent=`v${e}`,Zd.title=t?`Pier ${Xd?.latest} is out`:``,Zd.classList.remove(...t?qd:Jd),Zd.classList.add(...t?Jd:qd)}var $d=(e,t=`px-3 py-1 text-[12px] leading-snug text-neutral-500`)=>R(`p`,t,e);function ef(){let e=R(`div`,`flex w-72 flex-col gap-1 py-1`);if(!Xd)return e.append($d(`Checking the registry…`)),e;let{current:t,latest:n,available:r,canApply:i,problem:a}=Xd,o=R(`span`,``,``),s=(e,t)=>pi(o,e?`failed`:`idle`,t),c=R(`div`,`flex items-center gap-2 px-3 py-1.5`);if(e.append($d(r?`Pier ${n} is out`:`Pier ${t}`,`px-3 py-1 text-[12.5px] font-medium text-neutral-700`),$d(r?`You are running ${t}.`:n===null?`The registry could not be reached, so this may not be the latest.`:`This is the latest release.`)),a&&e.append($d(a,`mx-3 my-1 rounded-md bg-red-50 px-2 py-1.5 text-[11.5px] leading-snug text-red-700`)),r&&i&&!a){let e=Xr(`Update now`,!0);e.onclick=()=>void(async()=>{e.disabled=!0,s(!1,`starting the updater…`);let t=await b(`/api/update`,{});if(!t.ok)return e.disabled=!1,s(!0,await x(t,`Could not update`));let{draining:n}=await t.json();s(!1,n?`Waiting for running work to finish — Pier then installs and restarts.`:`Installing — Pier restarts once it is on disk, and this page reconnects on its own.`)})(),c.append(e)}c.append(Object.assign(R(`a`,`btn text-[12.5px] no-underline`,`Source`),{href:r?`${Kd}/releases`:Kd,target:`_blank`,rel:`noreferrer`,title:`Pier is free software (AGPL-3.0)`})),e.append(c,R(`div`,`px-3`,o)),r&&!i&&!a&&e.append($d(`No service manager owns this Pier, so it cannot restart itself — update it with: pier update`));let l=di(`Update automatically`,i?`Installs a new release once nothing is running — no turn in flight, no task run.`:`Needs the systemd service (pier service install); nothing here can restart Pier.`,Xd.autoUpdate,e=>void(async()=>{Xd&&(Xd.autoUpdate=e);let t=await b(`/api/settings`,{autoUpdate:e},`PUT`);t.ok||(Xd&&(Xd.autoUpdate=!e),u&&(u.checked=!e),s(!0,await x(t,`Could not save`)))})()),u=l.querySelector(`input`);return u&&(u.disabled=!i),e.append(R(`div`,`mt-1 border-t border-neutral-200 px-3 pb-1 pt-2`,l)),e}async function tf(e){let t=await Le(`/api/update`,`Update check failed`);t.ok&&Qd((Xd=t.value).current||e)}function nf(e){Qd(e),Zd.onclick=e=>{e.preventDefault(),bl(Zd,ef())};let t=()=>void tf(e);t(),setInterval(t,Yd)}var Q,rf=L(`#chat-header`),af=L(`#chat-title`),of=[rf,V,L(`#composer`)],sf=()=>mf===null,cf,lf,uf,df=new Map,ff=new Map,pf=new Map,mf=null,hf=0,gf=[`files`],_f=new Map,vf={tasks:`Tasks`,runs:`Runs`,activity:`Activity`,boards:`Boards`,settings:`Settings`,files:`Files`},yf=[`tasks`,`runs`,`activity`],bf=`Automation`,xf=L(`#automation-view`),Sf=L(`#automation-tabs`),Cf=e=>yf.includes(e)?`tasks`:e;function wf(e,t){let n=e!==null&&yf.includes(e);if(xf.classList.toggle(`hidden`,!n),xf.classList.toggle(`flex`,n),!n)return;let r=[];if(e===`tasks`&&!t){let e=Xr(`New task`,!0);e.classList.add(`ml-auto`),e.disabled=!cf,e.onclick=()=>cf?.create(),r.push(e)}Sf.replaceChildren(Qr(bf),...yf.map(t=>ti(vf[t],t===e,()=>kf(t))),...r)}var Tf=e=>cf?.refresh(e),Ef=()=>lf?.refresh(),Df=()=>uf?.refresh();function Of(){mf?zl(yf.includes(mf)?bf:vf[mf],!1):zl(af.textContent??``,Q.currentSession()!==void 0)}function kf(e,t,n){if(gf.includes(e)){let t=Vf();t&&(t.kind!==`console`||t.name!==e)&&_f.set(e,t)}Uf({kind:`console`,name:e,arg:t,query:n}),Rl(),mf=e;for(let e of of)e.classList.add(`hidden`);bc();for(let[t,n]of df)t!==e&&n.hide();for(let[t,n]of pf)n.classList.toggle(`bg-indigo-50`,t===Cf(e));wf(e,t),Of(),Af(e,t,n,++hf)}async function Af(e,t,n,r){let i=df.get(e);if(!i){let t=ff.get(e);if(!t){let n=L(`#${e}-view`);t=Kf[e](n).catch(t=>(console.warn(`${e} view failed to load`,t),Wr(n,()=>n.replaceChildren(R(`p`,`p-4 text-[13px] text-red-600`,`Could not load ${vf[e]} — reload the page.`))))),ff.set(e,t)}i=await t,df.set(e,i),ff.delete(e)}mf===e&&r===hf&&(i.show(t,n),e===`tasks`&&wf(e,t))}var jf=e=>kf(`tasks`,e),Mf=(e={},t)=>kf(`runs`,t,new URLSearchParams(e).toString()),Nf=e=>Mf({},e),Pf=e=>kf(`files`,e),Ff=(e,t)=>{mf===e?Lf(e):kf(e,t)},If=e=>Ff(`files`,e);function Lf(e){let t=Q.currentId(),n=_f.get(e)??(t?{kind:`session`,id:t}:null);_f.delete(e),n?Uf(n):(history.replaceState(null,``,`#/`),Rf())}function Rf(){if(mf){mf=null;for(let e of df.values())e.hide();for(let e of pf.values())e.classList.remove(`bg-indigo-50`);wf(null);for(let e of of)e.classList.remove(`hidden`);bc(),Of(),Q.maybeAckRead()}}var zf=e=>e.kind===`session`?`#/session/${encodeURIComponent(e.id)}`:`#/${e.name}${e.arg?`/${encodeURIComponent(e.arg)}`:``}${e.query?`?${e.query}`:``}`,Bf={config:`files`,channels:`channels`,providers:`models`};function Vf(){let e=location.hash.replace(/^#\/?/,``),t=e.indexOf(`?`),[n=``,r]=(t<0?e:e.slice(0,t)).split(`/`),i=t<0?void 0:e.slice(t+1)||void 0,a;try{a=r?decodeURIComponent(r):void 0}catch{return null}return Bf[n]?{kind:`console`,name:`settings`,arg:Bf[n]}:Object.hasOwn(vf,n)?{kind:`console`,name:n,arg:a,query:i}:n===`session`&&a?{kind:`session`,id:a}:null}var Hf=!1;function Uf(e,t=!1){if(Hf)return;let n=zf(e);location.hash!==n&&(t?history.replaceState(null,``,n):location.hash=n)}var Wf=e=>Uf({kind:`session`,id:e});function Gf(){let e=Vf(),t=Q.sessions(),n=Q.currentId(),r=e?.kind===`session`?e.id:null,{top:i,rest:a}=au(t),o=r??n??(i[0]??a[0])?.id??null;Hf=!0;try{o&&o!==n&&Q.select(o),e?.kind===`console`?kf(e.name,e.arg,e.query):Rf(),o||Dd()}finally{Hf=!1}e?.kind!==`console`&&o&&Uf({kind:`session`,id:o},!0)}var Kf={tasks:async e=>cf=(await Di(async()=>{let{createTasksView:e}=await import(`./tasks-BffPVgXg.js`);return{createTasksView:e}},__vite__mapDeps([0,1]))).createTasksView(e,()=>Q.sessions().map(({id:e,cwd:t,title:n})=>({id:e,cwd:t,title:n})),Q.loadSessions,Q.select,()=>Q.currentId(),Mf,jf),runs:async e=>lf=(await Di(async()=>{let{createRunsView:e}=await import(`./runs-Cv0A-e08.js`);return{createRunsView:e}},__vite__mapDeps([2,1]))).createRunsView(e,Q.select,Mf,jf),activity:async e=>uf=(await Di(async()=>{let{createActivityView:e}=await import(`./activity-DOr8dWeX.js`);return{createActivityView:e}},[])).createActivityView(e,Q.select,Nf),boards:async e=>(await Di(async()=>{let{createBoardsView:e}=await import(`./boards-CneyR23E.js`);return{createBoardsView:e}},[])).createBoardsView(e,Q.select),files:async e=>(await Di(async()=>{let{createExplorerView:e}=await import(`./explorer-D0srXT1c.js`);return{createExplorerView:e}},[])).createExplorerView(e,()=>Q.currentSession(),e=>kf(`files`,e),()=>Lf(`files`)),settings:async e=>(await Di(async()=>{let{createSettingsView:e}=await import(`./settings-VmCjhGBd.js`);return{createSettingsView:e}},[])).createSettingsView(e,()=>lu(Q.sessions()),e=>kf(`settings`,e))};function qf(e){Q=e;for(let e of[`tasks`,`boards`,`settings`]){let t=L(`#open-${e}`);pf.set(e,t),t.onclick=()=>kf(e)}let t=L(`#console-section`);t.open=localStorage.getItem(`pier.consoleCollapsed`)!==`1`,t.ontoggle=()=>localStorage.setItem(`pier.consoleCollapsed`,t.open?`0`:`1`),window.onhashchange=Gf}var Jf=[],Yf=null,Xf=0,Zf=0,Qf=!1,$=null,$f=`idle`,ep=null,tp=0,np=!1,rp=!1;async function ip(e){let t=++Xf;++Zf,Qf=!1,Rf(),Rl(),$=null,ep?.close(),ep=null,Ss(),xc([]),Sd(),Ed(e),Cs(!0),rp=!0,yc();let n=await b(`/api/sessions`,{cwd:e});if(t!==Xf)return;if(rp=!1,!n.ok){Cs(!1),Ed(null),yc(),H(`error`,`session create failed: ${n.status}`);return}let{id:r}=await n.json();t===Xf&&(Jf.unshift({id:r,cwd:e,createdAt:Date.now(),state:`idle`,unread:!1,channel:`web`,activeRuns:0}),await hp(r),$===r&&hc())}function ap(e){Jf=e.map(e=>({...e,title:Fe(e.title)})),Jf.sort((e,t)=>t.createdAt-e.createdAt),Su(),Dd(),sp()}var op=Ie(async()=>{ap(await Re(`/api/sessions`,`Could not load sessions`))});function sp(){if(document.hidden||!document.hasFocus()||!sf())return;let e=Jf.find(e=>e.id===$);e?.unread&&(e.unread=!1,Su(),fetch(`/api/sessions/${e.id}/read`,{method:`POST`}))}function cp(){return Jf.find(e=>e.id===$)??(Yf&&Yf.id===$?Yf:void 0)}async function lp(e){let t=await Le(`/api/sessions/${e}`,`failed to load session`);$!==e||!t.ok||(Yf={...t.value,title:Fe(t.value.title)},Dd())}function up(e,t){let n=Jf.find(t=>t.id===e);!n||n.title||!t.trim()||(n.title=t.trim().slice(0,80),Su(),Dd())}function dp(e){$f=e;let t=Jf.find(e=>e.id===$);t&&(t.state=e),Su(),Dd(),yc(),e===`idle`&&op()}function fp(e){if(!(e.sessionId!==$||e.seq<=tp))switch(tp=e.seq,e.type){case`turn-start`:np=!0;break;case`system-input`:vs(),Go(e.text,e.origin);break;case`task-status`:Ha(e.run);break;case`user-message`:{let t=Me(e.text).text;if(up(e.sessionId,t),gc(t))break;vs(),H(`user`,e.text,!1,e.ts),jo();break}case`text-start`:vs();break;case`text-delta`:_s(e.text);break;case`thinking-delta`:vs(),_o(e.ts,e.text);break;case`tool-start`:vs(),ho(e.ts,e.toolCallId,e.toolName,e.args);break;case`tool-end`:go(e.toolCallId,e.isError,e.output);break;case`turn-end`:np=!1,bs(e.text,e.meta),e.meta&&wd(e.meta);break;case`queue-state`:Sc(e.steering,e.followUp);break;case`queue-recovery`:xc(e.batches,e.uncertain);break;case`context-compacted`:vs(),H(`system`,`Context compacted — ${Ce(e.before)} → ${Ce(e.after)}`,!1,e.ts),jo();break;case`error`:po(),H(`error`,e.message);break;case`state`:e.state===`idle`&&np&&(np=!1,xs()),e.state===`idle`&&Sc([],[]),dp(e.state)}}function pp(){let e=new EventSource(`/api/events`);e.onopen=()=>{op(),Tf(),Ef(),Df()},e.onerror=()=>Is(e,`Workspace`),e.onmessage=e=>{let t=JSON.parse(e.data);if(t.type===`sessions-changed`){op();return}if(t.type===`tasks-changed`||t.type===`task-run-changed`||t.type===`task-message-changed`||t.type===`task-group-changed`){Tf(t.type===`task-run-changed`?t.taskId:void 0),Ef(),Df(),t.type===`task-run-changed`&&op();return}if(Df(),t.sessionId===$)return;let n=Jf.find(e=>e.id===t.sessionId);n&&(n.state=t.state,Su())}}function mp(e,t,n){ep?.close();let r=new EventSource(`/api/sessions/${e}/events?after=${t}`),i=()=>ep===r&&$===e&&n===Zf;r.onmessage=e=>{i()&&fp(JSON.parse(e.data))},r.addEventListener(`reset`,()=>{i()&&gp(e)}),r.onerror=()=>{i()&&Is(r,`Session`)},ep=r}async function hp(e){Rf(),Rl(),Wf(e),!(e===$&&(ep||Qf))&&(++Xf,++Zf,rp=!1,Mc(),$=e,Yf=null,Jf.some(t=>t.id===e)||lp(e),$f=Jf.find(t=>t.id===e)?.state??`idle`,Nc(e),Su(),Dd(),sp(),await gp(e))}async function gp(e){if($!==e)return;let t=++Zf;ep?.close(),ep=null,Qf=!0,Ss(),Sc([],[]),xc([]),Sd(),np=!1,vc(),tp=0,Cs(!0);let n=await Le(`/api/sessions/${e}/history`,`failed to load session`);if($!==e||t!==Zf)return;if(Qf=!1,!n.ok){Cs(!1),H(`error`,n.error);return}let r=n.value;ws(r.turns,r.state,r.backgroundRuns),tp=r.lastSeq,np=r.state===`streaming`,dp(r.state),Sc(r.queue.steering,r.queue.followUp),xc(r.queueRecovery,r.queueUncertain);let i=r.turns.reduce((e,t)=>t.meta?.completedAt??e,null);Cd(r.model,r.context,r.thinkingLevel,i),mp(e,`${r.epoch}:${r.lastSeq}`,t)}Ms(),ye(),Fs(),Gd();var _p=async e=>{$===e&&await gp(e)};Co({sessionId:()=>$,sessionState:()=>$f,select:e=>void hp(e),showRun:Nf,send:(e,t)=>void Ic(e,t),ownTurn:e=>{_c(e),dp(`streaming`)},reload:_p}),zc({sessionId:()=>$,starting:()=>rp,sessionState:()=>$f,chatVisible:sf,setState:dp,reload:_p}),tu({sessionMenu:e=>{let t=cp();t&&Ld(e,t)},sessionInfo:e=>{let t=cp();t&&Md(e,t)}}),wu({sessions:()=>Jf,currentId:()=>$,select:e=>void hp(e),sessionMenu:Ld,createSession:ip,onTitleChanged:Dd}),rd({sessions:()=>Jf,loadSessions:op,currentId:()=>$,select:hp,createSession:ip,openConsole:kf}),dd({currentId:()=>$,currentSession:cp,createSession:e=>void ip(e),syncBar:Of,openFiles:Pf,toggleFiles:If}),qf({sessions:()=>Jf,loadSessions:op,currentId:()=>$,currentSession:cp,select:e=>void hp(e),maybeAckRead:sp}),nf(`0.1.2`),el(),document.addEventListener(`gesturestart`,e=>e.preventDefault()),document.addEventListener(`visibilitychange`,sp),window.addEventListener(`focus`,sp),pp(),op().then(Gf);export{g as $,pi as A,Yr as B,ai as C,ti as D,Qr as E,_i as F,Ie as G,R as H,zr as I,Re as J,x as K,Br as L,ui as M,di as N,ei as O,$r as P,Se as Q,Wr as R,hi as S,ci as T,Rr as U,Ur as V,Vr as W,b as X,ze as Y,Fe as Z,fi as _,q as a,a as at,Xr as b,Ys as c,Li as d,ve as et,Ii as f,ri as g,ni as h,Al as i,o as it,si as j,li as k,Da as l,oi as m,ld as n,m as nt,bl as o,Ni as p,Le as q,Nl as r,l as rt,al as s,ud as t,de as tt,Oa as u,mi as v,gi as w,ii as x,Zr as y,Jr as z};
|
|
Binary file
|
|
Binary file
|