@maggioli-rd/aicore-agent-chat 1.1.1 → 1.3.0

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 (131) hide show
  1. package/README.md +33 -14
  2. package/dist/aicore-agent-chat.js +59 -38
  3. package/dist/aicore-agent-chat.js.map +1 -1
  4. package/dist/bundle/a2ui-C3GhjTrJ.js +113 -0
  5. package/dist/bundle/abnfDiagram-S7VZAUFO-DxkzIS8G.js +1 -0
  6. package/dist/bundle/architecture-WOLXFQ4H-BXMyXdT1.js +1 -0
  7. package/dist/bundle/architectureDiagram-YGSQEFNW-BmsDn6Ho.js +36 -0
  8. package/dist/bundle/blockDiagram-APKKGZFW-bG_MVPzT.js +140 -0
  9. package/dist/bundle/bpmnIcons-APHXDYXF-C0jbCElo.js +1 -0
  10. package/dist/bundle/c4Diagram-KJ2TOQU5-BVad-wQe.js +38 -0
  11. package/dist/bundle/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
  12. package/dist/bundle/chunk-5VM5RSS4-CwNG0iBi.js +15 -0
  13. package/dist/bundle/chunk-6MUBBAK2-CeH4cZO-.js +2 -0
  14. package/dist/bundle/chunk-AXFCVDMN-D0Vqm50X.js +62 -0
  15. package/dist/bundle/chunk-BG4553SI-DUBI9JbR.js +127 -0
  16. package/dist/bundle/chunk-DQASFODM-DBWVlIjs.js +10 -0
  17. package/dist/bundle/chunk-DUW6YSOI-ChybIQ82.js +1 -0
  18. package/dist/bundle/chunk-HFQBQIA3-D2xPptW8.js +1 -0
  19. package/dist/bundle/chunk-J5ZVWO5B-DHB__t6z.js +1 -0
  20. package/dist/bundle/chunk-JWPE2WC7-DVXcaiue.js +1 -0
  21. package/dist/bundle/chunk-KQLB2F66-BRGnyo9e.js +1 -0
  22. package/dist/bundle/chunk-KS47KZWR-DV3Gxewa.js +1 -0
  23. package/dist/bundle/chunk-LEVMRMFU-BdDTT4pw.js +1 -0
  24. package/dist/bundle/chunk-M57EVK23-BRqFqW5o.js +1 -0
  25. package/dist/bundle/chunk-NGNAAXSQ-DreF1ykJ.js +214 -0
  26. package/dist/bundle/chunk-OY52VR5R-BamrP8d_.js +88 -0
  27. package/dist/bundle/chunk-QB3YPZ4I-BqUUL29j.js +213 -0
  28. package/dist/bundle/chunk-R3KSYZAL-gmtEjdKU.js +1 -0
  29. package/dist/bundle/chunk-STOXU5M4-DdqxXfKq.js +72 -0
  30. package/dist/bundle/chunk-TU62E6Q5-B4GgWjUW.js +1 -0
  31. package/dist/bundle/chunk-X4PVCEUW-BcN5Aq5G.js +1 -0
  32. package/dist/bundle/chunk-XXDRQBXY-BIvjAdC_.js +1 -0
  33. package/dist/bundle/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
  34. package/dist/bundle/classDiagram-v2-L25IHNXF-Dw7so3mk.js +217 -0
  35. package/dist/bundle/cose-bilkent-JH36ORCC-DUvnuVrm.js +1 -0
  36. package/dist/bundle/cynefin-EF2NZ3EQ-CcVPiRLN.js +1 -0
  37. package/dist/bundle/cynefinDiagram-L36ESFBY-eO6Z3Kvn.js +62 -0
  38. package/dist/bundle/cytoscape.esm-CsT4DLSP.js +321 -0
  39. package/dist/bundle/d3-hierarchy-i5r04UUG.js +1 -0
  40. package/dist/bundle/d3-scale-BEO6F4Sh.js +1 -0
  41. package/dist/bundle/d3-scale-chromatic-DhHjp77O.js +1 -0
  42. package/dist/bundle/d3-selection-CBFxn8wf.js +1 -0
  43. package/dist/bundle/d3-shape-v1Y4qR5e.js +1 -0
  44. package/dist/bundle/dagre-SPEB5RXH-ByBZqBaT.js +4 -0
  45. package/dist/bundle/diagram-3B7GL73J-BkQkIpxz.js +200 -0
  46. package/dist/bundle/diagram-DNEMPZML-DYthXzRv.js +24 -0
  47. package/dist/bundle/diagram-L3MUGCDN-D4DIzfHH.js +41 -0
  48. package/dist/bundle/diagram-LA4NIPWU-C2P-hZD1.js +24 -0
  49. package/dist/bundle/diagram-MHCOC4E2-BwauFnTV.js +3 -0
  50. package/dist/bundle/diagram-XPFHEONP-DC_v3Llc.js +30 -0
  51. package/dist/bundle/dist-CwuaKeLF.js +1 -0
  52. package/dist/bundle/ebnfDiagram-UZSYDL2S-CmwGlC8L.js +1 -0
  53. package/dist/bundle/elk-XV6XMXQE-CTlty3p3.js +27 -0
  54. package/dist/bundle/erDiagram-EYBAPDEH-Bu6phvJH.js +99 -0
  55. package/dist/bundle/eventmodeling-K75KTNOO-B1q0nOJE.js +1 -0
  56. package/dist/bundle/flowDiagram-MALGAFMO-D9D_AzXh.js +1 -0
  57. package/dist/bundle/ganttDiagram-23REXITY-COK7rxO4.js +292 -0
  58. package/dist/bundle/gitGraph-VSP46ZUC-DS7S_jKI.js +1 -0
  59. package/dist/bundle/gitGraphDiagram-STJD7YCW-DhVK8Hqh.js +106 -0
  60. package/dist/bundle/graphlib-Bgy7WbC7.js +1 -0
  61. package/dist/bundle/info-OHQRW6UA-BjEWvFlW.js +1 -0
  62. package/dist/bundle/infoDiagram-KBXO4MBG-Dg3zWdHP.js +2 -0
  63. package/dist/bundle/ishikawaDiagram-M35NCXHK-C2g8ghrV.js +70 -0
  64. package/dist/bundle/journeyDiagram-OPLOXDXO-DMZkL-i1.js +139 -0
  65. package/dist/bundle/kanban-definition-BZKZHSQY-Dr43IiJD.js +89 -0
  66. package/dist/bundle/katex-rAoShGnF.js +257 -0
  67. package/dist/bundle/math-Cx-Q-b8s.js +262 -0
  68. package/dist/bundle/mermaid-DaDuEHir.js +43 -0
  69. package/dist/bundle/mermaid-parser.core-Bv_Zx_ZE.js +6 -0
  70. package/dist/bundle/mindmap-definition-I2QAS2VK-BXCWJ_1R.js +98 -0
  71. package/dist/bundle/packet-JDAUHWVQ-CgB2qE5t.js +1 -0
  72. package/dist/bundle/pegDiagram-FD4XPPHP-CR58gOgF.js +1 -0
  73. package/dist/bundle/pie-XZMESJXO-CvXWTfIG.js +1 -0
  74. package/dist/bundle/pieDiagram-J4AKIIQI-D0GhbNJg.js +39 -0
  75. package/dist/bundle/quadrantDiagram-XTYBLID2-BKBEdwvC.js +7 -0
  76. package/dist/bundle/radar-ABXABTNO-8V_xx_AB.js +1 -0
  77. package/dist/bundle/railroad-I3PHUGI6-Bvb0GUva.js +1 -0
  78. package/dist/bundle/railroad-abnf-LNEFI6M7-D8xGcObq.js +1 -0
  79. package/dist/bundle/railroad-ebnf-DWYD2UWJ-Ch8wBawI.js +1 -0
  80. package/dist/bundle/railroad-peg-JR7BVNR7-CGndbjed.js +1 -0
  81. package/dist/bundle/railroadDiagram-MRQ6NCDL-DvqHkO2C.js +1 -0
  82. package/dist/bundle/requirementDiagram-Y7LWUY3S-bCLAM9sl.js +84 -0
  83. package/dist/bundle/rolldown-runtime-BNaE-Ejt.js +1 -0
  84. package/dist/bundle/rough.esm-Dy-Kn_BL.js +1 -0
  85. package/dist/bundle/sankeyDiagram-WGJFYUXA-8ehuPvHQ.js +40 -0
  86. package/dist/bundle/sequenceDiagram-5NDRBG5M-Cdg1YzMw.js +169 -0
  87. package/dist/bundle/sizeCapture-INFHLROL-Ct7XApxm.js +1 -0
  88. package/dist/bundle/stateDiagram-v2-FJ4FJNEA-B69v2YYC.js +291 -0
  89. package/dist/bundle/swimlanes-UMQ2AFYF-C_qI6rnK.js +1 -0
  90. package/dist/bundle/swimlanesDiagram-OMPLPG4O-CS11qSCX.js +8 -0
  91. package/dist/bundle/timeline-definition-SEUHKTQE-BCU0-H8D.js +120 -0
  92. package/dist/bundle/treeView-D4JQ5SDB-CpjURS-c.js +1 -0
  93. package/dist/bundle/treemap-SAJKECNS-CFFTaiIN.js +1 -0
  94. package/dist/bundle/usecaseDiagram-AFA6YXN4-46V1jsea.js +476 -0
  95. package/dist/bundle/vega-eBn1AexV.js +33 -0
  96. package/dist/bundle/vennDiagram-NNMJR3RB-q4Q4x2Q6.js +34 -0
  97. package/dist/bundle/wardley-7MLQ67FV-DhnATL7b.js +1 -0
  98. package/dist/bundle/wardleyDiagram-S7YFUSEH-BHIufnZW.js +78 -0
  99. package/dist/bundle/xychartDiagram-GGNKY7IX-CxAjpN3O.js +7 -0
  100. package/dist/chunks/a2ui-BLaPxJ9N.js +961 -0
  101. package/dist/chunks/a2ui-BLaPxJ9N.js.map +1 -0
  102. package/dist/chunks/math-D5IXRTov.js +86 -0
  103. package/dist/chunks/math-D5IXRTov.js.map +1 -0
  104. package/dist/chunks/mermaid-j9RNkOnL.js +197 -0
  105. package/dist/chunks/mermaid-j9RNkOnL.js.map +1 -0
  106. package/dist/chunks/rich-C2iN_5zh.js +156 -0
  107. package/dist/chunks/rich-C2iN_5zh.js.map +1 -0
  108. package/dist/chunks/sanitize-COLQzplk.js +240 -0
  109. package/dist/chunks/sanitize-COLQzplk.js.map +1 -0
  110. package/dist/chunks/{src-DPfU5Bd2.js → src-Blgo9nVC.js} +387 -73
  111. package/dist/chunks/src-Blgo9nVC.js.map +1 -0
  112. package/dist/chunks/vega-BkX1Fjq6.js +301 -0
  113. package/dist/chunks/vega-BkX1Fjq6.js.map +1 -0
  114. package/dist/define.js +1 -1
  115. package/dist/index.js +1 -1
  116. package/dist/types/element/i18n.d.ts +21 -2
  117. package/dist/types/element/index.d.ts +11 -2
  118. package/dist/types/element/markdown.d.ts +6 -3
  119. package/dist/types/element/rich/a2ui-format.d.ts +45 -0
  120. package/dist/types/element/rich/a2ui-icons.d.ts +1 -0
  121. package/dist/types/element/rich/a2ui-views.d.ts +37 -0
  122. package/dist/types/element/rich/a2ui.d.ts +2 -0
  123. package/dist/types/element/rich/index.d.ts +66 -0
  124. package/dist/types/element/rich/math.d.ts +4 -0
  125. package/dist/types/element/rich/mermaid.d.ts +2 -0
  126. package/dist/types/element/rich/vega.d.ts +2 -0
  127. package/dist/types/element/sanitize.d.ts +34 -0
  128. package/dist/types/element/styles.d.ts +1 -1
  129. package/dist/types/jsx.d.ts +2 -0
  130. package/package.json +12 -6
  131. package/dist/chunks/src-DPfU5Bd2.js.map +0 -1
