@kodaris/krubble-app-components 1.0.137 → 1.0.138
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/krubble-app.bundled.js +441 -187
- package/dist/krubble-app.bundled.js.map +1 -1
- package/dist/krubble-app.bundled.min.js +9 -4
- package/dist/krubble-app.bundled.min.js.map +1 -1
- package/dist/krubble-app.umd.js +442 -189
- package/dist/krubble-app.umd.js.map +1 -1
- package/dist/krubble-app.umd.min.js +13 -8
- package/dist/krubble-app.umd.min.js.map +1 -1
- package/dist/router.d.ts +47 -6
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +325 -76
- package/dist/router.js.map +1 -1
- package/dist/screen-nav.d.ts +2 -2
- package/dist/screen-nav.js +3 -3
- package/package.json +1 -1
|
@@ -14,18 +14,23 @@
|
|
|
14
14
|
* Copyright 2017 Google LLC
|
|
15
15
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
16
16
|
*/
|
|
17
|
-
const S=globalThis,I=S.trustedTypes,C=I?I.createPolicy("lit-html",{createHTML:e=>e}):void 0,E="$lit$",A=`lit$${Math.random().toFixed(9).slice(2)}$`,T="?"+A,z=`<${T}>`,D=document,
|
|
17
|
+
const S=globalThis,I=S.trustedTypes,C=I?I.createPolicy("lit-html",{createHTML:e=>e}):void 0,E="$lit$",A=`lit$${Math.random().toFixed(9).slice(2)}$`,T="?"+A,z=`<${T}>`,D=document,R=()=>D.createComment(""),M=e=>null===e||"object"!=typeof e&&"function"!=typeof e,O=Array.isArray,N="[ \t\n\f\r]",P=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,L=/-->/g,F=/>/g,U=RegExp(`>|${N}(?:([^\\s"'>=/]+)(${N}*=${N}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),j=/'/g,H=/"/g,B=/^(?:script|style|textarea|title)$/i,q=(e=>(t,...i)=>({_$litType$:e,strings:t,values:i}))(1),W=Symbol.for("lit-noChange"),V=Symbol.for("lit-nothing"),X=new WeakMap,Q=D.createTreeWalker(D,129);function Y(e,t){if(!O(e)||!e.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==C?C.createHTML(t):t}class K{constructor({strings:e,_$litType$:t},i){let s;this.parts=[];let n=0,o=0;const r=e.length-1,a=this.parts,[l,h]=((e,t)=>{const i=e.length-1,s=[];let n,o=2===t?"<svg>":3===t?"<math>":"",r=P;for(let t=0;t<i;t++){const i=e[t];let a,l,h=-1,c=0;for(;c<i.length&&(r.lastIndex=c,l=r.exec(i),null!==l);)c=r.lastIndex,r===P?"!--"===l[1]?r=L:void 0!==l[1]?r=F:void 0!==l[2]?(B.test(l[2])&&(n=RegExp("</"+l[2],"g")),r=U):void 0!==l[3]&&(r=U):r===U?">"===l[0]?(r=n??P,h=-1):void 0===l[1]?h=-2:(h=r.lastIndex-l[2].length,a=l[1],r=void 0===l[3]?U:'"'===l[3]?H:j):r===H||r===j?r=U:r===L||r===F?r=P:(r=U,n=void 0);const d=r===U&&e[t+1].startsWith("/>")?" ":"";o+=r===P?i+z:h>=0?(s.push(a),i.slice(0,h)+E+i.slice(h)+A+d):i+A+(-2===h?t:d)}return[Y(e,o+(e[i]||"<?>")+(2===t?"</svg>":3===t?"</math>":"")),s]})(e,t);if(this.el=K.createElement(l,i),Q.currentNode=this.el.content,2===t||3===t){const e=this.el.content.firstChild;e.replaceWith(...e.childNodes)}for(;null!==(s=Q.nextNode())&&a.length<r;){if(1===s.nodeType){if(s.hasAttributes())for(const e of s.getAttributeNames())if(e.endsWith(E)){const t=h[o++],i=s.getAttribute(e).split(A),r=/([.?@])?(.*)/.exec(t);a.push({type:1,index:n,name:r[2],strings:i,ctor:"."===r[1]?te:"?"===r[1]?ie:"@"===r[1]?se:ee}),s.removeAttribute(e)}else e.startsWith(A)&&(a.push({type:6,index:n}),s.removeAttribute(e));if(B.test(s.tagName)){const e=s.textContent.split(A),t=e.length-1;if(t>0){s.textContent=I?I.emptyScript:"";for(let i=0;i<t;i++)s.append(e[i],R()),Q.nextNode(),a.push({type:2,index:++n});s.append(e[t],R())}}}else if(8===s.nodeType)if(s.data===T)a.push({type:2,index:n});else{let e=-1;for(;-1!==(e=s.data.indexOf(A,e+1));)a.push({type:7,index:n}),e+=A.length-1}n++}}static createElement(e,t){const i=D.createElement("template");return i.innerHTML=e,i}}function Z(e,t,i=e,s){if(t===W)return t;let n=void 0!==s?i._$Co?.[s]:i._$Cl;const o=M(t)?void 0:t._$litDirective$;return n?.constructor!==o&&(n?._$AO?.(!1),void 0===o?n=void 0:(n=new o(e),n._$AT(e,i,s)),void 0!==s?(i._$Co??=[])[s]=n:i._$Cl=n),void 0!==n&&(t=Z(e,n._$AS(e,t.values),n,s)),t}class J{constructor(e,t){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:t},parts:i}=this._$AD,s=(e?.creationScope??D).importNode(t,!0);Q.currentNode=s;let n=Q.nextNode(),o=0,r=0,a=i[0];for(;void 0!==a;){if(o===a.index){let t;2===a.type?t=new G(n,n.nextSibling,this,e):1===a.type?t=new a.ctor(n,a.name,a.strings,this,e):6===a.type&&(t=new ne(n,this,e)),this._$AV.push(t),a=i[++r]}o!==a?.index&&(n=Q.nextNode(),o++)}return Q.currentNode=D,s}p(e){let t=0;for(const i of this._$AV)void 0!==i&&(void 0!==i.strings?(i._$AI(e,i,t),t+=i.strings.length-2):i._$AI(e[t])),t++}}class G{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(e,t,i,s){this.type=2,this._$AH=V,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=i,this.options=s,this._$Cv=s?.isConnected??!0}get parentNode(){let e=this._$AA.parentNode;const t=this._$AM;return void 0!==t&&11===e?.nodeType&&(e=t.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,t=this){e=Z(this,e,t),M(e)?e===V||null==e||""===e?(this._$AH!==V&&this._$AR(),this._$AH=V):e!==this._$AH&&e!==W&&this._(e):void 0!==e._$litType$?this.$(e):void 0!==e.nodeType?this.T(e):(e=>O(e)||"function"==typeof e?.[Symbol.iterator])(e)?this.k(e):this._(e)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==V&&M(this._$AH)?this._$AA.nextSibling.data=e:this.T(D.createTextNode(e)),this._$AH=e}$(e){const{values:t,_$litType$:i}=e,s="number"==typeof i?this._$AC(e):(void 0===i.el&&(i.el=K.createElement(Y(i.h,i.h[0]),this.options)),i);if(this._$AH?._$AD===s)this._$AH.p(t);else{const e=new J(s,this),i=e.u(this.options);e.p(t),this.T(i),this._$AH=e}}_$AC(e){let t=X.get(e.strings);return void 0===t&&X.set(e.strings,t=new K(e)),t}k(e){O(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let i,s=0;for(const n of e)s===t.length?t.push(i=new G(this.O(R()),this.O(R()),this,this.options)):i=t[s],i._$AI(n),s++;s<t.length&&(this._$AR(i&&i._$AB.nextSibling,s),t.length=s)}_$AR(e=this._$AA.nextSibling,t){for(this._$AP?.(!1,!0,t);e!==this._$AB;){const t=e.nextSibling;e.remove(),e=t}}setConnected(e){void 0===this._$AM&&(this._$Cv=e,this._$AP?.(e))}}class ee{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,i,s,n){this.type=1,this._$AH=V,this._$AN=void 0,this.element=e,this.name=t,this._$AM=s,this.options=n,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=V}_$AI(e,t=this,i,s){const n=this.strings;let o=!1;if(void 0===n)e=Z(this,e,t,0),o=!M(e)||e!==this._$AH&&e!==W,o&&(this._$AH=e);else{const s=e;let r,a;for(e=n[0],r=0;r<n.length-1;r++)a=Z(this,s[i+r],t,r),a===W&&(a=this._$AH[r]),o||=!M(a)||a!==this._$AH[r],a===V?e=V:e!==V&&(e+=(a??"")+n[r+1]),this._$AH[r]=a}o&&!s&&this.j(e)}j(e){e===V?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class te extends ee{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===V?void 0:e}}class ie extends ee{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==V)}}class se extends ee{constructor(e,t,i,s,n){super(e,t,i,s,n),this.type=5}_$AI(e,t=this){if((e=Z(this,e,t,0)??V)===W)return;const i=this._$AH,s=e===V&&i!==V||e.capture!==i.capture||e.once!==i.once||e.passive!==i.passive,n=e!==V&&(i===V||s);s&&this.element.removeEventListener(this.name,this,i),n&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,e):this._$AH.handleEvent(e)}}class ne{constructor(e,t,i){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(e){Z(this,e)}}const oe={I:G},re=S.litHtmlPolyfillSupport;re?.(K,G),(S.litHtmlVersions??=[]).push("3.3.2");const ae=globalThis;
|
|
18
18
|
/**
|
|
19
19
|
* @license
|
|
20
20
|
* Copyright 2017 Google LLC
|
|
21
21
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
22
|
-
*/let le=class extends ${constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const e=super.createRenderRoot();return this.renderOptions.renderBefore??=e.firstChild,e}update(e){const t=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=((e,t,i)=>{const s=i?.renderBefore??t;let n=s._$litPart$;if(void 0===n){const e=i?.renderBefore??null;s._$litPart$=n=new G(t.insertBefore(
|
|
22
|
+
*/let le=class extends ${constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const e=super.createRenderRoot();return this.renderOptions.renderBefore??=e.firstChild,e}update(e){const t=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=((e,t,i)=>{const s=i?.renderBefore??t;let n=s._$litPart$;if(void 0===n){const e=i?.renderBefore??null;s._$litPart$=n=new G(t.insertBefore(R(),e),e,void 0,i??{})}return n._$AI(e),n})(t,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return W}};le._$litElement$=!0,le.finalized=!0,ae.litElementHydrateSupport?.({LitElement:le});const he=ae.litElementPolyfillSupport;he?.({LitElement:le}),(ae.litElementVersions??=[]).push("4.2.2");
|
|
23
23
|
/**
|
|
24
24
|
* @license
|
|
25
25
|
* Copyright 2017 Google LLC
|
|
26
26
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
27
27
|
*/
|
|
28
|
-
const ce={attribute:!0,type:String,converter:k,reflect:!1,hasChanged:w},de=(e=ce,t,i)=>{const{kind:s,metadata:n}=i;let o=globalThis.litPropertyMetadata.get(n);if(void 0===o&&globalThis.litPropertyMetadata.set(n,o=new Map),"setter"===s&&((e=Object.create(e)).wrapped=!0),o.set(i.name,e),"accessor"===s){const{name:s}=i;return{set(i){const n=t.get.call(this);t.set.call(this,i),this.requestUpdate(s,n,e,!0,i)},init(t){return void 0!==t&&this.C(s,void 0,e,t),t}}}if("setter"===s){const{name:s}=i;return function(i){const n=this[s];t.call(this,i),this.requestUpdate(s,n,e,!0,i)}}throw Error("Unsupported decorator location: "+s)};
|
|
28
|
+
const ce={attribute:!0,type:String,converter:k,reflect:!1,hasChanged:w},de=(e=ce,t,i)=>{const{kind:s,metadata:n}=i;let o=globalThis.litPropertyMetadata.get(n);if(void 0===o&&globalThis.litPropertyMetadata.set(n,o=new Map),"setter"===s&&((e=Object.create(e)).wrapped=!0),o.set(i.name,e),"accessor"===s){const{name:s}=i;return{set(i){const n=t.get.call(this);t.set.call(this,i),this.requestUpdate(s,n,e,!0,i)},init(t){return void 0!==t&&this.C(s,void 0,e,t),t}}}if("setter"===s){const{name:s}=i;return function(i){const n=this[s];t.call(this,i),this.requestUpdate(s,n,e,!0,i)}}throw Error("Unsupported decorator location: "+s)};
|
|
29
|
+
/**
|
|
30
|
+
* @license
|
|
31
|
+
* Copyright 2017 Google LLC
|
|
32
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
33
|
+
*/function pe(e){return(t,i)=>"object"==typeof i?de(e,t,i):((e,t,i)=>{const s=t.hasOwnProperty(i);return t.constructor.createProperty(i,e),s?Object.getOwnPropertyDescriptor(t,i):void 0})(e,t,i)
|
|
29
34
|
/**
|
|
30
35
|
* @license
|
|
31
36
|
* Copyright 2017 Google LLC
|
|
@@ -198,12 +203,12 @@ function ge(e,t){return(t,i,s)=>((e,t,i)=>(i.configurable=!0,i.enumerable=!0,Ref
|
|
|
198
203
|
* @license
|
|
199
204
|
* Copyright 2018 Google LLC
|
|
200
205
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
201
|
-
*/;const $e="important",Se=" !"+$e,Ie=ve(class extends be{constructor(e){if(super(e),e.type!==me||"style"!==e.name||e.strings?.length>2)throw Error("The `styleMap` directive must be used in the `style` attribute and must be the only part in the attribute.")}render(e){return Object.keys(e).reduce(((t,i)=>{const s=e[i];return null==s?t:t+`${i=i.includes("-")?i:i.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g,"-$&").toLowerCase()}:${s};`}),"")}update(e,[t]){const{style:i}=e.element;if(void 0===this.ft)return this.ft=new Set(Object.keys(t)),this.render(t);for(const e of this.ft)null==t[e]&&(this.ft.delete(e),e.includes("-")?i.removeProperty(e):i[e]=null);for(const e in t){const s=t[e];if(null!=s){this.ft.add(e);const t="string"==typeof s&&s.endsWith(Se);e.includes("-")||t?i.setProperty(e,t?s.slice(0,-11):s,t?$e:""):i[e]=s}}return W}}),{I:Ce}=oe,Ee=()=>document.createComment(""),Ae=(e,t,i)=>{const s=e._$AA.parentNode,n=void 0===t?e._$AB:t._$AA;if(void 0===i){const t=s.insertBefore(Ee(),n),o=s.insertBefore(Ee(),n);i=new Ce(t,o,e,e.options)}else{const t=i._$AB.nextSibling,o=i._$AM,r=o!==e;if(r){let t;i._$AQ?.(e),i._$AM=e,void 0!==i._$AP&&(t=e._$AU)!==o._$AU&&i._$AP(t)}if(t!==n||r){let e=i._$AA;for(;e!==t;){const t=e.nextSibling;s.insertBefore(e,n),e=t}}}return i},Te=(e,t,i=e)=>(e._$AI(t,i),e),ze={},De=(e,t=ze)=>e._$AH=t,
|
|
206
|
+
*/;const $e="important",Se=" !"+$e,Ie=ve(class extends be{constructor(e){if(super(e),e.type!==me||"style"!==e.name||e.strings?.length>2)throw Error("The `styleMap` directive must be used in the `style` attribute and must be the only part in the attribute.")}render(e){return Object.keys(e).reduce(((t,i)=>{const s=e[i];return null==s?t:t+`${i=i.includes("-")?i:i.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g,"-$&").toLowerCase()}:${s};`}),"")}update(e,[t]){const{style:i}=e.element;if(void 0===this.ft)return this.ft=new Set(Object.keys(t)),this.render(t);for(const e of this.ft)null==t[e]&&(this.ft.delete(e),e.includes("-")?i.removeProperty(e):i[e]=null);for(const e in t){const s=t[e];if(null!=s){this.ft.add(e);const t="string"==typeof s&&s.endsWith(Se);e.includes("-")||t?i.setProperty(e,t?s.slice(0,-11):s,t?$e:""):i[e]=s}}return W}}),{I:Ce}=oe,Ee=()=>document.createComment(""),Ae=(e,t,i)=>{const s=e._$AA.parentNode,n=void 0===t?e._$AB:t._$AA;if(void 0===i){const t=s.insertBefore(Ee(),n),o=s.insertBefore(Ee(),n);i=new Ce(t,o,e,e.options)}else{const t=i._$AB.nextSibling,o=i._$AM,r=o!==e;if(r){let t;i._$AQ?.(e),i._$AM=e,void 0!==i._$AP&&(t=e._$AU)!==o._$AU&&i._$AP(t)}if(t!==n||r){let e=i._$AA;for(;e!==t;){const t=e.nextSibling;s.insertBefore(e,n),e=t}}}return i},Te=(e,t,i=e)=>(e._$AI(t,i),e),ze={},De=(e,t=ze)=>e._$AH=t,Re=e=>{e._$AR(),e._$AA.remove()},Me=(e,t,i)=>{const s=new Map;for(let n=t;n<=i;n++)s.set(e[n],n);return s},Oe=ve(class extends be{constructor(e){if(super(e),e.type!==fe)throw Error("repeat() can only be used in text expressions")}dt(e,t,i){let s;void 0===i?i=t:void 0!==t&&(s=t);const n=[],o=[];let r=0;for(const t of e)n[r]=s?s(t,r):r,o[r]=i(t,r),r++;return{values:o,keys:n}}render(e,t,i){return this.dt(e,t,i).values}update(e,[t,i,s]){const n=(e=>e._$AH)(e),{values:o,keys:r}=this.dt(t,i,s);if(!Array.isArray(n))return this.ut=r,o;const a=this.ut??=[],l=[];let h,c,d=0,p=n.length-1,u=0,g=o.length-1;for(;d<=p&&u<=g;)if(null===n[d])d++;else if(null===n[p])p--;else if(a[d]===r[u])l[u]=Te(n[d],o[u]),d++,u++;else if(a[p]===r[g])l[g]=Te(n[p],o[g]),p--,g--;else if(a[d]===r[g])l[g]=Te(n[d],o[g]),Ae(e,l[g+1],n[d]),d++,g--;else if(a[p]===r[u])l[u]=Te(n[p],o[u]),Ae(e,n[d],n[p]),p--,u++;else if(void 0===h&&(h=Me(r,u,g),c=Me(a,d,p)),h.has(a[d]))if(h.has(a[p])){const t=c.get(r[u]),i=void 0!==t?n[t]:null;if(null===i){const t=Ae(e,n[d]);Te(t,o[u]),l[u]=t}else l[u]=Te(i,o[u]),Ae(e,n[d],i),n[t]=null;u++}else Re(n[p]),p--;else Re(n[d]),d++;for(;u<=g;){const t=Ae(e,l[g+1]);Te(t,o[u]),l[u++]=t}for(;d<=p;){const e=n[d++];null!==e&&Re(e)}return this.ut=r,De(e,l),W}});
|
|
202
207
|
/**
|
|
203
208
|
* @license
|
|
204
209
|
* Copyright 2020 Google LLC
|
|
205
210
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
206
|
-
*/function Ne(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let Pe={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function Le(e){Pe=e}const Fe=/[&<>"']/,Ue=new RegExp(Fe.source,"g"),He=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,je=new RegExp(He.source,"g"),Be={"&":"&","<":"<",">":">",'"':""","'":"'"},qe=e=>Be[e];function We(e,t){if(t){if(Fe.test(e))return e.replace(Ue,qe)}else if(He.test(e))return e.replace(je,qe);return e}const Ve=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function Xe(e){return e.replace(Ve,((e,t)=>"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""))}const Qe=/(^|[^\[])\^/g;function Ye(e,t){let i="string"==typeof e?e:e.source;t=t||"";const s={replace:(e,t)=>{let n="string"==typeof t?t:t.source;return n=n.replace(Qe,"$1"),i=i.replace(e,n),s},getRegex:()=>new RegExp(i,t)};return s}function Ke(e){try{e=encodeURI(e).replace(/%25/g,"%")}catch(e){return null}return e}const Ze={exec:()=>null};function Je(e,t){const i=e.replace(/\|/g,((e,t,i)=>{let s=!1,n=t;for(;--n>=0&&"\\"===i[n];)s=!s;return s?"|":" |"})).split(/ \|/);let s=0;if(i[0].trim()||i.shift(),i.length>0&&!i[i.length-1].trim()&&i.pop(),t)if(i.length>t)i.splice(t);else for(;i.length<t;)i.push("");for(;s<i.length;s++)i[s]=i[s].trim().replace(/\\\|/g,"|");return i}function Ge(e,t,i){const s=e.length;if(0===s)return"";let n=0;for(;n<s;){if(e.charAt(s-n-1)!==t)break;n++}return e.slice(0,s-n)}function et(e,t,i,s){const n=t.href,o=t.title?We(t.title):null,r=e[1].replace(/\\([\[\]])/g,"$1");if("!"!==e[0].charAt(0)){s.state.inLink=!0;const e={type:"link",raw:i,href:n,title:o,text:r,tokens:s.inlineTokens(r)};return s.state.inLink=!1,e}return{type:"image",raw:i,href:n,title:o,text:We(r)}}class tt{options;rules;lexer;constructor(e){this.options=e||Pe}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const e=t[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:Ge(e,"\n")}}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const e=t[0],i=function(e,t){const i=e.match(/^(\s+)(?:```)/);if(null===i)return t;const s=i[1];return t.split("\n").map((e=>{const t=e.match(/^\s+/);if(null===t)return e;const[i]=t;return i.length>=s.length?e.slice(s.length):e})).join("\n")}(e,t[3]||"");return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:i}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(/#$/.test(e)){const t=Ge(e,"#");this.options.pedantic?e=t.trim():t&&!/ $/.test(t)||(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){const t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:t[0]}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){let e=t[0].replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,"\n $1");e=Ge(e.replace(/^ *>[ \t]?/gm,""),"\n");const i=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(e);return this.lexer.state.top=i,{type:"blockquote",raw:t[0],tokens:s,text:e}}}list(e){let t=this.rules.block.list.exec(e);if(t){let i=t[1].trim();const s=i.length>1,n={type:"list",raw:"",ordered:s,start:s?+i.slice(0,-1):"",loose:!1,items:[]};i=s?`\\d{1,9}\\${i.slice(-1)}`:`\\${i}`,this.options.pedantic&&(i=s?i:"[*+-]");const o=new RegExp(`^( {0,3}${i})((?:[\t ][^\\n]*)?(?:\\n|$))`);let r="",a="",l=!1;for(;e;){let i=!1;if(!(t=o.exec(e)))break;if(this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let s=t[2].split("\n",1)[0].replace(/^\t+/,(e=>" ".repeat(3*e.length))),h=e.split("\n",1)[0],c=0;this.options.pedantic?(c=2,a=s.trimStart()):(c=t[2].search(/[^ ]/),c=c>4?1:c,a=s.slice(c),c+=t[1].length);let d=!1;if(!s&&/^ *$/.test(h)&&(r+=h+"\n",e=e.substring(h.length+1),i=!0),!i){const t=new RegExp(`^ {0,${Math.min(3,c-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),i=new RegExp(`^ {0,${Math.min(3,c-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),n=new RegExp(`^ {0,${Math.min(3,c-1)}}(?:\`\`\`|~~~)`),o=new RegExp(`^ {0,${Math.min(3,c-1)}}#`);for(;e;){const l=e.split("\n",1)[0];if(h=l,this.options.pedantic&&(h=h.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),n.test(h))break;if(o.test(h))break;if(t.test(h))break;if(i.test(e))break;if(h.search(/[^ ]/)>=c||!h.trim())a+="\n"+h.slice(c);else{if(d)break;if(s.search(/[^ ]/)>=4)break;if(n.test(s))break;if(o.test(s))break;if(i.test(s))break;a+="\n"+h}d||h.trim()||(d=!0),r+=l+"\n",e=e.substring(l.length+1),s=h.slice(c)}}n.loose||(l?n.loose=!0:/\n *\n *$/.test(r)&&(l=!0));let p,u=null;this.options.gfm&&(u=/^\[[ xX]\] /.exec(a),u&&(p="[ ] "!==u[0],a=a.replace(/^\[[ xX]\] +/,""))),n.items.push({type:"list_item",raw:r,task:!!u,checked:p,loose:!1,text:a,tokens:[]}),n.raw+=r}n.items[n.items.length-1].raw=r.trimEnd(),n.items[n.items.length-1].text=a.trimEnd(),n.raw=n.raw.trimEnd();for(let e=0;e<n.items.length;e++)if(this.lexer.state.top=!1,n.items[e].tokens=this.lexer.blockTokens(n.items[e].text,[]),!n.loose){const t=n.items[e].tokens.filter((e=>"space"===e.type)),i=t.length>0&&t.some((e=>/\n.*\n/.test(e.raw)));n.loose=i}if(n.loose)for(let e=0;e<n.items.length;e++)n.items[e].loose=!0;return n}}html(e){const t=this.rules.block.html.exec(e);if(t){return{type:"html",block:!0,raw:t[0],pre:"pre"===t[1]||"script"===t[1]||"style"===t[1],text:t[0]}}}def(e){const t=this.rules.block.def.exec(e);if(t){const e=t[1].toLowerCase().replace(/\s+/g," "),i=t[2]?t[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:e,raw:t[0],href:i,title:s}}}table(e){const t=this.rules.block.table.exec(e);if(!t)return;if(!/[:|]/.test(t[2]))return;const i=Je(t[1]),s=t[2].replace(/^\||\| *$/g,"").split("|"),n=t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split("\n"):[],o={type:"table",raw:t[0],header:[],align:[],rows:[]};if(i.length===s.length){for(const e of s)/^ *-+: *$/.test(e)?o.align.push("right"):/^ *:-+: *$/.test(e)?o.align.push("center"):/^ *:-+ *$/.test(e)?o.align.push("left"):o.align.push(null);for(const e of i)o.header.push({text:e,tokens:this.lexer.inline(e)});for(const e of n)o.rows.push(Je(e,o.header.length).map((e=>({text:e,tokens:this.lexer.inline(e)}))));return o}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){const t=this.rules.block.paragraph.exec(e);if(t){const e="\n"===t[1].charAt(t[1].length-1)?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){const 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){const t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:We(t[1])}}tag(e){const t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&/^<a /i.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.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){const t=this.rules.inline.link.exec(e);if(t){const e=t[2].trim();if(!this.options.pedantic&&/^</.test(e)){if(!/>$/.test(e))return;const t=Ge(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{const e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let i=0;for(let s=0;s<e.length;s++)if("\\"===e[s])s++;else if(e[s]===t[0])i++;else if(e[s]===t[1]&&(i--,i<0))return s;return-1}(t[2],"()");if(e>-1){const i=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,i).trim(),t[3]=""}}let i=t[2],s="";if(this.options.pedantic){const e=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(i);e&&(i=e[1],s=e[3])}else s=t[3]?t[3].slice(1,-1):"";return i=i.trim(),/^</.test(i)&&(i=this.options.pedantic&&!/>$/.test(e)?i.slice(1):i.slice(1,-1)),et(t,{href:i?i.replace(this.rules.inline.anyPunctuation,"$1"):i,title:s?s.replace(this.rules.inline.anyPunctuation,"$1"):s},t[0],this.lexer)}}reflink(e,t){let i;if((i=this.rules.inline.reflink.exec(e))||(i=this.rules.inline.nolink.exec(e))){const e=t[(i[2]||i[1]).replace(/\s+/g," ").toLowerCase()];if(!e){const e=i[0].charAt(0);return{type:"text",raw:e,text:e}}return et(i,e,i[0],this.lexer)}}emStrong(e,t,i=""){let s=this.rules.inline.emStrongLDelim.exec(e);if(!s)return;if(s[3]&&i.match(/[\p{L}\p{N}]/u))return;if(!(s[1]||s[2]||"")||!i||this.rules.inline.punctuation.exec(i)){const i=[...s[0]].length-1;let n,o,r=i,a=0;const l="*"===s[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+i);null!=(s=l.exec(t));){if(n=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!n)continue;if(o=[...n].length,s[3]||s[4]){r+=o;continue}if((s[5]||s[6])&&i%3&&!((i+o)%3)){a+=o;continue}if(r-=o,r>0)continue;o=Math.min(o,o+r+a);const t=[...s[0]][0].length,l=e.slice(0,i+s.index+t+o);if(Math.min(i,o)%2){const e=l.slice(1,-1);return{type:"em",raw:l,text:e,tokens:this.lexer.inlineTokens(e)}}const h=l.slice(2,-2);return{type:"strong",raw:l,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(/\n/g," ");const i=/[^ ]/.test(e),s=/^ /.test(e)&&/ $/.test(e);return i&&s&&(e=e.substring(1,e.length-1)),e=We(e,!0),{type:"codespan",raw:t[0],text:e}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){const t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){const t=this.rules.inline.autolink.exec(e);if(t){let e,i;return"@"===t[2]?(e=We(t[1]),i="mailto:"+e):(e=We(t[1]),i=e),{type:"link",raw:t[0],text:e,href:i,tokens:[{type:"text",raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,i;if("@"===t[2])e=We(t[0]),i="mailto:"+e;else{let s;do{s=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(s!==t[0]);e=We(t[0]),i="www."===t[1]?"http://"+t[0]:t[0]}return{type:"link",raw:t[0],text:e,href:i,tokens:[{type:"text",raw:e,text:e}]}}}inlineText(e){const t=this.rules.inline.text.exec(e);if(t){let e;return e=this.lexer.state.inRawBlock?t[0]:We(t[0]),{type:"text",raw:t[0],text:e}}}}const it=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,st=/(?:[*+-]|\d{1,9}[.)])/,nt=Ye(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,st).replace(/blockCode/g,/ {4}/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).getRegex(),ot=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,rt=/(?!\s*\])(?:\\.|[^\[\]\\])+/,at=Ye(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label",rt).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),lt=Ye(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,st).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",ct=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,dt=Ye("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))","i").replace("comment",ct).replace("tag",ht).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),pt=Ye(ot).replace("hr",it).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ht).getRegex(),ut={blockquote:Ye(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",pt).getRegex(),code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,def:at,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:it,html:dt,lheading:nt,list:lt,newline:/^(?: *(?:\n|$))+/,paragraph:pt,table:Ze,text:/^[^\n]+/},gt=Ye("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",it).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ht).getRegex(),mt={...ut,table:gt,paragraph:Ye(ot).replace("hr",it).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",gt).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ht).getRegex()},ft={...ut,html:Ye("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",ct).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:Ze,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Ye(ot).replace("hr",it).replace("heading"," *#{1,6} *[^\n]").replace("lheading",nt).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},vt=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,bt=/^( {2,}|\\)\n(?!\s*$)/,_t="\\p{P}\\p{S}",xt=Ye(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,_t).getRegex(),kt=Ye(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,_t).getRegex(),wt=Ye("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,_t).getRegex(),yt=Ye("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,_t).getRegex(),$t=Ye(/\\([punct])/,"gu").replace(/punct/g,_t).getRegex(),St=Ye(/^<(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=Ye(ct).replace("(?:--\x3e|$)","--\x3e").getRegex(),Ct=Ye("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",It).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Et=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,At=Ye(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",Et).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Tt=Ye(/^!?\[(label)\]\[(ref)\]/).replace("label",Et).replace("ref",rt).getRegex(),zt=Ye(/^!?\[(ref)\](?:\[\])?/).replace("ref",rt).getRegex(),Dt={_backpedal:Ze,anyPunctuation:$t,autolink:St,blockSkip:/\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g,br:bt,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:Ze,emStrongLDelim:kt,emStrongRDelimAst:wt,emStrongRDelimUnd:yt,escape:vt,link:At,nolink:zt,punctuation:xt,reflink:Tt,reflinkSearch:Ye("reflink|nolink(?!\\()","g").replace("reflink",Tt).replace("nolink",zt).getRegex(),tag:Ct,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:Ze},Mt={...Dt,link:Ye(/^!?\[(label)\]\((.*?)\)/).replace("label",Et).getRegex(),reflink:Ye(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Et).getRegex()},Rt={...Dt,escape:Ye(vt).replace("])","~|])").getRegex(),url:Ye(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},Ot={...Rt,br:Ye(bt).replace("{2,}","*").getRegex(),text:Ye(Rt.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Nt={normal:ut,gfm:mt,pedantic:ft},Pt={normal:Dt,gfm:Rt,breaks:Ot,pedantic:Mt};class Lt{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Pe,this.options.tokenizer=this.options.tokenizer||new tt,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const t={block:Nt.normal,inline:Pt.normal};this.options.pedantic?(t.block=Nt.pedantic,t.inline=Pt.pedantic):this.options.gfm&&(t.block=Nt.gfm,this.options.breaks?t.inline=Pt.breaks:t.inline=Pt.gfm),this.tokenizer.rules=t}static get rules(){return{block:Nt,inline:Pt}}static lex(e,t){return new Lt(t).lex(e)}static lexInline(e,t){return new Lt(t).inlineTokens(e)}lex(e){e=e.replace(/\r\n|\r/g,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){const t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[]){let i,s,n,o;for(e=this.options.pedantic?e.replace(/\t/g," ").replace(/^ +$/gm,""):e.replace(/^( *)(\t+)/gm,((e,t,i)=>t+" ".repeat(i.length)));e;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some((s=>!!(i=s.call({lexer:this},e,t))&&(e=e.substring(i.raw.length),t.push(i),!0)))))if(i=this.tokenizer.space(e))e=e.substring(i.raw.length),1===i.raw.length&&t.length>0?t[t.length-1].raw+="\n":t.push(i);else if(i=this.tokenizer.code(e))e=e.substring(i.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?t.push(i):(s.raw+="\n"+i.raw,s.text+="\n"+i.text,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(i=this.tokenizer.fences(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.heading(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.hr(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.blockquote(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.list(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.html(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.def(e))e=e.substring(i.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title}):(s.raw+="\n"+i.raw,s.text+="\n"+i.raw,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(i=this.tokenizer.table(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.lheading(e))e=e.substring(i.raw.length),t.push(i);else{if(n=e,this.options.extensions&&this.options.extensions.startBlock){let t=1/0;const i=e.slice(1);let s;this.options.extensions.startBlock.forEach((e=>{s=e.call({lexer:this},i),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(n=e.substring(0,t+1))}if(this.state.top&&(i=this.tokenizer.paragraph(n)))s=t[t.length-1],o&&"paragraph"===s.type?(s.raw+="\n"+i.raw,s.text+="\n"+i.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(i),o=n.length!==e.length,e=e.substring(i.raw.length);else if(i=this.tokenizer.text(e))e=e.substring(i.raw.length),s=t[t.length-1],s&&"text"===s.type?(s.raw+="\n"+i.raw,s.text+="\n"+i.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(i);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let i,s,n,o,r,a,l=e;if(this.tokens.links){const e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(o=this.tokenizer.rules.inline.reflinkSearch.exec(l));)e.includes(o[0].slice(o[0].lastIndexOf("[")+1,-1))&&(l=l.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+l.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(o=this.tokenizer.rules.inline.blockSkip.exec(l));)l=l.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+l.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;null!=(o=this.tokenizer.rules.inline.anyPunctuation.exec(l));)l=l.slice(0,o.index)+"++"+l.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;e;)if(r||(a=""),r=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some((s=>!!(i=s.call({lexer:this},e,t))&&(e=e.substring(i.raw.length),t.push(i),!0)))))if(i=this.tokenizer.escape(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.tag(e))e=e.substring(i.raw.length),s=t[t.length-1],s&&"text"===i.type&&"text"===s.type?(s.raw+=i.raw,s.text+=i.text):t.push(i);else if(i=this.tokenizer.link(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.reflink(e,this.tokens.links))e=e.substring(i.raw.length),s=t[t.length-1],s&&"text"===i.type&&"text"===s.type?(s.raw+=i.raw,s.text+=i.text):t.push(i);else if(i=this.tokenizer.emStrong(e,l,a))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.codespan(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.br(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.del(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.autolink(e))e=e.substring(i.raw.length),t.push(i);else if(this.state.inLink||!(i=this.tokenizer.url(e))){if(n=e,this.options.extensions&&this.options.extensions.startInline){let t=1/0;const i=e.slice(1);let s;this.options.extensions.startInline.forEach((e=>{s=e.call({lexer:this},i),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(n=e.substring(0,t+1))}if(i=this.tokenizer.inlineText(n))e=e.substring(i.raw.length),"_"!==i.raw.slice(-1)&&(a=i.raw.slice(-1)),r=!0,s=t[t.length-1],s&&"text"===s.type?(s.raw+=i.raw,s.text+=i.text):t.push(i);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}else e=e.substring(i.raw.length),t.push(i);return t}}class Ft{options;constructor(e){this.options=e||Pe}code(e,t,i){const s=(t||"").match(/^\S*/)?.[0];return e=e.replace(/\n$/,"")+"\n",s?'<pre><code class="language-'+We(s)+'">'+(i?e:We(e,!0))+"</code></pre>\n":"<pre><code>"+(i?e:We(e,!0))+"</code></pre>\n"}blockquote(e){return`<blockquote>\n${e}</blockquote>\n`}html(e,t){return e}heading(e,t,i){return`<h${t}>${e}</h${t}>\n`}hr(){return"<hr>\n"}list(e,t,i){const s=t?"ol":"ul";return"<"+s+(t&&1!==i?' start="'+i+'"':"")+">\n"+e+"</"+s+">\n"}listitem(e,t,i){return`<li>${e}</li>\n`}checkbox(e){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph(e){return`<p>${e}</p>\n`}table(e,t){return t&&(t=`<tbody>${t}</tbody>`),"<table>\n<thead>\n"+e+"</thead>\n"+t+"</table>\n"}tablerow(e){return`<tr>\n${e}</tr>\n`}tablecell(e,t){const i=t.header?"th":"td";return(t.align?`<${i} align="${t.align}">`:`<${i}>`)+e+`</${i}>\n`}strong(e){return`<strong>${e}</strong>`}em(e){return`<em>${e}</em>`}codespan(e){return`<code>${e}</code>`}br(){return"<br>"}del(e){return`<del>${e}</del>`}link(e,t,i){const s=Ke(e);if(null===s)return i;let n='<a href="'+(e=s)+'"';return t&&(n+=' title="'+t+'"'),n+=">"+i+"</a>",n}image(e,t,i){const s=Ke(e);if(null===s)return i;let n=`<img src="${e=s}" alt="${i}"`;return t&&(n+=` title="${t}"`),n+=">",n}text(e){return e}}class Ut{strong(e){return e}em(e){return e}codespan(e){return e}del(e){return e}html(e){return e}text(e){return e}link(e,t,i){return""+i}image(e,t,i){return""+i}br(){return""}}class Ht{options;renderer;textRenderer;constructor(e){this.options=e||Pe,this.options.renderer=this.options.renderer||new Ft,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new Ut}static parse(e,t){return new Ht(t).parse(e)}static parseInline(e,t){return new Ht(t).parseInline(e)}parse(e,t=!0){let i="";for(let s=0;s<e.length;s++){const n=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[n.type]){const e=n,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(e.type)){i+=t||"";continue}}switch(n.type){case"space":continue;case"hr":i+=this.renderer.hr();continue;case"heading":{const e=n;i+=this.renderer.heading(this.parseInline(e.tokens),e.depth,Xe(this.parseInline(e.tokens,this.textRenderer)));continue}case"code":{const e=n;i+=this.renderer.code(e.text,e.lang,!!e.escaped);continue}case"table":{const e=n;let t="",s="";for(let t=0;t<e.header.length;t++)s+=this.renderer.tablecell(this.parseInline(e.header[t].tokens),{header:!0,align:e.align[t]});t+=this.renderer.tablerow(s);let o="";for(let t=0;t<e.rows.length;t++){const i=e.rows[t];s="";for(let t=0;t<i.length;t++)s+=this.renderer.tablecell(this.parseInline(i[t].tokens),{header:!1,align:e.align[t]});o+=this.renderer.tablerow(s)}i+=this.renderer.table(t,o);continue}case"blockquote":{const e=n,t=this.parse(e.tokens);i+=this.renderer.blockquote(t);continue}case"list":{const e=n,t=e.ordered,s=e.start,o=e.loose;let r="";for(let t=0;t<e.items.length;t++){const i=e.items[t],s=i.checked,n=i.task;let a="";if(i.task){const e=this.renderer.checkbox(!!s);o?i.tokens.length>0&&"paragraph"===i.tokens[0].type?(i.tokens[0].text=e+" "+i.tokens[0].text,i.tokens[0].tokens&&i.tokens[0].tokens.length>0&&"text"===i.tokens[0].tokens[0].type&&(i.tokens[0].tokens[0].text=e+" "+i.tokens[0].tokens[0].text)):i.tokens.unshift({type:"text",text:e+" "}):a+=e+" "}a+=this.parse(i.tokens,o),r+=this.renderer.listitem(a,n,!!s)}i+=this.renderer.list(r,t,s);continue}case"html":{const e=n;i+=this.renderer.html(e.text,e.block);continue}case"paragraph":{const e=n;i+=this.renderer.paragraph(this.parseInline(e.tokens));continue}case"text":{let o=n,r=o.tokens?this.parseInline(o.tokens):o.text;for(;s+1<e.length&&"text"===e[s+1].type;)o=e[++s],r+="\n"+(o.tokens?this.parseInline(o.tokens):o.text);i+=t?this.renderer.paragraph(r):r;continue}default:{const e='Token with "'+n.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return i}parseInline(e,t){t=t||this.renderer;let i="";for(let s=0;s<e.length;s++){const n=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[n.type]){const e=this.options.extensions.renderers[n.type].call({parser:this},n);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(n.type)){i+=e||"";continue}}switch(n.type){case"escape":{const e=n;i+=t.text(e.text);break}case"html":{const e=n;i+=t.html(e.text);break}case"link":{const e=n;i+=t.link(e.href,e.title,this.parseInline(e.tokens,t));break}case"image":{const e=n;i+=t.image(e.href,e.title,e.text);break}case"strong":{const e=n;i+=t.strong(this.parseInline(e.tokens,t));break}case"em":{const e=n;i+=t.em(this.parseInline(e.tokens,t));break}case"codespan":{const e=n;i+=t.codespan(e.text);break}case"br":i+=t.br();break;case"del":{const e=n;i+=t.del(this.parseInline(e.tokens,t));break}case"text":{const e=n;i+=t.text(e.text);break}default:{const e='Token with "'+n.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return i}}class jt{options;constructor(e){this.options=e||Pe}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}}const Bt=new class{defaults={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};options=this.setOptions;parse=this.#e(Lt.lex,Ht.parse);parseInline=this.#e(Lt.lexInline,Ht.parseInline);Parser=Ht;Renderer=Ft;TextRenderer=Ut;Lexer=Lt;Tokenizer=tt;Hooks=jt;constructor(...e){this.use(...e)}walkTokens(e,t){let i=[];for(const s of e)switch(i=i.concat(t.call(this,s)),s.type){case"table":{const e=s;for(const s of e.header)i=i.concat(this.walkTokens(s.tokens,t));for(const s of e.rows)for(const e of s)i=i.concat(this.walkTokens(e.tokens,t));break}case"list":{const e=s;i=i.concat(this.walkTokens(e.items,t));break}default:{const e=s;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach((s=>{const n=e[s].flat(1/0);i=i.concat(this.walkTokens(n,t))})):e.tokens&&(i=i.concat(this.walkTokens(e.tokens,t)))}}return i}use(...e){const t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach((e=>{const i={...e};if(i.async=this.defaults.async||i.async||!1,e.extensions&&(e.extensions.forEach((e=>{if(!e.name)throw new Error("extension name required");if("renderer"in e){const i=t.renderers[e.name];t.renderers[e.name]=i?function(...t){let s=e.renderer.apply(this,t);return!1===s&&(s=i.apply(this,t)),s}:e.renderer}if("tokenizer"in e){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");const i=t[e.level];i?i.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&("block"===e.level?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:"inline"===e.level&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}"childTokens"in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)})),i.extensions=t),e.renderer){const t=this.defaults.renderer||new Ft(this.defaults);for(const i in e.renderer){if(!(i in t))throw new Error(`renderer '${i}' does not exist`);if("options"===i)continue;const s=i,n=e.renderer[s],o=t[s];t[s]=(...e)=>{let i=n.apply(t,e);return!1===i&&(i=o.apply(t,e)),i||""}}i.renderer=t}if(e.tokenizer){const t=this.defaults.tokenizer||new tt(this.defaults);for(const i in e.tokenizer){if(!(i in t))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;const s=i,n=e.tokenizer[s],o=t[s];t[s]=(...e)=>{let i=n.apply(t,e);return!1===i&&(i=o.apply(t,e)),i}}i.tokenizer=t}if(e.hooks){const t=this.defaults.hooks||new jt;for(const i in e.hooks){if(!(i in t))throw new Error(`hook '${i}' does not exist`);if("options"===i)continue;const s=i,n=e.hooks[s],o=t[s];jt.passThroughHooks.has(i)?t[s]=e=>{if(this.defaults.async)return Promise.resolve(n.call(t,e)).then((e=>o.call(t,e)));const i=n.call(t,e);return o.call(t,i)}:t[s]=(...e)=>{let i=n.apply(t,e);return!1===i&&(i=o.apply(t,e)),i}}i.hooks=t}if(e.walkTokens){const t=this.defaults.walkTokens,s=e.walkTokens;i.walkTokens=function(e){let i=[];return i.push(s.call(this,e)),t&&(i=i.concat(t.call(this,e))),i}}this.defaults={...this.defaults,...i}})),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return Lt.lex(e,t??this.defaults)}parser(e,t){return Ht.parse(e,t??this.defaults)}#e(e,t){return(i,s)=>{const n={...s},o={...this.defaults,...n};!0===this.defaults.async&&!1===n.async&&(o.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),o.async=!0);const r=this.#t(!!o.silent,!!o.async);if(null==i)return r(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof i)return r(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(i)+", string expected"));if(o.hooks&&(o.hooks.options=o),o.async)return Promise.resolve(o.hooks?o.hooks.preprocess(i):i).then((t=>e(t,o))).then((e=>o.hooks?o.hooks.processAllTokens(e):e)).then((e=>o.walkTokens?Promise.all(this.walkTokens(e,o.walkTokens)).then((()=>e)):e)).then((e=>t(e,o))).then((e=>o.hooks?o.hooks.postprocess(e):e)).catch(r);try{o.hooks&&(i=o.hooks.preprocess(i));let s=e(i,o);o.hooks&&(s=o.hooks.processAllTokens(s)),o.walkTokens&&this.walkTokens(s,o.walkTokens);let n=t(s,o);return o.hooks&&(n=o.hooks.postprocess(n)),n}catch(e){return r(e)}}}#t(e,t){return i=>{if(i.message+="\nPlease report this to https://github.com/markedjs/marked.",e){const e="<p>An error occurred:</p><pre>"+We(i.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(i);throw i}}};function qt(e,t){return Bt.parse(e,t)}qt.options=qt.setOptions=function(e){return Bt.setOptions(e),qt.defaults=Bt.defaults,Le(qt.defaults),qt},qt.getDefaults=Ne,qt.defaults=Pe,qt.use=function(...e){return Bt.use(...e),qt.defaults=Bt.defaults,Le(qt.defaults),qt},qt.walkTokens=function(e,t){return Bt.walkTokens(e,t)},qt.parseInline=Bt.parseInline,qt.Parser=Ht,qt.parser=Ht.parse,qt.Renderer=Ft,qt.TextRenderer=Ut,qt.Lexer=Lt,qt.lexer=Lt.lex,qt.Tokenizer=tt,qt.Hooks=jt,qt.parse=qt,qt.options,qt.setOptions,qt.use,qt.walkTokens,qt.parseInline,Ht.parse,Lt.lex;var Wt=function(e,t,i,s){var n,o=arguments.length,r=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(r=(o<3?n(r):o>3?n(t,i,r):n(t,i))||r);return o>3&&r&&Object.defineProperty(t,i,r),r};const Vt=[{decision:"approve",label:"Yes"},{decision:"approveAlways",label:"Always allow"},{decision:"reject",label:"No"}],Xt=[{mode:"NORMAL",label:"Ask",description:"Asks before making changes"},{mode:"EDIT",label:"Auto",description:"Makes changes automatically"},{mode:"PLAN",label:"Plan",description:"Suggests a plan, makes no changes"}],Qt=["jpg","jpeg","png","gif","webp"],Yt=["pdf","doc","docx","xls","xlsx","csv","html","md","txt","json","xml","vtt","srt",...Qt,"mp4","webm","ogg","mov"];class Kt extends le{constructor(){super(...arguments),this._inlineConfirm=!0,this._reasoningAsMessage=!0,this._reader=null,this._decoder=new TextDecoder,this._buffer="",this._turnFinishedCleanly=!1,this._reconnectAttempts=0,this._userHasScrolledUp=!1,this._isDragging=!1,this._isResizing=!1,this._overlay=null,this._resizeDir="",this._dragStartX=0,this._dragStartY=0,this._dragStartLeft=0,this._dragStartTop=0,this._resizeStartW=0,this._resizeStartH=0,this._drawerResizeStartX=0,this._drawerResizeStartW=0,this._dragDepth=0,this._pendingSeq=0,this._pendingAttachAnalyze=!0,this._orgSkillRequestId=0,this._globalSkillRequestId=0,this._invocableSkillRequestId=0,this._suggestedActionRequestId=0,this._globalSkillPending=new Set,this._speechRecognition=null,this._speechBaseValue="",this._speechFinalTranscript="",this.send=null,this.load=null,this.messages=[],this.label="Kat",this.placeholder="Type a message...",this.opened=!1,this.hideToggle=!1,this.variant="floating",this.conversationId=null,this._inputValue="",this._isStreaming=!1,this._error="",this._conversationTitle="",this._contextWarning="",this._contextLimitReached=!1,this._contextLimitMessage="",this._pendingActions=[],this._confirmationHighlighted=-1,this._confirmationInFlight=!1,this._telemetry=null,this._iterationLog=[],this._cacheCheckpoints={},this._drawerOpen=!1,this._drawerView="settings",this._conversations=[],this._conversationsLoading=!1,this._toolDetail=null,this._toolDetailCopied=null,this._toolDetailInputOpen=!0,this._toolDetailOutputOpen=!0,this._drawerWidth=430,this._isDrawerResizing=!1,this._pendingConversationFiles=[],this._isDraggingFile=!1,this._skillMenuOpened=!1,this._skillQuery="",this._orgSkills=[],this._globalSkills=[],this._invocableSkills=[],this._suggestedActions=[],this._aiFrameworkConfig={},this._skillHighlighted=0,this._copiedIndex=-1,this._skillBrowseOpened=!1,this._skillBrowseSource="org",this._skillBrowseQuery="",this._isDictating=!1,this._mode="NORMAL",this._modeMenuOpened=!1,this._showTools=!0,this._showToolInputs=!1,this._showConfirmationInput=!1,this._handleDocumentClick=e=>{if(this._modeMenuOpened){e.composedPath().some((e=>e instanceof HTMLElement&&e.classList.contains("mode")))||(this._modeMenuOpened=!1)}if(!this._skillMenuOpened)return;e.composedPath().some((e=>e instanceof HTMLElement&&(e.classList.contains("skill-menu")||e.classList.contains("input")||e.classList.contains("input-plus"))))||(this._skillMenuOpened=!1)},this._handleMouseMove=e=>{if(this._isDragging){let t=this._dragStartLeft+(e.clientX-this._dragStartX),i=this._dragStartTop+(e.clientY-this._dragStartY);const s=this._panelEl.offsetWidth;t=Math.max(48-s,Math.min(t,window.innerWidth-48)),i=Math.max(0,Math.min(i,window.innerHeight-48)),this._panelEl.style.left=t+"px",this._panelEl.style.top=i+"px"}else if(this._isResizing){const t=e.clientX-this._dragStartX,i=e.clientY-this._dragStartY,s=340,n=380,o=.9*window.innerWidth,r=window.innerHeight-72;let a=this._resizeStartW,l=this._resizeStartH,h=this._dragStartLeft,c=this._dragStartTop;this._resizeDir.includes("e")&&(a=Math.max(s,Math.min(this._resizeStartW+t,o))),this._resizeDir.includes("w")&&(a=Math.max(s,Math.min(this._resizeStartW-t,o)),h=this._dragStartLeft+(this._resizeStartW-a)),this._resizeDir.includes("s")&&(l=Math.max(n,Math.min(this._resizeStartH+i,r))),this._resizeDir.includes("n")&&(l=Math.max(n,Math.min(this._resizeStartH-i,r)),c=this._dragStartTop+(this._resizeStartH-l)),h=Math.max(0,h),c=Math.max(0,c),this._panelEl.style.width=a+"px",this._panelEl.style.height=l+"px",this._panelEl.style.left=h+"px",this._panelEl.style.top=c+"px"}},this._handleMouseUp=()=>{this._isDragging&&(this._isDragging=!1,this._panelEl.classList.remove("panel--dragging")),this._isResizing&&(this._isResizing=!1,this._panelEl.classList.remove("panel--resizing")),this._overlay&&(this._overlay.style.display="none"),document.removeEventListener("mousemove",this._handleMouseMove),document.removeEventListener("mouseup",this._handleMouseUp),this._saveState()},this._handleDocumentKeydown=e=>{if(this._pendingActions.length&&!this._confirmationInFlight){if("ArrowRight"===e.key)return e.preventDefault(),void(this._confirmationHighlighted=(this._confirmationHighlighted+1)%Vt.length);if("ArrowLeft"===e.key)return e.preventDefault(),void(this._confirmationHighlighted=(this._confirmationHighlighted-1+Vt.length)%Vt.length);if("Enter"===e.key){e.preventDefault();const t=Vt[this._confirmationHighlighted];t&&this._handleConfirmationDecision(t.decision)}}},this._handleDrawerResizeMouseMove=e=>{if(!this._isDrawerResizing)return;const t=e.clientX-this._drawerResizeStartX,i=Math.max(300,this.offsetWidth-300);this._drawerWidth=Math.max(300,Math.min(this._drawerResizeStartW-t,i))},this._handleDrawerResizeMouseUp=()=>{this._isDrawerResizing=!1,document.removeEventListener("mousemove",this._handleDrawerResizeMouseMove),document.removeEventListener("mouseup",this._handleDrawerResizeMouseUp),this._saveState()}}connectedCallback(){super.connectedCallback(),this.load||(this.load=()=>null==this.conversationId?Promise.resolve([]):i.Http.fetch({url:`/api/system/conversation/${this.conversationId}/messages`}).then((e=>e.json())).then((e=>Promise.all((e?.data||[]).map((e=>{if("tool_use"===e.type||"tool_result"===e.type){let t={};try{t=JSON.parse(e.content||"{}")}catch{}return Promise.resolve({type:e.type,content:"",data:t})}if("reasoning"===e.type)return Promise.resolve({type:"assistant",content:"",reasoning:e.content||""});if("action_decision"===e.type){let t={};try{t=JSON.parse(e.content||"{}")}catch{}return Promise.resolve({type:"action_decision",content:"",data:t})}let t=[];try{t=JSON.parse(e.conversationFileIDs||"[]")}catch{}return t.length?Promise.all(t.map((e=>i.Http.fetch({url:`/api/system/conversationFile/${e}`}).then((e=>e.json())).then((e=>e?.data)).catch((()=>null))))).then((t=>(e.conversationFiles=t.filter((e=>null!=e)),e))):Promise.resolve(e)}))))));let e=Promise.resolve();if("floating"===this.variant&&null==this.conversationId){const t=Number(sessionStorage.getItem("kr-chatbot-conversation-id"));t>0?(this.conversationId=t,e=i.Http.fetch({url:`/api/system/conversation/${t}`}).then((e=>e.json())).then((e=>{this._conversationTitle=e?.data?.title||""})).catch((()=>{}))):e=i.Http.fetch({url:"/api/system/conversation/last"}).then((e=>{if(e.ok)return e.json().then((e=>{const t=e?.data?.conversationID;"number"==typeof t&&(this.conversationId=t,this._conversationTitle=e?.data?.title||"",this._persistConversationId())}))})).catch((()=>{}))}e.then((()=>this.load())).then((e=>{e&&e.length&&(this.messages=e),this.conversationId&&!this._isStreaming&&this._reconnectStream()})).catch((()=>{})),i.Http.fetch({url:"/api/system/integration/aws/bedrock/aiFrameworkConfig"}).then((e=>e.json())).then((e=>{this._aiFrameworkConfig=e?.data||{}})).catch((()=>{})),"inline"===this.variant&&(this.opened=!0),this._restoreState(),document.addEventListener("click",this._handleDocumentClick),document.addEventListener("keydown",this._handleDocumentKeydown)}disconnectedCallback(){super.disconnectedCallback(),this._reader&&(this._reader.cancel(),this._reader=null),document.removeEventListener("mousemove",this._handleMouseMove),document.removeEventListener("mouseup",this._handleMouseUp),document.removeEventListener("click",this._handleDocumentClick),document.removeEventListener("keydown",this._handleDocumentKeydown),this._speechRecognition&&(this._speechRecognition.abort(),this._speechRecognition=null,this._isDictating=!1),this._pendingConversationFiles.forEach((e=>{e.previewUrl&&URL.revokeObjectURL(e.previewUrl)}))}updated(e){e.has("messages")&&(this._userHasScrolledUp||this._isStreaming||!this._messagesEl||requestAnimationFrame((()=>{this._messagesEl&&(this._messagesEl.scrollTop=this._messagesEl.scrollHeight)}))),e.has("opened")&&this.opened&&this._inputEl&&setTimeout((()=>{this._inputEl&&this._inputEl.focus()}),200),e.has("opened")&&this.opened&&0===this.messages.length&&this._loadSuggestedActions(),this._skillMenuOpened&&this._positionSkillMenu(),e.has("_skillHighlighted")&&this._skillMenuOpened&&this._skillMenuEl?.querySelector(".skill-menu__item--highlighted")?.scrollIntoView({block:"nearest"})}_positionSkillMenu(){requestAnimationFrame((()=>{if(!this._skillMenuEl||!this._inputWrapperEl)return;const e=this._inputWrapperEl.getBoundingClientRect();this._skillMenuEl.style.left=e.left+"px",this._skillMenuEl.style.width=e.width+"px";const t=this._panelEl.getBoundingClientRect().top+8,i=e.top-8-t;this._skillMenuEl.style.maxHeight=i+"px";const s=this._skillMenuEl.getBoundingClientRect(),n=Math.max(t,e.top-s.height-8);this._skillMenuEl.style.top=n+"px"}))}stop(){this._handleStop()}isStreaming(){return this._isStreaming}open(){this.opened||this._handleToggle()}close(){this.opened&&this._handleToggle()}toggle(){this._handleToggle()}_showOverlay(){this._overlay||(this._overlay=document.createElement("div"),this._overlay.style.cssText="position:fixed; inset:0; z-index:9999; display:none;",document.body.appendChild(this._overlay)),this._overlay.style.display="block"}_handleHeaderMouseDown(e){if("inline"===this.variant)return;if(e.target.closest("button"))return;if(!this._panelEl)return;this._isDragging=!0,this._panelEl.classList.add("panel--dragging"),this._showOverlay();const t=this._panelEl.getBoundingClientRect();this._panelEl.style.left=t.left+"px",this._panelEl.style.top=t.top+"px",this._panelEl.style.right="auto",this._panelEl.style.bottom="auto",this._panelEl.style.position="fixed",this._dragStartX=e.clientX,this._dragStartY=e.clientY,this._dragStartLeft=t.left,this._dragStartTop=t.top,e.preventDefault(),document.addEventListener("mousemove",this._handleMouseMove),document.addEventListener("mouseup",this._handleMouseUp)}_handleResizeMouseDown(e){if("inline"===this.variant)return;if(!this._panelEl)return;this._isResizing=!0,this._resizeDir=e.currentTarget.dataset.dir||"",this._panelEl.classList.add("panel--resizing"),this._showOverlay();const t=this._panelEl.getBoundingClientRect();this._panelEl.style.left=t.left+"px",this._panelEl.style.top=t.top+"px",this._panelEl.style.right="auto",this._panelEl.style.bottom="auto",this._panelEl.style.position="fixed",this._dragStartX=e.clientX,this._dragStartY=e.clientY,this._dragStartLeft=t.left,this._dragStartTop=t.top,this._resizeStartW=t.width,this._resizeStartH=t.height,e.preventDefault(),e.stopPropagation(),document.addEventListener("mousemove",this._handleMouseMove),document.addEventListener("mouseup",this._handleMouseUp)}_handleToggle(){this.opened=!this.opened,this.opened&&this._panelEl&&this._applyStoredLayout(),this._saveState()}_persistConversationId(){if("floating"===this.variant)try{null!=this.conversationId?sessionStorage.setItem("kr-chatbot-conversation-id",String(this.conversationId)):sessionStorage.removeItem("kr-chatbot-conversation-id")}catch{}}_saveState(){try{let e=this._drawerView;"toolDetail"===e&&(e="settings");const t={opened:String(this.opened),message:this._inputValue,mode:this._mode,showTools:String(this._showTools),showToolInputs:String(this._showToolInputs),showConfirmationInput:String(this._showConfirmationInput),drawerOpen:String(this._drawerOpen),drawerView:e,drawerWidth:String(this._drawerWidth)};if(this._panelEl){const e=this._panelEl.style;e.left&&(t.left=e.left),e.top&&(t.top=e.top),e.width&&(t.width=e.width),e.height&&(t.height=e.height),e.position&&(t.position=e.position)}localStorage.setItem("kr-chatbot-state",JSON.stringify(t))}catch{}}_restoreState(){try{const e=localStorage.getItem("kr-chatbot-state");if(!e)return;const t=JSON.parse(e);"string"==typeof t.message&&"/"!==t.message.trim()&&(this._inputValue=t.message),"NORMAL"!==t.mode&&"EDIT"!==t.mode&&"PLAN"!==t.mode||(this._mode=t.mode),this._showTools="true"===t.showTools,this._showToolInputs="true"===t.showToolInputs,this._showConfirmationInput="true"===t.showConfirmationInput,this._drawerOpen="true"===t.drawerOpen,"settings"!==t.drawerView&&"debug"!==t.drawerView&&"history"!==t.drawerView||(this._drawerView=t.drawerView,"history"===t.drawerView&&this._loadConversations());const i=Number(t.drawerWidth);i>=300&&(this._drawerWidth=i),"inline"!==this.variant&&"true"===t.opened&&(this.opened=!0,this.updateComplete.then((()=>this._applyStoredLayout())))}catch{}}_applyStoredLayout(){try{const e=localStorage.getItem("kr-chatbot-state");if(!e||!this._panelEl)return;const t=JSON.parse(e);t.position&&(this._panelEl.style.position=t.position),t.left&&(this._panelEl.style.left=t.left),t.top&&(this._panelEl.style.top=t.top),t.width&&(this._panelEl.style.width=t.width),t.height&&(this._panelEl.style.height=t.height)}catch{}}_handleInputChange(e){this._inputValue=e.target.value,this._saveState();const t=e.target;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,120)+"px";const i=this._inputValue.match(/^\/(\S*)$/);i?(this._skillMenuOpened=!0,this._skillQuery=i[1],this._skillHighlighted=0,this._searchInvocableSkills(this._skillQuery)):this._skillMenuOpened=!1}_handleKeyDown(e){if(this._skillMenuOpened){let t=3;"inline"===this.variant&&!0===this._aiFrameworkConfig.debugTelemetryEnabled&&(t=5);const i=t+this._invocableSkills.length;if("ArrowDown"===e.key)return e.preventDefault(),void(this._skillHighlighted=(this._skillHighlighted+1)%i);if("ArrowUp"===e.key)return e.preventDefault(),void(this._skillHighlighted=(this._skillHighlighted-1+i)%i);if("Enter"===e.key&&!e.shiftKey)return e.preventDefault(),void this._activateSkillMenuItem(this._skillHighlighted);if("Escape"===e.key)return e.preventDefault(),void(this._skillMenuOpened=!1)}"Enter"!==e.key||e.shiftKey||(e.preventDefault(),this._handleSubmit())}_activateSkillMenuItem(e){const t="inline"===this.variant&&!0===this._aiFrameworkConfig.debugTelemetryEnabled;let i=3;if(t&&(i=5),0===e)return void this._openFilePicker(!0);if(1===e)return void this._openFilePicker(!1);if(2===e)return void this._handleSkillBrowseOpen();if(t&&3===e)return this._skillMenuOpened=!1,void this._send({message:"/test-context-warning",conversationFiles:[]});if(t&&4===e)return this._skillMenuOpened=!1,void this._send({message:"/test-context-limit",conversationFiles:[]});const s=this._invocableSkills[e-i];s&&this._handleSkillSelect(s)}_searchOrgSkills(e){this._orgSkillRequestId++;const t=this._orgSkillRequestId;i.Http.fetch({url:"/api/system/conversation/localSkillList",method:"POST",body:{query:e.trim()}}).then((e=>e.json())).then((e=>{t===this._orgSkillRequestId&&(this._orgSkills=e?.data||[])})).catch((e=>{console.error("kr-chatbot: skill search failed",e)}))}_searchInvocableSkills(e){this._invocableSkillRequestId++;const t=this._invocableSkillRequestId;i.Http.fetch({url:"/api/system/conversation/availableSkills",method:"POST",body:{query:e.trim()}}).then((e=>e.json())).then((e=>{t===this._invocableSkillRequestId&&(this._invocableSkills=e?.data||[])})).catch((e=>{console.error("kr-chatbot: invocable skill search failed",e)}))}_loadSuggestedActions(){this._suggestedActionRequestId++;const e=this._suggestedActionRequestId,t=this._captureContext();i.Http.fetch({url:"/api/system/conversation/suggestedActions",method:"POST",body:{pageContext:t.pageContext,selectionContext:t.selectionContext}}).then((e=>e.json())).then((t=>{e!==this._suggestedActionRequestId||this.messages.length>0||(this._suggestedActions=t?.data||[])})).catch((e=>{console.error("kr-chatbot: suggested actions load failed",e)}))}_searchGlobalSkills(e){this._globalSkillRequestId++;const t=this._globalSkillRequestId;i.Http.fetch({url:"/api/system/conversation/globalSkillList",method:"POST",body:{query:e.trim()}}).then((e=>e.json())).then((e=>{t===this._globalSkillRequestId&&(this._globalSkills=e?.data||[])})).catch((e=>{console.error("kr-chatbot: global skill search failed",e)}))}_handleGlobalSkillEnable(e,s){if(s.stopPropagation(),!e.canEnable)return void t.Snackbar.show({title:"Permission Required",message:"You do not have permission to install skills. Please contact your site administrator.",type:"error"});if(this._globalSkillPending.has(e.code))return;const n=s.currentTarget;this._globalSkillPending.add(e.code),n?.showLoading(),i.Http.fetch({url:`/api/system/opensearch/aiskills/global/${encodeURIComponent(e.code)}/enabled`,method:"POST",body:{enabled:!e.enabled}}).then((e=>e.json())).then((t=>{e.enabled=t?.data?.enabled,n?.reset(),this.requestUpdate()})).catch((e=>{console.error("kr-chatbot: global skill enable failed",e),n?.showError("Error")})).finally((()=>{this._globalSkillPending.delete(e.code)}))}_handlePlusClick(){this._skillMenuOpened?this._skillMenuOpened=!1:(this._skillQuery="",this._skillHighlighted=0,this._skillMenuOpened=!0,this._searchInvocableSkills(""))}_handleModeToggle(){this._modeMenuOpened=!this._modeMenuOpened}_handleModeSelect(e){this._mode=e,this._modeMenuOpened=!1,this._saveState()}_handleShowToolsChange(e){this._showTools=e.target.checked,this._saveState()}_handleShowToolInputsChange(e){this._showToolInputs=e.target.checked,this._saveState()}_handleShowConfirmationInputChange(e){this._showConfirmationInput=e.target.checked,this._saveState()}_handleMicClick(){if(this._speechRecognition)return void this._speechRecognition.stop();const e=window.SpeechRecognition||window.webkitSpeechRecognition;if(!e)return;const t=new e;t.continuous=!0,t.interimResults=!0,this._speechBaseValue=this._inputValue,this._speechBaseValue&&!this._speechBaseValue.endsWith(" ")&&(this._speechBaseValue+=" "),this._speechFinalTranscript="",t.onresult=e=>{let t="";for(let i=e.resultIndex;i<e.results.length;i++)e.results[i].isFinal?this._speechFinalTranscript+=e.results[i][0].transcript:t+=e.results[i][0].transcript;this._inputValue=this._speechBaseValue+this._speechFinalTranscript+t,this._saveState(),this._inputEl&&(this._inputEl.style.height="auto",this._inputEl.style.height=Math.min(this._inputEl.scrollHeight,120)+"px")},t.onerror=e=>{"not-allowed"!==e.error&&"service-not-allowed"!==e.error||(this._error="Microphone access is blocked. Allow it in your browser settings to use voice input.")},t.onend=()=>{this._speechRecognition=null,this._isDictating=!1},this._speechRecognition=t,this._isDictating=!0,this._error="",t.start(),this._inputEl?.focus()}_handleSkillSelect(e){if(!1===e.canRun){let i=`You do not have access to "${e.name}". Ask your site administrator to grant it.`;return e.allowedRoles?.length&&(i=`"${e.name}" requires the ${e.allowedRoles.join(" or ")} role. Ask your site administrator to grant it.`),void t.Snackbar.show({title:"Access Required",message:i,type:"error"})}!e.global||e.enabled?(this._inputValue=`/${e.code} `,this._saveState(),this._skillMenuOpened=!1,this._skillBrowseOpened=!1,this._inputEl?.focus()):t.Snackbar.show({title:"Not Installed",message:`"${e.name}" has to be installed on this site before you can use it — use the Install button on the card.`,type:"info"})}_handleSkillCardKeydown(e,t){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),this._handleSkillSelect(t))}_handleSuggestedActionClick(e){this._inputValue=`/${e.code} `,this._saveState(),this._inputEl?.focus()}_handleCopyMessage(e,t){navigator.clipboard.writeText(e).then((()=>{this._copiedIndex=t,setTimeout((()=>{this._copiedIndex===t&&(this._copiedIndex=-1)}),2e3)})).catch((()=>{}))}_handleSkillBrowseOpen(){this._skillMenuOpened=!1,this._skillBrowseQuery="",this._skillBrowseOpened=!0,this._searchOrgSkills(""),!0!==this._aiFrameworkConfig.registryServer&&this._searchGlobalSkills("")}_handleSkillBrowseClose(){this._skillBrowseOpened=!1}_handleSkillBrowseSearch(e){this._skillBrowseQuery=e.target.value,this._searchOrgSkills(this._skillBrowseQuery),!0!==this._aiFrameworkConfig.registryServer&&this._searchGlobalSkills(this._skillBrowseQuery)}_handleSkillBrowseTabChange(e){this._skillBrowseSource=e.detail.activeTabId}_openFilePicker(e=!0){this._skillMenuOpened=!1,"/"===this._inputValue.trim()&&(this._inputValue="",this._saveState()),this._pendingAttachAnalyze=e,this._fileInputEl?.click()}_handleFileInputChange(e){const t=e.target;t.files&&this._addFiles(t.files,this._pendingAttachAnalyze),t.value=""}_handlePaste(e){const t=e.clipboardData?.items;if(!t)return;const i=[];for(let e=0;e<t.length;e++)if("file"===t[e].kind){const s=t[e].getAsFile();s&&i.push(s)}i.length&&(e.preventDefault(),this._addFiles(i))}_handleDragEnter(e){this._hasFiles(e)&&(e.preventDefault(),this._dragDepth++,this._isDraggingFile=!0)}_handleDragOver(e){this._hasFiles(e)&&e.preventDefault()}_handleDragLeave(e){this._hasFiles(e)&&(this._dragDepth--,this._dragDepth<=0&&(this._dragDepth=0,this._isDraggingFile=!1))}_handleDrop(e){this._hasFiles(e)&&(e.preventDefault(),this._dragDepth=0,this._isDraggingFile=!1,e.dataTransfer?.files&&this._addFiles(e.dataTransfer.files))}_hasFiles(e){return Array.from(e.dataTransfer?.types||[]).includes("Files")}_getFileExtension(e){const t=e.lastIndexOf(".");return t<0?"":e.slice(t+1).toLowerCase()}_addFiles(e,t=!0){const i=Array.from(e).filter((e=>Yt.includes(this._getFileExtension(e.name))));i.length&&i.forEach((e=>{let i;(e.type.startsWith("image/")||Qt.includes(this._getFileExtension(e.name)))&&(i=URL.createObjectURL(e));const s={localId:"att-"+this._pendingSeq++,file:e,name:e.name,mimeType:e.type,previewUrl:i,aiAnalyze:t};this._pendingConversationFiles=[...this._pendingConversationFiles,s]}))}_handlePendingRemove(e){const t=this._pendingConversationFiles.find((t=>t.localId===e));t?.previewUrl&&URL.revokeObjectURL(t.previewUrl),this._pendingConversationFiles=this._pendingConversationFiles.filter((t=>t.localId!==e))}_clearPending(){this._pendingConversationFiles.forEach((e=>{e.previewUrl&&URL.revokeObjectURL(e.previewUrl)})),this._pendingConversationFiles=[]}_handleFileOpen(e){const s=e.previewUrl||`${i.Http.getBaseUrl()}/api/system/conversationFile/${e.conversationFileID}/view`;t.FilePreview.open({src:s,name:e.niceName||"file"}).addEventListener("download",(()=>{window.open(`${i.Http.getBaseUrl()}/api/system/conversationFile/${e.conversationFileID}/view?download=true`,"_blank")}))}_handleSubmit(){if(this._isStreaming)return;if(this._pendingActions.length)return;const e=this._inputValue.trim(),t=this._pendingConversationFiles;if(!e&&!t.length)return;const i=t.map((e=>({file:e.file,aiAnalyze:e.aiAnalyze}))),s=new CustomEvent("message-submit",{detail:{message:e,conversationFiles:i},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(s),s.defaultPrevented||this._send({message:e,conversationFiles:i})}_send(e){const t={type:"user",content:e.message};this._pendingConversationFiles.length&&(t.conversationFiles=this._pendingConversationFiles.map((e=>({conversationFileID:-1,niceName:e.name,mimeType:e.mimeType,aiAnalyze:e.aiAnalyze,previewUrl:e.previewUrl})))),this._speechRecognition&&this._speechRecognition.abort(),this.messages=[...this.messages,t],this._inputValue="",this._suggestedActions=[],this._saveState(),this._error="",this._userHasScrolledUp=!1,this._pendingConversationFiles=[],this._inputEl&&(this._inputEl.style.height="auto"),this.messages=[...this.messages,{type:"assistant",content:""}],this._isStreaming=!0,this._turnFinishedCleanly=!1,this._reconnectAttempts=0,this.updateComplete.then((()=>{if(!this._messagesEl)return;this._messagesEl.querySelectorAll(".agent-turn").forEach((e=>{e.style.minHeight=""}));const e=this._messagesEl.querySelectorAll(".message--user"),t=e[e.length-1],i=this._messagesEl.querySelectorAll(".agent-turn"),s=i[i.length-1];s&&(s.style.minHeight=this._messagesEl.clientHeight+"px"),t&&(this._messagesEl.scrollTop=t.offsetTop-this._messagesEl.offsetTop-24)})),this.send||(this.send=e=>{if(e.confirmation)return i.Http.fetch({url:"/api/system/integration/aws/bedrock/stream/invokeModelForConversationWithState",method:"POST",headers:{Accept:"text/event-stream"},body:{confirmation:e.confirmation,conversationID:this.conversationId}});let t=Promise.resolve([]);return e.conversationFiles.length&&(t=Promise.all(e.conversationFiles.map((({file:e,aiAnalyze:t})=>{const s=new FormData;return s.append("file",e),s.append("type","LIBRARY"),s.append("niceName",e.name),t||s.append("aiAnalyze","false"),i.Http.fetch({url:"/api/system/conversationFile/upload",method:"POST",body:s}).then((e=>e.json())).then((e=>e.data))})))),t.then((t=>{if(t.length)for(let e=this.messages.length-1;e>=0;e--)if("user"===this.messages[e].type){(this.messages[e].conversationFiles||[]).forEach((e=>{e.previewUrl&&URL.revokeObjectURL(e.previewUrl)})),this.messages[e].conversationFiles=t,this.requestUpdate();break}const s={userText:e.message,fileIds:t.map((e=>e.conversationFileID)),mode:this._mode};return e.pageContext&&(s.pageContext=e.pageContext),e.selectionContext&&(s.selectionContext=e.selectionContext),null!=this.conversationId?s.conversationID=this.conversationId:s.createNew=!0,i.Http.fetch({url:"/api/system/integration/aws/bedrock/stream/invokeModelForConversationWithState",method:"POST",headers:{Accept:"text/event-stream"},body:s}).then((e=>(null==this.conversationId&&i.Http.fetch({url:"/api/system/conversation/last"}).then((e=>e.json())).then((e=>{const t=e?.data,i=t?.conversationID;"number"==typeof i&&(this.conversationId=i,this._persistConversationId(),this.dispatchEvent(new CustomEvent("conversation-created",{detail:{conversation:t},bubbles:!0,composed:!0})))})).catch((()=>{})),e)))}))});const s=this._captureContext();this.send({message:e.message,messages:this.messages.slice(0,-1),conversationFiles:e.conversationFiles,pageContext:s.pageContext,selectionContext:s.selectionContext}).then((e=>{e.ok?e.body?(this._reader=e.body.getReader(),this._decoder=new TextDecoder,this._buffer="",this._readStreamChunk()):this._handleStreamError("No response body"):this._handleStreamError("Request failed: "+e.status)})).catch((e=>{"AbortError"!==e.name&&this._handleStreamError(e.message)}))}_handleConfirmationDecision(e){if(this._confirmationInFlight)return;this._confirmationInFlight=!0,this._error="";const t=this._messagesEl?.querySelector(`.confirmation__btn[data-decision="${e}"]`);t?.showLoading(),this._isStreaming=!0,this._turnFinishedCleanly=!1,this._reconnectAttempts=0,this._userHasScrolledUp=!1,this.send({message:"",messages:this.messages,conversationFiles:[],pageContext:"",selectionContext:"",confirmation:e}).then((e=>e.ok?e.body?(this._reader=e.body.getReader(),this._decoder=new TextDecoder,this._buffer="",void this._readStreamChunk()):(this._confirmationInFlight=!1,t?.reset(),void this._handleStreamError("No response body")):(this._confirmationInFlight=!1,t?.reset(),void this._handleStreamError("Request failed: "+e.status)))).catch((e=>{this._confirmationInFlight=!1,t?.reset(),"AbortError"!==e.name&&this._handleStreamError(e.message)}))}_captureContext(){let e="";try{const t={url:window.location.href,title:document.title},i=document.getElementById("kodaris-page");if(i&&i.textContent)try{t.page=JSON.parse(i.textContent)}catch{}e=JSON.stringify(t)}catch{}let t="";try{const e=window.getSelection();e&&(t=e.toString().trim())}catch{}return{pageContext:e,selectionContext:t}}_handleStop(){this._reader&&(this._reader.cancel(),this._reader=null),this._isStreaming=!1}_handleMessagesScroll(e){const t=e.target,i=t.scrollHeight-t.scrollTop-t.clientHeight;this._userHasScrolledUp=i>50}_handleErrorDismiss(){this._error=""}_handleContextWarningDismiss(){this._contextWarning=""}_toggleDrawer(e){this._drawerOpen&&this._drawerView===e?this._drawerOpen=!1:(this._drawerOpen=!0,this._drawerView=e,"history"===e&&this._loadConversations()),this._saveState()}_loadConversations(){this._conversationsLoading=!0,i.Http.fetch({url:"/api/system/conversation/list",method:"POST",body:{page:0,size:50,sortBy:"lastModified",sortDirection:"desc",filterFields:[{name:"active",operation:"IS",value:"true"}]}}).then((e=>e.json())).then((e=>{this._conversations=e?.data?.content||[]})).catch((()=>{this._conversations=[]})).then((()=>{this._conversationsLoading=!1}))}_handleSwitchConversation(e){e!==this.conversationId?(this._handleStop(),this.conversationId=e,this._conversationTitle=this._conversations.find((t=>t.conversationID===e))?.title||"",this._persistConversationId(),this._pendingActions=[],this._inlineConfirm=!0,this._contextWarning="",this._contextLimitReached=!1,this._contextLimitMessage="",this._error="",this._reconnectAttempts=0,this._pendingConversationFiles.forEach((e=>{e.previewUrl&&URL.revokeObjectURL(e.previewUrl)})),this._pendingConversationFiles=[],this._drawerOpen=!1,this._saveState(),this.load&&this.load().then((e=>{this.messages=e||[],this.conversationId&&!this._isStreaming&&this._reconnectStream()})).catch((()=>{}))):this._handleCloseDrawer()}_handleNewConversation(){this._handleStop(),this.conversationId=null,this._conversationTitle="",this._persistConversationId(),this.messages=[],this._pendingActions=[],this._inlineConfirm=!0,this._contextWarning="",this._contextLimitReached=!1,this._contextLimitMessage="",this._error="",this._reconnectAttempts=0,this._pendingConversationFiles.forEach((e=>{e.previewUrl&&URL.revokeObjectURL(e.previewUrl)})),this._pendingConversationFiles=[],this._drawerOpen=!1,this._saveState()}_handleCloseDrawer(){this._drawerOpen=!1,this._saveState()}_openToolDetail(e){const t=this.messages[this.messages.indexOf(e)+1];this._toolDetail={use:e,result:null},"tool_result"===t?.type&&t.data?.toolUseId===e.data?.toolUseId&&(this._toolDetail.result=t),this._toolDetailCopied=null,this._toolDetailInputOpen=!0,this._toolDetailOutputOpen=!0,this._drawerView="toolDetail",this._drawerOpen=!0,this._saveState(),this.updateComplete.then((()=>{this._drawerBodyEl&&(this._drawerBodyEl.scrollTop=0)}))}_handleToggleToolDetailInput(){this._toolDetailInputOpen=!this._toolDetailInputOpen}_handleToggleToolDetailOutput(){this._toolDetailOutputOpen=!this._toolDetailOutputOpen}_formatToolJson(e){if(null==e)return"";const t=String(e),i=t.match(/(<<<[0-9a-f-]+_BEGIN>>>\n?)([\s\S]*?)(\n?<<<[0-9a-f-]+_END>>>)/);if(i&&null!=i.index){const e=i.index+i[1].length,s=e+i[2].length;return t.slice(0,e)+this._reindentJson(i[2])+t.slice(s)}return this._reindentJson(t)}_reindentJson(e){const t=e.trim();if(!t.startsWith("{")&&!t.startsWith("["))return e;try{return JSON.stringify(JSON.parse(t),null,2)}catch{}let i="",s=0,n=!1,o=!1;const r=e=>"\n"+" ".repeat(Math.max(0,e));for(let e=0;e<t.length;e++){const a=t[e];n?(i+=a,o?o=!1:"\\"===a?o=!0:'"'===a&&(n=!1)):'"'===a?(n=!0,i+=a):"{"===a||"["===a?(s++,i+=a+r(s)):"}"===a||"]"===a?(s--,i+=r(s)+a):","===a?i+=a+r(s):":"===a?i+=": ":" "===a||"\n"===a||"\t"===a||"\r"===a||(i+=a)}return i}_handleCopyToolDetailInput(e){e.stopPropagation(),this._copyToolDetail("input",this._formatToolJson(this._toolDetail?.use.data?.toolInput))}_handleCopyToolDetailOutput(e){e.stopPropagation(),this._copyToolDetail("output",this._formatToolJson(this._toolDetail?.result?.data?.toolResultString))}_copyToolDetail(e,t){navigator.clipboard.writeText(t).then((()=>{this._toolDetailCopied=e,setTimeout((()=>{this._toolDetailCopied===e&&(this._toolDetailCopied=null)}),2e3)})).catch((()=>{}))}_handleDrawerResizeMouseDown(e){this._isDrawerResizing=!0,this._drawerResizeStartX=e.clientX,this._drawerResizeStartW=this._drawerWidth,e.preventDefault(),e.stopPropagation(),document.addEventListener("mousemove",this._handleDrawerResizeMouseMove),document.addEventListener("mouseup",this._handleDrawerResizeMouseUp)}_readStreamChunk(){this._reader&&this._reader.read().then((e=>{if(e.done){if(this._turnFinishedCleanly)return;return void this._reconnectStream()}this._buffer=this._buffer+this._decoder.decode(e.value,{stream:!0});const t=this._buffer.split("\n\n");this._buffer=t.pop()||"";for(let e=0;e<t.length;e++){if(!t[e].trim())continue;const i=t[e].split("\n");for(let e=0;e<i.length;e++){if(!i[e].startsWith("data:"))continue;const t=i[e].slice(5).trim();if(!t)continue;let s;try{s=JSON.parse(t)}catch{continue}if(this.dispatchEvent(new CustomEvent("stream-event",{detail:s,bubbles:!0,composed:!0})),"REASONING_PART"===s.type){if(s.message){const e=this._ensureAssistantBubble();e.reasoning||(e.reasoning=""),e.reasoning+=String(s.message),this.requestUpdate()}}else if("RESPONSE_PART"===s.type)s.message&&(this._ensureAssistantBubble().content+=String(s.message),this.requestUpdate());else if("tool_use"===s.type||"tool_result"===s.type)this.messages.push(s),this.requestUpdate();else if("action_decision"===s.type)this._pendingActions=[],this._confirmationHighlighted=-1,this._confirmationInFlight=!1,this.messages.push(s),this.requestUpdate();else if("ERROR"===s.type)this._handleStreamError(String(s.message||"Unknown error"));else if("CONVERSATION_STATE"===s.type)"NORMAL"!==s.data?.mode&&"EDIT"!==s.data?.mode&&"PLAN"!==s.data?.mode||(this._mode=s.data.mode);else if("CONVERSATION_TOKEN_WARNING"===s.type)this._contextWarning=String(s.message||"");else if("CONVERSATION_TITLE"===s.type)s.data?.title&&(this._conversationTitle=s.data.title,this.dispatchEvent(new CustomEvent("conversation-title",{detail:{title:s.data.title},bubbles:!0,composed:!0})));else if("CONVERSATION_LIMIT_REACHED"===s.type)this._contextLimitReached=!0,this._contextLimitMessage=String(s.message||""),this._contextWarning="";else if("ACTION_CONFIRMATION_REQUIRED"===s.type){const e=s.data?.actions;Array.isArray(e)&&e.length&&(this._pendingActions=e,this._confirmationHighlighted=0)}else if("TOKEN_USAGE"===s.type){if(s.data){const e=s.data;this._telemetry=e,1===e.iteration?(this._iterationLog=[e],this._cacheCheckpoints={}):this._iterationLog=[...this._iterationLog,e]}}else if("CACHE_CHECKPOINT"===s.type&&s.data){const e=s.data;this._cacheCheckpoints={...this._cacheCheckpoints,[e.iteration]:e}}s.finished&&(this._turnFinishedCleanly=!0,this._finishStream())}}this._reader&&this._readStreamChunk()})).catch((e=>{"AbortError"!==e.name&&(this._turnFinishedCleanly?this._handleStreamError(e.message):this._reconnectStream())}))}_reconnectStream(){this.conversationId?this._reconnectAttempts>=5?this._handleStreamError("Lost connection to the assistant. Please reload the conversation."):(this._reconnectAttempts=this._reconnectAttempts+1,i.Http.fetch({url:`/api/system/integration/aws/bedrock/stream/attach/${this.conversationId}`,method:"GET",headers:{Accept:"text/event-stream"}}).then((e=>{if(204===e.status)return this._reconnectAttempts=0,this.load&&this.load().then((e=>{this.messages=e,this.requestUpdate()})).catch((()=>{})),void this._finishStream();e.ok&&e.body?(this._reconnectAttempts=0,this._isStreaming=!0,this._reader=e.body.getReader(),this._decoder=new TextDecoder,this._buffer="",this.load?this.load().then((e=>{this.messages=e,this.requestUpdate(),this._readStreamChunk()})).catch((()=>{this._readStreamChunk()})):this._readStreamChunk()):setTimeout((()=>this._reconnectStream()),1e3)})).catch((()=>{setTimeout((()=>this._reconnectStream()),1e3)}))):this._finishStream()}_ensureAssistantBubble(){const e=this.messages[this.messages.length-1];if(e&&"assistant"===e.type)return e;const t={type:"assistant",content:""};return this.messages=[...this.messages,t],t}_finishStream(){if(this._isStreaming=!1,this._reader=null,this._pendingActions.length){const e=this.messages.length-1;e>=0&&"assistant"===this.messages[e].type&&!this.messages[e].content&&!this.messages[e].reasoning&&(this.messages=this.messages.slice(0,-1)),this._inlineConfirm&&this.updateComplete.then((()=>{this._messagesEl?.querySelector(".confirmation")?.scrollIntoView({behavior:"smooth",block:"end"})}))}}_handleStreamError(e){if(this._isStreaming=!1,this._error=e,this._reader&&(this._reader.cancel(),this._reader=null),this.messages.length>0){const e=this.messages[this.messages.length-1];"assistant"!==e.type||e.content||(this.messages=this.messages.slice(0,-1))}}_renderModeSelector(){const e=Xt.find((e=>e.mode===this._mode))||Xt[0];return q`
|
|
211
|
+
*/function Ne(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let Pe={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function Le(e){Pe=e}const Fe=/[&<>"']/,Ue=new RegExp(Fe.source,"g"),je=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,He=new RegExp(je.source,"g"),Be={"&":"&","<":"<",">":">",'"':""","'":"'"},qe=e=>Be[e];function We(e,t){if(t){if(Fe.test(e))return e.replace(Ue,qe)}else if(je.test(e))return e.replace(He,qe);return e}const Ve=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function Xe(e){return e.replace(Ve,((e,t)=>"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""))}const Qe=/(^|[^\[])\^/g;function Ye(e,t){let i="string"==typeof e?e:e.source;t=t||"";const s={replace:(e,t)=>{let n="string"==typeof t?t:t.source;return n=n.replace(Qe,"$1"),i=i.replace(e,n),s},getRegex:()=>new RegExp(i,t)};return s}function Ke(e){try{e=encodeURI(e).replace(/%25/g,"%")}catch(e){return null}return e}const Ze={exec:()=>null};function Je(e,t){const i=e.replace(/\|/g,((e,t,i)=>{let s=!1,n=t;for(;--n>=0&&"\\"===i[n];)s=!s;return s?"|":" |"})).split(/ \|/);let s=0;if(i[0].trim()||i.shift(),i.length>0&&!i[i.length-1].trim()&&i.pop(),t)if(i.length>t)i.splice(t);else for(;i.length<t;)i.push("");for(;s<i.length;s++)i[s]=i[s].trim().replace(/\\\|/g,"|");return i}function Ge(e,t,i){const s=e.length;if(0===s)return"";let n=0;for(;n<s;){if(e.charAt(s-n-1)!==t)break;n++}return e.slice(0,s-n)}function et(e,t,i,s){const n=t.href,o=t.title?We(t.title):null,r=e[1].replace(/\\([\[\]])/g,"$1");if("!"!==e[0].charAt(0)){s.state.inLink=!0;const e={type:"link",raw:i,href:n,title:o,text:r,tokens:s.inlineTokens(r)};return s.state.inLink=!1,e}return{type:"image",raw:i,href:n,title:o,text:We(r)}}class tt{options;rules;lexer;constructor(e){this.options=e||Pe}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const e=t[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:Ge(e,"\n")}}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const e=t[0],i=function(e,t){const i=e.match(/^(\s+)(?:```)/);if(null===i)return t;const s=i[1];return t.split("\n").map((e=>{const t=e.match(/^\s+/);if(null===t)return e;const[i]=t;return i.length>=s.length?e.slice(s.length):e})).join("\n")}(e,t[3]||"");return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:i}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(/#$/.test(e)){const t=Ge(e,"#");this.options.pedantic?e=t.trim():t&&!/ $/.test(t)||(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){const t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:t[0]}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){let e=t[0].replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,"\n $1");e=Ge(e.replace(/^ *>[ \t]?/gm,""),"\n");const i=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(e);return this.lexer.state.top=i,{type:"blockquote",raw:t[0],tokens:s,text:e}}}list(e){let t=this.rules.block.list.exec(e);if(t){let i=t[1].trim();const s=i.length>1,n={type:"list",raw:"",ordered:s,start:s?+i.slice(0,-1):"",loose:!1,items:[]};i=s?`\\d{1,9}\\${i.slice(-1)}`:`\\${i}`,this.options.pedantic&&(i=s?i:"[*+-]");const o=new RegExp(`^( {0,3}${i})((?:[\t ][^\\n]*)?(?:\\n|$))`);let r="",a="",l=!1;for(;e;){let i=!1;if(!(t=o.exec(e)))break;if(this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let s=t[2].split("\n",1)[0].replace(/^\t+/,(e=>" ".repeat(3*e.length))),h=e.split("\n",1)[0],c=0;this.options.pedantic?(c=2,a=s.trimStart()):(c=t[2].search(/[^ ]/),c=c>4?1:c,a=s.slice(c),c+=t[1].length);let d=!1;if(!s&&/^ *$/.test(h)&&(r+=h+"\n",e=e.substring(h.length+1),i=!0),!i){const t=new RegExp(`^ {0,${Math.min(3,c-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),i=new RegExp(`^ {0,${Math.min(3,c-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),n=new RegExp(`^ {0,${Math.min(3,c-1)}}(?:\`\`\`|~~~)`),o=new RegExp(`^ {0,${Math.min(3,c-1)}}#`);for(;e;){const l=e.split("\n",1)[0];if(h=l,this.options.pedantic&&(h=h.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),n.test(h))break;if(o.test(h))break;if(t.test(h))break;if(i.test(e))break;if(h.search(/[^ ]/)>=c||!h.trim())a+="\n"+h.slice(c);else{if(d)break;if(s.search(/[^ ]/)>=4)break;if(n.test(s))break;if(o.test(s))break;if(i.test(s))break;a+="\n"+h}d||h.trim()||(d=!0),r+=l+"\n",e=e.substring(l.length+1),s=h.slice(c)}}n.loose||(l?n.loose=!0:/\n *\n *$/.test(r)&&(l=!0));let p,u=null;this.options.gfm&&(u=/^\[[ xX]\] /.exec(a),u&&(p="[ ] "!==u[0],a=a.replace(/^\[[ xX]\] +/,""))),n.items.push({type:"list_item",raw:r,task:!!u,checked:p,loose:!1,text:a,tokens:[]}),n.raw+=r}n.items[n.items.length-1].raw=r.trimEnd(),n.items[n.items.length-1].text=a.trimEnd(),n.raw=n.raw.trimEnd();for(let e=0;e<n.items.length;e++)if(this.lexer.state.top=!1,n.items[e].tokens=this.lexer.blockTokens(n.items[e].text,[]),!n.loose){const t=n.items[e].tokens.filter((e=>"space"===e.type)),i=t.length>0&&t.some((e=>/\n.*\n/.test(e.raw)));n.loose=i}if(n.loose)for(let e=0;e<n.items.length;e++)n.items[e].loose=!0;return n}}html(e){const t=this.rules.block.html.exec(e);if(t){return{type:"html",block:!0,raw:t[0],pre:"pre"===t[1]||"script"===t[1]||"style"===t[1],text:t[0]}}}def(e){const t=this.rules.block.def.exec(e);if(t){const e=t[1].toLowerCase().replace(/\s+/g," "),i=t[2]?t[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:e,raw:t[0],href:i,title:s}}}table(e){const t=this.rules.block.table.exec(e);if(!t)return;if(!/[:|]/.test(t[2]))return;const i=Je(t[1]),s=t[2].replace(/^\||\| *$/g,"").split("|"),n=t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split("\n"):[],o={type:"table",raw:t[0],header:[],align:[],rows:[]};if(i.length===s.length){for(const e of s)/^ *-+: *$/.test(e)?o.align.push("right"):/^ *:-+: *$/.test(e)?o.align.push("center"):/^ *:-+ *$/.test(e)?o.align.push("left"):o.align.push(null);for(const e of i)o.header.push({text:e,tokens:this.lexer.inline(e)});for(const e of n)o.rows.push(Je(e,o.header.length).map((e=>({text:e,tokens:this.lexer.inline(e)}))));return o}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){const t=this.rules.block.paragraph.exec(e);if(t){const e="\n"===t[1].charAt(t[1].length-1)?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){const 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){const t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:We(t[1])}}tag(e){const t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&/^<a /i.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.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){const t=this.rules.inline.link.exec(e);if(t){const e=t[2].trim();if(!this.options.pedantic&&/^</.test(e)){if(!/>$/.test(e))return;const t=Ge(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{const e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let i=0;for(let s=0;s<e.length;s++)if("\\"===e[s])s++;else if(e[s]===t[0])i++;else if(e[s]===t[1]&&(i--,i<0))return s;return-1}(t[2],"()");if(e>-1){const i=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,i).trim(),t[3]=""}}let i=t[2],s="";if(this.options.pedantic){const e=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(i);e&&(i=e[1],s=e[3])}else s=t[3]?t[3].slice(1,-1):"";return i=i.trim(),/^</.test(i)&&(i=this.options.pedantic&&!/>$/.test(e)?i.slice(1):i.slice(1,-1)),et(t,{href:i?i.replace(this.rules.inline.anyPunctuation,"$1"):i,title:s?s.replace(this.rules.inline.anyPunctuation,"$1"):s},t[0],this.lexer)}}reflink(e,t){let i;if((i=this.rules.inline.reflink.exec(e))||(i=this.rules.inline.nolink.exec(e))){const e=t[(i[2]||i[1]).replace(/\s+/g," ").toLowerCase()];if(!e){const e=i[0].charAt(0);return{type:"text",raw:e,text:e}}return et(i,e,i[0],this.lexer)}}emStrong(e,t,i=""){let s=this.rules.inline.emStrongLDelim.exec(e);if(!s)return;if(s[3]&&i.match(/[\p{L}\p{N}]/u))return;if(!(s[1]||s[2]||"")||!i||this.rules.inline.punctuation.exec(i)){const i=[...s[0]].length-1;let n,o,r=i,a=0;const l="*"===s[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+i);null!=(s=l.exec(t));){if(n=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!n)continue;if(o=[...n].length,s[3]||s[4]){r+=o;continue}if((s[5]||s[6])&&i%3&&!((i+o)%3)){a+=o;continue}if(r-=o,r>0)continue;o=Math.min(o,o+r+a);const t=[...s[0]][0].length,l=e.slice(0,i+s.index+t+o);if(Math.min(i,o)%2){const e=l.slice(1,-1);return{type:"em",raw:l,text:e,tokens:this.lexer.inlineTokens(e)}}const h=l.slice(2,-2);return{type:"strong",raw:l,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(/\n/g," ");const i=/[^ ]/.test(e),s=/^ /.test(e)&&/ $/.test(e);return i&&s&&(e=e.substring(1,e.length-1)),e=We(e,!0),{type:"codespan",raw:t[0],text:e}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){const t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){const t=this.rules.inline.autolink.exec(e);if(t){let e,i;return"@"===t[2]?(e=We(t[1]),i="mailto:"+e):(e=We(t[1]),i=e),{type:"link",raw:t[0],text:e,href:i,tokens:[{type:"text",raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,i;if("@"===t[2])e=We(t[0]),i="mailto:"+e;else{let s;do{s=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(s!==t[0]);e=We(t[0]),i="www."===t[1]?"http://"+t[0]:t[0]}return{type:"link",raw:t[0],text:e,href:i,tokens:[{type:"text",raw:e,text:e}]}}}inlineText(e){const t=this.rules.inline.text.exec(e);if(t){let e;return e=this.lexer.state.inRawBlock?t[0]:We(t[0]),{type:"text",raw:t[0],text:e}}}}const it=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,st=/(?:[*+-]|\d{1,9}[.)])/,nt=Ye(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,st).replace(/blockCode/g,/ {4}/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).getRegex(),ot=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,rt=/(?!\s*\])(?:\\.|[^\[\]\\])+/,at=Ye(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label",rt).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),lt=Ye(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,st).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",ct=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,dt=Ye("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))","i").replace("comment",ct).replace("tag",ht).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),pt=Ye(ot).replace("hr",it).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ht).getRegex(),ut={blockquote:Ye(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",pt).getRegex(),code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,def:at,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:it,html:dt,lheading:nt,list:lt,newline:/^(?: *(?:\n|$))+/,paragraph:pt,table:Ze,text:/^[^\n]+/},gt=Ye("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",it).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ht).getRegex(),mt={...ut,table:gt,paragraph:Ye(ot).replace("hr",it).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",gt).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ht).getRegex()},ft={...ut,html:Ye("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",ct).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:Ze,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Ye(ot).replace("hr",it).replace("heading"," *#{1,6} *[^\n]").replace("lheading",nt).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},vt=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,bt=/^( {2,}|\\)\n(?!\s*$)/,_t="\\p{P}\\p{S}",xt=Ye(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,_t).getRegex(),kt=Ye(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,_t).getRegex(),wt=Ye("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,_t).getRegex(),yt=Ye("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,_t).getRegex(),$t=Ye(/\\([punct])/,"gu").replace(/punct/g,_t).getRegex(),St=Ye(/^<(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=Ye(ct).replace("(?:--\x3e|$)","--\x3e").getRegex(),Ct=Ye("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",It).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Et=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,At=Ye(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",Et).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Tt=Ye(/^!?\[(label)\]\[(ref)\]/).replace("label",Et).replace("ref",rt).getRegex(),zt=Ye(/^!?\[(ref)\](?:\[\])?/).replace("ref",rt).getRegex(),Dt={_backpedal:Ze,anyPunctuation:$t,autolink:St,blockSkip:/\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g,br:bt,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:Ze,emStrongLDelim:kt,emStrongRDelimAst:wt,emStrongRDelimUnd:yt,escape:vt,link:At,nolink:zt,punctuation:xt,reflink:Tt,reflinkSearch:Ye("reflink|nolink(?!\\()","g").replace("reflink",Tt).replace("nolink",zt).getRegex(),tag:Ct,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:Ze},Rt={...Dt,link:Ye(/^!?\[(label)\]\((.*?)\)/).replace("label",Et).getRegex(),reflink:Ye(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Et).getRegex()},Mt={...Dt,escape:Ye(vt).replace("])","~|])").getRegex(),url:Ye(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},Ot={...Mt,br:Ye(bt).replace("{2,}","*").getRegex(),text:Ye(Mt.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Nt={normal:ut,gfm:mt,pedantic:ft},Pt={normal:Dt,gfm:Mt,breaks:Ot,pedantic:Rt};class Lt{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Pe,this.options.tokenizer=this.options.tokenizer||new tt,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const t={block:Nt.normal,inline:Pt.normal};this.options.pedantic?(t.block=Nt.pedantic,t.inline=Pt.pedantic):this.options.gfm&&(t.block=Nt.gfm,this.options.breaks?t.inline=Pt.breaks:t.inline=Pt.gfm),this.tokenizer.rules=t}static get rules(){return{block:Nt,inline:Pt}}static lex(e,t){return new Lt(t).lex(e)}static lexInline(e,t){return new Lt(t).inlineTokens(e)}lex(e){e=e.replace(/\r\n|\r/g,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){const t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[]){let i,s,n,o;for(e=this.options.pedantic?e.replace(/\t/g," ").replace(/^ +$/gm,""):e.replace(/^( *)(\t+)/gm,((e,t,i)=>t+" ".repeat(i.length)));e;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some((s=>!!(i=s.call({lexer:this},e,t))&&(e=e.substring(i.raw.length),t.push(i),!0)))))if(i=this.tokenizer.space(e))e=e.substring(i.raw.length),1===i.raw.length&&t.length>0?t[t.length-1].raw+="\n":t.push(i);else if(i=this.tokenizer.code(e))e=e.substring(i.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?t.push(i):(s.raw+="\n"+i.raw,s.text+="\n"+i.text,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(i=this.tokenizer.fences(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.heading(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.hr(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.blockquote(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.list(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.html(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.def(e))e=e.substring(i.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title}):(s.raw+="\n"+i.raw,s.text+="\n"+i.raw,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(i=this.tokenizer.table(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.lheading(e))e=e.substring(i.raw.length),t.push(i);else{if(n=e,this.options.extensions&&this.options.extensions.startBlock){let t=1/0;const i=e.slice(1);let s;this.options.extensions.startBlock.forEach((e=>{s=e.call({lexer:this},i),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(n=e.substring(0,t+1))}if(this.state.top&&(i=this.tokenizer.paragraph(n)))s=t[t.length-1],o&&"paragraph"===s.type?(s.raw+="\n"+i.raw,s.text+="\n"+i.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(i),o=n.length!==e.length,e=e.substring(i.raw.length);else if(i=this.tokenizer.text(e))e=e.substring(i.raw.length),s=t[t.length-1],s&&"text"===s.type?(s.raw+="\n"+i.raw,s.text+="\n"+i.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(i);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let i,s,n,o,r,a,l=e;if(this.tokens.links){const e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(o=this.tokenizer.rules.inline.reflinkSearch.exec(l));)e.includes(o[0].slice(o[0].lastIndexOf("[")+1,-1))&&(l=l.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+l.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(o=this.tokenizer.rules.inline.blockSkip.exec(l));)l=l.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+l.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;null!=(o=this.tokenizer.rules.inline.anyPunctuation.exec(l));)l=l.slice(0,o.index)+"++"+l.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;e;)if(r||(a=""),r=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some((s=>!!(i=s.call({lexer:this},e,t))&&(e=e.substring(i.raw.length),t.push(i),!0)))))if(i=this.tokenizer.escape(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.tag(e))e=e.substring(i.raw.length),s=t[t.length-1],s&&"text"===i.type&&"text"===s.type?(s.raw+=i.raw,s.text+=i.text):t.push(i);else if(i=this.tokenizer.link(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.reflink(e,this.tokens.links))e=e.substring(i.raw.length),s=t[t.length-1],s&&"text"===i.type&&"text"===s.type?(s.raw+=i.raw,s.text+=i.text):t.push(i);else if(i=this.tokenizer.emStrong(e,l,a))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.codespan(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.br(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.del(e))e=e.substring(i.raw.length),t.push(i);else if(i=this.tokenizer.autolink(e))e=e.substring(i.raw.length),t.push(i);else if(this.state.inLink||!(i=this.tokenizer.url(e))){if(n=e,this.options.extensions&&this.options.extensions.startInline){let t=1/0;const i=e.slice(1);let s;this.options.extensions.startInline.forEach((e=>{s=e.call({lexer:this},i),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(n=e.substring(0,t+1))}if(i=this.tokenizer.inlineText(n))e=e.substring(i.raw.length),"_"!==i.raw.slice(-1)&&(a=i.raw.slice(-1)),r=!0,s=t[t.length-1],s&&"text"===s.type?(s.raw+=i.raw,s.text+=i.text):t.push(i);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}else e=e.substring(i.raw.length),t.push(i);return t}}class Ft{options;constructor(e){this.options=e||Pe}code(e,t,i){const s=(t||"").match(/^\S*/)?.[0];return e=e.replace(/\n$/,"")+"\n",s?'<pre><code class="language-'+We(s)+'">'+(i?e:We(e,!0))+"</code></pre>\n":"<pre><code>"+(i?e:We(e,!0))+"</code></pre>\n"}blockquote(e){return`<blockquote>\n${e}</blockquote>\n`}html(e,t){return e}heading(e,t,i){return`<h${t}>${e}</h${t}>\n`}hr(){return"<hr>\n"}list(e,t,i){const s=t?"ol":"ul";return"<"+s+(t&&1!==i?' start="'+i+'"':"")+">\n"+e+"</"+s+">\n"}listitem(e,t,i){return`<li>${e}</li>\n`}checkbox(e){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph(e){return`<p>${e}</p>\n`}table(e,t){return t&&(t=`<tbody>${t}</tbody>`),"<table>\n<thead>\n"+e+"</thead>\n"+t+"</table>\n"}tablerow(e){return`<tr>\n${e}</tr>\n`}tablecell(e,t){const i=t.header?"th":"td";return(t.align?`<${i} align="${t.align}">`:`<${i}>`)+e+`</${i}>\n`}strong(e){return`<strong>${e}</strong>`}em(e){return`<em>${e}</em>`}codespan(e){return`<code>${e}</code>`}br(){return"<br>"}del(e){return`<del>${e}</del>`}link(e,t,i){const s=Ke(e);if(null===s)return i;let n='<a href="'+(e=s)+'"';return t&&(n+=' title="'+t+'"'),n+=">"+i+"</a>",n}image(e,t,i){const s=Ke(e);if(null===s)return i;let n=`<img src="${e=s}" alt="${i}"`;return t&&(n+=` title="${t}"`),n+=">",n}text(e){return e}}class Ut{strong(e){return e}em(e){return e}codespan(e){return e}del(e){return e}html(e){return e}text(e){return e}link(e,t,i){return""+i}image(e,t,i){return""+i}br(){return""}}class jt{options;renderer;textRenderer;constructor(e){this.options=e||Pe,this.options.renderer=this.options.renderer||new Ft,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new Ut}static parse(e,t){return new jt(t).parse(e)}static parseInline(e,t){return new jt(t).parseInline(e)}parse(e,t=!0){let i="";for(let s=0;s<e.length;s++){const n=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[n.type]){const e=n,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(e.type)){i+=t||"";continue}}switch(n.type){case"space":continue;case"hr":i+=this.renderer.hr();continue;case"heading":{const e=n;i+=this.renderer.heading(this.parseInline(e.tokens),e.depth,Xe(this.parseInline(e.tokens,this.textRenderer)));continue}case"code":{const e=n;i+=this.renderer.code(e.text,e.lang,!!e.escaped);continue}case"table":{const e=n;let t="",s="";for(let t=0;t<e.header.length;t++)s+=this.renderer.tablecell(this.parseInline(e.header[t].tokens),{header:!0,align:e.align[t]});t+=this.renderer.tablerow(s);let o="";for(let t=0;t<e.rows.length;t++){const i=e.rows[t];s="";for(let t=0;t<i.length;t++)s+=this.renderer.tablecell(this.parseInline(i[t].tokens),{header:!1,align:e.align[t]});o+=this.renderer.tablerow(s)}i+=this.renderer.table(t,o);continue}case"blockquote":{const e=n,t=this.parse(e.tokens);i+=this.renderer.blockquote(t);continue}case"list":{const e=n,t=e.ordered,s=e.start,o=e.loose;let r="";for(let t=0;t<e.items.length;t++){const i=e.items[t],s=i.checked,n=i.task;let a="";if(i.task){const e=this.renderer.checkbox(!!s);o?i.tokens.length>0&&"paragraph"===i.tokens[0].type?(i.tokens[0].text=e+" "+i.tokens[0].text,i.tokens[0].tokens&&i.tokens[0].tokens.length>0&&"text"===i.tokens[0].tokens[0].type&&(i.tokens[0].tokens[0].text=e+" "+i.tokens[0].tokens[0].text)):i.tokens.unshift({type:"text",text:e+" "}):a+=e+" "}a+=this.parse(i.tokens,o),r+=this.renderer.listitem(a,n,!!s)}i+=this.renderer.list(r,t,s);continue}case"html":{const e=n;i+=this.renderer.html(e.text,e.block);continue}case"paragraph":{const e=n;i+=this.renderer.paragraph(this.parseInline(e.tokens));continue}case"text":{let o=n,r=o.tokens?this.parseInline(o.tokens):o.text;for(;s+1<e.length&&"text"===e[s+1].type;)o=e[++s],r+="\n"+(o.tokens?this.parseInline(o.tokens):o.text);i+=t?this.renderer.paragraph(r):r;continue}default:{const e='Token with "'+n.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return i}parseInline(e,t){t=t||this.renderer;let i="";for(let s=0;s<e.length;s++){const n=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[n.type]){const e=this.options.extensions.renderers[n.type].call({parser:this},n);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(n.type)){i+=e||"";continue}}switch(n.type){case"escape":{const e=n;i+=t.text(e.text);break}case"html":{const e=n;i+=t.html(e.text);break}case"link":{const e=n;i+=t.link(e.href,e.title,this.parseInline(e.tokens,t));break}case"image":{const e=n;i+=t.image(e.href,e.title,e.text);break}case"strong":{const e=n;i+=t.strong(this.parseInline(e.tokens,t));break}case"em":{const e=n;i+=t.em(this.parseInline(e.tokens,t));break}case"codespan":{const e=n;i+=t.codespan(e.text);break}case"br":i+=t.br();break;case"del":{const e=n;i+=t.del(this.parseInline(e.tokens,t));break}case"text":{const e=n;i+=t.text(e.text);break}default:{const e='Token with "'+n.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return i}}class Ht{options;constructor(e){this.options=e||Pe}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}}const Bt=new class{defaults={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};options=this.setOptions;parse=this.#e(Lt.lex,jt.parse);parseInline=this.#e(Lt.lexInline,jt.parseInline);Parser=jt;Renderer=Ft;TextRenderer=Ut;Lexer=Lt;Tokenizer=tt;Hooks=Ht;constructor(...e){this.use(...e)}walkTokens(e,t){let i=[];for(const s of e)switch(i=i.concat(t.call(this,s)),s.type){case"table":{const e=s;for(const s of e.header)i=i.concat(this.walkTokens(s.tokens,t));for(const s of e.rows)for(const e of s)i=i.concat(this.walkTokens(e.tokens,t));break}case"list":{const e=s;i=i.concat(this.walkTokens(e.items,t));break}default:{const e=s;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach((s=>{const n=e[s].flat(1/0);i=i.concat(this.walkTokens(n,t))})):e.tokens&&(i=i.concat(this.walkTokens(e.tokens,t)))}}return i}use(...e){const t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach((e=>{const i={...e};if(i.async=this.defaults.async||i.async||!1,e.extensions&&(e.extensions.forEach((e=>{if(!e.name)throw new Error("extension name required");if("renderer"in e){const i=t.renderers[e.name];t.renderers[e.name]=i?function(...t){let s=e.renderer.apply(this,t);return!1===s&&(s=i.apply(this,t)),s}:e.renderer}if("tokenizer"in e){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");const i=t[e.level];i?i.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&("block"===e.level?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:"inline"===e.level&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}"childTokens"in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)})),i.extensions=t),e.renderer){const t=this.defaults.renderer||new Ft(this.defaults);for(const i in e.renderer){if(!(i in t))throw new Error(`renderer '${i}' does not exist`);if("options"===i)continue;const s=i,n=e.renderer[s],o=t[s];t[s]=(...e)=>{let i=n.apply(t,e);return!1===i&&(i=o.apply(t,e)),i||""}}i.renderer=t}if(e.tokenizer){const t=this.defaults.tokenizer||new tt(this.defaults);for(const i in e.tokenizer){if(!(i in t))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;const s=i,n=e.tokenizer[s],o=t[s];t[s]=(...e)=>{let i=n.apply(t,e);return!1===i&&(i=o.apply(t,e)),i}}i.tokenizer=t}if(e.hooks){const t=this.defaults.hooks||new Ht;for(const i in e.hooks){if(!(i in t))throw new Error(`hook '${i}' does not exist`);if("options"===i)continue;const s=i,n=e.hooks[s],o=t[s];Ht.passThroughHooks.has(i)?t[s]=e=>{if(this.defaults.async)return Promise.resolve(n.call(t,e)).then((e=>o.call(t,e)));const i=n.call(t,e);return o.call(t,i)}:t[s]=(...e)=>{let i=n.apply(t,e);return!1===i&&(i=o.apply(t,e)),i}}i.hooks=t}if(e.walkTokens){const t=this.defaults.walkTokens,s=e.walkTokens;i.walkTokens=function(e){let i=[];return i.push(s.call(this,e)),t&&(i=i.concat(t.call(this,e))),i}}this.defaults={...this.defaults,...i}})),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return Lt.lex(e,t??this.defaults)}parser(e,t){return jt.parse(e,t??this.defaults)}#e(e,t){return(i,s)=>{const n={...s},o={...this.defaults,...n};!0===this.defaults.async&&!1===n.async&&(o.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),o.async=!0);const r=this.#t(!!o.silent,!!o.async);if(null==i)return r(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof i)return r(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(i)+", string expected"));if(o.hooks&&(o.hooks.options=o),o.async)return Promise.resolve(o.hooks?o.hooks.preprocess(i):i).then((t=>e(t,o))).then((e=>o.hooks?o.hooks.processAllTokens(e):e)).then((e=>o.walkTokens?Promise.all(this.walkTokens(e,o.walkTokens)).then((()=>e)):e)).then((e=>t(e,o))).then((e=>o.hooks?o.hooks.postprocess(e):e)).catch(r);try{o.hooks&&(i=o.hooks.preprocess(i));let s=e(i,o);o.hooks&&(s=o.hooks.processAllTokens(s)),o.walkTokens&&this.walkTokens(s,o.walkTokens);let n=t(s,o);return o.hooks&&(n=o.hooks.postprocess(n)),n}catch(e){return r(e)}}}#t(e,t){return i=>{if(i.message+="\nPlease report this to https://github.com/markedjs/marked.",e){const e="<p>An error occurred:</p><pre>"+We(i.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(i);throw i}}};function qt(e,t){return Bt.parse(e,t)}qt.options=qt.setOptions=function(e){return Bt.setOptions(e),qt.defaults=Bt.defaults,Le(qt.defaults),qt},qt.getDefaults=Ne,qt.defaults=Pe,qt.use=function(...e){return Bt.use(...e),qt.defaults=Bt.defaults,Le(qt.defaults),qt},qt.walkTokens=function(e,t){return Bt.walkTokens(e,t)},qt.parseInline=Bt.parseInline,qt.Parser=jt,qt.parser=jt.parse,qt.Renderer=Ft,qt.TextRenderer=Ut,qt.Lexer=Lt,qt.lexer=Lt.lex,qt.Tokenizer=tt,qt.Hooks=Ht,qt.parse=qt,qt.options,qt.setOptions,qt.use,qt.walkTokens,qt.parseInline,jt.parse,Lt.lex;var Wt=function(e,t,i,s){var n,o=arguments.length,r=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(r=(o<3?n(r):o>3?n(t,i,r):n(t,i))||r);return o>3&&r&&Object.defineProperty(t,i,r),r};const Vt=[{decision:"approve",label:"Yes"},{decision:"approveAlways",label:"Always allow"},{decision:"reject",label:"No"}],Xt=[{mode:"NORMAL",label:"Ask",description:"Asks before making changes"},{mode:"EDIT",label:"Auto",description:"Makes changes automatically"},{mode:"PLAN",label:"Plan",description:"Suggests a plan, makes no changes"}],Qt=["jpg","jpeg","png","gif","webp"],Yt=["pdf","doc","docx","xls","xlsx","csv","html","md","txt","json","xml","vtt","srt",...Qt,"mp4","webm","ogg","mov"];class Kt extends le{constructor(){super(...arguments),this._inlineConfirm=!0,this._reasoningAsMessage=!0,this._reader=null,this._decoder=new TextDecoder,this._buffer="",this._turnFinishedCleanly=!1,this._reconnectAttempts=0,this._userHasScrolledUp=!1,this._isDragging=!1,this._isResizing=!1,this._overlay=null,this._resizeDir="",this._dragStartX=0,this._dragStartY=0,this._dragStartLeft=0,this._dragStartTop=0,this._resizeStartW=0,this._resizeStartH=0,this._drawerResizeStartX=0,this._drawerResizeStartW=0,this._dragDepth=0,this._pendingSeq=0,this._pendingAttachAnalyze=!0,this._orgSkillRequestId=0,this._globalSkillRequestId=0,this._invocableSkillRequestId=0,this._suggestedActionRequestId=0,this._globalSkillPending=new Set,this._speechRecognition=null,this._speechBaseValue="",this._speechFinalTranscript="",this.send=null,this.load=null,this.messages=[],this.label="Kat",this.placeholder="Type a message...",this.opened=!1,this.hideToggle=!1,this.variant="floating",this.conversationId=null,this._inputValue="",this._isStreaming=!1,this._error="",this._conversationTitle="",this._contextWarning="",this._contextLimitReached=!1,this._contextLimitMessage="",this._pendingActions=[],this._confirmationHighlighted=-1,this._confirmationInFlight=!1,this._telemetry=null,this._iterationLog=[],this._cacheCheckpoints={},this._drawerOpen=!1,this._drawerView="settings",this._conversations=[],this._conversationsLoading=!1,this._toolDetail=null,this._toolDetailCopied=null,this._toolDetailInputOpen=!0,this._toolDetailOutputOpen=!0,this._drawerWidth=430,this._isDrawerResizing=!1,this._pendingConversationFiles=[],this._isDraggingFile=!1,this._skillMenuOpened=!1,this._skillQuery="",this._orgSkills=[],this._globalSkills=[],this._invocableSkills=[],this._suggestedActions=[],this._aiFrameworkConfig={},this._skillHighlighted=0,this._copiedIndex=-1,this._skillBrowseOpened=!1,this._skillBrowseSource="org",this._skillBrowseQuery="",this._isDictating=!1,this._mode="NORMAL",this._modeMenuOpened=!1,this._showTools=!0,this._showToolInputs=!1,this._showConfirmationInput=!1,this._handleDocumentClick=e=>{if(this._modeMenuOpened){e.composedPath().some((e=>e instanceof HTMLElement&&e.classList.contains("mode")))||(this._modeMenuOpened=!1)}if(!this._skillMenuOpened)return;e.composedPath().some((e=>e instanceof HTMLElement&&(e.classList.contains("skill-menu")||e.classList.contains("input")||e.classList.contains("input-plus"))))||(this._skillMenuOpened=!1)},this._handleMouseMove=e=>{if(this._isDragging){let t=this._dragStartLeft+(e.clientX-this._dragStartX),i=this._dragStartTop+(e.clientY-this._dragStartY);const s=this._panelEl.offsetWidth;t=Math.max(48-s,Math.min(t,window.innerWidth-48)),i=Math.max(0,Math.min(i,window.innerHeight-48)),this._panelEl.style.left=t+"px",this._panelEl.style.top=i+"px"}else if(this._isResizing){const t=e.clientX-this._dragStartX,i=e.clientY-this._dragStartY,s=340,n=380,o=.9*window.innerWidth,r=window.innerHeight-72;let a=this._resizeStartW,l=this._resizeStartH,h=this._dragStartLeft,c=this._dragStartTop;this._resizeDir.includes("e")&&(a=Math.max(s,Math.min(this._resizeStartW+t,o))),this._resizeDir.includes("w")&&(a=Math.max(s,Math.min(this._resizeStartW-t,o)),h=this._dragStartLeft+(this._resizeStartW-a)),this._resizeDir.includes("s")&&(l=Math.max(n,Math.min(this._resizeStartH+i,r))),this._resizeDir.includes("n")&&(l=Math.max(n,Math.min(this._resizeStartH-i,r)),c=this._dragStartTop+(this._resizeStartH-l)),h=Math.max(0,h),c=Math.max(0,c),this._panelEl.style.width=a+"px",this._panelEl.style.height=l+"px",this._panelEl.style.left=h+"px",this._panelEl.style.top=c+"px"}},this._handleMouseUp=()=>{this._isDragging&&(this._isDragging=!1,this._panelEl.classList.remove("panel--dragging")),this._isResizing&&(this._isResizing=!1,this._panelEl.classList.remove("panel--resizing")),this._overlay&&(this._overlay.style.display="none"),document.removeEventListener("mousemove",this._handleMouseMove),document.removeEventListener("mouseup",this._handleMouseUp),this._saveState()},this._handleDocumentKeydown=e=>{if(this._pendingActions.length&&!this._confirmationInFlight){if("ArrowRight"===e.key)return e.preventDefault(),void(this._confirmationHighlighted=(this._confirmationHighlighted+1)%Vt.length);if("ArrowLeft"===e.key)return e.preventDefault(),void(this._confirmationHighlighted=(this._confirmationHighlighted-1+Vt.length)%Vt.length);if("Enter"===e.key){e.preventDefault();const t=Vt[this._confirmationHighlighted];t&&this._handleConfirmationDecision(t.decision)}}},this._handleDrawerResizeMouseMove=e=>{if(!this._isDrawerResizing)return;const t=e.clientX-this._drawerResizeStartX,i=Math.max(300,this.offsetWidth-300);this._drawerWidth=Math.max(300,Math.min(this._drawerResizeStartW-t,i))},this._handleDrawerResizeMouseUp=()=>{this._isDrawerResizing=!1,document.removeEventListener("mousemove",this._handleDrawerResizeMouseMove),document.removeEventListener("mouseup",this._handleDrawerResizeMouseUp),this._saveState()}}connectedCallback(){super.connectedCallback(),this.load||(this.load=()=>null==this.conversationId?Promise.resolve([]):i.Http.fetch({url:`/api/system/conversation/${this.conversationId}/messages`}).then((e=>e.json())).then((e=>Promise.all((e?.data||[]).map((e=>{if("tool_use"===e.type||"tool_result"===e.type){let t={};try{t=JSON.parse(e.content||"{}")}catch{}return Promise.resolve({type:e.type,content:"",data:t})}if("reasoning"===e.type)return Promise.resolve({type:"assistant",content:"",reasoning:e.content||""});if("action_decision"===e.type){let t={};try{t=JSON.parse(e.content||"{}")}catch{}return Promise.resolve({type:"action_decision",content:"",data:t})}let t=[];try{t=JSON.parse(e.conversationFileIDs||"[]")}catch{}return t.length?Promise.all(t.map((e=>i.Http.fetch({url:`/api/system/conversationFile/${e}`}).then((e=>e.json())).then((e=>e?.data)).catch((()=>null))))).then((t=>(e.conversationFiles=t.filter((e=>null!=e)),e))):Promise.resolve(e)}))))));let e=Promise.resolve();if("floating"===this.variant&&null==this.conversationId){const t=Number(sessionStorage.getItem("kr-chatbot-conversation-id"));t>0?(this.conversationId=t,e=i.Http.fetch({url:`/api/system/conversation/${t}`}).then((e=>e.json())).then((e=>{this._conversationTitle=e?.data?.title||""})).catch((()=>{}))):e=i.Http.fetch({url:"/api/system/conversation/last"}).then((e=>{if(e.ok)return e.json().then((e=>{const t=e?.data?.conversationID;"number"==typeof t&&(this.conversationId=t,this._conversationTitle=e?.data?.title||"",this._persistConversationId())}))})).catch((()=>{}))}e.then((()=>this.load())).then((e=>{e&&e.length&&(this.messages=e),this.conversationId&&!this._isStreaming&&this._reconnectStream()})).catch((()=>{})),i.Http.fetch({url:"/api/system/integration/aws/bedrock/aiFrameworkConfig"}).then((e=>e.json())).then((e=>{this._aiFrameworkConfig=e?.data||{}})).catch((()=>{})),"inline"===this.variant&&(this.opened=!0),this._restoreState(),document.addEventListener("click",this._handleDocumentClick),document.addEventListener("keydown",this._handleDocumentKeydown)}disconnectedCallback(){super.disconnectedCallback(),this._reader&&(this._reader.cancel(),this._reader=null),document.removeEventListener("mousemove",this._handleMouseMove),document.removeEventListener("mouseup",this._handleMouseUp),document.removeEventListener("click",this._handleDocumentClick),document.removeEventListener("keydown",this._handleDocumentKeydown),this._speechRecognition&&(this._speechRecognition.abort(),this._speechRecognition=null,this._isDictating=!1),this._pendingConversationFiles.forEach((e=>{e.previewUrl&&URL.revokeObjectURL(e.previewUrl)}))}updated(e){e.has("messages")&&(this._userHasScrolledUp||this._isStreaming||!this._messagesEl||requestAnimationFrame((()=>{this._messagesEl&&(this._messagesEl.scrollTop=this._messagesEl.scrollHeight)}))),e.has("opened")&&this.opened&&this._inputEl&&setTimeout((()=>{this._inputEl&&this._inputEl.focus()}),200),e.has("opened")&&this.opened&&0===this.messages.length&&this._loadSuggestedActions(),this._skillMenuOpened&&this._positionSkillMenu(),e.has("_skillHighlighted")&&this._skillMenuOpened&&this._skillMenuEl?.querySelector(".skill-menu__item--highlighted")?.scrollIntoView({block:"nearest"})}_positionSkillMenu(){requestAnimationFrame((()=>{if(!this._skillMenuEl||!this._inputWrapperEl)return;const e=this._inputWrapperEl.getBoundingClientRect();this._skillMenuEl.style.left=e.left+"px",this._skillMenuEl.style.width=e.width+"px";const t=this._panelEl.getBoundingClientRect().top+8,i=e.top-8-t;this._skillMenuEl.style.maxHeight=i+"px";const s=this._skillMenuEl.getBoundingClientRect(),n=Math.max(t,e.top-s.height-8);this._skillMenuEl.style.top=n+"px"}))}stop(){this._handleStop()}isStreaming(){return this._isStreaming}open(){this.opened||this._handleToggle()}close(){this.opened&&this._handleToggle()}toggle(){this._handleToggle()}_showOverlay(){this._overlay||(this._overlay=document.createElement("div"),this._overlay.style.cssText="position:fixed; inset:0; z-index:9999; display:none;",document.body.appendChild(this._overlay)),this._overlay.style.display="block"}_handleHeaderMouseDown(e){if("inline"===this.variant)return;if(e.target.closest("button"))return;if(!this._panelEl)return;this._isDragging=!0,this._panelEl.classList.add("panel--dragging"),this._showOverlay();const t=this._panelEl.getBoundingClientRect();this._panelEl.style.left=t.left+"px",this._panelEl.style.top=t.top+"px",this._panelEl.style.right="auto",this._panelEl.style.bottom="auto",this._panelEl.style.position="fixed",this._dragStartX=e.clientX,this._dragStartY=e.clientY,this._dragStartLeft=t.left,this._dragStartTop=t.top,e.preventDefault(),document.addEventListener("mousemove",this._handleMouseMove),document.addEventListener("mouseup",this._handleMouseUp)}_handleResizeMouseDown(e){if("inline"===this.variant)return;if(!this._panelEl)return;this._isResizing=!0,this._resizeDir=e.currentTarget.dataset.dir||"",this._panelEl.classList.add("panel--resizing"),this._showOverlay();const t=this._panelEl.getBoundingClientRect();this._panelEl.style.left=t.left+"px",this._panelEl.style.top=t.top+"px",this._panelEl.style.right="auto",this._panelEl.style.bottom="auto",this._panelEl.style.position="fixed",this._dragStartX=e.clientX,this._dragStartY=e.clientY,this._dragStartLeft=t.left,this._dragStartTop=t.top,this._resizeStartW=t.width,this._resizeStartH=t.height,e.preventDefault(),e.stopPropagation(),document.addEventListener("mousemove",this._handleMouseMove),document.addEventListener("mouseup",this._handleMouseUp)}_handleToggle(){this.opened=!this.opened,this.opened&&this._panelEl&&this._applyStoredLayout(),this._saveState()}_persistConversationId(){if("floating"===this.variant)try{null!=this.conversationId?sessionStorage.setItem("kr-chatbot-conversation-id",String(this.conversationId)):sessionStorage.removeItem("kr-chatbot-conversation-id")}catch{}}_saveState(){try{let e=this._drawerView;"toolDetail"===e&&(e="settings");const t={opened:String(this.opened),message:this._inputValue,mode:this._mode,showTools:String(this._showTools),showToolInputs:String(this._showToolInputs),showConfirmationInput:String(this._showConfirmationInput),drawerOpen:String(this._drawerOpen),drawerView:e,drawerWidth:String(this._drawerWidth)};if(this._panelEl){const e=this._panelEl.style;e.left&&(t.left=e.left),e.top&&(t.top=e.top),e.width&&(t.width=e.width),e.height&&(t.height=e.height),e.position&&(t.position=e.position)}localStorage.setItem("kr-chatbot-state",JSON.stringify(t))}catch{}}_restoreState(){try{const e=localStorage.getItem("kr-chatbot-state");if(!e)return;const t=JSON.parse(e);"string"==typeof t.message&&"/"!==t.message.trim()&&(this._inputValue=t.message),"NORMAL"!==t.mode&&"EDIT"!==t.mode&&"PLAN"!==t.mode||(this._mode=t.mode),this._showTools="true"===t.showTools,this._showToolInputs="true"===t.showToolInputs,this._showConfirmationInput="true"===t.showConfirmationInput,this._drawerOpen="true"===t.drawerOpen,"settings"!==t.drawerView&&"debug"!==t.drawerView&&"history"!==t.drawerView||(this._drawerView=t.drawerView,"history"===t.drawerView&&this._loadConversations());const i=Number(t.drawerWidth);i>=300&&(this._drawerWidth=i),"inline"!==this.variant&&"true"===t.opened&&(this.opened=!0,this.updateComplete.then((()=>this._applyStoredLayout())))}catch{}}_applyStoredLayout(){try{const e=localStorage.getItem("kr-chatbot-state");if(!e||!this._panelEl)return;const t=JSON.parse(e);t.position&&(this._panelEl.style.position=t.position),t.left&&(this._panelEl.style.left=t.left),t.top&&(this._panelEl.style.top=t.top),t.width&&(this._panelEl.style.width=t.width),t.height&&(this._panelEl.style.height=t.height)}catch{}}_handleInputChange(e){this._inputValue=e.target.value,this._saveState();const t=e.target;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,120)+"px";const i=this._inputValue.match(/^\/(\S*)$/);i?(this._skillMenuOpened=!0,this._skillQuery=i[1],this._skillHighlighted=0,this._searchInvocableSkills(this._skillQuery)):this._skillMenuOpened=!1}_handleKeyDown(e){if(this._skillMenuOpened){let t=3;"inline"===this.variant&&!0===this._aiFrameworkConfig.debugTelemetryEnabled&&(t=5);const i=t+this._invocableSkills.length;if("ArrowDown"===e.key)return e.preventDefault(),void(this._skillHighlighted=(this._skillHighlighted+1)%i);if("ArrowUp"===e.key)return e.preventDefault(),void(this._skillHighlighted=(this._skillHighlighted-1+i)%i);if("Enter"===e.key&&!e.shiftKey)return e.preventDefault(),void this._activateSkillMenuItem(this._skillHighlighted);if("Escape"===e.key)return e.preventDefault(),void(this._skillMenuOpened=!1)}"Enter"!==e.key||e.shiftKey||(e.preventDefault(),this._handleSubmit())}_activateSkillMenuItem(e){const t="inline"===this.variant&&!0===this._aiFrameworkConfig.debugTelemetryEnabled;let i=3;if(t&&(i=5),0===e)return void this._openFilePicker(!0);if(1===e)return void this._openFilePicker(!1);if(2===e)return void this._handleSkillBrowseOpen();if(t&&3===e)return this._skillMenuOpened=!1,void this._send({message:"/test-context-warning",conversationFiles:[]});if(t&&4===e)return this._skillMenuOpened=!1,void this._send({message:"/test-context-limit",conversationFiles:[]});const s=this._invocableSkills[e-i];s&&this._handleSkillSelect(s)}_searchOrgSkills(e){this._orgSkillRequestId++;const t=this._orgSkillRequestId;i.Http.fetch({url:"/api/system/conversation/localSkillList",method:"POST",body:{query:e.trim()}}).then((e=>e.json())).then((e=>{t===this._orgSkillRequestId&&(this._orgSkills=e?.data||[])})).catch((e=>{console.error("kr-chatbot: skill search failed",e)}))}_searchInvocableSkills(e){this._invocableSkillRequestId++;const t=this._invocableSkillRequestId;i.Http.fetch({url:"/api/system/conversation/availableSkills",method:"POST",body:{query:e.trim()}}).then((e=>e.json())).then((e=>{t===this._invocableSkillRequestId&&(this._invocableSkills=e?.data||[])})).catch((e=>{console.error("kr-chatbot: invocable skill search failed",e)}))}_loadSuggestedActions(){this._suggestedActionRequestId++;const e=this._suggestedActionRequestId,t=this._captureContext();i.Http.fetch({url:"/api/system/conversation/suggestedActions",method:"POST",body:{pageContext:t.pageContext,selectionContext:t.selectionContext}}).then((e=>e.json())).then((t=>{e!==this._suggestedActionRequestId||this.messages.length>0||(this._suggestedActions=t?.data||[])})).catch((e=>{console.error("kr-chatbot: suggested actions load failed",e)}))}_searchGlobalSkills(e){this._globalSkillRequestId++;const t=this._globalSkillRequestId;i.Http.fetch({url:"/api/system/conversation/globalSkillList",method:"POST",body:{query:e.trim()}}).then((e=>e.json())).then((e=>{t===this._globalSkillRequestId&&(this._globalSkills=e?.data||[])})).catch((e=>{console.error("kr-chatbot: global skill search failed",e)}))}_handleGlobalSkillEnable(e,s){if(s.stopPropagation(),!e.canEnable)return void t.Snackbar.show({title:"Permission Required",message:"You do not have permission to install skills. Please contact your site administrator.",type:"error"});if(this._globalSkillPending.has(e.code))return;const n=s.currentTarget;this._globalSkillPending.add(e.code),n?.showLoading(),i.Http.fetch({url:`/api/system/opensearch/aiskills/global/${encodeURIComponent(e.code)}/enabled`,method:"POST",body:{enabled:!e.enabled}}).then((e=>e.json())).then((t=>{e.enabled=t?.data?.enabled,n?.reset(),this.requestUpdate()})).catch((e=>{console.error("kr-chatbot: global skill enable failed",e),n?.showError("Error")})).finally((()=>{this._globalSkillPending.delete(e.code)}))}_handlePlusClick(){this._skillMenuOpened?this._skillMenuOpened=!1:(this._skillQuery="",this._skillHighlighted=0,this._skillMenuOpened=!0,this._searchInvocableSkills(""))}_handleModeToggle(){this._modeMenuOpened=!this._modeMenuOpened}_handleModeSelect(e){this._mode=e,this._modeMenuOpened=!1,this._saveState()}_handleShowToolsChange(e){this._showTools=e.target.checked,this._saveState()}_handleShowToolInputsChange(e){this._showToolInputs=e.target.checked,this._saveState()}_handleShowConfirmationInputChange(e){this._showConfirmationInput=e.target.checked,this._saveState()}_handleMicClick(){if(this._speechRecognition)return void this._speechRecognition.stop();const e=window.SpeechRecognition||window.webkitSpeechRecognition;if(!e)return;const t=new e;t.continuous=!0,t.interimResults=!0,this._speechBaseValue=this._inputValue,this._speechBaseValue&&!this._speechBaseValue.endsWith(" ")&&(this._speechBaseValue+=" "),this._speechFinalTranscript="",t.onresult=e=>{let t="";for(let i=e.resultIndex;i<e.results.length;i++)e.results[i].isFinal?this._speechFinalTranscript+=e.results[i][0].transcript:t+=e.results[i][0].transcript;this._inputValue=this._speechBaseValue+this._speechFinalTranscript+t,this._saveState(),this._inputEl&&(this._inputEl.style.height="auto",this._inputEl.style.height=Math.min(this._inputEl.scrollHeight,120)+"px")},t.onerror=e=>{"not-allowed"!==e.error&&"service-not-allowed"!==e.error||(this._error="Microphone access is blocked. Allow it in your browser settings to use voice input.")},t.onend=()=>{this._speechRecognition=null,this._isDictating=!1},this._speechRecognition=t,this._isDictating=!0,this._error="",t.start(),this._inputEl?.focus()}_handleSkillSelect(e){if(!1===e.canRun){let i=`You do not have access to "${e.name}". Ask your site administrator to grant it.`;return e.allowedRoles?.length&&(i=`"${e.name}" requires the ${e.allowedRoles.join(" or ")} role. Ask your site administrator to grant it.`),void t.Snackbar.show({title:"Access Required",message:i,type:"error"})}!e.global||e.enabled?(this._inputValue=`/${e.code} `,this._saveState(),this._skillMenuOpened=!1,this._skillBrowseOpened=!1,this._inputEl?.focus()):t.Snackbar.show({title:"Not Installed",message:`"${e.name}" has to be installed on this site before you can use it — use the Install button on the card.`,type:"info"})}_handleSkillCardKeydown(e,t){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),this._handleSkillSelect(t))}_handleSuggestedActionClick(e){this._inputValue=`/${e.code} `,this._saveState(),this._inputEl?.focus()}_handleCopyMessage(e,t){navigator.clipboard.writeText(e).then((()=>{this._copiedIndex=t,setTimeout((()=>{this._copiedIndex===t&&(this._copiedIndex=-1)}),2e3)})).catch((()=>{}))}_handleSkillBrowseOpen(){this._skillMenuOpened=!1,this._skillBrowseQuery="",this._skillBrowseOpened=!0,this._searchOrgSkills(""),!0!==this._aiFrameworkConfig.registryServer&&this._searchGlobalSkills("")}_handleSkillBrowseClose(){this._skillBrowseOpened=!1}_handleSkillBrowseSearch(e){this._skillBrowseQuery=e.target.value,this._searchOrgSkills(this._skillBrowseQuery),!0!==this._aiFrameworkConfig.registryServer&&this._searchGlobalSkills(this._skillBrowseQuery)}_handleSkillBrowseTabChange(e){this._skillBrowseSource=e.detail.activeTabId}_openFilePicker(e=!0){this._skillMenuOpened=!1,"/"===this._inputValue.trim()&&(this._inputValue="",this._saveState()),this._pendingAttachAnalyze=e,this._fileInputEl?.click()}_handleFileInputChange(e){const t=e.target;t.files&&this._addFiles(t.files,this._pendingAttachAnalyze),t.value=""}_handlePaste(e){const t=e.clipboardData?.items;if(!t)return;const i=[];for(let e=0;e<t.length;e++)if("file"===t[e].kind){const s=t[e].getAsFile();s&&i.push(s)}i.length&&(e.preventDefault(),this._addFiles(i))}_handleDragEnter(e){this._hasFiles(e)&&(e.preventDefault(),this._dragDepth++,this._isDraggingFile=!0)}_handleDragOver(e){this._hasFiles(e)&&e.preventDefault()}_handleDragLeave(e){this._hasFiles(e)&&(this._dragDepth--,this._dragDepth<=0&&(this._dragDepth=0,this._isDraggingFile=!1))}_handleDrop(e){this._hasFiles(e)&&(e.preventDefault(),this._dragDepth=0,this._isDraggingFile=!1,e.dataTransfer?.files&&this._addFiles(e.dataTransfer.files))}_hasFiles(e){return Array.from(e.dataTransfer?.types||[]).includes("Files")}_getFileExtension(e){const t=e.lastIndexOf(".");return t<0?"":e.slice(t+1).toLowerCase()}_addFiles(e,t=!0){const i=Array.from(e).filter((e=>Yt.includes(this._getFileExtension(e.name))));i.length&&i.forEach((e=>{let i;(e.type.startsWith("image/")||Qt.includes(this._getFileExtension(e.name)))&&(i=URL.createObjectURL(e));const s={localId:"att-"+this._pendingSeq++,file:e,name:e.name,mimeType:e.type,previewUrl:i,aiAnalyze:t};this._pendingConversationFiles=[...this._pendingConversationFiles,s]}))}_handlePendingRemove(e){const t=this._pendingConversationFiles.find((t=>t.localId===e));t?.previewUrl&&URL.revokeObjectURL(t.previewUrl),this._pendingConversationFiles=this._pendingConversationFiles.filter((t=>t.localId!==e))}_clearPending(){this._pendingConversationFiles.forEach((e=>{e.previewUrl&&URL.revokeObjectURL(e.previewUrl)})),this._pendingConversationFiles=[]}_handleFileOpen(e){const s=e.previewUrl||`${i.Http.getBaseUrl()}/api/system/conversationFile/${e.conversationFileID}/view`;t.FilePreview.open({src:s,name:e.niceName||"file"}).addEventListener("download",(()=>{window.open(`${i.Http.getBaseUrl()}/api/system/conversationFile/${e.conversationFileID}/view?download=true`,"_blank")}))}_handleSubmit(){if(this._isStreaming)return;if(this._pendingActions.length)return;const e=this._inputValue.trim(),t=this._pendingConversationFiles;if(!e&&!t.length)return;const i=t.map((e=>({file:e.file,aiAnalyze:e.aiAnalyze}))),s=new CustomEvent("message-submit",{detail:{message:e,conversationFiles:i},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(s),s.defaultPrevented||this._send({message:e,conversationFiles:i})}_send(e){const t={type:"user",content:e.message};this._pendingConversationFiles.length&&(t.conversationFiles=this._pendingConversationFiles.map((e=>({conversationFileID:-1,niceName:e.name,mimeType:e.mimeType,aiAnalyze:e.aiAnalyze,previewUrl:e.previewUrl})))),this._speechRecognition&&this._speechRecognition.abort(),this.messages=[...this.messages,t],this._inputValue="",this._suggestedActions=[],this._saveState(),this._error="",this._userHasScrolledUp=!1,this._pendingConversationFiles=[],this._inputEl&&(this._inputEl.style.height="auto"),this.messages=[...this.messages,{type:"assistant",content:""}],this._isStreaming=!0,this._turnFinishedCleanly=!1,this._reconnectAttempts=0,this.updateComplete.then((()=>{if(!this._messagesEl)return;this._messagesEl.querySelectorAll(".agent-turn").forEach((e=>{e.style.minHeight=""}));const e=this._messagesEl.querySelectorAll(".message--user"),t=e[e.length-1],i=this._messagesEl.querySelectorAll(".agent-turn"),s=i[i.length-1];s&&(s.style.minHeight=this._messagesEl.clientHeight+"px"),t&&(this._messagesEl.scrollTop=t.offsetTop-this._messagesEl.offsetTop-24)})),this.send||(this.send=e=>{if(e.confirmation)return i.Http.fetch({url:"/api/system/integration/aws/bedrock/stream/invokeModelForConversationWithState",method:"POST",headers:{Accept:"text/event-stream"},body:{confirmation:e.confirmation,conversationID:this.conversationId}});let t=Promise.resolve([]);return e.conversationFiles.length&&(t=Promise.all(e.conversationFiles.map((({file:e,aiAnalyze:t})=>{const s=new FormData;return s.append("file",e),s.append("type","LIBRARY"),s.append("niceName",e.name),t||s.append("aiAnalyze","false"),i.Http.fetch({url:"/api/system/conversationFile/upload",method:"POST",body:s}).then((e=>e.json())).then((e=>e.data))})))),t.then((t=>{if(t.length)for(let e=this.messages.length-1;e>=0;e--)if("user"===this.messages[e].type){(this.messages[e].conversationFiles||[]).forEach((e=>{e.previewUrl&&URL.revokeObjectURL(e.previewUrl)})),this.messages[e].conversationFiles=t,this.requestUpdate();break}const s={userText:e.message,fileIds:t.map((e=>e.conversationFileID)),mode:this._mode};return e.pageContext&&(s.pageContext=e.pageContext),e.selectionContext&&(s.selectionContext=e.selectionContext),null!=this.conversationId?s.conversationID=this.conversationId:s.createNew=!0,i.Http.fetch({url:"/api/system/integration/aws/bedrock/stream/invokeModelForConversationWithState",method:"POST",headers:{Accept:"text/event-stream"},body:s}).then((e=>(null==this.conversationId&&i.Http.fetch({url:"/api/system/conversation/last"}).then((e=>e.json())).then((e=>{const t=e?.data,i=t?.conversationID;"number"==typeof i&&(this.conversationId=i,this._persistConversationId(),this.dispatchEvent(new CustomEvent("conversation-created",{detail:{conversation:t},bubbles:!0,composed:!0})))})).catch((()=>{})),e)))}))});const s=this._captureContext();this.send({message:e.message,messages:this.messages.slice(0,-1),conversationFiles:e.conversationFiles,pageContext:s.pageContext,selectionContext:s.selectionContext}).then((e=>{e.ok?e.body?(this._reader=e.body.getReader(),this._decoder=new TextDecoder,this._buffer="",this._readStreamChunk()):this._handleStreamError("No response body"):this._handleStreamError("Request failed: "+e.status)})).catch((e=>{"AbortError"!==e.name&&this._handleStreamError(e.message)}))}_handleConfirmationDecision(e){if(this._confirmationInFlight)return;this._confirmationInFlight=!0,this._error="";const t=this._messagesEl?.querySelector(`.confirmation__btn[data-decision="${e}"]`);t?.showLoading(),this._isStreaming=!0,this._turnFinishedCleanly=!1,this._reconnectAttempts=0,this._userHasScrolledUp=!1,this.send({message:"",messages:this.messages,conversationFiles:[],pageContext:"",selectionContext:"",confirmation:e}).then((e=>e.ok?e.body?(this._reader=e.body.getReader(),this._decoder=new TextDecoder,this._buffer="",void this._readStreamChunk()):(this._confirmationInFlight=!1,t?.reset(),void this._handleStreamError("No response body")):(this._confirmationInFlight=!1,t?.reset(),void this._handleStreamError("Request failed: "+e.status)))).catch((e=>{this._confirmationInFlight=!1,t?.reset(),"AbortError"!==e.name&&this._handleStreamError(e.message)}))}_captureContext(){let e="";try{const t={url:window.location.href,title:document.title},i=document.getElementById("kodaris-page");if(i&&i.textContent)try{t.page=JSON.parse(i.textContent)}catch{}e=JSON.stringify(t)}catch{}let t="";try{const e=window.getSelection();e&&(t=e.toString().trim())}catch{}return{pageContext:e,selectionContext:t}}_handleStop(){this._reader&&(this._reader.cancel(),this._reader=null),this._isStreaming=!1}_handleMessagesScroll(e){const t=e.target,i=t.scrollHeight-t.scrollTop-t.clientHeight;this._userHasScrolledUp=i>50}_handleErrorDismiss(){this._error=""}_handleContextWarningDismiss(){this._contextWarning=""}_toggleDrawer(e){this._drawerOpen&&this._drawerView===e?this._drawerOpen=!1:(this._drawerOpen=!0,this._drawerView=e,"history"===e&&this._loadConversations()),this._saveState()}_loadConversations(){this._conversationsLoading=!0,i.Http.fetch({url:"/api/system/conversation/list",method:"POST",body:{page:0,size:50,sortBy:"lastModified",sortDirection:"desc",filterFields:[{name:"active",operation:"IS",value:"true"}]}}).then((e=>e.json())).then((e=>{this._conversations=e?.data?.content||[]})).catch((()=>{this._conversations=[]})).then((()=>{this._conversationsLoading=!1}))}_handleSwitchConversation(e){e!==this.conversationId?(this._handleStop(),this.conversationId=e,this._conversationTitle=this._conversations.find((t=>t.conversationID===e))?.title||"",this._persistConversationId(),this._pendingActions=[],this._inlineConfirm=!0,this._contextWarning="",this._contextLimitReached=!1,this._contextLimitMessage="",this._error="",this._reconnectAttempts=0,this._pendingConversationFiles.forEach((e=>{e.previewUrl&&URL.revokeObjectURL(e.previewUrl)})),this._pendingConversationFiles=[],this._drawerOpen=!1,this._saveState(),this.load&&this.load().then((e=>{this.messages=e||[],this.conversationId&&!this._isStreaming&&this._reconnectStream()})).catch((()=>{}))):this._handleCloseDrawer()}_handleNewConversation(){this._handleStop(),this.conversationId=null,this._conversationTitle="",this._persistConversationId(),this.messages=[],this._pendingActions=[],this._inlineConfirm=!0,this._contextWarning="",this._contextLimitReached=!1,this._contextLimitMessage="",this._error="",this._reconnectAttempts=0,this._pendingConversationFiles.forEach((e=>{e.previewUrl&&URL.revokeObjectURL(e.previewUrl)})),this._pendingConversationFiles=[],this._drawerOpen=!1,this._saveState()}_handleCloseDrawer(){this._drawerOpen=!1,this._saveState()}_openToolDetail(e){const t=this.messages[this.messages.indexOf(e)+1];this._toolDetail={use:e,result:null},"tool_result"===t?.type&&t.data?.toolUseId===e.data?.toolUseId&&(this._toolDetail.result=t),this._toolDetailCopied=null,this._toolDetailInputOpen=!0,this._toolDetailOutputOpen=!0,this._drawerView="toolDetail",this._drawerOpen=!0,this._saveState(),this.updateComplete.then((()=>{this._drawerBodyEl&&(this._drawerBodyEl.scrollTop=0)}))}_handleToggleToolDetailInput(){this._toolDetailInputOpen=!this._toolDetailInputOpen}_handleToggleToolDetailOutput(){this._toolDetailOutputOpen=!this._toolDetailOutputOpen}_formatToolJson(e){if(null==e)return"";const t=String(e),i=t.match(/(<<<[0-9a-f-]+_BEGIN>>>\n?)([\s\S]*?)(\n?<<<[0-9a-f-]+_END>>>)/);if(i&&null!=i.index){const e=i.index+i[1].length,s=e+i[2].length;return t.slice(0,e)+this._reindentJson(i[2])+t.slice(s)}return this._reindentJson(t)}_reindentJson(e){const t=e.trim();if(!t.startsWith("{")&&!t.startsWith("["))return e;try{return JSON.stringify(JSON.parse(t),null,2)}catch{}let i="",s=0,n=!1,o=!1;const r=e=>"\n"+" ".repeat(Math.max(0,e));for(let e=0;e<t.length;e++){const a=t[e];n?(i+=a,o?o=!1:"\\"===a?o=!0:'"'===a&&(n=!1)):'"'===a?(n=!0,i+=a):"{"===a||"["===a?(s++,i+=a+r(s)):"}"===a||"]"===a?(s--,i+=r(s)+a):","===a?i+=a+r(s):":"===a?i+=": ":" "===a||"\n"===a||"\t"===a||"\r"===a||(i+=a)}return i}_handleCopyToolDetailInput(e){e.stopPropagation(),this._copyToolDetail("input",this._formatToolJson(this._toolDetail?.use.data?.toolInput))}_handleCopyToolDetailOutput(e){e.stopPropagation(),this._copyToolDetail("output",this._formatToolJson(this._toolDetail?.result?.data?.toolResultString))}_copyToolDetail(e,t){navigator.clipboard.writeText(t).then((()=>{this._toolDetailCopied=e,setTimeout((()=>{this._toolDetailCopied===e&&(this._toolDetailCopied=null)}),2e3)})).catch((()=>{}))}_handleDrawerResizeMouseDown(e){this._isDrawerResizing=!0,this._drawerResizeStartX=e.clientX,this._drawerResizeStartW=this._drawerWidth,e.preventDefault(),e.stopPropagation(),document.addEventListener("mousemove",this._handleDrawerResizeMouseMove),document.addEventListener("mouseup",this._handleDrawerResizeMouseUp)}_readStreamChunk(){this._reader&&this._reader.read().then((e=>{if(e.done){if(this._turnFinishedCleanly)return;return void this._reconnectStream()}this._buffer=this._buffer+this._decoder.decode(e.value,{stream:!0});const t=this._buffer.split("\n\n");this._buffer=t.pop()||"";for(let e=0;e<t.length;e++){if(!t[e].trim())continue;const i=t[e].split("\n");for(let e=0;e<i.length;e++){if(!i[e].startsWith("data:"))continue;const t=i[e].slice(5).trim();if(!t)continue;let s;try{s=JSON.parse(t)}catch{continue}if(this.dispatchEvent(new CustomEvent("stream-event",{detail:s,bubbles:!0,composed:!0})),"REASONING_PART"===s.type){if(s.message){const e=this._ensureAssistantBubble();e.reasoning||(e.reasoning=""),e.reasoning+=String(s.message),this.requestUpdate()}}else if("RESPONSE_PART"===s.type)s.message&&(this._ensureAssistantBubble().content+=String(s.message),this.requestUpdate());else if("tool_use"===s.type||"tool_result"===s.type)this.messages.push(s),this.requestUpdate();else if("action_decision"===s.type)this._pendingActions=[],this._confirmationHighlighted=-1,this._confirmationInFlight=!1,this.messages.push(s),this.requestUpdate();else if("ERROR"===s.type)this._handleStreamError(String(s.message||"Unknown error"));else if("CONVERSATION_STATE"===s.type)"NORMAL"!==s.data?.mode&&"EDIT"!==s.data?.mode&&"PLAN"!==s.data?.mode||(this._mode=s.data.mode);else if("CONVERSATION_TOKEN_WARNING"===s.type)this._contextWarning=String(s.message||"");else if("CONVERSATION_TITLE"===s.type)s.data?.title&&(this._conversationTitle=s.data.title,this.dispatchEvent(new CustomEvent("conversation-title",{detail:{title:s.data.title},bubbles:!0,composed:!0})));else if("CONVERSATION_LIMIT_REACHED"===s.type)this._contextLimitReached=!0,this._contextLimitMessage=String(s.message||""),this._contextWarning="";else if("ACTION_CONFIRMATION_REQUIRED"===s.type){const e=s.data?.actions;Array.isArray(e)&&e.length&&(this._pendingActions=e,this._confirmationHighlighted=0)}else if("TOKEN_USAGE"===s.type){if(s.data){const e=s.data;this._telemetry=e,1===e.iteration?(this._iterationLog=[e],this._cacheCheckpoints={}):this._iterationLog=[...this._iterationLog,e]}}else if("CACHE_CHECKPOINT"===s.type&&s.data){const e=s.data;this._cacheCheckpoints={...this._cacheCheckpoints,[e.iteration]:e}}s.finished&&(this._turnFinishedCleanly=!0,this._finishStream())}}this._reader&&this._readStreamChunk()})).catch((e=>{"AbortError"!==e.name&&(this._turnFinishedCleanly?this._handleStreamError(e.message):this._reconnectStream())}))}_reconnectStream(){this.conversationId?this._reconnectAttempts>=5?this._handleStreamError("Lost connection to the assistant. Please reload the conversation."):(this._reconnectAttempts=this._reconnectAttempts+1,i.Http.fetch({url:`/api/system/integration/aws/bedrock/stream/attach/${this.conversationId}`,method:"GET",headers:{Accept:"text/event-stream"}}).then((e=>{if(204===e.status)return this._reconnectAttempts=0,this.load&&this.load().then((e=>{this.messages=e,this.requestUpdate()})).catch((()=>{})),void this._finishStream();e.ok&&e.body?(this._reconnectAttempts=0,this._isStreaming=!0,this._reader=e.body.getReader(),this._decoder=new TextDecoder,this._buffer="",this.load?this.load().then((e=>{this.messages=e,this.requestUpdate(),this._readStreamChunk()})).catch((()=>{this._readStreamChunk()})):this._readStreamChunk()):setTimeout((()=>this._reconnectStream()),1e3)})).catch((()=>{setTimeout((()=>this._reconnectStream()),1e3)}))):this._finishStream()}_ensureAssistantBubble(){const e=this.messages[this.messages.length-1];if(e&&"assistant"===e.type)return e;const t={type:"assistant",content:""};return this.messages=[...this.messages,t],t}_finishStream(){if(this._isStreaming=!1,this._reader=null,this._pendingActions.length){const e=this.messages.length-1;e>=0&&"assistant"===this.messages[e].type&&!this.messages[e].content&&!this.messages[e].reasoning&&(this.messages=this.messages.slice(0,-1)),this._inlineConfirm&&this.updateComplete.then((()=>{this._messagesEl?.querySelector(".confirmation")?.scrollIntoView({behavior:"smooth",block:"end"})}))}}_handleStreamError(e){if(this._isStreaming=!1,this._error=e,this._reader&&(this._reader.cancel(),this._reader=null),this.messages.length>0){const e=this.messages[this.messages.length-1];"assistant"!==e.type||e.content||(this.messages=this.messages.slice(0,-1))}}_renderModeSelector(){const e=Xt.find((e=>e.mode===this._mode))||Xt[0];return q`
|
|
207
212
|
<div class="mode">
|
|
208
213
|
${this._modeMenuOpened?q`
|
|
209
214
|
<div class="mode-menu">
|
|
@@ -4245,7 +4250,7 @@ function ge(e,t){return(t,i,s)=>((e,t,i)=>(i.configurable=!0,i.enumerable=!0,Ref
|
|
|
4245
4250
|
transform: scaleX(0.08);
|
|
4246
4251
|
}
|
|
4247
4252
|
}
|
|
4248
|
-
`,Zt([pe({type:String})],Jt.prototype,"logo",void 0),Zt([pe({type:String})],Jt.prototype,"label",void 0),Zt([pe({type:String,attribute:"home-url"})],Jt.prototype,"homeUrl",void 0),Zt([pe({type:String,reflect:!0})],Jt.prototype,"scheme",void 0),Zt([pe({type:Array})],Jt.prototype,"nav",void 0),Zt([pe({type:Boolean,attribute:"nav-icons-displayed",reflect:!0})],Jt.prototype,"navIconsDisplayed",void 0),Zt([pe({type:Boolean,attribute:"nav-expanded"})],Jt.prototype,"navExpanded",void 0),Zt([pe({type:Object})],Jt.prototype,"user",void 0),Zt([pe({type:Boolean})],Jt.prototype,"subbar",void 0),Zt([pe({type:Boolean,attribute:"nav-enabled"})],Jt.prototype,"navEnabled",void 0),Zt([pe({type:String,attribute:"user-type"})],Jt.prototype,"userType",void 0),Zt([pe({type:Array})],Jt.prototype,"breadcrumbs",void 0),Zt([ue()],Jt.prototype,"isDev",void 0),Zt([ue()],Jt.prototype,"navItemsExpanded",void 0),Zt([ue()],Jt.prototype,"navQuery",void 0),Zt([ue()],Jt.prototype,"activeNavItemId",void 0),Zt([ue()],Jt.prototype,"isNavScrolled",void 0),Zt([ue()],Jt.prototype,"isNavOpened",void 0),Zt([ue()],Jt.prototype,"isEditing",void 0),Zt([ue()],Jt.prototype,"isUserMenuOpen",void 0),Zt([ue()],Jt.prototype,"pref",void 0),Zt([ue()],Jt.prototype,"draggedNavItemId",void 0),Zt([ue()],Jt.prototype,"navItemDropTargetId",void 0),Zt([ue()],Jt.prototype,"navItemDropPosition",void 0),Zt([ue()],Jt.prototype,"pendingRequests",void 0),customElements.get("kr-scaffold")||customElements.define("kr-scaffold",Jt);var Gt=function(e,t,i,s){var n,o=arguments.length,r=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(r=(o<3?n(r):o>3?n(t,i,r):n(t,i))||r);return o>3&&r&&Object.defineProperty(t,i,r),r};class ei extends le{constructor(){super(...arguments),this.label="",this.subLabel="",this.items=[],this.activeId="",this.actions=[],this.maxVisibleActions=
|
|
4253
|
+
`,Zt([pe({type:String})],Jt.prototype,"logo",void 0),Zt([pe({type:String})],Jt.prototype,"label",void 0),Zt([pe({type:String,attribute:"home-url"})],Jt.prototype,"homeUrl",void 0),Zt([pe({type:String,reflect:!0})],Jt.prototype,"scheme",void 0),Zt([pe({type:Array})],Jt.prototype,"nav",void 0),Zt([pe({type:Boolean,attribute:"nav-icons-displayed",reflect:!0})],Jt.prototype,"navIconsDisplayed",void 0),Zt([pe({type:Boolean,attribute:"nav-expanded"})],Jt.prototype,"navExpanded",void 0),Zt([pe({type:Object})],Jt.prototype,"user",void 0),Zt([pe({type:Boolean})],Jt.prototype,"subbar",void 0),Zt([pe({type:Boolean,attribute:"nav-enabled"})],Jt.prototype,"navEnabled",void 0),Zt([pe({type:String,attribute:"user-type"})],Jt.prototype,"userType",void 0),Zt([pe({type:Array})],Jt.prototype,"breadcrumbs",void 0),Zt([ue()],Jt.prototype,"isDev",void 0),Zt([ue()],Jt.prototype,"navItemsExpanded",void 0),Zt([ue()],Jt.prototype,"navQuery",void 0),Zt([ue()],Jt.prototype,"activeNavItemId",void 0),Zt([ue()],Jt.prototype,"isNavScrolled",void 0),Zt([ue()],Jt.prototype,"isNavOpened",void 0),Zt([ue()],Jt.prototype,"isEditing",void 0),Zt([ue()],Jt.prototype,"isUserMenuOpen",void 0),Zt([ue()],Jt.prototype,"pref",void 0),Zt([ue()],Jt.prototype,"draggedNavItemId",void 0),Zt([ue()],Jt.prototype,"navItemDropTargetId",void 0),Zt([ue()],Jt.prototype,"navItemDropPosition",void 0),Zt([ue()],Jt.prototype,"pendingRequests",void 0),customElements.get("kr-scaffold")||customElements.define("kr-scaffold",Jt);var Gt=function(e,t,i,s){var n,o=arguments.length,r=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(r=(o<3?n(r):o>3?n(t,i,r):n(t,i))||r);return o>3&&r&&Object.defineProperty(t,i,r),r};class ei extends le{constructor(){super(...arguments),this.label="",this.subLabel="",this.items=[],this.activeId="",this.actions=[],this.maxVisibleActions=5,this.handlePopstate=()=>{this.syncActiveFromUrl()}}connectedCallback(){super.connectedCallback(),requestAnimationFrame((()=>this.syncActiveFromUrl())),window.addEventListener("popstate",this.handlePopstate)}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("popstate",this.handlePopstate)}handleNavItemClick(e,t){const i=new CustomEvent("nav-item-click",{detail:{item:t},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(i),i.defaultPrevented&&e.preventDefault(),this.activeId=t.id}syncActiveFromUrl(){const e=window.location.pathname,t=this.items.find((t=>!!t.url&&(t.url.startsWith("/")?e===t.url:e.endsWith("/"+t.url))));t&&(this.activeId=t.id)}handleActionClick(e,t){this.dispatchEvent(new CustomEvent("action-click",{detail:{action:t.id},bubbles:!0,composed:!0}))}handleMoreSelect(e){this.dispatchEvent(new CustomEvent("action-click",{detail:{action:e.detail.id},bubbles:!0,composed:!0}))}render(){const e=this.actions.length>this.maxVisibleActions;let t=this.actions,i=[];return e&&(t=this.actions.slice(0,this.maxVisibleActions-1),i=this.actions.slice(this.maxVisibleActions-1).map((e=>({id:e.id,label:e.label})))),q`
|
|
4249
4254
|
<nav class="nav">
|
|
4250
4255
|
${this.label?q`
|
|
4251
4256
|
<div class="nav-header">
|
|
@@ -4569,10 +4574,10 @@ function ge(e,t){return(t,i,s)=>((e,t,i)=>(i.configurable=!0,i.enumerable=!0,Ref
|
|
|
4569
4574
|
width: 18px;
|
|
4570
4575
|
height: 18px;
|
|
4571
4576
|
}
|
|
4572
|
-
`,si([pe({type:Array})],ni.prototype,"breadcrumbs",void 0),si([pe({type:Boolean})],ni.prototype,"menu",void 0),customElements.get("kr-subbar")||customElements.define("kr-subbar",ni);
|
|
4577
|
+
`,si([pe({type:Array})],ni.prototype,"breadcrumbs",void 0),si([pe({type:Boolean})],ni.prototype,"menu",void 0),customElements.get("kr-subbar")||customElements.define("kr-subbar",ni);var oi=function(e,t,i,s){var n,o=arguments.length,r=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(r=(o<3?n(r):o>3?n(t,i,r):n(t,i))||r);return o>3&&r&&Object.defineProperty(t,i,r),r};class ri{static configure(e){ri.base=e.base,ri.routes=e.routes,window.addEventListener("click",(e=>{const t=e.composedPath().find((e=>e instanceof HTMLAnchorElement));t&&t.origin===window.location.origin&&t.pathname.startsWith(ri.base)&&"_blank"!==t.target&&(e.preventDefault(),ri.navigate(t.pathname))})),window.addEventListener("popstate",(()=>{ri.handleNavigation()})),Promise.resolve().then((()=>{ri.handleNavigation()}))}static handleNavigation(){const e=ri.matchRoutes();if(!e.routes.length)return;let t=ri.base;e.url&&(t=ri.base+"/"+e.url),window.location.pathname!==t&&window.history.replaceState({},"",t);for(const t of ri.routeCache.keys())e.url.split("/").filter((e=>e)).length<t.split("/").filter((e=>e)).length&&ri.routeCache.delete(t);const i=++ri.navToken;Promise.all(e.routes.map((e=>{const t=ri.routeCache.get(e.url);if(t)return Promise.resolve(t.el);const i=document.createElement(e.route.component);ri.routeCache.set(e.url,{el:i,scrolls:[]});const s=customElements.get(e.route.component);return s&&"function"==typeof s.resolve?Promise.resolve(s.resolve(ri.getParams())).then((t=>(i.routeSnapshot={params:e.params,data:t},i))):Promise.resolve(i)}))).then((t=>{if(i!==ri.navToken)return;const s=Array.from(ri.outletContexts.keys()).sort(((e,t)=>t-e));for(const e of s){const i=ri.outletContexts.get(e);if(!i?.outlet?.el||i.outlet.el===t[e])continue;const s=ri.routeCache.get(i.url);s&&(s.scrolls=ri.getScrollableElements(i.outlet.el).map((e=>e.scrollTop))),i.outlet.deactivate(),i.element=null,i.url=""}t.forEach(((t,i)=>{let s=ri.outletContexts.get(i);if(s||(s={outlet:null,element:null,url:""},ri.outletContexts.set(i,s)),s.element=t,s.url=e.routes[i].url,s.outlet&&s.outlet.el!==t){s.outlet.activate(t);const e=ri.routeCache.get(s.url);e?.scrolls.length&&setTimeout((()=>{const t=ri.getScrollableElements(e.el);e.scrolls.forEach(((e,i)=>{t[i]&&(t[i].scrollTop=e)}))}),0)}}))}))}static registerOutlet(e,t){let i=ri.outletContexts.get(e);if(i||(i={outlet:null,element:null,url:""},ri.outletContexts.set(e,i)),i.outlet=t,i.element&&t.el!==i.element){t.activate(i.element);const e=ri.routeCache.get(i.url);e?.scrolls.length&&setTimeout((()=>{const t=ri.getScrollableElements(e.el);e.scrolls.forEach(((e,i)=>{t[i]&&(t[i].scrollTop=e)}))}),0)}}static unregisterOutlet(e,t){const i=ri.outletContexts.get(e);i&&i.outlet===t&&(i.outlet=null)}static navigate(e){let t=e;e.startsWith("/")||(t=ri.base+"/"+e),window.history.pushState({},"",t),window.dispatchEvent(new PopStateEvent("popstate"))}static getParams(){const e=ri.matchRoutes(),t={};for(const i of e.routes)for(const e in i.params)t[e]=decodeURIComponent(i.params[e]);return t}static getScrollableElements(e){const t=[],i=[e];for(;i.length;){const e=i.pop();if(!e)break;const s=getComputedStyle(e);"auto"!==s.overflow&&"scroll"!==s.overflow&&"auto"!==s.overflowY&&"scroll"!==s.overflowY||t.push(e);const n=[];e.shadowRoot&&n.push(...Array.from(e.shadowRoot.children)),n.push(...Array.from(e.children));for(let e=n.length-1;e>=0;e--)i.push(n[e])}return t}static matchRoutes(e=ri.routes,t){if(!t){let e=window.location.pathname;e.startsWith(ri.base)&&(e=e.slice(ri.base.length)),t=e.split("/").filter((e=>e))}for(const i of e){const e=i.path.split("/").filter((e=>e));if(0===e.length&&0===t.length)return{routes:[{route:i,params:{},url:""}],url:""};if(0===e.length)continue;if(t.length<e.length)continue;const s={};let n=!0;for(let i=0;i<e.length;i++)if(e[i].startsWith(":"))s[e[i].slice(1)]=t[i];else if(e[i]!==t[i]){n=!1;break}if(!n)continue;const o=t.slice(e.length),r=t.slice(0,e.length).join("/"),a=[{route:i,params:s,url:r}];if(o.length>0){if(!i.children)continue;const e=ri.matchRoutes(i.children,o);if(e.routes.length>0){for(const t of e.routes)t.url=r+"/"+t.url;return a.push(...e.routes),{routes:a,url:r+"/"+e.url}}}if(i.children&&0===o.length&&i.default){const e=ri.matchRoutes(i.children,[i.default]);if(e.routes.length>0){for(const t of e.routes)t.url=r+"/"+t.url;return a.push(...e.routes),{routes:a,url:r+"/"+e.url}}}return{routes:a,url:r}}return{routes:[],url:""}}}ri.base="",ri.routes=[],ri.routeCache=new Map,ri.outletContexts=new Map,ri.navToken=0,e.RouterOutlet=class extends le{constructor(){super(...arguments),this.level=-1,this.el=null}connectedCallback(){super.connectedCallback();let e=0,t=this;for(;t;)t instanceof ShadowRoot?t=t.host:(t instanceof HTMLElement&&"KR-ROUTER-OUTLET"===t.tagName&&t!==this&&e++,t=t instanceof HTMLElement?t.parentNode:null);this.level=e,ri.registerOutlet(this.level,this)}disconnectedCallback(){super.disconnectedCallback(),ri.unregisterOutlet(this.level,this)}activate(e){this.el=e}deactivate(){this.el=null}render(){return this.el?q`${this.el}`:q``}},e.RouterOutlet.styles=l`
|
|
4573
4578
|
:host {
|
|
4574
4579
|
display: block;
|
|
4575
4580
|
height: 100%;
|
|
4576
4581
|
}
|
|
4577
|
-
`,
|
|
4582
|
+
`,oi([ue()],e.RouterOutlet.prototype,"el",void 0),e.RouterOutlet=oi([(e=>(t,i)=>{void 0!==i?i.addInitializer((()=>{customElements.define(e,t)})):customElements.define(e,t)})("kr-router-outlet")],e.RouterOutlet),e.Chatbot=Kt,e.Router=ri,e.Scaffold=Jt,e.ScreenDetail=ii,e.ScreenNav=ei,e.Subbar=ni})),function(e){Object.keys(e).forEach((function(t){t.startsWith("KR")&&"function"==typeof e[t]&&(e[t.slice(2)]=e[t],delete e[t])}))}(krApp);
|
|
4578
4583
|
//# sourceMappingURL=krubble-app.umd.min.js.map
|