@timqi/pier 0.1.2 → 0.1.4

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