@webority/chat-elements 0.152.0 → 0.154.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat-elements.js +1 -1
- package/dist/chat.global.js +27 -27
- package/dist/web-DU1iwrnX.js +1 -0
- package/dist/web.js +1 -1
- package/package.json +8 -8
- package/dist/web-CEXzR2DU.js +0 -1
package/dist/chat-elements.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as e,D as t,E as n,M as r,O as i,P as a,S as o,T as s,_ as c,a as l,b as u,c as d,d as f,f as p,h as m,j as h,k as g,l as _,m as v,n as y,o as b,p as x,r as S,s as C,v as w,w as T,x as E,y as D}from"./web-CEXzR2DU.js";import{CHAT_HANDOFF_REQUEST_ID as O,buildTranscript as k,createChatClient as ee,createChatSession as te,createConversationList as A,createTurnApi as ne,formatChatDate as j,formatChatDay as re,formatChatValue as ie,formatClipTime as ae,formatFigure as oe,formatFileSize as se,isHandoffTarget as ce,isSafeLinkUrl as le,loaderView as ue,mergeLabels as de,mergeLook as fe,messagePlainText as M,resolveNudge as pe,showsCaptchaNote as N,sniffAudioType as me,toFigureRuns as P,toFigureText as he,transcriptToText as ge,voiceClipBars as _e}from"@webority/chat-core";import{linkTarget as ve,parseInline as ye}from"@webority/markdown-core";import{COPY_FEEDBACK_MS as be,copyTextToClipboard as xe,emptyValueLabel as Se,formatNumber as Ce,glyphNode as we,isImeSafeEnter as Te}from"@webority/ui-elements/helpers";import"@webority/ui-elements/elements/lightbox";import"@webority/ui-elements/elements/markdown";import"@webority/ui-elements/elements/code-block";var Ee=`@webority/chat-elements needs a browser DOM; import @webority/chat-core on the server`;if(typeof HTMLElement>`u`)throw Error(Ee);var De=HTMLElement,F=class extends De{#e=null;#t=null;#n=null;#r=!1;get chatPart(){return this.#e}set chatPart(e){this.#e=e,this.#i()}get message(){return this.#t}set message(e){this.#t=e,this.#i()}get turn(){return this.#n}set turn(e){this.#n=e,this.#i()}get activeTurn(){let e=this.#n;if(e===null)throw Error(`${this.localName} has no turn yet`);return e}connectedCallback(){this.#r=!0,this.#i()}disconnectedCallback(){this.#r=!1,queueMicrotask(()=>{this.isConnected||this.disposePart()})}#i(){this.#r&&this.#e&&this.#t&&this.#n&&this.renderPart(this.#e,this.#t,this.#n)}renderPart(e,t,n){throw Error(`${this.localName} must override renderPart`)}disposePart(){}};function I(e,t){typeof customElements>`u`||customElements.get(e)||customElements.define(e,t)}function L(e,t,n=null,r=null){let i=e.createElement(t);return n&&(i.className=n),r!==null&&(i.textContent=r),i}function Oe(e,t,n){let r=we(t,{size:n});return r===null?null:e.adoptNode(r)}var ke={Confirmed:`actionConfirmed`,Rejected:`actionRejected`,Expired:`actionExpired`,Failed:`actionFailed`},Ae=/^https?:\/\//i,je={strong:`strong`,em:`em`,strike:`s`};function R(e,t=null,n=null){let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r}function Me(e,t){return{id:e,label:t,action:`Send`,target:null,navigateAfterMs:null,icon:null,variant:null}}function Ne(e){return e.type in je}function Pe(e,t){for(let n of t)if(n.type===`text`||n.type===`citation`)e.append(document.createTextNode(n.text));else if(n.type===`link`){if(Ae.test(n.href)){let t=R(`a`);t.href=n.href,t.target=`_blank`,t.rel=`noopener noreferrer`,Pe(t,n.children),e.append(t)}else Pe(e,n.children)}else if(Ne(n)){let t=R(je[n.type]);Pe(t,n.children),e.append(t)}else n.type===`code`&&e.append(R(`code`,null,n.text))}function Fe(e){let t=R(`p`,`wui-chat-action-consent`);return Pe(t,ye(e)),t}function Ie(e){let t=R(`ul`,`wui-chat-action-lines`);for(let n of e)t.append(R(`li`,null,n));return t}function Le(e){let t=R(`dl`,`wui-chat-action-lines`);for(let n of e){let e=R(`div`,`wui-chat-action-line`),r=n.indexOf(`: `);r===-1?e.append(R(`dt`,null,n)):e.append(R(`dt`,null,n.slice(0,r)),R(`dd`,null,n.slice(r+2))),t.append(e)}return t}function Re(e){return typeof e!=`object`||!e||!(`message`in e)?``:typeof e.message==`string`?e.message:``}I(`wui-chat-part-action`,class extends F{_part;_turn;_working;_error;_menuOpen;constructor(){super(),this._part=null,this._turn=null,this._working=null,this._error=null,this._menuOpen=!1}renderPart(e,t,n){this._part?.actionId!==e.actionId&&(this._working=null,this._error=null,this._menuOpen=!1),this._part=e,this._turn=n,this._paint()}_paint(e=null){let t=this._part,n=this._turn;t!==null&&n!==null&&(this.replaceChildren(this._view(t,n)),e===`first`?this.querySelector(`[role="menuitem"]`)?.focus():e===`edit`&&this.querySelector(`.wui-chat-action-edit`)?.focus())}async _run(e){let t=this._part,n=this._turn;if(t===null||n===null)return;let r=t.actionId;this._working=e,this._error=null,this._paint();try{e===`confirm`?await n.confirmAction(r):await n.rejectAction(r),this._working=null}catch(e){if(this._part?.actionId!==r)return;this._working=null,this._error=Re(e)||n.labels.actionFailed,this._paint()}}_view(e,t){let n=t.labels,r=e.state===`Pending`,i=t.features.LeadRecap===!0&&e.actionKind===`ChatLeadCapture`,a=i&&(e.editFields?.length??0)>0,o=R(`div`,`wui-chat-action wui-chat-action--${e.state.toLowerCase()}`);if(o.append(R(`strong`,`wui-chat-action-title`,e.title)),e.lines.length>0&&o.append(i?Le(e.lines):Ie(e.lines)),i&&e.consentText&&o.append(Fe(e.consentText)),e.note&&o.append(R(`p`,`wui-chat-action-note`,e.note)),r||o.append(this._status(e,n)),(r||a)&&o.append(this._buttons(e,n,i,r,a)),e.editFields&&a&&this._menuOpen&&o.append(this._menu(e.editFields,n,t)),this._error){let e=R(`p`,`wui-chat-action-error`,this._error);e.setAttribute(`role`,`alert`),o.append(e)}return o}_status(e,t){let n=R(`p`,`wui-chat-action-status wui-chat-action-status--${e.state.toLowerCase()}`);if(e.state===`Repeat`)n.textContent=e.decidedDateTimeUtc?t.actionRepeat(j(e.decidedDateTimeUtc)):t.actionDone;else if(e.state===`Done`){if(n.append(t.actionDone),e.decidedDateTimeUtc){let t=R(`time`,null,j(e.decidedDateTimeUtc));t.dateTime=e.decidedDateTimeUtc,n.append(` `,t)}}else{let r=ke[e.state];n.textContent=r===void 0?``:t[r]}return n}_buttons(e,t,n,r,i){let a=R(`div`,`wui-chat-action-buttons`),o=this._working;if(r){let r=n&&e.confirmLabel||t.actionConfirm,i=n&&e.rejectLabel||t.actionDismiss,s=R(`button`,`btn btn-primary btn-sm`,o===`confirm`?t.actionWorking:r);s.type=`button`,s.disabled=o!==null,s.addEventListener(`click`,()=>this._run(`confirm`));let c=R(`button`,`btn btn-soft-primary btn-sm`,i);c.type=`button`,c.disabled=o!==null,c.addEventListener(`click`,()=>this._run(`dismiss`)),a.append(s,c)}if(i){let e=R(`button`,`btn btn-soft-primary btn-sm wui-chat-action-edit`,t.editSomething);e.type=`button`,e.setAttribute(`aria-haspopup`,`menu`),e.setAttribute(`aria-expanded`,String(this._menuOpen)),e.disabled=!r||o!==null,e.addEventListener(`click`,()=>{this._menuOpen=!this._menuOpen,this._paint(this._menuOpen?`first`:`edit`)}),a.append(e)}return a}_menu(e,t,n){let r=R(`ul`,`list-group wui-chat-action-menu`);r.setAttribute(`role`,`menu`),r.setAttribute(`aria-label`,t.editSomething),r.addEventListener(`keydown`,e=>this._onMenuKey(e,r));for(let t of e){let e=R(`li`);e.setAttribute(`role`,`none`);let i=R(`button`,`list-group-item list-group-item-action wui-chat-action-menu-item`,t.label);i.type=`button`,i.setAttribute(`role`,`menuitem`),i.addEventListener(`click`,()=>{this._menuOpen=!1,n.chooseQuickReply(Me(`lead.edit:${t.id}`,t.label)),this._paint(`edit`)}),e.append(i),r.append(e)}return r}_onMenuKey(e,t){if(e.key===`Escape`){e.preventDefault(),this._menuOpen=!1,this._paint(`edit`);return}let n=[...t.querySelectorAll(`[role="menuitem"]`)],r=document.activeElement,i=r instanceof HTMLElement?n.indexOf(r):-1,a=n.length-1,o=(/* @__PURE__ */ new Map([[`ArrowDown`,i<a?i+1:0],[`ArrowUp`,i>0?i-1:a],[`Home`,0],[`End`,a]])).get(e.key);o!==void 0&&(e.preventDefault(),n[o]?.focus())}});var ze=null;async function Be(){await import(`@webority/ui-elements/chart`),await customElements.whenDefined(`wui-chart`)}async function Ve(){return ze??=Be().catch(e=>{throw ze=null,e}),ze}var He={sub:`wui-chat-sub`,sup:`wui-chat-sup`};function z(e,t){let n=e.ownerDocument??document;for(let r of t)if(r.kind===`sub`||r.kind===`sup`){let t=n.createElement(r.kind);t.className=He[r.kind],t.textContent=r.text,e.append(t)}else e.append(n.createTextNode(r.text))}function B(e,t){e.replaceChildren(),z(e,P(String(t??``)))}function V(e){return he(String(e??``))}function Ue(e){return oe(e)}var We=8,Ge=8,Ke={Bar:`column`,Line:`line`,Donut:`donut`};function qe(e,t){return e===`Bar`&&t>4?300:240}function Je(e,t){let n=e.chartType===`Donut`,r=n?e.series.slice(0,1):e.series.slice(0,We),i=r.map((e,n)=>({key:`s${n}`,label:V(e.name)||t.chart})),a=Object.fromEntries(i.map(e=>[e.key,null])),o=/* @__PURE__ */ new Map;r.forEach((e,t)=>{for(let n of e.points){let e=String(n.label),r=o.get(e);r===void 0&&(r={label:V(e),...a},o.set(e,r)),r[`s${t}`]=n.value}});let s=[...o.values()],c={type:Ke[e.chartType],title:V(e.title)||t.chart,x:{key:`label`,kind:`category`},series:i,data:s,height:qe(e.chartType,s.length)};return e.chartType===`Bar`&&s.length<=Ge&&(c.x.labelFit=`all`,c.valueLabels=!0),!n&&e.unit&&(c.y={label:V(e.unit)}),s.length===0&&(c.state=`empty`,c.emptyText=t.chartEmpty),c}I(`wui-chat-part-chart`,class extends F{#e=null;#t=0;#n=null;#r=null;#i=null;#a=null;renderPart(e,t,n){let r=JSON.stringify(e);if(r===this.#e)return;this.#e=r,this.#t+=1;let i=this.#t,a=this.ownerDocument??document,o=this.#o(a);if(this.#r?.remove(),this.#r=null,e.title){let t=L(a,`figcaption`,`wui-chat-chart-title`);B(t,e.title),o.figure.prepend(t),this.#r=t}let s=this.#i;if(s!==null){let t=Je(e,n.labels);Object.assign(s,{spec:t}),this.#s(o,s,t.state!==`empty`,n.labels)}else Ve().then(()=>{if(i!==this.#t||!this.isConnected)return;let t=Je(e,n.labels),r=a.createElement(`wui-chart`);Object.assign(r,{spec:t}),this.#i=r,o.body.replaceChildren(r),this.#s(o,r,t.state!==`empty`,n.labels)},()=>{i===this.#t&&this.isConnected&&this.#l(o.body,n.labels)})}disposePart(){this.#t+=1,this.#e=null}#o(e){if(this.#n===null){let t=L(e,`figure`,`wui-chat-chart`),n=L(e,`div`,`wui-chat-chart-body`);t.append(n),this.replaceChildren(t),this.#n={figure:t,body:n}}return this.#n}#s(e,t,n,r){if(!n){this.#a?.remove(),this.#a=null;return}if(!this.#a){let n=L(this.ownerDocument??document,`button`,`btn btn-link btn-sm wui-chat-chart-toggle`);n.type=`button`,n.addEventListener(`click`,()=>this.#c(e,t)),e.figure.append(n),this.#a=n}let i=t.getAttribute(`view`)===`table`;this.#a.setAttribute(`aria-pressed`,String(i)),this.#a.textContent=i?r.chartShowChart:r.chartShowTable}#c(e,t){let n=this.activeTurn,r=t.getAttribute(`view`)!==`table`;t.setAttribute(`view`,r?`table`:`chart`),this.#s(e,t,!0,n.labels)}#l(e,t){let n=L(this.ownerDocument??document,`p`,`wui-chat-chart-error`,t.chartLoadFailed);n.setAttribute(`role`,`status`),e.replaceChildren(n),this.#a?.remove(),this.#a=null}});var Ye={Positive:`wui-metric-tone-success`,Caution:`wui-metric-tone-warning`,Negative:`wui-metric-tone-danger`},Xe=/* @__PURE__ */ new Set([`Positive`,`Caution`,`Negative`]),Ze=.001;function Qe(e,t,n){let r=Ye[t.status],i=L(e,`div`,r?`wui-metric ${r}`:`wui-metric`);i.dataset.status=t.status;let a=L(e,`div`,`wui-metric-label`);B(a,t.label);let o=L(e,`div`,`wui-metric-value`);if(z(o,t.value!==0&&Math.abs(t.value)<Ze?Ue(t.value):[{kind:`text`,text:Ce(t.value)}]),t.unit){let n=L(e,`span`,`wui-chat-figure-unit`);B(n,t.unit),n.prepend(` `),o.append(n)}return Xe.has(t.status)&&o.append(L(e,`span`,`visually-hidden`,n.figureStatus(t.status))),i.append(a,o),i}I(`wui-chat-part-figures`,class extends F{#e=null;renderPart(e,t,n){let r=JSON.stringify(e);if(r===this.#e)return;if(this.#e=r,!e.figures||e.figures.length===0){this.replaceChildren();return}let i=this.ownerDocument??document,a=L(i,`div`,`wui-chat-figures`),o=L(i,`div`,`wui-metric-strip wui-metric-strip-sm wui-chat-figures-strip`);o.setAttribute(`role`,`group`),o.setAttribute(`aria-label`,n.labels.figures);for(let t of e.figures)o.append(Qe(i,t,n.labels));a.append(o),this.replaceChildren(a)}}),I(`wui-chat-part-file`,class extends F{renderPart(e,t,n){let r=n.openAttachment,i=typeof r==`function`,a=document.createElement(i?`button`:`span`);a.className=`wui-chat-file-chip`,i&&(a.setAttribute(`type`,`button`),a.setAttribute(`aria-label`,n.labels.fileOpen(e.fileName)),a.addEventListener(`click`,()=>r(e)));let o=Oe(document,`document-text`,16),s=document.createElement(`span`);s.className=`wui-chat-file-name`,s.textContent=e.fileName;let c=document.createElement(`span`);c.className=`wui-chat-file-size`,c.textContent=se(e.length),a.append(...[o,s,c].filter(e=>e!==null));let l=document.createElement(`div`);l.className=`wui-chat-file`,l.append(a),this.replaceChildren(l)}});var $e={Open:`info`,InProgress:`info`,WaitingOnCustomer:`warning`,Resolved:`success`,Closed:`neutral`,Cancelled:`neutral`},et=/^\/[/\\]/,tt=/^https?:\/\//i,nt=/[\t\r\n]/g;function rt(e){return typeof e==`string`&&e.trim()!==``}function it(e){return e.replace(nt,``)}function at(e){if(typeof e!=`string`)return!1;let t=it(e);return t.startsWith(`/`)?!et.test(t):tt.test(t)}function ot(e){if(typeof e!=`string`)return`?`;let t=e.split(/\s+/).filter(Boolean).slice(0,2).map(e=>([...e][0]??``).toUpperCase()).join(``);return t===``?`?`:t}function st(e,n){let r=e?.displayName,i=ot(rt(r)?r:n),a=t(`span`,`wui-chat-avatar`,{"aria-hidden":`true`}),o=e?.avatarUrl,s=typeof o==`string`?it(o):null;if(at(s)){let e=t(`img`,null,{alt:``,src:s,loading:`lazy`});e.addEventListener(`error`,()=>{a.textContent=i}),a.append(e)}else a.textContent=i;return a}function ct(e,n){let r=t(`div`,`wui-chat-agent-head`),i=t(`span`,`wui-chat-agent-name`),a=e?.displayName;i.textContent=rt(a)?a:n.agent;let o=t(`span`,`wui-chat-agent-role wui-chat-agent-tag`);return o.textContent=n.agent,r.append(st(e,n.agent),i,o),r}function lt(e,n){let r=e.displayName,i=t(`li`,`wui-chat-message wui-chat-message--agent wui-chat-message--typing`),a=t(`span`,`wui-chat-typing`);for(let e=0;e<3;e+=1)a.append(t(`span`,`wui-chat-typing-dot`,{"aria-hidden":`true`}));let o=t(`span`,`visually-hidden`);return o.textContent=n.agentTyping(rt(r)?r:n.agent),i.append(ct({kind:`Agent`,displayName:r,avatarUrl:null},n),a,o),i}function ut(e){return typeof e==`string`&&i($e,e)?$e[e]??null:null}function dt(e,t){return ut(e)===null?``:t.ticketStatus(e)}var ft=/* @__PURE__ */ new Set([`Requested`,`Waiting`]),pt=/* @__PURE__ */ new Set([`Requested`,`Waiting`,`Joined`]),mt=pt;function ht(e,t){let n=e?.displayName;return typeof n==`string`&&n.trim()!==``?n:t.handoffAgentFallback}function gt(){let e=t(`div`,`wui-chat-handoff-pulses`);for(let n=0;n<3;n+=1)e.append(t(`span`,`wui-chat-handoff-pulse`,{"aria-hidden":`true`}));return e}function H(e,n,r){let i=t(e,n);return i.textContent=r,i}function _t(e,n){let r=t(`div`,`wui-chat-handoff-body`);return r.append(H(`strong`,`wui-chat-handoff-title`,e),H(`p`,`wui-chat-handoff-text`,n)),r}function vt(e,n){if(typeof e.queuePosition!=`number`){let e=t(`span`,`wui-chat-system-line-stack`);return e.append(H(`p`,`wui-chat-handoff-text`,n.handoffWaiting),H(`p`,`wui-chat-handoff-text`,n.handoffQueuedText)),[gt(),e]}let r=t(`span`,`wui-chat-handoff-position`,{"aria-hidden":`true`});return r.textContent=String(e.queuePosition),[r,_t(n.handoffQueued(e.queuePosition),n.handoffQueuedText)]}function yt(e,n){let r=ht(e.agent,n),i=t(`span`,`wui-chat-handoff-agent`);return i.append(st(e.agent,n.handoffAgentFallback),t(`span`,`wui-chat-handoff-online`,{"aria-hidden":`true`})),[i,_t(n.handoffJoined(r),n.handoffJoinedText(r))]}function bt(e,t){switch(e.state){case`Requested`:return[gt(),H(`p`,`wui-chat-handoff-text`,t.handoffRequested)];case`Waiting`:return vt(e,t);case`Joined`:return yt(e,t);case`Left`:return[_t(t.handoffLeft(ht(e.agent,t)),t.handoffLeftText)];case`Ended`:return[_t(t.handoffEnded,t.handoffEndedText)];default:return null}}I(`wui-chat-part-handoff`,class extends F{_signature;constructor(){super(),this._signature=null}renderPart(e,n,r){let i=r.isLast,a=r.handoffSettled===!0&&ft.has(e.state),o=JSON.stringify([e.state,e.queuePosition,e.agent,i,r.features.HumanHandoff,r.busy,a]);if(o===this._signature)return;if(this._signature=o,a){this.replaceChildren();return}let s=bt(e,r.labels);if(s===null){this.replaceChildren();return}let c=t(`div`,`wui-chat-handoff wui-chat-handoff--${e.state.toLowerCase()}`);if(i&&ft.has(e.state)&&c.classList.add(`wui-chat-handoff--live`),i&&pt.has(e.state)&&c.setAttribute(`role`,`status`),mt.has(e.state)){c.classList.add(`wui-chat-system-line`);let e=t(`span`,`wui-chat-system-line-content`);e.append(...s),c.append(e)}else c.append(...s);this.replaceChildren(c)}}),I(`wui-chat-part-image`,class extends F{#e=null;#t=0;#n=null;renderPart(e,t,n){if(e.attachmentId===this.#e)return;this.#e=e.attachmentId;let r=this.ownerDocument??document,i=L(r,`figure`,`wui-chat-image`),a=L(r,`div`,`wui-chat-image-frame`);this.#n=a;let{width:o,height:s}=e;o!==null&&s!==null&&Number.isFinite(o)&&Number.isFinite(s)&&o>0&&s>0&&(a.style.aspectRatio=`${o} / ${s}`),i.append(a),this.replaceChildren(i),this.#r(e,n)}disposePart(){this.#t+=1,this.#e=null}#r(e,t){this.#t+=1;let n=this.#t,r=this.ownerDocument??document,i=this.#n;if(i===null)return;let a=L(r,`div`,`wui-chat-image-skeleton`);a.setAttribute(`aria-hidden`,`true`);let o=L(r,`span`,`visually-hidden`,t.labels.imageLoading);o.setAttribute(`role`,`status`),i.replaceChildren(a,o),typeof t.loadAttachmentUrl==`function`?t.loadAttachmentUrl(e.attachmentId).then(r=>{n===this.#t&&this.isConnected&&this.#i(r,e,t)},()=>{n===this.#t&&this.isConnected&&this.#a(e,t)}):this.#a(e,t)}#i(e,t,n){let r=this.#n;if(r===null)return;let i=this.ownerDocument??document,a=V(t.alt),o=i.createElement(`wui-lightbox`);o.setAttribute(`label`,n.labels.imageViewer),o.setAttribute(`layout`,`single`);let s=L(i,`a`,`wui-lightbox-item`);s.setAttribute(`href`,e),s.dataset.caption=a,s.dataset.name=a;let c=i.createElement(`img`);c.src=e,c.alt=a,c.decoding=`async`,s.append(c),o.append(s),r.replaceChildren(o)}#a(e,t){let n=this.#n;if(n===null)return;let r=this.ownerDocument??document,i=L(r,`p`,`wui-chat-image-error`,t.labels.imageFailed);i.setAttribute(`role`,`status`);let a=L(r,`button`,`btn btn-soft-primary btn-sm`,t.labels.retry);a.type=`button`,a.addEventListener(`click`,()=>this.#r(e,t)),n.replaceChildren(i,a)}});var xt={Email:{type:`email`,autocomplete:`email`},Phone:{type:`tel`,autocomplete:`tel`},Name:{type:`text`,autocomplete:`name`},Company:{type:`text`,autocomplete:`organization`},Text:{type:`text`,autocomplete:null},LongText:{type:`text`,autocomplete:null}},St=[`Open`,`Answered`,`Skipped`,`Expired`],Ct=0;function U(e){return Ct+=1,`${e}-${Ct}`}function W(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r}function G(){let e=W(`p`,`wui-chat-field-error`);return e.id=U(`wui-chat-field-error`),e.setAttribute(`role`,`alert`),e.hidden=!0,e}function K(e,t){return e.required?[]:[W(`span`,`wui-chat-field-hint`,t.inputOptional)]}function wt(e,t,n){let r=U(`wui-chat-field`),i=xt[t],a=t===`LongText`&&!e.secret,o;if(a){let e=W(`textarea`,`form-control wui-chat-input-control`);e.rows=3,o=e}else{let t=W(`input`,`form-control wui-chat-input-control`);t.type=e.secret?`password`:i.type,e.secret?t.autocomplete=`off`:i.autocomplete&&(t.autocomplete=i.autocomplete),o=t}o.id=r,o.name=e.key,e.placeholder!=null&&(o.placeholder=e.placeholder),e.maxLength!=null&&(o.maxLength=e.maxLength),e.required&&o.setAttribute(`aria-required`,`true`);let s=W(`label`,`form-label`,e.label);s.htmlFor=r;let c=G();o.setAttribute(`aria-describedby`,c.id);let l=W(`div`,`wui-chat-field`);return l.dataset.key=e.key,l.append(s,...K(e,n),o,c),{field:e,element:l,controls:[o],focus:o,invalid:o,error:c,control:o,read:()=>e.secret?o.value:o.value.trim()}}function Tt(e,t,n,r,i){let a=e.control,o=W(`button`,`btn btn-soft-primary`,n.inputSendCode);o.type=`button`,o.dataset.wui=`AppButton`;let s=W(`p`,`wui-chat-field-hint`);s.setAttribute(`aria-live`,`polite`);let c=U(`wui-chat-field`),l=W(`label`,`form-label`,n.inputEnterCode);l.htmlFor=c,l.hidden=!0;let u=W(`input`,`form-control wui-chat-input-control`);return u.type=`text`,u.id=c,u.inputMode=`numeric`,u.autocomplete=`one-time-code`,u.hidden=!0,o.addEventListener(`click`,async()=>{o.disabled=!0;try{await r.sendOtp(i,{fieldKey:t.key,value:a.value.trim()}),s.textContent=n.inputCodeSent,l.hidden=!1,u.hidden=!1}catch{s.textContent=n.inputCodeFailed}finally{o.disabled=!1}}),e.element.insertBefore(o,e.error),e.element.insertBefore(s,e.error),e.element.insertBefore(l,e.error),e.element.insertBefore(u,e.error),{...e,controls:[...e.controls,o,u],codeRead:()=>u.value.trim()}}function Et(e,t){let n=U(`wui-chat-field-label`),r=W(`span`,`form-label`,e.label);r.id=n;let i=W(`div`);i.setAttribute(`role`,`radiogroup`),i.setAttribute(`aria-labelledby`,n);let a=G();i.setAttribute(`aria-describedby`,a.id);let o=[];for(let t of e.options??[]){let n=W(`div`,`form-check`),r=W(`input`,`form-check-input`);r.type=`radio`,r.name=e.key,r.value=t.id,r.id=U(`wui-chat-option`);let a=W(`label`,`form-check-label`,t.label);a.htmlFor=r.id,n.append(r,a),i.append(n),o.push(r)}o.length===0&&(i.tabIndex=-1);let s=W(`div`,`wui-chat-field`);return s.dataset.key=e.key,s.append(r,...K(e,t),i,a),{field:e,element:s,controls:o,focus:o[0]??i,invalid:i,error:a,read:()=>o.find(e=>e.checked)?.value??``}}function Dt(e,t){let n=U(`wui-chat-field-label`),r=W(`span`,`form-label`,e.label);r.id=n;let i=W(`div`,`wui-chat-input-choices`);i.setAttribute(`role`,`group`),i.setAttribute(`aria-labelledby`,n);let a=G();i.setAttribute(`aria-describedby`,a.id);let o=[];for(let t of e.options??[]){let n=W(`div`,`form-check`),r=W(`input`,`form-check-input`);r.type=`checkbox`,r.name=e.key,r.value=t.id,r.id=U(`wui-chat-option`);let a=W(`label`,`form-check-label`,t.label);a.htmlFor=r.id,n.append(r,a),i.append(n),o.push(r)}o.length===0&&(i.tabIndex=-1);let s=W(`div`,`wui-chat-field`);return s.dataset.key=e.key,s.append(r,...K(e,t),i,a),{field:e,element:s,controls:o,focus:o[0]??i,invalid:i,error:a,read:()=>JSON.stringify(o.filter(e=>e.checked).map(e=>e.value))}}function Ot(e,t){let n=U(`wui-chat-field-label`),r=W(`span`,`form-label`,e.label);r.id=n;let i=W(`div`,`wui-chat-input-slots`);i.setAttribute(`role`,`radiogroup`),i.setAttribute(`aria-labelledby`,n);let a=G();i.setAttribute(`aria-describedby`,a.id);let o=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`}),s=[];for(let t of e.slots??[]){let n=W(`input`,`wui-chat-input-slot-radio`);n.type=`radio`,n.name=e.key,n.value=t.id,n.id=U(`wui-chat-slot`);let r=W(`label`,`btn btn-soft-primary wui-chat-input-slot`,o.format(new Date(t.startDateTimeUtc)));r.htmlFor=n.id,i.append(n,r),s.push(n)}s.length===0&&(i.tabIndex=-1);let c=W(`div`,`wui-chat-field`);return c.dataset.key=e.key,c.append(r,...K(e,t),i,a),{field:e,element:c,controls:s,focus:s[0]??i,invalid:i,error:a,read:()=>s.find(e=>e.checked)?.value??``}}function kt(e,t,n){let r=U(`wui-chat-field-label`),i=W(`span`,`form-label`,e.label);i.id=r;let a=G(),o=W(`input`);o.type=`file`,o.name=e.key,o.id=U(`wui-chat-field`),o.hidden=!0,e.accept?.length&&(o.accept=e.accept.join(`,`));let s=W(`button`,`btn btn-soft-primary`,t.inputChooseFile);s.type=`button`,s.dataset.wui=`AppButton`,s.setAttribute(`aria-describedby`,a.id),s.addEventListener(`click`,()=>o.click());let c=W(`span`,`wui-chat-input-file-status`);c.setAttribute(`aria-live`,`polite`);let l=W(`button`,`btn btn-link-primary`);l.type=`button`,l.dataset.wui=`AppButton`,l.hidden=!0;let u=W(`div`,`wui-chat-input-file`);u.setAttribute(`role`,`group`),u.setAttribute(`aria-labelledby`,r),u.append(s,c,l,o);let d=`empty`,f=``,p=``,m=0,h=()=>{c.textContent=d===`uploading`?`${t.attachmentUploading} ${f}`:f,l.hidden=f===``,l.textContent=f===``?``:t.inputRemoveFile(f);let e=d===`failed`;a.textContent=e?t.attachmentFailed:``,a.hidden=!e,e?u.setAttribute(`aria-invalid`,`true`):u.removeAttribute(`aria-invalid`)},g=async e=>{m+=1;let t=m;d=`uploading`,f=e.name,p=``,h();try{let r=await n.uploadInputFile(e);if(t!==m)return;p=r,d=`ready`}catch{if(t!==m)return;d=`failed`}h()};o.addEventListener(`change`,()=>{let e=o.files?.[0];e&&g(e)}),l.addEventListener(`click`,()=>{m+=1,d=`empty`,f=``,p=``,o.value=``,h()}),h();let _=W(`div`,`wui-chat-field`);return _.dataset.key=e.key,_.append(i,...K(e,t),u,a),{field:e,element:_,controls:[s,l,o],focus:s,invalid:u,error:a,read:()=>d===`ready`?p:``,uploadProblem:()=>d===`uploading`?t.attachmentUploading:d===`failed`?t.attachmentFailed:null}}function At(e){let t=W(`input`,`form-check-input`);t.type=`checkbox`,t.name=e.key,t.id=U(`wui-chat-field`);let n=W(`label`,`form-check-label`,e.consentText||e.label);n.htmlFor=t.id;let r=G();t.setAttribute(`aria-describedby`,r.id);let i=W(`div`,`form-check`);i.append(t,n);let a=W(`div`,`wui-chat-field`);return a.dataset.key=e.key,a.append(i,r),{field:e,element:a,controls:[t],focus:t,invalid:t,error:r,read:()=>t.checked?`true`:`false`}}function jt(e,t,n,r){if(e.type===`Choice`)return Et(e,t);if(e.type===`MultiChoice`)return Dt(e,t);if(e.type===`TimeSlot`)return Ot(e,t);if(e.type===`File`)return kt(e,t,n);if(e.type===`Consent`)return At(e);let i=wt(e,e.type,t);return e.verify===`Otp`?Tt(i,e,t,n,r):i}function Mt(e,t,n){let r=e.uploadProblem?.();if(r)return r;let{field:i}=e;return i.required?i.type===`Consent`?t===`true`?null:n.inputConsentRequired:i.type===`MultiChoice`?t===`[]`?n.inputRequired:null:t===``?n.inputRequired:null:null}function Nt(e,t){return e.state===`Answered`?W(`p`,`wui-chat-input-summary`,e.answeredSummary||t.inputAnswered):W(`p`,`wui-chat-input-summary`,e.state===`Skipped`?t.inputSkipped:t.inputExpired)}I(`wui-chat-part-input-request`,class extends F{_signature;_generation;constructor(){super(),this._signature=null,this._generation=0}renderPart(e,t,n){for(let t of St)this.classList.toggle(`wui-chat-input-request--${t.toLowerCase()}`,e.state===t);let r=JSON.stringify([e.requestId,e.state,e.answeredSummary,e.fields]);r!==this._signature&&(this._signature=r,this._generation+=1,this.replaceChildren(this._content(e,n)))}_content(e,t){return e.state===`Open`?this._form(e,this._generation):Nt(e,t.labels)}_form(e,t){let n=this.activeTurn,r=n.labels,i=n.features,a=W(`form`,`wui-chat-input-form`);a.noValidate=!0,a.setAttribute(`aria-label`,e.title||e.submitLabel),e.title&&a.append(W(`h3`,`wui-chat-input-title`,e.title));let o=e.fields.map(t=>jt(t,r,n,e.requestId));for(let e of o)a.append(e.element);let s=W(`p`,`wui-chat-input-error`);s.setAttribute(`role`,`status`),s.hidden=!0,a.append(s);let c=W(`button`,`btn btn-primary`,e.submitLabel);c.type=`submit`,c.dataset.wui=`AppButton`;let l=W(`div`,`d-flex flex-wrap gap-2`);l.append(c);let u=[c];if(i.LeadShortcuts&&e.fields.length===1&&!e.fields[0]?.required){let t=W(`button`,`btn btn-soft-primary`,r.skip);t.type=`button`,t.dataset.wui=`AppButton`,t.addEventListener(`click`,()=>this.activeTurn.skipInput(e.requestId)),l.append(t),u.push(t)}if(i.LeadShortcuts&&e.cancellable){let e=W(`button`,`btn btn-link-primary`,r.cancel);e.type=`button`,e.dataset.wui=`AppButton`,e.addEventListener(`click`,()=>this.activeTurn.cancelLead()),l.append(e),u.push(e)}a.append(l),e.allowTyped&&a.append(W(`p`,`wui-chat-input-typed`,r.typeAnswer));let d=!1,f=t=>{for(let e of o)for(let n of e.controls)n.disabled=t;for(let e of u)e.disabled=t;c.textContent=t?r.inputSubmitting:e.submitLabel},p=()=>{for(let e of o)e.error.hidden=!0,e.error.textContent=``,e.invalid.removeAttribute(`aria-invalid`);s.hidden=!0,s.textContent=``},m=(e,t)=>{e.error.textContent=t,e.error.hidden=!1,e.invalid.setAttribute(`aria-invalid`,`true`)};return a.addEventListener(`submit`,async n=>{if(n.preventDefault(),d)return;p();let i={},a={},l=[];for(let e of o){let t=e.read();i[e.field.key]=t,e.codeRead&&(a[e.field.key]=e.codeRead());let n=Mt(e,t,r);n&&l.push([e,n])}let[u]=l;if(u){for(let[e,t]of l)m(e,t);u[0].focus.focus();return}d=!0,f(!0);let h;try{h=await this.activeTurn.answerInput(e.requestId,i,Object.keys(a).length>0?a:null)}catch{h={ok:!1,errors:{},message:r.errorGeneric}}if(t!==this._generation||h.ok)return;d=!1;let g=null;for(let e of o){let t=h.errors?.[e.field.key];t&&(m(e,t),g??=e)}h.message!=null&&(s.textContent=h.message,s.hidden=!1),f(!1),g?g.focus.focus():o[0]?o[0].focus.focus():c.focus()}),a}});var Pt={ActionLimitReached:`warning`,ConversationTooLong:`warning`,AssistantUnavailable:`danger`},Ft={info:`info`,warning:`alert-triangle`,danger:`alert-circle`};I(`wui-chat-part-notice`,class extends F{renderPart(e){let t=this.ownerDocument??document,n=Pt[e.code]??`info`,r=L(t,`div`,`wui-chat-notice wui-chat-notice--${n}`);r.setAttribute(`role`,n===`danger`?`alert`:`status`);let i=L(t,`span`,`wui-chat-notice-icon`);i.setAttribute(`aria-hidden`,`true`);let a=Oe(t,Ft[n],16);a&&i.append(a);let o=L(t,`div`,`wui-chat-notice-body`);o.append(L(t,`span`,`wui-chat-notice-text`,e.text));let s=e.action;if(s){let e=L(t,`button`,`wui-chat-notice-action`,s.label);e.type=`button`,e.addEventListener(`click`,()=>s.run()),o.append(e)}r.append(i,o),this.replaceChildren(r)}});function It(e){switch(e){case`Primary`:return`wui-chat-quick-reply--primary`;case`Cta`:return`wui-chat-quick-reply--cta`;case`Default`:case null:return``}}I(`wui-chat-part-quick-replies`,class extends F{#e=null;renderPart(e,t,n){let r=n.features.SuggestedReplies===!0&&n.isLast===!0&&n.busy===!1&&e.replies.length>0,i=typeof n.openTarget==`function`,a=typeof n.beginHandoff==`function`,o=n.handoffPause===!0,s=JSON.stringify([r,e.replies,e.placement,n.labels.quickReplies,n.labels.handoffMoment,i,a,o,n.handoffHosts??null,n.features.LinkHandoff===!0]);if(s===this.#e)return;this.#e=s;let c=this.querySelector(`:scope > .wui-chat-quick-replies:not(.wui-chat-quick-replies--leaving)`);if(!r&&c){this.#t(c);return}if(this.replaceChildren(),!r)return;let l=this.ownerDocument,u=e.placement===`Composer`,d=L(l,`div`,u?`wui-chat-quick-replies wui-chat-quick-replies--composer`:`wui-chat-quick-replies`);d.setAttribute(`role`,`group`),d.setAttribute(`aria-label`,n.labels.quickReplies);let f=u?null:e.replies.find(e=>e.id===O&&e.action===`Send`),p=0;f&&(d.classList.add(`wui-chat-quick-replies--offer`),d.append(this.#n(l,f,n)),p+=1);for(let t of e.replies){if(t===f||t.action===`Open`&&(!t.target||!i))continue;let e=null;if(t.action===`Navigate`){if(n.features.LinkHandoff!==!0)continue;if(ce(t.target,n.handoffHosts))e=t.target;else{let r=t.target===null?null:n.resolveLink?.(t.target);e=typeof r==`string`&&r!==``?r:null}if(e===null){d.append(L(l,`span`,null,t.label));continue}if(!a)continue}d.append(this.#r(l,t,p,n,f?`wui-chat-quick-reply--quiet`:``,e)),p+=1}if(o){let e=L(l,`span`,`visually-hidden`,n.labels.handoffMoment);e.setAttribute(`role`,`status`),d.append(e)}d.childElementCount>0&&this.append(d)}#t(e){e.classList.add(`wui-chat-quick-replies--leaving`);let t=this.ownerDocument.defaultView,n=Number.parseFloat(t?t.getComputedStyle(e).animationDuration:``)*1e3;t===null||!(n>0)?e.remove():t.setTimeout(()=>e.remove(),n)}#n(e,t,n){let r=L(e,`div`,`wui-chat-offer`);return r.style.setProperty(`--wui-chat-i`,`0`),r.append(L(e,`div`,`wui-chat-offer-title`,t.label)),r.append(this.#r(e,{...t,variant:`Primary`},0,n,`wui-chat-offer-action`)),r}#r(e,t,n,r,i=``,a=null){let o=e.createElement(`button`);o.type=`button`,o.className=[`wui-chat-quick-reply`,It(t.variant),i].filter(Boolean).join(` `),o.style.setProperty(`--wui-chat-i`,String(n));let s=t.action===`Navigate`,c=s&&r.handoffPause===!0;if(o.disabled=c,t.icon){let n=Oe(e,t.icon,16);if(n){let t=L(e,`span`,`wui-chat-quick-reply-icon`);t.setAttribute(`aria-hidden`,`true`),t.append(n),o.append(t)}}return o.append(L(e,`span`,`wui-chat-quick-reply-label`,c?r.labels.handoffMoment:t.label)),o.addEventListener(`click`,()=>{if(t.action===`Open`){let{openTarget:e}=this.activeTurn;if(t.target===null||e===void 0)throw Error(`${this.localName} drew an Open chip without a target or openTarget`);e.call(this.activeTurn,t.target)}else if(s){let{beginHandoff:e}=this.activeTurn;if(a===null||e===void 0)throw Error(`${this.localName} drew a Navigate chip without a destination or beginHandoff`);e.call(this.activeTurn,t,()=>this.#i(a))}else this.activeTurn.chooseQuickReply(t),this.closest(`.wui-chat`)?.querySelector(`.wui-chat-input`)?.focus()}),o}#i(e){typeof this.activeTurn.openTarget==`function`?this.activeTurn.openTarget(e):globalThis.location.assign(e)}});var Lt=/* @__PURE__ */ new Set([`Integer`,`Decimal`,`MoneyMinor`,`Percent`]);function Rt(e){return Lt.has(e)}function zt(e,t,n,r=!0){let i=e=>r?P(e):[{kind:`text`,text:e}];if(t==null||t===``)return[{kind:`text`,text:Se()}];if(e===`Date`||e===`DateTimeUtc`)return[{kind:`text`,text:ie(t,e,n)}];if(Rt(e)){let r=Number(t);return i(Number.isFinite(r)?ie(r,e,n):String(t))}return i(String(t))}var Bt=0;function Vt(e){return Bt+=1,`${e}-${Bt}`}I(`wui-chat-part-record-card`,class extends F{#e=null;renderPart(e,t,n){let r=!!e.target&&typeof n.openRecord==`function`,i=n.features?.FigureText===!0,a=JSON.stringify([e,r,i]);if(a===this.#e)return;this.#e=a;let o=this.ownerDocument,s=L(o,`article`,`wui-chat-record`),c=Vt(`wui-chat-record-title`);s.setAttribute(`aria-labelledby`,c);let l=L(o,`div`,`wui-chat-record-head`),u=L(o,`strong`,`wui-chat-record-title`);if(u.id=c,u.setAttribute(`role`,`heading`),u.setAttribute(`aria-level`,`3`),i?B(u,e.title):u.textContent=String(e.title??``),l.append(u),e.subtitle){let t=L(o,`span`,`wui-chat-record-subtitle`);i?B(t,e.subtitle):t.textContent=String(e.subtitle??``),l.append(t)}if(s.append(l),e.fields?.length>0){let t=L(o,`dl`,`wui-chat-record-fields`);for(let n of e.fields){let e=L(o,`div`),r=L(o,`dt`);i?B(r,n.label):r.textContent=String(n.label??``);let a=L(o,`dd`);Rt(n.type)&&(a.className=`wui-chat-num`),z(a,zt(n.type,n.value,null,i)),e.append(r,a),t.append(e)}s.append(t)}if(r){let t=L(o,`button`,`btn btn-soft-primary btn-sm wui-chat-record-open`,n.labels.recordOpen);t.type=`button`,t.setAttribute(`aria-label`,n.labels.recordOpenFor(V(e.title))),t.addEventListener(`click`,()=>{let{openRecord:t}=this.activeTurn;if(t===void 0)throw Error(`${this.localName} lost openRecord after it drew the button`);t.call(this.activeTurn,e)}),s.append(t)}this.replaceChildren(s)}});var Ht=/^https?:\/\//i;I(`wui-chat-part-sources`,class extends F{renderPart(e,t,n){if(this.replaceChildren(),!n.features.Sources||e.sources.length===0)return;let r=this.ownerDocument,i=L(r,`div`,`wui-chat-sources`);i.append(L(r,`p`,`wui-chat-sources-label`,n.labels.sources));let a=L(r,`ul`,`wui-chat-sources-list`);a.setAttribute(`aria-label`,n.labels.sources);for(let t of e.sources){let e=r.createElement(`li`);e.append(this.#e(r,t,n)),a.append(e)}i.append(a),this.append(i)}#e(e,t,n){let r;if(typeof t.url==`string`&&Ht.test(t.url)){let i=L(e,`a`,`wui-chat-source`);i.setAttribute(`href`,t.url),i.setAttribute(`target`,`_blank`),i.setAttribute(`rel`,`noopener noreferrer`),i.setAttribute(`aria-label`,n.labels.openSource(t.title)),r=i}else r=L(e,`span`,`wui-chat-source`),r.tabIndex=-1;return r.dataset.marker=String(t.marker),r.append(L(e,`span`,`wui-chat-source-marker`,String(t.marker)),L(e,`span`,`wui-chat-source-title`,t.title)),r}});var Ut=25,Wt=0;function Gt(e,t,n){let r=e.createElement(`tr`);for(let i of t.columns){let t=e.createElement(`th`);t.setAttribute(`scope`,`col`),Rt(i.type)&&(t.className=`wui-chat-num`),n?B(t,i.label):t.textContent=String(i.label??``),r.append(t)}return r}function Kt(e,t,n,r){let i=e.createElement(`tr`);return t.columns.forEach((a,o)=>{let s=o===0&&a.type===`Text`,c=e.createElement(s?`th`:`td`);s&&c.setAttribute(`scope`,`row`),Rt(a.type)&&(c.className=`wui-chat-num`);let l=n[o];l==null||l===``?c.append(L(c.ownerDocument,`span`,`wui-chat-null`,Se())):z(c,zt(a.type,l,t.currency,r)),i.append(c)}),i}function qt(e,t){let n=()=>{let n=t.scrollWidth-t.clientWidth;e.dataset.scroll=n<=1?`none`:t.scrollLeft>=n-1?`end`:t.scrollLeft>0?`middle`:`start`};t.addEventListener(`scroll`,n,{passive:!0}),typeof ResizeObserver<`u`&&new ResizeObserver(n).observe(t),n()}function Jt(e,t,n,r,i){let a=e.ownerDocument;for(let o of t.rows.slice(n,r))e.append(Kt(a,t,o,i))}I(`wui-chat-part-table`,class extends F{#e=null;renderPart(e,t,n){let r=n.features?.FigureText===!0,i=JSON.stringify([e,r]);if(i===this.#e)return;if(this.#e=i,!e.columns||e.columns.length===0){this.replaceChildren();return}let a=this.ownerDocument,o=L(a,`figure`,`wui-chat-table`),s=null;if(e.title){Wt+=1,s=`wui-chat-table-${Wt}`;let t=L(a,`figcaption`,`wui-chat-table-title`);t.id=s,r?B(t,e.title):t.textContent=String(e.title??``),o.append(t)}let c=L(a,`div`,`table-wrap wui-chat-table-wrap`);c.tabIndex=0,c.setAttribute(`role`,`region`),s?c.setAttribute(`aria-labelledby`,s):c.setAttribute(`aria-label`,n.labels.table);let l=L(a,`table`,`table table-sm wui-chat-table-grid`),u=a.createElement(`thead`);u.append(Gt(a,e,r));let d=a.createElement(`tbody`);Jt(d,e,0,Math.min(e.rows.length,Ut),r),l.append(u,d),c.append(l);let f=L(a,`div`,`wui-chat-table-frame`),p=L(a,`span`,`wui-chat-table-cue`);if(p.setAttribute(`aria-hidden`,`true`),f.append(c,p),o.append(f),qt(f,c),e.rows.length>Ut){let t=L(a,`button`,`btn btn-soft-primary btn-sm wui-chat-table-more`,n.labels.tableShowAll(e.rows.length));t.type=`button`,t.addEventListener(`click`,()=>{Jt(d,e,Ut,e.rows.length,r),t.remove()}),o.append(t)}this.replaceChildren(o)}});var Yt=/* @__PURE__ */ new Set([`Visitor`,`Customer`]),Xt=/^\d+$/;function Zt(e,t){return e?.features?.Sources===!0?typeof e?.isCitation==`function`?e.isCitation(t):Xt.test(t):!1}function Qt(e,t){if(ce(e,t?.handoffHosts))return e;let n=t?.resolveLink?.(e);return typeof n==`string`&&n!==``?n:null}function $t(e,t){let n=globalThis.location?.origin;for(let r of e.querySelectorAll(`a[href]`)){let e=r.dataset.linkSource??r.getAttribute(`href`)??``;r.dataset.linkSource=e;let i=Qt(e,t);i===null?r.replaceWith(r.ownerDocument.createTextNode(r.textContent??``)):(i!==r.getAttribute(`href`)&&r.setAttribute(`href`,i),ve(i,`web`,void 0,n)?.kind===`web`?(r.setAttribute(`target`,`_blank`),r.setAttribute(`rel`,`noopener noreferrer`)):(r.removeAttribute(`target`),r.removeAttribute(`rel`)))}}function en(e,t){$t(e,t)}I(`wui-chat-part-text`,class extends F{#e=null;#t=null;#n=!1;#r=null;constructor(){super(),this.addEventListener(`wui-markdown-citation`,e=>{let t=this.turn;typeof t?.openCitation==`function`&&t.openCitation(Number(e.detail.citation))}),this.addEventListener(`click`,e=>this.#a(e))}renderPart(e,t,n){let r=Yt.has(t.author.kind)?`plain`:`markdown`,i=this.#e;if((i===null||i.mode!==r)&&(i=r===`plain`?{mode:r,node:this.#s()}:this.#c(e.text),this.#e=i,this.#t=null,this.replaceChildren(i.node)),i.mode===`plain`){let t=this.turn?.features?.FigureText===!0,n=JSON.stringify([e.text,t]);n!==this.#t&&(this.#t=n,i.node.replaceChildren(),t?z(i.node,P(e.text)):i.node.append(this.ownerDocument.createTextNode(e.text)))}else this.#o(i.node),i.source.textContent!==e.text&&(i.source.textContent=e.text);this.toggleAttribute(`data-streaming`,t.streaming===!0),this.#n||(this.#n=!0,this.closest(`[data-restored]`)||this.classList.add(`wui-chat-part-enter`)),this.#i()}disposePart(){this.#r?.disconnect(),this.#r=null}#i(){this.#r||(this.#r=new MutationObserver(()=>en(this,this.turn)),this.#r.observe(this,{childList:!0,subtree:!0,characterData:!0}),en(this,this.turn))}#a(e){let t=e.target instanceof Element?e.target.closest(`a[href]`):null,n=this.turn;if(!t||!this.contains(t))return;let r=t.getAttribute(`href`)??``;r.startsWith(`#`)||(r.startsWith(`/`)&&typeof n?.onNavigate==`function`?(e.preventDefault(),n.onNavigate(r)):typeof n?.openTarget==`function`&&(e.preventDefault(),n.openTarget(r)))}#o(e){let t=this.turn?.features?.FigureText===!0?P:void 0;e.figureText!==t&&(e.figureText=t)}#s(){return L(this.ownerDocument,`div`,`wui-chat-bubble`)}#c(e){let t=this.ownerDocument,n=L(t,`wui-markdown`,`wui-markdown wui-chat-text`);n.setAttribute(`links`,`web`),n.setAttribute(`headings`,`text`),n.isCitation=e=>Zt(this.turn,e);let r=L(t,`pre`,`wui-markdown-source`,e);return n.append(r),{mode:`markdown`,node:n,source:r}}}),I(`wui-chat-part-ticket`,class extends F{renderPart(e,n,r){let{labels:i}=r,a=t(`article`,`wui-chat-ticket`,{"aria-label":i.ticketAria(e.number)}),o=t(`div`,`wui-chat-ticket-head`),s=t(`span`,`wui-chat-ticket-number`);s.textContent=i.ticketAria(e.number),o.append(s);let c=ut(e.status);if(c!==null){let n=t(`span`,`wui-chat-ticket-badge wui-chat-ticket-badge--${c}`);n.textContent=dt(e.status,i),o.append(n)}let l=t(`strong`,`wui-chat-ticket-title`);if(l.textContent=e.subject,a.append(o,l),typeof r.openTicket==`function`){let n=t(`div`,`wui-chat-ticket-foot`),o=t(`button`,`wui-chat-ticket-link`,{type:`button`});o.textContent=i.ticketView,o.addEventListener(`click`,()=>{let{openTicket:t}=r;if(t===void 0)throw Error(`${this.localName} lost openTicket after it drew the link`);t.call(r,{ticketId:e.ticketId,number:e.number})}),n.append(o),a.append(n)}this.replaceChildren(a)}});var tn=`http://www.w3.org/2000/svg`,nn={mic:`M12 15a3 3 0 0 0 3-3V6a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-2.08A7 7 0 0 0 19 12z`,stop:`M6 6h12v12H6z`,play:`M8 5v14l11-7z`,pause:`M6 5h4v14H6zm8 0h4v14h-4z`,speaker:`M3 9v6h4l5 5V4L7 9H3zm13.5 3a4.5 4.5 0 0 0-2.5-4v8a4.5 4.5 0 0 0 2.5-4zM14 3.2v2.1a7 7 0 0 1 0 13.4v2.1a9 9 0 0 0 0-17.6z`};function rn(e,t=18){if(!i(nn,e))throw Error(`Unknown voice icon "${e}".`);let n=document.createElementNS(tn,`svg`);n.setAttribute(`viewBox`,`0 0 24 24`),n.setAttribute(`width`,String(t)),n.setAttribute(`height`,String(t)),n.setAttribute(`aria-hidden`,`true`),n.setAttribute(`focusable`,`false`),n.setAttribute(`fill`,`currentColor`);let r=document.createElementNS(tn,`path`);return r.setAttribute(`d`,nn[e]),n.append(r),n}var an=40,q=null;function on(e){let t=L(document,`span`,`wui-chat-clip-bar`);return t.style.setProperty(`--wui-chat-bar-height`,`${Math.round(e*100)}%`),t}function sn(e,t){e.replaceChildren(..._e(t,an).map(on))}I(`wui-chat-part-voice-clip`,class extends F{#e=null;#t=!1;#n=0;#r=0;#i=!1;#a=null;#o=null;#s=null;#c=0;#l=!1;renderPart(e,t,n){if(!n.features.VoiceClips){this.#u(e.transcript);return}let r=this.#e??this.#d(e.attachmentId);e.attachmentId!==r.attachmentId&&(this.disposePart(),r.attachmentId=e.attachmentId,this.#r=0,sn(r.wave,e.attachmentId)),this.#n=e.durationMs,this.#f(r,e)}disposePart(){this.#c+=1,this.#a?.pause(),this.#s!==null&&URL.revokeObjectURL(this.#s),q===this&&(q=null),this.#a=null,this.#o=null,this.#s=null,this.#i=!1}#u(e){if(this.disposePart(),this.#e=null,typeof e==`string`&&e!==``){let t=L(document,`p`,`wui-chat-clip-transcript`);t.textContent=e,this.replaceChildren(t)}else this.replaceChildren()}#d(e){let t=L(document,`div`,`wui-chat-clip`);t.setAttribute(`role`,`group`);let n=L(document,`div`,`wui-chat-clip-row`),r=L(document,`button`,`wui-chat-clip-play`);r.type=`button`;let i=L(document,`div`,`wui-chat-clip-wave`);i.setAttribute(`aria-hidden`,`true`);let a=L(document,`span`,`wui-chat-clip-time`);n.append(r,i,a);let o=L(document,`p`,`wui-chat-clip-error`);o.setAttribute(`role`,`status`),o.hidden=!0,t.append(n,o);let s={attachmentId:e,root:t,play:r,wave:i,time:a,error:o,transcript:null};return r.addEventListener(`click`,()=>this.#C(s)),sn(i,e),this.#e=s,this.replaceChildren(t),s}#f(e,t){let n=this.activeTurn.labels;e.root.setAttribute(`aria-label`,n.voiceClip),e.play.disabled=this.#l||typeof this.activeTurn.readAttachment!=`function`,this.#p(e),this.#m(e),this.#h(e,t.transcript)}#p(e){let t=this.activeTurn.labels,n=this.#i?t.voiceClipPause:t.voiceClipPlay;e.play.setAttribute(`aria-label`,n),e.play.title=n,e.play.replaceChildren(rn(this.#i?`pause`:`play`,18))}#m(e){let t=this.#n/1e3,n=t>0?Math.min(1,this.#r/t):0,r=Math.floor(n*an);[...e.wave.children].forEach((e,t)=>{e.classList.toggle(`wui-chat-clip-bar--played`,t<r)});let i=ae(Math.max(1,Math.round(t)));e.time.textContent=this.activeTurn.labels.voiceClipTime(ae(this.#r),i)}#h(e,t){if(typeof t!=`string`||t===``){e.transcript?.toggle.remove(),e.transcript?.text.remove(),e.transcript=null;return}let n=e.transcript??this.#g(e);n.text.textContent=t,this.#_(n)}#g(e){let t=L(document,`button`,`wui-chat-clip-toggle`);t.type=`button`;let n=L(document,`p`,`wui-chat-clip-transcript`);n.hidden=!this.#t;let r={toggle:t,text:n};return t.addEventListener(`click`,()=>{this.#t=!this.#t,n.hidden=!this.#t,this.#_(r)}),e.transcript=r,e.root.append(t,n),r}#_(e){let t=this.activeTurn.labels;e.toggle.setAttribute(`aria-expanded`,String(this.#t)),e.toggle.textContent=this.#t?t.voiceClipHideTranscript:t.voiceClipShowTranscript}#v(e){return this.#o??=this.#y(e).catch(e=>{throw this.#o=null,e}),this.#o}async#y(e){let t=this.#c,{readAttachment:n}=this.activeTurn;if(n===void 0)throw Error(`${this.localName} loaded a clip on a turn without readAttachment`);let r=await n.call(this.activeTurn,e.attachmentId),i=URL.createObjectURL(new Blob([r],{type:me(r)}));if(t!==this.#c)return URL.revokeObjectURL(i),null;this.#s!==null&&URL.revokeObjectURL(this.#s),this.#s=i;let a=new Audio(this.#s);return a.addEventListener(`timeupdate`,()=>{this.#r=a.currentTime,this.#m(e)}),a.addEventListener(`ended`,()=>{this.#r=0,this.#b(),this.#m(e)}),a.addEventListener(`error`,()=>{this.#b(),this.#o=null,this.#S(e)}),this.#a=a,a}#b(){this.#a?.pause(),this.#x(!1)}#x(e){this.#i=e,e?(q&&q!==this&&q.#b(),q=this):q===this&&(q=null);let t=this.#e;t!==null&&this.#p(t)}#S(e){e.error.textContent=this.activeTurn.labels.voiceClipFailed,e.error.hidden=!1}async#C(e){if(this.#i)this.#b();else{e.error.hidden=!0,this.#l=!0,e.play.disabled=!0,e.play.setAttribute(`aria-busy`,`true`);try{let t=await this.#v(e);if(t===null)return;this.#x(!0),await t.play()}catch{this.#b(),this.#o=null,this.#S(e)}finally{this.#l=!1,e.play.removeAttribute(`aria-busy`),e.play.disabled=typeof this.activeTurn.readAttachment!=`function`}}}});var cn={Text:`wui-chat-part-text`,Sources:`wui-chat-part-sources`,QuickReplies:`wui-chat-part-quick-replies`,InputRequest:`wui-chat-part-input-request`,Action:`wui-chat-part-action`,Notice:`wui-chat-part-notice`,Table:`wui-chat-part-table`,Chart:`wui-chat-part-chart`,Figures:`wui-chat-part-figures`,RecordCard:`wui-chat-part-record-card`,Image:`wui-chat-part-image`,File:`wui-chat-part-file`,Ticket:`wui-chat-part-ticket`,Handoff:`wui-chat-part-handoff`,VoiceClip:`wui-chat-part-voice-clip`},ln=8e3,un=6e3,dn=/* @__PURE__ */ new Set([`Blocked`,`NoMicrophone`]);function fn(e){let t=e instanceof E?e.code:`Failed`;return{code:t,source:`Dictation`,sticky:dn.has(t)}}function pn(e){let t=M(e.filter(e=>e.kind===`Text`)).replace(/ ?\[\d+\]/g,``).replace(/\s+/g,` `).trim();if(t.length<=6e3)return t;let n=t.slice(0,un),r=n.lastIndexOf(`. `);return r===-1?n.trim():n.slice(0,r+1)}function mn(e,t){switch(e.code){case`Blocked`:return t.dictationBlocked;case`NoMicrophone`:return t.dictationNoMicrophone;case`NoSpeech`:return t.dictationNotHeard;case`Unavailable`:return t.dictationUnavailable;case`Failed`:return t.dictationFailed;case`SpeakFailed`:return t.readAloudFailed;default:throw Error(`Unknown voice note code "${e.code}".`)}}function hn(e){let t=e.getState,n=e.speech??o({getToken:e.getToken}),r=`Idle`,i=null,a=null,s=null,c=null,l=0,u=null,d=/* @__PURE__ */ new Set,f=()=>({mode:r,messageId:i,startedAtMs:a,note:s});function p(){let e=f();for(let t of[...d])t(e)}function m(e){r=e.mode,i=e.messageId??null,a=e.startedAtMs??null,p()}function h(){u!==null&&clearTimeout(u),u=null}function g(e){h(),s=e,e&&!e.sticky&&(u=setTimeout(()=>{u=null,s=null,p()},ln)),p()}function _(){s!==null&&(h(),s=null,p())}function v(){l+=1;let e={id:l,controller:new AbortController,stopped:!1};return c=e,e}function y(e){c===e&&(c=null,m({mode:`Idle`}))}function b(){let e=c;c=null,e&&(e.stopped=!0,e.controller.abort()),r!==`Idle`&&m({mode:`Idle`})}function x(){let e=t();return!!(e.features.Dictation&&e.profile?.speechAvailable&&n.dictation)}function S(){let e=t();return!!(e.features.ReadAloud&&e.profile?.speechAvailable&&n.readAloud)}async function C(e){if(r===`Dictating`){b();return}if(b(),g(null),!x())return;let t=e.getText(),i=t!==``&&!/\s$/.test(t)?`${t} `:t,a=v();m({mode:`Dictating`});try{await n.startDictation({signal:a.controller.signal,onText:t=>{c===a&&e.setText(i+t)},onEnd:()=>y(a)})}catch(e){if(a.stopped)return;y(a),g(fn(e))}}async function w(e,t){if(r===`Speaking`&&i===e){b();return}b(),g(null);let a=pn(t);if(a===``)return;let o=v();m({mode:`Speaking`,messageId:e});try{await n.speak(a,{signal:o.controller.signal}),y(o)}catch{if(o.stopped)return;y(o),g({code:`SpeakFailed`,source:`ReadAloud`,sticky:!1,messageId:e})}}function T(e){return d.add(e),()=>{d.delete(e)}}function E(){b(),h(),s=null,d.clear()}return{canDictate:x,canSpeak:S,getStatus:f,subscribe:T,toggleDictation:C,toggleSpeak:w,stop:b,dismissNote:_,destroy:E}}var gn=/* @__PURE__ */ new Set([`Shift`,`Control`,`Alt`,`Meta`,`Escape`]);function _n(e,t){e.isTrusted&&!gn.has(e.key)&&t.getStatus().mode===`Dictating`&&t.stop()}function vn({voice:e,getLabels:n,textarea:r,onTextChanged:i}){let a=null,o=t(`button`,`wui-chat-tool wui-chat-mic`,{type:`button`});o.append(rn(`mic`,20)),o.hidden=!0,o.addEventListener(`click`,()=>{e.toggleDictation({getText:()=>r.value,setText:e=>{r.value=r.maxLength>0?e.slice(0,r.maxLength):e,i(),r.setSelectionRange(r.value.length,r.value.length)}})});let s=t(`p`,`wui-chat-voice-note`,{role:`status`});s.hidden=!0;let c=t(`span`,`visually-hidden`,{"aria-live":`polite`});function l(e){let t=n(),r=e.note?.source===`ReadAloud`?null:e.note,i=e.mode===`Dictating`,a=i?t.dictateStop:t.dictate;o.setAttribute(`aria-pressed`,String(i)),o.setAttribute(`aria-label`,a),o.title=a;let l=r?.code===`Blocked`||r?.code===`NoMicrophone`;r===null?(s.hidden=!0,s.textContent=``):(s.hidden=!1,s.textContent=mn(r,t),s.setAttribute(`role`,r.sticky?`alert`:`status`)),s.classList.toggle(`wui-chat-voice-note--blocked`,l),c.textContent=i?t.dictateListening:``}function u(t){let{state:n}=t;o.hidden=!e.canDictate();let r=e.getStatus().mode===`Speaking`,i=n.messagesLeftToday===0;o.disabled=i||r||n.handoffPause===!0}function d(e){l(e),a!==null&&u(a)}let f=e.subscribe(d);function p(t){a=t,u(t),l(e.getStatus())}function m(){f()}return{buttons:[o],note:s,announcer:c,paint:p,destroy:m}}var yn=10,bn=.9,xn=0;function Sn(e){for(let t of e.toReversed())for(let e of t.parts.toReversed())if(e.kind===`InputRequest`&&e.state===`Open`)return e.fields[0]?.label??e.title??null;return null}function Cn(n){xn+=1;let r=`wui-chat-composer-hint-${xn}`,i=t(`p`,`wui-chat-allowance`,{role:`status`});i.hidden=!0;let a=t(`span`),o=t(`button`,`btn btn-ghost-primary btn-sm wui-chat-action-btn`,{type:`button`});o.addEventListener(`click`,()=>n.onCancelEdit());let s=t(`div`,`wui-chat-editing`);s.hidden=!0,s.append(a,o);let c=t(`div`,`wui-chat-attachments`);c.hidden=!0;let l=t(`button`,`wui-chat-tool`,{type:`button`});l.append(e(`paperclip`,20)),l.hidden=!0;let u=t(`input`,null,{type:`file`,multiple:``,tabindex:`-1`});u.hidden=!0,u.addEventListener(`change`,()=>{let e=[...u.files??[]];u.value=``,e.length>0&&n.onAttach(e)}),l.addEventListener(`click`,()=>u.click());let d=t(`textarea`,`wui-chat-input`,{rows:`1`,"aria-describedby":r}),f=t(`span`,`visually-hidden`,{id:r}),p=t(`span`,`wui-chat-counter`);p.hidden=!0;let m=t(`button`,`wui-chat-send`,{type:`submit`});m.append(e(`arrow-up`,18));let h=t(`button`,`wui-chat-send wui-chat-send--stop`,{type:`button`});h.append(e(`stop`,16)),h.hidden=!0,h.addEventListener(`click`,()=>n.onStop());let g=t(`form`,`wui-chat-composer`);g.append(l,u,d,p,f,h,m);let _=null,v=null,y=null,b=0,x=null;function S(){d.style.height=`auto`,d.style.height=`${d.scrollHeight}px`;let e=getComputedStyle(d),t=d.scrollHeight-parseFloat(e.paddingTop)-parseFloat(e.paddingBottom);g.classList.toggle(`wui-chat-composer--multiline`,t>(parseFloat(e.lineHeight)||22)*1.5)}function C(){return x?.attachments.some(e=>e.status===`Uploading`)??!1}function w(){return x?.attachments.some(e=>e.status===`Ready`)??!1}function T(){let e=d.value.length,t=b>0&&e>b*bn;p.hidden=!t,t&&y&&(p.textContent=y.counter(e,b))}function E(){let e=x?.messagesLeftToday??null,t=d.value.trim()===``&&!w();m.disabled=!!x?.streaming||e===0||C()||t||x?.handoffPause===!0,g.classList.toggle(`wui-chat-composer--has-text`,!t)}function D(){if(m.disabled)return;let e=d.value.trim();d.value=``,S(),T(),E(),n.voice?.stop(),n.voice?.dismissNote(),n.onSubmit(e)}d.addEventListener(`input`,()=>{S(),T(),E(),d.value!==``&&n.onTyping?.()}),d.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),D())}),g.addEventListener(`submit`,e=>{e.preventDefault(),D()});let O=n.voice,k=O?vn({voice:O,getLabels:()=>{if(y===null)throw Error(`composer labels are read before the first render`);return y},textarea:d,onTextChanged:()=>{S(),T(),E()}}):null;if(O&&k){let e=k.buttons[0];e&&g.insertBefore(e,m),d.addEventListener(`keydown`,e=>_n(e,O))}function ee(r,i){let a=r.map(r=>{let a=t(`span`,`wui-chat-chip`),o=t(`span`,null,r.status===`Failed`?{title:r.error??``}:null);o.textContent=r.fileName;let s=t(`button`,`wui-chat-chip-remove`,{type:`button`,"aria-label":i.removeAttachment(r.fileName)});s.append(e(`x`,14)),s.addEventListener(`click`,()=>n.onRemove(r.key));let c=[];if(r.status===`Uploading`){let e=t(`progress`,`wui-chat-chip-progress`,{max:`1`});typeof r.progress==`number`&&(e.value=r.progress);let n=t(`span`,`wui-chat-chip-status`);n.textContent=i.attachmentUploading,c.push(e,n)}if(r.status===`Failed`){let e=t(`span`,`wui-chat-chip-error`,{"aria-live":`polite`});e.textContent=r.error||i.attachmentFailed,c.push(e)}return a.append(o,...c,s),a});c.replaceChildren(...a),c.hidden=a.length===0}function te(t){x=t.state,y=t.labels,b=t.maxLength,t.sendIcon&&m.dataset.icon!==t.sendIcon&&(m.dataset.icon=t.sendIcon,m.replaceChildren(e(t.sendIcon,18)));let r=x.messagesLeftToday;g.setAttribute(`aria-label`,y.composer),f.textContent=y.composerHint,d.setAttribute(`aria-label`,y.composer),d.maxLength=b,d.placeholder=x.handoffPause?y.handoffMoment:Sn(x.messages)??y.placeholder,d.disabled=r===0||x.handoffPause===!0,i.hidden=!(r!==null&&r<=yn),!i.hidden&&r!==null&&(i.textContent=y.allowance(r));let c=x.editing?.messageId??null;if(c!==_){let e=_!==null;_=c,x.editing?(n.voice?.stop(),d.value=x.editing.text,S()):e&&(d.value=``,S())}s.hidden=!x.editing,a.textContent=y.editing,o.textContent=y.cancel;let p=t.draft??null;typeof p==`string`&&p!==``&&p!==v&&(v=p,d.value=p,d.dispatchEvent(new Event(`input`)),d.focus(),n.onDraftApplied?.()),ee(x.attachments,y);let C=x.features.Attachments&&(x.profile?.limits.maxAttachments??0)>0&&x.handoffPause!==!0;l.hidden=!C,l.setAttribute(`aria-label`,y.attach),l.title=y.attachHint,u.accept=t.accept??``;let w=x.streaming&&x.features.Stop===!0;h.hidden=!w,h.setAttribute(`aria-label`,y.stop),m.hidden=w,m.setAttribute(`aria-label`,y.send),T(),E(),k?.paint({state:x})}function A(){d.focus()}function ne(){k?.destroy();for(let e of j)e.remove()}let j=[i,s,c,...k?[k.note,k.announcer]:[],g];return{nodes:j,paint:te,focus:A,destroy:ne,getDraft:()=>d.value}}var wn=`https://policies.google.com/privacy`,Tn=`https://policies.google.com/terms`;function En(e,n){let r=t(`a`,`wui-chat-footer-link`,{href:n,target:`_blank`,rel:`noopener noreferrer`});return r.textContent=e,r}function Dn(){let e=t(`p`,`wui-chat-footer`);e.hidden=!0;function n(n){let{labels:r,profile:i}=n,a=[];if(i){let e=t(`span`,`wui-chat-footer-text`);e.textContent=i.footer.disclaimer||r.disclaimer,a.push(e);let{privacyText:n}=i.footer,o=le(i.footer.privacyUrl)?i.footer.privacyUrl:null;if(o){let e=t(`span`,`wui-chat-footer-privacy`),i=t(`a`,`wui-chat-footer-link`,{href:o});i.textContent=n||r.footerPrivacyFallback,e.append(i),a.push(e)}else if(n){let e=t(`span`,`wui-chat-footer-privacy`);e.textContent=n,a.push(e)}if(i.footer.assuranceText){let e=t(`span`);e.textContent=i.footer.assuranceText,a.push(e)}if(N(i)){let e=t(`span`,`wui-chat-footer-captcha`);e.append(document.createTextNode(r.captchaNoticeBefore),En(r.captchaPrivacyPolicy,wn),document.createTextNode(r.captchaNoticeAnd),En(r.captchaTerms,Tn),document.createTextNode(r.captchaNoticeAfter)),a.push(e)}}e.replaceChildren(...a),e.hidden=a.length===0}return{el:e,paint:n}}function J(t,n,r){t.setAttribute(`aria-label`,n),t.title=n,t.dataset.icon!==r&&(t.dataset.icon=r,t.replaceChildren(e(r,20)))}function On(e){let n=t(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),r=t(`strong`,`wui-chat-title`);e.titleId&&(r.id=e.titleId);let i=t(`span`,`wui-chat-tagline`),a=t(`span`,`wui-chat-status`),o=t(`div`,`wui-chat-header-text`);o.append(r,i,a);let s=t(`span`,`wui-chat-header-conversation`);s.hidden=!0;let c=g(``,`history`,()=>e.onHistory()),l=g(``,`volume-high`,()=>e.onMute()),u=g(``,`plus`,()=>e.onNew()),d=g(``,`maximize-4`,()=>e.onSwitch());d.classList.add(`wui-chat-switch-btn`,`wui-chat-switch-btn--full`);let f=g(``,`panel-left-open`,()=>e.onSwitch());f.classList.add(`wui-chat-switch-btn`,`wui-chat-switch-btn--side`);let p=g(``,`x`,()=>e.onClose());p.classList.add(`wui-chat-close-btn`);let m=t(`div`,`wui-chat-header-actions`);m.append(s,c,l,u,d,f,p);let h=t(`header`,`wui-chat-header`);h.append(n,o,m);function _(e){let{labels:t}=e;h.hidden=!1,r.textContent=e.title??``,i.textContent=e.tagline??``,i.hidden=!e.tagline,a.textContent=e.status??``,c.hidden=!e.showHistory,e.viewingHistory?J(c,t.backToChat,`arrow-left`):J(c,t.history,`history`),l.hidden=!e.showMute,J(l,e.muted?t.unmuteSounds:t.muteSounds,e.muted?`volume-mute`:`volume-high`),u.hidden=!!e.viewingHistory||e.showNew===!1,u.disabled=!e.canNew,J(u,t.newChat,`plus`),d.hidden=e.switchTo!==`full-page`,d.disabled=!e.canSwitch,J(d,t.openFullScreen,`maximize-4`),f.hidden=e.switchTo!==`docked`,f.disabled=!e.canSwitch,J(f,t.openSidePanel,`panel-left-open`),p.hidden=!e.showClose,J(p,t.close,`x`)}return{el:h,conversation:s,paint:_}}var kn=120;function Y(e,n,r=`outline`){let i=t(`button`,`${s(r,`sm`)} wui-chat-action-btn`,{type:`button`});return i.textContent=e,i.addEventListener(`click`,n),i}function An(e){let n=t(`div`,`wui-chat-history`);n.hidden=!0;let r=null,i=null,a=null,o=null,s=null,c=!1;function l(){return r||(r=A({client:e.getClient()}),i=r.subscribe(()=>y()),r)}function u(e){a={id:e.publicId,kind:`rename`,draft:e.title??``,saving:!1},o=null,s=null,c=!0,y()}function d(e){a={id:e.publicId,kind:`delete`,saving:!1},o=null,s=null,y()}function f(){a=null,o=null,s=null,y()}async function p(){let t=a;if(t?.kind!==`rename`||t.saving)return;let n=t.draft.trim();if(n){t.saving=!0,y();try{await l().rename(t.id,n),a===t&&(a=null),o=null,s=null}catch{if(a!==t)return;t.saving=!1,s=e.getLabels().renameFailed}y()}}async function m(){let t=a;if(!(t?.kind!==`delete`||t.saving)){t.saving=!0,y();try{await l().remove(t.id),a===t&&(a=null),o=null,e.onDeleted(t.id)}catch{if(a!==t)return;t.saving=!1,o=e.getLabels().deleteFailed}y()}}function h(e,n){let r=t(`li`,`wui-chat-history-row wui-chat-history-row--editing`),i=t(`input`,`wui-chat-history-input`,{type:`text`,"aria-label":e.conversationTitle,maxlength:String(kn)});i.value=n.draft,i.addEventListener(`input`,()=>{n.draft=i.value,a.disabled=n.saving||!n.draft.trim()}),i.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.isComposing&&e.keyCode!==229?(e.preventDefault(),p()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),f())});let a=Y(e.renameSave,()=>p(),`primary`);if(a.disabled=n.saving||!n.draft.trim(),r.append(i,a,Y(e.cancel,()=>f(),`ghost`)),s!==null){let e=t(`p`,`wui-chat-history-error`,{role:`alert`});e.textContent=s,r.append(e)}return c&&(c=!1,queueMicrotask(()=>i.focus())),r}function _(e,n){let r=t(`li`,`wui-chat-history-row wui-chat-history-row--confirm`),i=t(`p`);i.textContent=e.deleteConfirmTitle;let a=t(`p`);a.textContent=e.deleteConfirmMessage;let o=Y(e.deleteConfirm,()=>m(),`danger`);return o.disabled=n.saving,r.append(i,a,o,Y(e.cancel,()=>f(),`ghost`)),r}function v(n,r,i){if(a?.id===n.publicId&&a.kind===`rename`)return h(r,a);if(a?.id===n.publicId&&a.kind===`delete`)return _(r,a);let o=t(`li`,`wui-chat-history-row`),s=t(`button`,`wui-chat-history-open`,{type:`button`}),c=t(`span`,`wui-chat-history-title`);c.textContent=n.title||r.untitled;let l=t(`span`,`wui-chat-history-time`);return l.textContent=j(n.lastActivityDateTimeUtc),s.append(c,l),s.addEventListener(`click`,()=>e.onOpen(n.publicId)),o.append(s),i.Rename&&o.append(g(r.rename,`pencil`,()=>u(n))),i.Delete&&o.append(g(r.deleteChat,`trash`,()=>d(n))),o}function y(){let i=e.getLabels(),a=e.getFeatures(),s=r?r.getState():{items:[],totalCount:null,loading:!1,error:null,hasMore:!1},c=[];if(s.error||o){let e=t(`p`,`wui-chat-history-error`,{role:`alert`});s.error?(e.append(document.createTextNode(i.loadFailed),document.createTextNode(` `)),e.append(Y(i.retry,()=>l().load(),`outline`))):e.textContent=o,c.push(e)}if(s.loading&&s.items.length===0){let e=t(`p`,`wui-chat-history-empty`,{role:`status`});e.textContent=i.loadingConversation,c.push(e)}if(s.items.length===0&&!s.loading&&!s.error){let e=t(`p`,`wui-chat-history-empty`),n=t(`span`);n.textContent=i.historyEmptyTitle;let r=t(`span`);r.textContent=i.historyEmptyText,e.append(n,r),c.push(e)}if(s.items.length>0){let e=t(`ul`,`wui-chat-history-list`,{"aria-label":i.history});e.append(...s.items.map(e=>v(e,i,a))),c.push(e)}s.hasMore&&!s.loading&&c.push(Y(i.loadMore,()=>l().loadMore(),`outline`)),n.replaceChildren(...c)}function b(){n.hidden=!1,Promise.allSettled([l().load()]),y()}function x(){n.hidden=!0}function S(){i?.(),i=null,r?.dispose(),r=null}return{el:n,show:b,hide:x,paint:y,dispose:S}}var jn=/* @__PURE__ */ new Set([`GET`,`HEAD`]);function Mn(){let e=document.querySelector(`meta[name="wui-csrf"]`),t=e?.getAttribute(`content`);return t?{token:t,header:e?.getAttribute(`data-header`)||`RequestVerificationToken`}:null}async function Nn(e,{lenient:t=!1}={}){let n=await e.text();if(n){if((e.headers.get(`content-type`)||``).includes(`json`)){if(!t)return JSON.parse(n);try{return JSON.parse(n)}catch{return n}}return n}}async function Pn(e,t,n){let r=new TextDecoder,i=e.getReader(),a=``;for(;;){let{done:e,value:o}=await i.read();if(e)break;a+=r.decode(o,{stream:!0}),n({event:{target:{responseText:a,status:t}}})}return a+=r.decode(),a}function Fn({fetch:e=(...e)=>globalThis.fetch(...e)}={}){async function t(t,n,r,i={}){let a={...i.headers},o;if(typeof FormData<`u`&&r instanceof FormData){for(let e of Object.keys(a))e.toLowerCase()===`content-type`&&delete a[e];o=r}else r!==void 0&&(a[`Content-Type`]=`application/json`,o=JSON.stringify(r));if(!jn.has(t)){let e=Mn();e&&(a[e.header]=e.token)}let s=i.signal,c=s,l,u,d=()=>l?.abort(s?.reason);(i.timeout??0)>0&&(l=new AbortController,c=l.signal,s?.aborted?l.abort(s.reason):s?.addEventListener(`abort`,d,{once:!0}),u=setTimeout(()=>l?.abort(new DOMException(`The request timed out.`,`TimeoutError`)),i.timeout));try{let r={method:t,headers:a,credentials:`same-origin`};o!==void 0&&(r.body=o),c&&(r.signal=c);let s=await e(n,r);if(!s.ok){let e=/* @__PURE__ */ Error(`Request failed with status ${s.status}`);throw e.response={status:s.status,data:await Nn(s,{lenient:!0})},e}let l;return l=i.responseType===`arraybuffer`?await s.arrayBuffer():typeof i.onDownloadProgress==`function`&&s.body?await Pn(s.body,s.status,i.onDownloadProgress):await Nn(s),{data:l,status:s.status}}finally{clearTimeout(u),s?.removeEventListener(`abort`,d)}}return{get:(e,n)=>t(`GET`,e,void 0,n),post:(e,n,r)=>t(`POST`,e,n,r),put:(e,n,r)=>t(`PUT`,e,n,r),delete:(e,n)=>t(`DELETE`,e,void 0,n)}}function In(n){let r,i=!1,a=!1,o=t(`div`,`wui-chat-nudge`,{role:`status`});o.hidden=!0;let s=t(`button`,`wui-chat-nudge-text`,{type:`button`}),c=t(`button`,`wui-chat-nudge-close`,{type:`button`});c.append(e(`x`,14)),o.append(s,c);function l(){clearTimeout(r),r=void 0}function u(){l(),a=!0,o.hidden=!0}s.addEventListener(`click`,()=>{o.hidden=!0,n.onActivate()}),c.addEventListener(`click`,()=>{u(),n.onDismiss()});function d(e){l(),a||i||(r=setTimeout(()=>{r=void 0,s.textContent=e.text,c.setAttribute(`aria-label`,e.label),o.hidden=!1,i=!0},e.delaySeconds*1e3))}function f(){l(),o.remove()}return{el:o,schedule:d,cancel:l,dismiss:u,isShown:()=>i,destroy:f}}function Ln(e,t){e.addEventListener(`click`,()=>t()),e.addEventListener(`keydown`,e=>{(Te(e)||e.key===` `)&&(e.preventDefault(),t())})}function Rn(e){let{list:n,getLabels:r,getFeatures:i,onOpen:a}=e,o=e.now??(()=>Date.now()),s=t(`div`,`wui-chat-empty-rows wui-chat-empty-rows--past`);s.hidden=!0;let c=!1;function l(e,n){let r=t(`div`,`card card-pad-sm card-clickable wui-chat-empty-row`,{role:`button`,tabindex:`0`}),i=t(`div`,`card-body wui-chat-empty-row-body`),s=t(`span`,`wui-chat-empty-row-title`);s.textContent=e.title||n.earlierChat;let c=t(`span`,`wui-chat-empty-row-time`,{title:D(e.lastActivityDateTimeUtc)});return c.textContent=u(e.lastActivityDateTimeUtc,o()),i.append(s,c),r.append(i),Ln(r,()=>a(e.publicId)),r}function d(){if(c)return;let e=n.getState().items;if(i().History!==!0||e.length===0){s.replaceChildren(),s.hidden=!0;return}let t=r();s.replaceChildren(...e.slice(0,20).map(e=>l(e,t))),s.hidden=!1}let f=n.subscribe(d);return{el:s,refresh(){i().History===!0&&n.load().catch(e=>globalThis.reportError?.(e))},paint:d,dispose(){c=!0,f()}}}var zn=`https://www.google.com/recaptcha/api.js?render=`;function Bn(e){return e!==void 0&&typeof e.ready==`function`&&typeof e.execute==`function`}var Vn=/* @__PURE__ */ new Map;function Hn(e){let t=Vn.get(e);if(t!==void 0)return t;let n=new Promise((t,n)=>{let r=globalThis.grecaptcha;if(Bn(r)){t(r);return}let i=document.createElement(`script`);i.src=zn+encodeURIComponent(e),i.async=!0;let a=t=>{Vn.delete(e),n(Object.assign(Error(t),{code:`captcha_unavailable`}))};i.addEventListener(`load`,()=>{let e=globalThis.grecaptcha;e===void 0||typeof e.ready!=`function`?a(`The reCAPTCHA script loaded without grecaptcha.`):e.ready(()=>{let e=globalThis.grecaptcha;Bn(e)?t(e):a(`reCAPTCHA became ready without execute.`)})}),i.addEventListener(`error`,()=>{Vn.delete(e),n(/* @__PURE__ */ Error(`The reCAPTCHA script did not load.`))}),document.head.append(i)});return Vn.set(e,n),n}async function Un(e,t){let n=await Hn(e);await new Promise(e=>n.ready(()=>e()));let r=await n.execute(e,{action:t});if(!r)throw Object.assign(/* @__PURE__ */ Error(`reCAPTCHA returned no token.`),{code:`captcha_unavailable`});return r}var Wn=/* @__PURE__ */ new Set([`Assistant`,`Agent`,`Script`]),Gn=/* @__PURE__ */ new WeakMap;function Kn(e,t,n){let{labels:i,features:a,title:o,busy:s,assistantName:c}=n;if(M(t.parts)!==``){if(a.Share&&v()){let n=r(`ghost`,i.share,`share`,()=>void(async()=>{let e=Zn([t],a,i,o,!1,c);e!==``&&await m({title:o,text:e})===`failed`&&tr(n.parentElement,i.shareFailed)})());n.disabled=s===!0,e.append(n)}if(a.Print){let t=r(`ghost`,i.print,`printer`,()=>{try{let e=t.closest(`.wui-chat`),n=t.closest(`li.wui-chat-message`);if(!(e instanceof HTMLElement)||!(n instanceof HTMLElement))throw Error(`printReply needs a message inside the wui-chat root`);w(e,n,{title:o,printedOn:$n(i)})}catch{er(t,i.printFailed)}});e.append(t)}}}function qn(e,t,n){if(t.streaming||t.thinking||t.loading||t.conversationId===null||t.messages.filter(e=>e.stored&&Wn.has(e.author.kind)&&M(e.parts)!==``).length===0){e.hidden=!0;return}let{labels:r,features:i}=n,a=!!i.Share&&v(),o=!!i.Print;if(!a&&!o){e.hidden=!0;return}let s=[a,o,t.messages.length,r.shareConversation,r.printConversation].join(`|`);e.dataset.sig!==s&&(e.dataset.sig=s,e.replaceChildren(),a&&e.append(Yn(e,r,i,n)),o&&e.append(Xn(e,r,n))),e.hidden=!1}function Jn(e,t,n,i){return e.iconOnly?g(t,n,i):r(`ghost`,t,n,i)}function Yn(e,t,n,r){return Jn(r,t.shareConversation,`share`,()=>void(async()=>{let i=r.getState(),a=Qn(i,r),o=Zn(i.messages.filter(e=>e.stored),n,t,a,!0,i.profile?.assistant.name);await m({title:a,text:o})===`failed`&&tr(e,t.shareFailed)})())}function Xn(e,t,n){let r=Jn(n,t.printConversation,`printer`,()=>{try{let r=e.closest(`.wui-chat`);if(!(r instanceof HTMLElement))throw Error(`printConversation needs the wui-chat root`);c(r,{title:Qn(n.getState(),n),printedOn:$n(t)})}catch{n.iconOnly?tr(e,t.printFailed):er(r,t.printFailed)}});return r}function Zn(e,t,n,r,i,a){let o=k(e,{labels:n,title:r,figureText:t.FigureText,...a===void 0?{}:{assistantName:a}});return ge(o,{heading:i,speakers:i})}function Qn(e,t){return typeof e.title==`string`&&e.title!==``?e.title:t.title}function $n(e){return e.printedOn(j((/* @__PURE__ */ new Date()).toISOString()))}function er(e,t){let n=e.lastChild;if(!(n instanceof Text))return;let r=Gn.get(n);r&&clearTimeout(r.timer);let i=r??{original:n.data};n.data=t,i.timer=setTimeout(()=>{n.data=i.original,Gn.delete(n)},be),Gn.set(n,i)}function tr(e,t){if(!e)return;let n=document.createElement(`span`);n.className=`wui-chat-action-notice`,n.setAttribute(`role`,`status`),n.textContent=t,e.append(n),setTimeout(()=>n.remove(),be)}var nr=`data-wchat-docked`,rr=`--wui-chat-docked-width`,ir=420,ar=/* @__PURE__ */ new Set;function or(e,t){let n=document.documentElement;n.setAttribute(nr,e),n.style.setProperty(rr,t)}function sr(){let e=document.documentElement;e.removeAttribute(nr),e.style.removeProperty(rr)}function cr(e){let t=n({...e,layout:`docked`,role:`dialog`,launcher:!0}),r={},i=e.position,a=!1,o=null,s=()=>`${Math.round(t.panel.getBoundingClientRect().width)||ir}px`;function c(){ar.add(r),or(i,s()),typeof ResizeObserver==`function`&&(o=new ResizeObserver(()=>document.documentElement.style.setProperty(rr,s())),o.observe(t.panel))}function l(){o?.disconnect(),o=null,ar.delete(r),ar.size===0&&sr()}function u(e){t.setOpen(e),e&&!a?(a=!0,c()):!e&&a&&(a=!1,l())}function d(e){t.setAppearance(e),e.position!==void 0&&(i=e.position,a&&document.documentElement.setAttribute(nr,i))}function f(){u(!1)}return{...t,setOpen:u,setAppearance:d,destroy:f}}function lr(e){return n({...e,layout:`embedded`,role:`region`,launcher:!1})}var ur=`wchat:peeked`,dr=576,fr=200;function pr(e){let t=n({...e,layout:`launcher`,role:`dialog`,launcher:!0}),{root:r,panel:i}=t;if(!t.nudgeHost||!t.launcherButton)throw Error(`a launcher shell always has its launcher`);let a=t.nudgeHost,o=t.launcherButton,s={peek:!1,peekSeconds:3,hideWhileOpen:!1,expressive:!1};o.dataset.state=`closed`;let c=!1,l=!1,u,d,f=()=>s.hideWhileOpen||s.expressive;function p(){!s.peek||c||l||a.dataset.launcher!==`idle`||globalThis.innerWidth<dr||globalThis.sessionStorage.getItem(ur)!==null||(globalThis.sessionStorage.setItem(ur,`1`),a.dataset.launcher=`peeking`,u=setTimeout(()=>{u=void 0,a.dataset.launcher===`peeking`&&(a.dataset.launcher=`idle`)},s.peekSeconds*1e3))}a.addEventListener(`animationend`,e=>{e.target===a&&a.dataset.launcher===`idle`&&p()});function m(e){if(e!==l){if(l=e,clearTimeout(u),u=void 0,e)clearTimeout(d),d=void 0,f()?(a.dataset.launcher=`hidden`,a.toggleAttribute(`inert`,!0)):a.dataset.launcher===`peeking`&&(a.dataset.launcher=`idle`);else if(f()){let e=i.contains(document.activeElement);d=setTimeout(()=>{d=void 0,a.toggleAttribute(`inert`,!1),a.dataset.launcher=`idle`,e&&o.focus()},fr)}}o.dataset.state=e?`open`:`closed`,t.setOpen(e)}function h(e){e.reduced!==void 0&&(c=!!e.reduced),e.peek!==void 0&&(s.peek=e.peek),e.peekSeconds!==void 0&&(s.peekSeconds=e.peekSeconds),e.hideWhileOpen!==void 0&&(s.hideWhileOpen=e.hideWhileOpen),e.expressive!==void 0&&(s.expressive=e.expressive===!0),e.phoneMode!==void 0&&r.classList.toggle(`wui-chat--sheet`,e.phoneMode===`Sheet`),e.sheetHeightDvh!==void 0&&r.style.setProperty(`--wui-chat-sheet-height`,`${e.sheetHeightDvh}dvh`),e.sheetMaxHeightPx!==void 0&&r.style.setProperty(`--wui-chat-sheet-max-height`,`${e.sheetMaxHeightPx}px`),t.setAppearance(e),!f()&&a.dataset.launcher===`hidden`&&!l&&(a.dataset.launcher=`idle`),a.dataset.launcher===`idle`&&p()}return{...t,nudgeHost:a,launcherButton:o,setOpen:m,setAppearance:h}}function mr(e){return n({...e,layout:`full-page`,role:`region`,launcher:!1})}var hr=/* @__PURE__ */ new Set([`Agent`,`Customer`]);function gr(){let e=document.createElement(`div`);e.className=`wui-chat-loader-typing`,e.setAttribute(`aria-hidden`,`true`),e.hidden=!0;let t=document.createElement(`span`);t.className=`wui-chat-loader-typing-orb`;let n=document.createElement(`span`);n.className=`wui-chat-loader-typing-dots`;for(let e=0;e<3;e++){let e=document.createElement(`span`);e.className=`wui-chat-loader-typing-dot`,n.append(e)}e.append(t,n);function r({active:n,reduced:r,authorKind:i}){e.hidden=!n,e.classList.toggle(`wui-chat-loader--reduced`,r===!0),t.hidden=hr.has(i)}function i(){e.remove()}return{el:e,update:r,destroy:i}}var _r=3,vr={Primary:`wui-chat-starter--primary`,Cta:`wui-chat-starter--cta`};function yr(e,t){e.addEventListener(`click`,()=>t()),e.addEventListener(`keydown`,e=>{(Te(e)||e.key===` `)&&(e.preventDefault(),t())})}function br(n){let r=t(`h2`,`wui-chat-greeting`),i=t(`div`,`wui-chat-empty-hero`),a=t(`p`,`wui-chat-empty-intro`);a.hidden=!0,i.append(t(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),r,a);let o=t(`div`,`wui-chat-empty-extra`);o.hidden=!0;let s=t(`div`,`wui-chat-starters`,{role:`group`}),c=t(`div`,`wui-chat-empty-rows`),l=t(`div`,`wui-chat-empty-past`),u=t(`div`,`wui-chat-empty`,{role:`group`}),d=gr();u.append(d.el,i,o,s,c,l);let f;function p(r,i){let a=r.variant===null?void 0:vr[r.variant],o=t(`button`,[`wui-chat-starter`,a??``].filter(Boolean).join(` `),{type:`button`});return o.style.setProperty(`--wui-chat-i`,String(i)),r.icon&&o.append(e(r.icon,16)),o.append(document.createTextNode(r.label)),o.addEventListener(`click`,()=>n.onStarter(r)),o}function m(e,r){let i=t(`div`,`card card-pad-sm card-clickable wui-chat-empty-row`,{role:`button`,tabindex:`0`}),a=t(`div`,`card-body wui-chat-empty-row-body`),o=t(`span`,`wui-chat-empty-row-label`);o.textContent=r.resumeLast;let s=t(`span`,`wui-chat-empty-row-title`,{title:e.title||r.untitled});s.textContent=e.title||r.untitled;let c=t(`span`,`wui-chat-empty-row-time`);return c.textContent=j(e.lastActivityDateTimeUtc),a.append(o,s,c),i.append(a),yr(i,()=>n.onResume()),i}function h(e,r,i){let a=i?t(`div`,`card card-pad-sm card-clickable wui-chat-empty-row`,{role:`button`,tabindex:`0`}):t(`div`,`card card-pad-sm wui-chat-empty-row`),o=t(`div`,`card-body wui-chat-empty-row-body`),s=t(`span`,`wui-chat-empty-row-label`);s.textContent=r.ticketAria(e.number);let c=t(`span`,`wui-chat-empty-row-title`);c.textContent=e.subject;let l=t(`span`,`wui-chat-empty-row-status`);return l.textContent=dt(e.status,r),o.append(s,c,l),a.append(o),i&&yr(a,()=>n.onTicket(e)),a}function g(e,n){if(e.features?.OpenTickets!==!0||!e.openTickets?.length)return null;let r=t(`div`,`wui-chat-open-tickets`,{role:`group`,"aria-label":n.openTickets});return r.append(...e.openTickets.slice(0,_r).map(t=>h(t,n,e.ticketsClickable===!0))),r}function _(e){let{labels:t}=e;r.textContent=e.greeting??``;let n=e.intro??``;a.textContent=n,a.hidden=!n,u.setAttribute(`aria-label`,t.emptyTitle);let i=e.starters??[];s.setAttribute(`aria-label`,t.starters),s.hidden=!e.showStarters||i.length===0,s.replaceChildren(...i.map(p));let o=e.resume??null,l=g(e,t);c.hidden=o===null&&l===null,c.replaceChildren(...[o===null?null:m(o,t),l].filter(e=>e!==null))}function v(e){clearTimeout(f),u.classList.remove(`wui-chat-empty--revealed`),u.classList.add(`wui-chat-empty--intro`),d.update({active:!0,reduced:!1,authorKind:`Assistant`}),f=setTimeout(()=>{f=void 0,d.update({active:!1,reduced:!1,authorKind:`Assistant`}),u.classList.replace(`wui-chat-empty--intro`,`wui-chat-empty--revealed`)},e)}return{el:u,paint:_,intro:v,extraHost:o,pastHost:l}}function xr(){let e=document.createElement(`div`);e.className=`wui-chat-loader-orb`;let t=document.createElement(`span`);t.className=`wui-chat-loader-orb-mark`,t.setAttribute(`aria-hidden`,`true`);let n=document.createElement(`span`);n.className=`wui-chat-loader-orb-glow`,n.setAttribute(`aria-hidden`,`true`);let r=document.createElement(`span`);r.className=`wui-chat-loader-orb-disc`,r.setAttribute(`aria-hidden`,`true`),t.append(n,r);let i=document.createElement(`span`);return i.className=`wui-chat-loader-orb-label`,e.append(t,i),{el:e,render(e){i.textContent!==e.label&&(i.textContent=e.label)}}}var Sr=150,Cr=1800;function wr(){let e=document.createElement(`div`);e.className=`wui-chat-loader-phrases`;let t=document.createElement(`span`);t.className=`wui-chat-loader-phrases-orb`,t.setAttribute(`aria-hidden`,`true`);let n=document.createElement(`span`);n.className=`wui-chat-loader-phrases-stage`,e.append(t,n);let r=null,i=null;function a(){return e.closest(`.wui-chat-loader`)?.classList.contains(`wui-chat-loader--reduced`)===!0}function o(e){if(e.label===r)return;r=e.label;let t=i,o=document.createElement(`span`);o.className=`wui-chat-loader-phrases-text wui-chat-loader-phrases-text--in`,o.textContent=e.label,o.style.animationDelay=`-${Math.round(performance.now()%Cr)}ms, 0s`,n.append(o),i=o,t&&(t.classList.remove(`wui-chat-loader-phrases-text--in`),t.classList.add(`wui-chat-loader-phrases-text--out`),t.style.animationDelay=`-${Math.round(performance.now()%Cr)}ms, 0s`,a()?t.remove():setTimeout(()=>t.remove(),Sr))}return{el:e,render:o}}var Tr=[`95%`,`80%`,`60%`];function Er(){let e=document.createElement(`div`);e.className=`wui-chat-loader-skeleton`;let t=document.createElement(`div`);t.className=`wui-chat-loader-skeleton-label`;let n=document.createElement(`div`);n.className=`wui-chat-loader-skeleton-body`;let r=document.createElement(`span`);r.className=`wui-chat-loader-skeleton-avatar`,r.setAttribute(`aria-hidden`,`true`),n.append(r);for(let e of Tr){let t=document.createElement(`span`);t.className=`wui-chat-loader-skeleton-line`,t.setAttribute(`aria-hidden`,`true`),t.style.width=e,n.append(t)}return e.append(t,n),{el:e,render(e){t.textContent!==e.label&&(t.textContent=e.label)}}}var Dr=`http://www.w3.org/2000/svg`;function Or(e){if(e===`done`){let e=document.createElementNS(Dr,`svg`);e.setAttribute(`viewBox`,`0 0 16 16`),e.setAttribute(`class`,`wui-chat-loader-steps-check`);let t=document.createElementNS(Dr,`path`);return t.setAttribute(`d`,`M3 8.5 6.5 12 13 4.5`),t.setAttribute(`pathLength`,`1`),e.append(t),e}let t=document.createElement(`span`);return t.className=e===`active`?`wui-chat-loader-steps-ring`:`wui-chat-loader-steps-dot`,t}function kr(){let e=document.createElement(`div`);e.className=`wui-chat-loader-steps`;let t=document.createElement(`span`);t.className=`wui-chat-loader-steps-pill`;let n=document.createElement(`ol`);n.className=`wui-chat-loader-steps-list`,e.append(t,n);let r=[];function i(){let e=document.createElement(`li`);e.className=`wui-chat-loader-steps-item`;let t=document.createElement(`span`);t.className=`wui-chat-loader-steps-icon`,t.setAttribute(`aria-hidden`,`true`);let i=document.createElement(`span`);i.className=`wui-chat-loader-steps-text`,e.append(t,i);let a={li:e,icon:t,text:i,state:null};return r.push(a),n.append(e),a}function a(e){let a=e.steps.length===0;for(t.hidden=!a,n.hidden=a,a&&t.textContent!==e.label&&(t.textContent=e.label),e.steps.forEach((t,n)=>{let a=r[n]??i();a.text.textContent!==t&&(a.text.textContent=t);let o=n<e.activeIndex?`done`:n===e.activeIndex?`active`:`pending`;a.state!==o&&(a.state=o,a.li.dataset.state=o,a.icon.replaceChildren(Or(o)))});r.length>e.steps.length;)r.pop()?.li.remove()}return{el:e,render:a}}var Ar={Steps:kr,Phrases:wr,Orb:xr,Skeleton:Er},jr=500;function Mr(){let e=document.createElement(`div`);e.className=`wui-chat-loader`,e.setAttribute(`role`,`status`),e.hidden=!0;let t=document.createElement(`span`);t.className=`wui-chat-loader-avatar`,t.setAttribute(`aria-hidden`,`true`);let n=document.createElement(`div`);n.className=`wui-chat-loader-body`;let r=document.createElement(`span`);r.className=`visually-hidden`,e.append(t,n,r);let a=null,o=null,s=0,c=null,l=0,u=null,d=!1;function f(){c!==null&&clearInterval(c),c=null}function p(){e.isConnected?(s+=1,m()):f()}function m(){if(!o||!a)return;let t=ue(a.style,a.steps,a.phrases,s);o.render(t),e.setAttribute(`aria-label`,t.label)}function h(){u!==null&&clearTimeout(u),u=null,d=!1,r.textContent=``}function g(e){!d&&u===null&&e&&(u=setTimeout(()=>{u=null,d=!0,r.textContent=e},jr))}function _(t){if(!t.active)a=null,e.hidden=!0,e.removeAttribute(`data-loading`),f(),h();else{if(!i(Ar,t.style))throw Error(`Unknown loader style. Use Steps, Phrases, Orb or Skeleton.`);if(!(t.intervalMs>0))throw Error(`Loader intervalMs must be a positive number.`);if(a={...t,steps:t.steps??[],phrases:t.phrases??[]},e.hidden=!1,e.setAttribute(`data-loading`,`true`),e.classList.toggle(`wui-chat-loader--reduced`,t.reduced===!0),!o||o.style!==t.style){let r=Ar[t.style]();n.replaceChildren(r.el),o={style:t.style,render:r.render},e.dataset.style=t.style,s=0}g(t.announce),t.reduced===!0?(f(),s=0):(c===null||l!==t.intervalMs)&&(f(),l=t.intervalMs,c=setInterval(p,l)),m()}}function v(){f(),h(),o=null,a=null,e.remove()}return{el:e,update:_,destroy:v}}function Nr({voice:e,getLabels:n,message:r}){if(r.streaming||!e.canSpeak()||pn(r.parts)===``)return null;let i=e.getStatus(),a=i.mode===`Speaking`&&i.messageId===r.id,o=n(),s=a?o.readAloudStop:o.readAloud,c=t(`button`,`wui-chat-action-btn wui-chat-speak`,{type:`button`,"aria-pressed":String(a),"aria-label":s,title:s});return c.append(rn(a?`stop`:`speaker`,16)),c.addEventListener(`click`,()=>{e.toggleSpeak(r.id,r.parts)}),c}function Pr({voice:e,getLabels:n,message:r}){let i=e.getStatus().note;if(i?.code!==`SpeakFailed`||i.messageId!==r.id)return null;let a=t(`span`,`wui-chat-action-notice`,{role:`status`});return a.textContent=mn(i,n()),a}function Fr(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.author.kind===`Visitor`&&n.stored)return n}}var Ir=/* @__PURE__ */ new Set([`Assistant`,`Agent`]),Lr=/* @__PURE__ */ new Set([`Assistant`,`Agent`,`Script`]),Rr=/* @__PURE__ */ new Set([`Visitor`,`Customer`]),zr=48,Br=120,Vr={author:{kind:`Assistant`,displayName:null,avatarUrl:null}},Hr={warning:`alert-triangle`,danger:`alert-circle`};function Ur(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=zr}function Wr(e){let{kind:t,displayName:n}=e.author;return t===`Agent`?`Agent:${n??``}`:t===`Script`?`Assistant`:t}function Gr(e){for(let t=e?.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e}=getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t}return null}function Kr(e){let t=e.textContent?.trim();t&&!e.hasAttribute(`aria-label`)&&(e.setAttribute(`aria-label`,t),e.setAttribute(`title`,t))}function qr(e){return e.reduced===!0}function Jr(n,r,i){let a=t(`button`,`${s(`ghost`,`sm`)} wui-chat-action-btn`,{type:`button`,"aria-label":n,title:n}),o=t(`span`);return o.textContent=n,a.append(e(r,14),o),a.addEventListener(`click`,i),{node:a,text:o}}function Yr(e,t){return e.profile?.assistant.name??t.panelTitle}function Xr(e,t,n){return e.author.displayName==null?e.author.kind===`Visitor`||e.author.kind===`Customer`?n.you:e.author.kind===`Agent`?n.agent:t.profile?.assistant.name??n.assistant:e.author.displayName}function Zr(e){let n=t(`li`,`wui-chat-day`,{role:`presentation`}),r=t(`span`);return r.textContent=e,n.append(r),n}function Qr(n){let r=t(`ol`,`wui-chat-thread`),i=t(`div`,`wui-chat-log`,{role:`log`,"aria-live":`polite`});i.append(r);let a=Mr(),o=t(`li`,`wui-chat-message wui-chat-message--assistant wui-chat-message--loading`),c=t(`div`,`wui-chat-loader-slot`);c.append(a.el),o.append(c);let l=!1,u,d=t(`li`,`wui-chat-message wui-chat-message--assistant wui-chat-message--greeting`,{"data-run-start":``,"data-restored":``}),f=t(`div`,`wui-chat-message-body`),p=t(`p`,`wui-chat-text`);f.append(p),d.append(f);let m=t(`button`,`wui-chat-jump`,{type:`button`}),h=t(`div`,`wui-chat-jump-slot`);h.hidden=!0,h.append(m);let g=null,_=!0,v=null,y=null,b=/* @__PURE__ */ new Map,x=``,S=null;function C(e,t){return{kind:e.kind,part:e,tag:t[e.kind]}}function w(e,t,r){return Object.assign(document.createElement(e),{message:r,turn:n.makeTurnApi(r.id),chatPart:t})}function T(e){return t(`div`,`wui-chat-part wui-chat-part--${e.toLowerCase()}`)}function E(e,n,r,i){e.parts=[];let a=[],o=e=>{let t=C(e,r),i=T(t.kind);return i.append(w(t.tag,t.part,n)),i};for(let e of i(n))if(Array.isArray(e)){let n=t(`div`,`wui-chat-part-group`);n.append(...e.map(o)),a.push(n)}else a.push(o(e));e.body.replaceChildren(...a)}function O(e,t,r){let i=[];t.parts.forEach((a,o)=>{let s=C(a,r),c=e.parts[o];if(c&&c.kind===s.kind&&c.tag===s.tag){c.part!==s.part&&(c.element.message=t,c.element.turn=n.makeTurnApi(t.id),c.element.chatPart=s.part,c.part=s.part),i.push(c);return}let l=T(s.kind),u=w(s.tag,s.part,t);l.append(u),i.push({kind:s.kind,tag:s.tag,part:s.part,element:u,wrapper:l})}),e.parts=i,k(e.body,i.map(e=>e.wrapper))}function k(e,t){let n=new Set(t);for(let t of[...e.children])n.has(t)||t.remove();t.forEach((t,n)=>{e.children[n]!==t&&e.insertBefore(t,e.children[n]??null)})}function ee(n,r,i){let a=t(`div`,`wui-chat-rating`,{role:`group`,"aria-label":`${i.rateUp} / ${i.rateDown}`}),o=[[`Up`,i.rateUp,`thumbs-up`],[`Down`,i.rateDown,`thumbs-down`]];for(let[c,l,u]of o){let o=r.rating===c,d=t(`button`,`${s(o?`neutral`:`ghost`,`sm`)} wui-chat-action-btn`,{type:`button`,"aria-pressed":String(o),"data-rating":c,"aria-label":l,title:l}),f=t(`span`);f.textContent=l,d.append(e(u,14),f),d.addEventListener(`click`,()=>te(n,r,c,i)),a.append(d)}if(n.ratingNote){let e=t(`span`,null,{role:`status`});e.textContent=n.ratingNote,a.append(e)}return a}async function te(e,t,r,i){try{await n.onRate(t.id,r),e.ratingNote=i.rated}catch{e.ratingNote=i.ratingFailed}S&&N(S.state,S.context)}function A(e,r,i,a,o){let{labels:s}=a,c=i.features,l=r.author.kind,u=M(r.parts),d=[];if(c.Copy&&Lr.has(l)&&u){let t=Jr(s.copy,`copy`,()=>void(async()=>{await xe(u)&&(t.text.textContent=s.copied,t.node.dataset.done=``,t.node.setAttribute(`aria-label`,s.copied),t.node.title=s.copied,clearTimeout(e.copyTimer),e.copyTimer=setTimeout(()=>{t.text.textContent=s.copy,delete t.node.dataset.done,t.node.setAttribute(`aria-label`,s.copy),t.node.title=s.copy},be))})());d.push(t.node)}let f=n.getVoice?.();if(f&&Lr.has(l)){let e=Nr({voice:f,getLabels:()=>s,message:r});e&&d.push(e);let t=Pr({voice:f,getLabels:()=>s,message:r});t&&d.push(t)}if(Lr.has(l)){let e=t(`div`);Kn(e,r,{labels:s,features:c,title:Yr(i,s),assistantName:i.profile?.assistant.name,busy:i.streaming||i.thinking});for(let t of e.children)Kr(t);d.push(...e.childNodes)}let p=i.messages.some(e=>e.author.kind===`Visitor`&&e.stored);o&&l===`Assistant`&&!i.streaming&&!i.thinking&&c.Regenerate&&p&&d.push(Jr(s.regenerate,`refresh`,()=>n.onRegenerate()).node);let m=Fr(i.messages);c.Edit&&m?.id===r.id&&!i.streaming&&!i.thinking&&d.push(Jr(s.edit,`pencil`,()=>n.getSession().startEdit(r.id)).node),c.Rating&&r.stored&&Ir.has(l)&&d.push(ee(e,r,s)),e.actions.hidden=d.length===0,e.actions.replaceChildren(...d)}function ne(e){let n=b.get(e.id);if(n)return n;let r=t(`li`,`wui-chat-message`),i=t(`span`,`wui-chat-author visually-hidden`),a=t(`div`,`wui-chat-message-body`),o=t(`div`,`wui-chat-message-actions`);r.append(i,a,o);let s={li:r,author:i,body:a,actions:o,head:null,parts:[],copyTimer:void 0,ratingNote:null};return b.set(e.id,s),s}function j(e,t,n,r){let i=n?.author.kind===`Agent`&&t.author.kind===`Agent`&&(n.author.displayName??``)===(t.author.displayName??``);e.head?.remove(),e.head=t.author.kind===`Agent`&&!i?ct(t.author,r):null,e.head&&e.li.insertBefore(e.head,e.body)}function ie(e,t,r,i,a,o){let{labels:s}=i;e.li.className=`wui-chat-message wui-chat-message--${t.author.kind.toLowerCase()}`,e.li.toggleAttribute(`data-restored`,t.restored===!0),e.li.toggleAttribute(`data-run-start`,!o||Wr(o)!==Wr(t)),t.streaming?e.li.setAttribute(`aria-busy`,`true`):e.li.removeAttribute(`aria-busy`),e.author.textContent=`${Xr(t,r,s)}: `,j(e,t,o,s);let c=n.getRenderers(),l=n.getLayoutParts();typeof l==`function`?E(e,t,c,l):O(e,t,c),t.streaming?(e.actions.hidden=!0,e.actions.replaceChildren()):A(e,t,r,i,a)}function ae(n,r){let i=t(`li`,`wui-chat-message wui-chat-message--system wui-chat-message--notice`),a=t(`div`,`wui-chat-notice wui-chat-notice--${n}`,{role:n===`danger`?`alert`:`status`}),o=t(`span`,`wui-chat-notice-icon`,{"aria-hidden":`true`});o.append(e(Hr[n],16));let s=t(`div`,`wui-chat-notice-body`),c=t(`span`,`wui-chat-notice-text`);return c.textContent=r,s.append(c),a.append(o,s),i.append(a),i}function oe(e,t){let n=e.resetsDateTimeUtc?` ${t.dailyLimitRefresh(D(e.resetsDateTimeUtc))}`:``;return ae(`warning`,`${e.message}${n}`)}function se(r,i){let{labels:a}=i,o=r.turnError,s=o?.code??``;if(o&&s===`daily_limit`)return oe(o,a);if(s.endsWith(`feature_off`))return ae(`danger`,r.turnError?.message||a.stopped);let c=t(`li`,`wui-chat-message wui-chat-message--system wui-chat-message--error`),l=t(`p`,`wui-chat-error`,{role:`alert`});l.textContent=r.turnError?.message||a.stopped;let u=e(`alert-circle`,16);if(u.setAttribute(`aria-hidden`,`true`),c.append(u,l),r.features.Retry){let e=t(`div`,`wui-chat-message-actions`);e.append(Jr(a.retry,`rotate-ccw`,()=>n.onRetry()).node),c.append(e)}return c}function ce(){return r.closest(`.wui-chat`)}function le(){return r.closest(`.wui-chat-body`)??Gr(r)}function ue(e){ce()?.classList.toggle(`wui-chat--scrolled`,e.scrollTop>0),Ur(e)&&(h.hidden=!0)}function de(){g!==null&&(_=Ur(g),ue(g))}function fe(e){i.nextElementSibling!==h&&i.parentNode&&i.after(h),e!==g&&(g?.removeEventListener(`scroll`,de),g=e,e.addEventListener(`scroll`,de,{passive:!0}),!v&&typeof ResizeObserver==`function`&&(v=new ResizeObserver(()=>{_&&g&&(g.scrollTop=g.scrollHeight)}),v.observe(r)))}m.addEventListener(`click`,()=>{let e=le(),t=S?.context.reduced===!0;e?.scrollTo({top:e.scrollHeight,behavior:t?`auto`:`smooth`}),h.hidden=!0,m.blur()});function pe(e,t){let n=e.messages[e.messages.length-1],r=n?`${n.id}|${n.parts.length}|${M(n.parts).length}`:``;if(r===x)return;let i=x===``||e.conversationId!==y;x=r,y=e.conversationId;let a=le();a&&(fe(a),i||t||n!==void 0&&Rr.has(n.author.kind)?(a.scrollTop=a.scrollHeight,h.hidden=!0,_=!0):(h.hidden=!1,_=!1),ue(a))}function N(e,t){S={state:e,context:t};let{labels:n}=t;i.setAttribute(`aria-label`,n.thread),m.textContent=n.newMessages??`New messages`;let s=le();s&&fe(s);let c=s===null||s.clientHeight===0||Ur(s),f=[],h=/* @__PURE__ */ new Set,g=e.messages.filter(e=>!(e.streaming&&e.parts.length===0)),_=g[0],v=_!==void 0&&Rr.has(_.author.kind)&&e.greeting?e.greeting:null,y=null,x=e=>{let t=re(e.createdDateTimeUtc,n);t!==y&&(y=t,f.push(Zr(t)))};v&&_&&(x(_),p.textContent=v,f.push(d)),g.forEach((n,r)=>{let i=ne(n);h.add(n.id),x(n);let a=g[r-1]??(v?Vr:null);ie(i,n,e,t,r===g.length-1,a),f.push(i.li)});for(let e of[...b.keys()])h.has(e)||b.delete(e);e.agentTyping&&f.push(lt(e.agentTyping,n)),e.thinking?(clearTimeout(u),u=void 0,o.classList.remove(`wui-chat-message--leaving`),l=!0,a.update({active:!0,style:t.loaderStyle,steps:e.steps,phrases:t.phrases,intervalMs:t.intervalMs,reduced:t.reduced,announce:t.assistantName?.trim()?n.preparingAnswer(t.assistantName):void 0}),f.push(o)):l&&u===void 0&&!qr(t)?(o.classList.add(`wui-chat-message--leaving`),u=setTimeout(()=>{u=void 0,l=!1,o.classList.remove(`wui-chat-message--leaving`),a.update({active:!1}),S&&N(S.state,S.context)},Br),f.push(o)):u===void 0?(l=!1,a.update({active:!1})):f.push(o),!e.streaming&&(e.turnError||e.stopped)&&f.push(se(e,t)),k(r,f),pe(e,c)}function me(e){return b.get(e)?.li??null}function P(){clearTimeout(u),a.destroy(),g?.removeEventListener(`scroll`,de),v?.disconnect(),b.clear(),S=null,i.remove()}return{el:i,paint:N,find:me,destroy:P}}var $r=[`launcher`,`docked`,`full-page`,`embedded`],ei=[`end`,`start`],ti={steps:`Steps`,phrases:`Phrases`,orb:`Orb`,skeleton:`Skeleton`},ni={on:`On`,reduced:`Reduced`},ri=[`auto`,`light`,`dark`];function ii(e){return ri.find(t=>t===e)??`auto`}var ai=`wchat:muted`,oi=6e4,si=400,ci=[`labels`,`pageContext`,`compact`,`expressive`,`open`,`layoutParts`,`getCaptchaToken`,`attribution`,`openAttachment`,`openCitation`,`openTarget`,`openTicket`,`onNavigate`,`resolveLink`,`emptyContent`,`onPanelSwitch`,`preloadPanelSwitch`],li={...cn};function ui(e,t){if(!T.includes(e))throw Error(`Unknown part kind "${e}". Use one of ${T.join(`, `)}.`);if(typeof t!=`string`||!t.includes(`-`))throw Error(`Renderer tag "${t}" must be a custom element name containing a hyphen.`)}function X(e,t){return n=>{let r=n.toLowerCase(),a=i(t,r)?t[r]:void 0;if(a===void 0)throw Error(`<wui-chat ${e}> must be one of ${Object.keys(t).join(`, `)}, got "${n}".`);return a}}function Z(e){return t=>{let n=Number(t);if(!Number.isInteger(n)||n<0)throw Error(`<wui-chat ${e}> must be a whole number of pixels, got "${t}".`);return n}}function Q(e){return t=>{if(t===``||t===`true`)return!0;if(t===`false`)return!1;throw Error(`<wui-chat ${e}> must be true or false, got "${t}".`)}}var $=e=>e.split(`,`).map(e=>e.trim()).filter(Boolean),di=[[`launcher-style`,`launcher`,`style`,X(`launcher-style`,{round:`Round`,pill:`Pill`})],[`entrance`,`launcher`,`entrance`,X(`entrance`,{"slide-up":`SlideUp`,"bounce-in":`BounceIn`,"fade-in-pulse":`FadeInPulse`,"spin-scale":`SpinScale`,"wiggle-in":`WiggleIn`,"elastic-in":`ElasticIn`,rise:`Rise`,none:`None`})],[`idle`,`launcher`,`idle`,X(`idle`,{"float-and-pulse":`FloatAndPulse`,ring:`Ring`,none:`None`})],[`label-reveal`,`launcher`,`labelReveal`,X(`label-reveal`,{bubble:`Bubble`,expand:`Expand`})],[`compact`,`launcher`,`compact`,Q(`compact`)],[`launcher-mark`,`launcher`,`mark`,X(`launcher-mark`,{icon:`Icon`,avatar:`Avatar`,orb:`Orb`})],[`panel-height`,`panel`,`height`,X(`panel-height`,{fixed:`Fixed`,content:`Content`})],[`reply-avatars`,`panel`,`replyAvatars`,Q(`reply-avatars`)],[`greeting-loader-ms`,`panel`,`greetingLoaderMs`,Z(`greeting-loader-ms`)],[`panel-motion`,`panel`,`motion`,X(`panel-motion`,{spring:`Spring`,gentle:`Gentle`,none:`None`})],[`panel-width`,`panel`,`widthPx`,Z(`panel-width`)],[`panel-max-height`,`panel`,`maxHeightPx`,Z(`panel-max-height`)],[`panel-bottom-gap`,`panel`,`bottomGapPx`,Z(`panel-bottom-gap`)],[`phone-max-width`,`phone`,`maxWidthPx`,Z(`phone-max-width`)],[`phone-mode`,`phone`,`mode`,X(`phone-mode`,{"full-screen":`FullScreen`,sheet:`Sheet`})],[`sheet-height-dvh`,`phone`,`sheetHeightDvh`,Z(`sheet-height-dvh`)],[`sheet-max-height`,`phone`,`sheetMaxHeightPx`,Z(`sheet-max-height`)],[`input-ring`,`input`,`ring`,Q(`input-ring`)],[`send-reveal`,`input`,`sendReveal`,X(`send-reveal`,{"on-text":`OnText`,always:`Always`})],[`send-icon`,`input`,`sendIcon`,e=>e],[`lift-selectors`,`avoid`,`liftSelectors`,$],[`menu-selectors`,`avoid`,`menuSelectors`,$],[`dark-selectors`,`avoid`,`darkSelectors`,$],[`autoopen-busy-selectors`,`avoid`,`autoOpenBusySelectors`,$],[`autoopen-optout-selector`,`avoid`,`autoOpenOptOutSelector`,e=>e]],fi={layout:`launcher`,position:`end`,"offset-x":`24`,"offset-y":`24`,loader:`steps`,motion:`on`,icon:`chat`},pi=[`base`,`layout`,`position`,`offset-x`,`offset-y`,`loader`,`screen`,`motion`,`theme`,`icon`,`avatar`,`narrow`,...di.map(([e])=>e).filter(e=>e!==`compact`)],mi=e=>e.replace(/-([a-z0-9])/g,(e,t)=>t.toUpperCase());function hi(e){let t={launcher:{},panel:{},phone:{},input:{},avoid:{}};for(let[n,r,i,a]of di){let o=e.getAttribute(n);o!=null&&(t[r][i]=a(o))}let n=e.getAttribute(`motion`),r=e.getAttribute(`avatar`),i=e.getAttribute(`expressive`),a={...t,...n==null?{}:{motion:X(`motion`,ni)(n)},...r?{avatar:r}:{},...i==null?{}:{expressive:Q(`expressive`)(i)}};return fe(a)}function gi(e){let t=e.getAttribute(`loader`)??`steps`,n=i(ti,t)?ti[t]:void 0;if(n===void 0)throw Error(`<wui-chat loader> must be one of ${Object.keys(ti).join(`, `)}, got "${t}".`);return n}function _i(e){let t=e.getAttribute(`narrow`);if(t!=null&&t!==``)return Object.fromEntries($(t).map(e=>[e,!1]))}function vi(e){return e===ai?globalThis.localStorage:globalThis.sessionStorage}var yi={get:e=>vi(e).getItem(e),set:(e,t)=>vi(e).setItem(e,t)};function bi(e){return globalThis.innerWidth<=e.phone.maxWidthPx}function xi(e){let t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)}function Si(e){return e.features.HumanHandoff===!0&&e.conversationState===`Open`&&e.messages.some(e=>e.author.kind===`Visitor`||e.author.kind===`Customer`)&&!e.streaming&&!e.thinking}function Ci(e,t){if(e.conversationState===`WaitingForAgent`)return t.statusWaitingForAgent;if(e.conversationState===`WithAgent`){let n=e.agent?.displayName;return t.statusWithAgent(typeof n==`string`&&n.trim()!==``?n:t.handoffAgentFallback)}return t.headerStatus}function wi(e,t,n){return t.PanelSwitch!==!0||typeof n!=`function`?null:e===`docked`?`full-page`:e===`full-page`?`docked`:null}function Ti(e){if(!$r.some(t=>t===e))throw Error(`<wui-chat layout> must be one of ${$r.join(`, `)}, got "${e}".`)}function Ei(e){if(!ei.some(t=>t===e))throw Error(`<wui-chat position> must be one of ${ei.join(`, `)}, got "${e}".`)}function Di(e,t){let n=e[t];delete e[t],e[t]=n}function Oi(e){return e==null?{}:Object(e)}var ki=0,Ai=class extends De{static get observedAttributes(){return[...pi,`compact`,`expressive`,`open`,`labels`,`page-context`,`narrow`].filter((e,t,n)=>n.indexOf(e)===t)}constructor(){super(),ki+=1,this._uid=`wui-chat-${ki}`,this._built=!1,this._session=null,this._unsubscribe=null,this._voice=null,this._voiceConversationId=void 0,this._labelsProp=void 0,this._pageContextProp=void 0,this._layoutParts=null,this._renderers={...li},this._rendererApi={define:(e,t)=>{ui(e,t),this._renderers[e]=t,this._render()},map:this._renderers},this._captchaToken=null,this._attribution=null,this._openAttachmentProp=null,this._openCitationProp=null,this._openTargetProp=null,this._resolveLinkProp=null,this._openTicketProp=void 0,this._emptyContentProp=null,this._onPanelSwitchProp=null,this._preloadPanelSwitchProp=null,this._preloaded=!1,this._pastList=null,this._past=null,this._pastRefreshed=!1,this._historyShown=!1,this._openedConversation=null,this._lastOpen=!1,this._openTrigger=`manual`,this._focusTimer=null,this._nudgeArmed=!1,this._seeded=!1,this._wasLoading=!1,this._seen=/* @__PURE__ */ new Set,this._sound=null,this._behaviour=null,this._autoOpen=null,this._avoid=null,this._motion=null,this._phone=null,this._requesting=!1,this._onKeyDown=e=>{e.key===`Escape`&&this._session?.getState().open&&(e.stopPropagation(),this._session.close(`escape`))}}get session(){return this._session??null}get conversationId(){return this._session?.getState().conversationId??null}get labels(){return de({...Oi(h(this,`labels`)),...this._labelsProp})}set labels(e){this._labelsProp=e??void 0,this._render()}get pageContext(){return this._pageContextProp===void 0?h(this,`page-context`):this._pageContextProp}set pageContext(e){this._pageContextProp=e===null?void 0:e}get compact(){let e=this.getAttribute(`compact`);return e!=null&&Q(`compact`)(e)}set compact(e){this.toggleAttribute(`compact`,e===!0||e===``||e===`true`)}get expressive(){let e=this.getAttribute(`expressive`);return e!=null&&Q(`expressive`)(e)}set expressive(e){this.toggleAttribute(`expressive`,e===!0||e===``||e===`true`)}get open(){return this.hasAttribute(`open`)}set open(e){this.toggleAttribute(`open`,e===!0||e===``||e===`true`)}get renderers(){return this._rendererApi}get layoutParts(){return this._layoutParts}set layoutParts(e){this._layoutParts=typeof e==`function`?e:null,this._render()}get getCaptchaToken(){return this._captchaToken}set getCaptchaToken(e){this._captchaToken=typeof e==`function`?e:null}get attribution(){return this._attribution}set attribution(e){this._attribution=typeof e==`function`?e:null}get openAttachment(){return this._openAttachmentProp??(e=>this._defaultOpenAttachment(e))}set openAttachment(e){this._openAttachmentProp=typeof e==`function`?e:null}get openCitation(){return this._openCitationProp??((e,t)=>this._defaultOpenCitation(e,t))}set openCitation(e){this._openCitationProp=typeof e==`function`?e:null}get openTarget(){return this._openTargetProp??(e=>this._defaultOpenTarget(e))}set openTarget(e){this._openTargetProp=typeof e==`function`?e:null}get openTicket(){return this._openTicketProp}set openTicket(e){this._openTicketProp=typeof e==`function`?e:void 0}get onNavigate(){return this._onNavigateProp}set onNavigate(e){this._onNavigateProp=typeof e==`function`?e:void 0}get resolveLink(){return this._resolveLinkProp}set resolveLink(e){this._resolveLinkProp=typeof e==`function`?e:null}get emptyContent(){return this._emptyContentProp}set emptyContent(e){if(e!==null&&!(e instanceof Node))throw TypeError(`emptyContent must be a Node or null`);this._emptyContentProp=e,this._applyEmptyContent()}get onPanelSwitch(){return this._onPanelSwitchProp}set onPanelSwitch(e){this._onPanelSwitchProp=typeof e==`function`?e:null}get preloadPanelSwitch(){return this._preloadPanelSwitchProp}set preloadPanelSwitch(e){this._preloadPanelSwitchProp=typeof e==`function`?e:null}connectedCallback(){this._adoptEarlyProperties();let e=this._assertLayout();if(this._assertPosition(),this.base.trim()===``)throw TypeError(`<wui-chat> needs a base path, e.g. base="/api/assistant".`);this._built||this._build(),this._shell||this._buildShell(e),this._session||this._createSession(),this._past||this._createPast(),this._unsubscribe||=this.requireSession().subscribe(()=>this._render()),this._render()}_adoptEarlyProperties(){for(let e of ci)i(this,e)&&Di(this,e)}disconnectedCallback(){this._voice?.stop(),this._session?.stop(),this._unsubscribe?.(),this._unsubscribe=null,this._disposePast(),this._shell?.destroy?.(),document.removeEventListener(`keydown`,this._onKeyDown),this._avoid?.destroy(),this._avoid=null,this._autoOpen?.cancel(),this._autoOpen=null,this._motion?.destroy(),this._motion=null}attributeChangedCallback(e,t,n){if(this._built&&t!==n){if(e===`layout`)this._buildShell(this._assertLayout());else if(e===`position`)this._assertPosition();else if(e===`base`||e===`screen`||e===`narrow`)this._resetSession();else if(e===`motion`)this._motion?.destroy(),this._motion=null;else if(e===`open`&&this._session){let e=this._session.getState().open;this.open!==e&&this._setOpen(this.open,`manual`)}this._render()}}toggle(){this._session&&(this._session.getState().open?this._session.close(`button`):this._setOpen(!0,`manual`))}close(){this._voice?.stop(),this._session?.close(`button`)}newConversation(){this._voice?.stop(),this._session?.newConversation(),this._past?.refresh()}reset(){this._voice?.stop(),this._session?.reset()}_setOpen(e,t){this._session&&(e?(this._openTrigger=t,this._session.open({trigger:t})):this._session.close(`button`))}_assertLayout(){let e=this.layout;return Ti(e),e}_assertPosition(){Ei(this.position)}get _position(){let e=this.position;return Ei(e),e}_isLauncherLike(){return this.layout===`launcher`||this.layout===`docked`}requireSession(){if(!this._session)throw TypeError(`wui-chat: _session is not ready; the element is not connected`);return this._session}requireVoice(){if(!this._voice)throw TypeError(`wui-chat: _voice is not ready; the element is not connected`);return this._voice}requireMotion(){if(!this._motion)throw TypeError(`wui-chat: _motion is not ready; the element is not connected`);return this._motion}requirePastList(){if(!this._pastList)throw TypeError(`wui-chat: _pastList is not ready; the element is not connected`);return this._pastList}requireNudgeHost(){if(!this._shell.nudgeHost)throw TypeError(`wui-chat: the launcher shell has no nudge host`);return this._shell.nudgeHost}_build(){this._built=!0,this._header=On({onNew:()=>this.newConversation(),onHistory:()=>this._toggleHistory(),onClose:()=>this.close(),onMute:()=>{this._session&&this._session.setMuted(!this._session.getState().muted)},onSwitch:()=>this._switchPanel(),titleId:`${this._uid}-title`}),this._starters=br({onStarter:e=>this.requireSession().submit(e.message),onResume:()=>this.requireSession().resumeLast(),onTicket:e=>{typeof this.openTicket==`function`&&this.openTicket({ticketId:e.ticketId,number:e.number})}}),this._applyEmptyContent(),this._voice=hn({getState:()=>this.requireSession().getState(),getToken:()=>this.requireSession().client.getSpeechToken()}),this._voice.subscribe(()=>this._render()),this._thread=Qr({getRenderers:()=>this._renderers,getLayoutParts:()=>this._layoutParts,makeTurnApi:e=>this._makeTurnApi(e),onRetry:()=>this.requireSession().retry(),onRegenerate:()=>this.requireSession().regenerate(),onRate:(e,t)=>this.requireSession().rate(e,t),getSession:()=>this.requireSession(),getVoice:()=>this._voice}),this._composer=Cn({voice:this._voice,onSubmit:e=>this.requireSession().submit(e),onStop:()=>this.requireSession().stop(),onAttach:e=>this.requireSession().attach(e),onRemove:e=>this.requireSession().removeAttachment(e),onCancelEdit:()=>this.requireSession().cancelEdit(),onTyping:()=>this.requireSession().notifyTyping(),onDraftApplied:()=>this.requireSession().consumeDraft()}),this._footer=Dn(),this._history=An({getClient:()=>this.requireSession().client,getLabels:()=>this.labels,getFeatures:()=>this.requireSession().getState().features,onOpen:e=>{Promise.allSettled([this.requireSession().openConversation(e)]),this._toggleHistory(!1)},onDeleted:e=>{e===this.conversationId&&this.requireSession().newConversation()}}),this._nudge=In({onActivate:()=>this._setOpen(!0,`manual`),onDismiss:()=>{}}),this._status=t(`p`,null,{role:`status`}),this._status.hidden=!0,this._errorEl=t(`p`,`wui-chat-profile-error`,{role:`alert`}),this._errorEl.hidden=!0,this._liveStatus=t(`p`,`wui-chat-live-status`,{role:`status`}),this._liveStatus.hidden=!0,this._talk=t(`button`,`${s(`outline`,`sm`)} wui-chat-handoff-request`,{type:`button`}),this._talk.addEventListener(`click`,()=>this._requestHandoff()),this._liveRetry=t(`button`,s(`ghost`,`sm`),{type:`button`}),this._liveRetry.addEventListener(`click`,()=>this.requireSession().resumeLive()),this._liveError=t(`p`,`wui-chat-live-error`,{role:`alert`}),this._liveError.hidden=!0,this._live=t(`div`,`wui-chat-live`),this._live.append(this._liveStatus,this._talk,this._liveRetry,this._liveError),this._live.hidden=!0,this._body=t(`div`,`wui-chat-body`),this._body.append(this._starters.el,this._thread.el,this._live,this._history.el,this._status,this._errorEl),this._foot=t(`div`,`wui-chat-foot`),this._foot.append(...this._composer.nodes,this._footer.el)}_buildShell(e){let t={launcher:pr,docked:cr,"full-page":mr,embedded:lr};this._shell?.destroy?.(),this._avoid?.destroy(),this._avoid=null,this._autoOpen?.cancel(),this._autoOpen=null,this._lastOpen=!1,this._launcherPlayed=!1;let n=t[e]({id:`${this._uid}-panel`,position:this._position,onToggle:()=>this.toggle()});n.panel.append(this._header.el,this._body,this._foot),n.panel.setAttribute(`aria-labelledby`,`${this._uid}-title`),n.panel.addEventListener(`keydown`,e=>{e.key===`Tab`&&_(n.panel,e)}),n.nudgeHost&&n.nudgeHost.prepend(this._nudge.el),this._shell=n,this.replaceChildren(n.root)}_createSession(){let e=ee(Fn(),{base:this.base}),t=_i(this);this._session=te(e,{...this.screen?{screen:this.screen}:{},...t===void 0?{}:{narrow:t},pageContext:()=>this.pageContext,attribution:()=>this._attribution?.()??null,behaviour:()=>this._session?.getState().features.BehaviourStarters?this._behaviour?.()??null:null,prefs:yi,reducedMotion:()=>this._motion?.reduced??!1,schedule:xi,getCaptchaToken:e=>{if(this._captchaToken)return this._captchaToken(e);let t=this._session?.getState().profile?.captcha?.siteKey;return t?Un(t,e):Promise.resolve(null)},onEvent:(e,t)=>{this.dispatchEvent(new CustomEvent(`wui-chat-event`,{bubbles:!0,detail:{name:e,data:t}}))},onError:()=>{},labels:this.labels}),this._unsubscribe=null,this._lastOpen=!1,this._openApplied=!1,this._seeded=!1,this._wasLoading=!1,this._seen=/* @__PURE__ */ new Set,this._pastRefreshed=!1}_createPast(){this._pastList=A({client:this.requireSession().client,pageSize:20}),this._past=Rn({list:this._pastList,getLabels:()=>this.labels,getFeatures:()=>this.requireSession().getState().features,onOpen:e=>{Promise.allSettled([this.requireSession().openConversation(e)])}}),this._starters.pastHost.append(this._past.el)}_disposePast(){this._past&&(this._past.el.remove(),this._past.dispose(),this.requirePastList().dispose(),this._past=null,this._pastList=null)}_applyEmptyContent(){if(!this._starters)return;let e=this._starters.extraHost;e.replaceChildren(...this._emptyContentProp?[this._emptyContentProp]:[]),e.hidden=!this._emptyContentProp}_switchPanel(){let e=this.requireSession().getState(),t=this._onPanelSwitchProp,n=wi(this.layout,e.features,t);if(t===null||n===null)return;n===`full-page`&&this.close();let r={from:this.layout,to:n,conversationId:e.conversationId,draft:this._composer.getDraft()};S(()=>t.call(this,r),{target:n,reduced:this._motion?.reduced===!0}).then(()=>document.querySelector(`.wui-chat--${n} .wui-chat-input`)?.focus()).catch(e=>globalThis.reportError?.(e))}async _requestHandoff(){this._requesting=!0,this._liveError.hidden=!0,this._render();try{await this.requireSession().requestHandoff()}catch(e){let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;this._liveError.textContent=typeof t==`string`&&t||this.labels.errorGeneric,this._liveError.hidden=!1}finally{this._requesting=!1,this._render()}}_paintLive(e,t,n){let r=e.live===`Lost`,i=Si(e);this._liveStatus.hidden=!r,this._liveStatus.textContent=r?t.liveLost:``,this._liveRetry.hidden=!r,this._liveRetry.textContent=t.retry,this._talk.hidden=!i,this._talk.textContent=t.talkToPerson,this._talk.disabled=this._requesting,this._live.hidden=n||!r&&!i}_resetSession(){this._voice?.stop(),this._unsubscribe?.(),this._unsubscribe=null,this._session?.dispose(),this._session=null,this._disposePast(),this._history.dispose(),this.isConnected&&(this._createSession(),this._createPast(),this._unsubscribe=this.requireSession().subscribe(()=>this._render()))}_toggleHistory(e=!this._historyShown){this._historyShown=e,e?this._history.show():this._history.hide(),this._render()}_makeTurnApi(e){let t=ne(this.requireSession(),{messageId:e,labels:this.labels,openAttachment:e=>this.openAttachment(e),openCitation:t=>this.openCitation(e,t),openTarget:e=>this.openTarget(e),openTicket:this.openTicket,onNavigate:this.onNavigate});return t.resolveLink=this.resolveLink,t}_defaultOpenAttachment(e){this.requireSession().client.getAttachment(e.attachmentId).then(t=>{let n=URL.createObjectURL(new Blob([t],{type:e.contentType}));window.open(n,`_blank`,`noopener`),setTimeout(()=>URL.revokeObjectURL(n),oi)}).catch(e=>globalThis.reportError?.(e))}_defaultOpenCitation(e,t){let n=this._thread.find(e);if(n){for(let e of n.querySelectorAll(`[data-marker]`))if(e.dataset.marker===String(t)){e.focus();return}}}_defaultOpenTarget(e){/^https?:\/\//i.test(e)?window.open(e,`_blank`,`noopener`):window.location.assign(e)}_render(){this._built&&this._session&&this._paint(this._session.getState())}_paint(e){e.conversationId!==this._voiceConversationId&&(this._voiceConversationId=e.conversationId,this.requireVoice().stop());let t=this.labels,n=e.profile,r=this._isLauncherLike();if(!n){this.hidden=r,this._header.el.hidden=!0,this._starters.el.hidden=!0,this._thread.el.hidden=!0,this._history.el.hidden=!0,this._foot.hidden=!0,this._errorEl.hidden=e.profileError==null,e.profileError&&(this._errorEl.textContent=e.profileError.message),this._status.hidden=e.profileError!=null,this._status.textContent=t.loadingConversation,this._shell.panel.setAttribute(`aria-busy`,String(e.profileError==null));return}if(this._shell.panel.removeAttribute(`aria-busy`),!e.features.VisitorChat){this.hidden=!0,this._status.hidden=!0;return}this.hidden=!1;let i=e.features,a=hi(this);this._ensureRuntime(e,n,a,t);let o=e.loading,s=e.loadError,c=e.messages.length===0&&!o,l=this._historyShown&&i.History===!0,u=e.messages.some(e=>e.author.kind===`Visitor`||e.author.kind===`Customer`),d=wi(this.layout,i,this._onPanelSwitchProp),f=e.streaming||e.thinking;this._header.paint({labels:t,title:n.assistant.name,tagline:n.assistant.tagline,status:Ci(e,t),canNew:!f,showNew:this.layout===`full-page`||u,showHistory:i.History,showClose:r||this.layout===`full-page`&&d!==null,switchTo:d,canSwitch:!f,viewingHistory:l,showMute:i.Sounds&&n.experience.sound.muteControl,muted:e.muted}),qn(this._header.conversation,e,{labels:t,features:i,title:n.assistant.name??t.panelTitle,getState:()=>this.requireSession().getState(),iconOnly:!0}),l&&(this._header.conversation.hidden=!0),this._starters.el.hidden=!c||l,c&&e.open&&!this._introPlayed&&a.panel.greetingLoaderMs>0&&!this.requireMotion().reduced&&(this._introPlayed=!0,this._starters.intro(a.panel.greetingLoaderMs)),c&&this._starters.paint({labels:t,greeting:e.greeting,intro:n.assistant.intro,starters:e.starters,showStarters:i.Starters&&!e.streaming,resume:!i.History&&i.ResumeLast?e.lastConversation:null,openTickets:e.openTickets,features:e.features,ticketsClickable:typeof this.openTicket==`function`}),i.History&&!this._pastRefreshed&&(this._pastRefreshed=!0,this._past?.refresh()),this._past?.paint();let p=!c&&!o&&!s&&!l;this._thread.el.hidden=!p,p&&this._thread.paint(e,{labels:t,loaderStyle:gi(this),reduced:this._motion?.reduced??!1,phrases:n.experience.pacing.thinkingPhrases,intervalMs:n.experience.pacing.phraseIntervalMs,assistantName:n.assistant.name}),this._paintLive(e,t,l),this._status.hidden=!o||l,this._status.textContent=t.loadingConversation,this._errorEl.hidden=!s||l,s&&(this._errorEl.textContent=s.message),this._foot.hidden=l,this._composer.paint({state:e,labels:t,maxLength:n.limits.maxMessageLength,accept:n.limits.contentTypes.join(`,`),draft:e.draft??null,sendIcon:a.input.sendIcon}),this._footer.paint({labels:t,profile:n}),this._history.el.hidden=!l,this._syncOpen(e,n,i,t,r),this._syncConversation(e),this._playSounds(e)}_ensureRuntime(e,t,n,r){let i=e.features;this._motion||(this._motion=a(n,t.experience),this._motion.subscribe(()=>this._render())),i.Sounds&&!this._sound&&(this._sound=l(t.experience.sound,yi)),!i.Sounds&&this._sound&&(this._sound=null),i.BehaviourStarters&&!this._behaviour&&(this._behaviour=f(t.start.behaviour?.servicePathPrefixes??[]));let o=this._isLauncherLike();o&&!this._avoid&&this.layout===`launcher`&&(this._avoid=p(n.avoid,t.experience.launcher,this.requireNudgeHost())),this.layout===`launcher`&&i.AutoOpen&&!this._autoOpen&&(this._autoOpen=x(t.experience.autoOpen,n,{open:()=>this._setOpen(!0,`auto`),isOpen:()=>this.requireSession().getState().open,panelRect:()=>this._shell.panel.getBoundingClientRect()}));let s=bi(n);this._shell.setLabels(r),this._shell.setAppearance({position:this._position,offsetX:this.hasAttribute(`offset-x`)?Z(`offset-x`)(this.getAttribute(`offset-x`)??``):void 0,offsetY:this.hasAttribute(`offset-y`)?Z(`offset-y`)(this.getAttribute(`offset-y`)??``):void 0,width:`${n.panel.widthPx}px`,maxHeight:n.panel.maxHeightPx,bottomGap:n.panel.bottomGapPx,reduced:this._motion.reduced,sendReveal:n.input.sendReveal,inputRing:n.input.ring,panelMotion:n.panel.motion,theme:ii(this.getAttribute(`theme`)),icon:this.icon,launcherStyle:n.launcher.style,compact:n.launcher.compact,labelReveal:n.launcher.labelReveal,entrance:n.launcher.entrance,idle:n.launcher.idle,launcherMark:n.launcher.mark,panelHeight:n.panel.height,replyAvatars:n.panel.replyAvatars,avatar:n.avatar,expressive:n.expressive,phone:s,hoverLabel:t.experience.launcher.hoverLabel,peek:t.experience.launcher.peek,peekSeconds:t.experience.launcher.peekSeconds,hideWhileOpen:t.experience.launcher.hideWhileOpen,phoneMode:n.phone.mode,sheetHeightDvh:n.phone.sheetHeightDvh,sheetMaxHeightPx:n.phone.sheetMaxHeightPx,launcherState:this._launcherPlayed?void 0:`entering`}),this._launcherPlayed=!0,this._shell.root.classList.toggle(`wui-chat--phone`,o&&bi(n))}_syncOpen(e,t,n,r,i){if(i){if(!this._openApplied&&(this._openApplied=!0,this.hasAttribute(`open`)&&!e.open))this._setOpen(!0,`manual`);else if(this._shell.setOpen(e.open),this.toggleAttribute(`open`,e.open),e.open!==this._lastOpen&&(this._lastOpen=e.open,this._onOpenChange(e.open)),e.open)this._nudge.cancel(),this._nudgeArmed=!1,this._autoOpen?.cancel();else if(n.Nudges&&this.layout===`launcher`&&!this._nudgeArmed){let e=pe(t,n);e&&(this._nudge.schedule({text:e.text,delaySeconds:e.delaySeconds,label:r.nudgeDismiss}),this._nudgeArmed=!0)}}}_onOpenChange(e){let t=bi(hi(this));if(e){if(document.addEventListener(`keydown`,this._onKeyDown),this._sound?.play(`open`),this._past?.refresh(),this.layout===`docked`&&!this._preloaded&&typeof this._preloadPanelSwitchProp==`function`){this._preloaded=!0;let e=this._preloadPanelSwitchProp;Promise.allSettled([new Promise(t=>t(e.call(this)))]).then(e=>{for(let t of e)t.status===`rejected`&&globalThis.reportError?.(t.reason)})}if(t){let e=hi(this);this._phone={fit:y(this._shell.panel,e),unlock:b(this._thread.el)}}else this._openTrigger===`manual`&&(this._focusTimer=setTimeout(()=>{this._focusTimer=null,this._composer.focus()},si))}else document.removeEventListener(`keydown`,this._onKeyDown),clearTimeout(this._focusTimer??void 0),this._focusTimer=null,this._phone?.fit.destroy(),this._phone?.unlock(),this._phone=null,this._historyShown&&(this._historyShown=!1,this._history.hide(),this._render()),d(this._shell.launcherButton)}_syncConversation(e){let t=this.getAttribute(`conversation-id`);t&&t!==this._openedConversation&&!e.loading&&(this._openedConversation=t,e.conversationId!==t&&Promise.allSettled([this.requireSession().openConversation(t)]))}_playSounds(e){if(e.loading){this._wasLoading=!0;for(let t of e.messages)this._seen.add(t.id)}else if(this._wasLoading||!this._seeded){this._wasLoading=!1,this._seeded=!0;for(let t of e.messages)this._seen.add(t.id)}else for(let t of e.messages)this._seen.has(t.id)||(this._seen.add(t.id),this._announce(t))}_announce(e){if(!this._sound||e.restored||e.parts.some(e=>e.kind===`Notice`))return;let t=e.author.kind;if(t===`Visitor`)e.stored||this._sound.play(`sent`);else if(t===`Assistant`||t===`Script`||t===`Agent`){this._sound.play(`reply`);let e=this.requireSession().getState().profile;e?.experience.sound.vibrate&&C(e.experience.sound.vibrateMs,this._sound.isMuted())}}};Object.defineProperty(Ai.prototype,"layout",{get(){return this.getAttribute(`layout`)??fi.layout},set(e){this.setAttribute(`layout`,String(e))}});for(let e of pi)e!==`layout`&&Object.defineProperty(Ai.prototype,mi(e),{configurable:!0,get(){return this.getAttribute(e)??fi[e]??``},set(t){t==null?this.removeAttribute(e):this.setAttribute(e,String(t))}});function ji(){typeof customElements<`u`&&!customElements.get(`wui-chat`)&&customElements.define(`wui-chat`,Ai)}ji();export{Ai as WuiChat,Fn as createFetchChatHttp,cn as defaultRenderers,ji as defineChat};
|
|
1
|
+
import{A as e,D as t,E as n,M as r,O as i,P as a,S as o,T as s,_ as c,a as l,b as u,c as d,d as f,f as p,h as m,j as h,k as g,l as _,m as v,n as y,o as b,p as x,r as S,s as C,v as w,w as T,x as E,y as D}from"./web-DU1iwrnX.js";import{CHAT_HANDOFF_REQUEST_ID as O,buildTranscript as k,createChatClient as ee,createChatSession as te,createConversationList as A,createTurnApi as ne,formatChatDate as j,formatChatDay as re,formatChatValue as ie,formatClipTime as ae,formatFigure as oe,formatFileSize as se,isHandoffTarget as ce,isSafeLinkUrl as le,loaderView as ue,mergeLabels as de,mergeLook as fe,messagePlainText as M,resolveNudge as pe,showsCaptchaNote as N,sniffAudioType as me,toFigureRuns as P,toFigureText as he,transcriptToText as ge,voiceClipBars as _e}from"@webority/chat-core";import{linkTarget as ve,parseInline as ye}from"@webority/markdown-core";import{COPY_FEEDBACK_MS as be,copyTextToClipboard as xe,emptyValueLabel as Se,formatNumber as Ce,glyphNode as we,isImeSafeEnter as Te}from"@webority/ui-elements/helpers";import"@webority/ui-elements/elements/lightbox";import"@webority/ui-elements/elements/markdown";import"@webority/ui-elements/elements/code-block";var Ee=`@webority/chat-elements needs a browser DOM; import @webority/chat-core on the server`;if(typeof HTMLElement>`u`)throw Error(Ee);var De=HTMLElement,F=class extends De{#e=null;#t=null;#n=null;#r=!1;get chatPart(){return this.#e}set chatPart(e){this.#e=e,this.#i()}get message(){return this.#t}set message(e){this.#t=e,this.#i()}get turn(){return this.#n}set turn(e){this.#n=e,this.#i()}get activeTurn(){let e=this.#n;if(e===null)throw Error(`${this.localName} has no turn yet`);return e}connectedCallback(){this.#r=!0,this.#i()}disconnectedCallback(){this.#r=!1,queueMicrotask(()=>{this.isConnected||this.disposePart()})}#i(){this.#r&&this.#e&&this.#t&&this.#n&&this.renderPart(this.#e,this.#t,this.#n)}renderPart(e,t,n){throw Error(`${this.localName} must override renderPart`)}disposePart(){}};function I(e,t){typeof customElements>`u`||customElements.get(e)||customElements.define(e,t)}function L(e,t,n=null,r=null){let i=e.createElement(t);return n&&(i.className=n),r!==null&&(i.textContent=r),i}function Oe(e,t,n){let r=we(t,{size:n});return r===null?null:e.adoptNode(r)}var ke={Confirmed:`actionConfirmed`,Rejected:`actionRejected`,Expired:`actionExpired`,Failed:`actionFailed`},Ae=/^https?:\/\//i,je={strong:`strong`,em:`em`,strike:`s`};function R(e,t=null,n=null){let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r}function Me(e,t){return{id:e,label:t,action:`Send`,target:null,navigateAfterMs:null,icon:null,variant:null}}function Ne(e){return e.type in je}function Pe(e,t){for(let n of t)if(n.type===`text`||n.type===`citation`)e.append(document.createTextNode(n.text));else if(n.type===`link`){if(Ae.test(n.href)){let t=R(`a`);t.href=n.href,t.target=`_blank`,t.rel=`noopener noreferrer`,Pe(t,n.children),e.append(t)}else Pe(e,n.children)}else if(Ne(n)){let t=R(je[n.type]);Pe(t,n.children),e.append(t)}else n.type===`code`&&e.append(R(`code`,null,n.text))}function Fe(e){let t=R(`p`,`wui-chat-action-consent`);return Pe(t,ye(e)),t}function Ie(e){let t=R(`ul`,`wui-chat-action-lines`);for(let n of e)t.append(R(`li`,null,n));return t}function Le(e){let t=R(`dl`,`wui-chat-action-lines`);for(let n of e){let e=R(`div`,`wui-chat-action-line`),r=n.indexOf(`: `);r===-1?e.append(R(`dt`,null,n)):e.append(R(`dt`,null,n.slice(0,r)),R(`dd`,null,n.slice(r+2))),t.append(e)}return t}function Re(e){return typeof e!=`object`||!e||!(`message`in e)?``:typeof e.message==`string`?e.message:``}I(`wui-chat-part-action`,class extends F{_part;_turn;_working;_error;_menuOpen;constructor(){super(),this._part=null,this._turn=null,this._working=null,this._error=null,this._menuOpen=!1}renderPart(e,t,n){this._part?.actionId!==e.actionId&&(this._working=null,this._error=null,this._menuOpen=!1),this._part=e,this._turn=n,this._paint()}_paint(e=null){let t=this._part,n=this._turn;t!==null&&n!==null&&(this.replaceChildren(this._view(t,n)),e===`first`?this.querySelector(`[role="menuitem"]`)?.focus():e===`edit`&&this.querySelector(`.wui-chat-action-edit`)?.focus())}async _run(e){let t=this._part,n=this._turn;if(t===null||n===null)return;let r=t.actionId;this._working=e,this._error=null,this._paint();try{e===`confirm`?await n.confirmAction(r):await n.rejectAction(r),this._working=null}catch(e){if(this._part?.actionId!==r)return;this._working=null,this._error=Re(e)||n.labels.actionFailed,this._paint()}}_view(e,t){let n=t.labels,r=e.state===`Pending`,i=t.features.LeadRecap===!0&&e.actionKind===`ChatLeadCapture`,a=i&&(e.editFields?.length??0)>0,o=R(`div`,`wui-chat-action wui-chat-action--${e.state.toLowerCase()}`);if(o.append(R(`strong`,`wui-chat-action-title`,e.title)),e.lines.length>0&&o.append(i?Le(e.lines):Ie(e.lines)),i&&e.consentText&&o.append(Fe(e.consentText)),e.note&&o.append(R(`p`,`wui-chat-action-note`,e.note)),r||o.append(this._status(e,n)),(r||a)&&o.append(this._buttons(e,n,i,r,a)),e.editFields&&a&&this._menuOpen&&o.append(this._menu(e.editFields,n,t)),this._error){let e=R(`p`,`wui-chat-action-error`,this._error);e.setAttribute(`role`,`alert`),o.append(e)}return o}_status(e,t){let n=R(`p`,`wui-chat-action-status wui-chat-action-status--${e.state.toLowerCase()}`);if(e.state===`Repeat`)n.textContent=e.decidedDateTimeUtc?t.actionRepeat(j(e.decidedDateTimeUtc)):t.actionDone;else if(e.state===`Done`){if(n.append(t.actionDone),e.decidedDateTimeUtc){let t=R(`time`,null,j(e.decidedDateTimeUtc));t.dateTime=e.decidedDateTimeUtc,n.append(` `,t)}}else{let r=ke[e.state];n.textContent=r===void 0?``:t[r]}return n}_buttons(e,t,n,r,i){let a=R(`div`,`wui-chat-action-buttons`),o=this._working;if(r){let r=n&&e.confirmLabel||t.actionConfirm,i=n&&e.rejectLabel||t.actionDismiss,s=R(`button`,`btn btn-primary btn-sm`,o===`confirm`?t.actionWorking:r);s.type=`button`,s.disabled=o!==null,s.addEventListener(`click`,()=>this._run(`confirm`));let c=R(`button`,`btn btn-soft-primary btn-sm`,i);c.type=`button`,c.disabled=o!==null,c.addEventListener(`click`,()=>this._run(`dismiss`)),a.append(s,c)}if(i){let e=R(`button`,`btn btn-soft-primary btn-sm wui-chat-action-edit`,t.editSomething);e.type=`button`,e.setAttribute(`aria-haspopup`,`menu`),e.setAttribute(`aria-expanded`,String(this._menuOpen)),e.disabled=!r||o!==null,e.addEventListener(`click`,()=>{this._menuOpen=!this._menuOpen,this._paint(this._menuOpen?`first`:`edit`)}),a.append(e)}return a}_menu(e,t,n){let r=R(`ul`,`list-group wui-chat-action-menu`);r.setAttribute(`role`,`menu`),r.setAttribute(`aria-label`,t.editSomething),r.addEventListener(`keydown`,e=>this._onMenuKey(e,r));for(let t of e){let e=R(`li`);e.setAttribute(`role`,`none`);let i=R(`button`,`list-group-item list-group-item-action wui-chat-action-menu-item`,t.label);i.type=`button`,i.setAttribute(`role`,`menuitem`),i.addEventListener(`click`,()=>{this._menuOpen=!1,n.chooseQuickReply(Me(`lead.edit:${t.id}`,t.label)),this._paint(`edit`)}),e.append(i),r.append(e)}return r}_onMenuKey(e,t){if(e.key===`Escape`){e.preventDefault(),this._menuOpen=!1,this._paint(`edit`);return}let n=[...t.querySelectorAll(`[role="menuitem"]`)],r=document.activeElement,i=r instanceof HTMLElement?n.indexOf(r):-1,a=n.length-1,o=(/* @__PURE__ */ new Map([[`ArrowDown`,i<a?i+1:0],[`ArrowUp`,i>0?i-1:a],[`Home`,0],[`End`,a]])).get(e.key);o!==void 0&&(e.preventDefault(),n[o]?.focus())}});var ze=null;async function Be(){await import(`@webority/ui-elements/chart`),await customElements.whenDefined(`wui-chart`)}async function Ve(){return ze??=Be().catch(e=>{throw ze=null,e}),ze}var He={sub:`wui-chat-sub`,sup:`wui-chat-sup`};function z(e,t){let n=e.ownerDocument??document;for(let r of t)if(r.kind===`sub`||r.kind===`sup`){let t=n.createElement(r.kind);t.className=He[r.kind],t.textContent=r.text,e.append(t)}else e.append(n.createTextNode(r.text))}function B(e,t){e.replaceChildren(),z(e,P(String(t??``)))}function V(e){return he(String(e??``))}function Ue(e){return oe(e)}var We=8,Ge=8,Ke={Bar:`column`,Line:`line`,Donut:`donut`};function qe(e,t){return e===`Bar`&&t>4?300:240}function Je(e,t){let n=e.chartType===`Donut`,r=n?e.series.slice(0,1):e.series.slice(0,We),i=r.map((e,n)=>({key:`s${n}`,label:V(e.name)||t.chart})),a=Object.fromEntries(i.map(e=>[e.key,null])),o=/* @__PURE__ */ new Map;r.forEach((e,t)=>{for(let n of e.points){let e=String(n.label),r=o.get(e);r===void 0&&(r={label:V(e),...a},o.set(e,r)),r[`s${t}`]=n.value}});let s=[...o.values()],c={type:Ke[e.chartType],title:V(e.title)||t.chart,x:{key:`label`,kind:`category`},series:i,data:s,height:qe(e.chartType,s.length)};return e.chartType===`Bar`&&s.length<=Ge&&(c.x.labelFit=`all`,c.valueLabels=!0),!n&&e.unit&&(c.y={label:V(e.unit)}),s.length===0&&(c.state=`empty`,c.emptyText=t.chartEmpty),c}I(`wui-chat-part-chart`,class extends F{#e=null;#t=0;#n=null;#r=null;#i=null;#a=null;renderPart(e,t,n){let r=JSON.stringify(e);if(r===this.#e)return;this.#e=r,this.#t+=1;let i=this.#t,a=this.ownerDocument??document,o=this.#o(a);if(this.#r?.remove(),this.#r=null,e.title){let t=L(a,`figcaption`,`wui-chat-chart-title`);B(t,e.title),o.figure.prepend(t),this.#r=t}let s=this.#i;if(s!==null){let t=Je(e,n.labels);Object.assign(s,{spec:t}),this.#s(o,s,t.state!==`empty`,n.labels)}else Ve().then(()=>{if(i!==this.#t||!this.isConnected)return;let t=Je(e,n.labels),r=a.createElement(`wui-chart`);Object.assign(r,{spec:t}),this.#i=r,o.body.replaceChildren(r),this.#s(o,r,t.state!==`empty`,n.labels)},()=>{i===this.#t&&this.isConnected&&this.#l(o.body,n.labels)})}disposePart(){this.#t+=1,this.#e=null}#o(e){if(this.#n===null){let t=L(e,`figure`,`wui-chat-chart`),n=L(e,`div`,`wui-chat-chart-body`);t.append(n),this.replaceChildren(t),this.#n={figure:t,body:n}}return this.#n}#s(e,t,n,r){if(!n){this.#a?.remove(),this.#a=null;return}if(!this.#a){let n=L(this.ownerDocument??document,`button`,`btn btn-link btn-sm wui-chat-chart-toggle`);n.type=`button`,n.addEventListener(`click`,()=>this.#c(e,t)),e.figure.append(n),this.#a=n}let i=t.getAttribute(`view`)===`table`;this.#a.setAttribute(`aria-pressed`,String(i)),this.#a.textContent=i?r.chartShowChart:r.chartShowTable}#c(e,t){let n=this.activeTurn,r=t.getAttribute(`view`)!==`table`;t.setAttribute(`view`,r?`table`:`chart`),this.#s(e,t,!0,n.labels)}#l(e,t){let n=L(this.ownerDocument??document,`p`,`wui-chat-chart-error`,t.chartLoadFailed);n.setAttribute(`role`,`status`),e.replaceChildren(n),this.#a?.remove(),this.#a=null}});var Ye={Positive:`wui-metric-tone-success`,Caution:`wui-metric-tone-warning`,Negative:`wui-metric-tone-danger`},Xe=/* @__PURE__ */ new Set([`Positive`,`Caution`,`Negative`]),Ze=.001;function Qe(e,t,n){let r=Ye[t.status],i=L(e,`div`,r?`wui-metric ${r}`:`wui-metric`);i.dataset.status=t.status;let a=L(e,`div`,`wui-metric-label`);B(a,t.label);let o=L(e,`div`,`wui-metric-value`);if(z(o,t.value!==0&&Math.abs(t.value)<Ze?Ue(t.value):[{kind:`text`,text:Ce(t.value)}]),t.unit){let n=L(e,`span`,`wui-chat-figure-unit`);B(n,t.unit),n.prepend(` `),o.append(n)}return Xe.has(t.status)&&o.append(L(e,`span`,`visually-hidden`,n.figureStatus(t.status))),i.append(a,o),i}I(`wui-chat-part-figures`,class extends F{#e=null;renderPart(e,t,n){let r=JSON.stringify(e);if(r===this.#e)return;if(this.#e=r,!e.figures||e.figures.length===0){this.replaceChildren();return}let i=this.ownerDocument??document,a=L(i,`div`,`wui-chat-figures`),o=L(i,`div`,`wui-metric-strip wui-metric-strip-sm wui-chat-figures-strip`);o.setAttribute(`role`,`group`),o.setAttribute(`aria-label`,n.labels.figures);for(let t of e.figures)o.append(Qe(i,t,n.labels));a.append(o),this.replaceChildren(a)}}),I(`wui-chat-part-file`,class extends F{renderPart(e,t,n){let r=n.openAttachment,i=typeof r==`function`,a=document.createElement(i?`button`:`span`);a.className=`wui-chat-file-chip`,i&&(a.setAttribute(`type`,`button`),a.setAttribute(`aria-label`,n.labels.fileOpen(e.fileName)),a.addEventListener(`click`,()=>r(e)));let o=Oe(document,`document-text`,16),s=document.createElement(`span`);s.className=`wui-chat-file-name`,s.textContent=e.fileName;let c=document.createElement(`span`);c.className=`wui-chat-file-size`,c.textContent=se(e.length),a.append(...[o,s,c].filter(e=>e!==null));let l=document.createElement(`div`);l.className=`wui-chat-file`,l.append(a),this.replaceChildren(l)}});var $e={Open:`info`,InProgress:`info`,WaitingOnCustomer:`warning`,Resolved:`success`,Closed:`neutral`,Cancelled:`neutral`},et=/^\/[/\\]/,tt=/^https?:\/\//i,nt=/[\t\r\n]/g;function rt(e){return typeof e==`string`&&e.trim()!==``}function it(e){return e.replace(nt,``)}function at(e){if(typeof e!=`string`)return!1;let t=it(e);return t.startsWith(`/`)?!et.test(t):tt.test(t)}function ot(e){if(typeof e!=`string`)return`?`;let t=e.split(/\s+/).filter(Boolean).slice(0,2).map(e=>([...e][0]??``).toUpperCase()).join(``);return t===``?`?`:t}function st(e,n){let r=e?.displayName,i=ot(rt(r)?r:n),a=t(`span`,`wui-chat-avatar`,{"aria-hidden":`true`}),o=e?.avatarUrl,s=typeof o==`string`?it(o):null;if(at(s)){let e=t(`img`,null,{alt:``,src:s,loading:`lazy`});e.addEventListener(`error`,()=>{a.textContent=i}),a.append(e)}else a.textContent=i;return a}function ct(e,n){let r=t(`div`,`wui-chat-agent-head`),i=t(`span`,`wui-chat-agent-name`),a=e?.displayName;i.textContent=rt(a)?a:n.agent;let o=t(`span`,`wui-chat-agent-role wui-chat-agent-tag`);return o.textContent=n.agent,r.append(st(e,n.agent),i,o),r}function lt(e,n){let r=e.displayName,i=t(`li`,`wui-chat-message wui-chat-message--agent wui-chat-message--typing`),a=t(`span`,`wui-chat-typing`);for(let e=0;e<3;e+=1)a.append(t(`span`,`wui-chat-typing-dot`,{"aria-hidden":`true`}));let o=t(`span`,`visually-hidden`);return o.textContent=n.agentTyping(rt(r)?r:n.agent),i.append(ct({kind:`Agent`,displayName:r,avatarUrl:null},n),a,o),i}function ut(e){return typeof e==`string`&&i($e,e)?$e[e]??null:null}function dt(e,t){return ut(e)===null?``:t.ticketStatus(e)}var ft=/* @__PURE__ */ new Set([`Requested`,`Waiting`]),pt=/* @__PURE__ */ new Set([`Requested`,`Waiting`,`Joined`]),mt=pt;function ht(e,t){let n=e?.displayName;return typeof n==`string`&&n.trim()!==``?n:t.handoffAgentFallback}function gt(){let e=t(`div`,`wui-chat-handoff-pulses`);for(let n=0;n<3;n+=1)e.append(t(`span`,`wui-chat-handoff-pulse`,{"aria-hidden":`true`}));return e}function H(e,n,r){let i=t(e,n);return i.textContent=r,i}function _t(e,n){let r=t(`div`,`wui-chat-handoff-body`);return r.append(H(`strong`,`wui-chat-handoff-title`,e),H(`p`,`wui-chat-handoff-text`,n)),r}function vt(e,n){if(typeof e.queuePosition!=`number`){let e=t(`span`,`wui-chat-system-line-stack`);return e.append(H(`p`,`wui-chat-handoff-text`,n.handoffWaiting),H(`p`,`wui-chat-handoff-text`,n.handoffQueuedText)),[gt(),e]}let r=t(`span`,`wui-chat-handoff-position`,{"aria-hidden":`true`});return r.textContent=String(e.queuePosition),[r,_t(n.handoffQueued(e.queuePosition),n.handoffQueuedText)]}function yt(e,n){let r=ht(e.agent,n),i=t(`span`,`wui-chat-handoff-agent`);return i.append(st(e.agent,n.handoffAgentFallback),t(`span`,`wui-chat-handoff-online`,{"aria-hidden":`true`})),[i,_t(n.handoffJoined(r),n.handoffJoinedText(r))]}function bt(e,t){switch(e.state){case`Requested`:return[gt(),H(`p`,`wui-chat-handoff-text`,t.handoffRequested)];case`Waiting`:return vt(e,t);case`Joined`:return yt(e,t);case`Left`:return[_t(t.handoffLeft(ht(e.agent,t)),t.handoffLeftText)];case`Ended`:return[_t(t.handoffEnded,t.handoffEndedText)];default:return null}}I(`wui-chat-part-handoff`,class extends F{_signature;constructor(){super(),this._signature=null}renderPart(e,n,r){let i=r.isLast,a=r.handoffSettled===!0&&ft.has(e.state),o=JSON.stringify([e.state,e.queuePosition,e.agent,i,r.features.HumanHandoff,r.busy,a]);if(o===this._signature)return;if(this._signature=o,a){this.replaceChildren();return}let s=bt(e,r.labels);if(s===null){this.replaceChildren();return}let c=t(`div`,`wui-chat-handoff wui-chat-handoff--${e.state.toLowerCase()}`);if(i&&ft.has(e.state)&&c.classList.add(`wui-chat-handoff--live`),i&&pt.has(e.state)&&c.setAttribute(`role`,`status`),mt.has(e.state)){c.classList.add(`wui-chat-system-line`);let e=t(`span`,`wui-chat-system-line-content`);e.append(...s),c.append(e)}else c.append(...s);this.replaceChildren(c)}}),I(`wui-chat-part-image`,class extends F{#e=null;#t=0;#n=null;renderPart(e,t,n){if(e.attachmentId===this.#e)return;this.#e=e.attachmentId;let r=this.ownerDocument??document,i=L(r,`figure`,`wui-chat-image`),a=L(r,`div`,`wui-chat-image-frame`);this.#n=a;let{width:o,height:s}=e;o!==null&&s!==null&&Number.isFinite(o)&&Number.isFinite(s)&&o>0&&s>0&&(a.style.aspectRatio=`${o} / ${s}`),i.append(a),this.replaceChildren(i),this.#r(e,n)}disposePart(){this.#t+=1,this.#e=null}#r(e,t){this.#t+=1;let n=this.#t,r=this.ownerDocument??document,i=this.#n;if(i===null)return;let a=L(r,`div`,`wui-chat-image-skeleton`);a.setAttribute(`aria-hidden`,`true`);let o=L(r,`span`,`visually-hidden`,t.labels.imageLoading);o.setAttribute(`role`,`status`),i.replaceChildren(a,o),typeof t.loadAttachmentUrl==`function`?t.loadAttachmentUrl(e.attachmentId).then(r=>{n===this.#t&&this.isConnected&&this.#i(r,e,t)},()=>{n===this.#t&&this.isConnected&&this.#a(e,t)}):this.#a(e,t)}#i(e,t,n){let r=this.#n;if(r===null)return;let i=this.ownerDocument??document,a=V(t.alt),o=i.createElement(`wui-lightbox`);o.setAttribute(`label`,n.labels.imageViewer),o.setAttribute(`layout`,`single`);let s=L(i,`a`,`wui-lightbox-item`);s.setAttribute(`href`,e),s.dataset.caption=a,s.dataset.name=a;let c=i.createElement(`img`);c.src=e,c.alt=a,c.decoding=`async`,s.append(c),o.append(s),r.replaceChildren(o)}#a(e,t){let n=this.#n;if(n===null)return;let r=this.ownerDocument??document,i=L(r,`p`,`wui-chat-image-error`,t.labels.imageFailed);i.setAttribute(`role`,`status`);let a=L(r,`button`,`btn btn-soft-primary btn-sm`,t.labels.retry);a.type=`button`,a.addEventListener(`click`,()=>this.#r(e,t)),n.replaceChildren(i,a)}});var xt={Email:{type:`email`,autocomplete:`email`},Phone:{type:`tel`,autocomplete:`tel`},Name:{type:`text`,autocomplete:`name`},Company:{type:`text`,autocomplete:`organization`},Text:{type:`text`,autocomplete:null},LongText:{type:`text`,autocomplete:null}},St=[`Open`,`Answered`,`Skipped`,`Expired`],Ct=0;function U(e){return Ct+=1,`${e}-${Ct}`}function W(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r}function G(){let e=W(`p`,`wui-chat-field-error`);return e.id=U(`wui-chat-field-error`),e.setAttribute(`role`,`alert`),e.hidden=!0,e}function K(e,t){return e.required?[]:[W(`span`,`wui-chat-field-hint`,t.inputOptional)]}function wt(e,t,n){let r=U(`wui-chat-field`),i=xt[t],a=t===`LongText`&&!e.secret,o;if(a){let e=W(`textarea`,`form-control wui-chat-input-control`);e.rows=3,o=e}else{let t=W(`input`,`form-control wui-chat-input-control`);t.type=e.secret?`password`:i.type,e.secret?t.autocomplete=`off`:i.autocomplete&&(t.autocomplete=i.autocomplete),o=t}o.id=r,o.name=e.key,e.placeholder!=null&&(o.placeholder=e.placeholder),e.maxLength!=null&&(o.maxLength=e.maxLength),e.required&&o.setAttribute(`aria-required`,`true`);let s=W(`label`,`form-label`,e.label);s.htmlFor=r;let c=G();o.setAttribute(`aria-describedby`,c.id);let l=W(`div`,`wui-chat-field`);return l.dataset.key=e.key,l.append(s,...K(e,n),o,c),{field:e,element:l,controls:[o],focus:o,invalid:o,error:c,control:o,read:()=>e.secret?o.value:o.value.trim()}}function Tt(e,t,n,r,i){let a=e.control,o=W(`button`,`btn btn-soft-primary`,n.inputSendCode);o.type=`button`,o.dataset.wui=`AppButton`;let s=W(`p`,`wui-chat-field-hint`);s.setAttribute(`aria-live`,`polite`);let c=U(`wui-chat-field`),l=W(`label`,`form-label`,n.inputEnterCode);l.htmlFor=c,l.hidden=!0;let u=W(`input`,`form-control wui-chat-input-control`);return u.type=`text`,u.id=c,u.inputMode=`numeric`,u.autocomplete=`one-time-code`,u.hidden=!0,o.addEventListener(`click`,async()=>{o.disabled=!0;try{await r.sendOtp(i,{fieldKey:t.key,value:a.value.trim()}),s.textContent=n.inputCodeSent,l.hidden=!1,u.hidden=!1}catch{s.textContent=n.inputCodeFailed}finally{o.disabled=!1}}),e.element.insertBefore(o,e.error),e.element.insertBefore(s,e.error),e.element.insertBefore(l,e.error),e.element.insertBefore(u,e.error),{...e,controls:[...e.controls,o,u],codeRead:()=>u.value.trim()}}function Et(e,t){let n=U(`wui-chat-field-label`),r=W(`span`,`form-label`,e.label);r.id=n;let i=W(`div`);i.setAttribute(`role`,`radiogroup`),i.setAttribute(`aria-labelledby`,n);let a=G();i.setAttribute(`aria-describedby`,a.id);let o=[];for(let t of e.options??[]){let n=W(`div`,`form-check`),r=W(`input`,`form-check-input`);r.type=`radio`,r.name=e.key,r.value=t.id,r.id=U(`wui-chat-option`);let a=W(`label`,`form-check-label`,t.label);a.htmlFor=r.id,n.append(r,a),i.append(n),o.push(r)}o.length===0&&(i.tabIndex=-1);let s=W(`div`,`wui-chat-field`);return s.dataset.key=e.key,s.append(r,...K(e,t),i,a),{field:e,element:s,controls:o,focus:o[0]??i,invalid:i,error:a,read:()=>o.find(e=>e.checked)?.value??``}}function Dt(e,t){let n=U(`wui-chat-field-label`),r=W(`span`,`form-label`,e.label);r.id=n;let i=W(`div`,`wui-chat-input-choices`);i.setAttribute(`role`,`group`),i.setAttribute(`aria-labelledby`,n);let a=G();i.setAttribute(`aria-describedby`,a.id);let o=[];for(let t of e.options??[]){let n=W(`div`,`form-check`),r=W(`input`,`form-check-input`);r.type=`checkbox`,r.name=e.key,r.value=t.id,r.id=U(`wui-chat-option`);let a=W(`label`,`form-check-label`,t.label);a.htmlFor=r.id,n.append(r,a),i.append(n),o.push(r)}o.length===0&&(i.tabIndex=-1);let s=W(`div`,`wui-chat-field`);return s.dataset.key=e.key,s.append(r,...K(e,t),i,a),{field:e,element:s,controls:o,focus:o[0]??i,invalid:i,error:a,read:()=>JSON.stringify(o.filter(e=>e.checked).map(e=>e.value))}}function Ot(e,t){let n=U(`wui-chat-field-label`),r=W(`span`,`form-label`,e.label);r.id=n;let i=W(`div`,`wui-chat-input-slots`);i.setAttribute(`role`,`radiogroup`),i.setAttribute(`aria-labelledby`,n);let a=G();i.setAttribute(`aria-describedby`,a.id);let o=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`}),s=[];for(let t of e.slots??[]){let n=W(`input`,`wui-chat-input-slot-radio`);n.type=`radio`,n.name=e.key,n.value=t.id,n.id=U(`wui-chat-slot`);let r=W(`label`,`btn btn-soft-primary wui-chat-input-slot`,o.format(new Date(t.startDateTimeUtc)));r.htmlFor=n.id,i.append(n,r),s.push(n)}s.length===0&&(i.tabIndex=-1);let c=W(`div`,`wui-chat-field`);return c.dataset.key=e.key,c.append(r,...K(e,t),i,a),{field:e,element:c,controls:s,focus:s[0]??i,invalid:i,error:a,read:()=>s.find(e=>e.checked)?.value??``}}function kt(e,t,n){let r=U(`wui-chat-field-label`),i=W(`span`,`form-label`,e.label);i.id=r;let a=G(),o=W(`input`);o.type=`file`,o.name=e.key,o.id=U(`wui-chat-field`),o.hidden=!0,e.accept?.length&&(o.accept=e.accept.join(`,`));let s=W(`button`,`btn btn-soft-primary`,t.inputChooseFile);s.type=`button`,s.dataset.wui=`AppButton`,s.setAttribute(`aria-describedby`,a.id),s.addEventListener(`click`,()=>o.click());let c=W(`span`,`wui-chat-input-file-status`);c.setAttribute(`aria-live`,`polite`);let l=W(`button`,`btn btn-link-primary`);l.type=`button`,l.dataset.wui=`AppButton`,l.hidden=!0;let u=W(`div`,`wui-chat-input-file`);u.setAttribute(`role`,`group`),u.setAttribute(`aria-labelledby`,r),u.append(s,c,l,o);let d=`empty`,f=``,p=``,m=0,h=()=>{c.textContent=d===`uploading`?`${t.attachmentUploading} ${f}`:f,l.hidden=f===``,l.textContent=f===``?``:t.inputRemoveFile(f);let e=d===`failed`;a.textContent=e?t.attachmentFailed:``,a.hidden=!e,e?u.setAttribute(`aria-invalid`,`true`):u.removeAttribute(`aria-invalid`)},g=async e=>{m+=1;let t=m;d=`uploading`,f=e.name,p=``,h();try{let r=await n.uploadInputFile(e);if(t!==m)return;p=r,d=`ready`}catch{if(t!==m)return;d=`failed`}h()};o.addEventListener(`change`,()=>{let e=o.files?.[0];e&&g(e)}),l.addEventListener(`click`,()=>{m+=1,d=`empty`,f=``,p=``,o.value=``,h()}),h();let _=W(`div`,`wui-chat-field`);return _.dataset.key=e.key,_.append(i,...K(e,t),u,a),{field:e,element:_,controls:[s,l,o],focus:s,invalid:u,error:a,read:()=>d===`ready`?p:``,uploadProblem:()=>d===`uploading`?t.attachmentUploading:d===`failed`?t.attachmentFailed:null}}function At(e){let t=W(`input`,`form-check-input`);t.type=`checkbox`,t.name=e.key,t.id=U(`wui-chat-field`);let n=W(`label`,`form-check-label`,e.consentText||e.label);n.htmlFor=t.id;let r=G();t.setAttribute(`aria-describedby`,r.id);let i=W(`div`,`form-check`);i.append(t,n);let a=W(`div`,`wui-chat-field`);return a.dataset.key=e.key,a.append(i,r),{field:e,element:a,controls:[t],focus:t,invalid:t,error:r,read:()=>t.checked?`true`:`false`}}function jt(e,t,n,r){if(e.type===`Choice`)return Et(e,t);if(e.type===`MultiChoice`)return Dt(e,t);if(e.type===`TimeSlot`)return Ot(e,t);if(e.type===`File`)return kt(e,t,n);if(e.type===`Consent`)return At(e);let i=wt(e,e.type,t);return e.verify===`Otp`?Tt(i,e,t,n,r):i}function Mt(e,t,n){let r=e.uploadProblem?.();if(r)return r;let{field:i}=e;return i.required?i.type===`Consent`?t===`true`?null:n.inputConsentRequired:i.type===`MultiChoice`?t===`[]`?n.inputRequired:null:t===``?n.inputRequired:null:null}function Nt(e,t){return e.state===`Answered`?W(`p`,`wui-chat-input-summary`,e.answeredSummary||t.inputAnswered):W(`p`,`wui-chat-input-summary`,e.state===`Skipped`?t.inputSkipped:t.inputExpired)}I(`wui-chat-part-input-request`,class extends F{_signature;_generation;constructor(){super(),this._signature=null,this._generation=0}renderPart(e,t,n){for(let t of St)this.classList.toggle(`wui-chat-input-request--${t.toLowerCase()}`,e.state===t);let r=JSON.stringify([e.requestId,e.state,e.answeredSummary,e.fields]);r!==this._signature&&(this._signature=r,this._generation+=1,this.replaceChildren(this._content(e,n)))}_content(e,t){return e.state===`Open`?this._form(e,this._generation):Nt(e,t.labels)}_form(e,t){let n=this.activeTurn,r=n.labels,i=n.features,a=W(`form`,`wui-chat-input-form`);a.noValidate=!0,a.setAttribute(`aria-label`,e.title||e.submitLabel),e.title&&a.append(W(`h3`,`wui-chat-input-title`,e.title));let o=e.fields.map(t=>jt(t,r,n,e.requestId));for(let e of o)a.append(e.element);let s=W(`p`,`wui-chat-input-error`);s.setAttribute(`role`,`status`),s.hidden=!0,a.append(s);let c=W(`button`,`btn btn-primary`,e.submitLabel);c.type=`submit`,c.dataset.wui=`AppButton`;let l=W(`div`,`d-flex flex-wrap gap-2`);l.append(c);let u=[c];if(i.LeadShortcuts&&e.fields.length===1&&!e.fields[0]?.required){let t=W(`button`,`btn btn-soft-primary`,r.skip);t.type=`button`,t.dataset.wui=`AppButton`,t.addEventListener(`click`,()=>this.activeTurn.skipInput(e.requestId)),l.append(t),u.push(t)}if(i.LeadShortcuts&&e.cancellable){let e=W(`button`,`btn btn-link-primary`,r.cancel);e.type=`button`,e.dataset.wui=`AppButton`,e.addEventListener(`click`,()=>this.activeTurn.cancelLead()),l.append(e),u.push(e)}a.append(l),e.allowTyped&&a.append(W(`p`,`wui-chat-input-typed`,r.typeAnswer));let d=!1,f=t=>{for(let e of o)for(let n of e.controls)n.disabled=t;for(let e of u)e.disabled=t;c.textContent=t?r.inputSubmitting:e.submitLabel},p=()=>{for(let e of o)e.error.hidden=!0,e.error.textContent=``,e.invalid.removeAttribute(`aria-invalid`);s.hidden=!0,s.textContent=``},m=(e,t)=>{e.error.textContent=t,e.error.hidden=!1,e.invalid.setAttribute(`aria-invalid`,`true`)};return a.addEventListener(`submit`,async n=>{if(n.preventDefault(),d)return;p();let i={},a={},l=[];for(let e of o){let t=e.read();i[e.field.key]=t,e.codeRead&&(a[e.field.key]=e.codeRead());let n=Mt(e,t,r);n&&l.push([e,n])}let[u]=l;if(u){for(let[e,t]of l)m(e,t);u[0].focus.focus();return}d=!0,f(!0);let h;try{h=await this.activeTurn.answerInput(e.requestId,i,Object.keys(a).length>0?a:null)}catch{h={ok:!1,errors:{},message:r.errorGeneric}}if(t!==this._generation||h.ok)return;d=!1;let g=null;for(let e of o){let t=h.errors?.[e.field.key];t&&(m(e,t),g??=e)}h.message!=null&&(s.textContent=h.message,s.hidden=!1),f(!1),g?g.focus.focus():o[0]?o[0].focus.focus():c.focus()}),a}});var Pt={ActionLimitReached:`warning`,ConversationTooLong:`warning`,AssistantUnavailable:`danger`},Ft={info:`info`,warning:`alert-triangle`,danger:`alert-circle`};I(`wui-chat-part-notice`,class extends F{renderPart(e){let t=this.ownerDocument??document,n=Pt[e.code]??`info`,r=L(t,`div`,`wui-chat-notice wui-chat-notice--${n}`);r.setAttribute(`role`,n===`danger`?`alert`:`status`);let i=L(t,`span`,`wui-chat-notice-icon`);i.setAttribute(`aria-hidden`,`true`);let a=Oe(t,Ft[n],16);a&&i.append(a);let o=L(t,`div`,`wui-chat-notice-body`);o.append(L(t,`span`,`wui-chat-notice-text`,e.text));let s=e.action;if(s){let e=L(t,`button`,`wui-chat-notice-action`,s.label);e.type=`button`,e.addEventListener(`click`,()=>s.run()),o.append(e)}r.append(i,o),this.replaceChildren(r)}});function It(e){switch(e){case`Primary`:return`wui-chat-quick-reply--primary`;case`Cta`:return`wui-chat-quick-reply--cta`;case`Default`:case null:return``}}I(`wui-chat-part-quick-replies`,class extends F{#e=null;renderPart(e,t,n){let r=n.features.SuggestedReplies===!0&&n.isLast===!0&&n.busy===!1&&e.replies.length>0,i=typeof n.openTarget==`function`,a=typeof n.beginHandoff==`function`,o=n.handoffPause===!0,s=JSON.stringify([r,e.replies,e.placement,n.labels.quickReplies,n.labels.handoffMoment,i,a,o,n.handoffHosts??null,n.features.LinkHandoff===!0]);if(s===this.#e)return;this.#e=s;let c=this.querySelector(`:scope > .wui-chat-quick-replies:not(.wui-chat-quick-replies--leaving)`);if(!r&&c){this.#t(c);return}if(this.replaceChildren(),!r)return;let l=this.ownerDocument,u=e.placement===`Composer`,d=L(l,`div`,u?`wui-chat-quick-replies wui-chat-quick-replies--composer`:`wui-chat-quick-replies`);d.setAttribute(`role`,`group`),d.setAttribute(`aria-label`,n.labels.quickReplies);let f=u?null:e.replies.find(e=>e.id===O&&e.action===`Send`),p=0;f&&(d.classList.add(`wui-chat-quick-replies--offer`),d.append(this.#n(l,f,n)),p+=1);for(let t of e.replies){if(t===f||t.action===`Open`&&(!t.target||!i))continue;let e=null;if(t.action===`Navigate`){if(n.features.LinkHandoff!==!0)continue;if(ce(t.target,n.handoffHosts))e=t.target;else{let r=t.target===null?null:n.resolveLink?.(t.target);e=typeof r==`string`&&r!==``?r:null}if(e===null){d.append(L(l,`span`,null,t.label));continue}if(!a)continue}d.append(this.#r(l,t,p,n,f?`wui-chat-quick-reply--quiet`:``,e)),p+=1}if(o){let e=L(l,`span`,`visually-hidden`,n.labels.handoffMoment);e.setAttribute(`role`,`status`),d.append(e)}d.childElementCount>0&&this.append(d)}#t(e){e.classList.add(`wui-chat-quick-replies--leaving`);let t=this.ownerDocument.defaultView,n=Number.parseFloat(t?t.getComputedStyle(e).animationDuration:``)*1e3;t===null||!(n>0)?e.remove():t.setTimeout(()=>e.remove(),n)}#n(e,t,n){let r=L(e,`div`,`wui-chat-offer`);return r.style.setProperty(`--wui-chat-i`,`0`),r.append(L(e,`div`,`wui-chat-offer-title`,t.label)),r.append(this.#r(e,{...t,variant:`Primary`},0,n,`wui-chat-offer-action`)),r}#r(e,t,n,r,i=``,a=null){let o=e.createElement(`button`);o.type=`button`,o.className=[`wui-chat-quick-reply`,It(t.variant),i].filter(Boolean).join(` `),o.style.setProperty(`--wui-chat-i`,String(n));let s=t.action===`Navigate`,c=s&&r.handoffPause===!0;if(o.disabled=c,t.icon){let n=Oe(e,t.icon,16);if(n){let t=L(e,`span`,`wui-chat-quick-reply-icon`);t.setAttribute(`aria-hidden`,`true`),t.append(n),o.append(t)}}return o.append(L(e,`span`,`wui-chat-quick-reply-label`,c?r.labels.handoffMoment:t.label)),o.addEventListener(`click`,()=>{if(t.action===`Open`){let{openTarget:e}=this.activeTurn;if(t.target===null||e===void 0)throw Error(`${this.localName} drew an Open chip without a target or openTarget`);e.call(this.activeTurn,t.target)}else if(s){let{beginHandoff:e}=this.activeTurn;if(a===null||e===void 0)throw Error(`${this.localName} drew a Navigate chip without a destination or beginHandoff`);e.call(this.activeTurn,t,()=>this.#i(a))}else this.activeTurn.chooseQuickReply(t),this.closest(`.wui-chat`)?.querySelector(`.wui-chat-input`)?.focus()}),o}#i(e){typeof this.activeTurn.openTarget==`function`?this.activeTurn.openTarget(e):globalThis.location.assign(e)}});var Lt=/* @__PURE__ */ new Set([`Integer`,`Decimal`,`MoneyMinor`,`Percent`]);function Rt(e){return Lt.has(e)}function zt(e,t,n,r=!0){let i=e=>r?P(e):[{kind:`text`,text:e}];if(t==null||t===``)return[{kind:`text`,text:Se()}];if(e===`Date`||e===`DateTimeUtc`)return[{kind:`text`,text:ie(t,e,n)}];if(Rt(e)){let r=Number(t);return i(Number.isFinite(r)?ie(r,e,n):String(t))}return i(String(t))}var Bt=0;function Vt(e){return Bt+=1,`${e}-${Bt}`}I(`wui-chat-part-record-card`,class extends F{#e=null;renderPart(e,t,n){let r=!!e.target&&typeof n.openRecord==`function`,i=n.features?.FigureText===!0,a=JSON.stringify([e,r,i]);if(a===this.#e)return;this.#e=a;let o=this.ownerDocument,s=L(o,`article`,`wui-chat-record`),c=Vt(`wui-chat-record-title`);s.setAttribute(`aria-labelledby`,c);let l=L(o,`div`,`wui-chat-record-head`),u=L(o,`strong`,`wui-chat-record-title`);if(u.id=c,u.setAttribute(`role`,`heading`),u.setAttribute(`aria-level`,`3`),i?B(u,e.title):u.textContent=String(e.title??``),l.append(u),e.subtitle){let t=L(o,`span`,`wui-chat-record-subtitle`);i?B(t,e.subtitle):t.textContent=String(e.subtitle??``),l.append(t)}if(s.append(l),e.fields?.length>0){let t=L(o,`dl`,`wui-chat-record-fields`);for(let n of e.fields){let e=L(o,`div`),r=L(o,`dt`);i?B(r,n.label):r.textContent=String(n.label??``);let a=L(o,`dd`);Rt(n.type)&&(a.className=`wui-chat-num`),z(a,zt(n.type,n.value,null,i)),e.append(r,a),t.append(e)}s.append(t)}if(r){let t=L(o,`button`,`btn btn-soft-primary btn-sm wui-chat-record-open`,n.labels.recordOpen);t.type=`button`,t.setAttribute(`aria-label`,n.labels.recordOpenFor(V(e.title))),t.addEventListener(`click`,()=>{let{openRecord:t}=this.activeTurn;if(t===void 0)throw Error(`${this.localName} lost openRecord after it drew the button`);t.call(this.activeTurn,e)}),s.append(t)}this.replaceChildren(s)}});var Ht=/^https?:\/\//i;I(`wui-chat-part-sources`,class extends F{renderPart(e,t,n){if(this.replaceChildren(),!n.features.Sources||e.sources.length===0)return;let r=this.ownerDocument,i=L(r,`div`,`wui-chat-sources`);i.append(L(r,`p`,`wui-chat-sources-label`,n.labels.sources));let a=L(r,`ul`,`wui-chat-sources-list`);a.setAttribute(`aria-label`,n.labels.sources);for(let t of e.sources){let e=r.createElement(`li`);e.append(this.#e(r,t,n)),a.append(e)}i.append(a),this.append(i)}#e(e,t,n){let r;if(typeof t.url==`string`&&Ht.test(t.url)){let i=L(e,`a`,`wui-chat-source`);i.setAttribute(`href`,t.url),i.setAttribute(`target`,`_blank`),i.setAttribute(`rel`,`noopener noreferrer`),i.setAttribute(`aria-label`,n.labels.openSource(t.title)),r=i}else r=L(e,`span`,`wui-chat-source`),r.tabIndex=-1;return r.dataset.marker=String(t.marker),r.append(L(e,`span`,`wui-chat-source-marker`,String(t.marker)),L(e,`span`,`wui-chat-source-title`,t.title)),r}});var Ut=25,Wt=0;function Gt(e,t,n){let r=e.createElement(`tr`);for(let i of t.columns){let t=e.createElement(`th`);t.setAttribute(`scope`,`col`),Rt(i.type)&&(t.className=`wui-chat-num`),n?B(t,i.label):t.textContent=String(i.label??``),r.append(t)}return r}function Kt(e,t,n,r){let i=e.createElement(`tr`);return t.columns.forEach((a,o)=>{let s=o===0&&a.type===`Text`,c=e.createElement(s?`th`:`td`);s&&c.setAttribute(`scope`,`row`),Rt(a.type)&&(c.className=`wui-chat-num`);let l=n[o];l==null||l===``?c.append(L(c.ownerDocument,`span`,`wui-chat-null`,Se())):z(c,zt(a.type,l,t.currency,r)),i.append(c)}),i}function qt(e,t){let n=()=>{let n=t.scrollWidth-t.clientWidth;e.dataset.scroll=n<=1?`none`:t.scrollLeft>=n-1?`end`:t.scrollLeft>0?`middle`:`start`};t.addEventListener(`scroll`,n,{passive:!0}),typeof ResizeObserver<`u`&&new ResizeObserver(n).observe(t),n()}function Jt(e,t,n,r,i){let a=e.ownerDocument;for(let o of t.rows.slice(n,r))e.append(Kt(a,t,o,i))}I(`wui-chat-part-table`,class extends F{#e=null;renderPart(e,t,n){let r=n.features?.FigureText===!0,i=JSON.stringify([e,r]);if(i===this.#e)return;if(this.#e=i,!e.columns||e.columns.length===0){this.replaceChildren();return}let a=this.ownerDocument,o=L(a,`figure`,`wui-chat-table`),s=null;if(e.title){Wt+=1,s=`wui-chat-table-${Wt}`;let t=L(a,`figcaption`,`wui-chat-table-title`);t.id=s,r?B(t,e.title):t.textContent=String(e.title??``),o.append(t)}let c=L(a,`div`,`table-wrap wui-chat-table-wrap`);c.tabIndex=0,c.setAttribute(`role`,`region`),s?c.setAttribute(`aria-labelledby`,s):c.setAttribute(`aria-label`,n.labels.table);let l=L(a,`table`,`table table-sm wui-chat-table-grid`),u=a.createElement(`thead`);u.append(Gt(a,e,r));let d=a.createElement(`tbody`);Jt(d,e,0,Math.min(e.rows.length,Ut),r),l.append(u,d),c.append(l);let f=L(a,`div`,`wui-chat-table-frame`),p=L(a,`span`,`wui-chat-table-cue`);if(p.setAttribute(`aria-hidden`,`true`),f.append(c,p),o.append(f),qt(f,c),e.rows.length>Ut){let t=L(a,`button`,`btn btn-soft-primary btn-sm wui-chat-table-more`,n.labels.tableShowAll(e.rows.length));t.type=`button`,t.addEventListener(`click`,()=>{Jt(d,e,Ut,e.rows.length,r),t.remove()}),o.append(t)}this.replaceChildren(o)}});var Yt=/* @__PURE__ */ new Set([`Visitor`,`Customer`]),Xt=/^\d+$/;function Zt(e,t){return e?.features?.Sources===!0?typeof e?.isCitation==`function`?e.isCitation(t):Xt.test(t):!1}function Qt(e,t){if(ce(e,t?.handoffHosts))return e;let n=t?.resolveLink?.(e);return typeof n==`string`&&n!==``?n:null}function $t(e,t){let n=globalThis.location?.origin;for(let r of e.querySelectorAll(`a[href]`)){let e=r.dataset.linkSource??r.getAttribute(`href`)??``;r.dataset.linkSource=e;let i=Qt(e,t);i===null?r.replaceWith(r.ownerDocument.createTextNode(r.textContent??``)):(i!==r.getAttribute(`href`)&&r.setAttribute(`href`,i),ve(i,`web`,void 0,n)?.kind===`web`?(r.setAttribute(`target`,`_blank`),r.setAttribute(`rel`,`noopener noreferrer`)):(r.removeAttribute(`target`),r.removeAttribute(`rel`)))}}function en(e,t){$t(e,t)}I(`wui-chat-part-text`,class extends F{#e=null;#t=null;#n=!1;#r=null;constructor(){super(),this.addEventListener(`wui-markdown-citation`,e=>{let t=this.turn;typeof t?.openCitation==`function`&&t.openCitation(Number(e.detail.citation))}),this.addEventListener(`click`,e=>this.#a(e))}renderPart(e,t,n){let r=Yt.has(t.author.kind)?`plain`:`markdown`,i=this.#e;if((i===null||i.mode!==r)&&(i=r===`plain`?{mode:r,node:this.#s()}:this.#c(e.text),this.#e=i,this.#t=null,this.replaceChildren(i.node)),i.mode===`plain`){let t=this.turn?.features?.FigureText===!0,n=JSON.stringify([e.text,t]);n!==this.#t&&(this.#t=n,i.node.replaceChildren(),t?z(i.node,P(e.text)):i.node.append(this.ownerDocument.createTextNode(e.text)))}else this.#o(i.node),i.source.textContent!==e.text&&(i.source.textContent=e.text);this.toggleAttribute(`data-streaming`,t.streaming===!0),this.#n||(this.#n=!0,this.closest(`[data-restored]`)||this.classList.add(`wui-chat-part-enter`)),this.#i()}disposePart(){this.#r?.disconnect(),this.#r=null}#i(){this.#r||(this.#r=new MutationObserver(()=>en(this,this.turn)),this.#r.observe(this,{childList:!0,subtree:!0,characterData:!0}),en(this,this.turn))}#a(e){let t=e.target instanceof Element?e.target.closest(`a[href]`):null,n=this.turn;if(!t||!this.contains(t))return;let r=t.getAttribute(`href`)??``;r.startsWith(`#`)||(r.startsWith(`/`)&&typeof n?.onNavigate==`function`?(e.preventDefault(),n.onNavigate(r)):typeof n?.openTarget==`function`&&(e.preventDefault(),n.openTarget(r)))}#o(e){let t=this.turn?.features?.FigureText===!0?P:void 0;e.figureText!==t&&(e.figureText=t)}#s(){return L(this.ownerDocument,`div`,`wui-chat-bubble`)}#c(e){let t=this.ownerDocument,n=L(t,`wui-markdown`,`wui-markdown wui-chat-text`);n.setAttribute(`links`,`web`),n.setAttribute(`headings`,`text`),n.isCitation=e=>Zt(this.turn,e);let r=L(t,`pre`,`wui-markdown-source`,e);return n.append(r),{mode:`markdown`,node:n,source:r}}}),I(`wui-chat-part-ticket`,class extends F{renderPart(e,n,r){let{labels:i}=r,a=t(`article`,`wui-chat-ticket`,{"aria-label":i.ticketAria(e.number)}),o=t(`div`,`wui-chat-ticket-head`),s=t(`span`,`wui-chat-ticket-number`);s.textContent=i.ticketAria(e.number),o.append(s);let c=ut(e.status);if(c!==null){let n=t(`span`,`wui-chat-ticket-badge wui-chat-ticket-badge--${c}`);n.textContent=dt(e.status,i),o.append(n)}let l=t(`strong`,`wui-chat-ticket-title`);if(l.textContent=e.subject,a.append(o,l),typeof r.openTicket==`function`){let n=t(`div`,`wui-chat-ticket-foot`),o=t(`button`,`wui-chat-ticket-link`,{type:`button`});o.textContent=i.ticketView,o.addEventListener(`click`,()=>{let{openTicket:t}=r;if(t===void 0)throw Error(`${this.localName} lost openTicket after it drew the link`);t.call(r,{ticketId:e.ticketId,number:e.number})}),n.append(o),a.append(n)}this.replaceChildren(a)}});var tn=`http://www.w3.org/2000/svg`,nn={mic:`M12 15a3 3 0 0 0 3-3V6a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-2.08A7 7 0 0 0 19 12z`,stop:`M6 6h12v12H6z`,play:`M8 5v14l11-7z`,pause:`M6 5h4v14H6zm8 0h4v14h-4z`,speaker:`M3 9v6h4l5 5V4L7 9H3zm13.5 3a4.5 4.5 0 0 0-2.5-4v8a4.5 4.5 0 0 0 2.5-4zM14 3.2v2.1a7 7 0 0 1 0 13.4v2.1a9 9 0 0 0 0-17.6z`};function rn(e,t=18){if(!i(nn,e))throw Error(`Unknown voice icon "${e}".`);let n=document.createElementNS(tn,`svg`);n.setAttribute(`viewBox`,`0 0 24 24`),n.setAttribute(`width`,String(t)),n.setAttribute(`height`,String(t)),n.setAttribute(`aria-hidden`,`true`),n.setAttribute(`focusable`,`false`),n.setAttribute(`fill`,`currentColor`);let r=document.createElementNS(tn,`path`);return r.setAttribute(`d`,nn[e]),n.append(r),n}var an=40,q=null;function on(e){let t=L(document,`span`,`wui-chat-clip-bar`);return t.style.setProperty(`--wui-chat-bar-height`,`${Math.round(e*100)}%`),t}function sn(e,t){e.replaceChildren(..._e(t,an).map(on))}I(`wui-chat-part-voice-clip`,class extends F{#e=null;#t=!1;#n=0;#r=0;#i=!1;#a=null;#o=null;#s=null;#c=0;#l=!1;renderPart(e,t,n){if(!n.features.VoiceClips){this.#u(e.transcript);return}let r=this.#e??this.#d(e.attachmentId);e.attachmentId!==r.attachmentId&&(this.disposePart(),r.attachmentId=e.attachmentId,this.#r=0,sn(r.wave,e.attachmentId)),this.#n=e.durationMs,this.#f(r,e)}disposePart(){this.#c+=1,this.#a?.pause(),this.#s!==null&&URL.revokeObjectURL(this.#s),q===this&&(q=null),this.#a=null,this.#o=null,this.#s=null,this.#i=!1}#u(e){if(this.disposePart(),this.#e=null,typeof e==`string`&&e!==``){let t=L(document,`p`,`wui-chat-clip-transcript`);t.textContent=e,this.replaceChildren(t)}else this.replaceChildren()}#d(e){let t=L(document,`div`,`wui-chat-clip`);t.setAttribute(`role`,`group`);let n=L(document,`div`,`wui-chat-clip-row`),r=L(document,`button`,`wui-chat-clip-play`);r.type=`button`;let i=L(document,`div`,`wui-chat-clip-wave`);i.setAttribute(`aria-hidden`,`true`);let a=L(document,`span`,`wui-chat-clip-time`);n.append(r,i,a);let o=L(document,`p`,`wui-chat-clip-error`);o.setAttribute(`role`,`status`),o.hidden=!0,t.append(n,o);let s={attachmentId:e,root:t,play:r,wave:i,time:a,error:o,transcript:null};return r.addEventListener(`click`,()=>this.#C(s)),sn(i,e),this.#e=s,this.replaceChildren(t),s}#f(e,t){let n=this.activeTurn.labels;e.root.setAttribute(`aria-label`,n.voiceClip),e.play.disabled=this.#l||typeof this.activeTurn.readAttachment!=`function`,this.#p(e),this.#m(e),this.#h(e,t.transcript)}#p(e){let t=this.activeTurn.labels,n=this.#i?t.voiceClipPause:t.voiceClipPlay;e.play.setAttribute(`aria-label`,n),e.play.title=n,e.play.replaceChildren(rn(this.#i?`pause`:`play`,18))}#m(e){let t=this.#n/1e3,n=t>0?Math.min(1,this.#r/t):0,r=Math.floor(n*an);[...e.wave.children].forEach((e,t)=>{e.classList.toggle(`wui-chat-clip-bar--played`,t<r)});let i=ae(Math.max(1,Math.round(t)));e.time.textContent=this.activeTurn.labels.voiceClipTime(ae(this.#r),i)}#h(e,t){if(typeof t!=`string`||t===``){e.transcript?.toggle.remove(),e.transcript?.text.remove(),e.transcript=null;return}let n=e.transcript??this.#g(e);n.text.textContent=t,this.#_(n)}#g(e){let t=L(document,`button`,`wui-chat-clip-toggle`);t.type=`button`;let n=L(document,`p`,`wui-chat-clip-transcript`);n.hidden=!this.#t;let r={toggle:t,text:n};return t.addEventListener(`click`,()=>{this.#t=!this.#t,n.hidden=!this.#t,this.#_(r)}),e.transcript=r,e.root.append(t,n),r}#_(e){let t=this.activeTurn.labels;e.toggle.setAttribute(`aria-expanded`,String(this.#t)),e.toggle.textContent=this.#t?t.voiceClipHideTranscript:t.voiceClipShowTranscript}#v(e){return this.#o??=this.#y(e).catch(e=>{throw this.#o=null,e}),this.#o}async#y(e){let t=this.#c,{readAttachment:n}=this.activeTurn;if(n===void 0)throw Error(`${this.localName} loaded a clip on a turn without readAttachment`);let r=await n.call(this.activeTurn,e.attachmentId),i=URL.createObjectURL(new Blob([r],{type:me(r)}));if(t!==this.#c)return URL.revokeObjectURL(i),null;this.#s!==null&&URL.revokeObjectURL(this.#s),this.#s=i;let a=new Audio(this.#s);return a.addEventListener(`timeupdate`,()=>{this.#r=a.currentTime,this.#m(e)}),a.addEventListener(`ended`,()=>{this.#r=0,this.#b(),this.#m(e)}),a.addEventListener(`error`,()=>{this.#b(),this.#o=null,this.#S(e)}),this.#a=a,a}#b(){this.#a?.pause(),this.#x(!1)}#x(e){this.#i=e,e?(q&&q!==this&&q.#b(),q=this):q===this&&(q=null);let t=this.#e;t!==null&&this.#p(t)}#S(e){e.error.textContent=this.activeTurn.labels.voiceClipFailed,e.error.hidden=!1}async#C(e){if(this.#i)this.#b();else{e.error.hidden=!0,this.#l=!0,e.play.disabled=!0,e.play.setAttribute(`aria-busy`,`true`);try{let t=await this.#v(e);if(t===null)return;this.#x(!0),await t.play()}catch{this.#b(),this.#o=null,this.#S(e)}finally{this.#l=!1,e.play.removeAttribute(`aria-busy`),e.play.disabled=typeof this.activeTurn.readAttachment!=`function`}}}});var cn={Text:`wui-chat-part-text`,Sources:`wui-chat-part-sources`,QuickReplies:`wui-chat-part-quick-replies`,InputRequest:`wui-chat-part-input-request`,Action:`wui-chat-part-action`,Notice:`wui-chat-part-notice`,Table:`wui-chat-part-table`,Chart:`wui-chat-part-chart`,Figures:`wui-chat-part-figures`,RecordCard:`wui-chat-part-record-card`,Image:`wui-chat-part-image`,File:`wui-chat-part-file`,Ticket:`wui-chat-part-ticket`,Handoff:`wui-chat-part-handoff`,VoiceClip:`wui-chat-part-voice-clip`},ln=8e3,un=6e3,dn=/* @__PURE__ */ new Set([`Blocked`,`NoMicrophone`]);function fn(e){let t=e instanceof E?e.code:`Failed`;return{code:t,source:`Dictation`,sticky:dn.has(t)}}function pn(e){let t=M(e.filter(e=>e.kind===`Text`)).replace(/ ?\[\d+\]/g,``).replace(/\s+/g,` `).trim();if(t.length<=6e3)return t;let n=t.slice(0,un),r=n.lastIndexOf(`. `);return r===-1?n.trim():n.slice(0,r+1)}function mn(e,t){switch(e.code){case`Blocked`:return t.dictationBlocked;case`NoMicrophone`:return t.dictationNoMicrophone;case`NoSpeech`:return t.dictationNotHeard;case`Unavailable`:return t.dictationUnavailable;case`Failed`:return t.dictationFailed;case`SpeakFailed`:return t.readAloudFailed;default:throw Error(`Unknown voice note code "${e.code}".`)}}function hn(e){let t=e.getState,n=e.speech??o({getToken:e.getToken}),r=`Idle`,i=null,a=null,s=null,c=null,l=0,u=null,d=/* @__PURE__ */ new Set,f=()=>({mode:r,messageId:i,startedAtMs:a,note:s});function p(){let e=f();for(let t of[...d])t(e)}function m(e){r=e.mode,i=e.messageId??null,a=e.startedAtMs??null,p()}function h(){u!==null&&clearTimeout(u),u=null}function g(e){h(),s=e,e&&!e.sticky&&(u=setTimeout(()=>{u=null,s=null,p()},ln)),p()}function _(){s!==null&&(h(),s=null,p())}function v(){l+=1;let e={id:l,controller:new AbortController,stopped:!1};return c=e,e}function y(e){c===e&&(c=null,m({mode:`Idle`}))}function b(){let e=c;c=null,e&&(e.stopped=!0,e.controller.abort()),r!==`Idle`&&m({mode:`Idle`})}function x(){let e=t();return!!(e.features.Dictation&&e.profile?.speechAvailable&&n.dictation)}function S(){let e=t();return!!(e.features.ReadAloud&&e.profile?.speechAvailable&&n.readAloud)}async function C(e){if(r===`Dictating`){b();return}if(b(),g(null),!x())return;let t=e.getText(),i=t!==``&&!/\s$/.test(t)?`${t} `:t,a=v();m({mode:`Dictating`});try{await n.startDictation({signal:a.controller.signal,onText:t=>{c===a&&e.setText(i+t)},onEnd:()=>y(a)})}catch(e){if(a.stopped)return;y(a),g(fn(e))}}async function w(e,t){if(r===`Speaking`&&i===e){b();return}b(),g(null);let a=pn(t);if(a===``)return;let o=v();m({mode:`Speaking`,messageId:e});try{await n.speak(a,{signal:o.controller.signal}),y(o)}catch{if(o.stopped)return;y(o),g({code:`SpeakFailed`,source:`ReadAloud`,sticky:!1,messageId:e})}}function T(e){return d.add(e),()=>{d.delete(e)}}function E(){b(),h(),s=null,d.clear()}return{canDictate:x,canSpeak:S,getStatus:f,subscribe:T,toggleDictation:C,toggleSpeak:w,stop:b,dismissNote:_,destroy:E}}var gn=/* @__PURE__ */ new Set([`Shift`,`Control`,`Alt`,`Meta`,`Escape`]);function _n(e,t){e.isTrusted&&!gn.has(e.key)&&t.getStatus().mode===`Dictating`&&t.stop()}function vn({voice:e,getLabels:n,textarea:r,onTextChanged:i}){let a=null,o=t(`button`,`wui-chat-tool wui-chat-mic`,{type:`button`});o.append(rn(`mic`,20)),o.hidden=!0,o.addEventListener(`click`,()=>{e.toggleDictation({getText:()=>r.value,setText:e=>{r.value=r.maxLength>0?e.slice(0,r.maxLength):e,i(),r.setSelectionRange(r.value.length,r.value.length)}})});let s=t(`p`,`wui-chat-voice-note`,{role:`status`});s.hidden=!0;let c=t(`span`,`visually-hidden`,{"aria-live":`polite`});function l(e){let t=n(),r=e.note?.source===`ReadAloud`?null:e.note,i=e.mode===`Dictating`,a=i?t.dictateStop:t.dictate;o.setAttribute(`aria-pressed`,String(i)),o.setAttribute(`aria-label`,a),o.title=a;let l=r?.code===`Blocked`||r?.code===`NoMicrophone`;r===null?(s.hidden=!0,s.textContent=``):(s.hidden=!1,s.textContent=mn(r,t),s.setAttribute(`role`,r.sticky?`alert`:`status`)),s.classList.toggle(`wui-chat-voice-note--blocked`,l),c.textContent=i?t.dictateListening:``}function u(t){let{state:n}=t;o.hidden=!e.canDictate();let r=e.getStatus().mode===`Speaking`,i=n.messagesLeftToday===0;o.disabled=i||r||n.handoffPause===!0}function d(e){l(e),a!==null&&u(a)}let f=e.subscribe(d);function p(t){a=t,u(t),l(e.getStatus())}function m(){f()}return{buttons:[o],note:s,announcer:c,paint:p,destroy:m}}var yn=10,bn=.9,xn=0;function Sn(e){for(let t of e.toReversed())for(let e of t.parts.toReversed())if(e.kind===`InputRequest`&&e.state===`Open`)return e.fields[0]?.label??e.title??null;return null}function Cn(n){xn+=1;let r=`wui-chat-composer-hint-${xn}`,i=t(`p`,`wui-chat-allowance`,{role:`status`});i.hidden=!0;let a=t(`span`),o=t(`button`,`btn btn-ghost-primary btn-sm wui-chat-action-btn`,{type:`button`});o.addEventListener(`click`,()=>n.onCancelEdit());let s=t(`div`,`wui-chat-editing`);s.hidden=!0,s.append(a,o);let c=t(`div`,`wui-chat-attachments`);c.hidden=!0;let l=t(`button`,`wui-chat-tool`,{type:`button`});l.append(e(`paperclip`,20)),l.hidden=!0;let u=t(`input`,null,{type:`file`,multiple:``,tabindex:`-1`});u.hidden=!0,u.addEventListener(`change`,()=>{let e=[...u.files??[]];u.value=``,e.length>0&&n.onAttach(e)}),l.addEventListener(`click`,()=>u.click());let d=t(`textarea`,`wui-chat-input`,{rows:`1`,"aria-describedby":r}),f=t(`span`,`visually-hidden`,{id:r}),p=t(`span`,`wui-chat-counter`);p.hidden=!0;let m=t(`button`,`wui-chat-send`,{type:`submit`});m.append(e(`arrow-up`,18));let h=t(`button`,`wui-chat-send wui-chat-send--stop`,{type:`button`});h.append(e(`stop`,16)),h.hidden=!0,h.addEventListener(`click`,()=>n.onStop());let g=t(`form`,`wui-chat-composer`);g.append(l,u,d,p,f,h,m);let _=null,v=null,y=null,b=0,x=null;function S(){d.style.height=`auto`,d.style.height=`${d.scrollHeight}px`;let e=getComputedStyle(d),t=d.scrollHeight-parseFloat(e.paddingTop)-parseFloat(e.paddingBottom);g.classList.toggle(`wui-chat-composer--multiline`,t>(parseFloat(e.lineHeight)||22)*1.5)}function C(){return x?.attachments.some(e=>e.status===`Uploading`)??!1}function w(){return x?.attachments.some(e=>e.status===`Ready`)??!1}function T(){let e=d.value.length,t=b>0&&e>b*bn;p.hidden=!t,t&&y&&(p.textContent=y.counter(e,b))}function E(){let e=x?.messagesLeftToday??null,t=d.value.trim()===``&&!w();m.disabled=!!x?.streaming||e===0||C()||t||x?.handoffPause===!0,g.classList.toggle(`wui-chat-composer--has-text`,!t)}function D(){if(m.disabled)return;let e=d.value.trim();d.value=``,S(),T(),E(),n.voice?.stop(),n.voice?.dismissNote(),n.onSubmit(e)}d.addEventListener(`input`,()=>{S(),T(),E(),d.value!==``&&n.onTyping?.()}),d.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),D())}),g.addEventListener(`submit`,e=>{e.preventDefault(),D()});let O=n.voice,k=O?vn({voice:O,getLabels:()=>{if(y===null)throw Error(`composer labels are read before the first render`);return y},textarea:d,onTextChanged:()=>{S(),T(),E()}}):null;if(O&&k){let e=k.buttons[0];e&&g.insertBefore(e,m),d.addEventListener(`keydown`,e=>_n(e,O))}function ee(r,i){let a=r.map(r=>{let a=t(`span`,`wui-chat-chip`),o=t(`span`,null,r.status===`Failed`?{title:r.error??``}:null);o.textContent=r.fileName;let s=t(`button`,`wui-chat-chip-remove`,{type:`button`,"aria-label":i.removeAttachment(r.fileName)});s.append(e(`x`,14)),s.addEventListener(`click`,()=>n.onRemove(r.key));let c=[];if(r.status===`Uploading`){let e=t(`progress`,`wui-chat-chip-progress`,{max:`1`});typeof r.progress==`number`&&(e.value=r.progress);let n=t(`span`,`wui-chat-chip-status`);n.textContent=i.attachmentUploading,c.push(e,n)}if(r.status===`Failed`){let e=t(`span`,`wui-chat-chip-error`,{"aria-live":`polite`});e.textContent=r.error||i.attachmentFailed,c.push(e)}return a.append(o,...c,s),a});c.replaceChildren(...a),c.hidden=a.length===0}function te(t){x=t.state,y=t.labels,b=t.maxLength,t.sendIcon&&m.dataset.icon!==t.sendIcon&&(m.dataset.icon=t.sendIcon,m.replaceChildren(e(t.sendIcon,18)));let r=x.messagesLeftToday;g.setAttribute(`aria-label`,y.composer),f.textContent=y.composerHint,d.setAttribute(`aria-label`,y.composer),d.maxLength=b,d.placeholder=x.handoffPause?y.handoffMoment:Sn(x.messages)??y.placeholder,d.disabled=r===0||x.handoffPause===!0,i.hidden=!(r!==null&&r<=yn),!i.hidden&&r!==null&&(i.textContent=y.allowance(r));let c=x.editing?.messageId??null;if(c!==_){let e=_!==null;_=c,x.editing?(n.voice?.stop(),d.value=x.editing.text,S()):e&&(d.value=``,S())}s.hidden=!x.editing,a.textContent=y.editing,o.textContent=y.cancel;let p=t.draft??null;typeof p==`string`&&p!==``&&p!==v&&(v=p,d.value=p,d.dispatchEvent(new Event(`input`)),d.focus(),n.onDraftApplied?.()),ee(x.attachments,y);let C=x.features.Attachments&&(x.profile?.limits.maxAttachments??0)>0&&x.handoffPause!==!0;l.hidden=!C,l.setAttribute(`aria-label`,y.attach),l.title=y.attachHint,u.accept=t.accept??``;let w=x.streaming&&x.features.Stop===!0;h.hidden=!w,h.setAttribute(`aria-label`,y.stop),m.hidden=w,m.setAttribute(`aria-label`,y.send),T(),E(),k?.paint({state:x})}function A(){d.focus()}function ne(){k?.destroy();for(let e of j)e.remove()}let j=[i,s,c,...k?[k.note,k.announcer]:[],g];return{nodes:j,paint:te,focus:A,destroy:ne,getDraft:()=>d.value}}var wn=`https://policies.google.com/privacy`,Tn=`https://policies.google.com/terms`;function En(e,n){let r=t(`a`,`wui-chat-footer-link`,{href:n,target:`_blank`,rel:`noopener noreferrer`});return r.textContent=e,r}function Dn(){let e=t(`p`,`wui-chat-footer`);e.hidden=!0;function n(n){let{labels:r,profile:i}=n,a=[];if(i){let e=t(`span`,`wui-chat-footer-text`);e.textContent=i.footer.disclaimer||r.disclaimer,a.push(e);let{privacyText:n}=i.footer,o=le(i.footer.privacyUrl)?i.footer.privacyUrl:null;if(o){let e=t(`span`,`wui-chat-footer-privacy`),i=t(`a`,`wui-chat-footer-link`,{href:o});i.textContent=n||r.footerPrivacyFallback,e.append(i),a.push(e)}else if(n){let e=t(`span`,`wui-chat-footer-privacy`);e.textContent=n,a.push(e)}if(i.footer.assuranceText){let e=t(`span`);e.textContent=i.footer.assuranceText,a.push(e)}if(N(i)){let e=t(`span`,`wui-chat-footer-captcha`);e.append(document.createTextNode(r.captchaNoticeBefore),En(r.captchaPrivacyPolicy,wn),document.createTextNode(r.captchaNoticeAnd),En(r.captchaTerms,Tn),document.createTextNode(r.captchaNoticeAfter)),a.push(e)}}e.replaceChildren(...a),e.hidden=a.length===0}return{el:e,paint:n}}function J(t,n,r){t.setAttribute(`aria-label`,n),t.title=n,t.dataset.icon!==r&&(t.dataset.icon=r,t.replaceChildren(e(r,20)))}function On(e){let n=t(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),r=t(`strong`,`wui-chat-title`);e.titleId&&(r.id=e.titleId);let i=t(`span`,`wui-chat-tagline`),a=t(`span`,`wui-chat-status`),o=t(`div`,`wui-chat-header-text`);o.append(r,i,a);let s=t(`span`,`wui-chat-header-conversation`);s.hidden=!0;let c=g(``,`history`,()=>e.onHistory()),l=g(``,`volume-high`,()=>e.onMute()),u=g(``,`plus`,()=>e.onNew()),d=g(``,`maximize-4`,()=>e.onSwitch());d.classList.add(`wui-chat-switch-btn`,`wui-chat-switch-btn--full`);let f=g(``,`panel-left-open`,()=>e.onSwitch());f.classList.add(`wui-chat-switch-btn`,`wui-chat-switch-btn--side`);let p=g(``,`x`,()=>e.onClose());p.classList.add(`wui-chat-close-btn`);let m=t(`div`,`wui-chat-header-actions`);m.append(s,c,l,u,d,f,p);let h=t(`header`,`wui-chat-header`);h.append(n,o,m);function _(e){let{labels:t}=e;h.hidden=!1,r.textContent=e.title??``,i.textContent=e.tagline??``,i.hidden=!e.tagline,a.textContent=e.status??``,c.hidden=!e.showHistory,e.viewingHistory?J(c,t.backToChat,`arrow-left`):J(c,t.history,`history`),l.hidden=!e.showMute,J(l,e.muted?t.unmuteSounds:t.muteSounds,e.muted?`volume-mute`:`volume-high`),u.hidden=!!e.viewingHistory||e.showNew===!1,u.disabled=!e.canNew,J(u,t.newChat,`plus`),d.hidden=e.switchTo!==`full-page`,d.disabled=!e.canSwitch,J(d,t.openFullScreen,`maximize-4`),f.hidden=e.switchTo!==`docked`,f.disabled=!e.canSwitch,J(f,t.openSidePanel,`panel-left-open`),p.hidden=!e.showClose,J(p,t.close,`x`)}return{el:h,conversation:s,paint:_}}var kn=120;function Y(e,n,r=`outline`){let i=t(`button`,`${s(r,`sm`)} wui-chat-action-btn`,{type:`button`});return i.textContent=e,i.addEventListener(`click`,n),i}function An(e){let n=t(`div`,`wui-chat-history`);n.hidden=!0;let r=null,i=null,a=null,o=null,s=null,c=!1;function l(){return r||(r=A({client:e.getClient()}),i=r.subscribe(()=>y()),r)}function u(e){a={id:e.publicId,kind:`rename`,draft:e.title??``,saving:!1},o=null,s=null,c=!0,y()}function d(e){a={id:e.publicId,kind:`delete`,saving:!1},o=null,s=null,y()}function f(){a=null,o=null,s=null,y()}async function p(){let t=a;if(t?.kind!==`rename`||t.saving)return;let n=t.draft.trim();if(n){t.saving=!0,y();try{await l().rename(t.id,n),a===t&&(a=null),o=null,s=null}catch{if(a!==t)return;t.saving=!1,s=e.getLabels().renameFailed}y()}}async function m(){let t=a;if(!(t?.kind!==`delete`||t.saving)){t.saving=!0,y();try{await l().remove(t.id),a===t&&(a=null),o=null,e.onDeleted(t.id)}catch{if(a!==t)return;t.saving=!1,o=e.getLabels().deleteFailed}y()}}function h(e,n){let r=t(`li`,`wui-chat-history-row wui-chat-history-row--editing`),i=t(`input`,`wui-chat-history-input`,{type:`text`,"aria-label":e.conversationTitle,maxlength:String(kn)});i.value=n.draft,i.addEventListener(`input`,()=>{n.draft=i.value,a.disabled=n.saving||!n.draft.trim()}),i.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.isComposing&&e.keyCode!==229?(e.preventDefault(),p()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),f())});let a=Y(e.renameSave,()=>p(),`primary`);if(a.disabled=n.saving||!n.draft.trim(),r.append(i,a,Y(e.cancel,()=>f(),`ghost`)),s!==null){let e=t(`p`,`wui-chat-history-error`,{role:`alert`});e.textContent=s,r.append(e)}return c&&(c=!1,queueMicrotask(()=>i.focus())),r}function _(e,n){let r=t(`li`,`wui-chat-history-row wui-chat-history-row--confirm`),i=t(`p`);i.textContent=e.deleteConfirmTitle;let a=t(`p`);a.textContent=e.deleteConfirmMessage;let o=Y(e.deleteConfirm,()=>m(),`danger`);return o.disabled=n.saving,r.append(i,a,o,Y(e.cancel,()=>f(),`ghost`)),r}function v(n,r,i){if(a?.id===n.publicId&&a.kind===`rename`)return h(r,a);if(a?.id===n.publicId&&a.kind===`delete`)return _(r,a);let o=t(`li`,`wui-chat-history-row`),s=t(`button`,`wui-chat-history-open`,{type:`button`}),c=t(`span`,`wui-chat-history-title`);c.textContent=n.title||r.untitled;let l=t(`span`,`wui-chat-history-time`);return l.textContent=j(n.lastActivityDateTimeUtc),s.append(c,l),s.addEventListener(`click`,()=>e.onOpen(n.publicId)),o.append(s),i.Rename&&o.append(g(r.rename,`pencil`,()=>u(n))),i.Delete&&o.append(g(r.deleteChat,`trash`,()=>d(n))),o}function y(){let i=e.getLabels(),a=e.getFeatures(),s=r?r.getState():{items:[],totalCount:null,loading:!1,error:null,hasMore:!1},c=[];if(s.error||o){let e=t(`p`,`wui-chat-history-error`,{role:`alert`});s.error?(e.append(document.createTextNode(i.loadFailed),document.createTextNode(` `)),e.append(Y(i.retry,()=>l().load(),`outline`))):e.textContent=o,c.push(e)}if(s.loading&&s.items.length===0){let e=t(`p`,`wui-chat-history-empty`,{role:`status`});e.textContent=i.loadingConversation,c.push(e)}if(s.items.length===0&&!s.loading&&!s.error){let e=t(`p`,`wui-chat-history-empty`),n=t(`span`);n.textContent=i.historyEmptyTitle;let r=t(`span`);r.textContent=i.historyEmptyText,e.append(n,r),c.push(e)}if(s.items.length>0){let e=t(`ul`,`wui-chat-history-list`,{"aria-label":i.history});e.append(...s.items.map(e=>v(e,i,a))),c.push(e)}s.hasMore&&!s.loading&&c.push(Y(i.loadMore,()=>l().loadMore(),`outline`)),n.replaceChildren(...c)}function b(){n.hidden=!1,Promise.allSettled([l().load()]),y()}function x(){n.hidden=!0}function S(){i?.(),i=null,r?.dispose(),r=null}return{el:n,show:b,hide:x,paint:y,dispose:S}}var jn=/* @__PURE__ */ new Set([`GET`,`HEAD`]);function Mn(){let e=document.querySelector(`meta[name="wui-csrf"]`),t=e?.getAttribute(`content`);return t?{token:t,header:e?.getAttribute(`data-header`)||`RequestVerificationToken`}:null}async function Nn(e,{lenient:t=!1}={}){let n=await e.text();if(n){if((e.headers.get(`content-type`)||``).includes(`json`)){if(!t)return JSON.parse(n);try{return JSON.parse(n)}catch{return n}}return n}}async function Pn(e,t,n){let r=new TextDecoder,i=e.getReader(),a=``;for(;;){let{done:e,value:o}=await i.read();if(e)break;a+=r.decode(o,{stream:!0}),n({event:{target:{responseText:a,status:t}}})}return a+=r.decode(),a}function Fn({fetch:e=(...e)=>globalThis.fetch(...e)}={}){async function t(t,n,r,i={}){let a={...i.headers},o;if(typeof FormData<`u`&&r instanceof FormData){for(let e of Object.keys(a))e.toLowerCase()===`content-type`&&delete a[e];o=r}else r!==void 0&&(a[`Content-Type`]=`application/json`,o=JSON.stringify(r));if(!jn.has(t)){let e=Mn();e&&(a[e.header]=e.token)}let s=i.signal,c=s,l,u,d=()=>l?.abort(s?.reason);(i.timeout??0)>0&&(l=new AbortController,c=l.signal,s?.aborted?l.abort(s.reason):s?.addEventListener(`abort`,d,{once:!0}),u=setTimeout(()=>l?.abort(new DOMException(`The request timed out.`,`TimeoutError`)),i.timeout));try{let r={method:t,headers:a,credentials:`same-origin`};o!==void 0&&(r.body=o),c&&(r.signal=c);let s=await e(n,r);if(!s.ok){let e=/* @__PURE__ */ Error(`Request failed with status ${s.status}`);throw e.response={status:s.status,data:await Nn(s,{lenient:!0})},e}let l;return l=i.responseType===`arraybuffer`?await s.arrayBuffer():typeof i.onDownloadProgress==`function`&&s.body?await Pn(s.body,s.status,i.onDownloadProgress):await Nn(s),{data:l,status:s.status}}finally{clearTimeout(u),s?.removeEventListener(`abort`,d)}}return{get:(e,n)=>t(`GET`,e,void 0,n),post:(e,n,r)=>t(`POST`,e,n,r),put:(e,n,r)=>t(`PUT`,e,n,r),delete:(e,n)=>t(`DELETE`,e,void 0,n)}}function In(n){let r,i=!1,a=!1,o=t(`div`,`wui-chat-nudge`,{role:`status`});o.hidden=!0;let s=t(`button`,`wui-chat-nudge-text`,{type:`button`}),c=t(`button`,`wui-chat-nudge-close`,{type:`button`});c.append(e(`x`,14)),o.append(s,c);function l(){clearTimeout(r),r=void 0}function u(){l(),a=!0,o.hidden=!0}s.addEventListener(`click`,()=>{o.hidden=!0,n.onActivate()}),c.addEventListener(`click`,()=>{u(),n.onDismiss()});function d(e){l(),a||i||(r=setTimeout(()=>{r=void 0,s.textContent=e.text,c.setAttribute(`aria-label`,e.label),o.hidden=!1,i=!0},e.delaySeconds*1e3))}function f(){l(),o.remove()}return{el:o,schedule:d,cancel:l,dismiss:u,isShown:()=>i,destroy:f}}function Ln(e,t){e.addEventListener(`click`,()=>t()),e.addEventListener(`keydown`,e=>{(Te(e)||e.key===` `)&&(e.preventDefault(),t())})}function Rn(e){let{list:n,getLabels:r,getFeatures:i,onOpen:a}=e,o=e.now??(()=>Date.now()),s=t(`div`,`wui-chat-empty-rows wui-chat-empty-rows--past`);s.hidden=!0;let c=!1;function l(e,n){let r=t(`div`,`card card-pad-sm card-clickable wui-chat-empty-row`,{role:`button`,tabindex:`0`}),i=t(`div`,`card-body wui-chat-empty-row-body`),s=t(`span`,`wui-chat-empty-row-title`);s.textContent=e.title||n.earlierChat;let c=t(`span`,`wui-chat-empty-row-time`,{title:D(e.lastActivityDateTimeUtc)});return c.textContent=u(e.lastActivityDateTimeUtc,o()),i.append(s,c),r.append(i),Ln(r,()=>a(e.publicId)),r}function d(){if(c)return;let e=n.getState().items;if(i().History!==!0||e.length===0){s.replaceChildren(),s.hidden=!0;return}let t=r();s.replaceChildren(...e.slice(0,20).map(e=>l(e,t))),s.hidden=!1}let f=n.subscribe(d);return{el:s,refresh(){i().History===!0&&n.load().catch(e=>globalThis.reportError?.(e))},paint:d,dispose(){c=!0,f()}}}var zn=`https://www.google.com/recaptcha/api.js?render=`;function Bn(e){return e!==void 0&&typeof e.ready==`function`&&typeof e.execute==`function`}var Vn=/* @__PURE__ */ new Map;function Hn(e){let t=Vn.get(e);if(t!==void 0)return t;let n=new Promise((t,n)=>{let r=globalThis.grecaptcha;if(Bn(r)){t(r);return}let i=document.createElement(`script`);i.src=zn+encodeURIComponent(e),i.async=!0;let a=t=>{Vn.delete(e),n(Object.assign(Error(t),{code:`captcha_unavailable`}))};i.addEventListener(`load`,()=>{let e=globalThis.grecaptcha;e===void 0||typeof e.ready!=`function`?a(`The reCAPTCHA script loaded without grecaptcha.`):e.ready(()=>{let e=globalThis.grecaptcha;Bn(e)?t(e):a(`reCAPTCHA became ready without execute.`)})}),i.addEventListener(`error`,()=>{Vn.delete(e),n(/* @__PURE__ */ Error(`The reCAPTCHA script did not load.`))}),document.head.append(i)});return Vn.set(e,n),n}async function Un(e,t){let n=await Hn(e);await new Promise(e=>n.ready(()=>e()));let r=await n.execute(e,{action:t});if(!r)throw Object.assign(/* @__PURE__ */ Error(`reCAPTCHA returned no token.`),{code:`captcha_unavailable`});return r}var Wn=/* @__PURE__ */ new Set([`Assistant`,`Agent`,`Script`]),Gn=/* @__PURE__ */ new WeakMap;function Kn(e,t,n){let{labels:i,features:a,title:o,busy:s,assistantName:c}=n;if(M(t.parts)!==``){if(a.Share&&v()){let n=r(`ghost`,i.share,`share`,()=>void(async()=>{let e=Zn([t],a,i,o,!1,c);e!==``&&await m({title:o,text:e})===`failed`&&tr(n.parentElement,i.shareFailed)})());n.disabled=s===!0,e.append(n)}if(a.Print){let t=r(`ghost`,i.print,`printer`,()=>{try{let e=t.closest(`.wui-chat`),n=t.closest(`li.wui-chat-message`);if(!(e instanceof HTMLElement)||!(n instanceof HTMLElement))throw Error(`printReply needs a message inside the wui-chat root`);w(e,n,{title:o,printedOn:$n(i)})}catch{er(t,i.printFailed)}});e.append(t)}}}function qn(e,t,n){if(t.streaming||t.thinking||t.loading||t.conversationId===null||t.messages.filter(e=>e.stored&&Wn.has(e.author.kind)&&M(e.parts)!==``).length===0){e.hidden=!0;return}let{labels:r,features:i}=n,a=!!i.Share&&v(),o=!!i.Print;if(!a&&!o){e.hidden=!0;return}let s=[a,o,t.messages.length,r.shareConversation,r.printConversation].join(`|`);e.dataset.sig!==s&&(e.dataset.sig=s,e.replaceChildren(),a&&e.append(Yn(e,r,i,n)),o&&e.append(Xn(e,r,n))),e.hidden=!1}function Jn(e,t,n,i){return e.iconOnly?g(t,n,i):r(`ghost`,t,n,i)}function Yn(e,t,n,r){return Jn(r,t.shareConversation,`share`,()=>void(async()=>{let i=r.getState(),a=Qn(i,r),o=Zn(i.messages.filter(e=>e.stored),n,t,a,!0,i.profile?.assistant.name);await m({title:a,text:o})===`failed`&&tr(e,t.shareFailed)})())}function Xn(e,t,n){let r=Jn(n,t.printConversation,`printer`,()=>{try{let r=e.closest(`.wui-chat`);if(!(r instanceof HTMLElement))throw Error(`printConversation needs the wui-chat root`);c(r,{title:Qn(n.getState(),n),printedOn:$n(t)})}catch{n.iconOnly?tr(e,t.printFailed):er(r,t.printFailed)}});return r}function Zn(e,t,n,r,i,a){let o=k(e,{labels:n,title:r,figureText:t.FigureText,...a===void 0?{}:{assistantName:a}});return ge(o,{heading:i,speakers:i})}function Qn(e,t){return typeof e.title==`string`&&e.title!==``?e.title:t.title}function $n(e){return e.printedOn(j((/* @__PURE__ */ new Date()).toISOString()))}function er(e,t){let n=e.lastChild;if(!(n instanceof Text))return;let r=Gn.get(n);r&&clearTimeout(r.timer);let i=r??{original:n.data};n.data=t,i.timer=setTimeout(()=>{n.data=i.original,Gn.delete(n)},be),Gn.set(n,i)}function tr(e,t){if(!e)return;let n=document.createElement(`span`);n.className=`wui-chat-action-notice`,n.setAttribute(`role`,`status`),n.textContent=t,e.append(n),setTimeout(()=>n.remove(),be)}var nr=`data-wchat-docked`,rr=`--wui-chat-docked-width`,ir=420,ar=/* @__PURE__ */ new Set;function or(e,t){let n=document.documentElement;n.setAttribute(nr,e),n.style.setProperty(rr,t)}function sr(){let e=document.documentElement;e.removeAttribute(nr),e.style.removeProperty(rr)}function cr(e){let t=n({...e,layout:`docked`,role:`dialog`,launcher:!0}),r={},i=e.position,a=!1,o=null,s=()=>`${Math.round(t.panel.getBoundingClientRect().width)||ir}px`;function c(){ar.add(r),or(i,s()),typeof ResizeObserver==`function`&&(o=new ResizeObserver(()=>document.documentElement.style.setProperty(rr,s())),o.observe(t.panel))}function l(){o?.disconnect(),o=null,ar.delete(r),ar.size===0&&sr()}function u(e){t.setOpen(e),e&&!a?(a=!0,c()):!e&&a&&(a=!1,l())}function d(e){t.setAppearance(e),e.position!==void 0&&(i=e.position,a&&document.documentElement.setAttribute(nr,i))}function f(){u(!1)}return{...t,setOpen:u,setAppearance:d,destroy:f}}function lr(e){return n({...e,layout:`embedded`,role:`region`,launcher:!1})}var ur=`wchat:peeked`,dr=576,fr=200;function pr(e){let t=n({...e,layout:`launcher`,role:`dialog`,launcher:!0}),{root:r,panel:i}=t;if(!t.nudgeHost||!t.launcherButton)throw Error(`a launcher shell always has its launcher`);let a=t.nudgeHost,o=t.launcherButton,s={peek:!1,peekSeconds:3,hideWhileOpen:!1,expressive:!1};o.dataset.state=`closed`;let c=!1,l=!1,u,d,f=()=>s.hideWhileOpen||s.expressive;function p(){!s.peek||c||l||a.dataset.launcher!==`idle`||globalThis.innerWidth<dr||globalThis.sessionStorage.getItem(ur)!==null||(globalThis.sessionStorage.setItem(ur,`1`),a.dataset.launcher=`peeking`,u=setTimeout(()=>{u=void 0,a.dataset.launcher===`peeking`&&(a.dataset.launcher=`idle`)},s.peekSeconds*1e3))}a.addEventListener(`animationend`,e=>{e.target===a&&a.dataset.launcher===`idle`&&p()});function m(e){if(e!==l){if(l=e,clearTimeout(u),u=void 0,e)clearTimeout(d),d=void 0,f()?(a.dataset.launcher=`hidden`,a.toggleAttribute(`inert`,!0)):a.dataset.launcher===`peeking`&&(a.dataset.launcher=`idle`);else if(f()){let e=i.contains(document.activeElement);d=setTimeout(()=>{d=void 0,a.toggleAttribute(`inert`,!1),a.dataset.launcher=`idle`,e&&o.focus()},fr)}}o.dataset.state=e?`open`:`closed`,t.setOpen(e)}function h(e){e.reduced!==void 0&&(c=!!e.reduced),e.peek!==void 0&&(s.peek=e.peek),e.peekSeconds!==void 0&&(s.peekSeconds=e.peekSeconds),e.hideWhileOpen!==void 0&&(s.hideWhileOpen=e.hideWhileOpen),e.expressive!==void 0&&(s.expressive=e.expressive===!0),e.phoneMode!==void 0&&r.classList.toggle(`wui-chat--sheet`,e.phoneMode===`Sheet`),e.sheetHeightDvh!==void 0&&r.style.setProperty(`--wui-chat-sheet-height`,`${e.sheetHeightDvh}dvh`),e.sheetMaxHeightPx!==void 0&&r.style.setProperty(`--wui-chat-sheet-max-height`,`${e.sheetMaxHeightPx}px`),t.setAppearance(e),!f()&&a.dataset.launcher===`hidden`&&!l&&(a.dataset.launcher=`idle`),a.dataset.launcher===`idle`&&p()}return{...t,nudgeHost:a,launcherButton:o,setOpen:m,setAppearance:h}}function mr(e){return n({...e,layout:`full-page`,role:`region`,launcher:!1})}var hr=/* @__PURE__ */ new Set([`Agent`,`Customer`]);function gr(){let e=document.createElement(`div`);e.className=`wui-chat-loader-typing`,e.setAttribute(`aria-hidden`,`true`),e.hidden=!0;let t=document.createElement(`span`);t.className=`wui-chat-loader-typing-orb`;let n=document.createElement(`span`);n.className=`wui-chat-loader-typing-dots`;for(let e=0;e<3;e++){let e=document.createElement(`span`);e.className=`wui-chat-loader-typing-dot`,n.append(e)}e.append(t,n);function r({active:n,reduced:r,authorKind:i}){e.hidden=!n,e.classList.toggle(`wui-chat-loader--reduced`,r===!0),t.hidden=hr.has(i)}function i(){e.remove()}return{el:e,update:r,destroy:i}}var _r=3,vr={Primary:`wui-chat-starter--primary`,Cta:`wui-chat-starter--cta`};function yr(e,t){e.addEventListener(`click`,()=>t()),e.addEventListener(`keydown`,e=>{(Te(e)||e.key===` `)&&(e.preventDefault(),t())})}function br(n){let r=t(`h2`,`wui-chat-greeting`),i=t(`div`,`wui-chat-empty-hero`),a=t(`p`,`wui-chat-empty-intro`);a.hidden=!0,i.append(t(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),r,a);let o=t(`div`,`wui-chat-empty-extra`);o.hidden=!0;let s=t(`div`,`wui-chat-starters`,{role:`group`}),c=t(`div`,`wui-chat-empty-rows`),l=t(`div`,`wui-chat-empty-past`),u=t(`div`,`wui-chat-empty`,{role:`group`}),d=gr();u.append(d.el,i,o,s,c,l);let f;function p(r,i){let a=r.variant===null?void 0:vr[r.variant],o=t(`button`,[`wui-chat-starter`,a??``].filter(Boolean).join(` `),{type:`button`});return o.style.setProperty(`--wui-chat-i`,String(i)),r.icon&&o.append(e(r.icon,16)),o.append(document.createTextNode(r.label)),o.addEventListener(`click`,()=>n.onStarter(r)),o}function m(e,r){let i=t(`div`,`card card-pad-sm card-clickable wui-chat-empty-row`,{role:`button`,tabindex:`0`}),a=t(`div`,`card-body wui-chat-empty-row-body`),o=t(`span`,`wui-chat-empty-row-label`);o.textContent=r.resumeLast;let s=t(`span`,`wui-chat-empty-row-title`,{title:e.title||r.untitled});s.textContent=e.title||r.untitled;let c=t(`span`,`wui-chat-empty-row-time`);return c.textContent=j(e.lastActivityDateTimeUtc),a.append(o,s,c),i.append(a),yr(i,()=>n.onResume()),i}function h(e,r,i){let a=i?t(`div`,`card card-pad-sm card-clickable wui-chat-empty-row`,{role:`button`,tabindex:`0`}):t(`div`,`card card-pad-sm wui-chat-empty-row`),o=t(`div`,`card-body wui-chat-empty-row-body`),s=t(`span`,`wui-chat-empty-row-label`);s.textContent=r.ticketAria(e.number);let c=t(`span`,`wui-chat-empty-row-title`);c.textContent=e.subject;let l=t(`span`,`wui-chat-empty-row-status`);return l.textContent=dt(e.status,r),o.append(s,c,l),a.append(o),i&&yr(a,()=>n.onTicket(e)),a}function g(e,n){if(e.features?.OpenTickets!==!0||!e.openTickets?.length)return null;let r=t(`div`,`wui-chat-open-tickets`,{role:`group`,"aria-label":n.openTickets});return r.append(...e.openTickets.slice(0,_r).map(t=>h(t,n,e.ticketsClickable===!0))),r}function _(e){let{labels:t}=e;r.textContent=e.greeting??``;let n=e.intro??``;a.textContent=n,a.hidden=!n,u.setAttribute(`aria-label`,t.emptyTitle);let i=e.starters??[];s.setAttribute(`aria-label`,t.starters),s.hidden=!e.showStarters||i.length===0,s.replaceChildren(...i.map(p));let o=e.resume??null,l=g(e,t);c.hidden=o===null&&l===null,c.replaceChildren(...[o===null?null:m(o,t),l].filter(e=>e!==null))}function v(e){clearTimeout(f),u.classList.remove(`wui-chat-empty--revealed`),u.classList.add(`wui-chat-empty--intro`),d.update({active:!0,reduced:!1,authorKind:`Assistant`}),f=setTimeout(()=>{f=void 0,d.update({active:!1,reduced:!1,authorKind:`Assistant`}),u.classList.replace(`wui-chat-empty--intro`,`wui-chat-empty--revealed`)},e)}return{el:u,paint:_,intro:v,extraHost:o,pastHost:l}}function xr(){let e=document.createElement(`div`);e.className=`wui-chat-loader-orb`;let t=document.createElement(`span`);t.className=`wui-chat-loader-orb-mark`,t.setAttribute(`aria-hidden`,`true`);let n=document.createElement(`span`);n.className=`wui-chat-loader-orb-glow`,n.setAttribute(`aria-hidden`,`true`);let r=document.createElement(`span`);r.className=`wui-chat-loader-orb-disc`,r.setAttribute(`aria-hidden`,`true`),t.append(n,r);let i=document.createElement(`span`);return i.className=`wui-chat-loader-orb-label`,e.append(t,i),{el:e,render(e){i.textContent!==e.label&&(i.textContent=e.label)}}}var Sr=150,Cr=1800;function wr(){let e=document.createElement(`div`);e.className=`wui-chat-loader-phrases`;let t=document.createElement(`span`);t.className=`wui-chat-loader-phrases-orb`,t.setAttribute(`aria-hidden`,`true`);let n=document.createElement(`span`);n.className=`wui-chat-loader-phrases-stage`,e.append(t,n);let r=null,i=null;function a(){return e.closest(`.wui-chat-loader`)?.classList.contains(`wui-chat-loader--reduced`)===!0}function o(e){if(e.label===r)return;r=e.label;let t=i,o=document.createElement(`span`);o.className=`wui-chat-loader-phrases-text wui-chat-loader-phrases-text--in`,o.textContent=e.label,o.style.animationDelay=`-${Math.round(performance.now()%Cr)}ms, 0s`,n.append(o),i=o,t&&(t.classList.remove(`wui-chat-loader-phrases-text--in`),t.classList.add(`wui-chat-loader-phrases-text--out`),t.style.animationDelay=`-${Math.round(performance.now()%Cr)}ms, 0s`,a()?t.remove():setTimeout(()=>t.remove(),Sr))}return{el:e,render:o}}var Tr=[`95%`,`80%`,`60%`];function Er(){let e=document.createElement(`div`);e.className=`wui-chat-loader-skeleton`;let t=document.createElement(`div`);t.className=`wui-chat-loader-skeleton-label`;let n=document.createElement(`div`);n.className=`wui-chat-loader-skeleton-body`;let r=document.createElement(`span`);r.className=`wui-chat-loader-skeleton-avatar`,r.setAttribute(`aria-hidden`,`true`),n.append(r);for(let e of Tr){let t=document.createElement(`span`);t.className=`wui-chat-loader-skeleton-line`,t.setAttribute(`aria-hidden`,`true`),t.style.width=e,n.append(t)}return e.append(t,n),{el:e,render(e){t.textContent!==e.label&&(t.textContent=e.label)}}}var Dr=`http://www.w3.org/2000/svg`;function Or(e){if(e===`done`){let e=document.createElementNS(Dr,`svg`);e.setAttribute(`viewBox`,`0 0 16 16`),e.setAttribute(`class`,`wui-chat-loader-steps-check`);let t=document.createElementNS(Dr,`path`);return t.setAttribute(`d`,`M3 8.5 6.5 12 13 4.5`),t.setAttribute(`pathLength`,`1`),e.append(t),e}let t=document.createElement(`span`);return t.className=e===`active`?`wui-chat-loader-steps-ring`:`wui-chat-loader-steps-dot`,t}function kr(){let e=document.createElement(`div`);e.className=`wui-chat-loader-steps`;let t=document.createElement(`span`);t.className=`wui-chat-loader-steps-pill`;let n=document.createElement(`ol`);n.className=`wui-chat-loader-steps-list`,e.append(t,n);let r=[];function i(){let e=document.createElement(`li`);e.className=`wui-chat-loader-steps-item`;let t=document.createElement(`span`);t.className=`wui-chat-loader-steps-icon`,t.setAttribute(`aria-hidden`,`true`);let i=document.createElement(`span`);i.className=`wui-chat-loader-steps-text`,e.append(t,i);let a={li:e,icon:t,text:i,state:null};return r.push(a),n.append(e),a}function a(e){let a=e.steps.length===0;for(t.hidden=!a,n.hidden=a,a&&t.textContent!==e.label&&(t.textContent=e.label),e.steps.forEach((t,n)=>{let a=r[n]??i();a.text.textContent!==t&&(a.text.textContent=t);let o=n<e.activeIndex?`done`:n===e.activeIndex?`active`:`pending`;a.state!==o&&(a.state=o,a.li.dataset.state=o,a.icon.replaceChildren(Or(o)))});r.length>e.steps.length;)r.pop()?.li.remove()}return{el:e,render:a}}var Ar={Steps:kr,Phrases:wr,Orb:xr,Skeleton:Er},jr=500;function Mr(){let e=document.createElement(`div`);e.className=`wui-chat-loader`,e.setAttribute(`role`,`status`),e.hidden=!0;let t=document.createElement(`span`);t.className=`wui-chat-loader-avatar`,t.setAttribute(`aria-hidden`,`true`);let n=document.createElement(`div`);n.className=`wui-chat-loader-body`;let r=document.createElement(`span`);r.className=`visually-hidden`,e.append(t,n,r);let a=null,o=null,s=0,c=null,l=0,u=null,d=!1;function f(){c!==null&&clearInterval(c),c=null}function p(){e.isConnected?(s+=1,m()):f()}function m(){if(!o||!a)return;let t=ue(a.style,a.steps,a.phrases,s);o.render(t),e.setAttribute(`aria-label`,t.label)}function h(){u!==null&&clearTimeout(u),u=null,d=!1,r.textContent=``}function g(e){!d&&u===null&&e&&(u=setTimeout(()=>{u=null,d=!0,r.textContent=e},jr))}function _(t){if(!t.active)a=null,e.hidden=!0,e.removeAttribute(`data-loading`),f(),h();else{if(!i(Ar,t.style))throw Error(`Unknown loader style. Use Steps, Phrases, Orb or Skeleton.`);if(!(t.intervalMs>0))throw Error(`Loader intervalMs must be a positive number.`);if(a={...t,steps:t.steps??[],phrases:t.phrases??[]},e.hidden=!1,e.setAttribute(`data-loading`,`true`),e.classList.toggle(`wui-chat-loader--reduced`,t.reduced===!0),!o||o.style!==t.style){let r=Ar[t.style]();n.replaceChildren(r.el),o={style:t.style,render:r.render},e.dataset.style=t.style,s=0}g(t.announce),t.reduced===!0?(f(),s=0):(c===null||l!==t.intervalMs)&&(f(),l=t.intervalMs,c=setInterval(p,l)),m()}}function v(){f(),h(),o=null,a=null,e.remove()}return{el:e,update:_,destroy:v}}function Nr({voice:e,getLabels:n,message:r}){if(r.streaming||!e.canSpeak()||pn(r.parts)===``)return null;let i=e.getStatus(),a=i.mode===`Speaking`&&i.messageId===r.id,o=n(),s=a?o.readAloudStop:o.readAloud,c=t(`button`,`wui-chat-action-btn wui-chat-speak`,{type:`button`,"aria-pressed":String(a),"aria-label":s,title:s});return c.append(rn(a?`stop`:`speaker`,16)),c.addEventListener(`click`,()=>{e.toggleSpeak(r.id,r.parts)}),c}function Pr({voice:e,getLabels:n,message:r}){let i=e.getStatus().note;if(i?.code!==`SpeakFailed`||i.messageId!==r.id)return null;let a=t(`span`,`wui-chat-action-notice`,{role:`status`});return a.textContent=mn(i,n()),a}function Fr(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.author.kind===`Visitor`&&n.stored)return n}}var Ir=/* @__PURE__ */ new Set([`Assistant`,`Agent`]),Lr=/* @__PURE__ */ new Set([`Assistant`,`Agent`,`Script`]),Rr=/* @__PURE__ */ new Set([`Visitor`,`Customer`]),zr=48,Br=120,Vr={author:{kind:`Assistant`,displayName:null,avatarUrl:null}},Hr={warning:`alert-triangle`,danger:`alert-circle`};function Ur(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=zr}function Wr(e){let{kind:t,displayName:n}=e.author;return t===`Agent`?`Agent:${n??``}`:t===`Script`?`Assistant`:t}function Gr(e){for(let t=e?.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e}=getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t}return null}function Kr(e){let t=e.textContent?.trim();t&&!e.hasAttribute(`aria-label`)&&(e.setAttribute(`aria-label`,t),e.setAttribute(`title`,t))}function qr(e){return e.reduced===!0}function Jr(n,r,i){let a=t(`button`,`${s(`ghost`,`sm`)} wui-chat-action-btn`,{type:`button`,"aria-label":n,title:n}),o=t(`span`);return o.textContent=n,a.append(e(r,14),o),a.addEventListener(`click`,i),{node:a,text:o}}function Yr(e,t){return e.profile?.assistant.name??t.panelTitle}function Xr(e,t,n){return e.author.displayName==null?e.author.kind===`Visitor`||e.author.kind===`Customer`?n.you:e.author.kind===`Agent`?n.agent:t.profile?.assistant.name??n.assistant:e.author.displayName}function Zr(e){let n=t(`li`,`wui-chat-day`,{role:`presentation`}),r=t(`span`);return r.textContent=e,n.append(r),n}function Qr(n){let r=t(`ol`,`wui-chat-thread`),i=t(`div`,`wui-chat-log`,{role:`log`,"aria-live":`polite`});i.append(r);let a=Mr(),o=t(`li`,`wui-chat-message wui-chat-message--assistant wui-chat-message--loading`),c=t(`div`,`wui-chat-loader-slot`);c.append(a.el),o.append(c);let l=!1,u,d=t(`li`,`wui-chat-message wui-chat-message--assistant wui-chat-message--greeting`,{"data-run-start":``,"data-restored":``}),f=t(`div`,`wui-chat-message-body`),p=t(`p`,`wui-chat-text`);f.append(p),d.append(f);let m=t(`button`,`wui-chat-jump`,{type:`button`}),h=t(`div`,`wui-chat-jump-slot`);h.hidden=!0,h.append(m);let g=null,_=!0,v=null,y=null,b=/* @__PURE__ */ new Map,x=``,S=null;function C(e,t){return{kind:e.kind,part:e,tag:t[e.kind]}}function w(e,t,r){return Object.assign(document.createElement(e),{message:r,turn:n.makeTurnApi(r.id),chatPart:t})}function T(e){return t(`div`,`wui-chat-part wui-chat-part--${e.toLowerCase()}`)}function E(e,n,r,i){e.parts=[];let a=[],o=e=>{let t=C(e,r),i=T(t.kind);return i.append(w(t.tag,t.part,n)),i};for(let e of i(n))if(Array.isArray(e)){let n=t(`div`,`wui-chat-part-group`);n.append(...e.map(o)),a.push(n)}else a.push(o(e));e.body.replaceChildren(...a)}function O(e,t,r){let i=[];t.parts.forEach((a,o)=>{let s=C(a,r),c=e.parts[o];if(c&&c.kind===s.kind&&c.tag===s.tag){c.part!==s.part&&(c.element.message=t,c.element.turn=n.makeTurnApi(t.id),c.element.chatPart=s.part,c.part=s.part),i.push(c);return}let l=T(s.kind),u=w(s.tag,s.part,t);l.append(u),i.push({kind:s.kind,tag:s.tag,part:s.part,element:u,wrapper:l})}),e.parts=i,k(e.body,i.map(e=>e.wrapper))}function k(e,t){let n=new Set(t);for(let t of[...e.children])n.has(t)||t.remove();t.forEach((t,n)=>{e.children[n]!==t&&e.insertBefore(t,e.children[n]??null)})}function ee(n,r,i){let a=t(`div`,`wui-chat-rating`,{role:`group`,"aria-label":`${i.rateUp} / ${i.rateDown}`}),o=[[`Up`,i.rateUp,`thumbs-up`],[`Down`,i.rateDown,`thumbs-down`]];for(let[c,l,u]of o){let o=r.rating===c,d=t(`button`,`${s(o?`neutral`:`ghost`,`sm`)} wui-chat-action-btn`,{type:`button`,"aria-pressed":String(o),"data-rating":c,"aria-label":l,title:l}),f=t(`span`);f.textContent=l,d.append(e(u,14),f),d.addEventListener(`click`,()=>te(n,r,c,i)),a.append(d)}if(n.ratingNote){let e=t(`span`,null,{role:`status`});e.textContent=n.ratingNote,a.append(e)}return a}async function te(e,t,r,i){try{await n.onRate(t.id,r),e.ratingNote=i.rated}catch{e.ratingNote=i.ratingFailed}S&&N(S.state,S.context)}function A(e,r,i,a,o){let{labels:s}=a,c=i.features,l=r.author.kind,u=M(r.parts),d=[];if(c.Copy&&Lr.has(l)&&u){let t=Jr(s.copy,`copy`,()=>void(async()=>{await xe(u)&&(t.text.textContent=s.copied,t.node.dataset.done=``,t.node.setAttribute(`aria-label`,s.copied),t.node.title=s.copied,clearTimeout(e.copyTimer),e.copyTimer=setTimeout(()=>{t.text.textContent=s.copy,delete t.node.dataset.done,t.node.setAttribute(`aria-label`,s.copy),t.node.title=s.copy},be))})());d.push(t.node)}let f=n.getVoice?.();if(f&&Lr.has(l)){let e=Nr({voice:f,getLabels:()=>s,message:r});e&&d.push(e);let t=Pr({voice:f,getLabels:()=>s,message:r});t&&d.push(t)}if(Lr.has(l)){let e=t(`div`);Kn(e,r,{labels:s,features:c,title:Yr(i,s),assistantName:i.profile?.assistant.name,busy:i.streaming||i.thinking});for(let t of e.children)Kr(t);d.push(...e.childNodes)}let p=i.messages.some(e=>e.author.kind===`Visitor`&&e.stored);o&&l===`Assistant`&&!i.streaming&&!i.thinking&&c.Regenerate&&p&&d.push(Jr(s.regenerate,`refresh`,()=>n.onRegenerate()).node);let m=Fr(i.messages);c.Edit&&m?.id===r.id&&!i.streaming&&!i.thinking&&d.push(Jr(s.edit,`pencil`,()=>n.getSession().startEdit(r.id)).node),c.Rating&&r.stored&&Ir.has(l)&&d.push(ee(e,r,s)),e.actions.hidden=d.length===0,e.actions.replaceChildren(...d)}function ne(e){let n=b.get(e.id);if(n)return n;let r=t(`li`,`wui-chat-message`),i=t(`span`,`wui-chat-author visually-hidden`),a=t(`div`,`wui-chat-message-body`),o=t(`div`,`wui-chat-message-actions`);r.append(i,a,o);let s={li:r,author:i,body:a,actions:o,head:null,parts:[],copyTimer:void 0,ratingNote:null};return b.set(e.id,s),s}function j(e,t,n,r){let i=n?.author.kind===`Agent`&&t.author.kind===`Agent`&&(n.author.displayName??``)===(t.author.displayName??``);e.head?.remove(),e.head=t.author.kind===`Agent`&&!i?ct(t.author,r):null,e.head&&e.li.insertBefore(e.head,e.body)}function ie(e,t,r,i,a,o){let{labels:s}=i;e.li.className=`wui-chat-message wui-chat-message--${t.author.kind.toLowerCase()}`,e.li.toggleAttribute(`data-restored`,t.restored===!0),e.li.toggleAttribute(`data-run-start`,!o||Wr(o)!==Wr(t)),t.streaming?e.li.setAttribute(`aria-busy`,`true`):e.li.removeAttribute(`aria-busy`),e.author.textContent=`${Xr(t,r,s)}: `,j(e,t,o,s);let c=n.getRenderers(),l=n.getLayoutParts();typeof l==`function`?E(e,t,c,l):O(e,t,c),t.streaming?(e.actions.hidden=!0,e.actions.replaceChildren()):A(e,t,r,i,a)}function ae(n,r){let i=t(`li`,`wui-chat-message wui-chat-message--system wui-chat-message--notice`),a=t(`div`,`wui-chat-notice wui-chat-notice--${n}`,{role:n===`danger`?`alert`:`status`}),o=t(`span`,`wui-chat-notice-icon`,{"aria-hidden":`true`});o.append(e(Hr[n],16));let s=t(`div`,`wui-chat-notice-body`),c=t(`span`,`wui-chat-notice-text`);return c.textContent=r,s.append(c),a.append(o,s),i.append(a),i}function oe(e,t){let n=e.resetsDateTimeUtc?` ${t.dailyLimitRefresh(D(e.resetsDateTimeUtc))}`:``;return ae(`warning`,`${e.message}${n}`)}function se(r,i){let{labels:a}=i,o=r.turnError,s=o?.code??``;if(o&&s===`daily_limit`)return oe(o,a);if(s.endsWith(`feature_off`))return ae(`danger`,r.turnError?.message||a.stopped);let c=t(`li`,`wui-chat-message wui-chat-message--system wui-chat-message--error`),l=t(`p`,`wui-chat-error`,{role:`alert`});l.textContent=r.turnError?.message||a.stopped;let u=e(`alert-circle`,16);if(u.setAttribute(`aria-hidden`,`true`),c.append(u,l),r.features.Retry){let e=t(`div`,`wui-chat-message-actions`);e.append(Jr(a.retry,`rotate-ccw`,()=>n.onRetry()).node),c.append(e)}return c}function ce(){return r.closest(`.wui-chat`)}function le(){return r.closest(`.wui-chat-body`)??Gr(r)}function ue(e){ce()?.classList.toggle(`wui-chat--scrolled`,e.scrollTop>0),Ur(e)&&(h.hidden=!0)}function de(){g!==null&&(_=Ur(g),ue(g))}function fe(e){i.nextElementSibling!==h&&i.parentNode&&i.after(h),e!==g&&(g?.removeEventListener(`scroll`,de),g=e,e.addEventListener(`scroll`,de,{passive:!0}),!v&&typeof ResizeObserver==`function`&&(v=new ResizeObserver(()=>{_&&g&&(g.scrollTop=g.scrollHeight)}),v.observe(r)))}m.addEventListener(`click`,()=>{let e=le(),t=S?.context.reduced===!0;e?.scrollTo({top:e.scrollHeight,behavior:t?`auto`:`smooth`}),h.hidden=!0,m.blur()});function pe(e,t){let n=e.messages[e.messages.length-1],r=n?`${n.id}|${n.parts.length}|${M(n.parts).length}`:``;if(r===x)return;let i=x===``||e.conversationId!==y;x=r,y=e.conversationId;let a=le();a&&(fe(a),i||t||n!==void 0&&Rr.has(n.author.kind)?(a.scrollTop=a.scrollHeight,h.hidden=!0,_=!0):(h.hidden=!1,_=!1),ue(a))}function N(e,t){S={state:e,context:t};let{labels:n}=t;i.setAttribute(`aria-label`,n.thread),m.textContent=n.newMessages??`New messages`;let s=le();s&&fe(s);let c=s===null||s.clientHeight===0||Ur(s),f=[],h=/* @__PURE__ */ new Set,g=e.messages.filter(e=>!(e.streaming&&e.parts.length===0)),_=g[0],v=_!==void 0&&Rr.has(_.author.kind)&&e.greeting?e.greeting:null,y=null,x=e=>{let t=re(e.createdDateTimeUtc,n);t!==y&&(y=t,f.push(Zr(t)))};v&&_&&(x(_),p.textContent=v,f.push(d)),g.forEach((n,r)=>{let i=ne(n);h.add(n.id),x(n);let a=g[r-1]??(v?Vr:null);ie(i,n,e,t,r===g.length-1,a),f.push(i.li)});for(let e of[...b.keys()])h.has(e)||b.delete(e);e.agentTyping&&f.push(lt(e.agentTyping,n)),e.thinking?(clearTimeout(u),u=void 0,o.classList.remove(`wui-chat-message--leaving`),l=!0,a.update({active:!0,style:t.loaderStyle,steps:e.steps,phrases:t.phrases,intervalMs:t.intervalMs,reduced:t.reduced,announce:t.assistantName?.trim()?n.preparingAnswer(t.assistantName):void 0}),f.push(o)):l&&u===void 0&&!qr(t)?(o.classList.add(`wui-chat-message--leaving`),u=setTimeout(()=>{u=void 0,l=!1,o.classList.remove(`wui-chat-message--leaving`),a.update({active:!1}),S&&N(S.state,S.context)},Br),f.push(o)):u===void 0?(l=!1,a.update({active:!1})):f.push(o),!e.streaming&&(e.turnError||e.stopped)&&f.push(se(e,t)),k(r,f),pe(e,c)}function me(e){return b.get(e)?.li??null}function P(){clearTimeout(u),a.destroy(),g?.removeEventListener(`scroll`,de),v?.disconnect(),b.clear(),S=null,i.remove()}return{el:i,paint:N,find:me,destroy:P}}var $r=[`launcher`,`docked`,`full-page`,`embedded`],ei=[`end`,`start`],ti={steps:`Steps`,phrases:`Phrases`,orb:`Orb`,skeleton:`Skeleton`},ni={on:`On`,reduced:`Reduced`},ri=[`auto`,`light`,`dark`];function ii(e){return ri.find(t=>t===e)??`auto`}var ai=`wchat:muted`,oi=6e4,si=400,ci=[`labels`,`pageContext`,`compact`,`expressive`,`open`,`layoutParts`,`getCaptchaToken`,`attribution`,`openAttachment`,`openCitation`,`openTarget`,`openTicket`,`onNavigate`,`resolveLink`,`emptyContent`,`onPanelSwitch`,`preloadPanelSwitch`],li={...cn};function ui(e,t){if(!T.includes(e))throw Error(`Unknown part kind "${e}". Use one of ${T.join(`, `)}.`);if(typeof t!=`string`||!t.includes(`-`))throw Error(`Renderer tag "${t}" must be a custom element name containing a hyphen.`)}function X(e,t){return n=>{let r=n.toLowerCase(),a=i(t,r)?t[r]:void 0;if(a===void 0)throw Error(`<wui-chat ${e}> must be one of ${Object.keys(t).join(`, `)}, got "${n}".`);return a}}function Z(e){return t=>{let n=Number(t);if(!Number.isInteger(n)||n<0)throw Error(`<wui-chat ${e}> must be a whole number of pixels, got "${t}".`);return n}}function Q(e){return t=>{if(t===``||t===`true`)return!0;if(t===`false`)return!1;throw Error(`<wui-chat ${e}> must be true or false, got "${t}".`)}}var $=e=>e.split(`,`).map(e=>e.trim()).filter(Boolean),di=[[`launcher-style`,`launcher`,`style`,X(`launcher-style`,{round:`Round`,pill:`Pill`})],[`entrance`,`launcher`,`entrance`,X(`entrance`,{"slide-up":`SlideUp`,"bounce-in":`BounceIn`,"fade-in-pulse":`FadeInPulse`,"spin-scale":`SpinScale`,"wiggle-in":`WiggleIn`,"elastic-in":`ElasticIn`,rise:`Rise`,none:`None`})],[`idle`,`launcher`,`idle`,X(`idle`,{"float-and-pulse":`FloatAndPulse`,ring:`Ring`,none:`None`})],[`label-reveal`,`launcher`,`labelReveal`,X(`label-reveal`,{bubble:`Bubble`,expand:`Expand`})],[`compact`,`launcher`,`compact`,Q(`compact`)],[`launcher-mark`,`launcher`,`mark`,X(`launcher-mark`,{icon:`Icon`,avatar:`Avatar`,orb:`Orb`})],[`panel-height`,`panel`,`height`,X(`panel-height`,{fixed:`Fixed`,content:`Content`})],[`reply-avatars`,`panel`,`replyAvatars`,Q(`reply-avatars`)],[`greeting-loader-ms`,`panel`,`greetingLoaderMs`,Z(`greeting-loader-ms`)],[`panel-motion`,`panel`,`motion`,X(`panel-motion`,{spring:`Spring`,gentle:`Gentle`,none:`None`})],[`panel-width`,`panel`,`widthPx`,Z(`panel-width`)],[`panel-max-height`,`panel`,`maxHeightPx`,Z(`panel-max-height`)],[`panel-bottom-gap`,`panel`,`bottomGapPx`,Z(`panel-bottom-gap`)],[`phone-max-width`,`phone`,`maxWidthPx`,Z(`phone-max-width`)],[`phone-mode`,`phone`,`mode`,X(`phone-mode`,{"full-screen":`FullScreen`,sheet:`Sheet`})],[`sheet-height-dvh`,`phone`,`sheetHeightDvh`,Z(`sheet-height-dvh`)],[`sheet-max-height`,`phone`,`sheetMaxHeightPx`,Z(`sheet-max-height`)],[`input-ring`,`input`,`ring`,Q(`input-ring`)],[`send-reveal`,`input`,`sendReveal`,X(`send-reveal`,{"on-text":`OnText`,always:`Always`})],[`send-icon`,`input`,`sendIcon`,e=>e],[`lift-selectors`,`avoid`,`liftSelectors`,$],[`menu-selectors`,`avoid`,`menuSelectors`,$],[`dark-selectors`,`avoid`,`darkSelectors`,$],[`autoopen-busy-selectors`,`avoid`,`autoOpenBusySelectors`,$],[`autoopen-optout-selector`,`avoid`,`autoOpenOptOutSelector`,e=>e]],fi={layout:`launcher`,position:`end`,"offset-x":`24`,"offset-y":`24`,loader:`steps`,motion:`on`,icon:`chat`},pi=[`base`,`layout`,`position`,`offset-x`,`offset-y`,`loader`,`screen`,`motion`,`theme`,`icon`,`avatar`,`narrow`,...di.map(([e])=>e).filter(e=>e!==`compact`)],mi=e=>e.replace(/-([a-z0-9])/g,(e,t)=>t.toUpperCase());function hi(e){let t={launcher:{},panel:{},phone:{},input:{},avoid:{}};for(let[n,r,i,a]of di){let o=e.getAttribute(n);o!=null&&(t[r][i]=a(o))}let n=e.getAttribute(`motion`),r=e.getAttribute(`avatar`),i=e.getAttribute(`expressive`),a={...t,...n==null?{}:{motion:X(`motion`,ni)(n)},...r?{avatar:r}:{},...i==null?{}:{expressive:Q(`expressive`)(i)}};return fe(a)}function gi(e){let t=e.getAttribute(`loader`)??`steps`,n=i(ti,t)?ti[t]:void 0;if(n===void 0)throw Error(`<wui-chat loader> must be one of ${Object.keys(ti).join(`, `)}, got "${t}".`);return n}function _i(e){let t=e.getAttribute(`narrow`);if(t!=null&&t!==``)return Object.fromEntries($(t).map(e=>[e,!1]))}function vi(e){return e===ai?globalThis.localStorage:globalThis.sessionStorage}var yi={get:e=>vi(e).getItem(e),set:(e,t)=>vi(e).setItem(e,t)};function bi(e){return globalThis.innerWidth<=e.phone.maxWidthPx}function xi(e){let t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)}function Si(e){return e.features.HumanHandoff===!0&&e.conversationState===`Open`&&e.messages.some(e=>e.author.kind===`Visitor`||e.author.kind===`Customer`)&&!e.streaming&&!e.thinking}function Ci(e,t){if(e.conversationState===`WaitingForAgent`)return t.statusWaitingForAgent;if(e.conversationState===`WithAgent`){let n=e.agent?.displayName;return t.statusWithAgent(typeof n==`string`&&n.trim()!==``?n:t.handoffAgentFallback)}return t.headerStatus}function wi(e,t,n){return t.PanelSwitch!==!0||typeof n!=`function`?null:e===`docked`?`full-page`:e===`full-page`?`docked`:null}function Ti(e){if(!$r.some(t=>t===e))throw Error(`<wui-chat layout> must be one of ${$r.join(`, `)}, got "${e}".`)}function Ei(e){if(!ei.some(t=>t===e))throw Error(`<wui-chat position> must be one of ${ei.join(`, `)}, got "${e}".`)}function Di(e,t){let n=e[t];delete e[t],e[t]=n}function Oi(e){return e==null?{}:Object(e)}var ki=0,Ai=class extends De{static get observedAttributes(){return[...pi,`compact`,`expressive`,`open`,`labels`,`page-context`,`narrow`].filter((e,t,n)=>n.indexOf(e)===t)}constructor(){super(),ki+=1,this._uid=`wui-chat-${ki}`,this._built=!1,this._session=null,this._unsubscribe=null,this._voice=null,this._voiceConversationId=void 0,this._labelsProp=void 0,this._pageContextProp=void 0,this._layoutParts=null,this._renderers={...li},this._rendererApi={define:(e,t)=>{ui(e,t),this._renderers[e]=t,this._render()},map:this._renderers},this._captchaToken=null,this._attribution=null,this._openAttachmentProp=null,this._openCitationProp=null,this._openTargetProp=null,this._resolveLinkProp=null,this._openTicketProp=void 0,this._emptyContentProp=null,this._onPanelSwitchProp=null,this._preloadPanelSwitchProp=null,this._preloaded=!1,this._pastList=null,this._past=null,this._pastRefreshed=!1,this._historyShown=!1,this._openedConversation=null,this._lastOpen=!1,this._openTrigger=`manual`,this._focusTimer=null,this._nudgeArmed=!1,this._seeded=!1,this._wasLoading=!1,this._seen=/* @__PURE__ */ new Set,this._sound=null,this._behaviour=null,this._autoOpen=null,this._avoid=null,this._motion=null,this._phone=null,this._requesting=!1,this._onKeyDown=e=>{e.key===`Escape`&&this._session?.getState().open&&(e.stopPropagation(),this._session.close(`escape`))}}get session(){return this._session??null}get conversationId(){return this._session?.getState().conversationId??null}get labels(){return de({...Oi(h(this,`labels`)),...this._labelsProp})}set labels(e){this._labelsProp=e??void 0,this._render()}get pageContext(){return this._pageContextProp===void 0?h(this,`page-context`):this._pageContextProp}set pageContext(e){this._pageContextProp=e===null?void 0:e}get compact(){let e=this.getAttribute(`compact`);return e!=null&&Q(`compact`)(e)}set compact(e){this.toggleAttribute(`compact`,e===!0||e===``||e===`true`)}get expressive(){let e=this.getAttribute(`expressive`);return e!=null&&Q(`expressive`)(e)}set expressive(e){this.toggleAttribute(`expressive`,e===!0||e===``||e===`true`)}get open(){return this.hasAttribute(`open`)}set open(e){this.toggleAttribute(`open`,e===!0||e===``||e===`true`)}get renderers(){return this._rendererApi}get layoutParts(){return this._layoutParts}set layoutParts(e){this._layoutParts=typeof e==`function`?e:null,this._render()}get getCaptchaToken(){return this._captchaToken}set getCaptchaToken(e){this._captchaToken=typeof e==`function`?e:null}get attribution(){return this._attribution}set attribution(e){this._attribution=typeof e==`function`?e:null}get openAttachment(){return this._openAttachmentProp??(e=>this._defaultOpenAttachment(e))}set openAttachment(e){this._openAttachmentProp=typeof e==`function`?e:null}get openCitation(){return this._openCitationProp??((e,t)=>this._defaultOpenCitation(e,t))}set openCitation(e){this._openCitationProp=typeof e==`function`?e:null}get openTarget(){return this._openTargetProp??(e=>this._defaultOpenTarget(e))}set openTarget(e){this._openTargetProp=typeof e==`function`?e:null}get openTicket(){return this._openTicketProp}set openTicket(e){this._openTicketProp=typeof e==`function`?e:void 0}get onNavigate(){return this._onNavigateProp}set onNavigate(e){this._onNavigateProp=typeof e==`function`?e:void 0}get resolveLink(){return this._resolveLinkProp}set resolveLink(e){this._resolveLinkProp=typeof e==`function`?e:null}get emptyContent(){return this._emptyContentProp}set emptyContent(e){if(e!==null&&!(e instanceof Node))throw TypeError(`emptyContent must be a Node or null`);this._emptyContentProp=e,this._applyEmptyContent()}get onPanelSwitch(){return this._onPanelSwitchProp}set onPanelSwitch(e){this._onPanelSwitchProp=typeof e==`function`?e:null}get preloadPanelSwitch(){return this._preloadPanelSwitchProp}set preloadPanelSwitch(e){this._preloadPanelSwitchProp=typeof e==`function`?e:null}connectedCallback(){this._adoptEarlyProperties();let e=this._assertLayout();if(this._assertPosition(),this.base.trim()===``)throw TypeError(`<wui-chat> needs a base path, e.g. base="/api/assistant".`);this._built||this._build(),this._shell||this._buildShell(e),this._session||this._createSession(),this._past||this._createPast(),this._unsubscribe||=this.requireSession().subscribe(()=>this._render()),this._render()}_adoptEarlyProperties(){for(let e of ci)i(this,e)&&Di(this,e)}disconnectedCallback(){this._voice?.stop(),this._session?.stop(),this._unsubscribe?.(),this._unsubscribe=null,this._disposePast(),this._shell?.destroy?.(),document.removeEventListener(`keydown`,this._onKeyDown),this._avoid?.destroy(),this._avoid=null,this._autoOpen?.cancel(),this._autoOpen=null,this._motion?.destroy(),this._motion=null}attributeChangedCallback(e,t,n){if(this._built&&t!==n){if(e===`layout`)this._buildShell(this._assertLayout());else if(e===`position`)this._assertPosition();else if(e===`base`||e===`screen`||e===`narrow`)this._resetSession();else if(e===`motion`)this._motion?.destroy(),this._motion=null;else if(e===`open`&&this._session){let e=this._session.getState().open;this.open!==e&&this._setOpen(this.open,`manual`)}this._render()}}toggle(){this._session&&(this._session.getState().open?this._session.close(`button`):this._setOpen(!0,`manual`))}close(){this._voice?.stop(),this._session?.close(`button`)}newConversation(){this._voice?.stop(),this._session?.newConversation(),this._past?.refresh()}reset(){this._voice?.stop(),this._session?.reset()}_setOpen(e,t){this._session&&(e?(this._openTrigger=t,this._session.open({trigger:t})):this._session.close(`button`))}_assertLayout(){let e=this.layout;return Ti(e),e}_assertPosition(){Ei(this.position)}get _position(){let e=this.position;return Ei(e),e}_isLauncherLike(){return this.layout===`launcher`||this.layout===`docked`}requireSession(){if(!this._session)throw TypeError(`wui-chat: _session is not ready; the element is not connected`);return this._session}requireVoice(){if(!this._voice)throw TypeError(`wui-chat: _voice is not ready; the element is not connected`);return this._voice}requireMotion(){if(!this._motion)throw TypeError(`wui-chat: _motion is not ready; the element is not connected`);return this._motion}requirePastList(){if(!this._pastList)throw TypeError(`wui-chat: _pastList is not ready; the element is not connected`);return this._pastList}requireNudgeHost(){if(!this._shell.nudgeHost)throw TypeError(`wui-chat: the launcher shell has no nudge host`);return this._shell.nudgeHost}_build(){this._built=!0,this._header=On({onNew:()=>this.newConversation(),onHistory:()=>this._toggleHistory(),onClose:()=>this.close(),onMute:()=>{this._session&&this._session.setMuted(!this._session.getState().muted)},onSwitch:()=>this._switchPanel(),titleId:`${this._uid}-title`}),this._starters=br({onStarter:e=>this.requireSession().submit(e.message),onResume:()=>this.requireSession().resumeLast(),onTicket:e=>{typeof this.openTicket==`function`&&this.openTicket({ticketId:e.ticketId,number:e.number})}}),this._applyEmptyContent(),this._voice=hn({getState:()=>this.requireSession().getState(),getToken:()=>this.requireSession().client.getSpeechToken()}),this._voice.subscribe(()=>this._render()),this._thread=Qr({getRenderers:()=>this._renderers,getLayoutParts:()=>this._layoutParts,makeTurnApi:e=>this._makeTurnApi(e),onRetry:()=>this.requireSession().retry(),onRegenerate:()=>this.requireSession().regenerate(),onRate:(e,t)=>this.requireSession().rate(e,t),getSession:()=>this.requireSession(),getVoice:()=>this._voice}),this._composer=Cn({voice:this._voice,onSubmit:e=>this.requireSession().submit(e),onStop:()=>this.requireSession().stop(),onAttach:e=>this.requireSession().attach(e),onRemove:e=>this.requireSession().removeAttachment(e),onCancelEdit:()=>this.requireSession().cancelEdit(),onTyping:()=>this.requireSession().notifyTyping(),onDraftApplied:()=>this.requireSession().consumeDraft()}),this._footer=Dn(),this._history=An({getClient:()=>this.requireSession().client,getLabels:()=>this.labels,getFeatures:()=>this.requireSession().getState().features,onOpen:e=>{Promise.allSettled([this.requireSession().openConversation(e)]),this._toggleHistory(!1)},onDeleted:e=>{e===this.conversationId&&this.requireSession().newConversation()}}),this._nudge=In({onActivate:()=>this._setOpen(!0,`manual`),onDismiss:()=>{}}),this._status=t(`p`,null,{role:`status`}),this._status.hidden=!0,this._errorEl=t(`p`,`wui-chat-profile-error`,{role:`alert`}),this._errorEl.hidden=!0,this._liveStatus=t(`p`,`wui-chat-live-status`,{role:`status`}),this._liveStatus.hidden=!0,this._talk=t(`button`,`${s(`outline`,`sm`)} wui-chat-handoff-request`,{type:`button`}),this._talk.addEventListener(`click`,()=>this._requestHandoff()),this._liveRetry=t(`button`,s(`ghost`,`sm`),{type:`button`}),this._liveRetry.addEventListener(`click`,()=>this.requireSession().resumeLive()),this._liveError=t(`p`,`wui-chat-live-error`,{role:`alert`}),this._liveError.hidden=!0,this._live=t(`div`,`wui-chat-live`),this._live.append(this._liveStatus,this._talk,this._liveRetry,this._liveError),this._live.hidden=!0,this._body=t(`div`,`wui-chat-body`),this._body.append(this._starters.el,this._thread.el,this._live,this._history.el,this._status,this._errorEl),this._foot=t(`div`,`wui-chat-foot`),this._foot.append(...this._composer.nodes,this._footer.el)}_buildShell(e){let t={launcher:pr,docked:cr,"full-page":mr,embedded:lr};this._shell?.destroy?.(),this._avoid?.destroy(),this._avoid=null,this._autoOpen?.cancel(),this._autoOpen=null,this._lastOpen=!1,this._launcherPlayed=!1;let n=t[e]({id:`${this._uid}-panel`,position:this._position,onToggle:()=>this.toggle()});n.panel.append(this._header.el,this._body,this._foot),n.panel.setAttribute(`aria-labelledby`,`${this._uid}-title`),n.panel.addEventListener(`keydown`,e=>{e.key===`Tab`&&_(n.panel,e)}),n.nudgeHost&&n.nudgeHost.prepend(this._nudge.el),this._shell=n,this.replaceChildren(n.root)}_createSession(){let e=ee(Fn(),{base:this.base}),t=_i(this);this._session=te(e,{...this.screen?{screen:this.screen}:{},...t===void 0?{}:{narrow:t},pageContext:()=>this.pageContext,attribution:()=>this._attribution?.()??null,behaviour:()=>this._session?.getState().features.BehaviourStarters?this._behaviour?.()??null:null,prefs:yi,reducedMotion:()=>this._motion?.reduced??!1,schedule:xi,getCaptchaToken:e=>{if(this._captchaToken)return this._captchaToken(e);let t=this._session?.getState().profile?.captcha?.siteKey;return t?Un(t,e):Promise.resolve(null)},onEvent:(e,t)=>{this.dispatchEvent(new CustomEvent(`wui-chat-event`,{bubbles:!0,detail:{name:e,data:t}}))},onError:()=>{},labels:this.labels}),this._unsubscribe=null,this._lastOpen=!1,this._openApplied=!1,this._seeded=!1,this._wasLoading=!1,this._seen=/* @__PURE__ */ new Set,this._pastRefreshed=!1}_createPast(){this._pastList=A({client:this.requireSession().client,pageSize:20}),this._past=Rn({list:this._pastList,getLabels:()=>this.labels,getFeatures:()=>this.requireSession().getState().features,onOpen:e=>{Promise.allSettled([this.requireSession().openConversation(e)])}}),this._starters.pastHost.append(this._past.el)}_disposePast(){this._past&&(this._past.el.remove(),this._past.dispose(),this.requirePastList().dispose(),this._past=null,this._pastList=null)}_applyEmptyContent(){if(!this._starters)return;let e=this._starters.extraHost;e.replaceChildren(...this._emptyContentProp?[this._emptyContentProp]:[]),e.hidden=!this._emptyContentProp}_switchPanel(){let e=this.requireSession().getState(),t=this._onPanelSwitchProp,n=wi(this.layout,e.features,t);if(t===null||n===null)return;n===`full-page`&&this.close();let r={from:this.layout,to:n,conversationId:e.conversationId,draft:this._composer.getDraft()};S(()=>t.call(this,r),{target:n,reduced:this._motion?.reduced===!0}).then(()=>document.querySelector(`.wui-chat--${n} .wui-chat-input`)?.focus()).catch(e=>globalThis.reportError?.(e))}async _requestHandoff(){this._requesting=!0,this._liveError.hidden=!0,this._render();try{await this.requireSession().requestHandoff()}catch(e){let t=typeof e==`object`&&e&&`message`in e?e.message:void 0;this._liveError.textContent=typeof t==`string`&&t||this.labels.errorGeneric,this._liveError.hidden=!1}finally{this._requesting=!1,this._render()}}_paintLive(e,t,n){let r=e.live===`Lost`,i=Si(e);this._liveStatus.hidden=!r,this._liveStatus.textContent=r?t.liveLost:``,this._liveRetry.hidden=!r,this._liveRetry.textContent=t.retry,this._talk.hidden=!i,this._talk.textContent=t.talkToPerson,this._talk.disabled=this._requesting,this._live.hidden=n||!r&&!i}_resetSession(){this._voice?.stop(),this._unsubscribe?.(),this._unsubscribe=null,this._session?.dispose(),this._session=null,this._disposePast(),this._history.dispose(),this.isConnected&&(this._createSession(),this._createPast(),this._unsubscribe=this.requireSession().subscribe(()=>this._render()))}_toggleHistory(e=!this._historyShown){this._historyShown=e,e?this._history.show():this._history.hide(),this._render()}_makeTurnApi(e){let t=ne(this.requireSession(),{messageId:e,labels:this.labels,openAttachment:e=>this.openAttachment(e),openCitation:t=>this.openCitation(e,t),openTarget:e=>this.openTarget(e),openTicket:this.openTicket,onNavigate:this.onNavigate});return t.resolveLink=this.resolveLink,t}_defaultOpenAttachment(e){this.requireSession().client.getAttachment(e.attachmentId).then(t=>{let n=URL.createObjectURL(new Blob([t],{type:e.contentType}));window.open(n,`_blank`,`noopener`),setTimeout(()=>URL.revokeObjectURL(n),oi)}).catch(e=>globalThis.reportError?.(e))}_defaultOpenCitation(e,t){let n=this._thread.find(e);if(n){for(let e of n.querySelectorAll(`[data-marker]`))if(e.dataset.marker===String(t)){e.focus();return}}}_defaultOpenTarget(e){/^https?:\/\//i.test(e)?window.open(e,`_blank`,`noopener`):window.location.assign(e)}_render(){this._built&&this._session&&this._paint(this._session.getState())}_paint(e){e.conversationId!==this._voiceConversationId&&(this._voiceConversationId=e.conversationId,this.requireVoice().stop());let t=this.labels,n=e.profile,r=this._isLauncherLike();if(!n){this.hidden=r,this._header.el.hidden=!0,this._starters.el.hidden=!0,this._thread.el.hidden=!0,this._history.el.hidden=!0,this._foot.hidden=!0,this._errorEl.hidden=e.profileError==null,e.profileError&&(this._errorEl.textContent=e.profileError.message),this._status.hidden=e.profileError!=null,this._status.textContent=t.loadingConversation,this._shell.panel.setAttribute(`aria-busy`,String(e.profileError==null));return}if(this._shell.panel.removeAttribute(`aria-busy`),!e.features.VisitorChat){this.hidden=!0,this._status.hidden=!0;return}this.hidden=!1;let i=e.features,a=hi(this);this._ensureRuntime(e,n,a,t);let o=e.loading,s=e.loadError,c=e.messages.length===0&&!o,l=this._historyShown&&i.History===!0,u=e.messages.some(e=>e.author.kind===`Visitor`||e.author.kind===`Customer`),d=wi(this.layout,i,this._onPanelSwitchProp),f=e.streaming||e.thinking;this._header.paint({labels:t,title:n.assistant.name,tagline:n.assistant.tagline,status:Ci(e,t),canNew:!f,showNew:this.layout===`full-page`||u,showHistory:i.History,showClose:r||this.layout===`full-page`&&d!==null,switchTo:d,canSwitch:!f,viewingHistory:l,showMute:i.Sounds&&n.experience.sound.muteControl,muted:e.muted}),qn(this._header.conversation,e,{labels:t,features:i,title:n.assistant.name??t.panelTitle,getState:()=>this.requireSession().getState(),iconOnly:!0}),l&&(this._header.conversation.hidden=!0),this._starters.el.hidden=!c||l,c&&e.open&&!this._introPlayed&&a.panel.greetingLoaderMs>0&&!this.requireMotion().reduced&&(this._introPlayed=!0,this._starters.intro(a.panel.greetingLoaderMs)),c&&this._starters.paint({labels:t,greeting:e.greeting,intro:n.assistant.intro,starters:e.starters,showStarters:i.Starters&&!e.streaming,resume:!i.History&&i.ResumeLast?e.lastConversation:null,openTickets:e.openTickets,features:e.features,ticketsClickable:typeof this.openTicket==`function`}),i.History&&!this._pastRefreshed&&(this._pastRefreshed=!0,this._past?.refresh()),this._past?.paint();let p=!c&&!o&&!s&&!l;this._thread.el.hidden=!p,p&&this._thread.paint(e,{labels:t,loaderStyle:gi(this),reduced:this._motion?.reduced??!1,phrases:n.experience.pacing.thinkingPhrases,intervalMs:n.experience.pacing.phraseIntervalMs,assistantName:n.assistant.name}),this._paintLive(e,t,l),this._status.hidden=!o||l,this._status.textContent=t.loadingConversation,this._errorEl.hidden=!s||l,s&&(this._errorEl.textContent=s.message),this._foot.hidden=l,this._composer.paint({state:e,labels:t,maxLength:n.limits.maxMessageLength,accept:n.limits.contentTypes.join(`,`),draft:e.draft??null,sendIcon:a.input.sendIcon}),this._footer.paint({labels:t,profile:n}),this._history.el.hidden=!l,this._syncOpen(e,n,i,t,r),this._syncConversation(e),this._playSounds(e)}_ensureRuntime(e,t,n,r){let i=e.features;this._motion||(this._motion=a(n,t.experience),this._motion.subscribe(()=>this._render())),i.Sounds&&!this._sound&&(this._sound=l(t.experience.sound,yi)),!i.Sounds&&this._sound&&(this._sound=null),i.BehaviourStarters&&!this._behaviour&&(this._behaviour=f(t.start.behaviour?.servicePathPrefixes??[]));let o=this._isLauncherLike();o&&!this._avoid&&this.layout===`launcher`&&(this._avoid=p(n.avoid,t.experience.launcher,this.requireNudgeHost())),this.layout===`launcher`&&i.AutoOpen&&!this._autoOpen&&(this._autoOpen=x(t.experience.autoOpen,n,{open:()=>this._setOpen(!0,`auto`),isOpen:()=>this.requireSession().getState().open,panelRect:()=>this._shell.panel.getBoundingClientRect()}));let s=bi(n);this._shell.setLabels(r),this._shell.setAppearance({position:this._position,offsetX:this.hasAttribute(`offset-x`)?Z(`offset-x`)(this.getAttribute(`offset-x`)??``):void 0,offsetY:this.hasAttribute(`offset-y`)?Z(`offset-y`)(this.getAttribute(`offset-y`)??``):void 0,width:`${n.panel.widthPx}px`,maxHeight:n.panel.maxHeightPx,bottomGap:n.panel.bottomGapPx,reduced:this._motion.reduced,sendReveal:n.input.sendReveal,inputRing:n.input.ring,panelMotion:n.panel.motion,theme:ii(this.getAttribute(`theme`)),icon:this.icon,launcherStyle:n.launcher.style,compact:n.launcher.compact,labelReveal:n.launcher.labelReveal,entrance:n.launcher.entrance,idle:n.launcher.idle,launcherMark:n.launcher.mark,panelHeight:n.panel.height,replyAvatars:n.panel.replyAvatars,avatar:n.avatar,expressive:n.expressive,phone:s,hoverLabel:t.experience.launcher.hoverLabel,peek:t.experience.launcher.peek,peekSeconds:t.experience.launcher.peekSeconds,hideWhileOpen:t.experience.launcher.hideWhileOpen,phoneMode:n.phone.mode,sheetHeightDvh:n.phone.sheetHeightDvh,sheetMaxHeightPx:n.phone.sheetMaxHeightPx,launcherState:this._launcherPlayed?void 0:`entering`}),this._launcherPlayed=!0,this._shell.root.classList.toggle(`wui-chat--phone`,o&&bi(n))}_syncOpen(e,t,n,r,i){if(i){if(!this._openApplied&&(this._openApplied=!0,this.hasAttribute(`open`)&&!e.open))this._setOpen(!0,`manual`);else if(this._shell.setOpen(e.open),this.toggleAttribute(`open`,e.open),e.open!==this._lastOpen&&(this._lastOpen=e.open,this._onOpenChange(e.open)),e.open)this._nudge.cancel(),this._nudgeArmed=!1,this._autoOpen?.cancel();else if(n.Nudges&&this.layout===`launcher`&&!this._nudgeArmed){let e=pe(t,n);e&&(this._nudge.schedule({text:e.text,delaySeconds:e.delaySeconds,label:r.nudgeDismiss}),this._nudgeArmed=!0)}}}_onOpenChange(e){let t=bi(hi(this));if(e){if(document.addEventListener(`keydown`,this._onKeyDown),this._sound?.play(`open`),this._past?.refresh(),this.layout===`docked`&&!this._preloaded&&typeof this._preloadPanelSwitchProp==`function`){this._preloaded=!0;let e=this._preloadPanelSwitchProp;Promise.allSettled([new Promise(t=>t(e.call(this)))]).then(e=>{for(let t of e)t.status===`rejected`&&globalThis.reportError?.(t.reason)})}if(t){let e=hi(this);this._phone={fit:y(this._shell.panel,e),unlock:b(this._thread.el)}}else this._openTrigger===`manual`&&(this._focusTimer=setTimeout(()=>{this._focusTimer=null,this._composer.focus()},si))}else document.removeEventListener(`keydown`,this._onKeyDown),clearTimeout(this._focusTimer??void 0),this._focusTimer=null,this._phone?.fit.destroy(),this._phone?.unlock(),this._phone=null,this._historyShown&&(this._historyShown=!1,this._history.hide(),this._render()),d(this._shell.launcherButton)}_syncConversation(e){let t=this.getAttribute(`conversation-id`);t&&t!==this._openedConversation&&!e.loading&&(this._openedConversation=t,e.conversationId!==t&&Promise.allSettled([this.requireSession().openConversation(t)]))}_playSounds(e){if(e.loading){this._wasLoading=!0;for(let t of e.messages)this._seen.add(t.id)}else if(this._wasLoading||!this._seeded){this._wasLoading=!1,this._seeded=!0;for(let t of e.messages)this._seen.add(t.id)}else for(let t of e.messages)this._seen.has(t.id)||(this._seen.add(t.id),this._announce(t))}_announce(e){if(!this._sound||e.restored||e.parts.some(e=>e.kind===`Notice`))return;let t=e.author.kind;if(t===`Visitor`)e.stored||this._sound.play(`sent`);else if(t===`Assistant`||t===`Script`||t===`Agent`){this._sound.play(`reply`);let e=this.requireSession().getState().profile;e?.experience.sound.vibrate&&C(e.experience.sound.vibrateMs,this._sound.isMuted())}}};Object.defineProperty(Ai.prototype,"layout",{get(){return this.getAttribute(`layout`)??fi.layout},set(e){this.setAttribute(`layout`,String(e))}});for(let e of pi)e!==`layout`&&Object.defineProperty(Ai.prototype,mi(e),{configurable:!0,get(){return this.getAttribute(e)??fi[e]??``},set(t){t==null?this.removeAttribute(e):this.setAttribute(e,String(t))}});function ji(){typeof customElements<`u`&&!customElements.get(`wui-chat`)&&customElements.define(`wui-chat`,Ai)}ji();export{Ai as WuiChat,Fn as createFetchChatHttp,cn as defaultRenderers,ji as defineChat};
|