@runtypelabs/persona 3.21.2 → 3.21.3
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/index.cjs +12 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +21 -21
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/theme-editor.cjs +1 -6
- package/dist/theme-editor.js +1 -6
- package/package.json +1 -1
- package/src/components/composer-parts.test.ts +34 -0
- package/src/components/composer-parts.ts +9 -6
package/dist/index.global.js
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
`);let o=this.lexer.state.top;this.lexer.state.top=!0;let a=this.lexer.blockTokens(n);return this.lexer.state.top=o,{type:"blockquote",raw:t[0],tokens:a,text:n}}}list(r){let t=this.rules.block.list.exec(r);if(t){let n=t[1].trim(),o=n.length>1,a={type:"list",raw:"",ordered:o,start:o?+n.slice(0,-1):"",loose:!1,items:[]};n=o?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=o?n:"[*+-]");let s=new RegExp(`^( {0,3}${n})((?:[ ][^\\n]*)?(?:\\n|$))`),i="",d="",l=!1;for(;r;){let u=!1;if(!(t=s.exec(r))||this.rules.block.hr.test(r))break;i=t[0],r=r.substring(i.length);let p=t[2].split(`
|
|
8
8
|
`,1)[0].replace(/^\t+/,T=>" ".repeat(3*T.length)),f=r.split(`
|
|
9
9
|
`,1)[0],m=0;this.options.pedantic?(m=2,d=p.trimStart()):(m=t[2].search(/[^ ]/),m=m>4?1:m,d=p.slice(m),m+=t[1].length);let C=!1;if(!p&&/^ *$/.test(f)&&(i+=f+`
|
|
10
|
-
`,r=r.substring(f.length+1),u=!0),!u){let T=new RegExp(`^ {0,${Math.min(3,m-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),S=new RegExp(`^ {0,${Math.min(3,m-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),E=new RegExp(`^ {0,${Math.min(3,m-1)}}(?:\`\`\`|~~~)`),
|
|
11
|
-
`,1)[0];if(f=b,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),E.test(f)||
|
|
12
|
-
`+f.slice(m);else{if(C||p.search(/[^ ]/)>=4||E.test(p)||
|
|
10
|
+
`,r=r.substring(f.length+1),u=!0),!u){let T=new RegExp(`^ {0,${Math.min(3,m-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),S=new RegExp(`^ {0,${Math.min(3,m-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),E=new RegExp(`^ {0,${Math.min(3,m-1)}}(?:\`\`\`|~~~)`),w=new RegExp(`^ {0,${Math.min(3,m-1)}}#`);for(;r;){let b=r.split(`
|
|
11
|
+
`,1)[0];if(f=b,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),E.test(f)||w.test(f)||T.test(f)||S.test(r))break;if(f.search(/[^ ]/)>=m||!f.trim())d+=`
|
|
12
|
+
`+f.slice(m);else{if(C||p.search(/[^ ]/)>=4||E.test(p)||w.test(p)||S.test(p))break;d+=`
|
|
13
13
|
`+f}!C&&!f.trim()&&(C=!0),i+=b+`
|
|
14
|
-
`,r=r.substring(b.length+1),p=f.slice(m)}}a.loose||(l?a.loose=!0:/\n *\n *$/.test(i)&&(l=!0));let
|
|
14
|
+
`,r=r.substring(b.length+1),p=f.slice(m)}}a.loose||(l?a.loose=!0:/\n *\n *$/.test(i)&&(l=!0));let A=null,k;this.options.gfm&&(A=/^\[[ xX]\] /.exec(d),A&&(k=A[0]!=="[ ] ",d=d.replace(/^\[[ xX]\] +/,""))),a.items.push({type:"list_item",raw:i,task:!!A,checked:k,loose:!1,text:d,tokens:[]}),a.raw+=i}a.items[a.items.length-1].raw=i.trimEnd(),a.items[a.items.length-1].text=d.trimEnd(),a.raw=a.raw.trimEnd();for(let u=0;u<a.items.length;u++)if(this.lexer.state.top=!1,a.items[u].tokens=this.lexer.blockTokens(a.items[u].text,[]),!a.loose){let p=a.items[u].tokens.filter(m=>m.type==="space"),f=p.length>0&&p.some(m=>/\n.*\n/.test(m.raw));a.loose=f}if(a.loose)for(let u=0;u<a.items.length;u++)a.items[u].loose=!0;return a}}html(r){let t=this.rules.block.html.exec(r);if(t)return{type:"html",block:!0,raw:t[0],pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:t[0]}}def(r){let t=this.rules.block.def.exec(r);if(t){let n=t[1].toLowerCase().replace(/\s+/g," "),o=t[2]?t[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",a=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:n,raw:t[0],href:o,title:a}}}table(r){let t=this.rules.block.table.exec(r);if(!t||!/[:|]/.test(t[2]))return;let n=Xm(t[1]),o=t[2].replace(/^\||\| *$/g,"").split("|"),a=t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split(`
|
|
15
15
|
`):[],s={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===o.length){for(let i of o)/^ *-+: *$/.test(i)?s.align.push("right"):/^ *:-+: *$/.test(i)?s.align.push("center"):/^ *:-+ *$/.test(i)?s.align.push("left"):s.align.push(null);for(let i of n)s.header.push({text:i,tokens:this.lexer.inline(i)});for(let i of a)s.rows.push(Xm(i,s.header.length).map(d=>({text:d,tokens:this.lexer.inline(d)})));return s}}lheading(r){let t=this.rules.block.lheading.exec(r);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(r){let t=this.rules.block.paragraph.exec(r);if(t){let n=t[1].charAt(t[1].length-1)===`
|
|
16
|
-
`?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:n,tokens:this.lexer.inline(n)}}}text(r){let t=this.rules.block.text.exec(r);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(r){let t=this.rules.inline.escape.exec(r);if(t)return{type:"escape",raw:t[0],text:un(t[1])}}tag(r){let t=this.rules.inline.tag.exec(r);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(r){let t=this.rules.inline.link.exec(r);if(t){let n=t[2].trim();if(!this.options.pedantic&&/^</.test(n)){if(!/>$/.test(n))return;let s=si(n.slice(0,-1),"\\");if((n.length-s.length)%2===0)return}else{let s=Zx(t[2],"()");if(s>-1){let d=(t[0].indexOf("!")===0?5:4)+t[1].length+s;t[2]=t[2].substring(0,s),t[0]=t[0].substring(0,d).trim(),t[3]=""}}let o=t[2],a="";if(this.options.pedantic){let s=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(o);s&&(o=s[1],a=s[3])}else a=t[3]?t[3].slice(1,-1):"";return o=o.trim(),/^</.test(o)&&(this.options.pedantic&&!/>$/.test(n)?o=o.slice(1):o=o.slice(1,-1)),Jm(t,{href:o&&o.replace(this.rules.inline.anyPunctuation,"$1"),title:a&&a.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer)}}reflink(r,t){let n;if((n=this.rules.inline.reflink.exec(r))||(n=this.rules.inline.nolink.exec(r))){let o=(n[2]||n[1]).replace(/\s+/g," "),a=t[o.toLowerCase()];if(!a){let s=n[0].charAt(0);return{type:"text",raw:s,text:s}}return Jm(n,a,n[0],this.lexer)}}emStrong(r,t,n=""){let o=this.rules.inline.emStrongLDelim.exec(r);if(!o||o[3]&&n.match(/[\p{L}\p{N}]/u))return;if(!(o[1]||o[2]||"")||!n||this.rules.inline.punctuation.exec(n)){let s=[...o[0]].length-1,i,d,l=s,u=0,p=o[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(p.lastIndex=0,t=t.slice(-1*r.length+s);(o=p.exec(t))!=null;){if(i=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!i)continue;if(d=[...i].length,o[3]||o[4]){l+=d;continue}else if((o[5]||o[6])&&s%3&&!((s+d)%3)){u+=d;continue}if(l-=d,l>0)continue;d=Math.min(d,d+l+u);let f=[...o[0]][0].length,m=r.slice(0,s+o.index+f+d);if(Math.min(s,d)%2){let
|
|
16
|
+
`?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:n,tokens:this.lexer.inline(n)}}}text(r){let t=this.rules.block.text.exec(r);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(r){let t=this.rules.inline.escape.exec(r);if(t)return{type:"escape",raw:t[0],text:un(t[1])}}tag(r){let t=this.rules.inline.tag.exec(r);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(r){let t=this.rules.inline.link.exec(r);if(t){let n=t[2].trim();if(!this.options.pedantic&&/^</.test(n)){if(!/>$/.test(n))return;let s=si(n.slice(0,-1),"\\");if((n.length-s.length)%2===0)return}else{let s=Zx(t[2],"()");if(s>-1){let d=(t[0].indexOf("!")===0?5:4)+t[1].length+s;t[2]=t[2].substring(0,s),t[0]=t[0].substring(0,d).trim(),t[3]=""}}let o=t[2],a="";if(this.options.pedantic){let s=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(o);s&&(o=s[1],a=s[3])}else a=t[3]?t[3].slice(1,-1):"";return o=o.trim(),/^</.test(o)&&(this.options.pedantic&&!/>$/.test(n)?o=o.slice(1):o=o.slice(1,-1)),Jm(t,{href:o&&o.replace(this.rules.inline.anyPunctuation,"$1"),title:a&&a.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer)}}reflink(r,t){let n;if((n=this.rules.inline.reflink.exec(r))||(n=this.rules.inline.nolink.exec(r))){let o=(n[2]||n[1]).replace(/\s+/g," "),a=t[o.toLowerCase()];if(!a){let s=n[0].charAt(0);return{type:"text",raw:s,text:s}}return Jm(n,a,n[0],this.lexer)}}emStrong(r,t,n=""){let o=this.rules.inline.emStrongLDelim.exec(r);if(!o||o[3]&&n.match(/[\p{L}\p{N}]/u))return;if(!(o[1]||o[2]||"")||!n||this.rules.inline.punctuation.exec(n)){let s=[...o[0]].length-1,i,d,l=s,u=0,p=o[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(p.lastIndex=0,t=t.slice(-1*r.length+s);(o=p.exec(t))!=null;){if(i=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!i)continue;if(d=[...i].length,o[3]||o[4]){l+=d;continue}else if((o[5]||o[6])&&s%3&&!((s+d)%3)){u+=d;continue}if(l-=d,l>0)continue;d=Math.min(d,d+l+u);let f=[...o[0]][0].length,m=r.slice(0,s+o.index+f+d);if(Math.min(s,d)%2){let A=m.slice(1,-1);return{type:"em",raw:m,text:A,tokens:this.lexer.inlineTokens(A)}}let C=m.slice(2,-2);return{type:"strong",raw:m,text:C,tokens:this.lexer.inlineTokens(C)}}}}codespan(r){let t=this.rules.inline.code.exec(r);if(t){let n=t[2].replace(/\n/g," "),o=/[^ ]/.test(n),a=/^ /.test(n)&&/ $/.test(n);return o&&a&&(n=n.substring(1,n.length-1)),n=un(n,!0),{type:"codespan",raw:t[0],text:n}}}br(r){let t=this.rules.inline.br.exec(r);if(t)return{type:"br",raw:t[0]}}del(r){let t=this.rules.inline.del.exec(r);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(r){let t=this.rules.inline.autolink.exec(r);if(t){let n,o;return t[2]==="@"?(n=un(t[1]),o="mailto:"+n):(n=un(t[1]),o=n),{type:"link",raw:t[0],text:n,href:o,tokens:[{type:"text",raw:n,text:n}]}}}url(r){var n,o;let t;if(t=this.rules.inline.url.exec(r)){let a,s;if(t[2]==="@")a=un(t[0]),s="mailto:"+a;else{let i;do i=t[0],t[0]=(o=(n=this.rules.inline._backpedal.exec(t[0]))==null?void 0:n[0])!=null?o:"";while(i!==t[0]);a=un(t[0]),t[1]==="www."?s="http://"+t[0]:s=t[0]}return{type:"link",raw:t[0],text:a,href:s,tokens:[{type:"text",raw:a,text:a}]}}}inlineText(r){let t=this.rules.inline.text.exec(r);if(t){let n;return this.lexer.state.inRawBlock?n=t[0]:n=un(t[0]),{type:"text",raw:t[0],text:n}}}},ty=/^(?: *(?:\n|$))+/,ry=/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,ny=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,ss=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,oy=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,eg=/(?:[*+-]|\d{1,9}[.)])/,tg=Yt(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,eg).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(),Fl=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,ay=/^[^\n]+/,Nl=/(?!\s*\])(?:\\.|[^\[\]\\])+/,sy=Yt(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label",Nl).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),iy=Yt(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,eg).getRegex(),di="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",_l=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,ly=Yt("^ {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",_l).replace("tag",di).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),rg=Yt(Fl).replace("hr",ss).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",di).getRegex(),dy=Yt(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",rg).getRegex(),$l={blockquote:dy,code:ry,def:sy,fences:ny,heading:oy,hr:ss,html:ly,lheading:tg,list:iy,newline:ty,paragraph:rg,table:ns,text:ay},Km=Yt("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",ss).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",di).getRegex(),cy={...$l,table:Km,paragraph:Yt(Fl).replace("hr",ss).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Km).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",di).getRegex()},py={...$l,html:Yt(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",_l).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:ns,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Yt(Fl).replace("hr",ss).replace("heading",` *#{1,6} *[^
|
|
17
17
|
]`).replace("lheading",tg).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},ng=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,uy=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,og=/^( {2,}|\\)\n(?!\s*$)/,fy=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,is="\\p{P}\\p{S}",my=Yt(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,is).getRegex(),gy=/\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g,hy=Yt(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,is).getRegex(),xy=Yt("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,is).getRegex(),yy=Yt("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,is).getRegex(),by=Yt(/\\([punct])/,"gu").replace(/punct/g,is).getRegex(),Cy=Yt(/^<(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(),wy=Yt(_l).replace("(?:-->|$)","-->").getRegex(),vy=Yt("^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",wy).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),li=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,Ay=Yt(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",li).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),ag=Yt(/^!?\[(label)\]\[(ref)\]/).replace("label",li).replace("ref",Nl).getRegex(),sg=Yt(/^!?\[(ref)\](?:\[\])?/).replace("ref",Nl).getRegex(),Sy=Yt("reflink|nolink(?!\\()","g").replace("reflink",ag).replace("nolink",sg).getRegex(),Ul={_backpedal:ns,anyPunctuation:by,autolink:Cy,blockSkip:gy,br:og,code:uy,del:ns,emStrongLDelim:hy,emStrongRDelimAst:xy,emStrongRDelimUnd:yy,escape:ng,link:Ay,nolink:sg,punctuation:my,reflink:ag,reflinkSearch:Sy,tag:vy,text:fy,url:ns},Ty={...Ul,link:Yt(/^!?\[(label)\]\((.*?)\)/).replace("label",li).getRegex(),reflink:Yt(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",li).getRegex()},Wl={...Ul,escape:Yt(ng).replace("])","~|])").getRegex(),url:Yt(/^((?: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.!#$%&'*+\/=?_`{\|}~-]+@)))/},ky={...Wl,br:Yt(og).replace("{2,}","*").getRegex(),text:Yt(Wl.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},ii={normal:$l,gfm:cy,pedantic:py},rs={normal:Ul,gfm:Wl,breaks:ky,pedantic:Ty},eo=class e{constructor(r){tr(this,"tokens");tr(this,"options");tr(this,"state");tr(this,"tokenizer");tr(this,"inlineQueue");this.tokens=[],this.tokens.links=Object.create(null),this.options=r||Go,this.options.tokenizer=this.options.tokenizer||new xa,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={block:ii.normal,inline:rs.normal};this.options.pedantic?(t.block=ii.pedantic,t.inline=rs.pedantic):this.options.gfm&&(t.block=ii.gfm,this.options.breaks?t.inline=rs.breaks:t.inline=rs.gfm),this.tokenizer.rules=t}static get rules(){return{block:ii,inline:rs}}static lex(r,t){return new e(t).lex(r)}static lexInline(r,t){return new e(t).inlineTokens(r)}lex(r){r=r.replace(/\r\n|\r/g,`
|
|
18
18
|
`),this.blockTokens(r,this.tokens);for(let t=0;t<this.inlineQueue.length;t++){let n=this.inlineQueue[t];this.inlineTokens(n.src,n.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(r,t=[]){this.options.pedantic?r=r.replace(/\t/g," ").replace(/^ +$/gm,""):r=r.replace(/^( *)(\t+)/gm,(i,d,l)=>d+" ".repeat(l.length));let n,o,a,s;for(;r;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(i=>(n=i.call({lexer:this},r,t))?(r=r.substring(n.raw.length),t.push(n),!0):!1))){if(n=this.tokenizer.space(r)){r=r.substring(n.raw.length),n.raw.length===1&&t.length>0?t[t.length-1].raw+=`
|
|
19
19
|
`:t.push(n);continue}if(n=this.tokenizer.code(r)){r=r.substring(n.raw.length),o=t[t.length-1],o&&(o.type==="paragraph"||o.type==="text")?(o.raw+=`
|
|
@@ -42,16 +42,16 @@ ${r}</blockquote>
|
|
|
42
42
|
`}tablerow(r){return`<tr>
|
|
43
43
|
${r}</tr>
|
|
44
44
|
`}tablecell(r,t){let n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+r+`</${n}>
|
|
45
|
-
`}strong(r){return`<strong>${r}</strong>`}em(r){return`<em>${r}</em>`}codespan(r){return`<code>${r}</code>`}br(){return"<br>"}del(r){return`<del>${r}</del>`}link(r,t,n){let o=Gm(r);if(o===null)return n;r=o;let a='<a href="'+r+'"';return t&&(a+=' title="'+t+'"'),a+=">"+n+"</a>",a}image(r,t,n){let o=Gm(r);if(o===null)return n;r=o;let a=`<img src="${r}" alt="${n}"`;return t&&(a+=` title="${t}"`),a+=">",a}text(r){return r}},os=class{strong(r){return r}em(r){return r}codespan(r){return r}del(r){return r}html(r){return r}text(r){return r}link(r,t,n){return""+n}image(r,t,n){return""+n}br(){return""}},to=class e{constructor(r){tr(this,"options");tr(this,"renderer");tr(this,"textRenderer");this.options=r||Go,this.options.renderer=this.options.renderer||new ya,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new os}static parse(r,t){return new e(t).parse(r)}static parseInline(r,t){return new e(t).parseInline(r)}parse(r,t=!0){let n="";for(let o=0;o<r.length;o++){let a=r[o];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[a.type]){let s=a,i=this.options.extensions.renderers[s.type].call({parser:this},s);if(i!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(s.type)){n+=i||"";continue}}switch(a.type){case"space":continue;case"hr":{n+=this.renderer.hr();continue}case"heading":{let s=a;n+=this.renderer.heading(this.parseInline(s.tokens),s.depth,Yx(this.parseInline(s.tokens,this.textRenderer)));continue}case"code":{let s=a;n+=this.renderer.code(s.text,s.lang,!!s.escaped);continue}case"table":{let s=a,i="",d="";for(let u=0;u<s.header.length;u++)d+=this.renderer.tablecell(this.parseInline(s.header[u].tokens),{header:!0,align:s.align[u]});i+=this.renderer.tablerow(d);let l="";for(let u=0;u<s.rows.length;u++){let p=s.rows[u];d="";for(let f=0;f<p.length;f++)d+=this.renderer.tablecell(this.parseInline(p[f].tokens),{header:!1,align:s.align[f]});l+=this.renderer.tablerow(d)}n+=this.renderer.table(i,l);continue}case"blockquote":{let s=a,i=this.parse(s.tokens);n+=this.renderer.blockquote(i);continue}case"list":{let s=a,i=s.ordered,d=s.start,l=s.loose,u="";for(let p=0;p<s.items.length;p++){let f=s.items[p],m=f.checked,C=f.task,
|
|
45
|
+
`}strong(r){return`<strong>${r}</strong>`}em(r){return`<em>${r}</em>`}codespan(r){return`<code>${r}</code>`}br(){return"<br>"}del(r){return`<del>${r}</del>`}link(r,t,n){let o=Gm(r);if(o===null)return n;r=o;let a='<a href="'+r+'"';return t&&(a+=' title="'+t+'"'),a+=">"+n+"</a>",a}image(r,t,n){let o=Gm(r);if(o===null)return n;r=o;let a=`<img src="${r}" alt="${n}"`;return t&&(a+=` title="${t}"`),a+=">",a}text(r){return r}},os=class{strong(r){return r}em(r){return r}codespan(r){return r}del(r){return r}html(r){return r}text(r){return r}link(r,t,n){return""+n}image(r,t,n){return""+n}br(){return""}},to=class e{constructor(r){tr(this,"options");tr(this,"renderer");tr(this,"textRenderer");this.options=r||Go,this.options.renderer=this.options.renderer||new ya,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new os}static parse(r,t){return new e(t).parse(r)}static parseInline(r,t){return new e(t).parseInline(r)}parse(r,t=!0){let n="";for(let o=0;o<r.length;o++){let a=r[o];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[a.type]){let s=a,i=this.options.extensions.renderers[s.type].call({parser:this},s);if(i!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(s.type)){n+=i||"";continue}}switch(a.type){case"space":continue;case"hr":{n+=this.renderer.hr();continue}case"heading":{let s=a;n+=this.renderer.heading(this.parseInline(s.tokens),s.depth,Yx(this.parseInline(s.tokens,this.textRenderer)));continue}case"code":{let s=a;n+=this.renderer.code(s.text,s.lang,!!s.escaped);continue}case"table":{let s=a,i="",d="";for(let u=0;u<s.header.length;u++)d+=this.renderer.tablecell(this.parseInline(s.header[u].tokens),{header:!0,align:s.align[u]});i+=this.renderer.tablerow(d);let l="";for(let u=0;u<s.rows.length;u++){let p=s.rows[u];d="";for(let f=0;f<p.length;f++)d+=this.renderer.tablecell(this.parseInline(p[f].tokens),{header:!1,align:s.align[f]});l+=this.renderer.tablerow(d)}n+=this.renderer.table(i,l);continue}case"blockquote":{let s=a,i=this.parse(s.tokens);n+=this.renderer.blockquote(i);continue}case"list":{let s=a,i=s.ordered,d=s.start,l=s.loose,u="";for(let p=0;p<s.items.length;p++){let f=s.items[p],m=f.checked,C=f.task,A="";if(f.task){let k=this.renderer.checkbox(!!m);l?f.tokens.length>0&&f.tokens[0].type==="paragraph"?(f.tokens[0].text=k+" "+f.tokens[0].text,f.tokens[0].tokens&&f.tokens[0].tokens.length>0&&f.tokens[0].tokens[0].type==="text"&&(f.tokens[0].tokens[0].text=k+" "+f.tokens[0].tokens[0].text)):f.tokens.unshift({type:"text",text:k+" "}):A+=k+" "}A+=this.parse(f.tokens,l),u+=this.renderer.listitem(A,C,!!m)}n+=this.renderer.list(u,i,d);continue}case"html":{let s=a;n+=this.renderer.html(s.text,s.block);continue}case"paragraph":{let s=a;n+=this.renderer.paragraph(this.parseInline(s.tokens));continue}case"text":{let s=a,i=s.tokens?this.parseInline(s.tokens):s.text;for(;o+1<r.length&&r[o+1].type==="text";)s=r[++o],i+=`
|
|
46
46
|
`+(s.tokens?this.parseInline(s.tokens):s.text);n+=t?this.renderer.paragraph(i):i;continue}default:{let s='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw new Error(s)}}}return n}parseInline(r,t){t=t||this.renderer;let n="";for(let o=0;o<r.length;o++){let a=r[o];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[a.type]){let s=this.options.extensions.renderers[a.type].call({parser:this},a);if(s!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(a.type)){n+=s||"";continue}}switch(a.type){case"escape":{let s=a;n+=t.text(s.text);break}case"html":{let s=a;n+=t.html(s.text);break}case"link":{let s=a;n+=t.link(s.href,s.title,this.parseInline(s.tokens,t));break}case"image":{let s=a;n+=t.image(s.href,s.title,s.text);break}case"strong":{let s=a;n+=t.strong(this.parseInline(s.tokens,t));break}case"em":{let s=a;n+=t.em(this.parseInline(s.tokens,t));break}case"codespan":{let s=a;n+=t.codespan(s.text);break}case"br":{n+=t.br();break}case"del":{let s=a;n+=t.del(this.parseInline(s.tokens,t));break}case"text":{let s=a;n+=t.text(s.text);break}default:{let s='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw new Error(s)}}}return n}},zo=class{constructor(r){tr(this,"options");this.options=r||Go}preprocess(r){return r}postprocess(r){return r}processAllTokens(r){return r}};tr(zo,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"]));var jo,Dl,ig,as=class{constructor(...r){Vm(this,jo);tr(this,"defaults",Ol());tr(this,"options",this.setOptions);tr(this,"parse",ai(this,jo,Dl).call(this,eo.lex,to.parse));tr(this,"parseInline",ai(this,jo,Dl).call(this,eo.lexInline,to.parseInline));tr(this,"Parser",to);tr(this,"Renderer",ya);tr(this,"TextRenderer",os);tr(this,"Lexer",eo);tr(this,"Tokenizer",xa);tr(this,"Hooks",zo);this.use(...r)}walkTokens(r,t){var o,a;let n=[];for(let s of r)switch(n=n.concat(t.call(this,s)),s.type){case"table":{let i=s;for(let d of i.header)n=n.concat(this.walkTokens(d.tokens,t));for(let d of i.rows)for(let l of d)n=n.concat(this.walkTokens(l.tokens,t));break}case"list":{let i=s;n=n.concat(this.walkTokens(i.items,t));break}default:{let i=s;(a=(o=this.defaults.extensions)==null?void 0:o.childTokens)!=null&&a[i.type]?this.defaults.extensions.childTokens[i.type].forEach(d=>{let l=i[d].flat(1/0);n=n.concat(this.walkTokens(l,t))}):i.tokens&&(n=n.concat(this.walkTokens(i.tokens,t)))}}return n}use(...r){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return r.forEach(n=>{let o={...n};if(o.async=this.defaults.async||o.async||!1,n.extensions&&(n.extensions.forEach(a=>{if(!a.name)throw new Error("extension name required");if("renderer"in a){let s=t.renderers[a.name];s?t.renderers[a.name]=function(...i){let d=a.renderer.apply(this,i);return d===!1&&(d=s.apply(this,i)),d}:t.renderers[a.name]=a.renderer}if("tokenizer"in a){if(!a.level||a.level!=="block"&&a.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let s=t[a.level];s?s.unshift(a.tokenizer):t[a.level]=[a.tokenizer],a.start&&(a.level==="block"?t.startBlock?t.startBlock.push(a.start):t.startBlock=[a.start]:a.level==="inline"&&(t.startInline?t.startInline.push(a.start):t.startInline=[a.start]))}"childTokens"in a&&a.childTokens&&(t.childTokens[a.name]=a.childTokens)}),o.extensions=t),n.renderer){let a=this.defaults.renderer||new ya(this.defaults);for(let s in n.renderer){if(!(s in a))throw new Error(`renderer '${s}' does not exist`);if(s==="options")continue;let i=s,d=n.renderer[i],l=a[i];a[i]=(...u)=>{let p=d.apply(a,u);return p===!1&&(p=l.apply(a,u)),p||""}}o.renderer=a}if(n.tokenizer){let a=this.defaults.tokenizer||new xa(this.defaults);for(let s in n.tokenizer){if(!(s in a))throw new Error(`tokenizer '${s}' does not exist`);if(["options","rules","lexer"].includes(s))continue;let i=s,d=n.tokenizer[i],l=a[i];a[i]=(...u)=>{let p=d.apply(a,u);return p===!1&&(p=l.apply(a,u)),p}}o.tokenizer=a}if(n.hooks){let a=this.defaults.hooks||new zo;for(let s in n.hooks){if(!(s in a))throw new Error(`hook '${s}' does not exist`);if(s==="options")continue;let i=s,d=n.hooks[i],l=a[i];zo.passThroughHooks.has(s)?a[i]=u=>{if(this.defaults.async)return Promise.resolve(d.call(a,u)).then(f=>l.call(a,f));let p=d.call(a,u);return l.call(a,p)}:a[i]=(...u)=>{let p=d.apply(a,u);return p===!1&&(p=l.apply(a,u)),p}}o.hooks=a}if(n.walkTokens){let a=this.defaults.walkTokens,s=n.walkTokens;o.walkTokens=function(i){let d=[];return d.push(s.call(this,i)),a&&(d=d.concat(a.call(this,i))),d}}this.defaults={...this.defaults,...o}}),this}setOptions(r){return this.defaults={...this.defaults,...r},this}lexer(r,t){return eo.lex(r,t!=null?t:this.defaults)}parser(r,t){return to.parse(r,t!=null?t:this.defaults)}};jo=new WeakSet,Dl=function(r,t){return(n,o)=>{let a={...o},s={...this.defaults,...a};this.defaults.async===!0&&a.async===!1&&(s.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),s.async=!0);let i=ai(this,jo,ig).call(this,!!s.silent,!!s.async);if(typeof n=="undefined"||n===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(s.hooks&&(s.hooks.options=s),s.async)return Promise.resolve(s.hooks?s.hooks.preprocess(n):n).then(d=>r(d,s)).then(d=>s.hooks?s.hooks.processAllTokens(d):d).then(d=>s.walkTokens?Promise.all(this.walkTokens(d,s.walkTokens)).then(()=>d):d).then(d=>t(d,s)).then(d=>s.hooks?s.hooks.postprocess(d):d).catch(i);try{s.hooks&&(n=s.hooks.preprocess(n));let d=r(n,s);s.hooks&&(d=s.hooks.processAllTokens(d)),s.walkTokens&&this.walkTokens(d,s.walkTokens);let l=t(d,s);return s.hooks&&(l=s.hooks.postprocess(l)),l}catch(d){return i(d)}}},ig=function(r,t){return n=>{if(n.message+=`
|
|
47
|
-
Please report this to https://github.com/markedjs/marked.`,r){let o="<p>An error occurred:</p><pre>"+un(n.message+"",!0)+"</pre>";return t?Promise.resolve(o):o}if(t)return Promise.reject(n);throw n}};var Vo=new as;function Kt(e,r){return Vo.parse(e,r)}Kt.options=Kt.setOptions=function(e){return Vo.setOptions(e),Kt.defaults=Vo.defaults,Ym(Kt.defaults),Kt};Kt.getDefaults=Ol;Kt.defaults=Go;Kt.use=function(...e){return Vo.use(...e),Kt.defaults=Vo.defaults,Ym(Kt.defaults),Kt};Kt.walkTokens=function(e,r){return Vo.walkTokens(e,r)};Kt.parseInline=Vo.parseInline;Kt.Parser=to;Kt.parser=to.parse;Kt.Renderer=ya;Kt.TextRenderer=os;Kt.Lexer=eo;Kt.lexer=eo.lex;Kt.Tokenizer=xa;Kt.Hooks=zo;Kt.parse=Kt;var nw=Kt.options,ow=Kt.setOptions,aw=Kt.use,sw=Kt.walkTokens,iw=Kt.parseInline;var lw=to.parse,dw=eo.lex;var Ey=e=>{if(e)return e},ls=e=>{var o,a;let r=e==null?void 0:e.markedOptions,t=new as({gfm:(o=r==null?void 0:r.gfm)!=null?o:!0,breaks:(a=r==null?void 0:r.breaks)!=null?a:!0,pedantic:r==null?void 0:r.pedantic,silent:r==null?void 0:r.silent}),n=Ey(e==null?void 0:e.renderer);return n&&t.use({renderer:n}),s=>t.parse(s)},Xo=e=>e?ls({markedOptions:e.options,renderer:e.renderer}):ls(),My=ls(),ql=e=>My(e),Jo=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),dg=e=>e.replace(/"/g,""").replace(/</g,"<").replace(/>/g,">"),lg=e=>`%%FORM_PLACEHOLDER_${e}%%`,cg=(e,r)=>{let t=e;return t=t.replace(/<Directive>([\s\S]*?)<\/Directive>/gi,(n,o)=>{try{let a=JSON.parse(o.trim());if(a&&typeof a=="object"&&a.component==="form"&&a.type){let s=lg(r.length);return r.push({token:s,type:String(a.type)}),s}}catch{return n}return n}),t=t.replace(/<Form\s+type="([^"]+)"\s*\/>/gi,(n,o)=>{let a=lg(r.length);return r.push({token:a,type:o}),a}),t},pg=e=>{let r=Xo(e);return t=>{let n=[],o=cg(t,n),a=r(o);return n.forEach(({token:s,type:i})=>{let d=new RegExp(s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),u=`<div class="persona-form-directive" data-tv-form="${dg(i)}"></div>`;a=a.replace(d,u)}),a}},ug=e=>{let r=[],t=cg(e,r),n=ql(t);return r.forEach(({token:o,type:a})=>{let s=new RegExp(o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),d=`<div class="persona-form-directive" data-tv-form="${dg(a)}"></div>`;n=n.replace(s,d)}),n};var{entries:wg,setPrototypeOf:fg,isFrozen:Ly,getPrototypeOf:Py,getOwnPropertyDescriptor:Iy}=Object,{freeze:jr,seal:wn,create:ui}=Object,{apply:Kl,construct:Yl}=typeof Reflect!="undefined"&&Reflect;jr||(jr=function(r){return r});wn||(wn=function(r){return r});Kl||(Kl=function(r,t){for(var n=arguments.length,o=new Array(n>2?n-2:0),a=2;a<n;a++)o[a-2]=arguments[a];return r.apply(t,o)});Yl||(Yl=function(r){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];return new r(...n)});var ci=Gr(Array.prototype.forEach),Ry=Gr(Array.prototype.lastIndexOf),mg=Gr(Array.prototype.pop),ds=Gr(Array.prototype.push),Hy=Gr(Array.prototype.splice),fi=Gr(String.prototype.toLowerCase),zl=Gr(String.prototype.toString),Vl=Gr(String.prototype.match),cs=Gr(String.prototype.replace),By=Gr(String.prototype.indexOf),Wy=Gr(String.prototype.trim),fn=Gr(Object.prototype.hasOwnProperty),Vr=Gr(RegExp.prototype.test),ps=Dy(TypeError);function Gr(e){return function(r){r instanceof RegExp&&(r.lastIndex=0);for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];return Kl(e,r,n)}}function Dy(e){return function(){for(var r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];return Yl(e,t)}}function Tt(e,r){let t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:fi;fg&&fg(e,null);let n=r.length;for(;n--;){let o=r[n];if(typeof o=="string"){let a=t(o);a!==o&&(Ly(r)||(r[n]=a),o=a)}e[o]=!0}return e}function Oy(e){for(let r=0;r<e.length;r++)fn(e,r)||(e[r]=null);return e}function Un(e){let r=ui(null);for(let[t,n]of wg(e))fn(e,t)&&(Array.isArray(n)?r[t]=Oy(n):n&&typeof n=="object"&&n.constructor===Object?r[t]=Un(n):r[t]=n);return r}function us(e,r){for(;e!==null;){let n=Iy(e,r);if(n){if(n.get)return Gr(n.get);if(typeof n.value=="function")return Gr(n.value)}e=Py(e)}function t(){return null}return t}var gg=jr(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),jl=jr(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),Gl=jr(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),Fy=jr(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),Xl=jr(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),Ny=jr(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),hg=jr(["#text"]),xg=jr(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),Jl=jr(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),yg=jr(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),pi=jr(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),_y=wn(/\{\{[\w\W]*|[\w\W]*\}\}/gm),$y=wn(/<%[\w\W]*|[\w\W]*%>/gm),Uy=wn(/\$\{[\w\W]*/gm),qy=wn(/^data-[\-\w.\u00B7-\uFFFF]+$/),zy=wn(/^aria-[\-\w]+$/),vg=wn(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Vy=wn(/^(?:\w+script|data):/i),jy=wn(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Ag=wn(/^html$/i),Gy=wn(/^[a-z][.\w]*(-[.\w]+)+$/i),bg=Object.freeze({__proto__:null,ARIA_ATTR:zy,ATTR_WHITESPACE:jy,CUSTOM_ELEMENT:Gy,DATA_ATTR:qy,DOCTYPE_NAME:Ag,ERB_EXPR:$y,IS_ALLOWED_URI:vg,IS_SCRIPT_OR_DATA:Vy,MUSTACHE_EXPR:_y,TMPLIT_EXPR:Uy}),fs={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,progressingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},Xy=function(){return typeof window=="undefined"?null:window},Jy=function(r,t){if(typeof r!="object"||typeof r.createPolicy!="function")return null;let n=null,o="data-tt-policy-suffix";t&&t.hasAttribute(o)&&(n=t.getAttribute(o));let a="dompurify"+(n?"#"+n:"");try{return r.createPolicy(a,{createHTML(s){return s},createScriptURL(s){return s}})}catch{return console.warn("TrustedTypes policy "+a+" could not be created."),null}},Cg=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function Sg(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Xy(),r=Pe=>Sg(Pe);if(r.version="3.3.3",r.removed=[],!e||!e.document||e.document.nodeType!==fs.document||!e.Element)return r.isSupported=!1,r;let{document:t}=e,n=t,o=n.currentScript,{DocumentFragment:a,HTMLTemplateElement:s,Node:i,Element:d,NodeFilter:l,NamedNodeMap:u=e.NamedNodeMap||e.MozNamedAttrMap,HTMLFormElement:p,DOMParser:f,trustedTypes:m}=e,C=d.prototype,w=us(C,"cloneNode"),k=us(C,"remove"),T=us(C,"nextSibling"),S=us(C,"childNodes"),E=us(C,"parentNode");if(typeof s=="function"){let Pe=t.createElement("template");Pe.content&&Pe.content.ownerDocument&&(t=Pe.content.ownerDocument)}let v,b="",{implementation:y,createNodeIterator:M,createDocumentFragment:H,getElementsByTagName:B}=t,{importNode:R}=n,W=Cg();r.isSupported=typeof wg=="function"&&typeof E=="function"&&y&&y.createHTMLDocument!==void 0;let{MUSTACHE_EXPR:V,ERB_EXPR:ne,TMPLIT_EXPR:ue,DATA_ATTR:We,ARIA_ATTR:Ke,IS_SCRIPT_OR_DATA:xe,ATTR_WHITESPACE:me,CUSTOM_ELEMENT:Re}=bg,{IS_ALLOWED_URI:Ge}=bg,Y=null,Ee=Tt({},[...gg,...jl,...Gl,...Xl,...hg]),G=null,ce=Tt({},[...xg,...Jl,...yg,...pi]),de=Object.seal(ui(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),pe=null,He=null,Ye=Object.seal(ui(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),J=!0,ie=!0,Ue=!1,K=!0,j=!1,Ce=!0,De=!1,oe=!1,Se=!1,ge=!1,Rt=!1,Me=!1,ae=!0,ur=!1,Ut="user-content-",Qt=!0,Or=!1,vr={},Oe=null,q=Tt({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]),Te=null,_e=Tt({},["audio","video","img","source","image","track"]),Ne=null,qe=Tt({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),st="http://www.w3.org/1998/Math/MathML",nt="http://www.w3.org/2000/svg",pt="http://www.w3.org/1999/xhtml",Nt=pt,F=!1,ye=null,be=Tt({},[st,nt,pt],zl),it=Tt({},["mi","mo","mn","ms","mtext"]),Xe=Tt({},["annotation-xml"]),Wt=Tt({},["title","style","font","a","script"]),ar=null,Pt=["application/xhtml+xml","text/html"],kt="text/html",rt=null,lt=null,rr=t.createElement("form"),gn=function(P){return P instanceof RegExp||P instanceof Function},Ir=function(){let P=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!(lt&<===P)){if((!P||typeof P!="object")&&(P={}),P=Un(P),ar=Pt.indexOf(P.PARSER_MEDIA_TYPE)===-1?kt:P.PARSER_MEDIA_TYPE,rt=ar==="application/xhtml+xml"?zl:fi,Y=fn(P,"ALLOWED_TAGS")?Tt({},P.ALLOWED_TAGS,rt):Ee,G=fn(P,"ALLOWED_ATTR")?Tt({},P.ALLOWED_ATTR,rt):ce,ye=fn(P,"ALLOWED_NAMESPACES")?Tt({},P.ALLOWED_NAMESPACES,zl):be,Ne=fn(P,"ADD_URI_SAFE_ATTR")?Tt(Un(qe),P.ADD_URI_SAFE_ATTR,rt):qe,Te=fn(P,"ADD_DATA_URI_TAGS")?Tt(Un(_e),P.ADD_DATA_URI_TAGS,rt):_e,Oe=fn(P,"FORBID_CONTENTS")?Tt({},P.FORBID_CONTENTS,rt):q,pe=fn(P,"FORBID_TAGS")?Tt({},P.FORBID_TAGS,rt):Un({}),He=fn(P,"FORBID_ATTR")?Tt({},P.FORBID_ATTR,rt):Un({}),vr=fn(P,"USE_PROFILES")?P.USE_PROFILES:!1,J=P.ALLOW_ARIA_ATTR!==!1,ie=P.ALLOW_DATA_ATTR!==!1,Ue=P.ALLOW_UNKNOWN_PROTOCOLS||!1,K=P.ALLOW_SELF_CLOSE_IN_ATTR!==!1,j=P.SAFE_FOR_TEMPLATES||!1,Ce=P.SAFE_FOR_XML!==!1,De=P.WHOLE_DOCUMENT||!1,ge=P.RETURN_DOM||!1,Rt=P.RETURN_DOM_FRAGMENT||!1,Me=P.RETURN_TRUSTED_TYPE||!1,Se=P.FORCE_BODY||!1,ae=P.SANITIZE_DOM!==!1,ur=P.SANITIZE_NAMED_PROPS||!1,Qt=P.KEEP_CONTENT!==!1,Or=P.IN_PLACE||!1,Ge=P.ALLOWED_URI_REGEXP||vg,Nt=P.NAMESPACE||pt,it=P.MATHML_TEXT_INTEGRATION_POINTS||it,Xe=P.HTML_INTEGRATION_POINTS||Xe,de=P.CUSTOM_ELEMENT_HANDLING||{},P.CUSTOM_ELEMENT_HANDLING&&gn(P.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(de.tagNameCheck=P.CUSTOM_ELEMENT_HANDLING.tagNameCheck),P.CUSTOM_ELEMENT_HANDLING&&gn(P.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(de.attributeNameCheck=P.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),P.CUSTOM_ELEMENT_HANDLING&&typeof P.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(de.allowCustomizedBuiltInElements=P.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),j&&(ie=!1),Rt&&(ge=!0),vr&&(Y=Tt({},hg),G=ui(null),vr.html===!0&&(Tt(Y,gg),Tt(G,xg)),vr.svg===!0&&(Tt(Y,jl),Tt(G,Jl),Tt(G,pi)),vr.svgFilters===!0&&(Tt(Y,Gl),Tt(G,Jl),Tt(G,pi)),vr.mathMl===!0&&(Tt(Y,Xl),Tt(G,yg),Tt(G,pi))),fn(P,"ADD_TAGS")||(Ye.tagCheck=null),fn(P,"ADD_ATTR")||(Ye.attributeCheck=null),P.ADD_TAGS&&(typeof P.ADD_TAGS=="function"?Ye.tagCheck=P.ADD_TAGS:(Y===Ee&&(Y=Un(Y)),Tt(Y,P.ADD_TAGS,rt))),P.ADD_ATTR&&(typeof P.ADD_ATTR=="function"?Ye.attributeCheck=P.ADD_ATTR:(G===ce&&(G=Un(G)),Tt(G,P.ADD_ATTR,rt))),P.ADD_URI_SAFE_ATTR&&Tt(Ne,P.ADD_URI_SAFE_ATTR,rt),P.FORBID_CONTENTS&&(Oe===q&&(Oe=Un(Oe)),Tt(Oe,P.FORBID_CONTENTS,rt)),P.ADD_FORBID_CONTENTS&&(Oe===q&&(Oe=Un(Oe)),Tt(Oe,P.ADD_FORBID_CONTENTS,rt)),Qt&&(Y["#text"]=!0),De&&Tt(Y,["html","head","body"]),Y.table&&(Tt(Y,["tbody"]),delete pe.tbody),P.TRUSTED_TYPES_POLICY){if(typeof P.TRUSTED_TYPES_POLICY.createHTML!="function")throw ps('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof P.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw ps('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');v=P.TRUSTED_TYPES_POLICY,b=v.createHTML("")}else v===void 0&&(v=Jy(m,o)),v!==null&&typeof b=="string"&&(b=v.createHTML(""));jr&&jr(P),lt=P}},Tn=Tt({},[...jl,...Gl,...Fy]),Et=Tt({},[...Xl,...Ny]),hn=function(P){let Z=E(P);(!Z||!Z.tagName)&&(Z={namespaceURI:Nt,tagName:"template"});let se=fi(P.tagName),Mt=fi(Z.tagName);return ye[P.namespaceURI]?P.namespaceURI===nt?Z.namespaceURI===pt?se==="svg":Z.namespaceURI===st?se==="svg"&&(Mt==="annotation-xml"||it[Mt]):!!Tn[se]:P.namespaceURI===st?Z.namespaceURI===pt?se==="math":Z.namespaceURI===nt?se==="math"&&Xe[Mt]:!!Et[se]:P.namespaceURI===pt?Z.namespaceURI===nt&&!Xe[Mt]||Z.namespaceURI===st&&!it[Mt]?!1:!Et[se]&&(Wt[se]||!Tn[se]):!!(ar==="application/xhtml+xml"&&ye[P.namespaceURI]):!1},pr=function(P){ds(r.removed,{element:P});try{E(P).removeChild(P)}catch{k(P)}},Ar=function(P,Z){try{ds(r.removed,{attribute:Z.getAttributeNode(P),from:Z})}catch{ds(r.removed,{attribute:null,from:Z})}if(Z.removeAttribute(P),P==="is")if(ge||Rt)try{pr(Z)}catch{}else try{Z.setAttribute(P,"")}catch{}},Kr=function(P){let Z=null,se=null;if(Se)P="<remove></remove>"+P;else{let Ht=Vl(P,/^[\r\n\t ]+/);se=Ht&&Ht[0]}ar==="application/xhtml+xml"&&Nt===pt&&(P='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+P+"</body></html>");let Mt=v?v.createHTML(P):P;if(Nt===pt)try{Z=new f().parseFromString(Mt,ar)}catch{}if(!Z||!Z.documentElement){Z=y.createDocument(Nt,"template",null);try{Z.documentElement.innerHTML=F?b:Mt}catch{}}let zt=Z.body||Z.documentElement;return P&&se&&zt.insertBefore(t.createTextNode(se),zt.childNodes[0]||null),Nt===pt?B.call(Z,De?"html":"body")[0]:De?Z.documentElement:zt},bt=function(P){return M.call(P.ownerDocument||P,P,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},kn=function(P){return P instanceof p&&(typeof P.nodeName!="string"||typeof P.textContent!="string"||typeof P.removeChild!="function"||!(P.attributes instanceof u)||typeof P.removeAttribute!="function"||typeof P.setAttribute!="function"||typeof P.namespaceURI!="string"||typeof P.insertBefore!="function"||typeof P.hasChildNodes!="function")},nn=function(P){return typeof i=="function"&&P instanceof i};function Sr(Pe,P,Z){ci(Pe,se=>{se.call(r,P,Z,lt)})}let Tr=function(P){let Z=null;if(Sr(W.beforeSanitizeElements,P,null),kn(P))return pr(P),!0;let se=rt(P.nodeName);if(Sr(W.uponSanitizeElement,P,{tagName:se,allowedTags:Y}),Ce&&P.hasChildNodes()&&!nn(P.firstElementChild)&&Vr(/<[/\w!]/g,P.innerHTML)&&Vr(/<[/\w!]/g,P.textContent)||P.nodeType===fs.progressingInstruction||Ce&&P.nodeType===fs.comment&&Vr(/<[/\w]/g,P.data))return pr(P),!0;if(!(Ye.tagCheck instanceof Function&&Ye.tagCheck(se))&&(!Y[se]||pe[se])){if(!pe[se]&&En(se)&&(de.tagNameCheck instanceof RegExp&&Vr(de.tagNameCheck,se)||de.tagNameCheck instanceof Function&&de.tagNameCheck(se)))return!1;if(Qt&&!Oe[se]){let Mt=E(P)||P.parentNode,zt=S(P)||P.childNodes;if(zt&&Mt){let Ht=zt.length;for(let sr=Ht-1;sr>=0;--sr){let xr=w(zt[sr],!0);xr.__removalCount=(P.__removalCount||0)+1,Mt.insertBefore(xr,T(P))}}}return pr(P),!0}return P instanceof d&&!hn(P)||(se==="noscript"||se==="noembed"||se==="noframes")&&Vr(/<\/no(script|embed|frames)/i,P.innerHTML)?(pr(P),!0):(j&&P.nodeType===fs.text&&(Z=P.textContent,ci([V,ne,ue],Mt=>{Z=cs(Z,Mt," ")}),P.textContent!==Z&&(ds(r.removed,{element:P.cloneNode()}),P.textContent=Z)),Sr(W.afterSanitizeElements,P,null),!1)},Vn=function(P,Z,se){if(He[Z]||ae&&(Z==="id"||Z==="name")&&(se in t||se in rr))return!1;if(!(ie&&!He[Z]&&Vr(We,Z))){if(!(J&&Vr(Ke,Z))){if(!(Ye.attributeCheck instanceof Function&&Ye.attributeCheck(Z,P))){if(!G[Z]||He[Z]){if(!(En(P)&&(de.tagNameCheck instanceof RegExp&&Vr(de.tagNameCheck,P)||de.tagNameCheck instanceof Function&&de.tagNameCheck(P))&&(de.attributeNameCheck instanceof RegExp&&Vr(de.attributeNameCheck,Z)||de.attributeNameCheck instanceof Function&&de.attributeNameCheck(Z,P))||Z==="is"&&de.allowCustomizedBuiltInElements&&(de.tagNameCheck instanceof RegExp&&Vr(de.tagNameCheck,se)||de.tagNameCheck instanceof Function&&de.tagNameCheck(se))))return!1}else if(!Ne[Z]){if(!Vr(Ge,cs(se,me,""))){if(!((Z==="src"||Z==="xlink:href"||Z==="href")&&P!=="script"&&By(se,"data:")===0&&Te[P])){if(!(Ue&&!Vr(xe,cs(se,me,"")))){if(se)return!1}}}}}}}return!0},En=function(P){return P!=="annotation-xml"&&Vl(P,Re)},xn=function(P){Sr(W.beforeSanitizeAttributes,P,null);let{attributes:Z}=P;if(!Z||kn(P))return;let se={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:G,forceKeepAttr:void 0},Mt=Z.length;for(;Mt--;){let zt=Z[Mt],{name:Ht,namespaceURI:sr,value:xr}=zt,Fr=rt(Ht),kr=xr,ot=Ht==="value"?kr:Wy(kr);if(se.attrName=Fr,se.attrValue=ot,se.keepAttr=!0,se.forceKeepAttr=void 0,Sr(W.uponSanitizeAttribute,P,se),ot=se.attrValue,ur&&(Fr==="id"||Fr==="name")&&(Ar(Ht,P),ot=Ut+ot),Ce&&Vr(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,ot)){Ar(Ht,P);continue}if(Fr==="attributename"&&Vl(ot,"href")){Ar(Ht,P);continue}if(se.forceKeepAttr)continue;if(!se.keepAttr){Ar(Ht,P);continue}if(!K&&Vr(/\/>/i,ot)){Ar(Ht,P);continue}j&&ci([V,ne,ue],Nr=>{ot=cs(ot,Nr," ")});let wr=rt(P.nodeName);if(!Vn(wr,Fr,ot)){Ar(Ht,P);continue}if(v&&typeof m=="object"&&typeof m.getAttributeType=="function"&&!sr)switch(m.getAttributeType(wr,Fr)){case"TrustedHTML":{ot=v.createHTML(ot);break}case"TrustedScriptURL":{ot=v.createScriptURL(ot);break}}if(ot!==kr)try{sr?P.setAttributeNS(sr,Ht,ot):P.setAttribute(Ht,ot),kn(P)?pr(P):mg(r.removed)}catch{Ar(Ht,P)}}Sr(W.afterSanitizeAttributes,P,null)},vt=function Pe(P){let Z=null,se=bt(P);for(Sr(W.beforeSanitizeShadowDOM,P,null);Z=se.nextNode();)Sr(W.uponSanitizeShadowNode,Z,null),Tr(Z),xn(Z),Z.content instanceof a&&Pe(Z.content);Sr(W.afterSanitizeShadowDOM,P,null)};return r.sanitize=function(Pe){let P=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},Z=null,se=null,Mt=null,zt=null;if(F=!Pe,F&&(Pe="<!-->"),typeof Pe!="string"&&!nn(Pe))if(typeof Pe.toString=="function"){if(Pe=Pe.toString(),typeof Pe!="string")throw ps("dirty is not a string, aborting")}else throw ps("toString is not a function");if(!r.isSupported)return Pe;if(oe||Ir(P),r.removed=[],typeof Pe=="string"&&(Or=!1),Or){if(Pe.nodeName){let xr=rt(Pe.nodeName);if(!Y[xr]||pe[xr])throw ps("root node is forbidden and cannot be sanitized in-place")}}else if(Pe instanceof i)Z=Kr("<!---->"),se=Z.ownerDocument.importNode(Pe,!0),se.nodeType===fs.element&&se.nodeName==="BODY"||se.nodeName==="HTML"?Z=se:Z.appendChild(se);else{if(!ge&&!j&&!De&&Pe.indexOf("<")===-1)return v&&Me?v.createHTML(Pe):Pe;if(Z=Kr(Pe),!Z)return ge?null:Me?b:""}Z&&Se&&pr(Z.firstChild);let Ht=bt(Or?Pe:Z);for(;Mt=Ht.nextNode();)Tr(Mt),xn(Mt),Mt.content instanceof a&&vt(Mt.content);if(Or)return Pe;if(ge){if(Rt)for(zt=H.call(Z.ownerDocument);Z.firstChild;)zt.appendChild(Z.firstChild);else zt=Z;return(G.shadowroot||G.shadowrootmode)&&(zt=R.call(n,zt,!0)),zt}let sr=De?Z.outerHTML:Z.innerHTML;return De&&Y["!doctype"]&&Z.ownerDocument&&Z.ownerDocument.doctype&&Z.ownerDocument.doctype.name&&Vr(Ag,Z.ownerDocument.doctype.name)&&(sr="<!DOCTYPE "+Z.ownerDocument.doctype.name+`>
|
|
48
|
-
`+sr),j&&ci([V,ne,ue],xr=>{sr=cs(sr,xr," ")}),
|
|
47
|
+
Please report this to https://github.com/markedjs/marked.`,r){let o="<p>An error occurred:</p><pre>"+un(n.message+"",!0)+"</pre>";return t?Promise.resolve(o):o}if(t)return Promise.reject(n);throw n}};var Vo=new as;function Kt(e,r){return Vo.parse(e,r)}Kt.options=Kt.setOptions=function(e){return Vo.setOptions(e),Kt.defaults=Vo.defaults,Ym(Kt.defaults),Kt};Kt.getDefaults=Ol;Kt.defaults=Go;Kt.use=function(...e){return Vo.use(...e),Kt.defaults=Vo.defaults,Ym(Kt.defaults),Kt};Kt.walkTokens=function(e,r){return Vo.walkTokens(e,r)};Kt.parseInline=Vo.parseInline;Kt.Parser=to;Kt.parser=to.parse;Kt.Renderer=ya;Kt.TextRenderer=os;Kt.Lexer=eo;Kt.lexer=eo.lex;Kt.Tokenizer=xa;Kt.Hooks=zo;Kt.parse=Kt;var nw=Kt.options,ow=Kt.setOptions,aw=Kt.use,sw=Kt.walkTokens,iw=Kt.parseInline;var lw=to.parse,dw=eo.lex;var Ey=e=>{if(e)return e},ls=e=>{var o,a;let r=e==null?void 0:e.markedOptions,t=new as({gfm:(o=r==null?void 0:r.gfm)!=null?o:!0,breaks:(a=r==null?void 0:r.breaks)!=null?a:!0,pedantic:r==null?void 0:r.pedantic,silent:r==null?void 0:r.silent}),n=Ey(e==null?void 0:e.renderer);return n&&t.use({renderer:n}),s=>t.parse(s)},Xo=e=>e?ls({markedOptions:e.options,renderer:e.renderer}):ls(),My=ls(),ql=e=>My(e),Jo=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),dg=e=>e.replace(/"/g,""").replace(/</g,"<").replace(/>/g,">"),lg=e=>`%%FORM_PLACEHOLDER_${e}%%`,cg=(e,r)=>{let t=e;return t=t.replace(/<Directive>([\s\S]*?)<\/Directive>/gi,(n,o)=>{try{let a=JSON.parse(o.trim());if(a&&typeof a=="object"&&a.component==="form"&&a.type){let s=lg(r.length);return r.push({token:s,type:String(a.type)}),s}}catch{return n}return n}),t=t.replace(/<Form\s+type="([^"]+)"\s*\/>/gi,(n,o)=>{let a=lg(r.length);return r.push({token:a,type:o}),a}),t},pg=e=>{let r=Xo(e);return t=>{let n=[],o=cg(t,n),a=r(o);return n.forEach(({token:s,type:i})=>{let d=new RegExp(s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),u=`<div class="persona-form-directive" data-tv-form="${dg(i)}"></div>`;a=a.replace(d,u)}),a}},ug=e=>{let r=[],t=cg(e,r),n=ql(t);return r.forEach(({token:o,type:a})=>{let s=new RegExp(o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),d=`<div class="persona-form-directive" data-tv-form="${dg(a)}"></div>`;n=n.replace(s,d)}),n};var{entries:wg,setPrototypeOf:fg,isFrozen:Ly,getPrototypeOf:Py,getOwnPropertyDescriptor:Iy}=Object,{freeze:jr,seal:wn,create:ui}=Object,{apply:Kl,construct:Yl}=typeof Reflect!="undefined"&&Reflect;jr||(jr=function(r){return r});wn||(wn=function(r){return r});Kl||(Kl=function(r,t){for(var n=arguments.length,o=new Array(n>2?n-2:0),a=2;a<n;a++)o[a-2]=arguments[a];return r.apply(t,o)});Yl||(Yl=function(r){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];return new r(...n)});var ci=Gr(Array.prototype.forEach),Ry=Gr(Array.prototype.lastIndexOf),mg=Gr(Array.prototype.pop),ds=Gr(Array.prototype.push),Hy=Gr(Array.prototype.splice),fi=Gr(String.prototype.toLowerCase),zl=Gr(String.prototype.toString),Vl=Gr(String.prototype.match),cs=Gr(String.prototype.replace),By=Gr(String.prototype.indexOf),Wy=Gr(String.prototype.trim),fn=Gr(Object.prototype.hasOwnProperty),Vr=Gr(RegExp.prototype.test),ps=Dy(TypeError);function Gr(e){return function(r){r instanceof RegExp&&(r.lastIndex=0);for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];return Kl(e,r,n)}}function Dy(e){return function(){for(var r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];return Yl(e,t)}}function Tt(e,r){let t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:fi;fg&&fg(e,null);let n=r.length;for(;n--;){let o=r[n];if(typeof o=="string"){let a=t(o);a!==o&&(Ly(r)||(r[n]=a),o=a)}e[o]=!0}return e}function Oy(e){for(let r=0;r<e.length;r++)fn(e,r)||(e[r]=null);return e}function Un(e){let r=ui(null);for(let[t,n]of wg(e))fn(e,t)&&(Array.isArray(n)?r[t]=Oy(n):n&&typeof n=="object"&&n.constructor===Object?r[t]=Un(n):r[t]=n);return r}function us(e,r){for(;e!==null;){let n=Iy(e,r);if(n){if(n.get)return Gr(n.get);if(typeof n.value=="function")return Gr(n.value)}e=Py(e)}function t(){return null}return t}var gg=jr(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),jl=jr(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),Gl=jr(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),Fy=jr(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),Xl=jr(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),Ny=jr(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),hg=jr(["#text"]),xg=jr(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),Jl=jr(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),yg=jr(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),pi=jr(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),_y=wn(/\{\{[\w\W]*|[\w\W]*\}\}/gm),$y=wn(/<%[\w\W]*|[\w\W]*%>/gm),Uy=wn(/\$\{[\w\W]*/gm),qy=wn(/^data-[\-\w.\u00B7-\uFFFF]+$/),zy=wn(/^aria-[\-\w]+$/),vg=wn(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Vy=wn(/^(?:\w+script|data):/i),jy=wn(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Ag=wn(/^html$/i),Gy=wn(/^[a-z][.\w]*(-[.\w]+)+$/i),bg=Object.freeze({__proto__:null,ARIA_ATTR:zy,ATTR_WHITESPACE:jy,CUSTOM_ELEMENT:Gy,DATA_ATTR:qy,DOCTYPE_NAME:Ag,ERB_EXPR:$y,IS_ALLOWED_URI:vg,IS_SCRIPT_OR_DATA:Vy,MUSTACHE_EXPR:_y,TMPLIT_EXPR:Uy}),fs={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,progressingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},Xy=function(){return typeof window=="undefined"?null:window},Jy=function(r,t){if(typeof r!="object"||typeof r.createPolicy!="function")return null;let n=null,o="data-tt-policy-suffix";t&&t.hasAttribute(o)&&(n=t.getAttribute(o));let a="dompurify"+(n?"#"+n:"");try{return r.createPolicy(a,{createHTML(s){return s},createScriptURL(s){return s}})}catch{return console.warn("TrustedTypes policy "+a+" could not be created."),null}},Cg=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function Sg(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Xy(),r=Pe=>Sg(Pe);if(r.version="3.3.3",r.removed=[],!e||!e.document||e.document.nodeType!==fs.document||!e.Element)return r.isSupported=!1,r;let{document:t}=e,n=t,o=n.currentScript,{DocumentFragment:a,HTMLTemplateElement:s,Node:i,Element:d,NodeFilter:l,NamedNodeMap:u=e.NamedNodeMap||e.MozNamedAttrMap,HTMLFormElement:p,DOMParser:f,trustedTypes:m}=e,C=d.prototype,A=us(C,"cloneNode"),k=us(C,"remove"),T=us(C,"nextSibling"),S=us(C,"childNodes"),E=us(C,"parentNode");if(typeof s=="function"){let Pe=t.createElement("template");Pe.content&&Pe.content.ownerDocument&&(t=Pe.content.ownerDocument)}let w,b="",{implementation:y,createNodeIterator:M,createDocumentFragment:H,getElementsByTagName:B}=t,{importNode:R}=n,W=Cg();r.isSupported=typeof wg=="function"&&typeof E=="function"&&y&&y.createHTMLDocument!==void 0;let{MUSTACHE_EXPR:V,ERB_EXPR:ne,TMPLIT_EXPR:ue,DATA_ATTR:Be,ARIA_ATTR:Ke,IS_SCRIPT_OR_DATA:ye,ATTR_WHITESPACE:me,CUSTOM_ELEMENT:We}=bg,{IS_ALLOWED_URI:Xe}=bg,Y=null,Ee=Tt({},[...gg,...jl,...Gl,...Xl,...hg]),G=null,ce=Tt({},[...xg,...Jl,...yg,...pi]),de=Object.seal(ui(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),pe=null,Re=null,Ye=Object.seal(ui(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),J=!0,ie=!0,Ue=!1,K=!0,j=!1,Ce=!0,De=!1,oe=!1,Se=!1,ge=!1,Rt=!1,Me=!1,ae=!0,ur=!1,Ut="user-content-",Qt=!0,Or=!1,vr={},Oe=null,q=Tt({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]),Te=null,_e=Tt({},["audio","video","img","source","image","track"]),Ne=null,qe=Tt({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),st="http://www.w3.org/1998/Math/MathML",nt="http://www.w3.org/2000/svg",pt="http://www.w3.org/1999/xhtml",Nt=pt,F=!1,xe=null,be=Tt({},[st,nt,pt],zl),it=Tt({},["mi","mo","mn","ms","mtext"]),Ge=Tt({},["annotation-xml"]),Wt=Tt({},["title","style","font","a","script"]),ar=null,Pt=["application/xhtml+xml","text/html"],kt="text/html",rt=null,lt=null,rr=t.createElement("form"),gn=function(P){return P instanceof RegExp||P instanceof Function},Ir=function(){let P=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!(lt&<===P)){if((!P||typeof P!="object")&&(P={}),P=Un(P),ar=Pt.indexOf(P.PARSER_MEDIA_TYPE)===-1?kt:P.PARSER_MEDIA_TYPE,rt=ar==="application/xhtml+xml"?zl:fi,Y=fn(P,"ALLOWED_TAGS")?Tt({},P.ALLOWED_TAGS,rt):Ee,G=fn(P,"ALLOWED_ATTR")?Tt({},P.ALLOWED_ATTR,rt):ce,xe=fn(P,"ALLOWED_NAMESPACES")?Tt({},P.ALLOWED_NAMESPACES,zl):be,Ne=fn(P,"ADD_URI_SAFE_ATTR")?Tt(Un(qe),P.ADD_URI_SAFE_ATTR,rt):qe,Te=fn(P,"ADD_DATA_URI_TAGS")?Tt(Un(_e),P.ADD_DATA_URI_TAGS,rt):_e,Oe=fn(P,"FORBID_CONTENTS")?Tt({},P.FORBID_CONTENTS,rt):q,pe=fn(P,"FORBID_TAGS")?Tt({},P.FORBID_TAGS,rt):Un({}),Re=fn(P,"FORBID_ATTR")?Tt({},P.FORBID_ATTR,rt):Un({}),vr=fn(P,"USE_PROFILES")?P.USE_PROFILES:!1,J=P.ALLOW_ARIA_ATTR!==!1,ie=P.ALLOW_DATA_ATTR!==!1,Ue=P.ALLOW_UNKNOWN_PROTOCOLS||!1,K=P.ALLOW_SELF_CLOSE_IN_ATTR!==!1,j=P.SAFE_FOR_TEMPLATES||!1,Ce=P.SAFE_FOR_XML!==!1,De=P.WHOLE_DOCUMENT||!1,ge=P.RETURN_DOM||!1,Rt=P.RETURN_DOM_FRAGMENT||!1,Me=P.RETURN_TRUSTED_TYPE||!1,Se=P.FORCE_BODY||!1,ae=P.SANITIZE_DOM!==!1,ur=P.SANITIZE_NAMED_PROPS||!1,Qt=P.KEEP_CONTENT!==!1,Or=P.IN_PLACE||!1,Xe=P.ALLOWED_URI_REGEXP||vg,Nt=P.NAMESPACE||pt,it=P.MATHML_TEXT_INTEGRATION_POINTS||it,Ge=P.HTML_INTEGRATION_POINTS||Ge,de=P.CUSTOM_ELEMENT_HANDLING||{},P.CUSTOM_ELEMENT_HANDLING&&gn(P.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(de.tagNameCheck=P.CUSTOM_ELEMENT_HANDLING.tagNameCheck),P.CUSTOM_ELEMENT_HANDLING&&gn(P.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(de.attributeNameCheck=P.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),P.CUSTOM_ELEMENT_HANDLING&&typeof P.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(de.allowCustomizedBuiltInElements=P.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),j&&(ie=!1),Rt&&(ge=!0),vr&&(Y=Tt({},hg),G=ui(null),vr.html===!0&&(Tt(Y,gg),Tt(G,xg)),vr.svg===!0&&(Tt(Y,jl),Tt(G,Jl),Tt(G,pi)),vr.svgFilters===!0&&(Tt(Y,Gl),Tt(G,Jl),Tt(G,pi)),vr.mathMl===!0&&(Tt(Y,Xl),Tt(G,yg),Tt(G,pi))),fn(P,"ADD_TAGS")||(Ye.tagCheck=null),fn(P,"ADD_ATTR")||(Ye.attributeCheck=null),P.ADD_TAGS&&(typeof P.ADD_TAGS=="function"?Ye.tagCheck=P.ADD_TAGS:(Y===Ee&&(Y=Un(Y)),Tt(Y,P.ADD_TAGS,rt))),P.ADD_ATTR&&(typeof P.ADD_ATTR=="function"?Ye.attributeCheck=P.ADD_ATTR:(G===ce&&(G=Un(G)),Tt(G,P.ADD_ATTR,rt))),P.ADD_URI_SAFE_ATTR&&Tt(Ne,P.ADD_URI_SAFE_ATTR,rt),P.FORBID_CONTENTS&&(Oe===q&&(Oe=Un(Oe)),Tt(Oe,P.FORBID_CONTENTS,rt)),P.ADD_FORBID_CONTENTS&&(Oe===q&&(Oe=Un(Oe)),Tt(Oe,P.ADD_FORBID_CONTENTS,rt)),Qt&&(Y["#text"]=!0),De&&Tt(Y,["html","head","body"]),Y.table&&(Tt(Y,["tbody"]),delete pe.tbody),P.TRUSTED_TYPES_POLICY){if(typeof P.TRUSTED_TYPES_POLICY.createHTML!="function")throw ps('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof P.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw ps('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');w=P.TRUSTED_TYPES_POLICY,b=w.createHTML("")}else w===void 0&&(w=Jy(m,o)),w!==null&&typeof b=="string"&&(b=w.createHTML(""));jr&&jr(P),lt=P}},Tn=Tt({},[...jl,...Gl,...Fy]),Et=Tt({},[...Xl,...Ny]),hn=function(P){let Z=E(P);(!Z||!Z.tagName)&&(Z={namespaceURI:Nt,tagName:"template"});let se=fi(P.tagName),Mt=fi(Z.tagName);return xe[P.namespaceURI]?P.namespaceURI===nt?Z.namespaceURI===pt?se==="svg":Z.namespaceURI===st?se==="svg"&&(Mt==="annotation-xml"||it[Mt]):!!Tn[se]:P.namespaceURI===st?Z.namespaceURI===pt?se==="math":Z.namespaceURI===nt?se==="math"&&Ge[Mt]:!!Et[se]:P.namespaceURI===pt?Z.namespaceURI===nt&&!Ge[Mt]||Z.namespaceURI===st&&!it[Mt]?!1:!Et[se]&&(Wt[se]||!Tn[se]):!!(ar==="application/xhtml+xml"&&xe[P.namespaceURI]):!1},pr=function(P){ds(r.removed,{element:P});try{E(P).removeChild(P)}catch{k(P)}},Ar=function(P,Z){try{ds(r.removed,{attribute:Z.getAttributeNode(P),from:Z})}catch{ds(r.removed,{attribute:null,from:Z})}if(Z.removeAttribute(P),P==="is")if(ge||Rt)try{pr(Z)}catch{}else try{Z.setAttribute(P,"")}catch{}},Kr=function(P){let Z=null,se=null;if(Se)P="<remove></remove>"+P;else{let Ht=Vl(P,/^[\r\n\t ]+/);se=Ht&&Ht[0]}ar==="application/xhtml+xml"&&Nt===pt&&(P='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+P+"</body></html>");let Mt=w?w.createHTML(P):P;if(Nt===pt)try{Z=new f().parseFromString(Mt,ar)}catch{}if(!Z||!Z.documentElement){Z=y.createDocument(Nt,"template",null);try{Z.documentElement.innerHTML=F?b:Mt}catch{}}let zt=Z.body||Z.documentElement;return P&&se&&zt.insertBefore(t.createTextNode(se),zt.childNodes[0]||null),Nt===pt?B.call(Z,De?"html":"body")[0]:De?Z.documentElement:zt},bt=function(P){return M.call(P.ownerDocument||P,P,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},kn=function(P){return P instanceof p&&(typeof P.nodeName!="string"||typeof P.textContent!="string"||typeof P.removeChild!="function"||!(P.attributes instanceof u)||typeof P.removeAttribute!="function"||typeof P.setAttribute!="function"||typeof P.namespaceURI!="string"||typeof P.insertBefore!="function"||typeof P.hasChildNodes!="function")},nn=function(P){return typeof i=="function"&&P instanceof i};function Sr(Pe,P,Z){ci(Pe,se=>{se.call(r,P,Z,lt)})}let Tr=function(P){let Z=null;if(Sr(W.beforeSanitizeElements,P,null),kn(P))return pr(P),!0;let se=rt(P.nodeName);if(Sr(W.uponSanitizeElement,P,{tagName:se,allowedTags:Y}),Ce&&P.hasChildNodes()&&!nn(P.firstElementChild)&&Vr(/<[/\w!]/g,P.innerHTML)&&Vr(/<[/\w!]/g,P.textContent)||P.nodeType===fs.progressingInstruction||Ce&&P.nodeType===fs.comment&&Vr(/<[/\w]/g,P.data))return pr(P),!0;if(!(Ye.tagCheck instanceof Function&&Ye.tagCheck(se))&&(!Y[se]||pe[se])){if(!pe[se]&&En(se)&&(de.tagNameCheck instanceof RegExp&&Vr(de.tagNameCheck,se)||de.tagNameCheck instanceof Function&&de.tagNameCheck(se)))return!1;if(Qt&&!Oe[se]){let Mt=E(P)||P.parentNode,zt=S(P)||P.childNodes;if(zt&&Mt){let Ht=zt.length;for(let sr=Ht-1;sr>=0;--sr){let xr=A(zt[sr],!0);xr.__removalCount=(P.__removalCount||0)+1,Mt.insertBefore(xr,T(P))}}}return pr(P),!0}return P instanceof d&&!hn(P)||(se==="noscript"||se==="noembed"||se==="noframes")&&Vr(/<\/no(script|embed|frames)/i,P.innerHTML)?(pr(P),!0):(j&&P.nodeType===fs.text&&(Z=P.textContent,ci([V,ne,ue],Mt=>{Z=cs(Z,Mt," ")}),P.textContent!==Z&&(ds(r.removed,{element:P.cloneNode()}),P.textContent=Z)),Sr(W.afterSanitizeElements,P,null),!1)},Vn=function(P,Z,se){if(Re[Z]||ae&&(Z==="id"||Z==="name")&&(se in t||se in rr))return!1;if(!(ie&&!Re[Z]&&Vr(Be,Z))){if(!(J&&Vr(Ke,Z))){if(!(Ye.attributeCheck instanceof Function&&Ye.attributeCheck(Z,P))){if(!G[Z]||Re[Z]){if(!(En(P)&&(de.tagNameCheck instanceof RegExp&&Vr(de.tagNameCheck,P)||de.tagNameCheck instanceof Function&&de.tagNameCheck(P))&&(de.attributeNameCheck instanceof RegExp&&Vr(de.attributeNameCheck,Z)||de.attributeNameCheck instanceof Function&&de.attributeNameCheck(Z,P))||Z==="is"&&de.allowCustomizedBuiltInElements&&(de.tagNameCheck instanceof RegExp&&Vr(de.tagNameCheck,se)||de.tagNameCheck instanceof Function&&de.tagNameCheck(se))))return!1}else if(!Ne[Z]){if(!Vr(Xe,cs(se,me,""))){if(!((Z==="src"||Z==="xlink:href"||Z==="href")&&P!=="script"&&By(se,"data:")===0&&Te[P])){if(!(Ue&&!Vr(ye,cs(se,me,"")))){if(se)return!1}}}}}}}return!0},En=function(P){return P!=="annotation-xml"&&Vl(P,We)},xn=function(P){Sr(W.beforeSanitizeAttributes,P,null);let{attributes:Z}=P;if(!Z||kn(P))return;let se={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:G,forceKeepAttr:void 0},Mt=Z.length;for(;Mt--;){let zt=Z[Mt],{name:Ht,namespaceURI:sr,value:xr}=zt,Fr=rt(Ht),kr=xr,ot=Ht==="value"?kr:Wy(kr);if(se.attrName=Fr,se.attrValue=ot,se.keepAttr=!0,se.forceKeepAttr=void 0,Sr(W.uponSanitizeAttribute,P,se),ot=se.attrValue,ur&&(Fr==="id"||Fr==="name")&&(Ar(Ht,P),ot=Ut+ot),Ce&&Vr(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,ot)){Ar(Ht,P);continue}if(Fr==="attributename"&&Vl(ot,"href")){Ar(Ht,P);continue}if(se.forceKeepAttr)continue;if(!se.keepAttr){Ar(Ht,P);continue}if(!K&&Vr(/\/>/i,ot)){Ar(Ht,P);continue}j&&ci([V,ne,ue],Nr=>{ot=cs(ot,Nr," ")});let wr=rt(P.nodeName);if(!Vn(wr,Fr,ot)){Ar(Ht,P);continue}if(w&&typeof m=="object"&&typeof m.getAttributeType=="function"&&!sr)switch(m.getAttributeType(wr,Fr)){case"TrustedHTML":{ot=w.createHTML(ot);break}case"TrustedScriptURL":{ot=w.createScriptURL(ot);break}}if(ot!==kr)try{sr?P.setAttributeNS(sr,Ht,ot):P.setAttribute(Ht,ot),kn(P)?pr(P):mg(r.removed)}catch{Ar(Ht,P)}}Sr(W.afterSanitizeAttributes,P,null)},vt=function Pe(P){let Z=null,se=bt(P);for(Sr(W.beforeSanitizeShadowDOM,P,null);Z=se.nextNode();)Sr(W.uponSanitizeShadowNode,Z,null),Tr(Z),xn(Z),Z.content instanceof a&&Pe(Z.content);Sr(W.afterSanitizeShadowDOM,P,null)};return r.sanitize=function(Pe){let P=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},Z=null,se=null,Mt=null,zt=null;if(F=!Pe,F&&(Pe="<!-->"),typeof Pe!="string"&&!nn(Pe))if(typeof Pe.toString=="function"){if(Pe=Pe.toString(),typeof Pe!="string")throw ps("dirty is not a string, aborting")}else throw ps("toString is not a function");if(!r.isSupported)return Pe;if(oe||Ir(P),r.removed=[],typeof Pe=="string"&&(Or=!1),Or){if(Pe.nodeName){let xr=rt(Pe.nodeName);if(!Y[xr]||pe[xr])throw ps("root node is forbidden and cannot be sanitized in-place")}}else if(Pe instanceof i)Z=Kr("<!---->"),se=Z.ownerDocument.importNode(Pe,!0),se.nodeType===fs.element&&se.nodeName==="BODY"||se.nodeName==="HTML"?Z=se:Z.appendChild(se);else{if(!ge&&!j&&!De&&Pe.indexOf("<")===-1)return w&&Me?w.createHTML(Pe):Pe;if(Z=Kr(Pe),!Z)return ge?null:Me?b:""}Z&&Se&&pr(Z.firstChild);let Ht=bt(Or?Pe:Z);for(;Mt=Ht.nextNode();)Tr(Mt),xn(Mt),Mt.content instanceof a&&vt(Mt.content);if(Or)return Pe;if(ge){if(Rt)for(zt=H.call(Z.ownerDocument);Z.firstChild;)zt.appendChild(Z.firstChild);else zt=Z;return(G.shadowroot||G.shadowrootmode)&&(zt=R.call(n,zt,!0)),zt}let sr=De?Z.outerHTML:Z.innerHTML;return De&&Y["!doctype"]&&Z.ownerDocument&&Z.ownerDocument.doctype&&Z.ownerDocument.doctype.name&&Vr(Ag,Z.ownerDocument.doctype.name)&&(sr="<!DOCTYPE "+Z.ownerDocument.doctype.name+`>
|
|
48
|
+
`+sr),j&&ci([V,ne,ue],xr=>{sr=cs(sr,xr," ")}),w&&Me?w.createHTML(sr):sr},r.setConfig=function(){let Pe=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ir(Pe),oe=!0},r.clearConfig=function(){lt=null,oe=!1},r.isValidAttribute=function(Pe,P,Z){lt||Ir({});let se=rt(Pe),Mt=rt(P);return Vn(se,Mt,Z)},r.addHook=function(Pe,P){typeof P=="function"&&ds(W[Pe],P)},r.removeHook=function(Pe,P){if(P!==void 0){let Z=Ry(W[Pe],P);return Z===-1?void 0:Hy(W[Pe],Z,1)[0]}return mg(W[Pe])},r.removeHooks=function(Pe){W[Pe]=[]},r.removeAllHooks=function(){W=Cg()},r}var Tg=Sg();var Ky={ALLOWED_TAGS:["h1","h2","h3","h4","h5","h6","p","br","hr","div","span","ul","ol","li","dl","dt","dd","strong","em","b","i","u","s","del","ins","mark","small","sub","sup","abbr","kbd","var","samp","code","a","img","blockquote","pre","details","summary","table","thead","tbody","tfoot","tr","th","td","caption","colgroup","col","input","label","select","option","textarea","button"],ALLOWED_ATTR:["href","src","alt","title","target","rel","loading","width","height","colspan","rowspan","scope","class","id","type","name","value","placeholder","disabled","checked","for","aria-label","aria-hidden","aria-expanded","role","tabindex","data-tv-form","data-message-id","data-persona-component-directive","data-preserve-animation","data-persona-instance"]},Yy=/^data:image\/(?:png|jpe?g|gif|webp|bmp|x-icon|avif)/i,Ql=()=>{let e=Tg(typeof window!="undefined"?window:void 0);return e.addHook("uponSanitizeAttribute",(r,t)=>{if(t.attrName==="src"||t.attrName==="href"){let n=t.attrValue;n.toLowerCase().startsWith("data:")&&!Yy.test(n)&&(t.attrValue="",t.keepAttr=!1)}}),r=>e.sanitize(r,Ky)},ba=e=>e===!1?null:typeof e=="function"?e:Ql();var ro=Bl(hi(),1),xi=e=>e.replace(/\\n/g,`
|
|
49
49
|
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"),Ca=e=>{if(e===null)return"null";if(e===void 0)return"";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}},rb=e=>{var s,i;let r=(s=e.completedAt)!=null?s:Date.now(),t=(i=e.startedAt)!=null?i:r,o=(e.durationMs!==void 0?e.durationMs:Math.max(0,r-t))/1e3;return o<.1?"Thought for <0.1 seconds":`Thought for ${o>=10?Math.round(o).toString():o.toFixed(1).replace(/\.0$/,"")} seconds`},Eg=e=>e.status==="complete"?rb(e):e.status==="pending"?"Waiting":"",nb=e=>{var o,a,s;let t=(typeof e.duration=="number"?e.duration:typeof e.durationMs=="number"?e.durationMs:Math.max(0,((o=e.completedAt)!=null?o:Date.now())-((s=(a=e.startedAt)!=null?a:e.completedAt)!=null?s:Date.now())))/1e3;return t<.1?"Used tool for <0.1 seconds":`Used tool for ${t>=10?Math.round(t).toString():t.toFixed(1).replace(/\.0$/,"")} seconds`};var Mg=e=>e.status==="complete"?nb(e):"Using tool...",yi=e=>{let r=e/1e3;return r<.1?"<0.1s":r>=10?`${Math.round(r)}s`:`${r.toFixed(1).replace(/\.0$/,"")}s`},gs=e=>{var t,n,o;let r=typeof e.duration=="number"?e.duration:typeof e.durationMs=="number"?e.durationMs:Math.max(0,((t=e.completedAt)!=null?t:Date.now())-((o=(n=e.startedAt)!=null?n:e.completedAt)!=null?o:Date.now()));return yi(r)},bi=e=>{var t,n,o;let r=e.durationMs!==void 0?e.durationMs:Math.max(0,((t=e.completedAt)!=null?t:Date.now())-((o=(n=e.startedAt)!=null?n:e.completedAt)!=null?o:Date.now()));return yi(r)},ed=(e,r,t)=>{var a;if(!r)return t;let n=((a=e.name)==null?void 0:a.trim())||"tool",o=gs(e);return r.replace(/\{toolName\}/g,n).replace(/\{duration\}/g,o)},Ci=(e,r)=>{let t=e.replace(/\{toolName\}/g,r),n=[],o=/\*\*(.+?)\*\*|\*(.+?)\*|~(.+?)~/g,a=0,s;for(;(s=o.exec(t))!==null;)s.index>a&&ms(n,t.slice(a,s.index),[]),s[1]!==void 0?ms(n,s[1],["bold"]):s[2]!==void 0?ms(n,s[2],["italic"]):s[3]!==void 0&&ms(n,s[3],["dim"]),a=s.index+s[0].length;return a<t.length&&ms(n,t.slice(a),[]),n},ms=(e,r,t)=>{let n=r.split("{duration}");for(let o=0;o<n.length;o++)n[o]&&e.push({text:n[o],styles:t}),o<n.length-1&&e.push({text:"{duration}",styles:t,isDuration:!0})},ob=()=>{let e=null,r=0,t=n=>{let o=/"text"\s*:\s*"((?:[^"\\]|\\.|")*?)"/,a=n.match(o);if(a&&a[1])try{return a[1].replace(/\\n/g,`
|
|
50
50
|
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}catch{return a[1]}let s=/"text"\s*:\s*"((?:[^"\\]|\\.)*)/,i=n.match(s);if(i&&i[1])try{return i[1].replace(/\\n/g,`
|
|
51
|
-
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}catch{return i[1]}return null};return{getExtractedText:()=>e,processChunk:async n=>{if(n.length<=r)return e!==null?{text:e,raw:n}:null;let o=n.trim();if(!o.startsWith("{")&&!o.startsWith("["))return null;let a=t(n);return a!==null&&(e=a),r=n.length,e!==null?{text:e,raw:n}:null},close:async()=>{}}},Ko=e=>{try{let r=JSON.parse(e);if(r&&typeof r=="object"&&typeof r.text=="string")return r.text}catch{return null}return null},wi=()=>{let e={processChunk:r=>null,getExtractedText:()=>null};return e.__isPlainTextParser=!0,e},vi=()=>{var r;let e=ob();return{processChunk:async t=>{let n=t.trim();return!n.startsWith("{")&&!n.startsWith("[")?null:e.processChunk(t)},getExtractedText:e.getExtractedText.bind(e),close:(r=e.close)==null?void 0:r.bind(e)}},Ai=()=>{let e=null,r=0;return{getExtractedText:()=>e,processChunk:t=>{let n=t.trim();if(!n.startsWith("{")&&!n.startsWith("["))return null;if(t.length<=r)return e!==null||e===""?{text:e||"",raw:t}:null;try{let o=(0,ro.parse)(t,ro.STR|ro.OBJ);o&&typeof o=="object"&&(o.component&&typeof o.component=="string"?e=typeof o.text=="string"?xi(o.text):"":o.type==="init"&&o.form?e="":typeof o.text=="string"&&(e=xi(o.text)))}catch{}return r=t.length,e!==null?{text:e,raw:t}:null},close:()=>{}}},Lg=e=>{let r=null,t=0,o=e||(a=>{if(!a||typeof a!="object")return null;let s=i=>typeof i=="string"?xi(i):null;if(a.component&&typeof a.component=="string")return typeof a.text=="string"?xi(a.text):"";if(a.type==="init"&&a.form)return"";if(a.action)switch(a.action){case"nav_then_click":return s(a.on_load_text)||s(a.text)||null;case"message":case"message_and_click":case"checkout":return s(a.text)||null;default:return s(a.text)||s(a.display_text)||s(a.message)||null}return s(a.text)||s(a.display_text)||s(a.message)||s(a.content)||null});return{getExtractedText:()=>r,processChunk:a=>{let s=a.trim();if(!s.startsWith("{")&&!s.startsWith("["))return null;if(a.length<=t)return r!==null?{text:r,raw:a}:null;try{let i=(0,ro.parse)(a,ro.STR|ro.OBJ),d=o(i);d!==null&&(r=d)}catch{}return t=a.length,{text:r||"",raw:a}},close:()=>{}}},Si=()=>{let e=null;return{processChunk:r=>{if(!r.trim().startsWith("<"))return null;let n=r.match(/<text[^>]*>([\s\S]*?)<\/text>/);return n&&n[1]?(e=n[1],{text:e,raw:r}):null},getExtractedText:()=>e}};var Ti=class{constructor(r,t=50){this.nextExpectedSeq=null;this.buffer=new Map;this.flushTimer=null;this.emitter=r,this.gapTimeoutMs=t}push(r,t){var a,s,i;let n=(i=(a=t==null?void 0:t.seq)!=null?a:t==null?void 0:t.sequenceIndex)!=null?i:(s=t==null?void 0:t.agentContext)==null?void 0:s.seq;if(n==null){this.buffer.size>0&&this.flushAll(),this.emitter(r,t);return}if(this.nextExpectedSeq===null&&(this.nextExpectedSeq=1),n===this.nextExpectedSeq){this.emitter(r,t),this.nextExpectedSeq=n+1,this.drainConsecutive();return}if(n<this.nextExpectedSeq){this.emitter(r,t);return}let o=this.buffer.get(n);o!==void 0&&(typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(`[persona] SequenceReorderBuffer: duplicate seq=${n} (${o.payloadType} vs ${r}); emitting earlier event out-of-order to avoid loss`),this.emitter(o.payloadType,o.payload)),this.buffer.set(n,{payloadType:r,payload:t,seq:n}),this.startGapTimer()}drainConsecutive(){for(;this.buffer.has(this.nextExpectedSeq);){let r=this.buffer.get(this.nextExpectedSeq);this.buffer.delete(this.nextExpectedSeq),this.emitter(r.payloadType,r.payload),this.nextExpectedSeq++}this.buffer.size===0&&this.clearGapTimer()}startGapTimer(){this.flushTimer===null&&(this.flushTimer=setTimeout(()=>{this.flushAll()},this.gapTimeoutMs))}clearGapTimer(){this.flushTimer!==null&&(clearTimeout(this.flushTimer),this.flushTimer=null)}flushAll(){if(this.clearGapTimer(),this.buffer.size===0)return;let r=[...this.buffer.entries()].sort((t,n)=>t[0]-n[0]);for(let[t,n]of r)this.buffer.delete(t),this.emitter(n.payloadType,n.payload);r.length>0&&(this.nextExpectedSeq=r[r.length-1][0]+1)}destroy(){this.clearGapTimer(),this.buffer.clear()}flushPending(){this.flushAll()}};var ab="https://api.runtype.com/v1/dispatch",ki="https://api.runtype.com";function sb(e){var a,s;let r=e.toLowerCase(),n={"application/pdf":"pdf","application/json":"json","application/zip":"zip","text/plain":"txt","text/csv":"csv","text/markdown":"md"}[r];if(n)return`attachment.${n}`;let o=r.indexOf("/");if(o>0){let i=(s=(a=r.slice(o+1).split(";")[0])==null?void 0:a.trim())!=null?s:"";if(i&&i!=="octet-stream"&&/^[a-z0-9.+-]+$/i.test(i))return`attachment.${i}`}return"attachment"}var td=e=>!!(e.contentParts&&e.contentParts.length>0||e.llmContent&&e.llmContent.trim().length>0||e.rawContent&&e.rawContent.trim().length>0||e.content&&e.content.trim().length>0);function ib(e){switch(e){case"json":return Ai;case"regex-json":return vi;case"xml":return Si;default:return wi}}var Pg=e=>e.startsWith("{")||e.startsWith("[")||e.startsWith("<");function lb(e,r){if(!e)return r;let t=e.trim(),n=r.trim();if(t.length===0)return r;if(n.length===0)return e;let o=Pg(t);if(!Pg(n))return e;if(!o||n===t||n.startsWith(t))return r;let s=Ko(e);return Ko(r)!==null&&s===null?r:e}var Yo=class{constructor(r={}){this.config=r;this.clientSession=null;this.sessionInitPromise=null;var t,n,o;this.apiUrl=(t=r.apiUrl)!=null?t:ab,this.headers={"Content-Type":"application/json",...r.headers},this.debug=!!r.debug,this.createStreamParser=(n=r.streamParser)!=null?n:ib(r.parserType),this.contextProviders=(o=r.contextProviders)!=null?o:[],this.requestMiddleware=r.requestMiddleware,this.customFetch=r.customFetch,this.parseSSEEvent=r.parseSSEEvent,this.getHeaders=r.getHeaders}setSSEEventCallback(r){this.onSSEEvent=r}getSSEEventCallback(){return this.onSSEEvent}isClientTokenMode(){return!!this.config.clientToken}isAgentMode(){return!!this.config.agent}getClientApiUrl(r){var n;let t=((n=this.config.apiUrl)==null?void 0:n.replace(/\/+$/,"").replace(/\/v1\/dispatch$/,""))||ki;return r==="init"?`${t}/v1/client/init`:`${t}/v1/client/chat`}getClientSession(){return this.clientSession}async initSession(){var r,t;if(!this.isClientTokenMode())throw new Error("initSession() only available in client token mode");if(this.clientSession&&new Date<this.clientSession.expiresAt)return this.clientSession;if(this.sessionInitPromise)return this.sessionInitPromise;this.sessionInitPromise=this._doInitSession();try{let n=await this.sessionInitPromise;return this.clientSession=n,(t=(r=this.config).onSessionInit)==null||t.call(r,n),n}finally{this.sessionInitPromise=null}}async _doInitSession(){var a,s;let r=((s=(a=this.config).getStoredSessionId)==null?void 0:s.call(a))||null,t={token:this.config.clientToken,...this.config.flowId&&{flowId:this.config.flowId},...r&&{sessionId:r}},n=await fetch(this.getClientApiUrl("init"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok){let i=await n.json().catch(()=>({error:"Session initialization failed"}));throw n.status===401?new Error(`Invalid client token: ${i.hint||i.error}`):n.status===403?new Error(`Origin not allowed: ${i.hint||i.error}`):new Error(i.error||"Failed to initialize session")}let o=await n.json();return this.config.setStoredSessionId&&this.config.setStoredSessionId(o.sessionId),{sessionId:o.sessionId,expiresAt:new Date(o.expiresAt),flow:o.flow,config:{welcomeMessage:o.config.welcomeMessage,placeholder:o.config.placeholder,theme:o.config.theme}}}clearClientSession(){this.clientSession=null,this.sessionInitPromise=null}getFeedbackApiUrl(){var t;return`${((t=this.config.apiUrl)==null?void 0:t.replace(/\/+$/,"").replace(/\/v1\/dispatch$/,""))||ki}/v1/client/feedback`}async sendFeedback(r){var a,s;if(!this.isClientTokenMode())throw new Error("sendFeedback() only available in client token mode");if(!this.getClientSession())throw new Error("No active session. Please initialize session first.");if(["upvote","downvote","copy"].includes(r.type)&&!r.messageId)throw new Error(`messageId is required for ${r.type} feedback type`);if(r.type==="csat"&&(r.rating===void 0||r.rating<1||r.rating>5))throw new Error("CSAT rating must be between 1 and 5");if(r.type==="nps"&&(r.rating===void 0||r.rating<0||r.rating>10))throw new Error("NPS rating must be between 0 and 10");this.debug&&console.debug("[AgentWidgetClient] sending feedback",r);let o=await fetch(this.getFeedbackApiUrl(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok){let i=await o.json().catch(()=>({error:"Feedback submission failed"}));throw o.status===401?(this.clientSession=null,(s=(a=this.config).onSessionExpired)==null||s.call(a),new Error("Session expired. Please refresh to continue.")):new Error(i.error||"Failed to submit feedback")}}async submitMessageFeedback(r,t){let n=this.getClientSession();if(!n)throw new Error("No active session. Please initialize session first.");return this.sendFeedback({sessionId:n.sessionId,messageId:r,type:t})}async submitCSATFeedback(r,t){let n=this.getClientSession();if(!n)throw new Error("No active session. Please initialize session first.");return this.sendFeedback({sessionId:n.sessionId,type:"csat",rating:r,comment:t})}async submitNPSFeedback(r,t){let n=this.getClientSession();if(!n)throw new Error("No active session. Please initialize session first.");return this.sendFeedback({sessionId:n.sessionId,type:"nps",rating:r,comment:t})}async dispatch(r,t){return this.isAgentMode()?this.dispatchAgent(r,t):this.isClientTokenMode()?this.dispatchClientToken(r,t):this.dispatchProxy(r,t)}async dispatchClientToken(r,t){var o,a,s,i;let n=new AbortController;r.signal&&r.signal.addEventListener("abort",()=>n.abort()),t({type:"status",status:"connecting"});try{let d=await this.initSession();if(new Date>=new Date(d.expiresAt.getTime()-6e4)){this.clientSession=null,(a=(o=this.config).onSessionExpired)==null||a.call(o);let m=new Error("Session expired. Please refresh to continue.");throw t({type:"error",error:m}),m}let l=await this.buildPayload(r.messages),u=l.metadata?Object.fromEntries(Object.entries(l.metadata).filter(([m])=>m!=="sessionId"&&m!=="session_id")):void 0,p={sessionId:d.sessionId,messages:r.messages.filter(td).map(m=>{var C,w,k;return{id:m.id,role:m.role,content:(k=(w=(C=m.contentParts)!=null?C:m.llmContent)!=null?w:m.rawContent)!=null?k:m.content}}),...r.assistantMessageId&&{assistantMessageId:r.assistantMessageId},...u&&Object.keys(u).length>0&&{metadata:u},...l.inputs&&Object.keys(l.inputs).length>0&&{inputs:l.inputs},...l.context&&{context:l.context}};this.debug&&console.debug("[AgentWidgetClient] client token dispatch",p);let f=await fetch(this.getClientApiUrl("chat"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p),signal:n.signal});if(!f.ok){let m=await f.json().catch(()=>({error:"Chat request failed"}));if(f.status===401){this.clientSession=null,(i=(s=this.config).onSessionExpired)==null||i.call(s);let w=new Error("Session expired. Please refresh to continue.");throw t({type:"error",error:w}),w}if(f.status===429){let w=new Error(m.hint||"Message limit reached for this session.");throw t({type:"error",error:w}),w}let C=new Error(m.error||"Failed to send message");throw t({type:"error",error:C}),C}if(!f.body){let m=new Error("No response body received");throw t({type:"error",error:m}),m}t({type:"status",status:"connected"});try{await this.streamResponse(f.body,t,r.assistantMessageId)}finally{t({type:"status",status:"idle"})}}catch(d){let l=d instanceof Error?d:new Error(String(d));throw!l.message.includes("Session expired")&&!l.message.includes("Message limit")&&t({type:"error",error:l}),l}}async dispatchProxy(r,t){let n=new AbortController;r.signal&&r.signal.addEventListener("abort",()=>n.abort()),t({type:"status",status:"connecting"});let o=await this.buildPayload(r.messages);this.debug&&console.debug("[AgentWidgetClient] dispatch payload",o);let a={...this.headers};if(this.getHeaders)try{let i=await this.getHeaders();a={...a,...i}}catch(i){typeof console!="undefined"&&console.error("[AgentWidget] getHeaders error:",i)}let s;if(this.customFetch)try{s=await this.customFetch(this.apiUrl,{method:"POST",headers:a,body:JSON.stringify(o),signal:n.signal},o)}catch(i){let d=i instanceof Error?i:new Error(String(i));throw t({type:"error",error:d}),d}else s=await fetch(this.apiUrl,{method:"POST",headers:a,body:JSON.stringify(o),signal:n.signal});if(!s.ok||!s.body){let i=new Error(`Chat backend request failed: ${s.status} ${s.statusText}`);throw t({type:"error",error:i}),i}t({type:"status",status:"connected"});try{await this.streamResponse(s.body,t)}finally{t({type:"status",status:"idle"})}}async dispatchAgent(r,t){let n=new AbortController;r.signal&&r.signal.addEventListener("abort",()=>n.abort()),t({type:"status",status:"connecting"});let o=await this.buildAgentPayload(r.messages);this.debug&&console.debug("[AgentWidgetClient] agent dispatch payload",o);let a={...this.headers};if(this.getHeaders)try{let i=await this.getHeaders();a={...a,...i}}catch(i){typeof console!="undefined"&&console.error("[AgentWidget] getHeaders error:",i)}let s;if(this.customFetch)try{s=await this.customFetch(this.apiUrl,{method:"POST",headers:a,body:JSON.stringify(o),signal:n.signal},o)}catch(i){let d=i instanceof Error?i:new Error(String(i));throw t({type:"error",error:d}),d}else s=await fetch(this.apiUrl,{method:"POST",headers:a,body:JSON.stringify(o),signal:n.signal});if(!s.ok||!s.body){let i=new Error(`Agent execution request failed: ${s.status} ${s.statusText}`);throw t({type:"error",error:i}),i}t({type:"status",status:"connected"});try{await this.streamResponse(s.body,t,r.assistantMessageId)}finally{t({type:"status",status:"idle"})}}async processStream(r,t,n){t({type:"status",status:"connected"});try{await this.streamResponse(r,t,n)}finally{t({type:"status",status:"idle"})}}async resolveApproval(r,t){var s;let o=`${((s=this.config.apiUrl)==null?void 0:s.replace(/\/+$/,"").replace(/\/v1\/dispatch$/,""))||ki}/v1/agents/${r.agentId}/approve`,a={"Content-Type":"application/json",...this.headers};return this.getHeaders&&Object.assign(a,await this.getHeaders()),fetch(o,{method:"POST",headers:a,body:JSON.stringify({executionId:r.executionId,approvalId:r.approvalId,decision:t,streamResponse:!0})})}async resumeFlow(r,t,n){var i,d;let a=`${((i=this.config.apiUrl)==null?void 0:i.replace(/\/+$/,""))||ki}/resume`,s={"Content-Type":"application/json",...this.headers};return this.getHeaders&&Object.assign(s,await this.getHeaders()),fetch(a,{method:"POST",headers:s,body:JSON.stringify({executionId:r,toolOutputs:t,streamResponse:(d=n==null?void 0:n.streamResponse)!=null?d:!0})})}async buildAgentPayload(r){if(!this.config.agent)throw new Error("Agent configuration required for agent mode");let t=r.slice().filter(td).filter(o=>o.role==="user"||o.role==="assistant"||o.role==="system").filter(o=>!o.variant||o.variant==="assistant").sort((o,a)=>{let s=new Date(o.createdAt).getTime(),i=new Date(a.createdAt).getTime();return s-i}).map(o=>{var a,s,i;return{role:o.role,content:(i=(s=(a=o.contentParts)!=null?a:o.llmContent)!=null?s:o.rawContent)!=null?i:o.content,createdAt:o.createdAt}}),n={agent:this.config.agent,messages:t,options:{streamResponse:!0,recordMode:"virtual",...this.config.agentOptions}};if(this.contextProviders.length){let o={};await Promise.all(this.contextProviders.map(async a=>{try{let s=await a({messages:r,config:this.config});s&&typeof s=="object"&&Object.assign(o,s)}catch(s){typeof console!="undefined"&&console.warn("[AgentWidget] Context provider failed:",s)}})),Object.keys(o).length&&(n.context=o)}return n}async buildPayload(r){let n={messages:r.slice().filter(td).sort((o,a)=>{let s=new Date(o.createdAt).getTime(),i=new Date(a.createdAt).getTime();return s-i}).map(o=>{var a,s,i;return{role:o.role,content:(i=(s=(a=o.contentParts)!=null?a:o.llmContent)!=null?s:o.rawContent)!=null?i:o.content,createdAt:o.createdAt}}),...this.config.flowId&&{flowId:this.config.flowId}};if(this.contextProviders.length){let o={};await Promise.all(this.contextProviders.map(async a=>{try{let s=await a({messages:r,config:this.config});s&&typeof s=="object"&&Object.assign(o,s)}catch(s){typeof console!="undefined"&&console.warn("[AgentWidget] Context provider failed:",s)}})),Object.keys(o).length&&(n.context=o)}if(this.requestMiddleware)try{let o=await this.requestMiddleware({payload:{...n},config:this.config});if(o&&typeof o=="object")return o}catch(o){typeof console!="undefined"&&console.error("[AgentWidget] Request middleware error:",o)}return n}async handleCustomSSEEvent(r,t,n,o,a,s){if(!this.parseSSEEvent)return!1;try{let i=await this.parseSSEEvent(r);if(i===null)return!1;let d=u=>{let p={id:`assistant-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"assistant",sequence:a(),...u!==void 0&&{partId:u}};return n.current=p,o(p),p},l=u=>n.current?n.current:d(u);if(i.text!==void 0){i.partId!==void 0&&s.current!==null&&i.partId!==s.current&&(n.current&&(n.current.streaming=!1,o(n.current)),d(i.partId)),i.partId!==void 0&&(s.current=i.partId);let u=l(i.partId);i.partId!==void 0&&!u.partId&&(u.partId=i.partId),u.content+=i.text,o(u)}return i.done&&(n.current&&(n.current.streaming=!1,o(n.current)),s.current=null,t({type:"status",status:"idle"})),i.error&&(s.current=null,t({type:"error",error:new Error(i.error)})),!0}catch(i){return typeof console!="undefined"&&console.error("[AgentWidget] parseSSEEvent error:",i),!1}}async streamResponse(r,t,n){var Qt,Or,vr,Oe;let o=r.getReader(),a=new TextDecoder,s="",i=Date.now(),d=0,l=()=>i+d++,u=q=>{let Te=q.reasoning?{...q.reasoning,chunks:[...q.reasoning.chunks]}:void 0,_e=q.toolCall?{...q.toolCall,chunks:q.toolCall.chunks?[...q.toolCall.chunks]:void 0}:void 0,Ne=q.tools?q.tools.map(qe=>({...qe,chunks:qe.chunks?[...qe.chunks]:void 0})):void 0;return{...q,reasoning:Te,toolCall:_e,tools:Ne}},p=q=>{t({type:"message",message:u(q)})},f=null,m=null,C={current:null},w={current:null},k=!1,T=new Map,S=new Map,E=new Map,v=new Map,b={lastId:null,byStep:new Map},y={lastId:null,byCall:new Map},M=(q,Te,_e="")=>`${q}::${Te}::${_e}`,H=(q,Te)=>`${q}::${Te}::`,B=(q,Te,_e,Ne)=>{let qe=M(q,Te,_e),st=E.get(qe);if(st)return st;let nt=_e?`-${_e}`:"",pt={id:`nested-${q}-${Te}${nt}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,sequence:l(),..._e?{partId:_e}:{},agentMetadata:{executionId:Ne,parentToolId:q,parentStepId:Te}};return E.set(qe,pt),p(pt),pt},R=q=>{if(q==null)return null;try{return String(q)}catch{return null}},W=q=>{var Te,_e,Ne,qe,st;return R((st=(qe=(Ne=(_e=(Te=q.stepId)!=null?Te:q.step_id)!=null?_e:q.step)!=null?Ne:q.parentId)!=null?qe:q.flowStepId)!=null?st:q.flow_step_id)},V=q=>{var Te,_e,Ne,qe,st,nt,pt;return R((pt=(nt=(st=(qe=(Ne=(_e=(Te=q.callId)!=null?Te:q.call_id)!=null?_e:q.requestId)!=null?Ne:q.request_id)!=null?qe:q.toolCallId)!=null?st:q.tool_call_id)!=null?nt:q.stepId)!=null?pt:q.step_id)},ne=n,ue=!1,We=()=>{if(f)return f;let q;return!ue&&ne?(q=ne,ue=!0):ne&&w.current?q=`${ne}_${w.current}`:q=`assistant-${Date.now()}-${Math.random().toString(16).slice(2)}`,f={id:q,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,sequence:l()},p(f),f},Ke=(q,Te)=>{b.lastId=Te,q&&b.byStep.set(q,Te)},xe=(q,Te)=>{var st;let _e=(st=q.reasoningId)!=null?st:q.id,Ne=W(q);if(_e){let nt=String(_e);return Ke(Ne,nt),nt}if(Ne){let nt=b.byStep.get(Ne);if(nt)return b.lastId=nt,nt}if(b.lastId&&!Te)return b.lastId;if(!Te)return null;let qe=`reason-${l()}`;return Ke(Ne,qe),qe},me=q=>{let Te=T.get(q);if(Te)return Te;let _e={id:`reason-${q}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"reasoning",sequence:l(),reasoning:{id:q,status:"streaming",chunks:[]}};return T.set(q,_e),p(_e),_e},Re=(q,Te)=>{y.lastId=Te,q&&y.byCall.set(q,Te)},Ge=new Set,Y=new Map,Ee=new Set,G=new Map,ce=q=>{if(!q)return!1;let Te=q.replace(/_+/g,"_").replace(/^_|_$/g,"");return Te==="emit_artifact_markdown"||Te==="emit_artifact_component"},de=(q,Te)=>{var st;let _e=(st=q.toolId)!=null?st:q.id,Ne=V(q);if(_e){let nt=String(_e);return Re(Ne,nt),nt}if(Ne){let nt=y.byCall.get(Ne);if(nt)return y.lastId=nt,nt}if(y.lastId&&!Te)return y.lastId;if(!Te)return null;let qe=`tool-${l()}`;return Re(Ne,qe),qe},pe=q=>{let Te=S.get(q);if(Te)return Te;let _e={id:`tool-${q}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"tool",sequence:l(),toolCall:{id:q,status:"pending"}};return S.set(q,_e),p(_e),_e},He=q=>{if(typeof q=="number"&&Number.isFinite(q))return q;if(typeof q=="string"){let Te=Number(q);if(!Number.isNaN(Te)&&Number.isFinite(Te))return Te;let _e=Date.parse(q);if(!Number.isNaN(_e))return _e}return Date.now()},Ye=q=>{if(typeof q=="string")return q;if(q==null)return"";try{return JSON.stringify(q)}catch{return String(q)}},J=new Map,ie=new Map,Ue=new Map,K=new Map,j=null,Ce=(q,Te,_e)=>{var pt;let Ne=Ue.get(q);Ne||(Ne=[],Ue.set(q,Ne));let qe=0,st=Ne.length;for(;qe<st;){let Nt=qe+st>>>1;Ne[Nt].seq<Te?qe=Nt+1:st=Nt}((pt=Ne[qe])==null?void 0:pt.seq)===Te?Ne[qe]={seq:Te,text:_e}:Ne.splice(qe,0,{seq:Te,text:_e});let nt="";for(let Nt=0;Nt<Ne.length;Nt++)nt+=Ne[Nt].text;return nt},De=(q,Te)=>{let _e=Ye(Te),Ne=ie.get(q.id),qe=lb(Ne,_e);q.rawContent=qe;let st=J.get(q.id),nt=be=>{var Xe;let it=(Xe=q.content)!=null?Xe:"";be.trim()!==""&&(it.trim().length===0||be.startsWith(it)||be.trimStart().startsWith(it.trim()))&&(q.content=be)},pt=()=>{var be;if(st){let it=(be=st.close)==null?void 0:be.call(st);it instanceof Promise&&it.catch(()=>{})}J.delete(q.id),ie.delete(q.id),q.streaming=!1,p(q)};if(!st){nt(_e),pt();return}let Nt=Ko(qe);if(Nt!==null&&Nt.trim()!==""){nt(Nt),pt();return}let F=be=>{var Wt;let it=typeof be=="string"?be:(Wt=be==null?void 0:be.text)!=null?Wt:null;if(it!==null&&it.trim()!=="")return it;let Xe=st.getExtractedText();return Xe!==null&&Xe.trim()!==""?Xe:_e},ye;try{ye=st.processChunk(qe)}catch{nt(_e),pt();return}if(ye instanceof Promise){ye.then(be=>{nt(F(be)),pt()}).catch(()=>{nt(_e),pt()});return}nt(F(ye)),pt()},oe=[],Se=!1,ge,Rt=()=>{Se||(Se=!0,queueMicrotask(()=>{Se=!1,ge()}))},Me=new Ti((q,Te)=>{oe.push({payloadType:q,payload:Te}),Rt()}),ae=null,ur=new Map,Ut=(Qt=this.config.iterationDisplay)!=null?Qt:"separate";for(ge=()=>{var q,Te,_e,Ne,qe,st,nt,pt,Nt,F,ye,be,it,Xe,Wt,ar,Pt,kt,rt,lt,rr,gn,Ir,Tn,Et,hn,pr,Ar,Kr,bt,kn,nn,Sr,Tr,Vn,En,xn,vt,Pe,P,Z,se,Mt,zt,Ht,sr,xr,Fr,kr,ot,wr,Nr,co,jn,po,Fn,on,Mn,At,ir,lr,an,uo,yn,Ln,sn,z,he,ln,Pn,Nn,Fa,In,Rn,Hn,Gn,Io,_s,Na,$s,la,wt,_a,bn,Yr,Us,qs,da,Xn,zs,Ro,$a,Jn,Ua,fo,mo,Vs,js,Hl,Ho,go,Gs,qa,ho,Xs,za,xo,Va,Js,Kn,Ks,yo,qt,ca,pa,ja,_n,Ys,Ga,Xa,Ja,Ka,_r,dn,Yn,ut,Ya,Bo,Bn,Qs,ua,fa,Wo,bo,Zs,ei,Wn,Do;for(let ma=0;ma<oe.length;ma++){let Ze=oe[ma].payloadType,L=oe[ma].payload;if(Ze==="reason_start"){let _=(q=xe(L,!0))!=null?q:`reason-${l()}`,I=me(_);I.reasoning=(Te=I.reasoning)!=null?Te:{id:_,status:"streaming",chunks:[]},I.reasoning.startedAt=(Ne=I.reasoning.startedAt)!=null?Ne:He((_e=L.startedAt)!=null?_e:L.timestamp),I.reasoning.completedAt=void 0,I.reasoning.durationMs=void 0,I.streaming=!0,I.reasoning.status="streaming",p(I)}else if(Ze==="reason_delta"||Ze==="reason_chunk"){let _=(st=(qe=xe(L,!1))!=null?qe:xe(L,!0))!=null?st:`reason-${l()}`,I=me(_);I.reasoning=(nt=I.reasoning)!=null?nt:{id:_,status:"streaming",chunks:[]},I.reasoning.startedAt=(Nt=I.reasoning.startedAt)!=null?Nt:He((pt=L.startedAt)!=null?pt:L.timestamp);let Q=(be=(ye=(F=L.reasoningText)!=null?F:L.text)!=null?ye:L.delta)!=null?be:"";if(Q&&L.hidden!==!0){let le=typeof L.sequenceIndex=="number"?L.sequenceIndex:void 0;if(le!==void 0){let ee=Ce(_,le,String(Q));I.reasoning.chunks=[ee]}else I.reasoning.chunks.push(String(Q))}if(I.reasoning.status=L.done?"complete":"streaming",L.done){I.reasoning.completedAt=He((it=L.completedAt)!=null?it:L.timestamp);let le=(Xe=I.reasoning.startedAt)!=null?Xe:Date.now();I.reasoning.durationMs=Math.max(0,((Wt=I.reasoning.completedAt)!=null?Wt:Date.now())-le)}I.streaming=I.reasoning.status!=="complete",p(I)}else if(Ze==="reason_complete"){let _=(Pt=(ar=xe(L,!1))!=null?ar:xe(L,!0))!=null?Pt:`reason-${l()}`,I=T.get(_);if(I!=null&&I.reasoning){I.reasoning.status="complete",I.reasoning.completedAt=He((kt=L.completedAt)!=null?kt:L.timestamp);let le=(rt=I.reasoning.startedAt)!=null?rt:Date.now();I.reasoning.durationMs=Math.max(0,((lt=I.reasoning.completedAt)!=null?lt:Date.now())-le),I.streaming=!1,p(I)}let Q=W(L);Q&&b.byStep.delete(Q)}else if(Ze==="tool_start"){let _=(rr=de(L,!0))!=null?rr:`tool-${l()}`,I=(gn=L.toolName)!=null?gn:L.name;if(ce(I)){Ge.add(_);continue}let Q=pe(_),le=(Ir=Q.toolCall)!=null?Ir:{id:_,status:"pending"};le.name=I!=null?I:le.name,le.status="running",L.args!==void 0?le.args=L.args:L.parameters!==void 0&&(le.args=L.parameters),le.startedAt=(Et=le.startedAt)!=null?Et:He((Tn=L.startedAt)!=null?Tn:L.timestamp),le.completedAt=void 0,le.durationMs=void 0,Q.toolCall=le,Q.streaming=!0;let ee=L.agentContext;(ee||L.executionId)&&(Q.agentMetadata={executionId:(hn=ee==null?void 0:ee.executionId)!=null?hn:L.executionId,iteration:(pr=ee==null?void 0:ee.iteration)!=null?pr:L.iteration}),p(Q)}else if(Ze==="tool_chunk"||Ze==="tool_delta"){let _=(Kr=(Ar=de(L,!1))!=null?Ar:de(L,!0))!=null?Kr:`tool-${l()}`;if(Ge.has(_))continue;let I=pe(_),Q=(bt=I.toolCall)!=null?bt:{id:_,status:"running"};Q.startedAt=(nn=Q.startedAt)!=null?nn:He((kn=L.startedAt)!=null?kn:L.timestamp);let le=(Vn=(Tr=(Sr=L.text)!=null?Sr:L.delta)!=null?Tr:L.message)!=null?Vn:"";le&&(Q.chunks=(En=Q.chunks)!=null?En:[],Q.chunks.push(String(le))),Q.status="running",I.toolCall=Q,I.streaming=!0;let ee=L.agentContext;(ee||L.executionId)&&(I.agentMetadata=(Pe=I.agentMetadata)!=null?Pe:{executionId:(xn=ee==null?void 0:ee.executionId)!=null?xn:L.executionId,iteration:(vt=ee==null?void 0:ee.iteration)!=null?vt:L.iteration}),p(I)}else if(Ze==="tool_complete"){let _=(Z=(P=de(L,!1))!=null?P:de(L,!0))!=null?Z:`tool-${l()}`;if(Ge.has(_)){Ge.delete(_);continue}let I=pe(_),Q=(se=I.toolCall)!=null?se:{id:_,status:"running"};Q.status="complete",L.result!==void 0&&(Q.result=L.result),typeof L.duration=="number"&&(Q.duration=L.duration),Q.completedAt=He((Mt=L.completedAt)!=null?Mt:L.timestamp);let le=(zt=L.duration)!=null?zt:L.executionTime;if(typeof le=="number")Q.durationMs=le;else{let ze=(Ht=Q.startedAt)!=null?Ht:Date.now();Q.durationMs=Math.max(0,((sr=Q.completedAt)!=null?sr:Date.now())-ze)}I.toolCall=Q,I.streaming=!1;let ee=L.agentContext;(ee||L.executionId)&&(I.agentMetadata=(kr=I.agentMetadata)!=null?kr:{executionId:(xr=ee==null?void 0:ee.executionId)!=null?xr:L.executionId,iteration:(Fr=ee==null?void 0:ee.iteration)!=null?Fr:L.iteration}),p(I);let et=V(L);et&&y.byCall.delete(et)}else if(Ze==="step_await"&&L.awaitReason==="local_tool_required"&&L.toolName){let _=(ot=L.toolId)!=null?ot:`local-${l()}`,I=pe(_),Q=(wr=I.toolCall)!=null?wr:{id:_,status:"pending"};Q.name=L.toolName,Q.args=L.parameters,Q.status="complete",Q.chunks=(Nr=Q.chunks)!=null?Nr:[],Q.startedAt=(jn=Q.startedAt)!=null?jn:He((co=L.startedAt)!=null?co:L.timestamp),Q.completedAt=(po=Q.completedAt)!=null?po:Q.startedAt,I.toolCall=Q,I.streaming=!1,I.agentMetadata={...I.agentMetadata,executionId:(on=L.executionId)!=null?on:(Fn=I.agentMetadata)==null?void 0:Fn.executionId,awaitingLocalTool:!0},p(I)}else if(Ze==="text_start"){if((Mn=L.toolContext)!=null&&Mn.toolId)continue;let _=L.partId;if(_!==void 0&&w.current!==null&&_!==w.current){let I=f;I&&(I.streaming=!1,p(I),j=I,f=null,k=!0)}_!==void 0&&(w.current=_)}else if(Ze==="text_end"){if((At=L.toolContext)!=null&&At.toolId)continue;let _=f;_&&(_.streaming=!1,p(_),j=_,f=null,k=!0)}else if(Ze==="step_chunk"||Ze==="step_delta"){let _=L.stepType,I=L.executionType;if(_==="tool"||I==="context")continue;let Q=L.toolContext;if(Q!=null&&Q.toolId){let ze=String((lr=(ir=L.id)!=null?ir:Q.stepId)!=null?lr:`step-${l()}`),ft=L.partId!==void 0&&L.partId!==null?String(L.partId):"",dt=`${Q.toolId}::${ze}`,Dt=v.get(dt);if(ft!==""&&Dt!==void 0&&Dt!==""&&Dt!==ft){let St=E.get(M(Q.toolId,ze,Dt));St&&St.streaming!==!1&&(St.streaming=!1,p(St))}ft!==""&&v.set(dt,ft);let _t=B(Q.toolId,ze,ft,Q.executionId),fr=(Ln=(yn=(uo=(an=L.text)!=null?an:L.delta)!=null?uo:L.content)!=null?yn:L.chunk)!=null?Ln:"";fr&&(_t.content+=String(fr),_t.streaming=!0,p(_t)),L.isComplete&&(_t.streaming=!1,p(_t));continue}let le=L.partId;if(le!==void 0&&w.current!==null&&le!==w.current){let ze=f;ze&&(ze.streaming=!1,p(ze),j=ze,f=null,k=!0)}le!==void 0&&(w.current=le);let ee=le!==void 0&&(sn=K.get(le))!=null?sn:We();le!==void 0&&(ee.partId||(ee.partId=le),K.set(le,ee));let et=(Pn=(ln=(he=(z=L.text)!=null?z:L.delta)!=null?he:L.content)!=null?ln:L.chunk)!=null?Pn:"";if(et){let ze=typeof L.seq=="number"?L.seq:void 0,ft=le!=null?le:ee.id,dt=ze!==void 0?Ce(ft,ze,String(et)):((Nn=ie.get(ee.id))!=null?Nn:"")+et;ee.rawContent=dt,J.has(ee.id)||J.set(ee.id,this.createStreamParser());let Dt=J.get(ee.id),_t=dt.trim().startsWith("{")||dt.trim().startsWith("[");if(_t&&ie.set(ee.id,dt),Dt.__isPlainTextParser===!0){ee.content=ze!==void 0?dt:ee.content+et,ie.delete(ee.id),J.delete(ee.id),ee.rawContent=void 0,p(ee);continue}let St=Dt.processChunk(dt);if(St instanceof Promise)St.then(Ot=>{var Rr;let yr=typeof Ot=="string"?Ot:(Rr=Ot==null?void 0:Ot.text)!=null?Rr:null;if(yr!==null&&yr.trim()!=="")ee.content=yr,p(ee);else if(!_t&&!dt.trim().startsWith("<")){let Er=f,Xt=Er&&Er.id===ee.id?Er:ee;Xt.id===ee.id&&(Xt.content=ze!==void 0?dt:Xt.content+et,ie.delete(Xt.id),J.delete(Xt.id),Xt.rawContent=void 0,p(Xt))}}).catch(()=>{ee.content=ze!==void 0?dt:ee.content+et,ie.delete(ee.id),J.delete(ee.id),ee.rawContent=void 0,p(ee)});else{let Ot=typeof St=="string"?St:(Fa=St==null?void 0:St.text)!=null?Fa:null;Ot!==null&&Ot.trim()!==""?(ee.content=Ot,p(ee)):!_t&&!dt.trim().startsWith("<")&&(ee.content=ze!==void 0?dt:ee.content+et,ie.delete(ee.id),J.delete(ee.id),ee.rawContent=void 0,p(ee))}}if(L.isComplete){let ze=(Rn=(In=L.result)==null?void 0:In.response)!=null?Rn:ee.content;if(ze){let ft=ie.get(ee.id),dt=ft!=null?ft:Ye(ze);ee.rawContent=dt;let Dt=J.get(ee.id),_t=null,fr=!1;if(Dt&&(_t=Dt.getExtractedText(),_t===null&&(_t=Ko(dt)),_t===null)){let St=Dt.processChunk(dt);St instanceof Promise?(fr=!0,St.then(Ot=>{var Rr;let yr=typeof Ot=="string"?Ot:(Rr=Ot==null?void 0:Ot.text)!=null?Rr:null;if(yr!==null){let Er=f;Er&&Er.id===ee.id&&(Er.content=yr,Er.streaming=!1,J.delete(Er.id),ie.delete(Er.id),p(Er))}})):_t=typeof St=="string"?St:(Hn=St==null?void 0:St.text)!=null?Hn:null}if(!fr){_t!==null&&_t.trim()!==""?ee.content=_t:ie.has(ee.id)||(ee.content=Ye(ze));let St=J.get(ee.id);if(St){let Ot=(Gn=St.close)==null?void 0:Gn.call(St);Ot instanceof Promise&&Ot.catch(()=>{}),J.delete(ee.id)}ie.delete(ee.id),ee.streaming=!1,p(ee)}}}}else if(Ze==="step_complete"){let _=L.stepType,I=L.executionType;if(_==="tool"||I==="context")continue;let Q=L.toolContext;if(Q!=null&&Q.toolId){let ze=String((_s=(Io=L.id)!=null?Io:Q.stepId)!=null?_s:"");if(ze){let ft=H(Q.toolId,ze);for(let[dt,Dt]of E)dt.startsWith(ft)&&Dt.streaming!==!1&&(Dt.streaming=!1,p(Dt));v.delete(`${Q.toolId}::${ze}`)}continue}let le=L.stopReason;if(k){if(f!==null){let dt=f;le&&(dt.stopReason=le),J.delete(dt.id),ie.delete(dt.id),dt.streaming!==!1&&(dt.streaming=!1,p(dt))}let ze=(Na=L.result)==null?void 0:Na.response,ft=j;ft&&(le&&(ft.stopReason=le),ze!=null?De(ft,ze):(J.delete(ft.id),ie.delete(ft.id))),j=null;continue}let ee=($s=L.result)==null?void 0:$s.response,et=We();if(le&&(et.stopReason=le),ee!=null){let ze=J.get(et.id),ft=!1,dt=!1;if(ze){let Dt=ze.getExtractedText(),_t=ie.get(et.id),fr=_t!=null?_t:Ye(ee);if(et.rawContent=fr,Dt!==null&&Dt.trim()!=="")et.content=Dt,ft=!0;else{let St=Ko(fr);if(St!==null)et.content=St,ft=!0;else{let Ot=ze.processChunk(fr);if(Ot instanceof Promise)dt=!0,Ot.then(yr=>{var Er;let Rr=typeof yr=="string"?yr:(Er=yr==null?void 0:yr.text)!=null?Er:null;if(Rr!==null&&Rr.trim()!==""){let Xt=f;Xt&&Xt.id===et.id&&(Xt.content=Rr,Xt.streaming=!1,J.delete(Xt.id),ie.delete(Xt.id),p(Xt))}else{let Xt=ze.getExtractedText(),Qr=f;Qr&&Qr.id===et.id&&(Xt!==null&&Xt.trim()!==""?Qr.content=Xt:ie.has(Qr.id)||(Qr.content=Ye(ee)),Qr.streaming=!1,J.delete(Qr.id),ie.delete(Qr.id),p(Qr))}});else{let yr=typeof Ot=="string"?Ot:(la=Ot==null?void 0:Ot.text)!=null?la:null;if(yr!==null&&yr.trim()!=="")et.content=yr,ft=!0;else{let Rr=ze.getExtractedText();Rr!==null&&Rr.trim()!==""&&(et.content=Rr,ft=!0)}}}}}if(!dt){if(!et.rawContent){let Dt=ie.get(et.id);et.rawContent=Dt!=null?Dt:Ye(ee)}if(!ft&&!ie.has(et.id)&&(et.content=Ye(ee)),ze){let Dt=(wt=ze.close)==null?void 0:wt.call(ze);Dt instanceof Promise&&Dt.catch(()=>{})}J.delete(et.id),ie.delete(et.id),et.streaming=!1,p(et)}}else J.delete(et.id),ie.delete(et.id),et.streaming=!1,p(et)}else if(Ze==="flow_complete"){let _=(_a=L.result)==null?void 0:_a.response;if(k){if(f!==null){let I=f;J.delete(I.id),ie.delete(I.id),I.streaming!==!1&&(I.streaming=!1,p(I))}}else if(_!=null){let I=We(),Q=ie.get(I.id),le=Q!=null?Q:Ye(_);I.rawContent=le;let ee=Ye(_),et=J.get(I.id);if(et){let dt=Ko(le);if(dt!==null)ee=dt;else{let Dt=et.processChunk(le);Dt instanceof Promise&&Dt.then(fr=>{var Ot;let St=typeof fr=="string"?fr:(Ot=fr==null?void 0:fr.text)!=null?Ot:null;St!==null&&(I.content=St,I.streaming=!1,p(I))});let _t=et.getExtractedText();_t!==null&&(ee=_t)}}J.delete(I.id),ie.delete(I.id);let ze=ee!==I.content,ft=I.streaming!==!1;ze&&(I.content=ee),I.streaming=!1,(ze||ft)&&p(I)}else if(f!==null){let I=f;J.delete(I.id),ie.delete(I.id),I.streaming!==!1&&(I.streaming=!1,p(I))}t({type:"status",status:"idle"})}else if(Ze==="agent_start")ae={executionId:L.executionId,agentId:(bn=L.agentId)!=null?bn:"virtual",agentName:(Yr=L.agentName)!=null?Yr:"",status:"running",currentIteration:0,maxTurns:(Us=L.maxTurns)!=null?Us:1,startedAt:He(L.startedAt)};else if(Ze==="agent_iteration_start"){if(ae&&(ae.currentIteration=L.iteration),Ut==="separate"&&L.iteration>1){let _=f;_&&(_.streaming=!1,p(_),ur.set(L.iteration-1,_),f=null)}}else if(Ze==="agent_turn_start")m=null;else if(Ze==="agent_turn_delta"){if(L.contentType==="text"){let _=We();_.content+=(qs=L.delta)!=null?qs:"",_.agentMetadata={executionId:L.executionId,iteration:L.iteration,turnId:L.turnId,agentName:ae==null?void 0:ae.agentName},m=_,p(_)}else if(L.contentType==="thinking"){let _=(da=L.turnId)!=null?da:`agent-think-${L.iteration}`,I=me(_);I.reasoning=(Xn=I.reasoning)!=null?Xn:{id:_,status:"streaming",chunks:[]},I.reasoning.chunks.push((zs=L.delta)!=null?zs:""),I.agentMetadata={executionId:L.executionId,iteration:L.iteration,turnId:L.turnId},p(I)}else if(L.contentType==="tool_input"){let _=(Ro=L.toolCallId)!=null?Ro:y.lastId;if(_){let I=S.get(_);I!=null&&I.toolCall&&(I.toolCall.chunks=($a=I.toolCall.chunks)!=null?$a:[],I.toolCall.chunks.push((Jn=L.delta)!=null?Jn:""),p(I))}}}else if(Ze==="agent_turn_complete"){let _=L.turnId;if(_){let le=T.get(_);if(le!=null&&le.reasoning){le.reasoning.status="complete",le.reasoning.completedAt=He(L.completedAt);let ee=(Ua=le.reasoning.startedAt)!=null?Ua:Date.now();le.reasoning.durationMs=Math.max(0,((fo=le.reasoning.completedAt)!=null?fo:Date.now())-ee),le.streaming=!1,p(le)}}let I=L.stopReason,Q=f!=null?f:m;if(I&&Q!==null){let le=L.turnId;(!le||((mo=Q.agentMetadata)==null?void 0:mo.turnId)===le)&&(Q.stopReason=I,p(Q))}}else if(Ze==="agent_tool_start"){f&&(f.streaming=!1,p(f),f=null);let _=(Vs=L.toolCallId)!=null?Vs:`agent-tool-${l()}`;Re(V(L),_);let I=pe(_),Q=(js=I.toolCall)!=null?js:{id:_,status:"pending",name:void 0,args:void 0,chunks:void 0,result:void 0,duration:void 0,startedAt:void 0,completedAt:void 0,durationMs:void 0};Q.name=(Ho=(Hl=L.toolName)!=null?Hl:L.name)!=null?Ho:Q.name,Q.status="running",L.parameters!==void 0&&(Q.args=L.parameters),Q.startedAt=He((go=L.startedAt)!=null?go:L.timestamp),I.toolCall=Q,I.streaming=!0,I.agentMetadata={executionId:L.executionId,iteration:L.iteration},p(I)}else if(Ze==="agent_tool_delta"){let _=(Gs=L.toolCallId)!=null?Gs:y.lastId;if(_){let I=(qa=S.get(_))!=null?qa:pe(_);I.toolCall&&(I.toolCall.chunks=(ho=I.toolCall.chunks)!=null?ho:[],I.toolCall.chunks.push((Xs=L.delta)!=null?Xs:""),I.toolCall.status="running",I.streaming=!0,p(I))}}else if(Ze==="agent_tool_complete"){let _=(za=L.toolCallId)!=null?za:y.lastId;if(_){let I=(xo=S.get(_))!=null?xo:pe(_);if(I.toolCall){I.toolCall.status="complete",L.result!==void 0&&(I.toolCall.result=L.result),typeof L.executionTime=="number"&&(I.toolCall.durationMs=L.executionTime),I.toolCall.completedAt=He((Va=L.completedAt)!=null?Va:L.timestamp),I.streaming=!1,p(I);let Q=V(L);Q&&y.byCall.delete(Q)}}}else if(Ze==="agent_media"){let _=Array.isArray(L.media)?L.media:[],I=[];for(let Q of _){if(!Q||typeof Q!="object")continue;let le=Q,ee=typeof le.type=="string"?le.type:void 0,et=typeof le.mediaType=="string"?le.mediaType.toLowerCase():"",ze=null,ft="";if(ee==="media"){let dt=typeof le.data=="string"?le.data:void 0;if(!dt)continue;ft=et.length>0?et:"application/octet-stream",ze=`data:${ft};base64,${dt}`}else if(ee==="image-url"){let dt=typeof le.url=="string"?le.url:void 0;if(!dt)continue;ft=et,ze=dt}else if(ee==="file-url"){let dt=typeof le.url=="string"?le.url:void 0;if(!dt)continue;ft=et,ze=dt}else continue;if(ze)if(ee==="image-url"||ft.startsWith("image/"))I.push({type:"image",image:ze,...ft?{mimeType:ft}:{}});else if(ft.startsWith("audio/"))I.push({type:"audio",audio:ze,mimeType:ft});else if(ft.startsWith("video/"))I.push({type:"video",video:ze,mimeType:ft});else{let dt=ft||"application/octet-stream";I.push({type:"file",data:ze,mimeType:dt,filename:sb(dt)})}}if(I.length>0){let Q=l(),le=L.toolCallId,et={id:`agent-media-${typeof le=="string"&&le.length>0?`${le}-${Q}`:String(Q)}`,role:"assistant",content:"",contentParts:I,createdAt:new Date().toISOString(),streaming:!1,sequence:Q,agentMetadata:{executionId:L.executionId,iteration:L.iteration}};p(et);let ze=f;ze&&(ze.streaming=!1,p(ze)),f=null,C.current=null}}else if(Ze!=="agent_iteration_complete"){if(Ze==="agent_reflection"||Ze==="agent_reflect"){let _=`agent-reflection-${L.executionId}-${L.iteration}`,I={id:_,role:"assistant",content:(Js=L.reflection)!=null?Js:"",createdAt:new Date().toISOString(),streaming:!1,variant:"reasoning",sequence:l(),reasoning:{id:_,status:"complete",chunks:[(Kn=L.reflection)!=null?Kn:""]},agentMetadata:{executionId:L.executionId,iteration:L.iteration}};p(I)}else if(Ze==="agent_complete"){ae&&(ae.status=L.success?"complete":"error",ae.completedAt=He(L.completedAt),ae.stopReason=L.stopReason);let _=f;_&&(_.streaming=!1,p(_)),t({type:"status",status:"idle"})}else if(Ze==="agent_error"){let _=typeof L.error=="string"?L.error:(yo=(Ks=L.error)==null?void 0:Ks.message)!=null?yo:"Agent execution error";L.recoverable?typeof console!="undefined"&&console.warn("[AgentWidget] Recoverable agent error:",_):t({type:"error",error:new Error(_)})}else if(Ze!=="agent_ping"){if(Ze==="agent_approval_start"){let _=(qt=L.approvalId)!=null?qt:`approval-${l()}`,I={id:`approval-${_}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!1,variant:"approval",sequence:l(),approval:{id:_,status:"pending",agentId:(ca=ae==null?void 0:ae.agentId)!=null?ca:"virtual",executionId:(ja=(pa=L.executionId)!=null?pa:ae==null?void 0:ae.executionId)!=null?ja:"",toolName:(_n=L.toolName)!=null?_n:"",toolType:L.toolType,description:(Ga=L.description)!=null?Ga:`Execute ${(Ys=L.toolName)!=null?Ys:"tool"}`,parameters:L.parameters}};p(I)}else if(Ze==="step_await"&&L.awaitReason==="approval_required"){let _=(Xa=L.approvalId)!=null?Xa:`approval-${l()}`,I={id:`approval-${_}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!1,variant:"approval",sequence:l(),approval:{id:_,status:"pending",agentId:(Ja=ae==null?void 0:ae.agentId)!=null?Ja:"virtual",executionId:(_r=(Ka=L.executionId)!=null?Ka:ae==null?void 0:ae.executionId)!=null?_r:"",toolName:(dn=L.toolName)!=null?dn:"",toolType:L.toolType,description:(ut=L.description)!=null?ut:`Execute ${(Yn=L.toolName)!=null?Yn:"tool"}`,parameters:L.parameters}};p(I)}else if(Ze==="agent_approval_complete"){let _=L.approvalId;if(_){let Q={id:`approval-${_}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!1,variant:"approval",sequence:l(),approval:{id:_,status:(Ya=L.decision)!=null?Ya:"approved",agentId:(Bo=ae==null?void 0:ae.agentId)!=null?Bo:"virtual",executionId:(Qs=(Bn=L.executionId)!=null?Bn:ae==null?void 0:ae.executionId)!=null?Qs:"",toolName:(ua=L.toolName)!=null?ua:"",description:(fa=L.description)!=null?fa:"",resolvedAt:Date.now()}};p(Q)}}else if(Ze==="artifact_start"||Ze==="artifact_delta"||Ze==="artifact_update"||Ze==="artifact_complete"){if(Ze==="artifact_start"){let _=L.artifactType,I=String(L.id),Q=typeof L.title=="string"?L.title:void 0;if(t({type:"artifact_start",id:I,artifactType:_,title:Q,component:typeof L.component=="string"?L.component:void 0}),G.set(I,{markdown:"",title:Q}),!Ee.has(I)){Ee.add(I);let le={id:`artifact-ref-${I}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,sequence:l(),rawContent:JSON.stringify({component:"PersonaArtifactCard",props:{artifactId:I,title:Q,artifactType:_,status:"streaming"}})};Y.set(I,le),p(le)}}else if(Ze==="artifact_delta"){let _=String(L.id),I=typeof L.delta=="string"?L.delta:String((Wo=L.delta)!=null?Wo:"");t({type:"artifact_delta",id:_,artDelta:I});let Q=G.get(_);Q&&(Q.markdown+=I)}else if(Ze==="artifact_update"){let _=L.props&&typeof L.props=="object"&&!Array.isArray(L.props)?L.props:{};t({type:"artifact_update",id:String(L.id),props:_,component:typeof L.component=="string"?L.component:void 0})}else if(Ze==="artifact_complete"){let _=String(L.id);t({type:"artifact_complete",id:_});let I=Y.get(_);if(I){I.streaming=!1;try{let Q=JSON.parse((bo=I.rawContent)!=null?bo:"{}");if(Q.props){Q.props.status="complete";let le=G.get(_);le!=null&&le.markdown&&(Q.props.markdown=le.markdown)}I.rawContent=JSON.stringify(Q)}catch{}G.delete(_),p(I),Y.delete(_)}}}else if(Ze==="transcript_insert"){let _=L.message;if(!_||typeof _!="object")continue;let I=String((Zs=_.id)!=null?Zs:`msg-${l()}`),Q=_.role,ee={id:I,role:Q==="user"?"user":Q==="system"?"system":"assistant",content:typeof _.content=="string"?_.content:"",rawContent:typeof _.rawContent=="string"?_.rawContent:void 0,createdAt:typeof _.createdAt=="string"?_.createdAt:new Date().toISOString(),streaming:_.streaming===!0,...typeof _.variant=="string"?{variant:_.variant}:{},sequence:l()};if(p(ee),ee.rawContent)try{let et=JSON.parse(ee.rawContent),ze=(ei=et==null?void 0:et.props)==null?void 0:ei.artifactId;typeof ze=="string"&&Ee.add(ze)}catch{}f=null,C.current=null,J.delete(I),ie.delete(I)}else if(Ze==="error"||Ze==="step_error"||Ze==="dispatch_error"||Ze==="flow_error"){let _=null;if(L.error instanceof Error)_=L.error;else if(Ze==="dispatch_error"){let I=(Wn=L.message)!=null?Wn:L.error;I!=null&&I!==""&&(_=new Error(String(I)))}else if(Ze==="step_error"||Ze==="flow_error"){let I=L.error;typeof I=="string"&&I!==""?_=new Error(I):I!=null&&typeof I=="object"&&"message"in I&&(_=new Error(String((Do=I.message)!=null?Do:I)))}else Ze==="error"&&L.error!=null&&L.error!==""&&(_=new Error(String(L.error)));if(_){t({type:"error",error:_});let I=f;I&&I.streaming&&(I.streaming=!1,p(I)),t({type:"status",status:"idle"})}}}}}oe.length=0};;){let{done:q,value:Te}=await o.read();if(q)break;s+=a.decode(Te,{stream:!0});let _e=s.split(`
|
|
51
|
+
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}catch{return i[1]}return null};return{getExtractedText:()=>e,processChunk:async n=>{if(n.length<=r)return e!==null?{text:e,raw:n}:null;let o=n.trim();if(!o.startsWith("{")&&!o.startsWith("["))return null;let a=t(n);return a!==null&&(e=a),r=n.length,e!==null?{text:e,raw:n}:null},close:async()=>{}}},Ko=e=>{try{let r=JSON.parse(e);if(r&&typeof r=="object"&&typeof r.text=="string")return r.text}catch{return null}return null},wi=()=>{let e={processChunk:r=>null,getExtractedText:()=>null};return e.__isPlainTextParser=!0,e},vi=()=>{var r;let e=ob();return{processChunk:async t=>{let n=t.trim();return!n.startsWith("{")&&!n.startsWith("[")?null:e.processChunk(t)},getExtractedText:e.getExtractedText.bind(e),close:(r=e.close)==null?void 0:r.bind(e)}},Ai=()=>{let e=null,r=0;return{getExtractedText:()=>e,processChunk:t=>{let n=t.trim();if(!n.startsWith("{")&&!n.startsWith("["))return null;if(t.length<=r)return e!==null||e===""?{text:e||"",raw:t}:null;try{let o=(0,ro.parse)(t,ro.STR|ro.OBJ);o&&typeof o=="object"&&(o.component&&typeof o.component=="string"?e=typeof o.text=="string"?xi(o.text):"":o.type==="init"&&o.form?e="":typeof o.text=="string"&&(e=xi(o.text)))}catch{}return r=t.length,e!==null?{text:e,raw:t}:null},close:()=>{}}},Lg=e=>{let r=null,t=0,o=e||(a=>{if(!a||typeof a!="object")return null;let s=i=>typeof i=="string"?xi(i):null;if(a.component&&typeof a.component=="string")return typeof a.text=="string"?xi(a.text):"";if(a.type==="init"&&a.form)return"";if(a.action)switch(a.action){case"nav_then_click":return s(a.on_load_text)||s(a.text)||null;case"message":case"message_and_click":case"checkout":return s(a.text)||null;default:return s(a.text)||s(a.display_text)||s(a.message)||null}return s(a.text)||s(a.display_text)||s(a.message)||s(a.content)||null});return{getExtractedText:()=>r,processChunk:a=>{let s=a.trim();if(!s.startsWith("{")&&!s.startsWith("["))return null;if(a.length<=t)return r!==null?{text:r,raw:a}:null;try{let i=(0,ro.parse)(a,ro.STR|ro.OBJ),d=o(i);d!==null&&(r=d)}catch{}return t=a.length,{text:r||"",raw:a}},close:()=>{}}},Si=()=>{let e=null;return{processChunk:r=>{if(!r.trim().startsWith("<"))return null;let n=r.match(/<text[^>]*>([\s\S]*?)<\/text>/);return n&&n[1]?(e=n[1],{text:e,raw:r}):null},getExtractedText:()=>e}};var Ti=class{constructor(r,t=50){this.nextExpectedSeq=null;this.buffer=new Map;this.flushTimer=null;this.emitter=r,this.gapTimeoutMs=t}push(r,t){var a,s,i;let n=(i=(a=t==null?void 0:t.seq)!=null?a:t==null?void 0:t.sequenceIndex)!=null?i:(s=t==null?void 0:t.agentContext)==null?void 0:s.seq;if(n==null){this.buffer.size>0&&this.flushAll(),this.emitter(r,t);return}if(this.nextExpectedSeq===null&&(this.nextExpectedSeq=1),n===this.nextExpectedSeq){this.emitter(r,t),this.nextExpectedSeq=n+1,this.drainConsecutive();return}if(n<this.nextExpectedSeq){this.emitter(r,t);return}let o=this.buffer.get(n);o!==void 0&&(typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(`[persona] SequenceReorderBuffer: duplicate seq=${n} (${o.payloadType} vs ${r}); emitting earlier event out-of-order to avoid loss`),this.emitter(o.payloadType,o.payload)),this.buffer.set(n,{payloadType:r,payload:t,seq:n}),this.startGapTimer()}drainConsecutive(){for(;this.buffer.has(this.nextExpectedSeq);){let r=this.buffer.get(this.nextExpectedSeq);this.buffer.delete(this.nextExpectedSeq),this.emitter(r.payloadType,r.payload),this.nextExpectedSeq++}this.buffer.size===0&&this.clearGapTimer()}startGapTimer(){this.flushTimer===null&&(this.flushTimer=setTimeout(()=>{this.flushAll()},this.gapTimeoutMs))}clearGapTimer(){this.flushTimer!==null&&(clearTimeout(this.flushTimer),this.flushTimer=null)}flushAll(){if(this.clearGapTimer(),this.buffer.size===0)return;let r=[...this.buffer.entries()].sort((t,n)=>t[0]-n[0]);for(let[t,n]of r)this.buffer.delete(t),this.emitter(n.payloadType,n.payload);r.length>0&&(this.nextExpectedSeq=r[r.length-1][0]+1)}destroy(){this.clearGapTimer(),this.buffer.clear()}flushPending(){this.flushAll()}};var ab="https://api.runtype.com/v1/dispatch",ki="https://api.runtype.com";function sb(e){var a,s;let r=e.toLowerCase(),n={"application/pdf":"pdf","application/json":"json","application/zip":"zip","text/plain":"txt","text/csv":"csv","text/markdown":"md"}[r];if(n)return`attachment.${n}`;let o=r.indexOf("/");if(o>0){let i=(s=(a=r.slice(o+1).split(";")[0])==null?void 0:a.trim())!=null?s:"";if(i&&i!=="octet-stream"&&/^[a-z0-9.+-]+$/i.test(i))return`attachment.${i}`}return"attachment"}var td=e=>!!(e.contentParts&&e.contentParts.length>0||e.llmContent&&e.llmContent.trim().length>0||e.rawContent&&e.rawContent.trim().length>0||e.content&&e.content.trim().length>0);function ib(e){switch(e){case"json":return Ai;case"regex-json":return vi;case"xml":return Si;default:return wi}}var Pg=e=>e.startsWith("{")||e.startsWith("[")||e.startsWith("<");function lb(e,r){if(!e)return r;let t=e.trim(),n=r.trim();if(t.length===0)return r;if(n.length===0)return e;let o=Pg(t);if(!Pg(n))return e;if(!o||n===t||n.startsWith(t))return r;let s=Ko(e);return Ko(r)!==null&&s===null?r:e}var Yo=class{constructor(r={}){this.config=r;this.clientSession=null;this.sessionInitPromise=null;var t,n,o;this.apiUrl=(t=r.apiUrl)!=null?t:ab,this.headers={"Content-Type":"application/json",...r.headers},this.debug=!!r.debug,this.createStreamParser=(n=r.streamParser)!=null?n:ib(r.parserType),this.contextProviders=(o=r.contextProviders)!=null?o:[],this.requestMiddleware=r.requestMiddleware,this.customFetch=r.customFetch,this.parseSSEEvent=r.parseSSEEvent,this.getHeaders=r.getHeaders}setSSEEventCallback(r){this.onSSEEvent=r}getSSEEventCallback(){return this.onSSEEvent}isClientTokenMode(){return!!this.config.clientToken}isAgentMode(){return!!this.config.agent}getClientApiUrl(r){var n;let t=((n=this.config.apiUrl)==null?void 0:n.replace(/\/+$/,"").replace(/\/v1\/dispatch$/,""))||ki;return r==="init"?`${t}/v1/client/init`:`${t}/v1/client/chat`}getClientSession(){return this.clientSession}async initSession(){var r,t;if(!this.isClientTokenMode())throw new Error("initSession() only available in client token mode");if(this.clientSession&&new Date<this.clientSession.expiresAt)return this.clientSession;if(this.sessionInitPromise)return this.sessionInitPromise;this.sessionInitPromise=this._doInitSession();try{let n=await this.sessionInitPromise;return this.clientSession=n,(t=(r=this.config).onSessionInit)==null||t.call(r,n),n}finally{this.sessionInitPromise=null}}async _doInitSession(){var a,s;let r=((s=(a=this.config).getStoredSessionId)==null?void 0:s.call(a))||null,t={token:this.config.clientToken,...this.config.flowId&&{flowId:this.config.flowId},...r&&{sessionId:r}},n=await fetch(this.getClientApiUrl("init"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok){let i=await n.json().catch(()=>({error:"Session initialization failed"}));throw n.status===401?new Error(`Invalid client token: ${i.hint||i.error}`):n.status===403?new Error(`Origin not allowed: ${i.hint||i.error}`):new Error(i.error||"Failed to initialize session")}let o=await n.json();return this.config.setStoredSessionId&&this.config.setStoredSessionId(o.sessionId),{sessionId:o.sessionId,expiresAt:new Date(o.expiresAt),flow:o.flow,config:{welcomeMessage:o.config.welcomeMessage,placeholder:o.config.placeholder,theme:o.config.theme}}}clearClientSession(){this.clientSession=null,this.sessionInitPromise=null}getFeedbackApiUrl(){var t;return`${((t=this.config.apiUrl)==null?void 0:t.replace(/\/+$/,"").replace(/\/v1\/dispatch$/,""))||ki}/v1/client/feedback`}async sendFeedback(r){var a,s;if(!this.isClientTokenMode())throw new Error("sendFeedback() only available in client token mode");if(!this.getClientSession())throw new Error("No active session. Please initialize session first.");if(["upvote","downvote","copy"].includes(r.type)&&!r.messageId)throw new Error(`messageId is required for ${r.type} feedback type`);if(r.type==="csat"&&(r.rating===void 0||r.rating<1||r.rating>5))throw new Error("CSAT rating must be between 1 and 5");if(r.type==="nps"&&(r.rating===void 0||r.rating<0||r.rating>10))throw new Error("NPS rating must be between 0 and 10");this.debug&&console.debug("[AgentWidgetClient] sending feedback",r);let o=await fetch(this.getFeedbackApiUrl(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!o.ok){let i=await o.json().catch(()=>({error:"Feedback submission failed"}));throw o.status===401?(this.clientSession=null,(s=(a=this.config).onSessionExpired)==null||s.call(a),new Error("Session expired. Please refresh to continue.")):new Error(i.error||"Failed to submit feedback")}}async submitMessageFeedback(r,t){let n=this.getClientSession();if(!n)throw new Error("No active session. Please initialize session first.");return this.sendFeedback({sessionId:n.sessionId,messageId:r,type:t})}async submitCSATFeedback(r,t){let n=this.getClientSession();if(!n)throw new Error("No active session. Please initialize session first.");return this.sendFeedback({sessionId:n.sessionId,type:"csat",rating:r,comment:t})}async submitNPSFeedback(r,t){let n=this.getClientSession();if(!n)throw new Error("No active session. Please initialize session first.");return this.sendFeedback({sessionId:n.sessionId,type:"nps",rating:r,comment:t})}async dispatch(r,t){return this.isAgentMode()?this.dispatchAgent(r,t):this.isClientTokenMode()?this.dispatchClientToken(r,t):this.dispatchProxy(r,t)}async dispatchClientToken(r,t){var o,a,s,i;let n=new AbortController;r.signal&&r.signal.addEventListener("abort",()=>n.abort()),t({type:"status",status:"connecting"});try{let d=await this.initSession();if(new Date>=new Date(d.expiresAt.getTime()-6e4)){this.clientSession=null,(a=(o=this.config).onSessionExpired)==null||a.call(o);let m=new Error("Session expired. Please refresh to continue.");throw t({type:"error",error:m}),m}let l=await this.buildPayload(r.messages),u=l.metadata?Object.fromEntries(Object.entries(l.metadata).filter(([m])=>m!=="sessionId"&&m!=="session_id")):void 0,p={sessionId:d.sessionId,messages:r.messages.filter(td).map(m=>{var C,A,k;return{id:m.id,role:m.role,content:(k=(A=(C=m.contentParts)!=null?C:m.llmContent)!=null?A:m.rawContent)!=null?k:m.content}}),...r.assistantMessageId&&{assistantMessageId:r.assistantMessageId},...u&&Object.keys(u).length>0&&{metadata:u},...l.inputs&&Object.keys(l.inputs).length>0&&{inputs:l.inputs},...l.context&&{context:l.context}};this.debug&&console.debug("[AgentWidgetClient] client token dispatch",p);let f=await fetch(this.getClientApiUrl("chat"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p),signal:n.signal});if(!f.ok){let m=await f.json().catch(()=>({error:"Chat request failed"}));if(f.status===401){this.clientSession=null,(i=(s=this.config).onSessionExpired)==null||i.call(s);let A=new Error("Session expired. Please refresh to continue.");throw t({type:"error",error:A}),A}if(f.status===429){let A=new Error(m.hint||"Message limit reached for this session.");throw t({type:"error",error:A}),A}let C=new Error(m.error||"Failed to send message");throw t({type:"error",error:C}),C}if(!f.body){let m=new Error("No response body received");throw t({type:"error",error:m}),m}t({type:"status",status:"connected"});try{await this.streamResponse(f.body,t,r.assistantMessageId)}finally{t({type:"status",status:"idle"})}}catch(d){let l=d instanceof Error?d:new Error(String(d));throw!l.message.includes("Session expired")&&!l.message.includes("Message limit")&&t({type:"error",error:l}),l}}async dispatchProxy(r,t){let n=new AbortController;r.signal&&r.signal.addEventListener("abort",()=>n.abort()),t({type:"status",status:"connecting"});let o=await this.buildPayload(r.messages);this.debug&&console.debug("[AgentWidgetClient] dispatch payload",o);let a={...this.headers};if(this.getHeaders)try{let i=await this.getHeaders();a={...a,...i}}catch(i){typeof console!="undefined"&&console.error("[AgentWidget] getHeaders error:",i)}let s;if(this.customFetch)try{s=await this.customFetch(this.apiUrl,{method:"POST",headers:a,body:JSON.stringify(o),signal:n.signal},o)}catch(i){let d=i instanceof Error?i:new Error(String(i));throw t({type:"error",error:d}),d}else s=await fetch(this.apiUrl,{method:"POST",headers:a,body:JSON.stringify(o),signal:n.signal});if(!s.ok||!s.body){let i=new Error(`Chat backend request failed: ${s.status} ${s.statusText}`);throw t({type:"error",error:i}),i}t({type:"status",status:"connected"});try{await this.streamResponse(s.body,t)}finally{t({type:"status",status:"idle"})}}async dispatchAgent(r,t){let n=new AbortController;r.signal&&r.signal.addEventListener("abort",()=>n.abort()),t({type:"status",status:"connecting"});let o=await this.buildAgentPayload(r.messages);this.debug&&console.debug("[AgentWidgetClient] agent dispatch payload",o);let a={...this.headers};if(this.getHeaders)try{let i=await this.getHeaders();a={...a,...i}}catch(i){typeof console!="undefined"&&console.error("[AgentWidget] getHeaders error:",i)}let s;if(this.customFetch)try{s=await this.customFetch(this.apiUrl,{method:"POST",headers:a,body:JSON.stringify(o),signal:n.signal},o)}catch(i){let d=i instanceof Error?i:new Error(String(i));throw t({type:"error",error:d}),d}else s=await fetch(this.apiUrl,{method:"POST",headers:a,body:JSON.stringify(o),signal:n.signal});if(!s.ok||!s.body){let i=new Error(`Agent execution request failed: ${s.status} ${s.statusText}`);throw t({type:"error",error:i}),i}t({type:"status",status:"connected"});try{await this.streamResponse(s.body,t,r.assistantMessageId)}finally{t({type:"status",status:"idle"})}}async processStream(r,t,n){t({type:"status",status:"connected"});try{await this.streamResponse(r,t,n)}finally{t({type:"status",status:"idle"})}}async resolveApproval(r,t){var s;let o=`${((s=this.config.apiUrl)==null?void 0:s.replace(/\/+$/,"").replace(/\/v1\/dispatch$/,""))||ki}/v1/agents/${r.agentId}/approve`,a={"Content-Type":"application/json",...this.headers};return this.getHeaders&&Object.assign(a,await this.getHeaders()),fetch(o,{method:"POST",headers:a,body:JSON.stringify({executionId:r.executionId,approvalId:r.approvalId,decision:t,streamResponse:!0})})}async resumeFlow(r,t,n){var i,d;let a=`${((i=this.config.apiUrl)==null?void 0:i.replace(/\/+$/,""))||ki}/resume`,s={"Content-Type":"application/json",...this.headers};return this.getHeaders&&Object.assign(s,await this.getHeaders()),fetch(a,{method:"POST",headers:s,body:JSON.stringify({executionId:r,toolOutputs:t,streamResponse:(d=n==null?void 0:n.streamResponse)!=null?d:!0})})}async buildAgentPayload(r){if(!this.config.agent)throw new Error("Agent configuration required for agent mode");let t=r.slice().filter(td).filter(o=>o.role==="user"||o.role==="assistant"||o.role==="system").filter(o=>!o.variant||o.variant==="assistant").sort((o,a)=>{let s=new Date(o.createdAt).getTime(),i=new Date(a.createdAt).getTime();return s-i}).map(o=>{var a,s,i;return{role:o.role,content:(i=(s=(a=o.contentParts)!=null?a:o.llmContent)!=null?s:o.rawContent)!=null?i:o.content,createdAt:o.createdAt}}),n={agent:this.config.agent,messages:t,options:{streamResponse:!0,recordMode:"virtual",...this.config.agentOptions}};if(this.contextProviders.length){let o={};await Promise.all(this.contextProviders.map(async a=>{try{let s=await a({messages:r,config:this.config});s&&typeof s=="object"&&Object.assign(o,s)}catch(s){typeof console!="undefined"&&console.warn("[AgentWidget] Context provider failed:",s)}})),Object.keys(o).length&&(n.context=o)}return n}async buildPayload(r){let n={messages:r.slice().filter(td).sort((o,a)=>{let s=new Date(o.createdAt).getTime(),i=new Date(a.createdAt).getTime();return s-i}).map(o=>{var a,s,i;return{role:o.role,content:(i=(s=(a=o.contentParts)!=null?a:o.llmContent)!=null?s:o.rawContent)!=null?i:o.content,createdAt:o.createdAt}}),...this.config.flowId&&{flowId:this.config.flowId}};if(this.contextProviders.length){let o={};await Promise.all(this.contextProviders.map(async a=>{try{let s=await a({messages:r,config:this.config});s&&typeof s=="object"&&Object.assign(o,s)}catch(s){typeof console!="undefined"&&console.warn("[AgentWidget] Context provider failed:",s)}})),Object.keys(o).length&&(n.context=o)}if(this.requestMiddleware)try{let o=await this.requestMiddleware({payload:{...n},config:this.config});if(o&&typeof o=="object")return o}catch(o){typeof console!="undefined"&&console.error("[AgentWidget] Request middleware error:",o)}return n}async handleCustomSSEEvent(r,t,n,o,a,s){if(!this.parseSSEEvent)return!1;try{let i=await this.parseSSEEvent(r);if(i===null)return!1;let d=u=>{let p={id:`assistant-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"assistant",sequence:a(),...u!==void 0&&{partId:u}};return n.current=p,o(p),p},l=u=>n.current?n.current:d(u);if(i.text!==void 0){i.partId!==void 0&&s.current!==null&&i.partId!==s.current&&(n.current&&(n.current.streaming=!1,o(n.current)),d(i.partId)),i.partId!==void 0&&(s.current=i.partId);let u=l(i.partId);i.partId!==void 0&&!u.partId&&(u.partId=i.partId),u.content+=i.text,o(u)}return i.done&&(n.current&&(n.current.streaming=!1,o(n.current)),s.current=null,t({type:"status",status:"idle"})),i.error&&(s.current=null,t({type:"error",error:new Error(i.error)})),!0}catch(i){return typeof console!="undefined"&&console.error("[AgentWidget] parseSSEEvent error:",i),!1}}async streamResponse(r,t,n){var Qt,Or,vr,Oe;let o=r.getReader(),a=new TextDecoder,s="",i=Date.now(),d=0,l=()=>i+d++,u=q=>{let Te=q.reasoning?{...q.reasoning,chunks:[...q.reasoning.chunks]}:void 0,_e=q.toolCall?{...q.toolCall,chunks:q.toolCall.chunks?[...q.toolCall.chunks]:void 0}:void 0,Ne=q.tools?q.tools.map(qe=>({...qe,chunks:qe.chunks?[...qe.chunks]:void 0})):void 0;return{...q,reasoning:Te,toolCall:_e,tools:Ne}},p=q=>{t({type:"message",message:u(q)})},f=null,m=null,C={current:null},A={current:null},k=!1,T=new Map,S=new Map,E=new Map,w=new Map,b={lastId:null,byStep:new Map},y={lastId:null,byCall:new Map},M=(q,Te,_e="")=>`${q}::${Te}::${_e}`,H=(q,Te)=>`${q}::${Te}::`,B=(q,Te,_e,Ne)=>{let qe=M(q,Te,_e),st=E.get(qe);if(st)return st;let nt=_e?`-${_e}`:"",pt={id:`nested-${q}-${Te}${nt}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,sequence:l(),..._e?{partId:_e}:{},agentMetadata:{executionId:Ne,parentToolId:q,parentStepId:Te}};return E.set(qe,pt),p(pt),pt},R=q=>{if(q==null)return null;try{return String(q)}catch{return null}},W=q=>{var Te,_e,Ne,qe,st;return R((st=(qe=(Ne=(_e=(Te=q.stepId)!=null?Te:q.step_id)!=null?_e:q.step)!=null?Ne:q.parentId)!=null?qe:q.flowStepId)!=null?st:q.flow_step_id)},V=q=>{var Te,_e,Ne,qe,st,nt,pt;return R((pt=(nt=(st=(qe=(Ne=(_e=(Te=q.callId)!=null?Te:q.call_id)!=null?_e:q.requestId)!=null?Ne:q.request_id)!=null?qe:q.toolCallId)!=null?st:q.tool_call_id)!=null?nt:q.stepId)!=null?pt:q.step_id)},ne=n,ue=!1,Be=()=>{if(f)return f;let q;return!ue&&ne?(q=ne,ue=!0):ne&&A.current?q=`${ne}_${A.current}`:q=`assistant-${Date.now()}-${Math.random().toString(16).slice(2)}`,f={id:q,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,sequence:l()},p(f),f},Ke=(q,Te)=>{b.lastId=Te,q&&b.byStep.set(q,Te)},ye=(q,Te)=>{var st;let _e=(st=q.reasoningId)!=null?st:q.id,Ne=W(q);if(_e){let nt=String(_e);return Ke(Ne,nt),nt}if(Ne){let nt=b.byStep.get(Ne);if(nt)return b.lastId=nt,nt}if(b.lastId&&!Te)return b.lastId;if(!Te)return null;let qe=`reason-${l()}`;return Ke(Ne,qe),qe},me=q=>{let Te=T.get(q);if(Te)return Te;let _e={id:`reason-${q}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"reasoning",sequence:l(),reasoning:{id:q,status:"streaming",chunks:[]}};return T.set(q,_e),p(_e),_e},We=(q,Te)=>{y.lastId=Te,q&&y.byCall.set(q,Te)},Xe=new Set,Y=new Map,Ee=new Set,G=new Map,ce=q=>{if(!q)return!1;let Te=q.replace(/_+/g,"_").replace(/^_|_$/g,"");return Te==="emit_artifact_markdown"||Te==="emit_artifact_component"},de=(q,Te)=>{var st;let _e=(st=q.toolId)!=null?st:q.id,Ne=V(q);if(_e){let nt=String(_e);return We(Ne,nt),nt}if(Ne){let nt=y.byCall.get(Ne);if(nt)return y.lastId=nt,nt}if(y.lastId&&!Te)return y.lastId;if(!Te)return null;let qe=`tool-${l()}`;return We(Ne,qe),qe},pe=q=>{let Te=S.get(q);if(Te)return Te;let _e={id:`tool-${q}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"tool",sequence:l(),toolCall:{id:q,status:"pending"}};return S.set(q,_e),p(_e),_e},Re=q=>{if(typeof q=="number"&&Number.isFinite(q))return q;if(typeof q=="string"){let Te=Number(q);if(!Number.isNaN(Te)&&Number.isFinite(Te))return Te;let _e=Date.parse(q);if(!Number.isNaN(_e))return _e}return Date.now()},Ye=q=>{if(typeof q=="string")return q;if(q==null)return"";try{return JSON.stringify(q)}catch{return String(q)}},J=new Map,ie=new Map,Ue=new Map,K=new Map,j=null,Ce=(q,Te,_e)=>{var pt;let Ne=Ue.get(q);Ne||(Ne=[],Ue.set(q,Ne));let qe=0,st=Ne.length;for(;qe<st;){let Nt=qe+st>>>1;Ne[Nt].seq<Te?qe=Nt+1:st=Nt}((pt=Ne[qe])==null?void 0:pt.seq)===Te?Ne[qe]={seq:Te,text:_e}:Ne.splice(qe,0,{seq:Te,text:_e});let nt="";for(let Nt=0;Nt<Ne.length;Nt++)nt+=Ne[Nt].text;return nt},De=(q,Te)=>{let _e=Ye(Te),Ne=ie.get(q.id),qe=lb(Ne,_e);q.rawContent=qe;let st=J.get(q.id),nt=be=>{var Ge;let it=(Ge=q.content)!=null?Ge:"";be.trim()!==""&&(it.trim().length===0||be.startsWith(it)||be.trimStart().startsWith(it.trim()))&&(q.content=be)},pt=()=>{var be;if(st){let it=(be=st.close)==null?void 0:be.call(st);it instanceof Promise&&it.catch(()=>{})}J.delete(q.id),ie.delete(q.id),q.streaming=!1,p(q)};if(!st){nt(_e),pt();return}let Nt=Ko(qe);if(Nt!==null&&Nt.trim()!==""){nt(Nt),pt();return}let F=be=>{var Wt;let it=typeof be=="string"?be:(Wt=be==null?void 0:be.text)!=null?Wt:null;if(it!==null&&it.trim()!=="")return it;let Ge=st.getExtractedText();return Ge!==null&&Ge.trim()!==""?Ge:_e},xe;try{xe=st.processChunk(qe)}catch{nt(_e),pt();return}if(xe instanceof Promise){xe.then(be=>{nt(F(be)),pt()}).catch(()=>{nt(_e),pt()});return}nt(F(xe)),pt()},oe=[],Se=!1,ge,Rt=()=>{Se||(Se=!0,queueMicrotask(()=>{Se=!1,ge()}))},Me=new Ti((q,Te)=>{oe.push({payloadType:q,payload:Te}),Rt()}),ae=null,ur=new Map,Ut=(Qt=this.config.iterationDisplay)!=null?Qt:"separate";for(ge=()=>{var q,Te,_e,Ne,qe,st,nt,pt,Nt,F,xe,be,it,Ge,Wt,ar,Pt,kt,rt,lt,rr,gn,Ir,Tn,Et,hn,pr,Ar,Kr,bt,kn,nn,Sr,Tr,Vn,En,xn,vt,Pe,P,Z,se,Mt,zt,Ht,sr,xr,Fr,kr,ot,wr,Nr,co,jn,po,Fn,on,Mn,At,ir,lr,an,uo,yn,Ln,sn,z,he,ln,Pn,Nn,Fa,In,Rn,Hn,Gn,Io,_s,Na,$s,la,wt,_a,bn,Yr,Us,qs,da,Xn,zs,Ro,$a,Jn,Ua,fo,mo,Vs,js,Hl,Ho,go,Gs,qa,ho,Xs,za,xo,Va,Js,Kn,Ks,yo,qt,ca,pa,ja,_n,Ys,Ga,Xa,Ja,Ka,_r,dn,Yn,ut,Ya,Bo,Bn,Qs,ua,fa,Wo,bo,Zs,ei,Wn,Do;for(let ma=0;ma<oe.length;ma++){let Ze=oe[ma].payloadType,L=oe[ma].payload;if(Ze==="reason_start"){let _=(q=ye(L,!0))!=null?q:`reason-${l()}`,I=me(_);I.reasoning=(Te=I.reasoning)!=null?Te:{id:_,status:"streaming",chunks:[]},I.reasoning.startedAt=(Ne=I.reasoning.startedAt)!=null?Ne:Re((_e=L.startedAt)!=null?_e:L.timestamp),I.reasoning.completedAt=void 0,I.reasoning.durationMs=void 0,I.streaming=!0,I.reasoning.status="streaming",p(I)}else if(Ze==="reason_delta"||Ze==="reason_chunk"){let _=(st=(qe=ye(L,!1))!=null?qe:ye(L,!0))!=null?st:`reason-${l()}`,I=me(_);I.reasoning=(nt=I.reasoning)!=null?nt:{id:_,status:"streaming",chunks:[]},I.reasoning.startedAt=(Nt=I.reasoning.startedAt)!=null?Nt:Re((pt=L.startedAt)!=null?pt:L.timestamp);let Q=(be=(xe=(F=L.reasoningText)!=null?F:L.text)!=null?xe:L.delta)!=null?be:"";if(Q&&L.hidden!==!0){let le=typeof L.sequenceIndex=="number"?L.sequenceIndex:void 0;if(le!==void 0){let ee=Ce(_,le,String(Q));I.reasoning.chunks=[ee]}else I.reasoning.chunks.push(String(Q))}if(I.reasoning.status=L.done?"complete":"streaming",L.done){I.reasoning.completedAt=Re((it=L.completedAt)!=null?it:L.timestamp);let le=(Ge=I.reasoning.startedAt)!=null?Ge:Date.now();I.reasoning.durationMs=Math.max(0,((Wt=I.reasoning.completedAt)!=null?Wt:Date.now())-le)}I.streaming=I.reasoning.status!=="complete",p(I)}else if(Ze==="reason_complete"){let _=(Pt=(ar=ye(L,!1))!=null?ar:ye(L,!0))!=null?Pt:`reason-${l()}`,I=T.get(_);if(I!=null&&I.reasoning){I.reasoning.status="complete",I.reasoning.completedAt=Re((kt=L.completedAt)!=null?kt:L.timestamp);let le=(rt=I.reasoning.startedAt)!=null?rt:Date.now();I.reasoning.durationMs=Math.max(0,((lt=I.reasoning.completedAt)!=null?lt:Date.now())-le),I.streaming=!1,p(I)}let Q=W(L);Q&&b.byStep.delete(Q)}else if(Ze==="tool_start"){let _=(rr=de(L,!0))!=null?rr:`tool-${l()}`,I=(gn=L.toolName)!=null?gn:L.name;if(ce(I)){Xe.add(_);continue}let Q=pe(_),le=(Ir=Q.toolCall)!=null?Ir:{id:_,status:"pending"};le.name=I!=null?I:le.name,le.status="running",L.args!==void 0?le.args=L.args:L.parameters!==void 0&&(le.args=L.parameters),le.startedAt=(Et=le.startedAt)!=null?Et:Re((Tn=L.startedAt)!=null?Tn:L.timestamp),le.completedAt=void 0,le.durationMs=void 0,Q.toolCall=le,Q.streaming=!0;let ee=L.agentContext;(ee||L.executionId)&&(Q.agentMetadata={executionId:(hn=ee==null?void 0:ee.executionId)!=null?hn:L.executionId,iteration:(pr=ee==null?void 0:ee.iteration)!=null?pr:L.iteration}),p(Q)}else if(Ze==="tool_chunk"||Ze==="tool_delta"){let _=(Kr=(Ar=de(L,!1))!=null?Ar:de(L,!0))!=null?Kr:`tool-${l()}`;if(Xe.has(_))continue;let I=pe(_),Q=(bt=I.toolCall)!=null?bt:{id:_,status:"running"};Q.startedAt=(nn=Q.startedAt)!=null?nn:Re((kn=L.startedAt)!=null?kn:L.timestamp);let le=(Vn=(Tr=(Sr=L.text)!=null?Sr:L.delta)!=null?Tr:L.message)!=null?Vn:"";le&&(Q.chunks=(En=Q.chunks)!=null?En:[],Q.chunks.push(String(le))),Q.status="running",I.toolCall=Q,I.streaming=!0;let ee=L.agentContext;(ee||L.executionId)&&(I.agentMetadata=(Pe=I.agentMetadata)!=null?Pe:{executionId:(xn=ee==null?void 0:ee.executionId)!=null?xn:L.executionId,iteration:(vt=ee==null?void 0:ee.iteration)!=null?vt:L.iteration}),p(I)}else if(Ze==="tool_complete"){let _=(Z=(P=de(L,!1))!=null?P:de(L,!0))!=null?Z:`tool-${l()}`;if(Xe.has(_)){Xe.delete(_);continue}let I=pe(_),Q=(se=I.toolCall)!=null?se:{id:_,status:"running"};Q.status="complete",L.result!==void 0&&(Q.result=L.result),typeof L.duration=="number"&&(Q.duration=L.duration),Q.completedAt=Re((Mt=L.completedAt)!=null?Mt:L.timestamp);let le=(zt=L.duration)!=null?zt:L.executionTime;if(typeof le=="number")Q.durationMs=le;else{let ze=(Ht=Q.startedAt)!=null?Ht:Date.now();Q.durationMs=Math.max(0,((sr=Q.completedAt)!=null?sr:Date.now())-ze)}I.toolCall=Q,I.streaming=!1;let ee=L.agentContext;(ee||L.executionId)&&(I.agentMetadata=(kr=I.agentMetadata)!=null?kr:{executionId:(xr=ee==null?void 0:ee.executionId)!=null?xr:L.executionId,iteration:(Fr=ee==null?void 0:ee.iteration)!=null?Fr:L.iteration}),p(I);let et=V(L);et&&y.byCall.delete(et)}else if(Ze==="step_await"&&L.awaitReason==="local_tool_required"&&L.toolName){let _=(ot=L.toolId)!=null?ot:`local-${l()}`,I=pe(_),Q=(wr=I.toolCall)!=null?wr:{id:_,status:"pending"};Q.name=L.toolName,Q.args=L.parameters,Q.status="complete",Q.chunks=(Nr=Q.chunks)!=null?Nr:[],Q.startedAt=(jn=Q.startedAt)!=null?jn:Re((co=L.startedAt)!=null?co:L.timestamp),Q.completedAt=(po=Q.completedAt)!=null?po:Q.startedAt,I.toolCall=Q,I.streaming=!1,I.agentMetadata={...I.agentMetadata,executionId:(on=L.executionId)!=null?on:(Fn=I.agentMetadata)==null?void 0:Fn.executionId,awaitingLocalTool:!0},p(I)}else if(Ze==="text_start"){if((Mn=L.toolContext)!=null&&Mn.toolId)continue;let _=L.partId;if(_!==void 0&&A.current!==null&&_!==A.current){let I=f;I&&(I.streaming=!1,p(I),j=I,f=null,k=!0)}_!==void 0&&(A.current=_)}else if(Ze==="text_end"){if((At=L.toolContext)!=null&&At.toolId)continue;let _=f;_&&(_.streaming=!1,p(_),j=_,f=null,k=!0)}else if(Ze==="step_chunk"||Ze==="step_delta"){let _=L.stepType,I=L.executionType;if(_==="tool"||I==="context")continue;let Q=L.toolContext;if(Q!=null&&Q.toolId){let ze=String((lr=(ir=L.id)!=null?ir:Q.stepId)!=null?lr:`step-${l()}`),ft=L.partId!==void 0&&L.partId!==null?String(L.partId):"",dt=`${Q.toolId}::${ze}`,Dt=w.get(dt);if(ft!==""&&Dt!==void 0&&Dt!==""&&Dt!==ft){let St=E.get(M(Q.toolId,ze,Dt));St&&St.streaming!==!1&&(St.streaming=!1,p(St))}ft!==""&&w.set(dt,ft);let _t=B(Q.toolId,ze,ft,Q.executionId),fr=(Ln=(yn=(uo=(an=L.text)!=null?an:L.delta)!=null?uo:L.content)!=null?yn:L.chunk)!=null?Ln:"";fr&&(_t.content+=String(fr),_t.streaming=!0,p(_t)),L.isComplete&&(_t.streaming=!1,p(_t));continue}let le=L.partId;if(le!==void 0&&A.current!==null&&le!==A.current){let ze=f;ze&&(ze.streaming=!1,p(ze),j=ze,f=null,k=!0)}le!==void 0&&(A.current=le);let ee=le!==void 0&&(sn=K.get(le))!=null?sn:Be();le!==void 0&&(ee.partId||(ee.partId=le),K.set(le,ee));let et=(Pn=(ln=(he=(z=L.text)!=null?z:L.delta)!=null?he:L.content)!=null?ln:L.chunk)!=null?Pn:"";if(et){let ze=typeof L.seq=="number"?L.seq:void 0,ft=le!=null?le:ee.id,dt=ze!==void 0?Ce(ft,ze,String(et)):((Nn=ie.get(ee.id))!=null?Nn:"")+et;ee.rawContent=dt,J.has(ee.id)||J.set(ee.id,this.createStreamParser());let Dt=J.get(ee.id),_t=dt.trim().startsWith("{")||dt.trim().startsWith("[");if(_t&&ie.set(ee.id,dt),Dt.__isPlainTextParser===!0){ee.content=ze!==void 0?dt:ee.content+et,ie.delete(ee.id),J.delete(ee.id),ee.rawContent=void 0,p(ee);continue}let St=Dt.processChunk(dt);if(St instanceof Promise)St.then(Ot=>{var Rr;let yr=typeof Ot=="string"?Ot:(Rr=Ot==null?void 0:Ot.text)!=null?Rr:null;if(yr!==null&&yr.trim()!=="")ee.content=yr,p(ee);else if(!_t&&!dt.trim().startsWith("<")){let Er=f,Xt=Er&&Er.id===ee.id?Er:ee;Xt.id===ee.id&&(Xt.content=ze!==void 0?dt:Xt.content+et,ie.delete(Xt.id),J.delete(Xt.id),Xt.rawContent=void 0,p(Xt))}}).catch(()=>{ee.content=ze!==void 0?dt:ee.content+et,ie.delete(ee.id),J.delete(ee.id),ee.rawContent=void 0,p(ee)});else{let Ot=typeof St=="string"?St:(Fa=St==null?void 0:St.text)!=null?Fa:null;Ot!==null&&Ot.trim()!==""?(ee.content=Ot,p(ee)):!_t&&!dt.trim().startsWith("<")&&(ee.content=ze!==void 0?dt:ee.content+et,ie.delete(ee.id),J.delete(ee.id),ee.rawContent=void 0,p(ee))}}if(L.isComplete){let ze=(Rn=(In=L.result)==null?void 0:In.response)!=null?Rn:ee.content;if(ze){let ft=ie.get(ee.id),dt=ft!=null?ft:Ye(ze);ee.rawContent=dt;let Dt=J.get(ee.id),_t=null,fr=!1;if(Dt&&(_t=Dt.getExtractedText(),_t===null&&(_t=Ko(dt)),_t===null)){let St=Dt.processChunk(dt);St instanceof Promise?(fr=!0,St.then(Ot=>{var Rr;let yr=typeof Ot=="string"?Ot:(Rr=Ot==null?void 0:Ot.text)!=null?Rr:null;if(yr!==null){let Er=f;Er&&Er.id===ee.id&&(Er.content=yr,Er.streaming=!1,J.delete(Er.id),ie.delete(Er.id),p(Er))}})):_t=typeof St=="string"?St:(Hn=St==null?void 0:St.text)!=null?Hn:null}if(!fr){_t!==null&&_t.trim()!==""?ee.content=_t:ie.has(ee.id)||(ee.content=Ye(ze));let St=J.get(ee.id);if(St){let Ot=(Gn=St.close)==null?void 0:Gn.call(St);Ot instanceof Promise&&Ot.catch(()=>{}),J.delete(ee.id)}ie.delete(ee.id),ee.streaming=!1,p(ee)}}}}else if(Ze==="step_complete"){let _=L.stepType,I=L.executionType;if(_==="tool"||I==="context")continue;let Q=L.toolContext;if(Q!=null&&Q.toolId){let ze=String((_s=(Io=L.id)!=null?Io:Q.stepId)!=null?_s:"");if(ze){let ft=H(Q.toolId,ze);for(let[dt,Dt]of E)dt.startsWith(ft)&&Dt.streaming!==!1&&(Dt.streaming=!1,p(Dt));w.delete(`${Q.toolId}::${ze}`)}continue}let le=L.stopReason;if(k){if(f!==null){let dt=f;le&&(dt.stopReason=le),J.delete(dt.id),ie.delete(dt.id),dt.streaming!==!1&&(dt.streaming=!1,p(dt))}let ze=(Na=L.result)==null?void 0:Na.response,ft=j;ft&&(le&&(ft.stopReason=le),ze!=null?De(ft,ze):(J.delete(ft.id),ie.delete(ft.id))),j=null;continue}let ee=($s=L.result)==null?void 0:$s.response,et=Be();if(le&&(et.stopReason=le),ee!=null){let ze=J.get(et.id),ft=!1,dt=!1;if(ze){let Dt=ze.getExtractedText(),_t=ie.get(et.id),fr=_t!=null?_t:Ye(ee);if(et.rawContent=fr,Dt!==null&&Dt.trim()!=="")et.content=Dt,ft=!0;else{let St=Ko(fr);if(St!==null)et.content=St,ft=!0;else{let Ot=ze.processChunk(fr);if(Ot instanceof Promise)dt=!0,Ot.then(yr=>{var Er;let Rr=typeof yr=="string"?yr:(Er=yr==null?void 0:yr.text)!=null?Er:null;if(Rr!==null&&Rr.trim()!==""){let Xt=f;Xt&&Xt.id===et.id&&(Xt.content=Rr,Xt.streaming=!1,J.delete(Xt.id),ie.delete(Xt.id),p(Xt))}else{let Xt=ze.getExtractedText(),Qr=f;Qr&&Qr.id===et.id&&(Xt!==null&&Xt.trim()!==""?Qr.content=Xt:ie.has(Qr.id)||(Qr.content=Ye(ee)),Qr.streaming=!1,J.delete(Qr.id),ie.delete(Qr.id),p(Qr))}});else{let yr=typeof Ot=="string"?Ot:(la=Ot==null?void 0:Ot.text)!=null?la:null;if(yr!==null&&yr.trim()!=="")et.content=yr,ft=!0;else{let Rr=ze.getExtractedText();Rr!==null&&Rr.trim()!==""&&(et.content=Rr,ft=!0)}}}}}if(!dt){if(!et.rawContent){let Dt=ie.get(et.id);et.rawContent=Dt!=null?Dt:Ye(ee)}if(!ft&&!ie.has(et.id)&&(et.content=Ye(ee)),ze){let Dt=(wt=ze.close)==null?void 0:wt.call(ze);Dt instanceof Promise&&Dt.catch(()=>{})}J.delete(et.id),ie.delete(et.id),et.streaming=!1,p(et)}}else J.delete(et.id),ie.delete(et.id),et.streaming=!1,p(et)}else if(Ze==="flow_complete"){let _=(_a=L.result)==null?void 0:_a.response;if(k){if(f!==null){let I=f;J.delete(I.id),ie.delete(I.id),I.streaming!==!1&&(I.streaming=!1,p(I))}}else if(_!=null){let I=Be(),Q=ie.get(I.id),le=Q!=null?Q:Ye(_);I.rawContent=le;let ee=Ye(_),et=J.get(I.id);if(et){let dt=Ko(le);if(dt!==null)ee=dt;else{let Dt=et.processChunk(le);Dt instanceof Promise&&Dt.then(fr=>{var Ot;let St=typeof fr=="string"?fr:(Ot=fr==null?void 0:fr.text)!=null?Ot:null;St!==null&&(I.content=St,I.streaming=!1,p(I))});let _t=et.getExtractedText();_t!==null&&(ee=_t)}}J.delete(I.id),ie.delete(I.id);let ze=ee!==I.content,ft=I.streaming!==!1;ze&&(I.content=ee),I.streaming=!1,(ze||ft)&&p(I)}else if(f!==null){let I=f;J.delete(I.id),ie.delete(I.id),I.streaming!==!1&&(I.streaming=!1,p(I))}t({type:"status",status:"idle"})}else if(Ze==="agent_start")ae={executionId:L.executionId,agentId:(bn=L.agentId)!=null?bn:"virtual",agentName:(Yr=L.agentName)!=null?Yr:"",status:"running",currentIteration:0,maxTurns:(Us=L.maxTurns)!=null?Us:1,startedAt:Re(L.startedAt)};else if(Ze==="agent_iteration_start"){if(ae&&(ae.currentIteration=L.iteration),Ut==="separate"&&L.iteration>1){let _=f;_&&(_.streaming=!1,p(_),ur.set(L.iteration-1,_),f=null)}}else if(Ze==="agent_turn_start")m=null;else if(Ze==="agent_turn_delta"){if(L.contentType==="text"){let _=Be();_.content+=(qs=L.delta)!=null?qs:"",_.agentMetadata={executionId:L.executionId,iteration:L.iteration,turnId:L.turnId,agentName:ae==null?void 0:ae.agentName},m=_,p(_)}else if(L.contentType==="thinking"){let _=(da=L.turnId)!=null?da:`agent-think-${L.iteration}`,I=me(_);I.reasoning=(Xn=I.reasoning)!=null?Xn:{id:_,status:"streaming",chunks:[]},I.reasoning.chunks.push((zs=L.delta)!=null?zs:""),I.agentMetadata={executionId:L.executionId,iteration:L.iteration,turnId:L.turnId},p(I)}else if(L.contentType==="tool_input"){let _=(Ro=L.toolCallId)!=null?Ro:y.lastId;if(_){let I=S.get(_);I!=null&&I.toolCall&&(I.toolCall.chunks=($a=I.toolCall.chunks)!=null?$a:[],I.toolCall.chunks.push((Jn=L.delta)!=null?Jn:""),p(I))}}}else if(Ze==="agent_turn_complete"){let _=L.turnId;if(_){let le=T.get(_);if(le!=null&&le.reasoning){le.reasoning.status="complete",le.reasoning.completedAt=Re(L.completedAt);let ee=(Ua=le.reasoning.startedAt)!=null?Ua:Date.now();le.reasoning.durationMs=Math.max(0,((fo=le.reasoning.completedAt)!=null?fo:Date.now())-ee),le.streaming=!1,p(le)}}let I=L.stopReason,Q=f!=null?f:m;if(I&&Q!==null){let le=L.turnId;(!le||((mo=Q.agentMetadata)==null?void 0:mo.turnId)===le)&&(Q.stopReason=I,p(Q))}}else if(Ze==="agent_tool_start"){f&&(f.streaming=!1,p(f),f=null);let _=(Vs=L.toolCallId)!=null?Vs:`agent-tool-${l()}`;We(V(L),_);let I=pe(_),Q=(js=I.toolCall)!=null?js:{id:_,status:"pending",name:void 0,args:void 0,chunks:void 0,result:void 0,duration:void 0,startedAt:void 0,completedAt:void 0,durationMs:void 0};Q.name=(Ho=(Hl=L.toolName)!=null?Hl:L.name)!=null?Ho:Q.name,Q.status="running",L.parameters!==void 0&&(Q.args=L.parameters),Q.startedAt=Re((go=L.startedAt)!=null?go:L.timestamp),I.toolCall=Q,I.streaming=!0,I.agentMetadata={executionId:L.executionId,iteration:L.iteration},p(I)}else if(Ze==="agent_tool_delta"){let _=(Gs=L.toolCallId)!=null?Gs:y.lastId;if(_){let I=(qa=S.get(_))!=null?qa:pe(_);I.toolCall&&(I.toolCall.chunks=(ho=I.toolCall.chunks)!=null?ho:[],I.toolCall.chunks.push((Xs=L.delta)!=null?Xs:""),I.toolCall.status="running",I.streaming=!0,p(I))}}else if(Ze==="agent_tool_complete"){let _=(za=L.toolCallId)!=null?za:y.lastId;if(_){let I=(xo=S.get(_))!=null?xo:pe(_);if(I.toolCall){I.toolCall.status="complete",L.result!==void 0&&(I.toolCall.result=L.result),typeof L.executionTime=="number"&&(I.toolCall.durationMs=L.executionTime),I.toolCall.completedAt=Re((Va=L.completedAt)!=null?Va:L.timestamp),I.streaming=!1,p(I);let Q=V(L);Q&&y.byCall.delete(Q)}}}else if(Ze==="agent_media"){let _=Array.isArray(L.media)?L.media:[],I=[];for(let Q of _){if(!Q||typeof Q!="object")continue;let le=Q,ee=typeof le.type=="string"?le.type:void 0,et=typeof le.mediaType=="string"?le.mediaType.toLowerCase():"",ze=null,ft="";if(ee==="media"){let dt=typeof le.data=="string"?le.data:void 0;if(!dt)continue;ft=et.length>0?et:"application/octet-stream",ze=`data:${ft};base64,${dt}`}else if(ee==="image-url"){let dt=typeof le.url=="string"?le.url:void 0;if(!dt)continue;ft=et,ze=dt}else if(ee==="file-url"){let dt=typeof le.url=="string"?le.url:void 0;if(!dt)continue;ft=et,ze=dt}else continue;if(ze)if(ee==="image-url"||ft.startsWith("image/"))I.push({type:"image",image:ze,...ft?{mimeType:ft}:{}});else if(ft.startsWith("audio/"))I.push({type:"audio",audio:ze,mimeType:ft});else if(ft.startsWith("video/"))I.push({type:"video",video:ze,mimeType:ft});else{let dt=ft||"application/octet-stream";I.push({type:"file",data:ze,mimeType:dt,filename:sb(dt)})}}if(I.length>0){let Q=l(),le=L.toolCallId,et={id:`agent-media-${typeof le=="string"&&le.length>0?`${le}-${Q}`:String(Q)}`,role:"assistant",content:"",contentParts:I,createdAt:new Date().toISOString(),streaming:!1,sequence:Q,agentMetadata:{executionId:L.executionId,iteration:L.iteration}};p(et);let ze=f;ze&&(ze.streaming=!1,p(ze)),f=null,C.current=null}}else if(Ze!=="agent_iteration_complete"){if(Ze==="agent_reflection"||Ze==="agent_reflect"){let _=`agent-reflection-${L.executionId}-${L.iteration}`,I={id:_,role:"assistant",content:(Js=L.reflection)!=null?Js:"",createdAt:new Date().toISOString(),streaming:!1,variant:"reasoning",sequence:l(),reasoning:{id:_,status:"complete",chunks:[(Kn=L.reflection)!=null?Kn:""]},agentMetadata:{executionId:L.executionId,iteration:L.iteration}};p(I)}else if(Ze==="agent_complete"){ae&&(ae.status=L.success?"complete":"error",ae.completedAt=Re(L.completedAt),ae.stopReason=L.stopReason);let _=f;_&&(_.streaming=!1,p(_)),t({type:"status",status:"idle"})}else if(Ze==="agent_error"){let _=typeof L.error=="string"?L.error:(yo=(Ks=L.error)==null?void 0:Ks.message)!=null?yo:"Agent execution error";L.recoverable?typeof console!="undefined"&&console.warn("[AgentWidget] Recoverable agent error:",_):t({type:"error",error:new Error(_)})}else if(Ze!=="agent_ping"){if(Ze==="agent_approval_start"){let _=(qt=L.approvalId)!=null?qt:`approval-${l()}`,I={id:`approval-${_}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!1,variant:"approval",sequence:l(),approval:{id:_,status:"pending",agentId:(ca=ae==null?void 0:ae.agentId)!=null?ca:"virtual",executionId:(ja=(pa=L.executionId)!=null?pa:ae==null?void 0:ae.executionId)!=null?ja:"",toolName:(_n=L.toolName)!=null?_n:"",toolType:L.toolType,description:(Ga=L.description)!=null?Ga:`Execute ${(Ys=L.toolName)!=null?Ys:"tool"}`,parameters:L.parameters}};p(I)}else if(Ze==="step_await"&&L.awaitReason==="approval_required"){let _=(Xa=L.approvalId)!=null?Xa:`approval-${l()}`,I={id:`approval-${_}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!1,variant:"approval",sequence:l(),approval:{id:_,status:"pending",agentId:(Ja=ae==null?void 0:ae.agentId)!=null?Ja:"virtual",executionId:(_r=(Ka=L.executionId)!=null?Ka:ae==null?void 0:ae.executionId)!=null?_r:"",toolName:(dn=L.toolName)!=null?dn:"",toolType:L.toolType,description:(ut=L.description)!=null?ut:`Execute ${(Yn=L.toolName)!=null?Yn:"tool"}`,parameters:L.parameters}};p(I)}else if(Ze==="agent_approval_complete"){let _=L.approvalId;if(_){let Q={id:`approval-${_}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!1,variant:"approval",sequence:l(),approval:{id:_,status:(Ya=L.decision)!=null?Ya:"approved",agentId:(Bo=ae==null?void 0:ae.agentId)!=null?Bo:"virtual",executionId:(Qs=(Bn=L.executionId)!=null?Bn:ae==null?void 0:ae.executionId)!=null?Qs:"",toolName:(ua=L.toolName)!=null?ua:"",description:(fa=L.description)!=null?fa:"",resolvedAt:Date.now()}};p(Q)}}else if(Ze==="artifact_start"||Ze==="artifact_delta"||Ze==="artifact_update"||Ze==="artifact_complete"){if(Ze==="artifact_start"){let _=L.artifactType,I=String(L.id),Q=typeof L.title=="string"?L.title:void 0;if(t({type:"artifact_start",id:I,artifactType:_,title:Q,component:typeof L.component=="string"?L.component:void 0}),G.set(I,{markdown:"",title:Q}),!Ee.has(I)){Ee.add(I);let le={id:`artifact-ref-${I}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,sequence:l(),rawContent:JSON.stringify({component:"PersonaArtifactCard",props:{artifactId:I,title:Q,artifactType:_,status:"streaming"}})};Y.set(I,le),p(le)}}else if(Ze==="artifact_delta"){let _=String(L.id),I=typeof L.delta=="string"?L.delta:String((Wo=L.delta)!=null?Wo:"");t({type:"artifact_delta",id:_,artDelta:I});let Q=G.get(_);Q&&(Q.markdown+=I)}else if(Ze==="artifact_update"){let _=L.props&&typeof L.props=="object"&&!Array.isArray(L.props)?L.props:{};t({type:"artifact_update",id:String(L.id),props:_,component:typeof L.component=="string"?L.component:void 0})}else if(Ze==="artifact_complete"){let _=String(L.id);t({type:"artifact_complete",id:_});let I=Y.get(_);if(I){I.streaming=!1;try{let Q=JSON.parse((bo=I.rawContent)!=null?bo:"{}");if(Q.props){Q.props.status="complete";let le=G.get(_);le!=null&&le.markdown&&(Q.props.markdown=le.markdown)}I.rawContent=JSON.stringify(Q)}catch{}G.delete(_),p(I),Y.delete(_)}}}else if(Ze==="transcript_insert"){let _=L.message;if(!_||typeof _!="object")continue;let I=String((Zs=_.id)!=null?Zs:`msg-${l()}`),Q=_.role,ee={id:I,role:Q==="user"?"user":Q==="system"?"system":"assistant",content:typeof _.content=="string"?_.content:"",rawContent:typeof _.rawContent=="string"?_.rawContent:void 0,createdAt:typeof _.createdAt=="string"?_.createdAt:new Date().toISOString(),streaming:_.streaming===!0,...typeof _.variant=="string"?{variant:_.variant}:{},sequence:l()};if(p(ee),ee.rawContent)try{let et=JSON.parse(ee.rawContent),ze=(ei=et==null?void 0:et.props)==null?void 0:ei.artifactId;typeof ze=="string"&&Ee.add(ze)}catch{}f=null,C.current=null,J.delete(I),ie.delete(I)}else if(Ze==="error"||Ze==="step_error"||Ze==="dispatch_error"||Ze==="flow_error"){let _=null;if(L.error instanceof Error)_=L.error;else if(Ze==="dispatch_error"){let I=(Wn=L.message)!=null?Wn:L.error;I!=null&&I!==""&&(_=new Error(String(I)))}else if(Ze==="step_error"||Ze==="flow_error"){let I=L.error;typeof I=="string"&&I!==""?_=new Error(I):I!=null&&typeof I=="object"&&"message"in I&&(_=new Error(String((Do=I.message)!=null?Do:I)))}else Ze==="error"&&L.error!=null&&L.error!==""&&(_=new Error(String(L.error)));if(_){t({type:"error",error:_});let I=f;I&&I.streaming&&(I.streaming=!1,p(I)),t({type:"status",status:"idle"})}}}}}oe.length=0};;){let{done:q,value:Te}=await o.read();if(q)break;s+=a.decode(Te,{stream:!0});let _e=s.split(`
|
|
52
52
|
|
|
53
53
|
`);s=(Or=_e.pop())!=null?Or:"";for(let Ne of _e){let qe=Ne.split(`
|
|
54
|
-
`),st="message",nt="";for(let F of qe)F.startsWith("event:")?st=F.replace("event:","").trim():F.startsWith("data:")&&(nt+=F.replace("data:","").trim());if(!nt)continue;let pt;try{pt=JSON.parse(nt)}catch(F){t({type:"error",error:F instanceof Error?F:new Error("Failed to parse chat stream payload")});continue}let Nt=st!=="message"?st:(vr=pt.type)!=null?vr:"message";if((Oe=this.onSSEEvent)==null||Oe.call(this,Nt,pt),this.parseSSEEvent){C.current=f;let F=await this.handleCustomSSEEvent(pt,t,C,p,l,w);if(C.current&&C.current!==f&&(f=C.current),F)continue}Me.push(Nt,pt),ge()}}Me.flushPending(),ge(),Me.destroy()}};function Ig(){let e=Date.now().toString(36),r=Math.random().toString(36).substring(2,10);return`msg_${e}_${r}`}function wa(){let e=Date.now().toString(36),r=Math.random().toString(36).substring(2,10);return`usr_${e}_${r}`}function Qo(){let e=Date.now().toString(36),r=Math.random().toString(36).substring(2,10);return`ast_${e}_${r}`}var Ei="[Image]";function Rg(e){return typeof e=="string"?[{type:"text",text:e}]:e}function Hg(e){return typeof e=="string"?e:e.filter(r=>r.type==="text").map(r=>r.text).join("")}function Bg(e){return typeof e=="string"?!1:e.some(r=>r.type==="image")}function Wg(e){return typeof e=="string"?[]:e.filter(r=>r.type==="image")}function hs(e){return{type:"text",text:e}}function Dg(e,r){return{type:"image",image:e,...(r==null?void 0:r.mimeType)&&{mimeType:r.mimeType},...(r==null?void 0:r.alt)&&{alt:r.alt}}}async function Og(e){return new Promise((r,t)=>{let n=new FileReader;n.onload=()=>{let o=n.result;r({type:"image",image:o,mimeType:e.type,alt:e.name})},n.onerror=()=>t(new Error("Failed to read file")),n.readAsDataURL(e)})}function Fg(e,r=["image/png","image/jpeg","image/gif","image/webp"],t=10*1024*1024){return r.includes(e.type)?e.size>t?{valid:!1,error:`File too large. Maximum size: ${Math.round(t/1048576)}MB`}:{valid:!0}:{valid:!1,error:`Invalid file type. Accepted types: ${r.join(", ")}`}}var Ng=["image/png","image/jpeg","image/gif","image/webp","image/svg+xml","image/bmp"],db=["application/pdf","text/plain","text/markdown","text/csv","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/json"],no=[...Ng,...db];function cb(e){return Ng.includes(e)||e.startsWith("image/")}function Mi(e){return cb(e.type)}async function _g(e){return new Promise((r,t)=>{let n=new FileReader;n.onload=()=>{let o=n.result;Mi(e)?r({type:"image",image:o,mimeType:e.type,alt:e.name}):r({type:"file",data:o,mimeType:e.type,filename:e.name})},n.onerror=()=>t(new Error("Failed to read file")),n.readAsDataURL(e)})}function $g(e,r=no,t=10*1024*1024){return r.includes(e.type)?e.size>t?{valid:!1,error:`File too large. Maximum size: ${Math.round(t/1048576)}MB`}:{valid:!0}:{valid:!1,error:`Invalid file type "${e.type}". Accepted types: ${r.join(", ")}`}}function pb(e){let r=e.split(".");return r.length>1?r.pop().toLowerCase():""}function Ug(e,r){let t=pb(r).toUpperCase();return{"application/pdf":"PDF","text/plain":"TXT","text/markdown":"MD","text/csv":"CSV","application/msword":"DOC","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"DOCX","application/vnd.ms-excel":"XLS","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"XLSX","application/json":"JSON"}[e]||t||"FILE"}var Li=class{constructor(r=24e3){this.ctx=null;this.nextStartTime=0;this.activeSources=[];this.finishedCallbacks=[];this.playing=!1;this.streamEnded=!1;this.pendingCount=0;this.remainder=null;this.sampleRate=r}ensureContext(){if(!this.ctx){let t=typeof window!="undefined"?window:void 0;if(!t)throw new Error("AudioPlaybackManager requires a browser environment");let n=t.AudioContext||t.webkitAudioContext;this.ctx=new n({sampleRate:this.sampleRate})}let r=this.ctx;return r.state==="suspended"&&r.resume(),r}enqueue(r){if(r.length===0)return;let t=r;if(this.remainder){let d=new Uint8Array(this.remainder.length+r.length);d.set(this.remainder),d.set(r,this.remainder.length),t=d,this.remainder=null}if(t.length%2!==0&&(this.remainder=new Uint8Array([t[t.length-1]]),t=t.subarray(0,t.length-1)),t.length===0)return;let n=this.ensureContext(),o=this.pcmToFloat32(t),a=n.createBuffer(1,o.length,this.sampleRate);a.getChannelData(0).set(o);let s=n.createBufferSource();s.buffer=a,s.connect(n.destination);let i=n.currentTime;this.nextStartTime<i&&(this.nextStartTime=i),s.start(this.nextStartTime),this.nextStartTime+=a.duration,this.activeSources.push(s),this.pendingCount++,this.playing=!0,s.onended=()=>{let d=this.activeSources.indexOf(s);d!==-1&&this.activeSources.splice(d,1),this.pendingCount--,this.checkFinished()}}markStreamEnd(){this.streamEnded=!0,this.checkFinished()}flush(){for(let r of this.activeSources)try{r.stop(),r.disconnect()}catch{}this.activeSources=[],this.pendingCount=0,this.nextStartTime=0,this.playing=!1,this.streamEnded=!1,this.finishedCallbacks=[],this.remainder=null}isPlaying(){return this.playing}onFinished(r){this.finishedCallbacks.push(r)}async destroy(){this.flush(),this.ctx&&(await this.ctx.close(),this.ctx=null)}checkFinished(){if(this.streamEnded&&this.pendingCount<=0&&this.playing){this.playing=!1,this.streamEnded=!1;let r=this.finishedCallbacks.slice();this.finishedCallbacks=[];for(let t of r)t()}}pcmToFloat32(r){let t=Math.floor(r.length/2),n=new Float32Array(t),o=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let a=0;a<t;a++){let s=o.getInt16(a*2,!0);n[a]=s/32768}return n}};var Pi=class{constructor(){this.sourceNode=null;this.analyserNode=null;this.interval=null;this.conditionStart=null;this.fired=!1}start(r,t,n,o,a){this.stop(),this.fired=!1,this.conditionStart=null,this.sourceNode=r.createMediaStreamSource(t),this.analyserNode=r.createAnalyser(),this.analyserNode.fftSize=2048,this.sourceNode.connect(this.analyserNode);let s=new Float32Array(this.analyserNode.fftSize);this.interval=setInterval(()=>{if(!this.analyserNode||this.fired)return;this.analyserNode.getFloatTimeDomainData(s);let i=0;for(let u=0;u<s.length;u++)i+=s[u]*s[u];let d=Math.sqrt(i/s.length);(n==="silence"?d<o.threshold:d>=o.threshold)?this.conditionStart===null?this.conditionStart=Date.now():Date.now()-this.conditionStart>=o.duration&&(this.fired=!0,a()):this.conditionStart=null},100)}stop(){this.interval&&(clearInterval(this.interval),this.interval=null),this.sourceNode&&(this.sourceNode.disconnect(),this.sourceNode=null),this.analyserNode=null,this.conditionStart=null,this.fired=!1}};var xs=class{constructor(r){this.config=r;this.type="runtype";this.ws=null;this.audioContext=null;this.w=typeof window!="undefined"?window:void 0;this.mediaRecorder=null;this.resultCallbacks=[];this.errorCallbacks=[];this.statusCallbacks=[];this.processingStartCallbacks=[];this.audioChunks=[];this.isProcessing=!1;this.isSpeaking=!1;this.vad=new Pi;this.mediaStream=null;this.currentAudio=null;this.currentAudioUrl=null;this.currentRequestId=null;this.interruptionMode="none";this.playbackManager=null}getInterruptionMode(){return this.interruptionMode}isBargeInActive(){return this.interruptionMode==="barge-in"&&this.mediaStream!==null}async deactivateBargeIn(){this.vad.stop(),this.mediaStream&&(this.mediaStream.getTracks().forEach(r=>r.stop()),this.mediaStream=null),this.audioContext&&(await this.audioContext.close(),this.audioContext=null)}async connect(){var r,t,n;if(!(this.ws&&this.ws.readyState===WebSocket.OPEN))try{if(!this.w)throw new Error("Window object not available");let o=this.w;if(!o||!o.location)throw new Error("Window object or location not available");let a=o.location.protocol==="https:"?"wss:":"ws:",s=(r=this.config)==null?void 0:r.host,i=(t=this.config)==null?void 0:t.agentId,d=(n=this.config)==null?void 0:n.clientToken;if(!i||!d)throw new Error("agentId and clientToken are required");if(!s)throw new Error("host must be provided in Runtype voice provider configuration");let l=`${a}//${s}/ws/agents/${i}/voice?token=${d}`;this.ws=new WebSocket(l),this.setupWebSocketHandlers();let u=`${a}//${s}/ws/agents/${i}/voice?token=...`,p=" Check: API running on port 8787? Valid client token? Agent voice enabled? Token allowedOrigins includes this page?";await new Promise((f,m)=>{if(!this.ws)return m(new Error("WebSocket not created"));let C=!1,w=T=>{C||(C=!0,clearTimeout(k),m(new Error(T)))},k=setTimeout(()=>w("WebSocket connection timed out."+p),1e4);this.ws.addEventListener("open",()=>{C||(C=!0,clearTimeout(k),f())},{once:!0}),this.ws.addEventListener("error",()=>{w("WebSocket connection failed to "+u+"."+p)},{once:!0}),this.ws.addEventListener("close",T=>{if(!T.wasClean&&!C){let S=T.code!==1006?` (code ${T.code})`:"";w("WebSocket connection failed"+S+"."+p)}},{once:!0})}),this.sendHeartbeat()}catch(o){throw this.ws=null,this.errorCallbacks.forEach(a=>a(o)),this.statusCallbacks.forEach(a=>a("error")),o}}setupWebSocketHandlers(){this.ws&&(this.ws.onopen=()=>{this.statusCallbacks.forEach(r=>r("connected"))},this.ws.onclose=()=>{this.statusCallbacks.forEach(r=>r("disconnected"))},this.ws.onerror=r=>{this.errorCallbacks.forEach(t=>t(new Error("WebSocket error"))),this.statusCallbacks.forEach(t=>t("error"))},this.ws.binaryType="arraybuffer",this.ws.onmessage=r=>{if(r.data instanceof ArrayBuffer){this.handleAudioChunk(new Uint8Array(r.data));return}try{let t=JSON.parse(r.data);this.handleWebSocketMessage(t)}catch{this.errorCallbacks.forEach(n=>n(new Error("Message parsing failed")))}})}handleWebSocketMessage(r){var t,n;switch(r.type){case"session_config":r.interruptionMode&&(this.interruptionMode=r.interruptionMode);break;case"voice_response":this.isProcessing=!1,this.resultCallbacks.forEach(o=>o({text:r.response.agentResponseText||r.response.transcript,transcript:r.response.transcript,audio:r.response.audio,confidence:.95,provider:"runtype"})),(t=r.response.audio)!=null&&t.base64?(this.isSpeaking=!0,this.statusCallbacks.forEach(o=>o("speaking")),this.playAudio(r.response.audio).catch(o=>this.errorCallbacks.forEach(a=>a(o instanceof Error?o:new Error(String(o)))))):(n=r.response.audio)!=null&&n.base64;break;case"audio_end":if(r.requestId&&r.requestId!==this.currentRequestId)break;this.playbackManager?this.playbackManager.markStreamEnd():(this.isSpeaking=!1,this.isProcessing=!1,this.statusCallbacks.forEach(o=>o("idle")));break;case"cancelled":this.isProcessing=!1;break;case"error":this.errorCallbacks.forEach(o=>o(new Error(r.error))),this.statusCallbacks.forEach(o=>o("error")),this.isProcessing=!1;break;case"pong":break}}handleAudioChunk(r){r.length!==0&&this.currentRequestId&&(this.playbackManager||(this.playbackManager=new Li(24e3),this.playbackManager.onFinished(()=>{this.isSpeaking=!1,this.playbackManager=null,this.vad.stop(),this.statusCallbacks.forEach(t=>t("idle"))})),this.isSpeaking||(this.isSpeaking=!0,this.statusCallbacks.forEach(t=>t("speaking")),this.startBargeInMonitoring().catch(()=>{})),this.playbackManager.enqueue(r))}stopPlayback(){!this.isProcessing&&!this.isSpeaking||(this.cancelCurrentPlayback(),this.statusCallbacks.forEach(r=>r("idle")))}cancelCurrentPlayback(){this.currentAudio&&(this.currentAudio.pause(),this.currentAudio.src="",this.currentAudio=null),this.currentAudioUrl&&(URL.revokeObjectURL(this.currentAudioUrl),this.currentAudioUrl=null),this.playbackManager&&(this.playbackManager.flush(),this.playbackManager=null),this.currentRequestId&&this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"cancel",requestId:this.currentRequestId})),this.currentRequestId=null,this.isProcessing=!1,this.isSpeaking=!1}async startListening(){var r,t,n,o;try{if(this.isProcessing||this.isSpeaking)if(this.interruptionMode!=="none")this.cancelCurrentPlayback();else return;if(!this.mediaStream){let l=this.interruptionMode==="barge-in"?{audio:{echoCancellation:!0,noiseSuppression:!0}}:{audio:!0};this.mediaStream=await navigator.mediaDevices.getUserMedia(l)}let a=this.w;this.audioContext||(this.audioContext=new(a.AudioContext||a.webkitAudioContext));let s=this.audioContext,i=(t=(r=this.config)==null?void 0:r.pauseDuration)!=null?t:2e3,d=(o=(n=this.config)==null?void 0:n.silenceThreshold)!=null?o:.01;this.vad.start(s,this.mediaStream,"silence",{threshold:d,duration:i},()=>this.stopListening()),this.mediaRecorder=new MediaRecorder(this.mediaStream),this.audioChunks=[],this.mediaRecorder.ondataavailable=l=>{l.data.size>0&&this.audioChunks.push(l.data)},this.mediaRecorder.onstop=async()=>{var l;if(this.audioChunks.length>0){this.isProcessing=!0,this.statusCallbacks.forEach(f=>f("processing")),this.processingStartCallbacks.forEach(f=>f());let u=((l=this.mediaRecorder)==null?void 0:l.mimeType)||"audio/webm",p=new Blob(this.audioChunks,{type:u});await this.sendAudio(p),this.audioChunks=[]}},this.mediaRecorder.start(1e3),this.statusCallbacks.forEach(l=>l("listening"))}catch(a){throw this.errorCallbacks.forEach(s=>s(a)),this.statusCallbacks.forEach(s=>s("error")),a}}async stopListening(){this.vad.stop(),this.mediaRecorder&&(this.interruptionMode!=="barge-in"&&this.mediaRecorder.stream.getTracks().forEach(r=>r.stop()),this.mediaRecorder.stop(),this.mediaRecorder=null),this.interruptionMode!=="barge-in"&&(this.mediaStream&&(this.mediaStream.getTracks().forEach(r=>r.stop()),this.mediaStream=null),this.audioContext&&(await this.audioContext.close(),this.audioContext=null)),this.statusCallbacks.forEach(r=>r("idle"))}async startBargeInMonitoring(){var a,s;if(this.interruptionMode!=="barge-in")return;let r=this.w;if(!this.mediaStream&&r&&(this.mediaStream=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0}})),!this.audioContext&&r&&(this.audioContext=new(r.AudioContext||r.webkitAudioContext)),!this.audioContext||!this.mediaStream)return;let t=this.audioContext,n=(s=(a=this.config)==null?void 0:a.silenceThreshold)!=null?s:.01;this.vad.start(t,this.mediaStream,"speech",{threshold:n,duration:200},()=>this.handleBargeIn())}handleBargeIn(){this.cancelCurrentPlayback(),this.startListening().catch(r=>{this.errorCallbacks.forEach(t=>t(r instanceof Error?r:new Error(String(r))))})}generateRequestId(){return"vreq_"+Math.random().toString(36).substring(2,10)+Date.now().toString(36)}async sendAudio(r){var t;if(!this.ws||this.ws.readyState!==WebSocket.OPEN){this.errorCallbacks.forEach(n=>n(new Error("WebSocket not connected"))),this.statusCallbacks.forEach(n=>n("error"));return}try{let n=await this.blobToBase64(r),o=this.getFormatFromMimeType(r.type),a=this.generateRequestId();this.currentRequestId=a,this.ws.send(JSON.stringify({type:"audio_input",audio:n,format:o,sampleRate:16e3,voiceId:(t=this.config)==null?void 0:t.voiceId,requestId:a}))}catch(n){this.errorCallbacks.forEach(o=>o(n)),this.statusCallbacks.forEach(o=>o("error"))}}getFormatFromMimeType(r){return r.includes("wav")?"wav":r.includes("mpeg")||r.includes("mp3")?"mp3":"webm"}blobToBase64(r){return new Promise((t,n)=>{let o=new FileReader;o.onload=()=>{let s=o.result.split(",")[1];t(s)},o.onerror=n,o.readAsDataURL(r)})}async playAudio(r){if(!r.base64)return;let t=atob(r.base64),n=new Uint8Array(t.length);for(let l=0;l<t.length;l++)n[l]=t.charCodeAt(l);let o=r.format||"mp3",a=o==="mp3"?"audio/mpeg":`audio/${o}`,s=new Blob([n],{type:a}),i=URL.createObjectURL(s),d=new Audio(i);this.currentAudio=d,this.currentAudioUrl=i,d.onended=()=>{URL.revokeObjectURL(i),this.currentAudio===d&&(this.currentAudio=null,this.currentAudioUrl=null,this.isSpeaking=!1,this.statusCallbacks.forEach(l=>l("idle")))},await d.play()}onResult(r){this.resultCallbacks.push(r)}onError(r){this.errorCallbacks.push(r)}onStatusChange(r){this.statusCallbacks.push(r)}onProcessingStart(r){this.processingStartCallbacks.push(r)}async disconnect(){if(this.currentAudio&&(this.currentAudio.pause(),this.currentAudio.src="",this.currentAudio=null),this.currentAudioUrl&&(URL.revokeObjectURL(this.currentAudioUrl),this.currentAudioUrl=null),this.playbackManager&&(await this.playbackManager.destroy(),this.playbackManager=null),this.currentRequestId=null,this.isSpeaking=!1,this.vad.stop(),await this.stopListening(),this.mediaStream&&(this.mediaStream.getTracks().forEach(r=>r.stop()),this.mediaStream=null),this.audioContext&&(await this.audioContext.close(),this.audioContext=null),this.ws){try{this.ws.close()}catch{}this.ws=null}this.statusCallbacks.forEach(r=>r("disconnected"))}sendHeartbeat(){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"ping"}))}};var Zo=class{constructor(r={}){this.config=r;this.type="browser";this.recognition=null;this.resultCallbacks=[];this.errorCallbacks=[];this.statusCallbacks=[];this.isListening=!1;this.w=typeof window!="undefined"?window:void 0}async connect(){this.statusCallbacks.forEach(r=>r("connected"))}async startListening(){var r,t;try{if(this.isListening)throw new Error("Already listening");if(!this.w)throw new Error("Window object not available");let n=this.w.SpeechRecognition||this.w.webkitSpeechRecognition;if(!n)throw new Error("Browser speech recognition not supported");this.recognition=new n,this.recognition.lang=((r=this.config)==null?void 0:r.language)||"en-US",this.recognition.continuous=((t=this.config)==null?void 0:t.continuous)||!1,this.recognition.interimResults=!0,this.recognition.onresult=o=>{var i;let a=Array.from(o.results).map(d=>d[0]).map(d=>d.transcript).join(""),s=o.results[o.results.length-1].isFinal;this.resultCallbacks.forEach(d=>d({text:a,confidence:s?.8:.5,provider:"browser"})),s&&!((i=this.config)!=null&&i.continuous)&&this.stopListening()},this.recognition.onerror=o=>{this.errorCallbacks.forEach(a=>a(new Error(o.error))),this.statusCallbacks.forEach(a=>a("error"))},this.recognition.onstart=()=>{this.isListening=!0,this.statusCallbacks.forEach(o=>o("listening"))},this.recognition.onend=()=>{this.isListening=!1,this.statusCallbacks.forEach(o=>o("idle"))},this.recognition.start()}catch(n){throw this.errorCallbacks.forEach(o=>o(n)),this.statusCallbacks.forEach(o=>o("error")),n}}async stopListening(){this.recognition&&(this.recognition.stop(),this.recognition=null),this.isListening=!1,this.statusCallbacks.forEach(r=>r("idle"))}onResult(r){this.resultCallbacks.push(r)}onError(r){this.errorCallbacks.push(r)}onStatusChange(r){this.statusCallbacks.push(r)}async disconnect(){await this.stopListening(),this.statusCallbacks.forEach(r=>r("disconnected"))}static isSupported(){return"SpeechRecognition"in window||"webkitSpeechRecognition"in window}};function ea(e){switch(e.type){case"runtype":if(!e.runtype)throw new Error("Runtype voice provider requires configuration");return new xs(e.runtype);case"browser":if(!Zo.isSupported())throw new Error("Browser speech recognition not supported");return new Zo(e.browser||{});case"custom":throw new Error("Custom voice providers not yet implemented");default:throw new Error(`Unknown voice provider type: ${e.type}`)}}function Ii(e){if((e==null?void 0:e.type)==="runtype"&&e.runtype)return ea({type:"runtype",runtype:e.runtype});if(Zo.isSupported())return ea({type:"browser",browser:(e==null?void 0:e.browser)||{language:"en-US"}});throw new Error("No supported voice providers available")}function ys(e){try{return Ii(e),!0}catch{return!1}}var va=class e{constructor(r={},t){this.config=r;this.callbacks=t;this.status="idle";this.streaming=!1;this.abortController=null;this.sequenceCounter=Date.now();this.clientSession=null;this.agentExecution=null;this.artifacts=new Map;this.selectedArtifactId=null;this.voiceProvider=null;this.voiceActive=!1;this.voiceStatus="disconnected";this.pendingVoiceUserMessageId=null;this.pendingVoiceAssistantMessageId=null;this.ttsSpokenMessageIds=new Set;this.handleEvent=r=>{var t,n,o,a,s,i,d;r.type==="message"?(this.upsertMessage(r.message),(t=r.message.agentMetadata)!=null&&t.executionId&&(this.agentExecution?r.message.agentMetadata.iteration!==void 0&&(this.agentExecution.currentIteration=r.message.agentMetadata.iteration):this.agentExecution={executionId:r.message.agentMetadata.executionId,agentId:"",agentName:(n=r.message.agentMetadata.agentName)!=null?n:"",status:"running",currentIteration:(o=r.message.agentMetadata.iteration)!=null?o:0,maxTurns:0})):r.type==="status"?(this.setStatus(r.status),r.status==="connecting"?this.setStreaming(!0):(r.status==="idle"||r.status==="error")&&(this.setStreaming(!1),this.abortController=null,((a=this.agentExecution)==null?void 0:a.status)==="running"&&(this.agentExecution.status=r.status==="error"?"error":"complete"))):r.type==="error"?(this.setStatus("error"),this.setStreaming(!1),this.abortController=null,((s=this.agentExecution)==null?void 0:s.status)==="running"&&(this.agentExecution.status="error"),(d=(i=this.callbacks).onError)==null||d.call(i,r.error)):(r.type==="artifact_start"||r.type==="artifact_delta"||r.type==="artifact_update"||r.type==="artifact_complete")&&this.applyArtifactStreamEvent(r)};var n,o;this.messages=[...(n=r.initialMessages)!=null?n:[]].map(a=>{var s;return{...a,sequence:(s=a.sequence)!=null?s:this.nextSequence()}}),this.messages=this.sortMessages(this.messages),this.client=new Yo(r);for(let a of(o=r.initialArtifacts)!=null?o:[])this.artifacts.set(a.id,{...a,status:"complete"});r.initialSelectedArtifactId!=null&&(this.selectedArtifactId=r.initialSelectedArtifactId),this.messages.length&&this.callbacks.onMessagesChanged([...this.messages]),this.artifacts.size>0&&this.emitArtifactsState(),this.callbacks.onStatusChanged(this.status)}setSSEEventCallback(r){this.client.setSSEEventCallback(r)}isClientTokenMode(){return this.client.isClientTokenMode()}isAgentMode(){return this.client.isAgentMode()}getAgentExecution(){return this.agentExecution}isAgentExecuting(){var r;return((r=this.agentExecution)==null?void 0:r.status)==="running"}isVoiceSupported(){var r;return ys((r=this.config.voiceRecognition)==null?void 0:r.provider)}isVoiceActive(){return this.voiceActive}getVoiceStatus(){return this.voiceStatus}getVoiceInterruptionMode(){var r;return(r=this.voiceProvider)!=null&&r.getInterruptionMode?this.voiceProvider.getInterruptionMode():"none"}stopVoicePlayback(){var r;(r=this.voiceProvider)!=null&&r.stopPlayback&&this.voiceProvider.stopPlayback()}isBargeInActive(){var r,t,n;return(n=(t=(r=this.voiceProvider)==null?void 0:r.isBargeInActive)==null?void 0:t.call(r))!=null?n:!1}async deactivateBargeIn(){var r;(r=this.voiceProvider)!=null&&r.deactivateBargeIn&&await this.voiceProvider.deactivateBargeIn()}setupVoice(r){var t,n,o;try{let a=r||this.getVoiceConfigFromConfig();if(!a)throw new Error("Voice configuration not provided");this.voiceProvider=ea(a);let s=(t=this.config.voiceRecognition)!=null?t:{},i=(n=s.processingText)!=null?n:"\u{1F3A4} Processing voice...",d=(o=s.processingErrorText)!=null?o:"Voice processing failed. Please try again.";this.voiceProvider.onProcessingStart&&this.voiceProvider.onProcessingStart(()=>{let l=this.injectMessage({role:"user",content:i,streaming:!1,voiceProcessing:!0});this.pendingVoiceUserMessageId=l.id;let u=this.injectMessage({role:"assistant",content:"",streaming:!0,voiceProcessing:!0});this.pendingVoiceAssistantMessageId=u.id,this.setStreaming(!0)}),this.voiceProvider.onResult(l=>{var u,p,f,m,C,w;if(l.provider==="browser")l.text&&l.text.trim()&&this.sendMessage(l.text,{viaVoice:!0});else if(l.provider==="runtype"){this.pendingVoiceUserMessageId&&((u=l.transcript)!=null&&u.trim())?this.upsertMessage({id:this.pendingVoiceUserMessageId,role:"user",content:l.transcript.trim(),createdAt:new Date().toISOString(),streaming:!1,voiceProcessing:!1}):(p=l.transcript)!=null&&p.trim()&&this.injectUserMessage({content:l.transcript.trim()}),this.pendingVoiceAssistantMessageId&&((f=l.text)!=null&&f.trim())?this.upsertMessage({id:this.pendingVoiceAssistantMessageId,role:"assistant",content:l.text.trim(),createdAt:new Date().toISOString(),streaming:!1,voiceProcessing:!1}):(m=l.text)!=null&&m.trim()&&this.injectAssistantMessage({content:l.text.trim()});{let k=(w=this.pendingVoiceAssistantMessageId)!=null?w:(C=[...this.messages].reverse().find(T=>T.role==="assistant"))==null?void 0:C.id;k&&this.ttsSpokenMessageIds.add(k)}this.setStreaming(!1),this.pendingVoiceUserMessageId=null,this.pendingVoiceAssistantMessageId=null}}),this.voiceProvider.onError(l=>{console.error("Voice error:",l),this.pendingVoiceAssistantMessageId&&(this.upsertMessage({id:this.pendingVoiceAssistantMessageId,role:"assistant",content:d,createdAt:new Date().toISOString(),streaming:!1,voiceProcessing:!1}),this.setStreaming(!1),this.pendingVoiceUserMessageId=null,this.pendingVoiceAssistantMessageId=null)}),this.voiceProvider.onStatusChange(l=>{var u,p;this.voiceStatus=l,this.voiceActive=l==="listening",(p=(u=this.callbacks).onVoiceStatusChanged)==null||p.call(u,l)}),this.voiceProvider.connect()}catch(a){console.error("Failed to setup voice:",a)}}async toggleVoice(){if(!this.voiceProvider){console.error("Voice not configured");return}if(this.voiceActive)await this.voiceProvider.stopListening();else{this.stopSpeaking();try{await this.voiceProvider.startListening()}catch(r){console.error("Failed to start voice:",r)}}}cleanupVoice(){this.voiceProvider&&(this.voiceProvider.disconnect(),this.voiceProvider=null),this.voiceActive=!1,this.voiceStatus="disconnected"}getVoiceConfigFromConfig(){var t,n,o,a,s,i,d,l,u;if(!((t=this.config.voiceRecognition)!=null&&t.provider))return;let r=this.config.voiceRecognition.provider;switch(r.type){case"runtype":return{type:"runtype",runtype:{agentId:((n=r.runtype)==null?void 0:n.agentId)||"",clientToken:((o=r.runtype)==null?void 0:o.clientToken)||"",host:(a=r.runtype)==null?void 0:a.host,voiceId:(s=r.runtype)==null?void 0:s.voiceId,pauseDuration:(i=r.runtype)==null?void 0:i.pauseDuration,silenceThreshold:(d=r.runtype)==null?void 0:d.silenceThreshold}};case"browser":return{type:"browser",browser:{language:((l=r.browser)==null?void 0:l.language)||"en-US",continuous:(u=r.browser)==null?void 0:u.continuous}};default:return}}async initClientSession(){var r,t;if(!this.isClientTokenMode())return null;try{let n=await this.client.initSession();return this.setClientSession(n),n}catch(n){return(t=(r=this.callbacks).onError)==null||t.call(r,n instanceof Error?n:new Error(String(n))),null}}setClientSession(r){if(this.clientSession=r,r.config.welcomeMessage&&this.messages.length===0){let t={id:`welcome-${Date.now()}`,role:"assistant",content:r.config.welcomeMessage,createdAt:new Date().toISOString(),sequence:this.nextSequence()};this.appendMessage(t)}}getClientSession(){var r;return(r=this.clientSession)!=null?r:this.client.getClientSession()}isSessionValid(){let r=this.getClientSession();return r?new Date<r.expiresAt:!1}clearClientSession(){this.clientSession=null,this.client.clearClientSession()}getClient(){return this.client}async submitMessageFeedback(r,t){return this.client.submitMessageFeedback(r,t)}async submitCSATFeedback(r,t){return this.client.submitCSATFeedback(r,t)}async submitNPSFeedback(r,t){return this.client.submitNPSFeedback(r,t)}updateConfig(r){let t=this.client.getSSEEventCallback();this.config={...this.config,...r},this.client=new Yo(this.config),t&&this.client.setSSEEventCallback(t)}getMessages(){return[...this.messages]}getStatus(){return this.status}isStreaming(){return this.streaming}injectTestEvent(r){this.handleEvent(r)}injectMessage(r){let{role:t,content:n,llmContent:o,contentParts:a,id:s,createdAt:i,sequence:d,streaming:l=!1,voiceProcessing:u,rawContent:p}=r,m={id:s!=null?s:t==="user"?wa():t==="assistant"?Qo():`system-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:t,content:n,createdAt:i!=null?i:new Date().toISOString(),sequence:d!=null?d:this.nextSequence(),streaming:l,...o!==void 0&&{llmContent:o},...a!==void 0&&{contentParts:a},...u!==void 0&&{voiceProcessing:u},...p!==void 0&&{rawContent:p}};return this.upsertMessage(m),m}injectAssistantMessage(r){return this.injectMessage({...r,role:"assistant"})}injectUserMessage(r){return this.injectMessage({...r,role:"user"})}injectSystemMessage(r){return this.injectMessage({...r,role:"system"})}injectMessageBatch(r){let t=[];for(let n of r){let{role:o,content:a,llmContent:s,contentParts:i,id:d,createdAt:l,sequence:u,streaming:p=!1,voiceProcessing:f,rawContent:m}=n,w={id:d!=null?d:o==="user"?wa():o==="assistant"?Qo():`system-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:o,content:a,createdAt:l!=null?l:new Date().toISOString(),sequence:u!=null?u:this.nextSequence(),streaming:p,...s!==void 0&&{llmContent:s},...i!==void 0&&{contentParts:i},...f!==void 0&&{voiceProcessing:f},...m!==void 0&&{rawContent:m}};t.push(w)}return this.messages=this.sortMessages([...this.messages,...t]),this.callbacks.onMessagesChanged([...this.messages]),t}injectComponentDirective(r){let{component:t,props:n={},text:o="",llmContent:a,id:s,createdAt:i,sequence:d}=r,l={text:o,component:t,props:n};return this.injectMessage({role:"assistant",content:o,rawContent:JSON.stringify(l),...a!==void 0&&{llmContent:a},...s!==void 0&&{id:s},...i!==void 0&&{createdAt:i},...d!==void 0&&{sequence:d}})}async sendMessage(r,t){var l,u,p,f,m;let n=r.trim();if(!n&&(!(t!=null&&t.contentParts)||t.contentParts.length===0))return;this.stopSpeaking(),(l=this.abortController)==null||l.abort();let o=wa(),a=Qo(),s={id:o,role:"user",content:n||Ei,createdAt:new Date().toISOString(),sequence:this.nextSequence(),viaVoice:(t==null?void 0:t.viaVoice)||!1,...(t==null?void 0:t.contentParts)&&t.contentParts.length>0&&{contentParts:t.contentParts}};this.appendMessage(s),this.setStreaming(!0);let i=new AbortController;this.abortController=i;let d=[...this.messages];try{await this.client.dispatch({messages:d,signal:i.signal,assistantMessageId:a},this.handleEvent)}catch(C){let w=C instanceof Error&&(C.name==="AbortError"||C.message.includes("aborted")||C.message.includes("abort"));if(!w){let k={id:a,role:"assistant",createdAt:new Date().toISOString(),content:"It looks like the proxy isn't returning a real response yet. Here's a sample message so you can continue testing locally.",sequence:this.nextSequence()};this.appendMessage(k)}this.setStatus("idle"),this.setStreaming(!1),this.abortController=null,w||(C instanceof Error?(p=(u=this.callbacks).onError)==null||p.call(u,C):(m=(f=this.callbacks).onError)==null||m.call(f,new Error(String(C))))}}async continueConversation(){var o,a,s,i,d;if(this.streaming)return;(o=this.abortController)==null||o.abort();let r=Qo();this.setStreaming(!0);let t=new AbortController;this.abortController=t;let n=[...this.messages];try{await this.client.dispatch({messages:n,signal:t.signal,assistantMessageId:r},this.handleEvent)}catch(l){let u={id:r,role:"assistant",createdAt:new Date().toISOString(),content:"It looks like the proxy isn't returning a real response yet. Here's a sample message so you can continue testing locally.",sequence:this.nextSequence()};this.appendMessage(u),this.setStatus("idle"),this.setStreaming(!1),this.abortController=null,l instanceof Error?(s=(a=this.callbacks).onError)==null||s.call(a,l):(d=(i=this.callbacks).onError)==null||d.call(i,new Error(String(l)))}}async connectStream(r,t){var o,a,s;if(this.streaming&&!(t!=null&&t.allowReentry))return;t!=null&&t.allowReentry||(o=this.abortController)==null||o.abort();let n=!1;for(let i of this.messages)i.streaming&&(i.streaming=!1,n=!0);n&&this.callbacks.onMessagesChanged([...this.messages]),this.setStreaming(!0);try{await this.client.processStream(r,this.handleEvent,t==null?void 0:t.assistantMessageId)}catch(i){this.setStatus("error"),this.setStreaming(!1),this.abortController=null,(s=(a=this.callbacks).onError)==null||s.call(a,i instanceof Error?i:new Error(String(i)))}}async resolveApproval(r,t){var d,l,u,p;let n=`approval-${r.id}`,o={...r,status:t,resolvedAt:Date.now()},a={id:n,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!1,variant:"approval",approval:o};this.upsertMessage(a),(d=this.abortController)==null||d.abort(),this.abortController=new AbortController,this.setStreaming(!0);let s=this.config.approval,i=s&&typeof s=="object"?s.onDecision:void 0;try{let f;if(i?f=await i({approvalId:r.id,executionId:r.executionId,agentId:r.agentId,toolName:r.toolName},t):f=await this.client.resolveApproval({agentId:r.agentId,executionId:r.executionId,approvalId:r.id},t),f){let m=null;if(f instanceof Response){if(!f.ok){let C=await f.json().catch(()=>null);throw new Error((l=C==null?void 0:C.error)!=null?l:`Approval request failed: ${f.status}`)}m=f.body}else f instanceof ReadableStream&&(m=f);m?await this.connectStream(m,{allowReentry:!0}):(t==="denied"&&this.appendMessage({id:`denial-${r.id}`,role:"assistant",content:"Tool execution was denied by user.",createdAt:new Date().toISOString(),streaming:!1,sequence:this.nextSequence()}),this.setStreaming(!1),this.abortController=null)}else this.setStreaming(!1),this.abortController=null}catch(f){let m=f instanceof Error&&(f.name==="AbortError"||f.message.includes("aborted")||f.message.includes("abort"));this.setStreaming(!1),this.abortController=null,m||(p=(u=this.callbacks).onError)==null||p.call(u,f instanceof Error?f:new Error(String(f)))}}persistAskUserQuestionProgress(r,t){let n=this.messages.find(o=>o.id===r.id);n&&this.upsertMessage({...n,agentMetadata:{...n.agentMetadata,askUserQuestionAnswers:t.answers,askUserQuestionIndex:t.currentIndex}})}markAskUserQuestionResolved(r,t){let n=this.messages.find(o=>o.id===r.id);n&&this.upsertMessage({...n,agentMetadata:{...n.agentMetadata,awaitingLocalTool:!1,askUserQuestionAnswered:!0,...t?{askUserQuestionAnswers:t}:{}}})}async resolveAskUserQuestion(r,t){var u,p,f,m,C,w,k,T,S,E,v,b;let n=this.messages.find(y=>y.id===r.id);if(((u=n==null?void 0:n.agentMetadata)==null?void 0:u.askUserQuestionAnswered)===!0)return;let o=(p=r.agentMetadata)==null?void 0:p.executionId,a=(f=r.toolCall)==null?void 0:f.name;if(!o||!a){(C=(m=this.callbacks).onError)==null||C.call(m,new Error("resolveAskUserQuestion: message is missing executionId or toolCall.name"));return}let s=typeof t=="string"?void 0:t;if(s===void 0&&typeof t=="string"){let y=(w=r.toolCall)==null?void 0:w.args,M=Array.isArray(y==null?void 0:y.questions)?y.questions:[];if(M.length===1){let H=typeof((k=M[0])==null?void 0:k.question)=="string"?M[0].question:"";H&&(s={[H]:t})}}this.markAskUserQuestionResolved(r,s),(T=this.abortController)==null||T.abort(),this.abortController=new AbortController,this.setStreaming(!0);let i=r.toolCall.id,d=(S=r.toolCall)==null?void 0:S.args,l=Array.isArray(d==null?void 0:d.questions)?d.questions:[];if(l.length===0){let y=typeof t=="string"?t:Object.entries(t).map(([M,H])=>`${M}: ${Array.isArray(H)?H.join(", "):H}`).join(" | ");this.appendMessage({id:`ask-user-answer-${i}`,role:"user",content:y,createdAt:new Date().toISOString(),streaming:!1,sequence:this.nextSequence()})}else{let y=s!=null?s:{};l.forEach((M,H)=>{let B=typeof(M==null?void 0:M.question)=="string"?M.question:"";if(!B)return;let R=y[B],W=Array.isArray(R)?R.join(", "):typeof R=="string"?R:"";this.appendMessage({id:`ask-user-q-${i}-${H}`,role:"assistant",content:B,createdAt:new Date().toISOString(),streaming:!1,sequence:this.nextSequence()}),this.appendMessage({id:`ask-user-a-${i}-${H}`,role:"user",content:W||"*Skipped*",createdAt:new Date().toISOString(),streaming:!1,sequence:this.nextSequence()})})}try{let y=await this.client.resumeFlow(o,{[a]:t});if(!y.ok){let M=await y.json().catch(()=>null);throw new Error((E=M==null?void 0:M.error)!=null?E:`Resume failed: ${y.status}`)}y.body?await this.connectStream(y.body,{allowReentry:!0}):(this.setStreaming(!1),this.abortController=null)}catch(y){let M=y instanceof Error&&(y.name==="AbortError"||y.message.includes("aborted")||y.message.includes("abort"));this.setStreaming(!1),this.abortController=null,M||(b=(v=this.callbacks).onError)==null||b.call(v,y instanceof Error?y:new Error(String(y)))}}cancel(){var r;(r=this.abortController)==null||r.abort(),this.abortController=null,this.stopSpeaking(),this.stopVoicePlayback(),this.setStreaming(!1),this.setStatus("idle")}clearMessages(){var r;this.stopSpeaking(),(r=this.abortController)==null||r.abort(),this.abortController=null,this.messages=[],this.agentExecution=null,this.clearArtifactState(),this.setStreaming(!1),this.setStatus("idle"),this.callbacks.onMessagesChanged([...this.messages])}getArtifacts(){return[...this.artifacts.values()]}getArtifactById(r){return this.artifacts.get(r)}getSelectedArtifactId(){return this.selectedArtifactId}selectArtifact(r){this.selectedArtifactId=r,this.emitArtifactsState()}clearArtifacts(){this.clearArtifactState()}upsertArtifact(r){var o;let t=r.id||`art_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,9)}`;if(r.artifactType==="markdown"){let a={id:t,artifactType:"markdown",title:r.title,status:"complete",markdown:r.content};return this.artifacts.set(t,a),this.selectedArtifactId=t,this.emitArtifactsState(),a}let n={id:t,artifactType:"component",title:r.title,status:"complete",component:r.component,props:(o=r.props)!=null?o:{}};return this.artifacts.set(t,n),this.selectedArtifactId=t,this.emitArtifactsState(),n}clearArtifactState(){this.artifacts.size===0&&this.selectedArtifactId===null||(this.artifacts.clear(),this.selectedArtifactId=null,this.emitArtifactsState())}emitArtifactsState(){var r,t;(t=(r=this.callbacks).onArtifactsState)==null||t.call(r,{artifacts:[...this.artifacts.values()],selectedId:this.selectedArtifactId})}applyArtifactStreamEvent(r){var t,n;switch(r.type){case"artifact_start":{r.artifactType==="markdown"?this.artifacts.set(r.id,{id:r.id,artifactType:"markdown",title:r.title,status:"streaming",markdown:""}):this.artifacts.set(r.id,{id:r.id,artifactType:"component",title:r.title,status:"streaming",component:(t=r.component)!=null?t:"",props:{}}),this.selectedArtifactId=r.id;break}case"artifact_delta":{let o=this.artifacts.get(r.id);(o==null?void 0:o.artifactType)==="markdown"&&(o.markdown=((n=o.markdown)!=null?n:"")+r.artDelta);break}case"artifact_update":{let o=this.artifacts.get(r.id);(o==null?void 0:o.artifactType)==="component"&&(o.props={...o.props,...r.props},r.component&&(o.component=r.component));break}case"artifact_complete":{let o=this.artifacts.get(r.id);o&&(o.status="complete");break}default:return}this.emitArtifactsState()}hydrateMessages(r){var t;(t=this.abortController)==null||t.abort(),this.abortController=null,this.messages=this.sortMessages(r.map(n=>{var o;return{...n,streaming:!1,sequence:(o=n.sequence)!=null?o:this.nextSequence()}})),this.setStreaming(!1),this.setStatus("idle"),this.callbacks.onMessagesChanged([...this.messages])}hydrateArtifacts(r,t=null){this.artifacts.clear();for(let n of r)this.artifacts.set(n.id,{...n,status:"complete"});this.selectedArtifactId=t,this.emitArtifactsState()}setStatus(r){this.status!==r&&(this.status=r,this.callbacks.onStatusChanged(r))}setStreaming(r){if(this.streaming===r)return;let t=this.streaming;this.streaming=r,this.callbacks.onStreamingChanged(r),t&&!r&&this.speakLatestAssistantMessage()}speakLatestAssistantMessage(){let r=this.config.textToSpeech;if(!(r!=null&&r.enabled)||!(!r.provider||r.provider==="browser"||r.provider==="runtype"&&r.browserFallback))return;let n=[...this.messages].reverse().find(a=>a.role==="assistant"&&a.content&&!a.voiceProcessing);if(!n)return;if(this.ttsSpokenMessageIds.has(n.id)){this.ttsSpokenMessageIds.delete(n.id);return}let o=n.content;o.trim()&&this.speak(o,r)}speak(r,t){if(typeof window=="undefined"||!("speechSynthesis"in window))return;let n=window.speechSynthesis;n.cancel();let o=new SpeechSynthesisUtterance(r),a=n.getVoices();if(t.voice){let s=a.find(i=>i.name===t.voice);s&&(o.voice=s)}else a.length>0&&(o.voice=t.pickVoice?t.pickVoice(a):e.pickBestVoice(a));t.rate!==void 0&&(o.rate=t.rate),t.pitch!==void 0&&(o.pitch=t.pitch),setTimeout(()=>n.speak(o),50)}static pickBestVoice(r){var n;let t=["Microsoft Jenny Online (Natural) - English (United States)","Microsoft Aria Online (Natural) - English (United States)","Microsoft Guy Online (Natural) - English (United States)","Google US English","Google UK English Female","Ava (Premium)","Evan (Enhanced)","Samantha (Enhanced)","Samantha","Daniel","Karen","Microsoft David Desktop - English (United States)","Microsoft Zira Desktop - English (United States)"];for(let o of t){let a=r.find(s=>s.name===o);if(a)return a}return(n=r.find(o=>o.lang.startsWith("en")))!=null?n:r[0]}stopSpeaking(){typeof window!="undefined"&&"speechSynthesis"in window&&window.speechSynthesis.cancel()}appendMessage(r){let t=this.ensureSequence(r);this.messages=this.sortMessages([...this.messages,t]),this.callbacks.onMessagesChanged([...this.messages])}upsertMessage(r){let t=this.ensureSequence(r),n=this.messages.findIndex(o=>o.id===t.id);if(n===-1){this.appendMessage(t);return}this.messages=this.messages.map((o,a)=>{var i;if(a!==n)return o;let s={...o,...t};return((i=o.agentMetadata)==null?void 0:i.askUserQuestionAnswered)===!0&&t.agentMetadata&&(s.agentMetadata={...t.agentMetadata,askUserQuestionAnswered:!0,...o.agentMetadata.askUserQuestionAnswers?{askUserQuestionAnswers:o.agentMetadata.askUserQuestionAnswers}:{},awaitingLocalTool:!1}),s}),this.messages=this.sortMessages(this.messages),this.callbacks.onMessagesChanged([...this.messages])}ensureSequence(r){return r.sequence!==void 0?{...r}:{...r,sequence:this.nextSequence()}}nextSequence(){return this.sequenceCounter++}sortMessages(r){return[...r].sort((t,n)=>{var d,l;let o=new Date(t.createdAt).getTime(),a=new Date(n.createdAt).getTime();if(!Number.isNaN(o)&&!Number.isNaN(a)&&o!==a)return o-a;let s=(d=t.sequence)!=null?d:0,i=(l=n.sequence)!=null?l:0;return s!==i?s-i:t.id.localeCompare(n.id)})}};var h=(e,r)=>{let t=document.createElement(e);return r&&(t.className=r),t},qn=(e,r,t)=>{let n=e.createElement(r);return t&&(n.className=t),n};var rd=[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2"}]];var nd=[["path",{d:"M12 5v14"}],["path",{d:"m19 12-7 7-7-7"}]];var od=[["path",{d:"m12 19-7-7 7-7"}],["path",{d:"M19 12H5"}]];var ad=[["path",{d:"M5 12h14"}],["path",{d:"m12 5 7 7-7 7"}]];var sd=[["path",{d:"M7 7h10v10"}],["path",{d:"M7 17 17 7"}]];var id=[["path",{d:"m5 12 7-7 7 7"}],["path",{d:"M12 19V5"}]];var ld=[["circle",{cx:"12",cy:"12",r:"4"}],["path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"}]];var dd=[["path",{d:"M4.929 4.929 19.07 19.071"}],["circle",{cx:"12",cy:"12",r:"10"}]];var cd=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326"}]];var pd=[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"}]];var ud=[["path",{d:"M12 8V4H8"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2"}],["path",{d:"M2 14h2"}],["path",{d:"M20 14h2"}],["path",{d:"M15 13v2"}],["path",{d:"M9 13v2"}]];var fd=[["path",{d:"M12 10h.01"}],["path",{d:"M12 14h.01"}],["path",{d:"M12 6h.01"}],["path",{d:"M16 10h.01"}],["path",{d:"M16 14h.01"}],["path",{d:"M16 6h.01"}],["path",{d:"M8 10h.01"}],["path",{d:"M8 14h.01"}],["path",{d:"M8 6h.01"}],["path",{d:"M9 22v-3a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v3"}],["rect",{x:"4",y:"2",width:"16",height:"20",rx:"2"}]];var md=[["path",{d:"M8 2v4"}],["path",{d:"M16 2v4"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2"}],["path",{d:"M3 10h18"}],["path",{d:"M8 14h.01"}],["path",{d:"M12 14h.01"}],["path",{d:"M16 14h.01"}],["path",{d:"M8 18h.01"}],["path",{d:"M12 18h.01"}],["path",{d:"M16 18h.01"}]];var gd=[["path",{d:"M8 2v4"}],["path",{d:"M16 2v4"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2"}],["path",{d:"M3 10h18"}]];var hd=[["path",{d:"M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z"}],["circle",{cx:"12",cy:"13",r:"3"}]];var xd=[["path",{d:"M20 6 9 17l-5-5"}]];var yd=[["path",{d:"m6 9 6 6 6-6"}]];var bd=[["path",{d:"m15 18-6-6 6-6"}]];var Cd=[["path",{d:"m9 18 6-6-6-6"}]];var wd=[["path",{d:"m18 15-6-6-6 6"}]];var Ri=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"m9 12 2 2 4-4"}]];var Hi=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"m15 9-6 6"}],["path",{d:"m9 9 6 6"}]];var vd=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4"}],["path",{d:"M21 14H11"}],["path",{d:"m15 10-4 4 4 4"}]];var Ad=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"}]];var Sd=[["path",{d:"M12 6v6l4 2"}],["circle",{cx:"12",cy:"12",r:"10"}]];var Td=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"}]];var kd=[["rect",{width:"20",height:"14",x:"2",y:"5",rx:"2"}],["line",{x1:"2",x2:"22",y1:"10",y2:"10"}]];var Ed=[["line",{x1:"12",x2:"12",y1:"2",y2:"22"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"}]];var Md=[["path",{d:"M12 15V3"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}],["path",{d:"m7 10 5 5 5-5"}]];var Bi=[["circle",{cx:"12",cy:"12",r:"1"}],["circle",{cx:"12",cy:"5",r:"1"}],["circle",{cx:"12",cy:"19",r:"1"}]];var Wi=[["circle",{cx:"12",cy:"12",r:"1"}],["circle",{cx:"19",cy:"12",r:"1"}],["circle",{cx:"5",cy:"12",r:"1"}]];var Ld=[["path",{d:"M15 3h6v6"}],["path",{d:"M10 14 21 3"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}]];var Pd=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"}],["path",{d:"m2 2 20 20"}]];var Id=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}],["circle",{cx:"12",cy:"12",r:"3"}]];var Rd=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}],["path",{d:"M10 12.5 8 15l2 2.5"}],["path",{d:"m14 12.5 2 2.5-2 2.5"}]];var Hd=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}],["path",{d:"M8 13h2"}],["path",{d:"M14 13h2"}],["path",{d:"M8 17h2"}],["path",{d:"M14 17h2"}]];var Bd=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}],["path",{d:"M10 9H8"}],["path",{d:"M16 13H8"}],["path",{d:"M16 17H8"}]];var Wd=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}]];var Dd=[["path",{d:"M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8"}],["path",{d:"M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z"}],["path",{d:"M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1"}]];var Od=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}],["path",{d:"M7 3v18"}],["path",{d:"M3 7.5h4"}],["path",{d:"M3 12h18"}],["path",{d:"M3 16.5h4"}],["path",{d:"M17 3v18"}],["path",{d:"M17 7.5h4"}],["path",{d:"M17 16.5h4"}]];var Fd=[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528"}]];var Nd=[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"}]];var _d=[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"}]];var Di=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z"}]];var $d=[["rect",{x:"3",y:"8",width:"18",height:"4",rx:"1"}],["path",{d:"M12 8v13"}],["path",{d:"M19 12v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-7"}],["path",{d:"M7.5 8a2.5 2.5 0 0 1 0-5A4.8 8 0 0 1 12 8a4.8 8 0 0 1 4.5-5 2.5 2.5 0 0 1 0 5"}]];var Ud=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"}],["path",{d:"M2 12h20"}]];var qd=[["line",{x1:"4",x2:"20",y1:"9",y2:"9"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21"}]];var zd=[["path",{d:"M3 14h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-7a9 9 0 0 1 18 0v7a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3"}]];var Vd=[["path",{d:"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5"}]];var jd=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}],["path",{d:"M3 3v5h5"}],["path",{d:"M12 7v5l4 2"}]];var Oi=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}]];var Gd=[["path",{d:"M16 5h6"}],["path",{d:"M19 2v6"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"}],["circle",{cx:"9",cy:"9",r:"2"}]];var Xd=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}],["circle",{cx:"9",cy:"9",r:"2"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"}]];var Jd=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"M12 16v-4"}],["path",{d:"M12 8h.01"}]];var Kd=[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4"}],["path",{d:"m21 2-9.6 9.6"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5"}]];var Yd=[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"}]];var Fi=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56"}]];var Qd=[["path",{d:"M12 2v4"}],["path",{d:"m16.2 7.8 2.9-2.9"}],["path",{d:"M18 12h4"}],["path",{d:"m16.2 16.2 2.9 2.9"}],["path",{d:"M12 18v4"}],["path",{d:"m4.9 19.1 2.9-2.9"}],["path",{d:"M2 12h4"}],["path",{d:"m4.9 4.9 2.9 2.9"}]];var Zd=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4"}]];var ec=[["path",{d:"m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7"}],["rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}]];var tc=[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0"}],["circle",{cx:"12",cy:"10",r:"3"}]];var rc=[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3"}]];var nc=[["path",{d:"M4 5h16"}],["path",{d:"M4 12h16"}],["path",{d:"M4 19h16"}]];var oc=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719"}]];var ac=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z"}]];var sc=[["path",{d:"M12 19v3"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}],["rect",{x:"9",y:"2",width:"6",height:"13",rx:"3"}]];var ic=[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"}]];var lc=[["path",{d:"M5 12h14"}]];var dc=[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21"}]];var cc=[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401"}]];var pc=[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z"}],["path",{d:"M12 22V12"}],["polyline",{points:"3.29 7 12 12 20.71 7"}],["path",{d:"m7.5 4.27 9 5.15"}]];var uc=[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551"}]];var fc=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1"}]];var mc=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"}],["path",{d:"m15 5 4 4"}]];var gc=[["line",{x1:"19",x2:"5",y1:"5",y2:"19"}],["circle",{cx:"6.5",cy:"6.5",r:"2.5"}],["circle",{cx:"17.5",cy:"17.5",r:"2.5"}]];var hc=[["path",{d:"M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384"}]];var xc=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z"}]];var yc=[["path",{d:"M5 12h14"}],["path",{d:"M12 5v14"}]];var bc=[["path",{d:"M4 2v20l2-1 2 1 2-1 2 1 2-1 2 1 2-1 2 1V2l-2 1-2-1-2 1-2-1-2 1-2-1-2 1Z"}],["path",{d:"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8"}],["path",{d:"M12 17.5v-11"}]];var Cc=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"}],["path",{d:"M21 3v5h-5"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"}],["path",{d:"M8 16H3v5"}]];var wc=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}],["path",{d:"M21 3v5h-5"}]];var vc=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7"}]];var Ac=[["path",{d:"m21 21-4.34-4.34"}],["circle",{cx:"11",cy:"11",r:"8"}]];var Sc=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z"}],["path",{d:"m21.854 2.147-10.94 10.939"}]];var Tc=[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"}],["circle",{cx:"12",cy:"12",r:"3"}]];var kc=[["path",{d:"M12 2v13"}],["path",{d:"m16 6-4-4-4 4"}],["path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"}]];var Ec=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"M12 8v4"}],["path",{d:"M12 16h.01"}]];var Mc=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m9 12 2 2 4-4"}]];var Ni=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m14.5 9.5-5 5"}],["path",{d:"m9.5 9.5 5 5"}]];var Lc=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}]];var Pc=[["path",{d:"M16 10a4 4 0 0 1-8 0"}],["path",{d:"M3.103 6.034h17.794"}],["path",{d:"M3.4 5.467a2 2 0 0 0-.4 1.2V20a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6.667a2 2 0 0 0-.4-1.2l-2-2.667A2 2 0 0 0 17 2H7a2 2 0 0 0-1.6.8z"}]];var Ic=[["circle",{cx:"8",cy:"21",r:"1"}],["circle",{cx:"19",cy:"21",r:"1"}],["path",{d:"M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12"}]];var Rc=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2"}],["path",{d:"M12 18h.01"}]];var _i=[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z"}],["path",{d:"M20 2v4"}],["path",{d:"M22 4h-4"}],["circle",{cx:"4",cy:"20",r:"2"}]];var Hc=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}]];var Bc=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z"}]];var Wc=[["path",{d:"M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5"}],["path",{d:"M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244"}],["path",{d:"M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05"}]];var Dc=[["circle",{cx:"12",cy:"12",r:"4"}],["path",{d:"M12 2v2"}],["path",{d:"M12 20v2"}],["path",{d:"m4.93 4.93 1.41 1.41"}],["path",{d:"m17.66 17.66 1.41 1.41"}],["path",{d:"M2 12h2"}],["path",{d:"M20 12h2"}],["path",{d:"m6.34 17.66-1.41 1.41"}],["path",{d:"m19.07 4.93-1.41 1.41"}]];var Oc=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor"}]];var Fc=[["path",{d:"M17 14V2"}],["path",{d:"M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z"}]];var Nc=[["path",{d:"M7 10v12"}],["path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z"}]];var _c=[["line",{x1:"10",x2:"14",y1:"2",y2:"2"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11"}],["circle",{cx:"12",cy:"14",r:"8"}]];var $c=[["path",{d:"M10 11v6"}],["path",{d:"M14 11v6"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"}],["path",{d:"M3 6h18"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}]];var Uc=[["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"}],["path",{d:"M3 6h18"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}]];var $i=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}],["path",{d:"M12 9v4"}],["path",{d:"M12 17h.01"}]];var qc=[["path",{d:"M14 18V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v11a1 1 0 0 0 1 1h2"}],["path",{d:"M15 18H9"}],["path",{d:"M19 18h2a1 1 0 0 0 1-1v-3.65a1 1 0 0 0-.22-.624l-3.48-4.35A1 1 0 0 0 17.52 8H14"}],["circle",{cx:"17",cy:"18",r:"2"}],["circle",{cx:"7",cy:"18",r:"2"}]];var zc=[["path",{d:"M12 3v12"}],["path",{d:"m17 8-5-5-5 5"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}]];var Vc=[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}],["circle",{cx:"12",cy:"7",r:"4"}]];var jc=[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z"}],["path",{d:"M16 9a5 5 0 0 1 0 6"}],["path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728"}]];var Gc=[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z"}],["line",{x1:"22",x2:"16",y1:"9",y2:"15"}],["line",{x1:"16",x2:"22",y1:"9",y2:"15"}]];var Xc=[["path",{d:"M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1"}],["path",{d:"M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4"}]];var Jc=[["path",{d:"M18 6 6 18"}],["path",{d:"m6 6 12 12"}]];var Kc=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z"}]];var ub={activity:rd,"arrow-down":nd,"arrow-up":id,"arrow-up-right":sd,bot:ud,"chevron-down":yd,"chevron-up":wd,"chevron-right":Cd,"chevron-left":bd,check:xd,clipboard:Ad,"clipboard-copy":vd,copy:Td,file:Wd,"file-code":Rd,"file-spreadsheet":Hd,"file-text":Bd,"image-plus":Gd,loader:Qd,"loader-circle":Fi,mic:sc,paperclip:uc,"refresh-cw":Cc,search:Ac,send:Sc,"shield-alert":Ec,"shield-check":Mc,"shield-x":Ni,square:Hc,"thumbs-down":Fc,"thumbs-up":Nc,upload:zc,"volume-2":jc,x:Jc,user:Vc,mail:ec,phone:hc,calendar:gd,clock:Sd,building:fd,"map-pin":tc,lock:Zd,key:Kd,"credit-card":kd,"at-sign":ld,hash:qd,globe:Ud,link:Yd,"circle-check":Ri,"circle-x":Hi,"triangle-alert":$i,info:Jd,ban:dd,shield:Lc,"arrow-left":od,"arrow-right":ad,"external-link":Ld,ellipsis:Wi,"ellipsis-vertical":Bi,menu:nc,house:Oi,plus:yc,minus:lc,pencil:mc,trash:Uc,"trash-2":$c,save:vc,download:Md,share:kc,funnel:Di,settings:Tc,"rotate-cw":wc,maximize:rc,minimize:ic,"shopping-cart":Ic,"shopping-bag":Pc,package:pc,truck:qc,tag:Oc,gift:$d,receipt:bc,wallet:Xc,store:Wc,"dollar-sign":Ed,percent:gc,play:xc,pause:fc,"volume-x":Gc,camera:hd,image:Xd,film:Od,headphones:zd,"message-circle":oc,"message-square":ac,bell:cd,heart:Vd,star:Bc,eye:Id,"eye-off":Pd,bookmark:pd,"calendar-days":md,history:jd,timer:_c,folder:_d,"folder-open":Nd,files:Dd,sparkles:_i,zap:Kc,sun:Dc,moon:cc,flag:Fd,monitor:dc,smartphone:Rc},ve=(e,r=24,t="currentColor",n=2)=>{let o=ub[e];return o?fb(o,r,t,n):(console.warn(`Lucide icon "${e}" is not in the Persona registry. Add it to packages/widget/src/utils/icons.ts (see docs/icon-registry-shortlist.md).`),null)};function fb(e,r,t,n){if(!Array.isArray(e))return null;let o=document.createElementNS("http://www.w3.org/2000/svg","svg");return o.setAttribute("width",String(r)),o.setAttribute("height",String(r)),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none"),o.setAttribute("stroke",t),o.setAttribute("stroke-width",String(n)),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"),o.setAttribute("aria-hidden","true"),e.forEach(a=>{if(!Array.isArray(a)||a.length<2)return;let s=a[0],i=a[1];if(!i)return;let d=document.createElementNS("http://www.w3.org/2000/svg",s);Object.entries(i).forEach(([l,u])=>{l!=="stroke"&&d.setAttribute(l,String(u))}),o.appendChild(d)}),o}var Ui={allowedTypes:no,maxFileSize:10*1024*1024,maxFiles:4};function mb(){return`attach_${Date.now()}_${Math.random().toString(36).substring(2,9)}`}function gb(e){return e==="application/pdf"||e.startsWith("text/")||e.includes("word")?"file-text":e.includes("excel")||e.includes("spreadsheet")?"file-spreadsheet":e==="application/json"?"file-code":"file"}var ta=class e{constructor(r={}){this.attachments=[];this.previewsContainer=null;var t,n,o;this.config={allowedTypes:(t=r.allowedTypes)!=null?t:Ui.allowedTypes,maxFileSize:(n=r.maxFileSize)!=null?n:Ui.maxFileSize,maxFiles:(o=r.maxFiles)!=null?o:Ui.maxFiles,onFileRejected:r.onFileRejected,onAttachmentsChange:r.onAttachmentsChange}}setPreviewsContainer(r){this.previewsContainer=r}updateConfig(r){r.allowedTypes!==void 0&&(this.config.allowedTypes=r.allowedTypes.length>0?r.allowedTypes:Ui.allowedTypes),r.maxFileSize!==void 0&&(this.config.maxFileSize=r.maxFileSize),r.maxFiles!==void 0&&(this.config.maxFiles=r.maxFiles),r.onFileRejected!==void 0&&(this.config.onFileRejected=r.onFileRejected),r.onAttachmentsChange!==void 0&&(this.config.onAttachmentsChange=r.onAttachmentsChange)}getAttachments(){return[...this.attachments]}getContentParts(){return this.attachments.map(r=>r.contentPart)}hasAttachments(){return this.attachments.length>0}count(){return this.attachments.length}async handleFileSelect(r){!r||r.length===0||await this.handleFiles(Array.from(r))}async handleFiles(r){var t,n,o,a,s,i,d;if(r.length){for(let l of r){if(this.attachments.length>=this.config.maxFiles){(n=(t=this.config).onFileRejected)==null||n.call(t,l,"count");continue}let u=$g(l,this.config.allowedTypes,this.config.maxFileSize);if(!u.valid){let p=(o=u.error)!=null&&o.includes("type")?"type":"size";(s=(a=this.config).onFileRejected)==null||s.call(a,l,p);continue}try{let p=await _g(l),f=Mi(l)?URL.createObjectURL(l):null,m={id:mb(),file:l,previewUrl:f,contentPart:p};this.attachments.push(m),this.renderPreview(m)}catch(p){console.error("[AttachmentManager] Failed to process file:",p)}}this.updatePreviewsVisibility(),(d=(i=this.config).onAttachmentsChange)==null||d.call(i,this.getAttachments())}}removeAttachment(r){var a,s,i;let t=this.attachments.findIndex(d=>d.id===r);if(t===-1)return;let n=this.attachments[t];n.previewUrl&&URL.revokeObjectURL(n.previewUrl),this.attachments.splice(t,1);let o=(a=this.previewsContainer)==null?void 0:a.querySelector(`[data-attachment-id="${r}"]`);o&&o.remove(),this.updatePreviewsVisibility(),(i=(s=this.config).onAttachmentsChange)==null||i.call(s,this.getAttachments())}clearAttachments(){var r,t;for(let n of this.attachments)n.previewUrl&&URL.revokeObjectURL(n.previewUrl);this.attachments=[],this.previewsContainer&&(this.previewsContainer.innerHTML=""),this.updatePreviewsVisibility(),(t=(r=this.config).onAttachmentsChange)==null||t.call(r,this.getAttachments())}renderPreview(r){if(!this.previewsContainer)return;let t=Mi(r.file),n=h("div","persona-attachment-preview persona-relative persona-inline-block");if(n.setAttribute("data-attachment-id",r.id),n.style.width="48px",n.style.height="48px",t&&r.previewUrl){let s=h("img");s.src=r.previewUrl,s.alt=r.file.name,s.className="persona-w-full persona-h-full persona-object-cover persona-rounded-lg persona-border persona-border-gray-200",s.style.width="48px",s.style.height="48px",s.style.objectFit="cover",s.style.borderRadius="8px",n.appendChild(s)}else{let s=h("div");s.style.width="48px",s.style.height="48px",s.style.borderRadius="8px",s.style.backgroundColor="var(--persona-container, #f3f4f6)",s.style.border="1px solid var(--persona-border, #e5e7eb)",s.style.display="flex",s.style.flexDirection="column",s.style.alignItems="center",s.style.justifyContent="center",s.style.gap="2px",s.style.overflow="hidden";let i=gb(r.file.type),d=ve(i,20,"var(--persona-muted, #6b7280)",1.5);d&&s.appendChild(d);let l=h("span");l.textContent=Ug(r.file.type,r.file.name),l.style.fontSize="8px",l.style.fontWeight="600",l.style.color="var(--persona-muted, #6b7280)",l.style.textTransform="uppercase",l.style.lineHeight="1",s.appendChild(l),n.appendChild(s)}let o=h("button","persona-attachment-remove persona-absolute persona-flex persona-items-center persona-justify-center");o.type="button",o.setAttribute("aria-label","Remove attachment"),o.style.position="absolute",o.style.top="-4px",o.style.right="-4px",o.style.width="18px",o.style.height="18px",o.style.borderRadius="50%",o.style.backgroundColor="var(--persona-palette-colors-black-alpha-60, rgba(0, 0, 0, 0.6))",o.style.border="none",o.style.cursor="pointer",o.style.display="flex",o.style.alignItems="center",o.style.justifyContent="center",o.style.padding="0";let a=ve("x",10,"var(--persona-text-inverse, #ffffff)",2);a?o.appendChild(a):(o.textContent="\xD7",o.style.color="var(--persona-text-inverse, #ffffff)",o.style.fontSize="14px",o.style.lineHeight="1"),o.addEventListener("click",s=>{s.preventDefault(),s.stopPropagation(),this.removeAttachment(r.id)}),n.appendChild(o),this.previewsContainer.appendChild(n)}updatePreviewsVisibility(){this.previewsContainer&&(this.previewsContainer.style.display=this.attachments.length>0?"flex":"none")}static fromConfig(r,t){return new e({allowedTypes:r==null?void 0:r.allowedTypes,maxFileSize:r==null?void 0:r.maxFileSize,maxFiles:r==null?void 0:r.maxFiles,onFileRejected:r==null?void 0:r.onFileRejected,onAttachmentsChange:t})}};var qg=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function bs(e,r){if(!e)return r;if(!r)return e;let t={...e};for(let[n,o]of Object.entries(r)){let a=t[n];qg(a)&&qg(o)?t[n]=bs(a,o):t[n]=o}return t}var mn="min(440px, calc(100vw - 24px))",qi="440px",Gt={apiUrl:"https://api.runtype.com/api/chat/dispatch",clientToken:void 0,theme:void 0,darkTheme:void 0,colorScheme:"light",launcher:{enabled:!0,mountMode:"floating",dock:{side:"right",width:"420px"},title:"Chat Assistant",subtitle:"Here to help you get answers fast",agentIconText:"\u{1F4AC}",agentIconName:"bot",headerIconName:"bot",position:"bottom-right",width:mn,heightOffset:0,autoExpand:!1,callToActionIconHidden:!1,agentIconSize:"40px",headerIconSize:"40px",closeButtonSize:"32px",closeButtonPaddingX:"0px",closeButtonPaddingY:"0px",callToActionIconName:"arrow-up-right",callToActionIconText:"",callToActionIconSize:"32px",callToActionIconPadding:"5px",callToActionIconColor:void 0,callToActionIconBackgroundColor:void 0,closeButtonBackgroundColor:"transparent",clearChat:{backgroundColor:"transparent",borderColor:"transparent",enabled:!0,placement:"inline",iconName:"refresh-cw",size:"32px",showTooltip:!0,tooltipText:"Clear chat",paddingX:"0px",paddingY:"0px"},headerIconHidden:!1,border:void 0,shadow:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)"},copy:{welcomeTitle:"Hello \u{1F44B}",welcomeSubtitle:"Ask anything about your account or products.",inputPlaceholder:"How can I help...",sendButtonLabel:"Send"},sendButton:{borderWidth:"0px",paddingX:"12px",paddingY:"10px",borderColor:void 0,useIcon:!0,iconText:"\u2191",size:"40px",showTooltip:!0,tooltipText:"Send message",iconName:"send"},statusIndicator:{visible:!0,idleText:"Online",connectingText:"Connecting\u2026",connectedText:"Streaming\u2026",errorText:"Offline"},voiceRecognition:{enabled:!0,pauseDuration:2e3,iconName:"mic",iconSize:"39px",borderWidth:"0px",paddingX:"9px",paddingY:"14px",iconColor:void 0,backgroundColor:"transparent",borderColor:"transparent",recordingIconColor:void 0,recordingBackgroundColor:void 0,recordingBorderColor:"transparent",showTooltip:!0,tooltipText:"Start voice recognition"},features:{showReasoning:!0,showToolCalls:!0,scrollToBottom:{enabled:!0,iconName:"arrow-down",label:""},toolCallDisplay:{collapsedMode:"tool-call",activePreview:!1,grouped:!1,previewMaxLines:3,expandable:!0,loadingAnimation:"none"},reasoningDisplay:{activePreview:!1,previewMaxLines:3,expandable:!0,loadingAnimation:"none"},streamAnimation:{type:"none",placeholder:"none",speed:120,duration:1800},askUserQuestion:{enabled:!0,slideInMs:180,freeTextLabel:"Other\u2026",freeTextPlaceholder:"Type your answer\u2026",submitLabel:"Send"}},suggestionChips:["What can you help me with?","Tell me about your features","How does this work?"],suggestionChipsConfig:{fontFamily:"sans-serif",fontWeight:"500",paddingX:"12px",paddingY:"6px"},layout:{header:{layout:"default",showIcon:!0,showTitle:!0,showSubtitle:!0,showCloseButton:!0,showClearChat:!0},messages:{layout:"bubble",avatar:{show:!1,position:"left"},timestamp:{show:!1,position:"below"},groupConsecutive:!1},slots:{}},markdown:{options:{gfm:!0,breaks:!0},disableDefaultStyles:!1},messageActions:{enabled:!0,showCopy:!0,showUpvote:!1,showDownvote:!1,visibility:"hover",align:"right",layout:"pill-inside"},debug:!1};function zg(e,r){if(!(!e&&!r))return e?r?bs(e,r):e:r}function zi(e){var r,t,n,o,a,s,i,d,l,u,p,f,m,C,w,k,T,S,E,v,b;return e?{...Gt,...e,theme:zg(Gt.theme,e.theme),darkTheme:zg(Gt.darkTheme,e.darkTheme),launcher:{...Gt.launcher,...e.launcher,dock:{...(r=Gt.launcher)==null?void 0:r.dock,...(t=e.launcher)==null?void 0:t.dock},clearChat:{...(n=Gt.launcher)==null?void 0:n.clearChat,...(o=e.launcher)==null?void 0:o.clearChat}},copy:{...Gt.copy,...e.copy},sendButton:{...Gt.sendButton,...e.sendButton},statusIndicator:{...Gt.statusIndicator,...e.statusIndicator},voiceRecognition:{...Gt.voiceRecognition,...e.voiceRecognition},features:(()=>{var me,Re,Ge,Y,Ee,G,ce,de;let y=(me=Gt.features)==null?void 0:me.artifacts,M=(Re=e.features)==null?void 0:Re.artifacts,H=(Ge=Gt.features)==null?void 0:Ge.scrollToBottom,B=(Y=e.features)==null?void 0:Y.scrollToBottom,R=(Ee=Gt.features)==null?void 0:Ee.streamAnimation,W=(G=e.features)==null?void 0:G.streamAnimation,V=(ce=Gt.features)==null?void 0:ce.askUserQuestion,ne=(de=e.features)==null?void 0:de.askUserQuestion,ue=y===void 0&&M===void 0?void 0:{...y,...M,layout:{...y==null?void 0:y.layout,...M==null?void 0:M.layout}},We=H===void 0&&B===void 0?void 0:{...H,...B},Ke=R===void 0&&W===void 0?void 0:{...R,...W},xe=V===void 0&&ne===void 0?void 0:{...V,...ne,styles:{...V==null?void 0:V.styles,...ne==null?void 0:ne.styles}};return{...Gt.features,...e.features,...We!==void 0?{scrollToBottom:We}:{},...ue!==void 0?{artifacts:ue}:{},...Ke!==void 0?{streamAnimation:Ke}:{},...xe!==void 0?{askUserQuestion:xe}:{}}})(),suggestionChips:(a=e.suggestionChips)!=null?a:Gt.suggestionChips,suggestionChipsConfig:{...Gt.suggestionChipsConfig,...e.suggestionChipsConfig},layout:{...Gt.layout,...e.layout,header:{...(s=Gt.layout)==null?void 0:s.header,...(i=e.layout)==null?void 0:i.header},messages:{...(d=Gt.layout)==null?void 0:d.messages,...(l=e.layout)==null?void 0:l.messages,avatar:{...(p=(u=Gt.layout)==null?void 0:u.messages)==null?void 0:p.avatar,...(m=(f=e.layout)==null?void 0:f.messages)==null?void 0:m.avatar},timestamp:{...(w=(C=Gt.layout)==null?void 0:C.messages)==null?void 0:w.timestamp,...(T=(k=e.layout)==null?void 0:k.messages)==null?void 0:T.timestamp}},slots:{...(S=Gt.layout)==null?void 0:S.slots,...(E=e.layout)==null?void 0:E.slots}},markdown:{...Gt.markdown,...e.markdown,options:{...(v=Gt.markdown)==null?void 0:v.options,...(b=e.markdown)==null?void 0:b.options}},messageActions:{...Gt.messageActions,...e.messageActions}}:Gt}var Yc={colors:{primary:{50:"#ffffff",100:"#f5f5f5",200:"#d4d4d4",300:"#a3a3a3",400:"#737373",500:"#171717",600:"#0f0f0f",700:"#0a0a0a",800:"#050505",900:"#030303",950:"#000000"},secondary:{50:"#f5f3ff",100:"#ede9fe",200:"#ddd6fe",300:"#c4b5fd",400:"#a78bfa",500:"#8b5cf6",600:"#7c3aed",700:"#6d28d9",800:"#5b21b6",900:"#4c1d95",950:"#2e1065"},accent:{50:"#ecfeff",100:"#cffafe",200:"#a5f3fc",300:"#67e8f9",400:"#22d3ee",500:"#06b6d4",600:"#0891b2",700:"#0e7490",800:"#155e75",900:"#164e63",950:"#083344"},gray:{50:"#f9fafb",100:"#f3f4f6",200:"#e5e7eb",300:"#d1d5db",400:"#9ca3af",500:"#6b7280",600:"#4b5563",700:"#374151",800:"#1f2937",900:"#111827",950:"#030712"},success:{50:"#f0fdf4",100:"#dcfce7",200:"#bbf7d0",300:"#86efac",400:"#4ade80",500:"#22c55e",600:"#16a34a",700:"#15803d",800:"#166534",900:"#14532d"},warning:{50:"#fefce8",100:"#fef9c3",200:"#fef08a",300:"#fde047",400:"#facc15",500:"#eab308",600:"#ca8a04",700:"#a16207",800:"#854d0e",900:"#713f12"},error:{50:"#fef2f2",100:"#fee2e2",200:"#fecaca",300:"#fca5a5",400:"#f87171",500:"#ef4444",600:"#dc2626",700:"#b91c1c",800:"#991b1b",900:"#7f1d1d"},info:{50:"#eff6ff",100:"#dbeafe",200:"#bfdbfe",300:"#93c5fd",400:"#60a5fa",500:"#3b82f6",600:"#2563eb",700:"#1d4ed8",800:"#1e40af",900:"#1e3a8a",950:"#172554"}},spacing:{0:"0px",1:"0.25rem",2:"0.5rem",3:"0.75rem",4:"1rem",5:"1.25rem",6:"1.5rem",8:"2rem",10:"2.5rem",12:"3rem",16:"4rem",20:"5rem",24:"6rem",32:"8rem",40:"10rem",48:"12rem",56:"14rem",64:"16rem"},typography:{fontFamily:{sans:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',serif:'Georgia, Cambria, "Times New Roman", Times, serif',mono:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace"},fontSize:{xs:"0.75rem",sm:"0.875rem",base:"1rem",lg:"1.125rem",xl:"1.25rem","2xl":"1.5rem","3xl":"1.875rem","4xl":"2.25rem"},fontWeight:{normal:"400",medium:"500",semibold:"600",bold:"700"},lineHeight:{tight:"1.25",normal:"1.5",relaxed:"1.625"}},shadows:{none:"none",sm:"0 1px 2px 0 rgb(0 0 0 / 0.05)",md:"0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)",lg:"0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)",xl:"0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)","2xl":"0 25px 50px -12px rgb(0 0 0 / 0.25)"},borders:{none:"none",sm:"1px solid",md:"2px solid",lg:"4px solid"},radius:{none:"0px",sm:"0.125rem",md:"0.375rem",lg:"0.5rem",xl:"0.75rem","2xl":"1rem",full:"9999px"}},Qc={colors:{primary:"palette.colors.primary.500",secondary:"palette.colors.secondary.500",accent:"palette.colors.primary.600",surface:"palette.colors.gray.50",background:"palette.colors.gray.50",container:"palette.colors.gray.50",text:"palette.colors.gray.900",textMuted:"palette.colors.gray.500",textInverse:"palette.colors.gray.50",border:"palette.colors.gray.200",divider:"palette.colors.gray.200",interactive:{default:"palette.colors.primary.600",hover:"palette.colors.primary.700",focus:"palette.colors.primary.600",active:"palette.colors.primary.600",disabled:"palette.colors.gray.300"},feedback:{success:"palette.colors.success.500",warning:"palette.colors.warning.500",error:"palette.colors.error.500",info:"palette.colors.info.500"}},spacing:{xs:"palette.spacing.1",sm:"palette.spacing.2",md:"palette.spacing.4",lg:"palette.spacing.6",xl:"palette.spacing.8","2xl":"palette.spacing.10"},typography:{fontFamily:"palette.typography.fontFamily.sans",fontSize:"palette.typography.fontSize.base",fontWeight:"palette.typography.fontWeight.normal",lineHeight:"palette.typography.lineHeight.normal"}},Zc={button:{primary:{background:"palette.colors.primary.500",foreground:"palette.colors.primary.50",borderRadius:"palette.radius.lg",padding:"semantic.spacing.md"},secondary:{background:"semantic.colors.surface",foreground:"semantic.colors.secondary",borderRadius:"palette.radius.lg",padding:"semantic.spacing.md"},ghost:{background:"transparent",foreground:"semantic.colors.text",borderRadius:"palette.radius.md",padding:"semantic.spacing.sm"}},input:{background:"palette.colors.gray.50",placeholder:"palette.colors.gray.400",borderRadius:"palette.radius.lg",padding:"semantic.spacing.md",focus:{border:"palette.colors.gray.400",ring:"palette.colors.gray.400"}},launcher:{background:"palette.colors.primary.500",foreground:"palette.colors.primary.50",border:"palette.colors.gray.200",size:"60px",iconSize:"28px",borderRadius:"palette.radius.full",shadow:"palette.shadows.lg"},panel:{width:mn,maxWidth:qi,height:"600px",maxHeight:"calc(100vh - 80px)",borderRadius:"palette.radius.xl",shadow:"palette.shadows.xl"},header:{background:"palette.colors.primary.500",border:"palette.colors.primary.600",borderRadius:"palette.radius.xl palette.radius.xl 0 0",padding:"semantic.spacing.md",iconBackground:"palette.colors.primary.600",iconForeground:"palette.colors.primary.50",titleForeground:"palette.colors.primary.50",subtitleForeground:"palette.colors.primary.200",actionIconForeground:"palette.colors.primary.200"},message:{user:{background:"palette.colors.primary.500",text:"palette.colors.primary.50",borderRadius:"palette.radius.lg",shadow:"palette.shadows.sm"},assistant:{background:"palette.colors.gray.50",text:"palette.colors.gray.900",borderRadius:"palette.radius.lg",border:"palette.colors.gray.200",shadow:"palette.shadows.sm"},border:"semantic.colors.border"},introCard:{background:"semantic.colors.surface",borderRadius:"palette.radius.2xl",padding:"semantic.spacing.lg",shadow:"0 5px 15px rgba(15, 23, 42, 0.08)"},toolBubble:{shadow:"palette.shadows.sm"},reasoningBubble:{shadow:"palette.shadows.sm"},composer:{shadow:"none"},markdown:{inlineCode:{background:"palette.colors.gray.50",foreground:"palette.colors.gray.900"},link:{foreground:"palette.colors.primary.600"},prose:{fontFamily:"inherit"},codeBlock:{background:"semantic.colors.container",borderColor:"semantic.colors.border",textColor:"inherit"},table:{headerBackground:"semantic.colors.container",borderColor:"semantic.colors.border"},hr:{color:"semantic.colors.divider"},blockquote:{borderColor:"palette.colors.gray.900",background:"transparent",textColor:"palette.colors.gray.500"}},collapsibleWidget:{container:"palette.colors.gray.50",surface:"semantic.colors.surface",border:"semantic.colors.border"},voice:{recording:{indicator:"palette.colors.error.500",background:"palette.colors.error.50",border:"palette.colors.error.200"},processing:{icon:"palette.colors.primary.500",background:"palette.colors.primary.50"},speaking:{icon:"palette.colors.success.500"}},approval:{requested:{background:"palette.colors.warning.50",border:"palette.colors.warning.200",text:"palette.colors.gray.900"},approve:{background:"palette.colors.success.500",foreground:"palette.colors.gray.50",borderRadius:"palette.radius.md",padding:"semantic.spacing.sm"},deny:{background:"palette.colors.error.500",foreground:"palette.colors.gray.50",borderRadius:"palette.radius.md",padding:"semantic.spacing.sm"}},attachment:{image:{background:"palette.colors.gray.100",border:"palette.colors.gray.200"}},scrollToBottom:{background:"components.button.primary.background",foreground:"components.button.primary.foreground",border:"semantic.colors.primary",size:"40px",borderRadius:"palette.radius.full",shadow:"palette.shadows.sm",padding:"0.5rem 0.875rem",gap:"0.5rem",fontSize:"0.875rem",iconSize:"14px"},artifact:{pane:{background:"semantic.colors.container",toolbarBackground:"semantic.colors.container"}}};function Aa(e,r){if(!r.startsWith("palette.")&&!r.startsWith("semantic.")&&!r.startsWith("components."))return r;let t=r.split("."),n=e;for(let o of t){if(n==null)return;n=n[o]}return typeof n=="string"&&(n.startsWith("palette.")||n.startsWith("semantic.")||n.startsWith("components."))?Aa(e,n):n}function Vi(e){let r={};function t(n,o){for(let[a,s]of Object.entries(n)){let i=`${o}.${a}`;if(typeof s=="string"){let d=Aa(e,s);d!==void 0&&(r[i]={path:i,value:d,type:o.includes("color")?"color":o.includes("spacing")?"spacing":o.includes("typography")?"typography":o.includes("shadow")?"shadow":o.includes("border")?"border":"color"})}else typeof s=="object"&&s!==null&&t(s,i)}}return t(e.palette,"palette"),t(e.semantic,"semantic"),t(e.components,"components"),r}function ep(e){let r=[],t=[];return e.palette||r.push({path:"palette",message:"Theme must include a palette",severity:"error"}),e.semantic||t.push({path:"semantic",message:"No semantic tokens defined - defaults will be used",severity:"warning"}),e.components||t.push({path:"components",message:"No component tokens defined - defaults will be used",severity:"warning"}),{valid:r.length===0,errors:r,warnings:t}}function Vg(e,r){let t={...e};for(let[n,o]of Object.entries(r)){let a=t[n];a&&typeof a=="object"&&!Array.isArray(a)&&o&&typeof o=="object"&&!Array.isArray(o)?t[n]=Vg(a,o):t[n]=o}return t}function hb(e,r){return r?Vg(e,r):e}function Sa(e,r={}){var o,a,s,i,d,l,u,p,f,m,C,w,k;let t={palette:Yc,semantic:Qc,components:Zc},n={palette:{...t.palette,...e==null?void 0:e.palette,colors:{...t.palette.colors,...(o=e==null?void 0:e.palette)==null?void 0:o.colors},spacing:{...t.palette.spacing,...(a=e==null?void 0:e.palette)==null?void 0:a.spacing},typography:{...t.palette.typography,...(s=e==null?void 0:e.palette)==null?void 0:s.typography},shadows:{...t.palette.shadows,...(i=e==null?void 0:e.palette)==null?void 0:i.shadows},borders:{...t.palette.borders,...(d=e==null?void 0:e.palette)==null?void 0:d.borders},radius:{...t.palette.radius,...(l=e==null?void 0:e.palette)==null?void 0:l.radius}},semantic:{...t.semantic,...e==null?void 0:e.semantic,colors:{...t.semantic.colors,...(u=e==null?void 0:e.semantic)==null?void 0:u.colors,interactive:{...t.semantic.colors.interactive,...(f=(p=e==null?void 0:e.semantic)==null?void 0:p.colors)==null?void 0:f.interactive},feedback:{...t.semantic.colors.feedback,...(C=(m=e==null?void 0:e.semantic)==null?void 0:m.colors)==null?void 0:C.feedback}},spacing:{...t.semantic.spacing,...(w=e==null?void 0:e.semantic)==null?void 0:w.spacing},typography:{...t.semantic.typography,...(k=e==null?void 0:e.semantic)==null?void 0:k.typography}},components:hb(t.components,e==null?void 0:e.components)};if(r.validate!==!1){let T=ep(n);if(!T.valid)throw new Error(`Theme validation failed: ${T.errors.map(S=>S.message).join(", ")}`)}if(r.plugins)for(let T of r.plugins)n=T.transform(n);return n}function ji(e){var w,k,T,S,E,v,b,y,M,H,B,R,W,V,ne,ue,We,Ke,xe,me,Re,Ge,Y,Ee,G,ce,de,pe,He,Ye,J,ie,Ue,K,j,Ce,De,oe,Se,ge,Rt,Me,ae,ur,Ut,Qt,Or,vr,Oe,q,Te,_e,Ne,qe,st,nt,pt,Nt,F,ye,be,it,Xe,Wt,ar,Pt,kt,rt,lt,rr,gn,Ir,Tn,Et,hn,pr,Ar,Kr,bt,kn,nn,Sr,Tr,Vn,En,xn,vt,Pe,P,Z,se,Mt,zt,Ht,sr,xr,Fr,kr,ot,wr,Nr,co,jn,po,Fn,on,Mn,At,ir,lr,an,uo,yn,Ln,sn,z;let r=Vi(e),t={};for(let[he,ln]of Object.entries(r)){let Pn=he.replace(/\./g,"-");t[`--persona-${Pn}`]=ln.value}t["--persona-primary"]=(w=t["--persona-semantic-colors-primary"])!=null?w:t["--persona-palette-colors-primary-500"],t["--persona-secondary"]=(k=t["--persona-semantic-colors-secondary"])!=null?k:t["--persona-palette-colors-secondary-500"],t["--persona-accent"]=(T=t["--persona-semantic-colors-accent"])!=null?T:t["--persona-palette-colors-accent-500"],t["--persona-surface"]=(S=t["--persona-semantic-colors-surface"])!=null?S:t["--persona-palette-colors-gray-50"],t["--persona-background"]=(E=t["--persona-semantic-colors-background"])!=null?E:t["--persona-palette-colors-gray-50"],t["--persona-container"]=(v=t["--persona-semantic-colors-container"])!=null?v:t["--persona-palette-colors-gray-100"],t["--persona-text"]=(b=t["--persona-semantic-colors-text"])!=null?b:t["--persona-palette-colors-gray-900"],t["--persona-text-muted"]=(y=t["--persona-semantic-colors-text-muted"])!=null?y:t["--persona-palette-colors-gray-500"],t["--persona-text-inverse"]=(M=t["--persona-semantic-colors-text-inverse"])!=null?M:t["--persona-palette-colors-gray-50"],t["--persona-border"]=(H=t["--persona-semantic-colors-border"])!=null?H:t["--persona-palette-colors-gray-200"],t["--persona-divider"]=(B=t["--persona-semantic-colors-divider"])!=null?B:t["--persona-palette-colors-gray-200"],t["--persona-muted"]=t["--persona-text-muted"],t["--persona-voice-recording-indicator"]=(R=t["--persona-components-voice-recording-indicator"])!=null?R:t["--persona-palette-colors-error-500"],t["--persona-voice-recording-bg"]=(W=t["--persona-components-voice-recording-background"])!=null?W:t["--persona-palette-colors-error-50"],t["--persona-voice-processing-icon"]=(V=t["--persona-components-voice-processing-icon"])!=null?V:t["--persona-palette-colors-primary-500"],t["--persona-voice-speaking-icon"]=(ne=t["--persona-components-voice-speaking-icon"])!=null?ne:t["--persona-palette-colors-success-500"],t["--persona-approval-bg"]=(ue=t["--persona-components-approval-requested-background"])!=null?ue:t["--persona-palette-colors-warning-50"],t["--persona-approval-border"]=(We=t["--persona-components-approval-requested-border"])!=null?We:t["--persona-palette-colors-warning-200"],t["--persona-approval-text"]=(Ke=t["--persona-components-approval-requested-text"])!=null?Ke:t["--persona-palette-colors-gray-900"],t["--persona-approval-approve-bg"]=(xe=t["--persona-components-approval-approve-background"])!=null?xe:t["--persona-palette-colors-success-500"],t["--persona-approval-deny-bg"]=(me=t["--persona-components-approval-deny-background"])!=null?me:t["--persona-palette-colors-error-500"],t["--persona-attachment-image-bg"]=(Re=t["--persona-components-attachment-image-background"])!=null?Re:t["--persona-palette-colors-gray-100"],t["--persona-attachment-image-border"]=(Ge=t["--persona-components-attachment-image-border"])!=null?Ge:t["--persona-palette-colors-gray-200"],t["--persona-font-family"]=(Y=t["--persona-semantic-typography-fontFamily"])!=null?Y:t["--persona-palette-typography-fontFamily-sans"],t["--persona-font-size"]=(Ee=t["--persona-semantic-typography-fontSize"])!=null?Ee:t["--persona-palette-typography-fontSize-base"],t["--persona-font-weight"]=(G=t["--persona-semantic-typography-fontWeight"])!=null?G:t["--persona-palette-typography-fontWeight-normal"],t["--persona-line-height"]=(ce=t["--persona-semantic-typography-lineHeight"])!=null?ce:t["--persona-palette-typography-lineHeight-normal"],t["--persona-input-font-family"]=t["--persona-font-family"],t["--persona-input-font-weight"]=t["--persona-font-weight"],t["--persona-radius-sm"]=(de=t["--persona-palette-radius-sm"])!=null?de:"0.125rem",t["--persona-radius-md"]=(pe=t["--persona-palette-radius-md"])!=null?pe:"0.375rem",t["--persona-radius-lg"]=(He=t["--persona-palette-radius-lg"])!=null?He:"0.5rem",t["--persona-radius-xl"]=(Ye=t["--persona-palette-radius-xl"])!=null?Ye:"0.75rem",t["--persona-radius-full"]=(J=t["--persona-palette-radius-full"])!=null?J:"9999px",t["--persona-launcher-radius"]=(Ue=(ie=t["--persona-components-launcher-borderRadius"])!=null?ie:t["--persona-palette-radius-full"])!=null?Ue:"9999px",t["--persona-launcher-bg"]=(K=t["--persona-components-launcher-background"])!=null?K:t["--persona-primary"],t["--persona-launcher-fg"]=(j=t["--persona-components-launcher-foreground"])!=null?j:t["--persona-text-inverse"],t["--persona-launcher-border"]=(Ce=t["--persona-components-launcher-border"])!=null?Ce:t["--persona-border"],t["--persona-button-primary-bg"]=(De=t["--persona-components-button-primary-background"])!=null?De:t["--persona-primary"],t["--persona-button-primary-fg"]=(oe=t["--persona-components-button-primary-foreground"])!=null?oe:t["--persona-text-inverse"],t["--persona-button-radius"]=(ge=(Se=t["--persona-components-button-primary-borderRadius"])!=null?Se:t["--persona-palette-radius-full"])!=null?ge:"9999px",t["--persona-panel-radius"]=(Me=(Rt=t["--persona-components-panel-borderRadius"])!=null?Rt:t["--persona-radius-xl"])!=null?Me:"0.75rem",t["--persona-panel-border"]=(ae=t["--persona-components-panel-border"])!=null?ae:`1px solid ${t["--persona-border"]}`,t["--persona-panel-shadow"]=(Ut=(ur=t["--persona-components-panel-shadow"])!=null?ur:t["--persona-palette-shadows-xl"])!=null?Ut:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",t["--persona-input-radius"]=(Or=(Qt=t["--persona-components-input-borderRadius"])!=null?Qt:t["--persona-radius-lg"])!=null?Or:"0.5rem",t["--persona-message-user-radius"]=(Oe=(vr=t["--persona-components-message-user-borderRadius"])!=null?vr:t["--persona-radius-lg"])!=null?Oe:"0.5rem",t["--persona-message-assistant-radius"]=(Te=(q=t["--persona-components-message-assistant-borderRadius"])!=null?q:t["--persona-radius-lg"])!=null?Te:"0.5rem",t["--persona-header-bg"]=(_e=t["--persona-components-header-background"])!=null?_e:t["--persona-surface"],t["--persona-header-border"]=(Ne=t["--persona-components-header-border"])!=null?Ne:t["--persona-divider"],t["--persona-header-icon-bg"]=(qe=t["--persona-components-header-iconBackground"])!=null?qe:t["--persona-primary"],t["--persona-header-icon-fg"]=(st=t["--persona-components-header-iconForeground"])!=null?st:t["--persona-text-inverse"],t["--persona-header-title-fg"]=(nt=t["--persona-components-header-titleForeground"])!=null?nt:t["--persona-primary"],t["--persona-header-subtitle-fg"]=(pt=t["--persona-components-header-subtitleForeground"])!=null?pt:t["--persona-text-muted"],t["--persona-header-action-icon-fg"]=(Nt=t["--persona-components-header-actionIconForeground"])!=null?Nt:t["--persona-muted"];let n=(F=e.components)==null?void 0:F.header;n!=null&&n.shadow&&(t["--persona-header-shadow"]=n.shadow),n!=null&&n.borderBottom&&(t["--persona-header-border-bottom"]=n.borderBottom);let o=(ye=e.components)==null?void 0:ye.introCard;t["--persona-intro-card-bg"]=(be=t["--persona-components-introCard-background"])!=null?be:t["--persona-surface"],t["--persona-intro-card-radius"]=(it=t["--persona-components-introCard-borderRadius"])!=null?it:"1rem",t["--persona-intro-card-padding"]=(Xe=t["--persona-components-introCard-padding"])!=null?Xe:"1.5rem",t["--persona-intro-card-shadow"]=(ar=(Wt=o==null?void 0:o.shadow)!=null?Wt:t["--persona-components-introCard-shadow"])!=null?ar:"0 5px 15px rgba(15, 23, 42, 0.08)",t["--persona-input-background"]=(Pt=t["--persona-components-input-background"])!=null?Pt:t["--persona-surface"],t["--persona-input-placeholder"]=(kt=t["--persona-components-input-placeholder"])!=null?kt:t["--persona-text-muted"],t["--persona-message-user-bg"]=(rt=t["--persona-components-message-user-background"])!=null?rt:t["--persona-accent"],t["--persona-message-user-text"]=(lt=t["--persona-components-message-user-text"])!=null?lt:t["--persona-text-inverse"],t["--persona-message-user-shadow"]=(rr=t["--persona-components-message-user-shadow"])!=null?rr:"0 5px 15px rgba(15, 23, 42, 0.08)",t["--persona-message-assistant-bg"]=(gn=t["--persona-components-message-assistant-background"])!=null?gn:t["--persona-surface"],t["--persona-message-assistant-text"]=(Ir=t["--persona-components-message-assistant-text"])!=null?Ir:t["--persona-text"],t["--persona-message-assistant-border"]=(Tn=t["--persona-components-message-assistant-border"])!=null?Tn:t["--persona-border"],t["--persona-message-assistant-shadow"]=(Et=t["--persona-components-message-assistant-shadow"])!=null?Et:"0 1px 2px 0 rgb(0 0 0 / 0.05)",t["--persona-scroll-to-bottom-bg"]=(pr=(hn=t["--persona-components-scrollToBottom-background"])!=null?hn:t["--persona-button-primary-bg"])!=null?pr:t["--persona-accent"],t["--persona-scroll-to-bottom-fg"]=(Kr=(Ar=t["--persona-components-scrollToBottom-foreground"])!=null?Ar:t["--persona-button-primary-fg"])!=null?Kr:t["--persona-text-inverse"],t["--persona-scroll-to-bottom-border"]=(bt=t["--persona-components-scrollToBottom-border"])!=null?bt:t["--persona-primary"],t["--persona-scroll-to-bottom-size"]=(kn=t["--persona-components-scrollToBottom-size"])!=null?kn:"40px",t["--persona-scroll-to-bottom-radius"]=(Tr=(Sr=(nn=t["--persona-components-scrollToBottom-borderRadius"])!=null?nn:t["--persona-button-radius"])!=null?Sr:t["--persona-radius-full"])!=null?Tr:"9999px",t["--persona-scroll-to-bottom-shadow"]=(En=(Vn=t["--persona-components-scrollToBottom-shadow"])!=null?Vn:t["--persona-palette-shadows-sm"])!=null?En:"0 1px 2px 0 rgb(0 0 0 / 0.05)",t["--persona-scroll-to-bottom-padding"]=(xn=t["--persona-components-scrollToBottom-padding"])!=null?xn:"0.5rem 0.875rem",t["--persona-scroll-to-bottom-gap"]=(vt=t["--persona-components-scrollToBottom-gap"])!=null?vt:"0.5rem",t["--persona-scroll-to-bottom-font-size"]=(P=(Pe=t["--persona-components-scrollToBottom-fontSize"])!=null?Pe:t["--persona-palette-typography-fontSize-sm"])!=null?P:"0.875rem",t["--persona-scroll-to-bottom-icon-size"]=(Z=t["--persona-components-scrollToBottom-iconSize"])!=null?Z:"14px",t["--persona-tool-bubble-shadow"]=(se=t["--persona-components-toolBubble-shadow"])!=null?se:"0 5px 15px rgba(15, 23, 42, 0.08)",t["--persona-reasoning-bubble-shadow"]=(Mt=t["--persona-components-reasoningBubble-shadow"])!=null?Mt:"0 5px 15px rgba(15, 23, 42, 0.08)",t["--persona-composer-shadow"]=(zt=t["--persona-components-composer-shadow"])!=null?zt:"none",t["--persona-md-inline-code-bg"]=(Ht=t["--persona-components-markdown-inlineCode-background"])!=null?Ht:t["--persona-container"],t["--persona-md-inline-code-color"]=(sr=t["--persona-components-markdown-inlineCode-foreground"])!=null?sr:t["--persona-text"],t["--persona-md-link-color"]=(Fr=(xr=t["--persona-components-markdown-link-foreground"])!=null?xr:t["--persona-accent"])!=null?Fr:"#0f0f0f";let a=t["--persona-components-markdown-heading-h1-fontSize"];a&&(t["--persona-md-h1-size"]=a);let s=t["--persona-components-markdown-heading-h1-fontWeight"];s&&(t["--persona-md-h1-weight"]=s);let i=t["--persona-components-markdown-heading-h2-fontSize"];i&&(t["--persona-md-h2-size"]=i);let d=t["--persona-components-markdown-heading-h2-fontWeight"];d&&(t["--persona-md-h2-weight"]=d);let l=t["--persona-components-markdown-prose-fontFamily"];l&&l!=="inherit"&&(t["--persona-md-prose-font-family"]=l),t["--persona-md-code-block-bg"]=(kr=t["--persona-components-markdown-codeBlock-background"])!=null?kr:t["--persona-container"],t["--persona-md-code-block-border-color"]=(ot=t["--persona-components-markdown-codeBlock-borderColor"])!=null?ot:t["--persona-border"],t["--persona-md-code-block-text-color"]=(wr=t["--persona-components-markdown-codeBlock-textColor"])!=null?wr:"inherit",t["--persona-md-table-header-bg"]=(Nr=t["--persona-components-markdown-table-headerBackground"])!=null?Nr:t["--persona-container"],t["--persona-md-table-border-color"]=(co=t["--persona-components-markdown-table-borderColor"])!=null?co:t["--persona-border"],t["--persona-md-hr-color"]=(jn=t["--persona-components-markdown-hr-color"])!=null?jn:t["--persona-divider"],t["--persona-md-blockquote-border-color"]=(po=t["--persona-components-markdown-blockquote-borderColor"])!=null?po:t["--persona-palette-colors-gray-900"],t["--persona-md-blockquote-bg"]=(Fn=t["--persona-components-markdown-blockquote-background"])!=null?Fn:"transparent",t["--persona-md-blockquote-text-color"]=(on=t["--persona-components-markdown-blockquote-textColor"])!=null?on:t["--persona-palette-colors-gray-500"],t["--cw-container"]=(Mn=t["--persona-components-collapsibleWidget-container"])!=null?Mn:t["--persona-surface"],t["--cw-surface"]=(At=t["--persona-components-collapsibleWidget-surface"])!=null?At:t["--persona-surface"],t["--cw-border"]=(ir=t["--persona-components-collapsibleWidget-border"])!=null?ir:t["--persona-border"],t["--persona-message-border"]=(lr=t["--persona-components-message-border"])!=null?lr:t["--persona-border"];let u=e.components,p=u==null?void 0:u.iconButton;p&&(p.background&&(t["--persona-icon-btn-bg"]=p.background),p.border&&(t["--persona-icon-btn-border"]=p.border),p.color&&(t["--persona-icon-btn-color"]=p.color),p.padding&&(t["--persona-icon-btn-padding"]=p.padding),p.borderRadius&&(t["--persona-icon-btn-radius"]=p.borderRadius),p.hoverBackground&&(t["--persona-icon-btn-hover-bg"]=p.hoverBackground),p.hoverColor&&(t["--persona-icon-btn-hover-color"]=p.hoverColor),p.activeBackground&&(t["--persona-icon-btn-active-bg"]=p.activeBackground),p.activeBorder&&(t["--persona-icon-btn-active-border"]=p.activeBorder));let f=u==null?void 0:u.labelButton;f&&(f.background&&(t["--persona-label-btn-bg"]=f.background),f.border&&(t["--persona-label-btn-border"]=f.border),f.color&&(t["--persona-label-btn-color"]=f.color),f.padding&&(t["--persona-label-btn-padding"]=f.padding),f.borderRadius&&(t["--persona-label-btn-radius"]=f.borderRadius),f.hoverBackground&&(t["--persona-label-btn-hover-bg"]=f.hoverBackground),f.fontSize&&(t["--persona-label-btn-font-size"]=f.fontSize),f.gap&&(t["--persona-label-btn-gap"]=f.gap));let m=u==null?void 0:u.toggleGroup;m&&(m.gap&&(t["--persona-toggle-group-gap"]=m.gap),m.borderRadius&&(t["--persona-toggle-group-radius"]=m.borderRadius));let C=u==null?void 0:u.artifact;if(C!=null&&C.toolbar){let he=C.toolbar;he.iconHoverColor&&(t["--persona-artifact-toolbar-icon-hover-color"]=he.iconHoverColor),he.iconHoverBackground&&(t["--persona-artifact-toolbar-icon-hover-bg"]=he.iconHoverBackground),he.iconPadding&&(t["--persona-artifact-toolbar-icon-padding"]=he.iconPadding),he.iconBorderRadius&&(t["--persona-artifact-toolbar-icon-radius"]=he.iconBorderRadius),he.iconBorder&&(t["--persona-artifact-toolbar-icon-border"]=he.iconBorder),he.toggleGroupGap&&(t["--persona-artifact-toolbar-toggle-group-gap"]=he.toggleGroupGap),he.toggleBorderRadius&&(t["--persona-artifact-toolbar-toggle-radius"]=he.toggleBorderRadius),he.copyBackground&&(t["--persona-artifact-toolbar-copy-bg"]=he.copyBackground),he.copyBorder&&(t["--persona-artifact-toolbar-copy-border"]=he.copyBorder),he.copyColor&&(t["--persona-artifact-toolbar-copy-color"]=he.copyColor),he.copyBorderRadius&&(t["--persona-artifact-toolbar-copy-radius"]=he.copyBorderRadius),he.copyPadding&&(t["--persona-artifact-toolbar-copy-padding"]=he.copyPadding),he.copyMenuBackground&&(t["--persona-artifact-toolbar-copy-menu-bg"]=he.copyMenuBackground,t["--persona-dropdown-bg"]=(an=t["--persona-dropdown-bg"])!=null?an:he.copyMenuBackground),he.copyMenuBorder&&(t["--persona-artifact-toolbar-copy-menu-border"]=he.copyMenuBorder,t["--persona-dropdown-border"]=(uo=t["--persona-dropdown-border"])!=null?uo:he.copyMenuBorder),he.copyMenuShadow&&(t["--persona-artifact-toolbar-copy-menu-shadow"]=he.copyMenuShadow,t["--persona-dropdown-shadow"]=(yn=t["--persona-dropdown-shadow"])!=null?yn:he.copyMenuShadow),he.copyMenuBorderRadius&&(t["--persona-artifact-toolbar-copy-menu-radius"]=he.copyMenuBorderRadius,t["--persona-dropdown-radius"]=(Ln=t["--persona-dropdown-radius"])!=null?Ln:he.copyMenuBorderRadius),he.copyMenuItemHoverBackground&&(t["--persona-artifact-toolbar-copy-menu-item-hover-bg"]=he.copyMenuItemHoverBackground,t["--persona-dropdown-item-hover-bg"]=(sn=t["--persona-dropdown-item-hover-bg"])!=null?sn:he.copyMenuItemHoverBackground),he.iconBackground&&(t["--persona-artifact-toolbar-icon-bg"]=he.iconBackground),he.toolbarBorder&&(t["--persona-artifact-toolbar-border"]=he.toolbarBorder)}if(C!=null&&C.tab){let he=C.tab;he.background&&(t["--persona-artifact-tab-bg"]=he.background),he.activeBackground&&(t["--persona-artifact-tab-active-bg"]=he.activeBackground),he.activeBorder&&(t["--persona-artifact-tab-active-border"]=he.activeBorder),he.borderRadius&&(t["--persona-artifact-tab-radius"]=he.borderRadius),he.textColor&&(t["--persona-artifact-tab-color"]=he.textColor),he.hoverBackground&&(t["--persona-artifact-tab-hover-bg"]=he.hoverBackground),he.listBackground&&(t["--persona-artifact-tab-list-bg"]=he.listBackground),he.listBorderColor&&(t["--persona-artifact-tab-list-border-color"]=he.listBorderColor),he.listPadding&&(t["--persona-artifact-tab-list-padding"]=he.listPadding)}if(C!=null&&C.pane){let he=C.pane;if(he.toolbarBackground){let ln=(z=Aa(e,he.toolbarBackground))!=null?z:he.toolbarBackground;t["--persona-artifact-toolbar-bg"]=ln}}return t}var jg={header:"Widget header bar",messages:"Message list area","user-message":"User message bubble","assistant-message":"Assistant message bubble",composer:"Footer / composer area",container:"Main widget container","artifact-pane":"Artifact sidebar","artifact-toolbar":"Artifact toolbar"};var xb={colors:{primary:{50:"#ffffff",100:"#f5f5f5",200:"#d4d4d4",300:"#a3a3a3",400:"#737373",500:"#171717",600:"#0f0f0f",700:"#0a0a0a",800:"#050505",900:"#030303",950:"#000000"},secondary:{50:"#f5f3ff",100:"#ede9fe",200:"#ddd6fe",300:"#c4b5fd",400:"#a78bfa",500:"#8b5cf6",600:"#7c3aed",700:"#6d28d9",800:"#5b21b6",900:"#4c1d95",950:"#2e1065"},accent:{50:"#ecfeff",100:"#cffafe",200:"#a5f3fc",300:"#67e8f9",400:"#22d3ee",500:"#06b6d4",600:"#0891b2",700:"#0e7490",800:"#155e75",900:"#164e63",950:"#083344"},gray:{50:"#f9fafb",100:"#f3f4f6",200:"#e5e7eb",300:"#d1d5db",400:"#9ca3af",500:"#6b7280",600:"#4b5563",700:"#374151",800:"#1f2937",900:"#111827",950:"#030712"},success:{50:"#f0fdf4",100:"#dcfce7",200:"#bbf7d0",300:"#86efac",400:"#4ade80",500:"#22c55e",600:"#16a34a",700:"#15803d",800:"#166534",900:"#14532d"},warning:{50:"#fefce8",100:"#fef9c3",200:"#fef08a",300:"#fde047",400:"#facc15",500:"#eab308",600:"#ca8a04",700:"#a16207",800:"#854d0e",900:"#713f12"},error:{50:"#fef2f2",100:"#fee2e2",200:"#fecaca",300:"#fca5a5",400:"#f87171",500:"#ef4444",600:"#dc2626",700:"#b91c1c",800:"#991b1b",900:"#7f1d1d"}}},Gg=e=>{if(!(!e||typeof e!="object"||Array.isArray(e)))return e},Cs=()=>{var e;return typeof document!="undefined"&&document.documentElement.classList.contains("dark")||typeof window!="undefined"&&((e=window.matchMedia)!=null&&e.call(window,"(prefers-color-scheme: dark)").matches)?"dark":"light"},yb=e=>{var t;let r=(t=e==null?void 0:e.colorScheme)!=null?t:"light";return r==="light"?"light":r==="dark"?"dark":Cs()},tp=e=>yb(e),bb=e=>Sa(e),Cb=e=>{var t;let r=Sa(void 0,{validate:!1});return Sa({...e,palette:{...r.palette,colors:{...xb.colors,...(t=e==null?void 0:e.palette)==null?void 0:t.colors}}},{validate:!1})},Ta=e=>{let r=tp(e),t=Gg(e==null?void 0:e.theme),n=Gg(e==null?void 0:e.darkTheme);return r==="dark"?Cb(bs(t!=null?t:{},n!=null?n:{})):bb(t)},wb=e=>ji(e),wo=(e,r)=>{var a;let t=Ta(r),n=wb(t);for(let[s,i]of Object.entries(n))e.style.setProperty(s,i);let o=(a=r==null?void 0:r.toolCall)==null?void 0:a.shadow;o!==void 0&&e.style.setProperty("--persona-tool-bubble-shadow",o.trim()===""?"none":o)},Gi=e=>{let r=[];if(typeof document!="undefined"&&typeof MutationObserver!="undefined"){let t=new MutationObserver(()=>{e(Cs())});t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),r.push(()=>t.disconnect())}if(typeof window!="undefined"&&window.matchMedia){let t=window.matchMedia("(prefers-color-scheme: dark)"),n=()=>e(Cs());t.addEventListener?(t.addEventListener("change",n),r.push(()=>t.removeEventListener("change",n))):t.addListener&&(t.addListener(n),r.push(()=>t.removeListener(n)))}return()=>{r.forEach(t=>t())}};var Xg=(function(){"use strict";let e=()=>{},r={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:f=>f.getAttribute("im-preserve")==="true",shouldReAppend:f=>f.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},restoreFocus:!0};function t(f,m,C={}){f=u(f);let w=p(m),k=l(f,w,C),T=o(k,()=>i(k,f,w,S=>S.morphStyle==="innerHTML"?(a(S,f,w),Array.from(f.childNodes)):n(S,f,w)));return k.pantry.remove(),T}function n(f,m,C){let w=p(m);return a(f,w,C,m,m.nextSibling),Array.from(w.childNodes)}function o(f,m){var E;if(!f.config.restoreFocus)return m();let C=document.activeElement;if(!(C instanceof HTMLInputElement||C instanceof HTMLTextAreaElement))return m();let{id:w,selectionStart:k,selectionEnd:T}=C,S=m();return w&&w!==((E=document.activeElement)==null?void 0:E.getAttribute("id"))&&(C=f.target.querySelector(`[id="${w}"]`),C==null||C.focus()),C&&!C.selectionEnd&&T&&C.setSelectionRange(k,T),S}let a=(function(){function f(v,b,y,M=null,H=null){b instanceof HTMLTemplateElement&&y instanceof HTMLTemplateElement&&(b=b.content,y=y.content),M||(M=b.firstChild);for(let B of y.childNodes){if(M&&M!=H){let W=C(v,B,M,H);if(W){W!==M&&k(v,M,W),s(W,B,v),M=W.nextSibling;continue}}if(B instanceof Element){let W=B.getAttribute("id");if(v.persistentIds.has(W)){let V=T(b,W,M,v);s(V,B,v),M=V.nextSibling;continue}}let R=m(b,B,M,v);R&&(M=R.nextSibling)}for(;M&&M!=H;){let B=M;M=M.nextSibling,w(v,B)}}function m(v,b,y,M){if(M.callbacks.beforeNodeAdded(b)===!1)return null;if(M.idMap.has(b)){let H=document.createElement(b.tagName);return v.insertBefore(H,y),s(H,b,M),M.callbacks.afterNodeAdded(H),H}else{let H=document.importNode(b,!0);return v.insertBefore(H,y),M.callbacks.afterNodeAdded(H),H}}let C=(function(){function v(M,H,B,R){let W=null,V=H.nextSibling,ne=0,ue=B;for(;ue&&ue!=R;){if(y(ue,H)){if(b(M,ue,H))return ue;W===null&&(M.idMap.has(ue)||(W=ue))}if(W===null&&V&&y(ue,V)&&(ne++,V=V.nextSibling,ne>=2&&(W=void 0)),M.activeElementAndParents.includes(ue))break;ue=ue.nextSibling}return W||null}function b(M,H,B){let R=M.idMap.get(H),W=M.idMap.get(B);if(!W||!R)return!1;for(let V of R)if(W.has(V))return!0;return!1}function y(M,H){var W,V,ne;let B=M,R=H;return B.nodeType===R.nodeType&&B.tagName===R.tagName&&(!((W=B.getAttribute)!=null&&W.call(B,"id"))||((V=B.getAttribute)==null?void 0:V.call(B,"id"))===((ne=R.getAttribute)==null?void 0:ne.call(R,"id")))}return v})();function w(v,b){var y;if(v.idMap.has(b))E(v.pantry,b,null);else{if(v.callbacks.beforeNodeRemoved(b)===!1)return;(y=b.parentNode)==null||y.removeChild(b),v.callbacks.afterNodeRemoved(b)}}function k(v,b,y){let M=b;for(;M&&M!==y;){let H=M;M=M.nextSibling,w(v,H)}return M}function T(v,b,y,M){var B,R;let H=((R=(B=M.target).getAttribute)==null?void 0:R.call(B,"id"))===b&&M.target||M.target.querySelector(`[id="${b}"]`)||M.pantry.querySelector(`[id="${b}"]`);return S(H,M),E(v,H,y),H}function S(v,b){let y=v.getAttribute("id");for(;v=v.parentNode;){let M=b.idMap.get(v);M&&(M.delete(y),M.size||b.idMap.delete(v))}}function E(v,b,y){if(v.moveBefore)try{v.moveBefore(b,y)}catch{v.insertBefore(b,y)}else v.insertBefore(b,y)}return f})(),s=(function(){function f(S,E,v){return v.ignoreActive&&S===document.activeElement?null:(v.callbacks.beforeNodeMorphed(S,E)===!1||(S instanceof HTMLHeadElement&&v.head.ignore||(S instanceof HTMLHeadElement&&v.head.style!=="morph"?d(S,E,v):(m(S,E,v),T(S,v)||a(v,S,E))),v.callbacks.afterNodeMorphed(S,E)),S)}function m(S,E,v){let b=E.nodeType;if(b===1){let y=S,M=E,H=y.attributes,B=M.attributes;for(let R of B)k(R.name,y,"update",v)||y.getAttribute(R.name)!==R.value&&y.setAttribute(R.name,R.value);for(let R=H.length-1;0<=R;R--){let W=H[R];if(W&&!M.hasAttribute(W.name)){if(k(W.name,y,"remove",v))continue;y.removeAttribute(W.name)}}T(y,v)||C(y,M,v)}(b===8||b===3)&&S.nodeValue!==E.nodeValue&&(S.nodeValue=E.nodeValue)}function C(S,E,v){if(S instanceof HTMLInputElement&&E instanceof HTMLInputElement&&E.type!=="file"){let b=E.value,y=S.value;w(S,E,"checked",v),w(S,E,"disabled",v),E.hasAttribute("value")?y!==b&&(k("value",S,"update",v)||(S.setAttribute("value",b),S.value=b)):k("value",S,"remove",v)||(S.value="",S.removeAttribute("value"))}else if(S instanceof HTMLOptionElement&&E instanceof HTMLOptionElement)w(S,E,"selected",v);else if(S instanceof HTMLTextAreaElement&&E instanceof HTMLTextAreaElement){let b=E.value,y=S.value;if(k("value",S,"update",v))return;b!==y&&(S.value=b),S.firstChild&&S.firstChild.nodeValue!==b&&(S.firstChild.nodeValue=b)}}function w(S,E,v,b){let y=E[v],M=S[v];if(y!==M){let H=k(v,S,"update",b);H||(S[v]=E[v]),y?H||S.setAttribute(v,""):k(v,S,"remove",b)||S.removeAttribute(v)}}function k(S,E,v,b){return S==="value"&&b.ignoreActiveValue&&E===document.activeElement?!0:b.callbacks.beforeAttributeUpdated(S,E,v)===!1}function T(S,E){return!!E.ignoreActiveValue&&S===document.activeElement&&S!==document.body}return f})();function i(f,m,C,w){if(f.head.block){let k=m.querySelector("head"),T=C.querySelector("head");if(k&&T){let S=d(k,T,f);return Promise.all(S).then(()=>{let E=Object.assign(f,{head:{block:!1,ignore:!0}});return w(E)})}}return w(f)}function d(f,m,C){let w=[],k=[],T=[],S=[],E=new Map;for(let b of m.children)E.set(b.outerHTML,b);for(let b of f.children){let y=E.has(b.outerHTML),M=C.head.shouldReAppend(b),H=C.head.shouldPreserve(b);y||H?M?k.push(b):(E.delete(b.outerHTML),T.push(b)):C.head.style==="append"?M&&(k.push(b),S.push(b)):C.head.shouldRemove(b)!==!1&&k.push(b)}S.push(...E.values());let v=[];for(let b of S){let y=document.createRange().createContextualFragment(b.outerHTML).firstChild;if(C.callbacks.beforeNodeAdded(y)!==!1){if("href"in y&&y.href||"src"in y&&y.src){let M,H=new Promise(function(B){M=B});y.addEventListener("load",function(){M()}),v.push(H)}f.appendChild(y),C.callbacks.afterNodeAdded(y),w.push(y)}}for(let b of k)C.callbacks.beforeNodeRemoved(b)!==!1&&(f.removeChild(b),C.callbacks.afterNodeRemoved(b));return C.head.afterHeadMorphed(f,{added:w,kept:T,removed:k}),v}let l=(function(){function f(v,b,y){let{persistentIds:M,idMap:H}=S(v,b),B=m(y),R=B.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(R))throw`Do not understand how to morph style ${R}`;return{target:v,newContent:b,config:B,morphStyle:R,ignoreActive:B.ignoreActive,ignoreActiveValue:B.ignoreActiveValue,restoreFocus:B.restoreFocus,idMap:H,persistentIds:M,pantry:C(),activeElementAndParents:w(v),callbacks:B.callbacks,head:B.head}}function m(v){let b=Object.assign({},r);return Object.assign(b,v),b.callbacks=Object.assign({},r.callbacks,v.callbacks),b.head=Object.assign({},r.head,v.head),b}function C(){let v=document.createElement("div");return v.hidden=!0,document.body.insertAdjacentElement("afterend",v),v}function w(v){let b=[],y=document.activeElement;if((y==null?void 0:y.tagName)!=="BODY"&&v.contains(y))for(;y&&(b.push(y),y!==v);)y=y.parentElement;return b}function k(v){var y;let b=Array.from(v.querySelectorAll("[id]"));return(y=v.getAttribute)!=null&&y.call(v,"id")&&b.push(v),b}function T(v,b,y,M){for(let H of M){let B=H.getAttribute("id");if(b.has(B)){let R=H;for(;R;){let W=v.get(R);if(W==null&&(W=new Set,v.set(R,W)),W.add(B),R===y)break;R=R.parentElement}}}}function S(v,b){let y=k(v),M=k(b),H=E(y,M),B=new Map;T(B,H,v,y);let R=b.__idiomorphRoot||b;return T(B,H,R,M),{persistentIds:H,idMap:B}}function E(v,b){let y=new Set,M=new Map;for(let{id:B,tagName:R}of v)M.has(B)?y.add(B):M.set(B,R);let H=new Set;for(let{id:B,tagName:R}of b)H.has(B)?y.add(B):M.get(B)===R&&H.add(B);for(let B of y)H.delete(B);return H}return f})(),{normalizeElement:u,normalizeParent:p}=(function(){let f=new WeakSet;function m(T){return T instanceof Document?T.documentElement:T}function C(T){if(T==null)return document.createElement("div");if(typeof T=="string")return C(k(T));if(f.has(T))return T;if(T instanceof Node){if(T.parentNode)return new w(T);{let S=document.createElement("div");return S.append(T),S}}else{let S=document.createElement("div");for(let E of[...T])S.append(E);return S}}class w{constructor(S){this.originalNode=S,this.realParentNode=S.parentNode,this.previousSibling=S.previousSibling,this.nextSibling=S.nextSibling}get childNodes(){let S=[],E=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;E&&E!=this.nextSibling;)S.push(E),E=E.nextSibling;return S}querySelectorAll(S){return this.childNodes.reduce((E,v)=>{if(v instanceof Element){v.matches(S)&&E.push(v);let b=v.querySelectorAll(S);for(let y=0;y<b.length;y++)E.push(b[y])}return E},[])}insertBefore(S,E){return this.realParentNode.insertBefore(S,E)}moveBefore(S,E){return this.realParentNode.moveBefore(S,E)}get __idiomorphRoot(){return this.originalNode}}function k(T){let S=new DOMParser,E=T.replace(/<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim,"");if(E.match(/<\/html>/)||E.match(/<\/head>/)||E.match(/<\/body>/)){let v=S.parseFromString(T,"text/html");if(E.match(/<\/html>/))return f.add(v),v;{let b=v.firstChild;return b&&f.add(b),b}}else{let b=S.parseFromString("<body><template>"+T+"</template></body>","text/html").body.querySelector("template").content;return f.add(b),b}}return{normalizeElement:m,normalizeParent:C}})();return{morph:t,defaults:r}})();var Xi=(e,r,t={})=>{let{preserveTypingAnimation:n=!0}=t;Xg.morph(e,r.innerHTML,{morphStyle:"innerHTML",callbacks:{beforeNodeMorphed(o,a){var s,i;if(o instanceof HTMLElement&&n){if(o.classList.contains("persona-animate-typing")||o.hasAttribute("data-preserve-runtime"))return!1;if(o.hasAttribute("data-preserve-animation")){if(a instanceof HTMLElement&&!a.hasAttribute("data-preserve-animation"))return;if(a instanceof HTMLElement&&a.hasAttribute("data-preserve-animation")){let d=(s=o.textContent)!=null?s:"",l=(i=a.textContent)!=null?i:"";if(d!==l)return}return!1}}}}})};function Jg(e,r){var t,n,o,a,s,i,d,l,u,p,f,m,C,w,k,T,S,E,v,b,y,M,H,B,R,W,V,ne,ue,We;return[e.id,e.role,(n=(t=e.content)==null?void 0:t.length)!=null?n:0,(a=(o=e.content)==null?void 0:o.slice(-32))!=null?a:"",e.streaming?"1":"0",(s=e.variant)!=null?s:"",(d=(i=e.rawContent)==null?void 0:i.length)!=null?d:0,(u=(l=e.llmContent)==null?void 0:l.length)!=null?u:0,(f=(p=e.approval)==null?void 0:p.status)!=null?f:"",(C=(m=e.toolCall)==null?void 0:m.status)!=null?C:"",(k=(w=e.toolCall)==null?void 0:w.name)!=null?k:"",(E=(S=(T=e.toolCall)==null?void 0:T.chunks)==null?void 0:S.length)!=null?E:0,(M=(y=(b=(v=e.toolCall)==null?void 0:v.chunks)==null?void 0:b[e.toolCall.chunks.length-1])==null?void 0:y.slice(-32))!=null?M:"",typeof((H=e.toolCall)==null?void 0:H.args)=="string"?e.toolCall.args.length:(B=e.toolCall)!=null&&B.args?JSON.stringify(e.toolCall.args).length:0,(V=(W=(R=e.reasoning)==null?void 0:R.chunks)==null?void 0:W.length)!=null?V:0,(ue=(ne=e.contentParts)==null?void 0:ne.length)!=null?ue:0,(We=e.stopReason)!=null?We:"",r].join("\0")}function Kg(){return new Map}function Yg(e,r,t){let n=e.get(r);return n&&n.fingerprint===t?n.wrapper:null}function Qg(e,r,t,n){e.set(r,{fingerprint:t,wrapper:n})}function Zg(e,r){for(let t of e.keys())r.has(t)||e.delete(t)}function Ji(e=!0){let r=e;return{isFollowing:()=>r,pause:()=>r?(r=!1,!0):!1,resume:()=>r?!1:(r=!0,!0)}}function ws(e){return Math.max(0,e.scrollHeight-e.clientHeight)}function vs(e,r){return ws(e)-e.scrollTop<=r}function Ki(e){let{following:r,currentScrollTop:t,lastScrollTop:n,nearBottom:o,userScrollThreshold:a,isAutoScrolling:s=!1,pauseOnUpwardScroll:i=!1,pauseWhenAwayFromBottom:d=!0,resumeRequiresDownwardScroll:l=!1}=e,u=t-n;return s||Math.abs(u)<a?{action:"none",delta:u,nextLastScrollTop:t}:!r&&o&&(!l||u>0)?{action:"resume",delta:u,nextLastScrollTop:t}:r&&i&&u<0?{action:"pause",delta:u,nextLastScrollTop:t}:r&&d&&!o?{action:"pause",delta:u,nextLastScrollTop:t}:{action:"none",delta:u,nextLastScrollTop:t}}function Yi(e){let{following:r,deltaY:t,nearBottom:n=!1,resumeWhenNearBottom:o=!1}=e;return r&&t<0?"pause":!r&&o&&t>0&&n?"resume":"none"}var Wr={idle:"Online",connecting:"Connecting\u2026",connected:"Streaming\u2026",error:"Offline"},Dr=1e5,vo=Dr+1;var As={type:"none",placeholder:"none",speed:120,duration:1800,buffer:"none"},vb=["pre","code","a","script","style"],Qi=e=>{var r,t,n,o,a;return{type:(r=e==null?void 0:e.type)!=null?r:As.type,placeholder:(t=e==null?void 0:e.placeholder)!=null?t:As.placeholder,speed:(n=e==null?void 0:e.speed)!=null?n:As.speed,duration:(o=e==null?void 0:e.duration)!=null?o:As.duration,buffer:(a=e==null?void 0:e.buffer)!=null?a:As.buffer}},th=[{name:"typewriter",containerClass:"persona-stream-typewriter",wrap:"char",useCaret:!0},{name:"pop-bubble",bubbleClass:"persona-stream-pop",wrap:"none"},{name:"letter-rise",containerClass:"persona-stream-letter-rise",wrap:"char"},{name:"word-fade",containerClass:"persona-stream-word-fade",wrap:"word"}],Ss=new Map;for(let e of th)Ss.set(e.name,e);var ra=e=>{Ss.set(e.name,e)},op=e=>{th.some(r=>r.name===e)||Ss.delete(e)},ap=()=>Array.from(Ss.keys()),Ts=(e,r)=>{var t,n;return e==="none"?null:r&&Object.prototype.hasOwnProperty.call(r,e)?(t=r[e])!=null?t:null:(n=Ss.get(e))!=null?n:null},Zi=(e,r,t,n,o)=>{if(!o)return e;if(t!=null&&t.bufferContent)return t.bufferContent(e,n);if(!e)return e;if(r==="word"){let a=e.search(/\s(?=\S*$)/);return a<0?"":e.slice(0,a)}if(r==="line"){let a=e.lastIndexOf(`
|
|
54
|
+
`),st="message",nt="";for(let F of qe)F.startsWith("event:")?st=F.replace("event:","").trim():F.startsWith("data:")&&(nt+=F.replace("data:","").trim());if(!nt)continue;let pt;try{pt=JSON.parse(nt)}catch(F){t({type:"error",error:F instanceof Error?F:new Error("Failed to parse chat stream payload")});continue}let Nt=st!=="message"?st:(vr=pt.type)!=null?vr:"message";if((Oe=this.onSSEEvent)==null||Oe.call(this,Nt,pt),this.parseSSEEvent){C.current=f;let F=await this.handleCustomSSEEvent(pt,t,C,p,l,A);if(C.current&&C.current!==f&&(f=C.current),F)continue}Me.push(Nt,pt),ge()}}Me.flushPending(),ge(),Me.destroy()}};function Ig(){let e=Date.now().toString(36),r=Math.random().toString(36).substring(2,10);return`msg_${e}_${r}`}function wa(){let e=Date.now().toString(36),r=Math.random().toString(36).substring(2,10);return`usr_${e}_${r}`}function Qo(){let e=Date.now().toString(36),r=Math.random().toString(36).substring(2,10);return`ast_${e}_${r}`}var Ei="[Image]";function Rg(e){return typeof e=="string"?[{type:"text",text:e}]:e}function Hg(e){return typeof e=="string"?e:e.filter(r=>r.type==="text").map(r=>r.text).join("")}function Bg(e){return typeof e=="string"?!1:e.some(r=>r.type==="image")}function Wg(e){return typeof e=="string"?[]:e.filter(r=>r.type==="image")}function hs(e){return{type:"text",text:e}}function Dg(e,r){return{type:"image",image:e,...(r==null?void 0:r.mimeType)&&{mimeType:r.mimeType},...(r==null?void 0:r.alt)&&{alt:r.alt}}}async function Og(e){return new Promise((r,t)=>{let n=new FileReader;n.onload=()=>{let o=n.result;r({type:"image",image:o,mimeType:e.type,alt:e.name})},n.onerror=()=>t(new Error("Failed to read file")),n.readAsDataURL(e)})}function Fg(e,r=["image/png","image/jpeg","image/gif","image/webp"],t=10*1024*1024){return r.includes(e.type)?e.size>t?{valid:!1,error:`File too large. Maximum size: ${Math.round(t/1048576)}MB`}:{valid:!0}:{valid:!1,error:`Invalid file type. Accepted types: ${r.join(", ")}`}}var Ng=["image/png","image/jpeg","image/gif","image/webp","image/svg+xml","image/bmp"],db=["application/pdf","text/plain","text/markdown","text/csv","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/json"],no=[...Ng,...db];function cb(e){return Ng.includes(e)||e.startsWith("image/")}function Mi(e){return cb(e.type)}async function _g(e){return new Promise((r,t)=>{let n=new FileReader;n.onload=()=>{let o=n.result;Mi(e)?r({type:"image",image:o,mimeType:e.type,alt:e.name}):r({type:"file",data:o,mimeType:e.type,filename:e.name})},n.onerror=()=>t(new Error("Failed to read file")),n.readAsDataURL(e)})}function $g(e,r=no,t=10*1024*1024){return r.includes(e.type)?e.size>t?{valid:!1,error:`File too large. Maximum size: ${Math.round(t/1048576)}MB`}:{valid:!0}:{valid:!1,error:`Invalid file type "${e.type}". Accepted types: ${r.join(", ")}`}}function pb(e){let r=e.split(".");return r.length>1?r.pop().toLowerCase():""}function Ug(e,r){let t=pb(r).toUpperCase();return{"application/pdf":"PDF","text/plain":"TXT","text/markdown":"MD","text/csv":"CSV","application/msword":"DOC","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"DOCX","application/vnd.ms-excel":"XLS","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"XLSX","application/json":"JSON"}[e]||t||"FILE"}var Li=class{constructor(r=24e3){this.ctx=null;this.nextStartTime=0;this.activeSources=[];this.finishedCallbacks=[];this.playing=!1;this.streamEnded=!1;this.pendingCount=0;this.remainder=null;this.sampleRate=r}ensureContext(){if(!this.ctx){let t=typeof window!="undefined"?window:void 0;if(!t)throw new Error("AudioPlaybackManager requires a browser environment");let n=t.AudioContext||t.webkitAudioContext;this.ctx=new n({sampleRate:this.sampleRate})}let r=this.ctx;return r.state==="suspended"&&r.resume(),r}enqueue(r){if(r.length===0)return;let t=r;if(this.remainder){let d=new Uint8Array(this.remainder.length+r.length);d.set(this.remainder),d.set(r,this.remainder.length),t=d,this.remainder=null}if(t.length%2!==0&&(this.remainder=new Uint8Array([t[t.length-1]]),t=t.subarray(0,t.length-1)),t.length===0)return;let n=this.ensureContext(),o=this.pcmToFloat32(t),a=n.createBuffer(1,o.length,this.sampleRate);a.getChannelData(0).set(o);let s=n.createBufferSource();s.buffer=a,s.connect(n.destination);let i=n.currentTime;this.nextStartTime<i&&(this.nextStartTime=i),s.start(this.nextStartTime),this.nextStartTime+=a.duration,this.activeSources.push(s),this.pendingCount++,this.playing=!0,s.onended=()=>{let d=this.activeSources.indexOf(s);d!==-1&&this.activeSources.splice(d,1),this.pendingCount--,this.checkFinished()}}markStreamEnd(){this.streamEnded=!0,this.checkFinished()}flush(){for(let r of this.activeSources)try{r.stop(),r.disconnect()}catch{}this.activeSources=[],this.pendingCount=0,this.nextStartTime=0,this.playing=!1,this.streamEnded=!1,this.finishedCallbacks=[],this.remainder=null}isPlaying(){return this.playing}onFinished(r){this.finishedCallbacks.push(r)}async destroy(){this.flush(),this.ctx&&(await this.ctx.close(),this.ctx=null)}checkFinished(){if(this.streamEnded&&this.pendingCount<=0&&this.playing){this.playing=!1,this.streamEnded=!1;let r=this.finishedCallbacks.slice();this.finishedCallbacks=[];for(let t of r)t()}}pcmToFloat32(r){let t=Math.floor(r.length/2),n=new Float32Array(t),o=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let a=0;a<t;a++){let s=o.getInt16(a*2,!0);n[a]=s/32768}return n}};var Pi=class{constructor(){this.sourceNode=null;this.analyserNode=null;this.interval=null;this.conditionStart=null;this.fired=!1}start(r,t,n,o,a){this.stop(),this.fired=!1,this.conditionStart=null,this.sourceNode=r.createMediaStreamSource(t),this.analyserNode=r.createAnalyser(),this.analyserNode.fftSize=2048,this.sourceNode.connect(this.analyserNode);let s=new Float32Array(this.analyserNode.fftSize);this.interval=setInterval(()=>{if(!this.analyserNode||this.fired)return;this.analyserNode.getFloatTimeDomainData(s);let i=0;for(let u=0;u<s.length;u++)i+=s[u]*s[u];let d=Math.sqrt(i/s.length);(n==="silence"?d<o.threshold:d>=o.threshold)?this.conditionStart===null?this.conditionStart=Date.now():Date.now()-this.conditionStart>=o.duration&&(this.fired=!0,a()):this.conditionStart=null},100)}stop(){this.interval&&(clearInterval(this.interval),this.interval=null),this.sourceNode&&(this.sourceNode.disconnect(),this.sourceNode=null),this.analyserNode=null,this.conditionStart=null,this.fired=!1}};var xs=class{constructor(r){this.config=r;this.type="runtype";this.ws=null;this.audioContext=null;this.w=typeof window!="undefined"?window:void 0;this.mediaRecorder=null;this.resultCallbacks=[];this.errorCallbacks=[];this.statusCallbacks=[];this.processingStartCallbacks=[];this.audioChunks=[];this.isProcessing=!1;this.isSpeaking=!1;this.vad=new Pi;this.mediaStream=null;this.currentAudio=null;this.currentAudioUrl=null;this.currentRequestId=null;this.interruptionMode="none";this.playbackManager=null}getInterruptionMode(){return this.interruptionMode}isBargeInActive(){return this.interruptionMode==="barge-in"&&this.mediaStream!==null}async deactivateBargeIn(){this.vad.stop(),this.mediaStream&&(this.mediaStream.getTracks().forEach(r=>r.stop()),this.mediaStream=null),this.audioContext&&(await this.audioContext.close(),this.audioContext=null)}async connect(){var r,t,n;if(!(this.ws&&this.ws.readyState===WebSocket.OPEN))try{if(!this.w)throw new Error("Window object not available");let o=this.w;if(!o||!o.location)throw new Error("Window object or location not available");let a=o.location.protocol==="https:"?"wss:":"ws:",s=(r=this.config)==null?void 0:r.host,i=(t=this.config)==null?void 0:t.agentId,d=(n=this.config)==null?void 0:n.clientToken;if(!i||!d)throw new Error("agentId and clientToken are required");if(!s)throw new Error("host must be provided in Runtype voice provider configuration");let l=`${a}//${s}/ws/agents/${i}/voice?token=${d}`;this.ws=new WebSocket(l),this.setupWebSocketHandlers();let u=`${a}//${s}/ws/agents/${i}/voice?token=...`,p=" Check: API running on port 8787? Valid client token? Agent voice enabled? Token allowedOrigins includes this page?";await new Promise((f,m)=>{if(!this.ws)return m(new Error("WebSocket not created"));let C=!1,A=T=>{C||(C=!0,clearTimeout(k),m(new Error(T)))},k=setTimeout(()=>A("WebSocket connection timed out."+p),1e4);this.ws.addEventListener("open",()=>{C||(C=!0,clearTimeout(k),f())},{once:!0}),this.ws.addEventListener("error",()=>{A("WebSocket connection failed to "+u+"."+p)},{once:!0}),this.ws.addEventListener("close",T=>{if(!T.wasClean&&!C){let S=T.code!==1006?` (code ${T.code})`:"";A("WebSocket connection failed"+S+"."+p)}},{once:!0})}),this.sendHeartbeat()}catch(o){throw this.ws=null,this.errorCallbacks.forEach(a=>a(o)),this.statusCallbacks.forEach(a=>a("error")),o}}setupWebSocketHandlers(){this.ws&&(this.ws.onopen=()=>{this.statusCallbacks.forEach(r=>r("connected"))},this.ws.onclose=()=>{this.statusCallbacks.forEach(r=>r("disconnected"))},this.ws.onerror=r=>{this.errorCallbacks.forEach(t=>t(new Error("WebSocket error"))),this.statusCallbacks.forEach(t=>t("error"))},this.ws.binaryType="arraybuffer",this.ws.onmessage=r=>{if(r.data instanceof ArrayBuffer){this.handleAudioChunk(new Uint8Array(r.data));return}try{let t=JSON.parse(r.data);this.handleWebSocketMessage(t)}catch{this.errorCallbacks.forEach(n=>n(new Error("Message parsing failed")))}})}handleWebSocketMessage(r){var t,n;switch(r.type){case"session_config":r.interruptionMode&&(this.interruptionMode=r.interruptionMode);break;case"voice_response":this.isProcessing=!1,this.resultCallbacks.forEach(o=>o({text:r.response.agentResponseText||r.response.transcript,transcript:r.response.transcript,audio:r.response.audio,confidence:.95,provider:"runtype"})),(t=r.response.audio)!=null&&t.base64?(this.isSpeaking=!0,this.statusCallbacks.forEach(o=>o("speaking")),this.playAudio(r.response.audio).catch(o=>this.errorCallbacks.forEach(a=>a(o instanceof Error?o:new Error(String(o)))))):(n=r.response.audio)!=null&&n.base64;break;case"audio_end":if(r.requestId&&r.requestId!==this.currentRequestId)break;this.playbackManager?this.playbackManager.markStreamEnd():(this.isSpeaking=!1,this.isProcessing=!1,this.statusCallbacks.forEach(o=>o("idle")));break;case"cancelled":this.isProcessing=!1;break;case"error":this.errorCallbacks.forEach(o=>o(new Error(r.error))),this.statusCallbacks.forEach(o=>o("error")),this.isProcessing=!1;break;case"pong":break}}handleAudioChunk(r){r.length!==0&&this.currentRequestId&&(this.playbackManager||(this.playbackManager=new Li(24e3),this.playbackManager.onFinished(()=>{this.isSpeaking=!1,this.playbackManager=null,this.vad.stop(),this.statusCallbacks.forEach(t=>t("idle"))})),this.isSpeaking||(this.isSpeaking=!0,this.statusCallbacks.forEach(t=>t("speaking")),this.startBargeInMonitoring().catch(()=>{})),this.playbackManager.enqueue(r))}stopPlayback(){!this.isProcessing&&!this.isSpeaking||(this.cancelCurrentPlayback(),this.statusCallbacks.forEach(r=>r("idle")))}cancelCurrentPlayback(){this.currentAudio&&(this.currentAudio.pause(),this.currentAudio.src="",this.currentAudio=null),this.currentAudioUrl&&(URL.revokeObjectURL(this.currentAudioUrl),this.currentAudioUrl=null),this.playbackManager&&(this.playbackManager.flush(),this.playbackManager=null),this.currentRequestId&&this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"cancel",requestId:this.currentRequestId})),this.currentRequestId=null,this.isProcessing=!1,this.isSpeaking=!1}async startListening(){var r,t,n,o;try{if(this.isProcessing||this.isSpeaking)if(this.interruptionMode!=="none")this.cancelCurrentPlayback();else return;if(!this.mediaStream){let l=this.interruptionMode==="barge-in"?{audio:{echoCancellation:!0,noiseSuppression:!0}}:{audio:!0};this.mediaStream=await navigator.mediaDevices.getUserMedia(l)}let a=this.w;this.audioContext||(this.audioContext=new(a.AudioContext||a.webkitAudioContext));let s=this.audioContext,i=(t=(r=this.config)==null?void 0:r.pauseDuration)!=null?t:2e3,d=(o=(n=this.config)==null?void 0:n.silenceThreshold)!=null?o:.01;this.vad.start(s,this.mediaStream,"silence",{threshold:d,duration:i},()=>this.stopListening()),this.mediaRecorder=new MediaRecorder(this.mediaStream),this.audioChunks=[],this.mediaRecorder.ondataavailable=l=>{l.data.size>0&&this.audioChunks.push(l.data)},this.mediaRecorder.onstop=async()=>{var l;if(this.audioChunks.length>0){this.isProcessing=!0,this.statusCallbacks.forEach(f=>f("processing")),this.processingStartCallbacks.forEach(f=>f());let u=((l=this.mediaRecorder)==null?void 0:l.mimeType)||"audio/webm",p=new Blob(this.audioChunks,{type:u});await this.sendAudio(p),this.audioChunks=[]}},this.mediaRecorder.start(1e3),this.statusCallbacks.forEach(l=>l("listening"))}catch(a){throw this.errorCallbacks.forEach(s=>s(a)),this.statusCallbacks.forEach(s=>s("error")),a}}async stopListening(){this.vad.stop(),this.mediaRecorder&&(this.interruptionMode!=="barge-in"&&this.mediaRecorder.stream.getTracks().forEach(r=>r.stop()),this.mediaRecorder.stop(),this.mediaRecorder=null),this.interruptionMode!=="barge-in"&&(this.mediaStream&&(this.mediaStream.getTracks().forEach(r=>r.stop()),this.mediaStream=null),this.audioContext&&(await this.audioContext.close(),this.audioContext=null)),this.statusCallbacks.forEach(r=>r("idle"))}async startBargeInMonitoring(){var a,s;if(this.interruptionMode!=="barge-in")return;let r=this.w;if(!this.mediaStream&&r&&(this.mediaStream=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0}})),!this.audioContext&&r&&(this.audioContext=new(r.AudioContext||r.webkitAudioContext)),!this.audioContext||!this.mediaStream)return;let t=this.audioContext,n=(s=(a=this.config)==null?void 0:a.silenceThreshold)!=null?s:.01;this.vad.start(t,this.mediaStream,"speech",{threshold:n,duration:200},()=>this.handleBargeIn())}handleBargeIn(){this.cancelCurrentPlayback(),this.startListening().catch(r=>{this.errorCallbacks.forEach(t=>t(r instanceof Error?r:new Error(String(r))))})}generateRequestId(){return"vreq_"+Math.random().toString(36).substring(2,10)+Date.now().toString(36)}async sendAudio(r){var t;if(!this.ws||this.ws.readyState!==WebSocket.OPEN){this.errorCallbacks.forEach(n=>n(new Error("WebSocket not connected"))),this.statusCallbacks.forEach(n=>n("error"));return}try{let n=await this.blobToBase64(r),o=this.getFormatFromMimeType(r.type),a=this.generateRequestId();this.currentRequestId=a,this.ws.send(JSON.stringify({type:"audio_input",audio:n,format:o,sampleRate:16e3,voiceId:(t=this.config)==null?void 0:t.voiceId,requestId:a}))}catch(n){this.errorCallbacks.forEach(o=>o(n)),this.statusCallbacks.forEach(o=>o("error"))}}getFormatFromMimeType(r){return r.includes("wav")?"wav":r.includes("mpeg")||r.includes("mp3")?"mp3":"webm"}blobToBase64(r){return new Promise((t,n)=>{let o=new FileReader;o.onload=()=>{let s=o.result.split(",")[1];t(s)},o.onerror=n,o.readAsDataURL(r)})}async playAudio(r){if(!r.base64)return;let t=atob(r.base64),n=new Uint8Array(t.length);for(let l=0;l<t.length;l++)n[l]=t.charCodeAt(l);let o=r.format||"mp3",a=o==="mp3"?"audio/mpeg":`audio/${o}`,s=new Blob([n],{type:a}),i=URL.createObjectURL(s),d=new Audio(i);this.currentAudio=d,this.currentAudioUrl=i,d.onended=()=>{URL.revokeObjectURL(i),this.currentAudio===d&&(this.currentAudio=null,this.currentAudioUrl=null,this.isSpeaking=!1,this.statusCallbacks.forEach(l=>l("idle")))},await d.play()}onResult(r){this.resultCallbacks.push(r)}onError(r){this.errorCallbacks.push(r)}onStatusChange(r){this.statusCallbacks.push(r)}onProcessingStart(r){this.processingStartCallbacks.push(r)}async disconnect(){if(this.currentAudio&&(this.currentAudio.pause(),this.currentAudio.src="",this.currentAudio=null),this.currentAudioUrl&&(URL.revokeObjectURL(this.currentAudioUrl),this.currentAudioUrl=null),this.playbackManager&&(await this.playbackManager.destroy(),this.playbackManager=null),this.currentRequestId=null,this.isSpeaking=!1,this.vad.stop(),await this.stopListening(),this.mediaStream&&(this.mediaStream.getTracks().forEach(r=>r.stop()),this.mediaStream=null),this.audioContext&&(await this.audioContext.close(),this.audioContext=null),this.ws){try{this.ws.close()}catch{}this.ws=null}this.statusCallbacks.forEach(r=>r("disconnected"))}sendHeartbeat(){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"ping"}))}};var Zo=class{constructor(r={}){this.config=r;this.type="browser";this.recognition=null;this.resultCallbacks=[];this.errorCallbacks=[];this.statusCallbacks=[];this.isListening=!1;this.w=typeof window!="undefined"?window:void 0}async connect(){this.statusCallbacks.forEach(r=>r("connected"))}async startListening(){var r,t;try{if(this.isListening)throw new Error("Already listening");if(!this.w)throw new Error("Window object not available");let n=this.w.SpeechRecognition||this.w.webkitSpeechRecognition;if(!n)throw new Error("Browser speech recognition not supported");this.recognition=new n,this.recognition.lang=((r=this.config)==null?void 0:r.language)||"en-US",this.recognition.continuous=((t=this.config)==null?void 0:t.continuous)||!1,this.recognition.interimResults=!0,this.recognition.onresult=o=>{var i;let a=Array.from(o.results).map(d=>d[0]).map(d=>d.transcript).join(""),s=o.results[o.results.length-1].isFinal;this.resultCallbacks.forEach(d=>d({text:a,confidence:s?.8:.5,provider:"browser"})),s&&!((i=this.config)!=null&&i.continuous)&&this.stopListening()},this.recognition.onerror=o=>{this.errorCallbacks.forEach(a=>a(new Error(o.error))),this.statusCallbacks.forEach(a=>a("error"))},this.recognition.onstart=()=>{this.isListening=!0,this.statusCallbacks.forEach(o=>o("listening"))},this.recognition.onend=()=>{this.isListening=!1,this.statusCallbacks.forEach(o=>o("idle"))},this.recognition.start()}catch(n){throw this.errorCallbacks.forEach(o=>o(n)),this.statusCallbacks.forEach(o=>o("error")),n}}async stopListening(){this.recognition&&(this.recognition.stop(),this.recognition=null),this.isListening=!1,this.statusCallbacks.forEach(r=>r("idle"))}onResult(r){this.resultCallbacks.push(r)}onError(r){this.errorCallbacks.push(r)}onStatusChange(r){this.statusCallbacks.push(r)}async disconnect(){await this.stopListening(),this.statusCallbacks.forEach(r=>r("disconnected"))}static isSupported(){return"SpeechRecognition"in window||"webkitSpeechRecognition"in window}};function ea(e){switch(e.type){case"runtype":if(!e.runtype)throw new Error("Runtype voice provider requires configuration");return new xs(e.runtype);case"browser":if(!Zo.isSupported())throw new Error("Browser speech recognition not supported");return new Zo(e.browser||{});case"custom":throw new Error("Custom voice providers not yet implemented");default:throw new Error(`Unknown voice provider type: ${e.type}`)}}function Ii(e){if((e==null?void 0:e.type)==="runtype"&&e.runtype)return ea({type:"runtype",runtype:e.runtype});if(Zo.isSupported())return ea({type:"browser",browser:(e==null?void 0:e.browser)||{language:"en-US"}});throw new Error("No supported voice providers available")}function ys(e){try{return Ii(e),!0}catch{return!1}}var va=class e{constructor(r={},t){this.config=r;this.callbacks=t;this.status="idle";this.streaming=!1;this.abortController=null;this.sequenceCounter=Date.now();this.clientSession=null;this.agentExecution=null;this.artifacts=new Map;this.selectedArtifactId=null;this.voiceProvider=null;this.voiceActive=!1;this.voiceStatus="disconnected";this.pendingVoiceUserMessageId=null;this.pendingVoiceAssistantMessageId=null;this.ttsSpokenMessageIds=new Set;this.handleEvent=r=>{var t,n,o,a,s,i,d;r.type==="message"?(this.upsertMessage(r.message),(t=r.message.agentMetadata)!=null&&t.executionId&&(this.agentExecution?r.message.agentMetadata.iteration!==void 0&&(this.agentExecution.currentIteration=r.message.agentMetadata.iteration):this.agentExecution={executionId:r.message.agentMetadata.executionId,agentId:"",agentName:(n=r.message.agentMetadata.agentName)!=null?n:"",status:"running",currentIteration:(o=r.message.agentMetadata.iteration)!=null?o:0,maxTurns:0})):r.type==="status"?(this.setStatus(r.status),r.status==="connecting"?this.setStreaming(!0):(r.status==="idle"||r.status==="error")&&(this.setStreaming(!1),this.abortController=null,((a=this.agentExecution)==null?void 0:a.status)==="running"&&(this.agentExecution.status=r.status==="error"?"error":"complete"))):r.type==="error"?(this.setStatus("error"),this.setStreaming(!1),this.abortController=null,((s=this.agentExecution)==null?void 0:s.status)==="running"&&(this.agentExecution.status="error"),(d=(i=this.callbacks).onError)==null||d.call(i,r.error)):(r.type==="artifact_start"||r.type==="artifact_delta"||r.type==="artifact_update"||r.type==="artifact_complete")&&this.applyArtifactStreamEvent(r)};var n,o;this.messages=[...(n=r.initialMessages)!=null?n:[]].map(a=>{var s;return{...a,sequence:(s=a.sequence)!=null?s:this.nextSequence()}}),this.messages=this.sortMessages(this.messages),this.client=new Yo(r);for(let a of(o=r.initialArtifacts)!=null?o:[])this.artifacts.set(a.id,{...a,status:"complete"});r.initialSelectedArtifactId!=null&&(this.selectedArtifactId=r.initialSelectedArtifactId),this.messages.length&&this.callbacks.onMessagesChanged([...this.messages]),this.artifacts.size>0&&this.emitArtifactsState(),this.callbacks.onStatusChanged(this.status)}setSSEEventCallback(r){this.client.setSSEEventCallback(r)}isClientTokenMode(){return this.client.isClientTokenMode()}isAgentMode(){return this.client.isAgentMode()}getAgentExecution(){return this.agentExecution}isAgentExecuting(){var r;return((r=this.agentExecution)==null?void 0:r.status)==="running"}isVoiceSupported(){var r;return ys((r=this.config.voiceRecognition)==null?void 0:r.provider)}isVoiceActive(){return this.voiceActive}getVoiceStatus(){return this.voiceStatus}getVoiceInterruptionMode(){var r;return(r=this.voiceProvider)!=null&&r.getInterruptionMode?this.voiceProvider.getInterruptionMode():"none"}stopVoicePlayback(){var r;(r=this.voiceProvider)!=null&&r.stopPlayback&&this.voiceProvider.stopPlayback()}isBargeInActive(){var r,t,n;return(n=(t=(r=this.voiceProvider)==null?void 0:r.isBargeInActive)==null?void 0:t.call(r))!=null?n:!1}async deactivateBargeIn(){var r;(r=this.voiceProvider)!=null&&r.deactivateBargeIn&&await this.voiceProvider.deactivateBargeIn()}setupVoice(r){var t,n,o;try{let a=r||this.getVoiceConfigFromConfig();if(!a)throw new Error("Voice configuration not provided");this.voiceProvider=ea(a);let s=(t=this.config.voiceRecognition)!=null?t:{},i=(n=s.processingText)!=null?n:"\u{1F3A4} Processing voice...",d=(o=s.processingErrorText)!=null?o:"Voice processing failed. Please try again.";this.voiceProvider.onProcessingStart&&this.voiceProvider.onProcessingStart(()=>{let l=this.injectMessage({role:"user",content:i,streaming:!1,voiceProcessing:!0});this.pendingVoiceUserMessageId=l.id;let u=this.injectMessage({role:"assistant",content:"",streaming:!0,voiceProcessing:!0});this.pendingVoiceAssistantMessageId=u.id,this.setStreaming(!0)}),this.voiceProvider.onResult(l=>{var u,p,f,m,C,A;if(l.provider==="browser")l.text&&l.text.trim()&&this.sendMessage(l.text,{viaVoice:!0});else if(l.provider==="runtype"){this.pendingVoiceUserMessageId&&((u=l.transcript)!=null&&u.trim())?this.upsertMessage({id:this.pendingVoiceUserMessageId,role:"user",content:l.transcript.trim(),createdAt:new Date().toISOString(),streaming:!1,voiceProcessing:!1}):(p=l.transcript)!=null&&p.trim()&&this.injectUserMessage({content:l.transcript.trim()}),this.pendingVoiceAssistantMessageId&&((f=l.text)!=null&&f.trim())?this.upsertMessage({id:this.pendingVoiceAssistantMessageId,role:"assistant",content:l.text.trim(),createdAt:new Date().toISOString(),streaming:!1,voiceProcessing:!1}):(m=l.text)!=null&&m.trim()&&this.injectAssistantMessage({content:l.text.trim()});{let k=(A=this.pendingVoiceAssistantMessageId)!=null?A:(C=[...this.messages].reverse().find(T=>T.role==="assistant"))==null?void 0:C.id;k&&this.ttsSpokenMessageIds.add(k)}this.setStreaming(!1),this.pendingVoiceUserMessageId=null,this.pendingVoiceAssistantMessageId=null}}),this.voiceProvider.onError(l=>{console.error("Voice error:",l),this.pendingVoiceAssistantMessageId&&(this.upsertMessage({id:this.pendingVoiceAssistantMessageId,role:"assistant",content:d,createdAt:new Date().toISOString(),streaming:!1,voiceProcessing:!1}),this.setStreaming(!1),this.pendingVoiceUserMessageId=null,this.pendingVoiceAssistantMessageId=null)}),this.voiceProvider.onStatusChange(l=>{var u,p;this.voiceStatus=l,this.voiceActive=l==="listening",(p=(u=this.callbacks).onVoiceStatusChanged)==null||p.call(u,l)}),this.voiceProvider.connect()}catch(a){console.error("Failed to setup voice:",a)}}async toggleVoice(){if(!this.voiceProvider){console.error("Voice not configured");return}if(this.voiceActive)await this.voiceProvider.stopListening();else{this.stopSpeaking();try{await this.voiceProvider.startListening()}catch(r){console.error("Failed to start voice:",r)}}}cleanupVoice(){this.voiceProvider&&(this.voiceProvider.disconnect(),this.voiceProvider=null),this.voiceActive=!1,this.voiceStatus="disconnected"}getVoiceConfigFromConfig(){var t,n,o,a,s,i,d,l,u;if(!((t=this.config.voiceRecognition)!=null&&t.provider))return;let r=this.config.voiceRecognition.provider;switch(r.type){case"runtype":return{type:"runtype",runtype:{agentId:((n=r.runtype)==null?void 0:n.agentId)||"",clientToken:((o=r.runtype)==null?void 0:o.clientToken)||"",host:(a=r.runtype)==null?void 0:a.host,voiceId:(s=r.runtype)==null?void 0:s.voiceId,pauseDuration:(i=r.runtype)==null?void 0:i.pauseDuration,silenceThreshold:(d=r.runtype)==null?void 0:d.silenceThreshold}};case"browser":return{type:"browser",browser:{language:((l=r.browser)==null?void 0:l.language)||"en-US",continuous:(u=r.browser)==null?void 0:u.continuous}};default:return}}async initClientSession(){var r,t;if(!this.isClientTokenMode())return null;try{let n=await this.client.initSession();return this.setClientSession(n),n}catch(n){return(t=(r=this.callbacks).onError)==null||t.call(r,n instanceof Error?n:new Error(String(n))),null}}setClientSession(r){if(this.clientSession=r,r.config.welcomeMessage&&this.messages.length===0){let t={id:`welcome-${Date.now()}`,role:"assistant",content:r.config.welcomeMessage,createdAt:new Date().toISOString(),sequence:this.nextSequence()};this.appendMessage(t)}}getClientSession(){var r;return(r=this.clientSession)!=null?r:this.client.getClientSession()}isSessionValid(){let r=this.getClientSession();return r?new Date<r.expiresAt:!1}clearClientSession(){this.clientSession=null,this.client.clearClientSession()}getClient(){return this.client}async submitMessageFeedback(r,t){return this.client.submitMessageFeedback(r,t)}async submitCSATFeedback(r,t){return this.client.submitCSATFeedback(r,t)}async submitNPSFeedback(r,t){return this.client.submitNPSFeedback(r,t)}updateConfig(r){let t=this.client.getSSEEventCallback();this.config={...this.config,...r},this.client=new Yo(this.config),t&&this.client.setSSEEventCallback(t)}getMessages(){return[...this.messages]}getStatus(){return this.status}isStreaming(){return this.streaming}injectTestEvent(r){this.handleEvent(r)}injectMessage(r){let{role:t,content:n,llmContent:o,contentParts:a,id:s,createdAt:i,sequence:d,streaming:l=!1,voiceProcessing:u,rawContent:p}=r,m={id:s!=null?s:t==="user"?wa():t==="assistant"?Qo():`system-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:t,content:n,createdAt:i!=null?i:new Date().toISOString(),sequence:d!=null?d:this.nextSequence(),streaming:l,...o!==void 0&&{llmContent:o},...a!==void 0&&{contentParts:a},...u!==void 0&&{voiceProcessing:u},...p!==void 0&&{rawContent:p}};return this.upsertMessage(m),m}injectAssistantMessage(r){return this.injectMessage({...r,role:"assistant"})}injectUserMessage(r){return this.injectMessage({...r,role:"user"})}injectSystemMessage(r){return this.injectMessage({...r,role:"system"})}injectMessageBatch(r){let t=[];for(let n of r){let{role:o,content:a,llmContent:s,contentParts:i,id:d,createdAt:l,sequence:u,streaming:p=!1,voiceProcessing:f,rawContent:m}=n,A={id:d!=null?d:o==="user"?wa():o==="assistant"?Qo():`system-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:o,content:a,createdAt:l!=null?l:new Date().toISOString(),sequence:u!=null?u:this.nextSequence(),streaming:p,...s!==void 0&&{llmContent:s},...i!==void 0&&{contentParts:i},...f!==void 0&&{voiceProcessing:f},...m!==void 0&&{rawContent:m}};t.push(A)}return this.messages=this.sortMessages([...this.messages,...t]),this.callbacks.onMessagesChanged([...this.messages]),t}injectComponentDirective(r){let{component:t,props:n={},text:o="",llmContent:a,id:s,createdAt:i,sequence:d}=r,l={text:o,component:t,props:n};return this.injectMessage({role:"assistant",content:o,rawContent:JSON.stringify(l),...a!==void 0&&{llmContent:a},...s!==void 0&&{id:s},...i!==void 0&&{createdAt:i},...d!==void 0&&{sequence:d}})}async sendMessage(r,t){var l,u,p,f,m;let n=r.trim();if(!n&&(!(t!=null&&t.contentParts)||t.contentParts.length===0))return;this.stopSpeaking(),(l=this.abortController)==null||l.abort();let o=wa(),a=Qo(),s={id:o,role:"user",content:n||Ei,createdAt:new Date().toISOString(),sequence:this.nextSequence(),viaVoice:(t==null?void 0:t.viaVoice)||!1,...(t==null?void 0:t.contentParts)&&t.contentParts.length>0&&{contentParts:t.contentParts}};this.appendMessage(s),this.setStreaming(!0);let i=new AbortController;this.abortController=i;let d=[...this.messages];try{await this.client.dispatch({messages:d,signal:i.signal,assistantMessageId:a},this.handleEvent)}catch(C){let A=C instanceof Error&&(C.name==="AbortError"||C.message.includes("aborted")||C.message.includes("abort"));if(!A){let k={id:a,role:"assistant",createdAt:new Date().toISOString(),content:"It looks like the proxy isn't returning a real response yet. Here's a sample message so you can continue testing locally.",sequence:this.nextSequence()};this.appendMessage(k)}this.setStatus("idle"),this.setStreaming(!1),this.abortController=null,A||(C instanceof Error?(p=(u=this.callbacks).onError)==null||p.call(u,C):(m=(f=this.callbacks).onError)==null||m.call(f,new Error(String(C))))}}async continueConversation(){var o,a,s,i,d;if(this.streaming)return;(o=this.abortController)==null||o.abort();let r=Qo();this.setStreaming(!0);let t=new AbortController;this.abortController=t;let n=[...this.messages];try{await this.client.dispatch({messages:n,signal:t.signal,assistantMessageId:r},this.handleEvent)}catch(l){let u={id:r,role:"assistant",createdAt:new Date().toISOString(),content:"It looks like the proxy isn't returning a real response yet. Here's a sample message so you can continue testing locally.",sequence:this.nextSequence()};this.appendMessage(u),this.setStatus("idle"),this.setStreaming(!1),this.abortController=null,l instanceof Error?(s=(a=this.callbacks).onError)==null||s.call(a,l):(d=(i=this.callbacks).onError)==null||d.call(i,new Error(String(l)))}}async connectStream(r,t){var o,a,s;if(this.streaming&&!(t!=null&&t.allowReentry))return;t!=null&&t.allowReentry||(o=this.abortController)==null||o.abort();let n=!1;for(let i of this.messages)i.streaming&&(i.streaming=!1,n=!0);n&&this.callbacks.onMessagesChanged([...this.messages]),this.setStreaming(!0);try{await this.client.processStream(r,this.handleEvent,t==null?void 0:t.assistantMessageId)}catch(i){this.setStatus("error"),this.setStreaming(!1),this.abortController=null,(s=(a=this.callbacks).onError)==null||s.call(a,i instanceof Error?i:new Error(String(i)))}}async resolveApproval(r,t){var d,l,u,p;let n=`approval-${r.id}`,o={...r,status:t,resolvedAt:Date.now()},a={id:n,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!1,variant:"approval",approval:o};this.upsertMessage(a),(d=this.abortController)==null||d.abort(),this.abortController=new AbortController,this.setStreaming(!0);let s=this.config.approval,i=s&&typeof s=="object"?s.onDecision:void 0;try{let f;if(i?f=await i({approvalId:r.id,executionId:r.executionId,agentId:r.agentId,toolName:r.toolName},t):f=await this.client.resolveApproval({agentId:r.agentId,executionId:r.executionId,approvalId:r.id},t),f){let m=null;if(f instanceof Response){if(!f.ok){let C=await f.json().catch(()=>null);throw new Error((l=C==null?void 0:C.error)!=null?l:`Approval request failed: ${f.status}`)}m=f.body}else f instanceof ReadableStream&&(m=f);m?await this.connectStream(m,{allowReentry:!0}):(t==="denied"&&this.appendMessage({id:`denial-${r.id}`,role:"assistant",content:"Tool execution was denied by user.",createdAt:new Date().toISOString(),streaming:!1,sequence:this.nextSequence()}),this.setStreaming(!1),this.abortController=null)}else this.setStreaming(!1),this.abortController=null}catch(f){let m=f instanceof Error&&(f.name==="AbortError"||f.message.includes("aborted")||f.message.includes("abort"));this.setStreaming(!1),this.abortController=null,m||(p=(u=this.callbacks).onError)==null||p.call(u,f instanceof Error?f:new Error(String(f)))}}persistAskUserQuestionProgress(r,t){let n=this.messages.find(o=>o.id===r.id);n&&this.upsertMessage({...n,agentMetadata:{...n.agentMetadata,askUserQuestionAnswers:t.answers,askUserQuestionIndex:t.currentIndex}})}markAskUserQuestionResolved(r,t){let n=this.messages.find(o=>o.id===r.id);n&&this.upsertMessage({...n,agentMetadata:{...n.agentMetadata,awaitingLocalTool:!1,askUserQuestionAnswered:!0,...t?{askUserQuestionAnswers:t}:{}}})}async resolveAskUserQuestion(r,t){var u,p,f,m,C,A,k,T,S,E,w,b;let n=this.messages.find(y=>y.id===r.id);if(((u=n==null?void 0:n.agentMetadata)==null?void 0:u.askUserQuestionAnswered)===!0)return;let o=(p=r.agentMetadata)==null?void 0:p.executionId,a=(f=r.toolCall)==null?void 0:f.name;if(!o||!a){(C=(m=this.callbacks).onError)==null||C.call(m,new Error("resolveAskUserQuestion: message is missing executionId or toolCall.name"));return}let s=typeof t=="string"?void 0:t;if(s===void 0&&typeof t=="string"){let y=(A=r.toolCall)==null?void 0:A.args,M=Array.isArray(y==null?void 0:y.questions)?y.questions:[];if(M.length===1){let H=typeof((k=M[0])==null?void 0:k.question)=="string"?M[0].question:"";H&&(s={[H]:t})}}this.markAskUserQuestionResolved(r,s),(T=this.abortController)==null||T.abort(),this.abortController=new AbortController,this.setStreaming(!0);let i=r.toolCall.id,d=(S=r.toolCall)==null?void 0:S.args,l=Array.isArray(d==null?void 0:d.questions)?d.questions:[];if(l.length===0){let y=typeof t=="string"?t:Object.entries(t).map(([M,H])=>`${M}: ${Array.isArray(H)?H.join(", "):H}`).join(" | ");this.appendMessage({id:`ask-user-answer-${i}`,role:"user",content:y,createdAt:new Date().toISOString(),streaming:!1,sequence:this.nextSequence()})}else{let y=s!=null?s:{};l.forEach((M,H)=>{let B=typeof(M==null?void 0:M.question)=="string"?M.question:"";if(!B)return;let R=y[B],W=Array.isArray(R)?R.join(", "):typeof R=="string"?R:"";this.appendMessage({id:`ask-user-q-${i}-${H}`,role:"assistant",content:B,createdAt:new Date().toISOString(),streaming:!1,sequence:this.nextSequence()}),this.appendMessage({id:`ask-user-a-${i}-${H}`,role:"user",content:W||"*Skipped*",createdAt:new Date().toISOString(),streaming:!1,sequence:this.nextSequence()})})}try{let y=await this.client.resumeFlow(o,{[a]:t});if(!y.ok){let M=await y.json().catch(()=>null);throw new Error((E=M==null?void 0:M.error)!=null?E:`Resume failed: ${y.status}`)}y.body?await this.connectStream(y.body,{allowReentry:!0}):(this.setStreaming(!1),this.abortController=null)}catch(y){let M=y instanceof Error&&(y.name==="AbortError"||y.message.includes("aborted")||y.message.includes("abort"));this.setStreaming(!1),this.abortController=null,M||(b=(w=this.callbacks).onError)==null||b.call(w,y instanceof Error?y:new Error(String(y)))}}cancel(){var r;(r=this.abortController)==null||r.abort(),this.abortController=null,this.stopSpeaking(),this.stopVoicePlayback(),this.setStreaming(!1),this.setStatus("idle")}clearMessages(){var r;this.stopSpeaking(),(r=this.abortController)==null||r.abort(),this.abortController=null,this.messages=[],this.agentExecution=null,this.clearArtifactState(),this.setStreaming(!1),this.setStatus("idle"),this.callbacks.onMessagesChanged([...this.messages])}getArtifacts(){return[...this.artifacts.values()]}getArtifactById(r){return this.artifacts.get(r)}getSelectedArtifactId(){return this.selectedArtifactId}selectArtifact(r){this.selectedArtifactId=r,this.emitArtifactsState()}clearArtifacts(){this.clearArtifactState()}upsertArtifact(r){var o;let t=r.id||`art_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,9)}`;if(r.artifactType==="markdown"){let a={id:t,artifactType:"markdown",title:r.title,status:"complete",markdown:r.content};return this.artifacts.set(t,a),this.selectedArtifactId=t,this.emitArtifactsState(),a}let n={id:t,artifactType:"component",title:r.title,status:"complete",component:r.component,props:(o=r.props)!=null?o:{}};return this.artifacts.set(t,n),this.selectedArtifactId=t,this.emitArtifactsState(),n}clearArtifactState(){this.artifacts.size===0&&this.selectedArtifactId===null||(this.artifacts.clear(),this.selectedArtifactId=null,this.emitArtifactsState())}emitArtifactsState(){var r,t;(t=(r=this.callbacks).onArtifactsState)==null||t.call(r,{artifacts:[...this.artifacts.values()],selectedId:this.selectedArtifactId})}applyArtifactStreamEvent(r){var t,n;switch(r.type){case"artifact_start":{r.artifactType==="markdown"?this.artifacts.set(r.id,{id:r.id,artifactType:"markdown",title:r.title,status:"streaming",markdown:""}):this.artifacts.set(r.id,{id:r.id,artifactType:"component",title:r.title,status:"streaming",component:(t=r.component)!=null?t:"",props:{}}),this.selectedArtifactId=r.id;break}case"artifact_delta":{let o=this.artifacts.get(r.id);(o==null?void 0:o.artifactType)==="markdown"&&(o.markdown=((n=o.markdown)!=null?n:"")+r.artDelta);break}case"artifact_update":{let o=this.artifacts.get(r.id);(o==null?void 0:o.artifactType)==="component"&&(o.props={...o.props,...r.props},r.component&&(o.component=r.component));break}case"artifact_complete":{let o=this.artifacts.get(r.id);o&&(o.status="complete");break}default:return}this.emitArtifactsState()}hydrateMessages(r){var t;(t=this.abortController)==null||t.abort(),this.abortController=null,this.messages=this.sortMessages(r.map(n=>{var o;return{...n,streaming:!1,sequence:(o=n.sequence)!=null?o:this.nextSequence()}})),this.setStreaming(!1),this.setStatus("idle"),this.callbacks.onMessagesChanged([...this.messages])}hydrateArtifacts(r,t=null){this.artifacts.clear();for(let n of r)this.artifacts.set(n.id,{...n,status:"complete"});this.selectedArtifactId=t,this.emitArtifactsState()}setStatus(r){this.status!==r&&(this.status=r,this.callbacks.onStatusChanged(r))}setStreaming(r){if(this.streaming===r)return;let t=this.streaming;this.streaming=r,this.callbacks.onStreamingChanged(r),t&&!r&&this.speakLatestAssistantMessage()}speakLatestAssistantMessage(){let r=this.config.textToSpeech;if(!(r!=null&&r.enabled)||!(!r.provider||r.provider==="browser"||r.provider==="runtype"&&r.browserFallback))return;let n=[...this.messages].reverse().find(a=>a.role==="assistant"&&a.content&&!a.voiceProcessing);if(!n)return;if(this.ttsSpokenMessageIds.has(n.id)){this.ttsSpokenMessageIds.delete(n.id);return}let o=n.content;o.trim()&&this.speak(o,r)}speak(r,t){if(typeof window=="undefined"||!("speechSynthesis"in window))return;let n=window.speechSynthesis;n.cancel();let o=new SpeechSynthesisUtterance(r),a=n.getVoices();if(t.voice){let s=a.find(i=>i.name===t.voice);s&&(o.voice=s)}else a.length>0&&(o.voice=t.pickVoice?t.pickVoice(a):e.pickBestVoice(a));t.rate!==void 0&&(o.rate=t.rate),t.pitch!==void 0&&(o.pitch=t.pitch),setTimeout(()=>n.speak(o),50)}static pickBestVoice(r){var n;let t=["Microsoft Jenny Online (Natural) - English (United States)","Microsoft Aria Online (Natural) - English (United States)","Microsoft Guy Online (Natural) - English (United States)","Google US English","Google UK English Female","Ava (Premium)","Evan (Enhanced)","Samantha (Enhanced)","Samantha","Daniel","Karen","Microsoft David Desktop - English (United States)","Microsoft Zira Desktop - English (United States)"];for(let o of t){let a=r.find(s=>s.name===o);if(a)return a}return(n=r.find(o=>o.lang.startsWith("en")))!=null?n:r[0]}stopSpeaking(){typeof window!="undefined"&&"speechSynthesis"in window&&window.speechSynthesis.cancel()}appendMessage(r){let t=this.ensureSequence(r);this.messages=this.sortMessages([...this.messages,t]),this.callbacks.onMessagesChanged([...this.messages])}upsertMessage(r){let t=this.ensureSequence(r),n=this.messages.findIndex(o=>o.id===t.id);if(n===-1){this.appendMessage(t);return}this.messages=this.messages.map((o,a)=>{var i;if(a!==n)return o;let s={...o,...t};return((i=o.agentMetadata)==null?void 0:i.askUserQuestionAnswered)===!0&&t.agentMetadata&&(s.agentMetadata={...t.agentMetadata,askUserQuestionAnswered:!0,...o.agentMetadata.askUserQuestionAnswers?{askUserQuestionAnswers:o.agentMetadata.askUserQuestionAnswers}:{},awaitingLocalTool:!1}),s}),this.messages=this.sortMessages(this.messages),this.callbacks.onMessagesChanged([...this.messages])}ensureSequence(r){return r.sequence!==void 0?{...r}:{...r,sequence:this.nextSequence()}}nextSequence(){return this.sequenceCounter++}sortMessages(r){return[...r].sort((t,n)=>{var d,l;let o=new Date(t.createdAt).getTime(),a=new Date(n.createdAt).getTime();if(!Number.isNaN(o)&&!Number.isNaN(a)&&o!==a)return o-a;let s=(d=t.sequence)!=null?d:0,i=(l=n.sequence)!=null?l:0;return s!==i?s-i:t.id.localeCompare(n.id)})}};var h=(e,r)=>{let t=document.createElement(e);return r&&(t.className=r),t},qn=(e,r,t)=>{let n=e.createElement(r);return t&&(n.className=t),n};var rd=[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2"}]];var nd=[["path",{d:"M12 5v14"}],["path",{d:"m19 12-7 7-7-7"}]];var od=[["path",{d:"m12 19-7-7 7-7"}],["path",{d:"M19 12H5"}]];var ad=[["path",{d:"M5 12h14"}],["path",{d:"m12 5 7 7-7 7"}]];var sd=[["path",{d:"M7 7h10v10"}],["path",{d:"M7 17 17 7"}]];var id=[["path",{d:"m5 12 7-7 7 7"}],["path",{d:"M12 19V5"}]];var ld=[["circle",{cx:"12",cy:"12",r:"4"}],["path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"}]];var dd=[["path",{d:"M4.929 4.929 19.07 19.071"}],["circle",{cx:"12",cy:"12",r:"10"}]];var cd=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326"}]];var pd=[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"}]];var ud=[["path",{d:"M12 8V4H8"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2"}],["path",{d:"M2 14h2"}],["path",{d:"M20 14h2"}],["path",{d:"M15 13v2"}],["path",{d:"M9 13v2"}]];var fd=[["path",{d:"M12 10h.01"}],["path",{d:"M12 14h.01"}],["path",{d:"M12 6h.01"}],["path",{d:"M16 10h.01"}],["path",{d:"M16 14h.01"}],["path",{d:"M16 6h.01"}],["path",{d:"M8 10h.01"}],["path",{d:"M8 14h.01"}],["path",{d:"M8 6h.01"}],["path",{d:"M9 22v-3a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v3"}],["rect",{x:"4",y:"2",width:"16",height:"20",rx:"2"}]];var md=[["path",{d:"M8 2v4"}],["path",{d:"M16 2v4"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2"}],["path",{d:"M3 10h18"}],["path",{d:"M8 14h.01"}],["path",{d:"M12 14h.01"}],["path",{d:"M16 14h.01"}],["path",{d:"M8 18h.01"}],["path",{d:"M12 18h.01"}],["path",{d:"M16 18h.01"}]];var gd=[["path",{d:"M8 2v4"}],["path",{d:"M16 2v4"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2"}],["path",{d:"M3 10h18"}]];var hd=[["path",{d:"M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z"}],["circle",{cx:"12",cy:"13",r:"3"}]];var xd=[["path",{d:"M20 6 9 17l-5-5"}]];var yd=[["path",{d:"m6 9 6 6 6-6"}]];var bd=[["path",{d:"m15 18-6-6 6-6"}]];var Cd=[["path",{d:"m9 18 6-6-6-6"}]];var wd=[["path",{d:"m18 15-6-6-6 6"}]];var Ri=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"m9 12 2 2 4-4"}]];var Hi=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"m15 9-6 6"}],["path",{d:"m9 9 6 6"}]];var vd=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4"}],["path",{d:"M21 14H11"}],["path",{d:"m15 10-4 4 4 4"}]];var Ad=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"}]];var Sd=[["path",{d:"M12 6v6l4 2"}],["circle",{cx:"12",cy:"12",r:"10"}]];var Td=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"}]];var kd=[["rect",{width:"20",height:"14",x:"2",y:"5",rx:"2"}],["line",{x1:"2",x2:"22",y1:"10",y2:"10"}]];var Ed=[["line",{x1:"12",x2:"12",y1:"2",y2:"22"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"}]];var Md=[["path",{d:"M12 15V3"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}],["path",{d:"m7 10 5 5 5-5"}]];var Bi=[["circle",{cx:"12",cy:"12",r:"1"}],["circle",{cx:"12",cy:"5",r:"1"}],["circle",{cx:"12",cy:"19",r:"1"}]];var Wi=[["circle",{cx:"12",cy:"12",r:"1"}],["circle",{cx:"19",cy:"12",r:"1"}],["circle",{cx:"5",cy:"12",r:"1"}]];var Ld=[["path",{d:"M15 3h6v6"}],["path",{d:"M10 14 21 3"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}]];var Pd=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"}],["path",{d:"m2 2 20 20"}]];var Id=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}],["circle",{cx:"12",cy:"12",r:"3"}]];var Rd=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}],["path",{d:"M10 12.5 8 15l2 2.5"}],["path",{d:"m14 12.5 2 2.5-2 2.5"}]];var Hd=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}],["path",{d:"M8 13h2"}],["path",{d:"M14 13h2"}],["path",{d:"M8 17h2"}],["path",{d:"M14 17h2"}]];var Bd=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}],["path",{d:"M10 9H8"}],["path",{d:"M16 13H8"}],["path",{d:"M16 17H8"}]];var Wd=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}]];var Dd=[["path",{d:"M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8"}],["path",{d:"M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z"}],["path",{d:"M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1"}]];var Od=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}],["path",{d:"M7 3v18"}],["path",{d:"M3 7.5h4"}],["path",{d:"M3 12h18"}],["path",{d:"M3 16.5h4"}],["path",{d:"M17 3v18"}],["path",{d:"M17 7.5h4"}],["path",{d:"M17 16.5h4"}]];var Fd=[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528"}]];var Nd=[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"}]];var _d=[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"}]];var Di=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z"}]];var $d=[["rect",{x:"3",y:"8",width:"18",height:"4",rx:"1"}],["path",{d:"M12 8v13"}],["path",{d:"M19 12v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-7"}],["path",{d:"M7.5 8a2.5 2.5 0 0 1 0-5A4.8 8 0 0 1 12 8a4.8 8 0 0 1 4.5-5 2.5 2.5 0 0 1 0 5"}]];var Ud=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"}],["path",{d:"M2 12h20"}]];var qd=[["line",{x1:"4",x2:"20",y1:"9",y2:"9"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21"}]];var zd=[["path",{d:"M3 14h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-7a9 9 0 0 1 18 0v7a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3"}]];var Vd=[["path",{d:"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5"}]];var jd=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}],["path",{d:"M3 3v5h5"}],["path",{d:"M12 7v5l4 2"}]];var Oi=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}]];var Gd=[["path",{d:"M16 5h6"}],["path",{d:"M19 2v6"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"}],["circle",{cx:"9",cy:"9",r:"2"}]];var Xd=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}],["circle",{cx:"9",cy:"9",r:"2"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"}]];var Jd=[["circle",{cx:"12",cy:"12",r:"10"}],["path",{d:"M12 16v-4"}],["path",{d:"M12 8h.01"}]];var Kd=[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4"}],["path",{d:"m21 2-9.6 9.6"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5"}]];var Yd=[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"}]];var Fi=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56"}]];var Qd=[["path",{d:"M12 2v4"}],["path",{d:"m16.2 7.8 2.9-2.9"}],["path",{d:"M18 12h4"}],["path",{d:"m16.2 16.2 2.9 2.9"}],["path",{d:"M12 18v4"}],["path",{d:"m4.9 19.1 2.9-2.9"}],["path",{d:"M2 12h4"}],["path",{d:"m4.9 4.9 2.9 2.9"}]];var Zd=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4"}]];var ec=[["path",{d:"m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7"}],["rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}]];var tc=[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0"}],["circle",{cx:"12",cy:"10",r:"3"}]];var rc=[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3"}]];var nc=[["path",{d:"M4 5h16"}],["path",{d:"M4 12h16"}],["path",{d:"M4 19h16"}]];var oc=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719"}]];var ac=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z"}]];var sc=[["path",{d:"M12 19v3"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}],["rect",{x:"9",y:"2",width:"6",height:"13",rx:"3"}]];var ic=[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"}]];var lc=[["path",{d:"M5 12h14"}]];var dc=[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21"}]];var cc=[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401"}]];var pc=[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z"}],["path",{d:"M12 22V12"}],["polyline",{points:"3.29 7 12 12 20.71 7"}],["path",{d:"m7.5 4.27 9 5.15"}]];var uc=[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551"}]];var fc=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1"}]];var mc=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"}],["path",{d:"m15 5 4 4"}]];var gc=[["line",{x1:"19",x2:"5",y1:"5",y2:"19"}],["circle",{cx:"6.5",cy:"6.5",r:"2.5"}],["circle",{cx:"17.5",cy:"17.5",r:"2.5"}]];var hc=[["path",{d:"M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384"}]];var xc=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z"}]];var yc=[["path",{d:"M5 12h14"}],["path",{d:"M12 5v14"}]];var bc=[["path",{d:"M4 2v20l2-1 2 1 2-1 2 1 2-1 2 1 2-1 2 1V2l-2 1-2-1-2 1-2-1-2 1-2-1-2 1Z"}],["path",{d:"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8"}],["path",{d:"M12 17.5v-11"}]];var Cc=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"}],["path",{d:"M21 3v5h-5"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"}],["path",{d:"M8 16H3v5"}]];var wc=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}],["path",{d:"M21 3v5h-5"}]];var vc=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7"}]];var Ac=[["path",{d:"m21 21-4.34-4.34"}],["circle",{cx:"11",cy:"11",r:"8"}]];var Sc=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z"}],["path",{d:"m21.854 2.147-10.94 10.939"}]];var Tc=[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"}],["circle",{cx:"12",cy:"12",r:"3"}]];var kc=[["path",{d:"M12 2v13"}],["path",{d:"m16 6-4-4-4 4"}],["path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"}]];var Ec=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"M12 8v4"}],["path",{d:"M12 16h.01"}]];var Mc=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m9 12 2 2 4-4"}]];var Ni=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}],["path",{d:"m14.5 9.5-5 5"}],["path",{d:"m9.5 9.5 5 5"}]];var Lc=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}]];var Pc=[["path",{d:"M16 10a4 4 0 0 1-8 0"}],["path",{d:"M3.103 6.034h17.794"}],["path",{d:"M3.4 5.467a2 2 0 0 0-.4 1.2V20a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6.667a2 2 0 0 0-.4-1.2l-2-2.667A2 2 0 0 0 17 2H7a2 2 0 0 0-1.6.8z"}]];var Ic=[["circle",{cx:"8",cy:"21",r:"1"}],["circle",{cx:"19",cy:"21",r:"1"}],["path",{d:"M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12"}]];var Rc=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2"}],["path",{d:"M12 18h.01"}]];var _i=[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z"}],["path",{d:"M20 2v4"}],["path",{d:"M22 4h-4"}],["circle",{cx:"4",cy:"20",r:"2"}]];var Hc=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}]];var Bc=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z"}]];var Wc=[["path",{d:"M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5"}],["path",{d:"M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244"}],["path",{d:"M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05"}]];var Dc=[["circle",{cx:"12",cy:"12",r:"4"}],["path",{d:"M12 2v2"}],["path",{d:"M12 20v2"}],["path",{d:"m4.93 4.93 1.41 1.41"}],["path",{d:"m17.66 17.66 1.41 1.41"}],["path",{d:"M2 12h2"}],["path",{d:"M20 12h2"}],["path",{d:"m6.34 17.66-1.41 1.41"}],["path",{d:"m19.07 4.93-1.41 1.41"}]];var Oc=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor"}]];var Fc=[["path",{d:"M17 14V2"}],["path",{d:"M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z"}]];var Nc=[["path",{d:"M7 10v12"}],["path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z"}]];var _c=[["line",{x1:"10",x2:"14",y1:"2",y2:"2"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11"}],["circle",{cx:"12",cy:"14",r:"8"}]];var $c=[["path",{d:"M10 11v6"}],["path",{d:"M14 11v6"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"}],["path",{d:"M3 6h18"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}]];var Uc=[["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"}],["path",{d:"M3 6h18"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}]];var $i=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}],["path",{d:"M12 9v4"}],["path",{d:"M12 17h.01"}]];var qc=[["path",{d:"M14 18V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v11a1 1 0 0 0 1 1h2"}],["path",{d:"M15 18H9"}],["path",{d:"M19 18h2a1 1 0 0 0 1-1v-3.65a1 1 0 0 0-.22-.624l-3.48-4.35A1 1 0 0 0 17.52 8H14"}],["circle",{cx:"17",cy:"18",r:"2"}],["circle",{cx:"7",cy:"18",r:"2"}]];var zc=[["path",{d:"M12 3v12"}],["path",{d:"m17 8-5-5-5 5"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}]];var Vc=[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}],["circle",{cx:"12",cy:"7",r:"4"}]];var jc=[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z"}],["path",{d:"M16 9a5 5 0 0 1 0 6"}],["path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728"}]];var Gc=[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z"}],["line",{x1:"22",x2:"16",y1:"9",y2:"15"}],["line",{x1:"16",x2:"22",y1:"9",y2:"15"}]];var Xc=[["path",{d:"M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1"}],["path",{d:"M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4"}]];var Jc=[["path",{d:"M18 6 6 18"}],["path",{d:"m6 6 12 12"}]];var Kc=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z"}]];var ub={activity:rd,"arrow-down":nd,"arrow-up":id,"arrow-up-right":sd,bot:ud,"chevron-down":yd,"chevron-up":wd,"chevron-right":Cd,"chevron-left":bd,check:xd,clipboard:Ad,"clipboard-copy":vd,copy:Td,file:Wd,"file-code":Rd,"file-spreadsheet":Hd,"file-text":Bd,"image-plus":Gd,loader:Qd,"loader-circle":Fi,mic:sc,paperclip:uc,"refresh-cw":Cc,search:Ac,send:Sc,"shield-alert":Ec,"shield-check":Mc,"shield-x":Ni,square:Hc,"thumbs-down":Fc,"thumbs-up":Nc,upload:zc,"volume-2":jc,x:Jc,user:Vc,mail:ec,phone:hc,calendar:gd,clock:Sd,building:fd,"map-pin":tc,lock:Zd,key:Kd,"credit-card":kd,"at-sign":ld,hash:qd,globe:Ud,link:Yd,"circle-check":Ri,"circle-x":Hi,"triangle-alert":$i,info:Jd,ban:dd,shield:Lc,"arrow-left":od,"arrow-right":ad,"external-link":Ld,ellipsis:Wi,"ellipsis-vertical":Bi,menu:nc,house:Oi,plus:yc,minus:lc,pencil:mc,trash:Uc,"trash-2":$c,save:vc,download:Md,share:kc,funnel:Di,settings:Tc,"rotate-cw":wc,maximize:rc,minimize:ic,"shopping-cart":Ic,"shopping-bag":Pc,package:pc,truck:qc,tag:Oc,gift:$d,receipt:bc,wallet:Xc,store:Wc,"dollar-sign":Ed,percent:gc,play:xc,pause:fc,"volume-x":Gc,camera:hd,image:Xd,film:Od,headphones:zd,"message-circle":oc,"message-square":ac,bell:cd,heart:Vd,star:Bc,eye:Id,"eye-off":Pd,bookmark:pd,"calendar-days":md,history:jd,timer:_c,folder:_d,"folder-open":Nd,files:Dd,sparkles:_i,zap:Kc,sun:Dc,moon:cc,flag:Fd,monitor:dc,smartphone:Rc},ve=(e,r=24,t="currentColor",n=2)=>{let o=ub[e];return o?fb(o,r,t,n):(console.warn(`Lucide icon "${e}" is not in the Persona registry. Add it to packages/widget/src/utils/icons.ts (see docs/icon-registry-shortlist.md).`),null)};function fb(e,r,t,n){if(!Array.isArray(e))return null;let o=document.createElementNS("http://www.w3.org/2000/svg","svg");return o.setAttribute("width",String(r)),o.setAttribute("height",String(r)),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none"),o.setAttribute("stroke",t),o.setAttribute("stroke-width",String(n)),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"),o.setAttribute("aria-hidden","true"),e.forEach(a=>{if(!Array.isArray(a)||a.length<2)return;let s=a[0],i=a[1];if(!i)return;let d=document.createElementNS("http://www.w3.org/2000/svg",s);Object.entries(i).forEach(([l,u])=>{l!=="stroke"&&d.setAttribute(l,String(u))}),o.appendChild(d)}),o}var Ui={allowedTypes:no,maxFileSize:10*1024*1024,maxFiles:4};function mb(){return`attach_${Date.now()}_${Math.random().toString(36).substring(2,9)}`}function gb(e){return e==="application/pdf"||e.startsWith("text/")||e.includes("word")?"file-text":e.includes("excel")||e.includes("spreadsheet")?"file-spreadsheet":e==="application/json"?"file-code":"file"}var ta=class e{constructor(r={}){this.attachments=[];this.previewsContainer=null;var t,n,o;this.config={allowedTypes:(t=r.allowedTypes)!=null?t:Ui.allowedTypes,maxFileSize:(n=r.maxFileSize)!=null?n:Ui.maxFileSize,maxFiles:(o=r.maxFiles)!=null?o:Ui.maxFiles,onFileRejected:r.onFileRejected,onAttachmentsChange:r.onAttachmentsChange}}setPreviewsContainer(r){this.previewsContainer=r}updateConfig(r){r.allowedTypes!==void 0&&(this.config.allowedTypes=r.allowedTypes.length>0?r.allowedTypes:Ui.allowedTypes),r.maxFileSize!==void 0&&(this.config.maxFileSize=r.maxFileSize),r.maxFiles!==void 0&&(this.config.maxFiles=r.maxFiles),r.onFileRejected!==void 0&&(this.config.onFileRejected=r.onFileRejected),r.onAttachmentsChange!==void 0&&(this.config.onAttachmentsChange=r.onAttachmentsChange)}getAttachments(){return[...this.attachments]}getContentParts(){return this.attachments.map(r=>r.contentPart)}hasAttachments(){return this.attachments.length>0}count(){return this.attachments.length}async handleFileSelect(r){!r||r.length===0||await this.handleFiles(Array.from(r))}async handleFiles(r){var t,n,o,a,s,i,d;if(r.length){for(let l of r){if(this.attachments.length>=this.config.maxFiles){(n=(t=this.config).onFileRejected)==null||n.call(t,l,"count");continue}let u=$g(l,this.config.allowedTypes,this.config.maxFileSize);if(!u.valid){let p=(o=u.error)!=null&&o.includes("type")?"type":"size";(s=(a=this.config).onFileRejected)==null||s.call(a,l,p);continue}try{let p=await _g(l),f=Mi(l)?URL.createObjectURL(l):null,m={id:mb(),file:l,previewUrl:f,contentPart:p};this.attachments.push(m),this.renderPreview(m)}catch(p){console.error("[AttachmentManager] Failed to process file:",p)}}this.updatePreviewsVisibility(),(d=(i=this.config).onAttachmentsChange)==null||d.call(i,this.getAttachments())}}removeAttachment(r){var a,s,i;let t=this.attachments.findIndex(d=>d.id===r);if(t===-1)return;let n=this.attachments[t];n.previewUrl&&URL.revokeObjectURL(n.previewUrl),this.attachments.splice(t,1);let o=(a=this.previewsContainer)==null?void 0:a.querySelector(`[data-attachment-id="${r}"]`);o&&o.remove(),this.updatePreviewsVisibility(),(i=(s=this.config).onAttachmentsChange)==null||i.call(s,this.getAttachments())}clearAttachments(){var r,t;for(let n of this.attachments)n.previewUrl&&URL.revokeObjectURL(n.previewUrl);this.attachments=[],this.previewsContainer&&(this.previewsContainer.innerHTML=""),this.updatePreviewsVisibility(),(t=(r=this.config).onAttachmentsChange)==null||t.call(r,this.getAttachments())}renderPreview(r){if(!this.previewsContainer)return;let t=Mi(r.file),n=h("div","persona-attachment-preview persona-relative persona-inline-block");if(n.setAttribute("data-attachment-id",r.id),n.style.width="48px",n.style.height="48px",t&&r.previewUrl){let s=h("img");s.src=r.previewUrl,s.alt=r.file.name,s.className="persona-w-full persona-h-full persona-object-cover persona-rounded-lg persona-border persona-border-gray-200",s.style.width="48px",s.style.height="48px",s.style.objectFit="cover",s.style.borderRadius="8px",n.appendChild(s)}else{let s=h("div");s.style.width="48px",s.style.height="48px",s.style.borderRadius="8px",s.style.backgroundColor="var(--persona-container, #f3f4f6)",s.style.border="1px solid var(--persona-border, #e5e7eb)",s.style.display="flex",s.style.flexDirection="column",s.style.alignItems="center",s.style.justifyContent="center",s.style.gap="2px",s.style.overflow="hidden";let i=gb(r.file.type),d=ve(i,20,"var(--persona-muted, #6b7280)",1.5);d&&s.appendChild(d);let l=h("span");l.textContent=Ug(r.file.type,r.file.name),l.style.fontSize="8px",l.style.fontWeight="600",l.style.color="var(--persona-muted, #6b7280)",l.style.textTransform="uppercase",l.style.lineHeight="1",s.appendChild(l),n.appendChild(s)}let o=h("button","persona-attachment-remove persona-absolute persona-flex persona-items-center persona-justify-center");o.type="button",o.setAttribute("aria-label","Remove attachment"),o.style.position="absolute",o.style.top="-4px",o.style.right="-4px",o.style.width="18px",o.style.height="18px",o.style.borderRadius="50%",o.style.backgroundColor="var(--persona-palette-colors-black-alpha-60, rgba(0, 0, 0, 0.6))",o.style.border="none",o.style.cursor="pointer",o.style.display="flex",o.style.alignItems="center",o.style.justifyContent="center",o.style.padding="0";let a=ve("x",10,"var(--persona-text-inverse, #ffffff)",2);a?o.appendChild(a):(o.textContent="\xD7",o.style.color="var(--persona-text-inverse, #ffffff)",o.style.fontSize="14px",o.style.lineHeight="1"),o.addEventListener("click",s=>{s.preventDefault(),s.stopPropagation(),this.removeAttachment(r.id)}),n.appendChild(o),this.previewsContainer.appendChild(n)}updatePreviewsVisibility(){this.previewsContainer&&(this.previewsContainer.style.display=this.attachments.length>0?"flex":"none")}static fromConfig(r,t){return new e({allowedTypes:r==null?void 0:r.allowedTypes,maxFileSize:r==null?void 0:r.maxFileSize,maxFiles:r==null?void 0:r.maxFiles,onFileRejected:r==null?void 0:r.onFileRejected,onAttachmentsChange:t})}};var qg=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function bs(e,r){if(!e)return r;if(!r)return e;let t={...e};for(let[n,o]of Object.entries(r)){let a=t[n];qg(a)&&qg(o)?t[n]=bs(a,o):t[n]=o}return t}var mn="min(440px, calc(100vw - 24px))",qi="440px",Gt={apiUrl:"https://api.runtype.com/api/chat/dispatch",clientToken:void 0,theme:void 0,darkTheme:void 0,colorScheme:"light",launcher:{enabled:!0,mountMode:"floating",dock:{side:"right",width:"420px"},title:"Chat Assistant",subtitle:"Here to help you get answers fast",agentIconText:"\u{1F4AC}",agentIconName:"bot",headerIconName:"bot",position:"bottom-right",width:mn,heightOffset:0,autoExpand:!1,callToActionIconHidden:!1,agentIconSize:"40px",headerIconSize:"40px",closeButtonSize:"32px",closeButtonPaddingX:"0px",closeButtonPaddingY:"0px",callToActionIconName:"arrow-up-right",callToActionIconText:"",callToActionIconSize:"32px",callToActionIconPadding:"5px",callToActionIconColor:void 0,callToActionIconBackgroundColor:void 0,closeButtonBackgroundColor:"transparent",clearChat:{backgroundColor:"transparent",borderColor:"transparent",enabled:!0,placement:"inline",iconName:"refresh-cw",size:"32px",showTooltip:!0,tooltipText:"Clear chat",paddingX:"0px",paddingY:"0px"},headerIconHidden:!1,border:void 0,shadow:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)"},copy:{welcomeTitle:"Hello \u{1F44B}",welcomeSubtitle:"Ask anything about your account or products.",inputPlaceholder:"How can I help...",sendButtonLabel:"Send"},sendButton:{borderWidth:"0px",paddingX:"12px",paddingY:"10px",borderColor:void 0,useIcon:!0,iconText:"\u2191",size:"40px",showTooltip:!0,tooltipText:"Send message",iconName:"send"},statusIndicator:{visible:!0,idleText:"Online",connectingText:"Connecting\u2026",connectedText:"Streaming\u2026",errorText:"Offline"},voiceRecognition:{enabled:!0,pauseDuration:2e3,iconName:"mic",iconSize:"39px",borderWidth:"0px",paddingX:"9px",paddingY:"14px",iconColor:void 0,backgroundColor:"transparent",borderColor:"transparent",recordingIconColor:void 0,recordingBackgroundColor:void 0,recordingBorderColor:"transparent",showTooltip:!0,tooltipText:"Start voice recognition"},features:{showReasoning:!0,showToolCalls:!0,scrollToBottom:{enabled:!0,iconName:"arrow-down",label:""},toolCallDisplay:{collapsedMode:"tool-call",activePreview:!1,grouped:!1,previewMaxLines:3,expandable:!0,loadingAnimation:"none"},reasoningDisplay:{activePreview:!1,previewMaxLines:3,expandable:!0,loadingAnimation:"none"},streamAnimation:{type:"none",placeholder:"none",speed:120,duration:1800},askUserQuestion:{enabled:!0,slideInMs:180,freeTextLabel:"Other\u2026",freeTextPlaceholder:"Type your answer\u2026",submitLabel:"Send"}},suggestionChips:["What can you help me with?","Tell me about your features","How does this work?"],suggestionChipsConfig:{fontFamily:"sans-serif",fontWeight:"500",paddingX:"12px",paddingY:"6px"},layout:{header:{layout:"default",showIcon:!0,showTitle:!0,showSubtitle:!0,showCloseButton:!0,showClearChat:!0},messages:{layout:"bubble",avatar:{show:!1,position:"left"},timestamp:{show:!1,position:"below"},groupConsecutive:!1},slots:{}},markdown:{options:{gfm:!0,breaks:!0},disableDefaultStyles:!1},messageActions:{enabled:!0,showCopy:!0,showUpvote:!1,showDownvote:!1,visibility:"hover",align:"right",layout:"pill-inside"},debug:!1};function zg(e,r){if(!(!e&&!r))return e?r?bs(e,r):e:r}function zi(e){var r,t,n,o,a,s,i,d,l,u,p,f,m,C,A,k,T,S,E,w,b;return e?{...Gt,...e,theme:zg(Gt.theme,e.theme),darkTheme:zg(Gt.darkTheme,e.darkTheme),launcher:{...Gt.launcher,...e.launcher,dock:{...(r=Gt.launcher)==null?void 0:r.dock,...(t=e.launcher)==null?void 0:t.dock},clearChat:{...(n=Gt.launcher)==null?void 0:n.clearChat,...(o=e.launcher)==null?void 0:o.clearChat}},copy:{...Gt.copy,...e.copy},sendButton:{...Gt.sendButton,...e.sendButton},statusIndicator:{...Gt.statusIndicator,...e.statusIndicator},voiceRecognition:{...Gt.voiceRecognition,...e.voiceRecognition},features:(()=>{var me,We,Xe,Y,Ee,G,ce,de;let y=(me=Gt.features)==null?void 0:me.artifacts,M=(We=e.features)==null?void 0:We.artifacts,H=(Xe=Gt.features)==null?void 0:Xe.scrollToBottom,B=(Y=e.features)==null?void 0:Y.scrollToBottom,R=(Ee=Gt.features)==null?void 0:Ee.streamAnimation,W=(G=e.features)==null?void 0:G.streamAnimation,V=(ce=Gt.features)==null?void 0:ce.askUserQuestion,ne=(de=e.features)==null?void 0:de.askUserQuestion,ue=y===void 0&&M===void 0?void 0:{...y,...M,layout:{...y==null?void 0:y.layout,...M==null?void 0:M.layout}},Be=H===void 0&&B===void 0?void 0:{...H,...B},Ke=R===void 0&&W===void 0?void 0:{...R,...W},ye=V===void 0&&ne===void 0?void 0:{...V,...ne,styles:{...V==null?void 0:V.styles,...ne==null?void 0:ne.styles}};return{...Gt.features,...e.features,...Be!==void 0?{scrollToBottom:Be}:{},...ue!==void 0?{artifacts:ue}:{},...Ke!==void 0?{streamAnimation:Ke}:{},...ye!==void 0?{askUserQuestion:ye}:{}}})(),suggestionChips:(a=e.suggestionChips)!=null?a:Gt.suggestionChips,suggestionChipsConfig:{...Gt.suggestionChipsConfig,...e.suggestionChipsConfig},layout:{...Gt.layout,...e.layout,header:{...(s=Gt.layout)==null?void 0:s.header,...(i=e.layout)==null?void 0:i.header},messages:{...(d=Gt.layout)==null?void 0:d.messages,...(l=e.layout)==null?void 0:l.messages,avatar:{...(p=(u=Gt.layout)==null?void 0:u.messages)==null?void 0:p.avatar,...(m=(f=e.layout)==null?void 0:f.messages)==null?void 0:m.avatar},timestamp:{...(A=(C=Gt.layout)==null?void 0:C.messages)==null?void 0:A.timestamp,...(T=(k=e.layout)==null?void 0:k.messages)==null?void 0:T.timestamp}},slots:{...(S=Gt.layout)==null?void 0:S.slots,...(E=e.layout)==null?void 0:E.slots}},markdown:{...Gt.markdown,...e.markdown,options:{...(w=Gt.markdown)==null?void 0:w.options,...(b=e.markdown)==null?void 0:b.options}},messageActions:{...Gt.messageActions,...e.messageActions}}:Gt}var Yc={colors:{primary:{50:"#ffffff",100:"#f5f5f5",200:"#d4d4d4",300:"#a3a3a3",400:"#737373",500:"#171717",600:"#0f0f0f",700:"#0a0a0a",800:"#050505",900:"#030303",950:"#000000"},secondary:{50:"#f5f3ff",100:"#ede9fe",200:"#ddd6fe",300:"#c4b5fd",400:"#a78bfa",500:"#8b5cf6",600:"#7c3aed",700:"#6d28d9",800:"#5b21b6",900:"#4c1d95",950:"#2e1065"},accent:{50:"#ecfeff",100:"#cffafe",200:"#a5f3fc",300:"#67e8f9",400:"#22d3ee",500:"#06b6d4",600:"#0891b2",700:"#0e7490",800:"#155e75",900:"#164e63",950:"#083344"},gray:{50:"#f9fafb",100:"#f3f4f6",200:"#e5e7eb",300:"#d1d5db",400:"#9ca3af",500:"#6b7280",600:"#4b5563",700:"#374151",800:"#1f2937",900:"#111827",950:"#030712"},success:{50:"#f0fdf4",100:"#dcfce7",200:"#bbf7d0",300:"#86efac",400:"#4ade80",500:"#22c55e",600:"#16a34a",700:"#15803d",800:"#166534",900:"#14532d"},warning:{50:"#fefce8",100:"#fef9c3",200:"#fef08a",300:"#fde047",400:"#facc15",500:"#eab308",600:"#ca8a04",700:"#a16207",800:"#854d0e",900:"#713f12"},error:{50:"#fef2f2",100:"#fee2e2",200:"#fecaca",300:"#fca5a5",400:"#f87171",500:"#ef4444",600:"#dc2626",700:"#b91c1c",800:"#991b1b",900:"#7f1d1d"},info:{50:"#eff6ff",100:"#dbeafe",200:"#bfdbfe",300:"#93c5fd",400:"#60a5fa",500:"#3b82f6",600:"#2563eb",700:"#1d4ed8",800:"#1e40af",900:"#1e3a8a",950:"#172554"}},spacing:{0:"0px",1:"0.25rem",2:"0.5rem",3:"0.75rem",4:"1rem",5:"1.25rem",6:"1.5rem",8:"2rem",10:"2.5rem",12:"3rem",16:"4rem",20:"5rem",24:"6rem",32:"8rem",40:"10rem",48:"12rem",56:"14rem",64:"16rem"},typography:{fontFamily:{sans:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',serif:'Georgia, Cambria, "Times New Roman", Times, serif',mono:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace"},fontSize:{xs:"0.75rem",sm:"0.875rem",base:"1rem",lg:"1.125rem",xl:"1.25rem","2xl":"1.5rem","3xl":"1.875rem","4xl":"2.25rem"},fontWeight:{normal:"400",medium:"500",semibold:"600",bold:"700"},lineHeight:{tight:"1.25",normal:"1.5",relaxed:"1.625"}},shadows:{none:"none",sm:"0 1px 2px 0 rgb(0 0 0 / 0.05)",md:"0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)",lg:"0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)",xl:"0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)","2xl":"0 25px 50px -12px rgb(0 0 0 / 0.25)"},borders:{none:"none",sm:"1px solid",md:"2px solid",lg:"4px solid"},radius:{none:"0px",sm:"0.125rem",md:"0.375rem",lg:"0.5rem",xl:"0.75rem","2xl":"1rem",full:"9999px"}},Qc={colors:{primary:"palette.colors.primary.500",secondary:"palette.colors.secondary.500",accent:"palette.colors.primary.600",surface:"palette.colors.gray.50",background:"palette.colors.gray.50",container:"palette.colors.gray.50",text:"palette.colors.gray.900",textMuted:"palette.colors.gray.500",textInverse:"palette.colors.gray.50",border:"palette.colors.gray.200",divider:"palette.colors.gray.200",interactive:{default:"palette.colors.primary.600",hover:"palette.colors.primary.700",focus:"palette.colors.primary.600",active:"palette.colors.primary.600",disabled:"palette.colors.gray.300"},feedback:{success:"palette.colors.success.500",warning:"palette.colors.warning.500",error:"palette.colors.error.500",info:"palette.colors.info.500"}},spacing:{xs:"palette.spacing.1",sm:"palette.spacing.2",md:"palette.spacing.4",lg:"palette.spacing.6",xl:"palette.spacing.8","2xl":"palette.spacing.10"},typography:{fontFamily:"palette.typography.fontFamily.sans",fontSize:"palette.typography.fontSize.base",fontWeight:"palette.typography.fontWeight.normal",lineHeight:"palette.typography.lineHeight.normal"}},Zc={button:{primary:{background:"palette.colors.primary.500",foreground:"palette.colors.primary.50",borderRadius:"palette.radius.lg",padding:"semantic.spacing.md"},secondary:{background:"semantic.colors.surface",foreground:"semantic.colors.secondary",borderRadius:"palette.radius.lg",padding:"semantic.spacing.md"},ghost:{background:"transparent",foreground:"semantic.colors.text",borderRadius:"palette.radius.md",padding:"semantic.spacing.sm"}},input:{background:"palette.colors.gray.50",placeholder:"palette.colors.gray.400",borderRadius:"palette.radius.lg",padding:"semantic.spacing.md",focus:{border:"palette.colors.gray.400",ring:"palette.colors.gray.400"}},launcher:{background:"palette.colors.primary.500",foreground:"palette.colors.primary.50",border:"palette.colors.gray.200",size:"60px",iconSize:"28px",borderRadius:"palette.radius.full",shadow:"palette.shadows.lg"},panel:{width:mn,maxWidth:qi,height:"600px",maxHeight:"calc(100vh - 80px)",borderRadius:"palette.radius.xl",shadow:"palette.shadows.xl"},header:{background:"palette.colors.primary.500",border:"palette.colors.primary.600",borderRadius:"palette.radius.xl palette.radius.xl 0 0",padding:"semantic.spacing.md",iconBackground:"palette.colors.primary.600",iconForeground:"palette.colors.primary.50",titleForeground:"palette.colors.primary.50",subtitleForeground:"palette.colors.primary.200",actionIconForeground:"palette.colors.primary.200"},message:{user:{background:"palette.colors.primary.500",text:"palette.colors.primary.50",borderRadius:"palette.radius.lg",shadow:"palette.shadows.sm"},assistant:{background:"palette.colors.gray.50",text:"palette.colors.gray.900",borderRadius:"palette.radius.lg",border:"palette.colors.gray.200",shadow:"palette.shadows.sm"},border:"semantic.colors.border"},introCard:{background:"semantic.colors.surface",borderRadius:"palette.radius.2xl",padding:"semantic.spacing.lg",shadow:"0 5px 15px rgba(15, 23, 42, 0.08)"},toolBubble:{shadow:"palette.shadows.sm"},reasoningBubble:{shadow:"palette.shadows.sm"},composer:{shadow:"none"},markdown:{inlineCode:{background:"palette.colors.gray.50",foreground:"palette.colors.gray.900"},link:{foreground:"palette.colors.primary.600"},prose:{fontFamily:"inherit"},codeBlock:{background:"semantic.colors.container",borderColor:"semantic.colors.border",textColor:"inherit"},table:{headerBackground:"semantic.colors.container",borderColor:"semantic.colors.border"},hr:{color:"semantic.colors.divider"},blockquote:{borderColor:"palette.colors.gray.900",background:"transparent",textColor:"palette.colors.gray.500"}},collapsibleWidget:{container:"palette.colors.gray.50",surface:"semantic.colors.surface",border:"semantic.colors.border"},voice:{recording:{indicator:"palette.colors.error.500",background:"palette.colors.error.50",border:"palette.colors.error.200"},processing:{icon:"palette.colors.primary.500",background:"palette.colors.primary.50"},speaking:{icon:"palette.colors.success.500"}},approval:{requested:{background:"palette.colors.warning.50",border:"palette.colors.warning.200",text:"palette.colors.gray.900"},approve:{background:"palette.colors.success.500",foreground:"palette.colors.gray.50",borderRadius:"palette.radius.md",padding:"semantic.spacing.sm"},deny:{background:"palette.colors.error.500",foreground:"palette.colors.gray.50",borderRadius:"palette.radius.md",padding:"semantic.spacing.sm"}},attachment:{image:{background:"palette.colors.gray.100",border:"palette.colors.gray.200"}},scrollToBottom:{background:"components.button.primary.background",foreground:"components.button.primary.foreground",border:"semantic.colors.primary",size:"40px",borderRadius:"palette.radius.full",shadow:"palette.shadows.sm",padding:"0.5rem 0.875rem",gap:"0.5rem",fontSize:"0.875rem",iconSize:"14px"},artifact:{pane:{background:"semantic.colors.container",toolbarBackground:"semantic.colors.container"}}};function Aa(e,r){if(!r.startsWith("palette.")&&!r.startsWith("semantic.")&&!r.startsWith("components."))return r;let t=r.split("."),n=e;for(let o of t){if(n==null)return;n=n[o]}return typeof n=="string"&&(n.startsWith("palette.")||n.startsWith("semantic.")||n.startsWith("components."))?Aa(e,n):n}function Vi(e){let r={};function t(n,o){for(let[a,s]of Object.entries(n)){let i=`${o}.${a}`;if(typeof s=="string"){let d=Aa(e,s);d!==void 0&&(r[i]={path:i,value:d,type:o.includes("color")?"color":o.includes("spacing")?"spacing":o.includes("typography")?"typography":o.includes("shadow")?"shadow":o.includes("border")?"border":"color"})}else typeof s=="object"&&s!==null&&t(s,i)}}return t(e.palette,"palette"),t(e.semantic,"semantic"),t(e.components,"components"),r}function ep(e){let r=[],t=[];return e.palette||r.push({path:"palette",message:"Theme must include a palette",severity:"error"}),e.semantic||t.push({path:"semantic",message:"No semantic tokens defined - defaults will be used",severity:"warning"}),e.components||t.push({path:"components",message:"No component tokens defined - defaults will be used",severity:"warning"}),{valid:r.length===0,errors:r,warnings:t}}function Vg(e,r){let t={...e};for(let[n,o]of Object.entries(r)){let a=t[n];a&&typeof a=="object"&&!Array.isArray(a)&&o&&typeof o=="object"&&!Array.isArray(o)?t[n]=Vg(a,o):t[n]=o}return t}function hb(e,r){return r?Vg(e,r):e}function Sa(e,r={}){var o,a,s,i,d,l,u,p,f,m,C,A,k;let t={palette:Yc,semantic:Qc,components:Zc},n={palette:{...t.palette,...e==null?void 0:e.palette,colors:{...t.palette.colors,...(o=e==null?void 0:e.palette)==null?void 0:o.colors},spacing:{...t.palette.spacing,...(a=e==null?void 0:e.palette)==null?void 0:a.spacing},typography:{...t.palette.typography,...(s=e==null?void 0:e.palette)==null?void 0:s.typography},shadows:{...t.palette.shadows,...(i=e==null?void 0:e.palette)==null?void 0:i.shadows},borders:{...t.palette.borders,...(d=e==null?void 0:e.palette)==null?void 0:d.borders},radius:{...t.palette.radius,...(l=e==null?void 0:e.palette)==null?void 0:l.radius}},semantic:{...t.semantic,...e==null?void 0:e.semantic,colors:{...t.semantic.colors,...(u=e==null?void 0:e.semantic)==null?void 0:u.colors,interactive:{...t.semantic.colors.interactive,...(f=(p=e==null?void 0:e.semantic)==null?void 0:p.colors)==null?void 0:f.interactive},feedback:{...t.semantic.colors.feedback,...(C=(m=e==null?void 0:e.semantic)==null?void 0:m.colors)==null?void 0:C.feedback}},spacing:{...t.semantic.spacing,...(A=e==null?void 0:e.semantic)==null?void 0:A.spacing},typography:{...t.semantic.typography,...(k=e==null?void 0:e.semantic)==null?void 0:k.typography}},components:hb(t.components,e==null?void 0:e.components)};if(r.validate!==!1){let T=ep(n);if(!T.valid)throw new Error(`Theme validation failed: ${T.errors.map(S=>S.message).join(", ")}`)}if(r.plugins)for(let T of r.plugins)n=T.transform(n);return n}function ji(e){var A,k,T,S,E,w,b,y,M,H,B,R,W,V,ne,ue,Be,Ke,ye,me,We,Xe,Y,Ee,G,ce,de,pe,Re,Ye,J,ie,Ue,K,j,Ce,De,oe,Se,ge,Rt,Me,ae,ur,Ut,Qt,Or,vr,Oe,q,Te,_e,Ne,qe,st,nt,pt,Nt,F,xe,be,it,Ge,Wt,ar,Pt,kt,rt,lt,rr,gn,Ir,Tn,Et,hn,pr,Ar,Kr,bt,kn,nn,Sr,Tr,Vn,En,xn,vt,Pe,P,Z,se,Mt,zt,Ht,sr,xr,Fr,kr,ot,wr,Nr,co,jn,po,Fn,on,Mn,At,ir,lr,an,uo,yn,Ln,sn,z;let r=Vi(e),t={};for(let[he,ln]of Object.entries(r)){let Pn=he.replace(/\./g,"-");t[`--persona-${Pn}`]=ln.value}t["--persona-primary"]=(A=t["--persona-semantic-colors-primary"])!=null?A:t["--persona-palette-colors-primary-500"],t["--persona-secondary"]=(k=t["--persona-semantic-colors-secondary"])!=null?k:t["--persona-palette-colors-secondary-500"],t["--persona-accent"]=(T=t["--persona-semantic-colors-accent"])!=null?T:t["--persona-palette-colors-accent-500"],t["--persona-surface"]=(S=t["--persona-semantic-colors-surface"])!=null?S:t["--persona-palette-colors-gray-50"],t["--persona-background"]=(E=t["--persona-semantic-colors-background"])!=null?E:t["--persona-palette-colors-gray-50"],t["--persona-container"]=(w=t["--persona-semantic-colors-container"])!=null?w:t["--persona-palette-colors-gray-100"],t["--persona-text"]=(b=t["--persona-semantic-colors-text"])!=null?b:t["--persona-palette-colors-gray-900"],t["--persona-text-muted"]=(y=t["--persona-semantic-colors-text-muted"])!=null?y:t["--persona-palette-colors-gray-500"],t["--persona-text-inverse"]=(M=t["--persona-semantic-colors-text-inverse"])!=null?M:t["--persona-palette-colors-gray-50"],t["--persona-border"]=(H=t["--persona-semantic-colors-border"])!=null?H:t["--persona-palette-colors-gray-200"],t["--persona-divider"]=(B=t["--persona-semantic-colors-divider"])!=null?B:t["--persona-palette-colors-gray-200"],t["--persona-muted"]=t["--persona-text-muted"],t["--persona-voice-recording-indicator"]=(R=t["--persona-components-voice-recording-indicator"])!=null?R:t["--persona-palette-colors-error-500"],t["--persona-voice-recording-bg"]=(W=t["--persona-components-voice-recording-background"])!=null?W:t["--persona-palette-colors-error-50"],t["--persona-voice-processing-icon"]=(V=t["--persona-components-voice-processing-icon"])!=null?V:t["--persona-palette-colors-primary-500"],t["--persona-voice-speaking-icon"]=(ne=t["--persona-components-voice-speaking-icon"])!=null?ne:t["--persona-palette-colors-success-500"],t["--persona-approval-bg"]=(ue=t["--persona-components-approval-requested-background"])!=null?ue:t["--persona-palette-colors-warning-50"],t["--persona-approval-border"]=(Be=t["--persona-components-approval-requested-border"])!=null?Be:t["--persona-palette-colors-warning-200"],t["--persona-approval-text"]=(Ke=t["--persona-components-approval-requested-text"])!=null?Ke:t["--persona-palette-colors-gray-900"],t["--persona-approval-approve-bg"]=(ye=t["--persona-components-approval-approve-background"])!=null?ye:t["--persona-palette-colors-success-500"],t["--persona-approval-deny-bg"]=(me=t["--persona-components-approval-deny-background"])!=null?me:t["--persona-palette-colors-error-500"],t["--persona-attachment-image-bg"]=(We=t["--persona-components-attachment-image-background"])!=null?We:t["--persona-palette-colors-gray-100"],t["--persona-attachment-image-border"]=(Xe=t["--persona-components-attachment-image-border"])!=null?Xe:t["--persona-palette-colors-gray-200"],t["--persona-font-family"]=(Y=t["--persona-semantic-typography-fontFamily"])!=null?Y:t["--persona-palette-typography-fontFamily-sans"],t["--persona-font-size"]=(Ee=t["--persona-semantic-typography-fontSize"])!=null?Ee:t["--persona-palette-typography-fontSize-base"],t["--persona-font-weight"]=(G=t["--persona-semantic-typography-fontWeight"])!=null?G:t["--persona-palette-typography-fontWeight-normal"],t["--persona-line-height"]=(ce=t["--persona-semantic-typography-lineHeight"])!=null?ce:t["--persona-palette-typography-lineHeight-normal"],t["--persona-input-font-family"]=t["--persona-font-family"],t["--persona-input-font-weight"]=t["--persona-font-weight"],t["--persona-radius-sm"]=(de=t["--persona-palette-radius-sm"])!=null?de:"0.125rem",t["--persona-radius-md"]=(pe=t["--persona-palette-radius-md"])!=null?pe:"0.375rem",t["--persona-radius-lg"]=(Re=t["--persona-palette-radius-lg"])!=null?Re:"0.5rem",t["--persona-radius-xl"]=(Ye=t["--persona-palette-radius-xl"])!=null?Ye:"0.75rem",t["--persona-radius-full"]=(J=t["--persona-palette-radius-full"])!=null?J:"9999px",t["--persona-launcher-radius"]=(Ue=(ie=t["--persona-components-launcher-borderRadius"])!=null?ie:t["--persona-palette-radius-full"])!=null?Ue:"9999px",t["--persona-launcher-bg"]=(K=t["--persona-components-launcher-background"])!=null?K:t["--persona-primary"],t["--persona-launcher-fg"]=(j=t["--persona-components-launcher-foreground"])!=null?j:t["--persona-text-inverse"],t["--persona-launcher-border"]=(Ce=t["--persona-components-launcher-border"])!=null?Ce:t["--persona-border"],t["--persona-button-primary-bg"]=(De=t["--persona-components-button-primary-background"])!=null?De:t["--persona-primary"],t["--persona-button-primary-fg"]=(oe=t["--persona-components-button-primary-foreground"])!=null?oe:t["--persona-text-inverse"],t["--persona-button-radius"]=(ge=(Se=t["--persona-components-button-primary-borderRadius"])!=null?Se:t["--persona-palette-radius-full"])!=null?ge:"9999px",t["--persona-panel-radius"]=(Me=(Rt=t["--persona-components-panel-borderRadius"])!=null?Rt:t["--persona-radius-xl"])!=null?Me:"0.75rem",t["--persona-panel-border"]=(ae=t["--persona-components-panel-border"])!=null?ae:`1px solid ${t["--persona-border"]}`,t["--persona-panel-shadow"]=(Ut=(ur=t["--persona-components-panel-shadow"])!=null?ur:t["--persona-palette-shadows-xl"])!=null?Ut:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",t["--persona-input-radius"]=(Or=(Qt=t["--persona-components-input-borderRadius"])!=null?Qt:t["--persona-radius-lg"])!=null?Or:"0.5rem",t["--persona-message-user-radius"]=(Oe=(vr=t["--persona-components-message-user-borderRadius"])!=null?vr:t["--persona-radius-lg"])!=null?Oe:"0.5rem",t["--persona-message-assistant-radius"]=(Te=(q=t["--persona-components-message-assistant-borderRadius"])!=null?q:t["--persona-radius-lg"])!=null?Te:"0.5rem",t["--persona-header-bg"]=(_e=t["--persona-components-header-background"])!=null?_e:t["--persona-surface"],t["--persona-header-border"]=(Ne=t["--persona-components-header-border"])!=null?Ne:t["--persona-divider"],t["--persona-header-icon-bg"]=(qe=t["--persona-components-header-iconBackground"])!=null?qe:t["--persona-primary"],t["--persona-header-icon-fg"]=(st=t["--persona-components-header-iconForeground"])!=null?st:t["--persona-text-inverse"],t["--persona-header-title-fg"]=(nt=t["--persona-components-header-titleForeground"])!=null?nt:t["--persona-primary"],t["--persona-header-subtitle-fg"]=(pt=t["--persona-components-header-subtitleForeground"])!=null?pt:t["--persona-text-muted"],t["--persona-header-action-icon-fg"]=(Nt=t["--persona-components-header-actionIconForeground"])!=null?Nt:t["--persona-muted"];let n=(F=e.components)==null?void 0:F.header;n!=null&&n.shadow&&(t["--persona-header-shadow"]=n.shadow),n!=null&&n.borderBottom&&(t["--persona-header-border-bottom"]=n.borderBottom);let o=(xe=e.components)==null?void 0:xe.introCard;t["--persona-intro-card-bg"]=(be=t["--persona-components-introCard-background"])!=null?be:t["--persona-surface"],t["--persona-intro-card-radius"]=(it=t["--persona-components-introCard-borderRadius"])!=null?it:"1rem",t["--persona-intro-card-padding"]=(Ge=t["--persona-components-introCard-padding"])!=null?Ge:"1.5rem",t["--persona-intro-card-shadow"]=(ar=(Wt=o==null?void 0:o.shadow)!=null?Wt:t["--persona-components-introCard-shadow"])!=null?ar:"0 5px 15px rgba(15, 23, 42, 0.08)",t["--persona-input-background"]=(Pt=t["--persona-components-input-background"])!=null?Pt:t["--persona-surface"],t["--persona-input-placeholder"]=(kt=t["--persona-components-input-placeholder"])!=null?kt:t["--persona-text-muted"],t["--persona-message-user-bg"]=(rt=t["--persona-components-message-user-background"])!=null?rt:t["--persona-accent"],t["--persona-message-user-text"]=(lt=t["--persona-components-message-user-text"])!=null?lt:t["--persona-text-inverse"],t["--persona-message-user-shadow"]=(rr=t["--persona-components-message-user-shadow"])!=null?rr:"0 5px 15px rgba(15, 23, 42, 0.08)",t["--persona-message-assistant-bg"]=(gn=t["--persona-components-message-assistant-background"])!=null?gn:t["--persona-surface"],t["--persona-message-assistant-text"]=(Ir=t["--persona-components-message-assistant-text"])!=null?Ir:t["--persona-text"],t["--persona-message-assistant-border"]=(Tn=t["--persona-components-message-assistant-border"])!=null?Tn:t["--persona-border"],t["--persona-message-assistant-shadow"]=(Et=t["--persona-components-message-assistant-shadow"])!=null?Et:"0 1px 2px 0 rgb(0 0 0 / 0.05)",t["--persona-scroll-to-bottom-bg"]=(pr=(hn=t["--persona-components-scrollToBottom-background"])!=null?hn:t["--persona-button-primary-bg"])!=null?pr:t["--persona-accent"],t["--persona-scroll-to-bottom-fg"]=(Kr=(Ar=t["--persona-components-scrollToBottom-foreground"])!=null?Ar:t["--persona-button-primary-fg"])!=null?Kr:t["--persona-text-inverse"],t["--persona-scroll-to-bottom-border"]=(bt=t["--persona-components-scrollToBottom-border"])!=null?bt:t["--persona-primary"],t["--persona-scroll-to-bottom-size"]=(kn=t["--persona-components-scrollToBottom-size"])!=null?kn:"40px",t["--persona-scroll-to-bottom-radius"]=(Tr=(Sr=(nn=t["--persona-components-scrollToBottom-borderRadius"])!=null?nn:t["--persona-button-radius"])!=null?Sr:t["--persona-radius-full"])!=null?Tr:"9999px",t["--persona-scroll-to-bottom-shadow"]=(En=(Vn=t["--persona-components-scrollToBottom-shadow"])!=null?Vn:t["--persona-palette-shadows-sm"])!=null?En:"0 1px 2px 0 rgb(0 0 0 / 0.05)",t["--persona-scroll-to-bottom-padding"]=(xn=t["--persona-components-scrollToBottom-padding"])!=null?xn:"0.5rem 0.875rem",t["--persona-scroll-to-bottom-gap"]=(vt=t["--persona-components-scrollToBottom-gap"])!=null?vt:"0.5rem",t["--persona-scroll-to-bottom-font-size"]=(P=(Pe=t["--persona-components-scrollToBottom-fontSize"])!=null?Pe:t["--persona-palette-typography-fontSize-sm"])!=null?P:"0.875rem",t["--persona-scroll-to-bottom-icon-size"]=(Z=t["--persona-components-scrollToBottom-iconSize"])!=null?Z:"14px",t["--persona-tool-bubble-shadow"]=(se=t["--persona-components-toolBubble-shadow"])!=null?se:"0 5px 15px rgba(15, 23, 42, 0.08)",t["--persona-reasoning-bubble-shadow"]=(Mt=t["--persona-components-reasoningBubble-shadow"])!=null?Mt:"0 5px 15px rgba(15, 23, 42, 0.08)",t["--persona-composer-shadow"]=(zt=t["--persona-components-composer-shadow"])!=null?zt:"none",t["--persona-md-inline-code-bg"]=(Ht=t["--persona-components-markdown-inlineCode-background"])!=null?Ht:t["--persona-container"],t["--persona-md-inline-code-color"]=(sr=t["--persona-components-markdown-inlineCode-foreground"])!=null?sr:t["--persona-text"],t["--persona-md-link-color"]=(Fr=(xr=t["--persona-components-markdown-link-foreground"])!=null?xr:t["--persona-accent"])!=null?Fr:"#0f0f0f";let a=t["--persona-components-markdown-heading-h1-fontSize"];a&&(t["--persona-md-h1-size"]=a);let s=t["--persona-components-markdown-heading-h1-fontWeight"];s&&(t["--persona-md-h1-weight"]=s);let i=t["--persona-components-markdown-heading-h2-fontSize"];i&&(t["--persona-md-h2-size"]=i);let d=t["--persona-components-markdown-heading-h2-fontWeight"];d&&(t["--persona-md-h2-weight"]=d);let l=t["--persona-components-markdown-prose-fontFamily"];l&&l!=="inherit"&&(t["--persona-md-prose-font-family"]=l),t["--persona-md-code-block-bg"]=(kr=t["--persona-components-markdown-codeBlock-background"])!=null?kr:t["--persona-container"],t["--persona-md-code-block-border-color"]=(ot=t["--persona-components-markdown-codeBlock-borderColor"])!=null?ot:t["--persona-border"],t["--persona-md-code-block-text-color"]=(wr=t["--persona-components-markdown-codeBlock-textColor"])!=null?wr:"inherit",t["--persona-md-table-header-bg"]=(Nr=t["--persona-components-markdown-table-headerBackground"])!=null?Nr:t["--persona-container"],t["--persona-md-table-border-color"]=(co=t["--persona-components-markdown-table-borderColor"])!=null?co:t["--persona-border"],t["--persona-md-hr-color"]=(jn=t["--persona-components-markdown-hr-color"])!=null?jn:t["--persona-divider"],t["--persona-md-blockquote-border-color"]=(po=t["--persona-components-markdown-blockquote-borderColor"])!=null?po:t["--persona-palette-colors-gray-900"],t["--persona-md-blockquote-bg"]=(Fn=t["--persona-components-markdown-blockquote-background"])!=null?Fn:"transparent",t["--persona-md-blockquote-text-color"]=(on=t["--persona-components-markdown-blockquote-textColor"])!=null?on:t["--persona-palette-colors-gray-500"],t["--cw-container"]=(Mn=t["--persona-components-collapsibleWidget-container"])!=null?Mn:t["--persona-surface"],t["--cw-surface"]=(At=t["--persona-components-collapsibleWidget-surface"])!=null?At:t["--persona-surface"],t["--cw-border"]=(ir=t["--persona-components-collapsibleWidget-border"])!=null?ir:t["--persona-border"],t["--persona-message-border"]=(lr=t["--persona-components-message-border"])!=null?lr:t["--persona-border"];let u=e.components,p=u==null?void 0:u.iconButton;p&&(p.background&&(t["--persona-icon-btn-bg"]=p.background),p.border&&(t["--persona-icon-btn-border"]=p.border),p.color&&(t["--persona-icon-btn-color"]=p.color),p.padding&&(t["--persona-icon-btn-padding"]=p.padding),p.borderRadius&&(t["--persona-icon-btn-radius"]=p.borderRadius),p.hoverBackground&&(t["--persona-icon-btn-hover-bg"]=p.hoverBackground),p.hoverColor&&(t["--persona-icon-btn-hover-color"]=p.hoverColor),p.activeBackground&&(t["--persona-icon-btn-active-bg"]=p.activeBackground),p.activeBorder&&(t["--persona-icon-btn-active-border"]=p.activeBorder));let f=u==null?void 0:u.labelButton;f&&(f.background&&(t["--persona-label-btn-bg"]=f.background),f.border&&(t["--persona-label-btn-border"]=f.border),f.color&&(t["--persona-label-btn-color"]=f.color),f.padding&&(t["--persona-label-btn-padding"]=f.padding),f.borderRadius&&(t["--persona-label-btn-radius"]=f.borderRadius),f.hoverBackground&&(t["--persona-label-btn-hover-bg"]=f.hoverBackground),f.fontSize&&(t["--persona-label-btn-font-size"]=f.fontSize),f.gap&&(t["--persona-label-btn-gap"]=f.gap));let m=u==null?void 0:u.toggleGroup;m&&(m.gap&&(t["--persona-toggle-group-gap"]=m.gap),m.borderRadius&&(t["--persona-toggle-group-radius"]=m.borderRadius));let C=u==null?void 0:u.artifact;if(C!=null&&C.toolbar){let he=C.toolbar;he.iconHoverColor&&(t["--persona-artifact-toolbar-icon-hover-color"]=he.iconHoverColor),he.iconHoverBackground&&(t["--persona-artifact-toolbar-icon-hover-bg"]=he.iconHoverBackground),he.iconPadding&&(t["--persona-artifact-toolbar-icon-padding"]=he.iconPadding),he.iconBorderRadius&&(t["--persona-artifact-toolbar-icon-radius"]=he.iconBorderRadius),he.iconBorder&&(t["--persona-artifact-toolbar-icon-border"]=he.iconBorder),he.toggleGroupGap&&(t["--persona-artifact-toolbar-toggle-group-gap"]=he.toggleGroupGap),he.toggleBorderRadius&&(t["--persona-artifact-toolbar-toggle-radius"]=he.toggleBorderRadius),he.copyBackground&&(t["--persona-artifact-toolbar-copy-bg"]=he.copyBackground),he.copyBorder&&(t["--persona-artifact-toolbar-copy-border"]=he.copyBorder),he.copyColor&&(t["--persona-artifact-toolbar-copy-color"]=he.copyColor),he.copyBorderRadius&&(t["--persona-artifact-toolbar-copy-radius"]=he.copyBorderRadius),he.copyPadding&&(t["--persona-artifact-toolbar-copy-padding"]=he.copyPadding),he.copyMenuBackground&&(t["--persona-artifact-toolbar-copy-menu-bg"]=he.copyMenuBackground,t["--persona-dropdown-bg"]=(an=t["--persona-dropdown-bg"])!=null?an:he.copyMenuBackground),he.copyMenuBorder&&(t["--persona-artifact-toolbar-copy-menu-border"]=he.copyMenuBorder,t["--persona-dropdown-border"]=(uo=t["--persona-dropdown-border"])!=null?uo:he.copyMenuBorder),he.copyMenuShadow&&(t["--persona-artifact-toolbar-copy-menu-shadow"]=he.copyMenuShadow,t["--persona-dropdown-shadow"]=(yn=t["--persona-dropdown-shadow"])!=null?yn:he.copyMenuShadow),he.copyMenuBorderRadius&&(t["--persona-artifact-toolbar-copy-menu-radius"]=he.copyMenuBorderRadius,t["--persona-dropdown-radius"]=(Ln=t["--persona-dropdown-radius"])!=null?Ln:he.copyMenuBorderRadius),he.copyMenuItemHoverBackground&&(t["--persona-artifact-toolbar-copy-menu-item-hover-bg"]=he.copyMenuItemHoverBackground,t["--persona-dropdown-item-hover-bg"]=(sn=t["--persona-dropdown-item-hover-bg"])!=null?sn:he.copyMenuItemHoverBackground),he.iconBackground&&(t["--persona-artifact-toolbar-icon-bg"]=he.iconBackground),he.toolbarBorder&&(t["--persona-artifact-toolbar-border"]=he.toolbarBorder)}if(C!=null&&C.tab){let he=C.tab;he.background&&(t["--persona-artifact-tab-bg"]=he.background),he.activeBackground&&(t["--persona-artifact-tab-active-bg"]=he.activeBackground),he.activeBorder&&(t["--persona-artifact-tab-active-border"]=he.activeBorder),he.borderRadius&&(t["--persona-artifact-tab-radius"]=he.borderRadius),he.textColor&&(t["--persona-artifact-tab-color"]=he.textColor),he.hoverBackground&&(t["--persona-artifact-tab-hover-bg"]=he.hoverBackground),he.listBackground&&(t["--persona-artifact-tab-list-bg"]=he.listBackground),he.listBorderColor&&(t["--persona-artifact-tab-list-border-color"]=he.listBorderColor),he.listPadding&&(t["--persona-artifact-tab-list-padding"]=he.listPadding)}if(C!=null&&C.pane){let he=C.pane;if(he.toolbarBackground){let ln=(z=Aa(e,he.toolbarBackground))!=null?z:he.toolbarBackground;t["--persona-artifact-toolbar-bg"]=ln}}return t}var jg={header:"Widget header bar",messages:"Message list area","user-message":"User message bubble","assistant-message":"Assistant message bubble",composer:"Footer / composer area",container:"Main widget container","artifact-pane":"Artifact sidebar","artifact-toolbar":"Artifact toolbar"};var xb={colors:{primary:{50:"#ffffff",100:"#f5f5f5",200:"#d4d4d4",300:"#a3a3a3",400:"#737373",500:"#171717",600:"#0f0f0f",700:"#0a0a0a",800:"#050505",900:"#030303",950:"#000000"},secondary:{50:"#f5f3ff",100:"#ede9fe",200:"#ddd6fe",300:"#c4b5fd",400:"#a78bfa",500:"#8b5cf6",600:"#7c3aed",700:"#6d28d9",800:"#5b21b6",900:"#4c1d95",950:"#2e1065"},accent:{50:"#ecfeff",100:"#cffafe",200:"#a5f3fc",300:"#67e8f9",400:"#22d3ee",500:"#06b6d4",600:"#0891b2",700:"#0e7490",800:"#155e75",900:"#164e63",950:"#083344"},gray:{50:"#f9fafb",100:"#f3f4f6",200:"#e5e7eb",300:"#d1d5db",400:"#9ca3af",500:"#6b7280",600:"#4b5563",700:"#374151",800:"#1f2937",900:"#111827",950:"#030712"},success:{50:"#f0fdf4",100:"#dcfce7",200:"#bbf7d0",300:"#86efac",400:"#4ade80",500:"#22c55e",600:"#16a34a",700:"#15803d",800:"#166534",900:"#14532d"},warning:{50:"#fefce8",100:"#fef9c3",200:"#fef08a",300:"#fde047",400:"#facc15",500:"#eab308",600:"#ca8a04",700:"#a16207",800:"#854d0e",900:"#713f12"},error:{50:"#fef2f2",100:"#fee2e2",200:"#fecaca",300:"#fca5a5",400:"#f87171",500:"#ef4444",600:"#dc2626",700:"#b91c1c",800:"#991b1b",900:"#7f1d1d"}}},Gg=e=>{if(!(!e||typeof e!="object"||Array.isArray(e)))return e},Cs=()=>{var e;return typeof document!="undefined"&&document.documentElement.classList.contains("dark")||typeof window!="undefined"&&((e=window.matchMedia)!=null&&e.call(window,"(prefers-color-scheme: dark)").matches)?"dark":"light"},yb=e=>{var t;let r=(t=e==null?void 0:e.colorScheme)!=null?t:"light";return r==="light"?"light":r==="dark"?"dark":Cs()},tp=e=>yb(e),bb=e=>Sa(e),Cb=e=>{var t;let r=Sa(void 0,{validate:!1});return Sa({...e,palette:{...r.palette,colors:{...xb.colors,...(t=e==null?void 0:e.palette)==null?void 0:t.colors}}},{validate:!1})},Ta=e=>{let r=tp(e),t=Gg(e==null?void 0:e.theme),n=Gg(e==null?void 0:e.darkTheme);return r==="dark"?Cb(bs(t!=null?t:{},n!=null?n:{})):bb(t)},wb=e=>ji(e),wo=(e,r)=>{var a;let t=Ta(r),n=wb(t);for(let[s,i]of Object.entries(n))e.style.setProperty(s,i);let o=(a=r==null?void 0:r.toolCall)==null?void 0:a.shadow;o!==void 0&&e.style.setProperty("--persona-tool-bubble-shadow",o.trim()===""?"none":o)},Gi=e=>{let r=[];if(typeof document!="undefined"&&typeof MutationObserver!="undefined"){let t=new MutationObserver(()=>{e(Cs())});t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),r.push(()=>t.disconnect())}if(typeof window!="undefined"&&window.matchMedia){let t=window.matchMedia("(prefers-color-scheme: dark)"),n=()=>e(Cs());t.addEventListener?(t.addEventListener("change",n),r.push(()=>t.removeEventListener("change",n))):t.addListener&&(t.addListener(n),r.push(()=>t.removeListener(n)))}return()=>{r.forEach(t=>t())}};var Xg=(function(){"use strict";let e=()=>{},r={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:f=>f.getAttribute("im-preserve")==="true",shouldReAppend:f=>f.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},restoreFocus:!0};function t(f,m,C={}){f=u(f);let A=p(m),k=l(f,A,C),T=o(k,()=>i(k,f,A,S=>S.morphStyle==="innerHTML"?(a(S,f,A),Array.from(f.childNodes)):n(S,f,A)));return k.pantry.remove(),T}function n(f,m,C){let A=p(m);return a(f,A,C,m,m.nextSibling),Array.from(A.childNodes)}function o(f,m){var E;if(!f.config.restoreFocus)return m();let C=document.activeElement;if(!(C instanceof HTMLInputElement||C instanceof HTMLTextAreaElement))return m();let{id:A,selectionStart:k,selectionEnd:T}=C,S=m();return A&&A!==((E=document.activeElement)==null?void 0:E.getAttribute("id"))&&(C=f.target.querySelector(`[id="${A}"]`),C==null||C.focus()),C&&!C.selectionEnd&&T&&C.setSelectionRange(k,T),S}let a=(function(){function f(w,b,y,M=null,H=null){b instanceof HTMLTemplateElement&&y instanceof HTMLTemplateElement&&(b=b.content,y=y.content),M||(M=b.firstChild);for(let B of y.childNodes){if(M&&M!=H){let W=C(w,B,M,H);if(W){W!==M&&k(w,M,W),s(W,B,w),M=W.nextSibling;continue}}if(B instanceof Element){let W=B.getAttribute("id");if(w.persistentIds.has(W)){let V=T(b,W,M,w);s(V,B,w),M=V.nextSibling;continue}}let R=m(b,B,M,w);R&&(M=R.nextSibling)}for(;M&&M!=H;){let B=M;M=M.nextSibling,A(w,B)}}function m(w,b,y,M){if(M.callbacks.beforeNodeAdded(b)===!1)return null;if(M.idMap.has(b)){let H=document.createElement(b.tagName);return w.insertBefore(H,y),s(H,b,M),M.callbacks.afterNodeAdded(H),H}else{let H=document.importNode(b,!0);return w.insertBefore(H,y),M.callbacks.afterNodeAdded(H),H}}let C=(function(){function w(M,H,B,R){let W=null,V=H.nextSibling,ne=0,ue=B;for(;ue&&ue!=R;){if(y(ue,H)){if(b(M,ue,H))return ue;W===null&&(M.idMap.has(ue)||(W=ue))}if(W===null&&V&&y(ue,V)&&(ne++,V=V.nextSibling,ne>=2&&(W=void 0)),M.activeElementAndParents.includes(ue))break;ue=ue.nextSibling}return W||null}function b(M,H,B){let R=M.idMap.get(H),W=M.idMap.get(B);if(!W||!R)return!1;for(let V of R)if(W.has(V))return!0;return!1}function y(M,H){var W,V,ne;let B=M,R=H;return B.nodeType===R.nodeType&&B.tagName===R.tagName&&(!((W=B.getAttribute)!=null&&W.call(B,"id"))||((V=B.getAttribute)==null?void 0:V.call(B,"id"))===((ne=R.getAttribute)==null?void 0:ne.call(R,"id")))}return w})();function A(w,b){var y;if(w.idMap.has(b))E(w.pantry,b,null);else{if(w.callbacks.beforeNodeRemoved(b)===!1)return;(y=b.parentNode)==null||y.removeChild(b),w.callbacks.afterNodeRemoved(b)}}function k(w,b,y){let M=b;for(;M&&M!==y;){let H=M;M=M.nextSibling,A(w,H)}return M}function T(w,b,y,M){var B,R;let H=((R=(B=M.target).getAttribute)==null?void 0:R.call(B,"id"))===b&&M.target||M.target.querySelector(`[id="${b}"]`)||M.pantry.querySelector(`[id="${b}"]`);return S(H,M),E(w,H,y),H}function S(w,b){let y=w.getAttribute("id");for(;w=w.parentNode;){let M=b.idMap.get(w);M&&(M.delete(y),M.size||b.idMap.delete(w))}}function E(w,b,y){if(w.moveBefore)try{w.moveBefore(b,y)}catch{w.insertBefore(b,y)}else w.insertBefore(b,y)}return f})(),s=(function(){function f(S,E,w){return w.ignoreActive&&S===document.activeElement?null:(w.callbacks.beforeNodeMorphed(S,E)===!1||(S instanceof HTMLHeadElement&&w.head.ignore||(S instanceof HTMLHeadElement&&w.head.style!=="morph"?d(S,E,w):(m(S,E,w),T(S,w)||a(w,S,E))),w.callbacks.afterNodeMorphed(S,E)),S)}function m(S,E,w){let b=E.nodeType;if(b===1){let y=S,M=E,H=y.attributes,B=M.attributes;for(let R of B)k(R.name,y,"update",w)||y.getAttribute(R.name)!==R.value&&y.setAttribute(R.name,R.value);for(let R=H.length-1;0<=R;R--){let W=H[R];if(W&&!M.hasAttribute(W.name)){if(k(W.name,y,"remove",w))continue;y.removeAttribute(W.name)}}T(y,w)||C(y,M,w)}(b===8||b===3)&&S.nodeValue!==E.nodeValue&&(S.nodeValue=E.nodeValue)}function C(S,E,w){if(S instanceof HTMLInputElement&&E instanceof HTMLInputElement&&E.type!=="file"){let b=E.value,y=S.value;A(S,E,"checked",w),A(S,E,"disabled",w),E.hasAttribute("value")?y!==b&&(k("value",S,"update",w)||(S.setAttribute("value",b),S.value=b)):k("value",S,"remove",w)||(S.value="",S.removeAttribute("value"))}else if(S instanceof HTMLOptionElement&&E instanceof HTMLOptionElement)A(S,E,"selected",w);else if(S instanceof HTMLTextAreaElement&&E instanceof HTMLTextAreaElement){let b=E.value,y=S.value;if(k("value",S,"update",w))return;b!==y&&(S.value=b),S.firstChild&&S.firstChild.nodeValue!==b&&(S.firstChild.nodeValue=b)}}function A(S,E,w,b){let y=E[w],M=S[w];if(y!==M){let H=k(w,S,"update",b);H||(S[w]=E[w]),y?H||S.setAttribute(w,""):k(w,S,"remove",b)||S.removeAttribute(w)}}function k(S,E,w,b){return S==="value"&&b.ignoreActiveValue&&E===document.activeElement?!0:b.callbacks.beforeAttributeUpdated(S,E,w)===!1}function T(S,E){return!!E.ignoreActiveValue&&S===document.activeElement&&S!==document.body}return f})();function i(f,m,C,A){if(f.head.block){let k=m.querySelector("head"),T=C.querySelector("head");if(k&&T){let S=d(k,T,f);return Promise.all(S).then(()=>{let E=Object.assign(f,{head:{block:!1,ignore:!0}});return A(E)})}}return A(f)}function d(f,m,C){let A=[],k=[],T=[],S=[],E=new Map;for(let b of m.children)E.set(b.outerHTML,b);for(let b of f.children){let y=E.has(b.outerHTML),M=C.head.shouldReAppend(b),H=C.head.shouldPreserve(b);y||H?M?k.push(b):(E.delete(b.outerHTML),T.push(b)):C.head.style==="append"?M&&(k.push(b),S.push(b)):C.head.shouldRemove(b)!==!1&&k.push(b)}S.push(...E.values());let w=[];for(let b of S){let y=document.createRange().createContextualFragment(b.outerHTML).firstChild;if(C.callbacks.beforeNodeAdded(y)!==!1){if("href"in y&&y.href||"src"in y&&y.src){let M,H=new Promise(function(B){M=B});y.addEventListener("load",function(){M()}),w.push(H)}f.appendChild(y),C.callbacks.afterNodeAdded(y),A.push(y)}}for(let b of k)C.callbacks.beforeNodeRemoved(b)!==!1&&(f.removeChild(b),C.callbacks.afterNodeRemoved(b));return C.head.afterHeadMorphed(f,{added:A,kept:T,removed:k}),w}let l=(function(){function f(w,b,y){let{persistentIds:M,idMap:H}=S(w,b),B=m(y),R=B.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(R))throw`Do not understand how to morph style ${R}`;return{target:w,newContent:b,config:B,morphStyle:R,ignoreActive:B.ignoreActive,ignoreActiveValue:B.ignoreActiveValue,restoreFocus:B.restoreFocus,idMap:H,persistentIds:M,pantry:C(),activeElementAndParents:A(w),callbacks:B.callbacks,head:B.head}}function m(w){let b=Object.assign({},r);return Object.assign(b,w),b.callbacks=Object.assign({},r.callbacks,w.callbacks),b.head=Object.assign({},r.head,w.head),b}function C(){let w=document.createElement("div");return w.hidden=!0,document.body.insertAdjacentElement("afterend",w),w}function A(w){let b=[],y=document.activeElement;if((y==null?void 0:y.tagName)!=="BODY"&&w.contains(y))for(;y&&(b.push(y),y!==w);)y=y.parentElement;return b}function k(w){var y;let b=Array.from(w.querySelectorAll("[id]"));return(y=w.getAttribute)!=null&&y.call(w,"id")&&b.push(w),b}function T(w,b,y,M){for(let H of M){let B=H.getAttribute("id");if(b.has(B)){let R=H;for(;R;){let W=w.get(R);if(W==null&&(W=new Set,w.set(R,W)),W.add(B),R===y)break;R=R.parentElement}}}}function S(w,b){let y=k(w),M=k(b),H=E(y,M),B=new Map;T(B,H,w,y);let R=b.__idiomorphRoot||b;return T(B,H,R,M),{persistentIds:H,idMap:B}}function E(w,b){let y=new Set,M=new Map;for(let{id:B,tagName:R}of w)M.has(B)?y.add(B):M.set(B,R);let H=new Set;for(let{id:B,tagName:R}of b)H.has(B)?y.add(B):M.get(B)===R&&H.add(B);for(let B of y)H.delete(B);return H}return f})(),{normalizeElement:u,normalizeParent:p}=(function(){let f=new WeakSet;function m(T){return T instanceof Document?T.documentElement:T}function C(T){if(T==null)return document.createElement("div");if(typeof T=="string")return C(k(T));if(f.has(T))return T;if(T instanceof Node){if(T.parentNode)return new A(T);{let S=document.createElement("div");return S.append(T),S}}else{let S=document.createElement("div");for(let E of[...T])S.append(E);return S}}class A{constructor(S){this.originalNode=S,this.realParentNode=S.parentNode,this.previousSibling=S.previousSibling,this.nextSibling=S.nextSibling}get childNodes(){let S=[],E=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;E&&E!=this.nextSibling;)S.push(E),E=E.nextSibling;return S}querySelectorAll(S){return this.childNodes.reduce((E,w)=>{if(w instanceof Element){w.matches(S)&&E.push(w);let b=w.querySelectorAll(S);for(let y=0;y<b.length;y++)E.push(b[y])}return E},[])}insertBefore(S,E){return this.realParentNode.insertBefore(S,E)}moveBefore(S,E){return this.realParentNode.moveBefore(S,E)}get __idiomorphRoot(){return this.originalNode}}function k(T){let S=new DOMParser,E=T.replace(/<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim,"");if(E.match(/<\/html>/)||E.match(/<\/head>/)||E.match(/<\/body>/)){let w=S.parseFromString(T,"text/html");if(E.match(/<\/html>/))return f.add(w),w;{let b=w.firstChild;return b&&f.add(b),b}}else{let b=S.parseFromString("<body><template>"+T+"</template></body>","text/html").body.querySelector("template").content;return f.add(b),b}}return{normalizeElement:m,normalizeParent:C}})();return{morph:t,defaults:r}})();var Xi=(e,r,t={})=>{let{preserveTypingAnimation:n=!0}=t;Xg.morph(e,r.innerHTML,{morphStyle:"innerHTML",callbacks:{beforeNodeMorphed(o,a){var s,i;if(o instanceof HTMLElement&&n){if(o.classList.contains("persona-animate-typing")||o.hasAttribute("data-preserve-runtime"))return!1;if(o.hasAttribute("data-preserve-animation")){if(a instanceof HTMLElement&&!a.hasAttribute("data-preserve-animation"))return;if(a instanceof HTMLElement&&a.hasAttribute("data-preserve-animation")){let d=(s=o.textContent)!=null?s:"",l=(i=a.textContent)!=null?i:"";if(d!==l)return}return!1}}}}})};function Jg(e,r){var t,n,o,a,s,i,d,l,u,p,f,m,C,A,k,T,S,E,w,b,y,M,H,B,R,W,V,ne,ue,Be;return[e.id,e.role,(n=(t=e.content)==null?void 0:t.length)!=null?n:0,(a=(o=e.content)==null?void 0:o.slice(-32))!=null?a:"",e.streaming?"1":"0",(s=e.variant)!=null?s:"",(d=(i=e.rawContent)==null?void 0:i.length)!=null?d:0,(u=(l=e.llmContent)==null?void 0:l.length)!=null?u:0,(f=(p=e.approval)==null?void 0:p.status)!=null?f:"",(C=(m=e.toolCall)==null?void 0:m.status)!=null?C:"",(k=(A=e.toolCall)==null?void 0:A.name)!=null?k:"",(E=(S=(T=e.toolCall)==null?void 0:T.chunks)==null?void 0:S.length)!=null?E:0,(M=(y=(b=(w=e.toolCall)==null?void 0:w.chunks)==null?void 0:b[e.toolCall.chunks.length-1])==null?void 0:y.slice(-32))!=null?M:"",typeof((H=e.toolCall)==null?void 0:H.args)=="string"?e.toolCall.args.length:(B=e.toolCall)!=null&&B.args?JSON.stringify(e.toolCall.args).length:0,(V=(W=(R=e.reasoning)==null?void 0:R.chunks)==null?void 0:W.length)!=null?V:0,(ue=(ne=e.contentParts)==null?void 0:ne.length)!=null?ue:0,(Be=e.stopReason)!=null?Be:"",r].join("\0")}function Kg(){return new Map}function Yg(e,r,t){let n=e.get(r);return n&&n.fingerprint===t?n.wrapper:null}function Qg(e,r,t,n){e.set(r,{fingerprint:t,wrapper:n})}function Zg(e,r){for(let t of e.keys())r.has(t)||e.delete(t)}function Ji(e=!0){let r=e;return{isFollowing:()=>r,pause:()=>r?(r=!1,!0):!1,resume:()=>r?!1:(r=!0,!0)}}function ws(e){return Math.max(0,e.scrollHeight-e.clientHeight)}function vs(e,r){return ws(e)-e.scrollTop<=r}function Ki(e){let{following:r,currentScrollTop:t,lastScrollTop:n,nearBottom:o,userScrollThreshold:a,isAutoScrolling:s=!1,pauseOnUpwardScroll:i=!1,pauseWhenAwayFromBottom:d=!0,resumeRequiresDownwardScroll:l=!1}=e,u=t-n;return s||Math.abs(u)<a?{action:"none",delta:u,nextLastScrollTop:t}:!r&&o&&(!l||u>0)?{action:"resume",delta:u,nextLastScrollTop:t}:r&&i&&u<0?{action:"pause",delta:u,nextLastScrollTop:t}:r&&d&&!o?{action:"pause",delta:u,nextLastScrollTop:t}:{action:"none",delta:u,nextLastScrollTop:t}}function Yi(e){let{following:r,deltaY:t,nearBottom:n=!1,resumeWhenNearBottom:o=!1}=e;return r&&t<0?"pause":!r&&o&&t>0&&n?"resume":"none"}var Wr={idle:"Online",connecting:"Connecting\u2026",connected:"Streaming\u2026",error:"Offline"},Dr=1e5,vo=Dr+1;var As={type:"none",placeholder:"none",speed:120,duration:1800,buffer:"none"},vb=["pre","code","a","script","style"],Qi=e=>{var r,t,n,o,a;return{type:(r=e==null?void 0:e.type)!=null?r:As.type,placeholder:(t=e==null?void 0:e.placeholder)!=null?t:As.placeholder,speed:(n=e==null?void 0:e.speed)!=null?n:As.speed,duration:(o=e==null?void 0:e.duration)!=null?o:As.duration,buffer:(a=e==null?void 0:e.buffer)!=null?a:As.buffer}},th=[{name:"typewriter",containerClass:"persona-stream-typewriter",wrap:"char",useCaret:!0},{name:"pop-bubble",bubbleClass:"persona-stream-pop",wrap:"none"},{name:"letter-rise",containerClass:"persona-stream-letter-rise",wrap:"char"},{name:"word-fade",containerClass:"persona-stream-word-fade",wrap:"word"}],Ss=new Map;for(let e of th)Ss.set(e.name,e);var ra=e=>{Ss.set(e.name,e)},op=e=>{th.some(r=>r.name===e)||Ss.delete(e)},ap=()=>Array.from(Ss.keys()),Ts=(e,r)=>{var t,n;return e==="none"?null:r&&Object.prototype.hasOwnProperty.call(r,e)?(t=r[e])!=null?t:null:(n=Ss.get(e))!=null?n:null},Zi=(e,r,t,n,o)=>{if(!o)return e;if(t!=null&&t.bufferContent)return t.bufferContent(e,n);if(!e)return e;if(r==="word"){let a=e.search(/\s(?=\S*$)/);return a<0?"":e.slice(0,a)}if(r==="line"){let a=e.lastIndexOf(`
|
|
55
55
|
`);return a<0?"":e.slice(0,a)}return e},Ab=(e,r,t,n)=>{let o=e.createElement("span");return o.className="persona-stream-char",o.id=`stream-c-${t}-${n}`,o.style.setProperty("--char-index",String(n)),o.textContent=r,o},Sb=(e,r,t,n)=>{let o=e.createElement("span");return o.className="persona-stream-word",o.id=`stream-w-${t}-${n}`,o.style.setProperty("--word-index",String(n)),o.textContent=r,o},rp=/\s/,Tb=(e,r)=>{let t=e.parentNode;for(;t;){if(t.nodeType===1){let n=t;if(r.has(n.tagName.toLowerCase()))return!0}t=t.parentNode}return!1},kb=(e,r,t)=>{var d;let n=e.ownerDocument,o=e.parentNode;if(!n||!o)return;let a=(d=e.nodeValue)!=null?d:"";if(!a)return;let s=n.createDocumentFragment(),i=0;for(;i<a.length;)if(rp.test(a[i])){let l=i;for(;l<a.length&&rp.test(a[l]);)l+=1;s.appendChild(n.createTextNode(a.slice(i,l))),i=l}else{let l=n.createElement("span");l.className="persona-stream-word-group";let u=i;for(;u<a.length&&!rp.test(a[u]);)l.appendChild(Ab(n,a[u],r,t.value)),t.value+=1,u+=1;s.appendChild(l),i=u}o.replaceChild(s,e)},Eb=(e,r,t)=>{var d;let n=e.ownerDocument,o=e.parentNode;if(!n||!o)return;let a=(d=e.nodeValue)!=null?d:"";if(!a)return;let s=n.createDocumentFragment(),i=a.split(/(\s+)/);for(let l of i)l&&(/^\s+$/.test(l)?s.appendChild(n.createTextNode(l)):(s.appendChild(Sb(n,l,r,t.value)),t.value+=1));o.replaceChild(s,e)},ks=(e,r,t,n)=>{var p,f;if(!e||typeof document=="undefined")return e;let o=document.createElement("div");o.innerHTML=e;let a=new Set(((p=n==null?void 0:n.skipTags)!=null?p:vb).map(m=>m.toLowerCase())),s=document.createTreeWalker(o,NodeFilter.SHOW_TEXT,null),i=[],d=s.nextNode();for(;d;)Tb(d,a)||i.push(d),d=s.nextNode();let l={value:(f=n==null?void 0:n.startIndex)!=null?f:0},u=r==="char"?kb:Eb;for(let m of i)u(m,t,l);return o.innerHTML},el=(e=document)=>{let r=e.createElement("span");return r.className="persona-stream-caret",r.setAttribute("aria-hidden","true"),r.setAttribute("data-preserve-animation","stream-caret"),r},Es=(e=document)=>{let r=e.createElement("div");r.className="persona-stream-skeleton",r.setAttribute("data-preserve-animation","stream-skeleton"),r.setAttribute("aria-hidden","true");let t=e.createElement("div");return t.className="persona-stream-skeleton-line",r.appendChild(t),r},eh=new WeakMap,Mb=(e,r)=>{var a;if(!e.styles)return;let t=eh.get(r);if(t||(t=new Set,eh.set(r,t)),t.has(e.name)){let s=e.name.replace(/["\\]/g,"\\$&");if(r.querySelector(`style[data-persona-animation="${s}"]`))return;t.delete(e.name)}t.add(e.name);let o=(r instanceof ShadowRoot?r.ownerDocument:(a=r.ownerDocument)!=null?a:document).createElement("style");o.setAttribute("data-persona-animation",e.name),o.textContent=e.styles,r.appendChild(o)},np=new WeakMap,Lb=(e,r)=>{if(!e.onAttach)return;let t=np.get(r);if(t||(t=new Map,np.set(r,t)),t.has(e.name))return;let n=e.onAttach(r);t.set(e.name,n)},rh=e=>{let r=np.get(e);if(r){for(let t of r.values())typeof t=="function"&&t();r.clear()}},sp=(e,r)=>{Mb(e,r),Lb(e,r)};function ip(e,r=Dr){let t=e.style.position,n=e.style.zIndex,o=e.style.isolation,a=getComputedStyle(e),s=a.position==="static"||a.position==="";return s&&(e.style.position="relative"),e.style.zIndex=String(r),e.style.isolation="isolate",()=>{s&&(e.style.position=t),e.style.zIndex=n,e.style.isolation=o}}var Ms=0,Ao=null;function lp(e=document){var t;if(Ms++,Ms===1){let n=e.body,a=((t=e.defaultView)!=null?t:window).scrollY||e.documentElement.scrollTop;Ao={originalOverflow:n.style.overflow,originalPosition:n.style.position,originalTop:n.style.top,originalWidth:n.style.width,scrollY:a},n.style.overflow="hidden",n.style.position="fixed",n.style.top=`-${a}px`,n.style.width="100%"}let r=!1;return()=>{var n;if(!r&&(r=!0,Ms=Math.max(0,Ms-1),Ms===0&&Ao)){let o=e.body,a=(n=e.defaultView)!=null?n:window;o.style.overflow=Ao.originalOverflow,o.style.position=Ao.originalPosition,o.style.top=Ao.originalTop,o.style.width=Ao.originalWidth,a.scrollTo(0,Ao.scrollY),Ao=null}}}var tl={side:"right",width:"420px",animate:!0,reveal:"resize"},hr=e=>{var r,t;return((t=(r=e==null?void 0:e.launcher)==null?void 0:r.mountMode)!=null?t:"floating")==="docked"},So=e=>{var r,t;return((t=(r=e==null?void 0:e.launcher)==null?void 0:r.mountMode)!=null?t:"floating")==="composer-bar"},vn=e=>{var t,n,o,a,s;let r=(t=e==null?void 0:e.launcher)==null?void 0:t.dock;return{side:(n=r==null?void 0:r.side)!=null?n:tl.side,width:(o=r==null?void 0:r.width)!=null?o:tl.width,animate:(a=r==null?void 0:r.animate)!=null?a:tl.animate,reveal:(s=r==null?void 0:r.reveal)!=null?s:tl.reveal}};var On={"bottom-right":"persona-bottom-6 persona-right-6","bottom-left":"persona-bottom-6 persona-left-6","top-right":"persona-top-6 persona-right-6","top-left":"persona-top-6 persona-left-6"};var Ls=(e,r)=>{let t=h("button");t.type="button",t.innerHTML=`
|
|
56
56
|
<span class="persona-inline-flex persona-items-center persona-justify-center persona-rounded-full persona-bg-persona-primary persona-text-white" data-role="launcher-icon">\u{1F4AC}</span>
|
|
57
57
|
<img data-role="launcher-image" class="persona-rounded-full persona-object-cover" alt="" style="display:none" />
|
|
@@ -60,14 +60,14 @@ Please report this to https://github.com/markedjs/marked.`,r){let o="<p>An error
|
|
|
60
60
|
<span class="persona-block persona-w-full persona-truncate persona-text-xs persona-text-persona-muted" data-role="launcher-subtitle"></span>
|
|
61
61
|
</span>
|
|
62
62
|
<span class="persona-ml-2 persona-grid persona-place-items-center persona-rounded-full persona-bg-persona-primary persona-text-persona-call-to-action" data-role="launcher-call-to-action-icon">\u2197</span>
|
|
63
|
-
`,t.addEventListener("click",r);let n=a=>{var E,v,b,y,M,H,B,R,W,V,ne,ue,We,Ke;let s=(E=a.launcher)!=null?E:{},i=hr(a),d=t.querySelector("[data-role='launcher-title']");if(d){let xe=(v=s.title)!=null?v:"Chat Assistant";d.textContent=xe,d.setAttribute("title",xe)}let l=t.querySelector("[data-role='launcher-subtitle']");if(l){let xe=(b=s.subtitle)!=null?b:"Get answers fast";l.textContent=xe,l.setAttribute("title",xe)}let u=t.querySelector(".persona-flex-col");u&&(s.textHidden||i?u.style.display="none":u.style.display="");let p=t.querySelector("[data-role='launcher-icon']");if(p)if(s.agentIconHidden)p.style.display="none";else{let xe=(y=s.agentIconSize)!=null?y:"40px";if(p.style.height=xe,p.style.width=xe,p.innerHTML="",s.agentIconName){let me=parseFloat(xe)||24,Re=ve(s.agentIconName,me*.6,"var(--persona-text-inverse, #ffffff)",2);Re?(p.appendChild(Re),p.style.display=""):(p.textContent=(M=s.agentIconText)!=null?M:"\u{1F4AC}",p.style.display="")}else s.iconUrl?p.style.display="none":(p.textContent=(H=s.agentIconText)!=null?H:"\u{1F4AC}",p.style.display="")}let f=t.querySelector("[data-role='launcher-image']");if(f){let xe=(B=s.agentIconSize)!=null?B:"40px";f.style.height=xe,f.style.width=xe,s.iconUrl&&!s.agentIconName&&!s.agentIconHidden?(f.src=s.iconUrl,f.style.display="block"):f.style.display="none"}let m=t.querySelector("[data-role='launcher-call-to-action-icon']");if(m){let xe=(R=s.callToActionIconSize)!=null?R:"32px";m.style.height=xe,m.style.width=xe,s.callToActionIconBackgroundColor?(m.style.backgroundColor=s.callToActionIconBackgroundColor,m.classList.remove("persona-bg-persona-primary")):(m.style.backgroundColor="",m.classList.add("persona-bg-persona-primary")),s.callToActionIconColor?(m.style.color=s.callToActionIconColor,m.classList.remove("persona-text-persona-call-to-action")):(m.style.color="",m.classList.add("persona-text-persona-call-to-action"));let me=0;if(s.callToActionIconPadding?(m.style.boxSizing="border-box",m.style.padding=s.callToActionIconPadding,me=(parseFloat(s.callToActionIconPadding)||0)*2):(m.style.boxSizing="",m.style.padding=""),s.callToActionIconHidden)m.style.display="none";else if(m.style.display=i?"none":"",m.innerHTML="",s.callToActionIconName){let Re=parseFloat(xe)||24,Ge=Math.max(Re-me,8),Y=ve(s.callToActionIconName,Ge,"currentColor",2);Y?m.appendChild(Y):m.textContent=(W=s.callToActionIconText)!=null?W:"\u2197"}else m.textContent=(V=s.callToActionIconText)!=null?V:"\u2197"}let C=s.position&&On[s.position]?On[s.position]:On["bottom-right"],w="persona-fixed persona-flex persona-items-center persona-gap-3 persona-rounded-launcher persona-bg-persona-surface persona-py-2.5 persona-pl-3 persona-pr-3 persona-transition hover:persona-translate-y-[-2px] persona-cursor-pointer",k="persona-relative persona-mt-4 persona-mb-4 persona-mx-auto persona-flex persona-items-center persona-justify-center persona-rounded-launcher persona-bg-persona-surface persona-transition hover:persona-translate-y-[-2px] persona-cursor-pointer";t.className=i?k:`${w} ${C}`,i||(t.style.zIndex=String((ne=s.zIndex)!=null?ne:Dr));let T="1px solid var(--persona-border, #e5e7eb)",S="var(--persona-shadow, 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1))";t.style.border=(ue=s.border)!=null?ue:T,t.style.boxShadow=(We=s.shadow)!=null?We:S,i?(t.style.width="0",t.style.minWidth="0",t.style.maxWidth="0",t.style.padding="0",t.style.overflow="hidden",t.style.border="none",t.style.boxShadow="none"):(t.style.width="",t.style.minWidth="",t.style.maxWidth=(Ke=s.collapsedMaxWidth)!=null?Ke:"",t.style.justifyContent="",t.style.padding="",t.style.overflow="")},o=()=>{t.removeEventListener("click",r),t.remove()};return e&&n(e),{element:t,update:n,destroy:o}};var Pb="persona-relative persona-ml-auto persona-inline-flex persona-items-center persona-justify-center",rl=(e,r={})=>{var w,k,T,S,E,v;let{showClose:t=!0,wrapperClassName:n=Pb,buttonSize:o,iconSize:a="28px"}=r,s=(w=e==null?void 0:e.launcher)!=null?w:{},i=(k=o!=null?o:s.closeButtonSize)!=null?k:"32px",d=h("div",n),l=h("button","persona-inline-flex persona-items-center persona-justify-center persona-rounded-full hover:persona-bg-gray-100 persona-cursor-pointer persona-border-none");l.style.height=i,l.style.width=i,l.type="button";let u=(T=s.closeButtonTooltipText)!=null?T:"Close chat",p=(S=s.closeButtonShowTooltip)!=null?S:!0;l.setAttribute("aria-label",u),l.style.display=t?"":"none";let f=(E=s.closeButtonIconName)!=null?E:"x",m=(v=s.closeButtonIconText)!=null?v:"\xD7";l.style.color=s.closeButtonColor||Jr.actionIconColor;let C=ve(f,a,"currentColor",1);if(C?(C.style.display="block",l.appendChild(C)):l.textContent=m,s.closeButtonBackgroundColor?(l.style.backgroundColor=s.closeButtonBackgroundColor,l.classList.remove("hover:persona-bg-gray-100")):(l.style.backgroundColor="",l.classList.add("hover:persona-bg-gray-100")),s.closeButtonBorderWidth||s.closeButtonBorderColor){let b=s.closeButtonBorderWidth||"0px",y=s.closeButtonBorderColor||"transparent";l.style.border=`${b} solid ${y}`,l.classList.remove("persona-border-none")}else l.style.border="",l.classList.add("persona-border-none");if(s.closeButtonBorderRadius?(l.style.borderRadius=s.closeButtonBorderRadius,l.classList.remove("persona-rounded-full")):(l.style.borderRadius="",l.classList.add("persona-rounded-full")),s.closeButtonPaddingX?(l.style.paddingLeft=s.closeButtonPaddingX,l.style.paddingRight=s.closeButtonPaddingX):(l.style.paddingLeft="",l.style.paddingRight=""),s.closeButtonPaddingY?(l.style.paddingTop=s.closeButtonPaddingY,l.style.paddingBottom=s.closeButtonPaddingY):(l.style.paddingTop="",l.style.paddingBottom=""),d.appendChild(l),p&&u){let b=null,y=()=>{if(b)return;let H=l.ownerDocument,B=H.body;if(!B)return;b=qn(H,"div","persona-clear-chat-tooltip"),b.textContent=u;let R=qn(H,"div");R.className="persona-clear-chat-tooltip-arrow",b.appendChild(R);let W=l.getBoundingClientRect();b.style.position="fixed",b.style.zIndex=String(vo),b.style.left=`${W.left+W.width/2}px`,b.style.top=`${W.top-8}px`,b.style.transform="translate(-50%, -100%)",B.appendChild(b)},M=()=>{b&&b.parentNode&&(b.parentNode.removeChild(b),b=null)};d.addEventListener("mouseenter",y),d.addEventListener("mouseleave",M),l.addEventListener("focus",y),l.addEventListener("blur",M),d._cleanupTooltip=()=>{M(),d.removeEventListener("mouseenter",y),d.removeEventListener("mouseleave",M),l.removeEventListener("focus",y),l.removeEventListener("blur",M)}}return{button:l,wrapper:d}},Ib="persona-relative persona-ml-auto persona-clear-chat-button-wrapper",nl=(e,r={})=>{var b,y,M,H,B,R,W,V,ne,ue,We,Ke,xe;let{wrapperClassName:t=Ib,buttonSize:n,iconSize:o="20px"}=r,s=(y=((b=e==null?void 0:e.launcher)!=null?b:{}).clearChat)!=null?y:{},i=(M=n!=null?n:s.size)!=null?M:"32px",d=(H=s.iconName)!=null?H:"refresh-cw",l=(B=s.iconColor)!=null?B:"",u=(R=s.backgroundColor)!=null?R:"",p=(W=s.borderWidth)!=null?W:"",f=(V=s.borderColor)!=null?V:"",m=(ne=s.borderRadius)!=null?ne:"",C=(ue=s.paddingX)!=null?ue:"",w=(We=s.paddingY)!=null?We:"",k=(Ke=s.tooltipText)!=null?Ke:"Clear chat",T=(xe=s.showTooltip)!=null?xe:!0,S=h("div",t),E=h("button","persona-inline-flex persona-items-center persona-justify-center persona-rounded-full hover:persona-bg-gray-100 persona-cursor-pointer persona-border-none");E.style.height=i,E.style.width=i,E.type="button",E.setAttribute("aria-label",k),E.style.color=l||Jr.actionIconColor;let v=ve(d,o,"currentColor",1);if(v&&(v.style.display="block",E.appendChild(v)),u&&(E.style.backgroundColor=u,E.classList.remove("hover:persona-bg-gray-100")),p||f){let me=p||"0px",Re=f||"transparent";E.style.border=`${me} solid ${Re}`,E.classList.remove("persona-border-none")}if(m&&(E.style.borderRadius=m,E.classList.remove("persona-rounded-full")),C&&(E.style.paddingLeft=C,E.style.paddingRight=C),w&&(E.style.paddingTop=w,E.style.paddingBottom=w),S.appendChild(E),T&&k){let me=null,Re=()=>{if(me)return;let Y=E.ownerDocument,Ee=Y.body;if(!Ee)return;me=qn(Y,"div","persona-clear-chat-tooltip"),me.textContent=k;let G=qn(Y,"div");G.className="persona-clear-chat-tooltip-arrow",me.appendChild(G);let ce=E.getBoundingClientRect();me.style.position="fixed",me.style.zIndex=String(vo),me.style.left=`${ce.left+ce.width/2}px`,me.style.top=`${ce.top-8}px`,me.style.transform="translate(-50%, -100%)",Ee.appendChild(me)},Ge=()=>{me&&me.parentNode&&(me.parentNode.removeChild(me),me=null)};S.addEventListener("mouseenter",Re),S.addEventListener("mouseleave",Ge),E.addEventListener("focus",Re),E.addEventListener("blur",Ge),S._cleanupTooltip=()=>{Ge(),S.removeEventListener("mouseenter",Re),S.removeEventListener("mouseleave",Ge),E.removeEventListener("focus",Re),E.removeEventListener("blur",Ge)}}return{button:E,wrapper:S}};var Jr={titleColor:"var(--persona-header-title-fg, var(--persona-primary, #0f0f0f))",subtitleColor:"var(--persona-header-subtitle-fg, var(--persona-text-muted, var(--persona-muted, #9ca3af)))",actionIconColor:"var(--persona-header-action-icon-fg, var(--persona-muted, #9ca3af))"},oo=e=>{var b,y,M,H,B,R,W,V,ne,ue,We,Ke,xe,me,Re,Ge;let{config:r,showClose:t=!0}=e,n=h("div","persona-widget-header persona-flex persona-items-center persona-gap-3 persona-px-6 persona-py-5");n.setAttribute("data-persona-theme-zone","header"),n.style.backgroundColor="var(--persona-header-bg, var(--persona-surface, #ffffff))",n.style.borderBottomColor="var(--persona-header-border, var(--persona-divider, #f1f5f9))",n.style.boxShadow="var(--persona-header-shadow, none)",n.style.borderBottom="var(--persona-header-border-bottom, 1px solid var(--persona-header-border, var(--persona-divider, #f1f5f9)))";let o=(b=r==null?void 0:r.launcher)!=null?b:{},a=(y=o.headerIconSize)!=null?y:"48px",s=(M=o.closeButtonPlacement)!=null?M:"inline",i=(H=o.headerIconHidden)!=null?H:!1,d=o.headerIconName,l=h("div","persona-flex persona-items-center persona-justify-center persona-rounded-xl persona-text-xl");if(l.style.height=a,l.style.width=a,l.style.backgroundColor="var(--persona-header-icon-bg, var(--persona-primary, #0f0f0f))",l.style.color="var(--persona-header-icon-fg, var(--persona-text-inverse, #ffffff))",!i)if(d){let Y=parseFloat(a)||24,Ee=ve(d,Y*.6,"currentColor",1);Ee?l.replaceChildren(Ee):l.textContent=(R=(B=r==null?void 0:r.launcher)==null?void 0:B.agentIconText)!=null?R:"\u{1F4AC}"}else if((W=r==null?void 0:r.launcher)!=null&&W.iconUrl){let Y=h("img");Y.src=r.launcher.iconUrl,Y.alt="",Y.className="persona-rounded-xl persona-object-cover",Y.style.height=a,Y.style.width=a,l.replaceChildren(Y)}else l.textContent=(ne=(V=r==null?void 0:r.launcher)==null?void 0:V.agentIconText)!=null?ne:"\u{1F4AC}";let u=h("div","persona-flex persona-flex-col persona-flex-1 persona-min-w-0"),p=h("span","persona-text-base persona-font-semibold");p.style.color=Jr.titleColor,p.textContent=(We=(ue=r==null?void 0:r.launcher)==null?void 0:ue.title)!=null?We:"Chat Assistant";let f=h("span","persona-text-xs");f.style.color=Jr.subtitleColor,f.textContent=(xe=(Ke=r==null?void 0:r.launcher)==null?void 0:Ke.subtitle)!=null?xe:"Here to help you get answers fast",u.append(p,f),i?n.append(u):n.append(l,u);let m=(me=o.clearChat)!=null?me:{},C=(Re=m.enabled)!=null?Re:!0,w=(Ge=m.placement)!=null?Ge:"inline",k=null,T=null;if(C){let Ee=nl(r,{wrapperClassName:w==="top-right"?"persona-absolute persona-top-4 persona-z-50":"persona-relative persona-ml-auto persona-clear-chat-button-wrapper"});k=Ee.button,T=Ee.wrapper,w==="top-right"&&(T.style.right="48px"),w==="inline"&&n.appendChild(T)}let S=s==="top-right"?"persona-absolute persona-top-4 persona-right-4 persona-z-50":C&&w==="inline"?"persona-relative persona-inline-flex persona-items-center persona-justify-center":"persona-relative persona-ml-auto persona-inline-flex persona-items-center persona-justify-center",{button:E,wrapper:v}=rl(r,{showClose:t,wrapperClassName:S});return s!=="top-right"&&n.appendChild(v),{header:n,iconHolder:l,headerTitle:p,headerSubtitle:f,closeButton:E,closeButtonWrapper:v,clearChatButton:k,clearChatButtonWrapper:T}},na=(e,r,t)=>{var s,i,d,l;let n=(s=t==null?void 0:t.launcher)!=null?s:{},o=(i=n.closeButtonPlacement)!=null?i:"inline",a=(l=(d=n.clearChat)==null?void 0:d.placement)!=null?l:"inline";e.appendChild(r.header),o==="top-right"&&(e.style.position="relative",e.appendChild(r.closeButtonWrapper)),r.clearChatButtonWrapper&&a==="top-right"&&(e.style.position="relative",e.appendChild(r.clearChatButtonWrapper))};function To(e){let{items:r,onSelect:t,anchor:n,position:o="bottom-left",portal:a}=e,s=h("div","persona-dropdown-menu persona-hidden");s.setAttribute("role","menu"),s.setAttribute("data-persona-theme-zone","dropdown"),a?(s.style.position="fixed",s.style.zIndex=String(vo)):(s.style.position="absolute",s.style.top="100%",s.style.marginTop="4px",o==="bottom-right"?s.style.right="0":s.style.left="0");for(let m of r){if(m.dividerBefore){let k=document.createElement("hr");s.appendChild(k)}let C=document.createElement("button");if(C.type="button",C.setAttribute("role","menuitem"),C.setAttribute("data-dropdown-item-id",m.id),m.destructive&&C.setAttribute("data-destructive",""),m.icon){let k=ve(m.icon,16,"currentColor",1.5);k&&C.appendChild(k)}let w=document.createElement("span");w.textContent=m.label,C.appendChild(w),C.addEventListener("click",k=>{k.stopPropagation(),u(),t(m.id)}),s.appendChild(C)}let i=null;function d(){if(!a)return;let m=n.getBoundingClientRect();s.style.top=`${m.bottom+4}px`,o==="bottom-right"?(s.style.right=`${window.innerWidth-m.right}px`,s.style.left="auto"):(s.style.left=`${m.left}px`,s.style.right="auto")}function l(){d(),s.classList.remove("persona-hidden"),requestAnimationFrame(()=>{let m=C=>{!s.contains(C.target)&&!n.contains(C.target)&&u()};document.addEventListener("click",m,!0),i=()=>document.removeEventListener("click",m,!0)})}function u(){s.classList.add("persona-hidden"),i==null||i(),i=null}function p(){s.classList.contains("persona-hidden")?l():u()}function f(){u(),s.remove()}return a&&a.appendChild(s),{element:s,show:l,hide:u,toggle:p,destroy:f}}function Zt(e){let{icon:r,label:t,size:n,strokeWidth:o,className:a,onClick:s,aria:i}=e,d=h("button","persona-icon-btn"+(a?" "+a:""));d.type="button",d.setAttribute("aria-label",t),d.title=t;let l=ve(r,n!=null?n:16,"currentColor",o!=null?o:2);if(l&&d.appendChild(l),s&&d.addEventListener("click",s),i)for(let[u,p]of Object.entries(i))d.setAttribute(u,p);return d}function Ps(e){let{icon:r,label:t,variant:n="default",size:o="sm",iconSize:a,className:s,onClick:i,aria:d}=e,l="persona-label-btn";n!=="default"&&(l+=" persona-label-btn--"+n),l+=" persona-label-btn--"+o,s&&(l+=" "+s);let u=h("button",l);if(u.type="button",u.setAttribute("aria-label",t),r){let f=ve(r,a!=null?a:14,"currentColor",2);f&&u.appendChild(f)}let p=h("span");if(p.textContent=t,u.appendChild(p),i&&u.addEventListener("click",i),d)for(let[f,m]of Object.entries(d))u.setAttribute(f,m);return u}function Is(e){let{items:r,selectedId:t,onSelect:n,className:o}=e,a=h("div","persona-toggle-group"+(o?" "+o:""));a.setAttribute("role","group");let s=t,i=[];function d(){for(let u of i)u.btn.setAttribute("aria-pressed",u.id===s?"true":"false")}for(let u of r){let p;u.icon?p=Zt({icon:u.icon,label:u.label,onClick:()=>{s=u.id,d(),n(u.id)}}):(p=h("button","persona-icon-btn"),p.type="button",p.setAttribute("aria-label",u.label),p.title=u.label,p.textContent=u.label,p.addEventListener("click",()=>{s=u.id,d(),n(u.id)})),p.setAttribute("aria-pressed",u.id===s?"true":"false"),i.push({id:u.id,btn:p}),a.appendChild(p)}function l(u){s=u,d()}return{element:a,setSelected:l}}function ol(e){var m,C;let{label:r,icon:t="chevron-down",menuItems:n,onSelect:o,position:a="bottom-left",portal:s,className:i,hover:d}=e,l=h("div","persona-combo-btn"+(i?" "+i:""));l.style.position="relative",l.style.display="inline-flex",l.style.alignItems="center",l.style.cursor="pointer",l.setAttribute("role","button"),l.setAttribute("tabindex","0"),l.setAttribute("aria-haspopup","true"),l.setAttribute("aria-expanded","false"),l.setAttribute("aria-label",r);let u=h("span","persona-combo-btn-label");u.textContent=r,l.appendChild(u);let p=ve(t,14,"currentColor",2);p&&(p.style.marginLeft="4px",p.style.opacity="0.6",l.appendChild(p)),d&&(l.style.borderRadius=(m=d.borderRadius)!=null?m:"10px",l.style.padding=(C=d.padding)!=null?C:"6px 4px 6px 12px",l.style.border="1px solid transparent",l.style.transition="background-color 0.15s ease, border-color 0.15s ease",l.addEventListener("mouseenter",()=>{var w,k;l.style.backgroundColor=(w=d.background)!=null?w:"",l.style.borderColor=(k=d.border)!=null?k:""}),l.addEventListener("mouseleave",()=>{l.style.backgroundColor="",l.style.borderColor="transparent"}));let f=To({items:n,onSelect:w=>{l.setAttribute("aria-expanded","false"),o(w)},anchor:l,position:a,portal:s});return s||l.appendChild(f.element),l.addEventListener("click",w=>{w.stopPropagation();let k=!f.element.classList.contains("persona-hidden");l.setAttribute("aria-expanded",k?"false":"true"),f.toggle()}),l.addEventListener("keydown",w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),l.click())}),{element:l,setLabel:w=>{u.textContent=w,l.setAttribute("aria-label",w)},open:()=>{l.setAttribute("aria-expanded","true"),f.show()},close:()=>{l.setAttribute("aria-expanded","false"),f.hide()},toggle:()=>{let w=!f.element.classList.contains("persona-hidden");l.setAttribute("aria-expanded",w?"false":"true"),f.toggle()},destroy:()=>{f.destroy(),l.remove()}}}var dp=e=>{var n;let r=oo({config:e.config,showClose:e.showClose,onClose:e.onClose,onClearChat:e.onClearChat}),t=(n=e.layoutHeaderConfig)==null?void 0:n.onTitleClick;if(t){let o=r.headerTitle.parentElement;o&&(o.style.cursor="pointer",o.setAttribute("role","button"),o.setAttribute("tabindex","0"),o.addEventListener("click",()=>t()),o.addEventListener("keydown",a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),t())}))}return r};function Rb(e,r,t){var n,o,a;if(r!=null&&r.length)for(let s of r){let i=h("button","persona-inline-flex persona-items-center persona-justify-center persona-rounded-md persona-border-none persona-bg-transparent persona-p-0 persona-text-persona-muted hover:persona-opacity-80");if(i.type="button",i.setAttribute("aria-label",(o=(n=s.ariaLabel)!=null?n:s.label)!=null?o:s.id),s.icon){let d=ve(s.icon,14,"currentColor",2);d&&i.appendChild(d)}else s.label&&(i.textContent=s.label);if((a=s.menuItems)!=null&&a.length){let d=h("div","persona-relative");d.appendChild(i);let l=To({items:s.menuItems,onSelect:u=>t==null?void 0:t(u),anchor:d,position:"bottom-left"});d.appendChild(l.element),i.addEventListener("click",u=>{u.stopPropagation(),l.toggle()}),e.appendChild(d)}else i.addEventListener("click",()=>t==null?void 0:t(s.id)),e.appendChild(i)}}var cp=e=>{var S,E,v,b,y,M,H,B,R;let{config:r,showClose:t=!0,onClose:n,layoutHeaderConfig:o,onHeaderAction:a}=e,s=(S=r==null?void 0:r.launcher)!=null?S:{},i=h("div","persona-flex persona-items-center persona-justify-between persona-px-6 persona-py-4");i.setAttribute("data-persona-theme-zone","header"),i.style.backgroundColor="var(--persona-header-bg, var(--persona-surface, #ffffff))",i.style.borderBottomColor="var(--persona-header-border, var(--persona-divider, #f1f5f9))",i.style.boxShadow="var(--persona-header-shadow, none)",i.style.borderBottom="var(--persona-header-border-bottom, 1px solid var(--persona-header-border, var(--persona-divider, #f1f5f9)))";let d=o==null?void 0:o.titleMenu,l,u;if(d)l=ol({label:(E=s.title)!=null?E:"Chat Assistant",menuItems:d.menuItems,onSelect:d.onSelect,hover:d.hover,className:""}).element,l.style.color=Jr.titleColor,u=(v=l.querySelector(".persona-combo-btn-label"))!=null?v:l;else{if(l=h("div","persona-flex persona-min-w-0 persona-flex-1 persona-items-center persona-gap-1"),u=h("span","persona-text-base persona-font-semibold persona-truncate"),u.style.color=Jr.titleColor,u.textContent=(b=s.title)!=null?b:"Chat Assistant",l.appendChild(u),Rb(l,o==null?void 0:o.trailingActions,(y=o==null?void 0:o.onAction)!=null?y:a),o!=null&&o.onTitleClick){l.style.cursor="pointer",l.setAttribute("role","button"),l.setAttribute("tabindex","0");let V=o.onTitleClick;l.addEventListener("click",ne=>{ne.target.closest("button")||V()}),l.addEventListener("keydown",ne=>{(ne.key==="Enter"||ne.key===" ")&&(ne.preventDefault(),V())})}let W=o==null?void 0:o.titleRowHover;W&&(l.style.borderRadius=(M=W.borderRadius)!=null?M:"10px",l.style.padding=(H=W.padding)!=null?H:"6px 4px 6px 12px",l.style.margin="-6px 0 -6px -12px",l.style.border="1px solid transparent",l.style.transition="background-color 0.15s ease, border-color 0.15s ease",l.style.width="fit-content",l.style.flex="none",l.addEventListener("mouseenter",()=>{var V,ne;l.style.backgroundColor=(V=W.background)!=null?V:"",l.style.borderColor=(ne=W.border)!=null?ne:""}),l.addEventListener("mouseleave",()=>{l.style.backgroundColor="",l.style.borderColor="transparent"}))}i.appendChild(l);let p=(B=s.closeButtonSize)!=null?B:"32px",f=h("div",""),m=h("button","persona-inline-flex persona-items-center persona-justify-center persona-rounded-full hover:persona-bg-gray-100 persona-cursor-pointer persona-border-none");m.style.height=p,m.style.width=p,m.type="button",m.setAttribute("aria-label","Close chat"),m.style.display=t?"":"none",m.style.color=s.closeButtonColor||Jr.actionIconColor;let C=(R=s.closeButtonIconName)!=null?R:"x",w=ve(C,"28px","currentColor",1);w?m.appendChild(w):m.textContent="\xD7",n&&m.addEventListener("click",n),f.appendChild(m),i.appendChild(f);let k=h("div");k.style.display="none";let T=h("span");return T.style.display="none",{header:i,iconHolder:k,headerTitle:u,headerSubtitle:T,closeButton:m,closeButtonWrapper:f,clearChatButton:null,clearChatButtonWrapper:null}},al={default:dp,minimal:cp},pp=e=>{var r;return(r=al[e])!=null?r:al.default},ka=(e,r,t)=>{var s,i,d;if(r!=null&&r.render){let l=r.render({config:e,onClose:t==null?void 0:t.onClose,onClearChat:t==null?void 0:t.onClearChat,trailingActions:r.trailingActions,onAction:r.onAction}),u=h("div");u.style.display="none";let p=h("span"),f=h("span"),m=h("button");m.style.display="none";let C=h("div");return C.style.display="none",{header:l,iconHolder:u,headerTitle:p,headerSubtitle:f,closeButton:m,closeButtonWrapper:C,clearChatButton:null,clearChatButtonWrapper:null}}let n=(s=r==null?void 0:r.layout)!=null?s:"default",a=pp(n)({config:e,showClose:(d=(i=r==null?void 0:r.showCloseButton)!=null?i:t==null?void 0:t.showClose)!=null?d:!0,onClose:t==null?void 0:t.onClose,onClearChat:t==null?void 0:t.onClearChat,layoutHeaderConfig:r,onHeaderAction:r==null?void 0:r.onAction});return r&&(r.showIcon===!1&&(a.iconHolder.style.display="none"),r.showTitle===!1&&(a.headerTitle.style.display="none"),r.showSubtitle===!1&&(a.headerSubtitle.style.display="none"),r.showCloseButton===!1&&(a.closeButton.style.display="none"),r.showClearChat===!1&&a.clearChatButtonWrapper&&(a.clearChatButtonWrapper.style.display="none")),a};var sl=e=>{var s,i;let r=h("textarea");r.setAttribute("data-persona-composer-input",""),r.placeholder=(i=(s=e==null?void 0:e.copy)==null?void 0:s.inputPlaceholder)!=null?i:"Type your message\u2026",r.className="persona-w-full persona-min-h-[24px] persona-resize-none persona-border-none persona-bg-transparent persona-text-sm persona-text-persona-primary focus:persona-outline-none focus:persona-border-none persona-composer-textarea",r.rows=1,r.style.fontFamily='var(--persona-input-font-family, var(--persona-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif))',r.style.fontWeight="var(--persona-input-font-weight, var(--persona-font-weight, 400))";let t=3,n=20;r.style.maxHeight=`${t*n}px`,r.style.overflowY="auto";let o=()=>{let d=parseFloat(r.style.maxHeight);return Number.isFinite(d)&&d>0?d:t*n},a=()=>{r.addEventListener("input",()=>{r.style.height="auto";let d=Math.min(r.scrollHeight,o());r.style.height=`${d}px`})};return r.style.border="none",r.style.outline="none",r.style.borderWidth="0",r.style.borderStyle="none",r.style.borderColor="transparent",r.addEventListener("focus",()=>{r.style.border="none",r.style.outline="none",r.style.borderWidth="0",r.style.borderStyle="none",r.style.borderColor="transparent",r.style.boxShadow="none"}),r.addEventListener("blur",()=>{r.style.border="none",r.style.outline="none"}),{textarea:r,attachAutoResize:a}},il=e=>{var b,y,M,H,B,R,W,V,ne,ue,We,Ke;let r=(b=e==null?void 0:e.sendButton)!=null?b:{},t=(y=r.useIcon)!=null?y:!1,n=(M=r.iconText)!=null?M:"\u2191",o=r.iconName,a=(H=r.stopIconName)!=null?H:"square",s=(B=r.tooltipText)!=null?B:"Send message",i=(R=r.stopTooltipText)!=null?R:"Stop generating",d=(V=(W=e==null?void 0:e.copy)==null?void 0:W.sendButtonLabel)!=null?V:"Send",l=(ue=(ne=e==null?void 0:e.copy)==null?void 0:ne.stopButtonLabel)!=null?ue:"Stop",u=(We=r.showTooltip)!=null?We:!1,p=(Ke=r.size)!=null?Ke:"40px",f=r.backgroundColor,m=r.textColor,C=h("div","persona-send-button-wrapper"),w=h("button",t?"persona-rounded-button persona-flex persona-items-center persona-justify-center disabled:persona-opacity-50 persona-cursor-pointer":"persona-rounded-button persona-bg-persona-accent persona-px-4 persona-py-2 persona-text-sm persona-font-semibold disabled:persona-opacity-50 persona-cursor-pointer");w.type="submit",w.setAttribute("data-persona-composer-submit","");let k=null,T=null;if(t){w.style.width=p,w.style.height=p,w.style.minWidth=p,w.style.minHeight=p,w.style.fontSize="18px",w.style.lineHeight="1",w.innerHTML="",m?w.style.color=m:w.style.color="var(--persona-button-primary-fg, #ffffff)";let xe=parseFloat(p)||24,me=(m==null?void 0:m.trim())||"currentColor";o?(k=ve(o,xe,me,2),k?w.appendChild(k):w.textContent=n):w.textContent=n,T=ve(a,xe,me,2),f?w.style.backgroundColor=f:w.classList.add("persona-bg-persona-primary")}else w.textContent=d,m?w.style.color=m:w.classList.add("persona-text-white");r.borderWidth&&(w.style.borderWidth=r.borderWidth,w.style.borderStyle="solid"),r.borderColor&&(w.style.borderColor=r.borderColor),r.paddingX?(w.style.paddingLeft=r.paddingX,w.style.paddingRight=r.paddingX):(w.style.paddingLeft="",w.style.paddingRight=""),r.paddingY?(w.style.paddingTop=r.paddingY,w.style.paddingBottom=r.paddingY):(w.style.paddingTop="",w.style.paddingBottom="");let S=null;u&&s&&(S=h("div","persona-send-button-tooltip"),S.textContent=s,C.appendChild(S)),w.setAttribute("aria-label",s),C.appendChild(w);let E="send";return{button:w,wrapper:C,setMode:xe=>{if(xe===E)return;E=xe;let me=xe==="stop"?i:s;if(w.setAttribute("aria-label",me),S&&(S.textContent=me),t){if(k&&T){let Re=xe==="stop"?T:k,Ge=xe==="stop"?k:T;Ge.parentNode===w?w.replaceChild(Re,Ge):w.appendChild(Re)}}else w.textContent=xe==="stop"?l:d}}},ll=e=>{var S,E,v,b,y,M,H,B,R,W,V,ne;let r=(S=e==null?void 0:e.voiceRecognition)!=null?S:{};if(!(r.enabled===!0))return null;let n=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),o=((E=r.provider)==null?void 0:E.type)==="runtype";if(!(n||o))return null;let s=(b=(v=e==null?void 0:e.sendButton)==null?void 0:v.size)!=null?b:"40px",i=h("div","persona-send-button-wrapper"),d=h("button","persona-rounded-button persona-flex persona-items-center persona-justify-center disabled:persona-opacity-50 persona-cursor-pointer");d.type="button",d.setAttribute("data-persona-composer-mic",""),d.setAttribute("aria-label","Start voice recognition");let l=(y=r.iconName)!=null?y:"mic",u=(M=r.iconSize)!=null?M:s,p=parseFloat(u)||24,f=(B=r.backgroundColor)!=null?B:(H=e==null?void 0:e.sendButton)==null?void 0:H.backgroundColor,m=(W=r.iconColor)!=null?W:(R=e==null?void 0:e.sendButton)==null?void 0:R.textColor;d.style.width=u,d.style.height=u,d.style.minWidth=u,d.style.minHeight=u,d.style.fontSize="18px",d.style.lineHeight="1",m?d.style.color=m:d.style.color="var(--persona-text, #111827)";let w=ve(l,p,m||"currentColor",1.5);w?d.appendChild(w):d.textContent="\u{1F3A4}",f&&(d.style.backgroundColor=f),r.borderWidth&&(d.style.borderWidth=r.borderWidth,d.style.borderStyle="solid"),r.borderColor&&(d.style.borderColor=r.borderColor),r.paddingX&&(d.style.paddingLeft=r.paddingX,d.style.paddingRight=r.paddingX),r.paddingY&&(d.style.paddingTop=r.paddingY,d.style.paddingBottom=r.paddingY),i.appendChild(d);let k=(V=r.tooltipText)!=null?V:"Start voice recognition";if(((ne=r.showTooltip)!=null?ne:!1)&&k){let ue=h("div","persona-send-button-tooltip");ue.textContent=k,i.appendChild(ue)}return{button:d,wrapper:i}},dl=e=>{var C,w,k,T,S,E,v,b;let r=(C=e==null?void 0:e.attachments)!=null?C:{};if(r.enabled!==!0)return null;let t=(k=(w=e==null?void 0:e.sendButton)==null?void 0:w.size)!=null?k:"40px",n=h("div","persona-attachment-previews persona-flex persona-flex-wrap persona-gap-2 persona-mb-2");n.style.display="none";let o=h("input");o.type="file",o.accept=((T=r.allowedTypes)!=null?T:no).join(","),o.multiple=((S=r.maxFiles)!=null?S:4)>1,o.style.display="none",o.setAttribute("aria-label","Attach files");let a=h("div","persona-send-button-wrapper"),s=h("button","persona-rounded-button persona-flex persona-items-center persona-justify-center disabled:persona-opacity-50 persona-cursor-pointer persona-attachment-button");s.type="button",s.setAttribute("aria-label",(E=r.buttonTooltipText)!=null?E:"Attach file");let i=(v=r.buttonIconName)!=null?v:"paperclip",d=t,l=parseFloat(d)||40,u=Math.round(l*.6);s.style.width=d,s.style.height=d,s.style.minWidth=d,s.style.minHeight=d,s.style.fontSize="18px",s.style.lineHeight="1",s.style.backgroundColor="transparent",s.style.color="var(--persona-primary, #111827)",s.style.border="none",s.style.borderRadius="6px",s.style.transition="background-color 0.15s ease",s.addEventListener("mouseenter",()=>{s.style.backgroundColor="var(--persona-palette-colors-black-alpha-50, rgba(0, 0, 0, 0.05))"}),s.addEventListener("mouseleave",()=>{s.style.backgroundColor="transparent"});let p=ve(i,u,"currentColor",1.5);p?s.appendChild(p):s.textContent="\u{1F4CE}",s.addEventListener("click",y=>{y.preventDefault(),o.click()}),a.appendChild(s);let f=(b=r.buttonTooltipText)!=null?b:"Attach file",m=h("div","persona-send-button-tooltip");return m.textContent=f,a.appendChild(m),{button:s,wrapper:a,input:o,previewsContainer:n}},cl=e=>{var s,i,d;let r=(s=e==null?void 0:e.statusIndicator)!=null?s:{},t=r.align==="left"?"persona-text-left":r.align==="center"?"persona-text-center":"persona-text-right",n=h("div",`persona-mt-2 ${t} persona-text-xs persona-text-persona-muted`);n.setAttribute("data-persona-composer-status","");let o=(i=r.visible)!=null?i:!0;n.style.display=o?"":"none";let a=(d=r.idleText)!=null?d:"Online";if(r.idleLink){let l=h("a");l.href=r.idleLink,l.target="_blank",l.rel="noopener noreferrer",l.textContent=a,l.style.color="inherit",l.style.textDecoration="none",n.appendChild(l)}else n.textContent=a;return n},pl=()=>h("div","persona-mb-3 persona-flex persona-flex-wrap persona-gap-2");var Ea=e=>{var C,w,k,T,S,E;let{config:r}=e,t=h("div","persona-widget-footer persona-border-t-persona-divider persona-bg-persona-surface persona-px-6 persona-py-4");t.setAttribute("data-persona-theme-zone","composer");let n=pl(),o=h("form","persona-widget-composer persona-flex persona-flex-col persona-gap-2 persona-rounded-2xl persona-border persona-border-gray-200 persona-bg-persona-input-background persona-px-4 persona-py-3");o.setAttribute("data-persona-composer-form",""),o.style.outline="none";let{textarea:a,attachAutoResize:s}=sl(r);s();let i=il(r),d=ll(r),l=dl(r),u=cl(r);l&&(l.previewsContainer.style.gap="8px",o.append(l.previewsContainer,l.input)),o.append(a);let p=h("div","persona-widget-composer__actions persona-flex persona-items-center persona-justify-between persona-w-full"),f=h("div","persona-widget-composer__left-actions persona-flex persona-items-center persona-gap-2"),m=h("div","persona-widget-composer__right-actions persona-flex persona-items-center persona-gap-1");return l&&f.append(l.wrapper),d&&m.append(d.wrapper),m.append(i.wrapper),p.append(f,m),o.append(p),o.addEventListener("click",v=>{v.target!==i.button&&v.target!==i.wrapper&&v.target!==(d==null?void 0:d.button)&&v.target!==(d==null?void 0:d.wrapper)&&v.target!==(l==null?void 0:l.button)&&v.target!==(l==null?void 0:l.wrapper)&&a.focus()}),t.append(n,o,u),{footer:t,suggestions:n,composerForm:o,textarea:a,sendButton:i.button,sendButtonWrapper:i.wrapper,micButton:(C=d==null?void 0:d.button)!=null?C:null,micButtonWrapper:(w=d==null?void 0:d.wrapper)!=null?w:null,statusText:u,attachmentButton:(k=l==null?void 0:l.button)!=null?k:null,attachmentButtonWrapper:(T=l==null?void 0:l.wrapper)!=null?T:null,attachmentInput:(S=l==null?void 0:l.input)!=null?S:null,attachmentPreviewsContainer:(E=l==null?void 0:l.previewsContainer)!=null?E:null,actionsRow:p,leftActions:f,rightActions:m,setSendButtonMode:i.setMode}};var nh=()=>{let e=h("button","persona-pill-peek");e.type="button",e.setAttribute("data-persona-pill-peek",""),e.setAttribute("aria-label","Show conversation"),e.setAttribute("tabindex","-1");let r=h("span","persona-pill-peek__icon"),t=ve("message-square",16,"currentColor",1.5);t&&r.appendChild(t);let n=h("span","persona-pill-peek__text"),o=h("span","persona-pill-peek__caret"),a=ve("chevron-up",16,"currentColor",1.5);return a&&o.appendChild(a),e.append(r,n,o),{root:e,textNode:n}},oh=e=>{var C,w,k,T,S,E;let{config:r}=e,t=h("div","persona-widget-footer persona-widget-footer--pill");t.setAttribute("data-persona-theme-zone","composer");let n=pl();n.style.display="none";let o=cl(r);o.style.display="none";let{textarea:a,attachAutoResize:s}=sl(r);a.style.maxHeight="100px",s();let i=il(r),d=ll(r),l=dl(r);l&&l.previewsContainer.classList.add("persona-pill-composer__previews");let u=h("form","persona-widget-composer persona-pill-composer");u.setAttribute("data-persona-composer-form",""),u.style.outline="none";let p=h("div","persona-widget-composer__left-actions persona-pill-composer__left");l&&p.append(l.wrapper);let f=h("div","persona-widget-composer__right-actions persona-pill-composer__right");d&&f.append(d.wrapper),f.append(i.wrapper),u.addEventListener("click",v=>{v.target!==i.button&&v.target!==i.wrapper&&v.target!==(d==null?void 0:d.button)&&v.target!==(d==null?void 0:d.wrapper)&&v.target!==(l==null?void 0:l.button)&&v.target!==(l==null?void 0:l.wrapper)&&a.focus()}),l&&u.append(l.input),u.append(p,a,f),l&&t.append(l.previewsContainer),t.append(u,n,o);let m=u;return{footer:t,suggestions:n,composerForm:u,textarea:a,sendButton:i.button,sendButtonWrapper:i.wrapper,micButton:(C=d==null?void 0:d.button)!=null?C:null,micButtonWrapper:(w=d==null?void 0:d.wrapper)!=null?w:null,statusText:o,attachmentButton:(k=l==null?void 0:l.button)!=null?k:null,attachmentButtonWrapper:(T=l==null?void 0:l.wrapper)!=null?T:null,attachmentInput:(S=l==null?void 0:l.input)!=null?S:null,attachmentPreviewsContainer:(E=l==null?void 0:l.previewsContainer)!=null?E:null,actionsRow:m,leftActions:p,rightActions:f,setSendButtonMode:i.setMode}};var ah=e=>{var u,p,f,m,C,w,k,T,S,E,v,b,y,M,H,B,R;let r=(p=(u=e==null?void 0:e.launcher)==null?void 0:u.enabled)!=null?p:!0,t=hr(e);if(So(e)){let W=(m=(f=e==null?void 0:e.launcher)==null?void 0:f.composerBar)!=null?m:{},V=h("div","persona-widget-wrapper persona-fixed persona-transition");V.setAttribute("data-persona-composer-bar",""),V.dataset.state="collapsed",V.dataset.expandedSize=(C=W.expandedSize)!=null?C:"anchored",V.style.zIndex=String((k=(w=e==null?void 0:e.launcher)==null?void 0:w.zIndex)!=null?k:Dr);let ne=h("div","persona-widget-panel persona-relative persona-flex persona-flex-1 persona-min-h-0 persona-flex-col");ne.style.width="100%",V.appendChild(ne);let ue=h("div","persona-widget-pill-root");return ue.setAttribute("data-persona-composer-bar",""),ue.dataset.state="collapsed",ue.dataset.expandedSize=(T=W.expandedSize)!=null?T:"anchored",ue.style.zIndex=String((E=(S=e==null?void 0:e.launcher)==null?void 0:S.zIndex)!=null?E:Dr),{wrapper:V,panel:ne,pillRoot:ue}}if(t){let W=h("div","persona-relative persona-h-full persona-w-full persona-flex persona-flex-1 persona-min-h-0 persona-flex-col"),V=h("div","persona-relative persona-h-full persona-w-full persona-flex persona-flex-1 persona-min-h-0 persona-flex-col");return W.appendChild(V),{wrapper:W,panel:V}}if(!r){let W=h("div","persona-relative persona-h-full persona-flex persona-flex-col persona-flex-1 persona-min-h-0"),V=h("div","persona-relative persona-flex-1 persona-flex persona-flex-col persona-min-h-0"),ne=(b=(v=e==null?void 0:e.launcher)==null?void 0:v.width)!=null?b:"100%";return W.style.width=ne,V.style.width="100%",W.appendChild(V),{wrapper:W,panel:V}}let o=(y=e==null?void 0:e.launcher)!=null?y:{},a=o.position&&On[o.position]?On[o.position]:On["bottom-right"],s=h("div",`persona-widget-wrapper persona-fixed ${a} persona-transition`);s.style.zIndex=String((H=(M=e==null?void 0:e.launcher)==null?void 0:M.zIndex)!=null?H:Dr);let i=h("div","persona-widget-panel persona-relative persona-min-h-[320px]"),d=(R=(B=e==null?void 0:e.launcher)==null?void 0:B.width)!=null?R:e==null?void 0:e.launcherWidth,l=d!=null?d:mn;return i.style.width=l,i.style.maxWidth=l,s.appendChild(i),{wrapper:s,panel:i}},Hb=(e,r)=>{var v,b,y,M,H,B,R,W,V;let t=h("div","persona-widget-container persona-relative persona-flex persona-flex-1 persona-min-h-0 persona-flex-col persona-text-persona-primary");t.setAttribute("data-persona-theme-zone","container");let{button:n,wrapper:o}=rl(e,{showClose:r,wrapperClassName:"persona-composer-bar-close",buttonSize:"16px",iconSize:"14px"});o.style.position="absolute",o.style.top="8px",o.style.right="8px",o.style.zIndex="10";let a=(y=(b=(v=e==null?void 0:e.launcher)==null?void 0:v.clearChat)==null?void 0:b.enabled)!=null?y:!0,s=null,i=null;if(a){let ne=nl(e,{wrapperClassName:"persona-composer-bar-clear-chat",buttonSize:"16px",iconSize:"14px"});s=ne.button,i=ne.wrapper,i.style.position="absolute",i.style.top="8px",i.style.right="32px",i.style.zIndex="10"}let d=h("span","persona-widget-header");d.setAttribute("data-persona-theme-zone","header"),d.style.display="none";let l=h("div","persona-widget-body persona-flex persona-flex-1 persona-min-h-0 persona-flex-col persona-gap-6 persona-overflow-y-auto persona-bg-persona-container persona-px-6 persona-py-6");l.style.paddingTop="48px",l.id="persona-scroll-container",l.setAttribute("data-persona-theme-zone","messages");let u=h("div","persona-rounded-2xl persona-bg-persona-surface persona-p-6");u.style.boxShadow="var(--persona-intro-card-shadow, 0 5px 15px rgba(15, 23, 42, 0.08))",u.setAttribute("data-persona-intro-card","");let p=h("h2","persona-text-lg persona-font-semibold persona-text-persona-primary");p.textContent=(H=(M=e==null?void 0:e.copy)==null?void 0:M.welcomeTitle)!=null?H:"Hello \u{1F44B}";let f=h("p","persona-mt-2 persona-text-sm persona-text-persona-muted");f.textContent=(R=(B=e==null?void 0:e.copy)==null?void 0:B.welcomeSubtitle)!=null?R:"Ask anything about your account or products.",u.append(p,f);let m=h("div","persona-flex persona-flex-col persona-gap-3"),C=(W=e==null?void 0:e.layout)==null?void 0:W.contentMaxWidth;C&&(m.style.maxWidth=C,m.style.marginLeft="auto",m.style.marginRight="auto",m.style.width="100%"),((V=e==null?void 0:e.copy)==null?void 0:V.showWelcomeCard)!==!1||(u.style.display="none",l.classList.remove("persona-gap-6"),l.classList.add("persona-gap-3")),l.append(u,m);let k=h("div","persona-composer-overlay persona-pointer-events-none");k.setAttribute("data-persona-composer-overlay",""),k.style.position="absolute",k.style.left="0",k.style.right="0",k.style.bottom="0",k.style.zIndex="20";let T=oh({config:e}),{root:S,textNode:E}=nh();return t.append(d,o,l,k),i&&t.appendChild(i),{container:t,body:l,messagesWrapper:m,composerOverlay:k,suggestions:T.suggestions,textarea:T.textarea,sendButton:T.sendButton,sendButtonWrapper:T.sendButtonWrapper,micButton:T.micButton,micButtonWrapper:T.micButtonWrapper,composerForm:T.composerForm,statusText:T.statusText,introTitle:p,introSubtitle:f,closeButton:n,closeButtonWrapper:o,clearChatButton:s,clearChatButtonWrapper:i,iconHolder:h("span"),headerTitle:h("span"),headerSubtitle:h("span"),header:d,footer:T.footer,attachmentButton:T.attachmentButton,attachmentButtonWrapper:T.attachmentButtonWrapper,attachmentInput:T.attachmentInput,attachmentPreviewsContainer:T.attachmentPreviewsContainer,actionsRow:T.actionsRow,leftActions:T.leftActions,rightActions:T.rightActions,setSendButtonMode:T.setSendButtonMode,peekBanner:S,peekTextNode:E}},sh=(e,r=!0)=>{var k,T,S,E,v,b,y,M,H;if(So(e))return Hb(e,r);let t=h("div","persona-widget-container persona-flex persona-h-full persona-w-full persona-flex-1 persona-min-h-0 persona-flex-col persona-text-persona-primary persona-bg-persona-surface persona-rounded-2xl persona-overflow-hidden persona-border persona-border-persona-border");t.setAttribute("data-persona-theme-zone","container");let n=(k=e==null?void 0:e.layout)==null?void 0:k.header,o=((T=e==null?void 0:e.layout)==null?void 0:T.showHeader)!==!1,a=n?ka(e,n,{showClose:r}):oo({config:e,showClose:r}),s=h("div","persona-widget-body persona-flex persona-flex-1 persona-min-h-0 persona-flex-col persona-gap-6 persona-overflow-y-auto persona-bg-persona-container persona-px-6 persona-py-6");s.id="persona-scroll-container",s.setAttribute("data-persona-theme-zone","messages");let i=h("div","persona-rounded-2xl persona-bg-persona-surface persona-p-6");i.style.boxShadow=hr(e)?"none":"var(--persona-intro-card-shadow, 0 5px 15px rgba(15, 23, 42, 0.08))";let d=h("h2","persona-text-lg persona-font-semibold persona-text-persona-primary");d.textContent=(E=(S=e==null?void 0:e.copy)==null?void 0:S.welcomeTitle)!=null?E:"Hello \u{1F44B}";let l=h("p","persona-mt-2 persona-text-sm persona-text-persona-muted");l.textContent=(b=(v=e==null?void 0:e.copy)==null?void 0:v.welcomeSubtitle)!=null?b:"Ask anything about your account or products.",i.append(d,l);let u=h("div","persona-flex persona-flex-col persona-gap-3"),p=(y=e==null?void 0:e.layout)==null?void 0:y.contentMaxWidth;p&&(u.style.maxWidth=p,u.style.marginLeft="auto",u.style.marginRight="auto",u.style.width="100%"),i.setAttribute("data-persona-intro-card",""),((M=e==null?void 0:e.copy)==null?void 0:M.showWelcomeCard)!==!1||(i.style.display="none",s.classList.remove("persona-gap-6"),s.classList.add("persona-gap-3")),s.append(i,u);let m=Ea({config:e}),C=((H=e==null?void 0:e.layout)==null?void 0:H.showFooter)!==!1;o?na(t,a,e):(a.header.style.display="none",na(t,a,e)),t.append(s);let w=h("div","persona-composer-overlay persona-pointer-events-none");return w.setAttribute("data-persona-composer-overlay",""),w.style.position="absolute",w.style.left="0",w.style.right="0",w.style.bottom="0",w.style.zIndex="20",C||(m.footer.style.display="none"),t.append(m.footer),t.append(w),{container:t,body:s,messagesWrapper:u,composerOverlay:w,suggestions:m.suggestions,textarea:m.textarea,sendButton:m.sendButton,sendButtonWrapper:m.sendButtonWrapper,micButton:m.micButton,micButtonWrapper:m.micButtonWrapper,composerForm:m.composerForm,statusText:m.statusText,introTitle:d,introSubtitle:l,closeButton:a.closeButton,closeButtonWrapper:a.closeButtonWrapper,clearChatButton:a.clearChatButton,clearChatButtonWrapper:a.clearChatButtonWrapper,iconHolder:a.iconHolder,headerTitle:a.headerTitle,headerSubtitle:a.headerSubtitle,header:a.header,footer:m.footer,attachmentButton:m.attachmentButton,attachmentButtonWrapper:m.attachmentButtonWrapper,attachmentInput:m.attachmentInput,attachmentPreviewsContainer:m.attachmentPreviewsContainer,actionsRow:m.actionsRow,leftActions:m.leftActions,rightActions:m.rightActions,setSendButtonMode:m.setSendButtonMode}};var Bb=e=>{switch(e){case"max_tool_calls":return"Stopped after calling a tool. Send a follow-up to continue.";case"length":return"Response cut off as max tokens reached. Ask for more to continue.";case"content_filter":return"The provider filtered this response.";case"error":return"Something went wrong generating this response.";default:return null}},Wb=(e,r)=>{if(!e)return null;let t=Bb(e);if(t===null)return null;let n=r==null?void 0:r[e],o=n!==void 0?n:t;return o||null},Db=(e,r)=>{let t=h("div","persona-message-stop-reason persona-text-xs persona-mt-2 persona-italic");return t.setAttribute("data-stop-reason",e),t.setAttribute("role","note"),t.style.opacity="0.75",t.textContent=r,t},Ob=e=>{let r=e.toLowerCase();return r.startsWith("data:image/svg+xml")?!1:!!(/^(?:https?|blob):/i.test(e)||r.startsWith("data:image/")||!e.includes(":"))},up=e=>{let r=e.toLowerCase();return r.startsWith("javascript:")||r.startsWith("data:text/html")||r.startsWith("data:text/javascript")||r.startsWith("data:text/xml")||r.startsWith("data:application/xhtml")||r.startsWith("data:image/svg+xml")?!1:!!(/^(?:https?|blob):/i.test(e)||r.startsWith("data:")||!e.includes(":"))},fp=320,lh=320,Fb=e=>!e.contentParts||e.contentParts.length===0?[]:e.contentParts.filter(r=>r.type==="image"&&typeof r.image=="string"&&r.image.trim().length>0),Nb=e=>!e.contentParts||e.contentParts.length===0?[]:e.contentParts.filter(r=>r.type==="audio"&&typeof r.audio=="string"&&r.audio.trim().length>0),_b=e=>!e.contentParts||e.contentParts.length===0?[]:e.contentParts.filter(r=>r.type==="video"&&typeof r.video=="string"&&r.video.trim().length>0),$b=e=>!e.contentParts||e.contentParts.length===0?[]:e.contentParts.filter(r=>r.type==="file"&&typeof r.data=="string"&&r.data.trim().length>0),Ub=(e,r,t)=>{if(e.length===0)return null;try{let n=h("div","persona-flex persona-flex-col persona-gap-2");n.setAttribute("data-message-attachments","images"),r&&(n.style.marginBottom="8px");let o=0,a=!1,s=()=>{a||(a=!0,n.remove(),t==null||t())};return e.forEach((i,d)=>{var p;let l=h("img");l.alt=((p=i.alt)==null?void 0:p.trim())||`Attached image ${d+1}`,l.loading="lazy",l.decoding="async",l.referrerPolicy="no-referrer",l.style.display="block",l.style.width="100%",l.style.maxWidth=`${fp}px`,l.style.maxHeight=`${lh}px`,l.style.height="auto",l.style.objectFit="contain",l.style.borderRadius="10px",l.style.backgroundColor="var(--persona-attachment-image-bg, var(--persona-container, #f3f4f6))",l.style.border="1px solid var(--persona-attachment-image-border, var(--persona-border, #e5e7eb))";let u=!1;o+=1,l.addEventListener("error",()=>{u||(u=!0,o=Math.max(0,o-1),l.remove(),o===0&&s())}),l.addEventListener("load",()=>{u=!0}),Ob(i.image)?(l.src=i.image,n.appendChild(l)):(u=!0,o=Math.max(0,o-1),l.remove())}),o===0?(s(),null):n}catch{return t==null||t(),null}},qb=e=>{if(e.length===0)return null;try{let r=h("div","persona-flex persona-flex-col persona-gap-2");r.setAttribute("data-message-attachments","audio");let t=0;return e.forEach(n=>{if(!up(n.audio))return;let o=h("audio");o.controls=!0,o.preload="metadata",o.src=n.audio,o.style.display="block",o.style.width="100%",o.style.maxWidth=`${fp}px`,r.appendChild(o),t+=1}),t===0?(r.remove(),null):r}catch{return null}},zb=e=>{if(e.length===0)return null;try{let r=h("div","persona-flex persona-flex-col persona-gap-2");r.setAttribute("data-message-attachments","video");let t=0;return e.forEach(n=>{if(!up(n.video))return;let o=h("video");o.controls=!0,o.preload="metadata",o.src=n.video,o.style.display="block",o.style.width="100%",o.style.maxWidth=`${fp}px`,o.style.maxHeight=`${lh}px`,o.style.borderRadius="10px",o.style.backgroundColor="var(--persona-attachment-image-bg, var(--persona-container, #f3f4f6))",r.appendChild(o),t+=1}),t===0?(r.remove(),null):r}catch{return null}},Vb=e=>{if(e.length===0)return null;try{let r=h("div","persona-flex persona-flex-col persona-gap-2");r.setAttribute("data-message-attachments","files");let t=0;return e.forEach(n=>{if(!up(n.data))return;let o=h("a");o.href=n.data,o.download=n.filename,o.target="_blank",o.rel="noopener noreferrer",o.textContent=n.filename,o.className="persona-message-file-attachment",o.style.display="inline-flex",o.style.alignItems="center",o.style.gap="6px",o.style.padding="6px 10px",o.style.borderRadius="8px",o.style.fontSize="0.875rem",o.style.textDecoration="underline",o.style.backgroundColor="var(--persona-attachment-file-bg, var(--persona-container, #f3f4f6))",o.style.border="1px solid var(--persona-attachment-file-border, var(--persona-border, #e5e7eb))",o.style.color="inherit",r.appendChild(o),t+=1}),t===0?(r.remove(),null):r}catch{return null}},oa=()=>{let e=document.createElement("div");e.className="persona-flex persona-items-center persona-space-x-1 persona-h-5 persona-mt-2";let r=document.createElement("div");r.className="persona-animate-typing persona-rounded-full persona-h-1.5 persona-w-1.5",r.style.backgroundColor="currentColor",r.style.opacity="0.4",r.style.animationDelay="0ms";let t=document.createElement("div");t.className="persona-animate-typing persona-rounded-full persona-h-1.5 persona-w-1.5",t.style.backgroundColor="currentColor",t.style.opacity="0.4",t.style.animationDelay="250ms";let n=document.createElement("div");n.className="persona-animate-typing persona-rounded-full persona-h-1.5 persona-w-1.5",n.style.backgroundColor="currentColor",n.style.opacity="0.4",n.style.animationDelay="500ms";let o=document.createElement("span");return o.className="persona-sr-only",o.textContent="Loading",e.appendChild(r),e.appendChild(t),e.appendChild(n),e.appendChild(o),e},mp=(e,r,t)=>{let n={config:t!=null?t:{},streaming:!0,location:e,defaultRenderer:oa};if(r){let o=r(n);if(o!==null)return o}return oa()},jb=(e,r)=>{let t=h("div","persona-flex-shrink-0 persona-w-8 persona-h-8 persona-rounded-full persona-flex persona-items-center persona-justify-center persona-text-sm"),n=r==="user"?e.userAvatar:e.assistantAvatar;if(n)if(n.startsWith("http")||n.startsWith("/")||n.startsWith("data:")){let o=h("img");o.src=n,o.alt=r==="user"?"User":"Assistant",o.className="persona-w-full persona-h-full persona-rounded-full persona-object-cover",t.appendChild(o)}else t.textContent=n,t.classList.add(r==="user"?"persona-bg-persona-accent":"persona-bg-persona-primary","persona-text-white");else t.textContent=r==="user"?"U":"A",t.classList.add(r==="user"?"persona-bg-persona-accent":"persona-bg-persona-primary","persona-text-white");return t},ih=(e,r)=>{let t=h("div","persona-text-xs persona-text-persona-muted"),n=new Date(e.createdAt);return r.format?t.textContent=r.format(n):t.textContent=n.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),t},Gb=(e,r="bubble")=>{let t=["persona-message-bubble","persona-max-w-[85%]"];switch(r){case"flat":e==="user"?t.push("persona-message-user-bubble","persona-ml-auto","persona-text-persona-primary","persona-py-2"):t.push("persona-message-assistant-bubble","persona-text-persona-primary","persona-py-2");break;case"minimal":t.push("persona-text-sm","persona-leading-relaxed"),e==="user"?t.push("persona-message-user-bubble","persona-ml-auto","persona-bg-persona-accent","persona-text-white","persona-px-3","persona-py-2","persona-rounded-lg"):t.push("persona-message-assistant-bubble","persona-bg-persona-surface","persona-text-persona-primary","persona-px-3","persona-py-2","persona-rounded-lg");break;default:t.push("persona-rounded-2xl","persona-text-sm","persona-leading-relaxed","persona-shadow-sm"),e==="user"?t.push("persona-message-user-bubble","persona-ml-auto","persona-bg-persona-accent","persona-text-white","persona-px-5","persona-py-3"):t.push("persona-message-assistant-bubble","persona-bg-persona-surface","persona-border","persona-border-persona-message-border","persona-text-persona-primary","persona-px-5","persona-py-3");break}return t},gp=(e,r,t)=>{var m,C,w,k,T,S;let n=(m=r.showCopy)!=null?m:!0,o=(C=r.showUpvote)!=null?C:!0,a=(w=r.showDownvote)!=null?w:!0;if(!n&&!o&&!a){let E=h("div");return E.style.display="none",E.id=`actions-${e.id}`,E.setAttribute("data-actions-for",e.id),E}let s=(k=r.visibility)!=null?k:"hover",i=(T=r.align)!=null?T:"right",d=(S=r.layout)!=null?S:"pill-inside",l={left:"persona-message-actions-left",center:"persona-message-actions-center",right:"persona-message-actions-right"}[i],u={"pill-inside":"persona-message-actions-pill","row-inside":"persona-message-actions-row"}[d],p=h("div",`persona-message-actions persona-flex persona-items-center persona-gap-1 persona-mt-2 ${l} ${u} ${s==="hover"?"persona-message-actions-hover":""}`);p.id=`actions-${e.id}`,p.setAttribute("data-actions-for",e.id);let f=(E,v,b)=>{let y=Zt({icon:E,label:v,size:14,className:"persona-message-action-btn"});return y.setAttribute("data-action",b),y};return n&&p.appendChild(f("copy","Copy message","copy")),o&&p.appendChild(f("thumbs-up","Upvote","upvote")),a&&p.appendChild(f("thumbs-down","Downvote","downvote")),p},Ma=(e,r,t,n,o,a)=>{var Y,Ee,G,ce,de,pe,He,Ye,J,ie,Ue,K,j,Ce,De,oe,Se;let s=t!=null?t:{},i=(Y=s.layout)!=null?Y:"bubble",d=s.avatar,l=s.timestamp,u=(Ee=d==null?void 0:d.show)!=null?Ee:!1,p=(G=l==null?void 0:l.show)!=null?G:!1,f=(ce=d==null?void 0:d.position)!=null?ce:"left",m=(de=l==null?void 0:l.position)!=null?de:"below",C=Gb(e.role,i),w=h("div",C.join(" "));w.id=`bubble-${e.id}`,w.setAttribute("data-message-id",e.id),w.setAttribute("data-persona-theme-zone",e.role==="user"?"user-message":"assistant-message"),e.role==="user"?(w.style.backgroundColor="var(--persona-message-user-bg, var(--persona-accent))",w.style.color="var(--persona-message-user-text, white)"):e.role==="assistant"&&(w.style.backgroundColor="var(--persona-message-assistant-bg, var(--persona-surface))",w.style.color="var(--persona-message-assistant-text, var(--persona-text))");let k=Fb(e),T=(He=(pe=e.content)==null?void 0:pe.trim())!=null?He:"",E=k.length>0&&T===Ei,v=Qi((J=(Ye=a==null?void 0:a.widgetConfig)==null?void 0:Ye.features)==null?void 0:J.streamAnimation),b=(K=(Ue=(ie=a==null?void 0:a.widgetConfig)==null?void 0:ie.features)==null?void 0:Ue.streamAnimation)==null?void 0:K.plugins,y=e.role==="assistant"&&v.type!=="none"?Ts(v.type,b):null,M=e.role==="assistant"&&((j=y==null?void 0:y.isAnimating)==null?void 0:j.call(y,e))===!0,H=e.role==="assistant"&&y!==null&&(!!e.streaming||M);H&&(y!=null&&y.bubbleClass)&&w.classList.add(y.bubbleClass);let B=document.createElement("div");B.classList.add("persona-message-content"),H&&y&&(y.containerClass&&B.classList.add(y.containerClass),B.style.setProperty("--persona-stream-step",`${v.speed}ms`),B.style.setProperty("--persona-stream-duration",`${v.duration}ms`));let R=H?Zi((Ce=e.content)!=null?Ce:"",v.buffer,y,e,!!e.streaming):(De=e.content)!=null?De:"",W=r({text:R,message:e,streaming:!!e.streaming,raw:e.rawContent}),V=W;H&&(y==null?void 0:y.wrap)==="char"?V=ks(W,"char",e.id,{skipTags:y.skipTags}):H&&(y==null?void 0:y.wrap)==="word"&&(V=ks(W,"word",e.id,{skipTags:y.skipTags}));let ne=null;if(E?(ne=document.createElement("div"),ne.innerHTML=V,ne.style.display="none",B.appendChild(ne)):B.innerHTML=V,H&&(y!=null&&y.useCaret)&&!E&&T){let ge=el(),Rt=B.querySelectorAll(".persona-stream-char, .persona-stream-word"),Me=Rt[Rt.length-1];if(Me!=null&&Me.parentNode)Me.parentNode.insertBefore(ge,Me.nextSibling);else{let ae=B.lastElementChild;ae?ae.appendChild(ge):B.appendChild(ge)}}if(p&&m==="inline"&&e.createdAt){let ge=ih(e,l);ge.classList.add("persona-ml-2","persona-inline"),B.appendChild(ge)}if(k.length>0){let ge=Ub(k,!E&&!!T,()=>{E&&ne&&(ne.style.display="")});ge?w.appendChild(ge):E&&ne&&(ne.style.display="")}let ue=Nb(e);if(ue.length>0){let ge=qb(ue);ge&&w.appendChild(ge)}let We=_b(e);if(We.length>0){let ge=zb(We);ge&&w.appendChild(ge)}let Ke=$b(e);if(Ke.length>0){let ge=Vb(Ke);ge&&w.appendChild(ge)}if(w.appendChild(B),p&&m==="below"&&e.createdAt){let ge=ih(e,l);ge.classList.add("persona-mt-1"),w.appendChild(ge)}let xe=e.role==="assistant"?Wb(e.stopReason,(Se=(oe=a==null?void 0:a.widgetConfig)==null?void 0:oe.copy)==null?void 0:Se.stopReasonNotice):null;if(e.streaming&&e.role==="assistant"){let ge=!!(R&&R.trim()),Rt=v.placeholder==="skeleton",Me=Rt&&v.buffer==="line"&≥if(ge)Me&&w.appendChild(Es());else if(Rt)w.appendChild(Es());else{let ae=mp("inline",a==null?void 0:a.loadingIndicatorRenderer,a==null?void 0:a.widgetConfig);ae&&w.appendChild(ae)}}if(xe&&e.stopReason&&!e.streaming&&(T||(B.style.display="none"),w.appendChild(Db(e.stopReason,xe))),e.role==="assistant"&&!e.streaming&&e.content&&e.content.trim()&&(n==null?void 0:n.enabled)!==!1&&n){let ge=gp(e,n,o);w.appendChild(ge)}if(!u||e.role==="system")return w;let Re=h("div",`persona-flex persona-gap-2 ${e.role==="user"?"persona-flex-row-reverse":""}`),Ge=jb(d,e.role);return f==="right"||f==="left"&&e.role==="user"?Re.append(w,Ge):Re.append(Ge,w),w.classList.remove("persona-max-w-[85%]"),w.classList.add("persona-max-w-[calc(85%-2.5rem)]"),Re},dh=(e,r,t,n,o,a)=>{let s=t!=null?t:{};return e.role==="user"&&s.renderUserMessage?s.renderUserMessage({message:e,config:{},streaming:!!e.streaming}):e.role==="assistant"&&s.renderAssistantMessage?s.renderAssistantMessage({message:e,config:{},streaming:!!e.streaming}):Ma(e,r,t,n,o,a)};var La=new Set,Xb=(e,r)=>r==null?!1:typeof r=="string"?(e.textContent=r,!0):(e.appendChild(r),!0),Jb=(e,r)=>{var n,o;let t=(o=(n=e.reasoning)==null?void 0:n.chunks.join("").trim())!=null?o:"";return t?t.split(/\r?\n/).map(a=>a.trim()).filter(Boolean).slice(0,r).join(`
|
|
64
|
-
`):""},ch=(e,r)=>{let t=La.has(e),n=r.querySelector('button[data-expand-header="true"]'),o=r.querySelector(".persona-border-t"),a=r.querySelector('[data-persona-collapsed-preview="reasoning"]');if(!n||!o)return;n.setAttribute("aria-expanded",t?"true":"false");let s=n.querySelector(".persona-ml-auto"),i=s==null?void 0:s.querySelector(":scope > .persona-flex.persona-items-center");if(i){i.innerHTML="";let l=ve(t?"chevron-up":"chevron-down",16,"currentColor",2);l?i.appendChild(l):i.textContent=t?"Hide":"Show"}o.style.display=t?"":"none",a&&(a.style.display=t?"none":a.textContent||a.childNodes.length?"":"none")},hp=(e,r)=>{var
|
|
63
|
+
`,t.addEventListener("click",r);let n=a=>{var E,w,b,y,M,H,B,R,W,V,ne,ue,Be,Ke;let s=(E=a.launcher)!=null?E:{},i=hr(a),d=t.querySelector("[data-role='launcher-title']");if(d){let ye=(w=s.title)!=null?w:"Chat Assistant";d.textContent=ye,d.setAttribute("title",ye)}let l=t.querySelector("[data-role='launcher-subtitle']");if(l){let ye=(b=s.subtitle)!=null?b:"Get answers fast";l.textContent=ye,l.setAttribute("title",ye)}let u=t.querySelector(".persona-flex-col");u&&(s.textHidden||i?u.style.display="none":u.style.display="");let p=t.querySelector("[data-role='launcher-icon']");if(p)if(s.agentIconHidden)p.style.display="none";else{let ye=(y=s.agentIconSize)!=null?y:"40px";if(p.style.height=ye,p.style.width=ye,p.innerHTML="",s.agentIconName){let me=parseFloat(ye)||24,We=ve(s.agentIconName,me*.6,"var(--persona-text-inverse, #ffffff)",2);We?(p.appendChild(We),p.style.display=""):(p.textContent=(M=s.agentIconText)!=null?M:"\u{1F4AC}",p.style.display="")}else s.iconUrl?p.style.display="none":(p.textContent=(H=s.agentIconText)!=null?H:"\u{1F4AC}",p.style.display="")}let f=t.querySelector("[data-role='launcher-image']");if(f){let ye=(B=s.agentIconSize)!=null?B:"40px";f.style.height=ye,f.style.width=ye,s.iconUrl&&!s.agentIconName&&!s.agentIconHidden?(f.src=s.iconUrl,f.style.display="block"):f.style.display="none"}let m=t.querySelector("[data-role='launcher-call-to-action-icon']");if(m){let ye=(R=s.callToActionIconSize)!=null?R:"32px";m.style.height=ye,m.style.width=ye,s.callToActionIconBackgroundColor?(m.style.backgroundColor=s.callToActionIconBackgroundColor,m.classList.remove("persona-bg-persona-primary")):(m.style.backgroundColor="",m.classList.add("persona-bg-persona-primary")),s.callToActionIconColor?(m.style.color=s.callToActionIconColor,m.classList.remove("persona-text-persona-call-to-action")):(m.style.color="",m.classList.add("persona-text-persona-call-to-action"));let me=0;if(s.callToActionIconPadding?(m.style.boxSizing="border-box",m.style.padding=s.callToActionIconPadding,me=(parseFloat(s.callToActionIconPadding)||0)*2):(m.style.boxSizing="",m.style.padding=""),s.callToActionIconHidden)m.style.display="none";else if(m.style.display=i?"none":"",m.innerHTML="",s.callToActionIconName){let We=parseFloat(ye)||24,Xe=Math.max(We-me,8),Y=ve(s.callToActionIconName,Xe,"currentColor",2);Y?m.appendChild(Y):m.textContent=(W=s.callToActionIconText)!=null?W:"\u2197"}else m.textContent=(V=s.callToActionIconText)!=null?V:"\u2197"}let C=s.position&&On[s.position]?On[s.position]:On["bottom-right"],A="persona-fixed persona-flex persona-items-center persona-gap-3 persona-rounded-launcher persona-bg-persona-surface persona-py-2.5 persona-pl-3 persona-pr-3 persona-transition hover:persona-translate-y-[-2px] persona-cursor-pointer",k="persona-relative persona-mt-4 persona-mb-4 persona-mx-auto persona-flex persona-items-center persona-justify-center persona-rounded-launcher persona-bg-persona-surface persona-transition hover:persona-translate-y-[-2px] persona-cursor-pointer";t.className=i?k:`${A} ${C}`,i||(t.style.zIndex=String((ne=s.zIndex)!=null?ne:Dr));let T="1px solid var(--persona-border, #e5e7eb)",S="var(--persona-shadow, 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1))";t.style.border=(ue=s.border)!=null?ue:T,t.style.boxShadow=(Be=s.shadow)!=null?Be:S,i?(t.style.width="0",t.style.minWidth="0",t.style.maxWidth="0",t.style.padding="0",t.style.overflow="hidden",t.style.border="none",t.style.boxShadow="none"):(t.style.width="",t.style.minWidth="",t.style.maxWidth=(Ke=s.collapsedMaxWidth)!=null?Ke:"",t.style.justifyContent="",t.style.padding="",t.style.overflow="")},o=()=>{t.removeEventListener("click",r),t.remove()};return e&&n(e),{element:t,update:n,destroy:o}};var Pb="persona-relative persona-ml-auto persona-inline-flex persona-items-center persona-justify-center",rl=(e,r={})=>{var A,k,T,S,E,w;let{showClose:t=!0,wrapperClassName:n=Pb,buttonSize:o,iconSize:a="28px"}=r,s=(A=e==null?void 0:e.launcher)!=null?A:{},i=(k=o!=null?o:s.closeButtonSize)!=null?k:"32px",d=h("div",n),l=h("button","persona-inline-flex persona-items-center persona-justify-center persona-rounded-full hover:persona-bg-gray-100 persona-cursor-pointer persona-border-none");l.style.height=i,l.style.width=i,l.type="button";let u=(T=s.closeButtonTooltipText)!=null?T:"Close chat",p=(S=s.closeButtonShowTooltip)!=null?S:!0;l.setAttribute("aria-label",u),l.style.display=t?"":"none";let f=(E=s.closeButtonIconName)!=null?E:"x",m=(w=s.closeButtonIconText)!=null?w:"\xD7";l.style.color=s.closeButtonColor||Jr.actionIconColor;let C=ve(f,a,"currentColor",1);if(C?(C.style.display="block",l.appendChild(C)):l.textContent=m,s.closeButtonBackgroundColor?(l.style.backgroundColor=s.closeButtonBackgroundColor,l.classList.remove("hover:persona-bg-gray-100")):(l.style.backgroundColor="",l.classList.add("hover:persona-bg-gray-100")),s.closeButtonBorderWidth||s.closeButtonBorderColor){let b=s.closeButtonBorderWidth||"0px",y=s.closeButtonBorderColor||"transparent";l.style.border=`${b} solid ${y}`,l.classList.remove("persona-border-none")}else l.style.border="",l.classList.add("persona-border-none");if(s.closeButtonBorderRadius?(l.style.borderRadius=s.closeButtonBorderRadius,l.classList.remove("persona-rounded-full")):(l.style.borderRadius="",l.classList.add("persona-rounded-full")),s.closeButtonPaddingX?(l.style.paddingLeft=s.closeButtonPaddingX,l.style.paddingRight=s.closeButtonPaddingX):(l.style.paddingLeft="",l.style.paddingRight=""),s.closeButtonPaddingY?(l.style.paddingTop=s.closeButtonPaddingY,l.style.paddingBottom=s.closeButtonPaddingY):(l.style.paddingTop="",l.style.paddingBottom=""),d.appendChild(l),p&&u){let b=null,y=()=>{if(b)return;let H=l.ownerDocument,B=H.body;if(!B)return;b=qn(H,"div","persona-clear-chat-tooltip"),b.textContent=u;let R=qn(H,"div");R.className="persona-clear-chat-tooltip-arrow",b.appendChild(R);let W=l.getBoundingClientRect();b.style.position="fixed",b.style.zIndex=String(vo),b.style.left=`${W.left+W.width/2}px`,b.style.top=`${W.top-8}px`,b.style.transform="translate(-50%, -100%)",B.appendChild(b)},M=()=>{b&&b.parentNode&&(b.parentNode.removeChild(b),b=null)};d.addEventListener("mouseenter",y),d.addEventListener("mouseleave",M),l.addEventListener("focus",y),l.addEventListener("blur",M),d._cleanupTooltip=()=>{M(),d.removeEventListener("mouseenter",y),d.removeEventListener("mouseleave",M),l.removeEventListener("focus",y),l.removeEventListener("blur",M)}}return{button:l,wrapper:d}},Ib="persona-relative persona-ml-auto persona-clear-chat-button-wrapper",nl=(e,r={})=>{var b,y,M,H,B,R,W,V,ne,ue,Be,Ke,ye;let{wrapperClassName:t=Ib,buttonSize:n,iconSize:o="20px"}=r,s=(y=((b=e==null?void 0:e.launcher)!=null?b:{}).clearChat)!=null?y:{},i=(M=n!=null?n:s.size)!=null?M:"32px",d=(H=s.iconName)!=null?H:"refresh-cw",l=(B=s.iconColor)!=null?B:"",u=(R=s.backgroundColor)!=null?R:"",p=(W=s.borderWidth)!=null?W:"",f=(V=s.borderColor)!=null?V:"",m=(ne=s.borderRadius)!=null?ne:"",C=(ue=s.paddingX)!=null?ue:"",A=(Be=s.paddingY)!=null?Be:"",k=(Ke=s.tooltipText)!=null?Ke:"Clear chat",T=(ye=s.showTooltip)!=null?ye:!0,S=h("div",t),E=h("button","persona-inline-flex persona-items-center persona-justify-center persona-rounded-full hover:persona-bg-gray-100 persona-cursor-pointer persona-border-none");E.style.height=i,E.style.width=i,E.type="button",E.setAttribute("aria-label",k),E.style.color=l||Jr.actionIconColor;let w=ve(d,o,"currentColor",1);if(w&&(w.style.display="block",E.appendChild(w)),u&&(E.style.backgroundColor=u,E.classList.remove("hover:persona-bg-gray-100")),p||f){let me=p||"0px",We=f||"transparent";E.style.border=`${me} solid ${We}`,E.classList.remove("persona-border-none")}if(m&&(E.style.borderRadius=m,E.classList.remove("persona-rounded-full")),C&&(E.style.paddingLeft=C,E.style.paddingRight=C),A&&(E.style.paddingTop=A,E.style.paddingBottom=A),S.appendChild(E),T&&k){let me=null,We=()=>{if(me)return;let Y=E.ownerDocument,Ee=Y.body;if(!Ee)return;me=qn(Y,"div","persona-clear-chat-tooltip"),me.textContent=k;let G=qn(Y,"div");G.className="persona-clear-chat-tooltip-arrow",me.appendChild(G);let ce=E.getBoundingClientRect();me.style.position="fixed",me.style.zIndex=String(vo),me.style.left=`${ce.left+ce.width/2}px`,me.style.top=`${ce.top-8}px`,me.style.transform="translate(-50%, -100%)",Ee.appendChild(me)},Xe=()=>{me&&me.parentNode&&(me.parentNode.removeChild(me),me=null)};S.addEventListener("mouseenter",We),S.addEventListener("mouseleave",Xe),E.addEventListener("focus",We),E.addEventListener("blur",Xe),S._cleanupTooltip=()=>{Xe(),S.removeEventListener("mouseenter",We),S.removeEventListener("mouseleave",Xe),E.removeEventListener("focus",We),E.removeEventListener("blur",Xe)}}return{button:E,wrapper:S}};var Jr={titleColor:"var(--persona-header-title-fg, var(--persona-primary, #0f0f0f))",subtitleColor:"var(--persona-header-subtitle-fg, var(--persona-text-muted, var(--persona-muted, #9ca3af)))",actionIconColor:"var(--persona-header-action-icon-fg, var(--persona-muted, #9ca3af))"},oo=e=>{var b,y,M,H,B,R,W,V,ne,ue,Be,Ke,ye,me,We,Xe;let{config:r,showClose:t=!0}=e,n=h("div","persona-widget-header persona-flex persona-items-center persona-gap-3 persona-px-6 persona-py-5");n.setAttribute("data-persona-theme-zone","header"),n.style.backgroundColor="var(--persona-header-bg, var(--persona-surface, #ffffff))",n.style.borderBottomColor="var(--persona-header-border, var(--persona-divider, #f1f5f9))",n.style.boxShadow="var(--persona-header-shadow, none)",n.style.borderBottom="var(--persona-header-border-bottom, 1px solid var(--persona-header-border, var(--persona-divider, #f1f5f9)))";let o=(b=r==null?void 0:r.launcher)!=null?b:{},a=(y=o.headerIconSize)!=null?y:"48px",s=(M=o.closeButtonPlacement)!=null?M:"inline",i=(H=o.headerIconHidden)!=null?H:!1,d=o.headerIconName,l=h("div","persona-flex persona-items-center persona-justify-center persona-rounded-xl persona-text-xl");if(l.style.height=a,l.style.width=a,l.style.backgroundColor="var(--persona-header-icon-bg, var(--persona-primary, #0f0f0f))",l.style.color="var(--persona-header-icon-fg, var(--persona-text-inverse, #ffffff))",!i)if(d){let Y=parseFloat(a)||24,Ee=ve(d,Y*.6,"currentColor",1);Ee?l.replaceChildren(Ee):l.textContent=(R=(B=r==null?void 0:r.launcher)==null?void 0:B.agentIconText)!=null?R:"\u{1F4AC}"}else if((W=r==null?void 0:r.launcher)!=null&&W.iconUrl){let Y=h("img");Y.src=r.launcher.iconUrl,Y.alt="",Y.className="persona-rounded-xl persona-object-cover",Y.style.height=a,Y.style.width=a,l.replaceChildren(Y)}else l.textContent=(ne=(V=r==null?void 0:r.launcher)==null?void 0:V.agentIconText)!=null?ne:"\u{1F4AC}";let u=h("div","persona-flex persona-flex-col persona-flex-1 persona-min-w-0"),p=h("span","persona-text-base persona-font-semibold");p.style.color=Jr.titleColor,p.textContent=(Be=(ue=r==null?void 0:r.launcher)==null?void 0:ue.title)!=null?Be:"Chat Assistant";let f=h("span","persona-text-xs");f.style.color=Jr.subtitleColor,f.textContent=(ye=(Ke=r==null?void 0:r.launcher)==null?void 0:Ke.subtitle)!=null?ye:"Here to help you get answers fast",u.append(p,f),i?n.append(u):n.append(l,u);let m=(me=o.clearChat)!=null?me:{},C=(We=m.enabled)!=null?We:!0,A=(Xe=m.placement)!=null?Xe:"inline",k=null,T=null;if(C){let Ee=nl(r,{wrapperClassName:A==="top-right"?"persona-absolute persona-top-4 persona-z-50":"persona-relative persona-ml-auto persona-clear-chat-button-wrapper"});k=Ee.button,T=Ee.wrapper,A==="top-right"&&(T.style.right="48px"),A==="inline"&&n.appendChild(T)}let S=s==="top-right"?"persona-absolute persona-top-4 persona-right-4 persona-z-50":C&&A==="inline"?"persona-relative persona-inline-flex persona-items-center persona-justify-center":"persona-relative persona-ml-auto persona-inline-flex persona-items-center persona-justify-center",{button:E,wrapper:w}=rl(r,{showClose:t,wrapperClassName:S});return s!=="top-right"&&n.appendChild(w),{header:n,iconHolder:l,headerTitle:p,headerSubtitle:f,closeButton:E,closeButtonWrapper:w,clearChatButton:k,clearChatButtonWrapper:T}},na=(e,r,t)=>{var s,i,d,l;let n=(s=t==null?void 0:t.launcher)!=null?s:{},o=(i=n.closeButtonPlacement)!=null?i:"inline",a=(l=(d=n.clearChat)==null?void 0:d.placement)!=null?l:"inline";e.appendChild(r.header),o==="top-right"&&(e.style.position="relative",e.appendChild(r.closeButtonWrapper)),r.clearChatButtonWrapper&&a==="top-right"&&(e.style.position="relative",e.appendChild(r.clearChatButtonWrapper))};function To(e){let{items:r,onSelect:t,anchor:n,position:o="bottom-left",portal:a}=e,s=h("div","persona-dropdown-menu persona-hidden");s.setAttribute("role","menu"),s.setAttribute("data-persona-theme-zone","dropdown"),a?(s.style.position="fixed",s.style.zIndex=String(vo)):(s.style.position="absolute",s.style.top="100%",s.style.marginTop="4px",o==="bottom-right"?s.style.right="0":s.style.left="0");for(let m of r){if(m.dividerBefore){let k=document.createElement("hr");s.appendChild(k)}let C=document.createElement("button");if(C.type="button",C.setAttribute("role","menuitem"),C.setAttribute("data-dropdown-item-id",m.id),m.destructive&&C.setAttribute("data-destructive",""),m.icon){let k=ve(m.icon,16,"currentColor",1.5);k&&C.appendChild(k)}let A=document.createElement("span");A.textContent=m.label,C.appendChild(A),C.addEventListener("click",k=>{k.stopPropagation(),u(),t(m.id)}),s.appendChild(C)}let i=null;function d(){if(!a)return;let m=n.getBoundingClientRect();s.style.top=`${m.bottom+4}px`,o==="bottom-right"?(s.style.right=`${window.innerWidth-m.right}px`,s.style.left="auto"):(s.style.left=`${m.left}px`,s.style.right="auto")}function l(){d(),s.classList.remove("persona-hidden"),requestAnimationFrame(()=>{let m=C=>{!s.contains(C.target)&&!n.contains(C.target)&&u()};document.addEventListener("click",m,!0),i=()=>document.removeEventListener("click",m,!0)})}function u(){s.classList.add("persona-hidden"),i==null||i(),i=null}function p(){s.classList.contains("persona-hidden")?l():u()}function f(){u(),s.remove()}return a&&a.appendChild(s),{element:s,show:l,hide:u,toggle:p,destroy:f}}function Zt(e){let{icon:r,label:t,size:n,strokeWidth:o,className:a,onClick:s,aria:i}=e,d=h("button","persona-icon-btn"+(a?" "+a:""));d.type="button",d.setAttribute("aria-label",t),d.title=t;let l=ve(r,n!=null?n:16,"currentColor",o!=null?o:2);if(l&&d.appendChild(l),s&&d.addEventListener("click",s),i)for(let[u,p]of Object.entries(i))d.setAttribute(u,p);return d}function Ps(e){let{icon:r,label:t,variant:n="default",size:o="sm",iconSize:a,className:s,onClick:i,aria:d}=e,l="persona-label-btn";n!=="default"&&(l+=" persona-label-btn--"+n),l+=" persona-label-btn--"+o,s&&(l+=" "+s);let u=h("button",l);if(u.type="button",u.setAttribute("aria-label",t),r){let f=ve(r,a!=null?a:14,"currentColor",2);f&&u.appendChild(f)}let p=h("span");if(p.textContent=t,u.appendChild(p),i&&u.addEventListener("click",i),d)for(let[f,m]of Object.entries(d))u.setAttribute(f,m);return u}function Is(e){let{items:r,selectedId:t,onSelect:n,className:o}=e,a=h("div","persona-toggle-group"+(o?" "+o:""));a.setAttribute("role","group");let s=t,i=[];function d(){for(let u of i)u.btn.setAttribute("aria-pressed",u.id===s?"true":"false")}for(let u of r){let p;u.icon?p=Zt({icon:u.icon,label:u.label,onClick:()=>{s=u.id,d(),n(u.id)}}):(p=h("button","persona-icon-btn"),p.type="button",p.setAttribute("aria-label",u.label),p.title=u.label,p.textContent=u.label,p.addEventListener("click",()=>{s=u.id,d(),n(u.id)})),p.setAttribute("aria-pressed",u.id===s?"true":"false"),i.push({id:u.id,btn:p}),a.appendChild(p)}function l(u){s=u,d()}return{element:a,setSelected:l}}function ol(e){var m,C;let{label:r,icon:t="chevron-down",menuItems:n,onSelect:o,position:a="bottom-left",portal:s,className:i,hover:d}=e,l=h("div","persona-combo-btn"+(i?" "+i:""));l.style.position="relative",l.style.display="inline-flex",l.style.alignItems="center",l.style.cursor="pointer",l.setAttribute("role","button"),l.setAttribute("tabindex","0"),l.setAttribute("aria-haspopup","true"),l.setAttribute("aria-expanded","false"),l.setAttribute("aria-label",r);let u=h("span","persona-combo-btn-label");u.textContent=r,l.appendChild(u);let p=ve(t,14,"currentColor",2);p&&(p.style.marginLeft="4px",p.style.opacity="0.6",l.appendChild(p)),d&&(l.style.borderRadius=(m=d.borderRadius)!=null?m:"10px",l.style.padding=(C=d.padding)!=null?C:"6px 4px 6px 12px",l.style.border="1px solid transparent",l.style.transition="background-color 0.15s ease, border-color 0.15s ease",l.addEventListener("mouseenter",()=>{var A,k;l.style.backgroundColor=(A=d.background)!=null?A:"",l.style.borderColor=(k=d.border)!=null?k:""}),l.addEventListener("mouseleave",()=>{l.style.backgroundColor="",l.style.borderColor="transparent"}));let f=To({items:n,onSelect:A=>{l.setAttribute("aria-expanded","false"),o(A)},anchor:l,position:a,portal:s});return s||l.appendChild(f.element),l.addEventListener("click",A=>{A.stopPropagation();let k=!f.element.classList.contains("persona-hidden");l.setAttribute("aria-expanded",k?"false":"true"),f.toggle()}),l.addEventListener("keydown",A=>{(A.key==="Enter"||A.key===" ")&&(A.preventDefault(),l.click())}),{element:l,setLabel:A=>{u.textContent=A,l.setAttribute("aria-label",A)},open:()=>{l.setAttribute("aria-expanded","true"),f.show()},close:()=>{l.setAttribute("aria-expanded","false"),f.hide()},toggle:()=>{let A=!f.element.classList.contains("persona-hidden");l.setAttribute("aria-expanded",A?"false":"true"),f.toggle()},destroy:()=>{f.destroy(),l.remove()}}}var dp=e=>{var n;let r=oo({config:e.config,showClose:e.showClose,onClose:e.onClose,onClearChat:e.onClearChat}),t=(n=e.layoutHeaderConfig)==null?void 0:n.onTitleClick;if(t){let o=r.headerTitle.parentElement;o&&(o.style.cursor="pointer",o.setAttribute("role","button"),o.setAttribute("tabindex","0"),o.addEventListener("click",()=>t()),o.addEventListener("keydown",a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),t())}))}return r};function Rb(e,r,t){var n,o,a;if(r!=null&&r.length)for(let s of r){let i=h("button","persona-inline-flex persona-items-center persona-justify-center persona-rounded-md persona-border-none persona-bg-transparent persona-p-0 persona-text-persona-muted hover:persona-opacity-80");if(i.type="button",i.setAttribute("aria-label",(o=(n=s.ariaLabel)!=null?n:s.label)!=null?o:s.id),s.icon){let d=ve(s.icon,14,"currentColor",2);d&&i.appendChild(d)}else s.label&&(i.textContent=s.label);if((a=s.menuItems)!=null&&a.length){let d=h("div","persona-relative");d.appendChild(i);let l=To({items:s.menuItems,onSelect:u=>t==null?void 0:t(u),anchor:d,position:"bottom-left"});d.appendChild(l.element),i.addEventListener("click",u=>{u.stopPropagation(),l.toggle()}),e.appendChild(d)}else i.addEventListener("click",()=>t==null?void 0:t(s.id)),e.appendChild(i)}}var cp=e=>{var S,E,w,b,y,M,H,B,R;let{config:r,showClose:t=!0,onClose:n,layoutHeaderConfig:o,onHeaderAction:a}=e,s=(S=r==null?void 0:r.launcher)!=null?S:{},i=h("div","persona-flex persona-items-center persona-justify-between persona-px-6 persona-py-4");i.setAttribute("data-persona-theme-zone","header"),i.style.backgroundColor="var(--persona-header-bg, var(--persona-surface, #ffffff))",i.style.borderBottomColor="var(--persona-header-border, var(--persona-divider, #f1f5f9))",i.style.boxShadow="var(--persona-header-shadow, none)",i.style.borderBottom="var(--persona-header-border-bottom, 1px solid var(--persona-header-border, var(--persona-divider, #f1f5f9)))";let d=o==null?void 0:o.titleMenu,l,u;if(d)l=ol({label:(E=s.title)!=null?E:"Chat Assistant",menuItems:d.menuItems,onSelect:d.onSelect,hover:d.hover,className:""}).element,l.style.color=Jr.titleColor,u=(w=l.querySelector(".persona-combo-btn-label"))!=null?w:l;else{if(l=h("div","persona-flex persona-min-w-0 persona-flex-1 persona-items-center persona-gap-1"),u=h("span","persona-text-base persona-font-semibold persona-truncate"),u.style.color=Jr.titleColor,u.textContent=(b=s.title)!=null?b:"Chat Assistant",l.appendChild(u),Rb(l,o==null?void 0:o.trailingActions,(y=o==null?void 0:o.onAction)!=null?y:a),o!=null&&o.onTitleClick){l.style.cursor="pointer",l.setAttribute("role","button"),l.setAttribute("tabindex","0");let V=o.onTitleClick;l.addEventListener("click",ne=>{ne.target.closest("button")||V()}),l.addEventListener("keydown",ne=>{(ne.key==="Enter"||ne.key===" ")&&(ne.preventDefault(),V())})}let W=o==null?void 0:o.titleRowHover;W&&(l.style.borderRadius=(M=W.borderRadius)!=null?M:"10px",l.style.padding=(H=W.padding)!=null?H:"6px 4px 6px 12px",l.style.margin="-6px 0 -6px -12px",l.style.border="1px solid transparent",l.style.transition="background-color 0.15s ease, border-color 0.15s ease",l.style.width="fit-content",l.style.flex="none",l.addEventListener("mouseenter",()=>{var V,ne;l.style.backgroundColor=(V=W.background)!=null?V:"",l.style.borderColor=(ne=W.border)!=null?ne:""}),l.addEventListener("mouseleave",()=>{l.style.backgroundColor="",l.style.borderColor="transparent"}))}i.appendChild(l);let p=(B=s.closeButtonSize)!=null?B:"32px",f=h("div",""),m=h("button","persona-inline-flex persona-items-center persona-justify-center persona-rounded-full hover:persona-bg-gray-100 persona-cursor-pointer persona-border-none");m.style.height=p,m.style.width=p,m.type="button",m.setAttribute("aria-label","Close chat"),m.style.display=t?"":"none",m.style.color=s.closeButtonColor||Jr.actionIconColor;let C=(R=s.closeButtonIconName)!=null?R:"x",A=ve(C,"28px","currentColor",1);A?m.appendChild(A):m.textContent="\xD7",n&&m.addEventListener("click",n),f.appendChild(m),i.appendChild(f);let k=h("div");k.style.display="none";let T=h("span");return T.style.display="none",{header:i,iconHolder:k,headerTitle:u,headerSubtitle:T,closeButton:m,closeButtonWrapper:f,clearChatButton:null,clearChatButtonWrapper:null}},al={default:dp,minimal:cp},pp=e=>{var r;return(r=al[e])!=null?r:al.default},ka=(e,r,t)=>{var s,i,d;if(r!=null&&r.render){let l=r.render({config:e,onClose:t==null?void 0:t.onClose,onClearChat:t==null?void 0:t.onClearChat,trailingActions:r.trailingActions,onAction:r.onAction}),u=h("div");u.style.display="none";let p=h("span"),f=h("span"),m=h("button");m.style.display="none";let C=h("div");return C.style.display="none",{header:l,iconHolder:u,headerTitle:p,headerSubtitle:f,closeButton:m,closeButtonWrapper:C,clearChatButton:null,clearChatButtonWrapper:null}}let n=(s=r==null?void 0:r.layout)!=null?s:"default",a=pp(n)({config:e,showClose:(d=(i=r==null?void 0:r.showCloseButton)!=null?i:t==null?void 0:t.showClose)!=null?d:!0,onClose:t==null?void 0:t.onClose,onClearChat:t==null?void 0:t.onClearChat,layoutHeaderConfig:r,onHeaderAction:r==null?void 0:r.onAction});return r&&(r.showIcon===!1&&(a.iconHolder.style.display="none"),r.showTitle===!1&&(a.headerTitle.style.display="none"),r.showSubtitle===!1&&(a.headerSubtitle.style.display="none"),r.showCloseButton===!1&&(a.closeButton.style.display="none"),r.showClearChat===!1&&a.clearChatButtonWrapper&&(a.clearChatButtonWrapper.style.display="none")),a};var sl=e=>{var s,i;let r=h("textarea");r.setAttribute("data-persona-composer-input",""),r.placeholder=(i=(s=e==null?void 0:e.copy)==null?void 0:s.inputPlaceholder)!=null?i:"Type your message\u2026",r.className="persona-w-full persona-min-h-[24px] persona-resize-none persona-border-none persona-bg-transparent persona-text-sm persona-text-persona-primary focus:persona-outline-none focus:persona-border-none persona-composer-textarea",r.rows=1,r.style.fontFamily='var(--persona-input-font-family, var(--persona-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif))',r.style.fontWeight="var(--persona-input-font-weight, var(--persona-font-weight, 400))";let t=3,n=20;r.style.maxHeight=`${t*n}px`,r.style.overflowY="auto";let o=()=>{let d=parseFloat(r.style.maxHeight);return Number.isFinite(d)&&d>0?d:t*n},a=()=>{r.addEventListener("input",()=>{r.style.height="auto";let d=Math.min(r.scrollHeight,o());r.style.height=`${d}px`})};return r.style.border="none",r.style.outline="none",r.style.borderWidth="0",r.style.borderStyle="none",r.style.borderColor="transparent",r.addEventListener("focus",()=>{r.style.border="none",r.style.outline="none",r.style.borderWidth="0",r.style.borderStyle="none",r.style.borderColor="transparent",r.style.boxShadow="none"}),r.addEventListener("blur",()=>{r.style.border="none",r.style.outline="none"}),{textarea:r,attachAutoResize:a}},il=e=>{var b,y,M,H,B,R,W,V,ne,ue,Be,Ke;let r=(b=e==null?void 0:e.sendButton)!=null?b:{},t=(y=r.useIcon)!=null?y:!1,n=(M=r.iconText)!=null?M:"\u2191",o=r.iconName,a=(H=r.stopIconName)!=null?H:"square",s=(B=r.tooltipText)!=null?B:"Send message",i=(R=r.stopTooltipText)!=null?R:"Stop generating",d=(V=(W=e==null?void 0:e.copy)==null?void 0:W.sendButtonLabel)!=null?V:"Send",l=(ue=(ne=e==null?void 0:e.copy)==null?void 0:ne.stopButtonLabel)!=null?ue:"Stop",u=(Be=r.showTooltip)!=null?Be:!1,p=(Ke=r.size)!=null?Ke:"40px",f=r.backgroundColor,m=r.textColor,C=h("div","persona-send-button-wrapper"),A=h("button",t?"persona-rounded-button persona-flex persona-items-center persona-justify-center disabled:persona-opacity-50 persona-cursor-pointer":"persona-rounded-button persona-bg-persona-accent persona-px-4 persona-py-2 persona-text-sm persona-font-semibold disabled:persona-opacity-50 persona-cursor-pointer");A.type="submit",A.setAttribute("data-persona-composer-submit","");let k=null,T=null;if(t){A.style.width=p,A.style.height=p,A.style.minWidth=p,A.style.minHeight=p,A.style.fontSize="18px",A.style.lineHeight="1",A.innerHTML="",m?A.style.color=m:A.style.color="var(--persona-button-primary-fg, #ffffff)";let ye=parseFloat(p)||24,me=(m==null?void 0:m.trim())||"currentColor";o?(k=ve(o,ye,me,2),k?A.appendChild(k):A.textContent=n):A.textContent=n,T=ve(a,ye,me,2),f?A.style.backgroundColor=f:A.classList.add("persona-bg-persona-primary")}else A.textContent=d,m?A.style.color=m:A.classList.add("persona-text-white");r.borderWidth&&(A.style.borderWidth=r.borderWidth,A.style.borderStyle="solid"),r.borderColor&&(A.style.borderColor=r.borderColor),r.paddingX?(A.style.paddingLeft=r.paddingX,A.style.paddingRight=r.paddingX):(A.style.paddingLeft="",A.style.paddingRight=""),r.paddingY?(A.style.paddingTop=r.paddingY,A.style.paddingBottom=r.paddingY):(A.style.paddingTop="",A.style.paddingBottom="");let S=null;u&&s&&(S=h("div","persona-send-button-tooltip"),S.textContent=s,C.appendChild(S)),A.setAttribute("aria-label",s),C.appendChild(A);let E="send";return{button:A,wrapper:C,setMode:ye=>{if(ye===E)return;E=ye;let me=ye==="stop"?i:s;if(A.setAttribute("aria-label",me),S&&(S.textContent=me),t){if(k&&T){let We=ye==="stop"?T:k;A.replaceChildren(We)}}else A.textContent=ye==="stop"?l:d}}},ll=e=>{var S,E,w,b,y,M,H,B,R,W,V,ne;let r=(S=e==null?void 0:e.voiceRecognition)!=null?S:{};if(!(r.enabled===!0))return null;let n=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),o=((E=r.provider)==null?void 0:E.type)==="runtype";if(!(n||o))return null;let s=(b=(w=e==null?void 0:e.sendButton)==null?void 0:w.size)!=null?b:"40px",i=h("div","persona-send-button-wrapper"),d=h("button","persona-rounded-button persona-flex persona-items-center persona-justify-center disabled:persona-opacity-50 persona-cursor-pointer");d.type="button",d.setAttribute("data-persona-composer-mic",""),d.setAttribute("aria-label","Start voice recognition");let l=(y=r.iconName)!=null?y:"mic",u=(M=r.iconSize)!=null?M:s,p=parseFloat(u)||24,f=(B=r.backgroundColor)!=null?B:(H=e==null?void 0:e.sendButton)==null?void 0:H.backgroundColor,m=(W=r.iconColor)!=null?W:(R=e==null?void 0:e.sendButton)==null?void 0:R.textColor;d.style.width=u,d.style.height=u,d.style.minWidth=u,d.style.minHeight=u,d.style.fontSize="18px",d.style.lineHeight="1",m?d.style.color=m:d.style.color="var(--persona-text, #111827)";let A=ve(l,p,m||"currentColor",1.5);A?d.appendChild(A):d.textContent="\u{1F3A4}",f&&(d.style.backgroundColor=f),r.borderWidth&&(d.style.borderWidth=r.borderWidth,d.style.borderStyle="solid"),r.borderColor&&(d.style.borderColor=r.borderColor),r.paddingX&&(d.style.paddingLeft=r.paddingX,d.style.paddingRight=r.paddingX),r.paddingY&&(d.style.paddingTop=r.paddingY,d.style.paddingBottom=r.paddingY),i.appendChild(d);let k=(V=r.tooltipText)!=null?V:"Start voice recognition";if(((ne=r.showTooltip)!=null?ne:!1)&&k){let ue=h("div","persona-send-button-tooltip");ue.textContent=k,i.appendChild(ue)}return{button:d,wrapper:i}},dl=e=>{var C,A,k,T,S,E,w,b;let r=(C=e==null?void 0:e.attachments)!=null?C:{};if(r.enabled!==!0)return null;let t=(k=(A=e==null?void 0:e.sendButton)==null?void 0:A.size)!=null?k:"40px",n=h("div","persona-attachment-previews persona-flex persona-flex-wrap persona-gap-2 persona-mb-2");n.style.display="none";let o=h("input");o.type="file",o.accept=((T=r.allowedTypes)!=null?T:no).join(","),o.multiple=((S=r.maxFiles)!=null?S:4)>1,o.style.display="none",o.setAttribute("aria-label","Attach files");let a=h("div","persona-send-button-wrapper"),s=h("button","persona-rounded-button persona-flex persona-items-center persona-justify-center disabled:persona-opacity-50 persona-cursor-pointer persona-attachment-button");s.type="button",s.setAttribute("aria-label",(E=r.buttonTooltipText)!=null?E:"Attach file");let i=(w=r.buttonIconName)!=null?w:"paperclip",d=t,l=parseFloat(d)||40,u=Math.round(l*.6);s.style.width=d,s.style.height=d,s.style.minWidth=d,s.style.minHeight=d,s.style.fontSize="18px",s.style.lineHeight="1",s.style.backgroundColor="transparent",s.style.color="var(--persona-primary, #111827)",s.style.border="none",s.style.borderRadius="6px",s.style.transition="background-color 0.15s ease",s.addEventListener("mouseenter",()=>{s.style.backgroundColor="var(--persona-palette-colors-black-alpha-50, rgba(0, 0, 0, 0.05))"}),s.addEventListener("mouseleave",()=>{s.style.backgroundColor="transparent"});let p=ve(i,u,"currentColor",1.5);p?s.appendChild(p):s.textContent="\u{1F4CE}",s.addEventListener("click",y=>{y.preventDefault(),o.click()}),a.appendChild(s);let f=(b=r.buttonTooltipText)!=null?b:"Attach file",m=h("div","persona-send-button-tooltip");return m.textContent=f,a.appendChild(m),{button:s,wrapper:a,input:o,previewsContainer:n}},cl=e=>{var s,i,d;let r=(s=e==null?void 0:e.statusIndicator)!=null?s:{},t=r.align==="left"?"persona-text-left":r.align==="center"?"persona-text-center":"persona-text-right",n=h("div",`persona-mt-2 ${t} persona-text-xs persona-text-persona-muted`);n.setAttribute("data-persona-composer-status","");let o=(i=r.visible)!=null?i:!0;n.style.display=o?"":"none";let a=(d=r.idleText)!=null?d:"Online";if(r.idleLink){let l=h("a");l.href=r.idleLink,l.target="_blank",l.rel="noopener noreferrer",l.textContent=a,l.style.color="inherit",l.style.textDecoration="none",n.appendChild(l)}else n.textContent=a;return n},pl=()=>h("div","persona-mb-3 persona-flex persona-flex-wrap persona-gap-2");var Ea=e=>{var C,A,k,T,S,E;let{config:r}=e,t=h("div","persona-widget-footer persona-border-t-persona-divider persona-bg-persona-surface persona-px-6 persona-py-4");t.setAttribute("data-persona-theme-zone","composer");let n=pl(),o=h("form","persona-widget-composer persona-flex persona-flex-col persona-gap-2 persona-rounded-2xl persona-border persona-border-gray-200 persona-bg-persona-input-background persona-px-4 persona-py-3");o.setAttribute("data-persona-composer-form",""),o.style.outline="none";let{textarea:a,attachAutoResize:s}=sl(r);s();let i=il(r),d=ll(r),l=dl(r),u=cl(r);l&&(l.previewsContainer.style.gap="8px",o.append(l.previewsContainer,l.input)),o.append(a);let p=h("div","persona-widget-composer__actions persona-flex persona-items-center persona-justify-between persona-w-full"),f=h("div","persona-widget-composer__left-actions persona-flex persona-items-center persona-gap-2"),m=h("div","persona-widget-composer__right-actions persona-flex persona-items-center persona-gap-1");return l&&f.append(l.wrapper),d&&m.append(d.wrapper),m.append(i.wrapper),p.append(f,m),o.append(p),o.addEventListener("click",w=>{w.target!==i.button&&w.target!==i.wrapper&&w.target!==(d==null?void 0:d.button)&&w.target!==(d==null?void 0:d.wrapper)&&w.target!==(l==null?void 0:l.button)&&w.target!==(l==null?void 0:l.wrapper)&&a.focus()}),t.append(n,o,u),{footer:t,suggestions:n,composerForm:o,textarea:a,sendButton:i.button,sendButtonWrapper:i.wrapper,micButton:(C=d==null?void 0:d.button)!=null?C:null,micButtonWrapper:(A=d==null?void 0:d.wrapper)!=null?A:null,statusText:u,attachmentButton:(k=l==null?void 0:l.button)!=null?k:null,attachmentButtonWrapper:(T=l==null?void 0:l.wrapper)!=null?T:null,attachmentInput:(S=l==null?void 0:l.input)!=null?S:null,attachmentPreviewsContainer:(E=l==null?void 0:l.previewsContainer)!=null?E:null,actionsRow:p,leftActions:f,rightActions:m,setSendButtonMode:i.setMode}};var nh=()=>{let e=h("button","persona-pill-peek");e.type="button",e.setAttribute("data-persona-pill-peek",""),e.setAttribute("aria-label","Show conversation"),e.setAttribute("tabindex","-1");let r=h("span","persona-pill-peek__icon"),t=ve("message-square",16,"currentColor",1.5);t&&r.appendChild(t);let n=h("span","persona-pill-peek__text"),o=h("span","persona-pill-peek__caret"),a=ve("chevron-up",16,"currentColor",1.5);return a&&o.appendChild(a),e.append(r,n,o),{root:e,textNode:n}},oh=e=>{var C,A,k,T,S,E;let{config:r}=e,t=h("div","persona-widget-footer persona-widget-footer--pill");t.setAttribute("data-persona-theme-zone","composer");let n=pl();n.style.display="none";let o=cl(r);o.style.display="none";let{textarea:a,attachAutoResize:s}=sl(r);a.style.maxHeight="100px",s();let i=il(r),d=ll(r),l=dl(r);l&&l.previewsContainer.classList.add("persona-pill-composer__previews");let u=h("form","persona-widget-composer persona-pill-composer");u.setAttribute("data-persona-composer-form",""),u.style.outline="none";let p=h("div","persona-widget-composer__left-actions persona-pill-composer__left");l&&p.append(l.wrapper);let f=h("div","persona-widget-composer__right-actions persona-pill-composer__right");d&&f.append(d.wrapper),f.append(i.wrapper),u.addEventListener("click",w=>{w.target!==i.button&&w.target!==i.wrapper&&w.target!==(d==null?void 0:d.button)&&w.target!==(d==null?void 0:d.wrapper)&&w.target!==(l==null?void 0:l.button)&&w.target!==(l==null?void 0:l.wrapper)&&a.focus()}),l&&u.append(l.input),u.append(p,a,f),l&&t.append(l.previewsContainer),t.append(u,n,o);let m=u;return{footer:t,suggestions:n,composerForm:u,textarea:a,sendButton:i.button,sendButtonWrapper:i.wrapper,micButton:(C=d==null?void 0:d.button)!=null?C:null,micButtonWrapper:(A=d==null?void 0:d.wrapper)!=null?A:null,statusText:o,attachmentButton:(k=l==null?void 0:l.button)!=null?k:null,attachmentButtonWrapper:(T=l==null?void 0:l.wrapper)!=null?T:null,attachmentInput:(S=l==null?void 0:l.input)!=null?S:null,attachmentPreviewsContainer:(E=l==null?void 0:l.previewsContainer)!=null?E:null,actionsRow:m,leftActions:p,rightActions:f,setSendButtonMode:i.setMode}};var ah=e=>{var u,p,f,m,C,A,k,T,S,E,w,b,y,M,H,B,R;let r=(p=(u=e==null?void 0:e.launcher)==null?void 0:u.enabled)!=null?p:!0,t=hr(e);if(So(e)){let W=(m=(f=e==null?void 0:e.launcher)==null?void 0:f.composerBar)!=null?m:{},V=h("div","persona-widget-wrapper persona-fixed persona-transition");V.setAttribute("data-persona-composer-bar",""),V.dataset.state="collapsed",V.dataset.expandedSize=(C=W.expandedSize)!=null?C:"anchored",V.style.zIndex=String((k=(A=e==null?void 0:e.launcher)==null?void 0:A.zIndex)!=null?k:Dr);let ne=h("div","persona-widget-panel persona-relative persona-flex persona-flex-1 persona-min-h-0 persona-flex-col");ne.style.width="100%",V.appendChild(ne);let ue=h("div","persona-widget-pill-root");return ue.setAttribute("data-persona-composer-bar",""),ue.dataset.state="collapsed",ue.dataset.expandedSize=(T=W.expandedSize)!=null?T:"anchored",ue.style.zIndex=String((E=(S=e==null?void 0:e.launcher)==null?void 0:S.zIndex)!=null?E:Dr),{wrapper:V,panel:ne,pillRoot:ue}}if(t){let W=h("div","persona-relative persona-h-full persona-w-full persona-flex persona-flex-1 persona-min-h-0 persona-flex-col"),V=h("div","persona-relative persona-h-full persona-w-full persona-flex persona-flex-1 persona-min-h-0 persona-flex-col");return W.appendChild(V),{wrapper:W,panel:V}}if(!r){let W=h("div","persona-relative persona-h-full persona-flex persona-flex-col persona-flex-1 persona-min-h-0"),V=h("div","persona-relative persona-flex-1 persona-flex persona-flex-col persona-min-h-0"),ne=(b=(w=e==null?void 0:e.launcher)==null?void 0:w.width)!=null?b:"100%";return W.style.width=ne,V.style.width="100%",W.appendChild(V),{wrapper:W,panel:V}}let o=(y=e==null?void 0:e.launcher)!=null?y:{},a=o.position&&On[o.position]?On[o.position]:On["bottom-right"],s=h("div",`persona-widget-wrapper persona-fixed ${a} persona-transition`);s.style.zIndex=String((H=(M=e==null?void 0:e.launcher)==null?void 0:M.zIndex)!=null?H:Dr);let i=h("div","persona-widget-panel persona-relative persona-min-h-[320px]"),d=(R=(B=e==null?void 0:e.launcher)==null?void 0:B.width)!=null?R:e==null?void 0:e.launcherWidth,l=d!=null?d:mn;return i.style.width=l,i.style.maxWidth=l,s.appendChild(i),{wrapper:s,panel:i}},Hb=(e,r)=>{var w,b,y,M,H,B,R,W,V;let t=h("div","persona-widget-container persona-relative persona-flex persona-flex-1 persona-min-h-0 persona-flex-col persona-text-persona-primary");t.setAttribute("data-persona-theme-zone","container");let{button:n,wrapper:o}=rl(e,{showClose:r,wrapperClassName:"persona-composer-bar-close",buttonSize:"16px",iconSize:"14px"});o.style.position="absolute",o.style.top="8px",o.style.right="8px",o.style.zIndex="10";let a=(y=(b=(w=e==null?void 0:e.launcher)==null?void 0:w.clearChat)==null?void 0:b.enabled)!=null?y:!0,s=null,i=null;if(a){let ne=nl(e,{wrapperClassName:"persona-composer-bar-clear-chat",buttonSize:"16px",iconSize:"14px"});s=ne.button,i=ne.wrapper,i.style.position="absolute",i.style.top="8px",i.style.right="32px",i.style.zIndex="10"}let d=h("span","persona-widget-header");d.setAttribute("data-persona-theme-zone","header"),d.style.display="none";let l=h("div","persona-widget-body persona-flex persona-flex-1 persona-min-h-0 persona-flex-col persona-gap-6 persona-overflow-y-auto persona-bg-persona-container persona-px-6 persona-py-6");l.style.paddingTop="48px",l.id="persona-scroll-container",l.setAttribute("data-persona-theme-zone","messages");let u=h("div","persona-rounded-2xl persona-bg-persona-surface persona-p-6");u.style.boxShadow="var(--persona-intro-card-shadow, 0 5px 15px rgba(15, 23, 42, 0.08))",u.setAttribute("data-persona-intro-card","");let p=h("h2","persona-text-lg persona-font-semibold persona-text-persona-primary");p.textContent=(H=(M=e==null?void 0:e.copy)==null?void 0:M.welcomeTitle)!=null?H:"Hello \u{1F44B}";let f=h("p","persona-mt-2 persona-text-sm persona-text-persona-muted");f.textContent=(R=(B=e==null?void 0:e.copy)==null?void 0:B.welcomeSubtitle)!=null?R:"Ask anything about your account or products.",u.append(p,f);let m=h("div","persona-flex persona-flex-col persona-gap-3"),C=(W=e==null?void 0:e.layout)==null?void 0:W.contentMaxWidth;C&&(m.style.maxWidth=C,m.style.marginLeft="auto",m.style.marginRight="auto",m.style.width="100%"),((V=e==null?void 0:e.copy)==null?void 0:V.showWelcomeCard)!==!1||(u.style.display="none",l.classList.remove("persona-gap-6"),l.classList.add("persona-gap-3")),l.append(u,m);let k=h("div","persona-composer-overlay persona-pointer-events-none");k.setAttribute("data-persona-composer-overlay",""),k.style.position="absolute",k.style.left="0",k.style.right="0",k.style.bottom="0",k.style.zIndex="20";let T=oh({config:e}),{root:S,textNode:E}=nh();return t.append(d,o,l,k),i&&t.appendChild(i),{container:t,body:l,messagesWrapper:m,composerOverlay:k,suggestions:T.suggestions,textarea:T.textarea,sendButton:T.sendButton,sendButtonWrapper:T.sendButtonWrapper,micButton:T.micButton,micButtonWrapper:T.micButtonWrapper,composerForm:T.composerForm,statusText:T.statusText,introTitle:p,introSubtitle:f,closeButton:n,closeButtonWrapper:o,clearChatButton:s,clearChatButtonWrapper:i,iconHolder:h("span"),headerTitle:h("span"),headerSubtitle:h("span"),header:d,footer:T.footer,attachmentButton:T.attachmentButton,attachmentButtonWrapper:T.attachmentButtonWrapper,attachmentInput:T.attachmentInput,attachmentPreviewsContainer:T.attachmentPreviewsContainer,actionsRow:T.actionsRow,leftActions:T.leftActions,rightActions:T.rightActions,setSendButtonMode:T.setSendButtonMode,peekBanner:S,peekTextNode:E}},sh=(e,r=!0)=>{var k,T,S,E,w,b,y,M,H;if(So(e))return Hb(e,r);let t=h("div","persona-widget-container persona-flex persona-h-full persona-w-full persona-flex-1 persona-min-h-0 persona-flex-col persona-text-persona-primary persona-bg-persona-surface persona-rounded-2xl persona-overflow-hidden persona-border persona-border-persona-border");t.setAttribute("data-persona-theme-zone","container");let n=(k=e==null?void 0:e.layout)==null?void 0:k.header,o=((T=e==null?void 0:e.layout)==null?void 0:T.showHeader)!==!1,a=n?ka(e,n,{showClose:r}):oo({config:e,showClose:r}),s=h("div","persona-widget-body persona-flex persona-flex-1 persona-min-h-0 persona-flex-col persona-gap-6 persona-overflow-y-auto persona-bg-persona-container persona-px-6 persona-py-6");s.id="persona-scroll-container",s.setAttribute("data-persona-theme-zone","messages");let i=h("div","persona-rounded-2xl persona-bg-persona-surface persona-p-6");i.style.boxShadow=hr(e)?"none":"var(--persona-intro-card-shadow, 0 5px 15px rgba(15, 23, 42, 0.08))";let d=h("h2","persona-text-lg persona-font-semibold persona-text-persona-primary");d.textContent=(E=(S=e==null?void 0:e.copy)==null?void 0:S.welcomeTitle)!=null?E:"Hello \u{1F44B}";let l=h("p","persona-mt-2 persona-text-sm persona-text-persona-muted");l.textContent=(b=(w=e==null?void 0:e.copy)==null?void 0:w.welcomeSubtitle)!=null?b:"Ask anything about your account or products.",i.append(d,l);let u=h("div","persona-flex persona-flex-col persona-gap-3"),p=(y=e==null?void 0:e.layout)==null?void 0:y.contentMaxWidth;p&&(u.style.maxWidth=p,u.style.marginLeft="auto",u.style.marginRight="auto",u.style.width="100%"),i.setAttribute("data-persona-intro-card",""),((M=e==null?void 0:e.copy)==null?void 0:M.showWelcomeCard)!==!1||(i.style.display="none",s.classList.remove("persona-gap-6"),s.classList.add("persona-gap-3")),s.append(i,u);let m=Ea({config:e}),C=((H=e==null?void 0:e.layout)==null?void 0:H.showFooter)!==!1;o?na(t,a,e):(a.header.style.display="none",na(t,a,e)),t.append(s);let A=h("div","persona-composer-overlay persona-pointer-events-none");return A.setAttribute("data-persona-composer-overlay",""),A.style.position="absolute",A.style.left="0",A.style.right="0",A.style.bottom="0",A.style.zIndex="20",C||(m.footer.style.display="none"),t.append(m.footer),t.append(A),{container:t,body:s,messagesWrapper:u,composerOverlay:A,suggestions:m.suggestions,textarea:m.textarea,sendButton:m.sendButton,sendButtonWrapper:m.sendButtonWrapper,micButton:m.micButton,micButtonWrapper:m.micButtonWrapper,composerForm:m.composerForm,statusText:m.statusText,introTitle:d,introSubtitle:l,closeButton:a.closeButton,closeButtonWrapper:a.closeButtonWrapper,clearChatButton:a.clearChatButton,clearChatButtonWrapper:a.clearChatButtonWrapper,iconHolder:a.iconHolder,headerTitle:a.headerTitle,headerSubtitle:a.headerSubtitle,header:a.header,footer:m.footer,attachmentButton:m.attachmentButton,attachmentButtonWrapper:m.attachmentButtonWrapper,attachmentInput:m.attachmentInput,attachmentPreviewsContainer:m.attachmentPreviewsContainer,actionsRow:m.actionsRow,leftActions:m.leftActions,rightActions:m.rightActions,setSendButtonMode:m.setSendButtonMode}};var Bb=e=>{switch(e){case"max_tool_calls":return"Stopped after calling a tool. Send a follow-up to continue.";case"length":return"Response cut off as max tokens reached. Ask for more to continue.";case"content_filter":return"The provider filtered this response.";case"error":return"Something went wrong generating this response.";default:return null}},Wb=(e,r)=>{if(!e)return null;let t=Bb(e);if(t===null)return null;let n=r==null?void 0:r[e],o=n!==void 0?n:t;return o||null},Db=(e,r)=>{let t=h("div","persona-message-stop-reason persona-text-xs persona-mt-2 persona-italic");return t.setAttribute("data-stop-reason",e),t.setAttribute("role","note"),t.style.opacity="0.75",t.textContent=r,t},Ob=e=>{let r=e.toLowerCase();return r.startsWith("data:image/svg+xml")?!1:!!(/^(?:https?|blob):/i.test(e)||r.startsWith("data:image/")||!e.includes(":"))},up=e=>{let r=e.toLowerCase();return r.startsWith("javascript:")||r.startsWith("data:text/html")||r.startsWith("data:text/javascript")||r.startsWith("data:text/xml")||r.startsWith("data:application/xhtml")||r.startsWith("data:image/svg+xml")?!1:!!(/^(?:https?|blob):/i.test(e)||r.startsWith("data:")||!e.includes(":"))},fp=320,lh=320,Fb=e=>!e.contentParts||e.contentParts.length===0?[]:e.contentParts.filter(r=>r.type==="image"&&typeof r.image=="string"&&r.image.trim().length>0),Nb=e=>!e.contentParts||e.contentParts.length===0?[]:e.contentParts.filter(r=>r.type==="audio"&&typeof r.audio=="string"&&r.audio.trim().length>0),_b=e=>!e.contentParts||e.contentParts.length===0?[]:e.contentParts.filter(r=>r.type==="video"&&typeof r.video=="string"&&r.video.trim().length>0),$b=e=>!e.contentParts||e.contentParts.length===0?[]:e.contentParts.filter(r=>r.type==="file"&&typeof r.data=="string"&&r.data.trim().length>0),Ub=(e,r,t)=>{if(e.length===0)return null;try{let n=h("div","persona-flex persona-flex-col persona-gap-2");n.setAttribute("data-message-attachments","images"),r&&(n.style.marginBottom="8px");let o=0,a=!1,s=()=>{a||(a=!0,n.remove(),t==null||t())};return e.forEach((i,d)=>{var p;let l=h("img");l.alt=((p=i.alt)==null?void 0:p.trim())||`Attached image ${d+1}`,l.loading="lazy",l.decoding="async",l.referrerPolicy="no-referrer",l.style.display="block",l.style.width="100%",l.style.maxWidth=`${fp}px`,l.style.maxHeight=`${lh}px`,l.style.height="auto",l.style.objectFit="contain",l.style.borderRadius="10px",l.style.backgroundColor="var(--persona-attachment-image-bg, var(--persona-container, #f3f4f6))",l.style.border="1px solid var(--persona-attachment-image-border, var(--persona-border, #e5e7eb))";let u=!1;o+=1,l.addEventListener("error",()=>{u||(u=!0,o=Math.max(0,o-1),l.remove(),o===0&&s())}),l.addEventListener("load",()=>{u=!0}),Ob(i.image)?(l.src=i.image,n.appendChild(l)):(u=!0,o=Math.max(0,o-1),l.remove())}),o===0?(s(),null):n}catch{return t==null||t(),null}},qb=e=>{if(e.length===0)return null;try{let r=h("div","persona-flex persona-flex-col persona-gap-2");r.setAttribute("data-message-attachments","audio");let t=0;return e.forEach(n=>{if(!up(n.audio))return;let o=h("audio");o.controls=!0,o.preload="metadata",o.src=n.audio,o.style.display="block",o.style.width="100%",o.style.maxWidth=`${fp}px`,r.appendChild(o),t+=1}),t===0?(r.remove(),null):r}catch{return null}},zb=e=>{if(e.length===0)return null;try{let r=h("div","persona-flex persona-flex-col persona-gap-2");r.setAttribute("data-message-attachments","video");let t=0;return e.forEach(n=>{if(!up(n.video))return;let o=h("video");o.controls=!0,o.preload="metadata",o.src=n.video,o.style.display="block",o.style.width="100%",o.style.maxWidth=`${fp}px`,o.style.maxHeight=`${lh}px`,o.style.borderRadius="10px",o.style.backgroundColor="var(--persona-attachment-image-bg, var(--persona-container, #f3f4f6))",r.appendChild(o),t+=1}),t===0?(r.remove(),null):r}catch{return null}},Vb=e=>{if(e.length===0)return null;try{let r=h("div","persona-flex persona-flex-col persona-gap-2");r.setAttribute("data-message-attachments","files");let t=0;return e.forEach(n=>{if(!up(n.data))return;let o=h("a");o.href=n.data,o.download=n.filename,o.target="_blank",o.rel="noopener noreferrer",o.textContent=n.filename,o.className="persona-message-file-attachment",o.style.display="inline-flex",o.style.alignItems="center",o.style.gap="6px",o.style.padding="6px 10px",o.style.borderRadius="8px",o.style.fontSize="0.875rem",o.style.textDecoration="underline",o.style.backgroundColor="var(--persona-attachment-file-bg, var(--persona-container, #f3f4f6))",o.style.border="1px solid var(--persona-attachment-file-border, var(--persona-border, #e5e7eb))",o.style.color="inherit",r.appendChild(o),t+=1}),t===0?(r.remove(),null):r}catch{return null}},oa=()=>{let e=document.createElement("div");e.className="persona-flex persona-items-center persona-space-x-1 persona-h-5 persona-mt-2";let r=document.createElement("div");r.className="persona-animate-typing persona-rounded-full persona-h-1.5 persona-w-1.5",r.style.backgroundColor="currentColor",r.style.opacity="0.4",r.style.animationDelay="0ms";let t=document.createElement("div");t.className="persona-animate-typing persona-rounded-full persona-h-1.5 persona-w-1.5",t.style.backgroundColor="currentColor",t.style.opacity="0.4",t.style.animationDelay="250ms";let n=document.createElement("div");n.className="persona-animate-typing persona-rounded-full persona-h-1.5 persona-w-1.5",n.style.backgroundColor="currentColor",n.style.opacity="0.4",n.style.animationDelay="500ms";let o=document.createElement("span");return o.className="persona-sr-only",o.textContent="Loading",e.appendChild(r),e.appendChild(t),e.appendChild(n),e.appendChild(o),e},mp=(e,r,t)=>{let n={config:t!=null?t:{},streaming:!0,location:e,defaultRenderer:oa};if(r){let o=r(n);if(o!==null)return o}return oa()},jb=(e,r)=>{let t=h("div","persona-flex-shrink-0 persona-w-8 persona-h-8 persona-rounded-full persona-flex persona-items-center persona-justify-center persona-text-sm"),n=r==="user"?e.userAvatar:e.assistantAvatar;if(n)if(n.startsWith("http")||n.startsWith("/")||n.startsWith("data:")){let o=h("img");o.src=n,o.alt=r==="user"?"User":"Assistant",o.className="persona-w-full persona-h-full persona-rounded-full persona-object-cover",t.appendChild(o)}else t.textContent=n,t.classList.add(r==="user"?"persona-bg-persona-accent":"persona-bg-persona-primary","persona-text-white");else t.textContent=r==="user"?"U":"A",t.classList.add(r==="user"?"persona-bg-persona-accent":"persona-bg-persona-primary","persona-text-white");return t},ih=(e,r)=>{let t=h("div","persona-text-xs persona-text-persona-muted"),n=new Date(e.createdAt);return r.format?t.textContent=r.format(n):t.textContent=n.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),t},Gb=(e,r="bubble")=>{let t=["persona-message-bubble","persona-max-w-[85%]"];switch(r){case"flat":e==="user"?t.push("persona-message-user-bubble","persona-ml-auto","persona-text-persona-primary","persona-py-2"):t.push("persona-message-assistant-bubble","persona-text-persona-primary","persona-py-2");break;case"minimal":t.push("persona-text-sm","persona-leading-relaxed"),e==="user"?t.push("persona-message-user-bubble","persona-ml-auto","persona-bg-persona-accent","persona-text-white","persona-px-3","persona-py-2","persona-rounded-lg"):t.push("persona-message-assistant-bubble","persona-bg-persona-surface","persona-text-persona-primary","persona-px-3","persona-py-2","persona-rounded-lg");break;default:t.push("persona-rounded-2xl","persona-text-sm","persona-leading-relaxed","persona-shadow-sm"),e==="user"?t.push("persona-message-user-bubble","persona-ml-auto","persona-bg-persona-accent","persona-text-white","persona-px-5","persona-py-3"):t.push("persona-message-assistant-bubble","persona-bg-persona-surface","persona-border","persona-border-persona-message-border","persona-text-persona-primary","persona-px-5","persona-py-3");break}return t},gp=(e,r,t)=>{var m,C,A,k,T,S;let n=(m=r.showCopy)!=null?m:!0,o=(C=r.showUpvote)!=null?C:!0,a=(A=r.showDownvote)!=null?A:!0;if(!n&&!o&&!a){let E=h("div");return E.style.display="none",E.id=`actions-${e.id}`,E.setAttribute("data-actions-for",e.id),E}let s=(k=r.visibility)!=null?k:"hover",i=(T=r.align)!=null?T:"right",d=(S=r.layout)!=null?S:"pill-inside",l={left:"persona-message-actions-left",center:"persona-message-actions-center",right:"persona-message-actions-right"}[i],u={"pill-inside":"persona-message-actions-pill","row-inside":"persona-message-actions-row"}[d],p=h("div",`persona-message-actions persona-flex persona-items-center persona-gap-1 persona-mt-2 ${l} ${u} ${s==="hover"?"persona-message-actions-hover":""}`);p.id=`actions-${e.id}`,p.setAttribute("data-actions-for",e.id);let f=(E,w,b)=>{let y=Zt({icon:E,label:w,size:14,className:"persona-message-action-btn"});return y.setAttribute("data-action",b),y};return n&&p.appendChild(f("copy","Copy message","copy")),o&&p.appendChild(f("thumbs-up","Upvote","upvote")),a&&p.appendChild(f("thumbs-down","Downvote","downvote")),p},Ma=(e,r,t,n,o,a)=>{var Y,Ee,G,ce,de,pe,Re,Ye,J,ie,Ue,K,j,Ce,De,oe,Se;let s=t!=null?t:{},i=(Y=s.layout)!=null?Y:"bubble",d=s.avatar,l=s.timestamp,u=(Ee=d==null?void 0:d.show)!=null?Ee:!1,p=(G=l==null?void 0:l.show)!=null?G:!1,f=(ce=d==null?void 0:d.position)!=null?ce:"left",m=(de=l==null?void 0:l.position)!=null?de:"below",C=Gb(e.role,i),A=h("div",C.join(" "));A.id=`bubble-${e.id}`,A.setAttribute("data-message-id",e.id),A.setAttribute("data-persona-theme-zone",e.role==="user"?"user-message":"assistant-message"),e.role==="user"?(A.style.backgroundColor="var(--persona-message-user-bg, var(--persona-accent))",A.style.color="var(--persona-message-user-text, white)"):e.role==="assistant"&&(A.style.backgroundColor="var(--persona-message-assistant-bg, var(--persona-surface))",A.style.color="var(--persona-message-assistant-text, var(--persona-text))");let k=Fb(e),T=(Re=(pe=e.content)==null?void 0:pe.trim())!=null?Re:"",E=k.length>0&&T===Ei,w=Qi((J=(Ye=a==null?void 0:a.widgetConfig)==null?void 0:Ye.features)==null?void 0:J.streamAnimation),b=(K=(Ue=(ie=a==null?void 0:a.widgetConfig)==null?void 0:ie.features)==null?void 0:Ue.streamAnimation)==null?void 0:K.plugins,y=e.role==="assistant"&&w.type!=="none"?Ts(w.type,b):null,M=e.role==="assistant"&&((j=y==null?void 0:y.isAnimating)==null?void 0:j.call(y,e))===!0,H=e.role==="assistant"&&y!==null&&(!!e.streaming||M);H&&(y!=null&&y.bubbleClass)&&A.classList.add(y.bubbleClass);let B=document.createElement("div");B.classList.add("persona-message-content"),H&&y&&(y.containerClass&&B.classList.add(y.containerClass),B.style.setProperty("--persona-stream-step",`${w.speed}ms`),B.style.setProperty("--persona-stream-duration",`${w.duration}ms`));let R=H?Zi((Ce=e.content)!=null?Ce:"",w.buffer,y,e,!!e.streaming):(De=e.content)!=null?De:"",W=r({text:R,message:e,streaming:!!e.streaming,raw:e.rawContent}),V=W;H&&(y==null?void 0:y.wrap)==="char"?V=ks(W,"char",e.id,{skipTags:y.skipTags}):H&&(y==null?void 0:y.wrap)==="word"&&(V=ks(W,"word",e.id,{skipTags:y.skipTags}));let ne=null;if(E?(ne=document.createElement("div"),ne.innerHTML=V,ne.style.display="none",B.appendChild(ne)):B.innerHTML=V,H&&(y!=null&&y.useCaret)&&!E&&T){let ge=el(),Rt=B.querySelectorAll(".persona-stream-char, .persona-stream-word"),Me=Rt[Rt.length-1];if(Me!=null&&Me.parentNode)Me.parentNode.insertBefore(ge,Me.nextSibling);else{let ae=B.lastElementChild;ae?ae.appendChild(ge):B.appendChild(ge)}}if(p&&m==="inline"&&e.createdAt){let ge=ih(e,l);ge.classList.add("persona-ml-2","persona-inline"),B.appendChild(ge)}if(k.length>0){let ge=Ub(k,!E&&!!T,()=>{E&&ne&&(ne.style.display="")});ge?A.appendChild(ge):E&&ne&&(ne.style.display="")}let ue=Nb(e);if(ue.length>0){let ge=qb(ue);ge&&A.appendChild(ge)}let Be=_b(e);if(Be.length>0){let ge=zb(Be);ge&&A.appendChild(ge)}let Ke=$b(e);if(Ke.length>0){let ge=Vb(Ke);ge&&A.appendChild(ge)}if(A.appendChild(B),p&&m==="below"&&e.createdAt){let ge=ih(e,l);ge.classList.add("persona-mt-1"),A.appendChild(ge)}let ye=e.role==="assistant"?Wb(e.stopReason,(Se=(oe=a==null?void 0:a.widgetConfig)==null?void 0:oe.copy)==null?void 0:Se.stopReasonNotice):null;if(e.streaming&&e.role==="assistant"){let ge=!!(R&&R.trim()),Rt=w.placeholder==="skeleton",Me=Rt&&w.buffer==="line"&≥if(ge)Me&&A.appendChild(Es());else if(Rt)A.appendChild(Es());else{let ae=mp("inline",a==null?void 0:a.loadingIndicatorRenderer,a==null?void 0:a.widgetConfig);ae&&A.appendChild(ae)}}if(ye&&e.stopReason&&!e.streaming&&(T||(B.style.display="none"),A.appendChild(Db(e.stopReason,ye))),e.role==="assistant"&&!e.streaming&&e.content&&e.content.trim()&&(n==null?void 0:n.enabled)!==!1&&n){let ge=gp(e,n,o);A.appendChild(ge)}if(!u||e.role==="system")return A;let We=h("div",`persona-flex persona-gap-2 ${e.role==="user"?"persona-flex-row-reverse":""}`),Xe=jb(d,e.role);return f==="right"||f==="left"&&e.role==="user"?We.append(A,Xe):We.append(Xe,A),A.classList.remove("persona-max-w-[85%]"),A.classList.add("persona-max-w-[calc(85%-2.5rem)]"),We},dh=(e,r,t,n,o,a)=>{let s=t!=null?t:{};return e.role==="user"&&s.renderUserMessage?s.renderUserMessage({message:e,config:{},streaming:!!e.streaming}):e.role==="assistant"&&s.renderAssistantMessage?s.renderAssistantMessage({message:e,config:{},streaming:!!e.streaming}):Ma(e,r,t,n,o,a)};var La=new Set,Xb=(e,r)=>r==null?!1:typeof r=="string"?(e.textContent=r,!0):(e.appendChild(r),!0),Jb=(e,r)=>{var n,o;let t=(o=(n=e.reasoning)==null?void 0:n.chunks.join("").trim())!=null?o:"";return t?t.split(/\r?\n/).map(a=>a.trim()).filter(Boolean).slice(0,r).join(`
|
|
64
|
+
`):""},ch=(e,r)=>{let t=La.has(e),n=r.querySelector('button[data-expand-header="true"]'),o=r.querySelector(".persona-border-t"),a=r.querySelector('[data-persona-collapsed-preview="reasoning"]');if(!n||!o)return;n.setAttribute("aria-expanded",t?"true":"false");let s=n.querySelector(".persona-ml-auto"),i=s==null?void 0:s.querySelector(":scope > .persona-flex.persona-items-center");if(i){i.innerHTML="";let l=ve(t?"chevron-up":"chevron-down",16,"currentColor",2);l?i.appendChild(l):i.textContent=t?"Hide":"Show"}o.style.display=t?"":"none",a&&(a.style.display=t?"none":a.textContent||a.childNodes.length?"":"none")},hp=(e,r)=>{var Be,Ke,ye,me,We,Xe,Y,Ee,G,ce,de;let t=e.reasoning,n=h("div",["persona-message-bubble","persona-reasoning-bubble","persona-w-full","persona-max-w-[85%]","persona-rounded-2xl","persona-bg-persona-surface","persona-border","persona-border-persona-message-border","persona-text-persona-primary","persona-shadow-sm","persona-overflow-hidden","persona-px-0","persona-py-0"].join(" "));if(n.id=`bubble-${e.id}`,n.setAttribute("data-message-id",e.id),!t)return n;let o=(Ke=(Be=r==null?void 0:r.features)==null?void 0:Be.reasoningDisplay)!=null?Ke:{},a=o.expandable!==!1,s=a&&La.has(e.id),i=t.status!=="complete",d=Jb(e,(ye=o.previewMaxLines)!=null?ye:3),l=h("button",a?"persona-flex persona-w-full persona-items-center persona-justify-between persona-gap-3 persona-bg-transparent persona-px-4 persona-py-3 persona-text-left persona-cursor-pointer persona-border-none":"persona-flex persona-w-full persona-items-center persona-justify-between persona-gap-3 persona-bg-transparent persona-px-4 persona-py-3 persona-text-left persona-cursor-default persona-border-none");l.type="button",a&&(l.setAttribute("aria-expanded",s?"true":"false"),l.setAttribute("data-expand-header","true")),l.setAttribute("data-bubble-type","reasoning");let u=h("div","persona-flex persona-flex-col persona-text-left"),p=h("span","persona-text-xs persona-text-persona-primary"),f="Thinking...",m=(me=r==null?void 0:r.reasoning)!=null?me:{},C=String((We=t.startedAt)!=null?We:Date.now()),A=()=>{let pe=h("span","");return pe.setAttribute("data-tool-elapsed",C),pe.textContent=bi(t),pe},k=(Xe=m.renderCollapsedSummary)==null?void 0:Xe.call(m,{message:e,reasoning:t,defaultSummary:f,previewText:d,isActive:i,config:r!=null?r:{},elapsed:bi(t),createElapsedElement:A});typeof k=="string"&&k.trim()?(p.textContent=k,u.appendChild(p)):k instanceof HTMLElement?u.appendChild(k):(p.textContent=f,u.appendChild(p));let T=h("span","persona-text-xs persona-text-persona-primary");T.textContent=Eg(t),u.appendChild(T);let S=(Y=o.loadingAnimation)!=null?Y:"none",E=m.activeTextTemplate,w=m.completeTextTemplate,b=i?E:w,y=k instanceof HTMLElement,M=(pe,Re,Ye)=>{let J=Ye;for(let ie of Re){let Ue=h("span","persona-tool-char");Ue.style.setProperty("--char-index",String(J)),Ue.textContent=ie===" "?"\xA0":ie,pe.appendChild(Ue),J++}return J},H=(pe,Re)=>{p.textContent="";let Ye=Ci(pe,""),J=0;for(let ie of Ye){let Ue=ie.styles.length>0?(()=>{let K=h("span",ie.styles.map(j=>`persona-tool-text-${j}`).join(" "));return p.appendChild(K),K})():p;if(ie.isDuration&&i)Ue.appendChild(A());else{let K=ie.isDuration?bi(t):ie.text;Re?J=M(Ue,K,J):Ue.appendChild(document.createTextNode(K))}}};if(!y&&b)if(T.style.display="none",p.style.display="",i&&S!=="none"){let pe=(Ee=m.loadingAnimationDuration)!=null?Ee:2e3;p.setAttribute("data-preserve-animation","true"),S==="pulse"?(p.classList.add("persona-tool-loading-pulse"),p.style.setProperty("--persona-tool-anim-duration",`${pe}ms`),H(b,!1)):(p.classList.add(`persona-tool-loading-${S}`),p.style.setProperty("--persona-tool-anim-duration",`${pe}ms`),S==="shimmer-color"&&(m.loadingAnimationColor&&p.style.setProperty("--persona-tool-anim-color",m.loadingAnimationColor),m.loadingAnimationSecondaryColor&&p.style.setProperty("--persona-tool-anim-secondary-color",m.loadingAnimationSecondaryColor)),H(b,!0))}else H(b,!1);else if(!y&&i&&S!=="none"){p.style.display="";let pe=(G=m.loadingAnimationDuration)!=null?G:2e3;if(p.setAttribute("data-preserve-animation","true"),S==="pulse")p.classList.add("persona-tool-loading-pulse"),p.style.setProperty("--persona-tool-anim-duration",`${pe}ms`);else{p.classList.add(`persona-tool-loading-${S}`),p.style.setProperty("--persona-tool-anim-duration",`${pe}ms`),S==="shimmer-color"&&(m.loadingAnimationColor&&p.style.setProperty("--persona-tool-anim-color",m.loadingAnimationColor),m.loadingAnimationSecondaryColor&&p.style.setProperty("--persona-tool-anim-secondary-color",m.loadingAnimationSecondaryColor));let Re=p.textContent||f;p.textContent="",M(p,Re,0)}t.status==="complete"&&(p.style.display="none")}else y||(t.status==="complete"?p.style.display="none":p.style.display="");let B=null;if(a){B=h("div","persona-flex persona-items-center");let Re=ve(s?"chevron-up":"chevron-down",16,"currentColor",2);Re?B.appendChild(Re):B.textContent=s?"Hide":"Show";let Ye=h("div","persona-flex persona-items-center persona-ml-auto");Ye.append(B),l.append(u,Ye)}else l.append(u);let R=h("div","persona-px-4 persona-py-3 persona-text-xs persona-leading-snug persona-text-persona-muted");if(R.setAttribute("data-persona-collapsed-preview","reasoning"),R.style.display="none",R.style.whiteSpace="pre-wrap",!s&&i&&o.activePreview&&d){let pe=(de=(ce=r==null?void 0:r.reasoning)==null?void 0:ce.renderCollapsedPreview)==null?void 0:de.call(ce,{message:e,reasoning:t,defaultPreview:d,isActive:i,config:r!=null?r:{}});Xb(R,pe)||(R.textContent=d),R.style.display=""}if(!s&&i&&o.activeMinHeight&&(n.style.minHeight=o.activeMinHeight),!a)return n.append(l,R),n;let W=h("div","persona-border-t persona-border-gray-200 persona-bg-gray-50 persona-px-4 persona-py-3");W.style.display=s?"":"none";let V=t.chunks.join(""),ne=h("div","persona-whitespace-pre-wrap persona-text-xs persona-leading-snug persona-text-persona-muted");return ne.textContent=V||(t.status==="complete"?"No additional context was shared.":"Waiting for details\u2026"),W.appendChild(ne),(()=>{if(l.setAttribute("aria-expanded",s?"true":"false"),B){B.innerHTML="";let Re=ve(s?"chevron-up":"chevron-down",16,"currentColor",2);Re?B.appendChild(Re):B.textContent=s?"Hide":"Show"}W.style.display=s?"":"none",R.style.display=s?"none":R.textContent||R.childNodes.length?"":"none"})(),n.append(l,R,W),n};var Pa=new Set,Kb=(e,r)=>r==null?!1:typeof r=="string"?(e.textContent=r,!0):(e.appendChild(r),!0),Yb=(e,r)=>{var a;let t=e.toolCall;if(!t)return"";let n=((a=t.chunks)!=null?a:[]).join("").trim();if(n)return n.split(/\r?\n/).map(i=>i.trim()).filter(Boolean).slice(-r).join(`
|
|
65
65
|
`);let o=Ca(t.args).trim();return o?o.split(/\r?\n/).map(s=>s.trim()).filter(Boolean).slice(0,r).join(`
|
|
66
|
-
`):""},Qb=(e,r)=>{var u,p,f,m,C;let t=e.toolCall,n=(u=r==null?void 0:r.features)==null?void 0:u.toolCallDisplay,o=(p=n==null?void 0:n.collapsedMode)!=null?p:"tool-call",a=Yb(e,(f=n==null?void 0:n.previewMaxLines)!=null?f:3),s=t?Mg(t):"";if(!t)return{summary:s,previewText:a,isActive:!1};let i=t.status!=="complete",d=(m=r==null?void 0:r.toolCall)!=null?m:{},l=s;return o==="tool-name"?l=((C=t.name)==null?void 0:C.trim())||s:o==="tool-preview"&&a&&(l=a),i&&d.activeTextTemplate?l=ed(t,d.activeTextTemplate,l):!i&&d.completeTextTemplate&&(l=ed(t,d.completeTextTemplate,l)),{summary:l,previewText:a,isActive:i}},ph=(e,r,t)=>{var u;let n=Pa.has(e),o=(u=t==null?void 0:t.toolCall)!=null?u:{},a=r.querySelector('button[data-expand-header="true"]'),s=r.querySelector(".persona-border-t"),i=r.querySelector('[data-persona-collapsed-preview="tool"]');if(!a||!s)return;a.setAttribute("aria-expanded",n?"true":"false");let d=a.querySelector(".persona-ml-auto"),l=d==null?void 0:d.querySelector(":scope > .persona-flex.persona-items-center");if(l){l.innerHTML="";let p=o.toggleTextColor||o.headerTextColor||"currentColor",f=ve(n?"chevron-up":"chevron-down",16,p,2);f?l.appendChild(f):l.textContent=n?"Hide":"Show"}s.style.display=n?"":"none",i&&(i.style.display=n?"none":i.textContent||i.childNodes.length?"":"none")},xp=(e,r)=>{var V,ne,ue,We,Ke,xe,me,Re,Ge;let t=e.toolCall,n=(V=r==null?void 0:r.toolCall)!=null?V:{},o=h("div",["persona-message-bubble","persona-tool-bubble","persona-w-full","persona-max-w-[85%]","persona-rounded-2xl","persona-bg-persona-surface","persona-border","persona-border-persona-message-border","persona-text-persona-primary","persona-shadow-sm","persona-overflow-hidden","persona-px-0","persona-py-0"].join(" "));if(o.id=`bubble-${e.id}`,o.setAttribute("data-message-id",e.id),n.backgroundColor&&(o.style.backgroundColor=n.backgroundColor),n.borderColor&&(o.style.borderColor=n.borderColor),n.borderWidth&&(o.style.borderWidth=n.borderWidth),n.borderRadius&&(o.style.borderRadius=n.borderRadius),!t)return o;let a=(ue=(ne=r==null?void 0:r.features)==null?void 0:ne.toolCallDisplay)!=null?ue:{},s=a.expandable!==!1,i=s&&Pa.has(e.id),{summary:d,previewText:l,isActive:u}=Qb(e,r),p=h("button",s?"persona-flex persona-w-full persona-items-center persona-justify-between persona-gap-3 persona-bg-transparent persona-px-4 persona-py-3 persona-text-left persona-cursor-pointer persona-border-none":"persona-flex persona-w-full persona-items-center persona-justify-between persona-gap-3 persona-bg-transparent persona-px-4 persona-py-3 persona-text-left persona-cursor-default persona-border-none");p.type="button",s&&(p.setAttribute("aria-expanded",i?"true":"false"),p.setAttribute("data-expand-header","true")),p.setAttribute("data-bubble-type","tool"),n.headerBackgroundColor&&(p.style.backgroundColor=n.headerBackgroundColor),n.headerPaddingX&&(p.style.paddingLeft=n.headerPaddingX,p.style.paddingRight=n.headerPaddingX),n.headerPaddingY&&(p.style.paddingTop=n.headerPaddingY,p.style.paddingBottom=n.headerPaddingY);let f=h("div","persona-flex persona-flex-col persona-text-left"),m=h("span","persona-text-xs persona-text-persona-primary");n.headerTextColor&&(m.style.color=n.headerTextColor);let C=String((We=t.startedAt)!=null?We:Date.now()),w=()=>{let Y=h("span","");return Y.setAttribute("data-tool-elapsed",C),Y.textContent=gs(t),Y},k=(xe=n.renderCollapsedSummary)==null?void 0:xe.call(n,{message:e,toolCall:t,defaultSummary:d,previewText:l,collapsedMode:(Ke=a.collapsedMode)!=null?Ke:"tool-call",isActive:u,config:r!=null?r:{},elapsed:gs(t),createElapsedElement:w});typeof k=="string"&&k.trim()?(m.textContent=k,f.appendChild(m)):k instanceof HTMLElement?f.appendChild(k):(m.textContent=d,f.appendChild(m));let T=(me=a.loadingAnimation)!=null?me:"none",S=n.activeTextTemplate,E=n.completeTextTemplate,v=u?S:E,b=k instanceof HTMLElement,y=(Y,Ee,G)=>{let ce=G;for(let de of Ee){let pe=h("span","persona-tool-char");pe.style.setProperty("--char-index",String(ce)),pe.textContent=de===" "?"\xA0":de,Y.appendChild(pe),ce++}return ce},M=(Y,Ee)=>{var pe;m.textContent="";let G=((pe=t.name)==null?void 0:pe.trim())||"tool",ce=Ci(Y,G),de=0;for(let He of ce){let Ye=He.styles.length>0?(()=>{let J=h("span",He.styles.map(ie=>`persona-tool-text-${ie}`).join(" "));return m.appendChild(J),J})():m;if(He.isDuration&&u)Ye.appendChild(w());else{let J=He.isDuration?gs(t):He.text;Ee?de=y(Ye,J,de):Ye.appendChild(document.createTextNode(J))}}};if(!b)if(u&&T!=="none"){let Y=(Re=n.loadingAnimationDuration)!=null?Re:2e3;if(m.setAttribute("data-preserve-animation","true"),T==="pulse")m.classList.add("persona-tool-loading-pulse"),m.style.setProperty("--persona-tool-anim-duration",`${Y}ms`),v&&M(v,!1);else if(m.classList.add(`persona-tool-loading-${T}`),m.style.setProperty("--persona-tool-anim-duration",`${Y}ms`),T==="shimmer-color"&&(n.loadingAnimationColor&&m.style.setProperty("--persona-tool-anim-color",n.loadingAnimationColor),n.loadingAnimationSecondaryColor&&m.style.setProperty("--persona-tool-anim-secondary-color",n.loadingAnimationSecondaryColor)),v)M(v,!0);else{let Ee=m.textContent||d;m.textContent="",y(m,Ee,0)}}else v&&M(v,!1);let H=null;if(s){H=h("div","persona-flex persona-items-center");let Y=n.toggleTextColor||n.headerTextColor||"currentColor",Ee=ve(i?"chevron-up":"chevron-down",16,Y,2);Ee?H.appendChild(Ee):H.textContent=i?"Hide":"Show";let G=h("div","persona-flex persona-items-center persona-gap-2 persona-ml-auto");G.append(H),p.append(f,G)}else p.append(f);let B=h("div","persona-px-4 persona-py-3 persona-text-xs persona-leading-snug persona-text-persona-muted");if(B.setAttribute("data-persona-collapsed-preview","tool"),B.style.display="none",B.style.whiteSpace="pre-wrap",!i&&u&&a.activePreview&&l){let Y=(Ge=n.renderCollapsedPreview)==null?void 0:Ge.call(n,{message:e,toolCall:t,defaultPreview:l,isActive:u,config:r!=null?r:{}});Kb(B,Y)||(B.textContent=l),B.style.display=""}if(!i&&u&&a.activeMinHeight&&(o.style.minHeight=a.activeMinHeight),!s)return o.append(p,B),o;let R=h("div","persona-border-t persona-border-gray-200 persona-bg-gray-50 persona-space-y-3 persona-px-4 persona-py-3");if(R.style.display=i?"":"none",n.contentBackgroundColor&&(R.style.backgroundColor=n.contentBackgroundColor),n.contentTextColor&&(R.style.color=n.contentTextColor),n.contentPaddingX&&(R.style.paddingLeft=n.contentPaddingX,R.style.paddingRight=n.contentPaddingX),n.contentPaddingY&&(R.style.paddingTop=n.contentPaddingY,R.style.paddingBottom=n.contentPaddingY),t.name){let Y=h("div","persona-text-xs persona-text-persona-muted persona-italic");n.contentTextColor?Y.style.color=n.contentTextColor:n.headerTextColor&&(Y.style.color=n.headerTextColor),Y.textContent=t.name,R.appendChild(Y)}if(t.args!==void 0){let Y=h("div","persona-space-y-1"),Ee=h("div","persona-text-xs persona-text-persona-muted");n.labelTextColor&&(Ee.style.color=n.labelTextColor),Ee.textContent="Arguments";let G=h("pre","persona-max-h-48 persona-overflow-auto persona-whitespace-pre-wrap persona-rounded-lg persona-border persona-border-gray-100 persona-bg-white persona-px-3 persona-py-2 persona-text-xs persona-text-persona-primary");G.style.fontSize="0.75rem",G.style.lineHeight="1rem",n.codeBlockBackgroundColor&&(G.style.backgroundColor=n.codeBlockBackgroundColor),n.codeBlockBorderColor&&(G.style.borderColor=n.codeBlockBorderColor),n.codeBlockTextColor&&(G.style.color=n.codeBlockTextColor),G.textContent=Ca(t.args),Y.append(Ee,G),R.appendChild(Y)}if(t.chunks&&t.chunks.length){let Y=h("div","persona-space-y-1"),Ee=h("div","persona-text-xs persona-text-persona-muted");n.labelTextColor&&(Ee.style.color=n.labelTextColor),Ee.textContent="Activity";let G=h("pre","persona-max-h-48 persona-overflow-auto persona-whitespace-pre-wrap persona-rounded-lg persona-border persona-border-gray-100 persona-bg-white persona-px-3 persona-py-2 persona-text-xs persona-text-persona-primary");G.style.fontSize="0.75rem",G.style.lineHeight="1rem",n.codeBlockBackgroundColor&&(G.style.backgroundColor=n.codeBlockBackgroundColor),n.codeBlockBorderColor&&(G.style.borderColor=n.codeBlockBorderColor),n.codeBlockTextColor&&(G.style.color=n.codeBlockTextColor),G.textContent=t.chunks.join(""),Y.append(Ee,G),R.appendChild(Y)}if(t.status==="complete"&&t.result!==void 0){let Y=h("div","persona-space-y-1"),Ee=h("div","persona-text-xs persona-text-persona-muted");n.labelTextColor&&(Ee.style.color=n.labelTextColor),Ee.textContent="Result";let G=h("pre","persona-max-h-48 persona-overflow-auto persona-whitespace-pre-wrap persona-rounded-lg persona-border persona-border-gray-100 persona-bg-white persona-px-3 persona-py-2 persona-text-xs persona-text-persona-primary");G.style.fontSize="0.75rem",G.style.lineHeight="1rem",n.codeBlockBackgroundColor&&(G.style.backgroundColor=n.codeBlockBackgroundColor),n.codeBlockBorderColor&&(G.style.borderColor=n.codeBlockBorderColor),n.codeBlockTextColor&&(G.style.color=n.codeBlockTextColor),G.textContent=Ca(t.result),Y.append(Ee,G),R.appendChild(Y)}if(t.status==="complete"&&typeof t.duration=="number"){let Y=h("div","persona-text-xs persona-text-persona-muted");n.contentTextColor&&(Y.style.color=n.contentTextColor),Y.textContent=`Duration: ${t.duration}ms`,R.appendChild(Y)}return(()=>{if(p.setAttribute("aria-expanded",i?"true":"false"),H){H.innerHTML="";let Y=n.toggleTextColor||n.headerTextColor||"currentColor",Ee=ve(i?"chevron-up":"chevron-down",16,Y,2);Ee?H.appendChild(Ee):H.textContent=i?"Hide":"Show"}R.style.display=i?"":"none",B.style.display=i?"none":B.textContent||B.childNodes.length?"":"none"})(),o.append(p,B,R),o};var ko=Bl(hi(),1);var bp="ask_user_question",yp=8,Ia="data-persona-ask-sheet-for",Zb="Other",e0="Other\u2026",fh="Type your own answer here",mh="Send",t0="Next",r0="Back",n0="Submit all",o0="Skip",a0=3,Cp="data-ask-current-index",wp="data-ask-question-count",gh="data-ask-answers",vp="data-ask-grouped",hh="data-ask-layout",s0=e=>e.layout==="pills"?"pills":"rows",i0=e=>e.getAttribute(hh)==="pills"?"pills":"rows",uh=!1,xh=e=>e.replace(/["\\]/g,"\\$&"),ao=e=>e.variant==="tool"&&!!e.toolCall&&e.toolCall.name===bp,ul=e=>{var r,t;return(t=(r=e==null?void 0:e.features)==null?void 0:r.askUserQuestion)!=null?t:{}},so=e=>{let r=e.toolCall;if(!r)return{payload:null,complete:!1};let t=r.status==="complete";if(r.args&&typeof r.args=="object")return{payload:r.args,complete:t};let n=r.chunks;if(!n||n.length===0)return{payload:null,complete:t};try{let o=n.join(""),a=(0,ko.parse)(o,ko.STR|ko.OBJ|ko.ARR);if(a&&typeof a=="object")return{payload:a,complete:t}}catch{}return{payload:null,complete:t}},Rs=e=>{let r=Array.isArray(e==null?void 0:e.questions)?e.questions:[];return r.length>yp&&!uh&&(uh=!0,typeof console!="undefined"&&console.warn(`[AgentWidget] ask_user_question received ${r.length} questions; truncating to ${yp}.`)),r.slice(0,yp)},l0=e=>{var r;return(r=Rs(e)[0])!=null?r:null},d0=(e,r)=>{var t;return(t=Rs(e)[r])!=null?t:null},yh=(e,r)=>{let t=r.styles;t&&(t.sheetBackground&&e.style.setProperty("--persona-ask-sheet-bg",t.sheetBackground),t.sheetBorder&&e.style.setProperty("--persona-ask-sheet-border",t.sheetBorder),t.sheetShadow&&e.style.setProperty("--persona-ask-sheet-shadow",t.sheetShadow),t.pillBackground&&e.style.setProperty("--persona-ask-pill-bg",t.pillBackground),t.pillBackgroundSelected&&e.style.setProperty("--persona-ask-pill-bg-selected",t.pillBackgroundSelected),t.pillTextColor&&e.style.setProperty("--persona-ask-pill-fg",t.pillTextColor),t.pillTextColorSelected&&e.style.setProperty("--persona-ask-pill-fg-selected",t.pillTextColorSelected),t.pillBorderRadius&&e.style.setProperty("--persona-ask-pill-radius",t.pillBorderRadius),t.customInputBackground&&e.style.setProperty("--persona-ask-input-bg",t.customInputBackground))},bh=(e,r,t)=>{if(e!=="rows")return null;let n=h("span","persona-ask-row-affordance");if(n.setAttribute("aria-hidden","true"),r){let o=h("span","persona-ask-row-check");n.appendChild(o)}else{let o=h("span","persona-ask-row-badge");o.textContent=String(t+1),n.appendChild(o)}return n},c0=(e,r,t,n)=>{let a=h("button",t==="rows"?"persona-ask-pill persona-ask-row persona-pointer-events-auto":"persona-ask-pill persona-pointer-events-auto");if(a.type="button",a.setAttribute("role",n?"checkbox":"button"),a.setAttribute("aria-pressed","false"),a.setAttribute("data-ask-user-action","pick"),a.setAttribute("data-option-index",String(r)),a.setAttribute("data-option-label",e.label),t==="rows"){let s=h("span","persona-ask-row-content"),i=h("span","persona-ask-row-label");if(i.textContent=e.label,s.appendChild(i),e.description){let l=h("span","persona-ask-row-description");l.textContent=e.description,s.appendChild(l)}a.appendChild(s);let d=bh(t,n,r);d&&a.appendChild(d)}else a.textContent=e.label,e.description&&(a.title=e.description);return a},p0=e=>{let t=h("span",e==="rows"?"persona-ask-pill persona-ask-row persona-ask-pill-skeleton persona-pointer-events-none":"persona-ask-pill persona-ask-pill-skeleton persona-pointer-events-none");return t.setAttribute("aria-hidden","true"),t},u0=(e,r,t,n)=>{var u,p,f;let a=h("div",n==="rows"?"persona-ask-pills persona-ask-pills--rows persona-flex persona-flex-col persona-gap-2":"persona-ask-pills persona-flex persona-flex-wrap persona-gap-2");a.setAttribute("role","group"),a.setAttribute("data-ask-pill-list","true");let s=!!(e!=null&&e.multiSelect),d=(Array.isArray(e==null?void 0:e.options)?e.options:[]).filter(m=>m&&typeof m.label=="string"&&m.label.length>0);if(d.length===0&&!t){for(let m=0;m<a0;m++)a.appendChild(p0(n));return a}if(d.forEach((m,C)=>{a.appendChild(c0(m,C,n,s))}),(e==null?void 0:e.allowFreeText)!==!1){let m=n==="rows"?Zb:e0;if(n==="rows"){let C=h("div","persona-ask-pill persona-ask-row persona-ask-row--other persona-ask-pill-custom persona-pointer-events-auto");C.setAttribute("data-ask-user-action","focus-free-text"),C.setAttribute("data-option-index",String(d.length)),C.setAttribute("data-ask-other-row","true");let w=h("span","persona-ask-row-content"),k=document.createElement("input");k.type="text",k.className="persona-ask-row-input persona-flex-1 persona-pointer-events-auto",k.placeholder=(u=r.freeTextPlaceholder)!=null?u:fh,k.setAttribute("data-ask-free-text-input","true"),k.setAttribute("aria-label",(p=r.freeTextLabel)!=null?p:m),w.appendChild(k),C.appendChild(w);let T=bh(n,s,d.length);T&&C.appendChild(T),a.appendChild(C)}else{let C=h("button","persona-ask-pill persona-ask-pill-custom persona-pointer-events-auto");C.type="button",C.setAttribute("data-ask-user-action","open-free-text"),C.textContent=(f=r.freeTextLabel)!=null?f:m,a.appendChild(C)}}return a},Ch=(e,r)=>{var a,s;let n=h("div",r==="rows"?"persona-ask-free-text persona-ask-free-text--rows persona-flex persona-gap-2 persona-mt-2":"persona-ask-free-text persona-hidden persona-flex persona-gap-2 persona-mt-2");n.setAttribute("data-ask-free-text-row","true");let o=document.createElement("input");if(o.type="text",o.className="persona-ask-free-text-input persona-flex-1 persona-pointer-events-auto",o.placeholder=(a=e.freeTextPlaceholder)!=null?a:fh,o.setAttribute("data-ask-free-text-input","true"),n.appendChild(o),r!=="rows"){let i=h("button","persona-ask-free-text-submit persona-pointer-events-auto");i.type="button",i.textContent=(s=e.submitLabel)!=null?s:mh,i.setAttribute("data-ask-user-action","submit-free-text"),n.appendChild(i)}return n},f0=e=>{var n;let r=h("div","persona-ask-multi-actions persona-flex persona-justify-end persona-mt-2");r.setAttribute("data-ask-multi-actions","true");let t=h("button","persona-ask-multi-submit persona-pointer-events-auto");return t.type="button",t.textContent=(n=e.submitLabel)!=null?n:mh,t.setAttribute("data-ask-user-action","submit-multi"),t.disabled=!0,r.appendChild(t),r},m0=(e,r,t)=>{var l,u,p,f;let n=h("div","persona-ask-nav persona-flex persona-justify-between persona-items-center persona-gap-2 persona-mt-2");n.setAttribute("data-ask-nav-row","true");let o=h("button","persona-ask-nav-back persona-pointer-events-auto");o.type="button",o.textContent=(l=t.backLabel)!=null?l:r0,o.setAttribute("data-ask-user-action","back"),o.disabled=e===0,n.appendChild(o);let a=h("div","persona-ask-nav-right persona-flex persona-items-center persona-gap-2"),s=h("button","persona-ask-nav-skip persona-pointer-events-auto");s.type="button",s.textContent=(u=t.skipLabel)!=null?u:o0,s.setAttribute("data-ask-user-action","skip"),a.appendChild(s);let i=h("button","persona-ask-nav-next persona-pointer-events-auto");i.type="button";let d=e===r-1;return i.textContent=d?(p=t.submitAllLabel)!=null?p:n0:(f=t.nextLabel)!=null?f:t0,i.setAttribute("data-ask-user-action",d?"submit-all":"next"),i.disabled=!0,a.appendChild(i),n.appendChild(a),n},aa=e=>{let r=e.getAttribute(gh);if(!r)return{};try{let t=JSON.parse(r);return t&&typeof t=="object"?t:{}}catch{return{}}},wh=(e,r)=>{e.setAttribute(gh,JSON.stringify(r))},An=e=>{var t;let r=Number((t=e.getAttribute(Cp))!=null?t:"0");return Number.isFinite(r)?Math.max(0,Math.floor(r)):0},g0=(e,r)=>{e.setAttribute(Cp,String(Math.max(0,Math.floor(r))))},Ra=e=>{var t;let r=Number((t=e.getAttribute(wp))!=null?t:"1");return Number.isFinite(r)?Math.max(1,Math.floor(r)):1},Eo=e=>e.getAttribute(vp)==="true",h0=(e,r)=>{var o;let t=(o=e.agentMetadata)==null?void 0:o.askUserQuestionAnswers;if(!t||typeof t!="object")return{};let n={};return r.forEach((a,s)=>{let i=typeof(a==null?void 0:a.question)=="string"?a.question:"";if(i&&Object.prototype.hasOwnProperty.call(t,i)){let d=t[i];(typeof d=="string"||Array.isArray(d))&&(n[s]=d)}}),n},x0=(e,r)=>{var n;let t=(n=e.agentMetadata)==null?void 0:n.askUserQuestionIndex;return typeof t!="number"||!Number.isFinite(t)?0:Math.max(0,Math.min(r-1,Math.floor(t)))},fl=(e,r)=>{let{payload:t}=so(r),n=Rs(t),o=aa(e),a={},s=new Set;return n.forEach((i,d)=>{let l=typeof(i==null?void 0:i.question)=="string"?i.question:"";l&&(s.has(l)&&typeof console!="undefined"&&console.warn(`[AgentWidget] ask_user_question has duplicate question text "${l}"; later answer wins.`),s.add(l),Object.prototype.hasOwnProperty.call(o,d)&&(a[l]=o[d]))}),a},vh=e=>{let r=aa(e),t=An(e),n=r[t],o=new Set;typeof n=="string"?o.add(n):Array.isArray(n)&&n.forEach(d=>o.add(d));let a=e.querySelectorAll('[data-ask-user-action="pick"][data-option-label]');a.forEach(d=>{var p;let l=(p=d.getAttribute("data-option-label"))!=null?p:"",u=o.has(l);d.setAttribute("aria-pressed",u?"true":"false"),d.classList.toggle("persona-ask-pill-selected",u)});let s=new Set(Array.from(a).map(d=>{var l;return(l=d.getAttribute("data-option-label"))!=null?l:""})),i=e.querySelector('[data-ask-free-text-input="true"]');if(i)if(typeof n=="string"&&n.length>0&&!s.has(n)){i.value=n;let d=i.closest('[data-ask-free-text-row="true"]');d==null||d.classList.remove("persona-hidden")}else i.value=""},Ah=e=>{if(!Eo(e))return;let r=aa(e),t=An(e),n=r[t],o=typeof n=="string"&&n.length>0||Array.isArray(n)&&n.length>0,a=e.querySelector('[data-ask-user-action="next"], [data-ask-user-action="submit-all"]');a&&(a.disabled=!o);let s=e.querySelector('[data-ask-user-action="submit-multi"]');if(s){let i=Array.from(e.querySelectorAll('[aria-pressed="true"][data-option-label]'));s.disabled=i.length===0}},Ap=(e,r,t)=>{let n=ul(t),o=i0(e),{payload:a,complete:s}=so(r),i=Eo(e),d=An(e),l=Ra(e),u=i?d0(a,d):l0(a),p=!!(u!=null&&u.multiSelect),f=e.querySelector('[data-ask-step-inline="true"]');f&&(f.textContent=i?`${d+1}/${l}`:"");let m=e.querySelector('[data-ask-stepper="true"]');m&&m.remove();let C=e.querySelector('[data-ask-question="true"]');if(C){let S=typeof(u==null?void 0:u.question)=="string"?u.question:"";C.textContent=S,C.classList.toggle("persona-ask-question-skeleton",!S&&!s)}let w=e.querySelector('[data-ask-pill-list="true"]');if(w){let S=u0(u,n,s,o);w.replaceWith(S)}if(o!=="rows"){let S=e.querySelector('[data-ask-free-text-row="true"]');S&&S.replaceWith(Ch(n,o))}let k=e.querySelector('[data-ask-multi-actions="true"]');!i&&p&&!k?e.appendChild(f0(n)):(!p||i)&&k&&k.remove(),e.setAttribute("data-multi-select",p?"true":"false");let T=e.querySelector('[data-ask-nav-row="true"]');if(i){let S=m0(d,l,n);T?T.replaceWith(S):e.appendChild(S)}else T&&T.remove();vh(e),Ah(e)},y0=(e,r,t)=>{let n=ul(r),o=s0(n),a=e.toolCall.id,s=Rs(t),i=Math.max(1,s.length),d=i>1,l=h0(e,s),u=d?x0(e,i):0,p=h("div",["persona-ask-sheet",`persona-ask-sheet--${o}`,"persona-pointer-events-auto","persona-ask-sheet-enter"].join(" "));p.setAttribute(Ia,a),p.setAttribute("data-tool-call-id",a),p.setAttribute("data-message-id",e.id),p.setAttribute(wp,String(i)),p.setAttribute(Cp,String(u)),p.setAttribute(vp,d?"true":"false"),p.setAttribute(hh,o),wh(p,l),p.setAttribute("role","group"),p.setAttribute("aria-label","Suggested answers"),n.slideInMs!==void 0&&p.style.setProperty("--persona-ask-sheet-duration",`${n.slideInMs}ms`),yh(p,n);let f=h("div","persona-ask-sheet-header persona-flex persona-items-center persona-gap-3"),m=h("div","persona-ask-sheet-question persona-flex-1");m.setAttribute("data-ask-question","true"),m.textContent="",f.appendChild(m);let C=h("span","persona-ask-sheet-step-inline");C.setAttribute("data-ask-step-inline","true"),C.textContent="",f.appendChild(C),p.appendChild(f);let k=h("div",o==="rows"?"persona-ask-pills persona-ask-pills--rows persona-flex persona-flex-col persona-gap-2":"persona-ask-pills persona-flex persona-flex-wrap persona-gap-2");return k.setAttribute("data-ask-pill-list","true"),k.setAttribute("role","group"),p.appendChild(k),o!=="rows"&&p.appendChild(Ch(n,o)),Ap(p,e,r),requestAnimationFrame(()=>{requestAnimationFrame(()=>p.classList.remove("persona-ask-sheet-enter"))}),p},b0=(e,r,t)=>{let{payload:n}=so(r),o=Math.max(1,Rs(n).length);o>Ra(e)&&(e.setAttribute(wp,String(o)),o>1&&!Eo(e)&&e.setAttribute(vp,"true")),Ap(e,r,t)},Sh=(e,r)=>{let t=h("div","persona-ask-stub persona-inline-flex persona-items-center persona-gap-2");t.id=`bubble-${e.id}`,t.setAttribute("data-message-id",e.id),t.setAttribute("data-bubble-type","ask-user-question");let n=ul(r);yh(t,n);let o=h("span","persona-ask-stub-label"),{complete:a}=so(e);return o.textContent=a?"Awaiting your response\u2026":"Preparing options\u2026",t.appendChild(o),t},Ha=(e,r,t)=>{if(!t||!ao(e)||ul(r).enabled===!1)return;let o=e.toolCall.id;t.querySelectorAll(`[${Ia}]`).forEach(l=>{l.getAttribute(Ia)!==o&&l.remove()});let s=t.querySelector(`[${Ia}="${xh(o)}"]`);if(s){b0(s,e,r);return}let{payload:i}=so(e),d=y0(e,r,i);t.appendChild(d)},Mo=(e,r)=>{if(!e)return;let t=r?`[${Ia}="${xh(r)}"]`:`[${Ia}]`;e.querySelectorAll(t).forEach(o=>{o.classList.add("persona-ask-sheet-leave");let a=Number.parseInt(getComputedStyle(o).getPropertyValue("--persona-ask-sheet-duration")||"180",10);setTimeout(()=>o.remove(),Number.isFinite(a)?a:180)})},Sp=e=>Array.from(e.querySelectorAll('[aria-pressed="true"][data-option-label]')).map(r=>r.getAttribute("data-option-label")).filter(r=>typeof r=="string"&&r.length>0),Lo=(e,r)=>{let t=aa(e),n=An(e);typeof r=="string"&&r.length===0||Array.isArray(r)&&r.length===0?delete t[n]:t[n]=r,wh(e,t),vh(e),Ah(e)},ml=(e,r,t,n)=>{let o=Ra(e),a=Math.max(0,Math.min(o-1,n));g0(e,a),Ap(e,r,t)};var Tp=(e,r)=>{var w,k,T,S,E,v,b,y,M,H,B,R;let t=e.approval,n=(r==null?void 0:r.approval)!==!1?r==null?void 0:r.approval:void 0,o=(t==null?void 0:t.status)==="pending",a=h("div",["persona-approval-bubble","persona-w-full","persona-max-w-[85%]","persona-rounded-2xl","persona-border","persona-shadow-sm","persona-overflow-hidden"].join(" "));if(a.id=`bubble-${e.id}`,a.setAttribute("data-message-id",e.id),a.style.backgroundColor=(w=n==null?void 0:n.backgroundColor)!=null?w:"var(--persona-approval-bg, #fefce8)",a.style.borderColor=(k=n==null?void 0:n.borderColor)!=null?k:"var(--persona-approval-border, #fef08a)",!t)return a;let s=h("div","persona-flex persona-items-start persona-gap-3 persona-px-4 persona-py-3"),i=h("div","persona-flex-shrink-0 persona-mt-0.5");i.setAttribute("data-approval-icon","true");let d=t.status==="denied"?"shield-x":t.status==="timeout"?"shield-alert":"shield-check",l=t.status==="approved"?"var(--persona-feedback-success, #16a34a)":t.status==="denied"?"var(--persona-feedback-error, #dc2626)":t.status==="timeout"?"var(--persona-feedback-warning, #ca8a04)":(T=n==null?void 0:n.titleColor)!=null?T:"currentColor",u=ve(d,20,l,2);u&&i.appendChild(u);let p=h("div","persona-flex-1 persona-min-w-0"),f=h("div","persona-flex persona-items-center persona-gap-2"),m=h("span","persona-text-sm persona-font-medium persona-text-persona-primary");if(n!=null&&n.titleColor&&(m.style.color=n.titleColor),m.textContent=(S=n==null?void 0:n.title)!=null?S:"Approval Required",f.appendChild(m),!o){let W=h("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded-full persona-text-xs persona-font-medium");W.setAttribute("data-approval-status",t.status),t.status==="approved"?(W.style.backgroundColor="var(--persona-palette-colors-success-100, #dcfce7)",W.style.color="var(--persona-palette-colors-success-700, #15803d)",W.textContent="Approved"):t.status==="denied"?(W.style.backgroundColor="var(--persona-palette-colors-error-100, #fee2e2)",W.style.color="var(--persona-palette-colors-error-700, #b91c1c)",W.textContent="Denied"):t.status==="timeout"&&(W.style.backgroundColor="var(--persona-palette-colors-warning-100, #fef3c7)",W.style.color="var(--persona-palette-colors-warning-700, #b45309)",W.textContent="Timeout"),f.appendChild(W)}p.appendChild(f);let C=h("p","persona-text-sm persona-mt-0.5 persona-text-persona-muted");if(n!=null&&n.descriptionColor&&(C.style.color=n.descriptionColor),C.textContent=t.description,p.appendChild(C),t.parameters){let W=h("pre","persona-mt-2 persona-text-xs persona-p-2 persona-rounded persona-overflow-x-auto persona-max-h-32 persona-bg-persona-container persona-text-persona-primary");n!=null&&n.parameterBackgroundColor&&(W.style.backgroundColor=n.parameterBackgroundColor),n!=null&&n.parameterTextColor&&(W.style.color=n.parameterTextColor),W.style.fontSize="0.75rem",W.style.lineHeight="1rem",W.textContent=Ca(t.parameters),p.appendChild(W)}if(o){let W=h("div","persona-flex persona-gap-2 persona-mt-2");W.setAttribute("data-approval-buttons","true");let V=h("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-border-none persona-cursor-pointer");V.type="button",V.style.backgroundColor=(E=n==null?void 0:n.approveButtonColor)!=null?E:"var(--persona-approval-approve-bg, #22c55e)",V.style.color=(v=n==null?void 0:n.approveButtonTextColor)!=null?v:"#ffffff",V.setAttribute("data-approval-action","approve");let ne=ve("shield-check",14,(b=n==null?void 0:n.approveButtonTextColor)!=null?b:"#ffffff",2);ne&&(ne.style.marginRight="4px",V.appendChild(ne));let ue=document.createTextNode((y=n==null?void 0:n.approveLabel)!=null?y:"Approve");V.appendChild(ue);let We=h("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-cursor-pointer");We.type="button",We.style.backgroundColor=(M=n==null?void 0:n.denyButtonColor)!=null?M:"transparent",We.style.color=(H=n==null?void 0:n.denyButtonTextColor)!=null?H:"var(--persona-feedback-error, #dc2626)",We.style.border=`1px solid ${n!=null&&n.denyButtonTextColor?n.denyButtonTextColor:"var(--persona-palette-colors-error-200, #fca5a5)"}`,We.setAttribute("data-approval-action","deny");let Ke=ve("shield-x",14,(B=n==null?void 0:n.denyButtonTextColor)!=null?B:"var(--persona-feedback-error, #dc2626)",2);Ke&&(Ke.style.marginRight="4px",We.appendChild(Ke));let xe=document.createTextNode((R=n==null?void 0:n.denyLabel)!=null?R:"Deny");We.appendChild(xe),W.append(V,We),p.appendChild(W)}return s.append(i,p),a.appendChild(s),a};var Th=e=>{let r=[];return{buttons:r,render:(n,o,a,s,i)=>{if(e.innerHTML="",r.length=0,!n||!n.length||(s!=null?s:o?o.getMessages():[]).some(m=>m.role==="user"))return;let u=document.createDocumentFragment(),p=o?o.isStreaming():!1,f=m=>{switch(m){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};n.forEach(m=>{let C=h("button","persona-rounded-button persona-bg-persona-surface persona-px-3 persona-py-1.5 persona-text-xs persona-font-medium persona-text-persona-primary hover:persona-opacity-80 persona-cursor-pointer persona-border persona-border-persona-border");C.type="button",C.textContent=m,C.disabled=p,i!=null&&i.fontFamily&&(C.style.fontFamily=f(i.fontFamily)),i!=null&&i.fontWeight&&(C.style.fontWeight=i.fontWeight),i!=null&&i.paddingX&&(C.style.paddingLeft=i.paddingX,C.style.paddingRight=i.paddingX),i!=null&&i.paddingY&&(C.style.paddingTop=i.paddingY,C.style.paddingBottom=i.paddingY),C.addEventListener("click",()=>{!o||o.isStreaming()||(a.value="",o.sendMessage(m))}),u.appendChild(C),r.push(C)}),e.appendChild(u)}}};var Hs=class{constructor(r=2e3,t=null){this.head=0;this.count=0;this.totalCaptured=0;this.eventTypesSet=new Set;this.maxSize=r,this.buffer=new Array(r),this.store=t}push(r){var t;this.buffer[this.head]=r,this.head=(this.head+1)%this.maxSize,this.count<this.maxSize&&this.count++,this.totalCaptured++,this.eventTypesSet.add(r.type),(t=this.store)==null||t.put(r)}getAll(){return this.count===0?[]:this.count<this.maxSize?this.buffer.slice(0,this.count):[...this.buffer.slice(this.head,this.maxSize),...this.buffer.slice(0,this.head)]}async restore(){if(!this.store)return 0;let r=await this.store.getAll();if(r.length===0)return 0;let t=r.length>this.maxSize?r.slice(r.length-this.maxSize):r;for(let n of t)this.buffer[this.head]=n,this.head=(this.head+1)%this.maxSize,this.count<this.maxSize&&this.count++,this.eventTypesSet.add(n.type);return this.totalCaptured=r.length,t.length}getAllFromStore(){return this.store?this.store.getAll():Promise.resolve(this.getAll())}getRecent(r){let t=this.getAll();return r>=t.length?t:t.slice(t.length-r)}getSize(){return this.count}getTotalCaptured(){return this.totalCaptured}getEvictedCount(){return this.totalCaptured-this.count}clear(){var r;this.buffer=new Array(this.maxSize),this.head=0,this.count=0,this.totalCaptured=0,this.eventTypesSet.clear(),(r=this.store)==null||r.clear()}destroy(){var r;this.buffer=[],this.head=0,this.count=0,this.totalCaptured=0,this.eventTypesSet.clear(),(r=this.store)==null||r.destroy()}getEventTypes(){return Array.from(this.eventTypesSet)}};var Bs=class{constructor(r="persona-event-stream",t="events"){this.db=null;this.pendingWrites=[];this.flushScheduled=!1;this.isDestroyed=!1;this.dbName=r,this.storeName=t}open(){return new Promise((r,t)=>{try{let n=indexedDB.open(this.dbName,1);n.onupgradeneeded=()=>{let o=n.result;o.objectStoreNames.contains(this.storeName)||o.createObjectStore(this.storeName,{keyPath:"id"}).createIndex("timestamp","timestamp",{unique:!1})},n.onsuccess=()=>{this.db=n.result,r()},n.onerror=()=>{t(n.error)}}catch(n){t(n)}})}put(r){!this.db||this.isDestroyed||(this.pendingWrites.push(r),this.flushScheduled||(this.flushScheduled=!0,queueMicrotask(()=>this.flushWrites())))}putBatch(r){if(!(!this.db||this.isDestroyed||r.length===0))try{let n=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName);for(let o of r)n.put(o)}catch{}}getAll(){return new Promise((r,t)=>{if(!this.db){r([]);return}try{let s=this.db.transaction(this.storeName,"readonly").objectStore(this.storeName).index("timestamp").getAll();s.onsuccess=()=>{r(s.result)},s.onerror=()=>{t(s.error)}}catch(n){t(n)}})}getCount(){return new Promise((r,t)=>{if(!this.db){r(0);return}try{let a=this.db.transaction(this.storeName,"readonly").objectStore(this.storeName).count();a.onsuccess=()=>{r(a.result)},a.onerror=()=>{t(a.error)}}catch(n){t(n)}})}clear(){return new Promise((r,t)=>{if(!this.db){r();return}this.pendingWrites=[];try{let a=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).clear();a.onsuccess=()=>{r()},a.onerror=()=>{t(a.error)}}catch(n){t(n)}})}close(){this.db&&(this.db.close(),this.db=null)}destroy(){return this.isDestroyed=!0,this.pendingWrites=[],this.close(),new Promise((r,t)=>{try{let n=indexedDB.deleteDatabase(this.dbName);n.onsuccess=()=>{r()},n.onerror=()=>{t(n.error)}}catch(n){t(n)}})}flushWrites(){if(this.flushScheduled=!1,!this.db||this.isDestroyed||this.pendingWrites.length===0)return;let r=this.pendingWrites;this.pendingWrites=[];try{let n=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName);for(let o of r)n.put(o)}catch{}}};function Ba(e,r){r&&r.split(/\s+/).forEach(t=>t&&e.classList.add(t))}var C0={flow_:{bg:"var(--persona-palette-colors-success-100, #dcfce7)",text:"var(--persona-palette-colors-success-700, #166534)"},step_:{bg:"var(--persona-palette-colors-primary-100, #f5f5f5)",text:"var(--persona-palette-colors-primary-700, #0a0a0a)"},reason_:{bg:"var(--persona-palette-colors-warning-100, #ffedd5)",text:"var(--persona-palette-colors-warning-700, #9a3412)"},tool_:{bg:"var(--persona-palette-colors-purple-100, #f3e8ff)",text:"var(--persona-palette-colors-purple-700, #6b21a8)"},agent_:{bg:"var(--persona-palette-colors-teal-100, #ccfbf1)",text:"var(--persona-palette-colors-teal-700, #115e59)"},error:{bg:"var(--persona-palette-colors-error-100, #fecaca)",text:"var(--persona-palette-colors-error-700, #991b1b)"}},w0={bg:"var(--persona-palette-colors-gray-100, #f3f4f6)",text:"var(--persona-palette-colors-gray-600, #4b5563)"},v0=["flowName","stepName","reasoningText","text","name","tool","toolName"],A0=100;function S0(e,r){let t={...C0,...r};if(t[e])return t[e];for(let n of Object.keys(t))if(n.endsWith("_")&&e.startsWith(n))return t[n];return w0}function T0(e,r){return`+${((e-r)/1e3).toFixed(3)}s`}function k0(e){let r=new Date(e),t=String(r.getHours()).padStart(2,"0"),n=String(r.getMinutes()).padStart(2,"0"),o=String(r.getSeconds()).padStart(2,"0"),a=String(r.getMilliseconds()).padStart(3,"0");return`${t}:${n}:${o}.${a}`}function E0(e,r){try{let t=JSON.parse(e);if(typeof t!="object"||t===null)return null;for(let n of r){let o=n.split("."),a=t;for(let s of o)if(a&&typeof a=="object"&&a!==null)a=a[s];else{a=void 0;break}if(typeof a=="string"&&a.trim())return a.trim()}}catch{}return null}function M0(e){var r;return(r=navigator.clipboard)!=null&&r.writeText?navigator.clipboard.writeText(e):new Promise(t=>{let n=document.createElement("textarea");n.value=e,n.style.position="fixed",n.style.opacity="0",document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),t()})}function L0(e){let r;try{r=JSON.parse(e.payload)}catch{r=e.payload}return JSON.stringify({type:e.type,timestamp:new Date(e.timestamp).toISOString(),payload:r},null,2)}function P0(e,r,t){let n,o;try{o=JSON.parse(e.payload),n=JSON.stringify(o,null,2)}catch{o=e.payload,n=e.payload}let a=r.find(i=>i.renderEventStreamPayload);if(a!=null&&a.renderEventStreamPayload&&t){let i=a.renderEventStreamPayload({event:e,config:t,defaultRenderer:()=>s(),parsedPayload:o});if(i)return i}return s();function s(){let i=h("div","persona-bg-persona-container persona-border-t persona-border-persona-divider persona-px-3 persona-py-2 persona-ml-4 persona-mr-3 persona-mb-1 persona-rounded-b persona-overflow-auto persona-max-h-[300px]"),d=h("pre","persona-m-0 persona-whitespace-pre-wrap persona-break-all persona-text-[11px] persona-text-persona-secondary persona-font-mono");return d.textContent=n,i.appendChild(d),i}}function kp(e,r,t,n,o,a,s,i){var f;let d=o.has(e.id),l=h("div","persona-border-b persona-border-persona-divider persona-text-xs");Ba(l,(f=n.classNames)==null?void 0:f.eventRow);let u=s.find(m=>m.renderEventStreamRow);if(u!=null&&u.renderEventStreamRow&&i){let m=u.renderEventStreamRow({event:e,index:r,config:i,defaultRenderer:()=>p(),isExpanded:d,onToggleExpand:()=>a(e.id)});if(m)return l.appendChild(m),l}return l.appendChild(p()),l;function p(){var V,ne;let m=h("div",""),C=h("div","persona-flex persona-items-center persona-gap-2 persona-px-3 persona-py-3 hover:persona-bg-persona-container persona-cursor-pointer persona-group");C.setAttribute("data-event-id",e.id);let w=h("span","persona-flex-shrink-0 persona-text-persona-muted persona-w-4 persona-text-center persona-flex persona-items-center persona-justify-center"),k=ve(d?"chevron-down":"chevron-right","14px","currentColor",2);k&&w.appendChild(k);let T=h("span","persona-text-[11px] persona-text-persona-muted persona-whitespace-nowrap persona-flex-shrink-0 persona-font-mono persona-w-[70px]"),S=(V=n.timestampFormat)!=null?V:"relative";T.textContent=S==="relative"?T0(e.timestamp,t):k0(e.timestamp);let E=null;n.showSequenceNumbers!==!1&&(E=h("span","persona-text-[11px] persona-text-persona-muted persona-font-mono persona-flex-shrink-0 persona-w-[28px] persona-text-right"),E.textContent=String(r+1));let v=S0(e.type,n.badgeColors),b=h("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded persona-text-[11px] persona-font-mono persona-font-medium persona-whitespace-nowrap persona-flex-shrink-0 persona-border");b.style.backgroundColor=v.bg,b.style.color=v.text,b.style.borderColor=v.text+"50",b.textContent=e.type;let y=(ne=n.descriptionFields)!=null?ne:v0,M=E0(e.payload,y),H=null;M&&(H=h("span","persona-text-[11px] persona-text-persona-secondary persona-truncate persona-min-w-0"),H.textContent=M);let B=h("div","persona-flex-1 persona-min-w-0"),R=h("button","persona-text-persona-muted hover:persona-text-persona-primary persona-cursor-pointer persona-flex-shrink-0 persona-border-none persona-bg-transparent persona-p-0"),W=ve("clipboard","12px","currentColor",1.5);return W&&R.appendChild(W),R.addEventListener("click",async ue=>{ue.stopPropagation(),await M0(L0(e)),R.innerHTML="";let We=ve("check","12px","currentColor",1.5);We&&R.appendChild(We),setTimeout(()=>{R.innerHTML="";let Ke=ve("clipboard","12px","currentColor",1.5);Ke&&R.appendChild(Ke)},1500)}),C.appendChild(w),C.appendChild(T),E&&C.appendChild(E),C.appendChild(b),H&&C.appendChild(H),C.appendChild(B),C.appendChild(R),m.appendChild(C),d&&m.appendChild(P0(e,s,i)),m}}function kh(e){var m,C,w,k,T;let{buffer:r,getFullHistory:t,onClose:n,config:o,plugins:a=[]}=e,s=(m=o==null?void 0:o.features)==null?void 0:m.scrollToBottom,i=(s==null?void 0:s.enabled)!==!1,d=(C=s==null?void 0:s.iconName)!=null?C:"arrow-down",l=(w=s==null?void 0:s.label)!=null?w:"",u=(T=(k=o==null?void 0:o.features)==null?void 0:k.eventStream)!=null?T:{},p=a.find(S=>S.renderEventStreamView);if(p!=null&&p.renderEventStreamView&&o){let S=p.renderEventStreamView({config:o,events:r.getAll(),defaultRenderer:()=>f().element,onClose:n});if(S)return{element:S,update:()=>{},destroy:()=>{}}}return f();function f(){let S=u.classNames,E=h("div","persona-event-stream-view persona-flex persona-flex-col persona-flex-1 persona-min-h-0");Ba(E,S==null?void 0:S.panel);let v=[],b="",y="",M=null,H=[],B={},R=0,W=Ji(),V=0,ne=0,ue=!1,We=null,Ke=!1,xe=0,me=new Set,Re=new Map,Ge="",Y="",Ee=null,G,ce,de,pe,He;function Ye(){let F=h("div","persona-flex persona-flex-col persona-flex-shrink-0"),ye=h("div","persona-flex persona-items-center persona-gap-2 persona-px-4 persona-py-3 persona-pb-0 persona-border-persona-divider persona-bg-persona-surface persona-overflow-hidden");Ba(ye,S==null?void 0:S.headerBar);let be=h("span","persona-text-sm persona-font-medium persona-text-persona-primary persona-whitespace-nowrap");be.textContent="Events",G=h("span","persona-text-[11px] persona-font-mono persona-bg-persona-container persona-text-persona-muted persona-px-2 persona-py-0.5 persona-rounded persona-border persona-border-persona-border"),G.textContent="0";let it=h("div","persona-flex-1");ce=h("select","persona-text-xs persona-bg-persona-surface persona-border persona-border-persona-border persona-rounded persona-px-2.5 persona-py-1 persona-text-persona-primary persona-cursor-pointer");let Xe=h("option","");Xe.value="",Xe.textContent="All events",ce.appendChild(Xe),de=h("button","persona-inline-flex persona-items-center persona-gap-1.5 persona-rounded persona-text-xs persona-text-persona-muted hover:persona-bg-persona-container hover:persona-text-persona-primary persona-cursor-pointer persona-border persona-border-persona-border persona-bg-persona-surface persona-flex-shrink-0 persona-px-2.5 persona-py-1"),de.type="button",de.title="Copy All";let ar=ve("clipboard-copy","12px","currentColor",1.5);ar&&de.appendChild(ar);let Pt=h("span","persona-text-xs");Pt.textContent="Copy All",de.appendChild(Pt),ye.appendChild(be),ye.appendChild(G),ye.appendChild(it),ye.appendChild(ce),ye.appendChild(de);let kt=h("div","persona-relative persona-px-4 persona-py-2.5 persona-border-b persona-border-persona-divider persona-bg-persona-surface");Ba(kt,S==null?void 0:S.searchBar);let rt=ve("search","14px","var(--persona-muted, #9ca3af)",1.5),lt=h("span","persona-absolute persona-left-6 persona-top-1/2 persona--translate-y-1/2 persona-pointer-events-none persona-flex persona-items-center");rt&<.appendChild(rt),pe=h("input","persona-text-sm persona-bg-persona-surface persona-border persona-border-persona-border persona-rounded-md persona-pl-8 persona-pr-3 persona-py-1 persona-w-full persona-text-persona-primary"),Ba(pe,S==null?void 0:S.searchInput),pe.type="text",pe.placeholder="Search event payloads...",He=h("button","persona-absolute persona-right-5 persona-top-1/2 persona--translate-y-1/2 persona-text-persona-muted hover:persona-text-persona-primary persona-cursor-pointer persona-border-none persona-bg-transparent persona-p-0 persona-leading-none"),He.type="button",He.style.display="none";let rr=ve("x","12px","currentColor",2);return rr&&He.appendChild(rr),kt.appendChild(lt),kt.appendChild(pe),kt.appendChild(He),F.appendChild(ye),F.appendChild(kt),F}let J,ie=a.find(F=>F.renderEventStreamToolbar);if(ie!=null&&ie.renderEventStreamToolbar&&o){let F=ie.renderEventStreamToolbar({config:o,defaultRenderer:()=>Ye(),eventCount:r.getSize(),filteredCount:0,onFilterChange:ye=>{b=ye,ae(),Qt()},onSearchChange:ye=>{y=ye,ae(),Qt()}});J=F!=null?F:Ye()}else J=Ye();let Ue=h("div","persona-text-xs persona-text-persona-muted persona-text-center persona-py-0.5 persona-px-4 persona-bg-persona-container persona-border-b persona-border-persona-divider persona-italic persona-flex-shrink-0");Ue.style.display="none";let K=h("div","persona-flex-1 persona-min-h-0 persona-relative"),j=h("div","persona-event-stream-list persona-overflow-y-auto persona-min-h-0");j.style.height="100%";let Ce=h("div","persona-scroll-to-bottom-indicator persona-absolute persona-bottom-3 persona-left-1/2 persona-transform persona--translate-x-1/2 persona-cursor-pointer persona-z-10 persona-text-xs");Ba(Ce,S==null?void 0:S.scrollIndicator),Ce.style.display="none",Ce.setAttribute("data-persona-scroll-to-bottom-has-label",l?"true":"false");let De=ve(d,"14px","currentColor",2);De&&Ce.appendChild(De);let oe=h("span","");oe.textContent=l,Ce.appendChild(oe);let Se=h("div","persona-flex persona-items-center persona-justify-center persona-h-full persona-text-sm persona-text-persona-muted");Se.style.display="none",K.appendChild(j),K.appendChild(Se),K.appendChild(Ce),E.setAttribute("tabindex","0"),E.appendChild(J),E.appendChild(Ue),E.appendChild(K);function ge(){let F=r.getAll(),ye={};for(let Pt of F)ye[Pt.type]=(ye[Pt.type]||0)+1;let be=Object.keys(ye).sort(),it=be.length!==H.length||!be.every((Pt,kt)=>Pt===H[kt]),Xe=!it&&be.some(Pt=>ye[Pt]!==B[Pt]),Wt=F.length!==Object.values(B).reduce((Pt,kt)=>Pt+kt,0);if(!it&&!Xe&&!Wt||(H=be,B=ye,!ce))return;let ar=ce.value;if(ce.options[0].textContent="All events",it){for(;ce.options.length>1;)ce.remove(1);for(let Pt of be){let kt=h("option","");kt.value=Pt,kt.textContent=`${Pt} (${ye[Pt]||0})`,ce.appendChild(kt)}ar&&be.includes(ar)?ce.value=ar:ar&&(ce.value="",b="")}else for(let Pt=1;Pt<ce.options.length;Pt++){let kt=ce.options[Pt];kt.textContent=`${kt.value} (${ye[kt.value]||0})`}}function Rt(){let F=r.getAll();if(b&&(F=F.filter(ye=>ye.type===b)),y){let ye=y.toLowerCase();F=F.filter(be=>be.type.toLowerCase().includes(ye)||be.payload.toLowerCase().includes(ye))}return F}function Me(){return b!==""||y!==""}function ae(){R=0,V=0,W.resume(),Ce.style.display="none"}function ur(F){me.has(F)?me.delete(F):me.add(F),Ee=F;let ye=j.scrollTop,be=W.isFollowing();Ke=!0,W.pause(),Qt(),j.scrollTop=ye,be&&W.resume(),Ke=!1}function Ut(){return vs(j,50)}function Qt(){ne=Date.now(),ue=!1,ge();let F=r.getEvictedCount();F>0?(Ue.textContent=`${F.toLocaleString()} older events truncated`,Ue.style.display=""):Ue.style.display="none",v=Rt();let ye=v.length,be=r.getSize()>0;G&&(G.textContent=String(r.getSize())),ye===0&&be&&Me()?(Se.textContent=y?`No events matching '${y}'`:"No events matching filter",Se.style.display="",j.style.display="none"):(Se.style.display="none",j.style.display=""),de&&(de.title=Me()?`Copy Filtered (${ye})`:"Copy All"),i&&!W.isFollowing()&&ye>R&&(V+=ye-R,oe.textContent=l?`${l}${V>0?` (${V})`:""}`:"",Ce.style.display=""),R=ye;let it=r.getAll(),Xe=it.length>0?it[0].timestamp:0,Wt=new Set(v.map(kt=>kt.id));for(let kt of me)Wt.has(kt)||me.delete(kt);let ar=b!==Ge||y!==Y,Pt=Re.size===0&&v.length>0;if(ar||Pt||v.length===0){j.innerHTML="",Re.clear();let kt=document.createDocumentFragment();for(let rt=0;rt<v.length;rt++){let lt=kp(v[rt],rt,Xe,u,me,ur,a,o);Re.set(v[rt].id,lt),kt.appendChild(lt)}j.appendChild(kt),Ge=b,Y=y,Ee=null}else{if(Ee!==null){let rt=Re.get(Ee);if(rt&&rt.parentNode===j){let lt=v.findIndex(rr=>rr.id===Ee);if(lt>=0){let rr=kp(v[lt],lt,Xe,u,me,ur,a,o);j.insertBefore(rr,rt),rt.remove(),Re.set(Ee,rr)}}Ee=null}let kt=new Set(v.map(rt=>rt.id));for(let[rt,lt]of Re)kt.has(rt)||(lt.remove(),Re.delete(rt));for(let rt=0;rt<v.length;rt++){let lt=v[rt];if(!Re.has(lt.id)){let rr=kp(lt,rt,Xe,u,me,ur,a,o);Re.set(lt.id,rr),j.appendChild(rr)}}}W.isFollowing()&&(j.scrollTop=j.scrollHeight)}function Or(){if(Date.now()-ne>=A0){We!==null&&(cancelAnimationFrame(We),We=null),Qt();return}ue||(ue=!0,We=requestAnimationFrame(()=>{We=null,Qt()}))}let vr=(F,ye)=>{if(!de)return;de.innerHTML="";let be=ve(F,"12px","currentColor",1.5);be&&de.appendChild(be);let it=h("span","persona-text-xs");it.textContent="Copy All",de.appendChild(it),setTimeout(()=>{de.innerHTML="";let Xe=ve("clipboard-copy","12px","currentColor",1.5);Xe&&de.appendChild(Xe);let Wt=h("span","persona-text-xs");Wt.textContent="Copy All",de.appendChild(Wt),de.disabled=!1},ye)},Oe=async()=>{if(de){de.disabled=!0;try{let F;Me()?F=v:t?(F=await t(),F.length===0&&(F=r.getAll())):F=r.getAll();let ye=F.map(be=>{try{return JSON.parse(be.payload)}catch{return be.payload}});await navigator.clipboard.writeText(JSON.stringify(ye,null,2)),vr("check",1500)}catch{vr("x",1500)}}},q=()=>{ce&&(b=ce.value,ae(),Qt())},Te=()=>{!pe||!He||(He.style.display=pe.value?"":"none",M&&clearTimeout(M),M=setTimeout(()=>{y=pe.value,ae(),Qt()},150))},_e=()=>{!pe||!He||(pe.value="",y="",He.style.display="none",M&&clearTimeout(M),ae(),Qt())},Ne=()=>{if(Ke)return;let F=j.scrollTop,{action:ye,nextLastScrollTop:be}=Ki({following:W.isFollowing(),currentScrollTop:F,lastScrollTop:xe,nearBottom:Ut(),userScrollThreshold:1,resumeRequiresDownwardScroll:!0});xe=be,ye==="resume"?(W.resume(),V=0,Ce.style.display="none"):ye==="pause"&&(W.pause(),i&&(oe.textContent=l,Ce.style.display=""))},qe=F=>{let ye=Yi({following:W.isFollowing(),deltaY:F.deltaY,nearBottom:Ut(),resumeWhenNearBottom:!0});ye==="pause"?(W.pause(),i&&(oe.textContent=l,Ce.style.display="")):ye==="resume"&&(W.resume(),V=0,Ce.style.display="none")},st=()=>{i&&(j.scrollTop=j.scrollHeight,W.resume(),V=0,Ce.style.display="none")},nt=F=>{let ye=F.target;if(!ye||ye.closest("button"))return;let be=ye.closest("[data-event-id]");if(!be)return;let it=be.getAttribute("data-event-id");it&&ur(it)},pt=F=>{if((F.metaKey||F.ctrlKey)&&F.key==="f"){F.preventDefault(),pe==null||pe.focus(),pe==null||pe.select();return}F.key==="Escape"&&(pe&&document.activeElement===pe?(_e(),pe.blur(),E.focus()):n&&n())};de&&de.addEventListener("click",Oe),ce&&ce.addEventListener("change",q),pe&&pe.addEventListener("input",Te),He&&He.addEventListener("click",_e),j.addEventListener("scroll",Ne),j.addEventListener("wheel",qe,{passive:!0}),j.addEventListener("click",nt),Ce.addEventListener("click",st),E.addEventListener("keydown",pt);function Nt(){M&&clearTimeout(M),We!==null&&(cancelAnimationFrame(We),We=null),ue=!1,Re.clear(),de&&de.removeEventListener("click",Oe),ce&&ce.removeEventListener("change",q),pe&&pe.removeEventListener("input",Te),He&&He.removeEventListener("click",_e),j.removeEventListener("scroll",Ne),j.removeEventListener("wheel",qe),j.removeEventListener("click",nt),Ce.removeEventListener("click",st),E.removeEventListener("keydown",pt)}return{element:E,update:Or,destroy:Nt}}}function Eh(e,r){let t=typeof e.title=="string"&&e.title?e.title:"Untitled artifact",n=typeof e.artifactId=="string"?e.artifactId:"",o=e.status==="streaming"?"streaming":"complete",s=(typeof e.artifactType=="string"?e.artifactType:"markdown")==="component"?"Component":"Document",i=document.createElement("div");i.className="persona-flex persona-w-full persona-max-w-full persona-items-center persona-gap-3 persona-rounded-xl persona-px-4 persona-py-3",i.style.border="1px solid var(--persona-border, #e5e7eb)",i.style.backgroundColor="var(--persona-surface, #ffffff)",i.style.cursor="pointer",i.tabIndex=0,i.setAttribute("role","button"),i.setAttribute("aria-label",`Open ${t} in artifact panel`),n&&i.setAttribute("data-open-artifact",n);let d=document.createElement("div");d.className="persona-flex persona-h-10 persona-w-10 persona-flex-shrink-0 persona-items-center persona-justify-center persona-rounded-lg",d.style.border="1px solid var(--persona-border, #e5e7eb)",d.style.color="var(--persona-muted, #9ca3af)",d.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/><polyline points="14 2 14 8 20 8"/></svg>';let l=document.createElement("div");l.className="persona-min-w-0 persona-flex-1 persona-flex persona-flex-col persona-gap-0.5";let u=document.createElement("div");u.className="persona-truncate persona-text-sm persona-font-medium",u.style.color="var(--persona-text, #1f2937)",u.textContent=t;let p=document.createElement("div");if(p.className="persona-text-xs persona-flex persona-items-center persona-gap-1.5",p.style.color="var(--persona-muted, #9ca3af)",o==="streaming"){let f=document.createElement("span");f.className="persona-inline-block persona-w-1.5 persona-h-1.5 persona-rounded-full",f.style.backgroundColor="var(--persona-primary, #171717)",f.style.animation="persona-pulse 1.5s ease-in-out infinite",p.appendChild(f);let m=document.createElement("span");m.textContent=`Generating ${s.toLowerCase()}...`,p.appendChild(m)}else p.textContent=s;if(l.append(u,p),i.append(d,l),o==="complete"){let f=document.createElement("button");f.type="button",f.textContent="Download",f.title=`Download ${t}`,f.className="persona-flex-shrink-0 persona-rounded-md persona-px-3 persona-py-1.5 persona-text-xs persona-font-medium",f.style.border="1px solid var(--persona-border, #e5e7eb)",f.style.color="var(--persona-text, #1f2937)",f.style.backgroundColor="transparent",f.style.cursor="pointer",f.setAttribute("data-download-artifact",n),i.append(f)}return i}var Mh=(e,r)=>{var n,o,a;let t=(a=(o=(n=r==null?void 0:r.config)==null?void 0:n.features)==null?void 0:o.artifacts)==null?void 0:a.renderCard;if(t){let s=typeof e.title=="string"&&e.title?e.title:"Untitled artifact",i=typeof e.artifactId=="string"?e.artifactId:"",d=e.status==="streaming"?"streaming":"complete",l=typeof e.artifactType=="string"?e.artifactType:"markdown",u=t({artifact:{artifactId:i,title:s,artifactType:l,status:d},config:r.config,defaultRenderer:()=>Eh(e,r)});if(u)return u}return Eh(e,r)};var Ep=class{constructor(){this.components=new Map}register(r,t){this.components.has(r)&&console.warn(`[ComponentRegistry] Component "${r}" is already registered. Overwriting.`),this.components.set(r,t)}unregister(r){this.components.delete(r)}get(r){return this.components.get(r)}has(r){return this.components.has(r)}getAllNames(){return Array.from(this.components.keys())}clear(){this.components.clear()}registerAll(r){Object.entries(r).forEach(([t,n])=>{this.register(t,n)})}},io=new Ep;io.register("PersonaArtifactCard",Mh);function I0(e){var o;let r=h("div","persona-rounded-lg persona-border persona-border-persona-border persona-p-3 persona-text-persona-primary"),t=h("div","persona-font-semibold persona-text-sm persona-mb-2");t.textContent=e.component?`Component: ${e.component}`:"Component";let n=h("pre","persona-font-mono persona-text-xs persona-whitespace-pre-wrap persona-overflow-x-auto");return n.textContent=JSON.stringify((o=e.props)!=null?o:{},null,2),r.appendChild(t),r.appendChild(n),r}function Lh(e,r){var de,pe,He,Ye;let t=(pe=(de=e.features)==null?void 0:de.artifacts)==null?void 0:pe.layout,o=((He=t==null?void 0:t.toolbarPreset)!=null?He:"default")==="document",a=(Ye=t==null?void 0:t.panePadding)==null?void 0:Ye.trim(),s=e.markdown?Xo(e.markdown):null,i=ba(e.sanitize),d=J=>{let ie=s?s(J):Jo(J);return i?i(ie):ie},l=typeof document!="undefined"?h("div","persona-artifact-backdrop persona-fixed persona-inset-0 persona-z-[55] persona-bg-black/30 persona-hidden md:persona-hidden"):null,u=()=>{l==null||l.classList.add("persona-hidden"),p.classList.remove("persona-artifact-drawer-open"),W==null||W.hide()};l&&l.addEventListener("click",()=>{var J;u(),(J=r.onDismiss)==null||J.call(r)});let p=h("aside","persona-artifact-pane persona-flex persona-flex-col persona-min-h-0 persona-min-w-0 persona-bg-persona-surface persona-text-persona-primary persona-border-l persona-border-persona-border");p.setAttribute("data-persona-theme-zone","artifact-pane"),o&&p.classList.add("persona-artifact-pane-document");let f=h("div","persona-artifact-toolbar persona-flex persona-items-center persona-justify-between persona-gap-2 persona-px-2 persona-py-2 persona-border-b persona-border-persona-border persona-shrink-0");f.setAttribute("data-persona-theme-zone","artifact-toolbar"),o&&f.classList.add("persona-artifact-toolbar-document");let m=h("span","persona-text-xs persona-font-medium persona-truncate");m.textContent="Artifacts";let C=h("button","persona-rounded-md persona-border persona-border-persona-border persona-px-2 persona-py-1 persona-text-xs persona-bg-persona-surface");C.type="button",C.textContent="Close",C.setAttribute("aria-label","Close artifacts panel"),C.addEventListener("click",()=>{var J;u(),(J=r.onDismiss)==null||J.call(r)});let w="rendered",k=h("div","persona-flex persona-items-center persona-gap-1 persona-shrink-0 persona-artifact-toggle-group"),T=o?Zt({icon:"eye",label:"Rendered view",className:"persona-artifact-doc-icon-btn persona-artifact-view-btn"}):Zt({icon:"eye",label:"Rendered view"}),S=o?Zt({icon:"code-2",label:"Source",className:"persona-artifact-doc-icon-btn persona-artifact-code-btn"}):Zt({icon:"code-2",label:"Source"}),E=h("div","persona-flex persona-items-center persona-gap-1 persona-shrink-0"),v=(t==null?void 0:t.documentToolbarShowCopyLabel)===!0,b=(t==null?void 0:t.documentToolbarShowCopyChevron)===!0,y=t==null?void 0:t.documentToolbarCopyMenuItems,M=!!(b&&y&&y.length>0),H=null,B,R=null,W=null;if(o&&(v||b)&&!M){if(B=v?Ps({icon:"copy",label:"Copy",iconSize:14,className:"persona-artifact-doc-copy-btn"}):Zt({icon:"copy",label:"Copy",className:"persona-artifact-doc-copy-btn"}),b){let J=ve("chevron-down",14,"currentColor",2);J&&B.appendChild(J)}}else o&&M?(H=h("div","persona-relative persona-inline-flex persona-items-center persona-gap-0 persona-rounded-md"),B=v?Ps({icon:"copy",label:"Copy",iconSize:14,className:"persona-artifact-doc-copy-btn"}):Zt({icon:"copy",label:"Copy",className:"persona-artifact-doc-copy-btn"}),R=Zt({icon:"chevron-down",label:"More copy options",size:14,className:"persona-artifact-doc-copy-menu-chevron persona-artifact-doc-icon-btn",aria:{"aria-haspopup":"true","aria-expanded":"false"}}),H.append(B,R)):o?B=Zt({icon:"copy",label:"Copy",className:"persona-artifact-doc-icon-btn"}):B=Zt({icon:"copy",label:"Copy"});let V=o?Zt({icon:"refresh-cw",label:"Refresh",className:"persona-artifact-doc-icon-btn"}):Zt({icon:"refresh-cw",label:"Refresh"}),ne=o?Zt({icon:"x",label:"Close",className:"persona-artifact-doc-icon-btn"}):Zt({icon:"x",label:"Close"}),ue=()=>{var j,Ce,De;let J=(j=Ge.find(oe=>oe.id===Y))!=null?j:Ge[Ge.length-1],ie=(Ce=J==null?void 0:J.id)!=null?Ce:null,Ue=(J==null?void 0:J.artifactType)==="markdown"&&(De=J.markdown)!=null?De:"",K=J?JSON.stringify({component:J.component,props:J.props},null,2):"";return{markdown:Ue,jsonPayload:K,id:ie}},We=async()=>{var j;let{markdown:J,jsonPayload:ie}=ue(),Ue=(j=Ge.find(Ce=>Ce.id===Y))!=null?j:Ge[Ge.length-1],K=(Ue==null?void 0:Ue.artifactType)==="markdown"?J:Ue?ie:"";try{await navigator.clipboard.writeText(K)}catch{}};if(B.addEventListener("click",async()=>{let J=t==null?void 0:t.onDocumentToolbarCopyMenuSelect;if(J&&M){let{markdown:ie,jsonPayload:Ue,id:K}=ue();try{await J({actionId:"primary",artifactId:K,markdown:ie,jsonPayload:Ue})}catch{}return}await We()}),R&&(y!=null&&y.length)){let J=()=>{var Ue;return(Ue=p.closest("[data-persona-root]"))!=null?Ue:document.body},ie=()=>{W=To({items:y.map(Ue=>({id:Ue.id,label:Ue.label})),onSelect:async Ue=>{let{markdown:K,jsonPayload:j,id:Ce}=ue(),De=t==null?void 0:t.onDocumentToolbarCopyMenuSelect;try{De?await De({actionId:Ue,artifactId:Ce,markdown:K,jsonPayload:j}):Ue==="markdown"||Ue==="md"?await navigator.clipboard.writeText(K):Ue==="json"||Ue==="source"?await navigator.clipboard.writeText(j):await navigator.clipboard.writeText(K||j)}catch{}},anchor:H!=null?H:R,position:"bottom-right",portal:J()})};p.isConnected?ie():requestAnimationFrame(ie),R.addEventListener("click",Ue=>{Ue.stopPropagation(),W==null||W.toggle()})}V.addEventListener("click",async()=>{var J;try{await((J=t==null?void 0:t.onDocumentToolbarRefresh)==null?void 0:J.call(t))}catch{}G()}),ne.addEventListener("click",()=>{var J;u(),(J=r.onDismiss)==null||J.call(r)});let Ke=()=>{o&&(T.setAttribute("aria-pressed",w==="rendered"?"true":"false"),S.setAttribute("aria-pressed",w==="source"?"true":"false"))};T.addEventListener("click",()=>{w="rendered",Ke(),G()}),S.addEventListener("click",()=>{w="source",Ke(),G()});let xe=h("span","persona-min-w-0 persona-flex-1 persona-text-xs persona-font-medium persona-text-persona-primary persona-truncate persona-text-center md:persona-text-left");o?(f.replaceChildren(),k.append(T,S),H?E.append(H,V,ne):E.append(B,V,ne),f.append(k,xe,E),Ke()):(f.appendChild(m),f.appendChild(C)),a&&(f.style.paddingLeft=a,f.style.paddingRight=a);let me=h("div","persona-artifact-list persona-shrink-0 persona-flex persona-gap-1 persona-overflow-x-auto persona-p-2 persona-border-b persona-border-persona-border"),Re=h("div","persona-artifact-content persona-flex-1 persona-min-h-0 persona-overflow-y-auto persona-p-3");a&&(me.style.paddingLeft=a,me.style.paddingRight=a,Re.style.padding=a),p.appendChild(f),p.appendChild(me),p.appendChild(Re);let Ge=[],Y=null,Ee=!1,G=()=>{var K,j,Ce,De;let J=o&&Ge.length<=1;me.classList.toggle("persona-hidden",J),me.replaceChildren();for(let oe of Ge){let Se=h("button","persona-artifact-tab persona-shrink-0 persona-rounded-lg persona-px-2 persona-py-1 persona-text-xs persona-border persona-border-transparent persona-text-persona-primary");Se.type="button",Se.textContent=oe.title||oe.id.slice(0,8),oe.id===Y&&Se.classList.add("persona-bg-persona-container","persona-border-persona-border"),Se.addEventListener("click",()=>r.onSelect(oe.id)),me.appendChild(Se)}Re.replaceChildren();let ie=Y&&Ge.find(oe=>oe.id===Y)||Ge[Ge.length-1];if(!ie)return;if(o){let oe=ie.artifactType==="markdown"?"MD":(K=ie.component)!=null?K:"Component",ge=(ie.title||"Document").trim().replace(/\s*·\s*MD\s*$/i,"").trim()||"Document";xe.textContent=`${ge} \xB7 ${oe}`}else m.textContent="Artifacts";if(ie.artifactType==="markdown"){if(o&&w==="source"){let Se=h("pre","persona-font-mono persona-text-xs persona-whitespace-pre-wrap persona-break-words persona-text-persona-primary");Se.textContent=(j=ie.markdown)!=null?j:"",Re.appendChild(Se);return}let oe=h("div","persona-text-sm persona-leading-relaxed persona-markdown-bubble");oe.innerHTML=d((Ce=ie.markdown)!=null?Ce:""),Re.appendChild(oe);return}let Ue=ie.component?io.get(ie.component):void 0;if(Ue){let Se={message:{id:ie.id,role:"assistant",content:"",createdAt:new Date().toISOString()},config:e,updateProps:()=>{}};try{let ge=Ue((De=ie.props)!=null?De:{},Se);if(ge){Re.appendChild(ge);return}}catch{}}Re.appendChild(I0(ie))},ce=()=>{var ie;let J=Ge.length>0;if(p.classList.toggle("persona-hidden",!J),l){let Ue=typeof p.closest=="function"?p.closest("[data-persona-root]"):null,j=((ie=Ue==null?void 0:Ue.classList.contains("persona-artifact-narrow-host"))!=null?ie:!1)||typeof window!="undefined"&&window.matchMedia("(max-width: 640px)").matches;J&&j&&Ee?(l.classList.remove("persona-hidden"),p.classList.add("persona-artifact-drawer-open")):(l.classList.add("persona-hidden"),p.classList.remove("persona-artifact-drawer-open"))}};return{element:p,backdrop:l,update(J){var ie,Ue,K;Ge=J.artifacts,Y=(K=(Ue=J.selectedId)!=null?Ue:(ie=J.artifacts[J.artifacts.length-1])==null?void 0:ie.id)!=null?K:null,Ge.length>0&&(Ee=!0),G(),ce()},setMobileOpen(J){Ee=J,!J&&l?(l.classList.add("persona-hidden"),p.classList.remove("persona-artifact-drawer-open")):ce()}}}function Sn(e){var r,t;return((t=(r=e==null?void 0:e.features)==null?void 0:r.artifacts)==null?void 0:t.enabled)===!0}function Ph(e,r){var a,s,i,d;if(e.classList.remove("persona-artifact-border-full","persona-artifact-border-left"),e.style.removeProperty("--persona-artifact-pane-border"),e.style.removeProperty("--persona-artifact-pane-border-left"),!Sn(r))return;let t=(s=(a=r.features)==null?void 0:a.artifacts)==null?void 0:s.layout,n=(i=t==null?void 0:t.paneBorder)==null?void 0:i.trim(),o=(d=t==null?void 0:t.paneBorderLeft)==null?void 0:d.trim();n?(e.classList.add("persona-artifact-border-full"),e.style.setProperty("--persona-artifact-pane-border",n)):o&&(e.classList.add("persona-artifact-border-left"),e.style.setProperty("--persona-artifact-pane-border-left",o))}function R0(e){e.style.removeProperty("--persona-artifact-doc-toolbar-icon-color"),e.style.removeProperty("--persona-artifact-doc-toggle-active-bg"),e.style.removeProperty("--persona-artifact-doc-toggle-active-border")}function gl(e,r){var d,l,u,p,f,m,C,w,k,T;if(!Sn(r)){e.style.removeProperty("--persona-artifact-split-gap"),e.style.removeProperty("--persona-artifact-pane-width"),e.style.removeProperty("--persona-artifact-pane-max-width"),e.style.removeProperty("--persona-artifact-pane-min-width"),e.style.removeProperty("--persona-artifact-pane-bg"),e.style.removeProperty("--persona-artifact-pane-padding"),R0(e),Ph(e,r);return}let t=(l=(d=r.features)==null?void 0:d.artifacts)==null?void 0:l.layout;e.style.setProperty("--persona-artifact-split-gap",(u=t==null?void 0:t.splitGap)!=null?u:"0.5rem"),e.style.setProperty("--persona-artifact-pane-width",(p=t==null?void 0:t.paneWidth)!=null?p:"40%"),e.style.setProperty("--persona-artifact-pane-max-width",(f=t==null?void 0:t.paneMaxWidth)!=null?f:"28rem"),t!=null&&t.paneMinWidth?e.style.setProperty("--persona-artifact-pane-min-width",t.paneMinWidth):e.style.removeProperty("--persona-artifact-pane-min-width");let n=(m=t==null?void 0:t.paneBackground)==null?void 0:m.trim();n?e.style.setProperty("--persona-artifact-pane-bg",n):e.style.removeProperty("--persona-artifact-pane-bg");let o=(C=t==null?void 0:t.panePadding)==null?void 0:C.trim();o?e.style.setProperty("--persona-artifact-pane-padding",o):e.style.removeProperty("--persona-artifact-pane-padding");let a=(w=t==null?void 0:t.documentToolbarIconColor)==null?void 0:w.trim();a?e.style.setProperty("--persona-artifact-doc-toolbar-icon-color",a):e.style.removeProperty("--persona-artifact-doc-toolbar-icon-color");let s=(k=t==null?void 0:t.documentToolbarToggleActiveBackground)==null?void 0:k.trim();s?e.style.setProperty("--persona-artifact-doc-toggle-active-bg",s):e.style.removeProperty("--persona-artifact-doc-toggle-active-bg");let i=(T=t==null?void 0:t.documentToolbarToggleActiveBorderColor)==null?void 0:T.trim();i?e.style.setProperty("--persona-artifact-doc-toggle-active-border",i):e.style.removeProperty("--persona-artifact-doc-toggle-active-border"),Ph(e,r)}var Ih=["panel","seamless"];function hl(e,r){var i,d,l,u,p,f;for(let m of Ih)e.classList.remove(`persona-artifact-appearance-${m}`);if(e.classList.remove("persona-artifact-unified-split"),e.style.removeProperty("--persona-artifact-pane-radius"),e.style.removeProperty("--persona-artifact-pane-shadow"),e.style.removeProperty("--persona-artifact-unified-outer-radius"),!Sn(r))return;let t=(d=(i=r.features)==null?void 0:i.artifacts)==null?void 0:d.layout,n=(l=t==null?void 0:t.paneAppearance)!=null?l:"panel",o=Ih.includes(n)?n:"panel";e.classList.add(`persona-artifact-appearance-${o}`);let a=(u=t==null?void 0:t.paneBorderRadius)==null?void 0:u.trim();a&&e.style.setProperty("--persona-artifact-pane-radius",a);let s=(p=t==null?void 0:t.paneShadow)==null?void 0:p.trim();if(s&&e.style.setProperty("--persona-artifact-pane-shadow",s),(t==null?void 0:t.unifiedSplitChrome)===!0){e.classList.add("persona-artifact-unified-split");let m=((f=t.unifiedSplitOuterRadius)==null?void 0:f.trim())||a;m&&e.style.setProperty("--persona-artifact-unified-outer-radius",m)}}function Rh(e,r){var t,n,o;return!r||!Sn(e)?!1:((o=(n=(t=e.features)==null?void 0:t.artifacts)==null?void 0:n.layout)==null?void 0:o.expandLauncherPanelWhenOpen)!==!1}function H0(e,r){if(!(e!=null&&e.trim()))return r;let t=/^(\d+(?:\.\d+)?)px\s*$/i.exec(e.trim());return t?Math.max(0,Number(t[1])):r}function B0(e){if(!(e!=null&&e.trim()))return null;let r=/^(\d+(?:\.\d+)?)px\s*$/i.exec(e.trim());return r?Math.max(0,Number(r[1])):null}function W0(e,r,t){return t<r?r:Math.min(t,Math.max(r,e))}function D0(e,r,t,n){let o=e-n-2*r-t;return Math.max(0,o)}function Hh(e,r){var s;let n=(s=(r.getComputedStyle(e).gap||"0px").trim().split(/\s+/)[0])!=null?s:"0px",o=/^([\d.]+)px$/i.exec(n);if(o)return Number(o[1]);let a=/^([\d.]+)/.exec(n);return a?Number(a[1]):8}function Bh(e,r,t,n,o,a){let s=H0(o,200),i=D0(r,t,n,200);i=Math.max(s,i);let d=B0(a);return d!==null&&(i=Math.min(i,d)),W0(e,s,i)}var Wh={init:{title:"Schedule a Demo",description:"Share the basics and we'll follow up with a confirmation.",fields:[{name:"name",label:"Full name",placeholder:"Jane Doe",required:!0},{name:"email",label:"Work email",placeholder:"jane@example.com",type:"email",required:!0},{name:"notes",label:"What would you like to cover?",type:"textarea"}],submitLabel:"Submit details"},followup:{title:"Additional Information",description:"Provide any extra details to tailor the next steps.",fields:[{name:"company",label:"Company",placeholder:"Acme Inc."},{name:"context",label:"Context",type:"textarea",placeholder:"Share more about your use case"}],submitLabel:"Send"}},Mp=(e,r,t,n)=>{let o=e.querySelectorAll("[data-tv-form]");o.length&&o.forEach(a=>{var C,w,k;if(a.dataset.enhanced==="true")return;let s=(C=a.dataset.tvForm)!=null?C:"init";a.dataset.enhanced="true";let i=(w=Wh[s])!=null?w:Wh.init;a.classList.add("persona-form-card","persona-space-y-4");let d=h("div","persona-space-y-1"),l=h("h3","persona-text-base persona-font-semibold persona-text-persona-primary");if(l.textContent=i.title,d.appendChild(l),i.description){let T=h("p","persona-text-sm persona-text-persona-muted");T.textContent=i.description,d.appendChild(T)}let u=document.createElement("form");u.className="persona-form-grid persona-space-y-3",i.fields.forEach(T=>{var y,M;let S=h("label","persona-form-field persona-flex persona-flex-col persona-gap-1");S.htmlFor=`${r.id}-${s}-${T.name}`;let E=h("span","persona-text-xs persona-font-medium persona-text-persona-muted");E.textContent=T.label,S.appendChild(E);let v=(y=T.type)!=null?y:"text",b;v==="textarea"?(b=document.createElement("textarea"),b.rows=3):(b=document.createElement("input"),b.type=v),b.className="persona-rounded-xl persona-border persona-border-gray-200 persona-bg-white persona-px-3 persona-py-2 persona-text-sm persona-text-persona-primary focus:persona-outline-none focus:persona-border-persona-primary",b.id=`${r.id}-${s}-${T.name}`,b.name=T.name,b.placeholder=(M=T.placeholder)!=null?M:"",T.required&&(b.required=!0),S.appendChild(b),u.appendChild(S)});let p=h("div","persona-flex persona-items-center persona-justify-between persona-gap-2"),f=h("div","persona-text-xs persona-text-persona-muted persona-min-h-[1.5rem]"),m=h("button","persona-inline-flex persona-items-center persona-rounded-full persona-bg-persona-primary persona-px-4 persona-py-2 persona-text-sm persona-font-semibold persona-text-white disabled:persona-opacity-60 persona-cursor-pointer");m.type="submit",m.textContent=(k=i.submitLabel)!=null?k:"Submit",p.appendChild(f),p.appendChild(m),u.appendChild(p),a.replaceChildren(d,u),u.addEventListener("submit",async T=>{var b,y;T.preventDefault();let S=(b=t.formEndpoint)!=null?b:"/form",E=new FormData(u),v={};E.forEach((M,H)=>{v[H]=M}),v.type=s,m.disabled=!0,f.textContent="Submitting\u2026";try{let M=await fetch(S,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(v)});if(!M.ok)throw new Error(`Form submission failed (${M.status})`);let H=await M.json();f.textContent=(y=H.message)!=null?y:"Thanks! We'll be in touch soon.",H.success&&H.nextPrompt&&await n.sendMessage(String(H.nextPrompt))}catch(M){f.textContent=M instanceof Error?M.message:"Something went wrong. Please try again."}finally{m.disabled=!1}})})};var Lp=class{constructor(){this.plugins=new Map}register(r){var t;this.plugins.has(r.id)&&console.warn(`Plugin "${r.id}" is already registered. Overwriting.`),this.plugins.set(r.id,r),(t=r.onRegister)==null||t.call(r)}unregister(r){var n;let t=this.plugins.get(r);t&&((n=t.onUnregister)==null||n.call(t),this.plugins.delete(r))}getAll(){return Array.from(this.plugins.values()).sort((r,t)=>{var n,o;return((n=t.priority)!=null?n:0)-((o=r.priority)!=null?o:0)})}getForInstance(r){let t=this.getAll();if(!r||r.length===0)return t;let n=new Set(r.map(a=>a.id));return[...t.filter(a=>!n.has(a.id)),...r].sort((a,s)=>{var i,d;return((i=s.priority)!=null?i:0)-((d=a.priority)!=null?d:0)})}clear(){this.plugins.forEach(r=>{var t;return(t=r.onUnregister)==null?void 0:t.call(r)}),this.plugins.clear()}},Ws=new Lp;var Dh=()=>{let e=new Map,r=(o,a)=>(e.has(o)||e.set(o,new Set),e.get(o).add(a),()=>t(o,a)),t=(o,a)=>{var s;(s=e.get(o))==null||s.delete(a)};return{on:r,off:t,emit:(o,a)=>{var s;(s=e.get(o))==null||s.forEach(i=>{try{i(a)}catch(d){typeof console!="undefined"&&console.error("[AgentWidget] Event handler error:",d)}})}}};var O0=e=>{let r=e.match(/```(?:json)?\s*([\s\S]*?)```/i);return r?r[1]:e},F0=e=>{let r=e.trim(),t=r.indexOf("{");if(t===-1)return null;let n=0;for(let o=t;o<r.length;o+=1){let a=r[o];if(a==="{"&&(n+=1),a==="}"&&(n-=1,n===0))return r.slice(t,o+1)}return null},Ds=({text:e})=>{if(!e||!e.includes("{"))return null;try{let r=O0(e),t=F0(r);if(!t)return null;let n=JSON.parse(t);if(!n||typeof n!="object"||!n.action)return null;let{action:o,...a}=n;return{type:String(o),payload:a,raw:n}}catch{return null}},Pp=e=>typeof e=="string"?e:e==null?"":String(e),sa={message:e=>e.type!=="message"?void 0:{handled:!0,displayText:Pp(e.payload.text)},messageAndClick:(e,r)=>{var o;if(e.type!=="message_and_click")return;let t=e.payload,n=Pp(t.element);if(n&&((o=r.document)!=null&&o.querySelector)){let a=r.document.querySelector(n);a?setTimeout(()=>{a.click()},400):typeof console!="undefined"&&console.warn("[AgentWidget] Element not found for selector:",n)}return{handled:!0,displayText:Pp(t.text)}}},Oh=e=>Array.isArray(e)?e.map(r=>String(r)):[],Os=e=>{let r=new Set(Oh(e.getSessionMetadata().processedActionMessageIds)),t=()=>{r=new Set(Oh(e.getSessionMetadata().processedActionMessageIds))},n=()=>{let a=Array.from(r);e.updateSessionMetadata(s=>({...s,processedActionMessageIds:a}))};return{process:a=>{if(a.streaming||a.message.role!=="assistant"||!a.text||r.has(a.message.id))return null;let s=typeof a.raw=="string"&&a.raw||typeof a.message.rawContent=="string"&&a.message.rawContent||typeof a.text=="string"&&a.text||null;!s&&typeof a.text=="string"&&a.text.trim().startsWith("{")&&typeof console!="undefined"&&console.warn("[AgentWidget] Structured response detected but no raw payload was provided. Ensure your stream parser returns { text, raw }.");let i=s?e.parsers.reduce((l,u)=>l||(u==null?void 0:u({text:s,message:a.message}))||null,null):null;if(!i)return null;r.add(a.message.id),n();let d={action:i,message:a.message};e.emit("action:detected",d);for(let l of e.handlers)if(l)try{let u=()=>{e.emit("action:resubmit",d)},p=l(i,{message:a.message,metadata:e.getSessionMetadata(),updateMetadata:e.updateSessionMetadata,document:e.documentRef,triggerResubmit:u});if(!p)continue;if(p.handled){let f=p.persistMessage!==!1;return{text:p.displayText!==void 0?p.displayText:"",persist:f,resubmit:p.resubmit}}}catch(u){typeof console!="undefined"&&console.error("[AgentWidget] Action handler error:",u)}return{text:"",persist:!0}},syncFromMetadata:t}};var N0=e=>{if(!e)return null;try{return JSON.parse(e)}catch(r){return typeof console!="undefined"&&console.error("[AgentWidget] Failed to parse stored state:",r),null}},_0=e=>e.map(r=>({...r,streaming:!1})),$0=e=>e.map(r=>({...r,status:"complete"})),xl=(e="persona-state")=>{let r=()=>typeof window=="undefined"||!window.localStorage?null:window.localStorage;return{load:()=>{let t=r();return t?N0(t.getItem(e)):null},save:t=>{let n=r();if(n)try{let o={...t,messages:t.messages?_0(t.messages):void 0,artifacts:t.artifacts?$0(t.artifacts):void 0};n.setItem(e,JSON.stringify(o))}catch(o){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",o)}},clear:()=>{let t=r();if(t)try{t.removeItem(e)}catch(n){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear stored state:",n)}}}};var Wa=Bl(hi(),1);function U0(e){if(!e||typeof e!="object"||!("component"in e))return!1;let r=e.component;return typeof r=="string"&&r.length>0}function q0(e,r){if(!U0(e))return null;let t=e.props&&typeof e.props=="object"&&e.props!==null?e.props:{};return{component:e.component,props:t,raw:r}}function yl(){let e=null,r=0;return{getExtractedDirective:()=>e,processChunk:t=>{let n=t.trim();if(!n.startsWith("{")&&!n.startsWith("["))return null;if(t.length<=r)return e;try{let o=(0,Wa.parse)(t,Wa.STR|Wa.OBJ),a=q0(o,t);a&&(e=a)}catch{}return r=t.length,e},reset:()=>{e=null,r=0}}}function Fh(e){return typeof e=="object"&&e!==null&&"component"in e&&typeof e.component=="string"&&"props"in e&&typeof e.props=="object"}function bl(e,r){let{config:t,message:n,onPropsUpdate:o}=r,a=io.get(e.component);if(!a)return console.warn(`[ComponentMiddleware] Component "${e.component}" not found in registry. Falling back to default rendering.`),null;let s={message:n,config:t,updateProps:i=>{o&&o(i)}};try{return a(e.props,s)}catch(i){return console.error(`[ComponentMiddleware] Error rendering component "${e.component}":`,i),null}}function Nh(){let e=yl();return{processChunk:r=>e.processChunk(r),getDirective:()=>e.getExtractedDirective(),reset:()=>{e.reset()}}}function _h(e){if(typeof e.rawContent=="string"&&e.rawContent.length>0)return e.rawContent;if(typeof e.content=="string"){let r=e.content.trim();if(r.startsWith("{")||r.startsWith("["))return e.content}return null}function Cl(e){let r=_h(e);if(!r)return!1;try{let t=JSON.parse(r);return typeof t=="object"&&t!==null&&"component"in t&&typeof t.component=="string"}catch{return!1}}function wl(e){let r=_h(e);if(!r)return null;try{let t=JSON.parse(r);if(typeof t=="object"&&t!==null&&"component"in t&&typeof t.component=="string"){let n=t;return{component:n.component,props:n.props&&typeof n.props=="object"&&n.props!==null?n.props:{},raw:r}}}catch{}return null}var z0=["Very dissatisfied","Dissatisfied","Neutral","Satisfied","Very satisfied"];function vl(e){let{onSubmit:r,onDismiss:t,title:n="How satisfied are you?",subtitle:o="Please rate your experience",commentPlaceholder:a="Share your thoughts (optional)...",submitText:s="Submit",skipText:i="Skip",showComment:d=!0,ratingLabels:l=z0}=e,u=document.createElement("div");u.className="persona-feedback-container persona-feedback-csat",u.setAttribute("role","dialog"),u.setAttribute("aria-label","Customer satisfaction feedback");let p=null,f=document.createElement("div");f.className="persona-feedback-content";let m=document.createElement("div");m.className="persona-feedback-header";let C=document.createElement("h3");C.className="persona-feedback-title",C.textContent=n,m.appendChild(C);let w=document.createElement("p");w.className="persona-feedback-subtitle",w.textContent=o,m.appendChild(w),f.appendChild(m);let k=document.createElement("div");k.className="persona-feedback-rating persona-feedback-rating-csat",k.setAttribute("role","radiogroup"),k.setAttribute("aria-label","Satisfaction rating from 1 to 5");let T=[];for(let y=1;y<=5;y++){let M=document.createElement("button");M.type="button",M.className="persona-feedback-rating-btn persona-feedback-star-btn",M.setAttribute("role","radio"),M.setAttribute("aria-checked","false"),M.setAttribute("aria-label",`${y} star${y>1?"s":""}: ${l[y-1]}`),M.title=l[y-1],M.dataset.rating=String(y),M.innerHTML=`
|
|
66
|
+
`):""},Qb=(e,r)=>{var u,p,f,m,C;let t=e.toolCall,n=(u=r==null?void 0:r.features)==null?void 0:u.toolCallDisplay,o=(p=n==null?void 0:n.collapsedMode)!=null?p:"tool-call",a=Yb(e,(f=n==null?void 0:n.previewMaxLines)!=null?f:3),s=t?Mg(t):"";if(!t)return{summary:s,previewText:a,isActive:!1};let i=t.status!=="complete",d=(m=r==null?void 0:r.toolCall)!=null?m:{},l=s;return o==="tool-name"?l=((C=t.name)==null?void 0:C.trim())||s:o==="tool-preview"&&a&&(l=a),i&&d.activeTextTemplate?l=ed(t,d.activeTextTemplate,l):!i&&d.completeTextTemplate&&(l=ed(t,d.completeTextTemplate,l)),{summary:l,previewText:a,isActive:i}},ph=(e,r,t)=>{var u;let n=Pa.has(e),o=(u=t==null?void 0:t.toolCall)!=null?u:{},a=r.querySelector('button[data-expand-header="true"]'),s=r.querySelector(".persona-border-t"),i=r.querySelector('[data-persona-collapsed-preview="tool"]');if(!a||!s)return;a.setAttribute("aria-expanded",n?"true":"false");let d=a.querySelector(".persona-ml-auto"),l=d==null?void 0:d.querySelector(":scope > .persona-flex.persona-items-center");if(l){l.innerHTML="";let p=o.toggleTextColor||o.headerTextColor||"currentColor",f=ve(n?"chevron-up":"chevron-down",16,p,2);f?l.appendChild(f):l.textContent=n?"Hide":"Show"}s.style.display=n?"":"none",i&&(i.style.display=n?"none":i.textContent||i.childNodes.length?"":"none")},xp=(e,r)=>{var V,ne,ue,Be,Ke,ye,me,We,Xe;let t=e.toolCall,n=(V=r==null?void 0:r.toolCall)!=null?V:{},o=h("div",["persona-message-bubble","persona-tool-bubble","persona-w-full","persona-max-w-[85%]","persona-rounded-2xl","persona-bg-persona-surface","persona-border","persona-border-persona-message-border","persona-text-persona-primary","persona-shadow-sm","persona-overflow-hidden","persona-px-0","persona-py-0"].join(" "));if(o.id=`bubble-${e.id}`,o.setAttribute("data-message-id",e.id),n.backgroundColor&&(o.style.backgroundColor=n.backgroundColor),n.borderColor&&(o.style.borderColor=n.borderColor),n.borderWidth&&(o.style.borderWidth=n.borderWidth),n.borderRadius&&(o.style.borderRadius=n.borderRadius),!t)return o;let a=(ue=(ne=r==null?void 0:r.features)==null?void 0:ne.toolCallDisplay)!=null?ue:{},s=a.expandable!==!1,i=s&&Pa.has(e.id),{summary:d,previewText:l,isActive:u}=Qb(e,r),p=h("button",s?"persona-flex persona-w-full persona-items-center persona-justify-between persona-gap-3 persona-bg-transparent persona-px-4 persona-py-3 persona-text-left persona-cursor-pointer persona-border-none":"persona-flex persona-w-full persona-items-center persona-justify-between persona-gap-3 persona-bg-transparent persona-px-4 persona-py-3 persona-text-left persona-cursor-default persona-border-none");p.type="button",s&&(p.setAttribute("aria-expanded",i?"true":"false"),p.setAttribute("data-expand-header","true")),p.setAttribute("data-bubble-type","tool"),n.headerBackgroundColor&&(p.style.backgroundColor=n.headerBackgroundColor),n.headerPaddingX&&(p.style.paddingLeft=n.headerPaddingX,p.style.paddingRight=n.headerPaddingX),n.headerPaddingY&&(p.style.paddingTop=n.headerPaddingY,p.style.paddingBottom=n.headerPaddingY);let f=h("div","persona-flex persona-flex-col persona-text-left"),m=h("span","persona-text-xs persona-text-persona-primary");n.headerTextColor&&(m.style.color=n.headerTextColor);let C=String((Be=t.startedAt)!=null?Be:Date.now()),A=()=>{let Y=h("span","");return Y.setAttribute("data-tool-elapsed",C),Y.textContent=gs(t),Y},k=(ye=n.renderCollapsedSummary)==null?void 0:ye.call(n,{message:e,toolCall:t,defaultSummary:d,previewText:l,collapsedMode:(Ke=a.collapsedMode)!=null?Ke:"tool-call",isActive:u,config:r!=null?r:{},elapsed:gs(t),createElapsedElement:A});typeof k=="string"&&k.trim()?(m.textContent=k,f.appendChild(m)):k instanceof HTMLElement?f.appendChild(k):(m.textContent=d,f.appendChild(m));let T=(me=a.loadingAnimation)!=null?me:"none",S=n.activeTextTemplate,E=n.completeTextTemplate,w=u?S:E,b=k instanceof HTMLElement,y=(Y,Ee,G)=>{let ce=G;for(let de of Ee){let pe=h("span","persona-tool-char");pe.style.setProperty("--char-index",String(ce)),pe.textContent=de===" "?"\xA0":de,Y.appendChild(pe),ce++}return ce},M=(Y,Ee)=>{var pe;m.textContent="";let G=((pe=t.name)==null?void 0:pe.trim())||"tool",ce=Ci(Y,G),de=0;for(let Re of ce){let Ye=Re.styles.length>0?(()=>{let J=h("span",Re.styles.map(ie=>`persona-tool-text-${ie}`).join(" "));return m.appendChild(J),J})():m;if(Re.isDuration&&u)Ye.appendChild(A());else{let J=Re.isDuration?gs(t):Re.text;Ee?de=y(Ye,J,de):Ye.appendChild(document.createTextNode(J))}}};if(!b)if(u&&T!=="none"){let Y=(We=n.loadingAnimationDuration)!=null?We:2e3;if(m.setAttribute("data-preserve-animation","true"),T==="pulse")m.classList.add("persona-tool-loading-pulse"),m.style.setProperty("--persona-tool-anim-duration",`${Y}ms`),w&&M(w,!1);else if(m.classList.add(`persona-tool-loading-${T}`),m.style.setProperty("--persona-tool-anim-duration",`${Y}ms`),T==="shimmer-color"&&(n.loadingAnimationColor&&m.style.setProperty("--persona-tool-anim-color",n.loadingAnimationColor),n.loadingAnimationSecondaryColor&&m.style.setProperty("--persona-tool-anim-secondary-color",n.loadingAnimationSecondaryColor)),w)M(w,!0);else{let Ee=m.textContent||d;m.textContent="",y(m,Ee,0)}}else w&&M(w,!1);let H=null;if(s){H=h("div","persona-flex persona-items-center");let Y=n.toggleTextColor||n.headerTextColor||"currentColor",Ee=ve(i?"chevron-up":"chevron-down",16,Y,2);Ee?H.appendChild(Ee):H.textContent=i?"Hide":"Show";let G=h("div","persona-flex persona-items-center persona-gap-2 persona-ml-auto");G.append(H),p.append(f,G)}else p.append(f);let B=h("div","persona-px-4 persona-py-3 persona-text-xs persona-leading-snug persona-text-persona-muted");if(B.setAttribute("data-persona-collapsed-preview","tool"),B.style.display="none",B.style.whiteSpace="pre-wrap",!i&&u&&a.activePreview&&l){let Y=(Xe=n.renderCollapsedPreview)==null?void 0:Xe.call(n,{message:e,toolCall:t,defaultPreview:l,isActive:u,config:r!=null?r:{}});Kb(B,Y)||(B.textContent=l),B.style.display=""}if(!i&&u&&a.activeMinHeight&&(o.style.minHeight=a.activeMinHeight),!s)return o.append(p,B),o;let R=h("div","persona-border-t persona-border-gray-200 persona-bg-gray-50 persona-space-y-3 persona-px-4 persona-py-3");if(R.style.display=i?"":"none",n.contentBackgroundColor&&(R.style.backgroundColor=n.contentBackgroundColor),n.contentTextColor&&(R.style.color=n.contentTextColor),n.contentPaddingX&&(R.style.paddingLeft=n.contentPaddingX,R.style.paddingRight=n.contentPaddingX),n.contentPaddingY&&(R.style.paddingTop=n.contentPaddingY,R.style.paddingBottom=n.contentPaddingY),t.name){let Y=h("div","persona-text-xs persona-text-persona-muted persona-italic");n.contentTextColor?Y.style.color=n.contentTextColor:n.headerTextColor&&(Y.style.color=n.headerTextColor),Y.textContent=t.name,R.appendChild(Y)}if(t.args!==void 0){let Y=h("div","persona-space-y-1"),Ee=h("div","persona-text-xs persona-text-persona-muted");n.labelTextColor&&(Ee.style.color=n.labelTextColor),Ee.textContent="Arguments";let G=h("pre","persona-max-h-48 persona-overflow-auto persona-whitespace-pre-wrap persona-rounded-lg persona-border persona-border-gray-100 persona-bg-white persona-px-3 persona-py-2 persona-text-xs persona-text-persona-primary");G.style.fontSize="0.75rem",G.style.lineHeight="1rem",n.codeBlockBackgroundColor&&(G.style.backgroundColor=n.codeBlockBackgroundColor),n.codeBlockBorderColor&&(G.style.borderColor=n.codeBlockBorderColor),n.codeBlockTextColor&&(G.style.color=n.codeBlockTextColor),G.textContent=Ca(t.args),Y.append(Ee,G),R.appendChild(Y)}if(t.chunks&&t.chunks.length){let Y=h("div","persona-space-y-1"),Ee=h("div","persona-text-xs persona-text-persona-muted");n.labelTextColor&&(Ee.style.color=n.labelTextColor),Ee.textContent="Activity";let G=h("pre","persona-max-h-48 persona-overflow-auto persona-whitespace-pre-wrap persona-rounded-lg persona-border persona-border-gray-100 persona-bg-white persona-px-3 persona-py-2 persona-text-xs persona-text-persona-primary");G.style.fontSize="0.75rem",G.style.lineHeight="1rem",n.codeBlockBackgroundColor&&(G.style.backgroundColor=n.codeBlockBackgroundColor),n.codeBlockBorderColor&&(G.style.borderColor=n.codeBlockBorderColor),n.codeBlockTextColor&&(G.style.color=n.codeBlockTextColor),G.textContent=t.chunks.join(""),Y.append(Ee,G),R.appendChild(Y)}if(t.status==="complete"&&t.result!==void 0){let Y=h("div","persona-space-y-1"),Ee=h("div","persona-text-xs persona-text-persona-muted");n.labelTextColor&&(Ee.style.color=n.labelTextColor),Ee.textContent="Result";let G=h("pre","persona-max-h-48 persona-overflow-auto persona-whitespace-pre-wrap persona-rounded-lg persona-border persona-border-gray-100 persona-bg-white persona-px-3 persona-py-2 persona-text-xs persona-text-persona-primary");G.style.fontSize="0.75rem",G.style.lineHeight="1rem",n.codeBlockBackgroundColor&&(G.style.backgroundColor=n.codeBlockBackgroundColor),n.codeBlockBorderColor&&(G.style.borderColor=n.codeBlockBorderColor),n.codeBlockTextColor&&(G.style.color=n.codeBlockTextColor),G.textContent=Ca(t.result),Y.append(Ee,G),R.appendChild(Y)}if(t.status==="complete"&&typeof t.duration=="number"){let Y=h("div","persona-text-xs persona-text-persona-muted");n.contentTextColor&&(Y.style.color=n.contentTextColor),Y.textContent=`Duration: ${t.duration}ms`,R.appendChild(Y)}return(()=>{if(p.setAttribute("aria-expanded",i?"true":"false"),H){H.innerHTML="";let Y=n.toggleTextColor||n.headerTextColor||"currentColor",Ee=ve(i?"chevron-up":"chevron-down",16,Y,2);Ee?H.appendChild(Ee):H.textContent=i?"Hide":"Show"}R.style.display=i?"":"none",B.style.display=i?"none":B.textContent||B.childNodes.length?"":"none"})(),o.append(p,B,R),o};var ko=Bl(hi(),1);var bp="ask_user_question",yp=8,Ia="data-persona-ask-sheet-for",Zb="Other",e0="Other\u2026",fh="Type your own answer here",mh="Send",t0="Next",r0="Back",n0="Submit all",o0="Skip",a0=3,Cp="data-ask-current-index",wp="data-ask-question-count",gh="data-ask-answers",vp="data-ask-grouped",hh="data-ask-layout",s0=e=>e.layout==="pills"?"pills":"rows",i0=e=>e.getAttribute(hh)==="pills"?"pills":"rows",uh=!1,xh=e=>e.replace(/["\\]/g,"\\$&"),ao=e=>e.variant==="tool"&&!!e.toolCall&&e.toolCall.name===bp,ul=e=>{var r,t;return(t=(r=e==null?void 0:e.features)==null?void 0:r.askUserQuestion)!=null?t:{}},so=e=>{let r=e.toolCall;if(!r)return{payload:null,complete:!1};let t=r.status==="complete";if(r.args&&typeof r.args=="object")return{payload:r.args,complete:t};let n=r.chunks;if(!n||n.length===0)return{payload:null,complete:t};try{let o=n.join(""),a=(0,ko.parse)(o,ko.STR|ko.OBJ|ko.ARR);if(a&&typeof a=="object")return{payload:a,complete:t}}catch{}return{payload:null,complete:t}},Rs=e=>{let r=Array.isArray(e==null?void 0:e.questions)?e.questions:[];return r.length>yp&&!uh&&(uh=!0,typeof console!="undefined"&&console.warn(`[AgentWidget] ask_user_question received ${r.length} questions; truncating to ${yp}.`)),r.slice(0,yp)},l0=e=>{var r;return(r=Rs(e)[0])!=null?r:null},d0=(e,r)=>{var t;return(t=Rs(e)[r])!=null?t:null},yh=(e,r)=>{let t=r.styles;t&&(t.sheetBackground&&e.style.setProperty("--persona-ask-sheet-bg",t.sheetBackground),t.sheetBorder&&e.style.setProperty("--persona-ask-sheet-border",t.sheetBorder),t.sheetShadow&&e.style.setProperty("--persona-ask-sheet-shadow",t.sheetShadow),t.pillBackground&&e.style.setProperty("--persona-ask-pill-bg",t.pillBackground),t.pillBackgroundSelected&&e.style.setProperty("--persona-ask-pill-bg-selected",t.pillBackgroundSelected),t.pillTextColor&&e.style.setProperty("--persona-ask-pill-fg",t.pillTextColor),t.pillTextColorSelected&&e.style.setProperty("--persona-ask-pill-fg-selected",t.pillTextColorSelected),t.pillBorderRadius&&e.style.setProperty("--persona-ask-pill-radius",t.pillBorderRadius),t.customInputBackground&&e.style.setProperty("--persona-ask-input-bg",t.customInputBackground))},bh=(e,r,t)=>{if(e!=="rows")return null;let n=h("span","persona-ask-row-affordance");if(n.setAttribute("aria-hidden","true"),r){let o=h("span","persona-ask-row-check");n.appendChild(o)}else{let o=h("span","persona-ask-row-badge");o.textContent=String(t+1),n.appendChild(o)}return n},c0=(e,r,t,n)=>{let a=h("button",t==="rows"?"persona-ask-pill persona-ask-row persona-pointer-events-auto":"persona-ask-pill persona-pointer-events-auto");if(a.type="button",a.setAttribute("role",n?"checkbox":"button"),a.setAttribute("aria-pressed","false"),a.setAttribute("data-ask-user-action","pick"),a.setAttribute("data-option-index",String(r)),a.setAttribute("data-option-label",e.label),t==="rows"){let s=h("span","persona-ask-row-content"),i=h("span","persona-ask-row-label");if(i.textContent=e.label,s.appendChild(i),e.description){let l=h("span","persona-ask-row-description");l.textContent=e.description,s.appendChild(l)}a.appendChild(s);let d=bh(t,n,r);d&&a.appendChild(d)}else a.textContent=e.label,e.description&&(a.title=e.description);return a},p0=e=>{let t=h("span",e==="rows"?"persona-ask-pill persona-ask-row persona-ask-pill-skeleton persona-pointer-events-none":"persona-ask-pill persona-ask-pill-skeleton persona-pointer-events-none");return t.setAttribute("aria-hidden","true"),t},u0=(e,r,t,n)=>{var u,p,f;let a=h("div",n==="rows"?"persona-ask-pills persona-ask-pills--rows persona-flex persona-flex-col persona-gap-2":"persona-ask-pills persona-flex persona-flex-wrap persona-gap-2");a.setAttribute("role","group"),a.setAttribute("data-ask-pill-list","true");let s=!!(e!=null&&e.multiSelect),d=(Array.isArray(e==null?void 0:e.options)?e.options:[]).filter(m=>m&&typeof m.label=="string"&&m.label.length>0);if(d.length===0&&!t){for(let m=0;m<a0;m++)a.appendChild(p0(n));return a}if(d.forEach((m,C)=>{a.appendChild(c0(m,C,n,s))}),(e==null?void 0:e.allowFreeText)!==!1){let m=n==="rows"?Zb:e0;if(n==="rows"){let C=h("div","persona-ask-pill persona-ask-row persona-ask-row--other persona-ask-pill-custom persona-pointer-events-auto");C.setAttribute("data-ask-user-action","focus-free-text"),C.setAttribute("data-option-index",String(d.length)),C.setAttribute("data-ask-other-row","true");let A=h("span","persona-ask-row-content"),k=document.createElement("input");k.type="text",k.className="persona-ask-row-input persona-flex-1 persona-pointer-events-auto",k.placeholder=(u=r.freeTextPlaceholder)!=null?u:fh,k.setAttribute("data-ask-free-text-input","true"),k.setAttribute("aria-label",(p=r.freeTextLabel)!=null?p:m),A.appendChild(k),C.appendChild(A);let T=bh(n,s,d.length);T&&C.appendChild(T),a.appendChild(C)}else{let C=h("button","persona-ask-pill persona-ask-pill-custom persona-pointer-events-auto");C.type="button",C.setAttribute("data-ask-user-action","open-free-text"),C.textContent=(f=r.freeTextLabel)!=null?f:m,a.appendChild(C)}}return a},Ch=(e,r)=>{var a,s;let n=h("div",r==="rows"?"persona-ask-free-text persona-ask-free-text--rows persona-flex persona-gap-2 persona-mt-2":"persona-ask-free-text persona-hidden persona-flex persona-gap-2 persona-mt-2");n.setAttribute("data-ask-free-text-row","true");let o=document.createElement("input");if(o.type="text",o.className="persona-ask-free-text-input persona-flex-1 persona-pointer-events-auto",o.placeholder=(a=e.freeTextPlaceholder)!=null?a:fh,o.setAttribute("data-ask-free-text-input","true"),n.appendChild(o),r!=="rows"){let i=h("button","persona-ask-free-text-submit persona-pointer-events-auto");i.type="button",i.textContent=(s=e.submitLabel)!=null?s:mh,i.setAttribute("data-ask-user-action","submit-free-text"),n.appendChild(i)}return n},f0=e=>{var n;let r=h("div","persona-ask-multi-actions persona-flex persona-justify-end persona-mt-2");r.setAttribute("data-ask-multi-actions","true");let t=h("button","persona-ask-multi-submit persona-pointer-events-auto");return t.type="button",t.textContent=(n=e.submitLabel)!=null?n:mh,t.setAttribute("data-ask-user-action","submit-multi"),t.disabled=!0,r.appendChild(t),r},m0=(e,r,t)=>{var l,u,p,f;let n=h("div","persona-ask-nav persona-flex persona-justify-between persona-items-center persona-gap-2 persona-mt-2");n.setAttribute("data-ask-nav-row","true");let o=h("button","persona-ask-nav-back persona-pointer-events-auto");o.type="button",o.textContent=(l=t.backLabel)!=null?l:r0,o.setAttribute("data-ask-user-action","back"),o.disabled=e===0,n.appendChild(o);let a=h("div","persona-ask-nav-right persona-flex persona-items-center persona-gap-2"),s=h("button","persona-ask-nav-skip persona-pointer-events-auto");s.type="button",s.textContent=(u=t.skipLabel)!=null?u:o0,s.setAttribute("data-ask-user-action","skip"),a.appendChild(s);let i=h("button","persona-ask-nav-next persona-pointer-events-auto");i.type="button";let d=e===r-1;return i.textContent=d?(p=t.submitAllLabel)!=null?p:n0:(f=t.nextLabel)!=null?f:t0,i.setAttribute("data-ask-user-action",d?"submit-all":"next"),i.disabled=!0,a.appendChild(i),n.appendChild(a),n},aa=e=>{let r=e.getAttribute(gh);if(!r)return{};try{let t=JSON.parse(r);return t&&typeof t=="object"?t:{}}catch{return{}}},wh=(e,r)=>{e.setAttribute(gh,JSON.stringify(r))},An=e=>{var t;let r=Number((t=e.getAttribute(Cp))!=null?t:"0");return Number.isFinite(r)?Math.max(0,Math.floor(r)):0},g0=(e,r)=>{e.setAttribute(Cp,String(Math.max(0,Math.floor(r))))},Ra=e=>{var t;let r=Number((t=e.getAttribute(wp))!=null?t:"1");return Number.isFinite(r)?Math.max(1,Math.floor(r)):1},Eo=e=>e.getAttribute(vp)==="true",h0=(e,r)=>{var o;let t=(o=e.agentMetadata)==null?void 0:o.askUserQuestionAnswers;if(!t||typeof t!="object")return{};let n={};return r.forEach((a,s)=>{let i=typeof(a==null?void 0:a.question)=="string"?a.question:"";if(i&&Object.prototype.hasOwnProperty.call(t,i)){let d=t[i];(typeof d=="string"||Array.isArray(d))&&(n[s]=d)}}),n},x0=(e,r)=>{var n;let t=(n=e.agentMetadata)==null?void 0:n.askUserQuestionIndex;return typeof t!="number"||!Number.isFinite(t)?0:Math.max(0,Math.min(r-1,Math.floor(t)))},fl=(e,r)=>{let{payload:t}=so(r),n=Rs(t),o=aa(e),a={},s=new Set;return n.forEach((i,d)=>{let l=typeof(i==null?void 0:i.question)=="string"?i.question:"";l&&(s.has(l)&&typeof console!="undefined"&&console.warn(`[AgentWidget] ask_user_question has duplicate question text "${l}"; later answer wins.`),s.add(l),Object.prototype.hasOwnProperty.call(o,d)&&(a[l]=o[d]))}),a},vh=e=>{let r=aa(e),t=An(e),n=r[t],o=new Set;typeof n=="string"?o.add(n):Array.isArray(n)&&n.forEach(d=>o.add(d));let a=e.querySelectorAll('[data-ask-user-action="pick"][data-option-label]');a.forEach(d=>{var p;let l=(p=d.getAttribute("data-option-label"))!=null?p:"",u=o.has(l);d.setAttribute("aria-pressed",u?"true":"false"),d.classList.toggle("persona-ask-pill-selected",u)});let s=new Set(Array.from(a).map(d=>{var l;return(l=d.getAttribute("data-option-label"))!=null?l:""})),i=e.querySelector('[data-ask-free-text-input="true"]');if(i)if(typeof n=="string"&&n.length>0&&!s.has(n)){i.value=n;let d=i.closest('[data-ask-free-text-row="true"]');d==null||d.classList.remove("persona-hidden")}else i.value=""},Ah=e=>{if(!Eo(e))return;let r=aa(e),t=An(e),n=r[t],o=typeof n=="string"&&n.length>0||Array.isArray(n)&&n.length>0,a=e.querySelector('[data-ask-user-action="next"], [data-ask-user-action="submit-all"]');a&&(a.disabled=!o);let s=e.querySelector('[data-ask-user-action="submit-multi"]');if(s){let i=Array.from(e.querySelectorAll('[aria-pressed="true"][data-option-label]'));s.disabled=i.length===0}},Ap=(e,r,t)=>{let n=ul(t),o=i0(e),{payload:a,complete:s}=so(r),i=Eo(e),d=An(e),l=Ra(e),u=i?d0(a,d):l0(a),p=!!(u!=null&&u.multiSelect),f=e.querySelector('[data-ask-step-inline="true"]');f&&(f.textContent=i?`${d+1}/${l}`:"");let m=e.querySelector('[data-ask-stepper="true"]');m&&m.remove();let C=e.querySelector('[data-ask-question="true"]');if(C){let S=typeof(u==null?void 0:u.question)=="string"?u.question:"";C.textContent=S,C.classList.toggle("persona-ask-question-skeleton",!S&&!s)}let A=e.querySelector('[data-ask-pill-list="true"]');if(A){let S=u0(u,n,s,o);A.replaceWith(S)}if(o!=="rows"){let S=e.querySelector('[data-ask-free-text-row="true"]');S&&S.replaceWith(Ch(n,o))}let k=e.querySelector('[data-ask-multi-actions="true"]');!i&&p&&!k?e.appendChild(f0(n)):(!p||i)&&k&&k.remove(),e.setAttribute("data-multi-select",p?"true":"false");let T=e.querySelector('[data-ask-nav-row="true"]');if(i){let S=m0(d,l,n);T?T.replaceWith(S):e.appendChild(S)}else T&&T.remove();vh(e),Ah(e)},y0=(e,r,t)=>{let n=ul(r),o=s0(n),a=e.toolCall.id,s=Rs(t),i=Math.max(1,s.length),d=i>1,l=h0(e,s),u=d?x0(e,i):0,p=h("div",["persona-ask-sheet",`persona-ask-sheet--${o}`,"persona-pointer-events-auto","persona-ask-sheet-enter"].join(" "));p.setAttribute(Ia,a),p.setAttribute("data-tool-call-id",a),p.setAttribute("data-message-id",e.id),p.setAttribute(wp,String(i)),p.setAttribute(Cp,String(u)),p.setAttribute(vp,d?"true":"false"),p.setAttribute(hh,o),wh(p,l),p.setAttribute("role","group"),p.setAttribute("aria-label","Suggested answers"),n.slideInMs!==void 0&&p.style.setProperty("--persona-ask-sheet-duration",`${n.slideInMs}ms`),yh(p,n);let f=h("div","persona-ask-sheet-header persona-flex persona-items-center persona-gap-3"),m=h("div","persona-ask-sheet-question persona-flex-1");m.setAttribute("data-ask-question","true"),m.textContent="",f.appendChild(m);let C=h("span","persona-ask-sheet-step-inline");C.setAttribute("data-ask-step-inline","true"),C.textContent="",f.appendChild(C),p.appendChild(f);let k=h("div",o==="rows"?"persona-ask-pills persona-ask-pills--rows persona-flex persona-flex-col persona-gap-2":"persona-ask-pills persona-flex persona-flex-wrap persona-gap-2");return k.setAttribute("data-ask-pill-list","true"),k.setAttribute("role","group"),p.appendChild(k),o!=="rows"&&p.appendChild(Ch(n,o)),Ap(p,e,r),requestAnimationFrame(()=>{requestAnimationFrame(()=>p.classList.remove("persona-ask-sheet-enter"))}),p},b0=(e,r,t)=>{let{payload:n}=so(r),o=Math.max(1,Rs(n).length);o>Ra(e)&&(e.setAttribute(wp,String(o)),o>1&&!Eo(e)&&e.setAttribute(vp,"true")),Ap(e,r,t)},Sh=(e,r)=>{let t=h("div","persona-ask-stub persona-inline-flex persona-items-center persona-gap-2");t.id=`bubble-${e.id}`,t.setAttribute("data-message-id",e.id),t.setAttribute("data-bubble-type","ask-user-question");let n=ul(r);yh(t,n);let o=h("span","persona-ask-stub-label"),{complete:a}=so(e);return o.textContent=a?"Awaiting your response\u2026":"Preparing options\u2026",t.appendChild(o),t},Ha=(e,r,t)=>{if(!t||!ao(e)||ul(r).enabled===!1)return;let o=e.toolCall.id;t.querySelectorAll(`[${Ia}]`).forEach(l=>{l.getAttribute(Ia)!==o&&l.remove()});let s=t.querySelector(`[${Ia}="${xh(o)}"]`);if(s){b0(s,e,r);return}let{payload:i}=so(e),d=y0(e,r,i);t.appendChild(d)},Mo=(e,r)=>{if(!e)return;let t=r?`[${Ia}="${xh(r)}"]`:`[${Ia}]`;e.querySelectorAll(t).forEach(o=>{o.classList.add("persona-ask-sheet-leave");let a=Number.parseInt(getComputedStyle(o).getPropertyValue("--persona-ask-sheet-duration")||"180",10);setTimeout(()=>o.remove(),Number.isFinite(a)?a:180)})},Sp=e=>Array.from(e.querySelectorAll('[aria-pressed="true"][data-option-label]')).map(r=>r.getAttribute("data-option-label")).filter(r=>typeof r=="string"&&r.length>0),Lo=(e,r)=>{let t=aa(e),n=An(e);typeof r=="string"&&r.length===0||Array.isArray(r)&&r.length===0?delete t[n]:t[n]=r,wh(e,t),vh(e),Ah(e)},ml=(e,r,t,n)=>{let o=Ra(e),a=Math.max(0,Math.min(o-1,n));g0(e,a),Ap(e,r,t)};var Tp=(e,r)=>{var A,k,T,S,E,w,b,y,M,H,B,R;let t=e.approval,n=(r==null?void 0:r.approval)!==!1?r==null?void 0:r.approval:void 0,o=(t==null?void 0:t.status)==="pending",a=h("div",["persona-approval-bubble","persona-w-full","persona-max-w-[85%]","persona-rounded-2xl","persona-border","persona-shadow-sm","persona-overflow-hidden"].join(" "));if(a.id=`bubble-${e.id}`,a.setAttribute("data-message-id",e.id),a.style.backgroundColor=(A=n==null?void 0:n.backgroundColor)!=null?A:"var(--persona-approval-bg, #fefce8)",a.style.borderColor=(k=n==null?void 0:n.borderColor)!=null?k:"var(--persona-approval-border, #fef08a)",!t)return a;let s=h("div","persona-flex persona-items-start persona-gap-3 persona-px-4 persona-py-3"),i=h("div","persona-flex-shrink-0 persona-mt-0.5");i.setAttribute("data-approval-icon","true");let d=t.status==="denied"?"shield-x":t.status==="timeout"?"shield-alert":"shield-check",l=t.status==="approved"?"var(--persona-feedback-success, #16a34a)":t.status==="denied"?"var(--persona-feedback-error, #dc2626)":t.status==="timeout"?"var(--persona-feedback-warning, #ca8a04)":(T=n==null?void 0:n.titleColor)!=null?T:"currentColor",u=ve(d,20,l,2);u&&i.appendChild(u);let p=h("div","persona-flex-1 persona-min-w-0"),f=h("div","persona-flex persona-items-center persona-gap-2"),m=h("span","persona-text-sm persona-font-medium persona-text-persona-primary");if(n!=null&&n.titleColor&&(m.style.color=n.titleColor),m.textContent=(S=n==null?void 0:n.title)!=null?S:"Approval Required",f.appendChild(m),!o){let W=h("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded-full persona-text-xs persona-font-medium");W.setAttribute("data-approval-status",t.status),t.status==="approved"?(W.style.backgroundColor="var(--persona-palette-colors-success-100, #dcfce7)",W.style.color="var(--persona-palette-colors-success-700, #15803d)",W.textContent="Approved"):t.status==="denied"?(W.style.backgroundColor="var(--persona-palette-colors-error-100, #fee2e2)",W.style.color="var(--persona-palette-colors-error-700, #b91c1c)",W.textContent="Denied"):t.status==="timeout"&&(W.style.backgroundColor="var(--persona-palette-colors-warning-100, #fef3c7)",W.style.color="var(--persona-palette-colors-warning-700, #b45309)",W.textContent="Timeout"),f.appendChild(W)}p.appendChild(f);let C=h("p","persona-text-sm persona-mt-0.5 persona-text-persona-muted");if(n!=null&&n.descriptionColor&&(C.style.color=n.descriptionColor),C.textContent=t.description,p.appendChild(C),t.parameters){let W=h("pre","persona-mt-2 persona-text-xs persona-p-2 persona-rounded persona-overflow-x-auto persona-max-h-32 persona-bg-persona-container persona-text-persona-primary");n!=null&&n.parameterBackgroundColor&&(W.style.backgroundColor=n.parameterBackgroundColor),n!=null&&n.parameterTextColor&&(W.style.color=n.parameterTextColor),W.style.fontSize="0.75rem",W.style.lineHeight="1rem",W.textContent=Ca(t.parameters),p.appendChild(W)}if(o){let W=h("div","persona-flex persona-gap-2 persona-mt-2");W.setAttribute("data-approval-buttons","true");let V=h("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-border-none persona-cursor-pointer");V.type="button",V.style.backgroundColor=(E=n==null?void 0:n.approveButtonColor)!=null?E:"var(--persona-approval-approve-bg, #22c55e)",V.style.color=(w=n==null?void 0:n.approveButtonTextColor)!=null?w:"#ffffff",V.setAttribute("data-approval-action","approve");let ne=ve("shield-check",14,(b=n==null?void 0:n.approveButtonTextColor)!=null?b:"#ffffff",2);ne&&(ne.style.marginRight="4px",V.appendChild(ne));let ue=document.createTextNode((y=n==null?void 0:n.approveLabel)!=null?y:"Approve");V.appendChild(ue);let Be=h("button","persona-inline-flex persona-items-center persona-px-3 persona-py-1.5 persona-rounded-md persona-text-xs persona-font-medium persona-cursor-pointer");Be.type="button",Be.style.backgroundColor=(M=n==null?void 0:n.denyButtonColor)!=null?M:"transparent",Be.style.color=(H=n==null?void 0:n.denyButtonTextColor)!=null?H:"var(--persona-feedback-error, #dc2626)",Be.style.border=`1px solid ${n!=null&&n.denyButtonTextColor?n.denyButtonTextColor:"var(--persona-palette-colors-error-200, #fca5a5)"}`,Be.setAttribute("data-approval-action","deny");let Ke=ve("shield-x",14,(B=n==null?void 0:n.denyButtonTextColor)!=null?B:"var(--persona-feedback-error, #dc2626)",2);Ke&&(Ke.style.marginRight="4px",Be.appendChild(Ke));let ye=document.createTextNode((R=n==null?void 0:n.denyLabel)!=null?R:"Deny");Be.appendChild(ye),W.append(V,Be),p.appendChild(W)}return s.append(i,p),a.appendChild(s),a};var Th=e=>{let r=[];return{buttons:r,render:(n,o,a,s,i)=>{if(e.innerHTML="",r.length=0,!n||!n.length||(s!=null?s:o?o.getMessages():[]).some(m=>m.role==="user"))return;let u=document.createDocumentFragment(),p=o?o.isStreaming():!1,f=m=>{switch(m){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};n.forEach(m=>{let C=h("button","persona-rounded-button persona-bg-persona-surface persona-px-3 persona-py-1.5 persona-text-xs persona-font-medium persona-text-persona-primary hover:persona-opacity-80 persona-cursor-pointer persona-border persona-border-persona-border");C.type="button",C.textContent=m,C.disabled=p,i!=null&&i.fontFamily&&(C.style.fontFamily=f(i.fontFamily)),i!=null&&i.fontWeight&&(C.style.fontWeight=i.fontWeight),i!=null&&i.paddingX&&(C.style.paddingLeft=i.paddingX,C.style.paddingRight=i.paddingX),i!=null&&i.paddingY&&(C.style.paddingTop=i.paddingY,C.style.paddingBottom=i.paddingY),C.addEventListener("click",()=>{!o||o.isStreaming()||(a.value="",o.sendMessage(m))}),u.appendChild(C),r.push(C)}),e.appendChild(u)}}};var Hs=class{constructor(r=2e3,t=null){this.head=0;this.count=0;this.totalCaptured=0;this.eventTypesSet=new Set;this.maxSize=r,this.buffer=new Array(r),this.store=t}push(r){var t;this.buffer[this.head]=r,this.head=(this.head+1)%this.maxSize,this.count<this.maxSize&&this.count++,this.totalCaptured++,this.eventTypesSet.add(r.type),(t=this.store)==null||t.put(r)}getAll(){return this.count===0?[]:this.count<this.maxSize?this.buffer.slice(0,this.count):[...this.buffer.slice(this.head,this.maxSize),...this.buffer.slice(0,this.head)]}async restore(){if(!this.store)return 0;let r=await this.store.getAll();if(r.length===0)return 0;let t=r.length>this.maxSize?r.slice(r.length-this.maxSize):r;for(let n of t)this.buffer[this.head]=n,this.head=(this.head+1)%this.maxSize,this.count<this.maxSize&&this.count++,this.eventTypesSet.add(n.type);return this.totalCaptured=r.length,t.length}getAllFromStore(){return this.store?this.store.getAll():Promise.resolve(this.getAll())}getRecent(r){let t=this.getAll();return r>=t.length?t:t.slice(t.length-r)}getSize(){return this.count}getTotalCaptured(){return this.totalCaptured}getEvictedCount(){return this.totalCaptured-this.count}clear(){var r;this.buffer=new Array(this.maxSize),this.head=0,this.count=0,this.totalCaptured=0,this.eventTypesSet.clear(),(r=this.store)==null||r.clear()}destroy(){var r;this.buffer=[],this.head=0,this.count=0,this.totalCaptured=0,this.eventTypesSet.clear(),(r=this.store)==null||r.destroy()}getEventTypes(){return Array.from(this.eventTypesSet)}};var Bs=class{constructor(r="persona-event-stream",t="events"){this.db=null;this.pendingWrites=[];this.flushScheduled=!1;this.isDestroyed=!1;this.dbName=r,this.storeName=t}open(){return new Promise((r,t)=>{try{let n=indexedDB.open(this.dbName,1);n.onupgradeneeded=()=>{let o=n.result;o.objectStoreNames.contains(this.storeName)||o.createObjectStore(this.storeName,{keyPath:"id"}).createIndex("timestamp","timestamp",{unique:!1})},n.onsuccess=()=>{this.db=n.result,r()},n.onerror=()=>{t(n.error)}}catch(n){t(n)}})}put(r){!this.db||this.isDestroyed||(this.pendingWrites.push(r),this.flushScheduled||(this.flushScheduled=!0,queueMicrotask(()=>this.flushWrites())))}putBatch(r){if(!(!this.db||this.isDestroyed||r.length===0))try{let n=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName);for(let o of r)n.put(o)}catch{}}getAll(){return new Promise((r,t)=>{if(!this.db){r([]);return}try{let s=this.db.transaction(this.storeName,"readonly").objectStore(this.storeName).index("timestamp").getAll();s.onsuccess=()=>{r(s.result)},s.onerror=()=>{t(s.error)}}catch(n){t(n)}})}getCount(){return new Promise((r,t)=>{if(!this.db){r(0);return}try{let a=this.db.transaction(this.storeName,"readonly").objectStore(this.storeName).count();a.onsuccess=()=>{r(a.result)},a.onerror=()=>{t(a.error)}}catch(n){t(n)}})}clear(){return new Promise((r,t)=>{if(!this.db){r();return}this.pendingWrites=[];try{let a=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).clear();a.onsuccess=()=>{r()},a.onerror=()=>{t(a.error)}}catch(n){t(n)}})}close(){this.db&&(this.db.close(),this.db=null)}destroy(){return this.isDestroyed=!0,this.pendingWrites=[],this.close(),new Promise((r,t)=>{try{let n=indexedDB.deleteDatabase(this.dbName);n.onsuccess=()=>{r()},n.onerror=()=>{t(n.error)}}catch(n){t(n)}})}flushWrites(){if(this.flushScheduled=!1,!this.db||this.isDestroyed||this.pendingWrites.length===0)return;let r=this.pendingWrites;this.pendingWrites=[];try{let n=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName);for(let o of r)n.put(o)}catch{}}};function Ba(e,r){r&&r.split(/\s+/).forEach(t=>t&&e.classList.add(t))}var C0={flow_:{bg:"var(--persona-palette-colors-success-100, #dcfce7)",text:"var(--persona-palette-colors-success-700, #166534)"},step_:{bg:"var(--persona-palette-colors-primary-100, #f5f5f5)",text:"var(--persona-palette-colors-primary-700, #0a0a0a)"},reason_:{bg:"var(--persona-palette-colors-warning-100, #ffedd5)",text:"var(--persona-palette-colors-warning-700, #9a3412)"},tool_:{bg:"var(--persona-palette-colors-purple-100, #f3e8ff)",text:"var(--persona-palette-colors-purple-700, #6b21a8)"},agent_:{bg:"var(--persona-palette-colors-teal-100, #ccfbf1)",text:"var(--persona-palette-colors-teal-700, #115e59)"},error:{bg:"var(--persona-palette-colors-error-100, #fecaca)",text:"var(--persona-palette-colors-error-700, #991b1b)"}},w0={bg:"var(--persona-palette-colors-gray-100, #f3f4f6)",text:"var(--persona-palette-colors-gray-600, #4b5563)"},v0=["flowName","stepName","reasoningText","text","name","tool","toolName"],A0=100;function S0(e,r){let t={...C0,...r};if(t[e])return t[e];for(let n of Object.keys(t))if(n.endsWith("_")&&e.startsWith(n))return t[n];return w0}function T0(e,r){return`+${((e-r)/1e3).toFixed(3)}s`}function k0(e){let r=new Date(e),t=String(r.getHours()).padStart(2,"0"),n=String(r.getMinutes()).padStart(2,"0"),o=String(r.getSeconds()).padStart(2,"0"),a=String(r.getMilliseconds()).padStart(3,"0");return`${t}:${n}:${o}.${a}`}function E0(e,r){try{let t=JSON.parse(e);if(typeof t!="object"||t===null)return null;for(let n of r){let o=n.split("."),a=t;for(let s of o)if(a&&typeof a=="object"&&a!==null)a=a[s];else{a=void 0;break}if(typeof a=="string"&&a.trim())return a.trim()}}catch{}return null}function M0(e){var r;return(r=navigator.clipboard)!=null&&r.writeText?navigator.clipboard.writeText(e):new Promise(t=>{let n=document.createElement("textarea");n.value=e,n.style.position="fixed",n.style.opacity="0",document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),t()})}function L0(e){let r;try{r=JSON.parse(e.payload)}catch{r=e.payload}return JSON.stringify({type:e.type,timestamp:new Date(e.timestamp).toISOString(),payload:r},null,2)}function P0(e,r,t){let n,o;try{o=JSON.parse(e.payload),n=JSON.stringify(o,null,2)}catch{o=e.payload,n=e.payload}let a=r.find(i=>i.renderEventStreamPayload);if(a!=null&&a.renderEventStreamPayload&&t){let i=a.renderEventStreamPayload({event:e,config:t,defaultRenderer:()=>s(),parsedPayload:o});if(i)return i}return s();function s(){let i=h("div","persona-bg-persona-container persona-border-t persona-border-persona-divider persona-px-3 persona-py-2 persona-ml-4 persona-mr-3 persona-mb-1 persona-rounded-b persona-overflow-auto persona-max-h-[300px]"),d=h("pre","persona-m-0 persona-whitespace-pre-wrap persona-break-all persona-text-[11px] persona-text-persona-secondary persona-font-mono");return d.textContent=n,i.appendChild(d),i}}function kp(e,r,t,n,o,a,s,i){var f;let d=o.has(e.id),l=h("div","persona-border-b persona-border-persona-divider persona-text-xs");Ba(l,(f=n.classNames)==null?void 0:f.eventRow);let u=s.find(m=>m.renderEventStreamRow);if(u!=null&&u.renderEventStreamRow&&i){let m=u.renderEventStreamRow({event:e,index:r,config:i,defaultRenderer:()=>p(),isExpanded:d,onToggleExpand:()=>a(e.id)});if(m)return l.appendChild(m),l}return l.appendChild(p()),l;function p(){var V,ne;let m=h("div",""),C=h("div","persona-flex persona-items-center persona-gap-2 persona-px-3 persona-py-3 hover:persona-bg-persona-container persona-cursor-pointer persona-group");C.setAttribute("data-event-id",e.id);let A=h("span","persona-flex-shrink-0 persona-text-persona-muted persona-w-4 persona-text-center persona-flex persona-items-center persona-justify-center"),k=ve(d?"chevron-down":"chevron-right","14px","currentColor",2);k&&A.appendChild(k);let T=h("span","persona-text-[11px] persona-text-persona-muted persona-whitespace-nowrap persona-flex-shrink-0 persona-font-mono persona-w-[70px]"),S=(V=n.timestampFormat)!=null?V:"relative";T.textContent=S==="relative"?T0(e.timestamp,t):k0(e.timestamp);let E=null;n.showSequenceNumbers!==!1&&(E=h("span","persona-text-[11px] persona-text-persona-muted persona-font-mono persona-flex-shrink-0 persona-w-[28px] persona-text-right"),E.textContent=String(r+1));let w=S0(e.type,n.badgeColors),b=h("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded persona-text-[11px] persona-font-mono persona-font-medium persona-whitespace-nowrap persona-flex-shrink-0 persona-border");b.style.backgroundColor=w.bg,b.style.color=w.text,b.style.borderColor=w.text+"50",b.textContent=e.type;let y=(ne=n.descriptionFields)!=null?ne:v0,M=E0(e.payload,y),H=null;M&&(H=h("span","persona-text-[11px] persona-text-persona-secondary persona-truncate persona-min-w-0"),H.textContent=M);let B=h("div","persona-flex-1 persona-min-w-0"),R=h("button","persona-text-persona-muted hover:persona-text-persona-primary persona-cursor-pointer persona-flex-shrink-0 persona-border-none persona-bg-transparent persona-p-0"),W=ve("clipboard","12px","currentColor",1.5);return W&&R.appendChild(W),R.addEventListener("click",async ue=>{ue.stopPropagation(),await M0(L0(e)),R.innerHTML="";let Be=ve("check","12px","currentColor",1.5);Be&&R.appendChild(Be),setTimeout(()=>{R.innerHTML="";let Ke=ve("clipboard","12px","currentColor",1.5);Ke&&R.appendChild(Ke)},1500)}),C.appendChild(A),C.appendChild(T),E&&C.appendChild(E),C.appendChild(b),H&&C.appendChild(H),C.appendChild(B),C.appendChild(R),m.appendChild(C),d&&m.appendChild(P0(e,s,i)),m}}function kh(e){var m,C,A,k,T;let{buffer:r,getFullHistory:t,onClose:n,config:o,plugins:a=[]}=e,s=(m=o==null?void 0:o.features)==null?void 0:m.scrollToBottom,i=(s==null?void 0:s.enabled)!==!1,d=(C=s==null?void 0:s.iconName)!=null?C:"arrow-down",l=(A=s==null?void 0:s.label)!=null?A:"",u=(T=(k=o==null?void 0:o.features)==null?void 0:k.eventStream)!=null?T:{},p=a.find(S=>S.renderEventStreamView);if(p!=null&&p.renderEventStreamView&&o){let S=p.renderEventStreamView({config:o,events:r.getAll(),defaultRenderer:()=>f().element,onClose:n});if(S)return{element:S,update:()=>{},destroy:()=>{}}}return f();function f(){let S=u.classNames,E=h("div","persona-event-stream-view persona-flex persona-flex-col persona-flex-1 persona-min-h-0");Ba(E,S==null?void 0:S.panel);let w=[],b="",y="",M=null,H=[],B={},R=0,W=Ji(),V=0,ne=0,ue=!1,Be=null,Ke=!1,ye=0,me=new Set,We=new Map,Xe="",Y="",Ee=null,G,ce,de,pe,Re;function Ye(){let F=h("div","persona-flex persona-flex-col persona-flex-shrink-0"),xe=h("div","persona-flex persona-items-center persona-gap-2 persona-px-4 persona-py-3 persona-pb-0 persona-border-persona-divider persona-bg-persona-surface persona-overflow-hidden");Ba(xe,S==null?void 0:S.headerBar);let be=h("span","persona-text-sm persona-font-medium persona-text-persona-primary persona-whitespace-nowrap");be.textContent="Events",G=h("span","persona-text-[11px] persona-font-mono persona-bg-persona-container persona-text-persona-muted persona-px-2 persona-py-0.5 persona-rounded persona-border persona-border-persona-border"),G.textContent="0";let it=h("div","persona-flex-1");ce=h("select","persona-text-xs persona-bg-persona-surface persona-border persona-border-persona-border persona-rounded persona-px-2.5 persona-py-1 persona-text-persona-primary persona-cursor-pointer");let Ge=h("option","");Ge.value="",Ge.textContent="All events",ce.appendChild(Ge),de=h("button","persona-inline-flex persona-items-center persona-gap-1.5 persona-rounded persona-text-xs persona-text-persona-muted hover:persona-bg-persona-container hover:persona-text-persona-primary persona-cursor-pointer persona-border persona-border-persona-border persona-bg-persona-surface persona-flex-shrink-0 persona-px-2.5 persona-py-1"),de.type="button",de.title="Copy All";let ar=ve("clipboard-copy","12px","currentColor",1.5);ar&&de.appendChild(ar);let Pt=h("span","persona-text-xs");Pt.textContent="Copy All",de.appendChild(Pt),xe.appendChild(be),xe.appendChild(G),xe.appendChild(it),xe.appendChild(ce),xe.appendChild(de);let kt=h("div","persona-relative persona-px-4 persona-py-2.5 persona-border-b persona-border-persona-divider persona-bg-persona-surface");Ba(kt,S==null?void 0:S.searchBar);let rt=ve("search","14px","var(--persona-muted, #9ca3af)",1.5),lt=h("span","persona-absolute persona-left-6 persona-top-1/2 persona--translate-y-1/2 persona-pointer-events-none persona-flex persona-items-center");rt&<.appendChild(rt),pe=h("input","persona-text-sm persona-bg-persona-surface persona-border persona-border-persona-border persona-rounded-md persona-pl-8 persona-pr-3 persona-py-1 persona-w-full persona-text-persona-primary"),Ba(pe,S==null?void 0:S.searchInput),pe.type="text",pe.placeholder="Search event payloads...",Re=h("button","persona-absolute persona-right-5 persona-top-1/2 persona--translate-y-1/2 persona-text-persona-muted hover:persona-text-persona-primary persona-cursor-pointer persona-border-none persona-bg-transparent persona-p-0 persona-leading-none"),Re.type="button",Re.style.display="none";let rr=ve("x","12px","currentColor",2);return rr&&Re.appendChild(rr),kt.appendChild(lt),kt.appendChild(pe),kt.appendChild(Re),F.appendChild(xe),F.appendChild(kt),F}let J,ie=a.find(F=>F.renderEventStreamToolbar);if(ie!=null&&ie.renderEventStreamToolbar&&o){let F=ie.renderEventStreamToolbar({config:o,defaultRenderer:()=>Ye(),eventCount:r.getSize(),filteredCount:0,onFilterChange:xe=>{b=xe,ae(),Qt()},onSearchChange:xe=>{y=xe,ae(),Qt()}});J=F!=null?F:Ye()}else J=Ye();let Ue=h("div","persona-text-xs persona-text-persona-muted persona-text-center persona-py-0.5 persona-px-4 persona-bg-persona-container persona-border-b persona-border-persona-divider persona-italic persona-flex-shrink-0");Ue.style.display="none";let K=h("div","persona-flex-1 persona-min-h-0 persona-relative"),j=h("div","persona-event-stream-list persona-overflow-y-auto persona-min-h-0");j.style.height="100%";let Ce=h("div","persona-scroll-to-bottom-indicator persona-absolute persona-bottom-3 persona-left-1/2 persona-transform persona--translate-x-1/2 persona-cursor-pointer persona-z-10 persona-text-xs");Ba(Ce,S==null?void 0:S.scrollIndicator),Ce.style.display="none",Ce.setAttribute("data-persona-scroll-to-bottom-has-label",l?"true":"false");let De=ve(d,"14px","currentColor",2);De&&Ce.appendChild(De);let oe=h("span","");oe.textContent=l,Ce.appendChild(oe);let Se=h("div","persona-flex persona-items-center persona-justify-center persona-h-full persona-text-sm persona-text-persona-muted");Se.style.display="none",K.appendChild(j),K.appendChild(Se),K.appendChild(Ce),E.setAttribute("tabindex","0"),E.appendChild(J),E.appendChild(Ue),E.appendChild(K);function ge(){let F=r.getAll(),xe={};for(let Pt of F)xe[Pt.type]=(xe[Pt.type]||0)+1;let be=Object.keys(xe).sort(),it=be.length!==H.length||!be.every((Pt,kt)=>Pt===H[kt]),Ge=!it&&be.some(Pt=>xe[Pt]!==B[Pt]),Wt=F.length!==Object.values(B).reduce((Pt,kt)=>Pt+kt,0);if(!it&&!Ge&&!Wt||(H=be,B=xe,!ce))return;let ar=ce.value;if(ce.options[0].textContent="All events",it){for(;ce.options.length>1;)ce.remove(1);for(let Pt of be){let kt=h("option","");kt.value=Pt,kt.textContent=`${Pt} (${xe[Pt]||0})`,ce.appendChild(kt)}ar&&be.includes(ar)?ce.value=ar:ar&&(ce.value="",b="")}else for(let Pt=1;Pt<ce.options.length;Pt++){let kt=ce.options[Pt];kt.textContent=`${kt.value} (${xe[kt.value]||0})`}}function Rt(){let F=r.getAll();if(b&&(F=F.filter(xe=>xe.type===b)),y){let xe=y.toLowerCase();F=F.filter(be=>be.type.toLowerCase().includes(xe)||be.payload.toLowerCase().includes(xe))}return F}function Me(){return b!==""||y!==""}function ae(){R=0,V=0,W.resume(),Ce.style.display="none"}function ur(F){me.has(F)?me.delete(F):me.add(F),Ee=F;let xe=j.scrollTop,be=W.isFollowing();Ke=!0,W.pause(),Qt(),j.scrollTop=xe,be&&W.resume(),Ke=!1}function Ut(){return vs(j,50)}function Qt(){ne=Date.now(),ue=!1,ge();let F=r.getEvictedCount();F>0?(Ue.textContent=`${F.toLocaleString()} older events truncated`,Ue.style.display=""):Ue.style.display="none",w=Rt();let xe=w.length,be=r.getSize()>0;G&&(G.textContent=String(r.getSize())),xe===0&&be&&Me()?(Se.textContent=y?`No events matching '${y}'`:"No events matching filter",Se.style.display="",j.style.display="none"):(Se.style.display="none",j.style.display=""),de&&(de.title=Me()?`Copy Filtered (${xe})`:"Copy All"),i&&!W.isFollowing()&&xe>R&&(V+=xe-R,oe.textContent=l?`${l}${V>0?` (${V})`:""}`:"",Ce.style.display=""),R=xe;let it=r.getAll(),Ge=it.length>0?it[0].timestamp:0,Wt=new Set(w.map(kt=>kt.id));for(let kt of me)Wt.has(kt)||me.delete(kt);let ar=b!==Xe||y!==Y,Pt=We.size===0&&w.length>0;if(ar||Pt||w.length===0){j.innerHTML="",We.clear();let kt=document.createDocumentFragment();for(let rt=0;rt<w.length;rt++){let lt=kp(w[rt],rt,Ge,u,me,ur,a,o);We.set(w[rt].id,lt),kt.appendChild(lt)}j.appendChild(kt),Xe=b,Y=y,Ee=null}else{if(Ee!==null){let rt=We.get(Ee);if(rt&&rt.parentNode===j){let lt=w.findIndex(rr=>rr.id===Ee);if(lt>=0){let rr=kp(w[lt],lt,Ge,u,me,ur,a,o);j.insertBefore(rr,rt),rt.remove(),We.set(Ee,rr)}}Ee=null}let kt=new Set(w.map(rt=>rt.id));for(let[rt,lt]of We)kt.has(rt)||(lt.remove(),We.delete(rt));for(let rt=0;rt<w.length;rt++){let lt=w[rt];if(!We.has(lt.id)){let rr=kp(lt,rt,Ge,u,me,ur,a,o);We.set(lt.id,rr),j.appendChild(rr)}}}W.isFollowing()&&(j.scrollTop=j.scrollHeight)}function Or(){if(Date.now()-ne>=A0){Be!==null&&(cancelAnimationFrame(Be),Be=null),Qt();return}ue||(ue=!0,Be=requestAnimationFrame(()=>{Be=null,Qt()}))}let vr=(F,xe)=>{if(!de)return;de.innerHTML="";let be=ve(F,"12px","currentColor",1.5);be&&de.appendChild(be);let it=h("span","persona-text-xs");it.textContent="Copy All",de.appendChild(it),setTimeout(()=>{de.innerHTML="";let Ge=ve("clipboard-copy","12px","currentColor",1.5);Ge&&de.appendChild(Ge);let Wt=h("span","persona-text-xs");Wt.textContent="Copy All",de.appendChild(Wt),de.disabled=!1},xe)},Oe=async()=>{if(de){de.disabled=!0;try{let F;Me()?F=w:t?(F=await t(),F.length===0&&(F=r.getAll())):F=r.getAll();let xe=F.map(be=>{try{return JSON.parse(be.payload)}catch{return be.payload}});await navigator.clipboard.writeText(JSON.stringify(xe,null,2)),vr("check",1500)}catch{vr("x",1500)}}},q=()=>{ce&&(b=ce.value,ae(),Qt())},Te=()=>{!pe||!Re||(Re.style.display=pe.value?"":"none",M&&clearTimeout(M),M=setTimeout(()=>{y=pe.value,ae(),Qt()},150))},_e=()=>{!pe||!Re||(pe.value="",y="",Re.style.display="none",M&&clearTimeout(M),ae(),Qt())},Ne=()=>{if(Ke)return;let F=j.scrollTop,{action:xe,nextLastScrollTop:be}=Ki({following:W.isFollowing(),currentScrollTop:F,lastScrollTop:ye,nearBottom:Ut(),userScrollThreshold:1,resumeRequiresDownwardScroll:!0});ye=be,xe==="resume"?(W.resume(),V=0,Ce.style.display="none"):xe==="pause"&&(W.pause(),i&&(oe.textContent=l,Ce.style.display=""))},qe=F=>{let xe=Yi({following:W.isFollowing(),deltaY:F.deltaY,nearBottom:Ut(),resumeWhenNearBottom:!0});xe==="pause"?(W.pause(),i&&(oe.textContent=l,Ce.style.display="")):xe==="resume"&&(W.resume(),V=0,Ce.style.display="none")},st=()=>{i&&(j.scrollTop=j.scrollHeight,W.resume(),V=0,Ce.style.display="none")},nt=F=>{let xe=F.target;if(!xe||xe.closest("button"))return;let be=xe.closest("[data-event-id]");if(!be)return;let it=be.getAttribute("data-event-id");it&&ur(it)},pt=F=>{if((F.metaKey||F.ctrlKey)&&F.key==="f"){F.preventDefault(),pe==null||pe.focus(),pe==null||pe.select();return}F.key==="Escape"&&(pe&&document.activeElement===pe?(_e(),pe.blur(),E.focus()):n&&n())};de&&de.addEventListener("click",Oe),ce&&ce.addEventListener("change",q),pe&&pe.addEventListener("input",Te),Re&&Re.addEventListener("click",_e),j.addEventListener("scroll",Ne),j.addEventListener("wheel",qe,{passive:!0}),j.addEventListener("click",nt),Ce.addEventListener("click",st),E.addEventListener("keydown",pt);function Nt(){M&&clearTimeout(M),Be!==null&&(cancelAnimationFrame(Be),Be=null),ue=!1,We.clear(),de&&de.removeEventListener("click",Oe),ce&&ce.removeEventListener("change",q),pe&&pe.removeEventListener("input",Te),Re&&Re.removeEventListener("click",_e),j.removeEventListener("scroll",Ne),j.removeEventListener("wheel",qe),j.removeEventListener("click",nt),Ce.removeEventListener("click",st),E.removeEventListener("keydown",pt)}return{element:E,update:Or,destroy:Nt}}}function Eh(e,r){let t=typeof e.title=="string"&&e.title?e.title:"Untitled artifact",n=typeof e.artifactId=="string"?e.artifactId:"",o=e.status==="streaming"?"streaming":"complete",s=(typeof e.artifactType=="string"?e.artifactType:"markdown")==="component"?"Component":"Document",i=document.createElement("div");i.className="persona-flex persona-w-full persona-max-w-full persona-items-center persona-gap-3 persona-rounded-xl persona-px-4 persona-py-3",i.style.border="1px solid var(--persona-border, #e5e7eb)",i.style.backgroundColor="var(--persona-surface, #ffffff)",i.style.cursor="pointer",i.tabIndex=0,i.setAttribute("role","button"),i.setAttribute("aria-label",`Open ${t} in artifact panel`),n&&i.setAttribute("data-open-artifact",n);let d=document.createElement("div");d.className="persona-flex persona-h-10 persona-w-10 persona-flex-shrink-0 persona-items-center persona-justify-center persona-rounded-lg",d.style.border="1px solid var(--persona-border, #e5e7eb)",d.style.color="var(--persona-muted, #9ca3af)",d.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/><polyline points="14 2 14 8 20 8"/></svg>';let l=document.createElement("div");l.className="persona-min-w-0 persona-flex-1 persona-flex persona-flex-col persona-gap-0.5";let u=document.createElement("div");u.className="persona-truncate persona-text-sm persona-font-medium",u.style.color="var(--persona-text, #1f2937)",u.textContent=t;let p=document.createElement("div");if(p.className="persona-text-xs persona-flex persona-items-center persona-gap-1.5",p.style.color="var(--persona-muted, #9ca3af)",o==="streaming"){let f=document.createElement("span");f.className="persona-inline-block persona-w-1.5 persona-h-1.5 persona-rounded-full",f.style.backgroundColor="var(--persona-primary, #171717)",f.style.animation="persona-pulse 1.5s ease-in-out infinite",p.appendChild(f);let m=document.createElement("span");m.textContent=`Generating ${s.toLowerCase()}...`,p.appendChild(m)}else p.textContent=s;if(l.append(u,p),i.append(d,l),o==="complete"){let f=document.createElement("button");f.type="button",f.textContent="Download",f.title=`Download ${t}`,f.className="persona-flex-shrink-0 persona-rounded-md persona-px-3 persona-py-1.5 persona-text-xs persona-font-medium",f.style.border="1px solid var(--persona-border, #e5e7eb)",f.style.color="var(--persona-text, #1f2937)",f.style.backgroundColor="transparent",f.style.cursor="pointer",f.setAttribute("data-download-artifact",n),i.append(f)}return i}var Mh=(e,r)=>{var n,o,a;let t=(a=(o=(n=r==null?void 0:r.config)==null?void 0:n.features)==null?void 0:o.artifacts)==null?void 0:a.renderCard;if(t){let s=typeof e.title=="string"&&e.title?e.title:"Untitled artifact",i=typeof e.artifactId=="string"?e.artifactId:"",d=e.status==="streaming"?"streaming":"complete",l=typeof e.artifactType=="string"?e.artifactType:"markdown",u=t({artifact:{artifactId:i,title:s,artifactType:l,status:d},config:r.config,defaultRenderer:()=>Eh(e,r)});if(u)return u}return Eh(e,r)};var Ep=class{constructor(){this.components=new Map}register(r,t){this.components.has(r)&&console.warn(`[ComponentRegistry] Component "${r}" is already registered. Overwriting.`),this.components.set(r,t)}unregister(r){this.components.delete(r)}get(r){return this.components.get(r)}has(r){return this.components.has(r)}getAllNames(){return Array.from(this.components.keys())}clear(){this.components.clear()}registerAll(r){Object.entries(r).forEach(([t,n])=>{this.register(t,n)})}},io=new Ep;io.register("PersonaArtifactCard",Mh);function I0(e){var o;let r=h("div","persona-rounded-lg persona-border persona-border-persona-border persona-p-3 persona-text-persona-primary"),t=h("div","persona-font-semibold persona-text-sm persona-mb-2");t.textContent=e.component?`Component: ${e.component}`:"Component";let n=h("pre","persona-font-mono persona-text-xs persona-whitespace-pre-wrap persona-overflow-x-auto");return n.textContent=JSON.stringify((o=e.props)!=null?o:{},null,2),r.appendChild(t),r.appendChild(n),r}function Lh(e,r){var de,pe,Re,Ye;let t=(pe=(de=e.features)==null?void 0:de.artifacts)==null?void 0:pe.layout,o=((Re=t==null?void 0:t.toolbarPreset)!=null?Re:"default")==="document",a=(Ye=t==null?void 0:t.panePadding)==null?void 0:Ye.trim(),s=e.markdown?Xo(e.markdown):null,i=ba(e.sanitize),d=J=>{let ie=s?s(J):Jo(J);return i?i(ie):ie},l=typeof document!="undefined"?h("div","persona-artifact-backdrop persona-fixed persona-inset-0 persona-z-[55] persona-bg-black/30 persona-hidden md:persona-hidden"):null,u=()=>{l==null||l.classList.add("persona-hidden"),p.classList.remove("persona-artifact-drawer-open"),W==null||W.hide()};l&&l.addEventListener("click",()=>{var J;u(),(J=r.onDismiss)==null||J.call(r)});let p=h("aside","persona-artifact-pane persona-flex persona-flex-col persona-min-h-0 persona-min-w-0 persona-bg-persona-surface persona-text-persona-primary persona-border-l persona-border-persona-border");p.setAttribute("data-persona-theme-zone","artifact-pane"),o&&p.classList.add("persona-artifact-pane-document");let f=h("div","persona-artifact-toolbar persona-flex persona-items-center persona-justify-between persona-gap-2 persona-px-2 persona-py-2 persona-border-b persona-border-persona-border persona-shrink-0");f.setAttribute("data-persona-theme-zone","artifact-toolbar"),o&&f.classList.add("persona-artifact-toolbar-document");let m=h("span","persona-text-xs persona-font-medium persona-truncate");m.textContent="Artifacts";let C=h("button","persona-rounded-md persona-border persona-border-persona-border persona-px-2 persona-py-1 persona-text-xs persona-bg-persona-surface");C.type="button",C.textContent="Close",C.setAttribute("aria-label","Close artifacts panel"),C.addEventListener("click",()=>{var J;u(),(J=r.onDismiss)==null||J.call(r)});let A="rendered",k=h("div","persona-flex persona-items-center persona-gap-1 persona-shrink-0 persona-artifact-toggle-group"),T=o?Zt({icon:"eye",label:"Rendered view",className:"persona-artifact-doc-icon-btn persona-artifact-view-btn"}):Zt({icon:"eye",label:"Rendered view"}),S=o?Zt({icon:"code-2",label:"Source",className:"persona-artifact-doc-icon-btn persona-artifact-code-btn"}):Zt({icon:"code-2",label:"Source"}),E=h("div","persona-flex persona-items-center persona-gap-1 persona-shrink-0"),w=(t==null?void 0:t.documentToolbarShowCopyLabel)===!0,b=(t==null?void 0:t.documentToolbarShowCopyChevron)===!0,y=t==null?void 0:t.documentToolbarCopyMenuItems,M=!!(b&&y&&y.length>0),H=null,B,R=null,W=null;if(o&&(w||b)&&!M){if(B=w?Ps({icon:"copy",label:"Copy",iconSize:14,className:"persona-artifact-doc-copy-btn"}):Zt({icon:"copy",label:"Copy",className:"persona-artifact-doc-copy-btn"}),b){let J=ve("chevron-down",14,"currentColor",2);J&&B.appendChild(J)}}else o&&M?(H=h("div","persona-relative persona-inline-flex persona-items-center persona-gap-0 persona-rounded-md"),B=w?Ps({icon:"copy",label:"Copy",iconSize:14,className:"persona-artifact-doc-copy-btn"}):Zt({icon:"copy",label:"Copy",className:"persona-artifact-doc-copy-btn"}),R=Zt({icon:"chevron-down",label:"More copy options",size:14,className:"persona-artifact-doc-copy-menu-chevron persona-artifact-doc-icon-btn",aria:{"aria-haspopup":"true","aria-expanded":"false"}}),H.append(B,R)):o?B=Zt({icon:"copy",label:"Copy",className:"persona-artifact-doc-icon-btn"}):B=Zt({icon:"copy",label:"Copy"});let V=o?Zt({icon:"refresh-cw",label:"Refresh",className:"persona-artifact-doc-icon-btn"}):Zt({icon:"refresh-cw",label:"Refresh"}),ne=o?Zt({icon:"x",label:"Close",className:"persona-artifact-doc-icon-btn"}):Zt({icon:"x",label:"Close"}),ue=()=>{var j,Ce,De;let J=(j=Xe.find(oe=>oe.id===Y))!=null?j:Xe[Xe.length-1],ie=(Ce=J==null?void 0:J.id)!=null?Ce:null,Ue=(J==null?void 0:J.artifactType)==="markdown"&&(De=J.markdown)!=null?De:"",K=J?JSON.stringify({component:J.component,props:J.props},null,2):"";return{markdown:Ue,jsonPayload:K,id:ie}},Be=async()=>{var j;let{markdown:J,jsonPayload:ie}=ue(),Ue=(j=Xe.find(Ce=>Ce.id===Y))!=null?j:Xe[Xe.length-1],K=(Ue==null?void 0:Ue.artifactType)==="markdown"?J:Ue?ie:"";try{await navigator.clipboard.writeText(K)}catch{}};if(B.addEventListener("click",async()=>{let J=t==null?void 0:t.onDocumentToolbarCopyMenuSelect;if(J&&M){let{markdown:ie,jsonPayload:Ue,id:K}=ue();try{await J({actionId:"primary",artifactId:K,markdown:ie,jsonPayload:Ue})}catch{}return}await Be()}),R&&(y!=null&&y.length)){let J=()=>{var Ue;return(Ue=p.closest("[data-persona-root]"))!=null?Ue:document.body},ie=()=>{W=To({items:y.map(Ue=>({id:Ue.id,label:Ue.label})),onSelect:async Ue=>{let{markdown:K,jsonPayload:j,id:Ce}=ue(),De=t==null?void 0:t.onDocumentToolbarCopyMenuSelect;try{De?await De({actionId:Ue,artifactId:Ce,markdown:K,jsonPayload:j}):Ue==="markdown"||Ue==="md"?await navigator.clipboard.writeText(K):Ue==="json"||Ue==="source"?await navigator.clipboard.writeText(j):await navigator.clipboard.writeText(K||j)}catch{}},anchor:H!=null?H:R,position:"bottom-right",portal:J()})};p.isConnected?ie():requestAnimationFrame(ie),R.addEventListener("click",Ue=>{Ue.stopPropagation(),W==null||W.toggle()})}V.addEventListener("click",async()=>{var J;try{await((J=t==null?void 0:t.onDocumentToolbarRefresh)==null?void 0:J.call(t))}catch{}G()}),ne.addEventListener("click",()=>{var J;u(),(J=r.onDismiss)==null||J.call(r)});let Ke=()=>{o&&(T.setAttribute("aria-pressed",A==="rendered"?"true":"false"),S.setAttribute("aria-pressed",A==="source"?"true":"false"))};T.addEventListener("click",()=>{A="rendered",Ke(),G()}),S.addEventListener("click",()=>{A="source",Ke(),G()});let ye=h("span","persona-min-w-0 persona-flex-1 persona-text-xs persona-font-medium persona-text-persona-primary persona-truncate persona-text-center md:persona-text-left");o?(f.replaceChildren(),k.append(T,S),H?E.append(H,V,ne):E.append(B,V,ne),f.append(k,ye,E),Ke()):(f.appendChild(m),f.appendChild(C)),a&&(f.style.paddingLeft=a,f.style.paddingRight=a);let me=h("div","persona-artifact-list persona-shrink-0 persona-flex persona-gap-1 persona-overflow-x-auto persona-p-2 persona-border-b persona-border-persona-border"),We=h("div","persona-artifact-content persona-flex-1 persona-min-h-0 persona-overflow-y-auto persona-p-3");a&&(me.style.paddingLeft=a,me.style.paddingRight=a,We.style.padding=a),p.appendChild(f),p.appendChild(me),p.appendChild(We);let Xe=[],Y=null,Ee=!1,G=()=>{var K,j,Ce,De;let J=o&&Xe.length<=1;me.classList.toggle("persona-hidden",J),me.replaceChildren();for(let oe of Xe){let Se=h("button","persona-artifact-tab persona-shrink-0 persona-rounded-lg persona-px-2 persona-py-1 persona-text-xs persona-border persona-border-transparent persona-text-persona-primary");Se.type="button",Se.textContent=oe.title||oe.id.slice(0,8),oe.id===Y&&Se.classList.add("persona-bg-persona-container","persona-border-persona-border"),Se.addEventListener("click",()=>r.onSelect(oe.id)),me.appendChild(Se)}We.replaceChildren();let ie=Y&&Xe.find(oe=>oe.id===Y)||Xe[Xe.length-1];if(!ie)return;if(o){let oe=ie.artifactType==="markdown"?"MD":(K=ie.component)!=null?K:"Component",ge=(ie.title||"Document").trim().replace(/\s*·\s*MD\s*$/i,"").trim()||"Document";ye.textContent=`${ge} \xB7 ${oe}`}else m.textContent="Artifacts";if(ie.artifactType==="markdown"){if(o&&A==="source"){let Se=h("pre","persona-font-mono persona-text-xs persona-whitespace-pre-wrap persona-break-words persona-text-persona-primary");Se.textContent=(j=ie.markdown)!=null?j:"",We.appendChild(Se);return}let oe=h("div","persona-text-sm persona-leading-relaxed persona-markdown-bubble");oe.innerHTML=d((Ce=ie.markdown)!=null?Ce:""),We.appendChild(oe);return}let Ue=ie.component?io.get(ie.component):void 0;if(Ue){let Se={message:{id:ie.id,role:"assistant",content:"",createdAt:new Date().toISOString()},config:e,updateProps:()=>{}};try{let ge=Ue((De=ie.props)!=null?De:{},Se);if(ge){We.appendChild(ge);return}}catch{}}We.appendChild(I0(ie))},ce=()=>{var ie;let J=Xe.length>0;if(p.classList.toggle("persona-hidden",!J),l){let Ue=typeof p.closest=="function"?p.closest("[data-persona-root]"):null,j=((ie=Ue==null?void 0:Ue.classList.contains("persona-artifact-narrow-host"))!=null?ie:!1)||typeof window!="undefined"&&window.matchMedia("(max-width: 640px)").matches;J&&j&&Ee?(l.classList.remove("persona-hidden"),p.classList.add("persona-artifact-drawer-open")):(l.classList.add("persona-hidden"),p.classList.remove("persona-artifact-drawer-open"))}};return{element:p,backdrop:l,update(J){var ie,Ue,K;Xe=J.artifacts,Y=(K=(Ue=J.selectedId)!=null?Ue:(ie=J.artifacts[J.artifacts.length-1])==null?void 0:ie.id)!=null?K:null,Xe.length>0&&(Ee=!0),G(),ce()},setMobileOpen(J){Ee=J,!J&&l?(l.classList.add("persona-hidden"),p.classList.remove("persona-artifact-drawer-open")):ce()}}}function Sn(e){var r,t;return((t=(r=e==null?void 0:e.features)==null?void 0:r.artifacts)==null?void 0:t.enabled)===!0}function Ph(e,r){var a,s,i,d;if(e.classList.remove("persona-artifact-border-full","persona-artifact-border-left"),e.style.removeProperty("--persona-artifact-pane-border"),e.style.removeProperty("--persona-artifact-pane-border-left"),!Sn(r))return;let t=(s=(a=r.features)==null?void 0:a.artifacts)==null?void 0:s.layout,n=(i=t==null?void 0:t.paneBorder)==null?void 0:i.trim(),o=(d=t==null?void 0:t.paneBorderLeft)==null?void 0:d.trim();n?(e.classList.add("persona-artifact-border-full"),e.style.setProperty("--persona-artifact-pane-border",n)):o&&(e.classList.add("persona-artifact-border-left"),e.style.setProperty("--persona-artifact-pane-border-left",o))}function R0(e){e.style.removeProperty("--persona-artifact-doc-toolbar-icon-color"),e.style.removeProperty("--persona-artifact-doc-toggle-active-bg"),e.style.removeProperty("--persona-artifact-doc-toggle-active-border")}function gl(e,r){var d,l,u,p,f,m,C,A,k,T;if(!Sn(r)){e.style.removeProperty("--persona-artifact-split-gap"),e.style.removeProperty("--persona-artifact-pane-width"),e.style.removeProperty("--persona-artifact-pane-max-width"),e.style.removeProperty("--persona-artifact-pane-min-width"),e.style.removeProperty("--persona-artifact-pane-bg"),e.style.removeProperty("--persona-artifact-pane-padding"),R0(e),Ph(e,r);return}let t=(l=(d=r.features)==null?void 0:d.artifacts)==null?void 0:l.layout;e.style.setProperty("--persona-artifact-split-gap",(u=t==null?void 0:t.splitGap)!=null?u:"0.5rem"),e.style.setProperty("--persona-artifact-pane-width",(p=t==null?void 0:t.paneWidth)!=null?p:"40%"),e.style.setProperty("--persona-artifact-pane-max-width",(f=t==null?void 0:t.paneMaxWidth)!=null?f:"28rem"),t!=null&&t.paneMinWidth?e.style.setProperty("--persona-artifact-pane-min-width",t.paneMinWidth):e.style.removeProperty("--persona-artifact-pane-min-width");let n=(m=t==null?void 0:t.paneBackground)==null?void 0:m.trim();n?e.style.setProperty("--persona-artifact-pane-bg",n):e.style.removeProperty("--persona-artifact-pane-bg");let o=(C=t==null?void 0:t.panePadding)==null?void 0:C.trim();o?e.style.setProperty("--persona-artifact-pane-padding",o):e.style.removeProperty("--persona-artifact-pane-padding");let a=(A=t==null?void 0:t.documentToolbarIconColor)==null?void 0:A.trim();a?e.style.setProperty("--persona-artifact-doc-toolbar-icon-color",a):e.style.removeProperty("--persona-artifact-doc-toolbar-icon-color");let s=(k=t==null?void 0:t.documentToolbarToggleActiveBackground)==null?void 0:k.trim();s?e.style.setProperty("--persona-artifact-doc-toggle-active-bg",s):e.style.removeProperty("--persona-artifact-doc-toggle-active-bg");let i=(T=t==null?void 0:t.documentToolbarToggleActiveBorderColor)==null?void 0:T.trim();i?e.style.setProperty("--persona-artifact-doc-toggle-active-border",i):e.style.removeProperty("--persona-artifact-doc-toggle-active-border"),Ph(e,r)}var Ih=["panel","seamless"];function hl(e,r){var i,d,l,u,p,f;for(let m of Ih)e.classList.remove(`persona-artifact-appearance-${m}`);if(e.classList.remove("persona-artifact-unified-split"),e.style.removeProperty("--persona-artifact-pane-radius"),e.style.removeProperty("--persona-artifact-pane-shadow"),e.style.removeProperty("--persona-artifact-unified-outer-radius"),!Sn(r))return;let t=(d=(i=r.features)==null?void 0:i.artifacts)==null?void 0:d.layout,n=(l=t==null?void 0:t.paneAppearance)!=null?l:"panel",o=Ih.includes(n)?n:"panel";e.classList.add(`persona-artifact-appearance-${o}`);let a=(u=t==null?void 0:t.paneBorderRadius)==null?void 0:u.trim();a&&e.style.setProperty("--persona-artifact-pane-radius",a);let s=(p=t==null?void 0:t.paneShadow)==null?void 0:p.trim();if(s&&e.style.setProperty("--persona-artifact-pane-shadow",s),(t==null?void 0:t.unifiedSplitChrome)===!0){e.classList.add("persona-artifact-unified-split");let m=((f=t.unifiedSplitOuterRadius)==null?void 0:f.trim())||a;m&&e.style.setProperty("--persona-artifact-unified-outer-radius",m)}}function Rh(e,r){var t,n,o;return!r||!Sn(e)?!1:((o=(n=(t=e.features)==null?void 0:t.artifacts)==null?void 0:n.layout)==null?void 0:o.expandLauncherPanelWhenOpen)!==!1}function H0(e,r){if(!(e!=null&&e.trim()))return r;let t=/^(\d+(?:\.\d+)?)px\s*$/i.exec(e.trim());return t?Math.max(0,Number(t[1])):r}function B0(e){if(!(e!=null&&e.trim()))return null;let r=/^(\d+(?:\.\d+)?)px\s*$/i.exec(e.trim());return r?Math.max(0,Number(r[1])):null}function W0(e,r,t){return t<r?r:Math.min(t,Math.max(r,e))}function D0(e,r,t,n){let o=e-n-2*r-t;return Math.max(0,o)}function Hh(e,r){var s;let n=(s=(r.getComputedStyle(e).gap||"0px").trim().split(/\s+/)[0])!=null?s:"0px",o=/^([\d.]+)px$/i.exec(n);if(o)return Number(o[1]);let a=/^([\d.]+)/.exec(n);return a?Number(a[1]):8}function Bh(e,r,t,n,o,a){let s=H0(o,200),i=D0(r,t,n,200);i=Math.max(s,i);let d=B0(a);return d!==null&&(i=Math.min(i,d)),W0(e,s,i)}var Wh={init:{title:"Schedule a Demo",description:"Share the basics and we'll follow up with a confirmation.",fields:[{name:"name",label:"Full name",placeholder:"Jane Doe",required:!0},{name:"email",label:"Work email",placeholder:"jane@example.com",type:"email",required:!0},{name:"notes",label:"What would you like to cover?",type:"textarea"}],submitLabel:"Submit details"},followup:{title:"Additional Information",description:"Provide any extra details to tailor the next steps.",fields:[{name:"company",label:"Company",placeholder:"Acme Inc."},{name:"context",label:"Context",type:"textarea",placeholder:"Share more about your use case"}],submitLabel:"Send"}},Mp=(e,r,t,n)=>{let o=e.querySelectorAll("[data-tv-form]");o.length&&o.forEach(a=>{var C,A,k;if(a.dataset.enhanced==="true")return;let s=(C=a.dataset.tvForm)!=null?C:"init";a.dataset.enhanced="true";let i=(A=Wh[s])!=null?A:Wh.init;a.classList.add("persona-form-card","persona-space-y-4");let d=h("div","persona-space-y-1"),l=h("h3","persona-text-base persona-font-semibold persona-text-persona-primary");if(l.textContent=i.title,d.appendChild(l),i.description){let T=h("p","persona-text-sm persona-text-persona-muted");T.textContent=i.description,d.appendChild(T)}let u=document.createElement("form");u.className="persona-form-grid persona-space-y-3",i.fields.forEach(T=>{var y,M;let S=h("label","persona-form-field persona-flex persona-flex-col persona-gap-1");S.htmlFor=`${r.id}-${s}-${T.name}`;let E=h("span","persona-text-xs persona-font-medium persona-text-persona-muted");E.textContent=T.label,S.appendChild(E);let w=(y=T.type)!=null?y:"text",b;w==="textarea"?(b=document.createElement("textarea"),b.rows=3):(b=document.createElement("input"),b.type=w),b.className="persona-rounded-xl persona-border persona-border-gray-200 persona-bg-white persona-px-3 persona-py-2 persona-text-sm persona-text-persona-primary focus:persona-outline-none focus:persona-border-persona-primary",b.id=`${r.id}-${s}-${T.name}`,b.name=T.name,b.placeholder=(M=T.placeholder)!=null?M:"",T.required&&(b.required=!0),S.appendChild(b),u.appendChild(S)});let p=h("div","persona-flex persona-items-center persona-justify-between persona-gap-2"),f=h("div","persona-text-xs persona-text-persona-muted persona-min-h-[1.5rem]"),m=h("button","persona-inline-flex persona-items-center persona-rounded-full persona-bg-persona-primary persona-px-4 persona-py-2 persona-text-sm persona-font-semibold persona-text-white disabled:persona-opacity-60 persona-cursor-pointer");m.type="submit",m.textContent=(k=i.submitLabel)!=null?k:"Submit",p.appendChild(f),p.appendChild(m),u.appendChild(p),a.replaceChildren(d,u),u.addEventListener("submit",async T=>{var b,y;T.preventDefault();let S=(b=t.formEndpoint)!=null?b:"/form",E=new FormData(u),w={};E.forEach((M,H)=>{w[H]=M}),w.type=s,m.disabled=!0,f.textContent="Submitting\u2026";try{let M=await fetch(S,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(w)});if(!M.ok)throw new Error(`Form submission failed (${M.status})`);let H=await M.json();f.textContent=(y=H.message)!=null?y:"Thanks! We'll be in touch soon.",H.success&&H.nextPrompt&&await n.sendMessage(String(H.nextPrompt))}catch(M){f.textContent=M instanceof Error?M.message:"Something went wrong. Please try again."}finally{m.disabled=!1}})})};var Lp=class{constructor(){this.plugins=new Map}register(r){var t;this.plugins.has(r.id)&&console.warn(`Plugin "${r.id}" is already registered. Overwriting.`),this.plugins.set(r.id,r),(t=r.onRegister)==null||t.call(r)}unregister(r){var n;let t=this.plugins.get(r);t&&((n=t.onUnregister)==null||n.call(t),this.plugins.delete(r))}getAll(){return Array.from(this.plugins.values()).sort((r,t)=>{var n,o;return((n=t.priority)!=null?n:0)-((o=r.priority)!=null?o:0)})}getForInstance(r){let t=this.getAll();if(!r||r.length===0)return t;let n=new Set(r.map(a=>a.id));return[...t.filter(a=>!n.has(a.id)),...r].sort((a,s)=>{var i,d;return((i=s.priority)!=null?i:0)-((d=a.priority)!=null?d:0)})}clear(){this.plugins.forEach(r=>{var t;return(t=r.onUnregister)==null?void 0:t.call(r)}),this.plugins.clear()}},Ws=new Lp;var Dh=()=>{let e=new Map,r=(o,a)=>(e.has(o)||e.set(o,new Set),e.get(o).add(a),()=>t(o,a)),t=(o,a)=>{var s;(s=e.get(o))==null||s.delete(a)};return{on:r,off:t,emit:(o,a)=>{var s;(s=e.get(o))==null||s.forEach(i=>{try{i(a)}catch(d){typeof console!="undefined"&&console.error("[AgentWidget] Event handler error:",d)}})}}};var O0=e=>{let r=e.match(/```(?:json)?\s*([\s\S]*?)```/i);return r?r[1]:e},F0=e=>{let r=e.trim(),t=r.indexOf("{");if(t===-1)return null;let n=0;for(let o=t;o<r.length;o+=1){let a=r[o];if(a==="{"&&(n+=1),a==="}"&&(n-=1,n===0))return r.slice(t,o+1)}return null},Ds=({text:e})=>{if(!e||!e.includes("{"))return null;try{let r=O0(e),t=F0(r);if(!t)return null;let n=JSON.parse(t);if(!n||typeof n!="object"||!n.action)return null;let{action:o,...a}=n;return{type:String(o),payload:a,raw:n}}catch{return null}},Pp=e=>typeof e=="string"?e:e==null?"":String(e),sa={message:e=>e.type!=="message"?void 0:{handled:!0,displayText:Pp(e.payload.text)},messageAndClick:(e,r)=>{var o;if(e.type!=="message_and_click")return;let t=e.payload,n=Pp(t.element);if(n&&((o=r.document)!=null&&o.querySelector)){let a=r.document.querySelector(n);a?setTimeout(()=>{a.click()},400):typeof console!="undefined"&&console.warn("[AgentWidget] Element not found for selector:",n)}return{handled:!0,displayText:Pp(t.text)}}},Oh=e=>Array.isArray(e)?e.map(r=>String(r)):[],Os=e=>{let r=new Set(Oh(e.getSessionMetadata().processedActionMessageIds)),t=()=>{r=new Set(Oh(e.getSessionMetadata().processedActionMessageIds))},n=()=>{let a=Array.from(r);e.updateSessionMetadata(s=>({...s,processedActionMessageIds:a}))};return{process:a=>{if(a.streaming||a.message.role!=="assistant"||!a.text||r.has(a.message.id))return null;let s=typeof a.raw=="string"&&a.raw||typeof a.message.rawContent=="string"&&a.message.rawContent||typeof a.text=="string"&&a.text||null;!s&&typeof a.text=="string"&&a.text.trim().startsWith("{")&&typeof console!="undefined"&&console.warn("[AgentWidget] Structured response detected but no raw payload was provided. Ensure your stream parser returns { text, raw }.");let i=s?e.parsers.reduce((l,u)=>l||(u==null?void 0:u({text:s,message:a.message}))||null,null):null;if(!i)return null;r.add(a.message.id),n();let d={action:i,message:a.message};e.emit("action:detected",d);for(let l of e.handlers)if(l)try{let u=()=>{e.emit("action:resubmit",d)},p=l(i,{message:a.message,metadata:e.getSessionMetadata(),updateMetadata:e.updateSessionMetadata,document:e.documentRef,triggerResubmit:u});if(!p)continue;if(p.handled){let f=p.persistMessage!==!1;return{text:p.displayText!==void 0?p.displayText:"",persist:f,resubmit:p.resubmit}}}catch(u){typeof console!="undefined"&&console.error("[AgentWidget] Action handler error:",u)}return{text:"",persist:!0}},syncFromMetadata:t}};var N0=e=>{if(!e)return null;try{return JSON.parse(e)}catch(r){return typeof console!="undefined"&&console.error("[AgentWidget] Failed to parse stored state:",r),null}},_0=e=>e.map(r=>({...r,streaming:!1})),$0=e=>e.map(r=>({...r,status:"complete"})),xl=(e="persona-state")=>{let r=()=>typeof window=="undefined"||!window.localStorage?null:window.localStorage;return{load:()=>{let t=r();return t?N0(t.getItem(e)):null},save:t=>{let n=r();if(n)try{let o={...t,messages:t.messages?_0(t.messages):void 0,artifacts:t.artifacts?$0(t.artifacts):void 0};n.setItem(e,JSON.stringify(o))}catch(o){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",o)}},clear:()=>{let t=r();if(t)try{t.removeItem(e)}catch(n){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear stored state:",n)}}}};var Wa=Bl(hi(),1);function U0(e){if(!e||typeof e!="object"||!("component"in e))return!1;let r=e.component;return typeof r=="string"&&r.length>0}function q0(e,r){if(!U0(e))return null;let t=e.props&&typeof e.props=="object"&&e.props!==null?e.props:{};return{component:e.component,props:t,raw:r}}function yl(){let e=null,r=0;return{getExtractedDirective:()=>e,processChunk:t=>{let n=t.trim();if(!n.startsWith("{")&&!n.startsWith("["))return null;if(t.length<=r)return e;try{let o=(0,Wa.parse)(t,Wa.STR|Wa.OBJ),a=q0(o,t);a&&(e=a)}catch{}return r=t.length,e},reset:()=>{e=null,r=0}}}function Fh(e){return typeof e=="object"&&e!==null&&"component"in e&&typeof e.component=="string"&&"props"in e&&typeof e.props=="object"}function bl(e,r){let{config:t,message:n,onPropsUpdate:o}=r,a=io.get(e.component);if(!a)return console.warn(`[ComponentMiddleware] Component "${e.component}" not found in registry. Falling back to default rendering.`),null;let s={message:n,config:t,updateProps:i=>{o&&o(i)}};try{return a(e.props,s)}catch(i){return console.error(`[ComponentMiddleware] Error rendering component "${e.component}":`,i),null}}function Nh(){let e=yl();return{processChunk:r=>e.processChunk(r),getDirective:()=>e.getExtractedDirective(),reset:()=>{e.reset()}}}function _h(e){if(typeof e.rawContent=="string"&&e.rawContent.length>0)return e.rawContent;if(typeof e.content=="string"){let r=e.content.trim();if(r.startsWith("{")||r.startsWith("["))return e.content}return null}function Cl(e){let r=_h(e);if(!r)return!1;try{let t=JSON.parse(r);return typeof t=="object"&&t!==null&&"component"in t&&typeof t.component=="string"}catch{return!1}}function wl(e){let r=_h(e);if(!r)return null;try{let t=JSON.parse(r);if(typeof t=="object"&&t!==null&&"component"in t&&typeof t.component=="string"){let n=t;return{component:n.component,props:n.props&&typeof n.props=="object"&&n.props!==null?n.props:{},raw:r}}}catch{}return null}var z0=["Very dissatisfied","Dissatisfied","Neutral","Satisfied","Very satisfied"];function vl(e){let{onSubmit:r,onDismiss:t,title:n="How satisfied are you?",subtitle:o="Please rate your experience",commentPlaceholder:a="Share your thoughts (optional)...",submitText:s="Submit",skipText:i="Skip",showComment:d=!0,ratingLabels:l=z0}=e,u=document.createElement("div");u.className="persona-feedback-container persona-feedback-csat",u.setAttribute("role","dialog"),u.setAttribute("aria-label","Customer satisfaction feedback");let p=null,f=document.createElement("div");f.className="persona-feedback-content";let m=document.createElement("div");m.className="persona-feedback-header";let C=document.createElement("h3");C.className="persona-feedback-title",C.textContent=n,m.appendChild(C);let A=document.createElement("p");A.className="persona-feedback-subtitle",A.textContent=o,m.appendChild(A),f.appendChild(m);let k=document.createElement("div");k.className="persona-feedback-rating persona-feedback-rating-csat",k.setAttribute("role","radiogroup"),k.setAttribute("aria-label","Satisfaction rating from 1 to 5");let T=[];for(let y=1;y<=5;y++){let M=document.createElement("button");M.type="button",M.className="persona-feedback-rating-btn persona-feedback-star-btn",M.setAttribute("role","radio"),M.setAttribute("aria-checked","false"),M.setAttribute("aria-label",`${y} star${y>1?"s":""}: ${l[y-1]}`),M.title=l[y-1],M.dataset.rating=String(y),M.innerHTML=`
|
|
67
67
|
<svg class="persona-feedback-star" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
68
68
|
<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon>
|
|
69
69
|
</svg>
|
|
70
|
-
`,M.addEventListener("click",()=>{p=y,T.forEach((H,B)=>{let R=B<y;H.classList.toggle("selected",R),H.setAttribute("aria-checked",B===y-1?"true":"false")})}),T.push(M),k.appendChild(M)}f.appendChild(k);let S=null;if(d){let y=document.createElement("div");y.className="persona-feedback-comment-container",S=document.createElement("textarea"),S.className="persona-feedback-comment",S.placeholder=a,S.rows=3,S.setAttribute("aria-label","Additional comments"),y.appendChild(S),f.appendChild(y)}let E=document.createElement("div");E.className="persona-feedback-actions";let v=document.createElement("button");v.type="button",v.className="persona-feedback-btn persona-feedback-btn-skip",v.textContent=i,v.addEventListener("click",()=>{t==null||t(),u.remove()});let b=document.createElement("button");return b.type="button",b.className="persona-feedback-btn persona-feedback-btn-submit",b.textContent=s,b.addEventListener("click",async()=>{if(p===null){k.classList.add("persona-feedback-shake"),setTimeout(()=>k.classList.remove("persona-feedback-shake"),500);return}b.disabled=!0,b.textContent="Submitting...";try{let y=(S==null?void 0:S.value.trim())||void 0;await r(p,y),u.remove()}catch(y){b.disabled=!1,b.textContent=s,console.error("[CSAT Feedback] Failed to submit:",y)}}),E.appendChild(v),E.appendChild(b),f.appendChild(E),u.appendChild(f),u}function Al(e){let{onSubmit:r,onDismiss:t,title:n="How likely are you to recommend us?",subtitle:o="On a scale of 0 to 10",commentPlaceholder:a="What could we do better? (optional)...",submitText:s="Submit",skipText:i="Skip",showComment:d=!0,lowLabel:l="Not likely",highLabel:u="Very likely"}=e,p=document.createElement("div");p.className="persona-feedback-container persona-feedback-nps",p.setAttribute("role","dialog"),p.setAttribute("aria-label","Net Promoter Score feedback");let f=null,m=document.createElement("div");m.className="persona-feedback-content";let C=document.createElement("div");C.className="persona-feedback-header";let w=document.createElement("h3");w.className="persona-feedback-title",w.textContent=n,C.appendChild(w);let k=document.createElement("p");k.className="persona-feedback-subtitle",k.textContent=o,C.appendChild(k),m.appendChild(C);let T=document.createElement("div");T.className="persona-feedback-rating persona-feedback-rating-nps",T.setAttribute("role","radiogroup"),T.setAttribute("aria-label","Likelihood rating from 0 to 10");let S=document.createElement("div");S.className="persona-feedback-labels";let E=document.createElement("span");E.className="persona-feedback-label-low",E.textContent=l;let v=document.createElement("span");v.className="persona-feedback-label-high",v.textContent=u,S.appendChild(E),S.appendChild(v);let b=document.createElement("div");b.className="persona-feedback-numbers";let y=[];for(let W=0;W<=10;W++){let V=document.createElement("button");V.type="button",V.className="persona-feedback-rating-btn persona-feedback-number-btn",V.setAttribute("role","radio"),V.setAttribute("aria-checked","false"),V.setAttribute("aria-label",`Rating ${W} out of 10`),V.textContent=String(W),V.dataset.rating=String(W),W<=6?V.classList.add("persona-feedback-detractor"):W<=8?V.classList.add("persona-feedback-passive"):V.classList.add("persona-feedback-promoter"),V.addEventListener("click",()=>{f=W,y.forEach((ne,ue)=>{ne.classList.toggle("selected",ue===W),ne.setAttribute("aria-checked",ue===W?"true":"false")})}),y.push(V),b.appendChild(V)}T.appendChild(S),T.appendChild(b),m.appendChild(T);let M=null;if(d){let W=document.createElement("div");W.className="persona-feedback-comment-container",M=document.createElement("textarea"),M.className="persona-feedback-comment",M.placeholder=a,M.rows=3,M.setAttribute("aria-label","Additional comments"),W.appendChild(M),m.appendChild(W)}let H=document.createElement("div");H.className="persona-feedback-actions";let B=document.createElement("button");B.type="button",B.className="persona-feedback-btn persona-feedback-btn-skip",B.textContent=i,B.addEventListener("click",()=>{t==null||t(),p.remove()});let R=document.createElement("button");return R.type="button",R.className="persona-feedback-btn persona-feedback-btn-submit",R.textContent=s,R.addEventListener("click",async()=>{if(f===null){b.classList.add("persona-feedback-shake"),setTimeout(()=>b.classList.remove("persona-feedback-shake"),500);return}R.disabled=!0,R.textContent="Submitting...";try{let W=(M==null?void 0:M.value.trim())||void 0;await r(f,W),p.remove()}catch(W){R.disabled=!1,R.textContent=s,console.error("[NPS Feedback] Failed to submit:",W)}}),H.appendChild(B),H.appendChild(R),m.appendChild(H),p.appendChild(m),p}var Da="persona-chat-history",V0=30*1e3,j0={"image/png":"png","image/jpeg":"jpg","image/jpg":"jpg","image/gif":"gif","image/webp":"webp","image/svg+xml":"svg","image/bmp":"bmp","image/tiff":"tiff"};function G0(e){var n,o,a;if(!e)return[];let r=[],t=Array.from((n=e.items)!=null?n:[]);for(let s of t){if(s.kind!=="file"||!s.type.startsWith("image/"))continue;let i=s.getAsFile();if(!i)continue;if(i.name){r.push(i);continue}let d=(o=j0[i.type])!=null?o:"png";r.push(new File([i],`clipboard-image-${Date.now()}.${d}`,{type:i.type,lastModified:Date.now()}))}if(r.length>0)return r;for(let s of Array.from((a=e.files)!=null?a:[]))s.type.startsWith("image/")&&r.push(s);return r}function Sl(e){if(!e)return!1;let r=e.types;return r?typeof r.contains=="function"?r.contains("Files"):Array.from(r).includes("Files"):!1}function X0(e){var r,t,n,o,a,s,i,d,l;return e?e===!0?{storage:"session",keyPrefix:"persona-",persist:{openState:!0,voiceState:!0,focusInput:!0},clearOnChatClear:!0}:{storage:(r=e.storage)!=null?r:"session",keyPrefix:(t=e.keyPrefix)!=null?t:"persona-",persist:{openState:(o=(n=e.persist)==null?void 0:n.openState)!=null?o:!0,voiceState:(s=(a=e.persist)==null?void 0:a.voiceState)!=null?s:!0,focusInput:(d=(i=e.persist)==null?void 0:i.focusInput)!=null?d:!0},clearOnChatClear:(l=e.clearOnChatClear)!=null?l:!0}:null}function J0(e){try{let r=e==="local"?localStorage:sessionStorage,t="__persist_test__";return r.setItem(t,"1"),r.removeItem(t),r}catch{return null}}var Ip=e=>!e||typeof e!="object"?{}:{...e},$h=e=>e.map(r=>({...r,streaming:!1})),Uh=(e,r,t)=>{let n=e!=null&&e.markdown?Xo(e.markdown):null,o=ba(e==null?void 0:e.sanitize);return e!=null&&e.postprocessMessage&&o&&(e==null?void 0:e.sanitize)===void 0&&console.warn("[Persona] A custom postprocessMessage is active with the default HTML sanitizer. Tags or attributes not in the built-in allowlist will be stripped. To keep custom HTML, set `sanitize: false` or provide a custom sanitize function."),a=>{var l,u,p;let s=(l=a.text)!=null?l:"",i=(u=a.message.rawContent)!=null?u:null;if(r){let f=r.process({text:s,raw:i!=null?i:s,message:a.message,streaming:a.streaming});f!==null&&(s=f.text,f.persist||(a.message.__skipPersist=!0),f.resubmit&&!a.streaming&&t&&t())}let d;return e!=null&&e.postprocessMessage?d=e.postprocessMessage({...a,text:s,raw:(p=i!=null?i:a.text)!=null?p:""}):n?d=n(s):d=Jo(s),o?o(d):d}};function qh(e){var i,d,l,u;let r=h("div","persona-attachment-drop-overlay");e!=null&&e.background&&r.style.setProperty("--persona-drop-overlay-bg",e.background),(e==null?void 0:e.backdropBlur)!==void 0&&r.style.setProperty("--persona-drop-overlay-blur",e.backdropBlur),e!=null&&e.border&&r.style.setProperty("--persona-drop-overlay-border",e.border),e!=null&&e.borderRadius&&r.style.setProperty("--persona-drop-overlay-radius",e.borderRadius),e!=null&&e.inset&&r.style.setProperty("--persona-drop-overlay-inset",e.inset),e!=null&&e.labelSize&&r.style.setProperty("--persona-drop-overlay-label-size",e.labelSize),e!=null&&e.labelColor&&r.style.setProperty("--persona-drop-overlay-label-color",e.labelColor);let t=(i=e==null?void 0:e.iconName)!=null?i:"upload",n=(d=e==null?void 0:e.iconSize)!=null?d:"48px",o=(l=e==null?void 0:e.iconColor)!=null?l:"rgba(59, 130, 246, 0.6)",a=(u=e==null?void 0:e.iconStrokeWidth)!=null?u:.5,s=ve(t,n,o,a);if(s&&r.appendChild(s),e!=null&&e.label){let p=h("span","persona-drop-overlay-label");p.textContent=e.label,r.appendChild(p)}return r}var Tl=(e,r,t)=>{var Qp,Zp,eu,tu,ru,nu,ou,au,su,iu,lu,du,cu,pu,uu,fu,mu,gu,hu,xu,yu,bu,Cu,wu,vu,Au,Su,Tu,ku,Eu,Mu,Lu,Pu,Iu,Ru,Hu,Bu,Wu,Du,Ou,Fu,Nu,_u,$u,Uu,qu,zu;if(e==null)throw new Error('createAgentExperience: mount must be a non-null HTMLElement (e.g. pass document.getElementById("my-root") after the node exists).');e.id&&!e.getAttribute("data-persona-instance")&&e.setAttribute("data-persona-instance",e.id),e.hasAttribute("data-persona-root")||e.setAttribute("data-persona-root","true");let n=zi(r),o=Ws.getForInstance(n.plugins);n.components&&io.registerAll(n.components);let a=Dh(),i=n.persistState===!1?null:(Qp=n.storageAdapter)!=null?Qp:xl(),d={},l=null,u=!1,p=c=>{if(n.onStateLoaded)try{let g=n.onStateLoaded(c);if(g&&typeof g=="object"&&"state"in g){let{state:x,open:A}=g;return A&&(u=!0),x}return g}catch(g){typeof console!="undefined"&&console.error("[AgentWidget] onStateLoaded hook failed:",g)}return c};if(i!=null&&i.load)try{let c=i.load();if(c&&typeof c.then=="function")l=c.then(g=>{let x=g!=null?g:{messages:[],metadata:{}};return p(x)});else{let g=c!=null?c:{messages:[],metadata:{}},x=p(g);x.metadata&&(d=Ip(x.metadata)),(Zp=x.messages)!=null&&Zp.length&&(n={...n,initialMessages:x.messages}),(eu=x.artifacts)!=null&&eu.length&&(n={...n,initialArtifacts:x.artifacts,initialSelectedArtifactId:(tu=x.selectedArtifactId)!=null?tu:null})}}catch(c){typeof console!="undefined"&&console.error("[AgentWidget] Failed to load stored state:",c)}else if(n.onStateLoaded)try{let c=p({messages:[],metadata:{}});(ru=c.messages)!=null&&ru.length&&(n={...n,initialMessages:c.messages})}catch(c){typeof console!="undefined"&&console.error("[AgentWidget] onStateLoaded hook failed:",c)}let f=()=>d,m=c=>{var x;d=(x=c({...d}))!=null?x:{},da()},C=n.actionParsers&&n.actionParsers.length?n.actionParsers:[Ds],w=n.actionHandlers&&n.actionHandlers.length?n.actionHandlers:[sa.message,sa.messageAndClick],k=Os({parsers:C,handlers:w,getSessionMetadata:f,updateSessionMetadata:m,emit:a.emit,documentRef:typeof document!="undefined"?document:null});k.syncFromMetadata();let T=(ou=(nu=n.launcher)==null?void 0:nu.enabled)!=null?ou:!0,S=(su=(au=n.launcher)==null?void 0:au.autoExpand)!=null?su:!1,E=(iu=n.autoFocusInput)!=null?iu:!1,v=S,b=T,y=(du=(lu=n.layout)==null?void 0:lu.header)==null?void 0:du.layout,M=!1,H=()=>So(n),B=()=>T||H(),R=H()?!1:T?S:!0,W=!1,V=null,ne=()=>{W=!0,V&&clearTimeout(V),V=setTimeout(()=>{W&&(typeof console!="undefined"&&console.warn("[AgentWidget] Resubmit requested but no injection occurred within 10s"),W=!1)},1e4)},ue=Uh(n,k,ne),We=(pu=(cu=n.features)==null?void 0:cu.showReasoning)!=null?pu:!0,Ke=(fu=(uu=n.features)==null?void 0:uu.showToolCalls)!=null?fu:!0,xe=(gu=(mu=n.features)==null?void 0:mu.showEventStreamToggle)!=null?gu:!1,me=(xu=(hu=n.features)==null?void 0:hu.scrollToBottom)!=null?xu:{},Ge=`${(bu=typeof n.persistState=="object"?(yu=n.persistState)==null?void 0:yu.keyPrefix:void 0)!=null?bu:"persona-"}event-stream`,Y=xe?new Bs(Ge):null,Ee=(vu=(wu=(Cu=n.features)==null?void 0:Cu.eventStream)==null?void 0:wu.maxEvents)!=null?vu:2e3,G=xe?new Hs(Ee,Y):null,ce=null,de=!1,pe=null,He=0;Y==null||Y.open().then(()=>G==null?void 0:G.restore()).catch(c=>{n.debug&&console.warn("[AgentWidget] IndexedDB not available for event stream:",c)});let Ye={onCopy:c=>{var g,x;a.emit("message:copy",c),z!=null&&z.isClientTokenMode()&&z.submitMessageFeedback(c.id,"copy").catch(A=>{n.debug&&console.error("[AgentWidget] Failed to submit copy feedback:",A)}),(x=(g=n.messageActions)==null?void 0:g.onCopy)==null||x.call(g,c)},onFeedback:c=>{var g,x;a.emit("message:feedback",c),z!=null&&z.isClientTokenMode()&&z.submitMessageFeedback(c.messageId,c.type).catch(A=>{n.debug&&console.error("[AgentWidget] Failed to submit feedback:",A)}),(x=(g=n.messageActions)==null?void 0:g.onFeedback)==null||x.call(g,c)}},J=(Au=n.statusIndicator)!=null?Au:{},ie=c=>{var g,x,A,O;return c==="idle"?(g=J.idleText)!=null?g:Wr.idle:c==="connecting"?(x=J.connectingText)!=null?x:Wr.connecting:c==="connected"?(A=J.connectedText)!=null?A:Wr.connected:c==="error"?(O=J.errorText)!=null?O:Wr.error:Wr[c]};function Ue(c,g,x,A){if(A==="idle"&&x.idleLink){c.textContent="";let O=document.createElement("a");O.href=x.idleLink,O.target="_blank",O.rel="noopener noreferrer",O.textContent=g,O.style.color="inherit",O.style.textDecoration="none",c.appendChild(O)}else c.textContent=g}let{wrapper:K,panel:j,pillRoot:Ce}=ah(n),De=sh(n,B()),{container:oe,body:Se,messagesWrapper:ge,suggestions:Rt,textarea:Me,sendButton:ae,sendButtonWrapper:ur,composerForm:Ut,statusText:Qt,introTitle:Or,introSubtitle:vr,closeButton:Oe,iconHolder:q,headerTitle:Te,headerSubtitle:_e,header:Ne,footer:qe,actionsRow:st,leftActions:nt,rightActions:pt}=De,Nt=De.setSendButtonMode,F=De.micButton,ye=De.micButtonWrapper,be=De.attachmentButton,it=De.attachmentButtonWrapper,Xe=De.attachmentInput,Wt=De.attachmentPreviewsContainer;oe.classList.add("persona-relative"),Se.classList.add("persona-relative");let ar=12,Pt=()=>{var c;return(c=me.label)!=null?c:""},kt=()=>{var c;return(c=me.iconName)!=null?c:"arrow-down"},rt=()=>me.enabled!==!1,lt=h("button","persona-scroll-to-bottom-indicator persona-absolute persona-bottom-3 persona-left-1/2 persona-z-10 persona-flex persona-items-center persona-gap-1 persona-text-xs persona-transform persona--translate-x-1/2 persona-cursor-pointer");lt.type="button",lt.style.display="none",lt.setAttribute("data-persona-scroll-to-bottom","true");let rr=h("span","persona-flex persona-items-center"),gn=h("span","");lt.append(rr,gn),oe.appendChild(lt);let Ir=()=>{let g=qe.style.display==="none"?0:qe.offsetHeight;lt.style.bottom=`${g+ar}px`};Ir();let Tn=()=>{let c=!!Pt();lt.setAttribute("aria-label",Pt()||"Jump to latest"),lt.title=Pt(),lt.setAttribute("data-persona-scroll-to-bottom-has-label",c?"true":"false"),rr.innerHTML="";let g=ve(kt(),"14px","currentColor",2);g?(rr.appendChild(g),rr.style.display=""):rr.style.display="none",gn.textContent=Pt(),gn.style.display=c?"":"none"};Tn();let Et=null,hn=null,pr=o.find(c=>c.renderHeader);if(pr!=null&&pr.renderHeader){let c=pr.renderHeader({config:n,defaultRenderer:()=>{let g=oo({config:n,showClose:B()});return na(oe,g,n),g.header},onClose:()=>qt(!1,"user")});if(c){let g=oe.querySelector(".persona-border-b-persona-divider");g&&(g.replaceWith(c),Ne=c)}}let Ar=()=>{var g,x,A,O;if(!G)return;if(de=!0,!ce&&G&&(ce=kh({buffer:G,getFullHistory:()=>G.getAllFromStore(),onClose:()=>Kr(),config:n,plugins:o})),ce&&(Se.style.display="none",(g=qe.parentNode)==null||g.insertBefore(ce.element,qe),ce.update()),bt){bt.style.boxShadow=`inset 0 0 0 1.5px ${Jr.actionIconColor}`;let $=(O=(A=(x=n.features)==null?void 0:x.eventStream)==null?void 0:A.classNames)==null?void 0:O.toggleButtonActive;$&&$.split(/\s+/).forEach(U=>U&&bt.classList.add(U))}let c=()=>{if(!de)return;let $=Date.now();$-He>=200&&(ce==null||ce.update(),He=$),pe=requestAnimationFrame(c)};He=0,pe=requestAnimationFrame(c),Jn(),a.emit("eventStream:opened",{timestamp:Date.now()})},Kr=()=>{var c,g,x;if(de){if(de=!1,ce&&ce.element.remove(),Se.style.display="",bt){bt.style.boxShadow="";let A=(x=(g=(c=n.features)==null?void 0:c.eventStream)==null?void 0:g.classNames)==null?void 0:x.toggleButtonActive;A&&A.split(/\s+/).forEach(O=>O&&bt.classList.remove(O))}pe!==null&&(cancelAnimationFrame(pe),pe=null),Jn(),a.emit("eventStream:closed",{timestamp:Date.now()})}},bt=null;if(xe){let c=(Tu=(Su=n.features)==null?void 0:Su.eventStream)==null?void 0:Tu.classNames,g="persona-inline-flex persona-items-center persona-justify-center persona-rounded-full hover:persona-opacity-80 persona-cursor-pointer persona-border-none persona-bg-transparent persona-p-1"+(c!=null&&c.toggleButton?" "+c.toggleButton:"");bt=h("button",g),bt.style.width="28px",bt.style.height="28px",bt.style.color=Jr.actionIconColor,bt.type="button",bt.setAttribute("aria-label","Event Stream"),bt.title="Event Stream";let x=ve("activity","18px","currentColor",1.5);x&&bt.appendChild(x);let A=De.clearChatButtonWrapper,O=De.closeButtonWrapper,$=A||O;$&&$.parentNode===Ne?Ne.insertBefore(bt,$):Ne.appendChild(bt),bt.addEventListener("click",()=>{de?Kr():Ar()})}let kn=c=>{var A,O,$;let g=n.attachments;if(!(g!=null&&g.enabled))return;let x=c.querySelector(".persona-attachment-previews");if(!x){x=h("div","persona-attachment-previews persona-flex persona-flex-wrap persona-gap-2 persona-mb-2"),x.style.display="none";let U=c.querySelector("[data-persona-composer-form]");U!=null&&U.parentNode?U.parentNode.insertBefore(x,U):c.insertBefore(x,c.firstChild)}if(!c.querySelector('input[type="file"]')){let U=h("input");U.type="file",U.accept=((A=g.allowedTypes)!=null?A:no).join(","),U.multiple=((O=g.maxFiles)!=null?O:4)>1,U.style.display="none",U.setAttribute("aria-label",($=g.buttonTooltipText)!=null?$:"Attach files"),c.appendChild(U)}},nn=o.find(c=>c.renderComposer);if(nn!=null&&nn.renderComposer){let c=n.composer,g=nn.renderComposer({config:n,defaultRenderer:()=>Ea({config:n}).footer,onSubmit:x=>{var U;if(!z||z.isStreaming())return;let A=x.trim(),O=(U=Et==null?void 0:Et.hasAttachments())!=null?U:!1;if(!A&&!O)return;Ga();let $;O&&($=[],$.push(...Et.getContentParts()),A&&$.push(hs(A))),z.sendMessage(A,{contentParts:$}),O&&Et.clearAttachments()},streaming:!1,disabled:!1,openAttachmentPicker:()=>{Xe==null||Xe.click()},models:c==null?void 0:c.models,selectedModelId:c==null?void 0:c.selectedModelId,onModelChange:x=>{n.composer={...n.composer,selectedModelId:x},n.agent&&(n.agent={...n.agent,model:x})},onVoiceToggle:((ku=n.voiceRecognition)==null?void 0:ku.enabled)===!0?()=>{hn==null||hn()}:void 0});g&&(qe.replaceWith(g),qe=g)}let Sr=c=>{let g=c.querySelector("[data-persona-composer-form]"),x=c.querySelector("[data-persona-composer-input]"),A=c.querySelector("[data-persona-composer-submit]"),O=c.querySelector("[data-persona-composer-mic]"),$=c.querySelector("[data-persona-composer-status]");g&&(Ut=g),x&&(Me=x),A&&(ae=A),O&&(F=O,ye=O.parentElement),$&&(Qt=$);let U=c.querySelector(".persona-mb-3.persona-flex.persona-flex-wrap.persona-gap-2");U&&(Rt=U);let X=c.querySelector(".persona-attachment-button");X&&(be=X,it=X.parentElement),Xe=c.querySelector('input[type="file"]'),Wt=c.querySelector(".persona-attachment-previews");let N=c.querySelector(".persona-widget-composer .persona-flex.persona-items-center.persona-justify-between");N&&(st=N)};kn(qe),Sr(qe);let Tr=(Iu=(Eu=n.layout)==null?void 0:Eu.contentMaxWidth)!=null?Iu:H()?(Pu=(Lu=(Mu=n.launcher)==null?void 0:Mu.composerBar)==null?void 0:Lu.contentMaxWidth)!=null?Pu:"720px":void 0;if(Tr&&(ge.style.maxWidth=Tr,ge.style.marginLeft="auto",ge.style.marginRight="auto",ge.style.width="100%"),Tr&&Ut&&!H()&&(Ut.style.maxWidth=Tr,Ut.style.marginLeft="auto",Ut.style.marginRight="auto"),Tr&&Rt&&!H()&&(Rt.style.maxWidth=Tr,Rt.style.marginLeft="auto",Rt.style.marginRight="auto"),Tr&&Wt&&!H()&&(Wt.style.maxWidth=Tr,Wt.style.marginLeft="auto",Wt.style.marginRight="auto"),(Ru=n.attachments)!=null&&Ru.enabled&&Xe&&Wt){Et=ta.fromConfig(n.attachments),Et.setPreviewsContainer(Wt),Xe.addEventListener("change",x=>{let A=x.target;Et==null||Et.handleFileSelect(A.files),A.value=""});let c=n.attachments.dropOverlay,g=qh(c);oe.appendChild(g)}(()=>{var A,O;let c=(O=(A=n.layout)==null?void 0:A.slots)!=null?O:{},g=$=>{switch($){case"body-top":return oe.querySelector(".persona-rounded-2xl.persona-bg-persona-surface.persona-p-6")||null;case"messages":return ge;case"footer-top":return Rt;case"composer":return Ut;case"footer-bottom":return Qt;default:return null}},x=($,U)=>{var X;switch($){case"header-left":case"header-center":case"header-right":if($==="header-left")Ne.insertBefore(U,Ne.firstChild);else if($==="header-right")Ne.appendChild(U);else{let N=Ne.querySelector(".persona-flex-col");N?(X=N.parentNode)==null||X.insertBefore(U,N.nextSibling):Ne.appendChild(U)}break;case"body-top":{let N=Se.querySelector(".persona-rounded-2xl.persona-bg-persona-surface.persona-p-6");N?N.replaceWith(U):Se.insertBefore(U,Se.firstChild);break}case"body-bottom":Se.appendChild(U);break;case"footer-top":Rt.replaceWith(U);break;case"footer-bottom":Qt.replaceWith(U);break;default:break}};for(let[$,U]of Object.entries(c))if(U)try{let X=U({config:n,defaultContent:()=>g($)});X&&x($,X)}catch(X){typeof console!="undefined"&&console.error(`[AgentWidget] Error rendering slot "${$}":`,X)}})();let En=c=>{let x=c.target.closest('button[data-expand-header="true"]');if(!x)return;let A=x.closest(".persona-reasoning-bubble, .persona-tool-bubble");if(!A)return;let O=A.getAttribute("data-message-id");if(!O)return;let $=x.getAttribute("data-bubble-type");$==="reasoning"?(La.has(O)?La.delete(O):La.add(O),ch(O,A)):$==="tool"&&(Pa.has(O)?Pa.delete(O):Pa.add(O),ph(O,A,n)),ln.delete(O)};ge.addEventListener("pointerdown",c=>{c.target.closest('button[data-expand-header="true"]')&&(c.preventDefault(),En(c))}),ge.addEventListener("keydown",c=>{let g=c.target;(c.key==="Enter"||c.key===" ")&&g.closest('button[data-expand-header="true"]')&&(c.preventDefault(),En(c))});let xn=new Map;ge.addEventListener("click",c=>{var U;let x=c.target.closest(".persona-message-action-btn[data-action]");if(!x)return;c.preventDefault(),c.stopPropagation();let A=x.closest("[data-actions-for]");if(!A)return;let O=A.getAttribute("data-actions-for");if(!O)return;let $=x.getAttribute("data-action");if($==="copy"){let N=z.getMessages().find(ke=>ke.id===O);if(N&&Ye.onCopy){let ke=N.content||"";navigator.clipboard.writeText(ke).then(()=>{x.classList.add("persona-message-action-success");let fe=ve("check",14,"currentColor",2);fe&&(x.innerHTML="",x.appendChild(fe)),setTimeout(()=>{x.classList.remove("persona-message-action-success");let re=ve("copy",14,"currentColor",2);re&&(x.innerHTML="",x.appendChild(re))},2e3)}).catch(fe=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to copy message:",fe)}),Ye.onCopy(N)}}else if($==="upvote"||$==="downvote"){let N=((U=xn.get(O))!=null?U:null)===$,ke=$==="upvote"?"thumbs-up":"thumbs-down";if(N){xn.delete(O),x.classList.remove("persona-message-action-active");let fe=ve(ke,14,"currentColor",2);fe&&(x.innerHTML="",x.appendChild(fe))}else{let fe=$==="upvote"?"downvote":"upvote",re=A.querySelector(`[data-action="${fe}"]`);if(re){re.classList.remove("persona-message-action-active");let tt=ve(fe==="upvote"?"thumbs-up":"thumbs-down",14,"currentColor",2);tt&&(re.innerHTML="",re.appendChild(tt))}xn.set(O,$),x.classList.add("persona-message-action-active");let we=ve(ke,14,"currentColor",2);we&&(we.setAttribute("fill","currentColor"),x.innerHTML="",x.appendChild(we)),x.classList.remove("persona-message-action-pop"),x.offsetWidth,x.classList.add("persona-message-action-pop");let Ve=z.getMessages().find(ct=>ct.id===O);Ve&&Ye.onFeedback&&Ye.onFeedback({type:$,messageId:Ve.id,message:Ve})}}}),ge.addEventListener("click",c=>{let x=c.target.closest("button[data-approval-action]");if(!x)return;c.preventDefault(),c.stopPropagation();let A=x.closest(".persona-approval-bubble");if(!A)return;let O=A.getAttribute("data-message-id");if(!O)return;let $=x.getAttribute("data-approval-action");if(!$)return;let U=$==="approve"?"approved":"denied",N=z.getMessages().find(fe=>fe.id===O);if(!(N!=null&&N.approval))return;let ke=A.querySelector("[data-approval-buttons]");ke&&ke.querySelectorAll("button").forEach(re=>{re.disabled=!0,re.style.opacity="0.5",re.style.cursor="not-allowed"}),z.resolveApproval(N.approval,U)});let vt=null,Pe=null,P={artifacts:[],selectedId:null},Z=!1,se={current:null};ge.addEventListener("click",c=>{var re,we,Le,Ve,ct;let x=c.target.closest("[data-download-artifact]");if(!x)return;c.preventDefault(),c.stopPropagation();let A=x.getAttribute("data-download-artifact");if(!A||((Le=(we=(re=n.features)==null?void 0:re.artifacts)==null?void 0:we.onArtifactAction)==null?void 0:Le.call(we,{type:"download",artifactId:A}))===!0)return;let $=z.getArtifactById(A),U=$==null?void 0:$.markdown,X=($==null?void 0:$.title)||"artifact";if(!U){let tt=x.closest("[data-open-artifact]"),gt=tt==null?void 0:tt.closest("[data-message-id]"),ht=gt==null?void 0:gt.getAttribute("data-message-id");if(ht){let Be=z.getMessages().find(Je=>Je.id===ht);if(Be!=null&&Be.rawContent)try{let Je=JSON.parse(Be.rawContent);U=(Ve=Je==null?void 0:Je.props)==null?void 0:Ve.markdown,X=((ct=Je==null?void 0:Je.props)==null?void 0:ct.title)||X}catch{}}}if(!U)return;let N=new Blob([U],{type:"text/markdown"}),ke=URL.createObjectURL(N),fe=document.createElement("a");fe.href=ke,fe.download=`${X}.md`,fe.click(),URL.revokeObjectURL(ke)}),ge.addEventListener("click",c=>{var $,U,X;let x=c.target.closest("[data-open-artifact]");if(!x)return;let A=x.getAttribute("data-open-artifact");!A||((X=(U=($=n.features)==null?void 0:$.artifacts)==null?void 0:U.onArtifactAction)==null?void 0:X.call(U,{type:"open",artifactId:A}))===!0||(c.preventDefault(),c.stopPropagation(),Z=!1,z.selectArtifact(A),on())}),ge.addEventListener("keydown",c=>{if(c.key!=="Enter"&&c.key!==" ")return;let g=c.target;g.hasAttribute("data-open-artifact")&&(c.preventDefault(),g.click())});let Mt=De.composerOverlay,zt=(c,g,x)=>{var X,N,ke,fe;let A=g.trim();if(!A||!se.current)return;let O=(X=c.getAttribute("data-tool-call-id"))!=null?X:"",$=x.source==="free-text";e.dispatchEvent(new CustomEvent("persona:askUserQuestion:answered",{detail:{toolUseId:O,answer:A,answers:x.structured,values:(N=x.values)!=null?N:x.source==="multi"?A.split(", "):[A],isFreeText:$,source:x.source},bubbles:!0,composed:!0})),Mo(Mt,O);let U=se.current.getMessages().find(re=>{var we;return((we=re.toolCall)==null?void 0:we.id)===O});(ke=U==null?void 0:U.agentMetadata)!=null&&ke.awaitingLocalTool?se.current.resolveAskUserQuestion(U,(fe=x.structured)!=null?fe:A):se.current.sendMessage(A)},Ht=c=>{var O;let g=se.current;if(!g)return;let x=(O=c.getAttribute("data-tool-call-id"))!=null?O:"",A=g.getMessages().find($=>{var U;return((U=$.toolCall)==null?void 0:U.id)===x});A&&g.persistAskUserQuestionProgress(A,{answers:fl(c,A),currentIndex:An(c)})},sr=c=>Object.entries(c).map(([g,x])=>`${g}: ${Array.isArray(x)?x.join(", "):x}`).join(" | "),xr=c=>{var O,$,U;if((($=(O=n.features)==null?void 0:O.askUserQuestion)==null?void 0:$.groupedAutoAdvance)===!1)return;let g=An(c),x=Ra(c);if(g>=x-1)return;let A=(U=se.current)==null?void 0:U.getMessages().find(X=>{var N;return((N=X.toolCall)==null?void 0:N.id)===c.getAttribute("data-tool-call-id")});A&&(ml(c,A,n,g+1),Ht(c))};Mt.addEventListener("click",c=>{var $,U,X,N,ke,fe,re,we,Le,Ve,ct,tt,gt,ht;let x=c.target.closest("[data-ask-user-action]");if(!x)return;let A=x.closest("[data-persona-ask-sheet-for]");if(!A)return;let O=x.getAttribute("data-ask-user-action");if(c.preventDefault(),c.stopPropagation(),O==="dismiss"){let Fe=($=A.getAttribute("data-tool-call-id"))!=null?$:"";e.dispatchEvent(new CustomEvent("persona:askUserQuestion:dismissed",{detail:{toolUseId:Fe},bubbles:!0,composed:!0})),Mo(Mt,Fe);let Be=(U=se.current)==null?void 0:U.getMessages().find(Je=>{var D;return((D=Je.toolCall)==null?void 0:D.id)===Fe});(X=Be==null?void 0:Be.agentMetadata)!=null&&X.awaitingLocalTool&&((N=se.current)==null||N.markAskUserQuestionResolved(Be),(ke=se.current)==null||ke.resolveAskUserQuestion(Be,"(dismissed)"));return}if(O==="pick"){let Fe=x.getAttribute("data-option-label");if(!Fe)return;let Be=A.getAttribute("data-multi-select")==="true",Je=Eo(A);if(Je&&Be){let D=aa(A)[An(A)],Ie=new Set(Array.isArray(D)?D:[]);Ie.has(Fe)?Ie.delete(Fe):Ie.add(Fe),Lo(A,Array.from(Ie)),Ht(A);return}if(Je){Lo(A,Fe),Ht(A),xr(A);return}if(Be){let D=x.getAttribute("aria-pressed")==="true";x.setAttribute("aria-pressed",D?"false":"true"),x.classList.toggle("persona-ask-pill-selected",!D);let Ie=A.querySelector('[data-ask-user-action="submit-multi"]');Ie&&(Ie.disabled=Sp(A).length===0);return}zt(A,Fe,{source:"pick",values:[Fe]});return}if(O==="submit-multi"){let Fe=Sp(A);if(Fe.length===0)return;zt(A,Fe.join(", "),{source:"multi",values:Fe});return}if(O==="open-free-text"){let Fe=A.querySelector('[data-ask-free-text-row="true"]');if(Fe){Fe.classList.remove("persona-hidden");let Be=Fe.querySelector('[data-ask-free-text-input="true"]');Be==null||Be.focus()}return}if(O==="focus-free-text"){let Fe=A.querySelector('[data-ask-free-text-input="true"]');Fe==null||Fe.focus();return}if(O==="submit-free-text"){let Fe=A.querySelector('[data-ask-free-text-input="true"]'),Be=(fe=Fe==null?void 0:Fe.value)!=null?fe:"";if(!Be.trim())return;if(Eo(A)){Lo(A,Be.trim()),Ht(A),xr(A);return}zt(A,Be,{source:"free-text"});return}if(O==="next"||O==="back"){if(!se.current)return;let Fe=(re=A.getAttribute("data-tool-call-id"))!=null?re:"",Be=se.current.getMessages().find(Qe=>{var Ae;return((Ae=Qe.toolCall)==null?void 0:Ae.id)===Fe});if(!Be)return;let Je=A.querySelector('[data-ask-free-text-input="true"]'),D=(Le=(we=Je==null?void 0:Je.value)==null?void 0:we.trim())!=null?Le:"";if(D){let Qe=aa(A)[An(A)];(typeof Qe!="string"||Qe!==D)&&Lo(A,D)}let Ie=O==="next"?1:-1,$e=An(A)+Ie;ml(A,Be,n,$e),Ht(A);return}if(O==="submit-all"){if(!se.current)return;let Fe=(Ve=A.getAttribute("data-tool-call-id"))!=null?Ve:"",Be=se.current.getMessages().find(Qe=>{var Ae;return((Ae=Qe.toolCall)==null?void 0:Ae.id)===Fe});if(!Be)return;let Je=A.querySelector('[data-ask-free-text-input="true"]'),D=(tt=(ct=Je==null?void 0:Je.value)==null?void 0:ct.trim())!=null?tt:"";D&&Lo(A,D);let Ie=fl(A,Be);se.current.persistAskUserQuestionProgress(Be,{answers:Ie,currentIndex:An(A)});let $e=sr(Ie);zt(A,$e||"(submitted)",{source:"submit-all",structured:Ie});return}if(O==="skip"){if(!se.current)return;let Fe=(gt=A.getAttribute("data-tool-call-id"))!=null?gt:"",Be=se.current.getMessages().find(Ae=>{var Ft;return((Ft=Ae.toolCall)==null?void 0:Ft.id)===Fe});if(!Be)return;let Je=Eo(A),D=An(A),Ie=Ra(A),$e=D>=Ie-1;if(!Je){e.dispatchEvent(new CustomEvent("persona:askUserQuestion:dismissed",{detail:{toolUseId:Fe},bubbles:!0,composed:!0})),Mo(Mt,Fe),(ht=Be.agentMetadata)!=null&&ht.awaitingLocalTool&&(se.current.markAskUserQuestionResolved(Be),se.current.resolveAskUserQuestion(Be,"(dismissed)"));return}Lo(A,"");let Qe=A.querySelector('[data-ask-free-text-input="true"]');if(Qe&&(Qe.value=""),$e){let Ae=fl(A,Be),Ft=sr(Ae);zt(A,Ft||"(skipped)",{source:"submit-all",structured:Ae});return}ml(A,Be,n,D+1),Ht(A);return}}),Mt.addEventListener("keydown",c=>{var $;if(c.key!=="Enter")return;let x=c.target;if(!(($=x.matches)!=null&&$.call(x,'[data-ask-free-text-input="true"]')))return;let A=x.closest("[data-persona-ask-sheet-for]");if(!A)return;c.preventDefault();let O=x.value;if(O.trim()){if(Eo(A)){Lo(A,O.trim()),Ht(A),xr(A);return}zt(A,O,{source:"free-text"})}});let Fr=c=>{if(!/^[1-9]$/.test(c.key)||c.metaKey||c.ctrlKey||c.altKey)return;let g=c.target;if((g==null?void 0:g.tagName)==="INPUT"||(g==null?void 0:g.tagName)==="TEXTAREA"||g!=null&&g.isContentEditable)return;let x=Mt.querySelector("[data-persona-ask-sheet-for]");if(!x||x.getAttribute("data-ask-layout")!=="rows"||x.getAttribute("data-multi-select")==="true")return;let A=Number(c.key),$=x.querySelectorAll('[data-ask-pill-list="true"] [data-ask-user-action="pick"], [data-ask-pill-list="true"] [data-ask-user-action="focus-free-text"]')[A-1];$&&(c.preventDefault(),$.click())};document.addEventListener("keydown",Fr);let kr=null,ot=null,wr=null,Nr=null,co=()=>{};function jn(){Nr==null||Nr(),Nr=null}let po=()=>{var U;if(!kr||!ot)return;let c=e.classList.contains("persona-artifact-appearance-seamless"),x=((U=e.ownerDocument.defaultView)!=null?U:window).innerWidth<=640;if(!c||e.classList.contains("persona-artifact-narrow-host")||x){ot.style.removeProperty("position"),ot.style.removeProperty("left"),ot.style.removeProperty("top"),ot.style.removeProperty("bottom"),ot.style.removeProperty("width"),ot.style.removeProperty("z-index");return}let A=kr.firstElementChild;if(!A||A===ot)return;let O=10;ot.style.position="absolute",ot.style.top="0",ot.style.bottom="0",ot.style.width=`${O}px`,ot.style.zIndex="5";let $=A.offsetWidth-O/2;ot.style.left=`${Math.max(0,$)}px`},Fn=()=>{},on=()=>{var x,A,O,$,U;if(!vt||!Sn(n))return;gl(e,n),hl(e,n),Fn();let c=($=(O=(A=(x=n.features)==null?void 0:x.artifacts)==null?void 0:A.layout)==null?void 0:O.narrowHostMaxWidth)!=null?$:520,g=j.getBoundingClientRect().width||0;e.classList.toggle("persona-artifact-narrow-host",g>0&&g<=c),vt.update(P),Z?(vt.setMobileOpen(!1),vt.element.classList.add("persona-hidden"),(U=vt.backdrop)==null||U.classList.add("persona-hidden")):P.artifacts.length>0&&(vt.element.classList.remove("persona-hidden"),vt.setMobileOpen(!0)),co()};if(Sn(n)){j.style.position="relative";let c=h("div","persona-flex persona-flex-1 persona-flex-col persona-min-w-0 persona-min-h-0"),g=h("div","persona-flex persona-h-full persona-w-full persona-min-h-0 persona-artifact-split-root");c.appendChild(oe),vt=Lh(n,{onSelect:x=>{var A;return(A=se.current)==null?void 0:A.selectArtifact(x)},onDismiss:()=>{Z=!0,on()}}),vt.element.classList.add("persona-hidden"),kr=g,g.appendChild(c),g.appendChild(vt.element),vt.backdrop&&j.appendChild(vt.backdrop),j.appendChild(g),co=()=>{var A,O,$,U;if(!kr||!vt)return;if(!((($=(O=(A=n.features)==null?void 0:A.artifacts)==null?void 0:O.layout)==null?void 0:$.resizable)===!0)){wr==null||wr(),wr=null,jn(),ot&&(ot.remove(),ot=null),vt.element.style.removeProperty("width"),vt.element.style.removeProperty("maxWidth");return}if(!ot){let X=h("div","persona-artifact-split-handle persona-shrink-0 persona-h-full");X.setAttribute("role","separator"),X.setAttribute("aria-orientation","vertical"),X.setAttribute("aria-label","Resize artifacts panel"),X.tabIndex=0;let N=e.ownerDocument,ke=(U=N.defaultView)!=null?U:window,fe=re=>{var gt,ht;if(!vt||re.button!==0||e.classList.contains("persona-artifact-narrow-host")||ke.innerWidth<=640)return;re.preventDefault(),jn();let we=re.clientX,Le=vt.element.getBoundingClientRect().width,Ve=(ht=(gt=n.features)==null?void 0:gt.artifacts)==null?void 0:ht.layout,ct=Fe=>{let Be=kr.getBoundingClientRect().width,Je=e.classList.contains("persona-artifact-appearance-seamless"),D=Je?0:Hh(kr,ke),Ie=Je?0:X.getBoundingClientRect().width||6,$e=Le-(Fe.clientX-we),Qe=Bh($e,Be,D,Ie,Ve==null?void 0:Ve.resizableMinWidth,Ve==null?void 0:Ve.resizableMaxWidth);vt.element.style.width=`${Qe}px`,vt.element.style.maxWidth="none",po()},tt=()=>{N.removeEventListener("pointermove",ct),N.removeEventListener("pointerup",tt),N.removeEventListener("pointercancel",tt),Nr=null;try{X.releasePointerCapture(re.pointerId)}catch{}};Nr=tt,N.addEventListener("pointermove",ct),N.addEventListener("pointerup",tt),N.addEventListener("pointercancel",tt);try{X.setPointerCapture(re.pointerId)}catch{}};X.addEventListener("pointerdown",fe),ot=X,kr.insertBefore(X,vt.element),wr=()=>{X.removeEventListener("pointerdown",fe)}}if(ot){let X=P.artifacts.length>0&&!Z;ot.classList.toggle("persona-hidden",!X),po()}},Fn=()=>{var ke,fe,re,we,Le,Ve,ct,tt,gt,ht,Fe,Be,Je,D;if(!T||!vt||((fe=(ke=n.launcher)==null?void 0:ke.sidebarMode)!=null?fe:!1)||hr(n)&&vn(n).reveal==="emerge")return;let A=(re=e.ownerDocument.defaultView)!=null?re:window,O=(Le=(we=n.launcher)==null?void 0:we.mobileFullscreen)!=null?Le:!0,$=(ct=(Ve=n.launcher)==null?void 0:Ve.mobileBreakpoint)!=null?ct:640;if(O&&A.innerWidth<=$||!Rh(n,T))return;let U=(ht=(gt=(tt=n.launcher)==null?void 0:tt.width)!=null?gt:n.launcherWidth)!=null?ht:mn,X=(D=(Je=(Be=(Fe=n.features)==null?void 0:Fe.artifacts)==null?void 0:Be.layout)==null?void 0:Je.expandedPanelWidth)!=null?D:"min(720px, calc(100vw - 24px))";P.artifacts.length>0&&!Z?(j.style.width=X,j.style.maxWidth=X):(j.style.width=U,j.style.maxWidth=U)},typeof ResizeObserver!="undefined"&&(Pe=new ResizeObserver(()=>{on()}),Pe.observe(j))}else j.appendChild(oe),H()&&Ce&&(De.peekBanner&&Ce.appendChild(De.peekBanner),Ce.appendChild(qe));e.appendChild(K),Ce&&e.appendChild(Ce);let Mn=()=>{var Qe,Ae,Ft,mt,dr,Mr,$t,$r,Lr,at,xt,Ur,Hr,Oo,Fo,No,ga,ha,nr,_o,Co,Lt,Zr,Qn,qr,en,Vt,er;if(H()){j.style.width="100%",j.style.maxWidth="100%";let jt=(Ae=(Qe=n.launcher)==null?void 0:Qe.composerBar)!=null?Ae:{},or=K.dataset.state==="expanded",tn=(Ft=jt.expandedSize)!=null?Ft:"anchored";if(!(or&&tn!=="fullscreen")){oe.style.background="",oe.style.border="",oe.style.borderRadius="",oe.style.overflow="",oe.style.boxShadow="";return}let gr=(dr=(mt=n.theme)==null?void 0:mt.components)==null?void 0:dr.panel,$n=Ta(n),Zn=($o,oi)=>{var Qa;return $o==null||$o===""?oi:(Qa=Aa($n,$o))!=null?Qa:$o},ti="1px solid var(--persona-border)",ri="var(--persona-palette-shadows-xl, 0 25px 50px -12px rgba(0, 0, 0, 0.25))",ni="var(--persona-panel-radius, var(--persona-radius-xl, 0.75rem))";oe.style.background="var(--persona-surface, #ffffff)",oe.style.border=Zn(gr==null?void 0:gr.border,ti),oe.style.borderRadius=Zn(gr==null?void 0:gr.borderRadius,ni),oe.style.boxShadow=Zn(gr==null?void 0:gr.shadow,ri),oe.style.overflow="hidden";return}let c=hr(n),g=($t=(Mr=n.launcher)==null?void 0:Mr.sidebarMode)!=null?$t:!1,x=c||g||((Lr=($r=n.launcher)==null?void 0:$r.fullHeight)!=null?Lr:!1),A=((at=n.launcher)==null?void 0:at.enabled)===!1,O=(Ur=(xt=n.theme)==null?void 0:xt.components)==null?void 0:Ur.panel,$=Ta(n),U=(jt,or)=>{var tn;return jt==null||jt===""?or:(tn=Aa($,jt))!=null?tn:jt},X=(Hr=e.ownerDocument.defaultView)!=null?Hr:window,N=(Fo=(Oo=n.launcher)==null?void 0:Oo.mobileFullscreen)!=null?Fo:!0,ke=(ga=(No=n.launcher)==null?void 0:No.mobileBreakpoint)!=null?ga:640,fe=X.innerWidth<=ke,re=N&&fe&&T,we=(nr=(ha=n.launcher)==null?void 0:ha.position)!=null?nr:"bottom-left",Le=we==="bottom-left"||we==="top-left",Ve=(Co=(_o=n.launcher)==null?void 0:_o.zIndex)!=null?Co:Dr,ct=g||re?"none":"1px solid var(--persona-border)",tt=re?"none":g?Le?"var(--persona-palette-shadows-sidebar-left, 2px 0 12px rgba(0, 0, 0, 0.08))":"var(--persona-palette-shadows-sidebar-right, -2px 0 12px rgba(0, 0, 0, 0.08))":"var(--persona-palette-shadows-xl, 0 25px 50px -12px rgba(0, 0, 0, 0.25))";c&&!re&&(tt="none",ct="none");let gt=g||re?"0":"var(--persona-panel-radius, var(--persona-radius-xl, 0.75rem))",ht=U(O==null?void 0:O.border,ct),Fe=U(O==null?void 0:O.shadow,tt),Be=U(O==null?void 0:O.borderRadius,gt),Je=Se.scrollTop;e.style.cssText="",K.style.cssText="",j.style.cssText="",oe.style.cssText="",Se.style.cssText="",qe.style.cssText="";let D=()=>{var or;if(Je<=0)return;((or=Se.ownerDocument.defaultView)!=null?or:window).requestAnimationFrame(()=>{if(Se.scrollTop===Je)return;let tn=Se.scrollHeight-Se.clientHeight;tn<=0||(Se.scrollTop=Math.min(Je,tn))})};if(re){K.classList.remove("persona-bottom-6","persona-right-6","persona-left-6","persona-top-6","persona-bottom-4","persona-right-4","persona-left-4","persona-top-4"),K.style.cssText=`
|
|
70
|
+
`,M.addEventListener("click",()=>{p=y,T.forEach((H,B)=>{let R=B<y;H.classList.toggle("selected",R),H.setAttribute("aria-checked",B===y-1?"true":"false")})}),T.push(M),k.appendChild(M)}f.appendChild(k);let S=null;if(d){let y=document.createElement("div");y.className="persona-feedback-comment-container",S=document.createElement("textarea"),S.className="persona-feedback-comment",S.placeholder=a,S.rows=3,S.setAttribute("aria-label","Additional comments"),y.appendChild(S),f.appendChild(y)}let E=document.createElement("div");E.className="persona-feedback-actions";let w=document.createElement("button");w.type="button",w.className="persona-feedback-btn persona-feedback-btn-skip",w.textContent=i,w.addEventListener("click",()=>{t==null||t(),u.remove()});let b=document.createElement("button");return b.type="button",b.className="persona-feedback-btn persona-feedback-btn-submit",b.textContent=s,b.addEventListener("click",async()=>{if(p===null){k.classList.add("persona-feedback-shake"),setTimeout(()=>k.classList.remove("persona-feedback-shake"),500);return}b.disabled=!0,b.textContent="Submitting...";try{let y=(S==null?void 0:S.value.trim())||void 0;await r(p,y),u.remove()}catch(y){b.disabled=!1,b.textContent=s,console.error("[CSAT Feedback] Failed to submit:",y)}}),E.appendChild(w),E.appendChild(b),f.appendChild(E),u.appendChild(f),u}function Al(e){let{onSubmit:r,onDismiss:t,title:n="How likely are you to recommend us?",subtitle:o="On a scale of 0 to 10",commentPlaceholder:a="What could we do better? (optional)...",submitText:s="Submit",skipText:i="Skip",showComment:d=!0,lowLabel:l="Not likely",highLabel:u="Very likely"}=e,p=document.createElement("div");p.className="persona-feedback-container persona-feedback-nps",p.setAttribute("role","dialog"),p.setAttribute("aria-label","Net Promoter Score feedback");let f=null,m=document.createElement("div");m.className="persona-feedback-content";let C=document.createElement("div");C.className="persona-feedback-header";let A=document.createElement("h3");A.className="persona-feedback-title",A.textContent=n,C.appendChild(A);let k=document.createElement("p");k.className="persona-feedback-subtitle",k.textContent=o,C.appendChild(k),m.appendChild(C);let T=document.createElement("div");T.className="persona-feedback-rating persona-feedback-rating-nps",T.setAttribute("role","radiogroup"),T.setAttribute("aria-label","Likelihood rating from 0 to 10");let S=document.createElement("div");S.className="persona-feedback-labels";let E=document.createElement("span");E.className="persona-feedback-label-low",E.textContent=l;let w=document.createElement("span");w.className="persona-feedback-label-high",w.textContent=u,S.appendChild(E),S.appendChild(w);let b=document.createElement("div");b.className="persona-feedback-numbers";let y=[];for(let W=0;W<=10;W++){let V=document.createElement("button");V.type="button",V.className="persona-feedback-rating-btn persona-feedback-number-btn",V.setAttribute("role","radio"),V.setAttribute("aria-checked","false"),V.setAttribute("aria-label",`Rating ${W} out of 10`),V.textContent=String(W),V.dataset.rating=String(W),W<=6?V.classList.add("persona-feedback-detractor"):W<=8?V.classList.add("persona-feedback-passive"):V.classList.add("persona-feedback-promoter"),V.addEventListener("click",()=>{f=W,y.forEach((ne,ue)=>{ne.classList.toggle("selected",ue===W),ne.setAttribute("aria-checked",ue===W?"true":"false")})}),y.push(V),b.appendChild(V)}T.appendChild(S),T.appendChild(b),m.appendChild(T);let M=null;if(d){let W=document.createElement("div");W.className="persona-feedback-comment-container",M=document.createElement("textarea"),M.className="persona-feedback-comment",M.placeholder=a,M.rows=3,M.setAttribute("aria-label","Additional comments"),W.appendChild(M),m.appendChild(W)}let H=document.createElement("div");H.className="persona-feedback-actions";let B=document.createElement("button");B.type="button",B.className="persona-feedback-btn persona-feedback-btn-skip",B.textContent=i,B.addEventListener("click",()=>{t==null||t(),p.remove()});let R=document.createElement("button");return R.type="button",R.className="persona-feedback-btn persona-feedback-btn-submit",R.textContent=s,R.addEventListener("click",async()=>{if(f===null){b.classList.add("persona-feedback-shake"),setTimeout(()=>b.classList.remove("persona-feedback-shake"),500);return}R.disabled=!0,R.textContent="Submitting...";try{let W=(M==null?void 0:M.value.trim())||void 0;await r(f,W),p.remove()}catch(W){R.disabled=!1,R.textContent=s,console.error("[NPS Feedback] Failed to submit:",W)}}),H.appendChild(B),H.appendChild(R),m.appendChild(H),p.appendChild(m),p}var Da="persona-chat-history",V0=30*1e3,j0={"image/png":"png","image/jpeg":"jpg","image/jpg":"jpg","image/gif":"gif","image/webp":"webp","image/svg+xml":"svg","image/bmp":"bmp","image/tiff":"tiff"};function G0(e){var n,o,a;if(!e)return[];let r=[],t=Array.from((n=e.items)!=null?n:[]);for(let s of t){if(s.kind!=="file"||!s.type.startsWith("image/"))continue;let i=s.getAsFile();if(!i)continue;if(i.name){r.push(i);continue}let d=(o=j0[i.type])!=null?o:"png";r.push(new File([i],`clipboard-image-${Date.now()}.${d}`,{type:i.type,lastModified:Date.now()}))}if(r.length>0)return r;for(let s of Array.from((a=e.files)!=null?a:[]))s.type.startsWith("image/")&&r.push(s);return r}function Sl(e){if(!e)return!1;let r=e.types;return r?typeof r.contains=="function"?r.contains("Files"):Array.from(r).includes("Files"):!1}function X0(e){var r,t,n,o,a,s,i,d,l;return e?e===!0?{storage:"session",keyPrefix:"persona-",persist:{openState:!0,voiceState:!0,focusInput:!0},clearOnChatClear:!0}:{storage:(r=e.storage)!=null?r:"session",keyPrefix:(t=e.keyPrefix)!=null?t:"persona-",persist:{openState:(o=(n=e.persist)==null?void 0:n.openState)!=null?o:!0,voiceState:(s=(a=e.persist)==null?void 0:a.voiceState)!=null?s:!0,focusInput:(d=(i=e.persist)==null?void 0:i.focusInput)!=null?d:!0},clearOnChatClear:(l=e.clearOnChatClear)!=null?l:!0}:null}function J0(e){try{let r=e==="local"?localStorage:sessionStorage,t="__persist_test__";return r.setItem(t,"1"),r.removeItem(t),r}catch{return null}}var Ip=e=>!e||typeof e!="object"?{}:{...e},$h=e=>e.map(r=>({...r,streaming:!1})),Uh=(e,r,t)=>{let n=e!=null&&e.markdown?Xo(e.markdown):null,o=ba(e==null?void 0:e.sanitize);return e!=null&&e.postprocessMessage&&o&&(e==null?void 0:e.sanitize)===void 0&&console.warn("[Persona] A custom postprocessMessage is active with the default HTML sanitizer. Tags or attributes not in the built-in allowlist will be stripped. To keep custom HTML, set `sanitize: false` or provide a custom sanitize function."),a=>{var l,u,p;let s=(l=a.text)!=null?l:"",i=(u=a.message.rawContent)!=null?u:null;if(r){let f=r.process({text:s,raw:i!=null?i:s,message:a.message,streaming:a.streaming});f!==null&&(s=f.text,f.persist||(a.message.__skipPersist=!0),f.resubmit&&!a.streaming&&t&&t())}let d;return e!=null&&e.postprocessMessage?d=e.postprocessMessage({...a,text:s,raw:(p=i!=null?i:a.text)!=null?p:""}):n?d=n(s):d=Jo(s),o?o(d):d}};function qh(e){var i,d,l,u;let r=h("div","persona-attachment-drop-overlay");e!=null&&e.background&&r.style.setProperty("--persona-drop-overlay-bg",e.background),(e==null?void 0:e.backdropBlur)!==void 0&&r.style.setProperty("--persona-drop-overlay-blur",e.backdropBlur),e!=null&&e.border&&r.style.setProperty("--persona-drop-overlay-border",e.border),e!=null&&e.borderRadius&&r.style.setProperty("--persona-drop-overlay-radius",e.borderRadius),e!=null&&e.inset&&r.style.setProperty("--persona-drop-overlay-inset",e.inset),e!=null&&e.labelSize&&r.style.setProperty("--persona-drop-overlay-label-size",e.labelSize),e!=null&&e.labelColor&&r.style.setProperty("--persona-drop-overlay-label-color",e.labelColor);let t=(i=e==null?void 0:e.iconName)!=null?i:"upload",n=(d=e==null?void 0:e.iconSize)!=null?d:"48px",o=(l=e==null?void 0:e.iconColor)!=null?l:"rgba(59, 130, 246, 0.6)",a=(u=e==null?void 0:e.iconStrokeWidth)!=null?u:.5,s=ve(t,n,o,a);if(s&&r.appendChild(s),e!=null&&e.label){let p=h("span","persona-drop-overlay-label");p.textContent=e.label,r.appendChild(p)}return r}var Tl=(e,r,t)=>{var Qp,Zp,eu,tu,ru,nu,ou,au,su,iu,lu,du,cu,pu,uu,fu,mu,gu,hu,xu,yu,bu,Cu,wu,vu,Au,Su,Tu,ku,Eu,Mu,Lu,Pu,Iu,Ru,Hu,Bu,Wu,Du,Ou,Fu,Nu,_u,$u,Uu,qu,zu;if(e==null)throw new Error('createAgentExperience: mount must be a non-null HTMLElement (e.g. pass document.getElementById("my-root") after the node exists).');e.id&&!e.getAttribute("data-persona-instance")&&e.setAttribute("data-persona-instance",e.id),e.hasAttribute("data-persona-root")||e.setAttribute("data-persona-root","true");let n=zi(r),o=Ws.getForInstance(n.plugins);n.components&&io.registerAll(n.components);let a=Dh(),i=n.persistState===!1?null:(Qp=n.storageAdapter)!=null?Qp:xl(),d={},l=null,u=!1,p=c=>{if(n.onStateLoaded)try{let g=n.onStateLoaded(c);if(g&&typeof g=="object"&&"state"in g){let{state:x,open:v}=g;return v&&(u=!0),x}return g}catch(g){typeof console!="undefined"&&console.error("[AgentWidget] onStateLoaded hook failed:",g)}return c};if(i!=null&&i.load)try{let c=i.load();if(c&&typeof c.then=="function")l=c.then(g=>{let x=g!=null?g:{messages:[],metadata:{}};return p(x)});else{let g=c!=null?c:{messages:[],metadata:{}},x=p(g);x.metadata&&(d=Ip(x.metadata)),(Zp=x.messages)!=null&&Zp.length&&(n={...n,initialMessages:x.messages}),(eu=x.artifacts)!=null&&eu.length&&(n={...n,initialArtifacts:x.artifacts,initialSelectedArtifactId:(tu=x.selectedArtifactId)!=null?tu:null})}}catch(c){typeof console!="undefined"&&console.error("[AgentWidget] Failed to load stored state:",c)}else if(n.onStateLoaded)try{let c=p({messages:[],metadata:{}});(ru=c.messages)!=null&&ru.length&&(n={...n,initialMessages:c.messages})}catch(c){typeof console!="undefined"&&console.error("[AgentWidget] onStateLoaded hook failed:",c)}let f=()=>d,m=c=>{var x;d=(x=c({...d}))!=null?x:{},da()},C=n.actionParsers&&n.actionParsers.length?n.actionParsers:[Ds],A=n.actionHandlers&&n.actionHandlers.length?n.actionHandlers:[sa.message,sa.messageAndClick],k=Os({parsers:C,handlers:A,getSessionMetadata:f,updateSessionMetadata:m,emit:a.emit,documentRef:typeof document!="undefined"?document:null});k.syncFromMetadata();let T=(ou=(nu=n.launcher)==null?void 0:nu.enabled)!=null?ou:!0,S=(su=(au=n.launcher)==null?void 0:au.autoExpand)!=null?su:!1,E=(iu=n.autoFocusInput)!=null?iu:!1,w=S,b=T,y=(du=(lu=n.layout)==null?void 0:lu.header)==null?void 0:du.layout,M=!1,H=()=>So(n),B=()=>T||H(),R=H()?!1:T?S:!0,W=!1,V=null,ne=()=>{W=!0,V&&clearTimeout(V),V=setTimeout(()=>{W&&(typeof console!="undefined"&&console.warn("[AgentWidget] Resubmit requested but no injection occurred within 10s"),W=!1)},1e4)},ue=Uh(n,k,ne),Be=(pu=(cu=n.features)==null?void 0:cu.showReasoning)!=null?pu:!0,Ke=(fu=(uu=n.features)==null?void 0:uu.showToolCalls)!=null?fu:!0,ye=(gu=(mu=n.features)==null?void 0:mu.showEventStreamToggle)!=null?gu:!1,me=(xu=(hu=n.features)==null?void 0:hu.scrollToBottom)!=null?xu:{},Xe=`${(bu=typeof n.persistState=="object"?(yu=n.persistState)==null?void 0:yu.keyPrefix:void 0)!=null?bu:"persona-"}event-stream`,Y=ye?new Bs(Xe):null,Ee=(vu=(wu=(Cu=n.features)==null?void 0:Cu.eventStream)==null?void 0:wu.maxEvents)!=null?vu:2e3,G=ye?new Hs(Ee,Y):null,ce=null,de=!1,pe=null,Re=0;Y==null||Y.open().then(()=>G==null?void 0:G.restore()).catch(c=>{n.debug&&console.warn("[AgentWidget] IndexedDB not available for event stream:",c)});let Ye={onCopy:c=>{var g,x;a.emit("message:copy",c),z!=null&&z.isClientTokenMode()&&z.submitMessageFeedback(c.id,"copy").catch(v=>{n.debug&&console.error("[AgentWidget] Failed to submit copy feedback:",v)}),(x=(g=n.messageActions)==null?void 0:g.onCopy)==null||x.call(g,c)},onFeedback:c=>{var g,x;a.emit("message:feedback",c),z!=null&&z.isClientTokenMode()&&z.submitMessageFeedback(c.messageId,c.type).catch(v=>{n.debug&&console.error("[AgentWidget] Failed to submit feedback:",v)}),(x=(g=n.messageActions)==null?void 0:g.onFeedback)==null||x.call(g,c)}},J=(Au=n.statusIndicator)!=null?Au:{},ie=c=>{var g,x,v,O;return c==="idle"?(g=J.idleText)!=null?g:Wr.idle:c==="connecting"?(x=J.connectingText)!=null?x:Wr.connecting:c==="connected"?(v=J.connectedText)!=null?v:Wr.connected:c==="error"?(O=J.errorText)!=null?O:Wr.error:Wr[c]};function Ue(c,g,x,v){if(v==="idle"&&x.idleLink){c.textContent="";let O=document.createElement("a");O.href=x.idleLink,O.target="_blank",O.rel="noopener noreferrer",O.textContent=g,O.style.color="inherit",O.style.textDecoration="none",c.appendChild(O)}else c.textContent=g}let{wrapper:K,panel:j,pillRoot:Ce}=ah(n),De=sh(n,B()),{container:oe,body:Se,messagesWrapper:ge,suggestions:Rt,textarea:Me,sendButton:ae,sendButtonWrapper:ur,composerForm:Ut,statusText:Qt,introTitle:Or,introSubtitle:vr,closeButton:Oe,iconHolder:q,headerTitle:Te,headerSubtitle:_e,header:Ne,footer:qe,actionsRow:st,leftActions:nt,rightActions:pt}=De,Nt=De.setSendButtonMode,F=De.micButton,xe=De.micButtonWrapper,be=De.attachmentButton,it=De.attachmentButtonWrapper,Ge=De.attachmentInput,Wt=De.attachmentPreviewsContainer;oe.classList.add("persona-relative"),Se.classList.add("persona-relative");let ar=12,Pt=()=>{var c;return(c=me.label)!=null?c:""},kt=()=>{var c;return(c=me.iconName)!=null?c:"arrow-down"},rt=()=>me.enabled!==!1,lt=h("button","persona-scroll-to-bottom-indicator persona-absolute persona-bottom-3 persona-left-1/2 persona-z-10 persona-flex persona-items-center persona-gap-1 persona-text-xs persona-transform persona--translate-x-1/2 persona-cursor-pointer");lt.type="button",lt.style.display="none",lt.setAttribute("data-persona-scroll-to-bottom","true");let rr=h("span","persona-flex persona-items-center"),gn=h("span","");lt.append(rr,gn),oe.appendChild(lt);let Ir=()=>{let g=qe.style.display==="none"?0:qe.offsetHeight;lt.style.bottom=`${g+ar}px`};Ir();let Tn=()=>{let c=!!Pt();lt.setAttribute("aria-label",Pt()||"Jump to latest"),lt.title=Pt(),lt.setAttribute("data-persona-scroll-to-bottom-has-label",c?"true":"false"),rr.innerHTML="";let g=ve(kt(),"14px","currentColor",2);g?(rr.appendChild(g),rr.style.display=""):rr.style.display="none",gn.textContent=Pt(),gn.style.display=c?"":"none"};Tn();let Et=null,hn=null,pr=o.find(c=>c.renderHeader);if(pr!=null&&pr.renderHeader){let c=pr.renderHeader({config:n,defaultRenderer:()=>{let g=oo({config:n,showClose:B()});return na(oe,g,n),g.header},onClose:()=>qt(!1,"user")});if(c){let g=oe.querySelector(".persona-border-b-persona-divider");g&&(g.replaceWith(c),Ne=c)}}let Ar=()=>{var g,x,v,O;if(!G)return;if(de=!0,!ce&&G&&(ce=kh({buffer:G,getFullHistory:()=>G.getAllFromStore(),onClose:()=>Kr(),config:n,plugins:o})),ce&&(Se.style.display="none",(g=qe.parentNode)==null||g.insertBefore(ce.element,qe),ce.update()),bt){bt.style.boxShadow=`inset 0 0 0 1.5px ${Jr.actionIconColor}`;let $=(O=(v=(x=n.features)==null?void 0:x.eventStream)==null?void 0:v.classNames)==null?void 0:O.toggleButtonActive;$&&$.split(/\s+/).forEach(U=>U&&bt.classList.add(U))}let c=()=>{if(!de)return;let $=Date.now();$-Re>=200&&(ce==null||ce.update(),Re=$),pe=requestAnimationFrame(c)};Re=0,pe=requestAnimationFrame(c),Jn(),a.emit("eventStream:opened",{timestamp:Date.now()})},Kr=()=>{var c,g,x;if(de){if(de=!1,ce&&ce.element.remove(),Se.style.display="",bt){bt.style.boxShadow="";let v=(x=(g=(c=n.features)==null?void 0:c.eventStream)==null?void 0:g.classNames)==null?void 0:x.toggleButtonActive;v&&v.split(/\s+/).forEach(O=>O&&bt.classList.remove(O))}pe!==null&&(cancelAnimationFrame(pe),pe=null),Jn(),a.emit("eventStream:closed",{timestamp:Date.now()})}},bt=null;if(ye){let c=(Tu=(Su=n.features)==null?void 0:Su.eventStream)==null?void 0:Tu.classNames,g="persona-inline-flex persona-items-center persona-justify-center persona-rounded-full hover:persona-opacity-80 persona-cursor-pointer persona-border-none persona-bg-transparent persona-p-1"+(c!=null&&c.toggleButton?" "+c.toggleButton:"");bt=h("button",g),bt.style.width="28px",bt.style.height="28px",bt.style.color=Jr.actionIconColor,bt.type="button",bt.setAttribute("aria-label","Event Stream"),bt.title="Event Stream";let x=ve("activity","18px","currentColor",1.5);x&&bt.appendChild(x);let v=De.clearChatButtonWrapper,O=De.closeButtonWrapper,$=v||O;$&&$.parentNode===Ne?Ne.insertBefore(bt,$):Ne.appendChild(bt),bt.addEventListener("click",()=>{de?Kr():Ar()})}let kn=c=>{var v,O,$;let g=n.attachments;if(!(g!=null&&g.enabled))return;let x=c.querySelector(".persona-attachment-previews");if(!x){x=h("div","persona-attachment-previews persona-flex persona-flex-wrap persona-gap-2 persona-mb-2"),x.style.display="none";let U=c.querySelector("[data-persona-composer-form]");U!=null&&U.parentNode?U.parentNode.insertBefore(x,U):c.insertBefore(x,c.firstChild)}if(!c.querySelector('input[type="file"]')){let U=h("input");U.type="file",U.accept=((v=g.allowedTypes)!=null?v:no).join(","),U.multiple=((O=g.maxFiles)!=null?O:4)>1,U.style.display="none",U.setAttribute("aria-label",($=g.buttonTooltipText)!=null?$:"Attach files"),c.appendChild(U)}},nn=o.find(c=>c.renderComposer);if(nn!=null&&nn.renderComposer){let c=n.composer,g=nn.renderComposer({config:n,defaultRenderer:()=>Ea({config:n}).footer,onSubmit:x=>{var U;if(!z||z.isStreaming())return;let v=x.trim(),O=(U=Et==null?void 0:Et.hasAttachments())!=null?U:!1;if(!v&&!O)return;Ga();let $;O&&($=[],$.push(...Et.getContentParts()),v&&$.push(hs(v))),z.sendMessage(v,{contentParts:$}),O&&Et.clearAttachments()},streaming:!1,disabled:!1,openAttachmentPicker:()=>{Ge==null||Ge.click()},models:c==null?void 0:c.models,selectedModelId:c==null?void 0:c.selectedModelId,onModelChange:x=>{n.composer={...n.composer,selectedModelId:x},n.agent&&(n.agent={...n.agent,model:x})},onVoiceToggle:((ku=n.voiceRecognition)==null?void 0:ku.enabled)===!0?()=>{hn==null||hn()}:void 0});g&&(qe.replaceWith(g),qe=g)}let Sr=c=>{let g=c.querySelector("[data-persona-composer-form]"),x=c.querySelector("[data-persona-composer-input]"),v=c.querySelector("[data-persona-composer-submit]"),O=c.querySelector("[data-persona-composer-mic]"),$=c.querySelector("[data-persona-composer-status]");g&&(Ut=g),x&&(Me=x),v&&(ae=v),O&&(F=O,xe=O.parentElement),$&&(Qt=$);let U=c.querySelector(".persona-mb-3.persona-flex.persona-flex-wrap.persona-gap-2");U&&(Rt=U);let X=c.querySelector(".persona-attachment-button");X&&(be=X,it=X.parentElement),Ge=c.querySelector('input[type="file"]'),Wt=c.querySelector(".persona-attachment-previews");let N=c.querySelector(".persona-widget-composer .persona-flex.persona-items-center.persona-justify-between");N&&(st=N)};kn(qe),Sr(qe);let Tr=(Iu=(Eu=n.layout)==null?void 0:Eu.contentMaxWidth)!=null?Iu:H()?(Pu=(Lu=(Mu=n.launcher)==null?void 0:Mu.composerBar)==null?void 0:Lu.contentMaxWidth)!=null?Pu:"720px":void 0;if(Tr&&(ge.style.maxWidth=Tr,ge.style.marginLeft="auto",ge.style.marginRight="auto",ge.style.width="100%"),Tr&&Ut&&!H()&&(Ut.style.maxWidth=Tr,Ut.style.marginLeft="auto",Ut.style.marginRight="auto"),Tr&&Rt&&!H()&&(Rt.style.maxWidth=Tr,Rt.style.marginLeft="auto",Rt.style.marginRight="auto"),Tr&&Wt&&!H()&&(Wt.style.maxWidth=Tr,Wt.style.marginLeft="auto",Wt.style.marginRight="auto"),(Ru=n.attachments)!=null&&Ru.enabled&&Ge&&Wt){Et=ta.fromConfig(n.attachments),Et.setPreviewsContainer(Wt),Ge.addEventListener("change",x=>{let v=x.target;Et==null||Et.handleFileSelect(v.files),v.value=""});let c=n.attachments.dropOverlay,g=qh(c);oe.appendChild(g)}(()=>{var v,O;let c=(O=(v=n.layout)==null?void 0:v.slots)!=null?O:{},g=$=>{switch($){case"body-top":return oe.querySelector(".persona-rounded-2xl.persona-bg-persona-surface.persona-p-6")||null;case"messages":return ge;case"footer-top":return Rt;case"composer":return Ut;case"footer-bottom":return Qt;default:return null}},x=($,U)=>{var X;switch($){case"header-left":case"header-center":case"header-right":if($==="header-left")Ne.insertBefore(U,Ne.firstChild);else if($==="header-right")Ne.appendChild(U);else{let N=Ne.querySelector(".persona-flex-col");N?(X=N.parentNode)==null||X.insertBefore(U,N.nextSibling):Ne.appendChild(U)}break;case"body-top":{let N=Se.querySelector(".persona-rounded-2xl.persona-bg-persona-surface.persona-p-6");N?N.replaceWith(U):Se.insertBefore(U,Se.firstChild);break}case"body-bottom":Se.appendChild(U);break;case"footer-top":Rt.replaceWith(U);break;case"footer-bottom":Qt.replaceWith(U);break;default:break}};for(let[$,U]of Object.entries(c))if(U)try{let X=U({config:n,defaultContent:()=>g($)});X&&x($,X)}catch(X){typeof console!="undefined"&&console.error(`[AgentWidget] Error rendering slot "${$}":`,X)}})();let En=c=>{let x=c.target.closest('button[data-expand-header="true"]');if(!x)return;let v=x.closest(".persona-reasoning-bubble, .persona-tool-bubble");if(!v)return;let O=v.getAttribute("data-message-id");if(!O)return;let $=x.getAttribute("data-bubble-type");$==="reasoning"?(La.has(O)?La.delete(O):La.add(O),ch(O,v)):$==="tool"&&(Pa.has(O)?Pa.delete(O):Pa.add(O),ph(O,v,n)),ln.delete(O)};ge.addEventListener("pointerdown",c=>{c.target.closest('button[data-expand-header="true"]')&&(c.preventDefault(),En(c))}),ge.addEventListener("keydown",c=>{let g=c.target;(c.key==="Enter"||c.key===" ")&&g.closest('button[data-expand-header="true"]')&&(c.preventDefault(),En(c))});let xn=new Map;ge.addEventListener("click",c=>{var U;let x=c.target.closest(".persona-message-action-btn[data-action]");if(!x)return;c.preventDefault(),c.stopPropagation();let v=x.closest("[data-actions-for]");if(!v)return;let O=v.getAttribute("data-actions-for");if(!O)return;let $=x.getAttribute("data-action");if($==="copy"){let N=z.getMessages().find(ke=>ke.id===O);if(N&&Ye.onCopy){let ke=N.content||"";navigator.clipboard.writeText(ke).then(()=>{x.classList.add("persona-message-action-success");let fe=ve("check",14,"currentColor",2);fe&&(x.innerHTML="",x.appendChild(fe)),setTimeout(()=>{x.classList.remove("persona-message-action-success");let re=ve("copy",14,"currentColor",2);re&&(x.innerHTML="",x.appendChild(re))},2e3)}).catch(fe=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to copy message:",fe)}),Ye.onCopy(N)}}else if($==="upvote"||$==="downvote"){let N=((U=xn.get(O))!=null?U:null)===$,ke=$==="upvote"?"thumbs-up":"thumbs-down";if(N){xn.delete(O),x.classList.remove("persona-message-action-active");let fe=ve(ke,14,"currentColor",2);fe&&(x.innerHTML="",x.appendChild(fe))}else{let fe=$==="upvote"?"downvote":"upvote",re=v.querySelector(`[data-action="${fe}"]`);if(re){re.classList.remove("persona-message-action-active");let tt=ve(fe==="upvote"?"thumbs-up":"thumbs-down",14,"currentColor",2);tt&&(re.innerHTML="",re.appendChild(tt))}xn.set(O,$),x.classList.add("persona-message-action-active");let we=ve(ke,14,"currentColor",2);we&&(we.setAttribute("fill","currentColor"),x.innerHTML="",x.appendChild(we)),x.classList.remove("persona-message-action-pop"),x.offsetWidth,x.classList.add("persona-message-action-pop");let Ve=z.getMessages().find(ct=>ct.id===O);Ve&&Ye.onFeedback&&Ye.onFeedback({type:$,messageId:Ve.id,message:Ve})}}}),ge.addEventListener("click",c=>{let x=c.target.closest("button[data-approval-action]");if(!x)return;c.preventDefault(),c.stopPropagation();let v=x.closest(".persona-approval-bubble");if(!v)return;let O=v.getAttribute("data-message-id");if(!O)return;let $=x.getAttribute("data-approval-action");if(!$)return;let U=$==="approve"?"approved":"denied",N=z.getMessages().find(fe=>fe.id===O);if(!(N!=null&&N.approval))return;let ke=v.querySelector("[data-approval-buttons]");ke&&ke.querySelectorAll("button").forEach(re=>{re.disabled=!0,re.style.opacity="0.5",re.style.cursor="not-allowed"}),z.resolveApproval(N.approval,U)});let vt=null,Pe=null,P={artifacts:[],selectedId:null},Z=!1,se={current:null};ge.addEventListener("click",c=>{var re,we,Le,Ve,ct;let x=c.target.closest("[data-download-artifact]");if(!x)return;c.preventDefault(),c.stopPropagation();let v=x.getAttribute("data-download-artifact");if(!v||((Le=(we=(re=n.features)==null?void 0:re.artifacts)==null?void 0:we.onArtifactAction)==null?void 0:Le.call(we,{type:"download",artifactId:v}))===!0)return;let $=z.getArtifactById(v),U=$==null?void 0:$.markdown,X=($==null?void 0:$.title)||"artifact";if(!U){let tt=x.closest("[data-open-artifact]"),gt=tt==null?void 0:tt.closest("[data-message-id]"),ht=gt==null?void 0:gt.getAttribute("data-message-id");if(ht){let He=z.getMessages().find(Je=>Je.id===ht);if(He!=null&&He.rawContent)try{let Je=JSON.parse(He.rawContent);U=(Ve=Je==null?void 0:Je.props)==null?void 0:Ve.markdown,X=((ct=Je==null?void 0:Je.props)==null?void 0:ct.title)||X}catch{}}}if(!U)return;let N=new Blob([U],{type:"text/markdown"}),ke=URL.createObjectURL(N),fe=document.createElement("a");fe.href=ke,fe.download=`${X}.md`,fe.click(),URL.revokeObjectURL(ke)}),ge.addEventListener("click",c=>{var $,U,X;let x=c.target.closest("[data-open-artifact]");if(!x)return;let v=x.getAttribute("data-open-artifact");!v||((X=(U=($=n.features)==null?void 0:$.artifacts)==null?void 0:U.onArtifactAction)==null?void 0:X.call(U,{type:"open",artifactId:v}))===!0||(c.preventDefault(),c.stopPropagation(),Z=!1,z.selectArtifact(v),on())}),ge.addEventListener("keydown",c=>{if(c.key!=="Enter"&&c.key!==" ")return;let g=c.target;g.hasAttribute("data-open-artifact")&&(c.preventDefault(),g.click())});let Mt=De.composerOverlay,zt=(c,g,x)=>{var X,N,ke,fe;let v=g.trim();if(!v||!se.current)return;let O=(X=c.getAttribute("data-tool-call-id"))!=null?X:"",$=x.source==="free-text";e.dispatchEvent(new CustomEvent("persona:askUserQuestion:answered",{detail:{toolUseId:O,answer:v,answers:x.structured,values:(N=x.values)!=null?N:x.source==="multi"?v.split(", "):[v],isFreeText:$,source:x.source},bubbles:!0,composed:!0})),Mo(Mt,O);let U=se.current.getMessages().find(re=>{var we;return((we=re.toolCall)==null?void 0:we.id)===O});(ke=U==null?void 0:U.agentMetadata)!=null&&ke.awaitingLocalTool?se.current.resolveAskUserQuestion(U,(fe=x.structured)!=null?fe:v):se.current.sendMessage(v)},Ht=c=>{var O;let g=se.current;if(!g)return;let x=(O=c.getAttribute("data-tool-call-id"))!=null?O:"",v=g.getMessages().find($=>{var U;return((U=$.toolCall)==null?void 0:U.id)===x});v&&g.persistAskUserQuestionProgress(v,{answers:fl(c,v),currentIndex:An(c)})},sr=c=>Object.entries(c).map(([g,x])=>`${g}: ${Array.isArray(x)?x.join(", "):x}`).join(" | "),xr=c=>{var O,$,U;if((($=(O=n.features)==null?void 0:O.askUserQuestion)==null?void 0:$.groupedAutoAdvance)===!1)return;let g=An(c),x=Ra(c);if(g>=x-1)return;let v=(U=se.current)==null?void 0:U.getMessages().find(X=>{var N;return((N=X.toolCall)==null?void 0:N.id)===c.getAttribute("data-tool-call-id")});v&&(ml(c,v,n,g+1),Ht(c))};Mt.addEventListener("click",c=>{var $,U,X,N,ke,fe,re,we,Le,Ve,ct,tt,gt,ht;let x=c.target.closest("[data-ask-user-action]");if(!x)return;let v=x.closest("[data-persona-ask-sheet-for]");if(!v)return;let O=x.getAttribute("data-ask-user-action");if(c.preventDefault(),c.stopPropagation(),O==="dismiss"){let Fe=($=v.getAttribute("data-tool-call-id"))!=null?$:"";e.dispatchEvent(new CustomEvent("persona:askUserQuestion:dismissed",{detail:{toolUseId:Fe},bubbles:!0,composed:!0})),Mo(Mt,Fe);let He=(U=se.current)==null?void 0:U.getMessages().find(Je=>{var D;return((D=Je.toolCall)==null?void 0:D.id)===Fe});(X=He==null?void 0:He.agentMetadata)!=null&&X.awaitingLocalTool&&((N=se.current)==null||N.markAskUserQuestionResolved(He),(ke=se.current)==null||ke.resolveAskUserQuestion(He,"(dismissed)"));return}if(O==="pick"){let Fe=x.getAttribute("data-option-label");if(!Fe)return;let He=v.getAttribute("data-multi-select")==="true",Je=Eo(v);if(Je&&He){let D=aa(v)[An(v)],Ie=new Set(Array.isArray(D)?D:[]);Ie.has(Fe)?Ie.delete(Fe):Ie.add(Fe),Lo(v,Array.from(Ie)),Ht(v);return}if(Je){Lo(v,Fe),Ht(v),xr(v);return}if(He){let D=x.getAttribute("aria-pressed")==="true";x.setAttribute("aria-pressed",D?"false":"true"),x.classList.toggle("persona-ask-pill-selected",!D);let Ie=v.querySelector('[data-ask-user-action="submit-multi"]');Ie&&(Ie.disabled=Sp(v).length===0);return}zt(v,Fe,{source:"pick",values:[Fe]});return}if(O==="submit-multi"){let Fe=Sp(v);if(Fe.length===0)return;zt(v,Fe.join(", "),{source:"multi",values:Fe});return}if(O==="open-free-text"){let Fe=v.querySelector('[data-ask-free-text-row="true"]');if(Fe){Fe.classList.remove("persona-hidden");let He=Fe.querySelector('[data-ask-free-text-input="true"]');He==null||He.focus()}return}if(O==="focus-free-text"){let Fe=v.querySelector('[data-ask-free-text-input="true"]');Fe==null||Fe.focus();return}if(O==="submit-free-text"){let Fe=v.querySelector('[data-ask-free-text-input="true"]'),He=(fe=Fe==null?void 0:Fe.value)!=null?fe:"";if(!He.trim())return;if(Eo(v)){Lo(v,He.trim()),Ht(v),xr(v);return}zt(v,He,{source:"free-text"});return}if(O==="next"||O==="back"){if(!se.current)return;let Fe=(re=v.getAttribute("data-tool-call-id"))!=null?re:"",He=se.current.getMessages().find(Qe=>{var Ae;return((Ae=Qe.toolCall)==null?void 0:Ae.id)===Fe});if(!He)return;let Je=v.querySelector('[data-ask-free-text-input="true"]'),D=(Le=(we=Je==null?void 0:Je.value)==null?void 0:we.trim())!=null?Le:"";if(D){let Qe=aa(v)[An(v)];(typeof Qe!="string"||Qe!==D)&&Lo(v,D)}let Ie=O==="next"?1:-1,$e=An(v)+Ie;ml(v,He,n,$e),Ht(v);return}if(O==="submit-all"){if(!se.current)return;let Fe=(Ve=v.getAttribute("data-tool-call-id"))!=null?Ve:"",He=se.current.getMessages().find(Qe=>{var Ae;return((Ae=Qe.toolCall)==null?void 0:Ae.id)===Fe});if(!He)return;let Je=v.querySelector('[data-ask-free-text-input="true"]'),D=(tt=(ct=Je==null?void 0:Je.value)==null?void 0:ct.trim())!=null?tt:"";D&&Lo(v,D);let Ie=fl(v,He);se.current.persistAskUserQuestionProgress(He,{answers:Ie,currentIndex:An(v)});let $e=sr(Ie);zt(v,$e||"(submitted)",{source:"submit-all",structured:Ie});return}if(O==="skip"){if(!se.current)return;let Fe=(gt=v.getAttribute("data-tool-call-id"))!=null?gt:"",He=se.current.getMessages().find(Ae=>{var Ft;return((Ft=Ae.toolCall)==null?void 0:Ft.id)===Fe});if(!He)return;let Je=Eo(v),D=An(v),Ie=Ra(v),$e=D>=Ie-1;if(!Je){e.dispatchEvent(new CustomEvent("persona:askUserQuestion:dismissed",{detail:{toolUseId:Fe},bubbles:!0,composed:!0})),Mo(Mt,Fe),(ht=He.agentMetadata)!=null&&ht.awaitingLocalTool&&(se.current.markAskUserQuestionResolved(He),se.current.resolveAskUserQuestion(He,"(dismissed)"));return}Lo(v,"");let Qe=v.querySelector('[data-ask-free-text-input="true"]');if(Qe&&(Qe.value=""),$e){let Ae=fl(v,He),Ft=sr(Ae);zt(v,Ft||"(skipped)",{source:"submit-all",structured:Ae});return}ml(v,He,n,D+1),Ht(v);return}}),Mt.addEventListener("keydown",c=>{var $;if(c.key!=="Enter")return;let x=c.target;if(!(($=x.matches)!=null&&$.call(x,'[data-ask-free-text-input="true"]')))return;let v=x.closest("[data-persona-ask-sheet-for]");if(!v)return;c.preventDefault();let O=x.value;if(O.trim()){if(Eo(v)){Lo(v,O.trim()),Ht(v),xr(v);return}zt(v,O,{source:"free-text"})}});let Fr=c=>{if(!/^[1-9]$/.test(c.key)||c.metaKey||c.ctrlKey||c.altKey)return;let g=c.target;if((g==null?void 0:g.tagName)==="INPUT"||(g==null?void 0:g.tagName)==="TEXTAREA"||g!=null&&g.isContentEditable)return;let x=Mt.querySelector("[data-persona-ask-sheet-for]");if(!x||x.getAttribute("data-ask-layout")!=="rows"||x.getAttribute("data-multi-select")==="true")return;let v=Number(c.key),$=x.querySelectorAll('[data-ask-pill-list="true"] [data-ask-user-action="pick"], [data-ask-pill-list="true"] [data-ask-user-action="focus-free-text"]')[v-1];$&&(c.preventDefault(),$.click())};document.addEventListener("keydown",Fr);let kr=null,ot=null,wr=null,Nr=null,co=()=>{};function jn(){Nr==null||Nr(),Nr=null}let po=()=>{var U;if(!kr||!ot)return;let c=e.classList.contains("persona-artifact-appearance-seamless"),x=((U=e.ownerDocument.defaultView)!=null?U:window).innerWidth<=640;if(!c||e.classList.contains("persona-artifact-narrow-host")||x){ot.style.removeProperty("position"),ot.style.removeProperty("left"),ot.style.removeProperty("top"),ot.style.removeProperty("bottom"),ot.style.removeProperty("width"),ot.style.removeProperty("z-index");return}let v=kr.firstElementChild;if(!v||v===ot)return;let O=10;ot.style.position="absolute",ot.style.top="0",ot.style.bottom="0",ot.style.width=`${O}px`,ot.style.zIndex="5";let $=v.offsetWidth-O/2;ot.style.left=`${Math.max(0,$)}px`},Fn=()=>{},on=()=>{var x,v,O,$,U;if(!vt||!Sn(n))return;gl(e,n),hl(e,n),Fn();let c=($=(O=(v=(x=n.features)==null?void 0:x.artifacts)==null?void 0:v.layout)==null?void 0:O.narrowHostMaxWidth)!=null?$:520,g=j.getBoundingClientRect().width||0;e.classList.toggle("persona-artifact-narrow-host",g>0&&g<=c),vt.update(P),Z?(vt.setMobileOpen(!1),vt.element.classList.add("persona-hidden"),(U=vt.backdrop)==null||U.classList.add("persona-hidden")):P.artifacts.length>0&&(vt.element.classList.remove("persona-hidden"),vt.setMobileOpen(!0)),co()};if(Sn(n)){j.style.position="relative";let c=h("div","persona-flex persona-flex-1 persona-flex-col persona-min-w-0 persona-min-h-0"),g=h("div","persona-flex persona-h-full persona-w-full persona-min-h-0 persona-artifact-split-root");c.appendChild(oe),vt=Lh(n,{onSelect:x=>{var v;return(v=se.current)==null?void 0:v.selectArtifact(x)},onDismiss:()=>{Z=!0,on()}}),vt.element.classList.add("persona-hidden"),kr=g,g.appendChild(c),g.appendChild(vt.element),vt.backdrop&&j.appendChild(vt.backdrop),j.appendChild(g),co=()=>{var v,O,$,U;if(!kr||!vt)return;if(!((($=(O=(v=n.features)==null?void 0:v.artifacts)==null?void 0:O.layout)==null?void 0:$.resizable)===!0)){wr==null||wr(),wr=null,jn(),ot&&(ot.remove(),ot=null),vt.element.style.removeProperty("width"),vt.element.style.removeProperty("maxWidth");return}if(!ot){let X=h("div","persona-artifact-split-handle persona-shrink-0 persona-h-full");X.setAttribute("role","separator"),X.setAttribute("aria-orientation","vertical"),X.setAttribute("aria-label","Resize artifacts panel"),X.tabIndex=0;let N=e.ownerDocument,ke=(U=N.defaultView)!=null?U:window,fe=re=>{var gt,ht;if(!vt||re.button!==0||e.classList.contains("persona-artifact-narrow-host")||ke.innerWidth<=640)return;re.preventDefault(),jn();let we=re.clientX,Le=vt.element.getBoundingClientRect().width,Ve=(ht=(gt=n.features)==null?void 0:gt.artifacts)==null?void 0:ht.layout,ct=Fe=>{let He=kr.getBoundingClientRect().width,Je=e.classList.contains("persona-artifact-appearance-seamless"),D=Je?0:Hh(kr,ke),Ie=Je?0:X.getBoundingClientRect().width||6,$e=Le-(Fe.clientX-we),Qe=Bh($e,He,D,Ie,Ve==null?void 0:Ve.resizableMinWidth,Ve==null?void 0:Ve.resizableMaxWidth);vt.element.style.width=`${Qe}px`,vt.element.style.maxWidth="none",po()},tt=()=>{N.removeEventListener("pointermove",ct),N.removeEventListener("pointerup",tt),N.removeEventListener("pointercancel",tt),Nr=null;try{X.releasePointerCapture(re.pointerId)}catch{}};Nr=tt,N.addEventListener("pointermove",ct),N.addEventListener("pointerup",tt),N.addEventListener("pointercancel",tt);try{X.setPointerCapture(re.pointerId)}catch{}};X.addEventListener("pointerdown",fe),ot=X,kr.insertBefore(X,vt.element),wr=()=>{X.removeEventListener("pointerdown",fe)}}if(ot){let X=P.artifacts.length>0&&!Z;ot.classList.toggle("persona-hidden",!X),po()}},Fn=()=>{var ke,fe,re,we,Le,Ve,ct,tt,gt,ht,Fe,He,Je,D;if(!T||!vt||((fe=(ke=n.launcher)==null?void 0:ke.sidebarMode)!=null?fe:!1)||hr(n)&&vn(n).reveal==="emerge")return;let v=(re=e.ownerDocument.defaultView)!=null?re:window,O=(Le=(we=n.launcher)==null?void 0:we.mobileFullscreen)!=null?Le:!0,$=(ct=(Ve=n.launcher)==null?void 0:Ve.mobileBreakpoint)!=null?ct:640;if(O&&v.innerWidth<=$||!Rh(n,T))return;let U=(ht=(gt=(tt=n.launcher)==null?void 0:tt.width)!=null?gt:n.launcherWidth)!=null?ht:mn,X=(D=(Je=(He=(Fe=n.features)==null?void 0:Fe.artifacts)==null?void 0:He.layout)==null?void 0:Je.expandedPanelWidth)!=null?D:"min(720px, calc(100vw - 24px))";P.artifacts.length>0&&!Z?(j.style.width=X,j.style.maxWidth=X):(j.style.width=U,j.style.maxWidth=U)},typeof ResizeObserver!="undefined"&&(Pe=new ResizeObserver(()=>{on()}),Pe.observe(j))}else j.appendChild(oe),H()&&Ce&&(De.peekBanner&&Ce.appendChild(De.peekBanner),Ce.appendChild(qe));e.appendChild(K),Ce&&e.appendChild(Ce);let Mn=()=>{var Qe,Ae,Ft,mt,dr,Mr,$t,$r,Lr,at,xt,Ur,Hr,Oo,Fo,No,ga,ha,nr,_o,Co,Lt,Zr,Qn,qr,en,Vt,er;if(H()){j.style.width="100%",j.style.maxWidth="100%";let jt=(Ae=(Qe=n.launcher)==null?void 0:Qe.composerBar)!=null?Ae:{},or=K.dataset.state==="expanded",tn=(Ft=jt.expandedSize)!=null?Ft:"anchored";if(!(or&&tn!=="fullscreen")){oe.style.background="",oe.style.border="",oe.style.borderRadius="",oe.style.overflow="",oe.style.boxShadow="";return}let gr=(dr=(mt=n.theme)==null?void 0:mt.components)==null?void 0:dr.panel,$n=Ta(n),Zn=($o,oi)=>{var Qa;return $o==null||$o===""?oi:(Qa=Aa($n,$o))!=null?Qa:$o},ti="1px solid var(--persona-border)",ri="var(--persona-palette-shadows-xl, 0 25px 50px -12px rgba(0, 0, 0, 0.25))",ni="var(--persona-panel-radius, var(--persona-radius-xl, 0.75rem))";oe.style.background="var(--persona-surface, #ffffff)",oe.style.border=Zn(gr==null?void 0:gr.border,ti),oe.style.borderRadius=Zn(gr==null?void 0:gr.borderRadius,ni),oe.style.boxShadow=Zn(gr==null?void 0:gr.shadow,ri),oe.style.overflow="hidden";return}let c=hr(n),g=($t=(Mr=n.launcher)==null?void 0:Mr.sidebarMode)!=null?$t:!1,x=c||g||((Lr=($r=n.launcher)==null?void 0:$r.fullHeight)!=null?Lr:!1),v=((at=n.launcher)==null?void 0:at.enabled)===!1,O=(Ur=(xt=n.theme)==null?void 0:xt.components)==null?void 0:Ur.panel,$=Ta(n),U=(jt,or)=>{var tn;return jt==null||jt===""?or:(tn=Aa($,jt))!=null?tn:jt},X=(Hr=e.ownerDocument.defaultView)!=null?Hr:window,N=(Fo=(Oo=n.launcher)==null?void 0:Oo.mobileFullscreen)!=null?Fo:!0,ke=(ga=(No=n.launcher)==null?void 0:No.mobileBreakpoint)!=null?ga:640,fe=X.innerWidth<=ke,re=N&&fe&&T,we=(nr=(ha=n.launcher)==null?void 0:ha.position)!=null?nr:"bottom-left",Le=we==="bottom-left"||we==="top-left",Ve=(Co=(_o=n.launcher)==null?void 0:_o.zIndex)!=null?Co:Dr,ct=g||re?"none":"1px solid var(--persona-border)",tt=re?"none":g?Le?"var(--persona-palette-shadows-sidebar-left, 2px 0 12px rgba(0, 0, 0, 0.08))":"var(--persona-palette-shadows-sidebar-right, -2px 0 12px rgba(0, 0, 0, 0.08))":"var(--persona-palette-shadows-xl, 0 25px 50px -12px rgba(0, 0, 0, 0.25))";c&&!re&&(tt="none",ct="none");let gt=g||re?"0":"var(--persona-panel-radius, var(--persona-radius-xl, 0.75rem))",ht=U(O==null?void 0:O.border,ct),Fe=U(O==null?void 0:O.shadow,tt),He=U(O==null?void 0:O.borderRadius,gt),Je=Se.scrollTop;e.style.cssText="",K.style.cssText="",j.style.cssText="",oe.style.cssText="",Se.style.cssText="",qe.style.cssText="";let D=()=>{var or;if(Je<=0)return;((or=Se.ownerDocument.defaultView)!=null?or:window).requestAnimationFrame(()=>{if(Se.scrollTop===Je)return;let tn=Se.scrollHeight-Se.clientHeight;tn<=0||(Se.scrollTop=Math.min(Je,tn))})};if(re){K.classList.remove("persona-bottom-6","persona-right-6","persona-left-6","persona-top-6","persona-bottom-4","persona-right-4","persona-left-4","persona-top-4"),K.style.cssText=`
|
|
71
71
|
position: fixed !important;
|
|
72
72
|
inset: 0 !important;
|
|
73
73
|
width: 100% !important;
|
|
@@ -103,7 +103,7 @@ Please report this to https://github.com/markedjs/marked.`,r){let o="<p>An error
|
|
|
103
103
|
overflow: hidden !important;
|
|
104
104
|
border-radius: 0 !important;
|
|
105
105
|
border: none !important;
|
|
106
|
-
`,Se.style.flex="1 1 0%",Se.style.minHeight="0",Se.style.overflowY="auto",qe.style.flexShrink="0",M=!0,D();return}let Ie=(Zr=(Lt=n==null?void 0:n.launcher)==null?void 0:Lt.width)!=null?Zr:n==null?void 0:n.launcherWidth,$e=Ie!=null?Ie:mn;if(!g&&!c)
|
|
106
|
+
`,Se.style.flex="1 1 0%",Se.style.minHeight="0",Se.style.overflowY="auto",qe.style.flexShrink="0",M=!0,D();return}let Ie=(Zr=(Lt=n==null?void 0:n.launcher)==null?void 0:Lt.width)!=null?Zr:n==null?void 0:n.launcherWidth,$e=Ie!=null?Ie:mn;if(!g&&!c)v&&x?(j.style.width="100%",j.style.maxWidth="100%"):(j.style.width=$e,j.style.maxWidth=$e);else if(c)if(vn(n).reveal==="emerge"){let or=vn(n).width;j.style.width=or,j.style.maxWidth=or}else j.style.width="100%",j.style.maxWidth="100%";if(Fn(),j.style.boxShadow=Fe,j.style.borderRadius=He,oe.style.border=ht,oe.style.borderRadius=He,c&&!re&&(O==null?void 0:O.border)===void 0&&(oe.style.border="none",vn(n).side==="right"?oe.style.borderLeft="1px solid var(--persona-border)":oe.style.borderRight="1px solid var(--persona-border)"),x&&(e.style.display="flex",e.style.flexDirection="column",e.style.height="100%",e.style.minHeight="0",v&&(e.style.width="100%"),K.style.display="flex",K.style.flexDirection="column",K.style.flex="1 1 0%",K.style.minHeight="0",K.style.maxHeight="100%",K.style.height="100%",v&&(K.style.overflow="hidden"),j.style.display="flex",j.style.flexDirection="column",j.style.flex="1 1 0%",j.style.minHeight="0",j.style.maxHeight="100%",j.style.height="100%",j.style.overflow="hidden",oe.style.display="flex",oe.style.flexDirection="column",oe.style.flex="1 1 0%",oe.style.minHeight="0",oe.style.maxHeight="100%",oe.style.overflow="hidden",Se.style.flex="1 1 0%",Se.style.minHeight="0",Se.style.overflowY="auto",qe.style.flexShrink="0"),K.classList.remove("persona-bottom-6","persona-right-6","persona-left-6","persona-top-6","persona-bottom-4","persona-right-4","persona-left-4","persona-top-4"),!g&&!v&&!c&&((Qn=On[we])!=null?Qn:On["bottom-right"]).split(" ").forEach(or=>K.classList.add(or)),g){let jt=(en=(qr=n.launcher)==null?void 0:qr.sidebarWidth)!=null?en:"420px";K.style.cssText=`
|
|
107
107
|
position: fixed !important;
|
|
108
108
|
top: 0 !important;
|
|
109
109
|
bottom: 0 !important;
|
|
@@ -128,7 +128,7 @@ Please report this to https://github.com/markedjs/marked.`,r){let o="<p>An error
|
|
|
128
128
|
margin: 0 !important;
|
|
129
129
|
padding: 0 !important;
|
|
130
130
|
box-shadow: ${Fe} !important;
|
|
131
|
-
border-radius: ${
|
|
131
|
+
border-radius: ${He} !important;
|
|
132
132
|
`,j.style.setProperty("width","100%","important"),j.style.setProperty("max-width","100%","important"),oe.style.cssText=`
|
|
133
133
|
display: flex !important;
|
|
134
134
|
flex-direction: column !important;
|
|
@@ -138,15 +138,15 @@ Please report this to https://github.com/markedjs/marked.`,r){let o="<p>An error
|
|
|
138
138
|
min-height: 0 !important;
|
|
139
139
|
max-height: 100% !important;
|
|
140
140
|
overflow: hidden !important;
|
|
141
|
-
border-radius: ${
|
|
141
|
+
border-radius: ${He} !important;
|
|
142
142
|
border: ${ht} !important;
|
|
143
143
|
`,qe.style.cssText=`
|
|
144
144
|
flex-shrink: 0 !important;
|
|
145
145
|
border-top: none !important;
|
|
146
146
|
padding: 8px 16px 12px 16px !important;
|
|
147
|
-
`}if(!A&&!c){let jt="max-height: -moz-available !important; max-height: stretch !important;",or=g?"":"padding-top: 1.25em !important;",tn=g?"":`z-index: ${(er=(Vt=n.launcher)==null?void 0:Vt.zIndex)!=null?er:Dr} !important;`;K.style.cssText+=jt+or+tn}D()};Mn(),wo(e,n),gl(e,n),hl(e,n);let At=[];At.push(()=>{document.removeEventListener("keydown",Fr)});let ir=null,lr=null;At.push(()=>{ir==null||ir(),ir=null,lr==null||lr(),lr=null}),Pe&&At.push(()=>{Pe==null||Pe.disconnect(),Pe=null}),At.push(()=>{wr==null||wr(),wr=null,jn(),ot&&(ot.remove(),ot=null),vt==null||vt.element.style.removeProperty("width"),vt==null||vt.element.style.removeProperty("maxWidth")}),xe&&At.push(()=>{pe!==null&&(cancelAnimationFrame(pe),pe=null),ce==null||ce.destroy(),ce=null,G==null||G.destroy(),G=null,Y=null});let an=null,uo=()=>{an&&(an(),an=null),n.colorScheme==="auto"&&(an=Gi(()=>{wo(e,n)}))};uo(),At.push(()=>{an&&(an(),an=null)});let yn=(Hu=n.features)==null?void 0:Hu.streamAnimation;if(yn!=null&&yn.type&&yn.type!=="none"){let c=Ts(yn.type,yn.plugins);c&&(sp(c,e),At.push(()=>rh(e)))}let Ln=Th(Rt),sn=null,z,he=!1,ln=Kg(),Pn=new Map,Nn=new Map,Fa=0,In=Ji(),Rn=0,Hn=null,Gn=!1,Io=!1,_s=4,Na=24,$s=80,la=new Map,wt={active:!1,manuallyDeactivated:!1,lastUserMessageWasVoice:!1,lastUserMessageId:null},_a=(Wu=(Bu=n.voiceRecognition)==null?void 0:Bu.autoResume)!=null?Wu:!1,bn=c=>{a.emit("voice:state",{active:wt.active,source:c,timestamp:Date.now()})},Yr=()=>{m(c=>({...c,voiceState:{active:wt.active,timestamp:Date.now(),manuallyDeactivated:wt.manuallyDeactivated}}))},Us=()=>{var A,O;if(((A=n.voiceRecognition)==null?void 0:A.enabled)===!1)return;let c=Ip(d.voiceState),g=!!c.active,x=Number((O=c.timestamp)!=null?O:0);wt.manuallyDeactivated=!!c.manuallyDeactivated,g&&Date.now()-x<V0&&setTimeout(()=>{var $,U;wt.active||(wt.manuallyDeactivated=!1,((U=($=n.voiceRecognition)==null?void 0:$.provider)==null?void 0:U.type)==="runtype"?z.toggleVoice().then(()=>{wt.active=z.isVoiceActive(),bn("restore"),z.isVoiceActive()&&bo()}):Bo("restore"))},1e3)},qs=()=>z?$h(z.getMessages()).filter(c=>!c.__skipPersist):[];function da(c){if(!(i!=null&&i.save))return;let x={messages:c?$h(c):z?qs():[],metadata:d,artifacts:P.artifacts,selectedArtifactId:P.selectedId};try{let A=i.save(x);A instanceof Promise&&A.catch(O=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",O)})}catch(A){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",A)}}let Xn=null,zs=()=>K.querySelector("#persona-scroll-container")||Se,Ro=()=>{Xn!==null&&(cancelAnimationFrame(Xn),Xn=null),Gn=!1},$a=()=>{Hn!==null&&(cancelAnimationFrame(Hn),Hn=null),Io=!1,Ro()},Jn=()=>{if(!rt()||de){lt.parentNode&<.remove(),lt.style.display="none";return}lt.parentNode!==oe&&oe.appendChild(lt),Ir();let c=ws(Se)>0;lt.style.display=In.isFollowing()||!c?"none":""},Ua=()=>{In.pause()&&($a(),Jn())},fo=()=>{In.resume(),Jn()},mo=(c=!1)=>{In.isFollowing()&&(!c&&!he||(Hn!==null&&(cancelAnimationFrame(Hn),Hn=null),Io=!0,Hn=requestAnimationFrame(()=>{Hn=null,Io=!1,In.isFollowing()&&Vs(zs(),c?220:140)})))},Vs=(c,g=500)=>{let x=c.scrollTop,A=ws(c),O=A-x;if(Math.abs(O)<1){Rn=c.scrollTop;return}if(Math.abs(O)>=$s){Ro(),Gn=!0,c.scrollTop=A,Rn=c.scrollTop,Gn=!1;return}Ro();let $=performance.now();Gn=!0;let U=N=>1-Math.pow(1-N,3),X=N=>{if(!In.isFollowing()){Ro();return}let ke=ws(c);ke!==A&&(A=ke,O=A-x);let fe=N-$,re=Math.min(fe/g,1),we=U(re),Le=x+O*we;c.scrollTop=Le,Rn=c.scrollTop,re<1?Xn=requestAnimationFrame(X):(c.scrollTop=A,Rn=c.scrollTop,Xn=null,Gn=!1)};Xn=requestAnimationFrame(X)},js=c=>{let g=new Map;c.forEach(x=>{let A=la.get(x.id);g.set(x.id,{streaming:x.streaming,role:x.role}),!A&&x.role==="assistant"&&a.emit("assistant:message",x),x.role==="assistant"&&(A!=null&&A.streaming)&&x.streaming===!1&&a.emit("assistant:complete",x),x.variant==="approval"&&x.approval&&(A?x.approval.status!=="pending"&&a.emit("approval:resolved",{approval:x.approval,decision:x.approval.status}):a.emit("approval:requested",{approval:x.approval,message:x}))}),la.clear(),g.forEach((x,A)=>{la.set(A,x)})},Ho=(c,g,x)=>{var tt,gt,ht,Fe,Be,Je;let A=document.createElement("div"),$=(()=>{var Ie;let D=o.find($e=>$e.renderLoadingIndicator);if(D!=null&&D.renderLoadingIndicator)return D.renderLoadingIndicator;if((Ie=n.loadingIndicator)!=null&&Ie.render)return n.loadingIndicator.render})(),U=(D,Ie)=>Ie==null?!1:typeof Ie=="string"?(D.textContent=Ie,!0):(D.appendChild(Ie),!0),X=new Set,N=new Set,ke=o.some(D=>D.renderAskUserQuestion),fe=[],re=[],we=n.enableComponentStreaming!==!1;if(g.forEach(D=>{var $r,Lr,at,xt,Ur,Hr,Oo,Fo,No,ga,ha,nr,_o,Co;X.add(D.id);let Ie=ke&&ao(D),$e=!Ie&&D.role==="assistant"&&!D.variant&&we&&Cl(D);if(!$e&&Nn.has(D.id)){let Lt=c.querySelector(`#wrapper-${D.id}`);Lt==null||Lt.removeAttribute("data-preserve-runtime"),Nn.delete(D.id)}let Qe=ao(D)?`:${($r=D.agentMetadata)!=null&&$r.askUserQuestionAnswered?"a":"u"}:${(Lr=D.agentMetadata)!=null&&Lr.askUserQuestionAnswers?Object.keys(D.agentMetadata.askUserQuestionAnswers).length:0}`:"",Ae=Jg(D,Fa)+Qe,Ft=Ie||$e?null:Yg(ln,D.id,Ae);if(Ft){A.appendChild(Ft.cloneNode(!0)),ao(D)&&((at=D.toolCall)!=null&&at.id)&&((xt=D.agentMetadata)==null?void 0:xt.awaitingLocalTool)===!0&&!((Ur=D.agentMetadata)!=null&&Ur.askUserQuestionAnswered)&&(N.add(D.toolCall.id),Ha(D,n,De.composerOverlay));return}let mt=null,dr=o.find(Lt=>!!(D.variant==="reasoning"&&Lt.renderReasoning||D.variant==="tool"&&Lt.renderToolCall||D.variant==="approval"&&Lt.renderApproval||!D.variant&&Lt.renderMessage)),Mr=(Hr=n.layout)==null?void 0:Hr.messages;if(ao(D)&&((Oo=D.agentMetadata)==null?void 0:Oo.askUserQuestionAnswered)===!0){Pn.delete(D.id);let Lt=c.querySelector(`#wrapper-${D.id}`);Lt==null||Lt.removeAttribute("data-preserve-runtime");return}if(ao(D)&&((No=(Fo=n.features)==null?void 0:Fo.askUserQuestion)==null?void 0:No.enabled)!==!1){let Lt=o.find(Zr=>typeof Zr.renderAskUserQuestion=="function");if(Lt&&se.current){let Zr=Pn.get(D.id),Qn=Zr!==Ae,qr=null;if(Qn){let{payload:er,complete:jt}=so(D),or=D.id,tn=()=>{var cn;return(cn=se.current)==null?void 0:cn.getMessages().find(gr=>gr.id===or)};qr=Lt.renderAskUserQuestion({message:D,payload:er,complete:jt,resolve:cn=>{var $n;let gr=tn();gr&&(($n=se.current)==null||$n.resolveAskUserQuestion(gr,cn))},dismiss:()=>{var gr,$n,Zn;let cn=tn();(gr=cn==null?void 0:cn.agentMetadata)!=null&&gr.awaitingLocalTool&&(($n=se.current)==null||$n.markAskUserQuestionResolved(cn),(Zn=se.current)==null||Zn.resolveAskUserQuestion(cn,"(dismissed)"))},config:n})}let en=Zr!=null;if(Qn&&qr===null&&!en){((ga=D.agentMetadata)==null?void 0:ga.awaitingLocalTool)===!0&&!((ha=D.agentMetadata)!=null&&ha.askUserQuestionAnswered)&&(N.add(D.toolCall.id),Ha(D,n,De.composerOverlay));return}let Vt=document.createElement("div");Vt.className="persona-flex",Vt.id=`wrapper-${D.id}`,Vt.setAttribute("data-wrapper-id",D.id),Vt.setAttribute("data-ask-plugin-stub","true"),Vt.setAttribute("data-preserve-runtime","true"),A.appendChild(Vt),fe.push({messageId:D.id,fingerprint:Ae,bubble:qr});return}else{((nr=D.agentMetadata)==null?void 0:nr.awaitingLocalTool)===!0&&!((_o=D.agentMetadata)!=null&&_o.askUserQuestionAnswered)&&(N.add(D.toolCall.id),Ha(D,n,De.composerOverlay));return}}else if(dr)if(D.variant==="reasoning"&&D.reasoning&&dr.renderReasoning){if(!We)return;mt=dr.renderReasoning({message:D,defaultRenderer:()=>hp(D,n),config:n})}else if(D.variant==="tool"&&D.toolCall&&dr.renderToolCall){if(!Ke)return;mt=dr.renderToolCall({message:D,defaultRenderer:()=>xp(D,n),config:n})}else if(D.variant==="approval"&&D.approval&&dr.renderApproval){if(n.approval===!1)return;mt=dr.renderApproval({message:D,defaultRenderer:()=>Tp(D,n),config:n})}else dr.renderMessage&&(mt=dr.renderMessage({message:D,defaultRenderer:()=>{let Lt=Ma(D,x,Mr,n.messageActions,Ye,{loadingIndicatorRenderer:$,widgetConfig:n});return D.role!=="user"&&Mp(Lt,D,n,z),Lt},config:n}));if(!mt&&$e){let Lt=wl(D);if(Lt){let Zr=Nn.get(D.id),Qn=Zr!==Ae,qr=n.wrapComponentDirectiveInBubble!==!1,en=null;if(Qn){let Vt=bl(Lt,{config:n,message:D,transform:x});if(Vt)if(qr){let er=document.createElement("div");if(er.className=["persona-message-bubble","persona-max-w-[85%]","persona-rounded-2xl","persona-bg-persona-surface","persona-border","persona-border-persona-message-border","persona-p-4"].join(" "),er.id=`bubble-${D.id}`,er.setAttribute("data-message-id",D.id),D.content&&D.content.trim()){let jt=document.createElement("div");jt.className="persona-mb-3 persona-text-sm persona-leading-relaxed",jt.innerHTML=x({text:D.content,message:D,streaming:!!D.streaming,raw:D.rawContent}),er.appendChild(jt)}er.appendChild(Vt),en=er}else{let er=document.createElement("div");if(er.className="persona-flex persona-flex-col persona-w-full persona-max-w-full persona-gap-3 persona-items-stretch",er.id=`bubble-${D.id}`,er.setAttribute("data-message-id",D.id),er.setAttribute("data-persona-component-directive","true"),D.content&&D.content.trim()){let jt=document.createElement("div");jt.className="persona-text-sm persona-leading-relaxed persona-text-persona-primary persona-w-full",jt.innerHTML=x({text:D.content,message:D,streaming:!!D.streaming,raw:D.rawContent}),er.appendChild(jt)}er.appendChild(Vt),en=er}}if(en||Zr!=null){let Vt=document.createElement("div");Vt.className="persona-flex",Vt.id=`wrapper-${D.id}`,Vt.setAttribute("data-wrapper-id",D.id),Vt.setAttribute("data-component-directive-stub","true"),Vt.setAttribute("data-preserve-runtime","true"),qr||Vt.classList.add("persona-w-full"),A.appendChild(Vt),re.push({messageId:D.id,fingerprint:Ae,bubble:en});return}}}if(!mt)if(D.variant==="reasoning"&&D.reasoning){if(!We)return;mt=hp(D,n)}else if(D.variant==="tool"&&D.toolCall){if(!Ke)return;mt=xp(D,n)}else if(D.variant==="approval"&&D.approval){if(n.approval===!1)return;mt=Tp(D,n)}else{let Lt=(Co=n.layout)==null?void 0:Co.messages;Lt!=null&&Lt.renderUserMessage&&D.role==="user"?mt=Lt.renderUserMessage({message:D,config:n,streaming:!!D.streaming}):Lt!=null&&Lt.renderAssistantMessage&&D.role==="assistant"?mt=Lt.renderAssistantMessage({message:D,config:n,streaming:!!D.streaming}):mt=Ma(D,x,Lt,n.messageActions,Ye,{loadingIndicatorRenderer:$,widgetConfig:n}),D.role!=="user"&&mt&&Mp(mt,D,n,z)}let $t=document.createElement("div");$t.className="persona-flex",$t.id=`wrapper-${D.id}`,$t.setAttribute("data-wrapper-id",D.id),D.role==="user"&&$t.classList.add("persona-justify-end"),(mt==null?void 0:mt.getAttribute("data-persona-component-directive"))==="true"&&$t.classList.add("persona-w-full"),$t.appendChild(mt),Qg(ln,D.id,Ae,$t),A.appendChild($t)}),De.composerOverlay&&De.composerOverlay.querySelectorAll("[data-persona-ask-sheet-for]").forEach(Ie=>{let $e=Ie.getAttribute("data-persona-ask-sheet-for");$e&&!N.has($e)&&Mo(De.composerOverlay,$e)}),(gt=(tt=n.features)==null?void 0:tt.toolCallDisplay)!=null&>.grouped){let D=[],Ie=[];g.forEach($e=>{if($e.variant==="tool"&&$e.toolCall&&Ke){Ie.push($e);return}Ie.length>1&&D.push(Ie),Ie=[]}),Ie.length>1&&D.push(Ie),D.forEach(($e,Qe)=>{var Lr,at;let Ae=$e.map(xt=>Array.from(A.children).find(Ur=>Ur instanceof HTMLElement&&Ur.getAttribute("data-wrapper-id")===xt.id)).filter(xt=>!!xt);if(Ae.length<2)return;let Ft=document.createElement("div");Ft.className="persona-flex",Ft.id=`wrapper-tool-group-${Qe}-${$e[0].id}`,Ft.setAttribute("data-wrapper-id",`tool-group-${Qe}-${$e[0].id}`);let mt=document.createElement("div");mt.className="persona-tool-group persona-flex persona-w-full persona-flex-col persona-gap-2",mt.setAttribute("data-persona-tool-group","true");let dr=document.createElement("div");dr.className="persona-tool-group-summary persona-text-xs persona-text-persona-muted";let Mr=`Called ${$e.length} tools`,$t=(at=(Lr=n.toolCall)==null?void 0:Lr.renderGroupedSummary)==null?void 0:at.call(Lr,{messages:$e,toolCalls:$e.map(xt=>xt.toolCall).filter(xt=>!!xt),defaultSummary:Mr,config:n});U(dr,$t)||(dr.textContent=Mr);let $r=document.createElement("div");$r.className="persona-tool-group-stack persona-flex persona-flex-col",mt.append(dr,$r),Ft.appendChild(mt),Ae[0].before(Ft),Ae.forEach((xt,Ur)=>{let Hr=document.createElement("div");Hr.className="persona-tool-group-item persona-relative",Hr.setAttribute("data-persona-tool-group-item","true"),Ur<Ae.length-1&&Hr.setAttribute("data-persona-tool-group-connector","true"),Hr.appendChild(xt),$r.appendChild(Hr)})})}Zg(ln,X);let Le=g.some(D=>D.role==="assistant"&&D.streaming),Ve=g[g.length-1],ct=(Ve==null?void 0:Ve.role)==="assistant"&&!Ve.streaming&&Ve.variant!=="approval";if(he&&g.some(D=>D.role==="user")&&!Le&&!ct){let D={config:n,streaming:!0,location:"standalone",defaultRenderer:oa},Ie=o.find(Qe=>Qe.renderLoadingIndicator),$e=null;if(Ie!=null&&Ie.renderLoadingIndicator&&($e=Ie.renderLoadingIndicator(D)),$e===null&&((ht=n.loadingIndicator)!=null&&ht.render)&&($e=n.loadingIndicator.render(D)),$e===null&&($e=oa()),$e){let Qe=document.createElement("div"),Ae=((Fe=n.loadingIndicator)==null?void 0:Fe.showBubble)!==!1;Qe.className=Ae?["persona-max-w-[85%]","persona-rounded-2xl","persona-text-sm","persona-leading-relaxed","persona-shadow-sm","persona-bg-persona-surface","persona-border","persona-text-persona-primary","persona-px-5","persona-py-3"].join(" "):["persona-max-w-[85%]","persona-text-sm","persona-leading-relaxed","persona-text-persona-primary"].join(" "),Qe.setAttribute("data-typing-indicator","true"),Qe.style.borderColor="var(--persona-message-assistant-border, var(--persona-border, #e5e7eb))",Qe.appendChild($e);let Ft=document.createElement("div");Ft.className="persona-flex",Ft.id="wrapper-typing-indicator",Ft.setAttribute("data-wrapper-id","typing-indicator"),Ft.appendChild(Qe),A.appendChild(Ft)}}if(!he&&g.length>0){let D=g[g.length-1],Ie={config:n,lastMessage:D,messageCount:g.length},$e=o.find(Ae=>Ae.renderIdleIndicator),Qe=null;if($e!=null&&$e.renderIdleIndicator&&(Qe=$e.renderIdleIndicator(Ie)),Qe===null&&((Be=n.loadingIndicator)!=null&&Be.renderIdle)&&(Qe=n.loadingIndicator.renderIdle(Ie)),Qe){let Ae=document.createElement("div"),Ft=((Je=n.loadingIndicator)==null?void 0:Je.showBubble)!==!1;Ae.className=Ft?["persona-max-w-[85%]","persona-rounded-2xl","persona-text-sm","persona-leading-relaxed","persona-shadow-sm","persona-bg-persona-surface","persona-border","persona-border-persona-message-border","persona-text-persona-primary","persona-px-5","persona-py-3"].join(" "):["persona-max-w-[85%]","persona-text-sm","persona-leading-relaxed","persona-text-persona-primary"].join(" "),Ae.setAttribute("data-idle-indicator","true"),Ae.appendChild(Qe);let mt=document.createElement("div");mt.className="persona-flex",mt.id="wrapper-idle-indicator",mt.setAttribute("data-wrapper-id","idle-indicator"),mt.appendChild(Ae),A.appendChild(mt)}}if(Xi(c,A),fe.length>0)for(let{messageId:D,fingerprint:Ie,bubble:$e}of fe){let Qe=c.querySelector(`#wrapper-${D}`);Qe&&$e!==null&&(Qe.replaceChildren($e),Qe.setAttribute("data-bubble-fp",Ie),Pn.set(D,Ie))}if(Pn.size>0)for(let D of Pn.keys())X.has(D)||Pn.delete(D);if(re.length>0)for(let{messageId:D,fingerprint:Ie,bubble:$e}of re){let Qe=c.querySelector(`#wrapper-${D}`);Qe&&$e!==null&&(Qe.replaceChildren($e),Qe.setAttribute("data-bubble-fp",Ie),Nn.set(D,Ie))}if(Nn.size>0)for(let D of Nn.keys())X.has(D)||Nn.delete(D)},go=null,Gs=()=>{var x;if(go)return;let c=A=>{let O=A.composedPath();O.includes(K)||Ce&&O.includes(Ce)||qt(!1,"user")};go=c,((x=e.ownerDocument)!=null?x:document).addEventListener("pointerdown",c,!0)},qa=()=>{var g;if(!go)return;((g=e.ownerDocument)!=null?g:document).removeEventListener("pointerdown",go,!0),go=null};At.push(()=>qa());let ho=null,Xs=()=>{var x;if(ho)return;let c=A=>{A.key==="Escape"&&(A.isComposing||qt(!1,"user"))};ho=c,((x=e.ownerDocument)!=null?x:document).addEventListener("keydown",c,!0)},za=()=>{var g;if(!ho)return;((g=e.ownerDocument)!=null?g:document).removeEventListener("keydown",ho,!0),ho=null};At.push(()=>za());let xo=!1,Va=new Set,Js=()=>{var g,x,A,O;let c=(A=(x=(g=n.launcher)==null?void 0:g.composerBar)==null?void 0:x.peek)==null?void 0:A.streamAnimation;return c||((O=n.features)==null?void 0:O.streamAnimation)},Kn=()=>{var gt,ht,Fe,Be;if(!H())return;let c=De.peekBanner,g=De.peekTextNode;if(!c||!g)return;if(R){c.classList.remove("persona-pill-peek--visible");return}let x=(gt=z==null?void 0:z.getMessages())!=null?gt:[],A;for(let Je=x.length-1;Je>=0;Je--){let D=x[Je];if(D.role==="assistant"&&D.content){A=D;break}}if(!A){c.classList.remove("persona-pill-peek--visible");return}let O=A.content,$=!!A.streaming,U=Js(),X=Qi(U),N=X.type!=="none"?Ts(X.type,U==null?void 0:U.plugins):null,ke=((ht=N==null?void 0:N.isAnimating)==null?void 0:ht.call(N,A))===!0,fe=N!==null&&($||ke);fe&&N&&!Va.has(N.name)&&(sp(N,e),Va.add(N.name));let re=fe&&(N!=null&&N.containerClass)?N.containerClass:null,we=(Fe=g.dataset.personaPeekStreamClass)!=null?Fe:null;we&&we!==re&&(g.classList.remove(we),delete g.dataset.personaPeekStreamClass),re&&we!==re&&(g.classList.add(re),g.dataset.personaPeekStreamClass=re),fe?(g.style.setProperty("--persona-stream-step",`${X.speed}ms`),g.style.setProperty("--persona-stream-duration",`${X.duration}ms`)):(g.style.removeProperty("--persona-stream-step"),g.style.removeProperty("--persona-stream-duration"));let Le=fe?Zi(O,X.buffer,N,A,$):O;if(fe&&X.placeholder==="skeleton"&&$&&(!Le||!Le.trim())){let Je=document.createElement("div"),D=Es();D.classList.add("persona-pill-peek__skeleton"),Je.appendChild(D),Xi(g,Je)}else{let Je=Math.max(0,Le.length-100),D=Le.length>100?Le.slice(-100):Le,Ie=Jo(D);if(!fe||!N){let $e=Le.length>100?`\u2026${D}`:D;g.textContent!==$e&&(g.textContent=$e)}else{let $e=Ie;(N.wrap==="char"||N.wrap==="word")&&($e=ks(Ie,N.wrap,`peek-${A.id}`,{skipTags:N.skipTags,startIndex:Je}));let Qe=document.createElement("div");if(Qe.innerHTML=$e,N.useCaret&&D.length>0){let Ae=el(),Ft=Qe.querySelectorAll(".persona-stream-char, .persona-stream-word"),mt=Ft[Ft.length-1];mt!=null&&mt.parentNode?mt.parentNode.insertBefore(Ae,mt.nextSibling):Qe.appendChild(Ae)}Xi(g,Qe),(Be=N.onAfterRender)==null||Be.call(N,{container:g,bubble:c,messageId:A.id,message:A,speed:X.speed,duration:X.duration})}}let tt=he||xo;c.classList.toggle("persona-pill-peek--visible",tt)};if(H()){let c=De.peekBanner;if(c){let A=O=>{O.preventDefault(),O.stopPropagation(),qt(!0,"user")};c.addEventListener("pointerdown",A),At.push(()=>{c.removeEventListener("pointerdown",A)})}let g=()=>{xo||(xo=!0,Kn())},x=()=>{xo&&(xo=!1,Kn())};j.addEventListener("pointerenter",g),j.addEventListener("pointerleave",x),At.push(()=>{j.removeEventListener("pointerenter",g),j.removeEventListener("pointerleave",x)}),Ce&&(Ce.addEventListener("pointerenter",g),Ce.addEventListener("pointerleave",x),At.push(()=>{Ce.removeEventListener("pointerenter",g),Ce.removeEventListener("pointerleave",x)}))}let Ks=c=>{var we,Le,Ve,ct,tt,gt,ht,Fe;let g=(Le=(we=n.launcher)==null?void 0:we.composerBar)!=null?Le:{},x=(Ve=g.expandedSize)!=null?Ve:"anchored",A=(ct=g.bottomOffset)!=null?ct:"16px",O=g.collapsedMaxWidth,$=(tt=g.expandedMaxWidth)!=null?tt:"880px",U=(gt=g.expandedTopOffset)!=null?gt:"5vh",X=(ht=g.modalMaxWidth)!=null?ht:"880px",N=(Fe=g.modalMaxHeight)!=null?Fe:"min(90vh, 800px)",ke="calc(100vw - 32px)",fe="var(--persona-pill-area-height, 80px)",re=K.style;if(re.left="",re.right="",re.top="",re.bottom="",re.transform="",re.width="",re.maxWidth="",re.height="",re.maxHeight="",Ce){let Be=Ce.style;Be.bottom=A,Be.width=O!=null?O:""}if(c&&x!=="fullscreen"){if(x==="modal"){re.top="50%",re.left="50%",re.transform="translate(-50%, -50%)",re.bottom="auto",re.right="auto",re.width=X,re.maxWidth=ke,re.maxHeight=N,re.height=N;return}re.left="50%",re.transform="translateX(-50%)",re.bottom=`calc(${A} + ${fe})`,re.top=U,re.width=$,re.maxWidth=ke}},yo=()=>{var N,ke,fe,re,we,Le,Ve,ct;if(!B())return;if(H()){let gt=(fe=((ke=(N=n.launcher)==null?void 0:N.composerBar)!=null?ke:{}).expandedSize)!=null?fe:"anchored",ht=R?"expanded":"collapsed";K.dataset.state=ht,K.dataset.expandedSize=gt,Ce&&(Ce.dataset.state=ht,Ce.dataset.expandedSize=gt),K.style.removeProperty("display"),K.classList.remove("persona-pointer-events-none","persona-opacity-0"),j.classList.remove("persona-scale-95","persona-opacity-0","persona-scale-100","persona-opacity-100"),Ks(R),oe.style.display=R?"flex":"none",Mn(),R?(Gs(),Xs()):(qa(),za()),Kn();return}let c=hr(n),g=(re=e.ownerDocument.defaultView)!=null?re:window,x=(Le=(we=n.launcher)==null?void 0:we.mobileBreakpoint)!=null?Le:640,A=(ct=(Ve=n.launcher)==null?void 0:Ve.mobileFullscreen)!=null?ct:!0,O=g.innerWidth<=x,$=A&&O&&T,U=vn(n).reveal;R?(K.style.removeProperty("display"),K.style.display=c?"flex":"",K.classList.remove("persona-pointer-events-none","persona-opacity-0"),j.classList.remove("persona-scale-95","persona-opacity-0"),j.classList.add("persona-scale-100","persona-opacity-100"),_?_.element.style.display="none":I&&(I.style.display="none")):(c?c&&(U==="overlay"||U==="push")&&!$?(K.style.removeProperty("display"),K.style.display="flex",K.classList.remove("persona-pointer-events-none","persona-opacity-0"),j.classList.remove("persona-scale-100","persona-opacity-100","persona-scale-95","persona-opacity-0")):(K.style.setProperty("display","none","important"),K.classList.remove("persona-pointer-events-none","persona-opacity-0"),j.classList.remove("persona-scale-100","persona-opacity-100","persona-scale-95","persona-opacity-0")):(K.style.display="",K.classList.add("persona-pointer-events-none","persona-opacity-0"),j.classList.remove("persona-scale-100","persona-opacity-100"),j.classList.add("persona-scale-95","persona-opacity-0")),_?_.element.style.display=c?"none":"":I&&(I.style.display=c?"none":""))},qt=(c,g="user")=>{var $,U;if(!B()||R===c)return;let x=R;R=c,yo();let A=(()=>{var Ve,ct,tt,gt,ht,Fe,Be,Je,D,Ie;let X=(ct=(Ve=n.launcher)==null?void 0:Ve.sidebarMode)!=null?ct:!1,N=(tt=e.ownerDocument.defaultView)!=null?tt:window,ke=(ht=(gt=n.launcher)==null?void 0:gt.mobileFullscreen)!=null?ht:!0,fe=(Be=(Fe=n.launcher)==null?void 0:Fe.mobileBreakpoint)!=null?Be:640,re=N.innerWidth<=fe,we=hr(n)&&ke&&re,Le=H()&&((Ie=(D=(Je=n.launcher)==null?void 0:Je.composerBar)==null?void 0:D.expandedSize)!=null?Ie:"fullscreen")==="fullscreen";return X||ke&&re&&T||we||Le})();if(R&&A){if(!ir){let X=e.getRootNode(),N=X instanceof ShadowRoot?X.host:e.closest(".persona-host");N&&(ir=ip(N,(U=($=n.launcher)==null?void 0:$.zIndex)!=null?U:Dr))}lr||(lr=lp(e.ownerDocument))}else R||(ir==null||ir(),ir=null,lr==null||lr(),lr=null);R&&(Q(),mo(!0));let O={open:R,source:g,timestamp:Date.now()};R&&!x?a.emit("widget:opened",O):!R&&x&&a.emit("widget:closed",O),a.emit("widget:state",{open:R,launcherEnabled:T,voiceActive:wt.active,streaming:z.isStreaming()})},ca=c=>{Nt(c?"stop":"send"),F&&(F.disabled=c),Ln.buttons.forEach(g=>{g.disabled=c}),qe.dataset.personaComposerStreaming=c?"true":"false",qe.querySelectorAll("[data-persona-composer-disable-when-streaming]").forEach(g=>{(g instanceof HTMLButtonElement||g instanceof HTMLInputElement||g instanceof HTMLTextAreaElement||g instanceof HTMLSelectElement)&&(g.disabled=c)})},pa=()=>{wt.active||Me&&Me.focus()};a.on("widget:opened",()=>{n.autoFocusInput&&setTimeout(()=>pa(),200)});let ja=()=>{var x,A,O,$,U,X,N,ke,fe,re,we;Or.textContent=(A=(x=n.copy)==null?void 0:x.welcomeTitle)!=null?A:"Hello \u{1F44B}",vr.textContent=($=(O=n.copy)==null?void 0:O.welcomeSubtitle)!=null?$:"Ask anything about your account or products.",Me.placeholder=(X=(U=n.copy)==null?void 0:U.inputPlaceholder)!=null?X:"How can I help...";let c=Se.querySelector("[data-persona-intro-card]");if(c){let Le=((N=n.copy)==null?void 0:N.showWelcomeCard)!==!1;c.style.display=Le?"":"none",Le?(Se.classList.remove("persona-gap-3"),Se.classList.add("persona-gap-6")):(Se.classList.remove("persona-gap-6"),Se.classList.add("persona-gap-3"))}!((fe=(ke=n.sendButton)==null?void 0:ke.useIcon)!=null&&fe)&&!(z!=null&&z.isStreaming())&&(ae.textContent=(we=(re=n.copy)==null?void 0:re.sendButtonLabel)!=null?we:"Send"),Me.style.fontFamily='var(--persona-input-font-family, var(--persona-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif))',Me.style.fontWeight="var(--persona-input-font-weight, var(--persona-font-weight, 400))"};n.clientToken&&(n={...n,getStoredSessionId:()=>{let c=d.sessionId;return typeof c=="string"?c:null},setStoredSessionId:c=>{m(g=>({...g,sessionId:c}))}});let _n=null,Ys=()=>{_n==null&&(_n=setInterval(()=>{let c=ge.querySelectorAll("[data-tool-elapsed]");if(c.length===0){clearInterval(_n),_n=null;return}let g=Date.now();c.forEach(x=>{let A=Number(x.getAttribute("data-tool-elapsed"));A&&(x.textContent=yi(g-A))})},100))};if(z=new va(n,{onMessagesChanged(c){Ho(ge,c,ue),Ys(),z&&(c.some(O=>O.role==="user")?Ln.render([],z,Me,c):Ln.render(n.suggestionChips,z,Me,c,n.suggestionChipsConfig)),mo(!he),js(c);let g=[...c].reverse().find(A=>A.role==="user"),x=wt.lastUserMessageId;g&&g.id!==x&&(wt.lastUserMessageId=g.id,a.emit("user:message",g)),wt.lastUserMessageWasVoice=!!(g!=null&&g.viaVoice),da(c),Kn()},onStatusChanged(c){var A;let g=(A=n.statusIndicator)!=null?A:{};Ue(Qt,(O=>{var $,U,X,N;return O==="idle"?($=g.idleText)!=null?$:Wr.idle:O==="connecting"?(U=g.connectingText)!=null?U:Wr.connecting:O==="connected"?(X=g.connectedText)!=null?X:Wr.connected:O==="error"?(N=g.errorText)!=null?N:Wr.error:Wr[O]})(c),g,c)},onStreamingChanged(c){he=c,ca(c),z&&Ho(ge,z.getMessages(),ue),c||mo(!0),Kn()},onVoiceStatusChanged(c){var g,x;if(((x=(g=n.voiceRecognition)==null?void 0:g.provider)==null?void 0:x.type)==="runtype")switch(c){case"listening":break;case"processing":Wn(),Zs();break;case"speaking":Wn(),ei();break;default:c==="idle"&&z.isBargeInActive()?(Wn(),bo(),F==null||F.setAttribute("aria-label","End voice session")):(wt.active=!1,Wn(),bn("system"),Yr());break}},onArtifactsState(c){P=c,on(),da()}}),se.current=z,((Ou=(Du=n.voiceRecognition)==null?void 0:Du.provider)==null?void 0:Ou.type)==="runtype")try{z.setupVoice()}catch(c){typeof console!="undefined"&&console.warn("[AgentWidget] Runtype voice setup failed:",c)}n.clientToken&&z.initClientSession().catch(c=>{n.debug&&console.warn("[AgentWidget] Pre-init client session failed:",c)}),(G||n.onSSEEvent)&&z.setSSEEventCallback((c,g)=>{var x;(x=n.onSSEEvent)==null||x.call(n,c,g),G==null||G.push({id:`evt-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,type:c,timestamp:Date.now(),payload:JSON.stringify(g)})}),l&&l.then(c=>{var g,x,A;c&&(c.metadata&&(d=Ip(c.metadata),k.syncFromMetadata()),(g=c.messages)!=null&&g.length&&z.hydrateMessages(c.messages),(x=c.artifacts)!=null&&x.length&&z.hydrateArtifacts(c.artifacts,(A=c.selectedArtifactId)!=null?A:null))}).catch(c=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to hydrate stored state:",c)});let Ga=()=>{var g,x,A;!H()||R||!((A=(x=(g=n.launcher)==null?void 0:g.composerBar)==null?void 0:x.expandOnSubmit)==null||A)||qt(!0,"auto")},Xa=c=>{var O;if(c.preventDefault(),z.isStreaming()){z.cancel();return}let g=Me.value.trim(),x=(O=Et==null?void 0:Et.hasAttachments())!=null?O:!1;if(!g&&!x)return;Ga();let A;x&&(A=[],A.push(...Et.getContentParts()),g&&A.push(hs(g))),Me.value="",Me.style.height="auto",z.sendMessage(g,{contentParts:A}),x&&Et.clearAttachments()},Ja=c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),ae.click())},Ka=async c=>{var x;if(((x=n.attachments)==null?void 0:x.enabled)!==!0||!Et)return;let g=G0(c.clipboardData);g.length!==0&&(c.preventDefault(),await Et.handleFiles(g))},_r=null,dn=!1,Yn=null,ut=null,Ya=()=>typeof window=="undefined"?null:window.webkitSpeechRecognition||window.SpeechRecognition||null,Bo=(c="user")=>{var $,U,X,N,ke,fe,re;if(dn||z.isStreaming())return;let g=Ya();if(!g)return;_r=new g;let A=(U=(($=n.voiceRecognition)!=null?$:{}).pauseDuration)!=null?U:2e3;_r.continuous=!0,_r.interimResults=!0,_r.lang="en-US";let O=Me.value;_r.onresult=we=>{let Le="",Ve="";for(let tt=0;tt<we.results.length;tt++){let gt=we.results[tt],ht=gt[0].transcript;gt.isFinal?Le+=ht+" ":Ve=ht}let ct=O+Le+Ve;Me.value=ct,Yn&&clearTimeout(Yn),(Le||Ve)&&(Yn=window.setTimeout(()=>{let tt=Me.value.trim();tt&&_r&&dn&&(Bn(),Me.value="",Me.style.height="auto",z.sendMessage(tt,{viaVoice:!0}))},A))},_r.onerror=we=>{we.error!=="no-speech"&&Bn()},_r.onend=()=>{if(dn){let we=Me.value.trim();we&&we!==O.trim()&&(Me.value="",Me.style.height="auto",z.sendMessage(we,{viaVoice:!0})),Bn()}};try{if(_r.start(),dn=!0,wt.active=!0,c!=="system"&&(wt.manuallyDeactivated=!1),bn(c),Yr(),F){let we=(X=n.voiceRecognition)!=null?X:{};ut={backgroundColor:F.style.backgroundColor,color:F.style.color,borderColor:F.style.borderColor,iconName:(N=we.iconName)!=null?N:"mic",iconSize:parseFloat((re=(fe=we.iconSize)!=null?fe:(ke=n.sendButton)==null?void 0:ke.size)!=null?re:"40")||24};let Le=we.recordingBackgroundColor,Ve=we.recordingIconColor,ct=we.recordingBorderColor;if(F.classList.add("persona-voice-recording"),F.style.backgroundColor=Le!=null?Le:"var(--persona-voice-recording-bg, #ef4444)",F.style.color=Ve!=null?Ve:"var(--persona-voice-recording-indicator, #ffffff)",Ve){let tt=F.querySelector("svg");tt&&tt.setAttribute("stroke",Ve)}ct&&(F.style.borderColor=ct),F.setAttribute("aria-label","Stop voice recognition")}}catch{Bn("system")}},Bn=(c="user")=>{if(dn){if(dn=!1,Yn&&(clearTimeout(Yn),Yn=null),_r){try{_r.stop()}catch{}_r=null}if(wt.active=!1,bn(c),Yr(),F){if(F.classList.remove("persona-voice-recording"),ut){F.style.backgroundColor=ut.backgroundColor,F.style.color=ut.color,F.style.borderColor=ut.borderColor;let g=F.querySelector("svg");g&&g.setAttribute("stroke",ut.color||"currentColor"),ut=null}F.setAttribute("aria-label","Start voice recognition")}}},Qs=(c,g)=>{var gt,ht,Fe,Be,Je,D,Ie,$e;let x=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),A=((gt=c==null?void 0:c.provider)==null?void 0:gt.type)==="runtype";if(!(x||A))return null;let $=h("div","persona-send-button-wrapper"),U=h("button","persona-rounded-button persona-flex persona-items-center persona-justify-center disabled:persona-opacity-50 persona-cursor-pointer");U.type="button",U.setAttribute("aria-label","Start voice recognition");let X=(ht=c==null?void 0:c.iconName)!=null?ht:"mic",N=(Fe=g==null?void 0:g.size)!=null?Fe:"40px",ke=(Be=c==null?void 0:c.iconSize)!=null?Be:N,fe=parseFloat(ke)||24,re=(Je=c==null?void 0:c.backgroundColor)!=null?Je:g==null?void 0:g.backgroundColor,we=(D=c==null?void 0:c.iconColor)!=null?D:g==null?void 0:g.textColor;U.style.width=ke,U.style.height=ke,U.style.minWidth=ke,U.style.minHeight=ke,U.style.fontSize="18px",U.style.lineHeight="1",we?U.style.color=we:U.style.color="var(--persona-text, #111827)";let Ve=ve(X,fe,we||"currentColor",1.5);Ve?U.appendChild(Ve):U.textContent="\u{1F3A4}",re?U.style.backgroundColor=re:U.style.backgroundColor="",c!=null&&c.borderWidth&&(U.style.borderWidth=c.borderWidth,U.style.borderStyle="solid"),c!=null&&c.borderColor&&(U.style.borderColor=c.borderColor),c!=null&&c.paddingX&&(U.style.paddingLeft=c.paddingX,U.style.paddingRight=c.paddingX),c!=null&&c.paddingY&&(U.style.paddingTop=c.paddingY,U.style.paddingBottom=c.paddingY),$.appendChild(U);let ct=(Ie=c==null?void 0:c.tooltipText)!=null?Ie:"Start voice recognition";if((($e=c==null?void 0:c.showTooltip)!=null?$e:!1)&&ct){let Qe=h("div","persona-send-button-tooltip");Qe.textContent=ct,$.appendChild(Qe)}return{micButton:U,micButtonWrapper:$}},ua=()=>{var g,x,A,O,$;if(!F||ut)return;let c=(g=n.voiceRecognition)!=null?g:{};ut={backgroundColor:F.style.backgroundColor,color:F.style.color,borderColor:F.style.borderColor,iconName:(x=c.iconName)!=null?x:"mic",iconSize:parseFloat(($=(O=c.iconSize)!=null?O:(A=n.sendButton)==null?void 0:A.size)!=null?$:"40")||24}},fa=(c,g)=>{var $,U,X,N,ke;if(!F)return;let x=F.querySelector("svg");x&&x.remove();let A=(ke=ut==null?void 0:ut.iconSize)!=null?ke:parseFloat((N=(X=($=n.voiceRecognition)==null?void 0:$.iconSize)!=null?X:(U=n.sendButton)==null?void 0:U.size)!=null?N:"40")||24,O=ve(c,A,g,1.5);O&&F.appendChild(O)},Wo=()=>{F&&F.classList.remove("persona-voice-recording","persona-voice-processing","persona-voice-speaking")},bo=()=>{var O;if(!F)return;ua();let c=(O=n.voiceRecognition)!=null?O:{},g=c.recordingBackgroundColor,x=c.recordingIconColor,A=c.recordingBorderColor;if(Wo(),F.classList.add("persona-voice-recording"),F.style.backgroundColor=g!=null?g:"var(--persona-voice-recording-bg, #ef4444)",F.style.color=x!=null?x:"var(--persona-voice-recording-indicator, #ffffff)",x){let $=F.querySelector("svg");$&&$.setAttribute("stroke",x)}A&&(F.style.borderColor=A),F.setAttribute("aria-label","Stop voice recognition")},Zs=()=>{var X,N,ke,fe,re,we,Le,Ve;if(!F)return;ua();let c=(X=n.voiceRecognition)!=null?X:{},g=z.getVoiceInterruptionMode(),x=(N=c.processingIconName)!=null?N:"loader",A=(fe=(ke=c.processingIconColor)!=null?ke:ut==null?void 0:ut.color)!=null?fe:"",O=(we=(re=c.processingBackgroundColor)!=null?re:ut==null?void 0:ut.backgroundColor)!=null?we:"",$=(Ve=(Le=c.processingBorderColor)!=null?Le:ut==null?void 0:ut.borderColor)!=null?Ve:"";Wo(),F.classList.add("persona-voice-processing"),F.style.backgroundColor=O,F.style.borderColor=$;let U=A||"currentColor";F.style.color=U,fa(x,U),F.setAttribute("aria-label","Processing voice input"),g==="none"&&(F.style.cursor="default")},ei=()=>{var ke,fe,re,we,Le,Ve,ct,tt,gt,ht,Fe,Be;if(!F)return;ua();let c=(ke=n.voiceRecognition)!=null?ke:{},g=z.getVoiceInterruptionMode(),x=g==="cancel"?"square":g==="barge-in"?"mic":"volume-2",A=(fe=c.speakingIconName)!=null?fe:x,O=(Ve=c.speakingIconColor)!=null?Ve:g==="barge-in"?(we=(re=c.recordingIconColor)!=null?re:ut==null?void 0:ut.color)!=null?we:"":(Le=ut==null?void 0:ut.color)!=null?Le:"",$=(gt=c.speakingBackgroundColor)!=null?gt:g==="barge-in"?(ct=c.recordingBackgroundColor)!=null?ct:"var(--persona-voice-recording-bg, #ef4444)":(tt=ut==null?void 0:ut.backgroundColor)!=null?tt:"",U=(Be=c.speakingBorderColor)!=null?Be:g==="barge-in"?(ht=c.recordingBorderColor)!=null?ht:"":(Fe=ut==null?void 0:ut.borderColor)!=null?Fe:"";Wo(),F.classList.add("persona-voice-speaking"),F.style.backgroundColor=$,F.style.borderColor=U;let X=O||"currentColor";F.style.color=X,fa(A,X);let N=g==="cancel"?"Stop playback and re-record":g==="barge-in"?"Speak to interrupt":"Agent is speaking";F.setAttribute("aria-label",N),g==="none"&&(F.style.cursor="default"),g==="barge-in"&&F.classList.add("persona-voice-recording")},Wn=()=>{var c,g,x;F&&(Wo(),ut&&(F.style.backgroundColor=(c=ut.backgroundColor)!=null?c:"",F.style.color=(g=ut.color)!=null?g:"",F.style.borderColor=(x=ut.borderColor)!=null?x:"",fa(ut.iconName,ut.color||"currentColor"),ut=null),F.style.cursor="",F.setAttribute("aria-label","Start voice recognition"))},Do=()=>{var c,g;if(((g=(c=n.voiceRecognition)==null?void 0:c.provider)==null?void 0:g.type)==="runtype"){let x=z.getVoiceStatus(),A=z.getVoiceInterruptionMode();if(A==="none"&&(x==="processing"||x==="speaking"))return;if(A==="cancel"&&(x==="processing"||x==="speaking")){z.stopVoicePlayback();return}if(z.isBargeInActive()){z.stopVoicePlayback(),z.deactivateBargeIn().then(()=>{wt.active=!1,wt.manuallyDeactivated=!0,Yr(),bn("user"),Wn()});return}z.toggleVoice().then(()=>{wt.active=z.isVoiceActive(),wt.manuallyDeactivated=!z.isVoiceActive(),Yr(),bn("user"),z.isVoiceActive()?bo():Wn()});return}if(dn){let x=Me.value.trim();wt.manuallyDeactivated=!0,Yr(),Bn("user"),x&&(Me.value="",Me.style.height="auto",z.sendMessage(x))}else wt.manuallyDeactivated=!1,Yr(),Bo("user")};hn=Do,F&&(F.addEventListener("click",Do),At.push(()=>{var c,g;((g=(c=n.voiceRecognition)==null?void 0:c.provider)==null?void 0:g.type)==="runtype"?(z.isVoiceActive()&&z.toggleVoice(),Wn()):Bn("system"),F&&F.removeEventListener("click",Do)}));let ma=a.on("assistant:complete",()=>{_a&&(wt.active||wt.manuallyDeactivated||_a==="assistant"&&!wt.lastUserMessageWasVoice||setTimeout(()=>{var c,g;!wt.active&&!wt.manuallyDeactivated&&(((g=(c=n.voiceRecognition)==null?void 0:c.provider)==null?void 0:g.type)==="runtype"?z.toggleVoice().then(()=>{wt.active=z.isVoiceActive(),bn("auto"),z.isVoiceActive()&&bo()}):Bo("auto"))},600))});At.push(ma);let Ze=a.on("action:resubmit",()=>{setTimeout(()=>{z&&!z.isStreaming()&&z.continueConversation()},100)});At.push(Ze);let L=()=>{qt(!R,"user")},_=null,I=null;if(T&&!H()){let c=o.find(g=>g.renderLauncher);if(c!=null&&c.renderLauncher){let g=c.renderLauncher({config:n,defaultRenderer:()=>Ls(n,L).element,onToggle:L});g&&(I=g)}I||(_=Ls(n,L))}_?e.appendChild(_.element):I&&e.appendChild(I),yo(),Ln.render(n.suggestionChips,z,Me,void 0,n.suggestionChipsConfig),ja(),ca(z.isStreaming()),mo(!0),Us(),E&&(!T||H()?setTimeout(()=>pa(),0):R&&setTimeout(()=>pa(),200));let Q=()=>{var N,ke,fe,re,we,Le,Ve,ct,tt,gt,ht,Fe,Be,Je,D,Ie,$e,Qe,Ae,Ft,mt,dr;if(H()){Ir(),yo();return}let c=hr(n),g=(ke=(N=n.launcher)==null?void 0:N.sidebarMode)!=null?ke:!1,x=c||g||((re=(fe=n.launcher)==null?void 0:fe.fullHeight)!=null?re:!1),A=(we=e.ownerDocument.defaultView)!=null?we:window,O=(Ve=(Le=n.launcher)==null?void 0:Le.mobileFullscreen)!=null?Ve:!0,$=(tt=(ct=n.launcher)==null?void 0:ct.mobileBreakpoint)!=null?tt:640,U=A.innerWidth<=$,X=O&&U&&T;try{if(X){Mn(),wo(e,n);return}if(M&&(M=!1,Mn(),wo(e,n)),!T&&!c){j.style.height="",j.style.width="";return}if(!g&&!c){let Mr=(ht=(gt=n==null?void 0:n.launcher)==null?void 0:gt.width)!=null?ht:n==null?void 0:n.launcherWidth,$t=Mr!=null?Mr:mn;j.style.width=$t,j.style.maxWidth=$t}if(Fn(),!x){let Mr=A.innerHeight,$t=64,$r=(Be=(Fe=n.launcher)==null?void 0:Fe.heightOffset)!=null?Be:0,Lr=Math.max(200,Mr-$t),at=Math.min(640,Lr),xt=Math.max(200,at-$r);j.style.height=`${xt}px`}}finally{if(Ir(),yo(),R&&T){let $t=((Je=e.ownerDocument.defaultView)!=null?Je:window).innerWidth<=((Ie=(D=n.launcher)==null?void 0:D.mobileBreakpoint)!=null?Ie:640),$r=(Qe=($e=n.launcher)==null?void 0:$e.sidebarMode)!=null?Qe:!1,Lr=(Ft=(Ae=n.launcher)==null?void 0:Ae.mobileFullscreen)!=null?Ft:!0,at=hr(n)&&Lr&&$t,xt=$r||Lr&&$t&&T||at;if(xt&&!lr){let Ur=e.getRootNode(),Hr=Ur instanceof ShadowRoot?Ur.host:e.closest(".persona-host");Hr&&!ir&&(ir=ip(Hr,(dr=(mt=n.launcher)==null?void 0:mt.zIndex)!=null?dr:Dr)),lr=lp(e.ownerDocument)}else xt||(ir==null||ir(),ir=null,lr==null||lr(),lr=null)}}};Q();let le=(Fu=e.ownerDocument.defaultView)!=null?Fu:window;if(le.addEventListener("resize",Q),At.push(()=>le.removeEventListener("resize",Q)),typeof ResizeObserver!="undefined"){let c=new ResizeObserver(()=>{Ir()});c.observe(qe),At.push(()=>c.disconnect())}Rn=Se.scrollTop;let ee=Se.scrollHeight,et=()=>{let c=Se.scrollTop,g=Se.scrollHeight,x=g<ee;ee=g;let{action:A,nextLastScrollTop:O}=Ki({following:In.isFollowing(),currentScrollTop:c,lastScrollTop:Rn,nearBottom:vs(Se,Na),userScrollThreshold:_s,isAutoScrolling:Gn||Io||x,pauseOnUpwardScroll:!0,pauseWhenAwayFromBottom:!1,resumeRequiresDownwardScroll:!0});if(Rn=O,A==="resume"){fo();return}A==="pause"&&Ua()};Se.addEventListener("scroll",et,{passive:!0}),At.push(()=>Se.removeEventListener("scroll",et));let ze=c=>{let g=Yi({following:In.isFollowing(),deltaY:c.deltaY,nearBottom:vs(Se,Na),resumeWhenNearBottom:!0});g==="pause"?Ua():g==="resume"&&fo()};Se.addEventListener("wheel",ze,{passive:!0}),At.push(()=>Se.removeEventListener("wheel",ze)),lt.addEventListener("click",()=>{Se.scrollTop=Se.scrollHeight,Rn=Se.scrollTop,fo(),mo(!0)}),At.push(()=>lt.remove()),At.push(()=>{$a()});let ft=()=>{Oe&&(sn&&(Oe.removeEventListener("click",sn),sn=null),B()?(Oe.style.display="",sn=()=>{qt(!1,"user")},Oe.addEventListener("click",sn)):Oe.style.display="none")};ft(),(()=>{let{clearChatButton:c}=De;c&&c.addEventListener("click",()=>{z.clearMessages(),ln.clear(),fo(),Mo(De.composerOverlay);try{localStorage.removeItem(Da),n.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${Da}`)}catch(x){console.error("[AgentWidget] Failed to clear default localStorage:",x)}if(n.clearChatHistoryStorageKey&&n.clearChatHistoryStorageKey!==Da)try{localStorage.removeItem(n.clearChatHistoryStorageKey),n.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${n.clearChatHistoryStorageKey}`)}catch(x){console.error("[AgentWidget] Failed to clear custom localStorage:",x)}let g=new CustomEvent("persona:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(g),i!=null&&i.clear)try{let x=i.clear();x instanceof Promise&&x.catch(A=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",A)})}catch(x){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",x)}d={},k.syncFromMetadata(),G==null||G.clear(),ce==null||ce.update()})})(),Ut&&Ut.addEventListener("submit",Xa),Me==null||Me.addEventListener("keydown",Ja),Me==null||Me.addEventListener("paste",Ka);let Dt="persona-attachment-drop-active",_t=0,fr=()=>{_t=0,oe.classList.remove(Dt)},St=()=>{var c;return((c=n.attachments)==null?void 0:c.enabled)===!0&&Et!==null},Ot=c=>{!Sl(c.dataTransfer)||!St()||(_t++,_t===1&&oe.classList.add(Dt))},yr=c=>{!Sl(c.dataTransfer)||!St()||(_t--,_t<=0&&fr())},Rr=c=>{!Sl(c.dataTransfer)||!St()||(c.preventDefault(),c.dataTransfer.dropEffect="copy")},Er=c=>{var x;if(!Sl(c.dataTransfer)||!St())return;c.preventDefault(),c.stopPropagation(),fr();let g=Array.from((x=c.dataTransfer.files)!=null?x:[]);g.length!==0&&Et.handleFiles(g)},Xt=!0;oe.addEventListener("dragenter",Ot,Xt),oe.addEventListener("dragleave",yr,Xt),e.addEventListener("dragover",Rr,Xt),e.addEventListener("drop",Er,Xt);let Qr=e.ownerDocument,Kp=c=>{St()&&c.preventDefault()},Yp=c=>{St()&&c.preventDefault()};Qr.addEventListener("dragover",Kp),Qr.addEventListener("drop",Yp),At.push(()=>{Ut&&Ut.removeEventListener("submit",Xa),Me==null||Me.removeEventListener("keydown",Ja),Me==null||Me.removeEventListener("paste",Ka)}),At.push(()=>{oe.removeEventListener("dragenter",Ot,Xt),oe.removeEventListener("dragleave",yr,Xt),e.removeEventListener("dragover",Rr,Xt),e.removeEventListener("drop",Er,Xt),Qr.removeEventListener("dragover",Kp),Qr.removeEventListener("drop",Yp),fr()}),At.push(()=>{z.cancel()}),_?At.push(()=>{_==null||_.destroy()}):I&&At.push(()=>{I==null||I.remove()});let mr={update(c){var gr,$n,Zn,ti,ri,ni,$o,oi,Qa,Vu,ju,Gu,Xu,Ju,Ku,Yu,Qu,Zu,ef,tf,rf,nf,of,af,sf,lf,df,cf,pf,uf,ff,mf,gf,hf,xf,yf,bf,Cf,wf,vf,Af,Sf,Tf,kf,Ef,Mf,Lf,Pf,If,Rf,Hf,Bf,Wf,Df,Of,Ff,Nf,_f,$f,Uf,qf,zf,Vf,jf,Gf,Xf,Jf,Kf,Yf,Qf,Zf,em,tm,rm,nm,om,am,sm,im,lm,dm,cm,pm,um,fm,mm,gm,hm,xm,ym,bm,Cm,wm,vm,Am,Sm,Tm,km,Em,Mm,Lm,Pm,Im,Rm,Hm,Bm,Wm,Dm,Om,Fm,Nm,_m,$m;let g=n.toolCall,x=n.messageActions,A=(gr=n.layout)==null?void 0:gr.messages,O=n.colorScheme,$=n.loadingIndicator,U=n.iterationDisplay,X=($n=n.features)==null?void 0:$n.showReasoning,N=(Zn=n.features)==null?void 0:Zn.showToolCalls,ke=(ti=n.features)==null?void 0:ti.toolCallDisplay,fe=(ri=n.features)==null?void 0:ri.reasoningDisplay;n={...n,...c},Mn(),wo(e,n),gl(e,n),hl(e,n),on(),n.colorScheme!==O&&uo();let re=Ws.getForInstance(n.plugins);o.length=0,o.push(...re),T=($o=(ni=n.launcher)==null?void 0:ni.enabled)!=null?$o:!0,S=(Qa=(oi=n.launcher)==null?void 0:oi.autoExpand)!=null?Qa:!1,We=(ju=(Vu=n.features)==null?void 0:Vu.showReasoning)!=null?ju:!0,Ke=(Xu=(Gu=n.features)==null?void 0:Gu.showToolCalls)!=null?Xu:!0,me=(Ku=(Ju=n.features)==null?void 0:Ju.scrollToBottom)!=null?Ku:{},Tn(),Jn();let we=xe;if(xe=(Qu=(Yu=n.features)==null?void 0:Yu.showEventStreamToggle)!=null?Qu:!1,xe&&!we){if(G||(Y=new Bs(Ge),G=new Hs(Ee,Y),Y.open().then(()=>G==null?void 0:G.restore()).catch(()=>{}),z.setSSEEventCallback((te,It)=>{var Jt;(Jt=n.onSSEEvent)==null||Jt.call(n,te,It),G.push({id:`evt-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,type:te,timestamp:Date.now(),payload:JSON.stringify(It)})})),!bt&&Ne){let te=(ef=(Zu=n.features)==null?void 0:Zu.eventStream)==null?void 0:ef.classNames,It="persona-inline-flex persona-items-center persona-justify-center persona-rounded-full hover:persona-opacity-80 persona-cursor-pointer persona-border-none persona-bg-transparent persona-p-1"+(te!=null&&te.toggleButton?" "+te.toggleButton:"");bt=h("button",It),bt.style.width="28px",bt.style.height="28px",bt.style.color=Jr.actionIconColor,bt.type="button",bt.setAttribute("aria-label","Event Stream"),bt.title="Event Stream";let Jt=ve("activity","18px","currentColor",1.5);Jt&&bt.appendChild(Jt);let yt=De.clearChatButtonWrapper,Bt=De.closeButtonWrapper,br=yt||Bt;br&&br.parentNode===Ne?Ne.insertBefore(bt,br):Ne.appendChild(bt),bt.addEventListener("click",()=>{de?Kr():Ar()})}}else!xe&&we&&(Kr(),bt&&(bt.remove(),bt=null),G==null||G.clear(),Y==null||Y.destroy(),G=null,Y=null);if(((tf=n.launcher)==null?void 0:tf.enabled)===!1&&_&&(_.destroy(),_=null),((rf=n.launcher)==null?void 0:rf.enabled)===!1&&I&&(I.remove(),I=null),((nf=n.launcher)==null?void 0:nf.enabled)!==!1&&!_&&!I){let te=o.find(It=>It.renderLauncher);if(te!=null&&te.renderLauncher){let It=te.renderLauncher({config:n,defaultRenderer:()=>Ls(n,L).element,onToggle:L});It&&(I=It,e.appendChild(I))}I||(_=Ls(n,L),e.appendChild(_.element))}_&&_.update(n),Te&&((of=n.launcher)==null?void 0:of.title)!==void 0&&(Te.textContent=n.launcher.title),_e&&((af=n.launcher)==null?void 0:af.subtitle)!==void 0&&(_e.textContent=n.launcher.subtitle);let Le=(sf=n.layout)==null?void 0:sf.header;if((Le==null?void 0:Le.layout)!==y&&Ne){let te=Le?ka(n,Le,{showClose:B(),onClose:()=>qt(!1,"user")}):oo({config:n,showClose:B(),onClose:()=>qt(!1,"user")});Ne.replaceWith(te.header),Ne=te.header,q=te.iconHolder,Te=te.headerTitle,_e=te.headerSubtitle,Oe=te.closeButton,y=Le==null?void 0:Le.layout}else if(Le&&(q&&(q.style.display=Le.showIcon===!1?"none":""),Te&&(Te.style.display=Le.showTitle===!1?"none":""),_e&&(_e.style.display=Le.showSubtitle===!1?"none":""),Oe&&(Oe.style.display=Le.showCloseButton===!1?"none":""),De.clearChatButtonWrapper)){let te=Le.showClearChat;if(te!==void 0){De.clearChatButtonWrapper.style.display=te?"":"none";let{closeButtonWrapper:It}=De;It&&!It.classList.contains("persona-absolute")&&(te?It.classList.remove("persona-ml-auto"):It.classList.add("persona-ml-auto"))}}let ct=((lf=n.layout)==null?void 0:lf.showHeader)!==!1;Ne&&(Ne.style.display=ct?"":"none");let tt=((df=n.layout)==null?void 0:df.showFooter)!==!1;qe&&(qe.style.display=tt?"":"none"),Ir(),Jn(),T!==b?T?qt(S,"auto"):(R=!0,yo()):S!==v&&qt(S,"auto"),v=S,b=T,Q(),ft();let Fe=JSON.stringify(c.toolCall)!==JSON.stringify(g),Be=JSON.stringify(n.messageActions)!==JSON.stringify(x),Je=JSON.stringify((cf=n.layout)==null?void 0:cf.messages)!==JSON.stringify(A),D=((pf=n.loadingIndicator)==null?void 0:pf.render)!==($==null?void 0:$.render)||((uf=n.loadingIndicator)==null?void 0:uf.renderIdle)!==($==null?void 0:$.renderIdle)||((ff=n.loadingIndicator)==null?void 0:ff.showBubble)!==($==null?void 0:$.showBubble),Ie=n.iterationDisplay!==U,$e=((gf=(mf=n.features)==null?void 0:mf.showReasoning)!=null?gf:!0)!==(X!=null?X:!0)||((xf=(hf=n.features)==null?void 0:hf.showToolCalls)!=null?xf:!0)!==(N!=null?N:!0)||JSON.stringify((yf=n.features)==null?void 0:yf.toolCallDisplay)!==JSON.stringify(ke)||JSON.stringify((bf=n.features)==null?void 0:bf.reasoningDisplay)!==JSON.stringify(fe);(Fe||Be||Je||D||Ie||$e)&&z&&(Fa++,Ho(ge,z.getMessages(),ue));let Ae=(Cf=n.launcher)!=null?Cf:{},Ft=(wf=Ae.headerIconHidden)!=null?wf:!1,mt=(Af=(vf=n.layout)==null?void 0:vf.header)==null?void 0:Af.showIcon,dr=Ft||mt===!1,Mr=Ae.headerIconName,$t=(Sf=Ae.headerIconSize)!=null?Sf:"48px";if(q){let te=oe.querySelector(".persona-border-b-persona-divider"),It=te==null?void 0:te.querySelector(".persona-flex-col");if(dr)q.style.display="none",te&&It&&!te.contains(It)&&te.insertBefore(It,te.firstChild);else{if(q.style.display="",q.style.height=$t,q.style.width=$t,te&&It&&(te.contains(q)?q.nextSibling!==It&&(q.remove(),te.insertBefore(q,It)):te.insertBefore(q,It)),Mr){let yt=parseFloat($t)||24,Bt=ve(Mr,yt*.6,"#ffffff",2);Bt?q.replaceChildren(Bt):q.textContent=(Tf=Ae.agentIconText)!=null?Tf:"\u{1F4AC}"}else if(Ae.iconUrl){let yt=q.querySelector("img");if(yt)yt.src=Ae.iconUrl,yt.style.height=$t,yt.style.width=$t;else{let Bt=document.createElement("img");Bt.src=Ae.iconUrl,Bt.alt="",Bt.className="persona-rounded-xl persona-object-cover",Bt.style.height=$t,Bt.style.width=$t,q.replaceChildren(Bt)}}else{let yt=q.querySelector("svg"),Bt=q.querySelector("img");(yt||Bt)&&q.replaceChildren(),q.textContent=(kf=Ae.agentIconText)!=null?kf:"\u{1F4AC}"}let Jt=q.querySelector("img");Jt&&(Jt.style.height=$t,Jt.style.width=$t)}}let $r=(Mf=(Ef=n.layout)==null?void 0:Ef.header)==null?void 0:Mf.showTitle,Lr=(Pf=(Lf=n.layout)==null?void 0:Lf.header)==null?void 0:Pf.showSubtitle;if(Te&&(Te.style.display=$r===!1?"none":""),_e&&(_e.style.display=Lr===!1?"none":""),Oe){((Rf=(If=n.layout)==null?void 0:If.header)==null?void 0:Rf.showCloseButton)===!1?Oe.style.display="none":Oe.style.display="";let It=(Hf=Ae.closeButtonSize)!=null?Hf:"32px",Jt=(Bf=Ae.closeButtonPlacement)!=null?Bf:"inline";Oe.style.height=It,Oe.style.width=It;let{closeButtonWrapper:yt}=De,Bt=Jt==="top-right",br=yt==null?void 0:yt.classList.contains("persona-absolute");if(yt&&Bt!==br)if(yt.remove(),Bt)yt.className="persona-absolute persona-top-4 persona-right-4 persona-z-50",oe.style.position="relative",oe.appendChild(yt);else{let Ct=(Df=(Wf=Ae.clearChat)==null?void 0:Wf.placement)!=null?Df:"inline",Cr=(Ff=(Of=Ae.clearChat)==null?void 0:Of.enabled)!=null?Ff:!0;yt.className=Cr&&Ct==="inline"?"":"persona-ml-auto";let rn=oe.querySelector(".persona-border-b-persona-divider");rn&&rn.appendChild(yt)}if(Oe.style.color=Ae.closeButtonColor||Jr.actionIconColor,Ae.closeButtonBackgroundColor?(Oe.style.backgroundColor=Ae.closeButtonBackgroundColor,Oe.classList.remove("hover:persona-bg-gray-100")):(Oe.style.backgroundColor="",Oe.classList.add("hover:persona-bg-gray-100")),Ae.closeButtonBorderWidth||Ae.closeButtonBorderColor){let Ct=Ae.closeButtonBorderWidth||"0px",Cr=Ae.closeButtonBorderColor||"transparent";Oe.style.border=`${Ct} solid ${Cr}`,Oe.classList.remove("persona-border-none")}else Oe.style.border="",Oe.classList.add("persona-border-none");Ae.closeButtonBorderRadius?(Oe.style.borderRadius=Ae.closeButtonBorderRadius,Oe.classList.remove("persona-rounded-full")):(Oe.style.borderRadius="",Oe.classList.add("persona-rounded-full")),Ae.closeButtonPaddingX?(Oe.style.paddingLeft=Ae.closeButtonPaddingX,Oe.style.paddingRight=Ae.closeButtonPaddingX):(Oe.style.paddingLeft="",Oe.style.paddingRight=""),Ae.closeButtonPaddingY?(Oe.style.paddingTop=Ae.closeButtonPaddingY,Oe.style.paddingBottom=Ae.closeButtonPaddingY):(Oe.style.paddingTop="",Oe.style.paddingBottom="");let Br=(Nf=Ae.closeButtonIconName)!=null?Nf:"x",Dn=(_f=Ae.closeButtonIconText)!=null?_f:"\xD7";Oe.innerHTML="";let zr=ve(Br,"28px","currentColor",1);zr?Oe.appendChild(zr):Oe.textContent=Dn;let cr=($f=Ae.closeButtonTooltipText)!=null?$f:"Close chat",pn=(Uf=Ae.closeButtonShowTooltip)!=null?Uf:!0;if(Oe.setAttribute("aria-label",cr),yt&&(yt._cleanupTooltip&&(yt._cleanupTooltip(),delete yt._cleanupTooltip),pn&&cr)){let Ct=null,Cr=()=>{if(Ct||!Oe)return;let Uo=Oe.ownerDocument,Za=Uo.body;if(!Za)return;Ct=qn(Uo,"div","persona-clear-chat-tooltip"),Ct.textContent=cr;let es=qn(Uo,"div");es.className="persona-clear-chat-tooltip-arrow",Ct.appendChild(es);let qo=Oe.getBoundingClientRect();Ct.style.position="fixed",Ct.style.zIndex=String(vo),Ct.style.left=`${qo.left+qo.width/2}px`,Ct.style.top=`${qo.top-8}px`,Ct.style.transform="translate(-50%, -100%)",Za.appendChild(Ct)},rn=()=>{Ct&&Ct.parentNode&&(Ct.parentNode.removeChild(Ct),Ct=null)};yt.addEventListener("mouseenter",Cr),yt.addEventListener("mouseleave",rn),Oe.addEventListener("focus",Cr),Oe.addEventListener("blur",rn),yt._cleanupTooltip=()=>{rn(),yt&&(yt.removeEventListener("mouseenter",Cr),yt.removeEventListener("mouseleave",rn)),Oe&&(Oe.removeEventListener("focus",Cr),Oe.removeEventListener("blur",rn))}}}let{clearChatButton:at,clearChatButtonWrapper:xt}=De;if(at){let te=(qf=Ae.clearChat)!=null?qf:{},It=(zf=te.enabled)!=null?zf:!0,Jt=(jf=(Vf=n.layout)==null?void 0:Vf.header)==null?void 0:jf.showClearChat,yt=Jt!==void 0?Jt:It,Bt=(Gf=te.placement)!=null?Gf:"inline";if(xt){xt.style.display=yt?"":"none";let{closeButtonWrapper:br}=De;!H()&&br&&!br.classList.contains("persona-absolute")&&(yt?br.classList.remove("persona-ml-auto"):br.classList.add("persona-ml-auto"));let Br=Bt==="top-right",Dn=xt.classList.contains("persona-absolute");if(!H()&&Br!==Dn&&yt){if(xt.remove(),Br)xt.className="persona-absolute persona-top-4 persona-z-50",xt.style.right="48px",oe.style.position="relative",oe.appendChild(xt);else{xt.className="persona-relative persona-ml-auto persona-clear-chat-button-wrapper",xt.style.right="";let cr=oe.querySelector(".persona-border-b-persona-divider"),pn=De.closeButtonWrapper;cr&&pn&&pn.parentElement===cr?cr.insertBefore(xt,pn):cr&&cr.appendChild(xt)}let zr=De.closeButtonWrapper;zr&&!zr.classList.contains("persona-absolute")&&(Br?zr.classList.add("persona-ml-auto"):zr.classList.remove("persona-ml-auto"))}}if(yt){if(!H()){let Ct=(Xf=te.size)!=null?Xf:"32px";at.style.height=Ct,at.style.width=Ct}let br=(Jf=te.iconName)!=null?Jf:"refresh-cw",Br=(Kf=te.iconColor)!=null?Kf:"";at.style.color=Br||Jr.actionIconColor,at.innerHTML="";let Dn=H()?"14px":"20px",zr=ve(br,Dn,"currentColor",2);if(zr&&at.appendChild(zr),te.backgroundColor?(at.style.backgroundColor=te.backgroundColor,at.classList.remove("hover:persona-bg-gray-100")):(at.style.backgroundColor="",at.classList.add("hover:persona-bg-gray-100")),te.borderWidth||te.borderColor){let Ct=te.borderWidth||"0px",Cr=te.borderColor||"transparent";at.style.border=`${Ct} solid ${Cr}`,at.classList.remove("persona-border-none")}else at.style.border="",at.classList.add("persona-border-none");te.borderRadius?(at.style.borderRadius=te.borderRadius,at.classList.remove("persona-rounded-full")):(at.style.borderRadius="",at.classList.add("persona-rounded-full")),te.paddingX?(at.style.paddingLeft=te.paddingX,at.style.paddingRight=te.paddingX):(at.style.paddingLeft="",at.style.paddingRight=""),te.paddingY?(at.style.paddingTop=te.paddingY,at.style.paddingBottom=te.paddingY):(at.style.paddingTop="",at.style.paddingBottom="");let cr=(Yf=te.tooltipText)!=null?Yf:"Clear chat",pn=(Qf=te.showTooltip)!=null?Qf:!0;if(at.setAttribute("aria-label",cr),xt&&(xt._cleanupTooltip&&(xt._cleanupTooltip(),delete xt._cleanupTooltip),pn&&cr)){let Ct=null,Cr=()=>{if(Ct||!at)return;let Uo=at.ownerDocument,Za=Uo.body;if(!Za)return;Ct=qn(Uo,"div","persona-clear-chat-tooltip"),Ct.textContent=cr;let es=qn(Uo,"div");es.className="persona-clear-chat-tooltip-arrow",Ct.appendChild(es);let qo=at.getBoundingClientRect();Ct.style.position="fixed",Ct.style.zIndex=String(vo),Ct.style.left=`${qo.left+qo.width/2}px`,Ct.style.top=`${qo.top-8}px`,Ct.style.transform="translate(-50%, -100%)",Za.appendChild(Ct)},rn=()=>{Ct&&Ct.parentNode&&(Ct.parentNode.removeChild(Ct),Ct=null)};xt.addEventListener("mouseenter",Cr),xt.addEventListener("mouseleave",rn),at.addEventListener("focus",Cr),at.addEventListener("blur",rn),xt._cleanupTooltip=()=>{rn(),xt&&(xt.removeEventListener("mouseenter",Cr),xt.removeEventListener("mouseleave",rn)),at&&(at.removeEventListener("focus",Cr),at.removeEventListener("blur",rn))}}}}let Ur=n.actionParsers&&n.actionParsers.length?n.actionParsers:[Ds],Hr=n.actionHandlers&&n.actionHandlers.length?n.actionHandlers:[sa.message,sa.messageAndClick];k=Os({parsers:Ur,handlers:Hr,getSessionMetadata:f,updateSessionMetadata:m,emit:a.emit,documentRef:typeof document!="undefined"?document:null}),ue=Uh(n,k,ne),z.updateConfig(n),Ho(ge,z.getMessages(),ue),Ln.render(n.suggestionChips,z,Me,void 0,n.suggestionChipsConfig),ja(),ca(z.isStreaming());let Oo=((Zf=n.voiceRecognition)==null?void 0:Zf.enabled)===!0,Fo=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),No=((tm=(em=n.voiceRecognition)==null?void 0:em.provider)==null?void 0:tm.type)==="runtype";if(Oo&&(Fo||No))if(!F||!ye){let te=Qs(n.voiceRecognition,n.sendButton);te&&(F=te.micButton,ye=te.micButtonWrapper,pt.insertBefore(ye,ur),F.addEventListener("click",Do),F.disabled=z.isStreaming())}else{let te=(rm=n.voiceRecognition)!=null?rm:{},It=(nm=n.sendButton)!=null?nm:{},Jt=(om=te.iconName)!=null?om:"mic",yt=(am=It.size)!=null?am:"40px",Bt=(sm=te.iconSize)!=null?sm:yt,br=parseFloat(Bt)||24;F.style.width=Bt,F.style.height=Bt,F.style.minWidth=Bt,F.style.minHeight=Bt;let Br=(lm=(im=te.iconColor)!=null?im:It.textColor)!=null?lm:"currentColor";F.innerHTML="";let Dn=ve(Jt,br,Br,2);Dn?F.appendChild(Dn):F.textContent="\u{1F3A4}";let zr=(dm=te.backgroundColor)!=null?dm:It.backgroundColor;zr?F.style.backgroundColor=zr:F.style.backgroundColor="",Br?F.style.color=Br:F.style.color="var(--persona-text, #111827)",te.borderWidth?(F.style.borderWidth=te.borderWidth,F.style.borderStyle="solid"):(F.style.borderWidth="",F.style.borderStyle=""),te.borderColor?F.style.borderColor=te.borderColor:F.style.borderColor="",te.paddingX?(F.style.paddingLeft=te.paddingX,F.style.paddingRight=te.paddingX):(F.style.paddingLeft="",F.style.paddingRight=""),te.paddingY?(F.style.paddingTop=te.paddingY,F.style.paddingBottom=te.paddingY):(F.style.paddingTop="",F.style.paddingBottom="");let cr=ye==null?void 0:ye.querySelector(".persona-send-button-tooltip"),pn=(cm=te.tooltipText)!=null?cm:"Start voice recognition";if(((pm=te.showTooltip)!=null?pm:!1)&&pn)if(cr)cr.textContent=pn,cr.style.display="";else{let Cr=document.createElement("div");Cr.className="persona-send-button-tooltip",Cr.textContent=pn,ye==null||ye.insertBefore(Cr,F)}else cr&&(cr.style.display="none");ye.style.display="",F.disabled=z.isStreaming()}else F&&ye&&(ye.style.display="none",((fm=(um=n.voiceRecognition)==null?void 0:um.provider)==null?void 0:fm.type)==="runtype"?z.isVoiceActive()&&z.toggleVoice():dn&&Bn());if(((mm=n.attachments)==null?void 0:mm.enabled)===!0)if(!it||!be){let te=(gm=n.attachments)!=null?gm:{},Jt=(xm=((hm=n.sendButton)!=null?hm:{}).size)!=null?xm:"40px";Wt||(Wt=h("div","persona-attachment-previews persona-flex persona-flex-wrap persona-gap-2 persona-mb-2"),Wt.style.display="none",Ut.insertBefore(Wt,Me)),Xe||(Xe=document.createElement("input"),Xe.type="file",Xe.accept=((ym=te.allowedTypes)!=null?ym:no).join(","),Xe.multiple=((bm=te.maxFiles)!=null?bm:4)>1,Xe.style.display="none",Xe.setAttribute("aria-label","Attach files"),Ut.insertBefore(Xe,Me)),it=h("div","persona-send-button-wrapper"),be=h("button","persona-rounded-button persona-flex persona-items-center persona-justify-center disabled:persona-opacity-50 persona-cursor-pointer persona-attachment-button"),be.type="button",be.setAttribute("aria-label",(Cm=te.buttonTooltipText)!=null?Cm:"Attach file");let yt=(wm=te.buttonIconName)!=null?wm:"paperclip",Bt=Jt,br=parseFloat(Bt)||40,Br=Math.round(br*.6);be.style.width=Bt,be.style.height=Bt,be.style.minWidth=Bt,be.style.minHeight=Bt,be.style.fontSize="18px",be.style.lineHeight="1",be.style.backgroundColor="transparent",be.style.color="var(--persona-primary, #111827)",be.style.border="none",be.style.borderRadius="6px",be.style.transition="background-color 0.15s ease",be.addEventListener("mouseenter",()=>{be.style.backgroundColor="var(--persona-palette-colors-black-alpha-50, rgba(0, 0, 0, 0.05))"}),be.addEventListener("mouseleave",()=>{be.style.backgroundColor="transparent"});let Dn=ve(yt,Br,"currentColor",1.5);Dn?be.appendChild(Dn):be.textContent="\u{1F4CE}",be.addEventListener("click",pn=>{pn.preventDefault(),Xe==null||Xe.click()}),it.appendChild(be);let zr=(vm=te.buttonTooltipText)!=null?vm:"Attach file",cr=h("div","persona-send-button-tooltip");cr.textContent=zr,it.appendChild(cr),nt.append(it),!Et&&Xe&&Wt&&(Et=ta.fromConfig(te),Et.setPreviewsContainer(Wt),Xe.addEventListener("change",async()=>{Et&&(Xe!=null&&Xe.files)&&(await Et.handleFileSelect(Xe.files),Xe.value="")})),oe.querySelector(".persona-attachment-drop-overlay")||oe.appendChild(qh(te.dropOverlay))}else{it.style.display="";let te=(Am=n.attachments)!=null?Am:{};Xe&&(Xe.accept=((Sm=te.allowedTypes)!=null?Sm:no).join(","),Xe.multiple=((Tm=te.maxFiles)!=null?Tm:4)>1),Et&&Et.updateConfig({allowedTypes:te.allowedTypes,maxFileSize:te.maxFileSize,maxFiles:te.maxFiles})}else it&&(it.style.display="none"),Et&&Et.clearAttachments(),(km=oe.querySelector(".persona-attachment-drop-overlay"))==null||km.remove();let nr=(Em=n.sendButton)!=null?Em:{},_o=(Mm=nr.useIcon)!=null?Mm:!1,Co=(Lm=nr.iconText)!=null?Lm:"\u2191",Lt=nr.iconName,Zr=(Pm=nr.tooltipText)!=null?Pm:"Send message",Qn=(Im=nr.showTooltip)!=null?Im:!1,qr=(Rm=nr.size)!=null?Rm:"40px",en=nr.backgroundColor,Vt=nr.textColor;if(_o){if(ae.style.width=qr,ae.style.height=qr,ae.style.minWidth=qr,ae.style.minHeight=qr,ae.style.fontSize="18px",ae.style.lineHeight="1",ae.innerHTML="",Vt?ae.style.color=Vt:ae.style.color="var(--persona-button-primary-fg, #ffffff)",Lt){let te=parseFloat(qr)||24,It=(Vt==null?void 0:Vt.trim())||"currentColor",Jt=ve(Lt,te,It,2);Jt?ae.appendChild(Jt):ae.textContent=Co}else ae.textContent=Co;ae.className="persona-rounded-button persona-flex persona-items-center persona-justify-center disabled:persona-opacity-50 persona-cursor-pointer",en?(ae.style.backgroundColor=en,ae.classList.remove("persona-bg-persona-primary")):(ae.style.backgroundColor="",ae.classList.add("persona-bg-persona-primary"))}else ae.textContent=(Bm=(Hm=n.copy)==null?void 0:Hm.sendButtonLabel)!=null?Bm:"Send",ae.style.width="",ae.style.height="",ae.style.minWidth="",ae.style.minHeight="",ae.style.fontSize="",ae.style.lineHeight="",ae.className="persona-rounded-button persona-bg-persona-accent persona-px-4 persona-py-2 persona-text-sm persona-font-semibold persona-text-white disabled:persona-opacity-50 persona-cursor-pointer",en?(ae.style.backgroundColor=en,ae.classList.remove("persona-bg-persona-accent")):ae.classList.add("persona-bg-persona-accent"),Vt?ae.style.color=Vt:ae.classList.add("persona-text-white");nr.borderWidth?(ae.style.borderWidth=nr.borderWidth,ae.style.borderStyle="solid"):(ae.style.borderWidth="",ae.style.borderStyle=""),nr.borderColor?ae.style.borderColor=nr.borderColor:ae.style.borderColor="",nr.paddingX?(ae.style.paddingLeft=nr.paddingX,ae.style.paddingRight=nr.paddingX):(ae.style.paddingLeft="",ae.style.paddingRight=""),nr.paddingY?(ae.style.paddingTop=nr.paddingY,ae.style.paddingBottom=nr.paddingY):(ae.style.paddingTop="",ae.style.paddingBottom="");let er=ur==null?void 0:ur.querySelector(".persona-send-button-tooltip");if(Qn&&Zr)if(er)er.textContent=Zr,er.style.display="";else{let te=document.createElement("div");te.className="persona-send-button-tooltip",te.textContent=Zr,ur==null||ur.insertBefore(te,ae)}else er&&(er.style.display="none");let jt=(Nm=(Wm=n.layout)==null?void 0:Wm.contentMaxWidth)!=null?Nm:H()?(Fm=(Om=(Dm=n.launcher)==null?void 0:Dm.composerBar)==null?void 0:Om.contentMaxWidth)!=null?Fm:"720px":void 0;jt?(ge.style.maxWidth=jt,ge.style.marginLeft="auto",ge.style.marginRight="auto",ge.style.width="100%",Ut&&(Ut.style.maxWidth=jt,Ut.style.marginLeft="auto",Ut.style.marginRight="auto"),Rt&&(Rt.style.maxWidth=jt,Rt.style.marginLeft="auto",Rt.style.marginRight="auto")):(ge.style.maxWidth="",ge.style.marginLeft="",ge.style.marginRight="",ge.style.width="",Ut&&(Ut.style.maxWidth="",Ut.style.marginLeft="",Ut.style.marginRight=""),Rt&&(Rt.style.maxWidth="",Rt.style.marginLeft="",Rt.style.marginRight=""));let or=(_m=n.statusIndicator)!=null?_m:{},tn=($m=or.visible)!=null?$m:!0;if(Qt.style.display=tn?"":"none",z){let te=z.getStatus();Ue(Qt,(Jt=>{var yt,Bt,br,Br;return Jt==="idle"?(yt=or.idleText)!=null?yt:Wr.idle:Jt==="connecting"?(Bt=or.connectingText)!=null?Bt:Wr.connecting:Jt==="connected"?(br=or.connectedText)!=null?br:Wr.connected:Jt==="error"?(Br=or.errorText)!=null?Br:Wr.error:Wr[Jt]})(te),or,te)}Qt.classList.remove("persona-text-left","persona-text-center","persona-text-right");let cn=or.align==="left"?"persona-text-left":or.align==="center"?"persona-text-center":"persona-text-right";Qt.classList.add(cn)},open(){B()&&qt(!0,"api")},close(){B()&&qt(!1,"api")},toggle(){B()&&qt(!R,"api")},clearChat(){Z=!1,z.clearMessages(),ln.clear(),fo();try{localStorage.removeItem(Da),n.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${Da}`)}catch(g){console.error("[AgentWidget] Failed to clear default localStorage:",g)}if(n.clearChatHistoryStorageKey&&n.clearChatHistoryStorageKey!==Da)try{localStorage.removeItem(n.clearChatHistoryStorageKey),n.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${n.clearChatHistoryStorageKey}`)}catch(g){console.error("[AgentWidget] Failed to clear custom localStorage:",g)}let c=new CustomEvent("persona:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(c),i!=null&&i.clear)try{let g=i.clear();g instanceof Promise&&g.catch(x=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",x)})}catch(g){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",g)}d={},k.syncFromMetadata(),G==null||G.clear(),ce==null||ce.update()},setMessage(c){return!Me||z.isStreaming()?!1:(!R&&B()&&qt(!0,"system"),Me.value=c,Me.dispatchEvent(new Event("input",{bubbles:!0})),!0)},submitMessage(c){if(z.isStreaming())return!1;let g=(c==null?void 0:c.trim())||Me.value.trim();return g?(!R&&B()&&qt(!0,"system"),Me.value="",Me.style.height="auto",z.sendMessage(g),!0):!1},startVoiceRecognition(){var g,x;return z.isStreaming()?!1:((x=(g=n.voiceRecognition)==null?void 0:g.provider)==null?void 0:x.type)==="runtype"?(z.isVoiceActive()||(!R&&B()&&qt(!0,"system"),wt.manuallyDeactivated=!1,Yr(),z.toggleVoice().then(()=>{wt.active=z.isVoiceActive(),bn("user"),z.isVoiceActive()&&bo()})),!0):dn?!0:Ya()?(!R&&B()&&qt(!0,"system"),wt.manuallyDeactivated=!1,Yr(),Bo("user"),!0):!1},stopVoiceRecognition(){var c,g;return((g=(c=n.voiceRecognition)==null?void 0:c.provider)==null?void 0:g.type)==="runtype"?z.isVoiceActive()?(z.toggleVoice().then(()=>{wt.active=!1,wt.manuallyDeactivated=!0,Yr(),bn("user"),Wn()}),!0):!1:dn?(wt.manuallyDeactivated=!0,Yr(),Bn("user"),!0):!1},injectMessage(c){return!R&&B()&&qt(!0,"system"),z.injectMessage(c)},injectAssistantMessage(c){!R&&B()&&qt(!0,"system");let g=z.injectAssistantMessage(c);return W&&(W=!1,V&&(clearTimeout(V),V=null),setTimeout(()=>{z&&!z.isStreaming()&&z.continueConversation()},100)),g},injectUserMessage(c){return!R&&B()&&qt(!0,"system"),z.injectUserMessage(c)},injectSystemMessage(c){return!R&&B()&&qt(!0,"system"),z.injectSystemMessage(c)},injectMessageBatch(c){return!R&&B()&&qt(!0,"system"),z.injectMessageBatch(c)},injectComponentDirective(c){return!R&&B()&&qt(!0,"system"),z.injectComponentDirective(c)},injectTestMessage(c){!R&&B()&&qt(!0,"system"),z.injectTestEvent(c)},async connectStream(c,g){return z.connectStream(c,g)},__pushEventStreamEvent(c){G&&G.push({id:`evt-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,type:c.type,timestamp:Date.now(),payload:JSON.stringify(c.payload)})},showEventStream(){!xe||!G||Ar()},hideEventStream(){de&&Kr()},isEventStreamVisible(){return de},showArtifacts(){Sn(n)&&(Z=!1,on(),vt==null||vt.setMobileOpen(!0))},hideArtifacts(){Sn(n)&&(Z=!0,on())},upsertArtifact(c){return Sn(n)?(Z=!1,z.upsertArtifact(c)):null},selectArtifact(c){Sn(n)&&z.selectArtifact(c)},clearArtifacts(){Sn(n)&&z.clearArtifacts()},getArtifacts(){var c;return(c=z==null?void 0:z.getArtifacts())!=null?c:[]},getSelectedArtifactId(){var c;return(c=z==null?void 0:z.getSelectedArtifactId())!=null?c:null},focusInput(){return T&&!R&&!H()||!Me?!1:(Me.focus(),!0)},async resolveApproval(c,g){let A=z.getMessages().find(O=>{var $;return O.variant==="approval"&&(($=O.approval)==null?void 0:$.id)===c});if(!(A!=null&&A.approval))throw new Error(`Approval not found: ${c}`);return z.resolveApproval(A.approval,g)},getMessages(){return z.getMessages()},getStatus(){return z.getStatus()},getPersistentMetadata(){return{...d}},updatePersistentMetadata(c){m(c)},on(c,g){return a.on(c,g)},off(c,g){a.off(c,g)},isOpen(){return B()&&R},isVoiceActive(){return wt.active},getState(){return{open:B()&&R,launcherEnabled:T,voiceActive:wt.active,streaming:z.isStreaming()}},showCSATFeedback(c){!R&&B()&&qt(!0,"system");let g=ge.querySelector(".persona-feedback-container");g&&g.remove();let x=vl({onSubmit:async(A,O)=>{var $;z.isClientTokenMode()&&await z.submitCSATFeedback(A,O),($=c==null?void 0:c.onSubmit)==null||$.call(c,A,O)},onDismiss:c==null?void 0:c.onDismiss,...c});ge.appendChild(x),x.scrollIntoView({behavior:"smooth",block:"end"})},showNPSFeedback(c){!R&&B()&&qt(!0,"system");let g=ge.querySelector(".persona-feedback-container");g&&g.remove();let x=Al({onSubmit:async(A,O)=>{var $;z.isClientTokenMode()&&await z.submitNPSFeedback(A,O),($=c==null?void 0:c.onSubmit)==null||$.call(c,A,O)},onDismiss:c==null?void 0:c.onDismiss,...c});ge.appendChild(x),x.scrollIntoView({behavior:"smooth",block:"end"})},async submitCSATFeedback(c,g){return z.submitCSATFeedback(c,g)},async submitNPSFeedback(c,g){return z.submitNPSFeedback(c,g)},destroy(){_n!=null&&(clearInterval(_n),_n=null),At.forEach(c=>c()),K.remove(),Ce==null||Ce.remove(),_==null||_.destroy(),I==null||I.remove(),sn&&Oe.removeEventListener("click",sn)}};if((((Nu=t==null?void 0:t.debugTools)!=null?Nu:!1)||!!n.debug)&&typeof window!="undefined"){let c=window.AgentWidgetBrowser,g={controller:mr,getMessages:mr.getMessages,getStatus:mr.getStatus,getMetadata:mr.getPersistentMetadata,updateMetadata:mr.updatePersistentMetadata,clearHistory:()=>mr.clearChat(),setVoiceActive:x=>x?mr.startVoiceRecognition():mr.stopVoiceRecognition()};window.AgentWidgetBrowser=g,At.push(()=>{window.AgentWidgetBrowser===g&&(window.AgentWidgetBrowser=c)})}if(typeof window!="undefined"){let c=e.getAttribute("data-persona-instance")||e.id||"persona-"+Math.random().toString(36).slice(2,8),g=X=>{let N=X.detail;(!(N!=null&&N.instanceId)||N.instanceId===c)&&mr.focusInput()};if(window.addEventListener("persona:focusInput",g),At.push(()=>{window.removeEventListener("persona:focusInput",g)}),xe){let X=ke=>{let fe=ke.detail;(!(fe!=null&&fe.instanceId)||fe.instanceId===c)&&mr.showEventStream()},N=ke=>{let fe=ke.detail;(!(fe!=null&&fe.instanceId)||fe.instanceId===c)&&mr.hideEventStream()};window.addEventListener("persona:showEventStream",X),window.addEventListener("persona:hideEventStream",N),At.push(()=>{window.removeEventListener("persona:showEventStream",X),window.removeEventListener("persona:hideEventStream",N)})}let x=X=>{let N=X.detail;(!(N!=null&&N.instanceId)||N.instanceId===c)&&mr.showArtifacts()},A=X=>{let N=X.detail;(!(N!=null&&N.instanceId)||N.instanceId===c)&&mr.hideArtifacts()},O=X=>{let N=X.detail;N!=null&&N.instanceId&&N.instanceId!==c||N!=null&&N.artifact&&mr.upsertArtifact(N.artifact)},$=X=>{let N=X.detail;N!=null&&N.instanceId&&N.instanceId!==c||typeof(N==null?void 0:N.id)=="string"&&mr.selectArtifact(N.id)},U=X=>{let N=X.detail;(!(N!=null&&N.instanceId)||N.instanceId===c)&&mr.clearArtifacts()};window.addEventListener("persona:showArtifacts",x),window.addEventListener("persona:hideArtifacts",A),window.addEventListener("persona:upsertArtifact",O),window.addEventListener("persona:selectArtifact",$),window.addEventListener("persona:clearArtifacts",U),At.push(()=>{window.removeEventListener("persona:showArtifacts",x),window.removeEventListener("persona:hideArtifacts",A),window.removeEventListener("persona:upsertArtifact",O),window.removeEventListener("persona:selectArtifact",$),window.removeEventListener("persona:clearArtifacts",U)})}let Cn=X0(n.persistState);if(Cn&&B()){let c=J0(Cn.storage),g=`${Cn.keyPrefix}widget-open`,x=`${Cn.keyPrefix}widget-voice`,A=`${Cn.keyPrefix}widget-voice-mode`;if(c){let O=((_u=Cn.persist)==null?void 0:_u.openState)&&c.getItem(g)==="true",$=(($u=Cn.persist)==null?void 0:$u.voiceState)&&c.getItem(x)==="true",U=((Uu=Cn.persist)==null?void 0:Uu.voiceState)&&c.getItem(A)==="true";if(O&&setTimeout(()=>{mr.open(),setTimeout(()=>{var X;if($||U)mr.startVoiceRecognition();else if((X=Cn.persist)!=null&&X.focusInput){let N=e.querySelector("textarea");N&&N.focus()}},100)},0),(qu=Cn.persist)!=null&&qu.openState&&(a.on("widget:opened",()=>{c.setItem(g,"true")}),a.on("widget:closed",()=>{c.setItem(g,"false")})),(zu=Cn.persist)!=null&&zu.voiceState&&(a.on("voice:state",X=>{c.setItem(x,X.active?"true":"false")}),a.on("user:message",X=>{c.setItem(A,X.viaVoice?"true":"false")})),Cn.clearOnChatClear){let X=()=>{c.removeItem(g),c.removeItem(x),c.removeItem(A)},N=()=>X();window.addEventListener("persona:clear-chat",N),At.push(()=>{window.removeEventListener("persona:clear-chat",N)})}}}return u&&B()&&setTimeout(()=>{mr.open()},0),Kn(),mr};var K0=(e,r)=>{let t=e.trim(),n=/^(\d+(?:\.\d+)?)px$/i.exec(t);if(n)return Math.max(0,parseFloat(n[1]));let o=/^(\d+(?:\.\d+)?)%$/i.exec(t);return o?Math.max(0,r*parseFloat(o[1])/100):420},zh=(e,r)=>{var n,o;let t=(o=(n=r==null?void 0:r.launcher)==null?void 0:n.enabled)!=null?o:!0;e.className="persona-host",e.style.height=t?"":"100%",e.style.display=t?"":"flex",e.style.flexDirection=t?"":"column",e.style.flex=t?"":"1 1 auto",e.style.minHeight=t?"":"0"},Wp=e=>{e.style.position="",e.style.top="",e.style.bottom="",e.style.left="",e.style.right="",e.style.zIndex="",e.style.transform="",e.style.pointerEvents=""},Vh=e=>{e.style.inset="",e.style.width="",e.style.height="",e.style.maxWidth="",e.style.minWidth="",Wp(e)},Rp=e=>{e.style.transition=""},Hp=e=>{e.style.display="",e.style.flexDirection="",e.style.flex="",e.style.minHeight="",e.style.minWidth="",e.style.width="",e.style.height="",e.style.alignItems="",e.style.transition="",e.style.transform=""},Bp=e=>{e.style.width="",e.style.maxWidth="",e.style.minWidth="",e.style.flex="1 1 auto"},kl=(e,r)=>{e.style.width="",e.style.minWidth="",e.style.maxWidth="",e.style.boxSizing="",r.style.alignItems=""},Y0=(e,r,t,n,o)=>{o?t.parentElement!==r&&(e.replaceChildren(),r.replaceChildren(t,n),e.appendChild(r)):t.parentElement===r&&(r.replaceChildren(),e.appendChild(t),e.appendChild(n))},Q0=(e,r,t,n,o,a)=>{let s=a?r:e;o==="left"?s.firstElementChild!==n&&s.replaceChildren(n,t):s.lastElementChild!==n&&s.replaceChildren(t,n)},jh=(e,r,t,n,o,a,s)=>{var C,w,k,T,S,E;let i=vn(a),d=i.reveal==="push";Y0(e,r,t,n,d),Q0(e,r,t,n,i.side,d),e.dataset.personaHostLayout="docked",e.dataset.personaDockSide=i.side,e.dataset.personaDockOpen=s?"true":"false",e.style.width="100%",e.style.maxWidth="100%",e.style.minWidth="0",e.style.height="100%",e.style.minHeight="0",e.style.position="relative",t.style.display="flex",t.style.flexDirection="column",t.style.minHeight="0",t.style.position="relative",o.className="persona-host",o.style.height="100%",o.style.minHeight="0",o.style.display="flex",o.style.flexDirection="column",o.style.flex="1 1 auto";let l=e.ownerDocument.defaultView,u=(w=(C=a==null?void 0:a.launcher)==null?void 0:C.mobileFullscreen)!=null?w:!0,p=(T=(k=a==null?void 0:a.launcher)==null?void 0:k.mobileBreakpoint)!=null?T:640,f=l!=null?l.innerWidth<=p:!1;if(u&&f&&s){e.dataset.personaDockMobileFullscreen="true",e.removeAttribute("data-persona-dock-reveal"),Hp(r),Rp(n),Vh(n),Bp(t),kl(o,n),e.style.display="flex",e.style.flexDirection="column",e.style.alignItems="stretch",e.style.overflow="hidden",t.style.flex="1 1 auto",t.style.width="100%",t.style.minWidth="0",n.style.display="flex",n.style.flexDirection="column",n.style.position="fixed",n.style.inset="0",n.style.width="100%",n.style.height="100%",n.style.maxWidth="100%",n.style.minWidth="0",n.style.minHeight="0",n.style.overflow="hidden",n.style.zIndex=String((E=(S=a==null?void 0:a.launcher)==null?void 0:S.zIndex)!=null?E:Dr),n.style.transform="none",n.style.transition="none",n.style.pointerEvents="auto",n.style.flex="none",d&&(r.style.display="flex",r.style.flexDirection="column",r.style.width="100%",r.style.height="100%",r.style.minHeight="0",r.style.minWidth="0",r.style.flex="1 1 auto",r.style.alignItems="stretch",r.style.transform="none",r.style.transition="none",t.style.flex="1 1 auto",t.style.width="100%",t.style.maxWidth="100%",t.style.minWidth="0");return}if(e.removeAttribute("data-persona-dock-mobile-fullscreen"),Vh(n),i.reveal==="overlay"){e.style.display="flex",e.style.flexDirection="row",e.style.alignItems="stretch",e.style.overflow="hidden",e.dataset.personaDockReveal="overlay",Hp(r),Rp(n),Bp(t),kl(o,n);let v=i.animate?"transform 180ms ease":"none",b=i.side==="right"?"translateX(100%)":"translateX(-100%)",y=s?"translateX(0)":b;n.style.display="flex",n.style.flexDirection="column",n.style.flex="none",n.style.position="absolute",n.style.top="0",n.style.bottom="0",n.style.width=i.width,n.style.maxWidth=i.width,n.style.minWidth=i.width,n.style.minHeight="0",n.style.overflow="hidden",n.style.transition=v,n.style.transform=y,n.style.pointerEvents=s?"auto":"none",n.style.zIndex="2",i.side==="right"?(n.style.right="0",n.style.left=""):(n.style.left="0",n.style.right="")}else if(i.reveal==="push"){e.style.display="flex",e.style.flexDirection="row",e.style.alignItems="stretch",e.style.overflow="hidden",e.dataset.personaDockReveal="push",Rp(n),Wp(n),kl(o,n);let v=K0(i.width,e.clientWidth),b=Math.max(0,e.clientWidth),y=i.animate?"transform 180ms ease":"none",M=i.side==="right"?s?`translateX(-${v}px)`:"translateX(0)":s?"translateX(0)":`translateX(-${v}px)`;r.style.display="flex",r.style.flexDirection="row",r.style.flex="0 0 auto",r.style.minHeight="0",r.style.minWidth="0",r.style.alignItems="stretch",r.style.height="100%",r.style.width=`${b+v}px`,r.style.transition=y,r.style.transform=M,t.style.flex="0 0 auto",t.style.flexGrow="0",t.style.flexShrink="0",t.style.width=`${b}px`,t.style.maxWidth=`${b}px`,t.style.minWidth=`${b}px`,n.style.display="flex",n.style.flexDirection="column",n.style.flex="0 0 auto",n.style.flexShrink="0",n.style.width=i.width,n.style.minWidth=i.width,n.style.maxWidth=i.width,n.style.position="relative",n.style.overflow="hidden",n.style.transition="none",n.style.pointerEvents=s?"auto":"none"}else{e.style.display="flex",e.style.flexDirection="row",e.style.alignItems="stretch",e.style.overflow="",Hp(r),Wp(n),Bp(t),kl(o,n);let v=i.reveal==="emerge";v?e.dataset.personaDockReveal="emerge":e.removeAttribute("data-persona-dock-reveal");let b=s?i.width:"0px",y=i.animate?"width 180ms ease, min-width 180ms ease, max-width 180ms ease, flex-basis 180ms ease":"none",M=!s;n.style.display="flex",n.style.flexDirection="column",n.style.flex=`0 0 ${b}`,n.style.width=b,n.style.maxWidth=b,n.style.minWidth=b,n.style.minHeight="0",n.style.position="relative",n.style.overflow=v||M?"hidden":"visible",n.style.transition=y,v&&(n.style.alignItems=i.side==="right"?"flex-start":"flex-end",o.style.width=i.width,o.style.minWidth=i.width,o.style.maxWidth=i.width,o.style.boxSizing="border-box")}},Z0=(e,r)=>{let t=e.ownerDocument.createElement("div");return zh(t,r),e.appendChild(t),{mode:"direct",host:t,shell:null,syncWidgetState:()=>{},updateConfig(n){zh(t,n)},destroy(){t.remove()}}},eC=(e,r)=>{var S,E,v,b;let{ownerDocument:t}=e,n=e.parentElement;if(!n)throw new Error("Docked widget target must be attached to the DOM");let o=e.tagName.toUpperCase();if(o==="BODY"||o==="HTML")throw new Error('Docked widget target must be a concrete container element, not "body" or "html"');let a=e.nextSibling,s=t.createElement("div"),i=t.createElement("div"),d=t.createElement("div"),l=t.createElement("aside"),u=t.createElement("div"),p=(E=(S=r==null?void 0:r.launcher)==null?void 0:S.enabled)==null||E?(b=(v=r==null?void 0:r.launcher)==null?void 0:v.autoExpand)!=null?b:!1:!0;i.dataset.personaDockRole="push-track",d.dataset.personaDockRole="content",l.dataset.personaDockRole="panel",u.dataset.personaDockRole="host",l.appendChild(u),n.insertBefore(s,e),d.appendChild(e);let f=null,m=()=>{f==null||f.disconnect(),f=null},C=()=>{m(),vn(r).reveal==="push"&&typeof ResizeObserver!="undefined"&&(f=new ResizeObserver(()=>{jh(s,i,d,l,u,r,p)}),f.observe(s))},w=()=>{jh(s,i,d,l,u,r,p),C()},k=s.ownerDocument.defaultView,T=()=>{w()};return k==null||k.addEventListener("resize",T),vn(r).reveal==="push"?(i.appendChild(d),i.appendChild(l),s.appendChild(i)):(s.appendChild(d),s.appendChild(l)),w(),{mode:"docked",host:u,shell:s,syncWidgetState(y){let M=y.launcherEnabled?y.open:!0;p!==M&&(p=M,w())},updateConfig(y){var M,H;r=y,((H=(M=r==null?void 0:r.launcher)==null?void 0:M.enabled)!=null?H:!0)===!1&&(p=!0),w()},destroy(){k==null||k.removeEventListener("resize",T),m(),n.isConnected&&(a&&a.parentNode===n?n.insertBefore(e,a):n.appendChild(e)),s.remove()}}},Fs=(e,r)=>hr(r)?eC(e,r):Z0(e,r);var Dp={},tC=e=>{if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Chat widget can only be mounted in a browser environment");if(typeof e=="string"){let r=document.querySelector(e);if(!r)throw new Error(`Chat widget target "${e}" was not found`);return r}return e},rC=()=>{try{if(typeof Dp!="undefined"&&Dp.url)return new URL("../widget.css",Dp.url).href}catch{}return null},Gh=(e,r)=>{let t=rC(),n=()=>{if(!(e instanceof ShadowRoot)||e.querySelector("link[data-persona]"))return;let o=r.head.querySelector("link[data-persona]");if(!o)return;let a=o.cloneNode(!0);e.insertBefore(a,e.firstChild)};if(e instanceof ShadowRoot)if(t){let o=r.createElement("link");o.rel="stylesheet",o.href=t,o.setAttribute("data-persona","true"),e.insertBefore(o,e.firstChild)}else n();else if(!r.head.querySelector("link[data-persona]")&&t){let a=r.createElement("link");a.rel="stylesheet",a.href=t,a.setAttribute("data-persona","true"),r.head.appendChild(a)}},Xh=e=>{var k;let r=tC(e.target),t=e.useShadowDom===!0,n=r.ownerDocument,o=e.config,a=Fs(r,o),s,i=[],d=(T,S)=>{var y,M;let v=!((M=(y=S==null?void 0:S.launcher)==null?void 0:y.enabled)!=null?M:!0)||hr(S),b=n.createElement("div");if(b.setAttribute("data-persona-root","true"),v&&(b.style.height="100%",b.style.display="flex",b.style.flexDirection="column",b.style.flex="1",b.style.minHeight="0"),t){let H=T.attachShadow({mode:"open"});H.appendChild(b),Gh(H,n)}else T.appendChild(b),Gh(T,n);return r.id&&b.setAttribute("data-persona-instance",r.id),b},l=()=>{a.syncWidgetState(s.getState())},u=()=>{i.forEach(T=>T()),i=[s.on("widget:opened",l),s.on("widget:closed",l)],l()},p=()=>{let T=d(a.host,o);s=Tl(T,o,{debugTools:e.debugTools}),u()},f=()=>{i.forEach(T=>T()),i=[],s.destroy()};p(),(k=e.onReady)==null||k.call(e);let m=T=>{f(),a.destroy(),a=Fs(r,T),o=T,p()},C={update(T){var M,H,B,R,W,V;let S={...o,...T,launcher:{...(M=o==null?void 0:o.launcher)!=null?M:{},...(H=T==null?void 0:T.launcher)!=null?H:{},dock:{...(R=(B=o==null?void 0:o.launcher)==null?void 0:B.dock)!=null?R:{},...(V=(W=T==null?void 0:T.launcher)==null?void 0:W.dock)!=null?V:{}}}},E=hr(o),v=hr(S),b=So(o),y=So(S);if(E!==v||b!==y){m(S);return}o=S,a.updateConfig(o),s.update(T),l()},destroy(){f(),a.destroy(),e.windowKey&&typeof window!="undefined"&&delete window[e.windowKey]}},w=new Proxy(C,{get(T,S,E){if(S==="host")return a.host;if(S in T)return Reflect.get(T,S,E);let v=s[S];return typeof v=="function"?v.bind(s):v}});return e.windowKey&&typeof window!="undefined"&&(window[e.windowKey]=w),w};var Zh=new Set(["script","style","noscript","svg","path","meta","link","br","hr"]),nC=new Set(["button","a","input","select","textarea","details","summary"]),oC=new Set(["button","link","menuitem","tab","option","switch","checkbox","radio","combobox","listbox","slider","spinbutton","textbox"]),Op=/\b(product|card|item|listing|result)\b/i,Np=/\$[\d,]+(?:\.\d{2})?|€[\d,]+(?:\.\d{2})?|£[\d,]+(?:\.\d{2})?|USD\s*[\d,]+(?:\.\d{2})?/i,aC=3e3,sC=100;function ex(e){let r=typeof e.className=="string"?e.className:"";if(Op.test(r)||e.id&&Op.test(e.id))return!0;for(let t=0;t<e.attributes.length;t++){let n=e.attributes[t];if(n.name.startsWith("data-")&&Op.test(n.value))return!0}return!1}function tx(e){var r;return Np.test(((r=e.textContent)!=null?r:"").trim())}function rx(e){var t;let r=e.querySelectorAll("a[href]");for(let n=0;n<r.length;n++){let o=(t=r[n].getAttribute("href"))!=null?t:"";if(o&&o!=="#"&&!o.toLowerCase().startsWith("javascript:"))return!0}return!1}function iC(e){return!!e.querySelector('button, [role="button"], input[type="submit"], input[type="button"]')}function Jh(e){let r=e.match(Np);return r?r[0]:null}function Kh(e){var n,o,a;let r=(n=e.querySelector(".product-title a, h1 a, h2 a, h3 a, h4 a, .title a, a[href]"))!=null?n:e.querySelector("a[href]");if(r&&((o=r.textContent)!=null&&o.trim())){let s=r.getAttribute("href");return{title:r.textContent.trim(),href:s&&s!=="#"?s:null}}let t=e.querySelector("h1, h2, h3, h4, h5, h6");return(a=t==null?void 0:t.textContent)!=null&&a.trim()?{title:t.textContent.trim(),href:null}:{title:"",href:null}}function lC(e){let r=[],t=n=>{let o=n.trim();o&&!r.includes(o)&&r.push(o)};return e.querySelectorAll("button").forEach(n=>{var o;return t((o=n.textContent)!=null?o:"")}),e.querySelectorAll('[role="button"]').forEach(n=>{var o;return t((o=n.textContent)!=null?o:"")}),e.querySelectorAll('input[type="submit"], input[type="button"]').forEach(n=>{var o;t((o=n.value)!=null?o:"")}),r.slice(0,6)}var dC="commerce-card",cC="result-card";function Yh(e){return!ex(e)||!tx(e)||!rx(e)&&!iC(e)?0:5200}function Qh(e){var n;return!ex(e)||tx(e)||!rx(e)||((n=e.textContent)!=null?n:"").trim().length<20||!(!!e.querySelector("h1, h2, h3, h4, h5, h6, .title")||!!e.querySelector(".snippet, .description, p"))?0:2800}var _p=[{id:dC,scoreElement(e){return Yh(e)},shouldSuppressDescendant(e,r,t){if(r===e||!e.contains(r))return!1;if(t.interactivity==="static"){let n=t.text.trim();return!!(n.length===0||Np.test(n)&&n.length<32)}return!0},formatSummary(e,r){var d,l,u;if(Yh(e)===0)return null;let{title:t,href:n}=Kh(e),o=(u=(l=Jh(((d=e.textContent)!=null?d:"").trim()))!=null?l:Jh(r.text))!=null?u:"",a=lC(e);return[n&&t?`[${t}](${n})${o?` \u2014 ${o}`:""}`:t?`${t}${o?` \u2014 ${o}`:""}`:o||r.text.trim().slice(0,120),`selector: ${r.selector}`,a.length?`actions: ${a.join(", ")}`:""].filter(Boolean).join(`
|
|
147
|
+
`}if(!v&&!c){let jt="max-height: -moz-available !important; max-height: stretch !important;",or=g?"":"padding-top: 1.25em !important;",tn=g?"":`z-index: ${(er=(Vt=n.launcher)==null?void 0:Vt.zIndex)!=null?er:Dr} !important;`;K.style.cssText+=jt+or+tn}D()};Mn(),wo(e,n),gl(e,n),hl(e,n);let At=[];At.push(()=>{document.removeEventListener("keydown",Fr)});let ir=null,lr=null;At.push(()=>{ir==null||ir(),ir=null,lr==null||lr(),lr=null}),Pe&&At.push(()=>{Pe==null||Pe.disconnect(),Pe=null}),At.push(()=>{wr==null||wr(),wr=null,jn(),ot&&(ot.remove(),ot=null),vt==null||vt.element.style.removeProperty("width"),vt==null||vt.element.style.removeProperty("maxWidth")}),ye&&At.push(()=>{pe!==null&&(cancelAnimationFrame(pe),pe=null),ce==null||ce.destroy(),ce=null,G==null||G.destroy(),G=null,Y=null});let an=null,uo=()=>{an&&(an(),an=null),n.colorScheme==="auto"&&(an=Gi(()=>{wo(e,n)}))};uo(),At.push(()=>{an&&(an(),an=null)});let yn=(Hu=n.features)==null?void 0:Hu.streamAnimation;if(yn!=null&&yn.type&&yn.type!=="none"){let c=Ts(yn.type,yn.plugins);c&&(sp(c,e),At.push(()=>rh(e)))}let Ln=Th(Rt),sn=null,z,he=!1,ln=Kg(),Pn=new Map,Nn=new Map,Fa=0,In=Ji(),Rn=0,Hn=null,Gn=!1,Io=!1,_s=4,Na=24,$s=80,la=new Map,wt={active:!1,manuallyDeactivated:!1,lastUserMessageWasVoice:!1,lastUserMessageId:null},_a=(Wu=(Bu=n.voiceRecognition)==null?void 0:Bu.autoResume)!=null?Wu:!1,bn=c=>{a.emit("voice:state",{active:wt.active,source:c,timestamp:Date.now()})},Yr=()=>{m(c=>({...c,voiceState:{active:wt.active,timestamp:Date.now(),manuallyDeactivated:wt.manuallyDeactivated}}))},Us=()=>{var v,O;if(((v=n.voiceRecognition)==null?void 0:v.enabled)===!1)return;let c=Ip(d.voiceState),g=!!c.active,x=Number((O=c.timestamp)!=null?O:0);wt.manuallyDeactivated=!!c.manuallyDeactivated,g&&Date.now()-x<V0&&setTimeout(()=>{var $,U;wt.active||(wt.manuallyDeactivated=!1,((U=($=n.voiceRecognition)==null?void 0:$.provider)==null?void 0:U.type)==="runtype"?z.toggleVoice().then(()=>{wt.active=z.isVoiceActive(),bn("restore"),z.isVoiceActive()&&bo()}):Bo("restore"))},1e3)},qs=()=>z?$h(z.getMessages()).filter(c=>!c.__skipPersist):[];function da(c){if(!(i!=null&&i.save))return;let x={messages:c?$h(c):z?qs():[],metadata:d,artifacts:P.artifacts,selectedArtifactId:P.selectedId};try{let v=i.save(x);v instanceof Promise&&v.catch(O=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",O)})}catch(v){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",v)}}let Xn=null,zs=()=>K.querySelector("#persona-scroll-container")||Se,Ro=()=>{Xn!==null&&(cancelAnimationFrame(Xn),Xn=null),Gn=!1},$a=()=>{Hn!==null&&(cancelAnimationFrame(Hn),Hn=null),Io=!1,Ro()},Jn=()=>{if(!rt()||de){lt.parentNode&<.remove(),lt.style.display="none";return}lt.parentNode!==oe&&oe.appendChild(lt),Ir();let c=ws(Se)>0;lt.style.display=In.isFollowing()||!c?"none":""},Ua=()=>{In.pause()&&($a(),Jn())},fo=()=>{In.resume(),Jn()},mo=(c=!1)=>{In.isFollowing()&&(!c&&!he||(Hn!==null&&(cancelAnimationFrame(Hn),Hn=null),Io=!0,Hn=requestAnimationFrame(()=>{Hn=null,Io=!1,In.isFollowing()&&Vs(zs(),c?220:140)})))},Vs=(c,g=500)=>{let x=c.scrollTop,v=ws(c),O=v-x;if(Math.abs(O)<1){Rn=c.scrollTop;return}if(Math.abs(O)>=$s){Ro(),Gn=!0,c.scrollTop=v,Rn=c.scrollTop,Gn=!1;return}Ro();let $=performance.now();Gn=!0;let U=N=>1-Math.pow(1-N,3),X=N=>{if(!In.isFollowing()){Ro();return}let ke=ws(c);ke!==v&&(v=ke,O=v-x);let fe=N-$,re=Math.min(fe/g,1),we=U(re),Le=x+O*we;c.scrollTop=Le,Rn=c.scrollTop,re<1?Xn=requestAnimationFrame(X):(c.scrollTop=v,Rn=c.scrollTop,Xn=null,Gn=!1)};Xn=requestAnimationFrame(X)},js=c=>{let g=new Map;c.forEach(x=>{let v=la.get(x.id);g.set(x.id,{streaming:x.streaming,role:x.role}),!v&&x.role==="assistant"&&a.emit("assistant:message",x),x.role==="assistant"&&(v!=null&&v.streaming)&&x.streaming===!1&&a.emit("assistant:complete",x),x.variant==="approval"&&x.approval&&(v?x.approval.status!=="pending"&&a.emit("approval:resolved",{approval:x.approval,decision:x.approval.status}):a.emit("approval:requested",{approval:x.approval,message:x}))}),la.clear(),g.forEach((x,v)=>{la.set(v,x)})},Ho=(c,g,x)=>{var tt,gt,ht,Fe,He,Je;let v=document.createElement("div"),$=(()=>{var Ie;let D=o.find($e=>$e.renderLoadingIndicator);if(D!=null&&D.renderLoadingIndicator)return D.renderLoadingIndicator;if((Ie=n.loadingIndicator)!=null&&Ie.render)return n.loadingIndicator.render})(),U=(D,Ie)=>Ie==null?!1:typeof Ie=="string"?(D.textContent=Ie,!0):(D.appendChild(Ie),!0),X=new Set,N=new Set,ke=o.some(D=>D.renderAskUserQuestion),fe=[],re=[],we=n.enableComponentStreaming!==!1;if(g.forEach(D=>{var $r,Lr,at,xt,Ur,Hr,Oo,Fo,No,ga,ha,nr,_o,Co;X.add(D.id);let Ie=ke&&ao(D),$e=!Ie&&D.role==="assistant"&&!D.variant&&we&&Cl(D);if(!$e&&Nn.has(D.id)){let Lt=c.querySelector(`#wrapper-${D.id}`);Lt==null||Lt.removeAttribute("data-preserve-runtime"),Nn.delete(D.id)}let Qe=ao(D)?`:${($r=D.agentMetadata)!=null&&$r.askUserQuestionAnswered?"a":"u"}:${(Lr=D.agentMetadata)!=null&&Lr.askUserQuestionAnswers?Object.keys(D.agentMetadata.askUserQuestionAnswers).length:0}`:"",Ae=Jg(D,Fa)+Qe,Ft=Ie||$e?null:Yg(ln,D.id,Ae);if(Ft){v.appendChild(Ft.cloneNode(!0)),ao(D)&&((at=D.toolCall)!=null&&at.id)&&((xt=D.agentMetadata)==null?void 0:xt.awaitingLocalTool)===!0&&!((Ur=D.agentMetadata)!=null&&Ur.askUserQuestionAnswered)&&(N.add(D.toolCall.id),Ha(D,n,De.composerOverlay));return}let mt=null,dr=o.find(Lt=>!!(D.variant==="reasoning"&&Lt.renderReasoning||D.variant==="tool"&&Lt.renderToolCall||D.variant==="approval"&&Lt.renderApproval||!D.variant&&Lt.renderMessage)),Mr=(Hr=n.layout)==null?void 0:Hr.messages;if(ao(D)&&((Oo=D.agentMetadata)==null?void 0:Oo.askUserQuestionAnswered)===!0){Pn.delete(D.id);let Lt=c.querySelector(`#wrapper-${D.id}`);Lt==null||Lt.removeAttribute("data-preserve-runtime");return}if(ao(D)&&((No=(Fo=n.features)==null?void 0:Fo.askUserQuestion)==null?void 0:No.enabled)!==!1){let Lt=o.find(Zr=>typeof Zr.renderAskUserQuestion=="function");if(Lt&&se.current){let Zr=Pn.get(D.id),Qn=Zr!==Ae,qr=null;if(Qn){let{payload:er,complete:jt}=so(D),or=D.id,tn=()=>{var cn;return(cn=se.current)==null?void 0:cn.getMessages().find(gr=>gr.id===or)};qr=Lt.renderAskUserQuestion({message:D,payload:er,complete:jt,resolve:cn=>{var $n;let gr=tn();gr&&(($n=se.current)==null||$n.resolveAskUserQuestion(gr,cn))},dismiss:()=>{var gr,$n,Zn;let cn=tn();(gr=cn==null?void 0:cn.agentMetadata)!=null&&gr.awaitingLocalTool&&(($n=se.current)==null||$n.markAskUserQuestionResolved(cn),(Zn=se.current)==null||Zn.resolveAskUserQuestion(cn,"(dismissed)"))},config:n})}let en=Zr!=null;if(Qn&&qr===null&&!en){((ga=D.agentMetadata)==null?void 0:ga.awaitingLocalTool)===!0&&!((ha=D.agentMetadata)!=null&&ha.askUserQuestionAnswered)&&(N.add(D.toolCall.id),Ha(D,n,De.composerOverlay));return}let Vt=document.createElement("div");Vt.className="persona-flex",Vt.id=`wrapper-${D.id}`,Vt.setAttribute("data-wrapper-id",D.id),Vt.setAttribute("data-ask-plugin-stub","true"),Vt.setAttribute("data-preserve-runtime","true"),v.appendChild(Vt),fe.push({messageId:D.id,fingerprint:Ae,bubble:qr});return}else{((nr=D.agentMetadata)==null?void 0:nr.awaitingLocalTool)===!0&&!((_o=D.agentMetadata)!=null&&_o.askUserQuestionAnswered)&&(N.add(D.toolCall.id),Ha(D,n,De.composerOverlay));return}}else if(dr)if(D.variant==="reasoning"&&D.reasoning&&dr.renderReasoning){if(!Be)return;mt=dr.renderReasoning({message:D,defaultRenderer:()=>hp(D,n),config:n})}else if(D.variant==="tool"&&D.toolCall&&dr.renderToolCall){if(!Ke)return;mt=dr.renderToolCall({message:D,defaultRenderer:()=>xp(D,n),config:n})}else if(D.variant==="approval"&&D.approval&&dr.renderApproval){if(n.approval===!1)return;mt=dr.renderApproval({message:D,defaultRenderer:()=>Tp(D,n),config:n})}else dr.renderMessage&&(mt=dr.renderMessage({message:D,defaultRenderer:()=>{let Lt=Ma(D,x,Mr,n.messageActions,Ye,{loadingIndicatorRenderer:$,widgetConfig:n});return D.role!=="user"&&Mp(Lt,D,n,z),Lt},config:n}));if(!mt&&$e){let Lt=wl(D);if(Lt){let Zr=Nn.get(D.id),Qn=Zr!==Ae,qr=n.wrapComponentDirectiveInBubble!==!1,en=null;if(Qn){let Vt=bl(Lt,{config:n,message:D,transform:x});if(Vt)if(qr){let er=document.createElement("div");if(er.className=["persona-message-bubble","persona-max-w-[85%]","persona-rounded-2xl","persona-bg-persona-surface","persona-border","persona-border-persona-message-border","persona-p-4"].join(" "),er.id=`bubble-${D.id}`,er.setAttribute("data-message-id",D.id),D.content&&D.content.trim()){let jt=document.createElement("div");jt.className="persona-mb-3 persona-text-sm persona-leading-relaxed",jt.innerHTML=x({text:D.content,message:D,streaming:!!D.streaming,raw:D.rawContent}),er.appendChild(jt)}er.appendChild(Vt),en=er}else{let er=document.createElement("div");if(er.className="persona-flex persona-flex-col persona-w-full persona-max-w-full persona-gap-3 persona-items-stretch",er.id=`bubble-${D.id}`,er.setAttribute("data-message-id",D.id),er.setAttribute("data-persona-component-directive","true"),D.content&&D.content.trim()){let jt=document.createElement("div");jt.className="persona-text-sm persona-leading-relaxed persona-text-persona-primary persona-w-full",jt.innerHTML=x({text:D.content,message:D,streaming:!!D.streaming,raw:D.rawContent}),er.appendChild(jt)}er.appendChild(Vt),en=er}}if(en||Zr!=null){let Vt=document.createElement("div");Vt.className="persona-flex",Vt.id=`wrapper-${D.id}`,Vt.setAttribute("data-wrapper-id",D.id),Vt.setAttribute("data-component-directive-stub","true"),Vt.setAttribute("data-preserve-runtime","true"),qr||Vt.classList.add("persona-w-full"),v.appendChild(Vt),re.push({messageId:D.id,fingerprint:Ae,bubble:en});return}}}if(!mt)if(D.variant==="reasoning"&&D.reasoning){if(!Be)return;mt=hp(D,n)}else if(D.variant==="tool"&&D.toolCall){if(!Ke)return;mt=xp(D,n)}else if(D.variant==="approval"&&D.approval){if(n.approval===!1)return;mt=Tp(D,n)}else{let Lt=(Co=n.layout)==null?void 0:Co.messages;Lt!=null&&Lt.renderUserMessage&&D.role==="user"?mt=Lt.renderUserMessage({message:D,config:n,streaming:!!D.streaming}):Lt!=null&&Lt.renderAssistantMessage&&D.role==="assistant"?mt=Lt.renderAssistantMessage({message:D,config:n,streaming:!!D.streaming}):mt=Ma(D,x,Lt,n.messageActions,Ye,{loadingIndicatorRenderer:$,widgetConfig:n}),D.role!=="user"&&mt&&Mp(mt,D,n,z)}let $t=document.createElement("div");$t.className="persona-flex",$t.id=`wrapper-${D.id}`,$t.setAttribute("data-wrapper-id",D.id),D.role==="user"&&$t.classList.add("persona-justify-end"),(mt==null?void 0:mt.getAttribute("data-persona-component-directive"))==="true"&&$t.classList.add("persona-w-full"),$t.appendChild(mt),Qg(ln,D.id,Ae,$t),v.appendChild($t)}),De.composerOverlay&&De.composerOverlay.querySelectorAll("[data-persona-ask-sheet-for]").forEach(Ie=>{let $e=Ie.getAttribute("data-persona-ask-sheet-for");$e&&!N.has($e)&&Mo(De.composerOverlay,$e)}),(gt=(tt=n.features)==null?void 0:tt.toolCallDisplay)!=null&>.grouped){let D=[],Ie=[];g.forEach($e=>{if($e.variant==="tool"&&$e.toolCall&&Ke){Ie.push($e);return}Ie.length>1&&D.push(Ie),Ie=[]}),Ie.length>1&&D.push(Ie),D.forEach(($e,Qe)=>{var Lr,at;let Ae=$e.map(xt=>Array.from(v.children).find(Ur=>Ur instanceof HTMLElement&&Ur.getAttribute("data-wrapper-id")===xt.id)).filter(xt=>!!xt);if(Ae.length<2)return;let Ft=document.createElement("div");Ft.className="persona-flex",Ft.id=`wrapper-tool-group-${Qe}-${$e[0].id}`,Ft.setAttribute("data-wrapper-id",`tool-group-${Qe}-${$e[0].id}`);let mt=document.createElement("div");mt.className="persona-tool-group persona-flex persona-w-full persona-flex-col persona-gap-2",mt.setAttribute("data-persona-tool-group","true");let dr=document.createElement("div");dr.className="persona-tool-group-summary persona-text-xs persona-text-persona-muted";let Mr=`Called ${$e.length} tools`,$t=(at=(Lr=n.toolCall)==null?void 0:Lr.renderGroupedSummary)==null?void 0:at.call(Lr,{messages:$e,toolCalls:$e.map(xt=>xt.toolCall).filter(xt=>!!xt),defaultSummary:Mr,config:n});U(dr,$t)||(dr.textContent=Mr);let $r=document.createElement("div");$r.className="persona-tool-group-stack persona-flex persona-flex-col",mt.append(dr,$r),Ft.appendChild(mt),Ae[0].before(Ft),Ae.forEach((xt,Ur)=>{let Hr=document.createElement("div");Hr.className="persona-tool-group-item persona-relative",Hr.setAttribute("data-persona-tool-group-item","true"),Ur<Ae.length-1&&Hr.setAttribute("data-persona-tool-group-connector","true"),Hr.appendChild(xt),$r.appendChild(Hr)})})}Zg(ln,X);let Le=g.some(D=>D.role==="assistant"&&D.streaming),Ve=g[g.length-1],ct=(Ve==null?void 0:Ve.role)==="assistant"&&!Ve.streaming&&Ve.variant!=="approval";if(he&&g.some(D=>D.role==="user")&&!Le&&!ct){let D={config:n,streaming:!0,location:"standalone",defaultRenderer:oa},Ie=o.find(Qe=>Qe.renderLoadingIndicator),$e=null;if(Ie!=null&&Ie.renderLoadingIndicator&&($e=Ie.renderLoadingIndicator(D)),$e===null&&((ht=n.loadingIndicator)!=null&&ht.render)&&($e=n.loadingIndicator.render(D)),$e===null&&($e=oa()),$e){let Qe=document.createElement("div"),Ae=((Fe=n.loadingIndicator)==null?void 0:Fe.showBubble)!==!1;Qe.className=Ae?["persona-max-w-[85%]","persona-rounded-2xl","persona-text-sm","persona-leading-relaxed","persona-shadow-sm","persona-bg-persona-surface","persona-border","persona-text-persona-primary","persona-px-5","persona-py-3"].join(" "):["persona-max-w-[85%]","persona-text-sm","persona-leading-relaxed","persona-text-persona-primary"].join(" "),Qe.setAttribute("data-typing-indicator","true"),Qe.style.borderColor="var(--persona-message-assistant-border, var(--persona-border, #e5e7eb))",Qe.appendChild($e);let Ft=document.createElement("div");Ft.className="persona-flex",Ft.id="wrapper-typing-indicator",Ft.setAttribute("data-wrapper-id","typing-indicator"),Ft.appendChild(Qe),v.appendChild(Ft)}}if(!he&&g.length>0){let D=g[g.length-1],Ie={config:n,lastMessage:D,messageCount:g.length},$e=o.find(Ae=>Ae.renderIdleIndicator),Qe=null;if($e!=null&&$e.renderIdleIndicator&&(Qe=$e.renderIdleIndicator(Ie)),Qe===null&&((He=n.loadingIndicator)!=null&&He.renderIdle)&&(Qe=n.loadingIndicator.renderIdle(Ie)),Qe){let Ae=document.createElement("div"),Ft=((Je=n.loadingIndicator)==null?void 0:Je.showBubble)!==!1;Ae.className=Ft?["persona-max-w-[85%]","persona-rounded-2xl","persona-text-sm","persona-leading-relaxed","persona-shadow-sm","persona-bg-persona-surface","persona-border","persona-border-persona-message-border","persona-text-persona-primary","persona-px-5","persona-py-3"].join(" "):["persona-max-w-[85%]","persona-text-sm","persona-leading-relaxed","persona-text-persona-primary"].join(" "),Ae.setAttribute("data-idle-indicator","true"),Ae.appendChild(Qe);let mt=document.createElement("div");mt.className="persona-flex",mt.id="wrapper-idle-indicator",mt.setAttribute("data-wrapper-id","idle-indicator"),mt.appendChild(Ae),v.appendChild(mt)}}if(Xi(c,v),fe.length>0)for(let{messageId:D,fingerprint:Ie,bubble:$e}of fe){let Qe=c.querySelector(`#wrapper-${D}`);Qe&&$e!==null&&(Qe.replaceChildren($e),Qe.setAttribute("data-bubble-fp",Ie),Pn.set(D,Ie))}if(Pn.size>0)for(let D of Pn.keys())X.has(D)||Pn.delete(D);if(re.length>0)for(let{messageId:D,fingerprint:Ie,bubble:$e}of re){let Qe=c.querySelector(`#wrapper-${D}`);Qe&&$e!==null&&(Qe.replaceChildren($e),Qe.setAttribute("data-bubble-fp",Ie),Nn.set(D,Ie))}if(Nn.size>0)for(let D of Nn.keys())X.has(D)||Nn.delete(D)},go=null,Gs=()=>{var x;if(go)return;let c=v=>{let O=v.composedPath();O.includes(K)||Ce&&O.includes(Ce)||qt(!1,"user")};go=c,((x=e.ownerDocument)!=null?x:document).addEventListener("pointerdown",c,!0)},qa=()=>{var g;if(!go)return;((g=e.ownerDocument)!=null?g:document).removeEventListener("pointerdown",go,!0),go=null};At.push(()=>qa());let ho=null,Xs=()=>{var x;if(ho)return;let c=v=>{v.key==="Escape"&&(v.isComposing||qt(!1,"user"))};ho=c,((x=e.ownerDocument)!=null?x:document).addEventListener("keydown",c,!0)},za=()=>{var g;if(!ho)return;((g=e.ownerDocument)!=null?g:document).removeEventListener("keydown",ho,!0),ho=null};At.push(()=>za());let xo=!1,Va=new Set,Js=()=>{var g,x,v,O;let c=(v=(x=(g=n.launcher)==null?void 0:g.composerBar)==null?void 0:x.peek)==null?void 0:v.streamAnimation;return c||((O=n.features)==null?void 0:O.streamAnimation)},Kn=()=>{var gt,ht,Fe,He;if(!H())return;let c=De.peekBanner,g=De.peekTextNode;if(!c||!g)return;if(R){c.classList.remove("persona-pill-peek--visible");return}let x=(gt=z==null?void 0:z.getMessages())!=null?gt:[],v;for(let Je=x.length-1;Je>=0;Je--){let D=x[Je];if(D.role==="assistant"&&D.content){v=D;break}}if(!v){c.classList.remove("persona-pill-peek--visible");return}let O=v.content,$=!!v.streaming,U=Js(),X=Qi(U),N=X.type!=="none"?Ts(X.type,U==null?void 0:U.plugins):null,ke=((ht=N==null?void 0:N.isAnimating)==null?void 0:ht.call(N,v))===!0,fe=N!==null&&($||ke);fe&&N&&!Va.has(N.name)&&(sp(N,e),Va.add(N.name));let re=fe&&(N!=null&&N.containerClass)?N.containerClass:null,we=(Fe=g.dataset.personaPeekStreamClass)!=null?Fe:null;we&&we!==re&&(g.classList.remove(we),delete g.dataset.personaPeekStreamClass),re&&we!==re&&(g.classList.add(re),g.dataset.personaPeekStreamClass=re),fe?(g.style.setProperty("--persona-stream-step",`${X.speed}ms`),g.style.setProperty("--persona-stream-duration",`${X.duration}ms`)):(g.style.removeProperty("--persona-stream-step"),g.style.removeProperty("--persona-stream-duration"));let Le=fe?Zi(O,X.buffer,N,v,$):O;if(fe&&X.placeholder==="skeleton"&&$&&(!Le||!Le.trim())){let Je=document.createElement("div"),D=Es();D.classList.add("persona-pill-peek__skeleton"),Je.appendChild(D),Xi(g,Je)}else{let Je=Math.max(0,Le.length-100),D=Le.length>100?Le.slice(-100):Le,Ie=Jo(D);if(!fe||!N){let $e=Le.length>100?`\u2026${D}`:D;g.textContent!==$e&&(g.textContent=$e)}else{let $e=Ie;(N.wrap==="char"||N.wrap==="word")&&($e=ks(Ie,N.wrap,`peek-${v.id}`,{skipTags:N.skipTags,startIndex:Je}));let Qe=document.createElement("div");if(Qe.innerHTML=$e,N.useCaret&&D.length>0){let Ae=el(),Ft=Qe.querySelectorAll(".persona-stream-char, .persona-stream-word"),mt=Ft[Ft.length-1];mt!=null&&mt.parentNode?mt.parentNode.insertBefore(Ae,mt.nextSibling):Qe.appendChild(Ae)}Xi(g,Qe),(He=N.onAfterRender)==null||He.call(N,{container:g,bubble:c,messageId:v.id,message:v,speed:X.speed,duration:X.duration})}}let tt=he||xo;c.classList.toggle("persona-pill-peek--visible",tt)};if(H()){let c=De.peekBanner;if(c){let v=O=>{O.preventDefault(),O.stopPropagation(),qt(!0,"user")};c.addEventListener("pointerdown",v),At.push(()=>{c.removeEventListener("pointerdown",v)})}let g=()=>{xo||(xo=!0,Kn())},x=()=>{xo&&(xo=!1,Kn())};j.addEventListener("pointerenter",g),j.addEventListener("pointerleave",x),At.push(()=>{j.removeEventListener("pointerenter",g),j.removeEventListener("pointerleave",x)}),Ce&&(Ce.addEventListener("pointerenter",g),Ce.addEventListener("pointerleave",x),At.push(()=>{Ce.removeEventListener("pointerenter",g),Ce.removeEventListener("pointerleave",x)}))}let Ks=c=>{var we,Le,Ve,ct,tt,gt,ht,Fe;let g=(Le=(we=n.launcher)==null?void 0:we.composerBar)!=null?Le:{},x=(Ve=g.expandedSize)!=null?Ve:"anchored",v=(ct=g.bottomOffset)!=null?ct:"16px",O=g.collapsedMaxWidth,$=(tt=g.expandedMaxWidth)!=null?tt:"880px",U=(gt=g.expandedTopOffset)!=null?gt:"5vh",X=(ht=g.modalMaxWidth)!=null?ht:"880px",N=(Fe=g.modalMaxHeight)!=null?Fe:"min(90vh, 800px)",ke="calc(100vw - 32px)",fe="var(--persona-pill-area-height, 80px)",re=K.style;if(re.left="",re.right="",re.top="",re.bottom="",re.transform="",re.width="",re.maxWidth="",re.height="",re.maxHeight="",Ce){let He=Ce.style;He.bottom=v,He.width=O!=null?O:""}if(c&&x!=="fullscreen"){if(x==="modal"){re.top="50%",re.left="50%",re.transform="translate(-50%, -50%)",re.bottom="auto",re.right="auto",re.width=X,re.maxWidth=ke,re.maxHeight=N,re.height=N;return}re.left="50%",re.transform="translateX(-50%)",re.bottom=`calc(${v} + ${fe})`,re.top=U,re.width=$,re.maxWidth=ke}},yo=()=>{var N,ke,fe,re,we,Le,Ve,ct;if(!B())return;if(H()){let gt=(fe=((ke=(N=n.launcher)==null?void 0:N.composerBar)!=null?ke:{}).expandedSize)!=null?fe:"anchored",ht=R?"expanded":"collapsed";K.dataset.state=ht,K.dataset.expandedSize=gt,Ce&&(Ce.dataset.state=ht,Ce.dataset.expandedSize=gt),K.style.removeProperty("display"),K.classList.remove("persona-pointer-events-none","persona-opacity-0"),j.classList.remove("persona-scale-95","persona-opacity-0","persona-scale-100","persona-opacity-100"),Ks(R),oe.style.display=R?"flex":"none",Mn(),R?(Gs(),Xs()):(qa(),za()),Kn();return}let c=hr(n),g=(re=e.ownerDocument.defaultView)!=null?re:window,x=(Le=(we=n.launcher)==null?void 0:we.mobileBreakpoint)!=null?Le:640,v=(ct=(Ve=n.launcher)==null?void 0:Ve.mobileFullscreen)!=null?ct:!0,O=g.innerWidth<=x,$=v&&O&&T,U=vn(n).reveal;R?(K.style.removeProperty("display"),K.style.display=c?"flex":"",K.classList.remove("persona-pointer-events-none","persona-opacity-0"),j.classList.remove("persona-scale-95","persona-opacity-0"),j.classList.add("persona-scale-100","persona-opacity-100"),_?_.element.style.display="none":I&&(I.style.display="none")):(c?c&&(U==="overlay"||U==="push")&&!$?(K.style.removeProperty("display"),K.style.display="flex",K.classList.remove("persona-pointer-events-none","persona-opacity-0"),j.classList.remove("persona-scale-100","persona-opacity-100","persona-scale-95","persona-opacity-0")):(K.style.setProperty("display","none","important"),K.classList.remove("persona-pointer-events-none","persona-opacity-0"),j.classList.remove("persona-scale-100","persona-opacity-100","persona-scale-95","persona-opacity-0")):(K.style.display="",K.classList.add("persona-pointer-events-none","persona-opacity-0"),j.classList.remove("persona-scale-100","persona-opacity-100"),j.classList.add("persona-scale-95","persona-opacity-0")),_?_.element.style.display=c?"none":"":I&&(I.style.display=c?"none":""))},qt=(c,g="user")=>{var $,U;if(!B()||R===c)return;let x=R;R=c,yo();let v=(()=>{var Ve,ct,tt,gt,ht,Fe,He,Je,D,Ie;let X=(ct=(Ve=n.launcher)==null?void 0:Ve.sidebarMode)!=null?ct:!1,N=(tt=e.ownerDocument.defaultView)!=null?tt:window,ke=(ht=(gt=n.launcher)==null?void 0:gt.mobileFullscreen)!=null?ht:!0,fe=(He=(Fe=n.launcher)==null?void 0:Fe.mobileBreakpoint)!=null?He:640,re=N.innerWidth<=fe,we=hr(n)&&ke&&re,Le=H()&&((Ie=(D=(Je=n.launcher)==null?void 0:Je.composerBar)==null?void 0:D.expandedSize)!=null?Ie:"fullscreen")==="fullscreen";return X||ke&&re&&T||we||Le})();if(R&&v){if(!ir){let X=e.getRootNode(),N=X instanceof ShadowRoot?X.host:e.closest(".persona-host");N&&(ir=ip(N,(U=($=n.launcher)==null?void 0:$.zIndex)!=null?U:Dr))}lr||(lr=lp(e.ownerDocument))}else R||(ir==null||ir(),ir=null,lr==null||lr(),lr=null);R&&(Q(),mo(!0));let O={open:R,source:g,timestamp:Date.now()};R&&!x?a.emit("widget:opened",O):!R&&x&&a.emit("widget:closed",O),a.emit("widget:state",{open:R,launcherEnabled:T,voiceActive:wt.active,streaming:z.isStreaming()})},ca=c=>{Nt(c?"stop":"send"),F&&(F.disabled=c),Ln.buttons.forEach(g=>{g.disabled=c}),qe.dataset.personaComposerStreaming=c?"true":"false",qe.querySelectorAll("[data-persona-composer-disable-when-streaming]").forEach(g=>{(g instanceof HTMLButtonElement||g instanceof HTMLInputElement||g instanceof HTMLTextAreaElement||g instanceof HTMLSelectElement)&&(g.disabled=c)})},pa=()=>{wt.active||Me&&Me.focus()};a.on("widget:opened",()=>{n.autoFocusInput&&setTimeout(()=>pa(),200)});let ja=()=>{var x,v,O,$,U,X,N,ke,fe,re,we;Or.textContent=(v=(x=n.copy)==null?void 0:x.welcomeTitle)!=null?v:"Hello \u{1F44B}",vr.textContent=($=(O=n.copy)==null?void 0:O.welcomeSubtitle)!=null?$:"Ask anything about your account or products.",Me.placeholder=(X=(U=n.copy)==null?void 0:U.inputPlaceholder)!=null?X:"How can I help...";let c=Se.querySelector("[data-persona-intro-card]");if(c){let Le=((N=n.copy)==null?void 0:N.showWelcomeCard)!==!1;c.style.display=Le?"":"none",Le?(Se.classList.remove("persona-gap-3"),Se.classList.add("persona-gap-6")):(Se.classList.remove("persona-gap-6"),Se.classList.add("persona-gap-3"))}!((fe=(ke=n.sendButton)==null?void 0:ke.useIcon)!=null&&fe)&&!(z!=null&&z.isStreaming())&&(ae.textContent=(we=(re=n.copy)==null?void 0:re.sendButtonLabel)!=null?we:"Send"),Me.style.fontFamily='var(--persona-input-font-family, var(--persona-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif))',Me.style.fontWeight="var(--persona-input-font-weight, var(--persona-font-weight, 400))"};n.clientToken&&(n={...n,getStoredSessionId:()=>{let c=d.sessionId;return typeof c=="string"?c:null},setStoredSessionId:c=>{m(g=>({...g,sessionId:c}))}});let _n=null,Ys=()=>{_n==null&&(_n=setInterval(()=>{let c=ge.querySelectorAll("[data-tool-elapsed]");if(c.length===0){clearInterval(_n),_n=null;return}let g=Date.now();c.forEach(x=>{let v=Number(x.getAttribute("data-tool-elapsed"));v&&(x.textContent=yi(g-v))})},100))};if(z=new va(n,{onMessagesChanged(c){Ho(ge,c,ue),Ys(),z&&(c.some(O=>O.role==="user")?Ln.render([],z,Me,c):Ln.render(n.suggestionChips,z,Me,c,n.suggestionChipsConfig)),mo(!he),js(c);let g=[...c].reverse().find(v=>v.role==="user"),x=wt.lastUserMessageId;g&&g.id!==x&&(wt.lastUserMessageId=g.id,a.emit("user:message",g)),wt.lastUserMessageWasVoice=!!(g!=null&&g.viaVoice),da(c),Kn()},onStatusChanged(c){var v;let g=(v=n.statusIndicator)!=null?v:{};Ue(Qt,(O=>{var $,U,X,N;return O==="idle"?($=g.idleText)!=null?$:Wr.idle:O==="connecting"?(U=g.connectingText)!=null?U:Wr.connecting:O==="connected"?(X=g.connectedText)!=null?X:Wr.connected:O==="error"?(N=g.errorText)!=null?N:Wr.error:Wr[O]})(c),g,c)},onStreamingChanged(c){he=c,ca(c),z&&Ho(ge,z.getMessages(),ue),c||mo(!0),Kn()},onVoiceStatusChanged(c){var g,x;if(((x=(g=n.voiceRecognition)==null?void 0:g.provider)==null?void 0:x.type)==="runtype")switch(c){case"listening":break;case"processing":Wn(),Zs();break;case"speaking":Wn(),ei();break;default:c==="idle"&&z.isBargeInActive()?(Wn(),bo(),F==null||F.setAttribute("aria-label","End voice session")):(wt.active=!1,Wn(),bn("system"),Yr());break}},onArtifactsState(c){P=c,on(),da()}}),se.current=z,((Ou=(Du=n.voiceRecognition)==null?void 0:Du.provider)==null?void 0:Ou.type)==="runtype")try{z.setupVoice()}catch(c){typeof console!="undefined"&&console.warn("[AgentWidget] Runtype voice setup failed:",c)}n.clientToken&&z.initClientSession().catch(c=>{n.debug&&console.warn("[AgentWidget] Pre-init client session failed:",c)}),(G||n.onSSEEvent)&&z.setSSEEventCallback((c,g)=>{var x;(x=n.onSSEEvent)==null||x.call(n,c,g),G==null||G.push({id:`evt-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,type:c,timestamp:Date.now(),payload:JSON.stringify(g)})}),l&&l.then(c=>{var g,x,v;c&&(c.metadata&&(d=Ip(c.metadata),k.syncFromMetadata()),(g=c.messages)!=null&&g.length&&z.hydrateMessages(c.messages),(x=c.artifacts)!=null&&x.length&&z.hydrateArtifacts(c.artifacts,(v=c.selectedArtifactId)!=null?v:null))}).catch(c=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to hydrate stored state:",c)});let Ga=()=>{var g,x,v;!H()||R||!((v=(x=(g=n.launcher)==null?void 0:g.composerBar)==null?void 0:x.expandOnSubmit)==null||v)||qt(!0,"auto")},Xa=c=>{var O;if(c.preventDefault(),z.isStreaming()){z.cancel();return}let g=Me.value.trim(),x=(O=Et==null?void 0:Et.hasAttachments())!=null?O:!1;if(!g&&!x)return;Ga();let v;x&&(v=[],v.push(...Et.getContentParts()),g&&v.push(hs(g))),Me.value="",Me.style.height="auto",z.sendMessage(g,{contentParts:v}),x&&Et.clearAttachments()},Ja=c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),ae.click())},Ka=async c=>{var x;if(((x=n.attachments)==null?void 0:x.enabled)!==!0||!Et)return;let g=G0(c.clipboardData);g.length!==0&&(c.preventDefault(),await Et.handleFiles(g))},_r=null,dn=!1,Yn=null,ut=null,Ya=()=>typeof window=="undefined"?null:window.webkitSpeechRecognition||window.SpeechRecognition||null,Bo=(c="user")=>{var $,U,X,N,ke,fe,re;if(dn||z.isStreaming())return;let g=Ya();if(!g)return;_r=new g;let v=(U=(($=n.voiceRecognition)!=null?$:{}).pauseDuration)!=null?U:2e3;_r.continuous=!0,_r.interimResults=!0,_r.lang="en-US";let O=Me.value;_r.onresult=we=>{let Le="",Ve="";for(let tt=0;tt<we.results.length;tt++){let gt=we.results[tt],ht=gt[0].transcript;gt.isFinal?Le+=ht+" ":Ve=ht}let ct=O+Le+Ve;Me.value=ct,Yn&&clearTimeout(Yn),(Le||Ve)&&(Yn=window.setTimeout(()=>{let tt=Me.value.trim();tt&&_r&&dn&&(Bn(),Me.value="",Me.style.height="auto",z.sendMessage(tt,{viaVoice:!0}))},v))},_r.onerror=we=>{we.error!=="no-speech"&&Bn()},_r.onend=()=>{if(dn){let we=Me.value.trim();we&&we!==O.trim()&&(Me.value="",Me.style.height="auto",z.sendMessage(we,{viaVoice:!0})),Bn()}};try{if(_r.start(),dn=!0,wt.active=!0,c!=="system"&&(wt.manuallyDeactivated=!1),bn(c),Yr(),F){let we=(X=n.voiceRecognition)!=null?X:{};ut={backgroundColor:F.style.backgroundColor,color:F.style.color,borderColor:F.style.borderColor,iconName:(N=we.iconName)!=null?N:"mic",iconSize:parseFloat((re=(fe=we.iconSize)!=null?fe:(ke=n.sendButton)==null?void 0:ke.size)!=null?re:"40")||24};let Le=we.recordingBackgroundColor,Ve=we.recordingIconColor,ct=we.recordingBorderColor;if(F.classList.add("persona-voice-recording"),F.style.backgroundColor=Le!=null?Le:"var(--persona-voice-recording-bg, #ef4444)",F.style.color=Ve!=null?Ve:"var(--persona-voice-recording-indicator, #ffffff)",Ve){let tt=F.querySelector("svg");tt&&tt.setAttribute("stroke",Ve)}ct&&(F.style.borderColor=ct),F.setAttribute("aria-label","Stop voice recognition")}}catch{Bn("system")}},Bn=(c="user")=>{if(dn){if(dn=!1,Yn&&(clearTimeout(Yn),Yn=null),_r){try{_r.stop()}catch{}_r=null}if(wt.active=!1,bn(c),Yr(),F){if(F.classList.remove("persona-voice-recording"),ut){F.style.backgroundColor=ut.backgroundColor,F.style.color=ut.color,F.style.borderColor=ut.borderColor;let g=F.querySelector("svg");g&&g.setAttribute("stroke",ut.color||"currentColor"),ut=null}F.setAttribute("aria-label","Start voice recognition")}}},Qs=(c,g)=>{var gt,ht,Fe,He,Je,D,Ie,$e;let x=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),v=((gt=c==null?void 0:c.provider)==null?void 0:gt.type)==="runtype";if(!(x||v))return null;let $=h("div","persona-send-button-wrapper"),U=h("button","persona-rounded-button persona-flex persona-items-center persona-justify-center disabled:persona-opacity-50 persona-cursor-pointer");U.type="button",U.setAttribute("aria-label","Start voice recognition");let X=(ht=c==null?void 0:c.iconName)!=null?ht:"mic",N=(Fe=g==null?void 0:g.size)!=null?Fe:"40px",ke=(He=c==null?void 0:c.iconSize)!=null?He:N,fe=parseFloat(ke)||24,re=(Je=c==null?void 0:c.backgroundColor)!=null?Je:g==null?void 0:g.backgroundColor,we=(D=c==null?void 0:c.iconColor)!=null?D:g==null?void 0:g.textColor;U.style.width=ke,U.style.height=ke,U.style.minWidth=ke,U.style.minHeight=ke,U.style.fontSize="18px",U.style.lineHeight="1",we?U.style.color=we:U.style.color="var(--persona-text, #111827)";let Ve=ve(X,fe,we||"currentColor",1.5);Ve?U.appendChild(Ve):U.textContent="\u{1F3A4}",re?U.style.backgroundColor=re:U.style.backgroundColor="",c!=null&&c.borderWidth&&(U.style.borderWidth=c.borderWidth,U.style.borderStyle="solid"),c!=null&&c.borderColor&&(U.style.borderColor=c.borderColor),c!=null&&c.paddingX&&(U.style.paddingLeft=c.paddingX,U.style.paddingRight=c.paddingX),c!=null&&c.paddingY&&(U.style.paddingTop=c.paddingY,U.style.paddingBottom=c.paddingY),$.appendChild(U);let ct=(Ie=c==null?void 0:c.tooltipText)!=null?Ie:"Start voice recognition";if((($e=c==null?void 0:c.showTooltip)!=null?$e:!1)&&ct){let Qe=h("div","persona-send-button-tooltip");Qe.textContent=ct,$.appendChild(Qe)}return{micButton:U,micButtonWrapper:$}},ua=()=>{var g,x,v,O,$;if(!F||ut)return;let c=(g=n.voiceRecognition)!=null?g:{};ut={backgroundColor:F.style.backgroundColor,color:F.style.color,borderColor:F.style.borderColor,iconName:(x=c.iconName)!=null?x:"mic",iconSize:parseFloat(($=(O=c.iconSize)!=null?O:(v=n.sendButton)==null?void 0:v.size)!=null?$:"40")||24}},fa=(c,g)=>{var $,U,X,N,ke;if(!F)return;let x=F.querySelector("svg");x&&x.remove();let v=(ke=ut==null?void 0:ut.iconSize)!=null?ke:parseFloat((N=(X=($=n.voiceRecognition)==null?void 0:$.iconSize)!=null?X:(U=n.sendButton)==null?void 0:U.size)!=null?N:"40")||24,O=ve(c,v,g,1.5);O&&F.appendChild(O)},Wo=()=>{F&&F.classList.remove("persona-voice-recording","persona-voice-processing","persona-voice-speaking")},bo=()=>{var O;if(!F)return;ua();let c=(O=n.voiceRecognition)!=null?O:{},g=c.recordingBackgroundColor,x=c.recordingIconColor,v=c.recordingBorderColor;if(Wo(),F.classList.add("persona-voice-recording"),F.style.backgroundColor=g!=null?g:"var(--persona-voice-recording-bg, #ef4444)",F.style.color=x!=null?x:"var(--persona-voice-recording-indicator, #ffffff)",x){let $=F.querySelector("svg");$&&$.setAttribute("stroke",x)}v&&(F.style.borderColor=v),F.setAttribute("aria-label","Stop voice recognition")},Zs=()=>{var X,N,ke,fe,re,we,Le,Ve;if(!F)return;ua();let c=(X=n.voiceRecognition)!=null?X:{},g=z.getVoiceInterruptionMode(),x=(N=c.processingIconName)!=null?N:"loader",v=(fe=(ke=c.processingIconColor)!=null?ke:ut==null?void 0:ut.color)!=null?fe:"",O=(we=(re=c.processingBackgroundColor)!=null?re:ut==null?void 0:ut.backgroundColor)!=null?we:"",$=(Ve=(Le=c.processingBorderColor)!=null?Le:ut==null?void 0:ut.borderColor)!=null?Ve:"";Wo(),F.classList.add("persona-voice-processing"),F.style.backgroundColor=O,F.style.borderColor=$;let U=v||"currentColor";F.style.color=U,fa(x,U),F.setAttribute("aria-label","Processing voice input"),g==="none"&&(F.style.cursor="default")},ei=()=>{var ke,fe,re,we,Le,Ve,ct,tt,gt,ht,Fe,He;if(!F)return;ua();let c=(ke=n.voiceRecognition)!=null?ke:{},g=z.getVoiceInterruptionMode(),x=g==="cancel"?"square":g==="barge-in"?"mic":"volume-2",v=(fe=c.speakingIconName)!=null?fe:x,O=(Ve=c.speakingIconColor)!=null?Ve:g==="barge-in"?(we=(re=c.recordingIconColor)!=null?re:ut==null?void 0:ut.color)!=null?we:"":(Le=ut==null?void 0:ut.color)!=null?Le:"",$=(gt=c.speakingBackgroundColor)!=null?gt:g==="barge-in"?(ct=c.recordingBackgroundColor)!=null?ct:"var(--persona-voice-recording-bg, #ef4444)":(tt=ut==null?void 0:ut.backgroundColor)!=null?tt:"",U=(He=c.speakingBorderColor)!=null?He:g==="barge-in"?(ht=c.recordingBorderColor)!=null?ht:"":(Fe=ut==null?void 0:ut.borderColor)!=null?Fe:"";Wo(),F.classList.add("persona-voice-speaking"),F.style.backgroundColor=$,F.style.borderColor=U;let X=O||"currentColor";F.style.color=X,fa(v,X);let N=g==="cancel"?"Stop playback and re-record":g==="barge-in"?"Speak to interrupt":"Agent is speaking";F.setAttribute("aria-label",N),g==="none"&&(F.style.cursor="default"),g==="barge-in"&&F.classList.add("persona-voice-recording")},Wn=()=>{var c,g,x;F&&(Wo(),ut&&(F.style.backgroundColor=(c=ut.backgroundColor)!=null?c:"",F.style.color=(g=ut.color)!=null?g:"",F.style.borderColor=(x=ut.borderColor)!=null?x:"",fa(ut.iconName,ut.color||"currentColor"),ut=null),F.style.cursor="",F.setAttribute("aria-label","Start voice recognition"))},Do=()=>{var c,g;if(((g=(c=n.voiceRecognition)==null?void 0:c.provider)==null?void 0:g.type)==="runtype"){let x=z.getVoiceStatus(),v=z.getVoiceInterruptionMode();if(v==="none"&&(x==="processing"||x==="speaking"))return;if(v==="cancel"&&(x==="processing"||x==="speaking")){z.stopVoicePlayback();return}if(z.isBargeInActive()){z.stopVoicePlayback(),z.deactivateBargeIn().then(()=>{wt.active=!1,wt.manuallyDeactivated=!0,Yr(),bn("user"),Wn()});return}z.toggleVoice().then(()=>{wt.active=z.isVoiceActive(),wt.manuallyDeactivated=!z.isVoiceActive(),Yr(),bn("user"),z.isVoiceActive()?bo():Wn()});return}if(dn){let x=Me.value.trim();wt.manuallyDeactivated=!0,Yr(),Bn("user"),x&&(Me.value="",Me.style.height="auto",z.sendMessage(x))}else wt.manuallyDeactivated=!1,Yr(),Bo("user")};hn=Do,F&&(F.addEventListener("click",Do),At.push(()=>{var c,g;((g=(c=n.voiceRecognition)==null?void 0:c.provider)==null?void 0:g.type)==="runtype"?(z.isVoiceActive()&&z.toggleVoice(),Wn()):Bn("system"),F&&F.removeEventListener("click",Do)}));let ma=a.on("assistant:complete",()=>{_a&&(wt.active||wt.manuallyDeactivated||_a==="assistant"&&!wt.lastUserMessageWasVoice||setTimeout(()=>{var c,g;!wt.active&&!wt.manuallyDeactivated&&(((g=(c=n.voiceRecognition)==null?void 0:c.provider)==null?void 0:g.type)==="runtype"?z.toggleVoice().then(()=>{wt.active=z.isVoiceActive(),bn("auto"),z.isVoiceActive()&&bo()}):Bo("auto"))},600))});At.push(ma);let Ze=a.on("action:resubmit",()=>{setTimeout(()=>{z&&!z.isStreaming()&&z.continueConversation()},100)});At.push(Ze);let L=()=>{qt(!R,"user")},_=null,I=null;if(T&&!H()){let c=o.find(g=>g.renderLauncher);if(c!=null&&c.renderLauncher){let g=c.renderLauncher({config:n,defaultRenderer:()=>Ls(n,L).element,onToggle:L});g&&(I=g)}I||(_=Ls(n,L))}_?e.appendChild(_.element):I&&e.appendChild(I),yo(),Ln.render(n.suggestionChips,z,Me,void 0,n.suggestionChipsConfig),ja(),ca(z.isStreaming()),mo(!0),Us(),E&&(!T||H()?setTimeout(()=>pa(),0):R&&setTimeout(()=>pa(),200));let Q=()=>{var N,ke,fe,re,we,Le,Ve,ct,tt,gt,ht,Fe,He,Je,D,Ie,$e,Qe,Ae,Ft,mt,dr;if(H()){Ir(),yo();return}let c=hr(n),g=(ke=(N=n.launcher)==null?void 0:N.sidebarMode)!=null?ke:!1,x=c||g||((re=(fe=n.launcher)==null?void 0:fe.fullHeight)!=null?re:!1),v=(we=e.ownerDocument.defaultView)!=null?we:window,O=(Ve=(Le=n.launcher)==null?void 0:Le.mobileFullscreen)!=null?Ve:!0,$=(tt=(ct=n.launcher)==null?void 0:ct.mobileBreakpoint)!=null?tt:640,U=v.innerWidth<=$,X=O&&U&&T;try{if(X){Mn(),wo(e,n);return}if(M&&(M=!1,Mn(),wo(e,n)),!T&&!c){j.style.height="",j.style.width="";return}if(!g&&!c){let Mr=(ht=(gt=n==null?void 0:n.launcher)==null?void 0:gt.width)!=null?ht:n==null?void 0:n.launcherWidth,$t=Mr!=null?Mr:mn;j.style.width=$t,j.style.maxWidth=$t}if(Fn(),!x){let Mr=v.innerHeight,$t=64,$r=(He=(Fe=n.launcher)==null?void 0:Fe.heightOffset)!=null?He:0,Lr=Math.max(200,Mr-$t),at=Math.min(640,Lr),xt=Math.max(200,at-$r);j.style.height=`${xt}px`}}finally{if(Ir(),yo(),R&&T){let $t=((Je=e.ownerDocument.defaultView)!=null?Je:window).innerWidth<=((Ie=(D=n.launcher)==null?void 0:D.mobileBreakpoint)!=null?Ie:640),$r=(Qe=($e=n.launcher)==null?void 0:$e.sidebarMode)!=null?Qe:!1,Lr=(Ft=(Ae=n.launcher)==null?void 0:Ae.mobileFullscreen)!=null?Ft:!0,at=hr(n)&&Lr&&$t,xt=$r||Lr&&$t&&T||at;if(xt&&!lr){let Ur=e.getRootNode(),Hr=Ur instanceof ShadowRoot?Ur.host:e.closest(".persona-host");Hr&&!ir&&(ir=ip(Hr,(dr=(mt=n.launcher)==null?void 0:mt.zIndex)!=null?dr:Dr)),lr=lp(e.ownerDocument)}else xt||(ir==null||ir(),ir=null,lr==null||lr(),lr=null)}}};Q();let le=(Fu=e.ownerDocument.defaultView)!=null?Fu:window;if(le.addEventListener("resize",Q),At.push(()=>le.removeEventListener("resize",Q)),typeof ResizeObserver!="undefined"){let c=new ResizeObserver(()=>{Ir()});c.observe(qe),At.push(()=>c.disconnect())}Rn=Se.scrollTop;let ee=Se.scrollHeight,et=()=>{let c=Se.scrollTop,g=Se.scrollHeight,x=g<ee;ee=g;let{action:v,nextLastScrollTop:O}=Ki({following:In.isFollowing(),currentScrollTop:c,lastScrollTop:Rn,nearBottom:vs(Se,Na),userScrollThreshold:_s,isAutoScrolling:Gn||Io||x,pauseOnUpwardScroll:!0,pauseWhenAwayFromBottom:!1,resumeRequiresDownwardScroll:!0});if(Rn=O,v==="resume"){fo();return}v==="pause"&&Ua()};Se.addEventListener("scroll",et,{passive:!0}),At.push(()=>Se.removeEventListener("scroll",et));let ze=c=>{let g=Yi({following:In.isFollowing(),deltaY:c.deltaY,nearBottom:vs(Se,Na),resumeWhenNearBottom:!0});g==="pause"?Ua():g==="resume"&&fo()};Se.addEventListener("wheel",ze,{passive:!0}),At.push(()=>Se.removeEventListener("wheel",ze)),lt.addEventListener("click",()=>{Se.scrollTop=Se.scrollHeight,Rn=Se.scrollTop,fo(),mo(!0)}),At.push(()=>lt.remove()),At.push(()=>{$a()});let ft=()=>{Oe&&(sn&&(Oe.removeEventListener("click",sn),sn=null),B()?(Oe.style.display="",sn=()=>{qt(!1,"user")},Oe.addEventListener("click",sn)):Oe.style.display="none")};ft(),(()=>{let{clearChatButton:c}=De;c&&c.addEventListener("click",()=>{z.clearMessages(),ln.clear(),fo(),Mo(De.composerOverlay);try{localStorage.removeItem(Da),n.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${Da}`)}catch(x){console.error("[AgentWidget] Failed to clear default localStorage:",x)}if(n.clearChatHistoryStorageKey&&n.clearChatHistoryStorageKey!==Da)try{localStorage.removeItem(n.clearChatHistoryStorageKey),n.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${n.clearChatHistoryStorageKey}`)}catch(x){console.error("[AgentWidget] Failed to clear custom localStorage:",x)}let g=new CustomEvent("persona:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(g),i!=null&&i.clear)try{let x=i.clear();x instanceof Promise&&x.catch(v=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",v)})}catch(x){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",x)}d={},k.syncFromMetadata(),G==null||G.clear(),ce==null||ce.update()})})(),Ut&&Ut.addEventListener("submit",Xa),Me==null||Me.addEventListener("keydown",Ja),Me==null||Me.addEventListener("paste",Ka);let Dt="persona-attachment-drop-active",_t=0,fr=()=>{_t=0,oe.classList.remove(Dt)},St=()=>{var c;return((c=n.attachments)==null?void 0:c.enabled)===!0&&Et!==null},Ot=c=>{!Sl(c.dataTransfer)||!St()||(_t++,_t===1&&oe.classList.add(Dt))},yr=c=>{!Sl(c.dataTransfer)||!St()||(_t--,_t<=0&&fr())},Rr=c=>{!Sl(c.dataTransfer)||!St()||(c.preventDefault(),c.dataTransfer.dropEffect="copy")},Er=c=>{var x;if(!Sl(c.dataTransfer)||!St())return;c.preventDefault(),c.stopPropagation(),fr();let g=Array.from((x=c.dataTransfer.files)!=null?x:[]);g.length!==0&&Et.handleFiles(g)},Xt=!0;oe.addEventListener("dragenter",Ot,Xt),oe.addEventListener("dragleave",yr,Xt),e.addEventListener("dragover",Rr,Xt),e.addEventListener("drop",Er,Xt);let Qr=e.ownerDocument,Kp=c=>{St()&&c.preventDefault()},Yp=c=>{St()&&c.preventDefault()};Qr.addEventListener("dragover",Kp),Qr.addEventListener("drop",Yp),At.push(()=>{Ut&&Ut.removeEventListener("submit",Xa),Me==null||Me.removeEventListener("keydown",Ja),Me==null||Me.removeEventListener("paste",Ka)}),At.push(()=>{oe.removeEventListener("dragenter",Ot,Xt),oe.removeEventListener("dragleave",yr,Xt),e.removeEventListener("dragover",Rr,Xt),e.removeEventListener("drop",Er,Xt),Qr.removeEventListener("dragover",Kp),Qr.removeEventListener("drop",Yp),fr()}),At.push(()=>{z.cancel()}),_?At.push(()=>{_==null||_.destroy()}):I&&At.push(()=>{I==null||I.remove()});let mr={update(c){var gr,$n,Zn,ti,ri,ni,$o,oi,Qa,Vu,ju,Gu,Xu,Ju,Ku,Yu,Qu,Zu,ef,tf,rf,nf,of,af,sf,lf,df,cf,pf,uf,ff,mf,gf,hf,xf,yf,bf,Cf,wf,vf,Af,Sf,Tf,kf,Ef,Mf,Lf,Pf,If,Rf,Hf,Bf,Wf,Df,Of,Ff,Nf,_f,$f,Uf,qf,zf,Vf,jf,Gf,Xf,Jf,Kf,Yf,Qf,Zf,em,tm,rm,nm,om,am,sm,im,lm,dm,cm,pm,um,fm,mm,gm,hm,xm,ym,bm,Cm,wm,vm,Am,Sm,Tm,km,Em,Mm,Lm,Pm,Im,Rm,Hm,Bm,Wm,Dm,Om,Fm,Nm,_m,$m;let g=n.toolCall,x=n.messageActions,v=(gr=n.layout)==null?void 0:gr.messages,O=n.colorScheme,$=n.loadingIndicator,U=n.iterationDisplay,X=($n=n.features)==null?void 0:$n.showReasoning,N=(Zn=n.features)==null?void 0:Zn.showToolCalls,ke=(ti=n.features)==null?void 0:ti.toolCallDisplay,fe=(ri=n.features)==null?void 0:ri.reasoningDisplay;n={...n,...c},Mn(),wo(e,n),gl(e,n),hl(e,n),on(),n.colorScheme!==O&&uo();let re=Ws.getForInstance(n.plugins);o.length=0,o.push(...re),T=($o=(ni=n.launcher)==null?void 0:ni.enabled)!=null?$o:!0,S=(Qa=(oi=n.launcher)==null?void 0:oi.autoExpand)!=null?Qa:!1,Be=(ju=(Vu=n.features)==null?void 0:Vu.showReasoning)!=null?ju:!0,Ke=(Xu=(Gu=n.features)==null?void 0:Gu.showToolCalls)!=null?Xu:!0,me=(Ku=(Ju=n.features)==null?void 0:Ju.scrollToBottom)!=null?Ku:{},Tn(),Jn();let we=ye;if(ye=(Qu=(Yu=n.features)==null?void 0:Yu.showEventStreamToggle)!=null?Qu:!1,ye&&!we){if(G||(Y=new Bs(Xe),G=new Hs(Ee,Y),Y.open().then(()=>G==null?void 0:G.restore()).catch(()=>{}),z.setSSEEventCallback((te,It)=>{var Jt;(Jt=n.onSSEEvent)==null||Jt.call(n,te,It),G.push({id:`evt-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,type:te,timestamp:Date.now(),payload:JSON.stringify(It)})})),!bt&&Ne){let te=(ef=(Zu=n.features)==null?void 0:Zu.eventStream)==null?void 0:ef.classNames,It="persona-inline-flex persona-items-center persona-justify-center persona-rounded-full hover:persona-opacity-80 persona-cursor-pointer persona-border-none persona-bg-transparent persona-p-1"+(te!=null&&te.toggleButton?" "+te.toggleButton:"");bt=h("button",It),bt.style.width="28px",bt.style.height="28px",bt.style.color=Jr.actionIconColor,bt.type="button",bt.setAttribute("aria-label","Event Stream"),bt.title="Event Stream";let Jt=ve("activity","18px","currentColor",1.5);Jt&&bt.appendChild(Jt);let yt=De.clearChatButtonWrapper,Bt=De.closeButtonWrapper,br=yt||Bt;br&&br.parentNode===Ne?Ne.insertBefore(bt,br):Ne.appendChild(bt),bt.addEventListener("click",()=>{de?Kr():Ar()})}}else!ye&&we&&(Kr(),bt&&(bt.remove(),bt=null),G==null||G.clear(),Y==null||Y.destroy(),G=null,Y=null);if(((tf=n.launcher)==null?void 0:tf.enabled)===!1&&_&&(_.destroy(),_=null),((rf=n.launcher)==null?void 0:rf.enabled)===!1&&I&&(I.remove(),I=null),((nf=n.launcher)==null?void 0:nf.enabled)!==!1&&!_&&!I){let te=o.find(It=>It.renderLauncher);if(te!=null&&te.renderLauncher){let It=te.renderLauncher({config:n,defaultRenderer:()=>Ls(n,L).element,onToggle:L});It&&(I=It,e.appendChild(I))}I||(_=Ls(n,L),e.appendChild(_.element))}_&&_.update(n),Te&&((of=n.launcher)==null?void 0:of.title)!==void 0&&(Te.textContent=n.launcher.title),_e&&((af=n.launcher)==null?void 0:af.subtitle)!==void 0&&(_e.textContent=n.launcher.subtitle);let Le=(sf=n.layout)==null?void 0:sf.header;if((Le==null?void 0:Le.layout)!==y&&Ne){let te=Le?ka(n,Le,{showClose:B(),onClose:()=>qt(!1,"user")}):oo({config:n,showClose:B(),onClose:()=>qt(!1,"user")});Ne.replaceWith(te.header),Ne=te.header,q=te.iconHolder,Te=te.headerTitle,_e=te.headerSubtitle,Oe=te.closeButton,y=Le==null?void 0:Le.layout}else if(Le&&(q&&(q.style.display=Le.showIcon===!1?"none":""),Te&&(Te.style.display=Le.showTitle===!1?"none":""),_e&&(_e.style.display=Le.showSubtitle===!1?"none":""),Oe&&(Oe.style.display=Le.showCloseButton===!1?"none":""),De.clearChatButtonWrapper)){let te=Le.showClearChat;if(te!==void 0){De.clearChatButtonWrapper.style.display=te?"":"none";let{closeButtonWrapper:It}=De;It&&!It.classList.contains("persona-absolute")&&(te?It.classList.remove("persona-ml-auto"):It.classList.add("persona-ml-auto"))}}let ct=((lf=n.layout)==null?void 0:lf.showHeader)!==!1;Ne&&(Ne.style.display=ct?"":"none");let tt=((df=n.layout)==null?void 0:df.showFooter)!==!1;qe&&(qe.style.display=tt?"":"none"),Ir(),Jn(),T!==b?T?qt(S,"auto"):(R=!0,yo()):S!==w&&qt(S,"auto"),w=S,b=T,Q(),ft();let Fe=JSON.stringify(c.toolCall)!==JSON.stringify(g),He=JSON.stringify(n.messageActions)!==JSON.stringify(x),Je=JSON.stringify((cf=n.layout)==null?void 0:cf.messages)!==JSON.stringify(v),D=((pf=n.loadingIndicator)==null?void 0:pf.render)!==($==null?void 0:$.render)||((uf=n.loadingIndicator)==null?void 0:uf.renderIdle)!==($==null?void 0:$.renderIdle)||((ff=n.loadingIndicator)==null?void 0:ff.showBubble)!==($==null?void 0:$.showBubble),Ie=n.iterationDisplay!==U,$e=((gf=(mf=n.features)==null?void 0:mf.showReasoning)!=null?gf:!0)!==(X!=null?X:!0)||((xf=(hf=n.features)==null?void 0:hf.showToolCalls)!=null?xf:!0)!==(N!=null?N:!0)||JSON.stringify((yf=n.features)==null?void 0:yf.toolCallDisplay)!==JSON.stringify(ke)||JSON.stringify((bf=n.features)==null?void 0:bf.reasoningDisplay)!==JSON.stringify(fe);(Fe||He||Je||D||Ie||$e)&&z&&(Fa++,Ho(ge,z.getMessages(),ue));let Ae=(Cf=n.launcher)!=null?Cf:{},Ft=(wf=Ae.headerIconHidden)!=null?wf:!1,mt=(Af=(vf=n.layout)==null?void 0:vf.header)==null?void 0:Af.showIcon,dr=Ft||mt===!1,Mr=Ae.headerIconName,$t=(Sf=Ae.headerIconSize)!=null?Sf:"48px";if(q){let te=oe.querySelector(".persona-border-b-persona-divider"),It=te==null?void 0:te.querySelector(".persona-flex-col");if(dr)q.style.display="none",te&&It&&!te.contains(It)&&te.insertBefore(It,te.firstChild);else{if(q.style.display="",q.style.height=$t,q.style.width=$t,te&&It&&(te.contains(q)?q.nextSibling!==It&&(q.remove(),te.insertBefore(q,It)):te.insertBefore(q,It)),Mr){let yt=parseFloat($t)||24,Bt=ve(Mr,yt*.6,"#ffffff",2);Bt?q.replaceChildren(Bt):q.textContent=(Tf=Ae.agentIconText)!=null?Tf:"\u{1F4AC}"}else if(Ae.iconUrl){let yt=q.querySelector("img");if(yt)yt.src=Ae.iconUrl,yt.style.height=$t,yt.style.width=$t;else{let Bt=document.createElement("img");Bt.src=Ae.iconUrl,Bt.alt="",Bt.className="persona-rounded-xl persona-object-cover",Bt.style.height=$t,Bt.style.width=$t,q.replaceChildren(Bt)}}else{let yt=q.querySelector("svg"),Bt=q.querySelector("img");(yt||Bt)&&q.replaceChildren(),q.textContent=(kf=Ae.agentIconText)!=null?kf:"\u{1F4AC}"}let Jt=q.querySelector("img");Jt&&(Jt.style.height=$t,Jt.style.width=$t)}}let $r=(Mf=(Ef=n.layout)==null?void 0:Ef.header)==null?void 0:Mf.showTitle,Lr=(Pf=(Lf=n.layout)==null?void 0:Lf.header)==null?void 0:Pf.showSubtitle;if(Te&&(Te.style.display=$r===!1?"none":""),_e&&(_e.style.display=Lr===!1?"none":""),Oe){((Rf=(If=n.layout)==null?void 0:If.header)==null?void 0:Rf.showCloseButton)===!1?Oe.style.display="none":Oe.style.display="";let It=(Hf=Ae.closeButtonSize)!=null?Hf:"32px",Jt=(Bf=Ae.closeButtonPlacement)!=null?Bf:"inline";Oe.style.height=It,Oe.style.width=It;let{closeButtonWrapper:yt}=De,Bt=Jt==="top-right",br=yt==null?void 0:yt.classList.contains("persona-absolute");if(yt&&Bt!==br)if(yt.remove(),Bt)yt.className="persona-absolute persona-top-4 persona-right-4 persona-z-50",oe.style.position="relative",oe.appendChild(yt);else{let Ct=(Df=(Wf=Ae.clearChat)==null?void 0:Wf.placement)!=null?Df:"inline",Cr=(Ff=(Of=Ae.clearChat)==null?void 0:Of.enabled)!=null?Ff:!0;yt.className=Cr&&Ct==="inline"?"":"persona-ml-auto";let rn=oe.querySelector(".persona-border-b-persona-divider");rn&&rn.appendChild(yt)}if(Oe.style.color=Ae.closeButtonColor||Jr.actionIconColor,Ae.closeButtonBackgroundColor?(Oe.style.backgroundColor=Ae.closeButtonBackgroundColor,Oe.classList.remove("hover:persona-bg-gray-100")):(Oe.style.backgroundColor="",Oe.classList.add("hover:persona-bg-gray-100")),Ae.closeButtonBorderWidth||Ae.closeButtonBorderColor){let Ct=Ae.closeButtonBorderWidth||"0px",Cr=Ae.closeButtonBorderColor||"transparent";Oe.style.border=`${Ct} solid ${Cr}`,Oe.classList.remove("persona-border-none")}else Oe.style.border="",Oe.classList.add("persona-border-none");Ae.closeButtonBorderRadius?(Oe.style.borderRadius=Ae.closeButtonBorderRadius,Oe.classList.remove("persona-rounded-full")):(Oe.style.borderRadius="",Oe.classList.add("persona-rounded-full")),Ae.closeButtonPaddingX?(Oe.style.paddingLeft=Ae.closeButtonPaddingX,Oe.style.paddingRight=Ae.closeButtonPaddingX):(Oe.style.paddingLeft="",Oe.style.paddingRight=""),Ae.closeButtonPaddingY?(Oe.style.paddingTop=Ae.closeButtonPaddingY,Oe.style.paddingBottom=Ae.closeButtonPaddingY):(Oe.style.paddingTop="",Oe.style.paddingBottom="");let Br=(Nf=Ae.closeButtonIconName)!=null?Nf:"x",Dn=(_f=Ae.closeButtonIconText)!=null?_f:"\xD7";Oe.innerHTML="";let zr=ve(Br,"28px","currentColor",1);zr?Oe.appendChild(zr):Oe.textContent=Dn;let cr=($f=Ae.closeButtonTooltipText)!=null?$f:"Close chat",pn=(Uf=Ae.closeButtonShowTooltip)!=null?Uf:!0;if(Oe.setAttribute("aria-label",cr),yt&&(yt._cleanupTooltip&&(yt._cleanupTooltip(),delete yt._cleanupTooltip),pn&&cr)){let Ct=null,Cr=()=>{if(Ct||!Oe)return;let Uo=Oe.ownerDocument,Za=Uo.body;if(!Za)return;Ct=qn(Uo,"div","persona-clear-chat-tooltip"),Ct.textContent=cr;let es=qn(Uo,"div");es.className="persona-clear-chat-tooltip-arrow",Ct.appendChild(es);let qo=Oe.getBoundingClientRect();Ct.style.position="fixed",Ct.style.zIndex=String(vo),Ct.style.left=`${qo.left+qo.width/2}px`,Ct.style.top=`${qo.top-8}px`,Ct.style.transform="translate(-50%, -100%)",Za.appendChild(Ct)},rn=()=>{Ct&&Ct.parentNode&&(Ct.parentNode.removeChild(Ct),Ct=null)};yt.addEventListener("mouseenter",Cr),yt.addEventListener("mouseleave",rn),Oe.addEventListener("focus",Cr),Oe.addEventListener("blur",rn),yt._cleanupTooltip=()=>{rn(),yt&&(yt.removeEventListener("mouseenter",Cr),yt.removeEventListener("mouseleave",rn)),Oe&&(Oe.removeEventListener("focus",Cr),Oe.removeEventListener("blur",rn))}}}let{clearChatButton:at,clearChatButtonWrapper:xt}=De;if(at){let te=(qf=Ae.clearChat)!=null?qf:{},It=(zf=te.enabled)!=null?zf:!0,Jt=(jf=(Vf=n.layout)==null?void 0:Vf.header)==null?void 0:jf.showClearChat,yt=Jt!==void 0?Jt:It,Bt=(Gf=te.placement)!=null?Gf:"inline";if(xt){xt.style.display=yt?"":"none";let{closeButtonWrapper:br}=De;!H()&&br&&!br.classList.contains("persona-absolute")&&(yt?br.classList.remove("persona-ml-auto"):br.classList.add("persona-ml-auto"));let Br=Bt==="top-right",Dn=xt.classList.contains("persona-absolute");if(!H()&&Br!==Dn&&yt){if(xt.remove(),Br)xt.className="persona-absolute persona-top-4 persona-z-50",xt.style.right="48px",oe.style.position="relative",oe.appendChild(xt);else{xt.className="persona-relative persona-ml-auto persona-clear-chat-button-wrapper",xt.style.right="";let cr=oe.querySelector(".persona-border-b-persona-divider"),pn=De.closeButtonWrapper;cr&&pn&&pn.parentElement===cr?cr.insertBefore(xt,pn):cr&&cr.appendChild(xt)}let zr=De.closeButtonWrapper;zr&&!zr.classList.contains("persona-absolute")&&(Br?zr.classList.add("persona-ml-auto"):zr.classList.remove("persona-ml-auto"))}}if(yt){if(!H()){let Ct=(Xf=te.size)!=null?Xf:"32px";at.style.height=Ct,at.style.width=Ct}let br=(Jf=te.iconName)!=null?Jf:"refresh-cw",Br=(Kf=te.iconColor)!=null?Kf:"";at.style.color=Br||Jr.actionIconColor,at.innerHTML="";let Dn=H()?"14px":"20px",zr=ve(br,Dn,"currentColor",2);if(zr&&at.appendChild(zr),te.backgroundColor?(at.style.backgroundColor=te.backgroundColor,at.classList.remove("hover:persona-bg-gray-100")):(at.style.backgroundColor="",at.classList.add("hover:persona-bg-gray-100")),te.borderWidth||te.borderColor){let Ct=te.borderWidth||"0px",Cr=te.borderColor||"transparent";at.style.border=`${Ct} solid ${Cr}`,at.classList.remove("persona-border-none")}else at.style.border="",at.classList.add("persona-border-none");te.borderRadius?(at.style.borderRadius=te.borderRadius,at.classList.remove("persona-rounded-full")):(at.style.borderRadius="",at.classList.add("persona-rounded-full")),te.paddingX?(at.style.paddingLeft=te.paddingX,at.style.paddingRight=te.paddingX):(at.style.paddingLeft="",at.style.paddingRight=""),te.paddingY?(at.style.paddingTop=te.paddingY,at.style.paddingBottom=te.paddingY):(at.style.paddingTop="",at.style.paddingBottom="");let cr=(Yf=te.tooltipText)!=null?Yf:"Clear chat",pn=(Qf=te.showTooltip)!=null?Qf:!0;if(at.setAttribute("aria-label",cr),xt&&(xt._cleanupTooltip&&(xt._cleanupTooltip(),delete xt._cleanupTooltip),pn&&cr)){let Ct=null,Cr=()=>{if(Ct||!at)return;let Uo=at.ownerDocument,Za=Uo.body;if(!Za)return;Ct=qn(Uo,"div","persona-clear-chat-tooltip"),Ct.textContent=cr;let es=qn(Uo,"div");es.className="persona-clear-chat-tooltip-arrow",Ct.appendChild(es);let qo=at.getBoundingClientRect();Ct.style.position="fixed",Ct.style.zIndex=String(vo),Ct.style.left=`${qo.left+qo.width/2}px`,Ct.style.top=`${qo.top-8}px`,Ct.style.transform="translate(-50%, -100%)",Za.appendChild(Ct)},rn=()=>{Ct&&Ct.parentNode&&(Ct.parentNode.removeChild(Ct),Ct=null)};xt.addEventListener("mouseenter",Cr),xt.addEventListener("mouseleave",rn),at.addEventListener("focus",Cr),at.addEventListener("blur",rn),xt._cleanupTooltip=()=>{rn(),xt&&(xt.removeEventListener("mouseenter",Cr),xt.removeEventListener("mouseleave",rn)),at&&(at.removeEventListener("focus",Cr),at.removeEventListener("blur",rn))}}}}let Ur=n.actionParsers&&n.actionParsers.length?n.actionParsers:[Ds],Hr=n.actionHandlers&&n.actionHandlers.length?n.actionHandlers:[sa.message,sa.messageAndClick];k=Os({parsers:Ur,handlers:Hr,getSessionMetadata:f,updateSessionMetadata:m,emit:a.emit,documentRef:typeof document!="undefined"?document:null}),ue=Uh(n,k,ne),z.updateConfig(n),Ho(ge,z.getMessages(),ue),Ln.render(n.suggestionChips,z,Me,void 0,n.suggestionChipsConfig),ja(),ca(z.isStreaming());let Oo=((Zf=n.voiceRecognition)==null?void 0:Zf.enabled)===!0,Fo=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),No=((tm=(em=n.voiceRecognition)==null?void 0:em.provider)==null?void 0:tm.type)==="runtype";if(Oo&&(Fo||No))if(!F||!xe){let te=Qs(n.voiceRecognition,n.sendButton);te&&(F=te.micButton,xe=te.micButtonWrapper,pt.insertBefore(xe,ur),F.addEventListener("click",Do),F.disabled=z.isStreaming())}else{let te=(rm=n.voiceRecognition)!=null?rm:{},It=(nm=n.sendButton)!=null?nm:{},Jt=(om=te.iconName)!=null?om:"mic",yt=(am=It.size)!=null?am:"40px",Bt=(sm=te.iconSize)!=null?sm:yt,br=parseFloat(Bt)||24;F.style.width=Bt,F.style.height=Bt,F.style.minWidth=Bt,F.style.minHeight=Bt;let Br=(lm=(im=te.iconColor)!=null?im:It.textColor)!=null?lm:"currentColor";F.innerHTML="";let Dn=ve(Jt,br,Br,2);Dn?F.appendChild(Dn):F.textContent="\u{1F3A4}";let zr=(dm=te.backgroundColor)!=null?dm:It.backgroundColor;zr?F.style.backgroundColor=zr:F.style.backgroundColor="",Br?F.style.color=Br:F.style.color="var(--persona-text, #111827)",te.borderWidth?(F.style.borderWidth=te.borderWidth,F.style.borderStyle="solid"):(F.style.borderWidth="",F.style.borderStyle=""),te.borderColor?F.style.borderColor=te.borderColor:F.style.borderColor="",te.paddingX?(F.style.paddingLeft=te.paddingX,F.style.paddingRight=te.paddingX):(F.style.paddingLeft="",F.style.paddingRight=""),te.paddingY?(F.style.paddingTop=te.paddingY,F.style.paddingBottom=te.paddingY):(F.style.paddingTop="",F.style.paddingBottom="");let cr=xe==null?void 0:xe.querySelector(".persona-send-button-tooltip"),pn=(cm=te.tooltipText)!=null?cm:"Start voice recognition";if(((pm=te.showTooltip)!=null?pm:!1)&&pn)if(cr)cr.textContent=pn,cr.style.display="";else{let Cr=document.createElement("div");Cr.className="persona-send-button-tooltip",Cr.textContent=pn,xe==null||xe.insertBefore(Cr,F)}else cr&&(cr.style.display="none");xe.style.display="",F.disabled=z.isStreaming()}else F&&xe&&(xe.style.display="none",((fm=(um=n.voiceRecognition)==null?void 0:um.provider)==null?void 0:fm.type)==="runtype"?z.isVoiceActive()&&z.toggleVoice():dn&&Bn());if(((mm=n.attachments)==null?void 0:mm.enabled)===!0)if(!it||!be){let te=(gm=n.attachments)!=null?gm:{},Jt=(xm=((hm=n.sendButton)!=null?hm:{}).size)!=null?xm:"40px";Wt||(Wt=h("div","persona-attachment-previews persona-flex persona-flex-wrap persona-gap-2 persona-mb-2"),Wt.style.display="none",Ut.insertBefore(Wt,Me)),Ge||(Ge=document.createElement("input"),Ge.type="file",Ge.accept=((ym=te.allowedTypes)!=null?ym:no).join(","),Ge.multiple=((bm=te.maxFiles)!=null?bm:4)>1,Ge.style.display="none",Ge.setAttribute("aria-label","Attach files"),Ut.insertBefore(Ge,Me)),it=h("div","persona-send-button-wrapper"),be=h("button","persona-rounded-button persona-flex persona-items-center persona-justify-center disabled:persona-opacity-50 persona-cursor-pointer persona-attachment-button"),be.type="button",be.setAttribute("aria-label",(Cm=te.buttonTooltipText)!=null?Cm:"Attach file");let yt=(wm=te.buttonIconName)!=null?wm:"paperclip",Bt=Jt,br=parseFloat(Bt)||40,Br=Math.round(br*.6);be.style.width=Bt,be.style.height=Bt,be.style.minWidth=Bt,be.style.minHeight=Bt,be.style.fontSize="18px",be.style.lineHeight="1",be.style.backgroundColor="transparent",be.style.color="var(--persona-primary, #111827)",be.style.border="none",be.style.borderRadius="6px",be.style.transition="background-color 0.15s ease",be.addEventListener("mouseenter",()=>{be.style.backgroundColor="var(--persona-palette-colors-black-alpha-50, rgba(0, 0, 0, 0.05))"}),be.addEventListener("mouseleave",()=>{be.style.backgroundColor="transparent"});let Dn=ve(yt,Br,"currentColor",1.5);Dn?be.appendChild(Dn):be.textContent="\u{1F4CE}",be.addEventListener("click",pn=>{pn.preventDefault(),Ge==null||Ge.click()}),it.appendChild(be);let zr=(vm=te.buttonTooltipText)!=null?vm:"Attach file",cr=h("div","persona-send-button-tooltip");cr.textContent=zr,it.appendChild(cr),nt.append(it),!Et&&Ge&&Wt&&(Et=ta.fromConfig(te),Et.setPreviewsContainer(Wt),Ge.addEventListener("change",async()=>{Et&&(Ge!=null&&Ge.files)&&(await Et.handleFileSelect(Ge.files),Ge.value="")})),oe.querySelector(".persona-attachment-drop-overlay")||oe.appendChild(qh(te.dropOverlay))}else{it.style.display="";let te=(Am=n.attachments)!=null?Am:{};Ge&&(Ge.accept=((Sm=te.allowedTypes)!=null?Sm:no).join(","),Ge.multiple=((Tm=te.maxFiles)!=null?Tm:4)>1),Et&&Et.updateConfig({allowedTypes:te.allowedTypes,maxFileSize:te.maxFileSize,maxFiles:te.maxFiles})}else it&&(it.style.display="none"),Et&&Et.clearAttachments(),(km=oe.querySelector(".persona-attachment-drop-overlay"))==null||km.remove();let nr=(Em=n.sendButton)!=null?Em:{},_o=(Mm=nr.useIcon)!=null?Mm:!1,Co=(Lm=nr.iconText)!=null?Lm:"\u2191",Lt=nr.iconName,Zr=(Pm=nr.tooltipText)!=null?Pm:"Send message",Qn=(Im=nr.showTooltip)!=null?Im:!1,qr=(Rm=nr.size)!=null?Rm:"40px",en=nr.backgroundColor,Vt=nr.textColor;if(_o){if(ae.style.width=qr,ae.style.height=qr,ae.style.minWidth=qr,ae.style.minHeight=qr,ae.style.fontSize="18px",ae.style.lineHeight="1",ae.innerHTML="",Vt?ae.style.color=Vt:ae.style.color="var(--persona-button-primary-fg, #ffffff)",Lt){let te=parseFloat(qr)||24,It=(Vt==null?void 0:Vt.trim())||"currentColor",Jt=ve(Lt,te,It,2);Jt?ae.appendChild(Jt):ae.textContent=Co}else ae.textContent=Co;ae.className="persona-rounded-button persona-flex persona-items-center persona-justify-center disabled:persona-opacity-50 persona-cursor-pointer",en?(ae.style.backgroundColor=en,ae.classList.remove("persona-bg-persona-primary")):(ae.style.backgroundColor="",ae.classList.add("persona-bg-persona-primary"))}else ae.textContent=(Bm=(Hm=n.copy)==null?void 0:Hm.sendButtonLabel)!=null?Bm:"Send",ae.style.width="",ae.style.height="",ae.style.minWidth="",ae.style.minHeight="",ae.style.fontSize="",ae.style.lineHeight="",ae.className="persona-rounded-button persona-bg-persona-accent persona-px-4 persona-py-2 persona-text-sm persona-font-semibold persona-text-white disabled:persona-opacity-50 persona-cursor-pointer",en?(ae.style.backgroundColor=en,ae.classList.remove("persona-bg-persona-accent")):ae.classList.add("persona-bg-persona-accent"),Vt?ae.style.color=Vt:ae.classList.add("persona-text-white");nr.borderWidth?(ae.style.borderWidth=nr.borderWidth,ae.style.borderStyle="solid"):(ae.style.borderWidth="",ae.style.borderStyle=""),nr.borderColor?ae.style.borderColor=nr.borderColor:ae.style.borderColor="",nr.paddingX?(ae.style.paddingLeft=nr.paddingX,ae.style.paddingRight=nr.paddingX):(ae.style.paddingLeft="",ae.style.paddingRight=""),nr.paddingY?(ae.style.paddingTop=nr.paddingY,ae.style.paddingBottom=nr.paddingY):(ae.style.paddingTop="",ae.style.paddingBottom="");let er=ur==null?void 0:ur.querySelector(".persona-send-button-tooltip");if(Qn&&Zr)if(er)er.textContent=Zr,er.style.display="";else{let te=document.createElement("div");te.className="persona-send-button-tooltip",te.textContent=Zr,ur==null||ur.insertBefore(te,ae)}else er&&(er.style.display="none");let jt=(Nm=(Wm=n.layout)==null?void 0:Wm.contentMaxWidth)!=null?Nm:H()?(Fm=(Om=(Dm=n.launcher)==null?void 0:Dm.composerBar)==null?void 0:Om.contentMaxWidth)!=null?Fm:"720px":void 0;jt?(ge.style.maxWidth=jt,ge.style.marginLeft="auto",ge.style.marginRight="auto",ge.style.width="100%",Ut&&(Ut.style.maxWidth=jt,Ut.style.marginLeft="auto",Ut.style.marginRight="auto"),Rt&&(Rt.style.maxWidth=jt,Rt.style.marginLeft="auto",Rt.style.marginRight="auto")):(ge.style.maxWidth="",ge.style.marginLeft="",ge.style.marginRight="",ge.style.width="",Ut&&(Ut.style.maxWidth="",Ut.style.marginLeft="",Ut.style.marginRight=""),Rt&&(Rt.style.maxWidth="",Rt.style.marginLeft="",Rt.style.marginRight=""));let or=(_m=n.statusIndicator)!=null?_m:{},tn=($m=or.visible)!=null?$m:!0;if(Qt.style.display=tn?"":"none",z){let te=z.getStatus();Ue(Qt,(Jt=>{var yt,Bt,br,Br;return Jt==="idle"?(yt=or.idleText)!=null?yt:Wr.idle:Jt==="connecting"?(Bt=or.connectingText)!=null?Bt:Wr.connecting:Jt==="connected"?(br=or.connectedText)!=null?br:Wr.connected:Jt==="error"?(Br=or.errorText)!=null?Br:Wr.error:Wr[Jt]})(te),or,te)}Qt.classList.remove("persona-text-left","persona-text-center","persona-text-right");let cn=or.align==="left"?"persona-text-left":or.align==="center"?"persona-text-center":"persona-text-right";Qt.classList.add(cn)},open(){B()&&qt(!0,"api")},close(){B()&&qt(!1,"api")},toggle(){B()&&qt(!R,"api")},clearChat(){Z=!1,z.clearMessages(),ln.clear(),fo();try{localStorage.removeItem(Da),n.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${Da}`)}catch(g){console.error("[AgentWidget] Failed to clear default localStorage:",g)}if(n.clearChatHistoryStorageKey&&n.clearChatHistoryStorageKey!==Da)try{localStorage.removeItem(n.clearChatHistoryStorageKey),n.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${n.clearChatHistoryStorageKey}`)}catch(g){console.error("[AgentWidget] Failed to clear custom localStorage:",g)}let c=new CustomEvent("persona:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(c),i!=null&&i.clear)try{let g=i.clear();g instanceof Promise&&g.catch(x=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",x)})}catch(g){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",g)}d={},k.syncFromMetadata(),G==null||G.clear(),ce==null||ce.update()},setMessage(c){return!Me||z.isStreaming()?!1:(!R&&B()&&qt(!0,"system"),Me.value=c,Me.dispatchEvent(new Event("input",{bubbles:!0})),!0)},submitMessage(c){if(z.isStreaming())return!1;let g=(c==null?void 0:c.trim())||Me.value.trim();return g?(!R&&B()&&qt(!0,"system"),Me.value="",Me.style.height="auto",z.sendMessage(g),!0):!1},startVoiceRecognition(){var g,x;return z.isStreaming()?!1:((x=(g=n.voiceRecognition)==null?void 0:g.provider)==null?void 0:x.type)==="runtype"?(z.isVoiceActive()||(!R&&B()&&qt(!0,"system"),wt.manuallyDeactivated=!1,Yr(),z.toggleVoice().then(()=>{wt.active=z.isVoiceActive(),bn("user"),z.isVoiceActive()&&bo()})),!0):dn?!0:Ya()?(!R&&B()&&qt(!0,"system"),wt.manuallyDeactivated=!1,Yr(),Bo("user"),!0):!1},stopVoiceRecognition(){var c,g;return((g=(c=n.voiceRecognition)==null?void 0:c.provider)==null?void 0:g.type)==="runtype"?z.isVoiceActive()?(z.toggleVoice().then(()=>{wt.active=!1,wt.manuallyDeactivated=!0,Yr(),bn("user"),Wn()}),!0):!1:dn?(wt.manuallyDeactivated=!0,Yr(),Bn("user"),!0):!1},injectMessage(c){return!R&&B()&&qt(!0,"system"),z.injectMessage(c)},injectAssistantMessage(c){!R&&B()&&qt(!0,"system");let g=z.injectAssistantMessage(c);return W&&(W=!1,V&&(clearTimeout(V),V=null),setTimeout(()=>{z&&!z.isStreaming()&&z.continueConversation()},100)),g},injectUserMessage(c){return!R&&B()&&qt(!0,"system"),z.injectUserMessage(c)},injectSystemMessage(c){return!R&&B()&&qt(!0,"system"),z.injectSystemMessage(c)},injectMessageBatch(c){return!R&&B()&&qt(!0,"system"),z.injectMessageBatch(c)},injectComponentDirective(c){return!R&&B()&&qt(!0,"system"),z.injectComponentDirective(c)},injectTestMessage(c){!R&&B()&&qt(!0,"system"),z.injectTestEvent(c)},async connectStream(c,g){return z.connectStream(c,g)},__pushEventStreamEvent(c){G&&G.push({id:`evt-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,type:c.type,timestamp:Date.now(),payload:JSON.stringify(c.payload)})},showEventStream(){!ye||!G||Ar()},hideEventStream(){de&&Kr()},isEventStreamVisible(){return de},showArtifacts(){Sn(n)&&(Z=!1,on(),vt==null||vt.setMobileOpen(!0))},hideArtifacts(){Sn(n)&&(Z=!0,on())},upsertArtifact(c){return Sn(n)?(Z=!1,z.upsertArtifact(c)):null},selectArtifact(c){Sn(n)&&z.selectArtifact(c)},clearArtifacts(){Sn(n)&&z.clearArtifacts()},getArtifacts(){var c;return(c=z==null?void 0:z.getArtifacts())!=null?c:[]},getSelectedArtifactId(){var c;return(c=z==null?void 0:z.getSelectedArtifactId())!=null?c:null},focusInput(){return T&&!R&&!H()||!Me?!1:(Me.focus(),!0)},async resolveApproval(c,g){let v=z.getMessages().find(O=>{var $;return O.variant==="approval"&&(($=O.approval)==null?void 0:$.id)===c});if(!(v!=null&&v.approval))throw new Error(`Approval not found: ${c}`);return z.resolveApproval(v.approval,g)},getMessages(){return z.getMessages()},getStatus(){return z.getStatus()},getPersistentMetadata(){return{...d}},updatePersistentMetadata(c){m(c)},on(c,g){return a.on(c,g)},off(c,g){a.off(c,g)},isOpen(){return B()&&R},isVoiceActive(){return wt.active},getState(){return{open:B()&&R,launcherEnabled:T,voiceActive:wt.active,streaming:z.isStreaming()}},showCSATFeedback(c){!R&&B()&&qt(!0,"system");let g=ge.querySelector(".persona-feedback-container");g&&g.remove();let x=vl({onSubmit:async(v,O)=>{var $;z.isClientTokenMode()&&await z.submitCSATFeedback(v,O),($=c==null?void 0:c.onSubmit)==null||$.call(c,v,O)},onDismiss:c==null?void 0:c.onDismiss,...c});ge.appendChild(x),x.scrollIntoView({behavior:"smooth",block:"end"})},showNPSFeedback(c){!R&&B()&&qt(!0,"system");let g=ge.querySelector(".persona-feedback-container");g&&g.remove();let x=Al({onSubmit:async(v,O)=>{var $;z.isClientTokenMode()&&await z.submitNPSFeedback(v,O),($=c==null?void 0:c.onSubmit)==null||$.call(c,v,O)},onDismiss:c==null?void 0:c.onDismiss,...c});ge.appendChild(x),x.scrollIntoView({behavior:"smooth",block:"end"})},async submitCSATFeedback(c,g){return z.submitCSATFeedback(c,g)},async submitNPSFeedback(c,g){return z.submitNPSFeedback(c,g)},destroy(){_n!=null&&(clearInterval(_n),_n=null),At.forEach(c=>c()),K.remove(),Ce==null||Ce.remove(),_==null||_.destroy(),I==null||I.remove(),sn&&Oe.removeEventListener("click",sn)}};if((((Nu=t==null?void 0:t.debugTools)!=null?Nu:!1)||!!n.debug)&&typeof window!="undefined"){let c=window.AgentWidgetBrowser,g={controller:mr,getMessages:mr.getMessages,getStatus:mr.getStatus,getMetadata:mr.getPersistentMetadata,updateMetadata:mr.updatePersistentMetadata,clearHistory:()=>mr.clearChat(),setVoiceActive:x=>x?mr.startVoiceRecognition():mr.stopVoiceRecognition()};window.AgentWidgetBrowser=g,At.push(()=>{window.AgentWidgetBrowser===g&&(window.AgentWidgetBrowser=c)})}if(typeof window!="undefined"){let c=e.getAttribute("data-persona-instance")||e.id||"persona-"+Math.random().toString(36).slice(2,8),g=X=>{let N=X.detail;(!(N!=null&&N.instanceId)||N.instanceId===c)&&mr.focusInput()};if(window.addEventListener("persona:focusInput",g),At.push(()=>{window.removeEventListener("persona:focusInput",g)}),ye){let X=ke=>{let fe=ke.detail;(!(fe!=null&&fe.instanceId)||fe.instanceId===c)&&mr.showEventStream()},N=ke=>{let fe=ke.detail;(!(fe!=null&&fe.instanceId)||fe.instanceId===c)&&mr.hideEventStream()};window.addEventListener("persona:showEventStream",X),window.addEventListener("persona:hideEventStream",N),At.push(()=>{window.removeEventListener("persona:showEventStream",X),window.removeEventListener("persona:hideEventStream",N)})}let x=X=>{let N=X.detail;(!(N!=null&&N.instanceId)||N.instanceId===c)&&mr.showArtifacts()},v=X=>{let N=X.detail;(!(N!=null&&N.instanceId)||N.instanceId===c)&&mr.hideArtifacts()},O=X=>{let N=X.detail;N!=null&&N.instanceId&&N.instanceId!==c||N!=null&&N.artifact&&mr.upsertArtifact(N.artifact)},$=X=>{let N=X.detail;N!=null&&N.instanceId&&N.instanceId!==c||typeof(N==null?void 0:N.id)=="string"&&mr.selectArtifact(N.id)},U=X=>{let N=X.detail;(!(N!=null&&N.instanceId)||N.instanceId===c)&&mr.clearArtifacts()};window.addEventListener("persona:showArtifacts",x),window.addEventListener("persona:hideArtifacts",v),window.addEventListener("persona:upsertArtifact",O),window.addEventListener("persona:selectArtifact",$),window.addEventListener("persona:clearArtifacts",U),At.push(()=>{window.removeEventListener("persona:showArtifacts",x),window.removeEventListener("persona:hideArtifacts",v),window.removeEventListener("persona:upsertArtifact",O),window.removeEventListener("persona:selectArtifact",$),window.removeEventListener("persona:clearArtifacts",U)})}let Cn=X0(n.persistState);if(Cn&&B()){let c=J0(Cn.storage),g=`${Cn.keyPrefix}widget-open`,x=`${Cn.keyPrefix}widget-voice`,v=`${Cn.keyPrefix}widget-voice-mode`;if(c){let O=((_u=Cn.persist)==null?void 0:_u.openState)&&c.getItem(g)==="true",$=(($u=Cn.persist)==null?void 0:$u.voiceState)&&c.getItem(x)==="true",U=((Uu=Cn.persist)==null?void 0:Uu.voiceState)&&c.getItem(v)==="true";if(O&&setTimeout(()=>{mr.open(),setTimeout(()=>{var X;if($||U)mr.startVoiceRecognition();else if((X=Cn.persist)!=null&&X.focusInput){let N=e.querySelector("textarea");N&&N.focus()}},100)},0),(qu=Cn.persist)!=null&&qu.openState&&(a.on("widget:opened",()=>{c.setItem(g,"true")}),a.on("widget:closed",()=>{c.setItem(g,"false")})),(zu=Cn.persist)!=null&&zu.voiceState&&(a.on("voice:state",X=>{c.setItem(x,X.active?"true":"false")}),a.on("user:message",X=>{c.setItem(v,X.viaVoice?"true":"false")})),Cn.clearOnChatClear){let X=()=>{c.removeItem(g),c.removeItem(x),c.removeItem(v)},N=()=>X();window.addEventListener("persona:clear-chat",N),At.push(()=>{window.removeEventListener("persona:clear-chat",N)})}}}return u&&B()&&setTimeout(()=>{mr.open()},0),Kn(),mr};var K0=(e,r)=>{let t=e.trim(),n=/^(\d+(?:\.\d+)?)px$/i.exec(t);if(n)return Math.max(0,parseFloat(n[1]));let o=/^(\d+(?:\.\d+)?)%$/i.exec(t);return o?Math.max(0,r*parseFloat(o[1])/100):420},zh=(e,r)=>{var n,o;let t=(o=(n=r==null?void 0:r.launcher)==null?void 0:n.enabled)!=null?o:!0;e.className="persona-host",e.style.height=t?"":"100%",e.style.display=t?"":"flex",e.style.flexDirection=t?"":"column",e.style.flex=t?"":"1 1 auto",e.style.minHeight=t?"":"0"},Wp=e=>{e.style.position="",e.style.top="",e.style.bottom="",e.style.left="",e.style.right="",e.style.zIndex="",e.style.transform="",e.style.pointerEvents=""},Vh=e=>{e.style.inset="",e.style.width="",e.style.height="",e.style.maxWidth="",e.style.minWidth="",Wp(e)},Rp=e=>{e.style.transition=""},Hp=e=>{e.style.display="",e.style.flexDirection="",e.style.flex="",e.style.minHeight="",e.style.minWidth="",e.style.width="",e.style.height="",e.style.alignItems="",e.style.transition="",e.style.transform=""},Bp=e=>{e.style.width="",e.style.maxWidth="",e.style.minWidth="",e.style.flex="1 1 auto"},kl=(e,r)=>{e.style.width="",e.style.minWidth="",e.style.maxWidth="",e.style.boxSizing="",r.style.alignItems=""},Y0=(e,r,t,n,o)=>{o?t.parentElement!==r&&(e.replaceChildren(),r.replaceChildren(t,n),e.appendChild(r)):t.parentElement===r&&(r.replaceChildren(),e.appendChild(t),e.appendChild(n))},Q0=(e,r,t,n,o,a)=>{let s=a?r:e;o==="left"?s.firstElementChild!==n&&s.replaceChildren(n,t):s.lastElementChild!==n&&s.replaceChildren(t,n)},jh=(e,r,t,n,o,a,s)=>{var C,A,k,T,S,E;let i=vn(a),d=i.reveal==="push";Y0(e,r,t,n,d),Q0(e,r,t,n,i.side,d),e.dataset.personaHostLayout="docked",e.dataset.personaDockSide=i.side,e.dataset.personaDockOpen=s?"true":"false",e.style.width="100%",e.style.maxWidth="100%",e.style.minWidth="0",e.style.height="100%",e.style.minHeight="0",e.style.position="relative",t.style.display="flex",t.style.flexDirection="column",t.style.minHeight="0",t.style.position="relative",o.className="persona-host",o.style.height="100%",o.style.minHeight="0",o.style.display="flex",o.style.flexDirection="column",o.style.flex="1 1 auto";let l=e.ownerDocument.defaultView,u=(A=(C=a==null?void 0:a.launcher)==null?void 0:C.mobileFullscreen)!=null?A:!0,p=(T=(k=a==null?void 0:a.launcher)==null?void 0:k.mobileBreakpoint)!=null?T:640,f=l!=null?l.innerWidth<=p:!1;if(u&&f&&s){e.dataset.personaDockMobileFullscreen="true",e.removeAttribute("data-persona-dock-reveal"),Hp(r),Rp(n),Vh(n),Bp(t),kl(o,n),e.style.display="flex",e.style.flexDirection="column",e.style.alignItems="stretch",e.style.overflow="hidden",t.style.flex="1 1 auto",t.style.width="100%",t.style.minWidth="0",n.style.display="flex",n.style.flexDirection="column",n.style.position="fixed",n.style.inset="0",n.style.width="100%",n.style.height="100%",n.style.maxWidth="100%",n.style.minWidth="0",n.style.minHeight="0",n.style.overflow="hidden",n.style.zIndex=String((E=(S=a==null?void 0:a.launcher)==null?void 0:S.zIndex)!=null?E:Dr),n.style.transform="none",n.style.transition="none",n.style.pointerEvents="auto",n.style.flex="none",d&&(r.style.display="flex",r.style.flexDirection="column",r.style.width="100%",r.style.height="100%",r.style.minHeight="0",r.style.minWidth="0",r.style.flex="1 1 auto",r.style.alignItems="stretch",r.style.transform="none",r.style.transition="none",t.style.flex="1 1 auto",t.style.width="100%",t.style.maxWidth="100%",t.style.minWidth="0");return}if(e.removeAttribute("data-persona-dock-mobile-fullscreen"),Vh(n),i.reveal==="overlay"){e.style.display="flex",e.style.flexDirection="row",e.style.alignItems="stretch",e.style.overflow="hidden",e.dataset.personaDockReveal="overlay",Hp(r),Rp(n),Bp(t),kl(o,n);let w=i.animate?"transform 180ms ease":"none",b=i.side==="right"?"translateX(100%)":"translateX(-100%)",y=s?"translateX(0)":b;n.style.display="flex",n.style.flexDirection="column",n.style.flex="none",n.style.position="absolute",n.style.top="0",n.style.bottom="0",n.style.width=i.width,n.style.maxWidth=i.width,n.style.minWidth=i.width,n.style.minHeight="0",n.style.overflow="hidden",n.style.transition=w,n.style.transform=y,n.style.pointerEvents=s?"auto":"none",n.style.zIndex="2",i.side==="right"?(n.style.right="0",n.style.left=""):(n.style.left="0",n.style.right="")}else if(i.reveal==="push"){e.style.display="flex",e.style.flexDirection="row",e.style.alignItems="stretch",e.style.overflow="hidden",e.dataset.personaDockReveal="push",Rp(n),Wp(n),kl(o,n);let w=K0(i.width,e.clientWidth),b=Math.max(0,e.clientWidth),y=i.animate?"transform 180ms ease":"none",M=i.side==="right"?s?`translateX(-${w}px)`:"translateX(0)":s?"translateX(0)":`translateX(-${w}px)`;r.style.display="flex",r.style.flexDirection="row",r.style.flex="0 0 auto",r.style.minHeight="0",r.style.minWidth="0",r.style.alignItems="stretch",r.style.height="100%",r.style.width=`${b+w}px`,r.style.transition=y,r.style.transform=M,t.style.flex="0 0 auto",t.style.flexGrow="0",t.style.flexShrink="0",t.style.width=`${b}px`,t.style.maxWidth=`${b}px`,t.style.minWidth=`${b}px`,n.style.display="flex",n.style.flexDirection="column",n.style.flex="0 0 auto",n.style.flexShrink="0",n.style.width=i.width,n.style.minWidth=i.width,n.style.maxWidth=i.width,n.style.position="relative",n.style.overflow="hidden",n.style.transition="none",n.style.pointerEvents=s?"auto":"none"}else{e.style.display="flex",e.style.flexDirection="row",e.style.alignItems="stretch",e.style.overflow="",Hp(r),Wp(n),Bp(t),kl(o,n);let w=i.reveal==="emerge";w?e.dataset.personaDockReveal="emerge":e.removeAttribute("data-persona-dock-reveal");let b=s?i.width:"0px",y=i.animate?"width 180ms ease, min-width 180ms ease, max-width 180ms ease, flex-basis 180ms ease":"none",M=!s;n.style.display="flex",n.style.flexDirection="column",n.style.flex=`0 0 ${b}`,n.style.width=b,n.style.maxWidth=b,n.style.minWidth=b,n.style.minHeight="0",n.style.position="relative",n.style.overflow=w||M?"hidden":"visible",n.style.transition=y,w&&(n.style.alignItems=i.side==="right"?"flex-start":"flex-end",o.style.width=i.width,o.style.minWidth=i.width,o.style.maxWidth=i.width,o.style.boxSizing="border-box")}},Z0=(e,r)=>{let t=e.ownerDocument.createElement("div");return zh(t,r),e.appendChild(t),{mode:"direct",host:t,shell:null,syncWidgetState:()=>{},updateConfig(n){zh(t,n)},destroy(){t.remove()}}},eC=(e,r)=>{var S,E,w,b;let{ownerDocument:t}=e,n=e.parentElement;if(!n)throw new Error("Docked widget target must be attached to the DOM");let o=e.tagName.toUpperCase();if(o==="BODY"||o==="HTML")throw new Error('Docked widget target must be a concrete container element, not "body" or "html"');let a=e.nextSibling,s=t.createElement("div"),i=t.createElement("div"),d=t.createElement("div"),l=t.createElement("aside"),u=t.createElement("div"),p=(E=(S=r==null?void 0:r.launcher)==null?void 0:S.enabled)==null||E?(b=(w=r==null?void 0:r.launcher)==null?void 0:w.autoExpand)!=null?b:!1:!0;i.dataset.personaDockRole="push-track",d.dataset.personaDockRole="content",l.dataset.personaDockRole="panel",u.dataset.personaDockRole="host",l.appendChild(u),n.insertBefore(s,e),d.appendChild(e);let f=null,m=()=>{f==null||f.disconnect(),f=null},C=()=>{m(),vn(r).reveal==="push"&&typeof ResizeObserver!="undefined"&&(f=new ResizeObserver(()=>{jh(s,i,d,l,u,r,p)}),f.observe(s))},A=()=>{jh(s,i,d,l,u,r,p),C()},k=s.ownerDocument.defaultView,T=()=>{A()};return k==null||k.addEventListener("resize",T),vn(r).reveal==="push"?(i.appendChild(d),i.appendChild(l),s.appendChild(i)):(s.appendChild(d),s.appendChild(l)),A(),{mode:"docked",host:u,shell:s,syncWidgetState(y){let M=y.launcherEnabled?y.open:!0;p!==M&&(p=M,A())},updateConfig(y){var M,H;r=y,((H=(M=r==null?void 0:r.launcher)==null?void 0:M.enabled)!=null?H:!0)===!1&&(p=!0),A()},destroy(){k==null||k.removeEventListener("resize",T),m(),n.isConnected&&(a&&a.parentNode===n?n.insertBefore(e,a):n.appendChild(e)),s.remove()}}},Fs=(e,r)=>hr(r)?eC(e,r):Z0(e,r);var Dp={},tC=e=>{if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Chat widget can only be mounted in a browser environment");if(typeof e=="string"){let r=document.querySelector(e);if(!r)throw new Error(`Chat widget target "${e}" was not found`);return r}return e},rC=()=>{try{if(typeof Dp!="undefined"&&Dp.url)return new URL("../widget.css",Dp.url).href}catch{}return null},Gh=(e,r)=>{let t=rC(),n=()=>{if(!(e instanceof ShadowRoot)||e.querySelector("link[data-persona]"))return;let o=r.head.querySelector("link[data-persona]");if(!o)return;let a=o.cloneNode(!0);e.insertBefore(a,e.firstChild)};if(e instanceof ShadowRoot)if(t){let o=r.createElement("link");o.rel="stylesheet",o.href=t,o.setAttribute("data-persona","true"),e.insertBefore(o,e.firstChild)}else n();else if(!r.head.querySelector("link[data-persona]")&&t){let a=r.createElement("link");a.rel="stylesheet",a.href=t,a.setAttribute("data-persona","true"),r.head.appendChild(a)}},Xh=e=>{var k;let r=tC(e.target),t=e.useShadowDom===!0,n=r.ownerDocument,o=e.config,a=Fs(r,o),s,i=[],d=(T,S)=>{var y,M;let w=!((M=(y=S==null?void 0:S.launcher)==null?void 0:y.enabled)!=null?M:!0)||hr(S),b=n.createElement("div");if(b.setAttribute("data-persona-root","true"),w&&(b.style.height="100%",b.style.display="flex",b.style.flexDirection="column",b.style.flex="1",b.style.minHeight="0"),t){let H=T.attachShadow({mode:"open"});H.appendChild(b),Gh(H,n)}else T.appendChild(b),Gh(T,n);return r.id&&b.setAttribute("data-persona-instance",r.id),b},l=()=>{a.syncWidgetState(s.getState())},u=()=>{i.forEach(T=>T()),i=[s.on("widget:opened",l),s.on("widget:closed",l)],l()},p=()=>{let T=d(a.host,o);s=Tl(T,o,{debugTools:e.debugTools}),u()},f=()=>{i.forEach(T=>T()),i=[],s.destroy()};p(),(k=e.onReady)==null||k.call(e);let m=T=>{f(),a.destroy(),a=Fs(r,T),o=T,p()},C={update(T){var M,H,B,R,W,V;let S={...o,...T,launcher:{...(M=o==null?void 0:o.launcher)!=null?M:{},...(H=T==null?void 0:T.launcher)!=null?H:{},dock:{...(R=(B=o==null?void 0:o.launcher)==null?void 0:B.dock)!=null?R:{},...(V=(W=T==null?void 0:T.launcher)==null?void 0:W.dock)!=null?V:{}}}},E=hr(o),w=hr(S),b=So(o),y=So(S);if(E!==w||b!==y){m(S);return}o=S,a.updateConfig(o),s.update(T),l()},destroy(){f(),a.destroy(),e.windowKey&&typeof window!="undefined"&&delete window[e.windowKey]}},A=new Proxy(C,{get(T,S,E){if(S==="host")return a.host;if(S in T)return Reflect.get(T,S,E);let w=s[S];return typeof w=="function"?w.bind(s):w}});return e.windowKey&&typeof window!="undefined"&&(window[e.windowKey]=A),A};var Zh=new Set(["script","style","noscript","svg","path","meta","link","br","hr"]),nC=new Set(["button","a","input","select","textarea","details","summary"]),oC=new Set(["button","link","menuitem","tab","option","switch","checkbox","radio","combobox","listbox","slider","spinbutton","textbox"]),Op=/\b(product|card|item|listing|result)\b/i,Np=/\$[\d,]+(?:\.\d{2})?|€[\d,]+(?:\.\d{2})?|£[\d,]+(?:\.\d{2})?|USD\s*[\d,]+(?:\.\d{2})?/i,aC=3e3,sC=100;function ex(e){let r=typeof e.className=="string"?e.className:"";if(Op.test(r)||e.id&&Op.test(e.id))return!0;for(let t=0;t<e.attributes.length;t++){let n=e.attributes[t];if(n.name.startsWith("data-")&&Op.test(n.value))return!0}return!1}function tx(e){var r;return Np.test(((r=e.textContent)!=null?r:"").trim())}function rx(e){var t;let r=e.querySelectorAll("a[href]");for(let n=0;n<r.length;n++){let o=(t=r[n].getAttribute("href"))!=null?t:"";if(o&&o!=="#"&&!o.toLowerCase().startsWith("javascript:"))return!0}return!1}function iC(e){return!!e.querySelector('button, [role="button"], input[type="submit"], input[type="button"]')}function Jh(e){let r=e.match(Np);return r?r[0]:null}function Kh(e){var n,o,a;let r=(n=e.querySelector(".product-title a, h1 a, h2 a, h3 a, h4 a, .title a, a[href]"))!=null?n:e.querySelector("a[href]");if(r&&((o=r.textContent)!=null&&o.trim())){let s=r.getAttribute("href");return{title:r.textContent.trim(),href:s&&s!=="#"?s:null}}let t=e.querySelector("h1, h2, h3, h4, h5, h6");return(a=t==null?void 0:t.textContent)!=null&&a.trim()?{title:t.textContent.trim(),href:null}:{title:"",href:null}}function lC(e){let r=[],t=n=>{let o=n.trim();o&&!r.includes(o)&&r.push(o)};return e.querySelectorAll("button").forEach(n=>{var o;return t((o=n.textContent)!=null?o:"")}),e.querySelectorAll('[role="button"]').forEach(n=>{var o;return t((o=n.textContent)!=null?o:"")}),e.querySelectorAll('input[type="submit"], input[type="button"]').forEach(n=>{var o;t((o=n.value)!=null?o:"")}),r.slice(0,6)}var dC="commerce-card",cC="result-card";function Yh(e){return!ex(e)||!tx(e)||!rx(e)&&!iC(e)?0:5200}function Qh(e){var n;return!ex(e)||tx(e)||!rx(e)||((n=e.textContent)!=null?n:"").trim().length<20||!(!!e.querySelector("h1, h2, h3, h4, h5, h6, .title")||!!e.querySelector(".snippet, .description, p"))?0:2800}var _p=[{id:dC,scoreElement(e){return Yh(e)},shouldSuppressDescendant(e,r,t){if(r===e||!e.contains(r))return!1;if(t.interactivity==="static"){let n=t.text.trim();return!!(n.length===0||Np.test(n)&&n.length<32)}return!0},formatSummary(e,r){var d,l,u;if(Yh(e)===0)return null;let{title:t,href:n}=Kh(e),o=(u=(l=Jh(((d=e.textContent)!=null?d:"").trim()))!=null?l:Jh(r.text))!=null?u:"",a=lC(e);return[n&&t?`[${t}](${n})${o?` \u2014 ${o}`:""}`:t?`${t}${o?` \u2014 ${o}`:""}`:o||r.text.trim().slice(0,120),`selector: ${r.selector}`,a.length?`actions: ${a.join(", ")}`:""].filter(Boolean).join(`
|
|
148
148
|
`)}},{id:cC,scoreElement(e){return Qh(e)},formatSummary(e,r){if(Qh(e)===0)return null;let{title:t,href:n}=Kh(e);return[n&&t?`[${t}](${n})`:t||r.text.trim().slice(0,120),`selector: ${r.selector}`].filter(Boolean).join(`
|
|
149
|
-
`)}}];function pC(){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn('[persona] collectEnrichedPageContext: options.mode is "simple" but `rules` were provided; rules are ignored.')}function uC(e){var u,p,f,m,C,
|
|
149
|
+
`)}}];function pC(){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn('[persona] collectEnrichedPageContext: options.mode is "simple" but `rules` were provided; rules are ignored.')}function uC(e){var u,p,f,m,C,A,k,T,S,E,w,b,y;let r=(u=e.options)!=null?u:{},t=(f=(p=r.maxElements)!=null?p:e.maxElements)!=null?f:80,n=(C=(m=r.excludeSelector)!=null?m:e.excludeSelector)!=null?C:".persona-host",o=(k=(A=r.maxTextLength)!=null?A:e.maxTextLength)!=null?k:200,a=(S=(T=r.visibleOnly)!=null?T:e.visibleOnly)!=null?S:!0,s=(E=r.root)!=null?E:e.root,i=(w=r.mode)!=null?w:"structured",d=(b=r.maxCandidates)!=null?b:Math.max(500,t*10),l=(y=e.rules)!=null?y:_p;return i==="simple"&&e.rules&&e.rules.length>0?(pC(),l=[]):i==="simple"&&(l=[]),{mode:i,maxElements:t,maxCandidates:d,excludeSelector:n,maxTextLength:o,visibleOnly:a,root:s,rules:l}}function Fp(e){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/([^\w-])/g,"\\$1")}var fC=["data-testid","data-product","data-action","data-id","data-name","data-type"];function mC(e){let r=e.tagName.toLowerCase(),t=e.getAttribute("role");return r==="a"&&e.hasAttribute("href")?"navigable":r==="input"||r==="select"||r==="textarea"||t==="textbox"||t==="combobox"||t==="listbox"||t==="spinbutton"?"input":r==="button"||t==="button"||nC.has(r)||t&&oC.has(t)||e.hasAttribute("tabindex")||e.hasAttribute("onclick")||e.getAttribute("contenteditable")==="true"?"clickable":"static"}function nx(e){if(e.hidden)return!1;try{let r=getComputedStyle(e);if(r.display==="none"||r.visibility==="hidden")return!1}catch{}return!(e.style.display==="none"||e.style.visibility==="hidden")}function gC(e){let r={},t=e.id;t&&(r.id=t);let n=e.getAttribute("href");n&&(r.href=n);let o=e.getAttribute("aria-label");o&&(r["aria-label"]=o);let a=e.getAttribute("type");a&&(r.type=a);let s=e.getAttribute("value");s&&(r.value=s);let i=e.getAttribute("name");i&&(r.name=i);let d=e.getAttribute("role");d&&(r.role=d);for(let l=0;l<e.attributes.length;l++){let u=e.attributes[l];u.name.startsWith("data-")&&(r[u.name]=u.value)}return r}function $p(e){let r=e.tagName.toLowerCase();if(e.id){let o=`#${Fp(e.id)}`;try{if(e.ownerDocument.querySelectorAll(o).length===1)return o}catch{}}for(let o of fC){let a=e.getAttribute(o);if(a){let s=`${r}[${o}="${Fp(a)}"]`;try{if(e.ownerDocument.querySelectorAll(s).length===1)return s}catch{}}}let t=Array.from(e.classList).filter(o=>o&&!o.startsWith("persona-")).slice(0,3);if(t.length>0){let o=`${r}.${t.map(s=>Fp(s)).join(".")}`;try{if(e.ownerDocument.querySelectorAll(o).length===1)return o}catch{}let a=e.parentElement;if(a){let i=Array.from(a.querySelectorAll(`:scope > ${r}`)).indexOf(e);if(i>=0){let d=`${o}:nth-of-type(${i+1})`;try{if(e.ownerDocument.querySelectorAll(d).length===1)return d}catch{}}}}let n=e.parentElement;if(n){let a=Array.from(n.querySelectorAll(`:scope > ${r}`)).indexOf(e);if(a>=0)return`${r}:nth-of-type(${a+1})`}return r}function hC(e){return e==="static"?sC:aC}function ox(e,r){var o;let t=e.tagName.toLowerCase(),n=((o=e.textContent)!=null?o:"").trim().substring(0,r);return{selector:$p(e),tagName:t,text:n,role:e.getAttribute("role"),interactivity:mC(e),attributes:gC(e)}}function xC(e,r,t,n){let o=hC(r.interactivity),a=null;for(let s of t){let i=s.scoreElement(e,r,n);i>0&&(o+=i,s.formatSummary&&!a&&(a=s))}return{score:o,formattingRule:a}}function yC(e,r){var t;for(let n of e)if(r.el!==n.el&&(t=n.formattingRule)!=null&&t.shouldSuppressDescendant&&n.el.contains(r.el)&&n.formattingRule.shouldSuppressDescendant(n.el,r.el,r.enriched))return!0;return!1}function bC(e,r){let t={doc:r.ownerDocument,maxTextLength:e.maxTextLength},n=new Set,o=[],a=0,s=document.createTreeWalker(r,NodeFilter.SHOW_ELEMENT,null),i=s.currentNode;for(;i&&o.length<e.maxCandidates;){if(i.nodeType===Node.ELEMENT_NODE){let l=i,u=l.tagName.toLowerCase();if(Zh.has(u)){i=s.nextNode();continue}if(e.excludeSelector)try{if(l.closest(e.excludeSelector)){i=s.nextNode();continue}}catch{}if(e.visibleOnly&&!nx(l)){i=s.nextNode();continue}let p=ox(l,e.maxTextLength),f=p.text.length>0,m=Object.keys(p.attributes).length>0&&!Object.keys(p.attributes).every(k=>k==="role");if(!f&&!m){i=s.nextNode();continue}if(n.has(p.selector)){i=s.nextNode();continue}n.add(p.selector);let{score:C,formattingRule:A}=xC(l,p,e.rules,t);o.push({el:l,domIndex:a,enriched:p,score:C,formattingRule:A}),a+=1}i=s.nextNode()}o.sort((l,u)=>{let p=l.enriched.interactivity==="static"?1:0,f=u.enriched.interactivity==="static"?1:0;return p!==f?p-f:u.score!==l.score?u.score-l.score:l.domIndex-u.domIndex});let d=[];for(let l of o){if(d.length>=e.maxElements)break;yC(d,l)||d.push(l)}return d.sort((l,u)=>{let p=l.enriched.interactivity==="static"?1:0,f=u.enriched.interactivity==="static"?1:0;return p!==f?p-f:p===1&&u.score!==l.score?u.score-l.score:l.domIndex-u.domIndex}),d.map(l=>{var f;let u;if((f=l.formattingRule)!=null&&f.formatSummary){let m=l.formattingRule.formatSummary(l.el,l.enriched,t);m&&(u=m)}let p={...l.enriched};return u&&(p.formattedSummary=u),p})}function CC(e,r){let t=[],n=new Set,o=document.createTreeWalker(r,NodeFilter.SHOW_ELEMENT,null),a=o.currentNode;for(;a&&t.length<e.maxElements;){if(a.nodeType===Node.ELEMENT_NODE){let d=a,l=d.tagName.toLowerCase();if(Zh.has(l)){a=o.nextNode();continue}if(e.excludeSelector)try{if(d.closest(e.excludeSelector)){a=o.nextNode();continue}}catch{}if(e.visibleOnly&&!nx(d)){a=o.nextNode();continue}let u=ox(d,e.maxTextLength),p=u.text.length>0,f=Object.keys(u.attributes).length>0&&!Object.keys(u.attributes).every(m=>m==="role");if(!p&&!f){a=o.nextNode();continue}n.has(u.selector)||(n.add(u.selector),t.push(u))}a=o.nextNode()}let s=[],i=[];for(let d of t)d.interactivity!=="static"?s.push(d):i.push(d);return[...s,...i].slice(0,e.maxElements)}function ax(e={}){var n;let r=uC(e),t=(n=r.root)!=null?n:document.body;return t?r.mode==="simple"?CC(r,t):bC(r,t):[]}var El=100;function sx(e,r={}){var a;if(e.length===0)return"No page elements found.";let t=(a=r.mode)!=null?a:"structured",n=[];if(t==="structured"){let s=e.map(i=>i.formattedSummary).filter(i=>!!i&&i.length>0);s.length>0&&n.push(`Structured summaries:
|
|
150
150
|
${s.map(i=>`- ${i.split(`
|
|
151
151
|
`).join(`
|
|
152
152
|
`)}`).join(`
|
|
@@ -160,7 +160,7 @@ ${s.join(`
|
|
|
160
160
|
${s.join(`
|
|
161
161
|
`)}`)}return n.join(`
|
|
162
162
|
|
|
163
|
-
`)}var ix={name:"@runtypelabs/persona",version:"3.21.
|
|
163
|
+
`)}var ix={name:"@runtypelabs/persona",version:"3.21.3",description:"Themeable, pluggable streaming agent widget for websites, in plain JS with support for voice input and reasoning / tool output.",type:"module",main:"dist/index.cjs",module:"dist/index.js",types:"dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js",require:"./dist/index.cjs"},"./theme-reference":{types:"./dist/theme-reference.d.ts",import:"./dist/theme-reference.js",require:"./dist/theme-reference.cjs"},"./theme-editor":{types:"./dist/theme-editor.d.ts",import:"./dist/theme-editor.js",require:"./dist/theme-editor.cjs"},"./testing":{types:"./dist/testing.d.ts",import:"./dist/testing.js",require:"./dist/testing.cjs"},"./animations/glyph-cycle":{types:"./dist/animations/glyph-cycle.d.ts",import:"./dist/animations/glyph-cycle.js",require:"./dist/animations/glyph-cycle.cjs"},"./animations/wipe":{types:"./dist/animations/wipe.d.ts",import:"./dist/animations/wipe.js",require:"./dist/animations/wipe.cjs"},"./widget.css":"./dist/widget.css"},files:["dist","src"],scripts:{build:"rimraf dist && pnpm run build:styles && pnpm run build:client && pnpm run build:installer && pnpm run build:theme-ref && pnpm run build:theme-editor && pnpm run build:testing && pnpm run build:animations","build:theme-editor":"tsup src/theme-editor.ts --format esm,cjs --dts --out-dir dist --no-splitting","build:testing":"tsup src/testing.ts --format esm,cjs --dts --out-dir dist --no-splitting","build:animations":"tsup src/animations/glyph-cycle.ts src/animations/wipe.ts --format esm,cjs --dts --out-dir dist/animations --no-splitting","build:theme-ref":"tsup src/theme-reference.ts --format esm,cjs --minify --dts","build:styles":`node -e "const fs=require('fs');fs.mkdirSync('dist',{recursive:true});fs.copyFileSync('src/styles/widget.css','dist/widget.css');"`,"build:client":`tsup src/index.ts --format esm,cjs --minify --sourcemap --splitting false --dts --loader ".css=text" && tsup src/index-global.ts --format iife --global-name AgentWidget --minify --sourcemap --splitting false --out-dir dist --loader ".css=text" && node -e "const fs=require('fs');for(const ext of ['.global.js','.global.js.map']){const from='dist/index-global'+ext;if(fs.existsSync(from))fs.renameSync(from,'dist/index'+ext);}"`,"build:installer":"tsup src/install.ts --format iife --global-name SiteAgentInstaller --out-dir dist --minify --sourcemap --no-splitting",lint:"eslint . --ext .ts",typecheck:"tsc --noEmit",test:"vitest","test:ui":"vitest --ui","test:run":"vitest run"},dependencies:{dompurify:"^3.3.3",idiomorph:"^0.7.4",lucide:"^0.552.0",marked:"^12.0.2","partial-json":"^0.1.7",zod:"^3.22.4"},devDependencies:{"@types/node":"^20.12.7","@typescript-eslint/eslint-plugin":"^7.0.0","@typescript-eslint/parser":"^7.0.0","@vitest/ui":"^4.0.9",eslint:"^8.57.0","eslint-config-prettier":"^9.1.0","fake-indexeddb":"^6.2.5",rimraf:"^5.0.5",tsup:"^8.0.1",typescript:"^5.4.5",vitest:"^4.0.9"},engines:{node:">=20.0.0"},author:"Runtype",license:"MIT",keywords:["ai","chat","widget","streaming","typescript","persona","agent"],repository:{type:"git",url:"git+https://github.com/runtypelabs/persona.git",directory:"packages/widget"},bugs:{url:"https://github.com/runtypelabs/persona/issues"},homepage:"https://github.com/runtypelabs/persona/tree/main/packages/widget#readme",publishConfig:{access:"public"}};var ia=ix.version;function lo(e){if(e!==void 0)return typeof e=="string"?e:Array.isArray(e)?`[${e.map(r=>r.toString()).join(", ")}]`:e.toString()}function vC(e){if(e)return{getHeaders:lo(e.getHeaders),onFeedback:lo(e.onFeedback),onCopy:lo(e.onCopy),requestMiddleware:lo(e.requestMiddleware),actionHandlers:lo(e.actionHandlers),actionParsers:lo(e.actionParsers),postprocessMessage:lo(e.postprocessMessage),contextProviders:lo(e.contextProviders),streamParser:lo(e.streamParser)}}var lx=`({ text, message }: any) => {
|
|
164
164
|
const jsonSource = (message as any).rawContent || text || message.content;
|
|
165
165
|
if (!jsonSource || typeof jsonSource !== 'string') return null;
|
|
166
166
|
let cleanJson = jsonSource
|
|
@@ -480,7 +480,7 @@ ${s.join(`
|
|
|
480
480
|
min-height: 300px;
|
|
481
481
|
}
|
|
482
482
|
}
|
|
483
|
-
`;function HC(){if(document.querySelector("style[data-persona-dc-styles]"))return;let e=document.createElement("style");e.setAttribute("data-persona-dc-styles",""),e.textContent=RC,document.head.appendChild(e)}function BC(e,r){let t=e.clientWidth-qp*2-bx,n=e.clientHeight-qp*2-bx;return t<=0||n<=0?1:Math.min(t/r.w,n/r.h,1)}function WC(e,r,t,n,o){e.style.width=`${t.w*n}px`,e.style.height=`${t.h*n}px`,e.style.borderRadius=o==="mobile"?`${32*n}px`:"10px",r.style.width=`${t.w}px`,r.style.height=`${t.h}px`,r.style.transformOrigin="top left",r.style.transform=`scale(${n})`}function Cx(e,r){let{items:t,initialIndex:n=0,initialDevice:o="desktop",initialColorScheme:a="light",showZoomControls:s=!0,showDeviceToggle:i=!0,showColorSchemeToggle:d=!0,onChange:l}=r;if(t.length===0)throw new Error("createDemoCarousel: items array must not be empty");HC();let u=Math.max(0,Math.min(n,t.length-1)),p=o,f=a,m=null,C=1,
|
|
483
|
+
`;function HC(){if(document.querySelector("style[data-persona-dc-styles]"))return;let e=document.createElement("style");e.setAttribute("data-persona-dc-styles",""),e.textContent=RC,document.head.appendChild(e)}function BC(e,r){let t=e.clientWidth-qp*2-bx,n=e.clientHeight-qp*2-bx;return t<=0||n<=0?1:Math.min(t/r.w,n/r.h,1)}function WC(e,r,t,n,o){e.style.width=`${t.w*n}px`,e.style.height=`${t.h*n}px`,e.style.borderRadius=o==="mobile"?`${32*n}px`:"10px",r.style.width=`${t.w}px`,r.style.height=`${t.h}px`,r.style.transformOrigin="top left",r.style.transform=`scale(${n})`}function Cx(e,r){let{items:t,initialIndex:n=0,initialDevice:o="desktop",initialColorScheme:a="light",showZoomControls:s=!0,showDeviceToggle:i=!0,showColorSchemeToggle:d=!0,onChange:l}=r;if(t.length===0)throw new Error("createDemoCarousel: items array must not be empty");HC();let u=Math.max(0,Math.min(n,t.length-1)),p=o,f=a,m=null,C=1,A=!1,k=h("div","persona-dc-root"),T=h("div","persona-dc-toolbar"),S=h("div","persona-dc-toolbar-lead"),E=h("div","persona-dc-toolbar-trail"),w=Zt({icon:"chevron-left",label:"Previous demo",size:14,onClick:()=>Re(-1)}),b=h("div");b.style.position="relative";let y=h("button","persona-dc-title-btn");y.type="button",y.setAttribute("aria-expanded","false"),y.setAttribute("aria-haspopup","listbox");let M=h("span","persona-dc-title-text"),H=h("span","persona-dc-title-chevron"),B=ve("chevron-down",12,"currentColor",2);B&&H.appendChild(B),y.append(M,H);let R=h("div","persona-dc-dropdown");R.setAttribute("role","listbox"),R.style.display="none";let W=!1;function V(){R.innerHTML="";for(let K=0;K<t.length;K++){let j=t[K],Ce=h("button","persona-dc-dropdown-item");Ce.type="button",Ce.setAttribute("role","option"),Ce.setAttribute("aria-current",K===u?"true":"false");let De=h("span");if(De.textContent=j.title,Ce.appendChild(De),j.description){let oe=h("span","persona-dc-dropdown-desc");oe.textContent=j.description,Ce.appendChild(oe)}Ce.addEventListener("click",()=>{ue(),Ye(K)}),R.appendChild(Ce)}}function ne(){W=!W,R.style.display=W?"":"none",y.setAttribute("aria-expanded",W?"true":"false"),W&&V()}function ue(){W&&(W=!1,R.style.display="none",y.setAttribute("aria-expanded","false"))}y.addEventListener("click",K=>{K.stopPropagation(),ne()});let Be=()=>ue();document.addEventListener("click",Be),b.append(y,R);let Ke=Zt({icon:"chevron-right",label:"Next demo",size:14,onClick:()=>Re(1)}),ye=h("span","persona-dc-counter");S.append(w,b,Ke,ye);let me=null;i&&(me=Is({items:[{id:"desktop",icon:"monitor",label:"Desktop"},{id:"mobile",icon:"smartphone",label:"Mobile"}],selectedId:p,onSelect:K=>{p=K,G.dataset.device=p,m=null,J()}}),E.appendChild(me.element));let We=null;if(s){let K=h("div","persona-dc-zoom-controls"),j=Zt({icon:"minus",label:"Zoom out",size:14,onClick:()=>{let oe=m!=null?m:C;m=Math.max(xx,oe-hx),J()}});We=h("span","persona-dc-zoom-level"),We.title="Reset to 100%",We.style.cursor="pointer",We.addEventListener("click",()=>{m=1,J()});let Ce=Zt({icon:"plus",label:"Zoom in",size:14,onClick:()=>{let oe=m!=null?m:C;m=Math.min(yx,oe+hx),J()}}),De=Zt({icon:"maximize",label:"Fit to view",size:14,onClick:()=>{m=null,J()}});K.append(j,We,Ce,De),E.appendChild(K)}if(d){let K=h("div","persona-dc-separator");E.appendChild(K);let j=Is({items:[{id:"light",icon:"sun",label:"Light"},{id:"dark",icon:"moon",label:"Dark"}],selectedId:f,onSelect:Ce=>{f=Ce,G.dataset.colorScheme=f,de()}});E.appendChild(j.element)}let Xe=h("div","persona-dc-separator");E.appendChild(Xe);let Y=Zt({icon:"external-link",label:"Open in new tab",size:14,onClick:()=>{window.open(t[u].url,"_blank")}});E.appendChild(Y),T.append(S,E);let Ee=h("div","persona-dc-stage"),G=h("div","persona-dc-iframe-wrapper");G.dataset.device=p,G.dataset.colorScheme=f;let ce=h("iframe","persona-dc-iframe");ce.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms"),ce.setAttribute("loading","lazy"),ce.title=t[u].title,G.appendChild(ce),Ee.appendChild(G),k.append(T,Ee),e.appendChild(k);function de(){var K;try{let j=(K=ce.contentDocument)==null?void 0:K.body;if(!j)return;f==="dark"?j.classList.add("theme-dark"):j.classList.remove("theme-dark")}catch{}}ce.addEventListener("load",()=>de());function pe(){let K=t[u];M.textContent=K.title,ye.textContent=`${u+1} / ${t.length}`,ce.title=K.title}function Re(K){let j=((u+K)%t.length+t.length)%t.length;Ye(j)}function Ye(K){K<0||K>=t.length||(u=K,ce.src=t[u].url,pe(),l==null||l(u,t[u]))}function J(){var Ce;if(A)return;let K=(Ce=gx[p])!=null?Ce:gx.desktop;C=BC(Ee,K);let j=Math.max(xx,Math.min(yx,m!=null?m:C));WC(G,ce,K,j,p),We&&(We.textContent=`${Math.round(j*100)}%`)}let ie=new ResizeObserver(()=>J());ie.observe(Ee),pe(),ce.src=t[u].url,requestAnimationFrame(()=>J());function Ue(){A||(A=!0,ie.disconnect(),document.removeEventListener("click",Be),k.remove())}return{element:k,goTo:Ye,next:()=>Re(1),prev:()=>Re(-1),getIndex:()=>u,setDevice(K){p=K,G.dataset.device=K,me==null||me.setSelected(K),m=null,J()},setColorScheme(K){f=K,G.dataset.colorScheme=K},setZoom(K){m=K,J()},destroy:Ue}}function wx(){return{name:"@persona/accessibility",version:"1.0.0",transform(e){return{...e,semantic:{...e.semantic,colors:{...e.semantic.colors,interactive:{...e.semantic.colors.interactive,focus:"palette.colors.primary.700",disabled:"palette.colors.gray.300"}}}}},cssVariables:{"--persona-accessibility-focus-ring":"0 0 0 2px var(--persona-semantic-colors-surface, #fff), 0 0 0 4px var(--persona-semantic-colors-interactive-focus, #0f0f0f)"}}}function vx(){return{name:"@persona/animations",version:"1.0.0",transform(e){return{...e,palette:{...e.palette,transitions:{fast:"150ms",normal:"200ms",slow:"300ms",bounce:"500ms cubic-bezier(0.68, -0.55, 0.265, 1.55)"},easings:{easeIn:"cubic-bezier(0.4, 0, 1, 1)",easeOut:"cubic-bezier(0, 0, 0.2, 1)",easeInOut:"cubic-bezier(0.4, 0, 0.2, 1)"}}}},cssVariables:{"--persona-transition-fast":"150ms ease","--persona-transition-normal":"200ms ease","--persona-transition-slow":"300ms ease"}}}function Ax(e){return{name:"@persona/brand",version:"1.0.0",transform(r){var n;let t={...r.palette};return(n=e.colors)!=null&&n.primary&&(t.colors={...t.colors,primary:{50:zn(e.colors.primary,.95),100:zn(e.colors.primary,.9),200:zn(e.colors.primary,.8),300:zn(e.colors.primary,.7),400:zn(e.colors.primary,.6),500:e.colors.primary,600:zn(e.colors.primary,.8),700:zn(e.colors.primary,.7),800:zn(e.colors.primary,.6),900:zn(e.colors.primary,.5),950:zn(e.colors.primary,.45)}}),{...r,palette:t}}}}function Sx(){return{name:"@persona/reduced-motion",version:"1.0.0",transform(e){return{...e,palette:{...e.palette,transitions:{fast:"0ms",normal:"0ms",slow:"0ms",bounce:"0ms"}}}},afterResolve(e){return{...e,"--persona-transition-fast":"0ms","--persona-transition-normal":"0ms","--persona-transition-slow":"0ms"}}}}function Tx(){return{name:"@persona/high-contrast",version:"1.0.0",transform(e){return{...e,semantic:{...e.semantic,colors:{...e.semantic.colors,text:"palette.colors.gray.950",textMuted:"palette.colors.gray.700",border:"palette.colors.gray.900",divider:"palette.colors.gray.900"}}}}}}function zn(e,r){let t=parseInt(e.slice(1,3),16),n=parseInt(e.slice(3,5),16),o=parseInt(e.slice(5,7),16),a=Math.round(t+(255-t)*(1-r)),s=Math.round(n+(255-n)*(1-r)),i=Math.round(o+(255-o)*(1-r));return`#${a.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}function kx(e){return{name:e.name,version:e.version,transform:e.transform||(r=>r),cssVariables:e.cssVariables,afterResolve:e.afterResolve}}var DC={palette:{colors:{primary:{500:"#111827"},accent:{600:"#1d4ed8"},gray:{50:"#ffffff",100:"#f8fafc",200:"#f1f5f9",500:"#6b7280",900:"#000000"}},radius:{sm:"0.75rem",md:"1rem",lg:"1.5rem",launcher:"9999px",button:"9999px"}},semantic:{colors:{primary:"palette.colors.primary.500",textInverse:"palette.colors.gray.50"}}},Ex={components:{panel:{borderRadius:"0",shadow:"none"}}},zp={id:"shop",label:"Shopping Assistant",config:{theme:DC,launcher:{title:"Shopping Assistant",subtitle:"Here to help you find what you need",agentIconText:"\u{1F6CD}\uFE0F",position:"bottom-right",width:mn},copy:{welcomeTitle:"Welcome to our shop!",welcomeSubtitle:"I can help you find products and answer questions",inputPlaceholder:"Ask me anything...",sendButtonLabel:"Send"},suggestionChips:["What can you help me with?","Tell me about your features","How does this work?"]}},Vp={id:"minimal",label:"Minimal",config:{launcher:{enabled:!1,fullHeight:!0},layout:{header:{layout:"minimal",showCloseButton:!1},messages:{layout:"minimal"}},theme:Ex}},jp={id:"fullscreen",label:"Fullscreen Assistant",config:{launcher:{enabled:!1,fullHeight:!0},layout:{header:{layout:"minimal",showCloseButton:!1},contentMaxWidth:"72ch"},theme:Ex}},Gp={shop:zp,minimal:Vp,fullscreen:jp};function Mx(e){return Gp[e]}var OC=`
|
|
484
484
|
@keyframes persona-stream-wipe {
|
|
485
485
|
from { -webkit-mask-position: 100% 0; mask-position: 100% 0; }
|
|
486
486
|
to { -webkit-mask-position: 0% 0; mask-position: 0% 0; }
|