@webority/chat-elements 0.134.0 → 0.135.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.css +1 -1
- package/dist/chat.global.js +13 -13
- package/dist/types/web/index.d.ts +1 -1
- package/dist/types/web/motion.d.ts +1 -0
- package/dist/web-Dkz2jgyc.js +1 -0
- package/dist/web.js +1 -1
- package/package.json +8 -8
- package/dist/web-Ezt3Vwhd.js +0 -1
package/dist/chat-elements.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as e,C as t,D as n,E as r,M as i,O as a,S as o,T as s,a as c,b as l,c as u,f as d,g as f,h as p,j as m,k as h,l as g,m as _,n as v,o as y,p as b,r as x,s as S,u as C,v as w,x as T,y as E}from"./web-Ezt3Vwhd.js";import{CHAT_HANDOFF_REQUEST_ID as D,buildTranscript as O,createChatClient as ee,createChatSession as te,createConversationList as k,createTurnApi as ne,formatChatDate as A,formatChatValue as re,formatClipTime as ie,formatFigure as ae,formatFileSize as oe,isHandoffTarget as se,loaderView as ce,mergeLabels as j,mergeLook as le,messagePlainText as M,resolveNudge as ue,showsCaptchaNote as de,sniffAudioType as fe,toFigureRuns as N,toFigureText as pe,transcriptToText as me,voiceClipBars as he}from"@webority/chat-core";import{linkTarget as ge,parseInline as _e}from"@webority/markdown-core";import{COPY_FEEDBACK_MS as ve,EMPTY_VALUE as ye,copyTextToClipboard as be,formatNumber as xe,glyphSvg as Se}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 Ce=typeof HTMLElement>`u`?class{}:HTMLElement,P=class extends Ce{#e=null;#t=null;#n=null;#r=!1;get part(){return this.#e}set part(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()}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(){throw Error(`${this.localName} must override renderPart`)}disposePart(){}};function F(e,t){typeof customElements>`u`||customElements.get(e)||customElements.define(e,t)}function I(e,t,n=null,r=null){let i=e.createElement(t);return n&&(i.className=n),r!==null&&(i.textContent=r),i}function we(e,t,n){let r=Se(t,{size:n});if(!r)return null;let i=new DOMParser().parseFromString(r,`text/html`);return e.importNode(i.body.firstElementChild,!0)}var Te={Confirmed:`actionConfirmed`,Rejected:`actionRejected`,Expired:`actionExpired`,Failed:`actionFailed`},Ee=/^https?:\/\//i,De={strong:`strong`,em:`em`,strike:`s`};function L(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r}function Oe(e,t){return{id:e,label:t,action:`Send`,target:null,navigateAfterMs:null,icon:null,variant:null}}function R(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(Ee.test(n.href)){let t=L(`a`);t.href=n.href,t.target=`_blank`,t.rel=`noopener noreferrer`,R(t,n.children),e.append(t)}else R(e,n.children)}else if(n.type in De){let t=L(De[n.type]);R(t,n.children),e.append(t)}else n.type===`code`&&e.append(L(`code`,null,n.text))}function ke(e){let t=L(`p`,`wui-chat-action-consent`);return R(t,_e(e)),t}function Ae(e){let t=L(`ul`,`wui-chat-action-lines`);for(let n of e)t.append(L(`li`,null,n));return t}function je(e){let t=L(`dl`,`wui-chat-action-lines`);for(let n of e){let e=L(`div`,`wui-chat-action-line`),r=n.indexOf(`: `);r===-1?e.append(L(`dt`,null,n)):e.append(L(`dt`,null,n.slice(0,r)),L(`dd`,null,n.slice(r+2))),t.append(e)}return t}F(`wui-chat-part-action`,class extends P{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){this.replaceChildren(this._view()),e===`first`?this.querySelector(`[role="menuitem"]`)?.focus():e===`edit`&&this.querySelector(`.wui-chat-action-edit`)?.focus()}async _run(e){let t=this._part.actionId;this._working=e,this._error=null,this._paint();try{e===`confirm`?await this._turn.confirmAction(t):await this._turn.rejectAction(t),this._working=null}catch(e){if(this._part.actionId!==t)return;this._working=null,this._error=e?.message||this._turn.labels.actionFailed,this._paint()}}_view(){let{part:e,turn:t}=this,n=t.labels,r=e.state===`Pending`,i=t.features.LeadRecap&&e.actionKind===`ChatLeadCapture`,a=i&&e.editFields?.length>0,o=L(`div`,`wui-chat-action wui-chat-action--${e.state.toLowerCase()}`);if(o.append(L(`strong`,`wui-chat-action-title`,e.title)),e.lines.length>0&&o.append(i?je(e.lines):Ae(e.lines)),i&&e.consentText&&o.append(ke(e.consentText)),e.note&&o.append(L(`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)),a&&this._menuOpen&&o.append(this._menu(e.editFields,n)),this._error){let e=L(`p`,`wui-chat-action-error`,this._error);e.setAttribute(`role`,`alert`),o.append(e)}return o}_status(e,t){let n=L(`p`,`wui-chat-action-status wui-chat-action-status--${e.state.toLowerCase()}`);if(e.state===`Repeat`)n.textContent=e.decidedDateTimeUtc?t.actionRepeat(A(e.decidedDateTimeUtc)):t.actionDone;else if(e.state===`Done`){if(n.append(t.actionDone),e.decidedDateTimeUtc){let t=L(`time`,null,A(e.decidedDateTimeUtc));t.dateTime=e.decidedDateTimeUtc,n.append(` `,t)}}else n.textContent=t[Te[e.state]]??``;return n}_buttons(e,t,n,r,i){let a=L(`div`,`wui-chat-action-buttons`),o=this._working;if(r){let r=n&&e.confirmLabel||t.actionConfirm,i=n&&e.rejectLabel||t.actionDismiss,s=L(`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=L(`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=L(`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){let n=L(`ul`,`list-group wui-chat-action-menu`);n.setAttribute(`role`,`menu`),n.setAttribute(`aria-label`,t.editSomething),n.addEventListener(`keydown`,e=>this._onMenuKey(e));for(let t of e){let e=L(`li`);e.setAttribute(`role`,`none`);let r=L(`button`,`list-group-item list-group-item-action wui-chat-action-menu-item`,t.label);r.type=`button`,r.setAttribute(`role`,`menuitem`),r.addEventListener(`click`,()=>{this._menuOpen=!1,this._turn.chooseQuickReply(Oe(`lead.edit:${t.id}`,t.label)),this._paint(`edit`)}),e.append(r),n.append(e)}return n}_onMenuKey(e){if(e.key===`Escape`){e.preventDefault(),this._menuOpen=!1,this._paint(`edit`);return}let t=[...e.currentTarget.querySelectorAll(`[role="menuitem"]`)],n=t.indexOf(document.activeElement),r=t.length-1,i={ArrowDown:n<r?n+1:0,ArrowUp:n>0?n-1:r,Home:0,End:r};e.key in i&&(e.preventDefault(),t[i[e.key]].focus())}});var Me=null;async function Ne(){await import(`@webority/ui-elements/chart`),await customElements.whenDefined(`wui-chart`)}async function Pe(){return Me??=Ne().catch(e=>{throw Me=null,e}),Me}var Fe={sub:`wui-chat-sub`,sup:`wui-chat-sup`};function z(e,t){let n=e.ownerDocument;for(let r of t){if(Fe[r.kind]===void 0){e.append(n.createTextNode(r.text));continue}let t=n.createElement(r.kind);t.className=Fe[r.kind],t.textContent=r.text,e.append(t)}}function B(e,t){e.replaceChildren(),z(e,N(String(t??``)))}function V(e){return pe(String(e??``))}function Ie(e){return ae(e)}var Le=8,Re={Bar:`column`,Line:`line`,Donut:`donut`};function ze(e,t){return e===`Bar`&&t>4?300:240}function Be(e,t){let n=e.chartType===`Donut`,r=n?e.series.slice(0,1):e.series.slice(0,Le),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);o.has(e)||o.set(e,{label:V(e),...a}),o.get(e)[`s${t}`]=n.value}});let s=[...o.values()],c={type:Re[e.chartType],title:V(e.title)||t.chart,x:{key:`label`,kind:`category`},series:i,data:s,height:ze(e.chartType,s.length)};return!n&&e.unit&&(c.y={label:V(e.unit)}),s.length===0&&(c.state=`empty`,c.emptyText=t.chartEmpty),c}F(`wui-chat-part-chart`,class extends P{#e=null;#t=0;#n=!1;#r=null;#i=null;#a=null;#o=null;#s=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;if(this.#r||(this.#r=I(a,`figure`,`wui-chat-chart`),this.#a=I(a,`div`,`wui-chat-chart-body`),this.#r.append(this.#a),this.replaceChildren(this.#r)),this.#i?.remove(),this.#i=null,e.title&&(this.#i=I(a,`figcaption`,`wui-chat-chart-title`),B(this.#i,e.title),this.#r.prepend(this.#i)),this.#n){let t=Be(e,n.labels);this.#o.spec=t,this.#c(t.state!==`empty`,n.labels)}else Pe().then(()=>{if(i!==this.#t||!this.isConnected)return;let t=Be(e,n.labels);this.#o=a.createElement(`wui-chart`),this.#o.spec=t,this.#n=!0,this.#a.replaceChildren(this.#o),this.#c(t.state!==`empty`,n.labels)},()=>{i===this.#t&&this.isConnected&&this.#u(n.labels)})}disposePart(){this.#t+=1,this.#e=null}#c(e,t){if(!e){this.#s?.remove(),this.#s=null;return}this.#s||(this.#s=I(this.ownerDocument,`button`,`btn btn-link btn-sm wui-chat-chart-toggle`),this.#s.type=`button`,this.#s.addEventListener(`click`,()=>this.#l()),this.#r.append(this.#s));let n=this.#o.getAttribute(`view`)===`table`;this.#s.setAttribute(`aria-pressed`,String(n)),this.#s.textContent=n?t.chartShowChart:t.chartShowTable}#l(){let e=this.#o.getAttribute(`view`)!==`table`;this.#o.setAttribute(`view`,e?`table`:`chart`),this.#c(!0,this.turn.labels)}#u(e){let t=I(this.ownerDocument,`p`,`wui-chat-chart-error`,e.chartLoadFailed);t.setAttribute(`role`,`status`),this.#a.replaceChildren(t),this.#s?.remove(),this.#s=null}});var Ve={Positive:`wui-metric-tone-success`,Caution:`wui-metric-tone-warning`,Negative:`wui-metric-tone-danger`},He=/* @__PURE__ */ new Set([`Positive`,`Caution`,`Negative`]),Ue=.001;function We(e,t,n){let r=Ve[t.status],i=I(e,`div`,r?`wui-metric ${r}`:`wui-metric`);i.dataset.status=t.status;let a=I(e,`div`,`wui-metric-label`);B(a,t.label);let o=I(e,`div`,`wui-metric-value`);if(z(o,t.value!==0&&Math.abs(t.value)<Ue?Ie(t.value):[{kind:`text`,text:xe(t.value)}]),t.unit){let n=I(e,`span`,`wui-chat-figure-unit`);B(n,t.unit),n.prepend(` `),o.append(n)}return He.has(t.status)&&o.append(I(e,`span`,`visually-hidden`,n.figureStatus(t.status))),i.append(a,o),i}F(`wui-chat-part-figures`,class extends P{#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,a=I(i,`div`,`wui-chat-figures`),o=I(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(We(i,t,n.labels));a.append(o),this.replaceChildren(a)}}),F(`wui-chat-part-file`,class extends P{renderPart(e,t,n){let r=typeof n.openAttachment==`function`,i=document.createElement(r?`button`:`span`);i.className=`wui-chat-file-chip`,r&&(i.type=`button`,i.setAttribute(`aria-label`,n.labels.fileOpen(e.fileName)),i.addEventListener(`click`,()=>n.openAttachment(e)));let a=we(document,`document-text`,16),o=document.createElement(`span`);o.className=`wui-chat-file-name`,o.textContent=e.fileName;let s=document.createElement(`span`);s.className=`wui-chat-file-size`,s.textContent=oe(e.length),i.append(...[a,o,s].filter(Boolean));let c=document.createElement(`div`);c.className=`wui-chat-file`,c.append(i),this.replaceChildren(c)}});var Ge={Open:`info`,InProgress:`info`,WaitingOnCustomer:`warning`,Resolved:`success`,Closed:`neutral`,Cancelled:`neutral`},Ke=/^\/[/\\]/,qe=/^https?:\/\//i,Je=/[\t\r\n]/g;function Ye(e){return typeof e==`string`&&e.trim()!==``}function Xe(e){return e.replace(Je,``)}function Ze(e){if(typeof e!=`string`)return!1;let t=Xe(e);return t.startsWith(`/`)?!Ke.test(t):qe.test(t)}function Qe(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 $e(e,t){let n=Qe(Ye(e?.displayName)?e.displayName:t),r=a(`span`,`wui-chat-avatar`,{"aria-hidden":`true`}),i=typeof e?.avatarUrl==`string`?Xe(e.avatarUrl):null;if(Ze(i)){let e=a(`img`,null,{alt:``,src:i,loading:`lazy`});e.addEventListener(`error`,()=>{r.textContent=n}),r.append(e)}else r.textContent=n;return r}function et(e,t){let n=a(`div`,`wui-chat-agent-head`),r=a(`span`,`wui-chat-agent-name`);r.textContent=Ye(e?.displayName)?e.displayName:t.agent;let i=a(`span`,`wui-chat-agent-role wui-chat-agent-tag`);return i.textContent=t.agent,n.append($e(e,t.agent),r,i),n}function tt(e,t){let n=e.displayName,r=a(`li`,`wui-chat-message wui-chat-message--agent wui-chat-message--typing`),i=a(`span`,`wui-chat-typing`);for(let e=0;e<3;e+=1)i.append(a(`span`,`wui-chat-typing-dot`,{"aria-hidden":`true`}));let o=a(`span`,`visually-hidden`);return o.textContent=t.agentTyping(Ye(n)?n:t.agent),r.append(et({kind:`Agent`,displayName:n,avatarUrl:null},t),i,o),r}function nt(e){return Object.hasOwn(Ge,e)?Ge[e]:null}function rt(e,t){return nt(e)===null?``:t.ticketStatus(e)}var it=/* @__PURE__ */ new Set([`Requested`,`Waiting`]),at=/* @__PURE__ */ new Set([`Requested`,`Waiting`,`Joined`]),ot=at;function st(e,t){let n=e?.displayName;return typeof n==`string`&&n.trim()!==``?n:t.handoffAgentFallback}function ct(){let e=a(`div`,`wui-chat-handoff-pulses`);for(let t=0;t<3;t+=1)e.append(a(`span`,`wui-chat-handoff-pulse`,{"aria-hidden":`true`}));return e}function H(e,t,n){let r=a(e,t);return r.textContent=n,r}function U(e,t){let n=a(`div`,`wui-chat-handoff-body`);return n.append(H(`strong`,`wui-chat-handoff-title`,e),H(`p`,`wui-chat-handoff-text`,t)),n}function lt(e,t){if(typeof e.queuePosition!=`number`){let e=a(`span`,`wui-chat-system-line-stack`);return e.append(H(`p`,`wui-chat-handoff-text`,t.handoffWaiting),H(`p`,`wui-chat-handoff-text`,t.handoffQueuedText)),[ct(),e]}let n=a(`span`,`wui-chat-handoff-position`,{"aria-hidden":`true`});return n.textContent=String(e.queuePosition),[n,U(t.handoffQueued(e.queuePosition),t.handoffQueuedText)]}function ut(e,t){let n=st(e.agent,t),r=a(`span`,`wui-chat-handoff-agent`);return r.append($e(e.agent,t.handoffAgentFallback),a(`span`,`wui-chat-handoff-online`,{"aria-hidden":`true`})),[r,U(t.handoffJoined(n),t.handoffJoinedText(n))]}function dt(e,t){switch(e.state){case`Requested`:return[ct(),H(`p`,`wui-chat-handoff-text`,t.handoffRequested)];case`Waiting`:return lt(e,t);case`Joined`:return ut(e,t);case`Left`:return[U(t.handoffLeft(st(e.agent,t)),t.handoffLeftText)];case`Ended`:return[U(t.handoffEnded,t.handoffEndedText)];default:return null}}F(`wui-chat-part-handoff`,class extends P{constructor(){super(),this._signature=null}renderPart(e,t,n){let r=n.isLast,i=n.handoffSettled===!0&&it.has(e.state),o=JSON.stringify([e.state,e.queuePosition,e.agent,r,n.features.HumanHandoff,n.busy,i]);if(o===this._signature)return;if(this._signature=o,i){this.replaceChildren();return}let s=dt(e,n.labels);if(s===null){this.replaceChildren();return}let c=a(`div`,`wui-chat-handoff wui-chat-handoff--${e.state.toLowerCase()}`);if(r&&it.has(e.state)&&c.classList.add(`wui-chat-handoff--live`),r&&at.has(e.state)&&c.setAttribute(`role`,`status`),ot.has(e.state)){c.classList.add(`wui-chat-system-line`);let e=a(`span`,`wui-chat-system-line-content`);e.append(...s),c.append(e)}else c.append(...s);this.replaceChildren(c)}}),F(`wui-chat-part-image`,class extends P{#e=null;#t=0;#n=null;renderPart(e,t,n){if(e.attachmentId===this.#e)return;this.#e=e.attachmentId;let r=this.ownerDocument,i=I(r,`figure`,`wui-chat-image`);this.#n=I(r,`div`,`wui-chat-image-frame`),Number.isFinite(e.width)&&Number.isFinite(e.height)&&e.width>0&&e.height>0&&(this.#n.style.aspectRatio=`${e.width} / ${e.height}`),i.append(this.#n),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,i=I(r,`div`,`wui-chat-image-skeleton`);i.setAttribute(`aria-hidden`,`true`);let a=I(r,`span`,`visually-hidden`,t.labels.imageLoading);a.setAttribute(`role`,`status`),this.#n.replaceChildren(i,a),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.ownerDocument,i=V(t.alt),a=r.createElement(`wui-lightbox`);a.setAttribute(`label`,n.labels.imageViewer);let o=I(r,`a`,`wui-lightbox-item`);o.setAttribute(`href`,e),o.dataset.caption=i,o.dataset.name=i;let s=r.createElement(`img`);s.src=e,s.alt=i,s.decoding=`async`,o.append(s),a.append(o),this.#n.replaceChildren(a)}#a(e,t){let n=this.ownerDocument,r=I(n,`p`,`wui-chat-image-error`,t.labels.imageFailed);r.setAttribute(`role`,`status`);let i=I(n,`button`,`btn btn-soft-primary btn-sm`,t.labels.retry);i.type=`button`,i.addEventListener(`click`,()=>this.#r(e,t)),this.#n.replaceChildren(r,i)}});var ft={ActionLimitReached:`warning`,ConversationTooLong:`warning`,AssistantUnavailable:`danger`},pt={info:`info`,warning:`alert-triangle`,danger:`alert-circle`};F(`wui-chat-part-notice`,class extends P{renderPart(e){let t=this.ownerDocument,n=ft[e.code]??`info`,r=I(t,`div`,`wui-chat-notice wui-chat-notice--${n}`);r.setAttribute(`role`,n===`danger`?`alert`:`status`);let i=I(t,`span`,`wui-chat-notice-icon`);i.setAttribute(`aria-hidden`,`true`);let a=we(t,pt[n],16);a&&i.append(a);let o=I(t,`div`,`wui-chat-notice-body`);if(o.append(I(t,`span`,`wui-chat-notice-text`,e.text)),e.action){let n=I(t,`button`,`wui-chat-notice-action`,e.action.label);n.type=`button`,n.addEventListener(`click`,()=>e.action.run()),o.append(n)}r.append(i,o),this.replaceChildren(r)}});var mt=/* @__PURE__ */ new Set([`Email`,`Phone`,`Name`,`Company`,`Text`,`LongText`,`Choice`,`MultiChoice`,`TimeSlot`,`File`,`Consent`]),ht={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}},gt=[`Open`,`Answered`,`Skipped`,`Expired`],_t=0;function W(e){return _t+=1,`${e}-${_t}`}function G(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r}function K(){let e=G(`p`,`wui-chat-field-error`);return e.id=W(`wui-chat-field-error`),e.setAttribute(`role`,`alert`),e.hidden=!0,e}function q(e,t){return e.required?[]:[G(`span`,`wui-chat-field-hint`,t.inputOptional)]}function vt(e,t){let n=W(`wui-chat-field`),r=ht[e.type],i=e.type===`LongText`&&!e.secret,a=G(i?`textarea`:`input`,`form-control wui-chat-input-control`);i?a.rows=3:(a.type=e.secret?`password`:r.type,e.secret?a.autocomplete=`off`:r.autocomplete&&(a.autocomplete=r.autocomplete)),a.id=n,a.name=e.key,e.placeholder!=null&&(a.placeholder=e.placeholder),e.maxLength!=null&&(a.maxLength=e.maxLength),e.required&&a.setAttribute(`aria-required`,`true`);let o=G(`label`,`form-label`,e.label);o.htmlFor=n;let s=K();a.setAttribute(`aria-describedby`,s.id);let c=G(`div`,`wui-chat-field`);return c.dataset.key=e.key,c.append(o,...q(e,t),a,s),{field:e,element:c,controls:[a],focus:a,invalid:a,error:s,read:()=>e.secret?a.value:a.value.trim()}}function yt(e,t,n,r,i){let a=e.controls[0],o=G(`button`,`btn btn-soft-primary`,n.inputSendCode);o.type=`button`,o.dataset.wui=`AppButton`;let s=G(`p`,`wui-chat-field-hint`);s.setAttribute(`aria-live`,`polite`);let c=W(`wui-chat-field`),l=G(`label`,`form-label`,n.inputEnterCode);l.htmlFor=c,l.hidden=!0;let u=G(`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 bt(e,t){let n=W(`wui-chat-field-label`),r=G(`span`,`form-label`,e.label);r.id=n;let i=G(`div`);i.setAttribute(`role`,`radiogroup`),i.setAttribute(`aria-labelledby`,n);let a=K();i.setAttribute(`aria-describedby`,a.id);let o=[];for(let t of e.options??[]){let n=G(`div`,`form-check`),r=G(`input`,`form-check-input`);r.type=`radio`,r.name=e.key,r.value=t.id,r.id=W(`wui-chat-option`);let a=G(`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=G(`div`,`wui-chat-field`);return s.dataset.key=e.key,s.append(r,...q(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 xt(e,t){let n=W(`wui-chat-field-label`),r=G(`span`,`form-label`,e.label);r.id=n;let i=G(`div`,`wui-chat-input-choices`);i.setAttribute(`role`,`group`),i.setAttribute(`aria-labelledby`,n);let a=K();i.setAttribute(`aria-describedby`,a.id);let o=[];for(let t of e.options??[]){let n=G(`div`,`form-check`),r=G(`input`,`form-check-input`);r.type=`checkbox`,r.name=e.key,r.value=t.id,r.id=W(`wui-chat-option`);let a=G(`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=G(`div`,`wui-chat-field`);return s.dataset.key=e.key,s.append(r,...q(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 St(e,t){let n=W(`wui-chat-field-label`),r=G(`span`,`form-label`,e.label);r.id=n;let i=G(`div`,`wui-chat-input-slots`);i.setAttribute(`role`,`radiogroup`),i.setAttribute(`aria-labelledby`,n);let a=K();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=G(`input`,`wui-chat-input-slot-radio`);n.type=`radio`,n.name=e.key,n.value=t.id,n.id=W(`wui-chat-slot`);let r=G(`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=G(`div`,`wui-chat-field`);return c.dataset.key=e.key,c.append(r,...q(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 Ct(e,t,n){let r=W(`wui-chat-field-label`),i=G(`span`,`form-label`,e.label);i.id=r;let a=K(),o=G(`input`);o.type=`file`,o.name=e.key,o.id=W(`wui-chat-field`),o.hidden=!0,e.accept?.length&&(o.accept=e.accept.join(`,`));let s=G(`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=G(`span`,`wui-chat-input-file-status`);c.setAttribute(`aria-live`,`polite`);let l=G(`button`,`btn btn-link`);l.type=`button`,l.hidden=!0;let u=G(`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 _=G(`div`,`wui-chat-field`);return _.dataset.key=e.key,_.append(i,...q(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 wt(e){let t=G(`input`,`form-check-input`);t.type=`checkbox`,t.name=e.key,t.id=W(`wui-chat-field`);let n=G(`label`,`form-check-label`,e.consentText||e.label);n.htmlFor=t.id;let r=K();t.setAttribute(`aria-describedby`,r.id);let i=G(`div`,`form-check`);i.append(t,n);let a=G(`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 Tt(e,t,n,r){if(e.type===`Choice`)return bt(e,t);if(e.type===`MultiChoice`)return xt(e,t);if(e.type===`TimeSlot`)return St(e,t);if(e.type===`File`)return Ct(e,t,n);if(e.type===`Consent`)return wt(e);let i=vt(e,t);return e.verify===`Otp`?yt(i,e,t,n,r):i}function Et(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 Dt(e,t){return e.state===`Answered`?G(`p`,`wui-chat-input-summary`,e.answeredSummary||t.inputAnswered):G(`p`,`wui-chat-input-summary`,e.state===`Skipped`?t.inputSkipped:t.inputExpired)}function Ot(e){return{kind:`Notice`,code:`NeedsNewerApp`,text:e.needsNewerApp}}F(`wui-chat-part-input-request`,class extends P{constructor(){super(),this._signature=null,this._turn=null,this._notice=null,this._generation=0}renderPart(e,t,n){this._turn=n;for(let t of gt)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._notice&&(this._notice.message=t,this._notice.turn=n,this._notice.part=Ot(n.labels)):(this._signature=r,this._generation+=1,this._notice=null,this.replaceChildren(this._content(e,t,n)))}_content(e,t,n){if(e.state!==`Open`)return Dt(e,n.labels);if(e.fields.some(e=>!mt.has(e.type))){let e=document.createElement(`wui-chat-part-notice`);return e.message=t,e.turn=n,e.part=Ot(n.labels),this._notice=e,e}return this._form(e,this._generation)}_form(e,t){let n=this._turn.labels,r=this._turn.features,i=G(`form`,`wui-chat-input-form`);i.noValidate=!0,i.setAttribute(`aria-label`,e.title||e.submitLabel),e.title&&i.append(G(`h3`,`wui-chat-input-title`,e.title));let a=e.fields.map(t=>Tt(t,n,this._turn,e.requestId));for(let e of a)i.append(e.element);let o=G(`p`,`wui-chat-input-error`);o.setAttribute(`role`,`status`),o.hidden=!0,i.append(o);let s=G(`button`,`btn btn-primary`,e.submitLabel);s.type=`submit`,s.dataset.wui=`AppButton`;let c=G(`div`,`d-flex flex-wrap gap-2`);c.append(s);let l=[s];if(r.LeadShortcuts&&e.fields.length===1&&!e.fields[0].required){let t=G(`button`,`btn btn-soft-primary`,n.skip);t.type=`button`,t.dataset.wui=`AppButton`,t.addEventListener(`click`,()=>this._turn.skipInput(e.requestId)),c.append(t),l.push(t)}if(r.LeadShortcuts&&e.cancellable){let e=G(`button`,`btn btn-link`,n.cancel);e.type=`button`,e.addEventListener(`click`,()=>this._turn.cancelLead()),c.append(e),l.push(e)}i.append(c),e.allowTyped&&i.append(G(`p`,`wui-chat-input-typed`,n.typeAnswer));let u=!1,d=t=>{for(let e of a)for(let n of e.controls)n.disabled=t;for(let e of l)e.disabled=t;s.textContent=t?n.inputSubmitting:e.submitLabel},f=()=>{for(let e of a)e.error.hidden=!0,e.error.textContent=``,e.invalid.removeAttribute(`aria-invalid`);o.hidden=!0,o.textContent=``},p=(e,t)=>{e.error.textContent=t,e.error.hidden=!1,e.invalid.setAttribute(`aria-invalid`,`true`)};return i.addEventListener(`submit`,async r=>{if(r.preventDefault(),u)return;f();let i={},c={},l=[];for(let e of a){let t=e.read();i[e.field.key]=t,e.codeRead&&(c[e.field.key]=e.codeRead());let r=Et(e,t,n);r&&l.push([e,r])}if(l.length>0){for(let[e,t]of l)p(e,t);l[0][0].focus.focus();return}u=!0,d(!0);let m;try{m=await this._turn.answerInput(e.requestId,i,Object.keys(c).length>0?c:null)}catch{m={ok:!1,errors:{},message:n.errorGeneric}}if(t!==this._generation||m.ok)return;u=!1;let h=null;for(let e of a){let t=m.errors?.[e.field.key];t&&(p(e,t),h??=e)}m.message!=null&&(o.textContent=m.message,o.hidden=!1),d(!1),h?h.focus.focus():a[0]?a[0].focus.focus():s.focus()}),i}});var kt={Primary:`wui-chat-quick-reply--primary`,Cta:`wui-chat-quick-reply--cta`};F(`wui-chat-part-quick-replies`,class extends P{#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||(this.#e=s,this.replaceChildren(),!r))return;let c=this.ownerDocument,l=e.placement===`Composer`,u=I(c,`div`,l?`wui-chat-quick-replies wui-chat-quick-replies--composer`:`wui-chat-quick-replies`);u.setAttribute(`role`,`group`),u.setAttribute(`aria-label`,n.labels.quickReplies);let d=l?null:e.replies.find(e=>e.id===D&&e.action===`Send`),f=0;d&&(u.classList.add(`wui-chat-quick-replies--offer`),u.append(this.#t(c,d,n)),f+=1);for(let t of e.replies){if(t===d||t.action===`Open`&&(!t.target||!i))continue;let e=null;if(t.action===`Navigate`){if(n.features.LinkHandoff!==!0)continue;if(se(t.target,n.handoffHosts))e=t.target;else{let r=n.resolveLink?.(t.target);e=typeof r==`string`&&r!==``?r:null}if(e===null){u.append(I(c,`span`,null,t.label));continue}if(!a)continue}u.append(this.#n(c,t,f,n,d?`wui-chat-quick-reply--quiet`:``,e)),f+=1}if(o){let e=I(c,`span`,`visually-hidden`,n.labels.handoffMoment);e.setAttribute(`role`,`status`),u.append(e)}u.childElementCount>0&&this.append(u)}#t(e,t,n){let r=I(e,`div`,`wui-chat-offer`);return r.style.setProperty(`--wui-chat-i`,`0`),r.append(I(e,`div`,`wui-chat-offer-title`,t.label)),r.append(this.#n(e,{...t,variant:`Primary`},0,n,`wui-chat-offer-action`)),r}#n(e,t,n,r,i=``,a=null){let o=e.createElement(`button`);o.type=`button`,o.className=[`wui-chat-quick-reply`,kt[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=we(e,t.icon,16);if(n){let t=I(e,`span`,`wui-chat-quick-reply-icon`);t.setAttribute(`aria-hidden`,`true`),t.append(n),o.append(t)}}return o.append(I(e,`span`,`wui-chat-quick-reply-label`,c?r.labels.handoffMoment:t.label)),o.addEventListener(`click`,()=>{t.action===`Open`?this.turn.openTarget(t.target):s?this.turn.beginHandoff(t,()=>this.#r(a)):(this.turn.chooseQuickReply(t),this.closest(`.wui-chat`)?.querySelector(`.wui-chat-input`)?.focus())}),o}#r(e){typeof this.turn.openTarget==`function`?this.turn.openTarget(e):globalThis.location.assign(e)}});var At=/* @__PURE__ */ new Set([`Integer`,`Decimal`,`MoneyMinor`,`Percent`]);function jt(e){return At.has(e)}function Mt(e,t,n,r=!0){let i=e=>r?N(e):[{kind:`text`,text:e}];if(t==null||t===``)return[{kind:`text`,text:ye}];if(e===`Date`||e===`DateTimeUtc`)return[{kind:`text`,text:re(t,e,n)}];if(jt(e)){let r=Number(t);return i(Number.isFinite(r)?re(r,e,n):String(t))}return i(String(t))}var Nt=0;function Pt(e){return Nt+=1,`${e}-${Nt}`}F(`wui-chat-part-record-card`,class extends P{#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=I(o,`article`,`wui-chat-record`),c=Pt(`wui-chat-record-title`);s.setAttribute(`aria-labelledby`,c);let l=I(o,`div`,`wui-chat-record-head`),u=I(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=I(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=I(o,`dl`,`wui-chat-record-fields`);for(let n of e.fields){let e=I(o,`div`),r=I(o,`dt`);i?B(r,n.label):r.textContent=String(n.label??``);let a=I(o,`dd`);jt(n.type)&&(a.className=`wui-chat-num`),z(a,Mt(n.type,n.value,null,i)),e.append(r,a),t.append(e)}s.append(t)}if(r){let t=I(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`,()=>this.turn.openRecord(e)),s.append(t)}this.replaceChildren(s)}});var Ft=/^https?:\/\//i;F(`wui-chat-part-sources`,class extends P{renderPart(e,t,n){if(this.replaceChildren(),!n.features.Sources||e.sources.length===0)return;let r=this.ownerDocument,i=I(r,`div`,`wui-chat-sources`);i.append(I(r,`p`,`wui-chat-sources-label`,n.labels.sources));let a=I(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;return typeof t.url==`string`&&Ft.test(t.url)?(r=I(e,`a`,`wui-chat-source`),r.setAttribute(`href`,t.url),r.setAttribute(`target`,`_blank`),r.setAttribute(`rel`,`noopener noreferrer`),r.setAttribute(`aria-label`,n.labels.openSource(t.title))):(r=I(e,`span`,`wui-chat-source`),r.tabIndex=-1),r.dataset.marker=String(t.marker),r.append(I(e,`span`,`wui-chat-source-marker`,String(t.marker)),I(e,`span`,`wui-chat-source-title`,t.title)),r}});var It=25,Lt=0;function Rt(e,t,n){let r=e.createElement(`tr`);for(let i of t.columns){let t=e.createElement(`th`);t.setAttribute(`scope`,`col`),jt(i.type)&&(t.className=`wui-chat-num`),n?B(t,i.label):t.textContent=String(i.label??``),r.append(t)}return r}function zt(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`),jt(a.type)&&(c.className=`wui-chat-num`);let l=n[o];l==null||l===``?c.append(I(c.ownerDocument,`span`,`wui-chat-null`,ye)):z(c,Mt(a.type,l,t.currency,r)),i.append(c)}),i}function Bt(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 Vt(e,t,n,r,i){let a=e.ownerDocument;for(let o=n;o<r;o+=1)e.append(zt(a,t,t.rows[o],i))}F(`wui-chat-part-table`,class extends P{#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=I(a,`figure`,`wui-chat-table`),s=null;if(e.title){Lt+=1,s=`wui-chat-table-${Lt}`;let t=I(a,`figcaption`,`wui-chat-table-title`);t.id=s,r?B(t,e.title):t.textContent=String(e.title??``),o.append(t)}let c=I(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=I(a,`table`,`table table-sm wui-chat-table-grid`),u=a.createElement(`thead`);u.append(Rt(a,e,r));let d=a.createElement(`tbody`);Vt(d,e,0,Math.min(e.rows.length,It),r),l.append(u,d),c.append(l);let f=I(a,`div`,`wui-chat-table-frame`),p=I(a,`span`,`wui-chat-table-cue`);if(p.setAttribute(`aria-hidden`,`true`),f.append(c,p),o.append(f),Bt(f,c),e.rows.length>It){let t=I(a,`button`,`btn btn-soft-primary btn-sm wui-chat-table-more`,n.labels.tableShowAll(e.rows.length));t.type=`button`,t.addEventListener(`click`,()=>{Vt(d,e,It,e.rows.length,r),t.remove()}),o.append(t)}this.replaceChildren(o)}});var Ht=/* @__PURE__ */ new Set([`Visitor`,`Customer`]),Ut=/^\d+$/,Wt=`pre, code, .wui-markdown-source`;function Gt(e,t){return e?.features?.Sources===!0?typeof e?.isCitation==`function`?e.isCitation(t):Ut.test(t):!1}function Kt(e,t){if(se(e,t?.handoffHosts))return e;let n=t?.resolveLink?.(e);return typeof n==`string`&&n!==``?n:null}function qt(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=Kt(e,t);i===null?r.replaceWith(r.ownerDocument.createTextNode(r.textContent)):(i!==r.getAttribute(`href`)&&r.setAttribute(`href`,i),ge(i,`web`,void 0,n)?.kind===`web`?(r.setAttribute(`target`,`_blank`),r.setAttribute(`rel`,`noopener noreferrer`)):(r.removeAttribute(`target`),r.removeAttribute(`rel`)))}}function Jt(e){let t=e.ownerDocument,n=t.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=[];for(let e=n.nextNode();e;e=n.nextNode())e.parentElement?.closest(Wt)||r.push(e);for(let e of r){let n=N(e.nodeValue);if(n.length===1&&n[0].kind===`text`)continue;let r=t.createDocumentFragment();z(r,n),e.replaceWith(r)}}function Yt(e){let t=e.turn;qt(e,t),t?.features?.FigureText===!0&&Jt(e)}F(`wui-chat-part-text`,class extends P{#e=null;#t=null;#n=null;#r=null;#i=!1;#a=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.#s(e))}renderPart(e,t){let n=Ht.has(t.author.kind)?`plain`:`markdown`;if(n!==this.#e&&(this.#e=n,this.#r=null,this.#t=n===`plain`?this.#c():this.#l(e.text),this.#n=n===`plain`?null:this.#t.firstElementChild,this.replaceChildren(this.#t)),n===`plain`){let t=this.turn?.features?.FigureText===!0,n=JSON.stringify([e.text,t]);n!==this.#r&&(this.#r=n,this.#t.replaceChildren(),t?z(this.#t,N(e.text)):this.#t.append(this.ownerDocument.createTextNode(e.text)))}else this.#n.textContent!==e.text&&(this.#n.textContent=e.text);this.toggleAttribute(`data-streaming`,t.streaming===!0),this.#i||(this.#i=!0,this.closest(`[data-restored]`)||this.classList.add(`wui-chat-part-enter`)),this.#o()}disposePart(){this.#a?.disconnect(),this.#a=null}#o(){this.#a||(this.#a=new MutationObserver(()=>Yt(this)),this.#a.observe(this,{childList:!0,subtree:!0,characterData:!0}),Yt(this))}#s(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)))}#c(){return I(this.ownerDocument,`div`,`wui-chat-bubble`)}#l(e){let t=this.ownerDocument,n=I(t,`wui-markdown`,`wui-markdown wui-chat-text`);n.setAttribute(`links`,`web`),n.setAttribute(`headings`,`text`),n.isCitation=e=>Gt(this.turn,e);let r=I(t,`pre`,`wui-markdown-source`,e);return n.append(r),n}}),F(`wui-chat-part-ticket`,class extends P{renderPart(e,t,n){let{labels:r}=n,i=a(`article`,`wui-chat-ticket`,{"aria-label":r.ticketAria(e.number)}),o=a(`div`,`wui-chat-ticket-head`),s=a(`span`,`wui-chat-ticket-number`);s.textContent=r.ticketAria(e.number),o.append(s);let c=nt(e.status);if(c!==null){let t=a(`span`,`wui-chat-ticket-badge wui-chat-ticket-badge--${c}`);t.textContent=rt(e.status,r),o.append(t)}let l=a(`strong`,`wui-chat-ticket-title`);if(l.textContent=e.subject,i.append(o,l),typeof n.openTicket==`function`){let t=a(`div`,`wui-chat-ticket-foot`),o=a(`button`,`wui-chat-ticket-link`,{type:`button`});o.textContent=r.ticketView,o.addEventListener(`click`,()=>n.openTicket({ticketId:e.ticketId,number:e.number})),t.append(o),i.append(t)}this.replaceChildren(i)}});var Xt=`http://www.w3.org/2000/svg`,Zt={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 Qt(e,t=18){if(!Object.hasOwn(Zt,e))throw Error(`Unknown voice icon "${e}".`);let n=document.createElementNS(Xt,`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(Xt,`path`);return r.setAttribute(`d`,Zt[e]),n.append(r),n}var $t=40,J=null,en=class extends P{#e=null;#t=null;#n=null;#r=null;#i=null;#a=null;#o=null;#s=null;#c=!1;#l=null;#u=0;#d=0;#f=!1;#p=null;#m=null;#h=null;#g=0;#_=!1;renderPart(e,t,n){this.#e=n,n.features.VoiceClips?(this.#t===null&&this.#y(),e.attachmentId!==this.#l&&(this.disposePart(),this.#l=e.attachmentId,this.#d=0,this.#n.replaceChildren(...he(e.attachmentId,$t).map(tn))),this.#u=e.durationMs,this.#b(e)):this.#v(e.transcript)}disposePart(){this.#g+=1,this.#p?.pause(),this.#h!==null&&URL.revokeObjectURL(this.#h),J===this&&(J=null),this.#p=null,this.#m=null,this.#h=null,this.#f=!1}#v(e){if(this.disposePart(),this.#t=null,this.#l=null,this.#o=null,this.#s=null,typeof e==`string`&&e!==``){let t=I(document,`p`,`wui-chat-clip-transcript`);t.textContent=e,this.replaceChildren(t)}else this.replaceChildren()}#y(){this.#t=I(document,`div`,`wui-chat-clip`),this.#t.setAttribute(`role`,`group`);let e=I(document,`div`,`wui-chat-clip-row`);this.#r=I(document,`button`,`wui-chat-clip-play`),this.#r.type=`button`,this.#r.addEventListener(`click`,()=>this.#A()),this.#n=I(document,`div`,`wui-chat-clip-wave`),this.#n.setAttribute(`aria-hidden`,`true`),this.#i=I(document,`span`,`wui-chat-clip-time`),e.append(this.#r,this.#n,this.#i),this.#a=I(document,`p`,`wui-chat-clip-error`),this.#a.setAttribute(`role`,`status`),this.#a.hidden=!0,this.#t.append(e,this.#a),this.replaceChildren(this.#t)}#b(e){let t=this.#e.labels;this.#t.setAttribute(`aria-label`,t.voiceClip),this.#r.disabled=this.#_||typeof this.#e.readAttachment!=`function`,this.#x(),this.#S(),this.#C(e.transcript)}#x(){let e=this.#e.labels,t=this.#f?e.voiceClipPause:e.voiceClipPlay;this.#r.setAttribute(`aria-label`,t),this.#r.title=t,this.#r.replaceChildren(Qt(this.#f?`pause`:`play`,18))}#S(){let e=this.#u/1e3,t=e>0?Math.min(1,this.#d/e):0,n=Math.floor(t*$t);[...this.#n.children].forEach((e,t)=>{e.classList.toggle(`wui-chat-clip-bar--played`,t<n)});let r=ie(Math.max(1,Math.round(e)));this.#i.textContent=this.#e.labels.voiceClipTime(ie(this.#d),r)}#C(e){typeof e!=`string`||e===``?(this.#o?.remove(),this.#s?.remove(),this.#o=null,this.#s=null):(this.#o===null&&(this.#o=I(document,`button`,`wui-chat-clip-toggle`),this.#o.type=`button`,this.#o.addEventListener(`click`,()=>{this.#c=!this.#c,this.#s.hidden=!this.#c,this.#w()}),this.#s=I(document,`p`,`wui-chat-clip-transcript`),this.#s.hidden=!this.#c,this.#t.append(this.#o,this.#s)),this.#s.textContent=e,this.#w())}#w(){let e=this.#e.labels;this.#o.setAttribute(`aria-expanded`,String(this.#c)),this.#o.textContent=this.#c?e.voiceClipHideTranscript:e.voiceClipShowTranscript}#T(){return this.#m??=this.#E().catch(e=>{throw this.#m=null,e}),this.#m}async#E(){let e=this.#g,t=await this.#e.readAttachment(this.#l),n=URL.createObjectURL(new Blob([t],{type:fe(t)}));if(e!==this.#g)return URL.revokeObjectURL(n),null;this.#h!==null&&URL.revokeObjectURL(this.#h),this.#h=n;let r=new Audio(this.#h);return r.addEventListener(`timeupdate`,()=>{this.#d=r.currentTime,this.#S()}),r.addEventListener(`ended`,()=>{this.#d=0,this.#D(),this.#S()}),r.addEventListener(`error`,()=>{this.#D(),this.#m=null,this.#k()}),this.#p=r,r}#D(){this.#p?.pause(),this.#O(!1)}#O(e){this.#f=e,e?(J&&J!==this&&J.#D(),J=this):J===this&&(J=null),this.#t!==null&&this.#x()}#k(){this.#a.textContent=this.#e.labels.voiceClipFailed,this.#a.hidden=!1}async#A(){if(this.#f)this.#D();else{this.#a.hidden=!0,this.#_=!0,this.#r.disabled=!0,this.#r.setAttribute(`aria-busy`,`true`);try{let e=await this.#T();if(e===null)return;this.#O(!0),await e.play()}catch{this.#D(),this.#m=null,this.#k()}finally{this.#_=!1,this.#r.removeAttribute(`aria-busy`),this.#r.disabled=typeof this.#e.readAttachment!=`function`}}}};function tn(e){let t=I(document,`span`,`wui-chat-clip-bar`);return t.style.setProperty(`--wui-chat-bar-height`,`${Math.round(e*100)}%`),t}F(`wui-chat-part-voice-clip`,en);var nn={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`},rn=8e3,an=6e3,on=/* @__PURE__ */ new Set([`Blocked`,`NoMicrophone`]);function sn(e){let t=e instanceof o?e.code:`Failed`;return{code:t,source:`Dictation`,sticky:on.has(t)}}function cn(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,an),r=n.lastIndexOf(`. `);return r===-1?n.trim():n.slice(0,r+1)}function ln(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 un(e){let n=e.getState,r=e.speech??t({getToken:e.getToken}),i=`Idle`,a=null,o=null,s=null,c=null,l=0,u=null,d=/* @__PURE__ */ new Set,f=()=>({mode:i,messageId:a,startedAtMs:o,note:s});function p(){let e=f();for(let t of[...d])t(e)}function m(e){i=e.mode,a=e.messageId??null,o=e.startedAtMs??null,p()}function h(){clearTimeout(u),u=null}function g(e){h(),s=e,e&&!e.sticky&&(u=setTimeout(()=>{u=null,s=null,p()},rn)),p()}function _(){s!==null&&(h(),s=null,p())}function v(){return l+=1,c={id:l,controller:new AbortController,stopped:!1},c}function y(e){c===e&&(c=null,m({mode:`Idle`}))}function b(){let e=c;c=null,e&&(e.stopped=!0,e.controller.abort()),i!==`Idle`&&m({mode:`Idle`})}function x(){let e=n();return!!(e.features.Dictation&&e.profile?.speechAvailable&&r.dictation)}function S(){let e=n();return!!(e.features.ReadAloud&&e.profile?.speechAvailable&&r.readAloud)}async function C(e){if(i===`Dictating`){b();return}if(b(),g(null),!x())return;let t=e.getText(),n=t!==``&&!/\s$/.test(t)?`${t} `:t,a=v();m({mode:`Dictating`});try{await r.startDictation({signal:a.controller.signal,onText:t=>{c===a&&e.setText(n+t)},onEnd:()=>y(a)})}catch(e){if(a.stopped)return;y(a),g(sn(e))}}async function w(e,t){if(i===`Speaking`&&a===e){b();return}b(),g(null);let n=cn(t);if(n===``)return;let o=v();m({mode:`Speaking`,messageId:e});try{await r.speak(n,{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 dn=/* @__PURE__ */ new Set([`Shift`,`Control`,`Alt`,`Meta`,`Escape`]);function fn(e,t){e.isTrusted&&!dn.has(e.key)&&t.getStatus().mode===`Dictating`&&t.stop()}function pn({voice:e,getLabels:t,textarea:n,onTextChanged:r}){let i=null,o=a(`button`,`wui-chat-tool wui-chat-mic`,{type:`button`});o.append(Qt(`mic`,20)),o.hidden=!0,o.addEventListener(`click`,()=>{e.toggleDictation({getText:()=>n.value,setText:e=>{n.value=n.maxLength>0?e.slice(0,n.maxLength):e,r(),n.setSelectionRange(n.value.length,n.value.length)}})});let s=a(`p`,`wui-chat-voice-note`,{role:`status`});s.hidden=!0;let c=a(`span`,`visually-hidden`,{"aria-live":`polite`});function l(e){let n=t(),r=e.note?.source===`ReadAloud`?null:e.note,i=e.mode===`Dictating`,a=i?n.dictateStop:n.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=ln(r,n),s.setAttribute(`role`,r.sticky?`alert`:`status`)),s.classList.toggle(`wui-chat-voice-note--blocked`,l),c.textContent=i?n.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),i!==null&&u(i)}let f=e.subscribe(d);function p(t){i=t,u(t),l(e.getStatus())}function m(){f()}return{buttons:[o],note:s,announcer:c,paint:p,destroy:m}}var mn=10,hn=.9,gn=0;function _n(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 vn(t){gn+=1;let n=`wui-chat-composer-hint-${gn}`,r=a(`p`,`wui-chat-allowance`,{role:`status`});r.hidden=!0;let i=a(`span`),o=a(`button`,`btn btn-ghost-primary btn-sm wui-chat-action-btn`,{type:`button`});o.addEventListener(`click`,()=>t.onCancelEdit());let s=a(`div`,`wui-chat-editing`);s.hidden=!0,s.append(i,o);let c=a(`div`,`wui-chat-attachments`);c.hidden=!0;let l=a(`button`,`wui-chat-tool`,{type:`button`});l.append(e(`paperclip`,20)),l.hidden=!0;let u=a(`input`,null,{type:`file`,multiple:``,tabindex:`-1`});u.hidden=!0,u.addEventListener(`change`,()=>{let e=[...u.files];u.value=``,e.length>0&&t.onAttach(e)}),l.addEventListener(`click`,()=>u.click());let d=a(`textarea`,`wui-chat-input`,{rows:`1`,"aria-describedby":n}),f=a(`span`,`visually-hidden`,{id:n}),p=a(`span`,`wui-chat-counter`);p.hidden=!0;let m=a(`button`,`wui-chat-send`,{type:`submit`});m.append(e(`arrow-up`,18));let h=a(`button`,`wui-chat-send wui-chat-send--stop`,{type:`button`});h.append(e(`stop`,16)),h.hidden=!0,h.addEventListener(`click`,()=>t.onStop());let g=a(`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*hn;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(),t.voice?.stop(),t.voice?.dismissNote(),t.onSubmit(e)}d.addEventListener(`input`,()=>{S(),T(),E(),d.value!==``&&t.onTyping?.()}),d.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),D())}),g.addEventListener(`submit`,e=>{e.preventDefault(),D()});let O=t.voice?pn({voice:t.voice,getLabels:()=>y,textarea:d,onTextChanged:()=>{S(),T(),E()}}):null;O&&(g.insertBefore(O.buttons[0],m),d.addEventListener(`keydown`,e=>fn(e,t.voice)));function ee(n){let r=n.map(n=>{let r=a(`span`,`wui-chat-chip`),i=a(`span`,null,n.status===`Failed`?{title:n.error??``}:null);i.textContent=n.fileName;let o=a(`button`,`wui-chat-chip-remove`,{type:`button`,"aria-label":y.removeAttachment(n.fileName)});o.append(e(`x`,14)),o.addEventListener(`click`,()=>t.onRemove(n.key));let s=[];if(n.status===`Uploading`){let e=a(`progress`,`wui-chat-chip-progress`,{max:`1`});typeof n.progress==`number`&&(e.value=n.progress);let t=a(`span`,`wui-chat-chip-status`);t.textContent=y.attachmentUploading,s.push(e,t)}if(n.status===`Failed`){let e=a(`span`,`wui-chat-chip-error`,{"aria-live":`polite`});e.textContent=n.error||y.attachmentFailed,s.push(e)}return r.append(i,...s,o),r});c.replaceChildren(...r),c.hidden=r.length===0}function te(e){x=e.state,y=e.labels,b=e.maxLength;let n=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:_n(x.messages)??y.placeholder,d.disabled=n===0||x.handoffPause===!0,r.hidden=!(n!==null&&n<=mn),r.hidden||(r.textContent=y.allowance(n));let a=x.editing?.messageId??null;if(a!==_){let e=_!==null;_=a,x.editing?(t.voice?.stop(),d.value=x.editing.text,S()):e&&(d.value=``,S())}s.hidden=!x.editing,i.textContent=y.editing,o.textContent=y.cancel;let c=e.draft??null;typeof c==`string`&&c!==``&&c!==v&&(v=c,d.value=c,d.dispatchEvent(new Event(`input`)),d.focus(),t.onDraftApplied?.()),ee(x.attachments);let p=x.features.Attachments&&(x.profile?.limits.maxAttachments??0)>0&&x.handoffPause!==!0;l.hidden=!p,l.setAttribute(`aria-label`,y.attach),l.title=y.attachHint,u.accept=e.accept??``;let C=x.streaming&&x.features.Stop;h.hidden=!C,h.setAttribute(`aria-label`,y.stop),m.hidden=C,m.setAttribute(`aria-label`,y.send),T(),E(),O?.paint({state:x})}function k(){d.focus()}function ne(){O?.destroy();for(let e of A)e.remove()}let A=[r,s,c,...O?[O.note,O.announcer]:[],g];return{nodes:A,paint:te,focus:k,destroy:ne,getDraft:()=>d.value}}var yn=`https://policies.google.com/privacy`,bn=`https://policies.google.com/terms`;function xn(e,t){let n=a(`a`,`wui-chat-footer-link`,{href:t,target:`_blank`,rel:`noopener noreferrer`});return n.textContent=e,n}function Sn(){let e=a(`span`,`wui-chat-footer-sep`,{"aria-hidden":`true`});return e.textContent=`·`,e}function Cn(){let e=a(`p`,`wui-chat-footer`);e.hidden=!0;function t(t){let{labels:n,profile:r}=t,i=[];if(r){let e=a(`span`,`wui-chat-footer-text`);e.textContent=r.footer.disclaimer||n.disclaimer,i.push(e);let t=a(`span`,`wui-chat-footer-privacy`);if(r.footer.privacyText&&t.append(document.createTextNode(r.footer.privacyText)),r.footer.privacyUrl){t.hasChildNodes()&&t.append(document.createTextNode(` `));let e=a(`a`,`wui-chat-footer-link`,{href:r.footer.privacyUrl});e.textContent=n.footerPrivacy,t.append(e)}if(t.hasChildNodes()&&i.push(t),r.footer.assuranceText){let e=a(`span`);e.textContent=r.footer.assuranceText,i.push(e)}if(de(r)){let e=a(`span`,`wui-chat-footer-captcha`);e.append(document.createTextNode(`${n.captchaNote} `),xn(n.captchaPrivacy,yn),document.createTextNode(` `),xn(n.captchaTerms,bn)),i.push(e)}}e.replaceChildren(...i.flatMap((e,t)=>t?[Sn(),e]:[e])),e.hidden=i.length===0}return{el:e,paint:t}}function Y(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 wn(e){let t=a(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),n=a(`strong`,`wui-chat-title`);e.titleId&&(n.id=e.titleId);let r=a(`span`,`wui-chat-tagline`),i=a(`span`,`wui-chat-status`),o=a(`div`,`wui-chat-header-text`);o.append(n,r,i);let s=h(``,`history`,()=>e.onHistory()),c=h(``,`chat`,()=>e.onMute()),l=h(``,`plus`,()=>e.onNew()),u=h(``,`maximize-4`,()=>e.onSwitch());u.classList.add(`wui-chat-switch-btn`,`wui-chat-switch-btn--full`);let d=h(``,`panel-left-open`,()=>e.onSwitch());d.classList.add(`wui-chat-switch-btn`,`wui-chat-switch-btn--side`);let f=h(``,`x`,()=>e.onClose()),p=a(`div`,`wui-chat-header-actions`);p.append(s,c,l,u,d,f);let m=a(`header`,`wui-chat-header`);m.append(t,o,p);function g(e){let{labels:t}=e;m.hidden=!1,n.textContent=e.title??``,r.textContent=e.tagline??``,r.hidden=!e.tagline,i.textContent=e.status??``,s.hidden=!e.showHistory,e.viewingHistory?Y(s,t.backToChat,`arrow-left`):Y(s,t.history,`history`),c.hidden=!e.showMute,Y(c,e.muted?t.unmuteSounds:t.muteSounds,`chat`),l.hidden=!!e.viewingHistory||e.showNew===!1,l.disabled=!e.canNew,Y(l,t.newChat,`plus`),u.hidden=e.switchTo!==`full-page`,u.disabled=!e.canSwitch,Y(u,t.openFullScreen,`maximize-4`),d.hidden=e.switchTo!==`docked`,d.disabled=!e.canSwitch,Y(d,t.openSidePanel,`panel-left-open`),f.hidden=!e.showClose,Y(f,t.close,`x`)}return{el:m,paint:g}}var Tn=120;function X(e,t,n=`outline`){let i=a(`button`,`${r(n,`sm`)} wui-chat-action-btn`,{type:`button`});return i.textContent=e,i.addEventListener(`click`,t),i}function En(e){let t=a(`div`,`wui-chat-history`);t.hidden=!0;let n=null,r=null,i=null,o=null,s=null,c=!1;function l(){return n||(n=k({client:e.getClient()}),r=n.subscribe(()=>y()),n)}function u(e){i={id:e.publicId,kind:`rename`,draft:e.title??``,saving:!1},o=null,s=null,c=!0,y()}function d(e){i={id:e.publicId,kind:`delete`,saving:!1},o=null,s=null,y()}function f(){i=null,o=null,s=null,y()}async function p(){let t=i,n=t?.draft.trim()??``;if(t?.kind===`rename`&&!t.saving&&n){t.saving=!0,y();try{await l().rename(t.id,n),i===t&&(i=null),o=null,s=null}catch{if(i!==t)return;t.saving=!1,s=e.getLabels().renameFailed}y()}}async function m(){let t=i;if(!(t?.kind!==`delete`||t.saving)){t.saving=!0,y();try{await l().remove(t.id),i===t&&(i=null),o=null,e.onDeleted(t.id)}catch{if(i!==t)return;t.saving=!1,o=e.getLabels().deleteFailed}y()}}function g(e){let t=a(`li`,`wui-chat-history-row wui-chat-history-row--editing`),n=a(`input`,`wui-chat-history-input`,{type:`text`,"aria-label":e.conversationTitle,maxlength:String(Tn)});n.value=i.draft,n.addEventListener(`input`,()=>{i.draft=n.value,r.disabled=i.saving||!i.draft.trim()}),n.addEventListener(`keydown`,e=>{e.key===`Enter`?(e.preventDefault(),p()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),f())});let r=X(e.renameSave,()=>p(),`primary`);if(r.disabled=i.saving||!i.draft.trim(),t.append(n,r,X(e.cancel,()=>f(),`ghost`)),s!==null){let e=a(`p`,`wui-chat-history-error`,{role:`alert`});e.textContent=s,t.append(e)}return c&&(c=!1,queueMicrotask(()=>n.focus())),t}function _(e){let t=a(`li`,`wui-chat-history-row wui-chat-history-row--confirm`),n=a(`p`);n.textContent=e.deleteConfirmTitle;let r=a(`p`);r.textContent=e.deleteConfirmMessage;let o=X(e.deleteConfirm,()=>m(),`danger`);return o.disabled=i.saving,t.append(n,r,o,X(e.cancel,()=>f(),`ghost`)),t}function v(t,n,r){if(i?.id===t.publicId&&i.kind===`rename`)return g(n);if(i?.id===t.publicId&&i.kind===`delete`)return _(n);let o=a(`li`,`wui-chat-history-row`),s=a(`button`,`wui-chat-history-open`,{type:`button`}),c=a(`span`,`wui-chat-history-title`);c.textContent=t.title||n.untitled;let l=a(`span`,`wui-chat-history-time`);return l.textContent=A(t.lastActivityDateTimeUtc),s.append(c,l),s.addEventListener(`click`,()=>e.onOpen(t.publicId)),o.append(s),r.Rename&&o.append(h(n.rename,`pencil`,()=>u(t))),r.Delete&&o.append(h(n.deleteChat,`trash`,()=>d(t))),o}function y(){let r=e.getLabels(),i=e.getFeatures(),s=n?n.getState():{items:[],loading:!1,error:null,hasMore:!1},c=[];if(s.error||o){let e=a(`p`,`wui-chat-history-error`,{role:`alert`});s.error?(e.append(document.createTextNode(r.loadFailed),document.createTextNode(` `)),e.append(X(r.retry,()=>l().load(),`outline`))):e.textContent=o,c.push(e)}if(s.loading&&s.items.length===0){let e=a(`p`,`wui-chat-history-empty`,{role:`status`});e.textContent=r.loadingConversation,c.push(e)}if(s.items.length===0&&!s.loading&&!s.error){let e=a(`p`,`wui-chat-history-empty`),t=a(`span`);t.textContent=r.historyEmptyTitle;let n=a(`span`);n.textContent=r.historyEmptyText,e.append(t,n),c.push(e)}if(s.items.length>0){let e=a(`ul`,`wui-chat-history-list`,{"aria-label":r.history});e.append(...s.items.map(e=>v(e,r,i))),c.push(e)}s.hasMore&&!s.loading&&c.push(X(r.loadMore,()=>l().loadMore(),`outline`)),t.replaceChildren(...c)}function b(){t.hidden=!1,l().load().catch(()=>{}),y()}function x(){t.hidden=!0}function S(){r?.(),r=null,n?.dispose(),n=null}return{el:t,show:b,hide:x,paint:y,dispose:S}}var Dn=/* @__PURE__ */ new Set([`GET`,`HEAD`]);function On(){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 kn(e){let t=await e.text();if(t){if((e.headers.get(`content-type`)||``).includes(`json`))try{return JSON.parse(t)}catch{return t}return t}}async function An(e,t){let n=new TextDecoder,r=e.body.getReader(),i=``;for(;;){let{done:a,value:o}=await r.read();if(a)break;i+=n.decode(o,{stream:!0}),t({event:{target:{responseText:i,status:e.status}}})}return i+=n.decode(),i}function jn({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(!Dn.has(t)){let e=On();e&&(a[e.header]=e.token)}let s=i.signal,c=s,l,u,d=()=>l.abort(s.reason);i.timeout>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=await e(n,{method:t,headers:a,body:o,signal:c,credentials:`same-origin`});if(!r.ok){let e=/* @__PURE__ */ Error(`Request failed with status ${r.status}`);throw e.response={status:r.status,data:await kn(r)},e}let s=i.responseType===`arraybuffer`,l=!s&&typeof i.onDownloadProgress==`function`&&r.body,u;return u=s?await r.arrayBuffer():l?await An(r,i.onDownloadProgress):await kn(r),{data:u,status:r.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 Mn(t){let n=null,r=!1,i=!1,o=a(`div`,`wui-chat-nudge`,{role:`status`});o.hidden=!0;let s=a(`button`,`wui-chat-nudge-text`,{type:`button`}),c=a(`button`,`wui-chat-nudge-close`,{type:`button`});c.append(e(`x`,14)),o.append(s,c);function l(){clearTimeout(n),n=null}function u(){l(),i=!0,o.hidden=!0}s.addEventListener(`click`,()=>{o.hidden=!0,t.onActivate()}),c.addEventListener(`click`,()=>{u(),t.onDismiss()});function d(e){l(),i||r||(n=setTimeout(()=>{n=null,s.textContent=e.text,c.setAttribute(`aria-label`,e.label),o.hidden=!1,r=!0},e.delaySeconds*1e3))}function f(){l(),o.remove()}return{el:o,schedule:d,cancel:l,dismiss:u,isShown:()=>r,destroy:f}}function Nn(e){let{list:t,getLabels:n,getFeatures:r,onOpen:i}=e,o=e.now??(()=>Date.now()),s=a(`div`,`wui-chat-empty-rows wui-chat-empty-rows--past`);s.hidden=!0;let c=!1;function u(e,t){let n=a(`button`,`wui-chat-empty-row`,{type:`button`}),r=a(`span`,`wui-chat-empty-row-title`);r.textContent=e.title||t.earlierChat;let s=a(`span`,`wui-chat-empty-row-time`,{title:l(e.lastActivityDateTimeUtc)});return s.textContent=T(e.lastActivityDateTimeUtc,o()),n.append(r,s),n.addEventListener(`click`,()=>i(e.publicId)),n}function d(){if(c)return;let e=t.getState().items;if(r().History!==!0||e.length===0){s.replaceChildren(),s.hidden=!0;return}let i=n();s.replaceChildren(...e.slice(0,20).map(e=>u(e,i))),s.hidden=!1}let f=t.subscribe(d);return{el:s,refresh(){r().History===!0&&t.load().catch(()=>{})},paint:d,dispose(){c=!0,f()}}}var Pn=`https://www.google.com/recaptcha/api.js?render=`,Fn=/* @__PURE__ */ new Map;function In(e){let t=Fn.get(e);if(t)return t;let n=new Promise((t,n)=>{if(globalThis.grecaptcha?.execute){t(globalThis.grecaptcha);return}let r=document.createElement(`script`);r.src=Pn+encodeURIComponent(e),r.async=!0,r.addEventListener(`load`,()=>t(globalThis.grecaptcha)),r.addEventListener(`error`,()=>{Fn.delete(e),n(/* @__PURE__ */ Error(`The reCAPTCHA script did not load.`))}),document.head.append(r)});return Fn.set(e,n),n}async function Ln(e,t){let n=await In(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 Rn=`data-wui-chat-docked`,zn=`--wui-chat-docked-width`,Bn=420,Vn=/* @__PURE__ */ new Set;function Hn(e,t){let n=document.documentElement;n.setAttribute(Rn,e),n.style.setProperty(zn,t)}function Un(){let e=document.documentElement;e.removeAttribute(Rn),e.style.removeProperty(zn)}function Wn(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)||Bn}px`;function c(){Vn.add(r),Hn(i,s()),typeof ResizeObserver==`function`&&(o=new ResizeObserver(()=>document.documentElement.style.setProperty(zn,s())),o.observe(t.panel))}function l(){o?.disconnect(),o=null,Vn.delete(r),Vn.size===0&&Un()}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(Rn,i))}function f(){u(!1)}return{...t,setOpen:u,setAppearance:d,destroy:f}}function Gn(e){return n({...e,layout:`embedded`,role:`region`,launcher:!1})}var Kn=`wchat:peeked`,qn=576,Jn=200;function Yn(e){let t=n({...e,layout:`launcher`,role:`dialog`,launcher:!0}),{root:r,panel:i,nudgeHost:a,launcherButton:o}=t,s={peek:!1,peekSeconds:3,hideWhileOpen:!1};o.dataset.state=`closed`;let c=!1,l=!1,u=null,d=null;function f(){!s.peek||c||l||a.dataset.launcher!==`idle`||globalThis.innerWidth<qn||globalThis.sessionStorage.getItem(Kn)!==null||(globalThis.sessionStorage.setItem(Kn,`1`),a.dataset.launcher=`peeking`,u=setTimeout(()=>{u=null,a.dataset.launcher===`peeking`&&(a.dataset.launcher=`idle`)},s.peekSeconds*1e3))}a.addEventListener(`animationend`,e=>{e.target===a&&a.dataset.launcher===`idle`&&f()});function p(e){if(e!==l){if(l=e,clearTimeout(u),u=null,e)clearTimeout(d),d=null,s.hideWhileOpen?(a.dataset.launcher=`hidden`,a.toggleAttribute(`inert`,!0)):a.dataset.launcher===`peeking`&&(a.dataset.launcher=`idle`);else if(s.hideWhileOpen){let e=i.contains(document.activeElement);d=setTimeout(()=>{d=null,a.toggleAttribute(`inert`,!1),a.dataset.launcher=`idle`,e&&o.focus()},Jn)}}o.dataset.state=e?`open`:`closed`,t.setOpen(e)}function m(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.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),!s.hideWhileOpen&&a.dataset.launcher===`hidden`&&!l&&(a.dataset.launcher=`idle`),a.dataset.launcher===`idle`&&f()}return{...t,setOpen:p,setAppearance:m}}function Xn(e){return n({...e,layout:`full-page`,role:`region`,launcher:!1})}var Zn=3;function Qn(t){let n=a(`h2`,`wui-chat-greeting`),r=a(`div`,`wui-chat-empty-hero`);r.append(a(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),n);let i=a(`div`,`wui-chat-empty-extra`);i.hidden=!0;let o=a(`div`,`wui-chat-starters`,{role:`group`}),s=a(`div`,`wui-chat-empty-rows`),c=a(`div`,`wui-chat-empty-past`),l=a(`div`,`wui-chat-empty`,{role:`group`});l.append(r,i,o,s,c);function u(n,r){let i=a(`button`,`wui-chat-starter`,{type:`button`});return i.style.setProperty(`--wui-chat-i`,String(r)),n.icon&&i.append(e(n.icon,16)),i.append(document.createTextNode(n.label)),i.addEventListener(`click`,()=>t.onStarter(n)),i}function d(e,n){let r=a(`button`,`wui-chat-empty-row`,{type:`button`}),i=a(`span`,`wui-chat-empty-row-label`);i.textContent=n.resumeLast;let o=a(`span`,`wui-chat-empty-row-title`,{title:e.title||n.untitled});o.textContent=e.title||n.untitled;let s=a(`span`,`wui-chat-empty-row-time`);return s.textContent=A(e.lastActivityDateTimeUtc),r.append(i,o,s),r.addEventListener(`click`,()=>t.onResume()),r}function f(e,n,r){let i=r?a(`button`,`wui-chat-empty-row`,{type:`button`}):a(`span`,`wui-chat-empty-row`),o=a(`span`,`wui-chat-empty-row-label`);o.textContent=n.ticketAria(e.number);let s=a(`span`,`wui-chat-empty-row-title`);s.textContent=e.subject;let c=a(`span`,`wui-chat-empty-row-status`);return c.textContent=rt(e.status,n),i.append(o,s,c),r&&i.addEventListener(`click`,()=>t.onTicket(e)),i}function p(e,t){if(e.features?.OpenTickets!==!0||!e.openTickets?.length)return null;let n=a(`div`,`wui-chat-open-tickets`,{role:`group`,"aria-label":t.openTickets});return n.append(...e.openTickets.slice(0,Zn).map(n=>f(n,t,e.ticketsClickable===!0))),n}function m(e){let{labels:t}=e;n.textContent=e.greeting??``,l.setAttribute(`aria-label`,t.emptyTitle);let r=e.starters??[];o.setAttribute(`aria-label`,t.starters),o.hidden=!e.showStarters||r.length===0,o.replaceChildren(...r.map(u));let i=e.resume??null,a=p(e,t);s.hidden=i===null&&a===null,s.replaceChildren(...[i===null?null:d(i,t),a].filter(Boolean))}return{el:l,paint:m,extraHost:i,pastHost:c}}function $n(){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 er=150,tr=1800;function nr(){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()%tr)}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()%tr)}ms, 0s`,a()?t.remove():setTimeout(()=>t.remove(),er))}return{el:e,render:o}}var rr=[`95%`,`80%`,`60%`];function ir(){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 rr){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 ar=`http://www.w3.org/2000/svg`;function or(e){if(e===`done`){let e=document.createElementNS(ar,`svg`);e.setAttribute(`viewBox`,`0 0 16 16`),e.setAttribute(`class`,`wui-chat-loader-steps-check`);let t=document.createElementNS(ar,`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 sr(){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 cr={Steps:sr,Phrases:nr,Orb:$n,Skeleton:ir},lr=500;function ur(){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 i=null,a=null,o=0,s=null,c=0,l=null,u=!1;function d(){s!==null&&clearInterval(s),s=null}function f(){e.isConnected?(o+=1,p()):d()}function p(){if(!a||!i)return;let t=ce(i.style,i.steps,i.phrases,o);a.render(t),e.setAttribute(`aria-label`,t.label)}function m(){l!==null&&clearTimeout(l),l=null,u=!1,r.textContent=``}function h(e){!u&&l===null&&e&&(l=setTimeout(()=>{l=null,u=!0,r.textContent=e},lr))}function g(t){if(!t.active)i=null,e.hidden=!0,e.removeAttribute(`data-loading`),d(),m();else{if(!Object.hasOwn(cr,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(i={...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),!a||a.style!==t.style){let r=cr[t.style]();n.replaceChildren(r.el),a={style:t.style,render:r.render},e.dataset.style=t.style,o=0}h(t.announce),t.reduced===!0?(d(),o=0):(s===null||c!==t.intervalMs)&&(d(),c=t.intervalMs,s=setInterval(f,c)),p()}}function _(){d(),m(),a=null,i=null,e.remove()}return{el:e,update:g,destroy:_}}var dr=/* @__PURE__ */ new Set([`Assistant`,`Agent`,`Script`]),fr=/* @__PURE__ */ new WeakMap;function pr(e,t,n){let{labels:r,features:a,title:o,busy:s}=n;if(M(t.parts)!==``){if(a.Share&&p()){let n=i(`ghost`,r.share,`share`,async()=>{let e=_r([t],a,r,o,!1);e!==``&&await f({title:o,text:e})===`failed`&&xr(n.parentElement,r.shareFailed)});n.disabled=s===!0,e.append(n)}if(a.Print){let t=i(`ghost`,r.print,`printer`,()=>{try{E(t.closest(`.wui-chat`),t.closest(`li.wui-chat-message`),{title:o,printedOn:yr(r)})}catch{br(t,r.printFailed)}});e.append(t)}}}function mr(e,t,n){if(t.streaming||t.thinking||t.loading||t.conversationId===null||t.messages.filter(e=>e.stored&&dr.has(e.author.kind)&&M(e.parts)!==``).length===0){e.hidden=!0;return}let{labels:r,features:i}=n,a=!!i.Share&&p(),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(hr(e,r,i,n)),o&&e.append(gr(e,r,n))),e.hidden=!1}function hr(e,t,n,r){return i(`ghost`,t.shareConversation,`share`,async()=>{let i=r.getState(),a=vr(i,r),o=_r(i.messages.filter(e=>e.stored),n,t,a,!0);await f({title:a,text:o})===`failed`&&xr(e,t.shareFailed)})}function gr(e,t,n){let r=i(`ghost`,t.printConversation,`printer`,()=>{try{w(e.closest(`.wui-chat`),{title:vr(n.getState(),n),printedOn:yr(t)})}catch{br(r,t.printFailed)}});return r}function _r(e,t,n,r,i){let a=O(e,{labels:n,title:r,figureText:t.FigureText});return me(a,{heading:i,speakers:i})}function vr(e,t){return typeof e.title==`string`&&e.title!==``?e.title:t.title}function yr(e){return e.printedOn(A((/* @__PURE__ */ new Date()).toISOString()))}function br(e,t){let n=e.lastChild,r=fr.get(n);r?clearTimeout(r.timer):r={original:n.data},n.data=t,r.timer=setTimeout(()=>{n.data=r.original,fr.delete(n)},ve),fr.set(n,r)}function xr(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(),ve)}function Sr({voice:e,getLabels:t,message:n}){if(n.streaming||!e.canSpeak()||cn(n.parts)===``)return null;let r=e.getStatus(),i=r.mode===`Speaking`&&r.messageId===n.id,o=t(),s=i?o.readAloudStop:o.readAloud,c=a(`button`,`wui-chat-action-btn wui-chat-speak`,{type:`button`,"aria-pressed":String(i),"aria-label":s,title:s});return c.append(Qt(i?`stop`:`speaker`,16)),c.addEventListener(`click`,()=>{e.toggleSpeak(n.id,n.parts)}),c}function Cr({voice:e,getLabels:t,message:n}){let r=e.getStatus().note;if(r?.code!==`SpeakFailed`||r.messageId!==n.id)return null;let i=a(`span`,`wui-chat-action-notice`,{role:`status`});return i.textContent=ln(r,t()),i}var wr=/* @__PURE__ */ new Set([`Assistant`,`Agent`]),Tr=/* @__PURE__ */ new Set([`Assistant`,`Agent`,`Script`]),Er=/* @__PURE__ */ new Set([`Visitor`,`Customer`]),Dr=48,Or=120,kr={author:{kind:`Assistant`}},Ar={warning:`alert-triangle`,danger:`alert-circle`};function jr(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=Dr}function Mr(e){let{kind:t,displayName:n}=e.author;return t===`Agent`?`Agent:${n??``}`:t===`Script`?`Assistant`:t}function Nr(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 Pr(e){let t=e.textContent.trim();t&&!e.hasAttribute(`aria-label`)&&(e.setAttribute(`aria-label`,t),e.title=t)}function Fr(e){return e.reduced===!0}function Ir(t,n,i){let o=a(`button`,`${r(`ghost`,`sm`)} wui-chat-action-btn`,{type:`button`,"aria-label":t,title:t}),s=a(`span`);return s.textContent=t,o.append(e(n,14),s),o.addEventListener(`click`,i),{node:o,text:s}}function Lr(e,t){return e.profile?.assistant.name??t.panelTitle}function Rr(e,t){return e.author.displayName==null?e.author.kind===`Visitor`||e.author.kind===`Customer`?t.you:e.author.kind===`Agent`?t.agent:t.assistant:e.author.displayName}function zr(t){let n=a(`ol`,`wui-chat-thread`),i=a(`div`,`wui-chat-log`,{role:`log`,"aria-live":`polite`});i.append(n);let o=ur(),s=a(`li`,`wui-chat-message wui-chat-message--assistant wui-chat-message--loading`),c=a(`div`,`wui-chat-loader-slot`);c.append(o.el),s.append(c);let u=!1,d=null,f=a(`li`,`wui-chat-message wui-chat-message--assistant wui-chat-message--greeting`,{"data-run-start":``,"data-restored":``}),p=a(`div`,`wui-chat-message-body`),m=a(`p`,`wui-chat-text`);p.append(m),f.append(p);let h=a(`li`,`wui-chat-conversation-actions`);h.hidden=!0;let g=a(`button`,`wui-chat-jump`,{type:`button`}),_=a(`div`,`wui-chat-jump-slot`);_.hidden=!0,_.append(g);let v=null,y=!0,b=null,x=null,S=/* @__PURE__ */ new Map,C=``,w=null;function T(e,t,n){return n[e.kind]?{kind:e.kind,part:e,tag:n[e.kind]}:{kind:`Notice`,part:{kind:`Notice`,code:`NeedsNewerApp`,text:t.needsNewerApp},tag:n.Notice}}function E(e,n,r){let i=document.createElement(e);return i.message=r,i.turn=t.makeTurnApi(r.id),i.part=n,i}function D(e){return a(`div`,`wui-chat-part wui-chat-part--${e.toLowerCase()}`)}function O(e,t,n,r,i){e.parts=[];let o=[],s=e=>{let i=T(e,n,r),a=D(i.kind);return a.append(E(i.tag,i.part,t)),a};for(let e of i(t))if(Array.isArray(e)){let t=a(`div`,`wui-chat-part-group`);t.append(...e.map(s)),o.push(t)}else o.push(s(e));e.body.replaceChildren(...o)}function ee(e,n,r,i){let a=[];n.parts.forEach((o,s)=>{let c=T(o,r,i),l=e.parts[s];if(l&&l.kind===c.kind&&l.tag===c.tag){l.part!==c.part&&(l.element.message=n,l.element.turn=t.makeTurnApi(n.id),l.element.part=c.part,l.part=c.part),a.push(l);return}let u=D(c.kind),d=E(c.tag,c.part,n);u.append(d),a.push({kind:c.kind,tag:c.tag,part:c.part,element:d,wrapper:u})}),e.parts=a,e.body.replaceChildren(...a.map(e=>e.wrapper))}function te(t,n,i){let o=a(`div`,`wui-chat-rating`,{role:`group`,"aria-label":`${i.rateUp}/${i.rateDown}`});for(let[s,c,l]of[[`Up`,i.rateUp,`thumbs-up`],[`Down`,i.rateDown,`thumbs-down`]]){let u=n.rating===s,d=a(`button`,`${r(u?`neutral`:`ghost`,`sm`)} wui-chat-action-btn`,{type:`button`,"aria-pressed":String(u),"data-rating":s,"aria-label":c,title:c}),f=a(`span`);f.textContent=c,d.append(e(l,14),f),d.addEventListener(`click`,()=>k(t,n,s,i)),o.append(d)}if(t.ratingNote){let e=a(`span`,null,{role:`status`});e.textContent=t.ratingNote,o.append(e)}return o}async function k(e,n,r,i){try{await t.onRate(n.id,r),e.ratingNote=i.rated}catch{e.ratingNote=i.ratingFailed}w&&N(w.state,w.context)}function ne(e,n,r,i,o){let{labels:s}=i,c=r.features,l=n.author.kind,u=M(n.parts),d=[];if(c.Copy&&Tr.has(l)&&u){let t=Ir(s.copy,`copy`,async()=>{await be(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},ve))});d.push(t.node)}let f=t.getVoice?.();if(f&&Tr.has(l)){let e=Sr({voice:f,getLabels:()=>s,message:n});e&&d.push(e);let t=Cr({voice:f,getLabels:()=>s,message:n});t&&d.push(t)}if(Tr.has(l)){let e=a(`div`);pr(e,n,{labels:s,features:c,title:Lr(r,s),busy:r.streaming||r.thinking});for(let t of e.childNodes)Pr(t);d.push(...e.childNodes)}let p=r.messages.some(e=>e.author.kind===`Visitor`&&e.stored);o&&l===`Assistant`&&!r.streaming&&!r.thinking&&c.Regenerate&&p&&d.push(Ir(s.regenerate,`refresh`,()=>t.onRegenerate()).node);let m=r.messages.findLast(e=>e.author.kind===`Visitor`&&e.stored);c.Edit&&m?.id===n.id&&!r.streaming&&!r.thinking&&d.push(Ir(s.edit,`pencil`,()=>t.getSession().startEdit(n.id)).node),c.Rating&&n.stored&&wr.has(l)&&d.push(te(e,n,s)),e.actions.hidden=d.length===0,e.actions.replaceChildren(...d)}function A(e){let t=S.get(e.id);if(t)return t;let n=a(`li`,`wui-chat-message`),r=a(`span`,`wui-chat-author visually-hidden`),i=a(`div`,`wui-chat-message-body`),o=a(`div`,`wui-chat-message-actions`);n.append(r,i,o);let s={li:n,author:r,body:i,actions:o,head:null,parts:[],copyTimer:null,ratingNote:null};return S.set(e.id,s),s}function re(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?et(t.author,r):null,e.head&&e.li.insertBefore(e.head,e.body)}function ie(e,n,r,i,a,o){let{labels:s}=i;e.li.className=`wui-chat-message wui-chat-message--${n.author.kind.toLowerCase()}`,e.li.toggleAttribute(`data-restored`,n.restored===!0),e.li.toggleAttribute(`data-run-start`,!o||Mr(o)!==Mr(n)),n.streaming?e.li.setAttribute(`aria-busy`,`true`):e.li.removeAttribute(`aria-busy`),e.author.textContent=`${Rr(n,s)}: `,re(e,n,o,s);let c=t.getRenderers(),l=t.getLayoutParts();typeof l==`function`?O(e,n,s,c,l):ee(e,n,s,c),n.streaming?(e.actions.hidden=!0,e.actions.replaceChildren()):ne(e,n,r,i,a)}function ae(t,n){let r=a(`li`,`wui-chat-message wui-chat-message--system wui-chat-message--notice`),i=a(`div`,`wui-chat-notice wui-chat-notice--${t}`,{role:t===`danger`?`alert`:`status`}),o=a(`span`,`wui-chat-notice-icon`,{"aria-hidden":`true`});o.append(e(Ar[t],16));let s=a(`div`,`wui-chat-notice-body`),c=a(`span`,`wui-chat-notice-text`);return c.textContent=n,s.append(c),i.append(o,s),r.append(i),r}function oe(e,t){let n=e.resetsDateTimeUtc?` ${t.dailyLimitRefresh(l(e.resetsDateTimeUtc))}`:``;return ae(`warning`,`${e.message}${n}`)}function se(n,r){let{labels:i}=r,o=n.turnError?.code??``;if(o===`daily_limit`)return oe(n.turnError,i);if(o.endsWith(`feature_off`))return ae(`danger`,n.turnError.message||i.stopped);let s=a(`li`,`wui-chat-message wui-chat-message--system wui-chat-message--error`),c=a(`p`,`wui-chat-error`,{role:`alert`});c.textContent=n.turnError?.message||i.stopped;let l=e(`alert-circle`,16);if(l.setAttribute(`aria-hidden`,`true`),s.append(l,c),n.features.Retry){let e=a(`div`,`wui-chat-message-actions`);e.append(Ir(i.retry,`rotate-ccw`,()=>t.onRetry()).node),s.append(e)}return s}function ce(){return n.closest(`.wui-chat`)}function j(){return n.closest(`.wui-chat-body`)??Nr(n)}function le(e){ce()?.classList.toggle(`wui-chat--scrolled`,e.scrollTop>0),jr(e)&&(_.hidden=!0)}function ue(){y=jr(v),le(v)}function de(e){i.nextElementSibling!==_&&i.parentNode&&i.after(_),e!==v&&(v?.removeEventListener(`scroll`,ue),v=e,e.addEventListener(`scroll`,ue,{passive:!0}),!b&&typeof ResizeObserver==`function`&&(b=new ResizeObserver(()=>{y&&v&&(v.scrollTop=v.scrollHeight)}),b.observe(n)))}g.addEventListener(`click`,()=>{let e=j(),t=w?.context.reduced===!0;e?.scrollTo({top:e.scrollHeight,behavior:t?`auto`:`smooth`}),_.hidden=!0,g.blur()});function fe(e,t){let n=e.messages.at(-1),r=n?`${n.id}|${M(n.parts).length}`:``;if(r===C)return;let i=C===``||e.conversationId!==x;C=r,x=e.conversationId;let a=j();a&&(de(a),i||t||Er.has(n?.author.kind)?(a.scrollTop=a.scrollHeight,_.hidden=!0,y=!0):(_.hidden=!1,y=!1),le(a))}function N(e,r){w={state:e,context:r};let{labels:a}=r;i.setAttribute(`aria-label`,a.thread),g.textContent=a.newMessages??`New messages`;let c=j();c&&de(c);let l=c===null||c.clientHeight===0||jr(c),p=[],_=/* @__PURE__ */ new Set,v=e.messages.filter(e=>!(e.streaming&&e.parts.length===0)),y=v.length>0&&Er.has(v[0].author.kind)&&e.greeting?e.greeting:null;y&&(m.textContent=y,p.push(f)),v.forEach((t,n)=>{let i=A(t);_.add(t.id);let a=v[n-1]??(y?kr:null);ie(i,t,e,r,n===v.length-1,a),p.push(i.li)});for(let e of[...S.keys()])_.has(e)||S.delete(e);for(e.agentTyping&&p.push(tt(e.agentTyping,a)),e.thinking?(clearTimeout(d),d=null,s.classList.remove(`wui-chat-message--leaving`),u=!0,o.update({active:!0,style:r.loaderStyle,steps:e.steps,phrases:r.phrases,intervalMs:r.intervalMs,reduced:r.reduced,announce:r.assistantName?.trim()?a.preparingAnswer(r.assistantName):void 0}),p.push(s)):u&&d===null&&!Fr(r)?(s.classList.add(`wui-chat-message--leaving`),d=setTimeout(()=>{d=null,u=!1,s.classList.remove(`wui-chat-message--leaving`),o.update({active:!1}),w&&N(w.state,w.context)},Or),p.push(s)):d===null?(u=!1,o.update({active:!1})):p.push(s),!e.streaming&&(e.turnError||e.stopped)&&p.push(se(e,r)),mr(h,e,{labels:a,features:e.features,title:Lr(e,a),getState:()=>t.getSession().getState()}),p.push(h),p.forEach((e,t)=>{n.children[t]!==e&&n.insertBefore(e,n.children[t]??null)});n.children.length>p.length;)n.children[p.length].remove();fe(e,l)}function pe(e){return S.get(e)?.li??null}function me(){clearTimeout(d),o.destroy(),v?.removeEventListener(`scroll`,ue),b?.disconnect(),S.clear(),w=null,i.remove()}return{el:i,paint:N,find:pe,destroy:me}}var Br=typeof HTMLElement>`u`?class{}:HTMLElement;function Vr(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 Hr(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 Ur(e,t,n){return t.PanelSwitch!==!0||typeof n!=`function`?null:e===`docked`?`full-page`:e===`full-page`?`docked`:null}var Wr=[`launcher`,`docked`,`full-page`,`embedded`],Gr=[`end`,`start`],Kr={steps:`Steps`,phrases:`Phrases`,orb:`Orb`,skeleton:`Skeleton`},qr={on:`On`,reduced:`Reduced`},Jr=[`auto`,`light`,`dark`],Yr=`wchat:muted`,Xr=6e4,Zr=400,Qr=[`labels`,`pageContext`,`compact`,`open`,`layoutParts`,`getCaptchaToken`,`openAttachment`,`openCitation`,`openTarget`,`openTicket`,`onNavigate`,`resolveLink`,`emptyContent`,`onPanelSwitch`,`preloadPanelSwitch`],$r={...nn};function ei(e,t){if(!s.includes(e))throw Error(`Unknown part kind "${e}". Use one of ${s.join(`, `)}.`);if(typeof t!=`string`||!t.includes(`-`))throw Error(`Renderer tag "${t}" must be a custom element name containing a hyphen.`)}function Z(e,t){return n=>{let r=n.toLowerCase();if(!Object.hasOwn(t,r))throw Error(`<wui-chat ${e}> must be one of ${Object.keys(t).join(`, `)}, got "${n}".`);return t[r]}}function Q(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 ti(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),ni=[[`launcher-style`,`launcher`,`style`,Z(`launcher-style`,{round:`Round`,pill:`Pill`})],[`entrance`,`launcher`,`entrance`,Z(`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`,Z(`idle`,{"float-and-pulse":`FloatAndPulse`,ring:`Ring`,none:`None`})],[`label-reveal`,`launcher`,`labelReveal`,Z(`label-reveal`,{bubble:`Bubble`,expand:`Expand`})],[`compact`,`launcher`,`compact`,ti(`compact`)],[`panel-motion`,`panel`,`motion`,Z(`panel-motion`,{spring:`Spring`,none:`None`})],[`panel-width`,`panel`,`widthPx`,Q(`panel-width`)],[`panel-max-height`,`panel`,`maxHeightPx`,Q(`panel-max-height`)],[`panel-bottom-gap`,`panel`,`bottomGapPx`,Q(`panel-bottom-gap`)],[`phone-max-width`,`phone`,`maxWidthPx`,Q(`phone-max-width`)],[`phone-mode`,`phone`,`mode`,Z(`phone-mode`,{"full-screen":`FullScreen`,sheet:`Sheet`})],[`sheet-height-dvh`,`phone`,`sheetHeightDvh`,Q(`sheet-height-dvh`)],[`sheet-max-height`,`phone`,`sheetMaxHeightPx`,Q(`sheet-max-height`)],[`input-ring`,`input`,`ring`,ti(`input-ring`)],[`send-reveal`,`input`,`sendReveal`,Z(`send-reveal`,{"on-text":`OnText`,always:`Always`})],[`lift-selectors`,`avoid`,`liftSelectors`,$],[`menu-selectors`,`avoid`,`menuSelectors`,$],[`dark-selectors`,`avoid`,`darkSelectors`,$],[`autoopen-busy-selectors`,`avoid`,`autoOpenBusySelectors`,$],[`autoopen-optout-selector`,`avoid`,`autoOpenOptOutSelector`,e=>e]],ri={layout:`launcher`,position:`end`,"offset-x":`24`,"offset-y":`24`,loader:`steps`,motion:`on`,icon:`chat`},ii=[`base`,`layout`,`position`,`offset-x`,`offset-y`,`loader`,`screen`,`motion`,`theme`,`icon`,`narrow`,...ni.map(([e])=>e).filter(e=>e!==`compact`)],ai=e=>e.replace(/-([a-z0-9])/g,(e,t)=>t.toUpperCase());function oi(e){let t={launcher:{},panel:{},phone:{},input:{},avoid:{}};for(let[n,r,i,a]of ni){let o=e.getAttribute(n);o!=null&&(t[r][i]=a(o))}let n=e.getAttribute(`motion`);return le({...t,motion:n==null?void 0:Z(`motion`,qr)(n)})}function si(e){let t=e.getAttribute(`loader`)??`steps`;if(!Object.hasOwn(Kr,t))throw Error(`<wui-chat loader> must be one of ${Object.keys(Kr).join(`, `)}, got "${t}".`);return Kr[t]}function ci(e){let t=e.getAttribute(`narrow`);if(t!=null&&t!==``)return Object.fromEntries($(t).map(e=>[e,!1]))}function li(e){return e===Yr?globalThis.localStorage:globalThis.sessionStorage}var ui={get:e=>li(e).getItem(e),set:(e,t)=>li(e).setItem(e,t)};function di(e){return globalThis.innerWidth<=e.phone.maxWidthPx}function fi(e){let t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)}var pi=0,mi=class extends Br{static get observedAttributes(){return[...ii,`compact`,`open`,`labels`,`page-context`,`narrow`].filter((e,t,n)=>n.indexOf(e)===t)}constructor(){super(),pi+=1,this._uid=`wui-chat-${pi}`,this._built=!1,this._session=null,this._unsubscribe=null,this._voice=null,this._voiceConversationId=void 0,this._shell=null,this._labelsProp=void 0,this._pageContextProp=void 0,this._layoutParts=null,this._renderers={...$r},this._rendererApi={define:(e,t)=>{ei(e,t),this._renderers[e]=t,this._render()},map:this._renderers},this._captchaToken=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 j({...m(this,`labels`),...this._labelsProp})}set labels(e){this._labelsProp=e??void 0,this._render()}get pageContext(){return this._pageContextProp===void 0?m(this,`page-context`):this._pageContextProp}set pageContext(e){this._pageContextProp=e===null?void 0:e}get compact(){return this.hasAttribute(`compact`)}set compact(e){this.toggleAttribute(`compact`,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 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(){if(this._adoptEarlyProperties(),this._assertLayout(),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(),this._session||this._createSession(),this._past||this._createPast(),this._unsubscribe||=this._session.subscribe(()=>this._render()),this._render()}_adoptEarlyProperties(){for(let e of Qr){if(!Object.hasOwn(this,e))continue;let t=this[e];delete this[e],this[e]=t}}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._assertLayout(),this._buildShell();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;if(!Wr.includes(e))throw Error(`<wui-chat layout> must be one of ${Wr.join(`, `)}, got "${e}".`)}_assertPosition(){let e=this.position;if(!Gr.includes(e))throw Error(`<wui-chat position> must be one of ${Gr.join(`, `)}, got "${e}".`)}_isLauncherLike(){return this.layout===`launcher`||this.layout===`docked`}_build(){this._built=!0,this._header=wn({onNew:()=>this.newConversation(),onHistory:()=>this._toggleHistory(),onClose:()=>this.close(),onMute:()=>this._session?.setMuted(!this._session.getState().muted),onSwitch:()=>this._switchPanel(),titleId:`${this._uid}-title`}),this._starters=Qn({onStarter:e=>this._session.submit(e.message),onResume:()=>this._session.resumeLast(),onTicket:e=>{typeof this.openTicket==`function`&&this.openTicket({ticketId:e.ticketId,number:e.number})}}),this._applyEmptyContent(),this._voice=un({getState:()=>this._session.getState(),getLabels:()=>this.labels,getToken:()=>this._session.client.getSpeechToken()}),this._voice.subscribe(()=>this._render()),this._thread=zr({getRenderers:()=>this._renderers,getLayoutParts:()=>this._layoutParts,makeTurnApi:e=>this._makeTurnApi(e),onRetry:()=>this._session.retry(),onRegenerate:()=>this._session.regenerate(),onRate:(e,t)=>this._session.rate(e,t),getSession:()=>this._session,getVoice:()=>this._voice}),this._composer=vn({voice:this._voice,onSubmit:e=>this._session.submit(e),onStop:()=>this._session.stop(),onAttach:e=>this._session.attach(e),onRemove:e=>this._session.removeAttachment(e),onCancelEdit:()=>this._session.cancelEdit(),onTyping:()=>this._session.notifyTyping(),onDraftApplied:()=>this._session.consumeDraft()}),this._footer=Cn(),this._history=En({getClient:()=>this._session.client,getLabels:()=>this.labels,getFeatures:()=>this._session.getState().features,onOpen:e=>{this._session.openConversation(e).catch(()=>{}),this._toggleHistory(!1)},onDeleted:e=>{e===this.conversationId&&this._session.newConversation()}}),this._nudge=Mn({onActivate:()=>this._setOpen(!0,`manual`),onDismiss:()=>{}}),this._status=a(`p`,null,{role:`status`}),this._status.hidden=!0,this._errorEl=a(`p`,`wui-chat-profile-error`,{role:`alert`}),this._errorEl.hidden=!0,this._liveStatus=a(`p`,`wui-chat-live-status`,{role:`status`}),this._liveStatus.hidden=!0,this._talk=a(`button`,`${r(`outline`,`sm`)} wui-chat-handoff-request`,{type:`button`}),this._talk.addEventListener(`click`,()=>this._requestHandoff()),this._liveRetry=a(`button`,r(`ghost`,`sm`),{type:`button`}),this._liveRetry.addEventListener(`click`,()=>this._session.resumeLive()),this._liveError=a(`p`,`wui-chat-live-error`,{role:`alert`}),this._liveError.hidden=!0,this._live=a(`div`,`wui-chat-live`),this._live.append(this._liveStatus,this._talk,this._liveRetry,this._liveError),this._live.hidden=!0,this._body=a(`div`,`wui-chat-body`),this._body.append(this._starters.el,this._thread.el,this._live,this._history.el,this._status,this._errorEl),this._foot=a(`div`,`wui-chat-foot`),this._foot.append(...this._composer.nodes,this._footer.el)}_buildShell(){let e={launcher:Yn,docked:Wn,"full-page":Xn,embedded:Gn};this._shell?.destroy?.(),this._avoid?.destroy(),this._avoid=null,this._autoOpen?.cancel(),this._autoOpen=null,this._lastOpen=!1,this._launcherPlayed=!1;let t=e[this.layout]({id:`${this._uid}-panel`,position:this.position,onToggle:()=>this.toggle()});t.panel.append(this._header.el,this._body,this._foot),t.panel.setAttribute(`aria-labelledby`,`${this._uid}-title`),t.panel.addEventListener(`keydown`,e=>{e.key===`Tab`&&C(t.panel,e)}),t.nudgeHost&&t.nudgeHost.prepend(this._nudge.el),this._shell=t,this.replaceChildren(t.root)}_createSession(){let e=ee(jn(),{base:this.base}),t=ci(this);this._session=te(e,{screen:this.screen||void 0,narrow:t,pageContext:()=>this.pageContext,behaviour:()=>this._session?.getState().features.BehaviourStarters?this._behaviour?.()??null:null,prefs:ui,reducedMotion:()=>this._motion?.reduced??!1,schedule:fi,getCaptchaToken:e=>{if(this._captchaToken)return this._captchaToken(e);let t=this._session?.getState().profile?.captcha?.siteKey;return t?Ln(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=k({client:this._session.client,pageSize:20}),this._past=Nn({list:this._pastList,getLabels:()=>this.labels,getFeatures:()=>this._session.getState().features,onOpen:e=>{this._session.openConversation(e).catch(()=>{})}}),this._starters.pastHost.append(this._past.el)}_disposePast(){this._past&&(this._past.el.remove(),this._past.dispose(),this._pastList.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._session.getState(),t=Ur(this.layout,e.features,this._onPanelSwitchProp);if(t===null)return;t===`full-page`&&this.close();let n={from:this.layout,to:t,conversationId:e.conversationId,draft:this._composer.getDraft()};x(()=>this._onPanelSwitchProp(n),{target:t,reduced:this._motion?.reduced===!0}).then(()=>document.querySelector(`.wui-chat--${t} .wui-chat-input`)?.focus()).catch(e=>globalThis.reportError?.(e))}async _requestHandoff(){this._requesting=!0,this._liveError.hidden=!0,this._render();try{await this._session.requestHandoff()}catch(e){this._liveError.textContent=e?.message||this.labels.errorGeneric,this._liveError.hidden=!1}finally{this._requesting=!1,this._render()}}_paintLive(e,t,n){let r=e.live===`Lost`,i=Hr(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._session.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._session,{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._session.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),Xr)}).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._voice.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=oi(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`),d=Ur(this.layout,i,this._onPanelSwitchProp),f=e.streaming||e.thinking;this._header.paint({labels:t,title:n.assistant.name,tagline:n.assistant.tagline,status:Vr(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}),this._starters.el.hidden=!c||l,c&&this._starters.paint({labels:t,greeting:e.greeting,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:si(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}),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=S(n,t.experience),this._motion.subscribe(()=>this._render())),i.Sounds&&!this._sound&&(this._sound=c(t.experience.sound,ui)),!i.Sounds&&this._sound&&(this._sound=null),i.BehaviourStarters&&!this._behaviour&&(this._behaviour=d(t.start.behaviour?.servicePathPrefixes??[]));let a=this._isLauncherLike();a&&!this._avoid&&this.layout===`launcher`&&(this._avoid=b(n.avoid,t.experience.launcher,this._shell.nudgeHost)),this.layout===`launcher`&&i.AutoOpen&&!this._autoOpen&&(this._autoOpen=_(t.experience.autoOpen,n,{open:()=>this._setOpen(!0,`auto`),isOpen:()=>this._session.getState().open,panelRect:()=>this._shell.panel.getBoundingClientRect()}));let o=di(n);this._shell.setLabels(r),this._shell.setAppearance({position:this.position,offsetX:this.hasAttribute(`offset-x`)?Q(`offset-x`)(this.getAttribute(`offset-x`)):void 0,offsetY:this.hasAttribute(`offset-y`)?Q(`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,theme:Jr.includes(this.getAttribute(`theme`))?this.getAttribute(`theme`):`auto`,icon:this.icon,launcherStyle:n.launcher.style,compact:n.launcher.compact,labelReveal:n.launcher.labelReveal,entrance:n.launcher.entrance,idle:n.launcher.idle,phone:o,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`,a&&di(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=ue(t,n);e&&(this._nudge.schedule({text:e.text,delaySeconds:e.delaySeconds,label:r.nudgeDismiss}),this._nudgeArmed=!0)}}}_onOpenChange(e){let t=di(oi(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;try{this._preloadPanelSwitchProp()?.catch?.(()=>{})}catch{}}if(t){let e=oi(this);this._phone={fit:v(this._shell.panel,e),unlock:y(this._thread.el)}}else this._openTrigger===`manual`&&(this._focusTimer=setTimeout(()=>{this._focusTimer=null,this._composer.focus()},Zr))}else document.removeEventListener(`keydown`,this._onKeyDown),clearTimeout(this._focusTimer),this._focusTimer=null,this._phone?.fit.destroy(),this._phone?.unlock(),this._phone=null,this._historyShown&&(this._historyShown=!1,this._history.hide(),this._render()),g(this._shell.launcherButton)}_syncConversation(e){let t=this.getAttribute(`conversation-id`);t&&t!==this._openedConversation&&!e.loading&&(this._openedConversation=t,e.conversationId!==t&&this._session.openConversation(t).catch(()=>{}))}_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._session.getState().profile;e?.experience.sound.vibrate&&u(e.experience.sound.vibrateMs,this._sound.isMuted())}}};Object.defineProperty(mi.prototype,"layout",{get(){return this.getAttribute(`layout`)??ri.layout},set(e){this.setAttribute(`layout`,String(e))}});for(let e of ii)e!==`layout`&&Object.defineProperty(mi.prototype,ai(e),{configurable:!0,get(){return this.getAttribute(e)??ri[e]??``},set(t){t==null?this.removeAttribute(e):this.setAttribute(e,String(t))}});function hi(){typeof customElements<`u`&&!customElements.get(`wui-chat`)&&customElements.define(`wui-chat`,mi)}hi();export{mi as WuiChat,jn as createFetchChatHttp,nn as defaultRenderers,hi as defineChat};
|
|
1
|
+
import{A as e,D as t,E as n,N as r,O as i,S as a,T as o,_ as s,a as c,b as l,c as u,d,f,h as p,j as m,k as h,l as g,m as _,n as v,o as y,p as b,r as x,s as S,v as C,w,x as T,y as E}from"./web-Dkz2jgyc.js";import{CHAT_HANDOFF_REQUEST_ID as D,buildTranscript as O,createChatClient as ee,createChatSession as k,createConversationList as te,createTurnApi as ne,formatChatDate as A,formatChatValue as re,formatClipTime as ie,formatFigure as ae,formatFileSize as oe,isHandoffTarget as se,loaderView as ce,mergeLabels as le,mergeLook as j,messagePlainText as M,resolveNudge as ue,showsCaptchaNote as N,sniffAudioType as de,toFigureRuns as P,toFigureText as fe,transcriptToText as pe,voiceClipBars as me}from"@webority/chat-core";import{linkTarget as he,parseInline as ge}from"@webority/markdown-core";import{COPY_FEEDBACK_MS as _e,EMPTY_VALUE as ve,copyTextToClipboard as ye,formatNumber as be,glyphSvg as xe}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 Se=typeof HTMLElement>`u`?class{}:HTMLElement,F=class extends Se{#e=null;#t=null;#n=null;#r=!1;get part(){return this.#e}set part(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()}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(){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 Ce(e,t,n){let r=xe(t,{size:n});if(!r)return null;let i=new DOMParser().parseFromString(r,`text/html`);return e.importNode(i.body.firstElementChild,!0)}var we={Confirmed:`actionConfirmed`,Rejected:`actionRejected`,Expired:`actionExpired`,Failed:`actionFailed`},Te=/^https?:\/\//i,Ee={strong:`strong`,em:`em`,strike:`s`};function R(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r}function De(e,t){return{id:e,label:t,action:`Send`,target:null,navigateAfterMs:null,icon:null,variant:null}}function Oe(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(Te.test(n.href)){let t=R(`a`);t.href=n.href,t.target=`_blank`,t.rel=`noopener noreferrer`,Oe(t,n.children),e.append(t)}else Oe(e,n.children)}else if(n.type in Ee){let t=R(Ee[n.type]);Oe(t,n.children),e.append(t)}else n.type===`code`&&e.append(R(`code`,null,n.text))}function ke(e){let t=R(`p`,`wui-chat-action-consent`);return Oe(t,ge(e)),t}function Ae(e){let t=R(`ul`,`wui-chat-action-lines`);for(let n of e)t.append(R(`li`,null,n));return t}function je(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}I(`wui-chat-part-action`,class extends F{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){this.replaceChildren(this._view()),e===`first`?this.querySelector(`[role="menuitem"]`)?.focus():e===`edit`&&this.querySelector(`.wui-chat-action-edit`)?.focus()}async _run(e){let t=this._part.actionId;this._working=e,this._error=null,this._paint();try{e===`confirm`?await this._turn.confirmAction(t):await this._turn.rejectAction(t),this._working=null}catch(e){if(this._part.actionId!==t)return;this._working=null,this._error=e?.message||this._turn.labels.actionFailed,this._paint()}}_view(){let{part:e,turn:t}=this,n=t.labels,r=e.state===`Pending`,i=t.features.LeadRecap&&e.actionKind===`ChatLeadCapture`,a=i&&e.editFields?.length>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?je(e.lines):Ae(e.lines)),i&&e.consentText&&o.append(ke(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)),a&&this._menuOpen&&o.append(this._menu(e.editFields,n)),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(A(e.decidedDateTimeUtc)):t.actionDone;else if(e.state===`Done`){if(n.append(t.actionDone),e.decidedDateTimeUtc){let t=R(`time`,null,A(e.decidedDateTimeUtc));t.dateTime=e.decidedDateTimeUtc,n.append(` `,t)}}else n.textContent=t[we[e.state]]??``;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){let n=R(`ul`,`list-group wui-chat-action-menu`);n.setAttribute(`role`,`menu`),n.setAttribute(`aria-label`,t.editSomething),n.addEventListener(`keydown`,e=>this._onMenuKey(e));for(let t of e){let e=R(`li`);e.setAttribute(`role`,`none`);let r=R(`button`,`list-group-item list-group-item-action wui-chat-action-menu-item`,t.label);r.type=`button`,r.setAttribute(`role`,`menuitem`),r.addEventListener(`click`,()=>{this._menuOpen=!1,this._turn.chooseQuickReply(De(`lead.edit:${t.id}`,t.label)),this._paint(`edit`)}),e.append(r),n.append(e)}return n}_onMenuKey(e){if(e.key===`Escape`){e.preventDefault(),this._menuOpen=!1,this._paint(`edit`);return}let t=[...e.currentTarget.querySelectorAll(`[role="menuitem"]`)],n=t.indexOf(document.activeElement),r=t.length-1,i={ArrowDown:n<r?n+1:0,ArrowUp:n>0?n-1:r,Home:0,End:r};e.key in i&&(e.preventDefault(),t[i[e.key]].focus())}});var Me=null;async function Ne(){await import(`@webority/ui-elements/chart`),await customElements.whenDefined(`wui-chart`)}async function Pe(){return Me??=Ne().catch(e=>{throw Me=null,e}),Me}var Fe={sub:`wui-chat-sub`,sup:`wui-chat-sup`};function z(e,t){let n=e.ownerDocument;for(let r of t){if(Fe[r.kind]===void 0){e.append(n.createTextNode(r.text));continue}let t=n.createElement(r.kind);t.className=Fe[r.kind],t.textContent=r.text,e.append(t)}}function B(e,t){e.replaceChildren(),z(e,P(String(t??``)))}function V(e){return fe(String(e??``))}function Ie(e){return ae(e)}var Le=8,Re={Bar:`column`,Line:`line`,Donut:`donut`};function ze(e,t){return e===`Bar`&&t>4?300:240}function Be(e,t){let n=e.chartType===`Donut`,r=n?e.series.slice(0,1):e.series.slice(0,Le),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);o.has(e)||o.set(e,{label:V(e),...a}),o.get(e)[`s${t}`]=n.value}});let s=[...o.values()],c={type:Re[e.chartType],title:V(e.title)||t.chart,x:{key:`label`,kind:`category`},series:i,data:s,height:ze(e.chartType,s.length)};return!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=!1;#r=null;#i=null;#a=null;#o=null;#s=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;if(this.#r||(this.#r=L(a,`figure`,`wui-chat-chart`),this.#a=L(a,`div`,`wui-chat-chart-body`),this.#r.append(this.#a),this.replaceChildren(this.#r)),this.#i?.remove(),this.#i=null,e.title&&(this.#i=L(a,`figcaption`,`wui-chat-chart-title`),B(this.#i,e.title),this.#r.prepend(this.#i)),this.#n){let t=Be(e,n.labels);this.#o.spec=t,this.#c(t.state!==`empty`,n.labels)}else Pe().then(()=>{if(i!==this.#t||!this.isConnected)return;let t=Be(e,n.labels);this.#o=a.createElement(`wui-chart`),this.#o.spec=t,this.#n=!0,this.#a.replaceChildren(this.#o),this.#c(t.state!==`empty`,n.labels)},()=>{i===this.#t&&this.isConnected&&this.#u(n.labels)})}disposePart(){this.#t+=1,this.#e=null}#c(e,t){if(!e){this.#s?.remove(),this.#s=null;return}this.#s||(this.#s=L(this.ownerDocument,`button`,`btn btn-link btn-sm wui-chat-chart-toggle`),this.#s.type=`button`,this.#s.addEventListener(`click`,()=>this.#l()),this.#r.append(this.#s));let n=this.#o.getAttribute(`view`)===`table`;this.#s.setAttribute(`aria-pressed`,String(n)),this.#s.textContent=n?t.chartShowChart:t.chartShowTable}#l(){let e=this.#o.getAttribute(`view`)!==`table`;this.#o.setAttribute(`view`,e?`table`:`chart`),this.#c(!0,this.turn.labels)}#u(e){let t=L(this.ownerDocument,`p`,`wui-chat-chart-error`,e.chartLoadFailed);t.setAttribute(`role`,`status`),this.#a.replaceChildren(t),this.#s?.remove(),this.#s=null}});var Ve={Positive:`wui-metric-tone-success`,Caution:`wui-metric-tone-warning`,Negative:`wui-metric-tone-danger`},He=/* @__PURE__ */ new Set([`Positive`,`Caution`,`Negative`]),Ue=.001;function We(e,t,n){let r=Ve[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)<Ue?Ie(t.value):[{kind:`text`,text:be(t.value)}]),t.unit){let n=L(e,`span`,`wui-chat-figure-unit`);B(n,t.unit),n.prepend(` `),o.append(n)}return He.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,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(We(i,t,n.labels));a.append(o),this.replaceChildren(a)}}),I(`wui-chat-part-file`,class extends F{renderPart(e,t,n){let r=typeof n.openAttachment==`function`,i=document.createElement(r?`button`:`span`);i.className=`wui-chat-file-chip`,r&&(i.type=`button`,i.setAttribute(`aria-label`,n.labels.fileOpen(e.fileName)),i.addEventListener(`click`,()=>n.openAttachment(e)));let a=Ce(document,`document-text`,16),o=document.createElement(`span`);o.className=`wui-chat-file-name`,o.textContent=e.fileName;let s=document.createElement(`span`);s.className=`wui-chat-file-size`,s.textContent=oe(e.length),i.append(...[a,o,s].filter(Boolean));let c=document.createElement(`div`);c.className=`wui-chat-file`,c.append(i),this.replaceChildren(c)}});var Ge={Open:`info`,InProgress:`info`,WaitingOnCustomer:`warning`,Resolved:`success`,Closed:`neutral`,Cancelled:`neutral`},Ke=/^\/[/\\]/,qe=/^https?:\/\//i,Je=/[\t\r\n]/g;function Ye(e){return typeof e==`string`&&e.trim()!==``}function Xe(e){return e.replace(Je,``)}function Ze(e){if(typeof e!=`string`)return!1;let t=Xe(e);return t.startsWith(`/`)?!Ke.test(t):qe.test(t)}function Qe(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 $e(e,n){let r=Qe(Ye(e?.displayName)?e.displayName:n),i=t(`span`,`wui-chat-avatar`,{"aria-hidden":`true`}),a=typeof e?.avatarUrl==`string`?Xe(e.avatarUrl):null;if(Ze(a)){let e=t(`img`,null,{alt:``,src:a,loading:`lazy`});e.addEventListener(`error`,()=>{i.textContent=r}),i.append(e)}else i.textContent=r;return i}function et(e,n){let r=t(`div`,`wui-chat-agent-head`),i=t(`span`,`wui-chat-agent-name`);i.textContent=Ye(e?.displayName)?e.displayName:n.agent;let a=t(`span`,`wui-chat-agent-role wui-chat-agent-tag`);return a.textContent=n.agent,r.append($e(e,n.agent),i,a),r}function tt(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(Ye(r)?r:n.agent),i.append(et({kind:`Agent`,displayName:r,avatarUrl:null},n),a,o),i}function nt(e){return Object.hasOwn(Ge,e)?Ge[e]:null}function rt(e,t){return nt(e)===null?``:t.ticketStatus(e)}var it=/* @__PURE__ */ new Set([`Requested`,`Waiting`]),at=/* @__PURE__ */ new Set([`Requested`,`Waiting`,`Joined`]),ot=at;function st(e,t){let n=e?.displayName;return typeof n==`string`&&n.trim()!==``?n:t.handoffAgentFallback}function ct(){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 lt(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 ut(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)),[ct(),e]}let r=t(`span`,`wui-chat-handoff-position`,{"aria-hidden":`true`});return r.textContent=String(e.queuePosition),[r,lt(n.handoffQueued(e.queuePosition),n.handoffQueuedText)]}function dt(e,n){let r=st(e.agent,n),i=t(`span`,`wui-chat-handoff-agent`);return i.append($e(e.agent,n.handoffAgentFallback),t(`span`,`wui-chat-handoff-online`,{"aria-hidden":`true`})),[i,lt(n.handoffJoined(r),n.handoffJoinedText(r))]}function ft(e,t){switch(e.state){case`Requested`:return[ct(),H(`p`,`wui-chat-handoff-text`,t.handoffRequested)];case`Waiting`:return ut(e,t);case`Joined`:return dt(e,t);case`Left`:return[lt(t.handoffLeft(st(e.agent,t)),t.handoffLeftText)];case`Ended`:return[lt(t.handoffEnded,t.handoffEndedText)];default:return null}}I(`wui-chat-part-handoff`,class extends F{constructor(){super(),this._signature=null}renderPart(e,n,r){let i=r.isLast,a=r.handoffSettled===!0&&it.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=ft(e,r.labels);if(s===null){this.replaceChildren();return}let c=t(`div`,`wui-chat-handoff wui-chat-handoff--${e.state.toLowerCase()}`);if(i&&it.has(e.state)&&c.classList.add(`wui-chat-handoff--live`),i&&at.has(e.state)&&c.setAttribute(`role`,`status`),ot.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,i=L(r,`figure`,`wui-chat-image`);this.#n=L(r,`div`,`wui-chat-image-frame`),Number.isFinite(e.width)&&Number.isFinite(e.height)&&e.width>0&&e.height>0&&(this.#n.style.aspectRatio=`${e.width} / ${e.height}`),i.append(this.#n),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,i=L(r,`div`,`wui-chat-image-skeleton`);i.setAttribute(`aria-hidden`,`true`);let a=L(r,`span`,`visually-hidden`,t.labels.imageLoading);a.setAttribute(`role`,`status`),this.#n.replaceChildren(i,a),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.ownerDocument,i=V(t.alt),a=r.createElement(`wui-lightbox`);a.setAttribute(`label`,n.labels.imageViewer);let o=L(r,`a`,`wui-lightbox-item`);o.setAttribute(`href`,e),o.dataset.caption=i,o.dataset.name=i;let s=r.createElement(`img`);s.src=e,s.alt=i,s.decoding=`async`,o.append(s),a.append(o),this.#n.replaceChildren(a)}#a(e,t){let n=this.ownerDocument,r=L(n,`p`,`wui-chat-image-error`,t.labels.imageFailed);r.setAttribute(`role`,`status`);let i=L(n,`button`,`btn btn-soft-primary btn-sm`,t.labels.retry);i.type=`button`,i.addEventListener(`click`,()=>this.#r(e,t)),this.#n.replaceChildren(r,i)}});var pt={ActionLimitReached:`warning`,ConversationTooLong:`warning`,AssistantUnavailable:`danger`},mt={info:`info`,warning:`alert-triangle`,danger:`alert-circle`};I(`wui-chat-part-notice`,class extends F{renderPart(e){let t=this.ownerDocument,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=Ce(t,mt[n],16);a&&i.append(a);let o=L(t,`div`,`wui-chat-notice-body`);if(o.append(L(t,`span`,`wui-chat-notice-text`,e.text)),e.action){let n=L(t,`button`,`wui-chat-notice-action`,e.action.label);n.type=`button`,n.addEventListener(`click`,()=>e.action.run()),o.append(n)}r.append(i,o),this.replaceChildren(r)}});var ht=/* @__PURE__ */ new Set([`Email`,`Phone`,`Name`,`Company`,`Text`,`LongText`,`Choice`,`MultiChoice`,`TimeSlot`,`File`,`Consent`]),gt={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}},_t=[`Open`,`Answered`,`Skipped`,`Expired`],vt=0;function U(e){return vt+=1,`${e}-${vt}`}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 yt(e,t){let n=U(`wui-chat-field`),r=gt[e.type],i=e.type===`LongText`&&!e.secret,a=W(i?`textarea`:`input`,`form-control wui-chat-input-control`);i?a.rows=3:(a.type=e.secret?`password`:r.type,e.secret?a.autocomplete=`off`:r.autocomplete&&(a.autocomplete=r.autocomplete)),a.id=n,a.name=e.key,e.placeholder!=null&&(a.placeholder=e.placeholder),e.maxLength!=null&&(a.maxLength=e.maxLength),e.required&&a.setAttribute(`aria-required`,`true`);let o=W(`label`,`form-label`,e.label);o.htmlFor=n;let s=G();a.setAttribute(`aria-describedby`,s.id);let c=W(`div`,`wui-chat-field`);return c.dataset.key=e.key,c.append(o,...K(e,t),a,s),{field:e,element:c,controls:[a],focus:a,invalid:a,error:s,read:()=>e.secret?a.value:a.value.trim()}}function bt(e,t,n,r,i){let a=e.controls[0],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 xt(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 St(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 Ct(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 wt(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`);l.type=`button`,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 Tt(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 Et(e,t,n,r){if(e.type===`Choice`)return xt(e,t);if(e.type===`MultiChoice`)return St(e,t);if(e.type===`TimeSlot`)return Ct(e,t);if(e.type===`File`)return wt(e,t,n);if(e.type===`Consent`)return Tt(e);let i=yt(e,t);return e.verify===`Otp`?bt(i,e,t,n,r):i}function Dt(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 Ot(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)}function kt(e){return{kind:`Notice`,code:`NeedsNewerApp`,text:e.needsNewerApp}}I(`wui-chat-part-input-request`,class extends F{constructor(){super(),this._signature=null,this._turn=null,this._notice=null,this._generation=0}renderPart(e,t,n){this._turn=n;for(let t of _t)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._notice&&(this._notice.message=t,this._notice.turn=n,this._notice.part=kt(n.labels)):(this._signature=r,this._generation+=1,this._notice=null,this.replaceChildren(this._content(e,t,n)))}_content(e,t,n){if(e.state!==`Open`)return Ot(e,n.labels);if(e.fields.some(e=>!ht.has(e.type))){let e=document.createElement(`wui-chat-part-notice`);return e.message=t,e.turn=n,e.part=kt(n.labels),this._notice=e,e}return this._form(e,this._generation)}_form(e,t){let n=this._turn.labels,r=this._turn.features,i=W(`form`,`wui-chat-input-form`);i.noValidate=!0,i.setAttribute(`aria-label`,e.title||e.submitLabel),e.title&&i.append(W(`h3`,`wui-chat-input-title`,e.title));let a=e.fields.map(t=>Et(t,n,this._turn,e.requestId));for(let e of a)i.append(e.element);let o=W(`p`,`wui-chat-input-error`);o.setAttribute(`role`,`status`),o.hidden=!0,i.append(o);let s=W(`button`,`btn btn-primary`,e.submitLabel);s.type=`submit`,s.dataset.wui=`AppButton`;let c=W(`div`,`d-flex flex-wrap gap-2`);c.append(s);let l=[s];if(r.LeadShortcuts&&e.fields.length===1&&!e.fields[0].required){let t=W(`button`,`btn btn-soft-primary`,n.skip);t.type=`button`,t.dataset.wui=`AppButton`,t.addEventListener(`click`,()=>this._turn.skipInput(e.requestId)),c.append(t),l.push(t)}if(r.LeadShortcuts&&e.cancellable){let e=W(`button`,`btn btn-link`,n.cancel);e.type=`button`,e.addEventListener(`click`,()=>this._turn.cancelLead()),c.append(e),l.push(e)}i.append(c),e.allowTyped&&i.append(W(`p`,`wui-chat-input-typed`,n.typeAnswer));let u=!1,d=t=>{for(let e of a)for(let n of e.controls)n.disabled=t;for(let e of l)e.disabled=t;s.textContent=t?n.inputSubmitting:e.submitLabel},f=()=>{for(let e of a)e.error.hidden=!0,e.error.textContent=``,e.invalid.removeAttribute(`aria-invalid`);o.hidden=!0,o.textContent=``},p=(e,t)=>{e.error.textContent=t,e.error.hidden=!1,e.invalid.setAttribute(`aria-invalid`,`true`)};return i.addEventListener(`submit`,async r=>{if(r.preventDefault(),u)return;f();let i={},c={},l=[];for(let e of a){let t=e.read();i[e.field.key]=t,e.codeRead&&(c[e.field.key]=e.codeRead());let r=Dt(e,t,n);r&&l.push([e,r])}if(l.length>0){for(let[e,t]of l)p(e,t);l[0][0].focus.focus();return}u=!0,d(!0);let m;try{m=await this._turn.answerInput(e.requestId,i,Object.keys(c).length>0?c:null)}catch{m={ok:!1,errors:{},message:n.errorGeneric}}if(t!==this._generation||m.ok)return;u=!1;let h=null;for(let e of a){let t=m.errors?.[e.field.key];t&&(p(e,t),h??=e)}m.message!=null&&(o.textContent=m.message,o.hidden=!1),d(!1),h?h.focus.focus():a[0]?a[0].focus.focus():s.focus()}),i}});var At={Primary:`wui-chat-quick-reply--primary`,Cta:`wui-chat-quick-reply--cta`};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||(this.#e=s,this.replaceChildren(),!r))return;let c=this.ownerDocument,l=e.placement===`Composer`,u=L(c,`div`,l?`wui-chat-quick-replies wui-chat-quick-replies--composer`:`wui-chat-quick-replies`);u.setAttribute(`role`,`group`),u.setAttribute(`aria-label`,n.labels.quickReplies);let d=l?null:e.replies.find(e=>e.id===D&&e.action===`Send`),f=0;d&&(u.classList.add(`wui-chat-quick-replies--offer`),u.append(this.#t(c,d,n)),f+=1);for(let t of e.replies){if(t===d||t.action===`Open`&&(!t.target||!i))continue;let e=null;if(t.action===`Navigate`){if(n.features.LinkHandoff!==!0)continue;if(se(t.target,n.handoffHosts))e=t.target;else{let r=n.resolveLink?.(t.target);e=typeof r==`string`&&r!==``?r:null}if(e===null){u.append(L(c,`span`,null,t.label));continue}if(!a)continue}u.append(this.#n(c,t,f,n,d?`wui-chat-quick-reply--quiet`:``,e)),f+=1}if(o){let e=L(c,`span`,`visually-hidden`,n.labels.handoffMoment);e.setAttribute(`role`,`status`),u.append(e)}u.childElementCount>0&&this.append(u)}#t(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.#n(e,{...t,variant:`Primary`},0,n,`wui-chat-offer-action`)),r}#n(e,t,n,r,i=``,a=null){let o=e.createElement(`button`);o.type=`button`,o.className=[`wui-chat-quick-reply`,At[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=Ce(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`,()=>{t.action===`Open`?this.turn.openTarget(t.target):s?this.turn.beginHandoff(t,()=>this.#r(a)):(this.turn.chooseQuickReply(t),this.closest(`.wui-chat`)?.querySelector(`.wui-chat-input`)?.focus())}),o}#r(e){typeof this.turn.openTarget==`function`?this.turn.openTarget(e):globalThis.location.assign(e)}});var jt=/* @__PURE__ */ new Set([`Integer`,`Decimal`,`MoneyMinor`,`Percent`]);function Mt(e){return jt.has(e)}function Nt(e,t,n,r=!0){let i=e=>r?P(e):[{kind:`text`,text:e}];if(t==null||t===``)return[{kind:`text`,text:ve}];if(e===`Date`||e===`DateTimeUtc`)return[{kind:`text`,text:re(t,e,n)}];if(Mt(e)){let r=Number(t);return i(Number.isFinite(r)?re(r,e,n):String(t))}return i(String(t))}var Pt=0;function Ft(e){return Pt+=1,`${e}-${Pt}`}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=Ft(`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`);Mt(n.type)&&(a.className=`wui-chat-num`),z(a,Nt(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`,()=>this.turn.openRecord(e)),s.append(t)}this.replaceChildren(s)}});var It=/^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;return typeof t.url==`string`&&It.test(t.url)?(r=L(e,`a`,`wui-chat-source`),r.setAttribute(`href`,t.url),r.setAttribute(`target`,`_blank`),r.setAttribute(`rel`,`noopener noreferrer`),r.setAttribute(`aria-label`,n.labels.openSource(t.title))):(r=L(e,`span`,`wui-chat-source`),r.tabIndex=-1),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 Lt=25,Rt=0;function zt(e,t,n){let r=e.createElement(`tr`);for(let i of t.columns){let t=e.createElement(`th`);t.setAttribute(`scope`,`col`),Mt(i.type)&&(t.className=`wui-chat-num`),n?B(t,i.label):t.textContent=String(i.label??``),r.append(t)}return r}function Bt(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`),Mt(a.type)&&(c.className=`wui-chat-num`);let l=n[o];l==null||l===``?c.append(L(c.ownerDocument,`span`,`wui-chat-null`,ve)):z(c,Nt(a.type,l,t.currency,r)),i.append(c)}),i}function Vt(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 Ht(e,t,n,r,i){let a=e.ownerDocument;for(let o=n;o<r;o+=1)e.append(Bt(a,t,t.rows[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){Rt+=1,s=`wui-chat-table-${Rt}`;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(zt(a,e,r));let d=a.createElement(`tbody`);Ht(d,e,0,Math.min(e.rows.length,Lt),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),Vt(f,c),e.rows.length>Lt){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`,()=>{Ht(d,e,Lt,e.rows.length,r),t.remove()}),o.append(t)}this.replaceChildren(o)}});var Ut=/* @__PURE__ */ new Set([`Visitor`,`Customer`]),Wt=/^\d+$/,Gt=`pre, code, .wui-markdown-source`;function Kt(e,t){return e?.features?.Sources===!0?typeof e?.isCitation==`function`?e.isCitation(t):Wt.test(t):!1}function qt(e,t){if(se(e,t?.handoffHosts))return e;let n=t?.resolveLink?.(e);return typeof n==`string`&&n!==``?n:null}function Jt(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),he(i,`web`,void 0,n)?.kind===`web`?(r.setAttribute(`target`,`_blank`),r.setAttribute(`rel`,`noopener noreferrer`)):(r.removeAttribute(`target`),r.removeAttribute(`rel`)))}}function Yt(e){let t=e.ownerDocument,n=t.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=[];for(let e=n.nextNode();e;e=n.nextNode())e.parentElement?.closest(Gt)||r.push(e);for(let e of r){let n=P(e.nodeValue);if(n.length===1&&n[0].kind===`text`)continue;let r=t.createDocumentFragment();z(r,n),e.replaceWith(r)}}function Xt(e){let t=e.turn;Jt(e,t),t?.features?.FigureText===!0&&Yt(e)}I(`wui-chat-part-text`,class extends F{#e=null;#t=null;#n=null;#r=null;#i=!1;#a=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.#s(e))}renderPart(e,t){let n=Ut.has(t.author.kind)?`plain`:`markdown`;if(n!==this.#e&&(this.#e=n,this.#r=null,this.#t=n===`plain`?this.#c():this.#l(e.text),this.#n=n===`plain`?null:this.#t.firstElementChild,this.replaceChildren(this.#t)),n===`plain`){let t=this.turn?.features?.FigureText===!0,n=JSON.stringify([e.text,t]);n!==this.#r&&(this.#r=n,this.#t.replaceChildren(),t?z(this.#t,P(e.text)):this.#t.append(this.ownerDocument.createTextNode(e.text)))}else this.#n.textContent!==e.text&&(this.#n.textContent=e.text);this.toggleAttribute(`data-streaming`,t.streaming===!0),this.#i||(this.#i=!0,this.closest(`[data-restored]`)||this.classList.add(`wui-chat-part-enter`)),this.#o()}disposePart(){this.#a?.disconnect(),this.#a=null}#o(){this.#a||(this.#a=new MutationObserver(()=>Xt(this)),this.#a.observe(this,{childList:!0,subtree:!0,characterData:!0}),Xt(this))}#s(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)))}#c(){return L(this.ownerDocument,`div`,`wui-chat-bubble`)}#l(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=>Kt(this.turn,e);let r=L(t,`pre`,`wui-markdown-source`,e);return n.append(r),n}}),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=nt(e.status);if(c!==null){let n=t(`span`,`wui-chat-ticket-badge wui-chat-ticket-badge--${c}`);n.textContent=rt(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`,()=>r.openTicket({ticketId:e.ticketId,number:e.number})),n.append(o),a.append(n)}this.replaceChildren(a)}});var Zt=`http://www.w3.org/2000/svg`,Qt={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 $t(e,t=18){if(!Object.hasOwn(Qt,e))throw Error(`Unknown voice icon "${e}".`);let n=document.createElementNS(Zt,`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(Zt,`path`);return r.setAttribute(`d`,Qt[e]),n.append(r),n}var en=40,q=null,tn=class extends F{#e=null;#t=null;#n=null;#r=null;#i=null;#a=null;#o=null;#s=null;#c=!1;#l=null;#u=0;#d=0;#f=!1;#p=null;#m=null;#h=null;#g=0;#_=!1;renderPart(e,t,n){this.#e=n,n.features.VoiceClips?(this.#t===null&&this.#y(),e.attachmentId!==this.#l&&(this.disposePart(),this.#l=e.attachmentId,this.#d=0,this.#n.replaceChildren(...me(e.attachmentId,en).map(nn))),this.#u=e.durationMs,this.#b(e)):this.#v(e.transcript)}disposePart(){this.#g+=1,this.#p?.pause(),this.#h!==null&&URL.revokeObjectURL(this.#h),q===this&&(q=null),this.#p=null,this.#m=null,this.#h=null,this.#f=!1}#v(e){if(this.disposePart(),this.#t=null,this.#l=null,this.#o=null,this.#s=null,typeof e==`string`&&e!==``){let t=L(document,`p`,`wui-chat-clip-transcript`);t.textContent=e,this.replaceChildren(t)}else this.replaceChildren()}#y(){this.#t=L(document,`div`,`wui-chat-clip`),this.#t.setAttribute(`role`,`group`);let e=L(document,`div`,`wui-chat-clip-row`);this.#r=L(document,`button`,`wui-chat-clip-play`),this.#r.type=`button`,this.#r.addEventListener(`click`,()=>this.#A()),this.#n=L(document,`div`,`wui-chat-clip-wave`),this.#n.setAttribute(`aria-hidden`,`true`),this.#i=L(document,`span`,`wui-chat-clip-time`),e.append(this.#r,this.#n,this.#i),this.#a=L(document,`p`,`wui-chat-clip-error`),this.#a.setAttribute(`role`,`status`),this.#a.hidden=!0,this.#t.append(e,this.#a),this.replaceChildren(this.#t)}#b(e){let t=this.#e.labels;this.#t.setAttribute(`aria-label`,t.voiceClip),this.#r.disabled=this.#_||typeof this.#e.readAttachment!=`function`,this.#x(),this.#S(),this.#C(e.transcript)}#x(){let e=this.#e.labels,t=this.#f?e.voiceClipPause:e.voiceClipPlay;this.#r.setAttribute(`aria-label`,t),this.#r.title=t,this.#r.replaceChildren($t(this.#f?`pause`:`play`,18))}#S(){let e=this.#u/1e3,t=e>0?Math.min(1,this.#d/e):0,n=Math.floor(t*en);[...this.#n.children].forEach((e,t)=>{e.classList.toggle(`wui-chat-clip-bar--played`,t<n)});let r=ie(Math.max(1,Math.round(e)));this.#i.textContent=this.#e.labels.voiceClipTime(ie(this.#d),r)}#C(e){typeof e!=`string`||e===``?(this.#o?.remove(),this.#s?.remove(),this.#o=null,this.#s=null):(this.#o===null&&(this.#o=L(document,`button`,`wui-chat-clip-toggle`),this.#o.type=`button`,this.#o.addEventListener(`click`,()=>{this.#c=!this.#c,this.#s.hidden=!this.#c,this.#w()}),this.#s=L(document,`p`,`wui-chat-clip-transcript`),this.#s.hidden=!this.#c,this.#t.append(this.#o,this.#s)),this.#s.textContent=e,this.#w())}#w(){let e=this.#e.labels;this.#o.setAttribute(`aria-expanded`,String(this.#c)),this.#o.textContent=this.#c?e.voiceClipHideTranscript:e.voiceClipShowTranscript}#T(){return this.#m??=this.#E().catch(e=>{throw this.#m=null,e}),this.#m}async#E(){let e=this.#g,t=await this.#e.readAttachment(this.#l),n=URL.createObjectURL(new Blob([t],{type:de(t)}));if(e!==this.#g)return URL.revokeObjectURL(n),null;this.#h!==null&&URL.revokeObjectURL(this.#h),this.#h=n;let r=new Audio(this.#h);return r.addEventListener(`timeupdate`,()=>{this.#d=r.currentTime,this.#S()}),r.addEventListener(`ended`,()=>{this.#d=0,this.#D(),this.#S()}),r.addEventListener(`error`,()=>{this.#D(),this.#m=null,this.#k()}),this.#p=r,r}#D(){this.#p?.pause(),this.#O(!1)}#O(e){this.#f=e,e?(q&&q!==this&&q.#D(),q=this):q===this&&(q=null),this.#t!==null&&this.#x()}#k(){this.#a.textContent=this.#e.labels.voiceClipFailed,this.#a.hidden=!1}async#A(){if(this.#f)this.#D();else{this.#a.hidden=!0,this.#_=!0,this.#r.disabled=!0,this.#r.setAttribute(`aria-busy`,`true`);try{let e=await this.#T();if(e===null)return;this.#O(!0),await e.play()}catch{this.#D(),this.#m=null,this.#k()}finally{this.#_=!1,this.#r.removeAttribute(`aria-busy`),this.#r.disabled=typeof this.#e.readAttachment!=`function`}}}};function nn(e){let t=L(document,`span`,`wui-chat-clip-bar`);return t.style.setProperty(`--wui-chat-bar-height`,`${Math.round(e*100)}%`),t}I(`wui-chat-part-voice-clip`,tn);var rn={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`},an=8e3,on=6e3,sn=/* @__PURE__ */ new Set([`Blocked`,`NoMicrophone`]);function cn(e){let t=e instanceof T?e.code:`Failed`;return{code:t,source:`Dictation`,sticky:sn.has(t)}}function ln(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,on),r=n.lastIndexOf(`. `);return r===-1?n.trim():n.slice(0,r+1)}function un(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 dn(e){let t=e.getState,n=e.speech??a({getToken:e.getToken}),r=`Idle`,i=null,o=null,s=null,c=null,l=0,u=null,d=/* @__PURE__ */ new Set,f=()=>({mode:r,messageId:i,startedAtMs:o,note:s});function p(){let e=f();for(let t of[...d])t(e)}function m(e){r=e.mode,i=e.messageId??null,o=e.startedAtMs??null,p()}function h(){clearTimeout(u),u=null}function g(e){h(),s=e,e&&!e.sticky&&(u=setTimeout(()=>{u=null,s=null,p()},an)),p()}function _(){s!==null&&(h(),s=null,p())}function v(){return l+=1,c={id:l,controller:new AbortController,stopped:!1},c}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(cn(e))}}async function w(e,t){if(r===`Speaking`&&i===e){b();return}b(),g(null);let a=ln(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 fn=/* @__PURE__ */ new Set([`Shift`,`Control`,`Alt`,`Meta`,`Escape`]);function pn(e,t){e.isTrusted&&!fn.has(e.key)&&t.getStatus().mode===`Dictating`&&t.stop()}function mn({voice:e,getLabels:n,textarea:r,onTextChanged:i}){let a=null,o=t(`button`,`wui-chat-tool wui-chat-mic`,{type:`button`});o.append($t(`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=un(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 hn=10,gn=.9,_n=0;function vn(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 yn(e){_n+=1;let n=`wui-chat-composer-hint-${_n}`,r=t(`p`,`wui-chat-allowance`,{role:`status`});r.hidden=!0;let i=t(`span`),a=t(`button`,`btn btn-ghost-primary btn-sm wui-chat-action-btn`,{type:`button`});a.addEventListener(`click`,()=>e.onCancelEdit());let o=t(`div`,`wui-chat-editing`);o.hidden=!0,o.append(i,a);let s=t(`div`,`wui-chat-attachments`);s.hidden=!0;let c=t(`button`,`wui-chat-tool`,{type:`button`});c.append(h(`paperclip`,20)),c.hidden=!0;let l=t(`input`,null,{type:`file`,multiple:``,tabindex:`-1`});l.hidden=!0,l.addEventListener(`change`,()=>{let t=[...l.files];l.value=``,t.length>0&&e.onAttach(t)}),c.addEventListener(`click`,()=>l.click());let u=t(`textarea`,`wui-chat-input`,{rows:`1`,"aria-describedby":n}),d=t(`span`,`visually-hidden`,{id:n}),f=t(`span`,`wui-chat-counter`);f.hidden=!0;let p=t(`button`,`wui-chat-send`,{type:`submit`});p.append(h(`arrow-up`,18));let m=t(`button`,`wui-chat-send wui-chat-send--stop`,{type:`button`});m.append(h(`stop`,16)),m.hidden=!0,m.addEventListener(`click`,()=>e.onStop());let g=t(`form`,`wui-chat-composer`);g.append(c,l,u,f,d,m,p);let _=null,v=null,y=null,b=0,x=null;function S(){u.style.height=`auto`,u.style.height=`${u.scrollHeight}px`;let e=getComputedStyle(u),t=u.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=u.value.length,t=b>0&&e>b*gn;f.hidden=!t,t&&y&&(f.textContent=y.counter(e,b))}function E(){let e=x?.messagesLeftToday??null,t=u.value.trim()===``&&!w();p.disabled=!!x?.streaming||e===0||C()||t||x?.handoffPause===!0,g.classList.toggle(`wui-chat-composer--has-text`,!t)}function D(){if(p.disabled)return;let t=u.value.trim();u.value=``,S(),T(),E(),e.voice?.stop(),e.voice?.dismissNote(),e.onSubmit(t)}u.addEventListener(`input`,()=>{S(),T(),E(),u.value!==``&&e.onTyping?.()}),u.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),D())}),g.addEventListener(`submit`,e=>{e.preventDefault(),D()});let O=e.voice?mn({voice:e.voice,getLabels:()=>y,textarea:u,onTextChanged:()=>{S(),T(),E()}}):null;O&&(g.insertBefore(O.buttons[0],p),u.addEventListener(`keydown`,t=>pn(t,e.voice)));function ee(n){let r=n.map(n=>{let r=t(`span`,`wui-chat-chip`),i=t(`span`,null,n.status===`Failed`?{title:n.error??``}:null);i.textContent=n.fileName;let a=t(`button`,`wui-chat-chip-remove`,{type:`button`,"aria-label":y.removeAttachment(n.fileName)});a.append(h(`x`,14)),a.addEventListener(`click`,()=>e.onRemove(n.key));let o=[];if(n.status===`Uploading`){let e=t(`progress`,`wui-chat-chip-progress`,{max:`1`});typeof n.progress==`number`&&(e.value=n.progress);let r=t(`span`,`wui-chat-chip-status`);r.textContent=y.attachmentUploading,o.push(e,r)}if(n.status===`Failed`){let e=t(`span`,`wui-chat-chip-error`,{"aria-live":`polite`});e.textContent=n.error||y.attachmentFailed,o.push(e)}return r.append(i,...o,a),r});s.replaceChildren(...r),s.hidden=r.length===0}function k(t){x=t.state,y=t.labels,b=t.maxLength,t.sendIcon&&p.dataset.icon!==t.sendIcon&&(p.dataset.icon=t.sendIcon,p.replaceChildren(h(t.sendIcon,18)));let n=x.messagesLeftToday;g.setAttribute(`aria-label`,y.composer),d.textContent=y.composerHint,u.setAttribute(`aria-label`,y.composer),u.maxLength=b,u.placeholder=x.handoffPause?y.handoffMoment:vn(x.messages)??y.placeholder,u.disabled=n===0||x.handoffPause===!0,r.hidden=!(n!==null&&n<=hn),r.hidden||(r.textContent=y.allowance(n));let s=x.editing?.messageId??null;if(s!==_){let t=_!==null;_=s,x.editing?(e.voice?.stop(),u.value=x.editing.text,S()):t&&(u.value=``,S())}o.hidden=!x.editing,i.textContent=y.editing,a.textContent=y.cancel;let f=t.draft??null;typeof f==`string`&&f!==``&&f!==v&&(v=f,u.value=f,u.dispatchEvent(new Event(`input`)),u.focus(),e.onDraftApplied?.()),ee(x.attachments);let C=x.features.Attachments&&(x.profile?.limits.maxAttachments??0)>0&&x.handoffPause!==!0;c.hidden=!C,c.setAttribute(`aria-label`,y.attach),c.title=y.attachHint,l.accept=t.accept??``;let w=x.streaming&&x.features.Stop;m.hidden=!w,m.setAttribute(`aria-label`,y.stop),p.hidden=w,p.setAttribute(`aria-label`,y.send),T(),E(),O?.paint({state:x})}function te(){u.focus()}function ne(){O?.destroy();for(let e of A)e.remove()}let A=[r,o,s,...O?[O.note,O.announcer]:[],g];return{nodes:A,paint:k,focus:te,destroy:ne,getDraft:()=>u.value}}var bn=`https://policies.google.com/privacy`,xn=`https://policies.google.com/terms`;function Sn(e,n){let r=t(`a`,`wui-chat-footer-link`,{href:n,target:`_blank`,rel:`noopener noreferrer`});return r.textContent=e,r}function Cn(){let e=t(`span`,`wui-chat-footer-sep`,{"aria-hidden":`true`});return e.textContent=`·`,e}function wn(){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 n=t(`span`,`wui-chat-footer-privacy`);if(i.footer.privacyText&&n.append(document.createTextNode(i.footer.privacyText)),i.footer.privacyUrl){n.hasChildNodes()&&n.append(document.createTextNode(` `));let e=t(`a`,`wui-chat-footer-link`,{href:i.footer.privacyUrl});e.textContent=r.footerPrivacy,n.append(e)}if(n.hasChildNodes()&&a.push(n),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.captchaNote} `),Sn(r.captchaPrivacy,bn),document.createTextNode(` `),Sn(r.captchaTerms,xn)),a.push(e)}}e.replaceChildren(...a.flatMap((e,t)=>t?[Cn(),e]:[e])),e.hidden=a.length===0}return{el:e,paint:n}}function J(e,t,n){e.setAttribute(`aria-label`,t),e.title=t,e.dataset.icon!==n&&(e.dataset.icon=n,e.replaceChildren(h(n,20)))}function Tn(e){let n=t(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),r=t(`strong`,`wui-chat-title`);e.titleId&&(r.id=e.titleId);let a=t(`span`,`wui-chat-tagline`),o=t(`span`,`wui-chat-status`),s=t(`div`,`wui-chat-header-text`);s.append(r,a,o);let c=i(``,`history`,()=>e.onHistory()),l=i(``,`volume-high`,()=>e.onMute()),u=i(``,`plus`,()=>e.onNew()),d=i(``,`maximize-4`,()=>e.onSwitch());d.classList.add(`wui-chat-switch-btn`,`wui-chat-switch-btn--full`);let f=i(``,`panel-left-open`,()=>e.onSwitch());f.classList.add(`wui-chat-switch-btn`,`wui-chat-switch-btn--side`);let p=i(``,`x`,()=>e.onClose());p.classList.add(`wui-chat-close-btn`);let m=t(`div`,`wui-chat-header-actions`);m.append(c,l,u,d,f,p);let h=t(`header`,`wui-chat-header`);h.append(n,s,m);function g(e){let{labels:t}=e;h.hidden=!1,r.textContent=e.title??``,a.textContent=e.tagline??``,a.hidden=!e.tagline,o.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,paint:g}}var En=120;function Y(e,n,r=`outline`){let i=t(`button`,`${o(r,`sm`)} wui-chat-action-btn`,{type:`button`});return i.textContent=e,i.addEventListener(`click`,n),i}function Dn(e){let n=t(`div`,`wui-chat-history`);n.hidden=!0;let r=null,a=null,o=null,s=null,c=null,l=!1;function u(){return r||(r=te({client:e.getClient()}),a=r.subscribe(()=>y()),r)}function d(e){o={id:e.publicId,kind:`rename`,draft:e.title??``,saving:!1},s=null,c=null,l=!0,y()}function f(e){o={id:e.publicId,kind:`delete`,saving:!1},s=null,c=null,y()}function p(){o=null,s=null,c=null,y()}async function m(){let t=o,n=t?.draft.trim()??``;if(t?.kind===`rename`&&!t.saving&&n){t.saving=!0,y();try{await u().rename(t.id,n),o===t&&(o=null),s=null,c=null}catch{if(o!==t)return;t.saving=!1,c=e.getLabels().renameFailed}y()}}async function h(){let t=o;if(!(t?.kind!==`delete`||t.saving)){t.saving=!0,y();try{await u().remove(t.id),o===t&&(o=null),s=null,e.onDeleted(t.id)}catch{if(o!==t)return;t.saving=!1,s=e.getLabels().deleteFailed}y()}}function g(e){let n=t(`li`,`wui-chat-history-row wui-chat-history-row--editing`),r=t(`input`,`wui-chat-history-input`,{type:`text`,"aria-label":e.conversationTitle,maxlength:String(En)});r.value=o.draft,r.addEventListener(`input`,()=>{o.draft=r.value,i.disabled=o.saving||!o.draft.trim()}),r.addEventListener(`keydown`,e=>{e.key===`Enter`?(e.preventDefault(),m()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),p())});let i=Y(e.renameSave,()=>m(),`primary`);if(i.disabled=o.saving||!o.draft.trim(),n.append(r,i,Y(e.cancel,()=>p(),`ghost`)),c!==null){let e=t(`p`,`wui-chat-history-error`,{role:`alert`});e.textContent=c,n.append(e)}return l&&(l=!1,queueMicrotask(()=>r.focus())),n}function _(e){let n=t(`li`,`wui-chat-history-row wui-chat-history-row--confirm`),r=t(`p`);r.textContent=e.deleteConfirmTitle;let i=t(`p`);i.textContent=e.deleteConfirmMessage;let a=Y(e.deleteConfirm,()=>h(),`danger`);return a.disabled=o.saving,n.append(r,i,a,Y(e.cancel,()=>p(),`ghost`)),n}function v(n,r,a){if(o?.id===n.publicId&&o.kind===`rename`)return g(r);if(o?.id===n.publicId&&o.kind===`delete`)return _(r);let s=t(`li`,`wui-chat-history-row`),c=t(`button`,`wui-chat-history-open`,{type:`button`}),l=t(`span`,`wui-chat-history-title`);l.textContent=n.title||r.untitled;let u=t(`span`,`wui-chat-history-time`);return u.textContent=A(n.lastActivityDateTimeUtc),c.append(l,u),c.addEventListener(`click`,()=>e.onOpen(n.publicId)),s.append(c),a.Rename&&s.append(i(r.rename,`pencil`,()=>d(n))),a.Delete&&s.append(i(r.deleteChat,`trash`,()=>f(n))),s}function y(){let i=e.getLabels(),a=e.getFeatures(),o=r?r.getState():{items:[],loading:!1,error:null,hasMore:!1},c=[];if(o.error||s){let e=t(`p`,`wui-chat-history-error`,{role:`alert`});o.error?(e.append(document.createTextNode(i.loadFailed),document.createTextNode(` `)),e.append(Y(i.retry,()=>u().load(),`outline`))):e.textContent=s,c.push(e)}if(o.loading&&o.items.length===0){let e=t(`p`,`wui-chat-history-empty`,{role:`status`});e.textContent=i.loadingConversation,c.push(e)}if(o.items.length===0&&!o.loading&&!o.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(o.items.length>0){let e=t(`ul`,`wui-chat-history-list`,{"aria-label":i.history});e.append(...o.items.map(e=>v(e,i,a))),c.push(e)}o.hasMore&&!o.loading&&c.push(Y(i.loadMore,()=>u().loadMore(),`outline`)),n.replaceChildren(...c)}function b(){n.hidden=!1,u().load().catch(()=>{}),y()}function x(){n.hidden=!0}function S(){a?.(),a=null,r?.dispose(),r=null}return{el:n,show:b,hide:x,paint:y,dispose:S}}var On=/* @__PURE__ */ new Set([`GET`,`HEAD`]);function kn(){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 An(e){let t=await e.text();if(t){if((e.headers.get(`content-type`)||``).includes(`json`))try{return JSON.parse(t)}catch{return t}return t}}async function jn(e,t){let n=new TextDecoder,r=e.body.getReader(),i=``;for(;;){let{done:a,value:o}=await r.read();if(a)break;i+=n.decode(o,{stream:!0}),t({event:{target:{responseText:i,status:e.status}}})}return i+=n.decode(),i}function Mn({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(!On.has(t)){let e=kn();e&&(a[e.header]=e.token)}let s=i.signal,c=s,l,u,d=()=>l.abort(s.reason);i.timeout>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=await e(n,{method:t,headers:a,body:o,signal:c,credentials:`same-origin`});if(!r.ok){let e=/* @__PURE__ */ Error(`Request failed with status ${r.status}`);throw e.response={status:r.status,data:await An(r)},e}let s=i.responseType===`arraybuffer`,l=!s&&typeof i.onDownloadProgress==`function`&&r.body,u;return u=s?await r.arrayBuffer():l?await jn(r,i.onDownloadProgress):await An(r),{data:u,status:r.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 Nn(e){let n=null,r=!1,i=!1,a=t(`div`,`wui-chat-nudge`,{role:`status`});a.hidden=!0;let o=t(`button`,`wui-chat-nudge-text`,{type:`button`}),s=t(`button`,`wui-chat-nudge-close`,{type:`button`});s.append(h(`x`,14)),a.append(o,s);function c(){clearTimeout(n),n=null}function l(){c(),i=!0,a.hidden=!0}o.addEventListener(`click`,()=>{a.hidden=!0,e.onActivate()}),s.addEventListener(`click`,()=>{l(),e.onDismiss()});function u(e){c(),i||r||(n=setTimeout(()=>{n=null,o.textContent=e.text,s.setAttribute(`aria-label`,e.label),a.hidden=!1,r=!0},e.delaySeconds*1e3))}function d(){c(),a.remove()}return{el:a,schedule:u,cancel:c,dismiss:l,isShown:()=>r,destroy:d}}function Pn(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 u(e,n){let r=t(`button`,`wui-chat-empty-row`,{type:`button`}),i=t(`span`,`wui-chat-empty-row-title`);i.textContent=e.title||n.earlierChat;let s=t(`span`,`wui-chat-empty-row-time`,{title:E(e.lastActivityDateTimeUtc)});return s.textContent=l(e.lastActivityDateTimeUtc,o()),r.append(i,s),r.addEventListener(`click`,()=>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=>u(e,t))),s.hidden=!1}let f=n.subscribe(d);return{el:s,refresh(){i().History===!0&&n.load().catch(()=>{})},paint:d,dispose(){c=!0,f()}}}var Fn=`https://www.google.com/recaptcha/api.js?render=`,In=/* @__PURE__ */ new Map;function Ln(e){let t=In.get(e);if(t)return t;let n=new Promise((t,n)=>{if(globalThis.grecaptcha?.execute){t(globalThis.grecaptcha);return}let r=document.createElement(`script`);r.src=Fn+encodeURIComponent(e),r.async=!0,r.addEventListener(`load`,()=>t(globalThis.grecaptcha)),r.addEventListener(`error`,()=>{In.delete(e),n(/* @__PURE__ */ Error(`The reCAPTCHA script did not load.`))}),document.head.append(r)});return In.set(e,n),n}async function Rn(e,t){let n=await Ln(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 zn=`data-wui-chat-docked`,Bn=`--wui-chat-docked-width`,Vn=420,Hn=/* @__PURE__ */ new Set;function Un(e,t){let n=document.documentElement;n.setAttribute(zn,e),n.style.setProperty(Bn,t)}function Wn(){let e=document.documentElement;e.removeAttribute(zn),e.style.removeProperty(Bn)}function Gn(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)||Vn}px`;function c(){Hn.add(r),Un(i,s()),typeof ResizeObserver==`function`&&(o=new ResizeObserver(()=>document.documentElement.style.setProperty(Bn,s())),o.observe(t.panel))}function l(){o?.disconnect(),o=null,Hn.delete(r),Hn.size===0&&Wn()}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(zn,i))}function f(){u(!1)}return{...t,setOpen:u,setAppearance:d,destroy:f}}function Kn(e){return n({...e,layout:`embedded`,role:`region`,launcher:!1})}var qn=`wchat:peeked`,Jn=576,Yn=200;function Xn(e){let t=n({...e,layout:`launcher`,role:`dialog`,launcher:!0}),{root:r,panel:i,nudgeHost:a,launcherButton:o}=t,s={peek:!1,peekSeconds:3,hideWhileOpen:!1};o.dataset.state=`closed`;let c=!1,l=!1,u=null,d=null;function f(){!s.peek||c||l||a.dataset.launcher!==`idle`||globalThis.innerWidth<Jn||globalThis.sessionStorage.getItem(qn)!==null||(globalThis.sessionStorage.setItem(qn,`1`),a.dataset.launcher=`peeking`,u=setTimeout(()=>{u=null,a.dataset.launcher===`peeking`&&(a.dataset.launcher=`idle`)},s.peekSeconds*1e3))}a.addEventListener(`animationend`,e=>{e.target===a&&a.dataset.launcher===`idle`&&f()});function p(e){if(e!==l){if(l=e,clearTimeout(u),u=null,e)clearTimeout(d),d=null,s.hideWhileOpen?(a.dataset.launcher=`hidden`,a.toggleAttribute(`inert`,!0)):a.dataset.launcher===`peeking`&&(a.dataset.launcher=`idle`);else if(s.hideWhileOpen){let e=i.contains(document.activeElement);d=setTimeout(()=>{d=null,a.toggleAttribute(`inert`,!1),a.dataset.launcher=`idle`,e&&o.focus()},Yn)}}o.dataset.state=e?`open`:`closed`,t.setOpen(e)}function m(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.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),!s.hideWhileOpen&&a.dataset.launcher===`hidden`&&!l&&(a.dataset.launcher=`idle`),a.dataset.launcher===`idle`&&f()}return{...t,setOpen:p,setAppearance:m}}function Zn(e){return n({...e,layout:`full-page`,role:`region`,launcher:!1})}var Qn=3,$n={Primary:`wui-chat-starter--primary`,Cta:`wui-chat-starter--cta`};function er(e){let n=t(`h2`,`wui-chat-greeting`),r=t(`div`,`wui-chat-empty-hero`);r.append(t(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),n);let i=t(`div`,`wui-chat-empty-extra`);i.hidden=!0;let a=t(`div`,`wui-chat-starters`,{role:`group`}),o=t(`div`,`wui-chat-empty-rows`),s=t(`div`,`wui-chat-empty-past`),c=t(`div`,`wui-chat-empty`,{role:`group`});c.append(r,i,a,o,s);function l(n,r){let i=t(`button`,[`wui-chat-starter`,$n[n.variant]??``].filter(Boolean).join(` `),{type:`button`});return i.style.setProperty(`--wui-chat-i`,String(r)),n.icon&&i.append(h(n.icon,16)),i.append(document.createTextNode(n.label)),i.addEventListener(`click`,()=>e.onStarter(n)),i}function u(n,r){let i=t(`button`,`wui-chat-empty-row`,{type:`button`}),a=t(`span`,`wui-chat-empty-row-label`);a.textContent=r.resumeLast;let o=t(`span`,`wui-chat-empty-row-title`,{title:n.title||r.untitled});o.textContent=n.title||r.untitled;let s=t(`span`,`wui-chat-empty-row-time`);return s.textContent=A(n.lastActivityDateTimeUtc),i.append(a,o,s),i.addEventListener(`click`,()=>e.onResume()),i}function d(n,r,i){let a=i?t(`button`,`wui-chat-empty-row`,{type:`button`}):t(`span`,`wui-chat-empty-row`),o=t(`span`,`wui-chat-empty-row-label`);o.textContent=r.ticketAria(n.number);let s=t(`span`,`wui-chat-empty-row-title`);s.textContent=n.subject;let c=t(`span`,`wui-chat-empty-row-status`);return c.textContent=rt(n.status,r),a.append(o,s,c),i&&a.addEventListener(`click`,()=>e.onTicket(n)),a}function f(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,Qn).map(t=>d(t,n,e.ticketsClickable===!0))),r}function p(e){let{labels:t}=e;n.textContent=e.greeting??``,c.setAttribute(`aria-label`,t.emptyTitle);let r=e.starters??[];a.setAttribute(`aria-label`,t.starters),a.hidden=!e.showStarters||r.length===0,a.replaceChildren(...r.map(l));let i=e.resume??null,s=f(e,t);o.hidden=i===null&&s===null,o.replaceChildren(...[i===null?null:u(i,t),s].filter(Boolean))}return{el:c,paint:p,extraHost:i,pastHost:s}}function tr(){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 nr=150,rr=1800;function ir(){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()%rr)}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()%rr)}ms, 0s`,a()?t.remove():setTimeout(()=>t.remove(),nr))}return{el:e,render:o}}var ar=[`95%`,`80%`,`60%`];function or(){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 ar){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 sr=`http://www.w3.org/2000/svg`;function cr(e){if(e===`done`){let e=document.createElementNS(sr,`svg`);e.setAttribute(`viewBox`,`0 0 16 16`),e.setAttribute(`class`,`wui-chat-loader-steps-check`);let t=document.createElementNS(sr,`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 lr(){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(cr(o)))});r.length>e.steps.length;)r.pop().li.remove()}return{el:e,render:a}}var ur={Steps:lr,Phrases:ir,Orb:tr,Skeleton:or},dr=500;function fr(){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 i=null,a=null,o=0,s=null,c=0,l=null,u=!1;function d(){s!==null&&clearInterval(s),s=null}function f(){e.isConnected?(o+=1,p()):d()}function p(){if(!a||!i)return;let t=ce(i.style,i.steps,i.phrases,o);a.render(t),e.setAttribute(`aria-label`,t.label)}function m(){l!==null&&clearTimeout(l),l=null,u=!1,r.textContent=``}function h(e){!u&&l===null&&e&&(l=setTimeout(()=>{l=null,u=!0,r.textContent=e},dr))}function g(t){if(!t.active)i=null,e.hidden=!0,e.removeAttribute(`data-loading`),d(),m();else{if(!Object.hasOwn(ur,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(i={...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),!a||a.style!==t.style){let r=ur[t.style]();n.replaceChildren(r.el),a={style:t.style,render:r.render},e.dataset.style=t.style,o=0}h(t.announce),t.reduced===!0?(d(),o=0):(s===null||c!==t.intervalMs)&&(d(),c=t.intervalMs,s=setInterval(f,c)),p()}}function _(){d(),m(),a=null,i=null,e.remove()}return{el:e,update:g,destroy:_}}var pr=/* @__PURE__ */ new Set([`Assistant`,`Agent`,`Script`]),mr=/* @__PURE__ */ new WeakMap;function hr(e,t,n){let{labels:r,features:i,title:a,busy:o}=n;if(M(t.parts)!==``){if(i.Share&&_()){let n=m(`ghost`,r.share,`share`,async()=>{let e=yr([t],i,r,a,!1);e!==``&&await p({title:a,text:e})===`failed`&&Cr(n.parentElement,r.shareFailed)});n.disabled=o===!0,e.append(n)}if(i.Print){let t=m(`ghost`,r.print,`printer`,()=>{try{C(t.closest(`.wui-chat`),t.closest(`li.wui-chat-message`),{title:a,printedOn:xr(r)})}catch{Sr(t,r.printFailed)}});e.append(t)}}}function gr(e,t,n){if(t.streaming||t.thinking||t.loading||t.conversationId===null||t.messages.filter(e=>e.stored&&pr.has(e.author.kind)&&M(e.parts)!==``).length===0){e.hidden=!0;return}let{labels:r,features:i}=n,a=!!i.Share&&_(),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(_r(e,r,i,n)),o&&e.append(vr(e,r,n))),e.hidden=!1}function _r(e,t,n,r){return m(`ghost`,t.shareConversation,`share`,async()=>{let i=r.getState(),a=br(i,r),o=yr(i.messages.filter(e=>e.stored),n,t,a,!0);await p({title:a,text:o})===`failed`&&Cr(e,t.shareFailed)})}function vr(e,t,n){let r=m(`ghost`,t.printConversation,`printer`,()=>{try{s(e.closest(`.wui-chat`),{title:br(n.getState(),n),printedOn:xr(t)})}catch{Sr(r,t.printFailed)}});return r}function yr(e,t,n,r,i){let a=O(e,{labels:n,title:r,figureText:t.FigureText});return pe(a,{heading:i,speakers:i})}function br(e,t){return typeof e.title==`string`&&e.title!==``?e.title:t.title}function xr(e){return e.printedOn(A((/* @__PURE__ */ new Date()).toISOString()))}function Sr(e,t){let n=e.lastChild,r=mr.get(n);r?clearTimeout(r.timer):r={original:n.data},n.data=t,r.timer=setTimeout(()=>{n.data=r.original,mr.delete(n)},_e),mr.set(n,r)}function Cr(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(),_e)}function wr({voice:e,getLabels:n,message:r}){if(r.streaming||!e.canSpeak()||ln(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($t(a?`stop`:`speaker`,16)),c.addEventListener(`click`,()=>{e.toggleSpeak(r.id,r.parts)}),c}function Tr({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=un(i,n()),a}var Er=/* @__PURE__ */ new Set([`Assistant`,`Agent`]),Dr=/* @__PURE__ */ new Set([`Assistant`,`Agent`,`Script`]),Or=/* @__PURE__ */ new Set([`Visitor`,`Customer`]),kr=48,Ar=120,jr={author:{kind:`Assistant`}},Mr={warning:`alert-triangle`,danger:`alert-circle`};function Nr(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=kr}function Pr(e){let{kind:t,displayName:n}=e.author;return t===`Agent`?`Agent:${n??``}`:t===`Script`?`Assistant`:t}function Fr(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 Ir(e){let t=e.textContent.trim();t&&!e.hasAttribute(`aria-label`)&&(e.setAttribute(`aria-label`,t),e.title=t)}function Lr(e){return e.reduced===!0}function Rr(e,n,r){let i=t(`button`,`${o(`ghost`,`sm`)} wui-chat-action-btn`,{type:`button`,"aria-label":e,title:e}),a=t(`span`);return a.textContent=e,i.append(h(n,14),a),i.addEventListener(`click`,r),{node:i,text:a}}function zr(e,t){return e.profile?.assistant.name??t.panelTitle}function Br(e,t){return e.author.displayName==null?e.author.kind===`Visitor`||e.author.kind===`Customer`?t.you:e.author.kind===`Agent`?t.agent:t.assistant:e.author.displayName}function Vr(e){let n=t(`ol`,`wui-chat-thread`),r=t(`div`,`wui-chat-log`,{role:`log`,"aria-live":`polite`});r.append(n);let i=fr(),a=t(`li`,`wui-chat-message wui-chat-message--assistant wui-chat-message--loading`),s=t(`div`,`wui-chat-loader-slot`);s.append(i.el),a.append(s);let c=!1,l=null,u=t(`li`,`wui-chat-message wui-chat-message--assistant wui-chat-message--greeting`,{"data-run-start":``,"data-restored":``}),d=t(`div`,`wui-chat-message-body`),f=t(`p`,`wui-chat-text`);d.append(f),u.append(d);let p=t(`li`,`wui-chat-conversation-actions`);p.hidden=!0;let m=t(`button`,`wui-chat-jump`,{type:`button`}),g=t(`div`,`wui-chat-jump-slot`);g.hidden=!0,g.append(m);let _=null,v=!0,y=null,b=null,x=/* @__PURE__ */ new Map,S=``,C=null;function w(e,t,n){return n[e.kind]?{kind:e.kind,part:e,tag:n[e.kind]}:{kind:`Notice`,part:{kind:`Notice`,code:`NeedsNewerApp`,text:t.needsNewerApp},tag:n.Notice}}function T(t,n,r){let i=document.createElement(t);return i.message=r,i.turn=e.makeTurnApi(r.id),i.part=n,i}function D(e){return t(`div`,`wui-chat-part wui-chat-part--${e.toLowerCase()}`)}function O(e,n,r,i,a){e.parts=[];let o=[],s=e=>{let t=w(e,r,i),a=D(t.kind);return a.append(T(t.tag,t.part,n)),a};for(let e of a(n))if(Array.isArray(e)){let n=t(`div`,`wui-chat-part-group`);n.append(...e.map(s)),o.push(n)}else o.push(s(e));e.body.replaceChildren(...o)}function ee(t,n,r,i){let a=[];n.parts.forEach((o,s)=>{let c=w(o,r,i),l=t.parts[s];if(l&&l.kind===c.kind&&l.tag===c.tag){l.part!==c.part&&(l.element.message=n,l.element.turn=e.makeTurnApi(n.id),l.element.part=c.part,l.part=c.part),a.push(l);return}let u=D(c.kind),d=T(c.tag,c.part,n);u.append(d),a.push({kind:c.kind,tag:c.tag,part:c.part,element:d,wrapper:u})}),t.parts=a,k(t.body,a.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 te(e,n,r){let i=t(`div`,`wui-chat-rating`,{role:`group`,"aria-label":`${r.rateUp}/${r.rateDown}`});for(let[a,s,c]of[[`Up`,r.rateUp,`thumbs-up`],[`Down`,r.rateDown,`thumbs-down`]]){let l=n.rating===a,u=t(`button`,`${o(l?`neutral`:`ghost`,`sm`)} wui-chat-action-btn`,{type:`button`,"aria-pressed":String(l),"data-rating":a,"aria-label":s,title:s}),d=t(`span`);d.textContent=s,u.append(h(c,14),d),u.addEventListener(`click`,()=>ne(e,n,a,r)),i.append(u)}if(e.ratingNote){let n=t(`span`,null,{role:`status`});n.textContent=e.ratingNote,i.append(n)}return i}async function ne(t,n,r,i){try{await e.onRate(n.id,r),t.ratingNote=i.rated}catch{t.ratingNote=i.ratingFailed}C&&fe(C.state,C.context)}function A(n,r,i,a,o){let{labels:s}=a,c=i.features,l=r.author.kind,u=M(r.parts),d=[];if(c.Copy&&Dr.has(l)&&u){let e=Rr(s.copy,`copy`,async()=>{await ye(u)&&(e.text.textContent=s.copied,e.node.dataset.done=``,e.node.setAttribute(`aria-label`,s.copied),e.node.title=s.copied,clearTimeout(n.copyTimer),n.copyTimer=setTimeout(()=>{e.text.textContent=s.copy,delete e.node.dataset.done,e.node.setAttribute(`aria-label`,s.copy),e.node.title=s.copy},_e))});d.push(e.node)}let f=e.getVoice?.();if(f&&Dr.has(l)){let e=wr({voice:f,getLabels:()=>s,message:r});e&&d.push(e);let t=Tr({voice:f,getLabels:()=>s,message:r});t&&d.push(t)}if(Dr.has(l)){let e=t(`div`);hr(e,r,{labels:s,features:c,title:zr(i,s),busy:i.streaming||i.thinking});for(let t of e.childNodes)Ir(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(Rr(s.regenerate,`refresh`,()=>e.onRegenerate()).node);let m=i.messages.findLast(e=>e.author.kind===`Visitor`&&e.stored);c.Edit&&m?.id===r.id&&!i.streaming&&!i.thinking&&d.push(Rr(s.edit,`pencil`,()=>e.getSession().startEdit(r.id)).node),c.Rating&&r.stored&&Er.has(l)&&d.push(te(n,r,s)),n.actions.hidden=d.length===0,n.actions.replaceChildren(...d)}function re(e){let n=x.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:null,ratingNote:null};return x.set(e.id,s),s}function ie(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?et(t.author,r):null,e.head&&e.li.insertBefore(e.head,e.body)}function ae(t,n,r,i,a,o){let{labels:s}=i;t.li.className=`wui-chat-message wui-chat-message--${n.author.kind.toLowerCase()}`,t.li.toggleAttribute(`data-restored`,n.restored===!0),t.li.toggleAttribute(`data-run-start`,!o||Pr(o)!==Pr(n)),n.streaming?t.li.setAttribute(`aria-busy`,`true`):t.li.removeAttribute(`aria-busy`),t.author.textContent=`${Br(n,s)}: `,ie(t,n,o,s);let c=e.getRenderers(),l=e.getLayoutParts();typeof l==`function`?O(t,n,s,c,l):ee(t,n,s,c),n.streaming?(t.actions.hidden=!0,t.actions.replaceChildren()):A(t,n,r,i,a)}function oe(e,n){let r=t(`li`,`wui-chat-message wui-chat-message--system wui-chat-message--notice`),i=t(`div`,`wui-chat-notice wui-chat-notice--${e}`,{role:e===`danger`?`alert`:`status`}),a=t(`span`,`wui-chat-notice-icon`,{"aria-hidden":`true`});a.append(h(Mr[e],16));let o=t(`div`,`wui-chat-notice-body`),s=t(`span`,`wui-chat-notice-text`);return s.textContent=n,o.append(s),i.append(a,o),r.append(i),r}function se(e,t){let n=e.resetsDateTimeUtc?` ${t.dailyLimitRefresh(E(e.resetsDateTimeUtc))}`:``;return oe(`warning`,`${e.message}${n}`)}function ce(n,r){let{labels:i}=r,a=n.turnError?.code??``;if(a===`daily_limit`)return se(n.turnError,i);if(a.endsWith(`feature_off`))return oe(`danger`,n.turnError.message||i.stopped);let o=t(`li`,`wui-chat-message wui-chat-message--system wui-chat-message--error`),s=t(`p`,`wui-chat-error`,{role:`alert`});s.textContent=n.turnError?.message||i.stopped;let c=h(`alert-circle`,16);if(c.setAttribute(`aria-hidden`,`true`),o.append(c,s),n.features.Retry){let n=t(`div`,`wui-chat-message-actions`);n.append(Rr(i.retry,`rotate-ccw`,()=>e.onRetry()).node),o.append(n)}return o}function le(){return n.closest(`.wui-chat`)}function j(){return n.closest(`.wui-chat-body`)??Fr(n)}function ue(e){le()?.classList.toggle(`wui-chat--scrolled`,e.scrollTop>0),Nr(e)&&(g.hidden=!0)}function N(){v=Nr(_),ue(_)}function de(e){r.nextElementSibling!==g&&r.parentNode&&r.after(g),e!==_&&(_?.removeEventListener(`scroll`,N),_=e,e.addEventListener(`scroll`,N,{passive:!0}),!y&&typeof ResizeObserver==`function`&&(y=new ResizeObserver(()=>{v&&_&&(_.scrollTop=_.scrollHeight)}),y.observe(n)))}m.addEventListener(`click`,()=>{let e=j(),t=C?.context.reduced===!0;e?.scrollTo({top:e.scrollHeight,behavior:t?`auto`:`smooth`}),g.hidden=!0,m.blur()});function P(e,t){let n=e.messages.at(-1),r=n?`${n.id}|${M(n.parts).length}`:``;if(r===S)return;let i=S===``||e.conversationId!==b;S=r,b=e.conversationId;let a=j();a&&(de(a),i||t||Or.has(n?.author.kind)?(a.scrollTop=a.scrollHeight,g.hidden=!0,v=!0):(g.hidden=!1,v=!1),ue(a))}function fe(t,o){C={state:t,context:o};let{labels:s}=o;r.setAttribute(`aria-label`,s.thread),m.textContent=s.newMessages??`New messages`;let d=j();d&&de(d);let h=d===null||d.clientHeight===0||Nr(d),g=[],_=/* @__PURE__ */ new Set,v=t.messages.filter(e=>!(e.streaming&&e.parts.length===0)),y=v.length>0&&Or.has(v[0].author.kind)&&t.greeting?t.greeting:null;y&&(f.textContent=y,g.push(u)),v.forEach((e,n)=>{let r=re(e);_.add(e.id);let i=v[n-1]??(y?jr:null);ae(r,e,t,o,n===v.length-1,i),g.push(r.li)});for(let e of[...x.keys()])_.has(e)||x.delete(e);t.agentTyping&&g.push(tt(t.agentTyping,s)),t.thinking?(clearTimeout(l),l=null,a.classList.remove(`wui-chat-message--leaving`),c=!0,i.update({active:!0,style:o.loaderStyle,steps:t.steps,phrases:o.phrases,intervalMs:o.intervalMs,reduced:o.reduced,announce:o.assistantName?.trim()?s.preparingAnswer(o.assistantName):void 0}),g.push(a)):c&&l===null&&!Lr(o)?(a.classList.add(`wui-chat-message--leaving`),l=setTimeout(()=>{l=null,c=!1,a.classList.remove(`wui-chat-message--leaving`),i.update({active:!1}),C&&fe(C.state,C.context)},Ar),g.push(a)):l===null?(c=!1,i.update({active:!1})):g.push(a),!t.streaming&&(t.turnError||t.stopped)&&g.push(ce(t,o)),gr(p,t,{labels:s,features:t.features,title:zr(t,s),getState:()=>e.getSession().getState()}),g.push(p),k(n,g),P(t,h)}function pe(e){return x.get(e)?.li??null}function me(){clearTimeout(l),i.destroy(),_?.removeEventListener(`scroll`,N),y?.disconnect(),x.clear(),C=null,r.remove()}return{el:r,paint:fe,find:pe,destroy:me}}var Hr=typeof HTMLElement>`u`?class{}:HTMLElement;function Ur(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 Wr(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 Gr(e,t,n){return t.PanelSwitch!==!0||typeof n!=`function`?null:e===`docked`?`full-page`:e===`full-page`?`docked`:null}var Kr=[`launcher`,`docked`,`full-page`,`embedded`],qr=[`end`,`start`],Jr={steps:`Steps`,phrases:`Phrases`,orb:`Orb`,skeleton:`Skeleton`},Yr={on:`On`,reduced:`Reduced`},Xr=[`auto`,`light`,`dark`],Zr=`wchat:muted`,Qr=6e4,$r=400,ei=[`labels`,`pageContext`,`compact`,`open`,`layoutParts`,`getCaptchaToken`,`openAttachment`,`openCitation`,`openTarget`,`openTicket`,`onNavigate`,`resolveLink`,`emptyContent`,`onPanelSwitch`,`preloadPanelSwitch`],ti={...rn};function ni(e,t){if(!w.includes(e))throw Error(`Unknown part kind "${e}". Use one of ${w.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();if(!Object.hasOwn(t,r))throw Error(`<wui-chat ${e}> must be one of ${Object.keys(t).join(`, `)}, got "${n}".`);return t[r]}}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 ri(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 Q=e=>e.split(`,`).map(e=>e.trim()).filter(Boolean),ii=[[`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`,ri(`compact`)],[`launcher-mark`,`launcher`,`mark`,X(`launcher-mark`,{icon:`Icon`,avatar:`Avatar`})],[`panel-height`,`panel`,`height`,X(`panel-height`,{fixed:`Fixed`,content:`Content`})],[`reply-avatars`,`panel`,`replyAvatars`,ri(`reply-avatars`)],[`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`,ri(`input-ring`)],[`send-reveal`,`input`,`sendReveal`,X(`send-reveal`,{"on-text":`OnText`,always:`Always`})],[`send-icon`,`input`,`sendIcon`,e=>e],[`lift-selectors`,`avoid`,`liftSelectors`,Q],[`menu-selectors`,`avoid`,`menuSelectors`,Q],[`dark-selectors`,`avoid`,`darkSelectors`,Q],[`autoopen-busy-selectors`,`avoid`,`autoOpenBusySelectors`,Q],[`autoopen-optout-selector`,`avoid`,`autoOpenOptOutSelector`,e=>e]],ai={layout:`launcher`,position:`end`,"offset-x":`24`,"offset-y":`24`,loader:`steps`,motion:`on`,icon:`chat`},oi=[`base`,`layout`,`position`,`offset-x`,`offset-y`,`loader`,`screen`,`motion`,`theme`,`icon`,`avatar`,`narrow`,...ii.map(([e])=>e).filter(e=>e!==`compact`)],si=e=>e.replace(/-([a-z0-9])/g,(e,t)=>t.toUpperCase());function ci(e){let t={launcher:{},panel:{},phone:{},input:{},avoid:{}};for(let[n,r,i,a]of ii){let o=e.getAttribute(n);o!=null&&(t[r][i]=a(o))}let n=e.getAttribute(`motion`),r=e.getAttribute(`avatar`);return j({...t,motion:n==null?void 0:X(`motion`,Yr)(n),avatar:r||void 0})}function li(e){let t=e.getAttribute(`loader`)??`steps`;if(!Object.hasOwn(Jr,t))throw Error(`<wui-chat loader> must be one of ${Object.keys(Jr).join(`, `)}, got "${t}".`);return Jr[t]}function ui(e){let t=e.getAttribute(`narrow`);if(t!=null&&t!==``)return Object.fromEntries(Q(t).map(e=>[e,!1]))}function di(e){return e===Zr?globalThis.localStorage:globalThis.sessionStorage}var fi={get:e=>di(e).getItem(e),set:(e,t)=>di(e).setItem(e,t)};function pi(e){return globalThis.innerWidth<=e.phone.maxWidthPx}function mi(e){let t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)}var hi=0,$=class extends Hr{static get observedAttributes(){return[...oi,`compact`,`open`,`labels`,`page-context`,`narrow`].filter((e,t,n)=>n.indexOf(e)===t)}constructor(){super(),hi+=1,this._uid=`wui-chat-${hi}`,this._built=!1,this._session=null,this._unsubscribe=null,this._voice=null,this._voiceConversationId=void 0,this._shell=null,this._labelsProp=void 0,this._pageContextProp=void 0,this._layoutParts=null,this._renderers={...ti},this._rendererApi={define:(e,t)=>{ni(e,t),this._renderers[e]=t,this._render()},map:this._renderers},this._captchaToken=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 le({...e(this,`labels`),...this._labelsProp})}set labels(e){this._labelsProp=e??void 0,this._render()}get pageContext(){return this._pageContextProp===void 0?e(this,`page-context`):this._pageContextProp}set pageContext(e){this._pageContextProp=e===null?void 0:e}get compact(){return this.hasAttribute(`compact`)}set compact(e){this.toggleAttribute(`compact`,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 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(){if(this._adoptEarlyProperties(),this._assertLayout(),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(),this._session||this._createSession(),this._past||this._createPast(),this._unsubscribe||=this._session.subscribe(()=>this._render()),this._render()}_adoptEarlyProperties(){for(let e of ei){if(!Object.hasOwn(this,e))continue;let t=this[e];delete this[e],this[e]=t}}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._assertLayout(),this._buildShell();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;if(!Kr.includes(e))throw Error(`<wui-chat layout> must be one of ${Kr.join(`, `)}, got "${e}".`)}_assertPosition(){let e=this.position;if(!qr.includes(e))throw Error(`<wui-chat position> must be one of ${qr.join(`, `)}, got "${e}".`)}_isLauncherLike(){return this.layout===`launcher`||this.layout===`docked`}_build(){this._built=!0,this._header=Tn({onNew:()=>this.newConversation(),onHistory:()=>this._toggleHistory(),onClose:()=>this.close(),onMute:()=>this._session?.setMuted(!this._session.getState().muted),onSwitch:()=>this._switchPanel(),titleId:`${this._uid}-title`}),this._starters=er({onStarter:e=>this._session.submit(e.message),onResume:()=>this._session.resumeLast(),onTicket:e=>{typeof this.openTicket==`function`&&this.openTicket({ticketId:e.ticketId,number:e.number})}}),this._applyEmptyContent(),this._voice=dn({getState:()=>this._session.getState(),getLabels:()=>this.labels,getToken:()=>this._session.client.getSpeechToken()}),this._voice.subscribe(()=>this._render()),this._thread=Vr({getRenderers:()=>this._renderers,getLayoutParts:()=>this._layoutParts,makeTurnApi:e=>this._makeTurnApi(e),onRetry:()=>this._session.retry(),onRegenerate:()=>this._session.regenerate(),onRate:(e,t)=>this._session.rate(e,t),getSession:()=>this._session,getVoice:()=>this._voice}),this._composer=yn({voice:this._voice,onSubmit:e=>this._session.submit(e),onStop:()=>this._session.stop(),onAttach:e=>this._session.attach(e),onRemove:e=>this._session.removeAttachment(e),onCancelEdit:()=>this._session.cancelEdit(),onTyping:()=>this._session.notifyTyping(),onDraftApplied:()=>this._session.consumeDraft()}),this._footer=wn(),this._history=Dn({getClient:()=>this._session.client,getLabels:()=>this.labels,getFeatures:()=>this._session.getState().features,onOpen:e=>{this._session.openConversation(e).catch(()=>{}),this._toggleHistory(!1)},onDeleted:e=>{e===this.conversationId&&this._session.newConversation()}}),this._nudge=Nn({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`,`${o(`outline`,`sm`)} wui-chat-handoff-request`,{type:`button`}),this._talk.addEventListener(`click`,()=>this._requestHandoff()),this._liveRetry=t(`button`,o(`ghost`,`sm`),{type:`button`}),this._liveRetry.addEventListener(`click`,()=>this._session.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(){let e={launcher:Xn,docked:Gn,"full-page":Zn,embedded:Kn};this._shell?.destroy?.(),this._avoid?.destroy(),this._avoid=null,this._autoOpen?.cancel(),this._autoOpen=null,this._lastOpen=!1,this._launcherPlayed=!1;let t=e[this.layout]({id:`${this._uid}-panel`,position:this.position,onToggle:()=>this.toggle()});t.panel.append(this._header.el,this._body,this._foot),t.panel.setAttribute(`aria-labelledby`,`${this._uid}-title`),t.panel.addEventListener(`keydown`,e=>{e.key===`Tab`&&g(t.panel,e)}),t.nudgeHost&&t.nudgeHost.prepend(this._nudge.el),this._shell=t,this.replaceChildren(t.root)}_createSession(){let e=ee(Mn(),{base:this.base}),t=ui(this);this._session=k(e,{screen:this.screen||void 0,narrow:t,pageContext:()=>this.pageContext,behaviour:()=>this._session?.getState().features.BehaviourStarters?this._behaviour?.()??null:null,prefs:fi,reducedMotion:()=>this._motion?.reduced??!1,schedule:mi,getCaptchaToken:e=>{if(this._captchaToken)return this._captchaToken(e);let t=this._session?.getState().profile?.captcha?.siteKey;return t?Rn(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=te({client:this._session.client,pageSize:20}),this._past=Pn({list:this._pastList,getLabels:()=>this.labels,getFeatures:()=>this._session.getState().features,onOpen:e=>{this._session.openConversation(e).catch(()=>{})}}),this._starters.pastHost.append(this._past.el)}_disposePast(){this._past&&(this._past.el.remove(),this._past.dispose(),this._pastList.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._session.getState(),t=Gr(this.layout,e.features,this._onPanelSwitchProp);if(t===null)return;t===`full-page`&&this.close();let n={from:this.layout,to:t,conversationId:e.conversationId,draft:this._composer.getDraft()};x(()=>this._onPanelSwitchProp(n),{target:t,reduced:this._motion?.reduced===!0}).then(()=>document.querySelector(`.wui-chat--${t} .wui-chat-input`)?.focus()).catch(e=>globalThis.reportError?.(e))}async _requestHandoff(){this._requesting=!0,this._liveError.hidden=!0,this._render();try{await this._session.requestHandoff()}catch(e){this._liveError.textContent=e?.message||this.labels.errorGeneric,this._liveError.hidden=!1}finally{this._requesting=!1,this._render()}}_paintLive(e,t,n){let r=e.live===`Lost`,i=Wr(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._session.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._session,{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._session.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),Qr)}).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._voice.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=ci(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`),d=Gr(this.layout,i,this._onPanelSwitchProp),f=e.streaming||e.thinking;this._header.paint({labels:t,title:n.assistant.name,tagline:n.assistant.tagline,status:Ur(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}),this._starters.el.hidden=!c||l,c&&this._starters.paint({labels:t,greeting:e.greeting,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:li(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,i){let a=e.features;this._motion||(this._motion=r(n,t.experience),this._motion.subscribe(()=>this._render())),a.Sounds&&!this._sound&&(this._sound=c(t.experience.sound,fi)),!a.Sounds&&this._sound&&(this._sound=null),a.BehaviourStarters&&!this._behaviour&&(this._behaviour=d(t.start.behaviour?.servicePathPrefixes??[]));let o=this._isLauncherLike();o&&!this._avoid&&this.layout===`launcher`&&(this._avoid=f(n.avoid,t.experience.launcher,this._shell.nudgeHost)),this.layout===`launcher`&&a.AutoOpen&&!this._autoOpen&&(this._autoOpen=b(t.experience.autoOpen,n,{open:()=>this._setOpen(!0,`auto`),isOpen:()=>this._session.getState().open,panelRect:()=>this._shell.panel.getBoundingClientRect()}));let s=pi(n);this._shell.setLabels(i),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:Xr.includes(this.getAttribute(`theme`))?this.getAttribute(`theme`):`auto`,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,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&&pi(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=ue(t,n);e&&(this._nudge.schedule({text:e.text,delaySeconds:e.delaySeconds,label:r.nudgeDismiss}),this._nudgeArmed=!0)}}}_onOpenChange(e){let t=pi(ci(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;try{this._preloadPanelSwitchProp()?.catch?.(()=>{})}catch{}}if(t){let e=ci(this);this._phone={fit:v(this._shell.panel,e),unlock:y(this._thread.el)}}else this._openTrigger===`manual`&&(this._focusTimer=setTimeout(()=>{this._focusTimer=null,this._composer.focus()},$r))}else document.removeEventListener(`keydown`,this._onKeyDown),clearTimeout(this._focusTimer),this._focusTimer=null,this._phone?.fit.destroy(),this._phone?.unlock(),this._phone=null,this._historyShown&&(this._historyShown=!1,this._history.hide(),this._render()),u(this._shell.launcherButton)}_syncConversation(e){let t=this.getAttribute(`conversation-id`);t&&t!==this._openedConversation&&!e.loading&&(this._openedConversation=t,e.conversationId!==t&&this._session.openConversation(t).catch(()=>{}))}_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._session.getState().profile;e?.experience.sound.vibrate&&S(e.experience.sound.vibrateMs,this._sound.isMuted())}}};Object.defineProperty($.prototype,"layout",{get(){return this.getAttribute(`layout`)??ai.layout},set(e){this.setAttribute(`layout`,String(e))}});for(let e of oi)e!==`layout`&&Object.defineProperty($.prototype,si(e),{configurable:!0,get(){return this.getAttribute(e)??ai[e]??``},set(t){t==null?this.removeAttribute(e):this.setAttribute(e,String(t))}});function gi(){typeof customElements<`u`&&!customElements.get(`wui-chat`)&&customElements.define(`wui-chat`,$)}gi();export{$ as WuiChat,Mn as createFetchChatHttp,rn as defaultRenderers,gi as defineChat};
|