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