@timqi/pier 0.1.3 → 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 +9 -3
- package/dist/agent/events.js +1 -2
- package/dist/agent/packages.js +1 -7
- package/dist/agent/pi.js +6 -47
- 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/db.js +28 -0
- package/dist/main.js +19 -32
- package/dist/paths.js +3 -0
- package/dist/secrets.js +2 -1
- 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 +17 -0
- package/dist/vault.js +107 -0
- package/dist/web/auth.js +2 -1
- package/dist/web/public/assets/{activity-BSMeRcN2.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-BCWQMZry.js → boards-DleegoiC.js} +1 -1
- 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-Cr4XTi4j.js → explorer-vJvV1Sx0.js} +1 -1
- 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-DVIt5Gio.css → index-Bs-gol9o.css} +1 -1
- package/dist/web/public/assets/index-Bs-gol9o.css.br +0 -0
- package/dist/web/public/assets/{index-DVIt5Gio.css.gz → 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-DdERzeac.js → runs-C5FveZ75.js} +1 -1
- 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-C-dGUDsH.js → task-runs-CJJ2j5Ks.js} +1 -1
- 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-CY30H1u1.js → tasks-R2Pv0Abg.js} +1 -1
- 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/vault.js +68 -0
- package/docs/deploy.md +33 -10
- 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-BSMeRcN2.js.br +0 -0
- package/dist/web/public/assets/activity-BSMeRcN2.js.gz +0 -0
- package/dist/web/public/assets/boards-BCWQMZry.js.br +0 -0
- package/dist/web/public/assets/boards-BCWQMZry.js.gz +0 -0
- package/dist/web/public/assets/explorer-Cr4XTi4j.js.br +0 -0
- package/dist/web/public/assets/explorer-Cr4XTi4j.js.gz +0 -0
- package/dist/web/public/assets/index-C7tA0Ufu.js +0 -85
- package/dist/web/public/assets/index-C7tA0Ufu.js.br +0 -0
- package/dist/web/public/assets/index-C7tA0Ufu.js.gz +0 -0
- package/dist/web/public/assets/index-DVIt5Gio.css.br +0 -0
- package/dist/web/public/assets/runs-DdERzeac.js.br +0 -0
- package/dist/web/public/assets/runs-DdERzeac.js.gz +0 -0
- package/dist/web/public/assets/settings-CQDAHoMM.js +0 -5
- package/dist/web/public/assets/settings-CQDAHoMM.js.br +0 -0
- package/dist/web/public/assets/settings-CQDAHoMM.js.gz +0 -0
- package/dist/web/public/assets/task-runs-C-dGUDsH.js.br +0 -0
- package/dist/web/public/assets/task-runs-C-dGUDsH.js.gz +0 -0
- package/dist/web/public/assets/tasks-CY30H1u1.js.br +0 -0
- package/dist/web/public/assets/tasks-CY30H1u1.js.gz +0 -0
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/tasks-CY30H1u1.js","assets/task-runs-C-dGUDsH.js","assets/runs-DdERzeac.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`}]],f=[[`path`,{d:`M20 4v7a4 4 0 0 1-4 4H4`}],[`path`,{d:`m9 10-5 5 5 5`}]],p=[[`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`}]],m=[[`circle`,{cx:`12`,cy:`12`,r:`1`}],[`circle`,{cx:`19`,cy:`12`,r:`1`}],[`circle`,{cx:`5`,cy:`12`,r:`1`}]],ee=[[`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`}]],te=[[`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`}]],ne=[[`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`}]],re=[[`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`}]],h=[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`}]],ie=[[`path`,{d:`M4 5h16`}],[`path`,{d:`M4 12h16`}],[`path`,{d:`M4 19h16`}]],ae=[[`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`}]],oe=[[`path`,{d:`M5 12h14`}]],se=[[`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`}]],g=[[`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`}]],ce=[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`}]],le=[[`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`}]],ue=[[`path`,{d:`M5 12h14`}],[`path`,{d:`M12 5v14`}]],de=[[`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`}]],fe=[[`path`,{d:`m21 21-4.34-4.34`}],[`circle`,{cx:`11`,cy:`11`,r:`8`}]],pe=[[`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`}]],me=[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}]],he=[[`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`}]],ge=[[`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`}]],_e=[[`path`,{d:`M18 6 6 18`}],[`path`,{d:`m6 6 12 12`}]],_=(e,t=`h-3.5 w-3.5`)=>n(e,{class:`flex-none ${t}`,"aria-hidden":`true`,focusable:`false`});function ve(){let e={ArrowUp:a,ChevronLeft:c,ChevronRight:l,Clock:d,Ellipsis:m,LayoutDashboard:ne,ListTodo:re,Menu:ie,Plus:ue,RotateCw:de,Search:fe,Settings:pe,Square:me,Undo2:ge,X:_e};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(_(n,`h-full w-full`))}let t=_(s);t.setAttribute(`stroke`,`#737373`),document.documentElement.style.setProperty(`--select-chevron`,`url("data:image/svg+xml,${encodeURIComponent(t.outerHTML)}")`)}var ye=/[\u201c\u201d"\u2018\u2019'()\uff08\uff09\u300c\u300d\u300e\u300f\u3010\u3011\u300a\u300b\u3008\u3009[\]]/;function be(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&&ye.test(i[0]);)n+=i[0],i=i.slice(1);for(;i.length>1&&ye.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 v=e=>!e.text.trim()&&e.suggestions.length===0,xe=e=>e===`xhigh`?`Extra high`:e[0].toUpperCase()+e.slice(1),Se=e=>{if(e<1e3)return String(e);let t=e/1e3;return t>=9.95?`${Math.round(t)}K`:`${t.toFixed(1)}K`},Ce=/(?:^|\n)[ \t]*-{3,}[ \t]*\r?\n((?:[ \t]*\[[^\]\r\n]+\][ \t]*(?:[||][ \t]*)?)+)\s*$/,we=/\[([^\]\r\n]+)\]/g,Te=5,Ee=/<silent>([\s\S]*?)<\/silent>/gi;function De(e){let t=[...e.matchAll(Ee)].map(e=>(e[1]??``).trim()).filter(Boolean);return t.length?t.join(` · `):void 0}function Oe(e,t){let n=ke(e),r=De(e),i=Ce.exec(n);if(!i?.[1])return{text:n,suggestions:[],meta:t,silence:r};let a=[...i[1].matchAll(we)].map(e=>(e[1]??``).trim()).filter(Boolean).slice(0,Te);return a.length?{text:n.slice(0,i.index).trimEnd(),suggestions:a,meta:t,silence:r}:{text:n,suggestions:[],meta:t,silence:r}}var ke=e=>be(e.replace(Ee,``).trim()),y=/^(?:\s|[-*+>]|\d+[.)])/;function Ae(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&&!(y.test(s)&&y.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 b=/^\[(?:([^\n[\]<>]*)<([^\n[\]<>]+)>)? ?((?:\d{4}-\d{2}-\d{2} )?\d{1,2}:\d{2})?\]\n/;function je(e){let t=b.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 Me=/(?:\n\[[^\]\n]*(?:\]\(\s*<?file:\/\/[^\n]*|$))+$/,Ne=/^\s*`[^`\n]{40,}`\s+(\S[\s\S]*)$/;function Pe(e){if(!e)return e;let{text:t}=je(e);return t===e?e:t.replace(Me,``).replace(Ne,`$1`).replace(/\s+/g,` `).trim()||e}function Fe(e){let t,n=!1;return()=>(n=!0,t??=(async()=>{for(;n;)n=!1,await e()})().finally(()=>{t=void 0}))}var Ie=(e,t)=>({method:t,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),x=(e,t,n=`POST`)=>fetch(e,Ie(t,n)),Le=(e,t,n,r=`POST`)=>C(e,n,Ie(t,r));async function S(e,t){return(await e.json().catch(()=>({}))).error??`${t} (${e.status})`}async function C(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 S(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 C(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 S(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,w=Object.freeze,T=Object.seal,Ze=Object.create,Qe=typeof Reflect<`u`&&Reflect,$e=Qe.apply,et=Qe.construct;w||=function(e){return e},T||=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=O(Array.prototype.forEach),nt=O(Array.prototype.lastIndexOf),rt=O(Array.prototype.pop),it=O(Array.prototype.push),at=O(Array.prototype.splice),ot=Array.isArray,st=O(String.prototype.toLowerCase),ct=O(String.prototype.toString),lt=O(String.prototype.match),ut=O(String.prototype.replace),dt=O(String.prototype.indexOf),ft=O(String.prototype.trim),pt=O(Number.prototype.toString),mt=O(Boolean.prototype.toString),ht=typeof BigInt>`u`?null:O(BigInt.prototype.toString),gt=typeof Symbol>`u`?null:O(Symbol.prototype.toString),E=O(Object.prototype.hasOwnProperty),_t=O(Object.prototype.toString),D=O(RegExp.prototype.test),vt=yt(TypeError);function O(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 k(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++)E(e,t)||(e[t]=null);return e}function A(e){let t=Ze(null);for(let r of Ke(e)){var n=We(r,2);let i=n[0],a=n[1];E(e,i)&&(t[i]=ot(a)?bt(a):a&&typeof a==`object`&&a.constructor===Object?A(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 O(n.get);if(typeof n.value==`function`)return O(n.value)}e=Ye(e)}function n(){return null}return n}function Ct(e){try{return D(e,``),!0}catch{return!1}}var wt=w(`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=w(`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=w([`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=w([`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=w(`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=w([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),At=w([`#text`]),jt=w(`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=w(`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=w(`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=w([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),Ft=T(/{{[\w\W]*|^[\w\W]*}}/g),It=T(/<%[\w\W]*|^[\w\W]*%>/g),Lt=T(/\${[\w\W]*/g),Rt=T(/^data-[\-\w.\u00B7-\uFFFF]+$/),zt=T(/^aria-[\-\w]+$/),Bt=T(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Vt=T(/^(?:\w+script|data):/i),Ht=T(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Ut=T(/^html$/i),Wt=T(/^[a-z][.\w]*(-[.\w]+)+$/i),Gt=T(/<[/\w!]/g),Kt=T(/<[/\w]/g),qt=T(/<\/no(script|embed|frames)/i),Jt=T(/\/>/i),j={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=w(k({},Yt)),Zt=function(){let e={};return tt(Yt,t=>{e[t]=T(RegExp(`</`+t+`(?=[\\t\\n\\f\\r />])`,`i`))}),w(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 E(e,t)&&ot(e[t])?k(r.base?A(r.base):{},e[t],r.transform):n},nn=function(e,t,n){let r=E(e,t)?e[t]:void 0;return r&&typeof r==`object`?A(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!==j.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,f=St(d,`cloneNode`),p=St(d,`remove`),m=St(d,`nextSibling`),ee=St(d,`childNodes`),te=St(d,`parentNode`),ne=St(d,`shadowRoot`),re=St(d,`attributes`),h=o&&o.prototype?St(o.prototype,`nodeType`):null,ie=o&&o.prototype?St(o.prototype,`nodeName`):null,ae=o&&o.prototype?St(o.prototype,`ownerDocument`):null,oe=function(e){return h?h(e):e.nodeType},se=function(e){return ie?ie(e):e.nodeName};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let g,ce=``,le,ue=!1,de=0,fe=function(){if(de>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.`)},pe=function(e){fe(),de++;try{return g.createHTML(e)}finally{de--}},me=function(e){fe(),de++;try{return g.createScriptURL(e)}finally{de--}},he=function(){return ue||=(le=$t(u,i),!0),le},ge=n,_e=ge.implementation,_=ge.createNodeIterator,ve=ge.createDocumentFragment,ye=ge.getElementsByTagName,be=r.importNode,v=en();t.isSupported=typeof Ke==`function`&&typeof te==`function`&&_e&&_e.createHTMLDocument!==void 0;let xe=Ft,Se=It,Ce=Lt,we=Rt,Te=zt,Ee=Vt,De=Ht,Oe=Wt,ke=Bt,y=null,Ae=k({},[...wt,...Tt,...Et,...Ot,...At]),b=null,je=k({},[...jt,...Mt,...Nt,...Pt]),Me=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}})),Ne=null,Pe=null,Fe=Object.seal(Ze(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Ie=!0,x=!0,Le=!1,S=!0,C=!1,Re=!0,ze=!1,Be=!1,Ve=null,He=null,Ue=!1,We=!1,Ge=!1,qe=!1,Je=!0,Ye=!1,Xe=`user-content-`,Qe=!0,$e=!1,et={},pt=null,mt=k({},`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(`.`)),ht=null,gt=k({},[`audio`,`video`,`img`,`source`,`image`,`track`]),_t=null,O=k({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),yt=`http://www.w3.org/1998/Math/MathML`,bt=`http://www.w3.org/2000/svg`,Yt=`http://www.w3.org/1999/xhtml`,an=Yt,on=!1,sn=null,cn=k({},[yt,bt,Yt],ct),ln=w([`mi`,`mo`,`mn`,`ms`,`mtext`]),un=k({},ln),M=w([`annotation-xml`]),dn=k({},M),N=k({},[`title`,`style`,`font`,`a`,`script`]),fn=null,pn=[`application/xhtml+xml`,`text/html`],P=null,mn=null,hn=n.createElement(`form`),gn=function(e){return e instanceof RegExp||e instanceof Function},_n=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(mn&&mn===e)return;(!e||typeof e!=`object`)&&(e={}),e=A(e),fn=pn.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,P=fn===`application/xhtml+xml`?ct:st,y=tn(e,`ALLOWED_TAGS`,Ae,{transform:P}),b=tn(e,`ALLOWED_ATTR`,je,{transform:P}),sn=tn(e,`ALLOWED_NAMESPACES`,cn,{transform:ct}),_t=tn(e,`ADD_URI_SAFE_ATTR`,O,{transform:P,base:O}),ht=tn(e,`ADD_DATA_URI_TAGS`,gt,{transform:P,base:gt}),pt=tn(e,`FORBID_CONTENTS`,mt,{transform:P}),Ne=tn(e,`FORBID_TAGS`,A({}),{transform:P}),Pe=tn(e,`FORBID_ATTR`,A({}),{transform:P}),et=E(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?A(e.USE_PROFILES):e.USE_PROFILES:!1,Ie=e.ALLOW_ARIA_ATTR!==!1,x=e.ALLOW_DATA_ATTR!==!1,Le=e.ALLOW_UNKNOWN_PROTOCOLS||!1,S=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,C=e.SAFE_FOR_TEMPLATES||!1,Re=e.SAFE_FOR_XML!==!1,ze=e.WHOLE_DOCUMENT||!1,We=e.RETURN_DOM||!1,Ge=e.RETURN_DOM_FRAGMENT||!1,qe=e.RETURN_TRUSTED_TYPE||!1,Ue=e.FORCE_BODY||!1,Je=e.SANITIZE_DOM!==!1,Ye=e.SANITIZE_NAMED_PROPS||!1,Qe=e.KEEP_CONTENT!==!1,$e=e.IN_PLACE||!1,ke=Ct(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:Bt,an=typeof e.NAMESPACE==`string`?e.NAMESPACE:Yt,un=nn(e,`MATHML_TEXT_INTEGRATION_POINTS`,()=>k({},ln)),dn=nn(e,`HTML_INTEGRATION_POINTS`,()=>k({},M));let t=nn(e,`CUSTOM_ELEMENT_HANDLING`,()=>Ze(null));if(Me=Ze(null),E(t,`tagNameCheck`)&&gn(t.tagNameCheck)&&(Me.tagNameCheck=t.tagNameCheck),E(t,`attributeNameCheck`)&&gn(t.attributeNameCheck)&&(Me.attributeNameCheck=t.attributeNameCheck),E(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(Me.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),T(Me),C&&(x=!1),Ge&&(We=!0),et&&(y=k({},At),b=Ze(null),et.html===!0&&(k(y,wt),k(b,jt)),et.svg===!0&&(k(y,Tt),k(b,Mt),k(b,Pt)),et.svgFilters===!0&&(k(y,Et),k(b,Mt),k(b,Pt)),et.mathMl===!0&&(k(y,Ot),k(b,Nt),k(b,Pt))),Fe.tagCheck=null,Fe.attributeCheck=null,E(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?Fe.tagCheck=e.ADD_TAGS:ot(e.ADD_TAGS)&&(y===Ae&&(y=A(y)),k(y,e.ADD_TAGS,P))),E(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?Fe.attributeCheck=e.ADD_ATTR:ot(e.ADD_ATTR)&&(b===je&&(b=A(b)),k(b,e.ADD_ATTR,P))),E(e,`ADD_FORBID_CONTENTS`)&&ot(e.ADD_FORBID_CONTENTS)&&(pt===mt&&(pt=A(pt)),k(pt,e.ADD_FORBID_CONTENTS,P)),Qe&&(y[`#text`]=!0),ze&&k(y,[`html`,`head`,`body`]),y.table&&(k(y,[`tbody`]),delete Ne.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=g;g=e.TRUSTED_TYPES_POLICY;try{ce=pe(``)}catch(e){throw g=t,e}}else e.TRUSTED_TYPES_POLICY===null?(g=void 0,ce=``):(g===void 0&&(g=he()),g&&typeof ce==`string`&&(ce=pe(``)));w&&w(e),mn=e},vn=k({},[...Tt,...Et,...Dt]),yn=k({},[...Ot,...kt]),bn=function(e,t,n){return t.namespaceURI===Yt?e===`svg`:t.namespaceURI===yt?e===`svg`&&(n===`annotation-xml`||un[n]):!!vn[e]},xn=function(e,t,n){return t.namespaceURI===Yt?e===`math`:t.namespaceURI===bt?e===`math`&&dn[n]:!!yn[e]},Sn=function(e,t,n){return t.namespaceURI===bt&&!dn[n]||t.namespaceURI===yt&&!un[n]?!1:!yn[e]&&(N[e]||!vn[e])},Cn=function(e){let t=te(e);(!t||!t.tagName)&&(t={namespaceURI:an,tagName:`template`});let n=st(e.tagName),r=st(t.tagName);return sn[e.namespaceURI]?e.namespaceURI===bt?bn(n,t,r):e.namespaceURI===yt?xn(n,t,r):e.namespaceURI===Yt?Sn(n,t,r):!!(fn===`application/xhtml+xml`&&sn[e.namespaceURI]):!1},wn=function(e){it(t.removed,{element:e});try{te(e).removeChild(e)}catch{if(p(e),!te(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`)}},Tn=function(e,t,n){try{e.removeAttributeNode(t)}catch{try{e.removeAttribute(n)}catch{}}},En=function(e){kn(e);let t=ee(e);if(t){let e=[];tt(t,t=>{it(e,t)}),tt(e,e=>{try{p(e)}catch{}})}let n=re(e);if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;typeof i==`string`&&Tn(e,r,i)}},Dn=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(We||Ge)try{wn(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},On=function(e){let t=re(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;typeof i!=`string`||b[P(i)]||Tn(e,r,i)}},kn=function(e){let t=[e];for(;t.length>0;){let e=t.pop();oe(e)===j.element&&On(e);let n=ee(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},An=function(e,t){return Re?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},jn=function(e){if(!Re)return;let t=[e];for(;t.length>0;){let e=t.pop(),n=oe(e);if(n===j.processingInstruction||n===j.comment&&D(Kt,e.data)){try{p(e)}catch{}continue}if(n===j.element){let t=e,n=P(se(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&An(`for`,n)&&t.removeAttribute(`for`)}catch{}}let r=ee(e);if(r)for(let e=r.length-1;e>=0;--e)t.push(r[e])}},Mn=function(e){let t=null,r=null;if(Ue)e=`<remove></remove>`+e;else{let t=lt(e,/^[\r\n\t ]+/);r=t&&t[0]}fn===`application/xhtml+xml`&&an===Yt&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=g?pe(e):e;if(an===Yt)try{t=new l().parseFromString(i,fn)}catch{}if(!t||!t.documentElement){t=_e.createDocument(an,`template`,null);try{t.documentElement.innerHTML=on?ce:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),an===Yt?ye.call(t,ze?`html`:`body`)[0]:ze?t.documentElement:a},Nn=function(e){let t=ae?ae(e):e.ownerDocument;return _.call(t||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},Pn=function(e){return e=ut(e,xe,` `),e=ut(e,Se,` `),e=ut(e,Ce,` `),e},Fn=function(e){e.normalize();let t=ae?ae(e):e.ownerDocument,n=_.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=Pn(r.data),r=n.nextNode();let i=e.querySelectorAll?.call(e,`template`);i&&tt(i,e=>{Ln(e.content)&&Fn(e.content)})},In=function(e){let t=ie?ie(e):null;return typeof t!=`string`||P(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==re(e)||typeof e.removeAttribute!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==h(e)||e.childNodes!==ee(e)},Ln=function(e){if(!h||typeof e!=`object`||!e)return!1;try{return h(e)===j.documentFragment}catch{return!1}},Rn=function(e){if(!h||typeof e!=`object`||!e)return!1;try{return typeof h(e)==`number`}catch{return!1}};function F(e,n,r){e.length!==0&&tt(e,e=>{e.call(t,n,r,mn)})}let zn=function(e,t){return!!(Re&&e.hasChildNodes()&&!Rn(e.firstElementChild)&&D(Gt,e.textContent)&&D(Gt,e.innerHTML)||Re&&e.namespaceURI===Yt&&Xt[t]&&(Rn(e.firstElementChild)||typeof e.textContent==`string`&&D(Zt[t],e.textContent))||e.nodeType===j.processingInstruction||Re&&e.nodeType===j.comment&&D(Kt,e.data))},Bn=function(e,t){return e instanceof RegExp?D(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},Vn=function(e,t,n){if(!Ne[t]&&qn(t)&&Bn(Me.tagNameCheck,t))return!1;if(Qe&&!pt[t]){let t=te(e),r=ee(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?f(r[a],!0):r[a];t.insertBefore(i,m(e))}}}return wn(e),!0},Hn=function(e,t,n,r){return e.length===0?t:t===n||t===r?A(t):t},Un=function(e,t){return e===t||te(e)!==null?!1:($e&&kn(e),!0)},Wn=function(e,n){if(F(v.beforeSanitizeElements,e,null),Un(e,n))return!0;if(In(e))return wn(e),!0;let r=P(se(e));if(y=Hn(v.uponSanitizeElement,y,Ae,Ve),F(v.uponSanitizeElement,e,{tagName:r,allowedTags:y}),Un(e,n))return!0;if(zn(e,r))return wn(e),!0;if(Ne[r]||!(Fe.tagCheck instanceof Function&&Fe.tagCheck(r))&&!y[r]){let t=Vn(e,r,n);return t===!1&&F(v.afterSanitizeElements,e,null),t}if(oe(e)===j.element&&!Cn(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&D(qt,e.innerHTML))return wn(e),!0;if(C&&e.nodeType===j.text){let n=Pn(e.textContent);e.textContent!==n&&(it(t.removed,{element:e.cloneNode()}),e.textContent=n)}return F(v.afterSanitizeElements,e,null),!1},Gn=function(e,t,r){if(Pe[t]||An(t,e)||Je&&(t===`id`||t===`name`)&&(r in n||r in hn))return!1;let i=b[t]||Fe.attributeCheck instanceof Function&&Fe.attributeCheck(t,e);return x&&D(we,t)||Ie&&D(Te,t)?!0:i?_t[t]||D(ke,ut(r,De,``))||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&dt(r,`data:`)===0&&ht[e]||Le&&!D(Ee,ut(r,De,``))?!0:!r:qn(e)&&Bn(Me.tagNameCheck,e)&&Bn(Me.attributeNameCheck,t,e)||t===`is`&&Me.allowCustomizedBuiltInElements&&Bn(Me.tagNameCheck,r)},Kn=k({},[`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)]&&D(Oe,e)},Jn=function(e,t,n,r){if(g&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return pe(r);case`TrustedScriptURL`:return me(r)}return r},Yn=function(e,n,r,i){try{r?e.setAttributeNS(r,n,i):e.setAttribute(n,i),In(e)?wn(e):rt(t.removed)}catch{Dn(n,e)}},Xn=function(e){F(v.beforeSanitizeAttributes,e,null);let t=e.attributes;if(!t||In(e))return;b=Hn(v.uponSanitizeAttribute,b,je,He);let n={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:b,forceKeepAttr:void 0},r=t.length,i=P(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=P(o),u=c,d=o===`value`?u:ft(u);if(n.attrName=l,n.attrValue=d,n.keepAttr=!0,n.forceKeepAttr=void 0,F(v.uponSanitizeAttribute,e,n),d=n.attrValue,Ye&&(l===`id`||l===`name`)&&dt(d,Xe)!==0&&(Dn(o,e,a),d=Xe+d),Re&&D(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){Dn(o,e,a);continue}if(l===`attributename`&<(d,`href`)){Dn(o,e,a);continue}if(!n.forceKeepAttr){if(!n.keepAttr){Dn(o,e,a);continue}if(!S&&D(Jt,d)){Dn(o,e,a);continue}if(C&&(d=Pn(d)),!Gn(i,l,d)){Dn(o,e,a);continue}d=Jn(i,l,s,d),d!==u&&Yn(e,o,s,d)}}F(v.afterSanitizeAttributes,e,null)},Zn=function(e){let t=null,n=Nn(e);for(F(v.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(F(v.uponSanitizeShadowNode,t,null),Wn(t,e),Xn(t),Ln(t.content)&&Zn(t.content),oe(t)===j.element){let e=ne(t);Ln(e)&&(Qn(e),Zn(e))}F(v.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=oe(n)===j.element,i=ee(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=ie?ie(n):null;if(typeof e==`string`&&P(e)===`template`){let e=n.content;Ln(e)&&t.push({node:e,shadow:null})}}if(r){let e=ne(n);Ln(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(on=!e,on&&(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;Be?(y=Ve,b=He):_n(n),(v.uponSanitizeElement.length>0||v.uponSanitizeAttribute.length>0)&&(y=A(y)),v.uponSanitizeAttribute.length>0&&(b=A(b)),t.removed=[];let c=$e&&typeof e!=`string`&&Rn(e);if(c){jn(e);let t=se(e);if(typeof t==`string`){let n=P(t);if(!y[n]||Ne[n])throw En(e),vt(`root node is forbidden and cannot be sanitized in-place`)}if(In(e))throw En(e),vt(`root node is clobbered and cannot be sanitized in-place`);try{Qn(e)}catch(t){throw En(e),t}}else if(Rn(e))i=Mn(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===j.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),Qn(a);else{if(!We&&!C&&!ze&&e.indexOf(`<`)===-1)return g&&qe?pe(e):e;if(i=Mn(e),!i)return We?null:qe?ce:``}i&&Ue&&wn(i.firstChild);let l=c?e:i;try{let e=Nn(l);for(;o=e.nextNode();)Wn(o,l),Xn(o),Ln(o.content)&&Zn(o.content)}catch(n){throw c&&(En(e),tt(t.removed,e=>{e.element&&kn(e.element)})),n}if(c)return tt(t.removed,e=>{e.element&&kn(e.element)}),C&&Fn(e),e;if(We){if(C&&Fn(i),Ge)for(s=ve.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(b.shadowroot||b.shadowrootmode)&&(s=be.call(r,s,!0)),s}let u=ze?i.outerHTML:i.innerHTML;return ze&&y[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&D(Ut,i.ownerDocument.doctype.name)&&(u=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
|
|
6
|
-
`+u),C&&(u=Pn(u)),g&&qe?pe(u):u},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};_n(e),Be=!0,Ve=y,He=b},t.clearConfig=function(){mn=null,Be=!1,Ve=null,He=null,g=le,ce=``},t.isValidAttribute=function(e,t,n){mn||_n({});let r=P(e),i=P(t);return Gn(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&E(v,e)&&it(v[e],t)},t.removeHook=function(e,t){if(E(v,e)){if(t!==void 0){let n=nt(v[e],t);return n===-1?void 0:at(v[e],n,1)[0]}return rt(v[e])}},t.removeHooks=function(e){E(v,e)&&(v[e]=[])},t.removeAllHooks=function(){v=en()},t}var an=rn();function on(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var sn=on();function cn(e){sn=e}var ln={exec:()=>null};function un(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 M(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(N.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var dn=((e=``)=>{try{return!!RegExp(`(?<=1)(?<!1)`+e)}catch{return!1}})(),N={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:un(e=>RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:un(e=>RegExp(`^ {0,${e}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:un(e=>RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:un(e=>RegExp(`^ {0,${e}}#`)),htmlBeginRegex:un(e=>RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`,`i`)),blockquoteBeginRegex:un(e=>RegExp(`^ {0,${e}}>`))},fn=/^(?:[ \t]*(?:\n|$))+/,pn=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,P=/^ {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+|$)/,hn=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,gn=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,_n=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,vn=M(_n).replace(/bull/g,gn).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(),yn=M(_n).replace(/bull/g,gn).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(),bn=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,xn=/^[^\n]+/,Sn=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Cn=M(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,Sn).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),wn=M(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,gn).getRegex(),Tn=`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`,En=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Dn=M(`^ {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`,En).replace(`tag`,Tn).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),On=e=>M(bn).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`,Tn).getRegex(),kn=On(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),An=On(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),jn={blockquote:M(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,An).getRegex(),code:pn,def:Cn,fences:P,heading:hn,hr:mn,html:Dn,lheading:vn,list:wn,newline:fn,paragraph:kn,table:ln,text:xn},Mn=M(`^ *([^\\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`,Tn).getRegex(),Nn={...jn,lheading:yn,table:Mn,paragraph:M(bn).replace(`hr`,mn).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,Mn).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`,Tn).getRegex()},Pn={...jn,html:M(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,En).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:ln,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:M(bn).replace(`hr`,mn).replace(`heading`,` *#{1,6} *[^
|
|
7
|
-
]`).replace(`lheading`,vn).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},Fn=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,In=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Ln=/^( {2,}|\\)\n(?!\s*$)/,Rn=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,F=/[\p{P}\p{S}]/u,zn=/[\s\p{P}\p{S}]/u,Bn=/[^\s\p{P}\p{S}]/u,Vn=M(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,zn).getRegex(),Hn=/[\p{Pi}\p{Ps}"']/u,Un=/(?!~)[\p{P}\p{S}]/u,Wn=/(?!~)[\s\p{P}\p{S}]/u,Gn=/(?:[^\s\p{P}\p{S}]|~)/u,Kn=M(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,dn?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),qn=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Jn=M(qn,`u`).replace(/punct/g,F).getRegex(),Yn=M(qn,`u`).replace(/punct/g,Un).getRegex(),Xn=M(/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,`u`).replace(/openQuote/g,Hn).replace(/punct/g,F).getRegex(),Zn=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,Qn=M(Zn,`gu`).replace(/notPunctSpace/g,Bn).replace(/punctSpace/g,zn).replace(/punct/g,F).getRegex(),$n=M(Zn,`gu`).replace(/notPunctSpace/g,Gn).replace(/punctSpace/g,Wn).replace(/punct/g,Un).getRegex(),er=M(`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,Bn).replace(/punctSpace/g,zn).replace(/punct/g,F).getRegex(),tr=M(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,Bn).replace(/punctSpace/g,zn).replace(/punct/g,F).getRegex(),nr=M(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,Bn).replace(/punctSpace/g,zn).replace(/punct/g,F).getRegex(),rr=M(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,F).getRegex(),ir=M(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,Bn).replace(/punctSpace/g,zn).replace(/punct/g,F).getRegex(),ar=M(/\\(punct)/,`gu`).replace(/punct/g,F).getRegex(),or=M(/^<(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(),sr=M(En).replace(`(?:-->|$)`,`-->`).getRegex(),cr=M(`^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`,sr).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),lr=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,ur=M(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace(`label`,lr).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),dr=M(/^!?\[(label)\]\[(ref)\]/).replace(`label`,lr).replace(`ref`,Sn).getRegex(),fr=M(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,Sn).getRegex(),pr=M(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,dr).replace(`nolink`,fr).getRegex(),mr=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,hr={_backpedal:ln,anyPunctuation:ar,autolink:or,blockSkip:Kn,br:Ln,code:In,del:ln,delLDelim:ln,delRDelim:ln,emStrongLDelim:Jn,emStrongRDelimAst:Qn,emStrongRDelimUnd:tr,escape:Fn,link:ur,nolink:fr,punctuation:Vn,reflink:dr,reflinkSearch:pr,tag:cr,text:Rn,url:ln},gr={...hr,emStrongLDelim:Xn,emStrongRDelimAst:er,emStrongRDelimUnd:nr,link:M(/^!?\[(label)\]\((.*?)\)/).replace(`label`,lr).getRegex(),reflink:M(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,lr).getRegex()},_r={...hr,emStrongRDelimAst:$n,emStrongLDelim:Yn,delLDelim:rr,delRDelim:ir,url:M(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,mr).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:M(/^(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace(`protocol`,mr).getRegex()},vr={..._r,br:M(Ln).replace(`{2,}`,`*`).getRegex(),text:M(_r.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},yr={normal:jn,gfm:Nn,pedantic:Pn},br={normal:hr,gfm:_r,breaks:vr,pedantic:gr},xr={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},Sr=e=>xr[e];function Cr(e,t){if(t){if(N.escapeTest.test(e))return e.replace(N.escapeReplace,Sr)}else if(N.escapeTestNoEncode.test(e))return e.replace(N.escapeReplaceNoEncode,Sr);return e}function wr(e){try{e=encodeURI(e).replace(N.percentDecode,`%`)}catch{return null}return e}function Tr(e,t){let n=e.replace(N.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(N.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(N.slashPipe,`|`);return n}function Er(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 Dr(e){let t=e.split(`
|
|
8
|
-
`),n=t.length-1;for(;n>=0&&N.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
|
|
9
|
-
`)}function Or(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 kr(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 Ar(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 jr(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 Mr=class{options;rules;lexer;constructor(e){this.options=e||sn}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]:Dr(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=jr(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=Er(e,`#`);(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:`heading`,raw:Er(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:Er(t[0],`
|
|
13
|
-
`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=Er(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=kr(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),f=this.rules.other.blockquoteBeginRegex(d);for(;e;){let p=e.split(`
|
|
29
|
-
`,1)[0],m;if(l=p,this.options.pedantic?(l=l.replace(this.rules.other.listReplaceNesting,` `),m=l):m=l.replace(this.rules.other.tabCharGlobal,` `),i.test(l)||a.test(l)||o.test(l)||f.test(l)||t.test(l)||n.test(l))break;if(m.search(this.rules.other.nonSpaceChar)>=d||!l.trim())s+=`
|
|
30
|
-
`+m.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+=p+`
|
|
32
|
-
`,e=e.substring(p.length+1),c=m.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=Dr(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:Er(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=Tr(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:Er(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(Tr(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:Er(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=Er(e.slice(0,-1),`\\`);if((e.length-t.length)%2==0)return}else{let e=Or(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)),Ar(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 Ar(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}}}},Nr=class e{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||sn,this.options.tokenizer=this.options.tokenizer||new Mr,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:N,block:yr.normal,inline:br.normal};this.options.pedantic?(t.block=yr.pedantic,t.inline=br.pedantic):this.options.gfm&&(t.block=yr.gfm,t.inline=this.options.breaks?br.breaks:br.gfm),this.tokenizer.rules=t}static get rules(){return{block:yr,inline:br}}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(N.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(N.tabCharGlobal,` `).replace(N.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)}},Pr=class{options;parser;constructor(e){this.options=e||sn}space(e){return``}code({text:e,lang:t,escaped:n}){let r=(t||``).match(N.notSpaceStart)?.[0],i=e.replace(N.endingNewline,``)+`
|
|
52
|
-
`;return r?`<pre><code class="language-`+Cr(r)+`">`+(n?i:Cr(i,!0))+`</code></pre>
|
|
53
|
-
`:`<pre><code>`+(n?i:Cr(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>${Cr(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=wr(e);if(i===null)return r;e=i;let a=`<a href="`+e+`"`;return t&&(a+=` title="`+Cr(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=wr(e);if(i===null)return Cr(n);e=i;let a=`<img src="${e}" alt="${Cr(n)}"`;return t&&(a+=` title="${Cr(t)}"`),a+=`>`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:Cr(e.text)}},Fr=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}},Ir=class e{options;renderer;textRenderer;constructor(e){this.options=e||sn,this.options.renderer=this.options.renderer||new Pr,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Fr}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}},Lr=class{options;block;constructor(e){this.options=e||sn}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?Nr.lex:Nr.lexInline}provideParser(e=this.block){return e?Ir.parse:Ir.parseInline}},Rr=new class{defaults=on();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Ir;Renderer=Pr;TextRenderer=Fr;Lexer=Nr;Tokenizer=Mr;Hooks=Lr;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 Pr(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 Mr(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 Lr;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]=Lr.passThroughHooks.has(n)?e=>{if(this.defaults.async&&Lr.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 Nr.lex(e,t??this.defaults)}parser(e,t){return Ir.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?Nr.lex:Nr.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?Ir.parse:Ir.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?Nr.lex:Nr.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?Ir.parse:Ir.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>`+Cr(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function I(e,t){return Rr.parse(e,t)}I.options=I.setOptions=function(e){return Rr.setOptions(e),I.defaults=Rr.defaults,cn(I.defaults),I},I.getDefaults=on,I.defaults=sn;function zr(...e){return Rr.use(...e),I.defaults=Rr.defaults,cn(I.defaults),I}I.use=zr,I.walkTokens=function(e,t){return Rr.walkTokens(e,t)},I.parseInline=Rr.parseInline,I.Parser=Ir,I.parser=Ir.parse,I.Renderer=Pr,I.TextRenderer=Fr,I.Lexer=Nr,I.lexer=Nr.lex,I.Tokenizer=Mr,I.Hooks=Lr,I.parse=I,I.options,I.setOptions,I.walkTokens,I.parseInline,Ir.parse,Nr.lex;var L=e=>{let t=document.querySelector(e);if(!t)throw Error(`missing element: ${e}`);return t};function Br(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 Vr=e=>{let t=Br(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 Hr=e=>e.split(`/`).filter(Boolean).pop()??e,Ur=e=>`New session in ${Hr(e)}`;function Wr(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 Gr(e){let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function Kr(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 qr(e){let t=R(`span`,`help`);return t.innerHTML=an.sanitize(I.parseInline(e,{async:!1})),Jr(t),t}function Jr(e){for(let t of e.querySelectorAll(`a`))(t.getAttribute(`href`)??``).startsWith(`#`)||(t.target=`_blank`,t.rel=`noreferrer`)}async function Yr(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 Xr(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 Yr(t()).then(()=>`Copied`,()=>`Failed`),clearTimeout(r),r=setTimeout(()=>n.textContent=`Copy`,1200)},n}var Zr=450,Qr=8,$r=700;function ei(e,t){let n,r,i={x:0,y:0},a=!1,o=()=>clearTimeout(n),s=t=>{e.classList.remove(`bg-emerald-100`,`bg-red-100`),e.classList.add(t),clearTimeout(r),r=setTimeout(()=>e.classList.remove(t),$r)};e.addEventListener(`pointerdown`,e=>{a=!1,i={x:e.clientX,y:e.clientY},o(),n=setTimeout(()=>{a=!0,Yr(t()).then(()=>s(`bg-emerald-100`),()=>s(`bg-red-100`))},Zr)}),e.addEventListener(`pointermove`,e=>{Math.hypot(e.clientX-i.x,e.clientY-i.y)>Qr&&o()});for(let t of[`pointerup`,`pointercancel`,`pointerleave`])e.addEventListener(t,o);e.addEventListener(`click`,e=>{a&&(e.preventDefault(),e.stopImmediatePropagation())})}function ti(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(_(l,`chev h-3 w-3`),...t),n.append(r),{el:n,summary:r}}var ni=(e,t=!1)=>ri(e,`${t?`btn btn-primary`:`btn`} text-[12.5px]`),ri=(e,t=``)=>{let n=R(`button`,t,e);return n.type=`button`,n},ii=e=>R(`span`,`mr-1 flex-none font-medium max-md:hidden`,e),ai=(...e)=>R(`div`,`toolbar flex min-h-10 flex-none flex-wrap items-center gap-2 px-4 py-2`,...e);function oi(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=ri(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 si(e,t,n){let r=ri(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 ci=`rounded-3xl border border-neutral-200 bg-white shadow-sm`,li=`border-b border-neutral-200/70 bg-neutral-50/50`,ui=`${ci} flex flex-col overflow-hidden`,di=`${li} flex flex-none items-center`;function fi(e,t,...n){let r=R(`section`,ci),i=R(`div`,`rounded-t-3xl ${li} 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 pi(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 mi=`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`,hi=`${mi} cursor-pointer truncate text-left hover:bg-neutral-50`,gi=(e,t,n,r=!1)=>{let i=document.createElement(`input`);return i.className=r?`${mi} font-mono`:mi,i.value=e,i.placeholder=t,i.oninput=()=>n(i.value),i},_i=(e=``,t=`text`)=>{let n=document.createElement(`input`);return n.type=t,n.className=mi,n.value=e,n},vi=(e,t)=>{let n=document.createElement(`select`);return n.className=`${mi} select`,n.append(...e.map(([e,t])=>new Option(e,t))),n.value=t,n},yi=(e=``,t=4)=>{let n=document.createElement(`textarea`);return n.className=`${mi} resize-y font-mono`,n.value=e,n.rows=t,n.spellcheck=!1,n};function bi(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 peer-disabled:cursor-not-allowed peer-disabled:opacity-45`),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 xi={idle:`text-neutral-400`,saving:`text-neutral-400`,saved:`text-green-700`,failed:`text-red-600`};function Si(e,t,n){e.className=`text-[11.5px] ${xi[t]}`,e.textContent=n}var Ci=(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),wi=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 Ti(e,t,n=`left`){let r=R(`span`,`group relative inline-flex`),i=ri(``,`flex h-4 w-4 cursor-help items-center justify-center text-neutral-400 transition-colors group-hover:text-indigo-500`);i.append(_(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`?qr(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 Ei=(e,t)=>R(`span`,`flex flex-col gap-1`,qr(e),t),Di=e=>`[${e.split(`/`).pop()??`file`}](file://${encodeURI(e).replace(/\(/g,`%28`).replace(/\)/g,`%29`)})`,Oi=/^ {0,3}(`{3,}|~{3,})/;function ki(e){let t=[],n,r=0;for(let i of e.split(`
|
|
71
|
-
`)){let e=Oi.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 Ai(e,t,n){let r=ki(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 ji=/^\[[^\]\n]*\]\(\s*<?file:\/\/(\/[^)>\s]*)>?\s*\)$/;function Mi(e){let t=e.split(`
|
|
72
|
-
`),n=t.length;for(;n>0&&ji.test(t[n-1].trim());)n--;let r=t.slice(n).map(e=>{let t=ji.exec(e.trim())[1];try{return decodeURIComponent(t)}catch{return t}});return{text:t.slice(0,n).join(`
|
|
73
|
-
`).trimEnd(),paths:r}}var Ni=`modulepreload`,Pi=function(e){return`/`+e},Fi={},Ii=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=Pi(t,n),t=s(t),t in Fi)return;Fi[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`:Ni,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)})},Li,Ri;function zi(){return Ri??=Ii(()=>import(`./hljs-tWqyD59G.js`).then(e=>Li=e.default,e=>{console.warn(`highlighting unavailable — code stays plain text`,e)}),[]),Ri}async function Bi(e){let t=await zi();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 Vi={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 Hi(e){let t=await zi(),n=e.split(`.`).pop()?.toLowerCase()??``,r=Vi[n]??n;return t?.getLanguage(r)?r:null}function Ui(e,t){let n=document.createElement(`span`);return Li&&t&&e.length<=500?n.innerHTML=Li.highlight(e,{language:t}).value:n.textContent=e,n}var Wi=2e4;function Gi(e){let t=e.split(`
|
|
74
|
-
`);return t.at(-1)===``&&t.pop(),t.map((e,t)=>({nums:[t+1],text:e,tone:``}))}function Ki(e,t){let n=e.length<=Wi?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)}t.nums.length===1&&typeof t.nums[0]==`number`&&(e.dataset.line=String(t.nums[0])),e.append(qi(t,n)),i.append(e)}return i}function qi(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=Ui(e.text,t);return r.className=n,r}let[r,i]=e.mark,a=Ui(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,Ui(e.text.slice(0,r),t),a,Ui(e.text.slice(i),t))}var Ji=L(`#image-dialog`),z=L(`#image-stage`),Yi=L(`#image-full`),Xi=L(`#image-prev`),Zi=L(`#image-next`),Qi=L(`#image-close`),$i=[],ea=0;function ta(e){$i.length<2||(ea=(ea+e+$i.length)%$i.length,ia(!1),Yi.src=$i[ea])}var na=2.5,ra=()=>z.dataset.zoom!==void 0;function ia(e,t){if(!e){delete z.dataset.zoom,Yi.style.cssText=``;return}let n=Yi.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*na,s=n.height*na;z.dataset.zoom=``,Yi.style.width=`${String(o)}px`,Yi.style.height=`${String(s)}px`,z.scrollLeft=i*o-r.width/2,z.scrollTop=a*s-r.height/2}function aa(e){let t=e.closest(`[data-gallery]`);$i=t?[...t.querySelectorAll(`img.thumb`)].map(e=>e.src):[e.src],ea=Math.max(0,$i.indexOf(e.src)),Yi.src=e.src;let n=$i.length<2?`none`:`flex`;Xi.style.display=n,Zi.style.display=n,Ji.showModal()}var oa=4,sa,ca=!1;z.onpointerdown=e=>{ca=!1,!(!ra()||e.button!==0)&&(sa={x:e.clientX,y:e.clientY,left:z.scrollLeft,top:z.scrollTop},z.setPointerCapture(e.pointerId))},z.onpointermove=e=>{if(!sa)return;let t=e.clientX-sa.x,n=e.clientY-sa.y;(Math.abs(t)>oa||Math.abs(n)>oa)&&(ca=!0),z.scrollLeft=sa.left-t,z.scrollTop=sa.top-n};var la=()=>{sa=void 0};z.onpointerup=la,z.onpointercancel=la,z.onclick=e=>{ca||(e.target===Yi?ia(!ra(),{x:e.clientX,y:e.clientY}):Ji.close())},Qi.onclick=()=>Ji.close(),Ji.onclose=()=>ia(!1),Xi.onclick=()=>ta(-1),Zi.onclick=()=>ta(1),Ji.onkeydown=e=>{(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&(e.preventDefault(),ta(e.key===`ArrowLeft`?-1:1))};function ua(e){let t=e.querySelector(`:scope > .thumbs`);if(t)return t;let n=R(`div`,`thumbs`);return e.append(n),n}function da(e){let t=document.createElement(`img`);return t.src=e,t.loading=`lazy`,t.className=`thumb`,t.onclick=()=>aa(t),t}var fa=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`avif`,`bmp`]),pa=524288,ma=L(`#file-dialog`),ha=L(`#file-name`),ga=L(`#file-text`),_a=L(`#file-download`);L(`#file-close`).onclick=()=>ma.close();var va=e=>e.split(`.`).pop()?.toLowerCase()??``,ya=(e,t,n=!1)=>`/api/sessions/${encodeURIComponent(e)}/files?path=${encodeURIComponent(t)}${n?`&download=1`:``}`;function ba(e,t){return Ai(e,/\]\(\s*<?file:\/\/(\/[^)>\s]*)>?\s*\)/g,e=>{let n=e[1];try{n=decodeURIComponent(n)}catch{}return`](${ya(t,n)})`})}var xa=e=>/^\/api\/sessions\/[^/]+\/files\?/.test(e);function Sa(e,t){let n=Hr(t)||`file`,r=ya(e,t);return fa.has(va(n))?Aa(r,n):ja(r,n)}function Ca(e){return new URLSearchParams(e.slice(e.indexOf(`?`)+1)).get(`path`)??``}var wa=(e,t=`text-neutral-500`)=>R(`div`,`px-3 py-2 text-[12.5px] [overflow-wrap:anywhere] ${t}`,e),Ta=0;async function Ea(e,t,n){let r=++Ta;ha.textContent=t,_a.href=`${e}&download=1`,ga.replaceChildren(wa(`loading…`)),ma.showModal();let i=e=>{r===Ta&&ga.replaceChildren(e)},a;try{a=await fetch(e)}catch(e){return i(wa(`failed to load: ${String(e)}`,`text-red-600`))}if(!a.ok)return i(wa(`${await S(a,`failed to load`)}: ${Ca(e)}`,`text-red-600`));let o=a.headers.get(`content-type`)??``;if(!o.startsWith(`text/`)&&!o.startsWith(`image/svg+xml`))return i(wa(`Binary file — use Download.`));let s=await a.text(),c=s.length>pa?`${s.slice(0,pa)}\n…`:s,l=await Hi(t),u=Ki(Gi(c),l);if(i(u),n===void 0||r!==Ta)return;let d=u.querySelector(`[data-line="${String(n)}"]`);d?.classList.add(`bg-indigo-100`),d?.scrollIntoView({block:`center`})}var Da=new Set(`ts.tsx.mts.cts.js.jsx.mjs.cjs.json.md.css.html.py.rs.go.rb.java.c.h.cpp.hpp.sh.sql.yml.yaml.toml.ini.conf.txt.lock`.split(`.`));function Oa(e){let t=/^([^\s`"'()[\]{}<>]+?)(?::(\d+))?(?::\d+)?$/.exec(e);if(!t||e.includes(`://`))return null;let n=t[1],r=n.includes(`.`)?va(n):``;return!r||!Da.has(r)&&!n.includes(`/`)?null:{path:n,line:t[2]===void 0?void 0:Number(t[2])}}function ka(e,t,n){for(let r of e.querySelectorAll(`:not(pre) > code`)){let e=Oa(r.textContent?.trim()??``);if(!e||r.closest(`a`))continue;let i=e.path.startsWith(`/`)?e.path:n?`${n}/${e.path}`:null;if(!i)continue;let a=()=>void Ea(ya(t,i),Hr(i),e.line);r.classList.add(`fileref`),r.tabIndex=0,r.setAttribute(`role`,`button`),r.title=e.line===void 0?i:`${i}:${String(e.line)}`,r.onclick=a,r.addEventListener(`pointerup`,()=>r.blur()),r.onkeydown=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a())}}}function Aa(e,t){let n=da(e);return n.alt=t,n}function ja(e,t){let n=va(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]`,_(ee));s.setAttribute(`aria-label`,`Preview`),s.title=`Preview`,s.onclick=r=>{r.preventDefault(),n===`pdf`?window.open(e,`_blank`,`noopener`):Ea(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(_(p)),c.setAttribute(`aria-label`,`Download`),o.append(c),r.append(i,a,o),r}function Ma(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 Na(e){let t=[];for(let n of e.querySelectorAll(`img`)){let e=n.getAttribute(`src`)??``;if(!xa(e))continue;let r=Aa(e,Hr(Ca(e)));n.replaceWith(r),t.push(r)}for(let n of e.querySelectorAll(`a`)){let e=n.getAttribute(`href`)??``;if(!xa(e))continue;let r=Hr(Ca(e))||n.textContent?.trim()||`file`,i=fa.has(va(r))?Aa(e,r):ja(e,r);n.replaceWith(i),t.push(i)}t.length&&Ma(t)}var Pa=null,Fa=`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 Ia(){Pa=null}function La(e,t,n){if(Pa?.remove(),Pa=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`,Fa,e);t.type=`button`,t.onclick=()=>{Pa===r&&(Pa=null),r.remove(),n(e)},r.append(t)}e.append(r),Pa=r}var Ra=8e3,za=[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`],Ba=e=>typeof e==`string`&&za.includes(e),Va,Ha;function Ua(e,t){Va=e,Ha=t}var Wa=e=>e.slice(0,8),Ga=e=>`system-card group relative mt-1.5 rounded-xl px-4 py-2.5 ${e}`,Ka=e=>R(`div`,Ga(e));function qa(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 Ja(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`,Wa(e.runId));if(r.title=`Run ${e.runId}`,r.onclick=()=>Va.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`,Wa(t));r.title=`Open session ${t}`,r.onclick=()=>Va.select(t),n.append(r)}return t.append(n),t}var Ya={queued:{edge:`border-l-amber-400`,label:`text-amber-700`,glyph:h},running:{edge:`border-l-fuchsia-500`,label:`text-fuchsia-700`,glyph:h},succeeded:{edge:`border-l-green-500`,label:`text-green-700`,glyph:o},failed:{edge:`border-l-red-500`,label:`text-red-600`,glyph:_e},cancelled:{edge:`border-l-neutral-300`,label:`text-neutral-500`,glyph:oe},interrupted:{edge:`border-l-amber-400`,label:`text-amber-700`,glyph:ce},skipped:{edge:`border-l-neutral-300`,label:`text-neutral-500`,glyph:oe}},Xa=e=>_(Ya[e].glyph,`h-3 w-3 ${e===`queued`||e===`running`?`spinner`:``} ${Ya[e].label}`),Za=new Map,Qa=new WeakMap;function $a(e){for(let[e,t]of Za)t.isConnected||Za.delete(e);let t=Za.get(e.runId);t||(t=Ka(Ya[e.state].edge),t.dataset.kind=`background-run`,Ha.el.append(t),Za.set(e.runId,t)),t.className=Ga(Ya[e.state].edge);let n=e.state===`queued`||e.state===`running`;t.toggleAttribute(`data-active`,n);let r=Math.max(0,Math.round(((e.finishedAt??Date.now())-(e.startedAt??e.queuedAt))/1e3)),i=Ja({glyph:Xa(e.state),label:`run · ${e.state}`,labelCls:Ya[e.state].label,taskName:e.taskName,note:`${e.sessionMode??`task`} · depth ${String(e.depth)} · ${String(r)}s`,runId:e.runId,sessionId:e.targetSessionId}),a=Qa.get(t);!a&&e.prompt!==null&&(a=qa(e.prompt),Qa.set(t,a)),t.replaceChildren(i,...a??[]),Ha.scroll()}var B=null,eo=null,to=null,no=!1;function ro(){if(!eo)return;eo.text=eo.text.slice(-4e3),eo.pre.textContent=eo.text;let e=eo.text.split(`
|
|
76
|
-
`).filter(Boolean).pop()??`thinking…`,t=eo.summary.lastElementChild;t.textContent=e.length>90?`…`+e.slice(-90):e}function io(){if(to){no=!0;return}no=!1,ro(),to=setTimeout(()=>{to=null,no&&io()},80)}function ao(){to&&clearTimeout(to),to=null,no&&ro(),no=!1}var oo=new WeakMap,so=e=>{let t=oo.get(e)??[];return oo.set(e,t),t};function co(){B&&!B.toolRows.size&&Co(`done`)}var lo=null;function uo(){B=null,lo=null,eo=null,ao(),Za.clear()}function fo(){let e=lo;return!e||B?.el===e||(lo=null,e!==Ha.el.lastElementChild)?null:(e.remove(),e.dataset.adopted=`1`,mo(e,e.dataset.status),e)}var po={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 mo(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 ${po[t]}`}var ho={failed:_e,interrupted:ce};function go(e){return e===`running`?_(h,`spinner`):e===`done`?R(`span`,`hidden`):_(ho[e],`h-3 w-3`)}function _o(e){if(B)return B;let t=go(`running`),n=R(`span`,`min-w-0 truncate`,`working…`),{el:r}=ti(``,[t,n]);r.dataset.kind=`activity`,mo(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),bo(r,i),Ha.el.append(r),lo=r,Ha.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 vo(e,t=``){let n=_o(e);ao(),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),So(n,`running`,`writing…`),xo(n),Ha.scroll(),r}function yo(e){let t=e.closest(`details[data-kind="activity"]`);e.parentElement?.remove(),t&&!t.lastElementChild?.childElementCount&&(B?.el===t&&(B=null),lo===t&&(lo=null),t.remove())}function bo(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 xo(e){Ha.bulk()||!e.el.open||!e.rowsEl.dataset.follow||(e.rowsEl.scrollTop=e.rowsEl.scrollHeight)}function So(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}`,mo(e.el,t);let a=go(t);e.statusIcon.replaceWith(a),e.statusIcon=a}function Co(e){if(!B)return;ao();for(let{statusEl:e}of B.toolRows.values())e.textContent===`running…`&&(e.textContent=`interrupted`);let t=B.steps>0&&B.failedSteps===B.steps;So(B,(B.sawError||t)&&e===`done`?`failed`:e===`done`&&B.toolRows.size?`interrupted`:e),B=null}function wo(){B&&(B.sawError=!0)}function To(e){let t=e.slice(0,400).replace(/\s+/g,` `);return t.length>100?t.slice(0,100)+`…`:t}function Eo(e,t,n,r){let i=_o(e);i.steps+=1,ao(),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`,To(a)),{el:c}=ti(`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)),so(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),xo(i),So(i,`running`,n),Ha.scroll()}function Do(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,Ra)+`…`:n,i.outputPre.classList.remove(`hidden`)),t&&(r.failedSteps+=1)),So(r,`running`)}function Oo(e,t){let n=_o(e);if(!n.thinking){ao();let{el:e,summary:t}=ti(`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:``},eo=n.thinking,xo(n),So(n,`running`,`thinking…`)}n.thinking.text+=t,io()}var ko=0;function Ao(e,t=0,n=!1,r){let i=Date.now()-t,a=_o(i).el;for(let t of e){if(t.kind===`progress`){vo(i,t.text??``);continue}if(t.kind===`thinking`){Oo(i,t.text??``);continue}let e=t.id??`replay-${++ko}`;Eo(i,e,t.toolName??``,t.args),t.done&&Do(e,t.isError??!1,t.output??``)}r!==void 0&&e.some(e=>e.kind===`tool`&&e.args===void 0)&&jo(a,r),!n&&Co(e.some(e=>e.kind===`tool`&&!e.done)?`interrupted`:`done`)}function jo(e,t){let n=()=>{e.open&&(e.removeEventListener(`toggle`,n),Mo(e,t))};e.addEventListener(`toggle`,n)}async function Mo(e,t){let n=Va.sessionId(),r=so(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 C(`/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=To(r),n.output&&(t.outputPre.textContent=n.output,t.outputPre.classList.remove(`hidden`))}}var No,V=L(`#turns`);function Po(e){No=e,Ua(e,{el:V,scroll:Ho,bulk:()=>Fo})}var Fo=!1,Io=()=>V.scrollHeight-V.scrollTop-V.clientHeight<80,Lo=!0,Ro=0;V.addEventListener(`scroll`,()=>{let e=V.scrollTop,t=e<Ro-4;Ro=e,!Fo&&(t||Io())&&(Lo=Io())},{passive:!0});var zo=0;function Bo(){!Lo||Fo||zo||(zo=requestAnimationFrame(()=>{zo=0,Lo&&!Fo&&(V.scrollTop=V.scrollHeight)}))}new ResizeObserver(Bo).observe(V),V.addEventListener(`load`,Bo,!0),new MutationObserver(Bo).observe(V,{childList:!0,subtree:!0,characterData:!0});function Vo(){Io()&&(Lo=!0)}function Ho(e=!1){Fo||(e&&(Lo=!0),Lo&&(V.scrollTop=V.scrollHeight))}var Uo=1200;function Wo(e,t){let n=V.querySelector(`[data-kind="${e}"][data-at="${t}"]`);return n?(Ko(n),!0):!1}function Go(){let e=V.querySelectorAll(`[data-kind="background-run"][data-active]`),t=e[e.length-1];return t?(Ko(t),!0):!1}function Ko(e){Lo=!1,e.scrollIntoView({block:e.offsetHeight>V.clientHeight?`start`:`center`}),e.dataset.reveal=``,setTimeout(()=>delete e.dataset.reveal,Uo)}var qo=500,Jo=0,Yo=0,Xo=null;function Zo(){for(;V.childElementCount>qo;){let e=V.firstElementChild;e.remove(),e!==Xo&&(e.dataset.kind===`user`&&Jo++,Yo++)}Yo&&(Xo||(Xo=R(`div`,`px-5 py-2 text-center text-[11.5px] italic text-neutral-400`),Xo.dataset.kind=`trim`),Xo.textContent=`${Yo} earlier row${Yo===1?``:`s`} not shown — still in the transcript, not on this screen`,V.firstElementChild!==Xo&&V.prepend(Xo))}var Qo={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){co();let i=e===`assistant`?fo():null,a=Qo[e],o=e===`user`&&r!==void 0&&ps(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=``),Fo||(c.dataset.enter=``);let l=e===`user`?Mi(t):null,u=l?.text??t,d=e===`user`?je(u):null,f=d?.id||d?.when?d:null,p=f?.id&&f.id!==`web`?f:null,m=R(`div`,`whitespace-pre-wrap break-words ${a.body}`,f?.text??u);(l?.paths.length||f)&&(m.dataset.raw=t),n&&_s(m,t),r!==void 0&&ms(c,r),p&&c.append($o(p)),c.append(m);let ee=No.sessionId();if(l?.paths.length&&ee){let e=ua(c);for(let t of l.paths)e.append(Sa(ee,t))}if(e===`user`){rs?.(),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(_(le)),e.onclick=()=>as(c,m),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),us(e),ls??=setInterval(ds,6e4),e.title=Wr(o),V.append(e)}return i&&V.append(i),V.append(c),Zo(),Ho(),m}function $o(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 es={"task-delegation":[i,`delegated`,`text-cyan-700`],"task-callback":[f,`callback`,`text-cyan-700`],decision:[u,`decision needed`,`text-amber-700`]};function ts(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 ns(e,t){let n=t.kind===`task-message`?t.messageKind:t.kind,[r,i,a]=es[n]??[f,n.replace(`_`,` `),`text-cyan-700`];co();let o=t.kind===`task-callback`?t.state:void 0,s=Ka(o?Ya[o].edge:n===`decision`?`border-l-amber-400`:`border-l-cyan-500`);s.dataset.kind=`system`;let[c,l]=ts(e),u=Ja({glyph:o?Xa(o):_(r,`h-3 w-3 ${a}`),label:o?`${i} \u00b7 ${o}`:i,labelCls:o?Ya[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(...qa(l)),V.append(s),Zo(),Ho()}var rs=null,is=e=>e.isConnected&&V.querySelector(`.message-edit`)?.parentElement===e;function as(e,t){if(!is(e))return;if(No.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=ni(`Send edit`,!0),i=ni(`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,rs=null};rs=s,i.onclick=()=>{s(),e.querySelector(`.message-edit`)?.focus({preventScroll:!0})},r.onclick=()=>{let t=n.value.trim();t&&os(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 os(e,t){let n=No.sessionId();if(!n||!is(e))return;if(No.sessionState()!==`idle`){H(`error`,`can't edit while streaming — stop the turn first`);return}rs?.();let r=[...V.querySelectorAll(`[data-kind="user"]`)],i=Jo+r.indexOf(e),a=r[r.length-2]?.dataset.at;cs=a===void 0?null:Number(a);let o=e.previousElementSibling;for(o?.dataset.kind===`time`&&o.remove();e.nextElementSibling;)e.nextElementSibling.remove();e.remove(),No.ownTurn(t),H(`user`,t,!1,Date.now()),Ho(!0);let s=await x(`/api/sessions/${n}/turns/${i}/edit`,{text:t});if(!s.ok){let e=await S(s,`edit failed`);await No.reload(n),H(`error`,e)}}var ss=6e5,cs=null,ls;function us(e){let t=Number(e.dataset.at);e.textContent=`${Wr(t).slice(0,16)} · ${Vr(t)}`}function ds(){let e=V.querySelectorAll(`[data-kind="time"]`);for(let t of e)us(t);e.length||(clearInterval(ls),ls=void 0)}var fs=(e,t)=>new Date(e).toDateString()===new Date(t).toDateString();function ps(e){let t=cs;return cs=e,t===null||e-t>=ss||!fs(t,e)}function ms(e,t){e.dataset.at=String(t),e.dataset.time=Wr(t).slice(11)}function hs(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,Xr(`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 gs(e){let t=No.sessionId(),n=R(`div`,``);return n.innerHTML=an.sanitize(I.parse(t?ba(e,t):e,{async:!1})),Jr(n),n}function _s(e,t){e.replaceChildren(...gs(t).childNodes),e.classList.remove(`whitespace-pre-wrap`),e.classList.add(`md`),Bi(e),hs(e);for(let t of e.querySelectorAll(`:not(pre) > code`))ei(t,()=>t.textContent??``);Na(e);let n=No.sessionId();n&&ka(e,n,No.sessionCwd())}function vs(e,t,n,r=!1){let{text:i,suggestions:a}=Oe(t);return v({text:i,suggestions:a})?ys(e,De(t)):_s(e,i),r&&La(e.parentElement??e,a,e=>No.send(`auto`,e)),n&&ms(e.parentElement??e,n.completedAt),e}function ys(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 bs=(e,t,n=!1)=>vs(H(`assistant`,``),e,t,n),U=null,xs=null,Ss=!1,Cs=0,ws=0;function Ts(e){let t=e.dataset.raw??``;for(;e.childNodes.length>ws;)e.lastChild.remove();let n=Ae(t,Cs);n>Cs&&(e.append(...gs(ke(t.slice(Cs,n))).childNodes),Cs=n,ws=e.childNodes.length),e.append(...gs(Oe(t.slice(Cs)).text).childNodes),e.classList.remove(`whitespace-pre-wrap`),e.classList.add(`md`)}function Es(){if(xs){Ss=!0;return}Ss=!1,U&&(Ts(U),Ho()),xs=setTimeout(()=>{xs=null,Ss&&Es()},80)}function Ds(){xs&&clearTimeout(xs),xs=null,Ss=!1}function Os(e){U||(U=vo(Date.now()),Cs=0,ws=0),U.dataset.raw=(U.dataset.raw??``)+e,Es()}function ks(){if(!U)return;let e=U;U=null,Ds(),e.classList.remove(`md`),e.classList.add(`whitespace-pre-wrap`),e.textContent=e.dataset.raw??``}function As(){if(!U)return;let e=U.dataset.raw;return yo(U),U=null,Ds(),e}function js(e,t){e===``&&ks();let n=As();Co(`done`);let r=e??n;r&&bs(r,t,!0)}function Ms(){let e=As();Co(`interrupted`),e&&bs(e)}function Ns(){rs?.(),clearInterval(ls),ls=void 0,V.replaceChildren(),Jo=0,Yo=0,Xo=null,cs=null,U=null,Ds(),uo(),Ia()}function Ps(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 Fs(e,t,n){Ps(!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&&($a(e),r.delete(t))}},o=e.reduce((e,t,n)=>t.role===`assistant`?n:e,-1);Fo=!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&&(Ao(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]),ns(r.text,r.origin);continue}s?Os(r.text):r.role===`assistant`?bs(r.text,r.meta,t===`idle`&&n===o):H(r.role,r.text,!1,r.at)}}for(let e of r.values())$a(e)}finally{Fo=!1}Ho(!0)}var Is=window.fetch.bind(window),Ls=20,Rs=6e4,zs=[],Bs=new Map,Vs=e=>e instanceof Error?e.stack??`${e.name}: ${e.message}`:void 0;function Hs(e,t){let n=t===void 0?e:`${e}: ${String(t)}`,r=Date.now();return r-(Bs.get(n)??-6e4)<Rs||(Bs.size>100&&Bs.clear(),Bs.set(n,r),zs=zs.filter(e=>r-e<6e4),zs.length>=Ls)?null:(zs.push(r),Is(`/api/client-log`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({message:n,stack:Vs(t),view:location.hash||`/`}),keepalive:!0}).catch(()=>{}),H(`error`,n))}function Us(){window.__pierReporting=!0,window.addEventListener(`error`,e=>{!e.error&&e.message.includes(`ResizeObserver loop`)||Hs(`script error: ${e.message}`,e.error)}),window.addEventListener(`unhandledrejection`,e=>{Hs(`unhandled rejection`,e.reason)})}var Ws=window.fetch.bind(window),Gs=()=>{location.assign(`/login?next=${encodeURIComponent(location.pathname+location.hash)}`)};function Ks(){window.fetch=async(...e)=>{let t=await Ws(...e);return t.status===401&&Gs(),t}}function qs(e,t){if(e.readyState!==EventSource.CLOSED)return;let n=()=>{let e=Hs(`${t} stream disconnected`);if(!e)return;let n=ni(`Reload`);n.classList.add(`ml-2`,`align-middle`),n.onclick=()=>location.reload(),e.append(` `,n)};Ws(`/api/sessions`).then(e=>e.status===401?Gs():n(),n)}var Js=/Mac|iP(?:hone|ad|od)/.test(navigator.userAgent),Ys=Js?`⌘`:`Ctrl+`,Xs=Js?`⇧`:`Shift+`,Zs=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 Qs(e){let{key:t,shift:n,meta:r}=Zs(e);return`${r?`⌘`:Ys}${n?Xs:``}${t.toUpperCase()}`}var $s=()=>document.querySelector(`dialog[open]`)!==null,ec={"[":`{`,"]":`}`},tc=`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 nc(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`,tc,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 rc(e,t,n,r,i){nc(e,n,Qs(t)),sc(t,r,i)}function ic(e,t,n,r){nc(e,t,`Esc`),document.addEventListener(`keydown`,e=>{e.key!==`Escape`||e.isComposing||e.defaultPrevented||$s()||!r()||(e.preventDefault(),n())})}var ac=`input, textarea, select, [contenteditable]`;function oc(e,t,n,r,i){nc(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?.(ac)||$s()||!i()||(e.preventDefault(),r())})}function sc(e,t,n){let{key:r,shift:i,meta:a}=Zs(e),o=ec[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,cc=L(`#composer`),G=L(`#input`),lc=L(`#send`),uc=L(`#send-arrow`),dc=L(`#send-queue`),fc=L(`#stop`),pc=L(`#queue-panel`),mc=L(`#queue-rows`),hc=L(`#queue-label`),gc=R(`div`,`hidden max-h-48 overflow-y-auto border-t border-neutral-200 px-4 py-2 text-[13px]`);gc.id=`recovery-panel`,pc.after(gc);var _c=L(`#image-strip`),vc=L(`#attach-input`),yc=!1,bc=0,xc=new Set,Sc=[],Cc=[];function wc(){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 Tc(){let e=cc.parentElement,t=[pc,gc,cc],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 Ec(){G.focus()}function Dc(e){let t=Cc.indexOf(e);return t<0?!1:(Cc.splice(t,1),!0)}function Oc(e){Cc.push(e)}function kc(){Cc=[]}function Ac(){let e=W.sessionState()===`streaming`,t=W.sessionId()!==null,n=W.starting();lc.disabled=!t,lc.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`}`,lc.title=t?e?`Queue — delivered when the turn ends`:`Send`:n?`Starting the session…`:`No session`,G.placeholder=n?`Starting the session…`:`Message…`,uc.classList.toggle(`hidden`,e),dc.classList.toggle(`hidden`,!e),fc.classList.toggle(`hidden`,!e),fc.classList.toggle(`flex`,e)}function jc(){let e=W.chatVisible()&&yc;pc.classList.toggle(`hidden`,!e),pc.classList.toggle(`flex`,e),gc.classList.toggle(`hidden`,!W.chatVisible()||!gc.childElementCount)}function Mc(e,t=!1){let n=W.sessionId();if(gc.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),Xr(`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 x(`/api/sessions/${n}/queue/recovery/${e.id}/ack`,{}),r=t.ok?null:await S(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 Yc(),e.append(t),gc.prepend(e)}jc()}function Nc(e,t){++bc;let n=[...e.map(e=>({mode:`steer`,text:e})),...t.map(e=>({mode:`queued`,text:e}))];yc=n.length>0,hc.textContent=n.length>1?`Queued · ${n.length}`:`Queued`,jc(),mc.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 Pc=8;function Fc(){let e=W.sessionId();e&&Sc.length?Hc.set(e,Sc):e&&Hc.delete(e),_c.classList.toggle(`hidden`,Sc.length===0),_c.classList.toggle(`flex`,Sc.length>0),_c.replaceChildren(...Sc.map((e,t)=>{let n=e.mimeType.startsWith(`image/`)?da(`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`,_(_e,`h-3 w-3`));return r.setAttribute(`type`,`button`),r.setAttribute(`aria-label`,`Remove ${e.name??`attachment`}`),r.onclick=()=>{Sc.splice(t,1),Fc()},R(`div`,`relative`,n,r)}))}function Ic(e){if(Sc.length>=Pc){H(`error`,`attachment limit is ${Pc} 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;Sc.push({data:n.slice(n.indexOf(`,`)+1),mimeType:e.type||`application/octet-stream`,name:e.name||void 0}),Fc()},t.readAsDataURL(e)}async function Lc(e){let t=[];for(let n of e){let e=await x(`/api/inbox`,n);if(!e.ok)return null;let{path:r}=await e.json();t.push(Di(r))}return t}var Rc=`pier.draft.`,zc=e=>`${Rc}${e}`,Bc=0;function Vc(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n?.startsWith(Rc)&&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 Hc=new Map;function Uc(e=W.sessionId(),t=G.value){e&&(t?sessionStorage.setItem(zc(e),t):sessionStorage.removeItem(zc(e)))}function Wc(e){++Bc,G.value=sessionStorage.getItem(zc(e))??``,Gc(),Sc=Hc.get(e)??[],Fc()}function Gc(){let e=G.style.height;G.style.height=`auto`;let t=`${Math.min(G.scrollHeight,192)}px`;G.style.height=t,t!==e&&Ho()}var Kc=!1;async function qc(e,t){let n=(t??G.value).trim(),r=t===void 0?Sc:[],i=W.sessionId();if(!(!n&&r.length===0||!i)){if(t===void 0){if(Kc)return;Kc=!0,G.value=``,Gc(),Uc(),Sc=[],Fc()}try{let t=[];if(r.length){let e=await Lc(r);if(e===null){H(`error`,`attachment upload failed`),G.value=[n,G.value.trim()].filter(Boolean).join(`
|
|
81
|
-
`),Gc(),Uc(),Sc=r,Fc();return}t=e}let a=[n,...t].filter(Boolean).join(`
|
|
82
|
-
`),o=W.sessionState()===`idle`&&e===`auto`;o?W.setState(`streaming`):Ac(),(o||e===`steer`)&&(Oc(a),H(`user`,a,!1,Date.now()),Ho(!0));let s=await x(`/api/sessions/${i}/messages`,{text:a,mode:e});if(!s.ok){let e=await S(s,`send failed`);await W.reload(i),H(`error`,e)}}finally{t===void 0&&(Kc=!1)}}}async function Jc(e){let t=W.sessionId();if(!t)return;Nc([],[]);let n=await x(`/api/sessions/${t}/queue/deliver`,{mode:e});if(!n.ok){let r=await S(n,`Queue ${e} failed`);await W.reload(t),W.sessionId()===t&&H(`error`,r)}}async function Yc(){let e=W.sessionId();if(!e||xc.has(e))return;xc.add(e);let t=bc,n=Bc,r=document.activeElement;try{Uc();let i=await fetch(`/api/sessions/${e}/queue/recall`,{method:`POST`});if(!i.ok){let t=await S(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(zc(e))??``,i=(t?[t,...a]:a).join(`
|
|
83
|
-
`);o&&(G.value=i,Gc(),n===Bc&&W.chatVisible()&&document.activeElement===r&&G.focus()),Uc(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===bc&&Nc([],[])}finally{xc.delete(e)}}function Xc(e){W=e,Vc(),wc(),Tc();let t=()=>{let e=W.sessionId();e&&fetch(`/api/sessions/${e}/abort`,{method:`POST`})};fc.onclick=t,ic(fc,`Stop the running turn`,t,()=>W.sessionState()===`streaming`&&W.chatVisible()),L(`#queue-steer`).onclick=()=>void Jc(`steer`),L(`#queue-restart`).onclick=()=>void Jc(`restart`),L(`#queue-recall`).onclick=()=>void Yc(),cc.onsubmit=e=>{e.preventDefault(),qc(`auto`)},oc(G,[`/`],`Write a message`,Ec,W.chatVisible),G.onfocus=Vo,G.oninput=()=>{Gc(),Uc()};let n=!matchMedia(`(pointer: coarse)`).matches;G.onkeydown=e=>{e.isComposing||e.keyCode===229||n&&e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),qc(`auto`))},G.onpaste=e=>{for(let t of e.clipboardData?.items??[]){let e=t.kind===`file`?t.getAsFile():null;e&&Ic(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`),Gc(),Uc())},V.ondragover=e=>e.preventDefault(),V.ondrop=e=>{e.preventDefault();for(let t of e.dataTransfer?.files??[])Ic(t)},L(`#attach`).onclick=()=>vc.click(),vc.onchange=()=>{for(let e of vc.files??[])Ic(e);vc.value=``},Ac()}var Zc=`pier.push`,Qc=`/sw.js`,$c=()=>/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.maxTouchPoints>1&&/Macintosh/.test(navigator.userAgent),el=()=>matchMedia(`(display-mode: standalone)`).matches||navigator.standalone===!0;function tl(){return window.isSecureContext?$c()&&!el()?`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 nl=[[/iPhone/,`iPhone`],[/iPad/,`iPad`],[/Android/,`Android`],[/Macintosh/,`Mac`],[/Windows/,`Windows`]],rl=[[/Edg\//,`Edge`],[/Chrome\//,`Chrome`],[/Firefox\//,`Firefox`],[/Safari\//,`Safari`]];function il(){let e=navigator.userAgent,t=(t,n)=>t.find(([t])=>t.test(e))?.[1]??n;return`${t(nl,`Linux`)} · ${t(rl,`browser`)}${el()?` (installed)`:``}`}var al=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},ol=null;async function sl(){return!(`serviceWorker`in navigator)||!window.isSecureContext?null:(ol??=await navigator.serviceWorker.register(Qc,{scope:`/`}).catch(e=>(console.warn(`service worker registration failed`,e),null)),ol)}var cl=(e,t)=>{let n=e?new Uint8Array(e):null;return n?.length===t.length&&n.every((e,n)=>e===t[n])};async function ll(e){let{publicKey:t}=await Re(`/api/push`,`Could not read this instance's push key`),n=al(t),r=await e.pushManager.getSubscription();if(r){if(cl(r.options.applicationServerKey,n))return r;await r.unsubscribe()}return e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:n})}async function ul(e){return x(`/api/push/subscribe`,{...e.toJSON(),label:il()})}async function dl(){ml();let e=await sl();if(!(!e||localStorage.getItem(Zc)!==`on`)&&!(!(`Notification`in window)||Notification.permission!==`granted`))try{await ul(await ll(e))}catch(e){console.warn(`re-registering this browser for notifications failed`,e)}}var fl=null,pl=null;function ml(){window.addEventListener(`beforeinstallprompt`,e=>{e.preventDefault(),fl=e,pl?.()}),window.addEventListener(`appinstalled`,()=>{fl=null,pl?.()})}function hl(e){let t=navigator;(e>0?t.setAppBadge?.(e):t.clearAppBadge?.())?.catch(()=>{})}function gl(){let e=R(`span`,`text-[11.5px]`,``),t=ni(`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(Zc)===`on`;async function a(){Si(e,`saving`,`asking this browser…`);let t=await Notification.requestPermission();if(t!==`granted`)return localStorage.setItem(Zc,`off`),c(),Si(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 sl();if(!n)return Si(e,`failed`,`This browser refused to register a service worker.`);try{let t=await ul(await ll(n));if(!t.ok)return Si(e,`failed`,await S(t,`Could not register this browser`));localStorage.setItem(Zc,`on`),c(),Si(e,`saved`,`This browser will be notified when a turn finishes unseen.`)}catch(t){Si(e,`failed`,`Could not subscribe: ${String(t)}`)}}async function o(){localStorage.setItem(Zc,`off`),c();let t=await(await sl())?.pushManager.getSubscription();t&&(await x(`/api/push/unsubscribe`,{endpoint:t.endpoint}),await t.unsubscribe()),Si(e,`idle`,`This browser will not be notified.`)}t.onclick=()=>{Si(e,`saving`,`sending…`),(async()=>{let t=await x(`/api/push/test`,{});if(!t.ok)return Si(e,`failed`,await S(t,`Could not send`));let{sent:n,failed:r}=await t.json();Si(e,r?`failed`:`saved`,`Handed ${String(n)} device(s) to their push service${r?`, ${String(r)} refused`:``}.`)})()};function s(){if(!fl)return[];let e=ni(`Install Pier`,!0);return e.onclick=()=>{let e=fl;e&&e.prompt().then(()=>e.userChoice).finally(()=>{fl=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=tl();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(),bi(`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 pl=c,c(),fi(`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,_l=null,vl=null;function yl(e){K&&!K.contains(e.target)&&e.target!==vl&&q()}var bl={ArrowDown:1,ArrowUp:-1},xl={n:1,j:1,p:-1,k:-1},Sl=()=>K!==null;function Cl(e){if(!(e.altKey||e.metaKey||e.shiftKey||!e.key))return e.ctrlKey?xl[e.key.toLowerCase()]:bl[e.key]}function wl(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 Tl(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 El(e){let t=K?Tl(K):null;if(t){let n=(t.ends?e.key===`Home`?`first`:e.key===`End`?`last`:void 0:void 0)??Cl(e);if(n!==void 0&&wl(t.rows,n)){e.preventDefault();return}}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),q())}function Dl(e){K&&!K.contains(e.target)&&q()}function q(){if(!K)return;document.removeEventListener(`pointerdown`,yl,!0),document.removeEventListener(`focusin`,yl,!0),document.removeEventListener(`keydown`,El,!0),window.removeEventListener(`scroll`,Dl,!0),window.removeEventListener(`resize`,q);let e=K;K=null,vl?.remove(),vl=null,e.contains(document.activeElement)&&_l?.focus({preventScroll:!0}),_l?.removeAttribute(`aria-expanded`),_l=null,e.inert=!0,e.dataset.closing=``,Promise.allSettled(e.getAnimations().map(e=>e.finished)).then(()=>e.remove())}var Ol=null;function kl(e){let t=e.getBoundingClientRect(),n={top:t.bottom+4,left:t.left};return t.width||t.height?n:Ol?.anchor===e?{top:Ol.top,left:Ol.left}:n}var Al=()=>window.innerWidth<640;function jl(e,t){q(),document.querySelectorAll(`.glass-menu[data-closing]`).forEach(e=>e.remove());let n=Al();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&&(vl=R(`div`,`fixed inset-0 z-50 bg-black/15`),vl.onclick=e=>{e.stopPropagation(),q()},r.append(vl)),r.append(K),!n){let t=kl(e);Ol={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`}_l=e,_l.setAttribute(`aria-expanded`,`true`),K.tabIndex=-1,(K.querySelector(`button, input, select, [tabindex='0']`)??K).focus({preventScroll:!0}),document.addEventListener(`pointerdown`,yl,!0),document.addEventListener(`focusin`,yl,!0),document.addEventListener(`keydown`,El,!0),window.addEventListener(`scroll`,Dl,!0),window.addEventListener(`resize`,q)}function Ml(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 ${Al()?`min-h-12 py-3`:`min-h-10 py-2`}`,...e.checked===void 0?[]:[_(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 Nl(e,t,n){let r=R(`div`,``);if(n&&Al()){let e=R(`button`,`icon-btn h-11 w-11`,_(_e));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(Ml(e));jl(e,r),K&&(K.dataset.menu=`true`,K.setAttribute(`aria-label`,n?`Actions for ${n}`:`Actions`),K.setAttribute(`role`,`group`))}var Pl=async e=>{let t=await C(`/api/fs/ls${e?.startsWith(`/`)?`?path=${encodeURIComponent(e)}`:``}`,`Could not list directories`);return t.ok?t.value:null},Fl=e=>e.entries.filter(e=>e.dir&&!e.name.startsWith(`.`)).map(e=>e.name),Il=`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`,Ll=`font-mono text-[0.875rem]`,Rl=(e,t,n)=>{let r=ri(e,`${Il} ${t}`);return r.onclick=n,r};function zl(e,t){let n=R(`div`,`mt-2 flex-none border-t border-neutral-200 pt-2`),r=Rl(`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 ${Ll} 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 x(`/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(_(ue)),n.append(r),n}function Bl(e,t,n){let r=e=>{n(e),q()};async function i(t){let n=await Pl(t);if(!n)return;let a=R(`div`,`flex max-h-[60dvh] w-full flex-col sm:w-88`),o=ri(`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 ${Ll} 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 Pl(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(Rl(`../`,`${Ll} text-neutral-500`,()=>void i(n.parent)));let d=Fl(n);for(let e of d)u.append(Rl(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,zl(n.path,e=>void i(e))),jl(e,a)}i(t)}function Vl(e,t,n,r){Nl(e,[...t.map(e=>({label:e.path,...e.hint?{hint:e.hint}:{},checked:e.path===n,onSelect:()=>{q(),r(e.path)}})),{label:`Browse…`,onSelect:()=>Bl(e,n||void 0,r)}])}var Hl=(e,t)=>n=>{e.value=n,e.dispatchEvent(new Event(`input`,{bubbles:!0})),t?.(n)};function Ul(e,t){let n=ri(`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=()=>Bl(n,e.value.trim()||void 0,Hl(e,t)),n}function Wl(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,Ul(r,n)),input:r}}var J=L(`#sidebar`),Gl=L(`#drawer-scrim`),Kl=L(`#mobile-title`),ql=L(`#mobile-menu`),Jl=L(`#session-meta`);function Yl(){delete J.dataset.open,Gl.classList.add(`hidden`),ru()}function Xl(e,t){Kl.textContent=e,Kl.classList.toggle(`cursor-pointer`,t),ql.classList.toggle(`hidden`,!t)}var Zl=`pier.railClosed`;localStorage.getItem(Zl)===`1`&&(document.body.dataset.rail=`closed`);function Ql(e){document.body.dataset.rail=e?`closed`:``,localStorage.setItem(Zl,e?`1`:`0`),ru()}function $l(){if(J.dataset.open!==void 0)return Yl();J.dataset.open=``,Gl.classList.remove(`hidden`),ru()}var eu=window.matchMedia(`(width < 48rem)`),tu=()=>eu.matches;function nu(){tu()?L(`#mobile-bar`).append(Jl):L(`#chat-menu`).before(Jl)}function ru(){let e=tu()&&J.dataset.open!==void 0,t=L(`main`);t.inert=e,J.inert=tu()?!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(tu()?`#drawer-toggle`:`#rail-toggle`).focus()}var iu=[L(`#rail-toggle`),L(`#drawer-toggle`)],au=`attention absolute -right-0.5 -top-0.5 rounded-full bg-amber-500`,ou=e=>e===1?R(`span`,`${au} h-2 w-2`):R(`span`,`${au} 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 su(e){for(let t of iu)t.querySelector(`.attention`)?.remove(),e&&t.append(ou(e))}var cu=20,lu=.35,uu=8;function du(){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)`,Gl.style.transition=`none`,Gl.classList.remove(`hidden`),Gl.style.opacity=String(e/i)},o=t=>{J.style.transition=``,J.style.transform=``,Gl.style.transition=``,Gl.style.opacity=``,t?(J.dataset.open=``,Gl.classList.remove(`hidden`),ru()):Yl(),e=-1,r=!1};window.addEventListener(`touchstart`,a=>{if(r||(e=-1,!tu()||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>cu||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)<uu)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*lu:t>i*.65)};window.addEventListener(`touchend`,s),window.addEventListener(`touchcancel`,s)}function fu(e){du(),ru(),nu(),eu.addEventListener(`change`,()=>{Yl(),nu()}),L(`#drawer-toggle`).setAttribute(`aria-controls`,`sidebar`),J.addEventListener(`keydown`,e=>{if(!(!tu()||J.dataset.open===void 0||e.defaultPrevented||e.isComposing)){if(e.key===`Escape`)e.preventDefault(),e.stopPropagation(),Yl();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=$l,Gl.onclick=Yl,ql.onclick=()=>e.sessionMenu(ql),Kl.onclick=()=>{ql.classList.contains(`hidden`)||e.sessionInfo(Kl)};let t=L(`#rail-toggle`);t.onclick=()=>Ql(document.body.dataset.rail!==`closed`),rc(t,`meta+b`,`Toggle sidebar`,()=>tu()?$l():Ql(document.body.dataset.rail!==`closed`))}var Y,pu=L(`#session-list`),mu=L(`#new-session`),hu=e=>e.modified??e.createdAt;function gu(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 _u(e,t){let{top:n,rest:r}=gu(e),i=[...n,...r].slice(0,t);return{rows:i,hidden:e.length-i.length}}function vu(e,t,n){let{top:r,rest:i}=gu(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 yu=8,bu=e=>[...new Set([...e].sort((e,t)=>t.createdAt-e.createdAt).map(e=>e.cwd))];function xu(e){let t=bu(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 Su=`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`,Cu=e=>e.unread,wu=e=>`${e} subagent${e>1?`s`:``} running`,Tu=e=>e.state===`streaming`||Cu(e)||e.activeRuns>0;function Eu(e){if(!Tu(e))return[];let t=e.state===`streaming`?[`bg-green-500 animate-pulse`,`working…`]:Cu(e)?[`bg-amber-500`,`turn finished — not viewed yet`]:[`bg-sky-500`,wu(e.activeRuns)],n=R(`span`,`h-2 w-2 flex-none rounded-full ${t[0]}`);return n.title=t[1],[n]}async function Du(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,Pu(),Y.onTitleChanged()};r(t.trim()||void 0),(await x(`/api/sessions/${e.id}/rename`,{name:t})).ok||r(n)}var Ou=`flex-none text-xs font-medium uppercase leading-5 text-neutral-500`,ku=e=>e.channel&&e.channel!==`web`?[R(`span`,Ou,e.channel[0]??``)]:[];function Au(e,t=R(`button`,Su,_(m))){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`),...Eu(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,...ku(e),t),r.title=[e.cwd,`active ${Br(hu(e))} ago · created ${new Date(e.createdAt).toLocaleDateString()}`,...e.channel&&e.channel!==`web`?[`answering ${e.channel}`]:[]].join(`
|
|
85
|
-
`),r}var ju=()=>`${Y.currentId()??``}\n${Nu}\n${JSON.stringify(Y.sessions())}`,Mu=``,Nu=20;function Pu(){let e=ju();if(e===Mu)return;Mu=e;let t=Y.sessions(),n=t.filter(Cu);su(n.length),hl(n.length);let{rows:r,hidden:i}=_u(t,Nu),a=pu.querySelector(`.session-more[aria-expanded='true']`),o=a?.closest(`[data-session-id]`)?.dataset.sessionId,s=r.map(e=>Au(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=()=>{Nu+=20,Pu(),pu.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(pu.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=[...pu.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`&&(pu.querySelector(`#session-load-more`)??pu.querySelector(`.session-open`)??L(`#new-session`)).focus({preventScroll:!0});pd()}function Fu(){if(mu.getAttribute(`aria-expanded`)===`true`)return q();let e=Y.sessions().find(e=>e.id===Y.currentId())?.cwd,t=xu(Y.sessions()).slice(0,yu);if(e&&!t.includes(e)&&t.unshift(e),!t.length)return Bl(mu,void 0,Y.createSession);Vl(mu,t.map(e=>({path:e,hint:Hr(e)})),e,Y.createSession)}function Iu(e){Y=e,mu.onclick=Fu,rc(mu,`shift+o`,`New session`,Fu,$s);let t=e=>{let t=vu(Y.sessions(),Y.currentId(),e);t&&Y.select(t)};sc(`shift+[`,()=>t(-1),$s),sc(`shift+]`,()=>t(1),$s)}var Lu,Ru=L(`#palette`),zu=L(`#palette-input`),Bu=L(`#palette-list`),Vu=L(`#palette-count`),Hu=[{name:`tasks`,icon:re,label:`Tasks`,detail:`Automation — task definitions and schedules`},{name:`runs`,icon:re,label:`Runs`,detail:`Automation — executions, subagents, decisions and callbacks`},{name:`activity`,icon:re,label:`Activity`,detail:`Automation — sessions and relationships`},{name:`boards`,icon:ne,label:`Boards`,detail:`Console — the static pages Pier publishes`},{name:`settings`,icon:pe,label:`Settings`,detail:`Console — models and providers, agent files and extensions, channels, password, sign out, security`}],Uu=7,Wu=3,Gu=8,Ku=80,qu=``,Ju,Yu,Xu;function Zu(e){qu!==e&&(clearTimeout(Xu),Yu?.abort(),Yu=void 0,qu=e,Ju=void 0,e&&(Xu=setTimeout(()=>{let t=Yu=new AbortController;C(`/api/search?q=${encodeURIComponent(e)}`,`Search unavailable`,{signal:t.signal}).then(n=>{t.signal.aborted||qu!==e||(Yu=void 0,Ju=n.ok?{hits:n.value.hits}:{error:n.error},Ru.open&&fd())})},Ku)))}var Qu=[],$u=0;function ed(e){if(Qu.length){$u=(e+Qu.length)%Qu.length;for(let[e,{el:t}]of Qu.entries())t.classList.toggle(`bg-indigo-50`,e===$u),t.setAttribute(`aria-selected`,String(e===$u));Qu[$u]?.el.scrollIntoView({block:`nearest`})}}var td=e=>e.hit?.at??e.session?.createdAt;function nd(e){let t=R(`span`,`min-w-0 flex-1 truncate text-neutral-500`);for(let n of e.replaceAll(/\s+/g,` `).split(``)){let[e=``,r]=n.split(``,2);r===void 0?t.append(e):t.append(R(`span`,`font-medium text-neutral-800`,e),r)}return t}var rd=`flex min-w-0 flex-1 items-baseline gap-2`,id=`shrink-0 truncate`,ad=`min-w-[2.5em] truncate text-[0.8125rem] text-neutral-400`,od=`flex-none text-[0.75rem] tabular-nums text-neutral-400`,sd=`flex h-7 w-7 flex-none items-center justify-center rounded-[8px] bg-neutral-100 text-neutral-500`;function cd(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`,sd,_(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(...Eu(e.session));let i=R(`span`,rd,R(`span`,`${id} ${e.detail?`max-w-[calc(100%-3em)]`:`max-w-full`}`,e.label));e.detail&&i.append(R(`span`,ad,e.detail)),r.append(i);let a=td(e);return a!==void 0&&r.append(R(`span`,od,Br(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`),nd(e.hit.snippet))),t.append(n),t.onclick=e.open,t}var ld=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 ud(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 dd=e=>e.channel&&e.channel!==`web`?e.channel:``;function fd(){let e=zu.value.trim(),t=e.toLowerCase().split(/\s+/).filter(Boolean),n=e=>{let n=e.toLowerCase();return t.every(e=>n.includes(e))},r=e=>()=>{Ru.close(),e()},i=Lu.sessions(),a=new Map(i.map(e=>[e.id,e])),{top:o,rest:s}=gu(i),c=[...o,...s],l=e=>({icon:ae,label:e.title??Ur(e.cwd),detail:[Hr(e.cwd),dd(e)].filter(Boolean).join(` · `),open:r(()=>void Lu.select(e.id)),session:e}),u=e=>({icon:te,label:Ur(e),detail:e,open:r(()=>void Lu.createSession(e))}),d=Hu.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(()=>Lu.openConsole(e))})),f={icon:te,label:`New session in…`,detail:`Pick a directory`,open:r(Fu)},p=[];if(e){let t=xu(i).filter(e=>n(Hr(e))).slice(0,Wu),o=c.filter(e=>n(`${e.title??``} ${e.cwd} ${dd(e)}`)).slice(0,Gu),s=new Set(o.map(e=>e.id)),m=o.map(l);if(qu!==e||!Ju)m.push(ud(`Searching messages…`));else if(`error`in Ju)m.push(ud(`Message search unavailable`,Ju.error));else{for(let e of Ju.hits){if(m.length>=Gu)break;let t=a.get(e.sessionId);!t||s.has(t.id)||m.push({...l(t),hit:e,open:r(()=>void Lu.select(t.id).then(()=>Wo(e.role,e.at)))})}m.length||m.push(ud(`No sessions match`))}p.push([`Actions`,[...t.map(u),...n(f.label)?[f]:[],...d]],[`Sessions`,m])}else{let e=a.get(Lu.currentId()??``);p.push([`Running`,c.filter(Tu).map(l)],[`Recent`,c.filter(e=>!Tu(e)).slice(0,Uu).map(l)],[`Actions`,[...e?[u(e.cwd)]:[],f]],[`Console`,d])}Qu=[];let m=[];for(let[e,t]of p)if(t.length){m.push(ld(e));for(let e of t){if(e instanceof HTMLElement){m.push(e);continue}let t=cd(e);Qu.push({el:t,open:e.open}),m.push(t)}}Bu.replaceChildren(...m.length?m:[ud(`Nothing matches`)]),Vu.textContent=`${Qu.length} ${Qu.length===1?`row`:`rows`}`,ed(Math.min($u,Math.max(0,Qu.length-1)))}function pd(){Ru.open&&fd()}function md(){if(Ru.open)return Ru.close();zu.value=``,$u=0,Zu(``),fd(),Ru.showModal(),zu.focus(),Lu.loadSessions().then(pd)}function hd(e){Lu=e;let t=L(`#open-palette`);t.onclick=md,rc(t,`k`,`Search sessions, messages and Console`,md,()=>Ru.open||Sl()),Ru.onclick=e=>{e.target===Ru&&Ru.close()},Ru.onclose=()=>Zu(``),zu.oninput=()=>{$u=0,Zu(zu.value.trim()),fd()},zu.onkeydown=e=>{let t=Cl(e);if(t!==void 0){e.preventDefault(),ed($u+t);return}e.key===`Enter`&&!e.ctrlKey&&(e.preventDefault(),Qu[$u]?.open())}}var gd=0,_d=e=>`${e.provider}/${e.id}`,vd=null;async function yd(){let{modelMenu:e}=await Re(`/api/settings`,`Could not read the pinned model menu`);return e}function bd(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`,_(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 xd({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`,xe(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,_(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-${++gd}`;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=xe(o),m(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`,xe(e))))}e.append(n,i),c.append(e)}let d=R(`div`,`max-h-72 overflow-y-auto py-1`),f=new Map(e.map(e=>[_d(e),e])),p=e=>{let n=(vd??[]).map(e=>({e,model:f.get(_d(e))})).filter(t=>!!t.model&&(!e||_d(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})=>bd({label:n.id,hint:xe(e.thinking),title:e.note,checked:!!t&&_d(t)===_d(n)&&o===e.thinking,onSelect:()=>i(n,e.thinking)})),R(`div`,`my-1 border-t border-neutral-100`))},m=n=>{d.replaceChildren();let r=n.trim().toLowerCase();p(r);let a=new Map;for(let t of e){if(r&&!_d(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&&_d(t)===_d(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`,_(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=>bd({label:e.id,checked:!!t&&_d(t)===_d(e),onSelect:()=>i(e)}))),d.append(o)}};return u.oninput=()=>m(u.value),m(``),yd().then(e=>{let t=JSON.stringify(e)!==JSON.stringify(vd);vd=e,t&&m(u.value)}).catch(e=>Hs(`model menu unavailable`,e)),s.append(c,d),queueMicrotask(()=>u.focus()),s}function Sd(e,t,n,r){let i=ri(t.model?`${t.model.id}${t.thinking?` · ${xe(t.thinking)}`:``}`:t.thinking?`Pi default · ${xe(t.thinking)}`:`Pi default`,`${hi} flex items-center gap-1.5 ${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=xd({models:n,current:t.model,thinkingLevel:t.thinking??`medium`,thinkingLevels:[...za],onPick:(e,n)=>{q(),r({model:e,thinking:n??t.thinking})},onThinkingPick:e=>{t={...t,thinking:e},r(t)}}),a=ri(`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),jl(i,o)},pi(e,i)}var X;function Cd(e){X=e,sc(wd,()=>{X.currentSession()&&(q(),X.toggleFiles())},$s)}var wd=`i`,Td=L(`#chat-title`),Ed=L(`#chat-menu`),Dd=L(`#session-meta`),Od=null,kd=new Map,Ad=e=>`${e.provider}/${e.id}`,Z=null,jd=null,Md=null,Nd=null;function Pd(){Z=null,jd=null,Md=null,Nd=null,Ud()}function Fd(e,t,n,r){Z=e,jd=t,Md=n,Nd=r,zd()}function Id(e){Nd=e.completedAt,jd&&={...jd,tokens:e.tokens},Ud()}var Ld=null;function Rd(e){Ld=e===null?null:Ur(e),zd()}function zd(){let e=X.currentSession();e&&(Ld=null),Td.textContent=e?e.title??Ur(e.cwd):Ld??X.currentId()??`no session`,Td.classList.toggle(`cursor-pointer`,!!e),Td.title=e?`Session info`:``,Td.onclick=e?()=>Wd(Td,e):null,Ed.classList.toggle(`hidden`,!e),e&&(Ed.onclick=()=>Yd(Ed,e)),Ud(),X.syncBar()}var Bd=70,Vd=(e,t)=>Math.min(100,Math.round(e/t.contextWindow*100)),Hd=e=>e.tokens===null?`?/${Se(e.contextWindow)}`:`${Se(e.tokens)}/${Se(e.contextWindow)} · ${100-Vd(e.tokens,e)}% left`;function Ud(){let e=jd,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`,_(h,`spinner h-3 w-3`),`${r} running`);e.title=`${wu(r)} · show the newest`,e.onclick=()=>{Go()||H(`error`,`no run card left in this transcript — reload the session to see it`)},i.push(e)}if(!n&&Ld&&i.push(R(`span`,`flex flex-none items-center gap-1.5 text-neutral-500`,_(h,`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 Gd(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`)),Md&&i.push(e(Md,`text-neutral-500 hover:text-indigo-700`))}let a=0;if(e&&t!==null){a=Vd(t,e);let n=a>=90?`text-red-700`:a>=Bd?`text-amber-700`:`text-neutral-500`;i.push(R(`span`,`flex-none font-mono ${n}`,Se(t).toLowerCase()))}let o=i.flatMap((e,t)=>t===0?[e]:[R(`span`,`text-neutral-300`,`·`),e]);Dd.replaceChildren(...o),Dd.classList.toggle(`hidden`,i.length===0),Dd.classList.toggle(`flex`,i.length>0),Dd.toggleAttribute(`data-urgent`,!n&&!!Ld||r>0||a>=Bd)}function Wd(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`,Md??`—`]),i.push([`Context`,jd?Hd(jd):`—`])),i.push([`Created`,Wr(t.createdAt),Vr(t.createdAt)]),a){let e=Nd;i.push(e===null?[`Last reply`,`—`]:[`Last reply`,Wr(e),Vr(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`,_(_e));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??Ur(t.cwd))),s);if(n){let n=R(`button`,`icon-btn h-11 w-11 sm:h-8 sm:w-8`,_(r));n.setAttribute(`aria-label`,`Back to session actions`),n.onclick=()=>Yd(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=Xr(`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),jl(e,o)}async function Gd(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`,_(r));t.setAttribute(`aria-label`,`Back to session actions`),t.onclick=()=>Yd(e,n);let i=R(`button`,`icon-btn h-11 w-11`,_(_e));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??Ur(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))}jl(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=xd({models:n,current:t===X.currentId()?Z:null,thinkingLevel:r,thinkingLevels:i,onPick:(e,n)=>{q(),Kd(t,e,n)},onThinkingPick:e=>void Jd(t,e)});o.replaceWith(l),o=l,jl(e,a)},u=t===X.currentId()&&Z?kd.get(Ad(Z)):void 0;Od&&u&&Md&&l(Od,Md,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(Od=e,t===X.currentId()&&Z&&kd.set(Ad(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 Kd(e,t,n){await qd(e,t)&&n&&await Jd(e,n)}async function qd(e,t){let n=Z;e===X.currentId()&&(Z=t,zd());let r=await x(`/api/sessions/${e}/model`,t);if(!r.ok){let{error:t}=await r.json().catch(()=>({}));return e===X.currentId()&&(Z=n,zd()),H(`error`,`model change failed: ${t??r.status}`),!1}let{model:i}=await r.json();return e===X.currentId()&&i&&(Z=i,zd()),!0}async function Jd(e,t){let n=await x(`/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()&&(Md=r,Ud())}function Yd(e,t){let n=t.id===X.currentId();Nl(e,[{label:`Rename…`,onSelect:()=>{q(),Du(t)}},{label:`Session info`,onSelect:()=>Wd(e,t,!0)},{label:`New session here`,separatorBefore:!0,hint:Hr(t.cwd),onSelect:()=>{q(),X.createSession(t.cwd)}},{label:`Browse files`,hint:n?Qs(wd):``,onSelect:()=>{q(),X.openFiles(n?void 0:t.cwd)}},{label:`Model & reasoning…`,separatorBefore:!0,hint:n?Z?.id??`…`:``,onSelect:()=>void Gd(e,t.id,t)}],t.title??Ur(t.cwd))}var Xd=`pier.theme`,Zd=[`system`,`light`,`dark`],Qd=window.matchMedia(`(prefers-color-scheme: dark)`),$d={system:se,light:he,dark:g},ef=()=>{let e=null;try{e=localStorage.getItem(Xd)}catch{return`system`}return e===`light`||e===`dark`?e:`system`},tf=()=>{let e=ef();return e===`system`?Qd.matches?`dark`:`light`:e};function nf(){let e=tf();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 rf(){let e=L(`#theme-toggle`),t=()=>{let t=ef();e.title=`Theme: ${t}${t===`system`?` (${tf()})`:``}`,e.replaceChildren(_($d[t])),e.setAttribute(`aria-label`,e.title),nf()};e.onclick=()=>{let e=Zd[(Zd.indexOf(ef())+1)%Zd.length];try{e===`system`?localStorage.removeItem(Xd):localStorage.setItem(Xd,e)}catch{}t()},Qd.addEventListener(`change`,t),t()}var af=`https://github.com/timqi/pier`,of=[`text-neutral-400`,`hover:text-neutral-700`],sf=[`rounded-full`,`bg-emerald-50`,`px-1.5`,`text-emerald-700`,`ring-1`,`ring-inset`,`ring-emerald-600/20`,`hover:bg-emerald-100`],cf=18e5,lf=null,uf=L(`#version`);function df(e){let t=lf?.available===!0&&lf.latest!==null;uf.textContent=`v${e}`,uf.title=t?`Pier ${lf?.latest} is out`:``,uf.classList.remove(...t?of:sf),uf.classList.add(...t?sf:of)}var ff=(e,t=`px-3 py-1 text-[12px] leading-snug text-neutral-500`)=>R(`p`,t,e);function pf(){let e=R(`div`,`flex w-72 flex-col gap-1 py-1`);if(!lf)return e.append(ff(`Checking the registry…`)),e;let{current:t,latest:n,available:r,canApply:i,problem:a}=lf,o=R(`span`,``,``),s=(e,t)=>Si(o,e?`failed`:`idle`,t),c=R(`div`,`flex items-center gap-2 px-3 py-1.5`);if(e.append(ff(r?`Pier ${n} is out`:`Pier ${t}`,`px-3 py-1 text-[12.5px] font-medium text-neutral-700`),ff(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(ff(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=ni(`Update now`,!0);e.onclick=()=>void(async()=>{e.disabled=!0,s(!1,`starting the updater…`);let t=await x(`/api/update`,{});if(!t.ok)return e.disabled=!1,s(!0,await S(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?`${af}/releases`:af,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(ff(`No service manager owns this Pier, so it cannot restart itself — update it with: pier update`));let l=bi(`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.`,lf.autoUpdate,e=>void(async()=>{lf&&(lf.autoUpdate=e);let t=await x(`/api/settings`,{autoUpdate:e},`PUT`);t.ok||(lf&&(lf.autoUpdate=!e),u&&(u.checked=!e),s(!0,await S(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 mf(e){let t=await C(`/api/update`,`Update check failed`);t.ok&&df((lf=t.value).current||e)}function hf(e){df(e),uf.onclick=e=>{e.preventDefault(),jl(uf,pf())};let t=()=>void mf(e);t(),setInterval(t,cf)}var Q,gf=L(`#chat-header`),_f=L(`#chat-title`),vf=[gf,V,L(`#composer`)],yf=()=>Ef===null,bf,xf,Sf,Cf=new Map,wf=new Map,Tf=new Map,Ef=null,Df=0,Of=[`files`],kf=new Map,Af={tasks:`Tasks`,runs:`Runs`,activity:`Activity`,boards:`Boards`,settings:`Settings`,files:`Files`},jf=[`tasks`,`runs`,`activity`],Mf=`Automation`,Nf=L(`#automation-view`),Pf=L(`#automation-tabs`),Ff=e=>jf.includes(e)?`tasks`:e;function If(e,t){let n=e!==null&&jf.includes(e);if(Nf.classList.toggle(`hidden`,!n),Nf.classList.toggle(`flex`,n),!n)return;let r=[];if(e===`tasks`&&!t){let e=ni(`New task`,!0);e.classList.add(`ml-auto`),e.disabled=!bf,e.onclick=()=>bf?.create(),r.push(e)}Pf.replaceChildren(ii(Mf),...jf.map(t=>si(Af[t],t===e,()=>Vf(t))),...r)}var Lf=e=>bf?.refresh(e),Rf=()=>xf?.refresh(),zf=()=>Sf?.refresh();function Bf(){Ef?Xl(jf.includes(Ef)?Mf:Af[Ef],!1):Xl(_f.textContent??``,Q.currentSession()!==void 0)}function Vf(e,t,n){if(Of.includes(e)){let t=$f();t&&(t.kind!==`console`||t.name!==e)&&kf.set(e,t)}tp({kind:`console`,name:e,arg:t,query:n}),Yl(),Ef=e;for(let e of vf)e.classList.add(`hidden`);jc();for(let[t,n]of Cf)t!==e&&n.hide();for(let[t,n]of Tf)n.classList.toggle(`bg-indigo-50`,t===Ff(e));If(e,t),Bf(),Hf(e,t,n,++Df)}async function Hf(e,t,n,r){let i=Cf.get(e);if(!i){let t=wf.get(e);if(!t){let n=L(`#${e}-view`);t=ip[e](n).catch(t=>(console.warn(`${e} view failed to load`,t),Kr(n,()=>n.replaceChildren(R(`p`,`p-4 text-[13px] text-red-600`,`Could not load ${Af[e]} — reload the page.`))))),wf.set(e,t)}i=await t,Cf.set(e,i),wf.delete(e)}Ef===e&&r===Df&&(i.show(t,n),e===`tasks`&&If(e,t))}var Uf=e=>Vf(`tasks`,e),Wf=(e={},t)=>Vf(`runs`,t,new URLSearchParams(e).toString()),Gf=e=>Wf({},e),Kf=(e,t)=>Vf(`files`,e,t?new URLSearchParams({select:t}).toString():void 0),qf=(e,t)=>{Ef===e?Yf(e):Vf(e,t)},Jf=e=>qf(`files`,e);function Yf(e){let t=Q.currentId(),n=kf.get(e)??(t?{kind:`session`,id:t}:null);kf.delete(e),n?tp(n):(history.replaceState(null,``,`#/`),Xf())}function Xf(){if(Ef){Ef=null;for(let e of Cf.values())e.hide();for(let e of Tf.values())e.classList.remove(`bg-indigo-50`);If(null);for(let e of vf)e.classList.remove(`hidden`);jc(),Bf(),Q.maybeAckRead()}}var Zf=e=>e.kind===`session`?`#/session/${encodeURIComponent(e.id)}`:`#/${e.name}${e.arg?`/${encodeURIComponent(e.arg)}`:``}${e.query?`?${e.query}`:``}`,Qf={config:`files`,channels:`channels`,providers:`models`};function $f(){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 Qf[n]?{kind:`console`,name:`settings`,arg:Qf[n]}:Object.hasOwn(Af,n)?{kind:`console`,name:n,arg:a,query:i}:n===`session`&&a?{kind:`session`,id:a}:null}var ep=!1;function tp(e,t=!1){if(ep)return;let n=Zf(e);location.hash!==n&&(t?history.replaceState(null,``,n):location.hash=n)}var np=e=>tp({kind:`session`,id:e});function rp(){let e=$f(),t=Q.sessions(),n=Q.currentId(),r=e?.kind===`session`?e.id:null,{top:i,rest:a}=gu(t),o=r??n??(i[0]??a[0])?.id??null;ep=!0;try{o&&o!==n&&Q.select(o),e?.kind===`console`?Vf(e.name,e.arg,e.query):Xf(),o||zd()}finally{ep=!1}e?.kind!==`console`&&o&&tp({kind:`session`,id:o},!0)}var ip={tasks:async e=>bf=(await Ii(async()=>{let{createTasksView:e}=await import(`./tasks-CY30H1u1.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(),Wf,Uf),runs:async e=>xf=(await Ii(async()=>{let{createRunsView:e}=await import(`./runs-DdERzeac.js`);return{createRunsView:e}},__vite__mapDeps([2,1]))).createRunsView(e,Q.select,Wf,Uf),activity:async e=>Sf=(await Ii(async()=>{let{createActivityView:e}=await import(`./activity-BSMeRcN2.js`);return{createActivityView:e}},[])).createActivityView(e,Q.select,Gf),boards:async e=>(await Ii(async()=>{let{createBoardsView:e}=await import(`./boards-BCWQMZry.js`);return{createBoardsView:e}},[])).createBoardsView(e,Q.select),files:async e=>(await Ii(async()=>{let{createExplorerView:e}=await import(`./explorer-Cr4XTi4j.js`);return{createExplorerView:e}},[])).createExplorerView(e,()=>Q.currentSession(),e=>Vf(`files`,e),()=>Yf(`files`)),settings:async e=>(await Ii(async()=>{let{createSettingsView:e}=await import(`./settings-CQDAHoMM.js`);return{createSettingsView:e}},[])).createSettingsView(e,()=>xu(Q.sessions()),e=>Vf(`settings`,e),Kf)};function ap(e){Q=e;for(let e of[`tasks`,`boards`,`settings`]){let t=L(`#open-${e}`);Tf.set(e,t),t.onclick=()=>Vf(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=rp}var op=[],sp=null,cp=0,lp=0,up=!1,$=null,dp=`idle`,fp=null,pp=0,mp=!1,hp=!1;async function gp(e){let t=++cp;++lp,up=!1,Xf(),Yl(),$=null,fp?.close(),fp=null,Ns(),Mc([]),Pd(),Rd(e),Ps(!0),hp=!0,Ac();let n=await x(`/api/sessions`,{cwd:e});if(t!==cp)return;if(hp=!1,!n.ok){Ps(!1),Rd(null),Ac(),H(`error`,`session create failed: ${n.status}`);return}let{id:r}=await n.json();t===cp&&(op.unshift({id:r,cwd:e,createdAt:Date.now(),state:`idle`,unread:!1,channel:`web`,activeRuns:0}),await Dp(r),$===r&&Ec())}function _p(e){op=e.map(e=>({...e,title:Pe(e.title)})),op.sort((e,t)=>t.createdAt-e.createdAt),Pu(),zd(),yp()}var vp=Fe(async()=>{_p(await Re(`/api/sessions`,`Could not load sessions`))});function yp(){if(document.hidden||!document.hasFocus()||!yf())return;let e=op.find(e=>e.id===$);e?.unread&&(e.unread=!1,Pu(),fetch(`/api/sessions/${e.id}/read`,{method:`POST`}))}function bp(){return op.find(e=>e.id===$)??(sp&&sp.id===$?sp:void 0)}async function xp(e){let t=await C(`/api/sessions/${e}`,`failed to load session`);$!==e||!t.ok||(sp={...t.value,title:Pe(t.value.title)},zd())}function Sp(e,t){let n=op.find(t=>t.id===e);!n||n.title||!t.trim()||(n.title=t.trim().slice(0,80),Pu(),zd())}function Cp(e){dp=e;let t=op.find(e=>e.id===$);t&&(t.state=e),Pu(),zd(),Ac(),e===`idle`&&vp()}function wp(e){if(!(e.sessionId!==$||e.seq<=pp))switch(pp=e.seq,e.type){case`turn-start`:mp=!0;break;case`system-input`:ks(),ns(e.text,e.origin);break;case`task-status`:$a(e.run);break;case`user-message`:{let t=je(e.text).text;if(Sp(e.sessionId,t),Dc(t))break;ks(),H(`user`,e.text,!1,e.ts),Ho();break}case`text-start`:ks();break;case`text-delta`:Os(e.text);break;case`thinking-delta`:ks(),Oo(e.ts,e.text);break;case`tool-start`:ks(),Eo(e.ts,e.toolCallId,e.toolName,e.args);break;case`tool-end`:Do(e.toolCallId,e.isError,e.output);break;case`turn-end`:mp=!1,js(e.text,e.meta),e.meta&&Id(e.meta);break;case`queue-state`:Nc(e.steering,e.followUp);break;case`queue-recovery`:Mc(e.batches,e.uncertain);break;case`context-compacted`:ks(),H(`system`,`Context compacted — ${Se(e.before)} → ${Se(e.after)}`,!1,e.ts),Ho();break;case`error`:wo(),H(`error`,e.message);break;case`state`:e.state===`idle`&&mp&&(mp=!1,Ms()),e.state===`idle`&&Nc([],[]),Cp(e.state)}}function Tp(){let e=new EventSource(`/api/events`);e.onopen=()=>{vp(),Lf(),Rf(),zf()},e.onerror=()=>qs(e,`Workspace`),e.onmessage=e=>{let t=JSON.parse(e.data);if(t.type===`sessions-changed`){vp();return}if(t.type===`tasks-changed`||t.type===`task-run-changed`||t.type===`task-message-changed`||t.type===`task-group-changed`){Lf(t.type===`task-run-changed`?t.taskId:void 0),Rf(),zf(),t.type===`task-run-changed`&&vp();return}if(zf(),t.sessionId===$)return;let n=op.find(e=>e.id===t.sessionId);n&&(n.state=t.state,Pu())}}function Ep(e,t,n){fp?.close();let r=new EventSource(`/api/sessions/${e}/events?after=${t}`),i=()=>fp===r&&$===e&&n===lp;r.onmessage=e=>{i()&&wp(JSON.parse(e.data))},r.addEventListener(`reset`,()=>{i()&&Op(e)}),r.onerror=()=>{i()&&qs(r,`Session`)},fp=r}async function Dp(e){Xf(),Yl(),np(e),!(e===$&&(fp||up))&&(++cp,++lp,hp=!1,Uc(),$=e,sp=null,op.some(t=>t.id===e)||xp(e),dp=op.find(t=>t.id===e)?.state??`idle`,Wc(e),Pu(),zd(),yp(),await Op(e))}async function Op(e){if($!==e)return;let t=++lp;fp?.close(),fp=null,up=!0,Ns(),Nc([],[]),Mc([]),Pd(),mp=!1,kc(),pp=0,Ps(!0);let n=await C(`/api/sessions/${e}/history`,`failed to load session`);if($!==e||t!==lp)return;if(up=!1,!n.ok){Ps(!1),H(`error`,n.error);return}let r=n.value;Fs(r.turns,r.state,r.backgroundRuns),pp=r.lastSeq,mp=r.state===`streaming`,Cp(r.state),Nc(r.queue.steering,r.queue.followUp),Mc(r.queueRecovery,r.queueUncertain);let i=r.turns.reduce((e,t)=>t.meta?.completedAt??e,null);Fd(r.model,r.context,r.thinkingLevel,i),Ep(e,`${r.epoch}:${r.lastSeq}`,t)}Us(),ve(),Ks(),rf();var kp=async e=>{$===e&&await Op(e)};Po({sessionId:()=>$,sessionCwd:()=>bp()?.cwd??null,sessionState:()=>dp,select:e=>void Dp(e),showRun:Gf,send:(e,t)=>void qc(e,t),ownTurn:e=>{Oc(e),Cp(`streaming`)},reload:kp}),Xc({sessionId:()=>$,starting:()=>hp,sessionState:()=>dp,chatVisible:yf,setState:Cp,reload:kp}),fu({sessionMenu:e=>{let t=bp();t&&Yd(e,t)},sessionInfo:e=>{let t=bp();t&&Wd(e,t)}}),Iu({sessions:()=>op,currentId:()=>$,select:e=>void Dp(e),sessionMenu:Yd,createSession:gp,onTitleChanged:zd}),hd({sessions:()=>op,loadSessions:vp,currentId:()=>$,select:Dp,createSession:gp,openConsole:Vf}),Cd({currentId:()=>$,currentSession:bp,createSession:e=>void gp(e),syncBar:Bf,openFiles:Kf,toggleFiles:Jf}),ap({sessions:()=>op,loadSessions:vp,currentId:()=>$,currentSession:bp,select:e=>void Dp(e),maybeAckRead:yp}),hf(`0.1.3`),dl(),document.addEventListener(`gesturestart`,e=>e.preventDefault()),document.addEventListener(`visibilitychange`,yp),window.addEventListener(`focus`,yp),Tp(),vp().then(rp);export{Le as $,ii as A,Vr as B,ri as C,pi as D,wi as E,gi as F,Gr as G,Kr as H,yi as I,Ur as J,R as K,bi as L,oi as M,vi as N,Ti as O,Si as P,Re as Q,ai as R,Ci as S,fi as T,Xr as U,Hr as V,ti as W,S as X,Fe as Y,C as Z,hi as _,q as a,_e as at,li as b,gl as c,l as ct,Ba as d,a as dt,ze as et,Ki as f,mi as g,di as h,Vl as i,_ as it,si as j,_i as k,oc as l,s as lt,Hi as m,xd as n,Pe as nt,Nl as o,ue as ot,Gi as p,Br as q,Wl as r,xe as rt,jl as s,h as st,Sd as t,x as tt,za as u,o as ut,ui as v,ni as w,xi as x,ci as y,Ei as z};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|