@@ -1,62 +1,64 @@
1
1
  function e(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var t=class extends Error{status;kind;errorCode;requestId;retryAfter;authDescription;constructor(e,t){super(e.message||`HTTP ${e.status}`),this.name=`AicoreError`,this.status=e.status,this.errorCode=e.errorCode,this.requestId=e.requestId,this.retryAfter=e.retryAfter,this.authDescription=e.authDescription,this.kind=t??r(e)}},n=/* @__PURE__ */ new Set([`tenant_required`,`tenant_not_allowed`,`tenant_not_registered`]);function r({status:e,errorCode:t}){return e===0?`network`:t&&n.has(t)?`tenant_refused`:e===401?`auth_required`:e===403?`forbidden`:e===404?`not_found`:e===409?`busy`:e===423?`locked`:e===429?`rate_limited`:`http`}function i(e){return e instanceof t?e:new t({status:0,message:String(e)})}function a(e,t){return e instanceof DOMException&&e.name===`AbortError`||t?.aborted===!0}function o(e){if(!e)return{};let t=t=>RegExp(`${t}="([^"]*)"`).exec(e)?.[1];return{error:t(`error`),description:t(`error_description`)}}function s(e){return e.status===401&&o(e.headers.get(`WWW-Authenticate`)).error===`invalid_token`}async function c(n){let r=n.headers.get(`Retry-After`)?.trim(),i={status:n.status,message:``,requestId:n.headers.get(`X-Request-Id`)??void 0,retryAfter:r&&/^\d+$/.test(r)?Number(r):void 0,authDescription:o(n.headers.get(`WWW-Authenticate`)).description};try{let t=await n.json();if(e(t)){let e=[];typeof t.message==`string`&&t.message&&e.push(t.message),typeof t.detail==`string`&&t.detail&&e.push(t.detail),i.message=[...new Set(e)].join(`: `),typeof t.error_code==`string`&&(i.errorCode=t.error_code),typeof t.request_id==`string`&&(i.requestId=t.request_id)}}catch{}return new t(i)}var l=class{#e=``;#t=``;#n=[];#r;#i=!1;push(e){let t=e;this.#i&&t.startsWith(`
2
2
  `)&&(t=t.slice(1)),this.#i=!1,this.#e+=t;let n=[],r=/\r\n|\r|\n/g,i=0,a;for(;(a=r.exec(this.#e))!==null;){if(a[0]===`\r`&&a.index===this.#e.length-1){this.#i=!0;let e=this.#a(this.#e.slice(i,a.index));e&&n.push(e),i=this.#e.length;break}let e=this.#a(this.#e.slice(i,a.index));e&&n.push(e),i=a.index+a[0].length}return this.#e=this.#e.slice(i),n}end(){this.#e=``,this.#s()}#a(e){if(e===``)return this.#o();if(e.startsWith(`:`))return null;let t=e.indexOf(`:`),n=t>=0?e.slice(0,t):e,r=t>=0?e.slice(t+1):``;return r.startsWith(` `)&&(r=r.slice(1)),n===`event`?this.#t=r:n===`data`?this.#n.push(r):n===`id`&&!r.includes(`\0`)&&(this.#r=r),null}#o(){if(this.#n.length===0&&this.#t===``)return this.#s(),null;let e={event:this.#t||`message`,data:this.#n.join(`
3
- `)};return this.#r!==void 0&&(e.id=this.#r),this.#s(),e}#s(){this.#t=``,this.#n=[],this.#r=void 0}};async function*u(e){let t=e.getReader(),n=new TextDecoder,r=new l;try{for(;;){let{done:e,value:i}=await t.read(),a=e?n.decode():n.decode(i,{stream:!0});if(yield*r.push(a),e)break}r.end()}finally{await t.cancel().catch(()=>t.releaseLock())}}function d(e){try{return e.data?JSON.parse(e.data):{}}catch{return{raw:e.data}}}var f=3e4;function p(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=t+`=`.repeat((4-t.length%4)%4),r=atob(n),i=Uint8Array.from(r,e=>e.charCodeAt(0));return new TextDecoder().decode(i)}function m(t){let n=t.split(`.`)[1];if(!n)return null;try{let t=JSON.parse(p(n));return e(t)?t:null}catch{return null}}function h(e){let t=m(e)?.exp;return typeof t==`number`?t*1e3:null}var g=class{#e;#t;#n=null;#r=0;#i=null;#a=!1;#o=0;constructor(e,t=Date.now){this.#e=e,this.#t=t}get(){return this.#n&&this.#t()<this.#r-3e4?Promise.resolve(this.#n):this.#s(!1)}refresh(){return this.#n=null,this.#r=0,this.#s(!0)}clear(){this.#n=null,this.#r=0,this.#i=null,this.#a=!1,this.#o++}#s(e){if(this.#i&&(this.#a||!e))return this.#i;let n=++this.#o,r=Promise.resolve().then(()=>this.#e({retry:e})).then(e=>{if(!e)throw new t({status:401,message:`No token available for the user`},`auth_required`);return n===this.#o&&(this.#n=e,this.#r=h(e)??0),e}).finally(()=>{this.#i===r&&(this.#i=null,this.#a=!1)});return this.#i=r,this.#a=e,r}},_={text:``,result:null,sources:[],activity:null,title:null,error:null,finished:!1},ee=t=>e(t)?t:{};function v(e,t,n){let r=ee(n),i=e=>{let t=r[e];return typeof t==`string`&&t?t:void 0};switch(t){case`token`:return typeof r.text==`string`?{...e,text:e.text+r.text}:e;case`truncate`:return{...e,text:``};case`result`:return{...e,result:r.payload??null};case`context`:return{...e,sources:Array.isArray(r.context)?r.context:[]};case`title`:return{...e,title:i(`title`)??e.title};case`nop`:return i(`message`)?{...e,activity:i(`message`)}:e;case`error`:{let t=i(`error_code`),n=i(`detail`),a=i(`trace_id`);return{...e,error:{code:typeof r.code==`number`?r.code:500,...i(`message`)?{message:i(`message`)}:{},...t?{errorCode:t}:{},...n?{detail:n}:{},...a?{traceId:a}:{}}}}case`done`:return{...e,finished:!0,activity:null};default:return e}}function y({text:e,result:t}){return e||t==null?e:typeof t==`object`&&!Array.isArray(t)&&Object.keys(t).length===1&&`text`in t&&typeof t.text==`string`?t.text:"```json\n"+JSON.stringify(t,null,2)+"\n```"}function b({message:e,detail:t,traceId:n},r={}){let{failed:i=`The agent could not answer.`,trace:a=e=>`Trace ${e}`}=r,o=[e??i];return t&&o.push(t),n&&!e?.includes(n)&&o.push(a(n)),o.join(`
4
- `)}var x={conversation:`aicore-conversation`,turn:`aicore-turn`,error:`aicore-error`,authRequired:`aicore-auth-required`,tenantRefused:`aicore-tenant-refused`},S=3,te=1e3,ne=`100`;function re(e){let t=e.trim().replace(/\/+$/,``);return t.endsWith(`/api/v1`)?t:`${t}/api/v1`}function C(){if(typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));e[6]=(e[6]??0)&15|64,e[8]=(e[8]??0)&63|128;let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}var w=e=>e instanceof t&&(e.status===0||e.status>=502);function ie(e,t){return new Promise(n=>{if(t?.aborted)return n();let r=setTimeout(n,e);t?.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})})}var ae=class extends EventTarget{apiBase;tenant;#e;#t;#n;#r;#i;#a=null;constructor(e){super(),this.apiBase=re(e.baseUrl),this.tenant=e.tenant??null,this.#e=new g(e.getToken),this.#t=e.fetch??globalThis.fetch.bind(globalThis),this.#n=e.onRequest,this.#r=e.onIdentityChange}clearToken(){this.#e.clear()}async checkIdentity(){try{await this.#l(!1)}catch{}}#o(e,t,n){let r=new Headers({Accept:t.accept??`application/json`,Authorization:`Bearer ${e}`});return this.tenant&&r.set(`X-Tenant`,this.tenant),t.body!==void 0&&r.set(`Content-Type`,`application/json`),n&&r.set(`Idempotency-Key`,n),t.lastEventId&&r.set(`Last-Event-ID`,t.lastEventId),{method:t.method??`GET`,headers:r,body:t.form??(t.body===void 0?void 0:JSON.stringify(t.body)),credentials:`omit`,cache:`no-store`,signal:t.signal}}async#s(e,n,r){let i=performance.now(),o;try{o=await this.#t(this.apiBase+e,n)}catch(o){throw a(o,n.signal??void 0)?o:(this.#c(n,e,0,i,r),new t({status:0,message:`AI-CORE unreachable`}))}return this.#c(n,e,o.status,i,r,o),o}#c(e,t,n,r,i,a){this.#n?.({method:e.method??`GET`,path:t,status:n,requestId:a?.headers.get(`X-Request-Id`)??void 0,durationMs:Math.round(performance.now()-r),retriedWithFreshToken:i})}async#l(e){let n;try{n=await(e?this.#e.refresh():this.#e.get())}catch(e){throw e instanceof t?e:new t({status:0,message:`No token available: ${e instanceof Error?e.message:String(e)}`},`auth_required`)}let r=m(n)?.sub,i=typeof r==`string`&&r!==``?r:null,a=this.#i!==void 0&&(i===null||this.#i===null?n!==this.#a:i!==this.#i);return this.#i=i,this.#a=n,a&&this.#r?.(),n}async#u(e,t={}){let n=t.idempotent?C():void 0;try{let r=await this.#l(!1),i=await this.#s(e,this.#o(r,t,n),!1);if(s(i)&&(r=await this.#l(!0),i=await this.#s(e,this.#o(r,t,n),!0)),!i.ok)throw await c(i);return i}catch(e){if(a(e,t.signal))throw e;let n=i(e);throw t.report!==!1&&this.#f(n),n}}async#d(e,t){return await(await this.#u(e,t)).json()}#f(e){this.dispatchEvent(new CustomEvent(x.error,{detail:e})),e.kind===`auth_required`&&this.dispatchEvent(new CustomEvent(x.authRequired,{detail:e})),e.kind===`tenant_refused`&&this.dispatchEvent(new CustomEvent(x.tenantRefused,{detail:e}))}listAgents(e){let t=new URLSearchParams({limit:ne});return e&&t.set(`cursor`,e),this.#d(`/agents?${t.toString()}`)}getAgent(e){return this.#d(`/agents/${encodeURIComponent(e)}`)}listConversations(e,t){let n=new URLSearchParams({id_agent:e,limit:`50`});return t&&n.set(`cursor`,t),this.#d(`/conversations?${n.toString()}`)}async openConversation(e){let t=await this.#d(`/agents/${encodeURIComponent(e)}/conversations`,{method:`POST`,idempotent:!0});return this.dispatchEvent(new CustomEvent(x.conversation,{detail:{idConv:t.id_conv,idAgent:e}})),t}async history(e){let t=[],n=null;do{let r=new URLSearchParams({limit:ne});n&&r.set(`cursor`,n);let i=await this.#d(`/conversations/${encodeURIComponent(e)}/messages?${r.toString()}`);t.push(...i.items),n=i.next_cursor}while(n);return t}renameConversation(e,t){return this.#d(`/conversations/${encodeURIComponent(e)}`,{method:`PATCH`,body:{title:t}})}async deleteConversation(e){await this.#u(`/conversations/${encodeURIComponent(e)}`,{method:`DELETE`})}sendMessage(e,t){return this.#d(`/conversations/${encodeURIComponent(e)}/messages`,{method:`POST`,body:t,idempotent:!0})}uploadFile(e,t){let n=new FormData;return n.append(`file`,t,t.name),this.#d(`/conversations/${encodeURIComponent(e)}/files`,{method:`POST`,form:n})}listFiles(e){return this.#d(`/conversations/${encodeURIComponent(e)}/files`)}async deleteFile(e,t){await this.#u(`/conversations/${encodeURIComponent(e)}/files/${encodeURIComponent(t)}`,{method:`DELETE`})}async sendFeedback(e,t,n,r){await this.#u(`/conversations/${encodeURIComponent(e)}/messages/${encodeURIComponent(t)}/feedback`,{method:`PUT`,body:r?{rating:n,text:r}:{rating:n}})}async*streamTurn(e,n,r){let i=`/conversations/${encodeURIComponent(e)}/stream?id_query=${encodeURIComponent(n)}`,o,s=0;for(let e=!1;;e=!0){let n=o,c=null;try{c=await this.#u(i,{signal:r,accept:`text/event-stream`,lastEventId:o,report:!1})}catch(t){if(a(t,r))return;if(!e||!w(t))throw t}if(c?.body)try{for await(let e of u(c.body))if(e.id!==void 0&&(o=e.id),yield{kind:e.event,data:d(e),id:e.id},e.event===`done`)return}catch(e){if(a(e,r))return}if(o!==n&&(s=0),++s>S)throw new t({status:0,message:`Connection lost while streaming`});if(await ie(te*2**(s-1),r),r?.aborted)return}}async ask(e){let n=e.idConv??(await this.openConversation(e.idAgent)).id_conv;e.onConversation?.(n);let{id_query:r}=await this.sendMessage(n,e.request),i=_,a=!1;try{for await(let t of this.streamTurn(n,r,e.signal))i=v(i,t.kind,t.data),e.onUpdate?.(i,t)}catch(e){if(e instanceof t&&e.status===410)a=!0;else throw e instanceof t&&this.#f(e),e}return(a||i.error?.code===410)&&(i=await this.#p(n,r)),this.dispatchEvent(new CustomEvent(x.turn,{detail:{idConv:n,idQuery:r,turn:i}})),{idConv:n,idQuery:r,turn:i}}async#p(e,t){let n=(await this.history(e)).find(e=>e.role===`assistant`&&e.id_query===t);return{..._,text:n?.content??``,sources:n?.sources??[],finished:!0}}};function oe(e,t){this.v=e,this.k=t}function se(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 ce(e){if(Array.isArray(e))return e}function le(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){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function ue(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
5
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function de(e,t){return ce(e)||le(e,t)||fe(e,t)||ue()}function fe(e,t){if(e){if(typeof e==`string`)return se(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)?se(e,t):void 0}}function pe(e){var t,n;function r(t,n){try{var a=e[t](n),o=a.value,s=o instanceof oe;Promise.resolve(s?o.v:o).then(function(n){if(s){var c=t===`return`&&o.k?t:`next`;if(!o.k||n.done)return r(c,n);n=e[c](n).value}i(!!a.done,n)},function(e){r(`throw`,e)})}catch(e){i(2,e)}}function i(e,i){e===2?t.reject(i):t.resolve({value:i,done:e}),(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,i){return new Promise(function(a,o){var s={key:e,arg:i,resolve:a,reject:o,next:null};n?n=n.next=s:(t=n=s,r(e,i))})},typeof e.return!=`function`&&(this.return=void 0)}pe.prototype[typeof Symbol==`function`&&Symbol.asyncIterator||`@@asyncIterator`]=function(){return this},pe.prototype.next=function(e){return this._invoke(`next`,e)},pe.prototype.throw=function(e){return this._invoke(`throw`,e)},pe.prototype.return=function(e){return this._invoke(`return`,e)};var me=Object.entries,he=Object.setPrototypeOf,ge=Object.isFrozen,_e=Object.getPrototypeOf,T=Object.getOwnPropertyDescriptor,E=Object.freeze,D=Object.seal,ve=Object.create,ye=typeof Reflect<`u`&&Reflect,be=ye.apply,xe=ye.construct;E||=function(e){return e},D||=function(e){return e},be||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},xe||=function(e){return new e(...[...arguments].slice(1))};var Se=A(Array.prototype.forEach);Array.prototype.indexOf;var Ce=A(Array.prototype.lastIndexOf),we=A(Array.prototype.pop),Te=A(Array.prototype.push),Ee=A(Array.prototype.slice),De=A(Array.prototype.splice),Oe=Array.isArray,ke=j(Set),Ae=A(Set.prototype.add),je=A(Set.prototype.has),Me=A(String.prototype.toLowerCase),Ne=A(String.prototype.toString),Pe=A(String.prototype.match),Fe=A(String.prototype.replace),Ie=A(String.prototype.indexOf),Le=A(String.prototype.trim),Re=A(Number.prototype.toString),ze=A(Boolean.prototype.toString),Be=typeof BigInt>`u`?null:A(BigInt.prototype.toString),Ve=typeof Symbol>`u`?null:A(Symbol.prototype.toString),O=A(Object.prototype.hasOwnProperty),He=A(Object.prototype.toString),k=A(RegExp.prototype.test),Ue=j(TypeError);function A(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return be(e,t,n)}}function j(e){return function(){return xe(e,[...arguments])}}function M(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Me;if(he&&he(e,null),!Oe(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(ge(t)||(t[r]=e),i=e)}e[i]=!0}return e}function We(e){for(let t=0;t<e.length;t++)O(e,t)||(e[t]=null);return e}function N(e){let t=ve(null);for(let r of me(e)){var n=de(r,2);let i=n[0],a=n[1];O(e,i)&&(t[i]=Oe(a)?We(a):a&&typeof a==`object`&&a.constructor===Object?N(a):a)}return t}function Ge(e){switch(typeof e){case`string`:return e;case`number`:return Re(e);case`boolean`:return ze(e);case`bigint`:return Be?Be(e):`0`;case`symbol`:return Ve?Ve(e):`Symbol()`;case`undefined`:return He(e);case`function`:case`object`:{if(e===null)return He(e);let t=e,n=P(t,`toString`);if(typeof n==`function`){let e=n(t);return typeof e==`string`?e:He(e)}return He(e)}default:return He(e)}}function P(e,t){for(;e!==null;){let n=T(e,t);if(n){if(n.get)return A(n.get);if(typeof n.value==`function`)return A(n.value)}e=_e(e)}function n(){return null}return n}function Ke(e,t){for(;e!==null;){let n=T(e,t);if(n)return n.get?A(n.get):null;e=_e(e)}return null}function qe(e){try{return k(e,``),!0}catch{return!1}}var Je=E(/* @__PURE__ */ `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(`.`)),Ye=E(/* @__PURE__ */ `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(`.`)),Xe=E([`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`]),Ze=E([`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`]),Qe=E(/* @__PURE__ */ `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(`.`)),$e=E([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),et=E([`#text`]),tt=E(/* @__PURE__ */ `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(`.`)),nt=E(/* @__PURE__ */ `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(`.`)),rt=E(/* @__PURE__ */ `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(`.`)),it=E([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),at=D(/{{[\w\W]*|^[\w\W]*}}/g),ot=D(/<%[\w\W]*|^[\w\W]*%>/g),st=D(/\${[\w\W]*/g),ct=D(/^data-[\-\w.\u00B7-\uFFFF]+$/),lt=D(/^aria-[\-\w]+$/),ut=D(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),dt=D(/^(?:\w+script|data):/i),ft=D(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),pt=D(/^html$/i),mt=D(/^[a-z][.\w]*(-[.\w]+)+$/i),ht=D(/<[/\w!]/g),gt=D(/<[/\w]/g),_t=D(/<\/no(script|embed|frames)/i),vt=D(/\/>/i),F={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},yt=E(M({},[`style`,`script`,`xmp`,`iframe`,`noembed`,`noframes`,`plaintext`,`noscript`])),bt=function(){return typeof window>`u`?null:window},xt=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}},St=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Ct=function(e,t,n,r){return O(e,t)&&Oe(e[t])?M(r.base?N(r.base):{},e[t],r.transform):n},wt=function(e,t,n){let r=O(e,t)?e[t]:void 0;return r&&typeof r==`object`?N(r):n()};function Tt(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:bt(),t=e=>Tt(e);if(t.version=`3.4.17`,t.removed=[],!e||!e.document||e.document.nodeType!==F.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=P(d,`cloneNode`),p=P(d,`remove`),m=P(d,`removeAttributeNode`),h=P(d,`nextSibling`),g=P(d,`childNodes`),_=P(d,`parentNode`),ee=P(d,`shadowRoot`),v=P(d,`attributes`),y=o&&o.prototype?P(o.prototype,`nodeType`):null,b=o&&o.prototype?P(o.prototype,`nodeName`):null,x=o&&o.prototype?P(o.prototype,`ownerDocument`):null,S=function(e){return y?y(e):e.nodeType},te=function(e){return b?b(e):e.nodeName},ne=Ke(d,`namespaceURI`),re=function(e){return ne?ne(e):e.namespaceURI};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let C,w=``,ie,ae=!1,oe=0,se=function(){if(oe>0)throw Ue(`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.`)},ce=function(e){se(),oe++;try{return C.createHTML(e)}finally{oe--}},le=function(e){se(),oe++;try{return C.createScriptURL(e)}finally{oe--}},ue=function(){return ae||=(ie=xt(u,i),!0),ie},de=n,fe=de.implementation,pe=de.createNodeIterator,he=de.createDocumentFragment,ge=de.getElementsByTagName,_e=r.importNode,T=St();t.isSupported=typeof me==`function`&&typeof _==`function`&&fe&&fe.createHTMLDocument!==void 0;let ye=at,be=ot,xe=st,Re=ct,ze=lt,Be=dt,Ve=ft,He=mt,A=ut,j=null,We=M({},[...Je,...Ye,...Xe,...Qe,...et]),I=null,Et=M({},[...tt,...nt,...rt,...it]),L=Object.seal(ve(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}})),Dt=null,Ot=null,R=Object.seal(ve(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),z=!0,kt=!0,B=!1,At=!0,V=!1,jt=!0,H=!1,Mt=!1,Nt=null,Pt=null,Ft=!1,It=!1,Lt=!1,Rt=!1,zt=!0,Bt=!1,Vt=`user-content-`,Ht=!0,Ut=!1,Wt=null,Gt={},Kt=null,qt=M({},/* @__PURE__ */ `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(`.`)),Jt=null,Yt=M({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Xt=null,Zt=M({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Qt=`http://www.w3.org/1998/Math/MathML`,$t=`http://www.w3.org/2000/svg`,U=`http://www.w3.org/1999/xhtml`,en=U,W=!1,tn=null,nn=M({},[Qt,$t,U],Ne),rn=E([`mi`,`mo`,`mn`,`ms`,`mtext`]),an=M({},rn),on=E([`annotation-xml`]),sn=M({},on),cn=M({},[`title`,`style`,`font`,`a`,`script`]),ln=null,un=[`application/xhtml+xml`,`text/html`],G=null,dn=null,fn=n.createElement(`form`),pn=function(e){return e instanceof RegExp||e instanceof Function},mn=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(dn&&dn===e)return;e&&typeof e==`object`||(e={}),e=N(e),ln=un.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,G=ln===`application/xhtml+xml`?Ne:Me,j=Ct(e,`ALLOWED_TAGS`,We,{transform:G}),I=Ct(e,`ALLOWED_ATTR`,Et,{transform:G}),tn=Ct(e,`ALLOWED_NAMESPACES`,nn,{transform:Ne}),Xt=Ct(e,`ADD_URI_SAFE_ATTR`,Zt,{transform:G,base:Zt}),Jt=Ct(e,`ADD_DATA_URI_TAGS`,Yt,{transform:G,base:Yt}),Kt=Ct(e,`FORBID_CONTENTS`,qt,{transform:G}),Dt=Ct(e,`FORBID_TAGS`,N({}),{transform:G}),Ot=Ct(e,`FORBID_ATTR`,N({}),{transform:G}),Gt=O(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?N(e.USE_PROFILES):e.USE_PROFILES:!1,z=e.ALLOW_ARIA_ATTR!==!1,kt=e.ALLOW_DATA_ATTR!==!1,B=e.ALLOW_UNKNOWN_PROTOCOLS||!1,At=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,V=e.SAFE_FOR_TEMPLATES||!1,jt=e.SAFE_FOR_XML!==!1,H=e.WHOLE_DOCUMENT||!1,It=e.RETURN_DOM||!1,Lt=e.RETURN_DOM_FRAGMENT||!1,Rt=e.RETURN_TRUSTED_TYPE||!1,Ft=e.FORCE_BODY||!1,zt=e.SANITIZE_DOM!==!1,Bt=e.SANITIZE_NAMED_PROPS||!1,Ht=e.KEEP_CONTENT!==!1,Ut=e.IN_PLACE||!1,A=qe(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:ut,en=typeof e.NAMESPACE==`string`?e.NAMESPACE:U,an=wt(e,`MATHML_TEXT_INTEGRATION_POINTS`,()=>M({},rn)),sn=wt(e,`HTML_INTEGRATION_POINTS`,()=>M({},on));let t=wt(e,`CUSTOM_ELEMENT_HANDLING`,()=>ve(null));if(L=ve(null),O(t,`tagNameCheck`)&&pn(t.tagNameCheck)&&(L.tagNameCheck=t.tagNameCheck),O(t,`attributeNameCheck`)&&pn(t.attributeNameCheck)&&(L.attributeNameCheck=t.attributeNameCheck),O(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(L.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),D(L),V&&(kt=!1),Lt&&(It=!0),Gt&&(j=M({},et),I=ve(null),Gt.html===!0&&(M(j,Je),M(I,tt)),Gt.svg===!0&&(M(j,Ye),M(I,nt),M(I,it)),Gt.svgFilters===!0&&(M(j,Xe),M(I,nt),M(I,it)),Gt.mathMl===!0&&(M(j,Qe),M(I,rt),M(I,it))),R.tagCheck=null,R.attributeCheck=null,O(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?R.tagCheck=e.ADD_TAGS:Oe(e.ADD_TAGS)&&(j===We&&(j=N(j)),M(j,e.ADD_TAGS,G))),O(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?R.attributeCheck=e.ADD_ATTR:Oe(e.ADD_ATTR)&&(I===Et&&(I=N(I)),M(I,e.ADD_ATTR,G))),O(e,`ADD_FORBID_CONTENTS`)&&Oe(e.ADD_FORBID_CONTENTS)&&(Kt===qt&&(Kt=N(Kt)),M(Kt,e.ADD_FORBID_CONTENTS,G)),Ht&&(j[`#text`]=!0),H&&M(j,[`html`,`head`,`body`]),j.table&&(M(j,[`tbody`]),delete Dt.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw Ue(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw Ue(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=C;C=e.TRUSTED_TYPES_POLICY;try{w=ce(``)}catch(e){throw C=t,e}}else e.TRUSTED_TYPES_POLICY===null?(C=void 0,w=``):(C===void 0&&(C=ue()),C&&typeof w==`string`&&(w=ce(``)));E&&E(e),dn=e},hn=M({},[...Ye,...Xe,...Ze]),gn=M({},[...Qe,...$e]),_n=function(e,t,n){return t.namespaceURI===U?e===`svg`:t.namespaceURI===Qt?e===`svg`&&(n===`annotation-xml`||an[n]):!!hn[e]},vn=function(e,t,n){return t.namespaceURI===U?e===`math`:t.namespaceURI===$t?e===`math`&&sn[n]:!!gn[e]},yn=function(e,t,n){return t.namespaceURI===$t&&!sn[n]||t.namespaceURI===Qt&&!an[n]?!1:!gn[e]&&(cn[e]||!hn[e])},bn=function(e){let t=re(e),n=Me(te(e)),r=_(e),i,a;return r&&S(r)===F.element?(i={namespaceURI:re(r)},a=Me(te(r))):(i={namespaceURI:en},a=`template`),tn[t]?t===$t?_n(n,i,a):t===Qt?vn(n,i,a):t===U?yn(n,i,a):!!(ln===`application/xhtml+xml`&&tn[t]):!1},xn=function(e){Te(t.removed,{element:e});try{_(e).removeChild(e)}catch{if(p(e),!_(e))throw Ue(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},Sn=function(e,t,n){try{m(e,t)}catch{try{e.removeAttribute(n)}catch{}}},Cn=function(e){Dn(e);let t=g(e);t&&Se(Ee(t),e=>{try{p(e)}catch{}});let n=S(e)===F.element?v(e):null;if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;typeof i==`string`&&Sn(e,r,i)}},wn=function(e,n,r){if(!r)try{r=n.getAttributeNode(e)}catch{r=null}Te(t.removed,{attribute:r||null,from:n});try{r?m(n,r):n.removeAttribute(e)}catch{try{n.removeAttribute(e)}catch{}}if(e===`is`){if(It||Lt)try{xn(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},Tn=function(e){let t=v(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;typeof i!=`string`||I[G(i)]||Sn(e,r,i)}},En=function(e,t){let n=arguments.length>2&&arguments[2]!==void 0&&arguments[2],r=[e];for(;r.length>0;){let e=r.pop();if(t(e)===!1)continue;if(n&&S(e)===F.element){let t=ee(e);K(t)&&r.push(t)}let i=g(e);if(i)for(let e=i.length-1;e>=0;--e)r.push(i[e])}},Dn=function(e){En(e,e=>{S(e)===F.element&&Tn(e)})},On=function(e){let t=[];return En(e,e=>{t.push(e)},!0),t},kn=function(e,t){let n=ke();Se(On(e),e=>{S(e)===F.element&&Ae(n,e)}),Se(t,e=>{S(e)===F.element&&!je(n,e)&&Tn(e)})},An=function(e,n){let r=!1;return Se(t.removed,t=>{t.element&&(r||=t.element===e,Dn(t.element))}),kn(e,n),r},jn=function(e,t){let n=Wt,r=null,i=()=>(r||(r=ke(),Se(t,e=>{Ae(r,e)})),r);for(let t=0;;t++){let r=On(e),a=[e],o=!1;if(Se(r,e=>{S(e)===F.documentFragment?Te(a,e):!o&&!je(n,e)&&(o=je(i(),e))}),!o)return;if(t>=8)throw Ue(`the tree kept changing during in-place sanitization; refusing to return it`);Se(a,(t,n)=>{Mn(t,n>0,e,i())})}},Mn=function(e,t,n,r){let i=Ln(e),a;for(;a=i.nextNode();)je(r,a)&&!je(Wt,a)&&(t&&q(T.uponSanitizeShadowNode,a,null),qn(a,n),er(a,n),K(a.content)&&tr(a.content))},Nn=function(e){Wt&&Ae(Wt,e)},Pn=function(e,t){return jt?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},Fn=function(e){jt&&En(e,e=>{let t=S(e);if(t===F.processingInstruction||t===F.comment&&k(gt,e.data)){try{p(e)}catch{}return!1}if(t===F.element){let t=e,n=G(te(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&Pn(`for`,n)&&t.removeAttribute(`for`)}catch{}}return!0})},In=function(e){let t=null,r=null;if(Ft)e=`<remove></remove>`+e;else{let t=Pe(e,/^[\r\n\t ]+/);r=t&&t[0]}ln===`application/xhtml+xml`&&en===U&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=C?ce(e):e;if(en===U)try{t=new l().parseFromString(i,ln)}catch{}if(!t||!t.documentElement){t=fe.createDocument(en,`template`,null);try{t.documentElement.innerHTML=W?w:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),en===U?ge.call(t,H?`html`:`body`)[0]:H?t.documentElement:a},Ln=function(e){let t=x?x(e):e.ownerDocument;return pe.call(t||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},Rn=function(e){return e=Fe(e,ye,` `),e=Fe(e,be,` `),e=Fe(e,xe,` `),e},zn=function(e){Bn(e);let t=e.querySelectorAll?.call(e,`template`);t&&Se(t,e=>{K(e.content)&&zn(e.content)})},Bn=function(e){e.normalize();let t=x?x(e):e.ownerDocument,n=pe.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=Rn(r.data),r=n.nextNode()},Vn=function(e){let t=b?b(e):null;return typeof t!=`string`||G(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==v(e)||typeof e.removeAttribute!=`function`||typeof e.removeAttributeNode!=`function`||typeof e.getAttributeNode!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==y(e)||e.childNodes!==g(e)},K=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return y(e)===F.documentFragment}catch{return!1}},Hn=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return typeof y(e)==`number`}catch{return!1}};function q(e,n,r){e.length!==0&&Se(e,e=>{e.call(t,n,r,dn)})}let Un=function(e,t){return!!(jt&&e.hasChildNodes()&&!Hn(e.firstElementChild)&&k(ht,e.textContent)&&k(ht,e.innerHTML)||jt&&yt[t]&&S(e)===F.element&&re(e)===U&&(Hn(e.firstElementChild)||typeof e.textContent==`string`&&k(ht,e.textContent))||e.nodeType===F.processingInstruction||jt&&e.nodeType===F.comment&&k(gt,e.data))},Wn=function(e,t){return e instanceof RegExp?k(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},Gn=function(e,t,n){if(!Dt[t]&&Xn(t)&&Wn(L.tagNameCheck,t))return!1;if(Ht&&!Kt[t]&&!Kt[Me(t)]){let t=_(e),r=g(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,h(e))}}}return xn(e),!0},J=function(e,t,n,r){return e.length===0?t:t===n||t===r?N(t):t},Kn=function(e,t){return e===t||_(e)!==null?!1:(Ut&&Dn(e),!0)},qn=function(e,n){if(Nn(e),q(T.beforeSanitizeElements,e,null),Kn(e,n))return!0;if(Vn(e))return xn(e),!0;let r=G(te(e));if(j=J(T.uponSanitizeElement,j,We,Nt),q(T.uponSanitizeElement,e,{tagName:r,allowedTags:j}),Kn(e,n))return!0;if(Un(e,r))return xn(e),!0;if(Dt[r]||!(R.tagCheck instanceof Function&&R.tagCheck(r))&&!j[r]){let t=Gn(e,r,n);return t===!1&&(q(T.afterSanitizeElements,e,null),Kn(e,n))?!0:t}if(S(e)===F.element&&!bn(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&k(_t,e.innerHTML))return xn(e),!0;if(V&&e.nodeType===F.text){let n=Rn(e.textContent);e.textContent!==n&&(Te(t.removed,{element:e.cloneNode()}),e.textContent=n)}return q(T.afterSanitizeElements,e,null),Kn(e,n)},Jn=function(e,t,r){if(Ot[t]||Pn(t,e)||zt&&(t===`id`||t===`name`)&&(r in n||r in fn))return!1;let i=I[t]||R.attributeCheck instanceof Function&&R.attributeCheck(t,e);return kt&&k(Re,t)||z&&k(ze,t)?!0:i?Xt[t]||k(A,Fe(r,Ve,``))||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&Ie(r,`data:`)===0&&Jt[e]||B&&!k(Be,Fe(r,Ve,``))?!0:!r:Xn(e)&&Wn(L.tagNameCheck,e)&&Wn(L.attributeNameCheck,t,e)||t===`is`&&L.allowCustomizedBuiltInElements&&Wn(L.tagNameCheck,r)},Yn=M({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Xn=function(e){return!Yn[Me(e)]&&k(He,e)},Zn=function(e,t,n,r){if(C&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return ce(r);case`TrustedScriptURL`:return le(r)}return r},Qn=function(e,t,n,r){try{return n?e.setAttributeNS(n,t,r):e.setAttribute(t,r),!Vn(e)||(xn(e),!1)}catch{return wn(t,e),!1}},$n=function(e,t){return jt&&k(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,t)?!0:Me(e)===`attributename`&&Pe(t,`href`)!==null},er=function(e,n){if(q(T.beforeSanitizeAttributes,e,null),Kn(e,n))return;let r=e.attributes;if(!r||Vn(e))return;I=J(T.uponSanitizeAttribute,I,Et,Pt);let i={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:I,forceKeepAttr:void 0},a=r.length,o=G(e.nodeName);for(;a--;){let n=r[a],s=n.name,c=n.namespaceURI,l=n.value,u=G(s),d=l,f=s===`value`?d:Le(d),p=!1;i.attrName=u,i.attrValue=f,i.keepAttr=!0,i.forceKeepAttr=void 0,q(T.uponSanitizeAttribute,e,i),f=i.attrValue,Bt&&(u===`id`||u===`name`)&&Ie(f,Vt)!==0&&(wn(s,e,n),f=Vt+f,p=!0),$n(s,f)?wn(s,e,n):i.forceKeepAttr||(i.keepAttr?!At&&k(vt,f)?wn(s,e,n):(V&&(f=Rn(f)),Jn(o,u,f)?(f=Zn(o,u,c,f),f!==d&&Qn(e,s,c,f)&&p&&we(t.removed)):wn(s,e,n)):wn(s,e,n))}q(T.afterSanitizeAttributes,e,null),Kn(e,n)},tr=function(e){let t=null,n=Ln(e);for(q(T.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(q(T.uponSanitizeShadowNode,t,null),qn(t,e),er(t,e),K(t.content)&&tr(t.content),S(t)===F.element){let e=ee(t);K(e)&&(nr(e),tr(e))}V&&Bn(e),q(T.afterSanitizeShadowDOM,e,null)},nr=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){tr(e.shadow);continue}let n=e.node,r=S(n)===F.element,i=g(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=b?b(n):null;if(typeof e==`string`&&G(e)===`template`){let e=n.content;K(e)&&t.push({node:e,shadow:null})}}if(r){let e=ee(n);K(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(W=!e,W&&(e=`<!-->`),typeof e!=`string`&&!Hn(e)&&(e=Ge(e),typeof e!=`string`))throw Ue(`dirty is not a string, aborting`);if(!t.isSupported)return e;Mt?(j=Nt,I=Pt):mn(n),(T.uponSanitizeElement.length>0||T.uponSanitizeAttribute.length>0)&&(j=N(j)),T.uponSanitizeAttribute.length>0&&(I=N(I)),t.removed=[];let c=Ut&&typeof e!=`string`&&Hn(e),l=[],u=Wt;if(c){Fn(e);let t=te(e);if(typeof t==`string`){let n=G(t);if(!j[n]||Dt[n])throw Cn(e),Ue(`root node is forbidden and cannot be sanitized in-place`)}if(Vn(e))throw Cn(e),Ue(`root node is clobbered and cannot be sanitized in-place`);l=On(e),Wt=ke()}else if(Hn(e))i=In(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===F.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),nr(i);else{if(!It&&!V&&!H&&e.indexOf(`<`)===-1)return C&&Rt?ce(e):e;if(i=In(e),!i)return It?null:Rt?w:``}i&&Ft&&xn(i.firstChild);let d=c?e:i;try{c&&nr(e);let t=Ln(d);for(;o=t.nextNode();)qn(o,d),er(o,d),K(o.content)&&tr(o.content);c&&jn(e,l)}catch(t){throw c&&(Cn(e),An(e,l)),t}finally{Wt=u}if(c){if(An(e,l))throw Ue(`a node selected for removal could not be safely returned; refusing to sanitize in place`);return V&&zn(e),e}if(It){if(V&&zn(i),Lt)for(s=he.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(I.shadowroot||I.shadowrootmode)&&(s=_e.call(r,s,!0)),s}let f=H?i.outerHTML:i.innerHTML;return H&&j[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&k(pt,i.ownerDocument.doctype.name)&&(f=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
6
- `+f),V&&(f=Rn(f)),C&&Rt?ce(f):f},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};mn(e),Mt=!0,Nt=j,Pt=I},t.clearConfig=function(){dn=null,Mt=!1,Nt=null,Pt=null,C=ie,w=``},t.isValidAttribute=function(e,t,n){dn||mn({});let r=G(e),i=G(t);return typeof n==`string`&&($n(t,n)||!At&&k(vt,n))?!1:Jn(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&O(T,e)&&Te(T[e],t)},t.removeHook=function(e,t){if(O(T,e)){if(t!==void 0){let n=Ce(T[e],t);return n===-1?void 0:De(T[e],n,1)[0]}return we(T[e])}},t.removeHooks=function(e){O(T,e)&&(T[e]=[])},t.removeAllHooks=function(){T=St()},t}var I=Tt();function Et(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var L=Et();function Dt(e){L=e}var Ot={exec:()=>null};function R(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 z(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(B.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var kt=((e=``)=>{try{return!!RegExp(`(?<=1)(?<!1)`+e)}catch{return!1}})(),B={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,listInterruptsParagraph:/^ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+)[ \t]*)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,blockquoteMarkerWhitespace:/^( {0,3}>)([ \t]+)/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\][ \t]+\S/,listReplaceTask:/^\[[ xX]\][ \t]+/,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,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/,numericCharacterReferenceOrAmpersand:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,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:R(e=>RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:R(e=>RegExp(`^ {0,${e}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:R(e=>RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:R(e=>RegExp(`^ {0,${e}}#{1,6}(?:\\s|$)`)),pedanticHeadingBeginRegex:R(e=>RegExp(`^ {0,${e}}#`)),htmlBeginRegex:R(e=>RegExp(`^ {0,${e}}(?:</?(?:${Ht})(?: +|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`,`i`)),blockquoteBeginRegex:R(e=>RegExp(`^ {0,${e}}>`)),nestedContainerMarkers:/^(?: {0,3}(?:(?:[*+-]|\d{1,9}[.)])[ \t]+|>[ \t]?))+/},At=/^(?:[ \t]*(?:\n|$))+/,V=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,jt=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}(?:(?=`)\1`*|(?=~)\1~*) *(?=\n|$)|$)/,H=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Mt=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Nt=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Pt=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+)[ \t]*(?:\n+|$)/,Ft=z(Pt).replace(/bull/g,Nt).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(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),It=z(Pt).replace(/bull/g,Nt).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(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Lt=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,Rt=/^[^\n]+/,zt=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\\n]|\n(?![ \t]*\n))+/,Bt=z(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,zt).replace(`title`,/(?:"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\\n]|\n(?!\n))*'|\((?:\\[\s\S]|[^()\\])*\))/).getRegex(),Vt=z(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,Nt).getRegex(),Ht=`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`,Ut=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Wt=z(`^ {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)(?:[ \\t]+|\\n|/?>|$)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!(?:script|pre|style|textarea)(?![a-z0-9-]))([a-z][a-z0-9-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,Ut).replace(`tag`,Ht).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Gt=e=>z(Lt).replace(`hr`,H).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`,` {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`).replace(`tag`,Ht).getRegex(),Kt=Gt(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),qt=Gt(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),Jt={blockquote:z(/^( {0,3}> ?(?:(?![ \t]*(?:\n|$))(paragraph)|[^\n]*)(?:\n|$))+/).replace(`paragraph`,qt).getRegex(),code:V,def:Bt,fences:jt,heading:Mt,hr:H,html:Wt,lheading:Ft,list:Vt,newline:At,paragraph:Kt,table:Ot,text:Rt},Yt=z(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,H).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`,` {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`).replace(`tag`,Ht).getRegex(),Xt={...Jt,lheading:It,table:Yt,paragraph:z(Lt).replace(`hr`,H).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,Yt).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]`).replace(`html`,` {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`).replace(`tag`,Ht).getRegex()},Zt={...Jt,html:z(`^ *(?:comment(?: *\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1>(?: *\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?>(?: *\\n{2,}|\\s*$))`).replace(`comment`,Ut).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:Ot,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:z(Lt).replace(`hr`,H).replace(`heading`,` *#{1,6} *[^
7
- ]`).replace(`lheading`,Ft).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},Qt=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,$t=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,U=/^( {2,}|\\)\n(?!\s*$)[ \t]*/,en=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,W=/[\p{P}\p{S}]/u,tn=/[\s\p{P}\p{S}]/u,nn=/[^\s\p{P}\p{S}]/u,rn=z(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,tn).getRegex(),an=/[\p{Pi}\p{Ps}"']/u,on=/(?!~)[\p{P}\p{S}]/u,sn=/(?!~)[\s\p{P}\p{S}]/u,cn=/(?:[^\s\p{P}\p{S}]|~)/u,ln=z(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,kt?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),un=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,G=z(un,`u`).replace(/punct/g,W).getRegex(),dn=z(un,`u`).replace(/punct/g,on).getRegex(),fn=z(/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,`u`).replace(/openQuote/g,an).replace(/punct/g,W).getRegex(),pn=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,mn=z(pn,`gu`).replace(/notPunctSpace/g,nn).replace(/punctSpace/g,tn).replace(/punct/g,W).getRegex(),hn=z(pn,`gu`).replace(/notPunctSpace/g,cn).replace(/punctSpace/g,sn).replace(/punct/g,on).getRegex(),gn=z(`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,nn).replace(/punctSpace/g,tn).replace(/punct/g,W).getRegex(),_n=z(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,nn).replace(/punctSpace/g,tn).replace(/punct/g,W).getRegex(),vn=z(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,nn).replace(/punctSpace/g,tn).replace(/punct/g,W).getRegex(),yn=z(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,W).getRegex(),bn=z(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,nn).replace(/punctSpace/g,tn).replace(/punct/g,W).getRegex(),xn=z(/\\(punct)/,`gu`).replace(/punct/g,W).getRegex(),Sn=z(/(`+)(?:[^`]|[^`][\s\S]*?[^`])\1(?!`)|`+|\\(punct)/,`gu`).replace(/punct/g,W).getRegex(),Cn=z(/^<(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(),wn=z(Ut).replace(`(?:-->|$)`,`-->`).getRegex(),Tn=z(`^comment|^</[a-zA-Z][a-zA-Z0-9-]*\\s*>|^<[a-zA-Z][a-zA-Z0-9-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,wn).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),En=/\[(?:\\[\s\S]|[^\[\]\\])*\]/,Dn=z(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace(`brackets`,En).getRegex(),On=z(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/).replace(`label`,Dn).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace(`title`,/"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|\((?:\\[\s\S]|[^)\\])*\)/).getRegex(),kn=z(/^!?\[(label)\]\[(ref)\]/).replace(`label`,Dn).replace(`ref`,zt).getRegex(),An=z(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,zt).getRegex(),jn=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/,Mn=z(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace(`brackets`,En).getRegex(),Nn=z(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,z(/^!?\[(label)\]\[(ref)\]/).replace(`label`,Mn).replace(`ref`,jn).getRegex()).replace(`nolink`,z(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,jn).getRegex()).getRegex(),Pn=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,Fn=z(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g,/[A-Za-z0-9._+-]+@[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),In={_backpedal:Ot,anyPunctuation:xn,anyPunctuationOutsideCode:Sn,autolink:Cn,blockSkip:ln,br:U,code:$t,del:Ot,delLDelim:Ot,delRDelim:Ot,emStrongLDelim:G,emStrongRDelimAst:mn,emStrongRDelimUnd:_n,escape:Qt,link:On,nolink:An,punctuation:rn,reflink:kn,reflinkSearch:Nn,tag:Tn,text:en,url:Ot},Ln={...In,emStrongLDelim:fn,emStrongRDelimAst:gn,emStrongRDelimUnd:vn,link:z(/^!?\[(label)\]\((.*?)\)/).replace(`label`,Dn).getRegex(),reflink:z(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,Dn).getRegex()},Rn={...In,emStrongRDelimAst:hn,emStrongLDelim:dn,delLDelim:yn,delRDelim:bn,url:z(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`emailProtocol`,Fn).replace(`protocol`,Pn).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:z(/^(?:[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|wwwStart|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/).replace(`protocol`,Pn).replace(/emailProtocol/g,/(?:mailto|xmpp):/).replace(`wwwStart`,kt?`(?<![^\\s*_~(])www\\.`:`www\\.`).getRegex()},zn={...Rn,br:z(U).replace(`{2,}`,`*`).getRegex(),text:z(Rn.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},Bn={normal:Jt,gfm:Xt,pedantic:Zt},Vn={normal:In,gfm:Rn,breaks:zn,pedantic:Ln},K={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`},Hn=e=>K[e];function q(e,t){if(t){if(B.escapeTest.test(e))return e.replace(B.escapeReplace,Hn)}else if(B.escapeTestNoEncode.test(e))return e.replace(B.escapeReplaceNoEncode,Hn);return e}function Un(e){return B.numericCharacterReference.test(e)?e.replace(B.numericCharacterReferenceOrAmpersand,(e,t,n)=>{if(t===void 0&&n===void 0)return`&amp;`;let r=t===void 0?Number.parseInt(n,16):Number.parseInt(t,10);return r===0||r>1114111||r>=55296&&r<=57343?`�`:r===38?`&amp;`:String.fromCodePoint(r)}):e}function Wn(e){try{e=encodeURI(e).replace(B.percentDecode,`%`)}catch{return null}return e}function Gn(e,t){let n=e.replace(B.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(B.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(B.slashPipe,`|`);return n}function J(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 Kn(e){let t=e.split(`
8
- `),n=t.length-1;for(;n>=0&&B.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
9
- `)}function qn(e){return e.trim().replace(B.multipleSpaceGlobal,` `).toLowerCase().toUpperCase().toLowerCase()}function Jn(e,t){if(e.indexOf(t[0])===-1&&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}var Yn=/* @__PURE__ */ new WeakMap;function Xn(e){let t={"*":-1,_:-1},n=-1,r=e.length;for(let i=0;i<r;i++){let a=e[i];if(a!==`*`&&a!==`_`&&a!==`~`)continue;let o=i===0?`
3
+ `)};return this.#r!==void 0&&(e.id=this.#r),this.#s(),e}#s(){this.#t=``,this.#n=[],this.#r=void 0}};async function*u(e){let t=e.getReader(),n=new TextDecoder,r=new l;try{for(;;){let{done:e,value:i}=await t.read(),a=e?n.decode():n.decode(i,{stream:!0});if(yield*r.push(a),e)break}r.end()}finally{await t.cancel().catch(()=>t.releaseLock())}}function d(e){try{return e.data?JSON.parse(e.data):{}}catch{return{raw:e.data}}}var f=3e4;function p(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=t+`=`.repeat((4-t.length%4)%4),r=atob(n),i=Uint8Array.from(r,e=>e.charCodeAt(0));return new TextDecoder().decode(i)}function m(t){let n=t.split(`.`)[1];if(!n)return null;try{let t=JSON.parse(p(n));return e(t)?t:null}catch{return null}}function h(e){let t=m(e)?.exp;return typeof t==`number`?t*1e3:null}var ee=class{#e;#t;#n=null;#r=0;#i=null;#a=!1;#o=0;constructor(e,t=Date.now){this.#e=e,this.#t=t}get(){return this.#n&&this.#t()<this.#r-3e4?Promise.resolve(this.#n):this.#s(!1)}refresh(){return this.#n=null,this.#r=0,this.#s(!0)}clear(){this.#n=null,this.#r=0,this.#i=null,this.#a=!1,this.#o++}#s(e){if(this.#i&&(this.#a||!e))return this.#i;let n=++this.#o,r=Promise.resolve().then(()=>this.#e({retry:e})).then(e=>{if(!e)throw new t({status:401,message:`No token available for the user`},`auth_required`);return n===this.#o&&(this.#n=e,this.#r=h(e)??0),e}).finally(()=>{this.#i===r&&(this.#i=null,this.#a=!1)});return this.#i=r,this.#a=e,r}},g={text:``,result:null,sources:[],activity:null,title:null,error:null,finished:!1},_=t=>e(t)?t:{};function te(e,t,n){let r=_(n),i=e=>{let t=r[e];return typeof t==`string`&&t?t:void 0};switch(t){case`token`:return typeof r.text==`string`?{...e,text:e.text+r.text}:e;case`truncate`:return{...e,text:``};case`result`:return{...e,result:r.payload??null};case`context`:return{...e,sources:Array.isArray(r.context)?r.context:[]};case`title`:return{...e,title:i(`title`)??e.title};case`nop`:return i(`message`)?{...e,activity:i(`message`)}:e;case`error`:{let t=i(`error_code`),n=i(`detail`),a=i(`trace_id`);return{...e,error:{code:typeof r.code==`number`?r.code:500,...i(`message`)?{message:i(`message`)}:{},...t?{errorCode:t}:{},...n?{detail:n}:{},...a?{traceId:a}:{}}}}case`done`:return{...e,finished:!0,activity:null};default:return e}}function ne({text:e,result:t}){return e||t==null?e:typeof t==`object`&&!Array.isArray(t)&&Object.keys(t).length===1&&`text`in t&&typeof t.text==`string`?t.text:"```json\n"+JSON.stringify(t,null,2)+"\n```"}function v({message:e,detail:t,traceId:n},r={}){let{failed:i=`The agent could not answer.`,trace:a=e=>`Trace ${e}`}=r,o=[e??i];return t&&o.push(t),n&&!e?.includes(n)&&o.push(a(n)),o.join(`
4
+ `)}var y={conversation:`aicore-conversation`,turn:`aicore-turn`,error:`aicore-error`,authRequired:`aicore-auth-required`,tenantRefused:`aicore-tenant-refused`},re=3,b=1e3,x=`100`;function ie(e){let t=e.trim().replace(/\/+$/,``);return t.endsWith(`/api/v1`)?t:`${t}/api/v1`}function ae(){if(typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));e[6]=(e[6]??0)&15|64,e[8]=(e[8]??0)&63|128;let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}var oe=e=>e instanceof t&&(e.status===0||e.status>=502);function S(e,t){return new Promise(n=>{if(t?.aborted)return n();let r=setTimeout(n,e);t?.addEventListener(`abort`,()=>{clearTimeout(r),n()},{once:!0})})}var C=class extends EventTarget{apiBase;tenant;#e;#t;#n;#r;#i;#a=null;constructor(e){super(),this.apiBase=ie(e.baseUrl),this.tenant=e.tenant??null,this.#e=new ee(e.getToken),this.#t=e.fetch??globalThis.fetch.bind(globalThis),this.#n=e.onRequest,this.#r=e.onIdentityChange}clearToken(){this.#e.clear()}async checkIdentity(){try{await this.#l(!1)}catch{}}#o(e,t,n){let r=new Headers({Accept:t.accept??`application/json`,Authorization:`Bearer ${e}`});return this.tenant&&r.set(`X-Tenant`,this.tenant),t.body!==void 0&&r.set(`Content-Type`,`application/json`),n&&r.set(`Idempotency-Key`,n),t.lastEventId&&r.set(`Last-Event-ID`,t.lastEventId),{method:t.method??`GET`,headers:r,body:t.form??(t.body===void 0?void 0:JSON.stringify(t.body)),credentials:`omit`,cache:`no-store`,signal:t.signal}}async#s(e,n,r){let i=performance.now(),o;try{o=await this.#t(this.apiBase+e,n)}catch(o){throw a(o,n.signal??void 0)?o:(this.#c(n,e,0,i,r),new t({status:0,message:`AI-CORE unreachable`}))}return this.#c(n,e,o.status,i,r,o),o}#c(e,t,n,r,i,a){this.#n?.({method:e.method??`GET`,path:t,status:n,requestId:a?.headers.get(`X-Request-Id`)??void 0,durationMs:Math.round(performance.now()-r),retriedWithFreshToken:i})}async#l(e){let n;try{n=await(e?this.#e.refresh():this.#e.get())}catch(e){throw e instanceof t?e:new t({status:0,message:`No token available: ${e instanceof Error?e.message:String(e)}`},`auth_required`)}let r=m(n)?.sub,i=typeof r==`string`&&r!==``?r:null,a=this.#i!==void 0&&(i===null||this.#i===null?n!==this.#a:i!==this.#i);return this.#i=i,this.#a=n,a&&this.#r?.(),n}async#u(e,t={}){let n=t.idempotent?ae():void 0;try{let r=await this.#l(!1),i=await this.#s(e,this.#o(r,t,n),!1);if(s(i)&&(r=await this.#l(!0),i=await this.#s(e,this.#o(r,t,n),!0)),!i.ok)throw await c(i);return i}catch(e){if(a(e,t.signal))throw e;let n=i(e);throw t.report!==!1&&this.#f(n),n}}async#d(e,t){return await(await this.#u(e,t)).json()}#f(e){this.dispatchEvent(new CustomEvent(y.error,{detail:e})),e.kind===`auth_required`&&this.dispatchEvent(new CustomEvent(y.authRequired,{detail:e})),e.kind===`tenant_refused`&&this.dispatchEvent(new CustomEvent(y.tenantRefused,{detail:e}))}listAgents(e){let t=new URLSearchParams({limit:x});return e&&t.set(`cursor`,e),this.#d(`/agents?${t.toString()}`)}getAgent(e){return this.#d(`/agents/${encodeURIComponent(e)}`)}listConversations(e,t){let n=new URLSearchParams({id_agent:e,limit:`50`});return t&&n.set(`cursor`,t),this.#d(`/conversations?${n.toString()}`)}async openConversation(e){let t=await this.#d(`/agents/${encodeURIComponent(e)}/conversations`,{method:`POST`,idempotent:!0});return this.dispatchEvent(new CustomEvent(y.conversation,{detail:{idConv:t.id_conv,idAgent:e}})),t}async history(e){let t=[],n=null;do{let r=new URLSearchParams({limit:x});n&&r.set(`cursor`,n);let i=await this.#d(`/conversations/${encodeURIComponent(e)}/messages?${r.toString()}`);t.push(...i.items),n=i.next_cursor}while(n);return t}renameConversation(e,t){return this.#d(`/conversations/${encodeURIComponent(e)}`,{method:`PATCH`,body:{title:t}})}async deleteConversation(e){await this.#u(`/conversations/${encodeURIComponent(e)}`,{method:`DELETE`})}sendMessage(e,t){return this.#d(`/conversations/${encodeURIComponent(e)}/messages`,{method:`POST`,body:t,idempotent:!0})}uploadFile(e,t){let n=new FormData;return n.append(`file`,t,t.name),this.#d(`/conversations/${encodeURIComponent(e)}/files`,{method:`POST`,form:n})}listFiles(e){return this.#d(`/conversations/${encodeURIComponent(e)}/files`)}async deleteFile(e,t){await this.#u(`/conversations/${encodeURIComponent(e)}/files/${encodeURIComponent(t)}`,{method:`DELETE`})}async sendFeedback(e,t,n,r){await this.#u(`/conversations/${encodeURIComponent(e)}/messages/${encodeURIComponent(t)}/feedback`,{method:`PUT`,body:r?{rating:n,text:r}:{rating:n}})}async*streamTurn(e,n,r){let i=`/conversations/${encodeURIComponent(e)}/stream?id_query=${encodeURIComponent(n)}`,o,s=0;for(let e=!1;;e=!0){let n=o,c=null;try{c=await this.#u(i,{signal:r,accept:`text/event-stream`,lastEventId:o,report:!1})}catch(t){if(a(t,r))return;if(!e||!oe(t))throw t}if(c?.body)try{for await(let e of u(c.body))if(e.id!==void 0&&(o=e.id),yield{kind:e.event,data:d(e),id:e.id},e.event===`done`)return}catch(e){if(a(e,r))return}if(o!==n&&(s=0),++s>re)throw new t({status:0,message:`Connection lost while streaming`});if(await S(b*2**(s-1),r),r?.aborted)return}}async ask(e){let n=e.idConv??(await this.openConversation(e.idAgent)).id_conv;e.onConversation?.(n);let{id_query:r}=await this.sendMessage(n,e.request),i=g,a=!1;try{for await(let t of this.streamTurn(n,r,e.signal))i=te(i,t.kind,t.data),e.onUpdate?.(i,t)}catch(e){if(e instanceof t&&e.status===410)a=!0;else throw e instanceof t&&this.#f(e),e}return(a||i.error?.code===410)&&(i=await this.#p(n,r)),this.dispatchEvent(new CustomEvent(y.turn,{detail:{idConv:n,idQuery:r,turn:i}})),{idConv:n,idQuery:r,turn:i}}async#p(e,t){let n=(await this.history(e)).find(e=>e.role===`assistant`&&e.id_query===t);return{...g,text:n?.content??``,sources:n?.sources??[],finished:!0}}};function se(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var ce=se();function le(e){ce=e}var w={exec:()=>null};function T(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 E(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(D.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var ue=((e=``)=>{try{return!!RegExp(`(?<=1)(?<!1)`+e)}catch{return!1}})(),de=`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)`,D={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,listInterruptsParagraph:/^ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,textIndentedContinuation:/^(?:\n(?: {4}| {0,3}\t)[ \t]*[^ \t\n][^\n]*)+/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+)[ \t]*)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,blockquoteMarkerWhitespace:/^( {0,3}>)(\t[ \t]*)/gm,blockquoteFenceOpen:/^ {0,3}(`{3,}(?=[^`]*$)|~{3,})/,blockquoteFenceClose:/^ {0,3}(`{3,}|~{3,})[ \t]*$/,blockquoteListItemStart:/^ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|$)/,nestedBlockMarker:/^ {0,3}(?:(?:[*+-]|\d{1,9}[.)])(?: |$)|> ?)/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\][ \t]+\S/,listReplaceTask:/^\[[ xX]\][ \t]+/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableHeader:RegExp(de+`(?:\\n|$)`),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,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/,numericCharacterReferenceOrAmpersand:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,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:T(e=>RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:T(e=>RegExp(`^ {0,${e}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:T(e=>RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:T(e=>RegExp(`^ {0,${e}}#{1,6}(?:\\s|$)`)),pedanticHeadingBeginRegex:T(e=>RegExp(`^ {0,${e}}#`)),htmlBeginRegex:T(e=>RegExp(`^ {0,${e}}(?:</?(?:${_e})(?:[ \\t]+|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`,`i`)),blockquoteBeginRegex:T(e=>RegExp(`^ {0,${e}}>`)),nestedContainerMarkers:/^(?: {0,3}(?:(?:[*+-]|\d{1,9}[.)])[ \t]+|>[ \t]?))+/},fe=/^(?:[ \t]*(?:\n|$))+/,pe=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,me=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}(?:(?=`)\1`*|(?=~)\1~*)[ \t]*(?=\n|$)|$)/,he=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,ge=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,O=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,_e=`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`,ve=E(` {0,3}(?:</?(?:tag)(?:[ \\t]+|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`).replace(`tag`,_e).getRegex(),ye=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+)[ \t]*(?:\n+|$)/,be=E(ye).replace(/bull/g,O).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(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/\|table/g,``).replace(/html/g,ve).getRegex(),xe=E(ye).replace(/bull/g,O).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(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).replace(/html/g,ve).getRegex(),Se=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,Ce=/^[^\n]+/,we=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\\n]|\n(?![ \t]*\n))+/,Te=E(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<(?:\\.|[^\n<>\\])*>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,we).replace(`title`,/(?:"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\\n]|\n(?!\n))*'|\((?:\\[\s\S]|[^()\\])*\))/).getRegex(),k=E(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,O).getRegex(),Ee=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,A=E(`^ {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)(?:[ \\t]+|\\n|/?>|$)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!(?:script|pre|style|textarea)(?![a-z0-9-]))([a-z][a-z0-9-]*)(?:attribute)*?[ \\t]*/?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,Ee).replace(`tag`,_e).replace(`attribute`,/[ \t]+[a-zA-Z:_][\w.:-]*(?:[ \t]*=[ \t]*"[^"\n]*"|[ \t]*=[ \t]*'[^'\n]*'|[ \t]*=[ \t]*[^\s"'=<>`]+)?/).getRegex(),De=e=>E(Se).replace(`hr`,he).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`,ve).getRegex(),j=De(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),Oe=De(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),ke=/ {0,3}> ?(?:(?!blank)(paragraph)|[^\n]*)(?:\n|$)/,M={blockquote:E(/^(first)(?:next)*/).replace(`first`,E(ke).replace(`blank`,/[ \t]*(?:\n|$)| {4}/).getRegex()).replace(`next`,E(ke).replace(`blank`,/[ \t]*(?:\n|$)/).getRegex()).replace(/paragraph/g,Oe).getRegex(),code:pe,def:Te,fences:me,heading:ge,hr:he,html:A,lheading:be,list:k,newline:fe,paragraph:j,table:w,text:Ce},Ae=E(de+`(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,he).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`,ve).getRegex(),je={...M,lheading:xe,table:Ae,paragraph:E(Se).replace(`hr`,he).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,D.tableHeader).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]`).replace(`html`,ve).getRegex()},Me={...M,html:E(`^ *(?:comment(?: *\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1>(?: *\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?>(?: *\\n{2,}|\\s*$))`).replace(`comment`,Ee).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:w,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:E(Se).replace(`hr`,he).replace(`heading`,` *#{1,6} *[^
5
+ ]`).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).replace(`lheading`,be).getRegex()},Ne=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,N=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Pe=/^( {2,}|\\)\n(?!\s*$)[ \t]*/,Fe=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,P=/[\p{P}\p{S}]/u,Ie=/[\s\p{P}\p{S}]/u,Le=/[^\s\p{P}\p{S}]/u,Re=E(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,Ie).getRegex(),ze=/[\p{Pi}\p{Ps}"']/u,Be=/(?!~)[\p{P}\p{S}]/u,Ve=/(?!~)[\s\p{P}\p{S}]/u,He=/(?:[^\s\p{P}\p{S}]|~)/u,Ue=E(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,ue?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),We=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Ge=E(We,`u`).replace(/punct/g,P).getRegex(),Ke=E(We,`u`).replace(/punct/g,Be).getRegex(),qe=E(/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,`u`).replace(/openQuote/g,ze).replace(/punct/g,P).getRegex(),Je=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,Ye=E(Je,`gu`).replace(/notPunctSpace/g,Le).replace(/punctSpace/g,Ie).replace(/punct/g,P).getRegex(),Xe=E(Je,`gu`).replace(/notPunctSpace/g,He).replace(/punctSpace/g,Ve).replace(/punct/g,Be).getRegex(),Ze=E(`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,Le).replace(/punctSpace/g,Ie).replace(/punct/g,P).getRegex(),Qe=E(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,Le).replace(/punctSpace/g,Ie).replace(/punct/g,P).getRegex(),$e=E(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,Le).replace(/punctSpace/g,Ie).replace(/punct/g,P).getRegex(),et=E(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,P).getRegex(),tt=E(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,Le).replace(/punctSpace/g,Ie).replace(/punct/g,P).getRegex(),nt=E(/\\(punct)/,`gu`).replace(/punct/g,P).getRegex(),rt=E(/(`+)(?:[^`]|[^`][\s\S]*?[^`])\1(?!`)|`+|\\(punct)/,`gu`).replace(/punct/g,P).getRegex(),F=E(/^<(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(),it=E(Ee).replace(`(?:-->|$)`,`-->`).getRegex(),at=E(`^comment|^</[a-zA-Z][a-zA-Z0-9-]*\\s*>|^<[a-zA-Z][a-zA-Z0-9-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,it).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),ot=/\[(?:\\[\s\S]|[^\[\]\\])*\]/,st=E(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace(`brackets`,ot).getRegex(),ct=/\\[^ \t\n\x00-\x1f]|\\(?=[ \t\n])|[^ \t\n\x00-\x1f\\()]/,lt=E(/\((?:char)*\)/).replace(`char`,ct).getRegex(),ut=E(/\((?:char|p1)*\)/).replace(`char`,ct).replace(`p1`,lt).getRegex(),dt=E(/\((?:char|p2)*\)/).replace(`char`,ct).replace(`p2`,ut).getRegex(),ft=E(/(?!<)(?:char|p3)+/).replace(`char`,ct).replace(`p3`,dt).getRegex(),pt=E(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/).replace(`label`,st).replace(`href`,E(/<(?:\\.|[^\n<>\\])*>|bareHref|(?=\))/).replace(`bareHref`,ft).getRegex()).replace(`title`,/"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|\((?:\\[\s\S]|[^)\\])*\)/).getRegex(),mt=E(/^!?\[(label)\]\[(ref)\]/).replace(`label`,st).replace(`ref`,we).getRegex(),ht=E(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,we).getRegex(),I=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/,gt=E(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace(`brackets`,ot).getRegex(),_t=E(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,E(/^!?\[(label)\]\[(ref)\]/).replace(`label`,gt).replace(`ref`,I).getRegex()).replace(`nolink`,E(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,I).getRegex()).getRegex(),vt=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,yt=E(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g,/[A-Za-z0-9._+-]+@[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),bt={_backpedal:w,anyPunctuation:nt,anyPunctuationOutsideCode:rt,autolink:F,blockSkip:Ue,br:Pe,code:N,del:w,delLDelim:w,delRDelim:w,emStrongLDelim:Ge,emStrongRDelimAst:Ye,emStrongRDelimUnd:Qe,escape:Ne,link:pt,nolink:ht,punctuation:Re,reflink:mt,reflinkSearch:_t,tag:at,text:Fe,url:w},xt={...bt,emStrongLDelim:qe,emStrongRDelimAst:Ze,emStrongRDelimUnd:$e,link:E(/^!?\[(label)\]\((.*?)\)/).replace(`label`,st).getRegex(),reflink:E(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,st).getRegex()},St={...bt,emStrongRDelimAst:Xe,emStrongLDelim:Ke,delLDelim:et,delRDelim:tt,url:E(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`emailProtocol`,yt).replace(`protocol`,vt).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:E(/^(?:[A-Za-z0-9.+-]+(?=@)|[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|wwwStart|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/).replace(`protocol`,vt).replace(/emailProtocol/g,/(?:mailto|xmpp):/).replace(`wwwStart`,ue?`(?<![^\\s*_~(])www\\.`:`www\\.`).getRegex()},Ct={...St,br:E(Pe).replace(`{2,}`,`*`).getRegex(),text:E(St.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},wt={normal:M,gfm:je,pedantic:Me},Tt={normal:bt,gfm:St,breaks:Ct,pedantic:xt},Et={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`},Dt=e=>Et[e];function L(e,t){if(t){if(D.escapeTest.test(e))return e.replace(D.escapeReplace,Dt)}else if(D.escapeTestNoEncode.test(e))return e.replace(D.escapeReplaceNoEncode,Dt);return e}function Ot(e){return D.numericCharacterReference.test(e)?e.replace(D.numericCharacterReferenceOrAmpersand,(e,t,n)=>{if(t===void 0&&n===void 0)return`&amp;`;let r=t===void 0?Number.parseInt(n,16):Number.parseInt(t,10);return r===0||r>1114111||r>=55296&&r<=57343?`�`:r===38?`&amp;`:String.fromCodePoint(r)}):e}function kt(e){try{e=encodeURI(e).replace(D.percentDecode,`%`)}catch{return null}return e}function At(e,t){let n=e.replace(D.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(D.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(D.slashPipe,`|`);return n}function R(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 jt(e){let t=e.split(`
6
+ `),n=t.length-1;for(;n>=0&&D.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
7
+ `)}function Mt(e){return e.trim().replace(D.multipleSpaceGlobal,` `).toLowerCase().toUpperCase().toLowerCase()}function Nt(e,t){if(e.indexOf(t[0])===-1&&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}var Pt=/* @__PURE__ */ new WeakMap;function Ft(e){let t={"*":-1,_:-1},n=-1,r=e.length;for(let i=0;i<r;i++){let a=e[i];if(a!==`*`&&a!==`_`&&a!==`~`)continue;let o=i===0?`
10
8
  `:e[i-1],s=i+1;for(;s<r&&e[s]===a;)s++;o!==` `&&o!==` `&&o!==`
11
- `&&o!==`\r`&&o!==`\f`&&(a===`~`?n=i:t[a]=i),i=s-1}return{maskedSrc:e,lastPossibleEmStrongCloserIndex:t,lastPossibleDelCloserIndex:n}}function Zn(e,t){let n=Xn(t),r=Yn.get(e);r?r.push(n):Yn.set(e,[n])}function Qn(e){let t=Yn.get(e);t&&(t.pop(),t.length===0&&Yn.delete(e))}function $n(e,t,n){let r=Yn.get(e)?.at(-1);return r&&r.maskedSrc===t?r.lastPossibleEmStrongCloserIndex[n]:Xn(t).lastPossibleEmStrongCloserIndex[n]}function er(e,t){let n=Yn.get(e)?.at(-1);return n&&n.maskedSrc===t?n.lastPossibleDelCloserIndex:Xn(t).lastPossibleDelCloserIndex}function tr(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 nr(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`),c=e[0].charAt(0)===`!`,l=r.state.inLink,u=r.state.linkEmitted,d=r.state.inRawBlock;r.state.inLink=!0,r.state.linkEmitted=!1;let f=r.inlineTokens(s),p=r.state.linkEmitted;if(r.state.linkEmitted=u,r.state.inLink=l,!c){if(p){r.state.inRawBlock=d;return}r.state.linkEmitted=!0}return{type:c?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:f}}function rr(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
9
+ `&&o!==`\r`&&o!==`\f`&&(a===`~`?n=i:t[a]=i),i=s-1}return{maskedSrc:e,lastPossibleEmStrongCloserIndex:t,lastPossibleDelCloserIndex:n}}function It(e,t){let n=Ft(t),r=Pt.get(e);r?r.push(n):Pt.set(e,[n])}function Lt(e){let t=Pt.get(e);t&&(t.pop(),t.length===0&&Pt.delete(e))}function Rt(e,t,n){let r=Pt.get(e)?.at(-1);return r&&r.maskedSrc===t?r.lastPossibleEmStrongCloserIndex[n]:Ft(t).lastPossibleEmStrongCloserIndex[n]}function zt(e,t){let n=Pt.get(e)?.at(-1);return n&&n.maskedSrc===t?n.lastPossibleDelCloserIndex:Ft(t).lastPossibleDelCloserIndex}function Bt(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 Vt(e){let t,n=!1;return e.map(e=>{if(n)return e;let{depth:r,expanded:i,keptIndent:a,content:o}=Ht(e,t?.depth??1/0);if(t?.depth!==r&&(t=void 0),t){let e=D.blockquoteFenceClose.exec(o)?.[1];return!e||e[0]!==t.marker[0]||e.length<t.marker.length?a:(t=void 0,i)}if(n=D.blockquoteListItemStart.test(o),n)return e;let s=D.blockquoteFenceOpen.exec(o)?.[1];return s&&(t={marker:s,depth:r}),i}).join(`
10
+ `)}function Ht(e,t){let n=0,r=0,i=0,a=0,o=``;for(;i<t;){let t=n,s=r;for(;e[t]===` `||e[t]===` `;)s+=Ut(e[t],s),t++;if(e[t]!==`>`||s-a>3)break;o+=` `.repeat(s-r)+`>`,i++,n=t+1,r=s+1,a=e[n]===` `||e[n]===` `?r+1:r}if(i===0)return{depth:i,expanded:e,keptIndent:e,content:e};let s=``,c=``;for(;(e[n]===` `||e[n]===` `)&&r<a+4;){let t=Ut(e[n],r);s+=` `.repeat(t),c+=r<a&&t>1?` `.repeat(t):e[n],r+=t,n++}let l=e.slice(n);return{depth:i,expanded:o+s+l,keptIndent:o+c+l,content:` `.repeat(Math.max(0,r-a))+l}}function Ut(e,t){return e===` `?4-t%4:1}function Wt(e,t){let n=``;for(let r=0;r<e.length;r++){if(e[r]==="`"){let i=t.inline.code.exec(e.slice(r));if(i){n+=i[0],r+=i[0].length-1;continue}}e[r]===`\\`&&(e[r+1]===`[`||e[r+1]===`]`)?(n+=e[r+1],r++):n+=e[r]}return n}function Gt(e,t,n,r,i){let a=t.href,o=t.title||null,s=Wt(e[1],i),c=e[0].charAt(0)===`!`,l=r.state.inLink,u=r.state.linkEmitted,d=r.state.inRawBlock;r.state.inLink=!0,r.state.linkEmitted=!1;let f=r.inlineTokens(s),p=r.state.linkEmitted;if(r.state.linkEmitted=u,r.state.inLink=l,!c){if(p){r.state.inRawBlock=d;return}r.state.linkEmitted=!0}return{type:c?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:f}}function Kt(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
12
11
  `).map(e=>{let t=e.match(n.other.beginningSpace);if(t===null)return e;let[r]=t;return e.slice(Math.min(r.length,i.length))}).join(`
13
- `)}function ir(e,t,n,r){if(!t.includes(`<`))return!1;for(let i=0;i<t.length;i++){if(t[i]===`\\`){i++;continue}if(t[i]==="`"){let e=r.inline.code.exec(t.slice(i));if(e){i+=e[0].length-1;continue}}if(t[i]!==`<`)continue;let a=e.slice(n+i),o=r.inline.tag.exec(a)||r.inline.autolink.exec(a);if(o){if(o[0].length>t.length-i)return!0;i+=o[0].length-1}}return!1}var ar=class{options;rules;lexer;constructor(e){this.options=e||L}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]:Kn(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=rr(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=J(e,`#`);(this.options.pedantic||!t||this.rules.other.endingSpaceTabChar.test(t))&&(e=t.trim())}return{type:`heading`,raw:J(t[0],`
14
- `),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:J(t[0],`
15
- `)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=J(t[0],`
12
+ `)}function qt(e,t,n,r){if(!t.includes(`<`))return!1;for(let i=0;i<t.length;i++){if(t[i]===`\\`){i++;continue}if(t[i]==="`"){let e=r.inline.code.exec(t.slice(i));if(e){i+=e[0].length-1;continue}}if(t[i]!==`<`)continue;let a=e.slice(n+i),o=r.inline.tag.exec(a)||r.inline.autolink.exec(a);if(o){if(o[0].length>t.length-i)return!0;i+=o[0].length-1}}return!1}var Jt=class{options;rules;lexer;constructor(e){this.options=e||ce}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]:jt(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=Kt(e,t[3]||``,this.rules);return t[3]!==void 0&&(n===``||n.endsWith(`
13
+ `))&&(n+=`
14
+ `),{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=R(e,`#`);(this.options.pedantic||!t||this.rules.other.endingSpaceTabChar.test(t))&&(e=t.trim())}return{type:`heading`,raw:R(t[0],`
15
+ `),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:R(t[0],`
16
+ `)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=R(t[0],`
16
17
  `).split(`
17
18
  `),n=``,r=``,i=[];for(;e.length>0;){let t=!1,a=[],o=0;for(;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(`
18
- `),c=s.replace(this.rules.other.blockquoteMarkerWhitespace,(e,t,n)=>t+tr(n,t.length)).replace(this.rules.other.blockquoteSetextReplace,`
19
+ `),c=(this.lexer.state.top&&!this.lexer.state.inBlockquote&&s.includes(` `)?Vt(a):s).replace(this.rules.other.blockquoteMarkerWhitespace,(e,t,n)=>n.startsWith(` `)?t+` `+n.slice(1):t+Bt(n,t.length)).replace(this.rules.other.blockquoteSetextReplace,`
19
20
  $1`).replace(this.rules.other.blockquoteSetextReplace2,``);n=n?`${n}
20
21
  ${s}`:s,r=r?`${r}
21
- ${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`||u?.type===`heading`||u?.type===`hr`||u?.type===`html`||u?.type===`table`)break;if(u?.type===`blockquote`){let t=u,a=e.join(`
22
+ ${c}`:c;let l=this.lexer.state.top,u=this.lexer.state.inBlockquote;if(this.lexer.state.top=!0,this.lexer.state.inBlockquote=!0,this.lexer.blockTokens(c,i,!0),this.lexer.state.top=l,this.lexer.state.inBlockquote=u,e.length===0)break;let d=i.at(-1);if(d?.type===`code`||d?.type===`heading`||d?.type===`hr`||d?.type===`html`||d?.type===`table`)break;if(d?.type===`blockquote`){let t=d,a=e.join(`
22
23
  `),o=t.raw+`
23
- `+a.replace(this.rules.other.blockquoteSetextReplace2,``),s=this.blockquote(o);i[i.length-1]=s;let c=o.substring(s.raw.length).replace(/^\n/,``),l=c?c.split(`
24
- `).length:0,d=l?e.slice(0,-l):e;if(d.length>0&&(n=`${n}
25
- ${d.join(`
26
- `)}`),r=r.substring(0,r.length-t.text.length)+s.text,e=e.slice(d.length),e.length>0&&this.rules.other.blockquoteStart.test(e[0]))continue;break}if(u?.type===`list`){let t=u,a=t.raw+`
24
+ `+a.replace(this.rules.other.blockquoteSetextReplace2,``);this.lexer.state.inBlockquote=!0;let s=this.blockquote(o);this.lexer.state.inBlockquote=u,i[i.length-1]=s;let c=o.substring(s.raw.length).replace(/^\n/,``),l=c?c.split(`
25
+ `).length:0,f=l?e.slice(0,-l):e;if(f.length>0&&(n=`${n}
26
+ ${f.join(`
27
+ `)}`),r=r.substring(0,r.length-t.text.length)+s.text,e=e.slice(f.length),e.length>0&&this.rules.other.blockquoteStart.test(e[0]))continue;break}if(d?.type===`list`){let t=d,a=t.raw+`
27
28
  `+e.join(`
28
29
  `),o=this.list(a);i[i.length-1]=o;let s=o.raw.length>t.raw.length?a.slice(t.raw.length+1,o.raw.length).split(`
29
30
  `).length:0;if(s>0){let t=e.slice(0,s).join(`
30
31
  `);n=`${n}
31
32
  ${t}`,r=`${r}
32
- ${t}`}e=e.slice(s)}}return{type:`blockquote`,raw:n,tokens:i,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){if(!this.options.pedantic&&this.lexer.state.lastToken?.type===`text`&&!this.rules.other.listInterruptsParagraph.test(e))return;let n=e,r=()=>n.length-e.length,i=t[1].trim(),a=i.length>1,o={type:`list`,raw:``,ordered:a,start:a?+i.slice(0,-1):``,loose:!1,items:[]};i=a?`\\d{1,9}\\${i.slice(-1)}`:`\\${i}`,this.options.pedantic&&(i=a?i:`[*+-]`);let s=this.rules.other.listItemRegex(i),c=!1;for(;e;){let i=!1,a=``;if(!(t=s.exec(e))||this.rules.block.hr.test(e))break;let l=r();e=e.substring(t[0].length);let u=t[2].split(`
33
- `,1)[0],d=t[1].length,f=this.options.pedantic?tr(u,d):u.replace(this.rules.other.leadingSpaceTab,e=>tr(e,d)),p=e.split(`
33
+ ${t}`}if(e=e.slice(s),e.length>0&&!this.rules.other.blockquoteStart.test(e[0]))break}}return{type:`blockquote`,raw:n,tokens:i,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){if(!this.options.pedantic&&this.lexer.state.lastToken?.type===`text`&&!this.rules.other.listInterruptsParagraph.test(e))return;let n=e,r=()=>n.length-e.length,i=t[1].trim(),a=i.length>1,o={type:`list`,raw:``,ordered:a,start:a?+i.slice(0,-1):``,loose:!1,items:[]};i=a?`\\d{1,9}\\${i.slice(-1)}`:`\\${i}`,this.options.pedantic&&(i=a?i:`[*+-]`);let s=this.rules.other.listItemRegex(i),c=!1;for(;e;){let i=!1,a=``;if(!(t=s.exec(e))||this.rules.block.hr.test(e))break;let l=r();e=e.substring(t[0].length);let u=t[2].split(`
34
+ `,1)[0],d=t[1].length,f=this.options.pedantic?Bt(u,d):u.replace(this.rules.other.leadingSpaceTab,e=>Bt(e,d)),p=e.split(`
34
35
  `,1)[0],m=!f.trim(),h=0;if(this.options.pedantic?(h=2,a=f.trimStart()):m?h=d+1:(h=f.search(this.rules.other.nonSpaceChar),h=h>4?1:h,a=f.slice(h),h+=d),m&&this.rules.other.blankLine.test(p)&&(e=e.substring(p.length+1),i=!0),!i){let t=this.rules.other.nextBulletRegex(h),n=this.rules.other.hrRegex(h),r=this.rules.other.fencesBeginRegex(h),i=this.options.pedantic?this.rules.other.pedanticHeadingBeginRegex(h):this.rules.other.headingBeginRegex(h),o=this.rules.other.htmlBeginRegex(h),s=this.rules.other.blockquoteBeginRegex(h),c=!1;for(;e;){let l=e.split(`
35
- `,1)[0],u;if(p=l,this.options.pedantic?(p=p.replace(this.rules.other.listReplaceNesting,` `),u=p):u=p.replace(this.rules.other.leadingSpaceTab,e=>tr(e)),r.test(p)||i.test(p)||o.test(p)||s.test(p)||t.test(p)||n.test(p))break;if(u.search(this.rules.other.nonSpaceChar)>=h||!p.trim())a+=`
36
- `+u.slice(h),c=!1;else{if(m||f.replace(this.rules.other.tabCharGlobal,` `).search(this.rules.other.nonSpaceChar)>=4||r.test(f)||i.test(f)||o.test(f)||n.test(f))break;if(!this.options.pedantic&&!c){let e=f.replace(this.rules.other.nestedContainerMarkers,``);if(this.rules.block.fences.test(e)||this.rules.block.heading.test(e)||this.rules.block.hr.test(e))break}let e=!this.options.pedantic&&/^ {0,3}(?:=+|-+) *$/.test(p)&&this.rules.block.lheading.test(`${f}
36
+ `,1)[0],u;if(p=l,this.options.pedantic?(p=p.replace(this.rules.other.listReplaceNesting,` `),u=p):u=p.replace(this.rules.other.leadingSpaceTab,e=>Bt(e)),r.test(p)||i.test(p)||o.test(p)||s.test(p)||t.test(p)||n.test(p))break;if(u.search(this.rules.other.nonSpaceChar)>=h||!p.trim())a+=`
37
+ `+u.slice(h),c=!1;else{if(m)break;let e=f;if(!this.options.pedantic&&!a.includes(`
38
+ `)&&!f.includes(` `)){let t;for(;!n.test(e)&&(t=this.rules.other.nestedBlockMarker.exec(e));)e=e.slice(t[0].length);if(!e.trim())break}if(e.replace(this.rules.other.tabCharGlobal,` `).search(this.rules.other.nonSpaceChar)>=4||r.test(e)||i.test(e)||o.test(e)||n.test(e))break;if(!this.options.pedantic&&!c){let e=f.replace(this.rules.other.nestedContainerMarkers,``);if(this.rules.block.fences.test(e)||this.rules.block.heading.test(e)||this.rules.block.hr.test(e))break}let t=!this.options.pedantic&&/^ {0,3}(?:=+|-+) *$/.test(p)&&this.rules.block.lheading.test(`${f}
37
39
  ${p}`)?` ${u.replace(/^ {0,3}/,``)}`:p;a+=`
38
- `+e,c=!0}m=!p.trim(),e=e.substring(l.length+1),f=u.slice(h)}}let g=n.slice(l,r());o.loose||(c?o.loose=!0:this.rules.other.doubleBlankLine.test(g)&&(c=!0)),o.items.push({type:`list_item`,raw:g,task:!!this.options.gfm&&this.rules.other.listIsTask.test(a),loose:!1,text:a,tokens:[]})}let l=o.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;o.raw=n.slice(0,r()).trimEnd();for(let e of o.items)if(this.lexer.state.top=!1,e.tokens=this.lexer.blockTokens(e.text,[]),!o.loose){let t=e.tokens.filter(e=>e.type===`space`);o.loose=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw))}for(let e of o.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,o.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(o.loose)for(let e of o.items){e.loose=!0;for(let t of e.tokens)t.type===`text`&&(t.type=`paragraph`)}return o}}html(e){let t=this.rules.block.html.exec(e);if(t){let e=Kn(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){if(!this.rules.other.startAngleBracket.test(t[2])&&Jn(t[2],`()`)!==-1)return;let e=qn(t[1]),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:J(t[0],`
39
- `),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=Gn(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,``).split(`|`),i=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,``).split(`
40
- `):[],a={type:`table`,raw:J(t[0],`
41
- `),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(Gn(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:J(t[0],`
40
+ `+t,c=!0}m=!p.trim(),e=e.substring(l.length+1),f=u.slice(h)}}let ee=n.slice(l,r());o.loose||(c?o.loose=!0:this.rules.other.doubleBlankLine.test(ee)&&(c=!0)),o.items.push({type:`list_item`,raw:ee,task:!!this.options.gfm&&this.rules.other.listIsTask.test(a),loose:!1,text:a,tokens:[]})}let l=o.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;o.raw=n.slice(0,r()).trimEnd();let u=[];for(let e of o.items)if(this.lexer.state.top=!1,u.push(this.lexer.inlineQueue.length),e.tokens=this.lexer.blockTokens(e.text,[]),!o.loose){let t=e.tokens.filter(e=>e.type===`space`);o.loose=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw))}for(let e=0;e<o.items.length;e++){let t=o.items[e],n=t.tokens[0];if(t.task&&(n?.type===`text`||n?.type===`paragraph`)){t.text=t.text.replace(this.rules.other.listReplaceTask,``),n.raw=n.raw.replace(this.rules.other.listReplaceTask,``),n.text=n.text.replace(this.rules.other.listReplaceTask,``);let r=this.lexer.inlineQueue;for(let t=u[e];t<r.length;t++)if(r[t].tokens===n.tokens){r[t].src=r[t].src.replace(this.rules.other.listReplaceTask,``);break}let i=this.rules.other.listTaskCheckbox.exec(t.raw);if(i){let e={type:`checkbox`,raw:i[0]+` `,checked:i[0]!==`[ ]`};t.checked=e.checked,o.loose?t.tokens[0]&&[`paragraph`,`text`].includes(t.tokens[0].type)&&`tokens`in t.tokens[0]&&t.tokens[0].tokens?(t.tokens[0].raw=e.raw+t.tokens[0].raw,t.tokens[0].text=e.raw+t.tokens[0].text,t.tokens[0].tokens.unshift(e)):t.tokens.unshift({type:`paragraph`,raw:e.raw,text:e.raw,tokens:[e]}):t.tokens.unshift(e)}}else t.task&&=!1}if(o.loose)for(let e of o.items){e.loose=!0;for(let t of e.tokens)t.type===`text`&&(t.type=`paragraph`)}return o}}html(e){let t=this.rules.block.html.exec(e);if(t){if(this.lexer.state.lastToken?.type===`paragraph`&&!this.rules.other.htmlBeginRegex(4).test(e))return;let n=jt(t[0]);return{type:`html`,block:!0,raw:n,pre:t[1]===`pre`||t[1]===`script`||t[1]===`style`,text:n}}}def(e){let t=this.rules.block.def.exec(e);if(t){if(!this.rules.other.startAngleBracket.test(t[2])&&Nt(t[2],`()`)!==-1)return;let e=Mt(t[1]),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:R(t[0],`
41
+ `),href:n,title:r}}}table(e){let t,n;if(this.options.gfm&&!this.options.pedantic){let r=this.rules.other.tableHeader.exec(e);if(!r||!this.rules.other.tableDelimiter.test(r[2])||(t=At(r[1]),n=r[2].replace(this.rules.other.tableAlignChars,``).split(`|`),t.length!==n.length))return}let r=this.rules.block.table.exec(e);if(!r||!this.rules.other.tableDelimiter.test(r[2]))return;t??=At(r[1]),n??=r[2].replace(this.rules.other.tableAlignChars,``).split(`|`);let i=r[3]?.trim()?r[3].replace(this.rules.other.tableRowBlankLine,``).split(`
42
+ `):[],a={type:`table`,raw:R(r[0],`
43
+ `),header:[],align:[],rows:[]};if(t.length===n.length){for(let e of n)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<t.length;e++)a.header.push({text:t[e],tokens:this.lexer.inline(t[e]),header:!0,align:a.align[e]});for(let e of i)a.rows.push(At(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:R(t[0],`
42
44
  `),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)===`
43
- `?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){if(this.lexer.state.linkParenPossible===!1)return;let t=this.rules.inline.link.exec(e);if(t){let n=t[0].charAt(0)===`!`?2:1;if(!this.options.pedantic&&ir(e,t[1],n,this.rules))return;let r=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(r)){if(!this.rules.other.endAngleBracket.test(r))return;let e=J(r.slice(0,-1),`\\`);if((r.length-e.length)%2==0)return}else{let e=Jn(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 i=J(t[0].slice(0,-1),`\\`);if((t[0].length-i.length)%2==0)return;let a=t[2],o=``;if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(a);e&&(a=e[1],o=e[3])}else o=t[3]?t[3].slice(1,-1):``;return a=a.trim(),this.rules.other.startAngleBracket.test(a)&&(a=this.options.pedantic&&!this.rules.other.endAngleBracket.test(r)?a.slice(1):a.slice(1,-1)),nr(t,{href:a&&a.replace(this.rules.inline.anyPunctuation,`$1`),title:o&&o.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 r=n[0].charAt(0)===`!`?2:1;if(!this.options.pedantic&&ir(e,n[1],r,this.rules))return;let i=t[qn(n[2]||n[1])];if(!i){let e=n[0].charAt(0);return{type:`text`,raw:e,text:e}}return nr(n,i,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])return;let i=r[0][0],a=n===i,o=t.length-e.length,s=o;for(;!this.options.pedantic&&s>0&&t[s-1]===i;)s--;let c=[...t.slice(Math.max(0,s-2),s)].at(-1)??``,l=c===`*`||c===`_`||!!this.rules.inline.punctuation.exec(c);s<o&&(n=c);let u=s<o?l:n===`*`||n===`_`||!!this.rules.inline.punctuation.exec(n);if(r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))return;let d=r[1]||r[3]||``;if(!d||!n||u){let n=[...r[0]].length-1,u,f,p=n,m=0,h=o-s+n,g=!this.options.pedantic&&!!c.trim()&&(!!d||i===`*`&&!l);if(i!==`*`&&i!==`_`)return;let _=i===`*`?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd,ee=$n(this,t,i),v=t.length-e.length+n;if(ee<v)return;t=t.slice(-1*e.length+n);let y=ee-v;for(_.lastIndex=0;(r=_.exec(t))!==null&&!(r.index>y);){if(u=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!u)continue;if(f=[...u].length,r[3]||r[4]){p+=f;continue}if(r[5]||r[6]||g){if(a&&(r[5]||r[6]))break;if(h%3&&!((h+f)%3)){m+=f;continue}}if(p-=f,p>0)continue;f=Math.min(f,f+p+m);let t=[...r[0]][0].length,i=e.slice(0,n+r.index+t+f);if(Math.min(n,f)%2){let e=i.slice(1,-1);return{type:`em`,raw:i,text:e,tokens:this.lexer.inlineTokens(e)}}let o=i.slice(2,-2);return{type:`strong`,raw:i,text:o,tokens:this.lexer.inlineTokens(o)}}}}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,c=er(this,t),l=t.length-e.length+n;if(c<l)return;t=t.slice(-1*e.length+n);let u=c-l;for(s.lastIndex=0;(r=s.exec(t))!==null&&!(r.index>u);){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,autolink:!0,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,autolink:!0,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:e?t[0]:Un(t[0]),escaped:e}}}},Y=class e{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||L,this.options.tokenizer=this.options.tokenizer||new ar,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,linkEmitted:!1,linkParenPossible:!0,top:!0};let t={other:B,block:Bn.normal,inline:Vn.normal};this.options.pedantic?(t.block=Bn.pedantic,t.inline=Vn.pedantic):this.options.gfm&&(t.block=Bn.gfm,t.inline=this.options.breaks?Vn.breaks:Vn.gfm),this.tokenizer.rules=t}static get rules(){return{block:Bn,inline:Vn}}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(B.carriageReturn,`
44
- `),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.state.inRawBlock=!1,this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){this.tokenizer.lexer=this;let r=this.state.lastToken;this.options.pedantic&&(e=e.replace(B.tabCharGlobal,` `).replace(B.spaceLine,``));let i=1/0;for(;e;){if(e.length<i)i=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}this.state.lastToken=t.at(-1);let r;if(this.options.extensions?.block?.some(n=>(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let n=t.at(-1);r.raw.length===1&&n!==void 0?n.raw+=`
45
+ `?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){let n=t[0],r=t[0],i=this.rules.other.textIndentedContinuation.exec(e.slice(n.length));return i&&(n+=i[0],r+=i[0].replace(this.rules.other.codeRemoveIndent,``)),{type:`text`,raw:n,text:r,tokens:this.lexer.inline(r)}}}escape(e){if(e.charCodeAt(0)!==92)return;let t=this.rules.inline.escape.exec(e);if(t)return{type:`escape`,raw:t[0],text:t[1]}}tag(e){if(e.charCodeAt(0)!==60)return;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){if(this.lexer.state.linkParenPossible===!1)return;let t=e.charCodeAt(0);if(t!==91&&t!==33)return;let n=this.rules.inline.link.exec(e);if(n){let t=n[0].charAt(0)===`!`?2:1;if(!this.options.pedantic&&qt(e,n[1],t,this.rules))return;let r=n[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(r)){if(!this.rules.other.endAngleBracket.test(r))return;let e=R(r.slice(0,-1),`\\`);if((r.length-e.length)%2==0)return}else{let e=Nt(n[2],`()`);if(e===-2)return;if(e>-1){let t=(n[0].indexOf(`!`)===0?5:4)+n[1].length+e;n[2]=n[2].substring(0,e),n[0]=n[0].substring(0,t).trim(),n[3]=``}}let i=R(n[0].slice(0,-1),`\\`);if((n[0].length-i.length)%2==0)return;let a=n[2],o=``;if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(a);e&&(a=e[1],o=e[3])}else o=n[3]?n[3].slice(1,-1):``;return a=a.trim(),this.rules.other.startAngleBracket.test(a)&&(a=this.options.pedantic&&!this.rules.other.endAngleBracket.test(r)?a.slice(1):a.slice(1,-1)),Gt(n,{href:a&&a.replace(this.rules.inline.anyPunctuation,`$1`),title:o&&o.replace(this.rules.inline.anyPunctuation,`$1`)},n[0],this.lexer,this.rules)}}reflink(e,t){let n=e.charCodeAt(0);if(n!==91&&n!==33)return;let r;if((r=this.rules.inline.reflink.exec(e))||(r=this.rules.inline.nolink.exec(e))){let n=r[0].charAt(0)===`!`?2:1;if(!this.options.pedantic&&qt(e,r[1],n,this.rules))return;let i=t[Mt(r[2]||r[1])];if(!i){let e=r[0].charAt(0);return{type:`text`,raw:e,text:e}}return Gt(r,i,r[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])return;let i=r[0][0],a=n===i,o=t.length-e.length,s=o;for(;!this.options.pedantic&&s>0&&t[s-1]===i;)s--;let c=[...t.slice(Math.max(0,s-2),s)].at(-1)??``,l=c===`*`||c===`_`||!!this.rules.inline.punctuation.exec(c);s<o&&(n=c);let u=s<o?l:n===`*`||n===`_`||!!this.rules.inline.punctuation.exec(n);if(r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))return;let d=r[1]||r[3]||``;if(!d||!n||u){let n=[...r[0]].length-1,u,f,p=n,m=0,h=o-s+n,ee=!this.options.pedantic&&!!c.trim()&&(!!d||i===`*`&&!l);if(i!==`*`&&i!==`_`)return;let g=i===`*`?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd,_=Rt(this,t,i),te=t.length-e.length+n;if(_<te)return;t=t.slice(-1*e.length+n);let ne=_-te;for(g.lastIndex=0;(r=g.exec(t))!==null&&!(r.index>ne);){if(u=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!u)continue;if(f=[...u].length,r[3]||r[4]){p+=f;continue}if((r[5]||r[6]||ee)&&h%3&&!((h+f)%3)){if(a&&(r[5]||r[6]))break;m+=f;continue}if(p-=f,p>0)continue;f=Math.min(f,f+p+m);let t=[...r[0]][0].length,i=e.slice(0,n+r.index+t+f);if(Math.min(n,f)%2){let e=i.slice(1,-1);return{type:`em`,raw:i,text:e,tokens:this.lexer.inlineTokens(e)}}let o=i.slice(2,-2);return{type:`strong`,raw:i,text:o,tokens:this.lexer.inlineTokens(o)}}}}codespan(e){if(e.charCodeAt(0)!==96)return;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=e.charCodeAt(0);if(t!==32&&t!==92&&t!==10)return;let n=this.rules.inline.br.exec(e);if(n)return{type:`br`,raw:n[0]}}del(e,t,n=``){if(e.charCodeAt(0)!==126)return;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,c=zt(this,t),l=t.length-e.length+n;if(c<l)return;t=t.slice(-1*e.length+n);let u=c-l;for(s.lastIndex=0;(r=s.exec(t))!==null&&!(r.index>u);){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){if(e.charCodeAt(0)!==60)return;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,autolink:!0,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,autolink:!0,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:e?t[0]:Ot(t[0]),escaped:e}}}},z=class e{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||ce,this.options.tokenizer=this.options.tokenizer||new Jt,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,linkEmitted:!1,linkParenPossible:!0,top:!0,inBlockquote:!1};let t={other:D,block:wt.normal,inline:Tt.normal};this.options.pedantic?(t.block=wt.pedantic,t.inline=Tt.pedantic):this.options.gfm&&(t.block=wt.gfm,t.inline=this.options.breaks?Tt.breaks:Tt.gfm),this.tokenizer.rules=t}static get rules(){return{block:wt,inline:Tt}}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(D.carriageReturn,`
46
+ `),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.state.inRawBlock=!1,this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){this.tokenizer.lexer=this;let r=this.state.lastToken;this.options.pedantic&&(e=e.replace(D.tabCharGlobal,` `).replace(D.spaceLine,``));let i=1/0,a,o=this.options.gfm&&!this.options.pedantic&&this.tokenizer.paragraph===Jt.prototype.paragraph;for(;e;){if(e.length<i)i=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}this.state.lastToken=t.at(-1);let r;if(this.options.extensions?.block?.some(n=>(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let n=t.at(-1);r.raw.length===1&&n!==void 0?n.raw+=`
45
47
  `:t.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=(n.raw.endsWith(`
46
48
  `)?``:`
47
49
  `)+r.raw,n.text+=`
48
50
  `+r.text,this.inlineQueue.at(-1).src=n.text):t.push(r);continue}if((r=this.tokenizer.fences(e))||(r=this.tokenizer.heading(e))||(r=this.tokenizer.hr(e))||(r=this.tokenizer.blockquote(e))||(r=this.tokenizer.list(e))||(r=this.tokenizer.html(e))){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.def(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=(n.raw.endsWith(`
49
51
  `)?``:`
50
52
  `)+r.raw,n.text+=`
51
- `+r.raw,this.inlineQueue.at(-1).src=n.text):(this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title}),t.push(r));continue}if((r=this.tokenizer.table(e))||(r=this.tokenizer.lheading(e))){e=e.substring(r.raw.length),t.push(r);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&&(r=this.tokenizer.paragraph(a))){let i=t.at(-1);n&&i?.type===`paragraph`?(i.raw+=(i.raw.endsWith(`
53
+ `+r.raw,this.inlineQueue.at(-1).src=n.text):(this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title}),t.push(r));continue}if((r=this.tokenizer.table(e))||(r=this.tokenizer.lheading(e))){e=e.substring(r.raw.length),t.push(r);continue}let s=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&&(s=e.substring(0,t+1))}if(this.state.top&&(r=this.tokenizer.paragraph(s))){let i=t.at(-1);(n||i===a&&o)&&i?.type===`paragraph`?(i.raw+=(i.raw.endsWith(`
52
54
  `)?``:`
53
55
  `)+r.raw,i.text+=`
54
- `+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text):t.push(r),n=a.length!==e.length,e=e.substring(r.raw.length)}else if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`text`?(n.raw+=(n.raw.endsWith(`
56
+ `+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text,a=i):(t.push(r),a=r),n=s.length!==e.length,e=e.substring(r.raw.length)}else if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`text`?(n.raw+=(n.raw.endsWith(`
55
57
  `)?``:`
56
58
  `)+r.raw,n.text+=`
57
- `+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(r)}else if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,this.state.lastToken=r,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}linkInText(e){if(!e.includes(`[`))return!1;let t=this.tokenizer.rules.inline.link;for(let n of e.matchAll(this.tokenizer.rules.inline.blockSkip))if(t.test(n[0])&&e.charAt(n.index-1)!==`!`)return!0;for(let t of e.matchAll(this.tokenizer.rules.inline.reflinkSearch)){let e=t[0],n=e.lastIndexOf(`[`);if(e.charAt(0)!==`!`&&Object.hasOwn(this.tokens.links,qn(e.slice(n+1,-1)))&&!(n>1&&this.linkInText(e.slice(1,n-1))))return!0}return!1}inlineTokens(e,t=[]){this.tokenizer.lexer=this;let n=this.state.linkParenPossible;this.state.linkParenPossible=n&&e.includes(`)`);try{return this.#e(e,t)}finally{this.state.linkParenPossible=n}}#e(e,t){let n=e.includes(`*`)||e.includes(`_`)||e.includes(`~`)||this.options.hooks?.emStrongMask||this.tokenizer.emStrong!==ar.prototype.emStrong||this.tokenizer.del!==ar.prototype.del?this.#r(e):e;Zn(this.tokenizer,n);try{return this.#t(e,n,t)}finally{Qn(this.tokenizer)}}#t(e,t,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(t=>(o=t.call({lexer:this},e,n))?(e=e.substring(o.raw.length),n.push(o),!0):!1))continue;if((o=this.tokenizer.escape(e))||(o=this.tokenizer.tag(e))||(o=this.tokenizer.link(e))){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(o.raw.length);let t=n.at(-1);o.type===`text`&&t?.type===`text`?(t.raw+=o.raw,t.text+=o.text):n.push(o);continue}if((o=this.tokenizer.emStrong(e,t,i))||(o=this.tokenizer.codespan(e))||(o=this.tokenizer.br(e))||(o=this.tokenizer.del(e,t,i))||(o=this.tokenizer.autolink(e))||!this.state.inLink&&(o=this.tokenizer.url(e))){e=e.substring(o.raw.length),n.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 t=n.at(-1);t?.type===`text`?(t.raw+=o.raw,t.text+=o.text):n.push(o)}else if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return n}#n(e){let{blockSkip:t,tag:n,autolink:r}=this.tokenizer.rules.inline,i=``,a=0,o;for(t.lastIndex=0;o=t.exec(e);){let s=o.index+(o[2]?o[2].length:0),c=o.index+o[0].length;if(e.charAt(s)===`<`){let i=e.slice(s),a=n.exec(i)||r.exec(i);if(!a){t.lastIndex=s+1;continue}c=s+a[0].length,t.lastIndex=c}i+=e.slice(a,s)+`[`+`a`.repeat(c-s-2)+`]`,a=c}return i+e.slice(a)}#r(e){let t=e;if(this.tokens.links&&e.includes(`[`)){let e=this.tokenizer.rules.inline.reflinkSearch,n=t=>{let r=t.lastIndexOf(`[`);if(!Object.hasOwn(this.tokens.links,qn(t.slice(r+1,-1))))return t;if(r>1&&t.charAt(0)!==`!`){let i=t.slice(1,r-1);if(this.linkInText(i))return`[`+i.replace(e,n)+`][`+`a`.repeat(t.length-r-2)+`]`}return`[`+`a`.repeat(t.length-2)+`]`};t=t.replace(e,n)}return t=t.replace(this.tokenizer.rules.inline.anyPunctuationOutsideCode,(e,t,n)=>n?`+`.repeat(e.length):t?t+e.slice(t.length,-t.length).replace(/`/g,`+`)+t:e),t=this.#n(t),t=this.options.hooks?.emStrongMask?.call({lexer:this},t)??t,t}infiniteLoopError(e){let t=`Infinite loop on byte: `+e;if(this.options.silent)console.error(t);else throw Error(t)}},or=class{options;parser;constructor(e){this.options=e||L}space(e){return``}code({text:e,lang:t,escaped:n}){let r=(t||``).match(B.notSpaceStart)?.[0],i=e?e.replace(B.endingNewline,``)+`
58
- `:``;return r?`<pre><code class="language-`+q(r)+`">`+(n?i:q(i,!0))+`</code></pre>
59
- `:`<pre><code>`+(n?i:q(i,!0))+`</code></pre>
59
+ `+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(r)}else if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,this.state.lastToken=r,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}linkInText(e){if(!e.includes(`[`))return!1;let t=this.tokenizer.rules.inline.link;for(let n of e.matchAll(this.tokenizer.rules.inline.blockSkip))if(t.test(n[0])&&e.charAt(n.index-1)!==`!`)return!0;for(let t of e.matchAll(this.tokenizer.rules.inline.reflinkSearch)){let e=t[0],n=e.lastIndexOf(`[`);if(e.charAt(0)!==`!`&&Object.hasOwn(this.tokens.links,Mt(e.slice(n+1,-1)))&&!(n>1&&this.linkInText(e.slice(1,n-1))))return!0}return!1}inlineTokens(e,t=[]){this.tokenizer.lexer=this;let n=this.state.linkParenPossible;this.state.linkParenPossible=e.includes(`)`);try{return this.#e(e,t)}finally{this.state.linkParenPossible=n}}#e(e,t){let n=e.includes(`*`)||e.includes(`_`)||e.includes(`~`),r=n||this.options.hooks?.emStrongMask||this.tokenizer.emStrong!==Jt.prototype.emStrong||this.tokenizer.del!==Jt.prototype.del?this.#r(e):e;if(!n)return this.#t(e,r,t);It(this.tokenizer,r);try{return this.#t(e,r,t)}finally{Lt(this.tokenizer)}}#t(e,t,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(t=>(o=t.call({lexer:this},e,n))?(e=e.substring(o.raw.length),n.push(o),!0):!1))continue;if((o=this.tokenizer.escape(e))||(o=this.tokenizer.tag(e))||(o=this.tokenizer.link(e))){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(o.raw.length);let t=n.at(-1);o.type===`text`&&t?.type===`text`?(t.raw+=o.raw,t.text+=o.text):n.push(o);continue}let s=e[0];if(s===`*`||s===`_`){let a=t.length-e.length;if(Rt(this.tokenizer,t,s)<=a){let t=1;for(;t<e.length&&e.charCodeAt(t)===s.charCodeAt(0);)t++;let a=e.substring(0,t),o=n.at(-1);o?.type===`text`&&!o.escaped?(o.raw+=a,o.text+=a):n.push({type:`text`,raw:a,text:a,escaped:!1}),e=e.substring(t),i=s,r=!0;continue}}else if(s===`~`){let a=t.length-e.length;if(zt(this.tokenizer,t)<=a){let t=1;for(;t<e.length&&e.charCodeAt(t)===126;)t++;let a=e.substring(0,t),o=n.at(-1);o?.type===`text`&&!o.escaped?(o.raw+=a,o.text+=a):n.push({type:`text`,raw:a,text:a,escaped:!1}),e=e.substring(t),i=s,r=!0;continue}}if((o=this.tokenizer.emStrong(e,t,i))||(o=this.tokenizer.codespan(e))||(o=this.tokenizer.br(e))||(o=this.tokenizer.del(e,t,i))||(o=this.tokenizer.autolink(e))||!this.state.inLink&&(o=this.tokenizer.url(e))){e=e.substring(o.raw.length),n.push(o);continue}let c=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&&(c=e.substring(0,t+1))}if(o=this.tokenizer.inlineText(c)){e=e.substring(o.raw.length),o.raw.slice(-1)!==`_`&&(i=o.raw.slice(-1)),r=!0;let t=n.at(-1);t?.type===`text`?(t.raw+=o.raw,t.text+=o.text):n.push(o)}else if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return n}#n(e){let{blockSkip:t,tag:n,autolink:r}=this.tokenizer.rules.inline,i=``,a=0,o;for(t.lastIndex=0;o=t.exec(e);){let s=o.index+(o[2]?o[2].length:0),c=o.index+o[0].length;if(e.charAt(s)===`<`){let i=e.slice(s),a=n.exec(i)||r.exec(i);if(!a){t.lastIndex=s+1;continue}c=s+a[0].length,t.lastIndex=c}i+=e.slice(a,s)+`[`+`a`.repeat(c-s-2)+`]`,a=c}return i+e.slice(a)}#r(e){let t=e;if(this.tokens.links&&e.includes(`[`)){let e=this.tokenizer.rules.inline.reflinkSearch,n=t=>{let r=t.lastIndexOf(`[`);if(!Object.hasOwn(this.tokens.links,Mt(t.slice(r+1,-1))))return t;if(r>1&&t.charAt(0)!==`!`){let i=t.slice(1,r-1);if(this.linkInText(i))return`[`+i.replace(e,n)+`][`+`a`.repeat(t.length-r-2)+`]`}return`[`+`a`.repeat(t.length-2)+`]`};t=t.replace(e,n)}return t=t.replace(this.tokenizer.rules.inline.anyPunctuationOutsideCode,(e,t,n)=>n?`+`.repeat(e.length):t?t+e.slice(t.length,-t.length).replace(/`/g,`+`)+t:e),t=this.#n(t),t=this.options.hooks?.emStrongMask?.call({lexer:this},t)??t,t}infiniteLoopError(e){let t=`Infinite loop on byte: `+e;if(this.options.silent)console.error(t);else throw Error(t)}};function Yt(e){return e.map(e=>e.type===`codespan`||e.type===`escape`?{...e,text:L(e.text,!0)}:`tokens`in e&&e.tokens?{...e,tokens:Yt(e.tokens)}:e)}var Xt=class{options;parser;constructor(e){this.options=e||ce}space(e){return``}code({text:e,lang:t,escaped:n}){let r=(t||``).match(D.notSpaceStart)?.[0],i=e?e.replace(D.endingNewline,``)+`
60
+ `:``;return r?`<pre><code class="language-`+L(r)+`">`+(n?i:L(i,!0))+`</code></pre>
61
+ `:`<pre><code>`+(n?i:L(i,!0))+`</code></pre>
60
62
  `}blockquote({tokens:e}){return`<blockquote>
61
63
  ${this.parser.parse(e)}</blockquote>
62
64
  `}html({text:e}){return e}def(e){return``}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
@@ -72,9 +74,16 @@ ${this.parser.parse(e)}</blockquote>
72
74
  `}tablerow({text:e}){return`<tr>
73
75
  ${e}</tr>
74
76
  `}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?`th`:`td`;return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
75
- `}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>${q(e,!0)}</code>`}br(e){return`<br>`}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,text:n,tokens:r,autolink:i}){let a=i?q(n,!0):this.parser.parseInline(r),o=Wn(e);if(o===null)return a;e=q(o,i);let s=`<a href="`+e+`"`;return t&&(s+=` title="`+q(t)+`"`),s+=`>`+a+`</a>`,s}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=Wn(e);if(i===null)return q(n);e=i;let a=`<img src="${q(e)}" alt="${q(n)}"`;return t&&(a+=` title="${q(t)}"`),a+=`>`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:q(e.text)}},sr=class{parser;strong({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}em({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}codespan({text:e}){return e}del({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}html({text:e}){return e}text({text:e}){return e}link({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}image({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}br(){return`
76
- `}checkbox({raw:e}){return e}},X=class e{options;renderer;textRenderer;constructor(e){this.options=e||L,this.options.renderer=this.options.renderer||new or,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new sr,this.textRenderer.parser=this}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===!1?``: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===!1?``: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}},cr=class{options;block;constructor(e){this.options=e||L}static passThroughHooks=/* @__PURE__ */ new Set([`preprocess`,`postprocess`,`processAllTokens`,`emStrongMask`]);static passThroughHooksRespectAsync=/* @__PURE__ */ 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?Y.lex:Y.lexInline}provideParser(e=this.block){return e?X.parse:X.parseInline}};function lr(e,t){if(Array.isArray(t))for(let n=0;n<t.length;n++)e.push(t[n]);else e.push(t)}var ur=class{defaults=Et();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=X;Renderer=or;TextRenderer=sr;Lexer=Y;Tokenizer=ar;Hooks=cr;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(lr(n,t.call(this,r)),r.type){case`table`:{let e=r;for(let r of e.header)lr(n,this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)lr(n,this.walkTokens(e.tokens,t));break}case`list`:{let e=r;lr(n,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);lr(n,this.walkTokens(i,t))}):e.tokens&&lr(n,this.walkTokens(e.tokens,t))}}return n}use(...e){let t=this.defaults.extensions||{renderers:Object.create(null),childTokens:Object.create(null)};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 or(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===!1?``:n??``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new ar(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new cr;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]=cr.passThroughHooks.has(n)?e=>{if(t.options.async&&cr.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(t.options.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 lr(n,r.call(this,e)),t&&lr(n,t.call(this,e)),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return Y.lex(e,t??this.defaults)}parser(e,t){return X.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(/* @__PURE__ */ 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(/* @__PURE__ */ Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(/* @__PURE__ */ 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?Y.lex:Y.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?X.parse:X.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?Y.lex:Y.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?X.parse:X.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+=`
77
- Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+q(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}},dr=new ur;function Z(e,t){return dr.parse(e,t)}Z.options=Z.setOptions=function(e){return dr.setOptions(e),Z.defaults=dr.defaults,Dt(Z.defaults),Z},Z.getDefaults=Et,Z.defaults=L;function fr(...e){return dr.use(...e),Z.defaults=dr.defaults,Dt(Z.defaults),Z}Z.use=fr,Z.walkTokens=function(e,t){return dr.walkTokens(e,t)},Z.parseInline=dr.parseInline,Z.Parser=X,Z.parser=X.parse,Z.Renderer=or,Z.TextRenderer=sr,Z.Lexer=Y,Z.lexer=Y.lex,Z.Tokenizer=ar,Z.Hooks=cr,Z.parse=Z,Z.options,Z.setOptions,Z.walkTokens,Z.parseInline,X.parse,Y.lex;var pr={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`},mr=e=>e.replace(/[&<>"']/g,e=>pr[e]),hr=new ur({gfm:!0,breaks:!0,async:!1,renderer:{html:({text:e})=>mr(e),image:({href:e,text:t})=>`<a href="${mr(e)}">${mr(t||e)}</a>`}}),gr=null;function _r(){return gr||(gr=I(window),gr.addHook(`afterSanitizeAttributes`,e=>{e.tagName===`A`&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer nofollow`))}),gr)}function vr(e){let t=hr.parse(e);return _r().sanitize(t,{FORBID_TAGS:[`img`,`style`,`form`,`input`,`button`,`textarea`],FORBID_ATTR:[`style`]})}var yr;function br(){if(yr!==void 0)return yr;let e=globalThis.trustedTypes;try{yr=e?.createPolicy(`aicore-agent-chat`,{createHTML:e=>e})??null}catch{yr=null}return yr}function xr(e,t){let n=t?vr(t):``,r=br();e.innerHTML=r?r.createHTML(n):n}var Sr=`change`,Cr=5,wr=1,Tr=50,Er=1500,Dr=60,Or={agentId:null,agent:null,conversations:[],conversationsLoading:!1,conversationsFailed:!1,activeId:null,messages:[],turn:null,turnStartedAt:null,loadingHistory:!1,error:null,files:[],uploading:0,requests:[],events:[],tokens:0},kr=(e,t)=>[t,...e].slice(0,Tr),Ar=e=>typeof e?.rating==`number`?e.rating:null;function jr(e){return e.map(e=>e.role===`user`?{role:`user`,text:e.content,attachments:e.attachments??[]}:{role:`assistant`,text:e.content,sources:e.sources??[],idQuery:e.id_query??null,error:null,rating:Ar(e.feedback),interrupted:!1})}var Mr=class extends EventTarget{client;#e=Or;#t=0;#n=null;#r=0;#i=null;constructor(e){super(),this.client=new ae({...e,onRequest:e=>this.#a(t=>({requests:kr(t.requests,e)})),onIdentityChange:()=>this.#d()})}get state(){return this.#e}get busy(){return this.#n!==null}#a(e){this.#e={...this.#e,...e(this.#e)},this.dispatchEvent(new Event(Sr))}#o(e){this.#a(()=>e)}async#s(e,t){try{await t()}catch(t){!a(t)&&e()&&this.#o({error:i(t)})}}#c(e=this.#t){return()=>e===this.#t}#l(e){let t=this.#r;return()=>this.#e.agentId===e&&t===this.#r}#u(){this.#n?.abort(),this.#n=null,this.#i=null,this.#t++,this.#o({activeId:null,messages:[],turn:null,turnStartedAt:null,loadingHistory:!1,files:[],uploading:0,error:null})}#d(){this.#r++,this.#u(),this.#o({conversations:[],conversationsFailed:!1,conversationsLoading:!1,requests:[],events:[],tokens:0}),this.refreshConversations()}async setAgent(e){if(e===this.#e.agentId||(this.#u(),this.#o({agentId:e,agent:null,conversations:[],conversationsFailed:!1}),!e))return;let t=this.#l(e);await Promise.all([this.#s(t,async()=>{let n=await this.client.getAgent(e);t()&&this.#o({agent:n})}),this.refreshConversations()])}async refreshConversations(){let{agentId:e}=this.#e;if(!e)return;let t=this.#l(e);this.#o({conversationsLoading:!0});let n=!0;await this.#s(t,async()=>{let r=await this.client.listConversations(e);n=!1,t()&&this.#o({conversations:[...r.items].sort((e,t)=>t.last_message_at-e.last_message_at)})}),t()&&this.#o({conversationsLoading:!1,conversationsFailed:n})}newConversation(){this.#u()}async open(e){if(e===this.#e.activeId)return;this.#u();let t=this.#t;this.#o({activeId:e,loadingHistory:!0}),await this.#s(this.#c(t),async()=>{let n=await this.client.history(e);t===this.#t&&this.#o({messages:jr(n)})}),t===this.#t&&this.#o({loadingHistory:!1})}async rename(e,t){let{agentId:n,conversations:r}=this.#e,a=t.trim(),o=r.find(t=>t.id===e);if(!n||!a||o?.title===a)return;let s=this.#l(n),c=t=>this.#a(n=>({conversations:n.conversations.map(n=>n.id===e?{...n,...t(n)}:n)}));c(()=>({title:a}));try{let t=await this.client.renameConversation(e,a);s()&&c(()=>t)}catch(e){if(!s())return;o&&c(e=>e.title===a?{title:o.title}:null),this.#o({error:i(e)})}}async remove(e){let{agentId:t}=this.#e;t&&await this.#s(this.#l(t),async()=>{await this.client.deleteConversation(e),e===this.#e.activeId&&this.#u(),this.#a(t=>({conversations:t.conversations.filter(t=>t.id!==e)}))})}#f(e){if(this.#e.activeId)return Promise.resolve(this.#e.activeId);let t=this.#t;if(this.#i?.epoch===t)return this.#i.promise;let n=this.client.openConversation(e).then(e=>{if(t!==this.#t)throw new DOMException(`moved on`,`AbortError`);return this.#i=null,this.#o({activeId:e.id_conv}),this.refreshConversations(),e.id_conv});return this.#i={epoch:t,promise:n},n.catch(()=>{this.#i?.promise===n&&(this.#i=null)}),n}async#p(e,t,n){let r=!1;try{for(let i=0;i<Dr;i++){if(await new Promise(e=>setTimeout(e,Er)),e!==this.#t)return;let i=(await this.client.listFiles(t)).find(e=>e.id_file===n);if(e!==this.#t||!i)return;if(this.#a(e=>({files:e.files.map(e=>e.id_file===n?i:e)})),i.status!==`processing`){r=!0;return}}}finally{!r&&e===this.#t&&this.#a(e=>({files:e.files.map(e=>e.id_file===n&&e.status===`processing`?{...e,status:`error`,error:`Processing did not finish`}:e)}))}}async attach(e){let{agentId:t}=this.#e;if(!t||this.busy)return;this.#o({error:null});let n=this.#t,r=this.#c(n);this.#a(e=>({uploading:e.uploading+1}));try{await this.#s(r,async()=>{let i=await this.#f(t);for(let t of e){let e=await this.client.uploadFile(i,t);if(n!==this.#t)return;this.#a(t=>({files:[...t.files,e]})),e.status===`processing`&&this.#s(r,()=>this.#p(n,i,e.id_file))}})}finally{n===this.#t&&this.#a(e=>({uploading:Math.max(0,e.uploading-1)}))}}async detach(e){let{activeId:t}=this.#e;t&&await this.#s(this.#c(),async()=>{await this.client.deleteFile(t,e),this.#a(t=>({files:t.files.filter(t=>t.id_file!==e)}))})}async send(e,t={}){let{context:n}=t,{agentId:r,activeId:a,files:o,uploading:s}=this.#e,c=e.trim();if(!r||this.busy||!c||s>0||o.some(e=>e.status===`processing`))return;let l=o.filter(e=>e.status===`ready`),u=this.#t,d=new AbortController;this.#n=d,this.#a(e=>({error:null,files:[],turn:_,turnStartedAt:Date.now(),events:[],tokens:0,messages:[...e.messages,{role:`user`,text:c,attachments:l.map(({id_file:e,name:t,mime:n,size:r})=>({id_file:e,name:t,mime:n,size:r}))}]}));let f=()=>u===this.#t&&!d.signal.aborted;try{let e=await this.client.ask({idAgent:r,idConv:a,request:{text:c,...l.length>0?{attachments:l.map(e=>({id_file:e.id_file}))}:{},...n?{context:n}:{}},signal:d.signal,onConversation:e=>{u===this.#t&&this.#o({activeId:e})},onUpdate:(e,t)=>{f()&&this.#a(n=>t.kind===`token`?{turn:e,tokens:n.tokens+1}:{turn:e,events:kr(n.events,{at:Date.now(),kind:t.kind,id:t.id,data:t.data})})}});if(u!==this.#t)return;this.#a(t=>({turn:null,messages:[...t.messages,{role:`assistant`,text:y(e.turn),sources:e.turn.sources,idQuery:e.idQuery,error:e.turn.error,rating:null,interrupted:!e.turn.finished}]})),(a===null||e.turn.title)&&await this.refreshConversations()}catch(e){f()?this.#o({error:i(e)}):u===this.#t&&this.#a(e=>({messages:[...e.messages,{role:`assistant`,text:``,sources:[],idQuery:null,error:null,rating:null,interrupted:!0}]}))}finally{this.#n===d&&(this.#n=null),u===this.#t&&this.#o({turn:null})}}stop(){this.#n?.abort()}async rate(e,t){let{activeId:n}=this.#e;if(!n)return;let r=t=>this.#a(n=>({messages:n.messages.map(n=>n.role===`assistant`&&n.idQuery===e?{...n,rating:t}:n)})),a=this.#e.messages.find(t=>t.role===`assistant`&&t.idQuery===e);r(t);try{await this.client.sendFeedback(n,e,t)}catch(e){r(a?.role===`assistant`?a.rating:null),this.#o({error:i(e)})}}dismissError(){this.#o({error:null})}dispose(){this.#n?.abort(),this.#t++}},Nr={locale:`it-IT`,conversations:`Conversazioni`,newConversation:`Nuova conversazione`,noConversations:`Ancora nessuna conversazione.`,conversationsFailed:`Impossibile leggere le conversazioni.`,loading:`Caricamento…`,untitled:`Senza titolo`,disabled:`disabilitata`,renameConversation:e=>`Rinomina «${e}»`,newTitle:`Nuovo titolo`,save:`Salva`,cancel:`Annulla`,deleteConversation:e=>`Elimina «${e}»`,confirmDelete:e=>`Eliminare la conversazione «${e}»?`,confirmDeleteShort:`Elimina?`,ask:e=>`Chiedi a ${e}`,askGeneric:`Come posso esserti utile?`,noAgent:`Nessun agente indicato.`,notConnected:`Chat non configurata.`,placeholder:`Scrivi un messaggio`,send:`Invia`,stop:`Interrompi`,attach:`Allega documenti`,removeFile:e=>`Rimuovi ${e}`,processing:`in elaborazione`,fileError:`errore`,thinking:`Sto pensando…`,loadingHistory:`Carico la conversazione…`,copy:`Copia`,copied:`Copiato`,rateUp:`Risposta utile`,rateDown:`Risposta non utile`,sources:e=>e===1?`1 fonte`:`${e} fonti`,page:e=>`p. ${e}`,part:e=>`parte ${e}`,untitledSource:`Fonte senza titolo`,interrupted:`Risposta interrotta.`,turnFailed:`L'agente non è riuscito a rispondere.`,trace:e=>`Traccia ${e}`,disclaimer:`Le risposte sono generate da un'intelligenza artificiale e possono contenere errori: verifica sempre le informazioni.`,dismiss:`Chiudi`,you:`Tu`,agent:`Agente`,errors:{auth_required:`Accesso scaduto o non valido: rientra nell'applicazione.`,tenant_refused:`Il tuo account non può usare l'agente in questo spazio di lavoro.`,forbidden:`Non puoi usare questo agente.`,not_found:`Agente o conversazione non trovati.`,busy:`L'agente sta ancora rispondendo, oppure non è pubblicato. Riprova tra poco.`,locked:`Questa conversazione è disabilitata.`,rate_limited:`Troppe richieste.`,network:`Servizio non raggiungibile.`,http:`Errore del servizio.`},retryIn:e=>`Riprova tra ${e} s.`,developer:`Sviluppatore`,requests:`Richieste`,events:e=>`Eventi dell'ultimo turno · ${e} token`,lastError:`Ultimo errore`,renewed:`token rinnovato`,publishedVersion:`Versione pubblicata`,notPublished:`non pubblicato`,conversation:`Conversazione`,context:`Contesto del turno`,none:`—`},Pr={locale:`en-GB`,conversations:`Conversations`,newConversation:`New conversation`,noConversations:`No conversations yet.`,conversationsFailed:`Could not read the conversations.`,loading:`Loading…`,untitled:`Untitled`,disabled:`disabled`,renameConversation:e=>`Rename “${e}”`,newTitle:`New title`,save:`Save`,cancel:`Cancel`,deleteConversation:e=>`Delete “${e}”`,confirmDelete:e=>`Delete the conversation “${e}”?`,confirmDeleteShort:`Delete?`,ask:e=>`Ask ${e}`,askGeneric:`How can I help?`,noAgent:`No agent set.`,notConnected:`Chat not configured.`,placeholder:`Write a message`,send:`Send`,stop:`Stop`,attach:`Attach documents`,removeFile:e=>`Remove ${e}`,processing:`processing`,fileError:`error`,thinking:`Thinking…`,loadingHistory:`Loading the conversation…`,copy:`Copy`,copied:`Copied`,rateUp:`Helpful answer`,rateDown:`Unhelpful answer`,sources:e=>e===1?`1 source`:`${e} sources`,page:e=>`p. ${e}`,part:e=>`part ${e}`,untitledSource:`Untitled source`,interrupted:`Answer stopped.`,turnFailed:`The agent could not answer.`,trace:e=>`Trace ${e}`,disclaimer:`Answers are generated by AI and may contain mistakes: always check the information.`,dismiss:`Dismiss`,you:`You`,agent:`Agent`,errors:{auth_required:`Your sign-in expired or is invalid: sign in again.`,tenant_refused:`Your account cannot use the agent in this workspace.`,forbidden:`You cannot use this agent.`,not_found:`Agent or conversation not found.`,busy:`The agent is still answering, or it is not published. Try again shortly.`,locked:`This conversation is disabled.`,rate_limited:`Too many requests.`,network:`Service unreachable.`,http:`Service error.`},retryIn:e=>`Try again in ${e} s.`,developer:`Developer`,requests:`Requests`,events:e=>`Events of the last turn · ${e} tokens`,lastError:`Last error`,renewed:`token renewed`,publishedVersion:`Published version`,notPublished:`not published`,conversation:`Conversation`,context:`Turn context`,none:`—`};function Fr(e){let t=e?.trim().toLowerCase()??``;return t===``||t.startsWith(`it`)?Nr:Pr}function Ir(e,t){let n=Fr(e);return t?{...n,...t,errors:{...n.errors,...t.errors}}:n}var Lr={add:`M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z`,delete:`M16 9v10H8V9h8m-1.5-6h-5l-1 1H5v2h14V4h-3.5l-1-1zM18 7H6v12c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7z`,send:`M2.01 21 23 12 2.01 3 2 10l15 2-15 2z`,stop:`M6 6h12v12H6z`,attach:`M16.5 6v11.5c0 2.21-1.79 4-4 4s-4-1.79-4-4V5c0-1.38 1.12-2.5 2.5-2.5s2.5 1.12 2.5 2.5v10.5c0 .55-.45 1-1 1s-1-.45-1-1V6H10v9.5c0 1.38 1.12 2.5 2.5 2.5s2.5-1.12 2.5-2.5V5c0-2.21-1.79-4-4-4S7 2.79 7 5v12.5c0 3.04 2.46 5.5 5.5 5.5s5.5-2.46 5.5-5.5V6h-1.5z`,copy:`M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z`,check:`M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`,thumbUp:`M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.58 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h4v12H1z`,thumbDown:`M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L9.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h4v12h-4z`,close:`M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z`,menu:`M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z`,edit:`M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z`},Rr=`http://www.w3.org/2000/svg`;function zr(e){let t=document.createElementNS(Rr,`svg`);t.setAttribute(`viewBox`,`0 0 24 24`),t.setAttribute(`aria-hidden`,`true`),t.setAttribute(`focusable`,`false`);let n=document.createElementNS(Rr,`path`);return n.setAttribute(`d`,Lr[e]),n.setAttribute(`fill`,`currentColor`),t.append(n),t}var Br=`
77
+ `}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>${L(e,!0)}</code>`}br(e){return`<br>`}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,text:n,tokens:r,autolink:i}){let a=i?L(n,!0):this.parser.parseInline(r),o=kt(e);if(o===null)return a;e=L(o,i);let s=`<a href="`+e+`"`;return t&&(s+=` title="`+L(t)+`"`),s+=`>`+a+`</a>`,s}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(Yt(r),this.parser.textRenderer));let i=kt(e);if(i===null)return L(n);e=i;let a=`<img src="${L(e)}" alt="${L(n)}"`;return t&&(a+=` title="${L(t)}"`),a+=`>`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:L(e.text)}},Zt=class{parser;strong({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}em({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}codespan({text:e}){return e}del({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}html({text:e}){return e}text({text:e}){return e}link({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}image({text:e,tokens:t}){return t?this.parser.parseInline(t,this):e}br(){return`
78
+ `}checkbox({raw:e}){return e}},B=class e{options;renderer;textRenderer;constructor(e){this.options=e||ce,this.options.renderer=this.options.renderer||new Xt,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Zt,this.textRenderer.parser=this}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],i=this.options.extensions?.renderers;if(i&&Object.hasOwn(i,r.type)&&i[r.type]){let e=r,n=i[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===!1?``:n??``;continue}}let a=r;switch(a.type){case`space`:t+=this.renderer.space(a);break;case`hr`:t+=this.renderer.hr(a);break;case`heading`:t+=this.renderer.heading(a);break;case`code`:t+=this.renderer.code(a);break;case`table`:t+=this.renderer.table(a);break;case`blockquote`:t+=this.renderer.blockquote(a);break;case`list`:t+=this.renderer.list(a);break;case`checkbox`:t+=this.renderer.checkbox(a);break;case`html`:t+=this.renderer.html(a);break;case`def`:t+=this.renderer.def(a);break;case`paragraph`:t+=this.renderer.paragraph(a);break;case`text`:t+=this.renderer.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 t}parseInline(e,t=this.renderer){this.renderer.parser=this;let n=``;for(let r=0;r<e.length;r++){let i=e[r],a=this.options.extensions?.renderers;if(a&&Object.hasOwn(a,i.type)&&a[i.type]){let e=a[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===!1?``:e??``;continue}}let o=i;switch(o.type){case`escape`:n+=t.text(o);break;case`html`:n+=t.html(o);break;case`link`:n+=t.link(o);break;case`image`:n+=t.image(o);break;case`checkbox`:n+=t.checkbox(o);break;case`strong`:n+=t.strong(o);break;case`em`:n+=t.em(o);break;case`codespan`:n+=t.codespan(o);break;case`br`:n+=t.br(o);break;case`del`:n+=t.del(o);break;case`text`:n+=t.text(o);break;default:{let e=`Token with "`+o.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}},Qt=class{options;block;constructor(e){this.options=e||ce}static passThroughHooks=/* @__PURE__ */ new Set([`preprocess`,`postprocess`,`processAllTokens`,`emStrongMask`]);static passThroughHooksRespectAsync=/* @__PURE__ */ 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?z.lex:z.lexInline}provideParser(e=this.block){return e?B.parse:B.parseInline}};function $t(e,t){if(Array.isArray(t))for(let n=0;n<t.length;n++)e.push(t[n]);else e.push(t)}var en=class{defaults=se();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=B;Renderer=Xt;TextRenderer=Zt;Lexer=z;Tokenizer=Jt;Hooks=Qt;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch($t(n,t.call(this,r)),r.type){case`table`:{let e=r;for(let r of e.header)$t(n,this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)$t(n,this.walkTokens(e.tokens,t));break}case`list`:{let e=r;$t(n,this.walkTokens(e.items,t));break}default:{let e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(r=>{if(e[r]){let i=e[r].flat(1/0);$t(n,this.walkTokens(i,t))}}):e.tokens&&$t(n,this.walkTokens(e.tokens,t))}}return n}use(...e){let t=this.defaults.extensions||{renderers:Object.create(null),childTokens:Object.create(null)};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 Xt(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===!1?``:n??``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new Jt(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 Qt;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]=Qt.passThroughHooks.has(n)?e=>{if(t.options.async&&Qt.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(t.options.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 $t(n,r.call(this,e)),t&&$t(n,t.call(this,e)),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return z.lex(e,t??this.defaults)}parser(e,t){return B.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(/* @__PURE__ */ 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(/* @__PURE__ */ Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(/* @__PURE__ */ 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?z.lex:z.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?B.parse:B.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?z.lex:z.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?B.parse:B.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+=`
79
+ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+L(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}},tn=new en;function V(e,t){return tn.parse(e,t)}V.options=V.setOptions=function(e){return tn.setOptions(e),V.defaults=tn.defaults,le(V.defaults),V},V.getDefaults=se,V.defaults=ce;function nn(...e){return tn.use(...e),V.defaults=tn.defaults,le(V.defaults),V}V.use=nn,V.walkTokens=function(e,t){return tn.walkTokens(e,t)},V.parseInline=tn.parseInline,V.Parser=B,V.parser=B.parse,V.Renderer=Xt,V.TextRenderer=Zt,V.Lexer=z,V.lexer=z.lex,V.Tokenizer=Jt,V.Hooks=Qt,V.parse=V,V.options,V.setOptions,V.walkTokens,V.parseInline,B.parse,z.lex;function rn(e){let t=e.classList;return t.contains(`language-mermaid`)?`mermaid`:t.contains(`language-vega-lite`)||t.contains(`language-vegalite`)?`vega`:t.contains(`language-a2ui`)?`a2ui`:null}function an(e){let t=null,n=null;return{get:()=>t,load:()=>n??=e().then(e=>t=e,e=>{throw n=null,e})}}var on=an(()=>import(`./bundle/math-Cx-Q-b8s.js`)),sn={mermaid:an(()=>import(`./bundle/mermaid-DaDuEHir.js`).then(e=>e.t)),vega:an(()=>import(`./bundle/vega-eBn1AexV.js`)),a2ui:an(()=>import(`./bundle/a2ui-C3GhjTrJ.js`))},cn=`rich-drawing`,ln=/* @__PURE__ */ new WeakMap,un=/* @__PURE__ */ new WeakMap,dn=/* @__PURE__ */ new WeakMap;function fn(e,t){for(let n of e.querySelectorAll(`.${cn}`))dn.get(n)?.(t)}function pn(e){for(let t of e.querySelectorAll(`.${cn}`))un.get(t)?.()}function mn(e){let t=/* @__PURE__ */ new Map;for(let n of e.querySelectorAll(`.${cn}`)){let e=ln.get(n);if(e===void 0)continue;let r=t.get(e);r?r.push(n):t.set(e,[n])}return t}function hn(e){let t=getComputedStyle(e.host);return{host:e.host,root:e.host.shadowRoot??document,dark:_n(t.color),font:t.fontFamily,lang:e.lang,live:e.live??!1,strings:e.strings,interface:e.interface}}function gn(e){let t=/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/.exec(e);if(t)return[Number(t[1]),Number(t[2]),Number(t[3])];try{let t=document.createElement(`canvas`);t.width=t.height=1;let n=t.getContext(`2d`,{willReadFrequently:!0});if(!n)return null;n.fillStyle=e,n.fillRect(0,0,1,1);let[r=0,i=0,a=0]=n.getImageData(0,0,1,1).data;return[r,i,a]}catch{return null}}function _n(e){let[t,n,r]=gn(e)??[0,0,0];return .2126*t+.7152*n+.0722*r>140}function vn(e,t,n=/* @__PURE__ */ new Map){if(e.querySelector(`.math-inline, .math-display`)){let n=()=>{on.get()?.renderFormulas(e,t.host)};on.get()?n():on.load().then(n,()=>void 0)}if(t.widgets){let r=null;for(let i of e.querySelectorAll(`pre > code`)){let e=rn(i),a=i.parentElement;if(!e||!a||t.live&&e!==`a2ui`&&a.hasAttribute(`data-open`))continue;let o=(i.textContent??``).replace(/\n$/,``);r??=hn(t);let s=`${e}\n${r.dark}\n${o}`,c=n.get(s)?.shift();if(c){a.replaceWith(c);continue}let l=sn[e],u=l.get(),d=r;u?yn(a,u.draw(o,d),s):l.load().then(e=>{a.parentNode&&yn(a,e.draw(o,d),s)},()=>void 0)}}for(let e of n.values())for(let t of e)un.get(t)?.()}function yn(e,t,n){let r=t=>{!t||!e.parentNode?t&&un.get(t)?.():(t.classList.add(cn),ln.set(t,n),e.replaceWith(t))};t instanceof Promise?t.then(r,()=>void 0):r(t)}function bn(e,t){this.v=e,this.k=t}function xn(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 Sn(e){if(Array.isArray(e))return e}function Cn(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){if(Object(n)!==n)return;c=!1}else 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 wn(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
80
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Tn(e,t){return Sn(e)||Cn(e,t)||En(e,t)||wn()}function En(e,t){if(e){if(typeof e==`string`)return xn(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)?xn(e,t):void 0}}function Dn(e){var t,n;function r(t,n){try{var a=e[t](n),o=a.value,s=o instanceof bn;Promise.resolve(s?o.v:o).then(function(n){if(s){var c=t===`return`&&o.k?t:`next`;if(!o.k||n.done)return r(c,n);n=e[c](n).value}i(!!a.done,n)},function(e){r(`throw`,e)})}catch(e){i(2,e)}}function i(e,i){e===2?t.reject(i):t.resolve({value:i,done:e}),(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,i){return new Promise(function(a,o){var s={key:e,arg:i,resolve:a,reject:o,next:null};n?n=n.next=s:(t=n=s,r(e,i))})},typeof e.return!=`function`&&(this.return=void 0)}Dn.prototype[typeof Symbol==`function`&&Symbol.asyncIterator||`@@asyncIterator`]=function(){return this},Dn.prototype.next=function(e){return this._invoke(`next`,e)},Dn.prototype.throw=function(e){return this._invoke(`throw`,e)},Dn.prototype.return=function(e){return this._invoke(`return`,e)};var On=Object.entries,kn=Object.keys,An=Object.setPrototypeOf,jn=Object.isFrozen,Mn=Object.getPrototypeOf,Nn=Object.getOwnPropertyDescriptor,H=Object.freeze,U=Object.seal,Pn=Object.create,Fn=typeof Reflect<`u`&&Reflect,In=Fn.apply,Ln=Fn.construct;H||=function(e){return e},U||=function(e){return e},In||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},Ln||=function(e){return new e(...[...arguments].slice(1))};var W=J(Array.prototype.forEach),Rn=J(Array.prototype.lastIndexOf),zn=J(Array.prototype.pop),Bn=J(Array.prototype.push),Vn=J(Array.prototype.slice),Hn=J(Array.prototype.splice),Un=Array.isArray,Wn=lr(Set),Gn=J(Set.prototype.add),Kn=J(Set.prototype.has),qn=J(Set.prototype.delete),Jn=lr(Map),Yn=J(Map.prototype.get),Xn=J(Map.prototype.set),Zn=J(String.prototype.toLowerCase),Qn=J(String.prototype.toString),$n=J(String.prototype.match),er=J(String.prototype.replace),tr=J(String.prototype.indexOf),nr=J(String.prototype.trim),rr=J(Number.prototype.toString),ir=J(Boolean.prototype.toString),ar=typeof BigInt>`u`?null:J(BigInt.prototype.toString),or=typeof Symbol>`u`?null:J(Symbol.prototype.toString),G=J(Object.prototype.hasOwnProperty),sr=J(Object.prototype.toString),cr=RegExp.prototype.test,K=function(e,t){return e instanceof RegExp&&(e.lastIndex=0),In(cr,e,[t])},q=lr(TypeError);function J(e){return function(t){var n=[...arguments].slice(1);return In(e,t,n)}}function lr(e){return function(){return Ln(e,[...arguments])}}function Y(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Zn;if(An&&An(e,null),!Un(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(jn(t)||(t[r]=e),i=e)}e[i]=!0}return e}function ur(e){for(let t=0;t<e.length;t++)G(e,t)||(e[t]=null);return e}function dr(e){let t=Pn(null);for(let r of On(e)){var n=Tn(r,2);let i=n[0],a=n[1];G(e,i)&&(t[i]=Un(a)?ur(a):a&&typeof a==`object`&&a.constructor===Object?dr(a):a)}return t}function fr(e){let t=Pn(null),n=kn(e),r=n.length;for(;r--;)t[n[r]]=e[n[r]];return t}function pr(e){switch(typeof e){case`string`:return e;case`number`:return rr(e);case`boolean`:return ir(e);case`bigint`:return ar?ar(e):`0`;case`symbol`:return or?or(e):`Symbol()`;case`undefined`:return sr(e);case`function`:case`object`:{if(e===null)return sr(e);let t=e,n=X(t,`toString`);if(typeof n==`function`){let e=n(t);return typeof e==`string`?e:sr(e)}return sr(e)}default:return sr(e)}}function X(e,t){for(;e!==null;){let n=Nn(e,t);if(n){if(n.get)return J(n.get);if(typeof n.value==`function`)return J(n.value)}e=Mn(e)}function n(){return null}return n}function mr(e,t){for(;e!==null;){let n=Nn(e,t);if(n)return n.get?J(n.get):null;e=Mn(e)}return null}function hr(e){if(!e)return!1;try{return K(e,``),!0}catch{return!1}}var gr=H(/* @__PURE__ */ `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(`.`)),_r=H(/* @__PURE__ */ `svg.a.altglyph.altglyphdef.altglyphitem.animatecolor.animatemotion.animatetransform.circle.clippath.defs.desc.ellipse.filter.font.g.glyph.glyphref.hkern.image.line.lineargradient.marker.mask.metadata.mpath.path.pattern.polygon.polyline.radialgradient.rect.stop.style.switch.symbol.text.textpath.title.tref.tspan.view.vkern`.split(`.`)),vr=H([`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`]),yr=H([`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`]),br=H(/* @__PURE__ */ `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(`.`)),xr=H([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),Sr=H([`#text`]),Cr=H(/* @__PURE__ */ `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(`.`)),wr=H(/* @__PURE__ */ `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(`.`)),Tr=H(/* @__PURE__ */ `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(`.`)),Er=H([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),Dr=U(/{{[\w\W]*|^[\w\W]*}}/g),Or=U(/<%[\w\W]*|^[\w\W]*%>/g),kr=U(/\${[\w\W]*/g),Ar=U(/{{|}}|\${|<%|%>/),jr=U(/[^\t\n\f\r ]/),Mr=U(/\u0000/g),Nr=U(/^data-[\-\w.\u00B7-\uFFFF]+$/),Pr=U(/^aria-[\-\w]+$/),Fr=U(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Ir=U(/^(?:\w+script|data):/i),Lr=U(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Rr=U(/^html$/i),zr=U(/^[a-z][.\w]*(-[.\w]+)+$/i),Br=U(/<[/\w!]/g),Vr=U(/<[/\w]/g),Hr=U(/<[/\w]|^-?>|--!?>|<!-$/g),Ur=U(/<\/no(script|embed|frames)/i),Wr=U(/\/>/i),Gr=U(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i),Kr=U(/^[\r\n\t ]+/),Z={element:1,text:3,processingInstruction:7,comment:8,document:9,documentFragment:11},qr=H(Y({},[`style`,`script`,`xmp`,`iframe`,`noembed`,`noframes`,`plaintext`,`noscript`])),Jr=H(Y({},[`textarea`,`title`])),Yr=H(Y({},[`area`,`base`,`basefont`,`bgsound`,`br`,`col`,`embed`,`frame`,`hr`,`img`,`input`,`keygen`,`link`,`meta`,`param`,`source`,`track`,`wbr`])),Xr=function(){return typeof window>`u`?null:window},Zr=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}},Qr=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},$r=function(e,t,n,r){return G(e,t)&&Un(e[t])?Y(r.base?fr(r.base):{},e[t],r.transform):n},ei=function(e,t,n){let r=G(e,t)?e[t]:void 0;return r&&typeof r==`object`?dr(r):n};function ti(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Xr(),t=e=>ti(e);if(t.version=`3.5.0`,t.removed=[],!e||!e.document||e.document.nodeType!==Z.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript,a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter,l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=X(d,`cloneNode`),p=X(d,`remove`),m=X(d,`removeChild`),h=X(d,`removeAttributeNode`),ee=X(d,`nextSibling`),g=X(d,`childNodes`),_=X(d,`parentNode`),te=X(d,`shadowRoot`),ne=X(d,`attributes`),v=o&&o.prototype?X(o.prototype,`nodeType`):null,y=o&&o.prototype?X(o.prototype,`nodeName`):null,re=o&&o.prototype?X(o.prototype,`ownerDocument`):null,b=function(e){return v?v(e):e.nodeType},x=function(e){return y?y(e):e.nodeName},ie=mr(d,`namespaceURI`),ae=function(e){return ie?ie(e):e.namespaceURI},oe=function(e){return b(e)===Z.element?ne(e):null};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let S,C=``,se,ce=!1,le=0,w=function(){if(le>0)throw q(`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.`)},T=function(e){w(),le++;try{return S.createHTML(e)}finally{le--}},E=function(e){return S&&Ve?T(e):e},ue=function(e){w(),le++;try{return S.createScriptURL(e)}finally{le--}},de=function(){return ce||=(se=Zr(u,i),!0),se},D=n,fe=D.implementation,pe=D.createNodeIterator,me=D.createDocumentFragment,he=D.getElementsByTagName,ge=r.importNode,O=Qr();t.isSupported=typeof On==`function`&&typeof _==`function`&&fe&&fe.createHTMLDocument!==void 0;let _e=Dr,ve=Or,ye=kr,be=Nr,xe=Pr,Se=Ir,Ce=Lr,we=zr,Te=Fr,k=null,Ee=Y({},[...gr,..._r,...vr,...br,...Sr]),A=null,De=Y({},[...Cr,...wr,...Tr,...Er]),j=null,Oe=null,ke=null,M=Object.seal(Pn(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Ae=!0,je=!0,Me=!1,Ne=!0,N=!1,Pe=!0,Fe=!1,P=!1,Ie=null,Le=null,Re=!1,ze=!1,Be=!1,Ve=!1,He=!0,Ue=!1,We=`user-content-`,Ge=!0,Ke=!1,qe=null,Je=null,Ye=!1,Xe=null,Ze=Y({},/* @__PURE__ */ `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(`.`)),Qe=null,$e=Y({},[`audio`,`video`,`img`,`source`,`image`,`track`]),et=null,tt=Y({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),nt=`http://www.w3.org/1998/Math/MathML`,rt=`http://www.w3.org/2000/svg`,F=`http://www.w3.org/1999/xhtml`,it=F,at=!1,ot=null,st=Y({},[nt,rt,F],Qn),ct=H(Y({},[`mi`,`mo`,`mn`,`ms`,`mtext`])),lt=null,ut=H(Y({},[`annotation-xml`])),dt=null,ft=H(Pn(null)),pt=Y({},[`title`,`style`,`font`,`a`,`script`]),mt=null,ht=[`application/xhtml+xml`,`text/html`],I=null,gt=null,_t=null,vt=n.createElement(`form`),yt=function(e){return e instanceof RegExp||e instanceof Function},bt=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};e&&typeof e==`object`||(e={}),e=dr(e),mt=ht.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,I=mt===`application/xhtml+xml`?Qn:Zn,k=$r(e,`ALLOWED_TAGS`,Ee,{transform:I}),A=$r(e,`ALLOWED_ATTR`,De,{transform:I}),ot=$r(e,`ALLOWED_NAMESPACES`,st,{transform:Qn}),et=$r(e,`ADD_URI_SAFE_ATTR`,tt,{transform:I,base:tt}),Qe=$r(e,`ADD_DATA_URI_TAGS`,$e,{transform:I,base:$e}),Xe=$r(e,`FORBID_CONTENTS`,Ze,{transform:I}),Oe=$r(e,`FORBID_TAGS`,Pn(null),{transform:I}),ke=$r(e,`FORBID_ATTR`,Pn(null),{transform:I}),Ye=G(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?dr(e.USE_PROFILES):e.USE_PROFILES:!1,Ae=e.ALLOW_ARIA_ATTR!==!1,je=e.ALLOW_DATA_ATTR!==!1,Me=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Ne=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,N=e.SAFE_FOR_TEMPLATES||!1,Pe=e.SAFE_FOR_XML!==!1,Fe=e.WHOLE_DOCUMENT||!1,ze=e.RETURN_DOM||!1,Be=e.RETURN_DOM_FRAGMENT||!1,Ve=e.RETURN_TRUSTED_TYPE||!1,Re=e.FORCE_BODY||!1,He=e.SANITIZE_DOM!==!1,Ue=e.SANITIZE_NAMED_PROPS||!1,Ge=e.KEEP_CONTENT!==!1,Ke=e.IN_PLACE||!1,Te=hr(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:Fr,it=typeof e.NAMESPACE==`string`?e.NAMESPACE:F,lt=ei(e,`MATHML_TEXT_INTEGRATION_POINTS`,ct),dt=ei(e,`HTML_INTEGRATION_POINTS`,ut);let t=ei(e,`CUSTOM_ELEMENT_HANDLING`,ft);if(j=Pn(null),G(t,`tagNameCheck`)&&yt(t.tagNameCheck)&&(j.tagNameCheck=t.tagNameCheck),G(t,`attributeNameCheck`)&&yt(t.attributeNameCheck)&&(j.attributeNameCheck=t.attributeNameCheck),G(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(j.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),U(j),N&&(je=!1),Be&&(ze=!0),Ye&&((G(e,`ALLOWED_TAGS`)||G(e,`ALLOWED_ATTR`))&&typeof console<`u`&&typeof console.warn==`function`&&console.warn(`DOMPurify: USE_PROFILES overrides ALLOWED_TAGS and ALLOWED_ATTR. Do not use these options together.`),k=Y({},Sr),A=Pn(null),Ye.html===!0&&(Y(k,gr),Y(A,Cr)),Ye.svg===!0&&(Y(k,_r),Y(A,wr),Y(A,Er)),Ye.svgFilters===!0&&(Y(k,vr),Y(A,wr),Y(A,Er)),Ye.mathMl===!0&&(Y(k,br),Y(A,Tr),Y(A,Er))),M.tagCheck=null,M.attributeCheck=null,G(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?M.tagCheck=e.ADD_TAGS:Un(e.ADD_TAGS)&&(k===Ee&&(k=fr(k)),Y(k,e.ADD_TAGS,I))),G(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?M.attributeCheck=e.ADD_ATTR:Un(e.ADD_ATTR)&&(A===De&&(A=fr(A)),Y(A,e.ADD_ATTR,I))),G(e,`ADD_FORBID_CONTENTS`)&&Un(e.ADD_FORBID_CONTENTS)&&(Xe===Ze&&(Xe=fr(Xe)),Y(Xe,e.ADD_FORBID_CONTENTS,I)),Ge&&(k[`#text`]=!0),Fe&&Y(k,[`html`,`head`,`body`]),k.table&&(k.tbody=!0,delete Oe.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw q(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw q(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=S;S=e.TRUSTED_TYPES_POLICY;try{C=T(``)}catch(e){throw S=t,e}}else e.TRUSTED_TYPES_POLICY===null?(S=void 0,C=``):(S===void 0&&(S=de()),S&&typeof C==`string`&&(C=T(``)));gt=H(e)},xt=Y({},[..._r,...vr,...yr]),St=Y({},[...br,...xr]),Ct=function(e,t,n){return t===F?e===`svg`:t===nt?e===`svg`&&(n===`annotation-xml`||lt[n]):!!xt[e]},wt=function(e,t,n){return t===F?e===`math`:t===rt?e===`math`&&dt[n]:!!St[e]},Tt=function(e,t,n){return t===rt&&!dt[n]||t===nt&&!lt[n]?!1:!St[e]&&(pt[e]||!xt[e])},Et=function(e){let t=ae(e),n=Zn(x(e)),r=_(e),i=it,a=`template`;return r&&b(r)===Z.element&&(i=ae(r),a=Zn(x(r))),ot[t]?t===rt?Ct(n,i,a):t===nt?wt(n,i,a):t===F?Tt(n,i,a):mt===`application/xhtml+xml`:!1},Dt=function(e){Bn(t.removed,{element:e}),zt(e);try{_(e).removeChild(e)}catch{if(p(e),!_(e))throw q(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},L=function(e,t,n){try{h(e,t)}catch{try{e.removeAttribute(n)}catch{}}},Ot=function(e){jt(e);let t=g(e);t&&W(Vn(t),t=>{try{m(e,t)}catch{}}),b(e)===Z.element&&At(e,!1)},kt=function(e,n,r){if(!r)try{r=n.getAttributeNode(e)}catch{r=null}if(Bn(t.removed,{attribute:r||null,from:n}),r)L(n,r,e);else try{n.removeAttribute(e)}catch{}if(e===`is`){if(ze||Be)try{Dt(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},At=function(e,t){let n=ne(e);if(n)for(let r=n.length-1;r>=0;--r){let i=n[r],a=i&&i.name;typeof a==`string`&&!(t&&A[I(a)])&&L(e,i,a)}},R=function(e,t){let n=arguments.length>2&&arguments[2]!==void 0&&arguments[2],r=[e];for(;r.length>0;){let e=r.pop();if(t(e)===!1)continue;if(n&&b(e)===Z.element){let t=te(e);Xt(t)&&r.push(t)}let i=g(e);if(i)for(let e=i.length-1;e>=0;--e)r.push(i[e])}},jt=function(e){R(e,e=>{b(e)===Z.element&&At(e,!0)})},Mt=function(e){let t=[];return R(e,e=>{t.push(e)},!0),t},Nt=function(e,t){let n=Wn();W(Mt(e),e=>{b(e)===Z.element&&Gn(n,e)}),W(t,e=>{b(e)===Z.element&&!Kn(n,e)&&At(e,!0)})},Pt=function(e,n){let r=!1;return W(t.removed,t=>{t.element&&(r||=t.element===e,jt(t.element))}),Nt(e,n),r},Ft=function(e,t){Ot(e),Pt(e,t)},It=function(e,t){let n=qe,r=null,i=()=>(r||(r=Wn(),W(t,e=>{Gn(r,e)})),r);for(let t=0;;t++){let r=Mt(e),a=[e],o=!1;if(W(r,e=>{b(e)===Z.documentFragment?Bn(a,e):!o&&!Kn(n,e)&&(o=Kn(i(),e))}),!o)return;if(t>=8)throw q(`the tree kept changing during in-place sanitization; refusing to return it`);W(a,(t,n)=>{Lt(t,n>0,e,i())})}},Lt=function(e,t,n,r){let i=Ut(e),a;for(;a=i.nextNode();)Kn(r,a)&&!Kn(qe,a)&&(t&&B(O.uponSanitizeShadowNode,a,null),fn(a,n))},Rt=function(e){if(!qe)return;Gn(qe,e);let t=Yn(Je,e);if(t!==void 0){if(t>=8)throw q(`the tree kept changing during in-place sanitization; refusing to return it`);Xn(Je,e,t+1)}},zt=function(e){qe&&(qn(qe,e),Yn(Je,e)===void 0&&Xn(Je,e,0))},Bt=function(e,t){return Pe?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},Vt=function(e){Pe&&R(e,e=>{let t=b(e);if(t===Z.processingInstruction||t===Z.comment&&K(Vr,e.data)){try{p(e)}catch{}return!1}if(t===Z.element){let t=e,n=I(x(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&Bt(`for`,n)&&t.removeAttribute(`for`)}catch{}}return!0})},Ht=function(e){let t=null,r=null;if(Re)e=`<remove></remove>`+e;else{let t=$n(e,Kr);r=t&&t[0]}mt===`application/xhtml+xml`&&it===F&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=S?T(e):e;if(it===F)try{t=new l().parseFromString(i,mt)}catch{}if(!t||!t.documentElement){t=fe.createDocument(it,`template`,null);try{t.documentElement.innerHTML=at?C:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),it===F?he.call(t,Fe?`html`:`body`)[0]:Fe?t.documentElement:a},Ut=function(e){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1],n=re?re(e):e.ownerDocument;return pe.call(n||e,e,(t?0:c.SHOW_ELEMENT)|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},Wt=function(e){return e=er(e,_e,` `),e=er(e,ve,` `),e=er(e,ye,` `),e},Gt=function(e){Jt(e);let t=e.querySelectorAll?.call(e,`template`);t&&W(t,e=>{Xt(e.content)&&Gt(e.content)})},Kt=Y({},[`caption`,`colgroup`,`col`,`thead`,`tbody`,`tfoot`,`tr`,`td`,`th`,`style`,`script`,`template`]),qt=function(e){if(mt===`application/xhtml+xml`)return;let t=e.querySelectorAll?.call(e,`table,tbody,thead,tfoot,tr,colgroup`);t&&t.length!==0&&W(t,t=>{W(Vn(g(t)),n=>{let r=b(n);if(!(r===Z.text?K(jr,n.data):r===Z.element&&!Kt[Zn(x(n))]))return;let i=t;for(;i&&Zn(x(i))!==`table`;)i=i===e?null:_(i);let a=i&&i!==e?_(i):null;if(a)try{a.insertBefore(n,i)}catch{}})})},Jt=function(e){qt(e),e.normalize();let t=Ut(e,!0),n=null,r=t.nextNode();for(;r;){let e=r.data;if(K(Mr,e)&&(e=er(e,Mr,``),r.data=e),K(Ar,e)&&(e=Wt(e),r.data=e),e&&b(r)===Z.text){if(n){let t=n.data;K(Ar,t[t.length-1]+e[0])&&(n.data=Wt(t+e[0]))}n=r}r=t.nextNode()}},z=function(e){let t=y?y(e):null;return typeof t!=`string`||I(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==ne(e)||typeof e.removeAttribute!=`function`||typeof e.removeAttributeNode!=`function`||typeof e.getAttributeNode!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==v(e)||e.childNodes!==g(e)},Yt=function(e){if(!v||typeof e!=`object`||!e)return null;try{let t=v(e);return typeof t==`number`?t:null}catch{return null}},Xt=function(e){return Yt(e)===Z.documentFragment},Zt=function(e){return Yt(e)!==null};function B(e,n,r){e.length!==0&&W(e,e=>{e.call(t,n,r,gt)})}let Qt=function(e,t){let n=!!Yr[t],r=!!qr[t];return!n&&!r&&!Jr[t]||ae(e)!==F?!1:n?e.hasChildNodes():Zt(e.firstElementChild)?!0:r&&typeof e.textContent==`string`&&K(Br,e.textContent)},$t=function(e,t,n){return!!(Pe&&n===Z.element&&e.hasChildNodes()&&!Zt(e.firstElementChild)&&K(Br,e.textContent)&&K(Br,e.innerHTML)||Pe&&n===Z.element&&Qt(e,t)||n===Z.processingInstruction||Pe&&n===Z.comment&&K(Hr,e.data))},en=function(e,t){return e instanceof RegExp?K(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},tn=function(e,t,n){if(!Oe[t]&&sn(t)&&en(j.tagNameCheck,t))return!1;if(Ge&&!Xe[t]&&!Xe[Zn(t)]){let t=_(e),r=g(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,ee(e))}}}return Dt(e),!0},V=function(e,t,n,r){return e.length===0?t:t===n||t===r?fr(t):t},nn=function(e,t){return e===t||_(e)!==null?!1:(Ke&&jt(e),zt(e),!0)},rn=function(e,n){if(Rt(e),B(O.beforeSanitizeElements,e,null),nn(e,n))return!0;if(z(e))return Dt(e),!0;let r=I(x(e)),i=b(e);if(k=V(O.uponSanitizeElement,k,Ee,Ie),B(O.uponSanitizeElement,e,{tagName:r,allowedTags:k}),nn(e,n))return!0;if($t(e,r,i))return Dt(e),!0;if((Oe[r]||!(M.tagCheck instanceof Function&&M.tagCheck(r))&&!k[r])&&tn(e,r,n))return!0;if(i===Z.element&&!Et(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&K(Ur,e.innerHTML))return Dt(e),!0;if(N&&i===Z.text){let n=e.textContent,r=Wt(n);n!==r&&(Bn(t.removed,{element:e.cloneNode()}),e.textContent=r)}return B(O.afterSanitizeElements,e,null),nn(e,n)},an=function(e,t,r){if(ke[t]||Bt(t,e)||He&&(t===`id`||t===`name`)&&(r in n||r in vt))return!1;let i=A[t]||M.attributeCheck instanceof Function&&M.attributeCheck(t,e);if(je&&K(be,t)||Ae&&K(xe,t))return!0;if(!i)return sn(e)&&en(j.tagNameCheck,e)&&en(j.attributeNameCheck,t,e)||t===`is`&&j.allowCustomizedBuiltInElements&&en(j.tagNameCheck,r);if(et[t])return!0;let a=er(r,Ce,``);return K(Te,a)||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&tr(r,`data:`)===0&&Qe[e]||Me&&!K(Se,a)?!0:!r},on=Y({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),sn=function(e){return!on[Zn(e)]&&K(we,e)},cn=function(e,t,n,r){if(S&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return T(r);case`TrustedScriptURL`:return ue(r)}return r},ln=function(e,t,n,r){try{return n?e.setAttributeNS(n,t,r):e.setAttribute(t,r),!z(e)||(Dt(e),!1)}catch{return kt(t,e),!1}},un=function(e,t){return Pe&&K(Gr,t)?!0:Zn(e)===`attributename`&&tr(t,`href`)!==-1},dn=function(e,n){if(B(O.beforeSanitizeAttributes,e,null),nn(e,n))return;let r=oe(e);if(!r||z(e))return;A=V(O.uponSanitizeAttribute,A,De,Le);let i={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:A,forceKeepAttr:void 0},a=r.length,o=I(x(e));for(;a--;){let n=r[a];if(!n)continue;let s=n.name,c=n.namespaceURI,l=n.value,u=I(s),d=l,f=s===`value`?d:nr(d),p=!1;i.attrName=u,i.attrValue=f,i.keepAttr=!0,i.forceKeepAttr=void 0,B(O.uponSanitizeAttribute,e,i),f=i.attrValue,Ue&&(u===`id`||u===`name`)&&tr(f,We)!==0&&(kt(s,e,n),f=We+f,p=!0),un(s,f)?kt(s,e,n):i.forceKeepAttr||(i.keepAttr?!Ne&&K(Wr,f)?kt(s,e,n):(N&&(f=Wt(f)),an(o,u,f)?(f=cn(o,u,c,f),f!==d&&ln(e,s,c,f)&&p&&zn(t.removed)):kt(s,e,n)):kt(s,e,n))}B(O.afterSanitizeAttributes,e,null),nn(e,n)},fn=function(e,t){rn(e,t),dn(e,t),Xt(e.content)&&pn(e.content)},pn=function(e){let t=null,n=Ut(e);for(B(O.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(B(O.uponSanitizeShadowNode,t,null),fn(t,e),b(t)===Z.element){let e=te(t);Xt(e)&&(mn(e),pn(e))}N&&Jt(e),B(O.afterSanitizeShadowDOM,e,null)},mn=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){pn(e.shadow);continue}let n=e.node,r=b(n)===Z.element,i=g(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=y?y(n):null;if(typeof e==`string`&&I(e)===`template`){let e=n.content;Xt(e)&&t.push({node:e,shadow:null})}}if(r){let e=te(n);Xt(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}},hn=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(at=!e,at&&(e=`<!-->`),typeof e!=`string`&&!Zt(e)&&(e=pr(e),typeof e!=`string`))throw q(`dirty is not a string, aborting`);if(!t.isSupported)return e;P?(k=Ie,A=Le):bt(n),_t=gt,t.removed=[];let c=Ke&&typeof e!=`string`&&Zt(e),l=[],u=qe,d=Je;if(c){Vt(e),l=Mt(e);let t=x(e);if(typeof t==`string`){let n=I(t);if(!k[n]||Oe[n])throw Ft(e,l),q(`root node is forbidden and cannot be sanitized in-place`)}if(z(e))throw Ft(e,l),q(`root node is clobbered and cannot be sanitized in-place`);qe=Wn(),Je=Jn()}else if(Zt(e))i=Ht(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===Z.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),mn(i);else{if(!ze&&!N&&!Fe&&e.indexOf(`<`)===-1)return E(e);if(i=Ht(e),!i)return ze?null:Ve?C:``}i&&Re&&Dt(i.firstChild);let f=c?e:i;try{c&&mn(e);let t=Ut(f);for(;o=t.nextNode();)fn(o,f);c&&It(e,l)}catch(t){throw c&&Ft(e,l),t}finally{qe=u,Je=d}if(c){if(Pt(e,l))throw q(`a node selected for removal could not be safely returned; refusing to sanitize in place`);return N&&Gt(e),e}if(ze){if(N&&Gt(i),Be)for(s=me.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(A.shadowroot||A.shadowrootmode)&&(s=ge.call(r,s,!0)),s}N&&Jt(i);let p=Fe?i.outerHTML:i.innerHTML;return Fe&&k[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&K(Rr,i.ownerDocument.doctype.name)&&(p=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
81
+ `+p),E(p)};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=_t,i=k,a=A,o=t.removed;_t=null;try{return hn(e,n)}finally{_t=r,r&&(P||bt(r),k=i,A=a,t.removed=o)}},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};bt(e),P=!0,Ie=k,Le=A},t.clearConfig=function(){gt=null,P=!1,Ie=null,Le=null,S=se,C=``},t.isValidAttribute=function(e,t,n){gt||bt({});let r=I(e),i=I(t);return typeof n==`string`&&(un(t,n)||!Ne&&K(Wr,n))?!1:an(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&G(O,e)&&Bn(O[e],t)},t.removeHook=function(e,t){if(G(O,e)){if(t!==void 0){let n=Rn(O[e],t);return n===-1?void 0:Hn(O[e],n,1)[0]}return zn(O[e])}},t.removeHooks=function(e){G(O,e)&&(O[e]=[])},t.removeAllHooks=function(){O=Qr()},t}var ni=ti(),ri;function ii(){if(ri!==void 0)return ri;let e=globalThis.trustedTypes;try{ri=e?.createPolicy(`aicore-agent-chat`,{createHTML:e=>e,createScriptURL:()=>``})??null}catch{ri=null}return ri}var ai=[`img`,`image`,`feImage`,`picture`,`video`,`audio`,`source`,`track`,`iframe`,`frame`,`object`,`embed`,`link`,`meta`,`base`,`style`,`form`,`input`,`button`,`textarea`,`select`],oi=/* @__PURE__ */ new Set([`src`,`srcset`,`poster`,`background`,`lowsrc`,`dynsrc`,`data`,`ping`,`action`,`formaction`]),si=/* @__PURE__ */ new Set([`href`,`xlink:href`,`title`,`alt`]),ci={FORBID_TAGS:ai,FORBID_ATTR:[`style`]},li={USE_PROFILES:{html:!0,svg:!0,svgFilters:!0,mathMl:!0},ADD_TAGS:[`foreignObject`,`semantics`,`annotation`],HTML_INTEGRATION_POINTS:{foreignobject:!0},FORBID_TAGS:ai},ui=/url\(\s*(?!['"]?#)/i,di=/(?:image-set|image|cross-fade|element)\(/i,fi=null,pi=null;function mi(){return pi||(pi=ni(window),pi.addHook(`uponSanitizeElement`,(e,t)=>{fi&&t.tagName===`style`&&fi.sheets.push(e.textContent??``)}),pi.addHook(`uponSanitizeAttribute`,(e,t)=>{let n=t.attrName,r=t.attrValue;n===`style`?(fi&&fi.styles.set(e,r),t.keepAttr=!1):oi.has(n)||fi&&!si.has(n)&&!n.startsWith(`aria-`)&&ui.test(r)?t.keepAttr=!1:n!==`href`&&n!==`xlink:href`||e.nodeName.toLowerCase()===`a`||r.startsWith(`#`)||(t.keepAttr=!1)}),pi.addHook(`afterSanitizeAttributes`,e=>{e.nodeName.toLowerCase()===`a`&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer nofollow`))}),pi)}function hi(e){let t=ii();return t?{...e,TRUSTED_TYPES_POLICY:t}:e}function gi(e){return mi().sanitize(e,hi(ci))}function _i(e){let t=ii();return t?t.createHTML(e):e}function vi(e){let t=fi={styles:/* @__PURE__ */ new Map,sheets:[]};try{let n=mi().sanitize(e,{...hi(li),RETURN_DOM_FRAGMENT:!0}),r=document.adoptNode(n);for(let[e,n]of t.styles)bi(e,n);return{fragment:r,css:t.sheets.join(`
82
+ `)}}finally{fi=null}}function yi(e){let t=fi={styles:/* @__PURE__ */ new Map,sheets:[]};try{mi().sanitize(e,{...hi(li),IN_PLACE:!0});for(let[e,n]of t.styles)bi(e,n)}finally{fi=null}}function bi(e,t){let n=e.style;if(n){n.cssText=t;for(let e of[...n]){let t=n.getPropertyValue(e);(ui.test(t)||di.test(t))&&n.removeProperty(e)}}}function xi(e){let t;try{t=new CSSStyleSheet,t.replaceSync(e)}catch{return null}return Ci(t),t}var Si=/* @__PURE__ */ new Set([`CSSStyleRule`,`CSSNestedDeclarations`,`CSSMediaRule`,`CSSSupportsRule`,`CSSContainerRule`,`CSSLayerBlockRule`,`CSSKeyframesRule`,`CSSKeyframeRule`]);function Ci(e){for(let t=e.cssRules.length-1;t>=0;t--){let n=e.cssRules[t];if(!Si.has(n.constructor.name))e.deleteRule(t);else{if(`style`in n){let e=n.style;for(let t of[...e]){let n=e.getPropertyValue(t);(ui.test(n)||di.test(n))&&e.removeProperty(t)}}`cssRules`in n&&Ci(n)}}}function wi(e,t){e.adoptedStyleSheets.includes(t)||(e.adoptedStyleSheets=[...e.adoptedStyleSheets,t])}function Ti(e,t){e.adoptedStyleSheets.includes(t)&&(e.adoptedStyleSheets=e.adoptedStyleSheets.filter(e=>e!==t))}var Ei={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`},Di=e=>e.replace(/[&<>"']/g,e=>Ei[e]),Oi=/^(\$+)(?!\$)([\s\S]*?[^$])\1(?!\$)/,ki=/^ {0,3}(\${2,})[^$\n]*(?:\n|$)/,Ai=/^ {0,3}(\${2,})[ \t]*$/,ji=new en({gfm:!0,breaks:!0,async:!1,extensions:[{name:`blockMath`,level:`block`,start:e=>/^ {0,3}\${2,}[^$\n]*$/m.exec(e)?.index,tokenizer(e){let t=ki.exec(e);if(!t)return;let n=t[1].length,r=e.slice(t[0].length).split(`
83
+ `),i=[],a=t[0];for(let[e,t]of r.entries()){let o=e===r.length-1;a+=o?t:`${t}\n`;let s=Ai.exec(t);if(s&&s[1].length>=n)break;i.push(t)}return{type:`blockMath`,raw:a,text:i.join(`
84
+ `)}},renderer:e=>`<div class="math-display">${Di(e.text)}</div>\n`},{name:`inlineMath`,level:`inline`,start:e=>{let t=e.indexOf(`$`);return t<0?void 0:t},tokenizer(e){let t=Oi.exec(e);if(!t)return;let n=t[2];return/^[ \n]/.test(n)&&/[ \n]$/.test(n)&&/[^ \n]/.test(n)&&(n=n.slice(1,-1)),{type:`inlineMath`,raw:t[0],text:n}},renderer:e=>`<span class="math-inline">${Di(e.text)}</span>`}],renderer:{html:({text:e})=>Di(e),image:({href:e,text:t})=>`<a href="${Di(e)}">${Di(t||e)}</a>`,code:({text:e,lang:t,raw:n})=>{let r=/^\S*/.exec(t??``)?.[0]??``;if(r===`math`)return`<div class="math-display">${Di(e)}</div>\n`;let i=n.trimEnd().split(`
85
+ `),a=/^ {0,3}(`{3,}|~{3,})/.test(i[0]??``)&&(i.length<2||!/^ {0,3}(`{3,}|~{3,})[ \t]*$/.test(i.at(-1))),o=`${Di(e.replace(/\n$/,``))}\n`,s=r?` class="language-${Di(r)}"`:``;return`<pre${a?` data-open`:``}><code${s}>${o}</code></pre>\n`}}});function Mi(e){return gi(ji.parse(e))}function Ni(e,t,n){let r=mn(e);e.innerHTML=_i(t?Mi(t):``),vn(e,n,r)}var Pi=`change`,Fi=5,Ii=1,Li=50,Ri=1500,zi=60,Bi={agentId:null,agent:null,conversations:[],conversationsLoading:!1,conversationsFailed:!1,activeId:null,messages:[],turn:null,turnStartedAt:null,loadingHistory:!1,error:null,files:[],uploading:0,requests:[],events:[],tokens:0},Vi=(e,t)=>[t,...e].slice(0,Li),Hi=e=>typeof e?.rating==`number`?e.rating:null;function Ui(e){return e.map(e=>e.role===`user`?{role:`user`,text:e.content,attachments:e.attachments??[]}:{role:`assistant`,text:e.content,sources:e.sources??[],idQuery:e.id_query??null,error:null,rating:Hi(e.feedback),interrupted:!1})}var Wi=class extends EventTarget{client;#e=Bi;#t=0;#n=null;#r=0;#i=null;constructor(e){super(),this.client=new C({...e,onRequest:e=>this.#a(t=>({requests:Vi(t.requests,e)})),onIdentityChange:()=>this.#d()})}get state(){return this.#e}get busy(){return this.#n!==null}#a(e){this.#e={...this.#e,...e(this.#e)},this.dispatchEvent(new Event(Pi))}#o(e){this.#a(()=>e)}async#s(e,t){try{await t()}catch(t){!a(t)&&e()&&this.#o({error:i(t)})}}#c(e=this.#t){return()=>e===this.#t}#l(e){let t=this.#r;return()=>this.#e.agentId===e&&t===this.#r}#u(){this.#n?.abort(),this.#n=null,this.#i=null,this.#t++,this.#o({activeId:null,messages:[],turn:null,turnStartedAt:null,loadingHistory:!1,files:[],uploading:0,error:null})}#d(){this.#r++,this.#u(),this.#o({conversations:[],conversationsFailed:!1,conversationsLoading:!1,requests:[],events:[],tokens:0}),this.refreshConversations()}async setAgent(e){if(e===this.#e.agentId||(this.#u(),this.#o({agentId:e,agent:null,conversations:[],conversationsFailed:!1}),!e))return;let t=this.#l(e);await Promise.all([this.#s(t,async()=>{let n=await this.client.getAgent(e);t()&&this.#o({agent:n})}),this.refreshConversations()])}async refreshConversations(){let{agentId:e}=this.#e;if(!e)return;let t=this.#l(e);this.#o({conversationsLoading:!0});let n=!0;await this.#s(t,async()=>{let r=await this.client.listConversations(e);n=!1,t()&&this.#o({conversations:[...r.items].sort((e,t)=>t.last_message_at-e.last_message_at)})}),t()&&this.#o({conversationsLoading:!1,conversationsFailed:n})}newConversation(){this.#u()}async open(e){if(e===this.#e.activeId)return;this.#u();let t=this.#t;this.#o({activeId:e,loadingHistory:!0}),await this.#s(this.#c(t),async()=>{let n=await this.client.history(e);t===this.#t&&this.#o({messages:Ui(n)})}),t===this.#t&&this.#o({loadingHistory:!1})}async rename(e,t){let{agentId:n,conversations:r}=this.#e,a=t.trim(),o=r.find(t=>t.id===e);if(!n||!a||o?.title===a)return;let s=this.#l(n),c=t=>this.#a(n=>({conversations:n.conversations.map(n=>n.id===e?{...n,...t(n)}:n)}));c(()=>({title:a}));try{let t=await this.client.renameConversation(e,a);s()&&c(()=>t)}catch(e){if(!s())return;o&&c(e=>e.title===a?{title:o.title}:null),this.#o({error:i(e)})}}async remove(e){let{agentId:t}=this.#e;t&&await this.#s(this.#l(t),async()=>{await this.client.deleteConversation(e),e===this.#e.activeId&&this.#u(),this.#a(t=>({conversations:t.conversations.filter(t=>t.id!==e)}))})}#f(e){if(this.#e.activeId)return Promise.resolve(this.#e.activeId);let t=this.#t;if(this.#i?.epoch===t)return this.#i.promise;let n=this.client.openConversation(e).then(e=>{if(t!==this.#t)throw new DOMException(`moved on`,`AbortError`);return this.#i=null,this.#o({activeId:e.id_conv}),this.refreshConversations(),e.id_conv});return this.#i={epoch:t,promise:n},n.catch(()=>{this.#i?.promise===n&&(this.#i=null)}),n}async#p(e,t,n){let r=!1;try{for(let i=0;i<zi;i++){if(await new Promise(e=>setTimeout(e,Ri)),e!==this.#t)return;let i=(await this.client.listFiles(t)).find(e=>e.id_file===n);if(e!==this.#t||!i)return;if(this.#a(e=>({files:e.files.map(e=>e.id_file===n?i:e)})),i.status!==`processing`){r=!0;return}}}finally{!r&&e===this.#t&&this.#a(e=>({files:e.files.map(e=>e.id_file===n&&e.status===`processing`?{...e,status:`error`,error:`Processing did not finish`}:e)}))}}async attach(e){let{agentId:t}=this.#e;if(!t||this.busy)return;this.#o({error:null});let n=this.#t,r=this.#c(n);this.#a(e=>({uploading:e.uploading+1}));try{await this.#s(r,async()=>{let i=await this.#f(t);for(let t of e){let e=await this.client.uploadFile(i,t);if(n!==this.#t)return;this.#a(t=>({files:[...t.files,e]})),e.status===`processing`&&this.#s(r,()=>this.#p(n,i,e.id_file))}})}finally{n===this.#t&&this.#a(e=>({uploading:Math.max(0,e.uploading-1)}))}}async detach(e){let{activeId:t}=this.#e;t&&await this.#s(this.#c(),async()=>{await this.client.deleteFile(t,e),this.#a(t=>({files:t.files.filter(t=>t.id_file!==e)}))})}async send(e,t={}){let{context:n}=t,{agentId:r,activeId:a,files:o,uploading:s}=this.#e,c=e.trim();if(!r||this.busy||!c||s>0||o.some(e=>e.status===`processing`))return;let l=o.filter(e=>e.status===`ready`),u=this.#t,d=new AbortController;this.#n=d,this.#a(e=>({error:null,files:[],turn:g,turnStartedAt:Date.now(),events:[],tokens:0,messages:[...e.messages,{role:`user`,text:c,attachments:l.map(({id_file:e,name:t,mime:n,size:r})=>({id_file:e,name:t,mime:n,size:r}))}]}));let f=()=>u===this.#t&&!d.signal.aborted;try{let e=await this.client.ask({idAgent:r,idConv:a,request:{text:c,...l.length>0?{attachments:l.map(e=>({id_file:e.id_file}))}:{},...n?{context:n}:{}},signal:d.signal,onConversation:e=>{u===this.#t&&this.#o({activeId:e})},onUpdate:(e,t)=>{f()&&this.#a(n=>t.kind===`token`?{turn:e,tokens:n.tokens+1}:{turn:e,events:Vi(n.events,{at:Date.now(),kind:t.kind,id:t.id,data:t.data})})}});if(u!==this.#t)return;this.#a(t=>({turn:null,messages:[...t.messages,{role:`assistant`,text:ne(e.turn),sources:e.turn.sources,idQuery:e.idQuery,error:e.turn.error,rating:null,interrupted:!e.turn.finished}]})),(a===null||e.turn.title)&&await this.refreshConversations()}catch(e){f()?this.#o({error:i(e)}):u===this.#t&&this.#a(e=>({messages:[...e.messages,{role:`assistant`,text:``,sources:[],idQuery:null,error:null,rating:null,interrupted:!0}]}))}finally{this.#n===d&&(this.#n=null),u===this.#t&&this.#o({turn:null})}}stop(){this.#n?.abort()}async rate(e,t){let{activeId:n}=this.#e;if(!n)return;let r=t=>this.#a(n=>({messages:n.messages.map(n=>n.role===`assistant`&&n.idQuery===e?{...n,rating:t}:n)})),a=this.#e.messages.find(t=>t.role===`assistant`&&t.idQuery===e);r(t);try{await this.client.sendFeedback(n,e,t)}catch(e){r(a?.role===`assistant`?a.rating:null),this.#o({error:i(e)})}}dismissError(){this.#o({error:null})}dispose(){this.#n?.abort(),this.#t++}},Gi={locale:`it-IT`,conversations:`Conversazioni`,newConversation:`Nuova conversazione`,noConversations:`Ancora nessuna conversazione.`,conversationsFailed:`Impossibile leggere le conversazioni.`,loading:`Caricamento…`,untitled:`Senza titolo`,disabled:`disabilitata`,renameConversation:e=>`Rinomina «${e}»`,newTitle:`Nuovo titolo`,save:`Salva`,cancel:`Annulla`,deleteConversation:e=>`Elimina «${e}»`,confirmDelete:e=>`Eliminare la conversazione «${e}»?`,confirmDeleteShort:`Elimina?`,ask:e=>`Chiedi a ${e}`,askGeneric:`Come posso esserti utile?`,noAgent:`Nessun agente indicato.`,notConnected:`Chat non configurata.`,placeholder:`Scrivi un messaggio`,send:`Invia`,stop:`Interrompi`,attach:`Allega documenti`,removeFile:e=>`Rimuovi ${e}`,processing:`in elaborazione`,fileError:`errore`,thinking:`Sto pensando…`,loadingHistory:`Carico la conversazione…`,copy:`Copia`,copied:`Copiato`,rateUp:`Risposta utile`,rateDown:`Risposta non utile`,sources:e=>e===1?`1 fonte`:`${e} fonti`,page:e=>`p. ${e}`,part:e=>`parte ${e}`,untitledSource:`Fonte senza titolo`,interrupted:`Risposta interrotta.`,turnFailed:`L'agente non è riuscito a rispondere.`,trace:e=>`Traccia ${e}`,disclaimer:`Le risposte sono generate da un'intelligenza artificiale e possono contenere errori: verifica sempre le informazioni.`,dismiss:`Chiudi`,you:`Tu`,agent:`Agente`,errors:{auth_required:`Accesso scaduto o non valido: rientra nell'applicazione.`,tenant_refused:`Il tuo account non può usare l'agente in questo spazio di lavoro.`,forbidden:`Non puoi usare questo agente.`,not_found:`Agente o conversazione non trovati.`,busy:`L'agente sta ancora rispondendo, oppure non è pubblicato. Riprova tra poco.`,locked:`Questa conversazione è disabilitata.`,rate_limited:`Troppe richieste.`,network:`Servizio non raggiungibile.`,http:`Errore del servizio.`},retryIn:e=>`Riprova tra ${e} s.`,developer:`Sviluppatore`,requests:`Richieste`,events:e=>`Eventi dell'ultimo turno · ${e} token`,lastError:`Ultimo errore`,renewed:`token rinnovato`,publishedVersion:`Versione pubblicata`,notPublished:`non pubblicato`,conversation:`Conversazione`,context:`Contesto del turno`,none:`—`,a2uiPreparing:`Preparazione del modulo…`,a2uiRefused:e=>`Interfaccia non disegnata: ${e}`,a2uiInvalid:`il blocco non rispetta il catalogo`,a2uiSent:`Inviato`,a2uiDetails:`Dettagli`,a2uiTabs:`Schede`,close:`Chiudi`,a2uiAction:e=>`Azione ${e}`,yes:`sì`,no:`no`},Ki={locale:`en-GB`,conversations:`Conversations`,newConversation:`New conversation`,noConversations:`No conversations yet.`,conversationsFailed:`Could not read the conversations.`,loading:`Loading…`,untitled:`Untitled`,disabled:`disabled`,renameConversation:e=>`Rename “${e}”`,newTitle:`New title`,save:`Save`,cancel:`Cancel`,deleteConversation:e=>`Delete “${e}”`,confirmDelete:e=>`Delete the conversation “${e}”?`,confirmDeleteShort:`Delete?`,ask:e=>`Ask ${e}`,askGeneric:`How can I help?`,noAgent:`No agent set.`,notConnected:`Chat not configured.`,placeholder:`Write a message`,send:`Send`,stop:`Stop`,attach:`Attach documents`,removeFile:e=>`Remove ${e}`,processing:`processing`,fileError:`error`,thinking:`Thinking…`,loadingHistory:`Loading the conversation…`,copy:`Copy`,copied:`Copied`,rateUp:`Helpful answer`,rateDown:`Unhelpful answer`,sources:e=>e===1?`1 source`:`${e} sources`,page:e=>`p. ${e}`,part:e=>`part ${e}`,untitledSource:`Untitled source`,interrupted:`Answer stopped.`,turnFailed:`The agent could not answer.`,trace:e=>`Trace ${e}`,disclaimer:`Answers are generated by AI and may contain mistakes: always check the information.`,dismiss:`Dismiss`,you:`You`,agent:`Agent`,errors:{auth_required:`Your sign-in expired or is invalid: sign in again.`,tenant_refused:`Your account cannot use the agent in this workspace.`,forbidden:`You cannot use this agent.`,not_found:`Agent or conversation not found.`,busy:`The agent is still answering, or it is not published. Try again shortly.`,locked:`This conversation is disabled.`,rate_limited:`Too many requests.`,network:`Service unreachable.`,http:`Service error.`},retryIn:e=>`Try again in ${e} s.`,developer:`Developer`,requests:`Requests`,events:e=>`Events of the last turn · ${e} tokens`,lastError:`Last error`,renewed:`token renewed`,publishedVersion:`Published version`,notPublished:`not published`,conversation:`Conversation`,context:`Turn context`,none:`—`,a2uiPreparing:`Preparing the form…`,a2uiRefused:e=>`Interface not drawn: ${e}`,a2uiInvalid:`the block does not follow the catalog`,a2uiSent:`Sent`,a2uiDetails:`Details`,a2uiTabs:`Tabs`,close:`Close`,a2uiAction:e=>`Action ${e}`,yes:`yes`,no:`no`};function qi(e){let t=e?.trim().toLowerCase()??``;return t===``||t.startsWith(`it`)?`it`:`en`}function Ji(e){return qi(e)===`it`?Gi:Ki}function Yi(e,t){let n=Ji(e);return t?{...n,...t,errors:{...n.errors,...t.errors}}:n}var Xi={add:`M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z`,delete:`M16 9v10H8V9h8m-1.5-6h-5l-1 1H5v2h14V4h-3.5l-1-1zM18 7H6v12c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7z`,send:`M2.01 21 23 12 2.01 3 2 10l15 2-15 2z`,stop:`M6 6h12v12H6z`,attach:`M16.5 6v11.5c0 2.21-1.79 4-4 4s-4-1.79-4-4V5c0-1.38 1.12-2.5 2.5-2.5s2.5 1.12 2.5 2.5v10.5c0 .55-.45 1-1 1s-1-.45-1-1V6H10v9.5c0 1.38 1.12 2.5 2.5 2.5s2.5-1.12 2.5-2.5V5c0-2.21-1.79-4-4-4S7 2.79 7 5v12.5c0 3.04 2.46 5.5 5.5 5.5s5.5-2.46 5.5-5.5V6h-1.5z`,copy:`M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z`,check:`M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`,thumbUp:`M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.58 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h4v12H1z`,thumbDown:`M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L9.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h4v12h-4z`,close:`M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z`,menu:`M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z`,edit:`M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z`},Zi=`http://www.w3.org/2000/svg`;function Qi(e){let t=document.createElementNS(Zi,`svg`);t.setAttribute(`class`,`icon`),t.setAttribute(`viewBox`,`0 0 24 24`),t.setAttribute(`aria-hidden`,`true`),t.setAttribute(`focusable`,`false`);let n=document.createElementNS(Zi,`path`);return n.setAttribute(`d`,Xi[e]),n.setAttribute(`fill`,`currentColor`),t.append(n),t}var $i=`v0.9.1`,ea=`a2ui-action`,ta=[`createSurface`,`updateComponents`,`updateDataModel`,`deleteSurface`];function na(t){if(!e(t)||typeof t.version!=`string`)return!1;let n=ta.filter(e=>e in t);if(n.length!==1)return!1;let r=t[n[0]];return e(r)&&typeof r.surfaceId==`string`&&r.surfaceId!==``}function ra(e){let t;try{t=JSON.parse(e)}catch{return null}return!Array.isArray(t)||t.length===0||!t.every(na)?null:t}function ia(t){let n=[];for(let r of t){let t=r.createSurface;e(t)&&typeof t.surfaceId==`string`&&!n.includes(t.surfaceId)&&n.push(t.surfaceId)}return n}function aa(e){let t={name:e.name,surfaceId:e.surfaceId,sourceComponentId:e.sourceComponentId,timestamp:e.timestamp||(/* @__PURE__ */ new Date()).toISOString(),context:e.context};return`\`\`\`${ea}\n${JSON.stringify([{version:$i,action:t}])}\n\`\`\``}var oa=RegExp(`^\`\`\`${ea}[ \\t]*\\n([\\s\\S]*?)\\n\`\`\`$`);function sa(t){let n=oa.exec(t.replace(/\r\n/g,`
86
+ `).trim());if(!n)return null;let r;try{r=JSON.parse(n[1])}catch{return null}let i=Array.isArray(r)?r[0]:r;if(!e(i)||!e(i.action))return null;let a=i.action;return typeof a.name!=`string`||a.name===``||typeof a.surfaceId!=`string`||a.surfaceId===``||!e(a.context)?null:{name:a.name,surfaceId:a.surfaceId,sourceComponentId:typeof a.sourceComponentId==`string`?a.sourceComponentId:``,timestamp:typeof a.timestamp==`string`?a.timestamp:``,context:a.context}}var ca=/(?:^|\n) {0,3}(`{3,})a2ui[ \t]*\n([\s\S]*?)\n {0,3}\1`*[ \t]*(?=\n|$)/g,la=/* @__PURE__ */ new WeakMap;function ua(e){let t=la.get(e);if(!t){t=[];for(let n of e.text.matchAll(ca)){let e=ra(n[2]);e&&t.push(...ia(e))}la.set(e,t)}return t}function da(e){let t=e.map(()=>/* @__PURE__ */ new Map),n=/* @__PURE__ */ new Map;return e.forEach((e,r)=>{if(e.role===`assistant`){for(let t of ua(e))n.set(t,r);return}if(e.role!==`user`)return;let i=sa(e.text),a=i?n.get(i.surfaceId):void 0;if(!i||a===void 0)return;let o=t[a];o.has(i.surfaceId)||o.set(i.surfaceId,i)}),t}function fa(t,n){let r=null;for(let i of t){let t=i.updateComponents;if(e(t)&&t.surfaceId===n.surfaceId&&Array.isArray(t.components))for(let a of t.components)e(a)&&a.id===n.sourceComponentId&&(r={version:i.version,component:a})}let i=r?.component.action,a=e(i)?i.event:void 0;if(r===null||!e(a)||!e(a.context))return[];let o=[];for(let[t,i]of Object.entries(a.context))e(i)&&typeof i.path==`string`&&i.path.startsWith(`/`)&&t in n.context&&o.push({version:r.version,updateDataModel:{surfaceId:n.surfaceId,path:i.path,value:n.context[t]}});return o}function pa(e,t,n){return e==null?`—`:typeof e==`boolean`?e?t:n:Array.isArray(e)?e.map(e=>pa(e,t,n)).join(`, `):typeof e==`string`?e:typeof e==`number`||typeof e==`bigint`?String(e):typeof e==`function`||typeof e==`symbol`?`—`:JSON.stringify(e)}function ma(e,t){let n=e.name.replace(/_/g,` `).trim();return{label:n.charAt(0).toUpperCase()+n.slice(1),fields:Object.entries(e.context).map(([e,n])=>[e,pa(n,t.yes,t.no)])}}var ha=`
78
87
  :host {
79
88
  --_bg: var(--aicore-chat-surface, rgb(var(--magma-surface-default, 255 255 255)));
80
89
  --_raised: var(--aicore-chat-surface-muted, rgb(var(--magma-surface-muted, 245 245 247)));
@@ -111,7 +120,7 @@ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error
111
120
  :host([hidden]) { display: none; }
112
121
  *, *::before, *::after { box-sizing: border-box; }
113
122
  [hidden] { display: none !important; }
114
- svg { inline-size: 20px; block-size: 20px; flex: none; }
123
+ .icon { inline-size: 20px; block-size: 20px; flex: none; }
115
124
 
116
125
  button {
117
126
  font: inherit;
@@ -344,7 +353,9 @@ button:focus-visible, summary:focus-visible {
344
353
  .chip:not(:has(button)) { padding-inline-end: 10px; }
345
354
  .chip.error { border-color: var(--_danger); color: var(--_danger); }
346
355
  .chip .icon-button { inline-size: 22px; block-size: 22px; }
347
- .chip svg { inline-size: 16px; block-size: 16px; }
356
+ .chip .icon { inline-size: 16px; block-size: 16px; }
357
+ .action-summary { justify-content: flex-end; }
358
+ .chip.action { border-color: var(--_accent); background: var(--_accent); color: var(--_on-accent); font-weight: 600; }
348
359
 
349
360
  .message.assistant .answer { overflow-wrap: anywhere; }
350
361
  .note { margin: 0; color: var(--_muted); font-size: calc(var(--_fs) * 13 / 15); font-style: italic; }
@@ -422,6 +433,16 @@ button:focus-visible, summary:focus-visible {
422
433
  .markdown th, .markdown td { padding: 6px 10px; border: 1px solid var(--_border); text-align: start; }
423
434
  .markdown th { background: var(--_raised); }
424
435
  .markdown hr { border: 0; border-block-start: 1px solid var(--_border); }
436
+ .markdown .diagram, .markdown .chart {
437
+ display: flex;
438
+ justify-content: center;
439
+ overflow-x: auto;
440
+ margin-block: 0 0.75em;
441
+ padding: 20px;
442
+ border: 1px solid var(--_border);
443
+ border-radius: var(--_radius-sm);
444
+ background: var(--_bg);
445
+ }
425
446
 
426
447
  /* ---- composer ---------------------------------------------------------- */
427
448
 
@@ -487,5 +508,5 @@ textarea {
487
508
  .log { margin: 0; padding: 0; list-style: none; font-family: var(--_mono); }
488
509
  .log li { padding-block: 1px; overflow-wrap: anywhere; }
489
510
  .log .bad { color: var(--_danger); }
490
- `,Vr=`aicore-agent-chat`,Hr=`.pdf,.docx,.txt,.md,.html,.xlsx,.epub`,Ur=[x.turn,x.error,x.authRequired,x.tenantRefused],Wr=160,Gr=100,Kr=48,qr=4e3,Jr=[`getToken`,`strings`,`context`,`baseUrl`,`agent`,`tenant`,`conversation`,`developer`],Yr=typeof HTMLElement>`u`?class{}:HTMLElement,Xr;function Zr(){if(Xr!==void 0)return Xr;try{let e=new CSSStyleSheet;e.replaceSync(Br),Xr=`adoptedStyleSheets`in ShadowRoot.prototype?e:null}catch{Xr=null}return Xr}var Qr=()=>typeof navigator<`u`&&navigator.clipboard!==void 0;function Q(e,t={},...n){let r=document.createElement(e);t.class&&(r.className=t.class),t.part&&r.setAttribute(`part`,t.part),t.text!==void 0&&(r.textContent=t.text);for(let[e,n]of Object.entries(t.attrs??{}))r.setAttribute(e,n);for(let e of n)e&&r.append(e);return r}function $(e,t,n={},r=``){return Q(`button`,{class:`icon-button ${r}`.trim(),attrs:{type:`button`,"aria-label":t,title:t,...n}},zr(e))}function $r(e){return e&&/^https?:\/\//i.test(e)?e:null}function ei(e,t){return t.title??t.name??t.url??t.id_document??e.untitledSource}function ti(e,t){return t.page==null?t.part==null?``:e.part(t.part):e.page(String(t.page))}function ni(t,n){let r=n===null?``:`+${((t.at-n)/1e3).toFixed(1)}s`,i=e(t.data)?t.data:{},a=typeof i.name==`string`?`${typeof i.node==`string`?`${i.node} → `:``}${i.name}`:``;if(!a)try{a=JSON.stringify(t.data)??``}catch{a=``}return a.length>Wr&&(a=`${a.slice(0,Wr)}…`),[r,t.kind,t.id?`#${t.id}`:``,a].filter(Boolean).join(` `)}function ri(e,t){if(e.role!==`assistant`||t.role!==`assistant`)return!1;let n=n=>e[n]===t[n];return n(`text`)&&n(`sources`)&&n(`error`)&&n(`idQuery`)&&n(`interrupted`)}function ii(e,t){for(let n of e.querySelectorAll(`[data-action="rate"]`)){let e=Number(n.dataset.rating)===5;n.setAttribute(`aria-pressed`,String(t!==null&&(e?t>=4:t<=2)))}}var ai=class extends Yr{static observedAttributes=[`base-url`,`agent`,`tenant`,`conversation`,`lang`,`developer`];#e=null;#t=null;#n=null;#r=!1;#i=null;#a=null;#o=null;#s=null;#c=``;#l=null;#u=!1;#d=!0;#f=null;#p=!1;#m=[];#h=null;#g=0;#_=!1;#v=null;#y=!1;#b=!1;#x=!1;#S=!1;#C=!0;#w;constructor(){super();let e=this.attachShadow({mode:`open`}),t=Q(`button`,{class:`new-conversation`,attrs:{type:`button`,"data-action":`new`}}),n=Q(`p`,{class:`rail-status muted small`}),r=Q(`ul`,{class:`conversations`}),i=Q(`aside`,{class:`rail`,part:`rail`},t,n,r),a=$(`menu`,``,{"data-action":`toggle-rail`});a.classList.add(`rail-toggle`);let o=Q(`span`,{class:`agent-name`}),s=Q(`span`,{class:`agent-description`}),c=Q(`header`,{class:`header`,part:`header`},a,Q(`div`,{class:`agent`},o,s)),l=Q(`strong`),u=Q(`span`,{class:`small`}),d=$(`close`,``,{"data-action":`dismiss`}),f=Q(`div`,{class:`banner`,part:`error`,attrs:{role:`alert`}},Q(`div`,{class:`banner-text`},l,u),d);f.hidden=!0;let p=Q(`p`,{class:`empty-title`}),m=Q(`div`,{class:`empty`},p),h=Q(`p`,{class:`status`}),g=Q(`div`,{class:`messages`}),_=Q(`div`,{class:`answer markdown`}),ee=Q(`span`),v=Q(`article`,{class:`message assistant`,part:`message message-assistant`,attrs:{"aria-busy":`true`}},_,Q(`div`,{class:`status`},Q(`span`,{class:`dots`},Q(`span`),Q(`span`),Q(`span`)),ee));v.hidden=!0;let y=Q(`div`,{class:`thread`,attrs:{role:`log`,"aria-live":`polite`}},m,h,g,v);g.style.display=`contents`;let b=Q(`div`,{class:`transcript`,part:`transcript`},y),x=Q(`ul`,{class:`chips`}),S=Q(`input`,{attrs:{type:`file`,multiple:``,accept:Hr}});S.hidden=!0;let te=$(`attach`,``,{"data-action":`attach`}),ne=Q(`textarea`,{part:`input`,attrs:{rows:`1`}}),re=Q(`button`,{class:`send`,part:`send`,attrs:{type:`submit`}},zr(`send`)),C=Q(`button`,{class:`send`,part:`stop`,attrs:{type:`button`,"data-action":`stop`}},zr(`stop`)),w=Q(`p`,{class:`footnote`}),ie=Q(`form`,{class:`composer`,part:`composer`},x,Q(`div`,{class:`box`},te,ne,re,C),w,S),ae=Q(`summary`),oe=Q(`div`),se=Q(`details`,{class:`developer`,part:`developer`},ae,oe),ce=Q(`div`,{class:`layout`},i,Q(`section`,{class:`main`},c,f,b,ie,se)),le=Zr();le?e.adoptedStyleSheets=[le]:e.append(Q(`style`,{text:Br})),e.append(ce),this.#w={layout:ce,rail:i,newButton:t,railStatus:n,conversations:r,railToggle:a,agentName:o,agentDescription:s,banner:f,bannerTitle:l,bannerDetail:u,dismiss:d,transcript:b,thread:y,empty:m,emptyTitle:p,loading:h,messages:g,live:v,liveAnswer:_,liveActivity:ee,files:x,fileInput:S,attach:te,input:ne,send:re,stop:C,footnote:w,developer:se,developerSummary:ae,developerBody:oe},e.addEventListener(`click`,e=>this.#M(e)),r.addEventListener(`submit`,e=>{e.preventDefault(),this.#L()}),r.addEventListener(`keydown`,e=>{e.key===`Escape`&&this.#i&&(e.preventDefault(),this.#I(!0))}),y.addEventListener(`toggle`,e=>this.#B(e),!0),ie.addEventListener(`submit`,e=>{e.preventDefault(),this.#V()}),ne.addEventListener(`input`,()=>this.#ae()),ne.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),this.#V())}),S.addEventListener(`change`,()=>{let e=Array.from(S.files??[]);S.value=``,e.length>0&&this.#s?.attach(e)}),b.addEventListener(`scroll`,()=>{this.#C=b.scrollHeight-b.scrollTop-b.clientHeight<Kr},{passive:!0}),typeof ResizeObserver<`u`&&new ResizeObserver(()=>{this.#C&&(b.scrollTop=b.scrollHeight)}).observe(b)}get getToken(){return this.#e}set getToken(e){let t=typeof e==`function`?e:null,n=t!==this.#e;this.#e=t,n&&t&&this.#s&&(this.#s.client.clearToken(),this.#s.client.checkIdentity()),this.#E()}get strings(){return this.#t}set strings(t){this.#t=e(t)?t:null,this.#W(!0)}get context(){return this.#n}set context(t){this.#n=e(t)?t:null,this.#r=!0,this.#W()}get baseUrl(){return this.getAttribute(`base-url`)}set baseUrl(e){this.#T(`base-url`,e)}get agent(){return this.getAttribute(`agent`)}set agent(e){this.#T(`agent`,e)}get tenant(){return this.getAttribute(`tenant`)}set tenant(e){this.#T(`tenant`,e)}get conversation(){return this.getAttribute(`conversation`)}set conversation(e){this.#T(`conversation`,e)}get developer(){return this.hasAttribute(`developer`)}set developer(e){this.toggleAttribute(`developer`,!!e)}get state(){return this.#s?.state??null}#T(e,t){t==null||t===``?this.removeAttribute(e):this.setAttribute(e,String(t))}connectedCallback(){let e=this;for(let t of Jr)if(Object.prototype.hasOwnProperty.call(this,t)){let n=e[t];delete e[t],e[t]=n}this.#E(),this.#W(!0)}disconnectedCallback(){queueMicrotask(()=>{this.isConnected||this.#D()})}attributeChangedCallback(e,t,n){if(t!==n)switch(e){case`base-url`:case`tenant`:this.#E();break;case`agent`:this.#O(`agent`);break;case`conversation`:this.#O(`conversation`);break;default:this.#W(!0)}}#E(){if(!this.isConnected)return;let e=this.getAttribute(`base-url`),t=this.getAttribute(`tenant`),n=e&&this.#e?`${e}\n${t??``}`:``;if(n!==this.#c){if(this.#D(),this.#c=n,e&&n){let n=new Mr({baseUrl:e,tenant:t,getToken:async e=>this.#e?this.#e(e):null});for(let e of Ur)n.client.addEventListener(e,this.#A);n.addEventListener(Sr,this.#j),this.#s=n,n.setAgent(this.getAttribute(`agent`)),this.#k()}this.#W(!0)}}#D(){let e=this.#s;if(e){for(let t of Ur)e.client.removeEventListener(t,this.#A);e.removeEventListener(Sr,this.#j),e.dispose()}this.#s=null,this.#c=``,this.#l=null}#O(e){e===`agent`?this.#y=!0:this.#b=!0,this.#x||(this.#x=!0,queueMicrotask(()=>{let e=this.#y,t=this.#b;this.#x=this.#y=this.#b=!1;let n=this.#s;if(n){if(e){this.#S=!1;let e=this.getAttribute(`agent`);n.setAgent(e===``?null:e),t&&this.#k()}else this.#k()}}))}#k(){let e=this.#s;if(!e)return;let t=this.getAttribute(`conversation`);t?e.open(t):e.state.activeId&&!e.busy&&e.newConversation()}#A=e=>{this.dispatchEvent(new CustomEvent(e.type,{detail:e.detail,bubbles:!0,composed:!0}))};#j=()=>{let e=this.#s?.state;e?.agentId&&e.activeId!==this.#l&&(this.#l=e.activeId,this.dispatchEvent(new CustomEvent(x.conversation,{detail:{idConv:e.activeId,idAgent:e.agentId},bubbles:!0,composed:!0}))),this.#W()};#M(e){let t=e.target?.closest(`[data-action]`);this.#S&&!e.target?.closest(`.rail, .rail-toggle`)&&(this.#S=!1,this.#w.layout.classList.remove(`rail-open`));let{id:n}=t?.dataset??{};if(this.#i&&!e.target?.closest(`.rename`)&&this.#I(!1),this.#a!==null&&(t?.dataset.action!==`delete`||n!==this.#a)&&this.#N(null),!t||t.disabled)return;let r=this.#s;switch(t.dataset.action){case`new`:this.#S=!1,r?.newConversation(),this.#w.input.focus();break;case`open`:this.#S=!1,this.#C=!0,n&&r?.open(n);break;case`rename`:n&&this.#F(n);break;case`cancel-rename`:this.#I(!0);break;case`delete`:if(!n)break;this.#a===n?(this.#N(null),r?.remove(n)):this.#N(n);break;case`toggle-rail`:this.#S=!this.#S;break;case`dismiss`:r?.dismissError();break;case`attach`:this.#w.fileInput.click();break;case`detach`:n&&r?.detach(n);break;case`stop`:r?.stop();break;case`copy`:this.#z(t,Number(t.dataset.index));break;case`rate`:t.dataset.query&&r?.rate(t.dataset.query,Number(t.dataset.rating))}this.#w.layout.classList.toggle(`rail-open`,this.#S)}#N(e){this.#o!==null&&clearTimeout(this.#o),this.#o=e===null?null:setTimeout(()=>this.#N(null),qr),this.#a!==e&&(this.#a=e,this.#P(),e!==null&&this.#R(`delete`,e))}#P(){this.#q(this.#U(),this.#s?.state??null,this.#s?.busy??!1)}#F(e){let t=this.#s?.state.conversations.find(t=>t.id===e);if(!t)return;let n=Q(`input`,{attrs:{type:`text`,"aria-label":this.#U().newTitle}});n.value=t.title??``,n.addEventListener(`input`,()=>{let e=n.parentElement?.querySelector(`[type=submit]`);e&&(e.disabled=!n.value.trim())}),this.#i={id:e,input:n},this.#P(),n.focus(),n.select()}#I(e){let t=this.#i?.id;t!==void 0&&(this.#i=null,this.#P(),e&&this.#R(`rename`,t))}#L(){let e=this.#i,t=e?.input.value.trim();e&&t&&!this.#s?.busy&&(this.#I(!0),this.#s?.rename(e.id,t))}#R(e,t){for(let n of this.#w.conversations.querySelectorAll(`[data-action="${e}"]`))n.dataset.id===t&&n.focus()}#z(e,t){let n=this.#s?.state.messages[t];if(!n||!navigator.clipboard)return;let r=this.#U();navigator.clipboard.writeText(n.text).then(()=>{e.replaceChildren(zr(`check`)),e.setAttribute(`aria-label`,r.copied),setTimeout(()=>{e.replaceChildren(zr(`copy`)),e.setAttribute(`aria-label`,r.copy)},1500)})}#B(e){let t=e.target;if(!(t instanceof HTMLDetailsElement)||!t.open)return;let{message:n,source:r}=t.dataset,i=t.querySelector(`.source-text`);if(!i||i.hasChildNodes()||n===void 0)return;let a=this.#s?.state.messages[Number(n)],o=a?.role===`assistant`?a.sources[Number(r)]:void 0;if(!o)return;xr(i,o.text??``);let s=$r(o.url);s&&i.append(Q(`a`,{text:s,attrs:{href:s,target:`_blank`,rel:`noopener noreferrer`}}))}#V(){let e=this.#s,t=this.#w.input.value.trim();e&&t&&!this.#w.send.disabled&&(this.#w.input.value=``,this.#C=!0,e.send(t,{context:this.#n}),this.#ae())}#H(){return this.closest(`[lang]`)?.getAttribute(`lang`)??(typeof document>`u`?null:document.documentElement.lang)}#U(){return Ir(this.#H(),this.#t)}#W(e=!1){if(e&&(this.#d=!0),this.#u)return;this.#u=!0;let t=()=>{this.#u=!1,this.#G()};typeof requestAnimationFrame==`function`?requestAnimationFrame(t):setTimeout(t,16)}#G(){let e=this.#U(),t=this.#s?.state??null,n=this.#s?.busy??!1,r=this.#d?null:this.#f,i=n!==this.#p||r===null;this.#d=!1,this.#f=t,this.#p=n;let a=(...e)=>r===null||t===null||e.some(e=>r[e]!==t[e]);r===null&&this.#K(e),(i||a(`conversations`,`activeId`,`conversationsLoading`,`conversationsFailed`,`agentId`))&&this.#q(e,t,n),a(`agent`,`agentId`)&&this.#X(e,t),a(`error`)&&this.#Z(e,t),a(`messages`,`loadingHistory`,`agent`)&&this.#Q(e,t,r===null||a(`agent`)),this.#ne(e,t,r===null),this.#re(e,t),(i||a(`files`,`agentId`))&&this.#ie(e,t,n);let o=this.hasAttribute(`developer`);this.#w.developer.hidden=!o;let s=this.#r;this.#r=!1,o&&(s||a(`requests`,`events`,`error`,`agent`,`activeId`))?this.#se(e,t):o&&a(`tokens`)&&this.#v&&t&&(this.#v.textContent=e.events(t.tokens)),this.#w.layout.classList.toggle(`rail-open`,this.#S),this.#C&&(this.#w.transcript.scrollTop=this.#w.transcript.scrollHeight)}#K(e){let t=this.#w;t.rail.setAttribute(`aria-label`,e.conversations),t.newButton.replaceChildren(zr(`add`),e.newConversation);for(let[n,r]of[[t.railToggle,e.conversations],[t.dismiss,e.dismiss],[t.attach,e.attach],[t.send,e.send],[t.stop,e.stop]])n.setAttribute(`aria-label`,r),n.title=r;t.input.placeholder=e.placeholder,t.input.setAttribute(`aria-label`,e.placeholder),t.footnote.textContent=e.disclaimer,t.loading.textContent=e.loadingHistory,t.developerSummary.textContent=e.developer}#q(e,t,n){let r=this.#w;r.newButton.disabled=!t?.agentId||n;let i=t?.conversations??[],a=!t?.agentId||i.length>0?``:t.conversationsLoading?e.loading:t.conversationsFailed?e.conversationsFailed:e.noConversations;r.railStatus.textContent=a,r.railStatus.hidden=a===``;let o=this.#i;o&&!i.some(e=>e.id===o.id)&&(this.#i=null);let s=this.shadowRoot?.activeElement,c=s?r.conversations.contains(s):!1,l=this.#i?.input,u=c&&s===l,d=u?[l.selectionStart,l.selectionEnd]:[],{action:f,id:p}=c&&!u?s?.dataset??{}:{};r.conversations.replaceChildren(...i.map(r=>this.#Y(e,r,r.id===t?.activeId,n))),u&&l.isConnected?(l.focus(),l.setSelectionRange(d[0]??null,d[1]??null)):f&&p&&this.#R(f,p)}#J(e,t){return new Intl.DateTimeFormat(e.locale,{dateStyle:`short`,timeStyle:`short`}).format(t)}#Y(e,t,n,r){let i=this.#J(e,t.last_message_at),a=t.title??i,o=(t.title?i:e.untitled)+(t.enabled?``:` · ${e.disabled}`),s=Q(`button`,{class:`open`,attrs:{type:`button`,"data-action":`open`,"data-id":t.id}},Q(`span`,{class:`title`,text:a}),Q(`span`,{class:`meta`,text:o}));n&&s.setAttribute(`aria-current`,`true`),s.disabled=r;let c=Q(`li`,{class:n?`conversation active`:`conversation`});if(this.#i?.id===t.id){let{input:t}=this.#i,n=$(`check`,e.save,{type:`submit`});return n.disabled=r||!t.value.trim(),c.append(Q(`form`,{class:`rename`},t,n,$(`close`,e.cancel,{"data-action":`cancel-rename`}))),c}let l=$(`edit`,e.renameConversation(a),{"data-action":`rename`,"data-id":t.id});l.disabled=r;let u=this.#a===t.id,d=$(`delete`,u?e.confirmDelete(a):e.deleteConversation(a),{"data-action":`delete`,"data-id":t.id},u?`danger confirming`:`danger`);return u&&d.replaceChildren(e.confirmDeleteShort),d.disabled=r,c.append(s,l,d),c}#X(e,t){let n=this.#w;n.agentName.textContent=t?.agent?.name??t?.agentId??e.noAgent,n.agentDescription.textContent=t?.agent?.description??``,n.agentDescription.hidden=!t?.agent?.description}#Z(e,t){let n=this.#w,r=t?.error??null;n.banner.hidden=r===null,r&&(n.bannerTitle.textContent=e.errors[r.kind]+(r.kind===`rate_limited`&&r.retryAfter?` ${e.retryIn(r.retryAfter)}`:``),n.bannerDetail.textContent=[r.message,r.authDescription].filter(Boolean).join(` · `))}#Q(e,t,n){let r=this.#w,i=t?.loadingHistory??!1;r.loading.hidden=!i;let a=i?[]:t?.messages??[],o=t?.agent?.name??e.agent,s=a.map((t,r)=>{let i=n?void 0:this.#m[r];return i?.message===t?i:i&&ri(i.message,t)?(ii(i.node,t.rating),{message:t,node:i.node}):{message:t,node:t.role===`user`?this.#$(e,t):this.#ee(e,t,r,o)}});this.#m=s;let c=r.messages.children;(s.length!==c.length||s.some(({node:e},t)=>e!==c[t]))&&r.messages.replaceChildren(...s.map(({node:e})=>e))}#$(e,t){return Q(`article`,{class:`message user`,part:`message message-user`,attrs:{"aria-label":e.you}},Q(`div`,{class:`bubble`,text:t.text}),t.attachments.length>0&&Q(`ul`,{class:`chips`},...t.attachments.map(e=>Q(`li`,{class:`chip`},Q(`span`,{class:`chip-label`,text:e.name})))))}#ee(e,t,n,r){let i=Q(`div`,{class:`answer markdown`});xr(i,t.text);let a=Q(`article`,{class:`message assistant`,part:`message message-assistant`,attrs:{"aria-label":r}},i);t.interrupted&&a.append(Q(`p`,{class:`note`,text:e.interrupted})),t.error&&a.append(Q(`p`,{class:`turn-error`,text:b(t.error,{failed:e.turnFailed,trace:e.trace})})),t.sources.length>0&&a.append(this.#te(e,t.sources,n));let o=Q(`div`,{class:`actions`},t.text&&Qr()&&$(`copy`,e.copy,{"data-action":`copy`,"data-index":String(n)}));return t.idQuery&&(o.append($(`thumbUp`,e.rateUp,{"data-action":`rate`,"data-query":t.idQuery,"data-rating":`5`}),$(`thumbDown`,e.rateDown,{"data-action":`rate`,"data-query":t.idQuery,"data-rating":`1`})),ii(o,t.rating)),a.append(o),a}#te(e,t,n){return Q(`details`,{class:`sources`,part:`sources`},Q(`summary`,{text:e.sources(t.length)}),Q(`ol`,{},...t.map((t,r)=>{let i=ti(e,t);return Q(`li`,{},Q(`details`,{class:`source`,attrs:{"data-message":String(n),"data-source":String(r)}},Q(`summary`,{},ei(e,t),i&&Q(`span`,{class:`source-page`,text:` · ${i}`})),Q(`div`,{class:`source-text markdown`})))})))}#ne(e,t,n){let r=this.#w,i=t?.turn??null;if(!n&&i===this.#h)return;if(r.live.hidden=i===null,!i){this.#h=null,r.liveAnswer.replaceChildren();return}r.liveActivity.textContent=i.activity??e.thinking;let a=performance.now()-this.#g;if(!n&&this.#h!==null&&i.text!==this.#h.text&&a<Gr){this.#_||(this.#_=!0,setTimeout(()=>{this.#_=!1,this.#W()},Gr-a));return}let o=n||this.#h?.text!==i.text;this.#h=i,o&&(this.#g=performance.now(),r.liveAnswer.hidden=!i.text,xr(r.liveAnswer,i.text))}#re(e,t){let n=this.#w,r=t===null||!t.loadingHistory&&t.messages.length===0&&!t.turn;n.empty.hidden=!r,r&&(n.emptyTitle.textContent=t===null?e.notConnected:t.agentId?t.agent?e.ask(t.agent.name):e.askGeneric:e.noAgent)}#ie(e,t,n){let r=this.#w,i=t?.files??[];r.files.hidden=i.length===0,r.files.replaceChildren(...i.map(t=>{let n=t.name+(t.status===`processing`?` · ${e.processing}`:t.status===`error`?` · ${e.fileError}`:``);return Q(`li`,{class:t.status===`error`?`chip error`:`chip`,attrs:{title:t.error??n}},Q(`span`,{class:`chip-label`,text:n}),$(`close`,e.removeFile(t.name),{"data-action":`detach`,"data-id":t.id_file}))}));let a=!t?.agentId;r.input.disabled=a,r.attach.disabled=a||n,r.send.hidden=n,r.stop.hidden=!n,this.#ae()}#ae(){let e=this.#s?.state,t=(e?.uploading??0)>0||(e?.files.some(e=>e.status===`processing`)??!1);this.#w.send.disabled=!e?.agentId||(this.#s?.busy??!1)||t||!this.#w.input.value.trim()}#oe(){if(!this.#n)return null;let e;try{e=JSON.stringify(this.#n)}catch{return`?`}let t=new TextEncoder().encode(e).length;return`${e.length>Wr?`${e.slice(0,Wr)}…`:e} · ${t} B`}#se(e,t){let n=this.#w;if(!t||!this.#s){n.developerBody.replaceChildren();return}let r=e=>Q(`dl`,{},...e.flatMap(([e,t])=>[Q(`dt`,{text:e}),Q(`dd`,{text:t})])),{agent:i,error:a}=t,o=[r([[`API`,this.#s.client.apiBase],[`X-Tenant`,this.getAttribute(`tenant`)??e.none],[e.agent,t.agentId??e.none],[e.publishedVersion,i?i.published_version_number===null?e.notPublished:`v${i.published_version_number}`:e.none],[e.conversation,t.activeId??e.none],[e.context,this.#oe()??e.none]])];a&&o.push(Q(`h4`,{text:e.lastError}),r([[`status`,`${a.status} · ${a.kind}`],[`message`,a.message],[`error_code`,a.errorCode??e.none],[`error_description`,a.authDescription??e.none],[`X-Request-Id`,a.requestId??e.none]])),this.#v=Q(`h4`,{text:e.events(t.tokens)}),o.push(this.#v,Q(`ol`,{class:`log`},...[...t.events].reverse().map(e=>Q(`li`,{text:ni(e,t.turnStartedAt)}))),Q(`h4`,{text:e.requests}),Q(`ol`,{class:`log`},...t.requests.map(t=>Q(`li`,{class:t.status===0||t.status>=400?`bad`:``,text:`${t.status} ${t.method} ${t.path} · ${t.durationMs} ms`+(t.retriedWithFreshToken?` · ${e.renewed}`:``)+(t.requestId?` · ${t.requestId}`:``)})))),n.developerBody.replaceChildren(...o)}};function oi(e=Vr){typeof customElements>`u`||customElements.get(e)||customElements.define(e,e===`aicore-agent-chat`?ai:class extends ai{})}oi();export{Vr as AICORE_AGENT_CHAT_TAG,x as AICORE_EVENTS,ai as AicoreAgentChat,ae as AicoreChatClient,Mr as AicoreChatSession,t as AicoreError,Sr as CHAT_CHANGE,_ as EMPTY_TURN,f as EXPIRY_SKEW_MS,wr as RATING_DOWN,Cr as RATING_UP,g as TokenCache,y as answerOf,re as apiBaseOf,m as decodeJwtClaims,oi as defineAicoreAgentChat,c as errorFromResponse,v as foldTurn,a as isAbortError,s as isInvalidToken,h as jwtExpiry,r as kindOf,jr as messagesFromHistory,o as parseBearerChallenge,C as randomId,i as toAicoreError,b as turnErrorText};
511
+ `,ga=`aicore-agent-chat`,_a=`.pdf,.docx,.txt,.md,.html,.xlsx,.epub`,va=[y.turn,y.error,y.authRequired,y.tenantRefused],ya=160,ba=100,xa=48,Sa=4e3,Ca=[`getToken`,`strings`,`context`,`baseUrl`,`agent`,`tenant`,`conversation`,`developer`,`copyAnswer`,`noDisclaimer`],wa=typeof HTMLElement>`u`?class{}:HTMLElement,Ta;function Ea(){if(Ta!==void 0)return Ta;try{let e=new CSSStyleSheet;e.replaceSync(ha),Ta=`adoptedStyleSheets`in ShadowRoot.prototype?e:null}catch{Ta=null}return Ta}var Da=()=>typeof navigator<`u`&&navigator.clipboard!==void 0;function Q(e,t={},...n){let r=document.createElement(e);t.class&&(r.className=t.class),t.part&&r.setAttribute(`part`,t.part),t.text!==void 0&&(r.textContent=t.text);for(let[e,n]of Object.entries(t.attrs??{}))r.setAttribute(e,n);for(let e of n)e&&r.append(e);return r}function $(e,t,n={},r=``){return Q(`button`,{class:`icon-button ${r}`.trim(),attrs:{type:`button`,"aria-label":t,title:t,...n}},Qi(e))}function Oa(e){return e&&/^https?:\/\//i.test(e)?e:null}function ka(e,t){return t.title??t.name??t.url??t.id_document??e.untitledSource}function Aa(e,t){return t.page==null?t.part==null?``:e.part(t.part):e.page(String(t.page))}function ja(t,n){let r=n===null?``:`+${((t.at-n)/1e3).toFixed(1)}s`,i=e(t.data)?t.data:{},a=typeof i.name==`string`?`${typeof i.node==`string`?`${i.node} → `:``}${i.name}`:``;if(!a)try{a=JSON.stringify(t.data)??``}catch{a=``}return a.length>ya&&(a=`${a.slice(0,ya)}…`),[r,t.kind,t.id?`#${t.id}`:``,a].filter(Boolean).join(` `)}function Ma(e,t){if(e.role!==`assistant`||t.role!==`assistant`)return!1;let n=n=>e[n]===t[n];return n(`text`)&&n(`sources`)&&n(`error`)&&n(`idQuery`)&&n(`interrupted`)}function Na(e,t){for(let n of e.querySelectorAll(`[data-action="rate"]`)){let e=Number(n.dataset.rating)===5;n.setAttribute(`aria-pressed`,String(t!==null&&(e?t>=4:t<=2)))}}var Pa=class extends wa{static observedAttributes=[`base-url`,`agent`,`tenant`,`conversation`,`lang`,`developer`,`copy-answer`,`no-disclaimer`];#e=null;#t=null;#n=null;#r=!1;#i=null;#a=null;#o=null;#s=null;#c=``;#l=null;#u=!1;#d=!0;#f=null;#p=!1;#m=[];#h=null;#g=0;#_=!1;#v=null;#y=!1;#b=!1;#x=!1;#S=!1;#C=!0;#w;constructor(){super();let e=this.attachShadow({mode:`open`}),t=Q(`button`,{class:`new-conversation`,attrs:{type:`button`,"data-action":`new`}}),n=Q(`p`,{class:`rail-status muted small`}),r=Q(`ul`,{class:`conversations`}),i=Q(`aside`,{class:`rail`,part:`rail`},t,n,r),a=$(`menu`,``,{"data-action":`toggle-rail`});a.classList.add(`rail-toggle`);let o=Q(`span`,{class:`agent-name`}),s=Q(`span`,{class:`agent-description`}),c=Q(`header`,{class:`header`,part:`header`},a,Q(`div`,{class:`agent`},o,s)),l=Q(`strong`),u=Q(`span`,{class:`small`}),d=$(`close`,``,{"data-action":`dismiss`}),f=Q(`div`,{class:`banner`,part:`error`,attrs:{role:`alert`}},Q(`div`,{class:`banner-text`},l,u),d);f.hidden=!0;let p=Q(`p`,{class:`empty-title`}),m=Q(`div`,{class:`empty`},p),h=Q(`p`,{class:`status`}),ee=Q(`div`,{class:`messages`}),g=Q(`div`,{class:`answer markdown`}),_=Q(`span`),te=Q(`article`,{class:`message assistant`,part:`message message-assistant`,attrs:{"aria-busy":`true`}},g,Q(`div`,{class:`status`},Q(`span`,{class:`dots`},Q(`span`),Q(`span`),Q(`span`)),_));te.hidden=!0;let ne=Q(`div`,{class:`thread`,attrs:{role:`log`,"aria-live":`polite`}},m,h,ee,te);ee.style.display=`contents`;let v=Q(`div`,{class:`transcript`,part:`transcript`},ne),y=Q(`ul`,{class:`chips`}),re=Q(`input`,{attrs:{type:`file`,multiple:``,accept:_a}});re.hidden=!0;let b=$(`attach`,``,{"data-action":`attach`}),x=Q(`textarea`,{part:`input`,attrs:{rows:`1`}}),ie=Q(`button`,{class:`send`,part:`send`,attrs:{type:`submit`}},Qi(`send`)),ae=Q(`button`,{class:`send`,part:`stop`,attrs:{type:`button`,"data-action":`stop`}},Qi(`stop`)),oe=Q(`p`,{class:`footnote`}),S=Q(`form`,{class:`composer`,part:`composer`},y,Q(`div`,{class:`box`},b,x,ie,ae),oe,re),C=Q(`summary`),se=Q(`div`),ce=Q(`details`,{class:`developer`,part:`developer`},C,se),le=Q(`div`,{class:`layout`},i,Q(`section`,{class:`main`},c,f,v,S,ce)),w=Ea();w?e.adoptedStyleSheets=[w]:e.append(Q(`style`,{text:ha})),e.append(le),this.#w={layout:le,rail:i,newButton:t,railStatus:n,conversations:r,railToggle:a,agentName:o,agentDescription:s,banner:f,bannerTitle:l,bannerDetail:u,dismiss:d,transcript:v,thread:ne,empty:m,emptyTitle:p,loading:h,messages:ee,live:te,liveAnswer:g,liveActivity:_,files:y,fileInput:re,attach:b,input:x,send:ie,stop:ae,footnote:oe,developer:ce,developerSummary:C,developerBody:se},e.addEventListener(`click`,e=>this.#M(e)),r.addEventListener(`submit`,e=>{e.preventDefault(),this.#L()}),r.addEventListener(`keydown`,e=>{e.key===`Escape`&&this.#i&&(e.preventDefault(),this.#I(!0))}),ne.addEventListener(`toggle`,e=>this.#B(e),!0),S.addEventListener(`submit`,e=>{e.preventDefault(),this.#V()}),x.addEventListener(`input`,()=>this.#ue()),x.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),this.#V())}),re.addEventListener(`change`,()=>{let e=Array.from(re.files??[]);re.value=``,e.length>0&&this.#s?.attach(e)}),v.addEventListener(`scroll`,()=>{this.#C=v.scrollHeight-v.scrollTop-v.clientHeight<xa},{passive:!0}),typeof ResizeObserver<`u`&&new ResizeObserver(()=>{this.#C&&(v.scrollTop=v.scrollHeight)}).observe(v)}get getToken(){return this.#e}set getToken(e){let t=typeof e==`function`?e:null,n=t!==this.#e;this.#e=t,n&&t&&this.#s&&(this.#s.client.clearToken(),this.#s.client.checkIdentity()),this.#E()}get strings(){return this.#t}set strings(t){this.#t=e(t)?t:null,this.#J(!0)}get context(){return this.#n}set context(t){this.#n=e(t)?t:null,this.#r=!0,this.#J()}get baseUrl(){return this.getAttribute(`base-url`)}set baseUrl(e){this.#T(`base-url`,e)}get agent(){return this.getAttribute(`agent`)}set agent(e){this.#T(`agent`,e)}get tenant(){return this.getAttribute(`tenant`)}set tenant(e){this.#T(`tenant`,e)}get conversation(){return this.getAttribute(`conversation`)}set conversation(e){this.#T(`conversation`,e)}get developer(){return this.hasAttribute(`developer`)}set developer(e){this.toggleAttribute(`developer`,!!e)}get copyAnswer(){return this.hasAttribute(`copy-answer`)}set copyAnswer(e){this.toggleAttribute(`copy-answer`,!!e)}get noDisclaimer(){return this.hasAttribute(`no-disclaimer`)}set noDisclaimer(e){this.toggleAttribute(`no-disclaimer`,!!e)}get state(){return this.#s?.state??null}#T(e,t){t==null||t===``?this.removeAttribute(e):this.setAttribute(e,String(t))}connectedCallback(){let e=this;for(let t of Ca)if(Object.prototype.hasOwnProperty.call(this,t)){let n=e[t];delete e[t],e[t]=n}this.#E(),this.#J(!0)}disconnectedCallback(){queueMicrotask(()=>{this.isConnected||this.#D()})}attributeChangedCallback(e,t,n){if(t!==n)switch(e){case`base-url`:case`tenant`:this.#E();break;case`agent`:this.#O(`agent`);break;case`conversation`:this.#O(`conversation`);break;default:this.#J(!0)}}#E(){if(!this.isConnected)return;let e=this.getAttribute(`base-url`),t=this.getAttribute(`tenant`),n=e&&this.#e?`${e}\n${t??``}`:``;if(n!==this.#c){if(this.#D(),this.#c=n,e&&n){let n=new Wi({baseUrl:e,tenant:t,getToken:async e=>this.#e?this.#e(e):null});for(let e of va)n.client.addEventListener(e,this.#A);n.addEventListener(Pi,this.#j),this.#s=n,n.setAgent(this.getAttribute(`agent`)),this.#k()}this.#J(!0)}}#D(){let e=this.#s;if(e){for(let t of va)e.client.removeEventListener(t,this.#A);e.removeEventListener(Pi,this.#j),e.dispose()}this.#s=null,this.#c=``,this.#l=null}#O(e){e===`agent`?this.#y=!0:this.#b=!0,this.#x||(this.#x=!0,queueMicrotask(()=>{let e=this.#y,t=this.#b;this.#x=this.#y=this.#b=!1;let n=this.#s;if(n){if(e){this.#S=!1;let e=this.getAttribute(`agent`);n.setAgent(e===``?null:e),t&&this.#k()}else this.#k()}}))}#k(){let e=this.#s;if(!e)return;let t=this.getAttribute(`conversation`);t?e.open(t):e.state.activeId&&!e.busy&&e.newConversation()}#A=e=>{this.dispatchEvent(new CustomEvent(e.type,{detail:e.detail,bubbles:!0,composed:!0}))};#j=()=>{let e=this.#s?.state;e?.agentId&&e.activeId!==this.#l&&(this.#l=e.activeId,this.dispatchEvent(new CustomEvent(y.conversation,{detail:{idConv:e.activeId,idAgent:e.agentId},bubbles:!0,composed:!0}))),this.#J()};#M(e){let t=e.target?.closest(`[data-action]`);this.#S&&!e.target?.closest(`.rail, .rail-toggle`)&&(this.#S=!1,this.#w.layout.classList.remove(`rail-open`));let{id:n}=t?.dataset??{};if(this.#i&&!e.target?.closest(`.rename`)&&this.#I(!1),this.#a!==null&&(t?.dataset.action!==`delete`||n!==this.#a)&&this.#N(null),!t||t.disabled)return;let r=this.#s;switch(t.dataset.action){case`new`:this.#S=!1,r?.newConversation(),this.#w.input.focus();break;case`open`:this.#S=!1,this.#C=!0,n&&r?.open(n);break;case`rename`:n&&this.#F(n);break;case`cancel-rename`:this.#I(!0);break;case`delete`:if(!n)break;this.#a===n?(this.#N(null),r?.remove(n)):this.#N(n);break;case`toggle-rail`:this.#S=!this.#S;break;case`dismiss`:r?.dismissError();break;case`attach`:this.#w.fileInput.click();break;case`detach`:n&&r?.detach(n);break;case`stop`:r?.stop();break;case`copy`:this.#z(t,Number(t.dataset.index));break;case`rate`:t.dataset.query&&r?.rate(t.dataset.query,Number(t.dataset.rating))}this.#w.layout.classList.toggle(`rail-open`,this.#S)}#N(e){this.#o!==null&&clearTimeout(this.#o),this.#o=e===null?null:setTimeout(()=>this.#N(null),Sa),this.#a!==e&&(this.#a=e,this.#P(),e!==null&&this.#R(`delete`,e))}#P(){this.#Z(this.#K(),this.#s?.state??null,this.#s?.busy??!1)}#F(e){let t=this.#s?.state.conversations.find(t=>t.id===e);if(!t)return;let n=Q(`input`,{attrs:{type:`text`,"aria-label":this.#K().newTitle}});n.value=t.title??``,n.addEventListener(`input`,()=>{let e=n.parentElement?.querySelector(`[type=submit]`);e&&(e.disabled=!n.value.trim())}),this.#i={id:e,input:n},this.#P(),n.focus(),n.select()}#I(e){let t=this.#i?.id;t!==void 0&&(this.#i=null,this.#P(),e&&this.#R(`rename`,t))}#L(){let e=this.#i,t=e?.input.value.trim();e&&t&&!this.#s?.busy&&(this.#I(!0),this.#s?.rename(e.id,t))}#R(e,t){for(let n of this.#w.conversations.querySelectorAll(`[data-action="${e}"]`))n.dataset.id===t&&n.focus()}#z(e,t){let n=this.#s?.state.messages[t];if(!n||!navigator.clipboard)return;let r=this.#K();navigator.clipboard.writeText(n.text).then(()=>{e.replaceChildren(Qi(`check`)),e.setAttribute(`aria-label`,r.copied),setTimeout(()=>{e.replaceChildren(Qi(`copy`)),e.setAttribute(`aria-label`,r.copy)},1500)})}#B(e){let t=e.target;if(!(t instanceof HTMLDetailsElement)||!t.open)return;let{message:n,source:r}=t.dataset,i=t.querySelector(`.source-text`);if(!i||i.hasChildNodes()||n===void 0)return;let a=this.#s?.state.messages[Number(n)],o=a?.role===`assistant`?a.sources[Number(r)]:void 0;if(!o)return;Ni(i,o.text??``,this.#q(!1));let s=Oa(o.url);s&&i.append(Q(`a`,{text:s,attrs:{href:s,target:`_blank`,rel:`noopener noreferrer`}}))}#V(){let e=this.#s,t=this.#w.input.value.trim();e&&t&&!this.#w.send.disabled&&(this.#w.input.value=``,this.#C=!0,e.send(t,{context:this.#n}),this.#ue())}#H(e){let t=this.#s;return!t||!this.#U()?!1:(this.#C=!0,t.send(e,{context:this.#n}),this.#ue(),!0)}#U(){let e=this.#s,t=e?.state;return!!e&&!!t?.agentId&&!e.busy&&t.uploading===0&&t.files.length===0}#W(e){let t=e?.messages??[],n=this.#s?.busy??!1,r=this.#U()?e=>this.#H(e):void 0;return da(t).map(e=>({send:r,working:n,sent:e}))}#G(){return this.closest(`[lang]`)?.getAttribute(`lang`)??(typeof document>`u`?null:document.documentElement.lang)}#K(){return Yi(this.#G(),this.#t)}#q(e,t=!1,n){return{host:this,widgets:e,live:t,lang:qi(this.#G()),strings:this.#K(),interface:n??{working:t,sent:/* @__PURE__ */ new Map}}}#J(e=!1){if(e&&(this.#d=!0),this.#u)return;this.#u=!0;let t=()=>{this.#u=!1,this.#Y()};typeof requestAnimationFrame==`function`?requestAnimationFrame(t):setTimeout(t,16)}#Y(){let e=this.#K(),t=this.#s?.state??null,n=this.#s?.busy??!1,r=this.#d?null:this.#f,i=n!==this.#p||r===null;this.#d=!1,this.#f=t,this.#p=n;let a=(...e)=>r===null||t===null||e.some(e=>r[e]!==t[e]);if(r===null&&this.#X(e),(i||a(`conversations`,`activeId`,`conversationsLoading`,`conversationsFailed`,`agentId`))&&this.#Z(e,t,n),a(`agent`,`agentId`)&&this.#ee(e,t),a(`error`)&&this.#te(e,t),a(`messages`,`loadingHistory`,`agent`)&&this.#ne(e,t,r===null||a(`agent`)),i||a(`messages`,`files`,`uploading`,`agentId`)){let e=this.#W(t);this.#m.forEach(({node:t},n)=>{let r=e[n];r&&fn(t,r)})}this.#se(e,t,r===null),this.#ce(e,t),(i||a(`files`,`agentId`))&&this.#le(e,t,n);let o=this.hasAttribute(`developer`);this.#w.developer.hidden=!o;let s=this.#r;this.#r=!1,o&&(s||a(`requests`,`events`,`error`,`agent`,`activeId`))?this.#fe(e,t):o&&a(`tokens`)&&this.#v&&t&&(this.#v.textContent=e.events(t.tokens)),this.#w.layout.classList.toggle(`rail-open`,this.#S),this.#C&&(this.#w.transcript.scrollTop=this.#w.transcript.scrollHeight)}#X(e){let t=this.#w;t.rail.setAttribute(`aria-label`,e.conversations),t.newButton.replaceChildren(Qi(`add`),e.newConversation);for(let[n,r]of[[t.railToggle,e.conversations],[t.dismiss,e.dismiss],[t.attach,e.attach],[t.send,e.send],[t.stop,e.stop]])n.setAttribute(`aria-label`,r),n.title=r;t.input.placeholder=e.placeholder,t.input.setAttribute(`aria-label`,e.placeholder),t.footnote.textContent=e.disclaimer,t.footnote.hidden=!e.disclaimer||this.hasAttribute(`no-disclaimer`),t.loading.textContent=e.loadingHistory,t.developerSummary.textContent=e.developer}#Z(e,t,n){let r=this.#w;r.newButton.disabled=!t?.agentId||n;let i=t?.conversations??[],a=!t?.agentId||i.length>0?``:t.conversationsLoading?e.loading:t.conversationsFailed?e.conversationsFailed:e.noConversations;r.railStatus.textContent=a,r.railStatus.hidden=a===``;let o=this.#i;o&&!i.some(e=>e.id===o.id)&&(this.#i=null);let s=this.shadowRoot?.activeElement,c=s?r.conversations.contains(s):!1,l=this.#i?.input,u=c&&s===l,d=u?[l.selectionStart,l.selectionEnd]:[],{action:f,id:p}=c&&!u?s?.dataset??{}:{};r.conversations.replaceChildren(...i.map(r=>this.#$(e,r,r.id===t?.activeId,n))),u&&l.isConnected?(l.focus(),l.setSelectionRange(d[0]??null,d[1]??null)):f&&p&&this.#R(f,p)}#Q(e,t){return new Intl.DateTimeFormat(e.locale,{dateStyle:`short`,timeStyle:`short`}).format(t)}#$(e,t,n,r){let i=this.#Q(e,t.last_message_at),a=t.title??i,o=(t.title?i:e.untitled)+(t.enabled?``:` · ${e.disabled}`),s=Q(`button`,{class:`open`,attrs:{type:`button`,"data-action":`open`,"data-id":t.id}},Q(`span`,{class:`title`,text:a}),Q(`span`,{class:`meta`,text:o}));n&&s.setAttribute(`aria-current`,`true`),s.disabled=r;let c=Q(`li`,{class:n?`conversation active`:`conversation`});if(this.#i?.id===t.id){let{input:t}=this.#i,n=$(`check`,e.save,{type:`submit`});return n.disabled=r||!t.value.trim(),c.append(Q(`form`,{class:`rename`},t,n,$(`close`,e.cancel,{"data-action":`cancel-rename`}))),c}let l=$(`edit`,e.renameConversation(a),{"data-action":`rename`,"data-id":t.id});l.disabled=r;let u=this.#a===t.id,d=$(`delete`,u?e.confirmDelete(a):e.deleteConversation(a),{"data-action":`delete`,"data-id":t.id},u?`danger confirming`:`danger`);return u&&d.replaceChildren(e.confirmDeleteShort),d.disabled=r,c.append(s,l,d),c}#ee(e,t){let n=this.#w;n.agentName.textContent=t?.agent?.name??t?.agentId??e.noAgent,n.agentDescription.textContent=t?.agent?.description??``,n.agentDescription.hidden=!t?.agent?.description}#te(e,t){let n=this.#w,r=t?.error??null;n.banner.hidden=r===null,r&&(n.bannerTitle.textContent=e.errors[r.kind]+(r.kind===`rate_limited`&&r.retryAfter?` ${e.retryIn(r.retryAfter)}`:``),n.bannerDetail.textContent=[r.message,r.authDescription].filter(Boolean).join(` · `))}#ne(e,t,n){let r=this.#w,i=t?.loadingHistory??!1;r.loading.hidden=!i;let a=i?[]:t?.messages??[],o=t?.agent?.name??e.agent,s=this.#W(t),c=a.map((t,r)=>{let i=n?void 0:this.#m[r];return i?.message===t?i:i&&Ma(i.message,t)?(Na(i.node,t.rating),{message:t,node:i.node}):{message:t,node:t.role===`user`?this.#ie(e,t):this.#ae(e,t,r,o,s[r])}}),l=new Set(c.map(({node:e})=>e));for(let{node:e}of this.#m)l.has(e)||pn(e);this.#m=c;let u=r.messages.children;(c.length!==u.length||c.some(({node:e},t)=>e!==u[t]))&&r.messages.replaceChildren(...c.map(({node:e})=>e))}#re(e,t){let n=sa(t);if(!n)return Q(`div`,{class:`bubble`,text:t});let{label:r,fields:i}=ma(n,e);return Q(`ul`,{class:`chips action-summary`,attrs:{"aria-label":e.a2uiAction(r)}},Q(`li`,{class:`chip action`},Qi(`check`),Q(`span`,{class:`chip-label`,text:r})),...i.map(([e,t])=>Q(`li`,{class:`chip`},Q(`span`,{class:`chip-label`},Q(`span`,{class:`muted`,text:`${e}: `}),t))))}#ie(e,t){return Q(`article`,{class:`message user`,part:`message message-user`,attrs:{"aria-label":e.you}},this.#re(e,t.text),t.attachments.length>0&&Q(`ul`,{class:`chips`},...t.attachments.map(e=>Q(`li`,{class:`chip`},Q(`span`,{class:`chip-label`,text:e.name})))))}#ae(e,t,n,r,i){let a=Q(`div`,{class:`answer markdown`});Ni(a,t.text,this.#q(!0,!1,i));let o=Q(`article`,{class:`message assistant`,part:`message message-assistant`,attrs:{"aria-label":r}},a);t.interrupted&&o.append(Q(`p`,{class:`note`,text:e.interrupted})),t.error&&o.append(Q(`p`,{class:`turn-error`,text:v(t.error,{failed:e.turnFailed,trace:e.trace})})),t.sources.length>0&&o.append(this.#oe(e,t.sources,n));let s=Q(`div`,{class:`actions`},t.text&&this.hasAttribute(`copy-answer`)&&Da()&&$(`copy`,e.copy,{"data-action":`copy`,"data-index":String(n)}));return t.idQuery&&(s.append($(`thumbUp`,e.rateUp,{"data-action":`rate`,"data-query":t.idQuery,"data-rating":`5`}),$(`thumbDown`,e.rateDown,{"data-action":`rate`,"data-query":t.idQuery,"data-rating":`1`})),Na(s,t.rating)),o.append(s),o}#oe(e,t,n){return Q(`details`,{class:`sources`,part:`sources`},Q(`summary`,{text:e.sources(t.length)}),Q(`ol`,{},...t.map((t,r)=>{let i=Aa(e,t);return Q(`li`,{},Q(`details`,{class:`source`,attrs:{"data-message":String(n),"data-source":String(r)}},Q(`summary`,{},ka(e,t),i&&Q(`span`,{class:`source-page`,text:` · ${i}`})),Q(`div`,{class:`source-text markdown`})))})))}#se(e,t,n){let r=this.#w,i=t?.turn??null;if(!n&&i===this.#h)return;if(r.live.hidden=i===null,!i){this.#h=null,pn(r.liveAnswer),r.liveAnswer.replaceChildren();return}r.liveActivity.textContent=i.activity??e.thinking;let a=performance.now()-this.#g;if(!n&&this.#h!==null&&i.text!==this.#h.text&&a<ba){this.#_||(this.#_=!0,setTimeout(()=>{this.#_=!1,this.#J()},ba-a));return}let o=n||this.#h?.text!==i.text;this.#h=i,o&&(this.#g=performance.now(),r.liveAnswer.hidden=!i.text,Ni(r.liveAnswer,i.text,this.#q(!0,!0)))}#ce(e,t){let n=this.#w,r=t===null||!t.loadingHistory&&t.messages.length===0&&!t.turn;n.empty.hidden=!r,r&&(n.emptyTitle.textContent=t===null?e.notConnected:t.agentId?t.agent?e.ask(t.agent.name):e.askGeneric:e.noAgent)}#le(e,t,n){let r=this.#w,i=t?.files??[];r.files.hidden=i.length===0,r.files.replaceChildren(...i.map(t=>{let n=t.name+(t.status===`processing`?` · ${e.processing}`:t.status===`error`?` · ${e.fileError}`:``);return Q(`li`,{class:t.status===`error`?`chip error`:`chip`,attrs:{title:t.error??n}},Q(`span`,{class:`chip-label`,text:n}),$(`close`,e.removeFile(t.name),{"data-action":`detach`,"data-id":t.id_file}))}));let a=!t?.agentId;r.input.disabled=a,r.attach.disabled=a||n,r.send.hidden=n,r.stop.hidden=!n,this.#ue()}#ue(){let e=this.#s?.state,t=(e?.uploading??0)>0||(e?.files.some(e=>e.status===`processing`)??!1);this.#w.send.disabled=!e?.agentId||(this.#s?.busy??!1)||t||!this.#w.input.value.trim()}#de(){if(!this.#n)return null;let e;try{e=JSON.stringify(this.#n)}catch{return`?`}let t=new TextEncoder().encode(e).length;return`${e.length>ya?`${e.slice(0,ya)}…`:e} · ${t} B`}#fe(e,t){let n=this.#w;if(!t||!this.#s){n.developerBody.replaceChildren();return}let r=e=>Q(`dl`,{},...e.flatMap(([e,t])=>[Q(`dt`,{text:e}),Q(`dd`,{text:t})])),{agent:i,error:a}=t,o=[r([[`API`,this.#s.client.apiBase],[`X-Tenant`,this.getAttribute(`tenant`)??e.none],[e.agent,t.agentId??e.none],[e.publishedVersion,i?i.published_version_number===null?e.notPublished:`v${i.published_version_number}`:e.none],[e.conversation,t.activeId??e.none],[e.context,this.#de()??e.none]])];a&&o.push(Q(`h4`,{text:e.lastError}),r([[`status`,`${a.status} · ${a.kind}`],[`message`,a.message],[`error_code`,a.errorCode??e.none],[`error_description`,a.authDescription??e.none],[`X-Request-Id`,a.requestId??e.none]])),this.#v=Q(`h4`,{text:e.events(t.tokens)}),o.push(this.#v,Q(`ol`,{class:`log`},...[...t.events].reverse().map(e=>Q(`li`,{text:ja(e,t.turnStartedAt)}))),Q(`h4`,{text:e.requests}),Q(`ol`,{class:`log`},...t.requests.map(t=>Q(`li`,{class:t.status===0||t.status>=400?`bad`:``,text:`${t.status} ${t.method} ${t.path} · ${t.durationMs} ms`+(t.retriedWithFreshToken?` · ${e.renewed}`:``)+(t.requestId?` · ${t.requestId}`:``)})))),n.developerBody.replaceChildren(...o)}};function Fa(e=ga){typeof customElements>`u`||customElements.get(e)||customElements.define(e,e===`aicore-agent-chat`?Pa:class extends Pa{})}Fa();export{ga as AICORE_AGENT_CHAT_TAG,y as AICORE_EVENTS,Pa as AicoreAgentChat,C as AicoreChatClient,Wi as AicoreChatSession,t as AicoreError,Pi as CHAT_CHANGE,g as EMPTY_TURN,f as EXPIRY_SKEW_MS,Ii as RATING_DOWN,Fi as RATING_UP,ee as TokenCache,Ni as a,ne as answerOf,ie as apiBaseOf,xi as c,ni as d,m as decodeJwtClaims,Fa as defineAicoreAgentChat,c as errorFromResponse,un as f,te as foldTurn,ia as i,a as isAbortError,s as isInvalidToken,h as jwtExpiry,r as kindOf,vi as l,e as m,Ui as messagesFromHistory,ra as n,wi as o,dn as p,o as parseBearerChallenge,fa as r,ae as randomId,Ti as s,aa as t,i as toAicoreError,v as turnErrorText,yi as u};
491
512
  //# sourceMappingURL=aicore-agent-chat.js.map